Exemplo n.º 1
0
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool
  **/
 function importTasks($from_project_id, $scale_project = false)
 {
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $from_project_id);
     $sql = $q->prepare();
     $q->clear();
     $tasks = array_flip(db_loadColumn($sql));
     //Pristine Start and End Dates of Source and Destination Projects
     $origStartDate = new CDate($origProject->project_start_date);
     $origEndDate = new CDate($origProject->project_end_date);
     $destStartDate = new CDate($this->project_start_date);
     $destEndDate = new CDate($this->project_end_date);
     $dateOffset = $destStartDate->dateDiff($origStartDate);
     //Check that we have enough information to scale properly
     //(i.e. no information is missing or "zero")
     if (empty($origProject->project_start_date) || empty($origProject->project_end_date) || empty($this->project_start_date) || empty($this->project_end_date) || $origProject->project_start_date == '0000-00-00 00:00:00' || $origProject->project_end_date == '0000-00-00 00:00:00' || $this->project_start_date == '0000-00-00 00:00:00' || $this->project_end_date == '0000-00-00 00:00:00') {
         $scale_project = false;
     }
     if ($scale_project) {
         //get ratio for scaling, protect from division by 0
         $ratio = (abs($destEndDate->dateDiff($destStartDate)) + 1) / (abs($origEndDate->dateDiff($origStartDate)) + 1);
     }
     // Old dependencies array from imported tasks
     $deps = array();
     // New dependencies array for new copies of imported tasks
     $newDeps = array();
     // Old2New task ID array
     $taskXref = array();
     // New task ID to old parent array
     $nid2op = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         // Grab the old parent id
         $oldParent = (int) $objTask->task_parent;
         $deps[$orig] = $objTask->getDependencies();
         $destTask = $objTask->copy($this->project_id, 0);
         $nid2op[$destTask->task_id] = $oldParent;
         $tasks[$orig] = $destTask;
         $taskXref[$orig] = (int) $destTask->task_id;
     }
     // Build new dependencies array
     foreach ($deps as $odkey => $od) {
         $ndt = '';
         $ndkey = $taskXref[$odkey];
         $odep = explode(',', $od);
         foreach ($odep as $odt) {
             $ndt = $ndt . $taskXref[$odt] . ',';
         }
         $ndt = rtrim($ndt, ',');
         $newDeps[$ndkey] = $ndt;
     }
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $this->project_id);
     $tasks = $q->loadColumn();
     // Update dates based on new project's start date.
     $origDate = new CDate($origProject->project_start_date);
     $origStartHour = new CDate($this->project_start_date);
     $destDate = new CDate($this->project_start_date);
     foreach ($tasks as $task_id) {
         $newTask = new CTask();
         $newTask->load($task_id);
         if (in_array($task_id, $taskXref)) {
             $task_date_vars = array('task_start_date', 'task_end_date');
             //Adjust task dates based on calculated offsets
             foreach ($task_date_vars as $my_date) {
                 if (!empty($newTask->{$my_date}) && $newTask->{$my_date} != '0000-00-00 00:00:00') {
                     $origDate->setDate($newTask->{$my_date});
                     $origStartHour->setDate($newTask->{$my_date});
                     $origStartHour->setTime(intval(dPgetConfig('cal_day_start')));
                     $destDate->setDate($newTask->{$my_date});
                     $destDate->addDays($dateOffset);
                     if ($scale_project) {
                         $offsetAdd = round($origDate->dateDiff($origStartDate) * $ratio) - $origDate->dateDiff($origStartDate);
                         $destDate->addDays($offsetAdd);
                         $hours_in = $origStartHour->calcDuration($origDate);
                         $offsetAddHours = round($hours_in * $ratio) - $hours_in;
                         if ($offsetAddHours % dPgetConfig('daily_working_hours')) {
                             $destDate->addDuration($offsetAddHours);
                         }
                     }
                     $destDate = $destDate->next_working_day();
                     $newTask->{$my_date} = $destDate->format(FMT_DATETIME_MYSQL);
                 }
             }
             //Adjust durration to scale
             if ($scale_project) {
                 $newTask->task_duration = round($newTask->task_duration * $ratio, 2);
             }
             $newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]];
             $newTask->store();
             $newTask->updateDependencies($newDeps[$task_id]);
         }
         // end check if imported task
         $newTask->store();
     }
     // end Fix record integrity
 }
Exemplo n.º 2
0
    if ($hours > 0) {
        $allpdfdata[$company_name] = $pdfdata;
        echo $table;
        echo '<tr><td>Total</td><td>' . round($hours, 2) . '</td></tr></table>';
    }
    return $hours;
}
if ($do_report) {
    $total = 0;
    $q = new DBQuery();
    $q->addTable('companies');
    $q->addQuery('company_id');
    if (!$fullaccess) {
        $q->addWhere("company_owner='" . $AppUI->user_id . "'");
    }
    $companies = $q->loadColumn();
    if (!empty($companies)) {
        foreach ($companies as $company) {
            $total += showcompany($company);
        }
    } else {
        $q->addTable('companies');
        $q->addQuery('company_id');
        foreach ($q->loadColumn() as $company) {
            $total += showcompany($company, true);
        }
    }
    echo '<h2>' . $AppUI->_('Total Hours') . ":";
    printf("%.2f", $total);
    echo '</h2>';
    if ($log_pdf) {
Exemplo n.º 3
0
function getReadableModule()
{
    global $AppUI;
    $perms =& $AppUI->acl();
    $q = new DBQuery();
    $q->addTable('modules');
    $q->addQuery('mod_directory');
    $q->addWhere('mod_active = 1');
    $q->addOrder('mod_ui_order');
    $modules = $q->loadColumn();
    foreach ($modules as $mod) {
        if ($perms->checkModule($mod, 'access')) {
            return $mod;
        }
    }
    return null;
}
function projects_list_data($user_id = false)
{
    global $AppUI, $addPwOiD, $buffer, $company, $company_id, $company_prefix, $deny, $department, $dept_ids, $dPconfig, $orderby, $orderdir, $projects, $tasks_critical, $tasks_problems, $tasks_sum, $tasks_summy, $tasks_total, $owner;
    $addProjectsWithAssignedTasks = $AppUI->getState('addProjWithTasks') ? $AppUI->getState('addProjWithTasks') : 0;
    // get any records denied from viewing
    $obj = new CProject();
    $deny = $obj->getDeniedRecords($AppUI->user_id);
    // Let's delete temproary tables
    $q = new DBQuery();
    $q->dropTemp('tasks_sum, tasks_total, tasks_summy, tasks_critical, tasks_problems, tasks_users');
    $q->exec();
    $q->clear();
    // Task sum table
    // by Pablo Roca (pabloroca@mvps.org)
    // 16 August 2003
    $working_hours = $dPconfig['daily_working_hours'] ? $dPconfig['daily_working_hours'] : 8;
    // GJB: Note that we have to special case duration type 24 and this refers to the hours in a day, NOT 24 hours
    $q->createTemp('tasks_sum');
    $q->addTable('tasks');
    $q->addQuery("task_project, 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, SUM(task_duration * IF(task_duration_type = 24," . " {$working_hours}, task_duration_type)) AS project_duration");
    if ($user_id) {
        $q->addJoin('user_tasks', 'ut', 'ut.task_id = tasks.task_id');
        $q->addWhere('ut.user_id = ' . $user_id);
    }
    $q->addWhere("tasks.task_id = tasks.task_parent");
    $q->addGroup('task_project');
    $tasks_sum = $q->exec();
    $q->clear();
    // Task total table
    $q->createTemp('tasks_total');
    $q->addTable('tasks');
    $q->addQuery("task_project, COUNT(distinct tasks.task_id) AS total_tasks");
    if ($user_id) {
        $q->addJoin('user_tasks', 'ut', 'ut.task_id = tasks.task_id');
        $q->addWhere('ut.user_id = ' . $user_id);
    }
    $q->addGroup('task_project');
    $tasks_total = $q->exec();
    $q->clear();
    // temporary My Tasks
    // by Pablo Roca (pabloroca@mvps.org)
    // 16 August 2003
    $q->createTemp('tasks_summy');
    $q->addTable('tasks');
    $q->addQuery('task_project, COUNT(distinct task_id) AS my_tasks');
    if ($user_id) {
        $q->addWhere('task_owner = ' . $user_id);
    } else {
        $q->addWhere('task_owner = ' . $AppUI->user_id);
    }
    $q->addGroup('task_project');
    $tasks_summy = $q->exec();
    $q->clear();
    // temporary critical tasks
    $q->createTemp('tasks_critical');
    $q->addTable('tasks');
    $q->addQuery('task_project, task_id AS critical_task, MAX(task_end_date) AS project_actual_end_date');
    $q->addJoin('projects', 'p', 'p.project_id = task_project');
    $q->addOrder("task_end_date DESC");
    $q->addGroup('task_project');
    $tasks_critical = $q->exec();
    $q->clear();
    // temporary task problem logs
    $q->createTemp('tasks_problems');
    $q->addTable('tasks');
    $q->addQuery('task_project, task_log_problem');
    $q->addJoin('task_log', 'tl', 'tl.task_log_task = task_id');
    $q->addWhere("task_log_problem > '0'");
    $q->addGroup('task_project');
    $tasks_problems = $q->exec();
    $q->clear();
    if ($addProjectsWithAssignedTasks) {
        // temporary users tasks
        $q->createTemp('tasks_users');
        $q->addTable('tasks');
        $q->addQuery('task_project');
        $q->addQuery('ut.user_id');
        $q->addJoin('user_tasks', 'ut', 'ut.task_id = tasks.task_id');
        if ($user_id) {
            $q->addWhere('ut.user_id = ' . $user_id);
        }
        $q->addOrder("task_end_date DESC");
        $q->addGroup('task_project');
        $tasks_users = $q->exec();
        $q->clear();
    }
    // add Projects where the Project Owner is in the given department
    if ($addPwOiD && isset($department)) {
        $owner_ids = array();
        $q->addTable('users');
        $q->addQuery('user_id');
        $q->addJoin('contacts', 'c', 'c.contact_id = user_contact');
        $q->addWhere('c.contact_department = ' . $department);
        $owner_ids = $q->loadColumn();
        $q->clear();
    }
    if (isset($department)) {
        //If a department is specified, we want to display projects from the department, and all departments under that, so we need to build that list of departments
        $dept_ids = array();
        $q->addTable('departments');
        $q->addQuery('dept_id, dept_parent');
        $q->addOrder('dept_parent,dept_name');
        $rows = $q->loadList();
        addDeptId($rows, $department);
        $dept_ids[] = $department;
    }
    $q->clear();
    // retrieve list of records
    // modified for speed
    // by Pablo Roca (pabloroca@mvps.org)
    // 16 August 2003
    // get the list of permitted companies
    $obj = new CCompany();
    $companies = $obj->getAllowedRecords($AppUI->user_id, 'company_id,company_name', 'company_name');
    if (count($companies) == 0) {
        $companies = array(0);
    }
    $q->addTable('projects');
    $q->addQuery('projects.project_id, project_status, project_color_identifier, project_name, project_description, project_duration,
		project_start_date, project_end_date, project_color_identifier, project_company, company_name, company_description, project_status,
		project_priority, tc.critical_task, tc.project_actual_end_date, tp.task_log_problem, tt.total_tasks, tsy.my_tasks,
		ts.project_percent_complete, user_username');
    $q->addJoin('companies', 'com', 'projects.project_company = company_id');
    $q->addJoin('users', 'u', 'projects.project_owner = u.user_id');
    $q->addJoin('tasks_critical', 'tc', 'projects.project_id = tc.task_project');
    $q->addJoin('tasks_problems', 'tp', 'projects.project_id = tp.task_project');
    $q->addJoin('tasks_sum', 'ts', 'projects.project_id = ts.task_project');
    $q->addJoin('tasks_total', 'tt', 'projects.project_id = tt.task_project');
    $q->addJoin('tasks_summy', 'tsy', 'projects.project_id = tsy.task_project');
    if ($addProjectsWithAssignedTasks) {
        $q->addJoin('tasks_users', 'tu', 'projects.project_id = tu.task_project');
    }
    // DO we have to include the above DENY WHERE restriction, too?
    //$q->addJoin('', '', '');
    if (isset($department)) {
        $q->addJoin('project_departments', 'pd', 'pd.project_id = projects.project_id');
    }
    if (!isset($department) && $company_id && !$addPwOiD) {
        $q->addWhere("projects.project_company = '{$company_id}'");
    }
    if (isset($department) && !$addPwOiD) {
        $q->addWhere("pd.department_id in ( " . implode(',', $dept_ids) . " )");
    }
    if ($user_id && $addProjectsWithAssignedTasks) {
        $q->addWhere('(tu.user_id = ' . $user_id . ' OR projects.project_owner = ' . $user_id . ' )');
    } elseif ($user_id) {
        $q->addWhere('projects.project_owner = ' . $user_id);
    }
    if ($owner > 0) {
        $q->addWhere('projects.project_owner = ' . $owner);
    }
    // Show Projects where the Project Owner is in the given department
    if ($addPwOiD && !empty($owner_ids)) {
        $q->addWhere('projects.project_owner IN (' . implode(',', $owner_ids) . ')');
    }
    $q->addGroup('projects.project_id');
    $q->addOrder("{$orderby} {$orderdir}");
    $obj->setAllowedSQL($AppUI->user_id, $q);
    $projects = $q->loadList();
    // get the list of permitted companies
    $companies = arrayMerge(array('0' => $AppUI->_('All')), $companies);
    //get list of all departments, filtered by the list of permitted companies.
    $q->clear();
    $q->addTable('companies');
    $q->addQuery('company_id, company_name, dep.*');
    $q->addJoin('departments', 'dep', 'companies.company_id = dep.dept_company');
    $q->addOrder('company_name,dept_parent,dept_name');
    $obj->setAllowedSQL($AppUI->user_id, $q);
    $rows = $q->loadList();
    //display the select list
    $buffer = '<select name="department" onChange="document.pickCompany.submit()" class="text">';
    $buffer .= '<option value="company_0" style="font-weight:bold;">' . $AppUI->_('All') . '</option>' . "\n";
    $company = '';
    foreach ($rows as $row) {
        if ($row["dept_parent"] == 0) {
            if ($company != $row['company_id']) {
                $buffer .= '<option value="' . $company_prefix . $row['company_id'] . '" style="font-weight:bold;"' . ($company_id == $row['company_id'] ? 'selected="selected"' : '') . '>' . $row['company_name'] . '</option>' . "\n";
                $company = $row['company_id'];
            }
            if ($row["dept_parent"] != null) {
                showchilddept($row);
                findchilddept($rows, $row["dept_id"]);
            }
        }
    }
    $buffer .= '</select>';
}
Exemplo n.º 5
0
$q->addTable('history', 'h');
$q->leftJoin('users', 'u', 'u.user_id = h.history_user');
$q->addQuery('h.*, u.*');
if ($in_filter) {
    $filter .= ($filter ? ' AND ' : '') . "(h.`history_table` LIKE '" . $in_filter . "%')";
}
if ($denied_tables) {
    $filter .= ($filter ? ' AND ' : '') . "(NOT h.`history_table` IN ('" . $denied_tables . "'))";
}
if (!empty($_REQUEST['project_id'])) {
    $project_id = $_REQUEST['project_id'];
    $r = new DBQuery();
    $r->addTable('tasks');
    $r->addQuery('task_id');
    $r->addWhere('task_project = ' . $project_id);
    $project_tasks = implode(',', $r->loadColumn());
    $r->clear();
    $r->addTable('files');
    $r->addQuery('file_id');
    $r->addWhere('file_project = ' . $project_id);
    $project_files = implode(',', $r->loadColumn());
    $r->clear();
    if (!empty($project_tasks)) {
        $project_tasks = " OR (history_table = 'tasks' AND history_item IN ({$project_tasks})) ";
    }
    if (!empty($project_files)) {
        $project_files = " OR (history_table = 'files' AND history_item IN ({$project_files})) ";
    }
    $filter .= ($filter ? ' AND ' : '') . ("((history_table = 'projects' AND history_item = " . $project_id . ')' . $project_tasks . $project_files . ')');
}
if ($filter) {
Exemplo n.º 6
0
// Remove any empty elements
$contacts_id = remove_invalid(explode(',', $selected_contacts_id));
$selected_contacts_id = implode(',', $contacts_id);
require_once $AppUI->getModuleClass('companies');
$oCpy = new CCompany();
$aCpies = $oCpy->getAllowedRecords($AppUI->user_id, 'company_id, company_name', 'company_name');
$aCpies_esc = array();
foreach ($aCpies as $key => $company) {
    $aCpies_esc[$key] = db_escape($company);
}
$q = new DBQuery();
if (mb_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 (mb_substr($where, 0, 1) == ',' && $where != ',') {
        $where = '0' . $where;
    } else {
        if ($where == ',') {
            $where = '0';
        }
    }
    $where = $where ? 'contact_company IN(' . $where . ')' : '';
} else {
    if (!$company_id) {
        //  Contacts from all allowed companies
        $where = "contact_company = ''" . " OR (contact_company IN ('" . implode('\',\'', array_values($aCpies_esc)) . "'))" . " OR (contact_company IN ('" . implode('\',\'', array_keys($aCpies_esc)) . "'))";
        $company_name = $AppUI->_('Allowed Companies');
    } else {
Exemplo n.º 7
0
 /**
  * Tests importing tasks from one project to another
  */
 public function testImportTasks()
 {
     $this->obj->load(2);
     $this->obj->importTasks(1);
     $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 DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_created');
     $q->addWhere('task_project = 2');
     $results = $q->loadColumn();
     foreach ($results as $created) {
         $this->assertGreaterThanOrEqual($min_time, strtotime($created));
         $this->assertLessThanOrEqual($now_secs, strtotime($created));
     }
     /**
      * Get updated dates to test against
      */
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_updated');
     $q->addWhere('task_project = 2');
     $results = $q->loadColumn();
     foreach ($results as $updated) {
         $this->assertGreaterThanOrEqual($min_time, strtotime($updated));
         $this->assertLessThanOrEqual($now_secs, strtotime($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'));
 }
Exemplo n.º 8
0
    $tree = new CDpTree();
    $columns = array('<b>' . $AppUI->_('Task Name') . '</b>', '<b>' . $AppUI->_('Task Description') . '</b>', '<b>' . $AppUI->_('Assigned To') . '</b>', '<b>' . $AppUI->_('Task Start Date') . '</b>', '<b>' . $AppUI->_('Task End Date') . '</b>', '<b>' . $AppUI->_('Completion') . '</b>');
    if ($project_id == 0) {
        array_unshift($columns, '<b>' . $AppUI->_('Project Name') . '</b>');
    }
    while ($Tasks = db_fetch_assoc($Task_List)) {
        $Tasks['start_date'] = intval($Tasks['task_start_date']) ? new CDate($Tasks['task_start_date']) : ' ';
        $Tasks['end_date'] = intval($Tasks['task_end_date']) ? new CDate($Tasks['task_end_date']) : ' ';
        $task_id = $Tasks['task_id'];
        $q = new DBQuery();
        $q->addQuery("CONCAT_WS(' ', c.contact_first_name, c.contact_last_name)" . ' as contact_name');
        $q->addTable('user_tasks', 'ut');
        $q->leftJoin('users', 'u', 'u.user_id = ut.user_id');
        $q->leftJoin('contacts', 'c', 'c.contact_id = u.user_contact');
        $q->addWhere('ut.task_id = ' . $task_id);
        $sql_user = $q->loadColumn();
        $Tasks['users'] = implode(', ', $sql_user);
        $tree->add($Tasks['task_parent'], $task_id, $Tasks);
        unset($Tasks);
    }
    // Now show the tasks as HTML
    $tree->display('show_task_as_html');
    ?>
</table>

<?php 
    if ($log_pdf) {
        // make the PDF file
        $pdfdata = array();
        $tree->display('collate_pdf_task');
        $q = new DBQuery();
Exemplo n.º 9
0
</th>
	</tr>

<?php 
    if (count($user_list)) {
        $percentage_sum = $hours_allocated_sum = $hours_worked_sum = 0;
        $sum_total_hours_allocated = $sum_total_hours_worked = 0;
        $sum_hours_allocated_complete = $sum_hours_worked_complete = 0;
        //TODO: Split times for which more than one users were working...
        $q = new DBQuery();
        foreach ($user_list as $user_id => $user) {
            $q->clear();
            $q->addTable('user_tasks');
            $q->addQuery('task_id');
            $q->addWhere('user_id = ' . (int) $user_id);
            $tasks_id = $q->loadColumn();
            $total_hours_allocated = $total_hours_worked = 0;
            $hours_allocated_complete = $hours_worked_complete = 0;
            foreach ($tasks_id as $task_id) {
                if (isset($task_list[$task_id])) {
                    // Now let's figure out how many time did the user spent in this task
                    $q->clear();
                    $q->addTable('task_log');
                    $q->addQuery('sum(task_log_hours)');
                    $q->addWhere('task_log_task = ' . (int) $task_id);
                    $q->addWhere('task_log_creator = ' . (int) $user_id);
                    $hours_worked = round($q->loadResult(), 2);
                    $q->clear();
                    $q->addTable('tasks');
                    $q->addQuery('task_percent_complete');
                    $q->addWhere('task_id = ' . (int) $task_id);
Exemplo n.º 10
0
 public static function getUserDeptId($user_id)
 {
     $q = new DBQuery();
     $q->addQuery('con.contact_department');
     $q->addTable('users', 'u');
     $q->addJoin('contacts', 'con', 'user_contact = contact_id', 'inner');
     $q->addWhere('u.user_id = ' . (int) $user_id);
     $user_dept = $q->loadColumn();
     $q->clear();
     return $user_dept;
 }
Exemplo n.º 11
0
 function getAllowedItems($module, $uid = null)
 {
     // Checking in dotpermissions..
     // Is getAllowedItems operation-independent???
     $items = array();
     if (!$uid) {
         $uid = $GLOBALS['AppUI']->user_id;
     }
     // Bug found by Anne (dotproject forum) -- Changed from "allow=0" to "allow!=0"
     $q = new DBQuery();
     $q->addQuery('distinct axo');
     $q->addTable('dotpermissions');
     $q->addWhere("allow!=0 AND user_id={$uid} AND section='{$module}' AND enabled=1");
     $items = $q->loadColumn();
     dprint(__FILE__, __LINE__, 2, "getAllowedItems({$module}, {$uid}) returning " . count($items) . ' items');
     return $items;
 }
Exemplo n.º 12
0
 /**
  *	Overload of the w2PObject::getDeniedRecords
  *	to ensure that the projects owned by denied companies are denied.
  *
  *	@author	handco <*****@*****.**>
  *	@see	w2PObject::getAllowedRecords
  */
 public function getDeniedRecords($uid)
 {
     $aBuf1 = parent::getDeniedRecords($uid);
     $oCpy = new CCompany();
     // Retrieve which projects are allowed due to the company rules
     $aCpiesAllowed = $oCpy->getAllowedRecords($uid, 'company_id,company_name');
     //Department permissions
     $oDpt = new CDepartment();
     $aDptsAllowed = $oDpt->getAllowedRecords($uid, 'dept_id,dept_name');
     $q = new DBQuery();
     $q->addTable('projects');
     $q->addQuery('projects.project_id');
     $q->addJoin('project_departments', 'pd', 'pd.project_id = projects.project_id');
     if (count($aCpiesAllowed)) {
         if (array_search('0', $aCpiesAllowed) === false) {
             //If 0 (All Items of a module) are not permited then just add the allowed items only
             $q->addWhere('NOT (project_company IN (' . implode(',', array_keys($aCpiesAllowed)) . '))');
         } else {
             //If 0 (All Items of a module) are permited then don't add a where clause so the user is permitted to see all
         }
     } else {
         //if the user is not allowed any company then lets shut him off
         $q->addWhere('0=1');
     }
     if (count($aDptsAllowed)) {
         if (array_search('0', $aDptsAllowed) === false) {
             //If 0 (All Items of a module) are not permited then just add the allowed items only
             $q->addWhere('NOT (department_id IN (' . implode(',', array_keys($aDptsAllowed)) . '))');
         } else {
             //If 0 (All Items of a module) are permited then don't add a where clause so the user is permitted to see all
             $q->addWhere('NOT (department_id IS NULL)');
         }
     } else {
         //If 0 (All Items of a module) are permited then don't add a where clause so the user is permitted to see all
         $q->addWhere('NOT (department_id IS NULL)');
     }
     $aBuf2 = $q->loadColumn();
     $q->clear();
     return array_merge($aBuf1, $aBuf2);
 }
Exemplo n.º 13
0
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool	
  **/
 function importTasks($from_project_id)
 {
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $from_project_id);
     $sql = $q->prepare();
     $q->clear();
     $tasks = array_flip(db_loadColumn($sql));
     $origDate = new CDate($origProject->project_start_date);
     $destDate = new CDate($this->project_start_date);
     $dateOffset = $destDate->dateDiff($origDate);
     // Old dependencies array from imported tasks
     $deps = array();
     // New dependencies array for new copies of imported tasks
     $newDeps = array();
     // Old2New task ID array
     $taskXref = array();
     // New task ID to old parent array
     $nid2op = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         // Grab the old parent id
         $oldParent = (int) $objTask->task_parent;
         $deps[$orig] = $objTask->getDependencies();
         $destTask = $objTask->copy($this->project_id, 0);
         $nid2op[$destTask->task_id] = $oldParent;
         $tasks[$orig] = $destTask;
         $taskXref[$orig] = (int) $destTask->task_id;
     }
     // Build new dependencies array
     foreach ($deps as $odkey => $od) {
         $ndt = '';
         $ndkey = $taskXref[$odkey];
         $odep = explode(',', $od);
         foreach ($odep as $odt) {
             $ndt = $ndt . $taskXref[$odt] . ',';
         }
         $ndt = rtrim($ndt, ',');
         $newDeps[$ndkey] = $ndt;
     }
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $this->project_id);
     $tasks = $q->loadColumn();
     // Update dates based on new project's start date.
     foreach ($tasks as $task_id) {
         $newTask = new CTask();
         $newTask->load($task_id);
         if (in_array($task_id, $taskXref)) {
             // Fix task start date from project start date offset
             $origDate->setDate($newTask->task_start_date);
             $destDate->setDate($newTask->task_start_date);
             $destDate->addDays($dateOffset);
             $destDate = $destDate->next_working_day();
             $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
             // Fix task end date from start date + work duration
             //$newTask->calc_task_end_date();
             if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') {
                 $origDate->setDate($newTask->task_end_date);
                 $destDate->setDate($newTask->task_end_date);
                 $destDate->addDays($dateOffset);
                 $destDate = $destDate->next_working_day();
                 $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL);
             }
             $newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]];
             $newTask->store();
             $newTask->updateDependencies($newDeps[$task_id]);
         }
         // end check if imported task
         $newTask->store();
     }
     // end Fix record integrity
 }
Exemplo n.º 14
0
     // Now add any task reminders
     // If there wasn't a task, but there is one now, and
     // that task date is set, we need to set a reminder.
     if (empty($task_end_date) || !empty($end_date) && $task_end_date->dateDiff($end_date)) {
         $obj->addReminder();
     }
     // If there was a file that was attached to both the task, and the task
     // has moved projects, we need to move the file as well
     if ($move_files) {
         require_once $AppUI->getModuleClass('files');
         $filehandler = new CFile();
         $q = new DBQuery();
         $q->addTable('files', 'f');
         $q->addQuery('file_id');
         $q->addWhere('file_task = ' . (int) $obj->task_id);
         $files = $q->loadColumn();
         if (!empty($files)) {
             foreach ($files as $file) {
                 $filehandler->load($file);
                 $realname = $filehandler->file_real_filename;
                 $filehandler->file_project = $obj->task_project;
                 $filehandler->moveFile($move_files, $realname);
                 $filehandler->store();
             }
         }
     }
     $AppUI->setMsg($task_id ? 'Task updated' : 'Task added', UI_MSG_OK);
 }
 if (isset($hassign)) {
     $obj->updateAssigned($hassign, $hperc_assign_ar);
 }
Exemplo n.º 15
0
 /**
  * This function recursively updates all tasks project
  * to the one passed as parameter
  */
 public function updateSubTasksProject($new_project, $task_id = null)
 {
     $q = new DBQuery();
     if (is_null($task_id)) {
         $task_id = $this->task_id;
     }
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_parent = ' . (int) $task_id);
     $tasks_id = $q->loadColumn();
     $q->clear();
     if (count($tasks_id) == 0) {
         return true;
     }
     // update project of children
     $q->addTable('tasks');
     $q->addUpdate('task_project', $new_project);
     $q->addWhere('task_parent = ' . (int) $task_id);
     $q->exec();
     $q->clear();
     foreach ($tasks_id as $id) {
         if ($id != $task_id) {
             $this->updateSubTasksProject($new_project, $id);
         }
     }
 }
Exemplo n.º 16
0
 function checkClash($userlist = null)
 {
     global $AppUI;
     require_once $AppUI->getModuleClass('projects');
     if (!isset($userlist)) {
         return false;
     }
     $users = explode(',', $userlist);
     if (!count($users)) {
         return false;
     }
     $users = array_unique($users);
     $start_date = new CDate($this->event_start_date);
     $end_date = new CDate($this->event_end_date);
     $concurrent_events = array();
     $concurrent_events = $this->getEventsForPeriod($start_date, $end_date);
     if (!count($concurrent_events)) {
         return false;
     }
     $events = array();
     foreach ($concurrent_events as $event_rec) {
         $events[] = $event_rec['event_id'];
     }
     $events = array_unique($events);
     // Now build a query to find clashing events based on events fetched for time period
     // (the ones we're allowed to see anyway) and the users assigned to this event.
     $q = new DBQuery();
     $q->addTable('user_events', 'ue');
     $q->addQuery('ue.user_id');
     $q->addWhere('ue.event_id IN (' . implode(',', $events) . ')');
     if ($this->event_id) {
         $q->addWhere('NOT(ue.event_id = ' . $this->event_id . ')');
     }
     $clashes = $q->loadColumn();
     $q->clear();
     $clash = array_unique($clashes);
     if (count($clash)) {
         $q->addTable('users', 'u');
         $q->addJoin('contacts', 'con', 'con.contact_id = u.user_contact');
         $q->addQuery('u.user_id, CONCAT_WS(" ", con.contact_first_name, con.contact_last_name)' . ' AS user_name');
         $q->addWhere("user_id in (" . implode(",", $clash) . ")");
         return $q->loadHashList();
     } else {
         return false;
     }
 }
Exemplo n.º 17
0
$titleBlock->addCrumb("?m=projects", "projects list");
if ($project_id != 0) {
    $titleBlock->addCrumb("?m=projects&a=view&project_id={$project_id}", "view this project");
    //GT
    $titleBlock->addCrumb("?m=projects&a=edit_tasks&project_id={$project_id}", "organize tasks");
}
$titleBlock->show();
//Build display list for departments
$company_id = $row->project_company;
$selected_departments = array();
if ($project_id) {
    $q =& new DBQuery();
    $q->addTable('project_departments');
    $q->addQuery('department_id');
    $q->addWhere('project_id = ' . $project_id);
    $selected_departments = $q->loadColumn();
}
$departments_count = 0;
$department_selection_list = getDepartmentSelectionList($company_id, $selected_departments);
if ($department_selection_list != '' || $project_id) {
    $department_selection_list = $AppUI->_('Departments') . "<br />\n" . '<select name="dept_ids[]" class="text">' . "\n" . '<option value="0"></option>' . "\n" . $department_selection_list . "\n" . '</select>';
} else {
    $department_selection_list = '<input type="button" class="button" value="' . $AppUI->_('Select department...') . '" onclick="javascript:popDepartment();" />' . '<input type="hidden" name="project_departments"';
}
// Get contacts list
$selected_contacts = array();
if ($project_id) {
    $q =& new DBQuery();
    $q->addTable('project_contacts');
    $q->addQuery('contact_id');
    $q->addWhere('project_id = ' . $project_id);
Exemplo n.º 18
0
 /**
  * Tests updating dynamic task when from children = false, in hours
  */
 public function testUpdateDynamicsNotFromChildrenInHours()
 {
     $this->obj->load(25);
     $this->obj->updateDynamics(false);
     $this->obj->load(24);
     $now_secs = time();
     $min_time = $now_secs - 10;
     $this->assertEquals(24, $this->obj->task_id);
     $this->assertEquals('Task 24', $this->obj->task_name);
     $this->assertEquals(24, $this->obj->task_parent);
     $this->assertEquals(0, $this->obj->task_milestone);
     $this->assertEquals(1, $this->obj->task_project);
     $this->assertEquals(1, $this->obj->task_owner);
     $this->assertEquals('2009-09-09 00:00:00', $this->obj->task_start_date);
     $this->assertEquals(64, $this->obj->task_duration);
     $this->assertEquals(1, $this->obj->task_duration_type);
     $this->assertEquals(37, $this->obj->task_hours_worked);
     $this->assertEquals('2009-11-02 00:00:00', $this->obj->task_end_date);
     $this->assertEquals(0, $this->obj->task_status);
     $this->assertEquals(0, $this->obj->task_priority);
     $this->assertEquals(41, $this->obj->task_percent_complete);
     $this->assertEquals('This is task 24', $this->obj->task_description);
     $this->assertEquals(0.0, $this->obj->task_target_budget);
     $this->assertEquals('', $this->obj->task_related_url);
     $this->assertEquals(1, $this->obj->task_creator);
     $this->assertEquals(1, $this->obj->task_order);
     $this->assertEquals(1, $this->obj->task_client_publish);
     $this->assertEquals(1, $this->obj->task_dynamic);
     $this->assertEquals(1, $this->obj->task_access);
     $this->assertEquals(1, $this->obj->task_notify);
     $this->assertEquals('', $this->obj->task_departments);
     $this->assertEquals('', $this->obj->task_contacts);
     $this->assertEquals('', $this->obj->task_custom);
     $this->assertEquals(1, $this->obj->task_type);
     $this->assertEquals(1, $this->obj->task_updator);
     $this->assertEquals('2009-07-06 15:43:00', $this->obj->task_created);
     $xml_file_dataset = $this->createXMLDataSet($this->getDataSetPath() . 'tasksTestUpdateDynamicsNotFromChildrenInHours.xml');
     $xml_file_filtered_dataset = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($xml_file_dataset, array('tasks' => array('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_updated')));
     $this->assertTablesEqual($xml_file_filtered_dataset->getTable('tasks'), $xml_db_filtered_dataset->getTable('tasks'));
     /**
      * Get updated dates to test against
      */
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_updated');
     $q->addWhere('task_id = 24');
     $results = $q->loadColumn();
     foreach ($results as $updated) {
         $this->assertGreaterThanOrEqual($min_time, strtotime($updated));
         $this->assertLessThanOrEqual($now_secs, strtotime($updated));
     }
 }
Exemplo n.º 19
0
$projectStatus = arrayMerge(array('-2' => $AppUI->_('All w/o in progress'), '-3' => $AppUI->_($AppUI->user_id == $user_id ? 'My projects' : "User's projects")), $projectStatus);
$pjobj =& new CProject();
$working_hours = $dPconfig['daily_working_hours'];
$q = new DBQuery();
/* 
 * Load department info for the case where one
 * wants to see the ProjectsWithOwnerInDeparment (PwOiD)
 * instead of the projects related to the given department.
 */
$owner_ids = array();
if ($addPwOiD && $department > 0) {
    $q->addTable('users');
    $q->addQuery('user_id');
    $q->addJoin('contacts', 'c', 'c.contact_id = user_contact');
    $q->addWhere('c.contact_department = ' . $department);
    $owner_ids = $q->loadColumn();
    $q->clear();
}
// pull valid projects and their percent complete information
// GJB: Note that we have to special case duration type 24 and this refers to the hours in a day, NOT 24 hours
$q->addTable('projects', 'p');
$q->addQuery('DISTINCT p.project_id, project_color_identifier, project_name, project_start_date' . ', project_end_date, max(t1.task_end_date) AS project_actual_end_date' . ', 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' . ', project_status');
$q->addJoin('tasks', 't1', 'p.project_id = t1.task_project');
$q->addJoin('companies', 'c1', 'p.project_company = c1.company_id');
if ($department > 0) {
    $q->addJoin('project_departments', 'pd', 'pd.project_id = p.project_id');
    if (!$addPwOiD) {
        $q->addWhere('pd.department_id = ' . $department);
    } else {
        // Show Projects where the Project Owner is in the given department
        $q->addWhere('p.project_owner IN (' . (!empty($owner_ids) ? implode(',', $owner_ids) : 0) . ')');
Exemplo n.º 20
0
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool	
  **/
 function importTasks($from_project_id)
 {
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $from_project_id);
     $q->addWhere('task_id = task_parent');
     $sql = $q->prepare();
     $q->clear();
     $tasks = array_flip(db_loadColumn($sql));
     $origDate = new CDate($origProject->project_start_date);
     $destDate = new CDate($this->project_start_date);
     $timeOffset = $destDate->getTime() - $origDate->getTime();
     // Dependencies array
     $deps = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         $destTask = $objTask->deepCopy($this->project_id);
         $tasks[$orig] = $destTask;
         $deps[$orig] = $objTask->getDependencies();
     }
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $this->project_id);
     $tasks = $q->loadColumn();
     // Update dates based on new project's start date.
     $newTask = new CTask();
     foreach ($tasks as $task_id) {
         $newTask->load($task_id);
         // Fix task start date from project start date offset
         $origDate->setDate($newTask->task_start_date);
         $destDate->setDate($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME);
         $destDate = $destDate->next_working_day();
         $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
         // Fix task end date from start date + work duration
         //$newTask->calc_task_end_date();
         if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') {
             $origDate->setDate($newTask->task_end_date);
             $destDate->setDate($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME);
             $destDate = $destDate->next_working_day();
             $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL);
         }
         $newTask->store();
     }
     // end Fix record integrity
 }