]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/overview-inc.php
New functions introduced, several rewrites:
[mailer.git] / inc / modules / admin / overview-inc.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 07/13/2004 *
4  * ===================                          Last change: 08/02/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : overview-inc.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Output standard task management                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Standart-Aufgaben-Management ausgeben            *
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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 }
43
44 // @TODO This function does also check for uncompleted tasks
45 function outputStandardOverview (&$result_tasks) {
46         // First check for solved and not assigned tasks and assign them to current admin
47         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=%s WHERE assigned_admin < 1 AND status != 'NEW'",
48                 array(getCurrentAdminId()), __FILE__, __LINE__);
49
50         // We currently don't want to install an extension so let's find out if we need...
51         setExtensionMode('test');
52         $jobsDone = true;
53
54         // Open the extension directory
55         $extensionList = getArrayFromDirectory('inc/extensions/', 'ext-', false, false);
56         foreach ($extensionList as $file) {
57                 // Only file name is required... :(
58                 $file = basename($file);
59
60                 // Is this file an extension?
61                 if ((substr($file, 0, 4) == 'ext-') && (substr($file, -4) == '.php')) {
62                         // Possible newly installed extension found so we extract extension's name
63                         $ext_name = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!!
64
65                         // Init variables
66                         $result = false;
67
68                         // Check if extension is installed or not
69                         $extInstalled = (isExtensionInstalled($ext_name) && (isExtensionActive($ext_name)));
70
71                         // Is the extension not yet installed?
72                         if ($extInstalled === false) {
73                                 // Generate subject line
74                                 $ext_subj = sprintf("[%s:]", $ext_name);
75
76                                 // We maybe want to install an extension so let's test-drive it...
77                                 if (loadExtension($ext_name, getExtensionMode(), '', true)) {
78                                         // Create a task for newly installed extension
79                                         createNewExtensionTask(getCurrentAdminId(), $ext_subj, $ext_name);
80                                 } // END - if
81                         } else {
82                                 // Test-drive extension in update mode
83                                 loadExtension($ext_name, 'test');
84
85                                 // Get extension version
86                                 $ext_ver = getExtensionVersion($ext_name);
87                                 //* DEBUG: */ outputHtml($ext_name."=".$ext_ver."<br />");
88
89                                 // Update extension if extension is installed and outdated
90                                 //* DEBUG: */ outputHtml('ext=' . $ext_name . ',ver=' . getThisExtensionVersion() . '/' . getExtensionVersion($ext_name)."<br />");
91                                 if (getThisExtensionVersion() > $ext_ver) {
92                                         // Update the extension
93                                         updateExtension($ext_name, $ext_ver);
94                                 } // END - if
95
96                                 if (isset($GLOBALS['cache_array']['always_active'][$ext_name])) {
97                                         // Maybe we want to keept the current extension active?
98                                         if (($GLOBALS['cache_array']['always_active'][$ext_name] == 'Y') && (!isExtensionActive($ext_name))) {
99                                                 // Reactivate this extension!
100                                                 doActivateExtension($ext_name);
101                                         } // END - if
102                                 } // END - if
103                         }
104                 } // END - if
105         } // END - foreach
106
107         // At last - but not least - check for own and new unassigned tasks...
108         $result_tasks = SQL_QUERY_ESC("SELECT
109         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
110 FROM
111         `{?_MYSQL_PREFIX?}_task_system`
112 WHERE
113         `assigned_admin`=%s OR (`assigned_admin`=0 AND `status`='NEW')
114 ORDER BY
115         `userid` DESC,
116         `task_type` DESC,
117         `subject` ASC,
118         `task_created` DESC",
119                 array(getCurrentAdminId()), __FILE__, __LINE__);
120
121         if (SQL_NUMROWS($result_tasks) > 0) {
122                 // New jobs found!
123                 $jobsDone = false;
124         } // END - if
125
126         // Free the result
127         SQL_FREERESULT($result);
128
129         // Return status
130         return $jobsDone;
131 }
132
133 // Outputs selected tasks
134 function outputSeletectedTasks ($postData, $result_tasks) {
135         if ((isset($postData['assign'])) && (count($postData['sel']) > 0)) {
136                 // Assign / do tasks
137                 $OUT = ''; $SW = 2;
138                 foreach ($postData['sel'] as $id => $sel) {
139                         $result_task = SQL_QUERY_ESC("SELECT
140         `id`, `userid`, `task_type`, `subject`, `text`, `task_created`, `status`, `assigned_admin`
141 FROM
142         `{?_MYSQL_PREFIX?}_task_system`
143 WHERE
144         `id`=%s AND (`assigned_admin`=%s OR (`assigned_admin`=0 AND `status`='NEW'))
145 LIMIT 1",
146                                 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
147
148                         // Task is found?
149                         if (SQL_NUMROWS($result_task) == 1) {
150                                 // Task is valid...
151                                 list($tid, $userid, $type, $subj, $text, $created, $status, $adminId) = SQL_FETCHROW($result_task);
152
153                                 if ($adminId == '0') {
154                                         // Assgin current admin to unassgigned task
155                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=%s WHERE `id`=%s AND `assigned_admin`=0 LIMIT 1",
156                                                 array(
157                                                         getCurrentAdminId(),
158                                                         bigintval($tid)
159                                                 ), __FILE__, __LINE__);
160                                 } // END - if
161
162                                 $add = '';
163                                 // @TODO Rewrite this to a filter
164                                 if ($type == 'SUPPORT_MEMBER') {
165                                         $mode = substr($text, 0, strpos($text, ':'));
166                                         $text = substr($text, strpos($text, ':') + 1);
167                                         $add = "<li>{--ADMIN_TASK_SUPPORT_MODE--}: <strong>" . $mode . "</strong></li>";
168                                 } // END - if
169
170                                 // Is a userid assign?
171                                 if ($userid > 0) {
172                                         // Then load his data!
173                                         if (fetchUserData($userid)) {
174                                                 // Fetch row
175                                                 $content = getUserDataArray();
176
177                                                 // Generate HTML list entry
178                                                 $add = "<li>{--ADMIN_MEMBER_UID--}: <strong>".generateUserProfileLink($userid, 'user_data')." (<a href=\"".generateEmailLink($content['email'], 'user_data')."\">".translateGender($content['gender']) . ' ' . $content['surname'] . ' ' . $content['family']."</a>)</strong></li>";
179                                         } else {
180                                                 // Invalid userid, so log and zero it
181                                                 logDebugMessage(__FUNCTION__, __LINE__, 'Invalid userid=' . $userid . ' -> not found!');
182                                                 $userid = '0';
183                                         }
184                                 } // END - if
185
186                                 // Decode entities of the text
187                                 $text = decodeEntities($text);
188
189                                 // Compile and insert text from task into table template
190                                 $text = loadTemplate('admin_extensions_text', true, $text);
191
192                                 // Initialize variables (no title for SQL commands by default)
193                                 $ext_name = ''; $ext_ver = '';
194                                 $title = getMessage('TASK_NO_TITLE');
195
196                                 // Shall I list SQL commands assigned to an extension installation or update task?
197                                 if ((getConfig('verbose_sql') == 'Y')) {
198                                         // Extract extension name from subject
199                                         $ext_name = substr($subj, 1, strpos($subj, ':') - 1);
200
201                                         // Update task or extension task?
202                                         if (($type == 'EXTENSION') && (!isExtensionInstalled($ext_name))) {
203                                                 // Load SQL commands for registering in dry-run
204                                                 registerExtension($ext_name, $id, true);
205
206                                                 // Is this non-productive?
207                                                 if (isExtensionProductive() === false) {
208                                                         // Issue warning
209                                                         $text .= loadTemplate('admin_settings_saved', true, getMaskedMessage('ADMIN_EXTENSION_IS_NON_PRODUCTIVE', $ext_name));
210                                                 } // END - if
211
212                                                 // Set current extension name
213                                                 setCurrentExtensionName($ext_name);
214
215                                                 // Add notes to text
216                                                 $text .= getExtensionNotes();
217
218                                                 // Set title
219                                                 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REGISTER');
220                                         } elseif ($type == 'EXTENSION_UPDATE') {
221                                                 // Prepare extension name and version
222                                                 $ext_name = substr($ext_name, 7);
223                                                 $ext_name = substr($ext_name, 0, strpos($ext_name, '-'));
224                                                 $test = '[UPDATE-' . $ext_name . '-';
225                                                 $ext_ver = substr($subj, strlen($test));
226                                                 $ext_ver = substr($ext_ver, 0, strpos($ext_ver, ':'));
227
228                                                 // Load SQLs from file
229                                                 updateExtension($ext_name, $ext_ver, true);
230
231                                                 // Set current extension name
232                                                 setCurrentExtensionName($ext_name);
233
234                                                 // Add notes to text
235                                                 $text .= getExtensionNotes();
236
237                                                 // Set title
238                                                 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_UPDATE');
239                                         } else {
240                                                 // Remove extension's name
241                                                 $ext_name = '';
242                                         }
243
244                                         // Add SQLs to a table
245                                         if ((!empty($ext_name)) && (getExtensionVersion('sql_patches')) && (getConfig('verbose_sql') == 'Y')) {
246                                                 // Add verbose SQL table
247                                                 $text .= addExtensionVerboseSqlTable($title, " class=\"admin_table top left right\"", true, '100%') . "<br />\n";
248                                         } // END - if
249                                 } elseif ((!empty($ext_name)) && (!empty($ext_ver))) {
250                                         // Run SQL commands in dry mode but only return the notes
251                                         updateExtension($ext_name, $ext_ver, true);
252
253                                         // Set current extension name
254                                         setCurrentExtensionName($ext_name);
255
256                                         // Get notes
257                                         $text .= getExtensionNotes();
258                                 } else {
259                                         // This should not normally happen!
260                                         debug_report_bug('ext_name(' . $ext_name . ') or ext_ver(' . $ext_ver . ') is empty! sql_patches=' . getExtensionVersion('sql_patches') . '/verbose_sql=' . getConfig('verbose_sql'));
261                                 }
262
263                                 // Prepare array for the template
264                                 $content = array(
265                                         'sw'        => $SW,
266                                         'subject'   => $subj,
267                                         'add'       => $add,
268                                         'text'      => $text,
269                                         'created'   => generateDateTime($created, 1),
270                                         'extension' => $ext_name
271                                 );
272
273                                 // Load template
274                                 $OUT .= loadTemplate('admin_overview_row', true, $content);
275
276                                 // Which task do we actually have here?
277                                 // @TODO Rewrite this to something with include files and/or filter
278                                 switch ($type) {
279                                         case 'EXTENSION': // Install new extensions
280                                                 $ext_name = substr($subj, 1, strpos($subj, ':') - 1);
281                                                 $result_lines = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
282                                                         array($ext_name), __FILE__, __LINE__);
283                                                 $lines = SQL_NUMROWS($result_lines);
284                                                 SQL_FREERESULT($result_lines);
285                                                 if ($lines == '0') {
286                                                         // New extension found
287                                                         $OUT .= loadTemplate('admin_ext_reg_form', true, array(
288                                                                 'id'       => bigintval($id),
289                                                                 'ext_name' => $ext_name
290                                                         ));
291                                                 } else {
292                                                         // Task is closed so nothing is todo
293                                                         $OUT .= '<div class="admin_failed">{--ADMIN_EXT_ALREADY_REGISTERED--}</div>';
294
295                                                         // Close task but not already closed, solved, deleted or update tasks
296                                                         if ((!in_array($status, array('CLOSED','DELETED','SOLVED'))) && ($type != 'EXTENSION_UPDATE')) {
297                                                                 // Solve the task
298                                                                 runFilterChain('solve_task', $tid);
299                                                         } // END - if
300                                                 }
301                                                 break;
302
303                                         case 'EXTENSION_UPDATE': // Extension update
304                                                 // Extension updates are installed automatically
305                                                 $OUT .= '<div class="admin_failed medium">{--ADMIN_EXTENSION_UPDATED--}</div>';
306
307                                                 // Close task
308                                                 if (($status != 'CLOSED') && ($status != 'DELETED')) {
309                                                         // Solve the task
310                                                         runFilterChain('solve_task', $tid);
311                                                 } // END - if
312                                                 break;
313
314                                         case 'SUPPORT_MEMBER': // Assign on member's support request
315                                                 // @TODO This may also be rewritten to include files
316                                                 switch ($mode) {
317                                                         default: // @TODO Unknown support mode
318                                                         logDebugMessage(__FILE__, __LINE__, sprintf("Unknown support mode %s detected. This part is under construction!", $mode));
319                                                         $OUT .= '<div class="admin_failed medium">' . getMaskedMessage('ADMIN_UNKNOWN_SUPPORT_MODE', $mode) . '</div>';
320                                                         break;
321                                                 }
322                                                 break;
323
324                                         case 'PAYOUT_REQUEST': // Payout requests
325                                                 if (isExtensionActive('payout')) {
326                                                         // Extension is installed so let him send a notification to the user
327                                                         $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `userid`=%s AND `payout_timestamp`=%s LIMIT 1",
328                                                                 array(bigintval($userid), bigintval($created)), __FILE__, __LINE__);
329                                                         list($pid) = SQL_FETCHROW($result_pay);
330                                                         SQL_FREERESULT($result_pay);
331
332                                                         if ((!empty($pid)) && ($pid > 0)) {
333                                                                 // Payout id can be obtained
334                                                                 $content = array(
335                                                                         'pid' => $pid,
336                                                                         'tid' => $tid,
337                                                                 );
338
339                                                                 // Load template
340                                                                 $OUT .= loadTemplate('admin_payout_overview_form', true, $content);
341                                                         } else {
342                                                                 // Problem obtaining payout id
343                                                                 $OUT .= '<div class="admin_failed medium">{--PAYOUT_OBTAIN_ID_FAILED--}</div>';
344                                                         }
345                                                 } else {
346                                                         // Extension is not installed
347                                                         $OUT .= '<div class="admin_failed medium">{--ADMIN_PAYOUT_NOT_INSTALLED--}</div>';
348                                                 }
349                                                 break;
350
351                                         case 'WERNIS_REQUEST': // Wernis requests
352                                                 if (isExtensionActive('wernis')) {
353                                                         // Extension is installed so let him send a notification to the user
354                                                         $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_wernis` WHERE `userid`=%s AND wernis_timestamp=%s LIMIT 1",
355                                                                 array(bigintval($userid), bigintval($created)), __FILE__, __LINE__);
356                                                         list($pid) = SQL_FETCHROW($result_pay);
357                                                         SQL_FREERESULT($result_pay);
358
359                                                         if ((!empty($pid)) && ($pid > 0)) {
360                                                                 // Payout id can be obtained
361                                                                 $content = array(
362                                                                         'pid' => $pid,
363                                                                         'tid' => $tid,
364                                                                 );
365                                                                 $OUT .= loadTemplate('admin_wernis_overview_form', true, $content);
366                                                         } else {
367                                                                 // Problem obtaining wernis id
368                                                                 $OUT .= '<div class="admin_failed medium">{--WERNIS_OBTAIN_ID_FAILED--}</div>';
369                                                         }
370                                                 } else {
371                                                         // Extension is not installed
372                                                         $OUT .= '<div class="admin_failed medium">{--ADMIN_WERNIS_NOT_INSTALLED--}</div>';
373                                                 }
374                                                 break;
375
376                                         case 'HOLIDAY_REQUEST': // Holiday requests
377                                                 $OUT .= loadTemplate('admin_task_holiday', true, $userid);
378                                                 break;
379
380                                         case 'MEMBER_ORDER': // Member mail orders
381                                                 $OUT .= loadTemplate('admin_task_order', true, $id);
382                                                 break;
383
384                                         default: // Unknown task type
385                                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", $type));
386                                                 $OUT .= '<div class="admin_failed medium">' . sprintf(getMessage('ADMIN_UNKNOWN_TASK_TYPE'), $type, $id) . '</div>';
387                                                 break;
388                                 }
389                                 $OUT .= '
390   </td>
391 </tr>';
392                         } // END - if
393
394                         // Free result
395                         SQL_FREERESULT($result_task);
396
397                         // Switch colors
398                         $SW = 3 - $SW;
399                 } // END - foreach
400
401                 // Load final template
402                 loadTemplate('admin_overview_list', false, $OUT);
403         } else {
404                 if ((isset($postData['sel'])) && ((count($postData['sel']) > 0) || ($postData['sel'][0] == 1))) {
405                         // Only unassign / delete tasks when there are selected tasks posted
406                         if (!empty($postData['unassign'])) {
407                                 // Unassign from tasks
408                                 foreach ($postData['sel'] as $id => $sel) {
409                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=0 WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
410                                                 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
411                                 }
412                         } elseif (isset($postData['del'])) {
413                                 // Delete tasks
414                                 foreach ($postData['sel'] as $id => $sel) {
415                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `assigned_admin` IN (%s,0) LIMIT 1",
416                                                 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
417                                 }
418                         } else {
419                                 // Unknown action
420                                 debug_report_bug(sprintf("Unknown task action performed. data=<pre>%s</pre>", print_r($postData, true)));
421                         }
422
423                         // Update query
424                         $result_tasks = SQL_QUERY_ESC("SELECT `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `assigned_admin`=%s OR (`assigned_admin`=0 AND `status`='NEW') ORDER BY `task_created` DESC",
425                                 array(getCurrentAdminId()), __FILE__, __LINE__);
426                 } // END - if
427
428                 // There are uncompleted jobs!
429                 $OUT = ''; $SW = 2;
430                 while ($content = SQL_FETCHARRAY($result_tasks)) {
431                         // Init infos
432                         $content['infos'] = '---';
433
434                         // Generate assign link
435                         $content['assigned_admin'] = generateAdminLink($content['assigned_admin']);
436
437                         // Generate infos
438                         // @TODO Try to move this in includes
439                         switch ($content['task_type']) {
440                                 case 'EXTENSION':
441                                 case 'EXTENSION_UPDATE':
442                                         $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
443                                         break;
444                         }
445
446                         // Get task type
447                         $content['task_type_msg'] = getMessage('ADMIN_TASK_IS_'.strtoupper($content['task_type']).'');
448
449                         if ($content['userid'] > 0) {
450                                 // Member found otherwise it's a system task
451                                 $content['userid'] = generateUserProfileLink($content['userid']);
452                         } else {
453                                 $content['userid'] = '<em>{--ADMIN_IS_SYSTEM_TASK--}</em>';
454                         }
455
456                         // Prepare content
457                         $content = merge_array($content, array(
458                                 'sw'             => $SW,
459                                 'assigned_admin' => $content['assigned_admin'],
460                                 'userid'         => $content['userid'],
461                                 'task_type_msg'  => $content['task_type_msg'],
462                                 'created'        => generateDateTime($content['task_created'], 2)
463                         ));
464
465                         // Do we have extension task?
466                         if (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos']))) {
467                                 // Load extension row template
468                                 $OUT .= loadTemplate('admin_overview_list_ext_rows', true, $content);
469                         } else {
470                                 // Load default row template
471                                 $OUT .= loadTemplate('admin_overview_list_rows', true, $content);
472                         }
473
474                         // Switch color
475                         $SW = 3 - $SW;
476                 } // END - while
477
478                 // Free memory
479                 SQL_FREERESULT($result_tasks);
480
481                 // Load footer template
482                 loadTemplate('admin_overview_table', false, $OUT);
483         }
484 }
485
486 // [EOF]
487 ?>