/**
  * Create new comment
  *
  * @param void
  * @return null
  */
 function add()
 {
     $this->wireframe->print_button = false;
     $active_object = ProjectObjects::findById($this->request->getId('parent_id'));
     if (!instance_of($active_object, 'ProjectObject')) {
         $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall());
     }
     // if
     if (!$active_object->canComment($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall());
     }
     // if
     $active_object->prepareProjectSectionBreadcrumb($this->wireframe);
     $this->wireframe->addBreadCrumb($active_object->getName(), $active_object->getViewUrl());
     if (!$active_object->canComment($this->logged_user)) {
         if ($this->request->isApiCall()) {
             $this->httpError(HTTP_ERR_FORBIDDEN, null, true, true);
         } else {
             flash_error('Parent object not found');
             $this->redirectToReferer($this->active_project->getOverviewUrl());
         }
         // if
     }
     // if
     $comment_data = $this->request->post('comment');
     $this->smarty->assign(array('active_object' => $active_object, 'page_tab' => $active_object->getProjectTab(), 'comment_data' => $comment_data, 'recent_comments' => Comments::findRecentObject($active_object, 5, STATE_VISIBLE, $this->logged_user->getVisibility())));
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $complete_parent_object = (bool) array_var($comment_data, 'complete_parent_object');
         $this->active_comment = new Comment();
         $this->active_comment->log_activities = false;
         if ($complete_parent_object) {
             $this->active_comment->send_notification = false;
         }
         // if
         attach_from_files($this->active_comment, $this->logged_user);
         $this->active_comment->setAttributes($comment_data);
         $this->active_comment->setParent($active_object);
         $this->active_comment->setProjectId($this->active_project->getId());
         $this->active_comment->setState(STATE_VISIBLE);
         $this->active_comment->setVisibility($active_object->getVisibility());
         if (trim($this->active_comment->getCreatedByName()) == '' || trim($this->active_comment->getCreatedByEmail()) == '') {
             $this->active_comment->setCreatedBy($this->logged_user);
         }
         // if
         $save = $this->active_comment->save();
         if ($save && !is_error($save)) {
             $active_object->subscribe($this->logged_user);
             $activity = new NewCommentActivityLog();
             $activity->log($this->active_comment, $this->logged_user);
             if ($complete_parent_object && $active_object->canChangeCompleteStatus($this->logged_user)) {
                 $active_object->complete($this->logged_user, $this->active_comment->getFormattedBody(true));
             }
             // if
             db_commit();
             $this->active_comment->ready();
             //BOF: mod
             $subscribers_to_notify = array_var($comment_data, 'subscribers_to_notify');
             $action_request_user_id = array_var($comment_data, 'action_request');
             //$priority_actionrequest = array_var($comment_data, 'priority_actionrequest');
             //BOF:mod 20110517
             if ($complete_parent_object) {
                 $subscribers_to_notify = array();
                 $action_request_user_id = array();
             }
             //EOF:mod 20110517
             //BOF:mod 20110719
             /*
             //EOF:mod 20110719
             if (!empty($action_request_user_id)){
                 $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                 mysql_select_db(DB_NAME);
                 foreach ($action_request_user_id as $id){
                     $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'";
             						$result = mysql_query($query);
             						if (mysql_num_rows($result)){
                         $query = "update healingcrystals_assignments_action_request set is_action_request='1' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'";
                         mysql_query($query);
             						} else {
                         $query = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, selected_by_user_id, comment_id, date_added) values ('" . $id . "', '1', '0', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now())";
                         mysql_query($query);
                     }
                 }
             
                 foreach($priority_actionrequest as $val){
                     $temp = explode('_', $val);
             						list($temp_user_id, $priority) = $temp;
             						if (in_array($temp_user_id, $action_request_user_id)){
                         $query = "update healingcrystals_assignments_action_request set priority_actionrequest='" . $priority . "' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $temp_user_id . "'";
                         mysql_query($query);
             						}
                 }
                 mysql_close($link);
             }
             //BOF:mod 20110719
             */
             //EOF:mod 20110719
             //BOF:mod 20110719
             //$action_request_user_id = array();
             //if (!empty($priority_actionrequest)){
             $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             mysql_select_db(DB_NAME);
             if (!empty($action_request_user_id)) {
                 //foreach($priority_actionrequest as $val){
                 foreach ($action_request_user_id as $val) {
                     //$temp = explode('_', $val);
                     //list($temp_user_id, $priority) = $temp;
                     $temp_user_id = $val;
                     $priority = '0';
                     //if ((int)$priority>-10){
                     $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $temp_user_id . "'";
                     $result = mysql_query($query, $link);
                     if (mysql_num_rows($result)) {
                         $query1 = "update healingcrystals_assignments_action_request set is_action_request='1', priority_actionrequest='" . $priority . "' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $temp_user_id . "'";
                         mysql_query($query1, $link);
                     } else {
                         $query1 = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, selected_by_user_id, comment_id, date_added, priority_actionrequest) values ('" . $temp_user_id . "', '1', '0', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now(), '" . $priority . "')";
                         mysql_query($query1, $link);
                     }
                     //$action_request_user_id[] = $temp_user_id;
                     $task = new Task();
                     $task->setProjectId(TASK_LIST_PROJECT_ID);
                     $task->setParentId(Page::getTaskPageIdForUser($val));
                     $task->setParentType('Page');
                     $task->setCreatedBy($this->logged_user);
                     $task->setVisibility(VISIBILITY_NORMAL);
                     $task->setState(STATE_VISIBLE);
                     $task_body = '';
                     $parent = $this->active_comment->getParent();
                     $url = $parent->getViewUrl() . '#comment' . $this->active_comment->getId();
                     $comment_body = $this->active_comment->getBody();
                     $comment_body = strip_tags($comment_body);
                     //$task_body = substr($comment_body, 0, 10) . '.. <br/><a href="' . $url . '">View Task in Full</a>';
                     if (strlen($comment_body) > 525) {
                         $task_body .= substr($comment_body, 0, 525) . '..';
                     } else {
                         $task_body .= $comment_body;
                     }
                     $task_body .= '<br/><a href="' . $url . '">View Task in Full</a>';
                     $attachments = $this->active_comment->getAttachments();
                     if (is_foreachable($attachments)) {
                         $task_body .= '<br/>Attachments:<br/>';
                         foreach ($attachments as $attachment) {
                             $task_body .= '<a href="' . $attachment->getViewUrl() . '">' . $attachment->getName() . '</a><br/>';
                         }
                     }
                     $task->setBody($task_body);
                     $savetask = $task->save();
                     if ($savetask && !is_error($savetask)) {
                         $task->ready();
                         mysql_query("insert into actionrequests_to_tasklist (comment_id, user_id, type, object_id) values ('" . $this->active_comment->getId() . "', '" . $temp_user_id . "', 'Task', '" . $task->getId() . "')");
                     }
                     //}
                 }
             }
             //EOF:mod 20110719
             if (!empty($subscribers_to_notify)) {
                 //BOF:task_1260
                 /*
                                     //EOF:task_1260
                                     mysql_query("update healingcrystals_assignments_action_request set is_fyi='0' where object_id='" . $active_object->getId() . "'");
                 if (!empty($subscribers_to_notify)){
                 	$temp = $subscribers_to_notify;
                 	foreach($temp as $id){
                 		$query = "select * from healingcrystals_assignments_action_request where object_id='" . $active_object->getId() . "' and user_id='" . $id . "'";
                 		$result = mysql_query($query, $link);
                 		if (mysql_num_rows($result)){
                 			mysql_query("update healingcrystals_assignments_action_request set is_fyi='1' where user_id='" . $id . "' and object_id='" . $active_object->getId() . "'");
                 		} else {
                 			mysql_query("insert into healingcrystals_assignments_action_request (user_id, object_id, is_fyi) values ('" . $id . "', '" . $active_object->getId() . "', '1')");
                 		}
                 	}
                 }
                 mysql_query("delete from healingcrystals_assignments_action_request where object_id='" . $active_object->getId() . "' and is_action_request='0' and is_fyi='0'");
                 //BOF:task_1260
                 */
                 foreach ($subscribers_to_notify as $id) {
                     $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'";
                     $result = mysql_query($query);
                     if (mysql_num_rows($result)) {
                         $query = "update healingcrystals_assignments_action_request set is_fyi='1' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'";
                         mysql_query($query);
                     } else {
                         $query = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, selected_by_user_id, comment_id, date_added) values ('" . $id . "', '0', '1', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now())";
                         mysql_query($query);
                     }
                 }
                 //EOF:task_1260
             }
             //shawn wants to fire emails for only action request users and not for FYI users
             // for this, $subscribers_to_notify is set to $action_request_user_id, which will
             // take care of any assignments that were made above the code : 22-MAR-2011
             //BOF:mod 20110623
             $fyi_users = $subscribers_to_notify;
             $fyi_to = '';
             //EOF:mod 20110623
             $subscribers_to_notify = $action_request_user_id;
             //BOF:mod
             $email_to_user_ids = array_var($comment_data, 'email');
             $emailed_to = '';
             foreach ($email_to_user_ids as $user_id) {
                 $temp_user = new User($user_id);
                 //BOF:mod 20130429
                 /*
                 //EOF:mod 20130429
                 					$emailed_to .= $temp_user->getName() . ', ';
                 //BOF:mod 20130429
                 */
                 //EOF:mod 20130429
                 $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $user_id . "'";
                 $result = mysql_query($query);
                 if (mysql_num_rows($result)) {
                     $query = "update healingcrystals_assignments_action_request set marked_for_email='1' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $user_id . "'";
                     mysql_query($query);
                 } else {
                     $query = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, marked_for_email, selected_by_user_id, comment_id, date_added) values ('" . $user_id . "', '0', '0', '1', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now())";
                     mysql_query($query);
                 }
             }
             reset($email_to_user_ids);
             //EOF:mod
             if (!empty($subscribers_to_notify)) {
                 //$subscribers_to_notify = implode(',', $subscribers_to_notify);
                 //mysql_query("insert into healingcrystals_testing (query, fired_at) values ('" . $subscribers_to_notify . "', now())");
                 $notified_to = '';
                 //$subscribers = explode(',', $subscribers_to_notify);
                 $subscribers = $subscribers_to_notify;
                 $all_subscribers = $active_object->getSubscribers();
                 $excluded = array();
                 $included = array();
                 //$excluded_temp = array();
                 //$included_temp = array();
                 $subscribers_name = '';
                 foreach ($all_subscribers as $reg_subscriber) {
                     $subscribers_name .= $reg_subscriber->getName() . "<br/>";
                     $subscriber_excluded = true;
                     //if ($this->logged_user->getId()!=$reg_subscriber->getId()){
                     foreach ($subscribers as $subscriber_id) {
                         $subscriber_id = trim($subscriber_id);
                         if ($reg_subscriber->getId() == $subscriber_id) {
                             $included[] = $reg_subscriber;
                             //BOF:mod 20130429
                             /*
                             //EOF:mod 20130429
                             								$notified_to .= $reg_subscriber->getName() . ', ';
                             //BOF:mod 20130429
                             */
                             //EOF:mod 20130429
                             //$included_temp[] = $reg_subscriber->getId();
                             $subscriber_excluded = false;
                             //$subscribers_name .= $reg_subscriber->getName() . "<br/>";
                             break;
                         }
                     }
                     //BOF:mod 20110623
                     foreach ($fyi_users as $fyi_user_id) {
                         $fyi_user_id = trim($fyi_user_id);
                         if ($reg_subscriber->getId() == $fyi_user_id) {
                             //BOF:mod 20130429
                             /*
                             //EOF:mod 20130429
                             								$fyi_to .= $reg_subscriber->getName() . ', ';
                             //BOF:mod 20130429
                             */
                             //EOF:mod 20130429
                             break;
                         }
                     }
                     //EOF:mod 20110623
                     //}
                     if ($subscriber_excluded) {
                         $excluded[] = $reg_subscriber->getId();
                         //$excluded_temp[] = $reg_subscriber->getId();
                     }
                 }
                 //$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                 //mysql_select_db(DB_NAME);
                 //mysql_query("insert into healingcrystals_testing (query, fired_at) values ('" . implode('|', $included_temp) . ' = ' . implode('|', $excluded_temp) . "', now())");
                 //mysql_close($link);
                 //BOF:mod 20110517
                 //if (count($included)){
                 if (!$complete_parent_object && count($included)) {
                     //EOF:mod 20110517
                     //BOF:mod 20110623
                     //$notified_to = '<br/><br/>Notification emailed to: ' . substr($notified_to, 0, -2);
                     //$this->active_comment->setBody($this->active_comment->getBody() . $notified_to . $fyi_to);
                     //BOF:mod 20130429
                     /*
                                     //EOF:mod 20130429
                     if (!empty($notified_to)){
                     							$notified_to = '<br/><br/>Action Request marked to: ' . substr($notified_to, 0, -2);
                     }
                     if (!empty($fyi_to)){
                     							$fyi_to = (empty($notified_to) ? '<br/><br/>' : '<br/>') . 'FYI Comment marked to: ' . substr($fyi_to, 0, -2);
                     }
                     if (!empty($emailed_to)){
                     							$emailed_to = (empty($notified_to) && empty($fyi_to) ? '<br/><br/>' : '<br/>') . 'Email sent to: ' . substr($emailed_to, 0, -2);
                     }
                     $this->active_comment->setBody($this->active_comment->getBody() . $notified_to . $fyi_to . $emailed_to);
                     //EOF:mod 20110623
                     $this->active_comment->save();
                                     //BOF:mod 20130429
                     */
                     //EOF:mod 20130429
                     //BOF:mod 20110720 ticketid246
                     /*
                     //EOF:mod 20110720 ticketid246
                     $created_by = $this->active_comment->getCreatedBy();
                     $parent = $active_object;
                     $parent->sendToSubscribers('resources/new_comment', array(
                     			'comment_body' => $this->active_comment->getFormattedBody(),
                     			'comment_url' => $this->active_comment->getViewUrl(),
                     			'created_by_url' => $created_by->getViewUrl(),
                     			'created_by_name' => $created_by->getDisplayName(),
                     			'subscribers_name' => "<br/><br/>-- SET NOTIFICATIONS --<br/>" . $subscribers_name . "<br/><br/>",
                     			'comment_id' => $this->active_comment->getId(),
                     			), $excluded, $parent);
                     //BOF:mod 20110720 ticketid246
                     */
                     //EOF:mod 20110720 ticketid246
                     /*$created_by = $this->active_comment->getCreatedBy();
                     		$variables = array('owner_company_name' => get_owner_company(),
                     				'project_name'       => $this->active_project->getName(),
                     				'project_url'        => $this->active_project->getOverviewUrl(),
                     				'object_type'        => $this->active_comment->getVerboseType(),
                     				'object_name'        => $this->active_comment->getName(),
                     				'comment_body' => $this->active_comment->getFormattedBody(),
                     				'comment_url' => $this->active_comment->getViewUrl(),
                     				'created_by_url' => $created_by->getViewUrl(),
                     				'created_by_name' => $created_by->getDisplayName(),);
                     		ApplicationMailer::send($users, 'resources/new_comment', $variables, $this->active_milestone);*/
                 }
             } elseif (!empty($fyi_users)) {
                 $all_subscribers = $active_object->getSubscribers();
                 foreach ($all_subscribers as $reg_subscriber) {
                     foreach ($fyi_users as $fyi_user_id) {
                         $fyi_user_id = trim($fyi_user_id);
                         if ($reg_subscriber->getId() == $fyi_user_id) {
                             $fyi_to .= $reg_subscriber->getName() . ', ';
                             break;
                         }
                     }
                 }
                 /*$fyi_to = '<br/><br/>FYI Comment marked to: ' . substr($fyi_to, 0, -2);
                 		if (!empty($emailed_to)){
                 			$emailed_to = (empty($fyi_to) ? '<br/><br/>' : '<br/>') . 'Email sent to: ' . substr($emailed_to, 0, -2);
                                  }
                 		$this->active_comment->setBody($this->active_comment->getBody() . $fyi_to . $emailed_to);
                 		$this->active_comment->save();*/
             } elseif (!empty($email_to_user_ids)) {
                 /*$emailed_to = '<br/><br/>Email sent to: ' . substr($emailed_to, 0, -2);
                 		$this->active_comment->setBody($this->active_comment->getBody() . $emailed_to);
                 		$this->active_comment->save();*/
             }
             if (count($email_to_user_ids)) {
                 $users = array();
                 foreach ($email_to_user_ids as $user_id) {
                     if ($user_id != $this->logged_user->getId()) {
                         $users[] = new User($user_id);
                     }
                 }
                 $created_by = $this->active_comment->getCreatedBy();
                 $variables = array('owner_company_name' => get_owner_company(), 'project_name' => $this->active_project->getName(), 'project_url' => $this->active_project->getOverviewUrl(), 'object_type' => $this->active_comment->getVerboseType(), 'object_name' => $this->active_comment->getName(), 'object_body' => $this->active_comment->getFormattedBody(), 'object_url' => $this->active_comment->getViewUrl(), 'comment_body' => $this->active_comment->getFormattedBody(), 'comment_url' => $this->active_comment->getViewUrl(), 'created_by_url' => $created_by->getViewUrl(), 'created_by_name' => $created_by->getDisplayName(), 'details_body' => '', 'comment_id' => $this->active_comment->getId());
                 //BOF:mod 20111101
                 /*
                 //EOF:mod 20111101
                 ApplicationMailer::send($users, 'resources/new_comment', $variables, $this->active_milestone);
                 //BOF:mod 20111101
                 */
                 $parent_id = $this->active_comment->getParentId();
                 $parent_type = $this->active_comment->getParentType();
                 $parent_obj = new $parent_type($parent_id);
                 $attachments = null;
                 $object_attachments = $this->active_comment->getAttachments();
                 if ($object_attachments) {
                     $attachments = array();
                     foreach ($object_attachments as $object_attachment) {
                         $attachments[] = array('path' => $object_attachment->getFilePath(), 'name' => $object_attachment->getName(), 'mime_type' => $object_attachment->getMimeType());
                     }
                 }
                 ApplicationMailer::send($users, 'resources/new_comment', $variables, $parent_obj, $attachments);
                 //EOF:mod 20111101
             }
             //BOF:mod 20121030
             $modify_comments_sorting = false;
             $reply_to_comment_id = $this->request->post('reply_to_comment_id');
             if (!empty($reply_to_comment_id)) {
                 $sql_data = array('integer_field_2' => $reply_to_comment_id);
                 Comments::update($sql_data, "id='" . $this->active_comment->getId() . "'", TABLE_PREFIX . 'project_objects');
                 //$modify_comments_sorting = true;
             }
             //$count = 0;
             /*$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             		mysql_select_db(DB_NAME);
             		$sql = "select * from " . TABLE_PREFIX . "project_objects where parent_id='" . $this->active_comment->getParentId() . "' and parent_type='" . $this->active_comment->getParentType() . "' and type='Comment' and (position is null or position='0')";
             		$result = mysql_query($sql, $link);
             		if (!mysql_num_rows($result) ){
             			$sql = "select max(position) as count from " . TABLE_PREFIX . "project_objects where parent_id='" . $this->active_comment->getParentId() . "' and parent_type='" . $this->active_comment->getParentType() . "' and type='Comment'";
             			$result = mysql_query($sql, $link);
             			$info = mysql_fetch_assoc($result);
             			$count = $info['count'];
             			$sql_data = array('position' => ++$count);
             			Comments::update($sql_data, "id='" . $this->active_comment->getId() . "'", TABLE_PREFIX . 'project_objects');
             		} else {
             			$modify_comments_sorting = true;
             		}
             		mysql_close($link);*/
             //if ($modify_comments_sorting) $this->modify_comments_sorting($count);
             //EOF:mod 20121030
             if ($this->request->isApiCall()) {
                 $this->serveData($this->active_comment, 'comment');
             } else {
                 flash_success('Comment successfully posted');
                 //$this->redirectToUrl($this->active_comment->getRealViewUrl());
                 $this->redirectToUrl($this->active_comment->getParent()->getViewUrl());
             }
             // if
         } else {
             db_rollback();
             if ($this->request->isApiCall()) {
                 $this->serveData($save);
             } else {
                 $this->smarty->assign('errors', $save);
             }
             // if
         }
         // if
     } else {
         if ($this->request->isApiCall()) {
             $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, true);
         }
         // if
     }
     // if
 }
 function getAssignedActionRequestContent($user_id = '', $tickets_due_flag = '')
 {
     require_once SMARTY_PATH . '/plugins/modifier.html_excerpt.php';
     if (empty($user_id)) {
         $user_id = $this->getId();
     }
     $status_str = '';
     if ($_POST['status'] == 'complete') {
         $status_str = "and a.is_action_request != '1'";
     } elseif ($_POST['status'] == 'incomplete') {
         $status_str = "and a.is_action_request = '1'";
     }
     if ($_POST['sort'] == 'name') {
         $order_by = " order by first_name ASC, date_added DESC";
     } else {
         $order_by = " order by date_added DESC";
     }
     $assigned_ar_content = '<table width="250" border="1" cellspacing="2" cellpadding="2"> <form action="' . assemble_url('assigned_action_request') . '" method="post" name="sortForm">             
            <tr><td valign="top"><b>Sort:</b><br/><input style="width:10px;" type="radio" name="sort" value="date" onclick="" ' . ($_POST['sort'] != 'name' ? 'checked="checked"' : '') . '/> Date<br/><input style="width:10px;" type="radio" name="sort" value="name" onclick="" ' . ($_POST['sort'] == 'name' ? 'checked="checked"' : '') . '/> Assigned To</td></tr>
            <tr><td valign="top"><b>Status:</b><br/><input style="width:10px;" type="radio" name="status" value="" onclick="" ' . ($_POST['status'] == '' ? 'checked="checked"' : '') . '/> All Action Requests<br/><input style="width:10px;" type="radio" name="status" value="incomplete" onclick="" ' . ($_POST['status'] == 'incomplete' ? 'checked="checked"' : '') . '/> Incomplete Action Requests<br/><input style="width:10px;" type="radio" name="status" value="complete" onclick="" ' . ($_POST['status'] == 'complete' ? 'checked="checked"' : '') . '/> Completed Action Requests</td></tr>
            <tr><td><input style="cursor:pointer;" type="button" onclick="document.sortForm.submit();" name="Filter" value="Filter"/></td></tr>
            <tr><td><br/><br/></td></tr>
     </form> </table>';
     $assigned_ar_content .= '<table width="100%" cellspacing="2" cellpadding="2"><tr><td align="center"><b>Date</b></td><td><b>Ticket Name</b></td><td><b>Assigned To</b></td></tr>';
     $query = "select *\n                 from healingcrystals_assignments_action_request a, healingcrystals_users u\n                 where a.selected_by_user_id = '" . $user_id . "' and a.user_id = u.id " . $status_str . $order_by;
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     $result = mysql_query($query);
     while ($array = mysql_fetch_assoc($result)) {
         $comment = new Comment($array['comment_id']);
         $parent = $comment->getParent();
         if (instance_of($parent, 'ProjectObject')) {
             $assigned_ar_content .= '<tr><td valign="top" align="center" style="vertical-align:top;">' . date('m-d-Y', strtotime($comment->getCreatedOn())) . '<br/>' . date('(H:i)', strtotime($comment->getCreatedOn())) . '</td><td valign="top" style="vertical-align:top;"><a href="' . $comment->getViewUrl() . '">' . $parent->getName() . '</a>&nbsp;&nbsp;<span style="cursor:pointer; font-weight:bold" onclick="$(this).text() == \'[+]\' ? $(this).text(\'[-]\') :$(this).text(\'[+]\');$(\'#ticketResp_' . $comment->getId() . '\').toggle()">[+]</span></td><td valign="top" style="vertical-align:top;">' . $array['first_name'] . ' ' . $array['last_name'] . '</td></tr><tr style="display:none;" id="ticketResp_' . $comment->getId() . '"><td colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
             //$assigned_user = new User($array['user_id']);
             $assigned_ar_content .= '<tr><td valign="top">Priority:</td><td valign="top">' . $comment->getPriorityName() . '</td></tr>';
             $assigned_ar_content .= '<tr><td valign="top">Status:</td><td valign="top">' . ($array['is_action_request'] != '1' ? 'Complete' : 'Incomplete') . '</td></tr>';
             $assigned_ar_content .= '<tr><td valign="top">Comment:</td><td valign="top">' . $comment->getBody() . '</td></tr></table></td></tr><tr><td><br/></td></tr>';
         }
         //$assigned_ar_content .= '<tr><td colspan="3"><br/><br/></td></tr>';
     }
     mysql_close($link);
     $assigned_ar_content .= '</table>';
     return $assigned_ar_content;
 }
 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 distinct 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 distinct 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']);
             }
         }
     }
     //BOF:mod 20111103 #462
     /*
     //EOF:mod 20111103 #462
     	$query = "(select b.id, d.id as parent_ref , a.date_added as date_value, e.priority as prio, c.name as project_name
     		 from healingcrystals_assignments_action_request a
     		 inner join healingcrystals_project_objects b on a.comment_id=b.id
     		 inner join healingcrystals_project_objects d on b.parent_id=d.id
     		 left outer join healingcrystals_project_objects e on d.milestone_id=e.id
     		 inner join healingcrystals_projects c on b.project_id=c.id
     		 where b.state='" . STATE_VISIBLE . "' and a.user_id='" . $user_id . "' and a.is_action_request='1'
              and d.state='" . STATE_VISIBLE . "' and (d.completed_on is null or d.completed_on='') )
              union
              (select '' as id, a.object_id as parent_ref, b.created_on as date_value, e.priority as prio, c.name as project_name
              from healingcrystals_assignments_flag_fyi_actionrequest a
              inner join healingcrystals_project_objects b on a.object_id=b.id
              left outer join healingcrystals_project_objects e on b.milestone_id=e.id
              inner join healingcrystals_projects c on b.project_id=c.id
              where a.user_id='" . $user_id . "' and flag_actionrequest='1' and b.state='" . STATE_VISIBLE . "'
              and (b.completed_on is null or b.completed_on=''))
     		 order by prio desc, project_name, date_value desc";
     //BOF:mod 20111103 #462
     */
     $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
             }
         }
     }
     //BOF:mod 20111103 #462
     /*
     //EOF:mod 20111103 #462
     	$query = "(select b.id, d.id as parent_ref , a.date_added as date_value, e.priority as prio, c.name as project_name
     		 from healingcrystals_assignments_action_request a
     		 inner join healingcrystals_project_objects b on a.comment_id=b.id
     		 inner join healingcrystals_project_objects d on b.parent_id=d.id
     		 left outer join healingcrystals_project_objects e on d.milestone_id=e.id
     		 inner join healingcrystals_projects c on b.project_id=c.id
     		 where b.state='" . STATE_VISIBLE . "' and a.user_id='" . $user_id . "' and a.is_fyi='1'
              and d.state='" . STATE_VISIBLE . "' and (d.completed_on is null or d.completed_on='') )
              union
              (select '' as id, a.object_id as parent_ref, b.created_on as date_value, e.priority as prio, c.name as project_name
              from healingcrystals_assignments_flag_fyi_actionrequest a
              inner join healingcrystals_project_objects b on a.object_id=b.id
              left outer join healingcrystals_project_objects e on b.milestone_id=e.id
              inner join healingcrystals_projects c on b.project_id=c.id
              where a.user_id='" . $user_id . "' and flag_fyi='1' and b.state='" . STATE_VISIBLE . "'
              and (b.completed_on is null or b.completed_on=''))
     		 order by prio desc, project_name, date_value desc";
     //BOF:mod 20111103 #462
     */
     $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);
                 /*$projectobj = new Project($parentobj->getProjectId());
                 
                                     $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 = '--';
                                     }*/
                 $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++;
                         }
                         /*
                         $created_by_id = $temp_obj->getCreatedById();
                         $created_by_user = new User($created_by_id);
                         $created_on = strtotime($temp_obj->getCreatedOn());
                         $created_on = date('m-d-y', $created_on);
                         
                         $temp = $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;
                         //}
                         $comment_links .= '<a target="_blank" href="' . $temp_obj->getViewUrl() . '" class="anc01' . (!$is_unvisited ? '_visited' : '') . '">#' . $count . '</a>&nbsp;&nbsp;&nbsp;';
                         /*$comment_info .= '
                           <tr ' . ($count%2==1 ? ' style="background-color:#ffffff;" ' : ' style="background-color:#eeeeee;" ') . '>
                               <td valign="top">
                                   Comment by<br/>' .
                                   (!empty($created_by_id) ? '<a target="_blank" href="' . $created_by_user->getViewUrl() . '">' . $created_by_user->getName() . '</a>' : $temp_obj->getCreatedByName()) .
                                   '<br/><br/><br/>
                                   <a target="_blank" href="' . $temp_obj->getViewUrl() . '" class="anc02' . (!$is_unvisited ? '_visited' : '') . '">[view comment]</a><br/>&nbsp;&nbsp;&nbsp;' .
                                   $created_on .
                                   '<br/><br/><br/>
                                       <a class="mark_as_read" href="' . assemble_url('project_comment_fyi_read', array('project_id' => $temp_obj->getProjectId(), 'comment_id' => $temp_obj->getId())) . '">Mark this Notification<br/>as Read</a>
                               </td>
                               <td valign="top">
                                   <div style="overflow:auto;">' . $comment_body . '</div>' .
                                   ($show_read_link ? '<a target="_blank" href="' . $temp_obj->getViewUrl() . '">Click here to read the rest of this Comment</a>' : '') .
                               '</td>
                           </tr>
                           <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';*/
                         //BOF:mod 20111019 #448
                     } else {
                         $is_unvisited = $this->link_unvisited($temp_obj->getId());
                         if ($is_unvisited) {
                             $fyi_comments_unvisited++;
                         }
                         /*
                                                 $created_by_id = $parentobj->getCreatedById();
                                                 $created_by_user = new User($created_by_id);
                                                 $created_on = strtotime($parentobj->getCreatedOn());
                                                 $created_on = date('m-d-y', $created_on);*/
                         $comment_links .= '<a target="_blank" href="' . $parentobj->getViewUrl() . '" class="anc01' . (!$is_unvisited ? '_visited' : '') . '">#' . $count . '</a>&nbsp;&nbsp;&nbsp;';
                         /*$comment_info .= '
                           <tr ' . ($count%2==1 ? ' style="background-color:#ffffff;" ' : ' style="background-color:#eeeeee;" ') . '>
                               <td valign="top">
                                   Created by<br/>' .
                                   (!empty($created_by_id) ? '<a target="_blank" href="' . $created_by_user->getViewUrl() . '">' . $created_by_user->getName() . '</a>' : $parentobj->getCreatedByName()) .
                                   '<br/><br/><br/>
                                   <a target="_blank" href="' . $parentobj->getViewUrl() . '" class="anc02' . (!$is_unvisited ? '_visited' : '') . '">[view object]</a><br/>&nbsp;&nbsp;&nbsp;' .
                                   $created_on .
                                   '<br/><br/><br/>
                                   <a class="mark_as_read" href="' . assemble_url('project_object_fyi_read', array('project_id' => $parentobj->getProjectId())) . '&object_id=' . $parentobj->getId() . '&project_id=' . $parentobj->getProjectId() . '">Mark this Notification<br/>as Read</a>
                               </td>
                               <td valign="top">
                                   <div style="overflow:auto;">' . $parentobj->getFormattedBody(true, true) . '</div>
                               </td>
                           </tr>
                           <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';*/
                     }
                     //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>';
                 /*<tr id="row_fyi_' . $parentobj->getId() . '" style="display:none;">
                       <td colspan="4">
                           <table width="100%">
                               <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>
                               <tr>
                                   <td style="width:250px;" valign="top">Ticket</td>
                                   <td valign="top">
                                       <a target="_blank" href="' . $parentobj->getViewUrl() . '"><span class="homepageobject">' . $parentobj->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() . '</a></span>' : '--') .
                                   '</td>
                               </tr>
                               <tr>
                                   <td vlaign="top">Project Priority</td>
                                   <td valign="top">' .
                                       $priority .
                                   '</td>
                               </tr>
                               <tr>
                                   <td valign="top">Due on</td>
                                   <td valign="top">' .
                                       $dueon .
                                   '</td>
                               </tr>
                               <tr>
                                   <td valign="top">Assignees</td>
                                   <td valign="top">' .
                                       $assigneesstring .
                                   '</td>
                               </tr>
                               <tr><td colspan="2">&nbsp;</td></tr>' . $comment_info . '
                           </table>
                       </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;
                 /*$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;
                   }*/
                 $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);
                 /*$projectobj = new Project($parentobj->getProjectId());
                                     $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 = '--';
                                     }*/
                 $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++;
                         }
                         /*
                         $created_by_id = $temp_obj->getCreatedById();
                         $created_by_user = new User($created_by_id);
                         $created_on = strtotime($temp_obj->getCreatedOn());
                         $created_on = date('m-d-y', $created_on);
                         
                         $temp = $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;
                           }*/
                         $comment_links .= '<a target="_blank" href="' . $temp_obj->getViewUrl() . '" class="anc01' . (!$is_unvisited ? '_visited' : '') . '">#' . $count . '</a>&nbsp;&nbsp;&nbsp;';
                         /*$comment_info .= '
                           <tr ' . ($count%2==1 ? ' style="background-color:#ffffff;" ' : ' style="background-color:#eeeeee;" ') . '>
                               <td valign="top">
                                   Comment by<br/>' .
                                   (!empty($created_by_id) ? '<a target="_blank" href="' . $created_by_user->getViewUrl() . '">' . $created_by_user->getName() . '</a>' : $temp_obj->getCreatedByName()) .
                                   '<br/><br/><br/>
                                   <a target="_blank" href="' . $temp_obj->getViewUrl() . '" class="anc02' . (!$is_unvisited ? '_visited' : '') . '">[view comment]</a><br/>&nbsp;&nbsp;&nbsp;' .
                                   $created_on .
                                   '<br/><br/><br/>
                                   <a class="mark_as_complete" href="' . assemble_url('project_comment_action_request_completed', array('project_id' => $temp_obj->getProjectId(), 'comment_id' => $temp_obj->getId())) . '">Mark Action Request Complete</a>
                               </td>
                               <td valign="top">
                                   <div style="overflow:auto;">' . $comment_body . '</div>
                               </td>
                           </tr>
                           <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';*/
                         //BOF:mod 20111019 #448
                     } else {
                         $is_unvisited = $this->link_unvisited($temp_obj->getId());
                         if ($is_unvisited) {
                             $action_request_comments_unvisited++;
                         }
                         /*$created_by_id = $parentobj->getCreatedById();
                           $created_by_user = new User($created_by_id);
                           $created_on = strtotime($parentobj->getCreatedOn());
                           $created_on = date('m-d-y', $created_on);*/
                         $comment_links .= '<a target="_blank" href="' . $parentobj->getViewUrl() . '" class="anc01' . (!$is_unvisited ? '_visited' : '') . '">#' . $count . '</a>&nbsp;&nbsp;&nbsp;';
                         /*$comment_info .= '
                           <tr ' . ($count%2==1 ? ' style="background-color:#ffffff;" ' : ' style="background-color:#eeeeee;" ') . '>
                               <td valign="top">
                                   Created by<br/>' .
                                   (!empty($created_by_id) ? '<a target="_blank" href="' . $created_by_user->getViewUrl() . '">' . $created_by_user->getName() . '</a>' : $parentobj->getCreatedByName()) .
                                   '<br/><br/><br/>
                                   <a target="_blank" href="' . $parentobj->getViewUrl() . '" class="anc02' . (!$is_unvisited ? '_visited' : '') . '">[view object]</a><br/>&nbsp;&nbsp;&nbsp;' .
                                   $created_on .
                                   '<br/><br/><br/>
                                   <a class="mark_as_complete" href="' . assemble_url('project_object_action_request_completed', array('project_id' => $parentobj->getProjectId())) . '&object_id=' . $parentobj->getId() . '&project_id=' . $parentobj->getProjectId() . '">Mark Action Request Complete</a>
                               </td>
                               <td valign="top">
                                   <div style="overflow:auto;">' . $parentobj->getFormattedBody(true, true) . '</div>' .
                                   ($show_read_link ? '<a target="_blank" href="' . $temp_obj->getViewUrl() . '">Click here to read the rest of this Comment</a>' : '') .
                               '</td>
                           </tr>
                           <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';*/
                     }
                     //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>';
                 /*<tr id="row_action_' . $parentobj->getId() . '" style="display:none;">
                       <td colspan="4">
                           <table width="100%">
                               <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>
                               <tr>
                                   <td style="width:250px;" valign="top">Ticket</td>
                                   <td valign="top">
                                       <a target="_blank" href="' . $parentobj->getViewUrl() . '"><span class="homepageobject">' . $parentobj->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() . '</a></span>' : '--') .
                                   '</td>
                               </tr>
                               <tr>
                                   <td vlaign="top">Project Priority</td>
                                   <td valign="top">' .
                                       $priority .
                                   '</td>
                               </tr>
                               <tr>
                                   <td valign="top">Due on</td>
                                   <td valign="top">' .
                                       $dueon .
                                   '</td>
                               </tr>
                               <tr>
                                   <td valign="top">Assignees</td>
                                   <td valign="top">' .
                                       $assigneesstring .
                                   '</td>
                               </tr>
                               <tr><td colspan="2">&nbsp;</td></tr>' . $comment_info . '
                           </table>
                       </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.icon {padding:0px 6px 6px 0px;background-image:url("assets/images/icons/icon_comment.png"); background-repeat:no-repeat;background-position:0px 0px;}*/
                 /*td a.anc01:visited, td a.anc02:visited {color:#FF00FF;}*/
                 td a.anc01_visited, td a.anc02_visited {color:#FF00FF;}
                 body {}
                 span.homepageobject {}
                 table tr {line-height:1.5;}:
             </style>';
     /*<script type="text/javascript">
           function toggle_details(imgref, type, id){
               try{
                   //$("tr[id^=\'row_action_\']").css("display", "none");
                   //$("tr[id^=\'row_fyi_\']").css("display", "none");
                   var src =  $(imgref).attr("src");
                   if (src.indexOf("icon_plus.png")!=-1){
                       $("tr#row_" + type + "_" + id).css("display", "");
                       $(imgref).attr("src", src.replace(/icon_plus.png/, "icon_minus.png"));
                   } else {
                       $("tr#row_" + type + "_" + id).css("display", "none");
                       $(imgref).attr("src", src.replace(/icon_minus.png/, "icon_plus.png"));
                   }
               } catch(e){
                   alert(e);
               }
           }
       </script>';*/
     $home_tab_content = $css . $top_message . '<br/><br/>' . $goto_links . $home_tab_content;
     mysql_close($link);
     return $home_tab_content;
 }
 function get_action_request_comment_body()
 {
     $body = '';
     $row = db_execute_one("select comment_id from actionrequests_to_tasklist where object_id='" . $this->getId() . "'");
     if ($row) {
         if (!empty($row['comment_id'])) {
             $comment = new Comment($row['comment_id']);
             $body = strip_tags($comment->getBody(), '<p>') . '<br/><a href="' . $comment->getViewUrl() . '">Click to View Comment</a>';
         }
     }
     return $body;
 }
 function render_comments()
 {
     $response = '<table width="100%" style="border:5px solid #dddddd;">';
     $user_id = $this->request->get('user_id');
     if (empty($user_id)) {
         $user_id = $this->request->post('user_id');
         if (empty($user_id)) {
             $user_id = $this->logged_user->getId();
         }
     }
     $action_type = $_GET['action_type'];
     $parent_id = $_GET['parent_id'];
     $temp_obj = new ProjectObject($parent_id);
     $parenttype = $temp_obj->getType();
     $parentobj = new $parenttype($parent_id);
     $projectobj = new Project($parentobj->getProjectId());
     $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 = '--';
     }
     $response .= '
             <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>
                 <tr>
                     <td style="width:25%;" valign="top">' . $parenttype . '</td>
                     <td valign="top">
                         <a target="_blank" href="' . $parentobj->getViewUrl() . '"><span class="homepageobject">' . $parentobj->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() . '</a></span>' : '--') . '</td>
                 </tr>
                 <tr>
                     <td vlaign="top">Project Priority</td>
                     <td valign="top">' . $priority . '</td>
                 </tr>
                 <tr>
                     <td valign="top">Due on</td>
                     <td valign="top">' . $dueon . '</td>
                 </tr>
                 <tr>
                     <td valign="top">Assignees</td>
                     <td valign="top">' . $assigneesstring . '</td>
                 </tr>
                 <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     if ($action_type == 'actionrequest') {
         $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                     from healingcrystals_assignments_action_request a\n                     inner join healingcrystals_project_objects b on a.comment_id=b.id\n                     inner join healingcrystals_project_objects d on b.parent_id=d.id\n                     left outer join healingcrystals_project_objects e on d.milestone_id=e.id\n                     inner join healingcrystals_projects c on b.project_id=c.id\n                     where d.id='" . $parent_id . "' and 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 a.object_id='" . $parent_id . "' and flag_actionrequest='1' and b.state='" . STATE_VISIBLE . "'\n                      )\n                     order by prio desc, project_name, date_value desc";
     } elseif ($action_type == 'fyi') {
         $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                     from healingcrystals_assignments_action_request a\n                     inner join healingcrystals_project_objects b on a.comment_id=b.id\n                     inner join healingcrystals_project_objects d on b.parent_id=d.id\n                     left outer join healingcrystals_project_objects e on d.milestone_id=e.id\n                     inner join healingcrystals_projects c on b.project_id=c.id\n                     where d.id='" . $parent_id . "' and 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 a.object_id='" . $parent_id . "' and flag_fyi='1' and b.state='" . STATE_VISIBLE . "'\n                      )\n                     order by prio desc, project_name, date_value desc";
     }
     $result = mysql_query($query);
     $count = 0;
     while ($entry = mysql_fetch_assoc($result)) {
         $count++;
         if (!empty($entry['id'])) {
             $temp_obj = new Comment($entry['id']);
             $created_by_id = $temp_obj->getCreatedById();
             $created_by_user = new User($created_by_id);
             $created_on = strtotime($temp_obj->getCreatedOn());
             $created_on = date('m-d-y', $created_on);
             $temp = $temp_obj->getFormattedBody(true, true);
             $comment_body = $temp;
             $response .= '
                     <tr>
                         <td valign="top" style="vertical-align:top;">
                             Comment by<br/>' . (!empty($created_by_id) ? '<a target="_blank" href="' . $created_by_user->getViewUrl() . '">' . $created_by_user->getName() . '</a>' : $temp_obj->getCreatedByName()) . '<br/><br/><br/>
                             <a target="_blank" href="' . $temp_obj->getViewUrl() . '">[view comment]</a><br/>&nbsp;&nbsp;&nbsp;' . $created_on . '<br/><br/><br/>' . ($action_type == 'actionrequest' ? '<a class="mark_as_complete" count="' . $count . '" href="' . assemble_url('project_comment_action_request_completed', array('project_id' => $temp_obj->getProjectId(), 'comment_id' => $temp_obj->getId())) . '">Mark Action Request Complete</a>' : '') . ($action_type == 'fyi' ? '<a class="mark_as_read" count="' . $count . '" href="' . assemble_url('project_comment_fyi_read', array('project_id' => $temp_obj->getProjectId(), 'comment_id' => $temp_obj->getId())) . '">Mark this Notification<br/>as Read</a>' : '') . '</td>
                         <td valign="top" style="vertical-align:top;">
                             <div style="width:600px;overflow:auto;">' . $comment_body . '</div>' . ($show_read_link ? '<a target="_blank" href="' . $temp_obj->getViewUrl() . '">Click here to read the rest of this Comment</a>' : '') . '</td>
                     </tr>
                     <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';
         } else {
             $response .= '
                     <tr>
                        <td valign="top" style="vertical-align:top;">
                             Created by<br/>' . (!empty($created_by_id) ? '<a target="_blank" href="' . $created_by_user->getViewUrl() . '">' . $created_by_user->getName() . '</a>' : $parentobj->getCreatedByName()) . '<br/><br/><br/>
                             <a target="_blank" href="' . $parentobj->getViewUrl() . '">[view object]</a><br/>&nbsp;&nbsp;&nbsp;' . $created_on . '<br/><br/><br/>' . ($action_type == 'action_request' ? '<a class="mark_as_complete" count="' . $count . '" href="' . assemble_url('project_object_action_request_completed', array('project_id' => $parentobj->getProjectId())) . '&object_id=' . $parentobj->getId() . '&project_id=' . $parentobj->getProjectId() . '">Mark Action Request Complete</a>' : '') . ($action_type == 'fyi' ? '<a class="mark_as_read" count="' . $count . '" href="' . assemble_url('project_object_fyi_read', array('project_id' => $parentobj->getProjectId())) . '&object_id=' . $parentobj->getId() . '&project_id=' . $parentobj->getProjectId() . '">Mark this Notification<br/>as Read</a>' : '') . '</td>
                         <td valign="top" style="vertical-align:top;">
                             <div style="width:600px;overflow:auto;">' . $parentobj->getFormattedBody(true, true) . '</div>
                         </td>
                     </tr>
                     <tr><td colspan="2" style="height:20px;">&nbsp;</td></tr>';
         }
     }
     mysql_close($link);
     $response .= '</table>';
     $this->smarty->assign('response', $response);
 }
/**
 * Handle on_comment_added event (send email notifications)
 *
 * @param Comment $comment
 * @param ProjectObject $parent
 * @return null
 */
function resources_handle_on_comment_added(&$comment, &$parent)
{
    if (instance_of($parent, 'ProjectObject')) {
        $parent->refreshCommentsCount();
        //BOF:mod
        $subscribers_name = '';
        $all_subscribers = $parent->getSubscribers();
        foreach ($all_subscribers as $reg_subscriber) {
            $subscribers_name .= $reg_subscriber->getName() . "<br/>";
        }
        if (!empty($subscribers_name)) {
            $subscribers_name = "<br/><br/>-- SET NOTIFICATIONS --<br/>" . $subscribers_name . "<br/><br/>";
        }
        //EOF:mod
        if ($comment->send_notification) {
            $temp = explode("\n", strip_tags(htmlspecialchars($comment->getBody())));
            $flag_line_located = false;
            $flag_start_now = false;
            $notify_to = array();
            $expression = '/\\W+\\s?\\W+/';
            //$info = '#';
            foreach ($temp as $line) {
                if (!$flag_line_located) {
                    $pos = strpos($line, 'SET NOTIFICATIONS');
                    if ($pos !== false) {
                        $flag_line_located = true;
                    }
                }
                if ($flag_line_located) {
                    if ($flag_start_now) {
                        if ($line && $line != '') {
                            $split_vals = explode(' ', $line);
                            $first_name = '';
                            $last_name = '';
                            //$info .= '*' . $line . '|' . count($split_vals) .  '*';
                            for ($i = count($split_vals) - 1; $i >= 0; $i--) {
                                //$info .= '*' . $i . '|' . $split_vals[$i] . '*';
                                $val = $split_vals[$i];
                                preg_match_all($expression, $val, $matches);
                                //$info .= '*' . $val . ' | ' . count($matches[0]) . '*';
                                if (!count($matches[0])) {
                                    if ($last_name == '') {
                                        $last_name = $val;
                                    } elseif ($first_name == '') {
                                        $first_name = $val;
                                        break;
                                    }
                                }
                            }
                            if (!empty($first_name) && !empty($last_name)) {
                                $notify_to[] = array('first_name' => $first_name, 'last_name' => $last_name);
                                //$info .= '*' . $notify_to[count($notify_to)-1]['first_name'] . ' ' . $notify_to[count($notify_to)-1]['last_name'] . '*';
                            } else {
                                break;
                            }
                        } else {
                            break;
                        }
                    } else {
                        $flag_start_now = true;
                    }
                }
            }
            //$info .= '#';
            //$info = '';
            $ticket_id = $comment->getParentId();
            $exclude = array();
            $exclude[] = $comment->getCreatedById();
            $notified_to = '';
            $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
            mysql_select_db(DB_NAME);
            $query = "select a.user_id, b.first_name, b.last_name, b.email from healingcrystals_subscriptions a inner join healingcrystals_users b on a.user_id=b.id where a.parent_id='" . $ticket_id . "'";
            $result = mysql_query($query);
            while ($entry = mysql_fetch_assoc($result)) {
                $to_be_notified = false;
                foreach ($notify_to as $user) {
                    if ($user['first_name'] == $entry['first_name'] && $user['last_name'] == $entry['last_name']) {
                        if ($comment->getCreatedById() != $entry['user_id']) {
                            $to_be_notified = true;
                            //$info .= $entry['email'] . '|';
                            $notified_to .= $entry['first_name'] . ' ' . $entry['last_name'] . ', ';
                        }
                        break;
                    }
                }
                if (!$to_be_notified) {
                    $exclude[] = $entry['user_id'];
                }
            }
            //mysql_query("insert into testing (entry) values ('" . str_replace("'", "''", $info . $query) . "')");
            mysql_close($link);
            $created_by = $comment->getCreatedBy();
            $parent->sendToSubscribers('resources/new_comment', array('comment_body' => $comment->getFormattedBody(), 'comment_url' => $comment->getViewUrl(), 'created_by_url' => $created_by->getViewUrl(), 'created_by_name' => $created_by->getDisplayName(), 'subscribers_name' => $subscribers_name), $exclude, $parent);
        }
        // if
    }
    // if
}