pluginconfig.php 3.25 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
<?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);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
30
require_once('pieforms/pieform.php');
31
32
33
34

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

35
36
37
38
safe_require($plugintype, $pluginname);
if ($plugintype == 'artefact') {
    $type = param_alpha('type');
    $classname = generate_artefact_class_name($type);
39
}
40
41
42
43
44
45
46
47
48
49
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');
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
if (isset($form['submitfunction'])) {
    $submitfunction = $form['submitfunction'];
}
if (isset($form['validatefunction'])) {
    $validatefunction = $form['validatefunction'];
}

$form['submitfunction'] = 'pluginconfig_submit';
$form['validatefunction'] = 'pluginconfig_validate';
$form['elements']['plugintype']  = array(
    'type' => 'hidden',
    'value' => $plugintype
);
$form['elements']['pluginname'] = array(
    'type' => 'hidden',
    'value' => $pluginname
);
$form['elements']['type'] = array(
    'type' => 'hidden',
    'value' => $type
);

73
$smarty = smarty();
74
$smarty->assign('form', pieform($form));
75
76
77
78
$smarty->assign('plugintype', $plugintype);
$smarty->assign('pluginname', $pluginname);
$smarty->assign('type', $type);
$smarty->display('admin/plugins/pluginconfig.tpl');
79

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

function pluginconfig_submit($values) {
    $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
    }
    if ($success) {
        json_reply(false, get_string('settingssaved'));
    }
    else {
        json_reply(false, get_string('settingssavefailed'));
    }
}

104
function pluginconfig_validate(Pieform $form, $values) {
105
106
107
108
109
110
111
    global $validatefunction, $plugintype, $pluginname, $classname;
    if (!empty($validatefunction)) {
        call_static_method($classname, $validatefunction, $form, $values);
    }
    

}
112
?>