public static function set() { if (self::$action) { return; } if (!isset($_SESSION['client']['__history_id__'])) { $_SESSION['client']['__history_id__'] = 0; } $data = serialize($_SESSION['client']['__module_vars__']); if (GZIP_HISTORY && function_exists('gzcompress')) { $data = gzcompress($data); } if (DB::is_postgresql()) { $data = '\'' . DB::BlobEncode($data) . '\''; } else { $data = DB::qstr($data); } DB::StartTrans(); DB::Replace('history', array('data' => $data, 'page_id' => $_SESSION['client']['__history_id__'], 'session_name' => DB::qstr(self::session_id()), 'client_id' => CID), array('session_name', 'page_id')); $_SESSION['client']['__history_id__']++; $ret = DB::Execute('SELECT page_id FROM history WHERE session_name=%s AND (page_id>=%d OR page_id<%d) AND client_id=%d', array(self::session_id(), $_SESSION['client']['__history_id__'], $_SESSION['client']['__history_id__'] - 20, CID)); while ($row = $ret->FetchRow()) { DB::Execute('DELETE FROM history WHERE session_name=%s AND page_id=%d AND client_id=%d', array(self::session_id(), $row['page_id'], CID)); } DB::CompleteTrans(); }
public static function set_home_page($homepage) { $args = func_get_args(); array_shift($args); DB::StartTrans(); foreach ($args as $home_page) { $prio = DB::GetOne('SELECT MAX(priority) FROM base_home_page') + 1; DB::Execute('INSERT INTO base_home_page (home_page, priority) VALUES (%s, %d)', array($homepage, $prio)); $home_page_id = DB::Insert_ID('base_home_page', 'id'); if (!is_array($home_page)) { $home_page = array($home_page); } foreach ($home_page as $clearance) { DB::Execute('INSERT INTO base_home_page_clearance (home_page_id, clearance) VALUES (%d, %s)', array($home_page_id, $clearance)); } } DB::CompleteTrans(); }
public static function index_record($tab, $record, $table_rows = null, $tab_id = null) { if ($tab_id === null) { $tab_id = DB::GetOne('SELECT id FROM recordbrowser_table_properties WHERE tab=%s', array($tab)); } if ($table_rows === null) { $table_rows = self::init($tab); } $record = self::record_processing($tab, $record, 'index'); if ($record) { DB::Execute('DELETE FROM recordbrowser_words_map WHERE tab_id=%d AND record_id=%d', array($tab_id, $record['id'])); $token_length = self::get_token_length(); foreach ($table_rows as $field_info) { $field = $field_info['id']; if (!isset($record[$field])) { continue; } ob_start(); $text = self::get_val($tab, $field, $record, true); ob_end_clean(); $text = mb_strtolower(html_entity_decode(strip_tags($text))); $len = mb_strlen($text); if ($len < $token_length) { continue; } for ($i = 0; $i <= $len - $token_length; $i++) { $word = mb_substr($text, $i, $token_length); if (preg_match('/[^\\p{L}0-9]/u', $word)) { continue; } DB::StartTrans(); $word_id = DB::GetOne('SELECT id FROM recordbrowser_words_index WHERE word=%s', array($word)); if (!$word_id) { DB::Execute('INSERT INTO recordbrowser_words_index(word) VALUES(%s)', array($word)); $word_id = DB::Insert_ID('recordbrowser_words_index', 'id'); } DB::CompleteTrans(); if (!$word_id) { return; } DB::Execute('INSERT INTO recordbrowser_words_map(word_id,tab_id,record_id,field_id,position) VALUES(%d,%d,%d,%d,%d)', array($word_id, $tab_id, $record['id'], $field_info['pkey'], $i)); } } } DB::Execute('UPDATE ' . $tab . '_data_1 SET indexed=1 WHERE id=%d', array($record['id'])); }
public function delete_page($id) { DB::StartTrans(); $p = DB::GetOne('SELECT position FROM '.$this->tab.'_field WHERE field=%s', array($id)); $po = DB::GetOne('SELECT processing_order FROM '.$this->tab.'_field WHERE field=%s', array($id)); DB::Execute('UPDATE '.$this->tab.'_field SET position = position-1 WHERE position > %d', array($p)); DB::Execute('UPDATE '.$this->tab.'_field SET processing_order = processing_order-1 WHERE processing_order > %d', array($po)); DB::Execute('DELETE FROM '.$this->tab.'_field WHERE field=%s', array($id)); DB::CompleteTrans(); }
public static function reset_array_positions($name) { $arr = self::get_array($name, 'key'); DB::StartTrans(); $pos = 1; foreach ($arr as $k => $v) { $id = self::get_id($name . '/' . $k); DB::Execute('UPDATE utils_commondata_tree SET position=%d WHERE id=%d', array($pos, $id)); $pos++; } DB::CompleteTrans(); }
public static function pop_queued_notification_for_cron() { DB::StartTrans(); $event_id = DB::GetOne('SELECT event_id FROM utils_watchdog_notification_queue'); DB::Execute('DELETE FROM utils_watchdog_notification_queue WHERE event_id=%d', array($event_id)); DB::CompleteTrans(); return $event_id; }
DB::Execute('ALTER TABLE recordbrowser_words_map ADD CONSTRAINT "' . $b . '" FOREIGN KEY (tab_id) REFERENCES recordbrowser_table_properties(id) ON DELETE CASCADE ON UPDATE CASCADE'); DB::CompleteTrans(); } $alter_checkpoint->set('tab_id', true); } } elseif (DB::is_mysql()) { $a = DB::GetRow('SHOW CREATE TABLE recordbrowser_words_map'); if ($alter_checkpoint->get('word_id', false) == false) { Patch::require_time(5); preg_match('/CONSTRAINT (.+) FOREIGN KEY .*word_id/', $a[1], $m); if (isset($m[1])) { DB::StartTrans(); DB::Execute('ALTER TABLE recordbrowser_words_map DROP FOREIGN KEY ' . $m[1]); DB::Execute('ALTER TABLE recordbrowser_words_map ADD FOREIGN KEY (word_id) REFERENCES recordbrowser_words_index(id) ON DELETE CASCADE ON UPDATE CASCADE'); DB::CompleteTrans(); } unset($m); $alter_checkpoint->set('word_id', true); } if ($alter_checkpoint->get('tab_id', false) == false) { Patch::require_time(5); preg_match('/CONSTRAINT (.+) FOREIGN KEY .*tab_id/', $a[1], $m); if (isset($m[1])) { DB::StartTrans(); DB::Execute('ALTER TABLE recordbrowser_words_map DROP FOREIGN KEY ' . $m[1]); DB::Execute('ALTER TABLE recordbrowser_words_map ADD FOREIGN KEY (tab_id) REFERENCES recordbrowser_table_properties(id) ON DELETE CASCADE ON UPDATE CASCADE'); DB::CompleteTrans(); } $alter_checkpoint->set('tab_id', true); } }
public static function cleanup_paste_temp() { DB::StartTrans(); $ret = DB::Execute('SELECT * FROM utils_attachment_clipboard WHERE created_on<=%T', array(date('Y-m-d H:i:s', strtotime('-1 day')))); while ($row = $ret->FetchRow()) { DB::Execute('DELETE FROM utils_attachment_clipboard WHERE id=%d', array($row['id'])); if ($row['filename']) @unlink($row['filename']); } DB::CompleteTrans(); }
public function add_applet($mod, $tab_id) { $default_dash = $this->get_module_variable('default'); if (!$default_dash && !Base_DashboardCommon::has_permission_to_manage_applets()) { return; } $pos = 0; DB::StartTrans(); if ($default_dash) { $cols = DB::GetAssoc('SELECT col,count(id) FROM base_dashboard_default_applets WHERE tab=%d GROUP BY col ORDER BY col', array($tab_id)); for ($col = 0; $col < 3 && isset($cols[$col]); $col++) { } if ($col == 3) { $col = 0; } if (isset($cols[$col])) { $pos = $cols[$col]; } DB::Execute('INSERT INTO base_dashboard_default_applets(module_name,tab,col,pos) VALUES (%s,%d,%d,%d)', array($mod, $tab_id, $col, $pos)); } else { $cols = DB::GetAssoc('SELECT col,count(id) FROM base_dashboard_applets WHERE user_login_id=%d AND tab=%d GROUP BY col ORDER BY col', array(Base_AclCommon::get_user(), $tab_id)); for ($col = 0; $col < 3 && isset($cols[$col]); $col++) { } if ($col == 3) { $col = 0; } if (isset($cols[$col])) { $pos = $cols[$col]; } DB::Execute('INSERT INTO base_dashboard_applets(user_login_id,module_name,tab,col,pos) VALUES (%d,%s,%d,%d,%d)', array(Base_AclCommon::get_user(), $mod, $tab_id, $col, $pos)); } DB::CompleteTrans(); $sett_fn = array($mod . 'Common', 'applet_settings'); $this->set_module_variable('first_conf', DB::Insert_ID('base_dashboard_' . ($this->get_module_variable('default') ? 'default_' : '') . 'applets', 'id')); $this->set_module_variable('mod_conf', $mod); }
public function edit_home_page($id = null) { if ($this->is_back()) { return false; } $counts = 5; $all_clearances = array('' => '---') + array_flip(Base_AclCommon::get_clearance(true)); $home_pages = array('' => '---'); $current_clearance = 0; $form = $this->init_module('Libs_QuickForm'); $theme = $this->init_module('Base_Theme'); $theme->assign('labels', array('and' => '<span class="joint">' . __('and') . '</span>', 'or' => '<span class="joint">' . __('or') . '</span>', 'caption' => $id ? __('Edit Home Page') : __('Add Home Page'), 'clearance' => __('Clearance requried'), 'fields' => __('Fields allowed'), 'crits' => __('Criteria required'), 'add_clearance' => __('Add clearance'), 'add_or' => __('Add criteria (or)'), 'add_and' => __('Add criteria (and)'))); $tmp = Base_HomePageCommon::get_home_pages(); $home_pages = array(); foreach ($tmp as $k => $v) { $home_pages[$k] = _V($k); } // ****** - translating home_page options $form->addElement('select', 'home_page', __('Target Home Page'), array('' => '---') + $home_pages); if ($id) { $page = DB::GetOne('SELECT home_page FROM base_home_page WHERE id=%d', array($id)); $form->setDefaults(array('home_page' => $page)); } $form->addRule('home_page', __('Field required'), 'required'); for ($i = 0; $i < $counts; $i++) { $form->addElement('select', 'clearance_' . $i, __('Clearance'), $all_clearances); } $i = 0; $clearances = DB::GetAssoc('SELECT id, clearance FROM base_home_page_clearance WHERE home_page_id=%d', array($id)); foreach ($clearances as $v) { $form->setDefaults(array('clearance_' . $i => $v)); $i++; } $current_clearance = max($i - 1, 0); if ($form->validate()) { DB::StartTrans(); $vals = $form->exportValues(); $clearances = array(); for ($i = 0; $i < $counts; $i++) { if ($vals['clearance_' . $i]) { $clearances[] = $vals['clearance_' . $i]; } } if ($id !== null) { DB::Execute('DELETE FROM base_home_page_clearance WHERE home_page_id=%d', array($id)); DB::Execute('UPDATE base_home_page SET home_page=%s WHERE id=%d', array($vals['home_page'], $id)); } else { $prio = DB::GetOne('SELECT MAX(priority) FROM base_home_page') + 1; DB::Execute('INSERT INTO base_home_page (home_page,priority) VALUES (%s, %d)', array($vals['home_page'], $prio)); $id = DB::Insert_ID('base_home_page', 'id'); } foreach ($clearances as $c) { DB::Execute('INSERT INTO base_home_page_clearance (home_page_id, clearance) VALUES (%d, %s)', array($id, $c)); } DB::CompleteTrans(); return false; } $form->add_error_closing_buttons(); $form->assign_theme('form', $theme); $theme->assign('counts', $counts); $theme->display('edit_home_pages'); load_js('modules/Base/HomePage/edit_home_pages.js'); eval_js('base_home_page__init_clearance(' . $current_clearance . ', ' . $counts . ')'); eval_js('base_home_page__initialized = true;'); Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href()); Base_ActionBarCommon::add('delete', __('Cancel'), $this->create_back_href()); return true; }