made a copy
[atutor.git] / admin / index.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
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();
18
19 if (defined('AT_DEVEL_TRANSLATE') && AT_DEVEL_TRANSLATE) { 
20         $msg->addWarning('TRANSLATE_ON');       
21 }
22 // Social networking only switch
23 if (isset($_POST['social_submit'])) {
24         $_POST['just_social']          = intval($_POST['just_social']);
25
26         if ($_POST['just_social'] == 1) {
27                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('just_social', '$_POST[just_social]')";
28                 mysql_query($sql, $db);
29                 write_to_log(AT_ADMIN_LOG_REPLACE, 'config', mysql_affected_rows($db), $sql);
30                 $msg->addFeedback('ATUTOR_SOCIAL_ONLY');
31                 
32         } else if ($_POST['just_social'] == 0) {
33                 $sql = "DELETE FROM ".TABLE_PREFIX."config WHERE name='just_social'";
34                 mysql_query($sql, $db);
35                 write_to_log(AT_ADMIN_LOG_DELETE, 'config', mysql_affected_rows($db), $sql);
36                 $msg->addFeedback('ATUTOR_SOCIAL_LMS');
37                 
38         }
39         $_config['just_social'] = $_POST['just_social'];
40 }
41 require(AT_INCLUDE_PATH.'header.inc.php');
42
43 if ($_config['check_version']) {
44         $request = @file('http://atutor.ca/check_atutor_version.php?return');
45         if ($request && version_compare(VERSION, $request[0], '<')) {
46                 $msg->printFeedbacks('ATUTOR_UPDATE_AVAILABLE');
47         }
48 }
49
50 ?>
51
52 <div style="width: 40%; float: right; padding-top: 4px; padding-left: 10px;">
53         <div class="input-form" style="width: 98%;">
54                         <div class="row">
55                                 <h3><?php echo _AT('social_switch'); ?></h3>
56                                 <p><?php echo _AT('social_switch_text'); ?></p>
57                         </div>
58                         <div class="row">
59                         <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
60                         <?php echo _AT('social_switch'); ?> (<?php echo _AT('default'); ?>: <?php echo ($_config_defaults['just_social'] ? _AT('just_social') : _AT('social_and_lms')); ?>)<br />
61                         <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>
62                         </div>
63
64                         <div class="row buttons">
65                                 <input type="submit" name="social_submit" value="<?php echo _AT('save'); ?>" />
66                         </div>
67                         </form>
68
69         </div>
70         <div class="input-form" style="width: 98%;">
71                         <div class="row">
72                                 <h3><?php echo _AT('donate'); ?></h3>
73                                 <p><?php echo _AT('donate_text'); ?></p>
74                         </div>
75
76                         <div style="text-align:center;">
77                                 <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 />
78                         </div>
79         </div>
80         <?php if ($_config['allow_instructor_requests'] && admin_authenticate(AT_ADMIN_PRIV_USERS, AT_PRIV_RETURN)): ?> 
81                 <?php
82                         $sql    = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."instructor_approvals";
83                         $result = mysql_query($sql, $db);
84                         $row    = mysql_fetch_assoc($result);
85                 ?>
86         <div class="input-form" style="width: 98%;">
87                 <form method="get" action="admin/instructor_requests.php">
88                         <div class="row">
89                                 <h3><?php echo _AT('instructor_requests'); ?></h3>
90                                 <p><?php echo _AT('instructor_requests_text', $row['cnt']); ?></p>
91                         </div>
92
93                         <div class="row buttons">
94                                 <input type="submit" name="submit" value="<?php echo _AT('view'); ?>" />
95                         </div>
96                 </form>
97         </div>
98         <?php endif; ?>
99
100         <?php 
101
102
103         $update_server = "update.atutor.ca"; 
104
105         $file = fsockopen ($update_server, 80, $errno, $errstr, 15);
106         
107         if ($file) 
108         {
109                 // get patch list
110                 $patch_folder = "http://" . $update_server . '/patch/' . str_replace('.', '_', VERSION) . '/';
111
112                 $patch_list_xml = @file_get_contents($patch_folder . 'patch_list.xml');
113                 
114                 if ($patch_list_xml) 
115                 {
116                         require_once('../mods/_standard/patcher/classes/PatchListParser.class.php');
117                         $patchListParser =& new PatchListParser();
118                         $patchListParser->parse($patch_list_xml);
119                         $patch_list_array = $patchListParser->getMyParsedArrayForVersion(VERSION);
120                         
121                         foreach ($patch_list_array as $row_num => $patch)
122                                 $patch_ids .= '\'' . $patch['atutor_patch_id'] . '\', ';
123                                 
124                         $sql = "select count(distinct atutor_patch_id) cnt_installed_patches from ".TABLE_PREFIX."patches " .
125                                "where atutor_patch_id in (" . substr($patch_ids, 0, -2) .")".
126                                " and status like '%Installed'";
127                 
128                         $result = mysql_query($sql, $db) or die(mysql_error());
129                         $row = mysql_fetch_assoc($result);
130                         
131                         $cnt = count($patch_list_array) - $row['cnt_installed_patches'];
132
133                         if ($cnt > 0)
134                         {
135                 ?>
136         <div class="input-form" style="width: 98%;">
137                 <form method="get" action="mods/_standard/patcher/index_admin.php">
138                         <div class="row">
139                                 <h3><?php echo _AT('available_patches'); ?></h3>
140                                 <p><?php echo _AT('available_patches_text', $cnt); ?></p>
141                         </div>
142
143                         <div class="row buttons">
144                                 <input type="submit" name="submit" value="<?php echo _AT('view'); ?>" />
145                         </div>
146                 </form>
147         </div>
148         <?php 
149                         }
150                 }
151         } 
152
153         ?>
154
155         <div class="input-form" style="width: 98%">
156                 <?php
157                         if (!isset($_config['db_size']) || ($_config['db_size_ttl'] < time())) {
158                                 $_config['db_size'] = 0;
159                                 $sql = 'SHOW TABLE STATUS';
160                                 $result = mysql_query($sql, $db);
161                                 while($row = mysql_fetch_assoc($result)) {
162                                         $_config['db_size'] += $row['Data_length']+$row['Index_length'];
163                                 }
164
165                                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('db_size', '{$_config['db_size']}')";
166                                 mysql_query($sql, $db);
167
168                                 // get disk usage if we're on *nix
169                                 if (DIRECTORY_SEPARATOR == '/') {
170                                         $du = shell_exec('du -sk '.escapeshellcmd(AT_CONTENT_DIR));
171                                         if ($du) {
172                                                 $_config['du_size'] = (int) $du;
173                                                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('du_size', '{$_config['du_size']}')";
174                                                 mysql_query($sql, $db);
175                                         }
176                                 }
177
178                                 $ttl = time() + 24 * 60 * 60; // every 1 day.
179                                 $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('db_size_ttl', '$ttl')";
180                                 mysql_query($sql, $db);
181                         }
182
183                         $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."courses";
184                         $result = mysql_query($sql, $db);
185                         $row = mysql_fetch_assoc($result);
186                         $num_courses = $row['cnt'];
187
188                         $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."members";
189                         $result = mysql_query($sql, $db);
190                         $row = mysql_fetch_assoc($result);
191                         $num_users = $row['cnt'];
192
193                         $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."admins";
194                         $result = mysql_query($sql, $db);
195                         $row = mysql_fetch_assoc($result);
196                         $num_users += $row['cnt'];
197
198                         $sql = "SELECT VERSION()";
199                         $result = mysql_query($sql, $db);
200                         $row = mysql_fetch_array($result);
201                         $mysql_version = $row[0];
202                 ?>
203
204                 <div class="row">
205                         <h3><?php echo _AT('statistics_information'); ?></h3>
206
207                         <dl class="col-list">
208                                 <?php if ($_config['db_size']): ?>
209                                         <dt><?php echo _AT('database'); ?>:</dt>
210                                         <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>
211                                 <?php endif; ?>
212
213                                 <?php if ($_config['du_size']): ?>
214                                         <dt><?php echo _AT('disk_usage'); ?>:</dt>
215                                         <dd><?php echo number_format($_config['du_size']/AT_KBYTE_SIZE,2); ?> <acronym title="<?php echo _AT('megabytes'); ?>"><?php echo _AT('mb'); ?></acronym></dd>
216                                 <?php endif; ?>
217
218                                 <dt><?php echo _AT('courses'); ?>:</dt>
219                                 <dd><?php echo $num_courses; ?></dd>
220
221                                 <dt><?php echo _AT('users'); ?>:</dt>
222                                 <dd><?php echo $num_users; ?></dd>
223
224                                 <dt><?php echo _AT('atutor_version'); ?>:</dt>
225                                 <dd><?php echo _AT('atutor_version_text', VERSION, urlencode(VERSION)); ?></dd>
226
227                                 <dt><?php echo _AT('php_version'); ?>:</dt>
228                                 <dd><?php echo PHP_VERSION; ?></dd>
229
230                                 <dt><?php echo _AT('mysql_version'); ?>:</dt>
231                                 <dd><?php echo $mysql_version; ?></dd>
232
233                                 <dt><?php echo _AT('os'); ?>:</dt>
234                                 <dd><?php echo php_uname('s') . ' ' . php_uname('r'); ?></dd>
235                         </dl>
236                 </div>
237         </div>
238
239 </div>
240
241 <div style="width: 55%;">
242         <?php
243         $path_length = strlen($_base_path);
244
245         echo '<ol id="tools" style="margin-right: 0px;">';
246         foreach ($_top_level_pages as $page_info) {
247                 echo '<li class="top-tool"><a href="' . $page_info['url'] . '">' . $page_info['title'] . '</a>  ';
248
249                 $page_info['url'] = substr($page_info['url'], $path_length);
250
251                 if ($_pages[$page_info['url']]['children']) {
252                         echo '<ul class="child-top-tool">';
253                         foreach ($_pages[$page_info['url']]['children'] as $child) {
254                                 echo ' <li class="child-tool"><a href="'.$child.'">'._AT($_pages[$child]['title_var']).'</a></li>';
255                         }
256                         echo '</ul>';
257                 }
258                 echo '</li>';
259         }
260         echo '</ol>';
261 ?>
262 </div>
263 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>