ILIAS  Release_3_10_x_branch Revision 61812
 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  function ilObjMailGUI($a_data,$a_id,$a_call_by_reference)
44  {
45  $this->type = "mail";
46  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
47  }
48 
49  function viewObject()
50  {
51 # parent::editObject();
52 
53  $this->lng->loadLanguageModule("mail");
54 
55  $this->tpl->addBlockFile("SYSTEMSETTINGS", "systemsettings", "tpl.mail_basicdata.html", "Services/Mail");
56  $this->tpl->setCurrentBlock("systemsettings");
57 
58  $settings = $this->ilias->getAllSettings();
59 
60  if (isset($_POST["save_settings"])) // formular sent
61  {
62  //init checking var
63  $form_valid = true;
64 
65  // put any checks here!!!
66 
67  if (!$form_valid) //required fields not satisfied. Set formular to already fill in values
68  {
69  // mail server
70  $settings["mail_server"] = $_POST["mail_server"];
71  $settings["mail_port"] = $_POST["mail_port"];
72 
73  // internal mail
74 # $settings["mail_intern_enable"] = $_POST["mail_intern_enable"];
75  $settings["mail_maxsize_mail"] = $_POST["mail_maxsize_mail"];
76  $settings["mail_maxsize_attach"] = $_POST["mail_maxsize_attach"];
77  $settings["mail_maxsize_box"] = $_POST["mail_maxsize_box"];
78  $settings["mail_maxtime_mail"] = $_POST["mail_maxtime_mail"];
79  $settings["mail_maxtime_attach"] = $_POST["mail_maxtime_attach"];
80  $settings['mail_external_sender_noreply'] = ilUtil::stripSlashes($_POST['mail_external_sender_noreply']);
81  }
82  else // all required fields ok
83  {
84 
86  // write new settings
87 
88  // mail server
89  $this->ilias->setSetting("mail_server",$_POST["mail_server"]);
90  $this->ilias->setSetting("mail_port",$_POST["mail_port"]);
91 
92  // internal mail
93  $this->ilias->setSetting("mail_incoming_mail",$_POST["mail_incoming_mail"]);
94 
95 # $this->ilias->setSetting("mail_intern_enable",$_POST["mail_intern_enable"]);
96  $this->ilias->setSetting("mail_maxsize_mail",$_POST["mail_maxsize_mail"]);
97  $this->ilias->setSetting("mail_maxsize_attach",$_POST["mail_maxsize_attach"]);
98  $this->ilias->setSetting("mail_maxsize_box",$_POST["mail_maxsize_box"]);
99  $this->ilias->setSetting("mail_maxtime_mail",$_POST["mail_maxtime_mail"]);
100  $this->ilias->setSetting("mail_maxtime_attach",$_POST["mail_maxtime_attach"]);
101  $this->ilias->setSetting("pear_mail_enable",$_POST["pear_mail_enable"]);
102  $this->ilias->setSetting('mail_external_sender_noreply', ilUtil::stripSlashes($_POST['mail_external_sender_noreply']));
103 
104  $settings = $this->ilias->getAllSettings();
105 
106  // feedback
107  ilUtil::sendInfo($this->lng->txt("saved_successfully"));
108  }
109  }
110 
112  // setting language vars
113 
114  // common
115  $this->tpl->setVariable("TXT_DAYS",$this->lng->txt("days"));
116  $this->tpl->setVariable("TXT_KB",$this->lng->txt("kb"));
117 
118  // mail server
119  $this->tpl->setVariable("TXT_MAIL_SMTP", $this->lng->txt("mail")." (".$this->lng->txt("smtp").")");
120  $this->tpl->setVariable("TXT_MAIL_SERVER", $this->lng->txt("server"));
121  $this->tpl->setVariable("TXT_MAIL_PORT", $this->lng->txt("port"));
122 
123  // Pear Mail extension
124  // Note: We use the include statement to determine whether PEAR MAIL is
125  // installed. We use the @ operator to prevent PHP from issuing a
126  // warning while we test for PEAR MAIL.
127  $is_pear_mail_installed = @include_once 'Mail/RFC822.php';
128  $this->tpl->setVariable("TXT_PEAR_MAIL", $this->lng->txt("mail_use_pear_mail"));
129  if ($settings['pear_mail_enable'] && $is_pear_mail_installed)
130  {
131  $this->tpl->setVariable("PEAR_MAIL_CHECKED", 'checked="checked"');
132  }
133  if ($is_pear_mail_installed)
134  {
135  $this->tpl->setVariable("TXT_PEAR_MAIL_INFO",
136  $this->lng->txt("mail_use_pear_mail_info")
137  );
138  }
139  else
140  {
141  $this->tpl->setVariable("TXT_PEAR_MAIL_INFO",
142  $this->lng->txt("mail_use_pear_mail_info").'<br>'.
143  $this->lng->txt("mail_pear_mail_needed")
144  );
145  $this->tpl->setVariable("PEAR_MAIL_DISABLED", 'disabled="disabled"');
146  }
147 
148  // internal mail
149  include_once "Services/Mail/classes/class.ilMailOptions.php";
150  $this->tpl->setVariable("TXT_GENERAL_SETTINGS", $this->lng->txt("general_settings"));
151  $this->tpl->setVariable("TXT_MAIL_INCOMING", $this->lng->txt("mail_incoming"));
152  $types = array(
153  array(
154  "name" => $this->lng->txt("mail_incoming_local"),
155  "value" => IL_MAIL_LOCAL
156  ),
157  array(
158  "name" => $this->lng->txt("mail_incoming_smtp"),
159  "value" => IL_MAIL_EMAIL
160  ),
161  array(
162  "name" => $this->lng->txt("mail_incoming_both"),
163  "value" => IL_MAIL_BOTH
164  )
165  );
166  for ($i = 0; $i < count($types); $i++)
167  {
168  $this->tpl->setCurrentBlock("loop_incoming_mail");
169  $this->tpl->setVariable("LOOP_INCOMING_MAIL_VALUE", $types[$i]["value"]);
170  $this->tpl->setVariable("LOOP_INCOMING_MAIL_NAME", $types[$i]["name"]);
171  if ($settings["mail_incoming_mail"] == $types[$i]["value"])
172  {
173  $this->tpl->setVariable("LOOP_INCOMING_MAIL_SELECTED", "selected");
174  }
175  $this->tpl->parseCurrentBlock("loop_incoming_mail");
176  }
177 
178 # $this->tpl->setVariable("TXT_MAIL_INTERN", $this->lng->txt("mail")." (".$this->lng->txt("internal_system").")");
179  $this->tpl->setVariable("TXT_MAIL_INTERN", $this->lng->txt("internal_system"));
180 # $this->tpl->setVariable("TXT_MAIL_INTERN_ENABLE", $this->lng->txt("mail_intern_enable"));
181  $this->tpl->setVariable("TXT_MAIL_MAXSIZE_MAIL", $this->lng->txt("mail_maxsize_mail"));
182  $this->tpl->setVariable("TXT_MAIL_MAXSIZE_ATTACH", $this->lng->txt("mail_maxsize_attach"));
183  $this->tpl->setVariable("TXT_MAIL_MAXSIZE_BOX", $this->lng->txt("mail_maxsize_box"));
184  $this->tpl->setVariable("TXT_MAIL_MAXTIME_MAIL", $this->lng->txt("mail_maxtime_mail"));
185  $this->tpl->setVariable("TXT_MAIL_MAXTIME_ATTACH", $this->lng->txt("mail_maxtime_attach"));
186  $this->tpl->setVariable("TXT_SAVE", $this->lng->txt("save"));
187 
189  // display formula data
190 
191  // mail server
192  $this->tpl->setVariable("MAIL_SERVER",$settings["mail_server"]);
193  $this->tpl->setVariable("MAIL_PORT",$settings["mail_port"]);
194 
195  // internal mail
196 # if ($settings["mail_intern_enable"] == "y")
197 # {
198 # $this->tpl->setVariable("MAIL_INTERN_ENABLE","checked=\"checked\"");
199 # }
200 
201  $this->tpl->setVariable("MAIL_MAXSIZE_MAIL", $settings["mail_maxsize_mail"]);
202  $this->tpl->setVariable("MAIL_MAXSIZE_ATTACH", $settings["mail_maxsize_attach"]);
203  $this->tpl->setVariable("MAIL_MAXSIZE_BOX", $settings["mail_maxsize_box"]);
204  $this->tpl->setVariable("MAIL_MAXTIME_MAIL", $settings["mail_maxtime_mail"]);
205  $this->tpl->setVariable("MAIL_MAXTIME_ATTACH", $settings["mail_maxtime_attach"]);
206 
207  // noreply
208  $this->tpl->setVariable('TXT_MAIL_EXTERNAL_SENDER_NOREPLY', $this->lng->txt('mail_external_sender_noreply'));
209  $this->tpl->setVariable('MAIL_EXTERNAL_SENDER_NOREPLY', $settings['mail_external_sender_noreply']);
210  $this->tpl->setVariable('INFO_MAIL_EXTERNAL_SENDER_NOREPLY', $this->lng->txt('info_mail_external_sender_noreply'));
211 
212  $this->tpl->parseCurrentBlock();
213  }
214 
215  function importObject()
216  {
217  global $rbacsystem,$lng;
218 
219  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
220  {
221  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
222  }
223  #$this->getTemplateFile("import");
224  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_import.html", "Services/Mail");
225 
226  // GET ALREADY CREATED UPLOADED XML FILE
227  $this->__initFileObject();
228  if($this->file_obj->findXMLFile())
229  {
230  $this->tpl->setVariable("TXT_IMPORTED_FILE",$lng->txt("checked_files"));
231  $this->tpl->setVariable("XML_FILE",basename($this->file_obj->getXMLFile()));
232 
233  $this->tpl->setVariable("BTN_IMPORT",$this->lng->txt("import"));
234  }
235 
236  $this->tpl->setVariable("FORMACTION",
237  $this->ctrl->getFormAction($this));
238  $this->tpl->setVariable("TXT_IMPORT_MAIL",$this->lng->txt("table_mail_import"));
239  $this->tpl->setVariable("TXT_IMPORT_FILE",$this->lng->txt("mail_import_file"));
240  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
241  $this->tpl->setVariable("BTN_UPLOAD",$this->lng->txt("upload"));
242 
243  return true;
244  }
245 
247  {
248  global $rbacsystem,$lng;
249 
250  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
251  {
252  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
253  }
254  $this->__initFileObject();
255  $this->file_obj->findXMLFile();
256  $this->__initParserObject($this->file_obj->getXMLFile(),"import");
257  $this->parser_obj->startParsing();
258  $number = $this->parser_obj->getCountImported();
259  ilUtil::sendInfo($lng->txt("import_finished")." ".$number,true);
260 
261  $this->ctrl->redirect($this, "import");
262  }
263 
264 
265 
266  function uploadObject()
267  {
268  global $rbacsystem,$lng;
269 
270  if (!$rbacsystem->checkAccess('write',$this->object->getRefId()))
271  {
272  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
273  }
274 
275  $this->__initFileObject();
276  if(!$this->file_obj->storeUploadedFile($_FILES["importFile"])) // STEP 1 save file in ...import/mail
277  {
278  $this->message = $lng->txt("import_file_not_valid");
279  $this->file_obj->unlinkLast();
280  }
281  else if(!$this->file_obj->unzip())
282  {
283  $this->message = $lng->txt("cannot_unzip_file"); // STEP 2 unzip uplaoded file
284  $this->file_obj->unlinkLast();
285  }
286  else if(!$this->file_obj->findXMLFile()) // STEP 3 getXMLFile
287  {
288  $this->message = $lng->txt("cannot_find_xml");
289  $this->file_obj->unlinkLast();
290  }
291  else if(!$this->__initParserObject($this->file_obj->getXMLFile(),"check"))
292  {
293  $this->message = $lng->txt("error_parser"); // STEP 4 init sax parser
294  }
295  else if(!$this->parser_obj->startParsing())
296  {
297  $this->message = $lng->txt("users_not_imported").":<br/>"; // STEP 5 start parsing
298  $this->message .= $this->parser_obj->getNotAssignableUsers();
299  }
300  // FINALLY CHECK ERROR
301  if(!$this->message)
302  {
303  $this->message = $lng->txt("uploaded_and_checked");
304  }
305  ilUtil::sendInfo($this->message,true);
306 
307  $this->ctrl->redirect($this, "import");
308  }
309 
310  // PRIVATE
311  function __initFileObject()
312  {
313  include_once "./classes/class.ilFileDataImportMail.php";
314 
315  $this->file_obj =& new ilFileDataImportMail();
316 
317  return true;
318  }
319  function __initParserObject($a_xml,$a_mode)
320  {
321  include_once "Services/Mail/classes/class.ilMailImportParser.php";
322 
323  if(!$a_xml)
324  {
325  return false;
326  }
327 
328  $this->parser_obj =& new ilMailImportParser($a_xml,$a_mode);
329 
330  return true;
331  }
332 
333  function &executeCommand()
334  {
335  $next_class = $this->ctrl->getNextClass($this);
336  $cmd = $this->ctrl->getCmd();
337  $this->prepareOutput();
338 
339  switch($next_class)
340  {
341  case 'ilpermissiongui':
342  include_once("./classes/class.ilPermissionGUI.php");
343  $perm_gui =& new ilPermissionGUI($this);
344  $ret =& $this->ctrl->forwardCommand($perm_gui);
345  break;
346 
347  default:
348  if(!$cmd)
349  {
350  $cmd = "view";
351  }
352  $cmd .= "Object";
353  $this->$cmd();
354 
355  break;
356  }
357  return true;
358  }
359 
360  function getAdminTabs(&$tabs_gui)
361  {
362  $this->getTabs($tabs_gui);
363  }
364 
370  function getTabs(&$tabs_gui)
371  {
372  global $rbacsystem;
373 
374  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
375  {
376  $tabs_gui->addTarget("settings",
377  $this->ctrl->getLinkTarget($this, "view"), array("view",""), "", "");
378  }
379 
380  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
381  {
382  $tabs_gui->addTarget("perm_settings",
383  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
384  }
385 
386  if ($rbacsystem->checkAccess('write',$this->object->getRefId()))
387  {
388  $tabs_gui->addTarget("import",
389  $this->ctrl->getLinkTarget($this, "import"), "import", "", "");
390  }
391  }
392 } // END class.ilObjMailGUI
393 ?>