ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjCloudGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Object/classes/class.ilObject2GUI.php");
5 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
6 include_once("class.ilCloudPluginFileTreeGUI.php");
7 include_once("class.ilCloudFileTree.php");
8 include_once("class.ilCloudConnector.php");
9 
23 {
24 
28  protected $plugin_service;
29 
35  public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
36  {
37  global $lng;
38 
39  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
40  $lng->loadLanguageModule("cld");
41 
42  }
43 
47  final function getType()
48  {
49  return "cld";
50  }
51 
52  /*
53  * executeCommand
54  */
55  public function executeCommand()
56  {
57  global $ilCtrl, $ilTabs, $ilNavigationHistory, $lng;
58 
59  // Navigation History
60  $link = $ilCtrl->getLinkTarget($this, "render");
61 
62  try
63  {
65  } catch (Exception $e)
66  {
67  ilUtil::sendFailure($lng->txt("cld_no_service_active"), true);
68  ilObjectGUI::redirectToRefId($this->parent_id);
69  }
70 
71  if ($this->object != NULL)
72  {
73  $ilNavigationHistory->addItem($this->object->getRefId(), $link, "cld");
74 
75  try
76  {
77  ilCloudConnector::checkServiceActive($this->object->getServiceName());
78  }
79  catch(Exception $e)
80  {
81  ilUtil::sendFailure($lng->txt("cld_plugin_not_active"), true);
82  ilObjectGUI::redirectToRefId($this->parent_id);
83  }
84 
85  if($this->object->getAuthComplete() == false && !$_GET["authMode"])
86  {
87  if ($this->checkPermissionBool("write"))
88  {
89  $this->serviceAuth($this->object);
90  }
91  else
92  {
93  ilUtil::sendFailure($lng->txt("cld_auth_failed"),true);
94  ilObjectGUI::redirectToRefId($this->parent_id);
95  }
96  }
97  $this->plugin_service = ilCloudConnector::getServiceClass($this->object->getServiceName(), $this->object->getId(), false);
98  }
99 
100  $next_class = $ilCtrl->getNextClass($this);
101 
102  $cmd = $ilCtrl->getCmd($this);
103  switch ($cmd)
104  {
105  case "editSettings" :
106  $next_class = "ilcloudpluginsettingsgui";
107  break;
108  case "afterServiceAuth" :
109  $this->checkPermission("write");
110  $this->$cmd();
111  return;
112  case "render" :
113  $this->addHeaderAction();
114  break;
115  }
116 
117  switch ($next_class)
118  {
119  case "ilinfoscreengui":
120  $this->prepareOutput();
121  $this->infoScreenForward();
122  break;
123  case "ilcommonactiondispatchergui":
124  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
126  $this->ctrl->forwardCommand($gui);
127  break;
128  case "ilpermissiongui":
129  $this->prepareOutput();
130  $ilTabs->activateTab("id_permissions");
131  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
132  $perm_gui = new ilPermissionGUI($this);
133  $this->ctrl->forwardCommand($perm_gui);
134  break;
135  case "ilcloudpluginuploadgui":
136  if ($this->checkPermissionBool("upload"))
137  {
138  $upload_gui = ilCloudConnector::getUploadGUIClass($this->plugin_service);
139  $this->ctrl->forwardCommand($upload_gui);
140  }
141  break;
142  case "ilcloudplugincreatefoldergui":
143  if ($this->checkPermissionBool("folders_create"))
144  {
145  $folder_gui = ilCloudConnector::getCreateFolderGUIClass($this->plugin_service);
146  $this->ctrl->forwardCommand($folder_gui);
147  }
148  break;
149  case "ilcloudplugindeletegui":
150  if ($this->checkPermissionBool("delete_files") || $this->checkPermissionBool("delete_folders"))
151  {
152  $delete_gui = ilCloudConnector::getDeleteGUIClass($this->plugin_service);
153  $this->ctrl->forwardCommand($delete_gui);
154  }
155  break;
156  case "ilcloudpluginsettingsgui":
157  $this->prepareOutput();
158  if ($this->checkPermissionBool("write"))
159  {
160  $settings_gui = ilCloudConnector::getSettingsGUIClass($this->plugin_service);
161  $settings_gui->setCloudObject($this->object);
162  $this->ctrl->forwardCommand($settings_gui);
163  }
164  break;
165  case "ilcloudpluginactionlistgui":
166  $action_list_gui = ilCloudConnector::getActionListGUIClass($this->plugin_service);
167  $this->ctrl->forwardCommand($action_list_gui);
168  break;
169  case "ilcloudpluginitemcreationlistgui":
170  $item_creation_gui = ilCloudConnector::getItemCreationListGUIClass($this->plugin_service);
171  $this->ctrl->forwardCommand($item_creation_gui);
172  break;
173  case "ilcloudpluginfiletreegui":
174  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service,ilCloudFileTree::getFileTreeFromSession());
175  $this->ctrl->forwardCommand($file_tree_gui);
176  break;
177  case "ilcloudpluginheaderactiongui":
178  $header_action_gui = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
179  $this->ctrl->forwardCommand($header_action_gui);
180  break;
181  case "ilcloudplugininitgui":
182  $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
183  $this->ctrl->forwardCommand($init_gui);
184  break;
185  default:
186  return parent::executeCommand();
187  }
188 
189  return true;
190  }
191 
195  function getStandardCmd()
196  {
197  return "render";
198  }
199 
206  public function _goto($a_target)
207  {
208  $content = explode("_", $a_target);
209  $_GET["ref_id"] = $content[0];
210  $_POST["path"] = $content[2];
211  $_GET["baseClass"] = "ilrepositorygUI";
212  $_GET["cmdClass"] = "ilobjcloudgui";
213  $_GET["cmd"] = "render";
214  include("ilias.php");
215  }
216 
217  function infoScreen()
218  {
219  return false;
220  }
221 
225  function setTabs()
226  {
227  global $ilTabs, $ilCtrl, $ilAccess, $lng;
228 
229  // tab for the "show content" command
230  if ($ilAccess->checkAccess("read", "", $this->object->getRefId()))
231  {
232  $ilTabs->addTab("content", $lng->txt("content"), $ilCtrl->getLinkTarget($this, "render"));
233  $ilTabs->addTab("id_info", $lng->txt("info"), $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
234  }
235 
236  // a "properties" tab
237  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
238  {
239  $ilTabs->addTab("settings", $lng->txt("settings"), $ilCtrl->getLinkTargetByClass("ilcloudpluginsettingsgui", "editSettings"));
240  }
241 
242  // edit permissions
243  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId()))
244  {
245  $ilTabs->addTab("id_permissions", $lng->txt("perm_settings"), $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
246  }
247  }
248 
252  public function infoScreenForward()
253  {
254  global $ilTabs, $ilErr;
255 
256  $ilTabs->activateTab("id_info");
257 
258  if (!$this->checkPermissionBool("visible"))
259  {
260  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
261  }
262 
263  $plugin_info = ilCloudConnector::getInfoScreenGUIClass($this->plugin_service);
264  $info = $plugin_info->getInfoScreen($this);
265  $this->ctrl->forwardCommand($info);
266  }
267 
268 
277  protected function initCreationForms($a_new_type)
278  {
279  $forms = array(
280  self::CFORM_NEW => $this->initCreateForm($a_new_type)
281  );
282 
283  return $forms;
284  }
285 
292  protected function initCreateForm($a_new_type)
293  {
294  global $lng;
295 
296  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
297  $form = new ilPropertyFormGUI();
298  $form->setTarget("_top");
299  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
300  $form->setTitle($this->lng->txt($a_new_type . "_new"));
301 
302  // title
303  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
304  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
305  $ti->setMaxLength(ilObject::TITLE_LENGTH);
306  $ti->setRequired(true);
307  $ti->setValidationRegexp('/^[ a-zA-Z0-9\-]+$/i');
308  $form->addItem($ti);
309 
310  // description
311  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
312  $ta->setCols(40);
313  $ta->setRows(2);
314  $form->addItem($ta);
315 
316  $services_group = new ilRadioGroupInputGUI($lng->txt("cld_service"), "service");
317  $services_group->setRequired(true);
318  foreach (ilCloudConnector::getActiveServices() as $service)
319  {
320  $option = new ilRadioOption($service, $service);
321  $hook_object = ilCloudConnector::getPluginHookClass($option->getValue());
322  $option->setTitle($hook_object->txt($service));
323  $option->setInfo($hook_object->txt("create_info"));
324  $this->plugin_service = ilCloudConnector::getServiceClass($service, 0, false);
325  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
326  if($init_gui)
327  {
328  $init_gui->initPluginCreationFormSection($option);
329  }
330  $services_group->addOption($option);
331  }
332 
333  $form->addItem($services_group);
334 
335  $form = $this->initDidacticTemplate($form);
336 
337  $form->addCommandButton("save", $this->lng->txt($a_new_type . "_add"));
338  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
339 
340  return $form;
341  }
342 
343  /*
344  * afterSave
345  */
346  protected function afterSave(ilObjCloud $a_new_object)
347  {
348  try
349  {
350  $form = $this->initCreateForm("cld");
351 
352  if ($form->checkInput())
353  {
354  $a_new_object->setServiceName($form->getInput("service"));
355  $a_new_object->setRootFolder("/");
356  $a_new_object->setOnline(false);
357  $a_new_object->setAuthComplete(false);
358  $this->plugin_service = new ilCloudPluginService($a_new_object->getServiceName(), $a_new_object->getId());
359  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
360  if ($init_gui)
361  {
362  $init_gui->afterSavePluginCreation($a_new_object, $form);
363  }
364  $a_new_object->update();
365  $this->serviceAuth($a_new_object);
366  }
367 
368  } catch (Exception $e)
369  {
370  ilUtil::sendFailure($e->getMessage(),true);
371  ilObjectGUI::redirectToRefId($this->parent_id);
372  }
373  }
374 
375  protected function serviceAuth($object)
376  {
377  global $ilCtrl;
378  try{
379  $service = ilCloudConnector::getServiceClass($object->getServiceName(), $object->getId());
380  $service->authService($ilCtrl->getLinkTarget($this, "afterServiceAuth") . "&authMode=true");
381  } catch (Exception $e)
382  {
383  ilUtil::sendFailure($e->getMessage(), true);
384  ilObjectGUI::redirectToRefId($this->parent_id);
385  }
386 
387  }
388 
389  protected function afterServiceAuth()
390  {
391  global $ilCtrl,$lng;
392 
393  try
394  {
395  if($this->plugin_service->afterAuthService())
396  {
397  $this->object->setRootId("root",true);
398  $this->object->setAuthComplete(true);
399  $this->object->update();
400  ilUtil::sendSuccess($lng->txt("cld_object_added"), true);
401  $ilCtrl->redirectByClass("ilCloudPluginSettingsGUI", "editSettings");
402  }
403  else
404  {
405  include_once("./Services/Repository/classes/class.ilRepUtil.php");
406  ilRepUtil::deleteObjects($this->object->getRefId(), $this->object->getRefId());
407 
408  ilUtil::sendFailure($lng->txt("cld_auth_failed_no_object_created"),true);
409  ilObjectGUI::redirectToRefId($this->parent_id);
410  }
411  } catch (Exception $e)
412  {
413  ilUtil::sendFailure($e->getMessage(), true);
414  ilObjectGUI::redirectToRefId($this->parent_id);
415  }
416  }
417 
421  protected function addHeaderAction()
422  {
423  $lg = $this->initHeaderAction();
424  if($lg)
425  {
426  $header_action_class = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
427  $header_action_class->addCustomHeaderAction($lg);
428  $this->insertHeaderAction($lg);
429  }
430  }
431 
435  protected function addLocatorItems()
436  {
437  global $ilLocator;
438 
439  if (is_object($this->object))
440  {
441  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
442  }
443  }
444 
445  public function render()
446  {
447 
448  $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
449  $init_gui->initGUI($this, $this->checkPermissionBool("folders_create"),
450  $this->checkPermissionBool("upload"),
451  $this->checkPermissionBool("delete_files"),
452  $this->checkPermissionBool("delete_folders"),
453  $this->checkPermissionBool("download"),
454  $this->checkPermissionBool("files_visible"),
455  $this->checkPermissionBool("folders_visible"));
456  }
457 
458 
459  public function asyncGetBlock()
460  {
461  global $tpl;
462 
463  $response = new stdClass();
464  $response->message = null;
465  $response->locator = null;
466  $response->content = null;
467  $response->success = null;
468 
469  try{
471  $file_tree->updateFileTree($_POST["path"]);
472  $node = $file_tree->getNodeFromPath($_POST["path"]);
473  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service,$file_tree);
474  $response->content = $file_tree_gui->getFolderHtml($this,
475  $node->getId(),
476  $this->checkPermissionBool("delete_files"),
477  $this->checkPermissionBool("delete_folders"),
478  $this->checkPermissionBool("download"),
479  $this->checkPermissionBool("files_visible"),
480  $this->checkPermissionBool("folders_visible"));
481 
482  $response->locator = $file_tree_gui->getLocatorHtml($file_tree->getNodeFromId($node->getId()));
483  $response->success = true;
484  }
485  catch(Exception $e)
486  {
487  $response->message = $tpl->getMessageHTML($e->getMessage(),"failure");
488  }
489 
490  header('Content-type: application/json');
491  echo ilJsonUtil::encode($response);
492  exit;
493  }
494 
495  function getFile()
496  {
497  global $ilTabs;
498  if ($this->checkPermissionBool("download"))
499  {
500  try{
502  $file_tree->downloadFromService($_GET['id']);
503  } catch (Exception $e)
504  {
505  $ilTabs->activateTab("content");
506  ilUtil::sendFailure($e->getMessage());
507  }
508  }
509  }
510 
512  {
513  $action_list = ilCloudConnector::getActionListGUIClass($this->plugin_service);
515  return $action_list->asyncGetContent($this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $file_tree->getNodeFromId($_GET["node_id"]));
516  }
517 }
518 ?>