public static function new_id($name, $readonly = false) { $name = trim($name, '/'); if (!$name) { return false; } $pcs = explode('/', $name); $id = -1; $current_array = ''; foreach ($pcs as $v) { if ($v === '') { continue; } $id2 = DB::GetOne('SELECT id FROM utils_commondata_tree WHERE parent_id=%d AND akey=%s', array($id, $v)); $current_array .= '/'; if ($id2 === false || $id2 === null) { $pos = self::get_array_count($current_array) + 1; DB::Execute('INSERT INTO utils_commondata_tree(parent_id,akey,readonly,position) VALUES(%d,%s,%b,%d)', array($id, $v, $readonly, $pos)); $id = DB::Insert_ID('utils_commondata_tree', 'id'); } else { $id = $id2; } $current_array .= $v; } return $id; }
public static function init() { if ((!isset($_SESSION['base_login_audit']) || !isset($_SESSION['base_login_audit_user']) || $_SESSION['base_login_audit_user'] != Acl::get_user()) && Acl::is_user()) { $now = time(); $remote_address = get_client_ip_address(); $remote_host = gethostbyaddr($remote_address); DB::Execute('INSERT INTO base_login_audit(user_login_id,start_time,end_time,ip_address,host_name) VALUES(%d,%T,%T,%s,%s)', array(Acl::get_user(), $now, $now, $remote_address, $remote_host)); $_SESSION['base_login_audit'] = DB::Insert_ID('base_login_audit', 'id'); $_SESSION['base_login_audit_user'] = Acl::get_user(); } }
public static function add($id,$parent_type,$message,$alert_on, $callback_method,$callback_args=null,$users=null) { $callback_args = isset($callback_args)?((is_array($callback_args))?$callback_args:array($callback_args)):array(); if(!isset($users)) $users = Acl::get_user(); DB::Execute('INSERT INTO utils_messenger_message(page_id,parent_module,message,callback_method,callback_args,created_on,created_by,alert_on) VALUES(%s,%s,%s,%s,%s,%T,%d,%T)',array(md5($id),$parent_type,$message,serialize($callback_method),serialize($callback_args),time(),Acl::get_user(),$alert_on)); $id = DB::Insert_ID('utils_messenger_message','id'); if(is_array($users)) { foreach($users as $k) { if(is_numeric($k) && (Base_User_SettingsCommon::get('Utils_Messenger','allow_other',$k) || Acl::get_user()==$k)) DB::Execute('INSERT INTO utils_messenger_users(message_id,user_login_id) VALUES (%d,%d)',array($id,$k)); } } elseif(is_numeric($users)) DB::Execute('INSERT INTO utils_messenger_users(message_id,user_login_id) VALUES (%d,%d)',array($id,$users)); }
public static function new_id($name,$readonly=false) { $name = trim($name,'/'); if(!$name) return false; $pcs = explode('/',$name); $id = -1; foreach($pcs as $v) { if($v==='') continue; $id2 = DB::GetOne('SELECT id FROM utils_commondata_tree WHERE parent_id=%d AND akey=%s',array($id,$v)); if($id2===false || $id2===null) { DB::Execute('INSERT INTO utils_commondata_tree(parent_id,akey,readonly) VALUES(%d,%s,%b)',array($id,$v,$readonly)); $id = DB::Insert_ID('utils_commondata_tree','id'); } else $id=$id2; } return $id; }
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 write_file($filename, $file, $link = '') { $hash = hash_file('sha512', $file); $path = self::get_storage_file_path($hash); if (file_exists($path)) { $id = DB::GetOne('SELECT id FROM utils_filestorage_files WHERE hash=%s', array($hash)); } else { copy($file, $path); DB::Execute('INSERT INTO utils_filestorage_files(filename,uploaded_on,hash) VALUES(%s,%T,%s)', array($filename, time(), $hash)); $id = DB::Insert_ID('utils_filestorage_files', 'id'); } if (!$id) { throw new Utils_FileStorage_WriteError(); } if ($link) { self::add_link($link, $id); } return $id; }
public function body($file = null, $callback = null) { if (!isset($file)) { if (!isset($this->file)) { trigger_error('You have to specify file to download', E_USER_ERROR); } $file = $this->file; } if (!isset($callback)) { if (!isset($this->callback)) { trigger_error('You have to specify callback to call on download complete', E_USER_ERROR); } $callback = $this->callback; } if (isset($_REQUEST['download_complete_' . $this->get_path()])) { $did = $this->get_module_variable('download_id'); $dd = $this->get_data_dir(); if (!isset($did) || !file_exists($dd . $did . '.tmp')) { print 'Download error.'; } else { DB::Execute('DELETE FROM utils_filedownload_files WHERE id=%d', array($did)); $tf = $dd . $did . '.tmp'; call_user_func($callback, $tf, basename($file)); @unlink($tf); } return; } $path = $this->get_path(); $id = $this->create_unique_key('stat'); print '<div id="' . $id . '"></div>'; eval_js_once('utils_filedownload_refresh = function(id,path){var stat=$(id);if(!stat || stat.innerHTML==\'Processing downloaded file\') return;' . 'new Ajax.Updater(id,\'' . $this->get_module_dir() . 'refresh.php\',{method:\'post\', parameters:{path: path}});' . 'setTimeout("utils_filedownload_refresh(\'"+id+"\',\'"+path+"\')",3000);}'); eval_js_once('utils_filedownload_check_completed = function(id){stat=document.getElementById(id);' . 'if(stat && stat.innerHTML==\'Finished\'){ stat.innerHTML=\'Processing downloaded file\';' . $this->create_href_js(array('download_complete_' . $this->get_path() => 1), __('Download finished'), 'queue') . '}setTimeout(\'utils_filedownload_check_completed("\'+id+\'")\',500);}'); DB::Execute('INSERT INTO utils_filedownload_files(path,size) VALUES (%s,-1)', array($file)); $this->set_module_variable('download_id', DB::Insert_ID('utils_downloadfile_files', 'id')); print '<iframe src="' . $this->get_module_dir() . 'download.php?' . http_build_query(array('client_id' => CID, 'path' => $path)) . '" width=0 height=0 frameborder=0>'; eval_js('utils_filedownload_refresh("' . $id . '","' . $path . '");utils_filedownload_check_completed("' . $id . '")'); }
public function save() { if ($this->isPersistent) { return true; } //TODO: add validation // Begin database transaction DB::BeginTransaction(); $success = true; if ($this->att('objid')) { // we are in UPDATE modus if (!$this->_deactivate()) { $success = false; } } // insert new version of the object... $sql = 'INSERT INTO ' . $this->tableName() . "(objid, isActive, created, createdby, modified, modifiedby, IPv4"; foreach ($this->attributes as $att) { if (!in_array($att->name, $this->metaattributes)) { $sql .= ", " . $att->name; } } $sql .= ") VALUES ("; // objid if (!$this->att("objid")) { $minimumID = date("Ymd") * 100000 + rand(0, 50000); $minimumID = 1; $sql .= "ifnull((SELECT newID FROM (SELECT MAX(objID) + 1 as 'newID' FROM " . $this->tableName() . " WHERE objID >= " . $minimumID . ") as x), " . $minimumID . ")"; $this->att("created", time()); $this->att("createdby", 1); // TODO: effectieve gebruiker invullen! $this->att("modified", $this->att("created")); $this->att("modifiedBy", 1); // TODO: effectieve gebruiker invullen! } else { $sql .= DB::qstr($this->att("objid")); $this->att("modified", time()); $this->att("modifiedBy", 1); // TODO: effectieve gebruiker invullen! if (!$this->att("created")) { $this->att("created", time()); } } // isActive $sql .= ", 1"; // created $sql .= ', FROM_UNIXTIME(' . $this->att('created') . ')'; // createdby $sql .= ', ' . DB::qstr($this->att('createdby')); // modified $sql .= ", NOW()"; // modifiedBy $sql .= ", " . DB::qstr($this->att("modifiedby")); // IPvq adres van de modification $sql .= ", " . DB::qstr($_SERVER["REMOTE_ADDR"]); // loop over the attributes here... foreach ($this->attributes as $att) { if (!in_array($att->name, $this->metaattributes)) { switch ($att->type) { case "datetime": case "date": case "time": if ($this->att($att->name) == null) { $sql .= ", NULL"; break; } else { // timestamps are in unixtimestamp in php $sql .= ", FROM_UNIXTIME(" . $this->att($att->name) . ")"; break; } case "varchar": case "bigint": case "int": case "tinyint": case "text": case "decimal": $sql .= ", " . DB::qstr($this->att($att->name)); break; default: throw new Exception("Datatype " . $att->type . " not supported for " . get_class($this) . "." . $att->name); } } } $sql .= ")"; // end of values try { DB::Execute($sql); } catch (Exception $e) { // catching exception and returning false... echo $e->getMessage(); $success = false; } if ($success && !$this->att("objID")) { // we have a new object id... // let's get it from the database $sql = "SELECT objId as id FROM " . $this->tableName() . " WHERE seqid = " . DB::Insert_ID(); $rs = DB::Execute($sql); $this->att("objID", $rs->fields["id"]); } DB::Commit($success); return $success; }
public static function new_event($category_name, $id, $message) { if (self::$disabled) { return; } $category_id = self::get_category_id($category_name, false); if (!$category_id) { return; } DB::Execute('INSERT INTO utils_watchdog_event (category_id, internal_id, message, event_time) VALUES (%d,%d,%s,%T)', array($category_id, $id, $message, time())); $event_id = DB::Insert_ID('utils_watchdog_event', 'id'); $count = DB::GetOne('SELECT COUNT(*) FROM utils_watchdog_event WHERE category_id=%d AND internal_id=%d', array($category_id, $id)); if ($count == 1) { $subscribers = self::get_subscribers($category_id); foreach ($subscribers as $s) { self::user_subscribe($s, $category_name, $id); } } Utils_WatchdogCommon::notified($category_name, $id); self::queue_notification_for_cron($event_id); }
$view_doc = $view_row[1]?$view_row[1]:''; } DB::CompleteTrans(); $wait = 15; $time = microtime(true); if ($view_doc==='' && $wait > 0) { sleep(1); $view_doc = DB::GetOne('SELECT view_link FROM utils_attachment_googledocs WHERE note_id=%d', array($id)); if (!$view_doc) $view_doc = ''; $wait--; } if (!$view_doc) { if (!isset($uag_id)) { DB::Execute('INSERT INTO utils_attachment_googledocs (view_link, note_id, doc_id) VALUES (%s, %d, %s)', array('', $id, '')); $uag_id = DB::Insert_ID('utils_attachment_googledocs','id'); } $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $headers = array( "Authorization: GoogleLogin auth=" . $g_auth, "GData-Version: 3.0", ); curl_setopt($curl, CURLOPT_URL, "https://docs.google.com/feeds/default/private/full?showfolders=true"); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POST, false); $response = curl_exec($curl);
$val = null; } else { $table = 'base_dashboard_applets'; $val = $user; } foreach ($x['ab_item'] as $pos => $id) { if (is_numeric($id)) { $vals = array($pos, $_POST['col'], $id); if ($val) { $vals[] = $val; } DB::Execute('UPDATE ' . $table . ' SET pos=%d, col=%d WHERE id=%d' . ($val ? ' AND user_login_id=%d' : ''), $vals); } elseif (strpos($id, 'new_') === 0) { $id = substr($id, 4); $cleanId = str_replace('-', '_', $id); $vals = array($cleanId, $tab, $_POST['col'], $pos); if ($val) { $vals[] = $val; } DB::Execute('INSERT INTO ' . $table . '(module_name,tab,col,pos' . ($val ? ',user_login_id' : '') . ') VALUES (%s,%d,%d,%d' . ($val ? ',%d' : '') . ')', $vals); $new_id = DB::Insert_ID('base_dashboard_applets', 'id'); print 'if(jq("#copy_ab_item_new_' . $id . '").length>0){' . 'jq("#copy_dashboard_remove_applet_' . $id . '").attr("onclick","if(confirm(\'' . __('Delete this applet?') . '\'))remove_applet(' . $new_id . ',' . ($default ? 1 : 0) . ');")' . '.show("fade",300);' . 'jq("#copy_dashboard_applet_content_' . $id . '").hide("blind",300);' . 'jq("#copy_dashboard_remove_applet_' . $id . '").attr("id","dashboard_remove_applet_' . $new_id . '");' . 'jq("#copy_dashboard_applet_content_' . $id . '").attr("id","dashboard_applet_content_' . $new_id . '");' . 'jq("#copy_ab_item_new_' . $id . '").attr("id","ab_item_' . $new_id . '");' . '}'; } } } elseif ($_POST['col'] == 'new') { foreach ($x['ab_item'] as $pos => $id) { if (is_numeric($id)) { Base_DashboardCommon::remove_applet($id, $default); } } }
public static function add_permission($name) { $args = func_get_args(); array_shift($args); $perm_id = DB::GetOne('SELECT id FROM base_acl_permission WHERE name=%s', array($name)); if (!$perm_id) { DB::Execute('INSERT INTO base_acl_permission (name) VALUES (%s)', array($name)); $perm_id = DB::Insert_ID('base_acl_permission', 'id'); } foreach ($args as $rule) { DB::Execute('INSERT INTO base_acl_rules (permission_id) VALUES (%d)', array($perm_id)); $rule_id = DB::Insert_ID('base_acl_rules', 'id'); if (!is_array($rule)) { $rule = array($rule); } foreach ($rule as $clearance) { DB::Execute('INSERT INTO base_acl_rules_clearance (rule_id, clearance) VALUES (%d, %s)', array($rule_id, $clearance)); } } }
* Use this module if you want to add attachments to some page. * @author Arkadiusz Bisaga <*****@*****.**> * @copyright Copyright © 2012, Telaxus LLC * @license MIT * @version 1.0 * @package epesi-utils * @subpackage attachment */ if (!isset($_REQUEST['cid']) || !isset($_REQUEST['data'])) { die('Invalid usage'); } define('CID', $_REQUEST['cid']); define('READ_ONLY_SESSION', true); require_once '../../../include.php'; ModuleManager::load_modules(); if (!Acl::is_user()) { die('Permission denied'); } $targetDir = Utils_AttachmentCommon::get_temp_dir(); Utils_AttachmentCommon::cleanup_paste_temp(); DB::Execute('INSERT INTO utils_attachment_clipboard (created_by) VALUES (%d)', array(Acl::get_user())); $id = DB::Insert_ID('utils_attachment_clipboard', 'id'); $filename = 'clipboard' . '_' . $id; $f_filename = $targetDir . '/' . $filename; DB::Execute('UPDATE utils_attachment_clipboard SET filename=%s WHERE id=%d', array($f_filename, $id)); $data = explode(',', $_REQUEST['data']); if (!isset($data[1])) { die('Invalid file'); } file_put_contents($f_filename, base64_decode($data[1])); die(json_encode(array('id' => $id, 'name' => __('clipboard') . '.png')));
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; }
public function edit_rule($r_id, $p_id = null) { if ($this->is_back()) { return false; } $counts = 5; $all_clearances = array('' => '---') + array_flip(Base_AclCommon::get_clearance(true)); $translated_permission_names = array(); foreach (DB::GetAssoc('SELECT id, name FROM base_acl_permission ORDER BY name ASC') as $k => $v) { $translated_permission_names[$k] = _V($v); } $perms = array('' => '---') + $translated_permission_names; $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' => $r_id ? __('Edit permission rule') : __('Add permission rule'), 'clearance' => __('Clearance requried'), 'fields' => __('Fields allowed'), 'crits' => __('Criteria required'), 'add_clearance' => __('Add clearance'), 'add_or' => __('Add criteria (or)'), 'add_and' => __('Add criteria (and)'))); $form->addElement('select', 'permission', __('Permission'), $perms); if ($p_id) { $form->setDefaults(array('permission' => $p_id)); $form->freeze('permission'); } else { $form->addRule('permission', __('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_acl_rules_clearance WHERE rule_id=%d', array($r_id)); foreach ($clearances as $v) { $form->setDefaults(array('clearance_' . $i => $v)); $i++; } $current_clearance = max($i - 1, 0); if ($form->validate()) { $vals = $form->exportValues(); $clearances = array(); for ($i = 0; $i < $counts; $i++) { if ($vals['clearance_' . $i]) { $clearances[] = $vals['clearance_' . $i]; } } if ($r_id !== null) { DB::Execute('DELETE FROM base_acl_rules_clearance WHERE rule_id=%d', array($r_id)); } else { if (!$p_id) { $p_id = $vals['permission']; } DB::Execute('INSERT INTO base_acl_rules (permission_id) VALUES (%d)', array($p_id)); $r_id = DB::Insert_ID('base_acl_rules', 'id'); } foreach ($clearances as $c) { DB::Execute('INSERT INTO base_acl_rules_clearance (rule_id, clearance) VALUES (%d, %s)', array($r_id, $c)); } return false; } $form->add_error_closing_buttons(); $form->assign_theme('form', $theme); $theme->assign('counts', $counts); $theme->display('edit_permissions'); load_js('modules/Base/Acl/edit_permissions.js'); eval_js('base_acl__init_clearance(' . $current_clearance . ', ' . $counts . ')'); eval_js('base_acl__initialized = true;'); Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href()); Base_ActionBarCommon::add('delete', __('Cancel'), $this->create_back_href()); return true; }
public static function new_event($category_name, $id, $message) { if(self::$disabled) return; $category_id = self::get_category_id($category_name, false); if (!$category_id) return; DB::Execute('INSERT INTO utils_watchdog_event (category_id, internal_id, message, event_time) VALUES (%d,%d,%s,%T)',array($category_id,$id,$message,time())); $event_id = DB::Insert_ID('utils_watchdog_event', 'id'); Utils_WatchdogCommon::notified($category_name,$id); $count = DB::GetOne('SELECT COUNT(*) FROM utils_watchdog_event WHERE category_id=%d AND internal_id=%d', array($category_id,$id)); if ($count==1) { $subscribers = self::get_subscribers($category_id); foreach ($subscribers as $s) self::user_subscribe($s, $category_name, $id); } $subscribers = self::get_subscribers($category_name, $id); $c_user = Acl::get_user(); self::email_mode(true); foreach ($subscribers as $user_id) { if ($user_id==$c_user) continue; $wants_email = Base_User_SettingsCommon::get('Utils_Watchdog', 'email', $user_id); if (!$wants_email) continue; Acl::set_user($user_id); Base_LangCommon::load(); $email_data = self::display_events($category_id, array($event_id => $message), $id, true); if (!$email_data) continue; $contact = Utils_RecordBrowserCommon::get_id('contact', 'login', $user_id); if (!$contact) continue; $email = Utils_RecordBrowserCommon::get_value('contact', $contact, 'email'); if (!$email) continue; $title = __('%s notification - %s - %s', array(EPESI, $email_data['category'], strip_tags($email_data['title']))); Base_MailCommon::send($email, $title, $email_data['events'], null, null, true); } Acl::set_user($c_user); Base_LangCommon::load(); self::email_mode(false); }
public static function set_default_applets() { $tabs = DB::GetAll('SELECT id,pos,name FROM base_dashboard_default_tabs'); foreach ($tabs as $tab) { DB::Execute('INSERT INTO base_dashboard_tabs(user_login_id,pos,name) VALUES(%d,%d,%s)', array(Base_AclCommon::get_user(), $tab['pos'], $tab['name'])); $id = DB::Insert_ID('base_dashboard_tabs', 'id'); $ret = DB::GetAll('SELECT id,module_name,col,color,tab FROM base_dashboard_default_applets WHERE tab=%d ORDER BY pos', array($tab['id'])); foreach ($ret as $row) { DB::Execute('INSERT INTO base_dashboard_applets(module_name,col,user_login_id,color,tab) VALUES(%s,%d,%d,%d,%d)', array($row['module_name'], $row['col'], Base_AclCommon::get_user(), $row['color'], $id)); $ins_id = DB::Insert_ID('base_dashboard_applets', 'id'); $ret_set = DB::GetAll('SELECT name,value FROM base_dashboard_default_settings WHERE applet_id=%d', array($row['id'])); foreach ($ret_set as $row_set) { DB::Execute('INSERT INTO base_dashboard_settings(applet_id,value,name) VALUES(%d,%s,%s)', array($ins_id, $row_set['value'], $row_set['name'])); } } } }
public function edit($row) { if($this->is_back()) $this->pop_box0(); $f = $this->init_module('Libs/QuickForm'); if($row) { $a = Base_RegionalSettingsCommon::time2reg($row['alert_on'],true,true,true,false); $f->setDefaults(array_merge($row,array('alert_date'=>$a,'alert_time'=>$a))); } else { $tt = $this->def_date; $tt = $tt-$tt%300; $f->setDefaults(array('alert_date'=>$tt,'alert_time'=>$tt)); } $f->addElement('textarea', 'message', __('Message')); $f->addElement('datepicker', 'alert_date', __('Alert date')); $lang_code = Base_LangCommon::get_lang_code(); $time_format = Base_RegionalSettingsCommon::time_12h()?'h:i a':'H:i'; $f->addElement('date', 'alert_time', __('Alert time'), array('format'=>$time_format, 'optionIncrement' => array('i' => 5), 'language'=>$lang_code)); if(is_array($this->users)) { foreach($this->users as $k=>$r) { if(!Base_User_SettingsCommon::get($this->get_type(),'allow_other',$k) && Acl::get_user()!=$k) unset($this->users[$k]); } $f->addElement('multiselect', 'users', __('Assigned users'), $this->users); $f->addRule('users', __('At least one user must be assigned to an alarm.'), 'required'); $f->setDefaults(array('users'=>array_keys($this->users))); } if($f->validate()) { $ret = $f->exportValues(); if($row) $ret = array_merge($row,$ret); if(Base_RegionalSettingsCommon::time_12h()) $ret['alert_on'] = strtotime($ret['alert_date'])+($ret['alert_time']['h']%12)*3600+(($ret['alert_time']['a']=='pm')?(3600*12):0)+$ret['alert_time']['i']*60; else $ret['alert_on'] = strtotime($ret['alert_date'])+$ret['alert_time']['H']*3600+$ret['alert_time']['i']*60; $ret['alert_on'] = Base_RegionalSettingsCommon::reg2time(date('Y-m-d H:i:s',$ret['alert_on'])); if($row) { DB::Execute('UPDATE utils_messenger_message SET message=%s,alert_on=%T WHERE page_id=\''.$this->mid.'\' AND id=%d',array($ret['message'],$ret['alert_on'],$row['id'])); $id = $row['id']; DB::Execute('DELETE FROM utils_messenger_users WHERE message_id=%d',array($id)); } else { DB::Execute('INSERT INTO utils_messenger_message(page_id,parent_module,message,callback_method,callback_args,created_on,created_by,alert_on) VALUES(%s,%s,%s,%s,%s,%T,%d,%T)',array($this->mid,$this->parent_type,$ret['message'],serialize($this->callback_method),serialize($this->callback_args),time(),Acl::get_user(),$ret['alert_on'])); $id = DB::Insert_ID('utils_messenger_message','id'); } if(is_array($this->users)) { foreach($ret['users'] as $r) DB::Execute('INSERT INTO utils_messenger_users(message_id,user_login_id) VALUES (%d,%d)',array($id,$r)); } else DB::Execute('INSERT INTO utils_messenger_users(message_id,user_login_id) VALUES (%d,%d)',array($id,$this->users)); $this->pop_box0(); } Base_ActionBarCommon::add('save',__('Save'),$f->get_submit_form_href()); Base_ActionBarCommon::add('back',__('Back'),$this->create_back_href()); $f->display_as_column(); }
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 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_group($id = null) { if ($this->is_back()) { return false; } $form = $this->init_module('Libs/QuickForm', null, 'edit_group'); if (isset($id)) { $name = DB::GetOne('SELECT name FROM crm_filters_group WHERE id=%d', array($id)); $description = DB::GetOne('SELECT description FROM crm_filters_group WHERE id=%d', array($id)); $form->addElement('header', null, __('Edit group "%s"', array($name))); $contacts_def = DB::GetCol('SELECT contact_id FROM crm_filters_contacts WHERE group_id=%d', array($id)); $form->setDefaults(array('name' => $name, 'contacts' => $contacts_def, 'description' => $description)); } else { $form->addElement('header', null, __('New preset')); } $form->addElement('text', 'name', __('Name')); $form->addElement('text', 'description', __('Description')); $form->addRule('name', __('Max length of field exceeded'), 'maxlength', 128); $form->addRule('description', __('Max length of field exceeded'), 'maxlength', 256); $form->addRule('name', __('Field required'), 'required'); $form->registerRule('unique', 'callback', 'check_group_name_exists', 'CRM_Filters'); $form->addRule('name', __('Group with this name already exists'), 'unique', $id); $form->addFormRule(array($this, 'check_amount_of_records')); $form->addElement('automulti', 'contacts', __('Records of'), array('CRM_ContactsCommon', 'automulti_contact_suggestbox'), array(array(), array('CRM_ContactsCommon', 'contact_format_no_company')), array('CRM_ContactsCommon', 'contact_format_no_company')); if ($form->validate()) { $v = $form->exportValues(); if (isset($id)) { DB::Execute('UPDATE crm_filters_group SET name=%s,description=%s WHERE id=%d', array($v['name'], $v['description'], $id)); DB::Execute('DELETE FROM crm_filters_contacts WHERE group_id=%d', array($id)); } else { DB::Execute('INSERT INTO crm_filters_group(name,description,user_login_id) VALUES(%s,%s,%d)', array($v['name'], $v['description'], Acl::get_user())); $id = DB::Insert_ID('crm_filters_group', 'id'); } foreach ($v['contacts'] as $p) { DB::Execute('INSERT INTO crm_filters_contacts(group_id,contact_id) VALUES(%d,%d)', array($id, $p)); } return false; } else { Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href()); Base_ActionBarCommon::add('back', __('Cancel'), $this->create_back_href()); $form->display_as_column(); } return true; }
public static function submit_attachment($values, $mode) { static $new_values, $old_password; switch ($mode) { case 'browse': if (isset($values['id']) && isset($values['crypted']) && $values['crypted'] == false) { // store to mark as read. Do not mark it here, because // we won't get red eye in the table view self::$mark_as_read[] = $values['id']; } return $values; case 'index': if($values['crypted']) unset($values['note']); return $values; case 'adding': $values['edited_on'] = time(); return $values; case 'add': case 'edit': if(isset($values['__date'])) $values['edited_on'] = $values['__date']; else $values['edited_on'] = time(); $crypted = 0; $old_pass = ($mode=='edit' && isset($_SESSION['client']['cp'.$values['id']]))?$_SESSION['client']['cp'.$values['id']]:($mode=='add' && isset($values['clone_id']) && isset($_SESSION['client']['cp'.$values['clone_id']])?$_SESSION['client']['cp'.$values['clone_id']]:''); if((is_array($values['crypted']) && isset($values['crypted']['crypted']) && $values['crypted']['crypted']) || (!is_array($values['crypted']) && $values['crypted'])) { if(is_array($values['crypted']) && isset($values['crypted']['note_password'])) { if($values['crypted']['note_password']=='*@#old@#*') $values['crypted']['note_password'] = $old_pass; } $crypted = 1; } if(is_array($values['crypted']) && isset($values['crypted']['note_password']) && $mode=='edit' && $old_pass!=$values['crypted']['note_password']) { //reencrypt old revisions $old_notes = DB::GetAssoc('SELECT hd.edit_id,hd.old_value FROM utils_attachment_edit_history h INNER JOIN utils_attachment_edit_history_data hd ON h.id=hd.edit_id WHERE h.utils_attachment_id=%d AND hd.field="note"', array($values['id'])); foreach($old_notes as $old_id=>$old_note) { if($old_pass!=='') $old_note = Utils_AttachmentCommon::decrypt($old_note,$old_pass); if($old_note===false) continue; if($crypted && $values['crypted']['note_password']) $old_note = Utils_AttachmentCommon::encrypt($old_note,$values['crypted']['note_password']); if($old_note===false) continue; DB::Execute('UPDATE utils_attachment_edit_history_data SET old_value=%s WHERE edit_id=%d AND field="note"',array($old_note,$old_id)); } //file reencryption $old_files = DB::GetCol('SELECT uaf.id as id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d',array($values['id'])); foreach($old_files as $old_id) { $filename = DATA_DIR.'/Utils_Attachment/'.$values['id'].'/'.$old_id; $content = @file_get_contents($filename); if($content===false) continue; if($old_pass!=='') $content = Utils_AttachmentCommon::decrypt($content,$old_pass); if($content===false) continue; if($crypted && $values['crypted']['note_password']) $content = Utils_AttachmentCommon::encrypt($content,$values['crypted']['note_password']); if($content===false) continue; file_put_contents($filename,$content); } } if($crypted) { if(is_array($values['crypted']) && isset($values['crypted']['note_password'])) { $values['note'] = Utils_AttachmentCommon::encrypt($values['note'],$values['crypted']['note_password']); $values['note_password']=$values['crypted']['note_password']; } $values['crypted'] = 1; } else { $values['crypted'] = 0; } $new_values = $values; break; case 'cloning': $values['clone_id']=$values['id']; break; case 'added': if(isset($values['local'])) DB::Execute('INSERT INTO utils_attachment_local(attachment,local,func,args) VALUES(%d,%s,%s,%s)',array($values['id'],$values['local'],$values['func'],$values['args'])); $new_values = $values; break; case 'edit_changes': if(isset($values['note']) && isset($values['crypted']) && $new_values['crypted']!=$values['crypted']) { if($new_values['crypted'] && isset($new_values['note_password'])) { $values['note'] = Utils_AttachmentCommon::encrypt($values['note'],$new_values['note_password']); } elseif(!$new_values['crypted'] && isset($_SESSION['client']['cp'.$new_values['id']])) { $values['note'] = Utils_AttachmentCommon::decrypt($values['note'],$_SESSION['client']['cp'.$new_values['id']]); unset($_SESSION['client']['cp'.$new_values['id']]); } } elseif(isset($new_values['note_password']) && isset($old_password) && $new_values['note_password']!=$old_password) { $values['note'] = Utils_AttachmentCommon::decrypt($values['note'],$old_password); $values['note'] = Utils_AttachmentCommon::encrypt($values['note'],$new_values['note_password']); } break; case 'view': $ret = self::get_access($values['id']); if(!$ret) print(__('Access denied')); return $ret; case 'display': if(DB::GetOne('SELECT 1 FROM utils_attachment_file WHERE attach_id=%d',array($values['id']))) { $ret = array(); $ret['new'] = array(); $ret['new']['crm_filter'] = '<a '.Utils_TooltipCommon::open_tag_attrs(__('File history')).' '.Module::create_href(array('file_history'=>1)).'>F</a>'; if (isset($_REQUEST['file_history']) && (!$values['crypted'] || isset($_SESSION['client']['cp'.$values['id']]))) Base_BoxCommon::push_module('Utils_Attachment','file_history',array($values)); // CRM_FiltersCommon::set_profile('c'.$values['id']); return $ret; } break; case 'delete': if($values['crypted'] && !isset($_SESSION['client']['cp'.$values['id']])) { Epesi::alert(__('Cannot delete encrypted note')); return false; } $count_locals = DB::GetOne('SELECT count(DISTINCT local) FROM utils_attachment_local WHERE attachment=%d',array($values['id'])); if($count_locals>1) { $is_local = false; if(isset($_SESSION['client']['utils_attachment_group'])) $is_local = DB::GetOne('SELECT 1 FROM utils_attachment_local WHERE attachment=%d AND local=%s',array($values['id'],$_SESSION['client']['utils_attachment_group'])); if($is_local) { DB::Execute('DELETE FROM utils_attachment_local WHERE attachment=%d AND local=%s',array($values['id'],$_SESSION['client']['utils_attachment_group'])); self::new_watchdog_event($_SESSION['client']['utils_attachment_group'], '-', $values['id']); } else Epesi::alert(__('This note is attached to multiple records - please go to record and delete note there.')); location(array()); return false; } location(array()); return true; } switch($mode) { case 'edit': case 'added': if(isset($values['note_password'])) { $old_password = isset($_SESSION['client']['cp' . $values['id']]) ? $_SESSION['client']['cp' . $values['id']] : ''; $_SESSION['client']['cp'.$values['id']] = $values['note_password']; } $note_id = $values['id']; $files_dir = self::Instance()->get_data_dir().$note_id; if(isset($values['delete_files'])) $deleted_files = array_filter(explode(';',$values['delete_files'])); else $deleted_files = array(); foreach ($deleted_files as $k=>$v) $deleted_files[$k] = intVal($v); if($deleted_files) $deleted_files = array_combine($deleted_files,$deleted_files); if($mode=='added' && isset($values['clone_id'])) { //on cloning $locals = DB::Execute('SELECT local,func,args FROM utils_attachment_local WHERE attachment=%d',array($values['clone_id'])); while($local = $locals->FetchRow()) DB::Execute('INSERT INTO utils_attachment_local(attachment,local,func,args) VALUES(%d,%s,%s,%s)',array($note_id,$local['local'],$local['func'],$local['args'])); $clone_files = DB::GetAll('SELECT id,original,created_by,created_on FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($values['clone_id'])); foreach($clone_files as $file) { $cf = self::Instance()->get_data_dir().$values['clone_id'].'/'.$file['id']; if(!file_exists($cf)) continue; if(!file_exists($files_dir)) mkdir($files_dir,0777,true); DB::Execute('INSERT INTO utils_attachment_file (attach_id,deleted,original,created_by,created_on) VALUES(%d,0,%s,%d,%T)',array($note_id,$file['original'],$file['created_by'],$file['created_on'])); $new_file_id = DB::Insert_ID('utils_attachment_file','id'); if(isset($deleted_files[$file['id']])) $deleted_files[$file['id']] = $new_file_id; $cf2 = $files_dir.'/'.$new_file_id; copy($cf,$cf2); if(isset($_SESSION['client']['cp'.$values['clone_id']]) && $_SESSION['client']['cp'.$values['clone_id']]) file_put_contents($cf2,Utils_AttachmentCommon::decrypt(file_get_contents($cf2),$_SESSION['client']['cp'.$values['clone_id']])); if($values['crypted']) file_put_contents($cf2,Utils_AttachmentCommon::encrypt(file_get_contents($cf2),$values['note_password'])); } } $current_files = DB::GetAssoc('SELECT id, id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($note_id)); $remaining_files = $current_files; foreach ($deleted_files as $k=>$v) { if (!isset($remaining_files[$v])) unset($deleted_files[$k]); else unset($remaining_files[$v]); } foreach ($deleted_files as $v) DB::Execute('UPDATE utils_attachment_file SET deleted=1 WHERE id=%d', array($v)); if(isset($values['clipboard_files'])) { $clipboard_files = array_filter(explode(';',$values['clipboard_files'])); foreach ($clipboard_files as $cf_id) { $cf = DB::GetOne('SELECT filename FROM utils_attachment_clipboard WHERE id=%d', array($cf_id)); if($values['crypted']) file_put_contents($cf,Utils_AttachmentCommon::encrypt(file_get_contents($cf),$values['note_password'])); Utils_AttachmentCommon::add_file($note_id, Acl::get_user(), __('clipboard').'.png', $cf); } } $files = isset($_SESSION['client']['utils_attachment'][CID]['files'])?$_SESSION['client']['utils_attachment'][CID]['files']:array(); $_SESSION['client']['utils_attachment'][CID]['files'] = array(); foreach ($files as $f) { $file_path = $f['path']; $file_name = $f['name']; if($values['crypted']) file_put_contents($file_path,Utils_AttachmentCommon::encrypt(file_get_contents($file_path),$values['note_password'])); Utils_AttachmentCommon::add_file($note_id, Acl::get_user(), $file_name, $file_path); } $locals = DB::GetCol('SELECT local FROM utils_attachment_local WHERE attachment=%d',array($note_id)); foreach ($locals as $local) { $param = explode('/', $local); if (count($param) == 2 && preg_match('/^[1-9][0-9]*$/', $param[1])) { $subscribers = Utils_WatchdogCommon::get_subscribers($param[0], $param[1]); foreach ($subscribers as $user_id) { Utils_WatchdogCommon::user_subscribe($user_id, 'utils_attachment', $note_id); } } } break; } return $values; }