cbf3efe36e00c7809c266896818d9ecb2fc3e38e
[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, 2010 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 addMenuDescription('admin', __FILE__);
45
46 if (!isExtensionActive('task')) {
47         loadTemplate('admin_settings_saved', false, 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 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                 loadTemplate('admin_settings_saved', false, getMaskedMessage('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`=0 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                         // Get admin task
149                         $content['task_type_msg'] = '{--ADMIN_TASK_IS_' . strtoupper($content['task_type']) . '--}';
150
151                         // Generate infos
152                         switch ($content['task_type']) {
153                                 case 'EXTENSION':
154                                 case 'EXTENSION_UPDATE':
155                                         $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
156                                         break;
157                         } // END - switch
158
159                         // Member assigned with task?
160                         if (isValidUserId($content['userid'])) {
161                                 // Member found otherwise it's a system task
162                                 $content['userid'] = generateUserProfileLink($content['userid']);
163                         } else {
164                                 // Is a system task!
165                                 $content['userid'] = '<em>{--ADMIN_IS_SYSTEM_TASK--}</em>';
166                         }
167
168                         // Prepare content
169                         $content = merge_array($content, array(
170                                 'assign_admin'  => $content['assigned_admin'],
171                                 'userid'        => $content['userid'],
172                                 'task_type_msg' => $content['task_type_msg'],
173                                 'task_created'  => generateDateTime($content['task_created'], 2)
174                         ));
175
176                         // Do we have an extension task?
177                         if (isExtensionTask($content)) {
178                                 // Load extension row template
179                                 $OUT .= loadTemplate('admin_list_task_ext_rows', true, $content);
180                         } else {
181                                 // Load default row template
182                                 $OUT .= loadTemplate('admin_list_task_rows', true, $content);
183                         }
184                 } // END - while
185
186                 // Free memory
187                 SQL_FREERESULT($result_tasks);
188
189                 // Prepare content
190                 $content = array(
191                         'message' => '{--ADMIN_OVERVIEW_TASK_' . strtoupper(getRequestParameter('type')) . '_TYPE--}',
192                         'type'    => getRequestParameter('type'),
193                         'rows'    => $OUT
194                 );
195
196                 // Load footer template
197                 if (getRequestParameter('type') == 'deleted') {
198                         // Delete now button
199                         loadTemplate('admin_list_task_delete', false, $content);
200                 } else {
201                         // Normal footer
202                         loadTemplate('admin_list_task', false, $content);
203                 }
204         }
205 } // END - if
206
207 // [EOF]
208 ?>