remove old readme
[atutor.git] / mods / _core / themes / theme_install_step_2.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
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_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
20 require(AT_INCLUDE_PATH . '../mods/_core/themes/classes/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                 $type = $xml_parser->theme_rows['type'];
55                 $extra_info = $xml_parser->theme_rows['extra_info'];
56         }
57
58         if ($title == '') $title = str_replace('_', ' ', $theme);
59         $last_updated = date('Y-m-d');
60         $status       = '1';
61
62         //if version number is not compatible with current Atutor version, set theme as disabled
63         if ($version != VERSION) $status = '0';
64         
65         //save information in database
66         $sql = "INSERT INTO ".TABLE_PREFIX."themes (title, version, dir_name, type, last_updated, extra_info, status) ".
67                                 "VALUES ('$title', '$version', '$theme', '$type', '$last_updated', '$extra_info', '$status')";
68         $result = mysql_query($sql, $db);
69         
70         write_to_log(AT_ADMIN_LOG_INSERT, 'themes', mysql_affected_rows($db), $sql);
71 }
72
73 if (!$result) // error occurs
74 {
75         clr_dir("../../themes/".$theme);
76
77         if ($_GET['permission_granted']==1)
78         {
79                 header('Location: '.AT_BASE_HREF.'mods/_core/themes/theme_install_step_3.php?error=1');
80         }
81         else
82         {
83                 $msg->addError('IMPORT_FAILED');
84                 header('Location: '.AT_BASE_HREF.'mods/_core/themes/install_themes.php');
85         }
86 }
87 else // successful
88 {
89         if ($_GET['permission_granted']==1)
90         {
91                 header('Location: '.AT_BASE_HREF.'mods/_core/themes/theme_install_step_3.php?installed=1');
92         }
93         else
94         {
95                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
96                 header('Location: '.AT_BASE_HREF.'mods/_core/themes/index.php');
97         }
98 }
99 ?>