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