57 define(MAX_LINES,1000);
62 $this->obj_id = $a_id;
63 $this->owner_id = $ilUser->getId();
75 $this->room_id = $a_id;
90 $this->owner_id = $a_id;
110 $this->title = $a_title;
118 return $this->guests ? $this->guests : array();
122 $this->user_id = $a_id;
133 $statement = $ilDB->prepare(
'
134 SELECT * FROM chat_invitations
138 array(
'integer',
'integer',
'integer')
142 $res = $ilDB->execute($statement,
$data);
144 if(
$res->numRows() > 0)
146 $statement = $ilDB->prepareManip(
'
147 UPDATE chat_invitations
148 SET invitation_time = ?,
153 array(
'integer',
'integer',
'integer',
'integer',
'integer')
157 $res = $ilDB->execute($statement,
$data);
161 $statement = $ilDB->prepareManip(
162 'INSERT INTO chat_invitations (chat_id, room_id, guest_id, invitation_time) '.
163 'VALUES(?, ?, ?, ?)',
164 array(
'integer',
'integer',
'integer',
'integer')
168 $res = $ilDB->execute($statement,
$data);
175 $query =
"DELETE FROM chat_invitations ".
176 "WHERE chat_id = ".$ilDB->quote( $this->
getObjId() ).
" ".
177 "AND room_id = ".$ilDB->quote( $this->
getRoomId() ).
" ".
178 "AND guest_id = ".$ilDB->quote( $a_id ).
"";
180 $res = $this->ilias->db->query($query);
187 $query =
"UPDATE chat_invitations SET guest_informed = 1 ".
188 "WHERE chat_id = ".$ilDB->quote( $this->
getObjId() ).
" ".
189 "AND room_id = ".$ilDB->quote( $this->
getRoomId() ).
" ".
190 "AND guest_id = ".$ilDB->quote( $a_id ).
"";
192 $res = $this->ilias->db->query($query);
204 !$rbacsystem->checkAccess(
'moderate',
$_GET[
'ref_id']))
219 $query =
"SELECT * FROM chat_invitations AS ci JOIN chat_rooms AS ca ".
220 "WHERE ci.room_id = ca.room_id ".
221 "AND ci.chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
222 "AND ci.room_id = ".$ilDB->quote($this->
getRoomId()).
" ".
223 "AND owner = ".$ilDB->quote($this->
getOwnerId()).
" ".
224 "AND ci.guest_id = ".$ilDB->quote($a_id).
"";
226 $res = $this->ilias->db->query($query);
228 return $res->numRows() ?
true :
false;
250 $query =
"SELECT message FROM chat_room_messages ".
251 "WHERE chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
252 "AND room_id = ".$ilDB->quote($this->
getRoomId()).
" ".
253 "ORDER BY commit_timestamp ";
255 $res = $this->ilias->db->query($query);
258 $data[] = $row->message;
260 return is_array(
$data) ? implode(
"<br />",
$data) :
"";
266 $query =
"DELETE FROM chat_room_messages ".
267 "WHERE chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
268 "AND room_id = ".$ilDB->quote($this->
getRoomId()).
"";
270 $res = $this->ilias->db->query($query);
280 $query =
"DELETE FROM chat_user ".
281 "WHERE usr_id = ".$ilDB->quote($this->
getUserId()).
"";
282 $res = $this->ilias->db->query($query);
284 $query =
"INSERT INTO chat_user ".
285 "SET usr_id = ".$ilDB->quote($this->
getUserId()).
", ".
286 "room_id = ".$ilDB->quote($this->
getRoomId()).
", ".
287 "chat_id = ".$ilDB->quote($this->
getObjId()).
", ".
288 "last_conn_timestamp = '".time().
"'";
289 $res = $this->ilias->db->query($query);
297 $query =
"UPDATE chat_user SET kicked = '1' ".
298 "WHERE usr_id = ".$ilDB->quote($a_usr_id).
" ".
299 "AND chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
302 $this->ilias->db->query($query);
311 $query =
"UPDATE chat_user SET kicked = '0' ".
312 "WHERE usr_id = ".$ilDB->quote($a_usr_id).
" ".
313 "AND chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
316 $this->ilias->db->query($query);
325 $query =
"SELECT * FROM chat_user ".
327 "AND usr_id = ".$ilDB->quote($a_usr_id).
" ".
328 "AND chat_id = ".$ilDB->quote($this->
getObjId()).
"";
330 $res = $this->ilias->db->query($query);
332 return $res->numRows() ?
true :
false;
339 $query =
"SELECT * FROM chat_user ".
340 "WHERE chat_id = ".$ilDB->quote($chat_id).
" ".
341 "AND room_id = ".$ilDB->quote(
$room_id).
" ".
342 "AND last_conn_timestamp > ".time().
" - 40";
343 $res = $this->ilias->db->query($query);
345 return $res->numRows();
352 $query =
"SELECT * FROM chat_user ".
353 "WHERE chat_id = ".$ilDB->quote($chat_id).
" ".
354 "AND room_id = ".$ilDB->quote(
$room_id).
" ".
355 "AND last_conn_timestamp > ".time().
" - 40";
356 $res = $ilDB->query($query);
358 return $res->numRows();
366 $query =
"SELECT * FROM chat_user ".
367 "WHERE chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
368 "AND room_id = ".$ilDB->quote($this->room_id).
" ".
369 "AND last_conn_timestamp > ".time().
" - 40";
370 $res = $this->ilias->db->query($query);
373 $usr_ids[] = $row->usr_id;
375 return $usr_ids ? $usr_ids : array();
383 $query =
"SELECT * FROM chat_user ".
384 "WHERE room_id = 0 ".
385 "AND usr_id = ".$ilDB->quote((
int) $usr_id).
" ".
386 "AND last_conn_timestamp > ".time().
" - 40";
388 $res = $ilDB->query($query);
391 return $row->chat_id;
404 $this->error_msg =
"";
408 $this->error_msg .= $this->lng->txt(
"chat_title_missing");
412 $this->ilias->raiseError(
"MISSING OWNER ID",$this->ilias->error_obj->FATAL);
414 return $this->error_msg ?
false :
true;
418 if(!is_array($a_ids))
420 $this->ilias->raiseError(
"ARRAY REQUIRED",$this->ilias->error_obj->FATAL);
422 foreach($a_ids as $id)
429 function delete($a_id, $a_owner = 0)
434 $query =
"DELETE FROM chat_rooms WHERE ".
435 "room_id = ".$ilDB->quote($a_id).
"";
438 " AND owner = ".$ilDB->quote($a_owner).
"";
440 $res = $this->ilias->db->query($query);
443 $query =
"DELETE FROM chat_invitations WHERE ".
444 "room_id = ".$ilDB->quote($a_id).
"";
445 $res = $this->ilias->db->query($query);
448 $query =
"DELETE FROM chat_room_messages WHERE ".
449 "room_id = ".$ilDB->quote($a_id).
"";
450 $res = $this->ilias->db->query($query);
453 $query =
"DELETE FROM chat_user WHERE ".
454 "room_id = ".$ilDB->quote($a_id).
"";
457 " AND owner = ".$ilDB->quote($a_owner).
"";
459 $res = $this->ilias->db->query($query);
462 $query =
"SELECT record_id FROM chat_records WHERE
463 room_id = ".$ilDB->quote($a_id).
"";
464 $res = $this->ilias->db->query($query);
466 if (($num =
$res->numRows()) > 0)
468 for ($i = 0; $i < $num; $i++)
471 $this->ilias->db->query(
"DELETE FROM chat_record_data WHERE record_id = ".$ilDB->quote(
$data[
"record_id"]).
"");
475 $query =
"DELETE FROM chat_records WHERE
476 room_id = ".$ilDB->quote($a_id).
"";
477 $res = $this->ilias->db->query($query);
486 $query =
"UPDATE chat_rooms ".
487 "SET title = ".$ilDB->quote($this->
getTitle()).
" ".
488 "WHERE room_id = ".$ilDB->quote($this->
getRoomId()).
"";
490 $res = $this->ilias->db->query($query);
499 $query =
"SELECT * FROM chat_rooms ".
500 "WHERE title = ".$ilDB->quote($this->
getTitle()).
" ".
501 "AND chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
502 "AND owner = ".$ilDB->quote($this->
getOwnerId()).
"";
504 $res = $this->ilias->db->query($query);
507 return $row->room_id;
516 $query =
"INSERT INTO chat_rooms ".
517 "SET title = ".$ilDB->quote($this->
getTitle()).
", ".
518 "chat_id = ".$ilDB->quote($this->
getObjId()).
", ".
519 "owner = ".$ilDB->quote($this->
getOwnerId()).
"";
521 $res = $this->ilias->db->query($query);
524 return ($id = $this->ilias->db->getLastInsertId()) ? $id :
false;
541 global $tree, $ilDB, $rbacsystem;
543 $query =
"SELECT DISTINCT(cr.room_id) as room_id,owner,title,cr.chat_id as chat_id FROM chat_rooms AS cr NATURAL LEFT JOIN chat_invitations ".
544 "WHERE (owner = ".$ilDB->quote($this->
getUserId()).
") ".
545 "OR (guest_id = ".$ilDB->quote($this->
getUserId()).
")";
547 if($rbacsystem->checkAccess(
'moderate',
$_GET[
'ref_id']))
549 $query .=
" OR (1) ";
552 $res = $this->ilias->db->query($query);
555 $data[$row->room_id][
"room_id"] = $row->room_id;
556 $data[$row->room_id][
"chat_id"] = $row->chat_id;
557 $data[$row->room_id][
"owner"] = $row->owner;
558 $data[$row->room_id][
"title"] = $row->title;
567 $query =
"SELECT * FROM chat_rooms ".
568 "WHERE chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
569 "AND owner = ".$ilDB->quote($this->
getUserId()).
"";
571 $res = $this->ilias->db->query($query);
574 $data[$row->room_id][
"room_id"] = $row->room_id;
575 $data[$row->room_id][
"owner"] = $row->owner;
576 $data[$row->room_id][
"title"] = $row->title;
577 $data[$row->room_id][
"owner"] = $row->owner;
586 $query =
"SELECT * FROM chat_rooms ".
587 "WHERE chat_id = ".$ilDB->quote($this->
getObjId()).
"";
589 $res = $this->ilias->db->query($query);
592 $data[$row->room_id][
"room_id"] = $row->room_id;
593 $data[$row->room_id][
"owner"] = $row->owner;
594 $data[$row->room_id][
"title"] = $row->title;
595 $data[$row->room_id][
"owner"] = $row->owner;
602 global $ilObjDataCache,$ilUser,$rbacsystem;
605 $unique_chats = array();
608 if($rbacsystem->checkAccess(
'read',$pub_chat_id))
610 $obj_id = $ilObjDataCache->lookupObjId($pub_chat_id);
611 if(!in_array($obj_id,$obj_ids))
613 $unique_data[
'child'] = $pub_chat_id;
614 $unique_data[
'title'] = $ilObjDataCache->lookupTitle($obj_id);
615 $unique_data[
'obj_id'] = $obj_id;
616 $unique_data[
'ref_id'] = $pub_chat_id;
618 $unique_chats[] = $unique_data;
619 $obj_ids[] = $obj_id;
625 $obj_id = $ilObjDataCache->lookupObjId($chat_id);
626 if(!in_array($obj_id,$obj_ids))
628 $unique_data[
'child'] = $chat_id;
629 $unique_data[
'title'] = $ilObjDataCache->lookupTitle($obj_id);
630 $unique_data[
'obj_id'] = $obj_id;
631 $unique_data[
'ref_id'] = $chat_id;
633 $unique_chats[] = $unique_data;
634 $obj_ids[] = $obj_id;
637 return $unique_chats ? $unique_chats : array();
644 if($rbacsystem->checkAccess(
'moderate',
$_GET[
'ref_id']))
673 $query =
"SELECT COUNT(entry_id) as number_lines FROM chat_room_messages ".
674 "WHERE chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
675 "AND room_id = ".$ilDB->quote($this->
getRoomId()).
"";
677 $res = $this->ilias->db->query($query);
680 return $row->number_lines;
689 $query =
"SELECT entry_id, MIN(commit_timestamp) as last_comm FROM chat_room_messages ".
690 "WHERE chat_id = ".$ilDB->quote($this->
getObjId()).
" ".
691 "AND room_id = ".$ilDB->quote($this->
getRoomId()).
" ".
694 $res = $this->ilias->db->query($query);
697 $entry_id = $row->entry_id;
701 $query =
"DELETE FROM chat_room_messages ".
702 "WHERE entry_id = ".$ilDB->quote($entry_id).
"";
704 $res = $this->ilias->db->query($query);
713 $query =
"INSERT INTO chat_room_messages ".
714 "VALUES('0',".$ilDB->quote($this->
getObjId()).
",".$ilDB->quote($this->
getRoomId()).
",".$ilDB->quote($message).
",NOW())";
716 $res = $this->ilias->db->query($query);
719 $this->chat_record->setRoomId($this->
getRoomId());
720 if ($this->chat_record->isRecording())
722 $query =
"INSERT INTO chat_record_data VALUES (
724 ".$ilDB->quote($this->chat_record->getRecordId()).
",
725 ".$ilDB->quote($message).
",
728 $res = $this->ilias->db->query($query);
739 $this->guests = array();
741 $query =
"SELECT * FROM chat_rooms ".
742 "WHERE room_id = ".$ilDB->quote($this->
getRoomId()).
"";
744 $res = $this->ilias->db->query($query);
751 $query =
"SELECT * FROM chat_invitations ".
752 "WHERE chat_id = ".$ilDB->quote($this->
getObjId()).
" ";
753 "AND room_id = ".$ilDB->quote($this->
getRoomId()).
"";
755 $res = $this->ilias->db->query($query);
758 $this->guests[] = $row->guest_id;
767 $ilDB->query(
"UPDATE chat_user SET kicked = 0 WHERE usr_id = ".$ilDB->quote($a_usr_id).
"");