web.php 68.2 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
4
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 * Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
5
 *
Francois Marier's avatar
Francois Marier committed
6
7
8
9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
10
 *
Francois Marier's avatar
Francois Marier committed
11
12
13
14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
15
 *
Francois Marier's avatar
Francois Marier committed
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
20
21
22
23
24
25
26
27
28
29
 *
 * @package    mahara
 * @subpackage core
 * @author     Penny Leach <penny@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 * @copyright  (C) portions from Moodle, (C) Martin Dougiamas http://dougiamas.com
 */

defined('INTERNAL') || die();


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function &smarty_core() {

    require_once(get_config('libroot') . 'smarty/Smarty.class.php');
    $smarty =& new Smarty();
    
    $theme = theme_setup();
    $themepaths = themepaths();

    $smarty->template_dir = $theme->template_dir;

    $smarty->compile_dir  = get_config('dataroot').'smarty/compile';
    $smarty->cache_dir    = get_config('dataroot').'smarty/cache';

    $smarty->assign('THEMEURL', get_config('themeurl'));
    $smarty->assign('WWWROOT', get_config('wwwroot'));

    $theme_list = array();
    foreach ($themepaths['mahara'] as $themepath) {
        $theme_list[$themepath] = theme_get_url($themepath);
    }
    $smarty->assign('THEMELIST', json_encode($theme_list));

    return $smarty;
}


56
57
58
59
60
61
62
/**
 * This function creates a Smarty object and sets it up for use within our
 * podclass app, setting up some variables.
 *
 * The variables that it sets up are:
 *
 * - THEMEURL: The base url for static content
63
 * - WWWROOT: The base url for the Mahara system
64
65
66
67
68
 * - USER: The user object
 * - JAVASCRIPT: A list of javascript files to include in the header.  This
 *   list is passed into this function (see below).
 * - HEADERS: An array of any further headers to set.  Each header is just
 *   straight HTML (see below).
69
70
 * - PUBLIC: Set true if this page is a public page
 * - MAINNAV: Array defining the main navigation
71
 *
72
73
74
75
76
 * @param $javascript A list of javascript includes.  Each include should be just
 *                    the name of a file, and reside in {$THEMEURL}js/{filename}
 * @param $headers    A list of additional headers.  These are to be specified as
 *                    actual HTML.
 * @param $strings    A list of language strings required by the javascript code.
77
78
 * @return Smarty
 */
79
80

//smarty(array('js/tablerenderer.js', 'artefact/file/js/filebrowser.js'))
81
function &smarty($javascript = array(), $headers = array(), $pagestrings = array(), $extraconfig = array()) {
82
    global $USER, $SESSION;
83
84
85
86
87
88
89
90
91
92
93

    if (!is_array($headers)) {
        $headers = array();
    }
    if (!is_array($pagestrings)) {
        $pagestrings = array();
    }
    if (!is_array($extraconfig)) {
        $extraconfig = array();
    }

Martyn Smith's avatar
Martyn Smith committed
94
    $SIDEBLOCKS = array();
95

96
97
    $smarty = smarty_core();

98
    $wwwroot = get_config('wwwroot');
99
    $jswwwroot = json_encode($wwwroot);
Martyn Smith's avatar
Martyn Smith committed
100
101

    $theme_list = array();
102
103
104
105
    
    if (function_exists('pieform_get_headdata')) {
        $headers = array_merge($headers, pieform_get_headdata());
    }
106

107
    // Insert the appropriate javascript tags 
108
    $javascript_array = array();
109
    $jsroot = $wwwroot . 'js/';
110

Richard Mansfield's avatar
Richard Mansfield committed
111
    // TinyMCE must be included first for some reason we're not sure about
112
    $checkarray = array(&$javascript, &$headers);
113
    $found_tinymce = false;
114
    foreach ($checkarray as &$check) {
115
116
117
118
119
120
121
122
123
124
        if (($key = array_search('tinymce', $check)) !== false || ($key = array_search('tinytinymce', $check)) !== false) {
            if (!$found_tinymce) {
                $found_tinymce = $check[$key];
                $javascript_array[] = $jsroot . 'tinymce/tiny_mce.js';
                if (isset($extraconfig['tinymceinit'])) {
                    $headers[] = $extraconfig['tinymceinit'];
                }
                else {
                    $content_css = json_encode(theme_get_url('style/tinymce.css'));
                    $language = substr(current_language(), 0, 2);
125

126
127
                    if ($check[$key] == 'tinymce') {
                        $tinymce_config = <<<EOF
128
129
    editor_selector: 'wysiwyg',
    theme: "advanced",
130
131
    plugins: "table,emotions,iespell,inlinepopups,paste",
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,hr,emotions,iespell,cleanup,separator,link,unlink,separator,code",
132
    theme_advanced_buttons2 : "bullist,numlist,separator,tablecontrols,separator,cut,copy,paste,pasteword",
133
    theme_advanced_buttons3 : "fontselect,separator,fontsizeselect,separator,formatselect",
134
    theme_advanced_toolbar_location : "top",
135
    theme_advanced_toolbar_align : "center",
136
    width: '512',
137
EOF;
138
139
140
                    }
                    else {
                        $tinymce_config = <<<EOF
141
142
    editor_selector: 'tinywysiwyg',
    theme: "advanced",
143
144
145
    plugins: "fullscreen",
    theme_advanced_buttons1 : "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull",
    theme_advanced_buttons2 : "bullist,numlist,separator,link,unlink,separator,code,fullscreen",
146
147
148
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "center",
149
150
151
152
153
154
155
156
    fullscreen_new_window: true,
    fullscreen_settings: {
        theme: "advanced",
        plugins: "table,emotions,iespell,inlinepopups,paste",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,hr,emotions,iespell,cleanup,separator,link,unlink,separator,code",
        theme_advanced_buttons2 : "bullist,numlist,separator,tablecontrols,separator,cut,copy,paste,pasteword",
        theme_advanced_buttons3 : "fontselect,separator,fontsizeselect,separator,formatselect"
    },
157
EOF;
158
                    }
159

160
                    $headers[] = <<<EOF
161
162
163
164
165
166
<script type="text/javascript">
tinyMCE.init({
    mode: "textareas",
    button_tile_map: true,
    {$tinymce_config}
    language: '{$language}',
167
168
169
    content_css : {$content_css},
    document_base_url: {$jswwwroot},
    relative_urls: false
170
171
172
173
});
</script>

EOF;
174
175
176
177
178
179
180
181
                }
                unset($check[$key]);
            }
            else {
                if ($check[$key] != $found_tinymce) {
                    log_warn('Two differently configured tinyMCE instances have been asked for on this page! This is not possible');
                }
                unset($check[$key]);
182
            }
183
        }
184
185
    }

186
187
    if (get_config('developermode')) {
        $javascript_array[] = $jsroot . 'MochiKit/MochiKit.js';
188
189
190
191
        $javascript_array[] = $jsroot . 'MochiKit/Position.js';
        $javascript_array[] = $jsroot . 'MochiKit/Color.js';
        $javascript_array[] = $jsroot . 'MochiKit/Visual.js';
        $javascript_array[] = $jsroot . 'MochiKit/DragAndDrop.js';
192
        $javascript_array[] = $jsroot . 'MochiKit/Format.js';
193
194
195
196
    }
    else {
        $javascript_array[] = $jsroot . 'MochiKit/Packed.js';
    }
Martyn Smith's avatar
Martyn Smith committed
197
    $javascript_array[] = $jsroot . 'keyboardNavigation.js';
198

199
    $strings = array();
200
201
202
203
204
205
206
207
208
    foreach ($pagestrings as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $tag) {
                $strings[$tag] = get_raw_string($tag, $k);
            }
        }
        else {
            $strings[$k] = get_raw_string($k, $v);
        }
209
210
    }

211
    $jsstrings = jsstrings();
Martyn Smith's avatar
Martyn Smith committed
212
    $themepaths = themepaths();
213

Richard Mansfield's avatar
Richard Mansfield committed
214
    foreach ($javascript as $jsfile) {
215
216
217
218
        // For now, if there's no path in the js file, assume it's in
        // $jsroot and append '.js' to the name.  Later we may want to
        // ensure all smarty() calls include the full path to the js
        // file, with the proper extension.
219
        if (strpos($jsfile, '/') === false) {
220
            $javascript_array[] = $jsroot . $jsfile . '.js';
221
            if (isset($jsstrings[$jsfile])) {
222
223
224
                foreach ($jsstrings[$jsfile] as $section => $tags) {
                    foreach ($tags as $tag) {
                        $strings[$tag] = get_raw_string($tag, $section);
225
226
227
                    }
                }
            }
Martyn Smith's avatar
Martyn Smith committed
228
229
230
231
232
            if (isset($themepaths[$jsfile])) {
                foreach ($themepaths[$jsfile] as $themepath) {
                    $theme_list[$themepath] = theme_get_url($themepath);
                }
            }
233
234
        }
        else {
235
            // A .js file with a fully specified path
236
            $javascript_array[] = $wwwroot . $jsfile;
237
238
239
240
241
242
            // If $jsfile is from a plugin (i.e. plugintype/pluginname/js/foo.js)
            // Then get js strings from static function jsstrings in plugintype/pluginname/lib.php 
            $bits = explode('/', $jsfile);
            if (count($bits) == 4) {
                safe_require($bits[0], $bits[1]);
                $pluginclass = generate_class_name($bits[0], $bits[1]);
243
                $name = substr($bits[3], 0, strpos($bits[3], '.js'));
244
245
                if (is_callable(array($pluginclass, 'jsstrings'))) {
                    $tempstrings = call_static_method($pluginclass, 'jsstrings', $name);
246
247
248
                    foreach ($tempstrings as $section => $tags) {
                        foreach ($tags as $tag) {
                            $strings[$tag] = get_raw_string($tag, $section);
249
250
                        }
                    }
Richard Mansfield's avatar
Richard Mansfield committed
251
                }
252
253
254
255
256
257
258
259
260
                if (is_callable(array($pluginclass, 'jshelp'))) {
                    $tempstrings = call_static_method($pluginclass, 'jshelp', $name);
                    foreach ($tempstrings as $section => $tags) {
                        foreach ($tags as $tag) {
                            $strings[$tag . '.help'] = get_help_icon($bits[0], $bits[1], null, null,
                                                                     null, $tag);
                        }
                    }
                }
Martyn Smith's avatar
Martyn Smith committed
261
262
263
264
265
266
                if (is_callable(array($pluginclass, 'themepaths'))) {
                    $tmpthemepaths = call_static_method($pluginclass, 'themepaths', $name);
                    foreach ($tmpthemepaths as $themepath) {
                        $theme_list[$themepath] = theme_get_url($themepath);
                    }
                }
Martyn Smith's avatar
Martyn Smith committed
267
            }
Martyn Smith's avatar
Martyn Smith committed
268
        }
269
    }
270
271

    $javascript_array[] = $jsroot . 'mahara.js';
272
273
274
275
276
277
    if (get_config('developermode')) {
        $javascript_array[] = $jsroot . 'debug.js';
        if (isset($_SERVER['HTTP_USER_AGENT']) && false === stripos($_SERVER['HTTP_USER_AGENT'], 'gecko')) {
            $javascript_array[] = $jsroot . 'firebug/firebug.js';
        }
    }
278

279
280
281
    foreach ($jsstrings['mahara'] as $section => $tags) {
        foreach ($tags as $tag) {
            $strings[$tag] = get_raw_string($tag, $section);
282
283
        }
    }
284
285
286
287
288
    if (isset($extraconfig['themepaths']) && is_array($extraconfig['themepaths'])) {
        foreach ($extraconfig['themepaths'] as $themepath) {
            $theme_list[$themepath] = theme_get_url($themepath);
        }
    }
289

290
    $stringjs = '<script type="text/javascript">';
291
    $stringjs .= 'var strings = ' . json_encode($strings) . ';';
292
293
    $stringjs .= '</script>';

294
295
296
297
298
299
300
301

    // stylesheet set up - if we're in a plugin also get its stylesheet
    $stylesheets = array_reverse(theme_get_url('style/style.css', null, true));
    if (defined('SECTION_PLUGINTYPE') && defined('SECTION_PLUGINNAME') && SECTION_PLUGINTYPE != 'core') {
        if ($pluginsheets = theme_get_url('style/style.css', SECTION_PLUGINTYPE . '/' . SECTION_PLUGINNAME . '/', true)) {
            $stylesheets = array_merge($stylesheets, array_reverse($pluginsheets));
        }
    }
302
303
304
    if (get_config('developermode')) {
        $stylesheets[] = get_config('wwwroot') . 'theme/debug.css';
    }
305

306
307
308
309
310
311
312
313
314
    // look for extra stylesheets
    if (isset($extraconfig['stylesheets']) && is_array($extraconfig['stylesheets'])) {
        foreach ($extraconfig['stylesheets'] as $extrasheet) {
            if ($sheet = theme_get_url($extrasheet)) {
                $stylesheets[] = $sheet;
            }
        }
    }

315
    $smarty = smarty_core();
316
    $smarty->assign('STRINGJS', $stringjs);
317

318
    $smarty->assign('STYLESHEETLIST', $stylesheets);
319
320
321
322
    if (!empty($theme_list)) {
        // this gets assigned in smarty_core, but do it again here if it's changed locally
        $smarty->assign('THEMELIST', json_encode(array_merge((array)json_decode($smarty->get_template_vars('THEMELIST')),  $theme_list))); 
    }
323

Martyn Smith's avatar
Martyn Smith committed
324
325
326
327
328
329
330
    if (defined('TITLE')) {
        $smarty->assign('PAGETITLE', TITLE . ' - ' . get_config('sitename'));
    }
    else {
        $smarty->assign('PAGETITLE', get_config('sitename'));
    }

331

332
333
334
    $sitename = get_config('sitename');
    $smarty->assign('title', $sitename);
    $smarty->assign('heading', $sitename);
335

336
337
338
    if (defined('PUBLIC')) {
        $smarty->assign('PUBLIC', true);
    }
339
340
341
    if (defined('ADMIN')) {
        $smarty->assign('ADMIN', true);
    }
342
343
344
    if (defined('INSTITUTIONALADMIN')) {
        $smarty->assign('INSTITUTIONALADMIN', true);
    }
345

346
347
    $smarty->assign('LOGGEDIN', $USER->is_logged_in());
    if ($USER->is_logged_in()) {
348
        $smarty->assign('MAINNAV', main_nav());
349
        $smarty->assign('LOGGEDINSTR', get_loggedin_string());
350
351
    }

352
    $smarty->assign_by_ref('USER', $USER);
353
    $smarty->assign('SESSKEY', $USER->get('sesskey'));
354
    $smarty->assign_by_ref('JAVASCRIPT', $javascript_array);
355
356
    $smarty->assign_by_ref('HEADERS', $headers);

357
358
    $smarty->assign('searchform', searchform());

359
360
361
362
363
    if ($help = has_page_help()) {
        $smarty->assign('PAGEHELPNAME', $help[0]);
        $smarty->assign('PAGEHELPICON', $help[1]);
    }

Martyn Smith's avatar
Martyn Smith committed
364
    // ---------- sideblock stuff ----------
365
    if (!defined('INSTALLER') && (defined('MENUITEM') && substr(MENUITEM, 0, 5) != 'admin')) {
366
367
368
369
370
371
372
373
374
375
376
377
378
        if (get_config('installed')) {
            $data = site_menu();
            if (!empty($data)) {
                $smarty->assign('SITEMENU', site_menu());
                $SIDEBLOCKS[] = array(
                    'name'   => 'mainmenu',
                    'weight' => 10,
                    'data'   => $data,
                );
            }
        }

        if ($USER->is_logged_in() && defined('MENUITEM') && substr(MENUITEM, 0, 11) == 'myportfolio') {
Clare Lenihan's avatar
Clare Lenihan committed
379
            $SIDEBLOCKS[] = array(
380
381
382
                'name'   => 'selfsearch',
                'weight' => 0,
                'data'   => array(),
Clare Lenihan's avatar
Clare Lenihan committed
383
384
            );
        }
Clare Lenihan's avatar
Clare Lenihan committed
385

386
387
388
389
390
391
392
        if($USER->is_logged_in()) {
            $SIDEBLOCKS[] = array(
                'name'   => 'profile',
                'weight' => -20,
                'data'   => profile_sideblock()
            );
        }
Martyn Smith's avatar
Martyn Smith committed
393

394
       if (!$USER->is_logged_in()) {
395
            $SIDEBLOCKS[] = array(
396
397
398
399
400
401
                'name'   => 'login',
                'weight' => -10,
                'id'     => 'loginbox',
                'data'   => array(
                    'loginform' => auth_generate_login_form(),
                ),
402
403
            );
        }
404

405
406
407
408
409
410
411
412
413
        if (get_config('enablenetworking')) {
            require_once(get_config('docroot') .'api/xmlrpc/lib.php');
            if ($USER->is_logged_in() && $ssopeers = get_service_providers($USER->authinstance)) {
                $SIDEBLOCKS[] = array(
                    'name'   => 'ssopeers',
                    'weight' => 1,
                    'data'   => $ssopeers,
                );
            }
Martyn Smith's avatar
Martyn Smith committed
414
415
        }

416
417
418
419
420
        if (isset($extraconfig['sideblocks']) && is_array($extraconfig['sideblocks'])) {
            foreach ($extraconfig['sideblocks'] as $sideblock) {
                $SIDEBLOCKS[] = $sideblock;
            }
        }
Martyn Smith's avatar
Martyn Smith committed
421

422
423
424
425
426
        usort($SIDEBLOCKS, create_function('$a,$b', 'if ($a["weight"] == $b["weight"]) return 0; return ($a["weight"] < $b["weight"]) ? -1 : 1;'));

        $smarty->assign('userauthinstance', $USER->lastauthinstance);
        $smarty->assign('SIDEBLOCKS', $SIDEBLOCKS);
    }
Martyn Smith's avatar
Martyn Smith committed
427

428
429
430
    return $smarty;
}

431
432
/** 
 * Returns the lists of strings used in the .js files
433
 * @return array                   
434
435
 */

436
function jsstrings() {
Martyn Smith's avatar
Martyn Smith committed
437
    return array(
438
439
440
       'mahara' => array(                        // js file
            'mahara' => array(                   // section
                'namedfieldempty',               // string name
441
                'processing',
442
443
444
                'requiredfieldempty',
                'unknownerror',
                'loading',
Martyn Smith's avatar
Martyn Smith committed
445
                'showtags',
446
447
                'unreadmessages',
                'unreadmessage',
448
                'couldnotgethelp',
449
            ),
450
451
        ),
        'tablerenderer' => array(
452
453
454
455
456
457
            'mahara' => array(
                'firstpage',
                'nextpage',
                'prevpage',
                'lastpage',
            )
458
        ),
459
        'friends' => array(
460
            'group' => array(
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
                'confirmremovefriend',
                'seeallviews',
                'noviewstosee',
                'sendmessage',
                'whymakemeyourfriend',
                'approverequest',
                'denyrequest',
                'pending',
                'removefromfriendslist',
                'views',
                'trysearchingforfriends',
                'nobodyawaitsfriendapproval',
                'sendfriendrequest',
                'addtomyfriends',
                'friendshiprequested',
                'userdoesntwantfriends',
                'existingfriend',
                'nosearchresultsfound',
479
                'reason',
480
                'requestfriendship',
481
                'cancel',
482
            ),
483
484
485
486
            'mahara' => array(
                'pendingfriend',
                'pendingfriends',
            ),
487
        ),
488
489
490
491
492
        'views' => array(
            'view' => array(
                'confirmdeleteblockinstance',
            ),
        ),
493
494
495
496
497
498
499
500
501
        'adminusersearch' => array(
            'admin' => array(
                'suspenduser',
                'suspensionreason',
            ),
            'mahara' => array(
                'cancel',
            ),
        ),
Martyn Smith's avatar
Martyn Smith committed
502
503
504
    );
}

Martyn Smith's avatar
Martyn Smith committed
505
function themepaths() {
506
507
508
509
510
511
512
513
514
515
516
517
518
519

    static $paths;
    if (empty($paths)) {
        $paths = array(
            'mahara' => array(
                'images/icon_close.gif',
                'images/failure.gif',
                'images/loading.gif',
                'images/success.gif',
                'images/icon_help.gif',
            ),
        );
    }
    return $paths;
Martyn Smith's avatar
Martyn Smith committed
520
521
}

522
523
524
525
526
527
/** 
 * Takes an array of string identifiers and returns an array of the
 * corresponding strings, quoted for use in inline javascript here
 * docs.
 */

528
529
530
531
function quotestrings($strings) {
    $qstrings = array();
    foreach ($strings as $section => $tags) {
        foreach ($tags as $tag) {
532
            $qstrings[$tag] = json_encode(get_string($tag, $section));
533
        }
534
    }
535
    return $qstrings;
536
537
}

538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
/** 
 * This function sets up and caches info about the current selected theme
 * contains inheritance path (used for locating images) and template dirs
 * and potentially more stuff later ( like mime header to send (html vs xhtml))
 * @return object
 */

function theme_setup() {
    
    static $theme;

    if (!empty($theme)) {
        return $theme;
    }
    
    $theme = new StdClass;
554
555
556
557
558
559
560
    global $USER;
    if (!empty($USER)) {
        $theme->theme = $USER->get('theme');
    }
    if (empty($theme->theme)) {
        $theme->theme = get_config('theme');
    }
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
    $theme->path = get_config('docroot') . 'theme/' . $theme->theme . '/';
    $theme->template_dir = array($theme->path . 'templates/');
    $theme->inheritance = array($theme->theme);

    $parent = $theme->theme;

    while (true) {
        if (!$parent = theme_get_parent($parent)) {
            break;
        }
        if ($parent != 'default') {
            $theme->template_dir[] = get_config('docroot') . 'theme/' . $parent . '/templates/';
            $theme->inheritance[] = $parent;
        }
    }

577
    // always put the default theme at the top of the tree, unless we're already it
578
579
    if ($theme->theme != 'default') {
        $theme->template_dir[] = get_config('docroot')  . 'theme/default/templates/';
580
        $theme->inheritance[] = 'default';
581
    }
582

583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
    return $theme;
}

/** 
 * helper function to walk up the inheritance tree and find a parent
 * @param $currtheme the name of the theme to find the parent for
 * @return parent name or false
 */
function theme_get_parent($currtheme) {

    // look for a config file 
    if (is_readable(get_config('docroot') . 'theme/ ' . $currtheme. '/config.php')) {
        require_once(get_config('docroot') . 'theme/ ' . $currtheme. '/config.php');
        if (!empty($theme->parent) && is_dir(get_config('docroot') . 'theme/ ' . $theme->parent)) {
            return $theme->parent;
        }
    }
    return false;
}

/** 
 * This function returns the full url to an image
 * Always use it to get image urls
 * @param $imagelocation path to image relative to theme/$theme/static/
 * @param $pluginlocation path to plugin relative to docroot
 */
609
function theme_get_url($location, $pluginlocation='', $all = false) {
610
    $theme = theme_setup();
611
    $list = array();
612
613

    foreach ($theme->inheritance as $themedir) {
614
615
616
617
618
619
620
        if (is_readable(get_config('docroot') . $pluginlocation . 'theme/' . $themedir . '/static/' . $location)) {
            if ($all) {
                $list[] = get_config('wwwroot') . $pluginlocation . 'theme/' . $themedir . '/static/' . $location;
            }
            else {
                return get_config('wwwroot') . $pluginlocation . 'theme/' . $themedir . '/static/' . $location;
            }
621
622
        }
    }
623
624
625
626
    if ($all) {
        return $list;
    }
    return;
627
628
}

629
630
631
632
633
634
/** 
 * This function returns the full path to an image
 * Always use it to get image paths
 * @param $imagelocation path to image relative to theme/$theme/static/
 * @param $pluginlocation path to plugin relative to docroot
 */
635
function theme_get_path($location, $pluginlocation='') {
636
637
638
    $theme = theme_setup();

    foreach ($theme->inheritance as $themedir) {
639
640
        if (is_readable(get_config('docroot') . $pluginlocation . 'theme/' . $themedir . '/static/' . $location)) {
            return get_config('docroot') . $pluginlocation . 'theme/' . $themedir . '/static/' . $location;
641
642
643
644
        }
    }
}

645
646
647
648
649
/**
 * This function sends headers suitable for all JSON returning scripts.
 *
 */
function json_headers() {
Martyn Smith's avatar
Martyn Smith committed
650
    // @todo martyn This should be changed, but for now it's useful for debugging
651
652
    // header('Content-type: text/x-json');
    header('Content-type: text/plain');
Martyn Smith's avatar
Martyn Smith committed
653
    header('Pragma: no-cache');
654
655
}

Richard Mansfield's avatar
Richard Mansfield committed
656
/**
657
 * This function sends a JSON message, and ends the script.
Richard Mansfield's avatar
Richard Mansfield committed
658
 *
659
660
661
662
663
664
665
666
 * Scripts receiving replies will recieve a JSON array with two fields:
 *
 *  - error: True or false depending on whether the request was successful
 *  - message: JSON data representing a message sent back from the script
 *
 * @param boolean $error   Whether the script ended in an error or not
 * @param string  $message A message to pass back to the user, can be an
 *                         array of JSON data
Richard Mansfield's avatar
Richard Mansfield committed
667
 */
668
function json_reply($error, $message, $returncode=0) {
Richard Mansfield's avatar
Richard Mansfield committed
669
    json_headers();
670
    echo json_encode(array('error' => $error, 'message' => $message, 'returnCode' => $returncode));
671
    perf_to_log();
Richard Mansfield's avatar
Richard Mansfield committed
672
673
674
    exit;
}

675
function _param_retrieve($name) {
676
677
678
679
680
681
682
    // prefer post
    if (isset($_POST[$name])) {
        $value = $_POST[$name];
    } 
    else if (isset($_GET[$name])) {
        $value = $_GET[$name];
    }
683
    else if (func_num_args() == 2) {
684
685
686
        $php_work_around = func_get_arg(1);
        return array($php_work_around, true);
    }
687
    else {
688
689
690
        throw new ParameterException("Missing parameter '$name' and no default supplied");
    }

691
    return array($value, false);
692
693
}

Martyn Smith's avatar
Martyn Smith committed
694
695
696
697
698
699
700
701
702
703
704
/**
 * This function returns a GET or POST parameter with optional default.  If the
 * default isn't specified and the parameter hasn't been sent, a
 * ParameterException exception is thrown
 *
 * @param string The GET or POST parameter you want returned
 * @param mixed [optional] the default value for this parameter
 *
 * @return string The value of the parameter
 *
 */
Martyn Smith's avatar
Martyn Smith committed
705
function param_variable($name) {
706
707
708
    $args = func_get_args();
    list ($value) = call_user_func_array('_param_retrieve', $args);
    return $value;
Martyn Smith's avatar
Martyn Smith committed
709
710
711
712
713
714
715
716
717
718
719
}

/**
 * This function returns a GET or POST parameter as an integer with optional
 * default.  If the default isn't specified and the parameter hasn't been sent,
 * a ParameterException exception is thrown. Likewise, if the parameter isn't a
 * valid integer, a ParameterException exception is thrown
 *
 * @param string The GET or POST parameter you want returned
 * @param mixed [optional] the default value for this parameter
 *
Nigel McNie's avatar
Nigel McNie committed
720
 * @return int The value of the parameter
Martyn Smith's avatar
Martyn Smith committed
721
722
 *
 */
Martyn Smith's avatar
Martyn Smith committed
723
function param_integer($name) {
724
725
726
727
728
729
    $args = func_get_args();

    list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);

    if ($defaultused) {
        return $value;
Martyn Smith's avatar
Martyn Smith committed
730
731
732
733
734
735
    }

    if (preg_match('/^\d+$/',$value)) {
        return (int)$value;
    }

736
    throw new ParameterException("The '$name' parameter is not an integer");
Martyn Smith's avatar
Martyn Smith committed
737
738
}

Martyn Smith's avatar
Martyn Smith committed
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
/**
 * This function returns a GET or POST parameter as an alpha string with optional
 * default.  If the default isn't specified and the parameter hasn't been sent,
 * a ParameterException exception is thrown. Likewise, if the parameter isn't a
 * valid alpha string, a ParameterException exception is thrown
 *
 * Valid characters are a-z and A-Z
 *
 * @param string The GET or POST parameter you want returned
 * @param mixed [optional] the default value for this parameter
 *
 * @return string The value of the parameter
 *
 */
function param_alpha($name) {
754
755
756
757
758
759
    $args = func_get_args();

    list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);

    if ($defaultused) {
        return $value;
Martyn Smith's avatar
Martyn Smith committed
760
761
    }

Richard Mansfield's avatar
Richard Mansfield committed
762
    if (preg_match('/^[a-zA-Z]+$/',$value)) {
Martyn Smith's avatar
Martyn Smith committed
763
764
765
        return $value;
    }

766
    throw new ParameterException("The '$name' parameter is not alphabetical only");
Martyn Smith's avatar
Martyn Smith committed
767
768
}

769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/**
 * This function returns a GET or POST parameter as an alphanumeric string with optional
 * default.  If the default isn't specified and the parameter hasn't been sent,
 * a ParameterException exception is thrown. Likewise, if the parameter isn't a
 * valid alpha string, a ParameterException exception is thrown
 *
 * Valid characters are a-z and A-Z and 0-9
 *
 * @param string The GET or POST parameter you want returned
 * @param mixed [optional] the default value for this parameter
 *
 * @return string The value of the parameter
 *
 */
function param_alphanum($name) {
    $args = func_get_args();

    list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);

    if ($defaultused) {
        return $value;
    }

    if (preg_match('/^[a-zA-Z0-9]+$/',$value)) {
        return $value;
    }

796
    throw new ParameterException("The '$name' parameter is not alphanumeric only");
797
798
}

799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
/**
 * This function returns a GET or POST parameter as an alphanumeric string with optional
 * default.  If the default isn't specified and the parameter hasn't been sent,
 * a ParameterException exception is thrown. Likewise, if the parameter isn't a
 * valid alpha string, a ParameterException exception is thrown
 *
 * Valid characters are a-z and A-Z and 0-9 and _ and - and .
 *
 * @param string The GET or POST parameter you want returned
 * @param mixed [optional] the default value for this parameter
 *
 * @return string The value of the parameter
 *
 */
function param_alphanumext($name) {
    $args = func_get_args();

    list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);

    if ($defaultused) {
        return $value;
    }

    if (preg_match('/^[a-zA-Z0-9_.-]+$/',$value)) {
        return $value;
    }

826
    throw new ParameterException("The '$name' parameter contains invalid characters");
827
828
}

Martyn Smith's avatar
Martyn Smith committed
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
/**
 * This function returns a GET or POST parameter as an array of integers with optional
 * default.  If the default isn't specified and the parameter hasn't been sent,
 * a ParameterException exception is thrown. Likewise, if the parameter isn't a
 * valid integer list , a ParameterException exception is thrown.
 *
 * An integer list is integers separated by commas (with optional whitespace),
 * or just whitespace which indicates an empty list
 *
 * @param string The GET or POST parameter you want returned
 * @param mixed [optional] the default value for this parameter
 *
 * @return array The value of the parameter
 *
 */
function param_integer_list($name) {
845
846
847
848
849
850
    $args = func_get_args();

    list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);

    if ($defaultused) {
        return $value;
Martyn Smith's avatar
Martyn Smith committed
851
852
853
854
855
856
857
858
859
860
    }

    if ($value == '') {
        return array();
    }

    if (preg_match('/^(\d+(,\d+)*)$/',$value)) {
        return array_map('intval', explode(',', $value));
    }

861
    throw new ParameterException("The '$name' parameter is not an integer list");
Martyn Smith's avatar
Martyn Smith committed
862
863
}

Martyn Smith's avatar
Martyn Smith committed
864
865
866
867
868
/**
 * This function returns a GET or POST parameter as a boolean.
 *
 * @param string The GET or POST parameter you want returned
 *
Donal McMullan's avatar
Donal McMullan committed
869
 * @return bool The value of the parameter
Martyn Smith's avatar
Martyn Smith committed
870
871
 *
 */
Martyn Smith's avatar
Martyn Smith committed
872
function param_boolean($name) {
873
874
    
    list ($value) = _param_retrieve($name, false);
Martyn Smith's avatar
Martyn Smith committed
875

876
    if (empty($value) || $value == 'off' || $value == 'no' || $value == 'false') {
Martyn Smith's avatar
Martyn Smith committed
877
878
879
880
881
882
883
        return false;
    }
    else {
        return true;
    }
}

884
/**
885
886
887
 * NOTE: this function is only meant to be used by get_imagesize_parameters(),
 * which you should use in your scripts.
 *
888
889
890
891
892
893
894
 * This function returns a GET or POST parameter as a two element array 
 * repesenting an allowed width and height value for a resized image. If the 
 * default isn't specified and the parameter hasn't been sent, a 
 * ParameterException is thrown. Likewise, if the parameter isn't a valid size 
 * dimension, a ParameterException is thrown.
 *
 * A size parameter is a string, in the form /\d+x\d+/ - e.g. 200x150. The 
895
896
 * width and height are not allowed to be greater than the configured allowed
 * maximums - config variables imagemaxwidth and imagemaxheight.
897
898
899
900
901
902
 *
 * You call this function like so:
 *
 * list($width, $height) = param_imagesize('size');
 *
 * @param string The GET or POST parameter you want returned.
903
 * TODO: i18n for the error messages
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
 */
function param_imagesize($name) {
    $args = func_get_args();

    list ($value, $defaultused) = call_user_func_array('_param_retrieve', $args);

    if ($defaultused) {
        return $value;
    }

    if (!preg_match('/\d+x\d+/', $value)) {
        throw new ParameterException('Invalid size for image specified');
    }

    list($width, $height) = explode('x', $value);
919
    if ($width > get_config('imagemaxwidth') || $height > get_config('imagemaxheight')) {
920
921
        throw new ParameterException('Requested image size is too big');
    }
922
923
    if ($width < 16 || $height < 16) {
        throw new ParameterException('Requested image size is too small');
924
    }
925
926
927
928
929
930
931
932
933
    return array('w' => $width, 'h' => $height);
}

/**
 * Works out what size a requested image should be, based on request parameters
 *
 * The result of this function can be passed to get_dataroot_image_path to 
 * retrieve the filesystem path of the appropriate image
 */
934
935
936
937
938
939
940
941
942
function get_imagesize_parameters($sizeparam='size', $widthparam='width', $heightparam='height',
    $maxsizeparam='maxsize', $maxwidthparam='maxwidth', $maxheightparam='maxheight') {

    $size      = param_imagesize($sizeparam, '');
    $width     = param_integer($widthparam, 0);
    $height    = param_integer($heightparam, 0);
    $maxsize   = param_integer($maxsizeparam, 0);
    $maxwidth  = param_integer($maxwidthparam, 0);
    $maxheight = param_integer($maxheightparam, 0);
943

944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
    $imagemaxwidth  = get_config('imagemaxwidth');
    $imagemaxheight = get_config('imagemaxheight');

    if ($size) {
        return $size;
    }
    if ($maxsize) {
        if ($maxsize > $imagemaxwidth && $maxsize > $imagemaxheight) {
            throw new ParameterException('Requested image size is too big');
        }
        if ($maxsize < 16) {
            throw new ParameterException('Requested image size is too small');
        }
        return $maxsize;
    }
    if ($width) {
        if ($width > $imagemaxwidth) {
            throw new ParameterException('Requested image size is too big');
        }
        if ($width < 16) {
            throw new ParameterException('Requested image size is too small');
        }
        return array('w' => $width);
    }
    if ($height) {
        if ($height > $imagemaxheight) {
            throw new ParameterException('Requested image size is too big');
        }
        if ($height < 16) {
            throw new ParameterException('Requested image size is too small');
        }
        return array('h' => $height);
    }
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
    if ($maxwidth) {
        if ($maxwidth > $imagemaxwidth) {
            throw new ParameterException('Requested image size is too big');
        }
        if ($maxwidth < 16) {
            throw new ParameterException('Requested image size is too small');
        }
        return array('maxw' => $maxwidth);
    }
    if ($maxheight) {
        if ($maxheight > $imagemaxheight) {
            throw new ParameterException('Requested image size is too big');
        }
        if ($maxheight < 16) {
            throw new ParameterException('Requested image size is too small');
        }
        return array('maxh' => $maxheight);
    }
995
    return null;
996
997
}

998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
/**
 * Gets a cookie, respecting the configured cookie prefix
 *
 * @param string $name The name of the cookie to get the value of
 * @return string      The value of the cookie, or null if the cookie does not
 *                     exist.
 */
function get_cookie($name) {
    $name = get_config('cookieprefix') . $name;
    return (isset($_COOKIE[$name])) ? $_COOKIE[$name] : null;
}

/**
 * Sets a cookie, respecting the configured cookie prefix
 *
 * @param string $name    The name of the cookie
 * @param string $value   The value for the cookie
 * @param int    $expires The unix timestamp of the time the cookie should expire
 * @todo path/domain/secure: should be set automatically by this function if possible (?)
 */
function set_cookie($name, $value='', $expires=0, $path='', $domain='', $secure=false) {
    $name = get_config('cookieprefix') . $name;
    setcookie($name, $value, $expires, $path, $domain, $secure);
}

Martyn Smith's avatar
Martyn Smith committed
1023
1024
1025
1026
1027
1028
1029
/**
 * Returns an assoc array of countrys suitable for use with the "select" form
 * element
 *
 * @return array Associative array of countrycodes => countrynames
 */
function getoptions_country() {
1030
1031
1032
1033
    static $countries;
    if (!empty($countries)) {
        return $countries;
    }
1034
    $codes = array(
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
        'af',
        'ax',
        'al',
        'dz',
        'as',
        'ad',
        'ao',
        'ai',
        'aq',
        'ag',
        'ar',
        'am',
        'aw',
        'au',
        'at',
        'az',
        'bs',
        'bh',
        'bd',
        'bb',
        'by',
        'be',
        'bz',
        'bj',
        'bm',
        'bt',
        'bo',
        'ba',
        'bw',
        'bv',
        'br',
        'io',
        'bn',
        'bg',
        'bf',
        'bi',
        'kh',
        'cm',
        'ca',
        'cv',
        'ky',
        'cf',
        'td',
        'cl',
        'cn',
        'cx',
        'cc',
        'co',
        'km',
        'cg',
        'cd',
        'ck',
        'cr',
        'ci',
        'hr',
        'cu',
        'cy',
        'cz',
        'dk',
        'dj',
        'dm',
        'do',
        'ec',
        'eg',
        'sv',
        'gq',
        'er',
        'ee',
        'et',
        'fk',
        'fo',
        'fj',
        'fi',
        'fr',
        'gf',
        'pf',
        'tf',
        'ga',
        'gm',
        'ge',
        'de',
        'gh',
        'gi',
        'gr',
        'gl',
        'gd',
        'gp',
        'gu',
        'gt',
        'gg',
        'gn',
        'gw',
        'gy',
        'ht',
        'hm',
        'va',
        'hn',
        'hk',
        'hu',
        'is',
        'in',
        'id',
        'ir',
        'iq',
        'ie',
        'im',
        'il',
        'it',
        'jm',
        'jp',
        'je',
        'jo',
        'kz',
        'ke',
        'ki',
        'kp',
        'kr',
        'kw',
        'kg',
        'la',
        'lv',
        'lb',
        'ls',
        'lr',
        'ly',
        'li',
        'lt',
        'lu',
        'mo',
        'mk',
        'mg',
        'mw',
        'my',
        'mv',
        'ml',
        'mt',
        'mh',
        'mq',
        'mr',
        'mu',
        'yt',
        'mx',
        'fm',
        'md',
        'mc',
        'mn',
        'ms',
        'ma',
        'mz',
        'mm',
        'na',
        'nr',
        'np',
        'nl',
        'an',
        'nc',
        'nz',
        'ni',
        'ne',
        'ng',
        'nu',
        'nf',
        'mp',
        'no',
        'om',
        'pk',
        'pw',
        'ps',
        'pa',
        'pg',
        'py',
        'pe',
        'ph',
        'pn',
        'pl',
        'pt',
        'pr',
        'qa',
        're',
        'ro',
        'ru',
        'rw',
        'sh',
        'kn',
        'lc',
        'pm',
        'vc',
        'ws',
        'sm',
        'st',
        'sa',
        'sn',
        'cs',
        'sc',
        'sl',
        'sg',
        'sk',
        'si',
        'sb',
        'so',
        'za',
        'gs',
        'es',
        'lk',
        'sd',
        'sr',
        'sj',
        'sz',
        'se',
        'ch',
        'sy',
        'tw',
        'tj',
        'tz',
        'th',
        'tl',
        'tg',
        'tk',
        'to',
        'tt',
        'tn',
        'tr',
        'tm',
        'tc',
        'tv',
        'ug',
        'ua',
        'ae',
        'gb',
        'us',
        'um',
        'uy',
        'uz',
        'vu',
        've',
        'vn',
        'vg',
        'vi',
        'wf',
        'eh',
        'ye',
        'zm',
        'zw',
    );

1280
1281
1282
1283
    foreach ($codes as $c) {
        $countries[$c] = get_string("country.{$c}");
    };
    uasort($countries, 'strcoll');
1284
    return $countries;
Martyn Smith's avatar
Martyn Smith committed
1285
1286
}

Penny Leach's avatar
Penny Leach committed
1287
1288
1289
1290
/**
 * 
 */

1291
function get_help_icon($plugintype, $pluginname, $form, $element, $page='', $section='') {
Nigel McNie's avatar
Nigel McNie committed
1292
    // I see no reason why IE has to drag the quality of the interwebs down with it
1293
    $imageext = (isset($_SERVER['HTTP_USER_AGENT']) && false !== stripos($_SERVER['HTTP_USER_AGENT'], 'msie 6.0')) ? 'gif' : 'png';
1294
    return ' <span class="help"><a href="" onclick="'. 
1295
1296
1297
        hsc(
            'contextualHelp(' . json_encode($form) . ',' . 
            json_encode($element) . ',' . json_encode($plugintype) . ',' . 
1298
1299
1300
            json_encode($pluginname) . ',' . json_encode($page) . ',' . 
            json_encode($section)
            . ',this); return false;'
Nigel McNie's avatar
Nigel McNie committed
1301
        ) . '"><img src="' . theme_get_url('images/icon_help.' . $imageext) . '" alt="?"></a></span>';
Penny Leach's avatar
Penny Leach committed
1302
1303
}

1304
1305
1306
1307
1308
1309
function pieform_get_help(Pieform $form, $element) {
    return get_help_icon($form->get_property('plugintype'),
        $form->get_property('pluginname'),
        $form->get_name(), $element['name']);
}

1310
1311
1312
1313
function make_link($url) {
    return '<a href="' . $url . '">' . $url . '</a>';
}

1314
1315

/**
Nigel McNie's avatar
Nigel McNie committed
1316
 * Returns the entries in the standard admin menu
1317
1318
1319
1320
1321
1322
 *
 * @return $adminnav a data structure containing the admin navigation
 */
function admin_nav() {
    $menu = array(
        array(
1323
            'path'   => 'adminhome',
Nigel McNie's avatar
Nigel McNie committed
1324
1325
1326
            'url'    => 'admin/',
            'title'  => get_string('adminhome', 'admin'),
            'weight' => 10,
1327
1328
        ),
        array(
Nigel McNie's avatar
Nigel McNie committed
1329
1330
1331
1332
            'path'   => 'configsite',
            'url'    => 'admin/site/options.php',
            'title'  => get_string('configsite', 'admin'),
            'weight' => 20,
1333
1334
        ),
        array(
Nigel McNie's avatar
Nigel McNie committed
1335
1336
1337
1338
            'path'   => 'configsite/siteoptions',
            'url'    => 'admin/site/options.php',
            'title'  => get_string('siteoptions', 'admin'),
            'weight' => 10,
1339
        ),
1340
        array(
Nigel McNie's avatar
Nigel McNie committed
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
            'path'   => 'configsite/sitepages',
            'url'    => 'admin/site/pages.php',
            'title'  => get_string('sitepages', 'admin'),
            'weight' => 20
        ),
        array(
            'path'   => 'configsite/sitemenu',
            'url'    => 'admin/site/menu.php',
            'title'  => get_string('sitemenu', 'admin'),
            'weight' => 30,
        ),
        array(
            'path'   => 'configsite/adminfiles',
            'url'    => 'admin/site/files.php',
            'title'  => get_string('adminfiles', 'admin'),
            'weight' => 40,
        ),
        array(
            'path'   => 'configsite/networking',
            'url'    => 'admin/site/networking.php',
            'title'  => get_string('networking', 'admin'),
            'weight' => 50,
        ),
        array(
            'path'   => 'configusers',
1366
            'url'    => 'admin/users/search.php',
Nigel McNie's avatar
Nigel McNie committed
1367
1368
1369
1370
            'title'  => get_string('configusers', 'admin'),
            'weight' => 30,
        ),
        array(
1371
1372
1373
            'path'   => 'configusers/usersearch',
            'url'    => 'admin/users/search.php',
            'title'  => get_string('usersearch', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
1374
1375
1376
1377
1378
1379
            'weight' => 10,
        ),
        array(
            'path'   => 'configusers/suspendedusers',
            'url'    => 'admin/users/suspended.php',
            'title'  => get_string('suspendedusers', 'admin'),
1380
            'weight' => 15,
Nigel McNie's avatar
Nigel McNie committed
1381
1382
1383
1384
        ),
        array(
            'path'   => 'configusers/staffusers',
            'url'    => 'admin/users/staff.php',
1385
            'title'  => get_string('sitestaff', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
1386
1387
1388
1389
1390
            'weight' => 20,
        ),
        array(
            'path'   => 'configusers/adminusers',
            'url'    => 'admin/users/admins.php',
1391
            'title'  => get_string('siteadmins', 'admin'),
Nigel McNie's avatar
Nigel McNie committed
1392
1393
1394
1395
1396
1397
1398
1399
            'weight' => 30,
        ),
        array(
            'path'   => 'configusers/adminnotifications',
            'url'    => 'admin/users/notifications.php',
            'title'  => get_string('adminnotifications', 'admin'),
            'weight' => 40,
        ),
1400
1401
1402
1403
        array(
            'path'   => 'configusers/adduser',
            'url'    => 'admin/users/add.php',
            'title'  => get_string('adduser', 'admin'),
1404
            'weight' => 50,
1405
        ),
Nigel McNie's avatar
Nigel McNie committed
1406
1407
1408
1409
        array(
            'path'   => 'configusers/uploadcsv',
            'url'    => 'admin/users/uploadcsv.php',
            'title'  => get_string('uploadcsv', 'admin'),
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
            'weight' => 60,
        ),
        array(
            'path'   => 'manageinstitutions',
            'url'    => 'admin/users/institutions.php',
            'title'  => get_string('manageinstitutions', 'admin'),
            'weight' => 35,
        ),
        array(
            'path'   => 'manageinstitutions/institutions',
            'url'    => 'admin/users/institutions.php',
            'title'  => get_string('institutions', 'admin'),
            'weight' => 10,
        ),
        array(
            'path'   => 'manageinstitutions/institutionusers',
            'url'    => 'admin/users/institutionusers.php',
            'title'  => get_string('institutionmembers', 'admin'),
            'weight' => 20,
        ),
        array(
            'path'   => 'manageinstitutions/institutionstaff',
            'url'    => 'admin/users/institutionstaff.php',
            'title'  => get_string('institutionstaff', 'admin'),
            'weight' => 30,
        ),
        array(
            'path'   => 'manageinstitutions/institutionadmins',
            'url'    => 'admin/users/institutionadmins.php',
            'title'  => get_string('institutionadmins', 'admin'),
            'weight' => 40,
Nigel McNie's avatar
Nigel McNie committed
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
        ),
        array(
            'path'   => 'configextensions',
            'url'    => 'admin/extensions/plugins.php',
            'title'  => get_string('configextensions', 'admin'),
            'weight' => 40,
        ),
        array(
            'path'   => 'configextensions/pluginadmin',
            'url'    => 'admin/extensions/plugins.php',
            'title'  => get_string('pluginadmin', 'admin'),
            'weight' => 10,
        ),
Penny Leach's avatar