root/trunk/gui/admin/index.php

Revision 1359, 5.5 kB (checked in by scitech, 2 months ago)

Fixed #1544: Add SQL user has only one option -> useless. Fixed #1545: HTML bug with hint for updates. Fixed #1546: Tiny english typo

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 require '../include/ispcp-lib.php';
22
23 check_login(__FILE__);
24
25 $theme_color = Config::get('USER_INITIAL_THEME');
26
27 $tpl = new pTemplate();
28 $tpl->define_dynamic('page', Config::get('ADMIN_TEMPLATE_PATH') . '/index.tpl');
29 $tpl->define_dynamic('def_language', 'page');
30 $tpl->define_dynamic('def_layout', 'page');
31 $tpl->define_dynamic('no_messages', 'page');
32 $tpl->define_dynamic('msg_entry', 'page');
33 $tpl->define_dynamic('update_message', 'page');
34 $tpl->define_dynamic('database_update_message', 'page');
35 $tpl->define_dynamic('critical_update_message', 'page');
36 $tpl->define_dynamic('traff_warn', 'page');
37
38 function gen_system_message(&$tpl, &$sql) {
39     $user_id = $_SESSION['user_id'];
40
41     $query = "
42         SELECT
43             count(`ticket_id`) as cnum
44         FROM
45             `tickets`
46         WHERE
47             `ticket_to` = ?
48         AND
49             (`ticket_status` = '2' or `ticket_status` = '5')
50         AND
51             `ticket_reply` = 0
52     ";
53
54     $rs = exec_query($sql, $query, array($user_id));
55
56     $num_question = $rs->fields('cnum');
57
58     if ($num_question == 0) {
59         $tpl->assign(array('MSG_ENTRY' => ''));
60     } else {
61         $tpl->assign(
62                 array(
63                     'TR_NEW_MSGS' => tr('You have <b>%d</b> new support questions', $num_question),
64                     'TR_VIEW' => tr('View')
65                     )
66             );
67
68         $tpl->parse('MSG_ENTRY', 'msg_entry');
69     }
70 }
71
72 function get_update_infos(&$tpl) {
73
74     $sql = Database::getInstance();
75
76     if (criticalUpdate::getInstance()->checkUpdateExists()) {
77         criticalUpdate::getInstance()->executeUpdates();
78         if(criticalUpdate::getInstance()->getErrorMessage()!="")
79             system_message(criticalUpdate::getInstance()->getErrorMessage());
80         $tpl->assign(array('CRITICAL_MESSAGE' => 'Critical update has been performed'));
81         $tpl->parse('CRITICAL_UPDATE_MESSAGE', 'critical_update_message');
82     }
83     else {
84         $tpl->assign(array('CRITICAL_UPDATE_MESSAGE' => ''));
85     }
86
87     if(databaseUpdate::getInstance()->checkUpdateExists()) {
88         $tpl->assign(array('DATABASE_UPDATE' => '<a href="database_update.php" class="link">' . tr('A database update is available') . '</a>'));
89         $tpl->parse('DATABASE_UPDATE_MESSAGE', 'database_update_message');
90     } else {
91         $tpl->assign(array('DATABASE_UPDATE_MESSAGE' => ''));
92     }
93     
94     if (!Config::get('CHECK_FOR_UPDATES')) {
95         $tpl->assign(array('UPDATE' => tr('Update checking is disabled!')));
96         $tpl->parse('UPDATE_MESSAGE', 'update_message');
97         return false;
98     }
99
100     if (versionUpdate::getInstance()->checkUpdateExists()) {
101         $tpl->assign(array('UPDATE' => '<a href="ispcp_updates.php" class="link">' . tr('New ispCP update is now available') . '</a>'));
102         $tpl->parse('UPDATE_MESSAGE', 'update_message');
103     } else {
104         if( versionUpdate::getInstance()->getErrorMessage() != "" ) {
105             $tpl->assign(array('UPDATE' => versionUpdate::getInstance()->getErrorMessage()));
106             $tpl->parse('UPDATE_MESSAGE', 'update_message');
107         } else {
108             $tpl->assign(array('UPDATE_MESSAGE' => ''));
109         }
110     }
111 }
112
113 function gen_server_trafic(&$tpl, &$sql) {
114     $query = "SELECT `straff_max`, `straff_warn` FROM `straff_settings`";
115
116     $rs = exec_query($sql, $query, array());
117
118     $straff_max = (($rs->fields['straff_max']) * 1024) * 1024;
119
120     $fdofmnth = mktime(0, 0, 0, date("m"), 1, date("Y"));
121
122     $ldofmnth = mktime(1, 0, 0, date("m") + 1, 0, date("Y"));
123
124     $query = "
125         SELECT
126             IFNULL((sum(`bytes_in`) + sum(`bytes_out`)), 0) AS traffic
127         FROM
128             `server_traffic`
129         WHERE
130             `traff_time` > ?
131         AND
132             `traff_time` < ?
133     ";
134
135     $rs1 = exec_query($sql, $query, array($fdofmnth, $ldofmnth));
136
137     $traff = $rs1->fields['traffic'];
138
139     $mtraff = sprintf("%.2f", $traff);
140
141     if ($straff_max == 0) {
142         $pr = 0;
143     } else {
144         $pr = ($traff / $straff_max) * 100;
145     }
146
147     if (($straff_max != 0 || $straff_max != '') && ($mtraff > $straff_max)) {
148         $tpl->assign('TR_TRAFFIC_WARNING', tr('You are exceeding your traffic limit!')
149             );
150     } else {
151         $tpl->assign('TRAFF_WARN', '');
152     }
153
154     $bar_value = calc_bar_value($traff, $straff_max , 400);
155
156     $traff_msg = '';
157     if ($straff_max == 0) {
158         $traff_msg = tr('%1$d%% [%2$s of unlimited]', $pr, sizeit($mtraff));
159     } else {
160         $traff_msg = tr('%1$d%% [%2$s of %3$s]', $pr, sizeit($mtraff), sizeit($straff_max));
161     }
162
163     $tpl->assign(
164         array(
165             'TRAFFIC_WARNING' => $traff_msg,
166             'BAR_VALUE' => $bar_value,
167         )
168     );
169 }
170
171 /*
172  *
173  * static page messages.
174  *
175  */
176
177 $tpl->assign(
178         array(
179             'TR_ADMIN_MAIN_INDEX_PAGE_TITLE' => tr('ispCP - Admin/Main Index'),
180             'THEME_COLOR_PATH' => "../themes/$theme_color",
181             'ISP_LOGO' => get_logo($_SESSION['user_id']),
182             'THEME_CHARSET' => tr('encoding')
183             )
184     );
185
186 gen_admin_mainmenu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/main_menu_general_information.tpl');
187 gen_admin_menu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/menu_general_information.tpl');
188
189 get_admin_general_info($tpl, $sql);
190
191 get_update_infos($tpl);
192
193 gen_system_message($tpl, $sql);
194
195 gen_server_trafic($tpl, $sql);
196
197 gen_page_message($tpl);
198
199 $tpl->parse('PAGE', 'page');
200 $tpl->prnt();
201
202 if (Config::get('DUMP_GUI_DEBUG'))
203     dump_gui_debug();
204
205 unset_messages();
206
207 ?>
Note: See TracBrowser for help on using the browser.