ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjMailGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 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 "./classes/class.ilObjectGUI.php";
25 
38 {
43  public function __construct($a_data,$a_id,$a_call_by_reference)
44  {
45  $this->type = 'mail';
46  parent::__construct($a_data,$a_id,$a_call_by_reference, false);
47 
48  $this->lng->loadLanguageModule('mail');
49  }
50 
51  public function viewObject()
52  {
53  global $ilAccess;
54 
55  if(!$ilAccess->checkAccess('write,read', '', $this->object->getRefId()))
56  {
57  $this->ilias->raiseError($this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->WARNING);
58  }
59 
60  $this->initForm();
61  $this->setDefaultValues();
62  $this->tpl->setContent($this->form->getHTML());
63  }
64 
65  private function initForm()
66  {
67  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
68  $this->form = new ilPropertyFormGUI();
69 
70  $this->form->setFormAction($this->ctrl->getFormAction($this, 'save'));
71  $this->form->setTitle($this->lng->txt('general_settings'));
72 
73  // Subject prefix
74  $pre = new ilTextInputGUI($this->lng->txt('mail_subject_prefix'),'mail_subject_prefix');
75  $pre->setSize(12);
76  $pre->setMaxLength(32);
77  $pre->setInfo($this->lng->txt('mail_subject_prefix_info'));
78  $this->form->addItem($pre);
79 
80  // incoming type
81  include_once 'Services/Mail/classes/class.ilMailOptions.php';
82  $options = array(
83  IL_MAIL_LOCAL => $this->lng->txt('mail_incoming_local'),
84  IL_MAIL_EMAIL => $this->lng->txt('mail_incoming_smtp'),
85  IL_MAIL_BOTH => $this->lng->txt('mail_incoming_both')
86  );
87  $si = new ilSelectInputGUI($this->lng->txt('mail_incoming'), 'mail_incoming_mail');
88  $si->setOptions($options);
89  $this->ctrl->setParameterByClass('ilobjuserfoldergui', 'ref_id', USER_FOLDER_ID);
90  $si->setInfo(sprintf($this->lng->txt('mail_settings_incoming_type_see_also'), $this->ctrl->getLinkTargetByClass('ilobjuserfoldergui', 'settings')));
91  $this->ctrl->clearParametersByClass('ilobjuserfoldergui');
92  $this->form->addItem($si);
93 
94  // noreply address
95  $ti = new ilTextInputGUI($this->lng->txt('mail_external_sender_noreply'), 'mail_external_sender_noreply');
96  $ti->setInfo($this->lng->txt('info_mail_external_sender_noreply'));
97  $ti->setMaxLength(255);
98  $this->form->addItem($ti);
99 
100  // Pear Mail extension
101  // Note: We use the include statement to determine whether PEAR MAIL is
102  // installed. We use the @ operator to prevent PHP from issuing a
103  // warning while we test for PEAR MAIL.
104  $is_pear_mail_installed = @include_once 'Mail/RFC822.php';
105  $cb = new ilCheckboxInputGUI($this->lng->txt('mail_use_pear_mail'), 'pear_mail_enable');
106  if($is_pear_mail_installed)
107  {
108  $cb->setInfo($this->lng->txt('mail_use_pear_mail_info'));
109  }
110  else
111  {
112  $cb->setInfo($this->lng->txt('mail_use_pear_mail_info').' '.
113  $this->lng->txt('mail_pear_mail_needed'));
114  }
115  $cb->setValue('y');
116  $this->form->addItem($cb);
117 
118  // prevent smtp mails
119  $cb = new ilCheckboxInputGUI($this->lng->txt('mail_prevent_smtp_globally'), 'prevent_smtp_globally');
120  $cb->setValue(1);
121  $this->form->addItem($cb);
122 
123  // section header
124  $sh = new ilFormSectionHeaderGUI();
125  $sh->setTitle($this->lng->txt('mail').' ('.$this->lng->txt('internal_system').')');
126  $this->form->addItem($sh);
127 
128  // max attachment size
129  $ti = new ilTextInputGUI($this->lng->txt('mail_maxsize_attach'), 'mail_maxsize_attach');
130  $ti->setInfo($this->lng->txt('kb'));
131  $ti->setMaxLength(10);
132  $ti->setSize(10);
133  $this->form->addItem($ti);
134 
135  $this->form->addCommandButton('save', $this->lng->txt('save'));
136  }
137 
138  private function setDefaultValues()
139  {
140  $settings = $this->ilias->getAllSettings();
141  $is_pear_mail_installed = @include_once 'Mail/RFC822.php';
142 
143  $this->form->setValuesByArray(array(
144  'mail_subject_prefix' => $settings['mail_subject_prefix'] ? $settings['mail_subject_prefix'] : '[ILIAS]',
145  'mail_incoming_mail' => (int)$settings['mail_incoming_mail'],
146  'pear_mail_enable' => ($settings['pear_mail_enable'] == 'y' && $is_pear_mail_installed) ? true : false,
147  'mail_external_sender_noreply' => $settings['mail_external_sender_noreply'],
148  'prevent_smtp_globally' => ($settings['prevent_smtp_globally'] == '1') ? true : false,
149  'mail_maxsize_attach' => $settings['mail_maxsize_attach']
150  ));
151  }
152 
153  public function saveObject()
154  {
155  global $ilAccess;
156 
157  if(!$ilAccess->checkAccess('write,read', '', $this->object->getRefId()))
158  {
159  $this->ilias->raiseError($this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->WARNING);
160  }
161 
162  $this->initForm();
163  if($this->form->checkInput())
164  {
165  $this->ilias->setSetting('mail_subject_prefix',$this->form->getInput('mail_subject_prefix'));
166  $this->ilias->setSetting('mail_incoming_mail', (int)$this->form->getInput('mail_incoming_mail'));
167  $this->ilias->setSetting('mail_maxsize_attach', $this->form->getInput('mail_maxsize_attach'));
168  $this->ilias->setSetting('pear_mail_enable', $this->form->getInput('pear_mail_enable'));
169  $this->ilias->setSetting('mail_external_sender_noreply', $this->form->getInput('mail_external_sender_noreply'));
170  $this->ilias->setSetting('prevent_smtp_globally', (int)$this->form->getInput('prevent_smtp_globally'));
171 
172  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
173  }
174  $this->form->setValuesByPost();
175 
176  $this->tpl->setContent($this->form->getHTML());
177  }
178 
179  function importObject()
180  {
181  global $rbacsystem,$lng;
182 
183  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
184  {
185  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
186  }
187  #$this->getTemplateFile("import");
188  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_import.html", "Services/Mail");
189 
190  // GET ALREADY CREATED UPLOADED XML FILE
191  $this->__initFileObject();
192  if($this->file_obj->findXMLFile())
193  {
194  $this->tpl->setVariable("TXT_IMPORTED_FILE",$lng->txt("checked_files"));
195  $this->tpl->setVariable("XML_FILE",basename($this->file_obj->getXMLFile()));
196 
197  $this->tpl->setVariable("BTN_IMPORT",$this->lng->txt("import"));
198  }
199 
200  $this->tpl->setVariable("FORMACTION",
201  $this->ctrl->getFormAction($this));
202  $this->tpl->setVariable("TXT_IMPORT_MAIL",$this->lng->txt("table_mail_import"));
203  $this->tpl->setVariable("TXT_IMPORT_FILE",$this->lng->txt("mail_import_file"));
204  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
205  $this->tpl->setVariable("BTN_UPLOAD",$this->lng->txt("upload"));
206 
207  return true;
208  }
209 
211  {
212  global $rbacsystem,$lng;
213 
214  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
215  {
216  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
217  }
218  $this->__initFileObject();
219  $this->file_obj->findXMLFile();
220  $this->__initParserObject($this->file_obj->getXMLFile(),"import");
221  $this->parser_obj->startParsing();
222  $number = $this->parser_obj->getCountImported();
223  ilUtil::sendInfo($lng->txt("import_finished")." ".$number,true);
224 
225  $this->ctrl->redirect($this, "import");
226  }
227 
228 
229 
230  function uploadObject()
231  {
232  global $rbacsystem,$lng;
233 
234  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
235  {
236  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
237  }
238 
239  $this->__initFileObject();
240  if(!$this->file_obj->storeUploadedFile($_FILES["importFile"])) // STEP 1 save file in ...import/mail
241  {
242  $this->message = $lng->txt("import_file_not_valid");
243  $this->file_obj->unlinkLast();
244  }
245  else if(!$this->file_obj->unzip())
246  {
247  $this->message = $lng->txt("cannot_unzip_file"); // STEP 2 unzip uplaoded file
248  $this->file_obj->unlinkLast();
249  }
250  else if(!$this->file_obj->findXMLFile()) // STEP 3 getXMLFile
251  {
252  $this->message = $lng->txt("cannot_find_xml");
253  $this->file_obj->unlinkLast();
254  }
255  else if(!$this->__initParserObject($this->file_obj->getXMLFile(),"check"))
256  {
257  $this->message = $lng->txt("error_parser"); // STEP 4 init sax parser
258  }
259  else if(!$this->parser_obj->startParsing())
260  {
261  $this->message = $lng->txt("users_not_imported").":<br/>"; // STEP 5 start parsing
262  $this->message .= $this->parser_obj->getNotAssignableUsers();
263  }
264  // FINALLY CHECK ERROR
265  if(!$this->message)
266  {
267  $this->message = $lng->txt("uploaded_and_checked");
268  }
269  ilUtil::sendInfo($this->message,true);
270 
271  $this->ctrl->redirect($this, "import");
272  }
273 
274  // PRIVATE
275  function __initFileObject()
276  {
277  include_once "./classes/class.ilFileDataImportMail.php";
278 
279  $this->file_obj =& new ilFileDataImportMail();
280 
281  return true;
282  }
283  function __initParserObject($a_xml,$a_mode)
284  {
285  include_once "Services/Mail/classes/class.ilMailImportParser.php";
286 
287  if(!$a_xml)
288  {
289  return false;
290  }
291 
292  $this->parser_obj =& new ilMailImportParser($a_xml,$a_mode);
293 
294  return true;
295  }
296 
297  function &executeCommand()
298  {
299  $next_class = $this->ctrl->getNextClass($this);
300  $cmd = $this->ctrl->getCmd();
301  $this->prepareOutput();
302 
303  switch($next_class)
304  {
305  case 'ilpermissiongui':
306  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
307  $perm_gui =& new ilPermissionGUI($this);
308  $ret =& $this->ctrl->forwardCommand($perm_gui);
309  break;
310 
311  default:
312  if(!$cmd)
313  {
314  $cmd = "view";
315  }
316  $cmd .= "Object";
317  $this->$cmd();
318 
319  break;
320  }
321  return true;
322  }
323 
324  function getAdminTabs(&$tabs_gui)
325  {
326  $this->getTabs($tabs_gui);
327  }
328 
334  function getTabs(&$tabs_gui)
335  {
336  global $rbacsystem;
337 
338  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
339  {
340  $tabs_gui->addTarget("settings",
341  $this->ctrl->getLinkTarget($this, "view"), array("view", 'save', ""), "", "");
342  }
343 
344  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
345  {
346  $tabs_gui->addTarget("perm_settings",
347  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
348  }
349  }
350 
354  function _goto()
355  {
356  global $ilAccess, $ilErr, $lng, $rbacsystem;
357 
358 
359  $mail = new ilMail($_SESSION["AccountId"]);
360  if($rbacsystem->checkAccess('mail_visible', $mail->getMailObjectReferenceId()))
361  {
362  ilUtil::redirect("ilias.php?baseClass=ilMailGUI");
363  exit;
364  }
365  else
366  {
367  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
368  {
369  $_GET["cmd"] = "frameset";
370  $_GET["target"] = "";
371  $_GET["ref_id"] = ROOT_FOLDER_ID;
372  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
374  include("repository.php");
375  exit;
376  }
377  }
378  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
379  }
380 
381 } // END class.ilObjMailGUI
382 ?>