ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaymentTrusteeGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 include_once './Services/Payment/classes/class.ilPaymentTrustees.php';
13 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
14 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
15 include_once './Services/Payment/classes/class.ilShopTableGUI.php';
16 
18 {
19  public $trustee_obj = null;
20  public $user_obj;
21  public $ctrl;
22 
23  public function __construct($user_obj)
24  {
26 
27  $this->user_obj = $user_obj;
28  $this->trustee_obj = new ilPaymentTrustees($this->user_obj);
29  $this->lng->loadLanguageModule('crs');
30 
31  $this->ctrl->saveParameter($this, 'baseClass');
32  }
33 
34  protected function prepareOutput()
35  {
36  global $ilTabs;
37 
38  $this->setSection(6);
39 
41 
42  $ilTabs->setTabActive('paya_header');
43  $ilTabs->setSubTabActive('paya_trustees');
44  }
45 
46  public function executeCommand()
47  {
48  $cmd = $this->ctrl->getCmd();
49  switch ($this->ctrl->getNextClass($this))
50  {
51  default:
52  if(!$cmd = $this->ctrl->getCmd())
53  {
54  $cmd = 'showTrustees';
55  }
56  $this->prepareOutput();
57  $this->$cmd();
58  break;
59  }
60  }
61 
62  public function cancelDelete()
63  {
64  unset($_SESSION['paya_delete_trustee']);
65  $this->showTrustees();
66 
67  return true;
68  }
69 
70 
71  public function showTrustees($a_show_delete = false)
72  {
73  global $ilToolbar;
74 
75  $_SESSION['paya_delete_trustee'] = $_SESSION['paya_delete_trustee'] ? $_SESSION['paya_delete_trustee'] : array();
76 
77  $actions = array(0 => $this->lng->txt("paya_disabled"),
78  1 => $this->lng->txt("paya_enabled"));
79 
80  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
81  $ul = new ilTextInputGUI($this->lng->txt("user"), "search_str");
82  $ul->setDataSource($this->ctrl->getLinkTarget($this, "performSearch", "", true));
83  $ul->setSize(20);
84  $ilToolbar->addInputItem($ul, true);
85  $ilToolbar->addFormButton($this->lng->txt("add"), "performSearch");
86  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
87 
88  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
89 
90  if($a_show_delete)
91  {
92  $oConfirmationGUI = new ilConfirmationGUI();
93 
94  // set confirm/cancel commands
95  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"performDeleteTrustee"));
96  $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_selected_trustees"));
97  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "cancelDelete");
98  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDeleteTrustee");
99 
100  foreach($this->trustee_obj->getTrustees() as $trustee)
101  {
102  $delete_row = '';
103  if(in_array($trustee['trustee_id'],$_POST['trustee']))
104  {
105  if($tmp_obj = ilObjectFactory::getInstanceByObjId($trustee['trustee_id'],false))
106  {
107  $delete_row = $tmp_obj->getLogin().' -> '.$tmp_obj->getFirstname().' '.$tmp_obj->getLastname();
108  }
109  }
110 
111  $oConfirmationGUI->addItem('',$delete_row, $delete_row);
112  }
113 
114  $this->tpl->setVariable("CONFIRMATION",$oConfirmationGUI->getHTML());
115 
116  }
117 
118  if(!count($this->trustee_obj->getTrustees()))
119  {
120  ilUtil::sendInfo($this->lng->txt('paya_no_trustees'));
121  return true;
122  }
123 
124  $counter = 0;
125  $f_result = array();
126 
127  require_once 'Services/Mail/classes/class.ilMailFormCall.php';
128  foreach($this->trustee_obj->getTrustees() as $trustee)
129  {
130  // GET USER OBJ
131  if($tmp_obj = ilObjectFactory::getInstanceByObjId($trustee['trustee_id'],false))
132  {
133  $f_result[$counter]['trustee_id'] = ilUtil::formCheckbox(in_array($trustee['trustee_id'],$_SESSION['paya_delete_trustee']) ? 1 : 0,
134  "trustee[]",
135  $trustee['trustee_id']);
136  $f_result[$counter]['login'] = $tmp_obj->getLogin();
137  $f_result[$counter]['firstname'] = $tmp_obj->getFirstname();
138  $f_result[$counter]['lastname'] = $tmp_obj->getLastname();
139 
140  $f_result[$counter]['perm_stat'] = ilUtil::formSelect((int) $trustee['perm_stat'],
141  'perm_stat['.$trustee['trustee_id'].']',
142  $actions,
143  false,
144  true);
145 
146  $f_result[$counter]['perm_obj'] = ilUtil::formSelect((int) $trustee['perm_obj'],
147  'perm_obj['.$trustee['trustee_id'].']',
148  $actions,
149  false,
150  true);
151 
152  $f_result[$counter]['perm_coupons'] = ilUtil::formSelect((int) $trustee['perm_coupons'],
153  'perm_coupons['.$trustee['trustee_id'].']',
154  $actions,
155  false,
156  true);
157 
158 # $link_mail = "<a target=\"_blank\" href=\"./ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".
159 # $tmp_obj->getLogin()."\"".$img_mail."</a>";
160  $url_mail = ilMailFormCall::getLinkTarget($this, '', array(), array('type' => 'new', 'rcp_to' => $tmp_obj->getLogin()));
161  $link_mail = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".
162  $url_mail."\">".$this->lng->txt("mail")."</a></div>";
163 
164  $f_result[$counter]['options'] = $link_mail;
165 
166  unset($tmp_obj);
167  ++$counter;
168  }
169  }
170  return $this->__showTrusteesTable($f_result);
171  }
172 
173  public function deleteTrustee()
174  {
175  if(!is_array($_POST['trustee']))
176  {
177  ilUtil::sendInfo($this->lng->txt('crs_no_users_selected'));
178  $this->showTrustees();
179 
180  return true;
181  }
182  $_SESSION['paya_delete_trustee'] = $_POST['trustee'];
183  $this->showTrustees(true);
184 
185  return true;
186  }
187 
188  public function performDeleteTrustee()
189  {
190  if(is_array($_SESSION['paya_delete_trustee']))
191  {
192  foreach($_SESSION['paya_delete_trustee'] as $id)
193  {
194  $this->trustee_obj->setTrusteeId($id);
195  $this->trustee_obj->delete();
196  }
197  }
198  unset($_SESSION['paya_delete_trustee']);
199  ilUtil::sendInfo($this->lng->txt('paya_delete_trustee_msg'));
200  $this->showTrustees();
201 
202  return true;
203  }
204 
205  public function update()
206  {
207  foreach($this->trustee_obj->getTrustees() as $trustee)
208  {
209  $this->trustee_obj->setTrusteeId($trustee['trustee_id']);
210  $this->trustee_obj->toggleStatisticPermission($_POST['perm_stat']["$trustee[trustee_id]"]);
211  $this->trustee_obj->toggleObjectPermission($_POST['perm_obj']["$trustee[trustee_id]"]);
212  $this->trustee_obj->toggleCouponsPermission($_POST['perm_coupons']["$trustee[trustee_id]"]);
213  $this->trustee_obj->modify();
214  }
215  ilUtil::sendInfo($this->lng->txt('paya_updated_trustees'));
216  $this->showTrustees();
217 
218  return true;
219  }
220 
221  public function performSearch()
222  {
223  if(!$_POST["search_str"])
224  {
225  ilUtil::sendInfo($this->lng->txt("crs_search_enter_search_string"));
226  $this->showTrustees();
227 
228  return false;
229  }
230  if(!count($result = $this->__search(ilUtil::stripSlashes($_POST["search_str"]))))
231  {
232  ilUtil::sendInfo($this->lng->txt("crs_no_results_found"));
233  $this->showTrustees();
234 
235  return false;
236  }
237 
238  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.main_view.html",'Services/Payment');
239  $counter = 0;
240  $f_result = array();
241  foreach($result as $user)
242  {
243  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user["id"],false))
244  {
245  continue;
246  }
247  $f_result[$counter]['trustee_id'] = ilUtil::formCheckbox(0,"user[]",$user["id"]);
248  $f_result[$counter]['login'] = $tmp_obj->getLogin();
249  $f_result[$counter]['firstname'] = $tmp_obj->getFirstname();
250  $f_result[$counter]['lastname'] = $tmp_obj->getLastname();
251 
252  unset($tmp_obj);
253  ++$counter;
254  }
255  $this->__showSearchUserTable($f_result);
256  return true;
257  }
258 
259  public function addTrustee()
260  {
261  if(!is_array($_POST["user"]))
262  {
263  ilUtil::sendInfo($this->lng->txt("crs_no_users_selected"));
264  $this->performSearch();
265 
266  return false;
267  }
268  if(in_array($this->user_obj->getId(),$_POST['user']))
269  {
270  ilUtil::sendInfo($this->lng->txt('paya_not_assign_yourself'));
271  $this->showTrustees();
272 
273  return false;
274  }
275 
276  // add them
277  $counter = 0;
278  foreach($_POST['user'] as $user_id)
279  {
280  if($this->trustee_obj->isTrustee($user_id))
281  {
282  continue;
283  }
284  $this->trustee_obj->setTrusteeId($user_id);
285  $this->trustee_obj->toggleStatisticPermission(false);
286  $this->trustee_obj->toggleObjectPermission(true);
287  $this->trustee_obj->toggleCouponsPermission(true);
288  $this->trustee_obj->add();
289  ++$counter;
290  }
291 
292  if($counter)
293  {
294  ilUtil::sendInfo($this->lng->txt('paya_added_trustee'));
295  $this->showTrustees();
296 
297  return true;
298  }
299  else
300  {
301  ilUtil::sendInfo($this->lng->txt('paya_user_already_assigned'));
302  $this->performSearch();
303 
304  return false;
305  }
306 
307  }
308  function addUser()
309  {
310  if(!$_POST['trustee_login'])
311  {
312  ilUtil::sendInfo($this->lng->txt('paya_enter_login'));
313  $this->showTrustees();
314 
315  return false;
316  }
317  if(!$user_id = ilObjUser::getUserIdByLogin($_POST['trustee_login']))
318  {
319  ilUtil::sendInfo($this->lng->txt('paya_no_valid_login'));
320  $this->showTrustees();
321 
322  return false;
323  }
324  if($this->trustee_obj->isTrustee($user_id))
325  {
326  ilUtil::sendInfo($this->lng->txt('paya_user_already_assigned'));
327  $this->showTrustees();
328 
329  return false;
330  }
331  if($user_id == $this->user_obj->getId())
332  {
333  ilUtil::sendInfo($this->lng->txt('paya_not_assign_yourself'));
334  $this->showTrustees();
335 
336  return false;
337  }
338 
339  // checks passed => add trustee
340  $this->trustee_obj->setTrusteeId($user_id);
341  $this->trustee_obj->toggleObjectPermission(true);
342  $this->trustee_obj->toggleStatisticPermission(true);
343  $this->trustee_obj->toggleCouponsPermission(true);
344  $this->trustee_obj->add();
345 
346  ilUtil::sendInfo($this->lng->txt('paya_added_trustee'));
347  $this->showTrustees();
348 
349  return true;
350  }
351 
352 
353  // PRIVATE
354  function __search($a_search_string)
355  {
356  include_once("./Services/Search/classes/class.ilSearch.php");
357 
358  $this->lng->loadLanguageModule("content");
359 
360  $search = new ilSearch($this->user_obj->getId());
361  $search->setPerformUpdate(false);
362  $search->setSearchString(ilUtil::stripSlashes($a_search_string));
363  $search->setCombination("and");
364  $search->setSearchFor(array(0 => 'usr'));
365  $search->setSearchType('new');
366 
367  if($search->validate($message))
368  {
369  $search->performSearch();
370  }
371  else
372  {
373  ilUtil::sendInfo($message,true);
374  $this->ctrl->redirect($this,"searchUser");
375  }
376  return $search->getResultByType('usr');
377  }
378  function __showSearchUserTable($a_result_set)
379  {
380  $tbl = new ilShopTableGUI($this);
381 
382  $tbl->setTitle($this->lng->txt("paya_trustee_table"));
383  $tbl->setId('tbl_search_user_trustee');
384  $tbl->setRowTemplate("tpl.shop_users_row.html", "Services/Payment");
385 
386  $tbl->addColumn(' ', 'trustee_id', '1%', true);
387  $tbl->addColumn($this->lng->txt('login'), 'login', '10%');
388  $tbl->addColumn($this->lng->txt('firstname'),'firstname','20%');
389  $tbl->addColumn($this->lng->txt('lastname'), 'lastname', '20%');
390 
391  $tbl->setSelectAllCheckbox('user');
392  $tbl->addMultiCommand("addTrustee", $this->lng->txt("add"));
393  $tbl->addCommandButton('showTrustees',$this->lng->txt('cancel'));
394 
395  $tbl->fillFooter();
396  $tbl->setData($a_result_set);
397  $this->tpl->setVariable('TABLE', $tbl->getHTML());
398 
399  return true;
400  }
401 
402  function __showTrusteesTable($a_result_set)
403  {
404  $tbl = new ilShopTableGUI($this);
405 
406  $tbl->setTitle($this->lng->txt("paya_trustee_table"));
407  $tbl->setId('tbl_show_trustee');
408  $tbl->setRowTemplate("tpl.shop_users_row.html", "Services/Payment");
409 
410  $tbl->addColumn(' ', 'trustee_id', '1%', true);
411  $tbl->addColumn($this->lng->txt('login'), 'login', '10%');
412  $tbl->addColumn($this->lng->txt('firstname'),'firstname','20%');
413  $tbl->addColumn($this->lng->txt('lastname'), 'lastname', '20%');
414  $tbl->addColumn($this->lng->txt('paya_perm_stat'), 'perm_stat', '15%');
415  $tbl->addColumn($this->lng->txt('paya_perm_obj'), 'perm_obj', '15%');
416  $tbl->addColumn($this->lng->txt('paya_perm_coupons'), 'perm_coupons', '15%');
417  $tbl->addColumn('', 'options', '5%');
418 
419  $tbl->setSelectAllCheckbox('trustee_id');
420  $tbl->addMultiCommand("deleteTrustee", $this->lng->txt("delete"));
421 
422  $tbl->addCommandButton('update',$this->lng->txt('apply'));
423  $tbl->setData($a_result_set);
424  $this->tpl->setVariable('TABLE', $tbl->getHTML());
425 
426  return true;
427  }
428 
429 }
430 ?>