• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

chat/classes/class.ilObjChat.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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                 // USED ilObjectFactory::getInstance...
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                 // create a local role folder
00087                 $rolf_obj =& $this->createRoleFolder();
00088 
00089                 // create moderator role and assign role to rolefolder...
00090                 $role_obj = $rolf_obj->createRole("il_chat_moderator_".$this->getRefId(),"Moderator of chat obj_no.".$this->getId());
00091 
00092                 // grant permissions: visible,read,write,chat_moderate
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                 // FINALLY DELETE MESSAGES IN PUBLIC ROOM
00122                 $query = "DELETE FROM chat_room_messages ".
00123                         "WHERE chat_id = '".$this->getRefId()."'";
00124 
00125                 $res = $this->ilias->db->query($query);
00126 
00127                 // AND ALL USERS
00128                 $query = "DELETE FROM chat_user ".
00129                         "WHERE chat_id = '".$this->getRefId()."'";
00130 
00131                 $res = $this->ilias->db->query($query);
00132 
00133                 // AND ALL RECORDINGS
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                 // GET USER OBJECT
00161                 $tmp_user = ilObjectFactory::getInstanceByObjId($a_id);
00162 
00163                 // GET USERS LANGUAGE
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                 // return directory name of index.html
00190                 return $file_obj->addFile('index.html',$tmp_tpl->get());
00191         }
00192 
00193         // PRIVATE
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                 $room_id = $this->chat_room->getRoomId();
00211 
00212                 $body = $lang->txt("chat_invitation_body")." ";
00213                 $body .= $this->ilias->account->getFullname();
00214                 $body .= "\n";
00215                 $body .= $lang->txt("chat_chatroom_body")." ".$this->chat_room->getTitle()."\n\n";
00216                 $body .= "<a class=\"navigation\" href=\"./chat/chat.php?room_id=".$room_id."&ref_id=".$this->getRefId()."\" target=\"_blank\">".
00217                         $lang->txt("chat_to_chat_body")."</a>";
00218 
00219                 return $body;
00220         }
00221 
00222         // Protected
00223         function __initChatRecording()
00224         {
00225                 if(!is_object($this->chat_recording))
00226                 {
00227                         include_once 'chat/classes/class.ilChatRecording.php';
00228 
00229                         $this->chat_recording = new ilChatRecording($this->getId());
00230 
00231                         return true;
00232                 }
00233                 return false;
00234         }
00235 
00236         function _getPublicChatRefId()
00237         {
00238                 static $public_chat_ref_id = 0;
00239 
00240                 global $tree;
00241 
00242                 if($public_chat_ref_id)
00243                 {
00244                         return $public_chat_ref_id;
00245                 }
00246                 else
00247                 {
00248                         foreach($tree->getSubTree($tree->getNodeData(SYSTEM_FOLDER_ID)) as $node)
00249                         {
00250                                 if($node['type'] == 'chat')
00251                                 {
00252                                         return $public_chat_ref_id = $node['child'];
00253                                 }
00254                         }
00255                 }
00256                 return false;
00257         }
00258 
00259         function _goto($a_target)
00260         {
00261                 global $ilAccess, $ilErr, $lng;
00262 
00263                 if ($ilAccess->checkAccess("read", "", $a_target))
00264                 {
00265                         ilUtil::redirect("chat.php?ref_id=$a_target");
00266                 }
00267                 else
00268                 {
00269                         $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
00270                 }
00271         }
00272 
00273                         
00274         // SET/GET
00275 } // END class.ilObjTest
00276 ?>

Generated on Fri Dec 13 2013 11:57:53 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1