Even more fixes/improvements for rallye
[mailer.git] / inc / modules / admin / what-list_rallyes.php
index 1b945c75a9ab0acf2c8d660b4e2f258b9d110152..8c46526b68a11e427e5761a2568366779245ae30 100644 (file)
@@ -48,44 +48,41 @@ if (!isGetRequestElementSet('sub')) setRequestGetElement('sub', '');
 $message = '';
 
 // Quick actions on a rallye
-if (isGetRequestElementSet(('rallye'))) {
+if (isGetRequestElementSet('rallye')) {
        // Init SQL queries
        initSqls();
 
-       if (isGetRequestElementSet(('activate'))) {
+       if (isGetRequestElementSet('activate')) {
                // Activate / deactivate
-               switch (getRequestElement('activate'))
-               {
+               switch (getRequestElement('activate')) {
                        case 1: // Activate
-                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET is_active='Y' WHERE `id`=%s AND is_active='N' LIMIT 1");
+                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `is_active`='Y' WHERE `id`=%s AND `is_active`='N' LIMIT 1");
                                break;
 
                        case 0: // Deactivate
-                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET is_active='N' WHERE `id`=%s AND is_active='Y' LIMIT 1");
+                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `is_active`='N' WHERE `id`=%s AND `is_active`='Y' LIMIT 1");
                                break;
                }
        } elseif (isGetRequestElementSet('notify')) {
                // Automatic notification
-               switch (getRequestElement('notify'))
-               {
+               switch (getRequestElement('notify')) {
                        case 1: // Activate
-                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET send_notify='Y' WHERE `id`=%s AND send_notify='N' LIMIT 1");
+                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `send_notify`='Y' WHERE `id`=%s AND `send_notify`='N' LIMIT 1");
                                break;
 
                        case 0: // Deactivate
-                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET send_notify='N' WHERE `id`=%s AND send_notify='Y' LIMIT 1");
+                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `send_notify`='N' WHERE `id`=%s AND `send_notify`='Y' LIMIT 1");
                                break;
                }
-       } elseif (isGetRequestElementSet(('auto'))) {
+       } elseif (isGetRequestElementSet('auto')) {
                // Automatic adding of new members
-               switch (getRequestElement('auto'))
-               {
+               switch (getRequestElement('auto')) {
                        case 1: // Activate
-                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET auto_add_new_user='Y' WHERE `id`=%s AND auto_add_new_user='N' LIMIT 1");
+                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `auto_add_new_user`='Y' WHERE `id`=%s AND `auto_add_new_user`='N' LIMIT 1");
                                break;
 
                        case 0: // Deactivate
-                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET auto_add_new_user='N' WHERE `id`=%s AND auto_add_new_user='Y' LIMIT 1");
+                               addSql("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET `auto_add_new_user`='N' WHERE `id`=%s AND `auto_add_new_user`='Y' LIMIT 1");
                                break;
                }
        }
@@ -128,7 +125,7 @@ if (isGetRequestElementSet(('rallye'))) {
 
                // Change selected rallyes and all it's data
                foreach (postRequestElement('title') as $id => $title) {
-                       // Secure ID number
+                       // Secure id number
                        $id = bigintval($id);
 
                        // Generate timestamps
@@ -136,24 +133,28 @@ if (isGetRequestElementSet(('rallye'))) {
                        $END   = mktime(postRequestElement('end_hour', $id)  , postRequestElement('end_min', $id)  , postRequestElement('end_sec', $id)  , postRequestElement('end_month', $id)  , postRequestElement('end_day', $id)  , postRequestElement('end_year', $id)  );
 
                        // Update entry
-                       addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_rallye_data` SET
-title='%s',
-descr='%s',
-template='%s',
-start_time='%s',
-end_time='%s',
-min_users='%s',
-min_prices='%s'
-WHERE `id`='".$id."' LIMIT 1",
+                       addSql(SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_rallye_data`
+SET
+       `title`='%s',
+       `descr`='%s',
+       `template`='%s',
+       `start_time`='%s',
+       `end_time`='%s',
+       `min_users`='%s',
+       `min_prices`='%s'
+WHERE
+       `id`='%s'
+LIMIT 1",
                        array(
-                       $title,
-                       postRequestElement('descr', $id),
-                       postRequestElement('templ', $id),
-                       bigintval($START),
-                       bigintval($END),
-                       bigintval(postRequestElement('min_users', $id)),
-                       bigintval(postRequestElement('min_prices', $id)),
-                       $id
+                               $title,
+                               postRequestElement('descr', $id),
+                               postRequestElement('templ', $id),
+                               bigintval($START),
+                               bigintval($END),
+                               bigintval(postRequestElement('min_users', $id)),
+                               bigintval(postRequestElement('min_prices', $id)),
+                               $id
                        ), __FILE__, __LINE__, false));
                }
 
@@ -173,11 +174,14 @@ if (isPostRequestElementSet('edit')) {
                $OUT = ''; $SW = 2;
                foreach (postRequestElement('sel') as $id => $selected) {
                        // Load rallye basic data
-                       $result = SQL_QUERY_ESC("SELECT title, descr, template, start_time, end_time, min_users, min_prices
-FROM `{?_MYSQL_PREFIX?}_rallye_data`
-WHERE `id`=%s
+                       $result = SQL_QUERY_ESC("SELECT
+       `title`, `descr`, `template`, `start_time`, `end_time`, `min_users`, `min_prices`
+FROM
+       `{?_MYSQL_PREFIX?}_rallye_data`
+WHERE
+       `id`=%s
 LIMIT 1",
-                       array(bigintval($id)), __FILE__, __LINE__);
+                               array(bigintval($id)), __FILE__, __LINE__);
                        // Fetch an array
                        $content = SQL_FETCHARRAY($result);
 
@@ -220,8 +224,8 @@ LIMIT 1",
        }
 } elseif ((getRequestElement('sub') == 'users') && (getRequestElement('rallye') > 0)) {
        // List users and their refs before start and current
-       $result = SQL_QUERY_ESC("SELECT userid, refs, curr_points FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE rallye_id=%s ORDER BY `userid` ASC",
-       array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT `userid`, `refs`, `curr_points` FROM `{?_MYSQL_PREFIX?}_rallye_users` WHERE `rallye_id`=%s ORDER BY `userid` ASC",
+               array(bigintval(getRequestElement('rallye'))), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) > 0) {
                $OUT = ''; $SW = 2;
                $content['rallye'] = getRequestElement('rallye');
@@ -274,58 +278,60 @@ LIMIT 1",
        }
 } else {
        // Start listing rallyes
-       $result = SQL_QUERY("SELECT id, admin_id, title, descr, template, start_time, end_time, auto_add_new_user, is_active, send_notify, notified, min_users, min_prices
-FROM `{?_MYSQL_PREFIX?}_rallye_data`
-ORDER BY start_time DESC",
-       __FILE__, __LINE__);
+       $result = SQL_QUERY("SELECT
+       `id`, `admin_id`, `title`, `descr`, `template`, `start_time`, `end_time`, `auto_add_new_user`, `is_active`, `send_notify`, `notified`, `min_users`, `min_prices`
+FROM
+       `{?_MYSQL_PREFIX?}_rallye_data`
+ORDER BY
+       `start_time` DESC", __FILE__, __LINE__);
+
+       // Records found?
        if (SQL_NUMROWS($result) > 0) {
                // List found rallyes
                $OUT = ''; $SW = 2;
-               while ($row = SQL_FETCHARRAY($result)) {
+               while ($data = SQL_FETCHARRAY($result)) {
                        // Load admin login
-                       $row['alogin'] = getAdminLogin($row['admin_id']);
+                       $data['login'] = getAdminLogin($data['admin_id']);
 
                        // Count joined userids
-                       $joined = countSumTotalData($row['id'], "rallye_users", 'id', "rallye_id", true);
+                       $joined = countSumTotalData($data['id'], 'rallye_users', 'id', 'rallye_id', true);
 
                        // Did some users joined this rallye?
                        if ($joined > 0) {
                                // List joined users
-                               $joined = "<a href=\"{?URL?}/modules.php?module=admin&amp;what=list_rallyes&amp;sub=users&amp;rallye=".$row['id']."\" title=\"{--RALLYE_LIST_USERS_TITLE--}\">".$joined."</a>";
+                               $joined = "<a href=\"{?URL?}/modules.php?module=admin&amp;what=list_rallyes&amp;sub=users&amp;rallye=".$data['id']."\" title=\"{--RALLYE_LIST_USERS_TITLE--}\">".$joined."</a>";
                        } // END - if
 
                        // Alter some variables
-                       if (empty($row['alogin']))   $row['alogin']    = '???';
-                       if (empty($row['template'])) $row['template']  = '---';
-                       if (empty($row['descr']))    $row['descr']     = '---';
+                       if (empty($data['login']))    $data['login']     = '???';
+                       if (empty($data['template'])) $data['template']  = '---';
+                       if (empty($data['descr']))    $data['descr']     = '---';
 
                        // Transfer data into array for the template
-                       // @TODO Rewritings: admin_id->admin_id in template
                        $row = array(
-                               'select'     => "<input type=\"checkbox\" name=\"sel[".$row['id']."]\" class=\"admin_normal\" value=\"1\" />",
-                               'admin_id'        => $row['admin_id'],
-                               'email_link' => generateEmailLink($row['admin_id']),
-                               'alogin'     => $row['alogin'],
-                               'id'         => $row['id'],
+                               'select'     => "<input type=\"checkbox\" name=\"sel[".$data['id']."]\" class=\"admin_normal\" value=\"1\" />",
+                               'admin_id'   => $data['admin_id'],
+                               'email_link' => generateEmailLink($data['admin_id']),
+                               'login'      => $data['login'],
+                               'id'         => $data['id'],
                                'sw'         => $SW,
-                               'title'      => $row['title'],
-                               'template'   => $row['template'],
+                               'title'      => $data['title'],
+                               'template'   => $data['template'],
                                'joined'     => $joined,
-                               'start_date' => generateDateTime($row['start_time'], 2),
-                               'end_date'   => generateDateTime($row['end_time']  , 2),
-                               'active_lnk' => translateYesNo($row['is_active']),
-                               'notify_lnk' => translateYesNo($row['send_notify']),
-                               'auto_lnk'   => translateYesNo($row['auto_add_new_user']),
-                               'notified'   => translateYesNo($row['notified']),
-                               'prices_cnt' => translateComma(countSumTotalData($row['id'], 'rallye_prices', 'id', 'rallye_id', true)),
-                               'descr'      => $row['descr'],
-                               'min_users'  => $row['min_users'],
-                               'min_prices' => $row['min_prices'],
+                               'start_date' => generateDateTime($data['start_time'], 2),
+                               'end_date'   => generateDateTime($data['end_time']  , 2),
+                               'active_lnk' => translateYesNo($data['is_active']),
+                               'notify_lnk' => translateYesNo($data['send_notify']),
+                               'auto_lnk'   => translateYesNo($data['auto_add_new_user']),
+                               'notified'   => translateYesNo($data['notified']),
+                               'prices_cnt' => translateComma(countSumTotalData($data['id'], 'rallye_prices', 'id', 'rallye_id', true)),
+                               'descr'      => $data['descr'],
+                               'min_users'  => $data['min_users'],
+                               'min_prices' => $data['min_prices'],
                        );
 
                        // Is the rallye active or not?
-                       switch ($row['is_active'])
-                       {
+                       switch ($data['is_active']) {
                                case 'Y':
                                        // Rallye is active so do not edit it!
                                        $row['select'] = "<div class=\"big\">".$row['id']."</div>";
@@ -340,8 +346,7 @@ ORDER BY start_time DESC",
                        }
 
                        // Notification to members?
-                       switch ($row['send_notify'])
-                       {
+                       switch ($data['send_notify']) {
                                case 'Y':
                                        $row['notify_title'] = getMessage('RALLYE_STOP_NOTIFY_NOW');
                                        $row['notify'] = 0;
@@ -354,8 +359,7 @@ ORDER BY start_time DESC",
                        }
 
                        // Auto-add of new joined members?
-                       switch ($row['auto_add_new_user'])
-                       {
+                       switch ($data['auto_add_new_user']) {
                                case 'Y':
                                        $row['auto_title'] = getMessage('RALLYE_STOP_AUTO_ADD_NOW');
                                        $row['auto'] = 0;
@@ -370,7 +374,7 @@ ORDER BY start_time DESC",
                        // Output row
                        $OUT .= loadTemplate('admin_list_rallyes_row', true, $row);
                        $SW = 3 - $SW;
-               }
+               } // END - while
 
                // Free memory
                SQL_FREERESULT($result);