ILIAS  Release_4_0_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 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
31 include_once './payment/classes/class.ilPaymentTrustees.php';
32 
34 {
35  var $trustee_obj = null;
36  var $user_obj;
37  var $ctrl;
38 
39  public function ilPaymentTrusteeGUI($user_obj)
40  {
42 
43  $this->user_obj = $user_obj;
44  $this->trustee_obj = new ilPaymentTrustees($this->user_obj);
45  $this->lng->loadLanguageModule('crs');
46 
47  $this->ctrl->saveParameter($this, 'baseClass');
48  }
49 
50  protected function prepareOutput()
51  {
52  global $ilTabs;
53 
54  $this->setSection(6);
55 
57 
58  $ilTabs->setTabActive('paya_header');
59  $ilTabs->setSubTabActive('paya_trustees');
60  }
61 
62  public function executeCommand()
63  {
64  global $tree;
65 
66  $cmd = $this->ctrl->getCmd();
67  switch ($this->ctrl->getNextClass($this))
68  {
69  default:
70  if(!$cmd = $this->ctrl->getCmd())
71  {
72  $cmd = 'showTrustees';
73  }
74  $this->prepareOutput();
75  $this->$cmd();
76  break;
77  }
78  }
79 
80  function cancelDelete()
81  {
82  unset($_SESSION['paya_delete_trustee']);
83  $this->showTrustees();
84 
85  return true;
86  }
87 
88 
89  function showTrustees($a_show_delete = false)
90  {
91  $_SESSION['paya_delete_trustee'] = $_SESSION['paya_delete_trustee'] ? $_SESSION['paya_delete_trustee'] : array();
92 
93  $actions = array(0 => $this->lng->txt("paya_disabled"),
94  1 => $this->lng->txt("paya_enabled"));
95 
96 
97  $this->showButton('searchUser',$this->lng->txt('search_user'));
98 
99  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_trustees.html','payment');
100 
101  if($a_show_delete)
102  {
103  ilUtil::sendInfo($this->lng->txt('paya_sure_delete_selected_trustees'));
104  $this->tpl->setCurrentBlock("confirm_delete");
105  $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
106  $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
107  $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('delete'));
108  $this->tpl->parseCurrentBlock();
109  }
110 
111  if(!count($this->trustee_obj->getTrustees()))
112  {
113  ilUtil::sendInfo($this->lng->txt('paya_no_trustees'));
114 
115  return true;
116  }
117 
118  $counter = 0;
119  $f_result = array();
120 
121  $img_mail = "<img src=\"".ilUtil::getImagePath("icon_pencil_b.gif")."\" alt=\"".
122  $this->lng->txt("crs_mem_send_mail").
123  "\" title=\"".$this->lng->txt("crs_mem_send_mail")."\" border=\"0\" vspace=\"0\"/>";
124 
125 
126  foreach($this->trustee_obj->getTrustees() as $trustee)
127  {
128  // GET USER OBJ
129  if($tmp_obj = ilObjectFactory::getInstanceByObjId($trustee['trustee_id'],false))
130  {
131  $f_result[$counter][] = ilUtil::formCheckbox(in_array($trustee['trustee_id'],$_SESSION['paya_delete_trustee']) ? 1 : 0,
132  "trustee[]",
133  $trustee['trustee_id']);
134  $f_result[$counter][] = $tmp_obj->getLogin();
135  $f_result[$counter][] = $tmp_obj->getFirstname();
136  $f_result[$counter][] = $tmp_obj->getLastname();
137 
138  $f_result[$counter][] = ilUtil::formSelect((int) $trustee['perm_stat'],
139  'perm_stat['.$trustee['trustee_id'].']',
140  $actions,
141  false,
142  true);
143 
144  $f_result[$counter][] = ilUtil::formSelect((int) $trustee['perm_obj'],
145  'perm_obj['.$trustee['trustee_id'].']',
146  $actions,
147  false,
148  true);
149 
150  $f_result[$counter][] = ilUtil::formSelect((int) $trustee['perm_coupons'],
151  'perm_coupons['.$trustee['trustee_id'].']',
152  $actions,
153  false,
154  true);
155 
156 # $link_mail = "<a target=\"_blank\" href=\"./ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".
157 # $tmp_obj->getLogin()."\"".$img_mail."</a>";
158  $link_mail = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"./ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".
159  $tmp_obj->getLogin()."\">".$this->lng->txt("mail")."</a></div>";
160 
161  $f_result[$counter][] = $link_mail;
162 
163  unset($tmp_obj);
164  ++$counter;
165  }
166 
167  }
168  return $this->__showTrusteesTable($f_result);
169  }
170  function deleteTrustee()
171  {
172  if(!is_array($_POST['trustee']))
173  {
174  ilUtil::sendInfo($this->lng->txt('crs_no_users_selected'));
175  $this->showTrustees();
176 
177  return true;
178  }
179  $_SESSION['paya_delete_trustee'] = $_POST['trustee'];
180  $this->showTrustees(true);
181 
182  return true;
183  }
184 
186  {
187  if(is_array($_SESSION['paya_delete_trustee']))
188  {
189  foreach($_SESSION['paya_delete_trustee'] as $id)
190  {
191  $this->trustee_obj->setTrusteeId($id);
192  $this->trustee_obj->delete();
193  }
194  }
195  unset($_SESSION['paya_delete_trustee']);
196  ilUtil::sendInfo($this->lng->txt('paya_delete_trustee_msg'));
197  $this->showTrustees();
198 
199  return true;
200  }
201 
202  function update()
203  {
204  foreach($this->trustee_obj->getTrustees() as $trustee)
205  {
206  $this->trustee_obj->setTrusteeId($trustee['trustee_id']);
207  $this->trustee_obj->toggleStatisticPermission($_POST['perm_stat']["$trustee[trustee_id]"]);
208  $this->trustee_obj->toggleObjectPermission($_POST['perm_obj']["$trustee[trustee_id]"]);
209  $this->trustee_obj->toggleCouponsPermission($_POST['perm_coupons']["$trustee[trustee_id]"]);
210  $this->trustee_obj->modify();
211  }
212  ilUtil::sendInfo($this->lng->txt('paya_updated_trustees'));
213  $this->showTrustees();
214 
215  return true;
216  }
217 
218  function searchUser()
219  {
220  $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.paya_user_search.html",'payment');
221  $this->showButton('showTrustees',$this->lng->txt('back'));
222 
223  $this->lng->loadLanguageModule('search');
224 
225  $this->tpl->setVariable("F_ACTION",$this->ctrl->getFormAction($this));
226  $this->tpl->setVariable("SEARCH_ASSIGN_USR",$this->lng->txt("crs_search_members"));
227  $this->tpl->setVariable("SEARCH_SEARCH_TERM",$this->lng->txt("search_search_term"));
228  $this->tpl->setVariable("SEARCH_VALUE",$_SESSION["pays_search_str_trustee"] ? $_SESSION["pays_search_str_trustee"] : "");
229  $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt("cancel"));
230  $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("search"));
231  $this->tpl->setVariable("SEARCH","performSearch");
232  $this->tpl->setVariable("CANCEL","showTrustees");
233 
234  return true;
235  }
236 
237  function newSearch()
238  {
239  $_SESSION["paya_search_str"] = $_POST["search_str"];
240  $this->performSearch();
241  }
242 
243  function performSearch()
244  {
245  // SAVE it to allow sort in tables
246  $_SESSION["pays_search_str_trustee"] = $_POST["search_str"] = $_POST["search_str"] ? $_POST["search_str"] : $_SESSION["pays_search_str_trustee"];
247 
248 
249  if(!$_POST["search_str"])
250  {
251  ilUtil::sendInfo($this->lng->txt("crs_search_enter_search_string"));
252 # $this->searchUser();
253  $this->showTrustees();
254 
255  return false;
256  }
257  if(!count($result = $this->__search(ilUtil::stripSlashes($_POST["search_str"]))))
258  {
259  ilUtil::sendInfo($this->lng->txt("crs_no_results_found"));
260 # $this->searchUser();
261  $this->showTrustees();
262 
263  return false;
264  }
265 
266  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.paya_usr_selection.html",'payment');
267  $this->showButton("searchUser",$this->lng->txt("back"));
268 
269  $counter = 0;
270  $f_result = array();
271  foreach($result as $user)
272  {
273  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user["id"],false))
274  {
275  continue;
276  }
277  $f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user["id"]);
278  $f_result[$counter][] = $tmp_obj->getLogin();
279  $f_result[$counter][] = $tmp_obj->getFirstname();
280  $f_result[$counter][] = $tmp_obj->getLastname();
281 
282  unset($tmp_obj);
283  ++$counter;
284  }
285  $this->__showSearchUserTable($f_result);
286  }
287 
288  function addTrustee()
289  {
290  if(!is_array($_POST["user"]))
291  {
292  ilUtil::sendInfo($this->lng->txt("crs_no_users_selected"));
293  $this->performSearch();
294 # $this->showTrustees();
295 
296  return false;
297  }
298  if(in_array($this->user_obj->getId(),$_POST['user']))
299  {
300  ilUtil::sendInfo($this->lng->txt('paya_not_assign_yourself'));
301 # $this->performSearch();
302  $this->showTrustees();
303 
304  return false;
305  }
306 
307 
308  // add them
309  $counter = 0;
310  foreach($_POST['user'] as $user_id)
311  {
312  if($this->trustee_obj->isTrustee($user_id))
313  {
314  continue;
315  }
316  $this->trustee_obj->setTrusteeId($user_id);
317  $this->trustee_obj->toggleStatisticPermission(false);
318  $this->trustee_obj->toggleObjectPermission(true);
319  $this->trustee_obj->toggleCouponsPermission(true);
320  $this->trustee_obj->add();
321  ++$counter;
322  }
323 
324  if($counter)
325  {
326  ilUtil::sendInfo($this->lng->txt('paya_added_trustee'));
327  $this->showTrustees();
328 
329  return true;
330  }
331  else
332  {
333  ilUtil::sendInfo($this->lng->txt('paya_user_already_assigned'));
334  $this->performSearch();
335 
336  return false;
337  }
338 
339  }
340  function addUser()
341  {
342  if(!$_POST['trustee_login'])
343  {
344  ilUtil::sendInfo($this->lng->txt('paya_enter_login'));
345  $this->showTrustees();
346 
347  return false;
348  }
349  if(!$user_id = ilObjUser::getUserIdByLogin($_POST['trustee_login']))
350  {
351  ilUtil::sendInfo($this->lng->txt('paya_no_valid_login'));
352  $this->showTrustees();
353 
354  return false;
355  }
356  if($this->trustee_obj->isTrustee($user_id))
357  {
358  ilUtil::sendInfo($this->lng->txt('paya_user_already_assigned'));
359  $this->showTrustees();
360 
361  return false;
362  }
363  if($user_id == $this->user_obj->getId())
364  {
365  ilUtil::sendInfo($this->lng->txt('paya_not_assign_yourself'));
366  $this->showTrustees();
367 
368  return false;
369  }
370 
371  // checks passed => add trustee
372  $this->trustee_obj->setTrusteeId($user_id);
373  $this->trustee_obj->toggleObjectPermission(false);
374  $this->trustee_obj->toggleStatisticPermission(true);
375  $this->trustee_obj->toggleCouponsPermission(true);
376  $this->trustee_obj->add();
377 
378  ilUtil::sendInfo($this->lng->txt('paya_added_trustee'));
379  $this->showTrustees();
380 
381  return true;
382  }
383 
384 
385  // PRIVATE
386  function __search($a_search_string)
387  {
388  include_once("./classes/class.ilSearch.php");
389 
390  $this->lng->loadLanguageModule("content");
391 
392  $search =& new ilSearch($this->user_obj->getId());
393  $search->setPerformUpdate(false);
394  $search->setSearchString(ilUtil::stripSlashes($a_search_string));
395  $search->setCombination("and");
396  $search->setSearchFor(array(0 => 'usr'));
397  $search->setSearchType('new');
398 
399  if($search->validate($message))
400  {
401  $search->performSearch();
402  }
403  else
404  {
405  ilUtil::sendInfo($message,true);
406  $this->ctrl->redirect($this,"searchUser");
407  }
408  return $search->getResultByType('usr');
409  }
410  function __showSearchUserTable($a_result_set)
411  {
412  $tbl =& $this->initTableGUI();
413  $tpl =& $tbl->getTemplateObject();
414 
415 
416  // SET FORMACTION
417  $tpl->setCurrentBlock("tbl_form_header");
418  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
419  $tpl->parseCurrentBlock();
420 
421  $tpl->setCurrentBlock("tbl_action_btn");
422  $tpl->setVariable("BTN_NAME","addTrustee");
423  $tpl->setVariable("BTN_VALUE",$this->lng->txt("add"));
424  $tpl->parseCurrentBlock();
425 
426  $tpl->setCurrentBlock("tbl_action_btn");
427  $tpl->setVariable("BTN_NAME","showTrustees");
428  $tpl->setVariable("BTN_VALUE",$this->lng->txt("cancel"));
429  $tpl->parseCurrentBlock();
430 
431  $tpl->setCurrentBlock("tbl_action_row");
432  $tpl->setVariable("COLUMN_COUNTS",5);
433  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
434  $tpl->parseCurrentBlock();
435 
436  $tbl->setTitle($this->lng->txt("paya_trustee_table"),"icon_usr.gif",$this->lng->txt("crs_header_edit_members"));
437  $tbl->setHeaderNames(array("",
438  $this->lng->txt("login"),
439  $this->lng->txt("firstname"),
440  $this->lng->txt("lastname")));
441  $tbl->setHeaderVars(array("",
442  "login",
443  "firstname",
444  "lastname"),
445  array("cmd" => 'performSearch',
446  "cmdClass" => "ilpaymenttrusteegui",
447  "cmdNode" => $_GET["cmdNode"],
448  'baseClass' => 'ilShopController'));
449 
450  $tbl->setColumnWidth(array("3%","32%","32%","32%"));
451 
452  $this->setTableGUIBasicData($tbl,$a_result_set);
453  $tbl->render();
454 
455  $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
456 
457  return true;
458  }
459 
460  function __showTrusteesTable($a_result_set)
461  {
462  $tbl =& $this->initTableGUI();
463  $tpl =& $tbl->getTemplateObject();
464 
465  // SET FORMAACTION
466  $tpl->setCurrentBlock("tbl_form_header");
467 
468  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
469  $tpl->parseCurrentBlock();
470 
471  $tpl->setCurrentBlock("tbl_action_row");
472 
473 /* $tpl->setCurrentBlock("input_text");
474  $tpl->setVariable("PB_TXT_NAME",'trustee_login');
475  $tpl->parseCurrentBlock();
476 
477  $tpl->setCurrentBlock("plain_button");
478  $tpl->setVariable("PBTN_NAME","addUser");
479  $tpl->setVariable("PBTN_VALUE",$this->lng->txt("crs_add_member"));
480  $tpl->parseCurrentBlock();*/
481 
482  $tpl->setCurrentBlock("input_text");
483  $tpl->setVariable("PB_TXT_NAME",'search_str');
484  $tpl->setVariable("PB_TXT_VALUE",$_SESSION["paya_search_str"]);
485  $tpl->parseCurrentBlock();
486 
487  $tpl->setCurrentBlock("plain_button");
488  $tpl->setVariable("PBTN_NAME","newSearch");
489  $tpl->setVariable("PBTN_VALUE",$this->lng->txt("crs_add_member"));
490  $tpl->parseCurrentBlock();
491 
492  $tpl->setCurrentBlock("plain_button");
493  $tpl->setVariable("PBTN_NAME","update");
494  $tpl->setVariable("PBTN_VALUE",$this->lng->txt("apply"));
495  $tpl->parseCurrentBlock();
496 
497  $tpl->setCurrentBlock("plain_buttons");
498  $tpl->parseCurrentBlock();
499 
500  $tpl->setVariable("COLUMN_COUNTS",8);
501  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
502 
503  $tpl->setCurrentBlock("tbl_action_button");
504  $tpl->setVariable("BTN_NAME","deleteTrustee");
505  $tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
506  $tpl->parseCurrentBlock();
507  $tpl->setCurrentBlock("tbl_action_row");
508  $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
509  $tpl->parseCurrentBlock();
510 
511  $tbl->setTitle($this->lng->txt("paya_trustee_table"),"icon_usr.gif",$this->lng->txt("paya_trustee_table"));
512  $tbl->setHeaderNames(array('',
513  $this->lng->txt("login"),
514  $this->lng->txt("firstname"),
515  $this->lng->txt("lastname"),
516  $this->lng->txt("paya_perm_stat"),
517  $this->lng->txt("paya_perm_obj"),
518  $this->lng->txt("paya_perm_coupons"),
519  ''));
520  $tbl->setHeaderVars(array("",
521  "login",
522  "firstname",
523  "lastname",
524  "perm_stat",
525  "perm_obj",
526  "perm_coupons",
527  "options"),
528  array("cmd" => "showTrustees",
529  "cmdClass" => "ilpaymenttrusteegui",
530  "cmdNode" => $_GET["cmdNode"],
531  'baseClass' => 'ilShopController'));
532  $tbl->setColumnWidth(array("4%","15%","15%","15%","15%","15%","15%","15%"));
533 
534 
535  $this->setTableGUIBasicData($tbl,$a_result_set);
536  $tbl->render();
537 
538  $this->tpl->setVariable("TRUSTEE_TABLE",$tbl->tpl->get());
539 
540  return true;
541  }
542 
543 }
544 ?>