Listing of coupons rewritten to more clear
[mailer.git] / inc / modules / admin / what-list_coupon.php
index 0069ce021df9fb501c67f84e2b3a127f2f126313..2f6f89c79a3c43f91710df52a6dbb862b2bae2db 100644 (file)
@@ -43,8 +43,9 @@ if ((!defined('__SECURITY')) || (!isAdmin())) {
 // Add description as navigation point
 addYouAreHereLink('admin', __FILE__);
 
-// Check if the user has cashed coupons
-$result = SQL_QUERY('SELECT
+if (isGetRequestParameterSet('coupon_id')) {
+       // List userids for given coupon
+       $result = SQL_QUERY_ESC('SELECT
        u.`coupon_id`,
        u.`userid`,
        UNIX_TIMESTAMP(u.`cashed_on`) AS `cashed_on`,
@@ -57,34 +58,79 @@ INNER JOIN
        `{?_MYSQL_PREFIX?}_coupon_data` AS d
 ON
        u.`coupon_id`=d.`id`
+WHERE
+       u.`coupon_id`=%s
 ORDER BY
-       u.`cashed_on` DESC', __FILE__, __LINE__);
+       u.`cashed_on` DESC',
+               array(
+                       bigintval(getRequestParameter('coupon_id'))
+               ), __FILE__, __LINE__);
 
-// Do we have entries?
-if (SQL_NUMROWS($result) > 0) {
-       // Init variable
-       $OUT = '';
+       // Do we have entries?
+       if (SQL_NUMROWS($result) > 0) {
+               // Init variable
+               $OUT = '';
 
-       // Load all rows
-       while ($content = SQL_FETCHARRAY($result)) {
-               // Translate all timestamps
-               $content['cashed_on']      = generateDateTime($content['cashed_on']     , '2');
-               $content['coupon_created'] = generateDateTime($content['coupon_created'], '2');
-               $content['coupon_expired'] = generateDateTime($content['coupon_expired'], '2');
+               // Load all rows
+               while ($content = SQL_FETCHARRAY($result)) {
+                       // Translate all timestamps
+                       $content['cashed_on']      = generateDateTime($content['cashed_on']     , '2');
+                       $content['coupon_created'] = generateDateTime($content['coupon_created'], '2');
+                       $content['coupon_expired'] = generateDateTime($content['coupon_expired'], '2');
 
-               // Add the row template
-               $OUT .= loadTemplate('admin_list_coupon_row', true, $content);
-       } // END - while
+                       // Add the row template
+                       $OUT .= loadTemplate('admin_list_coupon_usr_row', true, $content);
+               } // END - while
 
-       // Load main template
-       loadTemplate('admin_list_coupon', false, $OUT);
+               // Load main template
+               loadTemplate('admin_list_coupon_usr', false, $OUT);
+       } else {
+               // No cashed coupons found
+               displayMessage('{--ADMIN_LIST_COUPON_404--}');
+       }
+
+       // Free result
+       SQL_FREERESULT($result);
 } else {
-       // No cashed coupons found
-       displayMessage('{--ADMIN_LIST_COUPON_404--}');
-}
+       // Check if the user has cashed coupons
+       $result = SQL_QUERY('SELECT
+       d.`id` AS `coupon_id`,
+       UNIX_TIMESTAMP(d.`coupon_created`) AS `coupon_created`,
+       UNIX_TIMESTAMP(d.`coupon_expired`) AS `coupon_expired`,
+       d.`points`,
+       d.`total_created`,
+       d.`total_cashed`,
+       d.`coupon_description`
+FROM
+       `{?_MYSQL_PREFIX?}_coupon_data` AS d
+ORDER BY
+       d.`id` ASC', __FILE__, __LINE__);
+
+       // Do we have entries?
+       if (SQL_NUMROWS($result) > 0) {
+               // Init variable
+               $OUT = '';
+
+               // Load all rows
+               while ($content = SQL_FETCHARRAY($result)) {
+                       // Translate all timestamps
+                       $content['coupon_created'] = generateDateTime($content['coupon_created'], '2');
+                       $content['coupon_expired'] = generateDateTime($content['coupon_expired'], '2');
 
-// Free result
-SQL_FREERESULT($result);
+                       // Add the row template
+                       $OUT .= loadTemplate('admin_list_coupon_row', true, $content);
+               } // END - while
+
+               // Load main template
+               loadTemplate('admin_list_coupon', false, $OUT);
+       } else {
+               // No cashed coupons found
+               displayMessage('{--ADMIN_LIST_COUPON_404--}');
+       }
+
+       // Free result
+       SQL_FREERESULT($result);
+}
 
 // [EOF]
 ?>