91150db8f6debecefaa287d9a32817fdf386dd2d
[mailer.git] / inc / modules / admin / what-list_yoomedia_tm.php
1 <?php
2 /************************************************************************
3  * M-XChange v0.2.1                                   Start: 10/10/2008 *
4  * ================                             Last change: 10/10/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_yoomedia_tm.php                        *
8  * -------------------------------------------------------------------- *
9  * Short description : List Yoo!Media text mails                        *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Auflisten von Yoo!Media Textmails                *
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.       *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
35         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
36         require($INC);
37 } elseif (!EXT_IS_ACTIVE("yoomedia")) {
38         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "yoomedia");
39         return;
40 } elseif (!EXT_IS_ACTIVE("bonus")) {
41         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "bonus");
42         return;
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("admin", __FILE__);
47
48 // Do actions here
49 if (isset($_POST['ok'])) {
50         // Prepare mail for delivery
51         YOOMEDIA_PREPARE_MAIL_DELIVERY($_POST);
52         return;
53 } elseif (isset($_POST['sent'])) {
54         // Sent mail
55         YOOMEDIA_SEND_BONUS_MAIL($_POST, "normal");
56 } elseif (isset($_POST['remove'])) {
57         // Add mail to exclude list
58         YOOMEDIA_EXCLUDE_MAIL($_POST, "normal");
59 } elseif (isset($_POST['unlist'])) {
60         // Remove mail from exclude list
61         YOOMEDIA_UNLIST_MAIL($_POST, "normal");
62 }
63
64 // Enougth queries left?
65 if ($_CONFIG['yoomedia_requests_remain'] == 0) {
66         // Output message
67         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_YOOMEDIA_REQUESTS_DEPLETED);
68
69         // Abort here!
70         return false;
71 } // END - if
72
73 // Get parsed array back
74 $result = YOOMEDIA_GET_PARSED_RESULT_TEXTMAILS();
75
76 // Sanity-check on result array
77 if ((!is_array($result)) || (count($result) == 0) || (!isset($result[0]['id']))) {
78         // Invalid result
79         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_YOOMEDIA_INVALID_RESULT);
80         return false;
81 } elseif (count($result[0]) < 7) {
82         // Error received so prepare error code
83         $code = explode(" ", $result[0]['id']);
84         $code = $code[0];
85         $code = explode("<br>", $code);
86         $code = $code[0];
87
88         // Output message
89         LOAD_TEMPLATE("admin_yoomedia_error", false, sprintf("{--ADMIN_YOOMEDIA_ERROR_%s--}", strtoupper(YOOMEDIA_TRANSLATE_ERROR($code))));
90         return false;
91 }
92
93 // Temporary set max comma
94 $_CONFIG['max_comma'] = 5;
95
96 // Prepare all entries
97 $OUT = ""; $SW = 2;
98 foreach ($result as $entry) {
99         // Translate some data
100         $entry['pay']    = TRANSLATE_COMMA($entry['pay']);
101         $entry['remain'] = TRANSLATE_COMMA($entry['remain']);
102         $entry['sw']     = $SW;
103
104         // Check reload lock
105         $reload = YOOMEDIA_CHECK_RELOAD($entry['id'], $entry['reload'], "textmail");
106
107         // Is this mail already sent?
108         if ($reload !== false) {
109                 // Init countdown
110                 $countdown = 0;
111
112                 // Not manually locked?
113                 if ($reload > 0) {
114                         // Calculate countdown
115                         $countdown = $reload + ($entry['reload'] * 60*60) - time();
116
117                         // Countdown < 60 seconds and bigger zero?
118                         if (($countdown < 60) && ($countdown > 0)) {
119                                 // Fix to one minute
120                                 $countdown = 60;
121                         } // END - if
122
123                         // Add reload lock
124                         $entry['already'] = sprintf(ADMIN_YOOMEDIA_TEXTMAIL_SEND_AGAIN, CREATE_FANCY_TIME($countdown));
125                 } else {
126                         // Never resentable unless manual removal
127                         $entry['already'] = ADMIN_YOOMEDIA_TEXTMAIL_MANUALLY_LOCKED;
128                 }
129
130                 // Load row template for displaying
131                 $OUT .= LOAD_TEMPLATE("admin_list_yoomedia_tm_already", true, $entry);
132         } else {
133                 // Load row template with buttons
134                 $OUT .= LOAD_TEMPLATE("admin_list_yoomedia_tm_row", true, $entry);
135         }
136
137         // Switch color
138         $SW = 3 - $SW;
139 } // END - if
140
141 // Load main template
142 LOAD_TEMPLATE("admin_list_yoomedia_tm", false, $OUT);
143
144 //
145 ?>