예제 #1
0
 /**
  * Create a test institution
  * @param array $record
  * @throws ErrorException if creating failed
  * @return int new institution id
  */
 public function create_institution($record)
 {
     // Data validation
     if (empty($record['name']) || !preg_match('/^[a-zA-Z]{1,255}$/', $record['name'])) {
         throw new SystemException("Invalid institution name '" . $record['name'] . "'. The institution name is entered for system database identification only and must be a single text word without numbers or symbols.");
     }
     if (!empty($record['name']) && record_exists('institution', 'name', $record['name'])) {
         throw new SystemException("Invalid institution name '" . $record['name'] . "'. " . get_string('institutionnamealreadytaken', 'admin'));
     }
     if (get_config('licensemetadata') && !empty($record['licensemandatory']) && (isset($record['licensedefault']) && $record['licensedefault'] == '')) {
         throw new SystemException("Invalid institution license setting. " . get_string('licensedefaultmandatory', 'admin'));
     }
     if (!empty($record['lang']) && $record['lang'] != 'sitedefault' && !array_key_exists($record['lang'], get_languages())) {
         throw new SystemException("Invalid institution language setting: '" . $record['lang'] . "'. This language is not installed for the site.");
     }
     // Create a new institution
     db_begin();
     // Update the basic institution record...
     $newinstitution = new Institution();
     $newinstitution->initialise($record['name'], $record['displayname']);
     $institution = $newinstitution->name;
     $newinstitution->showonlineusers = !isset($record['showonlineusers']) ? 2 : $record['showonlineusers'];
     if (get_config('usersuniquebyusername')) {
         // Registering absolutely not allowed when this setting is on, it's a
         // security risk. See the documentation for the usersuniquebyusername
         // setting for more information
         $newinstitution->registerallowed = 0;
     } else {
         $newinstitution->registerallowed = !empty($record['registerallowed']) ? 1 : 0;
         $newinstitution->registerconfirm = !empty($record['registerconfirm']) ? 1 : 0;
     }
     if (!empty($record['lang'])) {
         if ($record['lang'] == 'sitedefault') {
             $newinstitution->lang = null;
         } else {
             $newinstitution->lang = $record['lang'];
         }
     }
     $newinstitution->theme = empty($record['theme']) || $record['theme'] == 'sitedefault' ? null : $record['theme'];
     $newinstitution->dropdownmenu = !empty($record['dropdownmenu']) ? 1 : 0;
     $newinstitution->skins = !empty($record['skins']) ? 1 : 0;
     $newinstitution->style = null;
     if (get_config('licensemetadata')) {
         $newinstitution->licensemandatory = !empty($record['licensemandatory']) ? 1 : 0;
         $newinstitution->licensedefault = isset($record['licensedefault']) ? $record['licensedefault'] : '';
     }
     $newinstitution->defaultquota = empty($record['defaultquota']) ? get_config_plugin('artefact', 'file', 'defaultquota') : $record['defaultquota'];
     $newinstitution->defaultmembershipperiod = !empty($record['defaultmembershipperiod']) ? intval($record['defaultmembershipperiod']) : null;
     $newinstitution->maxuseraccounts = !empty($record['maxuseraccounts']) ? intval($record['maxuseraccounts']) : null;
     $newinstitution->expiry = !empty($record['expiry']) ? db_format_timestamp($record['expiry']) : null;
     $newinstitution->allowinstitutionpublicviews = isset($record['allowinstitutionpublicviews']) && $record['allowinstitutionpublicviews'] ? 1 : 0;
     // Save the changes to the DB
     $newinstitution->commit();
     // Automatically create an internal authentication authinstance
     $authinstance = (object) array('instancename' => 'internal', 'priority' => 0, 'institution' => $newinstitution->name, 'authname' => 'internal');
     insert_record('auth_instance', $authinstance);
     // We need to add the default lines to the site_content table for this institution
     // We also need to set the institution to be using default static pages to begin with
     // so that using custom institution pages is an opt-in situation
     $pages = site_content_pages();
     $now = db_format_timestamp(time());
     foreach ($pages as $name) {
         $page = new stdClass();
         $page->name = $name;
         $page->ctime = $now;
         $page->mtime = $now;
         $page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfiginstitution', 'install'));
         $page->institution = $newinstitution->name;
         insert_record('site_content', $page);
         $institutionconfig = new stdClass();
         $institutionconfig->institution = $newinstitution->name;
         $institutionconfig->field = 'sitepages_' . $name;
         $institutionconfig->value = 'mahara';
         insert_record('institution_config', $institutionconfig);
     }
     if (isset($record['commentthreaded'])) {
         set_config_institution($newinstitution->name, 'commentthreaded', (bool) $record['commentthreaded']);
     }
     db_commit();
 }
예제 #2
0
파일: web.php 프로젝트: sarahjcotton/mahara
/**
 * Builds a data structure representing the menu for Mahara.
 *
 * @return array
 */
function main_nav()
{
    global $USER;
    $language = current_language();
    $cachemenu = false;
    // Get the first institution
    $institution = $USER->get_primary_institution();
    $menutype = '';
    if (in_admin_section()) {
        global $USER, $SESSION;
        if ($USER->get('admin')) {
            $menutype = 'admin_nav';
            if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
                $menu = admin_nav();
            }
        } else {
            if ($USER->is_institutional_admin()) {
                $menutype = 'instadmin_nav';
                if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
                    $menu = institutional_admin_nav();
                }
            } else {
                if ($USER->get('staff')) {
                    $menutype = 'staff_nav';
                    if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
                        $menu = staff_nav();
                    }
                } else {
                    $menutype = 'inststaff_nav';
                    if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
                        $menu = institutional_staff_nav();
                    }
                }
            }
        }
    } else {
        // Build the menu structure for the site
        $menutype = 'standard_nav';
        if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
            $menu = mahara_standard_nav();
        }
    }
    if ($cachemenu) {
        $menu = json_decode($cachemenu, true);
    } else {
        $menu = array_filter($menu, create_function('$a', 'return empty($a["ignore"]);'));
        // enable plugins to augment the menu structure
        foreach (array('artefact', 'interaction', 'module', 'auth') as $plugintype) {
            if ($plugins = plugins_installed($plugintype)) {
                foreach ($plugins as &$plugin) {
                    if (safe_require_plugin($plugintype, $plugin->name)) {
                        $plugin_menu = call_static_method(generate_class_name($plugintype, $plugin->name), 'menu_items');
                        $menu = array_merge($menu, $plugin_menu);
                    }
                }
            }
        }
        set_config_institution($institution, $menutype . '_' . $language, json_encode($menu));
    }
    // local_main_nav_update allows sites to customise the menu by munging the $menu array.
    // as there is no internal way to know if the local_main_nav array has changed we keep it outside the cached menu
    if (function_exists('local_main_nav_update')) {
        local_main_nav_update($menu);
    }
    $menu_structure = find_menu_children($menu, '');
    return $menu_structure;
}
예제 #3
0
파일: mahara.php 프로젝트: banterweb/mahara
/**
 * Checks if theme still exists and if not resets it to default option
 *
 * @param $theme         string  Name of theme
 * @param $institution   string  Name of Institution
 *
 * @return  bool       True if theme exists
 */
function validate_theme($theme, $institution = null)
{
    global $SESSION;
    if ($institution) {
        $themeoptions = get_institution_themes($institution);
    } else {
        $themeoptions = get_all_themes();
    }
    if (!array_key_exists($theme, $themeoptions)) {
        if ($institution) {
            set_config_institution($institution, 'theme', null);
        } else {
            set_config('theme', 'default');
        }
        $SESSION->add_info_msg(get_string('thememissing', 'admin', $theme));
        return false;
    }
    return true;
}