/** * Create the meeting. */ public function create_meeting() { global $CFG, $USER; $update_url = new moodle_url("{$CFG->wwwroot}/blocks/helpmenow/plugins/wiziq/update.php"); $update_url->param('user_id', $USER->id); $params = array('title' => fullname($USER), 'start_time' => date('m/d/Y G:i:s'), 'time_zone' => date('e'), 'presenter_id' => $USER->id, 'presenter_name' => fullname($USER), 'duration' => HELPMENOW_WIZIQ_DURATION, 'status_ping_url' => $update_url->out()); $response = helpmenow_wiziq_api('create', $params); if ((string) $response['status'] == 'fail') { $error = (int) $response->error['code']; $error_msg = (string) $response->error['msg']; helpmenow_log($USER->id, 'wiziq_error', "code: {$error}; msg: {$error_msg}"); switch ($error) { case 1012: helpmenow_fatal_error('License limit has been reached. Please contact your administrator'); default: helpmenow_fatal_error("WizIQ error: {$error}. Please contact your administrator.<br />Error: {$error_msg}"); } } $this->class_id = (int) $response->create->class_details->class_id; $this->presenter_url = (string) $response->create->class_details->presenter_list->presenter[0]->presenter_url; $this->duration = HELPMENOW_WIZIQ_DURATION * 60; # we're saving in seconds instead of minutes $this->timecreated = time(); $this->last_updated = time(); $this->update(); return true; }
if ($login) { helpmenow_log($USER->id, 'logged_in', $message); $record->isloggedin = time(); } else { $duration = time() - $record->isloggedin; helpmenow_log($USER->id, 'logged_out', "{$message}duration: {$duration} seconds"); $record->isloggedin = 0; } if ($queueid) { # helper $DB->update_record('block_helpmenow_helper', $record); helpmenow_log($USER->id, 'updated block_helpmenow_helper', "{$record->isloggedin}"); } else { # instructor $DB->update_record('block_helpmenow_user', $record); helpmenow_log($USER->id, 'updated block_helpmenow_user', "{$record->isloggedin}"); } /** * handle plugins' on_login/on_logout * * plugins that return true don't need anymore * plugins that return a string are giving us a url to redirect too * * if multiple plugins give us a url to redirect to, we're going to have have * to handle that by presenting links to the user instead of auto redirecting */ $redirects = array(); foreach (helpmenow_plugin::get_plugins() as $pluginname) { $class = "helpmenow_plugin_{$pluginname}"; $method = $login ? 'on_login' : 'on_logout'; if (!method_exists($class, $method)) {
/** * chat block * * @param object $request request from client * @param object $response response */ function helpmenow_serverfunc_block($request, &$response) { global $USER, $CFG, $OUTPUT, $DB; #echo "entered serverfunc_block: " . microtime() . "\n"; # DEBUGGING $DB->set_field('block_helpmenow_user', 'lastaccess', time(), array('userid' => $USER->id)); # update our user lastaccess helpmenow_log($USER->id, 'block refresh', ''); $response->last_refresh = get_string('updated', 'block_helpmenow') . ': ' . userdate(time(), '%r'); # datetime for debugging $response->pending = 0; $response->alert = false; #echo "bumped lastaccess/logged: " . microtime() . "\n"; # DEBUGGING /** * queues */ $response->queues_html = ''; $connect = new moodle_url("{$CFG->wwwroot}/blocks/helpmenow/connect.php"); $queues = helpmenow_queue::get_queues(); foreach ($queues as $q) { $response->queues_html .= '<div>'; switch ($q->get_privilege()) { case HELPMENOW_QUEUE_HELPEE: case HELPMENOW_QUEUE_HELPER: $sql = "\n SELECT s.*, m.message, m.id AS messageid\n FROM {block_helpmenow_session} s\n JOIN {block_helpmenow_session2user} s2u ON s2u.sessionid = s.id AND s2u.userid = s.createdby\n JOIN {block_helpmenow_message} m ON m.id = (\n SELECT MAX(id) FROM {block_helpmenow_message} m2 WHERE m2.sessionid = s.id AND m2.userid <> s.createdby\n )\n WHERE s.iscurrent = 1\n AND s.createdby = {$USER->id}\n AND s.queueid = {$q->id}\n AND (s2u.last_refresh + 20) < " . time() . "\n AND s2u.last_refresh < m.time\n "; if ($session = $DB->get_record_sql($sql) or $q->is_open()) { $connect->remove_params('sessionid'); $connect->param('queueid', $q->id); $message = $style = ''; if ($session) { $response->pending++; $style = ' style="background-color:yellow"'; $message = '<div style="margin-left: 1em;">' . $session->message . '</div>' . $message; if (helpmenow_notify_once($session->messageid)) { $response->alert = true; } } $response->queues_html .= "<div{$style}>" . create_popup($q->name, $connect->out(), "queue{$q->id}") . "{$message}</div>"; } else { $response->queues_html .= "<div>{$q->name}</div>"; } if ($q->get_privilege() == HELPMENOW_QUEUE_HELPEE) { break; } $instyle = $outstyle = ''; if ($q->helpers[$USER->id]->isloggedin) { $outstyle = 'style="display: none;"'; } else { $instyle = 'style="display: none;"'; } $login_url = new moodle_url("{$CFG->wwwroot}/blocks/helpmenow/login.php"); $login_url->param('queueid', $q->id); $login_url->param('login', 0); $logout = create_popup(get_string('logout', 'block_helpmenow'), $login_url->out(), "login"); $login_url->param('login', 1); $login = create_popup(get_string('login', 'block_helpmenow'), $login_url->out(), "login"); $logout_status = get_string('logout_status', 'block_helpmenow'); $response->queues_html .= <<<EOF <div style="text-align: center; font-size:small; margin-top:.5em; margin-bottom:.5em;"> <div id="helpmenow_logged_in_div_{$q->id}" {$instyle}>{$logout}</div> <div id="helpmenow_logged_out_div_{$q->id}" {$outstyle}>{$logout_status} | {$login}</div> </div> EOF; # sessions $sql = "\n SELECT u.*, s.id AS sessionid, m.message, m.time, m.id AS messageid\n FROM {block_helpmenow_session} s\n JOIN {user} u ON u.id = s.createdby\n JOIN {block_helpmenow_message} m ON m.id = (\n SELECT MAX(id) FROM {block_helpmenow_message} m2 WHERE m2.sessionid = s.id AND m2.userid = s.createdby\n )\n WHERE s.queueid = {$q->id}\n AND s.iscurrent = 1\n "; if (!($sessions = $DB->get_records_sql($sql))) { break; } $response->queues_html .= '<div style="margin-left: 1em;">'; foreach ($sessions as &$s) { $s->pending = true; $sql = "\n SELECT *\n FROM {block_helpmenow_session2user} s2u\n JOIN {user} u ON u.id = s2u.userid\n WHERE s2u.sessionid = {$s->sessionid}\n AND s2u.userid <> {$s->id}\n "; $s->helpers = $DB->get_records_sql($sql); foreach ($s->helpers as $h) { if ($s->pending) { if ($h->last_refresh + 20 > time()) { $s->pending = false; } if ($h->last_refresh > $s->time) { $s->pending = false; } } if (!isset($s->helper_names)) { $s->helper_names = fullname($h); } else { $s->helper_names .= ', ' . fullname($h); } } } unset($s); # sort by unseen messages, lastname, firstname usort($sessions, function ($a, $b) { if (!($a->pending xor $b->pending)) { return strcmp(strtolower("{$a->lastname} {$a->firstname}"), strtolower("{$b->lastname} {$b->firstname}")); } return $a->pending ? -1 : 1; }); foreach ($sessions as $s) { $connect->remove_params('queueid'); $connect->param('sessionid', $s->sessionid); $message = $style = ''; if ($s->pending) { $response->pending++; $style = ' style="background-color:yellow"'; $message .= '"' . $s->message . '"<br />'; if ($q->helpers[$USER->id]->isloggedin) { if (helpmenow_notify_once($s->messageid)) { $response->alert = true; } } } if (isset($s->helper_names)) { $message .= '<small>' . $s->helper_names . '</small><br />'; } $message = '<div style="margin-left: 1em;">' . $message . '</div>'; $response->queues_html .= "<div{$style}>" . create_popup(fullname($s), $connect->out(), $s->sessionid) . "{$message}</div>"; } $response->queues_html .= '</div>'; break; } $desc_message = '<div style="margin-left: 1em; font-size: smaller;">' . $q->description . '</div>'; $response->queues_html .= '</div>' . $desc_message . '<hr />'; } #echo "processed queues: " . microtime() . "\n"; # DEBUGGING # show the correct login state for instructors $isloggedin = $DB->get_field('block_helpmenow_user', 'isloggedin', array('userid' => $USER->id)); if (!is_null($isloggedin)) { $response->isloggedin = $isloggedin ? true : false; } # build contact list $response->users_html = ''; $sql = "\n SELECT u.*, hu.isloggedin, hu.motd, hu.lastaccess AS hmn_lastaccess\n FROM {block_helpmenow_contact} c\n JOIN {user} u ON u.id = c.contact_userid\n JOIN {block_helpmenow_user} hu ON c.contact_userid = hu.userid\n WHERE c.userid = {$USER->id}\n "; $contacts = $DB->get_records_sql($sql); if (!$contacts) { return; } #echo "selected contacts: " . microtime() . "\n"; # DEBUGGING $cutoff = helpmenow_cutoff(); foreach ($contacts as $u) { $u->online = false; if ($u->hmn_lastaccess > $cutoff and (is_null($u->isloggedin) or $u->isloggedin != 0)) { $u->online = true; $sql = "\n SELECT s.id, m.message, m.time, m.id AS messageid, s2u2.last_refresh\n FROM mdl_block_helpmenow_session2user s2u\n JOIN mdl_block_helpmenow_session s ON s.iscurrent = 1 AND s.queueid IS NULL AND s.id = s2u.sessionid\n JOIN mdl_block_helpmenow_session2user s2u2 ON s2u2.sessionid = s.id AND s2u2.userid = {$USER->id}\n JOIN mdl_block_helpmenow_message m ON m.userid = s2u.userid AND m.sessionid = s2u.sessionid\n WHERE s2u.userid = {$u->id}\n ORDER BY m.id DESC\n "; if (!($message = $DB->get_record_sql($sql))) { continue; } print_object($message); if ($message->time < $message->last_refresh + HELPMENOW_BLOCK_ALERT_DELAY) { continue; } $u->message = $message->message; $u->messageid = $message->messageid; } } #echo "selected contact messages: " . microtime() . "\n"; # DEBUGGING # sort by unseen messages, online, lastname, firstname usort($contacts, function ($a, $b) { if (isset($a->message) xor isset($b->message)) { return isset($a->message) ? -1 : 1; } if ($a->online xor $b->online) { return $a->online ? -1 : 1; } return strcmp(strtolower("{$a->lastname} {$a->firstname}"), strtolower("{$b->lastname} {$b->firstname}")); }); #echo "sorted contacts: " . microtime() . "\n"; # DEBUGGING $connect->remove_params('queueid'); $connect->remove_params('sessionid'); foreach ($contacts as $u) { $connect->param('userid', $u->id); $message = ''; $style = 'margin-left: 1em;'; if (!isset($u->isloggedin)) { # if isloggedin is null, the user is always logged in when they are online if ($u->online) { if ($isloggedin) { $name = create_popup(fullname($u), $connect->out(), $u->id); } else { $name = fullname($u); } } else { continue; } } else { # if isloggedin is set, then 0 = loggedout, any other number is the timestamp of when they logged in if ($u->online) { $name = create_popup(fullname($u), $connect->out(), $u->id); $motd = $u->motd; } else { $name = fullname($u); $motd = get_string('offline', 'block_helpmenow'); } $message .= '<div style="font-size: smaller;">' . $motd . '</div>'; } if (isset($u->message)) { $response->pending++; $style .= 'background-color:yellow;'; $message .= '<div>' . $u->message . '</div>'; if (helpmenow_notify_once($u->messageid)) { $response->alert = true; } } $message = '<div style="margin-left: 1em;">' . $message . '</div>'; $response->users_html .= "<div style=\"{$style}\">" . $name . $message . "</div>"; } #echo "printed contacts: " . microtime() . "\n"; # DEBUGGING }