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