move code up one directory
[atutor.git] / mods / _core / modules / index.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12 // $Id$
13
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 admin_authenticate(AT_ADMIN_PRIV_MODULES);
17
18 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
19
20 $dir_name = str_replace(array('.','..'), '', $_GET['mod_dir']);
21
22 $args = '';
23
24 if (isset($_GET['enabled'])  && $_GET['enabled'])  {  $args .= 'enabled=1';      }
25 if (isset($_GET['disabled']) && $_GET['disabled']) {  $args .= SEP.'disabled=1'; }
26 if (isset($_GET['missing'])  && $_GET['missing'])  {  $args .= SEP.'missing=1';  }
27 if (isset($_GET['partially_uninstalled'])  && $_GET['partially_uninstalled'])  {  $args .= SEP.'partially_uninstalled=1';  }
28 if (isset($_GET['core'])     && $_GET['core'])     {  $args .= SEP.'core=1';     }
29 if (isset($_GET['standard']) && $_GET['standard']) {  $args .= SEP.'standard=1'; }
30 if (isset($_GET['extra'])    && $_GET['extra'])    {  $args .= SEP.'extra=1';    }
31
32 if (isset($_GET['reset_filter'])) {
33         header('Location: '.$_SERVER['PHP_SELF']);
34         exit;
35 }
36
37 if (isset($_GET['mod_dir'], $_GET['enable'])) {
38         $module = $moduleFactory->getModule($_GET['mod_dir']);
39         if (!$module->isEnabled() && !$module->isCore() && !$module->isMissing() && !$module->isPartiallyUninstalled()) {
40                 $module->enable();
41                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
42         }
43
44         header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args);
45         exit;
46 } else if (isset($_GET['mod_dir'], $_GET['disable'])) {
47         $module = $moduleFactory->getModule($_GET['mod_dir']);
48         if ($module->isCore()) {
49                 // core modules cannot be disabled!
50                 $msg->addError('DISABLE_CORE_MODULE');
51         } else if ($module->isMissing()) {
52                 $msg->addError('DISABLE_MISSING_MODULE');
53         } else if ($module->isPartiallyUninstalled()) {
54                 $msg->addError('DISABLE_PARTIALLY_UNINSTALLED_MODULE');
55         } else if ($module->isEnabled()) {
56                 $module->disable();
57                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
58         }
59         header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args);
60         exit;
61 } else if (isset($_GET['mod_dir'], $_GET['details'])) {
62         header('Location: details.php?mod='.$_GET['mod_dir'] . SEP . $args);
63         exit;
64
65 } else if (isset($_GET['mod_dir'], $_GET['uninstall'])) {
66         $module = $moduleFactory->getModule($_GET['mod_dir']);
67
68         $module_folder = '../../../mods/'.$_GET['mod_dir'];
69         // check if the module has been un-installed
70         if (!file_exists($module_folder))
71         {
72                 $msg->addError('ALREADY_UNINSTALLED');
73         }
74
75         // only extra modules can be uninstalled
76         if (!$module->isExtra()) {
77                 $msg->addError('ONLY_UNINSTALL_EXTRA_MODULE');
78         } 
79         // check if the module is installed via "Available Extra Modules"
80         // which are the modules can be un-installed 
81         else if (!file_exists($module_folder.'/module_uninstall.php') || !is_writable($module_folder))
82         {
83                 $msg->addError('CANNOT_UNINSTALL_MANUAL_MODULE');
84         }
85         
86   if (!$msg->containsErrors())
87         {
88                 header('Location: module_uninstall_step_1.php?mod=' . urlencode($_GET['mod_dir']) . SEP.'args='.urlencode($args));
89                 exit;
90         }
91
92 } else if (isset($_GET['mod_dir'], $_GET['export'])) {
93         $module = $moduleFactory->getModule($_GET['mod_dir']);
94
95         $module_folder = '../../../mods/'.$_GET['mod_dir'];
96         // check if the module has been un-installed
97         if (!file_exists($module_folder))
98         {
99                 $msg->addError('ITEM_NOT_FOUND');
100         }
101
102         // only extra modules can be uninstalled
103         if (!$module->isExtra()) {
104                 $msg->addError('ONLY_EXPORT_EXTRA_MODULE');
105         } 
106         
107   if (!$msg->containsErrors())
108         {
109                 require(AT_INCLUDE_PATH.'classes/zipfile.class.php');                           /* for zipfile */
110                 
111                 $zipfile = new zipfile();
112                 $zipfile->add_dir('../../../mods/'.$_GET['mod_dir'].'/', $_GET['mod_dir'].'/');
113                 $zipfile->close();
114                 $zipfile->send_file($_GET['mod_dir']);
115                 exit;
116         }
117
118 } else if (isset($_GET['disable']) || isset($_GET['enable']) || isset($_GET['details']) || isset($_GET['uninstall']) || isset($_GET['export'])) {
119         $msg->addError('NO_ITEM_SELECTED');
120         header('Location: '.$_SERVER['PHP_SELF'] . '?' . $args);
121         exit;
122 }
123
124 require(AT_INCLUDE_PATH.'header.inc.php'); 
125
126 $module_status_bits = $module_type_bits = 0;
127
128 if ($_GET['enabled'])  { $module_status_bits += AT_MODULE_STATUS_ENABLED;  }
129 if ($_GET['disabled']) {        $module_status_bits += AT_MODULE_STATUS_DISABLED; }
130 if ($_GET['missing'])  {        $module_status_bits += AT_MODULE_STATUS_MISSING;  }
131 if ($_GET['partially_uninstalled'])  {  $module_status_bits += AT_MODULE_STATUS_PARTIALLY_UNINSTALLED;  }
132
133 if ($_GET['core'])     {  $module_type_bits += AT_MODULE_TYPE_CORE;     }
134 if ($_GET['standard']) {  $module_type_bits += AT_MODULE_TYPE_STANDARD; }
135 if ($_GET['extra'])    {  $module_type_bits += AT_MODULE_TYPE_EXTRA;    }
136
137 if ($module_status_bits == 0) {
138         $module_status_bits = AT_MODULE_STATUS_DISABLED | AT_MODULE_STATUS_ENABLED | AT_MODULE_STATUS_MISSING | AT_MODULE_STATUS_PARTIALLY_UNINSTALLED;
139         $_GET['enabled'] = $_GET['disabled'] = $_GET['missing'] = $_GET['partially_uninstalled'] = 1;
140 }
141
142 if ($module_type_bits == 0) {
143         $module_type_bits = AT_MODULE_TYPE_STANDARD + AT_MODULE_TYPE_EXTRA;
144         $_GET['standard'] = $_GET['extra'] = 1;
145 }
146
147
148 $module_list = $moduleFactory->getModules($module_status_bits, $module_type_bits, $sort = TRUE);
149 $keys = array_keys($module_list);
150 $savant->assign('module_list', $module_list);
151 $savant->assign('keys', $keys);
152 $savant->display('admin/modules/index.tmpl.php');
153 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>