function setComplete($id) { global $AppUI; $task = new CTask(); if ($task->load($id)) { $q = new DBQuery(); $q->addTable('user_tasks'); $q->addQuery('user_id'); $q->addWhere('task_id = ' . $id); $q->addWhere('user_id = ' . $AppUI->user_id); $r = $q->loadResult(); if ($r != $AppUI->user_id) { $p = new CProject($task->task_project); if (!$p->project_id || $p->getManager() != $AppUI->user_id) { return 'Error'; } } $q->addTable('tasks'); $q->addUpdate('task_percent_complete', '100'); $q->addWhere('task_id = ' . $id); $q->exec(); return 'OK'; } return 'Error'; }
function updateContactCompany($contact_array, $company_id) { $q = new DBQuery(); $q->addTable('contacts'); $q->addUpdate('contact_company = ' . $company_id); $q->addWhere('contact_id = ' . $contact_array['contact_id']); db_exec($q->prepareUpdate()); }
function testUpdateBD() { $q = new DBQuery(); $q->addTable('eap'); $q->addQuery("id,nome,linha,coluna"); $q->addUpdate(nome, 'Dot Project'); $q->addWhere("id = 1"); $q->prepareUpdate(); $this->assertEqual($q->exec(), true); $q->clear(); }
protected function _deDynamicLeafNodes($projectId) { $q = new DBQuery(); $q->addUpdate('task_dynamic', 0); $q->addWhere("task_project = {$projectId}"); $q->addTable('tasks'); $q->exec(); $q->addQuery('distinct(task_parent)'); $q->addTable('tasks'); $q->addWhere("task_project = {$projectId}"); $q->addWhere("task_id <> task_parent"); $taskList = $q->loadHashList(); foreach ($taskList as $id => $nothing) { $dynamicTasks .= $id . ','; } $dynamicTasks .= '0'; $q->clear(); $q->addUpdate('task_dynamic', 1); $q->addWhere("task_project = {$projectId}"); $q->addWhere("task_id IN ({$dynamicTasks})"); $q->addTable('tasks'); $q->exec(); }
function sendNewPass() { global $AppUI; $_live_site = dPgetConfig('base_url'); $_sitename = dPgetConfig('company_name'); // ensure no malicous sql gets past $checkusername = trim(dPgetParam($_POST, 'checkusername', '')); $checkusername = db_escape($checkusername); $confirmEmail = trim(dPgetParam($_POST, 'checkemail', '')); $confirmEmail = mb_strtolower(db_escape($confirmEmail)); $q = new DBQuery(); $q->addTable('users', 'u'); $q->addQuery('u.user_id'); $q->addWhere('user_username=\'' . $checkusername . '\' AND LOWER(contact_email)=\'' . $confirmEmail . '\''); $q->leftJoin('contacts', 'c', 'u.user_contact = c.contact_id'); 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 Mail(); // create the mail $m->From("dotProject@" . dPgetConfig('site_domain')); $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->clear(); $q->addTable('users'); $q->addUpdate('user_password', $newpass, true); $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(); } }
function dPsessionWrite($id, $data) { $q = new DBQuery(); $q->addQuery('count(*) as row_count'); $q->addTable('sessions'); $q->addWhere("session_id = '{$id}'"); if (($qid =& $q->exec()) && (@$qid->fields['row_count'] > 0 || @$qid->fields[0] > 0)) { dprint(__FILE__, __LINE__, 11, "Updating session {$id}"); $q->query = null; $q->addUpdate('session_data', $data); } else { dprint(__FILE__, __LINE__, 11, "Creating new session {$id}"); $q->query = null; $q->where = null; $q->addInsert('session_id', $id); $q->addInsert('session_data', $data); $q->addInsert('session_created', date('Y-m-d H:i:s')); } $q->exec(); $q->clear(); return true; }
/** *@Function for update table user_acces_log in field date_time_lost_action */ function updateLastAction($last_insert_id) { $q = new DBQuery(); $q->addTable('user_access_log'); $q->addUpdate('date_time_last_action', date('Y-m-d H:i:s')); $q->addWhere("user_access_log_id = {$last_insert_id}"); if ($last_insert_id > 0) { $q->exec(); $q->clear(); } }
$history_description = dPgetParam($_POST, 'history_description', ''); $history_project = dPgetParam($_POST, 'history_project', ''); $userid = $AppUI->user_id; if ($action == 'add') { $q->addTable('history'); $q->addInsert('history_table', "history"); $q->addInsert('history_action', "add"); $q->addInsert('history_date', str_replace("'", '', $db->DBTimeStamp(time()))); $q->addInsert('history_description', $history_description); $q->addInsert('history_user', $userid); $q->addInsert('history_project', $history_project); $okMsg = 'History added'; } else { if ($action == 'update') { $q->addTable('history'); $q->addUpdate('history_description', $history_description); $q->addUpdate('history_project', $history_project); $q->addWhere('history_id =' . $history_id); $okMsg = 'History updated'; } else { if ($action == 'del') { $q->setDelete('history'); $q->addWhere('history_id =' . $history_id); $okMsg = 'History deleted'; } } } if (!$q->exec()) { $AppUI->setMsg(db_error()); } else { $AppUI->setMsg($okMsg);
function commit_updates() { $q = new DBQuery(); if (count($this->delete_list)) { $q->setDelete($this->table); $q->addWhere("queue_id in (" . implode(',', $this->delete_list) . ")"); $q->exec(); $q->clear(); } $this->delete_list = array(); foreach ($this->update_list as $fields) { $q->addTable($this->table); $q->addUpdate('queue_repeat_count', $fields['queue_repeat_count']); $q->addUpdate('queue_start', $fields['queue_start']); $q->addWhere('queue_id = ' . $fields['queue_id']); $q->exec(); $q->clear(); } $this->update_list = array(); }
$q = new DBQuery(); $q->addTable('tasks'); $q->addUpdate('task_percent_complete', '100'); $q->addWhere('task_id=' . (int) $val); } else { if ($task_priority == 'd') { // delete task $q = new DBQuery(); $q->setDelete('tasks'); $q->addWhere('task_id=' . (int) $val); } else { if ($task_priority > -2 && $task_priority < 2) { // set priority $q = new DBQuery(); $q->addTable('tasks'); $q->addUpdate('task_priority', $task_priority); $q->addWhere('task_id=' . (int) $val); } } } $q->exec(); echo db_error(); $q->clear(); } } $AppUI->savePlace(); $proj = new CProject(); $tobj = new CTask(); $allowedProjects = $proj->getAllowedSQL($AppUI->user_id, 'pr.project_id'); $allowedTasks = $tobj->getAllowedSQL($AppUI->user_id, 'ta.task_id'); // query my sub-tasks (ignoring task parents)
$ed = $ed->format(FMT_DATETIME_MYSQL); } $task_name = htmlentities(stripslashes($_POST['task_name']), ENT_QUOTES); $task_dynamic = isset($_POST['task_dynamic']) ? 1 : 0; $task_milestone = isset($_POST['task_milestone']) ? 1 : 0; $task_status = isset($_POST['task_status']) ? 0 : -1; $task_creator = isset($_POST['task_creator']) ? $_POST['task_creator'] : $AppUI->user_id; $q = new DBQuery(); $q->addTable('tasks'); $values = array($task_name, $_POST['task_parent'], $_POST['task_project'], $task_creator, $sd, $_POST['task_duration'], 1, $ed, htmlentities(stripslashes($_POST['task_description']), ENT_QUOTES), $_POST['task_priority'], $task_creator, 0, 0, $task_dynamic, 0, 0, 0, $task_milestone, $task_status); $fields = 'task_name,task_parent,task_project,task_owner,' . 'task_start_date,task_duration,task_duration_type,task_end_date,task_description,' . 'task_priority,task_creator,task_order,task_client_publish,' . 'task_dynamic,task_access,task_notify,task_type,task_milestone,task_status'; if ($task_id <= 0) { $q->addInsert($fields, $values, true); $AppUI->setMsg('Task <br/>[' . $task_name . ']<br/>has been added', UI_MSG_OK); } else { $q->addUpdate($fields, $values, true); $q->addWhere('task_id = ' . $task_id); $AppUI->setMsg('Task <br/>[' . $task_name . ']<br/>has been updated', UI_MSG_OK); } $q->exec(); if ($task_id <= 0) { $q->clear(); $q->addTable('tasks'); $q->addQuery('task_id'); $q->addWhere('task_name = "' . $task_name . '"'); $q->addWhere('task_project = ' . $_POST['task_project']); $q->addWhere('task_creator = ' . $AppUI->user_id); $task_id = $q->loadResult(); } db_exec('DELETE FROM user_tasks WHERE task_id = ' . $task_id); if (is_array($_POST['task_members'])) {
function store() { $q = new DBQuery(); $q->addQuery('billingcode_id'); $q->addTable('billingcode'); $q->addWhere("billingcode_name = '" . $this->billingcode_name . "'"); $q->addWhere('company_id = ' . $this->company_id); $found_id = $q->loadResult(); if ($found_id && $found_id != $this->_billingcode_id) { return 'Billing Code::code already exists'; } else { if ($this->_billingcode_id) { $q->addTable('billingcode'); $q->addUpdate('billingcode_desc', $this->billingcode_desc); $q->addUpdate('billingcode_name', $this->billingcode_name); $q->addUpdate('billingcode_value', $this->billingcode_value); $q->addUpdate('billingcode_status', $this->billingcode_status); $q->addUpdate('company_id', $this->company_id); $q->addWhere('billingcode_id = ' . $this->_billingcode_id); $q->exec(); $q->clear(); } else { if (!($ret = db_insertObject('billingcode', $this, 'billingcode_id'))) { return 'Billing Code::store failed <br />' . db_error(); } else { return NULL; } } } }
public function delete() { $q = new DBQuery(); $q->setDelete('forum_visits'); $q->addWhere('visit_message = ' . (int) $this->message_id); $q->exec(); // No error if this fails, it is not important. $q->clear(); $q->addTable('forum_messages'); $q->addQuery('message_forum'); $q->addWhere('message_id = ' . (int) $this->message_id); $forumId = $q->loadResult(); $q->clear(); $q->setDelete('forum_messages'); $q->addWhere('message_id = ' . (int) $this->message_id); if (!$q->exec()) { $result = db_error(); } else { $result = null; } $q->clear(); $q->addTable('forum_messages'); $q->addQuery('COUNT(message_id)'); $q->addWhere('message_forum = ' . (int) $forumId); $messageCount = $q->loadResult(); $q->clear(); $q->addTable('forums'); $q->addUpdate('forum_message_count', $messageCount); $q->addWhere('forum_id = ' . (int) $forumId); $q->exec(); $q->clear(); return $result; }
/** *@Function for update table user_acces_log in field date_time_lost_action */ public function updateLastAction($last_insert_id) { $q = new DBQuery(); $q->addTable('user_access_log'); $q->addUpdate('date_time_last_action', $q->dbfnNow(), false, true); $q->addWhere('user_access_log_id = ' . $last_insert_id); if ($last_insert_id > 0) { $q->exec(); $q->clear(); } }
if (!$file_id) { $obj->file_owner = $AppUI->user_id; if (!$obj->file_version_id) { $q = new DBQuery(); $q->addTable('files'); $q->addQuery('file_version_id'); $q->addOrder('file_version_id DESC'); $q->setLimit(1); $sql = $q->prepare(); $q->clear(); $latest_file_version = db_loadResult($sql); $obj->file_version_id = $latest_file_version + 1; } else { $q = new DBQuery(); $q->addTable('files'); $q->addUpdate('file_checkout', ''); $q->addWhere("file_version_id = {$obj->file_version_id}"); $q->exec(); $q->clear(); } } if ($msg = $obj->store()) { $AppUI->setMsg($msg, UI_MSG_ERROR); } else { $obj->load($obj->file_id); if ($not == '1') { $obj->notify(); } $AppUI->setMsg($file_id ? 'updated' : 'added', UI_MSG_OK, true); /* Workaround for indexing large files: ** Based on the value defined in config data,
$ned->addDuration($obj->task_duration, $obj->task_duration_type); } else { // calc task time span start - end $d = $tsd->calcDuration($ted); // Re-add (keep) task time span for end date. // This is independent from $obj->task_duration. // The value returned by Date::Duration() is always in hours ('1') $ned->addDuration($d, '1'); } // prefer tue 16:00 over wed 8:00 as an end date $ned = $ned->prev_working_day(); $obj->task_start_date = $nsd->format(FMT_DATETIME_MYSQL); $obj->task_end_date = $ned->format(FMT_DATETIME_MYSQL); $q = new DBQuery(); $q->addTable('tasks', 't'); $q->addUpdate('task_start_date', $obj->task_start_date); $q->addUpdate('task_end_date', $obj->task_end_date); $q->addWhere('task_id = ' . (int) $obj->task_id); $q->addWhere('task_dynamic <> 1'); $q->exec(); $q->clear(); } $obj->pushDependencies($obj->task_id, $obj->task_end_date); } // If there is a set of post_save functions, then we process them if (isset($post_save)) { foreach ($post_save as $post_save_function) { $post_save_function(); } } if ($notify) {
} dPmsg('Converting users to contacts'); $q = new DBQuery(); $q->addTable("users"); $q->addQuery("*"); $users = db_loadList($q->prepare(true)); $flds = array('contact_first_name', 'contact_last_name', 'contact_birthday', 'contact_company', 'contact_department', 'contact_email', 'contact_phone', 'contact_phone2', 'contact_mobile', 'contact_address1', 'contact_address2', 'contact_city', 'contact_state', 'contact_zip', 'contact_country', 'contact_icq', 'contact_icon', 'contact_owner'); foreach ($users as $user) { $vals = array($user['user_first_name'], $user['user_last_name'], $user['user_birthday'], (int) dPgetParam($user, 'user_company', 0), (int) dPgetParam($user, 'user_department', 0), $user['user_email'], $user['user_phone'], $user['user_home_phone'], $user['user_mobile'], $user['user_address1'], $user['user_address2'], $user['user_city'], $user['user_state'], $user['user_zip'], $user['user_country'], $user['user_icq'], $user['user_pic'], $user['user_owner']); $q->addTable('contacts'); $q->addInsert($flds, $vals, true); db_exec($q->prepareInsert()); $q->clear(); $msg = db_error(); $vals = array($user['user_id'], 'USERFORMAT', 'user'); $q->addTable('user_preferences'); db_exec($q->addInsert($flds, $vals, true)); $q->clear(); $msg = db_error(); if ($msg) { dPmsg($msg); } $q->addTable('users'); $q->addUpdate('user_contact=LAST_INSERT_ID()'); $q->addWhere('user_id = ' . $user['user_id']); db_exec($q->prepare(true)); $msg = db_error(); if ($msg) { dPmsg($msg); } }
function dPsessionDestroy($id, $user_access_log_id = 0) { global $AppUI; if (!$user_access_log_id && isset($AppUI->last_insert_id)) { $user_access_log_id = $AppUI->last_insert_id; } dprint(__FILE__, __LINE__, 11, "Killing session {$id}"); $q = new DBQuery(); $q->setDelete('sessions'); $q->addWhere("session_id = '{$id}'"); $q->exec(); $q->clear(); if ($user_access_log_id) { $q->addTable('user_access_log'); $q->addUpdate('date_time_out', date("Y-m-d H:i:s")); $q->addWhere('user_access_log_id = ' . $user_access_log_id); $q->exec(); $q->clear(); } return true; }
function authenticate($username, $password) { global $db, $AppUI; if (!isset($_REQUEST['userdata'])) { // fallback to SQL Authentication if PostNuke fails. if ($this->fallback) { return parent::authenticate($username, $password); } else { die($AppUI->_('You have not configured your PostNuke site correctly')); } } if (!($compressed_data = base64_decode(urldecode($_REQUEST['userdata'])))) { die($AppUI->_('The credentials supplied were missing or corrupted') . ' (1)'); } if (!($userdata = gzuncompress($compressed_data))) { die($AppUI->_('The credentials supplied were missing or corrupted') . ' (2)'); } if (!($_REQUEST['check'] = md5($userdata))) { die($AppUI->_('The credentials supplied were issing or corrupted') . ' (3)'); } $user_data = unserialize($userdata); // Now we need to check if the user already exists, if so we just // update. If not we need to create a new user and add a default // role. $username = trim($user_data['login']); $this->username = $username; $names = explode(' ', trim($user_data['name'])); $last_name = array_pop($names); $first_name = implode(' ', $names); $passwd = trim($user_data['passwd']); $email = trim($user_data['email']); $q = new DBQuery(); $q->addTable('users'); $q->addQuery('user_id, user_password, user_contact'); $q->addWhere("user_username = '******'"); if (!($rs = $q->exec())) { die($AppUI->_('Failed to get user details') . ' - error was ' . $db->ErrorMsg()); } if ($rs->RecordCount() < 1) { $q->clear(); $this->createsqluser($username, $passwd, $email, $first_name, $last_name); } else { if (!($row = $rs->FetchRow())) { die($AppUI->_('Failed to retrieve user detail')); } // User exists, update the user details. $this->user_id = $row['user_id']; $q->clear(); $q->addTable('users'); $q->addUpdate('user_password', $passwd); $q->addWhere("user_id = {$this->user_id}"); if (!$q->exec()) { die($AppUI->_('Could not update user credentials')); } $q->clear(); $q->addTable('contacts'); $q->addUpdate('contact_first_name', $first_name); $q->addUpdate('contact_last_name', $last_name); $q->addUpdate('contact_email', $email); $q->addWhere("contact_id = {$row['user_contact']}"); if (!$q->exec()) { die($AppUI->_('Could not update user details')); } $q->clear(); } return true; }
public function import($AppUI) { $output = ''; $company_id = (int) w2PgetParam($_POST, 'company_id', 0); if ($company_id == 0) { if (isset($_POST['new_company'])) { $companyName = w2PgetParam($_POST, 'new_company', 'New Company'); $company = new CCompany(); $company->company_name = $companyName; $company->company_owner = $AppUI->user_id; $AppUI->version_major <= 1 && $AppUI->version_minor <= 1 ? $company->store() : $company->store($AppUI); $company_id = $company->company_id; $output .= $AppUI->_('createcomp') . $companyName . '<br>'; echo $output; } else { $error = $AppUI->_('emptycomp'); return $error; } } $result = $this->_processProject($AppUI, $company_id, $_POST); if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR); $AppUI->redirect('m=importers'); } $this->project_id = $result; $q = new DBQuery(); // Users Setup if (isset($_POST['users']) && is_array($_POST['users']) && $_POST['nouserimport'] != "true") { foreach ($_POST['users'] as $ruid => $r) { $q->clear(); if (!empty($r['user_username'])) { $result = $this->_processContact($AppUI, $r['user_username'], $company_id); if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR); $AppUI->redirect('m=importers'); } $contact_id = $result; //TODO: Replace with the regular create users functionality $q->addInsert('user_username', $r['user_username']); $q->addInsert('user_contact', $contact_id); $q->addTable('users'); $q->exec(); $insert_id = db_insert_id(); $r['user_id'] = $insert_id; } else { $r['user_id'] = $r['user_userselect']; } if (!empty($r['user_id'])) { $resources[$ruid] = $r; } } } // Tasks Setup foreach ($_POST['tasks'] as $k => $task) { $result = $this->_processTask($AppUI, $this->project_id, $task); if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR); $AppUI->redirect('m=importers'); } $task_id = $result; // Task Parenthood $outline[$task['OUTLINENUMBER']] = $task_id; $q->clear(); if (!strpos($task['OUTLINENUMBER'], '.')) { $q->addUpdate('task_parent', $task_id); $q->addWhere('task_id = ' . $task_id); $q->addTable('tasks'); } else { $parent_string = substr($task['OUTLINENUMBER'], 0, strrpos($task['OUTLINENUMBER'], '.')); $parent_outline = isset($outline[$parent_string]) ? $outline[$parent_string] : $task_id; $q->addUpdate('task_parent', $parent_outline); $q->addWhere('task_id = ' . $task_id); $q->addTable('tasks'); } $q->exec(); $task['task_id'] = $task_id; $tasks[$task['UID']] = $task; // Resources (Workers) if (count($task['resources']) > 0) { $sql = "DELETE FROM user_tasks WHERE task_id = {$task_id}"; db_exec($sql); $resourceArray = array(); foreach ($task['resources'] as $uk => $user) { $alloc = $task['resources_alloc'][$uk]; if ($alloc > 0 && $resources[$user]['user_id'] > 0) { $q->clear(); if (!in_array($resources[$user]['user_id'], $resourceArray)) { $q->addInsert('user_id', $resources[$user]['user_id']); $q->addInsert('task_id', $task_id); $q->addInsert('perc_assignment', $alloc); $q->addTable('user_tasks'); $q->exec(); } $resourceArray[] = $resources[$user]['user_id']; } } } } //dependencies have to be handled alone after all tasks have been saved since the //predecessor (ms project term) task might come later and the associated task id //is not yet available. foreach ($tasks as $k => $task) { // Task Dependencies if (isset($task['dependencies']) && is_array($task['dependencies'])) { $sql = "DELETE FROM task_dependencies WHERE dependencies_task_id = {$task_id}"; db_exec($sql); $dependencyArray = array(); foreach ($task['dependencies'] as $task_uid) { if ($task_uid > 0 && $tasks[$task_uid]['task_id'] > 0) { $q->clear(); if (!in_array($tasks[$task_uid]['task_id'], $dependencyArray)) { $q->addInsert('dependencies_task_id', $task['task_id']); $q->addInsert('dependencies_req_task_id', $tasks[$task_uid]['task_id']); $q->addTable('task_dependencies'); $q->exec(); } $dependencyTestArray[] = $tasks[$task_uid]['task_id']; } } } } $this->_deDynamicLeafNodes($this->project_id); addHistory('projects', $this->project_id, 'add', $projectName, $this->project_id); return $output; }
$task_sort_item1 = dPgetParam($_GET, 'task_sort_item1', ''); $task_sort_type1 = dPgetParam($_GET, 'task_sort_type1', 0); $task_sort_order1 = intval(dPgetParam($_GET, 'task_sort_order1', 0)); $task_sort_item2 = dPgetParam($_GET, 'task_sort_item2', ''); $task_sort_type2 = dPgetParam($_GET, 'task_sort_type2', 0); $task_sort_order2 = intval(dPgetParam($_GET, 'task_sort_order2', 0)); // if task priority set and items selected, do some work $task_priority = dPgetParam($_POST, 'task_priority', 99); $selected = dPgetParam($_POST, 'selected_task', 0); $q = new DBQuery(); if (is_array($selected) && count($selected)) { foreach ($selected as $key => $val) { if ($task_priority == 'c') { // mark task as completed $q->addTable('tasks'); $q->addUpdate('task_percent_complete', "'100'"); $q->addWhere('task_id=' . $val); } else { if ($task_priority == 'd') { // delete task $q->setDelete('tasks'); $q->addWhere('task_id=' . $val); } else { if ($task_priority > -2 && $task_priority < 2) { // set priority $q->addTable('tasks'); $q->addUpdate('task_priority', $task_priority); $q->addWhere('task_id=' . $val); } } }
function update($field_id, $field_name, $field_description, $field_htmltype, $field_datatype, $field_extratags, &$error_msg) { global $db; $q = new DBQuery(); $q->addTable('custom_fields_struct'); $q->addUpdate('field_name', $field_name); $q->addUpdate('field_description', $field_description); $q->addUpdate('field_htmltype', $field_htmltype); $q->addUpdate('field_datatype', $field_datatype); $q->addUpdate('field_extratags', $field_extratags); $q->addWhere("field_id = " . $field_id); if (!$q->exec()) { $error_msg = $db->ErrorMsg(); $q->clear(); return 0; } else { $q->clear(); return $field_id; } }
if ($first) { $first = false; } else { $project_where .= ','; } $project_where .= (int) $prj; } $project_where .= ')'; } else { $project_where = '= ' . (int) $projects[0]; } // Need to figure out which items to update. Easiest to do this // as separate queries. // Projects: $q = new DBQuery(); $q->addUpdate('project_owner', $user_id); $q->addTable('projects'); $q->addWhere('project_owner = ' . $from_user); $q->addWhere('project_id' . $project_where); if (!$q->exec()) { $AppUI->setMsg('failed to update project owner', UI_MSG_ERROR); return; } $q->clear(); $q->addUpdate('contact_id', $user_id); $q->addTable('project_contacts'); $q->addWhere('contact_id = ' . $from_user); $q->addWhere('project_id ' . $project_where); if (!$q->exec()) { $AppUI->setMsg('failed to update project contacts', UI_MSG_ERROR); return;
protected function commit_updates($batched = false) { $q = new DBQuery(); if (count($this->delete_list)) { $q->setDelete($this->table); $q->addWhere("queue_id in (" . implode(',', $this->delete_list) . ")"); $q->exec(); $q->clear(); } $this->delete_list = array(); foreach ($this->update_list as $fields) { $q->addTable($this->table); $q->addUpdate('queue_repeat_count', $fields['queue_repeat_count']); $q->addUpdate('queue_start', $fields['queue_start']); $q->addWhere('queue_id = ' . $fields['queue_id']); $q->exec(); $q->clear(); } $this->update_list = array(); /** * Finally notify the batch handlers that the batch has been terminated. * This is done by calling the method EventQueue_<method_name>_batchTerminate. * Note that at this stage we will have all of the classes loaded, as we will * have executed the class methods to handle the batch requests. */ if ($batched) { foreach ($this->batch_list as $batcher) { $method = 'EventQueue_' . $batcher['method'] . '_terminateBatch'; if (method_exists($batcher['class'], $method)) { $batcher['object']->{$method}(); } } } $this->batch_list = array(); }
public static function updateHoursWorked($taskId, $totalHours) { $q = new DBQuery(); $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); }
<?php global $currentTabId, $pstatus; $currentTabId = $psfilter = isset($_REQUEST['psfilter']) ? $_REQUEST['psfilter'] : P_ACTIVE; $AppUI->savePlace(); // Load the companies class to retrieved denied companies require_once $AppUI->getModuleClass('companies'); // Update project status! if (isset($_GET['update_project_status']) && isset($_GET['project_status']) && isset($_GET['project_id'])) { $r = new DBQuery(); $r->addTable('projects'); $r->addUpdate('project_status', $_GET['project_status']); $r->addWhere('project_id IN (' . implode(',', $_GET['project_id']) . ')'); $r->exec(); $r->clear(); } // Retrieve any state parameters if (isset($_GET['tab'])) { $AppUI->setState('ProjIdxTab', $_GET['tab']); } $tab = $AppUI->getState('ProjIdxTab') !== NULL ? $AppUI->getState('ProjIdxTab') : 0; $active = intval(!$AppUI->getState('ProjIdxTab')); if (isset($_POST['company_id'])) { $AppUI->setState('ProjIdxCompany', intval($_POST['company_id'])); } $company_id = $AppUI->getState('ProjIdxCompany') !== NULL ? $AppUI->getState('ProjIdxCompany') : $AppUI->user_company; $company_prefix = 'company_'; if (isset($_POST['department'])) { $AppUI->setState('ProjIdxDepartment', $_POST['department']); //if department is set, ignore the company_id field unset($company_id);
public function cancelCheckout($fileId) { $q = new DBQuery(); $q->addTable('files'); $q->addUpdate('file_checkout', ''); $q->addWhere('file_id = ' . (int) $fileId); $q->exec(); return true; }
function dPsessionGC($maxlifetime) { global $AppUI; dprint(__FILE__, __LINE__, 11, 'Session Garbage collection running'); $now = time(); $max = dPsessionConvertTime('max_lifetime'); $idle = dPsessionConvertTime('idle_time'); // First pass is to kill any users that are logged in at the time of the session. $where = 'UNIX_TIMESTAMP() - UNIX_TIMESTAMP(session_updated) > ' . $idle . ' OR UNIX_TIMESTAMP() - UNIX_TIMESTAMP(session_created) > ' . $max; $q = new DBQuery(); $q->addTable('sessions'); $q->addQuery('session_user'); $q->addWhere($where); $sql2 = $q->prepare(true); $q->addTable('user_access_log'); $q->addUpdate('date_time_out', date('Y-m-d H:i:s')); $q->addWhere('user_access_log_id IN (' . $sql2 . ')'); $q->exec(); $q->clear(); // Now we simply delete the expired sessions. $q->setDelete('sessions'); $q->addWhere($where); $q->exec(); $q->clear(); if (dPgetConfig('session_gc_scan_queue')) { // We need to scan the event queue. If $AppUI isn't created yet // And it isn't likely that it will be, we create it and run the // queue scanner. if (!isset($AppUI)) { $AppUI = new CAppUI(); $queue = new EventQueue(); $queue->scan(); } } return true; }
/** * This function recursively updates all tasks project * to the one passed as parameter */ 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 = '" . $task_id . "'"); $sql = $q->prepare(); $q->clear(); $tasks_id = db_loadColumn($sql); if (count($tasks_id) == 0) { return true; } // update project of children $q->addTable('tasks'); $q->addUpdate('task_project', $new_project); $q->addWhere("task_parent = '" . $task_id . "'"); $q->exec(); $q->clear(); foreach ($tasks_id as $id) { if ($id != $task_id) { $this->updateSubTasksProject($new_project, $id); } } }
<?php $AppUI->savePlace(); // load the companies class to retrieved denied companies require_once $AppUI->getModuleClass('companies'); // Let's update project status! if ($perms->checkModule('projects', 'edit')) { if (isset($_GET["update_project_status"]) && isset($_GET["project_status"]) && isset($_GET["project_id"])) { $projects_id = $_GET["project_id"]; // This must be an array foreach ($projects_id as $project_id) { $r = new DBQuery(); $r->addTable('projects'); $r->addUpdate('project_status', "{$_GET['project_status']}"); $r->addWhere('project_id = ' . $project_id); $r->exec(); $r->clear(); } } } // End of project status update // retrieve any state parameters if (isset($_GET['tab'])) { $AppUI->setState('ProjIdxTab', $_GET['tab']); } $tab = $AppUI->getState('ProjIdxTab') !== NULL ? $AppUI->getState('ProjIdxTab') : 0; $active = intval(!$AppUI->getState('ProjIdxTab')); if (isset($_POST['company_id'])) { $AppUI->setState('ProjIdxCompany', intval($_POST['company_id'])); } $company_id = $AppUI->getState('ProjIdxCompany') !== NULL ? $AppUI->getState('ProjIdxCompany') : $AppUI->user_company;