Beispiel #1
0
            $smarty->assign('noinstitutionsadmin', $USER->admin ? get_string('noinstitutionstaticpagesadmin', 'admin', get_config('wwwroot') . 'admin/site/pages.php') : false);
            $smarty->assign('noinstitutions', get_string('noinstitutionstaticpages', 'admin'));
            $smarty->assign('PAGEHEADING', TITLE);
            $smarty->display('admin/site/pages.tpl');
            exit;
        }
    }
}
foreach ($sitepages as $page) {
    $section = in_array($page->name, $localpagenames) ? 'local' : 'admin';
    $pageoptions[$page->name] = get_string($page->name, $section);
    $pagecontents[$page->name] = $page->content;
}
asort($pageoptions);
$getstring = array('discardpageedits' => json_encode(get_string('discardpageedits', 'admin')));
$form = pieform(array('name' => 'editsitepage', 'jsform' => true, 'jssuccesscallback' => 'contentSaved', 'elements' => array('pageinstitution' => $institutionelement, 'pagename' => array('type' => 'select', 'title' => get_string('pagename', 'admin'), 'defaultvalue' => DEFAULTPAGE, 'options' => $pageoptions), 'pageusedefault' => array('type' => 'switchbox', 'title' => get_string('usedefault', 'admin'), 'description' => get_string('usedefaultdescription2', 'admin'), 'defaultvalue' => get_config_institution($institutionelement['defaultvalue'], 'sitepages_' . DEFAULTPAGE) == 'mahara' ? 1 : 0), 'pagetext' => array('name' => 'pagetext', 'type' => 'wysiwyg', 'rows' => 25, 'cols' => 100, 'title' => get_string('pagetext', 'admin'), 'defaultvalue' => $pagecontents[DEFAULTPAGE], 'rules' => array('maxlength' => 65536, 'required' => true)), 'submit' => array('type' => 'submit', 'class' => 'btn-success', 'value' => get_string('savechanges', 'admin')))));
function editsitepage_validate(Pieform $form, $values)
{
    $allowedinstitutions = get_institution_selector(false);
    if (array_search($values['pageinstitution'], array_flip($allowedinstitutions['options'])) === false) {
        $form->set_error(null, get_string('staticpageinstitutionbad', 'admin', $values['pageinstitution']));
    }
}
function editsitepage_submit(Pieform $form, $values)
{
    global $USER;
    $data = new StdClass();
    $data->name = $values['pagename'];
    if (empty($values['pageusedefault'])) {
        $data->content = $values['pagetext'];
    }
Beispiel #2
0
 /**
  * Get institution name by checking which 'institution theme' a user is allocated to see
  * and if that theme has sitepages set.
  * Or if a lastinstitution cookie is set. Or if an institution url parameter is set.
  * Defaults to 'mahara'.
  *
  * @return string   Institution name
  */
 public function sitepages_institutionname_by_theme($page)
 {
     // get institution when logged in
     if ($this->is_logged_in()) {
         if ($theme = $this->get('institutiontheme')) {
             if (!empty($theme->institutionname)) {
                 // check to see if institution is using it's own site pages or default site pages
                 if ($institution = get_record('institution', 'name', $theme->institutionname)) {
                     if (get_config_institution($institution->name, 'sitepages_' . $page)) {
                         return get_config_institution($institution->name, 'sitepages_' . $page);
                     }
                 } else {
                     return $theme->institutionname;
                 }
             } else {
                 return 'mahara';
             }
         }
     }
     // or from url
     if ($institution = param_alphanum('institution', null)) {
         return $institution;
     }
     // or from cookie
     if ($institution = get_cookie('lastinstitution')) {
         return $institution;
     }
     return 'mahara';
 }
Beispiel #3
0
/**
 * 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;
}
Beispiel #4
0
/**
 * Fetch a config setting for the specified user's institutions (from either the "institution" or "institution_config" table)
 *
 * @param string $key
 * @param int $userid (Optional) If not supplied, fetch for the current user's institutions
 * @return array The results for the all the users' institutions, in the order
 *               supplied by load_user_institutions(). Array key is institution name.
 */
function get_configs_user_institutions($key, $userid = null)
{
    global $USER, $CFG;
    if ($userid === null) {
        $userid = $USER->id;
    }
    // Check for the user and key in the cache (The cache is stored in $CFG so it can be cleared/updated
    // if we ever write a set_config_institution() method)
    $userobj = "user{$userid}";
    if (isset($CFG->userinstconf->{$userobj}->{$key})) {
        return $CFG->userinstconf->{$userobj}->{$key};
    }
    // We didn't hit the cache, so retrieve the config from their
    // institution.
    // First, get a list of their institution names
    if (!$userid) {
        // The logged-out user has no institutions.
        $institutions = false;
    } else {
        if ($userid == $USER->id) {
            // Institutions for current logged-in user
            $institutions = $USER->get('institutions');
        } else {
            $institutions = load_user_institutions($userid);
        }
    }
    // If the user belongs to no institution, check the Mahara institution
    if (!$institutions) {
        // For compatibility with $USER->get('institutions') and
        // load_user_institutions(), we only really care about the
        // array keys
        $institutions = array('mahara' => 'mahara');
    }
    $results = array();
    foreach ($institutions as $instname => $inst) {
        $results[$instname] = get_config_institution($instname, $key);
    }
    // Cache the result
    if (!isset($CFG->userinstconf)) {
        $CFG->userinstconf = new stdClass();
    }
    if (!isset($CFG->userinstconf->{$userobj})) {
        $CFG->userinstconf->{$userobj} = new stdClass();
    }
    $CFG->userinstconf->{$userobj}->{$key} = $results;
    return $results;
}
Beispiel #5
0
function general_account_prefs_form_elements($prefs)
{
    global $USER;
    require_once 'license.php';
    $elements = array();
    $elements['friendscontrol'] = array('type' => 'radio', 'defaultvalue' => $prefs->friendscontrol, 'title' => get_string('friendsdescr', 'account'), 'class' => 'mrs mls', 'options' => array('nobody' => get_string('friendsnobody', 'account'), 'auth' => get_string('friendsauth', 'account'), 'auto' => get_string('friendsauto', 'account')), 'help' => true);
    $elements['wysiwyg'] = array('type' => 'switchbox', 'defaultvalue' => get_config('wysiwyg') ? get_config('wysiwyg') == 'enable' : $prefs->wysiwyg, 'title' => get_string('wysiwygdescr', 'account'), 'help' => true, 'disabled' => get_config('wysiwyg'));
    if (get_config('licensemetadata')) {
        $elements['licensedefault'] = license_form_el_basic(null);
        $elements['licensedefault']['title'] = get_string('licensedefault', 'account');
        if ($USER->get('institutions')) {
            $elements['licensedefault']['options'][LICENSE_INSTITUTION_DEFAULT] = get_string('licensedefaultinherit', 'account');
        }
        $elements['licensedefault']['description'] = get_string('licensedefaultdescription', 'account');
        if (isset($prefs->licensedefault)) {
            $elements['licensedefault']['defaultvalue'] = $prefs->licensedefault;
        }
    }
    $elements['maildisabled'] = array('type' => 'switchbox', 'defaultvalue' => $prefs->maildisabled, 'title' => get_string('disableemail', 'account'), 'help' => true);
    $elements['messages'] = array('type' => 'radio', 'defaultvalue' => $prefs->messages, 'title' => get_string('messagesdescr', 'account'), 'options' => array('nobody' => get_string('messagesnobody', 'account'), 'friends' => get_string('messagesfriends', 'account'), 'allow' => get_string('messagesallow', 'account')), 'help' => true);
    $languages = get_languages();
    // Determine default language.
    $instlang = get_user_institution_language($USER->id, $instlanginstname);
    if (!empty($instlang) && $instlang != 'default') {
        $sitedefaultlabel = get_string('defaultlangforinstitution', 'admin', get_config_institution($instlanginstname, 'displayname')) . ' (' . $languages[$instlang] . ')';
    } else {
        $sitedefaultlabel = get_string('sitedefault', 'admin') . ' (' . $languages[get_config('lang')] . ')';
    }
    $elements['lang'] = array('type' => 'select', 'defaultvalue' => $prefs->lang, 'title' => get_string('language', 'account'), 'options' => array_merge(array('default' => $sitedefaultlabel), $languages), 'help' => true, 'ignore' => count($languages) < 2);
    $sitethemes = array();
    // Get all available standard site themes
    if (get_config('sitethemeprefs') && !in_admin_section()) {
        // get_user_accessible_themes() returns 'sitedefault' to mean fall back to the site or
        // institution theme.  This won't work for account prefs, where 'sitedefault' is just
        // a theme that doesn't exist.  So change the 'sitedefault' key to '', and the empty
        // preference will be interpreted as "No theme selected".
        $sitethemes = array_reverse(get_user_accessible_themes());
        unset($sitethemes['sitedefault']);
        $sitethemes = array_reverse($sitethemes);
    }
    // Get all user's institution themes
    $institutionthemes = array();
    if ($institutions = $USER->get('institutions')) {
        $allthemes = get_all_theme_objects();
        foreach ($institutions as $i) {
            if (empty($i->theme)) {
                $institutionthemes['sitedefault' . '/' . $i->institution] = $i->displayname . ' - ' . get_string('sitedefault', 'admin');
            } else {
                $institutionthemes[$i->theme . '/' . $i->institution] = $i->displayname . ' - ' . $allthemes[$i->theme]->displayname;
            }
        }
    }
    $themes = array_merge($sitethemes, $institutionthemes);
    natcasesort($themes);
    $currenttheme = $USER->get_themedata();
    if (!isset($currenttheme->basename)) {
        $defaulttheme = 'sitedefault';
    } else {
        $defaulttheme = $currenttheme->basename;
    }
    if (isset($currenttheme->institutionname)) {
        $defaulttheme = $defaulttheme . '/' . $currenttheme->institutionname;
    }
    if (!array_key_exists($defaulttheme, $themes)) {
        reset($themes);
        $defaulttheme = key($themes);
    }
    $elements['theme'] = array('type' => 'select', 'defaultvalue' => $defaulttheme, 'title' => get_string('theme'), 'options' => $themes, 'ignore' => count($themes) < 2, 'help' => true);
    $elements['addremovecolumns'] = array('type' => 'switchbox', 'defaultvalue' => $prefs->addremovecolumns, 'title' => get_string('showviewcolumns', 'account'), 'help' => 'true');
    // TODO: add a way for plugins (like blog!) to have account preferences
    $elements['multipleblogs'] = array('type' => 'switchbox', 'title' => get_string('enablemultipleblogs1', 'account'), 'description' => get_string('enablemultipleblogsdescription1', 'account'), 'defaultvalue' => $prefs->multipleblogs);
    if (get_config('showtagssideblock')) {
        $elements['tagssideblockmaxtags'] = array('type' => 'text', 'size' => 4, 'title' => get_string('tagssideblockmaxtags', 'account'), 'description' => get_string('tagssideblockmaxtagsdescription', 'account'), 'defaultvalue' => isset($prefs->tagssideblockmaxtags) ? $prefs->tagssideblockmaxtags : get_config('tagssideblockmaxtags'), 'rules' => array('integer' => true, 'minvalue' => 0, 'maxvalue' => 1000));
    }
    $elements['groupsideblockmaxgroups'] = array('type' => 'text', 'size' => 4, 'title' => get_string('limitto1', 'blocktype.mygroups'), 'description' => get_string('limittodescsideblock1', 'blocktype.mygroups'), 'defaultvalue' => isset($prefs->groupsideblockmaxgroups) ? $prefs->groupsideblockmaxgroups : '', 'rules' => array('regex' => '/^[0-9]*$/', 'minvalue' => 0, 'maxvalue' => 1000));
    $elements['groupsideblocksortby'] = array('type' => 'select', 'defaultvalue' => isset($prefs->groupsideblocksortby) ? $prefs->groupsideblocksortby : 'alphabetical', 'title' => get_string('sortgroups', 'blocktype.mygroups'), 'options' => array('latest' => get_string('latest', 'blocktype.mygroups'), 'earliest' => get_string('earliest', 'blocktype.mygroups'), 'alphabetical' => get_string('alphabetical', 'blocktype.mygroups')));
    if (get_config('userscanhiderealnames')) {
        $elements['hiderealname'] = array('type' => 'switchbox', 'title' => get_string('hiderealname', 'account'), 'description' => get_string('hiderealnamedescription', 'account'), 'defaultvalue' => $prefs->hiderealname);
    }
    if (get_config('homepageinfo')) {
        $elements['showhomeinfo'] = array('type' => 'switchbox', 'defaultvalue' => $prefs->showhomeinfo, 'title' => get_string('showhomeinfo2', 'account'), 'description' => get_string('showhomeinfodescription1', 'account', hsc(get_config('sitename'))), 'help' => 'true');
    }
    if (get_config('showprogressbar')) {
        $elements['showprogressbar'] = array('type' => 'switchbox', 'defaultvalue' => $prefs->showprogressbar, 'title' => get_string('showprogressbar', 'account'), 'description' => get_string('showprogressbardescription', 'account', hsc(get_config('sitename'))));
    }
    if (get_config('allowmobileuploads')) {
        $defaultvalue = array();
        $mobileuploadtoken = isset($prefs->mobileuploadtoken) ? $prefs->mobileuploadtoken : get_config('mobileuploadtoken');
        $defaultvalue = explode('|', trim($mobileuploadtoken, '|'));
        $elements['mobileuploadtoken'] = array('type' => 'multitext', 'title' => get_string('mobileuploadtoken', 'account'), 'defaultvalue' => $defaultvalue, 'help' => 'true');
    }
    if (get_config_plugin('artefact', 'file', 'resizeonuploadenable')) {
        $elements['resizeonuploaduserdefault'] = array('type' => 'switchbox', 'title' => get_string('resizeonuploaduserdefault1', 'account'), 'description' => get_string('resizeonuploaduserdefaultdescription2', 'account'), 'defaultvalue' => $prefs->resizeonuploaduserdefault);
    }
    if (get_config('userscandisabledevicedetection')) {
        $elements['devicedetection'] = array('type' => 'switchbox', 'title' => get_string('devicedetection', 'account'), 'description' => get_string('devicedetectiondescription', 'account'), 'defaultvalue' => $prefs->devicedetection);
    }
    return $elements;
}
Beispiel #6
0
/**
 * Fetch a config setting for the specified user's institution.
 * @param string $key
 * @param int $userid (Optional) If not supplied, fetch for the current user's institution
 */
function get_config_user_institution($key, $userid = null)
{
    global $USER;
    if ($userid === null) {
        $userid = $USER->id;
    }
    static $cache = array();
    if (isset($cache[$userid][$key])) {
        return $cache[$userid][$key];
    }
    if ($userid == null) {
        $institutions = $USER->get('institutions');
    } else {
        $institutions = load_user_institutions($userid);
    }
    // If the user belongs to no institution, check the Mahara institution
    if (!$institutions) {
        $institutions = get_records_assoc('institution', 'name', 'mahara');
    }
    $results = array();
    foreach ($institutions as $instname => $inst) {
        $results[$instname] = get_config_institution($instname, $key);
    }
    $cache[$userid][$key] = $results;
    return $results;
}
Beispiel #7
0
     } else {
         $SESSION->add_error_msg(get_string('noauthpluginforinstitution', 'admin'));
     }
 }
 if (!get_config('usersuniquebyusername')) {
     $elements['registerallowed'] = array('type' => 'switchbox', 'title' => get_string('registrationallowed', 'admin'), 'description' => get_string('registrationalloweddescription4', 'admin'), 'defaultvalue' => $data->registerallowed, 'help' => true);
     $elements['registerconfirm'] = array('type' => 'switchbox', 'title' => get_string('registrationconfirm', 'admin'), 'description' => get_string('registrationconfirmdescription2', 'admin'), 'disabled' => get_config('requireregistrationconfirm') == true, 'defaultvalue' => $data->registerconfirm);
 }
 // Some fields to hide from the default institution config screen
 if (empty($data->name) || $data->name != 'mahara') {
     $elements['defaultmembershipperiod'] = array('type' => 'expiry', 'title' => get_string('defaultmembershipperiod', 'admin'), 'description' => get_string('defaultmembershipperioddescription', 'admin'), 'defaultvalue' => $data->defaultmembershipperiod, 'help' => true);
     $languages = get_languages();
     // Get the default language. If the institution has one stored, use that. Otherwise, use 'sitedefault'
     $defaultlang = false;
     if (!empty($data->name)) {
         $defaultlang = get_config_institution($data->name, 'lang');
     }
     // If the defaultlang they provided is no longer valid, use "site default"
     if (!$defaultlang || !array_key_exists($defaultlang, $languages)) {
         $defaultlang = 'sitedefault';
     }
     $elements['lang'] = array('type' => 'select', 'defaultvalue' => $defaultlang, 'title' => get_string('institutionlanguage', 'admin'), 'description' => get_string('institutionlanguagedescription', 'admin'), 'options' => array_merge(array('sitedefault' => get_string('sitedefault', 'admin') . ' (' . $languages[get_config('lang')] . ')'), $languages), 'ignore' => count($languages) < 2);
 }
 $elements['logo'] = array('type' => 'file', 'title' => get_string('Logo', 'admin'), 'description' => get_string('logodescription', 'admin'), 'maxfilesize' => get_max_upload_size(false));
 if (!empty($data->logo)) {
     $logourl = get_config('wwwroot') . 'thumb.php?type=logobyid&id=' . $data->logo;
     $elements['logohtml'] = array('type' => 'html', 'value' => '<img src="' . $logourl . '" alt="' . get_string('Logo', 'admin') . '">');
     $elements['deletelogo'] = array('type' => 'switchbox', 'title' => get_string('deletelogo', 'admin'), 'description' => get_string('deletelogodescription1', 'admin'));
 }
 if (empty($data->name) || $data->name != 'mahara') {
     if (!empty($data->style)) {