2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 07/13/2004 *
4 * =================== Last change: 08/02/2004 *
6 * -------------------------------------------------------------------- *
7 * File : overview-inc.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Output standard task management *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Standart-Aufgaben-Management ausgeben *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // @TODO This function does also check for uncompleted tasks
46 function outputStandardOverview (&$result_tasks) {
47 // First check for solved and not assigned tasks and assign them to current admin
48 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=%s WHERE assigned_admin < 1 AND status != 'NEW'",
49 array(getCurrentAdminId()), __FILE__, __LINE__);
51 // We currently don't want to install an extension so let's find out if we need...
52 setExtensionMode('test');
55 // Open the extension directory
56 $extensionList = getArrayFromDirectory('inc/extensions/', 'ext-', false, false);
57 foreach ($extensionList as $file) {
58 // Only file name is required... :(
59 $file = basename($file);
61 // Is this file an extension?
62 if ((substr($file, 0, 4) == 'ext-') && (substr($file, -4) == '.php')) {
63 // Possible newly installed extension found so we extract extension's name
64 $ext_name = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!!
69 // Check if extension is installed or not
70 $extInstalled = (isExtensionInstalled($ext_name) && (isExtensionActive($ext_name)));
72 // Is the extension not yet installed?
73 if ($extInstalled === false) {
74 // Generate subject line
75 $ext_subj = sprintf("[%s:]", $ext_name);
77 // We maybe want to install an extension so let's test-drive it...
78 if (loadExtension($ext_name, getExtensionMode(), '', true)) {
79 // Create a task for newly installed extension
80 createNewExtensionTask(getCurrentAdminId(), $ext_subj, $ext_name);
83 // Test-drive extension in update mode
84 loadExtension($ext_name, 'test');
86 // Get extension version
87 $ext_ver = getExtensionVersion($ext_name);
88 //* DEBUG: */ outputHtml($ext_name."=".$ext_ver."<br />");
90 // Update extension if extension is installed and outdated
91 //* DEBUG: */ outputHtml('ext=' . $ext_name . ',ver=' . getThisExtensionVersion() . '/' . getExtensionVersion($ext_name)."<br />");
92 if (getThisExtensionVersion() > $ext_ver) {
93 // Update the extension
94 updateExtension($ext_name, $ext_ver);
97 if (isset($GLOBALS['cache_array']['always_active'][$ext_name])) {
98 // Maybe we want to keept the current extension active?
99 if (($GLOBALS['cache_array']['always_active'][$ext_name] == 'Y') && (!isExtensionActive($ext_name))) {
100 // Reactivate this extension!
101 doActivateExtension($ext_name);
108 // At last - but not least - check for own and new unassigned tasks...
109 $result_tasks = SQL_QUERY_ESC("SELECT
110 `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
112 `{?_MYSQL_PREFIX?}_task_system`
114 `assigned_admin`=%s OR (`assigned_admin`=0 AND `status`='NEW')
119 `task_created` DESC",
120 array(getCurrentAdminId()), __FILE__, __LINE__);
122 if (SQL_NUMROWS($result_tasks) > 0) {
128 SQL_FREERESULT($result);
134 // Outputs selected tasks
135 function outputSeletectedTasks ($postData, $result_tasks) {
136 if ((isset($postData['assign'])) && (count($postData['sel']) > 0)) {
139 foreach ($postData['sel'] as $id => $sel) {
140 $result_task = SQL_QUERY_ESC("SELECT
141 `id`, `userid`, `task_type`, `subject`, `text`, `task_created`, `status`, `assigned_admin`
143 `{?_MYSQL_PREFIX?}_task_system`
145 `id`=%s AND (`assigned_admin`=%s OR (`assigned_admin`=0 AND `status`='NEW'))
147 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
150 if (SQL_NUMROWS($result_task) == 1) {
152 list($tid, $userid, $type, $subj, $text, $created, $status, $adminId) = SQL_FETCHROW($result_task);
154 if ($adminId == '0') {
155 // Assgin current admin to unassgigned task
156 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=%s WHERE `id`=%s AND `assigned_admin`=0 LIMIT 1",
160 ), __FILE__, __LINE__);
164 // @TODO Rewrite this to a filter
165 if ($type == 'SUPPORT_MEMBER') {
166 $mode = substr($text, 0, strpos($text, ':'));
167 $text = substr($text, strpos($text, ':') + 1);
168 $add = "<li>{--ADMIN_TASK_SUPPORT_MODE--}: <strong>" . $mode . "</strong></li>";
171 // Is a userid assign?
173 // Then load his data!
174 if (fetchUserData($userid)) {
176 $content = getUserDataArray();
178 // Generate HTML list entry
179 $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>";
181 // Invalid userid, so log and zero it
182 logDebugMessage(__FUNCTION__, __LINE__, 'Invalid userid=' . $userid . ' -> not found!');
187 // Decode entities of the text
188 $text = decodeEntities($text);
190 // Compile and insert text from task into table template
191 $text = loadTemplate('admin_extensions_text', true, $text);
193 // Initialize variables (no title for SQL commands by default)
194 $ext_name = ''; $ext_ver = '';
195 $title = getMessage('TASK_NO_TITLE');
197 // Shall I list SQL commands assigned to an extension installation or update task?
198 if ((getConfig('verbose_sql') == 'Y')) {
199 // Extract extension name from subject
200 $ext_name = substr($subj, 1, strpos($subj, ':') - 1);
202 // Update task or extension task?
203 if (($type == 'EXTENSION') && (!isExtensionInstalled($ext_name))) {
204 // Load SQL commands for registering in dry-run
205 registerExtension($ext_name, $id, true);
207 // Is this non-productive?
208 if (isExtensionProductive() === false) {
210 $text .= loadTemplate('admin_settings_saved', true, getMaskedMessage('ADMIN_EXTENSION_IS_NON_PRODUCTIVE', $ext_name));
213 // Set current extension name
214 setCurrentExtensionName($ext_name);
217 $text .= getExtensionNotes();
220 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REGISTER');
221 } elseif ($type == 'EXTENSION_UPDATE') {
222 // Prepare extension name and version
223 $ext_name = substr($ext_name, 7);
224 $ext_name = substr($ext_name, 0, strpos($ext_name, '-'));
225 $test = '[UPDATE-' . $ext_name . '-';
226 $ext_ver = substr($subj, strlen($test));
227 $ext_ver = substr($ext_ver, 0, strpos($ext_ver, ':'));
229 // Load SQLs from file
230 updateExtension($ext_name, $ext_ver, true);
232 // Set current extension name
233 setCurrentExtensionName($ext_name);
236 $text .= getExtensionNotes();
239 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_UPDATE');
241 // Remove extension's name
245 // Add SQLs to a table
246 if ((!empty($ext_name)) && (isExtensionInstalled('sql_patches')) && (getConfig('verbose_sql') == 'Y')) {
247 // Add verbose SQL table
248 $text .= addExtensionVerboseSqlTable($title, ' class="admin_table top left right"', true, '100%') . "<br />\n";
250 } elseif ((!empty($ext_name)) && (!empty($ext_ver))) {
251 // Run SQL commands in dry mode but only return the notes
252 updateExtension($ext_name, $ext_ver, true);
254 // Set current extension name
255 setCurrentExtensionName($ext_name);
258 $text .= getExtensionNotes();
260 // This should not normally happen!
261 debug_report_bug('ext_name(' . $ext_name . ') or ext_ver(' . $ext_ver . ') is empty! sql_patches=' . getExtensionVersion('sql_patches') . '/verbose_sql=' . getConfig('verbose_sql'));
264 // Prepare array for the template
270 'created' => generateDateTime($created, 1),
271 'extension' => $ext_name
275 $OUT .= loadTemplate('admin_overview_row', true, $content);
277 // Which task do we actually have here?
278 // @TODO Rewrite this to something with include files and/or filter
280 case 'EXTENSION': // Install new extensions
281 $ext_name = substr($subj, 1, strpos($subj, ':') - 1);
282 $result_lines = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
283 array($ext_name), __FILE__, __LINE__);
284 $lines = SQL_NUMROWS($result_lines);
285 SQL_FREERESULT($result_lines);
287 // New extension found
288 $OUT .= loadTemplate('admin_ext_reg_form', true, array(
289 'id' => bigintval($id),
290 'ext_name' => $ext_name
293 // Task is closed so nothing is todo
294 $OUT .= '<div class="admin_failed">{--ADMIN_EXT_ALREADY_REGISTERED--}</div>';
296 // Close task but not already closed, solved, deleted or update tasks
297 if ((!in_array($status, array('CLOSED','DELETED','SOLVED'))) && ($type != 'EXTENSION_UPDATE')) {
299 runFilterChain('solve_task', $tid);
304 case 'EXTENSION_UPDATE': // Extension update
305 // Extension updates are installed automatically
306 $OUT .= '<div class="admin_failed medium">{--ADMIN_EXTENSION_UPDATED--}</div>';
309 if (($status != 'CLOSED') && ($status != 'DELETED')) {
311 runFilterChain('solve_task', $tid);
315 case 'SUPPORT_MEMBER': // Assign on member's support request
316 // @TODO This may also be rewritten to include files
318 default: // @TODO Unknown support mode
319 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown support mode %s detected. This part is under construction!", $mode));
320 $OUT .= '<div class="admin_failed medium">' . getMaskedMessage('ADMIN_UNKNOWN_SUPPORT_MODE', $mode) . '</div>';
325 case 'PAYOUT_REQUEST': // Payout requests
326 if (isExtensionActive('payout')) {
327 // Extension is installed so let him send a notification to the user
328 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `userid`=%s AND `payout_timestamp`=%s LIMIT 1",
329 array(bigintval($userid), bigintval($created)), __FILE__, __LINE__);
330 list($pid) = SQL_FETCHROW($result_pay);
331 SQL_FREERESULT($result_pay);
333 if ((!empty($pid)) && ($pid > 0)) {
334 // Payout id can be obtained
341 $OUT .= loadTemplate('admin_payout_overview_form', true, $content);
343 // Problem obtaining payout id
344 $OUT .= '<div class="admin_failed medium">{--PAYOUT_OBTAIN_ID_FAILED--}</div>';
347 // Extension is not installed
348 $OUT .= '<div class="admin_failed medium">{--ADMIN_PAYOUT_NOT_INSTALLED--}</div>';
352 case 'WERNIS_REQUEST': // Wernis requests
353 if (isExtensionActive('wernis')) {
354 // Extension is installed so let him send a notification to the user
355 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_wernis` WHERE `userid`=%s AND wernis_timestamp=%s LIMIT 1",
356 array(bigintval($userid), bigintval($created)), __FILE__, __LINE__);
357 list($pid) = SQL_FETCHROW($result_pay);
358 SQL_FREERESULT($result_pay);
360 if ((!empty($pid)) && ($pid > 0)) {
361 // Payout id can be obtained
366 $OUT .= loadTemplate('admin_wernis_overview_form', true, $content);
368 // Problem obtaining wernis id
369 $OUT .= '<div class="admin_failed medium">{--WERNIS_OBTAIN_ID_FAILED--}</div>';
372 // Extension is not installed
373 $OUT .= '<div class="admin_failed medium">{--ADMIN_WERNIS_NOT_INSTALLED--}</div>';
377 case 'HOLIDAY_REQUEST': // Holiday requests
378 $OUT .= loadTemplate('admin_task_holiday', true, $userid);
381 case 'MEMBER_ORDER': // Member mail orders
382 $OUT .= loadTemplate('admin_task_order', true, $id);
385 default: // Unknown task type
386 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", $type));
387 $OUT .= '<div class="admin_failed medium">' . sprintf(getMessage('ADMIN_UNKNOWN_TASK_TYPE'), $type, $id) . '</div>';
396 SQL_FREERESULT($result_task);
402 // Load final template
403 loadTemplate('admin_overview_list', false, $OUT);
405 if ((isset($postData['sel'])) && ((count($postData['sel']) > 0) || ($postData['sel'][0] == 1))) {
406 // Only unassign / delete tasks when there are selected tasks posted
407 if (!empty($postData['unassign'])) {
408 // Unassign from tasks
409 foreach ($postData['sel'] as $id => $sel) {
410 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=0 WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
411 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
413 } elseif (isset($postData['del'])) {
415 foreach ($postData['sel'] as $id => $sel) {
416 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `assigned_admin` IN (%s,0) LIMIT 1",
417 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
421 debug_report_bug(sprintf("Unknown task action performed. data=<pre>%s</pre>", print_r($postData, true)));
425 $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",
426 array(getCurrentAdminId()), __FILE__, __LINE__);
429 // There are uncompleted jobs!
431 while ($content = SQL_FETCHARRAY($result_tasks)) {
433 $content['infos'] = '---';
435 // Generate assign link
436 $content['assigned_admin'] = generateAdminLink($content['assigned_admin']);
439 // @TODO Try to move this in includes
440 switch ($content['task_type']) {
442 case 'EXTENSION_UPDATE':
443 $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
448 $content['task_type_msg'] = getMessage('ADMIN_TASK_IS_'.strtoupper($content['task_type']).'');
450 if ($content['userid'] > 0) {
451 // Member found otherwise it's a system task
452 $content['userid'] = generateUserProfileLink($content['userid']);
454 $content['userid'] = '<em>{--ADMIN_IS_SYSTEM_TASK--}</em>';
458 $content = merge_array($content, array(
460 'assigned_admin' => $content['assigned_admin'],
461 'userid' => $content['userid'],
462 'task_type_msg' => $content['task_type_msg'],
463 'created' => generateDateTime($content['task_created'], 2)
466 // Do we have extension task?
467 if (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos']))) {
468 // Load extension row template
469 $OUT .= loadTemplate('admin_overview_list_ext_rows', true, $content);
471 // Load default row template
472 $OUT .= loadTemplate('admin_overview_list_rows', true, $content);
480 SQL_FREERESULT($result_tasks);
482 // Load footer template
483 loadTemplate('admin_overview_table', false, $OUT);