/**
  * 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()))));
 }
 /**
  * Get all commits related to a project object
  *
  * @param integer $object_id
  * @return array
  */
 function findCommitsByObject($object)
 {
     $parent_object_ids = array();
     $parent_object_ids[] = $object->getId();
     /**
      * Try to find commits related to children objects
      */
     $task_ids = array();
     if (instance_of($object, 'Ticket')) {
         $tasks = db_execute_all("SELECT id FROM " . TABLE_PREFIX . "project_objects WHERE parent_id = " . $object->getid() . " AND `type` = 'Task'");
         if (is_foreachable($tasks)) {
             foreach ($tasks as $task) {
                 $task_ids[] = $task['id'];
             }
             // foreach
         }
         // if
     }
     // if
     $objects_ids = array_merge($parent_object_ids, $task_ids);
     $commit_project_objects = CommitProjectObjects::find(array('conditions' => array("object_id IN(" . implode(',', $objects_ids) . ")"), 'order' => 'repository_id ASC, revision DESC'));
     if (is_foreachable($commit_project_objects)) {
         $commits = array();
         $revisions = array();
         foreach ($commit_project_objects as $commit_project_object) {
             if (!in_array($commit_project_object->getRevision(), $revisions)) {
                 // prevent commits from showing more than once
                 $revisions[] = $commit_project_object->getRevision();
                 $commit = Commits::findByRevision($commit_project_object->getRevision(), Repositories::findById($commit_project_object->getRepositoryId()));
                 if (instance_of($commit, 'Commit')) {
                     $commit->repository = Repositories::findById($commit->getProjectId());
                     $commits[] = $commit;
                 }
                 // if
             }
             // if
         }
         // foreach
         return group_by_date($commits);
     } else {
         return false;
     }
     // if
 }
 /**
  * View commit history of selected repository
  *
  * @param null
  * @return void
  */
 function history()
 {
     if (!$this->active_repository->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $this->wireframe->addPageAction(lang('Browse repository'), $this->active_repository->getBrowseUrl(), null);
     if ($this->active_repository->canEdit($this->logged_user) || $this->active_repository->getCreatedById() == $this->logged_user->getId()) {
         $this->wireframe->addPageAction(lang('Update'), $this->active_repository->getUpdateUrl(), null, array('id' => 'repository_ajax_update'));
     }
     $per_page = 20;
     $page = intval(array_var($_GET, 'page')) > 0 ? array_var($_GET, 'page') : 1;
     $commits_count_params = array("parent_id = ?", $this->active_repository->getId());
     $filter_by_author = $this->request->get('filter_by_author');
     if (!is_null($filter_by_author)) {
         $commits_count_params['created_by_name'] = $filter_by_author;
     }
     // if
     list($commits, $pagination) = Commits::paginateByRepository($this->active_repository, $page, $per_page, $filter_by_author);
     if (is_foreachable($commits)) {
         foreach ($commits as $commit) {
             $commit->total_paths = count($commit->getPaths());
             $commit->setPaths($this->repository_engine->groupPaths($commit->getPaths()));
         }
         // foreach
         if (!is_null($filter_by_author)) {
             $filter_by_author = array();
             $filter_by_author['user_object'] = $commits['0']->getAuthor();
             $filter_by_author['user_name'] = $commits['0']->getCreatedbyName();
         }
         // if
     }
     // if
     $commits = group_by_date($commits, $this->logged_user);
     $this->smarty->assign(array('filter_by_author' => $filter_by_author, 'commits' => $commits, 'pagination' => $pagination, 'project' => $this->active_project, 'total_commits' => Commits::count($commits_count_params)));
 }
 /**
  * Show project overview page
  *
  * @param void
  * @return null
  */
 function index()
 {
     if ($this->active_project->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if ($this->request->isApiCall()) {
         $this->serveData($this->active_project, 'project', array('describe_leader' => true, 'describe_company' => true, 'describe_group' => true, 'describe_permissions' => true, 'describe_icon' => true));
     } else {
         //        $options = $this->active_project->getOptions($this->logged_user);
         //        if(is_foreachable($options)) {
         //          $this->wireframe->addPageAction(lang('Options'), $this->active_project->getOverviewUrl(), $options, null, 255);
         //        } // if
         $this->wireframe->addRssFeed(lang(':project project', array('project' => $this->active_project->getName())) . ' - ' . lang('Recent activities'), assemble_url('project_rss', array('project_id' => $this->active_project->getId(), 'token' => $this->logged_user->getToken(true))), FEED_RSS);
         $task_types = get_completable_project_object_types();
         $day_types = get_day_project_object_types();
         $home_sidebars = array();
         event_trigger('on_project_overview_sidebars', array(&$home_sidebars, &$this->active_project, &$this->logged_user));
         $this->smarty->assign(array('project_group' => $this->active_project->getGroup(), 'project_company' => $this->active_project->getCompany(), 'late_and_today' => ProjectObjects::findLateAndToday($this->logged_user, $this->active_project, $day_types), 'upcoming_objects' => ProjectObjects::findUpcoming($this->logged_user, $this->active_project, $day_types), 'grouped_activities' => group_by_date(ActivityLogs::findProjectActivitiesByUser($this->active_project, $this->logged_user, 20), $this->logged_user), 'home_sidebars' => $home_sidebars));
         $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
         mysql_select_db(DB_NAME);
         $query = "select count(*) as count from healingcrystals_project_objects \n\t\t\t\t where project_id='" . $this->active_project->getId() . "' and type='Milestone' and completed_on is null";
         $result = mysql_query($query);
         $info = mysql_fetch_assoc($result);
         $milestones_count = $info['count'];
         $query = "select count(*) as count from healingcrystals_project_objects \n\t\t\t\t where project_id='" . $this->active_project->getId() . "' and type='Ticket' and completed_on is null";
         $result = mysql_query($query);
         $info = mysql_fetch_assoc($result);
         $tickets_count = $info['count'];
         $query = "select count(*) as count from healingcrystals_project_objects \n\t\t\t\t where project_id='" . $this->active_project->getId() . "' and type='Page' and completed_on is null";
         $result = mysql_query($query);
         $info = mysql_fetch_assoc($result);
         $pages_count = $info['count'];
         $query = "select count(*) as count from healingcrystals_project_objects \n\t\t\t\t where project_id='" . $this->active_project->getId() . "' and type='Task' and completed_on is null";
         $result = mysql_query($query);
         $info = mysql_fetch_assoc($result);
         $tasks_count = $info['count'];
         $query = "select count(*) as count from healingcrystals_project_objects \n\t\t\t\t where project_id='" . $this->active_project->getId() . "' and type='File' and completed_on is null";
         $result = mysql_query($query);
         $info = mysql_fetch_assoc($result);
         $files_count = $info['count'];
         $query = "select count(*) as count from healingcrystals_project_objects \n\t\t\t\t where project_id='" . $this->active_project->getId() . "' and type='Discussion' and completed_on is null";
         $result = mysql_query($query);
         $info = mysql_fetch_assoc($result);
         $discussions_count = $info['count'];
         $query = "select count(*) as count from healingcrystals_project_objects \n\t\t\t\t where project_id='" . $this->active_project->getId() . "' and type='Checklist' and completed_on is null";
         $result = mysql_query($query);
         $info = mysql_fetch_assoc($result);
         $checklists_count = $info['count'];
         mysql_close($link);
         $this->smarty->assign(array('milestones_count' => $milestones_count, 'tickets_count' => $tickets_count, 'pages_count' => $pages_count, 'tasks_count' => $tasks_count, 'files_count' => $files_count, 'discussions_count' => $discussions_count, 'checklists_count' => $checklists_count));
     }
     // if
 }
 /**
  * Render pages associtate with a specific project, pages homepage
  *
  * @param void
  * @return null
  */
 function index()
 {
     if ($this->request->isApiCall()) {
         if ($this->active_category->isLoaded()) {
             $this->serveData(Pages::findByCategory($this->active_category, STATE_VISIBLE, $this->logged_user->getVisibility()), 'pages');
         } else {
             $this->serveData(Categories::findByModuleSection($this->active_project, PAGES_MODULE, 'pages'), 'categories');
         }
         // if
     } else {
         //BOF:mod 20121108
         $category_is_selected = false;
         $selected_category_id = $_GET['category_id'];
         if ($selected_category_id === '0' || $selected_category_id > 0) {
             $category_is_selected = true;
         }
         //EOF:mod 20121108
         $per_page = 30;
         $page = (int) $this->request->get('page');
         if ($page < 1) {
             $page = 1;
         }
         // if
         //BOF:mod 20121108
         /*
         //EOF:mod 20121108
                 if($this->active_category->isLoaded()) {
                 //BOF:mod 20121108
         */
         if ($category_is_selected) {
             //EOF:mod 20121108
             $this->setTemplate(array('module' => PAGES_MODULE, 'controller' => 'pages', 'template' => 'category'));
             //BOF:mod 20121108
             /*
             //EOF:mod 20121108
                       $this->wireframe->addPageAction(lang('Reorder Pages'), assemble_url('project_pages_reorder', array('project_id' => $this->active_project->getId(), 'category_id' => $this->active_category->getId())), null, array('id' => 'reorder_pages_button'));
                       
                       $this->smarty->assign('pages', Pages::findByCategory($this->active_category, STATE_VISIBLE, $this->logged_user->getVisibility()));
             //BOF:mod 20121108
             */
             $this->wireframe->addPageAction(lang('Reorder Pages'), assemble_url('project_pages_reorder', array('project_id' => $this->active_project->getId())), null, array('id' => 'reorder_pages_button'));
             $this->smarty->assign('pages', Pages::findByCategoryNew($this->active_project->getId(), $selected_category_id, STATE_VISIBLE, $this->logged_user->getVisibility()));
             //EOF:mod 20121108
         } else {
             list($pages, $pagination) = Pages::paginateByProject($this->active_project, $page, $per_page, STATE_VISIBLE, $this->logged_user->getVisibility());
             $grouped_pages = group_by_date($pages, $this->logged_user, 'getUpdatedOn', true);
             $this->smarty->assign(array('grouped_pages' => $grouped_pages, 'pagination' => $pagination));
         }
         // if
         //BOF:mod 20121108
         $departments = Pages::getItemsByDepartment($this->active_project->getId(), new Discussion());
         //EOF:mod 20121108
         $this->smarty->assign(array('departments' => $departments, 'selected_category_id' => $selected_category_id, 'categories_url' => assemble_url('project_manage_milestone_categories', array('project_id' => $this->active_project->getId())), 'can_manage_categories' => $this->logged_user->isProjectLeader($this->active_project) || $this->logged_user->isProjectManager()));
     }
     // if
 }
 /**
  * Recent activities for selected user
  *
  * @param void
  * @return null
  */
 function recent_activities()
 {
     if ($this->active_user->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_user->canViewActivities($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $page = (int) $this->request->get('page');
     if ($page < 1) {
         $page = 1;
     }
     // if
     $per_page = 15;
     list($recent_activities, $pagination) = ActivityLogs::paginateActivitiesByUser($this->active_user, $page, $per_page);
     $this->smarty->assign(array('recent_activities' => group_by_date($recent_activities), 'pagination' => $pagination));
 }
 /**
  * Show recent activities page
  *
  * @param void
  * @return null
  */
 function recent_activities()
 {
     $this->skip_layout = $this->request->isAsyncCall();
     $this->smarty->assign(array('grouped_activities' => group_by_date(ActivityLogs::findActiveProjectsActivitiesByUser($this->logged_user, 20), $this->logged_user)));
 }
 /**
  * Page which displays mailbox activity history
  * 
  * @param void
  * @return void
  */
 function view_mailbox()
 {
     if ($this->active_mailbox->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     use_model('incoming_mail_activity_logs', INCOMING_MAIL_MODULE);
     $this->wireframe->addBreadCrumb(clean($this->active_mailbox->getDisplayName()), $this->active_mailbox->getViewUrl());
     $per_page = 50;
     // mailbox activity per page
     $page = (int) $this->request->get('page');
     if ($page < 1) {
         $page = 1;
     }
     // if
     $only_problematic = (bool) array_var($_GET, 'only_problematic', false);
     if ($only_problematic) {
         list($activity_history, $pagination) = IncomingMailActivityLogs::paginateConflictsByMailbox($this->active_mailbox, $page, $per_page);
     } else {
         list($activity_history, $pagination) = IncomingMailActivityLogs::paginateByMailbox($this->active_mailbox, $page, $per_page);
     }
     // if
     $activity_history = group_by_date($activity_history);
     $this->smarty->assign(array('activity_history' => $activity_history, 'pagination' => $pagination, 'only_problematic' => $only_problematic));
 }