Example #1
0
 public function getProjectTaskLinksByCategory(CAppUI $AppUI, $project_id = 0, $task_id = 0, $category_id = 0, $search = '')
 {
     // load the following classes to retrieved denied records
     $project = new CProject();
     $task = new CTask();
     // SETUP FOR LINK LIST
     $q = new w2p_Database_Query();
     $q->addQuery('DISTINCT links.*');
     $q->addQuery('contact_first_name, contact_last_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($AppUI->user_id, $q, 'link_project');
     $task->setAllowedSQL($AppUI->user_id, $q, 'link_task and task_project = link_project');
     $q->addOrder('project_name, link_name');
     return $q->loadList();
 }
 public function loadFull(CAppUI $AppUI, $holidayId)
 {
     $q = new w2p_Database_Query();
     $q->addTable('holiday');
     $q->addQuery('holiday.*');
     $q->addWhere('holiday.holiday_id = ' . (int) $holidayId);
     $q->loadObject($this, true, false);
 }
 public function _fetchPreviousData()
 {
     $q = new w2p_Database_Query();
     $q->addTable($this->table_name);
     $q->addQuery($this->field_name);
     $q->addWhere($this->id_field_name . ' = ' . $this->row_id);
     $previous_data = $q->loadResult();
     if ($previous_data != '') {
         $previous_data = unserialize($previous_data);
         $previous_data = !is_array($previous_data) ? array() : $previous_data;
     } else {
         $previous_data = array();
     }
     $this->previous_data = $previous_data;
 }
Example #4
0
 public function authenticate($username, $password)
 {
     global $db, $AppUI;
     $this->username = $username;
     $q = new w2p_Database_Query();
     $q->addTable('users');
     $q->addQuery('user_id, user_password');
     $q->addWhere("user_username = '******'");
     $q->addWhere("user_password = '******'");
     $q->exec();
     if ($row = $q->fetchRow()) {
         $this->user_id = $row['user_id'];
         return true;
     }
     return false;
 }
 public function store(CAppUI $AppUI = null)
 {
     global $AppUI;
     $perms = $AppUI->acl();
     $stored = false;
     $this->_error = $this->check();
     if (count($this->_error)) {
         return $this->_error;
     }
     $q = new w2p_Database_Query();
     if ($this->message_id && $perms->checkModuleItem('forums', 'edit', $this->forum_id)) {
         $q->setDelete('forum_visits');
         $q->addWhere('visit_message = ' . (int) $this->message_id);
         $q->exec();
         if ($msg = parent::store()) {
             return $msg;
         }
         $stored = true;
     }
     if (0 == $this->message_id && $perms->checkModuleItem('forums', 'add')) {
         $this->message_date = $q->dbfnNowWithTZ();
         if ($msg = parent::store()) {
             return $msg;
         }
         $q->addTable('forum_messages');
         $q->addQuery('count(message_id), MAX(message_date)');
         $q->addWhere('message_forum = ' . (int) $this->message_forum);
         $reply = $q->fetchRow();
         //update forum descriptor
         $forum = new CForum();
         $forum->load($AppUI, $this->message_forum);
         $forum->forum_message_count = $reply[0];
         /*
          * Note: the message_date here has already been adjusted for the
          *    timezone above, so don't do it again!
          */
         $forum->forum_last_date = $this->message_date;
         $forum->forum_last_id = $this->message_id;
         $forum->store($AppUI);
         $this->sendWatchMail(false);
         $stored = true;
     }
     return $stored;
 }
 public function store()
 {
     if (!is_array($this->options)) {
         $this->options = array();
     }
     $newoptions = $this->options;
     //insert the new option
     foreach ($newoptions as $opt) {
         $q = new w2p_Database_Query();
         $q->addTable('custom_fields_lists');
         $q->addQuery('MAX(list_option_id)');
         $max_id = $q->loadResult();
         $optid = $max_id ? $max_id + 1 : 1;
         $q = new w2p_Database_Query();
         $q->addTable('custom_fields_lists');
         $q->addInsert('field_id', $this->field_id);
         $q->addInsert('list_option_id', $optid);
         $q->addInsert('list_value', $opt);
         $q->exec();
     }
 }
Example #7
0
 public function authenticate($username, $password)
 {
     global $db, $AppUI;
     $this->username = $username;
     $q = new w2p_Database_Query();
     $q->addTable('users');
     $q->addQuery('user_id, user_password');
     $q->addWhere('user_username = \'' . $username . '\'');
     if (!($rs = $q->exec())) {
         $q->clear();
         return false;
     }
     if (!($row = $q->fetchRow())) {
         $q->clear();
         return false;
     }
     $this->user_id = $row['user_id'];
     $q->clear();
     if (MD5($password) == $row['user_password']) {
         return true;
     }
     return false;
 }
 public function getAllTasksForPeriod($start_date, $end_date, $company_id = 0, $user_id = null)
 {
     global $AppUI;
     $q = new w2p_Database_Query();
     // convert to default db time stamp
     $db_start = $start_date->format(FMT_DATETIME_MYSQL);
     $db_end = $end_date->format(FMT_DATETIME_MYSQL);
     // Allow for possible passing of user_id 0 to stop user filtering
     if (!isset($user_id)) {
         $user_id = $AppUI->user_id;
     }
     // check permissions on projects
     $proj = new CProject();
     $task_filter_where = $proj->getAllowedSQL($AppUI->user_id, 't.task_project');
     // exclude read denied projects
     $deny = $proj->getDeniedRecords($AppUI->user_id);
     // check permissions on tasks
     $obj = new CTask();
     $allow = $obj->getAllowedSQL($AppUI->user_id, 't.task_id');
     $q->addTable('tasks', 't');
     if ($user_id) {
         $q->innerJoin('user_tasks', 'ut', 't.task_id=ut.task_id');
     }
     $q->innerJoin('projects', 'projects', 't.task_project = projects.project_id');
     $q->innerJoin('companies', 'companies', 'projects.project_company = companies.company_id');
     $q->leftJoin('project_departments', '', 'projects.project_id = project_departments.project_id');
     $q->leftJoin('departments', '', 'departments.dept_id = project_departments.department_id');
     $q->addQuery('DISTINCT t.task_id, t.task_name, t.task_start_date, t.task_end_date, t.task_percent_complete, t.task_duration' . ', t.task_duration_type, projects.project_color_identifier AS color, projects.project_name, t.task_milestone, task_description, task_type, company_name, task_access, task_owner');
     $q->addWhere('task_status > -1' . ' AND (task_start_date <= \'' . $db_end . '\'  AND t.task_percent_complete<100  OR task_end_date = \'0000-00-00 00:00:00\' OR task_end_date = NULL )');
     $q->addWhere('project_active = 1');
     if (($template_status = w2PgetConfig('template_projects_status_id')) != '') {
         $q->addWhere('project_status <> ' . $template_status);
     }
     if ($user_id) {
         $q->addWhere('ut.user_id = ' . (int) $user_id);
     }
     if ($company_id) {
         $q->addWhere('projects.project_company = ' . (int) $company_id);
     }
     if (count($task_filter_where) > 0) {
         $q->addWhere('(' . implode(' AND ', $task_filter_where) . ')');
     }
     if (count($deny) > 0) {
         $q->addWhere('(t.task_project NOT IN (' . implode(', ', $deny) . '))');
     }
     if (count($allow) > 0) {
         $q->addWhere('(' . implode(' AND ', $allow) . ')');
     }
     $q->addOrder('t.task_start_date');
     // assemble query
     $tasks = $q->loadList(-1, 'task_id');
     // check tasks access
     $result = array();
     foreach ($tasks as $key => $row) {
         $obj->load($row['task_id']);
         $canAccess = $obj->canAccess();
         if (!$canAccess) {
             continue;
         }
         $result[$key] = $row;
     }
     // execute and return
     return $result;
 }
Example #9
0
    } else {
        $catsql = 'file_category = ' . ($tab - 1);
    }
} else {
    if ($tab < 0) {
        $catsql = false;
    } else {
        $catsql = 'file_category = ' . $tab;
    }
}
// Fetch permissions once for all queries
$allowedProjects = $project->getAllowedSQL($AppUI->user_id, 'file_project');
$allowedTasks = $task->getAllowedSQL($AppUI->user_id, 'file_task');
// SQL text for count the total recs from the selected option
$q = new w2p_Database_Query();
$q->addQuery('count(file_id)');
$q->addTable('files', 'f');
$q->addJoin('projects', 'p', 'p.project_id = file_project');
$q->addJoin('tasks', 't', 't.task_id = file_task');
$q->leftJoin('project_departments', 'project_departments', 'p.project_id = project_departments.project_id OR project_departments.project_id IS NULL');
$q->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL');
if (count($allowedProjects)) {
    $q->addWhere('( ( ' . implode(' AND ', $allowedProjects) . ') OR file_project = 0 )');
}
if (count($allowedTasks)) {
    $q->addWhere('( ( ' . implode(' AND ', $allowedTasks) . ') OR file_task = 0 )');
}
if ($catsql) {
    $q->addWhere($catsql);
}
if ($company_id) {
Example #10
0
$q->addQuery('task_duration, task_duration_type');
$q->addQuery('task_project, task_represents_project');
$q->addQuery('task_description, task_owner, task_status');
$q->addQuery('usernames.user_username, usernames.user_id');
$q->addQuery('assignees.user_username as assignee_username');
$q->addQuery('count(distinct assignees.user_id) as assignee_count');
$q->addQuery('co.contact_first_name, co.contact_last_name');
$q->addQuery('CONCAT(co.contact_first_name,\' \', co.contact_last_name) AS owner');
$q->addQuery('task_milestone');
$q->addQuery('count(distinct f.file_task) as file_count');
$q->addQuery('tlog.task_log_problem');
$q->addQuery('task_access');
//subquery the parent state
$sq = new w2p_Database_Query();
$sq->addTable('tasks', 'stasks');
$sq->addQuery('COUNT(stasks.task_id)');
$sq->addWhere('stasks.task_id <> tasks.task_id AND stasks.task_parent = tasks.task_id');
$subquery = $sq->prepare();
$sq->clear();
$q->addQuery('(' . $subquery . ') AS task_nr_of_children');
$q->addTable('tasks');
$mods = $AppUI->getActiveModules();
if (!empty($mods['history']) && canView('history')) {
    $q->addQuery('MAX(history_date) as last_update');
    $q->leftJoin('history', 'h', 'history_item = tasks.task_id AND history_table=\'tasks\'');
}
$q->addJoin('projects', 'p', 'p.project_id = task_project', 'inner');
$q->leftJoin('users', 'usernames', 'task_owner = usernames.user_id');
$q->leftJoin('user_tasks', 'ut', 'ut.task_id = tasks.task_id');
$q->leftJoin('users', 'assignees', 'assignees.user_id = ut.user_id');
$q->leftJoin('contacts', 'co', 'co.contact_id = usernames.user_contact');
Example #11
0
 /**
  * Tests adding a reminder to a task
  */
 public function testAddReminder()
 {
     global $AppUI;
     global $w2Pconfig;
     $this->obj->load(1);
     // Ensure our global setting for task_reminder_control is set properly for this
     $old_task_reminder_control = $w2Pconfig['task_reminder_control'];
     $w2Pconfig['task_reminder_control'] = true;
     $this->obj->addReminder();
     $this->obj->task_percent_complete = 50;
     $xml_file_dataset = $this->createXMLDataset($this->getDataSetPath() . 'tasksTestAddReminder.xml');
     $xml_file_filtered_dataset = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($xml_file_dataset, array('event_queue' => array('queue_start')));
     $xml_db_dataset = $this->getConnection()->createDataSet();
     $xml_db_filtered_dataset = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($xml_db_dataset, array('event_queue' => array('queue_start')));
     $this->assertTablesEqual($xml_file_filtered_dataset->getTable('event_queue'), $xml_db_filtered_dataset->getTable('event_queue'));
     $now_secs = time();
     $min_time = $now_secs - 10;
     /**
      * Get updated dates to test against
      */
     $q = new w2p_Database_Query();
     $q->addTable('event_queue');
     $q->addQuery('queue_start');
     $q->addWhere('queue_id = 2');
     $results = $q->loadColumn();
     foreach ($results as $queue_start) {
         $this->assertGreaterThanOrEqual($min_time, $queue_start);
         $this->assertLessThanOrEqual($now_secs, $queue_start);
     }
     $w2Pconfig['task_reminder_control'] = $old_task_reminder_control;
 }
Example #12
0
$taskPriority = w2PgetSysVal('TaskPriority');
$task_project = $project_id;
$task_sort_item1 = w2PgetParam($_GET, 'task_sort_item1', '');
$task_sort_type1 = w2PgetParam($_GET, 'task_sort_type1', '');
$task_sort_item2 = w2PgetParam($_GET, 'task_sort_item2', '');
$task_sort_type2 = w2PgetParam($_GET, 'task_sort_type2', '');
$task_sort_order1 = (int) w2PgetParam($_GET, 'task_sort_order1', 0);
$task_sort_order2 = (int) w2PgetParam($_GET, 'task_sort_order2', 0);
if (isset($_POST['show_task_options'])) {
    $AppUI->setState('TaskListShowIncomplete', w2PgetParam($_POST, 'show_incomplete', 0));
}
$showIncomplete = $AppUI->getState('TaskListShowIncomplete', 0);
$project = new CProject();
$allowedProjects = $project->getAllowedSQL($AppUI->user_id);
$working_hours = $w2Pconfig['daily_working_hours'] ? $w2Pconfig['daily_working_hours'] : 8;
$q->addQuery('projects.project_id, project_color_identifier, project_name');
$q->addQuery('SUM(task_duration * task_percent_complete * IF(task_duration_type = 24, ' . $working_hours . ', task_duration_type)) / SUM(task_duration * IF(task_duration_type = 24, ' . $working_hours . ', task_duration_type)) AS project_percent_complete');
$q->addQuery('company_name');
$q->addTable('projects');
$q->leftJoin('tasks', 't1', 'projects.project_id = t1.task_project');
$q->leftJoin('companies', 'c', 'company_id = project_company');
$q->leftJoin('project_departments', 'project_departments', 'projects.project_id = project_departments.project_id OR project_departments.project_id IS NULL');
$q->leftJoin('departments', 'departments', 'departments.dept_id = project_departments.department_id OR dept_id IS NULL');
$q->addWhere('t1.task_id = t1.task_parent');
$q->addWhere('projects.project_id=' . $project_id);
if (count($allowedProjects)) {
    $q->addWhere($allowedProjects);
}
$q->addGroup('projects.project_id');
$q2 = new w2p_Database_Query();
$q2 = $q;
Example #13
0
<?php

/* $Id$ $URL$ */
if (!defined('W2P_BASE_DIR')) {
    die('You should not access this file directly.');
}
$perms =& $AppUI->acl();
if (!canView('tasks')) {
    $AppUI->redirect('m=public&a=access_denied');
}
$proj = (int) w2PgetParam($_GET, 'project', 0);
$userFilter = w2PgetParam($_GET, 'userFilter', false);
$q = new w2p_Database_Query();
$q->addQuery('t.task_id, t.task_name');
$q->addTable('tasks', 't');
if ($userFilter) {
    $q->addJoin('user_tasks', 'ut', 'ut.task_id = t.task_id');
    $q->addWhere('ut.user_id = ' . (int) $AppUI->user_id);
}
if ($proj != 0) {
    $q->addWhere('task_project = ' . (int) $proj);
}
$tasks = $q->loadList();
$q->clear();
?>

<script language="javascript" type="text/javascript">
function loadTasks() {
	var tasks = new Array();
	var sel = parent.document.forms['form'].new_task;
	while (sel.options.length) {
Example #14
0
 /**
  * Tests storing task log in database
  */
 public function testStoreUpdate()
 {
     $this->obj->bind($this->post_data, null, true, true);
     $this->obj->task_log_id = 1;
     unset($this->obj->task_log_created);
     $this->obj->store();
     $xml_file_dataset = $this->createXMLDataSet($this->getDataSetPath() . 'tasklogsTestStoreUpdate.xml');
     $xml_file_filtered_dataset = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($xml_file_dataset, array('task_log' => array('task_log_created', 'task_log_updated')));
     $xml_db_dataset = $this->getConnection()->createDataSet();
     $xml_db_filtered_dataset = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($xml_db_dataset, array('task_log' => array('task_log_created', 'task_log_updated')));
     $this->assertTablesEqual($xml_file_filtered_dataset->getTable('task_log'), $xml_db_filtered_dataset->getTable('task_log'));
     $this->assertTablesEqual($xml_file_filtered_dataset->getTable('tasks'), $xml_db_filtered_dataset->getTable('tasks'));
     $this->assertTablesEqual($xml_file_filtered_dataset->getTable('projects'), $xml_db_filtered_dataset->getTable('projects'));
     /**
      * Get updated dates to test against
      */
     $now_secs = time();
     $min_time = $now_secs - 10;
     $q = new w2p_Database_Query();
     $q->addTable('task_log');
     $q->addQuery('task_log_updated');
     $q->addWhere('task_log_id = 1');
     $results = $q->loadList();
     foreach ($results as $dates) {
         $this->assertGreaterThanOrEqual($min_time, strtotime($dates['task_log_updated']));
         $this->assertLessThanOrEqual($now_secs, strtotime($dates['task_log_updated']));
     }
 }
Example #15
0
}
##
## add or edit a user preferences
##
$user_id = (int) w2PgetParam($_GET, 'user_id', '0');
$perms =& $AppUI->acl();
// check permissions for this record
$canEdit = canEdit('system');
// Check permissions
if (!$canEdit && $user_id != $AppUI->user_id) {
    $AppUI->redirect('m=public&a=access_denied');
}
// load the preferences
$q = new w2p_Database_Query();
$q->addTable('user_preferences');
$q->addQuery('pref_name, pref_value');
$q->addWhere('pref_user = '******'Default';
}
$titleBlock = new w2p_Theme_TitleBlock('Edit User Preferences', 'myevo-weather.png', $m, $m . '.' . $a);
$perms =& $AppUI->acl();
if ($canEdit) {
    $titleBlock->addCrumb('?m=system', 'system admin');
    $titleBlock->addCrumb('?m=system&a=systemconfig', 'system configuration');
}
    ?>
<script language="javascript" type="text/javascript">
	<?php 
    echo $call_back_string;
    ?>
	self.close();
</script>
<?php 
}
// Remove any empty elements
$contacts_id = remove_invalid(explode(',', $selected_contacts_id));
$selected_contacts_id = implode(',', $contacts_id);
$q = new w2p_Database_Query();
if (strlen($selected_contacts_id) > 0 && !$show_all && !$company_id) {
    $q->addTable('contacts');
    $q->addQuery('DISTINCT contact_company');
    $q->addWhere('contact_id IN (' . $selected_contacts_id . ')');
    $where = implode(',', $q->loadColumn());
    $q->clear();
    if (substr($where, 0, 1) == ',') {
        $where = '0' . $where;
    }
    $where = $where ? 'contact_company IN(' . $where . ')' : '';
} elseif (!$company_id && !$show_all) {
    //  Contacts from all allowed companies
    $where = '(contact_company IS NULL OR contact_company = 0)';
    $company_name = $AppUI->_('No Company');
} elseif ($show_all) {
    $company_name = $AppUI->_('Allowed Companies');
} else {
    // Contacts for this company only
Example #17
0
$today = new w2p_Utilities_Date();
$today->convertTZ($AppUI->getPref('TIMEZONE'));
//Lets load the users panel viewing options
$q = new w2p_Database_Query();
$q->addTable('project_designer_options', 'pdo');
$q->addQuery('pdo.*');
$q->addWhere('pdo.pd_option_user = '******'project_id', 0);
$project_id = (int) w2PgetParam($_GET, 'project_id', $project_id);
$extra = array('where' => 'project_active = 1');
$project = new CProject();
$projects = $project->getAllowedRecords($AppUI->user_id, 'projects.project_id,project_name', 'project_name', null, $extra, 'projects');
$q = new w2p_Database_Query();
$q->addTable('projects');
$q->addQuery('projects.project_id, company_name');
$q->addJoin('companies', 'co', 'co.company_id = project_company');
$idx_companies = $q->loadHashList();
$q->clear();
foreach ($projects as $prj_id => $prj_name) {
    $projects[$prj_id] = $idx_companies[$prj_id] . ': ' . $prj_name;
}
asort($projects);
$projects = arrayMerge(array('0' => $AppUI->_('(None)', UI_OUTPUT_RAW)), $projects);
$extra = array();
$task = new CTask();
$tasks = $task->getAllowedRecords($AppUI->user_id, 'task_id,task_name', 'task_name', null, $extra);
$tasks = arrayMerge(array('0' => $AppUI->_('(None)', UI_OUTPUT_RAW)), $tasks);
if (!$project_id) {
    // setup the title block
    $ttl = 'ProjectDesigner';
Example #18
0
 /**
  * Tests importing tasks from one project to another
  */
 public function testImportTasks()
 {
     $this->markTestIncomplete("This test is failing miserably.. not sure of the best way to solve it yet.");
     $this->obj->load(4);
     $response = $this->obj->importTasks(3);
     $this->assertEquals(array(), $response);
     //        $xml_file_dataset = $this->createXMLDataSet($this->getDataSetPath().'projectsTestImportTasks.xml');
     //        $xml_file_filtered_dataset = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($xml_file_dataset, array('tasks' => array('task_created', 'task_updated')));
     //        $xml_db_dataset = $this->getConnection()->createDataSet();
     //        $xml_db_filtered_dataset = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($xml_db_dataset, array('tasks' => array('task_created', 'task_updated')));
     //        $this->assertTablesEqual($xml_file_filtered_dataset->getTable('tasks'), $xml_db_filtered_dataset->getTable('tasks'));
     $now_secs = time();
     $min_time = $now_secs - 10;
     /**
      * Get created dates to test against
      */
     $q = new w2p_Database_Query();
     $q->addTable('tasks');
     $q->addQuery('task_created');
     $q->addWhere('task_project = 4');
     $results = $q->loadColumn();
     global $AppUI;
     foreach ($results as $created) {
         $created = strtotime($AppUI->formatTZAwareTime($created, '%Y-%m-%d %T'));
         $this->assertGreaterThanOrEqual($created, $now_secs);
         $this->assertLessThanOrEqual($created, $min_time);
     }
     /**
      * Get updated dates to test against
      */
     $q = new w2p_Database_Query();
     $q->addTable('tasks');
     $q->addQuery('task_updated');
     $q->addWhere('task_project = 4');
     $results = $q->loadColumn();
     foreach ($results as $updated) {
         $updated = strtotime($AppUI->formatTZAwareTime($updated, '%Y-%m-%d %T'));
         $this->assertGreaterThanOrEqual($min_time, $updated);
         $this->assertLessThanOrEqual($now_secs, $updated);
     }
     //        $xml_dataset = $this->createXMLDataSet($this->getDataSetPath().'projectsTestImportTasks.xml');
     //        $this->assertTablesEqual($xml_dataset->getTable('user_tasks'), $this->getConnection()->createDataSet()->getTable('user_tasks'));
     //        $this->assertTablesEqual($xml_dataset->getTable('task_dependencies'), $this->getConnection()->createDataSet()->getTable('task_dependencies'));
 }
Example #19
0
 public static function updateHoursWorked($taskId, $totalHours)
 {
     $q = new w2p_Database_Query();
     $q->addTable('tasks');
     $q->addUpdate('task_hours_worked', $totalHours + 0);
     $q->addWhere('task_id = ' . $taskId);
     $q->exec();
     $q->clear();
     $q->addTable('tasks');
     $q->addQuery('task_project');
     $q->addWhere('task_id = ' . $taskId);
     $project_id = $q->loadResult();
     CProject::updateHoursWorked($project_id);
 }
Example #20
0
function showcompany($company, $restricted = false)
{
    global $AppUI, $allpdfdata, $log_start_date, $log_end_date, $log_all;
    $q = new w2p_Database_Query();
    $q->addTable('projects');
    $q->addQuery('project_id, project_name');
    $q->addWhere('project_company = ' . (int) $company);
    $projects = $q->loadHashList();
    $q->clear();
    $q->addTable('companies');
    $q->addQuery('company_name');
    $q->addWhere('company_id = ' . (int) $company);
    $company_name = $q->loadResult();
    $q->clear();
    $table = '<h2>Company: ' . $company_name . '</h2>
    	<table cellspacing="1" cellpadding="4" border="0" class="tbl">';
    $project_row = '
        <tr>
                <th>' . $AppUI->_('Project') . '</th>';
    $pdfth[] = $AppUI->_('Project');
    $project_row .= '<th>' . $AppUI->_('Total') . '</th></tr>';
    $pdfth[] = $AppUI->_('Total');
    $pdfdata[] = $pdfth;
    $hours = 0.0;
    $table .= $project_row;
    foreach ($projects as $project => $name) {
        $pdfproject = array();
        $pdfproject[] = $name;
        $project_hours = 0;
        $project_row = '<tr><td>' . $name . '</td>';
        $q->addTable('projects');
        $q->addTable('tasks');
        $q->addTable('task_log');
        $q->addQuery('task_log_costcode, SUM(task_log_hours) as hours');
        $q->addWhere('project_id = ' . (int) $project);
        $q->addWhere('project_active = 1');
        if (($template_status = w2PgetConfig('template_projects_status_id')) != '') {
            $q->addWhere('project_status <> ' . (int) $template_status);
        }
        if ($log_start_date != 0 && !$log_all) {
            $q->addWhere('task_log_date >=' . $log_start_date);
        }
        if ($log_end_date != 0 && !$log_all) {
            $q->addWhere('task_log_date <=' . $log_end_date);
        }
        if ($restricted) {
            $q->addWhere('task_log_creator = ' . (int) $AppUI->user_id);
        }
        $q->addWhere('project_id = task_project');
        $q->addWhere('task_id = task_log_task');
        $q->addGroup('project_id');
        $task_logs = $q->loadHashList();
        $q->clear();
        foreach ($task_logs as $task_log) {
            $project_hours += $task_log;
        }
        $project_row .= '<td style="text-align:right;">' . sprintf('%.2f', round($project_hours, 2)) . '</td></tr>';
        $pdfproject[] = round($project_hours, 2);
        $hours += $project_hours;
        if ($project_hours > 0) {
            $table .= $project_row;
            $pdfdata[] = $pdfproject;
        }
    }
    if ($hours > 0) {
        $pdfdata[] = array($AppUI->_('Total'), round($hours, 2));
        $allpdfdata[$company_name] = $pdfdata;
        echo $table;
        echo '<tr><td>' . $AppUI->_('Total') . '</td><td style="text-align:right;">' . sprintf('%.2f', round($hours, 2)) . '</td></tr></table>';
    }
    return $hours;
}
Example #21
0
    }
    echo '<table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">
	<tr>
		<td>';
    // Let's figure out which users we have
    $user_list = w2PgetUsersHashList();
    // Now which tasks will we need and the real allocated hours (estimated time / number of users)
    // Also we will use tasks with duration_type = 1 (hours) and those that are not marked
    // as milstones
    // GJB: Note that we have to special case duration type 24 and this refers to the hours in a day, NOT 24 hours
    $working_hours = $w2Pconfig['daily_working_hours'];
    $q = new w2p_Database_Query();
    $q->addTable('tasks', 't');
    $q->addTable('user_tasks', 'ut');
    $q->addJoin('projects', '', 'project_id = task_project', 'inner');
    $q->addQuery('t.task_id, round(t.task_duration * IF(t.task_duration_type = 24, ' . $working_hours . ', t.task_duration_type)/count(ut.task_id),2) as hours_allocated');
    $q->addWhere('t.task_id = ut.task_id');
    $q->addWhere('t.task_milestone = 0');
    $q->addWhere('project_active = 1');
    if (($template_status = w2PgetConfig('template_projects_status_id')) != '') {
        $q->addWhere('project_status <> ' . (int) $template_status);
    }
    if ($project_id != 0) {
        $q->addWhere('t.task_project = ' . (int) $project_id);
    }
    if (!$log_all) {
        $q->addWhere('t.task_start_date >= \'' . $start_date->format(FMT_DATETIME_MYSQL) . '\'');
        $q->addWhere('t.task_start_date <= \'' . $end_date->format(FMT_DATETIME_MYSQL) . '\'');
    }
    $q->addGroup('t.task_id');
    $task_list = $q->loadHashList('task_id');
 public static function updatePercentComplete($project_id)
 {
     $working_hours = w2PgetConfig('daily_working_hours') ? w2PgetConfig('daily_working_hours') : 8;
     $q = new w2p_Database_Query();
     $q->addTable('projects');
     $q->addQuery('SUM(t1.task_duration * t1.task_percent_complete * IF(t1.task_duration_type = 24, ' . $working_hours . ', t1.task_duration_type)) / SUM(t1.task_duration * IF(t1.task_duration_type = 24, ' . $working_hours . ', t1.task_duration_type)) AS project_percent_complete');
     $q->addJoin('tasks', 't1', 'projects.project_id = t1.task_project', 'inner');
     $q->addWhere('project_id = ' . $project_id . ' AND t1.task_id = t1.task_parent');
     $project_percent_complete = $q->loadResult();
     $q->clear();
     $q->addTable('projects');
     $q->addUpdate('project_percent_complete', $project_percent_complete);
     $q->addWhere('project_id  = ' . (int) $project_id);
     $q->exec();
     global $AppUI;
     CTask::storeTokenTask($AppUI, $project_id);
 }
Example #23
0
*/
if ($addPwOiD && $department > 0) {
    $owner_ids = array();
    $q = new w2p_Database_Query();
    $q->addTable('users');
    $q->addQuery('user_id');
    $q->addJoin('contacts', 'c', 'c.contact_id = user_contact', 'inner');
    $q->addWhere('c.contact_department = ' . (int) $department);
    $owner_ids = $q->loadColumn();
    $q->clear();
}
// pull valid projects and their percent complete information
$q = new w2p_Database_Query();
$q->addTable('projects', 'pr');
$q->addQuery('DISTINCT pr.project_id, project_color_identifier, project_name, project_start_date, project_end_date,
                max(t1.task_end_date) AS project_actual_end_date, project_percent_complete,
                project_status, project_active');
$q->addJoin('tasks', 't1', 'pr.project_id = t1.task_project');
$q->addJoin('companies', 'c1', 'pr.project_company = c1.company_id');
if ($department > 0 && !$addPwOiD) {
    $q->addWhere('project_departments.department_id = ' . (int) $department);
}
if ($project_type > -1) {
    $q->addWhere('pr.project_type = ' . (int) $project_type);
}
if ($owner > 0) {
    $q->addWhere('pr.project_owner = ' . (int) $owner);
}
if ($proFilter == '-3') {
    $q->addWhere('pr.project_owner = ' . (int) $user_id);
} elseif ($proFilter != '-1') {
Example #24
0
 public static function getFileList($AppUI = null, $company_id = 0, $project_id = 0, $task_id = 0, $category_id = 0)
 {
     global $AppUI;
     $q = new w2p_Database_Query();
     $q->addQuery('f.*');
     $q->addTable('files', 'f');
     $q->addJoin('projects', 'p', 'p.project_id = file_project');
     $q->addJoin('project_departments', 'pd', 'p.project_id = pd.project_id');
     $q->addJoin('departments', '', 'pd.department_id = dept_id');
     $q->addJoin('tasks', 't', 't.task_id = file_task');
     $project = new CProject();
     //TODO: We need to convert this from static to use ->overrideDatabase() for testing.
     $allowedProjects = $project->getAllowedSQL($AppUI->user_id, 'file_project');
     if (count($allowedProjects)) {
         $q->addWhere('( ( ' . implode(' AND ', $allowedProjects) . ') OR file_project = 0 )');
     }
     if (isset($company_id) && (int) $company_id > 0) {
         $q->addWhere('project_company = ' . (int) $company_id);
     }
     if (isset($project_id) && (int) $project_id > 0) {
         $q->addWhere('file_project = ' . (int) $project_id);
     }
     if (isset($task_id) && (int) $task_id > 0) {
         $q->addWhere('file_task = ' . (int) $task_id);
     }
     if ($category_id >= 0) {
         $q->addWhere('file_category = ' . (int) $category_id);
     }
     return $q->loadList();
 }
 public static function getProjects($contactId)
 {
     $q = new w2p_Database_Query();
     $q->addQuery('p.project_id, p.project_name');
     $q->addTable('project_contacts', 'pc');
     $q->addJoin('projects', 'p', 'p.project_id = pc.project_id', 'inner');
     $q->addWhere("contact_id =  {$contactId}");
     return $q->loadList();
 }
Example #26
0
            $boot_query_row = $r->fetchRow();
            if ($boot_query_row) {
                $boot_user_session = $boot_query_row['session_id'];
                $boot_user_log_id = $boot_query_row['user_access_log_id'];
            } else {
                $r->clear();
            }
        }
    } while ($boot_query_row);
    $msg = $boot_user_name . ' logged out by ' . $AppUI->user_first_name . ' ' . $AppUI->user_last_name;
    $AppUI->setMsg($msg, UI_MSG_OK);
    $AppUI->redirect('m=admin&tab=3');
}
$q = new w2p_Database_Query();
$q->addTable('sessions', 's');
$q->addQuery('DISTINCT(session_id), user_access_log_id, u.user_id as u_user_id, user_username, contact_last_name, contact_first_name, company_name, contact_company, date_time_in, user_ip');
$q->addJoin('user_access_log', 'ual', 'session_user = user_access_log_id');
$q->addJoin('users', 'u', 'ual.user_id = u.user_id');
$q->addJoin('contacts', 'con', 'u.user_contact = contact_id');
$q->addJoin('companies', 'com', 'contact_company = company_id');
$q->addOrder($orderby);
$rows = $q->loadList();
$q->clear();
$tab = w2PgetParam($_REQUEST, 'tab', 0);
?>

<table cellpadding="2" cellspacing="1" border="0" width="100%" class="tbl">
    <tr>
        <th colspan="2">&nbsp; <?php 
echo $AppUI->_('sort by');
?>
Example #27
0
    echo $AppUI->getTheme()->styleRenderBoxTop();
    echo '<table class="std">
	<tr>
		<td align="center">';
    // Let's figure out which users we have
    $user_list = w2PgetUsersHashList();
    if ($log_userfilter != 0) {
        $user_list = array($log_userfilter => $user_list[$log_userfilter]);
    }
    $ss = "'" . $start_date->format(FMT_DATETIME_MYSQL) . "'";
    $se = "'" . $end_date->format(FMT_DATETIME_MYSQL) . "'";
    $and = false;
    $where = false;
    $q = new w2p_Database_Query();
    $q->addTable('tasks', 't');
    $q->addQuery('t.*');
    $q->addJoin('projects', '', 'projects.project_id = task_project', 'inner');
    $q->addJoin('project_departments', '', 'project_departments.project_id = projects.project_id');
    $q->addJoin('departments', '', 'department_id = dept_id');
    $q->addWhere('project_active = 1');
    if (($template_status = w2PgetConfig('template_projects_status_id')) != '') {
        $q->addWhere('project_status <> ' . (int) $template_status);
    }
    if ($use_period) {
        $q->addWhere('( (task_start_date >= ' . $ss . ' AND task_start_date <= ' . $se . ') OR ' . '(task_end_date <= ' . $se . ' AND task_end_date >= ' . $ss . ') )');
    }
    if ($project_id != 0) {
        $q->addWhere('task_project=' . $project_id);
    }
    $proj = new CProject();
    $obj = new CTask();
Example #28
0
<?php

/* $Id$ $URL$ */
if (!defined('W2P_BASE_DIR')) {
    die('You should not access this file directly.');
}
// check permissions
$perms =& $AppUI->acl();
if (!canEdit('system')) {
    $AppUI->redirect('m=public&a=access_denied');
}
$q = new w2p_Database_Query();
$q->addTable('syskeys');
$q->addQuery('*');
$q->addOrder('syskey_name');
$keys = $q->loadList();
$q->clear();
$syskey_id = (int) w2PgetParam($_GET, 'syskey_id', 0);
$titleBlock = new CTitleBlock('System Lookup Keys', 'myevo-weather.png', $m, $m . '.' . $a);
$titleBlock->addCrumb('?m=system', 'System Admin');
$titleBlock->show();
?>
<script language="javascript" type="text/javascript">
<?php 
// security improvement:
// some javascript functions may not appear on client side in case of user not having write permissions
// else users would be able to arbitrarily run 'bad' functions
if ($canEdit) {
    ?>
function delIt(id) {
	if (confirm( 'Are you sure you want to delete this?' )) {
$gantt->SetDateRange($start_date, $end_date);
$row = 0;
if (!is_array($projects) || sizeof($projects) == 0) {
    $d = new w2p_Utilities_Date();
    $columnValues = array('project_name' => $AppUI->_('No projects found'), 'start_date' => $d->getDate(), 'end_date' => $d->getDate(), 'actual_end' => '');
    $gantt->addBar($columnValues, ' ', 0.6, 'red');
} else {
    if (is_array($projects)) {
        //pull all tasks into an array keyed by the project id, and get the tasks in hierarchy
        if ($showAllGantt) {
            // insert tasks into Gantt Chart
            // select for tasks for each project
            // pull tasks
            $q = new w2p_Database_Query();
            $q->addTable('tasks', 't');
            $q->addQuery('t.task_id, task_parent, task_name, task_start_date, task_end_date, task_duration, task_duration_type, task_priority, task_percent_complete, task_order, task_project, task_milestone, project_id, project_name, task_dynamic');
            $q->addJoin('projects', 'p', 'project_id = t.task_project');
            $q->addOrder('project_id, task_start_date');
            $q->addWhere('project_original_parent = ' . (int) $original_project_id);
            //$tasks = $q->loadList();
            $task = new CTask();
            $task->setAllowedSQL($AppUI->user_id, $q);
            $proTasks = $q->loadHashList('task_id');
            $orrarr[] = array('task_id' => 0, 'order_up' => 0, 'order' => '');
            $end_max = '0000-00-00 00:00:00';
            $start_min = date('Y-m-d H:i:s');
            //pull the tasks into an array
            foreach ($proTasks as $rec) {
                if ($rec['task_start_date'] == '0000-00-00 00:00:00') {
                    $rec['task_start_date'] = date('Y-m-d H:i:s');
                }
Example #30
0
$company_id = isset($_REQUEST['company_id']) ? w2PgetParam($_REQUEST, 'company_id', 0) : 0;
// Check permissions
$perms =& $AppUI->acl();
if (!canEdit('system')) {
    $AppUI->redirect('m=public&a=access_denied');
}
$q = new w2p_Database_Query();
$q->addTable('billingcode', 'bc');
$q->addQuery('billingcode_id, billingcode_name, billingcode_value, billingcode_desc, billingcode_status');
$q->addOrder('billingcode_name ASC');
$q->addWhere('company_id = ' . (int) $company_id);
$billingcodes = $q->loadList();
$q->clear();
$q = new w2p_Database_Query();
$q->addTable('companies', 'c');
$q->addQuery('company_id, company_name');
$q->addOrder('company_name ASC');
$company_list = $q->loadHashList();
$company_list[0] = $AppUI->_('Select Company');
$q->clear();
$company_name = $company_list[$company_id];
$titleBlock = new CTitleBlock('Edit Billing Codes', 'myevo-weather.png', $m, $m . '.' . $a);
$titleBlock->addCrumb('?m=system', 'system admin');
$titleBlock->show();
?>
<script language="javascript" type="text/javascript">
<!--
function submitIt(){
	var form = document.changeuser;
	form.submit();
}