ILIAS  Release_5_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("./Services/Object/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, $ilCtrl;
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 
63  // configure classes
64  $config = false;
65  if (substr(strtolower($next_class), strlen($next_class) - 9) == "configgui")
66  {
67  $path = $ilCtrl->lookupClassPath(strtolower($next_class));
68  if ($path != "")
69  {
70  include_once($path);
71  $nc = new $next_class();
72 
74  $_GET["cname"], $_GET["slot_id"], $_GET["pname"]);
75 
76  $nc->setPluginObject($pl);
77 
78  $ret = $this->ctrl->forwardCommand($nc);
79  $config = true;
80  }
81  }
82 
83  if (!$config)
84  {
85  if(!$cmd || $cmd == 'view')
86  {
87  $cmd = "listPlugins";
88  }
89 
90  $this->$cmd();
91  }
92  break;
93  }
94  return true;
95  }
96 
103  public function getAdminTabs()
104  {
105  global $rbacsystem, $ilAccess, $lng;
106 
107  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
108  {
109  $this->tabs_gui->addTab("plugins",
110  $lng->txt("cmps_plugins"),
111  $this->ctrl->getLinkTarget($this, "listPlugins"));
112 
113  if(DEVMODE)
114  {
115  $this->tabs_gui->addTab("slots",
116  $lng->txt("cmps_slots"),
117  $this->ctrl->getLinkTarget($this, "listSlots"));
118  }
119  }
120 
121  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
122  {
123  $this->tabs_gui->addTab("perm_settings",
124  $lng->txt("perm_settings"),
125  $this->ctrl->getLinkTargetByClass('ilpermissiongui',"perm"));
126  }
127 
128  if ($_GET["ctype"] == "Services")
129  {
130  $this->tabs_gui->activateTab("services");
131  }
132  }
133 
137  public function listSlots()
138  {
139  if(!DEVMODE)
140  {
141  $this->ctrl->redirect($this, "listPlugins");
142  }
143 
144  $this->tabs_gui->activateTab('slots');
145 
146  include_once("./Services/Component/classes/class.ilComponentsTableGUI.php");
147  $comp_table = new ilComponentsTableGUI($this, "listSlots");
148 
149  $this->tpl->setContent($comp_table->getHTML());
150  }
151 
158  function listPlugins()
159  {
160  global $tpl, $ilTabs;
161 
162  $ilTabs->activateTab("plugins");
163  include_once("./Services/Component/classes/class.ilPluginsOverviewTableGUI.php");
164  $table = new ilPluginsOverviewTableGUI($this, "listPlugins");
165  $tpl->setContent($table->getHTML());
166  }
167 
172  {
173  global $tpl,$lng, $ilTabs, $ilCtrl;
174 
175  if(!DEVMODE)
176  {
177  $ilCtrl->redirect($this, "listPlugins");
178  }
179 
180  $ilTabs->clearTargets();
181 
182  $ilTabs->setBackTarget($lng->txt("cmps_slots"),
183  $ilCtrl->getLinkTarget($this, "listSlots"));
184 
185  include_once("./Services/Component/classes/class.ilComponent.php");
186  $comp = ilComponent::getComponentObject($_GET["ctype"], $_GET["cname"]);
187 
188  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
189  $form = new ilPropertyFormGUI();
190 
191  // component
192  $ne = new ilNonEditableValueGUI($lng->txt("cmps_component"), "", true);
193  $ne->setValue($comp->getComponentType()."/".$comp->getName()." [".$comp->getId()."]");
194  $form->addItem($ne);
195 
196  // plugin slot
197  $ne = new ilNonEditableValueGUI($lng->txt("cmps_plugin_slot"), "", true);
198  $ne->setValue($comp->getPluginSlotName($_GET["slot_id"])." [".$_GET["slot_id"]."]");
199  $form->addItem($ne);
200 
201  // main dir
202  $ne = new ilNonEditableValueGUI($lng->txt("cmps_main_dir"), "", true);
203  $ne->setValue($comp->getPluginSlotDirectory($_GET["slot_id"])."/&lt;Plugin_Name&gt;");
204  $form->addItem($ne);
205 
206  // plugin file
207  $ne = new ilNonEditableValueGUI($lng->txt("cmps_plugin_file"), "", true);
208  $ne->setValue("&lt;".$lng->txt("cmps_main_dir")."&gt;".
209  "/classes/class.il&lt;Plugin_Name&gt;Plugin.php");
210  $form->addItem($ne);
211 
212  // language files
213  $ne = new ilNonEditableValueGUI($lng->txt("cmps_lang_files"), "", true);
214  $ne->setValue("&lt;".$lng->txt("cmps_main_dir")."&gt;".
215  "/lang/ilias_&lt;Language ID&gt;.lang");
216  $form->addItem($ne);
217 
218  // db update
219  $ne = new ilNonEditableValueGUI($lng->txt("cmps_db_update"), "", true);
220  $ne->setValue("&lt;".$lng->txt("cmps_main_dir")."&gt;".
221  "/sql/dbupdate.php");
222  $form->addItem($ne);
223 
224  // lang prefix
225  $ne = new ilNonEditableValueGUI($lng->txt("cmps_plugin_lang_prefixes"), "", true);
226  $ne->setValue($comp->getPluginSlotLanguagePrefix($_GET["slot_id"])."&lt;Plugin_ID&gt;_");
227  $form->addItem($ne);
228 
229  // db prefix
230  $ne = new ilNonEditableValueGUI($lng->txt("cmps_plugin_db_prefixes"), "", true);
231  $ne->setValue($comp->getPluginSlotLanguagePrefix($_GET["slot_id"])."&lt;Plugin_ID&gt;_");
232  $form->addItem($ne);
233 
234  $form->setTitle($lng->txt("cmps_plugin_slot"));
235 
236  // set content and title
237  $tpl->setContent($form->getHTML());
238  $tpl->setTitle($comp->getComponentType()."/".$comp->getName().": ".
239  $lng->txt("cmps_plugin_slot")." \"".$comp->getPluginSlotName($_GET["slot_id"])."\"");
240  $tpl->setDescription("");
241  }
242 
243  function showPlugin()
244  {
245  global $ilCtrl, $ilTabs, $lng, $tpl, $ilDB, $ilToolbar;
246 
247  if(!$_GET["ctype"] ||
248  !$_GET["cname"] ||
249  !$_GET["slot_id"] ||
250  !$_GET["plugin_id"])
251  {
252  $ilCtrl->redirect($this, "listPlugins");
253  }
254 
255  include_once("./Services/Component/classes/class.ilPluginSlot.php");
256  $slot = new ilPluginSlot($_GET["ctype"], $_GET["cname"], $_GET["slot_id"]);
257 
258  $plugin = null;
259  foreach($slot->getPluginsInformation() as $item)
260  {
261  if($item["id"] == $_GET["plugin_id"])
262  {
263  $plugin = $item;
264  break;
265  }
266  }
267  if(!$plugin)
268  {
269  $ilCtrl->redirect($this, "listPlugins");
270  }
271 
272  $ilTabs->clearTargets();
273  $ilTabs->setBackTarget($lng->txt("cmps_plugins"),
274  $ilCtrl->getLinkTarget($this, "listPlugins"));
275 
276  $ilCtrl->setParameter($this, "ctype", $_GET["ctype"]);
277  $ilCtrl->setParameter($this, "cname", $_GET["cname"]);
278  $ilCtrl->setParameter($this, "slot_id", $_GET["slot_id"]);
279  $ilCtrl->setParameter($this, "plugin_id", $_GET["plugin_id"]);
280  $ilCtrl->setParameter($this, "pname", $plugin["name"]);
281 
282  $langs = ilPlugin::getAvailableLangFiles($slot->getPluginsDirectory()."/".
283  $plugin["name"]."/lang");
284 
285  // dbupdate
286  $file = ilPlugin::getDBUpdateScriptName($_GET["ctype"], $_GET["cname"],
287  ilPluginSlot::lookupSlotName($_GET["ctype"], $_GET["cname"], $_GET["slot_id"]),
288  $plugin["name"]);
289  $db_curr = $db_file = null;
290  if (@is_file($file))
291  {
292  include_once("./Services/Component/classes/class.ilPluginDBUpdate.php");
293  $dbupdate = new ilPluginDBUpdate($_GET["ctype"], $_GET["cname"],
294  $_GET["slot_id"], $plugin["name"], $ilDB, true, "");
295 
296  $db_curr = $dbupdate->getCurrentVersion();
297  $db_file = $dbupdate->getFileVersion();
298 
299  /* update command
300  if ($db_file > $db_curr)
301  {
302  $ilToolbar->addButton($lng->txt("cmps_update_db"),
303  $ilCtrl->getLinkTarget($this, "updatePluginDB"));
304  } */
305  }
306 
307 
308  // toolbar actions
309 
310  if ($plugin["activation_possible"])
311  {
312  $ilToolbar->addButton($lng->txt("cmps_activate"),
313  $ilCtrl->getLinkTarget($this, "activatePlugin"));
314  }
315 
316  // deactivation/refresh languages button
317  if ($plugin["is_active"])
318  {
319  // refresh languages button
320  if (count($langs) > 0)
321  {
322  $ilToolbar->addButton($lng->txt("cmps_refresh"),
323  $ilCtrl->getLinkTarget($this, "refreshLanguages"));
324  }
325 
326  // configure button
327  if (ilPlugin::hasConfigureClass($slot->getPluginsDirectory(), $plugin["name"]) &&
328  $ilCtrl->checkTargetClass(ilPlugin::getConfigureClassName($plugin["name"])))
329  {
330  $ilToolbar->addButton($lng->txt("cmps_configure"),
331  $ilCtrl->getLinkTargetByClass(strtolower(ilPlugin::getConfigureClassName($plugin["name"])), "configure"));
332  }
333 
334  // deactivate button
335  $ilToolbar->addButton($lng->txt("cmps_deactivate"),
336  $ilCtrl->getLinkTarget($this, "deactivatePlugin"));
337  }
338 
339  // update button
340  if ($plugin["needs_update"])
341  {
342  $ilToolbar->addButton($lng->txt("cmps_update"),
343  $ilCtrl->getLinkTarget($this, "updatePlugin"));
344  }
345 
346 
347  // info
348 
349  $resp = array();
350  if (strlen($plugin["responsible"]))
351  {
352  $responsibles = explode('/', $plugin["responsible_mail"]);
353  foreach($responsibles as $responsible)
354  {
355  if(!strlen($responsible = trim($responsible)))
356  {
357  continue;
358  }
359 
360  $resp[] = $responsible;
361  }
362 
363  $resp = $plugin["responsible"]." (".implode(" / ", $resp).")";
364  }
365 
366  if ($plugin["is_active"])
367  {
368  $status = $lng->txt("cmps_active");
369  }
370  else
371  {
372  $r = ($status["inactive_reason"] != "")
373  ? " (".$status["inactive_reason"].")"
374  : "";
375 
376  $status = $lng->txt("cmps_inactive").$r;
377  }
378 
379  $info[""][$lng->txt("cmps_name")] = $plugin["name"];
380  $info[""][$lng->txt("cmps_id")] = $plugin["id"];
381  $info[""][$lng->txt("cmps_version")] = $plugin["version"];
382  if($resp)
383  {
384  $info[""][$lng->txt("cmps_responsible")] = $resp;
385  }
386  $info[""][$lng->txt("cmps_ilias_min_version")] = $plugin["ilias_min_version"];
387  $info[""][$lng->txt("cmps_ilias_max_version")] = $plugin["ilias_max_version"];
388  $info[""][$lng->txt("cmps_status")] = $status;
389 
390  if(sizeof($langs))
391  {
392  $lang_files = array();
393  foreach($langs as $lang)
394  {
395  $lang_files[] = $lang["file"];
396  }
397  $info[""][$lng->txt("cmps_languages")] = implode(", ", $lang_files);
398  }
399  else
400  {
401  $info[""][$lng->txt("cmps_languages")] = $lng->txt("cmps_no_language_file_available");
402  }
403 
404  $info[$lng->txt("cmps_basic_files")]["plugin.php"] = $plugin["plugin_php_file_status"] ?
405  $lng->txt("cmps_available") :
406  $lng->txt("cmps_missing");
407  $info[$lng->txt("cmps_basic_files")][$lng->txt("cmps_class_file")] = ($plugin["class_file_status"] ?
408  $lng->txt("cmps_available") :
409  $lng->txt("cmps_missing")).
410  " (".$plugin["class_file"].")";
411 
412  if(!$db_file)
413  {
414  $info[$lng->txt("cmps_database")][$lng->txt("file")] = $lng->txt("cmps_no_db_update_file_available");
415  }
416  else
417  {
418  $info[$lng->txt("cmps_database")][$lng->txt("file")] = "dbupdate.php";
419  $info[$lng->txt("cmps_database")][$lng->txt("cmps_current_version")] = $db_curr;
420  $info[$lng->txt("cmps_database")][$lng->txt("cmps_file_version")] = $db_file;
421  }
422 
423  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
424  $form = new ilPropertyFormGUI();
425  $form->setTitle($lng->txt("cmps_plugin"));
426 
427  foreach($info as $section => $items)
428  {
429  if(trim($section))
430  {
431  $sec = new ilFormSectionHeaderGUI();
432  $sec->setTitle($section);
433  $form->addItem($sec);
434  }
435  foreach($items as $key => $value)
436  {
437  $non = new ilNonEditableValueGUI($key);
438  $non->setValue($value);
439  $form->addItem($non);
440  }
441  }
442 
443  $tpl->setContent($form->getHTML());
444  }
445 
450  {
451  global $ilCtrl;
452 
453 die ("ilObjComponentSettigsGUI::refreshPluginsInformation: deprecated");
454 
455  include_once("./Services/Component/classes/class.ilPlugin.php");
456  ilPlugin::refreshPluginXmlInformation();
457 
458  if ($_GET["mode"] == IL_COMP_SERVICE)
459  {
460  $ilCtrl->redirect($this, "listServices");
461  }
462  else
463  {
464  $ilCtrl->redirect($this, "listModules");
465  }
466  }
467 
471  function activatePlugin()
472  {
473  global $ilCtrl, $lng;
474 
475  include_once("./Services/Component/classes/class.ilPlugin.php");
476  $pl = ilPlugin::getPluginObject($_GET["ctype"], $_GET["cname"],
477  $_GET["slot_id"], $_GET["pname"]);
478 
479  try
480  {
481  $result = $pl->activate();
482  if ($result !== true)
483  {
485  }
486  else
487  {
488  ilUtil::sendSuccess($lng->txt("cmps_plugin_activated"), true);
489  }
490  }
491  catch(ilPluginException $e)
492  {
493  ilUtil::sendFailure($e->getMessage, true);
494  }
495 
496  $ilCtrl->setParameter($this, "ctype", $_GET["ctype"]);
497  $ilCtrl->setParameter($this, "cname", $_GET["cname"]);
498  $ilCtrl->setParameter($this, "slot_id", $_GET["slot_id"]);
499 
500  if($_GET["plugin_id"])
501  {
502  $ilCtrl->setParameter($this, "plugin_id", $_GET["plugin_id"]);
503  $ilCtrl->redirect($this, "showPlugin");
504  }
505  else
506  {
507  $ilCtrl->redirect($this, "listPlugins");
508  }
509  }
510 
514  function updatePlugin()
515  {
516  include_once("./Services/Component/classes/class.ilPlugin.php");
517  $pl = ilPlugin::getPluginObject($_GET["ctype"], $_GET["cname"],
518  $_GET["slot_id"], $_GET["pname"]);
519 
520  $result = $pl->update();
521 
522  if ($result !== true)
523  {
524  ilUtil::sendFailure($pl->message, true);
525  }
526  else
527  {
528  ilUtil::sendSuccess($pl->message, true);
529  }
530 
531  // reinitialize control class
532  global $ilCtrl;
533  $ilCtrl->initBaseClass("iladministrationgui");
534  $_GET["cmd"] = "jumpToPluginSlot";
535  $ilCtrl->setParameterByClass("iladministrationgui", "ctype", $_GET["ctype"]);
536  $ilCtrl->setParameterByClass("iladministrationgui", "cname", $_GET["cname"]);
537  $ilCtrl->setParameterByClass("iladministrationgui", "slot_id", $_GET["slot_id"]);
538  $ilCtrl->setParameterByClass("iladministrationgui", "plugin_id", $_GET["plugin_id"]);
539  $ilCtrl->setTargetScript("ilias.php");
540 // $ilCtrl->callBaseClass();
541  ilUtil::redirect("ilias.php?admin_mode=settings&baseClass=ilAdministrationGUI".
542  "&cmd=jumpToPluginSlot&ref_id=".$_GET["ref_id"]."&ctype=".$_GET["ctype"].
543  "&cname=".$_GET["cname"]."&slot_id=".$_GET["slot_id"]."&plugin_id=".$_GET["plugin_id"]);
544  //$ilCtrl->redirectByClass("iladministrationgui", );
545  }
546 
550  function deactivatePlugin()
551  {
552  global $ilCtrl, $lng;
553 
554  include_once("./Services/Component/classes/class.ilPlugin.php");
555  $pl = ilPlugin::getPluginObject($_GET["ctype"], $_GET["cname"],
556  $_GET["slot_id"], $_GET["pname"]);
557 
558  $result = $pl->deactivate();
559 
560  if ($result !== true)
561  {
563  }
564  else
565  {
566  ilUtil::sendSuccess($lng->txt("cmps_plugin_deactivated"), true);
567  }
568 
569  $ilCtrl->setParameter($this, "ctype", $_GET["ctype"]);
570  $ilCtrl->setParameter($this, "cname", $_GET["cname"]);
571  $ilCtrl->setParameter($this, "slot_id", $_GET["slot_id"]);
572 
573  if($_GET["plugin_id"])
574  {
575  $ilCtrl->setParameter($this, "plugin_id", $_GET["plugin_id"]);
576  $ilCtrl->redirect($this, "showPlugin");
577  }
578  else
579  {
580  $ilCtrl->redirect($this, "listPlugins");
581  }
582  }
583 
587  function refreshLanguages()
588  {
589  global $ilCtrl;
590 
591  include_once("./Services/Component/classes/class.ilPlugin.php");
592  $pl = ilPlugin::getPluginObject($_GET["ctype"], $_GET["cname"],
593  $_GET["slot_id"], $_GET["pname"]);
594 
595  $result = $pl->updateLanguages();
596 
597  if ($result !== true)
598  {
600  }
601 
602  $ilCtrl->setParameter($this, "ctype", $_GET["ctype"]);
603  $ilCtrl->setParameter($this, "cname", $_GET["cname"]);
604  $ilCtrl->setParameter($this, "slot_id", $_GET["slot_id"]);
605 
606  if($_GET["plugin_id"])
607  {
608  $ilCtrl->setParameter($this, "plugin_id", $_GET["plugin_id"]);
609  $ilCtrl->redirect($this, "showPlugin");
610  }
611  else
612  {
613  $ilCtrl->redirect($this, "listPlugins");
614  }
615  }
616 
620  function updatePluginDB()
621  {
622  global $ilDB;
623 
624 die ("ilObjComponentSettigsGUI::updatePluginDB: deprecated");
625 
626  include_once("./Services/Component/classes/class.ilPluginDBUpdate.php");
627  $dbupdate = new ilPluginDBUpdate($_GET["ctype"], $_GET["cname"],
628  $_GET["slot_id"], $_GET["pname"], $ilDB, true);
629 
630  $dbupdate->applyUpdate();
631 
632  if ($dbupdate->updateMsg == "no_changes")
633  {
634  $message = $this->lng->txt("no_changes").". ".$this->lng->txt("database_is_uptodate");
635  }
636  else
637  {
638  foreach ($dbupdate->updateMsg as $row)
639  {
640  $message .= $this->lng->txt($row["msg"]).": ".$row["nr"]."<br/>";
641  }
642  }
643 
644  ilUtil::sendInfo($message, true);
645 
646  $ilCtrl->setParameter($this, "ctype", $_GET["ctype"]);
647  $ilCtrl->setParameter($this, "cname", $_GET["cname"]);
648  $ilCtrl->setParameter($this, "slot_id", $_GET["slot_id"]);
649  $ilCtrl->redirect($this, "listPlugins");
650  }
651 
652 
653 }
654 ?>