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
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->getRefId());
00063 }
00064
00065 function read()
00066 {
00067
00068 parent::read();
00069
00070 $this->server_conf =& new ilChatServerConfig();
00071 $this->server_comm =& new ilChatServerCommunicator($this);
00072 $this->chat_user =& new ilChatUser();
00073 $this->chat_room =& new ilChatRoom($this->getRefId());
00074 }
00075
00081 function initDefaultRoles()
00082 {
00083 global $rbacadmin;
00084
00085
00086 $rolf_obj =& $this->createRoleFolder();
00087
00088
00089 $role_obj = $rolf_obj->createRole("il_chat_moderator_".$this->getRefId(),"Moderator of chat obj_no.".$this->getId());
00090
00091
00092 $permissions = ilRbacReview::_getOperationIdsByName(array('visible','read','moderate'));
00093 $rbacadmin->grantPermission($role_obj->getId(),
00094 $permissions,
00095 $this->getRefId());
00096
00097 unset($rolf_obj);
00098
00099 return array($role_obj->getId());
00100 }
00101
00102 function ilClone($a_parent_ref)
00103 {
00104 $tmp_obj =& ilObjectFactory::getInstanceByRefId(parent::ilClone($a_parent_ref));
00105 }
00106
00107
00108 function delete()
00109 {
00110 if(!parent::delete())
00111 {
00112 return false;
00113 }
00114 $rooms = $this->chat_room->getAllRoomsOfObject();
00115 foreach($rooms as $room)
00116 {
00117 $this->chat_room->delete($room["room_id"]);
00118 }
00119
00120
00121 $query = "DELETE FROM chat_room_messages ".
00122 "WHERE chat_id = '".$this->getRefId()."'";
00123
00124 $res = $this->ilias->db->query($query);
00125
00126
00127 $query = "DELETE FROM chat_user ".
00128 "WHERE chat_id = '".$this->getRefId()."'";
00129
00130 $res = $this->ilias->db->query($query);
00131
00132
00133 $query = "SELECT record_id FROM chat_records WHERE
00134 chat_id = '".$this->getRefId()."'";
00135 $res = $this->ilias->db->query($query);
00136 if (DB::isError($res)) die("ilObjChat::delete(): " . $res->getMessage() . "<br>SQL-Statement: ".$q);
00137 if (($num = $res->numRows()) > 0)
00138 {
00139 for ($i = 0; $i < $num; $i++)
00140 {
00141 $data = $res->fetchRow(DB_FETCHMODE_ASSOC);
00142 $this->ilias->db->query("DELETE FROM chat_record_data WHERE record_id = '" . $data["record_id"] . "'");
00143 }
00144
00145 }
00146 $query = "DELETE FROM chat_records WHERE
00147 chat_id = '".$this->getRefId()."'";
00148 $res = $this->ilias->db->query($query);
00149
00150 return true;
00151 }
00152
00153 function sendMessage($a_id)
00154 {
00155 include_once "./classes/class.ilMail.php";
00156
00157 $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
00158
00159
00160 $tmp_user = ilObjectFactory::getInstanceByObjId($a_id);
00161
00162
00163 $tmp_lang =& new ilLanguage($tmp_user->getLanguage());
00164 $tmp_lang->loadLanguageModule("chat");
00165
00166 $message = $tmp_mail_obj->sendMail($this->__formatRecipient($tmp_user),"","",$this->__formatSubject($tmp_lang),
00167 $this->__formatBody($tmp_user,$tmp_lang),array(),array("normal"));
00168
00169 unset($tmp_mail_obj);
00170 unset($tmp_lang);
00171 unset($tmp_user);
00172
00173 return true;
00174 }
00175
00176 function getHTMLDirectory()
00177 {
00178 $tmp_tpl =& new ilTemplate("tpl.chat_export.html",true,true);
00179
00180 $this->chat_room->setRoomId(0);
00181
00182 $tmp_tpl->setVariable("CHAT_NAME",$this->getTitle());
00183 $tmp_tpl->setVariable("CHAT_DATE",strftime("%c",time()));
00184 $tmp_tpl->setVariable("CONTENT",$this->chat_room->getAllMessages());
00185
00186 $file_obj =& new ilFileDataChat($this);
00187
00188
00189 return $file_obj->addFile('index.html',$tmp_tpl->get());
00190 }
00191
00192
00193 function __formatRecipient(&$user)
00194 {
00195 if(is_object($user))
00196 {
00197 return $user->getLogin();
00198 }
00199 return false;
00200 }
00201
00202 function __formatSubject(&$lang)
00203 {
00204 return $lang->txt("chat_invitation_subject");
00205 }
00206
00207 function __formatBody(&$user,&$lang)
00208 {
00209 $room_id = $this->chat_room->getRoomId();
00210
00211 $body = $lang->txt("chat_invitation_body")." ";
00212 $body .= $this->ilias->account->getFullname();
00213 $body .= "\n";
00214 $body .= $lang->txt("chat_chatroom_body")." ".$this->chat_room->getTitle()."\n\n";
00215 $body .= "<a class=\"navigation\" href=\"./chat/chat.php?room_id=".$room_id."&ref_id=".$this->getRefId()."\" target=\"_blank\">".
00216 $lang->txt("chat_to_chat_body")."</a>";
00217
00218 return $body;
00219 }
00220
00221 }
00222 ?>