New feature of repaying points to user/jackpot/shred added
[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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!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         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "task");
40         return;
41 }
42
43 // Add description as navigation point
44 ADD_DESCR("admin", basename(__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_ADMIN_ID(get_session('admin_login'))."' 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_ADMIN_ID(get_session('admin_login'))."' 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_ADMIN_ID(get_session('admin_login'))."' 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_ADMIN_ID(get_session('admin_login'))."' AND status='CLOSED'";
73         break;
74
75 default: // Unknown type
76         LOAD_TEMPLATE("admin_settings_saved", false, TASK_ADMIN_UNKNOWN_MODE_1.$_GET['type'].TASK_ADMIN_UNKNOWN_MODE_2);
77         break;
78 }
79
80 if (!empty($whereStatement))
81 {
82         $SEL = 0;
83         if (isset($_POST['task'])) $SEL = SELECTION_COUNT($_POST['task']);
84         if ((isset($_POST['assign'])) && ($SEL > 0))
85         {
86                 // Assign / do tasks
87                 require_once(PATH."inc/modules/admin/overview-inc.php");
88                 if (empty($dmy)) $dmy = "";
89                 OUTPUT_SELECTED_TASKS($_POST, $dmy);
90         }
91          else
92         {
93                 // Start listing tasks matching selected filter
94                 $result_tasks = SQL_QUERY("SELECT id, assigned_admin, userid, task_type, subject, text, task_created
95 FROM "._MYSQL_PREFIX."_task_system
96 WHERE ".$whereStatement."
97 ORDER BY userid DESC, task_type DESC, subject, task_created DESC", __FILE__, __LINE__);
98                 if (($SEL > 0) && (!IS_DEMO()))
99                 {
100                         // Only unassign / delete tasks when there are selected tasks posted
101                         if (isset($_POST['unassign']))
102                         {
103                                 // Unassign from tasks
104                                 foreach ($_POST['task'] as $id=>$sel)
105                                 {
106                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin='0' WHERE id=%d AND assigned_admin='%s' LIMIT 1",
107                                          array(bigintval($id), GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
108                                 }
109                         }
110                          elseif (isset($_POST['del']))
111                         {
112                                 // Delete tasks
113                                 foreach ($_POST['task'] as $id=>$sel)
114                                 {
115                                         if ($_GET['type'] == "deleted")
116                                         {
117                                                 // Delete task immediately
118                                                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE id=%d LIMIT 1",
119                                                  array(bigintval($id)),__FILE__, __LINE__);
120                                         }
121                                          else
122                                         {
123                                                 // Mark task as to be deleted (purged by autppurge extension)
124                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET status='DELETED' WHERE id=%d LIMIT 1",
125                                                  array(bigintval($id)), __FILE__, __LINE__);
126                                         }
127                                 }
128                         }
129
130                         // Update query
131                         $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__);
132                 }
133
134                 // There are uncompleted jobs!
135                 $eval = "\$type = ADMIN_OVERVIEW_TASK_".strtoupper($_GET['type'])."_TYPE;";
136                 eval($eval);
137                 LOAD_TEMPLATE("admin_overview_header_task", false, array(
138                         'message' => $type,
139                         'type'    => $_GET['type']
140                 ));
141                 $SW = 2;
142                 while (list($id, $admin, $uid, $type, $subj, $text, $created) = SQL_FETCHROW($result_tasks))
143                 {
144                         $infos = "---";
145                         if ($admin == "0")
146                         {
147                                 // No admin currently is assigned
148                                 $admin = "<FONT class=\"admin_note\">".ADMIN_NO_ADMIN_ASSIGNED."</FONT>";
149                         }
150                          else
151                         {
152                                 // Load admin's data
153                                 $login = GET_ADMIN_LOGIN($admin);
154                                 if ($login != "***")
155                                 {
156                                         // Admin found
157                                         $admin = "<A href=\"".URL."/modules.php?module=admin&amp;what=admins_contct&amp;admin=".$admin."\">".$login."</A>";
158                                 }
159                                  else
160                                 {
161                                         // Maybe deleted?
162                                         $admin = "<FONT class=\"admin_note\">".ADMIN_ID_404_1.$admin.ADMIN_ID_404_2."</FONT>";
163                                 }
164                         }
165                         $evl = "\$type_out = ADMIN_TASK_IS_".strtoupper($type).";";
166                         eval($evl);
167                         $type2 = substr($text, 0, strpos($text, ":"));
168                         // Generate infos
169                         switch ($type)
170                         {
171                         case "EXTENSION":
172                         case "EXTENSION_UPDATE":
173                                 $infos = substr($subj, 1, strpos($subj, ":") - 1);
174                                 break;
175                         }
176                         if ($uid > 0)
177                         {
178                                 // Member found otherwise it's a system task
179                                 $uid = ADMIN_USER_PROFILE_LINK($uid);
180                         }
181                          else
182                         {
183                                 $uid = "<I>".ADMIN_IS_SYSTEM_TASK."</I>";
184                         }
185                         $content = array(
186                                 'sw'      => $SW,
187                                 'id'      => $id,
188                                 'admin'   => $admin,
189                                 'infos'   => $infos,
190                                 'uid'     => $uid,
191                                 'type'    => $type_out,
192                                 'created' => MAKE_DATETIME($created, "2")
193                         );
194                         LOAD_TEMPLATE("admin_list_task_rows", false, $content);
195                         $SW = 3 - $SW;
196                 }
197
198                 // Free memory
199                 SQL_FREERESULT($result_tasks);
200
201                 // Load footer template
202                 if ($_GET['type'] == "deleted")
203                 {
204                         // Delete now button
205                         LOAD_TEMPLATE("admin_overview_footer_task");
206                 }
207                  else
208                 {
209                         // Normal footer
210                         LOAD_TEMPLATE("admin_overview_footer");
211                 }
212         }
213 }
214 //
215 ?>