move code up one directory
[atutor.git] / mods / _core / themes / index.php
1 <?php\r
2 /****************************************************************/\r
3 /* ATutor                                                                                                               */\r
4 /****************************************************************/\r
5 /* Copyright (c) 2002-2010                                      */\r
6 /* Inclusive Design Institute                                   */\r
7 /* http://atutor.ca                                                                                             */\r
8 /*                                                              */\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
13 // $Id$\r
14 \r
15 $_user_location = 'admin';\r
16 \r
17 define('AT_INCLUDE_PATH', '../../../include/');\r
18 \r
19 require(AT_INCLUDE_PATH.'vitals.inc.php');\r
20 require(AT_INCLUDE_PATH.'../mods/_core/themes/lib/themes.inc.php');\r
21 admin_authenticate(AT_ADMIN_PRIV_THEMES);\r
22 \r
23 $theme   = $addslashes($_GET['theme_dir']);\r
24 $version = $addslashes($_GET[$theme.'_version']);\r
25 \r
26 if (isset($_GET['export'], $_GET['theme_dir'])) {\r
27         export_theme($theme);\r
28 } else if (isset($_GET['delete'], $_GET['theme_dir'])) {\r
29         header('Location: delete.php?theme_code='.urlencode($theme));\r
30         exit;\r
31 } else if (isset($_GET['default'], $_GET['theme_dir'])) {\r
32         set_theme_as_default($theme, $_GET['type']);\r
33         $_config['pref_defaults'] = unserialize($_config['pref_defaults']);\r
34         if ($_GET['type']==MOBILE_DEVICE) {\r
35                 $_config['pref_defaults']['PREF_MOBILE_THEME'] = $theme;\r
36         } else {\r
37                 $_config['pref_defaults']['PREF_THEME'] = $theme;\r
38         }\r
39         $_config['pref_defaults'] = serialize($_config['pref_defaults']);\r
40 \r
41         $sql    = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('pref_defaults','{$_config['pref_defaults']}')";\r
42         $result = mysql_query($sql, $db);\r
43 \r
44         header('Location: '.$_SERVER['PHP_SELF']);\r
45         exit;\r
46 } else if (isset($_GET['enable'], $_GET['theme_dir'])) {\r
47         if ($version != VERSION) {\r
48                 $str = $theme . ' - version: ' . $version;\r
49                 $warnings = array('THEME_VERSION_DIFF', $str);\r
50                 $msg->addWarning($warnings);\r
51         }\r
52         enable_theme($theme);\r
53         header('Location: '.$_SERVER['PHP_SELF']);\r
54         exit;\r
55 } else if (isset($_GET['disable'], $_GET['theme_dir'])) {\r
56         disable_theme($theme);\r
57         header('Location: '.$_SERVER['PHP_SELF']);\r
58         exit;\r
59 } else if (isset($_GET['preview'], $_GET['theme_dir'])) {\r
60         $_SESSION['prefs']['PREF_THEME'] = $_GET['theme_dir'];\r
61         header('Location: '.$_SERVER['PHP_SELF']);\r
62         exit;\r
63 } else if (isset($_GET['disable']) || isset($_GET['enable']) || isset($_GET['default']) || isset($_GET['delete']) || isset($_GET['export'])) {\r
64         $msg->addError('NO_ITEM_SELECTED');\r
65 }\r
66 \r
67 require(AT_INCLUDE_PATH.'header.inc.php');\r
68 ?>\r
69 \r
70 <?php if (!is_writeable(realpath('./../../../themes'))): ?>\r
71         <div class="input-form">\r
72                 <div class="row">\r
73                         <?php echo _AT('install_themes_text', realpath('./../../../themes')); ?>                \r
74                 </div>\r
75         </div>\r
76 <?php else: ?>\r
77         <form name="importForm" method="post" action="mods/_core/themes/import.php" enctype="multipart/form-data">\r
78         <div class="input-form" style="width:95%;">\r
79                 <div class="row">\r
80                         <h3><?php echo _AT('import_theme'); ?></h3>\r
81                 </div>\r
82 \r
83                 <div class="row">\r
84                         <label for="file"><?php echo _AT('upload_theme_package'); ?></label><br />\r
85                         <input type="file" name="file" size="40" id="file" />\r
86                 </div>\r
87 \r
88                 <div class="row">\r
89                         <label for="url"><?php echo _AT('specify_url_to_theme_package'); ?></label><br />\r
90                         <input type="text" name="url" value="http://" size="40" id="url" />\r
91                 </div>\r
92                         \r
93                 <div class="row buttons">\r
94                         <input type= "submit" name="import" value="<?php echo _AT('import'); ?>" />\r
95                 </div>\r
96         </div>\r
97         </form>\r
98         <br />\r
99 <?php endif; \r
100 \r
101 $sql    = "SELECT * FROM " . TABLE_PREFIX . "themes WHERE type='".DESKTOP_DEVICE."' ORDER BY title ASC";\r
102 $result = mysql_query($sql, $db);\r
103 print_data_table($result, DESKTOP_DEVICE);\r
104 echo '<br /><br />';\r
105 $sql    = "SELECT * FROM " . TABLE_PREFIX . "themes WHERE type='".MOBILE_DEVICE."' ORDER BY title ASC";\r
106 $result = mysql_query($sql, $db);\r
107 print_data_table($result, MOBILE_DEVICE);\r
108 ?>\r
109 \r
110 <?php function print_data_table($result, $type) {\r
111         if (@mysql_num_rows($result) == 0) return;\r
112 ?>\r
113 <h3><?php if ($type == DESKTOP_DEVICE) echo _AT('themes_for_desktop'); else echo _AT('themes_for_mobile');?></h3><br />\r
114 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" name="form_<?php echo $type; ?>">\r
115 <input type="hidden" name="type" value="<?php echo $type; ?>" />\r
116 <table class="data" summary="" rules="cols">\r
117 <thead>\r
118 <tr>\r
119         <th scope="col">&nbsp;</th>\r
120         <th scope="col"><?php echo _AT('title'); ?></th>\r
121         <th scope="col"><?php echo _AT('status'); ?></th>\r
122         <th scope="col"><?php echo _AT('version'); ?></th>\r
123         <th scope="col"><?php echo _AT('directory_name'); ?></th>\r
124         <th scope="col"><?php echo _AT('description'); ?></th>\r
125         <th scope="col"><?php echo _AT('theme_screenshot'); ?></th>\r
126 </tr>\r
127 </thead>\r
128 <tfoot>\r
129 <tr>\r
130         <td colspan="7">\r
131                 <input type="submit" name="preview"  value="<?php echo _AT('preview'); ?>" />\r
132                 <input type="submit" name="enable"  value="<?php echo _AT('enable'); ?>" />\r
133                 <input type="submit" name="disable" value="<?php echo _AT('disable'); ?>" />\r
134                 <input type="submit" name="default" value="<?php echo _AT('set_default').'&nbsp;'; if ($type == DESKTOP_DEVICE) echo _AT('desktop_theme'); else echo _AT('mobile_theme'); ?>" />\r
135                 <input type="submit" name="export"  value="<?php echo _AT('export'); ?>" />\r
136                 <input type="submit" name="delete"  value="<?php echo _AT('delete'); ?>" />\r
137         </td>\r
138 </tr>\r
139 </tfoot>\r
140 <?php while($row = mysql_fetch_assoc($result)) : ?>\r
141         <tbody>\r
142         <tr onmousedown="document.form_<?php echo $type; ?>['t_<?php echo $row['dir_name']; ?>'].checked = true; rowselect(this);" id="r_<?php echo $row['dir_name']; ?>">\r
143                 <td valign="top">\r
144                         <input type="radio" id="t_<?php echo $row['dir_name']; ?>" name="theme_dir" value="<?php echo $row['dir_name']; ?>" />\r
145                         <input type="hidden" name="<?php echo $row['dir_name']; ?>_version" value="<?php echo $row['version']; ?>" />\r
146                 </td>\r
147                 <td nowrap="nowrap" valign="top"><label for="t_<?php echo $row['dir_name']; ?>"><?php echo AT_print($row['title'], 'themes.title'); ?></label></td>\r
148                 <td valign="top"><?php\r
149                         if ($row['status'] == 0) {\r
150                                 echo _AT('disabled');\r
151                         } else if ($row['status'] == 1) {\r
152                                 echo _AT('enabled');\r
153                         } else if (($type == DESKTOP_DEVICE && $row['status'] == 2) || ($type == MOBILE_DEVICE && $row['status'] == 3)) {\r
154                                 echo '<strong>'._AT('default').'</strong>'; \r
155                         }\r
156                         ?>\r
157                 </td>\r
158                 <td valign="top"><?php echo $row['version']; ?></td>\r
159                 <td valign="top"><code><?php echo $row['dir_name']; ?>/</code></td>\r
160                 <td valign="top"><?php echo $row['extra_info']; ?></td>\r
161                 <td valign="top"><?php\r
162                         if (file_exists('../../../themes/'.$row['dir_name'].'/screenshot.jpg')) { ?>\r
163                                   <img src="<?php echo AT_BASE_HREF; ?>themes/<?php echo $row['dir_name']; ?>/screenshot.jpg" border="1" alt="<?php echo _AT('theme_screenshot'); ?>" />\r
164                         <?php           \r
165                         } else if (file_exists('../../../themes/'.$row['dir_name'].'/screenshot.gif')) { ?>\r
166                                  <img src="<?php echo AT_BASE_HREF; ?>themes/<?php echo $row['dir_name']; ?>/screenshot.gif" border="1" alt="<?php echo _AT('theme_screenshot'); ?>" />\r
167                         <?php } ?>\r
168                 </td>\r
169         </tr>\r
170         </tbody>\r
171 <?php endwhile; ?>\r
172 </table>\r
173 </form>\r
174 <?php\r
175 }\r
176  \r
177 require(AT_INCLUDE_PATH.'footer.inc.php'); \r
178 ?>