ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjComponentSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 include_once("./classes/class.ilObjectGUI.php");
4 
5 
17 {
18  private static $ERROR_MESSAGE;
24  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
25  {
26  $this->type = 'cmps';
27  parent::ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
28 
29  $this->lng->loadLanguageModule('cmps');
30  }
31 
38  public function executeCommand()
39  {
40  global $rbacsystem,$ilErr,$ilAccess;
41 
42  $next_class = $this->ctrl->getNextClass($this);
43  $cmd = $this->ctrl->getCmd();
44 
45  $this->prepareOutput();
46 
47  if(!$ilAccess->checkAccess('read','',$this->object->getRefId()))
48  {
49  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
50  }
51 
52  switch($next_class)
53  {
54  case 'ilpermissiongui':
55  $this->tabs_gui->setTabActive('perm_settings');
56  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
57  $perm_gui =& new ilPermissionGUI($this);
58  $ret =& $this->ctrl->forwardCommand($perm_gui);
59  break;
60 
61  default:
62  if(!$cmd || $cmd == 'view')
63  {
64  $cmd = "listModules";
65  }
66 
67  $this->$cmd();
68  break;
69  }
70  return true;
71  }
72 
79  public function getAdminTabs()
80  {
81  global $rbacsystem, $ilAccess;
82  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
83  {
84  $this->tabs_gui->addTarget("cmps_modules",
85  $this->ctrl->getLinkTarget($this, "listModules"),
86  array("listModules", "view", "showPluginSlot"));
87 
88  $this->tabs_gui->addTarget("cmps_services",
89  $this->ctrl->getLinkTarget($this, "listServices"),
90  array("listServices"));
91  }
92 
93  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
94  {
95  $this->tabs_gui->addTarget("perm_settings",
96  $this->ctrl->getLinkTargetByClass('ilpermissiongui',"perm"),
97  array(),'ilpermissiongui');
98  }
99 
100  if ($_GET["ctype"] == "Services")
101  {
102  $this->tabs_gui->activateTab("cmps_services");
103  }
104  }
105 
109  public function listModules()
110  {
111  global $ilCtrl, $lng, $ilSetting;
112 
113  $this->tabs_gui->setTabActive('cmps_modules');
114 
115  $tpl = new ilTemplate("tpl.component_list.html", true, true, "Services/Component");
116 
117  /*
118  $tpl->setVariable("HREF_REFRESH_PLUGINS_INFORMATION",
119  $ilCtrl->getLinkTarget($this, "refreshPluginsInformation"));
120  $tpl->setVariable("TXT_REFRESH_PLUGINS_INFORMATION",
121  $lng->txt("cmps_refresh_plugins_inf"));
122  */
123 
124  include_once("./Services/Component/classes/class.ilComponentsTableGUI.php");
125  $comp_table = new ilComponentsTableGUI($this, "listModules");
126 
127  $tpl->setVariable("TABLE", $comp_table->getHTML());
128  $this->tpl->setContent($tpl->get());
129  }
130 
134  public function listServices()
135  {
136  global $ilCtrl, $lng, $ilSetting;
137 
138  $this->tabs_gui->setTabActive('cmps_services');
139 
140  $tpl = new ilTemplate("tpl.component_list.html", true, true, "Services/Component");
141 
142  $ilCtrl->setParameter($this, "mode", IL_COMP_SERVICE);
143  $tpl->setVariable("HREF_REFRESH_PLUGINS_INFORMATION",
144  $ilCtrl->getLinkTarget($this, "refreshPluginsInformation"));
145  $tpl->setVariable("TXT_REFRESH_PLUGINS_INFORMATION",
146  $lng->txt("cmps_refresh_plugins_inf"));
147 
148  include_once("./Services/Component/classes/class.ilComponentsTableGUI.php");
149  $comp_table = new ilComponentsTableGUI($this, "listServices", IL_COMP_SERVICE);
150 
151  $tpl->setVariable("TABLE", $comp_table->getHTML());
152  $this->tpl->setContent($tpl->get());
153  }
154 
158  function saveOptions()
159  {
160  global $ilSetting, $ilCtrl, $lng;
161 
162  // disable creation
163  if (is_array($_POST["obj_pos"]))
164  {
165  foreach($_POST["obj_pos"] as $k => $v)
166  {
167  $ilSetting->set("obj_dis_creation_".$k, (int) $_POST["obj_dis_creation"][$k]);
168  }
169  }
170 
171  // add new position
172  $double = $ex_pos = array();
173  if (is_array($_POST["obj_pos"]))
174  {
175  reset($_POST["obj_pos"]);
176  foreach($_POST["obj_pos"] as $k => $v)
177  {
178  if (in_array($v, $ex_pos))
179  {
180  $double[$v] = $v;
181  }
182  $ex_pos[] = $v;
183  $ilSetting->set("obj_add_new_pos_".$k, $v);
184  }
185  }
186 
187  if (count($double) == 0)
188  {
189  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
190  }
191  else
192  {
193  ilUtil::sendInfo($lng->txt("cmps_duplicate_positions")." ".implode($double, ", "), true);
194  }
195 
196  $ilCtrl->redirect($this, "listModules");
197  }
198 
202  function showPluginSlot()
203  {
204  global $tpl,$lng, $ilTabs;
205 
206  if ($_GET["mode"] == "Services")
207  {
208  $ilTabs->setTabActive("cmps_services");
209  }
210 
211  //slot_id
212  $ptpl = new ilTemplate("tpl.plugin_slot.html", true, true,
213  "Services/Component");
214 
215  include_once("./Services/Component/classes/class.ilComponent.php");
216  $comp = ilComponent::getComponentObject($_GET["ctype"], $_GET["cname"]);
217  $ptpl->setVariable("TXT_COMPONENT", $lng->txt("cmps_component"));
218  $ptpl->setVariable("VAL_COMPONENT_NAME", $comp->getComponentType()."/".$comp->getName());
219  $ptpl->setVariable("VAL_COMPONENT_ID", $comp->getId());
220 
221  $ptpl->setVariable("TXT_PLUGIN_SLOT", $lng->txt("cmps_plugin_slot"));
222  $ptpl->setVariable("VAL_PLUGIN_SLOT", $comp->getPluginSlotName($_GET["slot_id"]));
223  $ptpl->setVariable("VAL_PLUGIN_SLOT_ID", $_GET["slot_id"]);
224 
225  // directories
226  $ptpl->setVariable("TXT_PLUGIN_DIR", $lng->txt("cmps_plugin_dirs"));
227  $ptpl->setVariable("VAL_PLUGIN_DIR",
228  $comp->getPluginSlotDirectory($_GET["slot_id"])."/&lt;Plugin_Name&gt;");
229  $ptpl->setVariable("TXT_MAIN_DIR", $lng->txt("cmps_main_dir"));
230  $ptpl->setVariable("TXT_PLUGIN_FILE", $lng->txt("cmps_plugin_file"));
231  $ptpl->setVariable("TXT_LANG_FILES", $lng->txt("cmps_lang_files"));
232  $ptpl->setVariable("TXT_DB_UPDATE", $lng->txt("cmps_db_update"));
233  $ptpl->setVariable("VAL_PLUGIN_FILE",
234  "&lt;".$lng->txt("cmps_main_dir")."&gt;".
235  "/classes/class.il&lt;Plugin_Name&gt;Plugin.php");
236  $ptpl->setVariable("VAL_LANG_FILES",
237  "&lt;".$lng->txt("cmps_main_dir")."&gt;".
238  "/lang/ilias_&lt;Language ID&gt;.lang");
239  $ptpl->setVariable("VAL_DB_UPDATE",
240  "&lt;".$lng->txt("cmps_main_dir")."&gt;".
241  "/sql/dbupdate.php");
242 
243  $ptpl->setVariable("TXT_PLUGIN_LANG_PREFIX", $lng->txt("cmps_plugin_lang_prefixes"));
244  $ptpl->setVariable("VAL_PLUGIN_LANG_PREFIX",
245  $comp->getPluginSlotLanguagePrefix($_GET["slot_id"])."&lt;Plugin_ID&gt;_");
246 
247  $ptpl->setVariable("TXT_PLUGIN_DB_PREFIX", $lng->txt("cmps_plugin_db_prefixes"));
248  $ptpl->setVariable("VAL_PLUGIN_DB_PREFIX",
249  $comp->getPluginSlotLanguagePrefix($_GET["slot_id"])."&lt;Plugin_ID&gt;_");
250 
251  // plugins table
252  include_once("./Services/Component/classes/class.ilPluginsTableGUI.php");
253  $plugins_table = new ilPluginsTableGUI($this, "showPluginSlot",
254  $_GET["ctype"], $_GET["cname"], $_GET["slot_id"]);
255  $ptpl->setVariable("PLUGIN_LIST", $plugins_table->getHTML());
256 
257  // set content and title
258  $tpl->setContent($ptpl->get());
259  $tpl->setTitle($comp->getComponentType()."/".$comp->getName().": ".
260  $lng->txt("cmps_plugin_slot")." \"".$comp->getPluginSlotName($_GET["slot_id"])."\"");
261  $tpl->setDescription("");
262  }
263 
268  {
269  global $ilCtrl;
270 die ("ilObjComponentSettigsGUI::refreshPluginsInformation: deprecated");
271  include_once("./Services/Component/classes/class.ilPlugin.php");
272  ilPlugin::refreshPluginXmlInformation();
273 
274  if ($_GET["mode"] == IL_COMP_SERVICE)
275  {
276  $ilCtrl->redirect($this, "listServices");
277  }
278  else
279  {
280  $ilCtrl->redirect($this, "listModules");
281  }
282  }
283 
287  function activatePlugin()
288  {
289  global $ilCtrl, $lng;
290 
291  include_once("./Services/Component/classes/class.ilPlugin.php");
292  $pl = ilPlugin::getPluginObject($_GET["ctype"], $_GET["cname"],
293  $_GET["slot_id"], $_GET["pname"]);
294 
295  try
296  {
297  $result = $pl->activate();
298  if ($result !== true)
299  {
301  }
302  else
303  {
304  ilUtil::sendSuccess($lng->txt("cmps_plugin_activated"), true);
305  }
306  }
307  catch(ilPluginException $e)
308  {
309  ilUtil::sendFailure($e->getMessage, true);
310  }
311 
312  $ilCtrl->setParameter($this, "ctype", $_GET["ctype"]);
313  $ilCtrl->setParameter($this, "cname", $_GET["cname"]);
314  $ilCtrl->setParameter($this, "slot_id", $_GET["slot_id"]);
315  $ilCtrl->redirect($this, "showPluginSlot");
316  }
317 
321  function updatePlugin()
322  {
323 
324  include_once("./Services/Component/classes/class.ilPlugin.php");
325  $pl = ilPlugin::getPluginObject($_GET["ctype"], $_GET["cname"],
326  $_GET["slot_id"], $_GET["pname"]);
327 
328  $result = $pl->update();
329 
330  if ($result !== true)
331  {
332  ilUtil::sendFailure($pl->message, true);
333  }
334  else
335  {
336  ilUtil::sendSuccess($pl->message, true);
337  }
338 
339  // reinitialize control class
340  global $ilCtrl;
341  $ilCtrl->initBaseClass("iladministrationgui");
342  $_GET["cmd"] = "jumpToPluginSlot";
343  $ilCtrl->setParameterByClass("iladministrationgui", "ctype", $_GET["ctype"]);
344  $ilCtrl->setParameterByClass("iladministrationgui", "cname", $_GET["cname"]);
345  $ilCtrl->setParameterByClass("iladministrationgui", "slot_id", $_GET["slot_id"]);
346  $ilCtrl->setTargetScript("ilias.php");
347  $ilCtrl->callBaseClass();
348  //$ilCtrl->redirectByClass("iladministrationgui", );
349  }
350 
354  function deactivatePlugin()
355  {
356  global $ilCtrl, $lng;
357 
358  include_once("./Services/Component/classes/class.ilPlugin.php");
359  $pl = ilPlugin::getPluginObject($_GET["ctype"], $_GET["cname"],
360  $_GET["slot_id"], $_GET["pname"]);
361 
362  $result = $pl->deactivate();
363 
364  if ($result !== true)
365  {
367  }
368  else
369  {
370  ilUtil::sendSuccess($lng->txt("cmps_plugin_deactivated"), true);
371  }
372 
373  $ilCtrl->setParameter($this, "ctype", $_GET["ctype"]);
374  $ilCtrl->setParameter($this, "cname", $_GET["cname"]);
375  $ilCtrl->setParameter($this, "slot_id", $_GET["slot_id"]);
376  $ilCtrl->redirect($this, "showPluginSlot");
377  }
378 
382  function refreshLanguages()
383  {
384  global $ilCtrl;
385 
386  include_once("./Services/Component/classes/class.ilPlugin.php");
387  $pl = ilPlugin::getPluginObject($_GET["ctype"], $_GET["cname"],
388  $_GET["slot_id"], $_GET["pname"]);
389 
390  $result = $pl->updateLanguages();
391 
392  if ($result !== true)
393  {
395  }
396 
397  $ilCtrl->setParameter($this, "ctype", $_GET["ctype"]);
398  $ilCtrl->setParameter($this, "cname", $_GET["cname"]);
399  $ilCtrl->setParameter($this, "slot_id", $_GET["slot_id"]);
400  $ilCtrl->redirect($this, "showPluginSlot");
401  }
402 
406  function updatePluginDB()
407  {
408  global $ilDB;
409 
410  include_once("./Services/Component/classes/class.ilPluginDBUpdate.php");
411  $dbupdate = new ilPluginDBUpdate($_GET["ctype"], $_GET["cname"],
412  $_GET["slot_id"], $_GET["pname"], $ilDB, true);
413 
414  $dbupdate->applyUpdate();
415 
416  if ($dbupdate->updateMsg == "no_changes")
417  {
418  $message = $this->lng->txt("no_changes").". ".$this->lng->txt("database_is_uptodate");
419  }
420  else
421  {
422  foreach ($dbupdate->updateMsg as $row)
423  {
424  $message .= $this->lng->txt($row["msg"]).": ".$row["nr"]."<br/>";
425  }
426  }
427 
428  ilUtil::sendInfo($message, true);
429 
430  $ilCtrl->setParameter($this, "ctype", $_GET["ctype"]);
431  $ilCtrl->setParameter($this, "cname", $_GET["cname"]);
432  $ilCtrl->setParameter($this, "slot_id", $_GET["slot_id"]);
433  $ilCtrl->redirect($this, "showPluginSlot");
434  }
435 
436 
437 }
438 ?>