1<?php 2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4include_once("./Services/Form/classes/class.ilPropertyFormGUI.php"); 5include_once("./Modules/Cloud/exceptions/class.ilCloudException.php"); 6 7/** 8 * Class ilCloudPluginDeleteGUI 9 * 10 * Standard GUI when deleting files or folders. Could be overwritten by the plugin if needed. 11 * 12 * @author Timon Amstutz <timon.amstutz@ilub.unibe.ch> 13 * @version $Id: 14 * @extends ilCloudPluginGUI 15 * @ingroup ModulesCloud 16 */ 17class ilCloudPluginDeleteGUI extends ilCloudPluginGUI 18{ 19 20 /** 21 * @var string 22 */ 23 protected $path = "/"; 24 /** 25 * @var int 26 */ 27 protected $id = 0; 28 /** 29 * @var bool 30 */ 31 protected $is_dir; 32 /** 33 * @var ilConfirmationGUI 34 */ 35 protected $gui; 36 37 38 /** 39 * is called async and prints the content from the confirmation gui 40 */ 41 public function asyncDeleteItem() 42 { 43 global $DIC; 44 $tpl = $DIC['tpl']; 45 $lng = $DIC['lng']; 46 $response = new stdClass(); 47 $response->success = null; 48 $response->message = null; 49 $response->content = null; 50 $file_tree = ilCloudFileTree::getFileTreeFromSession(); 51 try { 52 $node = $file_tree->getNodeFromId($_POST["id"]); 53 if (!$node) { 54 throw new ilCloudException(ilCloudException::ID_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION); 55 } else { 56 $this->is_dir = $node->getIsDir(); 57 } 58 59 $this->path = $node->getPath(); 60 $this->id = $node->getId(); 61 if (!$this->is_dir) { 62 $this->path = rtrim($this->path, "/"); 63 } 64 $this->initDeleteItem(); 65 $response->content = "<div id = 'cld_delete_item' >"; 66 if ($this->is_dir) { 67 $response->content .= ilUtil::getSystemMessageHTML($lng->txt("cld_confirm_delete_folder"), "question"); 68 } else { 69 $response->content .= ilUtil::getSystemMessageHTML($lng->txt("cld_confirm_delete_file"), "question"); 70 } 71 $response->content .= $this->gui->getHTML(); 72 $response->content .= "</div >"; 73 $response->success = true; 74 } catch (Exception $e) { 75 $response->message = ilUtil::getSystemMessageHTML($e->getMessage(), "failure"); 76 } 77 header('Content-type: application/json'); 78 echo ilJsonUtil::encode($response); 79 exit; 80 } 81 82 83 public function initDeleteItem() 84 { 85 global $DIC; 86 $ilCtrl = $DIC['ilCtrl']; 87 $lng = $DIC['lng']; 88 89 include_once("Services/Utilities/classes/class.ilConfirmationTableGUI.php"); 90 $this->gui = new ilConfirmationTableGUI(true); 91 $this->gui->setFormName("cld_delete_item"); 92 $this->gui->getTemplateObject()->setVariable("ACTIONTARGET", "cld_blank_target"); 93 94 $this->gui->addCommandButton('deleteItem', $lng->txt('confirm')); 95 $this->gui->addCommandButton('cancel', $lng->txt('cancel')); 96 $this->gui->setFormAction($ilCtrl->getFormAction($this)); 97 98 if ($this->is_dir) { 99 $item[] = array( 100 "var" => 'id', 101 "id" => $this->id, 102 "text" => basename($this->path), 103 "img" => ilUtil::getImagePath('icon_dcl_fold.svg'), 104 ); 105 } else { 106 $item[] = array( 107 "var" => 'id', 108 "id" => $this->id, 109 "text" => basename($this->path), 110 "img" => ilUtil::getImagePath('icon_dcl_file.svg'), 111 ); 112 } 113 $this->gui->setData($item); 114 } 115 116 117 /** 118 * Update properties 119 */ 120 public function deleteItem() 121 { 122 global $DIC; 123 $tpl = $DIC['tpl']; 124 $lng = $DIC['lng']; 125 126 $response = new stdClass(); 127 $response->success = null; 128 $response->message = null; 129 130 if (true) { 131 try { 132 $file_tree = ilCloudFileTree::getFileTreeFromSession(); 133 $node = $file_tree->getNodeFromId($_POST["id"]); 134 $file_tree->deleteFromService($node->getId()); 135 $response->message = ilUtil::getSystemMessageHTML($lng->txt("cld_file_deleted"), "success"); 136 $response->success = true; 137 } catch (Exception $e) { 138 $response->message = ilUtil::getSystemMessageHTML($e->getMessage(), "failure"); 139 } 140 } 141 echo "<script language='javascript' type='text/javascript'>window.parent.il.CloudFileList.afterDeleteItem(" . ilJsonUtil::encode($response) 142 . ");</script>"; 143 exit; 144 } 145 146 147 /** 148 * Update properties 149 */ 150 public function cancel() 151 { 152 $response = new stdClass(); 153 $response->status = "cancel"; 154 155 echo "<script language='javascript' type='text/javascript'>window.parent.il.CloudFileList.afterDeleteItem(" . ilJsonUtil::encode($response) 156 . ");</script>"; 157 exit; 158 } 159} 160