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 - 2012 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 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',extInstalled=' . intval($extInstalled));
72 if ($extInstalled === FALSE) {
73 // We maybe want to install an extension so let's test-drive it...
74 if (loadExtension($ext_name, 'test', '0.0.0', TRUE)) {
75 // Create a task for newly installed extension (we ignore the task id here)
76 createNewExtensionTask($ext_name);
79 // Test-drive extension
80 loadExtension($ext_name, 'test');
82 // Get extension version
83 $ext_ver = getExtensionVersion($ext_name);
84 //* DEBUG: */ debugOutput($ext_name.'='.$ext_ver);
86 // Update extension if extension is installed and outdated
87 //* DEBUG: */ debugOutput('ext=' . $ext_name . ',ver=' . getThisExtensionVersion() . '/' . getExtensionVersion($ext_name));
88 if (getThisExtensionVersion() > $ext_ver) {
89 // Update the extension
90 updateExtension($ext_name, $ext_ver);
93 if (isset($GLOBALS['cache_array']['always_active'][$ext_name])) {
94 // Shall the current extension kept activated?
95 if (($GLOBALS['cache_array']['always_active'][$ext_name] == 'Y') && (!isExtensionActive($ext_name))) {
96 // Reactivate this extension!
97 doActivateExtension($ext_name);
104 // At last - but not least - check for own and new unassigned tasks...
105 $result_tasks = SQL_QUERY_ESC("SELECT
114 `{?_MYSQL_PREFIX?}_task_system`
116 `assigned_admin`=%s OR ((`assigned_admin`=0 OR `assigned_admin` IS NULL) AND `status`='NEW')
121 `task_created` DESC",
122 array(getCurrentAdminId()), __FILE__, __LINE__);
124 if (!SQL_HASZERONUMS($result_tasks)) {
130 SQL_FREERESULT($result);
136 // Outputs selected tasks
137 function outputSeletectedTasks ($postData, $result_tasks) {
138 if ((isset($postData['assign'])) && (count($postData['sel']) > 0)) {
141 foreach ($postData['sel'] as $taskId => $sel) {
142 $result_task = SQL_QUERY_ESC("SELECT
152 `{?_MYSQL_PREFIX?}_task_system`
154 `id`=%s AND (`assigned_admin`=%s OR ((`assigned_admin`=0 OR `assigned_admin` IS NULL) AND `status`='NEW'))
159 ), __FILE__, __LINE__);
162 if (SQL_NUMROWS($result_task) == 1) {
163 // Task is valid so load it's data
164 $taskData = SQL_FETCHARRAY($result_task);
166 if ($taskData['assigned_admin'] == '0') {
167 // Assgin current admin to unassgigned task
168 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=%s WHERE `id`=%s AND `assigned_admin` IS NULL LIMIT 1",
171 bigintval($taskData['id'])
172 ), __FILE__, __LINE__);
176 // @TODO Rewrite this to a filter
177 if ($taskData['task_type'] == 'MEMBER_SUPPORT') {
178 $mode = substr($taskData['text'], 0, strpos($taskData['text'], ':'));
179 $taskData['text'] = substr($taskData['text'], strpos($taskData['text'], ':') + 1);
180 $add = '<li>{--ADMIN_TASK_SUPPORT_MODE--}: <strong>' . $mode . '</strong></li>';
183 // Is a userid assign?
184 if ($taskData['userid'] > 0) {
185 // Then load his data!
186 if (fetchUserData($taskData['userid'])) {
188 $content = getUserDataArray();
190 // Generate HTML list entry
191 $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>';
193 // Invalid userid, so log and zero it
194 logDebugMessage(__FUNCTION__, __LINE__, 'fetchUserData() failed: userid=' . $taskData['userid'] . ' not found.');
195 $taskData['userid'] = '0';
199 // Decode entities of the text
200 $taskData['text'] = decodeEntities($taskData['text']);
202 // Compile and insert text from task into table template
203 $taskData['text'] = loadTemplate('admin_extensions_text', TRUE, $taskData['text']);
205 // Initialize variables (no title for SQL commands by default)
206 $ext_name = ''; $ext_ver = '';
207 $title = '{--ADMIN_TASK_NO_SQL_TITLE--}';
209 // Shall I list SQL commands assigned to an extension installation or update task?
210 if ((isVerboseSqlEnabled()) || (!isExtensionInstalled('sql_patches'))) {
211 // Extract extension name from subject
212 $ext_name = substr($taskData['subject'], 1, strpos($taskData['subject'], ':') - 1);
214 // Update task or extension task?
215 if (($taskData['task_type'] == 'EXTENSION') && (!isExtensionInstalled($ext_name))) {
216 // Load SQL commands for registering in dry-run
217 registerExtension($ext_name, $taskId, TRUE);
219 // Is this non-productive?
220 if (isExtensionProductive() === FALSE) {
222 $taskData['text'] = displayMessage('{%message,ADMIN_EXTENSION_IS_NON_PRODUCTIVE=' . $ext_name . '%}', TRUE) . $taskData['text'];
225 // Set current extension name
226 setCurrentExtensionName($ext_name);
229 $taskData['text'] .= getExtensionNotes();
232 $title = '{--ADMIN_SQLS_EXECUTED_ON_REGISTER--}';
233 } elseif ($taskData['task_type'] == 'EXTENSION_UPDATE') {
234 // Prepare extension name and version
235 $ext_name = substr($ext_name, 7);
236 $ext_name = substr($ext_name, 0, strpos($ext_name, '-'));
237 $test = '[UPDATE-' . $ext_name . '-';
238 $ext_ver = substr($taskData['subject'], strlen($test));
239 $ext_ver = substr($ext_ver, 0, strpos($ext_ver, ':'));
241 // Load SQLs from file
242 updateExtension($ext_name, $ext_ver, TRUE);
244 // Set current extension name
245 setCurrentExtensionName($ext_name);
248 $taskData['text'] .= getExtensionNotes();
251 $title = '{--ADMIN_SQLS_EXECUTED_ON_UPDATE--}';
253 // Remove extension's name
257 // Add SQLs to a table
258 if ((!empty($ext_name)) && (isVerboseSqlEnabled())) {
259 // Add verbose SQL table
260 $taskData['text'] .= addExtensionVerboseSqlTable($title);
262 } elseif ((!empty($ext_name)) && (!empty($ext_ver))) {
263 // Run SQL commands in dry mode but only return the notes
264 updateExtension($ext_name, $ext_ver, TRUE);
266 // Set current extension name
267 setCurrentExtensionName($ext_name);
270 $taskData['text'] .= getExtensionNotes();
272 // This should not normally happen!
273 reportBug(__FILE__, __LINE__, 'ext_name(' . $ext_name . ') or ext_ver(' . $ext_ver . ') is empty! isVerboseSqlEnabled=' . intval(isVerboseSqlEnabled()));
276 // Prepare array for the template
278 'subject' => $taskData['subject'],
280 'text' => $taskData['text'],
281 'task_created' => generateDateTime($taskData['task_created'], '1'),
282 'ext_name' => $ext_name
286 $OUT .= loadTemplate('admin_overview_row', TRUE, $content);
288 // Which task do we actually have here?
289 // @TODO Rewrite this to something with include files and/or filter
290 switch ($taskData['task_type']) {
291 case 'EXTENSION': // Install new extensions
292 $ext_name = substr($taskData['subject'], 1, strpos($taskData['subject'], ':') - 1);
293 if (!isExtensionInstalled($ext_name)) {
294 // New (not yet installed) extension found
295 $OUT .= loadTemplate('admin_extension_reg_form', TRUE, array(
296 'id' => bigintval($taskId),
297 'ext_name' => $ext_name
300 // Extension is already installed
301 $OUT .= '<div class="notice">{--ADMIN_EXTENSION_ALREADY_REGISTERED--}</div>';
303 // Close task but not already closed, solved, deleted or update tasks
304 if ((!in_array($taskData['status'], array('CLOSED', 'DELETED', 'SOLVED'))) && ($taskData['task_type'] != 'EXTENSION_UPDATE')) {
306 runFilterChain('solve_task', $taskData['id']);
311 case 'EXTENSION_UPDATE': // Extension update
312 // Extension updates are installed automatically
313 $OUT .= '<div class="notice medium">{--ADMIN_EXTENSION_UPDATED--}</div>';
315 // Close task if not closed or deleted
316 if (!in_array($taskData['status'], array('CLOSED', 'DELETED'))) {
318 runFilterChain('solve_task', $taskData['id']);
322 case 'MEMBER_SUPPORT': // Assign on member's support request
323 // @TODO This may also be rewritten to include files
325 default: // @TODO Unknown support mode
326 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown support mode %s detected. This part is under construction.", $mode));
327 $OUT .= '<div class="notice medium">{%message,ADMIN_UNKNOWN_SUPPORT_MODE=' . $mode . '%}</div>';
332 case 'PAYOUT_REQUEST': // Payout requests
333 if (isExtensionActive('payout')) {
334 // Extension is installed so let him send a notification to the user
335 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `userid`=%s AND `payout_timestamp`=%s LIMIT 1",
336 array(bigintval($taskData['userid']), bigintval($taskData['task_created'])), __FILE__, __LINE__);
337 list($pid) = SQL_FETCHROW($result_pay);
338 SQL_FREERESULT($result_pay);
340 if ((!empty($pid)) && ($pid > 0)) {
341 // Payout id can be obtained
344 'tid' => $taskData['id'],
348 $OUT .= loadTemplate('admin_payout_overview_form', TRUE, $content);
350 // Problem obtaining payout id
351 $OUT .= '<div class="notice medium">{--ADMIN_PAYOUT_OBTAIN_ID_FAILED--}</div>';
354 // Extension is not installed
355 $OUT .= '<div class="notice medium">{--ADMIN_PAYOUT_NOT_INSTALLED--}</div>';
359 case 'WERNIS_REQUEST': // Wernis requests
360 if (isExtensionActive('wernis')) {
361 // Extension is installed so let him send a notification to the user
362 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_wernis` WHERE `userid`=%s AND wernis_timestamp=%s LIMIT 1",
363 array(bigintval($taskData['userid']), bigintval($taskData['task_created'])), __FILE__, __LINE__);
364 list($pid) = SQL_FETCHROW($result_pay);
365 SQL_FREERESULT($result_pay);
367 if ((!empty($pid)) && ($pid > 0)) {
368 // Payout id can be obtained
371 'tid' => $taskData['id'],
373 $OUT .= loadTemplate('admin_wernis_overview_form', TRUE, $content);
375 // Problem obtaining wernis id
376 $OUT .= '<div class="notice medium">{--WERNIS_OBTAIN_ID_FAILED--}</div>';
379 // Extension is not installed
380 $OUT .= '<div class="notice medium">{--ADMIN_WERNIS_NOT_INSTALLED--}</div>';
384 case 'HOLIDAY_REQUEST': // Holiday requests
385 $OUT .= loadTemplate('admin_task_holiday', TRUE, $taskData['userid']);
388 case 'MEMBER_ORDER': // Member mail orders
389 $OUT .= loadTemplate('admin_task_order', TRUE, $taskId);
392 default: // Unknown task type
393 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", $taskData['task_type']));
394 $OUT .= '<div class="notice medium">' . sprintf(getMessage('ADMIN_UNKNOWN_TASK_TYPE'), $taskData['task_type'], $taskId) . '</div>';
403 SQL_FREERESULT($result_task);
406 // Load final template
407 loadTemplate('admin_overview_list', FALSE, $OUT);
409 if ((isset($postData['sel'])) && ((count($postData['sel']) > 0) || ($postData['sel'][0] == 1))) {
410 // Only unassign / delete tasks when there are selected tasks posted
411 if (!empty($postData['unassign'])) {
412 // Unassign from tasks
413 foreach ($postData['sel'] as $taskId => $sel) {
414 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=NULL WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
415 array(bigintval($taskId), getCurrentAdminId()), __FILE__, __LINE__);
417 } elseif (!empty($postData['delete'])) {
419 foreach ($postData['sel'] as $taskId => $sel) {
420 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `assigned_admin` IN (%s,0,NULL) LIMIT 1",
421 array(bigintval($taskId), getCurrentAdminId()), __FILE__, __LINE__);
425 reportBug(__FILE__, __LINE__, sprintf("Unknown task action performed. data=<pre>%s</pre>", print_r($postData, TRUE)));
429 $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",
430 array(getCurrentAdminId()), __FILE__, __LINE__);
433 // There are uncompleted jobs!
435 while ($content = SQL_FETCHARRAY($result_tasks)) {
437 $content['infos'] = '';
440 // @TODO Try to move this in includes
441 switch ($content['task_type']) {
443 case 'EXTENSION_UPDATE':
444 $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
448 if (isValidUserId($content['userid'])) {
449 // Member found otherwise it's a system task
450 $content['userid'] = generateUserProfileLink($content['userid']);
452 $content['userid'] = '{--ADMIN_IS_SYSTEM_TASK--}';
455 // Add/translate some content
456 $content['task_created'] = generateDateTime($content['task_created'], 2);
458 // Is there extension task?
459 if (isExtensionTask($content)) {
460 // Load extension row template
461 $OUT .= loadTemplate('admin_overview_list_ext_rows', TRUE, $content);
463 // Load default row template
464 $OUT .= loadTemplate('admin_overview_list_rows', TRUE, $content);
469 SQL_FREERESULT($result_tasks);
471 // Load footer template
472 loadTemplate('admin_overview_table', FALSE, $OUT);