Cache class rewritten to better convention
[mailer.git] / inc / modules / admin / what-updates.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 01/16/2004 *
4  * ================                             Last change: 05/14/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-updates.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Check for updates                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Prueft nach Updates                              *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Init array
44 $ONLINE['code'] = "???";
45
46 // Get response from our server in an array
47 $response = GET_URL("check-updates3.php");
48
49 if (empty($response[0]) && empty($response[1]) && empty($response[2]) && empty($response[3])) {
50         // Error!
51         $response = array("", "", "");
52 } else {
53         // Analyse header for response code
54         if (eregi("200 OK", $response[0])) {
55                 // Found, kill header
56                 $pos = 0;
57                 foreach($response as $k => $v) {
58                         $v = trim($v);
59                         if (empty($v)) {
60                                 // Header ends here (+1)
61                                 $pos = $k + 1; break;
62                         }
63                 }
64
65                 $response2 = array();
66                 for($i = $pos; $i < count($response); $i++) {
67                         $response2[] = trim($response[$i]);
68                 }
69                 $response = $response2; unset($response2);
70                 unset($pos);
71
72                 // Which is the latest version on server?
73                 $ONLINE = array(
74                         'version'  => str_replace("\n", "", $response[0]),
75                         'changed'  => str_replace("\n", "", $response[1]),
76                         'revision' => str_replace("\n", "", $response[2]),
77                 );
78
79                 // Array for available patches
80                 $PATCHES = array(
81                         'fname' => array(),
82                         'fsize' => array(),
83                         'ctime' => array()
84                 );
85
86                 if (($response[3] != "[EOF]") && ($ONLINE['version'] == FULL_VERSION)) {
87                         // We have found new patches (newer than FULL_VERSION)
88                         $max = str_replace("\n", "", $response[sizeof($response) - 2]); $TOTAL_SIZE = 0;
89
90                         // Maximum of available pacthes extracted (above). Now we can get all informations
91                         for ($idx = 0; $idx < $max; $idx++) {
92                                 // List only newer patches
93                                 $TEST = substr(str_replace("\n", "", $response[$idx * 5 + 2]), 0, strlen($_CONFIG['patch_level']));
94
95                                 // I have removed the addional test for the stored timemark in database or you cannot find
96                                 // new updates on my server when you haven't installed it before I upload a patch... :-(
97                                 if (bigintval($TEST) > bigintval($_CONFIG['patch_level'])) {
98                                         // Copy every data from the response array
99                                         $PATCHES['fname'][] = str_replace("\n", "", $response[$idx * 5 + 2]);
100                                         $PATCHES['fsize'][] = str_replace("\n", "", $response[$idx * 5 + 3]);
101                                         $PATCHES['ctime'][] = str_replace("\n", "", $response[$idx * 5 + 4]);
102                                         switch (GET_LANGUAGE()) {
103                                                 case "de": $PATCHES['descr'][] = str_replace("\n", "", $response[$idx * 5 + 5]); break; // Load german description
104                                                 default  : $PATCHES['descr'][] = str_replace("\n", "", $response[$idx * 5 + 6]); break; // Load english description as default
105                                         }
106
107                                         // Add patch's size to total
108                                         $TOTAL_SIZE += $PATCHES['fsize'][$idx];
109                                 }
110                         }
111
112                         array_pk_sort($PATCHES, array("ctime", "fname"));
113
114                         // All done here!
115                         $ONLINE['code'] = "200 OK";
116                 }
117         } else {
118                 // 404 / 403 error from server
119                 $ONLINE['code'] = $response[0];
120         }
121 }
122
123 // Is a newer version available?
124 if (empty($ONLINE['version'])) {
125         // Disconnected?
126         LOAD_TEMPLATE("admin_settings_saved", false, "<FONT class=\"admin_failed\">".ADMIN_CANNOT_CHECK_VERSION." (".$ONLINE['code'].")</FONT>");
127 } elseif (($ONLINE['version'] != FULL_VERSION) || ($ONLINE['revision'] != CURR_SVN_REVISION)) {
128         // New full-version available (all previous released patches are included in this version!)
129         define('__ONLINE_VERSION', $ONLINE['version']);
130         define('__ONLINE_CHANGE' , MAKE_DATETIME($ONLINE['changed'], "2"));
131         define('__ONLINE_REVISION', $ONLINE['revision']);
132
133         // Load template
134         LOAD_TEMPLATE("admin_update_download");
135 } else {
136         // You have the latest version!
137         LOAD_TEMPLATE("admin_settings_saved", false, NO_UPDATES_AVAILABLE);
138 }
139
140 //
141 ?>