diff --git a/gen/du_info_export b/gen/du_info_export index 4f083908..ba8c8219 100755 --- a/gen/du_info_export +++ b/gen/du_info_export @@ -9,7 +9,7 @@ use Tie::IxHash; our $SERVICE_NAME = "du_info_export"; our $PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.2"; +my $SCRIPT_VERSION = "3.0.3"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; @@ -77,7 +77,6 @@ foreach my $resourceId ($data->getResourceIds()) { foreach my $memberId ($data->getMemberIdsForResource(resource => $resourceId)) { my $uuid = $data->getUserAttributeValue(attrName => $A_U_UUID, member => $memberId); my $einfraLogin = $data->getUserAttributeValue(attrName => $A_USER_LOGIN_EINFRA, member => $memberId); - $einfraLogin = defined $einfraLogin ? $einfraLogin : ""; unless(defined $attributesByUUID{$uuid}) { diff --git a/gen/myq_printsvc b/gen/myq_printsvc index 7c03e87d..7bb71054 100755 --- a/gen/myq_printsvc +++ b/gen/myq_printsvc @@ -7,7 +7,7 @@ use perunServicesUtils; local $::SERVICE_NAME = "myq_printsvc"; local $::PROTOCOL_VERSION = "3.1.0"; -my $SCRIPT_VERSION = "3.0.0"; +my $SCRIPT_VERSION = "3.0.1"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; @@ -84,7 +84,7 @@ for my $login (@logins) { # CODE print FILE $login . ";"; # SCANSTORAGE - print FILE '"' . "\\\\copy.ics.muni.cz\\$login\\Scan" . '";'; + print FILE '"' . "\\\\ha-bay.ics.muni.cz\\sciscan\\$login\\Scan" . '";'; # PIN print FILE ";"; # MANAGED_GROUPS diff --git a/gen/o365_mu b/gen/o365_mu index 4a356d3e..2d51f325 100755 --- a/gen/o365_mu +++ b/gen/o365_mu @@ -16,8 +16,8 @@ sub saveUsersToFile; sub saveGroupsToFile; our $SERVICE_NAME = "o365_mu"; -our $PROTOCOL_VERSION = "3.1.0"; -my $SCRIPT_VERSION = "3.1.1"; +our $PROTOCOL_VERSION = "3.2.0"; +my $SCRIPT_VERSION = "3.2.0"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; @@ -28,6 +28,7 @@ my $data = perunServicesInit::getHashedDataWithGroups; #------------------------------------------------------------------------- our $A_G_AD_NAME; *A_G_AD_NAME = \'urn:perun:group:attribute-def:def:adName:o365mu'; +our $A_G_O365_MAILS; *A_G_O365_MAILS = \'urn:perun:group:attribute-def:def:o365EmailAddresses:o365mu'; our $A_F_DOMAIN_NAME; *A_F_DOMAIN_NAME = \'urn:perun:facility:attribute-def:def:o365DomainName'; our $A_MG_O365_SEND_AS; *A_MG_O365_SEND_AS = \'urn:perun:member_group:attribute-def:virt:o365SendAs'; our $A_U_O365_MAIL_ADDRS; *A_U_O365_MAIL_ADDRS = \'urn:perun:user:attribute-def:def:o365EmailAddresses:mu'; @@ -45,6 +46,8 @@ our $MAIL_FORWARD_TEXT = "mailForward"; our $ARCHIVE_TEXT = "archive"; our $STORE_AND_FORWARD_TEXT = "storeAndForward"; our $EMAIL_ADDRESSES = "emailAddresses"; +our $GROUP_MAIL_TEXT = "groupMail"; +our $GROUP_CONTACTS_TEXT = "groupContacts"; ###------------------------------------------------------------------------------ ### RESOURCE MAILBOXES CONFIGURATION @@ -338,7 +341,18 @@ sub processGroup { if($groupADName) { #all groups for mu should have specific part of name $groupADName = $groupADName . '_group.muni.cz'; - $groups->{$groupADName} = undef; + #get group mail + my $groupMails = $data->getGroupAttributeValue( group => $groupId, attrName => $A_G_O365_MAILS ); + #take the first email if there is none with right domain + my $groupMail = $groupMails->[0]; + foreach my $mail(sort @$groupMails) { + if($mail =~ m/\@group[.]muni[.]cz/) { + $groupMail = $mail; + last; + } + } + + $groups->{$groupADName}->{$GROUP_MAIL_TEXT} = $groupMail; foreach my $memberId($data->getMemberIdsForResourceAndGroup( resource => $resourceId, group => $groupId )) { processGroupMember $memberId, $groupId, $resourceId, $groupADName; @@ -361,7 +375,7 @@ sub processGroupMember { my $UPN = $users->{$UCO}->{$UPN_TEXT}; my $sendAsGroup = $data->getMemberGroupAttributeValue( member => $memberId, group => $groupId, attrName => $A_MG_O365_SEND_AS ); - if($sendAsGroup) { $groups->{$groupADName}->{$UPN} = 1; } + if($sendAsGroup) { $groups->{$groupADName}->{$GROUP_CONTACTS_TEXT}->{$UPN} = 1; } } # input: file name for users data, usersData structure @@ -394,9 +408,10 @@ sub saveGroupsToFile { binmode FILE, ":utf8"; foreach my $adName (sort keys %$groupsData) { - my $contacts = join " ", sort keys %{$groupsData->{$adName}}; + my $groupMail = $groupsData->{$adName}->{$GROUP_MAIL_TEXT}; + my $contacts = join " ", sort keys %{$groupsData->{$adName}->{$GROUP_CONTACTS_TEXT}}; unless($contacts) { $contacts = ""; } - print FILE $adName . "\t" . $contacts . "\n"; + print FILE $adName . "\t" . $contacts . "\t" . $groupMail . "\n"; } close(FILE) or die "Cannot close $fileName: $! \n"; diff --git a/send/VsupIfis.pm b/send/VsupIfis.pm index 45af03f7..bb79e2b4 100755 --- a/send/VsupIfis.pm +++ b/send/VsupIfis.pm @@ -1,7 +1,7 @@ package VsupIfis; use Exporter 'import'; @ISA = ('Exporter'); -@EXPORT = qw(load_kos load_vema load_dc2); +@EXPORT = qw(load_kos load_vema load_dc2 load_is); use strict; use warnings FATAL => 'all'; @@ -42,12 +42,12 @@ sub init_config($) { } # -# Load map of users relations from KOS +# Load map of users relations from IS # Require params: $hostname, $port, $db_name, $db_user, $db_password # -sub load_kos() { +sub load_is() { - my $config = init_config("kos.conf"); + my $config = init_config("is.conf"); my $hostname = $config->{"hostname"}; my $port = $config->{"port"}; @@ -55,30 +55,30 @@ sub load_kos() { my $db_user = $config->{"username"}; my $db_password = $config->{"password"}; - my $dbh = DBI->connect("dbi:Oracle://$hostname:$port/$db_name", $db_user, $db_password,{ RaiseError=>1, AutoCommit=>0, LongReadLen=>65536, ora_charset => 'AL32UTF8'}) or die "Connect to database $db_name Error!\n"; - $dbh->do("alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'"); + my $dbh = DBI->connect("dbi:Pg:dbname=$db_name;host=$hostname;port=$port", $db_user, $db_password,{ RaiseError=>1, AutoCommit=>0 }) or die "Connect to database $db_name Error!\n"; - # Select query for input database (KOS) - all students with UCO not null and DO_ >= now or null - my $sth = $dbh->prepare(qq{select case when OSB_ID=UCO then null else UCO end as UCO, NS, 'STU' as TYP_VZTAHU, STUD_FORMA as DRUH_VZTAHU, ID_STUDIA as VZTAH_CISLO, STUD_FORMA as STU_FORMA, STUD_STAV as STUD_STAV, STUD_TYP as STU_PROGR, OD, DO_, KARTA_LIC as KARTA_IDENT from SIS2IDM_STUDIA where (case when OSB_ID=UCO then null else UCO end) is not null and (DO_ >= TRUNC(SYSDATE) OR DO_ is NULL)}); + # Select query for input database (IS) - all students with UCO_PERUN not null and STUD_DO >= now or null + my $sth = $dbh->prepare(qq{select distinct ex_is2idm_studia.UCO_PERUN as UCO, NS, 'STU' as TYP_VZTAHU, STUD_FORMA as DRUH_VZTAHU, ex_is2idm_studia.ID_STUDIA as VZTAH_CISLO, STUD_FORMA as STU_FORMA, STUD_STAV as STUD_STAV, STUD_TYP as STU_PROGR, STUD_OD, STUD_DO, KARTA_LIC as KARTA_IDENT from ex_is2idm_studia left join ex_is2idm_adresy on ex_is2idm_studia.ID_STUDIA=ex_is2idm_adresy.ID_STUDIA where ex_is2idm_studia.UCO_PERUN is not null and (STUD_DO >= CURRENT_DATE OR STUD_DO is NULL)}); $sth->execute(); - # Structure to store data from input database (KOS) + # Structure to store data from input database (IS) my $inputData = {}; while(my $row = $sth->fetchrow_hashref()) { - my $key = $row->{VZTAH_CISLO}; - $inputData->{$key}->{'OSB_ID'} = $row->{UCO}; - $inputData->{$key}->{'TYP_VZTAHU'} = $row->{TYP_VZTAHU}; - $inputData->{$key}->{'DRUH_VZTAHU'} = $row->{DRUH_VZTAHU}; - $inputData->{$key}->{'STU_FORMA'} = $row->{STU_FORMA}; - $inputData->{$key}->{'STUD_STAV'} = $row->{STUD_STAV}; - $inputData->{$key}->{'STU_PROGR'} = $row->{STU_PROGR}; - $inputData->{$key}->{'NS'} = $row->{NS}; - $inputData->{$key}->{'VZTAH_OD'} = $row->{OD}; - $inputData->{$key}->{'VZTAH_DO'} = $row->{DO_}; - $inputData->{$key}->{'KARTA_IDENT'} = $row->{KARTA_IDENT}; + # disregarding the select Postgres is using lower-cased column names. + my $key = $row->{vztah_cislo}; + $inputData->{$key}->{'OSB_ID'} = $row->{uco}; + $inputData->{$key}->{'TYP_VZTAHU'} = $row->{typ_vztahu}; + $inputData->{$key}->{'DRUH_VZTAHU'} = $row->{druh_vztahu}; + $inputData->{$key}->{'STU_FORMA'} = $row->{stu_forma}; + $inputData->{$key}->{'STUD_STAV'} = $row->{stud_stav}; + $inputData->{$key}->{'STU_PROGR'} = $row->{stu_progr}; + $inputData->{$key}->{'NS'} = $row->{ns}; + $inputData->{$key}->{'VZTAH_OD'} = $row->{stud_od}; + $inputData->{$key}->{'VZTAH_DO'} = $row->{stud_do}; + $inputData->{$key}->{'KARTA_IDENT'} = $row->{karta_ident}; } - # Disconnect from input database (KOS) + # Disconnect from input database (IS) $dbh->disconnect(); return $inputData; @@ -132,6 +132,50 @@ sub load_dc2() { } +# +# Load map of users relations from KOS +# Require params: $hostname, $port, $db_name, $db_user, $db_password +# +sub load_kos() { + + my $config = init_config("kos.conf"); + + my $hostname = $config->{"hostname"}; + my $port = $config->{"port"}; + my $db_name = $config->{"db_name"}; + my $db_user = $config->{"username"}; + my $db_password = $config->{"password"}; + + my $dbh = DBI->connect("dbi:Oracle://$hostname:$port/$db_name", $db_user, $db_password,{ RaiseError=>1, AutoCommit=>0, LongReadLen=>65536, ora_charset => 'AL32UTF8'}) or die "Connect to database $db_name Error!\n"; + $dbh->do("alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'"); + + # Select query for input database (KOS) - all students with UCO not null and DO_ >= now or null + my $sth = $dbh->prepare(qq{select case when OSB_ID=UCO then null else UCO end as UCO, NS, 'STU' as TYP_VZTAHU, STUD_FORMA as DRUH_VZTAHU, ID_STUDIA as VZTAH_CISLO, STUD_FORMA as STU_FORMA, STUD_STAV as STUD_STAV, STUD_TYP as STU_PROGR, OD, DO_, KARTA_LIC as KARTA_IDENT from SIS2IDM_STUDIA where (case when OSB_ID=UCO then null else UCO end) is not null and (DO_ >= TRUNC(SYSDATE) OR DO_ is NULL)}); + $sth->execute(); + + # Structure to store data from input database (KOS) + my $inputData = {}; + while(my $row = $sth->fetchrow_hashref()) { + my $key = $row->{VZTAH_CISLO}; + $inputData->{$key}->{'OSB_ID'} = $row->{UCO}; + $inputData->{$key}->{'TYP_VZTAHU'} = $row->{TYP_VZTAHU}; + $inputData->{$key}->{'DRUH_VZTAHU'} = $row->{DRUH_VZTAHU}; + $inputData->{$key}->{'STU_FORMA'} = $row->{STU_FORMA}; + $inputData->{$key}->{'STUD_STAV'} = $row->{STUD_STAV}; + $inputData->{$key}->{'STU_PROGR'} = $row->{STU_PROGR}; + $inputData->{$key}->{'NS'} = $row->{NS}; + $inputData->{$key}->{'VZTAH_OD'} = $row->{OD}; + $inputData->{$key}->{'VZTAH_DO'} = $row->{DO_}; + $inputData->{$key}->{'KARTA_IDENT'} = $row->{KARTA_IDENT}; + } + + # Disconnect from input database (KOS) + $dbh->disconnect(); + + return $inputData; + +} + # # Load map of users relations from VEMA # diff --git a/send/o365_mu_process.pl b/send/o365_mu_process.pl index 8d0dd781..8e52da07 100755 --- a/send/o365_mu_process.pl +++ b/send/o365_mu_process.pl @@ -64,6 +64,7 @@ my $PLAIN_TEXT_OBJECT_TEXT = "plainTextObject"; my $AD_GROUP_NAME_TEXT = "groupName"; my $SEND_AS_TEXT = "sendAs"; +my $GROUP_MAIL_TEXT = "groupMail"; my $COMMAND_TEXT = "command"; my $PARAMETERS_TEXT = "parameters"; @@ -504,6 +505,8 @@ sub readDataAboutGroups { my $groupADName = $parts[0]; my @emails = (); if($parts[1]) { @emails = split / /, $parts[1]; } + my $groupMail = ""; + if($parts[2]) { $groupMail = $parts[2]; } #If groupADName is from any reason empty, set global return code to 1 and skip this group unless($line) { @@ -514,6 +517,7 @@ sub readDataAboutGroups { $groupsStruc->{$groupADName}->{$AD_GROUP_NAME_TEXT} = $groupADName; $groupsStruc->{$groupADName}->{$SEND_AS_TEXT} = \@emails; + $groupsStruc->{$groupADName}->{$GROUP_MAIL_TEXT} = $groupMail; $groupsStruc->{$groupADName}->{$PLAIN_TEXT_OBJECT_TEXT} = $line; } close FILE or die "ERROR - Could not close file $pathToFile: $!\n"; @@ -596,6 +600,7 @@ sub getGroupsContent { my $group = {}; $group->{$AD_GROUP_NAME_TEXT} = $key; $group->{$SEND_AS_TEXT} = $groupToProcess->{$SEND_AS_TEXT}; + $group->{$GROUP_MAIL_TEXT} = $groupToProcess->{$GROUP_MAIL_TEXT}; push @parameters, $group; } diff --git a/send/vsup_ifis b/send/vsup_ifis index e49eafa5..9807251c 100755 --- a/send/vsup_ifis +++ b/send/vsup_ifis @@ -12,6 +12,7 @@ binmode STDOUT, ":utf8"; sub handleContact; sub handleAkt; +sub appendParam; my $username; my $password; @@ -494,43 +495,14 @@ foreach my $key (sort keys %$dc2_data) { if($personExists->fetch) { if($DEBUG == 1) { print "FIND: UCO -> $OSB_ID, VZTAH_ID -> $VZTAH_CISLO\n"; } - #Generate proper select on NULLs - my $select = "SELECT 1 from $tableNameVzt where OSB_ID=? and VZTAH_CISLO=? and EXT_ID=? and TYP_VZTAHU=? and NS"; + my $select = "SELECT 1 from $tableNameVzt where OSB_ID=? and VZTAH_CISLO=? and EXT_ID=? and TYP_VZTAHU=?"; my @params = ($OSB_ID, $VZTAH_CISLO, $EXT_ID, $TYP_VZTAHU); - if (defined($NS)) { - $select = $select . "=?"; - push(@params, $NS); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and DRUH_VZTAHU"; - if (defined($DRUH_VZTAHU)) { - $select = $select . "=?"; - push(@params, $DRUH_VZTAHU); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and OD"; - if (defined($VZTAH_OD)) { - $select = $select . "=?"; - push(@params, $VZTAH_OD); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and DO_"; - if (defined($VZTAH_DO)) { - $select = $select . "=?"; - push(@params, $VZTAH_DO); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and KARTA_IDENT"; - if (defined($KARTA_IDENT)) { - $select = $select . "=?"; - push(@params, $KARTA_IDENT); - } else { - $select = $select . " is NULL"; - } + + $select = appendParam(select => $select, params => \@params, paramName => 'NS', paramValue => $NS); + $select = appendParam(select => $select, params => \@params, paramName => 'DRUH_VZTAHU', paramValue => $DRUH_VZTAHU); + $select = appendParam(select => $select, params => \@params, paramName => 'OD', paramValue => $VZTAH_OD); + $select = appendParam(select => $select, params => \@params, paramName => 'DO_', paramValue => $VZTAH_DO); + $select = appendParam(select => $select, params => \@params, paramName => 'KARTA_IDENT', paramValue => $KARTA_IDENT); # We need to know if these two records are without changes, if yes, skip them my $recordAreEquals = $dbh->prepare($select); @@ -623,64 +595,17 @@ foreach my $key (sort keys %$kos_data) { if($personExists->fetch) { if($DEBUG == 1) { print "FIND: UCO -> $OSB_ID, VZTAH_ID -> $VZTAH_CISLO\n"; } - #Generate proper select on NULLs - my $select = "SELECT 1 from $tableNameVzt where OSB_ID=? and VZTAH_CISLO=? and EXT_ID=? and TYP_VZTAHU=? and NS"; + my $select = "SELECT 1 from $tableNameVzt where OSB_ID=? and VZTAH_CISLO=? and EXT_ID=? and TYP_VZTAHU=?"; my @params = ($OSB_ID, $VZTAH_CISLO, $EXT_ID, $TYP_VZTAHU); - if (defined($NS)) { - $select = $select . "=?"; - push(@params, $NS); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and DRUH_VZTAHU"; - if (defined($DRUH_VZTAHU)) { - $select = $select . "=?"; - push(@params, $DRUH_VZTAHU); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and STU_FORMA"; - if (defined($STU_FORMA)) { - $select = $select . "=?"; - push(@params, $STU_FORMA); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and STUD_STAV"; - if (defined($STUD_STAV)) { - $select = $select . "=?"; - push(@params, $STUD_STAV); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and STU_PROGR"; - if (defined($STU_PROGR)) { - $select = $select . "=?"; - push(@params, $STU_PROGR); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and OD"; - if (defined($VZTAH_OD)) { - $select = $select . "=?"; - push(@params, $VZTAH_OD); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and DO_"; - if (defined($VZTAH_DO)) { - $select = $select . "=?"; - push(@params, $VZTAH_DO); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and KARTA_IDENT"; - if (defined($KARTA_IDENT)) { - $select = $select . "=?"; - push(@params, $KARTA_IDENT); - } else { - $select = $select . " is NULL"; - } + + $select = appendParam(select => $select, params => \@params, paramName => 'NS', paramValue => $NS); + $select = appendParam(select => $select, params => \@params, paramName => 'DRUH_VZTAHU', paramValue => $DRUH_VZTAHU); + $select = appendParam(select => $select, params => \@params, paramName => 'STU_FORMA', paramValue => $STU_FORMA); + $select = appendParam(select => $select, params => \@params, paramName => 'STUD_STAV', paramValue => $STUD_STAV); + $select = appendParam(select => $select, params => \@params, paramName => 'STU_PROGR', paramValue => $STU_PROGR); + $select = appendParam(select => $select, params => \@params, paramName => 'OD', paramValue => $VZTAH_OD); + $select = appendParam(select => $select, params => \@params, paramName => 'DO_', paramValue => $VZTAH_DO); + $select = appendParam(select => $select, params => \@params, paramName => 'KARTA_IDENT', paramValue => $KARTA_IDENT); # We need to know if these two records are without changes, if yes, skip them my $recordAreEquals = $dbh->prepare($select); @@ -1043,3 +968,25 @@ sub handleAkt() { } } + +# +# Appends PARAM with respecting to possible NULL to select +# +sub appendParam() { + + my %args = @_; + my $select = $args{select}; + my $paramsRef = $args{params}; + my $paramName = $args{paramName}; + my $paramValue = $args{paramValue}; + + if (defined($paramValue)) { + $select = $select . " and $paramName=?"; + push(@$paramsRef, $paramValue); + } else { + $select = $select . " and $paramName is NULL"; + } + + return $select; + +} diff --git a/send/vsup_web b/send/vsup_web index ad485423..2e84ae7d 100755 --- a/send/vsup_web +++ b/send/vsup_web @@ -8,6 +8,8 @@ use Encode qw(encode); use ScriptLock; binmode STDOUT, ":utf8"; +sub appendParam; + my $username; my $password; my $tableName = 'IDM2WEB_OSOBY'; @@ -110,71 +112,18 @@ foreach my $uco (sort keys %$dataByUco) { if($DEBUG == 1) { print "FIND: $uco\n"; } # generate proper select on NULLs - my $select = "SELECT 1 from $tableName where UCO=? and LOGIN=? and EMAIL_SKOLNI=? and TITUL_PRED"; + my $select = "SELECT 1 from $tableName where UCO=? and LOGIN=? and EMAIL_SKOLNI=?"; my @params = ($uco, $LOGIN, $EMAIL); - if ($TITLE_BEFORE) { - $select = $select . "=?"; - push(@params, $TITLE_BEFORE); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and JMENO"; - if ($FIRST_NAME) { - $select = $select . "=?"; - push(@params, $FIRST_NAME); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and PRIJMENI"; - if ($LAST_NAME) { - $select = $select . "=?"; - push(@params, $LAST_NAME); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and TITUL_ZA"; - if ($TITLE_AFTER) { - $select = $select . "=?"; - push(@params, $TITLE_AFTER); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and TEL_PRAC_LINKA"; - if ($PHONE) { - $select = $select . "=?"; - push(@params, $PHONE); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and TEL_PRAC_MOB"; - if ($MOBILE) { - $select = $select . "=?"; - push(@params, $MOBILE); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and EMAIL_SOUKR"; - if ($EMAIL_PRIV) { - $select = $select . "=?"; - push(@params, $EMAIL_PRIV); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and TEL_SOUKR"; - if ($PHONE_PRIV) { - $select = $select . "=?"; - push(@params, $PHONE_PRIV); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and FOTO"; - if ($FOTO) { - $select = $select . "=?"; - push(@params, $FOTO); - } else { - $select = $select . " is NULL"; - } - $select = $select . ";"; + + $select = appendParam(select => $select, params => \@params, paramName => 'TITUL_PRED', paramValue => $TITLE_BEFORE); + $select = appendParam(select => $select, params => \@params, paramName => 'JMENO', paramValue => $FIRST_NAME); + $select = appendParam(select => $select, params => \@params, paramName => 'PRIJMENI', paramValue => $LAST_NAME); + $select = appendParam(select => $select, params => \@params, paramName => 'TITUL_ZA', paramValue => $TITLE_AFTER); + $select = appendParam(select => $select, params => \@params, paramName => 'TEL_PRAC_LINKA', paramValue => $PHONE); + $select = appendParam(select => $select, params => \@params, paramName => 'TEL_PRAC_MOB', paramValue => $MOBILE); + $select = appendParam(select => $select, params => \@params, paramName => 'EMAIL_SOUKR', paramValue => $EMAIL_PRIV); + $select = appendParam(select => $select, params => \@params, paramName => 'TEL_SOUKR', paramValue => $PHONE_PRIV); + $select = appendParam(select => $select, params => \@params, paramName => 'FOTO', paramValue => $FOTO); #we need to know if these two records are without changes, if yes, skip them my $recordAreEquals = $dbh->prepare($select); @@ -222,6 +171,7 @@ open FILE, $service_file_cao or die "Could not open $service_file_cao: $!"; while(my $line = ) { my @parts = split /\t/, $line; + chomp(@parts); my $UCO = (($parts[0] ne '') ? $parts[0] : undef); my $CAO_ORGAN = (($parts[1] ne '') ? $parts[1] : undef); @@ -258,7 +208,7 @@ close FILE; # Delete removed CAOs ##### -# delete completly removed people from CAO +# delete completely removed people from CAO my @keptUcos = sort keys %{$cao}; my $elements = join(',',@keptUcos); if($DEBUG == 1) { print "DELETED NOT IN ($elements)\n"; } @@ -299,6 +249,7 @@ open FILE, $service_file_ext or die "Could not open $service_file_ext: $!"; while(my $line = ) { my @parts = split /\t/, $line; + chomp(@parts); my $UCO = (($parts[0] ne '') ? $parts[0] : undef); my $VZTAH_ID = (($parts[1] ne '') ? $parts[1] : undef); @@ -317,28 +268,11 @@ while(my $line = ) { if($extExist->fetch) { if($DEBUG == 1) { print "FIND: $UCO\n"; } - my $select = "SELECT 1 from $tableName_ext where UCO=? and VZTAH_ID=? and VZTAH_TYP=? and ZAM_FUNKCE_NAZEV"; + my $select = "SELECT 1 from $tableName_ext where UCO=? and VZTAH_ID=? and VZTAH_TYP=?"; my @params = ($UCO, $VZTAH_ID, $VZTAH_TYP); - if ($ZAM_FCE_NAZ) { - $select = $select . "=?"; - push(@params, $ZAM_FCE_NAZ); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and ZAM_FUNKCE_CISLO"; - if ($ZAM_FCE_CIS) { - $select = $select . "=?"; - push(@params, $ZAM_FCE_CIS); - } else { - $select = $select . " is NULL"; - } - $select = $select . " and NS"; - if ($NS) { - $select = $select . "=?"; - push(@params, $NS); - } else { - $select = $select . " is NULL"; - } + $select = appendParam(select => $select, params => \@params, paramName => 'ZAM_FUNKCE_NAZEV', paramValue => $ZAM_FCE_NAZ); + $select = appendParam(select => $select, params => \@params, paramName => 'ZAM_FUNKCE_CISLO', paramValue => $ZAM_FCE_CIS); + $select = appendParam(select => $select, params => \@params, paramName => 'NS', paramValue => $NS); my $recordAreEquals = $dbh->prepare($select); $recordAreEquals->execute(@params); @@ -593,3 +527,25 @@ print "Deleted users:\t$deletedUsers\n"; print "=======================================\n"; $lock->unlock(); + +# +# Appends PARAM with respecting to possible NULL to select +# +sub appendParam() { + + my %args = @_; + my $select = $args{select}; + my $paramsRef = $args{params}; + my $paramName = $args{paramName}; + my $paramValue = $args{paramValue}; + + if (defined($paramValue)) { + $select = $select . " and $paramName=?"; + push(@$paramsRef, $paramValue); + } else { + $select = $select . " and $paramName is NULL"; + } + + return $select; + +}