示例#1
0
文件: options.php 项目: Br3nda/mahara
function siteoptions_submit(Pieform $form, $values)
{
    $fields = array('sitename', 'lang', 'theme', 'pathtoclam', 'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn', 'allowpublicviews', 'allowpublicprofiles', 'createpublicgroups', 'searchplugin', 'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend');
    $oldlanguage = get_config('lang');
    $oldtheme = get_config('theme');
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
            siteoptions_fail($form, $field);
        }
    }
    if ($oldlanguage != $values['lang']) {
        safe_require('artefact', 'file');
        ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
    }
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
        siteoptions_fail($form, 'sessionlifetime');
    }
    // Submitted value is on/off; database entry should be 1/0
    foreach (array('viruschecking', 'usersallowedmultipleinstitutions') as $checkbox) {
        if (!set_config($checkbox, (int) ($values[$checkbox] == 'on'))) {
            siteoptions_fail($form, $checkbox);
        }
    }
    $message = get_string('siteoptionsset', 'admin');
    if ($oldtheme != $values['theme']) {
        $message .= '  ' . get_string('usersseenewthemeonlogin', 'admin');
    }
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/options.php'));
}
function siteoptions_submit(Pieform $form, $values)
{
    $fields = array('sitename', 'lang', 'theme', 'pathtoclam', 'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn', 'allowpublicviews', 'allowpublicprofiles', 'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend', 'showselfsearchsideblock', 'searchusernames', 'showtagssideblock', 'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes', 'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments', 'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'homepageinfo', 'showonlineuserssideblock', 'registerterms', 'creategroups', 'createpublicgroups', 'allowgroupcategories');
    $oldlanguage = get_config('lang');
    $oldtheme = get_config('theme');
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
            siteoptions_fail($form, $field);
        }
    }
    if ($oldlanguage != $values['lang']) {
        safe_require('artefact', 'file');
        ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
    }
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
        siteoptions_fail($form, 'sessionlifetime');
    }
    // Submitted value is on/off; database entry should be 1/0
    foreach (array('viruschecking', 'usersallowedmultipleinstitutions') as $checkbox) {
        if (!set_config($checkbox, (int) ($values[$checkbox] == 'on'))) {
            siteoptions_fail($form, $checkbox);
        }
    }
    if ($values['viruschecking'] == 'on') {
        $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam')));
        if (!$pathtoclam || !file_exists($pathtoclam) && !is_executable($pathtoclam)) {
            $form->reply(PIEFORM_ERR, array('message' => get_string('clamlost', 'mahara', $pathtoclam), 'goto' => '/admin/site/options.php'));
        }
    }
    $message = get_string('siteoptionsset', 'admin');
    if ($oldtheme != $values['theme']) {
        global $USER;
        $message .= '  ' . get_string('usersseenewthemeonlogin', 'admin');
        $USER->update_theme();
    }
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/options.php'));
}
示例#3
0
function siteoptions_submit(Pieform $form, $values)
{
    $fields = array('sitename', 'lang', 'theme', 'dropdownmenu', 'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn', 'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap', 'registration_sendweeklyupdates', 'mathjax', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm', 'showselfsearchsideblock', 'nousernames', 'searchplugin', 'showtagssideblock', 'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes', 'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments', 'recaptchaonregisterform', 'recaptchapublickey', 'recaptchaprivatekey', 'loggedinprofileviewaccess', 'disableexternalresources', 'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'smtphosts', 'smtpport', 'smtpuser', 'smtppass', 'smtpsecure', 'noreplyaddress', 'homepageinfo', 'showprogressbar', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers', 'registerterms', 'licensemetadata', 'licenseallowcustom', 'allowmobileuploads', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg', 'staffreports', 'staffstats', 'userscandisabledevicedetection', 'watchlistnotification_delay', 'masqueradingreasonrequired', 'masqueradingnotified', 'searchuserspublic', 'eventloglevel', 'eventlogexpiry', 'sitefilesaccess', 'exporttoqueue', 'defaultmultipleblogs');
    $count = 0;
    $where_sql = " WHERE admin = 0 AND id != 0";
    // if default account lifetime expiry has no end date
    if (empty($values['defaultaccountlifetime'])) {
        if ($values['defaultaccountlifetimeupdate'] == 'all') {
            // need to remove user expiry
            db_begin();
            $count = count_records_sql("SELECT COUNT(*) FROM {usr} {$where_sql}");
            execute_sql("UPDATE {usr} SET expiry = NULL {$where_sql}");
            db_commit();
        } else {
            // make the 'some' option the same as 'none' as it is meaningless to
            // update existing users without expiry date to having 'no end date'
            $values['defaultaccountlifetimeupdate'] = 'none';
        }
    } else {
        // fetch all the users that are not siteadmins
        $user_expiry = mktime(0, 0, 0, date('n'), date('j'), date('Y')) + (int) $values['defaultaccountlifetime'];
        if ($values['defaultaccountlifetimeupdate'] == 'some') {
            // and the user's expiry is not set
            $where_sql .= " AND expiry IS NULL";
            $count = count_records_sql("SELECT COUNT(*) FROM {usr} {$where_sql}");
            db_begin();
            execute_sql("UPDATE {usr} SET expiry = ? {$where_sql}", array(format_date($user_expiry)));
            db_commit();
        } else {
            if ($values['defaultaccountlifetimeupdate'] == 'all') {
                // and the user's expiry is set
                db_begin();
                $count = count_records_sql("SELECT COUNT(*) FROM {usr} {$where_sql}");
                execute_sql("UPDATE {usr} SET expiry = ? {$where_sql}", array(format_date($user_expiry)));
                db_commit();
            }
        }
    }
    // if public views are disabled, sitemap generation must also be disabled.
    if ($values['allowpublicviews'] == false) {
        $values['generatesitemap'] = false;
    } else {
        // Ensure allowpublicprofiles is set as well
        $values['allowpublicprofiles'] = 1;
    }
    $oldsearchplugin = get_config('searchplugin');
    $oldlanguage = get_config('lang');
    $oldtheme = get_config('theme');
    foreach ($fields as $field) {
        if (!set_config($field, $values[$field])) {
            siteoptions_fail($form, $field);
        }
    }
    if ($oldlanguage != $values['lang']) {
        safe_require('artefact', 'file');
        ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
    }
    save_notification_settings($values, null, true);
    if ($oldsearchplugin != $values['searchplugin']) {
        // Call the old search plugin's sitewide cleanup method
        safe_require('search', $oldsearchplugin);
        call_static_method(generate_class_name('search', $oldsearchplugin), 'cleanup_sitewide');
        // Call the new search plugin's sitewide initialize method
        safe_require('search', $values['searchplugin']);
        $initialize = call_static_method(generate_class_name('search', $values['searchplugin']), 'initialize_sitewide');
        if (!$initialize) {
            $form->reply(PIEFORM_ERR, array('message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']), 'goto' => '/admin/site/options.php'));
        }
    }
    // Call the new search plugin's can connect
    safe_require('search', $values['searchplugin']);
    $connect = call_static_method(generate_class_name('search', $values['searchplugin']), 'can_connect');
    if (!$connect) {
        $form->reply(PIEFORM_ERR, array('message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']), 'goto' => '/admin/site/options.php'));
    }
    // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
    if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
        siteoptions_fail($form, 'sessionlifetime');
    }
    // Submitted value is on/off; database entry should be 1/0
    foreach (array('viruschecking', 'usersallowedmultipleinstitutions') as $checkbox) {
        if (!set_config($checkbox, (int) ($values[$checkbox] == 'on'))) {
            siteoptions_fail($form, $checkbox);
        }
    }
    if ($values['viruschecking'] == 'on') {
        $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam')));
        if (!$pathtoclam) {
            $form->reply(PIEFORM_ERR, array('message' => get_string('clamnotset', 'mahara', $pathtoclam), 'goto' => '/admin/site/options.php'));
        } else {
            if (!file_exists($pathtoclam) && !is_executable($pathtoclam)) {
                $form->reply(PIEFORM_ERR, array('message' => get_string('clamlost', 'mahara', $pathtoclam), 'goto' => '/admin/site/options.php'));
            }
        }
    }
    if (get_config('recaptchaonregisterform') && !(get_config('recaptchapublickey') && get_config('recaptchaprivatekey'))) {
        $form->reply(PIEFORM_ERR, array('message' => get_string('recaptchakeysmissing1', 'admin'), 'goto' => '/admin/site/options.php'));
    }
    // Need to clear the cached menus in case site config changes effect them.
    clear_menu_cache();
    $message = get_string('siteoptionsset', 'admin');
    if ($oldtheme != $values['theme']) {
        global $USER;
        $message .= '  ' . get_string('usersseenewthemeonlogin', 'admin');
        $USER->reset_institutions();
    }
    if ($count) {
        $message .= ' ' . get_string('numberusersupdated', 'admin', $count);
    }
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/options.php'));
}