ILIAS  Release_3_10_x_branch Revision 61812
 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  if(file_exists($this->mfile->getMailPath().'/'.basename($ilUser->getId().'_'.$file)))
86  {
87  $files[] = $file;
88  }
89  }
90  }
91 
92  $this->umail->saveAttachments($files);
93 
94  $this->ctrl->returnToParent($this);
95  }
96 
97  public function cancelSaveAttachments()
98  {
99  $this->ctrl->setParameter($this, "type", "attach");
100  $this->ctrl->returnToParent($this);
101  }
102 
103  public function deleteAttachments()
104  {
105  if(!$_POST["filename"])
106  {
107  ilUtil::sendInfo($this->lng->txt("mail_select_one_file"));
108  $this->errorDelete = true;
109  }
110  else
111  {
112  ilUtil::sendInfo($this->lng->txt("mail_sure_delete_file"));
113  }
114 
115  $this->showAttachments();
116  }
117 
118  public function confirmDeleteAttachments()
119  {
120  if(!$_POST["filename"])
121  {
122  ilUtil::sendInfo($this->lng->txt("mail_select_one_mail"));
123  }
124  else if($error = $this->mfile->unlinkFiles($_POST["filename"]))
125  {
126  ilUtil::sendInfo($this->lng->txt("mail_error_delete_file")." ".$error);
127  }
128  else
129  {
130  $mailData = $this->umail->getSavedData();
131  if (is_array($mailData["attachments"]))
132  {
133  $tmp = array();
134  for ($i = 0; $i < count($mailData["attachments"]); $i++)
135  {
136  if (!in_array($mailData["attachments"][$i], $_POST["filename"]))
137  {
138  $tmp[] = $mailData["attachments"][$i];
139  }
140  }
141  $mailData["attachments"] = $tmp;
142  $this->umail->saveAttachments($tmp);
143  }
144 
145  ilUtil::sendInfo($this->lng->txt("mail_files_deleted"));
146  }
147 
148  $this->showAttachments();
149  }
150 
151  public function cancelDeleteAttachments()
152  {
153  $this->showAttachments();
154  }
155 
156  public function uploadFile()
157  {
158  if (trim($_FILES["userfile"]["name"]) != "")
159  {
160  if($this->mfile->storeUploadedFile($_FILES["userfile"]) == 1)
161  {
162  ilUtil::sendInfo($this->lng->txt("mail_maxsize_attachment_error")." ".$this->mfile->getUploadLimit()." K".$this->lng->txt("mail_byte"));
163  }
164  }
165 
166  $this->showAttachments();
167  }
168 
169  public function showAttachments()
170  {
171  global $rbacsystem;
172 
173  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_attachment.html", "Services/Mail");
174  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
175  $this->tpl->setVariable("TXT_ATTACHMENT",$this->lng->txt("attachment"));
176 
177  $mailData = $this->umail->getSavedData();
178 
179  $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this, 'saveAttachments'));
180  $this->tpl->setVariable("UPLOAD", $this->ctrl->getFormAction($this, 'uploadFile'));
181  $this->ctrl->clearParameters($this);
182 
183  // BEGIN CONFIRM_DELETE
184  if (isset($_POST["cmd"]["deleteAttachments"]) &&
185  !$this->errorDelete &&
186  !isset($_POST["cmd"]["confirm"]))
187  {
188  $this->tpl->setCurrentBlock("confirm_delete");
189  $this->tpl->setVariable("BUTTON_CONFIRM",$this->lng->txt("confirm"));
190  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
191  $this->tpl->parseCurrentBlock();
192  }
193 
194  // SET STATIC VARIABLES ;-)
195  $this->tpl->setVariable("TXT_ATTACHMENT",$this->lng->txt("attachment"));
196  $this->tpl->setVariable("TXT_FILENAME",$this->lng->txt("mail_file_name"));
197  $this->tpl->setVariable("TXT_FILESIZE",$this->lng->txt("mail_file_size"));
198  $this->tpl->setVariable("TXT_CREATE_TIME",$this->lng->txt("create_date"));
199  $this->tpl->setVariable("TXT_NEW_FILE",$this->lng->txt("mail_new_file"));
200 
201  // ACTIONS
202  $this->tpl->setVariable("BUTTON_ATTACHMENT_ADOPT",$this->lng->txt("adopt"));
203  $this->tpl->setVariable("BUTTON_ATTACHMENT_CANCEL",$this->lng->txt("cancel"));
204  $this->tpl->setVariable("BUTTON_ATTACHMENT_DELETE",$this->lng->txt("delete"));
205 
206  // BUTTONS
207  $this->tpl->setVariable("BUTTON_SUBMIT",$this->lng->txt("submit"));
208  $this->tpl->setVariable("BUTTON_UPLOAD",$this->lng->txt("upload"));
209 
210  // BEGIN FILES
211  if($files = $this->mfile->getUserFilesData())
212  {
213  $counter = 0;
214  foreach($files as $file)
215  {
216  $this->tpl->setCurrentBlock('files');
217  if((!isset($_POST["cmd"]["deleteAttachments"]) && is_array($mailData["attachments"]) && in_array($file["name"],$mailData["attachments"])) ||
218  (isset($_POST["cmd"]["deleteAttachments"]) && is_array($_POST["filename"]) && in_array($file["name"],$_POST["filename"])))
219  {
220  $this->tpl->setVariable("CHECKED",'checked');
221  }
222  $this->tpl->setVariable('CSSROW',++$counter%2 ? 'tblrow1' : 'tblrow2');
223  $this->tpl->setVariable('FILE_NAME',$file["name"]);
224  $this->tpl->setVariable("NAME",$file["name"]);
225  $this->tpl->setVariable("SIZE",$file["size"]);
226  $this->tpl->setVariable("CTIME",$file["ctime"]);
227  $this->tpl->parseCurrentBlock();
228  }
229  }
230  else
231  {
232  $this->tpl->setCurrentBlock("no_content");
233  $this->tpl->setVariable("TXT_ATTACHMENT_NO",$this->lng->txt("mail_no_attachments_found"));
234  $this->tpl->parseCurrentBlock();
235  }
236 
237  $this->tpl->setVariable("TXT_MARKED_ENTRIES",$this->lng->txt("marked_entries"));
238 
239  $this->tpl->show();
240  }
241 
242 }
243 
244 ?>