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

classes/class.ilObjStyleSettingsGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2005 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 
00034 include_once "class.ilObjectGUI.php";
00035 
00036 class ilObjStyleSettingsGUI extends ilObjectGUI
00037 {
00042         function ilObjStyleSettingsGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output = true)
00043         {
00044                 $this->type = "stys";
00045                 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
00046         }
00047         
00052         function saveObject()
00053         {
00054                 global $rbacadmin;
00055 
00056                 // create and insert forum in objecttree
00057                 $newObj = parent::saveObject();
00058 
00059                 // setup rolefolder & default local roles
00060                 //$roles = $newObj->initDefaultRoles();
00061 
00062                 // ...finally assign role to creator of object
00063                 //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "y");
00064 
00065                 // put here object specific stuff
00066                         
00067                 // always send a message
00068                 sendInfo($this->lng->txt("object_added"),true);
00069                 
00070                 ilUtil::redirect($this->getReturnLocation("save",$this->ctrl->getLinkTarget($this,"")));
00071         }
00072         
00076         function viewObject()
00077         {
00078                 global $rbacsystem, $ilias;
00079                 
00080                 if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
00081                 {
00082                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00083                 }
00084                 
00085                 include_once "./classes/class.ilTableGUI.php";
00086 
00087                 // load template for table
00088                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
00089                 
00090                 // load template for table content data
00091                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.styf_row.html");
00092 
00093                 $num = 0;
00094 
00095                 $this->tpl->setVariable("FORMACTION", "adm_object.php?ref_id=".$this->ref_id."$obj_str&cmd=gateway");
00096 
00097                 // create table
00098                 $tbl = new ilTableGUI();
00099 
00100                 // title & header columns
00101                 $tbl->setTitle($this->lng->txt("content_styles"),"icon_styf.gif",
00102                         $this->lng->txt("content_styles"));
00103 
00104                 //$tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help"));
00105 
00106                 // title
00107                 $header_names = array("", $this->lng->txt("title"),
00108                         $this->lng->txt("purpose"));
00109                 $tbl->setHeaderNames($header_names);
00110 
00111                 $header_params = array("ref_id" => $this->ref_id);
00112                 $tbl->setHeaderVars(array("", "title", "purpose"), $header_params);
00113                 $tbl->setColumnWidth(array("0%", "80%", "20%"));
00114 
00115                 // control
00116                 $tbl->setOrderColumn($_GET["sort_by"]);
00117                 $tbl->setOrderDirection($_GET["sort_order"]);
00118                 $tbl->setLimit($_GET["limit"]);
00119                 $tbl->setOffset($_GET["offset"]);
00120                 
00121                 // get style ids
00122                 $style_entries = array();
00123                 $styles = $this->object->getStyles();
00124                 foreach($styles as $style)
00125                 {
00126                         $style_entries[$style["title"].":".$style["id"]]
00127                                 = $style;
00128                 }
00129                 ksort($style_entries);
00130                 
00131                 // todo
00132                 $tbl->setMaxCount(count($style_entries));
00133 
00134                 $this->tpl->setVariable("COLUMN_COUNTS", 3);
00135 
00136                 // footer
00137                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00138 
00139                 $this->showActions(true);
00140 
00141                 include_once ("classes/class.ilObjStyleSheet.php");
00142                 
00143                 $fixed_style = $ilias->getSetting("fixed_content_style_id");
00144                 $default_style = $ilias->getSetting("default_content_style_id");
00145 
00146                 foreach ($style_entries as $style)
00147                 {
00148                         $this->tpl->setCurrentBlock("style_row");
00149                 
00150                         // color changing
00151                         $css_row = ($css_row == "tblrow2")
00152                                 ? "tblrow1"
00153                                 : "tblrow2";
00154 
00155                         $this->tpl->setVariable("CHECKBOX_ID", $style["id"]);
00156                         $this->tpl->setVariable("TXT_TITLE", $style["title"]);
00157                         $this->tpl->setVariable("TXT_DESC", ilObject::_lookupDescription($style["id"]));
00158                         $this->tpl->setVariable("LINK_STYLE",
00159                                 "adm_object.php?ref_id=".$_GET["ref_id"].
00160                                 "&obj_id=".$style["id"]);
00161                         $this->tpl->setVariable("ROWCOL", $css_row);
00162                         if ($style["id"] == $fixed_style)
00163                         {
00164                                 $this->tpl->setVariable("TXT_PURPOSE", $this->lng->txt("global_fixed"));
00165                         }
00166                         if ($style["id"] == $default_style)
00167                         {
00168                                 $this->tpl->setVariable("TXT_PURPOSE", $this->lng->txt("global_default"));
00169                         }
00170                         $this->tpl->parseCurrentBlock();
00171 
00172                         $this->tpl->setCurrentBlock("tbl_content");
00173                         $this->tpl->parseCurrentBlock();
00174 
00175                 } //if is_array
00176                 
00177                 if (count($style_entries) == 0)
00178                 {
00179             $tbl->disable("header");
00180                         $tbl->disable("footer");
00181                         
00182                         $this->tpl->setCurrentBlock("text");
00183                         $this->tpl->setVariable("TXT_CONTENT", $this->lng->txt("obj_not_found"));
00184                         $this->tpl->parseCurrentBlock();
00185                         
00186                         $this->tpl->setCurrentBlock("tbl_content");
00187                         $this->tpl->parseCurrentBlock();
00188                 }
00189 
00190                 // render table
00191                 $tbl->render();
00192                 
00193                 $this->displayStyleSettings();
00194         }
00195         
00196         
00200         function displayStyleSettings()
00201         {
00202                 global $styleDefinition;
00203                 
00204                 $this->tpl->addBlockFile("SYSTEMSETTINGS", "style_settings", "tpl.stys_settings.html");
00205                 $this->tpl->setCurrentBlock("style_settings");
00206 
00207                 $settings = $this->ilias->getAllSettings();
00208 
00209                 $this->tpl->setVariable("FORMACTION_STYLESETTINGS", $this->ctrl->getFormAction($this));         
00210                 $this->tpl->setVariable("TXT_STYLE_SETTINGS", $this->lng->txt("system_style_settings"));
00211                 $this->tpl->setVariable("TXT_SAVE", $this->lng->txt("save"));
00212                 $this->tpl->setVariable("TXT_DEFAULT_SKIN_STYLE", $this->lng->txt("default_skin_style"));
00213                 $this->tpl->setVariable("TXT_SKIN_STYLE_ACTIVATION", $this->lng->txt("style_activation"));
00214                 $this->tpl->setVariable("TXT_NUMBER_OF_USERS", $this->lng->txt("num_users"));
00215                 $this->tpl->setVariable("TXT_MOVE_USERS_TO_STYLE", $this->lng->txt("move_users_to_style"));
00216                 
00217                 // get all templates
00218                 $templates = $styleDefinition->getAllTemplates();
00219 
00220                 foreach ($templates as $template)
00221                 {
00222                         // get styles definition for template
00223                         $styleDef =& new ilStyleDefinition($template["id"]);
00224                         $styleDef->startParsing();
00225                         $styles = $styleDef->getStyles();
00226 
00227                         foreach ($styles as $style)
00228                         {
00229                                 if ($this->ilias->ini->readVariable("layout","skin") == $template["id"] &&
00230                                         $this->ilias->ini->readVariable("layout","style") == $style["id"])
00231                                 {
00232                                         $this->tpl->setVariable("SKINSELECTED", "selected=\"selected\"");
00233                                 }
00234 
00235                                 // default selection list
00236                                 $this->tpl->setCurrentBlock("selectskin");
00237                                 $this->tpl->setVariable("SKINVALUE", $template["id"].":".$style["id"]);
00238                                 $this->tpl->setVariable("SKINOPTION", $styleDef->getTemplateName()." / ".$style["name"]);
00239                                 $this->tpl->parseCurrentBlock();
00240                                 
00241                                 // can be optimized
00242                                 foreach ($templates as $template2)
00243                                 {
00244                                         // get styles definition for template
00245                                         $styleDef2 =& new ilStyleDefinition($template2["id"]);
00246                                         $styleDef2->startParsing();
00247                                         $styles2 = $styleDef2->getStyles();
00248                 
00249                                         foreach ($styles2 as $style2)
00250                                         {
00251                                                 if (ilObjStyleSettings::_lookupActivatedStyle($template2["id"], $style2["id"]))
00252                                                 {
00253                                                         $this->tpl->setCurrentBlock("move_to_skin");
00254                                                         $this->tpl->setVariable("TOSKINVALUE", $template2["id"].":".$style2["id"]);
00255                                                         $this->tpl->setVariable("TOSKINOPTION", $styleDef2->getTemplateName()." / ".$style2["name"]);
00256                                                         $this->tpl->parseCurrentBlock();
00257                                                 }
00258                                         }
00259                                 }
00260                                 
00261                                 // activation list
00262                                 $this->tpl->setCurrentBlock("style_activation");
00263                                 $this->tpl->setVariable("TXT_SKIN_STYLE_TITLE", 
00264                                         $styleDef->getTemplateName()." / ".$style["name"]);
00265                                 $this->tpl->setVariable("VAL_SKIN_STYLE", $template["id"].":".$style["id"]);
00266                                 $num_users = ilObjUser::_getNumberOfUsersForStyle($template["id"], $style["id"]);
00267                                 $this->tpl->setVariable("VAL_NUM_USERS", $num_users);
00268                                 if (ilObjStyleSettings::_lookupActivatedStyle($template["id"], $style["id"]))
00269                                 {
00270                                         $this->tpl->setVariable("CHK_SKIN_STYLE", " checked=\"1\" ");
00271                                 }
00272                                 $this->tpl->parseCurrentBlock();
00273                         }
00274                 }
00275 
00276                 $this->tpl->parseCurrentBlock();
00277         }
00278         
00282         function saveStyleSettingsObject()
00283         {
00284                 global $styleDefinition;
00285                 
00286                 // check if one style is activated
00287                 if (count($_POST["st_act"]) < 1)
00288                 {
00289                         $this->ilias->raiseError($this->lng->txt("at_least_one_style"), $this->ilias->error_obj->MESSAGE);
00290                 }
00291                 
00292                 // check if a style should be deactivated, that still has
00293                 // a user assigned to
00294                 $templates = $styleDefinition->getAllTemplates();
00295                 foreach ($templates as $template)
00296                 {
00297                         // get styles definition for template
00298                         $styleDef =& new ilStyleDefinition($template["id"]);
00299                         $styleDef->startParsing();
00300                         $styles = $styleDef->getStyles();
00301                         foreach ($styles as $style)
00302                         {
00303                                 if (!isset($_POST["st_act"][$template["id"].":".$style["id"]]))
00304                                 {
00305                                         if (ilObjUser::_getNumberOfUsersForStyle($template["id"], $style["id"]) > 1)
00306                                         {
00307                                                 $this->ilias->raiseError($this->lng->txt("cant_deactivate_if_users_assigned"), $this->ilias->error_obj->MESSAGE);
00308                                         }
00309                                         else
00310                                         {
00311                                                 ilObjStyleSettings::_deactivateStyle($template["id"], $style["id"]);
00312                                         }
00313                                 }
00314                                 else
00315                                 {
00316                                         ilObjStyleSettings::_activateStyle($template["id"], $style["id"]);
00317                                 }
00318                         }
00319                 }
00320                 
00321                 // move users to other skin
00322                 foreach($_POST["move_users"] as $key => $value)
00323                 {
00324                         if ($value != "")
00325                         {
00326                                 $from = explode(":", $key);
00327                                 $to = explode(":", $value);
00328                                 ilObjUser::_moveUsersToStyle($from[0],$from[1],$to[0],$to[1]);
00329                         }
00330                 }
00331                 
00332                 //set default skin and style
00333                 if ($_POST["default_skin_style"] != "")
00334                 {
00335                         $sknst = explode(":", $_POST["default_skin_style"]);
00336 
00337                         if ($this->ilias->ini->readVariable("layout","style") != $sknst[1] ||
00338                                 $this->ilias->ini->readVariable("layout","skin") != $sknst[0])
00339                         {
00340                                 $this->ilias->ini->setVariable("layout","skin", $sknst[0]);
00341                                 $this->ilias->ini->setVariable("layout","style",$sknst[1]);
00342                         }
00343                 }
00344                 $this->ilias->ini->write();
00345                 ilUtil::redirect($this->ctrl->getLinkTarget($this,"view"));
00346         }
00347         
00353         function deleteStyleObject($a_error = false)
00354         {
00355                 if (!isset($_POST["id"]))
00356                 {
00357                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00358                 }
00359 
00360                 // SAVE POST VALUES
00361                 $_SESSION["saved_post"] = $_POST["id"];
00362 
00363                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.confirm_deletion.html");
00364 
00365                 if(!$a_error)
00366                 {
00367                         sendInfo($this->lng->txt("info_delete_sure"));
00368                 }
00369 
00370                 $this->tpl->setVariable("FORMACTION", $this->getFormAction("delete",
00371                         "adm_object.php?ref_id=".$_GET["ref_id"]."&cmd=gateway"));
00372 
00373                 // BEGIN TABLE HEADER
00374                 $this->tpl->setCurrentBlock("table_header");
00375                 $this->tpl->setVariable("TEXT", $this->lng->txt("objects"));
00376                 $this->tpl->parseCurrentBlock();
00377                 
00378                 // END TABLE HEADER
00379 
00380                 // BEGIN TABLE DATA
00381                 $counter = 0;
00382 
00383                 foreach ($_POST["id"] as $id)
00384                 {
00385                         $this->tpl->setCurrentBlock("table_row");
00386                         $this->tpl->setVariable("IMG_OBJ",ilUtil::getImagePath("icon_styf.gif"));
00387                         $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
00388                         $this->tpl->setVariable("TEXT_CONTENT",ilObject::_lookupTitle($id));
00389                         $this->tpl->parseCurrentBlock();
00390                 }
00391                 
00392                 // END TABLE DATA
00393 
00394                 // BEGIN OPERATION_BTN
00395                 $buttons = array("confirmedDelete"  => $this->lng->txt("confirm"),
00396                         "cancelDelete"  => $this->lng->txt("cancel"));
00397                 foreach ($buttons as $name => $value)
00398                 {
00399                         $this->tpl->setCurrentBlock("operation_btn");
00400                         $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
00401                         $this->tpl->setVariable("BTN_NAME",$name);
00402                         $this->tpl->setVariable("BTN_VALUE",$value);
00403                         $this->tpl->parseCurrentBlock();
00404                 }
00405         }
00406         
00407         
00411         function confirmedDeleteObject()
00412         {
00413                 global $ilias;
00414                 
00415                 foreach($_SESSION["saved_post"] as $id)
00416                 {
00417                         $this->object->removeStyle($id);
00418                         $style_obj =& $ilias->obj_factory->getInstanceByObjId($id);
00419                         $style_obj->delete();
00420                 }
00421                 $this->object->update();
00422                 
00423                 ilUtil::redirect($this->getReturnLocation("delete",$this->ctrl->getLinkTarget($this,"")));
00424         }
00425         
00426         
00432         function toggleGlobalDefaultObject()
00433         {
00434                 global $ilias;
00435                 
00436                 if (!isset($_POST["id"]))
00437                 {
00438                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00439                 }
00440                 if(count($_POST["id"]) > 1)
00441                 {
00442                         $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00443                 }
00444 
00445                 $ilias->deleteSetting("fixed_content_style_id");
00446                 $def_style = $ilias->getSetting("default_content_style_id");
00447                 
00448                 if ($def_style != $_POST["id"][0])
00449                 {
00450                         $ilias->setSetting("default_content_style_id", $_POST["id"][0]);
00451                 }
00452                 else
00453                 {
00454                         $ilias->deleteSetting("default_content_style_id");
00455                 }
00456                 
00457                 ilUtil::redirect($this->ctrl->getLinkTarget($this,"view"));
00458         }
00459 
00465         function toggleGlobalFixedObject()
00466         {
00467                 global $ilias;
00468                 
00469                 if (!isset($_POST["id"]))
00470                 {
00471                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00472                 }
00473                 if(count($_POST["id"]) > 1)
00474                 {
00475                         $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00476                 }
00477 
00478                 $ilias->deleteSetting("default_content_style_id");
00479                 $fixed_style = $ilias->getSetting("fixed_content_style_id");
00480                 if ($fixed_style == $_POST["id"][0])
00481                 {
00482                         $ilias->deleteSetting("fixed_content_style_id");
00483                 }
00484                 else
00485                 {
00486                         $ilias->setSetting("fixed_content_style_id", $_POST["id"][0]);
00487                 }
00488                 ilUtil::redirect($this->ctrl->getLinkTarget($this,"view"));
00489         }
00490 
00491         
00498         function showActions($with_subobjects = false)
00499         {
00500 
00501                 // delete
00502                 $this->tpl->setCurrentBlock("tbl_action_btn");
00503                 $this->tpl->setVariable("BTN_NAME", "deleteStyle");
00504                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
00505                 $this->tpl->parseCurrentBlock();
00506 
00507                 // set global default
00508                 $this->tpl->setCurrentBlock("tbl_action_btn");
00509                 $this->tpl->setVariable("BTN_NAME", "toggleGlobalDefault");
00510                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalDefault"));
00511                 $this->tpl->parseCurrentBlock();
00512                 
00513                 // set global default
00514                 $this->tpl->setCurrentBlock("tbl_action_btn");
00515                 $this->tpl->setVariable("BTN_NAME", "toggleGlobalFixed");
00516                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("toggleGlobalFixed"));
00517                 $this->tpl->parseCurrentBlock();
00518 
00519                 if ($with_subobjects === true)
00520                 {
00521                         $this->showPossibleSubObjects();
00522                 }
00523                 
00524                 $this->tpl->setCurrentBlock("tbl_action_row");
00525                 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00526                 $this->tpl->parseCurrentBlock();
00527         }
00528 
00529         
00535         function getTabs(&$tabs_gui)
00536         {
00537                 // tabs are defined manually here. The autogeneration via objects.xml will be deprecated in future
00538                 // for usage examples see ilObjGroupGUI or ilObjSystemFolderGUI
00539         }
00540 } // END class.ilObjStyleSettings
00541 ?>

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