ILIAS  Release_5_0_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 class ilObjCloudGUI extends ilObject2GUI {
24 
28  protected $plugin_service;
29 
30 
36  public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0) {
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  return "cld";
49  }
50 
51 
56  public function executeCommand() {
57  global $ilCtrl, $ilTabs, $ilNavigationHistory, $lng;
58 
59  // Navigation History
60  $link = $ilCtrl->getLinkTarget($this, "render");
61 
62  try {
64  } catch (Exception $e) {
65  ilUtil::sendFailure($lng->txt("cld_no_service_active"), true);
66  ilObjectGUI::redirectToRefId($this->parent_id);
67  }
68 
69  if ($this->object != NULL) {
70  $ilNavigationHistory->addItem($this->object->getRefId(), $link, "cld");
71 
72  try {
73  ilCloudConnector::checkServiceActive($this->object->getServiceName());
74  } catch (Exception $e) {
75  ilUtil::sendFailure($lng->txt("cld_plugin_not_active"), true);
76  ilObjectGUI::redirectToRefId($this->parent_id);
77  }
78 
79  if ($this->object->getAuthComplete() == false && !$_GET["authMode"]) {
80  if ($this->checkPermissionBool("write")) {
81  $this->serviceAuth($this->object);
82  } else {
83  ilUtil::sendFailure($lng->txt("cld_auth_failed"), true);
84  ilObjectGUI::redirectToRefId($this->parent_id);
85  }
86  }
87  $this->plugin_service = ilCloudConnector::getServiceClass($this->object->getServiceName(), $this->object->getId(), false);
88  }
89 
90  $next_class = $ilCtrl->getNextClass($this);
91 
92  $cmd = $ilCtrl->getCmd($this);
93  switch ($cmd) {
94  case "editSettings" :
95  $next_class = "ilcloudpluginsettingsgui";
96  break;
97  case "afterServiceAuth" :
98  $this->checkPermission("write");
99  $this->$cmd();
100 
101  return;
102  case "render" :
103  $this->addHeaderAction();
104  break;
105  }
106 
107  switch ($next_class) {
108  case "ilinfoscreengui":
109  $this->prepareOutput();
110  $this->infoScreenForward();
111  break;
112  case "ilcommonactiondispatchergui":
113  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
115  $this->ctrl->forwardCommand($gui);
116  break;
117  case "ilpermissiongui":
118  $this->prepareOutput();
119  $ilTabs->activateTab("id_permissions");
120  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
121  $perm_gui = new ilPermissionGUI($this);
122  $this->ctrl->forwardCommand($perm_gui);
123  break;
124  case "ilcloudpluginuploadgui":
125  if ($this->checkPermissionBool("upload")) {
126  $upload_gui = ilCloudConnector::getUploadGUIClass($this->plugin_service);
127  $this->ctrl->forwardCommand($upload_gui);
128  }
129  break;
130  case "ilcloudplugincreatefoldergui":
131  if ($this->checkPermissionBool("folders_create")) {
132  $folder_gui = ilCloudConnector::getCreateFolderGUIClass($this->plugin_service);
133  $this->ctrl->forwardCommand($folder_gui);
134  }
135  break;
136  case "ilcloudplugindeletegui":
137  if ($this->checkPermissionBool("delete_files") || $this->checkPermissionBool("delete_folders")) {
138  $delete_gui = ilCloudConnector::getDeleteGUIClass($this->plugin_service);
139  $this->ctrl->forwardCommand($delete_gui);
140  }
141  break;
142  case "ilcloudpluginsettingsgui":
143  $this->prepareOutput();
144  if ($this->checkPermissionBool("write")) {
145  $settings_gui = ilCloudConnector::getSettingsGUIClass($this->plugin_service);
146  $settings_gui->setCloudObject($this->object);
147  $this->ctrl->forwardCommand($settings_gui);
148  }
149  break;
150  case "ilcloudpluginactionlistgui":
151  $action_list_gui = ilCloudConnector::getActionListGUIClass($this->plugin_service);
152  $this->ctrl->forwardCommand($action_list_gui);
153  break;
154  case "ilcloudpluginitemcreationlistgui":
155  $item_creation_gui = ilCloudConnector::getItemCreationListGUIClass($this->plugin_service);
156  $this->ctrl->forwardCommand($item_creation_gui);
157  break;
158  case "ilcloudpluginfiletreegui":
159  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, ilCloudFileTree::getFileTreeFromSession());
160  $this->ctrl->forwardCommand($file_tree_gui);
161  break;
162  case "ilcloudpluginheaderactiongui":
163  $header_action_gui = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
164  $this->ctrl->forwardCommand($header_action_gui);
165  break;
166  case "ilcloudplugininitgui":
167  $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
168  $this->ctrl->forwardCommand($init_gui);
169  break;
170  default:
171  return parent::executeCommand();
172  }
173 
174  return true;
175  }
176 
177 
181  function getStandardCmd() {
182  return "render";
183  }
184 
185 
192  public static function _goto($a_target) {
193  $content = explode("_", $a_target);
194  $_GET["ref_id"] = $content[0];
195  $_POST["path"] = $content[2];
196  $_GET["baseClass"] = "ilrepositorygUI";
197  $_GET["cmdClass"] = "ilobjcloudgui";
198  $_GET["cmd"] = "render";
199  include("ilias.php");
200  }
201 
202 
203  public function infoScreen() {
204  return false;
205  }
206 
207 
208  public function setTabs() {
209  global $ilTabs, $ilCtrl, $ilAccess, $lng;
210 
211  // tab for the "show content" command
212  if ($ilAccess->checkAccess("read", "", $this->object->getRefId())) {
213  $ilTabs->addTab("content", $lng->txt("content"), $ilCtrl->getLinkTarget($this, "render"));
214  $ilTabs->addTab("id_info", $lng->txt("info_short"), $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
215  }
216 
217  // a "properties" tab
218  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
219  $ilTabs->addTab("settings", $lng->txt("settings"), $ilCtrl->getLinkTargetByClass("ilcloudpluginsettingsgui", "editSettings"));
220  }
221 
222  // edit permissions
223  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
224  $ilTabs->addTab("id_permissions", $lng->txt("perm_settings"), $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
225  }
226  }
227 
228 
232  public function infoScreenForward() {
233  global $ilTabs, $ilErr;
234 
235  $ilTabs->activateTab("id_info");
236 
237  if (!$this->checkPermissionBool("visible")) {
238  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
239  }
240 
241  $plugin_info = ilCloudConnector::getInfoScreenGUIClass($this->plugin_service);
242  $info = $plugin_info->getInfoScreen($this);
243  $this->ctrl->forwardCommand($info);
244  }
245 
246 
256  protected function initCreationForms($a_new_type) {
257  $forms = array(
258  self::CFORM_NEW => $this->initCreateForm($a_new_type)
259  );
260 
261  return $forms;
262  }
263 
264 
272  protected function initCreateForm($a_new_type) {
273  global $lng;
274 
275  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
276  $form = new ilPropertyFormGUI();
277  $form->setTarget("_top");
278  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
279  $form->setTitle($this->lng->txt($a_new_type . "_new"));
280 
281  // title
282  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
283  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
284  $ti->setMaxLength(ilObject::TITLE_LENGTH);
285  $ti->setRequired(true);
286  $form->addItem($ti);
287 
288  // description
289  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
290  $ta->setCols(40);
291  $ta->setRows(2);
292  $form->addItem($ta);
293 
294  $services_group = new ilRadioGroupInputGUI($lng->txt("cld_service"), "service");
295  $services_group->setRequired(true);
296  foreach (ilCloudConnector::getActiveServices() as $service) {
297  $option = new ilRadioOption($service, $service);
298  $hook_object = ilCloudConnector::getPluginHookClass($option->getValue());
299  $option->setTitle($hook_object->txt($service));
300  $option->setInfo($hook_object->txt("create_info"));
301  $this->plugin_service = ilCloudConnector::getServiceClass($service, 0, false);
302  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
303  if ($init_gui) {
304  $init_gui->initPluginCreationFormSection($option);
305  }
306  $services_group->addOption($option);
307  }
308 
309  //Select first radio-button by default
310  $services_group->setValue(array_shift($services_group->getOptions())->getValue());
311 
312  $form->addItem($services_group);
313 
314  $form = $this->initDidacticTemplate($form);
315 
316  $form->addCommandButton("save", $this->lng->txt($a_new_type . "_add"));
317  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
318 
319  return $form;
320  }
321 
322 
326  protected function afterSave(ilObjCloud $a_new_object) {
327  try {
328  $form = $this->initCreateForm("cld");
329 
330  if ($form->checkInput()) {
331  $a_new_object->setServiceName($form->getInput("service"));
332  $a_new_object->setRootFolder("/");
333  $a_new_object->setOnline(false);
334  $a_new_object->setAuthComplete(false);
335  $this->plugin_service = new ilCloudPluginService($a_new_object->getServiceName(), $a_new_object->getId());
336  $init_gui = ilCloudConnector::getCreationGUIClass($this->plugin_service);
337  if ($init_gui) {
338  $init_gui->afterSavePluginCreation($a_new_object, $form);
339  }
340  $a_new_object->update();
341  $this->serviceAuth($a_new_object);
342  }
343  } catch (Exception $e) {
344  ilUtil::sendFailure($e->getMessage(), true);
345  ilObjectGUI::redirectToRefId($this->parent_id);
346  }
347  }
348 
349 
353  protected function serviceAuth(ilObjCloud $object) {
354  global $ilCtrl;
355  try {
356  $service = ilCloudConnector::getServiceClass($object->getServiceName(), $object->getId());
357  $service->authService($ilCtrl->getLinkTarget($this, "afterServiceAuth") . "&authMode=true");
358  } catch (Exception $e) {
359  ilUtil::sendFailure($e->getMessage(), true);
360  ilObjectGUI::redirectToRefId($this->parent_id);
361  }
362  }
363 
364  protected function afterServiceAuth() {
365  global $ilCtrl, $lng;
366 
367  try {
368  if ($this->plugin_service->afterAuthService()) {
369  $this->object->setRootId("root", true);
370  $this->object->setAuthComplete(true);
371  $this->object->update();
372  ilUtil::sendSuccess($lng->txt("cld_object_added"), true);
373  $ilCtrl->redirectByClass("ilCloudPluginSettingsGUI", "editSettings");
374  } else {
375  include_once("./Services/Repository/classes/class.ilRepUtil.php");
376  ilRepUtil::deleteObjects($this->object->getRefId(), $this->object->getRefId());
377 
378  ilUtil::sendFailure($lng->txt("cld_auth_failed_no_object_created"), true);
379  ilObjectGUI::redirectToRefId($this->parent_id);
380  }
381  } catch (Exception $e) {
382  ilUtil::sendFailure($e->getMessage(), true);
383  ilObjectGUI::redirectToRefId($this->parent_id);
384  }
385  }
386 
387 
391  protected function addHeaderAction() {
392  $lg = $this->initHeaderAction();
393  if ($lg) {
394  $header_action_class = ilCloudConnector::getHeaderActionGUIClass($this->plugin_service);
395  $header_action_class->addCustomHeaderAction($lg);
396  $this->insertHeaderAction($lg);
397  }
398  }
399 
400 
404  protected function addLocatorItems() {
405  global $ilLocator;
406 
407  if (is_object($this->object)) {
408  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
409  }
410  }
411 
412 
413  public function render() {
414  $init_gui = ilCloudConnector::getInitGUIClass($this->plugin_service);
415  $init_gui->initGUI($this, $this->checkPermissionBool("folders_create"), $this->checkPermissionBool("upload"), $this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $this->checkPermissionBool("download"), $this->checkPermissionBool("files_visible"), $this->checkPermissionBool("folders_visible"));
416  }
417 
418 
419  public function asyncGetBlock() {
420  global $tpl;
421 
422  $response = new stdClass();
423  $response->message = NULL;
424  $response->locator = NULL;
425  $response->content = NULL;
426  $response->success = NULL;
427 
428  try {
430  $file_tree->updateFileTree($_POST["path"]);
431  $node = $file_tree->getNodeFromPath($_POST["path"]);
432  $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, $file_tree);
433  $response->content = $file_tree_gui->getFolderHtml($this, $node->getId(), $this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $this->checkPermissionBool("download"), $this->checkPermissionBool("files_visible"), $this->checkPermissionBool("folders_visible"));
434 
435  $response->locator = $file_tree_gui->getLocatorHtml($file_tree->getNodeFromId($node->getId()));
436  $response->success = true;
437  } catch (Exception $e) {
438  $response->message = $tpl->getMessageHTML($e->getMessage(), "failure");
439  }
440 
441  header('Content-type: application/json');
442  echo ilJsonUtil::encode($response);
443  exit;
444  }
445 
446 
447  function getFile() {
448  global $ilTabs;
449  if ($this->checkPermissionBool("download")) {
450  try {
452  $file_tree->downloadFromService($_GET['id']);
453  } catch (Exception $e) {
454  $ilTabs->activateTab("content");
455  ilUtil::sendFailure($e->getMessage());
456  }
457  }
458  }
459 
460 
462  $action_list = ilCloudConnector::getActionListGUIClass($this->plugin_service);
464 
465  return $action_list->asyncGetContent($this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $file_tree->getNodeFromId($_GET["node_id"]));
466  }
467 }
468 
469 ?>