PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/staff_admin/staff_search.php

https://github.com/timschofield/2.8
PHP | 412 lines | 290 code | 73 blank | 49 comment | 58 complexity | 5b0cb55de8870b7c8be696a222b7e9e1 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?php
  2. error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
  3. require('./roots.php');
  4. require('../../include/helpers/inc_environment_global.php');
  5. /**
  6. * CARE2X Integrated Hospital Information System Deployment 2.1 - 2004-10-02
  7. * GNU General Public License
  8. * Copyright 2002,2003,2004,2005 Elpidio Latorilla
  9. * elpidio@care2x.org,
  10. *
  11. * See the file "copy_notice.txt" for the licence notice
  12. */
  13. # Default value for the maximum nr of rows per block displayed, define this to the value you wish
  14. # In normal cases this value is derived from the db table "care_config_global" using the "pagin_insurance_list_max_block_rows" element.
  15. define('MAX_BLOCK_ROWS',30);
  16. define('MODULE','staff_admin');
  17. define('LANG_FILE_MODULAR','staff_admin.php');
  18. $local_user='aufnahme_user';
  19. require_once($root_path.'include/helpers/inc_front_chain_lang.php');
  20. require_once($root_path.'include/helpers/inc_date_format_functions.php');
  21. ///$db->debug=true;
  22. # If a forwarded nr is available, convert it to searchkey and set mode to "search"
  23. if(isset($fwd_nr)&&$fwd_nr){
  24. $searchkey=$fwd_nr;
  25. $mode='search';
  26. }else{
  27. # Translate *? wildcards
  28. $searchkey=strtr($searchkey,'*?','%_');
  29. }
  30. $thisfile=basename(__FILE__);
  31. $toggle=0;
  32. if($_COOKIE['ck_login_logged'.$sid]) $breakfile=$root_path.'main/plugin.php'.URL_APPEND;
  33. else $breakfile='staff_admin_pass.php'.URL_APPEND.'&target='.$target;
  34. /* Set color values for the search mask */
  35. $searchmask_bgcolor='#f3f3f3';
  36. $searchprompt=$LDEnterEmployeeSearchKey;
  37. $entry_block_bgcolor='#fff3f3';
  38. $entry_border_bgcolor='#6666ee';
  39. $entry_body_bgcolor='#ffffff';
  40. if(!isset($searchkey)) $searchkey='';
  41. if(!isset($mode)) $mode='';
  42. # Initialize page's control variables
  43. if($mode=='paginate'){
  44. $searchkey=$_SESSION['sess_searchkey'];
  45. }else{
  46. # Reset paginator variables
  47. $pgx=0;
  48. $totalcount=0;
  49. $odir='';
  50. $oitem='';
  51. }
  52. #Load and create paginator object
  53. require_once($root_path.'include/core/class_paginator.php');
  54. $pagen=new Paginator($pgx,$thisfile,$_SESSION['sess_searchkey'],$root_path);
  55. if(isset($mode)&&($mode=='search'||$mode=='paginate')&&isset($searchkey)&&($searchkey)){
  56. include_once($root_path.'include/helpers/inc_date_format_functions.php');
  57. if($mode!='paginate'){
  58. $_SESSION['sess_searchkey']=$searchkey;
  59. }
  60. # convert * and ? to % and &
  61. $searchkey=strtr($searchkey,'*?','%_');
  62. $GLOBAL_CONFIG=array();
  63. include_once($root_path.'include/core/class_globalconfig.php');
  64. $glob_obj=new GlobalConfig($GLOBAL_CONFIG);
  65. $glob_obj->getConfig('staff_nr_adder');
  66. # Get the max nr of rows from global config
  67. $glob_obj->getConfig('pagin_staff_search_max_block_rows');
  68. if(empty($GLOBAL_CONFIG['pagin_staff_search_max_block_rows'])) $pagen->setMaxCount(MAX_BLOCK_ROWS); # Last resort, use the default defined at the start of this page
  69. else $pagen->setMaxCount($GLOBAL_CONFIG['pagin_staff_search_max_block_rows']);
  70. $searchkey=trim($searchkey);
  71. $suchwort=$searchkey;
  72. if(is_numeric($suchwort)) {
  73. $suchwort=(int) $suchwort;
  74. $numeric=1;
  75. if($suchwort<$GLOBAL_CONFIG['staff_nr_adderr']){
  76. $suchbuffer=(int) ($suchwort + $GLOBAL_CONFIG['staff_nr_adder']) ;
  77. }
  78. if(empty($oitem)) $oitem='nr';
  79. if(empty($odir)) $odir='DESC'; # default, latest pid at top
  80. $sql2=" WHERE ( ps.nr='$suchwort' OR ps.nr = '$suchbuffer' )";
  81. } else {
  82. # Try to detect if searchkey is composite of first name + last name
  83. if(stristr($searchkey,',')){
  84. $lastnamefirst=TRUE;
  85. }else{
  86. $lastnamefirst=FALSE;
  87. }
  88. $searchkey=strtr($searchkey,',',' ');
  89. $cbuffer=explode(' ',$searchkey);
  90. # Remove empty variables
  91. for($x=0;$x<sizeof($cbuffer);$x++){
  92. $cbuffer[$x]=trim($cbuffer[$x]);
  93. if($cbuffer[$x]!='') $comp[]=$cbuffer[$x];
  94. }
  95. # Arrange the values, ln= lastname, fn=first name, bd = birthday
  96. if($lastnamefirst){
  97. $fn=$comp[1];
  98. $ln=$comp[0];
  99. $bd=$comp[2];
  100. }else{
  101. $fn=$comp[0];
  102. $ln=$comp[1];
  103. $bd=$comp[2];
  104. }
  105. if(empty($oitem)) $oitem='name_last';
  106. # Check the size of the comp
  107. if(sizeof($comp)>1){
  108. $DOB=formatDate2STD($suchwort,$date_format);
  109. $sql2=" WHERE ( p.name_last $sql_LIKE '".strtr($ln,'+',' ')."%'
  110. AND p.name_first $sql_LIKE '".strtr($fn,'+',' ')."%'";
  111. if($bd && $DOB){
  112. $sql2.=" AND p.date_birth = '$DOB' )";
  113. }else{
  114. $sql2.=')';
  115. }
  116. if(empty($odir)) $odir='DESC'; # default, latest birth at top
  117. }else{
  118. $sql2=" WHERE (p.name_last $sql_LIKE '".strtr($suchwort,'+',' ')."%'
  119. OR p.name_first $sql_LIKE '".strtr($suchwort,'+',' ')."%'";
  120. if($DOB) $sql2.=" OR p.date_birth = '$DOB' ";
  121. else $sql2.=')';
  122. if(empty($odir)) $odir='ASC'; # default, ascending alphabetic
  123. }
  124. }
  125. $sql2.=" AND ps.status NOT IN ('void','hidden','deleted','inactive')
  126. AND ps.is_discharged IN ('',0)
  127. AND ps.pid=p.pid ";
  128. # Filter if it is staff nr
  129. if($oitem=='nr') $sql3.='ORDER BY ps.'.$oitem.' '.$odir;
  130. else $sql3 ='ORDER BY p.'.$oitem.' '.$odir;
  131. $dbtable='FROM care_staff as ps,care_person as p ';
  132. $sql='SELECT ps.nr, ps.is_discharged, p.name_last, p.name_first, p.date_birth, p.addr_zip, p.sex,p.photo_filename '.$dbtable.$sql2.$sql3;
  133. //echo $sql;
  134. if($ergebnis=$db->SelectLimit($sql,$pagen->MaxCount(),$pagen->BlockStartIndex()))
  135. {
  136. if ($linecount=$ergebnis->RecordCount())
  137. {
  138. if(($linecount==1)&&$numeric)
  139. {
  140. $zeile=$ergebnis->FetchRow();
  141. header("location:staff_register_show.php".URL_REDIRECT_APPEND."&from=such&target=staff_search&staff_nr=".$zeile['nr']."&sem=".(!$zeile['is_discharged']));
  142. exit;
  143. }
  144. # Set the object to actual nr of rows
  145. $pagen->setTotalBlockCount($linecount);
  146. # If more than one count all available
  147. if(isset($totalcount)&&$totalcount){
  148. $pagen->setTotalDataCount($totalcount);
  149. }else{
  150. # Count total available data
  151. $sql='SELECT COUNT(ps.nr) AS count '.$dbtable.$sql2;
  152. if($result=$db->Execute($sql)){
  153. if ($result->RecordCount()) {
  154. $rescount=$result->FetchRow();
  155. $totalcount=$rescount['count'];
  156. }
  157. }
  158. $pagen->setTotalDataCount($totalcount);
  159. }
  160. # Set the sort parameters
  161. $pagen->setSortItem($oitem);
  162. $pagen->setSortDirection($odir);
  163. }
  164. }
  165. else {echo "<p>".$sql."<p>$LDDbNoRead";};
  166. } else {
  167. $mode='';
  168. }
  169. # Start Smarty templating here
  170. /**
  171. * LOAD Smarty
  172. */
  173. # Note: it is advisable to load this after the inc_front_chain_lang.php so
  174. # that the smarty script can use the user configured template theme
  175. require_once(CARE_BASE.'/include/helpers/smarty_care.class.php');
  176. $smarty = new smarty_care('system_admin');
  177. # Title in toolbar
  178. $smarty->assign('sToolbarTitle',"$LDstaffManagement :: $LDstaffData :: $LDSearch");
  179. $smarty->assign('LDBack', $LDBack);
  180. $smarty->assign('LDHelp', $LDHelp);
  181. $smarty->assign('LDClose', $LDClose);
  182. # hide return button
  183. $smarty->assign('pbBack',FALSE);
  184. # href for help button
  185. $smarty->assign('pbHelp',CARE_GUI . "modules/" . MODULE . "/help/" . $lang . "/employee_search.html");
  186. # href for close button
  187. $smarty->assign('breakfile',$breakfile);
  188. # Window bar title
  189. $smarty->assign('sWindowTitle',"$LDstaffManagement :: $LDstaffData :: $LDSearch");
  190. # Body onLoad Javascript code
  191. $smarty->assign('sOnLoadJs','onLoad="document.searchform.searchkey.select()"');
  192. # Colllect javascript code
  193. ob_start();
  194. ?>
  195. <table width=100% border=0 cellspacing="0" cellpadding=0>
  196. <!-- Load tabs -->
  197. <?php
  198. $target='staff_search';
  199. include('./gui_bridge/default/gui_tabs_staff_reg.php')
  200. ?>
  201. </table>
  202. <ul>
  203. <table border=0 cellpadding=10 bgcolor="<?php echo $entry_border_bgcolor ?>">
  204. <tr>
  205. <td>
  206. <?php
  207. include($root_path.'include/helpers/inc_patient_searchmask.php');
  208. ?>
  209. </td>
  210. </tr>
  211. </table>
  212. <p>
  213. <a href="<?php echo $breakfile; ?>" class="button icon remove danger">Cancel</a>
  214. <p>
  215. <?php
  216. if($mode=='search'||$mode=='paginate'){
  217. if ($linecount) echo '<hr width=80% align=left>'.str_replace("~nr~",$totalcount,$LDSearchFound).' '.$LDShowing.' '.$pagen->BlockStartNr().' '.$LDTo.' '.$pagen->BlockEndNr().'.';
  218. else echo str_replace('~nr~','0',$LDSearchFound);
  219. if ($linecount) {
  220. # Load the common icons
  221. $img_options=createComIcon($root_path,'statbel2.gif','0','',TRUE);
  222. $img_male=createComIcon($root_path,'spm.gif','0','',TRUE);
  223. $img_female=createComIcon($root_path,'spf.gif','0','',TRUE);
  224. echo '
  225. <table border=0 cellpadding=2 cellspacing=1> <tr class="wardlisttitlerow">';
  226. ?>
  227. <td><b>
  228. <?php
  229. if($oitem=='nr') $flag=TRUE;
  230. else $flag=FALSE;
  231. echo $pagen->SortLink($LDstaffNr,'nr',$odir,$flag);
  232. ?></b></td>
  233. <td><b>
  234. <?php
  235. if($oitem=='sex') $flag=TRUE;
  236. else $flag=FALSE;
  237. echo $pagen->SortLink($LDSex,'sex',$odir,$flag);
  238. ?></b></td>
  239. <td><b>
  240. <?php
  241. if($oitem=='name_last') $flag=TRUE;
  242. else $flag=FALSE;
  243. echo $pagen->SortLink($LDLastName,'name_last',$odir,$flag);
  244. ?></b></td>
  245. <td><b>
  246. <?php
  247. if($oitem=='name_first') $flag=TRUE;
  248. else $flag=FALSE;
  249. echo $pagen->SortLink($LDFirstName,'name_first',$odir,$flag);
  250. ?></b></td>
  251. <td><b>
  252. <?php
  253. if($oitem=='date_birth') $flag=TRUE;
  254. else $flag=FALSE;
  255. echo $pagen->SortLink($LDBday,'date_birth',$odir,$flag);
  256. ?></b></td>
  257. <td align='center'><b>
  258. <?php
  259. if($oitem=='addr_zip') $flag=TRUE;
  260. else $flag=FALSE;
  261. echo $pagen->SortLink($LDZipCode,'addr_zip',$odir,$flag);
  262. ?></b></td>
  263. <td background="<?php echo createBgSkin($root_path,'tableHeaderbg.gif'); ?>"><font color="#ffffff"><b><?php echo $LDOptions; ?></td>
  264. <?php
  265. echo"</tr>";
  266. while($zeile=$ergebnis->FetchRow())
  267. {
  268. echo "
  269. <tr class=";
  270. if($toggle) { echo "wardlistrow2>"; $toggle=0;} else {echo "wardlistrow1>"; $toggle=1;};
  271. echo"<td>";
  272. // echo '&nbsp;'.($zeile['nr']+$GLOBAL_CONFIG['staff_nr_adder']);
  273. echo '&nbsp;'.$zeile['nr'];
  274. echo "</td>";
  275. echo '<td><a href="javascript:popPic(\''.$zeile['name_last'].', '.$bed['name_first'].' '.formatDate2Local($zeile['date_birth'],$date_format).'\',\''.$zeile['photo_filename'].'\')">';
  276. switch($zeile['sex']){
  277. case 'f': echo '<img '.$img_female.'>'; break;
  278. case 'm': echo '<img '.$img_male.'>'; break;
  279. default: echo '&nbsp;'; break;
  280. }
  281. echo '</a></td>
  282. ';
  283. echo"<td>";
  284. echo "&nbsp;".ucfirst($zeile['name_last']);
  285. echo "</td>";
  286. echo"<td>";
  287. echo "&nbsp;".ucfirst($zeile['name_first']);
  288. echo "</td>";
  289. echo"<td>";
  290. echo "&nbsp;".formatDate2Local($zeile['date_birth'],$date_format);
  291. echo "</td>";
  292. echo '</td>
  293. <td align=right>&nbsp; &nbsp;'.$zeile['addr_zip'].'</td>';
  294. if($_COOKIE[$local_user.$sid]) echo '
  295. <td>&nbsp;
  296. <a href="staff_register_show.php'.URL_APPEND.'&from=such&staff_nr='.$zeile['nr'].'&target=staff_search">
  297. <img '.$img_options.' alt="'.$LDShowData.'"></a>&nbsp;';
  298. if(!file_exists($root_path.'cache/barcodes/en_'.$zeile['nr'].'.png'))
  299. {
  300. echo "<img src='".$root_path."classes/barcode/image.php?code=".$zeile['nr']."&style=68&type=I25&width=180&height=50&xres=2&font=5&label=2&form_file=en' border=0 width=0 height=0>";
  301. }
  302. echo '</td></tr>';
  303. }
  304. echo '
  305. <tr><td colspan=6>'.$pagen->makePrevLink($LDPrevious).'</td>
  306. <td align=right>'.$pagen->makeNextLink($LDNext).'</td>
  307. </tr>
  308. </table>';
  309. if($linecount>$pagen->MaxCount())
  310. {
  311. /* Set the appending nr for the searchform */
  312. $searchform_count=2;
  313. ?>
  314. <p>
  315. <table border=0 cellpadding=10 bgcolor="<?php echo $entry_border_bgcolor ?>">
  316. <tr>
  317. <td>
  318. <?php
  319. include($root_path.'include/helpers/inc_patient_searchmask.php');
  320. ?>
  321. </td>
  322. </tr>
  323. </table>
  324. <?php
  325. }
  326. }
  327. }
  328. ?>
  329. </ul>
  330. <?php
  331. $sTemp = ob_get_contents();
  332. ob_end_clean();
  333. # Assign page output to the mainframe template
  334. $smarty->assign('sMainFrameBlockData',$sTemp);
  335. /**
  336. * show Template
  337. */
  338. $smarty->display(CARE_BASE . 'main/view/mainframe.tpl');
  339. ?>