templates.php 3.53 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 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
 *
 */

define('INTERNAL', 1);
define('ADMIN', 1);

Nigel McNie's avatar
Nigel McNie committed
30
define('MENUITEM', 'configextensions');
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
define('SUBMENUITEM', 'templateadmin');

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('libroot') . 'template.php');


$installedtemplates = get_column('template', 'name');
$alltemplates = array();
$templates = get_dir_contents(get_config('dataroot') . 'templates/');
foreach ($templates as $dir) {
    $alltemplates[$dir] = array();
}
$templates = get_dir_contents(get_config('libroot') . 'templates/');
foreach ($templates as $dir) {
    if (!array_key_exists($dir,$templates)) {
        $alltemplates[$dir] = array();
    }
}

foreach (array_keys($alltemplates) as $t) {
    try {
        $alltemplates[$t]['template'] = template_parse($t);
    }
    catch (TemplateParserException $e) {
        $alltemplates[$t]['error'] = $e->getMessage();
    }
    if (in_array($t, $installedtemplates)) {
        $alltemplates[$t]['installed'] = true;
    }
}
61
62
63
$loadingicon = theme_get_image_url('loading.gif');
$successicon = theme_get_image_url('success.gif');
$failureicon = theme_get_image_url('failure.gif');
64
65
66
67
68
69
70
71

$loadingstring = get_string('upgradeloading', 'admin');
$successstring = get_string('upgradesuccess', 'admin');
$failurestring = get_string('upgradefailure', 'admin');

$javascript = <<<JAVASCRIPT

function installtemplate(name) {
72
    var d = loadJSONDoc('templateinstall.json.php', { 'name': name });
73
74
75
76
77

    $(name + '.message').innerHTML = '<img src="{$loadingicon}" alt="{$loadingstring}" />';

    d.addCallbacks(function (data) {
        if (!data.error) {
78
            var message = '{$successstring}';
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
104
105
106
107
108
109
            $(name + '.message').innerHTML = '<img src="{$successicon}" alt=":)" />  ' + message;
            // move the whole thing into the list of installed plugins 
            // new parent node
            $(name + '.status').src = '$successicon';
        }
        else {
            var message = '';
            if (data.message) {
                message = data.message;
            } 
            else {
                message = '{$failurestring}';
            }
            $(name).innerHTML = '<img src="{$failureicon}" alt=":(" /> ' + message;
        }
    },
                   function () {
                       message = '{$failurestring}';
                       $(name).innerHTML = message;
                   });
}
JAVASCRIPT;


$smarty = smarty();
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('templates', $alltemplates);
$smarty->assign('installlink', 'installtemplate');
$smarty->display('admin/extensions/templates.tpl');

?>