ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAccountCodesGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  protected $ref_id; // [int]
16 
22  function __construct($a_ref_id)
23  {
24  global $lng;
25 
26  $this->ref_id = $a_ref_id;
27  $lng->loadLanguageModule("user");
28  }
29 
30  function executeCommand()
31  {
32  global $ilCtrl;
33 
34  $next_class = $ilCtrl->getNextClass($this);
35  $cmd = $ilCtrl->getCmd();
36 
37  switch($next_class)
38  {
39  default:
40  if(!$cmd)
41  {
42  $cmd = "listCodes";
43  }
44  $this->$cmd();
45  break;
46  }
47 
48  return true;
49  }
50 
51  function listCodes()
52  {
53  global $ilAccess, $ilErr, $ilCtrl, $ilToolbar, $lng, $tpl;
54 
55  if(!$ilAccess->checkAccess('read','',$this->ref_id))
56  {
57  $ilErr->raiseError($lng->txt("msg_no_perm_read"),$ilErr->MESSAGE);
58  }
59 
60  $ilToolbar->addButton($lng->txt("user_account_codes_add"),
61  $ilCtrl->getLinkTarget($this, "addCodes"));
62 
63  include_once("./Services/User/classes/class.ilAccountCodesTableGUI.php");
64  $ctab = new ilAccountCodesTableGUI($this, "listCodes");
65  $tpl->setContent($ctab->getHTML());
66  }
67 
68  function initAddCodesForm()
69  {
70  global $ilCtrl, $lng;
71 
72  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
73 
74  $this->form_gui = new ilPropertyFormGUI();
75  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, 'createCodes'));
76  $this->form_gui->setTitle($lng->txt('user_account_codes_edit_header'));
77 
78  $count = new ilNumberInputGUI($lng->txt('user_account_codes_number'), 'acc_codes_number');
79  $count->setSize(4);
80  $count->setMaxLength(4);
81  $count->setMinValue(1);
82  $count->setMaxValue(1000);
83  $count->setRequired(true);
84  $this->form_gui->addItem($count);
85 
86  $valid = new ilRadioGroupInputGUI($lng->txt('user_account_code_valid_until'), 'valid_type');
87  $valid->setRequired(true);
88 
89  $unl = new ilRadioOption($lng->txt('user_account_code_valid_until_unlimited'), 'valid_unlimited');
90  $valid->addOption($unl);
91 
92  $st = new ilRadioOption($lng->txt('user_account_code_valid_until_static'), 'valid_static');
93  $valid->addOption($st);
94 
95  $dt = new ilDateTimeInputGUI($lng->txt('date'), 'valid_date');
96  $dt->setRequired(true);
97  $st->addSubItem($dt);
98 
99  $dyn = new ilRadioOption($lng->txt('user_account_code_valid_until_dynamic'), 'valid_dynamic');
100  $valid->addOption($dyn);
101 
102  $ds = new ilNumberInputGUI($lng->txt('days'), 'valid_days');
103  $ds->setSize(5);
104  $ds->setRequired(true);
105  $dyn->addSubItem($ds);
106 
107  $this->form_gui->addItem($valid);
108 
109  $this->form_gui->addCommandButton('createCodes', $lng->txt('create'));
110  $this->form_gui->addCommandButton('listCodes', $lng->txt('cancel'));
111  }
112 
113  function addCodes()
114  {
115  global $ilAccess, $ilErr, $tpl, $lng;
116 
117  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
118  {
119  $ilErr->raiseError($lng->txt("msg_no_perm_write"), $ilErr->MESSAGE);
120  }
121 
122  $this->initAddCodesForm();
123  $tpl->setContent($this->form_gui->getHTML());
124  }
125 
126  function createCodes()
127  {
128  global $ilAccess, $ilErr, $lng, $tpl, $ilCtrl;
129 
130  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
131  {
132  $ilErr->raiseError($lng->txt("msg_no_perm_write"), $ilErr->MESSAGE);
133  }
134 
135  $this->initAddCodesForm();
136  if($this->form_gui->checkInput())
137  {
138  $number = $this->form_gui->getInput('acc_codes_number');
139  switch($this->form_gui->getInput('valid_type'))
140  {
141  case 'valid_unlimited':
142  $valid = 0;
143  break;
144 
145  case 'valid_static':
146  $valid = $this->form_gui->getInput('valid_date');
147  $valid = $valid['date'];
148  break;
149 
150  case 'valid_dynamic':
151  $valid = $this->form_gui->getInput('valid_days');
152  break;
153  }
154 
155  include_once './Services/User/classes/class.ilAccountCode.php';
156 
157  $stamp = time();
158  for($loop = 1; $loop <= $number; $loop++)
159  {
160  ilAccountCode::create($valid, $stamp);
161  }
162 
163  ilUtil::sendSuccess($lng->txt('saved_successfully'), true);
164  $ilCtrl->redirect($this, "listCodes");
165  }
166  else
167  {
168  $this->form_gui->setValuesByPost();
169  $tpl->setContent($this->form_gui->getHtml());
170  }
171  }
172 
173  function deleteCodes()
174  {
175  global $lng, $ilCtrl;
176 
177  include_once './Services/User/classes/class.ilAccountCode.php';
179 
180  ilUtil::sendSuccess($lng->txt('info_deleted'), true);
181  $ilCtrl->redirect($this, "listCodes");
182  }
183 
185  {
186  global $ilErr, $lng, $ilCtrl, $tpl;
187 
188  if(!isset($_POST["id"]))
189  {
190  $ilErr->raiseError($lng->txt("no_checkbox"), $ilErr->MESSAGE);
191  }
192 
193  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
194  $gui = new ilConfirmationGUI();
195  $gui->setHeaderText($lng->txt("info_delete_sure"));
196  $gui->setCancel($lng->txt("cancel"), "listCodes");
197  $gui->setConfirm($lng->txt("confirm"), "deleteCodes");
198  $gui->setFormAction($ilCtrl->getFormAction($this, "deleteCodes"));
199 
200  include_once './Services/User/classes/class.ilAccountCode.php';
201  $data = ilAccountCode::loadCodesByIds($_POST["id"]);
202  foreach($data as $code)
203  {
204  $gui->addItem("id[]", $code["code_id"], $code["code"]);
205  }
206 
207  $tpl->setContent($gui->getHTML());
208  }
209 
210  function resetCodesFilter()
211  {
212  include_once("./Services/User/classes/class.ilAccountCodesTableGUI.php");
213  $utab = new ilAccountCodesTableGUI($this, "listCodes");
214  $utab->resetOffset();
215  $utab->resetFilter();
216 
217  $this->listCodes();
218  }
219 
220  function applyCodesFilter()
221  {
222  include_once("./Services/User/classes/class.ilAccountCodesTableGUI.php");
223  $utab = new ilAccountCodesTableGUI($this, "listCodes");
224  $utab->resetOffset();
225  $utab->writeFilterToSession();
226 
227  $this->listCodes();
228  }
229 
230  function exportCodes()
231  {
232  global $ilAccess, $ilErr, $lng;
233 
234  if(!$ilAccess->checkAccess('read', '', $this->ref_id))
235  {
236  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->MESSAGE);
237  }
238 
239  include_once("./Services/User/classes/class.ilAccountCodesTableGUI.php");
240  $utab = new ilAccountCodesTableGUI($this, "listCodes");
241 
242  include_once './Services/User/classes/class.ilAccountCode.php';
243  $codes = ilAccountCode::getCodesForExport($utab->filter["code"], $utab->filter["valid_until"], $utab->filter["generated"]);
244 
245  if(sizeof($codes))
246  {
247  // #13497
248  ilUtil::deliverData(implode("\r\n", $codes), "ilias_account_codes_".date("d-m-Y").".txt","text/plain");
249  }
250  else
251  {
252  ilUtil::sendFailure($lng->txt("account_export_codes_no_data"));
253  $this->listCodes();
254  }
255  }
256 }
257 
258 ?>