/modules/hours/includes/hours.inc.php
PHP | 255 lines | 238 code | 7 blank | 10 comment | 56 complexity | 0bb45a683c03b4b2f0003301fc4c45fd MD5 | raw file
- <div class="navbar">
- <div class="navbar-inner">
- <div class="container">
- <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-images-collapse">
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </a>
- <a class="brand" href="<?php echo $basehref; ?>images/">Hours</a>
- <div class="nav-collapse nav-images-collapse collapse">
- <ul class="nav nav-pills">
- <li class="active"><a href="#clocked" data-toggle="tab">Clocked</a></li>
- <li><a href="#invoiced" data-toggle="tab">Invoiced</a></li>
- <li><a href="#nonhourly" data-toggle="tab">Non-Hourly</a></li>
- </ul>
- <div class="pull-right">
- <form class="navbar-search">
- <input type="text" id="searchbox" class="search-query" placeholder="Search Hours" data-provide="typeahead">
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="span6 pull-left">
- <input type="button" id="createinvoice" class="btn" value="Invoice" disabled="disabled" />
- </div>
- <div class="span6 pull-right">
- <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>
- </div>
- </div>
- <br clear="all" /><br clear="all" />
- <!--
- <?php
- if(!isset($_POST['doAddHours'])) $_POST['doAddHours'] = "0";
- if($_POST['doAddHours'] == "1" && $link) {
- // add the hours
- $insert_sql = "INSERT INTO hours (
- `task_title`,
- `task_describe`,
- `created`,
- `userid`,
- `milestoneid`,
- `priority`,
- `duedate`,
- `projectid`
- ) VALUES (
- '" . $_POST['task_title'] . "',
- '" . $_POST['task_describe'] . "',
- NOW(),
- '" . $_SESSION['userid_auth'] . "',
- '0',
- '" . $_POST['priority'] . "',
- '" . $_POST['duedate'] . "',
- '" . $projectid . "'
- )";
- //echo $insert_sql . "<br />";
- $q = mysql_query($insert_sql);
- //$_SESSION["command_results"]["addhours"] = "Your hours were added.";
- //display_command_results("addhours");
- }
- // set date format
- if(getSetting("dateFormat", $_SESSION['userid_auth']) == "0") {
- $date_format_setting = "%b %e %Y";
- } else {
- $date_format_setting = getSetting("dateFormat", $_SESSION['userid_auth']);
- }
- if (isset($_POST['search']) && $_POST['search']) {
- $level_auth = getCurrentUserAccessLevel();
- $group_auth = getCurrentUserGroupID();
- $search_project = "Project: ";
- $search_client = "Client: ";
- $search_task = "Task: ";
- // PROJECTS SECTION
- if(substr($_POST['search'], 0, strlen($search_project)) == $search_project) {
- $project_sql = "SELECT id FROM projects WHERE project_name LIKE '%" . str_replace($search_project, "", $_POST['search']) . "%'";
- $project_q = mysql_query($project_sql);
- while($i = mysql_fetch_object($project_q)) {
- $projectid = $i->id;
- }
- $sql = "SELECT hours.`id` AS `id`,
- hours.`taskid` AS `taskid`,
- DATE_FORMAT(hours.`clock_in`, '" . $date_format_setting . ", %l:%i %p') AS `clock_in`,
- DATE_FORMAT(hours.`clock_out`, '" . $date_format_setting . ", %l:%i %p') AS `clock_out`,
- hours.duration,
- hours.invoiced
- FROM hours, tasks, projects, users
- WHERE projects.id='" . $projectid . "'
- AND hours.taskid=tasks.id
- AND projects.id=tasks.projectid
- AND users.id=projects.userid";
- if($level_auth < "11" || ($level_auth == "11" && getSetting("onlyShowProjectsInMyGroup", $_SESSION['userid_auth']) == "1"))
- $sql .= "
- AND users.groupid = '" . $group_auth . "'";
- $sql .= "
- AND hours.invoiced='0'
- AND clock_out!='0000-00-00 00:00:00'
- ORDER BY hours.clock_in DESC";
- $search_text = "Hours for the project <span id=\"searchcriteria\">Project: </span><span id=\"searchterm\">".str_replace($search_project, "", $_POST['search'])."</span>";
- // CLIENTS SECTION
- } elseif(substr($_POST['search'], 0, strlen($search_client)) == $search_client) {
- $client_sql = "SELECT id FROM clients WHERE fullname LIKE '%" . str_replace($search_client, "", $_POST['search']) . "%'";
- $client_q = mysql_query($client_sql);
- while($i = mysql_fetch_object($client_q)) {
- $clientid = $i->id;
- }
- $sql = "SELECT hours.`id` AS `id`,
- hours.`taskid` AS `taskid`,
- DATE_FORMAT(hours.`clock_in`, '" . $date_format_setting . ", %l:%i %p') AS `clock_in`,
- DATE_FORMAT(hours.`clock_out`, '" . $date_format_setting . ", %l:%i %p') AS `clock_out`,
- hours.duration,
- hours.invoiced
- FROM hours, tasks, projects, users
- WHERE projects.clientid='" . $clientid . "'
- AND hours.taskid=tasks.id
- AND projects.id=tasks.projectid
- AND users.id=projects.userid";
- if($level_auth < "11" || ($level_auth == "11" && getSetting("onlyShowProjectsInMyGroup", $_SESSION['userid_auth']) == "1"))
- $sql .= "
- AND users.groupid = '" . $group_auth . "'";
- $sql .= "
- AND hours.invoiced='0'
- AND clock_out!='0000-00-00 00:00:00'
- ORDER BY hours.clock_in DESC";
- $search_text = "Hours for the client <span id=\"searchcriteria\">Client: </span><span id=\"searchterm\">".str_replace($search_client, "", $_POST['search'])."</span>";
- // TASKS SECTION
- } elseif(substr($_POST['search'], 0, strlen($search_task)) == $search_task) {
- $task_sql = "SELECT id FROM tasks WHERE task_title LIKE '%" . str_replace($search_task, "", $_POST['search']) . "%'";
- $task_q = mysql_query($task_sql);
- while($i = mysql_fetch_object($task_q)) {
- $taskid = $i->id;
- }
- $sql = "SELECT hours.`id` AS `id`,
- hours.`taskid` AS `taskid`,
- DATE_FORMAT(hours.`clock_in`, '" . $date_format_setting . ", %l:%i %p') AS `clock_in`,
- DATE_FORMAT(hours.`clock_out`, '" . $date_format_setting . ", %l:%i %p') AS `clock_out`,
- hours.duration,
- hours.invoiced
- FROM hours, tasks, projects, users
- WHERE tasks.id='" . $taskid . "'
- AND hours.taskid=tasks.id
- AND projects.id=tasks.projectid
- AND users.id=projects.userid";
- if($level_auth < "11" || ($level_auth == "11" && getSetting("onlyShowProjectsInMyGroup", $_SESSION['userid_auth']) == "1"))
- $sql .= "
- AND users.groupid = '" . $group_auth . "'";
- $sql .= "
- AND hours.invoiced='0'
- AND clock_out!='0000-00-00 00:00:00'
- ORDER BY hours.clock_in DESC";
- $search_text = "Hours for the task <span id=\"searchcriteria\">Task: </span><span id=\"searchterm\">".str_replace($search_task, "", $_POST['search'])."</span>";
- }
- // NO SEARCH, LOAD EVERYTHING
- } else {
- $sql = "SELECT hours.`id` AS `id`,
- hours.`taskid` AS `taskid`,
- DATE_FORMAT(hours.`clock_in`, '" . $date_format_setting . ", %l:%i %p') AS `clock_in`,
- DATE_FORMAT(hours.`clock_out`, '" . $date_format_setting . ", %l:%i %p') AS `clock_out`,
- hours.duration,
- hours.invoiced,
- projects.project_payment_type
- FROM hours, tasks, projects, users
- WHERE hours.taskid=tasks.id
- AND projects.id=tasks.projectid
- AND users.id=projects.userid";
- if($level_auth < "11" || ($level_auth == "11" && getSetting("onlyShowProjectsInMyGroup", $_SESSION['userid_auth']) == "1"))
- $sql .= "
- AND users.groupid = '" . $group_auth . "'";
- $sql .= "
- AND hours.invoiced='0'
- AND hours.clock_out!='0000-00-00 00:00:00'
- AND projects.project_payment_type='hourly'
- AND hours.invoiced='0'
- ORDER BY hours.clock_in DESC";
- }
- //echo "<pre>".$sql."</pre><br />";
- $q = mysql_query($sql) or die(mysql_error());
- $total_numrows = mysql_num_rows($q);
- if($_POST['search']) echo "<p><strong>" . $search_text . "</strong></p>";
- ?><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>
- <form id="hoursform" method="post" action="/invoices/">
- <input type="hidden" name="invoiceHours" value="1" />
- <table id="hours" class="rowsbox tablesorter" border="0" cellspacing="0" cellpadding="4" summary="">
- <thead>
- <tr>
- <th class="checkbox"><input type="checkbox" class="checkall" /></th>
- <th class="item">Task</th>
- <th>Project</th>
- <th class="datetime">Clocked In</th>
- <th class="datetime">Clocked Out</th>
- <th class="duration">Duration</th>
- <th class="delete"></th>
- </tr>
- </thead>
- <tbody><?php
- if(($_POST['search'] && $total_numrows) || $total_numrows) {
- $j = 0;
- $hourly = 0;
- $invoiced = 0;
- $nonhourly = 0;
- while($i = mysql_fetch_object($q)) {
- $id = $i->id;
- $clock_in = $i->clock_in;
- $clock_out = $i->clock_out;
- $duration = $i->duration;
- $invoiced = $i->invoiced;
- $payment_type = $i->project_payment_type;
- $project_name = getProjectName(getProjectID($i->taskid));
- $task_title = getTaskTitle($i->taskid);
- if($j % 2 == 0) $rowcolor = "row"; else $rowcolor = "altrow";
- if($payment_type == "hourly") {
- if($invoiced == "0"):
- $rowtype = "hourly";
- $hourly++;
- else:
- $rowtype = "invoiced";
- $invoiced++;
- endif;
- } elseif($payment_type == "onetime") {
- $rowtype = "nonhourly";
- $nonhourly++;
- }
- ?>
- <tr id="item_<?php echo $id; ?>" class="<? echo $rowcolor; ?> item_<? echo $id; ?>">
- <td class="checkbox"><?php if($rowtype == "hourly"): ?><input type="checkbox"<? if($invoiced) echo ' checked="checked"'; ?> name="hours[]" value="<? echo $id; ?>" /><? endif; ?></td>
- <td class="task"><?php echo $task_title; ?></td>
- <td><?php echo $project_name; ?></td>
- <td class="datetime"><?php echo $clock_in; ?></td>
- <td class="datetime"><?php echo $clock_out; ?></td>
- <td class="time"><?php echo $duration; ?></td>
- <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>
- </tr>
- <?php
- $j++;
- }
- } elseif($_POST['search'] && !$total_numrows) {
- ?><tr class="notice"><td colspan="8">There are no hours matching your search.</td></tr><?php
- } elseif(!$total_numrows) {
- ?><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
- }
- mysql_close($link);
- ?>
- </tbody>
- <?php if($total_numrows > "10") pagination('8'); ?>
- </table>
- </form>
- -->