public function store() { $this->w2PTrimAll(); $msg = $this->check(); if ($msg) { return get_class($this) . '::store-check failed - ' . $msg; } $values = parseFormatSysval($this->sysval_value, $this->sysval_key_id); //lets delete the old values $q = new w2p_Database_Query(); if ($this->sysval_key_id && $this->sysval_title) { $q->setDelete('sysvals'); $q->addWhere('sysval_key_id = ' . (int) $this->sysval_key_id); $q->addWhere('sysval_title = \'' . $this->sysval_title . '\''); if (!$q->exec()) { $q->clear(); return get_class($this) . '::store failed: ' . db_error(); } } foreach ($values as $key => $value) { $q->addTable('sysvals'); $q->addInsert('sysval_key_id', $this->sysval_key_id); $q->addInsert('sysval_title', $this->sysval_title); $q->addInsert('sysval_value_id', $key); $q->addInsert('sysval_value', $value); if (!$q->exec()) { $q->clear(); return get_class($this) . '::store failed: ' . db_error(); } $q->clear(); } return null; }
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 store($object_id) { global $db; $object_id = (int) $object_id; if ($object_id) { $this->value_intvalue = (int) $this->value_intvalue; $ins_charvalue = $this->value_charvalue == null ? '' : stripslashes($this->value_charvalue); $q = new w2p_Database_Query(); $q->addTable('custom_fields_values'); if ($this->value_id) { $q->addUpdate('value_charvalue', $ins_charvalue); $q->addUpdate('value_intvalue', $this->value_intvalue); $q->addWhere('value_id = ' . $this->value_id); } else { $q->addInsert('value_module', ''); $q->addInsert('value_field_id', $this->field_id); $q->addInsert('value_object_id', $object_id); $q->addInsert('value_charvalue', $ins_charvalue); $q->addInsert('value_intvalue', $this->value_intvalue); } $rs = $q->exec(); $q->clear(); if (!$rs) { return $db->ErrorMsg() . ' | SQL: '; } } else { return 'Error: Cannot store field (' . $this->field_name . '), associated id not supplied.'; } }
public function install() { global $AppUI; // Create holiday table $q = new w2p_Database_Query(); $q->createTable('holiday'); $q->createDefinition('( `holiday_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `holiday_user` int(10) NOT NULL DEFAULT \'0\', `holiday_type` int(10) NOT NULL DEFAULT \'0\', `holiday_annual` int(10) NOT NULL DEFAULT \'0\', `holiday_start_date` datetime NOT NULL DEFAULT \'0000-00-00 00:00:00\', `holiday_end_date` datetime NOT NULL DEFAULT \'0000-00-00 00:00:00\', `holiday_description` text, PRIMARY KEY (`holiday_id`), KEY `holiday_start_end_date` (`holiday_start_date`,`holiday_end_date`), KEY `holiday_type` (`holiday_type`), KEY `holiday_user` (`holiday_user`) ) ENGINE=MyISAM CHARACTER SET=utf8 COLLATE=utf8_general_ci '); $q->exec(); $q->clear(); // Create settings table $q->createTable('holiday_settings'); $q->createDefinition('( `holiday_manual` int(10) NOT NULL default \'0\', `holiday_auto` int(10) NOT NULL default \'0\', `holiday_driver` int(10) NOT NULL default \'-1\', `holiday_filter` int(10) NOT NULL default \'-1\', UNIQUE KEY `holiday_manual` (holiday_manual), UNIQUE KEY `holiday_auto` (holiday_auto), UNIQUE KEY `holiday_driver` (holiday_driver), UNIQUE KEY `holiday_filter` (holiday_filter) ) ENGINE=MyISAM CHARACTER SET=utf8 COLLATE=utf8_general_ci '); $q->exec(); $q->clear(); // Set default settings $q->addTable('holiday_settings'); $q->addInsert('holiday_manual', 0); $q->addInsert('holiday_auto', 0); $q->addInsert('holiday_driver', -1); $q->addInsert('holiday_filter', -1); $q->exec(); $i = 0; $user_holiday_types = array('holidays', 'sick stoppage', 'formation', 'seminar', 'mission', 'strike', 'other holiday'); foreach ($user_holiday_types as $user_holiday_type) { $q->clear(); $q->addTable('sysvals'); $q->addInsert('sysval_key_id', 1); // select list $q->addInsert('sysval_title', 'UserHolidayType'); $q->addInsert('sysval_value', $user_holiday_type); $q->addInsert('sysval_value_id', $i++); $q->exec(); } $perms = $AppUI->acl(); return $perms->registerModule('Holiday', 'holiday'); }
public function install() { $ok = true; $q = new w2p_Database_Query(); $sql = '( resource_id integer not null auto_increment, resource_name varchar(255) not null default "", resource_key varchar(64) not null default "", resource_type integer not null default 0, resource_note text not null default "", resource_max_allocation integer not null default 100, primary key (resource_id), key (resource_name), key (resource_type) )'; $q->createTable('resources', $sql); $ok = $ok && $q->exec(); $q->clear(); $sql = '( resource_type_id integer not null auto_increment, resource_type_name varchar(255) not null default "", resource_type_note text, primary key (resource_type_id) )'; $q->createTable('resource_types', $sql); $ok = $ok && $q->exec(); $q->clear(); $sql = '( resource_id integer not null default 0, task_id integer not null default 0, percent_allocated integer not null default 100, key (resource_id), key (task_id, resource_id) )'; $q->createTable('resource_tasks', $sql); $ok = $ok && $q->exec(); $q->clear(); $q->addTable('resource_types'); $q->addInsert('resource_type_name', 'Equipment'); $q->exec(); $q->addInsert('resource_type_name', 'Tool'); $q->exec(); $q->addInsert('resource_type_name', 'Venue'); $ok = $ok && $q->exec(); if (!$ok) { return false; } return null; }
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(); } }
function w2PsessionWrite($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 . '\''); if (($qid =& $q->exec()) && ($qid->fields['row_count'] > 0 || $qid->fields[0] > 0)) { $q->query = null; $q->addUpdate('session_data', $data); if (isset($AppUI)) { $q->addUpdate('session_user', (int) $AppUI->last_insert_id); } } else { $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; }
public function registerLogin() { $q = new w2p_Database_Query(); $q->addTable('user_access_log'); $q->addInsert('user_id', '' . $this->user_id); $q->addInsert('date_time_in', "'" . $q->dbfnNowWithTZ() . "'", false, true); $q->addInsert('user_ip', $_SERVER['REMOTE_ADDR']); $q->exec(); $this->last_insert_id = db_insert_id(); }
&message_parent=<?php echo $message_id; ?> &post_message=1';" /> <input type="button" class="button" value="<?php echo $AppUI->_('New Topic'); ?> " onclick="javascript:window.location='./index.php?m=forums&a=viewer&forum_id=<?php echo $forum_id; ?> &message_id=0&post_message=1';" /> <?php } ?> </td> </tr> </table> </td></tr> </table> <?php // Now we need to update the forum visits with the new messages so they don't show again. foreach ($new_messages as $msg_id) { $q = new w2p_Database_Query(); $q->addTable('forum_visits'); $q->addInsert('visit_user', $AppUI->user_id); $q->addInsert('visit_forum', $forum_id); $q->addInsert('visit_message', $msg_id); $q->addInsert('visit_date', $date->getDate()); $q->exec(); $q->clear(); }
public static function saveSettings($moduleName, $configName, $displayColumns, $displayOrder, $configValue, $configText) { if ('' == $moduleName || '' == $configName) { return false; } $q = new w2p_Database_Query(); $q->setDelete('module_config'); $q->addWhere("module_name = '{$moduleName}'"); $q->addWhere("module_config_name = '{$configName}'"); $q->exec(); $q->clear(); $i = 0; foreach ($configValue as $index => $field) { if (isset($displayColumns[$field])) { $q->addTable('module_config'); $q->addInsert('module_name', $moduleName); $q->addInsert('module_config_name', $configName); $q->addInsert('module_config_value', $field); $q->addInsert('module_config_text', $configText[$index]); $q->addInsert('module_config_order', (int) $displayOrder[$field]); $q->exec(); $q->clear(); $i++; } } }
## Change forum watches ## $watch = w2PgetParam($_POST, 'watch', ''); if ($watch) { // clear existing watches $q = new w2p_Database_Query(); $q->setDelete('forum_watch'); $q->addWhere('watch_user = '******'watch_' . $watch . ' IS NOT NULL'); if (!$q->exec()) { $AppUI->setMsg(db_error(), UI_MSG_ERROR); $q->clear(); } else { $q->clear(); foreach ($_POST as $k => $v) { if (strpos($k, 'forum_') !== false) { $q->addTable('forum_watch'); $q->addInsert('watch_user', $AppUI->user_id); $q->addInsert('watch_' . $watch, substr($k, 6)); if (!$q->exec()) { $AppUI->setMsg(db_error(), UI_MSG_ERROR); } else { $AppUI->setMsg('Watch updated', UI_MSG_OK); } $q->clear(); } } } } else { $AppUI->setMsg('Incorrect watch type passed to sql handler.', UI_MSG_ERROR); }
public function registerModule($module_name, $module_value, $section_value = 'app') { $q = new w2p_Database_Query(); $q->addTable('gacl_axo'); $q->addInsert('name', $module_name); $q->addInsert('value', $module_value); $q->addInsert('section_value', $section_value); $q->exec(); return true; }
public function install() { global $AppUI; $q = new w2p_Database_Query(); $q->createTable('links'); $q->createDefinition('( link_id int( 11 ) NOT NULL AUTO_INCREMENT , link_url varchar( 255 ) NOT NULL default "", link_project int( 11 ) NOT NULL default "0", link_task int( 11 ) NOT NULL default "0", link_name varchar( 255 ) NOT NULL default "", link_parent int( 11 ) default "0", link_description text, link_owner int( 11 ) default "0", link_date datetime default NULL , link_icon varchar( 20 ) default "obj/", link_category int( 11 ) NOT NULL default "0", PRIMARY KEY ( link_id ) , KEY idx_link_task ( link_task ) , KEY idx_link_project ( link_project ) , KEY idx_link_parent ( link_parent ) ) ENGINE = MYISAM DEFAULT CHARSET=utf8 '); $q->exec($sql); $i = 0; $linkTypes = array('Unknown', 'Document', 'Application'); foreach ($linkTypes as $linkType) { $q->clear(); $q->addTable('sysvals'); $q->addInsert('sysval_key_id', 1); $q->addInsert('sysval_title', 'LinkType'); $q->addInsert('sysval_value', $linkType); $q->addInsert('sysval_value_id', $i); $q->exec(); $i++; } $perms = $AppUI->acl(); return $perms->registerModule('Links', 'links'); }
/* $Id$ $URL$ */ if (!defined('W2P_BASE_DIR')) { die('You should not access this file directly.'); } // deny all but system admins $canEdit = canEdit('system'); if (!$canEdit) { $AppUI->redirect('m=public&a=access_denied'); } $AppUI->savePlace(); $q = new w2p_Database_Query(); if (isset($_POST['forcewatch']) && isset($_POST['forcesubmit'])) { // insert row into forum_watch for forcing Watch $q->addTable('forum_watch'); $q->addInsert('watch_user', '0'); $q->addInsert('watch_forum', '0'); $q->addInsert('watch_topic', '0'); if (!$q->exec()) { $AppUI->setMsg(db_error(), UI_MSG_ERROR); } else { $AppUI->setMsg('Watch Forced', UI_MSG_OK); } $q->clear(); $AppUI->redirect('m=forums&a=configure'); } elseif (isset($_POST['forcesubmit']) && !isset($_POST['forcewatch'])) { // delete row from forum_watch for unorcing Watch $q->setDelete('forum_watch'); $q->addWhere('watch_user = 0'); $q->addWhere('watch_forum = 0'); $q->addWhere('watch_topic = 0');
public function setContactMethods(array $methods) { $q = new w2p_Database_Query(); $q->setDelete('contacts_methods'); $q->addWhere('contact_id=' . (int) $this->contact_id); $q->exec(); $q->clear(); if (!empty($methods)) { $q = new w2p_Database_Query(); $q->addTable('contacts_methods'); $q->addInsert('contact_id', (int) $this->contact_id); foreach ($methods as $name => $value) { if (!empty($value)) { $q->addInsert('method_name', $name); $q->addInsert('method_value', $value); $q->exec(); } } $q->clear(); } }
public function createsqluser($username, $password, $email, $first, $last) { global $db, $AppUI; $c = new CContact(); $c->contact_first_name = $first; $c->contact_last_name = $last; $c->contact_order_by = $first . ' ' . $last; $c->contact_email = $email; $c->store(); $q = new w2p_Database_Query(); $q->addTable('users'); $q->addInsert('user_username', $username); $q->addInsert('user_password', $password); $q->addInsert('user_type', '1'); $q->addInsert('user_contact', $c->contact_id); if (!$q->exec()) { die($AppUI->_('Failed to create user credentials')); } $user_id = $db->Insert_ID(); $this->user_id = $user_id; $q->clear(); $acl =& $AppUI->acl(); $acl->insertUserRole($acl->get_group_id('anon'), $this->user_id); }
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(); }
/** * @param $AppUI * @param $forum_id * @param $msg_id * @param $date */ function __extract_from_forums_view_messages2($AppUI, $forum_id, $msg_id, $date) { $q = new w2p_Database_Query(); $q->addTable('forum_visits'); $q->addInsert('visit_user', $AppUI->user_id); $q->addInsert('visit_forum', $forum_id); $q->addInsert('visit_message', $msg_id); $q->addInsert('visit_date', $date->getDate()); $q->exec(); }
if (!$canEdit) { $AppUI->redirect('m=public&a=access_denied'); } $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';
public function updateAssigned($assigned) { // First remove the assigned from the user_events table global $AppUI; $q = new w2p_Database_Query(); $q->setDelete('user_events'); $q->addWhere('event_id = ' . (int) $this->event_id); $q->exec(); $q->clear(); if (is_array($assigned) && count($assigned)) { foreach ($assigned as $uid) { if ($uid) { $q->addTable('user_events', 'ue'); $q->addInsert('event_id', $this->event_id); $q->addInsert('user_id', (int) $uid); $q->exec(); $q->clear(); } } if ($msg = db_error()) { $AppUI->setMsg($msg, UI_MSG_ERROR); } } }
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; } }
/** * postsave functions are only called after a succesful save. They are * used to perform database operations after the event. */ function resource_postsave() { global $other_resources; global $obj; $task_id = $obj->task_id; if (isset($other_resources)) { $value = array(); $reslist = explode(';', $other_resources); foreach ($reslist as $res) { if ($res) { list($resource, $perc) = explode('=', $res); $value[] = array($task_id, $resource, $perc); } } // first delete any elements already there, then replace with this // list. $q = new w2p_Database_Query(); $q->setDelete('resource_tasks'); $q->addWhere('task_id = ' . (int) $obj->task_id); $q->exec(); $q->clear(); if (count($value)) { foreach ($value as $v) { $q->addTable('resource_tasks'); $q->addInsert('task_id,resource_id,percent_allocated', $v, true); $q->exec(); $q->clear(); } } } }
$mods = $AppUI->getActiveModules(); $history_active = !empty($mods['history']) && canView('history'); // Number of columns (used to calculate how many columns to span things through) $cols = 13; /**** // Let's figure out which tasks are selected */ $q = new w2p_Database_Query(); $pinned_only = (int) w2PgetParam($_GET, 'pinned', 0); if (isset($_GET['pin'])) { $pin = (int) w2PgetParam($_GET, 'pin', 0); $msg = ''; // load the record data if ($pin) { $q->addTable('user_task_pin'); $q->addInsert('user_id', $AppUI->user_id); $q->addInsert('task_id', $task_id); } else { $q->setDelete('user_task_pin'); $q->addWhere('user_id = ' . (int) $AppUI->user_id); $q->addWhere('task_id = ' . (int) $task_id); } if (!$q->exec()) { $AppUI->setMsg('ins/del err', UI_MSG_ERROR, true); } else { $q->clear(); } $AppUI->redirect('', -1); } $AppUI->savePlace(); $durnTypes = w2PgetSysVal('TaskDurationType');
public function hook_cron() { if (w2PgetConfig('system_update_check', true)) { $lastCheck = w2PgetConfig('system_update_last_check', ''); $nowDate = new DateTime("now"); if ('' == $lastCheck) { $checkForUpdates = true; } else { $systemDate = new DateTime($lastCheck); $difference = 0; //$nowDate->diff($systemDate)->format('%d'); $checkForUpdates = $difference >= 7 ? true : false; } if ($checkForUpdates) { $AppUI = new w2p_Core_CAppUI(); $configList = array(); $moduleList = $AppUI->getLoadableModuleList(); foreach ($moduleList as $module) { $configList[$module['mod_directory']] = $module['mod_version']; } $configList['w2p_ver'] = $AppUI->getVersion(); $configList['php_ver'] = PHP_VERSION; $configList['database'] = $this->_w2Pconfig['dbtype']; $configList['server'] = $_SERVER['SERVER_SOFTWARE']; $configList['connector'] = php_sapi_name(); $configList['database_ver'] = mysql_get_client_info(); $libraries = array('tidy', 'json', 'libxml', 'mysql'); foreach ($libraries as $library) { $configList[$library . '_extver'] = phpversion($library); } if (function_exists('gd_info')) { $lib_version = gd_info(); $configList['gd_extver'] = $lib_version['GD Version']; } if (function_exists('curl_version')) { $lib_version = curl_version(); $configList['curl_extver'] = $lib_version['version']; } $request = new w2p_Utilities_HTTPRequest('http://stats.web2project.net'); $request->addParameters($configList); $result = $request->processRequest(); $data = json_decode($result); $q = new w2p_Database_Query(); $q->addTable('config'); if ('' == w2PgetConfig('available_version', '')) { $q->addInsert('config_name', 'available_version'); $q->addInsert('config_value', $data->w2p_ver); $q->addInsert('config_group', 'admin_system'); $q->addInsert('config_type', 'text'); } else { $q->addUpdate('config_value', $data->w2p_ver); $q->addWhere("config_name = 'available_version'"); } $q->exec(); $q->clear(); $q->addTable('config'); $q->addUpdate('config_value', date('Y-m-d H:i:s')); $q->addWhere("config_name = 'system_update_last_check'"); $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; }
public static function pinUserTask($userId, $taskId) { $q = new w2p_Database_Query(); $q->addTable('user_task_pin'); $q->addInsert('user_id', (int) $userId); $q->addInsert('task_id', (int) $taskId); if (!$q->exec()) { return 'Error pinning task'; } else { return true; } }
/** * Add an event to the queue. * * The callback can either be the name of a global function or the * name of a class * @param mixed $callback function to call when this event is due. * @param mixed $args Arguments to pass to the callback * @param string $module module, or originator of the event * @param string $type type of event (to allow searching) * @param integer $id id of originating event. * @param integer $date Seconds since 1970 to trigger event. * @param integer $repeat_interval seconds to repeat * @param integer $repeat_count number of times to repeat * @return integer queue id */ public function add($callback, &$args, $module, $sysmodule = false, $id = 0, $type = '', $date = 0, $repeat_interval = 0, $repeat_count = 1) { global $AppUI; if (!isset($AppUI)) { $user_id = 0; } else { $user_id = $AppUI->user_id; } if (is_array($callback)) { list($class, $method) = $callback; if (is_object($class)) { $class = get_class($class); } $caller = $class . '::' . $method; } else { $caller = $callback; } $q = new w2p_Database_Query(); $q->addTable($this->table); $q->addInsert('queue_owner', $user_id); $q->addInsert('queue_start', $date); $q->addInsert('queue_callback', $caller); $q->addInsert('queue_data', serialize($args)); $q->addInsert('queue_repeat_interval', $repeat_interval); $q->addInsert('queue_repeat_count', $repeat_count); $q->addInsert('queue_module', $module); $q->addInsert('queue_type', $type); $q->addInsert('queue_origin_id', $id); if ($sysmodule) { $q->addInsert('queue_module_type', 'system'); } else { $q->addInsert('queue_module_type', 'module'); } if ($q->exec()) { $return = db_insert_id(); } else { $return = false; } $q->clear(); return $return; }
$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); $q->addInsert('method_value', $value); $q->exec(); $q->clear(); } } } $s .= '</tr>'; } $s .= '</table>'; } ldap_close($ds); } } echo $s;
public static function generateUserToken($userId, $token = '') { $q = new w2p_Database_Query(); $q->setDelete('user_feeds'); $q->addWhere('feed_user = '******'{$token}'"); $q->exec(); $q->clear(); $token = md5(time() . $userId . $token . time()); $q->addTable('user_feeds'); $q->addInsert('feed_user', $userId); $q->addInsert('feed_token', $token); $q->exec(); return true; }