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

classes/class.ilObjUserFolderGUI.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 */
00023 
00024 
00038 require_once "class.ilObjectGUI.php";
00039 
00040 class ilObjUserFolderGUI extends ilObjectGUI
00041 {
00042         var $ctrl;
00043 
00048         function ilObjUserFolderGUI($a_data,$a_id,$a_call_by_reference, $a_prepare_output = true)
00049         {
00050                 // TODO: move this to class.ilias.php
00051                 define('USER_FOLDER_ID',7);
00052 
00053                 $this->type = "usrf";
00054                 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,false);
00055         }
00056 
00057         function setUserOwnerId($a_id)
00058         {
00059                 $this->user_owner_id = $a_id;
00060         }
00061         function getUserOwnerId()
00062         {
00063                 return $this->user_owner_id ? $this->user_owner_id : USER_FOLDER_ID;
00064         }
00065 
00066         function &executeCommand()
00067         {
00068                 $next_class = $this->ctrl->getNextClass($this);
00069                 $cmd = $this->ctrl->getCmd();
00070 
00071                 if($this->ctrl->getTargetScript() != 'repository.php')
00072                 {
00073                         $this->prepareOutput();
00074                 }
00075 
00076                 switch($next_class)
00077                 {
00078                         case 'ilpermissiongui':
00079                                 include_once("./classes/class.ilPermissionGUI.php");
00080                                 $perm_gui =& new ilPermissionGUI($this);
00081                                 $ret =& $this->ctrl->forwardCommand($perm_gui);
00082                                 break;
00083 
00084                         default:
00085                                 if(!$cmd)
00086                                 {
00087                                         $cmd = "view";
00088                                 }
00089                                 $cmd .= "Object";
00090                                 $this->$cmd();
00091 
00092                                 break;
00093                 }
00094                 return true;
00095         }
00096 
00097         function learningProgressObject()
00098         {
00099                 include_once 'Services/Tracking/classes/class.ilOnlineTracking.php';
00100                 include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
00101 
00102                 $lp_active = ilObjUserTracking::_enabledLearningProgress();
00103 
00104                 global $ilUser,$rbacsystem;
00105 
00106                 $this->max_count = $ilUser->getPref('hits_per_page');
00107 
00108                 if (!$rbacsystem->checkAccess("read",$this->object->getRefId()))
00109                 {
00110                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00111                 }
00112 
00113                 //prepare objectlist
00114                 $data["cols"] = array("login", "firstname", "lastname", "total_online","last_login");
00115                 
00116                 $usr_data = ilObjUser::_getAllUserData(array("login","firstname","lastname",'last_login'),1);
00117                 $num_users = count($usr_data) - 1;
00118 
00119 
00120                 if ($_GET["sort_by"] == "name")
00121                 {
00122                         $_GET["sort_by"] = "login";
00123                 }
00124 
00125                 // sort and slice array
00126                 $usr_data = ilUtil::sortArray($usr_data,$_GET["sort_by"],$_GET["sort_order"]);
00127                 $usr_data = array_slice($usr_data,$_GET["offset"],$this->max_count);
00128 
00129                 foreach ($usr_data as $val)
00130                 {
00131                         if ($val["usr_id"] == ANONYMOUS_USER_ID)
00132                         {
00133                 continue;
00134             }
00135                         
00136                         $total_online = ilOnlineTracking::_getOnlineTime($val['usr_id']);
00137 
00138                         $data["data"]["$val[usr_id]"] = array(
00139                                 "login"                 => $val["login"],
00140                                 "firstname"             => $val["firstname"],
00141                                 "lastname"              => $val["lastname"],
00142                                 "total_online"  => ilFormat::_secondsToShortString($total_online),
00143                                 "last_login"    => $val['last_login']
00144                                 );
00145                 }
00146                 
00147                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.usr_list.html");
00148 
00149                 // Show Table
00150 
00151                 include_once "./classes/class.ilTableGUI.php";
00152                 $this->tpl->addBlockfile("USR_TABLE", "user_table", "tpl.table.html");
00153                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.usr_tbl_row.html");
00154 
00155                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00156 
00157                 // create table
00158                 $tbl = new ilTableGUI();
00159 
00160                 // title & header columns
00161                 $tbl->setTitle($this->object->getTitle(),"icon_usr.gif",
00162                                            $this->lng->txt("obj_".$this->object->getType()));
00163 
00164                 foreach ($data["cols"] as $val)
00165                 {
00166                         $header_names[] = $this->lng->txt($val);
00167                 }
00168 
00169                 $tbl->setHeaderNames($header_names);
00170 
00171                 $header_params = $this->ctrl->getParameterArray($this, "learningProgress");
00172                 $tbl->setHeaderVars($data["cols"],$header_params);
00173                 $tbl->setColumnWidth(array("20%","20$%","20%","20%"));
00174                 
00175 
00176                 // control
00177         //$tbl->enable("hits");
00178                 $tbl->setOrderColumn($_GET["sort_by"]);
00179                 $tbl->setOrderDirection($_GET["sort_order"]);
00180                 $tbl->setLimit($this->max_count);
00181                 $tbl->setOffset($_GET["offset"]);
00182                 $tbl->setMaxCount($num_users);
00183 
00184                 // footer
00185                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00186 
00187                 // render table
00188                 $tbl->render();
00189                 
00190                 //table cell
00191                 $counter = 0;
00192                 foreach($data['data'] as $usr_id => $fields)
00193                 {
00194                         // color changing
00195                         $css_row = ilUtil::switchColor($counter++,"tblrow1","tblrow2");
00196 
00197                         $this->tpl->setVariable("CSS_ROW", $css_row);
00198 
00199                         foreach ($fields as $key => $val)
00200                         {
00201                                 //build link
00202                                         
00203                                 // dirty workaround to have ids for function showActions (checkbox toggle option)
00204                                 $this->ids[] = $ctrl["obj_id"];
00205 
00206                                 if ($key == "login" and $lp_active)
00207                                 {
00208                                         $this->ctrl->setParameterByClass("illearningprogressgui", "ref_id",$this->object->getRefId());
00209                                         $this->ctrl->setParameterByClass("illearningprogressgui", "obj_id", $usr_id);
00210                                         $link = $this->ctrl->getLinkTargetByClass(array("ilobjusergui",'illearningprogressgui'), "");
00211                                         
00212                                         $this->tpl->setCurrentBlock("begin_link");
00213                                         $this->tpl->setVariable("LINK_TARGET", $link);
00214                                         $this->tpl->parseCurrentBlock();
00215                                         $this->tpl->touchBlock("end_link");
00216                                 }
00217 
00218                                 $this->tpl->setCurrentBlock("text");
00219                                 $this->tpl->setVariable("TEXT_CONTENT", $val);
00220                                 $this->tpl->parseCurrentBlock();
00221                                 $this->tpl->setCurrentBlock("table_cell");
00222                                 $this->tpl->parseCurrentBlock();
00223                         } //foreach
00224                         
00225                         $this->tpl->setCurrentBlock("tbl_content");
00226                         $this->tpl->setVariable("CSS_ROW", $css_row);
00227                         $this->tpl->parseCurrentBlock();
00228                 } //for
00229         }
00230 
00236         function viewObject()
00237         {
00238                 global $rbacsystem;
00239 
00240                 if (isset($_POST["user_filter"]))
00241                 {
00242                         $_SESSION["user_filter"] = $_POST["user_filter"];
00243                 }
00244                 if (!isset($_SESSION["user_filter"]))
00245                 {
00246                         $_SESSION["user_filter"] = 1;
00247                 }
00248                 
00249                 // keep offset/sorting
00250                 if (isset($_GET["sort_by"]))
00251                 {
00252                         $_SESSION["user_folder_sort_by"] = $_GET["sort_by"];
00253                 }
00254                 if (isset($_GET["sort_order"]))
00255                 {
00256                         $_SESSION["user_folder_order"] = $_GET["sort_order"];
00257                 }
00258                 if (isset($_GET["offset"]))
00259                 {
00260                         $_SESSION["user_folder_offset"] = $_GET["offset"];
00261                 }
00262                 $_GET["offset"] = $_SESSION["user_folder_offset"]; 
00263                 $_GET["sort_order"] = $_SESSION["user_folder_order"];
00264                 $_GET["sort_by"] = $_SESSION["user_folder_sort_by"];
00265 
00266                 if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
00267                 {
00268                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00269                 }
00270 
00271                 //prepare objectlist
00272                 $this->data = array();
00273                 $this->data["data"] = array();
00274                 $this->data["ctrl"] = array();
00275 
00276                 $this->data["cols"] = array("", "login", "firstname", "lastname", "email");
00277                 
00278                 $usr_data = ilObjUser::_getAllUserData(array("login","firstname","lastname","email"), $_SESSION["user_filter"]);
00279 
00280                 foreach ($usr_data as $val)
00281                 {
00282                         if ($val["usr_id"] == ANONYMOUS_USER_ID)
00283                         {
00284                 continue;
00285             }
00286 
00287                         //visible data part
00288                         $this->data["data"][] = array(
00289                                                         "login"                 => $val["login"],
00290                                                         "firstname"             => $val["firstname"],
00291                                                         "lastname"              => $val["lastname"],
00292                                                         "email"                 => $val["email"],
00293                                                         "obj_id"                => $val["usr_id"]
00294                                                 );
00295                 }
00296                 
00297                 $this->maxcount = count($this->data["data"]);
00298 
00299                 if ($_GET["offset"] >= $this->maxcount)
00300                 {
00301                         $_GET["offset"] = $_SESSION["user_folder_offset"] = 0;
00302                 }
00303                 
00304                 // TODO: correct this in objectGUI
00305                 if ($_GET["sort_by"] == "name")
00306                 {
00307                         $_GET["sort_by"] = "login";
00308                 }
00309                 
00310                 // sorting array
00311                 $this->data["data"] = ilUtil::sortArray($this->data["data"],$_GET["sort_by"],$_GET["sort_order"]);
00312                 $this->data["data"] = array_slice($this->data["data"],$_GET["offset"],$_GET["limit"]);
00313 
00314                 // now compute control information
00315                 foreach ($this->data["data"] as $key => $val)
00316                 {
00317                         $this->data["ctrl"][$key] = array(
00318                                                                                                 "ref_id"        => $this->id,
00319                                                                                                 "obj_id"        => $val["obj_id"]
00320                                                                                         );
00321                         $tmp[] = $val["obj_id"];
00322                         unset($this->data["data"][$key]["obj_id"]);
00323                 }
00324 
00325                 //add template for buttons
00326                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00327 
00328                 // display button
00329                 $this->tpl->setCurrentBlock("btn_cell");
00330                 $this->tpl->setVariable("BTN_LINK",
00331                         $this->ctrl->getLinkTarget($this, "searchUserForm"));
00332                 $this->tpl->setVariable("BTN_TXT",$this->lng->txt("search_user"));
00333                 $this->tpl->parseCurrentBlock();
00334 
00335                 //if (AUTH_DEFAULT == AUTH_LOCAL)
00336                 //{
00337                         $this->tpl->setCurrentBlock("btn_cell");
00338                         $this->tpl->setVariable("BTN_LINK",
00339                                 $this->ctrl->getLinkTarget($this, "importUserForm"));
00340                         $this->tpl->setVariable("BTN_TXT", $this->lng->txt("import_users"));
00341                         $this->tpl->parseCurrentBlock();
00342                 //}
00343 
00344                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.usr_list.html");
00345                 
00346                 $this->tpl->setCurrentBlock("filter");
00347                 $this->tpl->setVariable("FILTER_TXT_FILTER",$this->lng->txt('filter'));
00348                 $this->tpl->setVariable("SELECT_FILTER",$this->__buildUserFilterSelect());
00349                 $this->tpl->setVariable("FILTER_ACTION",$this->ctrl->getFormAction($this));
00350                 $this->tpl->setVariable("FILTER_NAME",'view');
00351                 $this->tpl->setVariable("FILTER_VALUE",$this->lng->txt('apply_filter'));
00352                 $this->tpl->parseCurrentBlock();
00353 
00354                 $this->displayList();
00355         } //function
00356 
00357 
00363         function displayList()
00364         {
00365                 include_once "./classes/class.ilTableGUI.php";
00366 
00367                 // load template for table
00368                 $this->tpl->addBlockfile("USR_TABLE", "user_table", "tpl.table.html");
00369                 // load template for table content data
00370                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
00371 
00372                 $num = 0;
00373 
00374                 //$obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
00375                 $this->tpl->setVariable("FORMACTION",
00376                         $this->ctrl->getFormAction($this));
00377 
00378                 // create table
00379                 $tbl = new ilTableGUI();
00380 
00381                 // title & header columns
00382                 $tbl->setTitle($this->object->getTitle(),"icon_usr.gif",
00383                                            $this->lng->txt("obj_".$this->object->getType()));
00384                 //$tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help"));
00385 
00386                 foreach ($this->data["cols"] as $val)
00387                 {
00388                         $header_names[] = $this->lng->txt($val);
00389                 }
00390 
00391                 $tbl->setHeaderNames($header_names);
00392 
00393                 //$header_params = array("ref_id" => $this->ref_id);
00394                 $header_params = $this->ctrl->getParameterArray($this, "view");
00395                 $tbl->setHeaderVars($this->data["cols"],$header_params);
00396                 $tbl->setColumnWidth(array("","25%","25$%","25%","25%"));
00397                 
00398 
00399                 // control
00400         //$tbl->enable("hits");
00401                 $tbl->setOrderColumn($_GET["sort_by"]);
00402                 $tbl->setOrderDirection($_GET["sort_order"]);
00403                 $tbl->setLimit($_GET["limit"]);
00404                 $tbl->setOffset($_GET["offset"]);
00405                 $tbl->setMaxCount($this->maxcount);
00406 
00407                 // footer
00408                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00409                 #$tbl->disable("footer");
00410 
00411                 // render table
00412                 $tbl->render();
00413                 
00414                 if (is_array($this->data["data"][0]))
00415                 {
00416                         //table cell
00417                         for ($i=0; $i < count($this->data["data"]); $i++)
00418                         {
00419                                 $data = $this->data["data"][$i];
00420                                 $ctrl = $this->data["ctrl"][$i];
00421 
00422                                 // color changing
00423                                 $css_row = ilUtil::switchColor($i+1,"tblrow1","tblrow2");
00424 
00425                                 $this->tpl->setCurrentBlock("checkbox");
00426                                 $this->tpl->setVariable("CHECKBOX_ID", $ctrl["obj_id"]);
00427                                 //$this->tpl->setVariable("CHECKED", $checked);
00428                                 $this->tpl->setVariable("CSS_ROW", $css_row);
00429                                 $this->tpl->parseCurrentBlock();
00430 
00431                                 $this->tpl->setCurrentBlock("table_cell");
00432                                 $this->tpl->setVariable("CELLSTYLE", "tblrow1");
00433                                 $this->tpl->parseCurrentBlock();
00434 
00435                                 foreach ($data as $key => $val)
00436                                 {
00437                                         //build link
00438                                         $this->ctrl->setParameterByClass("ilobjusergui", "ref_id", "7");
00439                                         $this->ctrl->setParameterByClass("ilobjusergui", "obj_id", $ctrl["obj_id"]);
00440                                         $link = $this->ctrl->getLinkTargetByClass("ilobjusergui", "view");
00441                                         
00442                                         // dirty workaround to have ids for function showActions (checkbox toggle option)
00443                                         $this->ids[] = $ctrl["obj_id"];
00444 
00445                                         if ($key == "login")
00446                                         {
00447                                                 $this->tpl->setCurrentBlock("begin_link");
00448                                                 $this->tpl->setVariable("LINK_TARGET", $link);
00449                                                 $this->tpl->parseCurrentBlock();
00450                                                 $this->tpl->touchBlock("end_link");
00451                                         }
00452 
00453                                         $this->tpl->setCurrentBlock("text");
00454                                         $this->tpl->setVariable("TEXT_CONTENT", $val);
00455                                         $this->tpl->parseCurrentBlock();
00456                                         $this->tpl->setCurrentBlock("table_cell");
00457                                         $this->tpl->parseCurrentBlock();
00458                                 } //foreach
00459 
00460                                 $this->tpl->setCurrentBlock("tbl_content");
00461                                 $this->tpl->setVariable("CSS_ROW", $css_row);
00462                                 $this->tpl->parseCurrentBlock();
00463                         } //for
00464                 }
00465                 
00466 /*              if (AUTH_DEFAULT != AUTH_LOCAL)
00467                 {
00468                         $this->showActions(false);
00469                 }
00470                 else*/
00471                 {
00472                         $this->showActions(true);
00473                 }
00474         }
00475         
00482         function showActions($with_subobjects = false)
00483         {
00484                 global $rbacsystem;
00485 
00486                 $operations = array();
00487 
00488                 if ($this->actions == "")
00489                 {
00490                         $d = $this->objDefinition->getActions($this->object->getType());
00491                 }
00492                 else
00493                 {
00494                         $d = $this->actions;
00495                 }
00496 
00497                 foreach ($d as $row)
00498                 {
00499                         if ($rbacsystem->checkAccess($row["name"],$this->object->getRefId()))
00500                         {
00501                                 $operations[] = $row;
00502                         }
00503                 }
00504 
00505                 if (count($operations) > 0)
00506                 {
00507                         foreach ($operations as $val)
00508                         {
00509                                 $this->tpl->setCurrentBlock("tbl_action_btn");
00510                                 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00511                                 $this->tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
00512                                 $this->tpl->setVariable("BTN_NAME", $val["name"]);
00513                                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt($val["lng"]));
00514                                 $this->tpl->parseCurrentBlock();
00515                         }
00516                 }
00517 
00518                 if ($with_subobjects === true)
00519                 {
00520                         $subobjs = $this->showPossibleSubObjects();
00521                 }
00522 
00523                 if ((count($operations) > 0) or $subobjs === true)
00524                 {
00525 
00526                         if (!empty($this->ids))
00527                         {
00528                                 $this->tpl->setCurrentBlock("tbl_select_all");
00529                                 $this->tpl->setVariable("COLUMN_COUNTS",
00530                                         count($this->data["cols"]));
00531                                 $this->tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
00532                                 $this->tpl->parseCurrentBlock();
00533 
00534                                 // set checkbox toggles
00535                                 /*
00536                                 $this->tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
00537                                 $this->tpl->setVariable("JS_VARNAME","id");                     
00538                                 $this->tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($this->ids));
00539                                 $this->tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
00540                                 $this->tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
00541                                 $this->tpl->parseCurrentBlock();*/
00542                         }
00543                 
00544                         $this->tpl->setCurrentBlock("tbl_action_row");
00545                         $this->tpl->setVariable("COLUMN_COUNTS",count($this->data["cols"]));
00546                         $this->tpl->parseCurrentBlock();
00547                 }
00548         }
00549 
00556         function showPossibleSubObjects()
00557         {
00558                 global $rbacsystem;
00559 
00560                 $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
00561                 
00562                 if (!$rbacsystem->checkAccess('create_user',$this->object->getRefId()))
00563                 {
00564                         unset($d["usr"]);                       
00565                 }
00566 
00567                 if (count($d) > 0)
00568                 {
00569                         foreach ($d as $row)
00570                         {
00571                             $count = 0;
00572                                 if ($row["max"] > 0)
00573                                 {
00574                                         //how many elements are present?
00575                                         for ($i=0; $i<count($this->data["ctrl"]); $i++)
00576                                         {
00577                                                 if ($this->data["ctrl"][$i]["type"] == $row["name"])
00578                                                 {
00579                                                     $count++;
00580                                                 }
00581                                         }
00582                                 }
00583                                 if ($row["max"] == "" || $count < $row["max"])
00584                                 {
00585                                         $subobj[] = $row["name"];
00586                                 }
00587                         }
00588                 }
00589 
00590                 if (is_array($subobj))
00591                 {
00592                         //build form
00593                         $opts = ilUtil::formSelect(12,"new_type",$subobj);
00594                         $this->tpl->setCurrentBlock("add_object");
00595                         $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
00596                         $this->tpl->setVariable("BTN_NAME", "create");
00597                         $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
00598                         $this->tpl->parseCurrentBlock();
00599                         
00600                         return true;
00601                 }
00602 
00603                 return false;
00604         }
00605 
00611         function confirmedDeleteObject()
00612         {
00613                 global $rbacsystem;
00614 
00615                 // FOR NON_REF_OBJECTS WE CHECK ACCESS ONLY OF PARENT OBJECT ONCE
00616                 if (!$rbacsystem->checkAccess('delete',$this->object->getRefId()))
00617                 {
00618                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_delete"),$this->ilias->error_obj->WARNING);
00619                 }
00620 
00621                 if (in_array($_SESSION["AccountId"],$_SESSION["saved_post"]))
00622                 {
00623                         $this->ilias->raiseError($this->lng->txt("msg_no_delete_yourself"),$this->ilias->error_obj->WARNING);
00624                 }
00625 
00626                 // FOR ALL SELECTED OBJECTS
00627                 foreach ($_SESSION["saved_post"] as $id)
00628                 {
00629                         // instatiate correct object class (usr)
00630                         $obj =& $this->ilias->obj_factory->getInstanceByObjId($id);
00631                         $obj->delete();
00632                 }
00633 
00634                 // Feedback
00635                 sendInfo($this->lng->txt("user_deleted"),true);
00636 
00637                 $this->ctrl->redirect($this, "view");
00638         }
00639 
00643         function deleteObject()
00644         {
00645                 if(!isset($_POST["id"]))
00646                 {
00647                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00648                 }
00649                 // SAVE POST VALUES
00650                 $_SESSION["saved_post"] = $_POST["id"];
00651 
00652                 unset($this->data);
00653                 $this->data["cols"] = array("type", "title", "description", "last_change");
00654 
00655                 foreach($_POST["id"] as $id)
00656                 {
00657                         $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($id);
00658 
00659                         $this->data["data"]["$id"] = array(
00660                                 "type"        => $obj_data->getType(),
00661                                 "title"       => $obj_data->getTitle(),
00662                                 "desc"        => $obj_data->getDescription(),
00663                                 "last_update" => $obj_data->getLastUpdateDate());
00664                 }
00665 
00666                 $this->data["buttons"] = array( "cancelDelete"  => $this->lng->txt("cancel"),
00667                                                                   "confirmedDelete"  => $this->lng->txt("confirm"));
00668 
00669                 $this->getTemplateFile("confirm");
00670 
00671                 sendInfo($this->lng->txt("info_delete_sure"));
00672 
00673                 $this->tpl->setVariable("FORMACTION",
00674                         $this->ctrl->getFormAction($this));
00675 
00676                 // BEGIN TABLE HEADER
00677                 foreach ($this->data["cols"] as $key)
00678                 {
00679                         $this->tpl->setCurrentBlock("table_header");
00680                         $this->tpl->setVariable("TEXT",$this->lng->txt($key));
00681                         $this->tpl->parseCurrentBlock();
00682                 }
00683                 // END TABLE HEADER
00684 
00685                 // BEGIN TABLE DATA
00686                 $counter = 0;
00687 
00688                 foreach($this->data["data"] as $key => $value)
00689                 {
00690                         // BEGIN TABLE CELL
00691                         foreach($value as $key => $cell_data)
00692                         {
00693                                 $this->tpl->setCurrentBlock("table_cell");
00694 
00695                                 // CREATE TEXT STRING
00696                                 if($key == "type")
00697                                 {
00698                                         $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
00699                                 }
00700                                 else
00701                                 {
00702                                         $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
00703                                 }
00704                                 $this->tpl->parseCurrentBlock();
00705                         }
00706 
00707                         $this->tpl->setCurrentBlock("table_row");
00708                         $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
00709                         $this->tpl->parseCurrentBlock();
00710                         // END TABLE CELL
00711                 }
00712                 // END TABLE DATA
00713 
00714                 // BEGIN OPERATION_BTN
00715                 foreach($this->data["buttons"] as $name => $value)
00716                 {
00717                         $this->tpl->setCurrentBlock("operation_btn");
00718                         $this->tpl->setVariable("BTN_NAME",$name);
00719                         $this->tpl->setVariable("BTN_VALUE",$value);
00720                         $this->tpl->parseCurrentBlock();
00721                 }
00722         }
00723         
00729         function searchUserFormObject ()
00730         {
00731                 $this->tabs_gui->setTabActive('obj_usrf');
00732 
00733                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.usr_search_form.html");
00734 
00735                 $this->tpl->setVariable("FORMACTION",
00736                         $this->ctrl->getFormAction($this));
00737                 $this->tpl->setVariable("USERNAME_CHECKED", " checked=\"checked\"");
00738                 $this->tpl->setVariable("FIRSTNAME_CHECKED", " checked=\"checked\"");
00739                 $this->tpl->setVariable("LASTNAME_CHECKED", " checked=\"checked\"");
00740                 $this->tpl->setVariable("EMAIL_CHECKED", " checked=\"checked\"");
00741                 $this->tpl->setVariable("ACTIVE_CHECKED", " checked=\"checked\"");
00742                 $this->tpl->setVariable("TXT_SEARCH_USER",$this->lng->txt("search_user"));
00743                 $this->tpl->setVariable("TXT_SEARCH_IN",$this->lng->txt("search_in"));
00744                 $this->tpl->setVariable("TXT_SEARCH_USERNAME",$this->lng->txt("username"));
00745                 $this->tpl->setVariable("TXT_SEARCH_FIRSTNAME",$this->lng->txt("firstname"));
00746                 $this->tpl->setVariable("TXT_SEARCH_LASTNAME",$this->lng->txt("lastname"));
00747                 $this->tpl->setVariable("TXT_SEARCH_EMAIL",$this->lng->txt("email"));
00748         $this->tpl->setVariable("TXT_SEARCH_ACTIVE",$this->lng->txt("search_active"));
00749         $this->tpl->setVariable("TXT_SEARCH_INACTIVE",$this->lng->txt("search_inactive"));
00750                 $this->tpl->setVariable("BUTTON_SEARCH",$this->lng->txt("search"));
00751                 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00752         $this->tpl->setVariable("TXT_SEARCH_NOTE",$this->lng->txt("search_note"));
00753                 $this->tpl->setVariable("ACTIVE_CHECKED","checked=\"checked\"");
00754         }
00755 
00756         function searchCancelledObject()
00757         {
00758                 sendInfo($this->lng->txt("action_aborted"),true);
00759 
00760                 $this->ctrl->redirect($this, "view");
00761         }
00762 
00763         function searchUserObject()
00764         {
00765                 global $rbacreview;
00766 
00767                 $obj_str = "&obj_id=".$this->obj_id;
00768 
00769                 $_POST["search_string"] = trim($_POST["search_string"]) ? trim($_POST["search_string"]) : trim(urldecode($_GET["search_string"]));
00770         $_POST["search_fields"] = $_POST["search_fields"] ? $_POST["search_fields"] : explode(",",urldecode($_GET["search_fields"]));
00771                 $_SESSION['us_active'] = isset($_POST['active']) ? $_POST['active'] : $_SESSION['us_active'];
00772 
00773         if (empty($_POST["search_string"]))
00774         {
00775             $_POST["search_string"] = "%";
00776         }
00777 
00778         if (empty($_POST["search_fields"]))
00779         {
00780             $_POST["search_fields"] = array();
00781         }
00782                 if (count($search_result = ilObjUser::searchUsers($_POST["search_string"],$_SESSION['us_active'])) == 0)
00783                 {
00784                 if ($_POST["search_string"] == "%")
00785             {
00786                     $_POST["search_string"] = "";
00787                 }
00788                         $msg = $this->lng->txt("msg_no_search_result");
00789                         if ($_POST["search_string"] != "")
00790                         {
00791                                 $msg .= " ".$this->lng->txt("with")." '".htmlspecialchars($_POST["search_string"])."'";
00792                         }
00793                         sendInfo($msg, true);
00794                         $this->ctrl->redirect($this, "searchUserForm");
00795                 }
00796                 //add template for buttons
00797                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00798                 
00799                 // display button
00800                 $this->tpl->setCurrentBlock("btn_cell");
00801                 $this->tpl->setVariable("BTN_LINK",
00802                         $this->ctrl->getLinkTarget($this, "searchUserForm"));
00803                 $this->tpl->setVariable("BTN_TXT",$this->lng->txt("search_new"));
00804                 $this->tpl->parseCurrentBlock();
00805 
00806         $this->data["cols"] = array("", "login", "firstname", "lastname", "email", "active");
00807 
00808                 if($_SESSION['us_active'] == 1)
00809                 {
00810             $searchActive = true;
00811                 }
00812         else
00813         {
00814             $searchInactive = true;
00815         }
00816 
00817                 foreach ($search_result as $key => $val)
00818                 {
00819             $val["active_text"] = $this->lng->txt("inactive");
00820             if ($val["active"])
00821             {
00822                 $val["active_text"] = $this->lng->txt("active");
00823             }
00824 
00825                         // check if the fields are set
00826                         $searchStringToLower = strtolower($_POST["search_string"]);
00827                         $displaySearchResult = false;
00828                         if (in_array("username", $_POST["search_fields"]))
00829                                 if (strpos(strtolower($val["login"]), strtolower($_POST["search_string"])) !== false)
00830                                         $displaySearchResult = true;
00831                         if (in_array("firstname", $_POST["search_fields"]))
00832                                 if (strpos(strtolower($val["firstname"]), strtolower($_POST["search_string"])) !== false)
00833                                         $displaySearchResult = true;
00834                         if (in_array("lastname", $_POST["search_fields"]))
00835                                 if (strpos(strtolower($val["lastname"]), strtolower($_POST["search_string"])) !== false)
00836                                         $displaySearchResult = true;
00837                         if (in_array("email", $_POST["search_fields"]))
00838                                 if (strpos(strtolower($val["email"]), strtolower($_POST["search_string"])) !== false)
00839                                         $displaySearchResult = true;
00840                         if (($val["active"] == 1) && ($searchActive == true) ||
00841                                 ($val["active"] == 0) && ($searchInactive == true))
00842             {
00843                                 if ((strcmp($_POST["search_string"], "%") == 0) || $displaySearchResult)
00844                                 {
00845                                         //visible data part
00846                                         $this->data["data"][] = array(
00847                                                 "login"         => $val["login"],
00848                                                 "firstname"     => $val["firstname"],
00849                                                 "lastname"      => $val["lastname"],
00850                                                 "email"         => $val["email"],
00851                                                 "active"        => $val["active_text"],
00852                                                 "obj_id"        => $val["usr_id"]
00853                                                 );
00854                                 }
00855             }
00856                 }
00857                 if (count($this->data["data"]) == 0)
00858                 {
00859                         sendInfo($this->lng->txt("msg_no_search_result")." ".$this->lng->txt("with")." '".htmlspecialchars($_POST["search_string"])."'",true);
00860 
00861                         $this->ctrl->redirect($this, "searchUserForm");
00862                 }
00863                 
00864                 $this->maxcount = count($this->data["data"]);
00865 
00866                 // TODO: correct this in objectGUI
00867                 if ($_GET["sort_by"] == "name")
00868                 {
00869                         $_GET["sort_by"] = "login";
00870                 }
00871 
00872                 // sorting array
00873                 $this->data["data"] = ilUtil::sortArray($this->data["data"],$_GET["sort_by"],$_GET["sort_order"]);
00874                 $this->data["data"] = array_slice($this->data["data"],$_GET["offset"],$_GET["limit"]);
00875 
00876                 // now compute control information
00877                 foreach ($this->data["data"] as $key => $val)
00878                 {
00879                         $this->data["ctrl"][$key] = array(
00880                                                                                                 "ref_id"        => $this->id,
00881                                                                                                 "obj_id"        => $val["obj_id"]
00882                                                                                         );
00883                         $tmp[] = $val["obj_id"];
00884                         unset($this->data["data"][$key]["obj_id"]);
00885                 }
00886 
00887                 // remember filtered users
00888                 $_SESSION["user_list"] = $tmp;          
00889         
00890                 // load template for table
00891                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
00892                 // load template for table content data
00893                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
00894 
00895                 $num = 0;
00896 
00897                 $this->ctrl->setParameter($this, "sort_by", "name");
00898                 $this->ctrl->setParameter($this, "sort_order", $_GET["sort_order"]);
00899                 $this->ctrl->setParameter($this, "offset", $_GET["offset"]);
00900                 $this->tpl->setVariable("FORMACTION",
00901                         $this->ctrl->getFormAction($this));
00902 
00903                 // create table
00904                 include_once "./classes/class.ilTableGUI.php";
00905                 $tbl = new ilTableGUI();
00906 
00907                 // title & header columns
00908                 $tbl->setTitle($this->lng->txt("search_result"),"icon_".$this->object->getType().".gif",$this->lng->txt("obj_".$this->object->getType()));
00909                 $tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help"));
00910                 
00911                 foreach ($this->data["cols"] as $val)
00912                 {
00913                         $header_names[] = $this->lng->txt($val);
00914                 }
00915                 
00916                 $tbl->setHeaderNames($header_names);
00917 
00918                 $header_params = $this->ctrl->getParameterArray($this, "searchUser");
00919                 $header_params["search_string"] = urlencode($_POST["search_string"]);
00920                 $header_params["search_fields"] = urlencode(implode(",",$_POST["search_fields"]));
00921 
00922                 $tbl->setHeaderVars($this->data["cols"],$header_params);
00923                 $tbl->setColumnWidth(array("","25%","25$%","25%","25%"));
00924 
00925                 // control
00926         $tbl->enable("hits");
00927                 $tbl->setOrderColumn($_GET["sort_by"]);
00928                 $tbl->setOrderDirection($_GET["sort_order"]);
00929                 $tbl->setLimit($_GET["limit"]);
00930                 $tbl->setOffset($_GET["offset"]);
00931                 $tbl->setMaxCount($this->maxcount);
00932 
00933                 $this->tpl->setVariable("COLUMN_COUNTS",count($this->data["cols"]));    
00934 
00935                 // footer
00936                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00937 
00938                 // render table
00939                 $tbl->render();
00940 
00941                 if (is_array($this->data["data"][0]))
00942                 {
00943                         //table cell
00944                         for ($i=0; $i < count($this->data["data"]); $i++)
00945                         {
00946                                 $data = $this->data["data"][$i];
00947                                 $ctrl = $this->data["ctrl"][$i];
00948 
00949                                 // dirty workaround to have ids for function showActions (checkbox toggle option)
00950                                 $this->ids[] = $ctrl["obj_id"];
00951                                         
00952                                 // color changing
00953                                 $css_row = ilUtil::switchColor($i+1,"tblrow1","tblrow2");
00954 
00955                                 $this->tpl->setCurrentBlock("checkbox");
00956                                 $this->tpl->setVariable("CHECKBOX_ID", $ctrl["obj_id"]);
00957                                 //$this->tpl->setVariable("CHECKED", $checked);
00958                                 $this->tpl->setVariable("CSS_ROW", $css_row);
00959                                 $this->tpl->parseCurrentBlock();
00960 
00961                                 $this->tpl->setCurrentBlock("table_cell");
00962                                 $this->tpl->setVariable("CELLSTYLE", "tblrow1");
00963                                 $this->tpl->parseCurrentBlock();
00964 
00965                                 foreach ($data as $key => $val)
00966                                 {
00967                                         //build link
00968                                         $this->ctrl->setParameterByClass("ilobjusergui", "ref_id", "7");
00969                                         $this->ctrl->setParameterByClass("ilobjusergui", "obj_id", $ctrl["obj_id"]);
00970                                         $link = $this->ctrl->getLinkTargetByClass("ilobjusergui", "view");
00971 
00972                                         if ($key == "login")
00973                                         {
00974                                                 $this->tpl->setCurrentBlock("begin_link");
00975                                                 $this->tpl->setVariable("LINK_TARGET", $link);
00976                                                 $this->tpl->parseCurrentBlock();
00977                                                 $this->tpl->touchBlock("end_link");
00978                                         }
00979 
00980                                         $this->tpl->setCurrentBlock("text");
00981                                         $this->tpl->setVariable("TEXT_CONTENT", $val);
00982                                         $this->tpl->parseCurrentBlock();
00983                                         $this->tpl->setCurrentBlock("table_cell");
00984                                         $this->tpl->parseCurrentBlock();
00985                                 } //foreach
00986 
00987                                 $this->tpl->setCurrentBlock("tbl_content");
00988                                 $this->tpl->setVariable("CSS_ROW", $css_row);
00989                                 $this->tpl->parseCurrentBlock();
00990                         } //for
00991                         
00992                         $this->showActions(true);
00993                 }
00994         }
00995 
00999         function importUserFormObject ()
01000         {
01001                 $this->tabs_gui->setTabActive('obj_usrf');
01002                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.usr_import_form.html");
01003 
01004                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this));
01005 
01006                 $this->tpl->setVariable("TXT_IMPORT_USERS", $this->lng->txt("import_users"));
01007                 $this->tpl->setVariable("TXT_IMPORT_FILE", $this->lng->txt("import_file"));
01008                 $this->tpl->setVariable("TXT_IMPORT_ROOT_USER", $this->lng->txt("import_root_user"));
01009 
01010                 $this->tpl->setVariable("BTN_IMPORT", $this->lng->txt("upload"));
01011                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
01012         }
01013 
01014 
01020         function importCancelledObject()
01021         {
01022                 // purge user import directory
01023                 $import_dir = $this->getImportDir();
01024                 if (@is_dir($import_dir))
01025                 {
01026                         ilUtil::delDir($import_dir);
01027                 }
01028 
01029                 sendInfo($this->lng->txt("msg_cancel"),true);
01030 
01031                 if (strtolower($_GET["baseClass"]) == 'iladministrationgui')
01032                 {
01033                         $this->ctrl->redirect($this, "view");
01034                         //ilUtil::redirect($this->ctrl->getLinkTarget($this,$return_location));
01035                 }
01036                 else
01037                 {
01038                         $this->ctrl->redirectByClass('ilobjcategorygui','listUsers');
01039                 }
01040         }
01041 
01045         function getImportDir()
01046         {
01047                 // For each user session a different directory must be used to prevent
01048                 // that one user session overwrites the import data that another session
01049                 // is currently importing.
01050                 global $ilUser;
01051                 $importDir = ilUtil::getDataDir().'/user_import/usr_'.$ilUser->getId().'_'.session_id(); 
01052                 ilUtil::makeDirParents($importDir);
01053                 return $importDir;
01054         }
01055 
01059         function importUserRoleAssignmentObject ()
01060         {
01061                 include_once './classes/class.ilObjRole.php';
01062                 include_once './classes/class.ilUserImportParser.php';
01063                 
01064                 global $rbacreview, $rbacsystem, $tree, $lng;
01065                 
01066 
01067                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.usr_import_roles.html");
01068 
01069                 $import_dir = $this->getImportDir();
01070 
01071                 // recreate user import directory
01072                 if (@is_dir($import_dir))
01073                 {
01074                         ilUtil::delDir($import_dir);
01075                 }
01076                 ilUtil::makeDir($import_dir);
01077 
01078                 // move uploaded file to user import directory
01079                 $file_name = $_FILES["importFile"]["name"];
01080                 $parts = pathinfo($file_name);
01081                 $full_path = $import_dir."/".$file_name;
01082 
01083                 // check if import file exists
01084                 if (!is_file($_FILES["importFile"]["tmp_name"]))
01085                 {
01086                         ilUtil::delDir($import_dir);
01087                         $this->ilias->raiseError($this->lng->txt("no_import_file_found")
01088                                 , $this->ilias->error_obj->MESSAGE);
01089                 }
01090                 ilUtil::moveUploadedFile($_FILES["importFile"]["tmp_name"],
01091                         $_FILES["importFile"]["name"], $full_path);
01092 
01093                 // handle zip file              
01094                 if (strtolower($parts["extension"]) == "zip")
01095                 {
01096                         // unzip file
01097                         ilUtil::unzip($full_path);
01098 
01099                         $xml_file = null;
01100                         $file_list = ilUtil::getDir($import_dir);
01101                         foreach ($file_list as $a_file)
01102                         {
01103                                 if (substr($a_file['entry'],-4) == '.xml')
01104                                 {
01105                                         $xml_file = $import_dir."/".$a_file['entry'];
01106                                         break;
01107                                 }
01108                         }
01109                         if (is_null($xml_file))
01110                         {
01111                                 $subdir = basename($parts["basename"],".".$parts["extension"]);
01112                                 $xml_file = $import_dir."/".$subdir."/".$subdir.".xml";
01113                         }
01114                 }
01115                 // handle xml file
01116                 else
01117                 {
01118                         $xml_file = $full_path;
01119                 }
01120 
01121                 // check xml file               
01122                 if (!is_file($xml_file))
01123                 {
01124                         ilUtil::delDir($import_dir);
01125                         $this->ilias->raiseError($this->lng->txt("no_xml_file_found_in_zip")
01126                                 ." ".$subdir."/".$subdir.".xml", $this->ilias->error_obj->MESSAGE);
01127                 }
01128 
01129                 require_once("classes/class.ilUserImportParser.php");
01130 
01131                 // Verify the data
01132                 // ---------------
01133                 $importParser = new ilUserImportParser($xml_file, IL_VERIFY);
01134                 $importParser->startParsing();
01135                 switch ($importParser->getErrorLevel())
01136                 {
01137                         case IL_IMPORT_SUCCESS :
01138                                 break;
01139                         case IL_IMPORT_WARNING :
01140                                 $this->tpl->setVariable("IMPORT_LOG", $importParser->getProtocolAsHTML($lng->txt("verification_warning_log")));
01141                                 break;
01142                         case IL_IMPORT_FAILURE :
01143                                 ilUtil::delDir($import_dir);
01144                                 $this->ilias->raiseError(
01145                                         $lng->txt("verification_failed").$importParser->getProtocolAsHTML($lng->txt("verification_failure_log")),
01146                                         $this->ilias->error_obj->MESSAGE
01147                                 );
01148                                 return;
01149                 }
01150 
01151                 // Create the role selection form
01152                 // ------------------------------
01153                 $this->tpl->setCurrentBlock("role_selection_form");
01154                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
01155                 $this->tpl->setVariable("TXT_IMPORT_USERS", $this->lng->txt("import_users"));
01156                 $this->tpl->setVariable("TXT_IMPORT_FILE", $this->lng->txt("import_file"));
01157                 $this->tpl->setVariable("IMPORT_FILE", $file_name);
01158                 $this->tpl->setVariable("TXT_USER_ELEMENT_COUNT", $this->lng->txt("num_users"));
01159                 $this->tpl->setVariable("USER_ELEMENT_COUNT", $importParser->getUserCount());
01160                 $this->tpl->setVariable("TXT_ROLE_ASSIGNMENT", $this->lng->txt("role_assignment"));
01161                 $this->tpl->setVariable("BTN_IMPORT", $this->lng->txt("import"));
01162                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
01163                 $this->tpl->setVariable("XML_FILE_NAME", $xml_file);
01164 
01165                 // Extract the roles
01166                 $importParser = new ilUserImportParser($xml_file, IL_EXTRACT_ROLES);
01167                 $importParser->startParsing();
01168                 $roles = $importParser->getCollectedRoles();
01169 
01170                 // get global roles
01171                 $all_gl_roles = $rbacreview->getRoleListByObject(ROLE_FOLDER_ID);
01172                 $gl_roles = array();
01173                 foreach ($all_gl_roles as $obj_data)
01174                 {
01175                         // check assignment permission if called from local admin
01176                         if($this->object->getRefId() != USER_FOLDER_ID)
01177                         {
01178                                 if(!ilObjRole::_getAssignUsersStatus($obj_data['obj_id']))
01179                                 {
01180                                         continue;
01181                                 }
01182                         }
01183                         // exclude anonymous role from list
01184                         if ($obj_data["obj_id"] != ANONYMOUS_ROLE_ID)
01185                         {
01186                                 // do not allow to assign users to administrator role if current user does not has SYSTEM_ROLE_ID
01187                                 if ($obj_data["obj_id"] != SYSTEM_ROLE_ID or in_array(SYSTEM_ROLE_ID,$_SESSION["RoleId"]))
01188                                 {
01189                                         $gl_roles[$obj_data["obj_id"]] = $obj_data["title"];
01190                                 }
01191                         }
01192                 }
01193 
01194                 // global roles
01195                 $got_globals = false;
01196                 foreach($roles as $role_id => $role)
01197                 {
01198                         if ($role["type"] == "Global")
01199                         {
01200                                 if (! $got_globals)
01201                                 {
01202                                         $got_globals = true;
01203 
01204                                         $this->tpl->setCurrentBlock("global_role_section");
01205                                         $this->tpl->setVariable("TXT_GLOBAL_ROLES_IMPORT", $this->lng->txt("roles_of_import_global"));
01206                                         $this->tpl->setVariable("TXT_GLOBAL_ROLES", $this->lng->txt("assign_global_role"));
01207                                 }
01208 
01209                                 // pre selection for role
01210                                 $pre_select = array_search($role[name], $gl_roles);
01211                                 if (! $pre_select)
01212                                 {
01213                                         switch($role["name"])
01214                                         {
01215                                                 case "Administrator":   // ILIAS 2/3 Administrator
01216                                                         $pre_select = array_search("Administrator", $gl_roles);
01217                                                         break;
01218 
01219                                                 case "Autor":                   // ILIAS 2 Author
01220                                                         $pre_select = array_search("User", $gl_roles);
01221                                                         break;
01222 
01223                                                 case "Lerner":                  // ILIAS 2 Learner
01224                                                         $pre_select = array_search("User", $gl_roles);
01225                                                         break;
01226 
01227                                                 case "Gast":                    // ILIAS 2 Guest
01228                                                         $pre_select = array_search("Guest", $gl_roles);
01229                                                         break;
01230 
01231                                                 default:
01232                                                         $pre_select = array_search("User", $gl_roles);
01233                                                         break;
01234                                         }
01235                                 }
01236                                 $this->tpl->setCurrentBlock("global_role");
01237                                 $role_select = ilUtil::formSelect($pre_select, "role_assign[".$role_id."]", $gl_roles, false, true);
01238                                 $this->tpl->setVariable("TXT_IMPORT_GLOBAL_ROLE", $role["name"]." [".$role_id."]");
01239                                 $this->tpl->setVariable("SELECT_GLOBAL_ROLE", $role_select);
01240                                 $this->tpl->parseCurrentBlock();
01241                         }
01242                 }
01243 
01244                 // Check if local roles need to be assigned
01245                 $got_locals = false;
01246                 foreach($roles as $role_id => $role)
01247                 {
01248                         if ($role["type"] == "Local")
01249                         {
01250                                 $got_locals = true;
01251                                 break;
01252                         }
01253                 }
01254 
01255                 if ($got_locals) 
01256                 {
01257                         $this->tpl->setCurrentBlock("local_role_section");
01258                         $this->tpl->setVariable("TXT_LOCAL_ROLES_IMPORT", $this->lng->txt("roles_of_import_local"));
01259                         $this->tpl->setVariable("TXT_LOCAL_ROLES", $this->lng->txt("assign_local_role"));
01260 
01261 
01262                         // get local roles
01263                         $loc_roles = $rbacreview->getAssignableRoles();
01264                         $l_roles = array();
01265                         $l_roles_searcharray = array(); 
01266                         foreach ($loc_roles as $key => $loc_role)
01267                         {
01268                                 // fetch context path of role
01269                                 $rolf = $rbacreview->getFoldersAssignedToRole($loc_role["obj_id"],true);
01270 
01271                                 // only process role folders that are not set to status "deleted" 
01272                                 // and for which the user has write permissions.
01273                                 // We also don't show the roles which are in the ROLE_FOLDER_ID folder.
01274                                 // (The ROLE_FOLDER_ID folder contains the global roles).
01275                                 if (!$rbacreview->isDeleted($rolf[0])
01276                                 && $rbacsystem->checkAccess('write',$tree->getParentId($rolf[0]))
01277                                 && $rolf[0] != ROLE_FOLDER_ID
01278                                 )
01279                                 {
01280                                         // A local role is only displayed, if it is contained in the subtree of 
01281                                         // the localy administrated category. If the import function has been 
01282                                         // invoked from the user folder object, we show all local roles, because
01283                                         // the user folder object is considered the parent of all local roles.
01284                                         // Thus, if we start from the user folder object, we initialize the
01285                                         // isInSubtree variable with true. In all other cases it is initialized 
01286                                         // with false, and only set to true if we find the object id of the
01287                                         // locally administrated category in the tree path to the local role.
01288                                         $isInSubtree = $this->object->getRefId() == USER_FOLDER_ID;
01289                                         
01290                                         $path = "";
01291                                         if ($this->tree->isInTree($rolf[0]))
01292                                         {
01293                                                 // Create path. Paths which have more than 4 segments
01294                                                 // are truncated in the middle.
01295                                                 $tmpPath = $this->tree->getPathFull($rolf[0]);
01296                                                 for ($i = 1, $n = count($tmpPath) - 1; $i < $n; $i++)
01297                                                 {
01298                                                         if ($i > 1)
01299                                                         {
01300                                                                 $path = $path.' > ';
01301                                                         }
01302                                                         if ($i < 3 || $i > $n - 3)
01303                                                         {
01304                                                                 $path = $path.$tmpPath[$i]['title'];
01305                                                         } 
01306                                                         else if ($i == 3 || $i == $n - 3)
01307                                                         {
01308                                                                 $path = $path.'...';
01309                                                         }
01310                                                         
01311                                                         $isInSubtree |= $tmpPath[$i]['obj_id'] == $this->object->getId();
01312                                                 }
01313                                         }
01314                                         else
01315                                         {
01316                                                 $path = "<b>Rolefolder ".$rolf[0]." not found in tree! (Role ".$loc_role["obj_id"].")</b>";
01317                                         }
01318 
01319                                         if ($loc_role["role_type"] != "Global" && $isInSubtree)
01320                                         {
01321                                                 $l_roles[$loc_role['obj_id']] = $loc_role["title"]." ($path)";
01322                                                 $l_roles_searcharray[$loc_role['obj_id']] = $loc_role["title"];
01323                                         }
01324                                 }
01325                         } //foreach role
01326 
01327                         $l_roles[""] = ""; 
01328                         natsort($l_roles);
01329                         $l_roles[""] = $this->lng->txt("usrimport_ignore_role"); 
01330 
01331                         foreach($roles as $role_id => $role)
01332                         {
01333                                 if ($role["type"] == "Local")
01334                                 {
01335                                         $this->tpl->setCurrentBlock("local_role");
01336                                         $this->tpl->setVariable("TXT_IMPORT_LOCAL_ROLE", $role["name"]." [".$role_id."]");
01337                                         $pre_select = array_search($role_id, $l_roles_searcharray);
01338                                         if (!($pre_select !== false)) 
01339                                         {
01340                                                 $pre_select = array_search($role['name'], $l_roles_searcharray);
01341                                         }
01342                                         $role_select = ilUtil::formSelect($pre_select, "role_assign[".$role_id."]", $l_roles, false, true);
01343                                         $this->tpl->setVariable("SELECT_LOCAL_ROLE", $role_select);
01344                                         $this->tpl->parseCurrentBlock();
01345                                 }
01346                         }
01347                 }
01348                 // 
01349  
01350                 $this->tpl->setVariable("TXT_CONFLICT_HANDLING", $lng->txt("conflict_handling"));
01351                 $handlers = array(
01352                         IL_IGNORE_ON_CONFLICT => "ignore_on_conflict",
01353                         IL_UPDATE_ON_CONFLICT => "update_on_conflict"
01354                 );
01355                 $this->tpl->setVariable("TXT_CONFLICT_HANDLING_INFO", str_replace('\n','<br>',$this->lng->txt("usrimport_conflict_handling_info")));
01356                 $this->tpl->setVariable("TXT_CONFLICT_CHOICE", $lng->txt("conflict_handling"));
01357                 $this->tpl->setVariable("SELECT_CONFLICT", ilUtil::formSelect(IL_IGNORE_ON_CONFLICT, "conflict_handling_choice", $handlers, false, false));
01358         }
01359 
01363         function importUsersObject()
01364         {
01365                 include_once './classes/class.ilObjRole.php';
01366                 include_once './classes/class.ilUserImportParser.php';
01367 
01368                 global $rbacreview, $rbacsystem, $tree, $lng;
01369 
01370                 switch ($_POST["conflict_handling_choice"])
01371                 {
01372                         case "update_on_conflict" :
01373                                 $rule = IL_UPDATE_ON_CONFLICT;
01374                                 break;
01375                         case "ignore_on_conflict" :
01376                         default :
01377                                 $rule = IL_IGNORE_ON_CONFLICT;
01378                                 break;
01379                 }
01380                 $importParser = new ilUserImportParser($_POST["xml_file"],  IL_USER_IMPORT, $rule);
01381                 $importParser->setFolderId($this->getUserOwnerId());
01382                 $import_dir = $this->getImportDir();
01383 
01384                 // Catch hack attempts
01385                 // We check here again, if the role folders are in the tree, and if the
01386                 // user has permission on the roles.
01387                 if ($_POST["role_assign"])
01388                 {
01389                         $global_roles = $rbacreview->getGlobalRoles();
01390                         foreach ($_POST["role_assign"] as $role_id)
01391                         {
01392                                 if ($role_id != "") 
01393                                 {
01394                                         if (in_array($role_id, $global_roles))
01395                                         {
01396                                                 if ($role_id == SYSTEM_ROLE_ID && ! in_array(SYSTEM_ROLE_ID,$_SESSION["RoleId"])
01397                                                 || ($this->object->getRefId() != USER_FOLDER_ID 
01398                                                         && ! ilObjRole::_getAssignUsersStatus($role_id))
01399                                                 )
01400                                                 {
01401                                                         ilUtil::delDir($import_dir);
01402                                                         $this->ilias->raiseError($this->lng->txt("usrimport_with_specified_role_not_permitted"), 
01403                                                                 $this->ilias->error_obj->MESSAGE);
01404                                                 }
01405                                         }
01406                                         else
01407                                         {
01408                                                 $rolf = $rbacreview->getFoldersAssignedToRole($role_id,true);
01409                                                 if ($rbacreview->isDeleted($rolf[0])
01410                                                         || ! $rbacsystem->checkAccess('write',$tree->getParentId($rolf[0])))
01411                                                 {
01412                                                         ilUtil::delDir($import_dir);
01413                                                         $this->ilias->raiseError($this->lng->txt("usrimport_with_specified_role_not_permitted"), 
01414                                                                 $this->ilias->error_obj->MESSAGE);
01415                                                         return;
01416                                                 }
01417                                         }
01418                                 }
01419                         }
01420                 }
01421 
01422                 $importParser->setRoleAssignment($_POST["role_assign"]);
01423                 $importParser->startParsing();
01424 
01425                 // purge user import directory
01426                 ilUtil::delDir($import_dir);
01427 
01428                 switch ($importParser->getErrorLevel())
01429                 {
01430                         case IL_IMPORT_SUCCESS :
01431                                 sendInfo($this->lng->txt("user_imported"), true);
01432                                 break;
01433                         case IL_IMPORT_WARNING :
01434                                 sendInfo($this->lng->txt("user_imported_with_warnings").$importParser->getProtocolAsHTML($lng->txt("import_warning_log")), true);
01435                                 break;
01436                         case IL_IMPORT_FAILURE :
01437                                 $this->ilias->raiseError(
01438                                         $this->lng->txt("user_import_failed")
01439                                         .$importParser->getProtocolAsHTML($lng->txt("import_failure_log")),
01440                                         $this->ilias->error_obj->MESSAGE
01441                                 );
01442                                 break;
01443                 }
01444 
01445                 if (strtolower($_GET["baseClass"]) == "iladministrationgui")
01446                 {
01447                         $this->ctrl->redirect($this, "view");
01448                         //ilUtil::redirect($this->ctrl->getLinkTarget($this));
01449                 }
01450                 else
01451                 {
01452                         $this->ctrl->redirectByClass('ilobjcategorygui','listUsers');
01453                 }
01454         }
01455 
01456 
01457         function appliedUsersObject()
01458         {
01459                 global $rbacsystem,$ilias;
01460 
01461                 unset($_SESSION['applied_users']);
01462 
01463                 if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
01464                 {
01465                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
01466                 }
01467                 
01468                 if(!count($app_users =& $ilias->account->getAppliedUsers()))
01469                 {
01470                         sendInfo($this->lng->txt('no_users_applied'));
01471 
01472                         return false;
01473                 }
01474 
01475                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.usr_applied_users.html");
01476                 $this->lng->loadLanguageModule('crs');
01477                 
01478                 $counter = 0;
01479                 foreach($app_users as $usr_id)
01480                 {
01481                         $tmp_user =& ilObjectFactory::getInstanceByObjId($usr_id);
01482 
01483                         $f_result[$counter][]   = ilUtil::formCheckbox(0,"users[]",$usr_id);
01484                         $f_result[$counter][]   = $tmp_user->getLogin();
01485                         $f_result[$counter][]   = $tmp_user->getFirstname();
01486                         $f_result[$counter][]   = $tmp_user->getLastname();
01487                         
01488                         if($tmp_user->getTimeLimitUnlimited())
01489                         {
01490                                 $f_result[$counter][]   = "<b>".$this->lng->txt('crs_unlimited')."</b>";
01491                         }
01492                         else
01493                         {
01494                                 $limit = "<b>".$this->lng->txt('crs_from').'</b> '.strftime("%Y-%m-%d %R",$tmp_user->getTimeLimitFrom()).'<br />';
01495                                 $limit .= "<b>".$this->lng->txt('crs_to').'</b> '.strftime("%Y-%m-%d %R",$tmp_user->getTimeLimitUntil());
01496 
01497                                 $f_result[$counter][]   = $limit;
01498                         }
01499                         ++$counter;
01500                 }
01501 
01502                 $this->__showAppliedUsersTable($f_result);
01503 
01504                 return true;
01505         }
01506 
01507         function editAppliedUsersObject()
01508         {
01509                 global $rbacsystem;
01510 
01511                 if(!$rbacsystem->checkAccess("write", $this->ref_id))
01512                 {
01513                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
01514                 }
01515 
01516                 $this->lng->loadLanguageModule('crs');
01517 
01518                 $_POST['users'] = $_SESSION['applied_users'] = ($_SESSION['applied_users'] ? $_SESSION['applied_users'] : $_POST['users']);
01519 
01520                 if(!isset($_SESSION['error_post_vars']))
01521                 {
01522                         sendInfo($this->lng->txt('time_limit_add_time_limit_for_selected'));
01523                 }
01524 
01525                 if(!count($_POST["users"]))
01526                 {
01527                         sendInfo($this->lng->txt("time_limit_no_users_selected"));
01528                         $this->appliedUsersObject();
01529 
01530                         return false;
01531                 }
01532                 
01533                 $counter = 0;
01534                 foreach($_POST['users'] as $usr_id)
01535                 {
01536                         if($counter)
01537                         {
01538                                 $title .= ', ';
01539                         }
01540                         $tmp_user =& ilObjectFactory::getInstanceByObjId($usr_id);
01541                         $title .= $tmp_user->getLogin();
01542                         ++$counter;
01543                 }
01544                 if(strlen($title) > 79)
01545                 {
01546                         $title = substr($title,0,80);
01547                         $title .= '...';
01548                 }
01549 
01550 
01551                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.usr_edit_applied_users.html");
01552                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
01553 
01554                 // LOAD SAVED DATA IN CASE OF ERROR
01555                 $time_limit_unlimited = $_SESSION["error_post_vars"]["au"]["time_limit_unlimited"] ? 
01556                         1 : 0;
01557 
01558                 $time_limit_start = $_SESSION["error_post_vars"]["au"]["time_limit_start"] ? 
01559                         $this->__toUnix($_SESSION["error_post_vars"]["au"]["time_limit_start"]) :
01560                         time();
01561                 $time_limit_end = $_SESSION["error_post_vars"]["au"]["time_limit_end"] ? 
01562                         $this->__toUnix($_SESSION["error_post_vars"]["au"]["time_limit_end"]) :
01563                         time();
01564 
01565                 
01566                 // SET TEXT VARIABLES
01567                 $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_usr"));
01568                 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath("icon_usr_b.gif"));
01569                 $this->tpl->setVariable("TITLE",$title);
01570                 $this->tpl->setVariable("TXT_TIME_LIMIT",$this->lng->txt("time_limit"));
01571                 $this->tpl->setVariable("TXT_TIME_LIMIT_START",$this->lng->txt("crs_start"));
01572                 $this->tpl->setVariable("TXT_TIME_LIMIT_END",$this->lng->txt("crs_end"));
01573                 $this->tpl->setVariable("CMD_SUBMIT","updateAppliedUsers");
01574                 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt("cancel"));
01575                 $this->tpl->setVariable("TXT_SUBMIT",$this->lng->txt("submit"));
01576                 
01577 
01578 
01579                 $this->tpl->setVariable("SELECT_TIME_LIMIT_START_DAY",$this->__getDateSelect("day","au[time_limit_start][day]",
01580                                                                                                                                                                          date("d",$time_limit_start)));
01581                 $this->tpl->setVariable("SELECT_TIME_LIMIT_START_MONTH",$this->__getDateSelect("month","au[time_limit_start][month]",
01582                                                                                                                                                                            date("m",$time_limit_start)));
01583                 $this->tpl->setVariable("SELECT_TIME_LIMIT_START_YEAR",$this->__getDateSelect("year","au[time_limit_start][year]",
01584                                                                                                                                                                           date("Y",$time_limit_start)));
01585                 $this->tpl->setVariable("SELECT_TIME_LIMIT_START_HOUR",$this->__getDateSelect("hour","au[time_limit_start][hour]",
01586                                                                                                                                                                           date("G",$time_limit_start)));
01587                 $this->tpl->setVariable("SELECT_TIME_LIMIT_START_MINUTE",$this->__getDateSelect("minute","au[time_limit_start][minute]",
01588                                                                                                                                                                           date("i",$time_limit_start)));
01589                 $this->tpl->setVariable("SELECT_TIME_LIMIT_END_DAY",$this->__getDateSelect("day","au[time_limit_end][day]",
01590                                                                                                                                                                    date("d",$time_limit_end)));
01591                 $this->tpl->setVariable("SELECT_TIME_LIMIT_END_MONTH",$this->__getDateSelect("month","au[time_limit_end][month]",
01592                                                                                                                                                                          date("m",$time_limit_end)));
01593                 $this->tpl->setVariable("SELECT_TIME_LIMIT_END_YEAR",$this->__getDateSelect("year","au[time_limit_end][year]",
01594                                                                                                                                                                         date("Y",$time_limit_end)));
01595                 $this->tpl->setVariable("SELECT_TIME_LIMIT_END_HOUR",$this->__getDateSelect("hour","au[time_limit_end][hour]",
01596                                                                                                                                                                           date("G",$time_limit_end)));
01597                 $this->tpl->setVariable("SELECT_TIME_LIMIT_END_MINUTE",$this->__getDateSelect("minute","au[time_limit_end][minute]",
01598                                                                                                                                                                           date("i",$time_limit_end)));
01599                 if($this->ilias->account->getTimeLimitUnlimited())
01600                 {
01601                         $this->tpl->setVariable("ROWSPAN",3);
01602                         $this->tpl->setCurrentBlock("unlimited");
01603                         $this->tpl->setVariable("TXT_TIME_LIMIT_UNLIMITED",$this->lng->txt("crs_unlimited"));
01604                         $this->tpl->setVariable("TIME_LIMIT_UNLIMITED",ilUtil::formCheckbox($time_limit_unlimited,"au[time_limit_unlimited]",1));
01605                         $this->tpl->parseCurrentBlock();
01606                 }
01607                 else
01608                 {
01609                         $this->tpl->setVariable("ROWSPAN",2);
01610                 }
01611         }
01612 
01613         function updateAppliedUsersObject()
01614         {
01615                 global $rbacsystem;
01616 
01617                 if(!$rbacsystem->checkAccess("write", $this->ref_id))
01618                 {
01619                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
01620                 }
01621 
01622                 $start  = $this->__toUnix($_POST['au']['time_limit_start']);
01623                 $end    = $this->__toUnix($_POST['au']['time_limit_end']);
01624 
01625                 if(!$_POST['au']['time_limit_unlimited'])
01626                 {
01627                         if($start > $end)
01628                         {
01629                                 $_SESSION['error_post_vars'] = $_POST;
01630                                 sendInfo($this->lng->txt('time_limit_not_valid'));
01631                                 $this->editAppliedUsersObject();
01632 
01633                                 return false;
01634                         }
01635                 }
01636                 #if(!$this->ilias->account->getTimeLimitUnlimited())
01637                 #{
01638                 #       if($start < $this->ilias->account->getTimeLimitFrom() or
01639                 #          $end > $this->ilias->account->getTimeLimitUntil())
01640                 #       {
01641                 #               $_SESSION['error_post_vars'] = $_POST;
01642                 #               sendInfo($this->lng->txt('time_limit_not_within_owners'));
01643                 #               $this->editAppliedUsersObject();
01644 
01645                 #               return false;
01646                 #       }
01647                 #}
01648 
01649                 foreach($_SESSION['applied_users'] as $usr_id)
01650                 {
01651                         $tmp_user =& ilObjectFactory::getInstanceByObjId($usr_id);
01652 
01653                         $tmp_user->setTimeLimitUnlimited((int) $_POST['au']['time_limit_unlimited']);
01654                         $tmp_user->setTimeLimitFrom($start);
01655                         $tmp_user->setTimeLimitUntil($end);
01656                         $tmp_user->setTimeLimitMessage(0);
01657                         $tmp_user->update();
01658 
01659                         unset($tmp_user);
01660                 }
01661 
01662                 unset($_SESSION['applied_users']);
01663                 sendInfo($this->lng->txt('time_limit_users_updated'));
01664                 $this->appliedUsersObject();
01665                 
01666                 return true;
01667         }
01668 
01669         function __showAppliedUsersTable($a_result_set)
01670         {
01671                 $tbl =& $this->__initTableGUI();
01672                 $tpl =& $tbl->getTemplateObject();
01673 
01674                 // SET FORMAACTION
01675                 $tpl->setCurrentBlock("tbl_form_header");
01676 
01677                 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
01678                 $tpl->parseCurrentBlock();
01679 
01680                 $tpl->setCurrentBlock("tbl_action_btn");
01681                 $tpl->setVariable("BTN_NAME",'editAppliedUsers');
01682                 $tpl->setVariable("BTN_VALUE",$this->lng->txt('edit'));
01683                 $tpl->parseCurrentBlock();
01684 
01685                 $tpl->setCurrentBlock("tbl_action_row");
01686                 $tpl->setVariable("COLUMN_COUNTS",5);
01687                 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
01688                 $tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
01689                 $tpl->parseCurrentBlock();
01690 
01691 
01692 
01693                 $tbl->setTitle($this->lng->txt("time_limit_applied_users"),"icon_usr_b.gif",$this->lng->txt("users"));
01694                 $tbl->setHeaderNames(array('',
01695                                                                    $this->lng->txt("login"),
01696                                                                    $this->lng->txt("firstname"),
01697                                                                    $this->lng->txt("lastname"),
01698                                                                    $this->lng->txt("time_limits")));
01699                 $header_params = $this->ctrl->getParameterArray($this, "appliedUsers");
01700                 $tbl->setHeaderVars(array("",
01701                                                                   "login",
01702                                                                   "firstname",
01703                                                                   "lastname",
01704                                                                   "time_limit"),
01705                                                         array($header_params));
01706                 $tbl->setColumnWidth(array("3%","19%","19%","19%","40%"));
01707 
01708 
01709                 $this->__setTableGUIBasicData($tbl,$a_result_set);
01710                 $tbl->render();
01711 
01712                 $this->tpl->setVariable("APPLIED_USERS",$tbl->tpl->get());
01713 
01714                 return true;
01715         }
01716 
01717         function &__initTableGUI()
01718         {
01719                 include_once "./classes/class.ilTableGUI.php";
01720 
01721                 return new ilTableGUI(0,false);
01722         }
01723 
01724         function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
01725         {
01726                 $offset = $_GET["offset"];
01727                 $order = $_GET["sort_by"];
01728                 $direction = $_GET["sort_order"];
01729 
01730         //$tbl->enable("hits");
01731                 $tbl->setOrderColumn($order);
01732                 $tbl->setOrderDirection($direction);
01733                 $tbl->setOffset($offset);
01734                 $tbl->setLimit($_GET["limit"]);
01735                 $tbl->setMaxCount(count($result_set));
01736                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
01737                 $tbl->setData($result_set);
01738         }
01739 
01740         function __getDateSelect($a_type,$a_varname,$a_selected)
01741     {
01742         switch($a_type)
01743         {
01744             case "minute":
01745                 for($i=0;$i<=60;$i++)
01746                 {
01747                     $days[$i] = $i < 10 ? "0".$i : $i;
01748                 }
01749                 return ilUtil::formSelect($a_selected,$a_varname,$days,false,true);
01750 
01751             case "hour":
01752                 for($i=0;$i<24;$i++)
01753                 {
01754                     $days[$i] = $i < 10 ? "0".$i : $i;
01755                 }
01756                 return ilUtil::formSelect($a_selected,$a_varname,$days,false,true);
01757 
01758             case "day":
01759                 for($i=1;$i<32;$i++)
01760                 {
01761                     $days[$i] = $i < 10 ? "0".$i : $i;
01762                 }
01763                 return ilUtil::formSelect($a_selected,$a_varname,$days,false,true);
01764 
01765             case "month":
01766                 for($i=1;$i<13;$i++)
01767                 {
01768                     $month[$i] = $i < 10 ? "0".$i : $i;
01769                 }
01770                 return ilUtil::formSelect($a_selected,$a_varname,$month,false,true);
01771 
01772             case "year":
01773                 for($i = date("Y",time());$i < date("Y",time()) + 3;++$i)
01774                 {
01775                     $year[$i] = $i;
01776                 }
01777                 return ilUtil::formSelect($a_selected,$a_varname,$year,false,true);
01778         }
01779     }
01780         function __toUnix($a_time_arr)
01781     {
01782         return mktime($a_time_arr["hour"],
01783                       $a_time_arr["minute"],
01784                       $a_time_arr["second"],
01785                       $a_time_arr["month"],
01786                       $a_time_arr["day"],
01787                       $a_time_arr["year"]);
01788     }
01789 
01790         function hitsperpageObject()
01791         {
01792         parent::hitsperpageObject();
01793         $this->viewObject();
01794         }
01795 
01806         function settingsObject()
01807         {
01808                 global $ilias;
01809                 
01810                 $this->getTemplateFile("settings","usr");
01811 
01812                 $profile_fields =& $this->object->getProfileFields();
01813                 // For the following fields, the required state can not be changed.
01814                 // key = field, value = 1 (field is required), 0 (field is not required)
01815                 $fixed_required_fields = array(
01816                         "gender" => 1,
01817                         "firstname" => 1,
01818                         "lastname" => 1,
01819                         "upload" => 0,
01820                         "email" => 1,
01821                         "password" => 0,
01822                         "language" => 0,
01823                         "skin_style" => 0,
01824                         "hits_per_page" => 0,
01825                         "show_users_online" => 0
01826                 );
01827                 $no_export_fields = array(
01828                         "skin_style",
01829                         "hits_per_page",
01830                         "show_users_online"
01831                 );
01832                 foreach ($profile_fields as $field)
01833                 {
01834                         $this->tpl->setCurrentBlock("profile_settings");
01835                         $this->tpl->setVariable("TXT_PROFILE_DATA", $this->lng->txt($field));
01836                         $this->tpl->setVariable("PROFILE_OPTION_ENABLED", "enabled_" . $field);
01837                         $this->tpl->setVariable("PROFILE_OPTION_VISIBLE", "visible_" . $field);
01838                         $this->tpl->setVariable("PROFILE_OPTION_REQUIRED", "required_" . $field);
01839 
01840                         // BEGIN Enable field in Personal Profile
01841                         if ($ilias->getSetting("usr_settings_disable_".$field) != "1")
01842                         {
01843                                 $this->tpl->setVariable("CHECKED_ENABLED", " checked=\"checked\"");
01844                         }
01845                         // END Enable field in Personal Profile
01846                         // BEGIN Show field in Personal Profile
01847                         if ($ilias->getSetting("usr_settings_hide_".$field) != "1")
01848                         {
01849                                 $this->tpl->setVariable("CHECKED_VISIBLE", " checked=\"checked\"");
01850                         }
01851                         // END Show field in Personal Profile
01852                         if (!in_array($field, $no_export_fields))
01853                         {
01854                                 $this->tpl->setVariable("PROFILE_OPTION_EXPORT", "export_" . $field);
01855                                 // BEGIN Export field of Personal Profile
01856                                 if ($ilias->getSetting("usr_settings_export_".$field) == "1")
01857                                 {
01858                                         $this->tpl->setVariable("CHECKED_EXPORT", " checked=\"checked\"");
01859                                 }
01860                                 // END Export field of Personal Profile
01861                         }
01862                         // BEGIN Require field in Personal Profile
01863                         $is_fixed = array_key_exists($field, $fixed_required_fields);
01864                         if ($is_fixed && $fixed_required_fields[$field] || ! $is_fixed && $ilias->getSetting("require_".$field) == "1")
01865                         {
01866                                 $this->tpl->setVariable("CHECKED_REQUIRED", " checked=\"checked\"");
01867                         }
01868                         if ($is_fixed)
01869                         {
01870                                 $this->tpl->setVariable("DISABLE_REQUIRED", " disabled=\"disabled\"");
01871                         }
01872                         // END Require field in Personal Profile
01873 
01874                         // BEGIN Default value for hits per pages field in Personal Profile
01875                         if ($field == "hits_per_page")
01876                         {
01877                                 $this->tpl->setVariable("PROFILE_OPTION_DEFAULT_VALUE", "default_" . $field);
01878                                 $options = array(2,10,15,20,30,40,50,100,9999);
01879                                 $selected_option = $ilias->getSetting("hits_per_page");
01880                                 if ($selected_option == null) $selected_option = 10;
01881                                 $this->tpl->setCurrentBlock("default_value_option");
01882                                 foreach ($options as $option)
01883                                 {
01884                                         if ($option == $selected_option)
01885                                         {
01886                                                 $this->tpl->setVariable("OPTION_SELECTED", " selected=\"selected\"");
01887                                         }
01888 
01889                                         $this->tpl->setVariable("OPTION_VALUE", $option);
01890                                         $this->tpl->setVariable("OPTION_TEXT", ($option == 9999) ? $this->lng->txt("no_limit") : $option);
01891                                         $this->tpl->parseCurrentBlock();
01892                                 }
01893                                 $this->tpl->setCurrentBlock("profile_settings");
01894                         }
01895                         // END Default value for language field in Personal Profile
01896 
01897                         // BEGIN Show Users Online
01898                         else if ($field == "show_users_online")
01899                         {
01900                                 $this->tpl->setVariable("PROFILE_OPTION_DEFAULT_VALUE", "default_" . $field);
01901                                 $options = array('y','associated','n');
01902                                 $selected_option = $ilias->getSetting("show_users_online");
01903                                 if ($selected_option == null) $selected_option = 10;
01904                                 $this->tpl->setCurrentBlock("default_value_option");
01905                                 foreach ($options as $option)
01906                                 {
01907                                         if ($option == $selected_option)
01908                                         {
01909                                                 $this->tpl->setVariable("OPTION_SELECTED", " selected=\"selected\"");
01910                                         }
01911 
01912                                         $this->tpl->setVariable("OPTION_VALUE", $option);
01913                                         $this->tpl->setVariable("OPTION_TEXT", $this->lng->txt("users_online_show_".$option));
01914                                         $this->tpl->parseCurrentBlock();
01915                                 }
01916                                 $this->tpl->setCurrentBlock("profile_settings");
01917                         }
01918                         // END Show Users Online
01919 
01920                         $this->tpl->parseCurrentBlock();
01921                 }
01922                 $this->tpl->setVariable("FORMACTION",
01923                         $this->ctrl->getFormAction($this));
01924                 $this->tpl->setVariable("TXT_HEADER_PROFILE", $this->lng->txt("usr_settings_header_profile"));
01925                 $this->tpl->setVariable("TXT_EXPLANATION_PROFILE", $this->lng->txt("usr_settings_explanation_profile"));
01926                 $this->tpl->setVariable("HEADER_PROFILE_DATA", $this->lng->txt("usr_settings_header_profile_profile"));
01927                 $this->tpl->setVariable("HEADER_ENABLED", $this->lng->txt("changeable"));
01928                 $this->tpl->setVariable("HEADER_VISIBLE", $this->lng->txt("visible"));
01929                 $this->tpl->setVariable("HEADER_REQUIRED", $this->lng->txt("required_field"));
01930                 $this->tpl->setVariable("HEADER_EXPORT", $this->lng->txt("export"));
01931                 $this->tpl->setVariable("HEADER_DEFAULT_VALUE", $this->lng->txt("default_value"));
01932                 $this->tpl->setVariable("TXT_SAVE", $this->lng->txt("save"));
01933         }
01934         
01935         function saveGlobalUserSettingsObject()
01936         {
01937                 global $ilias;
01938                 
01939                 $profile_fields =& $this->object->getProfileFields();
01940                 // For the following fields, the required state can not be changed
01941                 $fixed_required_fields = array(
01942                         "gender" => 1,
01943                         "firstname" => 1,
01944                         "lastname" => 1,
01945                         "upload" => 0,
01946                         "email" => 1,
01947                         "password" => 0,
01948                         "language" => 0,
01949                         "skin_style" => 0,
01950                         "hits_per_page" => 0,
01951                         "show_users_online" => 0
01952                 );
01953 
01954                 foreach ($profile_fields as $field)
01955                 {
01956                         if (! $_POST["chb"]["visible_".$field])
01957                         {
01958                                 $ilias->setSetting("usr_settings_hide_".$field, "1");
01959                         }
01960                         else
01961                         {
01962                                 $ilias->deleteSetting("usr_settings_hide_".$field);
01963                         }
01964 
01965                         if (! $_POST["chb"]["enabled_" . $field])
01966                         {
01967                                 $ilias->setSetting("usr_settings_disable_".$field, "1");
01968                         }
01969                         else
01970                         {
01971                                 $ilias->deleteSetting("usr_settings_disable_".$field);
01972                         }
01973 
01974                         if ($_POST["chb"]["export_" . $field])
01975                         {
01976                                 $ilias->setSetting("usr_settings_export_".$field, "1");
01977                         }
01978                         else
01979                         {
01980                                 $ilias->deleteSetting("usr_settings_export_".$field);
01981                         }
01982 
01983                         $is_fixed = array_key_exists($field, $fixed_required_fields);
01984                         if ($is_fixed && $fixed_required_fields[$field] || ! $is_fixed && $_POST["chb"]["required_".$field])
01985                         {
01986                                 $ilias->setSetting("require_".$field, "1");
01987                         }
01988                         else
01989                         {
01990                                 $ilias->deleteSetting("require_" . $field);
01991                         }
01992                 }
01993 
01994                 if ($_POST["select"]["default_hits_per_page"])
01995                 {       
01996                         $ilias->setSetting("hits_per_page",$_POST["select"]["default_hits_per_page"]);
01997                 }
01998 
01999                 if ($_POST["select"]["default_show_users_online"])
02000                 {
02001                         $ilias->setSetting("show_users_online",$_POST["select"]["default_show_users_online"]);
02002                 }
02003 
02004                 sendInfo($this->lng->txt("usr_settings_saved"));
02005                 $this->settingsObject();
02006         }
02007         
02008         
02012         function __buildUserFilterSelect()
02013         {
02014                 $action[-1] = $this->lng->txt('all_users');
02015                 $action[1] = $this->lng->txt('usr_active_only');
02016                 $action[0] = $this->lng->txt('usr_inactive_only');
02017 
02018                 return  ilUtil::formSelect($_SESSION['user_filter'],"user_filter",$action,false,true);
02019         }
02020 
02027         function downloadExportFileObject()
02028         {
02029                 if(!isset($_POST["file"]))
02030                 {
02031                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
02032                 }
02033 
02034                 if (count($_POST["file"]) > 1)
02035                 {
02036                         $this->ilias->raiseError($this->lng->txt("select_max_one_item"),$this->ilias->error_obj->MESSAGE);
02037                 }
02038 
02039 
02040                 $export_dir = $this->object->getExportDirectory();
02041                 ilUtil::deliverFile($export_dir."/".$_POST["file"][0],
02042                         $_POST["file"][0]);
02043         }
02044         
02048         function confirmDeleteExportFileObject()
02049         {
02050                 if(!isset($_POST["file"]))
02051                 {
02052                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
02053                 }
02054 
02055                 // SAVE POST VALUES
02056                 $_SESSION["ilExportFiles"] = $_POST["file"];
02057 
02058                 $this->getTemplateFile("confirm_delete_export","usr");          
02059 
02060                 sendInfo($this->lng->txt("info_delete_sure"));
02061 
02062                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
02063 
02064                 // BEGIN TABLE HEADER
02065                 $this->tpl->setCurrentBlock("table_header");
02066                 $this->tpl->setVariable("TEXT",$this->lng->txt("objects"));
02067                 $this->tpl->parseCurrentBlock();
02068 
02069                 // BEGIN TABLE DATA
02070                 $counter = 0;
02071                 foreach($_POST["file"] as $file)
02072                 {
02073                                 $this->tpl->setCurrentBlock("table_row");
02074                                 $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
02075                                 $this->tpl->setVariable("IMG_OBJ",ilUtil::getImagePath("icon_usrf.gif"));
02076                                 $this->tpl->setVariable("TEXT_CONTENT", $file);
02077                                 $this->tpl->parseCurrentBlock();
02078                 }
02079 
02080                 // cancel/confirm button
02081                 $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
02082                 $this->tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
02083                 $buttons = array( "cancelDeleteExportFile"  => $this->lng->txt("cancel"),
02084                         "deleteExportFile"  => $this->lng->txt("confirm"));
02085                 foreach ($buttons as $name => $value)
02086                 {
02087                         $this->tpl->setCurrentBlock("operation_btn");
02088                         $this->tpl->setVariable("BTN_NAME",$name);
02089                         $this->tpl->setVariable("BTN_VALUE",$value);
02090                         $this->tpl->parseCurrentBlock();
02091                 }
02092         }
02093 
02094 
02098         function cancelDeleteExportFileObject()
02099         {
02100                 session_unregister("ilExportFiles");
02101                 ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilobjuserfoldergui", "export"));
02102         }
02103 
02104 
02108         function deleteExportFileObject()
02109         {
02110                 $export_dir = $this->object->getExportDirectory();
02111                 foreach($_SESSION["ilExportFiles"] as $file)
02112                 {
02113                         $exp_file = $export_dir."/".$file;
02114                         if (@is_file($exp_file))
02115                         {
02116                                 unlink($exp_file);
02117                         }
02118                 }
02119                 ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilobjuserfoldergui", "export"));
02120         }
02121 
02132         function exportObject()
02133         {
02134                 global $ilias;
02135                 
02136                 if ($_POST["cmd"]["export"])
02137                 {
02138                         $this->object->buildExportFile($_POST["export_type"]);
02139                         ilUtil::redirect($this->ctrl->getLinkTargetByClass("ilobjuserfoldergui", "export"));
02140                         exit;
02141                 }
02142                 
02143                 $this->getTemplateFile("export","usr");
02144                 
02145                 $export_types = array(
02146                         "userfolder_export_excel_x86",
02147                         "userfolder_export_csv",
02148                         "userfolder_export_xml"
02149                 );
02150 
02151                 // create table
02152                 include_once("./classes/class.ilTableGUI.php");
02153                 $tbl = new ilTableGUI();
02154 
02155                 // load files templates
02156                 $this->tpl->addBlockfile("EXPORT_FILES", "export_files", "tpl.table.html");
02157 
02158                 // load template for table content data
02159                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.usr_export_file_row.html");
02160 
02161                 $num = 0;
02162 
02163                 $tbl->setTitle($this->lng->txt("userfolder_export_files"));
02164 
02165                 $tbl->setHeaderNames(array("<input type=\"checkbox\" name=\"chb_check_all\" value=\"1\" onclick=\"setChecked('ObjectItems', 'file', document.ObjectItems.chb_check_all.checked);\" />", $this->lng->txt("userfolder_export_file"),
02166                         $this->lng->txt("userfolder_export_file_size"), $this->lng->txt("date") ));
02167 
02168                 $tbl->enabled["sort"] = false;
02169                 $tbl->setColumnWidth(array("1%", "49%", "25%", "25%"));
02170 
02171                 // control
02172                 $tbl->setOrderColumn($_GET["sort_by"]);
02173                 $tbl->setOrderDirection($_GET["sort_order"]);
02174                 $tbl->setLimit($_GET["limit"]);
02175                 $tbl->setOffset($_GET["offset"]);
02176                 $tbl->setMaxCount($this->maxcount);             // ???
02177 
02178 
02179                 $this->tpl->setVariable("COLUMN_COUNTS", 4);
02180 
02181                 // delete button
02182                 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
02183                 $this->tpl->setVariable("ALT_ARROW", $this->lng->txt("actions"));
02184                 $this->tpl->setCurrentBlock("tbl_action_btn");
02185                 $this->tpl->setVariable("BTN_NAME", "confirmDeleteExportFile");
02186                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
02187                 $this->tpl->parseCurrentBlock();
02188 
02189                 $this->tpl->setCurrentBlock("tbl_action_btn");
02190                 $this->tpl->setVariable("BTN_NAME", "downloadExportFile");
02191                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("download"));
02192                 $this->tpl->parseCurrentBlock();
02193 
02194                 // footer
02195                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
02196                 //$tbl->disable("footer");
02197 
02198                 $export_files = $this->object->getExportFiles();
02199 
02200                 $tbl->setMaxCount(count($export_files));
02201                 $export_files = array_slice($export_files, $_GET["offset"], $_GET["limit"]);
02202 
02203                 $tbl->render();
02204 
02205                 if(count($export_files) > 0)
02206                 {
02207                         $i=0;
02208                         foreach($export_files as $exp_file)
02209                         {
02210                                 $this->tpl->setCurrentBlock("tbl_content");
02211                                 $this->tpl->setVariable("TXT_FILENAME", $exp_file["filename"]);
02212 
02213                                 $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
02214                                 $this->tpl->setVariable("CSS_ROW", $css_row);
02215 
02216                                 $this->tpl->setVariable("TXT_SIZE", $exp_file["filesize"]);
02217                                 $this->tpl->setVariable("CHECKBOX_ID", $exp_file["filename"]);
02218 
02219                                 $file_arr = explode("__", $exp_file["filename"]);
02220                                 $this->tpl->setVariable("TXT_DATE", date("Y-m-d H:i:s",$file_arr[0]));
02221 
02222                                 $this->tpl->parseCurrentBlock();
02223                         }
02224                 } //if is_array
02225                 else
02226                 {
02227                         $this->tpl->setCurrentBlock("notfound");
02228                         $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
02229                         $this->tpl->setVariable("NUM_COLS", 3);
02230                         $this->tpl->parseCurrentBlock();
02231                 }
02232 
02233                 $this->tpl->parseCurrentBlock();
02234                 
02235                 
02236                 foreach ($export_types as $export_type)
02237                 {               
02238                         $this->tpl->setCurrentBlock("option");
02239                         $this->tpl->setVariable("OPTION_VALUE", $export_type);
02240                         $this->tpl->setVariable("OPTION_TEXT", $this->lng->txt($export_type));
02241                         $this->tpl->parseCurrentBlock();
02242                 }
02243                 
02244                 $this->tpl->setVariable("EXPORT_BUTTON", $this->lng->txt("create_export_file"));
02245                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
02246         }
02247         
02248         function getAdminTabs(&$tabs_gui)
02249         {
02250                 $this->getTabs($tabs_gui);
02251         }
02252 
02258         function getTabs(&$tabs_gui)
02259         {
02260                 include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
02261 
02262 
02263                 global $rbacsystem;
02264 
02265                 if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
02266                 {
02267                         $tabs_gui->addTarget("obj_usrf",
02268                                 $this->ctrl->getLinkTarget($this, "view"), array("view","delete",""), "", "");
02269                 }
02270                 
02271                 if ($rbacsystem->checkAccess("write",$this->object->getRefId()))
02272                 {
02273                         $tabs_gui->addTarget("global_settings",
02274                                 $this->ctrl->getLinkTarget($this, "settings"), "settings", "", "");
02275                                 
02276                         $tabs_gui->addTarget("export",
02277                                 $this->ctrl->getLinkTarget($this, "export"), "export", "", "");
02278 
02279                         if((ilObjUserTracking::_enabledLearningProgress() or
02280                                 ilObjUserTracking::_enabledTracking())
02281                            and ilObjUserTracking::_enabledUserRelatedData())
02282                         {
02283                                 $tabs_gui->addTarget("learning_progress",
02284                                                                          $this->ctrl->getLinkTarget($this, "learningProgress"), "learningProgress", "", "");
02285                         }
02286                 }
02287 
02288                 if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
02289                 {
02290                         $tabs_gui->addTarget("perm_settings",
02291                                                                  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), 
02292                                                                  array("perm","info","owner"), 'ilpermissiongui');
02293                 }
02294         }
02295 } // END class.ilObjUserFolderGUI
02296 ?>

Generated on Fri Dec 13 2013 11:57:55 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1