Way more usage of EL code:
[mailer.git] / inc / modules / admin / what-list_task.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 08/03/2004 *
4  * ===================                          Last change: 08/07/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_task.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : List all tasks                                   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle Aufgaben auflisten                          *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if (!isExtensionActive('task')) {
47         displayMessage(generateExtensionInactiveNotInstalledMessage('task'));
48         return;
49 } // END - if
50
51 $whereStatement = '';
52 if (!isGetRequestParameterSet('type')) setGetRequestParameter('type', 'your');
53
54 switch (getRequestParameter('type')) {
55         case 'your': // List only your own open (new) tasks
56                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='NEW' AND `task_type` != 'EXTENSION_UPDATE'";
57                 break;
58
59         case 'updates': // List only updates assigned to you
60                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='NEW' AND `task_type`='EXTENSION_UPDATE'";
61                 break;
62
63         case 'solved': // List only solved tasks assigned to you
64                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='SOLVED'";
65                 break;
66
67         case 'unassigned': // List unassigned (but not deleted) tasks
68                 $whereStatement = "(`assigned_admin`=0 OR `assigned_admin` IS NULL) AND `status` != 'DELETED'";
69                 break;
70
71         case 'deleted': // List all deleted
72                 $whereStatement = "`status`='DELETED'";
73                 break;
74
75         case 'closed': // List all closed
76                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='CLOSED'";
77                 break;
78
79         default: // Unknown type
80                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", getRequestParameter('type')));
81                 displayMessage('{%message,ADMIN_TASK_UNKNOWN_MODE' . getRequestParameter('type') . '%}');
82                 break;
83 } // END - switch
84
85 if (!empty($whereStatement)) {
86         if ((isPostRequestParameterSet('assign')) && (ifPostContainsSelections())) {
87                 // Assign / do tasks
88                 loadIncludeOnce('inc/modules/admin/overview-inc.php');
89                 if (empty($dmy)) $dmy = '';
90                 outputSeletectedTasks(postRequestArray(), $dmy);
91         } else {
92                 // Start listing tasks matching selected filter
93                 $result_tasks = SQL_QUERY('SELECT
94         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
95 FROM
96         `{?_MYSQL_PREFIX?}_task_system`
97 WHERE
98         '.$whereStatement.'
99 ORDER BY
100         `userid` DESC,
101         `task_type` DESC,
102         `subject` ASC,
103         `task_created` DESC',
104                         __FILE__, __LINE__);
105                 if ((ifPostContainsSelections()) && (!isDemoModeActive())) {
106                         // Only unassign / delete tasks when there are selected tasks posted
107                         if (isPostRequestParameterSet('unassign')) {
108                                 // Unassign from tasks
109                                 foreach (postRequestParameter('sel') as $id => $sel) {
110                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=NULL WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
111                                                 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
112                                 } // END - foreach
113                         } elseif (isFormSent('delete')) {
114                                 // Delete tasks
115                                 foreach (postRequestParameter('sel') as $id => $sel) {
116                                         if (getRequestParameter('type') == 'deleted') {
117                                                 // Delete task immediately
118                                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
119                                                         array(bigintval($id)),__FILE__, __LINE__);
120                                         } else {
121                                                 // Mark task as to be deleted (purged by autopurge extension)
122                                                 adminDeleteTask($id);
123                                         }
124                                 } // END - foreach
125                         } else {
126                                 // Unknown action performed
127                                 debug_report_bug(__FILE__, __LINE__, sprintf("Unknown task action performed. data=<pre>%s</pre>", print_r(postRequestArray(), true)));
128                         }
129
130                         // Update query
131                         $result_tasks = SQL_QUERY('SELECT
132         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
133 FROM
134         `{?_MYSQL_PREFIX?}_task_system`
135 WHERE
136         '.$whereStatement.'
137 ORDER BY
138         `subject` ASC,
139         `task_created` DESC', __FILE__, __LINE__);
140                 }
141
142                 // There are uncompleted jobs!
143                 $OUT = '';
144                 while ($content = SQL_FETCHARRAY($result_tasks)) {
145                         // Init infos
146                         $content['infos'] = '';
147
148                         // Generate infos
149                         switch ($content['task_type']) {
150                                 case 'EXTENSION':
151                                 case 'EXTENSION_UPDATE':
152                                         $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
153                                         break;
154                         } // END - switch
155
156                         // Member assigned with task?
157                         if (isValidUserId($content['userid'])) {
158                                 // Member found otherwise it's a system task
159                                 $content['userid'] = generateUserProfileLink($content['userid']);
160                         } else {
161                                 // Is a system task!
162                                 $content['userid'] = '<em>{--ADMIN_IS_SYSTEM_TASK--}</em>';
163                         }
164
165                         // Prepare content
166                         $content = merge_array($content, array(
167                                 'task_created'  => generateDateTime($content['task_created'], 2)
168                         ));
169
170                         // Do we have an extension task?
171                         if (isExtensionTask($content)) {
172                                 // Load extension row template
173                                 $OUT .= loadTemplate('admin_list_task_ext_rows', true, $content);
174                         } else {
175                                 // Load default row template
176                                 $OUT .= loadTemplate('admin_list_task_rows', true, $content);
177                         }
178                 } // END - while
179
180                 // Free memory
181                 SQL_FREERESULT($result_tasks);
182
183                 // Prepare content
184                 $content = array(
185                         'message' => '{--ADMIN_OVERVIEW_TASK_' . strtoupper(getRequestParameter('type')) . '_TYPE--}',
186                         'type'    => getRequestParameter('type'),
187                         'rows'    => $OUT
188                 );
189
190                 // Load footer template
191                 if (getRequestParameter('type') == 'deleted') {
192                         // Delete now button
193                         loadTemplate('admin_list_task_delete', false, $content);
194                 } else {
195                         // Normal footer
196                         loadTemplate('admin_list_task', false, $content);
197                 }
198         }
199 } // END - if
200
201 // [EOF]
202 ?>