• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

payment/classes/class.ilPaymentTrusteeGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00031 include_once './payment/classes/class.ilPaymentTrustees.php';
00032 
00033 class ilPaymentTrusteeGUI extends ilPaymentBaseGUI
00034 {
00035         var $trustee_obj = null;
00036         var $user_obj;
00037         var $ctrl;
00038 
00039         function ilPaymentTrusteeGUI(&$user_obj)
00040         {
00041                 global $ilCtrl;
00042 
00043                 $this->ctrl =& $ilCtrl;
00044 
00045                 $this->ilPaymentBaseGUI();
00046 
00047                 $this->user_obj =& $user_obj;
00048                 $this->trustee_obj =& new ilPaymentTrustees($this->user_obj);
00049 
00050                 $this->lng->loadLanguageModule('crs');
00051         }
00055         function &executeCommand()
00056         {
00057                 global $tree;
00058 
00059                 $cmd = $this->ctrl->getCmd();
00060                 switch ($this->ctrl->getNextClass($this))
00061                 {
00062                         default:
00063                                 if(!$cmd = $this->ctrl->getCmd())
00064                                 {
00065                                         $cmd = 'showTrustees';
00066                                 }
00067                                 $this->$cmd();
00068                                 break;
00069                 }
00070         }
00071 
00072         function cancelDelete()
00073         {
00074                 unset($_SESSION['paya_delete_trustee']);
00075                 $this->showTrustees();
00076 
00077                 return true;
00078         }
00079 
00080 
00081         function showTrustees($a_show_delete = false)
00082         {
00083                 $_SESSION['paya_delete_trustee'] = $_SESSION['paya_delete_trustee'] ? $_SESSION['paya_delete_trustee'] : array();
00084 
00085                 $actions = array(0      => $this->lng->txt("paya_disabled"),
00086                                                  1      => $this->lng->txt("paya_enabled"));
00087 
00088 
00089                 $this->showButton('searchUser',$this->lng->txt('search_user'));
00090 
00091                 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_trustees.html',true);
00092 
00093                 if($a_show_delete)
00094                 {
00095                         sendInfo($this->lng->txt('paya_sure_delete_selected_trustees'));
00096                         $this->tpl->setCurrentBlock("confirm_delete");
00097                         $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
00098                         $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
00099                         $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('delete'));
00100                         $this->tpl->parseCurrentBlock();
00101                 }
00102 
00103                 if(!count($this->trustee_obj->getTrustees()))
00104                 {
00105                         sendInfo($this->lng->txt('paya_no_trustees'));
00106                         
00107                         return true;
00108                 }
00109                 
00110                 $counter = 0;
00111                 $f_result = array();
00112                 
00113                 $img_mail = "<img src=\"".ilUtil::getImagePath("icon_pencil_b.gif")."\" alt=\"".
00114                         $this->lng->txt("crs_mem_send_mail").
00115                         "\" title=\"".$this->lng->txt("crs_mem_send_mail")."\" border=\"0\" vspace=\"0\"/>";
00116                 
00117                 
00118                 foreach($this->trustee_obj->getTrustees() as $trustee)
00119                 {
00120                         // GET USER OBJ
00121                         if($tmp_obj = ilObjectFactory::getInstanceByObjId($trustee['trustee_id'],false))
00122                         {
00123                                 $f_result[$counter][]   = ilUtil::formCheckbox(in_array($trustee['trustee_id'],$_SESSION['paya_delete_trustee']) ? 1 : 0,
00124                                                                                                                            "trustee[]",
00125                                                                                                                            $trustee['trustee_id']);
00126                                 $f_result[$counter][]   = $tmp_obj->getLogin();
00127                                 $f_result[$counter][]   = $tmp_obj->getFirstname();
00128                                 $f_result[$counter][]   = $tmp_obj->getLastname();
00129 
00130                                 $f_result[$counter][]   = ilUtil::formSelect((int) $trustee['perm_stat'],
00131                                                                                                                          'perm_stat['.$trustee['trustee_id'].']',
00132                                                                                                                          $actions,
00133                                                                                                                          false,
00134                                                                                                                          true);
00135                                 
00136                                 $f_result[$counter][]   = ilUtil::formSelect((int) $trustee['perm_obj'],
00137                                                                                                                          'perm_obj['.$trustee['trustee_id'].']',
00138                                                                                                                          $actions,
00139                                                                                                                          false,
00140                                                                                                                          true);
00141 
00142                                 $link_mail = "<a target=\"_blank\" href=\"../mail_new.php?type=new&rcp_to=".
00143                                         $tmp_obj->getLogin()."\"".$img_mail."</a>";
00144                                 
00145                                 $f_result[$counter][]   = $link_mail;
00146 
00147                                 unset($tmp_obj);
00148                                 ++$counter;
00149                         }
00150 
00151                 }
00152                 return $this->__showTrusteesTable($f_result);
00153         }
00154         function deleteTrustee()
00155         {
00156                 if(!is_array($_POST['trustee']))
00157                 {
00158                         sendInfo($this->lng->txt('crs_no_users_selected'));
00159                         $this->showTrustees();
00160 
00161                         return true;
00162                 }
00163                 $_SESSION['paya_delete_trustee'] = $_POST['trustee'];
00164                 $this->showTrustees(true);
00165                 
00166                 return true;
00167         }
00168 
00169         function performDeleteTrustee()
00170         {
00171                 if(is_array($_SESSION['paya_delete_trustee']))
00172                 {
00173                         foreach($_SESSION['paya_delete_trustee'] as $id)
00174                         {
00175                                 $this->trustee_obj->setTrusteeId($id);
00176                                 $this->trustee_obj->delete();
00177                         }
00178                 }
00179                 unset($_SESSION['paya_delete_trustee']);
00180                 sendInfo($this->lng->txt('paya_delete_trustee_msg'));
00181                 $this->showTrustees();
00182 
00183                 return true;
00184         }
00185 
00186         function update()
00187         {
00188                 foreach($this->trustee_obj->getTrustees() as $trustee)
00189                 {
00190                         $this->trustee_obj->setTrusteeId($trustee['trustee_id']);
00191                         $this->trustee_obj->toggleStatisticPermission($_POST['perm_stat']["$trustee[trustee_id]"]);
00192                         $this->trustee_obj->toggleObjectPermission($_POST['perm_obj']["$trustee[trustee_id]"]);
00193                         $this->trustee_obj->modify();
00194                 }
00195                 sendInfo($this->lng->txt('paya_updated_trustees'));
00196                 $this->showTrustees();
00197 
00198                 return true;
00199         }
00200 
00201         function searchUser()
00202         {
00203                 $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.paya_user_search.html",true);
00204                 $this->showButton('showTrustees',$this->lng->txt('back'));
00205 
00206                 $this->lng->loadLanguageModule('search');
00207 
00208                 $this->tpl->setVariable("F_ACTION",$this->ctrl->getFormAction($this));
00209                 $this->tpl->setVariable("SEARCH_ASSIGN_USR",$this->lng->txt("crs_search_members"));
00210                 $this->tpl->setVariable("SEARCH_SEARCH_TERM",$this->lng->txt("search_search_term"));
00211                 $this->tpl->setVariable("SEARCH_VALUE",$_SESSION["pays_search_str"] ? $_SESSION["pays_search_str"] : "");
00212                 $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt("cancel"));
00213                 $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("search"));
00214 
00215                 return true;
00216         }
00217 
00218         function newSearch()
00219         {
00220                 $_SESSION["paya_search_str"] = $_POST["search_str"];
00221                 $this->performSearch();
00222         }
00223 
00224         function performSearch()
00225         {
00226                 // SAVE it to allow sort in tables
00227                 $_SESSION["paya_search_str"] = $_POST["search_str"] = $_POST["search_str"] ? $_POST["search_str"] : $_SESSION["paya_search_str"];
00228 
00229 
00230                 if(!$_POST["search_str"])
00231                 {
00232                         sendInfo($this->lng->txt("crs_search_enter_search_string"));
00233 #                       $this->searchUser();
00234                         $this->showTrustees();
00235 
00236                         return false;
00237                 }
00238                 if(!count($result = $this->__search(ilUtil::stripSlashes($_POST["search_str"]))))
00239                 {
00240                         sendInfo($this->lng->txt("crs_no_results_found"));
00241 #                       $this->searchUser();
00242                         $this->showTrustees();
00243 
00244                         return false;
00245                 }
00246 
00247                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.paya_usr_selection.html",true);
00248 #               $this->showButton("searchUser",$this->lng->txt("crs_new_search"));
00249                 $this->showButton("showTrustees",$this->lng->txt("back"));
00250                 
00251                 $counter = 0;
00252                 $f_result = array();
00253                 foreach($result as $user)
00254                 {
00255                         if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user["id"],false))
00256                         {
00257                                 continue;
00258                         }
00259                         $f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user["id"]);
00260                         $f_result[$counter][] = $tmp_obj->getLogin();
00261                         $f_result[$counter][] = $tmp_obj->getLastname();
00262                         $f_result[$counter][] = $tmp_obj->getFirstname();
00263                         
00264                         unset($tmp_obj);
00265                         ++$counter;
00266                 }
00267                 $this->__showSearchUserTable($f_result);
00268         }
00269 
00270         function addTrustee()
00271         {
00272                 if(!is_array($_POST["user"]))
00273                 {
00274                         sendInfo($this->lng->txt("crs_no_users_selected"));
00275                         $this->performSearch();
00276 #                       $this->showTrustees();
00277 
00278                         return false;
00279                 }
00280                 if(in_array($this->user_obj->getId(),$_POST['user']))
00281                 {
00282                         sendInfo($this->lng->txt('paya_not_assign_yourself'));
00283 #                       $this->performSearch();
00284                         $this->showTrustees();
00285 
00286                         return false;
00287                 }
00288 
00289 
00290                 // add them
00291                 $counter = 0;
00292                 foreach($_POST['user'] as $user_id)
00293                 {
00294                         if($this->trustee_obj->isTrustee($user_id))
00295                         {
00296                                 continue;
00297                         }
00298                         $this->trustee_obj->setTrusteeId($user_id);
00299                         $this->trustee_obj->toggleStatisticPermission(false);
00300                         $this->trustee_obj->toggleObjectPermission(true);
00301                         $this->trustee_obj->add();
00302                         ++$counter;
00303                 }
00304 
00305                 if($counter)
00306                 {
00307                         sendInfo($this->lng->txt('paya_added_trustee'));
00308                         $this->showTrustees();
00309 
00310                         return true;
00311                 }
00312                 else
00313                 {
00314                         sendInfo($this->lng->txt('paya_user_already_assigned'));
00315                         $this->performSearch();
00316 
00317                         return false;
00318                 }
00319 
00320         }
00321         function addUser()
00322         {
00323                 if(!$_POST['trustee_login'])
00324                 {
00325                         sendInfo($this->lng->txt('paya_enter_login'));
00326                         $this->showTrustees();
00327                         
00328                         return false;
00329                 }
00330                 if(!$user_id = ilObjUser::getUserIdByLogin($_POST['trustee_login']))
00331                 {
00332                         sendInfo($this->lng->txt('paya_no_valid_login'));
00333                         $this->showTrustees();
00334                         
00335                         return false;
00336                 }
00337                 if($this->trustee_obj->isTrustee($user_id))
00338                 {
00339                         sendInfo($this->lng->txt('paya_user_already_assigned'));
00340                         $this->showTrustees();
00341                         
00342                         return false;
00343                 }
00344                 if($user_id == $this->user_obj->getId())
00345                 {
00346                         sendInfo($this->lng->txt('paya_not_assign_yourself'));
00347                         $this->showTrustees();
00348 
00349                         return false;
00350                 }
00351                 
00352                 // checks passed => add trustee
00353                 $this->trustee_obj->setTrusteeId($user_id);
00354                 $this->trustee_obj->toggleObjectPermission(false);
00355                 $this->trustee_obj->toggleStatisticPermission(true);
00356                 $this->trustee_obj->add();
00357 
00358                 sendInfo($this->lng->txt('paya_added_trustee'));
00359                 $this->showTrustees();
00360 
00361                 return true;
00362         }
00363         
00364 
00365         // PRIVATE
00366         function __search($a_search_string)
00367         {
00368                 include_once("./classes/class.ilSearch.php");
00369 
00370                 $this->lng->loadLanguageModule("content");
00371 
00372                 $search =& new ilSearch($this->user_obj->getId());
00373                 $search->setPerformUpdate(false);
00374                 $search->setSearchString(ilUtil::stripSlashes($a_search_string));
00375                 $search->setCombination("and");
00376                 $search->setSearchFor(array(0 => 'usr'));
00377                 $search->setSearchType('new');
00378 
00379                 if($search->validate($message))
00380                 {
00381                         $search->performSearch();
00382                 }
00383                 else
00384                 {
00385                         sendInfo($message,true);
00386                         $this->ctrl->redirect($this,"searchUser");
00387                 }
00388                 return $search->getResultByType('usr');
00389         }
00390         function __showSearchUserTable($a_result_set)
00391         {
00392                 $tbl =& $this->initTableGUI();
00393                 $tpl =& $tbl->getTemplateObject();
00394 
00395 
00396                 // SET FORMACTION
00397                 $tpl->setCurrentBlock("tbl_form_header");
00398                 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00399                 $tpl->parseCurrentBlock();
00400 
00401                 $tpl->setCurrentBlock("tbl_action_btn");
00402                 $tpl->setVariable("BTN_NAME","showTrustees");
00403                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("cancel"));
00404                 $tpl->parseCurrentBlock();
00405 
00406                 $tpl->setCurrentBlock("tbl_action_btn");
00407                 $tpl->setVariable("BTN_NAME","addTrustee");
00408                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("add"));
00409                 $tpl->parseCurrentBlock();
00410 
00411                 $tpl->setCurrentBlock("tbl_action_row");
00412                 $tpl->setVariable("COLUMN_COUNTS",5);
00413                 $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
00414                 $tpl->parseCurrentBlock();
00415 
00416                 $tbl->setTitle($this->lng->txt("paya_trustee_table"),"icon_usr_b.gif",$this->lng->txt("crs_header_edit_members"));
00417                 $tbl->setHeaderNames(array("",
00418                                                                    $this->lng->txt("login"),
00419                                                                    $this->lng->txt("firstname"),
00420                                                                    $this->lng->txt("lastname")));
00421                 $tbl->setHeaderVars(array("",
00422                                                                   "login",
00423                                                                   "firstname",
00424                                                                   "lastname"),
00425                                                         array("cmd" => 'performSearch',
00426                                                                   "cmdClass" => "ilpaymenttrusteegui",
00427                                                                   "cmdNode" => $_GET["cmdNode"]));
00428 
00429                 $tbl->setColumnWidth(array("3%","32%","32%","32%"));
00430 
00431                 $this->setTableGUIBasicData($tbl,$a_result_set);
00432                 $tbl->render();
00433                 
00434                 $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
00435 
00436                 return true;
00437         }
00438         
00439         function __showTrusteesTable($a_result_set)
00440         {
00441                 $tbl =& $this->initTableGUI();
00442                 $tpl =& $tbl->getTemplateObject();
00443 
00444                 // SET FORMAACTION
00445                 $tpl->setCurrentBlock("tbl_form_header");
00446 
00447                 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00448                 $tpl->parseCurrentBlock();
00449 
00450                 $tpl->setCurrentBlock("tbl_action_row");
00451 
00452 /*              $tpl->setCurrentBlock("input_text");
00453                 $tpl->setVariable("PB_TXT_NAME",'trustee_login');
00454                 $tpl->parseCurrentBlock();
00455 
00456                 $tpl->setCurrentBlock("plain_button");
00457                 $tpl->setVariable("PBTN_NAME","addUser");
00458                 $tpl->setVariable("PBTN_VALUE",$this->lng->txt("crs_add_member"));
00459                 $tpl->parseCurrentBlock();*/
00460 
00461                 $tpl->setCurrentBlock("input_text");
00462                 $tpl->setVariable("PB_TXT_NAME",'search_str');
00463                 $tpl->setVariable("PB_TXT_VALUE",$_SESSION["paya_search_str"]);
00464                 $tpl->parseCurrentBlock();
00465 
00466                 $tpl->setCurrentBlock("plain_button");
00467                 $tpl->setVariable("PBTN_NAME","newSearch");
00468                 $tpl->setVariable("PBTN_VALUE",$this->lng->txt("crs_add_member"));
00469                 $tpl->parseCurrentBlock();
00470 
00471                 $tpl->setCurrentBlock("plain_button");
00472                 $tpl->setVariable("PBTN_NAME","update");
00473                 $tpl->setVariable("PBTN_VALUE",$this->lng->txt("apply"));
00474                 $tpl->parseCurrentBlock();
00475 
00476                 $tpl->setCurrentBlock("plain_buttons");
00477                 $tpl->parseCurrentBlock();
00478 
00479                 $tpl->setVariable("COLUMN_COUNTS",7);
00480                 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00481 
00482                 $tpl->setCurrentBlock("tbl_action_button");
00483                 $tpl->setVariable("BTN_NAME","deleteTrustee");
00484                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
00485                 $tpl->parseCurrentBlock();
00486                 $tpl->setCurrentBlock("tbl_action_row");
00487                 $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
00488                 $tpl->parseCurrentBlock();
00489 
00490                 $tbl->setTitle($this->lng->txt("paya_trustee_table"),"icon_usr_b.gif",$this->lng->txt("paya_trustee_table"));
00491                 $tbl->setHeaderNames(array('',
00492                                                                    $this->lng->txt("login"),
00493                                                                    $this->lng->txt("firstname"),
00494                                                                    $this->lng->txt("lastname"),
00495                                                                    $this->lng->txt("paya_perm_stat"),
00496                                                                    $this->lng->txt("paya_perm_obj"),
00497                                                                    $this->lng->txt("crs_options")));
00498                 $tbl->setHeaderVars(array("",
00499                                                                   "login",
00500                                                                   "firstname",
00501                                                                   "lastname",
00502                                                                   "perm_stat",
00503                                                                   "perm_obj",
00504                                                                   "options"),
00505                                                         array("cmd" => "showTrustees",
00506                                                                   "cmdClass" => "ilpaymenttrusteegui",
00507                                                                   "cmdNode" => $_GET["cmdNode"]));
00508                 $tbl->setColumnWidth(array("4%","15%","15%","15%","20%","20%","15%"));
00509 
00510 
00511                 $this->setTableGUIBasicData($tbl,$a_result_set);
00512                 $tbl->render();
00513 
00514                 $this->tpl->setVariable("TRUSTEE_TABLE",$tbl->tpl->get());
00515 
00516                 return true;
00517         }
00518 
00519 }
00520 ?>

Generated on Fri Dec 13 2013 09:06:37 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1