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