예제 #1
0
 public static function update_record($tab, $id, $values, $all_fields = false, $date = null, $dont_notify = false)
 {
     DB::StartTrans();
     self::init($tab);
     $record = self::get_record($tab, $id, false);
     if (!is_array($record)) {
         return false;
     }
     $process_method_args = $values;
     $process_method_args['id'] = $id;
     foreach ($record as $k => $v) {
         if (!isset($process_method_args[$k])) {
             $process_method_args[$k] = $v;
         }
     }
     $values = self::record_processing($tab, $process_method_args, 'edit');
     $diff = array();
     self::init($tab);
     foreach (self::$table_rows as $field => $args) {
         if ($args['type'] == 'calculated' && preg_match('/^[a-z]+(\\([0-9]+\\))?$/i', $args['param']) === 0) {
             continue;
         }
         // FIXME move DB definiton to *_field table
         if ($args['id'] == 'id') {
             continue;
         }
         if (!isset($values[$args['id']])) {
             if ($all_fields) {
                 $values[$args['id']] = '';
             } else {
                 continue;
             }
         }
         if ($args['type'] == 'checkbox') {
             if ($values[$args['id']]) {
                 $values[$args['id']] = 1;
             } else {
                 $values[$args['id']] = 0;
             }
             if ($record[$args['id']]) {
                 $record[$args['id']] = 1;
             } else {
                 $record[$args['id']] = 0;
             }
         }
         if ($args['type'] == 'long text') {
             $values[$args['id']] = Utils_BBCodeCommon::optimize($values[$args['id']]);
         }
         if ($args['type'] == 'multiselect') {
             if (!is_array($values[$args['id']])) {
                 $values[$args['id']] = array($values[$args['id']]);
             }
             $array_diff = array_diff($record[$args['id']], $values[$args['id']]);
             if (empty($array_diff)) {
                 $array_diff = array_diff($values[$args['id']], $record[$args['id']]);
                 if (empty($array_diff)) {
                     continue;
                 }
             }
             $v = self::encode_multi($values[$args['id']]);
             $old = self::encode_multi($record[$args['id']]);
         } else {
             if ($record[$args['id']] === $values[$args['id']]) {
                 continue;
             }
             $v = $values[$args['id']];
             $old = $record[$args['id']];
         }
         if ($v !== '') {
             DB::Execute('UPDATE ' . $tab . '_data_1 SET f_' . $args['id'] . '=' . self::get_sql_type($args['type']) . ' WHERE id=%d', array($v, $id));
         } else {
             DB::Execute('UPDATE ' . $tab . '_data_1 SET f_' . $args['id'] . '=NULL WHERE id=%d', array($id));
         }
         $diff[$args['id']] = $old;
     }
     if (!empty($diff)) {
         @DB::Execute('UPDATE ' . $tab . '_data_1 SET indexed=0 WHERE id=%d', array($id));
         self::record_processing($tab, $values, 'edited');
     }
     if (!$dont_notify && !empty($diff)) {
         $diff = self::record_processing($tab, $diff, 'edit_changes');
         DB::Execute('INSERT INTO ' . $tab . '_edit_history(edited_on, edited_by, ' . $tab . '_id) VALUES (%T,%d,%d)', array($date == null ? date('Y-m-d G:i:s') : $date, Acl::get_user(), $id));
         $edit_id = DB::Insert_ID('' . $tab . '_edit_history', 'id');
         foreach ($diff as $k => $v) {
             if (!is_array($v)) {
                 $v = array($v);
             }
             foreach ($v as $c) {
                 DB::Execute('INSERT INTO ' . $tab . '_edit_history_data(edit_id, field, old_value) VALUES (%d,%s,%s)', array($edit_id, $k, $c));
             }
         }
         Utils_WatchdogCommon::new_event($tab, $id, 'E_' . $edit_id);
     }
     return DB::CompleteTrans();
 }
예제 #2
0
 public function chat($big = false, $uid = null)
 {
     $to =& $this->get_module_variable('to', "all");
     eval_js('shoutbox_uid="' . $to . '"');
     if (Base_AclCommon::is_user()) {
         //initialize HTML_QuickForm
         $qf = $this->init_module(Libs_QuickForm::module_name());
         /*            $myid = Base_AclCommon::get_user();
                 	if(Base_User_SettingsCommon::get('Apps_Shoutbox','enable_im')) {
                 	    $adm = Base_User_SettingsCommon::get_admin('Apps_Shoutbox','enable_im');
                 	    if(ModuleManager::is_installed('CRM_Contacts')>=0) {
                     	    $emps = DB::GetAssoc('SELECT l.id,IF(cd.f_last_name!=\'\',CONCAT(cd.f_last_name,\' \',cd.f_first_name,\' (\',l.login,\')\'),l.login) as name FROM user_login l LEFT JOIN contact_data_1 cd ON (cd.f_login=l.id AND cd.active=1) LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is '.($adm?'':'not ').'null) ORDER BY name',array($myid,serialize(1)));			    
         		        } else
             		        $emps = DB::GetAssoc('SELECT l.id,l.login FROM user_login l LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is '.($adm?'':'not ').'null) ORDER BY l.login',array($myid,serialize(1)));
             		} else $emps = array();
             		if(ModuleManager::is_installed('Tools_WhoIsOnline')>=0) {
             		    $online = Tools_WhoIsOnlineCommon::get_ids();
             		    foreach($online as $id) {
             		        if(isset($emps[$id])) 
             		            $emps[$id] = '* '.$emps[$id] ;
             		    }
             		}
                		$qf->addElement('select','to',__('To'),array('all'=>'['.__('All').']')+$emps,array('id'=>'shoutbox_to'.($big?'_big':''),'onChange'=>'shoutbox_uid=this.value;shoutbox_refresh'.($big?'_big':'').'()'));*/
         $myid = Base_AclCommon::get_user();
         if (Base_User_SettingsCommon::get('Apps_Shoutbox', 'enable_im') && ModuleManager::is_installed('Tools_WhoIsOnline') >= 0) {
             $adm = Base_User_SettingsCommon::get_admin('Apps_Shoutbox', 'enable_im');
             $online = Tools_WhoIsOnlineCommon::get_ids();
             if ($online) {
                 if (ModuleManager::is_installed('CRM_Contacts') >= 0) {
                     $emps = DB::GetAssoc('SELECT l.id,' . DB::Concat(DB::qstr("* "), DB::ifelse('cd.f_last_name!=\'\'', DB::concat('cd.f_last_name', DB::qstr(' '), 'cd.f_first_name', DB::qstr(' ('), 'l.login', DB::qstr(')')), 'l.login')) . ' as name FROM user_login l LEFT JOIN contact_data_1 cd ON (cd.f_login=l.id AND cd.active=1) LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND l.id IN (' . implode(',', $online) . ') ORDER BY name', array($myid, serialize(1)));
                 } else {
                     $emps = DB::GetAssoc('SELECT l.id,' . DB::Concat(DB::qstr("* "), 'l.login') . ' FROM user_login l LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND l.id IN (' . implode(',', $online) . ') ORDER BY l.login', array($myid, serialize(1)));
                 }
             } else {
                 $emps = array();
             }
         } else {
             $emps = array();
         }
         $e = $qf->addElement('autoselect', 'shoutbox_to', __('To'), array('all' => '[' . __('All') . ']') + $emps, array(array($this->get_type() . 'Common', 'user_search'), array()), array($this->get_type() . 'Common', 'user_format'));
         $e->setAttribute('id', 'shoutbox_to' . ($big ? '_big' : ''));
         $e->setAttribute('onChange', 'shoutbox_uid=this.value;shoutbox_refresh' . ($big ? '_big' : '') . '()');
         if (!Base_User_SettingsCommon::get('Apps_Shoutbox', 'enable_im')) {
             $qf->freeze(array('shoutbox_to'));
         }
         //create text box
         $qf->addElement($big ? 'textarea' : 'textarea', 'post', __('Message'), 'class="border_radius_6px" id="shoutbox_text' . ($big ? '_big' : '') . '"');
         $qf->addRule('post', __('Field required'), 'required');
         //create submit button
         $qf->addElement('submit', 'submit_button', __('Send'), 'id="shoutbox_button' . ($big ? '_big' : '') . '"');
         //add it
         $qf->setRequiredNote(null);
         $qf->setDefaults(array('shoutbox_to' => $to));
         $theme = $this->init_module(Base_Theme::module_name());
         $qf->assign_theme('form', $theme);
         //confirm when sending messages to all
         eval_js("jq('#shoutbox_button, #shoutbox_button_big').click(function() {\n      \t\t\t\t\tvar submit = true;\n\t\t    \t\t\tif (jq('#shoutbox_to').val() == 'all' && !confirm('" . __('Send message to all?') . "')) {\n         \t\t\t\t\tsubmit = false;\n      \t\t\t\t\t}\n\t\t    \n\t\t    \t\t\treturn submit;\t\t    \t\t\t\n\t\t\t\t\t});");
         //if submited
         if ($qf->validate()) {
             //get post group
             $msg = $qf->exportValue('post');
             $to = $qf->exportValue('shoutbox_to');
             //get msg from post group
             $msg = Utils_BBCodeCommon::optimize($msg);
             //get logged user id
             $user_id = Base_AclCommon::get_user();
             //clear text box and focus it
             eval_js('$(\'shoutbox_text' . ($big ? '_big' : '') . '\').value=\'\';focus_by_id(\'shoutbox_text' . ($big ? '_big' : '') . '\');shoutbox_uid="' . $to . '"');
             //insert to db
             DB::Execute('INSERT INTO apps_shoutbox_messages(message,base_user_login_id,to_user_login_id) VALUES(%s,%d,%d)', array(htmlspecialchars($msg, ENT_QUOTES, 'UTF-8'), $user_id, is_numeric($to) ? $to : null));
         }
     } else {
         print __('Please log in to post message') . '<br>';
         return;
     }
     $theme->assign('board', '<div id=\'shoutbox_board' . ($big ? '_big' : '') . '\'></div>');
     $theme->assign('header', __('Shoutbox'));
     $theme->display('chat_form' . ($big ? '_big' : ''));
     //if shoutbox is diplayed, call myFunctions->refresh from refresh.php file every 5s
     eval_js_once('shoutbox_refresh' . ($big ? '_big' : '') . ' = function(){if(!$(\'shoutbox_board' . ($big ? '_big' : '') . '\')) return;' . 'new Ajax.Updater(\'shoutbox_board' . ($big ? '_big' : '') . '\',\'modules/Apps/Shoutbox/refresh.php\',{method:\'get\', parameters: { uid: shoutbox_uid }});' . '};setInterval(\'shoutbox_refresh' . ($big ? '_big' : '') . '()\',' . ($big ? '10000' : '30000') . ')');
     eval_js('shoutbox_refresh' . ($big ? '_big' : '') . '()');
 }