2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /************************************************************************/
15 define('AT_INCLUDE_PATH', '../../include/');
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_ADMIN);
18 require(AT_INCLUDE_PATH.'classes/Module/ModuleListParser.class.php');
19 require(AT_INCLUDE_PATH.'lib/filemanager.inc.php');
21 // delete all folders and files in $dir
22 function clear_dir($dir)
24 if ($dh = opendir($dir))
26 while (($file = readdir($dh)) !== false)
28 if (($file == '.') || ($file == '..'))
31 if (is_dir($dir.$file))
43 // check the connection to server update.atutor.ca
44 $update_server = "http://update.atutor.ca";
45 $connection_test_file = $update_server . '/index.php';
46 $connection = @file_get_contents($connection_test_file);
50 $msg->addInfo(array('CANNOT_CONNECT_MOD_SERVER'));
55 $module_folder = $update_server . '/modules/';
57 $module_list_xml = @file_get_contents($module_folder . 'module_list.xml');
61 $moduleListParser = new ModuleListParser();
62 $moduleListParser->parse($module_list_xml);
63 $module_list_array = $moduleListParser->getParsedArray();
65 // end of get module list
67 $module_content_folder = AT_CONTENT_DIR . "module/";
69 if (!is_dir($module_content_folder)) mkdir($module_content_folder);
71 // end of get module list
73 $module_content_folder = AT_CONTENT_DIR . "module/";
75 if (!is_dir($module_content_folder)) mkdir($module_content_folder);
77 // Installation process
78 if ((isset($_POST['install']) || isset($_POST["download"]) || isset($_POST["version_history"])) && !isset($_POST["id"]))
80 $msg->addError('NO_ITEM_SELECTED');
82 else if (isset($_POST['install']) || isset($_POST["download"]) || isset($_POST["version_history"]) || isset($_POST["install_upload"]))
84 if ($_POST['version_history'])
86 header('Location: '.AT_BASE_HREF.'admin/modules/version_history.php?id='.$_POST["id"]);
90 // install and download
91 if ($_POST["install_upload"])
92 $module_zip_file = $_FILES['modulefile']['tmp_name'];
94 $module_zip_file = $module_folder . $module_list_array[$_POST["id"]]['history'][0]['location'].$module_list_array[$_POST["id"]]['history'][0]['filename'];
96 $file_content = file_get_contents($module_zip_file);
98 if (!$file_content & ($_POST['install'] || $_POST['download']))
100 $msg->addError('FILE_NOT_EXIST');
104 if ($_POST['install'] || $_POST['install_upload'])
106 clear_dir($module_content_folder);
108 // download zip file from update.atutor.ca and write into module content folder
109 if ($_POST["install_upload"])
110 $local_module_zip_file = $module_content_folder . $_FILES['modulefile']['name'];
112 $local_module_zip_file = $module_content_folder. $module_list_array[$_POST["id"]]['history'][0]['filename'];
114 $fp = fopen($local_module_zip_file, "w");
115 fwrite($fp, $file_content);
118 // unzip uploaded file to module's content directory
119 include_once(AT_INCLUDE_PATH . '/classes/pclzip.lib.php');
121 $archive = new PclZip($local_module_zip_file);
123 if ($archive->extract(PCLZIP_OPT_PATH, $module_content_folder) == 0)
125 clear_dir($module_content_folder);
126 $msg->addError('CANNOT_UNZIP');
129 if (!$msg->containsErrors())
131 // find unzip module folder name
134 if ($dh = opendir($module_content_folder))
136 while (($module_folder = readdir($dh)) !== false)
138 if ($module_folder <> "." && $module_folder <> ".." && is_dir($module_content_folder.$module_folder)) break;
144 if ($module_folder == "." || $module_folder == ".." || !isset($module_folder))
145 $msg->addError('EMPTY_ZIP_FILE');
148 // check if the same module exists in "mods" folder. If exists, it has been installed
149 if (!$msg->containsErrors())
151 if (is_dir("../../mods/". $module_folder))
152 $msg->addError('ALREADY_INSTALLED');
155 if (!$msg->containsErrors())
157 header('Location: module_install_step_1.php?mod='.urlencode($module_folder).SEP.'new=1');
162 if ($_POST['download'])
164 $id = intval($_POST['id']);
166 header('Content-Type: application/x-zip');
167 header('Content-transfer-encoding: binary');
168 header('Content-Disposition: attachment; filename="'.htmlspecialchars($module_list_array[$id]['history'][0]['filename']).'"');
169 header('Expires: 0');
170 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
171 header('Pragma: public');
172 header('Content-Length: '.strlen($file_content));
180 if (isset($_POST['mod'])) {
181 $dir_name = str_replace(array('.','..'), '', $_POST['mod']);
183 if (isset($_POST['install_manually'])) {
184 header('Location: '.AT_BASE_HREF.'admin/modules/module_install_step_2.php?mod='.urlencode($dir_name).SEP.'new=1'.SEP.'mod_in=1');
188 } else if (isset($_POST['install_manually'])) {
189 $msg->addError('NO_ITEM_SELECTED');
192 $module_list = $moduleFactory->getModules(AT_MODULE_STATUS_UNINSTALLED | AT_MODULE_STATUS_MISSING | AT_MODULE_STATUS_PARTIALLY_UNINSTALLED, AT_MODULE_TYPE_EXTRA);
193 $keys = array_keys($module_list);
196 require (AT_INCLUDE_PATH.'header.inc.php');
202 <form name="frm_upload" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
204 <div class="input-form">
205 <div class="row"><?php echo _AT("upload_module"); ?></div>
208 <input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
209 <input type="file" name="modulefile" size="50" />
212 <div class="row buttons">
213 <input type="submit" name="install_upload" value="<?php echo _AT('install'); ?>" onclick="javascript: return validate_filename(); " class="submit" />
214 <input type="hidden" name="uploading" value="1" />
221 if (count($keys) > 0)
224 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="installform">
225 <table class="data" summary="" rules="cols">
228 <th scope="col"> </th>
229 <th scope="col"><?php echo _AT('module_name'); ?></th>
230 <th scope="col"><?php echo _AT('directory_name'); ?></th>
231 <th scope="col"><?php echo _AT('description'); ?></th>
238 <input type="submit" name="install_manually" value="<?php echo _AT('install'); ?>" />
244 <?php if (!empty($keys)): ?>
245 <?php foreach($keys as $dir_name) : $module =& $module_list[$dir_name]; ?>
246 <tr onmousedown="document.installform['m_<?php echo $dir_name; ?>'].checked = true; rowselect(this);" id="r_<?php echo $dir_name; ?>">
247 <td valign="top"><input type="radio" id="m_<?php echo $dir_name; ?>" name="mod" value="<?php echo $dir_name; ?>" /></td>
248 <td valign="top"><label for="m_<?php echo $row['dir_name']; ?>"><?php echo $module->getName(); ?></label></td>
249 <td valign="top"><code><?php echo $dir_name; ?>/</code></td>
250 <td valign="top"><?php echo $module->getDescription($_SESSION['lang']); ?></td>
255 <td colspan="4"><?php echo _AT('none_found'); ?></td>
266 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
269 <table class="data" summary="" rules="cols">
272 <th scope="col"> </th>
273 <th scope="col"><?php echo _AT('module_name');?></th>
274 <th scope="col"><?php echo _AT('description');?></th>
275 <th scope="col"><?php echo _AT('version');?></th>
276 <th scope="col"><?php echo _AT('atutor_version_tested_with');?></th>
277 <th scope="col"><?php echo _AT('maintainers');?></th>
278 <th scope="col"><?php echo _AT('installed').'?';?></th>
285 <input type="submit" name="install" value="<?php echo _AT('install'); ?>" />
286 <input type="submit" name="download" value="<?php echo _AT('download'); ?>" />
287 <input type="submit" name="version_history" value="<?php echo _AT('version_history'); ?>" />
294 $num_of_modules = count($module_list_array);
296 if ($num_of_modules == 0)
301 <td colspan="7"><?php echo _AT('none_found'); ?></td>
309 if(is_array($module_list_array))
311 for ($i=0; $i < $num_of_modules; $i++)
313 // check if the module has been installed
314 $sql = "SELECT * FROM ".TABLE_PREFIX."modules WHERE dir_name = '" . $module_list_array[$i]["history"][0]["install_folder"] . "'";
315 $result = mysql_query($sql, $db) or die(mysql_error());
317 if (mysql_num_rows($result) == 0) $installed = false;
318 else $installed = true;
321 <tr onmousedown="document.form['m<?php echo $i; ?>'].checked = true; rowselect(this);" id="r_<?php echo $i; ?>">
322 <td><input type="radio" name="id" value="<?php echo $i; ?>" id="m<?php echo $i; ?>" <?php if ($installed) echo 'disabled="disabled"'; ?> /></td>
323 <td><label for="m<?php echo $i; ?>"><?php echo $module_list_array[$i]["name"]; ?></label></td>
324 <td><?php echo $module_list_array[$i]["description"]; ?></td>
325 <td><?php echo $module_list_array[$i]["history"][0]["version"]; ?></td>
326 <td><?php echo $module_list_array[$i]["atutor_version"]; ?></td>
327 <td><?php echo $module_list_array[$i]["history"][0]["maintainer"]; ?></td>
328 <td><?php if ($installed) echo _AT("installed"); else echo _AT("not_installed"); ?></td>
344 <script language="JavaScript">
347 String.prototype.trim = function() {
348 return this.replace(/^\s+|\s+$/g,"");
351 // This function validates if and only if a zip file is given
352 function validate_filename() {
354 var file = document.frm_upload.modulefile.value;
355 if (!file || file.trim()=='') {
356 alert('Please give a zip file!');
360 if(file.slice(file.lastIndexOf(".")).toLowerCase() != '.zip') {
361 alert('Please upload ZIP file only!');
370 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>