Пример #1
0
/**
 * Display the jclic applet
 *
 */
function jclic_view_applet($jclic, $context, $ispreview = false)
{
    global $OUTPUT, $PAGE, $CFG, $USER;
    $timenow = time();
    $isopen = empty($jclic->timeavailable) || $jclic->timeavailable < $timenow;
    if (!$isopen) {
        echo $OUTPUT->box(get_string('notopenyet', 'jclic', userdate($jclic->timeavailable)), 'generalbox boxaligncenter jclicdates');
        if (!$ispreview) {
            return;
        }
    }
    $isclosed = !empty($jclic->timedue) && $jclic->timedue < $timenow;
    if ($isclosed) {
        echo $OUTPUT->box(get_string('expired', 'jclic', userdate($jclic->timedue)), 'generalbox boxaligncenter jclicdates');
        if (!$ispreview) {
            return;
        }
    }
    $sessions = jclic_get_sessions($jclic->id, $USER->id);
    $attempts = count($sessions);
    if (!$ispreview && ($attempts > 0 || $isopen)) {
        echo '<br><A href="#" onclick="window.open(\'action/student_results.php?id=' . $context->instanceid . '\',\'JClic\',\'navigation=0,toolbar=0,resizable=1,scrollbars=1,width=700,height=400\');" >' . get_string('show_my_results', 'jclic') . '</A>';
    }
    $config = get_config('jclic');
    if ($jclic->maxattempts < 0 || $attempts < $jclic->maxattempts) {
        echo '<div id="jclic_applet" style="text-align:center;padding-top:10px;">';
        echo '</div>';
        if (isset($config->pluginjs) && !empty($config->pluginjs)) {
            echo '<script type="text/javascript" src="' . $config->pluginjs . '"></script>';
        } else {
            $PAGE->requires->js('/mod/jclic/jclicplugin.js');
        }
        $PAGE->requires->js('/mod/jclic/jclic.js');
        $params = get_object_vars($jclic);
        $params['jclic_url'] = jclic_get_url($jclic, $context);
        $params['jclic_path'] = jclic_get_server();
        $params['jclic_service'] = jclic_get_path() . '/mod/jclic/action/beans.php';
        $params['jclic_user'] = $USER->id;
        $params['jclic_jarbase'] = $config->jarbase;
        $params['jclic_lap'] = $config->lap;
        $params['width'] = 800;
        $params['height'] = 600;
        if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 || substr($CFG->wwwroot, 0, strlen('https')) === 'https') {
            $params['jclic_protocol'] = 'https';
        } else {
            $params['jclic_protocol'] = 'http';
        }
        $PAGE->requires->js_init_call('M.mod_jclic.init', array($params));
    } else {
        echo $OUTPUT->box(get_string('msg_noattempts', 'jclic'), 'generalbox boxaligncenter');
    }
    jclic_view_dates($jclic, $context, $timenow);
}
    }
    echo '</tbody></table><br>';
    $delid = optional_param('delete', PARAM_INT);
    if (isset($delid)) {
        jclic_delete_instance($delid);
    }
} else {
    $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https" : "http";
    echo "<script language=\"JavaScript\" src=\"{$CFG->jclic_jclicpluginjs}\" type=\"text/javascript\"></script>";
    echo '<br><A href="#" onclick="window.open(\'action/student_results.php?id=' . $id . '\',\'JClic\',\'navigation=0,toolbar=0,resizable=1,scrollbars=1,width=700,height=400\');" >' . $strshow_results . '</A>';
    $sessions = jclic_get_sessions($jclic->id, $USER->id);
    $attempts = sizeof($sessions);
    if ($jclic->maxattempts < 0 || $attempts < $jclic->maxattempts) {
        //$jclic_url = (substr($jclic->url, 0, 4)=='http')?$jclic->url:'http://'.jclic_get_server().jclic_get_path().'/file.php/'.$course->id.'/'.$jclic->url;
        echo '<div style="text-align:center;padding-top:10px;">';
        echo '<script language="JavaScript">';
        //echo "setJarBase('./dist');";
        echo "setReporter('TCPReporter','path=" . jclic_get_server() . ";service=" . jclic_get_path() . "/mod/jclic/action/beans.php;user={$USER->id};key={$jclic->id};lap={$CFG->jclic_lap};protocol={$protocol}');";
        echo "setSkin('{$jclic->skin}');";
        echo "setLanguage('{$jclic->lang}');";
        echo "setExitUrl('{$jclic->exiturl}');";
        echo "writePlugin('{$jclic_url}', '{$jclic->width}', '{$jclic->height}');";
        echo "</script>";
        echo '</div>';
    } else {
        echo "<br/><br/>" . $strnoattempts;
    }
}
echo "</p>";
/// Finish the page
print_footer($course);