/**
  * 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'));
 }
/**
 * Render comments
 * 
 * Parameters:
 * 
 * - comments - comments that needs to be rendered
 * - page - current_page
 * - total_pages - total pages
 * - counter - counter for comment #
 * - url - base URL for link assembly
 * - parent - parent object
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_object_comments($params, &$smarty)
{
    $url_params = '';
    if (is_foreachable($params)) {
        foreach ($params as $k => $v) {
            if (strpos($k, 'url_param_') !== false && $v) {
                $url_params .= '&' . substr($k, 10) . '=' . $v;
            }
            // if
        }
        // foreach
    }
    // if
    $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
    $user = array_var($params, 'user');
    if (!instance_of($user, 'User')) {
        return new InvalidParamError('object', $user, '$user is expected to be an instance of User class', true);
    }
    // if
    $page = array_var($params, 'page', 1);
    $page = (int) array_var($_GET, 'page');
    if ($page < 1) {
        $page = 1;
    }
    // if
    $counter = array_var($params, 'counter', 1);
    $counter = ($page - 1) * $object->comments_per_page + $counter;
    list($comments, $pagination) = $object->paginateComments($page, $object->comments_per_page, $user->getVisibility());
    $smarty->assign(array("_mobile_access_comments_comments" => $comments, "_mobile_access_comments_paginator" => $pagination, "_mobile_access_comments_url" => mobile_access_module_get_view_url($object), "_mobile_access_comments_url_params" => $url_params, "_mobile_access_comments_counter" => $counter, "_mobile_access_comments_show_counter" => array_var($params, 'show_counter', true)));
    return $smarty->fetch(get_template_path('_object_comments', null, MOBILE_ACCESS_MODULE));
}
/**
 * Render object assignees list
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_object_assignees($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
    $owner = $object->getResponsibleAssignee();
    if (!instance_of($owner, 'User')) {
        Assignments::deleteByObject($object);
        return lang('No one is responsible');
    }
    // if
    require_once SYSTEM_MODULE_PATH . '/helpers/function.user_link.php';
    $other_assignees = array();
    $assignees = $object->getAssignees();
    if (is_foreachable($assignees)) {
        foreach ($assignees as $assignee) {
            if ($assignee->getId() != $owner->getId()) {
                $other_assignees[] = '<a href="' . mobile_access_module_get_view_url($assignee) . '">' . clean($assignee->getName()) . '</a>';
            }
            // if
        }
        // foreach
    }
    // if
    if (count($other_assignees)) {
        return '<a href="' . mobile_access_module_get_view_url($owner) . '">' . clean($owner->getName()) . '</a> ' . lang('is responsible') . '. ' . lang('Other assignees') . ': ' . implode(', ', $other_assignees);
    } else {
        return '<a href="' . mobile_access_module_get_view_url($owner) . '">' . clean($owner->getName()) . '</a> ' . lang('is responsible') . '.';
    }
    // if
}
/**
 * Render action name and user link based on input parameters
 * 
 * - action - Action string, default is 'Posted'. It is used for lang retrival
 * - user - User who took the action. Can be registered user or anonymous user
 * - short_names - Use short user name
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_action_by($params, &$smarty)
{
    $action = clean(array_var($params, 'action', 'Posted'));
    $short_names = (bool) array_var($params, 'short_names');
    $user = array_var($params, 'user');
    if (instance_of($user, 'User')) {
        return "<span class='no_break'>" . lang($action) . "</span> " . lang('by') . " <a href='mailto:" . mobile_access_module_get_view_url($user) . "'>" . $user->getDisplayName($short_names) . "</a>";
    } elseif (instance_of($user, 'AnonymousUser')) {
        return "<span class='no_break'>" . lang($action) . "</span> " . lang('by') . " <a href='mailto:" . $user->getEmail() . "'>" . $user->getName() . "</a>";
    } else {
        return new InvalidParamError('user', $user, '$user is required attribute and it needs to be instance of User or AnonymousUser class', true);
    }
    // if
}
 /**
  * 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'));
 }
 /**
  * View the repository
  *
  */
 function view()
 {
     if ($this->active_repository->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_repository->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $this->addBreadcrumb(str_excerpt(clean($this->active_repository->getName()), 10), mobile_access_module_get_view_url($this->active_repository));
     $this->addBreadcrumb(lang('View'));
     $per_page = 20;
     $page = intval(array_var($_GET, 'page')) > 0 ? array_var($_GET, 'page') : 1;
     list($commits, $pagination) = Commits::paginateByRepository($this->active_repository, $page, $per_page);
     $commits = group_by_date($commits);
     $this->smarty->assign(array('pagination' => $pagination, 'commits' => $commits, 'pagination_url' => assemble_url('mobile_access_view_repository', array('object_id' => $this->active_repository->getId(), 'project_id' => $this->active_project->getId())), 'page_back_url' => assemble_url('mobile_access_view_project', array('project_id' => $this->active_project->getId()))));
 }
/**
 * returns View Url for provided object
 * 
 * - object - object
 * 
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_get_view_url($params, &$smarty)
{
    return mobile_access_module_get_view_url(array_var($params, 'object', null));
}
 /**
  * Render Page Version
  * 
  * @param void
  * @return null
  */
 function version()
 {
     if (!instance_of($this->active_page, 'Page')) {
         $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
     $version = PageVersions::findByPage($this->active_page, $this->request->get('version'));
     if (!instance_of($version, 'PageVersion')) {
         $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall());
     }
     // if
     $this->addBreadcrumb($this->active_page->getName(), mobile_access_module_get_view_url($this->active_page));
     $this->addBreadcrumb(lang('Version #:version', array('version' => $version->getVersion())));
     $this->smarty->assign(array('page_back_url' => mobile_access_module_get_view_url($this->active_page), 'version' => $version));
 }
 /**
  * Display user details
  */
 function user()
 {
     $user_id = $this->request->get('object_id');
     if ($user_id) {
         $current_user = Users::findById($user_id);
     }
     // if
     if (!instance_of($current_user, 'User')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     if (!in_array($current_user->getId(), $this->logged_user->visibleUserIds())) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $current_user_company = $current_user->getCompany();
     $this->smarty->assign(array("current_user" => $current_user, "current_user_company" => $current_user->getCompany(), "page_title" => $current_user->getName(), "page_back_url" => mobile_access_module_get_view_url($current_user_company)));
 }
 /**
  * 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'));
 }
 /**
  * Toggles object completed state
  * 
  */
 function toggle_completed()
 {
     $object_id = (int) $this->request->get('object_id');
     if ($object_id) {
         $object = ProjectObjects::findById($object_id);
     } else {
         $object = new ProjectObject();
     }
     // if
     if ($object->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if ($object->isCompleted()) {
         $object->open($this->logged_user);
     } else {
         $object->complete($this->logged_user);
     }
     $this->redirectToUrl(mobile_access_module_get_view_url($object));
 }
 /**
  * Add comment to object
  *
  */
 function add_comment()
 {
     $parent_id = $this->request->get('parent_id');
     $parent = ProjectObjects::findById($parent_id);
     if (!instance_of($parent, 'ProjectObject')) {
         $this->httpError(HTTP_NOT_FOUND);
     }
     // if
     if (!$parent->canComment($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $comment_data = $this->request->post('comment');
     $this->smarty->assign(array('parent' => $parent, 'comment_data' => $comment_data, 'recent_comments' => Comments::findRecentObject($parent, 5, STATE_VISIBLE, $this->logged_user->getVisibility()), 'page_back_url' => mobile_access_module_get_view_url($parent)));
     $this->addBreadcrumb(ucfirst(lang($parent->getModule())), assemble_url('mobile_access_view_' . $parent->getModule(), array('project_id' => $this->active_project->getId())));
     $this->addBreadcrumb($parent->getName(), mobile_access_module_get_view_url($parent));
     $this->addBreadcrumb('Add Comment');
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $comment = new Comment();
         $comment->setAttributes($comment_data);
         $comment->setParent($parent);
         $comment->setProjectId($this->active_project->getId());
         $comment->setState(STATE_VISIBLE);
         $comment->setVisibility($parent->getVisibility());
         $comment->setCreatedBy($this->logged_user);
         $save = $comment->save();
         if ($save && !is_error($save)) {
             db_commit();
             flash_success('Comment successfully posted');
             $this->redirectToUrl(mobile_access_module_get_view_url($comment));
         } else {
             db_rollback();
             $this->smarty->assign('errors', $save);
             $this->render();
         }
         // if
     }
     // if
 }
 /**
  * Render log for mobile devices
  *
  * @param ProjectObject $object
  * @param boolean $in_project
  * @return string
  */
 function renderMobile($object = null, $in_project = false)
 {
     if ($object === null) {
         $object = $this->getObject();
     }
     // if
     require_once SMARTY_PATH . '/plugins/modifier.date.php';
     if (instance_of($object, 'ProjectObject')) {
         $return_string .= '<a href="' . mobile_access_module_get_view_url($object) . '">' . '<span class="object_type">' . $object->getVerboseType() . '</span>' . '<span class="main_link"><span>' . str_excerpt(clean($object->getName()), 40) . '</span></span>' . '<span class="details">' . ucfirst(lang($this->action_name)) . ' ' . lang('by') . ' <strong>' . clean($this->getCreatedByName()) . '</strong><br/>' . smarty_modifier_date($this->getCreatedOn()) . '</span>' . '</a>';
     }
     return $return_string;
 }
 /**
  * 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 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'));
 }