/**
 * Render single page tree cell
 *
 * @param Page $page
 * @param User $user
 * @param Smarty $smarty
 * @param string $indent
 * @return string
 */
function _mobile_access_pages_tree_render_cell($page, $user, &$smarty, $indent = '')
{
    $smarty->assign(array('_page' => $page, '_indent' => $indent));
    $result = $smarty->fetch(get_template_path('_page_tree_row', 'mobile_access_project_pages', MOBILE_ACCESS_MODULE));
    $subpages = $page->getSubpages($user->getVisibility());
    if (is_foreachable($subpages)) {
        foreach ($subpages as $subpage) {
            $result .= _mobile_access_pages_tree_render_cell($subpage, $user, $smarty, $indent . '··');
        }
        // foreach
    }
    // if
    return $result;
}
/**
 * Render single page tree cell
 *
 * @param Page $page
 * @param integer $visibility
 * @param Smarty $smarty
 * @param string $indent
 * @return string
 */
function _project_exporter_pages_tree_render_cell($page, $visibility, &$smarty, $indent = '')
{
    $smarty->assign(array('_page' => $page, '_indent' => $indent));
    $result = $smarty->fetch(get_template_path('export/_page_tree_row', 'pages', PAGES_MODULE));
    $subpages = $page->getSubpages($visibility);
    if (is_foreachable($subpages)) {
        foreach ($subpages as $subpage) {
            $result .= _project_exporter_pages_tree_render_cell($subpage, $visibility, $smarty, $indent . '··');
        }
        // foreach
    }
    // if
    return $result;
}
/**
 * Populate options array with options recursivly
 *
 * @param Page $page
 * @param integer $value
 * @param User $user
 * @param Page $skip
 * @param array $options
 * @param string $indent
 * @return null
 */
function smarty_function_select_page_populate_options($page, $value, $user, $skip, &$options, $indent = '')
{
    if (instance_of($skip, 'Page') && $skip->getId() == $page->getId()) {
        return;
    }
    // if
    $attributes = $value == $page->getId() ? array('selected' => true) : null;
    $options[] = option_tag($indent . $page->getName(), $page->getId(), $attributes);
    $subpages = $page->getSubpages($user->getVisibility());
    if (is_foreachable($subpages)) {
        foreach ($subpages as $subpage) {
            smarty_function_select_page_populate_options($subpage, $value, $user, $skip, $options, $indent . '- ');
        }
        // foreach
    }
    // if
}
 /**
  * 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
 }