dd4e2303af607e7cfa5c8fab397fe3853182cc19
[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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software. You can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License.       *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
40         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
41         require($INC);
42 } elseif (!EXT_IS_ACTIVE('yoomedia')) {
43         addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('yoomedia'));
44         return;
45 } elseif (!EXT_IS_ACTIVE('bonus')) {
46         addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('bonus'));
47         return;
48 }
49
50 // Add description as navigation point
51 ADD_DESCR('admin', __FILE__);
52
53 // Do actions here
54 if (isFormSent()) {
55         // Prepare mail for delivery
56         YOOMEDIA_PREPARE_MAIL_DELIVERY(REQUEST_POST_ARRAY());
57         return;
58 } elseif (REQUEST_ISSET_POST(('sent'))) {
59         // Sent mail
60         YOOMEDIA_SEND_BONUS_MAIL(REQUEST_POST_ARRAY(), 'normal');
61 } elseif (REQUEST_ISSET_POST('remove')) {
62         // Add mail to exclude list
63         YOOMEDIA_EXCLUDE_MAIL(REQUEST_POST_ARRAY(), 'normal');
64 } elseif (REQUEST_ISSET_POST(('unlist'))) {
65         // Remove mail from exclude list
66         YOOMEDIA_UNLIST_MAIL(REQUEST_POST_ARRAY(), 'normal');
67 }
68
69 // Enougth queries left?
70 if (getConfig('yoomedia_requests_remain') == 0) {
71         // Output message
72         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_YOOMEDIA_REQUESTS_DEPLETED'));
73
74         // Abort here!
75         return false;
76 } // END - if
77
78 // Get parsed array back
79 $result = YOOMEDIA_GET_PARSED_RESULT_TEXTMAILS();
80
81 // Sanity-check on result array
82 if ((!is_array($result)) || (count($result) == 0) || (!isset($result[0]['id']))) {
83         // Invalid result
84         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_YOOMEDIA_INVALID_RESULT'));
85         return false;
86 } elseif (count($result[0]) < 7) {
87         // Error received so prepare error code
88         $codeArray = explode(" ", $result[0]['id']);
89         $code = $codeArray[0];
90         $codeArray = explode("<br />", $code);
91         $code = $codeArray[0];
92         $codeArray = explode("<br>", $code);
93         $code = $codeArray[0];
94
95         // Remove all new-line characters
96         $codeArray = explode("\n", $code);
97         $code = $codeArray[0];
98
99         // Remove carrige-return
100         $code = str_replace("\n", '', $code);
101
102         // Output message
103         LOAD_TEMPLATE('admin_yoomedia_error', false, sprintf("{--ADMIN_YOOMEDIA_ERROR_%s--}", strtoupper(yoomediaTranslateError($code))));
104         return false;
105 }
106
107 // Prepare all entries
108 $OUT = ''; $SW = 2;
109 foreach ($result as $entry) {
110         // Translate some data
111         $entry['pay']    = translateComma($entry['pay'], true, 5);
112         $entry['remain'] = translateComma($entry['remain']);
113         $entry['sw']     = $SW;
114
115         // Check reload lock
116         $reload = YOOMEDIA_CHECK_RELOAD($entry['id'], $entry['reload'], 'textmail');
117
118         // Is this mail already sent?
119         if ($reload !== false) {
120                 // Init countdown
121                 $countdown = 0;
122
123                 // Not manually locked?
124                 if ($reload > 0) {
125                         // Calculate countdown
126                         $countdown = $reload + ($entry['reload'] * 60*60) - time();
127
128                         // Countdown < 60 seconds and bigger zero?
129                         if (($countdown < 60) && ($countdown > 0)) {
130                                 // Fix to one minute
131                                 $countdown = 60;
132                         } // END - if
133
134                         // Add reload lock
135                         $entry['already'] = sprintf(getMessage('ADMIN_YOOMEDIA_TEXTMAIL_SEND_AGAIN'), createFancyTime($countdown));
136                 } else {
137                         // Never resentable unless manual removal
138                         $entry['already'] = getMessage('ADMIN_YOOMEDIA_TEXTMAIL_MANUALLY_LOCKED');
139                 }
140
141                 // Load row template for displaying
142                 $OUT .= LOAD_TEMPLATE('admin_list_yoomedia_tm_already', true, $entry);
143         } else {
144                 // Load row template with buttons
145                 $OUT .= LOAD_TEMPLATE('admin_list_yoomedia_tm_row', true, $entry);
146         }
147
148         // Switch color
149         $SW = 3 - $SW;
150 } // END - if
151
152 // Load main template
153 LOAD_TEMPLATE('admin_list_yoomedia_tm', false, $OUT);
154
155 //
156 ?>