Issue-4845: Merged in branch 'gsoc11_benj' for the enhanced mobile theme.
[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
46 require(AT_INCLUDE_PATH.'header.inc.php');
47
48 if ($_config['check_version']) {
49         $request = @file('http://atutor.ca/check_atutor_version.php?return');
50         if ($request && version_compare(VERSION, $request[0], '<')) {
51                 $msg->printFeedbacks('ATUTOR_UPDATE_AVAILABLE');
52         }
53 }
54 if ($_config['allow_instructor_requests'] && admin_authenticate(AT_ADMIN_PRIV_USERS, AT_PRIV_RETURN)){
55         $sql    = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."instructor_approvals";
56                         $result = mysql_query($sql, $db);
57                         $row    = mysql_fetch_assoc($result);
58                         $instructor_row[] = $row;
59                         $savant->assign('row_instructor', $instructor_row);
60 }
61
62
63
64 $update_server = "update.atutor.ca"; 
65
66 $file = fsockopen ($update_server, 80, $errno, $errstr, 15);
67
68 if ($file) 
69 {
70         // get patch list
71         $patch_folder = "http://" . $update_server . '/patch/' . str_replace('.', '_', VERSION) . '/';
72
73         $patch_list_xml = @file_get_contents($patch_folder . 'patch_list.xml');
74         
75         if ($patch_list_xml) 
76         {
77                 require_once('../mods/_standard/patcher/classes/PatchListParser.class.php');
78                 $patchListParser = new PatchListParser();
79                 $patchListParser->parse($patch_list_xml);
80                 $patch_list_array = $patchListParser->getMyParsedArrayForVersion(VERSION);
81                 
82                 if (count($patch_list_array)) {
83                         foreach ($patch_list_array as $row_num => $patch) {
84                                 $patch_ids .= '\'' . $patch['atutor_patch_id'] . '\', ';
85                         }
86                                 
87                         $sql = "select count(distinct atutor_patch_id) cnt_installed_patches from ".TABLE_PREFIX."patches " .
88                                "where atutor_patch_id in (" . substr($patch_ids, 0, -2) .")".
89                                " and status like '%Installed'";
90                 
91                         $result = mysql_query($sql, $db) or die(mysql_error());
92                         $row = mysql_fetch_assoc($result);
93                         
94                         $cnt = count($patch_list_array) - $row['cnt_installed_patches'];
95                         $savant->assign('cnt', $cnt);
96
97                         if ($cnt > 0)
98                         {
99
100
101
102                         }
103                 }
104         }
105
106
107 if (!isset($_config['db_size']) || ($_config['db_size_ttl'] < time())) {
108         $_config['db_size'] = 0;
109         $sql = 'SHOW TABLE STATUS';
110         $result = mysql_query($sql, $db);
111         while($row = mysql_fetch_assoc($result)) {
112                 $_config['db_size'] += $row['Data_length']+$row['Index_length'];
113         
114         }
115
116         $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('db_size', '{$_config['db_size']}')";
117         mysql_query($sql, $db);
118
119         // get disk usage if we're on *nix
120         if (DIRECTORY_SEPARATOR == '/') {
121                 $du = @shell_exec('du -sk '.escapeshellcmd(AT_CONTENT_DIR));
122                 if ($du) {
123                         $_config['du_size'] = (int) $du;
124                         $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('du_size', '{$_config['du_size']}')";
125                         mysql_query($sql, $db);
126                         
127                 }
128         }
129
130         $ttl = time() + 24 * 60 * 60; // every 1 day.
131         $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES ('db_size_ttl', '$ttl')";
132         mysql_query($sql, $db);
133         
134 }
135
136 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."courses";
137 $result = mysql_query($sql, $db);
138 $row = mysql_fetch_assoc($result);
139 $num_courses = $row['cnt'];
140 $savant->assign('num_courses', $num_courses);
141
142 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."members";
143 $result = mysql_query($sql, $db);
144 $row = mysql_fetch_assoc($result);
145 $num_users = $row['cnt'];
146 $savant->assign('num_users', $num_users);
147
148 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."admins";
149 $result = mysql_query($sql, $db);
150 $row = mysql_fetch_assoc($result);
151 $num_users += $row['cnt'];
152
153
154 $sql = "SELECT VERSION()";
155 $result = mysql_query($sql, $db);
156 $row = mysql_fetch_array($result);
157 $mysql_version = $row[0];
158
159 $savant->assign('path_length', $path_length);
160 $savant->assign('pages', $_pages);
161 $savant->assign('db_size', $_config['db_size']);
162 $savant->assign('du_size', $_config['du_size']);
163 $savant->assign('row', $row);
164
165 $savant->display('admin/index.tmpl.php');
166
167 require(AT_INCLUDE_PATH.'footer.inc.php'); 
168
169 ?>