PageRenderTime 65ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/data/employees.php

https://github.com/tlezotte/HCR
PHP | 178 lines | 119 code | 24 blank | 35 comment | 15 complexity | 23415ec2fe18d83ae99bd9a8e16a5101 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. * Employee List
  4. *
  5. * index.php is the search page for the Employee List.
  6. *
  7. * @version 0.1
  8. * @link http://a2.yourcompany.com/go/Employees/
  9. * @author Thomas LeZotte (tom@lezotte.net)
  10. *
  11. * @global mixed $default[]
  12. * @filesource
  13. */
  14. /**
  15. * - Start Page Loading Timer
  16. */
  17. include_once('../include/Timer.php');
  18. $starttime = StartLoadTimer();
  19. /**
  20. * - Set debug mode
  21. */
  22. $debug_page = false;
  23. include_once('debug/header.php');
  24. /**
  25. * - Database Connection
  26. */
  27. require_once('../Connections/connDB.php');
  28. require_once('../Connections/connStandards.php');
  29. /**
  30. * --- CHECK USER ACCESS ---
  31. */
  32. require_once('../security/check_user.php');
  33. /**
  34. * - Common Information
  35. */
  36. require_once('../include/config.php');
  37. if ($_GET['output'] == 'ajax') {
  38. $q = $_GET['q'];
  39. $v = ($_GET['v'] != 'all') ? "AND e.status='0'" : $blank;
  40. $l = ($_GET['l'] == 'on') ? "INNER JOIN Users u ON u.eid=e.eid" : $blank;
  41. $query="SELECT *
  42. FROM Standards.Employees e
  43. $l
  44. WHERE e.lst REGEXP '$q' OR e.eid REGEXP '$q'
  45. $v
  46. ORDER BY e.lst LIMIT 10";
  47. $result=mysql_query($query);
  48. $num=mysql_numrows($result);
  49. mysql_close();
  50. $i = 0;
  51. while ($i < $num) {
  52. $lst = mysql_result($result, $i, "lst");
  53. $fst = mysql_result($result, $i, "fst");
  54. $mdl = mysql_result($result, $i, "mdl");
  55. $eid = mysql_result($result, $i, "eid");
  56. $name = ucwords(strtolower($fst." ".$mdl." ".$lst));
  57. echo "<div onSelect=\"this.txtBox.value='$name';
  58. $('ajaxEID').value = '$eid';
  59. $('ajaxName').value = '$name ($eid)';
  60. $('EID').innerHTML = '$eid';
  61. \"> $name </div>";
  62. $i++;
  63. }
  64. if ($num == 0) {
  65. echo "<img src=\"/Common/images/nochange.gif\" align=\"absmiddle\"> No employees found.";
  66. }
  67. } else {
  68. /* ------------------ START DATABASE CONNECTIONS ----------------------- */
  69. if (is_numeric($_GET['eid'])) {
  70. $data_sql = "SELECT *, e.eid AS _eid, p.name AS _location, d.name AS _dept, e.status AS _status
  71. FROM Employees e
  72. LEFT JOIN ComDevices c ON c.cell_eid=e.eid
  73. LEFT JOIN Plants p ON p.id=e.Location
  74. LEFT JOIN Department d ON d.id=e.dept
  75. WHERE e.eid LIKE '" . $_GET['eid'] . "%'";
  76. } else {
  77. if (strlen($_GET['fst']) >= 1 AND strlen($_GET['lst']) >= 1) {
  78. $how_to_search = ($_GET['fst'] == $_GET['lst']) ? 'OR' : 'AND';
  79. $data_sql = "SELECT *, e.eid AS _eid, p.name AS _location, d.name AS _dept, e.status AS _status
  80. FROM Employees e
  81. LEFT JOIN ComDevices c ON c.cell_eid=e.eid
  82. LEFT JOIN Plants p ON p.id=e.Location
  83. LEFT JOIN Department d ON d.id=e.dept
  84. WHERE e.fst LIKE '" . $_GET['fst'] . "%' " . $how_to_search . " e.lst LIKE '" . $_GET['lst'] . "%'";
  85. } elseif (strlen($_GET['fst']) >= 1) {
  86. $data_sql = "SELECT *, e.eid AS _eid, p.name AS _location, d.name AS _dept, e.status AS _status
  87. FROM Employees e
  88. LEFT JOIN ComDevices c ON c.cell_eid=e.eid
  89. LEFT JOIN Plants p ON p.id=e.Location
  90. LEFT JOIN Department d ON d.id=e.dept
  91. WHERE e.fst LIKE '" . $_GET['fst'] . "%'";
  92. } elseif (strlen($_GET['lst']) >= 1) {
  93. $data_sql = "SELECT *, e.eid AS _eid, p.name AS _location, d.name AS _dept, e.status AS _status
  94. FROM Employees e
  95. LEFT JOIN ComDevices c ON c.cell_eid=e.eid
  96. LEFT JOIN Plants p ON p.id=e.Location
  97. LEFT JOIN Department d ON d.id=e.dept
  98. WHERE e.lst LIKE '" . $_GET['lst'] . "%'";
  99. } else {
  100. $data_sql = "SELECT *, e.eid AS _eid, p.name AS _location, d.name AS _dept, e.status AS _status
  101. FROM Employees e
  102. LEFT JOIN ComDevices c ON c.cell_eid=e.eid
  103. LEFT JOIN Plants p ON p.id=e.Location
  104. LEFT JOIN Department d ON d.id=e.dept
  105. ORDER BY e.lst ASC";
  106. }
  107. }
  108. $data_query = $dbh_standards->prepare($data_sql);
  109. $data_sth = $dbh_standards->execute($data_query);
  110. $num_rows = $data_sth->numRows();
  111. /* ------------------ END DATABASE CONNECTIONS ----------------------- */
  112. $format_phone="(000)000-0000";
  113. header('Content-type: text/xml');
  114. header('Pragma: public');
  115. header('Cache-control: private');
  116. header('Expires: -1');
  117. $output .= "<employees>\n";
  118. while($data_sth->fetchInto($DATA)) {
  119. $status = ($DATA['_status'] == 0) ? 'Current' : 'Inactive';
  120. $cellStatus = (strlen($DATA['cell_eid']) == 5) ? 'yes' : 'no';
  121. $output .= " <employee id=\"" . $DATA['_eid'] . "\" status=\"" . $status . "\">\n";
  122. $output .= " <lst>" . caps($DATA['lst']) . "</lst>\n";
  123. $output .= " <fst>" . caps($DATA['fst']) . "</fst>\n";
  124. $output .= " <dept id=\"" . caps($DATA['dept']) . "\">" . caps(str_replace("&", "and", $DATA['_dept'])) . "</dept>\n";
  125. $output .= " <location id=\"" . caps($DATA['Location']) . "\" conbr=\"" . caps($DATA['conbr']) . "\">" . caps($DATA['_location']) . "</location>\n";
  126. $output .= " <hire>" . $DATA['hire'] . "</hire>\n";
  127. $output .= " <description>" . caps(str_replace("&", "and", $DATA['Job_Description'])) . "</description>\n";
  128. $output .= " <language>" . $DATA['language'] . "</language>\n";
  129. $output .= " <email>" . $DATA['email'] . "</email>\n";
  130. $output .= " <username>" . $DATA['username'] . "</username>\n";
  131. $output .= " <password>" . $DATA['password'] . "</password>\n";
  132. $output .= " <cell status=\"" . $cellStatus . "\">\n";
  133. $output .= " <number>" . str_format_number($DATA['cell_number'], $format_phone) . "</number>\n";
  134. $output .= " <model>" . $DATA['cell_model'] . "</model>\n";
  135. $output .= " <cycle>" . $DATA['cell_billCycle'] . "</cycle>\n";
  136. $output .= " <comments><![CDATA[" . $DATA['cell_comments'] . "]]></comments>\n";
  137. $output .= " </cell>\n";
  138. $output .= " </employee>\n";
  139. }
  140. $output .= "</employees>\n";
  141. print $output;
  142. }
  143. ?>
  144. <?php
  145. /**
  146. * - Display debug information
  147. */
  148. include_once('debug/footer.php');
  149. /*
  150. * - Disconnect from database
  151. */
  152. $dbh->disconnect();
  153. $dbh_standards->disconnect();
  154. ?>