Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.32 KB | None | 0 0
  1. <?php
  2. function is_weekend($date = false)
  3. {
  4. return (date("D",strtotime($date)) == 'Sun' || date("D",strtotime($date)) == 'Sat')? true : false;
  5. }
  6. // Make a function for on time, makes that part changeable
  7. // gives the ability to change start times ($default) in the future
  8. function on_time($timein = false, $default = '09:30')
  9. {
  10. if($timein == false)
  11. return true;
  12.  
  13. return (strtotime($timein) > strtotime($default))? false : true;
  14. }
  15.  
  16. function early($timeout = false, $default = '18:00')
  17. {
  18. if($timeout == false)
  19. return true;
  20.  
  21. return (strtotime($timeout) < strtotime($default))? false : true;
  22. }
  23.  
  24. $staff = $dome = array();
  25.  
  26. while($row = ibase_fetch_assoc($result))
  27. { $dome[] = $row; }
  28.  
  29. foreach($dome as &$value)
  30. if (ctype_upper(substr($value['NAME'],0,2))== TRUE)
  31. $staff[] = $value['NAME'];
  32. $staff = array_values(array_unique($staff,SORT_REGULAR));
  33.  
  34. $m = $_POST['month'];
  35. $y = $_POST['year'];
  36.  
  37. //reorganize the array by day
  38. foreach($dome as $user) {
  39. if(!preg_match('/^'.$y.'/'.$m.'/',$user['DATEIN']))
  40. continue;
  41.  
  42. $new[trim(substr($user['DATEIN'],-2),"0")][strtolower($user['NAME'])][] = $user['TIMEIN'];
  43. $newto[trim(substr($user['DATEIN'],-2),"0")][strtolower($user['NAME'])][] = $user['TIMEOUT'];
  44. }
  45.  
  46. if ($m != '' || $y != '')
  47. echo "<br><u>Attendance for ".date("F", mktime(null, null, null, $m, 1)).", ".$y."</u>";
  48. else
  49. break;
  50. ?>
  51.  
  52. <table id="caltable" cellpadding="0" cellspacing="0" border="0">
  53. <tr>
  54. <td>
  55. NAME
  56. </td>
  57. <?php
  58. // Set header row
  59. $day_in_mo = cal_days_in_month(CAL_GREGORIAN,$m,$y);
  60. for($i = 1; $i <= $day_in_mo; $i++) { ?>
  61. <td><?php echo $i; ?></td>
  62. <?php
  63. } ?>
  64. </tr>
  65. <?php
  66. // Loop through staff
  67. foreach($staff as $name) { ?>
  68. <tr>
  69. <td rowspan=2><?php echo $name; ?></td>
  70. <?php
  71. $keyname = strtolower($name);
  72. for($i = 1; $i <= $day_in_mo; $i++) {
  73. $timein = (!empty($new[$i][$keyname][0]))? $new[$i][$keyname][0] : false;?>
  74.  
  75. <td class="<?php if(!is_weekend("{$y}-{$m}-{$i}")) { echo 'weekday'; if(!on_time($timein)) echo ' late'; echo '"'; } else echo 'weekend' ?>"><?php
  76. // Match keys and see if user is listed in that day
  77. echo ($timein != false)? $timein : '<div class="absent">-</div>'; ?></td>
  78. <?php
  79. } ?>
  80. </tr>
  81. <tr>
  82. <td style="display:none"></td>
  83. <?php
  84. $keyname = strtolower($name);
  85. for($i = 1; $i <= $day_in_mo; $i++) {
  86. $timeout = (!empty($newto[$i][$keyname][0]))? $newto[$i][$keyname][0] : false; ?>
  87.  
  88. <td class="<?php if(!is_weekend("{$y}-{$m}-{$i}")) { echo 'weekday'; if(!early($timeout)) echo ' early'; echo '"'; } else echo 'weekend' ?>"><?php
  89. echo ($timeout != false)? $timeout : '<div class="absent">-</div>'; ?></td>
  90. <?php
  91. } ?>
  92. </tr>
  93. <?php
  94. } ?>
  95.  
  96. </table>
  97.  
  98. <?php
  99. // Make a function for the weekend to isolate that condition
  100. // makes it much cleaner
  101. function is_weekend($date = false)
  102. {
  103. return (date("D",strtotime($date)) == 'Sun' || date("D",strtotime($date)) == 'Sat')? true : false;
  104. }
  105. // Make a function for on time, makes that part changeable
  106. // by giving you the ability to change start times ($default) in the future
  107. function on_time($timein = false, $default = '09:10')
  108. {
  109. if($timein == false)
  110. return true;
  111.  
  112. return (strtotime($timein) > strtotime($default))? false : true;
  113. }
  114.  
  115. <!-- Just some quick styling -->
  116. <style>
  117. #caltable td {
  118. width: 50px;
  119. padding: 5px;
  120. font-family: Arial, Helvetica, sans-serif;
  121. font-size: 13px;
  122. text-align: center;
  123. border-bottom: 1px solid #CCC;
  124. }
  125. #caltable td:first-child {
  126. width: 150px;
  127. }
  128. .weekend {
  129. background-color: #FFFF00;
  130. }
  131. .late {
  132. background-color: orange;
  133. color: #FFF;
  134. }
  135. .weekday {
  136. background-color: #EBEBEB;
  137. }
  138. .absent {
  139. color: #888;
  140. font-weight: bold;
  141. }
  142. </style>
  143.  
  144. $y = '2015';
  145. $m = '01';
  146.  
  147. // I think it's important to reorganize the array by day
  148. foreach($dome as $user) {
  149. if(!preg_match('/^'.$y.'/'.$m.'/',$user['DATEIN']))
  150. continue;
  151.  
  152. $new[trim(substr($user['DATEIN'],-2),"0")][strtolower($user['NAME'])][] = $user['TIMEIN'];
  153. } ?>
  154.  
  155.  
  156. <table id="caltable" cellpadding="0" cellspacing="0" border="0">
  157. <tr>
  158. <td>
  159. NAME
  160. </td>
  161. <?php
  162. // Set header row
  163. $day_in_mo = cal_days_in_month(CAL_GREGORIAN,$m,$y);
  164. for($i = 1; $i <= $day_in_mo; $i++) { ?>
  165. <td><?php echo $i; ?></td>
  166. <?php
  167. } ?>
  168. </tr>
  169. <?php
  170. // Loop through staff
  171. foreach($staff as $name) { ?>
  172. <tr>
  173. <td><?php echo $name; ?></td>
  174. <?php
  175. $keyname = strtolower($name);
  176. for($i = 1; $i <= $day_in_mo; $i++) {
  177. $timein = (!empty($new[$i][$keyname][0]))? $new[$i][$keyname][0] : false; ?>
  178.  
  179. <td class="<?php if(is_weekend("{$y}-{$m}-{$i}")) { echo 'weekend'; if(!on_time($timein)) echo ' late'; echo '"'; } else echo 'weekday' ?>"><?php
  180. // Match keys and see if user is listed in that day
  181. echo ($timein != false)? $timein : '<div class="absent">-</div>'; ?></td>
  182. <?php
  183. } ?>
  184. </tr>
  185. <?php
  186. } ?>
  187. </table>
  188.  
  189. $inidate = "$y/$m/01"; //$y and $m chosen by user
  190. $count=0;
  191. foreach ($staff as $key => $team) //row or use count on staff
  192. {
  193. $j=0;
  194. echo "<tr><td>".($count+1).".</td><td>".$team."</td>";
  195. for ($i=0;$i<cal_days_in_month(CAL_GREGORIAN,$m,$y);$i++) //column
  196. {
  197. $cond = FALSE;
  198. while (($dome[$j]['DATEIN'] != "") && ($cond == FALSE))
  199. {
  200. if ($dome[$j]['DATEIN'] == $inidate)
  201. {
  202. if (strtoupper($team) == strtoupper($dome[$j]['NAME']))
  203. {
  204. if ($dome[$j]['TIMEIN'] != "")
  205. {
  206. $cond = TRUE;
  207. if (date("D",strtotime($getdate)) == 'Sun' || date("D",strtotime($getdate)) == 'Sat')
  208. {
  209. //if late output time in yellow cell
  210. if (strtotime($dome[$j]['TIMEIN']) > strtotime('09:10'))
  211. echo "<td BGCOLOR='#ffff00'>".$dome[$j]['TIMEIN']."</td>";
  212. else //output time normally
  213. echo "<td>".$dome[$j]['TIMEIN']."</td>";
  214. }
  215. else //if its weekday outputs gray cell
  216. echo "<td BGCOLOR='#525266'>".$dome[$j]['TIMEIN']."</td>";
  217. }
  218. else
  219. echo "<td>AB</td>";
  220. }
  221. $j++;
  222. }
  223. }
  224. $inidate = strftime("%Y/%m/%d", strtotime("$inidate +1 day"));
  225. echo "</tr>";
  226. }
  227. $count++;
  228. }
  229.  
  230. <?php
  231. $month = "01";
  232. $year = "2015";
  233.  
  234. $staff=array('STAFF A-Full Name',
  235. 'STAFF B-Full Name',
  236. 'STAFF C-Full Name');
  237.  
  238. $dome[]=array('NAME' => 'STAFF A-Full Name',
  239. 'DATEIN' => '2015/01/01' ,
  240. 'TIMEIN' => '09:02');
  241. $dome[]=array('NAME' => 'STAFF A-Full Name',
  242. 'DATEIN' => '2015/01/02',
  243. 'TIMEIN' => '08:30');
  244. $dome[]=array('NAME' => 'STAFF B-Full Name',
  245. 'DATEIN' => '2015/01/01',
  246. 'TIMEIN' => '08:43');
  247. $dome[]=array('NAME' => 'Staff B-Full Name',
  248. 'DATEIN' => '2015/01/03',
  249. 'TIMEIN' => '09:11');
  250.  
  251. echo "<table>";
  252. $countTeam = 0;
  253. foreach ($staff as $key => $team) //row or use count on staff
  254. {
  255. $inidate = "$year/$month/01"; //$year and $month chosen by user
  256.  
  257. echo "<tr><td>".($countTeam + 1).".</td><td>".$team."</td>";
  258. for ($i = 0; $i < cal_days_in_month(CAL_GREGORIAN, $month, $year); $i++) //column
  259. {
  260. $found = false;
  261.  
  262. foreach($dome as $domeKey => $staffAssignment){
  263. if($found){
  264. break;
  265. }
  266.  
  267. if ($staffAssignment['DATEIN'] == $inidate)
  268. {
  269. if (strtoupper($team) == strtoupper($staffAssignment['NAME']))
  270. {
  271. if ($staffAssignment['TIMEIN'] != "")
  272. {
  273. $found = true;
  274. if (date("D", strtotime($inidate)) == 'Sun' || date("D", strtotime($inidate)) == 'Sat')
  275. {
  276. //if late output time in yellow cell
  277. if (strtotime($staffAssignment['TIMEIN']) > strtotime('09:10')){
  278. echo "<td BGCOLOR='#ffff00'>".$staffAssignment['TIMEIN']."</td>";
  279. }
  280. else { //output time normally
  281. echo "<td>".$staffAssignment['TIMEIN']."</td>";
  282. }
  283. }
  284. else { //if its weekday outputs gray cell
  285. echo "<td BGCOLOR='#525266'>".$staffAssignment['TIMEIN']."</td>";
  286. }
  287. }
  288. else {
  289. echo "<td>AB</td>";
  290. }
  291. }
  292. }
  293. }
  294.  
  295. if(!$found){
  296. echo "<td></td>";
  297. }
  298.  
  299. $inidate = strftime("%Y/%m/%d", strtotime("$inidate +1 day"));
  300. }
  301.  
  302. $countTeam++;
  303. echo "</tr>";
  304. }
  305. echo "</table>";
  306. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement