ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailOptionsGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 "Services/Mail/classes/class.ilMailbox.php";
25 require_once "Services/Mail/classes/class.ilFormatMail.php";
26 require_once 'Services/Mail/classes/class.ilMailOptions.php';
27 
35 {
36  private $tpl = null;
37  private $ctrl = null;
38  private $lng = null;
39 
40  private $umail = null;
41  private $mbox = null;
42 
43  private $errorDelete = false;
44 
45  public function __construct()
46  {
47  global $tpl, $ilCtrl, $lng, $ilUser;
48 
49  $this->tpl = $tpl;
50  $this->ctrl = $ilCtrl;
51  $this->lng = $lng;
52 
53  $this->ctrl->saveParameter($this, "mobj_id");
54 
55  $this->umail = new ilFormatMail($ilUser->getId());
56  $this->mbox = new ilMailBox($ilUser->getId());
57  }
58 
59  public function executeCommand()
60  {
61  $forward_class = $this->ctrl->getNextClass($this);
62  switch($forward_class)
63  {
64  default:
65  if (!($cmd = $this->ctrl->getCmd()))
66  {
67  $cmd = "showOptions";
68  }
69 
70  $this->$cmd();
71  break;
72  }
73  return true;
74  }
75 
83  public function saveOptions()
84  {
85  global $lng, $ilUser, $ilSetting;
86 
87  $this->tpl->setVariable('HEADER', $lng->txt('mail'));
88  $this->initMailOptionsForm();
89 
90  $mailOptions = new ilMailOptions($ilUser->getId());
91  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1' &&
92  $ilSetting->get('usr_settings_disable_mail_incoming_mail') != '1')
93  {
94  $incoming_type = (int)$_POST['incoming_type'];
95  }
96  else
97  {
98  $incoming_type = $mailOptions->getIncomingType();
99  }
100 
101  if($this->form->checkInput())
102  {
103  $mailOptions->updateOptions(
104  ilUtil::stripSlashes($_POST['signature']),
105  (int)$_POST['linebreak'],
106  $incoming_type,
107  (int)$_POST['cronjob_notification']
108  );
109 
110  ilUtil::sendSuccess($lng->txt('mail_options_saved'));
111  }
112 
113  $this->form->setValuesByPost();
114 
115  $this->tpl->setContent($this->form->getHTML());
116  $this->tpl->show();
117  }
118 
125  public function showOptions()
126  {
127  global $lng;
128 
129  $this->tpl->setVariable('HEADER', $lng->txt('mail'));
130 
131  $this->initMailOptionsForm();
132  $this->setMailOptionsValuesByDB();
133 
134  $this->tpl->setContent($this->form->getHTML());
135  $this->tpl->show();
136  }
137 
144  private function setMailOptionsValuesByDB()
145  {
146  global $ilUser, $ilSetting;
147 
148  $mailOptions = new ilMailOptions($ilUser->getId());
149 
150  $data= array(
151  'linebreak' => $mailOptions->getLinebreak(),
152  'signature' => $mailOptions->getSignature(),
153  'cronjob_notification' => $mailOptions->getCronjobNotification()
154  );
155 
156  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1')
157  {
158  $data['incoming_type'] = $mailOptions->getIncomingType();
159  }
160 
161  $this->form->setValuesByArray($data);
162  }
163 
170  private function initMailOptionsForm()
171  {
172  global $ilCtrl, $ilSetting, $lng, $ilUser;
173 
174  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
175  $this->form = new ilPropertyFormGUI();
176 
177  $this->form->setFormAction($ilCtrl->getFormAction($this, 'saveOptions'));
178  $this->form->setTitle($lng->txt('mail_settings'));
179 
180  // BEGIN INCOMING
181  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1')
182  {
183  $options = array(
184  IL_MAIL_LOCAL => $lng->txt('mail_incoming_local'),
185  IL_MAIL_EMAIL => $lng->txt('mail_incoming_smtp'),
186  IL_MAIL_BOTH => $lng->txt('mail_incoming_both')
187  );
188  $si = new ilSelectInputGUI($lng->txt('mail_incoming'), 'incoming_type');
189  $si->setOptions($options);
190  if(!strlen(ilObjUser::_lookupEmail($ilUser->getId())) ||
191  $ilSetting->get('usr_settings_disable_mail_incoming_mail') == '1')
192  {
193  $si->setDisabled(true);
194  }
195  $this->form->addItem($si);
196  }
197 
198  // BEGIN LINEBREAK_OPTIONS
199  $options = array();
200  for($i = 50; $i <= 80; $i++)
201  {
202  $options[$i] = $i;
203  }
204  $si = new ilSelectInputGUI($lng->txt('linebreak'), 'linebreak');
205  $si->setOptions($options);
206  $this->form->addItem($si);
207 
208  // BEGIN SIGNATURE
209  $ta = new ilTextAreaInputGUI($lng->txt('signature'), 'signature');
210  $ta->setRows(10);
211  $ta->setCols(60);
212  $this->form->addItem($ta);
213 
214  // BEGIN CRONJOB NOTIFICATION
215  if($ilSetting->get('mail_notification'))
216  {
217  $cb = new ilCheckboxInputGUI($lng->txt('cron_mail_notification'), 'cronjob_notification');
218  $cb->setInfo($lng->txt('mail_cronjob_notification_info'));
219  $cb->setValue(1);
220  $this->form->addItem($cb);
221  }
222 
223  $this->form->addCommandButton('saveOptions', $lng->txt('save'));
224  }
225 }
226 
227 ?>