ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
14  public function __construct()
15  {
16  throw new Exception('METHOD_NOT_IN_USE', 1456435027);
17  }
18 
23  public function executeDefault($requestedMethod)
24  {
25 
26  }
27 
32  public function uploadFile()
33  {
34  global $ilCtrl;
35 
36  if(!ilChatroom::checkUserPermissions('read', $this->gui->ref_id))
37  {
38  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
39  $ilCtrl->redirectByClass("ilrepositorygui", "");
40  }
41 
42  $upload_path = $this->getUploadPath();
43 
44  $this->checkUploadPath($upload_path);
45 
49  $file = $_FILES['file_to_upload']['tmp_name'];
50  $filename = $_FILES['file_to_upload']['name'];
51  $type = $_FILES['file_to_upload']['type'];
52  $target = $upload_path . $filename;
53 
55  {
56  global $ilUser;
57 
58  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
59  require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
60 
61  $room = ilChatroom::byObjectId($this->gui->object->getId());
62  $chat_user = new ilChatroomUser($ilUser, $room);
63  $user_id = $chat_user->getUserId();
64 
65  if(!$room)
66  {
67  throw new Exception('unkown room');
68  }
69  else if(!$room->isSubscribed($chat_user->getUserId()))
70  {
71  throw new Exception('not subscribed');
72  }
73 
74  $room->saveFileUploadToDb($user_id, $filename, $type);
75  $this->displayLinkToUploadedFile($room, $chat_user);
76  }
77 
78  }
79 
84  public function getUploadPath()
85  {
86  $path = ilUtil::getDataDir() . "/chatroom/" . $this->gui->object->getId() . "/uploads/";
87 
88  return $path;
89  }
90 
95  public function checkUploadPath($path)
96  {
97  $err = false;
98 
99  switch(true)
100  {
101  case !file_exists($path):
103  {
104  $err = true;
105  $msg = 'Error: Upload path could not be created!';
106  }
107  break;
108 
109  case !is_dir($path):
110  $err = true;
111  $msg = 'Error: Upload path is not a directory!';
112  break;
113 
114  case !is_readable($path):
115  $err = true;
116  $msg = 'Error: Upload path is not readable!';
117  break;
118 
119  default:
120  }
121 
122  if($err)
123  {
124  throw new Exception($msg);
125  }
126  }
127 
128  protected function displayLinkToUploadedFile($room, $chat_user)
129  {
130  global $ilCtrl;
131 
132  $scope = $room->getRoomId();
133  $params = array();
134  $params['public'] = 1;
138  $message = json_encode($this->buildMessage(
139  json_encode(array(
140  'format' => array(),
141  'content' => ilUtil::stripSlashes(
142  'Eine neue Datei mit dem Link ' .
143  $ilCtrl->getLinkTarget($this->gui, 'uploadFile-deliverFile') .
144  ' wurde hochgeladen'
145  )
146  )), $params, $chat_user
147  ));
148 
149  $params = array_merge($params, array('message' => $message));
150  $query = http_build_query($params);
151 
152  $connector = $this->gui->getConnector();
153  $response = $connector->post($scope, $query);
154  $responseObject = json_decode($response);
155  /*
156  if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
157  {
158  $room->addHistoryEntry( $message, $recipient, $publicMessage );
159  }
160  */
161  echo $response;
162  exit;
163  }
164 
165  private function buildMessage($messageString, $params, ilChatroomUser $chat_user)
166  {
167  $data = new stdClass();
168 
169  $data->user = $this->gui->object->getPersonalInformation($chat_user);
170  $data->message = $messageString;
171  $data->timestamp = date('c');
172  $data->type = 'message';
173  $data->public = (int)$params['public'];
174  $data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
175 
176  return $data;
177  }
178 
179  public function deliverFile()
180  {
181  // send file
182 
183  echo "hello world";
184  }
185 
186 }
187 
188 ?>
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$path
Definition: aliased.php:25
executeDefault($requestedMethod)
Default execute method.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
Class ilChatroomGUIHandler.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
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.
uploadFile()
Saves file, fetched from $_FILES to specified upload path.
$params
Definition: example_049.php:96