ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailOptionsGUI.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/Mail/classes/class.ilMailbox.php";
5 require_once "Services/Mail/classes/class.ilFormatMail.php";
6 require_once 'Services/Mail/classes/class.ilMailOptions.php';
7 
15 {
16  private $tpl = null;
17  private $ctrl = null;
18  private $lng = null;
19 
20  private $umail = null;
21  private $mbox = null;
22 
23  private $errorDelete = false;
24 
25  public function __construct()
26  {
27  global $tpl, $ilCtrl, $lng, $ilUser;
28 
29  $this->tpl = $tpl;
30  $this->ctrl = $ilCtrl;
31  $this->lng = $lng;
32 
33  $this->ctrl->saveParameter($this, "mobj_id");
34 
35  $this->umail = new ilFormatMail($ilUser->getId());
36  $this->mbox = new ilMailBox($ilUser->getId());
37  }
38 
39  public function executeCommand()
40  {
41  $forward_class = $this->ctrl->getNextClass($this);
42  switch($forward_class)
43  {
44  default:
45  if (!($cmd = $this->ctrl->getCmd()))
46  {
47  $cmd = "showOptions";
48  }
49 
50  $this->$cmd();
51  break;
52  }
53  return true;
54  }
55 
63  public function saveOptions()
64  {
65  global $lng, $ilUser, $ilSetting;
66 
67  $this->tpl->setTitle($lng->txt('mail'));
68  $this->initMailOptionsForm();
69 
70  $mailOptions = new ilMailOptions($ilUser->getId());
71  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1' &&
72  $ilSetting->get('usr_settings_disable_mail_incoming_mail') != '1')
73  {
74  $incoming_type = (int)$_POST['incoming_type'];
75  }
76  else
77  {
78  $incoming_type = $mailOptions->getIncomingType();
79  }
80 
81  if($this->form->checkInput())
82  {
83  $mailOptions->updateOptions(
84  ilUtil::stripSlashes($_POST['signature']),
85  (int)$_POST['linebreak'],
86  $incoming_type,
87  (int)$_POST['cronjob_notification']
88  );
89 
90  ilUtil::sendSuccess($lng->txt('mail_options_saved'));
91  }
92 
93  $this->form->setValuesByPost();
94 
95  $this->tpl->setContent($this->form->getHTML());
96  $this->tpl->show();
97  }
98 
105  public function showOptions()
106  {
107  global $lng;
108 
109  $this->tpl->setTitle($lng->txt('mail'));
110 
111  $this->initMailOptionsForm();
112  $this->setMailOptionsValuesByDB();
113 
114  $this->tpl->setContent($this->form->getHTML());
115  $this->tpl->show();
116  }
117 
124  private function setMailOptionsValuesByDB()
125  {
126  global $ilUser, $ilSetting;
127 
128  $mailOptions = new ilMailOptions($ilUser->getId());
129 
130  $data= array(
131  'linebreak' => $mailOptions->getLinebreak(),
132  'signature' => $mailOptions->getSignature(),
133  'cronjob_notification' => $mailOptions->getCronjobNotification()
134  );
135 
136  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1')
137  {
138  $data['incoming_type'] = $mailOptions->getIncomingType();
139  }
140 
141  $this->form->setValuesByArray($data);
142  }
143 
150  private function initMailOptionsForm()
151  {
152  global $ilCtrl, $ilSetting, $lng, $ilUser;
153 
154  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
155  $this->form = new ilPropertyFormGUI();
156 
157  $this->form->setFormAction($ilCtrl->getFormAction($this, 'saveOptions'));
158  $this->form->setTitle($lng->txt('mail_settings'));
159 
160  // BEGIN INCOMING
161  if($ilSetting->get('usr_settings_hide_mail_incoming_mail') != '1')
162  {
163  $options = array(
164  IL_MAIL_LOCAL => $lng->txt('mail_incoming_local'),
165  IL_MAIL_EMAIL => $lng->txt('mail_incoming_smtp'),
166  IL_MAIL_BOTH => $lng->txt('mail_incoming_both')
167  );
168  $si = new ilSelectInputGUI($lng->txt('mail_incoming'), 'incoming_type');
169  $si->setOptions($options);
170  if(!strlen(ilObjUser::_lookupEmail($ilUser->getId())) ||
171  $ilSetting->get('usr_settings_disable_mail_incoming_mail') == '1')
172  {
173  $si->setDisabled(true);
174  }
175  $this->form->addItem($si);
176  }
177 
178  // BEGIN LINEBREAK_OPTIONS
179  $options = array();
180  for($i = 50; $i <= 80; $i++)
181  {
182  $options[$i] = $i;
183  }
184  $si = new ilSelectInputGUI($lng->txt('linebreak'), 'linebreak');
185  $si->setOptions($options);
186  $this->form->addItem($si);
187 
188  // BEGIN SIGNATURE
189  $ta = new ilTextAreaInputGUI($lng->txt('signature'), 'signature');
190  $ta->setRows(10);
191  $ta->setCols(60);
192  $this->form->addItem($ta);
193 
194  // BEGIN CRONJOB NOTIFICATION
195  if($ilSetting->get('mail_notification'))
196  {
197  $cb = new ilCheckboxInputGUI($lng->txt('cron_mail_notification'), 'cronjob_notification');
198  $cb->setInfo($lng->txt('mail_cronjob_notification_info'));
199  $cb->setValue(1);
200  $this->form->addItem($cb);
201  }
202 
203  $this->form->addCommandButton('saveOptions', $lng->txt('save'));
204  }
205 }
206 
207 ?>