ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilChatroomUploadFileTask.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
16{
17
18 private $gui;
19
26 {
27 $this->gui = $gui;
28 }
29
35 public function executeDefault($requestedMethod)
36 {
37
38 }
39
45 public function uploadFile()
46 {
47 global $ilCtrl;
48
49 if ( !ilChatroom::checkUserPermissions( 'read', $this->gui->ref_id ) )
50 {
51 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
52 $ilCtrl->redirectByClass("ilrepositorygui", "");
53 }
54
55 $upload_path = $this->getUploadPath();
56
57 $this->checkUploadPath($upload_path);
58
62 $file = $_FILES['file_to_upload']['tmp_name'];
63 $filename = $_FILES['file_to_upload']['name'];
64 $type = $_FILES['file_to_upload']['type'];
65 $target = $upload_path . $filename;
66
68 {
69 global $ilUser;
70
71 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
72 require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
73
74 $room = ilChatroom::byObjectId( $this->gui->object->getId() );
75 $chat_user = new ilChatroomUser($ilUser, $room);
76 $user_id = $chat_user->getUserId();
77
78 if( !$room )
79 {
80 throw new Exception('unkown room');
81 }
82 else if( !$room->isSubscribed( $chat_user->getUserId() ) )
83 {
84 throw new Exception('not subscribed');
85 }
86
87 $room->saveFileUploadToDb($user_id, $filename, $type);
88 $this->displayLinkToUploadedFile($room, $chat_user);
89 }
90
91 }
92
93 protected function displayLinkToUploadedFile($room, $chat_user)
94 {
95 global $ilCtrl;
96
97 $scope = $room->getRoomId();
98 $params = array();
99 $params['public'] = 1;
103 $message = json_encode( $this->buildMessage(
104 json_encode(array(
105 'format' => array(),
106 'content' => ilUtil::stripSlashes(
107 'Eine neue Datei mit dem Link ' .
108 $ilCtrl->getLinkTarget($this->gui, 'uploadFile-deliverFile') .
109 ' wurde hochgeladen'
110 )
111 )) , $params, $chat_user
112 ) );
113
114 $params = array_merge( $params, array('message' => $message) );
115 $query = http_build_query( $params );
116
117 $connector = $this->gui->getConnector();
118 $response = $connector->post( $scope, $query );
119 $responseObject = json_decode( $response );
120 /*
121 if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
122 {
123 $room->addHistoryEntry( $message, $recipient, $publicMessage );
124 }
125 */
126 echo $response;
127 exit;
128 }
129
130 public function deliverFile()
131 {
132 // send file
133
134 echo "hello world";
135 }
136
137 private function buildMessage($messageString, $params, ilChatroomUser $chat_user)
138 {
139 $data = new stdClass();
140
141 $data->user = $this->gui->object->getPersonalInformation( $chat_user );
142 $data->message = $messageString;
143 $data->timestamp = date( 'c' );
144 $data->type = 'message';
145 $data->public = (int)$params['public'];
146 $data->recipients = $params['recipients']; // ? explode(",", $params['recipients']) : array();
147
148 return $data;
149 }
150
156 public function checkUploadPath($path)
157 {
158 $err = false;
159
160 switch( true )
161 {
162 case !file_exists( $path ):
164 {
165 $err = true;
166 $msg = 'Error: Upload path could not be created!';
167 }
168 break;
169
170 case !is_dir( $path ):
171 $err = true;
172 $msg = 'Error: Upload path is not a directory!';
173 break;
174
175 case !is_readable( $path ):
176 $err = true;
177 $msg = 'Error: Upload path is not readable!';
178 break;
179
180 default:
181 }
182
183 if( $err )
184 {
185 throw new Exception( $msg );
186 }
187 }
188
194 public function getUploadPath()
195 {
196 $path = ilUtil::getDataDir() . "/chatroom/" . $this->gui->object->getId() . "/uploads/";
197
198 return $path;
199 }
200
201}
202
203?>
print $file
$filename
Definition: buildRTE.php:89
Class ilChatroomUploadFileTask.
buildMessage($messageString, $params, ilChatroomUser $chat_user)
checkUploadPath($path)
Checks if given upload path exists, is readable or can be created.
executeDefault($requestedMethod)
Default execute method.
uploadFile()
Saves file, fetched from $_FILES to specified upload path.
__construct(ilChatroomObjectGUI $gui)
Constructor.
Class ilChatroomUser.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
static getDataDir()
get data directory (outside webspace)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$data
$params
Definition: example_049.php:96
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
$path
Definition: index.php:22
global $ilUser
Definition: imgupload.php:15