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