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);
19 require(AT_INCLUDE_PATH.'lib/filemanager.inc.php');
20 require(AT_INCLUDE_PATH . 'classes/Themes/ThemeParser.class.php');
22 // theme content folder
23 $theme_content_folder = AT_CONTENT_DIR . "theme/";
25 if (isset($_GET["theme"])) $theme = str_replace(array('.','..'), '', $_GET['theme']);
26 else if (isset($_POST["theme"])) $theme = $_POST["theme"];
28 if (isset($_GET["title"])) $title = $_GET['title'];
29 else if (isset($_POST["title"])) $title = $_POST["title"];
31 if (isset($_GET["permission_granted"])) $permission_granted = $_GET["permission_granted"];
32 else if (isset($_POST["permission_granted"])) $permission_granted = $_POST["permission_granted"];
34 // copy theme from content folder into themes folder
35 if (isset($_GET["theme"]))
37 copys($theme_content_folder.$theme, '../../themes/'.$theme);
39 $theme_xml = @file_get_contents('../../themes/'.$theme . '/theme_info.xml');
41 //Check if XML file exists (if it doesnt send error and clear directory)
42 if ($theme_xml == false)
45 $extra_info = 'unspecified';
50 $xml_parser =& new ThemeParser();
51 $xml_parser->parse($theme_xml);
53 $version = $xml_parser->theme_rows['version'];
54 $extra_info = $xml_parser->theme_rows['extra_info'];
57 if ($title == '') $title = str_replace('_', ' ', $theme);
58 $last_updated = date('Y-m-d');
61 //if version number is not compatible with current Atutor version, set theme as disabled
62 if ($version != VERSION) $status = '0';
64 //save information in database
65 $sql = "INSERT INTO ".TABLE_PREFIX."themes (title, version, dir_name, last_updated, extra_info, status) ".
66 "VALUES ('$title', '$version', '$theme', '$last_updated', '$extra_info', '$status')";
67 $result = mysql_query($sql, $db);
69 write_to_log(AT_ADMIN_LOG_INSERT, 'themes', mysql_affected_rows($db), $sql);
72 if (!$result) // error occurs
74 clr_dir("../../themes/".$theme);
76 if ($_GET['permission_granted']==1)
78 header('Location: '.AT_BASE_HREF.'admin/themes/theme_install_step_3.php?error=1');
82 $msg->addError('IMPORT_FAILED');
83 header('Location: '.AT_BASE_HREF.'admin/themes/install_themes.php');
88 if ($_GET['permission_granted']==1)
90 header('Location: '.AT_BASE_HREF.'admin/themes/theme_install_step_3.php?installed=1');
94 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
95 header('Location: '.AT_BASE_HREF.'admin/themes/index.php');