Example #1
0
/**
 * Validate the data in passed in the configuration page
 * 
 * @param  $config - the information from the form mod.html
 * @return nothing , but returns an error if the configuration is wrong
 */
function liveclassroom_process_options(&$config)
{
    global $CFG, $USER;
    /*******
       we do the following verfication before submitting the configuration
       -The parameters sent can not be empty
       -The url of the server can not finish with a /
       -The url must start with http:// 
       -The api account has to valid
       ********/
    $config->servername = trim($config->servername);
    $config->adminusername = trim($config->adminusername);
    $config->adminpassword = trim($config->adminpassword);
    if (!isadmin($USER->id)) {
        wimba_add_log(WIMBA_ERROR, WC, get_string('wrongconfigurationURLunavailable', 'liveclassroom'));
        error(get_string('errormustbeadmin', 'liveclassroom'));
    }
    if (empty($config->servername)) {
        wimba_add_log(WIMBA_ERROR, WC, get_string('wrongconfigurationURLunavailable', 'liveclassroom'));
        error(get_string('wrongconfigurationURLunavailable', 'liveclassroom'), $_SERVER["HTTP_REFERER"]);
    } else {
        if (empty($config->adminusername)) {
            wimba_add_log(WIMBA_ERROR, WC, get_string('emptyAdminUsername', 'liveclassroom'));
            error(get_string('emptyAdminUsername', 'liveclassroom'), $_SERVER["HTTP_REFERER"]);
        } else {
            if (empty($config->adminpassword)) {
                wimba_add_log(WIMBA_ERROR, WC, get_string('emptyAdminPassword', 'liveclassroom'));
                error(get_string('emptyAdminPassword', 'liveclassroom'), $_SERVER["HTTP_REFERER"]);
            }
        }
    }
    $length = strlen($config->servername);
    if ($config->servername[$length - 1] == '/') {
        wimba_add_log(WIMBA_ERROR, WC, get_String('trailingSlash', 'liveclassroom'));
        error(get_String('trailingSlash', 'liveclassroom'), $_SERVER["HTTP_REFERER"]);
    }
    if (!preg_match('/^http:\\/\\//', $config->servername)) {
        wimba_add_log(WIMBA_ERROR, WC, get_String('trailingHttp', 'liveclassroom'));
        error(get_String('trailingHttp', 'liveclassroom'), $_SERVER["HTTP_REFERER"]);
    }
    $prefixUtil = new PrefixUtil();
    $prefix = $prefixUtil->getPrefix($config->adminusername);
    $api = new LCApi($config->servername, $config->adminusername, $config->adminpassword, $prefix);
    if (!$api->lcapi_authenticate()) {
        wimba_add_log(WIMBA_ERROR, WC, get_string('wrongadminpass', 'liveclassroom'));
        error(get_string('wrongadminpass', 'liveclassroom'), $_SERVER["HTTP_REFERER"]);
    }
    $domxml = false;
    $php_extension = get_loaded_extensions();
    for ($i = 0; $i < count($php_extension); $i++) {
        if ($php_extension[$i] == "libxml" || $php_extension[$i] == "domxml") {
            $domxml = true;
        }
    }
    if ($domxml === false) {
        wimba_add_log(WIMBA_ERROR, WC, get_string('domxml', 'liveclassroom'));
        error(get_string('domxml', 'liveclassroom'), $_SERVER["HTTP_REFERER"]);
    }
    return;
}