function getAllUsersGroupByDept() { $q = new DBQuery(); $q->addTable('users'); $q->addQuery('user_id, contact_department, concat_ws(", ", contact_last_name, contact_first_name) as contact_name'); $q->addJoin('contacts', 'con', 'contact_id = user_contact'); $q->addOrder('contact_last_name'); $res = $q->exec(); $userlist = array(); while ($row = $q->fetchRow()) { if ($row['contact_department'] == null) { $row['contact_department'] = 0; } if (!isset($userlist[$row['contact_department']])) { $userlist[$row['contact_department']] = array(); } $userlist[$row['contact_department']][$row['user_id']] = $row['contact_name']; } $q->clear(); return $userlist; }
function dPgetSysVal($title) { $q = new DBQuery(); $q->addTable('sysvals'); $q->leftJoin('syskeys', 'sk', 'syskey_id = sysval_key_id'); $q->addQuery('syskey_type, syskey_sep1, syskey_sep2, sysval_value'); $q->addWhere("sysval_title = '{$title}'"); $q->exec(); $row = $q->fetchRow(); $q->clear(); // type 0 = list $sep1 = $row['syskey_sep1']; // item separator $sep2 = $row['syskey_sep2']; // alias separator // A bit of magic to handle newlines and returns as separators // Missing sep1 is treated as a newline. if (!isset($sep1) || empty($sep1)) { $sep1 = "\n"; } if ($sep1 == "\\n") { $sep1 = "\n"; } if ($sep1 == "\\r") { $sep1 = "\r"; } $temp = explode($sep1, $row['sysval_value']); $arr = array(); // We use trim() to make sure a numeric that has spaces // is properly treated as a numeric foreach ($temp as $item) { if ($item) { $sep2 = empty($sep2) ? "\n" : $sep2; $temp2 = explode($sep2, $item); if (isset($temp2[1])) { $arr[trim($temp2[0])] = trim($temp2[1]); } else { $arr[trim($temp2[0])] = trim($temp2[0]); } } } return $arr; }
if ($_POST['out_session'] && $_POST['out_user_log_id']) { $boot_user_session = $_POST['out_session']; $boot_user_log_id = $_POST['out_user_log_id']; $boot_query_row = false; } else { if ($canEdit && $canDelete && $logoutUserFlag) { // query for all sessions open for a given user $r = new DBQuery(); $r->addTable('sessions', 's'); $r->addQuery('DISTINCT(session_id), user_access_log_id'); $r->addJoin('user_access_log', 'ual', 'session_user = user_access_log_id'); $r->addWhere('user_id = ' . $boot_user_id); $r->addOrder('user_access_log_id'); //execute query and fetch results $r->exec(); $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']; } } } do { if ($boot_user_id == $AppUI->user_id && $boot_user_session == $_COOKIE['PHPSESSID']) { $AppUI->resetPlace(); $AppUI->redirect('logout=-1'); } else { addHistory('login', $boot_user_id, 'logout', $details); dPsessionDestroy($boot_user_session, $boot_user_log_id); } if ($boot_query_row) {
function store() { global $db; if (!is_array($this->options)) { $this->options = array(); } //load the dbs options and compare them with the options $q = new DBQuery(); $q->addTable('custom_fields_lists'); $q->addWhere('field_id = ' . $this->field_id); $q->addOrder('list_value'); if (!($rs = $q->exec())) { $q->clear(); return $db->ErrorMsg(); } $dboptions = array(); while ($opt_row = $q->fetchRow()) { $dboptions[$opt_row['list_option_id']] = $opt_row['list_value']; } $q->clear(); $newoptions = array(); $newoptions = array_diff($this->options, $dboptions); $deleteoptions = array_diff($dboptions, $this->options); //insert the new options foreach ($newoptions as $opt) { $optid = $db->GenID('custom_fields_option_id', 1); $q = new DBQuery(); $q->addTable('custom_fields_lists'); $q->addInsert('field_id', $this->field_id); $q->addInsert('list_option_id', $optid); $q->addInsert('list_value', db_escape($opt)); if (!$q->exec()) { $insert_error = $db->ErrorMsg(); } $q->clear(); } //delete the deleted options foreach ($deleteoptions as $opt => $value) { $q = new DBQuery(); $q->setDelete('custom_fields_lists'); $q->addWhere('list_option_id = ' . $opt); if (!$q->exec()) { $delete_error = $db->ErrorMsg(); } $q->clear(); } return $insert_error . ' ' . $delete_error; }
public function sendWatchMail($debug = false) { global $AppUI, $debug, $w2Pconfig; $subj_prefix = $AppUI->_('forumEmailSubj', UI_OUTPUT_RAW); $body_msg = $AppUI->_('forumEmailBody', UI_OUTPUT_RAW); // Get the message from details. $q = new DBQuery(); $q->addTable('users', 'u'); $q->addQuery('contact_email, contact_first_name, contact_last_name'); $q->addJoin('contacts', 'con', 'contact_id = user_contact', 'inner'); $q->addWhere('user_id = ' . (int) $this->message_author); $res = $q->exec(); if ($row = $q->fetchRow()) { $message_from = $row['contact_first_name'] . ' ' . $row['contact_last_name'] . '<' . $row['contact_email'] . '>'; } else { $message_from = 'Unknown user'; } // Get the forum name; $q->clear(); $q->addTable('forums'); $q->addQuery('forum_name'); $q->addWhere('forum_id = \'' . $this->message_forum . '\''); $res = $q->exec(); if ($row = $q->fetchRow()) { $forum_name = $row['forum_name']; } else { $forum_name = 'Unknown'; } // SQL-Query to check if the message should be delivered to all users (forced) // In positive case there will be a (0,0,0) row in the forum_watch table $q->clear(); $q->addTable('forum_watch'); $q->addQuery('*'); $q->addWhere('watch_user = 0 AND watch_forum = 0 AND watch_topic = 0'); $resAll = $q->exec(); $AllCount = db_num_rows($resAll); $q->clear(); $q->addTable('users'); $q->addQuery('DISTINCT contact_email, user_id, contact_first_name, contact_last_name'); $q->leftJoin('contacts', 'con', 'contact_id = user_contact'); if ($AllCount < 1) { //message is only delivered to users that checked the forum watch $q->addTable('forum_watch'); $q->addWhere('user_id = watch_user AND (watch_forum = ' . (int) $this->message_forum . ' OR watch_topic = ' . (int) $this->message_parent . ')'); } if (!($res = $q->exec(ADODB_FETCH_ASSOC))) { $q->clear(); return; } if (db_num_rows($res) < 1) { return; } $mail = new Mail(); $mail->Subject($subj_prefix . ' ' . $this->message_title, isset($GLOBALS['locale_char_set']) ? $GLOBALS['locale_char_set'] : ''); $body = $body_msg; $body .= "\n\n" . $AppUI->_('Forum', UI_OUTPUT_RAW) . ': ' . $forum_name; $body .= "\n" . $AppUI->_('Subject', UI_OUTPUT_RAW) . ': ' . $this->message_title; $body .= "\n" . $AppUI->_('Message From', UI_OUTPUT_RAW) . ': ' . $message_from; $body .= "\n\n" . W2P_BASE_URL . '/index.php?m=forums&a=viewer&forum_id=' . $this->message_forum; $body .= "\n\n" . $this->message_body; $mail->Body($body, isset($GLOBALS['locale_char_set']) ? $GLOBALS['locale_char_set'] : ''); while ($row = $q->fetchRow()) { if ($mail->ValidEmail($row['contact_email'])) { $mail->To($row['contact_email'], true); $mail->Send(); } } $q->clear(); return; }
/** * Called by the Event Queue processor to process a reminder * on a task. * @access public * @param string $module Module name (not used) * @param string $type Type of event (not used) * @param integer $id ID of task being reminded * @param integer $owner Originator of event * @param mixed $args event-specific arguments. * @return mixed true, dequeue event, false, event stays in queue. -1, event is destroyed. */ function remind($module, $type, $id, $owner, &$args) { global $locale_char_set, $AppUI; $q = new DBQuery(); $df = $AppUI->getPref('SHDATEFORMAT'); $tf = $AppUI->getPref('TIMEFORMAT'); // If we don't have preferences set for these, use ISO defaults. if (!$df) { $df = '%Y-%m-%d'; } if (!$tf) { $tf = '%H:%m'; } $df .= ' ' . $tf; // At this stage we won't have an object yet if (!$this->load($id)) { return -1; // No point it trying again later. } $this->htmlDecode(); // Only remind on working days. $today = new CDate(); if (!$today->isWorkingDay()) { return true; } // Check if the task is completed if ($this->task_percent_complete == 100) { return -1; } // Grab the assignee list $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->addQuery('c.contact_id, contact_first_name, contact_last_name, contact_email'); $q->addWhere('ut.task_id = ' . $id); $contacts = $q->loadHashList('contact_id'); $q->clear(); // Now we also check the owner of the task, as we will need // to notify them as well. $owner_is_not_assignee = false; $q->addTable('users', 'u'); $q->leftJoin('contacts', 'c', 'c.contact_id = u.user_contact'); $q->addQuery('c.contact_id, contact_first_name, contact_last_name, contact_email'); $q->addWhere('u.user_id = ' . $this->task_owner); if ($q->exec(ADODB_FETCH_NUM)) { list($owner_contact, $owner_first_name, $owner_last_name, $owner_email) = $q->fetchRow(); if (!isset($contacts[$owner_contact])) { $owner_is_not_assignee = true; $contacts[$owner_contact] = array('contact_id' => $owner_contact, 'contact_first_name' => $owner_first_name, 'contact_last_name' => $owner_last_name, 'contact_email' => $owner_email); } } $q->clear(); // build the subject line, based on how soon the // task will be overdue. $starts = new CDate($this->task_start_date); $expires = new CDate($this->task_end_date); $now = new CDate(); $diff = $expires->dateDiff($now); $prefix = $AppUI->_('Task Due', UI_OUTPUT_RAW); if ($diff == 0) { $msg = $AppUI->_('TODAY', UI_OUTPUT_RAW); } else { if ($diff == 1) { $msg = $AppUI->_('TOMORROW', UI_OUTPUT_RAW); } else { if ($diff < 0) { $msg = $AppUI->_(array('OVERDUE', abs($diff), 'DAYS')); $prefix = $AppUI->_('Task', UI_OUTPUT_RAW); } else { $msg = $AppUI->_(array($diff, 'DAYS')); } } } $q->addTable('projects'); $q->addQuery('project_name'); $q->addWhere('project_id = ' . $this->task_project); $project_name = htmlspecialchars_decode($q->loadResult()); $q->clear(); $subject = $prefix . ' ' . $msg . ' ' . $this->task_name . '::' . $project_name; $body = $AppUI->_('Task Due', UI_OUTPUT_RAW) . ': ' . $msg . "\n" . $AppUI->_('Project', UI_OUTPUT_RAW) . ': ' . $project_name . "\n" . $AppUI->_('Task', UI_OUTPUT_RAW) . ': ' . $this->task_name . "\n" . $AppUI->_('Start Date', UI_OUTPUT_RAW) . ': ' . $starts->format($df) . "\n" . $AppUI->_('Finish Date', UI_OUTPUT_RAW) . ': ' . $expires->format($df) . "\n" . $AppUI->_('URL', UI_OUTPUT_RAW) . ': ' . DP_BASE_URL . '/index.php?m=tasks&a=view&task_id=' . $this->task_id . '&reminded=1' . "\n\n" . $AppUI->_('Resources', UI_OUTPUT_RAW) . ":\n"; foreach ($contacts as $contact) { if ($owner_is_not_assignee || $contact['contact_id'] != $owner_contact) { $body .= $contact['contact_first_name'] . ' ' . $contact['contact_last_name'] . ' <' . $contact['contact_email'] . ">\n"; } } $body .= "\n" . $AppUI->_('Description', UI_OUTPUT_RAW) . ":\n" . $this->task_description . "\n"; $mail = new Mail(); foreach ($contacts as $contact) { if ($mail->ValidEmail($contact['contact_email'])) { $mail->To($contact['contact_email']); } } $mail->From('"' . $owner_first_name . ' ' . $owner_last_name . '" <' . $owner_email . '>'); $mail->Subject($subject, $locale_char_set); $mail->Body($body, $locale_char_set); return $mail->Send(); }
$q2->addWhere($where_list); } if ($project_id > 0) { $q2->addWhere('project_id = ' . $project_id); } $q2->addGroup('project_id'); $perms =& $AppUI->acl(); $projects = array(); $canViewTask = $perms->checkModule('tasks', 'view'); if ($canViewTask) { $prc = $q->exec(); echo db_error(); while ($row = $q->fetchRow()) { $projects[$row['project_id']] = $row; } $prc2 = $q2->fetchRow(); echo db_error(); while ($row2 = $q2->fetchRow()) { if ($projects[$row2['project_id']]) { array_push($projects[$row2['project_id']], $row2); } } } $q->clear(); $q2->clear(); $q->addQuery('tasks.task_id, task_parent, task_name'); $q->addQuery('task_start_date, task_end_date, task_dynamic'); $q->addQuery('task_pinned, pin.user_id as pin_user'); $q->addQuery('task_priority, task_percent_complete'); $q->addQuery('task_duration, task_duration_type'); $q->addQuery('task_project');
$df = $AppUI->getPref('SHDATEFORMAT'); $tf = $AppUI->getPref('TIMEFORMAT'); $q = new DBQuery(); $q->addTable('forums'); $q->addTable('projects', 'p'); $q->addTable('users', 'u'); $q->addQuery('forum_id, forum_project, forum_description, forum_owner, forum_name, forum_create_date, forum_last_date, forum_message_count, forum_moderated, user_username, contact_first_name, contact_last_name, project_name, project_color_identifier'); $q->addJoin('contacts', 'con', 'contact_id = user_contact'); $q->addWhere("user_id = forum_owner"); $q->addWhere("forum_id = {$forum_id}"); $q->addWhere("forum_project = project_id"); $q->exec(ADODB_FETCH_ASSOC); $forum = $q->fetchRow(); $forum_name = $forum["forum_name"]; echo db_error(); $q->clear(); $start_date = intval($forum["forum_create_date"]) ? new CDate($forum["forum_create_date"]) : null; //20090907 KSen@Itsutsubashi $project_id = $forum['forum_project']; // setup the title block $titleBlock = new CTitleBlock('Forum', 'support.png', $m, "{$m}.{$a}"); $titleBlock->addCell(arraySelect($filters, 'f', 'size="1" class="text" onchange="document.filterFrm.submit();"', $f, true), '', '<form action="?m=forums&a=viewer&forum_id=' . $forum_id . '" method="post" name="filterFrm">', '</form>'); $titleBlock->show(); ?> <table width="100%" cellspacing="0" cellpadding="2" border="0" class="std"> <tr> <td height="20" colspan="3" style="border: outset #D1D1CD 1px;background-color:#<?php echo $forum["project_color_identifier"];
$projTasks = array(); $task_parent_options = ''; // Now lets get non-root tasks, grouped by the task parent $q = new DBQuery(); $q->addTable('tasks'); $q->addQuery('task_id, task_name, task_end_date, task_start_date, task_milestone, task_parent, task_dynamic'); $q->addWhere('task_project = ' . (int) $task_project); $q->addWhere('task_id <> task_parent'); $q->addOrder('task_start_date'); $parents = array(); $projTasksWithEndDates = array($task->task_id => $AppUI->_('None')); //arrays contains task end date info for setting new task start date as maximum end date of dependenced tasks $all_tasks = array(); $sub_tasks = $q->exec(); if ($sub_tasks) { while ($sub_task = $q->fetchRow()) { // Build parent/child task list $parents[$sub_task['task_parent']][] = $sub_task['task_id']; $all_tasks[$sub_task['task_id']] = $sub_task; build_date_list($projTasksWithEndDates, $sub_task); } } $q->clear(); // let's iterate root tasks foreach ($root_tasks as $root_task) { build_date_list($projTasksWithEndDates, $root_task); if ($root_task['task_id'] != $task_id) { constructTaskTree($root_task); } } // setup the title block
function show_history($history) { global $AppUI; $id = $history['history_item']; $table = $history['history_table']; $q = new DBQuery(); $q->addTable('modules', 'm'); $q->addQuery('m.*'); $q->addWhere("m.`permissions_item_table` LIKE '" . $table . "'"); $q - exec(); $module_result = $q->fetchRow(); $q->clear(); $table_id = $module_result['permissions_item_field']; $module = $module_result['mod_directory']; if (!($table_id || $module)) { //valid "modules" w/o item level permissions switch ($table) { case 'history': //table name does not match with module name $table_id = 'history_id'; $module = 'history'; break; } } if ($table == 'login') { return $AppUI->_('User') . ' \'' . $history['history_description'] . '\' ' . $AppUI->_($history['history_action']); } if ($history['history_action'] == 'add') { $msg = $AppUI->_('Added new') . ' '; } else { if ($history['history_action'] == 'update') { $msg = $AppUI->_('Modified') . ' '; } else { if ($history['history_action'] == 'delete') { return $AppUI->_('Deleted') . ' \'' . $history['history_description'] . '\' ' . $AppUI->_('from') . ' ' . $AppUI->_($table) . ' ' . $AppUI->_('table'); } } } if ($table_id && $module) { $q->addTable($table); $q->addQuery($table_id); $q->addWhere($table_id . '=' . $id); $is_table_result = $q->loadResult(); $q->clear(); } if ($is_table_result) { switch ($table) { case 'history': case 'files': case 'links': $link = '&a=addedit&' . $table_id . '='; break; case 'tasks': case 'projects': case 'companies': case 'departments': case 'events': case 'contacts': $link = '&a=view&' . $table_id . '='; break; case 'forums': $link = '&a=viewer&' . $table_id . '='; break; case 'task_log': $module = 'tasks'; $q->addTable('task_log'); $q->addQuery('task_log_task'); $q->addWhere('task_log_id = ' . $id); $task_log_task = $q->loadResult(); $q->clear(); $link = '&a=view&task_id=' . $task_log_task . '&tab=1&' . $table_id . '='; $in_page_anchor = '#log'; break; } } $link = !empty($link) ? '<a href="?m=' . $module . $link . $id . $in_page_anchor . '">' . stripslashes($history['history_description']) . '</a>' : stripslashes($history['history_description']); $msg .= $AppUI->_('item') . ' "' . $link . '" ' . $AppUI->_('in') . ' "' . $AppUI->_($table) . '" ' . $AppUI->_('table'); return $msg; }
$canEdit = $perms->checkModuleItem('forums', 'edit', $forum_id); // check permissions if (!$canAuthor && !$forum_id) { $AppUI->redirect('m=public&a=access_denied'); } if (!$canEdit && $forum_id) { $AppUI->redirect('m=public&a=access_denied'); } $forum_id = intval(w2PgetParam($_GET, 'forum_id', 0)); //Pull forum information $q = new DBQuery(); $q->addTable('forums'); $q->addWhere('forums.forum_id = ' . (int) $forum_id); $res = $q->exec(ADODB_FETCH_ASSOC); echo db_error(); $forum_info = $q->fetchRow(); $status = isset($forum_info['forum_status']) ? $forum_info['forum_status'] : -1; // get any project records denied from viewing $projObj = new CProject(); //Pull project Information $q = new DBQuery(); $q->addTable('projects', 'pr'); $q->addQuery('pr.project_id, project_name'); $q->addWhere('project_active = 1'); $q->addOrder('project_name'); $projObj->setAllowedSQL($AppUI->user_id, $q, null, 'pr'); if (isset($company_id)) { $q->addWhere('project_company = ' . (int) $company_id); } $projects = array('0' => '') + $q->loadHashList(); echo db_error();
public function getEventsInWindow($start_date, $end_date, $start_time, $end_time, $users = null) { global $AppUI; if (!isset($users)) { return false; } if (!count($users)) { return false; } // Now build a query to find matching events. $q = new DBQuery(); $q->addTable('events', 'e'); $q->addQuery('e.event_owner, ue.user_id, e.event_cwd, e.event_id, e.event_start_date, e.event_end_date'); $q->addJoin('user_events', 'ue', 'ue.event_id = e.event_id'); $q->addWhere('event_start_date >= \'' . $start_date . '\' AND event_end_date <= \'' . $end_date . '\' AND EXTRACT(HOUR_MINUTE FROM e.event_end_date) >= \'' . $start_time . '\' AND EXTRACT(HOUR_MINUTE FROM e.event_start_date) <= \'' . $end_time . '\' AND ( e.event_owner in (' . implode(',', $users) . ') OR ue.user_id in (' . implode(',', $users) . ') )'); $result = $q->exec(); if (!$result) { return false; } $eventlist = array(); while ($row = $q->fetchRow()) { $eventlist[] = $row; } $q->clear(); return $eventlist; }
function parseFormatSysval($text, $syskey) { $q = new DBQuery(); $q->addTable('syskeys'); $q->addQuery('syskey_type, syskey_sep1, syskey_sep2'); $q->addWhere('syskey_id = ' . (int) $syskey); $q->exec(); $row = $q->fetchRow(); $q->clear(); // type 0 = list $sep1 = $row['syskey_sep1']; // item separator $sep2 = $row['syskey_sep2']; // alias separator // A bit of magic to handle newlines and returns as separators // Missing sep1 is treated as a newline. if (!isset($sep1) || empty($sep1)) { $sep1 = "\n"; } if ($sep1 == "\\n") { $sep1 = "\n"; } if ($sep1 == "\\r") { $sep1 = "\r"; } $temp = explode($sep1, $text); $arr = array(); // We use trim() to make sure a numeric that has spaces // is properly treated as a numeric foreach ($temp as $item) { if ($item) { $sep2 = empty($sep2) ? "\n" : $sep2; $temp2 = explode($sep2, $item); if (isset($temp2[1])) { $arr[mb_trim($temp2[0])] = mb_trim($temp2[1]); } else { $arr[mb_trim($temp2[0])] = mb_trim($temp2[0]); } } } return $arr; }
function getTaskName() { if (!$this->file_task) { return ''; } $q = new DBQuery(); $q->addTable('tasks'); $q->addQuery('task_name'); $q->addWhere('task_id = ' . $this->file_task); if (!$q->exec()) { $q->clear(); return db_error(); } $row = $q->fetchRow(); $q->clear(); return $row['task_name']; }
function load() { global $db; $q = new DBQuery(); $q->addTable('custom_fields_lists'); $q->addWhere("field_id = {$this->field_id}"); if (!($rs = $q->exec())) { $q->clear(); return $db->ErrorMsg(); } $this->options = array(); while ($opt_row = $q->fetchRow()) { $this->options[] = $opt_row["list_value"]; } $q->clear(); }
function authenticate($username, $password) { global $db, $AppUI; $this->username = $username; $q = new DBQuery(); $q->addTable('users'); $q->addQuery('user_id, user_password'); $q->addWhere("user_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; }
$q->addQuery('forum_name, forum_owner, forum_moderated, project_name, project_id'); $q->addWhere("forums.forum_id = {$forum_id}"); $q->addWhere('forums.forum_project = projects.project_id'); $res = $q->exec(); $forum_info = $q->fetchRow(); $q->clear(); echo db_error(); //pull message information $q = new DBQuery(); $q->addTable('forum_messages'); $q->addQuery('forum_messages.*, user_username'); $q->addJoin('users', 'u', 'message_author = u.user_id'); $q->addWhere('message_id = ' . ($message_id ? $message_id : $message_parent)); $res = $q->exec(); echo db_error(); $message_info = $q->fetchRow(); $q->clear(); //pull message information from last response if ($message_parent != -1) { $q->addTable('forum_messages'); $q->addWhere('message_parent = ' . ($message_id ? $message_id : $message_parent)); $q->addOrder('message_id DESC'); // fetch last message first $q->setLimit(1); $res = $q->exec(); echo db_error(); $last_message_info = $q->fetchRow(); if (!$last_message_info) { // if it's first response, use original message $last_message_info =& $message_info; $last_message_info["message_body"] = wordwrap(@$last_message_info["message_body"], 50, "\n> ");
public function get_object_sections($section_value = null, $return_hidden = 1, $object_type = null, $limit_clause = null) { switch (strtolower(trim($object_type))) { case 'aco': $object_type = 'aco'; $table = $this->_db_acl_prefix . 'aco_sections'; break; case 'aro': $object_type = 'aro'; $table = $this->_db_acl_prefix . 'aro_sections'; break; case 'axo': $object_type = 'axo'; $table = $this->_db_acl_prefix . 'axo_sections'; break; default: $this->debug_text('get_object_sections(): Invalid Object Type: ' . $object_type); return false; } $this->debug_text("get_objects(): Section Value: {$section_value} Object Type: {$object_type}"); // $query = 'SELECT id, value, name, order_value, hidden FROM '. $table; $q = new DBQuery(); $q->addTable($table); $q->addQuery('id, value, name, order_value, hidden'); if (!empty($section_value)) { $q->addWhere('value=' . $this->db->quote($section_value)); } if ($return_hidden == 0) { $q->addWhere('hidden=0'); } if (!empty($limit_clause)) { $q->addWhere($limit_clause); } $q->addOrder('order_value'); $rs = $q->exec(); /* if (!is_object($rs)) { $this->debug_db('get_object_sections'); return FALSE; } */ $retarr = array(); while ($row = $q->fetchRow()) { $retarr[] = array('id' => $row[0], 'value' => $row[1], 'name' => $row[2], 'order_value' => $row[3], 'hidden' => $row[4]); } $q->clear(); // Return objects return $retarr; }
$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 DBQuery(); $q2 = $q; $q2->addQuery('projects.project_id, COUNT(t1.task_id) as total_tasks'); $perms =& $AppUI->acl(); $projects = array(); if ($canViewTasks) { $prc = $q->exec(); echo db_error(); while ($row = $q->fetchRow()) { $projects[$row['project_id']] = $row; } $prc2 = $q2->exec(); echo db_error(); while ($row2 = $q2->fetchRow()) { $projects[$row2['project_id']] = !$projects[$row2['project_id']] ? array() : $projects[$row2['project_id']]; array_push($projects[$row2['project_id']], $row2); } } $q->clear(); $q2->clear(); $q->addQuery('tasks.task_id, task_parent, task_name'); $q->addQuery('task_start_date, task_end_date, task_dynamic'); $q->addQuery('count(tasks.task_parent) as children'); $q->addQuery('task_pinned, pin.user_id as pin_user');
function process_dependencies($i) { global $tasks, $option_advance_if_possible; if ($tasks[$i]["fixed"]) { return; } log_info("<div style='padding-left: 1em'>Dependecies for '" . $tasks[$i]["task_name"] . "':<br />"); // query dependencies for this task $q = new DBQuery(); $q->addTable('tasks', 't'); $q->addTable('task_dependencies', 'td'); $q->addQuery('t.*'); $q->addWhere('task_id=dependencies_req_task_id and dependencies_task_id=' . (int) $tasks[$i]['task_id']); $q->includeCount(); $q->exec(); if ($q->foundRows() != 0) { $all_fixed = true; $latest_end_date = null; // store dependencies in an array (for adding more entries on the fly) $dependencies = array(); while ($row = $q->fetchRow()) { array_push($dependencies, $row); } $d = 0; while ($d < count($dependencies)) { $row = $dependencies[$d]; $index = search_task($row["task_id"]); if ($index == -1) { // task is not listed => it's a task group // => $i depends on all its subtasks // => add all subtasks to the dependencies array log_info("- task '" . $row["task_name"] . "' is a task group (processing subtask's dependencies)"); $children = get_last_children($row); // replace this taskgroup with all its subtasks array_splice($dependencies, $d, 1, $children); continue; } log_info(" - '" . $tasks[$index]["task_name"] . ($tasks[$index]["fixed"] ? " (FIXED)" : "") . "'"); // TODO: Detect dependencies loops (A->B, B->C, C->A) process_dependencies($index); if (!$tasks[$index]["fixed"]) { $all_fixed = false; } else { // ignore dependencies of finished tasks if option is enabled if (!$option_advance_if_possible || $tasks[$index]["task_percent_complete"] != 100) { // get latest end_date $end_date = db_dateTime2unix($tasks[$index]["task_end_date"]); if (!$latest_end_date || $end_date > $latest_end_date) { $latest_end_date = $end_date; $dep_on_task = $row; } } else { log_info("this task is complete => don't check dependency"); } $d++; } } if ($all_fixed) { // this task depends only on fixated tasks log_info("all dependencies are fixed"); fixate_task($i, $latest_end_date, $dep_on_task); } else { log_error("task has not fixed dependencies"); } } else { // task has no dependencies log_info("no dependencies => "); fixate_task($i, time(), ""); } log_info("</div><br />\n"); }