2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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.'../mods/_core/themes/classes/ThemeListParser.class.php');
19 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/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.'mods/_core/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 debug($local_theme_folder. $this_theme_folder);
165 if (is_dir($local_theme_folder. $this_theme_folder))
166 $msg->addError('ALREADY_INSTALLED');
169 if (!$msg->containsErrors())
171 header('Location: theme_install_step_1.php?theme='.urlencode($this_theme_folder).SEP.'title='.urlencode($theme_list_array[$_POST["id"]]["name"]));
176 if ($_POST['download'])
178 $id = intval($_POST['id']);
180 header('Content-Type: application/x-zip');
181 header('Content-transfer-encoding: binary');
182 header('Content-Disposition: attachment; filename="'.htmlspecialchars($theme_list_array[$id]['history'][0]['filename']).'"');
183 header('Expires: 0');
184 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
185 header('Pragma: public');
186 header('Content-Length: '.strlen($file_content));
194 require (AT_INCLUDE_PATH.'header.inc.php');
200 <form name="frm_upload" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
201 <div class="input-form" style="width:95%;">
203 <h3><?php echo _AT('import_theme'); ?></h3>
207 <input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
208 <label for="file"><?php echo _AT('upload_theme_package'); ?></label><br />
209 <input type="file" name="themefile" size="40" id="file" />
213 <label for="url"><?php echo _AT('specify_url_to_theme_package'); ?></label><br />
214 <input type="text" name="url" value="http://" size="40" id="url" />
217 <div class="row buttons">
218 <input type= "submit" name="import" value="<?php echo _AT('import'); ?>" onclick="javascript: return validate_filename(); " />
223 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
226 <table class="data" summary="" rules="all">
229 <th scope="col"> </th>
230 <th scope="col"><?php echo _AT('title');?></th>
231 <th scope="col"><?php echo _AT('installed').'?';?></th>
232 <th scope="col"><?php echo _AT('atutor_version_tested_with');?></th>
233 <th scope="col"><?php echo _AT('description');?></th>
234 <th scope="col"><?php echo _AT('theme_screenshot');?></th>
241 <input type="submit" name="install" value="<?php echo _AT('install'); ?>" />
242 <input type="submit" name="download" value="<?php echo _AT('download'); ?>" />
243 <input type="submit" name="version_history" value="<?php echo _AT('version_history'); ?>" />
250 $num_of_themes = count($theme_list_array);
252 if ($num_of_themes == 0)
257 <td colspan="6"><?php echo _AT('none_found'); ?></td>
265 if(is_array($theme_list_array))
267 for ($i=0; $i < $num_of_themes; $i++)
269 // check if the theme has been installed
270 if (is_dir($local_theme_folder . $theme_list_array[$i]["history"][0]["install_folder"]))
276 <tr onmousedown="document.form['m<?php echo $i; ?>'].checked = true; rowselect(this);" id="r_<?php echo $i; ?>">
277 <td><input type="radio" name="id" value="<?php echo $i; ?>" id="m<?php echo $i; ?>" <?php if ($installed) echo 'disabled="disabled"'; ?> /></td>
278 <td><label for="m<?php echo $i; ?>"><?php echo $theme_list_array[$i]["name"]; ?></label></td>
279 <td><?php if ($installed) echo _AT("installed"); else echo _AT("not_installed"); ?></td>
280 <td><?php echo $theme_list_array[$i]["history"][0]["atutor_version"]; ?></td>
281 <td><?php echo $theme_list_array[$i]["description"]; ?></td>
282 <td><?php if (file_get_contents($theme_folder.$theme_list_array[$i]["history"][0]["screenshot_file"])) { ?>
283 <img src="<?php echo $theme_folder.$theme_list_array[$i]["history"][0]["screenshot_file"]; ?>" border="1" alt="<?php echo _AT('theme_screenshot'); ?>" />
301 <script language="JavaScript">
304 String.prototype.trim = function() {
305 return this.replace(/^\s+|\s+$/g,"");
308 // This function validates if and only if a zip file is given
309 function validate_filename() {
313 if (document.frm_upload.themefile.value != '')
314 file = document.frm_upload.themefile.value;
315 else if (document.frm_upload.url.value != 'http://')
316 file = document.frm_upload.url.value;
318 if (!file || file.trim()=='') {
319 alert('Please give a zip file!');
323 if(file.slice(file.lastIndexOf(".")).toLowerCase() != '.zip') {
324 alert('Please upload ZIP file only!');
333 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>