Improvements to task extension
authorRoland Häder <roland@mxchange.org>
Tue, 9 Sep 2008 17:11:53 +0000 (17:11 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 9 Sep 2008 17:11:53 +0000 (17:11 +0000)
inc/databases.php
inc/extensions.php
inc/libs/admins_functions.php
inc/modules/admin/admin-inc.php
inc/modules/admin/overview-inc.php
inc/modules/admin/what-list_newsletter.php
inc/modules/admin/what-list_payouts.php
inc/modules/admin/what-list_task.php

index 01d9d3d..c4e612d 100644 (file)
@@ -114,7 +114,7 @@ define('USAGE_BASE', "usage");
 define('SERVER_URL', "http://www.mxchange.org");
 
 // This current patch level
-define('CURR_SVN_REVISION', "283");
+define('CURR_SVN_REVISION', "284");
 
 // Take a prime number which is long (if you know a longer one please try it out!)
 define('_PRIME', 591623);
index f566d1d..711a3d1 100644 (file)
@@ -198,8 +198,7 @@ function EXTENSION_REGISTER ($ext_name, $id, $dry_run=false)
                                 array($ext_name, $EXT_LANG_PREFIX, $EXT_ALWAYS_ACTIVE, $EXT_VERSION), __FILE__, __LINE__);
 
                                // Update task management
-                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET status='SOLVED' WHERE id=%s LIMIT 1",
-                                array(bigintval($id)), __FILE__, __LINE__);
+                               ADMIN_SOLVE_TASK($id);
 
                                // In normal mode return a true on success
                                $ret = true; unset($SQLs);
index 8b01726..a296438 100644 (file)
@@ -370,7 +370,7 @@ function ADMINS_REMOVE_ADMIN_ACCOUNTS ($POST) {
                // Delete only when it's not your own account!
                if (($del == 1) && (GET_ADMIN_ID(get_session('admin_login')) != $id)) {
                        // Rewrite his tasks to all admins
-                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin='0' WHERE assigned_admin='%s'",
+                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin=0 WHERE assigned_admin=%s",
                         array($id), __FILE__, __LINE__);
 
                        // Remove account
index 0534bef..2fe4a3a 100644 (file)
@@ -1002,5 +1002,21 @@ function ADMIN_RESET_PASSWORD ($login, $password) {
        // Return output
        return ADMIN_PASSWORD_RESET_DONE;
 }
+// Solves a task by given id number
+function ADMIN_SOLVE_TASK ($id) {
+       // Update the task data
+       ADMIN_UPDATE_TASK_DATA($id, "status", "SOLVED");
+}
+// Marks a given task as deleted
+function ADMIN_DELETE_TASK ($id) {
+       // Update the task data
+       ADMIN_UPDATE_TASK_DATA($id, "status", "DELETED");
+}
+// Function to update task data
+function ADMIN_UPDATE_TASK_DATA ($id, $row, $data) {
+       // Update the task
+       SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET %s='%s' WHERE id=%s LIMIT 1",
+               array($row, $data, bigintval($id)), __FILE__, __LINE__);
+}
 //
 ?>
index 6fdcafc..aa2f8e7 100644 (file)
@@ -290,10 +290,8 @@ function OUTPUT_SELECTED_TASKS($_POST, $result_tasks) {
                                                $OUT .= "<FONT class=\"admin_failed\">".ADMIN_EXT_ALREADY_REGISTERED."</FONT>\n";
 
                                                // Close task but not already closes or deleted or update tasks
-                                               if (($status != "CLOSED") && ($status != "DELETED") && ($type != "EXTENSION_UPDATE"))
-                                               {
-                                                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET status='SOLVED' WHERE id=%s LIMIT 1",
-                                                        array(bigintval($tid)), __FILE__, __LINE__);
+                                               if (($status != "CLOSED") && ($status != "DELETED") && ($type != "EXTENSION_UPDATE")) {
+                                                       ADMIN_SOLVE_TASK($tid);
                                                }
                                        }
                                        break;
@@ -304,8 +302,8 @@ function OUTPUT_SELECTED_TASKS($_POST, $result_tasks) {
 
                                        // Close task
                                        if (($status != "CLOSED") && ($status != "DELETED")) {
-                                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET status='SOLVED' WHERE id=%s LIMIT 1",
-                                                array(bigintval($tid)), __FILE__, __LINE__);
+                                               // Solve the task
+                                               ADMIN_SOLVE_TASK($tid);
                                        }
                                        break;
 
@@ -431,7 +429,7 @@ function OUTPUT_SELECTED_TASKS($_POST, $result_tasks) {
                                // Unassign from tasks
                                foreach ($_POST['task'] as $id=>$sel)
                                {
-                                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin='0' WHERE id=%s AND assigned_admin='%s' LIMIT 1",
+                                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin=0 WHERE id=%s AND assigned_admin=%s LIMIT 1",
                                         array(bigintval($id), GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
                                }
                        }
@@ -440,13 +438,13 @@ function OUTPUT_SELECTED_TASKS($_POST, $result_tasks) {
                                // Delete tasks
                                foreach ($_POST['task'] as $id=>$sel)
                                {
-                                       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE id=%s AND (assigned_admin='%s' OR assigned_admin='0') LIMIT 1",
+                                       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE id=%s AND assigned_admin IN (%s,0) LIMIT 1",
                                         array(bigintval($id), GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
                                }
                        }
 
                        // Update query
-                       $result_tasks = SQL_QUERY_ESC("SELECT id, assigned_admin, userid, task_type, subject, text, task_created FROM "._MYSQL_PREFIX."_task_system WHERE assigned_admin='%s' OR (assigned_admin='0' AND status='NEW') ORDER BY task_created DESC",
+                       $result_tasks = SQL_QUERY_ESC("SELECT id, assigned_admin, userid, task_type, subject, text, task_created FROM "._MYSQL_PREFIX."_task_system WHERE assigned_admin=%s OR (assigned_admin=0 AND status='NEW') ORDER BY task_created DESC",
                         array(GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
                }
 
index 93ec1c9..0c668e8 100644 (file)
@@ -49,8 +49,7 @@ if ((!empty($_POST['uid'])) && (!empty($_POST['id'])))
         array(bigintval($_POST['uid'])), __FILE__, __LINE__);
 
        // Next the task system...
-       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET status='SOLVED' WHERE id=%s LIMIT 1",
-        array(bigintval($_POST['id'])), __FILE__, __LINE__);
+       ADMIN_SOLVE_TASK($_POST['id']);
 
        // Send mail to user
        $msg = LOAD_EMAIL_TEMPLATE("member_newsletter_done", true, bigintval($_POST['uid']));
index 7378631..a4d1dc6 100644 (file)
@@ -134,10 +134,8 @@ if (!empty($_GET['pid']))
                                        if ($ret[0] == $eok)
                                        {
                                                // Clear task
-                                               if ($task > 0)
-                                               {
-                                                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET status='SOLVED' WHERE id=%s LIMIT 1",
-                                                        array(bigintval($task)),__FILE__, __LINE__);
+                                               if ($task > 0) {
+                                                       ADMIN_SOLVE_TASK($task);
                                                }
 
                                                // Clear payout request
@@ -186,11 +184,9 @@ if (!empty($_GET['pid']))
                        // Ok, now we can output the form or execute rejecting
                        if (isset($_POST['ok']))
                        {
-                               if ($task > 0)
-                               {
+                               if ($task > 0) {
                                        // Clear task
-                                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET status='SOLVED' WHERE id=%s LIMIT 1",
-                                        array(bigintval($task)), __FILE__, __LINE__);
+                                       ADMIN_SOLVE_TASK($task);
                                }
 
                                // Clear payout request
index 5ac8fff..110dab5 100644 (file)
@@ -81,48 +81,35 @@ if (!empty($whereStatement))
 {
        $SEL = 0;
        if (isset($_POST['task'])) $SEL = SELECTION_COUNT($_POST['task']);
-       if ((isset($_POST['assign'])) && ($SEL > 0))
-       {
+       if ((isset($_POST['assign'])) && ($SEL > 0)) {
                // Assign / do tasks
                require_once(PATH."inc/modules/admin/overview-inc.php");
                if (empty($dmy)) $dmy = "";
                OUTPUT_SELECTED_TASKS($_POST, $dmy);
-       }
-        else
-       {
+       } else {
                // Start listing tasks matching selected filter
                $result_tasks = SQL_QUERY("SELECT id, assigned_admin, userid, task_type, subject, text, task_created
 FROM "._MYSQL_PREFIX."_task_system
 WHERE ".$whereStatement."
 ORDER BY userid DESC, task_type DESC, subject, task_created DESC", __FILE__, __LINE__);
-               if (($SEL > 0) && (!IS_DEMO()))
-               {
+               if (($SEL > 0) && (!IS_DEMO())) {
                        // Only unassign / delete tasks when there are selected tasks posted
-                       if (isset($_POST['unassign']))
-                       {
+                       if (isset($_POST['unassign'])) {
                                // Unassign from tasks
-                               foreach ($_POST['task'] as $id=>$sel)
-                               {
-                                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin='0' WHERE id=%s AND assigned_admin='%s' LIMIT 1",
+                               foreach ($_POST['task'] as $id => $sel) {
+                                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin=0 WHERE id=%s AND assigned_admin=%s LIMIT 1",
                                         array(bigintval($id), GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
                                }
-                       }
-                        elseif (isset($_POST['del']))
-                       {
+                       } elseif (isset($_POST['del'])) {
                                // Delete tasks
-                               foreach ($_POST['task'] as $id=>$sel)
-                               {
-                                       if ($_GET['type'] == "deleted")
-                                       {
+                               foreach ($_POST['task'] as $id => $sel) {
+                                       if ($_GET['type'] == "deleted") {
                                                // Delete task immediately
                                                $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE id=%s LIMIT 1",
                                                 array(bigintval($id)),__FILE__, __LINE__);
-                                       }
-                                        else
-                                       {
+                                       } else {
                                                // Mark task as to be deleted (purged by autppurge extension)
-                                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET status='DELETED' WHERE id=%s LIMIT 1",
-                                                array(bigintval($id)), __FILE__, __LINE__);
+                                               ADMIN_DELETE_TASK($id);
                                        }
                                }
                        }