ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
12include_once './Services/Payment/classes/class.ilPaymentTrustees.php';
13include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
14include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
15include_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 {
25 parent::__construct();
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 parent::prepareOutput();
39
40 $ilTabs->setTabActive('paya_header');
41 $ilTabs->setSubTabActive('paya_trustees');
42 }
43
44 public function executeCommand()
45 {
46 $cmd = $this->ctrl->getCmd();
47 switch ($this->ctrl->getNextClass($this))
48 {
49 default:
50 if(!$cmd = $this->ctrl->getCmd())
51 {
52 $cmd = 'showTrustees';
53 }
54 $this->prepareOutput();
55 $this->$cmd();
56 break;
57 }
58 }
59
60 public function cancelDelete()
61 {
62 unset($_SESSION['paya_delete_trustee']);
63 $this->showTrustees();
64
65 return true;
66 }
67
68
69 public function showTrustees($a_show_delete = false)
70 {
71 global $ilToolbar;
72
73 $_SESSION['paya_delete_trustee'] = $_SESSION['paya_delete_trustee'] ? $_SESSION['paya_delete_trustee'] : array();
74
75 $actions = array(0 => $this->lng->txt("paya_disabled"),
76 1 => $this->lng->txt("paya_enabled"));
77
78 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
79 $ul = new ilTextInputGUI($this->lng->txt("user"), "search_str");
80 $ul->setDataSource($this->ctrl->getLinkTarget($this, "performSearch", "", true));
81 $ul->setSize(20);
82 $ilToolbar->addInputItem($ul, true);
83 $ilToolbar->addFormButton($this->lng->txt("add"), "performSearch");
84 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
85
86 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.main_view.html','Services/Payment');
87
88 if($a_show_delete)
89 {
90 $oConfirmationGUI = new ilConfirmationGUI();
91
92 // set confirm/cancel commands
93 $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"performDeleteTrustee"));
94 $oConfirmationGUI->setHeaderText($this->lng->txt("paya_sure_delete_selected_trustees"));
95 $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "cancelDelete");
96 $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDeleteTrustee");
97
98 foreach($this->trustee_obj->getTrustees() as $trustee)
99 {
100 $delete_row = '';
101 if(in_array($trustee['trustee_id'],$_POST['trustee']))
102 {
103 if($tmp_obj = ilObjectFactory::getInstanceByObjId($trustee['trustee_id'],false))
104 {
105 $delete_row = $tmp_obj->getLogin().' -> '.$tmp_obj->getFirstname().' '.$tmp_obj->getLastname();
106 }
107 }
108
109 $oConfirmationGUI->addItem('',$delete_row, $delete_row);
110 }
111
112 $this->tpl->setVariable("CONFIRMATION",$oConfirmationGUI->getHTML());
113
114 }
115
116 if(!count($this->trustee_obj->getTrustees()))
117 {
118 ilUtil::sendInfo($this->lng->txt('paya_no_trustees'));
119 return true;
120 }
121
122 $counter = 0;
123 $f_result = array();
124
125 require_once 'Services/Mail/classes/class.ilMailFormCall.php';
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]['trustee_id'] = ilUtil::formCheckbox(in_array($trustee['trustee_id'],$_SESSION['paya_delete_trustee']) ? 1 : 0,
132 "trustee[]",
133 $trustee['trustee_id']);
134 $f_result[$counter]['login'] = $tmp_obj->getLogin();
135 $f_result[$counter]['firstname'] = $tmp_obj->getFirstname();
136 $f_result[$counter]['lastname'] = $tmp_obj->getLastname();
137
138 $f_result[$counter]['perm_stat'] = ilUtil::formSelect((int) $trustee['perm_stat'],
139 'perm_stat['.$trustee['trustee_id'].']',
140 $actions,
141 false,
142 true);
143
144 $f_result[$counter]['perm_obj'] = ilUtil::formSelect((int) $trustee['perm_obj'],
145 'perm_obj['.$trustee['trustee_id'].']',
146 $actions,
147 false,
148 true);
149
150 $f_result[$counter]['perm_coupons'] = 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 $url_mail = ilMailFormCall::getLinkTarget($this, '', array(), array('type' => 'new', 'rcp_to' => $tmp_obj->getLogin()));
159 $link_mail = "<div class=\"il_ContainerItemCommands\"><a class=\"il_ContainerItemCommand\" href=\"".
160 $url_mail."\">".$this->lng->txt("mail")."</a></div>";
161
162 $f_result[$counter]['options'] = $link_mail;
163
164 unset($tmp_obj);
165 ++$counter;
166 }
167 }
168 return $this->__showTrusteesTable($f_result);
169 }
170
171 public function deleteTrustee()
172 {
173 if(!is_array($_POST['trustee']))
174 {
175 ilUtil::sendInfo($this->lng->txt('crs_no_users_selected'));
176 $this->showTrustees();
177
178 return true;
179 }
180 $_SESSION['paya_delete_trustee'] = $_POST['trustee'];
181 $this->showTrustees(true);
182
183 return true;
184 }
185
186 public function performDeleteTrustee()
187 {
188 if(is_array($_SESSION['paya_delete_trustee']))
189 {
190 foreach($_SESSION['paya_delete_trustee'] as $id)
191 {
192 $this->trustee_obj->setTrusteeId($id);
193 $this->trustee_obj->delete();
194 }
195 }
196 unset($_SESSION['paya_delete_trustee']);
197 ilUtil::sendInfo($this->lng->txt('paya_delete_trustee_msg'));
198 $this->showTrustees();
199
200 return true;
201 }
202
203 public function update()
204 {
205 foreach($this->trustee_obj->getTrustees() as $trustee)
206 {
207 $this->trustee_obj->setTrusteeId($trustee['trustee_id']);
208 $this->trustee_obj->toggleStatisticPermission($_POST['perm_stat']["$trustee[trustee_id]"]);
209 $this->trustee_obj->toggleObjectPermission($_POST['perm_obj']["$trustee[trustee_id]"]);
210 $this->trustee_obj->toggleCouponsPermission($_POST['perm_coupons']["$trustee[trustee_id]"]);
211 $this->trustee_obj->modify();
212 }
213 ilUtil::sendInfo($this->lng->txt('paya_updated_trustees'));
214 $this->showTrustees();
215
216 return true;
217 }
218
219 public function performSearch()
220 {
221 if(!$_POST["search_str"])
222 {
223 ilUtil::sendInfo($this->lng->txt("crs_search_enter_search_string"));
224 $this->showTrustees();
225
226 return false;
227 }
228 if(!count($result = $this->__search(ilUtil::stripSlashes($_POST["search_str"]))))
229 {
230 ilUtil::sendInfo($this->lng->txt("crs_no_results_found"));
231 $this->showTrustees();
232
233 return false;
234 }
235
236 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.main_view.html",'Services/Payment');
237 $counter = 0;
238 $f_result = array();
239 foreach($result as $user)
240 {
241 if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user["id"],false))
242 {
243 continue;
244 }
245 $f_result[$counter]['trustee_id'] = ilUtil::formCheckbox(0,"user[]",$user["id"]);
246 $f_result[$counter]['login'] = $tmp_obj->getLogin();
247 $f_result[$counter]['firstname'] = $tmp_obj->getFirstname();
248 $f_result[$counter]['lastname'] = $tmp_obj->getLastname();
249
250 unset($tmp_obj);
251 ++$counter;
252 }
253 $this->__showSearchUserTable($f_result);
254 return true;
255 }
256
257 public function addTrustee()
258 {
259 if(!is_array($_POST["user"]))
260 {
261 ilUtil::sendInfo($this->lng->txt("crs_no_users_selected"));
262 $this->performSearch();
263
264 return false;
265 }
266 if(in_array($this->user_obj->getId(),$_POST['user']))
267 {
268 ilUtil::sendInfo($this->lng->txt('paya_not_assign_yourself'));
269 $this->showTrustees();
270
271 return false;
272 }
273
274 // add them
275 $counter = 0;
276 foreach($_POST['user'] as $user_id)
277 {
278 if($this->trustee_obj->isTrustee($user_id))
279 {
280 continue;
281 }
282 $this->trustee_obj->setTrusteeId($user_id);
283 $this->trustee_obj->toggleStatisticPermission(false);
284 $this->trustee_obj->toggleObjectPermission(true);
285 $this->trustee_obj->toggleCouponsPermission(true);
286 $this->trustee_obj->add();
287 ++$counter;
288 }
289
290 if($counter)
291 {
292 ilUtil::sendInfo($this->lng->txt('paya_added_trustee'));
293 $this->showTrustees();
294
295 return true;
296 }
297 else
298 {
299 ilUtil::sendInfo($this->lng->txt('paya_user_already_assigned'));
300 $this->performSearch();
301
302 return false;
303 }
304
305 }
306 function addUser()
307 {
308 if(!$_POST['trustee_login'])
309 {
310 ilUtil::sendInfo($this->lng->txt('paya_enter_login'));
311 $this->showTrustees();
312
313 return false;
314 }
315 if(!$user_id = ilObjUser::getUserIdByLogin($_POST['trustee_login']))
316 {
317 ilUtil::sendInfo($this->lng->txt('paya_no_valid_login'));
318 $this->showTrustees();
319
320 return false;
321 }
322 if($this->trustee_obj->isTrustee($user_id))
323 {
324 ilUtil::sendInfo($this->lng->txt('paya_user_already_assigned'));
325 $this->showTrustees();
326
327 return false;
328 }
329 if($user_id == $this->user_obj->getId())
330 {
331 ilUtil::sendInfo($this->lng->txt('paya_not_assign_yourself'));
332 $this->showTrustees();
333
334 return false;
335 }
336
337 // checks passed => add trustee
338 $this->trustee_obj->setTrusteeId($user_id);
339 $this->trustee_obj->toggleObjectPermission(true);
340 $this->trustee_obj->toggleStatisticPermission(true);
341 $this->trustee_obj->toggleCouponsPermission(true);
342 $this->trustee_obj->add();
343
344 ilUtil::sendInfo($this->lng->txt('paya_added_trustee'));
345 $this->showTrustees();
346
347 return true;
348 }
349
350
351 // PRIVATE
352 function __search($a_search_string)
353 {
354 include_once("./Services/Search/classes/class.ilSearch.php");
355
356 $this->lng->loadLanguageModule("content");
357
358 $search = new ilSearch($this->user_obj->getId());
359 $search->setPerformUpdate(false);
360 $search->setSearchString(ilUtil::stripSlashes($a_search_string));
361 $search->setCombination("and");
362 $search->setSearchFor(array(0 => 'usr'));
363 $search->setSearchType('new');
364
365 if($search->validate($message))
366 {
367 $search->performSearch();
368 }
369 else
370 {
371 ilUtil::sendInfo($message,true);
372 $this->ctrl->redirect($this,"searchUser");
373 }
374 return $search->getResultByType('usr');
375 }
376 function __showSearchUserTable($a_result_set)
377 {
378 $tbl = new ilShopTableGUI($this);
379
380 $tbl->setTitle($this->lng->txt("paya_trustee_table"));
381 $tbl->setId('tbl_search_user_trustee');
382 $tbl->setRowTemplate("tpl.shop_users_row.html", "Services/Payment");
383
384 $tbl->addColumn(' ', 'trustee_id', '1%', true);
385 $tbl->addColumn($this->lng->txt('login'), 'login', '10%');
386 $tbl->addColumn($this->lng->txt('firstname'),'firstname','20%');
387 $tbl->addColumn($this->lng->txt('lastname'), 'lastname', '20%');
388
389 $tbl->setSelectAllCheckbox('user');
390 $tbl->addMultiCommand("addTrustee", $this->lng->txt("add"));
391 $tbl->addCommandButton('showTrustees',$this->lng->txt('cancel'));
392
393 $tbl->fillFooter();
394 $tbl->setData($a_result_set);
395 $this->tpl->setVariable('TABLE', $tbl->getHTML());
396
397 return true;
398 }
399
400 function __showTrusteesTable($a_result_set)
401 {
402 $tbl = new ilShopTableGUI($this);
403
404 $tbl->setTitle($this->lng->txt("paya_trustee_table"));
405 $tbl->setId('tbl_show_trustee');
406 $tbl->setRowTemplate("tpl.shop_users_row.html", "Services/Payment");
407
408 $tbl->addColumn(' ', 'trustee_id', '1%', true);
409 $tbl->addColumn($this->lng->txt('login'), 'login', '10%');
410 $tbl->addColumn($this->lng->txt('firstname'),'firstname','20%');
411 $tbl->addColumn($this->lng->txt('lastname'), 'lastname', '20%');
412 $tbl->addColumn($this->lng->txt('paya_perm_stat'), 'perm_stat', '15%');
413 $tbl->addColumn($this->lng->txt('paya_perm_obj'), 'perm_obj', '15%');
414 $tbl->addColumn($this->lng->txt('paya_perm_coupons'), 'perm_coupons', '15%');
415 $tbl->addColumn('', 'options', '5%');
416
417 $tbl->setSelectAllCheckbox('trustee_id');
418 $tbl->addMultiCommand("deleteTrustee", $this->lng->txt("delete"));
419
420 $tbl->addCommandButton('update',$this->lng->txt('apply'));
421 $tbl->setData($a_result_set);
422 $this->tpl->setVariable('TABLE', $tbl->getHTML());
423
424 return true;
425 }
426
427}
428?>
$result
$_SESSION["AccountId"]
Confirmation screen class.
static getLinkTarget($gui, $cmd, Array $gui_params=array(), Array $mail_params=array(), $context_params=array())
getUserIdByLogin($a_login)
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
showTrustees($a_show_delete=false)
Class ilShopBaseGUI.
Class ilShopTableGUI.
This class represents a text property in a property form.
static formCheckbox($checked, $varname, $value, $disabled=false)
??? @access public
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static formSelect($selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
$_POST['username']
Definition: cron.php:12
$tbl
Definition: example_048.php:81
$cmd
Definition: sahs_server.php:35