public function store(CAppUI $AppUI = null) { global $AppUI; $perms = $AppUI->acl(); $stored = false; $this->_error = $this->check(); if (count($this->_error)) { return $this->_error; } $q = new w2p_Database_Query(); if ($this->message_id && $perms->checkModuleItem('forums', 'edit', $this->forum_id)) { $q->setDelete('forum_visits'); $q->addWhere('visit_message = ' . (int) $this->message_id); $q->exec(); if ($msg = parent::store()) { return $msg; } $stored = true; } if (0 == $this->message_id && $perms->checkModuleItem('forums', 'add')) { $this->message_date = $q->dbfnNowWithTZ(); if ($msg = parent::store()) { return $msg; } $q->addTable('forum_messages'); $q->addQuery('count(message_id), MAX(message_date)'); $q->addWhere('message_forum = ' . (int) $this->message_forum); $reply = $q->fetchRow(); //update forum descriptor $forum = new CForum(); $forum->load($AppUI, $this->message_forum); $forum->forum_message_count = $reply[0]; /* * Note: the message_date here has already been adjusted for the * timezone above, so don't do it again! */ $forum->forum_last_date = $this->message_date; $forum->forum_last_id = $this->message_id; $forum->store($AppUI); $this->sendWatchMail(false); $stored = true; } return $stored; }
public function update_dep_dates($task_id) { $q = new w2p_Database_Query(); $newTask = new CTask(); $newTask->load($task_id); // Do not update tasks that are not tracking dependencies if (!in_array($newTask->task_dynamic, self::$tracking_dynamics)) { return; } // load original task dates and calculate task time span $tsd = new w2p_Utilities_Date($newTask->task_start_date); $ted = new w2p_Utilities_Date($newTask->task_end_date); $duration = $tsd->calcDuration($ted); // reset start date $nsd = new w2p_Utilities_Date($newTask->get_deps_max_end_date($newTask)); // prefer Wed 8:00 over Tue 16:00 as start date $nsd = $nsd->next_working_day(); $new_start_date = $nsd->format(FMT_DATETIME_MYSQL); // Add task time span to End Date again $ned = new w2p_Utilities_Date(); $ned->copy($nsd); $ned->addDuration($duration, '1'); // make sure one didn't land on a non-working day $ned = $ned->next_working_day(true); // prefer tue 16:00 over wed 8:00 as an end date $ned = $ned->prev_working_day(); $new_end_date = $ned->format(FMT_DATETIME_MYSQL); // update the db $q->addTable('tasks'); $q->addUpdate('task_start_date', $new_start_date); $q->addUpdate('task_end_date', $new_end_date); $q->addUpdate('task_updated', "'" . $q->dbfnNowWithTZ() . "'", false, true); $q->addWhere('task_dynamic <> 1 AND task_id = ' . (int) $task_id); $q->exec(); $q->clear(); if ($newTask->task_parent != $newTask->task_id) { $newTask->updateDynamics(); } return; }
</a> </td> </tr> </table> <?php } ?> </td> <?php if (w2PgetParam($_REQUEST, 'tab', 0) == 0) { ?> <td> <?php $q = new w2p_Database_Query(); $q->addTable('user_access_log', 'ual'); $q->addQuery('user_access_log_id, ( unix_timestamp( \'' . $q->dbfnNowWithTZ() . '\' ) - unix_timestamp( date_time_in ) ) / 3600 as hours, ( unix_timestamp( \'' . $q->dbfnNowWithTZ() . '\' ) - unix_timestamp( date_time_last_action ) ) / 3600 as idle, if(isnull(date_time_out) or date_time_out =\'0000-00-00 00:00:00\',\'1\',\'0\') as online'); $q->addWhere('user_id = ' . (int) $row['user_id']); $q->addOrder('user_access_log_id DESC'); $q->setLimit(1); $user_logs = $q->loadList(); if ($user_logs) { foreach ($user_logs as $row_log) { if ($row_log['online'] == '1') { echo '<span style="color: green">' . $row_log['hours'] . ' ' . $AppUI->_('hrs.') . '( ' . $row_log['idle'] . ' ' . $AppUI->_('hrs.') . ' ' . $AppUI->_('idle') . ') - ' . $AppUI->_('Online'); } else { echo '<span style="color: red">' . $AppUI->_('Offline'); } } } else { echo '<span style="color: grey">' . $AppUI->_('Never Visited'); }
} $action = $_REQUEST['action']; $q = new w2p_Database_Query(); if ($action) { $history_description = w2PgetParam($_POST, 'history_description', ''); $history_project = (int) w2PgetParam($_POST, 'history_project', 0); $userid = $AppUI->user_id; $perms =& $AppUI->acl(); if ($action == 'add') { if (!canAdd('history')) { $AppUI->redirect('m=public&a=access_denied'); } $q->addTable('history'); $q->addInsert('history_table', "history"); $q->addInsert('history_action', "add"); $q->addInsert('history_date', "'" . $q->dbfnNowWithTZ() . "'"); $q->addInsert('history_description', $history_description); $q->addInsert('history_user', $userid); $q->addInsert('history_project', $history_project); $okMsg = 'History added'; } elseif ($action == 'update') { if (!canEdit('history')) { $AppUI->redirect('m=public&a=access_denied'); } $q->addTable('history'); $q->addUpdate('history_description', $history_description); $q->addUpdate('history_project', $history_project); $q->addWhere('history_id =' . $history_id); $okMsg = 'History updated'; } elseif ($action == 'del') { if (!canDelete('history')) {
/** * @Function for update table user_acces_log in field date_time_lost_action */ public function updateLastAction($last_insert_id) { if ($last_insert_id > 0) { $q = new w2p_Database_Query(); $q->addTable('user_access_log'); $q->addUpdate('date_time_last_action', "'" . $q->dbfnNowWithTZ() . "'", false, true); $q->addWhere('user_access_log_id = ' . $last_insert_id); $q->exec(); } }
public function store(CAppUI $AppUI = null) { global $AppUI; $perms = $AppUI->acl(); $stored = false; $this->w2PTrimAll(); // ensure changes of state in checkboxes is captured $this->project_active = (int) $this->project_active; $this->project_private = (int) $this->project_private; $this->project_target_budget = filterCurrency($this->project_target_budget); $this->project_actual_budget = filterCurrency($this->project_actual_budget); // Make sure project_short_name is the right size (issue for languages with encoded characters) $this->project_short_name = mb_substr($this->project_short_name, 0, 10); if (empty($this->project_end_date)) { $this->project_end_date = null; } $this->_error = $this->check(); if (count($this->_error)) { return $this->_error; } $this->project_id = (int) $this->project_id; // convert dates to SQL format first if ($this->project_start_date) { $date = new w2p_Utilities_Date($this->project_start_date); $this->project_start_date = $date->format(FMT_DATETIME_MYSQL); } if ($this->project_end_date) { $date = new w2p_Utilities_Date($this->project_end_date); $date->setTime(23, 59, 59); $this->project_end_date = $date->format(FMT_DATETIME_MYSQL); } if ($this->project_actual_end_date) { $date = new w2p_Utilities_Date($this->project_actual_end_date); $this->project_actual_end_date = $date->format(FMT_DATETIME_MYSQL); } // check project parents and reset them to self if they do not exist if (!$this->project_parent) { $this->project_parent = $this->project_id; $this->project_original_parent = $this->project_id; } else { $parent_project = new CProject(); $parent_project->load($this->project_parent); $this->project_original_parent = $parent_project->project_original_parent; } if (!$this->project_original_parent) { $this->project_original_parent = $this->project_id; } /* * TODO: I don't like the duplication on each of these two branches, but I * don't have a good idea on how to fix it at the moment... */ $q = new w2p_Database_Query(); $this->project_updated = $q->dbfnNowWithTZ(); if ($this->project_id && $perms->checkModuleItem('projects', 'edit', $this->project_id)) { if ($msg = parent::store()) { return $msg; } $stored = true; } if (0 == $this->project_id && $perms->checkModuleItem('projects', 'add')) { $this->project_created = $q->dbfnNowWithTZ(); if ($msg = parent::store()) { return $msg; } if (0 == $this->project_parent || 0 == $this->project_original_parent) { $this->project_parent = $this->project_id; $this->project_original_parent = $this->project_id; if ($msg = parent::store()) { return $msg; } } $stored = true; } //split out related departments and store them seperatly. $q = new w2p_Database_Query(); $q->setDelete('project_departments'); $q->addWhere('project_id=' . (int) $this->project_id); $q->exec(); $q->clear(); if ($this->project_departments) { foreach ($this->project_departments as $department) { if ($department) { $q->addTable('project_departments'); $q->addInsert('project_id', $this->project_id); $q->addInsert('department_id', $department); $q->exec(); $q->clear(); } } } //split out related contacts and store them seperatly. $q->setDelete('project_contacts'); $q->addWhere('project_id=' . (int) $this->project_id); $q->exec(); $q->clear(); if ($this->project_contacts) { foreach ($this->project_contacts as $contact) { if ($contact) { $q->addTable('project_contacts'); $q->addInsert('project_id', $this->project_id); $q->addInsert('contact_id', $contact); $q->exec(); $q->clear(); } } } if ($stored) { $custom_fields = new w2p_Core_CustomFields('projects', 'addedit', $this->project_id, 'edit'); $custom_fields->bind($_POST); $sql = $custom_fields->store($this->project_id); // Store Custom Fields CTask::storeTokenTask($AppUI, $this->project_id); } return $stored; }
function addHistory($table, $id, $action = 'modify', $description = '', $project_id = 0) { global $AppUI; /* * TODO: * 1) description should be something like: * command(arg1, arg2...) * The command should be as module_action * for example: * forums_new('Forum Name', 'URL') * * This way, the history module will be able to display descriptions * using locale definitions: * "forums_new" -> "New forum '%s' was created" -> "Se ha creado un nuevo foro llamado '%s'" * * 2) project_id and module_id should be provided in order to filter history entries * */ if (!w2PgetConfig('log_changes') || !$AppUI->isActiveModule('history')) { return; } $q = new w2p_Database_Query(); $q->addTable('history'); $q->addInsert('history_action', $action); $q->addInsert('history_item', $id); $q->addInsert('history_description', $description); $q->addInsert('history_user', $AppUI->user_id); $q->addInsert('history_date', "'" . $q->dbfnNowWithTZ() . "'", false, true); $q->addInsert('history_project', $project_id); $q->addInsert('history_table', $table); $q->exec(); //echo db_error(); }
public function clearUpdateKey() { global $AppUI; $q = new w2p_Database_Query(); $this->contact_updatekey = ''; $this->contact_lastupdate = $q->dbfnNowWithTZ(); $this->store($AppUI); }
/** * @param $row * * @return Array */ function __extract_from_vw_usr($row) { $q = new w2p_Database_Query(); $q->addTable('user_access_log', 'ual'); $q->addQuery('user_access_log_id, ( unix_timestamp( \'' . $q->dbfnNowWithTZ() . '\' ) - unix_timestamp( date_time_in ) ) / 3600 as hours, ( unix_timestamp( \'' . $q->dbfnNowWithTZ() . '\' ) - unix_timestamp( date_time_last_action ) ) / 3600 as idle, if(isnull(date_time_out) or date_time_out =\'0000-00-00 00:00:00\',\'1\',\'0\') as online'); $q->addWhere('user_id = ' . (int) $row['user_id']); $q->addOrder('user_access_log_id DESC'); $q->setLimit(1); $user_logs = $q->loadList(); return $user_logs; }
public function getCalendarEvents($userId, $days = 30) { /* * This list of fields - id, name, description, startDate, endDate, * updatedDate - are named specifically for the iCal creation. * If you change them, it's probably going to break. So don't do that. */ $q = new w2p_Database_Query(); $q->addQuery('e.event_id as id'); $q->addQuery('event_title as name'); $q->addQuery('event_description as description'); $q->addQuery('event_start_date as startDate'); $q->addQuery('event_end_date as endDate'); $q->addQuery("'" . $q->dbfnNowWithTZ() . "' as updatedDate"); $q->addQuery('CONCAT(\'' . W2P_BASE_URL . '/index.php?m=calendar&a=view&event_id=' . '\', e.event_id) as url'); $q->addQuery('projects.project_id, projects.project_name'); $q->addTable('events', 'e'); $q->leftJoin('projects', 'projects', 'e.event_project = projects.project_id'); $q->addWhere('(event_start_date > ' . $q->dbfnNow() . ' OR event_end_date > ' . $q->dbfnNow() . ')'); $q->addWhere('(event_start_date < ' . $q->dbfnDateAdd($q->dbfnNow(), $days, 'DAY') . ' OR event_end_date < ' . $q->dbfnDateAdd($q->dbfnNow(), $days, 'DAY') . ')'); $q->innerJoin('user_events', 'ue', 'ue.event_id = e.event_id'); $q->addWhere('ue.user_id = ' . $userId); $q->addOrder('event_start_date'); return $q->loadList(); }
public function gc() { global $AppUI; $max = $this->convertTime('max_lifetime'); $idle = $this->convertTime('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 w2p_Database_Query(); $q->addTable('user_access_log'); $q->addUpdate('date_time_out', $q->dbfnNowWithTZ()); $q2 = new w2p_Database_Query(); $q2->addTable('sessions'); $q2->addQuery('session_user'); $q2->addWhere($where); $q->addWhere('user_access_log_id IN ( ' . $q2->prepare() . ' )'); $q->exec(); $q->clear(); $q2->clear(); // Now we simply delete the expired sessions. $q->setDelete('sessions'); $q->addWhere($where); $q->exec(); $q->clear(); if (w2PgetConfig('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 w2p_Core_CAppUI(); $queue = new w2p_System_EventQueue(); $queue->scan(); } } return true; }
public function store(CAppUI $AppUI) { $perms = $AppUI->acl(); $stored = false; if (strpos($this->link_url, ':') === false && strpos($this->link_url, "//") === false) { $this->link_url = 'http://' . $this->link_url; } $this->_error = $this->check(); if (count($this->_error)) { return $this->_error; } /* * TODO: I don't like the duplication on each of these two branches, but I * don't have a good idea on how to fix it at the moment... */ $q = new w2p_Database_Query(); $this->link_date = $q->dbfnNowWithTZ(); if ($this->link_id && $perms->checkModuleItem('links', 'edit', $this->link_id)) { if ($msg = parent::store()) { return $msg; } $stored = true; } if (0 == $this->link_id && $perms->checkModuleItem('links', 'add')) { if ($msg = parent::store()) { return $msg; } $stored = true; } return $stored; }
/** * Stores the current task log in the database updating the task_log_updated * field appropriately. Then updates total hours worked cache on task. * * @return void * * @access public */ public function store(CAppUI $AppUI = null) { global $AppUI; $perms = $AppUI->acl(); $this->_error = $this->check(); if (count($this->_error)) { return $this->_error; } $q = new w2p_Database_Query(); $this->task_log_updated = $q->dbfnNowWithTZ(); if ($this->task_log_date) { $date = new w2p_Utilities_Date($this->task_log_date); $this->task_log_date = $date->format(FMT_DATETIME_MYSQL); } $dot = strpos($this->task_log_hours, ':'); if ($dot > 0) { $log_duration_minutes = sprintf('%.3f', substr($this->task_log_hours, $dot + 1) / 60.0); $this->task_log_hours = floor($this->task_log_hours) + $log_duration_minutes; } $this->task_log_hours = $this->task_log_hours; $this->task_log_costcode = cleanText($this->task_log_costcode); if ($this->task_log_id && $perms->checkModuleItem('task_log', 'edit', $this->task_log_id)) { if ($msg = parent::store()) { return $msg; } $stored = true; $this->updateHoursWorked($this->task_log_task); } if (0 == $this->task_log_id && $perms->checkModuleItem('task_log', 'add')) { $this->task_log_created = $q->dbfnNowWithTZ(); if ($msg = parent::store()) { return $msg; } $stored = true; $this->updateHoursWorked($this->task_log_task); } return $stored; }