function announces_prune($force_prune = false)
{
    global $db, $board_config;
    // do we prune the announces ?
    $today_time = time();
    $today = mktime(0, 0, 0, date('m', $today_time), date('d', $today_time) + 1, date('Y', $today_time)) - 1;
    $do_prune = false;
    // last prune date
    if (intval($board_config['announcement_last_prune']) < $today || $force_prune) {
        $do_prune = true;
        if ($sql = set_config('announcement_last_prune', $today, TRUE)) {
            message_die(GENERAL_ERROR, 'Could not update key announcement_last_prune in the config table', '', __LINE__, __FILE__, $sql);
        }
    }
    // is the prune function activated ?
    $default_duration = isset($board_config['announcement_duration']) ? intval($board_config['announcement_duration']) : 7;
    if ($default_duration <= 0) {
        $do_prune = false;
    }
    // process fix and prune
    if ($do_prune) {
        // fix announces duration
        $default_duration = isset($board_config['announcement_duration']) ? intval($board_config['announcement_duration']) : 7;
        $sql = "UPDATE " . TOPICS_TABLE . "\n\t\t\t\tSET topic_announce_duration = {$default_duration}\n\t\t\t\tWHERE topic_announce_duration = 0\n\t\t\t\t\tAND (topic_type=" . POST_ANNOUNCE . " OR topic_type=" . POST_GLOBAL_ANNOUNCE . ")";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not update topic duration list', '', __LINE__, __FILE__, $sql);
        }
        // prune announces
        $prune_strategy = isset($board_config['announcement_prune_strategy']) ? intval($board_config['announcement_prune_strategy']) : POST_NORMAL;
        $sql = "UPDATE " . TOPICS_TABLE . "\n\t\t\t\tSET topic_type = {$prune_strategy}\n\t\t\t\tWHERE (topic_announce_duration > -1)\n\t\t\t\t\tAND ( (topic_time + topic_announce_duration * 86400) <= {$today} )\n\t\t\t\t\tAND (topic_type=" . POST_ANNOUNCE . " OR topic_type=" . POST_GLOBAL_ANNOUNCE . ")";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not update topic type to prune announcements', '', __LINE__, __FILE__, $sql);
        }
    }
}
Example #2
0
/**
 * @param int $oldversion the version we are upgrading from
 * @return bool result
 */
function xmldb_filter_mediaplugin_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2011121200) {
        // Move all the media enable setttings that are now handled by core media renderer.
        foreach (array('html5video', 'html5audio', 'mp3', 'flv', 'wmp', 'qt', 'rm', 'youtube', 'vimeo', 'swf') as $type) {
            $existingkey = 'filter_mediaplugin_enable_' . $type;
            if (array_key_exists($existingkey, $CFG)) {
                set_config('core_media_enable_' . $type, $CFG->{$existingkey});
                unset_config($existingkey);
            }
        }
        // Override setting for html5 to turn it on (previous default was off; because
        // of changes in the way fallbacks are handled, this is now unlikely to cause
        // a problem, and is required for mobile a/v support on non-Flash devices, so
        // this change is basically needed in order to maintain existing behaviour).
        set_config('core_media_enable_html5video', 1);
        set_config('core_media_enable_html5audio', 1);
        upgrade_plugin_savepoint(true, 2011121200, 'filter', 'mediaplugin');
    }
    // Moodle v2.3.0 release upgrade line
    // Put any upgrade step following this
    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this
    return true;
}
function xmldb_theme_formal_white_upgrade($oldversion)
{
    // Moodle v2.2.0 release upgrade line
    // Put any upgrade step following this
    if ($oldversion < 2012051503) {
        $currentsetting = get_config('theme_formal_white');
        if (isset($currentsetting->displaylogo)) {
            // useless but safer
            // Create a new config setting called headercontent and give it the current displaylogo value.
            set_config('headercontent', $currentsetting->displaylogo, 'theme_formal_white');
            unset_config('displaylogo', 'theme_formal_white');
        }
        if (isset($currentsetting->logo)) {
            // useless but safer
            // Create a new config setting called headercontent and give it the current displaylogo value.
            set_config('customlogourl', $currentsetting->logo, 'theme_formal_white');
            unset_config('logo', 'theme_formal_white');
        }
        if (isset($currentsetting->frontpagelogo)) {
            // useless but safer
            // Create a new config setting called headercontent and give it the current displaylogo value.
            set_config('frontpagelogourl', $currentsetting->frontpagelogo, 'theme_formal_white');
            unset_config('frontpagelogo', 'theme_formal_white');
        }
        upgrade_plugin_savepoint(true, 2012051503, 'theme', 'formal_white');
    }
    // Moodle v2.3.0 release upgrade line
    // Put any upgrade step following this
    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this
    // Moodle v2.5.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
/**
 * Runs the cron functions
 */
function as_cron()
{
    global $db, $config;
    set_config('last_as_run', time(), true);
    if (!function_exists('add_log')) {
        include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
    }
    if ($config['as_max_posts'] > 0) {
        $sql = 'SELECT COUNT(shout_id) as total FROM ' . SHOUTBOX_TABLE;
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchfield('total', $result);
        $db->sql_freeresult($result);
        if ($row > $config['as_max_posts']) {
            $sql = 'SELECT shout_id FROM ' . SHOUTBOX_TABLE . ' ORDER BY shout_time DESC';
            $result = $db->sql_query_limit($sql, $config['as_max_posts']);
            $delete = array();
            while ($row = $db->sql_fetchrow($result)) {
                $delete[] = $row['shout_id'];
            }
            $sql = 'DELETE FROM ' . SHOUTBOX_TABLE . ' WHERE ' . $db->sql_in_set('shout_id', $delete, true);
            $db->sql_query($sql);
            add_log('admin', 'LOG_AS_REMOVED', $db->sql_affectedrows($result));
        }
    } else {
        if ($config['as_prune'] > 0) {
            $time = time() - $config['as_prune'] * 3600;
            $sql = 'DELETE FROM  ' . SHOUTBOX_TABLE . " WHERE shout_time < {$time}";
            $db->sql_query($sql);
            $deleted = $db->sql_affectedrows($result);
            if ($deleted > 0) {
                add_log('admin', 'LOG_AS_PURGED', $deleted);
            }
        }
    }
}
Example #5
0
 protected function disable_plugin()
 {
     $enabled = enrol_get_plugins(true);
     unset($enabled['cohort']);
     $enabled = array_keys($enabled);
     set_config('enrol_plugins_enabled', implode(',', $enabled));
 }
/**
 * @param int $oldversion the version we are upgrading from
 * @return bool result
 */
function xmldb_filter_texwjax_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    // Moodle v2.3.0 release upgrade line
    // Put any upgrade step following this
    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this
    // Moodle v2.5.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    if ($oldversion < 2013120300) {
        $settings = array('density', 'latexbackground', 'convertformat', 'pathlatex', 'convertformat', 'pathconvert', 'pathdvips', 'latexpreamble');
        // Move tex settings to config_pluins and delete entries from the config table.
        foreach ($settings as $setting) {
            $existingkey = 'filter_texwjax_' . $setting;
            if (array_key_exists($existingkey, $CFG)) {
                set_config($setting, $CFG->{$existingkey}, 'filter_texwjax');
                unset_config($existingkey);
            }
        }
        upgrade_plugin_savepoint(true, 2013120300, 'filter', 'texwjax');
    }
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
 function setUp()
 {
     global $DB, $CFG;
     $this->realDB = $DB;
     $dbclass = get_class($this->realDB);
     $DB = new $dbclass();
     $DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->unittestprefix);
     if ($DB->get_manager()->table_exists('onlinejudge_tasks')) {
         $DB->get_manager()->delete_tables_from_xmldb_file($CFG->dirroot . '/local/onlinejudge/db/install.xml');
     }
     $DB->get_manager()->install_from_xmldb_file($CFG->dirroot . '/local/onlinejudge/db/install.xml');
     if ($DB->get_manager()->table_exists('files')) {
         $table = new xmldb_table('files');
         $DB->get_manager()->drop_table($table);
         $table = new xmldb_table('config_plugins');
         $DB->get_manager()->drop_table($table);
         $table = new xmldb_table('events_handlers');
         $DB->get_manager()->drop_table($table);
     }
     $DB->get_manager()->install_one_table_from_xmldb_file($CFG->dirroot . '/lib/db/install.xml', 'files');
     $DB->get_manager()->install_one_table_from_xmldb_file($CFG->dirroot . '/lib/db/install.xml', 'config_plugins');
     $DB->get_manager()->install_one_table_from_xmldb_file($CFG->dirroot . '/lib/db/install.xml', 'events_handlers');
     set_config('maxmemlimit', 64, 'local_onlinejudge');
     set_config('maxcpulimit', 10, 'local_onlinejudge');
     set_config('ideonedelay', 10, 'local_onlinejudge');
 }
Example #8
0
 /**
  * Validate that redirection from My Moodle does not happen for admins
  */
 public function test_mymoodleredirectreturnsfalseforadmin()
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . '/user/lib.php';
     // Make sure we're not a guest.
     set_config('siteguest', '');
     // Obtain the system context.
     $syscontext = context_system::instance();
     // Set up the current user global.
     $user = new stdClass();
     $user->username = "******";
     $userid = user_create_user($user);
     $USER = $DB->get_record('user', array('id' => $userid));
     // Enable functionaltiy.
     pm_set_config('mymoodle_redirect', 1);
     elis::$config = new elis_config();
     // Give the admin sufficient permissions.
     $roleid = create_role('adminrole', 'adminrole', 'adminrole');
     assign_capability('moodle/site:config', CAP_ALLOW, $roleid, $syscontext->id);
     role_assign($roleid, $USER->id, $syscontext->id);
     // Validate that redirection does not happen for admins.
     $result = pm_mymoodle_redirect();
     // Clear out cached permissions data so we don't affect other tests.
     accesslib_clear_all_caches(true);
     $this->assertFalse($result);
 }
Example #9
0
function xmldb_editor_tinymce_upgrade($oldversion)
{
    global $CFG, $DB;
    if ($oldversion < 2014062900) {
        // We only want to delete DragMath from the customtoolbar setting if the directory no longer exists. If
        // the directory is present then it means it has been restored, so do not remove any settings.
        if (!check_dir_exists($CFG->libdir . '/editor/tinymce/plugins/dragmath', false)) {
            // Remove the DragMath plugin from the 'customtoolbar' setting (if it exists) as it has been removed.
            $currentorder = get_config('editor_tinymce', 'customtoolbar');
            $newtoolbarrows = array();
            $currenttoolbarrows = explode("\n", $currentorder);
            foreach ($currenttoolbarrows as $currenttoolbarrow) {
                $currenttoolbarrow = implode(',', array_diff(str_getcsv($currenttoolbarrow), array('dragmath')));
                $newtoolbarrows[] = $currenttoolbarrow;
            }
            $neworder = implode("\n", $newtoolbarrows);
            unset_config('customtoolbar', 'editor_tinymce');
            set_config('customtoolbar', $neworder, 'editor_tinymce');
        }
        upgrade_plugin_savepoint(true, 2014062900, 'editor', 'tinymce');
    }
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.0.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.1.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
Example #10
0
 /**
  * Automatically update the registration on all hubs
  */
 public function cron()
 {
     global $CFG;
     if (extension_loaded('xmlrpc')) {
         //check if the last registration cron update was less than a week ago
         $lastcron = get_config('registration', 'crontime');
         if ($lastcron === false or $lastcron < strtotime("-7 day")) {
             //set to a week, see MDL-23704
             $function = 'hub_update_site_info';
             require_once $CFG->dirroot . "/webservice/xmlrpc/lib.php";
             //update all hub where the site is registered on
             $hubs = $this->get_registered_on_hubs();
             foreach ($hubs as $hub) {
                 //update the registration
                 $siteinfo = $this->get_site_info($hub->huburl);
                 $params = array('siteinfo' => $siteinfo);
                 $serverurl = $hub->huburl . "/local/hub/webservice/webservices.php";
                 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
                 try {
                     $result = $xmlrpcclient->call($function, $params);
                     mtrace(get_string('siteupdatedcron', 'hub', $hub->hubname));
                 } catch (Exception $e) {
                     $errorparam = new stdClass();
                     $errorparam->errormessage = $e->getMessage();
                     $errorparam->hubname = $hub->hubname;
                     mtrace(get_string('errorcron', 'hub', $errorparam));
                 }
             }
             set_config('crontime', time(), 'registration');
         }
     } else {
         mtrace(get_string('errorcronnoxmlrpc', 'hub'));
     }
 }
Example #11
0
    public function test_get_site_info() {
        global $DB, $USER, $CFG;

        $this->resetAfterTest(true);

        // This is the info we are going to check
        set_config('release', '2.4dev (Build: 20120823)');
        set_config('version', '2012083100.00');

        // Set current user
        $user = array();
        $user['username'] = '******';
        $user['firstname'] = 'John';
        $user['lastname'] = 'Doe';
        self::setUser(self::getDataGenerator()->create_user($user));

        // Add a web service and token.
        $webservice = new stdClass();
        $webservice->name = 'Test web service';
        $webservice->enabled = true;
        $webservice->restrictedusers = false;
        $webservice->component = 'moodle';
        $webservice->timecreated = time();
        $webservice->downloadfiles = true;
        $externalserviceid = $DB->insert_record('external_services', $webservice);

        // Add a function to the service
        $DB->insert_record('external_services_functions', array('externalserviceid' => $externalserviceid,
            'functionname' => 'core_course_get_contents'));

        $_POST['wstoken'] = 'testtoken';
        $externaltoken = new stdClass();
        $externaltoken->token = 'testtoken';
        $externaltoken->tokentype = 0;
        $externaltoken->userid = $USER->id;
        $externaltoken->externalserviceid = $externalserviceid;
        $externaltoken->contextid = 1;
        $externaltoken->creatorid = $USER->id;
        $externaltoken->timecreated = time();
        $DB->insert_record('external_tokens', $externaltoken);

        $siteinfo = core_webservice_external::get_site_info();

        // We need to execute the return values cleaning process to simulate the web service server.
        $siteinfo = external_api::clean_returnvalue(core_webservice_external::get_site_info_returns(), $siteinfo);

        $this->assertEquals('johnd', $siteinfo['username']);
        $this->assertEquals('John', $siteinfo['firstname']);
        $this->assertEquals('Doe', $siteinfo['lastname']);
        $this->assertEquals(current_language(), $siteinfo['lang']);
        $this->assertEquals($USER->id, $siteinfo['userid']);
        $this->assertEquals(true, $siteinfo['downloadfiles']);
        $this->assertEquals($CFG->release, $siteinfo['release']);
        $this->assertEquals($CFG->version, $siteinfo['version']);
        $this->assertEquals($CFG->mobilecssurl, $siteinfo['mobilecssurl']);
        $this->assertEquals(count($siteinfo['functions']), 1);
        $function = array_pop($siteinfo['functions']);
        $this->assertEquals($function['name'], 'core_course_get_contents');
        $this->assertEquals($function['version'], $siteinfo['version']);
    }
 public function __construct()
 {
     // Use this context for filtering.
     $this->context = context_system::instance();
     // Define FORMAT_HTML as only one filtering in DB.
     set_config('formats', implode(',', array(FORMAT_HTML)), get_class($this));
 }
Example #13
0
function networkingform_submit(Pieform $form, $values)
{
    $reply = '';
    if ($form->get_submitvalue() === 'deletekey') {
        global $SESSION;
        $openssl = OpenSslRepo::singleton();
        $openssl->get_keypair(true);
        $SESSION->add_info_msg(get_string('keydeleted', 'admin'));
        // Using cancel here as a hack to get it to redirect so it shows the new keys
        $form->reply(PIEFORM_CANCEL, array('location' => get_config('wwwroot') . 'admin/site/networking.php'));
    }
    if (get_config('enablenetworking') != $values['enablenetworking']) {
        if (!set_config('enablenetworking', $values['enablenetworking'])) {
            networkingform_fail($form);
        } else {
            if (empty($values['enablenetworking'])) {
                $reply .= get_string('networkingdisabled', 'admin');
            } else {
                $reply .= get_string('networkingenabled', 'admin');
            }
        }
    }
    if (get_config('promiscuousmode') != $values['promiscuousmode']) {
        if (!set_config('promiscuousmode', $values['promiscuousmode'])) {
            networkingform_fail($form);
        } else {
            if (empty($values['promiscuousmode'])) {
                $reply .= get_string('promiscuousmodedisabled', 'admin');
            } else {
                $reply .= get_string('promiscuousmodeenabled', 'admin');
            }
        }
    }
    $form->reply(PIEFORM_OK, array('message' => $reply == '' ? get_string('networkingunchanged', 'admin') : $reply, 'goto' => '/admin/site/networking.php'));
}
Example #14
0
 public function setUp()
 {
     $this->resetAfterTest();
     set_config('enableglobalsearch', true);
     // Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
     $search = testable_core_search::instance();
 }
Example #15
0
 /**
  * Processes and stores configuration data for this authentication plugin.
  * $this->config->somefield
  */
 function process_config($config)
 {
     // set to defaults if undefined
     if (!isset($config->mainrule_fld)) {
         $config->mainrule_fld = '';
     }
     if (!isset($config->secondrule_fld)) {
         $config->secondrule_fld = 'n/a';
     }
     if (!isset($config->replace_arr)) {
         $config->replace_arr = '';
     }
     if (!isset($config->delim)) {
         $config->delim = 'CR+LF';
     }
     if (!isset($config->donttouchusers)) {
         $config->donttouchusers = '';
     }
     if (!isset($config->enableunenrol)) {
         $config->enableunenrol = 0;
     }
     // save settings
     set_config('mainrule_fld', $config->mainrule_fld, self::COMPONENT_NAME);
     set_config('secondrule_fld', $config->secondrule_fld, self::COMPONENT_NAME);
     set_config('replace_arr', $config->replace_arr, self::COMPONENT_NAME);
     set_config('delim', $config->delim, self::COMPONENT_NAME);
     set_config('donttouchusers', $config->donttouchusers, self::COMPONENT_NAME);
     set_config('enableunenrol', $config->enableunenrol, self::COMPONENT_NAME);
     return true;
 }
 public function execute()
 {
     global $USER;
     // Check to make sure external communications hasn't been disabled
     $extcom = !!get_config('mod_hvp', 'external_communication');
     $extcomnotify = !!get_config('mod_hvp', 'external_communication_notify');
     if ($extcom || !$extcomnotify) {
         $core = \mod_hvp\framework::instance();
         $core->fetchLibrariesMetadata(!$extcom);
         set_config('external_communication_notify', $extcom ? false : time(), 'mod_hvp');
         // Notify admin if there are updates available!
         $update_available = \get_config('mod_hvp', 'update_available');
         $current_update = \get_config('mod_hvp', 'current_update');
         $admin_notified = \get_config('mod_hvp', 'admin_notified');
         if ($admin_notified !== $update_available && $update_available !== false && $current_update !== false && $current_update < $update_available) {
             // New update is available
             // Send message
             $updatesurl = new \moodle_url('/mod/hvp/library_list.php');
             $message = new \stdClass();
             $message->component = 'mod_hvp';
             $message->name = 'updates';
             $message->userfrom = $USER;
             $message->userto = get_admin();
             $message->subject = get_string('updatesavailabletitle', 'mod_hvp');
             $message->fullmessage = get_string('updatesavailablemsgpt1', 'mod_hvp') . ' ' . get_string('updatesavailablemsgpt2', 'mod_hvp') . "\n\n" . get_string('updatesavailablemsgpt3', 'mod_hvp', date('Y-m-d', $update_available)) . "\n" . get_string('updatesavailablemsgpt4', 'mod_hvp', date('Y-m-d', $current_update)) . "\n\n" . $updatesurl;
             $message->fullmessageformat = FORMAT_PLAIN;
             $message->fullmessagehtml = '<p>' . get_string('updatesavailablemsgpt1', 'mod_hvp') . '<br/>' . get_string('updatesavailablemsgpt2', 'mod_hvp') . '</p>' . '<p>' . get_string('updatesavailablemsgpt3', 'mod_hvp', '<b>' . date('Y-m-d', $update_available) . '</b>') . '<br/>' . get_string('updatesavailablemsgpt4', 'mod_hvp', '<b>' . date('Y-m-d', $current_update) . '</b>') . '</p>' . '<a href="' . $updatesurl . '" target="_blank">' . $updatesurl . '</a>';
             $message->smallmessage = '';
             $message->notification = 1;
             message_send($message);
             // Keep track of which version we've notfied about
             \set_config('admin_notified', $update_available, 'mod_hvp');
         }
     }
 }
Example #17
0
 public function createSchema()
 {
     $data = $this->_data;
     if (isset($data['cancel'])) {
         $this->view->set('info_message', 'Database creation cancelled');
         sendTo($this->name, 'index', $this->_modules);
     }
     if (isset($data['createdb']) && isset($data['Schema'])) {
         set_config('DB_TYPE', $data['Schema']['database_type']);
         set_config('DB_USER', $data['Schema']['database_admin_username']);
         set_config('DB_HOST', $data['Schema']['database_host']);
         set_config('DB_PASSWORD', $data['Schema']['database_admin_password']);
         set_config('DB_CREATE', true);
         $db = DB::Instance();
         if ($db === null) {
             echo 'Unable to connect to database<br>';
         }
         $dict = NewDataDictionary($db);
         $sql = $dict->CreateDatabase($data['Schema']['database_name']);
         $result = $dict->ExecuteSQLArray($sql);
         if ($result != 2) {
             $this->view->set('message', $db->ErrorMsg());
             $this->setTemplateName('systemerror');
             $this->view->set('page_title', $this->getPageName('Creation Error', 'Database'));
         } else {
             $this->view->set('message', 'Database created');
             $this->setTemplateName('systemerror');
             $this->view->set('page_title', $this->getPageName('Created', 'Database'));
         }
     }
 }
function xmldb_theme_formal_white_install()
{
    // We need here to check whether or not the theme has been installed.
    // If it has been installed then we need to change the name of the settings to the new names.
    // If it is not installed it won't have any settings yet and we won't need to worry about this.
    $currentsetting = get_config('theme_formal_white');
    if (!empty($currentsetting)) {
        // Remove the settings that are no longer used by this theme
        // Remove regionwidth
        unset_config('regionwidth', 'theme_formal_white');
        // Remove alwayslangmenu
        unset_config('alwayslangmenu', 'theme_formal_white');
        // previous releases of formal_white them were not equipped with version number
        // so I can not know if a theme specific variable exists or not.
        // This is the reason why I try to use them both.
        if (!empty($currentsetting->backgroundcolor)) {
            // Create a new config setting called lblockcolumnbgc and give it backgroundcolor's value.
            set_config('lblockcolumnbgc', $currentsetting->backgroundcolor, 'theme_formal_white');
            // Remove backgroundcolor
            unset_config('backgroundcolor', 'theme_formal_white');
        } elseif (!empty($currentsetting->blockcolumnbgc)) {
            // Create a new config setting called lblockcolumnbgc and give it blockcolumnbgc's value.
            set_config('lblockcolumnbgc', $currentsetting->blockcolumnbgc, 'theme_formal_white');
            // Remove blockcolumnbgc
            unset_config('blockcolumnbgc', 'theme_formal_white');
        }
    }
    return true;
}
Example #19
0
 /**
  * 保存配置信息
  */
 public function save()
 {
     $setting = array();
     $setting['admin_email'] = is_email($_POST['setting']['admin_email']) ? trim($_POST['setting']['admin_email']) : showmessage(L('email_illegal'), HTTP_REFERER);
     $setting['maxloginfailedtimes'] = intval($_POST['setting']['maxloginfailedtimes']);
     $setting['minrefreshtime'] = intval($_POST['setting']['minrefreshtime']);
     $setting['mail_type'] = intval($_POST['setting']['mail_type']);
     $setting['mail_server'] = trim($_POST['setting']['mail_server']);
     $setting['mail_port'] = intval($_POST['setting']['mail_port']);
     $setting['category_ajax'] = intval(abs($_POST['setting']['category_ajax']));
     $setting['mail_user'] = trim($_POST['setting']['mail_user']);
     $setting['mail_auth'] = intval($_POST['setting']['mail_auth']);
     $setting['mail_from'] = trim($_POST['setting']['mail_from']);
     $setting['mail_password'] = trim($_POST['setting']['mail_password']);
     $setting['errorlog_size'] = trim($_POST['setting']['errorlog_size']);
     $setting = array2string($setting);
     $this->db->update(array('setting' => $setting), array('module' => 'admin'));
     //存入admin模块setting字段
     //如果开始盛大通行证接入,判断服务器是否支持curl
     $snda_error = '';
     if ($_POST['setconfig']['snda_akey'] || $_POST['setconfig']['snda_skey']) {
         if (function_exists('curl_init') == FALSE) {
             $snda_error = L('snda_need_curl_init');
             $_POST['setconfig']['snda_enable'] = 0;
         }
     }
     set_config($_POST['setconfig']);
     //保存进config文件
     $this->setcache();
     showmessage(L('setting_succ') . $snda_error, HTTP_REFERER);
 }
/**
 * Upgrade code for the section links block.
 *
 * @global moodle_database $DB
 * @param int $oldversion
 * @param object $block
 */
function xmldb_block_section_links_upgrade($oldversion, $block)
{
    global $DB;
    // Moodle v2.3.0 release upgrade line
    // Put any upgrade step following this
    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this
    if ($oldversion < 2013012200.0) {
        // The section links block used to use its own crazy plugin name.
        // Here we are converting it to the proper component name.
        $oldplugin = 'blocks/section_links';
        $newplugin = 'block_section_links';
        // Use the proper API here... thats what we should be doing as it ensures any caches etc are cleared
        // along the way!
        // It may be quicker to just write an SQL statement but that would be reckless.
        $config = get_config($oldplugin);
        if (!empty($config)) {
            foreach ($config as $name => $value) {
                set_config($name, $value, $newplugin);
                unset_config($name, $oldplugin);
            }
        }
        // Main savepoint reached.
        upgrade_block_savepoint(true, 2013012200.0, 'section_links');
    }
    // Moodle v2.5.0 release upgrade line
    // Put any upgrade step following this
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
Example #21
0
/**
 * @param int $oldversion the version we are upgrading from
 * @return bool result
 */
function xmldb_repository_dropbox_upgrade($oldversion) {
    global $CFG, $DB;

    $dbman = $DB->get_manager();

    // Moodle v2.3.0 release upgrade line
    // Put any upgrade step following this

    if ($oldversion < 2012080702) {
        // Set the default value for dropbox_cachelimit
        $value = get_config('dropbox', 'dropbox_cachelimit');
        if (empty($value)) {
            set_config('dropbox_cachelimit', 1024*1024, 'dropbox');
        }
        upgrade_plugin_savepoint(true, 2012080702, 'repository', 'dropbox');
    }

    // Moodle v2.4.0 release upgrade line
    // Put any upgrade step following this


    // Moodle v2.5.0 release upgrade line.
    // Put any upgrade step following this.


    return true;
}
function xmldb_oublog_install()
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/course/lib.php';
    // Setup the global blog.
    $oublog = new stdClass();
    $oublog->course = SITEID;
    $oublog->name = 'Personal Blogs';
    $oublog->intro = '';
    $oublog->introformat = FORMAT_HTML;
    $oublog->accesstoken = md5(uniqid(rand(), true));
    $oublog->maxvisibility = 300;
    // OUBLOG_VISIBILITY_PUBLIC.
    $oublog->global = 1;
    $oublog->allowcomments = 2;
    // OUBLOG_COMMENTS_ALLOWPUBLIC.
    if (!($oublog->id = $DB->insert_record('oublog', $oublog))) {
        return false;
    }
    $mod = new stdClass();
    $mod->course = SITEID;
    $mod->module = $DB->get_field('modules', 'id', array('name' => 'oublog'));
    $mod->instance = $oublog->id;
    $mod->visible = 1;
    $mod->visibleold = 0;
    $mod->section = 1;
    if (!($cm = add_course_module($mod))) {
        return true;
    }
    set_config('oublogsetup', null);
    // For unit tests to work, it's necessary to create context now.
    context_module::instance($cm);
    return true;
}
Example #23
0
 function post()
 {
     check_form_security_token_redirectOnErr('/admin/security', 'admin_security');
     $allowed_email = x($_POST, 'allowed_email') ? notags(trim($_POST['allowed_email'])) : '';
     $not_allowed_email = x($_POST, 'not_allowed_email') ? notags(trim($_POST['not_allowed_email'])) : '';
     set_config('system', 'allowed_email', $allowed_email);
     set_config('system', 'not_allowed_email', $not_allowed_email);
     $block_public = x($_POST, 'block_public') ? True : False;
     set_config('system', 'block_public', $block_public);
     $ws = $this->trim_array_elems(explode("\n", $_POST['whitelisted_sites']));
     set_config('system', 'whitelisted_sites', $ws);
     $bs = $this->trim_array_elems(explode("\n", $_POST['blacklisted_sites']));
     set_config('system', 'blacklisted_sites', $bs);
     $wc = $this->trim_array_elems(explode("\n", $_POST['whitelisted_channels']));
     set_config('system', 'whitelisted_channels', $wc);
     $bc = $this->trim_array_elems(explode("\n", $_POST['blacklisted_channels']));
     set_config('system', 'blacklisted_channels', $bc);
     $embed_sslonly = x($_POST, 'embed_sslonly') ? True : False;
     set_config('system', 'embed_sslonly', $embed_sslonly);
     $we = $this->trim_array_elems(explode("\n", $_POST['embed_allow']));
     set_config('system', 'embed_allow', $we);
     $be = $this->trim_array_elems(explode("\n", $_POST['embed_deny']));
     set_config('system', 'embed_deny', $be);
     $ts = x($_POST, 'transport_security') ? True : False;
     set_config('system', 'transport_security_header', $ts);
     $cs = x($_POST, 'content_security') ? True : False;
     set_config('system', 'content_security_policy', $cs);
     goaway(z_root() . '/admin/security');
 }
Example #24
0
/**
* @param object $resource
* @uses CFG, USER
*/
function get_text_for_indexing_pdf(&$resource)
{
    global $CFG, $USER;
    // SECURITY : do not allow non admin execute anything on system !!
    if (!isadmin($USER->id)) {
        return;
    }
    // adds moodle root switch if none was defined
    if (!isset($CFG->block_search_usemoodleroot)) {
        set_config('block_search_usemoodleroot', 1);
    }
    $moodleroot = $CFG->block_search_usemoodleroot ? "{$CFG->dirroot}/" : '';
    // just call pdftotext over stdout and capture the output
    if (!empty($CFG->block_search_pdf_to_text_cmd)) {
        preg_match("/^\\S+/", $CFG->block_search_pdf_to_text_cmd, $matches);
        if (!file_exists("{$moodleroot}{$matches[0]}")) {
            mtrace('Error with pdf to text converter command : executable not found at ' . $moodleroot . $matches[0]);
        } else {
            $file = escapeshellarg($CFG->dataroot . '/' . $resource->course . '/' . $resource->reference);
            $command = trim($CFG->block_search_pdf_to_text_cmd);
            $text_converter_cmd = "{$moodleroot}{$command} {$file} -";
            $result = shell_exec($text_converter_cmd);
            if ($result) {
                return $result;
            } else {
                mtrace('Error with pdf to text converter command : execution failed for ' . $text_converter_cmd . '. Check for execution permission on pdf converter executable.');
                return '';
            }
        }
    } else {
        mtrace('Error with pdf to text converter command : command not set up. Execute once search block configuration.');
        return '';
    }
}
Example #25
0
function xmldb_enrol_license_install()
{
    global $CFG, $DB;
    // Migrate welcome message.
    if (isset($CFG->sendcoursewelcomemessage)) {
        // New course default.
        set_config('sendcoursewelcomemessage', $CFG->sendcoursewelcomemessage, 'enrol_license');
        // Each instance has different setting now.
        $DB->set_field('enrol', 'customint4', $CFG->sendcoursewelcomemessage, array('enrol' => 'license'));
        unset_config('sendcoursewelcomemessage');
    }
    // Migrate long-time-no-see feature settings.
    if (isset($CFG->longtimenosee)) {
        $nosee = $CFG->longtimenosee * 3600 * 24;
        set_config('longtimenosee', $nosee, 'enrol_license');
        $DB->set_field('enrol', 'customint2', $nosee, array('enrol' => 'license'));
        unset_config('longtimenosee');
    }
    // Enable by default on the site.
    $enabledenrols = explode(',', $CFG->enrol_plugins_enabled);
    if (!in_array('license', $enabledenrols)) {
        $enabledenrols[] = 'license';
        set_config('enrol_plugins_enabled', implode(',', $enabledenrols));
    }
}
Example #26
0
/**
 * Enable WIRIS plugin buttons on installation.
 */
function xmldb_atto_wiris_install()
{
    $toolbar = get_config('editor_atto', 'toolbar');
    if (strpos($toolbar, 'wiris') === false) {
        $groups = explode("\n", $toolbar);
        // Try to put wiris in math group
        $found = false;
        foreach ($groups as $i => $group) {
            $parts = explode('=', $group);
            if (trim($parts[0]) == 'math') {
                $groups[$i] = 'math = ' . trim($parts[1]) . ', wiris';
                $found = true;
            }
        }
        // Otherwise create a math group in the second position starting from
        // the end.
        if (!$found) {
            do {
                $last = array_pop($groups);
            } while (empty($last) && !empty($groups));
            $groups[] = 'math = wiris';
            $groups[] = $last;
        }
        // Update config variable.
        $toolbar = implode("\n", $groups);
        set_config('toolbar', $toolbar, 'editor_atto');
    }
}
 /**
  * Set up all data needed for testing.
  * @param array $userids List of moodle user ids to test with.
  * @param array $itemgrades List of grade item grades to test with.
  */
 public function fixture_moodleenrol($userids, $itemgrades)
 {
     global $DB;
     // Import CSV data.
     $dataset = $this->createCsvDataSet(array(course::TABLE => elispm::file('tests/fixtures/pmcourse.csv'), pmclass::TABLE => elispm::file('tests/fixtures/pmclass.csv'), 'user' => elispm::file('tests/fixtures/mdluser.csv'), user::TABLE => elispm::file('tests/fixtures/pmuser.csv'), usermoodle::TABLE => elispm::file('tests/fixtures/user_moodle.csv'), coursecompletion::TABLE => elispm::file('tests/fixtures/course_completion.csv')));
     $this->loadDataSet($dataset);
     // Create course.
     $course = $this->getDataGenerator()->create_course();
     // Link with ELIS class.
     $DB->insert_record(classmoodlecourse::TABLE, (object) array('classid' => 100, 'moodlecourseid' => $course->id));
     // Create grade items.
     $items = array(array('courseid' => $course->id, 'idnumber' => 'required', 'itemtype' => 'manual'), array('courseid' => $course->id, 'idnumber' => 'notrequired', 'itemtype' => 'manual'), array('courseid' => $course->id, 'idnumber' => 'course', 'itemtype' => 'course'));
     foreach ($items as $item) {
         $DB->insert_record('grade_items', (object) $item);
     }
     // Set up our test role.
     $roleid = create_role('gradedrole', 'gradedrole', 'gradedrole');
     set_config('gradebookroles', $roleid);
     // Create all of our test enrolments.
     foreach ($userids as $userid) {
         $this->getDataGenerator()->enrol_user($userid, $course->id, $roleid);
     }
     // Assign item grades.
     foreach ($itemgrades as $itemgrade) {
         $DB->insert_record('grade_grades', (object) $itemgrade);
     }
 }
Example #28
0
 function acp_page($id, &$module)
 {
     global $config, $db, $template, $user;
     $captcha_vars = array('recaptcha_pubkey' => 'RECAPTCHA_PUBKEY', 'recaptcha_privkey' => 'RECAPTCHA_PRIVKEY');
     $module->tpl_name = 'captcha_recaptcha_acp';
     $module->page_title = 'ACP_VC_SETTINGS';
     $form_key = 'acp_captcha';
     add_form_key($form_key);
     $submit = request_var('submit', '');
     if ($submit && check_form_key($form_key)) {
         $captcha_vars = array_keys($captcha_vars);
         foreach ($captcha_vars as $captcha_var) {
             $value = request_var($captcha_var, '');
             if ($value) {
                 set_config($captcha_var, $value);
             }
         }
         add_log('admin', 'LOG_CONFIG_VISUAL');
         trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action));
     } else {
         if ($submit) {
             trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action));
         } else {
             foreach ($captcha_vars as $captcha_var => $template_var) {
                 $var = isset($_REQUEST[$captcha_var]) ? request_var($captcha_var, '') : (isset($config[$captcha_var]) ? $config[$captcha_var] : '');
                 $template->assign_var($template_var, $var);
             }
             $template->assign_vars(array('CAPTCHA_PREVIEW' => $this->get_demo_template($id), 'CAPTCHA_NAME' => $this->get_service_name(), 'U_ACTION' => $module->u_action));
         }
     }
 }
Example #29
0
 public function test_notifications()
 {
     global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_log;
     include_once $phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx;
     include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx;
     include_once $phpbb_root_path . 'includes/functions_content.' . $phpEx;
     set_config(false, false, false, $this->config);
     $this->container->set('groupposition.legend', new \phpbb\groupposition\legend($this->db, $this->user));
     $this->container->set('groupposition.teampage', new \phpbb\groupposition\teampage($this->db, $this->user, $this->cache->get_driver()));
     $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
     $phpbb_log = new \phpbb\log\null();
     // Now on to the actual test
     $group_id = false;
     group_create($group_id, GROUP_OPEN, 'test', 'test group', array());
     // Add user 2 as group leader
     group_user_add($group_id, 2, false, false, false, true, false);
     // Add user 3 as pending
     group_user_add($group_id, 3, false, false, false, false, true);
     $this->assert_notifications(array(array('item_id' => 3, 'item_parent_id' => $group_id, 'user_id' => 2, 'notification_read' => 0, 'notification_data' => array('group_name' => 'test'))), array('user_id' => 2));
     // Approve user 3 joining the group
     group_user_attributes('approve', $group_id, array(3));
     // user 3 pending notification should have been deleted
     $this->assert_notifications(array(), array('user_id' => 2));
     $this->assert_notifications(array(array('item_id' => $group_id, 'user_id' => 3, 'notification_read' => 0, 'notification_data' => array('group_name' => 'test'))), array('user_id' => 3));
 }
 function acp_page($id, &$module)
 {
     global $db, $user, $auth, $template;
     global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
     $user->add_lang('acp/board');
     $config_vars = array('enable_confirm' => 'REG_ENABLE', 'enable_post_confirm' => 'POST_ENABLE', 'confirm_refresh' => 'CONFIRM_REFRESH', 'captcha_gd' => 'CAPTCHA_GD');
     $module->tpl_name = 'captcha_gd_acp';
     $module->page_title = 'ACP_VC_SETTINGS';
     $form_key = 'acp_captcha';
     add_form_key($form_key);
     $submit = request_var('submit', '');
     if ($submit && check_form_key($form_key)) {
         $captcha_vars = array_keys($this->captcha_vars);
         foreach ($captcha_vars as $captcha_var) {
             $value = request_var($captcha_var, 0);
             if ($value >= 0) {
                 set_config($captcha_var, $value);
             }
         }
         add_log('admin', 'LOG_CONFIG_VISUAL');
         trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action));
     } else {
         if ($submit) {
             trigger_error($user->lang['FORM_INVALID'] . adm_back_link($module->u_action));
         } else {
             foreach ($this->captcha_vars as $captcha_var => $template_var) {
                 $var = isset($_REQUEST[$captcha_var]) ? request_var($captcha_var, 0) : $config[$captcha_var];
                 $template->assign_var($template_var, $var);
             }
             $template->assign_vars(array('CAPTCHA_PREVIEW' => $this->get_demo_template($id), 'CAPTCHA_NAME' => $this->get_class_name(), 'U_ACTION' => $module->u_action));
         }
     }
 }