made a copy
[atutor.git] / admin / themes / theme_install_step_2.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto          */
7 /* http://atutor.ca                                                     */
8 /*                                                                      */
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 /************************************************************************/
13 // $Id: 
14
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_ADMIN);
18
19 require(AT_INCLUDE_PATH.'lib/filemanager.inc.php');
20 require(AT_INCLUDE_PATH . 'classes/Themes/ThemeParser.class.php');
21
22 // theme content folder
23 $theme_content_folder = AT_CONTENT_DIR . "theme/";
24
25 if (isset($_GET["theme"])) $theme = str_replace(array('.','..'), '', $_GET['theme']);
26 else if (isset($_POST["theme"])) $theme = $_POST["theme"];
27
28 if (isset($_GET["title"])) $title = $_GET['title'];
29 else if (isset($_POST["title"])) $title = $_POST["title"];
30
31 if (isset($_GET["permission_granted"])) $permission_granted = $_GET["permission_granted"];
32 else if (isset($_POST["permission_granted"])) $permission_granted = $_POST["permission_granted"];
33
34 // copy theme from content folder into themes folder
35 if (isset($_GET["theme"]))
36 {
37         copys($theme_content_folder.$theme, '../../themes/'.$theme);
38
39         $theme_xml = @file_get_contents('../../themes/'.$theme . '/theme_info.xml');
40
41         //Check if XML file exists (if it doesnt send error and clear directory)
42         if ($theme_xml == false) 
43         {
44                 $version = '1.4.x';
45                 $extra_info = 'unspecified';
46         } 
47         else 
48         {
49                 //parse information
50                 $xml_parser =& new ThemeParser();
51                 $xml_parser->parse($theme_xml);
52
53                 $version      = $xml_parser->theme_rows['version'];
54                 $extra_info   = $xml_parser->theme_rows['extra_info'];
55         }
56
57         if ($title == '') $title = str_replace('_', ' ', $theme);
58         $last_updated = date('Y-m-d');
59         $status       = '1';
60
61         //if version number is not compatible with current Atutor version, set theme as disabled
62         if ($version != VERSION) $status = '0';
63         
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);
68         
69         write_to_log(AT_ADMIN_LOG_INSERT, 'themes', mysql_affected_rows($db), $sql);
70 }
71
72 if (!$result) // error occurs
73 {
74         clr_dir("../../themes/".$theme);
75         
76         if ($_GET['permission_granted']==1)
77         {
78                 header('Location: '.AT_BASE_HREF.'admin/themes/theme_install_step_3.php?error=1');
79         }
80         else
81         {
82                 $msg->addError('IMPORT_FAILED');
83                 header('Location: '.AT_BASE_HREF.'admin/themes/install_themes.php');
84         }
85 }
86 else // successful
87 {
88         if ($_GET['permission_granted']==1)
89         {
90                 header('Location: '.AT_BASE_HREF.'admin/themes/theme_install_step_3.php?installed=1');
91         }
92         else
93         {
94                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
95                 header('Location: '.AT_BASE_HREF.'admin/themes/index.php');
96         }
97 }
98 ?>