2 /****************************************************************************/
\r
4 /****************************************************************************/
\r
5 /* Copyright (c) 2002-2010 */
\r
6 /* Inclusive Design Institute */
\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 ($type = "all") {
\r
80 if ($type == MOBILE_DEVICE) {
\r
81 $where_clause = " AND type='".MOBILE_DEVICE."' ";
\r
82 } else if ($type == DESKTOP_DEVICE) {
\r
83 $where_clause = " AND type='".DESKTOP_DEVICE."' ";
\r
85 $sql = "SELECT title FROM ".TABLE_PREFIX."themes WHERE (status = '1' OR status = '2' OR status = '3') ".$where_clause." ORDER BY title";
\r
86 $result = mysql_query($sql, $db);
\r
88 //Get all theme names into array
\r
90 while ($row = mysql_fetch_array($result)) {
\r
91 $themes[$i] = $row['title'];
\r
99 * Gets number of enabled themes
\r
101 * @return int the number of enabled themes
\r
102 * @author Shozub Qureshi
\r
104 function num_enabled_themes () {
\r
107 $sql = "SELECT title FROM ".TABLE_PREFIX."themes WHERE status = '1' OR status = '2'";
\r
108 $result = mysql_query($sql, $db);
\r
110 return mysql_num_rows($result);
\r
114 * Gets list of disabled themes
\r
116 * @return array the version of the theme
\r
117 * @author Shozub Qureshi
\r
119 function get_disabled_themes () {
\r
122 $sql = "SELECT title FROM ".TABLE_PREFIX."themes WHERE status = '0'";
\r
123 $result = mysql_query($sql, $db);
\r
125 //Get all theme names into array
\r
127 while ($row = mysql_fetch_array($result)) {
\r
128 $themes[$i] = $row['title'];
\r
136 * Gets list of all currently installed themes
\r
138 * @return array the version of the theme
\r
139 * @author Shozub Qureshi
\r
141 function get_all_themes () {
\r
144 // The ordering is as follow. The default theme followed by ASC ordering of rest of themes
\r
146 // Assert, one of them must be a default
\r
147 $result = mysql_query('SELECT title FROM ' . TABLE_PREFIX . 'themes WHERE status = 2', $db);
\r
148 $row = mysql_fetch_assoc($result);
\r
149 $first_one = $row['title'];
\r
151 $themes[$i] = $first_one;
\r
154 $sql = "SELECT title FROM " . TABLE_PREFIX . "themes WHERE title != '$first_one' ORDER BY title ASC";
\r
155 $result = mysql_query($sql, $db);
\r
157 // Get all theme names into array
\r
159 while ($row = mysql_fetch_assoc($result)) {
\r
160 $themes[$i] = $row['title'];
\r
167 function enable_theme ($theme_dir) {
\r
170 if ($_SESSION['prefs']['PREF_THEME'] != $theme_dir) {
\r
171 $sql = "UPDATE ".TABLE_PREFIX."themes SET status = '1' WHERE dir_name = '$theme_dir'";
\r
172 $result = mysql_query($sql, $db);
\r
173 write_to_log(AT_ADMIN_LOG_UPDATE, 'themes', mysql_affected_rows($db), $sql);
\r
175 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
178 function disable_theme ($theme_dir) {
\r
181 $sql = "SELECT status FROM ".TABLE_PREFIX."themes WHERE dir_name = '$theme_dir'";
\r
182 $result = mysql_query ($sql, $db);
\r
183 $row = mysql_fetch_array($result);
\r
184 $status = intval($row['status']);
\r
186 //If default theme, then it cannot be disabled
\r
187 if ($status == 2) {
\r
188 $msg->addError('THEME_NOT_DISABLED');
\r
191 $sql = "UPDATE ".TABLE_PREFIX."themes SET status = '0' WHERE dir_name = '$theme_dir'";
\r
192 $result = mysql_query($sql, $db);
\r
194 $feedback = array('THEME_DISABLED', $theme_dir);
\r
195 $msg->addFeedback($feedback);
\r
197 write_to_log(AT_ADMIN_LOG_UPDATE, 'themes', mysql_affected_rows($db), $sql);
\r
201 function set_theme_as_default ($theme_dir, $type) {
\r
204 //unset current default theme
\r
205 if ($type == MOBILE_DEVICE) {
\r
206 $default_status = 3;
\r
208 $default_status = 2;
\r
210 $sql = "UPDATE ".TABLE_PREFIX."themes SET status = 1 WHERE status = ".$default_status;
\r
211 $result = mysql_query($sql, $db);
\r
213 write_to_log(AT_ADMIN_LOG_UPDATE, 'themes', mysql_affected_rows($db), $sql);
\r
216 $sql = "UPDATE ".TABLE_PREFIX."themes SET status = ".$default_status." WHERE dir_name = '$theme_dir'";
\r
217 $result = mysql_query($sql, $db);
\r
219 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
220 $feedback = array('THEME_DEFAULT', $theme_dir);
\r
221 $msg->addFeedback($feedback);
\r
223 //only over-ride the current theme iff it's not mobile themes.
\r
224 if($type != MOBILE_DEVICE){
\r
225 $_SESSION['prefs']['PREF_THEME'] = $theme_dir;
\r
227 write_to_log(AT_ADMIN_LOG_UPDATE, 'themes', mysql_affected_rows($db), $sql);
\r
230 function delete_theme ($theme_dir) {
\r
234 $sql = "SELECT status FROM ".TABLE_PREFIX."themes WHERE dir_name='$theme_dir'";
\r
235 $result = mysql_query ($sql, $db);
\r
236 $row = mysql_fetch_assoc($result);
\r
237 $status = intval($row['status']);
\r
239 //can't delete original default or current default theme
\r
240 if (($theme_dir == 'default') || ($status == 2)) {
\r
241 $msg->addError('THEME_NOT_DELETED');
\r
244 } else { //disable, clear directory and delete theme from db
\r
246 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php'); /* for clr_dir() */
\r
247 if ($status != 0) {
\r
248 disable_theme($theme_dir);
\r
249 $msg->deleteFeedback('THEME_DISABLED');
\r
252 $dir = '../../../themes/' . $theme_dir;
\r
253 //chmod($dir, 0777);
\r
256 $sql1 = "DELETE FROM ".TABLE_PREFIX."themes WHERE dir_name = '$theme_dir'";
\r
257 $result1 = mysql_query ($sql1, $db);
\r
259 write_to_log(AT_ADMIN_LOG_DELETE, 'themes', mysql_affected_rows($db), $sql);
\r
261 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
266 function export_theme($theme_dir) {
\r
267 require(AT_INCLUDE_PATH.'classes/zipfile.class.php'); /* for zipfile */
\r
268 require(AT_INCLUDE_PATH.'classes/XML/XML_HTMLSax/XML_HTMLSax.php'); /* for XML_HTMLSax */
\r
269 require('theme_template.inc.php'); /* for theme XML templates */
\r
273 //identify current theme and then searches db for relavent info
\r
274 $sql = "SELECT * FROM ".TABLE_PREFIX."themes WHERE dir_name = '$theme_dir'";
\r
275 $result = mysql_query($sql, $db);
\r
276 $row = mysql_fetch_assoc($result);
\r
278 $dir = $row['dir_name'] . '/';
\r
279 $title = $row['title'];
\r
280 $version = $row['version'];
\r
281 $type = $row['type'];
\r
282 $last_updated = $row['last_updated'];
\r
283 $extra_info = $row['extra_info'];
\r
287 //generate 'theme_info.xml' file based on info
\r
288 $info_xml = str_replace(array('{TITLE}', '{VERSION}', '{TYPE}', '{LAST_UPDATED}', '{EXTRA_INFO}'),
\r
289 array($title, $version, $type, $last_updated, $extra_info),
\r
290 $theme_template_xml);
\r
292 //zip together all the contents of the folder along with the XML file
\r
293 $zipfile = new zipfile();
\r
294 $zipfile->create_dir($dir);
\r
296 //update installation folder
\r
297 $dir1 = '../../../themes/' . $dir;
\r
299 $zipfile->add_file($info_xml, $dir . 'theme_info.xml');
\r
301 /* zip other required files */
\r
302 $zipfile->add_dir($dir1, $dir);
\r
306 //Name the Zip file and sends to user for download
\r
307 $zipfile->send_file(str_replace(array(' ', ':'), '_', $title));
\r