/**
  * postDispatch
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 public function postDispatch()
 {
     if ($this->blnPostDispatch == true) {
         // trigger client specific dispatch helper
         if ($this->core->sysConfig->helpers->client->dispatcher === 'enabled') {
             ClientHelper::get('Dispatcher')->postDispatch($this);
         }
         if (function_exists('tidy_parse_string') && $this->blnCachingOutput == false && $this->getResponse()->getBody() != '') {
             /**
              * Tidy is a binding for the Tidy HTML clean and repair utility which allows 
              * you to not only clean and otherwise manipulate HTML documents, 
              * but also traverse the document tree. 
              */
             $arrConfig = array('indent' => TRUE, 'output-xhtml' => TRUE, 'wrap' => 200);
             $objTidy = tidy_parse_string($this->getResponse()->getBody(), $arrConfig, $this->core->sysConfig->encoding->db);
             $objTidy->cleanRepair();
             $this->getResponse()->setBody($objTidy);
         }
         if (isset($this->objCache) && $this->objCache instanceof Zend_Cache_Frontend_Output) {
             if ($this->blnCachingStart === true) {
                 $response = $this->getResponse()->getBody();
                 $this->getResponse()->setBody(str_replace("<head>", "<head>\r\n      <!-- This is a ZOOLU cached page (" . date('d.m.Y H:i:s') . ") -->", $response));
                 $this->getResponse()->outputBody();
                 $arrTags = array();
                 if ($this->objPage->getIsStartElement(false) == true) {
                     $arrTags[] = 'Start' . ucfirst($this->objPage->getType());
                 }
                 $arrTags[] = ucfirst($this->objPage->getType()) . 'Type_' . $this->objPage->getTypeId();
                 $arrTags[] = ucfirst($this->objPage->getType()) . 'Id_' . $this->objPage->getPageId() . '_' . $this->objPage->getLanguageId();
                 $this->core->logger->debug(var_export($arrTags, true));
                 $this->objCache->end($arrTags);
                 $this->core->logger->debug('... end caching!');
                 exit;
             }
         }
         parent::postDispatch();
     }
 }
 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;
 }
 function move()
 {
     $new_parent_id = $this->request->post('new_parent_id');
     $new_parent_type = $this->request->post('new_parent_type');
     $new_parent_url = '';
     $move_mode = false;
     if (!empty($new_parent_id) && !empty($new_parent_type)) {
         $move_mode = true;
         $parent_obj = $sql_part = null;
         switch ($new_parent_type) {
             case 'milestone':
                 $parent_obj = new MileStone($new_parent_id);
                 break;
             case 'ticket':
                 $parent_obj = new Ticket($new_parent_id);
                 break;
             case 'page':
                 $parent_obj = new Page($new_parent_id);
                 break;
         }
         if ($parent_obj) {
             $body = $this->active_task->getBody();
             $doc = new DOMDocument();
             if ($doc->loadHTML($body)) {
                 $anc_tags = $doc->getElementsByTagName('a');
                 $new_parent_url = '';
                 foreach ($anc_tags as $anc) {
                     if ($anc->nodeValue == 'View Task in Full') {
                         $href = $anc->getAttribute('href');
                         $fragment = substr($href, strpos($href, '#'));
                         $anc->setAttribute('href', $parent_obj->getViewUrl() . $fragment);
                         break;
                     }
                 }
                 if (!empty($fragment)) {
                     $body_tag = $doc->getElementsByTagName('body');
                     $body = $doc->saveXML($body_tag->item(0)->firstChild);
                     $comment_id = str_replace('#comment', '', $fragment);
                 }
             }
             $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             mysql_select_db(DB_NAME);
             $query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t  set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tbody = '" . mysql_real_escape_string($body) . "' \n\t\t\t\t\t\t  where\tid='" . $this->active_task->getId() . "'";
             mysql_query($query, $link);
             if (!empty($comment_id)) {
                 $comment_query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t  set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tposition=null\n\t\t\t\t\t\t  where\tid='" . $comment_id . "'";
                 mysql_query($comment_query, $link);
             }
             mysql_close($link);
             $new_parent_url = $parent_obj->getViewUrl() . '#task' . $this->active_task->getId();
             $cache_id = TABLE_PREFIX . 'project_objects_id_' . $this->active_task->getId();
             $cache_obj = cache_get($cache_id);
             if ($cache_obj) {
                 cache_remove($cache_id);
             }
         }
     } else {
         $listing = array();
         switch ($this->active_task_parent->getType()) {
             case 'Milestone':
                 //$listing = Milestones::findByProject($this->active_project, $this->logged_user);
                 $listing = Milestones::findActiveByProject_custom($this->active_project);
                 break;
             case 'Ticket':
                 $listing = Tickets::findOpenByProjectByNameSort($this->active_project, STATE_VISIBLE, $this->logged_user->getVisibility());
                 break;
             case 'Page':
                 $categories = Categories::findByModuleSection($this->active_project, 'pages', 'pages');
                 $listing = Pages::findByCategories($categories, STATE_VISIBLE, $this->logged_user->getVisibility());
                 /*foreach($categories as $category){
                 			$listing = array_merge($listing, Pages::findByCategory($category, STATE_VISIBLE, $this->logged_user->getVisibility()));
                 		}*/
                 break;
         }
         $this->smarty->assign(array('teams' => Projects::findNamesByUser($this->logged_user), 'listing' => $listing, 'task_parent_id' => $this->active_task_parent->getId()));
     }
     $this->smarty->assign('new_parent_url', $new_parent_url);
     $this->smarty->assign('move_mode', $move_mode);
 }
 /**
  * Show and process edit page form. Also, handle all other page update 
  * requests
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->wireframe->print_button = false;
     if ($this->active_page->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_page->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     //BOF:mod 20110615
     $subscribers = $this->active_page->getSubscribers();
     $notify_users = array(array(), null);
     foreach ($subscribers as $subscriber) {
         $notify_users[0][] = $subscriber->getId();
     }
     $this->smarty->assign('notify_users', $notify_users);
     //EOF:mod 20110615
     $page_data = $this->request->post('page');
     if (!is_array($page_data)) {
         $page_data = array('name' => $this->active_page->getName(), 'body' => $this->active_page->getBody(), 'visibility' => $this->active_page->getVisibility(), 'parent_id' => $this->active_page->getParentId(), 'milestone_id' => $this->active_page->getMilestoneId(), 'tags' => $this->active_page->getTags());
     }
     // if
     //BOF:mod 20110519
     //$subscribers = $this->active_page->getSubscribers();
     //$page_data['subscribers'] = $subscribers;
     //EOF:mod 20110519
     //BOF:mod 20121116
     $options = array();
     $options[] = array('url' => 'javascript:convert_object_to_milestone(\'' . $this->active_page->getProjectId() . '\', \'' . $this->active_page->getId() . '\', \'' . $this->active_page->getType() . '\');', 'text' => 'Milestone');
     $options[] = array('url' => 'javascript:convert_object_to_ticket(\'' . $this->active_page->getProjectId() . '\', \'' . $this->active_page->getId() . '\', \'' . $this->active_page->getType() . '\');', 'text' => 'Ticket');
     $this->wireframe->addPageAction(lang('Convert To'), 'javascript://', $options);
     //EOF:mod 20121116
     $this->smarty->assign(array('page_data' => $page_data));
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $old_page_name = $this->active_page->getName();
         $old_page_body = $this->active_page->getBody();
         $this->active_page->setAttributes($page_data);
         $new_version = null;
         $error = null;
         // Create a new version
         if (!array_var($page_data, 'is_minor_revision', false) && ($this->active_page->getName() != $old_page_name || $this->active_page->getBody() != $old_page_body)) {
             $new_version = $this->active_page->createVersion($this->logged_user);
             if (is_error($new_version)) {
                 $error = $new_version;
             }
             // if
         }
         // if
         // Update page properties if we don't have an error already
         if (!is_error($error)) {
             //BOF:mod 20121122
             if (!empty($page_data['new_team_id']) && $page_data['new_team_id'] != $this->active_project->getId()) {
                 $this->active_page->setProjectId($page_data['new_team_id']);
             }
             //EOF:mod 20121122
             $save = $this->active_page->save();
             if (is_error($save)) {
                 $error = $save;
             }
             // if
         }
         // if
         if (!is_error($error)) {
             if ($new_version) {
                 //BOF:mod 20010519
                 /*
                 //EOF:mod 20010519
                             event_trigger('on_new_revision', array(&$this->active_page, &$new_version, &$this->logged_user));
                 //BOF:mod 20010519
                 */
                 /*if ($page_data['subscribers_to_notify']){
                 			$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                 			mysql_select_db(DB_NAME);
                 			foreach($page_data['subscribers_to_notify'] as $fyi_user_id){
                 				$query = "insert into healingcrystals_project_objects_to_fyi_users (fyi_user_id, selected_by_user_id, object_id) values ('" . $fyi_user_id . "', '" . $this->logged_user->getId() . "', '" . $this->active_page->getId() . "')";
                 				mysql_query($query);
                 			}				
                 			mysql_close($link);
                 		}*/
                 //EOF:mod 20010519
                 $activity_log = new NewPageVersionActivityLog();
                 $activity_log->log($this->active_page, $this->logged_user);
             }
             // if
             //BOF:mod 20110614
             $subscribers = $this->request->post('notify_users');
             if (!in_array($this->active_project->getLeaderId(), $subscribers)) {
                 $subscribers[] = $this->active_project->getLeaderId();
             }
             // if
             Subscriptions::subscribeUsers($subscribers, $this->active_page);
             //EOF:mod 20110614
             //Subscriptions::subscribe($this->logged_user, $this->active_page);
             db_commit();
             //BOF: mod
             $this->active_page->register_departments(!empty($page_data['departments']) ? $page_data['departments'] : array());
             //EOF: mod
             //BOF:mod 20110614
             $assignees_flag_data = $this->request->post('assignee');
             $this->active_page->register_assignees_flag($assignees_flag_data);
             //EOF:mod 20110614
             if ($this->request->getFormat() == FORMAT_HTML) {
                 flash_success('Page ":name" has been updated', array('name' => $old_page_name));
                 $this->redirectToUrl($this->active_page->getViewUrl());
             } else {
                 $this->serveData($this->active_page, 'page');
             }
             // if
         } else {
             db_rollback();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 $this->smarty->assign('errors', $error);
             } else {
                 $this->serveData($error);
             }
             // if
         }
         // if
     }
     // if
 }