예제 #1
0
 public function getProjectTaskLinksByCategory($AppUI = null, $project_id = 0, $task_id = 0, $category_id = 0, $search = '')
 {
     // load the following classes to retrieved denied records
     $project = new CProject();
     $project->overrideDatabase($this->_query);
     $task = new CTask();
     $task->overrideDatabase($this->_query);
     // SETUP FOR LINK LIST
     $q = $this->_getQuery();
     $q->addQuery('DISTINCT links.*');
     $q->addQuery('contact_first_name, contact_last_name, contact_display_name as contact_name');
     $q->addQuery('project_name, project_color_identifier, project_status');
     $q->addQuery('task_name, task_id');
     $q->addTable('links');
     $q->leftJoin('users', 'u', 'user_id = link_owner');
     $q->leftJoin('contacts', 'c', 'user_contact = contact_id');
     if ($search != '') {
         $q->addWhere('(link_name LIKE \'%' . $search . '%\' OR link_description LIKE \'%' . $search . '%\')');
     }
     if ($project_id > 0) {
         // Project
         $q->addWhere('link_project = ' . (int) $project_id);
     }
     if ($task_id > 0) {
         // Task
         $q->addWhere('link_task = ' . (int) $task_id);
     }
     if ($category_id >= 0) {
         // Category
         $q->addWhere('link_category = ' . $category_id);
     }
     // Permissions
     $project->setAllowedSQL($this->_AppUI->user_id, $q, 'link_project');
     $task->setAllowedSQL($this->_AppUI->user_id, $q, 'link_task and task_project = link_project');
     $q->addOrder('project_name, link_name');
     return $q->loadList();
 }
예제 #2
0
 public function getFileCountByFolder($notUsed = null, $folder_id, $task_id, $project_id, $company_id, $allowed_companies)
 {
     // SQL text for count the total recs from the selected option
     $q = $this->_getQuery();
     $q->addTable('files');
     $q->addQuery('count(files.file_id)');
     $q->addJoin('projects', 'p', 'p.project_id = file_project');
     $q->addJoin('users', 'u', 'u.user_id = file_owner');
     $q->addJoin('tasks', 't', 't.task_id = file_task');
     $q->addJoin('file_folders', 'ff', 'ff.file_folder_id = file_folder');
     $q->addWhere('file_folder = ' . (int) $folder_id);
     //TODO: apply permissions properly
     $project = new CProject();
     $project->overrideDatabase($this->_query);
     $deny1 = $project->getDeniedRecords($this->_AppUI->user_id);
     if (count($deny1) > 0) {
         $q->addWhere('file_project NOT IN (' . implode(',', $deny1) . ')');
     }
     //TODO: apply permissions properly
     $task = new CTask();
     $task->overrideDatabase($this->_query);
     $deny2 = $task->getDeniedRecords($this->_AppUI->user_id);
     if (count($deny2) > 0) {
         $q->addWhere('file_task NOT IN (' . implode(',', $deny2) . ')');
     }
     if ($project_id) {
         $q->addWhere('file_project = ' . (int) $project_id);
     }
     if ($task_id) {
         $q->addWhere('file_task = ' . (int) $task_id);
     }
     if ($company_id) {
         $q->innerJoin('companies', 'co', 'co.company_id = p.project_company');
         $q->addWhere('company_id = ' . (int) $company_id);
         $q->addWhere('company_id IN (' . $allowed_companies . ')');
     }
     $q->addGroup('file_folder_name');
     $q->addGroup('project_name');
     $q->addGroup('file_name');
     // counts total recs from selection
     return count($q->loadList());
 }
예제 #3
0
 /**
  * Tests deletion of a project.
  */
 public function testDelete()
 {
     $this->obj->bind($this->post_data);
     $result = $this->obj->store();
     $this->assertTrue($result);
     $original_id = $this->obj->project_id;
     $result = $this->obj->delete();
     $item = new CProject();
     $item->overrideDatabase($this->mockDB);
     $this->mockDB->stageHash(array('project_name' => '', 'project_url' => ''));
     $item->load($original_id);
     $this->assertTrue(is_a($item, 'CProject'));
     $this->assertEquals('', $item->project_name);
     $this->assertEquals('', $item->project_url);
     /*
      * TODO: Not sure on how to test the cascading deletes. They're handled
      *   in PHP, not in the database, so we need some assurance that they
      *   actually happen..
      */
 }
예제 #4
0
 protected function hook_preStore()
 {
     $q = $this->_getQuery();
     $this->project_updated = $q->dbfnNowWithTZ();
     // ensure changes of state in checkboxes is captured
     $this->project_active = (int) $this->project_active;
     $this->project_private = (int) $this->project_private;
     $this->project_target_budget = filterCurrency($this->project_target_budget);
     $this->project_url = str_replace(array('"', '"', '<', '>'), '', $this->project_url);
     $this->project_demo_url = str_replace(array('"', '"', '<', '>'), '', $this->project_demo_url);
     $this->project_owner = (int) $this->project_owner ? $this->project_owner : $this->_AppUI->user_id;
     $this->project_creator = (int) $this->project_creator ? $this->project_creator : $this->_AppUI->user_id;
     $this->project_priority = (int) $this->project_priority;
     $this->project_type = (int) $this->project_type;
     $this->project_status = (int) $this->project_status;
     // Make sure project_short_name is the right size (issue for languages with encoded characters)
     if ('' == $this->project_short_name) {
         $this->project_short_name = mb_substr($this->project_name, 0, 10);
     }
     $this->project_short_name = mb_substr($this->project_short_name, 0, 10);
     if (empty($this->project_end_date)) {
         $this->project_end_date = null;
     }
     $this->project_id = (int) $this->project_id;
     // convert dates to SQL format first
     if ($this->project_start_date) {
         $date = new w2p_Utilities_Date($this->project_start_date);
         $this->project_start_date = $date->format(FMT_DATETIME_MYSQL);
     }
     if ($this->project_end_date) {
         $date = new w2p_Utilities_Date($this->project_end_date);
         $this->project_end_date = $date->format(FMT_DATETIME_MYSQL);
     }
     // check project parents and reset them to self if they do not exist
     if (!$this->project_parent) {
         $this->project_parent = $this->project_id;
         $this->project_original_parent = $this->project_id;
     } else {
         $parent_project = new CProject();
         $parent_project->overrideDatabase($this->_query);
         $parent_project->load($this->project_parent);
         $this->project_original_parent = $parent_project->project_original_parent;
     }
     if (!$this->project_original_parent) {
         $this->project_original_parent = $this->project_id;
     }
     parent::hook_preStore();
 }
예제 #5
0
 public function getAllowedRecords($uid, $fields = '*', $orderby = '', $index = null, $extra = null, $unused = '')
 {
     $oPrj = new CProject();
     $oPrj->overrideDatabase($this->_query);
     $aPrjs = $oPrj->getAllowedRecords($uid, 'projects.project_id, project_name', '', null, null, 'projects');
     if (count($aPrjs)) {
         $buffer = '(event_project IN (' . implode(',', array_keys($aPrjs)) . ') OR event_project IS NULL OR event_project = \'\' OR event_project = 0)';
         if ($extra['where'] != '') {
             $extra['where'] = $extra['where'] . ' AND ' . $buffer;
         } else {
             $extra['where'] = $buffer;
         }
     } else {
         // There are no allowed projects, so only allow events with no project.
         if ($extra['where'] != '') {
             $extra['where'] = $extra['where'] . ' AND (event_project IS NULL OR event_project = \'\' OR event_project = 0) ';
         } else {
             $extra['where'] = '(event_project IS NULL OR event_project = \'\' OR event_project = 0)';
         }
     }
     return parent::getAllowedRecords($uid, $fields, $orderby, $index, $extra);
 }
예제 #6
0
 public function getAllowedRecords($uid, $fields = '*', $orderby = '', $index = null, $extra = null, $unused = '')
 {
     $oPrj = new CProject();
     $oPrj->overrideDatabase($this->_query);
     $aPrjs = $oPrj->getAllowedRecords($uid, 'projects.project_id, project_name', '', null, null, 'projects');
     if (count($aPrjs)) {
         $buffer = '(task_project IN (' . implode(',', array_keys($aPrjs)) . '))';
         if (isset($extra['where']) && $extra['where'] != '') {
             $extra['where'] = $extra['where'] . ' AND ' . $buffer;
         } else {
             $extra['where'] = $buffer;
         }
     } else {
         // There are no allowed projects, so don't allow tasks.
         if ($extra['where'] != '') {
             $extra['where'] = $extra['where'] . ' AND 1 = 0 ';
         } else {
             $extra['where'] = '1 = 0';
         }
     }
     return parent::getAllowedRecords($uid, $fields, $orderby, $index, $extra);
 }
예제 #7
0
 public function store()
 {
     $stored = false;
     $this->w2PTrimAll();
     // ensure changes of state in checkboxes is captured
     $this->project_active = (int) $this->project_active;
     $this->project_private = (int) $this->project_private;
     $this->project_target_budget = filterCurrency($this->project_target_budget);
     // Make sure project_short_name is the right size (issue for languages with encoded characters)
     $this->project_short_name = mb_substr($this->project_short_name, 0, 10);
     if (empty($this->project_end_date)) {
         $this->project_end_date = null;
     }
     $this->_error = $this->check();
     if (count($this->_error)) {
         return $this->_error;
     }
     $this->project_id = (int) $this->project_id;
     // convert dates to SQL format first
     if ($this->project_start_date) {
         $date = new w2p_Utilities_Date($this->project_start_date);
         $this->project_start_date = $date->format(FMT_DATETIME_MYSQL);
     }
     if ($this->project_end_date) {
         $date = new w2p_Utilities_Date($this->project_end_date);
         $date->setTime(23, 59, 59);
         $this->project_end_date = $date->format(FMT_DATETIME_MYSQL);
     }
     if ($this->project_actual_end_date) {
         $date = new w2p_Utilities_Date($this->project_actual_end_date);
         $this->project_actual_end_date = $date->format(FMT_DATETIME_MYSQL);
     }
     // check project parents and reset them to self if they do not exist
     if (!$this->project_parent) {
         $this->project_parent = $this->project_id;
         $this->project_original_parent = $this->project_id;
     } else {
         $parent_project = new CProject();
         $parent_project->overrideDatabase($this->_query);
         $parent_project->load($this->project_parent);
         $this->project_original_parent = $parent_project->project_original_parent;
     }
     if (!$this->project_original_parent) {
         $this->project_original_parent = $this->project_id;
     }
     /*
      * TODO: I don't like the duplication on each of these two branches, but I
      *   don't have a good idea on how to fix it at the moment...
      */
     $q = $this->_getQuery();
     $this->project_updated = $q->dbfnNowWithTZ();
     if ($this->{$this->_tbl_key} && $this->_perms->checkModuleItem($this->_tbl_module, 'edit', $this->{$this->_tbl_key})) {
         if ($msg = parent::store()) {
             $this->_error['store'] = $msg;
         } else {
             $stored = true;
         }
     }
     if (0 == $this->{$this->_tbl_key} && $this->_perms->checkModuleItem($this->_tbl_module, 'add')) {
         $this->project_created = $q->dbfnNowWithTZ();
         if ($msg = parent::store()) {
             $this->_error['store'] = $msg;
         } else {
             $stored = true;
             if (0 == $this->project_parent || 0 == $this->project_original_parent) {
                 $this->project_parent = $this->project_id;
                 $this->project_original_parent = $this->project_id;
                 if ($msg = parent::store()) {
                     $this->_error['store-check'] = $msg;
                 } else {
                     $stored = true;
                 }
             }
         }
     }
     if ($stored) {
         //split out related departments and store them seperatly.
         $q->setDelete('project_departments');
         $q->addWhere('project_id=' . (int) $this->project_id);
         $q->exec();
         $q->clear();
         $stored_departments = array();
         if ($this->project_departments) {
             foreach ($this->project_departments as $department) {
                 if ($department) {
                     $q->addTable('project_departments');
                     $q->addInsert('project_id', $this->project_id);
                     $q->addInsert('department_id', $department);
                     $stored_departments[$department] = $this->project_id;
                     $q->exec();
                     $q->clear();
                 }
             }
         }
         $this->stored_departments = $stored_departments;
         //split out related contacts and store them seperatly.
         $q->setDelete('project_contacts');
         $q->addWhere('project_id=' . (int) $this->project_id);
         $q->exec();
         $q->clear();
         $stored_contacts = array();
         if ($this->project_contacts) {
             foreach ($this->project_contacts as $contact) {
                 if ($contact) {
                     $q->addTable('project_contacts');
                     $q->addInsert('project_id', $this->project_id);
                     $q->addInsert('contact_id', $contact);
                     $stored_contacts[$contact] = $this->project_id;
                     $q->exec();
                     $q->clear();
                 }
             }
         }
         $this->stored_contacts = $stored_contacts;
         $custom_fields = new w2p_Core_CustomFields('projects', 'addedit', $this->project_id, 'edit');
         $custom_fields->bind($_POST);
         $sql = $custom_fields->store($this->project_id);
         // Store Custom Fields
         CTask::storeTokenTask($this->_AppUI, $this->project_id);
     }
     return $stored;
 }