PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 2ms app.codeStats 0ms

/includes/stats.php

https://bitbucket.org/d3bugg3r/shiftsystem
PHP | 110 lines | 99 code | 10 blank | 1 comment | 23 complexity | 46eb68a7131a7c3cdccb20b4848e4dd6 MD5 | raw file
  1. <?
  2. if (isset($_GET['date'])) {
  3. $new = escape($_GET['date']);
  4. $_SESSION['nav_date'] = strtotime($new);
  5. }
  6. $month = date("01-m-Y", $_SESSION['nav_date']);
  7. $d = date("d", $_SESSION['nav_date']);
  8. $m = date("m", $_SESSION['nav_date']);
  9. $y = date("Y", $_SESSION['nav_date']); //these are the numerical values
  10. $mon = date("F", $_SESSION['nav_date']);
  11. $dmonth = strtotime($month); //returns a timestamp for the first day of the selected month
  12. echo "<br /><br /><h2>Displaying User Statistics for $mon $y</h2><br />";
  13. echo "Scheduled hours for $y: " . yearly($g_user, $y). "<br />";
  14. echo "Scheduled monthly hours:&nbsp; " . monthly($g_user, $m, $y);
  15. ?>
  16. <h2>Export your monthly calendar to iCalendar for use in Outlook, Google Calendar, etc.</h2>
  17. <?
  18. $ical="BEGIN:VCALENDAR
  19. ";
  20. //To achieve this, we will consolidate the assigned hours into "shifts" and create events for each
  21. $i = 1;
  22. set_time_limit(1);
  23. while ($i <= 31) { //cycling through the days of the month
  24. $cal = mysql_query("SELECT * FROM hours WHERE worker='$g_user' AND year='$y' AND month='$m' AND day='$i' ORDER BY hour ASC"); //retrieve all the worker's hours for this day
  25. $c=0;
  26. if (mysql_num_rows($cal) != 0) {
  27. while ($row = mysql_fetch_row($cal)) {
  28. $split = $row[4]-$end;
  29. if (($split > 1) && ($c > 0)) { //this is a seperate shift in the same day
  30. if ($i < 10) $i2 = "0$i";
  31. else $i2 = $i;
  32. if ($begin < 10) $begin = "0$begin";
  33. if ($end < 10) $end = "0$end";
  34. $start = "$y$m$i2"."T$begin"."0000";
  35. $end = "$y$m$i2"."T$end"."0000";
  36. $ical_add = "BEGIN:VEVENT
  37. DTSTART:$start
  38. DTEND:$end
  39. SUMMARY:Work
  40. LOCATION:
  41. DESCRIPTION:
  42. PRIORITY:1
  43. END:VEVENT
  44. ";
  45. $ical = "$ical$ical_add";
  46. $c=0; //reset so the next lot is a new "shift"
  47. }
  48. if ($c==0) { //This is the first hour of the shift
  49. $begin = $row[4];
  50. }
  51. $end = $row[4];
  52. $c++;
  53. }
  54. if ($i < 10) $i2 = "0$i";
  55. else $i2 = $i;
  56. if ($begin < 10) $begin = "0$begin";
  57. if ($end < 10) $end = "0$end";
  58. $start = "$y$m$i2"."T$begin"."0000";
  59. $end = "$y$m$i2"."T$end"."0000";
  60. $ical_add = "BEGIN:VEVENT
  61. DTSTART:$start
  62. DTEND:$end
  63. SUMMARY:Work
  64. LOCATION:
  65. DESCRIPTION:
  66. PRIORITY:1
  67. END:VEVENT
  68. ";
  69. $ical = "$ical$ical_add";
  70. }
  71. $i++;
  72. }
  73. $ical = "$ical"."END:VCALENDAR";
  74. $file = fopen("calendars/calendar_$m_$y_$g_user.ics", "w");
  75. fwrite($file, $ical);
  76. echo "Click <a href='calendars/calendar_$m_$y_$g_user.ics'>here</a> to download your calendar file";
  77. ?>
  78. <div id="footer_bg">
  79. <div class="footer">
  80. <div align="center" class="month_nav">
  81. <?
  82. $prev_year = date("Y", strtotime("-1 year", $_SESSION['nav_date']));
  83. $next_year = date("Y", strtotime("+1 year", $_SESSION['nav_date']));
  84. echo "<a class='nav' href='index.php?p=stats&date=01-01-$prev_year'>$prev_year &lt;&lt; -</a>"; //this displays a link to the previous year
  85. $i = 1;
  86. while ($i <=12 ){
  87. $str = "01-$i-$y";
  88. $m = date("F", strtotime($str)); //$m is the textual representation of the current month being used
  89. if (date("n", $_SESSION['nav_date']) == $i) {
  90. echo "<i> $m </i>-";
  91. } else {
  92. echo "<a class='nav' href='index.php?p=stats&date=$str'> $m -</a>";
  93. }
  94. $i++;
  95. }
  96. echo "<a class='nav' href='index.php?p=stats&date=01-01-$next_year'> &gt;&gt; $next_year</a>"; //this displays a link to the next year
  97. ?>
  98. </div>
  99. </div>
  100. </div>