public function applet($v, $o) { $all = Tools_WhoIsOnlineCommon::get(); $map = array(); foreach ($all as $id => $x) { $c = CRM_ContactsCommon::get_contact_by_user_id(Base_UserCommon::get_user_id($x)); if ($c) { $all[$id] = CRM_ContactsCommon::contact_format_no_company($c); $map[$id] = $c['last_name']; } else { $map[$id] = $x; } } asort($map); $c = count($all); if ($c == 1) { $o['title'] = __('%d user online', array($c)); } else { $o['title'] = __('%d users online', array($c)); } print '<ul>'; foreach ($map as $id => $x) { print '<li>' . $all[$id] . '</li>'; } print '</ul>'; }
public static function user_search($search = null) { $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,' . DB::ifelse('cd.f_last_name!=\'\'', DB::concat('cd.f_last_name', DB::qstr(' '), 'cd.f_first_name'), '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 (cd.f_first_name ' . DB::like() . ' ' . DB::concat(DB::qstr("%%"), "%s", DB::qstr("%%")) . ' OR cd.f_last_name ' . DB::like() . ' ' . DB::concat(DB::qstr("%%"), "%s", DB::qstr("%%")) . ') ORDER BY name', array($myid, serialize(1), $search, $search)); } 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) AND l.login ' . DB::like() . ' ' . DB::concat(DB::qstr("%%"), "%s", DB::qstr("%%")) . ' ORDER BY l.login', array($myid, serialize(1), $search)); } } 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]; } } } return $emps; }
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' : '') . '()'); }