18 public static function install()
25 if(!$ilDB->tableExists(
'chatroom_settings'))
28 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
29 'object_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
false,
'default' => 0),
30 'room_type' => array(
'type' =>
'text',
'length' => 20,
'notnull' =>
true),
31 'allow_anonymous' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
32 'allow_custom_usernames' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
33 'enable_history' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
34 'restrict_history' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
35 'autogen_usernames' => array(
'type' =>
'text',
'length' => 50,
'notnull' =>
false,
'default' =>
'Anonymous #'),
36 'allow_private_rooms' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
39 $ilDB->createTable(
'chatroom_settings', $fields);
40 $ilDB->addPrimaryKey(
'chatroom_settings', array(
'room_id'));
41 $ilDB->createSequence(
'chatroom_settings');
44 if(!$ilDB->tableExists(
'chatroom_users'))
47 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
48 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
49 'userdata' => array(
'type' =>
'text',
'length' => 4000,
'notnull' =>
true),
50 'connected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
52 $ilDB->createTable(
'chatroom_users', $fields);
53 $ilDB->addPrimaryKey(
'chatroom_users', array(
'room_id',
'user_id'));
56 if(!$ilDB->tableExists(
'chatroom_sessions'))
59 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
60 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
61 'userdata' => array(
'type' =>
'text',
'length' => 4000,
'notnull' =>
true),
62 'connected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
63 'disconnected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
65 $ilDB->createTable(
'chatroom_sessions', $fields);
68 if(!$ilDB->tableExists(
'chatroom_history'))
71 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
72 'message' => array(
'type' =>
'text',
'length' => 4000,
'notnull' =>
true),
73 'timestamp' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
75 $ilDB->createTable(
'chatroom_history', $fields);
78 if(!$ilDB->tableExists(
'chatroom_bans'))
81 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
82 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
83 'timestamp' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
84 'remark' => array(
'type' =>
'text',
'length' => 1000,
'notnull' =>
false),
86 $ilDB->createTable(
'chatroom_bans', $fields);
89 if(!$ilDB->tableExists(
'chatroom_admconfig'))
92 'instance_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
93 'server_settings' => array(
'type' =>
'text',
'length' => 2000,
'notnull' =>
true),
94 'default_config' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
true,
'default' => 0),
96 $ilDB->createTable(
'chatroom_admconfig', $fields);
97 $ilDB->addPrimaryKey(
'chatroom_admconfig', array(
'instance_id'));
98 $ilDB->createSequence(
'chatroom_admconfig');
101 if(!$ilDB->tableExists(
'chatroom_prooms'))
104 'proom_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
105 'parent_id' => array(
'type' =>
'text',
'length' => 2000,
'notnull' =>
true),
106 'title' => array(
'type' =>
'text',
'length' => 200,
'notnull' =>
true,
'default' => 0),
107 'owner' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true,
'default' => 0),
108 'created' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true,
'default' => 0),
109 'closed' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
false,
'default' => 0),
111 $ilDB->createTable(
'chatroom_prooms', $fields);
112 $ilDB->addPrimaryKey(
'chatroom_prooms', array(
'proom_id'));
113 $ilDB->createSequence(
'chatroom_prooms');
116 if(!$ilDB->tableExists(
'chatroom_psessions'))
119 'proom_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
120 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
121 'connected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
122 'disconnected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
124 $ilDB->createTable(
'chatroom_psessions', $fields);
127 if(!$ilDB->tableExists(
'chatroom_uploads'))
130 'upload_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
131 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
132 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
133 'filename' => array(
'type' =>
'text',
'length' => 200,
'notnull' =>
true),
134 'filetype' => array(
'type' =>
'text',
'length' => 200,
'notnull' =>
true),
135 'timestamp' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true)
137 $ilDB->createTable(
'chatroom_uploads', $fields);
138 $ilDB->addPrimaryKey(
'chatroom_uploads', array(
'upload_id'));
139 $ilDB->createSequence(
'chatroom_uploads');
142 if(!$ilDB->tableColumnExists(
'chatroom_prooms',
'is_public'))
144 $ilDB->addTableColumn(
'chatroom_prooms',
'is_public', array(
'type' =>
'integer',
'default' => 1,
'length' => 1));
147 if(!$ilDB->tableExists(
'chatroom_psessions'))
150 'proom_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
151 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
152 'connected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
153 'disconnected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
155 $ilDB->createTable(
'chatroom_psessions', $fields);
158 if(!$ilDB->tableExists(
'chatroom_proomaccess'))
161 'proom_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
162 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
164 $ilDB->createTable(
'chatroom_proomaccess', $fields);
167 if(!$ilDB->tableColumnExists(
'chatroom_admconfig',
'client_settings'))
169 $ilDB->addTableColumn(
170 "chatroom_admconfig",
"client_settings",
179 if(!$ilDB->tableExists(
'chatroom_smilies'))
182 'smiley_id' => array(
186 'smiley_keywords' => array(
190 'smiley_path' => array(
196 $ilDB->createTable(
'chatroom_smilies', $fields);
197 $ilDB->addPrimaryKey(
'chatroom_smilies', array(
'smiley_id'));
198 $ilDB->createSequence(
'chatroom_smilies');
201 self::registerObject();
202 self::registerAdminObject();
203 self::removeOldChatEntries();
204 self::convertChatObjects();
207 $notificationSettings =
new ilSetting(
'notifications');
208 $notificationSettings->set(
'enable_osd',
true);
211 public static function removeOldChatEntries()
218 $res = $ilDB->queryF(
219 'SELECT object_data.obj_id, ref_id, lft, rgt
221 INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
222 INNER JOIN tree ON child = ref_id
228 $data = $ilDB->fetchAssoc(
$res);
231 $res = $ilDB->queryF(
'SELECT * FROM tree
232 INNER JOIN object_reference ON ref_id = child
233 INNER JOIN object_data ON object_data.obj_id = object_reference.obj_id
234 WHERE lft BETWEEN %s AND %s', array(
'integer',
'integer'), array($data[
'lft'], $data[
'rgt']));
235 while(
$row = $ilDB->fetchAssoc(
$res))
240 WHERE obj_id = ' . $ilDB->quote(
$row[
'obj_id'],
'integer')
245 FROM object_reference
246 WHERE ref_id = ' . $ilDB->quote(
$row[
'ref_id'],
'integer')
252 WHERE child = ' . $ilDB->quote(
$row[
'ref_id'],
'integer')
257 $ilDB->manipulateF(
'DELETE FROM object_data WHERE type = %s AND title = %s', array(
'text',
'text'), array(
'typ',
'chat'));
258 $ilDB->manipulateF(
'DELETE FROM object_data WHERE type = %s AND title = %s', array(
'text',
'text'), array(
'typ',
'chac'));
261 public static function createDefaultPublicRoom($force =
false)
270 $query =
'DELETE FROM chatroom_settings WHERE room_type = ' . $ilDB->quote(
'default',
'text');
271 $ilDB->manipulate(
$query);
276 $query =
'SELECT * FROM chatroom_settings WHERE room_type = ' . $ilDB->quote(
'default',
'text');
277 $rset = $ilDB->query(
$query);
278 $create = !$ilDB->fetchAssoc($rset);
283 SELECT object_data.obj_id, object_reference.ref_id
285 INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
286 WHERE type = " . $ilDB->quote(
'chta',
'text');
287 $rset = $ilDB->query(
$query);
288 $row = $ilDB->fetchAssoc($rset);
289 $chatfolder_ref_id =
$row[
'ref_id'];
291 require_once
'Modules/Chatroom/classes/class.ilObjChatroom.php';
294 $newObj->setType(
'chtr');
295 $newObj->setTitle(
'Public Chat');
296 $newObj->setDescription(
'');
298 $newObj->createReference();
299 $newObj->putInTree($chatfolder_ref_id);
300 $newObj->setPermissions($chatfolder_ref_id);
302 $obj_id = $newObj->getId();
305 $id = $ilDB->nextId(
'chatroom_settings');
309 'room_id' => array(
'integer', $id),
310 'object_id' => array(
'integer', $obj_id),
311 'room_type' => array(
'text',
'default'),
312 'allow_anonymous' => array(
'integer', 0),
313 'allow_custom_usernames' => array(
'integer', 0),
314 'enable_history' => array(
'integer', 0),
315 'restrict_history' => array(
'integer', 0),
316 'autogen_usernames' => array(
'text',
'Anonymous #'),
317 'allow_private_rooms' => array(
'integer', 1),
322 $settings->set(
'public_room_ref',
$ref_id);
330 public static function registerObject()
339 $query =
'SELECT obj_id FROM object_data ' .
340 'WHERE type = ' . $ilDB->quote(
'typ',
'text') .
' ' .
341 'AND title = ' . $ilDB->quote(
'chtr',
'text');
342 if(!($object_definition_row = $ilDB->fetchAssoc($ilDB->query(
$query))))
344 $typ_id = $ilDB->nextId(
'object_data');
348 'obj_id' => array(
'integer', $typ_id),
349 'type' => array(
'text',
'typ'),
350 'title' => array(
'text',
'chtr'),
351 'description' => array(
'text',
'Chatroom Object'),
352 'owner' => array(
'integer', -1),
353 'create_date' => array(
'timestamp', date(
'Y-m-d H:i:s')),
354 'last_update' => array(
'timestamp', date(
'Y-m-d H:i:s'))
360 foreach(array(1, 2, 3, 4) as $ops_id)
362 $query =
"INSERT INTO rbac_ta (typ_id, ops_id) VALUES ( " .
363 $ilDB->quote($typ_id,
'integer') .
"," . $ilDB->quote($ops_id,
'integer') .
365 $ilDB->manipulate(
$query);
369 if($moderatePermissionId = self::getModeratorPermissionId())
373 $typ_id = $object_definition_row[
'obj_id'];
379 'DELETE FROM rbac_ta WHERE typ_id = %s AND ops_id = %s',
380 array(
'integer',
'integer'),
381 array($typ_id, $moderatePermissionId)
387 'typ_id' => array(
'integer', $typ_id),
388 'ops_id' => array(
'integer', $moderatePermissionId),
395 private static function getModeratorPermissionId()
402 $rset = $ilDB->queryF(
403 'SELECT ops_id FROM rbac_operations WHERE operation = %s',
407 if(
$row = $ilDB->fetchAssoc($rset))
409 return $row[
'ops_id'];
418 public static function registerAdminObject()
425 $query =
'SELECT * FROM object_data WHERE type = ' . $ilDB->quote(
'chta',
'text');
426 if(!$ilDB->fetchAssoc($ilDB->query(
$query)))
428 $obj_id = $ilDB->nextId(
'object_data');
432 'obj_id' => array(
'integer', $obj_id),
433 'type' => array(
'text',
'chta'),
434 'title' => array(
'text',
'Chatroom Admin'),
435 'description' => array(
'text',
'Chatroom General Settings'),
436 'owner' => array(
'integer', -1),
437 'create_date' => array(
'timestamp', date(
'Y-m-d H:i:s')),
438 'last_update' => array(
'timestamp', date(
'Y-m-d H:i:s'))
442 $ref_id = $ilDB->nextId(
'object_reference');
443 $query =
"INSERT INTO object_reference (ref_id, obj_id) VALUES(" . $ilDB->quote(
$ref_id,
'integer') .
", " . $ilDB->quote($obj_id,
'integer') .
")";
444 $ilDB->manipulate(
$query);
446 $tree =
new ilTree(ROOT_FOLDER_ID);
447 $tree->insertNode(
$ref_id, SYSTEM_FOLDER_ID);
457 if(is_array($obj_ids))
459 foreach($obj_ids as $obj_id)
462 $room->saveSettings(array(
463 'object_id' => $obj_id,
464 'autogen_usernames' =>
'Autogen #',
465 'room_type' =>
'repository'
474 public static function convertChatObjects()
481 $res = $ilDB->queryF(
491 while(
$row = $ilDB->fetchAssoc(
$res))
493 $obj_ids[] =
$row[
'obj_id'];
500 array(
'text',
'text'),
501 array(
'chtr',
'chat')
507 public static function createMissinRoomSettingsForConvertedObjects()
514 $res = $ilDB->queryF(
515 "SELECT obj_id FROM object_data
516 LEFT JOIN chatroom_settings ON object_id = obj_id
518 AND room_id IS NULL",
523 $roomsToFix = array();
524 while(
$row = $ilDB->fetchAssoc(
$res))
526 $roomsToFix[] =
$row[
'obj_id'];
535 public static function ensureCorrectPublicChatroomTreeLocation(
$ref_id)
542 global $tree,
$ilDB, $rbacadmin;
546 SELECT object_data.obj_id, object_reference.ref_id
548 INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
549 WHERE type = " . $ilDB->quote(
'chta',
'text');
550 $rset = $ilDB->query(
$query);
551 $row = $ilDB->fetchAssoc($rset);
552 $chatfolder_ref_id =
$row[
'ref_id'];
553 $pid = $tree->getParentId(
$ref_id);
556 $chatfolder_ref_id &&
557 $pid != $chatfolder_ref_id &&
558 !$tree->isDeleted($chatfolder_ref_id)
561 $tree->moveTree(
$ref_id, $chatfolder_ref_id);
562 $rbacadmin->adjustMovedObjectPermissions(
$ref_id, $pid);
563 include_once(
'./Services/AccessControl/classes/class.ilConditionHandler.php');