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
Line 
1<?php
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';
8
9 function Show()
10 {
11 $Output = $this->System->ModuleManager->Modules['EmailQueue']->Process();
12 $Output = $this->SystemMessage('Zpracování fronty emailů', 'Nové emaily byly odeslány').$Output;
13 return($Output);
14 }
15}
16
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
30 function DoInstall()
31 {
32 }
33
34 function DoUninstall()
35 {
36 }
37
38 function DoStart()
39 {
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ů',
53 'Table' => 'EmailQueue',
54 'DefaultSortColumn' => 'Time',
55 'DefaultSortOrder' => 1,
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 ),
69 ));
70 }
71
72 function DoStop()
73 {
74 }
75
76 function AddItem($To, $Subject, $Content, $From, $AttachmentFileId = '')
77 {
78 $Values = array('To' => $To,
79 'Subject' => $Subject, 'Content' => $Content, 'Time' => 'NOW()',
80 'From' => $From);
81 if($AttachmentFileId != '') $Values['AttachmentFile'] = $AttachmentFileId;
82 $this->Database->insert('EmailQueue', $Values);
83 }
84
85 function Process()
86 {
87 $Output = '';
88 $DbResult = $this->Database->select('EmailQueue', '*', 'Archive=0');
89 while($DbRow = $DbResult->fetch_assoc())
90 {
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));
105 $this->System->ModuleManager->Modules['Log']->NewRecord('System', 'SendEmail', $DbRow['Id']);
106 $Output .= 'To: '.$DbRow['To'].' Subject: '.$DbRow['Subject'].'<br />';
107 }
108 return($Output);
109 }
110}
111
Note: See TracBrowser for help on using the repository browser.