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 : Standard-Aufgaben-Management ausgeben *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // @TODO This function does also check for uncompleted tasks
44 function outputStandardOverview (&$result_tasks) {
45 // First check for solved and not assigned tasks and assign them to current admin
46 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=%s WHERE `assigned_admin` IS NULL AND status != 'NEW'",
47 array(getCurrentAdminId()), __FILE__, __LINE__);
49 // We currently don't want to install an extension so let's find out if we need...
50 setExtensionMode('test');
53 // Open the extension directory
54 $extensionList = getArrayFromDirectory('inc/extensions/', 'ext-', false, false);
55 foreach ($extensionList as $file) {
56 // Only file name is required... :(
57 $file = basename($file);
59 // Is this file an extension?
60 if ((substr($file, 0, 4) == 'ext-') && (substr($file, -4) == '.php')) {
61 // Possible newly installed extension found so we extract extension's name
62 $ext_name = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!!
67 // Check if extension is installed or not
68 $extInstalled = (isExtensionInstalled($ext_name) && (isExtensionActive($ext_name)));
70 // Is the extension not yet installed?
71 if ($extInstalled === false) {
72 // We maybe want to install an extension so let's test-drive it...
73 if (loadExtension($ext_name, getExtensionMode(), '0.0.0', true)) {
74 // Create a task for newly installed extension (we ignore the task id here)
75 createNewExtensionTask($ext_name);
78 // Test-drive extension
79 loadExtension($ext_name, 'test');
81 // Get extension version
82 $ext_ver = getExtensionVersion($ext_name);
83 //* DEBUG: */ debugOutput($ext_name.'='.$ext_ver);
85 // Update extension if extension is installed and outdated
86 //* DEBUG: */ debugOutput('ext=' . $ext_name . ',ver=' . getThisExtensionVersion() . '/' . getExtensionVersion($ext_name));
87 if (getThisExtensionVersion() > $ext_ver) {
88 // Update the extension
89 updateExtension($ext_name, $ext_ver);
92 if (isset($GLOBALS['cache_array']['always_active'][$ext_name])) {
93 // Maybe we want to keept the current extension active?
94 if (($GLOBALS['cache_array']['always_active'][$ext_name] == 'Y') && (!isExtensionActive($ext_name))) {
95 // Reactivate this extension!
96 doActivateExtension($ext_name);
103 // At last - but not least - check for own and new unassigned tasks...
104 $result_tasks = SQL_QUERY_ESC("SELECT
105 `id`,`assigned_admin`,`userid`,`task_type`,`subject`,`text`,`task_created`
107 `{?_MYSQL_PREFIX?}_task_system`
109 `assigned_admin`=%s OR ((`assigned_admin`=0 OR `assigned_admin` IS NULL) AND `status`='NEW')
114 `task_created` DESC",
115 array(getCurrentAdminId()), __FILE__, __LINE__);
117 if (!SQL_HASZERONUMS($result_tasks)) {
123 SQL_FREERESULT($result);
129 // Outputs selected tasks
130 function outputSeletectedTasks ($postData, $result_tasks) {
131 if ((isset($postData['assign'])) && (count($postData['sel']) > 0)) {
134 foreach ($postData['sel'] as $taskId => $sel) {
135 $result_task = SQL_QUERY_ESC("SELECT
136 `id`,`userid`,`task_type`,`subject`,`text`,`task_created`,`status`,`assigned_admin`
138 `{?_MYSQL_PREFIX?}_task_system`
140 `id`=%s AND (`assigned_admin`=%s OR ((`assigned_admin`=0 OR `assigned_admin` IS NULL) AND `status`='NEW'))
145 ), __FILE__, __LINE__);
148 if (SQL_NUMROWS($result_task) == 1) {
149 // Task is valid so load it's data
150 $taskData = SQL_FETCHARRAY($result_task);
152 if ($taskData['assigned_admin'] == '0') {
153 // Assgin current admin to unassgigned task
154 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=%s WHERE `id`=%s AND `assigned_admin` IS NULL LIMIT 1",
157 bigintval($taskData['id'])
158 ), __FILE__, __LINE__);
162 // @TODO Rewrite this to a filter
163 if ($taskData['task_type'] == 'MEMBER_SUPPORT') {
164 $mode = substr($taskData['text'], 0, strpos($taskData['text'], ':'));
165 $taskData['text'] = substr($taskData['text'], strpos($taskData['text'], ':') + 1);
166 $add = '<li>{--ADMIN_TASK_SUPPORT_MODE--}: <strong>' . $mode . '</strong></li>';
169 // Is a userid assign?
170 if ($taskData['userid'] > 0) {
171 // Then load his data!
172 if (fetchUserData($taskData['userid'])) {
174 $content = getUserDataArray();
176 // Generate HTML list entry
177 $add = '<li>{--ADMIN_MEMBER_USERID--}: <strong>' . generateUserProfileLink($taskData['userid'], 'user_data') . ' (<a href="' . generateEmailLink($content['email'], 'user_data') . '">{%pipe,translateGender=' . $content['gender'] . '%} ' . $content['surname'] . ' ' . $content['family'] . '</a>)</strong></li>';
179 // Invalid userid, so log and zero it
180 logDebugMessage(__FUNCTION__, __LINE__, 'fetchUserData() failed: userid=' . $taskData['userid'] . ' not found.');
181 $taskData['userid'] = '0';
185 // Decode entities of the text
186 $taskData['text'] = decodeEntities($taskData['text']);
188 // Compile and insert text from task into table template
189 $taskData['text'] = loadTemplate('admin_extensions_text', true, $taskData['text']);
191 // Initialize variables (no title for SQL commands by default)
192 $ext_name = ''; $ext_ver = '';
193 $title = '{--ADMIN_TASK_NO_SQL_TITLE--}';
195 // Shall I list SQL commands assigned to an extension installation or update task?
196 if ((isVerboseSqlEnabled()) || (!isExtensionInstalled('sql_patches'))) {
197 // Extract extension name from subject
198 $ext_name = substr($taskData['subject'], 1, strpos($taskData['subject'], ':') - 1);
200 // Update task or extension task?
201 if (($taskData['task_type'] == 'EXTENSION') && (!isExtensionInstalled($ext_name))) {
202 // Load SQL commands for registering in dry-run
203 registerExtension($ext_name, $taskId, true);
205 // Is this non-productive?
206 if (isExtensionProductive() === false) {
208 $taskData['text'] = displayMessage('{%message,ADMIN_EXTENSION_IS_NON_PRODUCTIVE=' . $ext_name . '%}', true) . $taskData['text'];
211 // Set current extension name
212 setCurrentExtensionName($ext_name);
215 $taskData['text'] .= getExtensionNotes();
218 $title = '{--ADMIN_SQLS_EXECUTED_ON_REGISTER--}';
219 } elseif ($taskData['task_type'] == 'EXTENSION_UPDATE') {
220 // Prepare extension name and version
221 $ext_name = substr($ext_name, 7);
222 $ext_name = substr($ext_name, 0, strpos($ext_name, '-'));
223 $test = '[UPDATE-' . $ext_name . '-';
224 $ext_ver = substr($taskData['subject'], strlen($test));
225 $ext_ver = substr($ext_ver, 0, strpos($ext_ver, ':'));
227 // Load SQLs from file
228 updateExtension($ext_name, $ext_ver, true);
230 // Set current extension name
231 setCurrentExtensionName($ext_name);
234 $taskData['text'] .= getExtensionNotes();
237 $title = '{--ADMIN_SQLS_EXECUTED_ON_UPDATE--}';
239 // Remove extension's name
243 // Add SQLs to a table
244 if ((!empty($ext_name)) && (isVerboseSqlEnabled())) {
245 // Add verbose SQL table
246 $taskData['text'] .= addExtensionVerboseSqlTable($title);
248 } elseif ((!empty($ext_name)) && (!empty($ext_ver))) {
249 // Run SQL commands in dry mode but only return the notes
250 updateExtension($ext_name, $ext_ver, true);
252 // Set current extension name
253 setCurrentExtensionName($ext_name);
256 $taskData['text'] .= getExtensionNotes();
258 // This should not normally happen!
259 debug_report_bug(__FILE__, __LINE__, 'ext_name(' . $ext_name . ') or ext_ver(' . $ext_ver . ') is empty! isVerboseSqlEnabled=' . intval(isVerboseSqlEnabled()));
262 // Prepare array for the template
264 'subject' => $taskData['subject'],
266 'text' => $taskData['text'],
267 'task_created' => generateDateTime($taskData['task_created'], '1'),
268 'extension' => $ext_name
272 $OUT .= loadTemplate('admin_overview_row', true, $content);
274 // Which task do we actually have here?
275 // @TODO Rewrite this to something with include files and/or filter
276 switch ($taskData['task_type']) {
277 case 'EXTENSION': // Install new extensions
278 $ext_name = substr($taskData['subject'], 1, strpos($taskData['subject'], ':') - 1);
279 if (!isExtensionInstalled($ext_name)) {
280 // New (not yet installed) extension found
281 $OUT .= loadTemplate('admin_extension_reg_form', true, array(
282 'id' => bigintval($taskId),
283 'ext_name' => $ext_name
286 // Extension is already installed
287 $OUT .= '<div class="notice">{--ADMIN_EXTENSION_ALREADY_REGISTERED--}</div>';
289 // Close task but not already closed, solved, deleted or update tasks
290 if ((!in_array($taskData['status'], array('CLOSED', 'DELETED', 'SOLVED'))) && ($taskData['task_type'] != 'EXTENSION_UPDATE')) {
292 runFilterChain('solve_task', $taskData['id']);
297 case 'EXTENSION_UPDATE': // Extension update
298 // Extension updates are installed automatically
299 $OUT .= '<div class="notice medium">{--ADMIN_EXTENSION_UPDATED--}</div>';
301 // Close task if not closed or deleted
302 if (!in_array($taskData['status'], array('CLOSED', 'DELETED'))) {
304 runFilterChain('solve_task', $taskData['id']);
308 case 'MEMBER_SUPPORT': // Assign on member's support request
309 // @TODO This may also be rewritten to include files
311 default: // @TODO Unknown support mode
312 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown support mode %s detected. This part is under construction!", $mode));
313 $OUT .= '<div class="notice medium">{%message,ADMIN_UNKNOWN_SUPPORT_MODE=' . $mode . '%}</div>';
318 case 'PAYOUT_REQUEST': // Payout requests
319 if (isExtensionActive('payout')) {
320 // Extension is installed so let him send a notification to the user
321 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `userid`=%s AND `payout_timestamp`=%s LIMIT 1",
322 array(bigintval($taskData['userid']), bigintval($taskData['task_created'])), __FILE__, __LINE__);
323 list($pid) = SQL_FETCHROW($result_pay);
324 SQL_FREERESULT($result_pay);
326 if ((!empty($pid)) && ($pid > 0)) {
327 // Payout id can be obtained
330 'tid' => $taskData['id'],
334 $OUT .= loadTemplate('admin_payout_overview_form', true, $content);
336 // Problem obtaining payout id
337 $OUT .= '<div class="notice medium">{--ADMIN_PAYOUT_OBTAIN_ID_FAILED--}</div>';
340 // Extension is not installed
341 $OUT .= '<div class="notice medium">{--ADMIN_PAYOUT_NOT_INSTALLED--}</div>';
345 case 'WERNIS_REQUEST': // Wernis requests
346 if (isExtensionActive('wernis')) {
347 // Extension is installed so let him send a notification to the user
348 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_wernis` WHERE `userid`=%s AND wernis_timestamp=%s LIMIT 1",
349 array(bigintval($taskData['userid']), bigintval($taskData['task_created'])), __FILE__, __LINE__);
350 list($pid) = SQL_FETCHROW($result_pay);
351 SQL_FREERESULT($result_pay);
353 if ((!empty($pid)) && ($pid > 0)) {
354 // Payout id can be obtained
357 'tid' => $taskData['id'],
359 $OUT .= loadTemplate('admin_wernis_overview_form', true, $content);
361 // Problem obtaining wernis id
362 $OUT .= '<div class="notice medium">{--WERNIS_OBTAIN_ID_FAILED--}</div>';
365 // Extension is not installed
366 $OUT .= '<div class="notice medium">{--ADMIN_WERNIS_NOT_INSTALLED--}</div>';
370 case 'HOLIDAY_REQUEST': // Holiday requests
371 $OUT .= loadTemplate('admin_task_holiday', true, $taskData['userid']);
374 case 'MEMBER_ORDER': // Member mail orders
375 $OUT .= loadTemplate('admin_task_order', true, $taskId);
378 default: // Unknown task type
379 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", $taskData['task_type']));
380 $OUT .= '<div class="notice medium">' . sprintf(getMessage('ADMIN_UNKNOWN_TASK_TYPE'), $taskData['task_type'], $taskId) . '</div>';
389 SQL_FREERESULT($result_task);
392 // Load final template
393 loadTemplate('admin_overview_list', false, $OUT);
395 if ((isset($postData['sel'])) && ((count($postData['sel']) > 0) || ($postData['sel'][0] == 1))) {
396 // Only unassign / delete tasks when there are selected tasks posted
397 if (!empty($postData['unassign'])) {
398 // Unassign from tasks
399 foreach ($postData['sel'] as $taskId => $sel) {
400 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=NULL WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
401 array(bigintval($taskId), getCurrentAdminId()), __FILE__, __LINE__);
403 } elseif (isset($postData['delete'])) {
405 foreach ($postData['sel'] as $taskId => $sel) {
406 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `assigned_admin` IN (%s,0,NULL) LIMIT 1",
407 array(bigintval($taskId), getCurrentAdminId()), __FILE__, __LINE__);
411 debug_report_bug(__FILE__, __LINE__, sprintf("Unknown task action performed. data=<pre>%s</pre>", print_r($postData, true)));
415 $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 OR `assigned_admin` IS NULL) AND `status`='NEW') ORDER BY `task_created` DESC",
416 array(getCurrentAdminId()), __FILE__, __LINE__);
419 // There are uncompleted jobs!
421 while ($content = SQL_FETCHARRAY($result_tasks)) {
423 $content['infos'] = '';
426 // @TODO Try to move this in includes
427 switch ($content['task_type']) {
429 case 'EXTENSION_UPDATE':
430 $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
434 if (isValidUserId($content['userid'])) {
435 // Member found otherwise it's a system task
436 $content['userid'] = generateUserProfileLink($content['userid']);
438 $content['userid'] = '<em>{--ADMIN_IS_SYSTEM_TASK--}</em>';
441 // Add/translate some content
442 $content['task_created'] = generateDateTime($content['task_created'], 2);
444 // Do we have extension task?
445 if (isExtensionTask($content)) {
446 // Load extension row template
447 $OUT .= loadTemplate('admin_overview_list_ext_rows', true, $content);
449 // Load default row template
450 $OUT .= loadTemplate('admin_overview_list_rows', true, $content);
455 SQL_FREERESULT($result_tasks);
457 // Load footer template
458 loadTemplate('admin_overview_table', false, $OUT);