/**
  * View the ticket
  *
  */
 function view()
 {
     if ($this->active_ticket->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_ticket->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     ProjectObjectViews::log($this->active_ticket, $this->logged_user);
     $this->smarty->assign(array('page_back_url' => assemble_url('mobile_access_view_tickets', array('project_id' => $this->active_project->getId()))));
     $this->addBreadcrumb(str_excerpt(clean($this->active_ticket->getName()), 10), mobile_access_module_get_view_url($this->active_ticket));
     $this->addBreadcrumb(lang('View'));
 }
Пример #2
0
 /**
  * Show projecttasks for a ticket
  *
  * @param $ticket Ticket object
  **/
 static function showForTicket(Ticket $ticket)
 {
     global $DB, $CFG_GLPI;
     $ID = $ticket->getField('id');
     if (!$ticket->can($ID, READ)) {
         return false;
     }
     $canedit = $ticket->canEdit($ID);
     $rand = mt_rand();
     $query = "SELECT DISTINCT `glpi_projecttasks_tickets`.`id` AS linkID,\n                                `glpi_projecttasks`.*\n                FROM `glpi_projecttasks`\n                LEFT JOIN `glpi_projecttasks_tickets`\n                   ON (`glpi_projecttasks_tickets`.`projecttasks_id` = `glpi_projecttasks`.`id`)\n                WHERE `glpi_projecttasks_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY `glpi_projecttasks`.`name`";
     $result = $DB->query($query);
     $pjtasks = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $pjtasks[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     //       if ($canedit) {
     //          echo "<div class='firstbloc'>";
     //          echo "<form name='projecttaskticket_form$rand' id='projecttaskticket_form$rand'
     //                 method='post' action='".Toolbox::getItemTypeFormURL(__CLASS__)."'>";
     //
     //          echo "<table class='tab_cadre_fixe'>";
     //          echo "<tr class='tab_bg_2'><th colspan='3'>".__('Add a project task')."</th></tr>";
     //
     //          echo "<tr class='tab_bg_2'><td class='right'>";
     //          echo "<input type='hidden' name='tickets_id' value='$ID'>";
     //          $condition = "`glpi_projecttasks`.`projectstates_id` <> 3";
     //          ProjectTask::dropdown(array('used'        => $used,
     //                                      'entity'      => $ticket->getEntityID(),
     //                                      'entity_sons' => $ticket->isRecursive(),
     //                                      'condition'   => $condition,
     //                                      'displaywith' => array('id')));
     //          echo "</td><td width='20%'>";
     // //          echo "<a href='".Toolbox::getItemTypeFormURL('ProjectTask')."?tickets_id=$ID'>";
     // //                 _e('Create a project task from this ticket');
     // //          echo "</a>";
     //          echo "</td><td class='center'>";
     //          echo "<input type='submit' name='add' value=\""._sx('button', 'Add')."\" class='submit'>";
     //          echo "</td></tr>";
     //
     //          echo "</table>";
     //          Html::closeForm();
     //          echo "</div>";
     //       }
     echo "<div class='spaced'>";
     if ($numrows) {
         $columns = array('projectname' => Project::getTypeName(Session::getPluralNumber()), 'name' => ProjectTask::getTypeName(Session::getPluralNumber()), 'tname' => __('Type'), 'sname' => __('Status'), 'percent_done' => __('Percent done'), 'plan_start_date' => __('Planned start date'), 'plan_end_date' => __('Planned end date'), 'planned_duration' => __('Planned duration'), '_effect_duration' => __('Effective duration'), 'fname' => __('Father'));
         if (isset($_GET["order"]) && $_GET["order"] == "DESC") {
             $order = "DESC";
         } else {
             $order = "ASC";
         }
         if (!isset($_GET["sort"]) || empty($_GET["sort"])) {
             $_GET["sort"] = "plan_start_date";
         }
         if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) {
             $sort = "`" . $_GET["sort"] . "`";
         } else {
             $sort = "`plan_start_date` {$order}, `name`";
         }
         $query = "SELECT `glpi_projecttasks`.*,\n                       `glpi_projecttasktypes`.`name` AS tname,\n                       `glpi_projectstates`.`name` AS sname,\n                       `glpi_projectstates`.`color`,\n                       `father`.`name` AS fname,\n                       `father`.`id` AS fID,\n                       `glpi_projects`.`name` AS projectname,\n                       `glpi_projects`.`content` AS projectcontent\n                FROM `glpi_projecttasks`\n                LEFT JOIN `glpi_projecttasktypes`\n                   ON (`glpi_projecttasktypes`.`id` = `glpi_projecttasks`.`projecttasktypes_id`)\n                LEFT JOIN `glpi_projectstates`\n                   ON (`glpi_projectstates`.`id` = `glpi_projecttasks`.`projectstates_id`)\n                LEFT JOIN `glpi_projecttasks` as father\n                   ON (`father`.`id` = `glpi_projecttasks`.`projecttasks_id`)\n                LEFT JOIN `glpi_projecttasks_tickets`\n                   ON (`glpi_projecttasks_tickets`.`projecttasks_id` = `glpi_projecttasks`.`id`)\n                LEFT JOIN `glpi_projects`\n                   ON (`glpi_projecttasks`.`projects_id` = `glpi_projects`.`id`)\n                WHERE `glpi_projecttasks_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY {$sort} {$order}";
         Session::initNavigateListItems('ProjectTask', sprintf(__('%1$s = %2$s'), $ticket::getTypeName(1), $ticket->getName()));
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result)) {
                 echo "<table class='tab_cadre_fixehov'>";
                 echo "<tr><th colspan='10'>" . ProjectTask::getTypeName($numrows) . "</th>";
                 echo "</tr>";
                 $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
                 $header = '<tr>';
                 foreach ($columns as $key => $val) {
                     // Non order column
                     if ($key[0] == '_') {
                         $header .= "<th>{$val}</th>";
                     } else {
                         $header .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>{$val}</a></th>";
                     }
                 }
                 $header .= "</tr>\n";
                 echo $header;
                 while ($data = $DB->fetch_assoc($result)) {
                     Session::addToNavigateListItems('ProjectTask', $data['id']);
                     $rand = mt_rand();
                     echo "<tr class='tab_bg_2'>";
                     echo "<td>";
                     $link = "<a id='Project" . $data["projects_id"] . $rand . "' href='project.form.php?id=" . $data['projects_id'] . "'>" . $data['projectname'] . (empty($data['projectname']) ? "(" . $data['projects_id'] . ")" : "") . "</a>";
                     echo sprintf(__('%1$s %2$s'), $link, Html::showToolTip($data['projectcontent'], array('display' => false, 'applyto' => "Project" . $data["projects_id"] . $rand)));
                     echo "</td>";
                     echo "<td>";
                     $link = "<a id='ProjectTask" . $data["id"] . $rand . "' href='projecttask.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a>";
                     echo sprintf(__('%1$s %2$s'), $link, Html::showToolTip($data['content'], array('display' => false, 'applyto' => "ProjectTask" . $data["id"] . $rand)));
                     echo "</td>";
                     echo "<td>" . $data['tname'] . "</td>";
                     echo "<td";
                     echo " style=\"background-color:" . $data['color'] . "\"";
                     echo ">" . $data['sname'] . "</td>";
                     echo "<td>";
                     echo Dropdown::getValueWithUnit($data["percent_done"], "%");
                     echo "</td>";
                     echo "<td>" . Html::convDateTime($data['plan_start_date']) . "</td>";
                     echo "<td>" . Html::convDateTime($data['plan_end_date']) . "</td>";
                     echo "<td>" . Html::timestampToString($data['planned_duration'], false) . "</td>";
                     echo "<td>" . Html::timestampToString(ProjectTask::getTotalEffectiveDuration($data['id']), false) . "</td>";
                     echo "<td>";
                     if ($data['projecttasks_id'] > 0) {
                         $father = Dropdown::getDropdownName('glpi_projecttasks', $data['projecttasks_id']);
                         echo "<a id='ProjectTask" . $data["projecttasks_id"] . $rand . "' href='projecttask.form.php?id=" . $data['projecttasks_id'] . "'>" . $father . (empty($father) ? "(" . $data['projecttasks_id'] . ")" : "") . "</a>";
                     }
                     echo "</td></tr>";
                 }
                 echo $header;
                 echo "</table>\n";
             } else {
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr><th>" . __('No item found') . "</th></tr>";
                 echo "</table>\n";
             }
         }
         echo "</div>";
     }
 }
Пример #3
0
 static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job)
 {
     global $CFG_GLPI, $DB;
     $ID = $job->getField('id');
     if (!$job->can($ID, 'r')) {
         return false;
     }
     $pdf->setColumnsSize(100);
     $pdf->displayTitle('<b>' . (empty($job->fields["name"]) ? __('Without title') : ($name = $job->fields["name"])) . '</b>');
     if (count($_SESSION['glpiactiveentities']) > 1) {
         $entity = " (" . Dropdown::getDropdownName("glpi_entities", $job->fields["entities_id"]) . ")";
     } else {
         $entity = '';
     }
     $pdf->setColumnsSize(50, 50);
     $recipient_name = '';
     if ($job->fields["users_id_recipient"]) {
         $recipient = new User();
         $recipient->getFromDB($job->fields["users_id_recipient"]);
         $recipient_name = $recipient->getName();
     }
     $sla = $due = $commentsla = '';
     if ($job->fields['due_date']) {
         $due = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Due date') . "</b></i>", Html::convDateTime($job->fields['due_date']));
     }
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Opening date') . "</i></b>", Html::convDateTime($job->fields["date"])), $due);
     $pdf->setColumnsSize(100);
     if ($job->fields["slas_id"] > 0) {
         $sla = "<b><i>" . sprintf(__('%1$s: %2$s'), __('SLA') . "</b></i>", Html::clean(Dropdown::getDropdownName("glpi_slas", $job->fields["slas_id"])));
         $slalevel = new SlaLevel();
         if ($slalevel->getFromDB($job->fields['slalevels_id'])) {
             $commentsla = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Escalation level') . "</b></i>", $slalevel->getName());
         }
         $nextaction = new SlaLevel_Ticket();
         if ($nextaction->getFromDBForTicket($job->fields["id"])) {
             $commentsla .= " <b><i>" . sprintf(__('Next escalation: %s') . "</b></i>", Html::convDateTime($nextaction->fields['date']));
             if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) {
                 $commentsla .= " <b><i>" . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName());
             }
         }
         $pdf->displayText($sla, $commentsla, 1);
     }
     $pdf->setColumnsSize(50, 50);
     $lastupdate = Html::convDateTime($job->fields["date_mod"]);
     if ($job->fields['users_id_lastupdater'] > 0) {
         $lastupdate = sprintf(__('%1$s by %2$s'), $lastupdate, getUserName($job->fields["users_id_lastupdater"]));
     }
     $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('By') . "</i></b>", $recipient_name), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Last update') . '</i></b>', $lastupdate));
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Type') . "</i></b>", Html::clean(Ticket::getTicketTypeName($job->fields["type"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Category') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_itilcategories", $job->fields["itilcategories_id"]))));
     $status = '';
     if (in_array($job->fields["status"], $job->getSolvedStatusArray()) || in_array($job->fields["status"], $job->getClosedStatusArray())) {
         $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields["solvedate"]));
     }
     if (in_array($job->fields["status"], $job->getClosedStatusArray())) {
         $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields["closedate"]));
     }
     if ($job->fields["status"] == Ticket::WAITING) {
         $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields['begin_waiting_date']));
     }
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Status') . "</i></b>", Html::clean($job->getStatus($job->fields["status"])) . $status), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Request source') . "</i></b>", Html::clean(Dropdown::getDropdownName('glpi_requesttypes', $job->fields['requesttypes_id']))));
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Urgency') . "</i></b>", Html::clean($job->getUrgencyName($job->fields["urgency"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Approval') . "</i></b>", TicketValidation::getStatus($job->fields['global_validation'])));
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Impact') . "</i></b>", Html::clean($job->getImpactName($job->fields["impact"]))));
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Priority') . "</i></b>", Html::clean($job->getPriorityName($job->fields["priority"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Location') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_locations", $job->fields["locations_id"]))));
     // Item
     $name = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Associated element') . "</i></b>", '');
     $commentitem = '';
     $pdf->setColumnsSize(100);
     if ($job->fields['itemtype'] && ($item = getItemForItemtype($job->fields['itemtype']))) {
         if ($item->getFromDB($job->fields["items_id"])) {
             $name = "<b><i>" . sprintf(__('%1$s: %2$s'), __('Associated element') . "</i></b>", $item->getNameID());
             if (isset($item->fields["serial"])) {
                 $commentitem = ", <b><i>" . sprintf(__('%1$s: %2$s'), __('Serial number') . "</i></b>", Html::clean($item->fields["serial"]));
                 Html::clean($item->fields["serial"]);
             }
             if (isset($item->fields["otherserial"])) {
                 $commentitem .= ", <b><i>" . sprintf(__('%1$s: %2$s'), __('Inventory number') . "</i></b>", Html::clean($item->fields["otherserial"]));
             }
             if (isset($item->fields["locations_id"])) {
                 $commentitem .= ", <b><i>" . sprintf(__('%1$s: %2$s'), __('Location') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_locations", $item->fields["locations_id"])));
             }
         }
     }
     $pdf->displayText($name, $commentitem, 1);
     $pdf->setColumnsSize(50, 50);
     // Requester
     $users = array();
     $listusers = '';
     $requester = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Requester'), $listusers);
     foreach ($job->getUsers(CommonITILActor::REQUESTER) as $d) {
         if ($d['users_id']) {
             $tmp = Html::clean(getUserName($d['users_id']));
             if ($d['alternative_email']) {
                 $tmp .= ' (' . $d['alternative_email'] . ')';
             }
         } else {
             $tmp = $d['alternative_email'];
         }
         $users[] = $tmp;
     }
     if (count($users)) {
         $listusers = implode(', ', $users);
     }
     $pdf->displayText($requester, $listusers, 1);
     $groups = array();
     $listgroups = '';
     $requestergroup = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Requester group'), $listgroups);
     foreach ($job->getGroups(CommonITILActor::REQUESTER) as $d) {
         $groups[] = Html::clean(Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
     }
     if (count($groups)) {
         $listgroups = implode(', ', $groups);
     }
     $pdf->displayText($requestergroup, $listgroups, 1);
     // Observer
     $users = array();
     $listusers = '';
     $watcher = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Watcher'), $listusers);
     foreach ($job->getUsers(CommonITILActor::OBSERVER) as $d) {
         if ($d['users_id']) {
             $tmp = Html::clean(getUserName($d['users_id']));
             if ($d['alternative_email']) {
                 $tmp .= ' (' . $d['alternative_email'] . ')';
             }
         } else {
             $tmp = $d['alternative_email'];
         }
         $users[] = $tmp;
     }
     if (count($users)) {
         $listusers = implode(', ', $users);
     }
     $pdf->displayText($watcher, $listusers, 1);
     $groups = array();
     $listgroups = '';
     $watchergroup = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Watcher group'), $listgroups);
     foreach ($job->getGroups(CommonITILActor::OBSERVER) as $d) {
         $groups[] = Html::clean(Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
     }
     if (count($groups)) {
         $listgroups = implode(', ', $groups);
     }
     $pdf->displayText($watchergroup, $listgroups, 1);
     // Assign to
     $users = array();
     $listusers = '';
     $assign = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('User assigned'), $listusers);
     foreach ($job->getUsers(CommonITILActor::ASSIGN) as $d) {
         if ($d['users_id']) {
             $tmp = Html::clean(getUserName($d['users_id']));
             if ($d['alternative_email']) {
                 $tmp .= ' (' . $d['alternative_email'] . ')';
             }
         } else {
             $tmp = $d['alternative_email'];
         }
         $users[] = $tmp;
     }
     if (count($users)) {
         $listusers = implode(', ', $users);
     }
     $pdf->displayText($assign, $listusers, 1);
     $groups = array();
     $listgroups = '';
     $assigngroup = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Group assigned'), $listgroups);
     foreach ($job->getGroups(CommonITILActor::ASSIGN) as $d) {
         $groups[] = Html::clean(Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
     }
     if (count($groups)) {
         $listgroups = implode(', ', $groups);
     }
     $pdf->displayText($assigngroup, $listgroups, 1);
     // Supplier
     $suppliers = array();
     $listsuppliers = '';
     $assignsupplier = '<b><i>' . sprintf(__('%1$s: %2$s') . "</i></b>", __('Supplier assigned'), $listsuppliers);
     foreach ($job->getSuppliers(CommonITILActor::ASSIGN) as $d) {
         $suppliers[] = Html::clean(Dropdown::getDropdownName("glpi_suppliers", $d['suppliers_id']));
     }
     if (count($suppliers)) {
         $listsuppliers = implode(', ', $suppliers);
     }
     $pdf->displayText($assignsupplier, $listsuppliers, 1);
     $pdf->setColumnsSize(100);
     $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Title') . "</i></b>", $job->fields["name"]));
     $pdf->displayText("<b><i>" . sprintf(__('%1$s: %2$s'), __('Description') . "</i></b>", $job->fields['content']));
     // Linked tickets
     $tickets = Ticket_Ticket::getLinkedTicketsTo($ID);
     if (is_array($tickets) && count($tickets)) {
         $ticket = new Ticket();
         foreach ($tickets as $linkID => $data) {
             $tmp = sprintf(__('%1$s %2$s'), Ticket_Ticket::getLinkName($data['link']), sprintf(__('%1$s %2$s'), __('ID'), $data['tickets_id']));
             if ($ticket->getFromDB($data['tickets_id'])) {
                 $tmp = sprintf(__('%1$s: %2$s'), $tmp, $ticket->getName());
             }
             $jobs[] = $tmp;
             $jobs = implode("\n", $jobs);
         }
         $linked = "<b><i>" . sprintf(__('%1$s: %2$s') . "</i></b>", __('Linked tickets'), '');
         $pdf->displayText($linked, $jobs, 1);
     }
     $pdf->displaySpace();
 }
Пример #4
0
 function getHomeTabContent($user_id = '', $tickets_due_flag = '')
 {
     require_once SMARTY_PATH . '/plugins/modifier.html_excerpt.php';
     if (empty($user_id)) {
         $user_id = $this->getId();
     }
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     $query = "select setting_value from healingcrystals_user_settings where user_id='" . $user_id . "' and setting_type='HOMETAB_LAYOUT'";
     $result = mysql_query($query);
     if (mysql_num_rows($result)) {
         $info = mysql_fetch_assoc($result);
         $layout_type = $info['setting_value'];
     } else {
         $layout_type = 'summary';
     }
     //possible values for tickets_due_flag: 'due' or 'all'
     if (empty($tickets_due_flag)) {
         $tickets_due_flag = 'due';
     }
     $query = '';
     if ($tickets_due_flag == 'due') {
         $query = "SELECT a.id, a.type, b.user_id, c.reminder_date, IF(c.reminder_date is null, a.due_on, IF(a.due_on<=c.reminder_date, a.due_on, c.reminder_date)) as old_date\n                      FROM healingcrystals_project_objects a\n                      inner join healingcrystals_assignments b on a.id=b.object_id\n                      left outer join healingcrystals_project_object_misc c on (a.id=c.object_id)\n                      where a.state='" . STATE_VISIBLE . "' and b.user_id='" . $user_id . "' and b.is_owner='1' and\n                      (a.type='Task' or a.type='Ticket') and (a.completed_on is null or a.completed_on='') and\n                      ((c.reminder_date is not null and c.reminder_date<>'0000-00-00' and c.reminder_date<=now()) or (a.due_on is not null and a.due_on<=now()) )\n                       order by b.user_id, IFNULL(a.priority, '0') desc, old_date";
     } elseif ($tickets_due_flag == 'all') {
         $query = "SELECT a.id, a.type, b.user_id\n                      FROM healingcrystals_project_objects a\n                      inner join healingcrystals_assignments b on a.id=b.object_id\n                      left outer join healingcrystals_project_object_misc c on (a.id=c.object_id)\n                      where a.state='" . STATE_VISIBLE . "' and b.user_id='" . $user_id . "' and b.is_owner='1' and\n                      (a.type='Task' or a.type='Ticket') and (a.completed_on is null or a.completed_on='') and\n                      a.due_on is not null\n                      order by b.user_id, IFNULL(a.priority, '0') desc";
     }
     if (!empty($query)) {
         $result = mysql_query($query, $link);
         $tickets_due_info = array();
         if (mysql_num_rows($result)) {
             while ($entry = mysql_fetch_assoc($result)) {
                 $tickets_due_info[] = array('type' => $entry['type'], 'id' => $entry['id'], 'reminder' => $entry['reminder_date']);
             }
         }
     }
     $query = "(select b.id, d.id as parent_ref , a.date_added as date_value, e.priority as prio, c.name as project_name\n\t\t from healingcrystals_assignments_action_request a\n\t\t inner join healingcrystals_project_objects b on a.comment_id=b.id\n\t\t inner join healingcrystals_project_objects d on b.parent_id=d.id\n\t\t left outer join healingcrystals_project_objects e on d.milestone_id=e.id\n\t\t inner join healingcrystals_projects c on b.project_id=c.id\n\t\t where b.state='" . STATE_VISIBLE . "' and a.user_id='" . $user_id . "' and a.is_action_request='1'\n                 and d.state='" . STATE_VISIBLE . "'  )\n                 union\n                 (select '' as id, a.object_id as parent_ref, b.created_on as date_value, e.priority as prio, c.name as project_name\n                 from healingcrystals_assignments_flag_fyi_actionrequest a\n                 inner join healingcrystals_project_objects b on a.object_id=b.id\n                 left outer join healingcrystals_project_objects e on b.milestone_id=e.id\n                 inner join healingcrystals_projects c on b.project_id=c.id\n                 where a.user_id='" . $user_id . "' and flag_actionrequest='1' and b.state='" . STATE_VISIBLE . "'\n                  )\n\t\t order by prio desc, project_name, date_value desc";
     //EOF:mod 20111103 #462
     $result = mysql_query($query, $link);
     $action_request_info = array();
     if (mysql_num_rows($result)) {
         while ($entry = mysql_fetch_assoc($result)) {
             if ($layout_type == 'summary') {
                 if (!array_key_exists((string) $entry['parent_ref'], $action_request_info)) {
                     $action_request_info[(string) $entry['parent_ref']] = array();
                 }
                 $action_request_info[(string) $entry['parent_ref']][] = $entry['id'];
             } else {
                 //BOF:mod 20111019 #448
                 if (empty($entry['id'])) {
                     $action_request_info[] = $entry['parent_ref'];
                 } else {
                     //EOF:mod 20111019 #448
                     $action_request_info[] = $entry['id'];
                     //BOF:mod 20111019
                 }
                 //EOF:Mod 20111019
             }
         }
     }
     $query = "(select b.id, d.id as parent_ref , a.date_added as date_value, e.priority as prio, c.name as project_name\n\t\t from healingcrystals_assignments_action_request a\n\t\t inner join healingcrystals_project_objects b on a.comment_id=b.id\n\t\t inner join healingcrystals_project_objects d on b.parent_id=d.id\n\t\t left outer join healingcrystals_project_objects e on d.milestone_id=e.id\n\t\t inner join healingcrystals_projects c on b.project_id=c.id\n\t\t where b.state='" . STATE_VISIBLE . "' and a.user_id='" . $user_id . "' and a.is_fyi='1'\n                 and d.state='" . STATE_VISIBLE . "' )\n                 union\n                 (select '' as id, a.object_id as parent_ref, b.created_on as date_value, e.priority as prio, c.name as project_name\n                 from healingcrystals_assignments_flag_fyi_actionrequest a\n                 inner join healingcrystals_project_objects b on a.object_id=b.id\n                 left outer join healingcrystals_project_objects e on b.milestone_id=e.id\n                 inner join healingcrystals_projects c on b.project_id=c.id\n                 where a.user_id='" . $user_id . "' and flag_fyi='1' and b.state='" . STATE_VISIBLE . "'\n                  )\n\t\t order by prio desc, project_name, date_value desc";
     //EOF:mod 20111103 #462
     $result = mysql_query($query, $link);
     $info = array();
     if (mysql_num_rows($result)) {
         while ($entry = mysql_fetch_assoc($result)) {
             if ($layout_type == 'summary') {
                 if (!array_key_exists((string) $entry['parent_ref'], $info)) {
                     $info[(string) $entry['parent_ref']] = array();
                 }
                 $info[(string) $entry['parent_ref']][] = $entry['id'];
             } else {
                 //BOF:mod 20111019 #448
                 if (empty($entry['id'])) {
                     $info[] = $entry['parent_ref'];
                 } else {
                     //EOF:mod 20111019 #448
                     $info[] = $entry['id'];
                     //BOF:mod 20111019
                 }
                 //EOF:Mod 20111019
             }
         }
     }
     $search_from = time() - 24 * 60 * 60;
     $query = "SELECT a.id, b.user_id FROM healingcrystals_project_objects a\n                 inner join healingcrystals_assignments b on a.id=b.object_id\n\t\t where a.state='" . STATE_VISIBLE . "' and b.user_id='" . $user_id . "' and a.type='Ticket' and a.completed_on is not null and\n\t\t a.completed_on >= '" . date('Y-m-d H:i', $search_from) . "' order by b.user_id, a.due_on";
     $result = mysql_query($query, $link);
     $completed_objects = array();
     if (mysql_num_rows($result)) {
         while ($entry = mysql_fetch_assoc($result)) {
             $query02 = "select max(id) as comment_id from healingcrystals_project_objects where parent_id='" . $entry['id'] . "' and parent_type='Ticket' and type='Comment'";
             $result02 = mysql_query($query02);
             if (mysql_num_rows($result02)) {
                 $comment_info = mysql_fetch_assoc($result02);
             }
             $completed_objects[] = array('ticket_id' => $entry['id'], 'last_comment_id' => $comment_info['comment_id']);
         }
     }
     $fyi_updates = array();
     $query = "select id, fyi_user_id, object_id from healingcrystals_project_objects_to_fyi_users where fyi_user_id='" . $user_id . "' and user_intimated_on is null";
     $result = mysql_query($query);
     if (mysql_num_rows($result)) {
         while ($entry = mysql_fetch_assoc($result)) {
             $fyi_updates[] = $entry['object_id'];
         }
     }
     $fyi_table_start = '
             <a name="fyi"></a>
             <table style="border:1px solid black;">
                 <tr>
                     <td colspan="4">&nbsp;</td>
                 </tr>' . (count($info) ? '
                 <tr>
                     <th colspan="4">FYI Comment(s)</th>
                 </tr>
                 <tr>
                     <td colspan="4">&nbsp;</td>
                 </tr>' : '');
     $fyi_table_end = '
             </table>';
     $action_request_table_start = '
             <a name="action_request"></a>
             <table style="border:1px solid black;">
                 <tr>
                     <td colspan="4">&nbsp;</td>
                 </tr>' . (count($action_request_info) ? '
                 <tr>
                     <th colspan="4">Action Request Comment(s)</th>
                 </tr>
                 <tr>
                     <td colspan="4">&nbsp;</td>
                 </tr>' : '');
     $action_request_table_end = '
             </table>';
     $completed_objects_table_start = '
             <a name="closed_tickets"></a>
             <table style="border:1px solid black;">
                 <tr>
                     <td colspan="2">&nbsp;</td>
                 </tr>' . (count($completed_objects) ? '
                 <tr>
                     <th colspan="2">Recently Closed Tickets</th>
                 </tr>
                 <tr>
                     <td colspan="2">&nbsp;</td>
                 </tr>' : '');
     $completed_objects_table_end = '
             </table>';
     $fyi_updates_table_start = '
             <table style="border:1px solid black;">
                 <tr>
                     <td colspan="2">&nbsp;</td>
                 </tr>' . (count($fyi_updates) ? '
                 <tr>
                     <th colspan="2">FYI Updates</th>
                 </tr>
                 <tr>
                     <td colspan="2">&nbsp;</td>
                 </tr>' : '');
     $fyi_updates_table_end = '
             </table>';
     $tickets_due_table_start = '
             <a name="tickets_due"></a>
             <table style="border:1px solid black;">
                 <tr><td colspan="4">&nbsp;</td></tr>
                 <tr>
                     <th colspan="4">
                         Due Tickets & Tasks:
                         <div style="float:right;font-weight:normal;">
                             <table cellspacing="0" cellpadding="0">
                                 <tr>
                                     <td valign="middle">
                                         <input type="radio" onclick="location.href=\'' . assemble_url('goto_home_tab') . '&due_flag=due\'" name="objects_due" value="due" style="width:20px;" ' . ($tickets_due_flag == 'due' ? ' checked="true"' : '') . ' />
                                     </td>
                                     <td valign="middle">Show Due Dates/Reminders</td>
                                     <td valign="middle">&nbsp;&nbsp;&nbsp;</td>
                                     <td valign="middle">
                                         <input type="radio" onclick="location.href=\'' . assemble_url('goto_home_tab') . '&due_flag=all\'" name="objects_due" value="all" style="width:20px;" ' . ($tickets_due_flag == 'all' ? ' checked="true"' : '') . ' />
                                     </td>
                                     <td valign="middle">Show All Tickets & Tasks</td>
                                 </tr>
                             </table>
                         </div>
                     </th>
                 </tr>
                 <tr><td colspan="4">&nbsp;</td></tr>
                 <tr>
                     <th align="left">Type</th>
                     <th align="left">Name</th>
                     <th align="left">Priority</th>
                     <th align="left">' . ($tickets_due_flag == 'due' ? 'Due on / Reminder' : 'Due on') . '</th>
                 </tr>';
     $tickets_due_table_end = '
             </table>';
     $tickets_due_content = '';
     if ($tickets_due_info && is_array($tickets_due_info)) {
         foreach ($tickets_due_info as $entry) {
             $type = $entry['type'];
             $obj = new $type($entry['id']);
             $due_date_val = $obj->getDueOn();
             if (!empty($due_date_val)) {
                 $due_date = date('F d, Y', strtotime($obj->getDueOn()));
             } else {
                 $due_date = '--';
             }
             if (!empty($entry['reminder']) && $entry['reminder'] != '0000-00-00') {
                 $reminder_date = date('F d, Y', strtotime($entry['reminder']));
             } else {
                 $reminder_date = '--';
             }
             if ($tickets_due_flag == 'due') {
                 $date_string = $due_date . ' / ' . $reminder_date;
             } else {
                 $date_string = $due_date;
             }
             $tickets_due_content .= '
                 <tr>
                     <td>' . $type . '</td>
                     <td>
                         <a target="_blank" href="' . $obj->getViewUrl() . '">
                             <span class="homepageobject">' . strip_tags($obj->getName()) . '</span>
                         </a>
                     </td>
                     <td>' . $obj->getFormattedPriority() . '</td>
                     <td> ' . $date_string . '</td>
                 </tr>';
             unset($obj);
         }
     } else {
         $tickets_due_content .= '
             <tr>
                 <td colspan="4">No Records to Display</td>
             </tr>';
     }
     $fyi_comments_unvisited = 0;
     $content = '';
     if ($info && is_array($info)) {
         if ($layout_type == 'summary') {
             foreach ($info as $ticket_id => $comments) {
                 //BOF:mod 20111019 #448
                 if (!empty($comments[0])) {
                     //EOF:mod 20111019 #448
                     $temp_obj = new Comment($comments[0]);
                     $parenttype = $temp_obj->getParentType();
                     //BOF:mod 20111019 #448
                 } else {
                     $temp_obj = new ProjectObject($ticket_id);
                     $parenttype = $temp_obj->getType();
                 }
                 //EOF:mod 20111019 #448
                 $parentobj = new $parenttype($ticket_id);
                 $comment_links = '';
                 //$comment_info = '';
                 $count = 0;
                 //$max_chars = 1000;
                 foreach ($comments as $comment_id) {
                     $count++;
                     //BOF:mod 20111019 #448
                     if (!empty($comment_id)) {
                         //EOF:mod 20111019 #448
                         $temp_obj = new Comment($comment_id);
                         $is_unvisited = $this->link_unvisited($temp_obj->getId());
                         if ($is_unvisited) {
                             $fyi_comments_unvisited++;
                         }
                         $comment_links .= '<a target="_blank" href="' . $temp_obj->getViewUrl() . '" class="anc01' . (!$is_unvisited ? '_visited' : '') . '">#' . $count . '</a>&nbsp;&nbsp;&nbsp;';
                         //BOF:mod 20111019 #448
                     } else {
                         $is_unvisited = $this->link_unvisited($temp_obj->getId());
                         if ($is_unvisited) {
                             $fyi_comments_unvisited++;
                         }
                         $comment_links .= '<a target="_blank" href="' . $parentobj->getViewUrl() . '" class="anc01' . (!$is_unvisited ? '_visited' : '') . '">#' . $count . '</a>&nbsp;&nbsp;&nbsp;';
                     }
                     //EOF:mod 20111019 #448
                 }
                 $content .= '
                     <tr>
                         <td vlaign="top" class="comment_link" colspan="4">
                             &nbsp;&nbsp;&nbsp;
                             <a target="_blank" href="' . $parentobj->getViewUrl() . '">
                                <span class="homepageobject">' . $parentobj->getName() . '</span>
                             </a>
                             &nbsp;&nbsp;&nbsp;' . $comment_links . '<span id="fyi_' . $parentobj->getId() . '"><img id="icon_plus" src="' . ROOT_URL . '/assets/images/icons/icon_plus.png" hspace="0" vspace="0" border="0" style="cursor:pointer;" /></span>
                         </td>
                     </tr>';
             }
         } else {
             foreach ($info as $comment_id) {
                 //BOF:mod 20111019 #448
                 $temp_obj = new ProjectObject($comment_id);
                 $temp_type = $temp_obj->getType();
                 if ($temp_type == 'Comment') {
                     //EOF:mod 20111019 #448
                     $obj = new Comment($comment_id);
                     //BOF:mod 20111019 #448
                     $is_comment_obj = true;
                 } else {
                     $obj = new $temp_type($comment_id);
                     $is_comment_obj = false;
                 }
                 //EOF:mod 20111019 #448
                 $is_unvisited = $this->link_unvisited($obj->getId());
                 if ($is_unvisited) {
                     $fyi_comments_unvisited++;
                 }
                 $created_by_id = $obj->getCreatedById();
                 $created_by_user = new User($created_by_id);
                 $created_on = strtotime($obj->getCreatedOn());
                 $created_on = date('m-d-y', $created_on);
                 $projectobj = new Project($obj->getProjectId());
                 $parenttype = $obj->getParentType();
                 //BOF:mod 20111019 #448
                 if ($is_comment_obj) {
                     //EOF:mod 20111019 #448
                     $parentobj = new $parenttype($obj->getParentId());
                     //BOF:mod 20111019 #448
                 } else {
                     $parentobj = $obj;
                 }
                 //EOF:mod 20111019 #448
                 $milestone_id = $parentobj->getMilestoneId();
                 if (!empty($milestone_id)) {
                     $milestoneobj = new Milestone($milestone_id);
                 }
                 $assigneesstring = '';
                 list($assignees, $owner_id) = $parentobj->getAssignmentData();
                 foreach ($assignees as $assignee) {
                     $assigneeobj = new User($assignee);
                     $assigneesstring .= '<a target="_blank" href="' . $assigneeobj->getViewUrl() . '">' . $assigneeobj->getName() . '</a>, ';
                     unset($assigneeobj);
                 }
                 if (!empty($assigneesstring)) {
                     $assigneesstring = substr($assigneesstring, 0, -2);
                 }
                 $dueon = date('F d, Y', strtotime($parentobj->getDueOn()));
                 if ($dueon == 'January 01, 1970') {
                     $dueon = '--';
                 }
                 if ($milestoneobj) {
                     $priority = $milestoneobj->getPriority();
                     if (!empty($priority) || $priority == '0') {
                         $priority = $milestoneobj->getFormattedPriority();
                     } else {
                         $priority = '--';
                     }
                 } else {
                     $priority = '--';
                 }
                 $max_chars = 1000;
                 $temp = $obj->getFormattedBody(true, true);
                 $comment_body = $temp;
                 $content .= '
                     <tr>
                         <td valign="top" width="150">Ticket</td>
                         <td valign="top">
                             <a target="_blank" href="' . $parentobj->getViewUrl() . '">' . $parentobj->getName() . '</a>
                         </td>
                     </tr>
                     <tr>
                         <td valign="top">Team &raquo; Project</td>
                         <td valign="top">
                             <a target="_blank" href="' . $projectobj->getOverviewUrl() . '">' . $projectobj->getName() . '</a> &raquo; ' . ($milestoneobj ? '<a target="_blank" href="' . $milestoneobj->getViewUrl() . '">' . $milestoneobj->getName() . '</a>' : '--') . '</td>
                     </tr>
                     <tr>
                         <td valign="top">Project Priority</td>
                         <td valign="top">' . $priority . '</td>
                     </tr>
                     <tr>
                         <td valign="top">Due on</td>
                         <td valign="top">' . $dueon . '</td>
                     </tr>' . (!empty($assigneesstring) ? '<tr>
                         <td valign="top">Assignees</td>
                         <td valign="top">' . $assigneesstring . '</td>
                     </tr>' : '<tr><td colpan="2"></td></tr>') . '<tr>
                         <td valign="top">' . ($is_comment_obj ? 'Comment' : 'Created') . ' by<br/>' . $created_by_user->getName() . '<br/><br/><br/><a target="_blank" href="' . $obj->getViewUrl() . '" class="anc02' . (!$is_unvisited ? '_visited' : '') . '">[view ' . ($is_comment_obj ? 'comment' : 'object') . ']</a><br/>' . $created_on . '<br/><br/><br/><a class="mark_as_read" href="' . ($is_comment_obj ? assemble_url('project_comment_fyi_read', array('project_id' => $obj->getProjectId(), 'comment_id' => $obj->getId())) : assemble_url('project_object_fyi_read', array('project_id' => $obj->getProjectId())) . '&object_id=' . $obj->getId() . '&project_id=' . $obj->getProjectId()) . '">Mark this Notification<br/>as Read</a></td>
                         <td valign="top" style="max-width:500px;"><div style="overflow:auto;">' . $obj->getBody() . '</div></td>
                     </tr>
                     <tr><td colspan="2" style="border-bottom:1px dotted #000000;">&nbsp;</td></tr>
                     <tr><td colspan="2">&nbsp;</td></tr>';
             }
         }
         unset($obj);
         unset($projectobj);
         unset($parentobj);
         unset($milestone_id);
         unset($milestoneobj);
         unset($assignees);
         unset($owner_id);
     }
     $action_request_content = '';
     $action_request_comments_unvisited = 0;
     if ($action_request_info && is_array($action_request_info)) {
         if ($layout_type == 'summary') {
             foreach ($action_request_info as $ticket_id => $comments) {
                 //BOF:mod 20111019 #448
                 if (!empty($comments[0])) {
                     //EOF:mod 20111019 #448
                     $temp_obj = new Comment($comments[0]);
                     $parenttype = $temp_obj->getParentType();
                     //BOF:mod 20111019 #448
                 } else {
                     $temp_obj = new ProjectObject($ticket_id);
                     $parenttype = $temp_obj->getType();
                 }
                 //EOF:mod 20111019 #448
                 $parentobj = new $parenttype($ticket_id);
                 $comment_links = '';
                 //$comment_info = '';
                 $count = 0;
                 //$max_chars = 1000;
                 foreach ($comments as $comment_id) {
                     $count++;
                     //BOF:mod 20111019 #448
                     if (!empty($comment_id)) {
                         //EOF:mod 20111019 #448
                         $temp_obj = new Comment($comment_id);
                         $is_unvisited = $this->link_unvisited($temp_obj->getId());
                         if ($is_unvisited) {
                             $action_request_comments_unvisited++;
                         }
                         $comment_links .= '<a target="_blank" href="' . $temp_obj->getViewUrl() . '" class="anc01' . (!$is_unvisited ? '_visited' : '') . '">#' . $count . '</a>&nbsp;&nbsp;&nbsp;';
                         //BOF:mod 20111019 #448
                     } else {
                         $is_unvisited = $this->link_unvisited($temp_obj->getId());
                         if ($is_unvisited) {
                             $action_request_comments_unvisited++;
                         }
                         $comment_links .= '<a target="_blank" href="' . $parentobj->getViewUrl() . '" class="anc01' . (!$is_unvisited ? '_visited' : '') . '">#' . $count . '</a>&nbsp;&nbsp;&nbsp;';
                     }
                     //EOF:mod 20111019 #448
                 }
                 $action_request_content .= '
                     <tr>
                         <td vlaign="top" class="comment_link" colspan="4">
                             &nbsp;&nbsp;&nbsp;
                             <a target="_blank" href="' . $parentobj->getViewUrl() . '">
                                 <span class="homepageobject">' . $parentobj->getName() . '</span>
                             </a>
                             &nbsp;&nbsp;&nbsp;' . $comment_links . '<span id="action_' . $parentobj->getId() . '"><img id="icon_plus" src="' . ROOT_URL . '/assets/images/icons/icon_plus.png" hspace="0" vspace="0" border="0" style="cursor:pointer;" /></span>
                         </td>
                     </tr>';
             }
         } else {
             foreach ($action_request_info as $comment) {
                 //BOF:mod 20111019 #448
                 $temp_obj = new ProjectObject($comment);
                 $temp_type = $temp_obj->getType();
                 if ($temp_type == 'Comment') {
                     //EOF:mod 20111019 #448
                     $obj = new Comment($comment);
                     //BOF:mod 20111019 #448
                     $is_comment_obj = true;
                 } else {
                     $obj = new $temp_type($comment);
                     $is_comment_obj = false;
                 }
                 //EOF:mod 20111019 #448
                 $is_unvisited = $this->link_unvisited($obj->getId());
                 if ($is_unvisited) {
                     $action_request_comments_unvisited++;
                 }
                 $created_by_id = $obj->getCreatedById();
                 $created_by_user = new User($created_by_id);
                 $created_on = strtotime($obj->getCreatedOn());
                 $created_on = date('m-d-y', $created_on);
                 $projectobj = new Project($obj->getProjectId());
                 $parenttype = $obj->getParentType();
                 //BOF:mod 20111019 #448
                 if ($is_comment_obj) {
                     //EOF:mod 20111019 #448
                     $parentobj = new $parenttype($obj->getParentId());
                     //BOF:mod 20111019 #448
                 } else {
                     $parentobj = $obj;
                 }
                 //EOF:mod 20111019 #448
                 $milestone_id = $parentobj->getMilestoneId();
                 if (!empty($milestone_id)) {
                     $milestoneobj = new Milestone($milestone_id);
                 }
                 $assigneesstring = '';
                 list($assignees, $owner_id) = $parentobj->getAssignmentData();
                 foreach ($assignees as $assignee) {
                     $assigneeobj = new User($assignee);
                     $assigneesstring .= '<a target="_blank" href="' . $assigneeobj->getViewUrl() . '">' . $assigneeobj->getName() . '</a>, ';
                     unset($assigneeobj);
                 }
                 if (!empty($assigneesstring)) {
                     $assigneesstring = substr($assigneesstring, 0, -2);
                 }
                 $dueon = date('F d, Y', strtotime($parentobj->getDueOn()));
                 if ($dueon == 'January 01, 1970') {
                     $dueon = '--';
                 }
                 if ($milestoneobj) {
                     $priority = $milestoneobj->getPriority();
                     if (!empty($priority) || $priority == '0') {
                         $priority = $milestoneobj->getFormattedPriority();
                     } else {
                         $priority = '--';
                     }
                 } else {
                     $priority = '--';
                 }
                 $max_chars = 1000;
                 $temp = $obj->getFormattedBody(true, true);
                 $comment_body = $temp;
                 /*$comment_body = trim(str_excerpt(smarty_modifier_html_excerpt($temp), $max_chars));
                   if (strlen($temp)>$max_chars){
                       $show_read_link = true;
                   } else {
                       $show_read_link = false;
                   }*/
                 $action_request_content .= '
                     <tr>
                         <td valign="top" width="150">Ticket</td>
                         <td valign="top">
                             <a target="_blank" href="' . $parentobj->getViewUrl() . '">' . $parentobj->getName() . '</a>
                         </td>
                     </tr>
                     <tr>
                         <td valign="top">Team &raquo; Project</td>
                         <td valign="top"><a target="_blank" href="' . $projectobj->getOverviewUrl() . '">' . $projectobj->getName() . '</a> &raquo; ' . ($milestoneobj ? '<a target="_blank" href="' . $milestoneobj->getViewUrl() . '">' . $milestoneobj->getName() . '</a>' : '--') . '</td>
                     </tr>
                     <tr>
                         <td valign="top">Project Priority</td>
                         <td valign="top">' . $priority . '</td>
                     </tr>
                     <tr>
                         <td valign="top">Due on</td>
                         <td valign="top">' . $dueon . '</td>
                     </tr>' . (!empty($assigneesstring) ? '<tr>
                         <td valign="top">Assignees</td>
                         <td valign="top">' . $assigneesstring . '</td>
                     </tr>' : '<tr><td colspan="2"></td></tr>') . '<tr>
                         <td valign="top">' . ($is_comment_obj ? 'Comment' : 'Created') . ' by<br/>' . $created_by_user->getName() . '<br/><br/><br/><a target="_blank" href="' . $obj->getViewUrl() . '" class="anc02' . (!$is_unvisited ? '_visited' : '') . '">[view ' . ($is_comment_obj ? 'comment' : 'object') . ']</a><br/>' . $created_on . '<br/><br/><br/><a class="mark_as_complete" href="' . ($is_comment_obj ? assemble_url('project_comment_action_request_completed', array('project_id' => $obj->getProjectId(), 'comment_id' => $obj->getId())) : assemble_url('project_object_action_request_completed', array('project_id' => $obj->getProjectId())) . '&object_id=' . $obj->getId() . '&project_id=' . $obj->getProjectId()) . '">Mark Action Request Complete</a></td>
                         <td valign="top" style="max-width:500px;"><div style="overflow:auto;">' . $obj->getBody() . '</div></td>
                     </tr>
                     <tr><td colspan="2" style="border-bottom:1px dotted #000000;">&nbsp;</td></tr>
                     <tr><td colspan="2">&nbsp;</td></tr>';
             }
         }
         unset($obj);
         unset($projectobj);
         unset($parentobj);
         unset($milestone_id);
         unset($milestoneobj);
         unset($assignees);
         unset($owner_id);
     }
     $completed_objects_content = '';
     if ($completed_objects && is_array($completed_objects)) {
         foreach ($completed_objects[(string) $userid] as $entry) {
             $obj = new Ticket($entry['ticket_id']);
             $projectobj = new Project($obj->getProjectId());
             $milestone_id = $obj->getMilestoneId();
             if (!empty($milestone_id)) {
                 $milestoneobj = new Milestone($milestone_id);
             }
             $assigneesstring = '';
             list($assignees, $owner_id) = $obj->getAssignmentData();
             foreach ($assignees as $assignee) {
                 $assigneeobj = new User($assignee);
                 $assigneesstring .= '<a target="_blank" href="' . $assigneeobj->getViewUrl() . '">' . $assigneeobj->getName() . '</a>, ';
                 unset($assigneeobj);
             }
             if (!empty($assigneesstring)) {
                 $assigneesstring = substr($assigneesstring, 0, -2);
             }
             $completedon = date('F d, Y', strtotime($obj->getCompletedOn()));
             if (!empty($entry['last_comment_id'])) {
                 $commentobj = new Comment($entry['last_comment_id']);
                 $last_comment_body = '<br>' . $commentobj->getBody();
                 unset($commentobj);
             } else {
                 $last_comment_body = '<br>None';
             }
             $completed_objects_content .= '
                 <tr>
                     <td valign="top" width="150">' . $obj->getType() . '</td>
                     <td valign="top"><a target="_blank" href="' . $obj->getViewUrl() . '"><span class="homepageobject">' . $obj->getName() . '</span></a></td>
                 </tr>
                 <tr>
                     <td valign="top">Team &raquo; Project</td>
                     <td valign="top"><a target="_blank" href="' . $projectobj->getOverviewUrl() . '"><span class="homepageobject">' . $projectobj->getName() . '</span></a> &raquo; ' . ($milestoneobj ? '<a target="_blank" href="' . $milestoneobj->getViewUrl() . '"><span class="homepageobject">' . $milestoneobj->getName() . '</span></a>' : '--') . '</td>
                 </tr>
                 <tr>
                     <td valign="top">Completed on</td>
                     <td valign="top">' . $completedon . '</td>
                 </tr>' . (!empty($assigneesstring) ? '<tr>
                     <td valign="top">Assignees</td>
                     <td valign="top">' . $assigneesstring . '</td>
                 </tr>' : '') . '<tr>
                     <td valign="top">&nbsp;</td>
                     <td valign="top" style="max-width:500px;"><div style="overflow:auto;">' . $obj->getBody() . '</div></td>
                 </tr>
                 <tr><td colspan="2">&nbsp;</td></tr>
                 <tr>
                     <td valign="top">&nbsp;</td>
                     <td valign="top"><b>Last comment associated with the ticket:</b><br>' . $last_comment_body . '</td>
                 </tr>
                 <tr><td colspan="2" style="border-bottom:1px dotted #000000;">&nbsp;</td></tr>
                 <tr><td colspan="2">&nbsp;</td></tr>';
             unset($obj);
             unset($projectobj);
             unset($milestone_id);
             unset($milestoneobj);
             unset($assignees);
             unset($owner_id);
         }
     }
     $fyi_updates_content = '';
     if ($fyi_updates && is_array($fyi_updates)) {
         foreach ($fyi_updates[(string) $userid] as $object_id) {
             $baseobj = new ProjectObject($object_id);
             $type = $baseobj->getType();
             switch ($baseobj->getType()) {
                 case 'Page':
                     $obj = new Page($object_id);
                     break;
             }
             if ($obj) {
                 $projectobj = new Project($obj->getProjectId());
                 $milestone_id = $obj->getMilestoneId();
                 if (!empty($milestone_id)) {
                     $milestoneobj = new Milestone($milestone_id);
                 }
                 $subscribers = $obj->getSubscribers();
                 foreach ($subscribers as $subscriber) {
                     $subscriberstring .= '<a target="_blank" href="' . $subscriber->getViewUrl() . '">' . $subscriber->getName() . '</a>, ';
                 }
                 if (!empty($subscriberstring)) {
                     $subscriberstring = substr($subscriberstring, 0, -2);
                 }
                 $fyi_updates_content .= '
             <tr>
                 <td valign="top" width="150">' . $obj->getType() . '</td>
                 <td valign="top"><a target="_blank" href="' . $obj->getViewUrl() . '"><span class="homepageobject">' . $obj->getName() . '</span></a></td>
             </tr>
             <tr>
                 <td valign="top">Team &raquo; Project</td>
                 <td valign="top"><a target="_blank" href="' . $projectobj->getOverviewUrl() . '"><span class="homepageobject">' . $projectobj->getName() . '</span></a> &raquo; ' . ($milestoneobj ? '<a target="_blank" href="' . $milestoneobj->getViewUrl() . '"><span class="homepageobject">' . $milestoneobj->getName() . '</span></a>' : '--') . '</td>
             </tr>' . (!empty($subscriberstring) ? '<tr>
                 <td valign="top">Subscribers</td>
                 <td valign="top">' . $subscriberstring . '</td>
             </tr>' : '') . '<tr>
                 <td valign="top">&nbsp;</td>
                 <td valign="top" style="max-width:500px;"><div style="overflow:auto;">' . $obj->getBody() . '</div></td>
             </tr>
             <tr><td colspan="2" style="border-bottom:1px dotted #000000;">&nbsp;</td></tr>
             <tr><td colspan="2">&nbsp;</td></tr>';
             }
             unset($obj);
             unset($projectobj);
             unset($milestoneobj);
         }
     }
     $home_tab_content = '';
     if (!empty($tickets_due_content)) {
         $home_tab_content .= $tickets_due_table_start . $tickets_due_content . $tickets_due_table_end . '<br/><br/>';
         $goto_links .= '<a href="#tickets_due">Go to Due Tickets & Tasks</a><br/>';
     }
     if (!empty($action_request_content)) {
         $home_tab_content .= $action_request_table_start . $action_request_content . $action_request_table_end . '<br/><br/>';
         $goto_links .= '<a href="#action_request">Go to Action Request Comment(s)</a><br/>';
     }
     if (!empty($content)) {
         $home_tab_content .= $fyi_table_start . $content . $fyi_table_end . '<br/><br/>';
         $goto_links .= '<a href="#fyi">Go to FYI Comment(s)</a><br/>';
     }
     if (!empty($fyi_updates_content)) {
         $home_tab_content .= $fyi_updates_table_start . $fyi_updates_content . $fyi_updates_table_end . '<br/><br/>';
     }
     if (!empty($completed_objects_content)) {
         $home_tab_content .= $completed_objects_table_start . $completed_objects_content . $completed_objects_table_end;
         $goto_links .= '<a href="#closed_tickets">Go to Closed Ticket(s)</a><br/>';
     }
     if (!empty($goto_links)) {
         $goto_links .= '<br/><br/>';
     }
     $goto_links .= '<input type="hidden" id="unvisited_fyi_comments" value="' . $fyi_comments_unvisited . '" />
                    <input type="hidden" id="unvisited_action_request_comments" value="' . $action_request_comments_unvisited . '" />
                    <input type="hidden" id="user_id" value="' . $user_id . '" />';
     $css = '
             <style>
                 td a.anc01_visited, td a.anc02_visited {color:#FF00FF;}
                 body {}
                 span.homepageobject {}
                 table tr {line-height:1.5;}:
             </style>';
     $home_tab_content = $css . $top_message . '<br/><br/>' . $goto_links . $home_tab_content;
     mysql_close($link);
     return $home_tab_content;
 }
Пример #5
0
 /**
  * Print the ticket costs
  *
  * @param $ticket                  Ticket object
  * @param $withtemplate boolean  Template or basic item (default '')
  *
  * @return Nothing (call to classes members)
  **/
 static function showForTicket(Ticket $ticket, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $ticket->fields['id'];
     if (!$ticket->getFromDB($ID) || !$ticket->can($ID, "r") || !Session::haveRight('ticketcost', 'r')) {
         return false;
     }
     $canedit = Session::haveRight('ticketcost', 'w');
     echo "<div class='center'>";
     $query = "SELECT *\n                FROM `glpi_ticketcosts`\n                WHERE `tickets_id` = '{$ID}'\n                ORDER BY `begin_date`";
     $rand = mt_rand();
     if ($canedit) {
         echo "<div id='viewcost" . $ID . "_{$rand}'></div>\n";
         echo "<script type='text/javascript' >\n";
         echo "function viewAddCost" . $ID . "_{$rand}() {\n";
         $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $ID, 'id' => -1);
         Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo "};";
         echo "</script>\n";
         echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddCost" . $ID . "_{$rand}();'>";
         echo __('Add a new cost') . "</a></div>\n";
     }
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th colspan='7'>" . self::getTypeName($DB->numrows($result)) . "</th>";
         echo "<th>" . __('Ticket duration') . "</th>";
         echo "<th>" . CommonITILObject::getActionTime($ticket->fields['actiontime']) . "</th>";
         echo "</tr>";
         if ($DB->numrows($result)) {
             echo "<tr><th>" . __('Name') . "</th>";
             echo "<th>" . __('Begin date') . "</th>";
             echo "<th>" . __('End date') . "</th>";
             echo "<th>" . __('Budget') . "</th>";
             echo "<th>" . __('Duration') . "</th>";
             echo "<th>" . __('Time cost') . "</th>";
             echo "<th>" . __('Fixed cost') . "</th>";
             echo "<th>" . __('Material cost') . "</th>";
             echo "<th>" . __('Total cost') . "</th>";
             echo "</tr>";
             Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Ticket::getTypeName(1), $ticket->getName()));
             $total = 0;
             $total_time = 0;
             $total_costtime = 0;
             $total_fixed = 0;
             $total_material = 0;
             while ($data = $DB->fetch_assoc($result)) {
                 echo "<tr class='tab_bg_2' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditCost" . $data['tickets_id'] . "_" . $data['id'] . "_{$rand}();\"" : '') . ">";
                 $name = empty($data['name']) ? sprintf(__('%1$s (%2$s)'), $data['name'], $data['id']) : $data['name'];
                 echo "<td>";
                 printf(__('%1$s %2$s'), $name, Html::showToolTip($data['comment'], array('display' => false)));
                 if ($canedit) {
                     echo "\n<script type='text/javascript' >\n";
                     echo "function viewEditCost" . $data['tickets_id'] . "_" . $data["id"] . "_{$rand}() {\n";
                     $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $data["tickets_id"], 'id' => $data["id"]);
                     Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
                     echo "};";
                     echo "</script>\n";
                 }
                 echo "</td>";
                 echo "<td>" . Html::convDate($data['begin_date']) . "</td>";
                 echo "<td>" . Html::convDate($data['end_date']) . "</td>";
                 echo "<td>" . Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']) . "</td>";
                 echo "<td>" . CommonITILObject::getActionTime($data['actiontime']) . "</td>";
                 $total_time += $data['actiontime'];
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost_time']) . "</td>";
                 $total_costtime += $data['actiontime'] * $data['cost_time'] / HOUR_TIMESTAMP;
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost_fixed']) . "</td>";
                 $total_fixed += $data['cost_fixed'];
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost_material']) . "</td>";
                 $total_material += $data['cost_material'];
                 $cost = self::computeTotalCost($data['actiontime'], $data['cost_time'], $data['cost_fixed'], $data['cost_material']);
                 echo "<td class='numeric'>" . Html::formatNumber($cost) . "</td>";
                 $total += $cost;
                 echo "</tr>";
                 Session::addToNavigateListItems(__CLASS__, $data['id']);
             }
             echo "<tr class='b'><td colspan='4' class='right'>" . __('Total') . '</td>';
             echo "<td>" . CommonITILObject::getActionTime($total_time) . "</td>";
             echo "<td class='numeric'>" . Html::formatNumber($total_costtime) . "</td>";
             echo "<td class='numeric'>" . Html::formatNumber($total_fixed) . '</td>';
             echo "<td class='numeric'>" . Html::formatNumber($total_material) . '</td>';
             echo "<td class='numeric'>" . Html::formatNumber($total) . '</td></tr>';
         } else {
             echo "<tr><th colspan='9'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
     }
     echo "</div><br>";
 }
Пример #6
0
 function create($var, &$errors, $origin, $autorespond = true, $alertstaff = true)
 {
     global $cfg, $thisclient, $_FILES;
     $id = 0;
     $fields = array();
     $fields['name'] = array('type' => 'string', 'required' => 1, 'error' => 'Name required');
     $fields['email'] = array('type' => 'email', 'required' => 1, 'error' => 'Valid email required');
     $fields['subject'] = array('type' => 'string', 'required' => 1, 'error' => 'Subject required');
     $fields['message'] = array('type' => 'text', 'required' => 1, 'error' => 'Message required');
     if (strcasecmp($origin, 'web') == 0) {
         //Help topic only applicable on web tickets.
         $fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => 'Select help topic');
     } elseif (strcasecmp($origin, 'staff') == 0) {
         //tickets created by staff...e.g on callins.
         $fields['deptId'] = array('type' => 'int', 'required' => 1, 'error' => 'Dept. required');
         $fields['source'] = array('type' => 'string', 'required' => 1, 'error' => 'Indicate source');
     } else {
         //Incoming emails (PIPE or POP.
         $fields['emailId'] = array('type' => 'int', 'required' => 1, 'error' => 'Email unknown');
     }
     $fields['pri'] = array('type' => 'int', 'required' => 0, 'error' => 'Invalid Priority');
     $fields['phone'] = array('type' => 'phone', 'required' => 0, 'error' => 'Phone # required');
     $validate = new Validator($fields);
     if (!$validate->validate($var)) {
         $errors = array_merge($errors, $validate->errors());
     }
     //Make sure the email is not banned
     if (!$errors && BanList::isbanned($var['email'])) {
         $errors['err'] = 'Ticket denied Error #403';
     }
     if (!$errors && $thisclient && strcasecmp($thisclient->getEmail(), $var['email'])) {
         $errors['email'] = 'Email mismatch.';
     }
     //check attachment..if any is set ...only set on webbased tickets..
     if ($_FILES['attachment']['name'] && $cfg->allowOnlineAttachments()) {
         if (!$cfg->canUploadFileType($_FILES['attachment']['name'])) {
             $errors['attachment'] = 'Invalid file type [ ' . $_FILES['attachment']['name'] . ' ]';
         } elseif ($_FILES['attachment']['size'] > $cfg->getMaxFileSize()) {
             $errors['attachment'] = 'File is too big. Max ' . $cfg->getMaxFileSize() . ' bytes allowed';
         }
     }
     //check ticket limits..if limit set is >0
     //TODO: Base ticket limits on SLA...
     if ($var['email'] && !$errors && $cfg->getMaxOpenTickets() > 0) {
         $openTickets = Ticket::getOpenTicketsByEmail($var['email']);
         if ($openTickets >= $cfg->getMaxOpenTickets()) {
             $errors['err'] = "You've reached the maximum open tickets allowed.";
             //Send the notice only once (when the limit is reached) incase of autoresponders at client end.
             if ($cfg->getMaxOpenTickets() == $openTickets && $cfg->sendOverlimitNotice()) {
                 $sql = 'SELECT ticket_overlimit_subj,ticket_overlimit_body FROM ' . EMAIL_TEMPLATE_TABLE . ' WHERE cfg_id=' . db_input($cfg->getId()) . ' AND tpl_id=' . db_input($cfg->getDefaultTemplateId());
                 $resp = db_query($sql);
                 if (db_num_rows($resp) && (list($subj, $body) = db_fetch_row($resp))) {
                     $body = str_replace("%name", $var['name'], $body);
                     $body = str_replace("%email", $var['email'], $body);
                     $body = str_replace("%url", $cfg->getBaseUrl(), $body);
                     Misc::sendmail($var['email'], $subj, $body, $cfg->getNoReplyEmail());
                 }
             }
             //Alert admin...this might be spammy (no option to disable)...but it is helpful..I think.
             $msg = 'Support ticket request denied for ' . $var['email'] . "\n" . 'Open ticket:' . $openTickets . "\n" . 'Max Allowed:' . $cfg->getMaxOpenTickets() . "\n";
             Misc::alertAdmin('Overlimit Notice', $msg);
         }
     }
     //Any error above is fatal.
     if ($errors) {
         return 0;
     }
     // OK...just do it.
     $deptId = $var['deptId'];
     //pre-selected Dept if any.
     $priorityId = $var['pri'];
     $source = ucfirst($var['source']);
     // Intenal mapping magic...see if we need to overwrite anything
     if (isset($var['topicId']) && !$var['deptId']) {
         //Ticket created via web by user
         if ($var['topicId'] && ($topic = new Topic($var['topicId'])) && $topic->getId()) {
             $deptId = $topic->getDeptId();
             $priorityId = $priorityId ? $priorityId : $topic->getPriorityId();
             $autorespond = $topic->autoRespond();
         }
         $topic = null;
         $source = 'Web';
     } elseif ($var['emailId'] && !$var['deptId']) {
         //Emailed Tickets
         $email = new Email($var['emailId']);
         if ($email && $email->getId()) {
             $deptId = $email->getDeptId();
             $autorespond = $email->autoRespond();
             $priorityId = $priorityId ? $priorityId : $email->getPriorityId();
         }
         $email = null;
         $source = 'Email';
     } elseif ($var['deptId']) {
         //Opened by staff.
         $deptId = $var['deptId'];
         $source = ucfirst($var['source']);
     }
     //Last minute checks
     $priorityId = $priorityId ? $priorityId : $cfg->getDefaultPriorityId();
     $deptId = $deptId ? $deptId : $cfg->getDefaultDeptId();
     $ipaddress = $var['ip'] ? $var['ip'] : $_SERVER['REMOTE_ADDR'];
     //We are ready son...hold on to the rails.
     $extId = Ticket::genExtRandID();
     $sql = 'INSERT INTO ' . TICKET_TABLE . ' SET created=NOW() ' . ',ticketID=' . db_input($extId) . ',dept_id=' . db_input($deptId) . ',priority_id=' . db_input($priorityId) . ',email=' . db_input($var['email']) . ',name=' . db_input(Format::striptags($var['name'])) . ',subject=' . db_input(Format::striptags($var['subject'])) . ',phone=' . db_input($var['phone']) . ',ip_address=' . db_input($ipaddress) . ',source=' . db_input($source);
     //echo $sql;
     $ticket = null;
     //return $ticket;
     if (db_query($sql) && ($id = db_insert_id())) {
         if (!$cfg->useRandomIds()) {
             //Sequential ticketIDs support really..really suck arse.
             $extId = $id;
             //To make things really easy we are going to use autoincrement ticket_id.
             db_query('UPDATE ' . TICKET_TABLE . ' SET ticketID=' . db_input($extId) . ' WHERE ticket_id=' . $id);
             //TODO: RETHING what happens if this fails?? [At the moment on failure random ID is used...making stuff usable]
         }
         //Load newly created ticket.
         $ticket = new Ticket($id);
         //post the message.
         $msgid = $ticket->postMessage($var['message'], $var['header'], $source, true);
         //TODO: recover from postMessage error??
         //Upload attachments...web based.
         if ($_FILES['attachment']['name'] && $cfg->allowOnlineAttachments() && $msgid) {
             if (!$cfg->allowAttachmentsOnlogin() || $cfg->allowAttachmentsOnlogin() && ($thisclient && $thisclient->isValid())) {
                 $ticket->uploadAttachment($_FILES['attachment'], $msgid, 'M');
                 //TODO: recover from upload issues?
             }
         }
         $dept = $ticket->getDept();
         //SEND OUT NEW TICKET AUTORESP && ALERTS.
         //New Ticket AutoResponse..
         if ($autorespond && $cfg->autoRespONNewTicket() && $dept->autoRespONNewTicket()) {
             $sql = 'SELECT ticket_autoresp_subj,ticket_autoresp_body FROM ' . EMAIL_TEMPLATE_TABLE . ' WHERE cfg_id=' . db_input($cfg->getId()) . ' AND tpl_id=' . db_input($cfg->getDefaultTemplateId());
             $resp = db_query($sql);
             if ($resp && (list($subj, $body) = db_fetch_row($resp))) {
                 $subj = str_replace("%ticket", $ticket->getExtId(), $subj);
                 $body = str_replace("%ticket", $ticket->getExtId(), $body);
                 $body = str_replace("%name", $ticket->getName(), $body);
                 $body = str_replace("%email", $ticket->getEmail(), $body);
                 $body = str_replace("%url", $cfg->getBaseUrl(), $body);
                 $body = str_replace("%signature", $dept ? $dept->getSignature() : '', $body);
                 $email = $from = $fromName = null;
                 if (!$dept->noreplyAutoResp() && ($email = $dept->getEmail())) {
                     $from = $email->getEmail();
                     $fromName = $email->getName();
                     //Reply separator tag.
                     if ($cfg->stripQuotedReply() && ($tag = $cfg->getReplySeparator())) {
                         $body = "\n{$tag}\n\n" . $body;
                     }
                 } else {
                     $from = $cfg->getNoReplyEmail();
                 }
                 Misc::sendmail($ticket->getEmail(), $subj, $body, $from, $fromName);
             }
         }
         //If enabled...send alert to staff (New Ticket Alert)
         if ($alertstaff && $cfg->alertONNewTicket() && is_object($ticket)) {
             $sql = 'SELECT ticket_alert_subj,ticket_alert_body FROM ' . EMAIL_TEMPLATE_TABLE . ' WHERE cfg_id=' . db_input($cfg->getId()) . ' AND tpl_id=' . db_input($cfg->getDefaultTemplateId());
             $resp = db_query($sql);
             if ($resp && (list($subj, $body) = db_fetch_row($resp))) {
                 $body = str_replace("%ticket", $ticket->getExtId(), $body);
                 $body = str_replace("%name", $ticket->getName(), $body);
                 $body = str_replace("%email", $ticket->getEmail(), $body);
                 $body = str_replace("%subject", $ticket->getSubject(), $body);
                 $body = str_replace("%dept", $dept ? $dept->getName() : '', $body);
                 $body = str_replace("%message", $var['message'], $body);
                 $body = str_replace("%url", $cfg->getBaseUrl(), $body);
                 $sentlist = array();
                 //Admin Alert.
                 if ($cfg->alertAdminONNewTicket()) {
                     $alert = str_replace("%staff", 'Admin', $body);
                     Misc::sendmail($cfg->getAdminEmail(), $subj, $alert, $cfg->getAlertEmail());
                     $sentlist[] = $cfg->getAdminEmail();
                 }
                 //get the list
                 $recipients = array();
                 //Dept. Manager
                 if ($cfg->alertDeptManagerONNewTicket()) {
                     $recipients[] = $dept->getManager();
                 }
                 //Staff members
                 if ($cfg->alertDeptMembersONNewTicket()) {
                     $sql = 'SELECT staff_id FROM ' . STAFF_TABLE . ' WHERE onvacation=0 AND dept_id=' . db_input($dept->getId());
                     if (($users = db_query($sql)) && db_num_rows($users)) {
                         while (list($id) = db_fetch_row($users)) {
                             $recipients[] = new Staff($id);
                         }
                     }
                 }
                 //Ok...we are ready to go...baby!
                 foreach ($recipients as $k => $staff) {
                     if (!$staff || !is_object($staff) || !$staff->isAvailable()) {
                         continue;
                     }
                     if (in_array($staff->getEmail(), $sentlist)) {
                         continue;
                     }
                     //avoid duplicate emails.
                     $alert = str_replace("%staff", $staff->getFirstName(), $body);
                     Misc::sendmail($staff->getEmail(), $subj, $alert, $cfg->getAlertEmail());
                     $sentlist[] = $staff->getEmail();
                 }
             }
         }
     }
     return $ticket;
 }
Пример #7
0
 public static function generateSubject(Ticket $ticket)
 {
     return 'Re: [F1LAB-HLPDSK-' . $ticket->getId() . '] ' . $ticket->getName();
 }
 /**
  * Update existing ticket
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $mode = $_GET['mode'];
     if (!empty($mode) and $mode == 'reminder_only_update_mode') {
         $this->register_reminder_info($this->active_ticket->getId(), array('date' => dateval($_POST['reminder']), 'period' => $_POST['recurring_period'], 'type' => $_POST['recurring_period_type']));
         $this->redirectToUrl($this->active_ticket->getViewUrl());
     } else {
         $this->wireframe->print_button = false;
         if ($this->request->isApiCall() && !$this->request->isSubmitted()) {
             $this->httpError(HTTP_ERR_BAD_REQUEST);
         }
         // ifs
         if ($this->active_ticket->isNew()) {
             $this->httpError(HTTP_ERR_NOT_FOUND);
         }
         // if
         if (!$this->active_ticket->canEdit($this->logged_user)) {
             $this->httpError(HTTP_ERR_FORBIDDEN);
         }
         // if
         $ticket_data = $this->request->post('ticket');
         if (!is_array($ticket_data)) {
             $ticket_data = array('name' => $this->active_ticket->getName(), 'body' => $this->active_ticket->getBody(), 'visibility' => $this->active_ticket->getVisibility(), 'parent_id' => $this->active_ticket->getParentId(), 'milestone_id' => $this->active_ticket->getMilestoneId(), 'priority' => $this->active_ticket->getPriority(), 'assignees' => Assignments::findAssignmentDataByObject($this->active_ticket), 'tags' => $this->active_ticket->getTags(), 'due_on' => $this->active_ticket->getDueOn());
         }
         // if
         //BOF:mod 20121116
         $options = array();
         $options[] = array('url' => 'javascript:convert_object_to_milestone(\'' . $this->active_ticket->getProjectId() . '\', \'' . $this->active_ticket->getId() . '\', \'' . $this->active_ticket->getType() . '\');', 'text' => 'Milestone');
         $options[] = array('url' => 'javascript:convert_object_to_page(\'' . $this->active_ticket->getProjectId() . '\', \'' . $this->active_ticket->getId() . '\', \'' . $this->active_ticket->getType() . '\');', 'text' => 'Page');
         $this->wireframe->addPageAction(lang('Convert To'), 'javascript://', $options);
         //EOF:mod 20121116
         $this->smarty->assign('ticket_data', $ticket_data);
         $this->smarty->assign('reminder', $this->get_reminder_info($this->active_ticket->getId()));
         //BOF:mod 13052011
         $this->smarty->assign('ticket_id', $this->active_ticket->getId());
         //EOF:mod 13052011
         if ($this->request->isSubmitted()) {
             if (!isset($ticket_data['assignees'])) {
                 $ticket_data['assignees'] = array(array(), 0);
             }
             // if
             db_begin_work();
             $this->active_ticket->setAttributes($ticket_data);
             $save = $this->active_ticket->save();
             if ($save && !is_error($save)) {
                 db_commit();
                 //BOF: mod
                 $this->active_ticket->register_departments(!empty($ticket_data['departments']) ? $ticket_data['departments'] : array());
                 $this->register_reminder_info($this->active_ticket->getId(), array('date' => dateval($ticket_data['reminder']), 'period' => $ticket_data['recurring_period'], 'type' => $ticket_data['recurring_period_type']));
                 //EOF: mod
                 $assignees_flag_data = $this->request->post('assignee');
                 $this->active_ticket->register_assignees_flag($assignees_flag_data);
                 //BOF:mod 13052011
                 //if ($ticket_data['flag_fyi'] || $ticket_data['flag_actionrequest']){
                 //	$this->register_flag_fyi_actionrequest($ticket_data['flag_fyi'], $ticket_data['flag_actionrequest']);
                 //}
                 //EOF:mod 13052011
                 if ($ticket_data['new_team_id'] != $this->active_project->getId()) {
                     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                     mysql_select_db(DB_NAME);
                     $query = "select max(integer_field_1) as count from healingcrystals_project_objects where project_id='" . $ticket_data['new_team_id'] . "' and type='Ticket'";
                     $result = mysql_query($query, $link);
                     $cur_ticket_id = '1';
                     if (mysql_num_rows($result)) {
                         $info = mysql_fetch_assoc($result);
                         if ($info['count']) {
                             $cur_ticket_id = (int) $info['count'] + 1;
                         }
                     }
                     $query = "update healingcrystals_project_objects set project_id='" . $ticket_data['new_team_id'] . "', milestone_id=null, integer_field_1='" . $cur_ticket_id . "', updated_on=now(), updated_by_id='" . $this->logged_user->getId() . "' where id='" . $this->active_ticket->getId() . "' and project_id='" . $this->active_project->getId() . "'";
                     mysql_query($query);
                     $query = "update healingcrystals_project_objects set project_id='" . $ticket_data['new_team_id'] . "', milestone_id=null, updated_on=now(), updated_by_id='" . $this->logged_user->getId() . "' where parent_id='" . $this->active_ticket->getId() . "' and project_id='" . $this->active_project->getId() . "'";
                     mysql_query($query);
                     mysql_close($link);
                     $this->redirectToUrl(assemble_url('project_ticket', array('project_id' => $ticket_data['new_team_id'], 'ticket_id' => $cur_ticket_id)));
                 }
                 if ($this->request->getFormat() == FORMAT_HTML) {
                     flash_success('Ticket #:ticket_id has been updated', array('ticket_id' => $this->active_ticket->getTicketId()));
                     $this->redirectToUrl($this->active_ticket->getViewUrl());
                 } else {
                     $this->serveData($this->active_ticket, 'ticket');
                 }
                 // if
             } else {
                 db_rollback();
                 if ($this->request->getFormat() == FORMAT_HTML) {
                     $this->smarty->assign('errors', $save);
                 } else {
                     $this->serveData($save);
                 }
                 // if
             }
             // if
         }
         // if
     }
 }