ILIAS  Release_5_0_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  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
61  $button = ilLinkButton::getInstance();
62  $button->setCaption("user_account_codes_add");
63  $button->setUrl($ilCtrl->getLinkTarget($this, "addCodes"));
64  $ilToolbar->addButtonInstance($button);
65 
66  include_once("./Services/User/classes/class.ilAccountCodesTableGUI.php");
67  $ctab = new ilAccountCodesTableGUI($this, "listCodes");
68  $tpl->setContent($ctab->getHTML());
69  }
70 
71  function initAddCodesForm()
72  {
73  global $ilCtrl, $lng;
74 
75  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
76 
77  $this->form_gui = new ilPropertyFormGUI();
78  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, 'createCodes'));
79  $this->form_gui->setTitle($lng->txt('user_account_codes_edit_header'));
80 
81  $count = new ilNumberInputGUI($lng->txt('user_account_codes_number'), 'acc_codes_number');
82  $count->setSize(4);
83  $count->setMaxLength(4);
84  $count->setMinValue(1);
85  $count->setMaxValue(1000);
86  $count->setRequired(true);
87  $this->form_gui->addItem($count);
88 
89  $valid = new ilRadioGroupInputGUI($lng->txt('user_account_code_valid_until'), 'valid_type');
90  $valid->setRequired(true);
91 
92  $unl = new ilRadioOption($lng->txt('user_account_code_valid_until_unlimited'), 'valid_unlimited');
93  $valid->addOption($unl);
94 
95  $st = new ilRadioOption($lng->txt('user_account_code_valid_until_static'), 'valid_static');
96  $valid->addOption($st);
97 
98  $dt = new ilDateTimeInputGUI($lng->txt('date'), 'valid_date');
99  $dt->setRequired(true);
100  $st->addSubItem($dt);
101 
102  $dyn = new ilRadioOption($lng->txt('user_account_code_valid_until_dynamic'), 'valid_dynamic');
103  $valid->addOption($dyn);
104 
105  $ds = new ilNumberInputGUI($lng->txt('days'), 'valid_days');
106  $ds->setSize(5);
107  $ds->setRequired(true);
108  $dyn->addSubItem($ds);
109 
110  $this->form_gui->addItem($valid);
111 
112  $this->form_gui->addCommandButton('createCodes', $lng->txt('create'));
113  $this->form_gui->addCommandButton('listCodes', $lng->txt('cancel'));
114  }
115 
116  function addCodes()
117  {
118  global $ilAccess, $ilErr, $tpl, $lng;
119 
120  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
121  {
122  $ilErr->raiseError($lng->txt("msg_no_perm_write"), $ilErr->MESSAGE);
123  }
124 
125  $this->initAddCodesForm();
126  $tpl->setContent($this->form_gui->getHTML());
127  }
128 
129  function createCodes()
130  {
131  global $ilAccess, $ilErr, $lng, $tpl, $ilCtrl;
132 
133  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
134  {
135  $ilErr->raiseError($lng->txt("msg_no_perm_write"), $ilErr->MESSAGE);
136  }
137 
138  $this->initAddCodesForm();
139  if($this->form_gui->checkInput())
140  {
141  $number = $this->form_gui->getInput('acc_codes_number');
142  switch($this->form_gui->getInput('valid_type'))
143  {
144  case 'valid_unlimited':
145  $valid = 0;
146  break;
147 
148  case 'valid_static':
149  $valid = $this->form_gui->getInput('valid_date');
150  $valid = $valid['date'];
151  break;
152 
153  case 'valid_dynamic':
154  $valid = $this->form_gui->getInput('valid_days');
155  break;
156  }
157 
158  include_once './Services/User/classes/class.ilAccountCode.php';
159 
160  $stamp = time();
161  for($loop = 1; $loop <= $number; $loop++)
162  {
163  ilAccountCode::create($valid, $stamp);
164  }
165 
166  ilUtil::sendSuccess($lng->txt('saved_successfully'), true);
167  $ilCtrl->redirect($this, "listCodes");
168  }
169  else
170  {
171  $this->form_gui->setValuesByPost();
172  $tpl->setContent($this->form_gui->getHtml());
173  }
174  }
175 
176  function deleteCodes()
177  {
178  global $lng, $ilCtrl;
179 
180  include_once './Services/User/classes/class.ilAccountCode.php';
182 
183  ilUtil::sendSuccess($lng->txt('info_deleted'), true);
184  $ilCtrl->redirect($this, "listCodes");
185  }
186 
188  {
189  global $ilErr, $lng, $ilCtrl, $tpl;
190 
191  if(!isset($_POST["id"]))
192  {
193  $ilErr->raiseError($lng->txt("no_checkbox"), $ilErr->MESSAGE);
194  }
195 
196  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
197  $gui = new ilConfirmationGUI();
198  $gui->setHeaderText($lng->txt("info_delete_sure"));
199  $gui->setCancel($lng->txt("cancel"), "listCodes");
200  $gui->setConfirm($lng->txt("confirm"), "deleteCodes");
201  $gui->setFormAction($ilCtrl->getFormAction($this, "deleteCodes"));
202 
203  include_once './Services/User/classes/class.ilAccountCode.php';
204  $data = ilAccountCode::loadCodesByIds($_POST["id"]);
205  foreach($data as $code)
206  {
207  $gui->addItem("id[]", $code["code_id"], $code["code"]);
208  }
209 
210  $tpl->setContent($gui->getHTML());
211  }
212 
213  function resetCodesFilter()
214  {
215  include_once("./Services/User/classes/class.ilAccountCodesTableGUI.php");
216  $utab = new ilAccountCodesTableGUI($this, "listCodes");
217  $utab->resetOffset();
218  $utab->resetFilter();
219 
220  $this->listCodes();
221  }
222 
223  function applyCodesFilter()
224  {
225  include_once("./Services/User/classes/class.ilAccountCodesTableGUI.php");
226  $utab = new ilAccountCodesTableGUI($this, "listCodes");
227  $utab->resetOffset();
228  $utab->writeFilterToSession();
229 
230  $this->listCodes();
231  }
232 
233  function exportCodes()
234  {
235  global $ilAccess, $ilErr, $lng;
236 
237  if(!$ilAccess->checkAccess('read', '', $this->ref_id))
238  {
239  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->MESSAGE);
240  }
241 
242  include_once("./Services/User/classes/class.ilAccountCodesTableGUI.php");
243  $utab = new ilAccountCodesTableGUI($this, "listCodes");
244 
245  include_once './Services/User/classes/class.ilAccountCode.php';
246  $codes = ilAccountCode::getCodesForExport($utab->filter["code"], $utab->filter["valid_until"], $utab->filter["generated"]);
247 
248  if(sizeof($codes))
249  {
250  // #13497
251  ilUtil::deliverData(implode("\r\n", $codes), "ilias_account_codes_".date("d-m-Y").".txt","text/plain");
252  }
253  else
254  {
255  ilUtil::sendFailure($lng->txt("account_export_codes_no_data"));
256  $this->listCodes();
257  }
258  }
259 }
260 
261 ?>