ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilChatroomUploadFileGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  public function __construct()
14  {
15  throw new Exception('METHOD_NOT_IN_USE', 1456435027);
16  }
17 
22  public function executeDefault($requestedMethod)
23  {
24  }
25 
30  public function uploadFile()
31  {
32  $this->redirectIfNoPermission('read');
33 
34  $upload_path = $this->getUploadPath();
35 
36  $this->checkUploadPath($upload_path);
37 
41  $file = $_FILES['file_to_upload']['tmp_name'];
42  $filename = $_FILES['file_to_upload']['name'];
43  $type = $_FILES['file_to_upload']['type'];
44  $target = $upload_path . $filename;
45 
46  if (ilUtil::moveUploadedFile($file, $filename, $target)) {
47  global $ilUser;
48 
49  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
50  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
51 
52  $room = ilChatroom::byObjectId($this->gui->object->getId());
53  $chat_user = new ilChatroomUser($ilUser, $room);
54  $user_id = $chat_user->getUserId();
55 
56  if (!$room) {
57  throw new Exception('unkown room');
58  } elseif (!$room->isSubscribed($chat_user->getUserId())) {
59  throw new Exception('not subscribed');
60  }
61 
62  $room->saveFileUploadToDb($user_id, $filename, $type);
63  $this->displayLinkToUploadedFile($room, $chat_user);
64  }
65  }
66 
71  public function getUploadPath()
72  {
73  $path = ilUtil::getDataDir() . "/chatroom/" . $this->gui->object->getId() . "/uploads/";
74 
75  return $path;
76  }
77 
82  public function checkUploadPath($path)
83  {
84  $err = false;
85 
86  switch (true) {
87  case !file_exists($path):
89  $err = true;
90  $msg = 'Error: Upload path could not be created!';
91  }
92  break;
93 
94  case !is_dir($path):
95  $err = true;
96  $msg = 'Error: Upload path is not a directory!';
97  break;
98 
99  case !is_readable($path):
100  $err = true;
101  $msg = 'Error: Upload path is not readable!';
102  break;
103 
104  default:
105  }
106 
107  if ($err) {
108  throw new Exception($msg);
109  }
110  }
111 
112  protected function displayLinkToUploadedFile($room, $chat_user)
113  {
114  global $ilCtrl;
115 
116  $scope = $room->getRoomId();
117  $params = array();
118  $params['public'] = 1;
122  $message = json_encode($this->buildMessage(
123  json_encode(array(
124  'format' => array(),
125  'content' => ilUtil::stripSlashes(
126  'Eine neue Datei mit dem Link ' .
127  $ilCtrl->getLinkTarget($this->gui, 'uploadFile-deliverFile') .
128  ' wurde hochgeladen'
129  )
130  )),
131  $params,
132  $chat_user
133  ));
134 
135  $params = array_merge($params, array('message' => $message));
136  $query = http_build_query($params);
137 
138  $connector = $this->gui->getConnector();
139  $response = $connector->post($scope, $query);
140  $responseObject = json_decode($response);
141  /*
142  if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
143  {
144  $room->addHistoryEntry( $message, $recipient, $publicMessage );
145  }
146  */
147  echo $response;
148  exit;
149  }
150 
151  private function buildMessage($messageString, $params, ilChatroomUser $chat_user)
152  {
153  $data = new stdClass();
154 
155  $data->user = $this->gui->object->getPersonalInformation($chat_user);
156  $data->message = $messageString;
157  $data->timestamp = date('c');
158  $data->type = 'message';
159  $data->public = (int) $params['public'];
160  $data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
161 
162  return $data;
163  }
164 
165  public function deliverFile()
166  {
167  // send file
168 
169  echo "hello world";
170  }
171 }
$params
Definition: disable.php:11
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$type
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
executeDefault($requestedMethod)
Default execute method.
catch(Exception $e) $message
Class ilChatroomGUIHandler.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$query
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
buildMessage($messageString, $params, ilChatroomUser $chat_user)
Create styles array
The data for the language used.
checkUploadPath($path)
Checks if given upload path exists, is readable or can be created.
static getDataDir()
get data directory (outside webspace)
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
Class ilChatroomUploadFileGUI Provides methods to upload a file.
$response
uploadFile()
Saves file, fetched from $_FILES to specified upload path.