frameworkmanager.php 2.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
 *
 * @package    mahara
 * @subpackage module-framework
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */

define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configextensions/frameworks');
define('SECTION_PLUGINTYPE', 'module');
define('SECTION_PLUGINNAME', 'framework');
define('SECTION_PAGE', 'frameworks');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('Framework', 'module.framework'));

safe_require('module', 'framework');

$frameworkid  = param_integer('id', 0);
$framework = new Framework($frameworkid);

$plugintype = 'module';
$pluginname = 'framework';
$classname = 'Framework';

$form = $framework->get_framework_config_options();
if (!array_key_exists('class', $form)) {
    $form['class'] = 'panel panel-body';
}

$form['name'] = 'frameworkconfig';
$form['frameworkconfigform'] = true;
$form['jsform'] = true;
$form['successcallback'] = 'frameworkconfig_submit';
$form['elements']['plugintype']  = array(
    'type' => 'hidden',
    'value' => $plugintype
);
$form['elements']['pluginname'] = array(
    'type' => 'hidden',
    'value' => $pluginname
);
$form['elements']['framework'] = array(
    'type' => 'hidden',
    'value' => $frameworkid
);
$form['elements']['save'] = array(
    'type'  => 'submitcancel',
    'class' => 'btn-primary',
    'value' => array(
          get_string('save'),
          get_string('cancel')
    ),
    'goto' => get_config('wwwroot') . 'module/framework/frameworks.php',
);

$form = pieform($form);

$smarty = smarty();
$smarty->assign('form', $form);
$smarty->assign('plugintype', $plugintype);
$smarty->assign('pluginname', $pluginname);
$heading = get_string('pluginadmin', 'admin') . ': ' . $plugintype . ': ' . $pluginname;
$smarty->assign('PAGEHEADING', $heading);
$smarty->display('module:framework:frameworkmanager.tpl');


function frameworkconfig_submit(Pieform $form, $values) {
    $success = false;
    global $plugintype, $pluginname, $classname, $USER;

    if (!is_plugin_active($pluginname, $plugintype)) {
        $SESSION->add_error_msg(get_string('needtoactivate', 'module.framework'));
    }
    if (!$USER->get('admin')) {
        $SESSION->add_error_msg(get_string('accessdenied'));
    }
    try {
        $frameworkid = $values['framework'];
        $framework = new Framework($frameworkid);
        $framework->save_config_options($form, $values);
        $success = true;
    }
    catch (Exception $e) {
        $success = false;
    }

    if ($success) {
        $form->json_reply(PIEFORM_OK, get_string('settingssaved'));
    }
    else {
        $form->json_reply(PIEFORM_ERR, array('message' => get_string('settingssavefailed')));
    }

}