2 /****************************************************************************/
\r
4 /****************************************************************************/
\r
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton */
\r
6 /* Adaptive Technology Resource Centre / University of Toronto */
\r
7 /* http://atutor.ca */
\r
9 /* This program is free software. You can redistribute it and/or */
\r
10 /* modify it under the terms of the GNU General Public License */
\r
11 /* as published by the Free Software Foundation. */
\r
12 /****************************************************************************/
\r
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
\r
18 * Gets the name of the folder where the theme is stored
\r
20 * @param string $theme_dir the name of the theme
\r
21 * @return string theme folder
\r
22 * @author Shozub Qureshi
\r
24 //used by preferences.tmpl.php only
\r
25 function get_folder ($theme_name) {
\r
28 $sql = "SELECT dir_name FROM ".TABLE_PREFIX."themes WHERE title = '$theme_name'";
\r
29 $result = mysql_query($sql, $db);
\r
30 $row = mysql_fetch_assoc($result);
\r
32 return $row['dir_name'];
\r
37 * Gets the attributes of the theme from the themes database table
\r
39 * @param string $theme_dir the name of the theme
\r
40 * @return array theme info
\r
41 * @author Shozub Qureshi
\r
43 function get_themes_info($theme_dir) {
\r
46 $sql = "SELECT * FROM ".TABLE_PREFIX."themes WHERE dir_name = '$theme_dir'";
\r
47 $result = mysql_query($sql, $db);
\r
49 $info = mysql_fetch_assoc($result);
\r
55 * Gets the name of the theme
\r
57 * @param string $theme_dir theme folder
\r
58 * @return string theme name
\r
59 * @author heidi hazelton
\r
61 function get_theme_name ($theme_dir) {
\r
64 $sql = "SELECT title FROM ".TABLE_PREFIX."themes WHERE dir_name = '$theme_dir'";
\r
65 $result = mysql_query($sql, $db);
\r
66 $row = mysql_fetch_assoc($result);
\r
68 return $row['title'];
\r
72 * Gets list of enabled themes
\r
74 * @return array the version of the theme
\r
75 * @author Shozub Qureshi
\r
77 function get_enabled_themes () {
\r
80 $sql = "SELECT title FROM ".TABLE_PREFIX."themes WHERE status = '1' OR status = '2' ORDER BY title";
\r
81 $result = mysql_query($sql, $db);
\r
83 //Get all theme names into array
\r
85 while ($row = mysql_fetch_array($result)) {
\r
86 $themes[$i] = $row['title'];
\r
94 * Gets number of enabled themes
\r
96 * @return int the number of enabled themes
\r
97 * @author Shozub Qureshi
\r
99 function num_enabled_themes () {
\r
102 $sql = "SELECT title FROM ".TABLE_PREFIX."themes WHERE status = '1' OR status = '2'";
\r
103 $result = mysql_query($sql, $db);
\r
105 return mysql_num_rows($result);
\r
109 * Gets list of disabled themes
\r
111 * @return array the version of the theme
\r
112 * @author Shozub Qureshi
\r
114 function get_disabled_themes () {
\r
117 $sql = "SELECT title FROM ".TABLE_PREFIX."themes WHERE status = '0'";
\r
118 $result = mysql_query($sql, $db);
\r
120 //Get all theme names into array
\r
122 while ($row = mysql_fetch_array($result)) {
\r
123 $themes[$i] = $row['title'];
\r
131 * Gets list of all currently installed themes
\r
133 * @return array the version of the theme
\r
134 * @author Shozub Qureshi
\r
136 function get_all_themes () {
\r
139 // The ordering is as follow. The default theme followed by ASC ordering of rest of themes
\r
141 // Assert, one of them must be a default
\r
142 $result = mysql_query('SELECT title FROM ' . TABLE_PREFIX . 'themes WHERE status = 2', $db);
\r
143 $row = mysql_fetch_assoc($result);
\r
144 $first_one = $row['title'];
\r
146 $themes[$i] = $first_one;
\r
149 $sql = "SELECT title FROM " . TABLE_PREFIX . "themes WHERE title != '$first_one' ORDER BY title ASC";
\r
150 $result = mysql_query($sql, $db);
\r
152 // Get all theme names into array
\r
154 while ($row = mysql_fetch_assoc($result)) {
\r
155 $themes[$i] = $row['title'];
\r
162 function enable_theme ($theme_dir) {
\r
165 if ($_SESSION['prefs']['PREF_THEME'] != $theme_dir) {
\r
166 $sql = "UPDATE ".TABLE_PREFIX."themes SET status = '1' WHERE dir_name = '$theme_dir'";
\r
167 $result = mysql_query($sql, $db);
\r
168 write_to_log(AT_ADMIN_LOG_UPDATE, 'themes', mysql_affected_rows($db), $sql);
\r
170 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
173 function disable_theme ($theme_dir) {
\r
176 $sql = "SELECT status FROM ".TABLE_PREFIX."themes WHERE dir_name = '$theme_dir'";
\r
177 $result = mysql_query ($sql, $db);
\r
178 $row = mysql_fetch_array($result);
\r
179 $status = intval($row['status']);
\r
181 //If default theme, then it cannot be disabled
\r
182 if ($status == 2) {
\r
183 $msg->addError('THEME_NOT_DISABLED');
\r
186 $sql = "UPDATE ".TABLE_PREFIX."themes SET status = '0' WHERE dir_name = '$theme_dir'";
\r
187 $result = mysql_query($sql, $db);
\r
189 $feedback = array('THEME_DISABLED', $theme_dir);
\r
190 $msg->addFeedback($feedback);
\r
192 write_to_log(AT_ADMIN_LOG_UPDATE, 'themes', mysql_affected_rows($db), $sql);
\r
196 function set_theme_as_default ($theme_dir) {
\r
199 //unset current default theme
\r
200 $sql = "UPDATE ".TABLE_PREFIX."themes SET status = '1' WHERE status = '2'";
\r
201 $result = mysql_query($sql, $db);
\r
203 write_to_log(AT_ADMIN_LOG_UPDATE, 'themes', mysql_affected_rows($db), $sql);
\r
206 $sql = "UPDATE ".TABLE_PREFIX."themes SET status = '2' WHERE dir_name = '$theme_dir'";
\r
207 $result = mysql_query($sql, $db);
\r
209 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
210 $feedback = array('THEME_DEFAULT', $theme_dir);
\r
211 $msg->addFeedback($feedback);
\r
212 $_SESSION['prefs']['PREF_THEME'] = $theme_dir;
\r
214 write_to_log(AT_ADMIN_LOG_UPDATE, 'themes', mysql_affected_rows($db), $sql);
\r
217 function delete_theme ($theme_dir) {
\r
221 $sql = "SELECT status FROM ".TABLE_PREFIX."themes WHERE dir_name='$theme_dir'";
\r
222 $result = mysql_query ($sql, $db);
\r
223 $row = mysql_fetch_assoc($result);
\r
224 $status = intval($row['status']);
\r
226 //can't delete original default or current default theme
\r
227 if (($theme_dir == 'default') || ($status == 2)) {
\r
228 $msg->addError('THEME_NOT_DELETED');
\r
231 } else { //disable, clear directory and delete theme from db
\r
233 require (AT_INCLUDE_PATH . 'lib/filemanager.inc.php'); /* for clr_dir() */
\r
234 if ($status != 0) {
\r
235 disable_theme($theme_dir);
\r
236 $msg->deleteFeedback('THEME_DISABLED');
\r
239 $dir = '../../themes/' . $theme_dir;
\r
240 //chmod($dir, 0777);
\r
243 $sql1 = "DELETE FROM ".TABLE_PREFIX."themes WHERE dir_name = '$theme_dir'";
\r
244 $result1 = mysql_query ($sql1, $db);
\r
246 write_to_log(AT_ADMIN_LOG_DELETE, 'themes', mysql_affected_rows($db), $sql);
\r
248 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
253 function export_theme($theme_dir) {
\r
254 require(AT_INCLUDE_PATH.'classes/zipfile.class.php'); /* for zipfile */
\r
255 require(AT_INCLUDE_PATH.'classes/XML/XML_HTMLSax/XML_HTMLSax.php'); /* for XML_HTMLSax */
\r
256 require('theme_template.inc.php'); /* for theme XML templates */
\r
260 //identify current theme and then searches db for relavent info
\r
261 $sql = "SELECT * FROM ".TABLE_PREFIX."themes WHERE dir_name = '$theme_dir'";
\r
262 $result = mysql_query($sql, $db);
\r
263 $row = mysql_fetch_assoc($result);
\r
265 $dir = $row['dir_name'] . '/';
\r
266 $title = $row['title'];
\r
267 $version = $row['version'];
\r
268 $last_updated = $row['last_updated'];
\r
269 $extra_info = $row['extra_info'];
\r
273 //generate 'theme_info.xml' file based on info
\r
274 $info_xml = str_replace(array('{TITLE}', '{VERSION}', '{LAST_UPDATED}', '{EXTRA_INFO}'),
\r
275 array($title, $version, $last_updated, $extra_info),
\r
276 $theme_template_xml);
\r
278 //zip together all the contents of the folder along with the XML file
\r
279 $zipfile = new zipfile();
\r
280 $zipfile->create_dir($dir);
\r
282 //update installation folder
\r
283 $dir1 = '../../themes/' . $dir;
\r
285 $zipfile->add_file($info_xml, $dir . 'theme_info.xml');
\r
287 /* zip other required files */
\r
288 $zipfile->add_dir($dir1, $dir);
\r
292 //Name the Zip file and sends to user for download
\r
293 $zipfile->send_file(str_replace(array(' ', ':'), '_', $title));
\r