00001 <?php
00002
00003
00004
00005
00006
00007
00011
00012 require_once('util.php');
00013 require_once('text.php');
00014
00046
00047 $fields = array (
00048 "last_name" => array (
00049 "type" => "text",
00050 "size" => 64,
00051 "query" => "select last_name from persons " .
00052 "where id = '@id@'",
00053 "update" => "update persons " .
00054 "set last_name='@val@' where id='@id@'",
00055 "valid" => "/^[ -~漩周遌+$/",
00056 "pica_field" => "a105"
00057 ),
00058
00059 "first_name" => array (
00060 "type" => "text",
00061 "size" => 15,
00062 "query" => "select first_name from persons " .
00063 "where id = '@id@'",
00064 "update" => "update persons " .
00065 "set first_name='@val@' where id='@id@'",
00066 "valid" => "/^[ -~漩周遌+$/",
00067 "pica_field" => "a107"
00068 ),
00069 "title" => array (
00070 "type" => "text",
00071 "size" => 32,
00072 "query" => "select title from persons " .
00073 "where id = '@id@'",
00074 "update" => "update persons " .
00075 "set title='@val@' where id='@id@'",
00076 "valid" => "/^[ -~漩周遌*$/",
00077 "pica_field" => "a108"
00078 ),
00079 "sex" => array (
00080 "type" => "choice",
00081 "query" => "select sex from persons " .
00082 "where id = '@id@'",
00083 "update" => "update persons " .
00084 "set sex='@val@' where id='@id@'",
00085 "valid" => "/^[mw]$/",
00086 "pica_field" => "a110"
00087 ),
00088 "birthday" => array (
00089 "type" => "date",
00090 "query" => "select birthday " .
00091 "from persons where id='@id@'",
00092 "update" => "update persons " .
00093 "set birthday='@val@' where id='@id@'",
00094 "valid" => "/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/",
00095 "pica_field" => "a109",
00096 "pica_query" => "select DATE_FORMAT(birthday,'%d-%m-%Y') " .
00097 "from persons where id='@id@'",
00098 "view_query" => "select DATE_FORMAT(birthday,'%d-%m-%Y') " .
00099 "from persons where id='@id@'"
00100 ),
00101 "usertype" => array (
00102 "type" => "choice",
00103 "query" => "select usertype_id from persons " .
00104 "where id = '@id@'",
00105 "update" => "update persons " .
00106 "set usertype_id='@val@' where id='@id@'",
00107 "choice" => array(),
00108 "valid" => "/^[0-9]*$/",
00109 "pica_field" => "a103",
00110 "pica_query" => "select usertypes.pica_user_group " .
00111 "from usertypes, persons " .
00112 "where persons.usertype_id = usertypes.id " .
00113 "and persons.id = '@id@'"
00114 ),
00115 "student_id" => array (
00116 "type" => "text",
00117 "size" => 12,
00118 "query" => "select TRIM( LEADING '0' FROM student_id ) from persons " .
00119 "where id = '@id@'",
00120 "update" => "update persons set student_id='@val@' " .
00121 "where id='@id@'",
00122 "valid" => "/^(|[0-9]*)$/",
00123 "pica_field" => "a101"
00124 ),
00125 "carry_over_1" => array (
00126 "type" => "text",
00127 "size" => 64,
00128 "query" => "select carry_over " .
00129 "from addresses where person_id = '@id@' " .
00130 "and is_primary = 'true'",
00131 "update" => "update addresses set carry_over='@val@' " .
00132 "where person_id='@id@' and is_primary = 'true'; ",
00133 "valid" => "/^[ -~漩周遌*$/",
00134 "pica_field" => "a310"
00135 ),
00136 "street_1" => array (
00137 "type" => "text",
00138 "size" => 45,
00139 "query" => "select street " .
00140 "from addresses where person_id = '@id@' " .
00141 "and is_primary = 'true'",
00142 "update" => "update addresses set street='@val@' " .
00143 "where person_id='@id@' and is_primary = 'true';",
00144 "valid" => "/^[ -~漩周遌+$/",
00145 "pica_field" => "a303"
00146
00147 ),
00148 "house_1" => array (
00149 "type" => "text",
00150 "size" => 6,
00151 "query" => "select house " .
00152 "from addresses where person_id = '@id@' " .
00153 "and is_primary = 'true'",
00154 "update" => "update addresses set house='@val@' " .
00155 "where person_id='@id@' and is_primary = 'true'; ",
00156 "valid" => "/^[a-zA-Z0-9 -]+$/",
00157 "pica_field" => "a303"
00158 ),
00159 "zip_1" => array (
00160 "type" => "text",
00161 "size" => 5,
00162 "query" => "select zip " .
00163 "from addresses where person_id = '@id@' " .
00164 "and is_primary = 'true'",
00165 "update" => "update addresses set zip='@val@' " .
00166 "where person_id='@id@' and is_primary = 'true'; ",
00167 "valid" => "/^[0-9][0-9][0-9][0-9][0-9]$/",
00168 "pica_field" => "a304"
00169 ),
00170 "town_1" => array (
00171 "type" => "text",
00172 "size" => 64,
00173 "query" => "select town " .
00174 "from addresses where person_id = '@id@' " .
00175 "and is_primary = 'true'",
00176 "update" => "update addresses set town='@val@' " .
00177 "where person_id='@id@' and is_primary = 'true'; ",
00178 "valid" => "/^[ -~漩周遌+$/",
00179 "pica_field" => "a305"
00180 ),
00181 "phone_1" => array (
00182 "label" => "Telefon:",
00183 "type" => "text",
00184 "size" => 20,
00185 "query" => "select phone " .
00186 "from addresses where person_id = '@id@' " .
00187 "and is_primary = 'true'",
00188 "update" => "update addresses set phone='@val@' " .
00189 "where person_id='@id@' and is_primary = 'true'; ",
00190 "valid" => "/^[-0-9 \/]*$/",
00191 "pica_field" => "a308"
00192 ),
00193
00194 "mobile_1" => array (
00195 "label" => "Mobil:",
00196 "type" => "text",
00197 "size" => 20,
00198 "query" => "select mobile_phone " .
00199 "from addresses where person_id = '@id@' " .
00200 "and is_primary = 'true'",
00201 "update" => "update addresses set mobile_phone='@val@' " .
00202 "where person_id='@id@' and is_primary = 'true'; ",
00203 "valid" => "/^[-0-9 \/]*$/",
00204 "pica_field" => "a311"
00205 ),
00206 "carry_over_2" => array (
00207 "label" => "c/o:",
00208 "type" => "text",
00209 "size" => 64,
00210 "query" => "select carry_over " .
00211 "from addresses where person_id = '@id@' " .
00212 "and is_primary = 'false'",
00213 "update" => "update addresses set carry_over='@val@' " .
00214 "where person_id='@id@' and is_primary = 'false'; ",
00215 "valid" => "/^[ -~漩周遌*$/",
00216 "pica_field" => "b310"
00217 ),
00218 "street_2" => array (
00219 "label" => "Stra遝:",
00220 "type" => "text",
00221 "size" => 45,
00222 "query" => "select street " .
00223 "from addresses where person_id = '@id@' " .
00224 "and is_primary = 'false'",
00225 "update" => "update addresses set street='@val@' " .
00226 "where person_id='@id@' and is_primary = 'false';",
00227 "valid" => "/^[ -~漩周遌*$/",
00228 "pica_field" => "b303"
00229 ),
00230 "house_2" => array (
00231 "label" => "Hausnummer:",
00232 "type" => "text",
00233 "size" => 6,
00234 "query" => "select house " .
00235 "from addresses where person_id = '@id@' " .
00236 "and is_primary = 'false'",
00237 "update" => "update addresses set house='@val@' " .
00238 "where person_id='@id@' and is_primary = 'false'; ",
00239 "valid" => "/^[a-zA-Z0-9 -]*$/",
00240 "pica_field" => "b303"
00241 ),
00242 "zip_2" => array (
00243 "label" => "PLZ:",
00244 "type" => "text",
00245 "size" => 5,
00246 "query" => "select zip " .
00247 "from addresses where person_id = '@id@' " .
00248 "and is_primary = 'false'",
00249 "update" => "update addresses set zip='@val@' " .
00250 "where person_id='@id@' and is_primary = 'false'; ",
00251 "valid" => "/^(|[0-9][0-9][0-9][0-9][0-9])$/",
00252 "pica_field" => "b304"
00253 ),
00254 "town_2" => array (
00255 "label" => "Ort:",
00256 "type" => "text",
00257 "size" => 64,
00258 "query" => "select town " .
00259 "from addresses where person_id = '@id@' " .
00260 "and is_primary = 'false'",
00261 "update" => "update addresses set town='@val@' " .
00262 "where person_id='@id@' and is_primary = 'false'; ",
00263 "valid" => "/^[ -~漩周遌*$/",
00264 "pica_field" => "b305"
00265 ),
00266 "phone_2" => array (
00267 "label" => "Telefon:",
00268 "type" => "text",
00269 "size" => 20,
00270 "query" => "select phone " .
00271 "from addresses where person_id = '@id@' " .
00272 "and is_primary = 'false'",
00273 "update" => "update addresses set phone='@val@' " .
00274 "where person_id='@id@' and is_primary = 'false'; ",
00275 "valid" => "/^[-0-9 \/]*$/",
00276 "pica_field" => "b308"
00277 ),
00278
00279 "mobile_2" => array (
00280 "label" => "Mobil:",
00281 "type" => "text",
00282 "size" => 20,
00283 "query" => "select mobile_phone " .
00284 "from addresses where person_id = '@id@' " .
00285 "and is_primary = 'false'",
00286 "update" => "update addresses set mobile_phone='@val@' " .
00287 "where person_id='@id@' and is_primary = 'false'; ",
00288 "valid" => "/^[-0-9 \/]*$/",
00289 "pica_field" => "b311"
00290 ),
00291 "nametag" => array (
00292 "type" => "text",
00293 "size" => 6,
00294 "query" => "select usertype_names.name "
00295 . "from usertype_names, usertypes, "
00296 . " persons where usertypes.id=persons.usertype_id"
00297 . " and usertype_names.usertype_id = usertypes.id"
00298 . " and usertype_names.type = 'short' "
00299 . " and persons.id='@id@'",
00300 "update" => "",
00301 "valid" => "/^[a-zA-Z0-9]*$/",
00302 "pica_field" => "a106"
00303 ),
00304 "notabene" => array (
00305 "type" => "text",
00306 "size" => 6,
00307 "query" => "select pica_id from persons where id='@id@'",
00308 "update" => "update persons set pica_id='@val@' " .
00309 " where id='@id@'",
00310 "valid" => "/^[0-9][0-9]\/[0-9]*$/",
00311 "pica_field" => "a114"
00312 ),
00313 "room_1" => array (
00314 "type" => "text",
00315 "size" => 10,
00316 "query" => "select room " .
00317 "from addresses where person_id = '@id@' " .
00318 "and is_primary = 'true'",
00319 "update" => "update addresses set room='@val@' " .
00320 "where person_id='@id@' and is_primary = 'true'",
00321 "valid" => "/^[ -~漩周遌*$/",
00322 "pica_field" => "a303",
00323 "pica_query" => "select IF(length(room) = 0, '', "
00324 . "CONCAT('/ ', room)) from addresses "
00325 . "where person_id='@id@' and is_primary='true'"
00326 ),
00327 "room_2" => array (
00328 "type" => "text",
00329 "size" => 10,
00330 "query" => "select room " .
00331 "from addresses where person_id = '@id@' " .
00332 "and is_primary = 'false'",
00333 "update" => "update addresses set room='@val@' " .
00334 "where person_id='@id@' and is_primary = 'false'",
00335 "valid" => "/^[ -~漩周遌*$/",
00336 "pica_field" => "b303",
00337 "pica_query" => "select IF(length(room) = 0, '', "
00338 . "CONCAT('/ ', room)) from addresses "
00339 . "where person_id='@id@' and is_primary='false'"
00340 ),
00341 "expiry_date" => array (
00342 "type" => "text",
00343 "size" => 10,
00344 "query" => "select DATE_ADD(NOW(), INTERVAL expire_after DAY) from usertypes, persons where persons.id=@id@ and persons.usertype_id = usertypes.id" ,
00345 "update" => "",
00346 "valid" => "/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/",
00347 "pica_field" => "a202",
00348 "pica_query" => "select DATE_FORMAT(DATE_ADD(NOW(), INTERVAL expire_after DAY),\"%d-%m-%Y\") from usertypes, persons where persons.id=@id@ and persons.usertype_id = usertypes.id" ,
00349 "view_query" => "select DATE_FORMAT(DATE_ADD(NOW(), INTERVAL expire_after DAY),\"%d-%m-%Y\") from usertypes, persons where persons.id=@id@ and persons.usertype_id = usertypes.id"
00350 ),
00351 "entry_date" => array (
00352 "type" => "date",
00353 "query" => "select entry_date " .
00354 "from persons where id='@id@'",
00355 "update" => "update persons " .
00356 "set entry_date='@val@' where id='@id@'",
00357 "valid" => "/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/",
00358 "view_query" => "select DATE_FORMAT(entry_date,'%d-%m-%Y') " .
00359 "from persons where id='@id@'"
00360 ),
00361 "password" => array (
00362 "label" => "Passwort:",
00363 "type" => "text",
00364 "size" => 10,
00365 "query" => "select DATE_FORMAT(birthday, '%d%m%y') from " .
00366 "persons where id='@id@'",
00367 "update" => "",
00368 "valid" => "/^[0-9][0-9][0-9][0-9][0-9][0-9]$/",
00369 "pica_field" => "b401"
00370 ),
00371 "barcode" => array (
00372 "label" => "Barcode:",
00373 "type" => "text",
00374 "size" => 12,
00375 "query" => "select pica_barcode " .
00376 "from persons where id = '@id@' " ,
00377 "update" => "update persons set pica_barcode='@val@' " .
00378 "where id='@id@'",
00379 "valid" => "/^[0-9\/]*[0-9xX]$/",
00380 "pica_field" => "a102"
00381 )
00382 );
00383
00391
00392 function fields_init($link, $lang) {
00393 global $field_labels, $fields, $text_multi;
00394
00395 $q = "select usertype_names.usertype_id, usertype_names.name "
00396 . "from usertype_names where "
00397 . "usertype_names.type = 'u' and usertype_names.lang='@lang@'";
00398
00399 $result = db_query_mysql($link, $q, array("@lang@" => $lang));
00400
00401 foreach ($result as $row)
00402 $fields["usertype"]["choices"][$row["usertype_id"]] =
00403 $row["name"];
00404
00405 foreach ($fields as $k => $v) {
00406 if (!isset($v['pica_query']))
00407 $fields[$k]['pica_query'] = $v['query'];
00408
00409 if (!isset($v['view_query']))
00410 $fields[$k]['view_query'] = $v['query'];
00411 }
00412
00413 ## assign field labels
00414
00415 foreach ($field_labels[$lang] as $k => $v) {
00416 $fields[$k]['label'] = $v;
00417 }
00418
00419 $fields['sex']['choices'] = array();
00420
00421 $fields['sex']['choices']['m'] = $text_multi[$lang]['sex_m'];
00422 $fields['sex']['choices']['w'] = $text_multi[$lang]['sex_w'];
00423 }
00424
00436
00437 function input_control($field, $name, $value) {
00438 global $fields;
00439
00440 if (isset($fields[$field])) {
00441 $f = $fields[$field];
00442
00443 if ($f["type"] == "text") {
00444
00445 print '<input type="text" name="' . $name . '" ';
00446 print 'value="' . htmlentities($value) . '" ';
00447 print 'size="' . $f["size"] . '" ';
00448 print 'maxlength="' . $f["size"] . '" >';
00449
00450 } else if ($f["type"] == "choice") {
00451
00452 print '<select name="' . $name . '">';
00453 foreach ($f["choices"] as $k => $v) {
00454 print '<option value="' . htmlentities($k) . '"';
00455 if ($k == $value)
00456 print ' selected="yes" ';
00457 print '>';
00458 print htmlentities($v);
00459 print '</option>';
00460 }
00461 print '</select>';
00462 } else if ($f["type"] == "date") {
00463 global $months;
00464
00465 list($year, $month, $day) = split('-', $value,3);
00466
00467 print '<input type="text" name="' . $name . '_day" ';
00468 print 'size="2" maxlength="2" value="' . $day . '"> ';
00469
00470 print '<select name="' . $name . '_month">';
00471 foreach ($months as $k => $v) {
00472 print '<option value="' . htmlentities($k) . '"';
00473 if ($k == $month)
00474 print ' selected="yes" ';
00475 print '>';
00476 print htmlentities($v);
00477 print '</option>';
00478 }
00479 print '</select>';
00480
00481 print ' <input type="text" name="' . $name . '_year" ';
00482 print 'size="4" maxlength="4" value="' . $year . '">';
00483
00484 }
00485
00486 }
00487
00488 }
00489 ?>