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