1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: global $area, $action, $perm;
18:
19: $page = new cGuiPage('mail_log_overview');
20:
21: if (!$perm->have_perm_area_action($area)) {
22: $page->displayError(i18n('Permission denied'));
23: $page->abortRendering();
24: $page->render();
25: exit();
26: }
27:
28:
29: if (getSystemProperty('system', 'mail_log') === 'false') {
30: $page->displayWarning(i18n('Mail logging is disabled!'));
31: }
32:
33: $mailLogCollection = new cApiMailLogCollection();
34:
35:
36: if ($action == 'mail_log_delete') {
37:
38:
39: if (!empty($_REQUEST['idmails'])) {
40: $mailLogSuccessCollection = new cApiMailLogSuccessCollection();
41: $idmails = json_decode($_REQUEST['idmails'], true);
42: foreach ($idmails as $idmail) {
43: $mailLogCollection->delete($idmail);
44:
45: $mailLogSuccessCollection->deleteBy('idmail', $idmail);
46: }
47: }
48: } else if ($action == 'mail_log_resend') {
49: $mailer = new cMailer();
50: $mailer->resendMail($_REQUEST['idmailsuccess']);
51: }
52:
53: $mailLogCollection->query();
54:
55:
56: if ($mailLogCollection->count() === 0) {
57:
58:
59: if (getSystemProperty('system', 'mail_log') !== 'false') {
60: $page->displayInfo(i18n('No mails have been logged yet.'));
61: }
62:
63: $page->abortRendering();
64: $page->render();
65: exit();
66: }
67:
68: if ($area === 'mail_log' || $area === 'mail_log_overview') {
69:
70: $form = new cHTMLForm('bulk_editing', '', 'post', 'action-form');
71: $form->setVar('area', '');
72: $form->setVar('frame', '4');
73: $form->setVar('action', '');
74: $form->setVar('contenido', cRegistry::getSession()->id);
75: $form->setVar('idmail', '');
76: $form->setVar('idmails', '');
77: $page->appendContent($form);
78:
79:
80: $page->appendContent(mailLogBulkEditingFunctions());
81:
82:
83: $table = new cHTMLTable();
84: $table->setClass('generic');
85: $table->setWidth('100%');
86:
87:
88: $headers = array(
89: 'checkbox' => i18n('Mark'),
90: 'subject' => i18n('Subject'),
91: 'to' => i18n('To'),
92: 'created' => i18n('Date'),
93: 'client' => i18n('Client'),
94: 'action' => i18n('Action')
95: );
96: $thead = new cHTMLTableHeader();
97: $tr = new cHTMLTableRow();
98: foreach ($headers as $header) {
99: $th = new cHTMLTableHead();
100: $th->setContent($header);
101: $tr->appendContent($th);
102: }
103: $thead->setContent($tr);
104: $table->appendContent($thead);
105:
106:
107: $tbody = new cHTMLTableBody();
108:
109: while (($item = $mailLogCollection->next()) !== false) {
110: $tr = new cHTMLTableRow();
111: foreach ($headers as $key => $value) {
112: $td = new cHTMLTableData();
113: switch ($key) {
114: case 'checkbox':
115: $checkbox = new cHTMLCheckbox('', $item->get('idmail'), '', false, '', '', '', 'mark_emails');
116: $td->setContent($checkbox->toHtml(false));
117: break;
118: case 'client':
119: $idclient = $item->get('idclient');
120: $clientItem = new cApiClient($idclient);
121: $td->setContent($clientItem->get('name') . ' ');
122: break;
123: case 'from':
124: case 'to':
125: $addresses = $item->get($key);
126: $addresses = mailLogDecodeAddresses($addresses);
127: $td->setContent($addresses . ' ');
128: break;
129: case 'action':
130:
131: $img = new cHTMLImage('images/info.gif');
132: $link = new cHTMLLink('javascript:void(0)');
133: $link->setEvent('click', 'showInfo(' . $item->get('idmail') . ');');
134: $link->setContent($img);
135: $link->appendStyleDefinition('margin-right', '5px');
136: $td->appendContent($link);
137:
138: $img = new cHTMLImage('images/delete.gif');
139: $link = new cHTMLLink('javascript:void(0)');
140: $link->setEvent('click', 'Con.showConfirmation("' . i18n('Do you really want to delete this email?') . '", function() { deleteEmails(' . $item->get('idmail') . '); });return false;');
141: $link->setContent($img);
142: $td->appendContent($link);
143: break;
144: default:
145: $td->setContent($item->get($key) . ' ');
146: }
147: $tr->appendContent($td);
148: }
149: $tbody->appendContent($tr);
150: }
151: $table->appendContent($tbody);
152: $page->appendContent($table);
153:
154:
155: $page->appendContent(mailLogBulkEditingFunctions());
156: } else if ($area === 'mail_log_detail') {
157: if (isset($_REQUEST['idmail']) && is_numeric($_REQUEST['idmail'])) {
158:
159: $link = new cHTMLLink(cRegistry::getBackendUrl() . 'main.php?area=mail_log&frame=4&contenido=' . cRegistry::getSession()->id);
160: $image = new cHTMLImage('images/but_back.gif');
161: $image->appendStyleDefinition('cursor', 'pointer');
162: $image->appendStyleDefinition('margin-bottom', '10px');
163: $link->setContent($image);
164: $page->appendContent($link);
165:
166: $idmail = $_REQUEST['idmail'];
167:
168: $form = new cHTMLForm('', '', 'post', 'action-form');
169: $form->setVar('area', '');
170: $form->setVar('frame', '4');
171: $form->setVar('action', 'mail_log_overview');
172: $form->setVar('contenido', cRegistry::getSession()->id);
173: $form->setVar('idmail', $idmail);
174: $form->setVar('idmails', '[' . $idmail . ']');
175: $form->setVar('idmailsuccess', '');
176: $page->appendContent($form);
177:
178:
179: $tableHeaderDetail = array(
180: 'from' => i18n('From'),
181: 'to' => i18n('To'),
182: 'reply_to' => i18n('Reply to'),
183: 'cc' => i18n('CC'),
184: 'bcc' => i18n('BCC'),
185: 'subject' => i18n('Subject'),
186: 'body' => i18n('Body'),
187: 'created' => i18n('Date')
188: );
189: $table = new cHTMLTable();
190: $table->setClass('generic');
191: $table->appendStyleDefinition('border-top', '1px solid #B3B3B3');
192: $mailItem = new cApiMailLog($idmail);
193: foreach ($tableHeaderDetail as $key => $value) {
194: $tr = new cHTMLTableRow();
195: $td = new cHTMLTableData();
196: $td->setContent($value . ' ');
197: $tr->appendContent($td);
198: switch ($key) {
199:
200: case 'from':
201: case 'to':
202: case 'reply_to':
203: case 'cc':
204: case 'bcc':
205: $td = new cHTMLTableData();
206: $addresses = mailLogDecodeAddresses($mailItem->get($key));
207: $td->setContent($addresses . ' ');
208: $tr->appendContent($td);
209: break;
210: default:
211: $td = new cHTMLTableData();
212: $data = $mailItem->get($key);
213: if ($mailItem->get('content_type') === 'text/plain') {
214: $data = nl2br($data);
215: }
216: $td->setContent($data . ' ');
217: $tr->appendContent($td);
218: }
219: $table->appendContent($tr);
220: }
221:
222: $tr = new cHTMLTableRow();
223: $td = new cHTMLTableData();
224: $td->setContent(i18n('Action'));
225: $tr->appendContent($td);
226: $td = new cHTMLTableData();
227: $link = new cHTMLLink('javascript:void(0)');
228: $link->setClass('con_deletemails');
229: $link->setEvent('click', 'Con.showConfirmation("' . i18n('Do you really want to delete this email?') . '", function() { deleteEmails(' . $idmail . '); });return false;');
230: $image = new cHTMLImage('images/delete.gif');
231: $image->setAlt(i18n('Delete emails'));
232: $link->setContent($image);
233: $td->setContent($link);
234: $tr->appendContent($td);
235: $table->appendContent($tr);
236: $page->appendContent($table);
237:
238:
239: $successTable = new cHTMLTable();
240: $successTable->setClass('generic');
241: $successTable->appendStyleDefinition('margin-top', '20px');
242:
243: $mailLogSuccessCollection = new cApiMailLogSuccessCollection();
244: $mailLogSuccessCollection->select('`idmail`=' . $idmail);
245: $tr = new cHTMLTableRow();
246: $th = new cHTMLTableHead();
247: $th->setContent(i18n('Recipient'));
248: $tr->appendContent($th);
249: $th = new cHTMLTableHead();
250: $th->setContent(i18n('Status'));
251: $tr->appendContent($th);
252: $successTable->appendContent($tr);
253:
254:
255: while (($mailSuccessItem = $mailLogSuccessCollection->next()) !== false) {
256: $tr = new cHTMLTableRow();
257: $td = new cHTMLTableData();
258: $td->setContent(mailLogDecodeAddresses($mailSuccessItem->get('recipient')));
259: $tr->appendContent($td);
260: $td = new cHTMLTableData();
261: if ($mailSuccessItem->get('success')) {
262:
263: $image = new cHTMLImage('images/but_ok.gif');
264: $image->appendStyleDefinition('display', 'block');
265: $image->appendStyleDefinition('margin', '0 auto');
266: $image->appendStyleDefinition('padding', '3px');
267: $image->setAlt(i18n('Mail sent successfully!'));
268: $td->setContent($image);
269: } else {
270:
271: $link = new cHTMLLink('javascript:void(0)');
272: $link->setEvent('click', 'resendEmail(' . $mailSuccessItem->get('idmailsuccess') . ')');
273: $link->setAlt(i18n('Resend email'));
274: $image = new cHTMLImage('images/but_refresh.gif');
275: $image->appendStyleDefinition('display', 'block');
276: $image->appendStyleDefinition('margin', '0 auto');
277: $image->appendStyleDefinition('padding', '3px');
278: $link->setContent($image);
279: $td->setContent($link);
280: }
281: $tr->appendContent($td);
282: $successTable->appendContent($tr);
283: }
284: $page->appendContent($successTable);
285: } else {
286:
287: $contenidoNotification = new cGuiNotification();
288: $contenidoNotification->displayNotification('error', i18n('No item selected!'));
289: }
290: }
291:
292: $page->render();
293:
294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306:
307: function mailLogDecodeAddresses($addresses) {
308: $result = '';
309: $addresses = json_decode($addresses, true);
310: if (!is_array($addresses)) {
311: return "";
312: }
313: foreach ($addresses as $mail => $name) {
314: $result .= $name . ' <' . $mail . '><br>';
315: }
316: $result = cString::getPartOfString($result, 0, cString::getStringLength($result) - 4);
317:
318: return $result;
319: }
320:
321: 322: 323: 324: 325: 326:
327: function mailLogBulkEditingFunctions() {
328:
329: $table = new cHTMLTable();
330: $table->setClass('generic');
331: $table->setWidth('100%');
332: $table->appendStyleDefinition('margin', '10px 0');
333:
334: $tr = new cHTMLTableRow();
335:
336: $th = new cHTMLTableHead();
337: $th->appendStyleDefinition('border-bottom', '1px solid #B3B3B3');
338:
339:
340: $link = new cHTMLLink();
341: $link->setClass('flip_mark');
342: $image = new cHTMLImage('images/but_invert_selection.gif');
343: $image->setAlt(i18n('Flip Selection'));
344: $link->appendContent($image);
345: $link->appendContent(' ' . i18n('Flip Selection'));
346: $th->appendContent($link);
347:
348:
349: $link = new cHTMLLink('javascript:void(0)');
350: $link->setClass('con_deletemails');
351: $link->setEvent('click', 'Con.showConfirmation("' . i18n('Do you really want to delete the selected emails?') . '", deleteEmails);return false;');
352: $image = new cHTMLImage('images/delete.gif');
353: $image->setAlt(i18n('Delete emails'));
354: $link->setContent($image);
355: $div = new cHTMLDiv(i18n('Apply to all selected emails:'), 'bulk_editing_functions');
356: $div->appendContent($link);
357: $th->appendContent($div);
358:
359: $tr->setContent($th);
360: $table->setContent($tr);
361:
362: return $table;
363:
364: }
365: