pica.php File Reference

Submit an applicant's record to PICA. More...

Go to the source code of this file.

Functions

 export_to_pica ($dblink, $id, $barcode)
 perform the transfer of a record to the PICA database
 check_registration_number ($regnum)
 check a registration number for validity
 check_for_doubles ($dblink, $id)
 avoid double membership


Detailed Description

Submit an applicant's record to PICA.

These functions perform the transfer of an applicant's record in the MySQL database into the PICA system, using the PICA tool 'ousp_upd_borrower'. They also provide some safety catches (e.g. checking for conflicts with existing PICA records).

See also:
PICA documentation (OUS_F docu, chap. 6.3)

Definition in file pica.php.


Function Documentation

check_for_doubles ( dblink,
id 
)

avoid double membership

Parameters:
$dblink open handle to MySQL database
$id record number of user in MySQL database
This function performs a PICA database query to find pre-existing PICA records similar to the applicants'. Records are considered similar if the last name and the date of birth match.

Returns:
a list of PICA records that are similar to the applicant's record, or FALSE if a database error occurs.
We expect the applicant not to be a library user yet, so this function should return an empty list.

Definition at line 255 of file pica.php.

References $fields, $id, $q, $r, db_query_mysql(), and error_msg().

00255                                           {
00256 global $fields;
00257 
00258 global $LBSServer;
00259 global $LBSDB;
00260 global $LBSUser;
00261 global $LBSPw;
00262 global $iln;
00263 
00264 
00265 $birthday = "0000-00-00";
00266 
00267 $q =  $fields["last_name"]["query"];
00268 $r = db_query_mysql($dblink, $q, array('@id@' => $id));
00269 
00270 $name = (isset($r[1][0])) ? $r[1][0] : "";
00271 
00272 $q =  $fields["birthday"]["query"];
00273 $r = db_query_mysql($dblink, $q, array('@id@' => $id));
00274 
00275 $birthday = (isset($r[1][0])) ? $r[1][0] : "";
00276 
00277 if (empty($name) or empty($birthday))
00278         return FALSE;
00279 
00280 list ($year,$month,$day)  = split('-', $birthday);
00281 
00282 
00283 $months_by_name = array (
00284         "01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr",
00285         "05" => "May", "06" => "Jun", "07" => "Jul", "08" => "Aug",
00286         "09" => "Sep", "10" => "Oct", "11" => "Nov", "12" => "Dec" );
00287 
00288 $users = array();
00289 
00290 ($lnk = @ sybase_pconnect($LBSServer,$LBSUser,$LBSPw)) or error_msg("SYBASE: pconnect failed");
00291 
00292 (@ sybase_select_db($LBSDB,$lnk)) or error_msg("SYBASE: database $LBSDB not found");
00293 
00294 
00295 // extract last name
00296 
00297 $users = array();
00298 
00299 $q = "select name,first_name_initials_prefix,gender,date_of_birth," . 
00300      "borrower_bar,borrower_status from borrower where " .  
00301      "LOWER(name) LIKE '%@name@%' and " .
00302      "date_of_birth = '@birth@' and iln = $iln";
00303 
00304 $birth = $months_by_name[$month] . " " . $day . " " . $year;
00305 $names = explode(" ", $name);
00306 $name  = $names[count($names) - 1];
00307 $name = strtr($name, array( "'" => "''", "%" => "" ));
00308 
00309 // umlaut translation
00310 $name = strtolower(strtr($name,"ÄÖÜäöüß", "_______"));
00311 
00312 $q = strtr($q, array( "@name@" => $name, "@birth@" => $birth ));
00313 
00314 ( $erg = sybase_query($q, $lnk) ) or error_msg("SYBASE: database query failed");
00315 
00316 
00317 if ($erg) {
00318      $i = 0;
00319         
00320       while ($row = sybase_fetch_array($erg)) {
00321 
00322                 // umlaut back-translation
00323 
00324                 $row["name"] = strtr($row["name"],
00325                                      "\301\302\303\321\322\323\276",
00326                                      "ÄÖÜäöüß"
00327                                 );
00328                 $row["first_name_initials_prefix"] = strtr(
00329                                      $row["first_name_initials_prefix"],
00330                                      "\301\302\303\321\322\323\276",
00331                                      "ÄÖÜäöüß"
00332                                  );
00333 
00334                 $users[$i] = $row;
00335                 $i++;
00336       }
00337 }
00338 
00339 
00340 sybase_close($lnk);
00341 
00342 return $users;
00343 }

Here is the call graph for this function:

check_registration_number ( regnum  ) 

check a registration number for validity

Parameters:
$regnum registration number
The registration number is a field in a PICA user record.

It is mandatory that the registration number of a new PICA record be chosen unique, because the PICA tool 'ousp_upd_borrower' uses this field as a primary key.

If a pre-existing PICA record has the same registration number as the new one, the old record will be overwritten. This must be avoided.

This function verifies that the chosen registration number is indeed unique by performing query a on the PICA database.

Returns:
TRUE if the registration number is unique (i.e. usable), and FALSE if it is not unique or the database query failed for some reason

Definition at line 214 of file pica.php.

References $q, $res, and error_msg().

Referenced by export_to_pica().

00214                                              {
00215 
00216 global $LBSServer;
00217 global $LBSDB;
00218 global $LBSUser;
00219 global $LBSPw;
00220 global $iln;
00221 
00222 ($lnk = @ sybase_pconnect($LBSServer,$LBSUser,$LBSPw)) or error_msg("SYBASE: pconnect failed");
00223 
00224 (@ sybase_select_db($LBSDB,$lnk)) or error_msg("SYBASE: database $LBSDB not found");
00225 
00226 $q = "select * from borrower where " . "registration_number = '@regnum@' and iln = $iln";
00227 // . "registration_number = '@regnum@'";
00228 
00229 
00230 $regnum = strtr($regnum, array( "'" => "''", "%" => "" ));
00231 $q = strtr($q, array( "@regnum@" => $regnum));
00232 
00233 // print $q;
00234 
00235 ( $res = sybase_query($q, $lnk) ) or error_msg("SYBASE: database query failed");
00236 
00237 return (($res) and (sybase_num_rows($res) > 0)) ? FALSE : TRUE;
00238 }

Here is the call graph for this function:

Here is the caller graph for this function:

export_to_pica ( dblink,
id,
barcode 
)

perform the transfer of a record to the PICA database

Parameters:
$dblink open handle to MySQL database
$id record number to be transferred
Returns:
TRUE if the transfer was successful, FALSE otherwise
Warning:
This function does not check whether the new user is actually an old user who already has a PICA account. If you want to check this, call check_for_doubles() before calling this function.

Definition at line 33 of file pica.php.

References $f, $fields, $id, $kw, $q, $r, $text, $v, check_registration_number(), db_query_mysql(), error_msg(), print, print_footer(), and print_header().

00033                                                 {
00034         global $text;
00035         global $fields;
00036         global $iln;
00037         global $pica_export_command;
00038 
00039 // default values 
00040 
00041         $pica = array(
00042                 "a000" => $iln,         // ILN
00043                 "a100" => "U",          // Update       
00044                 "a104" => "0",          // user status (loan allowed)
00045                 "a111" => "1",          // Nummer der Mahnadresse
00046                 "a200" => "U",          // Update
00047                 "a201" => "001",        // Abteilungsgruppen-Nummer
00048                 "a300" => "U",          // Update
00049                 "a301" => "1",          // 1: extern, 0: intern
00050                 "b400" => "U"           // Update
00051         ); 
00052 
00053 // query database, assign results to $pica[] array
00054 
00055         foreach ($fields as $f) {
00056 
00057                 $q = (isset($f["pica_query"])) ? $f["pica_query"] : $f["query"];
00058                 $r = db_query_mysql($dblink, $q, array("@id@" => $id));
00059 
00060                 $k = (isset($f["pica_field"])) ? $f["pica_field"] : "" ;
00061 
00062                 if ((!empty($k)) and (!empty($r)))  
00063                         $pica[$k] .=  $r[1][0] . " ";
00064         }
00065 
00066 // strip trailing blanks
00067 
00068         foreach ($fields as $f) {
00069                 $k = (isset($f["pica_field"])) ? $f["pica_field"] : "" ;
00070                 if (!empty($k))
00071                         $pica[$k] = preg_replace("/ $/","", $pica[$k]);
00072         }
00073 
00074 // do postprocessing
00075 
00076 // date of creation
00077         $pica["a001"] = strftime('%d-%m-%Y');   
00078 
00079 // barcode
00080 
00081         if (!empty($barcode))
00082                 $pica["a102"] = $barcode;
00083 
00084 // create serial number
00085 
00086         if (!isset($pica["a114"]) or ($pica["a114"] == "")) {
00087                 $qs = array(
00088                         "lock tables serial_number write ", 
00089                         "update serial_number set number=0, " .
00090                         " time=CURDATE() where YEAR(time) != YEAR(CURDATE()) ",
00091                         " update serial_number set number=number+1 ",
00092                         " select DATE_FORMAT(time,'%y'), number " . 
00093                         " from serial_number "
00094                 );
00095 
00096                 foreach ($qs as $q) 
00097                         $r = db_query_mysql($dblink,$q, array());
00098 
00099                 if (!empty($r))   {
00100                         $pica["a114"]  = $r[1][0] . '/' . $r[1][1];
00101                 }
00102 
00103                 db_query_mysql($dblink,"unlock tables", array());
00104 
00105         }
00106 
00107 
00108 // fix registration number (student id, or Nota Bene ID) 
00109 
00110         $q = $fields["usertype"]["query"];
00111         $r = db_query_mysql($dblink, $q, array('@id@' => $id));
00112 
00113         if (!empty($r))   {
00114                 $usertype = $r[1][0];
00115 
00116                 if ($usertype == 2)
00117                         $pica["a101"] = "FH" . $pica["a101"]; 
00118                 else if ($usertype == 3)
00119                         $pica["a101"] = "HBK" . $pica["a101"]; 
00120                 else if ($usertype >= 4)
00121                         $pica["a101"] = "NB" . 
00122                                 strtr($pica["a114"],array( "/" => "" )) ; 
00123         }
00124 
00125 // check reg no
00126 
00127 if (!check_registration_number($pica["a101"])) {
00128         $kw = array ( 
00129                 '@notabene@' => "",  
00130                 '@bodyattr@' => "",
00131                 '@url-de@' => "index.php?lang=de", 
00132                 '@url-en@' => "index.php?lang=en",
00133                 '@regno@' => $pica['a101']); 
00134 
00135         print_header($kw);
00136         print strtr($text['conflict_regno'],$kw);
00137         print_footer($kw);
00138         exit(0);
00139 }
00140 
00141 // write serial number into database
00142 
00143 $q = $fields["notabene"]["update"];
00144 $kw = array( '@id@' => $id, '@val@' => $pica["a114"]);
00145 
00146 db_query_mysql($dblink, $q, $kw);
00147 
00148 
00149 // determine whether we've got a second address
00150 // create header if necessary
00151 
00152         $second_address = FALSE;
00153 
00154         foreach ( $pica as $k => $v ) {
00155                 if (strpos($k,"b3") === 0 and ($v != "") )  {
00156                         $second_address = TRUE;
00157                 }
00158         }
00159 
00160         if ($second_address) {
00161                 $pica["b300"] = "U";
00162                 $pica["b301"] = "2";
00163         }
00164 
00165 // create export file
00166 
00167         ksort($pica);           // sort by key
00168         reset($pica);
00169 
00170         $export = "";
00171 
00172         foreach ($pica as $k => $v) {
00173                 $k = preg_replace("/^[a-zA-Z]/", "", $k);
00174                 if ($v != "")
00175                         $export .= "$k $v\n";
00176         }
00177 
00178 
00179 // do character translation for german umlauts
00180 
00181         $export = strtr($export,"ÄÖÜäöüß", "\301\302\303\321\322\323\276");
00182                 
00183 // run export command
00184 
00185 // print "<pre>$export</pre>";
00186         ($handle = popen($pica_export_command, "w")) or 
00187                 error_msg("could not run command: $pica_export_command");
00188         fwrite($handle, $export) or error_msg("pipe broken");   
00189         return pclose($handle); 
00190 }

Here is the call graph for this function:


Generated on Mon Aug 28 09:46:10 2006 for anmeldung by  doxygen 1.4.7