ILIAS  Release_4_2_x_branch Revision 61807
 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(1);
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  $cron_mail = new ilSelectInputGUI($this->lng->txt('cron_mail_notification'), 'mail_notification');
124  $cron_options = array(
125  0 => $this->lng->txt('cron_mail_notification_never'),
126  1 => $this->lng->txt('cron_mail_notification_cron')
127  );
128 
129  $cron_mail->setOptions($cron_options);
130  $cron_mail->setInfo($this->lng->txt('cron_mail_notification_desc'));
131  $this->form->addItem($cron_mail);
132 
133  // section header
134  $sh = new ilFormSectionHeaderGUI();
135  $sh->setTitle($this->lng->txt('mail').' ('.$this->lng->txt('internal_system').')');
136  $this->form->addItem($sh);
137 
138  // max attachment size
139  $ti = new ilTextInputGUI($this->lng->txt('mail_maxsize_attach'), 'mail_maxsize_attach');
140  $ti->setInfo($this->lng->txt('kb'));
141  $ti->setMaxLength(10);
142  $ti->setSize(10);
143  $this->form->addItem($ti);
144 
145  // Course/Group member notification
146  $mn = new ilFormSectionHeaderGUI();
147  $mn->setTitle($this->lng->txt('mail_member_notification'));
148  $this->form->addItem($mn);
149 
150  // Course member notification
151  $cn = new ilCheckboxInputGUI($this->lng->txt('mail_enable_crs_member_notification'), 'mail_crs_member_notification');
152  $cn->setInfo($this->lng->txt('mail_enable_crs_member_notification_info'));
153  $this->form->addItem($cn);
154 
155  // Group member notification
156  $gn = new ilCheckboxInputGUI($this->lng->txt('mail_enable_grp_member_notification'), 'mail_grp_member_notification');
157  $gn->setInfo($this->lng->txt('mail_enable_grp_member_notification_info'));
158  $this->form->addItem($gn);
159 
160  $this->form->addCommandButton('save', $this->lng->txt('save'));
161  }
162 
163  private function setDefaultValues()
164  {
165  $settings = $this->ilias->getAllSettings();
166  $is_pear_mail_installed = @include_once 'Mail/RFC822.php';
167 
168  $this->form->setValuesByArray(array(
169  'mail_subject_prefix' => $settings['mail_subject_prefix'] ? $settings['mail_subject_prefix'] : '[ILIAS]',
170  'mail_incoming_mail' => (int)$settings['mail_incoming_mail'],
171  'pear_mail_enable' => ($settings['pear_mail_enable'] && $is_pear_mail_installed) ? true : false,
172  'mail_external_sender_noreply' => $settings['mail_external_sender_noreply'],
173  'prevent_smtp_globally' => ($settings['prevent_smtp_globally'] == '1') ? true : false,
174  'mail_maxsize_attach' => $settings['mail_maxsize_attach'],
175  'mail_notification' => $settings['mail_notification'],
176  'mail_crs_member_notification' => isset($settings['mail_crs_member_notification']) ? $settings['mail_crs_member_notification'] : 1,
177  'mail_grp_member_notification' => isset($settings['mail_grp_member_notification']) ? $settings['mail_grp_member_notification'] : 1
178  ));
179  }
180 
181  public function saveObject()
182  {
183  global $ilAccess,$ilSetting;
184 
185  if(!$ilAccess->checkAccess('write,read', '', $this->object->getRefId()))
186  {
187  $this->ilias->raiseError($this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->WARNING);
188  }
189 
190  $this->initForm();
191  if($this->form->checkInput())
192  {
193  $this->ilias->setSetting('mail_subject_prefix',$this->form->getInput('mail_subject_prefix'));
194  $this->ilias->setSetting('mail_incoming_mail', (int)$this->form->getInput('mail_incoming_mail'));
195  $this->ilias->setSetting('mail_maxsize_attach', $this->form->getInput('mail_maxsize_attach'));
196  $this->ilias->setSetting('pear_mail_enable', (int)$this->form->getInput('pear_mail_enable'));
197  $this->ilias->setSetting('mail_external_sender_noreply', $this->form->getInput('mail_external_sender_noreply'));
198  $this->ilias->setSetting('prevent_smtp_globally', (int)$this->form->getInput('prevent_smtp_globally'));
199  $this->ilias->setSetting('mail_notification', (int)$this->form->getInput('mail_notification'));
200  $ilSetting->set('mail_crs_member_notification', (int) $this->form->getInput('mail_crs_member_notification'));
201  $ilSetting->set('mail_grp_member_notification', (int) $this->form->getInput('mail_grp_member_notification'));
202 
203  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
204  }
205  $this->form->setValuesByPost();
206 
207  $this->tpl->setContent($this->form->getHTML());
208  }
209 
210  function importObject()
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->getTemplateFile("import");
219  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_import.html", "Services/Mail");
220 
221  // GET ALREADY CREATED UPLOADED XML FILE
222  $this->__initFileObject();
223  if($this->file_obj->findXMLFile())
224  {
225  $this->tpl->setVariable("TXT_IMPORTED_FILE",$lng->txt("checked_files"));
226  $this->tpl->setVariable("XML_FILE",basename($this->file_obj->getXMLFile()));
227 
228  $this->tpl->setVariable("BTN_IMPORT",$this->lng->txt("import"));
229  }
230 
231  $this->tpl->setVariable("FORMACTION",
232  $this->ctrl->getFormAction($this));
233  $this->tpl->setVariable("TXT_IMPORT_MAIL",$this->lng->txt("table_mail_import"));
234  $this->tpl->setVariable("TXT_IMPORT_FILE",$this->lng->txt("mail_import_file"));
235  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
236  $this->tpl->setVariable("BTN_UPLOAD",$this->lng->txt("upload"));
237 
238  return true;
239  }
240 
242  {
243  global $rbacsystem,$lng;
244 
245  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
246  {
247  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
248  }
249  $this->__initFileObject();
250  $this->file_obj->findXMLFile();
251  $this->__initParserObject($this->file_obj->getXMLFile(),"import");
252  $this->parser_obj->startParsing();
253  $number = $this->parser_obj->getCountImported();
254  ilUtil::sendInfo($lng->txt("import_finished")." ".$number,true);
255 
256  $this->ctrl->redirect($this, "import");
257  }
258 
259 
260 
261  function uploadObject()
262  {
263  global $rbacsystem,$lng;
264 
265  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
266  {
267  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
268  }
269 
270  $this->__initFileObject();
271  if(!$this->file_obj->storeUploadedFile($_FILES["importFile"])) // STEP 1 save file in ...import/mail
272  {
273  $this->message = $lng->txt("import_file_not_valid");
274  $this->file_obj->unlinkLast();
275  }
276  else if(!$this->file_obj->unzip())
277  {
278  $this->message = $lng->txt("cannot_unzip_file"); // STEP 2 unzip uplaoded file
279  $this->file_obj->unlinkLast();
280  }
281  else if(!$this->file_obj->findXMLFile()) // STEP 3 getXMLFile
282  {
283  $this->message = $lng->txt("cannot_find_xml");
284  $this->file_obj->unlinkLast();
285  }
286  else if(!$this->__initParserObject($this->file_obj->getXMLFile(),"check"))
287  {
288  $this->message = $lng->txt("error_parser"); // STEP 4 init sax parser
289  }
290  else if(!$this->parser_obj->startParsing())
291  {
292  $this->message = $lng->txt("users_not_imported").":<br/>"; // STEP 5 start parsing
293  $this->message .= $this->parser_obj->getNotAssignableUsers();
294  }
295  // FINALLY CHECK ERROR
296  if(!$this->message)
297  {
298  $this->message = $lng->txt("uploaded_and_checked");
299  }
300  ilUtil::sendInfo($this->message,true);
301 
302  $this->ctrl->redirect($this, "import");
303  }
304 
305  // PRIVATE
306  function __initFileObject()
307  {
308  include_once "./classes/class.ilFileDataImportMail.php";
309 
310  $this->file_obj =& new ilFileDataImportMail();
311 
312  return true;
313  }
314  function __initParserObject($a_xml,$a_mode)
315  {
316  include_once "Services/Mail/classes/class.ilMailImportParser.php";
317 
318  if(!$a_xml)
319  {
320  return false;
321  }
322 
323  $this->parser_obj =& new ilMailImportParser($a_xml,$a_mode);
324 
325  return true;
326  }
327 
328  function &executeCommand()
329  {
330  $next_class = $this->ctrl->getNextClass($this);
331  $cmd = $this->ctrl->getCmd();
332  $this->prepareOutput();
333 
334  switch($next_class)
335  {
336  case 'ilpermissiongui':
337  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
338  $perm_gui =& new ilPermissionGUI($this);
339  $ret =& $this->ctrl->forwardCommand($perm_gui);
340  break;
341 
342  default:
343  if(!$cmd)
344  {
345  $cmd = "view";
346  }
347  $cmd .= "Object";
348  $this->$cmd();
349 
350  break;
351  }
352  return true;
353  }
354 
355  function getAdminTabs(&$tabs_gui)
356  {
357  $this->getTabs($tabs_gui);
358  }
359 
365  function getTabs(&$tabs_gui)
366  {
367  global $rbacsystem;
368 
369  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
370  {
371  $tabs_gui->addTarget("settings",
372  $this->ctrl->getLinkTarget($this, "view"), array("view", 'save', ""), "", "");
373  }
374 
375  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
376  {
377  $tabs_gui->addTarget("perm_settings",
378  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
379  }
380  }
381 
385  function _goto($a_target)
386  {
387  global $ilAccess, $ilErr, $lng, $rbacsystem;
388 
389  require_once 'Services/Mail/classes/class.ilMail.php';
390  $mail = new ilMail($_SESSION["AccountId"]);
391  if($rbacsystem->checkAccess('mail_visible', $mail->getMailObjectReferenceId()))
392  {
393  ilUtil::redirect("ilias.php?baseClass=ilMailGUI");
394  exit;
395  }
396  else
397  {
398  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
399  {
400  $_GET["cmd"] = "frameset";
401  $_GET["target"] = "";
402  $_GET["ref_id"] = ROOT_FOLDER_ID;
403  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
405  include("repository.php");
406  exit;
407  }
408  }
409  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
410  }
411 
412 } // END class.ilObjMailGUI
413 ?>