652fb048f002164beb67d7277bbdbff7361f14af
[mailer.git] / inc / modules / admin / what-list_task.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!EXT_IS_ACTIVE("task")) {
39         addFatalMessage(EXTENSION_PROBLEM_EXT_INACTIVE, "task");
40         return;
41 }
42
43 // Add description as navigation point
44 ADD_DESCR("admin", __FILE__);
45
46 $whereStatement = "";
47 if (empty($_GET['type'])) $_GET['type'] = "your";
48
49 switch ($_GET['type'])
50 {
51 case "your": // List only your own open (new) tasks
52         $whereStatement = "assigned_admin='".GET_CURRENT_ADMIN_ID()."' AND `status`='NEW' AND task_type != 'EXTENSION_UPDATE'";
53         break;
54
55 case "updates": // List only updates assigned to you
56         $whereStatement = "assigned_admin=".GET_CURRENT_ADMIN_ID()." AND `status`='NEW' AND task_type = 'EXTENSION_UPDATE'";
57         break;
58
59 case "solved": // List only solved tasks assigned to you
60         $whereStatement = "assigned_admin=".GET_CURRENT_ADMIN_ID()." AND `status`='SOLVED'";
61         break;
62
63 case "unassigned": // List unassigned (but not deleted) tasks
64         $whereStatement = "assigned_admin='0' AND status != 'DELETED'";
65         break;
66
67 case "deleted": // List all deleted
68         $whereStatement = "`status`='DELETED'";
69         break;
70
71 case "closed": // List all closed
72         $whereStatement = "assigned_admin=".GET_CURRENT_ADMIN_ID()." AND `status`='CLOSED'";
73         break;
74
75 default: // Unknown type
76         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", $_GET['type']));
77         LOAD_TEMPLATE("admin_settings_saved", false, TASK_ADMIN_UNKNOWN_MODE_1.$_GET['type'].TASK_ADMIN_UNKNOWN_MODE_2);
78         break;
79 }
80
81 if (!empty($whereStatement))
82 {
83         $SEL = 0;
84         if (isset($_POST['task'])) $SEL = SELECTION_COUNT($_POST['task']);
85         if ((isset($_POST['assign'])) && ($SEL > 0)) {
86                 // Assign / do tasks
87                 LOAD_INC_ONCE("inc/modules/admin/overview-inc.php");
88                 if (empty($dmy)) $dmy = "";
89                 OUTPUT_SELECTED_TASKS($_POST, $dmy);
90         } else {
91                 // Start listing tasks matching selected filter
92                 $result_tasks = SQL_QUERY("SELECT id, assigned_admin, userid, task_type, subject, text, task_created
93 FROM `{!_MYSQL_PREFIX!}_task_system`
94 WHERE ".$whereStatement."
95 ORDER BY userid DESC, task_type DESC, subject, task_created DESC", __FILE__, __LINE__);
96                 if (($SEL > 0) && (!IS_DEMO())) {
97                         // Only unassign / delete tasks when there are selected tasks posted
98                         if (isset($_POST['unassign'])) {
99                                 // Unassign from tasks
100                                 foreach ($_POST['task'] as $id => $sel) {
101                                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET assigned_admin=0 WHERE id=%s AND assigned_admin=%s LIMIT 1",
102                                                 array(bigintval($id), GET_CURRENT_ADMIN_ID()), __FILE__, __LINE__);
103                                 }
104                         } elseif (isset($_POST['del'])) {
105                                 // Delete tasks
106                                 foreach ($_POST['task'] as $id => $sel) {
107                                         if ($_GET['type'] == "deleted") {
108                                                 // Delete task immediately
109                                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE id=%s LIMIT 1",
110                                                         array(bigintval($id)),__FILE__, __LINE__);
111                                         } else {
112                                                 // Mark task as to be deleted (purged by autppurge extension)
113                                                 ADMIN_DELETE_TASK($id);
114                                         }
115                                 }
116                         }
117
118                         // Update query
119                         $result_tasks = SQL_QUERY("SELECT id, assigned_admin, userid, task_type, subject, text, task_created FROM `{!_MYSQL_PREFIX!}_task_system` WHERE ".$whereStatement." ORDER BY subject, task_created DESC", __FILE__, __LINE__);
120                 }
121
122                 // There are uncompleted jobs!
123                 $type = constant('ADMIN_OVERVIEW_TASK_'.strtoupper($_GET['type']).'_TYPE');
124                 LOAD_TEMPLATE("admin_overview_header_task", false, array(
125                         'message' => $type,
126                         'type'    => $_GET['type']
127                 ));
128                 $SW = 2;
129                 while (list($id, $admin, $uid, $type, $subj, $text, $created) = SQL_FETCHROW($result_tasks)) {
130                         $infos = "---";
131                         if ($admin == "0") {
132                                 // No admin currently is assigned
133                                 $admin = "<div class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</div>";
134                         } else {
135                                 // Load admin's data
136                                 $login = GET_ADMIN_LOGIN($admin);
137                                 if ($login != "***") {
138                                         // Admin found
139                                         $admin = "<a href=\"{!URL!}/modules.php?module=admin&amp;what=admins_contct&amp;admin=".$admin."\">".$login."</a>";
140                                 } else {
141                                         // Maybe deleted?
142                                         $admin = "<div class=\"admin_note\">".ADMIN_ID_404_1.$admin.ADMIN_ID_404_2."</div>";
143                                 }
144                         }
145
146                         // Get admin task
147                         $type_out = constant('ADMIN_TASK_IS_'.strtoupper($type).'');
148
149                         $type2 = substr($text, 0, strpos($text, ":"));
150                         // Generate infos
151                         switch ($type)
152                         {
153                         case "EXTENSION":
154                         case "EXTENSION_UPDATE":
155                                 $infos = substr($subj, 1, strpos($subj, ":") - 1);
156                                 break;
157                         }
158
159                         // Member assigned with task?
160                         if ($uid > 0) {
161                                 // Member found otherwise it's a system task
162                                 $uid = ADMIN_USER_PROFILE_LINK($uid);
163                         } else {
164                                 // Is a system task!
165                                 $uid = "<em>".ADMIN_IS_SYSTEM_TASK."</em>";
166                         }
167
168                         // Prepare content
169                         $content = array(
170                                 'sw'      => $SW,
171                                 'id'      => $id,
172                                 'admin'   => $admin,
173                                 'infos'   => $infos,
174                                 'uid'     => $uid,
175                                 'type'    => $type_out,
176                                 'created' => MAKE_DATETIME($created, "2")
177                         );
178
179                         // Do we have an extension task?
180                         if (($type == "EXTENSION") && (GET_EXT_VERSION($infos) == "")) {
181                                 // Load extension row template
182                                 LOAD_TEMPLATE("admin_list_task_ext_rows", false, $content);
183                         } else {
184                                 // Load default row template
185                                 LOAD_TEMPLATE("admin_list_task_rows", false, $content);
186                         }
187
188                         // Switch colors
189                         $SW = 3 - $SW;
190                 }
191
192                 // Free memory
193                 SQL_FREERESULT($result_tasks);
194
195                 // Load footer template
196                 if ($_GET['type'] == "deleted")
197                 {
198                         // Delete now button
199                         LOAD_TEMPLATE("admin_overview_footer_task");
200                 }
201                  else
202                 {
203                         // Normal footer
204                         LOAD_TEMPLATE("admin_overview_footer");
205                 }
206         }
207 }
208 //
209 ?>