/**
  * 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));
}
Exemplo n.º 4
0
/**
 * Handle on shutdown
 *
 * @param void
 * @return null
 */
function system_handle_on_shutdown()
{
    ProjectObjectViews::save();
    // Lets kill a transaction if we have something open
    $database =& DBConnection::instance();
    if (instance_of($database, 'DBConnection') && $database->transaction_level > 0) {
        $database->rollback();
    }
    // if
    if (DEBUG >= DEBUG_DEVELOPMENT) {
        $logger =& Logger::instance();
        $logger->logToFile(ENVIRONMENT_PATH . '/logs/' . date('Y-m-d') . '.txt');
    }
    // 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'));
 }
/**
 * 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));
}
/**
 * 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));
}
/**
 * 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));
}
 /**
  * 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 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'));
 }
 /**
  * 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
 }
 /**
  * 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
 }
 /**
  * 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
 }
/**
 * 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));
    //}
}
 /**
  * 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'));
 }
 /**
  * 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
 }
 /**
  * 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
 }
 /**
  * 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
 }
 /**
  * Return number of new objects in $project_ids since $since
  *
  * @param DateTimeValue $since
  * @param array $project_ids
  * @param array $exclude
  * @param integer $min_state
  * @param integer $min_visibility
  * @return integer
  */
 function countNew($user)
 {
     $type_filter = ProjectUsers::getVisibleTypesFilter($user, array(PROJECT_STATUS_ACTIVE, PROJECT_STATUS_PAUSED, PROJECT_STATUS_CANCELED, PROJECT_STATUS_COMPLETED));
     if ($type_filter) {
         $exclude = ProjectObjectViews::findViewedObjectIds($user);
         $last_visit_on = $user->getLastVisitOn();
         if (!instance_of($last_visit_on, 'DateTimeValue')) {
             $last_visit_on = new DateTimeValue(filemtime(ENVIRONMENT_PATH . '/config/config.php'));
         }
         // if
         $month_ago = new DateTimeValue('-30 days');
         // Last visit or last month
         $since = $last_visit_on->getTimestamp() > $month_ago->getTimestamp() ? $last_visit_on : $month_ago;
         if ($exclude) {
             return ProjectObjects::count(array($type_filter . ' AND state >= ? AND visibility >= ? AND created_on >= ? AND created_by_id != ? AND id NOT IN (?)', STATE_VISIBLE, $user->getVisibility(), $since, $user->getId(), $exclude));
         } else {
             return ProjectObjects::count(array($type_filter . ' AND state >= ? AND visibility >= ? AND created_on >= ? AND created_by_id != ? ', STATE_VISIBLE, $user->getVisibility(), $since, $user->getid()));
         }
         // if
     } else {
         return 0;
     }
     // if
 }
Exemplo n.º 22
0
/**
 * Do daily taks
 *
 * @param void
 * @return null
 */
function system_handle_on_daily()
{
    ProjectObjectViews::cleanUp();
    $priorities_images = array(PRIORITY_URGENT => 'assets/images/icons/priority/urgent.png', PRIORITY_HIGHEST => 'assets/images/icons/priority/highest.gif', PRIORITY_HIGH => 'assets/images/icons/priority/high.gif', PRIORITY_NORMAL => 'assets/images/icons/priority/normal.gif', PRIORITY_LOW => 'assets/images/icons/priority/low.gif', PRIORITY_LOWEST => 'assets/images/icons/priority/lowest.gif', PRIORITY_HOLD => 'assets/images/icons/priority/hold.png', '-99' => 'assets/images/icons/priority/unknown.png');
    $pages = array();
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME);
    $sql = "select id, name from healingcrystals_project_objects where project_id='" . TASK_LIST_PROJECT_ID . "' and type='Page'";
    $result = mysql_query($sql, $link);
    while ($entry = mysql_fetch_assoc($result)) {
        list($name, ) = explode('-', $entry['name']);
        $name = trim($name);
        $pages[$name] = $entry['id'];
    }
    $current_time = time();
    $users = Users::findAll();
    foreach ($users as $user) {
        $flag = 1;
        $message = '';
        $name = $user->getName();
        if (array_key_exists($name, $pages)) {
            $page = new Page($pages[$name]);
            if ($page) {
                $sql = "select id from healingcrystals_project_objects where parent_id='" . $pages[$name] . "' and parent_type='Page' and type='Task' and completed_on is null and priority is null and created_on>='" . date('Y-m-d H:i:s', $current_time - 1 * 24 * 60 * 60) . "' order by created_on";
                $result = mysql_query($sql, $link);
                if (mysql_num_rows($result)) {
                    $show_task_list = true;
                } else {
                    $show_task_list = false;
                }
                if (date('N') == '1' || $show_task_list) {
                    $message .= '<style>
		.odd {background-color:#ffffff;}
		.even{background-color:#eeeeee;}
	</style>
	<table>
		<tr>
			<td colspan="3">Task List: ' . $name . '</td>
		</tr>
		<tr>
			<td align="center">Priority</td>
			<td>Task</td>
			<td>&nbsp;</td>
		</tr>';
                    $tasks = Tasks::findOpenByObject($page);
                    foreach ($tasks as $task) {
                        $message .= '
		<tr class="' . ($flag % 2 === 1 ? 'odd' : 'even') . '">
			<td valign="top" align="center"><img  src="http://projects.ffbh.org/public/' . $priorities_images[$task->getPriority()] . '"/></td>
			<td valign="top">' . $task->getName() . '</td>
			<td valign="top"><a href="' . $task->getViewUrl() . '">View</a></td>
		</tr>';
                        $flag++;
                    }
                    $message .= '
	</table>';
                    $subject = 'projects: healingcrystals.com Task list';
                    $headers = 'MIME-Version: 1.0' . "\r\n";
                    $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                    $headers .= 'From: FFBH Reminder <*****@*****.**>' . "\r\n";
                    mail($user->getEmail(), $subject, $message, $headers);
                }
            }
        }
    }
    $sql = "select po.id, cast(if( pom.recurring_period_type='D', DATE_ADD(po.due_on, interval pom.recurring_period day), if(pom.recurring_period_type='W', DATE_ADD(po.due_on, interval pom.recurring_period week), if(pom.recurring_period_type='M', DATE_ADD(po.due_on, interval pom.recurring_period month), null ) ) ) as Date) as next_due_date, cast(DATE_ADD(now(), interval 0 day) as Date) as cur_date, cast(if(isnull(pom.email_reminder_unit), null, if( pom.email_reminder_unit='D', DATE_ADD(po.due_on, interval pom.email_reminder_period day), if(pom.email_reminder_unit='W', DATE_ADD(po.due_on, interval pom.email_reminder_period week), if(pom.email_reminder_unit='M', DATE_ADD(po.due_on, interval pom.email_reminder_period month), null ) ) )\t) as Date) as reminder_date from healingcrystals_project_objects po inner join  healingcrystals_project_object_misc pom on po.id=pom.object_id where po.type='Task' and po.due_on is not null and po.due_on<=now() and po.completed_on is null and pom.recurring_period_condition='after_due_date' and if(pom.recurring_end_date is not null and pom.recurring_end_date!='0000-00-00', if(pom.recurring_end_date>=now(), 1, 0), 1)=1 having next_due_date=cur_date";
    $result = mysql_query($sql);
    while ($entry = mysql_fetch_assoc($result)) {
        $task = new Task($entry['id']);
        $action = $task->complete(new AnonymousUser('auto', '*****@*****.**'));
        if (!empty($entry['reminder_date']) && $entry['cur_date'] == $entry['reminder_date']) {
            $sql02 = "select id from " . TABLE_PREFIX . "project_objects where type='Task' and project_id='" . $task->getProjectId() . "' and milestone_id='" . $task->getMilestoneId() . "' and parent_id='" . $task->getParentId() . "' order by id desc limit 0, 1";
            $result02 = mysql_query($sql02);
            if (mysql_num_rows($result02)) {
                $info = mysql_fetch_assoc($result02);
                $recurring_task = new Task($info['id']);
                $parent = $recurring_task->getParent();
                $project = $recurring_task->getProject();
                $assignees = $recurring_task->getAssignees();
                $priorities = array(PRIORITY_HIGHEST => lang('Highest'), PRIORITY_HIGH => lang('High'), PRIORITY_NORMAL => lang('Normal'), PRIORITY_LOW => lang('Low'), PRIORITY_LOWEST => lang('Lowest'), PRIORITY_ONGOING => lang('Ongoing'), PRIORITY_HOLD => lang('Hold'));
                $due_date = $task->getDueOn();
                $due_date = date('m/d/Y', strtotime($due_date));
                $reminder_date = date('m/d/Y', strtotime($entry['reminder_date']));
                foreach ($assignees as $assignee) {
                    $assignees_string .= $assignee->getDisplayName() . ', ';
                }
                if (!empty($assignees_string)) {
                    $assignees_string = substr($assignees_string, 0, -2);
                } else {
                    $assignees_string = '--';
                }
                $reminders_sent = array();
                foreach ($assignees as $user) {
                    //if ($user->getEmail()=='*****@*****.**'){
                    $reminder = new Reminder();
                    $reminder->setAttributes(array('user_id' => $user->getId(), 'object_id' => $recurring_task->getId(), 'comment' => $comment));
                    $save = $reminder->save();
                    if ($save && !is_error($save)) {
                        $reminders_sent[] = $user->getDisplayName();
                        ApplicationMailer::send($user, 'system/reminder', array('reminded_by_name' => 'AutoReminder', 'reminded_by_url' => '', 'object_name' => $recurring_task->getName(), 'object_url' => $recurring_task->getViewUrl(), 'object_type' => strtolower($recurring_task->getType()), 'comment_body' => $comment, 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'ticket_name' => $parent->getName(), 'ticket_url' => $parent->getViewUrl(), 'object_priority' => $priorities[(string) $recurring_task->getPriority()], 'object_due_date' => $due_date, 'object_reminder_date_n_time' => $reminder_date, 'object_assignees' => $assignees_string, 'task_mark_complete_url' => $recurring_task->getCompleteUrl() . '&auto=1', 'display_status_for_complete_url' => $recurring_task->is_action_request_task() ? '' : 'none'), $recurring_task);
                    }
                    //}
                }
            }
        }
    }
    mysql_close($link);
}