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