Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 require_once "classes/class.ilObjectGUI.php";
00034 require_once "Modules/Chat/classes/class.ilChatServerConfig.php";
00035 require_once "Modules/Chat/classes/class.ilChatServerCommunicator.php";
00036 require_once "Modules/Chat/classes/class.ilChatUser.php";
00037 require_once "Modules/Chat/classes/class.ilChatRoom.php";
00038 require_once "Modules/Chat/classes/class.ilFileDataChat.php";
00039
00040 class ilObjChat extends ilObject
00041 {
00042 var $server_conf;
00043 var $server_comm;
00044 var $chat_room;
00045 var $chat_user;
00046 var $chat_recording = null;
00047
00054 function ilObjChat($a_id = 0,$a_call_by_reference = true)
00055 {
00056 $this->type = "chat";
00057 $this->ilObject($a_id,$a_call_by_reference);
00058
00059 $this->server_conf =& new ilChatServerConfig();
00060 $this->server_comm =& new ilChatServerCommunicator($this);
00061 $this->chat_user =& new ilChatUser();
00062 $this->chat_room =& new ilChatRoom($this->getId());
00063 }
00064
00073 public static function _lookupModeratorRole($a_ref_id)
00074 {
00075 global $ilDB;
00076
00077 $mod_title = 'il_chat_moderator_'.$a_ref_id;
00078 $query = "SELECT * FROM object_data WHERE title = ".$ilDB->quote($mod_title);
00079 $res = $ilDB->query($query);
00080 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00081 {
00082 return $row->obj_id;
00083 }
00084 return 0;
00085 }
00086
00087
00088
00097 public function cloneObject($a_target_id,$a_copy_id = 0)
00098 {
00099 global $ilDB,$ilUser;
00100
00101 $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
00102 $this->cloneAutoGeneratedRoles($new_obj);
00103 }
00104
00112 public function cloneAutoGeneratedRoles($new_obj)
00113 {
00114 global $ilLog,$rbacadmin,$rbacreview;
00115
00116 $moderator = ilObjChat::_lookupModeratorRole($this->getRefId());
00117 $new_moderator = ilObjChat::_lookupModeratorRole($new_obj->getRefId());
00118 $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
00119 $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
00120
00121 if(!$moderator || !$new_moderator || !$source_rolf || !$target_rolf)
00122 {
00123 $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_chat_moderator');
00124 }
00125 $rbacadmin->copyRolePermissions($moderator,$source_rolf,$target_rolf,$new_moderator,true);
00126 $ilLog->write(__METHOD__.' : Finished copying of role il_chat_moderator.');
00127 }
00128
00129
00130 function read()
00131 {
00132
00133 parent::read();
00134
00135 $this->server_conf =& new ilChatServerConfig();
00136 $this->server_comm =& new ilChatServerCommunicator($this);
00137 $this->chat_user =& new ilChatUser();
00138 $this->chat_room =& new ilChatRoom($this->getId());
00139 }
00140
00146 function initDefaultRoles()
00147 {
00148 global $rbacadmin;
00149
00150
00151 $rolf_obj =& $this->createRoleFolder();
00152
00153
00154 $role_obj = $rolf_obj->createRole("il_chat_moderator_".$this->getRefId(),"Moderator of chat obj_no.".$this->getId());
00155
00156
00157 $permissions = ilRbacReview::_getOperationIdsByName(array('visible','read','moderate'));
00158 $rbacadmin->grantPermission($role_obj->getId(),
00159 $permissions,
00160 $this->getRefId());
00161
00162 unset($rolf_obj);
00163
00164 return array($role_obj->getId());
00165 }
00166
00167 function delete()
00168 {
00169 global $ilDB;
00170
00171 if(!parent::delete())
00172 {
00173 return false;
00174 }
00175 $rooms = $this->chat_room->getAllRoomsOfObject();
00176 foreach($rooms as $room)
00177 {
00178 $this->chat_room->delete($room["room_id"]);
00179 }
00180
00181
00182 $query = "DELETE FROM chat_room_messages ".
00183 "WHERE chat_id = ".$ilDB->quote($this->getRefId())."";
00184
00185 $res = $this->ilias->db->query($query);
00186
00187
00188 $query = "DELETE FROM chat_user ".
00189 "WHERE chat_id = ".$ilDB->quote($this->getRefId())."";
00190
00191 $res = $this->ilias->db->query($query);
00192
00193
00194 $query = "SELECT record_id FROM chat_records WHERE
00195 chat_id = ".$ilDB->quote($this->getId())."";
00196 $res = $this->ilias->db->query($query);
00197 if (DB::isError($res)) die("ilObjChat::delete(): " . $res->getMessage() . "<br>SQL-Statement: ".$query);
00198 if (($num = $res->numRows()) > 0)
00199 {
00200 for ($i = 0; $i < $num; $i++)
00201 {
00202 $data = $res->fetchRow(DB_FETCHMODE_ASSOC);
00203 $this->ilias->db->query("DELETE FROM chat_record_data WHERE record_id = ".$ilDB->quote($data["record_id"])."");
00204 }
00205
00206 }
00207 $query = "DELETE FROM chat_records WHERE
00208 chat_id = ".$ilDB->quote($this->getId())."";
00209 $res = $this->ilias->db->query($query);
00210
00211 return true;
00212 }
00213
00214 function sendMessage($a_id)
00215 {
00216 include_once "Services/Mail/classes/class.ilMail.php";
00217
00218 $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
00219
00220
00221 $tmp_user = ilObjectFactory::getInstanceByObjId($a_id);
00222
00223
00224 $tmp_lang =& new ilLanguage($tmp_user->getLanguage());
00225 $tmp_lang->loadLanguageModule("chat");
00226
00227 $message = $tmp_mail_obj->sendMail($this->__formatRecipient($tmp_user),"","",$this->__formatSubject($tmp_lang),
00228 $this->__formatBody($tmp_user,$tmp_lang),array(),array("normal"));
00229
00230 unset($tmp_mail_obj);
00231 unset($tmp_lang);
00232 unset($tmp_user);
00233
00234 return true;
00235 }
00236
00237 function getHTMLDirectory()
00238 {
00239 $tmp_tpl =& new ilTemplate("tpl.chat_export.html",true,true);
00240
00241 $this->chat_room->setRoomId(0);
00242
00243 $tmp_tpl->setVariable("CHAT_NAME",$this->getTitle());
00244 $tmp_tpl->setVariable("CHAT_DATE",strftime("%c",time()));
00245 $tmp_tpl->setVariable("CONTENT",$this->chat_room->getAllMessages());
00246
00247 $file_obj =& new ilFileDataChat($this);
00248
00249
00250 return $file_obj->addFile('index.html',$tmp_tpl->get());
00251 }
00252
00253
00254 function __formatRecipient(&$user)
00255 {
00256 if(is_object($user))
00257 {
00258 return $user->getLogin();
00259 }
00260 return false;
00261 }
00262
00263 function __formatSubject(&$lang)
00264 {
00265 return $lang->txt("chat_invitation_subject");
00266 }
00267
00268 function __formatBody(&$user,&$lang)
00269 {
00270 global $ilClientIniFile;
00271
00272 $room_id = $this->chat_room->getRoomId();
00273 $room_title = $this->chat_room->getTitle();
00274
00275 $body = sprintf($this->lng->txt("chat_notification_intro"), $ilClientIniFile->readVariable("client","name"), ILIAS_HTTP_PATH)."\n\n";
00276 $body .= $lang->txt("chat_invitation_body")." ";
00277 $body .= $this->ilias->account->getFullname();
00278 $body .= "\n";
00279 $body .= $lang->txt("chat_chatroom_body").' '.$this->getTitle();
00280 if ($room_title != '')
00281 {
00282 $body .= ', '.$room_title;
00283 }
00284 $body .= "\n\n";
00285 $body .= $lang->txt('chat_to_chat_body');
00286 $body .= ': '.ILIAS_HTTP_PATH."/chat.php?room_id=".$room_id."&ref_id=".$this->getRefId();
00287
00288 return $body;
00289 }
00290
00291
00292 function __initChatRecording()
00293 {
00294 if(!is_object($this->chat_recording))
00295 {
00296 include_once 'Modules/Chat/classes/class.ilChatRecording.php';
00297
00298 $this->chat_recording = new ilChatRecording($this->getId());
00299
00300 return true;
00301 }
00302 return false;
00303 }
00304
00305 function _getPublicChatRefId()
00306 {
00307 static $public_chat_ref_id = 0;
00308
00309 global $tree;
00310
00311 if($public_chat_ref_id)
00312 {
00313 return $public_chat_ref_id;
00314 }
00315 else
00316 {
00317 foreach($tree->getSubTree($tree->getNodeData(SYSTEM_FOLDER_ID)) as $node)
00318 {
00319 if($node['type'] == 'chat')
00320 {
00321 return $public_chat_ref_id = $node['child'];
00322 }
00323 }
00324 }
00325 return false;
00326 }
00327
00328
00329 }
00330 ?>