public function add($field_name, $field_description, $field_htmltype, $field_datatype, $field_extratags, $field_order, $field_published, &$error_msg) { global $db; $q = new w2p_Database_Query(); $q->addTable('custom_fields_struct'); $q->addQuery('MAX(field_id)'); $max_id = $q->loadResult(); $next_id = $max_id ? $max_id + 1 : 1; $field_order = $field_order ? $field_order : 1; $field_published = $field_published ? 1 : 0; $field_a = 'addedit'; // TODO - module pages other than addedit // TODO - validation that field_name doesnt already exist $q = new w2p_Database_Query(); $q->addTable('custom_fields_struct'); $q->addInsert('field_id', $next_id); $q->addInsert('field_module', $this->m); $q->addInsert('field_page', $field_a); $q->addInsert('field_htmltype', $field_htmltype); $q->addInsert('field_datatype', $field_datatype); $q->addInsert('field_order', $field_order); $q->addInsert('field_name', $field_name); $q->addInsert('field_description', $field_description); $q->addInsert('field_extratags', $field_extratags); $q->addInsert('field_order', $field_order); $q->addInsert('field_published', $field_published); if (!$q->exec()) { $error_msg = $db->ErrorMsg(); $q->clear(); return 0; } else { $q->clear(); return $next_id; } }
public function write($id, $data) { global $AppUI; $q = new w2p_Database_Query(); $q->addQuery('count(session_id) as row_count'); $q->addTable('sessions'); $q->addWhere('session_id = \'' . $id . '\''); $row_count = (int) $q->loadResult(); $q->clear(); if ($row_count) { $q->addTable('sessions'); $q->addWhere('session_id = \'' . $id . '\''); $q->addUpdate('session_data', $data); if (isset($AppUI)) { $q->addUpdate('session_user', (int) $AppUI->last_insert_id); } } else { $q->addTable('sessions'); $q->addInsert('session_id', $id); $q->addInsert('session_data', $data); $q->addInsert('session_created', $q->dbfnNowWithTZ()); } $q->exec(); $q->clear(); return true; }
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; }
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(); } }
<?php /* $Id$ $URL$ */ if (!defined('W2P_BASE_DIR')) { die('You should not access this file directly.'); } // Output the PDF // make the PDF file if ($project_id != 0) { $q = new w2p_Database_Query(); $q->addTable('projects'); $q->addQuery('project_name'); $q->addWhere('project_id=' . $project_id); $pname = 'Project: ' . $q->loadResult(); } else { $pname = $AppUI->_('All Projects'); } if ($err = db_error()) { $AppUI->setMsg($err, UI_MSG_ERROR); $AppUI->redirect(); } $font_dir = W2P_BASE_DIR . '/lib/ezpdf/fonts'; require $AppUI->getLibraryClass('ezpdf/class.ezpdf'); $pdf = new Cezpdf($paper = 'A4', $orientation = 'landscape'); $pdf->ezSetCmMargins(1, 2, 1.5, 1.5); $pdf->selectFont($font_dir . '/Helvetica.afm'); $pdf->ezText(utf8_decode(w2PgetConfig('company_name')), 12); $date = new w2p_Utilities_Date(); $pdf->ezText("\n" . $date->format($df), 8); $next_week = new w2p_Utilities_Date($date); $next_week->addSpan(new Date_Span(array(7, 0, 0, 0)));
public static function getHolidayTitle($date = 0, $userid = 0) { global $AppUI; self::loadHolidaysSettings(); if (!$date) { $date = new w2p_Utilities_Date(); } if (self::$holiday_manual) { $q = new w2p_Database_Query(); // Check if we have a whitelist item for this date $q->addTable("holiday"); $q->addQuery("holiday_description"); $where = "( date(holiday_start_date) <= '"; $where .= $date->format('%Y-%m-%d'); $where .= "' AND date(holiday_end_date) >= '"; $where .= $date->format('%Y-%m-%d'); if ($userid > 0) { $where .= "' AND ("; $where .= "(holiday_user=0 AND holiday_type=" . HOLIDAY_TYPE_COMPANY_HOLIDAY . ")"; $where .= " OR "; $where .= "(holiday_user="******" AND holiday_type=" . HOLIDAY_TYPE_USER_HOLIDAY . ")"; $where .= ")"; } else { $where .= "' AND holiday_type=" . HOLIDAY_TYPE_COMPANY_HOLIDAY; } $where .= " ) OR ( "; $where .= " DATE_FORMAT(holiday_start_date, '%m-%d') <= '"; $where .= $date->format('%m-%d'); $where .= "' AND DATE_FORMAT(holiday_end_date, '%m-%d') >= '"; $where .= $date->format('%m-%d'); $where .= "' AND holiday_annual=1"; $where .= " AND holiday_type=" . HOLIDAY_TYPE_COMPANY_HOLIDAY . " )"; $q->addWhere($where); $holiday_description = $q->loadResult(); if ($holiday_description !== false) { return $holiday_description; } } if (self::$holiday_auto && self::$holiday_driver >= 0) { // Still here? Ok, lets poll the automatic system if (self::$holiday_driver_instance->getYear() != $date->getYear()) { self::$holiday_driver_instance->setYear($date->getYear()); self::$holiday_driver_instance->setLocale($AppUI->user_locale); } if (!Date_Holidays::isError(self::$holiday_driver_instance)) { $holidays = self::$holiday_driver_instance->getHolidayForDate($date, null, true); if (!is_null($holidays)) { $titles = array(); foreach ($holidays as $holiday) { if (is_null(self::$holiday_filter_instance) || self::$holiday_filter_instance->accept($holiday->getInternalName())) { $title = $holiday->getTitle(); if (!in_array($title, $titles)) { $titles[] = gettype($title) == 'object' ? $title->getMessage() : $title; } } } return implode("/", $titles); } } } return ""; }
function getHelpdeskFolder() { $q = new w2p_Database_Query(); $q->addTable('file_folders', 'ff'); $q->addQuery('file_folder_id'); $q->addWhere('ff.file_folder_name = \'Helpdesk\''); $ffid = $q->loadResult(); $q->clear(); return intval($ffid); }
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); }
foreach ($user_list as $user_id => $user) { $q->addTable('user_tasks', 'ut'); $q->addQuery('task_id'); $q->addWhere('user_id = ' . (int) $user_id); $tasks_id = $q->loadColumn(); $q->clear(); $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->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); $percent = $q->loadColumn(); $q->clear(); $complete = $percent[0] == 100; if ($complete) { $hours_allocated_complete += $task_list[$task_id]['hours_allocated']; $hours_worked_complete += $hours_worked; } $total_hours_allocated += $task_list[$task_id]['hours_allocated']; $total_hours_worked += $hours_worked; } }
function get_actual_end_date_pd($task_id, $task) { global $AppUI; $q = new w2p_Database_Query(); $mods = $AppUI->getActiveModules(); if (!empty($mods['history']) && canView('history')) { $q->addQuery('MAX(history_date) as actual_end_date'); $q->addTable('history'); $q->addWhere('history_table=\'tasks\' AND history_item=' . $task_id); } else { $q->addQuery('MAX(task_log_date) AS actual_end_date'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_id); } $task_log_end_date = $q->loadResult(); $edate = $task_log_end_date; $edate = $edate > $task->task_end_date || $task->task_percent_complete == 100 ? $edate : $task->task_end_date; return $edate; }
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; }
function sendNewPass() { global $AppUI; $_live_site = w2PgetConfig('base_url'); $_sitename = w2PgetConfig('company_name'); // ensure no malicous sql gets past $checkusername = trim(w2PgetParam($_POST, 'checkusername', '')); $checkusername = db_escape($checkusername); $confirmEmail = trim(w2PgetParam($_POST, 'checkemail', '')); $confirmEmail = strtolower(db_escape($confirmEmail)); $q = new w2p_Database_Query(); $q->addTable('users'); $q->addJoin('contacts', 'con', 'user_contact = contact_id', 'inner'); $q->addQuery('user_id'); $q->addWhere('user_username = \'' . $checkusername . '\''); /* Begin Hack */ /* * This is a particularly annoying hack but I don't know of a better * way to resolve #457. In v2.0, there was a refactoring to allow for * muliple contact methods which resulted in the contact_email being * removed from the contacts table. If the user is upgrading from * v1.x and they try to log in before applying the database, crash. * Info: http://bugs.web2project.net/view.php?id=457 */ $qTest = new w2p_Database_Query(); $qTest->addTable('w2pversion'); $qTest->addQuery('max(db_version)'); $dbVersion = $qTest->loadResult(); if ($dbVersion >= 21 && $dbVersion < 26) { $q->leftJoin('contacts_methods', 'cm', 'cm.contact_id = con.contact_id'); $q->addWhere("cm.method_value = '{$confirmEmail}'"); } else { $q->addWhere("LOWER(contact_email) = '{$confirmEmail}'"); } /* End Hack */ if (!($user_id = $q->loadResult()) || !$checkusername || !$confirmEmail) { $AppUI->setMsg('Invalid username or email.', UI_MSG_ERROR); $AppUI->redirect(); } $newpass = makePass(); $message = $AppUI->_('sendpass0', UI_OUTPUT_RAW) . ' ' . $checkusername . ' ' . $AppUI->_('sendpass1', UI_OUTPUT_RAW) . ' ' . $_live_site . ' ' . $AppUI->_('sendpass2', UI_OUTPUT_RAW) . ' ' . $newpass . ' ' . $AppUI->_('sendpass3', UI_OUTPUT_RAW); $subject = $_sitename . ' :: ' . $AppUI->_('sendpass4', UI_OUTPUT_RAW) . ' - ' . $checkusername; $m = new w2p_Utilities_Mail(); // create the mail $m->To($confirmEmail); $m->Subject($subject); $m->Body($message, isset($GLOBALS['locale_char_set']) ? $GLOBALS['locale_char_set'] : ''); // set the body $m->Send(); // send the mail $newpass = md5($newpass); $q->addTable('users'); $q->addUpdate('user_password', $newpass); $q->addWhere('user_id=' . $user_id); $cur = $q->exec(); if (!$cur) { die('SQL error' . $database->stderr(true)); } else { $AppUI->setMsg('New User Password created and emailed to you'); $AppUI->redirect(); } }
$q->clear(); $q->updateArray($sql_table, $pairs, 'contact_id'); $q->clear(); $s .= '<td><span style="color:#880000;">There is a duplicate record for ' . $pairs['contact_first_name'] . ' ' . $pairs['contact_last_name'] . ', the record has been updated.</span></td>'; } else { //If the contact has no name, go to the next if (!mb_trim($pairs['contact_first_name'] . ' ' . $pairs['contact_last_name'])) { continue; } $s .= '<td>Adding ' . $pairs['contact_first_name'] . ' ' . $pairs['contact_last_name'] . '.</td>'; //Try to find a matching company name in the system, if not them set contact_company to 0 $q = new w2p_Database_Query(); $q->addQuery('company_id'); $q->addTable('companies'); $q->addWhere('company_name LIKE \'' . mb_trim($pairs['contact_company']) . '\''); $company_id = $q->loadResult(); $pairs['contact_company'] = $company_id ? $company_id : 0; $q->clear(); //Try to find a matching department name in the system, if not them set contact_department to 0 $q->addQuery('dept_id'); $q->addTable('departments'); $q->addWhere('dept_name LIKE \'' . mb_trim($pairs['contact_department']) . '\''); $dept_id = $q->loadResult(); $pairs['contact_department'] = $dept_id ? $dept_id : 0; $q->clear(); $contact_id = $q->insertArray($sql_table, $pairs); $q->clear(); foreach ($contact_array as $name => $value) { $q->addTable('contacts_methods'); $q->addInsert('contact_id', $contact_id); $q->addInsert('method_name', $name);
// setup the title block $titleBlock = new CTitleBlock('Checkout', 'folder5.png', $m, "{$m}.{$a}"); $titleBlock->addCrumb('?m=files', 'files list'); $titleBlock->show(); if ($obj->file_project) { $file_project = $obj->file_project; } if ($obj->file_task) { $file_task = $obj->file_task; $task_name = $obj->getTaskName(); } elseif ($file_task) { $q = new w2p_Database_Query(); $q->addTable('tasks'); $q->addQuery('task_name'); $q->addWhere('task_id=' . (int) $file_task); $task_name = $q->loadResult(); $q->clear(); } else { $task_name = ''; } $extra = array('where' => 'project_active<>0'); $project = new CProject(); $projects = $project->getAllowedRecords($AppUI->user_id, 'projects.project_id,project_name', 'project_name', null, $extra, 'projects'); $projects = arrayMerge(array('0' => $AppUI->_('All')), $projects); ?> <script language="javascript" type="text/javascript"> function popFile( params ) { fileloader = window.open("fileviewer.php?"+params,"mywindow","location=1,status=1,scrollbars=0,width=80,height=80"); fileloader.moveTo(0,0); }
/* $Id$ $URL$ */ if (!defined('W2P_BASE_DIR')) { die('You should not access this file directly.'); } $perms =& $AppUI->acl(); if (!canEdit('system')) { $AppUI->redirect('m=public&a=access_denied'); } $obj = new CConfig(); // set all checkboxes to false // overwrite the true/enabled/checked checkboxes later $q = new w2p_Database_Query(); $q->addTable('config'); $q->addUpdate('config_value', 'false'); $q->addWhere("config_type = 'checkbox'"); $rs = $q->loadResult(); $q->clear(); foreach ($_POST['w2Pcfg'] as $name => $value) { $obj->config_name = $name; $obj->config_value = $value; // grab the appropriate id for the object in order to ensure // that the db is updated well (config_name must be unique) $obj->config_id = $_POST['w2PcfgId'][$name]; $update = false; // This is really kludgy, but it works.. suggestions? if (strpos($name, '_pass') !== false) { if (1 == $_POST[$name . '_mod']) { $update = true; } } else { $update = true;
$q = new w2p_Database_Query(); $q->addTable('companies'); $q->addQuery('company_name'); $q->addWhere('company_id=' . (int) $company_id); $cname = 'Company: ' . $q->loadResult(); } else { $cname = 'All Companies and All Projects'; } echo db_error(); if ($log_userfilter) { $q = new w2p_Database_Query(); $q->addTable('contacts'); $q->addQuery('CONCAT(contact_first_name, \' \', contact_last_name)'); $q->addJoin('users', '', 'user_contact = contact_id', 'inner'); $q->addWhere('user_id =' . (int) $log_userfilter); $uname = 'User: '******'All Users'; } $font_dir = W2P_BASE_DIR . '/lib/ezpdf/fonts'; $temp_dir = W2P_BASE_DIR . '/files/temp'; $base_url = w2PgetConfig('base_url'); require $AppUI->getLibraryClass('ezpdf/class.ezpdf'); $pdf = new Cezpdf(); $pdf->ezSetCmMargins(1, 2, 1.5, 1.5); $pdf->selectFont($font_dir . '/Helvetica.afm', 'none'); $pdf->ezText(w2PgetConfig('company_name'), 12); // $pdf->ezText( w2PgetConfig( 'company_name' ).' :: '.w2PgetConfig( 'page_title' ), 12 ); $date = new w2p_Utilities_Date(); $pdf->ezText("\n" . $date->format($df), 8); $pdf->selectFont($font_dir . '/Helvetica-Bold.afm');
$table = '<table class="tbl" width="100%" cellspacing="1" cellpadding="2" border="0">'; $table .= '<tr><th colspan="9"><b>Permission Result Table</b></th></tr>'; $table .= '<tr><th>UserID</th><th>User</th><th>User Name</th><th>Module</th><th>Item</th><th>Item Name</th><th>Action</th><th>Allow</th><th>ACL_ID</th></tr>'; foreach ($permissions as $permission) { $item = ''; if ($permission['item_id']) { $q = new w2p_Database_Query(); $q->addTable('modules'); $q->addQuery('permissions_item_field,permissions_item_label'); $q->addWhere('mod_directory = \'' . $permission['module'] . '\''); $field = $q->loadHash(); $q = new w2p_Database_Query(); $q->addTable($permission['module']); $q->addQuery($field['permissions_item_label']); $q->addWhere($field['permissions_item_field'] . ' = \'' . $permission['item_id'] . '\''); $item = $q->loadResult(); } if (!($permission['item_id'] && !$permission['acl_id'])) { $table .= '<tr>' . '<td style="text-align:right;">' . $permission['user_id'] . '</td>' . '<td>' . $permission['user_name'] . '</td>' . '<td>' . $users[$permission['user_id']] . '</td>' . '<td>' . $permission['module'] . '</td>' . '<td style="text-align:right;">' . ($permission['item_id'] ? $permission['item_id'] : '') . '</td>' . '<td>' . ($item ? $item : 'ALL') . '</td>' . '<td>' . $permission['action'] . '</td>' . '<td ' . (!$permission['access'] ? 'style="text-align:right;background-color:red"' : 'style="text-align:right;background-color:green"') . '>' . $permission['access'] . '</td>' . '<td ' . ($permission['acl_id'] ? '' : 'style="background-color:gray"') . '>' . ($permission['acl_id'] ? $permission['acl_id'] : 'soft-denial') . '</td>' . '</tr>'; } } $table .= '</table>'; $users = array('' => '(' . $AppUI->_('Select User') . ')') + $users; $user = isset($_POST['user']) && $_POST['user'] != '' ? $_POST['user'] : $AppUI->user_id; $user_selector = arraySelect($users, 'user', 'class="text" onchange="javascript:document.pickUser.submit()"', $user); $module = isset($_POST['module']) && $_POST['module'] != '' ? $_POST['module'] : ''; $module_selector = arraySelect($modules, 'module', 'class="text" onchange="javascript:document.pickUser.submit()"', $module); $action = isset($_POST['action']) && $_POST['action'] != '' ? $_POST['action'] : ''; $action_selector = arraySelect($actions, 'action', 'class="text" onchange="javascript:document.pickUser.submit()"', $action); echo $AppUI->_('View Users Permissions') . ':<form action="?m=system&a=acls_view" method="post" name="pickUser" accept-charset="utf-8">' . $user_selector . $AppUI->_('View by Module') . ':' . $module_selector . $AppUI->_('View by Action') . ':' . $action_selector . '</form><br />'; echo $table;
function w2PuserHasRole($name) { global $AppUI; $uid = $AppUI->user_id; $q = new w2p_Database_Query(); $q->addTable('roles', 'r'); $q->addTable('user_roles', 'ur'); $q->addQuery('r.role_id'); $q->addWhere('ur.user_id = ' . $uid . ' AND ur.role_id = r.role_id AND r.role_name = \'' . $name . '\''); return $q->loadResult(); }
/** * @param $module * @param $mod_data * * @return Value */ function __extract_from_vw_usr_perms($module, $mod_data) { $q = new w2p_Database_Query(); $q->addTable($module['permissions_item_table']); $q->addQuery($module['permissions_item_label']); $q->addWhere($module['permissions_item_field'] . '=' . $mod_data['value']); $data = $q->loadResult(); return $data; }
} } $users[0]['hours'] += $users[0]['all'][$task['task_id']]['work']; $tasks['hours'] += $users[0]['all'][$task['task_id']]['work']; } } $q = new w2p_Database_Query(); $q->addTable('files'); $q->addQuery('sum(file_size)'); if ($project_id) { $q->addWhere('file_project = ' . (int) $project_id); } else { $q->addWhere('file_project = 0'); } $q->addGroup('file_project'); $files = $q->loadResult(); $q->clear(); $ontime = round(100 * (1 - $tasks['overdue'] / count($all_tasks) - $tasks['completed'] / count($all_tasks))); ?> <table width="100%" border="1" cellpadding="0" cellspacing="0" class="tbl"> <tr> <th colspan="3"><?php echo $AppUI->_('Progress Chart (completed/in progress/pending)'); ?> </th> </tr> <tr> <td width="<?php echo round($tasks['completed'] / count($all_tasks) * 100); ?>
} } else { $type = $a['task_duration_type']; $dur = $a['task_duration']; if ($type == 24) { $dur *= $w2Pconfig['daily_working_hours']; } if ($showWork == '1') { $work_hours = 0; $q = new w2p_Database_Query(); $q->addTable('tasks', 't'); $q->addJoin('user_tasks', 'u', 't.task_id = u.task_id', 'inner'); $q->addQuery('ROUND(SUM(t.task_duration*u.perc_assignment/100),2) AS wh'); $q->addWhere('t.task_duration_type = 24'); $q->addWhere('t.task_id = ' . (int) $a['task_id']); $wh = $q->loadResult(); $work_hours = $wh * $w2Pconfig['daily_working_hours']; $q->clear(); $q->addTable('tasks', 't'); $q->addJoin('user_tasks', 'u', 't.task_id = u.task_id', 'inner'); $q->addQuery('ROUND(SUM(t.task_duration*u.perc_assignment/100),2) AS wh'); $q->addWhere('t.task_duration_type = 1'); $q->addWhere('t.task_id = ' . (int) $a['task_id']); $wh2 = $q->loadResult(); $work_hours += $wh2; $q->clear(); //due to the round above, we don't want to print decimals unless they really exist $dur = $work_hours; } $dur .= ' h'; $enddate = new w2p_Utilities_Date($end);
public function getTotalProjectHours() { global $w2Pconfig; // now milestones are summed up, too, for consistence with the tasks duration sum // the sums have to be rounded to prevent the sum form having many (unwanted) decimals because of the mysql floating point issue // more info on http://www.mysql.com/doc/en/Problems_with_float.html $q = new w2p_Database_Query(); $q->addTable('tasks'); $q->addQuery('ROUND(SUM(task_duration),2)'); $q->addWhere('task_project = ' . (int) $this->project_id . ' AND task_duration_type = 24 AND task_dynamic <> 1'); $days = $q->loadResult(); $q->clear(); $q->addTable('tasks'); $q->addQuery('ROUND(SUM(task_duration),2)'); $q->addWhere('task_project = ' . (int) $this->project_id . ' AND task_duration_type = 1 AND task_dynamic <> 1'); $hours = $q->loadResult(); $total_project_hours = $days * $w2Pconfig['daily_working_hours'] + $hours; return rtrim($total_project_hours, '.'); }
/** * w2Pacl::w2Pacl_check() * //w2Pacl_check is used for modules only * * @param mixed $application it passes 'application' string by default and is not used * @param mixed $op one of the acos 'access','view','add','delete','edit' * @param mixed $user it passes 'user' string by default and is not used * @param mixed $userid it passes the user_id * @param mixed $app it passes 'app' string by default and is not used * @param mixed $module it passes the modules name * @return */ public function w2Pacl_check($application = 'application', $op, $user = '******', $userid, $app = 'app', $module) { global $w2p_performance_acltime, $w2p_performance_aclchecks; $q = new w2p_Database_Query(); $q->addTable($this->_db_acl_prefix . 'permissions'); $q->addQuery('access'); $q->addWhere('module = \'' . $module . '\''); $q->addWhere('action = \'' . $op . '\''); $q->addWhere('item_id = 0'); $q->addWhere('user_id = ' . (int) $userid); $q->addOrder('acl_id DESC'); if (W2P_PERFORMANCE_DEBUG) { $startTime = array_sum(explode(' ', microtime())); } $res = $q->loadResult(); if (W2P_PERFORMANCE_DEBUG) { ++$w2p_performance_aclchecks; $w2p_performance_acltime += array_sum(explode(' ', microtime())) - $startTime; } return $res; }
/** * * @param w2p_Core_CAppUI $AppUI * @param CProject $project_id * * The point of this function is to create/update a task to represent a * subproject. * */ public static function storeTokenTask(w2p_Core_CAppUI $AppUI, $project_id) { $subProject = new CProject(); //TODO: We need to convert this from static to use ->overrideDatabase() for testing. $subProject->load($project_id); if ($subProject->project_parent > 0 && $subProject->project_id != $subProject->project_parent) { $q = new w2p_Database_Query(); $q->addTable('tasks'); $q->addQuery('MIN(task_start_date) AS min_task_start_date'); $q->addQuery('MAX(task_end_date) AS max_task_end_date'); $q->addWhere('task_project = ' . $subProject->project_id); $q->addWhere('task_status <> -1'); $projectDates = $q->loadList(); $q->clear(); $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_represents_project = ' . $subProject->project_id); $task_id = (int) $q->loadResult(); $task = new CTask(); //TODO: We need to convert this from static to use ->overrideDatabase() for testing. if ($task_id) { $task->load($task_id); } else { $task->task_description = $task->task_name; $task->task_priority = $subProject->project_priority; $task->task_project = $subProject->project_parent; $task->task_represents_project = $subProject->project_id; $task->task_owner = $AppUI->user_id; } $task->task_name = $AppUI->_('Subproject') . ': ' . $subProject->project_name; $task->task_duration_type = 1; $task->task_duration = $subProject->project_scheduled_hours; $task->task_start_date = $projectDates[0]['min_task_start_date']; $task->task_end_date = $projectDates[0]['max_task_end_date']; $task->task_percent_complete = $subProject->project_percent_complete; $task->store(); //TODO: we should do something with this store result? } }
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); }
$str .= '</tr>'; echo $str; if ($project_id == 0) { $pdfdata[] = array($Tasks['project_name'], $Tasks['task_name'], $Tasks['task_description'], $users, $start_date != ' ' ? $start_date->format($df) : ' ', $end_date != ' ' ? $end_date->format($df) : ' ', $Tasks['task_percent_complete'] . '%'); } else { $pdfdata[] = array($Tasks['task_name'], $Tasks['task_description'], $users, $start_date != ' ' ? $start_date->format($df) : ' ', $end_date != ' ' ? $end_date->format($df) : ' ', $Tasks['task_percent_complete'] . '%'); } } echo '</table>'; if ($log_pdf) { // make the PDF file $q = new w2p_Database_Query(); $q->addTable('projects'); $q->addQuery('project_name'); $q->addWhere('project_id=' . (int) $project_id); $pname = $q->loadResult(); $font_dir = W2P_BASE_DIR . '/lib/ezpdf/fonts'; $temp_dir = W2P_BASE_DIR . '/files/temp'; require $AppUI->getLibraryClass('ezpdf/class.ezpdf'); $pdf = new Cezpdf($paper = 'A4', $orientation = 'landscape'); $pdf->ezSetCmMargins(1, 2, 1.5, 1.5); $pdf->selectFont($font_dir . '/Helvetica.afm'); $pdf->ezText(w2PgetConfig('company_name'), 12); $date = new w2p_Utilities_Date(); $pdf->ezText("\n" . $date->format($df), 8); $pdf->selectFont($font_dir . '/Helvetica-Bold.afm'); $pdf->ezText("\n" . $AppUI->_('Project Task Report'), 12); if ($project_id != 0) { $pdf->ezText($pname, 15); } if ($log_all) {
$q->addQuery('ut.user_id, u.user_username'); $q->addQuery('ut.perc_assignment, SUM(ut.perc_assignment) AS assign_extent'); $q->addQuery('contact_first_name, contact_last_name, contact_email'); $q->addTable('user_tasks', 'ut'); $q->leftJoin('users', 'u', 'u.user_id = ut.user_id'); $q->leftJoin('contacts', 'c', 'u.user_contact = c.contact_id'); $q->addWhere('ut.task_id = ' . (int) $row['task_id']); $q->addGroup('ut.user_id'); $q->addOrder('perc_assignment desc, user_username'); $assigned_users = array(); $row['task_assigned_users'] = $q->loadList(); $q->addQuery('count(task_id) as children'); $q->addTable('tasks'); $q->addWhere('task_parent = ' . (int) $row['task_id']); $q->addWhere('task_id <> task_parent'); $row['children'] = $q->loadResult(); $i = count($projects[$row['task_project']]['tasks']) + 1; $row['task_number'] = $i; $row['node_id'] = 'node_' . $i . '-' . $row['task_id']; if (strpos($row['task_duration'], '.') && $row['task_duration_type'] == 1) { $row['task_duration'] = floor($row['task_duration']) . ':' . round(60 * ($row['task_duration'] - floor($row['task_duration']))); } //pull the final task row into array $projects[$row['task_project']]['tasks'][] = $row; } $showEditCheckbox = isset($canEditTasks) && $canEditTasks || canView('admin'); $durnTypes = w2PgetSysVal('TaskDurationType'); $tempoTask = new CTask(); $userAlloc = $tempoTask->getAllocation('user_id'); $fieldList = array(); $fieldNames = array();
public function isActiveModule($module) { $q = new w2p_Database_Query(); $q->addTable('modules'); $q->addQuery('mod_active'); $q->addWhere("mod_directory = '{$module}'"); return $q->loadResult(); }
public static function getContactByUpdatekey($updateKey) { $q = new w2p_Database_Query(); $q->addTable('contacts'); $q->addQuery('contact_id'); $q->addWhere("contact_updatekey= '{$updateKey}'"); return $q->loadResult(); }
foreach ($permission['axo_groups'] as $group_id) { $group_data = $perms->get_group_data($group_id, 'axo'); $modlist[] = $AppUI->_($group_data[3]); } } if (is_array($permission['axo'])) { foreach ($permission['axo'] as $key => $section) { foreach ($section as $id) { $mod_data = $perms->get_object_full($id, $key, 1, 'axo'); if (is_numeric($mod_data['name'])) { $module = $pgo_list[ucfirst($key)]; $q = new w2p_Database_Query(); $q->addTable($module['permissions_item_table']); $q->addQuery($module['permissions_item_label']); $q->addWhere($module['permissions_item_field'] . '=' . $mod_data['name']); $data = $q->loadResult(); $q->clear(); $modlist[] = $AppUI->_(ucfirst($key)) . ': ' . w2PHTMLDecode($data); } else { $modlist[] = $AppUI->_(ucfirst($key)) . ': ' . w2PHTMLDecode($mod_data['name']); } } } } $buf .= implode('<br />', $modlist); $buf .= '</td>'; // Item information TODO: need to figure this one out. // $buf .= '<td></td>'; // Type information. $buf .= '<td>'; $perm_type = array();