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/Themes/ThemeListParser.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 $infos = array('CANNOT_CONNECT_SERVER', $update_server);
51 $msg->addError($infos);
53 require(AT_INCLUDE_PATH.'header.inc.php');
55 require(AT_INCLUDE_PATH.'footer.inc.php');
60 $theme_folder = $update_server . '/themes/';
61 $local_theme_folder = "../../themes/";
63 $theme_list_xml = @file_get_contents($theme_folder . 'theme_list.xml');
67 $themeListParser = new ThemeListParser();
68 $themeListParser->parse($theme_list_xml);
69 $theme_list_array = $themeListParser->getParsedArray();
71 // end of get theme list
73 $theme_content_folder = AT_CONTENT_DIR . "theme/";
75 // create theme content dir if not exists
76 if (!is_dir($theme_content_folder)) mkdir($theme_content_folder);
78 // Installation process
79 if ((isset($_POST['install']) || isset($_POST["download"]) || isset($_POST["version_history"])) && !isset($_POST["id"]))
81 $msg->addError('NO_ITEM_SELECTED');
83 else if (isset($_POST['install']) || isset($_POST["download"]) || isset($_POST["version_history"]) || isset($_POST["import"]))
85 if ($_POST['version_history'])
87 header('Location: '.AT_BASE_HREF.'admin/themes/version_history.php?id='.$_POST["id"]);
91 // install and download
94 if (isset($_POST['url']) && ($_POST['url'] != 'http://') )
96 $file_content = file_get_contents($_POST['url']);
97 $filename = pathinfo($_POST['url']);
98 $filename = $filename['basename'];
102 $file_content = file_get_contents($_FILES['themefile']['tmp_name']);
103 $filename = $_FILES['themefile']['name'];
108 $file_content = file_get_contents($theme_folder . $theme_list_array[$_POST["id"]]['history'][0]['location'].$theme_list_array[$_POST["id"]]['history'][0]['filename']);
111 if (!$file_content & ($_POST['install'] || $_POST['download']))
113 $msg->addError('FILE_NOT_EXIST');
117 if ($_POST['install'] || $_POST['import'])
119 clear_dir($theme_content_folder);
121 // download zip file from update.atutor.ca and write into theme content folder
122 if ($_POST["import"])
123 $local_theme_zip_file = $theme_content_folder . $filename;
125 $local_theme_zip_file = $theme_content_folder. $theme_list_array[$_POST["id"]]['history'][0]['filename'];
127 $fp = fopen($local_theme_zip_file, "w");
128 fwrite($fp, $file_content);
131 // unzip uploaded file to theme's content directory
132 include_once(AT_INCLUDE_PATH . '/classes/pclzip.lib.php');
134 $archive = new PclZip($local_theme_zip_file);
136 if ($archive->extract(PCLZIP_OPT_PATH, $theme_content_folder) == 0)
138 clear_dir($theme_content_folder);
139 $msg->addError('CANNOT_UNZIP');
142 if (!$msg->containsErrors())
144 // find unzip theme folder name
147 if ($dh = opendir($theme_content_folder))
149 while (($this_theme_folder = readdir($dh)) !== false)
151 if ($this_theme_folder <> "." && $this_theme_folder <> ".." && is_dir($theme_content_folder.$this_theme_folder)) break;
157 if ($this_theme_folder == "." || $this_theme_folder == ".." || !isset($this_theme_folder))
158 $msg->addError('EMPTY_ZIP_FILE');
161 // check if the same theme exists in "themes" folder. If exists, it has been installed
162 if (!$msg->containsErrors())
164 if (is_dir($local_theme_folder. $this_theme_folder))
165 $msg->addError('ALREADY_INSTALLED');
168 if (!$msg->containsErrors())
170 header('Location: theme_install_step_1.php?theme='.urlencode($this_theme_folder).SEP.'title='.urlencode($theme_list_array[$_POST["id"]]["name"]));
175 if ($_POST['download'])
177 $id = intval($_POST['id']);
179 header('Content-Type: application/x-zip');
180 header('Content-transfer-encoding: binary');
181 header('Content-Disposition: attachment; filename="'.htmlspecialchars($theme_list_array[$id]['history'][0]['filename']).'"');
182 header('Expires: 0');
183 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
184 header('Pragma: public');
185 header('Content-Length: '.strlen($file_content));
193 require (AT_INCLUDE_PATH.'header.inc.php');
199 <form name="frm_upload" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
200 <div class="input-form" style="width:50%;">
202 <h3><?php echo _AT('import_theme'); ?></h3>
206 <input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
207 <label for="file"><?php echo _AT('upload_theme_package'); ?></label><br />
208 <input type="file" name="themefile" size="40" id="file" />
212 <label for="url"><?php echo _AT('specify_url_to_theme_package'); ?></label><br />
213 <input type="text" name="url" value="http://" size="40" id="url" />
216 <div class="row buttons">
217 <input type= "submit" name="import" value="<?php echo _AT('import'); ?>" onclick="javascript: return validate_filename(); " />
222 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
225 <table class="data" summary="" rules="all">
228 <th scope="col"> </th>
229 <th scope="col"><?php echo _AT('title');?></th>
230 <th scope="col"><?php echo _AT('installed').'?';?></th>
231 <th scope="col"><?php echo _AT('atutor_version_tested_with');?></th>
232 <th scope="col"><?php echo _AT('description');?></th>
233 <th scope="col"><?php echo _AT('theme_screenshot');?></th>
240 <input type="submit" name="install" value="<?php echo _AT('install'); ?>" />
241 <input type="submit" name="download" value="<?php echo _AT('download'); ?>" />
242 <input type="submit" name="version_history" value="<?php echo _AT('version_history'); ?>" />
249 $num_of_themes = count($theme_list_array);
251 if ($num_of_themes == 0)
256 <td colspan="6"><?php echo _AT('none_found'); ?></td>
264 if(is_array($theme_list_array))
266 for ($i=0; $i < $num_of_themes; $i++)
268 // check if the theme has been installed
269 if (is_dir($local_theme_folder . $theme_list_array[$i]["history"][0]["install_folder"]))
275 <tr onmousedown="document.form['m<?php echo $i; ?>'].checked = true; rowselect(this);" id="r_<?php echo $i; ?>">
276 <td><input type="radio" name="id" value="<?php echo $i; ?>" id="m<?php echo $i; ?>" <?php if ($installed) echo 'disabled="disabled"'; ?> /></td>
277 <td><label for="m<?php echo $i; ?>"><?php echo $theme_list_array[$i]["name"]; ?></label></td>
278 <td><?php if ($installed) echo _AT("installed"); else echo _AT("not_installed"); ?></td>
279 <td><?php echo $theme_list_array[$i]["history"][0]["atutor_version"]; ?></td>
280 <td><?php echo $theme_list_array[$i]["description"]; ?></td>
281 <td><?php if (file_get_contents($theme_folder.$theme_list_array[$i]["history"][0]["screenshot_file"])) { ?>
282 <img src="<?php echo $theme_folder.$theme_list_array[$i]["history"][0]["screenshot_file"]; ?>" border="1" alt="<?php echo _AT('theme_screenshot'); ?>" />
300 <script language="JavaScript">
303 String.prototype.trim = function() {
304 return this.replace(/^\s+|\s+$/g,"");
307 // This function validates if and only if a zip file is given
308 function validate_filename() {
312 if (document.frm_upload.themefile.value != '')
313 file = document.frm_upload.themefile.value;
314 else if (document.frm_upload.url.value != 'http://')
315 file = document.frm_upload.url.value;
317 if (!file || file.trim()=='') {
318 alert('Please give a zip file!');
322 if(file.slice(file.lastIndexOf(".")).toLowerCase() != '.zip') {
323 alert('Please upload ZIP file only!');
332 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>