57 define(MAX_LINES,1000);
62 $this->obj_id = $a_id;
63 $this->owner_id = $ilUser->getId();
75 $this->room_id = $a_id;
91 $this->owner_id = $a_id;
105 $res = $ilDB->queryf(
'
106 SELECT owner FROM chat_rooms WHERE room_id = %s',
131 $this->title = $a_title;
141 return $this->guests ? $this->guests : array();
146 $this->user_id = $a_id;
158 $res = $ilDB->queryf(
'
159 SELECT * FROM chat_invitations
163 array(
'integer',
'integer',
'integer'),
167 if(
$res->numRows() > 0)
169 $res = $ilDB->manipulateF(
'
170 UPDATE chat_invitations
171 SET invitation_time = %s,
176 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
181 $res = $ilDB->manipulateF(
182 'INSERT INTO chat_invitations
188 VALUES (%s, %s, %s, %s)',
189 array(
'integer',
'integer',
'integer',
'integer'),
199 $res = $ilDB->manipulateF(
'
200 DELETE FROM chat_invitations
204 array(
'integer',
'integer',
'integer'),
213 $res = $ilDB->manipulateF(
'
214 UPDATE chat_invitations
215 SET guest_informed = %s
219 array(
'integer',
'integer',
'integer',
'integer'),
233 !$rbacsystem->checkAccess(
'moderate',
$_GET[
'ref_id']))
251 !$rbacsystem->checkAccess(
'moderate',
$ref_id))
263 $res = $ilDB->queryf(
'
264 SELECT * FROM chat_invitations ci, chat_rooms ca
265 WHERE ci.room_id = ca.room_id
269 AND ci.guest_id = %s',
270 array(
'integer',
'integer',
'integer',
'integer'),
273 return $res->numRows() ?
true :
false;
281 $res = $ilDB->queryf(
'
282 SELECT * FROM chat_invitations ci, chat_rooms ca
283 WHERE ci.room_id = ca.room_id
287 AND ci.guest_id = %s',
288 array(
'integer',
'integer',
'integer',
'integer'),
291 return $res->numRows() ?
true :
false;
306 $id = $this->
addLine($message);
313 $res = $ilDB->queryf(
'
314 SELECT message FROM chat_room_messages
317 AND commit_timestamp > %s
318 ORDER BY commit_timestamp',
319 array(
'integer',
'integer',
'integer'),
327 return is_array(
$data) ? implode(
"<br />",
$data) :
"";
330 public function getNewMessages($last_known_id, &$new_last_known_id = -1, $max_age = 0)
333 $res = $ilDB->queryf(
'
334 SELECT message, entry_id FROM chat_room_messages
338 AND commit_timestamp > %s
339 ORDER BY commit_timestamp',
340 array(
'integer',
'integer',
'integer',
'integer'),
347 $max_id = max($max_id,
$row->entry_id);
350 if ($new_last_known_id !== -1) {
351 $new_last_known_id = $max_id;
360 $res = $ilDB->manipulateF(
'
361 DELETE FROM chat_room_messages
364 array(
'integer',
'integer'),
375 $res = $ilDB->manipulateF(
'
376 DELETE FROM chat_user WHERE usr_id = %s',
380 $res = $ilDB->manipulateF(
'
381 INSERT INTO chat_user
388 VALUES(%s, %s, %s, %s, %s)',
389 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
398 $res = $ilDB->manipulateF(
'
404 array(
'integer',
'integer',
'integer',
'integer'),
405 array(
'1', $a_usr_id, $this->
getObjId(),
'0'));
414 $res = $ilDB->manipulateF(
'
415 UPDATE chat_user SET kicked = %s
419 array(
'integer',
'integer',
'integer',
'integer'),
420 array(
'0', $a_usr_id, $this->
getObjId(),
'0'));
429 $res = $ilDB->queryf(
'
430 SELECT * FROM chat_user
434 array(
'integer',
'integer',
'integer'),
435 array(
'1', $a_usr_id, $this->
getObjId()));
438 return $res->numRows() ?
true :
false;
445 $res = $ilDB->queryf(
'
446 SELECT * FROM chat_user
450 array(
'integer',
'integer',
'integer'),
451 array(
'1', $a_usr_id, $chat_id));
454 return $res->numRows() ?
true :
false;
461 $res = $ilDB->queryf(
'
462 SELECT * FROM chat_user
465 AND last_conn_timestamp > %s',
466 array(
'integer',
'integer',
'integer'),
467 array($chat_id,
$room_id, time() - 40));
470 return $res->numRows();
477 $res = $ilDB->queryf(
'
478 SELECT * FROM chat_user
481 AND last_conn_timestamp > %s',
482 array(
'integer',
'integer',
'integer'),
483 array($chat_id,
$room_id, time() - 40));
486 return $res->numRows();
494 $res = $ilDB->queryf(
'
495 SELECT * FROM chat_user
498 AND last_conn_timestamp > %s',
499 array(
'integer',
'integer',
'integer'),
500 array($this->
getObjId(), $this->room_id, time() - 40));
504 $usr_ids[] =
$row->usr_id;
506 return $usr_ids ? $usr_ids : array();
513 $res = $ilDB->queryf(
'
514 SELECT * FROM chat_user
517 AND last_conn_timestamp > %s',
518 array(
'integer',
'integer',
'integer'),
519 array(
'0',
$usr_id, time() - 40));
523 return $row->chat_id;
536 $this->error_msg =
"";
540 $this->error_msg .= $this->lng->txt(
"chat_title_missing");
544 $this->ilias->raiseError(
"MISSING OWNER ID",$this->ilias->error_obj->FATAL);
546 return $this->error_msg ?
false :
true;
551 if(!is_array($a_ids))
553 $this->ilias->raiseError(
"ARRAY REQUIRED",$this->ilias->error_obj->FATAL);
555 foreach($a_ids as $id)
562 public function delete($a_id, $a_owner = 0)
567 $data_values = array();
568 $data_types = array();
570 $query =
'DELETE FROM chat_rooms WHERE room_id = %s';
571 array_push($data_types,
'integer');
572 array_push($data_values, $a_id);
576 $query .=
' AND owner = %s';
577 array_push($data_types,
'integer');
578 array_push($data_values,$a_owner);
580 $res = $ilDB->manipulateF(
$query, $data_types, $data_values);
583 $res = $ilDB->manipulateF(
'
584 DELETE FROM chat_invitations WHERE room_id = %s',
585 array(
'integer'), array($a_id));
588 $res = $ilDB->manipulateF(
'
589 DELETE FROM chat_room_messages WHERE room_id = %s',
590 array(
'integer'),array($a_id));
593 $data_types = array();
594 $data_values = array();
596 $query =
'DELETE FROM chat_user WHERE room_id = %s';
597 array_push($data_types,
'integer');
598 array_push($data_values,$a_id);
602 $query .=
' AND owner = %s';
603 array_push($data_types,
'integer');
604 array_push($data_values,$a_owner);
606 $res = $ilDB->manipulateF(
$query, $data_types, $data_values);
609 $res = $ilDB->queryf(
'
610 SELECT record_id FROM chat_records WHERE room_id = %s',
611 array(
'integer'), array($a_id));
616 if (($num =
$res->numRows()) > 0)
618 for ($i = 0; $i < $num; $i++)
621 $statement_2 = $ilDB->manipulateF(
'
622 DELETE FROM chat_record_data WHERE record_id = %s',
623 array(
'integer'), array(
$row[
'record_id']));
628 $statement = $ilDB->manipulateF(
'
629 DELETE FROM chat_records WHERE room_id = %s',
630 array(
'integer'), array($a_id));
639 $res = $ilDB->manipulateF(
'
643 array(
'text',
'integer'),
653 $res = $ilDB->queryf(
'
654 SELECT * FROM chat_rooms
658 array(
'text',
'integer',
'integer'),
663 return $row->room_id;
672 $next_id = $ilDB->nextId(
'chat_rooms');
673 $res = $ilDB->manipulateF(
'
674 INSERT INTO chat_rooms
679 VALUES(%s, %s, %s, %s)',
680 array(
'integer',
'text',
'integer',
'integer'),
701 global $tree,
$ilDB, $rbacsystem;
703 $data_types = array();
704 $data_values = array();
705 $query =
'SELECT DISTINCT(cr.room_id) room_id, owner, title, cr.chat_id chat_id
706 FROM chat_rooms cr LEFT JOIN chat_invitations ON cr.room_id = chat_invitations.room_id
707 WHERE (owner = %s) OR (guest_id = %s)';
709 array_push($data_types,
'integer',
'integer');
712 if($rbacsystem->checkAccess(
'moderate',
$_GET[
'ref_id']))
718 $res = $ilDB->queryf(
$query, $data_types, $data_values);
739 $res = $ilDB->queryf(
'
740 SELECT * FROM chat_rooms
743 array(
'integer',
'integer'),
763 $res = $ilDB->queryf(
'
764 SELECT * FROM chat_rooms
780 global $ilObjDataCache,$ilUser,$rbacsystem;
783 $unique_chats = array();
786 if($rbacsystem->checkAccess(
'read',$pub_chat_id))
788 $obj_id = $ilObjDataCache->lookupObjId($pub_chat_id);
789 if(!in_array($obj_id,$obj_ids))
791 $unique_data[
'child'] = $pub_chat_id;
792 $unique_data[
'title'] = $ilObjDataCache->lookupTitle($obj_id);
793 $unique_data[
'obj_id'] = $obj_id;
794 $unique_data[
'ref_id'] = $pub_chat_id;
796 $unique_chats[] = $unique_data;
797 $obj_ids[] = $obj_id;
803 $obj_id = $ilObjDataCache->lookupObjId($chat_id);
804 if(!in_array($obj_id,$obj_ids))
806 $unique_data[
'child'] = $chat_id;
807 $unique_data[
'title'] = $ilObjDataCache->lookupTitle($obj_id);
808 $unique_data[
'obj_id'] = $obj_id;
809 $unique_data[
'ref_id'] = $chat_id;
811 $unique_chats[] = $unique_data;
812 $obj_ids[] = $obj_id;
815 return $unique_chats ? $unique_chats : array();
822 if($rbacsystem->checkAccess(
'moderate',
$_GET[
'ref_id']))
850 if($rbacsystem->checkAccess(
'moderate',
$ref_id))
878 $res =$ilDB->queryf(
'
879 SELECT COUNT(entry_id) number_lines FROM chat_room_messages
882 array(
'integer',
'integer'),
887 return $row->number_lines;
904 $res = $ilDB->queryf(
'
905 SELECT entry_id, MIN(commit_timestamp) last_comm FROM chat_room_messages
909 array(
'integer',
'integer'),
914 $entry_id =
$row->entry_id;
918 $res = $ilDB->manipulateF(
'
919 DELETE FROM chat_room_messages WHERE entry_id = %s',
920 array(
'integer'), array($entry_id));
928 $next_id = $ilDB->nextId(
'chat_room_messages');
929 $res = $ilDB->manipulateF(
'
930 INSERT INTO chat_room_messages
936 VALUES(%s, %s, %s, %s, %s)',
937 array(
'integer',
'integer',
'integer',
'text',
'integer'),
940 $id = $ilDB->getLastInsertId();
943 $this->chat_record->setRoomId($this->
getRoomId());
944 if ($this->chat_record->isRecording())
946 $next_id = $ilDB->nextId(
'chat_record_data');
947 $res = $ilDB->manipulateF(
'
948 INSERT INTO chat_record_data
953 VALUES(%s, %s, %s, %s)',
954 array(
'integer',
'integer',
'text',
'integer'),
955 array($next_id, $this->chat_record->getRecordId(), $message, time()));
966 $this->guests = array();
968 $res = $ilDB->queryf(
'
969 SELECT * FROM chat_rooms WHERE room_id = %s',
979 $res = $ilDB->queryf(
'
980 SELECT * FROM chat_invitations
983 array(
'integer',
'integer'),
988 $this->guests[] =
$row->guest_id;
997 $statement = $ilDB->manipulateF(
'
998 UPDATE chat_user SET kicked = %s
1000 array(
'integer',
'integer'),
1001 array(
'0', $a_usr_id));