/**
  * View the checklist
  *
  */
 function view()
 {
     if ($this->active_checklist->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_checklist->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     ProjectObjectViews::log($this->active_checklist, $this->logged_user);
     $this->addBreadcrumb(str_excerpt(clean($this->active_checklist->getName()), 10), mobile_access_module_get_view_url($this->active_checklist));
     $this->addBreadcrumb(lang('View'));
 }
/**
 * List object comments
 * 
 * Parameters:
 * 
 * - object - Parent object. It needs to be an instance of ProjectObject class
 * - comments - List of comments. It is optional. If it is missing comments 
 *   will be loaded by calling getCommetns() method of parent object
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_comments_all($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $logged_user = $smarty->get_template_vars('logged_user');
    if (!instance_of($logged_user, 'User')) {
        return '';
    }
    // if
    $visiblity = $logged_user->getVisibility();
    //    if ($object->canView($logged_user) && $object->getVisibility() == VISIBILITY_PRIVATE) {
    if ($object->canView($logged_user)) {
        $visiblity = VISIBILITY_PRIVATE;
    }
    $comments = $object->getComments($visiblity);
    if (is_foreachable($comments)) {
        foreach ($comments as $comment) {
            ProjectObjectViews::log($comment, $logged_user);
            //BOF:task_1260
            $comment->set_action_request_n_fyi_flag($logged_user);
            //EOF:task_1260
        }
        // foreach
    }
    // if
    $count_from = 0;
    $smarty->assign(array('_object_comments_object' => $object, '_object_comments_count_from' => $count_from, '_object_comments_comments' => $comments, '_total_comments' => sizeof($comments)));
    return $smarty->fetch(get_template_path('_object_comments_all', 'comments', RESOURCES_MODULE));
}
/**
 * Render object tasks section
 * 
 * Parameters:
 * 
 * - object - Selected project object
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_tasks($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $open_tasks = $object->getOpenTasks();
    if (is_foreachable($open_tasks)) {
        foreach ($open_tasks as $open_task) {
            ProjectObjectViews::log($open_task, $smarty->get_template_vars('logged_user'));
        }
        // foreach
    }
    // if
    $completed_tasks = $object->getCompletedTasks(COMPLETED_TASKS_PER_OBJECT);
    if (is_foreachable($completed_tasks)) {
        foreach ($completed_tasks as $completed_task) {
            ProjectObjectViews::log($completed_task, $smarty->get_template_vars('logged_user'));
        }
        // foreach
    }
    // if
    $smarty->assign(array('_object_tasks_object' => $object, '_object_tasks_open' => $open_tasks, '_object_tasks_can_reorder' => (int) $object->canEdit($smarty->get_template_vars('logged_user')), '_object_tasks_completed' => $completed_tasks, '_object_tasks_completed_remaining' => $object->countCompletedTasks() - COMPLETED_TASKS_PER_OBJECT, '_object_tasks_skip_wrapper' => array_var($params, 'skip_wrapper', false), '_object_tasks_skip_head' => array_var($params, 'skip_head', false), '_object_tasks_force_show' => array_var($params, 'force_show', true)));
    return $smarty->fetch(get_template_path('_object_tasks', 'tasks', RESOURCES_MODULE));
}
 /**
  * View the ticket
  *
  */
 function view()
 {
     if ($this->active_ticket->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_ticket->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     ProjectObjectViews::log($this->active_ticket, $this->logged_user);
     $this->smarty->assign(array('page_back_url' => assemble_url('mobile_access_view_tickets', array('project_id' => $this->active_project->getId()))));
     $this->addBreadcrumb(str_excerpt(clean($this->active_ticket->getName()), 10), mobile_access_module_get_view_url($this->active_ticket));
     $this->addBreadcrumb(lang('View'));
 }
/**
 * Render file revisions resource block
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_file_revisions($params, &$smarty)
{
    $file = array_var($params, 'file');
    if (!instance_of($file, 'File')) {
        return new InvalidParamError('file', $file, '$file is expected to be an instance of File class', true);
    }
    // if
    $revisions = $file->getRevisions();
    if (is_foreachable($revisions)) {
        foreach ($revisions as $revision) {
            ProjectObjectViews::log($revision, $smarty->get_template_vars('logged_user'));
        }
        // foreach
    }
    // if
    $smarty->assign(array('_file' => $file, '_file_revisions' => $revisions, '_file_revisions_count' => is_array($revisions) ? count($revisions) : 1));
    return $smarty->fetch(get_template_path('_file_revisions', 'files', FILES_MODULE));
}
/**
 * Render object attachments
 * 
 * Parameters:
 * 
 * - object - object which has attachments
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_object_attachments($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $logged_user = $smarty->get_template_vars('logged_user');
    if (!instance_of($logged_user, 'User')) {
        return '';
    }
    // if
    $attachments = $object->getAttachments();
    if (is_foreachable($attachments)) {
        foreach ($attachments as $attachment) {
            ProjectObjectViews::log($attachment, $logged_user);
        }
        // foreach
    }
    // if
    $smarty->assign(array('_mobile_access_object_attachments_object' => $object, '_mobile_access_object_attachments' => $attachments));
    return $smarty->fetch(get_template_path('_object_attachments', null, MOBILE_ACCESS_MODULE));
}
/**
 * List object attachments
 * 
 * Parameters:
 * 
 * - object - selected object
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_attachments_all($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $logged_user = $smarty->get_template_vars('logged_user');
    if (!instance_of($logged_user, 'User')) {
        return '';
    }
    // if
    $attachments = $object->getAttachments();
    if (is_foreachable($attachments)) {
        foreach ($attachments as $attachment) {
            ProjectObjectViews::log($attachment, $logged_user);
        }
        // foreach
    }
    // if
    $smarty->assign(array('_object_attachments_object' => $object, '_object_attachments' => $attachments, '_object_attachments_show_header' => array_var($params, 'show_header', true), '_object_attachments_brief' => array_var($params, 'brief', false), '_object_attachments_show_empty' => array_var($params, 'show_empty', false), '_total_attachments' => sizeof($attachments)));
    return $smarty->fetch(get_template_path('_object_attachments_all', 'attachments', RESOURCES_MODULE));
}
 /**
  * View the discussion
  *
  */
 function view()
 {
     if ($this->active_milestone->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_milestone->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     ProjectObjectViews::log($this->active_milestone, $this->logged_user);
     $total_objects = 0;
     $objects = $this->active_milestone->getObjects($this->logged_user);
     if (is_foreachable($objects)) {
         foreach ($objects as $objects_by_module) {
             $total_objects += count($objects_by_module);
         }
         // foreach
     }
     // if
     $this->smarty->assign(array('objects' => $objects, 'total_objects' => $total_objects, 'page_back_url' => assemble_url('mobile_access_view_milestones', array('project_id' => $this->active_project->getId()))));
     $this->addBreadcrumb(str_excerpt(clean($this->active_milestone->getName()), 10), mobile_access_module_get_view_url($this->active_milestone));
     $this->addBreadcrumb(lang('View'));
 }
 /**
  * View specific page
  *
  * @param void
  * @return null
  */
 function view()
 {
     //BOF:mod 20120814
     $redirect_to_page_id = '';
     switch ($this->active_page->getId()) {
         case '22836':
             $redirect_to_page_id = '26019';
             break;
         case '21394':
             $redirect_to_page_id = '26136';
             break;
         case '21400':
             $redirect_to_page_id = '26137';
             break;
         case '21401':
             $redirect_to_page_id = '26138';
             break;
         case '24845':
             $redirect_to_page_id = '26139';
             break;
         case '24859':
             $redirect_to_page_id = '26140';
             break;
         case '24867':
             $redirect_to_page_id = '26141';
             break;
         case '25498':
             $redirect_to_page_id = '26142';
             break;
     }
     if (!empty($redirect_to_page_id)) {
         $this->redirectToUrl(assemble_url('project_page', array('project_id' => TASK_LIST_PROJECT_ID, 'page_id' => $redirect_to_page_id)));
     }
     //EOF:mod 20120814
     if ($this->active_page->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall());
     }
     // if
     if (!$this->active_page->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall());
     }
     // if
     if ($this->request->isApiCall()) {
         $this->serveData($this->active_page, 'page', array('describe_comments' => true, 'describe_tasks' => true, 'describe_attachments' => true, 'describe_subpages' => true, 'describe_revisions' => true));
     } else {
         ProjectObjectViews::log($this->active_page, $this->logged_user);
         $page = (int) $this->request->get('page');
         if ($page < 1) {
             $page = 1;
         }
         // if
         $show_all = $this->request->get('show_all');
         if (!empty($show_all) && $show_all == '1' && !isset($_GET['comment_id'])) {
             $comments = null;
             $pagination = null;
         } else {
             $show_all = '';
             list($comments, $pagination) = $this->active_page->paginateComments($page, $this->active_page->comments_per_page, $this->logged_user->getVisibility());
         }
         $comments_only_mode = $this->request->get('comments_only_mode');
         if ($comments_only_mode) {
             $this->smarty->assign(array('_object_comments_comments' => $comments, 'pagination' => $pagination, '_counter' => ($page - 1) * $this->active_page->comments_per_page));
             echo $this->smarty->fetch(get_template_path('_object_comments_ajax', 'comments', RESOURCES_MODULE));
             exit;
         }
         $scroll_to_comment = $this->request->get('comment_id');
         /*if (!empty($scroll_to_comment)){
         			for($i=0; $i<count($comments); $i++){
         				if ($comments[$i]->getId()==$scroll_to_comment){
         					$scroll_to_comment = '';
         					break;
         				}
         			}
         		}*/
         $dID = $_GET['dID'];
         if (!empty($dID)) {
             $this->active_page->changeDepartmentTo($dID);
         }
         $pID = $_GET['pID'];
         if (!empty($pID)) {
             $this->active_page->setMilestoneId($pID);
             $this->active_page->save();
             $this->active_page->changeDepartmentTo(ProjectObject::getDepartmentId($pID));
         }
         $this->smarty->assign(array('parent' => $this->active_page->getParent(), 'subpages' => $this->active_page->getSubpages($this->logged_user->getVisibility()), 'versions' => $this->active_page->getVersions(), 'comments' => $comments, 'pagination' => $pagination, 'subscribers' => $this->active_page->getSubscribers(), 'current_user_id' => $this->logged_user->getId(), 'object_id' => $this->active_page->getId(), 'scroll_to_comment' => $scroll_to_comment, 'show_all' => $show_all));
     }
     // if
 }
 /**
  * Show single milestone
  *
  * @param void
  * @return null
  */
 function view()
 {
     $show_archived_pages = '0';
     $show_completed_tkts = '0';
     if ($this->active_milestone->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_milestone->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     ProjectObjectViews::log($this->active_milestone, $this->logged_user);
     if ($this->request->isApiCall()) {
         $this->serveData($this->active_milestone, 'milestone', array('describe_assignees' => true));
     } else {
         $page = (int) $this->request->get('page');
         if ($page < 1) {
             $page = 1;
         }
         // if
         $show_all = $this->request->get('show_all');
         if (!empty($show_all) && $show_all == '1' && !isset($_GET['comment_id'])) {
             $comments = null;
             $pagination = null;
         } else {
             $show_all = '';
             list($comments, $pagination) = $this->active_milestone->paginateComments($page, $this->active_milestone->comments_per_page, $this->logged_user->getVisibility());
         }
         $comments_only_mode = $this->request->get('comments_only_mode');
         if ($comments_only_mode) {
             $this->smarty->assign(array('_object_comments_comments' => $comments, 'pagination' => $pagination, '_counter' => ($page - 1) * $this->active_milestone->comments_per_page));
             echo $this->smarty->fetch(get_template_path('_object_comments_ajax', 'comments', RESOURCES_MODULE));
             exit;
         }
         $scroll_to_comment = $this->request->get('comment_id');
         /*if (!empty($scroll_to_comment)){
         			for($i=0; $i<count($comments); $i++){
         				if ($comments[$i]->getId()==$scroll_to_comment){
         					$scroll_to_comment = '';
         					break;
         				}
         			}
         		}*/
         if (isset($_GET['archived_pages'])) {
             $show_archived_pages = $_GET['archived_pages'];
         }
         if (isset($_GET['completed_tkts'])) {
             $show_completed_tkts = $_GET['completed_tkts'];
         }
         $total_objects = 0;
         $objects = $this->active_milestone->getObjects($this->logged_user);
         if (is_foreachable($objects)) {
             foreach ($objects as $objects_by_module) {
                 $total_objects += count($objects_by_module);
             }
             // foreach
         }
         // if
         // ---------------------------------------------------
         //  Prepare add suboject links
         // ---------------------------------------------------
         $links_code = '';
         $links = array();
         event_trigger('on_milestone_add_links', array($this->active_milestone, $this->logged_user, &$links));
         if (is_foreachable($links)) {
             $total_links = count($links);
             $counter = 1;
             foreach ($links as $k => $v) {
                 $links_code .= open_html_tag('a', array('href' => $v)) . $k . '</a>';
                 if ($counter < $total_links - 1) {
                     $links_code .= ', ';
                 } elseif ($counter == $total_links - 1) {
                     $links_code .= ' ' . lang('or') . ' ';
                 }
                 // if
                 $counter++;
             }
             // foreach
         }
         // if
         $dID = $_GET['dID'];
         if (!empty($dID)) {
             $this->active_milestone->changeDepartmentTo($dID, array('Page'));
         }
         $this->smarty->assign(array('total_objects' => $total_objects, 'milestone_objects' => $objects, 'milestone_add_links_code' => $links_code, 'subscribers' => $this->active_milestone->getSubscribers(), 'current_user_id' => $this->logged_user->getId(), 'show_archived_pages' => $show_archived_pages, 'show_completed_tkts' => $show_completed_tkts, 'object_id' => $this->active_milestone->getId(), 'comments' => $comments, 'pagination' => $pagination, 'counter' => ($page - 1) * $this->active_milestone->comments_per_page, 'scroll_to_comment' => $scroll_to_comment, 'show_all' => $show_all));
     }
     // if
 }
/**
 * List object comments
 * 
 * Parameters:
 * 
 * - object - Parent object. It needs to be an instance of ProjectObject class
 * - comments - List of comments. It is optional. If it is missing comments 
 *   will be loaded by calling getCommetns() method of parent object
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_comments($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $logged_user = $smarty->get_template_vars('logged_user');
    if (!instance_of($logged_user, 'User')) {
        return '';
    }
    // if
    //Ticket ID #362 - modify Private button (SA) 15March2012 BOF
    $visiblity = $logged_user->getVisibility();
    //    if ($object->canView($logged_user) && $object->getVisibility() == VISIBILITY_PRIVATE) {
    if ($object->canView($logged_user)) {
        $visiblity = VISIBILITY_PRIVATE;
    }
    //19 March2012 (SA) Ticket #760: fix broken permalinks BOF
    /*if ($_GET['show_all'] == '1') {
          $comments = $object->getComments($visiblity);
          if (is_foreachable($comments)) {
              foreach ($comments as $comment) {
                  ProjectObjectViews::log($comment, $logged_user);
                  $comment->set_action_request_n_fyi_flag($logged_user);
              } // foreach
          } // if    
          $count_from = 0;
          $smarty->assign(array(
              '_object_comments_object' => $object,
              '_object_comments_count_from' => $count_from,
              '_object_comments_comments' => $comments,
              '_total_comments' => sizeof($comments),
              '_object_comments_show_header' => array_var($params, 'show_header', true),
               '_object_comments_show_form' => array_var($params, 'show_form', true),
              '_counter' =>sizeof($comments)+1,
          ));
          return $smarty->fetch(get_template_path('_object_comments', 'comments', RESOURCES_MODULE));
      } else {*/
    $comments = isset($params['comments']) ? $params['comments'] : $object->getComments($visiblity);
    //Ticket ID #362 - modify Private button (SA) 15March2012 EOF
    if (is_foreachable($comments)) {
        foreach ($comments as $comment) {
            ProjectObjectViews::log($comment, $logged_user);
            //BOF:task_1260
            $comment->set_action_request_n_fyi_flag($logged_user);
            //EOF:task_1260
        }
        // foreach
    }
    // if
    $count_from = 0;
    if (isset($params['count_from'])) {
        $count_from = (int) $params['count_from'];
    }
    // if
    $object->refreshCommentsCount();
    $total_comments = $object->getCommentsCount();
    if (empty($total_comments)) {
        $total_comments = Comments::countByObject($object);
    }
    $smarty->assign(array('_object_comments_object' => $object, '_object_comments_count_from' => $count_from, '_object_comments_comments' => $comments, '_object_comments_show_header' => array_var($params, 'show_header', true), '_object_comments_show_form' => array_var($params, 'show_form', true), '_object_comments_next_page' => array_var($params, 'next_page', ''), '_total_comments' => $total_comments, '_counter' => '21', 'current_page' => array_var($params, 'current_page', '1'), 'last_page' => array_var($params, 'last_page', ''), 'view_url' => array_var($params, 'view_url', ''), 'scroll_to_comment' => array_var($params, 'scroll_to_comment', '')));
    return $smarty->fetch(get_template_path('_object_comments', 'comments', RESOURCES_MODULE));
    //}
}
 /**
  * Commit info
  *
  * @param null
  * @return void
  */
 function commit()
 {
     if (!$this->active_repository->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     if (!instance_of($this->active_commit, 'Commit')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $this->wireframe->addPageAction(lang('Revision history'), $this->active_repository->getHistoryUrl());
     $this->wireframe->addPageAction(lang('Browse repository'), $this->active_repository->getBrowseUrl());
     $grouped_paths = RepositoryEngine::groupPaths($this->active_commit->getPaths());
     ksort($grouped_paths);
     $diff = $this->active_commit->getDiff();
     if (!is_array($diff)) {
         $diff = $this->repository_engine->getCommitDiff($this->active_revision, $this->active_file);
         if (is_array($diff)) {
             $this->active_commit->setDiff($diff);
             $this->active_commit->setCreatedBy(new AnonymousUser($this->active_commit->getCreatedByName(), '*****@*****.**'));
             $save = $this->active_commit->save();
         } else {
             flash_error("Unable to retrieve diff information for selected commit");
             $this->redirectToReferer(source_module_url($this->active_project));
         }
         // if
     }
     // if
     $parsed = $this->repository_engine->parseDiff($diff);
     if (is_foreachable($parsed)) {
         for ($x = 0; $x < count($parsed); $x++) {
             $filename = substr($parsed[$x]['file'], 0, 1) == '/' ? substr($parsed[$x]['file'], 1) : '/' . $parsed[$x]['file'];
             if (!in_array($filename, $grouped_paths[SOURCE_MODULE_STATE_MODIFIED])) {
                 unset($parsed[$x]);
             }
             // if
         }
         // for
     }
     // if
     $parsed = array_values($parsed);
     ProjectObjectViews::log($this->active_commit, $this->logged_user);
     $this->smarty->assign(array('grouped_paths' => $grouped_paths, 'diff' => $parsed));
 }
 /**
  * Show file details
  *
  * @param void
  * @return null
  */
 function view()
 {
     if ($this->active_file->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_file->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $last_revision = $this->active_file->getLastRevision();
     if (!instance_of($last_revision, 'Attachment')) {
         flash_error('Invalid file - last revision was not found');
         $this->redirectToUrl(files_module_url($this->active_project));
     }
     // if
     ProjectObjectViews::log($this->active_file, $this->logged_user);
     if ($this->request->isApiCall()) {
         $this->serveData($this->active_file, 'file', array('describe_revisions' => true));
     } else {
         $page = (int) $this->request->get('page');
         if ($page < 1) {
             $page = 1;
         }
         // if
         list($comments, $pagination) = $this->active_file->paginateComments($page, $this->active_file->comments_per_page, $this->logged_user->getVisibility());
         $this->smarty->assign(array('revisions' => $this->active_file->getRevisions(), 'last_revision' => $last_revision, 'comments' => $comments, 'pagination' => $pagination, 'counter' => ($page - 1) * $this->active_file->comments_per_page));
     }
     // if
 }
 /**
  * View specific discussion
  *
  * @param void
  * @return null
  */
 function view()
 {
     if ($this->active_discussion->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_discussion->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     if ($this->active_discussion->getIsPinned()) {
         $this->wireframe->addPageMessage(lang('<strong>Pinned</strong> - This discussion is pinned'), 'pinned');
     }
     // if
     if ($this->request->isApiCall()) {
         $this->serveData($this->active_discussion, 'discussion', array('describe_comments' => true));
     } else {
         ProjectObjectViews::log($this->active_discussion, $this->logged_user);
         $parent = $this->active_discussion->getParent();
         if (instance_of($parent, 'Category')) {
             $this->active_category = $parent;
             $this->smarty->assign('active_category', $parent);
         }
         // if
         $page = (int) $this->request->get('page');
         if ($page < 1) {
             $page = 1;
         }
         // if
         list($comments, $pagination) = $this->active_discussion->paginateComments($page, $this->active_discussion->comments_per_page, $this->logged_user->getVisibility());
         $this->smarty->assign(array('category' => $this->active_discussion->getParent(), 'comments' => $comments, 'pagination' => $pagination, 'counter' => ($page - 1) * $this->active_discussion->comments_per_page, 'subscribers' => $this->active_discussion->getSubscribers(), 'object_id' => $this->active_discussion->getId()));
     }
     // if
 }
 /**
  * View the file
  *
  */
 function view()
 {
     if ($this->active_file->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_file->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $last_revision = $this->active_file->getLastRevision();
     if (!instance_of($last_revision, 'Attachment')) {
         flash_error('Invalid file - last revision was not found');
         $this->redirectToUrl(assemble_url('mobile_access'));
     }
     // if
     ProjectObjectViews::log($this->active_file, $this->logged_user);
     ProjectObjectViews::log($last_revision, $this->logged_user);
     $this->smarty->assign(array('revisions' => $this->active_file->getRevisions(), 'last_revision' => $last_revision, 'page_back_url' => assemble_url('mobile_access_view_files', array('project_id' => $this->active_project->getId()))));
     $this->addBreadcrumb(str_excerpt(clean($this->active_file->getName()), 10), mobile_access_module_get_view_url($this->active_file));
     $this->addBreadcrumb(lang('View'));
 }
 /**
  * Show timetracking module homepage
  *
  * @param void
  * @return null
  */
 function index()
 {
     if ($this->request->isApiCall()) {
         $this->serveData(TimeRecords::findByProject($this->active_project, STATE_VISIBLE, $this->logged_user->getVisibility()), 'time_records');
     } else {
         // Content for widget popup
         if ($this->request->get('for_popup_dialog')) {
             $this->_render_popup_content();
             // Classic page
         } else {
             if (instance_of($this->active_object, 'ProjectObject')) {
                 $this->wireframe->addPageMessage(lang('Time spent on <a href=":url">:name</a> :type', array('url' => $this->active_object->getViewUrl(), 'name' => $this->active_object->getName(), 'type' => $this->active_object->getVerboseType(true))), 'info');
             }
             // if
             $timetracking_data = array('record_date' => new DateValue(time() + get_user_gmt_offset($this->logged_user)), 'user_id' => $this->logged_user->getId());
             $per_page = 20;
             $page = (int) $this->request->get('page');
             if ($page < 1) {
                 $page = 1;
             }
             // if
             if (instance_of($this->active_object, 'ProjectObject')) {
                 list($timerecords, $pagination) = TimeRecords::paginateByObject($this->active_object, $page, $per_page, STATE_VISIBLE, $this->logged_user->getVisibility());
             } else {
                 list($timerecords, $pagination) = TimeRecords::paginateByProject($this->active_project, $page, $per_page, STATE_VISIBLE, $this->logged_user->getVisibility());
             }
             // if
             // Mark this objects as read
             if (is_foreachable($timerecords)) {
                 foreach ($timerecords as $timerecord) {
                     ProjectObjectViews::log($timerecord, $this->logged_user);
                 }
                 // foreach
             }
             // if
             $this->smarty->assign(array('timetracking_data' => $timetracking_data, 'timerecords' => $timerecords, 'pagination' => $pagination, 'can_add' => TimeRecord::canAdd($this->logged_user, $this->active_project)));
             js_assign('mass_update_url', assemble_url('project_time_mass_update', array('project_id' => $this->active_project->getId())));
         }
         // if
     }
     // if
 }
 /**
  * Show single ticket
  *
  * @param void
  * @return null
  */
 function view()
 {
     if ($this->active_ticket->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_ticket->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     if ($this->request->isApiCall()) {
         $this->serveData($this->active_ticket, 'ticket', array('describe_comments' => true, 'describe_tasks' => true, 'describe_attachments' => true, 'describe_assignees' => true));
     } else {
         ProjectObjectViews::log($this->active_ticket, $this->logged_user);
         $page = (int) $this->request->get('page');
         if ($page < 1) {
             $page = 1;
         }
         // if
         //$show_all = $this->request->get('show_all');
         //if (!empty($show_all) && $show_all=='1' && !isset($_GET['comment_id'])){
         //	$comments = null;
         //	$pagination = null;
         //} else {
         //	$show_all = '';
         list($comments, $pagination) = $this->active_ticket->paginateComments($page, $this->active_ticket->comments_per_page, $this->logged_user->getVisibility());
         //}
         $comments_only_mode = $this->request->get('comments_only_mode');
         if ($comments_only_mode) {
             $this->smarty->assign(array('_object_comments_comments' => $comments, 'pagination' => $pagination, '_counter' => ($page - 1) * $this->active_ticket->comments_per_page));
             echo $this->smarty->fetch(get_template_path('_object_comments_ajax', 'comments', RESOURCES_MODULE));
             exit;
         }
         $scroll_to_comment = $this->request->get('comment_id');
         /*if (!empty($scroll_to_comment)){
         			for($i=0; $i<count($comments); $i++){
         				if ($comments[$i]->getId()==$scroll_to_comment){
         					$scroll_to_comment = '';
         					break;
         				}
         			}
         		}*/
         $parent_id = $this->active_ticket->getParentId();
         $parent_category_name = 'Not Set';
         if (!empty($parent_id)) {
             $cat = new Category($parent_id);
             if (instance_of($cat, 'Category')) {
                 $parent_category_name = $cat->getName();
             }
         }
         $is_responsible = $_GET['is_responsible'];
         if (!empty($is_responsible) && is_numeric($is_responsible)) {
             $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             mysql_select_db(DB_NAME);
             $query = "select * from healingcrystals_assignments where object_id='" . $this->active_ticket->getId() . "' and user_id='" . (int) $is_responsible . "'";
             $result = mysql_query($query, $link);
             if (mysql_num_rows($result)) {
                 mysql_query("update healingcrystals_assignments set is_owner='0' where object_id='" . $this->active_ticket->getId() . "'");
                 mysql_query("update healingcrystals_assignments set is_owner='1' where object_id='" . $this->active_ticket->getId() . "' and user_id='" . (int) $is_responsible . "'");
             }
             mysql_close($link);
         }
         $priority = $_GET['priority'];
         if (is_numeric($priority)) {
             /*$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             		mysql_select_db(DB_NAME);
             		mysql_query("update healingcrystals_project_objects set priority='" . $priority . "' where id='" . $this->active_ticket->getId() . "'");
             		mysql_close($link);*/
             $this->active_ticket->setPriority($priority);
             $this->active_ticket->save();
         }
         $action_request_user = $_GET['action_request_user'];
         if (!empty($action_request_user)) {
             $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             mysql_select_db(DB_NAME);
             if ($action_request_user == -1) {
                 $query = "select * from healingcrystals_assignments_action_request where object_id='" . $this->active_ticket->getId() . "' and is_action_request='1'";
                 $result = mysql_query($query, $link);
                 if (mysql_num_rows($result)) {
                     $info = mysql_fetch_assoc($result);
                     if (!$info['is_fyi']) {
                         mysql_query("delete from healingcrystals_assignments_action_request where object_id='" . $this->active_ticket->getId() . "' and user_id='" . $info['user_id'] . "'");
                     } else {
                         mysql_query("update healingcrystals_assignments_action_request set is_action_request='0' where user_id='" . $info['user_id'] . "' and object_id='" . $this->active_ticket->getId() . "'");
                     }
                 }
             } else {
                 if ($action_request_user > 0) {
                     $query = "select * from healingcrystals_assignments_action_request where object_id='" . $this->active_ticket->getId() . "' and is_action_request='1'";
                     $result = mysql_query($query, $link);
                     if (mysql_num_rows($result)) {
                         $info = mysql_fetch_assoc($result);
                         if (!$info['is_fyi']) {
                             mysql_query("delete from healingcrystals_assignments_action_request where object_id='" . $this->active_ticket->getId() . "' and user_id='" . $info['user_id'] . "'");
                         } else {
                             mysql_query("update healingcrystals_assignments_action_request set is_action_request='0' where user_id='" . $info['user_id'] . "' and object_id='" . $this->active_ticket->getId() . "'");
                         }
                     }
                     $query = "select * from healingcrystals_assignments_action_request where object_id='" . $this->active_ticket->getId() . "' and user_id='" . $action_request_user . "'";
                     $result = mysql_query($query, $link);
                     if (mysql_num_rows($result)) {
                         mysql_query("update healingcrystals_assignments_action_request set is_action_request='1' where user_id='" . $action_request_user . "' and object_id='" . $this->active_ticket->getId() . "'");
                     } else {
                         mysql_query("insert into healingcrystals_assignments_action_request (user_id, object_id, is_action_request) values ('" . $action_request_user . "', '" . $this->active_ticket->getId() . "', '1')");
                     }
                 }
             }
             /*if ($action_request_user==-1){
             			mysql_query("delete from healingcrystals_assignments_action_request where object_id='" . $this->active_ticket->getId() . "'");
             		} elseif ((int)$action_request_user > 0) {
             			$query = "select * from healingcrystals_assignments_action_request where object_id='" . $this->active_ticket->getId() . "'";
             			$result = mysql_query($query, $link);
             			if (mysql_num_rows($result)){
             				mysql_query("update healingcrystals_assignments_action_request set user_id='" . $action_request_user . "' where object_id='" . $this->active_ticket->getId() . "'");
             			} else {
             				mysql_query("insert into healingcrystals_assignments_action_request (user_id, object_id) values ('" . $action_request_user . "', '" . $this->active_ticket->getId() . "')");
             			}
             		}*/
             mysql_close($link);
         }
         $dID = $_GET['dID'];
         if (!empty($dID)) {
             $this->active_ticket->changeDepartmentTo($dID);
         }
         $pID = $_GET['pID'];
         if (!empty($pID)) {
             //$this->active_ticket->changeMilestoneTo($pID);
             $this->active_ticket->setMilestoneId($pID);
             $this->active_ticket->save();
         }
         $this->smarty->assign(array('comments' => $comments, 'pagination' => $pagination, 'counter' => ($page - 1) * $this->active_ticket->comments_per_page, 'parent_category_name' => $parent_category_name, 'subscribers' => $this->active_ticket->getSubscribers(), 'current_user_id' => $this->logged_user->getId(), 'object_id' => $this->active_ticket->getId(), 'scroll_to_comment' => $scroll_to_comment, 'show_all' => $show_all));
     }
     // if
 }
 /**
  * View the discussion
  *
  */
 function view()
 {
     if ($this->active_discussion->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_discussion->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     ProjectObjectViews::log($this->active_discussion, $this->logged_user);
     $parent = $this->active_discussion->getParent();
     if (instance_of($parent, 'Category')) {
         $this->active_category = $parent;
         $this->smarty->assign('active_category', $parent);
     }
     // if
     $page = $this->request->get('page');
     if ($page < 1) {
         $page = 1;
     }
     // if
     $this->smarty->assign(array('page_back_url' => assemble_url('mobile_access_view_discussions', array('project_id' => $this->active_project->getId())), 'page' => $page));
     $this->addBreadcrumb(str_excerpt(clean($this->active_discussion->getName()), 10), mobile_access_module_get_view_url($this->active_discussion));
     $this->addBreadcrumb(lang('View'));
 }
 /**
  * View specific checklist
  *
  * @param void
  * @return null
  */
 function view()
 {
     if ($this->active_checklist->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_checklist->canView($this->logged_user)) {
         $this->httpError($this->logged_user);
     }
     // if
     if ($this->request->isApiCall()) {
         $this->serveData($this->active_checklist, 'checklist', array('describe_tasks' => true));
     } else {
         ProjectObjectViews::log($this->active_checklist, $this->logged_user);
     }
     // if
     $show_only_tasks = $this->request->get('show_only_tasks');
     if ($show_only_tasks) {
         $this->skip_layout = true;
         $this->smarty->assign(array('show_only_tasks' => true));
     }
     // if
     //BOF:mod 20110615
     $this->smarty->assign('object_id', $this->active_checklist->getId());
     //EOF:mod 20110615
 }