source: trunk/Modules/EmailQueue/EmailQueue.php@ 689

Last change on this file since 689 was 689, checked in by chronos, 11 years ago
  • Opraveno: Zobrazení stavu placení u Subjektů v ISu.
  • Přidáno: Výchozí řazení u fronty emailů podle času.
File size: 3.9 KB
RevLine 
[532]1<?php
[553]2
3class PageEmailQueueProcess extends Page
4{
5 var $FullTitle = 'Odeslání pošty z fronty';
6 var $ShortTitle = 'Fronta pošty';
7 var $ParentClass = 'PagePortal';
[689]8
[553]9 function Show()
10 {
[563]11 $Output = $this->System->ModuleManager->Modules['EmailQueue']->Process();
[553]12 $Output = $this->SystemMessage('Zpracování fronty emailů', 'Nové emaily byly odeslány').$Output;
13 return($Output);
[689]14 }
[553]15}
[689]16
[553]17class ModuleEmailQueue extends AppModule
18{
19 function __construct($System)
20 {
21 parent::__construct($System);
22 $this->Name = 'EmailQueue';
23 $this->Version = '1.0';
24 $this->Creator = 'Chronos';
25 $this->License = 'GNU/GPLv3';
26 $this->Description = 'Queue for delayed email sending and history';
27 $this->Dependencies = array('Log');
28 }
29
[586]30 function DoInstall()
[553]31 {
32 }
33
[593]34 function DoUninstall()
[553]35 {
36 }
37
[586]38 function DoStart()
[689]39 {
[553]40 $this->System->RegisterPage('fronta-posty', 'PageEmailQueueProcess');
41 $this->System->FormManager->RegisterClass('Email', array(
42 'Title' => 'Nový email',
43 'Table' => 'EmailQueue',
44 'SubmitText' => 'Odeslat',
45 'Items' => array(
46 'Address' => array('Type' => 'String', 'Caption' => 'Adresa', 'Default' => ''),
47 'Subject' => array('Type' => 'String', 'Caption' => 'Předmět', 'Default' => ''),
48 'Content' => array('Type' => 'Text', 'Caption' => 'Obsah', 'Default' => ''),
49 ),
50 ));
51 $this->System->FormManager->RegisterClass('EmailQueue', array(
52 'Title' => 'Fronta e-mailů',
[689]53 'Table' => 'EmailQueue',
54 'DefaultSortColumn' => 'Time',
55 'DefaultSortOrder' => 1,
[553]56 'Items' => array(
57 'Time' => array('Type' => 'DateTime', 'Caption' => 'Vytvořeno'),
58 'To' => array('Type' => 'String', 'Caption' => 'Příjemce', 'Default' => ''),
59 'Subject' => array('Type' => 'String', 'Caption' => 'Předmět', 'Default' => ''),
60 'Content' => array('Type' => 'Text', 'Caption' => 'Obsah', 'Default' => ''),
61 'Headers' => array('Type' => 'String', 'Caption' => 'Hlavička', 'Default' => ''),
62 'Archive' => array('Type' => 'Boolean', 'Caption' => 'Odesláno', 'Default' => '0'),
63 'From' => array('Type' => 'String', 'Caption' => 'Odesílatel', 'Default' => ''),
64 'AttachmentFile' => array('Type' => 'TFile', 'Caption' => 'Příloha', 'Default' => '', 'Null' => true),
65 ),
66 'Actions' => array(
67 array('Caption' => 'Odeslat nové', 'URL' => '/fronta-posty/'),
68 ),
[689]69 ));
[553]70 }
71
[586]72 function DoStop()
[553]73 {
74 }
75
[532]76 function AddItem($To, $Subject, $Content, $From, $AttachmentFileId = '')
77 {
[689]78 $Values = array('To' => $To,
79 'Subject' => $Subject, 'Content' => $Content, 'Time' => 'NOW()',
[532]80 'From' => $From);
81 if($AttachmentFileId != '') $Values['AttachmentFile'] = $AttachmentFileId;
82 $this->Database->insert('EmailQueue', $Values);
[526]83 }
[689]84
[532]85 function Process()
86 {
87 $Output = '';
88 $DbResult = $this->Database->select('EmailQueue', '*', 'Archive=0');
89 while($DbRow = $DbResult->fetch_assoc())
[689]90 {
[532]91 $Mail = new Mail();
92 $Mail->AddToCombined($DbRow['To']);
93 $Mail->Subject = $DbRow['Subject'];
94 $Mail->From = $DbRow['From'];
95 $Mail->AddBody(strip_tags($DbRow['Content']), 'text/plain');
96 $Mail->AddBody($DbRow['Content'], 'text/html');
97 if($DbRow['AttachmentFile'] != '')
98 {
99 $DbResult2 = $this->Database->select('File', '*', 'Id='.$DbRow['AttachmentFile']);
100 while($File = $DbResult2->fetch_assoc())
101 $Mail->AttachFile($this->Config['Web']['FileRootFolder'].$File['DrivePath'], $File['MimeType']);
102 }
103 $Mail->Send();
104 $this->Database->update('EmailQueue', 'Id='.$DbRow['Id'], array('Archive' => 1));
[553]105 $this->System->ModuleManager->Modules['Log']->NewRecord('System', 'SendEmail', $DbRow['Id']);
[532]106 $Output .= 'To: '.$DbRow['To'].' Subject: '.$DbRow['Subject'].'<br />';
[689]107 }
[532]108 return($Output);
109 }
[553]110}
111
Note: See TracBrowser for help on using the repository browser.