00001 <?php
00002
00003
00004
00005
00006
00007
00040
00041 require_once ('config.php');
00042 require_once ('../util.php');
00043 require_once ('../fields.php');
00044 require_once ('pica.php');
00045 require_once ('../text.php');
00046
00047 session_start();
00048
00049
00050
00051 $lang = (isset($_REQUEST['lang'])) ? $_REQUEST['lang'] : $lang_default;
00052
00053 if (!isset($text_multi[$lang]))
00054 $lang = $lang_default;
00055
00056 $text = $text_multi[$lang];
00057 $buttons = $buttons_multi[$lang];
00058 $months = $months_multi[$lang];
00059
00060
00061
00062
00063
00064
00065 $valid_params = array(
00066 "action" => "/^(show|edit|delete|submit|submit-check|print)$/",
00067 "button" => "/^(" . $buttons['ok'] . "|" .
00068 $buttons['cancel'] . "|" .
00069 $buttons['goto_index'] . "|" .
00070 $buttons['submit'] . "|" .
00071 $buttons['print'] . "|" .
00072 $buttons['edit'] . "|" .
00073 $buttons['delete'] . "|)$/",
00074 "id" => "/^[0-9]*$/",
00075 "lang" => "/^(de|en|)$/",
00076 "barcode" => "/^[0-9]*[0-9xX]$/"
00077 );
00078
00079
00080
00081 $default_params = array(
00082 "action" => "show",
00083 "id" => "",
00084 "button" => "",
00085 "lang" => $lang_default,
00086 "barcode" => ""
00087 );
00088
00089
00090
00091 foreach ($default_params as $k => $v) {
00092 if (!isset($_SESSION[$k]))
00093 $_SESSION[$k] = $v;
00094 }
00095
00096 foreach ($_GET as $k => $v) {
00097
00098
00099
00100 if (param_ok($valid_params, $k, $v))
00101 $_SESSION[$k] = $v;
00102 }
00103
00104
00105
00106 ($link = mysql_pconnect($dbhost, $dbuser, $dbpass)) or db_error_mysql();
00107 mysql_select_db($dbname,$link) or db_error_mysql();
00108
00109 fields_init($link, $lang);
00110
00111
00112
00113 $q = "select * from persons where id='@id@'";
00114
00115 $r = db_query_mysql($link, $q, array('@id@' => $_SESSION['id']));
00116
00117 if (empty($r)) {
00118 redirect("index.php?lang=$lang");
00119 }
00120
00121 $status = $r[1]["status"];
00122
00123
00124
00125
00126
00127
00128
00129
00130 $f = $_SESSION["field"];
00131
00132 if ($_SESSION["button"] == $buttons["edit"] and ($status == "new")) {
00133
00134 $id = $_SESSION['id'];
00135
00136
00137
00138 $cancel = "admin/action.php?lang=@lang@&id=$id&action=show";
00139 $finish = "admin/action.php?lang=@lang@&id=$id&action=edit";
00140
00141
00142
00143 foreach ($_SESSION as $k => $v ) {
00144 unset($_SESSION[$k]);
00145 }
00146
00147
00148
00149 $_SESSION['cancelURL'] = $cancel;
00150 $_SESSION['finishURL'] = $finish;
00151
00152 foreach ($fields as $k => $v ) {
00153
00154 $q = $v['query'];
00155 $r = db_query_mysql($link, $q,
00156 array('@id@' => $id));
00157
00158 $_SESSION[$k] = (isset($r[1][0])) ? $r[1][0] : "";
00159
00160
00161 }
00162
00163 redirect("../edit.php?lang=$lang");
00164 }
00165
00166 if (($_SESSION["action"] == "edit") and isset($_SESSION['edit_finished'])) {
00167
00168
00169
00170 $kw = array();
00171
00172 foreach ( $fields as $k => $v) {
00173 if (isset($_SESSION[$k]))
00174 $kw[ '@' . $k . '@'] = $_SESSION[$k];
00175 }
00176
00177 $kw['@id@'] = $_SESSION['id'];
00178
00179
00180
00181 $q = "update persons set last_name='@last_name@', " .
00182 "first_name='@first_name@', title='@title@', sex='@sex@', " .
00183 "birthday='@birthday@', usertype_id='@usertype@', " .
00184 "student_id='@student_id@' where id=@id@";
00185
00186 db_query_mysql($link,$q,$kw);
00187
00188 $q = "UPDATE addresses SET carry_over='@carry_over_1@', " .
00189 "street='@street_1@', house='@house_1@', room='@room_1@', " .
00190 "zip='@zip_1@', town='@town_1@', phone='@phone_1@', " .
00191 "mobile_phone='@mobile_1@' " .
00192 "WHERE person_id=@id@ AND is_primary='true'";
00193
00194 db_query_mysql($link,$q,$kw);
00195
00196 $q = "UPDATE addresses SET carry_over='@carry_over_2@', " .
00197 "street='@street_2@', house='@house_2@', room='@room_2@', " .
00198 "zip='@zip_2@', town='@town_2@', phone='@phone_2@', " .
00199 "mobile_phone='@mobile_2@' WHERE " .
00200 "person_id=@id@ AND is_primary='false'";
00201
00202 db_query_mysql($link,$q,$kw);
00203
00204 $_SESSION["action"] = "show";
00205 $_SESSION["button"] = "";
00206
00207 unset($_SESSION["edit_finished"]);
00208
00209 } else if (($_SESSION["action"] == "delete") and
00210 ($_SESSION["button"] == $buttons['ok'])) {
00211
00212
00213
00214
00215 $q = "delete from persons where id='@id@' ;";
00216 db_query_mysql($link, $q, array('@id@' => $_SESSION['id']));
00217
00218 $q = "delete from addresses where person_id='@id@' ; ";
00219 db_query_mysql($link, $q, array('@id@' => $_SESSION['id']));
00220
00221 $_SESSION["action"] = "show";
00222 $_SESSION["button"] = "";
00223 redirect("index.php?lang=$lang");
00224 }
00225 else if ($_SESSION["button"] == $buttons['goto_index'] ) {
00226
00227
00228
00229
00230 $_SESSION["action"] = "show";
00231 $_SESSION["button"] = "";
00232
00233 redirect("index.php?lang=$lang");
00234 }
00235 else if (($_SESSION["button"] == $buttons['submit']) or
00236 ( $_SESSION['button'] == "" and $_SESSION['barcode'] != "" ) ) {
00237
00238 $_SESSION["action"] = "submit";
00239 }
00240 else if ($_SESSION["button"] == $buttons['delete'])
00241 $_SESSION["action"] = "delete";
00242 else if ($_SESSION["button"] == $buttons['print'])
00243 $_SESSION["action"] = "print";
00244 else if ($_SESSION["action"] == "submit-check") {
00245
00246
00247 if ($_SESSION["button"] == $buttons['ok']) {
00248 $_SESSION["force_submit"] = TRUE;
00249 $_SESSION["action"] = "submit";
00250 } else {
00251 $_SESSION["action"] = "show";
00252 $_SESSION["force_submit"] = FALSE;
00253 }
00254
00255 } else if (isset($_SESSION["button"]))
00256 $_SESSION["action"] = "show";
00257
00258
00259 $_SESSION["button"] = "";
00260
00261
00262
00263
00264 if ($_SESSION["action"] == "submit") {
00265
00266
00267 $double_accs = check_for_doubles($link,$_SESSION["id"]);
00268
00269
00270 if ($status == "old")
00271 $_SESSION["action"] = "show";
00272 else if ( (empty($double_accs) or $_SESSION["force_submit"]) ) {
00273
00274
00275
00276 if ($_SESSION["barcode"] == "") {
00277 $barcode_error = TRUE;
00278 $_SESSION["action"] = "show";
00279 }
00280 else {
00281
00282 $barcode = $_SESSION['barcode'];
00283 unset($_SESSION['barcode']);
00284
00285 (export_to_pica($link, $_SESSION["id"], $barcode) == 0)
00286 or error_msg("Error: export_to_pica() failed");
00287
00288
00289
00290 $q = "UPDATE persons set status='old' where id='@id@'";
00291 db_query_mysql($link, $q, array('@id@' => $_SESSION['id']));
00292 $status = "old";
00293
00294
00295
00296 $q = $fields['barcode']['update'];
00297 db_query_mysql($link, $q,
00298 array('@id@' => $_SESSION['id'],
00299 '@val@' => $barcode));
00300 }
00301
00302 $_SESSION["force_submit"] = FALSE;
00303
00304 } else
00305 $_SESSION["action"] = "submit-check";
00306 }
00307
00308
00324
00325 $table1 = array(
00326 array( "label" => $fields['last_name']["label"],
00327 "query" => $fields['last_name']["view_query"]
00328 ),
00329 array( "label" => $fields['first_name']["label"],
00330 "query" => $fields['first_name']["view_query"]
00331 ),
00332 array( "label" => $fields['title']["label"],
00333 "query" => $fields['title']["view_query"]
00334 ),
00335 array( "label" => $fields['sex']["label"],
00336 "query" => $fields['sex']["view_query"]
00337 )
00338 );
00339
00340
00341 $table2 = array(
00342 array( "label" => $fields['birthday']["label"],
00343 "query" => $fields['birthday']["view_query"]
00344 ),
00345 array( "label" => $fields['usertype']["label"],
00346 "query" => "select usertype_names.name " .
00347 "from persons, usertype_names, usertypes " .
00348 "where persons.usertype_id = usertypes.id " .
00349 "and usertype_names.usertype_id = usertypes.id ".
00350 "and usertype_names.type = persons.sex " .
00351 "and persons.id='@id@' " .
00352 "and usertype_names.lang='@lang@'"
00353 ),
00354
00355 array( "label" => $fields['student_id']["label"],
00356 "query" => $fields['student_id']["view_query"]
00357 ),
00358 array( "label" => $fields['barcode']['label'],
00359 "query" => $fields['barcode']["view_query"]
00360 )
00361 );
00362
00363
00364 $table3 = array(
00365 array( "label" => $text['mahnaddr'],
00366 "query" => "select address_types.name " .
00367 "from address_types, persons, usertypes " .
00368 "where persons.usertype_id = usertypes.id " .
00369 "and usertypes.primary_address_type = " .
00370 "address_types.id and persons.id = '@id@' " .
00371 "and address_types.lang='@lang@'"
00372 ),
00373 array( "label" => $fields['carry_over_1']['label'],
00374 "query" => $fields['carry_over_1']["view_query"]
00375 ),
00376
00377 array( "label" => $fields['street_1']['label'] . " / " .
00378 $fields['house_1']['label'],
00379 "query" => "select street, house " .
00380 "from addresses where person_id = '@id@' " .
00381 "and is_primary = 'true'"
00382 ),
00383 array( "label" => $fields['room_1']['label'],
00384 "query" => $fields['room_1']["view_query"]
00385 ),
00386 array( "label" => $fields['zip_1']['label'] . " / " .
00387 $fields['town_1']['label'],
00388 "query" => "select zip, town " .
00389 "from addresses where person_id = '@id@' " .
00390 "and is_primary = 'true'"
00391 ),
00392 array( "label" => $fields['phone_1']["label"],
00393 "query" => $fields['phone_1']["view_query"]
00394 ),
00395 array( "label" => $fields['mobile_1']["label"],
00396 "query" => $fields['mobile_1']["view_query"]
00397 )
00398 );
00399
00400 $table4 = array(
00401 array( "label" => "",
00402 "query" => "select address_types.name " .
00403 "from address_types, persons, usertypes " .
00404 "where persons.usertype_id = usertypes.id " .
00405 "and usertypes.secondary_address_type = " .
00406 "address_types.id and persons.id = '@id@' " .
00407 "and address_types.lang='@lang@'"
00408 ),
00409 array( "label" => $fields['carry_over_2']["label"],
00410 "query" => $fields['carry_over_2']["view_query"]
00411 ),
00412
00413 array( "label" => $fields['street_2']['label'] . " / " .
00414 $fields['house_2']['label'],
00415 "query" => "select street, house " .
00416 "from addresses where person_id = '@id@' " .
00417 "and is_primary = 'false'"
00418 ),
00419 array( "label" => $fields['room_2']['label'],
00420 "query" => $fields['room_2']["view_query"]
00421 ),
00422 array( "label" => $fields['zip_2']['label'] . " / " .
00423 $fields['town_2']['label'],
00424 "query" => "select zip, town " .
00425 "from addresses where person_id = '@id@' " .
00426 "and is_primary = 'false'"
00427 ),
00428 array( "label" => $fields['phone_2']["label"],
00429 "query" => $fields['phone_2']["view_query"]
00430 ),
00431 array( "label" => $fields['mobile_2']["label"],
00432 "query" => $fields['mobile_2']["view_query"]
00433 )
00434 );
00435
00436 $f = $_SESSION["field"];
00437
00438
00439
00440 $q = $fields["notabene"]["view_query"];
00441 $r = db_query_mysql($link, $q, array('@id@' => $_SESSION['id']));
00442
00443 $pica_id = (isset($r[1][0])) ? "[" . $r[1][0] . "]" : "";
00444
00445 $url = "action.php?id=" . $_SESSION['id'] . "&action=show";
00446
00447 $kw = array( '@notabene@' => $pica_id, '@bodyattr@' => "",
00448 '@url-de@' => $url . "&lang=de" , '@url-en@' => $url . "&lang=en" );
00449
00450
00451
00452 if (($_SESSION["action"] == "print") or ($_SESSION["action"] == "submit")) {
00453 $kw['@bodyattr@'] = 'onLoad="javascript:window.print()" ';
00454 }
00455
00456 print_header($kw);
00457
00458
00459 $kw = array( '@id@' => $_SESSION['id'], '@lang@' => $lang);
00460
00461 ?>
00462
00463
00464
00465 <table width="100%" border="1" cellpadding="0" >
00466 <tr>
00467 <td valign="top" width="50%">
00468 <?php print_table($table1, 1, "border=\"0\" height=\"100%\" ", $link, $kw); ?>
00469 </td>
00470 <td valign="top" >
00471 <?php print_table($table2, 1, "border=\"0\" height=\"100%\" ", $link, $kw); ?>
00472 </td>
00473 </tr>
00474 <tr>
00475 <td valign="top" width="50%">
00476 <?php print_table($table3, 1, "border=\"0\" height=\"100%\" ", $link, $kw); ?>
00477 </td>
00478 <td valign="top" >
00479 <?php print_table($table4, 1, "border=\"0\" height=\"100%\" ", $link, $kw); ?>
00480 </td>
00481 </tr>
00482 </table>
00483
00484 <?php
00485
00486
00487 print "<form>";
00488
00489 print '<input type="hidden" name="lang" value="' . $lang . '">';
00490 print '<input type="hidden" name="id" value="' . $_SESSION["id"] . '">';
00491 print '<input type="hidden" name="action" value="' . $_SESSION["action"] . '">';
00492
00493 if ($_SESSION["action"] == "show") {
00494
00495 print '<table border="0" width="100%"><tr><td>';
00496
00497 if ($status != 'old') {
00498 if ($barcode_error)
00499 print $text['error'];
00500 print "<strong>" . $text['barcode'] . ":</strong> ";
00501
00502 unset ($_SESSION['barcode']);
00503 print '<input type="text" name="barcode" size="12" maxlength="12">';
00504
00505 print ' <input type="submit" name="button" value="' .
00506 $buttons['submit'] . '"> ';
00507 } else
00508 print ' ';
00509
00510 print '</td></tr><tr><td> ';
00511 print '</td><td> </td></tr><tr><td>';
00512
00513 print '<input type="submit" name="button" value="' . $buttons['goto_index'] .
00514 '"> ';
00515
00516 print '<input type="submit" name="button" value="' . $buttons['edit']. '" ';
00517 print ($status == "old") ? "disabled=yes" : "";
00518 print '> ';
00519
00520 print '<input type="submit" name="button" value="' . $buttons['print'] . '" ';
00521 print ($status != "old") ? "disabled=yes" : "";
00522 print '> ';
00523
00524 print '<input type="submit" name="button" value="' . $buttons['delete'] .
00525 '">';
00526 print ' </td></tr>';
00527
00528 print '<tr><td><br>';
00529 print ($barcode_error) ? $text['error'] . "<strong>" . $text['error_msg'] . "</strong>" : " ";
00530 print '</td><td> </td></tr></table>';
00531
00532 print '</table>';
00533
00534 } else if ($_SESSION["action"] == "delete") {
00535
00536 print "<br><br>";
00537 print $text['confirm_delete'];
00538 print ' <input type="submit" name="button" value="' .
00539 $buttons['ok'] . '"> ';
00540 print ' <input type="submit" name="button" value="' .
00541 $buttons['cancel'] . '"> <br>';
00542
00543
00544 } else if (($_SESSION["action"] == "print") or
00545 ($_SESSION["action"] == "submit")) {
00546
00547 $kw = array("@today@" => strftime('%d. %m. %Y'));
00548
00549 # print "<br><br>\n";
00550 print $text['info_1'];
00551 print strtr($text['sign_here'], $kw);
00552
00553 }
00554 else if (($_SESSION["action"] == "submit-check")) {
00555 $fields = array (
00556 "name" => "Nachname",
00557 "first_name_initials_prefix" => "Vorname",
00558
00559 "date_of_birth" => "Geburtsdatum",
00560 "borrower_bar" => "Barcode",
00561 "borrower_status" => "Status",
00562 );
00563
00564 print $text['user_account_conflict'];
00565
00566 print "<br><br><table border=\"1\" cellpadding=\"5\">";
00567
00568 print "<tr>";
00569 foreach ($fields as $f)
00570 print "<th>$f</th>";
00571 print "</tr>";
00572
00573 foreach ($double_accs as $row) {
00574 print "<tr>";
00575
00576 foreach ($fields as $k => $dummy)
00577 print "<td>" . htmlentities($row[$k]) . "</td>";
00578
00579 print "</tr>";
00580 }
00581
00582 print "</table>";
00583
00584 print $text['confirm_submit'];
00585 print ' <input type="submit" name="button" value="' .
00586 $buttons['ok'] . '"> ';
00587 print ' <input type="submit" name="button" value="' .
00588 $buttons['cancel'] . '"> ';
00589
00590 }
00591
00592 print "</form>";
00593
00594 print_footer(array());
00595
00596 mysql_close($link);
00597 ?>