ILIAS  Release_4_0_x_branch Revision 61816
 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  // section header
119  $sh = new ilFormSectionHeaderGUI();
120  $sh->setTitle($this->lng->txt('mail').' ('.$this->lng->txt('internal_system').')');
121  $this->form->addItem($sh);
122 
123  // max attachment size
124  $ti = new ilTextInputGUI($this->lng->txt('mail_maxsize_attach'), 'mail_maxsize_attach');
125  $ti->setInfo($this->lng->txt('kb'));
126  $ti->setMaxLength(10);
127  $ti->setSize(10);
128  $this->form->addItem($ti);
129 
130  $this->form->addCommandButton('save', $this->lng->txt('save'));
131  }
132 
133  private function setDefaultValues()
134  {
135  $settings = $this->ilias->getAllSettings();
136  $is_pear_mail_installed = @include_once 'Mail/RFC822.php';
137 
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'] == 'y' && $is_pear_mail_installed) ? true : false,
142  'mail_external_sender_noreply' => $settings['mail_external_sender_noreply'],
143  'mail_maxsize_attach' => $settings['mail_maxsize_attach']
144  ));
145  }
146 
147  public function saveObject()
148  {
149  global $ilAccess;
150 
151  if(!$ilAccess->checkAccess('write,read', '', $this->object->getRefId()))
152  {
153  $this->ilias->raiseError($this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->WARNING);
154  }
155 
156  $this->initForm();
157  if($this->form->checkInput())
158  {
159  $this->ilias->setSetting('mail_subject_prefix',$this->form->getInput('mail_subject_prefix'));
160  $this->ilias->setSetting('mail_incoming_mail', (int)$this->form->getInput('mail_incoming_mail'));
161  $this->ilias->setSetting('mail_maxsize_attach', $this->form->getInput('mail_maxsize_attach'));
162  $this->ilias->setSetting('pear_mail_enable', $this->form->getInput('pear_mail_enable'));
163  $this->ilias->setSetting('mail_external_sender_noreply', $this->form->getInput('mail_external_sender_noreply'));
164 
165  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
166  }
167  $this->form->setValuesByPost();
168 
169  $this->tpl->setContent($this->form->getHTML());
170  }
171 
172  function importObject()
173  {
174  global $rbacsystem,$lng;
175 
176  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
177  {
178  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
179  }
180  #$this->getTemplateFile("import");
181  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_import.html", "Services/Mail");
182 
183  // GET ALREADY CREATED UPLOADED XML FILE
184  $this->__initFileObject();
185  if($this->file_obj->findXMLFile())
186  {
187  $this->tpl->setVariable("TXT_IMPORTED_FILE",$lng->txt("checked_files"));
188  $this->tpl->setVariable("XML_FILE",basename($this->file_obj->getXMLFile()));
189 
190  $this->tpl->setVariable("BTN_IMPORT",$this->lng->txt("import"));
191  }
192 
193  $this->tpl->setVariable("FORMACTION",
194  $this->ctrl->getFormAction($this));
195  $this->tpl->setVariable("TXT_IMPORT_MAIL",$this->lng->txt("table_mail_import"));
196  $this->tpl->setVariable("TXT_IMPORT_FILE",$this->lng->txt("mail_import_file"));
197  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
198  $this->tpl->setVariable("BTN_UPLOAD",$this->lng->txt("upload"));
199 
200  return true;
201  }
202 
204  {
205  global $rbacsystem,$lng;
206 
207  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
208  {
209  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
210  }
211  $this->__initFileObject();
212  $this->file_obj->findXMLFile();
213  $this->__initParserObject($this->file_obj->getXMLFile(),"import");
214  $this->parser_obj->startParsing();
215  $number = $this->parser_obj->getCountImported();
216  ilUtil::sendInfo($lng->txt("import_finished")." ".$number,true);
217 
218  $this->ctrl->redirect($this, "import");
219  }
220 
221 
222 
223  function uploadObject()
224  {
225  global $rbacsystem,$lng;
226 
227  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
228  {
229  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
230  }
231 
232  $this->__initFileObject();
233  if(!$this->file_obj->storeUploadedFile($_FILES["importFile"])) // STEP 1 save file in ...import/mail
234  {
235  $this->message = $lng->txt("import_file_not_valid");
236  $this->file_obj->unlinkLast();
237  }
238  else if(!$this->file_obj->unzip())
239  {
240  $this->message = $lng->txt("cannot_unzip_file"); // STEP 2 unzip uplaoded file
241  $this->file_obj->unlinkLast();
242  }
243  else if(!$this->file_obj->findXMLFile()) // STEP 3 getXMLFile
244  {
245  $this->message = $lng->txt("cannot_find_xml");
246  $this->file_obj->unlinkLast();
247  }
248  else if(!$this->__initParserObject($this->file_obj->getXMLFile(),"check"))
249  {
250  $this->message = $lng->txt("error_parser"); // STEP 4 init sax parser
251  }
252  else if(!$this->parser_obj->startParsing())
253  {
254  $this->message = $lng->txt("users_not_imported").":<br/>"; // STEP 5 start parsing
255  $this->message .= $this->parser_obj->getNotAssignableUsers();
256  }
257  // FINALLY CHECK ERROR
258  if(!$this->message)
259  {
260  $this->message = $lng->txt("uploaded_and_checked");
261  }
262  ilUtil::sendInfo($this->message,true);
263 
264  $this->ctrl->redirect($this, "import");
265  }
266 
267  // PRIVATE
268  function __initFileObject()
269  {
270  include_once "./classes/class.ilFileDataImportMail.php";
271 
272  $this->file_obj =& new ilFileDataImportMail();
273 
274  return true;
275  }
276  function __initParserObject($a_xml,$a_mode)
277  {
278  include_once "Services/Mail/classes/class.ilMailImportParser.php";
279 
280  if(!$a_xml)
281  {
282  return false;
283  }
284 
285  $this->parser_obj =& new ilMailImportParser($a_xml,$a_mode);
286 
287  return true;
288  }
289 
290  function &executeCommand()
291  {
292  $next_class = $this->ctrl->getNextClass($this);
293  $cmd = $this->ctrl->getCmd();
294  $this->prepareOutput();
295 
296  switch($next_class)
297  {
298  case 'ilpermissiongui':
299  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
300  $perm_gui =& new ilPermissionGUI($this);
301  $ret =& $this->ctrl->forwardCommand($perm_gui);
302  break;
303 
304  default:
305  if(!$cmd)
306  {
307  $cmd = "view";
308  }
309  $cmd .= "Object";
310  $this->$cmd();
311 
312  break;
313  }
314  return true;
315  }
316 
317  function getAdminTabs(&$tabs_gui)
318  {
319  $this->getTabs($tabs_gui);
320  }
321 
327  function getTabs(&$tabs_gui)
328  {
329  global $rbacsystem;
330 
331  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
332  {
333  $tabs_gui->addTarget("settings",
334  $this->ctrl->getLinkTarget($this, "view"), array("view", 'save', ""), "", "");
335  }
336 
337  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
338  {
339  $tabs_gui->addTarget("perm_settings",
340  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
341  }
342  }
343 } // END class.ilObjMailGUI
344 ?>