Example #1
1
 /**
  * Returns all the users visible by the requesting user
  *
  * @param User $user
  * @return array
  */
 static function getVisibleUsers(User $user)
 {
     if ($user->isMemberOfOwnerCompany()) {
         return self::findAll(array('order' => 'concat(`display_name`, `username`)'));
     } else {
         return $user->getCompany()->getUsers();
     }
 }
 /**
  * Does user have view access
  *
  * @param void
  * @return boolean
  */
 function canView(User $user)
 {
     if ($user->isAdministrator() || $user->isMemberOfOwnerCompany()) {
         return true;
     }
     // if
     if ($user->isProjectUser($this->getProject())) {
         return true;
     }
     // if
     return false;
 }
 /**
  * Does user have view access
  *
  * @param void
  * @return boolean
  */
 function canView(User $user)
 {
     if ($user->isAdministrator() || $user->isMemberOfOwnerCompany()) {
         return true;
     }
     // if
     if ($user->getId() == $this->getEditor()) {
         return true;
     }
     // if
     return false;
 }
Example #4
0
 /**
  * Return array of task that are assigned to specific user or his company
  *
  * @param User $user
  * @return array
  */
 function getUsersTasks(User $user)
 {
     $task_lists = $this->getTaskLists();
     if (!is_array($task_lists)) {
         return false;
     }
     // if
     $task_list_ids = array();
     foreach ($task_lists as $task_list) {
         if (!$user->isMemberOfOwnerCompany() && $task_list->isPrivate()) {
             continue;
         }
         // if
         $task_list_ids[] = $task_list->getId();
     }
     // if
     return ProjectTasks::findAll(array('conditions' => array('`task_list_id` IN (?) AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?)) AND `completed_on` = ?', $task_list_ids, $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, EMPTY_DATETIME), 'order' => '`created_on`'));
     // findAll
 }
Example #5
0
 /**
  * Empty implementation of static method. Update tag permissions are check by the taggable
  * object, not tag itself
  *
  * @param User $user
  * @return boolean
  */
 function canEdit(User $user)
 {
     $project = $this->getProject();
     if (!$project instanceof Project || !$user->isProjectUser($this->getProject())) {
         return false;
     }
     // if
     $object = $this->getObject();
     if ($object instanceof ProjectDataObject) {
         if ($user->isAdministrator()) {
             return true;
         }
         // if
         if (!$user->isMemberOfOwnerCompany() && $this->isPrivate()) {
             return false;
             // private object
         }
         // if
         $edit_limit = DateTimeValueLib::now();
         $edit_limit->advance(180);
         if ($this->getCreatedById() == $user->getId() && $this->getCreatedOn()->getTimestamp() < $edit_limit->getTimestamp()) {
             return true;
             // author withing three minutes
         }
         // if
     }
     // if
     return false;
 }
Example #6
0
 /**
  * Can the user edit this page
  * 
  * @param mixed User object
  * @return (bool)
  */
 function canEdit(User $user)
 {
     //Is the user a member of the owner company, or an admin?
     return $user->isAdministrator() || $user->isMemberOfOwnerCompany();
 }
 /**
  * Check if specific user can comment this message
  *
  * @access public
  * @param void
  * @return boolean
  */
 function canAddComment(User $user)
 {
     if (!$user->isProjectUser($this->getProject())) {
         return false;
         // user is on project
     }
     // if
     if (!$user->isMemberOfOwnerCompany()) {
         if ($this->isPrivate()) {
             return false;
         }
         // if
         if ($this->getIsLocked()) {
             return false;
         }
         // if
     }
     // if
     if (!$this->canManage($user)) {
         return false;
     }
     // if
     return true;
 }
 /**
  * Render icalendar from milestones
  *
  * @param string $calendar_name
  * @param array $milestones
  * @return null
  */
 private function renderCalendar(User $user, $calendar_name, $milestones)
 {
     $calendar = new iCalendar_Calendar();
     $calendar->setPropertyValue('VERSION', '2.0');
     $calendar->setPropertyValue('PRODID', '-//Apple Computer\\, Inc//iCal 1.5//EN');
     $calendar->setPropertyValue('X-WR-CALNAME', $calendar_name);
     $calendar->setPropertyValue('X-WR-TIMEZONE', 'GMT');
     if (is_array($milestones)) {
         foreach ($milestones as $milestone) {
             if (!$user->isMemberOfOwnerCompany() && $milestone->isPrivate()) {
                 continue;
             }
             // hide private milestone
             if (!$milestone->isCompleted()) {
                 $event = new iCalendar_Event();
                 $date = $milestone->getDueDate();
                 $event->setPropertyValue('DTSTART', $date->format('Ymd'), array('VALUE' => 'DATE'));
                 $date->advance(24 * 60 * 60);
                 $event->setPropertyValue('DTEND', $date->format('Ymd'), array('VALUE' => 'DATE'));
                 $event->setPropertyValue('UID', $milestone->getId());
                 $event->setPropertyValue('SUMMARY', $milestone->getName() . ' (' . $milestone->getProject()->getName() . ')');
                 $event->setPropertyValue('DESCRIPTION', $desc = $milestone->getDescription());
                 /* pre_var_dump($desc); */
                 $calendar->addComponent($event);
             }
             // if
         }
         // foreach
     }
     // if
     header('Content-Disposition: inline; filename=calendar.ics');
     $this->renderText(iCalendar::render($calendar), true);
     die;
 }
Example #9
0
 /**
 * Return array of task that are assigned to specific user or his company
 *
 * @param User $user
 * @return array
 */
 function getUsersTickets(User $user) {
   if (!plugin_active('tickets')) return null;
   $conditions = DB::prepareString('`project_id` = ? AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR `created_by_id`= ?) AND `closed_on` = ?', array($this->getId(), $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, $user->getId(), EMPTY_DATETIME));
   if(!$user->isMemberOfOwnerCompany()) {
     $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
   } // if
   return ProjectTickets::findAll(array(
     'conditions' => $conditions,
     'order' => '`created_on`'
   )); // findAll
 } // getUsersTickets
Example #10
0
 /**
  * Empty implementation. Task list is responsible for this check
  *
  * @param User $user
  * @return boolean
  */
 function canView(User $user)
 {
     if (!$user->isProjectUser($this->getProject())) {
         return false;
         // user does not have access to project
     }
     // if
     if ($this->isPrivate() && !$user->isMemberOfOwnerCompany()) {
         return false;
         // user not member of owner company can't access private objects
     }
     // if
     return true;
 }
Example #11
0
 /**
  * Check if specific user can delete this comment
  *
  * @access public
  * @param User $user
  * @return boolean
  */
 function canDelete(User $user)
 {
     if ($user->isAdministrator()) {
         return true;
     }
     // if
     if (!$user->isProjectUser($this->getProject())) {
         return false;
     }
     // if
     if (!$this->canManage(logged_user())) {
         return false;
         // user don't have access to this project or can't manage files
     }
     // if
     if ($this->isPrivate() && !$user->isMemberOfOwnerCompany()) {
         return false;
         // reserved only for members of owner company
     }
     // if
     return true;
 }
 /**
  * Implementation of static method.
  *
  * @param User $user
  * @return boolean
  */
 function canEdit(User $user)
 {
     $project = $this->getProject();
     if (!$project instanceof Project || !$user->isProjectUser($this->getProject())) {
         return false;
     }
     // if
     $object = $this->getObject();
     if ($object instanceof ProjectDataObject) {
         if ($user->isAdministrator()) {
             return true;
         }
         // if
         if (!$user->isMemberOfOwnerCompany() && $this->isPrivate()) {
             return false;
             // private object
         }
         // if
     }
     // if
     return false;
 }
 /**
  * Render icalendar from milestones
  *
  * @param string $calendar_name
  * @param array $milestones
  * @return null
  */
 private function renderCalendar(User $user, $calendar_name, $milestones, $user_active_projects)
 {
     $calendar = new iCalendar_Calendar();
     $calendar->setPropertyValue('VERSION', '2.0');
     $calendar->setPropertyValue('PRODID', '-//Apple Computer\\, Inc//iCal 1.5//EN');
     $calendar->setPropertyValue('X-WR-CALNAME', $calendar_name);
     $calendar->setPropertyValue('X-WR-TIMEZONE', 'GMT');
     if (is_array($user_active_projects)) {
         foreach ($user_active_projects as $project) {
             $assigned_tasks = $project->getUsersTasks(logged_user());
             if (is_array($assigned_tasks)) {
                 foreach ($assigned_tasks as $task) {
                     $todo = new iCalendar_Todo();
                     $todo->setPropertyValue('SUMMARY', $project->getName() . ": " . $task->getText());
                     $todo->setPropertyValue('UID', 'a9idfv00fd99q344o' . rand() . '*****@*****.**');
                     $date = $task->getDueDate();
                     if (!is_null($date)) {
                         $todo->setPropertyValue('DTSTART', $date->format('Ymd'), array('VALUE' => 'DATE'));
                     }
                     $priority = $task->getTaskList()->getPriority();
                     $priority = $priority ? $priority : 1;
                     $todo->setPropertyValue('PRIORITY', $priority);
                     $todo->setPropertyValue('STATUS', "NEEDS-ACTION");
                     $todo->setPropertyValue('URL', externalUrl($task->getCompleteUrl()));
                     $todo->setPropertyValue('DESCRIPTION', 'Bla Bla Bla');
                     // seting an alarm
                     $alarm = new iCalendar_Alarm();
                     $alarm->setPropertyValue('ACTION', 'DISPLAY');
                     $alarm->setPropertyValue('TRIGGER', '-P7D');
                     $alarm->setPropertyValue('DESCRIPTION', $project->getName() . ": " . $task->getText());
                     $todo->addComponent($alarm);
                     // end alarm
                     $calendar->addComponent($todo);
                 }
             }
         }
     }
     if (is_array($milestones)) {
         foreach ($milestones as $milestone) {
             if (!$user->isMemberOfOwnerCompany() && $milestone->isPrivate()) {
                 continue;
                 // hide private milestone
             }
             if (!$milestone->isCompleted()) {
                 $event = new iCalendar_Event();
                 $date = $milestone->getDueDate();
                 $event->setPropertyValue('DTSTART', $date->format('Ymd'), array('VALUE' => 'DATE'));
                 $date->advance(24 * 60 * 60);
                 $event->setPropertyValue('DTEND', $date->format('Ymd'), array('VALUE' => 'DATE'));
                 $event->setPropertyValue('UID', 'a9idfv00fd99q344o' . rand() . '*****@*****.**');
                 $event->setPropertyValue('SUMMARY', $milestone->getName() . ' (' . $milestone->getProject()->getName() . ')');
                 $event->setPropertyValue('DESCRIPTION', $desc = $milestone->getDescription());
                 $event->setPropertyValue('URL', externalUrl($milestone->getViewUrl()));
                 // setting an alarm
                 $alarm = new iCalendar_Alarm();
                 $alarm->setPropertyValue('ACTION', 'DISPLAY');
                 $alarm->setPropertyValue('TRIGGER', '-P7D');
                 $alarm->setPropertyValue('DESCRIPTION', $milestone->getName() . ' (' . $milestone->getProject()->getName() . ')');
                 $event->addComponent($alarm);
                 // end alarm
                 /* pre_var_dump($desc); */
                 $calendar->addComponent($event);
             }
             // if
         }
         // foreach
     }
     // if
     header('Content-Disposition: inline; filename=calendar.ics');
     $this->renderText(iCalendar::render($calendar), true);
     session_write_close();
     die;
 }
 /**
  * Check if $user can update message options
  *
  * @param User $user
  * @return boolean
  */
 function canUpdateOptions(User $user)
 {
     return $user->isMemberOfOwnerCompany() && $this->canEdit($user);
 }
Example #15
0
 /**
 * Returns true if this user can see $user
 *
 * @param User $user
 * @return boolean
 */
 function canSeeUser(User $user) {
   if ($this->isMemberOfOwnerCompany()) {
     return true; // see all
   } // if
   if ($user->getCompanyId() == $this->getCompanyId()) {
     return true; // see members of your own company
   } // if
   if ($user->isMemberOfOwnerCompany()) {
     return true; // see members of owner company
   } // if
   return false;
 } // canSeeUser
 /**
  * Check if user can reorder tasks in this list
  *
  * @param User $user
  * @return boolean
  */
 function canReorderTasks(User $user)
 {
     if (!$user->isProjectUser($this->getProject())) {
         return false;
         // user is on project
     }
     // if
     if ($user->isAdministrator()) {
         return true;
         // user is administrator or root
     }
     // if
     if ($this->isPrivate() && !$user->isMemberOfOwnerCompany()) {
         return false;
         // user that is not member of owner company can't add task lists
     }
     // if
     return $this->canManage($user, $this->getProject());
 }
 /**
  * Returns true if $user can view this milestone
  *
  * @param User $user
  * @return boolean
  */
 function canView(User $user)
 {
     if (!$user->isProjectUser($this->getProject())) {
         return false;
     }
     if ($user->isAdministrator()) {
         return true;
     }
     if ($this->isPrivate() && !$user->isMemberOfOwnerCompany()) {
         return false;
     }
     return true;
 }
Example #18
0
 /**
  * Return array of task that are assigned to specific user or his company
  *
  * @param User $user
  * @param array $options
  * @param boolean $include_company
  * @return array
  */
 function getUsersTickets(User $user, $options = null, $include_company = false)
 {
     if (!plugin_active('tickets')) {
         return null;
     }
     if ($include_company) {
         $conditions = DB::prepareString('`project_id` = ? AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR `created_by_id`= ?) AND `closed_on` = ?', array($this->getId(), $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, $user->getId(), EMPTY_DATETIME));
     } else {
         $conditions = DB::prepareString('`project_id` = ? AND `assigned_to_user_id` = ? AND `closed_on` = ?', array($this->getId(), $user->getId(), EMPTY_DATETIME));
     }
     // if
     if (!$user->isMemberOfOwnerCompany()) {
         $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
     }
     // if
     $options['conditions'] = $conditions;
     if (!isset($options['order'])) {
         $options['order'] = '`created_on`';
     }
     return ProjectTickets::findAll($options);
     // findAll
 }