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