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
00034 require_once "classes/class.ilObjectGUI.php";
00035 require_once "chat/classes/class.ilChatServerConfig.php";
00036 require_once "chat/classes/class.ilChatServerCommunicator.php";
00037 require_once "chat/classes/class.ilChatUser.php";
00038 require_once "chat/classes/class.ilChatRoom.php";
00039 require_once "chat/classes/class.ilFileDataChat.php";
00040
00041 class ilObjChat extends ilObject
00042 {
00043 var $server_conf;
00044 var $server_comm;
00045 var $chat_room;
00046 var $chat_user;
00047 var $chat_recording = null;
00048
00055 function ilObjChat($a_id = 0,$a_call_by_reference = true)
00056 {
00057 $this->type = "chat";
00058 $this->ilObject($a_id,$a_call_by_reference);
00059
00060 $this->server_conf =& new ilChatServerConfig();
00061 $this->server_comm =& new ilChatServerCommunicator($this);
00062 $this->chat_user =& new ilChatUser();
00063 $this->chat_room =& new ilChatRoom($this->getId());
00064 }
00065
00066 function read()
00067 {
00068
00069 parent::read();
00070
00071 $this->server_conf =& new ilChatServerConfig();
00072 $this->server_comm =& new ilChatServerCommunicator($this);
00073 $this->chat_user =& new ilChatUser();
00074 $this->chat_room =& new ilChatRoom($this->getId());
00075 }
00076
00082 function initDefaultRoles()
00083 {
00084 global $rbacadmin;
00085
00086
00087 $rolf_obj =& $this->createRoleFolder();
00088
00089
00090 $role_obj = $rolf_obj->createRole("il_chat_moderator_".$this->getRefId(),"Moderator of chat obj_no.".$this->getId());
00091
00092
00093 $permissions = ilRbacReview::_getOperationIdsByName(array('visible','read','moderate'));
00094 $rbacadmin->grantPermission($role_obj->getId(),
00095 $permissions,
00096 $this->getRefId());
00097
00098 unset($rolf_obj);
00099
00100 return array($role_obj->getId());
00101 }
00102
00103 function ilClone($a_parent_ref)
00104 {
00105 $tmp_obj =& ilObjectFactory::getInstanceByRefId(parent::ilClone($a_parent_ref));
00106 }
00107
00108
00109 function delete()
00110 {
00111 if(!parent::delete())
00112 {
00113 return false;
00114 }
00115 $rooms = $this->chat_room->getAllRoomsOfObject();
00116 foreach($rooms as $room)
00117 {
00118 $this->chat_room->delete($room["room_id"]);
00119 }
00120
00121
00122 $query = "DELETE FROM chat_room_messages ".
00123 "WHERE chat_id = '".$this->getRefId()."'";
00124
00125 $res = $this->ilias->db->query($query);
00126
00127
00128 $query = "DELETE FROM chat_user ".
00129 "WHERE chat_id = '".$this->getRefId()."'";
00130
00131 $res = $this->ilias->db->query($query);
00132
00133
00134 $query = "SELECT record_id FROM chat_records WHERE
00135 chat_id = '".$this->getId()."'";
00136 $res = $this->ilias->db->query($query);
00137 if (DB::isError($res)) die("ilObjChat::delete(): " . $res->getMessage() . "<br>SQL-Statement: ".$q);
00138 if (($num = $res->numRows()) > 0)
00139 {
00140 for ($i = 0; $i < $num; $i++)
00141 {
00142 $data = $res->fetchRow(DB_FETCHMODE_ASSOC);
00143 $this->ilias->db->query("DELETE FROM chat_record_data WHERE record_id = '" . $data["record_id"] . "'");
00144 }
00145
00146 }
00147 $query = "DELETE FROM chat_records WHERE
00148 chat_id = '".$this->getId()."'";
00149 $res = $this->ilias->db->query($query);
00150
00151 return true;
00152 }
00153
00154 function sendMessage($a_id)
00155 {
00156 include_once "./classes/class.ilMail.php";
00157
00158 $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
00159
00160
00161 $tmp_user = ilObjectFactory::getInstanceByObjId($a_id);
00162
00163
00164 $tmp_lang =& new ilLanguage($tmp_user->getLanguage());
00165 $tmp_lang->loadLanguageModule("chat");
00166
00167 $message = $tmp_mail_obj->sendMail($this->__formatRecipient($tmp_user),"","",$this->__formatSubject($tmp_lang),
00168 $this->__formatBody($tmp_user,$tmp_lang),array(),array("normal"));
00169
00170 unset($tmp_mail_obj);
00171 unset($tmp_lang);
00172 unset($tmp_user);
00173
00174 return true;
00175 }
00176
00177 function getHTMLDirectory()
00178 {
00179 $tmp_tpl =& new ilTemplate("tpl.chat_export.html",true,true);
00180
00181 $this->chat_room->setRoomId(0);
00182
00183 $tmp_tpl->setVariable("CHAT_NAME",$this->getTitle());
00184 $tmp_tpl->setVariable("CHAT_DATE",strftime("%c",time()));
00185 $tmp_tpl->setVariable("CONTENT",$this->chat_room->getAllMessages());
00186
00187 $file_obj =& new ilFileDataChat($this);
00188
00189
00190 return $file_obj->addFile('index.html',$tmp_tpl->get());
00191 }
00192
00193
00194 function __formatRecipient(&$user)
00195 {
00196 if(is_object($user))
00197 {
00198 return $user->getLogin();
00199 }
00200 return false;
00201 }
00202
00203 function __formatSubject(&$lang)
00204 {
00205 return $lang->txt("chat_invitation_subject");
00206 }
00207
00208 function __formatBody(&$user,&$lang)
00209 {
00210 global $ilClientIniFile;
00211
00212 $room_id = $this->chat_room->getRoomId();
00213
00214 $body = sprintf($this->lng->txt("chat_notification_intro"), $ilClientIniFile->readVariable("client","name"), ILIAS_HTTP_PATH)."\n\n";
00215 $body .= $lang->txt("chat_invitation_body")." ";
00216 $body .= $this->ilias->account->getFullname();
00217 $body .= "\n";
00218 $body .= $lang->txt("chat_chatroom_body")." ".$this->chat_room->getTitle()."\n\n";
00219 $body .= $lang->txt('chat_to_chat_body');
00220 $body .= (': '.ILIAS_HTTP_PATH."/chat/chat.php?room_id=".$room_id."&ref_id=".$this->getRefId());
00221
00222 return $body;
00223 }
00224
00225
00226 function __initChatRecording()
00227 {
00228 if(!is_object($this->chat_recording))
00229 {
00230 include_once 'chat/classes/class.ilChatRecording.php';
00231
00232 $this->chat_recording = new ilChatRecording($this->getId());
00233
00234 return true;
00235 }
00236 return false;
00237 }
00238
00239 function _getPublicChatRefId()
00240 {
00241 static $public_chat_ref_id = 0;
00242
00243 global $tree;
00244
00245 if($public_chat_ref_id)
00246 {
00247 return $public_chat_ref_id;
00248 }
00249 else
00250 {
00251 foreach($tree->getSubTree($tree->getNodeData(SYSTEM_FOLDER_ID)) as $node)
00252 {
00253 if($node['type'] == 'chat')
00254 {
00255 return $public_chat_ref_id = $node['child'];
00256 }
00257 }
00258 }
00259 return false;
00260 }
00261
00262
00263 }
00264 ?>