ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailAttachmentGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once "Services/Mail/classes/class.ilFormatMail.php";
25 require_once "classes/class.ilFileDataMail.php";
26 
34 {
35  private $tpl = null;
36  private $ctrl = null;
37  private $lng = null;
38 
39  private $umail = null;
40  private $mfile = null;
41 
42  private $errorDelete = false;
43 
44  public function __construct()
45  {
46  global $tpl, $ilCtrl, $lng, $ilUser;
47 
48  $this->tpl = $tpl;
49  $this->ctrl = $ilCtrl;
50  $this->lng = $lng;
51 
52  $this->ctrl->saveParameter($this, "mobj_id");
53 
54  $this->umail = new ilFormatMail($ilUser->getId());
55  $this->mfile = new ilFileDataMail($ilUser->getId());
56  }
57 
58  public function executeCommand()
59  {
60  $forward_class = $this->ctrl->getNextClass($this);
61  switch($forward_class)
62  {
63  default:
64  if (!($cmd = $this->ctrl->getCmd()))
65  {
66  $cmd = "showAttachments";
67  }
68 
69  $this->$cmd();
70  break;
71  }
72  return true;
73  }
74 
75  public function saveAttachments()
76  {
77  global $ilUser;
78 
79  $files = array();
80 
81  if(is_array($_POST['filename']) && count($_POST['filename']))
82  {
83  foreach($_POST['filename'] as $file)
84  {
85  // decode post value
86  if(file_exists($this->mfile->getMailPath().'/'.basename($ilUser->getId().'_'.urldecode($file))))
87  {
88  $files[] = urldecode($file);
89  }
90  }
91  }
92 
93  $this->umail->saveAttachments($files);
94 
95  $this->ctrl->returnToParent($this);
96  }
97 
98  public function cancelSaveAttachments()
99  {
100  $this->ctrl->setParameter($this, "type", "attach");
101  $this->ctrl->returnToParent($this);
102  }
103 
104  public function deleteAttachments()
105  {
106  if(!is_array($_POST["filename"]))
107  {
108  ilUtil::sendInfo($this->lng->txt("mail_select_one_file"));
109  $this->errorDelete = true;
110  }
111  else
112  {
113  ilUtil::sendInfo($this->lng->txt("mail_sure_delete_file"));
114  }
115 
116  $this->showAttachments();
117  }
118 
119  public function confirmDeleteAttachments()
120  {
121  if(!is_array($_POST['filename']))
122  {
123  ilUtil::sendInfo($this->lng->txt('mail_select_one_mail'));
124  }
125 
126  // decode post values
127  $files = array();
128  foreach($_POST['filename'] as $value)
129  {
130  $files[] = urldecode($value);
131  }
132 
133  if(strlen(($error = $this->mfile->unlinkFiles($files))))
134  {
135  ilUtil::sendInfo($this->lng->txt('mail_error_delete_file').' '.$error);
136  }
137  else
138  {
139  $mailData = $this->umail->getSavedData();
140  if (is_array($mailData['attachments']))
141  {
142  $tmp = array();
143  for ($i = 0; $i < count($mailData['attachments']); $i++)
144  {
145  if (!in_array($mailData['attachments'][$i], $files))
146  {
147  $tmp[] = $mailData['attachments'][$i];
148  }
149  }
150  $mailData['attachments'] = $tmp;
151  $this->umail->saveAttachments($tmp);
152  }
153 
154  ilUtil::sendInfo($this->lng->txt('mail_files_deleted'));
155  }
156 
157  $this->showAttachments();
158  }
159 
160  public function cancelDeleteAttachments()
161  {
162  $this->showAttachments();
163  }
164 
165  public function uploadFile()
166  {
167  if (trim($_FILES["userfile"]["name"]) != "")
168  {
169  if($this->mfile->storeUploadedFile($_FILES["userfile"]) == 1)
170  {
171  ilUtil::sendInfo($this->lng->txt("mail_maxsize_attachment_error")." ".$this->mfile->getUploadLimit()." K".$this->lng->txt("mail_byte"));
172  }
173  }
174 
175  $this->showAttachments();
176  }
177 
178  public function showAttachments()
179  {
180  global $rbacsystem;
181 
182  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_attachment.html", "Services/Mail");
183  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
184  $this->tpl->setVariable("TXT_ATTACHMENT",$this->lng->txt("attachment"));
185 
186  $mailData = $this->umail->getSavedData();
187 
188  $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this, 'saveAttachments'));
189  $this->tpl->setVariable("UPLOAD", $this->ctrl->getFormAction($this, 'uploadFile'));
190  $this->ctrl->clearParameters($this);
191 
192  // BEGIN CONFIRM_DELETE
193  if (isset($_POST["cmd"]["deleteAttachments"]) &&
194  !$this->errorDelete &&
195  !isset($_POST["cmd"]["confirm"]))
196  {
197  $this->tpl->setCurrentBlock("confirm_delete");
198  $this->tpl->setVariable("BUTTON_CONFIRM",$this->lng->txt("confirm"));
199  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
200  $this->tpl->parseCurrentBlock();
201  }
202 
203  // SET STATIC VARIABLES ;-)
204  $this->tpl->setVariable("TXT_ATTACHMENT",$this->lng->txt("attachment"));
205  $this->tpl->setVariable("TXT_FILENAME",$this->lng->txt("mail_file_name"));
206  $this->tpl->setVariable("TXT_FILESIZE",$this->lng->txt("mail_file_size"));
207  $this->tpl->setVariable("TXT_CREATE_TIME",$this->lng->txt("create_date"));
208  $this->tpl->setVariable("TXT_NEW_FILE",$this->lng->txt("mail_new_file"));
209 
210  // ACTIONS
211  $this->tpl->setVariable("BUTTON_ATTACHMENT_ADOPT",$this->lng->txt("adopt"));
212  $this->tpl->setVariable("BUTTON_ATTACHMENT_CANCEL",$this->lng->txt("cancel"));
213  $this->tpl->setVariable("BUTTON_ATTACHMENT_DELETE",$this->lng->txt("delete"));
214 
215  // BUTTONS
216  $this->tpl->setVariable("BUTTON_SUBMIT",$this->lng->txt("submit"));
217  $this->tpl->setVariable("BUTTON_UPLOAD",$this->lng->txt("upload"));
218 
219  // BEGIN FILES
220  if($files = $this->mfile->getUserFilesData())
221  {
222  $counter = 0;
223  foreach($files as $file)
224  {
225  $this->tpl->setCurrentBlock('files');
226  if((!isset($_POST["cmd"]["deleteAttachments"]) && is_array($mailData["attachments"]) && in_array($file["name"],$mailData["attachments"])) ||
227  (isset($_POST["cmd"]["deleteAttachments"]) && is_array($_POST["filename"]) && in_array(urlencode($file["name"]), $_POST["filename"])))
228  {
229  $this->tpl->setVariable("CHECKED",'checked');
230  }
231  $this->tpl->setVariable('CSSROW',++$counter%2 ? 'tblrow1' : 'tblrow2');
232  $this->tpl->setVariable('FILE_NAME',urlencode($file["name"]));
233  $this->tpl->setVariable("NAME",$file["name"]);
234  $this->tpl->setVariable("SIZE",$file["size"]);
235  $this->tpl->setVariable("CTIME",$file["ctime"]);
236  $this->tpl->parseCurrentBlock();
237  }
238  }
239  else
240  {
241  $this->tpl->setCurrentBlock("no_content");
242  $this->tpl->setVariable("TXT_ATTACHMENT_NO",$this->lng->txt("mail_no_attachments_found"));
243  $this->tpl->parseCurrentBlock();
244  }
245 
246  $this->tpl->setVariable("TXT_MARKED_ENTRIES",$this->lng->txt("marked_entries"));
247 
248  $this->tpl->show();
249  }
250 
251 }
252 
253 ?>