"copied"
[mailer.git] / 0.2.1-FINAL / 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 (getConfig('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 // Prepare all entries
94 $OUT = ""; $SW = 2;
95 foreach ($result as $entry) {
96         // Translate some data
97         $entry['pay']    = TRANSLATE_COMMA($entry['pay'], true, 5);
98         $entry['remain'] = TRANSLATE_COMMA($entry['remain']);
99         $entry['sw']     = $SW;
100
101         // Check reload lock
102         $reload = YOOMEDIA_CHECK_RELOAD($entry['id'], $entry['reload'], "textmail");
103
104         // Is this mail already sent?
105         if ($reload !== false) {
106                 // Init countdown
107                 $countdown = 0;
108
109                 // Not manually locked?
110                 if ($reload > 0) {
111                         // Calculate countdown
112                         $countdown = $reload + ($entry['reload'] * 60*60) - time();
113
114                         // Countdown < 60 seconds and bigger zero?
115                         if (($countdown < 60) && ($countdown > 0)) {
116                                 // Fix to one minute
117                                 $countdown = 60;
118                         } // END - if
119
120                         // Add reload lock
121                         $entry['already'] = sprintf(ADMIN_YOOMEDIA_TEXTMAIL_SEND_AGAIN, CREATE_FANCY_TIME($countdown));
122                 } else {
123                         // Never resentable unless manual removal
124                         $entry['already'] = ADMIN_YOOMEDIA_TEXTMAIL_MANUALLY_LOCKED;
125                 }
126
127                 // Load row template for displaying
128                 $OUT .= LOAD_TEMPLATE("admin_list_yoomedia_tm_already", true, $entry);
129         } else {
130                 // Load row template with buttons
131                 $OUT .= LOAD_TEMPLATE("admin_list_yoomedia_tm_row", true, $entry);
132         }
133
134         // Switch color
135         $SW = 3 - $SW;
136 } // END - if
137
138 // Load main template
139 LOAD_TEMPLATE("admin_list_yoomedia_tm", false, $OUT);
140
141 //
142 ?>