public static function get_list($_FORM) { /* * * Get a list of task history items with sophisticated filtering and somewhat sophisticated output * * (n.b., the output from this generally needs to be post-processed to handle the semantic meaning of changes in various fields) * */ $filter = audit::get_list_filter($_FORM); if (is_array($filter) && count($filter)) { $where_clause = " WHERE " . implode(" AND ", $filter); } if ($_FORM["projectID"]) { $entity = new project(); $entity->set_id($_FORM["projectID"]); $entity->select(); } else { if ($_FORM["taskID"]) { $entity = new task(); $entity->set_id($_FORM["taskID"]); $entity->select(); } } $q = "SELECT *\n FROM audit\n {$where_clause}\n ORDER BY dateChanged"; $db = new db_alloc(); $db->query($q); $items = array(); while ($row = $db->next_record()) { $audit = new audit(); $audit->read_db_record($db); $rows[] = $row; } return $rows; }
/** * Get all the commments on a task * @param string $taskID * @return array an array of comments */ public function get_task_comments($taskID) { if ($taskID) { $task = new task(); $task->set_id($taskID); $task->select(); return $task->get_task_comments_array(); } }
function add_tsiHint($stuff) { $current_user =& singleton("current_user"); $errstr = "Failed to record new time sheet item hint. "; $username = $stuff["username"]; $people = person::get_people_by_username(); $personID = $people[$username]["personID"]; $personID or alloc_error("Person " . $username . " not found."); $taskID = $stuff["taskID"]; $projectID = $stuff["projectID"]; $duration = $stuff["duration"]; $comment = $stuff["comment"]; $date = $stuff["date"]; if ($taskID) { $task = new task(); $task->set_id($taskID); $task->select(); $projectID = $task->get_value("projectID"); $extra = " for task " . $taskID; } $projectID or alloc_error(sprintf($errstr . "No project found%s.", $extra)); $row_projectPerson = projectPerson::get_projectPerson_row($projectID, $current_user->get_id()); $row_projectPerson or alloc_error($errstr . "The person(" . $current_user->get_id() . ") has not been added to the project(" . $projectID . ")."); if ($row_projectPerson && $projectID) { // Add new time sheet item $tsiHint = new tsiHint(); $d = $date or $d = date("Y-m-d"); $tsiHint->set_value("date", $d); $tsiHint->set_value("duration", $duration); if (is_object($task)) { $tsiHint->set_value("taskID", sprintf("%d", $taskID)); } $tsiHint->set_value("personID", $personID); $tsiHint->set_value("comment", $comment); $tsiHint->save(); $ID = $tsiHint->get_id(); } if ($ID) { return array("status" => "yay", "message" => $ID); } else { alloc_error($errstr . "Time hint not added."); } }
* You should have received a copy of the GNU Affero General Public License * along with allocPSA. If not, see <http://www.gnu.org/licenses/>. */ define("NO_REDIRECT", 1); require_once "../alloc.php"; //usleep(1000); $t = timeSheetItem::parse_time_string($_REQUEST["time_item"]); $timeUnit = new timeUnit(); $units = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA"); $timeSheetItemMultiplier = new meta("timeSheetItemMultiplier"); $tsims = $timeSheetItemMultiplier->get_list(); foreach ($t as $k => $v) { if ($v) { if ($k == "taskID") { $task = new task(); $task->set_id($v); if ($task->select()) { $v = $task->get_id() . " " . $task->get_link(); } else { $v = "Task " . $v . " not found."; } } else { if ($k == "unit") { $v = $units[$v]; } else { if ($k == "multiplier") { $v = $tsims[sprintf("%0.2f", $v)]["timeSheetItemMultiplierName"]; } } } $rtn[$k] = $v;
function get_project_id() { $this->select(); if ($this->get_value("commentType") == "task" && $this->get_value("commentLinkID")) { $t = new task(); $t->set_id($this->get_value("commentLinkID")); $t->select(); $projectID = $t->get_value("projectID"); } else { if ($this->get_value("commentType") == "project" && $this->get_value("commentLinkID")) { $projectID = $this->get_value("commentLinkID"); } else { if ($this->get_value("commentType") == "timeSheet" && $this->get_value("commentLinkID")) { $t = new timeSheet(); $t->set_id($this->get_value("commentLinkID")); $t->select(); $projectID = $t->get_value("projectID"); } } } return $projectID; }
$TPL["main_alloc_title"] = "Task List - " . APPLICATION_NAME; $defaults = array("showHeader" => true, "showTaskID" => true, "showEdit" => true, "taskView" => "byProject", "showStatus" => "true", "showTotals" => "true", "padding" => 1, "url_form_action" => $TPL["url_alloc_taskList"], "form_name" => "taskList_filter"); // Load task list $_FORM = task::load_form_data($defaults); $TPL["taskListRows"] = task::get_list($_FORM); $TPL["_FORM"] = $_FORM; // Load filter $arr = task::load_task_filter($_FORM); is_array($arr) and $TPL = array_merge($TPL, $arr); // Check for updates if ($_POST["mass_update"]) { if ($_POST["select"]) { $allowed_auto_fields = array("dateTargetStart", "dateTargetCompletion", "dateActualStart", "dateActualCompletion", "managerID", "timeLimit", "timeBest", "timeWorst", "timeExpected", "priority", "taskTypeID", "taskStatus", "personID"); foreach ($_POST["select"] as $taskID => $selected) { $task = new task(); $task->set_id($taskID); $task->select(); // Special case: projectID and parentTaskID have to be done together if ($_POST["update_action"] == "projectIDAndParentTaskID") { // Can't set self to be parent if ($_POST["parentTaskID"] != $task->get_id()) { $task->set_value("parentTaskID", $_POST["parentTaskID"]); } // If task is a parent, change the project of that tasks children if ($_POST["projectID"] != $task->get_value("projectID") && $task->get_value("taskTypeID") == "Parent") { $task->update_children("projectID", $_POST["projectID"]); } $task->set_value("projectID", $_POST["projectID"]); $task->updateSearchIndexLater = true; $task->save(); // All other cases are generic and can be handled by a single clause
* Copyright (C) 2006-2011 Alex Lance, Clancy Malcolm, Cyber IT Solutions * Pty. Ltd. * * This file is part of the allocPSA application <*****@*****.**>. * * allocPSA is free software: you can redistribute it and/or modify it * under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at * your option) any later version. * * allocPSA is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public * License for more details. * * You should have received a copy of the GNU Affero General Public License * along with allocPSA. If not, see <http://www.gnu.org/licenses/>. */ define("NO_REDIRECT", 1); require_once "../alloc.php"; #if ($_GET["projectID"]) { usleep(500000); if ($_GET["taskID"]) { $task = new task(); $task->set_id($_GET["taskID"]); $task->select(); echo $task->get_task_cc_list_select($_GET["projectID"]); } else { echo task::get_task_cc_list_select($_GET["projectID"]); } #}
unset($st1, $st2); if (substr($realtask->get_value("taskStatus"), 0, 6) == "closed") { $st1 = "<strike>"; $st2 = "</strike>"; } else { $wasopen = true; } $pendingTaskLinks[] = $st1 . $realtask->get_task_link(array("prefixTaskID" => 1, "return" => "html")) . $st2; } $is = "was"; $wasopen and $is = "is"; $pendingTaskLinks and $TPL["message_help_no_esc"][] = "This task " . $is . " pending the completion of:<br>" . implode("<br>", $pendingTaskLinks); $rows = $task->get_pending_tasks(true); foreach ((array) $rows as $tID) { $realtask = new task(); $realtask->set_id($tID); $realtask->select(); unset($st1, $st2); if (substr($realtask->get_value("taskStatus"), 0, 6) == "closed") { $st1 = "<strike>"; $st2 = "</strike>"; } else { $wasopen = true; } $blockTaskLinks[] = $st1 . $realtask->get_task_link(array("prefixTaskID" => 1, "return" => "html")) . $st2; } $is = "was"; $wasopen and $is = "is"; $blockTaskLinks and $TPL["message_help_no_esc"][] = "This task " . $is . " blocking the start of:<br>" . implode("<br>", $blockTaskLinks); if (in_str("pending_", $task->get_value("taskStatus"))) { $rows = $task->get_reopen_reminders();
function set_option_tpl_values() { // Set template values to provide options for edit selects global $TPL; $current_user =& singleton("current_user"); global $isMessage; $db = new db_alloc(); $projectID = $_GET["projectID"] or $projectID = $this->get_value("projectID"); $TPL["personOptions"] = "<select name=\"personID\"><option value=\"\">" . $this->get_personList_dropdown($projectID, "personID") . "</select>"; $TPL["managerPersonOptions"] = "<select name=\"managerID\"><option value=\"\">" . $this->get_personList_dropdown($projectID, "managerID") . "</select>"; $TPL["estimatorPersonOptions"] = "<select name=\"estimatorID\"><option value=\"\">" . $this->get_personList_dropdown($projectID, "estimatorID") . "</select>"; // TaskType Options $taskType = new meta("taskType"); $taskType_array = $taskType->get_assoc_array("taskTypeID", "taskTypeID"); $TPL["taskTypeOptions"] = page::select_options($taskType_array, $this->get_value("taskTypeID")); // Project dropdown $TPL["projectOptions"] = task::get_project_options($projectID); // We're building these two with the <select> tags because they will be // replaced by an AJAX created dropdown when the projectID changes. $TPL["parentTaskOptions"] = $this->get_parent_task_select(); $TPL["interestedPartyOptions"] = $this->get_task_cc_list_select(); $db->query(prepare("SELECT fullName, emailAddress, clientContactPhone, clientContactMobile\n FROM interestedParty\n LEFT JOIN clientContact ON interestedParty.clientContactID = clientContact.clientContactID\n WHERE entity='task' \n AND entityID = %d\n AND interestedPartyActive = 1\n ORDER BY fullName", $this->get_id())); while ($db->next_record()) { $value = interestedParty::get_encoded_interested_party_identifier($db->f("fullName"), $db->f("emailAddress")); $phone = array("p" => $db->f('clientContactPhone'), "m" => $db->f('clientContactMobile')); $TPL["interestedParties"][] = array('key' => $value, 'name' => $db->f("fullName"), 'email' => $db->f("emailAddress"), 'phone' => $phone); } $TPL["task_taskStatusLabel"] = $this->get_task_status("label"); $TPL["task_taskStatusColour"] = $this->get_task_status("colour"); $TPL["task_taskStatusValue"] = $this->get_value("taskStatus"); $TPL["task_taskStatusOptions"] = page::select_options(task::get_task_statii_array(true), $this->get_value("taskStatus")); // Project label if (has("project")) { $p = new project(); $p->set_id($this->get_value("projectID")); $p->select(); $TPL["projectName"] = $p->get_display_value(); } $taskPriorities = config::get_config_item("taskPriorities") or $taskPriorities = array(); $projectPriorities = config::get_config_item("projectPriorities") or $projectPriorities = array(); $priority = $this->get_value("priority") or $priority = 3; $TPL["priorityOptions"] = page::select_options(array_kv($taskPriorities, null, "label"), $priority); $TPL["priorityLabel"] = " <div style=\"display:inline; color:" . $taskPriorities[$priority]["colour"] . "\">["; if (is_object($p)) { list($priorityFactor, $daysUntilDue) = $this->get_overall_priority($p->get_value("projectPriority"), $this->get_value("priority"), $this->get_value("dateTargetCompletion")); $str = "Task priority: " . $taskPriorities[$this->get_value("priority")]["label"] . "<br>"; $str .= "Project priority: " . $projectPriorities[$p->get_value("projectPriority")]["label"] . "<br>"; $str .= "Days until due: " . $daysUntilDue . "<br>"; $str .= "Calculated priority: " . $priorityFactor; $TPL["priorityLabel"] .= page::help($str, $this->get_priority_label()); } else { $TPL["priorityLabel"] .= $this->get_priority_label(); } $TPL["priorityLabel"] .= "]</div>"; // If we're viewing the printer friendly view if ($_GET["media"] == "print") { // Parent Task label $t = new task(); $t->set_id($this->get_value("parentTaskID")); $t->select(); $TPL["parentTask"] = $t->get_display_value(); // Task Type label $TPL["taskType"] = $this->get_value("taskTypeID"); // Priority $TPL["priority"] = $this->get_value("priority"); // Assignee label $p = new person(); $p->set_id($this->get_value("personID")); $p->select(); $TPL["person"] = $p->get_display_value(); } }
function show_timeSheet_list($template) { global $TPL; global $timeSheet; global $db; global $tskDesc; global $timeSheetItem; global $timeSheetID; $db_task = new db_alloc(); if (is_object($timeSheet) && ($timeSheet->get_value("status") == "edit" || $timeSheet->get_value("status") == "rejected")) { $TPL["timeSheetItem_buttons"] = ' <button type="submit" name="timeSheetItem_delete" value="1" class="delete_button">Delete<i class="icon-trash"></i></button> <button type="submit" name="timeSheetItem_edit" value="1">Edit<i class="icon-edit"></i></button>'; } $TPL["currency"] = page::money($timeSheet->get_value("currencyTypeID"), '', "%S"); $timeUnit = new timeUnit(); $unit_array = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA"); $item_query = prepare("SELECT * from timeSheetItem WHERE timeSheetID=%d", $timeSheetID); // If editing a timeSheetItem then don't display it in the list $timeSheetItemID = $_POST["timeSheetItemID"] or $timeSheetItemID = $_GET["timeSheetItemID"]; $timeSheetItemID and $item_query .= prepare(" AND timeSheetItemID != %d", $timeSheetItemID); $item_query .= prepare(" GROUP BY timeSheetItemID ORDER BY dateTimeSheetItem, timeSheetItemID"); $db->query($item_query); if (is_object($timeSheet)) { $project = $timeSheet->get_foreign_object("project"); $row_projectPerson = projectPerson::get_projectPerson_row($project->get_id(), $timeSheet->get_value("personID")); $default_rate = array(); if ($row_projectPerson && $row_projectPerson['rate'] > 0) { $default_rate['rate'] = $row_projectPerson['rate']; $default_rate['unit'] = $row_projectPerson['rateUnitID']; } } while ($db->next_record()) { $timeSheetItem = new timeSheetItem(); $timeSheetItem->currency = $timeSheet->get_value("currencyTypeID"); $timeSheetItem->read_db_record($db); $timeSheetItem->set_tpl_values("timeSheetItem_"); $TPL["timeSheet_totalHours"] += $timeSheetItem->get_value("timeSheetItemDuration"); $TPL["unit"] = $unit_array[$timeSheetItem->get_value("timeSheetItemDurationUnitID")]; $br = ""; $commentPrivateText = ""; $text = $timeSheetItem->get_value('description', DST_HTML_DISPLAY); if ($timeSheetItem->get_value("commentPrivate")) { $commentPrivateText = "<b>[Private Comment]</b> "; } $text and $TPL["timeSheetItem_description"] = "<a href=\"" . $TPL["url_alloc_task"] . "taskID=" . $timeSheetItem->get_value('taskID') . "\">" . $text . "</a>"; $text && $timeSheetItem->get_value("comment") and $br = "<br>"; $timeSheetItem->get_value("comment") and $TPL["timeSheetItem_comment"] = $br . $commentPrivateText . page::to_html($timeSheetItem->get_value("comment")); $TPL["timeSheetItem_unit_times_rate"] = $timeSheetItem->calculate_item_charge($timeSheet->get_value("currencyTypeID"), $timeSheetItem->get_value("rate")); $m = new meta("timeSheetItemMultiplier"); $tsMultipliers = $m->get_list(); $timeSheetItem->get_value('multiplier') and $TPL["timeSheetItem_multiplier"] = $tsMultipliers[$timeSheetItem->get_value('multiplier')]['timeSheetItemMultiplierName']; // Check to see if this tsi is part of an overrun $TPL["timeSheetItem_class"] = "panel"; $TPL["timeSheetItem_status"] = ""; $row_messages = array(); if ($timeSheetItem->get_value('taskID')) { $task = new task(); $task->set_id($timeSheetItem->get_value('taskID')); $task->select(); if ($task->get_value('timeLimit') > 0) { $total_billed_time = $task->get_time_billed(false) / 3600; // get_time_billed returns seconds, limit hours is in hours if ($total_billed_time > $task->get_value('timeLimit')) { $row_messages[] = "<em class='faint warn nobr'>[ Exceeds Limit ]</em>"; } } } // Highlight the rate if the project person has a non-zero rate and it doesn't match the item's rate if ($default_rate) { if ($timeSheetItem->get_value('rate') != $default_rate['rate'] || $timeSheetItem->get_value('timeSheetItemDurationUnitID') != $default_rate['unit']) { $row_messages[] = "<em class='faint warn nobr'>[ Modified rate ]</em>"; } } if ($row_messages) { $TPL["timeSheetItem_status"] = implode("<br />", $row_messages); $TPL["timeSheetItem_class"] = "panel loud"; } include_template($template); } $TPL["summary_totals"] = $timeSheet->pay_info["summary_unit_totals"]; }
function add_timeSheetItem($stuff) { $current_user =& singleton("current_user"); $errstr = "Failed to record new time sheet item. "; $taskID = $stuff["taskID"]; $projectID = $stuff["projectID"]; $duration = $stuff["duration"]; $comment = $stuff["comment"]; $emailUID = $stuff["msg_uid"]; $emailMessageID = $stuff["msg_id"]; $date = $stuff["date"]; $unit = $stuff["unit"]; $multiplier = $stuff["multiplier"]; if ($taskID) { $task = new task(); $task->set_id($taskID); $task->select(); $projectID = $task->get_value("projectID"); $extra = " for task " . $taskID; } $projectID or alloc_error(sprintf($errstr . "No project found%s.", $extra)); $row_projectPerson = projectPerson::get_projectPerson_row($projectID, $current_user->get_id()); $row_projectPerson or alloc_error($errstr . "The person(" . $current_user->get_id() . ") has not been added to the project(" . $projectID . ")."); if ($row_projectPerson && $projectID) { if ($stuff["timeSheetID"]) { $q = prepare("SELECT *\n FROM timeSheet\n WHERE status = 'edit'\n AND personID = %d\n AND timeSheetID = %d\n ORDER BY dateFrom\n LIMIT 1\n ", $current_user->get_id(), $stuff["timeSheetID"]); $db = new db_alloc(); $db->query($q); $row = $db->row(); $row or alloc_error("Couldn't find an editable time sheet with that ID."); } else { $q = prepare("SELECT *\n FROM timeSheet\n WHERE status = 'edit'\n AND projectID = %d\n AND personID = %d\n ORDER BY dateFrom\n LIMIT 1\n ", $projectID, $current_user->get_id()); $db = new db_alloc(); $db->query($q); $row = $db->row(); } // If no timeSheets add a new one if (!$row) { $project = new project(); $project->set_id($projectID); $project->select(); $timeSheet = new timeSheet(); $timeSheet->set_value("projectID", $projectID); $timeSheet->set_value("status", "edit"); $timeSheet->set_value("personID", $current_user->get_id()); $timeSheet->set_value("recipient_tfID", $current_user->get_value("preferred_tfID")); $timeSheet->set_value("customerBilledDollars", page::money($project->get_value("currencyTypeID"), $project->get_value("customerBilledDollars"), "%mo")); $timeSheet->set_value("currencyTypeID", $project->get_value("currencyTypeID")); $timeSheet->save(); $timeSheetID = $timeSheet->get_id(); // Else use the first timesheet we found } else { $timeSheetID = $row["timeSheetID"]; } $timeSheetID or alloc_error($errstr . "Couldn't locate an existing, or create a new Time Sheet."); // Add new time sheet item if ($timeSheetID) { $timeSheet = new timeSheet(); $timeSheet->set_id($timeSheetID); $timeSheet->select(); $tsi = new timeSheetItem(); $tsi->currency = $timeSheet->get_value("currencyTypeID"); $tsi->set_value("timeSheetID", $timeSheetID); $d = $date or $d = date("Y-m-d"); $tsi->set_value("dateTimeSheetItem", $d); $tsi->set_value("timeSheetItemDuration", $duration); $tsi->set_value("timeSheetItemDurationUnitID", $unit); if (is_object($task)) { $tsi->set_value("description", $task->get_name()); $tsi->set_value("taskID", sprintf("%d", $taskID)); $_POST["timeSheetItem_taskID"] = sprintf("%d", $taskID); // this gets used in timeSheetItem->save(); } $tsi->set_value("personID", $current_user->get_id()); $tsi->set_value("rate", page::money($timeSheet->get_value("currencyTypeID"), $row_projectPerson["rate"], "%mo")); $tsi->set_value("multiplier", $multiplier); $tsi->set_value("comment", $comment); $tsi->set_value("emailUID", $emailUID); $tsi->set_value("emailMessageID", $emailMessageID); $tsi->save(); $id = $tsi->get_id(); $tsi = new timeSheetItem(); $tsi->set_id($id); $tsi->select(); $ID = $tsi->get_value("timeSheetID"); } } if ($ID) { return array("status" => "yay", "message" => $ID); } else { alloc_error($errstr . "Time not added."); } }
function populate_string($str, $entity, $entityID = false) { // Actually do the text substitution $current_user =& singleton("current_user"); is_object($current_user) and $swap["cu"] = person::get_fullname($current_user->get_id()); if ($entity == "timeSheet" && $entityID) { $timeSheet = new timeSheet(); $timeSheet->set_id($entityID); $timeSheet->select(); $timeSheet->load_pay_info(); foreach ($timeSheet->pay_info as $k => $v) { $swap[$k] = $v; } if ($timeSheet->get_value("approvedByManagerPersonID")) { $swap["tm"] = person::get_fullname($timeSheet->get_value("approvedByManagerPersonID")); } else { $project = $timeSheet->get_foreign_object("project"); $projectManagers = $project->get_timeSheetRecipients(); if (is_array($projectManagers) && count($projectManagers)) { $people =& get_cached_table("person"); foreach ($projectManagers as $pID) { $swap["tm"] .= $commar . $people[$pID]["name"]; $commar = ", "; } } } if ($timeSheet->get_value("approvedByAdminPersonID")) { $swap["tc"] = person::get_fullname($timeSheet->get_value("approvedByAdminPersonID")); } else { $people =& get_cached_table("person"); $timeSheetAdministrators = config::get_config_item('defaultTimeSheetAdminList'); if (count($timeSheetAdministrators)) { $swap["tc"] = ""; $comma = ""; foreach ($timeSheetAdministrators as $adminID) { $swap["tc"] .= $comma . $people[$adminID]["name"]; $comma = ", "; } } else { $swap["tc"] = 'no-one'; } } $swap["ti"] = $timeSheet->get_id(); $swap["to"] = person::get_fullname($timeSheet->get_value("personID")); $swap["ta"] = person::get_fullname($timeSheet->get_value("personID")); $swap["tf"] = $timeSheet->get_value("dateFrom"); $swap["tt"] = $timeSheet->get_value("dateTo"); $swap["ts"] = $timeSheet->get_timeSheet_status(); $swap["tu"] = config::get_config_item("allocURL") . "time/timeSheet.php?timeSheetID=" . $timeSheet->get_id(); $projectID = $timeSheet->get_value("projectID"); } if ($entity == "task" && $entityID) { $task = new task(); $task->set_id($entityID); $task->select(); $swap["ti"] = $task->get_id(); $swap["to"] = person::get_fullname($task->get_value("creatorID")); $swap["ta"] = person::get_fullname($task->get_value("personID")); $swap["tm"] = person::get_fullname($task->get_value("managerID")); $swap["tc"] = person::get_fullname($task->get_value("closerID")); $swap["tn"] = $task->get_value("taskName"); $swap["td"] = $task->get_value("taskDescription"); $swap["tu"] = config::get_config_item("allocURL") . "task/task.php?taskID=" . $task->get_id(); $swap["tp"] = $task->get_priority_label(); $swap["ts"] = $task->get_task_status("label"); $swap["teb"] = $task->get_value("timeBest"); $swap["tem"] = $task->get_value("timeExpected"); $swap["tew"] = $task->get_value("timeWorst"); $swap["tep"] = person::get_fullname($task->get_value("estimatorID")); //time estimate person, when it's implemented $projectID = $task->get_value("projectID"); } if ($entity == "project" && $entityID || $projectID) { $project = new project(); if ($projectID) { $project->set_id($projectID); } else { $project->set_id($entityID); } $project->select(); $swap["pn"] = $project->get_value("projectName"); $swap["pi"] = $project->get_id(); $clientID = $project->get_value("clientID"); } if ($entity == "client" && $entityID || $clientID) { $client = new client(); if ($clientID) { $client->set_id($clientID); } else { $client->set_id($entityID); } $client->select(); $swap["li"] = $client->get_id(); $swap["cc"] = $client->get_value("clientName"); } $swap["cd"] = config::get_config_item("companyContactAddress"); $swap["cd"] .= " " . config::get_config_item("companyContactAddress2"); $swap["cd"] .= " " . config::get_config_item("companyContactAddress3"); $swap["cd"] .= "\nP: " . config::get_config_item("companyContactPhone"); $swap["cd"] .= "\nF: " . config::get_config_item("companyContactFax"); $swap["cd"] .= "\nE: " . config::get_config_item("companyContactEmail"); $swap["cd"] .= "\nW: " . config::get_config_item("companyContactHomePage"); $swap["cn"] = config::get_config_item("companyName"); $swap["c1"] = config::get_config_item("companyContactAddress"); $swap["c2"] = config::get_config_item("companyContactAddress2"); $swap["c3"] = config::get_config_item("companyContactAddress3"); $swap["ce"] = config::get_config_item("companyContactEmail"); $swap["cp"] = config::get_config_item("companyContactPhone"); $swap["cf"] = config::get_config_item("companyContactFax"); $swap["cw"] = config::get_config_item("companyContactHomePage"); foreach ($swap as $k => $v) { $str = str_replace("%" . $k, $v, $str); } return $str; }
function get_timeSheetItem_list_items($timeSheetID) { global $TPL; list($db, $customerBilledDollars, $timeSheet, $unit_array, $currency) = $this->get_timeSheetItem_vars($timeSheetID); $m = new meta("timeSheetItemMultiplier"); $multipliers = $m->get_list(); while ($db->next_record()) { $timeSheetItem = new timeSheetItem(); $timeSheetItem->read_db_record($db); $row_num++; $taskID = sprintf("%d", $timeSheetItem->get_value("taskID")); $num = sprintf("%0.2f", $timeSheetItem->get_value("timeSheetItemDuration")); $info["total"] += $num; $rows[$row_num]["date"] = $timeSheetItem->get_value("dateTimeSheetItem"); $rows[$row_num]["units"] = $num . " " . $unit_array[$timeSheetItem->get_value("timeSheetItemDurationUnitID")]; $rows[$row_num]["multiplier_string"] = $multipliers[$timeSheetItem->get_value("multiplier")]["timeSheetItemMultiplierName"]; unset($str); $d = $timeSheetItem->get_value('taskID', DST_HTML_DISPLAY) . ": " . $timeSheetItem->get_value('description', DST_HTML_DISPLAY); $d && !$rows[$row_num]["desc"] and $str[] = "<b>" . $d . "</b>"; // Get task description if ($taskID && $TPL["printDesc"]) { $t = new task(); $t->set_id($taskID); $t->select(); $d2 = str_replace("\r\n", "\n", $t->get_value("taskDescription", DST_HTML_DISPLAY)); $d2 .= "\n"; $d2 && !$d2s[$taskID] and $str[] = $d2; $d2 and $d2s[$taskID] = true; } $c = str_replace("\r\n", "\n", $timeSheetItem->get_value("comment")); !$timeSheetItem->get_value("commentPrivate") && $c and $str[] = page::htmlentities($c); is_array($str) and $rows[$row_num]["desc"] .= trim(implode(DEFAULT_SEP, $str)); } $timeSheet->load_pay_info(); $info["total"] = $timeSheet->pay_info["summary_unit_totals"]; $rows or $rows = array(); $info or $info = array(); return array($rows, $info); }
function edit_timeSheetItem($commands) { $item_fields = $this->get_fields("item"); // Time Sheet Item commands if ($commands["item"]) { $timeSheetItem = new timeSheetItem(); if ($commands["item"] && strtolower($commands["item"] != "new")) { $timeSheetItem->set_id($commands["item"]); if (!$timeSheetItem->select()) { alloc_error("Unable to select time sheet item with ID: " . $commands["item"]); } } $timeSheet = $timeSheetItem->get_foreign_object("timeSheet"); $timeSheetItem->currency = $timeSheet->get_value("currencyTypeID"); $timeSheetItem->set_value("rate", $timeSheetItem->get_value("rate", DST_HTML_DISPLAY)); foreach ($commands as $k => $v) { // Validate/coerce the fields if ($k == "unit") { $changes[$k] = "timeSheetItemDurationUnitID"; in_array($v, array(1, 2, 3, 4, 5)) or $err[] = "Invalid unit. Try a number from 1-5."; } else { if ($k == "task") { $changes[$k] = "taskID"; $t = new task(); $t->set_id($v); $t->select(); is_object($timeSheet) && $timeSheet->get_id() && $t->get_value("projectID") != $timeSheet->get_value("projectID") and $err[] = "Invalid task. Task belongs to different project."; } } // Plug the value in if ($item_fields[$k][0]) { $changes[$k] = $item_fields[$k][0]; $timeSheetItem->set_value($item_fields[$k][0], sprintf("%s", $v)); } } $after_label2 = "After: "; if (strtolower($commands["item"]) != "new") { $str = $this->condense_changes($changes, $timeSheetItem->row()); $str and $status[] = "msg"; $str and $message[] = "Before: " . $str; } else { $after_label2 = "Fields: "; } if ($commands["delete"]) { $id = $timeSheetItem->get_id(); $timeSheetItem->delete(); $status[] = "yay"; $message[] = "Time sheet item " . $id . " deleted."; // Save timeSheetItem } else { if (!$err && $commands["item"] && $timeSheetItem->save()) { $timeSheetItem->select(); $str = $this->condense_changes($changes, $timeSheetItem->row()); $str and $status[] = "msg"; $str and $message[] = $after_label2 . $str; $status[] = "yay"; if (strtolower($commands["item"]) == "new") { $message[] = "Time sheet item " . $timeSheetItem->get_id() . " created."; } else { $message[] = "Time sheet item " . $timeSheetItem->get_id() . " updated."; } // Problems } else { if ($err && $commands["item"]) { alloc_error("Problem updating time sheet item: " . implode("\n", (array) $err)); } } } } return array($status, $message); }
function attach_email_to_existing_task($req = array()) { global $TPL; $info = inbox::get_mail_info(); $current_user =& singleton("current_user"); $orig_current_user =& $current_user; $req["taskID"] = sprintf("%d", $req["taskID"]); $task = new task(); $task->set_id($req["taskID"]); if ($task->select()) { $email_receive = new email_receive($info); $email_receive->open_mailbox($info["folder"]); $email_receive->set_msg($req["id"]); $email_receive->get_msg_header(); $email_receive->save_email(); $c = comment::add_comment_from_email($email_receive, $task); $commentID = $c->get_id(); $commentID and $TPL["message_good_no_esc"][] = "Created comment " . $commentID . " on task " . $task->get_task_link(array("prefixTaskID" => true)); // Possibly change the identity of current_user list($from_address, $from_name) = parse_email_address($email_receive->mail_headers["from"]); $person = new person(); $personID = $person->find_by_email($from_address); $personID or $personID = $person->find_by_name($from_name); if ($personID) { $current_user = new person(); $current_user->load_current_user($personID); singleton("current_user", $current_user); } // swap back to normal user $current_user =& $orig_current_user; singleton("current_user", $current_user); // manually add task manager and assignee to ip list $extraips = array(); if ($task->get_value("personID")) { $p = new person($task->get_value("personID")); if ($p->get_value("emailAddress")) { $extraips[$p->get_value("emailAddress")]["name"] = $p->get_name(); $extraips[$p->get_value("emailAddress")]["role"] = "assignee"; $extraips[$p->get_value("emailAddress")]["personID"] = $task->get_value("personID"); $extraips[$p->get_value("emailAddress")]["selected"] = 1; } } if ($task->get_value("managerID")) { $p = new person($task->get_value("managerID")); if ($p->get_value("emailAddress")) { $extraips[$p->get_value("emailAddress")]["name"] = $p->get_name(); $extraips[$p->get_value("emailAddress")]["role"] = "manager"; $extraips[$p->get_value("emailAddress")]["personID"] = $task->get_value("managerID"); $extraips[$p->get_value("emailAddress")]["selected"] = 1; } } // add all the other interested parties $ips = interestedParty::get_interested_parties("task", $req["taskID"], $extraips); foreach ((array) $ips as $k => $inf) { $inf["entity"] = "comment"; $inf["entityID"] = $commentID; $inf["email"] and $inf["emailAddress"] = $inf["email"]; if ($req["emailto"] == "internal" && !$inf["external"] && !$inf["clientContactID"]) { $id = interestedParty::add_interested_party($inf); $recipients[] = $inf["name"] . " " . add_brackets($k); } else { if ($req["emailto"] == "default") { $id = interestedParty::add_interested_party($inf); $recipients[] = $inf["name"] . " " . add_brackets($k); } } } $recipients and $recipients = implode(", ", (array) $recipients); $recipients and $TPL["message_good"][] = "Sent email to " . $recipients; // Re-email the comment out comment::send_comment($commentID, array("interested"), $email_receive); // File email away in the task's mail folder $mailbox = "INBOX/task" . $task->get_id(); $email_receive->create_mailbox($mailbox) and $TPL["message_good"][] = "Created mailbox: " . $mailbox; $email_receive->move_mail($req["id"], $mailbox) and $TPL["message_good"][] = "Moved email " . $req["id"] . " to " . $mailbox; $email_receive->close(); } }
function get_effective_person_id($recipient) { if ($recipient->get_value('personID') == null) { //nulls don't come through correctly? // OK, slightly more complicated, we need to get the relevant link entity $metaperson = -$recipient->get_value('metaPersonID'); $type = $this->get_value("reminderType"); if ($type == "task") { $task = new task(); $task->set_id($this->get_value('reminderLinkID')); $task->select(); switch ($metaperson) { case REMINDER_METAPERSON_TASK_ASSIGNEE: return $task->get_value('personID'); break; case REMINDER_METAPERSON_TASK_MANAGER: return $task->get_value('managerID'); break; } } else { // we should never actually get here... alloc_error("Unknown metaperson."); } } else { return $recipient->get_value('personID'); } }