4837: Upgraded infusion library to 1.4 as of Sep 13, 2011.
[atutor.git] / docs / admin / index.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12 // $Id$
13
14 define('AT_INCLUDE_PATH', '../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 admin_authenticate();
17
18 if (defined('AT_DEVEL_TRANSLATE') && AT_DEVEL_TRANSLATE) { 
19         $msg->addWarning('TRANSLATE_ON');       
20 }
21 $smtp_server = ini_get('SMTP');
22 if (($smtp_server == '' || $smtp_server == 'localhost') && ini_get('sendmail_path') == '') {
23         $msg->addWarning('MAIL_NOT_ON');
24 }
25
26 // Social networking only switch
27 if (isset($_POST['social_submit'])) {
28         $_POST['just_social']          = intval($_POST['just_social']);
29
30         if ($_POST['just_social'] == 1) {
31                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('just_social', '$_POST[just_social]')";
32                 mysql_query($sql, $db);
33                 write_to_log(AT_ADMIN_LOG_REPLACE, 'config', mysql_affected_rows($db), $sql);
34                 $msg->addFeedback('ATUTOR_SOCIAL_ONLY');
35                 
36         } else if ($_POST['just_social'] == 0) {
37                 $sql = "DELETE FROM ".TABLE_PREFIX."config WHERE name='just_social'";
38                 mysql_query($sql, $db);
39                 write_to_log(AT_ADMIN_LOG_DELETE, 'config', mysql_affected_rows($db), $sql);
40                 $msg->addFeedback('ATUTOR_SOCIAL_LMS');
41                 
42         }
43         $_config['just_social'] = $_POST['just_social'];
44 }
45 require(AT_INCLUDE_PATH.'header.inc.php');
46
47 if ($_config['check_version']) {
48         $request = @file('http://atutor.ca/check_atutor_version.php?return');
49         if ($request && version_compare(VERSION, $request[0], '<')) {
50                 $msg->printFeedbacks('ATUTOR_UPDATE_AVAILABLE');
51         }
52 }
53
54 ?>
55
56 <div class="container" style="width: 40%; float: right; padding-top: 4px; padding-left: 10px;">
57         <div class="input-form" style="width: 98%;">
58                         <div class="row">
59                                 <h3><?php echo _AT('social_switch'); ?></h3>
60                                 <p><?php echo _AT('social_switch_text'); ?></p>
61                         </div>
62                         <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
63                         <div class="row">
64                         <?php echo _AT('social_switch'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['just_social'] ? _AT('just_social') : _AT('social_and_lms')); ?>)<br />
65                         <input type="radio" name="just_social" value="1" id="social_y" <?php if($_config['just_social']) { echo 'checked="checked"'; }?>  /><label for="social_y"><?php echo _AT('just_social'); ?></label> <br /><input type="radio" name="just_social" value="0" id="social_n" <?php if(!$_config['just_social']) { echo 'checked="checked"'; }?>  /><label for="social_n"><?php echo _AT('social_and_lms'); ?></label>
66                         </div>
67
68                         <div class="row buttons">
69                                 <input type="submit" name="social_submit" value="<?php echo _AT('save'); ?>" />
70                         </div>
71                         </form>
72
73         </div>
74         <div class="input-form" style="width: 98%;">
75                         <div class="row">
76                                 <h3><?php echo _AT('donate'); ?></h3>
77                                 <p><?php echo _AT('donate_text'); ?></p>
78                         </div>
79
80                         <div style="text-align:center;">
81                                 <a href="http://www.atutor.ca/payment/index.php?project=ATutor-Donation"><img src="<?php echo $_base_href; ?>/images/donate.gif" height="28" width="136" border="0" alt="<?php echo _AT('donate'); ?>" /></a><br /><br />
82                         </div>
83         </div>
84         <?php if ($_config['allow_instructor_requests'] && admin_authenticate(AT_ADMIN_PRIV_USERS, AT_PRIV_RETURN)): ?> 
85                 <?php
86                         $sql    = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."instructor_approvals";
87                         $result = mysql_query($sql, $db);
88                         $row    = mysql_fetch_assoc($result);
89                 ?>
90         <div class="input-form" style="width: 98%;">
91                 <form method="get" action="mods/_core/users/instructor_requests.php">
92                         <div class="row">
93                                 <h3><?php echo _AT('instructor_requests'); ?></h3>
94                                 <p><?php echo _AT('instructor_requests_text', $row['cnt']); ?></p>
95                         </div>
96
97                         <div class="row buttons">
98                                 <input type="submit" name="submit" value="<?php echo _AT('view'); ?>" />
99                         </div>
100                 </form>
101         </div>
102         <?php endif; ?>
103
104         <?php 
105
106
107         $update_server = "update.atutor.ca"; 
108
109         $file = fsockopen ($update_server, 80, $errno, $errstr, 15);
110         
111         if ($file) 
112         {
113                 // get patch list
114                 $patch_folder = "http://" . $update_server . '/patch/' . str_replace('.', '_', VERSION) . '/';
115
116                 $patch_list_xml = @file_get_contents($patch_folder . 'patch_list.xml');
117                 
118                 if ($patch_list_xml) 
119                 {
120                         require_once('../mods/_standard/patcher/classes/PatchListParser.class.php');
121                         $patchListParser = new PatchListParser();
122                         $patchListParser->parse($patch_list_xml);
123                         $patch_list_array = $patchListParser->getMyParsedArrayForVersion(VERSION);
124                         
125                         if (count($patch_list_array)) {
126                                 foreach ($patch_list_array as $row_num => $patch) {
127                                         $patch_ids .= '\'' . $patch['atutor_patch_id'] . '\', ';
128                                 }
129                                         
130                                 $sql = "select count(distinct atutor_patch_id) cnt_installed_patches from ".TABLE_PREFIX."patches " .
131                                        "where atutor_patch_id in (" . substr($patch_ids, 0, -2) .")".
132                                        " and status like '%Installed'";
133                         
134                                 $result = mysql_query($sql, $db) or die(mysql_error());
135                                 $row = mysql_fetch_assoc($result);
136                                 
137                                 $cnt = count($patch_list_array) - $row['cnt_installed_patches'];
138         
139                                 if ($cnt > 0)
140                                 {
141                 ?>
142         <div class="input-form" style="width: 98%;">
143                 <form method="get" action="mods/_standard/patcher/index_admin.php">
144                         <div class="row">
145                                 <h3><?php echo _AT('available_patches'); ?></h3>
146                                 <p><?php echo _AT('available_patches_text', $cnt); ?></p>
147                         </div>
148
149                         <div class="row buttons">
150                                 <input type="submit" name="submit" value="<?php echo _AT('view'); ?>" />
151                         </div>
152                 </form>
153         </div>
154         <?php 
155                                 }
156                         }
157                 }
158         } 
159
160         ?>
161
162         <div class="input-form" style="width: 98%">
163                 <?php
164                         if (!isset($_config['db_size']) || ($_config['db_size_ttl'] < time())) {
165                                 $_config['db_size'] = 0;
166                                 $sql = 'SHOW TABLE STATUS';
167                                 $result = mysql_query($sql, $db);
168                                 while($row = mysql_fetch_assoc($result)) {
169                                         $_config['db_size'] += $row['Data_length']+$row['Index_length'];
170                                 }
171
172                                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('db_size', '{$_config['db_size']}')";
173                                 mysql_query($sql, $db);
174
175                                 // get disk usage if we're on *nix
176                                 if (DIRECTORY_SEPARATOR == '/') {
177                                         $du = @shell_exec('du -sk '.escapeshellcmd(AT_CONTENT_DIR));
178                                         if ($du) {
179                                                 $_config['du_size'] = (int) $du;
180                                                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('du_size', '{$_config['du_size']}')";
181                                                 mysql_query($sql, $db);
182                                         }
183                                 }
184
185                                 $ttl = time() + 24 * 60 * 60; // every 1 day.
186                                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('db_size_ttl', '$ttl')";
187                                 mysql_query($sql, $db);
188                         }
189
190                         $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."courses";
191                         $result = mysql_query($sql, $db);
192                         $row = mysql_fetch_assoc($result);
193                         $num_courses = $row['cnt'];
194
195                         $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."members";
196                         $result = mysql_query($sql, $db);
197                         $row = mysql_fetch_assoc($result);
198                         $num_users = $row['cnt'];
199
200                         $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."admins";
201                         $result = mysql_query($sql, $db);
202                         $row = mysql_fetch_assoc($result);
203                         $num_users += $row['cnt'];
204
205                         $sql = "SELECT VERSION()";
206                         $result = mysql_query($sql, $db);
207                         $row = mysql_fetch_array($result);
208                         $mysql_version = $row[0];
209                 ?>
210
211                 <div class="row">
212                         <h3><?php echo _AT('statistics_information'); ?></h3>
213
214                         <dl class="col-list">
215                                 <?php if ($_config['db_size']): ?>
216                                         <dt><?php echo _AT('database'); ?>:</dt>
217                                         <dd><?php echo number_format($_config['db_size']/AT_KBYTE_SIZE/AT_KBYTE_SIZE,2); ?> <acronym title="<?php echo _AT('megabytes'); ?>"><?php echo _AT('mb'); ?></acronym></dd>
218                                 <?php endif; ?>
219
220                                 <?php if ($_config['du_size']): ?>
221                                         <dt><?php echo _AT('disk_usage'); ?>:</dt>
222                                         <dd><?php echo number_format($_config['du_size']/AT_KBYTE_SIZE,2); ?> <acronym title="<?php echo _AT('megabytes'); ?>"><?php echo _AT('mb'); ?></acronym></dd>
223                                 <?php endif; ?>
224
225                                 <dt><?php echo _AT('courses'); ?>:</dt>
226                                 <dd><?php echo $num_courses; ?></dd>
227
228                                 <dt><?php echo _AT('users'); ?>:</dt>
229                                 <dd><?php echo $num_users; ?></dd>
230
231                                 <dt><?php echo _AT('atutor_version'); ?>:</dt>
232                 <?php
233                     require('../svn.php');
234                     if (!empty($svn_data)) {
235                         $svn_data   = explode("\n", $svn_data);
236                         if (substr($svn_data[1], 0, 1) == 'r') {
237                             $svn_data = $svn_data[1];
238                         } else if (substr($svn_data[2], 0, 1) == 'r') {
239                             $svn_data = $svn_data[2];
240                         }
241
242                         if (count($svn_data) > 1) {
243                             $build = 'unknown';
244                             $build_date = date('Y-m-d H:i:s');
245                         } else {
246                             $svn_data   = explode(' ', $svn_data);
247
248                             $build      = $svn_data[0];
249                             $build_date = $svn_data[4] .' '. $svn_data[5];
250                         }
251                         $build_str = '(' . $build . ' - '.$build_date . ')';
252                     }
253                 ?>
254                                 <dd><?php echo _AT('atutor_version_text', VERSION . $build_str, urlencode(VERSION)); ?></dd>
255
256                                 <dt><?php echo _AT('php_version'); ?>:</dt>
257                                 <dd><?php echo PHP_VERSION; ?></dd>
258
259                                 <dt><?php echo _AT('mysql_version'); ?>:</dt>
260                                 <dd><?php echo $mysql_version; ?></dd>
261
262                                 <dt><?php echo _AT('os'); ?>:</dt>
263                                 <dd><?php echo @php_uname('s') . ' ' . @php_uname('r'); ?></dd>
264                         </dl>
265                 </div>
266         </div>
267
268 </div>
269
270 <div class="admin_container" style="width: 55%;">
271         <?php
272         $path_length = strlen($_base_path);
273
274         echo '<ol id="tools" style="margin-right: 0px;">';
275         foreach ($_top_level_pages as $page_info) {
276                 echo '<li class="top-tool"><a href="' . $page_info['url'] . '">' . $page_info['title'] . '</a>  ';
277
278                 $page_info['url'] = substr($page_info['url'], $path_length);
279
280                 if ($_pages[$page_info['url']]['children']) {
281                         echo '<ul class="child-top-tool">';
282                         foreach ($_pages[$page_info['url']]['children'] as $child) {
283                                 // check whether the page is set to be available for mobile themes. @see include/lib/menu_pages.php
284                                 if (page_available($child)) {
285                                         echo ' <li class="child-tool"><a href="'.$child.'">'._AT($_pages[$child]['title_var']).'</a></li>';
286                                 }
287                         }
288                         echo '</ul>';
289                 }
290                 echo '</li>';
291         }
292         echo '</ol>';
293 ?>
294 </div>
295 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>