PageRenderTime 107ms CodeModel.GetById 37ms RepoModel.GetById 3ms app.codeStats 0ms

/modules/hours/includes/hours.inc.php

https://bitbucket.org/websightdesigns/project-manager
PHP | 255 lines | 238 code | 7 blank | 10 comment | 56 complexity | 0bb45a683c03b4b2f0003301fc4c45fd MD5 | raw file
  1. <div class="navbar">
  2. <div class="navbar-inner">
  3. <div class="container">
  4. <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-images-collapse">
  5. <span class="icon-bar"></span>
  6. <span class="icon-bar"></span>
  7. <span class="icon-bar"></span>
  8. </a>
  9. <a class="brand" href="<?php echo $basehref; ?>images/">Hours</a>
  10. <div class="nav-collapse nav-images-collapse collapse">
  11. <ul class="nav nav-pills">
  12. <li class="active"><a href="#clocked" data-toggle="tab">Clocked</a></li>
  13. <li><a href="#invoiced" data-toggle="tab">Invoiced</a></li>
  14. <li><a href="#nonhourly" data-toggle="tab">Non-Hourly</a></li>
  15. </ul>
  16. <div class="pull-right">
  17. <form class="navbar-search">
  18. <input type="text" id="searchbox" class="search-query" placeholder="Search Hours" data-provide="typeahead">
  19. </form>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <div class="row">
  26. <div class="span6 pull-left">
  27. <input type="button" id="createinvoice" class="btn" value="Invoice" disabled="disabled" />
  28. </div>
  29. <div class="span6 pull-right">
  30. <button href="#addImage" role="button" class="btn btn-success pull-right" type="button" data-toggle="modal"><i class="icon-plus icon-white"></i> Add A New Image</button>
  31. </div>
  32. </div>
  33. <br clear="all" /><br clear="all" />
  34. <!--
  35. <?php
  36. if(!isset($_POST['doAddHours'])) $_POST['doAddHours'] = "0";
  37. if($_POST['doAddHours'] == "1" && $link) {
  38. // add the hours
  39. $insert_sql = "INSERT INTO hours (
  40. `task_title`,
  41. `task_describe`,
  42. `created`,
  43. `userid`,
  44. `milestoneid`,
  45. `priority`,
  46. `duedate`,
  47. `projectid`
  48. ) VALUES (
  49. '" . $_POST['task_title'] . "',
  50. '" . $_POST['task_describe'] . "',
  51. NOW(),
  52. '" . $_SESSION['userid_auth'] . "',
  53. '0',
  54. '" . $_POST['priority'] . "',
  55. '" . $_POST['duedate'] . "',
  56. '" . $projectid . "'
  57. )";
  58. //echo $insert_sql . "<br />";
  59. $q = mysql_query($insert_sql);
  60. //$_SESSION["command_results"]["addhours"] = "Your hours were added.";
  61. //display_command_results("addhours");
  62. }
  63. // set date format
  64. if(getSetting("dateFormat", $_SESSION['userid_auth']) == "0") {
  65. $date_format_setting = "%b %e %Y";
  66. } else {
  67. $date_format_setting = getSetting("dateFormat", $_SESSION['userid_auth']);
  68. }
  69. if (isset($_POST['search']) && $_POST['search']) {
  70. $level_auth = getCurrentUserAccessLevel();
  71. $group_auth = getCurrentUserGroupID();
  72. $search_project = "Project: ";
  73. $search_client = "Client: ";
  74. $search_task = "Task: ";
  75. // PROJECTS SECTION
  76. if(substr($_POST['search'], 0, strlen($search_project)) == $search_project) {
  77. $project_sql = "SELECT id FROM projects WHERE project_name LIKE '%" . str_replace($search_project, "", $_POST['search']) . "%'";
  78. $project_q = mysql_query($project_sql);
  79. while($i = mysql_fetch_object($project_q)) {
  80. $projectid = $i->id;
  81. }
  82. $sql = "SELECT hours.`id` AS `id`,
  83. hours.`taskid` AS `taskid`,
  84. DATE_FORMAT(hours.`clock_in`, '" . $date_format_setting . ", %l:%i %p') AS `clock_in`,
  85. DATE_FORMAT(hours.`clock_out`, '" . $date_format_setting . ", %l:%i %p') AS `clock_out`,
  86. hours.duration,
  87. hours.invoiced
  88. FROM hours, tasks, projects, users
  89. WHERE projects.id='" . $projectid . "'
  90. AND hours.taskid=tasks.id
  91. AND projects.id=tasks.projectid
  92. AND users.id=projects.userid";
  93. if($level_auth < "11" || ($level_auth == "11" && getSetting("onlyShowProjectsInMyGroup", $_SESSION['userid_auth']) == "1"))
  94. $sql .= "
  95. AND users.groupid = '" . $group_auth . "'";
  96. $sql .= "
  97. AND hours.invoiced='0'
  98. AND clock_out!='0000-00-00 00:00:00'
  99. ORDER BY hours.clock_in DESC";
  100. $search_text = "Hours for the project <span id=\"searchcriteria\">Project: </span><span id=\"searchterm\">".str_replace($search_project, "", $_POST['search'])."</span>";
  101. // CLIENTS SECTION
  102. } elseif(substr($_POST['search'], 0, strlen($search_client)) == $search_client) {
  103. $client_sql = "SELECT id FROM clients WHERE fullname LIKE '%" . str_replace($search_client, "", $_POST['search']) . "%'";
  104. $client_q = mysql_query($client_sql);
  105. while($i = mysql_fetch_object($client_q)) {
  106. $clientid = $i->id;
  107. }
  108. $sql = "SELECT hours.`id` AS `id`,
  109. hours.`taskid` AS `taskid`,
  110. DATE_FORMAT(hours.`clock_in`, '" . $date_format_setting . ", %l:%i %p') AS `clock_in`,
  111. DATE_FORMAT(hours.`clock_out`, '" . $date_format_setting . ", %l:%i %p') AS `clock_out`,
  112. hours.duration,
  113. hours.invoiced
  114. FROM hours, tasks, projects, users
  115. WHERE projects.clientid='" . $clientid . "'
  116. AND hours.taskid=tasks.id
  117. AND projects.id=tasks.projectid
  118. AND users.id=projects.userid";
  119. if($level_auth < "11" || ($level_auth == "11" && getSetting("onlyShowProjectsInMyGroup", $_SESSION['userid_auth']) == "1"))
  120. $sql .= "
  121. AND users.groupid = '" . $group_auth . "'";
  122. $sql .= "
  123. AND hours.invoiced='0'
  124. AND clock_out!='0000-00-00 00:00:00'
  125. ORDER BY hours.clock_in DESC";
  126. $search_text = "Hours for the client <span id=\"searchcriteria\">Client: </span><span id=\"searchterm\">".str_replace($search_client, "", $_POST['search'])."</span>";
  127. // TASKS SECTION
  128. } elseif(substr($_POST['search'], 0, strlen($search_task)) == $search_task) {
  129. $task_sql = "SELECT id FROM tasks WHERE task_title LIKE '%" . str_replace($search_task, "", $_POST['search']) . "%'";
  130. $task_q = mysql_query($task_sql);
  131. while($i = mysql_fetch_object($task_q)) {
  132. $taskid = $i->id;
  133. }
  134. $sql = "SELECT hours.`id` AS `id`,
  135. hours.`taskid` AS `taskid`,
  136. DATE_FORMAT(hours.`clock_in`, '" . $date_format_setting . ", %l:%i %p') AS `clock_in`,
  137. DATE_FORMAT(hours.`clock_out`, '" . $date_format_setting . ", %l:%i %p') AS `clock_out`,
  138. hours.duration,
  139. hours.invoiced
  140. FROM hours, tasks, projects, users
  141. WHERE tasks.id='" . $taskid . "'
  142. AND hours.taskid=tasks.id
  143. AND projects.id=tasks.projectid
  144. AND users.id=projects.userid";
  145. if($level_auth < "11" || ($level_auth == "11" && getSetting("onlyShowProjectsInMyGroup", $_SESSION['userid_auth']) == "1"))
  146. $sql .= "
  147. AND users.groupid = '" . $group_auth . "'";
  148. $sql .= "
  149. AND hours.invoiced='0'
  150. AND clock_out!='0000-00-00 00:00:00'
  151. ORDER BY hours.clock_in DESC";
  152. $search_text = "Hours for the task <span id=\"searchcriteria\">Task: </span><span id=\"searchterm\">".str_replace($search_task, "", $_POST['search'])."</span>";
  153. }
  154. // NO SEARCH, LOAD EVERYTHING
  155. } else {
  156. $sql = "SELECT hours.`id` AS `id`,
  157. hours.`taskid` AS `taskid`,
  158. DATE_FORMAT(hours.`clock_in`, '" . $date_format_setting . ", %l:%i %p') AS `clock_in`,
  159. DATE_FORMAT(hours.`clock_out`, '" . $date_format_setting . ", %l:%i %p') AS `clock_out`,
  160. hours.duration,
  161. hours.invoiced,
  162. projects.project_payment_type
  163. FROM hours, tasks, projects, users
  164. WHERE hours.taskid=tasks.id
  165. AND projects.id=tasks.projectid
  166. AND users.id=projects.userid";
  167. if($level_auth < "11" || ($level_auth == "11" && getSetting("onlyShowProjectsInMyGroup", $_SESSION['userid_auth']) == "1"))
  168. $sql .= "
  169. AND users.groupid = '" . $group_auth . "'";
  170. $sql .= "
  171. AND hours.invoiced='0'
  172. AND hours.clock_out!='0000-00-00 00:00:00'
  173. AND projects.project_payment_type='hourly'
  174. AND hours.invoiced='0'
  175. ORDER BY hours.clock_in DESC";
  176. }
  177. //echo "<pre>".$sql."</pre><br />";
  178. $q = mysql_query($sql) or die(mysql_error());
  179. $total_numrows = mysql_num_rows($q);
  180. if($_POST['search']) echo "<p><strong>" . $search_text . "</strong></p>";
  181. ?><p class="filterlinks"><a href="" id="clocked_link">Clocked</a><span id="clocked_text">Clocked</span> | <a href="" id="invoiced_link">Invoiced</a><span id="invoiced_text">Invoiced</span> | <a href="" id="nonhourly_link">Non-Hourly</a><span id="nonhourly_text">Non-Hourly</span></p>
  182. <form id="hoursform" method="post" action="/invoices/">
  183. <input type="hidden" name="invoiceHours" value="1" />
  184. <table id="hours" class="rowsbox tablesorter" border="0" cellspacing="0" cellpadding="4" summary="">
  185. <thead>
  186. <tr>
  187. <th class="checkbox"><input type="checkbox" class="checkall" /></th>
  188. <th class="item">Task</th>
  189. <th>Project</th>
  190. <th class="datetime">Clocked In</th>
  191. <th class="datetime">Clocked Out</th>
  192. <th class="duration">Duration</th>
  193. <th class="delete"></th>
  194. </tr>
  195. </thead>
  196. <tbody><?php
  197. if(($_POST['search'] && $total_numrows) || $total_numrows) {
  198. $j = 0;
  199. $hourly = 0;
  200. $invoiced = 0;
  201. $nonhourly = 0;
  202. while($i = mysql_fetch_object($q)) {
  203. $id = $i->id;
  204. $clock_in = $i->clock_in;
  205. $clock_out = $i->clock_out;
  206. $duration = $i->duration;
  207. $invoiced = $i->invoiced;
  208. $payment_type = $i->project_payment_type;
  209. $project_name = getProjectName(getProjectID($i->taskid));
  210. $task_title = getTaskTitle($i->taskid);
  211. if($j % 2 == 0) $rowcolor = "row"; else $rowcolor = "altrow";
  212. if($payment_type == "hourly") {
  213. if($invoiced == "0"):
  214. $rowtype = "hourly";
  215. $hourly++;
  216. else:
  217. $rowtype = "invoiced";
  218. $invoiced++;
  219. endif;
  220. } elseif($payment_type == "onetime") {
  221. $rowtype = "nonhourly";
  222. $nonhourly++;
  223. }
  224. ?>
  225. <tr id="item_<?php echo $id; ?>" class="<? echo $rowcolor; ?> item_<? echo $id; ?>">
  226. <td class="checkbox"><?php if($rowtype == "hourly"): ?><input type="checkbox"<? if($invoiced) echo ' checked="checked"'; ?> name="hours[]" value="<? echo $id; ?>" /><? endif; ?></td>
  227. <td class="task"><?php echo $task_title; ?></td>
  228. <td><?php echo $project_name; ?></td>
  229. <td class="datetime"><?php echo $clock_in; ?></td>
  230. <td class="datetime"><?php echo $clock_out; ?></td>
  231. <td class="time"><?php echo $duration; ?></td>
  232. <td class="delete"><?php if($rowtype == "hourly"): ?><a href="" id="<? echo $id; ?>"><img src="/img/icons/button-delete.png" border="0" alt="" /></a><? endif; ?></td>
  233. </tr>
  234. <?php
  235. $j++;
  236. }
  237. } elseif($_POST['search'] && !$total_numrows) {
  238. ?><tr class="notice"><td colspan="8">There are no hours matching your search.</td></tr><?php
  239. } elseif(!$total_numrows) {
  240. ?><tr class="notice"><td colspan="8">No hours have been tracked yet. Select a task from the tasks page and then use the "Clock In" button to track your time.</td></tr><?php
  241. }
  242. mysql_close($link);
  243. ?>
  244. </tbody>
  245. <?php if($total_numrows > "10") pagination('8'); ?>
  246. </table>
  247. </form>
  248. -->