Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[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 - 2015 by Mailer Developer Team                   *
20  * For more information visit: http://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 $whereStatement = '';
47 if (!isGetRequestElementSet('type')) {
48         setGetRequestElement('type', 'your');
49 } // END - if
50
51 switch (getRequestElement('type')) {
52         case 'your': // List only your own open (new) tasks
53                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='NEW' AND `task_type` != 'EXTENSION_UPDATE'";
54                 break;
55
56         case 'updates': // List only updates assigned to you
57                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='NEW' AND `task_type`='EXTENSION_UPDATE'";
58                 break;
59
60         case 'solved': // List only solved tasks assigned to you
61                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='SOLVED'";
62                 break;
63
64         case 'unassigned': // List unassigned (but not deleted) tasks
65                 $whereStatement = "(`assigned_admin`=0 OR `assigned_admin` IS NULL) AND `status` != 'DELETED'";
66                 break;
67
68         case 'deleted': // List all deleted
69                 $whereStatement = "`status`='DELETED'";
70                 break;
71
72         case 'closed': // List all closed
73                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='CLOSED'";
74                 break;
75
76         default: // Unknown type
77                 logDebugMessage(__FILE__, __LINE__, sprintf('Unknown task type %s detected.', getRequestElement('type')));
78                 displayMessage('{%message,ADMIN_TASK_UNKNOWN_MODE' . getRequestElement('type') . '%}');
79                 break;
80 } // END - switch
81
82 if (!empty($whereStatement)) {
83         if ((isPostRequestElementSet('assign')) && (ifPostContainsSelections())) {
84                 // Assign / do tasks
85                 loadIncludeOnce('inc/modules/admin/overview-inc.php');
86                 if (empty($dmy)) $dmy = '';
87                 outputSeletectedTasks(postRequestArray(), $dmy);
88         } else {
89                 // Start listing tasks matching selected filter
90                 $result_tasks = sqlQuery('SELECT
91         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
92 FROM
93         `{?_MYSQL_PREFIX?}_task_system`
94 WHERE
95         '.$whereStatement.'
96 ORDER BY
97         `userid` DESC,
98         `task_type` DESC,
99         `subject` ASC,
100         `task_created` DESC',
101                         __FILE__, __LINE__);
102                 if ((ifPostContainsSelections()) && (!isDemoModeActive())) {
103                         // Only unassign / delete tasks when there are selected tasks posted
104                         if (isFormSent('unassign')) {
105                                 // Unassign from tasks
106                                 foreach (postRequestElement('sel') as $id => $sel) {
107                                         sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=NULL WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
108                                                 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
109                                 } // END - foreach
110                         } elseif (isFormSent('delete')) {
111                                 // Delete tasks
112                                 foreach (postRequestElement('sel') as $id => $sel) {
113                                         if (getRequestElement('type') == 'deleted') {
114                                                 // Delete task immediately
115                                                 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
116                                                         array(bigintval($id)),__FILE__, __LINE__);
117                                         } else {
118                                                 // Mark task as to be deleted (purged by autopurge extension)
119                                                 adminDeleteTask($id);
120                                         }
121                                 } // END - foreach
122                         } else {
123                                 // Unknown action performed
124                                 reportBug(__FILE__, __LINE__, sprintf('Unknown task action performed. data=<pre>%s</pre>', print_r(postRequestArray(), TRUE)));
125                         }
126
127                         // Update query
128                         $result_tasks = sqlQuery('SELECT
129         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
130 FROM
131         `{?_MYSQL_PREFIX?}_task_system`
132 WHERE
133         '.$whereStatement.'
134 ORDER BY
135         `subject` ASC,
136         `task_created` DESC', __FILE__, __LINE__);
137                 }
138
139                 // There are uncompleted jobs!
140                 $OUT = '';
141                 while ($content = sqlFetchArray($result_tasks)) {
142                         // Init infos
143                         $content['infos'] = '';
144
145                         // Generate infos
146                         switch ($content['task_type']) {
147                                 case 'EXTENSION':
148                                 case 'EXTENSION_UPDATE':
149                                         $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
150                                         break;
151                         } // END - switch
152
153                         // Member assigned with task?
154                         if (isValidId($content['userid'])) {
155                                 // Member found otherwise it's a system task
156                                 $content['userid'] = generateUserProfileLink($content['userid']);
157                         } else {
158                                 // Is a system task!
159                                 $content['userid'] = '{--ADMIN_IS_SYSTEM_TASK--}';
160                         }
161
162                         // Prepare content
163                         $content = merge_array($content, array(
164                                 'task_created'  => generateDateTime($content['task_created'], 2)
165                         ));
166
167                         // Is there an extension task?
168                         if (isExtensionTask($content)) {
169                                 // Load extension row template
170                                 $OUT .= loadTemplate('admin_list_task_ext_rows', TRUE, $content);
171                         } else {
172                                 // Load default row template
173                                 $OUT .= loadTemplate('admin_list_task_rows', TRUE, $content);
174                         }
175                 } // END - while
176
177                 // Free memory
178                 sqlFreeResult($result_tasks);
179
180                 // Prepare content
181                 $content = array(
182                         'message' => '{--ADMIN_OVERVIEW_TASK_' . strtoupper(getRequestElement('type')) . '_TYPE_TITLE--}',
183                         'type'    => getRequestElement('type'),
184                         'rows'    => $OUT
185                 );
186
187                 // Load footer template
188                 if (getRequestElement('type') == 'deleted') {
189                         // Delete now button
190                         loadTemplate('admin_list_task_delete', FALSE, $content);
191                 } else {
192                         // Normal footer
193                         loadTemplate('admin_list_task', FALSE, $content);
194                 }
195         }
196 } // END - if
197
198 // [EOF]
199 ?>