ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjChat.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 require_once "classes/class.ilObjectGUI.php";
34 require_once "Modules/Chat/classes/class.ilChatServerConfig.php";
35 require_once "Modules/Chat/classes/class.ilChatServerCommunicator.php";
36 require_once "Modules/Chat/classes/class.ilChatUser.php";
37 require_once "Modules/Chat/classes/class.ilChatRoom.php";
38 require_once "Modules/Chat/classes/class.ilFileDataChat.php";
39 
40 class ilObjChat extends ilObject
41 {
46  var $chat_recording = null;
47 
54  function ilObjChat($a_id = 0,$a_call_by_reference = true)
55  {
56  $this->type = "chat";
57  $this->ilObject($a_id,$a_call_by_reference);
58 
59  $this->server_conf =& new ilChatServerConfig();
60  $this->server_comm =& new ilChatServerCommunicator($this);
61  $this->chat_user =& new ilChatUser();
62  $this->chat_room =& new ilChatRoom($this->getId());
63  }
64 
73  public static function _lookupModeratorRole($a_ref_id)
74  {
75  global $ilDB;
76 
77  $mod_title = 'il_chat_moderator_'.$a_ref_id;
78  $query = "SELECT * FROM object_data WHERE title = ".$ilDB->quote($mod_title);
79  $res = $ilDB->query($query);
80  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
81  {
82  return $row->obj_id;
83  }
84  return 0;
85  }
86 
87 
88 
97  public function cloneObject($a_target_id,$a_copy_id = 0)
98  {
99  global $ilDB,$ilUser;
100 
101  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
102  $this->cloneAutoGeneratedRoles($new_obj);
103  }
104 
112  public function cloneAutoGeneratedRoles($new_obj)
113  {
114  global $ilLog,$rbacadmin,$rbacreview;
115 
116  $moderator = ilObjChat::_lookupModeratorRole($this->getRefId());
117  $new_moderator = ilObjChat::_lookupModeratorRole($new_obj->getRefId());
118  $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
119  $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
120 
121  if(!$moderator || !$new_moderator || !$source_rolf || !$target_rolf)
122  {
123  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_chat_moderator');
124  }
125  $rbacadmin->copyRolePermissions($moderator,$source_rolf,$target_rolf,$new_moderator,true);
126  $ilLog->write(__METHOD__.' : Finished copying of role il_chat_moderator.');
127  }
128 
129 
130  function read()
131  {
132  // USED ilObjectFactory::getInstance...
133  parent::read();
134 
135  $this->server_conf =& new ilChatServerConfig();
136  $this->server_comm =& new ilChatServerCommunicator($this);
137  $this->chat_user =& new ilChatUser();
138  $this->chat_room =& new ilChatRoom($this->getId());
139  }
140 
146  function initDefaultRoles()
147  {
148  global $rbacadmin;
149 
150  // create a local role folder
151  $rolf_obj =& $this->createRoleFolder();
152 
153  // create moderator role and assign role to rolefolder...
154  $role_obj = $rolf_obj->createRole("il_chat_moderator_".$this->getRefId(),"Moderator of chat obj_no.".$this->getId());
155 
156  // grant permissions: visible,read,write,chat_moderate
157  $permissions = ilRbacReview::_getOperationIdsByName(array('visible','read','moderate'));
158  $rbacadmin->grantPermission($role_obj->getId(),
159  $permissions,
160  $this->getRefId());
161 
162  unset($rolf_obj);
163 
164  return array($role_obj->getId());
165  }
166 
167  function delete()
168  {
169  global $ilDB;
170 
171  if(!parent::delete())
172  {
173  return false;
174  }
175  $rooms = $this->chat_room->getAllRoomsOfObject();
176  foreach($rooms as $room)
177  {
178  $this->chat_room->delete($room["room_id"]);
179  }
180 
181  // FINALLY DELETE MESSAGES IN PUBLIC ROOM
182  $query = "DELETE FROM chat_room_messages ".
183  "WHERE chat_id = ".$ilDB->quote($this->getRefId())."";
184 
185  $res = $this->ilias->db->query($query);
186 
187  // AND ALL USERS
188  $query = "DELETE FROM chat_user ".
189  "WHERE chat_id = ".$ilDB->quote($this->getRefId())."";
190 
191  $res = $this->ilias->db->query($query);
192 
193  // AND ALL RECORDINGS
194  $query = "SELECT record_id FROM chat_records WHERE
195  chat_id = ".$ilDB->quote($this->getId())."";
196  $res = $this->ilias->db->query($query);
197  if (ilDBx::isDbError($res)) die("ilObjChat::delete(): " . $res->getMessage() . "<br>SQL-Statement: ".$query);
198  if (($num = $res->numRows()) > 0)
199  {
200  for ($i = 0; $i < $num; $i++)
201  {
202  $data = $res->fetchRow(DB_FETCHMODE_ASSOC);
203  $this->ilias->db->query("DELETE FROM chat_record_data WHERE record_id = ".$ilDB->quote($data["record_id"])."");
204  }
205 
206  }
207  $query = "DELETE FROM chat_records WHERE
208  chat_id = ".$ilDB->quote($this->getId())."";
209  $res = $this->ilias->db->query($query);
210 
211  return true;
212  }
213 
214  function sendMessage($a_id)
215  {
216  include_once "Services/Mail/classes/class.ilMail.php";
217 
218  $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
219 
220  // GET USER OBJECT
221  $tmp_user = ilObjectFactory::getInstanceByObjId($a_id);
222 
223  // GET USERS LANGUAGE
224  $tmp_lang =& new ilLanguage($tmp_user->getLanguage());
225  $tmp_lang->loadLanguageModule("chat");
226 
227  $message = $tmp_mail_obj->sendMail($this->__formatRecipient($tmp_user),"","",$this->__formatSubject($tmp_lang),
228  $this->__formatBody($tmp_user,$tmp_lang),array(),array("normal"));
229 
230  unset($tmp_mail_obj);
231  unset($tmp_lang);
232  unset($tmp_user);
233 
234  return true;
235  }
236 
237  function getHTMLDirectory()
238  {
239  $tmp_tpl =& new ilTemplate("tpl.chat_export.html",true,true);
240 
241  $this->chat_room->setRoomId(0);
242 
243  $tmp_tpl->setVariable("CHAT_NAME",$this->getTitle());
244  $tmp_tpl->setVariable("CHAT_DATE",strftime("%c",time()));
245  $tmp_tpl->setVariable("CONTENT",$this->chat_room->getAllMessages());
246 
247  $file_obj =& new ilFileDataChat($this);
248 
249  // return directory name of index.html
250  return $file_obj->addFile('index.html',$tmp_tpl->get());
251  }
252 
253  // PRIVATE
255  {
256  if(is_object($user))
257  {
258  return $user->getLogin();
259  }
260  return false;
261  }
262 
264  {
265  return $lang->txt("chat_invitation_subject");
266  }
267 
269  {
270  global $ilClientIniFile;
271 
272  $room_id = $this->chat_room->getRoomId();
273  $room_title = $this->chat_room->getTitle();
274 
275  $body = sprintf($this->lng->txt("chat_notification_intro"), $ilClientIniFile->readVariable("client","name"), ILIAS_HTTP_PATH)."\n\n";
276  $body .= $lang->txt("chat_invitation_body")." ";
277  $body .= $this->ilias->account->getFullname();
278  $body .= "\n";
279  $body .= $lang->txt("chat_chatroom_body").' '.$this->getTitle();
280  if ($room_title != '')
281  {
282  $body .= ', '.$room_title;
283  }
284  $body .= "\n\n";
285  $body .= $lang->txt('chat_to_chat_body');
286  $body .= ': '.ILIAS_HTTP_PATH."/ilias.php?baseClass=ilChatPresentationGUI&room_id=".$room_id."&ref_id=".$this->getRefId();
287 
288  return $body;
289  }
290 
291  // Protected
293  {
294  if(!is_object($this->chat_recording))
295  {
296  include_once 'Modules/Chat/classes/class.ilChatRecording.php';
297 
298  $this->chat_recording = new ilChatRecording($this->getId());
299 
300  return true;
301  }
302  return false;
303  }
304 
306  {
307  static $public_chat_ref_id = 0;
308 
309  global $tree;
310 
311  if($public_chat_ref_id)
312  {
313  return $public_chat_ref_id;
314  }
315  else
316  {
317  foreach($tree->getSubTree($tree->getNodeData(SYSTEM_FOLDER_ID)) as $node)
318  {
319  if($node['type'] == 'chat')
320  {
321  return $public_chat_ref_id = $node['child'];
322  }
323  }
324  }
325  return false;
326  }
327 
328  // SET/GET
329 } // END class.ilObjTest
330 ?>