public function testGetLength() { $instance = new History(); $this->assertEquals(0, $instance->getLength()); $instance->add('foo'); $this->assertEquals(1, $instance->getLength()); $instance->add('bar'); $this->assertEquals(2, $instance->getLength()); $instance->clear(); $this->assertEquals(0, $instance->getLength()); }
function show_GET($w) { list($lotid, $householdid) = $w->pathMatch("lotid", "householdid"); if (empty($lotid)) { $w->error("Need a Lot ID"); } if (empty($householdid)) { $w->error("Need a household ID"); } $lot = $w->Bend->getLotForId($lotid); if (empty($lot)) { $w->error("Lot {$lotid} does not exist"); } $household = $w->Bend->getHouseholdForId($householdid); if (empty($household)) { $w->error("Household {$householdid} does not exist"); } History::add("Bend Household: " . $household->streetnumber); $lotTable = array(); $lotTable["Household"] = array(array(array("Lot Number", "static", "", $lot->lot_number), array("Occupancy", "static", "", $lot->occupancy)), array(array("Street Number", "static", "", $household->streetnumber), array("Is CHL?", "static", "", $household->is_chl ? "yes" : "no"), array("Is Occupied?", "static", "", $household->is_occupied ? "yes" : "no"), array("Number of Occupants", "static", "", $household->num_occupants))); $w->ctx("lot", $lot); $w->ctx("table", Html::multiColTable($lotTable)); $w->ctx("household", $household); $w->ctx("currentOccupants", $household->getCurrentOccupants()); $w->ctx("pastOccupants", $household->getPastOccupants()); }
function admin_ALL(Web $w) { History::add("Workhours Admin"); $w->ctx("workperiods", $w->Bend->getAllWorkPeriods()); $w->ctx("focusgroups", $w->Bend->getTopLevelWorkCategories()); $w->enqueueStyle(["uri" => "/modules/bend/assets/css/bend.css", "weight" => 500]); }
function list_GET(Web $w) { History::add("List Workhours"); list($userid, $periodid) = $w->pathMatch("a", "b"); // get the user if (!empty($userid)) { $user = $w->Auth->getUser($userid); } else { $user = $w->Auth->user(); } // calculate total work hours for this period $workentries = $w->Bend->getWorkhoursForUser($user, $periodid); $total_worked = 0; $total_accredited = 0; if (!empty($workentries)) { foreach ($workentries as $we) { $total_worked += $we->hours; if ($we->user_id == $we->attributed_user_id) { $total_accredited += $we->hours; } } } $w->ctx("total_worked", $total_worked); $w->ctx("total_accredited", $total_accredited); $w->ctx("user", $user); $w->ctx("workentries", $workentries); $w->ctx("workPeriod", $w->Bend->getWorkPeriodForId($periodid)); $w->ctx("allWorkPeriods", $w->Bend->getAllWorkPeriods()); }
/** * Modifies an Issue's Reporter. * * @param integer $issue_id The id of the issue. * @param string $fullname The id of the user. * @param boolean $add_history If this should be logged. * @return int */ public static function update($issue_id, $email, $add_history = true) { $email = strtolower(Mail_Helper::getEmailAddress($email)); $usr_id = User::getUserIDByEmail($email, true); // If no valid user found reset to system account if (!$usr_id) { $usr_id = APP_SYSTEM_USER_ID; } $sql = 'UPDATE {{%issue}} SET iss_usr_id = ? WHERE iss_id = ?'; try { DB_Helper::getInstance()->query($sql, array($usr_id, $issue_id)); } catch (DbException $e) { return -1; } if ($add_history) { // TRANSLATORS: %1: email, %2: full name $current_usr_id = Auth::getUserID(); History::add($issue_id, $current_usr_id, 'issue_updated', 'Reporter was changed to {email} by {user}', array('email' => $email, 'user' => User::getFullName($current_usr_id))); } // Add new user to notification list if ($usr_id > 0) { Notification::subscribeEmail($usr_id, $issue_id, $email, Notification::getDefaultActions()); } return 1; }
function viewtaskgrouptypes_ALL(Web $w) { $w->Task->navigation($w, "Manage Task Groups"); History::add("Manage Task Groups"); $task_groups = $w->Task->getTaskGroups(); if ($task_groups) { usort($task_groups, array("TaskService", "sortbyGroup")); } // prepare column headings for display $line = array(array("Title", "Type", "Description", "Default Assignee")); // if task group exists, display title, group type, description, default assignee and button for specific task group info if ($task_groups) { foreach ($task_groups as $group) { $line[] = array(Html::a(WEBROOT . "/task-group/viewmembergroup/" . $group->id, $group->title), $group->getTypeTitle(), $group->description, $group->getDefaultAssigneeName()); } } else { // if no groups for this group type, say as much $line[] = array("There are no Task Groups Configured. Please create a New Task Group.", "", "", "", ""); } // display list of task groups in the target task group type $w->ctx("dashboard", Html::table($line, null, "tablesorter", true)); // tab: new task group // get generic task group permissions $arrassign = $w->Task->getTaskGroupPermissions(); // unset 'ALL' given all can never assign a task unset($arrassign[0]); // set Is Task Active dropdown $is_active = array(array("Yes", "1"), array("No", "0")); $grouptypes = $w->Task->getAllTaskGroupTypes(); // build form to create a new task group within the target group type $f = Html::form(array(array("Task Group Attributes", "section"), array("Task Group Type", "select", "task_group_type", null, $grouptypes), array("Title", "text", "title"), array("Who Can Assign", "select", "can_assign", null, $arrassign), array("Who Can View", "select", "can_view", null, $w->Task->getTaskGroupPermissions()), array("Who Can Create", "select", "can_create", null, $w->Task->getTaskGroupPermissions()), array("Active", "select", "is_active", null, $is_active), array("", "hidden", "is_deleted", "0"), array("Description", "textarea", "description", null, "26", "6"), array("Default Assignee", "select", "default_assignee_id", null, $w->Auth->getUsers())), $w->localUrl("/task-group/createtaskgroup"), "POST", "Save"); // display form $w->ctx("creategroup", $f); }
function showperiod_GET(Web $w) { list($id) = $w->pathMatch("a"); $wp = $w->Bend->getWorkperiodForId($id); if (empty($wp)) { $w->error("Workperiod does not exist", "/bend-workhours/admin"); } History::add("Work Period: " . formatDate($wp->d_start)); $w->ctx("workperiod", $wp); $w->ctx("categories", $w->Bend->getTopLevelWorkCategories()); $w->ctx("households", $w->Bend->getAllHouseholds()); }
function viewmembergroup_GET(Web $w) { $p = $w->pathMatch("id"); // tab: Members // get all members in a task group given a task group ID $member_group = $w->Task->getMemberGroup($p['id']); // get the group attributes given a task group ID $group = $w->Task->getTaskGroup($p['id']); // put the group title into the page heading $w->Task->navigation($w, "Task Group - " . $group->title); History::add("Task Group: " . $group->title); // set columns headings for display of members $line[] = array("Member", "Role", ""); // if their are members, display their full name, role and buttons to edit or delete the member if ($member_group) { foreach ($member_group as $member) { $line[] = array($w->Task->getUserById($member->user_id), $member->role, Html::box(WEBROOT . "/task-group/viewmember/" . $member->id, " Edit ", true) . " " . Html::box(WEBROOT . "/task-group/deletegroupmember/" . $member->id, " Delete ", true)); } } else { // if there are no members, say as much $line[] = array("Group currently has no members. Please Add New Members.", "", ""); } // enter task group attributes sa query string for buttons providing group specific functions such as delete or add members $w->ctx("taskgroup", $group->task_group_type); $w->ctx("grpid", $group->id); $w->ctx("groupid", $p['id']); // display list of group members $w->ctx("viewmembers", Html::table($line, null, "tablesorter", true)); // tab: Notify $notify = $w->Task->getTaskGroupNotify($group->id); if ($notify) { foreach ($notify as $n) { $v[$n->role][$n->type] = $n->value; } } else { $v['guest']['creator'] = 0; $v['member']['creator'] = 0; $v['member']['assignee'] = 0; $v['owner']['creator'] = 0; $v['owner']['assignee'] = 0; $v['owner']['other'] = 0; } $notifyForm['Task Group Notifications'] = array(array(array("", "hidden", "task_group_id", $group->id)), array(array("", "static", ""), array("Creator", "static", "creator"), array("Assignee", "static", "assignee"), array("All Others", "static", "others")), array(array("Guest", "static", "guest"), array("", "checkbox", "guest_creator", $v['guest']['creator'])), array(array("Member", "static", "member"), array("", "checkbox", "member_creator", $v['member']['creator']), array("", "checkbox", "member_assignee", $v['member']['assignee'])), array(array("Owner", "static", "owner"), array("", "checkbox", "owner_creator", $v['owner']['creator']), array("", "checkbox", "owner_assignee", $v['owner']['assignee']), array("", "checkbox", "owner_other", $v['owner']['other']))); $w->ctx("notifymatrix", Html::multiColForm($notifyForm, $w->localUrl("/task-group/updategroupnotify/"), "POST", " Submit ")); }
function showlot_GET(Web $w) { list($id) = $w->pathMatch("id"); if (empty($id)) { $w->error("Need a Lot ID"); } $lot = $w->Bend->getLotForId($id); if (empty($lot)) { $w->error("Lot {$id} does not exist"); } History::add("Bend Lot: " . $lot->lot_number); $lotTable = array(); $lotTable["Lot"] = array(array(array("Lot Number", "static", "", $lot->lot_number), array("Occupancy", "static", "", $lot->occupancy))); $w->ctx("lot", $lot); $w->ctx("lotTable", Html::multiColTable($lotTable)); $w->ctx("owners", $lot->getAllOwners()); $w->ctx("households", $lot->getAllHouseholds()); }
function viewtaskgroup_GET(Web &$w) { $p = $w->pathMatch("id"); // return task group details given a task group ID $group_details = $w->Task->getTaskGroup($p['id']); if (!empty($group_details)) { History::add("Taskgroup: " . $group_details->title); } // if is_active is set to '0', display 'Yes', else display 'No' $isactive = $group_details->is_active == "1" ? "Yes" : "No"; // set Is Task Active, Is Task Deleted dropdowns for display $is_active = array(array("Yes", "1"), array("No", "0")); $is_deleted = array(array("Yes", "1"), array("No", "0")); // get generic task group permissions $arrassign = $w->Task->getTaskGroupPermissions(); // unset 'ALL' given all can never assign a task unset($arrassign[0]); // build form displaying current attributes from database $f = Html::form(array(array("Task Group Details", "section"), array("Task Group Type", "static", "task_group_type", $group_details->getTypeTitle()), array("Title", "text", "title", $group_details->title), array("Who Can Assign", "select", "can_assign", $group_details->can_assign, $arrassign), array("Who Can View", "select", "can_view", $group_details->can_view, $w->Task->getTaskGroupPermissions()), array("Who Can Create", "select", "can_create", $group_details->can_create, $w->Task->getTaskGroupPermissions()), array("Is Active", "select", "is_active", $group_details->is_active, $is_active), array("Description", "textarea", "description", $group_details->description, "26", "6"), array("Default Assignee", "select", "default_assignee_id", $group_details->default_assignee_id, $w->Task->getMembersInGroup($p['id']))), $w->localUrl("/task-group/updatetaskgroup/" . $group_details->id), "POST", " Update "); // display form $w->setLayout(null); $w->ctx("viewgroup", $f); }
/** * Sets the assignees for the issue * * @param integer $issue_id * @param array $assignees * @return int 1 if success, -1 if error, 0 if no change was needed. */ public static function setAssignees($issue_id, $assignees) { if (!is_array($assignees)) { $assignees = array(); } // see if there is anything to change $old_assignees = self::getAssignedUserIDs($issue_id); if (count(array_diff($old_assignees, $assignees)) == 0 && count(array_diff($assignees, $old_assignees)) == 0) { return 0; } $old_assignee_names = self::getAssignedUsers($issue_id); Workflow::handleAssignmentChange(self::getProjectID($issue_id), $issue_id, Auth::getUserID(), self::getDetails($issue_id), $assignees, true); // clear up the assignments for this issue, and then assign it to the current user self::deleteUserAssociations($issue_id); $assignee_names = array(); foreach ($assignees as $assignee) { $res = self::addUserAssociation(Auth::getUserID(), $issue_id, $assignee, false); if ($res == -1) { return -1; } $assignee_names[] = User::getFullName($assignee); Notification::subscribeUser(Auth::getUserID(), $issue_id, $assignee, Notification::getDefaultActions($issue_id, User::getEmail($assignee), 'set_assignees'), false); } Notification::notifyNewAssignment($assignees, $issue_id); $usr_id = Auth::getUserID(); History::add($issue_id, $usr_id, 'user_associated', 'Issue assignment to changed ({changes}) by {user}', array('changes' => History::formatChanges(implode(', ', $old_assignee_names), implode(', ', $assignee_names)), 'user' => User::getFullName($usr_id))); return 1; }
$error = IMG_SAVE_ROTATE_FAILED; } break; default: $error = IMG_SAVE_UNKNOWN_MODE; } if (empty($error)) { $sessionNewPath = $sessionDir . uniqid(md5(time())) . "." . getFileExt($_POST['path']); if (!@copy($originalImage, $sessionNewPath)) { //keep a copy under the session folder $error = IMG_SAVE_BACKUP_FAILED; } else { $isSaveAsRequest = !empty($_POST['new_name']) && !empty($_POST['save_to']) ? true : false; //save the modified image $sessionImageInfo = array('name' => basename($sessionNewPath), 'restorable' => 1); $history->add($sessionImageInfo); if (CONFIG_SYS_DEMO_ENABLE) { //demo only if (isset($originalSessionImageInfo) && sizeof($originalSessionImageInfo)) { $imagePath = $sessionDir . $originalSessionImageInfo['info']['name']; } else { $imagePath = $sessionDir . uniqid(md5(time())) . "." . getFileExt($_POST['path']); } } else { if ($isSaveAsRequest) { //save as request //check save to folder if exists if (isset($_POST['save_to']) && strlen($_POST['save_to'])) { $imagePath = $originalImage; } else { $imagePath = addTrailingSlash(backslashToSlash($_POST['save_to'])) . $_POST['new_name'] . "." . getFileExt($_POST['path']);
$res = Issue::deleteUserAssociation($iss_id, $usr_id); Workflow::handleAssignmentChange($prj_id, $iss_id, Auth::getUserID(), Issue::getDetails($iss_id), Issue::getAssignedUserIDs($iss_id)); $tpl->assign('unassign_result', $res); } elseif ($cat == 'remove_email') { $res = Support::removeEmails(); $tpl->assign('remove_email_result', $res); } elseif ($cat == 'clear_duplicate') { $res = Issue::clearDuplicateStatus($iss_id); $tpl->assign('clear_duplicate_result', $res); } elseif ($cat == 'delete_phone') { $res = Phone_Support::remove($id); $tpl->assign('delete_phone_result', $res); } elseif ($cat == 'new_status') { $res = Issue::setStatus($iss_id, $status_id, true); if ($res == 1) { History::add($iss_id, $usr_id, 'status_changed', "Issue manually set to status '{status}' by {user}", array('status' => Status::getStatusTitle($status_id), 'user' => User::getFullName($usr_id))); } $tpl->assign('new_status_result', $res); } elseif ($cat == 'authorize_reply') { $res = Authorized_Replier::addUser($iss_id, $usr_id); $tpl->assign('authorize_reply_result', $res); } elseif ($cat == 'remove_quarantine') { if (Auth::getCurrentRole() > User::getRoleID('Developer')) { $res = Issue::setQuarantine($iss_id, 0); $tpl->assign('remove_quarantine_result', $res); } } elseif ($cat == 'selfnotify') { if (Issue::canAccess($iss_id, $usr_id)) { $res = Notification::subscribeUser($usr_id, $iss_id, $usr_id, Notification::getDefaultActions($iss_id)); $tpl->assign('selfnotify_result', $res); }
function enter_GET(Web $w) { History::add("Enter Workhours"); $form["Work Hours"] = array(array($w->Auth->hasRole("bend_admin") ? array("Who did the work?", "select", "user_id", $w->Auth->user()->id, $w->Bend->getOccupantUsers()) : array("Who did the work?", "static", "", $w->Auth->user()->getFullName()), array("Who to credit to", "select", "attributed_user_id", $w->Auth->user()->id, $w->Bend->getOccupantUsers()), array("Date", "date", "d_date"), array("Hours", "text", "hours")), array(array("Focus Group", "select", "category_1", null, $w->Bend->getTopLevelWorkCategories()), array("Team or Activity", "select", "category_2", null), array("Activity", "select", "category_3", null)), array(array("Description", "text", "description", ""))); $w->ctx("form", Html::multiColForm($form, "/bend-workhours/enter", "POST", "Save")); }
/** * Attach uploaded files to an issue * It also notifies any subscribers of this new attachment. * * @param int $issue_id The issue ID * @param int $usr_id The user ID * @param int[] $iaf_ids attachment file id-s to attach * @param boolean $internal_only Whether this attachment is supposed to be internal only or not * @param string $file_description File description text * @param string $unknown_user The email of the user who originally sent this email, who doesn't have an account. * @param integer $associated_note_id The note ID that these attachments should be associated with */ public static function attachFiles($issue_id, $usr_id, $iaf_ids, $internal_only, $file_description, $unknown_user = null, $associated_note_id = null) { if (!$iaf_ids) { throw new LogicException('No attachment ids'); } $attachment_id = self::add($issue_id, $usr_id, $file_description, $internal_only, $unknown_user, $associated_note_id); self::associateFiles($attachment_id, $iaf_ids); Issue::markAsUpdated($issue_id, 'file uploaded'); History::add($issue_id, $usr_id, 'attachment_added', 'Attachment uploaded by {user}', array('user' => User::getFullName($usr_id))); // if there is customer integration, mark last customer action $prj_id = Issue::getProjectID($issue_id); $has_crm = CRM::hasCustomerIntegration($prj_id); $is_customer = User::getRoleByUser($usr_id, $prj_id) == User::ROLE_CUSTOMER; if ($has_crm && $is_customer) { Issue::recordLastCustomerAction($issue_id); } Workflow::handleAttachment($prj_id, $issue_id, $usr_id); Notification::notify($issue_id, 'files', $attachment_id, $internal_only); }
/** * Check if this email needs to be blocked and if so, block it. * * */ public static function blockEmailIfNeeded($email) { if (empty($email['issue_id'])) { return false; } $issue_id = $email['issue_id']; $prj_id = Issue::getProjectID($issue_id); $sender_email = strtolower(Mail_Helper::getEmailAddress($email['from'])); list($text_headers, $body) = Mime_Helper::splitHeaderBody($email['full_email']); if (Mail_Helper::isVacationAutoResponder($email['headers']) || Notification::isBounceMessage($sender_email) || !self::isAllowedToEmail($issue_id, $sender_email)) { // add the message body as a note $_POST = array('full_message' => $email['full_email'], 'title' => @$email['headers']['subject'], 'note' => Mail_Helper::getCannedBlockedMsgExplanation($issue_id) . $email['body'], 'message_id' => Mail_Helper::getMessageID($text_headers, $body)); // avoid having this type of message re-open the issue if (Mail_Helper::isVacationAutoResponder($email['headers'])) { $closing = true; $notify = false; } else { $closing = false; $notify = true; } $res = Note::insertFromPost(Auth::getUserID(), $issue_id, $email['headers']['from'], false, $closing, $notify, true); // associate the email attachments as internal-only files on this issue if ($res != -1) { self::extractAttachments($issue_id, $email['full_email'], true, $res); } $_POST['issue_id'] = $issue_id; $_POST['from'] = $sender_email; // avoid having this type of message re-open the issue if (Mail_Helper::isVacationAutoResponder($email['headers'])) { $email_type = 'vacation-autoresponder'; } else { $email_type = 'routed'; } Workflow::handleBlockedEmail($prj_id, $issue_id, $_POST, $email_type); // try to get usr_id of sender, if not, use system account $usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($email['from']), true); if (!$usr_id) { $usr_id = APP_SYSTEM_USER_ID; } History::add($issue_id, $usr_id, 'email_blocked', "Email from '{from}' blocked", array('from' => $email['from'])); return true; } return false; }
function edit_GET($w) { $p = $w->pathMatch("id"); $task = !empty($p["id"]) ? $w->Task->getTask($p["id"]) : new Task($w); if (!empty($task->id) && !$task->canView($w->Auth->user())) { $w->error("You do not have permission to edit this Task", "/task/tasklist"); } // Get a list of the taskgroups and filter by what can be used $taskgroups = array_filter($w->Task->getTaskGroups(), function ($taskgroup) { return $taskgroup->getCanICreate(); }); $tasktypes = array(); $priority = array(); $members = array(); // Try and prefetch the taskgroup by given id $taskgroup = null; $taskgroup_id = $w->request("gid"); if (!empty($taskgroup_id) || !empty($task->task_group_id)) { $taskgroup = $w->Task->getTaskGroup(!empty($task->task_group_id) ? $task->task_group_id : $taskgroup_id); if (!empty($taskgroup->id)) { $tasktypes = $w->Task->getTaskTypes($taskgroup->task_group_type); $priority = $w->Task->getTaskPriority($taskgroup->task_group_type); $members = $w->Task->getMembersBeAssigned($taskgroup->id); sort($members); } } // Create form $form = array(!empty($p["id"]) ? "Edit task" : "Create a new task" => array(array(!empty($p["id"]) ? array("Task Group", "text", "-task_group_id_text", $taskgroup->title) : array("Task Group", "autocomplete", "task_group_id", !empty($task->task_group_id) ? $task->task_group_id : $taskgroup_id, $taskgroups), !empty($p["id"]) ? array("Task Type", "select", "-task_type", $task->task_type, $tasktypes) : array("Task Type", "select", "task_type", $task->task_type, $tasktypes)), array(array("Task Title", "text", "title", $task->title), array("Status", "select", "status", $task->status, $task->getTaskGroupStatus())), array(array("Priority", "select", "priority", $task->priority, $priority), array("Date Due", "date", "dt_due", formatDate($task->dt_due)), !empty($taskgroup) && $taskgroup->getCanIAssign() ? array("Assigned To", "select", "assignee_id", $task->assignee_id, $members) : array("Assigned To", "select", "-assignee_id", $task->assignee_id, $members)), array(array("Description", "textarea", "description", $task->description)))); if (empty($p['id'])) { History::add("New Task"); } else { History::add("Task: {$task->title}"); } $w->ctx("task", $task); $w->ctx("form", Html::multiColForm($form, $w->localUrl("/task/edit/{$task->id}"), "POST", "Save", "edit_form")); ////////////////////////// // Build time log table // ////////////////////////// $timelog = $task->getTimeLog(); $total_seconds = 0; $table_header = array("Assignee", "Start", "Period (hours)", "Comment", "Actions"); $table_data = array(); if (!empty($timelog)) { // for each entry display, calculate period and display total time on task foreach ($timelog as $log) { // get time difference, start to end $seconds = $log->dt_end - $log->dt_start; $period = $w->Task->getFormatPeriod($seconds); $comment = $w->Comment->getComment($log->comment_id); $comment = !empty($comment) ? $comment->comment : ""; $table_row = array($w->Task->getUserById($log->user_id), formatDateTime($log->dt_start), $period, !empty($comment) ? $w->Comment->renderComment($comment) : ""); // Build list of buttons $buttons = ''; if ($log->is_suspect == "0") { $total_seconds += $seconds; $buttons .= Html::box($w->localUrl("/task/addtime/" . $task->id . "/" . $log->id), " Edit ", true); } if ($w->Task->getIsOwner($task->task_group_id, $w->Auth->user()->id)) { $buttons .= Html::b($w->localUrl("/task/suspecttime/" . $task->id . "/" . $log->id), empty($log->is_suspect) || $log->is_suspect == "0" ? "Review" : "Accept"); } $buttons .= Html::b($w->localUrl("/task/deletetime/" . $task->id . "/" . $log->id), "Delete", "Are you sure you wish to DELETE this Time Log Entry?"); $table_row[] = $buttons; $table_data[] = $table_row; } $table_data[] = array("<b>Total</b>", "", "<b>" . $w->Task->getFormatPeriod($total_seconds) . "</b>", "", ""); } // display the task time log $w->ctx("timelog", Html::table($table_data, null, "tablesorter", $table_header)); /////////////////// // Notifications // /////////////////// $notify = null; // If I am assignee, creator or task group owner, I can get notifications for this task if (!empty($task->id) && $task->getCanINotify()) { // get User set notifications for this Task $notify = $w->Task->getTaskUserNotify($w->Auth->user()->id, $task->id); if (empty($notify)) { $logged_in_user_id = $w->Auth->user()->id; // Get my role in this task group $me = $w->Task->getMemberGroupById($task->task_group_id, $logged_in_user_id); $type = ""; if ($task->assignee_id == $logged_in_user_id) { $type = "assignee"; } else { if ($task->getTaskCreatorId() == $logged_in_user_id) { $type = "creator"; } else { if ($w->Task->getIsOwner($task->task_group_id, $logged_in_user_id)) { $type = "other"; } } } if (!empty($type) && !empty($me)) { $notify = $w->Task->getTaskGroupUserNotifyType($logged_in_user_id, $task->task_group_id, strtolower($me->role), $type); } } // create form. if still no 'notify' all boxes are unchecked $form = array("Notification Events" => array(array(array("", "hidden", "task_creation", "0")), array(array("Task Details Update", "checkbox", "task_details", !empty($notify->task_details) ? $notify->task_details : null), array("Comments Added", "checkbox", "task_comments", !empty($notify->task_comments) ? $notify->task_comments : null)), array(array("Time Log Entry", "checkbox", "time_log", !empty($notify->time_log) ? $notify->time_log : null), array("Task Data Updated", "checkbox", "task_data", !empty($notify->task_data) ? $notify->task_data : null)), array(array("Documents Added", "checkbox", "task_documents", !empty($notify->task_documents) ? $notify->task_documents : null)))); $w->ctx("tasknotify", Html::multiColForm($form, $w->localUrl("/task/updateusertasknotify/" . $task->id), "POST")); } }
/** * Converts a note to a draft or an email * * @param int $note_id The id of the note * @param string $target What the note should be converted too (email, etc) * @param bool $authorize_sender If $authorize_sender If the sender should be added to authorized senders list. * @return int */ public static function convertNote($note_id, $target, $authorize_sender = false) { $issue_id = self::getIssueID($note_id); $email_account_id = Email_Account::getEmailAccount(); $blocked_message = self::getBlockedMessage($note_id); $unknown_user = self::getUnknownUser($note_id); $structure = Mime_Helper::decode($blocked_message, true, true); $body = $structure->body; $sender_email = strtolower(Mail_Helper::getEmailAddress($structure->headers['from'])); $current_usr_id = Auth::getUserID(); if ($target == 'email') { if (Mime_Helper::hasAttachments($structure)) { $has_attachments = 1; } else { $has_attachments = 0; } list($blocked_message, $headers) = Mail_Helper::rewriteThreadingHeaders($issue_id, $blocked_message, @$structure->headers); $t = array('issue_id' => $issue_id, 'ema_id' => $email_account_id, 'message_id' => @$structure->headers['message-id'], 'date' => Date_Helper::getCurrentDateGMT(), 'from' => @$structure->headers['from'], 'to' => @$structure->headers['to'], 'cc' => @$structure->headers['cc'], 'subject' => @$structure->headers['subject'], 'body' => @$body, 'full_email' => @$blocked_message, 'has_attachment' => $has_attachments, 'headers' => $headers); // need to check for a possible customer association if (!empty($structure->headers['from'])) { $details = Email_Account::getDetails($email_account_id); // check from the associated project if we need to lookup any customers by this email address if (CRM::hasCustomerIntegration($details['ema_prj_id'])) { $crm = CRM::getInstance($details['ema_prj_id']); // check for any customer contact association try { $contact = $crm->getContactByEmail($sender_email); $issue_contract = $crm->getContract(Issue::getContractID($issue_id)); if ($contact->canAccessContract($issue_contract)) { $t['customer_id'] = $issue_contract->getCustomerID(); } } catch (CRMException $e) { } } } if (empty($t['customer_id'])) { $update_type = 'staff response'; $t['customer_id'] = null; } else { $update_type = 'customer action'; } $res = Support::insertEmail($t, $structure, $sup_id); if ($res != -1) { Support::extractAttachments($issue_id, $structure); // notifications about new emails are always external $internal_only = false; // special case when emails are bounced back, so we don't want to notify the customer about those if (Notification::isBounceMessage($sender_email)) { $internal_only = true; } Notification::notifyNewEmail($current_usr_id, $issue_id, $t, $internal_only, false, '', $sup_id); Issue::markAsUpdated($issue_id, $update_type); self::remove($note_id, false); History::add($issue_id, $current_usr_id, 'note_converted_email', 'Note converted to e-mail (from: {from}) by {user}', array('from' => @$structure->headers['from'], 'user' => User::getFullName($current_usr_id))); // now add sender as an authorized replier if ($authorize_sender) { Authorized_Replier::manualInsert($issue_id, @$structure->headers['from']); } } return $res; } // save message as a draft $res = Draft::saveEmail($issue_id, $structure->headers['to'], $structure->headers['cc'], $structure->headers['subject'], $body, false, $unknown_user); // remove the note, if the draft was created successfully if ($res) { self::remove($note_id, false); $usr_id = $current_usr_id; History::add($issue_id, $usr_id, 'note_converted_draft', 'Note converted to draft (from: {from}) by {user}', array('from' => @$structure->headers['from'], 'user' => User::getFullName($current_usr_id))); } return $res; }
/** * Method used to update an existing draft response. * * @param integer $issue_id The issue ID * @param integer $emd_id The email draft ID * @param string $to The primary recipient of the draft * @param string $cc The secondary recipients of the draft * @param string $subject The subject of the draft * @param string $message The draft body * @param integer $parent_id The ID of the email that this draft is replying to, if any * @return integer 1 if the update worked, -1 otherwise */ public static function update($issue_id, $emd_id, $to, $cc, $subject, $message, $parent_id = null) { if (!$parent_id) { $parent_id = null; } $usr_id = Auth::getUserID(); // update previous draft and insert new record $stmt = "UPDATE\n {{%email_draft}}\n SET\n emd_updated_date=?,\n emd_status = 'edited'\n WHERE\n emd_id=?"; $params = array(Date_Helper::getCurrentDateGMT(), $emd_id); try { DB_Helper::getInstance()->query($stmt, $params); } catch (DbException $e) { return -1; } Issue::markAsUpdated($issue_id, 'draft saved'); History::add($issue_id, $usr_id, 'draft_updated', 'Email message draft updated by {user}', array('user' => User::getFullName($usr_id))); self::saveEmail($issue_id, $to, $cc, $subject, $message, $parent_id, false, false); return 1; }
function index_ALL(Web $w) { History::add("Bend Households"); $w->ctx("households", $w->Bend->getAllHouseholds()); }
/** * Send the reminder * * @param Texts $texts Text object * @param History $hist History * @param Db $zdb Database instance * * @return boolean */ public function send($texts, $hist, $zdb) { $type_name = 'late'; if ($this->_type === self::IMPENDING) { $type_name = 'impending'; } if ($this->hasMail()) { $texts->setReplaces($this->_replaces); $texts->getTexts($type_name . 'duedate', $this->_dest->language); $mail = new GaletteMail(); $mail->setSubject($texts->getSubject()); $mail->setRecipients(array($this->_dest->email => $this->_dest->sname)); $mail->setMessage($texts->getBody()); $sent = $mail->send(); $details = str_replace(array('%name', '%mail', '%days'), array($this->_dest->sname, $this->_dest->email, $this->_dest->days_remaining), _T("%name <%mail> (%days days)")); if ($sent == GaletteMail::MAIL_SENT) { $this->_success = true; $msg = ''; if ($type_name == 'late') { $msg = _T("Sent reminder mail for late membership"); } else { $msg = _T("Sent reminder mail for impending membership"); } $this->_msg = $details; $hist->add($msg, $details); } else { $this->_success = false; if ($type_name == 'late') { $msg = _T("A problem happened while sending late membership mail"); } else { $msg = _T("A problem happened while sending impending membership mail"); } $this->_msg = $details; $hist->add($str, $details); } } else { $this->_success = false; $this->_nomail = true; $str = str_replace('%membership', $type_name, _T("Unable to send %membership reminder (no mail address).")); $details = str_replace(array('%name', '%id', '%days'), array($this->_dest->sname, $this->_dest->id, $this->_dest->days_remaining), _T("%name (#%id - %days days)")); $hist->add($str, $details); $this->_msg = $this->_dest->sname; } //store reminder in database $this->_store($zdb); return $this->_success; }
/** * Method used to remotely record a time tracking entry. * * @param integer $issue_id The issue ID * @param integer $usr_id The user ID * @param integer $cat_id The time tracking category ID * @param string $summary The summary of the work entry * @param integer $time_spent The time spent in minutes * @return integer 1 if the insert worked, -1 otherwise */ public static function recordRemoteTimeEntry($issue_id, $usr_id, $cat_id, $summary, $time_spent) { $stmt = 'INSERT INTO {{%time_tracking}} ( ttr_ttc_id, ttr_iss_id, ttr_usr_id, ttr_created_date, ttr_time_spent, ttr_summary ) VALUES ( ?, ?, ?, ?, ?, ? )'; $params = array($cat_id, $issue_id, $usr_id, Date_Helper::getCurrentDateGMT(), $time_spent, $summary); try { DB_Helper::getInstance()->query($stmt, $params); } catch (DbException $e) { return -1; } Issue::markAsUpdated($issue_id); History::add($issue_id, $usr_id, 'remote_time_added', 'Time tracking entry submitted remotely by {user}', array('user' => User::getFullName($usr_id))); return 1; }
/** * Method used to update the values stored in the database. * * @return integer 1 if the update worked properly, any other value otherwise */ public static function updateValues() { $prj_id = Auth::getCurrentProject(); $issue_id = $_POST['issue_id']; $old_values = self::getValuesByIssue($prj_id, $issue_id); if (isset($_POST['custom_fields']) && count($_POST['custom_fields']) > 0) { $custom_fields = $_POST['custom_fields']; // get the types for all of the custom fields being submitted $cf = array_keys($custom_fields); $cf_list = DB_Helper::buildList($cf); $stmt = "SELECT\n fld_id,\n fld_type\n FROM\n {{%custom_field}}\n WHERE\n fld_id IN ({$cf_list})"; $field_types = DB_Helper::getInstance()->getPair($stmt, $cf); // get the titles for all of the custom fields being submitted $stmt = "SELECT\n fld_id,\n fld_title\n FROM\n {{%custom_field}}\n WHERE\n fld_id IN ({$cf_list})"; $field_titles = DB_Helper::getInstance()->getPair($stmt, $cf); $updated_fields = array(); foreach ($custom_fields as $fld_id => $value) { // security check $sql = 'SELECT fld_min_role FROM {{%custom_field}} WHERE fld_id = ?'; $min_role = DB_Helper::getInstance()->getOne($sql, array($fld_id)); if ($min_role > Auth::getCurrentRole()) { continue; } $option_types = array('multiple', 'combo', 'checkbox'); if (!in_array($field_types[$fld_id], $option_types)) { // check if this is a date field $fld_db_name = self::getDBValueFieldNameByType($field_types[$fld_id]); // first check if there is actually a record for this field for the issue $stmt = "SELECT\n icf_id,\n {$fld_db_name} as value\n FROM\n {{%issue_custom_field}}\n WHERE\n icf_iss_id=? AND\n icf_fld_id=?"; try { $res = DB_Helper::getInstance()->getRow($stmt, array($issue_id, $fld_id)); } catch (DbException $e) { return -1; } $icf_id = $res['icf_id']; $old_value = $res['value']; if ($old_value == $value) { continue; } if (empty($icf_id)) { // record doesn't exist, insert new record $stmt = "INSERT INTO\n {{%issue_custom_field}}\n (\n icf_iss_id,\n icf_fld_id,\n {$fld_db_name}\n ) VALUES (\n ?, ?, ?\n )"; $params = array($issue_id, $fld_id, $value); try { DB_Helper::getInstance()->query($stmt, $params); } catch (DbException $e) { return -1; } } else { // record exists, update it $stmt = "UPDATE\n {{%issue_custom_field}}\n SET\n {$fld_db_name}=?\n WHERE\n icf_id=?"; $params = array($value, $icf_id); try { DB_Helper::getInstance()->query($stmt, $params); } catch (DbException $e) { return -1; } } if ($field_types[$fld_id] == 'textarea') { $updated_fields[$field_titles[$fld_id]] = ''; } else { $updated_fields[$field_titles[$fld_id]] = History::formatChanges($old_value, $value); } } else { $old_value = self::getDisplayValue($issue_id, $fld_id, true); if (!is_array($old_value)) { $old_value = array($old_value); } if (!is_array($value)) { $value = array($value); } if (count(array_diff($old_value, $value)) > 0 || count(array_diff($value, $old_value)) > 0) { $old_display_value = self::getDisplayValue($issue_id, $fld_id); // need to remove all associated options from issue_custom_field and then // add the selected options coming from the form self::removeIssueAssociation($fld_id, $issue_id); if (@count($value) > 0) { self::associateIssue($issue_id, $fld_id, $value); } $new_display_value = self::getDisplayValue($issue_id, $fld_id); $updated_fields[$field_titles[$fld_id]] = History::formatChanges($old_display_value, $new_display_value); } } } Workflow::handleCustomFieldsUpdated($prj_id, $issue_id, $old_values, self::getValuesByIssue($prj_id, $issue_id)); Issue::markAsUpdated($issue_id); // need to save a history entry for this if (count($updated_fields) > 0) { // log the changes $changes = ''; $i = 0; foreach ($updated_fields as $key => $value) { if ($i > 0) { $changes .= '; '; } if (!empty($value)) { $changes .= "{$key}: {$value}"; } else { $changes .= "{$key}"; } $i++; } $usr_id = Auth::getUserID(); History::add($issue_id, $usr_id, 'custom_field_updated', 'Custom field updated ({changes}) by {user}', array('changes' => $changes, 'user' => User::getFullName($usr_id))); } } return 1; }
function viewtask_GET(Web &$w) { $p = $w->pathMatch("id"); // declare delete button $btndelete = ""; // get relevant object for viewing a task given input task ID $task = $w->Task->getTask($p['id']); $w->ctx("task", $task); $taskdata = $w->Task->getTaskData($p['id']); $group = $w->Task->getTaskGroup($task->task_group_id); $w->Task->navigation($w, "View Task: " . $task->title); // if task is deleted, say as much and return to task list if ($task->is_deleted != 0) { $w->msg("This Task has been deleted", "/task/tasklist/"); } elseif ($task->getCanIView()) { History::add("Task: {$task->title}"); // tab: Task Details // if I can assign tasks, provide dropdown of group members else display current assignee. // my role in group Vs group can_assign value if ($task->getCanIAssign()) { $members = $task ? $w->Task->getMembersBeAssigned($task->task_group_id) : $w->Auth->getUsers(); sort($members); $assign = array("Assigned To", "select", "assignee_id", $task->assignee_id, $members); } else { $assigned = $task->assignee_id == "0" ? "Not Assigned" : $w->Task->getUserById($task->assignee_id); $assign = array("Assigned To", "static", "assignee_id", $assigned); } // changing type = dymanically loading of relevant form fields ... problem when presenting on single page. // array("Task Type","select","task_type",$task->task_type,$task->getTaskGroupTypes()), // check a due date exists $dtdue = $task->dt_due == "0000-00-00 00:00:00" || $task->dt_due == "" ? "" : date('d/m/Y', $task->dt_due); // Guests can view but not edit // See if i am assignee or creator, if yes provide editable form, else provide static display $btndelete = ""; if ($task->getCanIEdit()) { $btndelete = Html::b(WEBROOT . "/task/deletetask/" . $task->id, " Delete Task ", "Are you should you with to DELETE this task?"); // if task is closed and Task Group type says cannot be reopened, display static status if ($task->getisTaskClosed() && !$task->getTaskReopen()) { $status = array("Status", "static", "status", $task->status); } else { $status = array("Status", "select", "status", $task->status, $task->getTaskGroupStatus()); } $f = array(array("Task Details", "section"), array("Title", "text", "title", $task->title), array("Created By", "static", "creator", $task->getTaskCreatorName()), array("Task Group", "static", "tg", $task->getTaskGroupTypeTitle()), array("Task Type", "static", "task_type", $task->getTypeTitle()), array("Description", "static", "tdesc", $task->getTypeDescription()), $status, array("Priority", "select", "priority", $task->priority, $task->getTaskGroupPriority()), array("Date Due", "date", "dt_due", $dtdue), array("Description", "textarea", "description", $task->description, "80", "15"), $assign); } else { $f = array(array("Task Details", "section"), array("Title", "static", "title", $task->title), array("Created By", "static", "creator", $task->getTaskCreatorName()), array("Task Group", "static", "tg", $task->getTaskGroupTypeTitle()), array("Task Type", "static", "task_type", $task->getTypeTitle()), array("Description", "static", "tdesc", $task->getTypeDescription()), array("Status", "static", "status", $task->status), array("Priority", "static", "priority", $task->priority), array("Date Due", "static", "dt_due", $dtdue), array("Description", "static", "description", str_replace("\r\n", "<br>", $task->description)), $assign); } // got additional form fields for this task type $form = $w->Task->getFormFieldsByTask($task->task_type, $group); // if there are additional form fields, display them if ($form) { // string match form fields with task data by key // can then push db:value into form field for display foreach ($form as $x) { if ($x[1] == "section") { array_push($f, $x); } if ($taskdata) { foreach ($taskdata as $td) { $key = $td->key; $value = $td->value; // Guests can view but not edit // See if i am a guest, if yes provide static display, else provide editable form if (!$task->getCanIEdit()) { $x[1] = "static"; } if ($key == $x[2]) { $x[3] = $value; array_push($f, $x); } } } else { if ($x[1] != "section") { array_push($f, $x); } } } } // create form $form = Html::form($f, $w->localUrl("/task/updatetask/" . $task->id), "POST", " Update "); // create 'start time log' button $buttontimelog = ""; if ($task->assignee_id == $w->Auth->user()->id) { $buttontimelog = new \Html\Button(); $buttontimelog->href("/task/starttimelog/{$task->id}")->setClass("startTime button small")->text("Start Time Log"); // $btntimelog = "<button class=\"startTime\" href=\"/task/starttimelog/".$task->id."\"> Start Time Log </button>"; } // display variables $w->ctx("btntimelog", !empty($buttontimelog) ? $buttontimelog->__toString() : ""); $w->ctx("btndelete", $btndelete); $w->ctx("viewtask", $form); $w->ctx("extradetails", $task->displayExtraDetails()); // tab: time log // provide button to add time entry $addtime = ""; if ($task->assignee_id == $w->Auth->user()->id) { $addtime = Html::box(WEBROOT . "/task/addtime/" . $task->id, " Add Time Log entry ", true); } $w->ctx("addtime", $addtime); // get time log for task $timelog = $task->getTimeLog(); // set total period $totseconds = 0; // set headings $line = array(array("Assignee", "Start", "End", "Period (hours)", "Comment", "")); // if log exists, display ... if ($timelog) { // for each entry display, calculate period and display total time on task foreach ($timelog as $log) { // get time difference, start to end $seconds = $log->dt_end - $log->dt_start; $period = $w->Task->getFormatPeriod($seconds); // if suspect, label button, style period, remove edit button if ($log->is_suspect == "1") { $label = " Accept "; $period = "(" . $period . ")"; $bedit = ""; } // if accepted, label button, tally period, include edit button if ($log->is_suspect == "0") { $label = " Review "; $totseconds += $seconds; $bedit = Html::box($w->localUrl("/task/addtime/" . $task->id . "/" . $log->id), " Edit ", true); } // ony Task Group owner gets to reject/accept time log entries $bsuspect = $w->Task->getIsOwner($task->task_group_id, $_SESSION['user_id']) ? Html::b($w->localUrl("/task/suspecttime/" . $task->id . "/" . $log->id), $label) : ""; $line[] = array($w->Task->getUserById($log->user_id), $w->Task->getUserById($log->creator_id), formatDateTime($log->dt_start), formatDateTime($log->dt_end), $period, !empty($w->Comment->getComment($log->comment_id)) ? $w->Comment->getComment($log->comment_id)->comment : "", $bedit . Html::b($w->localUrl("/task/deletetime/" . $task->id . "/" . $log->id), " Delete ", "Are you sure you wish to DELETE this Time Log Entry?") . $bsuspect . Html::box($w->localUrl("/task/popComment/" . $task->id . "/" . $log->comment_id), " Comment ", true)); } $line[] = array("", "", "", "<b>Total</b>", "<b>" . $w->Task->getFormatPeriod($totseconds) . "</b>", ""); } else { $line[] = array("No time log entries have been made", "", "", "", "", ""); } // display the task time log $w->ctx("timelog", Html::table($line, null, "tablesorter", true)); // tab: notifications // if i am assignee, creator or task group owner, i can get notifications for this task if ($task->getCanINotify()) { // get User set notifications for this Task $notify = $w->Task->getTaskUserNotify($_SESSION['user_id'], $task->id); if ($notify) { $task_creation = $notify->task_creation; $task_details = $notify->task_details; $task_comments = $notify->task_comments; $time_log = $notify->time_log; $task_documents = $notify->task_documents; } else { // need my role in group $me = $w->Task->getMemberGroupById($task->task_group_id, $_SESSION['user_id']); // get task creator ID $creator_id = $task->getTaskCreatorId(); // which am i? $assignee = $task->assignee_id == $_SESSION['user_id'] ? true : false; $creator = $creator_id == $_SESSION['user_id'] ? true : false; $owner = $w->Task->getIsOwner($task->task_group_id, $_SESSION['user_id']); // get single type given this is specific to a single Task if ($assignee) { $type = "assignee"; } elseif ($creator) { $type = "creator"; } elseif ($owner) { $type = "other"; } $role = strtolower($me->role); if ($type) { // for type, check the User defined notification table $notify = $w->Task->getTaskGroupUserNotifyType($_SESSION['user_id'], $task->task_group_id, $role, $type); // get list of notification flags if ($notify) { if ($notify->value == "1") { $task_creation = $notify->task_creation; $task_details = $notify->task_details; $task_comments = $notify->task_comments; $time_log = $notify->time_log; $task_documents = $notify->task_documents; $task_pages = $notify->task_pages; } } } } // create form. if still no 'notify' all boxes are unchecked $f = array(array("For which Task Events should you receive Notification?", "section")); $f[] = array("", "hidden", "task_creation", "0"); $f[] = array("Task Details Update", "checkbox", "task_details", !empty($task_details) ? $task_details : null); $f[] = array("Comments Added", "checkbox", "task_comments", !empty($task_comments) ? $task_comments : null); $f[] = array("Time Log Entry", "checkbox", "time_log", !empty($time_log) ? $time_log : null); $f[] = array("Task Data Updated", "checkbox", "task_data", !empty($task_data) ? $task_data : null); $f[] = array("Documents Added", "checkbox", "task_documents", !empty($task_documents) ? $task_documents : null); $form = Html::form($f, $w->localUrl("/task/updateusertasknotify/" . $task->id), "POST", "Save"); // display $w->ctx("tasknotify", $form); } } else { // if i cannot view task details, return to task list with error message // for display get my role in the group, the group owners, the group title and the minimum membership required to view a task $me = $w->Task->getMemberGroupById($task->task_group_id, $_SESSION['user_id']); $myrole = !$me ? "Not a Member" : $me->role; $owners = $w->Task->getTaskGroupOwners($task->task_group_id); // get owners names for display $strOwners = ""; foreach ($owners as $owner) { $strOwners .= $w->Task->getUserById($owner->user_id) . ", "; } $strOwners = rtrim($strOwners, ", "); $form = "You must be at least a <b>" . $group->can_view . "</b> of the Task Group: <b>" . strtoupper($group->title) . "</b>, to view tasks in this group.<p>Your current Membership Level: <b>" . $myrole . "</b><p>Please appeal to the group owner(s): <b>" . $strOwners . "</b> for promotion."; $w->error($form, "/task/tasklist"); } }
function admin_ALL(Web $w) { History::add("Bend Admin"); }
public static function removePartnerFromIssue($iss_id, $par_code) { $params = array($iss_id, $par_code); $sql = 'DELETE FROM {{%issue_partner}} WHERE ipa_iss_id = ? AND ipa_par_code = ?'; try { DB_Helper::getInstance()->query($sql, $params); } catch (DbException $e) { return false; } $backend = self::getBackend($par_code); $backend->issueRemoved($iss_id); $usr_id = Auth::getUserID(); History::add($iss_id, $usr_id, 'partner_removed', "Partner '{partner}' removed from issue by {user}", array('partner' => $backend->getName(), 'user' => User::getFullName($usr_id))); return true; }
/** * Method used to remotely add an authorized replier to a given issue. * * @param integer $issue_id The issue ID * @param integer $usr_id The user ID of the person performing the change * @param boolean $replier The user ID of the authorized replier * @return integer The status ID */ public static function remoteAddAuthorizedReplier($issue_id, $usr_id, $replier) { $res = self::manualInsert($issue_id, $replier, false); if ($res != -1) { // save a history entry about this... History::add($issue_id, $usr_id, 'remote_replier_added', '{replier} remotely added to authorized repliers by {user}', array('replier' => $replier, 'user' => User::getFullName($usr_id))); } return $res; }
exit; } Workflow::prePage($prj_id, 'send_email'); // since emails associated with issues are sent to the notification list, not the to: field, set the to field to be blank // this field should already be blank, but may also be unset. if ($issue_id) { $_POST['to'] = ''; } if ($cat == 'send_email') { $res = Support::sendEmailFromPost($_POST['parent_id']); $tpl->assign('send_result', $res); if (Access::canChangeStatus($issue_id, $usr_id) && isset($_POST['new_status']) && !empty($_POST['new_status'])) { $res = Issue::setStatus($issue_id, $_POST['new_status']); if ($res != -1) { $new_status = Status::getStatusTitle($_POST['new_status']); History::add($issue_id, $usr_id, 'status_changed', "Status changed to '{status}' by {user} when sending an email", array('status' => $new_status, 'user' => User::getFullName($usr_id))); } } // remove the existing email draft, if appropriate if (!empty($_POST['draft_id'])) { Draft::remove($_POST['draft_id']); } // enter the time tracking entry about this new email if (!empty($_POST['time_spent'])) { $date = (array) $_POST['date']; $ttc_id = Time_Tracking::getCategoryId($prj_id, 'Email Discussion'); $time_spent = (int) $_POST['time_spent']; $summary = 'Time entry inserted when sending outgoing email.'; Time_Tracking::addTimeEntry($issue_id, $ttc_id, $time_spent, $date, $summary); } } elseif ($cat == 'save_draft') {
@($issue_id = $HTTP_GET_VARS["issue_id"] ? $HTTP_GET_VARS["issue_id"] : $HTTP_POST_VARS["issue_id"]); $details = Issue::getDetails($issue_id); $tpl->assign("issue_id", $issue_id); $tpl->assign("issue", $details); if (!Issue::canAccess($issue_id, $usr_id)) { $tpl->setTemplate("permission_denied.tpl.html"); $tpl->displayTemplate(); exit; } if (@$HTTP_POST_VARS["cat"] == "post_note") { // change status if (!@empty($HTTP_POST_VARS['new_status'])) { $res = Issue::setStatus($issue_id, $HTTP_POST_VARS['new_status']); if ($res != -1) { $new_status = Status::getStatusTitle($HTTP_POST_VARS['new_status']); History::add($issue_id, $usr_id, History::getTypeID('status_changed'), "Status changed to '{$new_status}' by " . User::getFullName($usr_id)); } } $res = Note::insert($usr_id, $issue_id); $tpl->assign("post_result", $res); // enter the time tracking entry about this phone support entry if (!empty($HTTP_POST_VARS['time_spent'])) { $HTTP_POST_VARS['issue_id'] = $issue_id; $HTTP_POST_VARS['category'] = $HTTP_POST_VARS['time_category']; $HTTP_POST_VARS['summary'] = 'Time entry inserted when sending an internal note.'; Time_Tracking::insertEntry(); } } elseif (@$HTTP_GET_VARS["cat"] == "reply") { if (!@empty($HTTP_GET_VARS["id"])) { $note = Note::getDetails($HTTP_GET_VARS["id"]); $date = Misc::formatReplyDate($note["timestamp"]);
function edit_GET(Web &$w) { $p = $w->pathMatch("id"); $w->Report->navigation($w, (!empty($p['id']) ? "Edit" : "Create") . " Report"); // Get or create report object $report = !empty($p['id']) ? $w->Report->getReport($p['id']) : new Report($w); if (!empty($p['id']) and empty($report->id)) { $w->error("Report not found", "/report"); } if (empty($report)) { History::add("Create Report"); } else { History::add("Edit Report: " . $report->title); } $w->ctx("report", $report); // If we're creating this is the table $form = array(array((!empty($report->id) ? "Edit" : "Create a New") . " Report", "section"), array("Title", "text", "title", $report->title), array("Module", "select", "module", $report->module, $w->Report->getModules()), array("Description", "textarea", "description", $report->description, "110", "2"), array("Code", "textarea", "report_code", $report->report_code, "110", "22", "codemirror"), array("Connection", "select", "report_connection_id", $report->report_connection_id, $w->Report->getConnections())); // DB view table $db_table = Html::form(array(array("Special Parameters", "section"), array("User", "static", "user", "{{current_user_id}}"), array("Roles", "static", "roles", "{{roles}}"), array("Site URL", "static", "webroot", "{{webroot}}"), array("View Database", "section"), array("Tables", "select", "dbtables", null, $w->Report->getAllDBTables()), array("Fields", "static", "dbfields", "<span id=\"dbfields\"></span>"))); $w->ctx("dbform", $db_table); if (!empty($report->id)) { $btnrun = Html::b("/report/runreport/" . $report->id, "Execute Report"); $w->ctx("btnrun", $btnrun); } // Check access rights // If user is editing, we need to check multiple things, detailed in the helper function if (!empty($report->id)) { // Get the report member object for the logged in user $member = $w->Report->getReportMember($report->id, $w->Auth->user()->id); // Check if user can edit this report if (!$w->Report->canUserEditReport($report, $member)) { $w->error("You do not have access to this report", "/report"); } } else { // If we're creating a report, check that the user has rights if ($w->Auth->user()->is_admin == 0 and !$w->Auth->user()->hasAnyRole(array('report_admin', 'report_editor'))) { $w->error("You do not have create report permissions", "/report"); } } // Access checked and OK, add approval to form only if is report_admin or admin if ($w->Auth->user()->is_admin == 1 or $w->Auth->user()->hasRole("report_admin")) { $form[0][] = array("Approved", "checkbox", "is_approved", $report->is_approved); } $w->ctx("report_form", Html::form($form, $w->localUrl("/report/edit/{$report->id}"), "POST", "Save Report")); if (!empty($report->id)) { // ============= Members tab =================== $members = $w->Report->getReportMembers($report->id); // set columns headings for display of members $line[] = array("Member", "Role", ""); // if there are members, display their full name, role and button to delete the member if ($members) { foreach ($members as $member) { $line[] = array($w->Report->getUserById($member->user_id), $member->role, Html::box("/report/editmember/" . $report->id . "/" . $member->user_id, " Edit ", true) . Html::box("/report/deletemember/" . $report->id . "/" . $member->user_id, " Delete ", true)); } } else { // if there are no members, say as much $line[] = array("Group currently has no members. Please Add New Members.", "", ""); } // display list of group members $w->ctx("viewmembers", Html::table($line, null, "tablesorter", true)); // =========== template tab ====================== $report_templates = $report->getTemplates(); // Build table $table_header = array("Title", "Category", "Type", "Actions"); $table_data = array(); if (!empty($report_templates)) { // Add data to table layout foreach ($report_templates as $report_template) { $template = $report_template->getTemplate(); $table_data[] = array($template->title, $template->category, $report_template->type, Html::box("/report-templates/edit/{$report->id}/{$report_template->id}", "Edit", true) . Html::b("/report-templates/delete/{$report_template->id}", "Delete", "Are you sure you want to delete this Report template entry?")); } } // Render table $w->ctx("templates_table", Html::table($table_data, null, "tablesorter", $table_header)); } }