/**
  * 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'));
 }
 /**
  * Constructor
  *
  * @param Request $request
  * @return CompanyProfileController
  */
 function __construct($request)
 {
     parent::__construct($request);
     $company_id = $this->request->getId('company_id');
     if ($company_id) {
         $this->active_company = Companies::findById($company_id);
     }
     // if
     if (instance_of($this->active_company, 'Company')) {
         $this->wireframe->page_actions = array();
         if (!$this->active_company->canView($this->logged_user)) {
             $this->httpError(HTTP_ERR_FORBIDDEN);
         }
         // if
         if ($this->active_company->getIsArchived() && $this->logged_user->isPeopleManager()) {
             $this->wireframe->addBreadCrumb(lang('Archive'), assemble_url('people_archive'));
         }
         // if
         $this->wireframe->addBreadCrumb($this->active_company->getName(), $this->active_company->getViewUrl());
         // Collect company tabs
         $tabs = new NamedList();
         $tabs->add('overview', array('text' => str_excerpt($this->active_company->getName(), 25), 'url' => $this->active_company->getViewUrl()));
         $tabs->add('people', array('text' => lang('People'), 'url' => $this->active_company->getViewUrl()));
         $tabs->add('projects', array('text' => lang('Projects'), 'url' => $this->active_company->getViewUrl()));
         event_trigger('on_company_tabs', array(&$tabs, &$this->logged_user, &$this->active_company));
         $this->smarty->assign(array('company_tabs' => $tabs, 'company_tab' => 'overview'));
     } else {
         $this->active_company = new Company();
     }
     // if
     $this->smarty->assign(array('active_company' => $this->active_company));
 }
 /**
  * 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()))));
 }
 /**
  * Render log details
  * 
  * @param ProjectObject $object
  * @param boolean $in_project
  * @return string
  */
 function renderBody($object = null, $in_project = false)
 {
     require_once SMARTY_PATH . '/plugins/modifier.html_excerpt.php';
     if ($object === null) {
         $object = $this->getObject();
     }
     // if
     $excerpt_body = trim(str_excerpt(smarty_modifier_html_excerpt($object->getFormattedBody(true, true)), 200));
     if ($excerpt_body) {
         $result = '<div class="comment_body">' . $excerpt_body . '</div>';
     }
     // if
     return $result;
 }
 /**
  * Render log details
  * 
  * @param ProjectObject $object
  * @param boolean $in_project
  * @return string
  */
 function renderBody($object = null, $in_project = false)
 {
     if ($object === null) {
         $object = $this->getObject();
     }
     // if
     require_once SMARTY_PATH . '/plugins/modifier.filesize.php';
     $result = '<div class="file_details">';
     $result .= '<div class="file_thumbnail"><a href="' . $object->getViewUrl() . '"><img src="' . $object->getThumbnailUrl() . '" alt="" /></a></div>';
     $result .= '<div class="file_name"><a href="' . $object->getViewUrl() . '">' . clean($object->getName()) . '</a>, ' . smarty_modifier_filesize($object->getSize()) . '</div>';
     if ($object->getBody()) {
         $result .= '<div class="file_description">' . nl2br(str_excerpt(strip_tags($object->getBody()), 250)) . '</div>';
     }
     // if
     $result .= '</div>';
     return $result;
 }
 /**
  * Construct project controller
  *
  * @param Request $request
  * @return ProjectController
  */
 function __construct($request)
 {
     parent::__construct($request);
     $this->wireframe->page_actions = array();
     // Reset page actions
     $project_id = $this->request->get('project_id');
     if ($project_id) {
         $this->active_project = Projects::findById($project_id);
     }
     // if
     if (instance_of($this->active_project, 'Project')) {
         if (!$this->logged_user->isProjectMember($this->active_project)) {
             $this->httpError(HTTP_ERR_FORBIDDEN);
         }
         // if
         if ($this->active_project->getType() == PROJECT_TYPE_SYSTEM) {
             $this->httpError(HTTP_ERR_NOT_FOUND);
         }
         // if
         if ($this->active_project->isCompleted()) {
             $this->wireframe->addBreadCrumb(lang('Archive'), assemble_url('projects_archive'));
         }
         // if
         $this->wireframe->addBreadCrumb($this->active_project->getName(), $this->active_project->getOverviewUrl());
         $tabs = new NamedList();
         $tabs->add('overview', array('text' => str_excerpt($this->active_project->getName(), 25), 'url' => $this->active_project->getOverviewUrl()));
         event_trigger('on_project_tabs', array(&$tabs, &$this->logged_user, &$this->active_project));
         $tabs->add('people', array('text' => lang('People'), 'url' => $this->active_project->getPeopleUrl()));
         $tabs->add('recent_pages', array('text' => lang('Recent Pages'), 'url' => assemble_url('recent_pages') . '&project_id=' . $this->active_project->getId()));
         /*$tabs->add('recent_pages_1', array(
             'text' => lang('Recent Pages'),
             'url' => assemble_url('project_recent_pages_1'),
           ));*/
         //BOF:mod
         /*$tabs->add('attachments', array(
             'text' => lang('Attachments'),
             'url' => assemble_url('attachments_list', array('project_id' => $this->active_project->getId())) ,
           ));*/
         //EOF:mod
         $tabs->add('reminders', array('text' => lang('Notifications'), 'url' => assemble_url('reminders_list', array('project_id' => $this->active_project->getId()))));
         $tabs->add('calendar', array('text' => lang('Calendar'), 'url' => Calendar::getProjectCalendarUrl($this->active_project)));
         js_assign('image_picker_url', assemble_url('image_picker', array('project_id' => $this->active_project->getId())));
         js_assign('active_project_id', $this->active_project->getId());
         $this->smarty->assign('page_tabs', $tabs);
         // ---------------------------------------------------
         //  Set page company and page project
         // ---------------------------------------------------
         $page_company = $this->active_project->getCompany();
         if (instance_of($page_company, 'Company')) {
             $this->wireframe->page_company = $page_company;
         }
         // if
         $this->wireframe->page_project = $this->active_project;
         // New project
     } else {
         if ($this->controller_name == 'project') {
             $this->active_project = new Project();
         } else {
             $this->httpError(HTTP_ERR_NOT_FOUND);
         }
         // if
     }
     // if
     $this->smarty->assign(array('active_project' => $this->active_project, 'page_tab' => 'overview'));
     // -----------------------------------------------------------------------
     //  Do category related voodoo if categories are enabled. Categories are
     //  not initialized if we don't have a loaded project (no project ID)
     // -----------------------------------------------------------------------
     if ($this->active_project->isLoaded() && $this->enable_categories) {
         $category_id = $this->request->get('category_id');
         if ($category_id) {
             $this->active_category = Categories::findById($category_id);
         }
         // if
         if (instance_of($this->active_category, 'Category')) {
             if ($this->active_category->getProjectId() != $this->active_project->getId()) {
                 $this->active_category = new Category();
                 // this category is not part of selected project
             }
             // if
         } else {
             $this->active_category = new Category();
         }
         // if
         $this->smarty->assign(array('active_category' => $this->active_category, 'categories_url' => Category::getSectionUrl($this->active_project, $this->getControllerName(), $this->active_module), 'add_category_url' => Category::getAddUrl($this->active_project, $this->getControllerName(), $this->active_module)));
     }
     // if
 }
 /**
  * Render log details
  * 
  * @param ProjectObject $object
  * @param boolean $in_project
  * @return string
  */
 function renderBody($object = null, $in_project = false)
 {
     require_once SMARTY_PATH . '/plugins/modifier.html_excerpt.php';
     if ($object === null) {
         $object = $this->getObject();
     }
     // if
     $result = '';
     if (instance_of($object, 'ProjectObject')) {
         $excerpt_body = trim(str_excerpt(smarty_modifier_html_excerpt($object->getFormattedBody(true, true)), 200));
         if ($excerpt_body) {
             $result .= '<div class="new_object_body"><strong>"</strong>' . $excerpt_body . '<strong>"</strong></div>';
         }
         // if
     }
     // if
     return $result;
 }
 /**
  * Reopen specific object
  *
  * @param void
  * @return null
  */
 function open()
 {
     if ($this->active_task->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_task->canChangeCompleteStatus($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $action = $this->active_task->open($this->logged_user);
         if ($action && !is_error($action)) {
             db_commit();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 if ($this->request->get('async')) {
                     $this->smarty->assign(array('_object_task' => $this->active_task));
                     print tpl_fetch(get_template_path('_task_opened_row', $this->controller_name, RESOURCES_MODULE));
                     die;
                 } else {
                     //flash_success('Task ":name" has been opened', array('name' => str_excerpt($this->active_task->getName(), 80, '...')));
                     //bof:mod
                     flash_success('Task ":name" has been opened', array('name' => str_excerpt(strip_tags($this->active_task->getName()), 80, '...')));
                     //eof:mod
                     $this->redirectToReferer($this->active_task->getViewUrl());
                 }
                 // if
             } else {
                 $this->serveData($this->active_task);
             }
             // if
         } else {
             db_rollback();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 if ($this->request->get('async')) {
                     $this->serveData($action);
                 } else {
                     flash_error('Failed to open task ":name"', array('name' => str_excerpt($this->active_task->getName(), 80, '...')));
                     $this->redirectToReferer($this->active_task->getViewUrl());
                 }
                 // if
             } else {
                 $this->httpError(HTTP_ERR_OPERATION_FAILED);
             }
             // if
         }
         // if
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // 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'));
 }
 /**
  * Rss for status updates
  * 
  * @param void
  * @return void
  */
 function rss()
 {
     require_once ANGIE_PATH . '/classes/feed/init.php';
     $archive_url = assemble_url('status_updates');
     $selected_user = $this->request->get('user_id');
     if ($selected_user) {
         if (!in_array($selected_user, $this->logged_user->visibleUserIds())) {
             $this->httpError(HTTP_ERR_FORBIDDEN);
         }
         // if
         $user = Users::findById($selected_user);
         if (!instance_of($user, 'User')) {
             $this->httpError(HTTP_ERR_NOT_FOUND);
         }
         // if
         $archive_url = assemble_url('status_updates', array('user_id' => $user->getId()));
         $latest_status_updates = StatusUpdates::findByUser($user, 20);
         $feed = new Feed(lang(":display_name's Status Updates", array('display_name' => $user->getDisplayName())), $archive_url);
     } else {
         $latest_status_updates = StatusUpdates::findVisibleForUser($this->logged_user, 20);
         $feed = new Feed(lang('Status Updates'), $archive_url);
     }
     // if
     if (is_foreachable($latest_status_updates)) {
         foreach ($latest_status_updates as $status_update) {
             $this->smarty->assign(array('status_update' => $status_update));
             $item = new FeedItem(str_excerpt($status_update->getMessage(), 50), $status_update->getViewUrl(), $this->smarty->fetch(get_template_path('feed_item', 'status', STATUS_MODULE)), $status_update->getLastUpdateOn());
             $item->setId($status_update->getId());
             $feed->addItem($item);
         }
         // foreach
     }
     // if
     print render_rss_feed($feed);
     die;
 }
 /**
  * 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;
 }
 function reminders_list()
 {
     $project_id = $_GET['project_id'];
     $flag = $_GET['flag'];
     $active_project = Projects::findById($project_id);
     $tabs = new NamedList();
     $tabs->add('overview', array('text' => str_excerpt($active_project->getName(), 25), 'url' => $active_project->getOverviewUrl()));
     event_trigger('on_project_tabs', array(&$tabs, &$this->logged_user, &$active_project));
     $tabs->add('people', array('text' => lang('People'), 'url' => $active_project->getPeopleUrl()));
     $tabs->add('recent_pages', array('text' => lang('Recent Pages'), 'url' => assemble_url('recent_pages') . '&project_id=' . $active_project->getId()));
     /*$tabs->add('attachments', array(
         'text' => lang('Attachments'),
         'url' => assemble_url('attachments_list', array('project_id' => $active_project->getId())) ,
       ));*/
     $tabs->add('reminders', array('text' => lang('Notifications'), 'url' => assemble_url('reminders_list', array('project_id' => $active_project->getId()))));
     $tabs->add('calendar', array('text' => lang('Calendar'), 'url' => Calendar::getProjectCalendarUrl($active_project)));
     js_assign('active_project_id', $active_project->getId());
     $this->smarty->assign('page_tabs', $tabs);
     $reminders = array();
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME);
     if ($flag) {
         $query = "select a.user_id, a.object_id, a.comment, a.created_by_id, a.created_on from healingcrystals_reminders a inner join healingcrystals_project_objects b on a.object_id=b.id where b.project_id='" . $active_project->getId() . "' and a.user_id='" . $this->logged_user->getId() . "' order by a.created_on desc";
     } else {
         $query = "select a.user_id, a.object_id, a.comment, a.created_by_id, a.created_on from healingcrystals_reminders a inner join healingcrystals_project_objects b on a.object_id=b.id where b.project_id='" . $active_project->getId() . "' and (a.created_by_id='" . $this->logged_user->getId() . "' or a.user_id='" . $this->logged_user->getId() . "') order by a.created_on desc";
     }
     $result = mysql_query($query, $link);
     while ($entry = mysql_fetch_assoc($result)) {
         $object_ref = new ProjectObject($entry['object_id']);
         $cur_type = $object_ref->getType();
         $type_ref = new $cur_type($entry['object_id']);
         $reminders[] = array('sent_to' => new User($entry['user_id']), 'object' => $type_ref, 'comment' => $entry['comment'], 'sent_by' => new User($entry['created_by_id']), 'sent_on' => date('d-M-Y H:i', strtotime($entry['created_on'])));
     }
     mysql_close($link);
     $this->smarty->assign('reminders', $reminders);
     $this->smarty->assign('page_tab', 'reminders');
     $this->smarty->assign('flag', $flag);
 }
 /**
  * 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'));
 }
/**
 * Return excerpt from string
 *
 * @param string $string
 * @param integer $lenght
 * @param string $etc
 * @param boolean $flat
 * @return string
 */
function smarty_modifier_excerpt($string, $lenght = 100, $etc = '...', $flat = false)
{
    $text = $flat ? strip_tags($string) : $string;
    return str_excerpt($text, $lenght, $etc);
}
 /**
  * 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'));
 }