Пример #1
0
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * This script is a quick 'n' dirty list of Instructor queues, who's online,
 * and meeting links.
 *
 * @package     block_helpmenow
 * @copyright   2012 VLACS
 * @author      David Zaharee <*****@*****.**>
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once dirname(__FILE__) . '/lib.php';
helpmenow_plugin::get_plugins();
# require login
require_login(0, false);
# contexts and cap check
$context = context_system::instance();
$admin = has_capability(HELPMENOW_CAP_MANAGE, $context);
if (!($admin or $DB->record_exists('block_helpmenow_helper', array('userid' => $USER->id)))) {
    redirect();
}
$PAGE->set_context($context);
$PAGE->set_url('/blocks/helpmenow/hallway.php');
$PAGE->set_pagelayout('standard');
# title, navbar, and a nice box
if (!empty($CFG->helpmenow_title)) {
    $blockname = $CFG->helpmenow_title;
} else {
Пример #2
0
    function get_content()
    {
        global $OUTPUT;
        if ($this->content !== NULL) {
            return $this->content;
        }
        global $CFG, $USER, $SESSION, $DB;
        $this->content = (object) array('text' => '', 'footer' => '');
        $this->content->text .= '<noscript>' . get_string('noscript', 'block_helpmenow') . '</noscript>';
        # the first time a user loads the block this session try to popout
        helpmenow_clean_sessions();
        # clean up users sessions
        $popout_url = "{$CFG->wwwroot}/blocks/helpmenow/popout.php";
        $contact_list = helpmenow_contact_list::get_plugin();
        $contact_list::update_contacts($USER->id);
        # do stuff that stuff that should be done when a user first logs in
        if (!isset($SESSION->helpmenow_first_load)) {
            $SESSION->helpmenow_first_load = true;
            # try to popout the interface (except if the user is not logged in)
            if (!empty($USER->id)) {
                $this->content->text .= <<<EOF
<script>
    try {
        var popout = window.open('', 'hmn_popout', 'menubar=0,location=0,scrollbars,resizable,width=250,height=400');
        if (popout.location.href == "about:blank" || typeof popout.location === 'undefined') {
            popout.location = "{$popout_url}";
        }
    } catch (error) {
    }
</script>
EOF;
            }
            # update the users contacts
        }
        $this->content->text .= helpmenow_block_interface();
        $break = false;
        if ($contact_list_display = $contact_list::block_display()) {
            $this->contect->footer .= $contact_list_display;
            $break = true;
        }
        # admin link
        $sitecontext = context_system::instance();
        if (has_capability(HELPMENOW_CAP_MANAGE, $sitecontext)) {
            $admin = "{$CFG->wwwroot}/blocks/helpmenow/admin/manage_queues.php";
            $admin_text = get_string('admin_link', 'block_helpmenow');
            if ($break) {
                $this->content->footer .= "<br />";
            } else {
                $break = true;
            }
            $this->content->footer .= "<a href='{$admin}'>{$admin_text}</a>";
        }
        # "hallway" link
        if (has_capability(HELPMENOW_CAP_MANAGE, $sitecontext) or $DB->record_exists('block_helpmenow_helper', array('userid' => $USER->id))) {
            $who = get_string('who', 'block_helpmenow');
            if ($break) {
                $this->content->footer .= "<br />";
            } else {
                $break = true;
            }
            $this->content->footer .= "<a href='{$CFG->wwwroot}/blocks/helpmenow/hallway.php'>{$who}</a>";
        }
        # Chat histories link
        $chathistories = get_string('chathistories', 'block_helpmenow');
        if ($break) {
            $this->content->footer .= "<br />";
        } else {
            $break = true;
        }
        $chat_history_url = new moodle_url("{$CFG->wwwroot}/blocks/helpmenow/chathistorylist.php");
        $chat_history_url->param('userid', $USER->id);
        $this->content->footer .= "<a href=" . $chat_history_url->out() . ">{$chathistories}</a>";
        if ($contact_list::is_admin_or_teacher()) {
            # call plugin methods to check for additional display information
            foreach (helpmenow_plugin::get_plugins() as $pluginname) {
                $class = "helpmenow_plugin_{$pluginname}";
                if ($plugindisplay = $class::block_display()) {
                    if ($break) {
                        $this->content->footer .= "<br />";
                    } else {
                        $break = true;
                    }
                    $this->content->footer .= $plugindisplay;
                }
            }
        }
        $this->content->footer .= <<<EOF
<div id="helpmenow_last_refresh_div"></div>
<div class="helpmenow_textalignright">
    <div class="helpmenow_floatleft">
        <a href="javascript:void(0)" onclick="helpmenow.chime();">
            <img src="{$CFG->wwwroot}/blocks/helpmenow/media/Bell.png" />
        </a>
    </div>
EOF;
        $popout = get_string('popout', 'block_helpmenow');
        $action = new popup_action('click', $popout_url, 'hmn_popout', array('height' => 400, 'width' => 250));
        $this->content->footer .= $OUTPUT->action_link($popout_url, $popout, $action) . '</div>';
        return $this->content;
    }
Пример #3
0
} 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)) {
        continue;
    }
    $returned = $class::$method();
    if (!is_bool($returned)) {
        $redirects[$pluginname] = $returned;
    }
}
if (count($redirects) == 0) {
    helpmenow_fatal_error(get_string('may_close', 'block_helpmenow'), true, true);
}
if (count($redirects) == 1) {
    redirect(reset($redirects));
Пример #4
0
/**
 * plugin functions
 *
 * @param object $request request from client
 * @param object $response response
 */
function helpmenow_serverfunc_plugin($request, &$response)
{
    $plugin = $request->plugin;
    $class = "helpmenow_plugin_{$plugin}";
    $plugin_function = $request->plugin_function;
    if (!in_array($plugin, helpmenow_plugin::get_plugins())) {
        throw new Exception('Unknown plugin');
    }
    if (!in_array($plugin_function, $class::get_ajax_functions())) {
        throw new Exception('Unknown function');
    }
    $response = (object) array_merge((array) $response, (array) $plugin_function($request));
}