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