PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/src/www/pm/calendar.php

https://github.com/olberger/fusionforge
PHP | 346 lines | 251 code | 36 blank | 59 comment | 88 complexity | c6b0f4b9cf8efc0c484e348f249bd03f MD5 | raw file
  1. <?php
  2. /**
  3. * Project Management Facility : Display Calendar
  4. *
  5. * Copyright 2002 GForge, LLC
  6. * http://fusionforge.org
  7. *
  8. * This file is part of FusionForge.
  9. *
  10. * FusionForge is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * FusionForge is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with FusionForge; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /**
  25. *
  26. * Display a calendar.
  27. * This file displays various sorts of calendars.
  28. *
  29. * @todo some locales start the week with "Monday", and not "Sunday".
  30. * @todo display holidays.
  31. */
  32. require_once('../env.inc.php');
  33. require_once $gfcommon.'include/pre.php';
  34. require_once $gfwww.'pm/include/ProjectGroupHTML.class.php';
  35. $group_id = getIntFromRequest('group_id');
  36. $group_project_id = getIntFromRequest('group_project_id');
  37. $year = getIntFromRequest('year');
  38. $month = getIntFromRequest('month');
  39. $day = getIntFromRequest('day');
  40. $type = getStringFromRequest('type');
  41. // Some sanity checks first.
  42. if ($year && ($year < 1990 || $year > 2020)) {
  43. exit_error(_('Invalid year: Not between 1990 and 2020'),'pm');
  44. }
  45. if ($month && ($month < 1 || $month > 12)) {
  46. exit_error(_('Invalid month: Not between 1 and 12'),'pm');
  47. }
  48. if ($day && ($day < 1 || $day > 31)) {
  49. exit_error(_('Invalid day: Not between 1 and 31'),'pm');
  50. }
  51. if ($year && isset($month) && isset($day)) {
  52. if (!checkdate($month, $day, $year)) {
  53. exit_error(_('Invalid date').sprintf(_('Date not valid'), "$year-$month-$day"),'pm');
  54. }
  55. }
  56. if ($type && $type != 'onemonth' && $type != 'threemonth' && $type != 'currentyear' && $type != 'comingyear') {
  57. exit_error(_('Invalid type: Type not in onemonth, threemonth, currentyear, comingyear'),'pm');
  58. }
  59. // Fill in defaults
  60. if (!$type) {
  61. $type = 'threemonth';
  62. }
  63. $today = getdate(time());
  64. if (!$year) {
  65. $year = $today['year'];
  66. }
  67. if (!$month) {
  68. $month = $today['mon'];
  69. }
  70. if (!$day) {
  71. $day = $today['mday'];
  72. }
  73. $months = array(1 => _('January'), _('February'), _('March'), _('April'), _('May'), _('June'),
  74. _('July'), _('August'), _('September'), _('October'), _('November'), _('December'));
  75. if ($group_id && $group_project_id) {
  76. require_once $gfcommon.'pm/ProjectTaskFactory.class.php';
  77. require_once $gfcommon.'pm/ProjectGroup.class.php';
  78. $g = group_get_object($group_id);
  79. if (!$g || !is_object($g)) {
  80. exit_no_group();
  81. } elseif ($g->isError()) {
  82. exit_error($g->getErrorMessage(),'pm');
  83. }
  84. $pg = new ProjectGroup($g, $group_project_id);
  85. if (!$pg || !is_object($pg)) {
  86. exit_error(_('Error: Could Not Get Factory'),'pm');
  87. } elseif ($pg->isError()) {
  88. exit_error($pg->getErrorMessage(),'pm');
  89. }
  90. $ptf = new ProjectTaskFactory($pg);
  91. if (!$ptf || !is_object($ptf)) {
  92. exit_error(_('Error: Could Not Get ProjectTaskFactory'),'pm');
  93. } elseif ($ptf->isError()) {
  94. exit_error($ptf->getErrorMessage(),'pm');
  95. }
  96. // Violate all known laws about OOP here
  97. $ptf->offset=0;
  98. $ptf->order='start_date';
  99. $ptf->max_rows=50;
  100. $ptf->status=1;
  101. $ptf->assigned_to=0;
  102. $ptf->category=0;
  103. $pt_arr =& $ptf->getTasks();
  104. if ($ptf->isError()) {
  105. exit_error($ptf->getErrorMessage(),'pm');
  106. }
  107. }
  108. pm_header(array('title'=>_('Calendar'),'group'=>$group_id));
  109. /**
  110. * Create link to a task.
  111. * This returns a string that is a link to a particular task.
  112. *
  113. * @author Ryan T. Sammartino <ryants at shaw dot ca>
  114. * @param $task the task to make a link for.
  115. * @param $type either 'begin' for beginning of a task or 'end' for
  116. * end of a task.
  117. * @date 2002-01-04
  118. *
  119. */
  120. function make_task_link($task, $type) {
  121. global $HTML, $group_id, $group_project_id;
  122. return '<a title="'. sprintf(_('Task summary: %s'), $task->getSummary())
  123. . '" href="'.util_make_url ('/pm/task.php?func=detailtask&amp;project_task_id=' . $task->getID() . '&amp;group_id=' . $group_id . '&amp;group_project_id=' .$group_project_id)
  124. . '">' . ($type == 'begin' ?
  125. sprintf(_('Task %d begins'), $task->getID()) :
  126. sprintf(_('Task %d ends'), $task->getID()) )
  127. . '</a>';
  128. }
  129. /**
  130. * Display one month.
  131. * This displays one month. m may be less than 0 and greater than 12: display_month
  132. * uses mktime() to readjust it and the year in such cases.
  133. *
  134. * @author Ryan T. Sammartino <ryants at shaw dot ca>
  135. * @param m month
  136. * @param y year
  137. * @date 2002-12-29
  138. *
  139. */
  140. function display_month($m, $y) {
  141. global $months, $today, $month, $day, $year, $HTML,
  142. $pt_arr, $group_id, $group_project_id;
  143. $dow = array(_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'));
  144. $tstamp = mktime(0, 0, 0, $m + 1, 0, $y) ;
  145. $date = getdate($tstamp);
  146. $days_in_month = $date['mday'];
  147. $date = getdate($tstamp);
  148. $first_dow = $date['wday'];
  149. $m = $date['mon'];
  150. $y = $date['year'];
  151. ?>
  152. <table align="center" cellpadding="1" cellspacing="1" border="1" width="100%">
  153. <tr>
  154. <th colspan="7"><?php echo date (_('F Y'), $tstamp); ?></th>
  155. </tr>
  156. <tr>
  157. <?php
  158. reset($dow);
  159. while (list ($key, $val) = each ($dow)) {
  160. print "\t\t\t<th width=\"14%\">$val</th>\n";
  161. }
  162. ?>
  163. </tr>
  164. <?php
  165. $curr_dow = 0;
  166. $curr_date = 1;
  167. print "\t\t<tr>\n";
  168. while ($curr_dow != $first_dow) {
  169. print "\t\t\t<td></td>\n";
  170. $curr_dow++;
  171. }
  172. while ($curr_date <= $days_in_month) {
  173. while ($curr_dow < 7) {
  174. if ($curr_date <= $days_in_month) {
  175. $colour = "";
  176. if ($curr_date == $today['mday']
  177. && $y == $today['year']
  178. && $m == $today['mon']) {
  179. $colour = "today";
  180. } elseif ($curr_date == $day
  181. && $y == $year
  182. && $m == $month) {
  183. $colour = "day";
  184. }
  185. print "\t\t\t<td valign=\"top\" class=\"" . $colour . "\">$curr_date";
  186. $cell_contents = '';
  187. $rows = count($pt_arr);
  188. for ($i = 0; $i < $rows; $i++) {
  189. $start_date = getdate($pt_arr[$i]->getStartDate());
  190. $end_date = getdate($pt_arr[$i]->getEndDate());
  191. if ($curr_date == $start_date['mday']
  192. && $y == $start_date['year']
  193. && $m == $start_date['mon']) {
  194. $cell_contents .= make_task_link($pt_arr[$i], 'begin');
  195. } elseif ($curr_date == $end_date['mday']
  196. && $y == $end_date['year']
  197. && $m == $end_date['mon']) {
  198. $cell_contents .= make_task_link($pt_arr[$i], 'end');
  199. }
  200. }
  201. if ($cell_contents == '') {
  202. $cell_contents = '<br /><br /><br />';
  203. }
  204. print "$cell_contents</td>\n";
  205. } else {
  206. print "\t\t\t<td></td>\n";
  207. }
  208. $curr_dow++;
  209. $curr_date++;
  210. }
  211. print "\t\t</tr>\n";
  212. if ($curr_date <= $days_in_month) {
  213. print "\t\t<tr>\n";
  214. }
  215. $curr_dow = 0;
  216. }
  217. ?>
  218. </table>
  219. <?php
  220. }
  221. ?>
  222. <form action="/pm/calendar.php" method="get">
  223. <table width="100%">
  224. <tr>
  225. <td><?php echo _('Period'); ?><br />
  226. <select name="type">
  227. <?php
  228. print '
  229. <option value="onemonth"' . ($type == 'onemonth' ? ' selected="selected"' : '') . '>'. _('One month') . '</option>';
  230. print '
  231. <option value="threemonth"' . ($type == 'threemonth' ? ' selected="selected"' : '') . '>'. _('Three month') . '</option>';
  232. print '
  233. <option value="currentyear"' . ($type == 'currentyear' ? ' selected="selected"' : '') . '>' . _('Current year') . '</option>';
  234. print '
  235. <option value="comingyear"' . ($type == 'comingyear' ? ' selected="selected"' : '') . '>' . _('Coming year') . '</option>';
  236. ?>
  237. </select>
  238. </td>
  239. <td><?php echo _('Date'); ?><br />
  240. <select name="year">
  241. <?php
  242. for ($i = 1990; $i < 2020; $i++) {
  243. print "\t\t\t\t<option value=\"$i\"" . ($year == $i ? ' selected="selected"' : '') . ">$i</option>\n";
  244. }
  245. ?>
  246. </select>
  247. <select name="month">
  248. <?php
  249. for ($i = 1; $i <= 12; $i++) {
  250. print "\t\t\t\t<option value=\"$i\"" . ($month == $i ? ' selected="selected"' : '') . ">" . $months[$i] . "</option>\n";
  251. }
  252. ?>
  253. </select>
  254. <select name="day">
  255. <?php
  256. for ($i = 1; $i <= 31; $i++) {
  257. print "\t\t\t\t<option value=\"$i\"" . ($day == $i ? ' selected="selected"' : '') . ">$i</option>\n";
  258. }
  259. ?>
  260. </select>
  261. </td>
  262. <td>
  263. <input type="submit" value="<?php echo _('Update') ?>" />
  264. </td>
  265. </tr>
  266. </table>
  267. <?php
  268. if (isset($group_id) && isset($group_project_id)) {
  269. print '
  270. <input type="hidden" name="group_id" value="'. $group_id .'" />
  271. <input type="hidden" name="group_project_id" value="'. $group_project_id .'" />';
  272. }
  273. ?>
  274. </form>
  275. <table width="100%">
  276. <tr>
  277. <td width="20px" class="selected"></td>
  278. <td><?php echo _('today\'s date') ?></td>
  279. </tr>
  280. <tr>
  281. <td width="20px"></td>
  282. <td><?php echo _('selected date') ?></td>
  283. </tr>
  284. </table>
  285. <?php
  286. if ($type == 'onemonth') {
  287. display_month($month, $year);
  288. } elseif ($type == 'threemonth') {
  289. display_month($month - 1, $year);
  290. print "\t<br />\n\n";
  291. display_month($month, $year);
  292. print "\t<br />\n\n";
  293. display_month($month + 1, $year);
  294. } elseif ($type == 'currentyear') {
  295. for ($i = 1; $i <= 12; $i++) {
  296. display_month($i, $year);
  297. print "\t<br />\n\n";
  298. }
  299. } elseif ($type == 'comingyear') {
  300. for ($i = 0; $i < 12; $i++) {
  301. display_month($month + $i, $year);
  302. print "\t<br />\n\n";
  303. }
  304. }
  305. pm_footer(array());
  306. // Local Variables:
  307. // mode: php
  308. // c-file-style: "bsd"
  309. // End:
  310. ?>