pluginconfig.php 3.41 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
<?php
/**
 * This program is part of Mahara
 *
 *  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 2 of the License, or
 *  (at your option) any later version.
 *
 *  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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 * @package    mahara
 * @subpackage admin
 * @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
 *
 */

define('INTERNAL', 1);
define('ADMIN', 1);
29
30
define('MENUITEM', 'configextensions');
define('SUBMENUITEM', 'pluginadmin');
31
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
32
require_once('pieforms/pieform.php');
33
34
35
36

$plugintype = param_alpha('plugintype');
$pluginname = param_alpha('pluginname');

37
38
39
40
safe_require($plugintype, $pluginname);
if ($plugintype == 'artefact') {
    $type = param_alpha('type');
    $classname = generate_artefact_class_name($type);
41
}
42
43
44
45
46
47
48
49
50
51
else {
    $type = null;
    $classname = generate_class_name($plugintype, $pluginname);
}

if (!call_static_method($classname, 'has_config')) {
    throw new InvalidArgumentException("$classname doesn't have config options available");
}

$form = call_static_method($classname, 'get_config_options');
52

53
54
55
56
57
58
59
if (isset($form['submitfunction'])) {
    $submitfunction = $form['submitfunction'];
}
if (isset($form['validatefunction'])) {
    $validatefunction = $form['validatefunction'];
}

60
61
62
$form['jsform'] = true;
$form['successcallback'] = 'pluginconfig_submit';
$form['validatecallback'] = 'pluginconfig_validate';
63
64
65
66
67
68
69
70
71
72
73
74
75
$form['elements']['plugintype']  = array(
    'type' => 'hidden',
    'value' => $plugintype
);
$form['elements']['pluginname'] = array(
    'type' => 'hidden',
    'value' => $pluginname
);
$form['elements']['type'] = array(
    'type' => 'hidden',
    'value' => $type
);

76
$smarty = smarty();
77
$smarty->assign('form', pieform($form));
78
79
80
$smarty->assign('plugintype', $plugintype);
$smarty->assign('pluginname', $pluginname);
$smarty->assign('type', $type);
81
$smarty->display('admin/extensions/pluginconfig.tpl');
82

83

84
function pluginconfig_submit(Pieform $form, $values) {
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    $success = false;
    global $submitfunction, $plugintype, $pluginname, $classname;
    if (!empty($submitfunction)) {
        try {
            call_static_method($classname, $submitfunction, $values);
            $success = true;
        }
        catch (Exception $e) {
            $success = false;
        }
    }
    else {
        // call set_plugin_config and stuffs
    }
99

100
    if ($success) {
101
        $form->json_reply(PIEFORM_OK, get_string('settingssaved'));
102
103
    }
    else {
104
        $form->json_reply(PIEFORM_ERR, array('message' => get_string('settingssavefailed')));
105
106
107
    }
}

108
function pluginconfig_validate(PieForm $form, $values) {
109
110
111
112
    global $validatefunction, $plugintype, $pluginname, $classname;
    if (!empty($validatefunction)) {
        call_static_method($classname, $validatefunction, $form, $values);
    }
Richard Mansfield's avatar
Richard Mansfield committed
113
}
114
?>