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