]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-extensions.php
b3cc40546d28d3bd1f15a9472b7b37eda6fdeeb1
[mailer.git] / inc / modules / admin / what-extensions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 03/22/2004 *
4  * ===================                          Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-extentions.php                              *
8  * -------------------------------------------------------------------- *
9  * Short description : Extension management                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Erweiterungen-Management                         *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 // Normally we want the overview of all registered extensions
49 $do = 'overview';
50
51 if (isGetRequestParameterSet('reg_ext')) {
52         // We are about to register a new extension
53         $do = 'register';
54         $taskId = determineExtensionTaskId(getRequestParameter('reg_ext'));
55
56         // The id comes from task management and it is - of course - *not* the extension's name!
57 } elseif ((isFormSent('change')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
58         // De-/activate extensions
59         foreach (postRequestParameter('sel') as $taskId => $active) {
60                 // Shall we keep the extension always active?
61                 if ((isset($GLOBALS['cache_array']['always_active'][getExtensionName($taskId)])) && ($GLOBALS['cache_array']['always_active'][getExtensionName($taskId)] == 'Y') && ($active == 'Y')) {
62                         // Keep this extension active!
63                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_ALWAYS_ACTIVE', getExtensionName($taskId)));
64                 } else {
65                         // De/activate extension
66                         $active = 'N'; setExtensionMode('deactivate');
67                         if ($active != 'Y') {
68                                 $active = 'Y';
69                                 setExtensionMode('activate');
70                         } // END - if
71
72                         // Update database
73                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s AND `ext_active`='%s' LIMIT 1",
74                                 array($active, bigintval($taskId), $active), __FILE__, __LINE__);
75
76                         // Run embeded SQL commands
77                         doExtensionSqls($taskId, getExtensionMode());
78                 }
79         } // END - foreach
80
81         // Redirect to prevent missing cache in js.php
82         redirectToUrl('modules.php?module=admin&amp;what=extensions&amp;changed=' . countPostSelection());
83 } elseif (((isFormSent('edit')) || (isPostRequestParameterSet('modify'))) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
84         // Change settings like CSS file load
85         if (isPostRequestParameterSet('modify')) {
86                 // Change entries
87                 $cache_update = '0';
88                 foreach (postRequestParameter('sel') as $taskId => $sel) {
89                         // Secure id
90                         $taskId = bigintval($taskId);
91
92                         // Change this extension?
93                         if ($sel == 1) {
94                                 // Load mode is modify
95                                 setExtensionMode('modify');
96
97                                 // Get entry for 'active'
98                                 $active = postRequestParameter('active', $taskId);
99
100                                 // Update extension's record
101                                 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
102                                         // Update also CSS column when extensions sql_patches is newer or exact v0.0.6
103                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_has_css`='%s', `ext_active`='%s' WHERE `id`=%s LIMIT 1",
104                                                 array(postRequestParameter('css', $taskId), $active, $taskId), __FILE__, __LINE__);
105                                 } else {
106                                         // When extension is older than v0.0.6 there is no column for the CSS information
107                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='%s' WHERE `id`=%s LIMIT 1",
108                                                 array($active, $taskId), __FILE__, __LINE__);
109                                 }
110
111                                 // Run SQLs on activation / deactivation
112                                 switch ($active) {
113                                         case 'Y': setExtensionMode('activate');   break;
114                                         case 'N': setExtensionMode('deactivate'); break;
115                                 } // END - if
116
117                                 // Run embeded SQL commands
118                                 doExtensionSqls($taskId, getExtensionMode());
119                         }
120                 }
121
122                 // Redirect to prevent missing cache in js.php
123                 redirectToUrl('modules.php?module=admin&amp;what=extensions&amp;edited=' . countPostSelection());
124         } else {
125                 // Edit selected entries
126                 $OUT = '';
127                 foreach (postRequestParameter('sel') as $taskId => $sel) {
128                         // Edit this extension?
129                         if (($sel == 'Y') || ($sel != 'Y')) {
130                                 // Default is no CSS for non-updated mailers
131                                 $css = 'N';
132
133                                 // Load required data
134                                 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
135                                         $result = SQL_QUERY_ESC("SELECT ext_has_css, ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
136                                                 array(bigintval($taskId)), __FILE__, __LINE__);
137                                         list($css, $active) = SQL_FETCHROW($result);
138                                         SQL_FREERESULT($result);
139                                 } else {
140                                         $result = SQL_QUERY_ESC("SELECT ext_active FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
141                                                 array(bigintval($taskId)), __FILE__, __LINE__);
142                                         list($active) = SQL_FETCHROW($result);
143                                         SQL_FREERESULT($result);
144                                         $css = 'X';
145                                 }
146
147                                 // Prepare CSS column
148                                 $cssSelection = '---';
149                                 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
150                                         $cssSelection = addSelectionBox('yn', $css, 'css', $taskId);
151                                 } // END - if
152
153                                 // Prepare data for the row template
154                                 $content = array(
155                                         'id'     => $taskId,
156                                         'name'   => getExtensionName($taskId),
157                                         'active' => addSelectionBox('yn', $active, 'active', $taskId),
158                                         'css'    => $cssSelection,
159                                 );
160
161                                 // Load row template and switch color
162                                 $OUT .= loadTemplate('admin_extensions_edit_row', true, $content);
163                         } // END - if
164                 } // END - foreach
165
166                 // Load template
167                 loadTemplate('admin_extensions_edit', false, $OUT);
168                 $do = 'edit';
169         }
170 } elseif ((isPostRequestParameterSet('delete')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
171         // List extensions and when verbose is enabled SQL statements which will be executed
172         $OUT = '';
173         foreach (postRequestParameter('sel') as $taskId => $sel) {
174                 // Init variables
175                 $VERBOSE_OUT = '';
176                 initSqls();
177
178                 // Secure id number
179                 $taskId = bigintval($taskId);
180
181                 // Is the id valid?
182                 if (isExtensionIdValid($taskId)) {
183                         // Get extension name
184                         $ext_name = getExtensionName($taskId);
185
186                         if (isVerboseSqlEnabled()) {
187                                 // Load SQL commands in remove mode
188                                 if (loadExtension($ext_name, 'remove', '', true)) {
189                                         // Generate extra table with loaded SQL commands
190                                         $VERBOSE_OUT = addExtensionVerboseSqlTable();
191                                 } // END - if
192                         } // END - if
193
194                         // Prepare data for the row template
195                         $content = array(
196                                 'id'       => $taskId,
197                                 'ext_name' => $ext_name,
198                                 'ext_ver'  => getExtensionVersion($ext_name),
199                                 'verbose'  => $VERBOSE_OUT
200                         );
201
202                         // Load row template and switch color
203                         $OUT .= loadTemplate('admin_extensions_delete_row', true, $content);
204                 } else {
205                         // Prepare data for the row template
206                         $content = array(
207                                 'id'       => $taskId
208                         );
209
210                         // Not valid!
211                         $OUT .= loadTemplate('admin_extensions_delete_row_404', true, $content);
212                 }
213         } // END - foreach
214
215         // Load template
216         loadTemplate('admin_extensions_delete', false, $OUT);
217         $do = 'delete';
218 } elseif ((isFormSent('remove')) && (ifPostContainsSelections()) && (!isDemoModeActive())) {
219         // Remove extensions from DB (you have to delete all files manually!)
220         $cache_update = '0';
221         foreach (postRequestParameter('sel') as $taskId => $active) {
222                 // Secure id number
223                 $taskId = bigintval($taskId);
224
225                 // Is this extension selected and id valid?
226                 if (($active == 1) && (isExtensionIdValid($taskId))) {
227                         // Run embeded SQL commands
228                         doExtensionSqls($taskId, 'remove');
229                 } // END - if
230         } // END - foreach
231
232         // Redirect to prevent missing cache in js.php
233         redirectToUrl('modules.php?module=admin&amp;what=extensions&amp;removed=' . countPostSelection());
234 } elseif ((isGetRequestParameterSet('do')) && (!isDemoModeActive())) {
235         // Other things to do
236         $do = SQL_ESCAPE(secureString(getRequestParameter('do')));
237 } elseif (isGetRequestParameterSet('do')) {
238         // Demo mode active!
239         $do = 'demo';
240 } elseif (isGetRequestParameterSet('registered')) {
241         // Extensions changed
242         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTERED', getExtensionName(getRequestParameter('registered'))));
243
244         // Show next link
245         if (isExtensionActive('task')) {
246                 loadTemplate('admin_next_link', false, array(
247                         'url'   => 'modules.php?module=admin&amp;what=list_task',
248                         'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
249                 ));
250         } else {
251                 loadTemplate('admin_next_link', false, array(
252                         'url'   => 'modules.php?module=admin',
253                         'title' => '{--ADMIN_EXTENSION_REGISTER_NEXT_LINK--}'
254                 ));
255         }
256 } elseif (isGetRequestParameterSet('changed')) {
257         // Extensions changed
258         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_CHANGED', bigintval(getRequestParameter('changed'))));
259 } elseif (isGetRequestParameterSet('edited')) {
260         // Extensions changed
261         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_EDITED', bigintval(getRequestParameter('edited'))));
262 } elseif (isGetRequestParameterSet('removed')) {
263         // Extensions changed
264         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSIONS_REMOVED', bigintval(getRequestParameter('removed'))));
265 }
266
267 // Shall we display active/inactive extensions?
268 $where = '';
269 if (isGetRequestParameterSet('active')) {
270         $where = sprintf("WHERE `ext_active`='%s'", SQL_ESCAPE(secureString(getRequestParameter('active'))));
271 } // END - if
272
273 // Case selection
274 switch ($do) {
275         case 'overview': // List all registered extensions
276                 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
277                         // Load extension data with CSS informations
278                         $result = SQL_QUERY("SELECT
279         `id` AS ext_id, `ext_name`, `ext_active`, `ext_has_css` AS ext_css, `ext_version`
280 FROM
281         `{?_MYSQL_PREFIX?}_extensions`
282 ".$where."
283 ORDER BY
284         `ext_name` ASC", __FILE__, __LINE__);
285                 } else {
286                         // Load extension data without CSS informations
287                         $result = SQL_QUERY("SELECT
288         `id` AS ext_id, `ext_name`, `ext_active`, `ext_version`
289 FROM
290         `{?_MYSQL_PREFIX?}_extensions`
291 ".$where."
292 ORDER BY
293         `ext_name` ASC", __FILE__, __LINE__);
294                 }
295
296                 // Are there some entries?
297                 if (!SQL_HASZERONUMS($result)) {
298                         // Extensions are registered
299                         $OUT = '';
300                         while ($content = SQL_FETCHARRAY($result)) {
301                                 // Prepare CSS selection output
302                                 $cssSelection = '---';
303                                 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) $cssSelection = translateYesNo($content['ext_css']);
304
305                                 // Prepare data for the row template
306                                 $content['ext_css'] = $cssSelection;
307
308                                 // Load row template and switch color
309                                 $OUT .= loadTemplate('admin_extensions_row', true, $content);
310                         } // END - while
311
312                         // Free memory
313                         SQL_FREERESULT($result);
314
315                         // Load template
316                         loadTemplate('admin_extensions', false, $OUT);
317                 } else {
318                         // No extensions are registered
319                         loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_EXTENSION_REGISTERED--}');
320                 }
321                 break;
322
323         case 'register': // Register new extension
324                 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `assigned_admin`=%s AND `task_type`='EXTENSION' LIMIT 1",
325                         array(getCurrentAdminId()), __FILE__, __LINE__);
326                 $task_found = SQL_NUMROWS($result);
327
328                 // Free result
329                 SQL_FREERESULT($result);
330
331                 // Is the id number valid and the task was found?
332                 if (($taskId > 0) && ($task_found == 1)) {
333                         // id is valid so begin with registration, we first want to it's real name from task management (subject column)
334                         $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
335                                 array(bigintval($taskId)), __FILE__, __LINE__);
336                         list($subject) = SQL_FETCHROW($result);
337
338                         // Free result
339                         SQL_FREERESULT($result);
340
341                         // Disable cache update by default
342                         $cache_update = '0';
343                         if (!empty($subject)) {
344                                 // Extract extension's name from subject...
345                                 $ext_name = trim(substr($subject, 1, strpos($subject, ':') - 1));
346
347                                 // Test the extension for deprecation
348                                 loadExtension($ext_name, 'test');
349
350                                 // Is the extension deprecated?
351                                 if (!isExtensionDeprecated()) {
352                                         // ... so we can finally register and load it in registration mode
353                                         if (registerExtension($ext_name, $taskId)) {
354                                                 // Errors?
355                                                 if (!ifFatalErrorsDetected()) {
356                                                         // Extension was found and successfully registered
357                                                         redirectToUrl('modules.php?module=admin&amp;what=extensions&amp;registered=' . getExtensionId($ext_name));
358                                                 } else {
359                                                         // Errors detected!
360                                                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_NOT_REGISTERED', $ext_name));
361                                                 }
362
363                                                 // Do we need to update cache file?
364                                                 // @TODO Rewrite this to a filter
365                                                 if (isExtensionActive('cache')) {
366                                                         // Remove cache file (will be auto-created again!)
367                                                         if ($GLOBALS['cache_instance']->loadCacheFile('config'))    $GLOBALS['cache_instance']->removeCacheFile();
368                                                         if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
369                                                         if ($GLOBALS['cache_instance']->loadCacheFile('filter'))    $GLOBALS['cache_instance']->removeCacheFile();
370                                                         if ($GLOBALS['cache_instance']->loadCacheFile('modules'))   $GLOBALS['cache_instance']->removeCacheFile();
371                                                 } // END - if
372                                         } elseif (isExtensionInstalled($ext_name)) {
373                                                 // Notify the admin that we have a problem here...
374                                                 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY--}');
375                                         } else {
376                                                 // Notify the admin that we have a problem here...
377                                                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_EXTENSION_REGISTRATION_FAILED_404', $ext_name));
378                                         }
379                                 } else {
380                                         // Motify the admin that we have a problem here...
381                                         loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_DEPRECATED--}');
382                                 }
383                         } else {
384                                 // Extension was not found in task management
385                                 loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ID_404--}');
386                         }
387                 } elseif ($task_found == '0') {
388                         // No longer assigned or old task
389                         loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_ASSIGED--}');
390                 } else {
391                         // id is invalid
392                         loadTemplate('admin_settings_saved', false, '{--ADMIN_EXTENSION_REGISTRATION_FAILED_INVALID--}');
393                 }
394                 break;
395
396         case 'demo':
397                 loadTemplate('admin_settings_saved', false, '{--SETTINGS_NOT_SAVED--}');
398                 break;
399 } // END - switch
400
401 // [EOF]
402 ?>