4 require_once
'./Modules/Forum/classes/class.ilForumProperties.php';
5 require_once
'./Modules/Forum/classes/class.ilObjForum.php';
6 require_once
'./Modules/Forum/classes/class.ilForumTopic.php';
7 require_once
'./Modules/Forum/classes/class.ilForumPost.php';
98 static $lngCache = array();
103 if(!isset($lngCache[$languageShorthandle]))
105 $lngCache[$languageShorthandle] =
new ilLanguage($languageShorthandle);
106 $lngCache[$languageShorthandle]->loadLanguageModule(
'forum');
109 return $lngCache[$languageShorthandle];
120 if (!isset($a_obj_id))
122 $message = get_class($this).
"::setForumId(): No obj_id given!";
123 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
126 $this->
id = $a_obj_id;
136 if (!isset($a_ref_id))
138 $message = get_class($this).
"::setForumRefId(): No ref_id given!";
139 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
142 $this->ref_id = $a_ref_id;
175 die($this->className .
"::setOrderField(): No orderField given.");
204 die($this->className .
"::setDbTable(): No database table given.");
235 $this->mdb2Query = $query_string;
236 $this->mdb2DataValue = $data_value;
237 $this->mdb2DataType = $data_type;
250 if($this->mdb2Query !=
'')
264 if($this->mdb2DataValue !=
'')
277 if($this->mdb2DataType !=
'')
293 die($this->className .
"::setPageHits(): No int pageHits given.");
324 $data_type = array();
325 $data_value = array();
327 $query =
'SELECT * FROM frm_data WHERE ';
331 $query .=
''.$this->getMDB2Query().
'';
335 $res = $ilDB->queryf(
$query, $data_type, $data_value);
338 if(is_null(
$row))
return NULL;
340 $row[
"top_name"] = trim(
$row[
"top_name"]);
341 $row[
"top_description"] = nl2br(
$row[
"top_description"]);
353 if(!is_array(
$row) || !count(
$row))
return null;
355 $row[
'top_name'] = trim(
$row[
'top_name']);
356 $row[
'top_description'] = nl2br(
$row[
'top_description']);
371 $data_type = array();
372 $data_value = array();
374 $query =
'SELECT * FROM frm_threads WHERE ';
382 $sql_res = $ilDB->queryf(
$query, $data_type, $data_value);
383 $result = $ilDB->fetchAssoc($sql_res);
400 $res = $ilDB->queryf(
'
401 SELECT frm_posts.*, usr_data.lastname FROM frm_posts, usr_data
403 AND pos_usr_id = usr_id',
404 array(
'integer'), array($post));
410 $row[
"pos_message"] = nl2br(
$row[
"pos_message"]);
419 $res = $ilDB->queryf(
'
420 SELECT * FROM frm_posts WHERE pos_pk = %s',
421 array(
'integer'), array($a_id));
423 while(
$row = $ilDB->fetchObject(
$res))
425 return $row->pos_message;
444 public function generatePost($forum_id, $thread_id, $user, $message, $parent_pos, $notify, $subject =
'', $alias =
'', $date =
'', $status = 1, $send_activation_mail = 0)
449 $objNewPost->setForumId($forum_id);
450 $objNewPost->setThreadId($thread_id);
451 $objNewPost->setSubject($subject);
452 $objNewPost->setMessage($message);
453 $objNewPost->setUserId($user);
454 $objNewPost->setUserAlias($alias);
457 $objNewPost->setCreateDate(date(
"Y-m-d H:i:s"));
461 if (strpos($date,
"-") > 0)
463 $objNewPost->setCreateDate($date);
467 $objNewPost->setCreateDate(date(
"Y-m-d H:i:s", $date));
472 $objNewPost->setNotification($notify);
473 $objNewPost->setStatus($status);
474 $objNewPost->insert();
477 if ($parent_pos == 0)
479 $this->
addPostTree($objNewPost->getThreadId(), $objNewPost->getId(), $objNewPost->getCreateDate());
483 $this->
insertPostNode($objNewPost->getId(), $parent_pos, $objNewPost->getThreadId(), $objNewPost->getCreateDate());
488 $lastPost = $objNewPost->getForumId().
"#".$objNewPost->getThreadId().
"#".$objNewPost->getId();
493 SET thr_num_posts = thr_num_posts + 1,
496 array(
'text',
'integer'),
497 array($lastPost, $objNewPost->getThreadId()));
502 SET top_num_posts = top_num_posts + 1,
505 array(
'text',
'integer'),
506 array($lastPost, $objNewPost->getForumId()));
510 $forum_obj->markPostRead($objNewPost->getUserId(), $objNewPost->getThreadId(), $objNewPost->getId());
512 $pos_data = $objNewPost->getDataAsArray();
517 if (!$status && $send_activation_mail)
519 $pos_data[
"top_name"] = $forum_obj->getTitle();
526 require_once
'Services/RTE/classes/class.ilRTE.php';
527 include_once(
"./Services/News/classes/class.ilNewsItem.php");
529 $news_item->setContext($forum_obj->getId(),
'frm', $objNewPost->getId(),
'pos');
531 $news_item->setTitle($objNewPost->getSubject());
533 $news_item->setUserId($user);
535 $news_item->create();
538 return $objNewPost->getId();
554 public function generateThread($forum_id, $user, $subject, $message, $notify, $notify_posts, $alias =
'', $date =
'')
559 $objNewThread->setForumId($forum_id);
560 $objNewThread->setUserId($user);
561 $objNewThread->setSubject($subject);
564 $objNewThread->setCreateDate(date(
"Y-m-d H:i:s"));
568 if (strpos($date,
"-") > 0)
570 $objNewThread->setCreateDate($date);
574 $objNewThread->setCreateDate(date(
"Y-m-d H:i:s", $date));
578 $objNewThread->setUserAlias($alias);
579 $objNewThread->insert();
581 if ($notify_posts == 1)
583 $objNewThread->enableNotification($user);
587 $statement = $ilDB->manipulateF(
'
589 SET top_num_threads = top_num_threads + 1
591 array(
'integer'), array($forum_id));
593 return $this->
generatePost($forum_id, $objNewThread->getId(), $user, $message, 0, $notify, $subject, $alias, $objNewThread->getCreateDate());
604 public function moveThreads($thread_ids = array(), $src_ref_id = 0, $dest_top_frm_fk = 0)
610 if (is_numeric($src_top_frm_fk) && $src_top_frm_fk > 0 && is_numeric($dest_top_frm_fk) && $dest_top_frm_fk > 0)
621 if ($oldFrmData[
'top_pk'] && $newFrmData[
'top_pk'])
626 foreach ($thread_ids as
$id)
630 $numPosts = $objTmpThread->movePosts($src_top_frm_fk, $oldFrmData[
'top_pk'], $dest_top_frm_fk, $newFrmData[
'top_pk']);
631 if (($last_post_string = $objTmpThread->getLastPostString()) !=
'')
633 $last_post_string = explode(
'#', $last_post_string);
634 $last_post_string[0] = $newFrmData[
'top_pk'];
635 $last_post_string = implode(
'#', $last_post_string);
636 $objTmpThread->setLastPostString($last_post_string);
639 $visits += $objTmpThread->getVisits();
641 $moved_posts += $numPosts;
644 $objTmpThread->setForumId($newFrmData[
'top_pk']);
645 $objTmpThread->update();
647 unset($objTmpThread);
652 $res = $ilDB->queryf(
'
653 SELECT pos_thr_fk, pos_pk
655 WHERE pos_top_fk = %s
656 ORDER BY pos_date DESC',
657 array(
'integer'), array($oldFrmData[
'top_pk']));
660 $last_post_src = $oldFrmData[
'top_pk'] .
'#' .
$row->pos_thr_fk .
'#' .
$row->pos_pk;
662 $statement = $ilDB->manipulateF(
'
664 SET top_num_posts = top_num_posts - %s,
665 top_num_threads = top_num_threads - %s,
666 visits = visits - %s,
669 array(
'integer',
'integer',
'integer',
'text',
'integer'),
674 $oldFrmData[
'top_pk']));
679 $res = $ilDB->queryf(
'
680 SELECT pos_thr_fk, pos_pk
682 WHERE pos_top_fk = %s
683 ORDER BY pos_date DESC',
684 array(
'integer'), array($newFrmData[
'top_kp']));
687 $last_post_dest = $newFrmData[
'top_pk'] .
'#' .
$row->pos_thr_fk .
'#' .
$row->pos_pk;
689 $statement = $ilDB->manipulateF(
'
691 SET top_num_posts = top_num_posts + %s,
692 top_num_threads = top_num_threads + %s,
693 visits = visits + %s,
696 array(
'integer',
'integer',
'integer',
'text',
'integer'),
697 array($moved_posts, $moved_threads, $visits, $last_post_dest, $newFrmData[
'top_pk']));
731 $statement = $ilDB->manipulateF(
'
733 SET pos_cens_com = %s,
738 array(
'text',
'timestamp',
'integer',
'integer',
'integer'),
739 array($message, date(
"Y-m-d H:i:s"), $cens,
$_SESSION[
'AccountId'], $pos_pk));
742 include_once(
"./Services/News/classes/class.ilNewsItem.php");
744 "frm", $pos_pk,
"pos");
751 $news_item->setContent(nl2br($this->
prepareText($message, 0)));
752 $news_item->update();
757 $res = $ilDB->queryf(
'
758 SELECT * FROM frm_posts
760 array(
'integer'), array($pos_pk));
762 $rec = $ilDB->fetchAssoc(
$res);
766 $news_item->setContent(nl2br($this->
prepareText($rec[
"pos_message"], 0)));
767 $news_item->update();
784 include_once
"./Modules/Forum/classes/class.ilObjForum.php";
792 foreach($del_id as $post_id)
794 ilObjForum::_deleteReadEntries($post_id);
800 $dead_pos = count($del_id);
804 if ($p_node[
"parent"] == 0)
807 include_once
'./Modules/Forum/classes/class.ilObjForum.php';
809 ilObjForum::_deleteAccessEntries($p_node[
'tree']);
812 $dead_thr = $p_node[
"tree"];
814 $statement = $ilDB->manipulateF(
'
815 DELETE FROM frm_threads
817 array(
'integer'), array($p_node[
'tree']));
820 $statement = $ilDB->manipulateF(
'
822 SET top_num_threads = top_num_threads - 1
823 WHERE top_frm_fk = %s',
824 array(
'integer'), array($this->
id));
827 $posset = $ilDB->queryf(
'
828 SELECT * FROM frm_posts
829 WHERE pos_thr_fk = %s',
830 array(
'integer'), array($p_node[
'tree']));
832 while ($posrec = $ilDB->fetchAssoc($posset))
834 include_once(
"./Services/News/classes/class.ilNewsItem.php");
836 "frm", $posrec[
"pos_pk"],
"pos");
840 $news_item->delete();
845 include_once
'Services/MediaObjects/classes/class.ilObjMediaObject.php';
847 foreach(
$mobs as $mob)
864 $statement = $ilDB->manipulateF(
'
865 DELETE FROM frm_posts
866 WHERE pos_thr_fk = %s',
867 array(
'integer'), array($p_node[
'tree']));
874 for ($i = 0; $i < $dead_pos; $i++)
876 $statement = $ilDB->manipulateF(
'
877 DELETE FROM frm_posts
879 array(
'integer'), array($del_id[$i]));
882 include_once(
"./Services/News/classes/class.ilNewsItem.php");
884 "frm", $del_id[$i],
"pos");
888 $news_item->delete();
893 include_once
'Services/MediaObjects/classes/class.ilObjMediaObject.php';
895 foreach(
$mobs as $mob)
911 $statement = $ilDB->manipulateF(
'
913 SET thr_num_posts = thr_num_posts - %s
915 array(
'integer',
'integer'),
916 array($dead_pos, $p_node[
'tree']));
920 $res1 = $ilDB->queryf(
'
921 SELECT * FROM frm_posts
922 WHERE pos_thr_fk = %s
923 ORDER BY pos_date DESC',
924 array(
'integer'), array($p_node[
'tree']));
926 if ($res1->numRows() == 0)
934 while ($selData = $ilDB->fetchAssoc($res1))
941 $lastPost_thr = $selData[
"pos_top_fk"].
"#".$selData[
"pos_thr_fk"].
"#".$selData[
"pos_pk"];
946 $statement = $ilDB->manipulateF(
'
948 SET thr_last_post = %s
950 array(
'text',
'integer'), array($lastPost_thr, $p_node[
'tree']));
954 $statement = $ilDB->manipulateF(
'
956 SET top_num_posts = top_num_posts - %s
957 WHERE top_frm_fk = %s',
958 array(
'integer',
'integer'), array($dead_pos, $this->
id));
962 $res2 = $ilDB->queryf(
'
963 SELECT * FROM frm_posts, frm_data
964 WHERE pos_top_fk = top_pk
966 ORDER BY pos_date DESC',
967 array(
'integer'), array($this->
id));
969 if ($res2->numRows() == 0)
977 while ($selData = $ilDB->fetchAssoc($res2))
984 $lastPost_top = $selData[
"pos_top_fk"].
"#".$selData[
"pos_thr_fk"].
"#".$selData[
"pos_pk"];
989 $statement = $ilDB->manipulateF(
'
991 SET top_last_post = %s
992 WHERE top_frm_fk = %s',
993 array(
'text',
'integer'), array($lastPost_top, $this->
id));
1005 public function getAllThreads($a_topic_id, $is_moderator =
false, $limit = 0, $offset = 0)
1010 $query =
'SELECT COUNT(thr_pk) cnt
1012 WHERE thr_top_fk = %s';
1013 $res = $ilDB->queryF(
$query, array(
'integer'), array($a_topic_id));
1015 $cnt = (int)
$data[
'cnt'];
1020 $data_types = array();
1023 $active_inner_query =
'';
1026 $active_query =
' AND (pos_status = %s OR pos_usr_id = %s) ';
1027 $active_inner_query =
' AND (ipos.pos_status = %s OR ipos.pos_usr_id = %s) ';
1030 if(!$ilUser->isAnonymous())
1033 (CASE WHEN COUNT(DISTINCT(notification_id)) > 0 THEN 1 ELSE 0 END) usr_notification_is_enabled,
1034 MAX(pos_date) post_date,
1035 COUNT(DISTINCT(pos_pk)) num_posts,
1037 COUNT(DISTINCT(pos_pk)) - COUNT(DISTINCT(postread.post_id)) num_unread_posts,
1040 SELECT COUNT(DISTINCT(ipos.pos_pk))
1042 LEFT JOIN frm_user_read iread ON iread.post_id = ipos.pos_pk AND iread.usr_id = %s
1043 LEFT JOIN frm_thread_access iacc ON (iacc.thread_id = ipos.pos_thr_fk AND iacc.usr_id = %s)
1044 WHERE ipos.pos_thr_fk = thr_pk
1047 (ipos.pos_date > iacc.access_old_ts OR ipos.pos_update > iacc.access_old_ts)
1049 (iacc.access_old IS NULL AND (ipos.pos_date > ".$ilDB->quote(date(
'Y-m-d H:i:s', NEW_DEADLINE),
'timestamp').
" OR ipos.pos_update > ".$ilDB->quote(date(
'Y-m-d H:i:s', NEW_DEADLINE),
'timestamp').
"))
1052 AND ipos.pos_usr_id != %s
1053 AND iread.usr_id IS NULL $active_inner_query
1056 thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed
1060 LEFT JOIN frm_notification
1061 ON frm_notification.thread_id = thr_pk
1062 AND frm_notification.user_id = %s
1065 ON pos_thr_fk = thr_pk $active_query
1067 LEFT JOIN frm_user_read postread
1068 ON postread.post_id = pos_pk
1069 AND postread.usr_id = %s
1071 WHERE thr_top_fk = %s
1072 GROUP BY thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed
1073 ORDER BY is_sticky DESC, post_date DESC, thr_date DESC";
1075 $data_types[] =
'integer';
1076 $data_types[] =
'integer';
1077 $data_types[] =
'integer';
1080 array_push($data_types,
'integer',
'integer');
1082 $data_types[] =
'integer';
1085 array_push($data_types,
'integer',
'integer');
1087 $data_types[] =
'integer';
1088 $data_types[] =
'integer';
1090 $data[] = $ilUser->getId();
1091 $data[] = $ilUser->getId();
1092 $data[] = $ilUser->getId();
1095 array_push(
$data,
'1', $ilUser->getId());
1097 $data[] = $ilUser->getId();
1100 array_push(
$data,
'1', $ilUser->getId());
1102 $data[] = $ilUser->getId();
1103 $data[] = $a_topic_id;
1108 0 usr_notification_is_enabled,
1109 MAX(pos_date) post_date,
1110 COUNT(DISTINCT(pos_pk)) num_posts,
1111 COUNT(DISTINCT(pos_pk)) num_unread_posts,
1112 COUNT(DISTINCT(pos_pk)) num_new_posts,
1113 thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed
1117 ON pos_thr_fk = thr_pk $active_query";
1120 $query .=
" WHERE thr_top_fk = %s
1121 GROUP BY thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed
1122 ORDER BY is_sticky DESC, thr_date DESC";
1126 array_push($data_types,
'integer',
'integer');
1128 $data_types[] =
'integer';
1132 array_push(
$data,
'1', $ilUser->getId());
1134 $data[] = $a_topic_id;
1137 if($limit || $offset)
1139 $ilDB->setLimit($limit, $offset);
1142 while(
$row = $ilDB->fetchAssoc(
$res))
1145 $thread->assignData(
$row);
1146 $threads[] = $thread;
1150 'items' => $threads,
1159 $statistic = array();
1161 $data_types = array();
1164 $query =
"SELECT COUNT(f.pos_usr_id) ranking, u.login, p.value, u.lastname, u.firstname
1166 INNER JOIN frm_posts_tree t
1167 ON f.pos_pk = t.pos_fk
1168 INNER JOIN frm_threads th
1169 ON t.thr_fk = th.thr_pk
1170 INNER JOIN usr_data u
1171 ON u.usr_id = f.pos_usr_id
1172 INNER JOIN frm_data d
1173 ON d.top_pk = f.pos_top_fk
1174 LEFT JOIN usr_pref p
1175 ON p.usr_id = u.usr_id AND p.keyword = %s
1178 array_push($data_types,
'text');
1179 array_push(
$data,
'public_profile');
1183 $query .=
' AND (pos_status = %s
1185 AND pos_usr_id = %s ))';
1187 array_push($data_types,
'integer',
'integer',
'integer');
1188 array_push(
$data,
'1',
'0', $ilUser->getId());
1191 $query .=
' AND d.top_frm_fk = %s
1192 GROUP BY pos_usr_id, u.login, p.value,u.lastname, u.firstname';
1194 array_push($data_types,
'integer');
1200 while (
$row = $ilDB->fetchAssoc(
$res))
1202 $statistic[$counter][] =
$row[
'ranking'];
1203 $statistic[$counter][] =
$row[
'login'];
1208 if(!$ilUser->getId() == ANONYMOUS_USER_ID && in_array(
$row[
'value'], array(
'y',
'g')) ||
1209 $ilUser->getId() == ANONYMOUS_USER_ID &&
'g' ==
$row[
'value'])
1211 $lastname =
$row[
'lastname'];
1212 $firstname =
$row[
'firstname'];
1215 $statistic[$counter][] = $lastname;
1216 $statistic[$counter][] = $firstname;
1220 return is_array($statistic) ? $statistic : array();
1235 $res = $ilDB->queryf(
'
1236 SELECT * FROM frm_posts_tree
1238 AND parent_pos = %s',
1239 array(
'integer',
'integer'), array($a_thread_id,
'0'));
1243 return $row->pos_fk ?
$row->pos_fk : 0;
1270 $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
1271 $role_arr = $rbacreview->getRolesOfRoleFolder($rolf[
"ref_id"]);
1273 foreach ($role_arr as $role_id)
1277 if (
$title ==
"il_frm_moderator_".$a_ref_id)
1279 #return $rbacreview->assignedUsers($roleObj->getId());
1280 return $title = $rbacreview->assignedUsers($role_id);
1311 $res = $ilDB->queryf(
'
1312 SELECT * FROM frm_data
1313 INNER JOIN frm_posts ON pos_top_fk = top_pk
1314 WHERE top_frm_fk = %s
1315 AND pos_usr_id = %s',
1316 array(
'integer',
'integer'),
1319 return $res->numRows();
1326 $res = $ilDB->queryf(
'
1327 SELECT * FROM frm_data
1328 INNER JOIN frm_posts ON pos_top_fk = top_pk
1329 WHERE top_frm_fk = %s
1330 AND (pos_status = %s
1335 AND pos_usr_id = %s',
1336 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
1337 array($this->
getForumId(),
'1',
'0', $ilUser->getId(), $a_user_id));
1339 return $res->numRows();
1360 public function addPostTree($a_tree_id, $a_node_id = -1, $a_date =
'')
1364 $a_date = $a_date ? $a_date : date(
"Y-m-d H:i:s");
1366 if ($a_node_id <= 0)
1368 $a_node_id = $a_tree_id;
1371 $nextId = $ilDB->nextId(
'frm_posts_tree');
1373 $statement = $ilDB->manipulateF(
'
1374 INSERT INTO frm_posts_tree
1384 VALUES(%s, %s, %s, %s, %s, %s, %s, %s )',
1385 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'timestamp'),
1386 array($nextId, $a_tree_id, $a_node_id,
'0',
'1',
'2',
'1', $a_date));
1402 $a_date = $a_date ? $a_date : date(
"Y-m-d H:i:s");
1405 $sql_res = $ilDB->queryf(
'
1406 SELECT * FROM frm_posts_tree
1409 array(
'integer',
'integer'),
1410 array($a_parent_id, $tree_id));
1412 $res = $ilDB->fetchObject($sql_res);
1420 $statement = $ilDB->manipulateF(
'
1421 UPDATE frm_posts_tree
1433 array(
'integer',
'integer',
'integer'),
1434 array($left, $left, $tree_id));
1436 $depth = $this->
getPostDepth($a_parent_id, $tree_id) + 1;
1439 $nextId = $ilDB->nextId(
'frm_posts_tree');
1440 $statement = $ilDB->manipulateF(
'
1441 INSERT INTO frm_posts_tree
1451 VALUES(%s,%s,%s, %s, %s, %s,%s, %s)',
1452 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'timestamp'),
1478 $sql_res = $ilDB->queryf(
'
1479 SELECT depth FROM frm_posts_tree
1482 array(
'integer',
'integer'),
1483 array($a_node_id, $tree_id));
1485 $res = $ilDB->fetchObject($sql_res);
1505 $res = $ilDB->queryf(
'
1506 SELECT * FROM frm_posts, frm_posts_tree
1507 WHERE pos_pk = pos_fk
1510 array(
'integer',
'integer'),
1511 array(
'0', $tree_id));
1528 $res = $ilDB->queryf(
'
1529 SELECT * FROM frm_posts, frm_posts_tree
1530 WHERE pos_pk = pos_fk
1550 require_once(
'./Services/User/classes/class.ilObjUser.php');
1554 $tmp_user =
new ilObjUser($a_row->pos_usr_id);
1555 $fullname = $tmp_user->getFullname();
1556 $loginname = $tmp_user->getLogin();
1559 $fullname = $fullname ? $fullname : ($a_row->import_name ? $a_row->import_name : $lng->txt(
"unknown"));
1562 "pos_pk" => $a_row->pos_pk,
1563 "child" => $a_row->pos_pk,
1564 "author" => $a_row->pos_usr_id,
1565 "alias" => $a_row->pos_usr_alias,
1566 "title" => $fullname,
1567 "loginname" => $loginname,
1569 "message" => $a_row->pos_message,
1570 "subject" => $a_row->pos_subject,
1571 "pos_cens_com" => $a_row->pos_cens_com,
1572 "pos_cens" => $a_row->pos_cens,
1574 "date" => $a_row->fpt_date,
1575 "create_date" => $a_row->pos_date,
1576 "update" => $a_row->pos_update,
1577 "update_user" => $a_row->update_user,
1578 "tree" => $a_row->thr_fk,
1579 "parent" => $a_row->parent_pos,
1580 "lft" => $a_row->lft,
1581 "rgt" => $a_row->rgt,
1582 "depth" => $a_row->depth,
1583 "id" => $a_row->fpt_pk,
1584 "notify" => $a_row->notify,
1585 "import_name" => $a_row->import_name,
1586 "pos_status" => $a_row->pos_status
1606 $res = $ilDB->queryf(
'
1607 SELECT * FROM frm_posts_tree
1610 AND parent_pos = %s',
1611 array(
'integer',
'integer',
'integer'),
1612 array($a_node[
'tree'], $a_node[
'pos_pk'], $a_node[
'parent']));
1614 while(
$row = $ilDB->fetchObject(
$res))
1616 $a_node[
"lft"] =
$row->lft;
1617 $a_node[
"rgt"] =
$row->rgt;
1620 $diff = $a_node[
"rgt"] - $a_node[
"lft"] + 1;
1624 SELECT * FROM frm_posts_tree
1625 WHERE lft BETWEEN %s AND %s
1627 array(
'integer',
'integer',
'integer'),
1628 array($a_node[
'lft'], $a_node[
'rgt'], $a_node[
'tree']));
1632 while ($treeData = $ilDB->fetchAssoc(
$result))
1634 $del_id[] = $treeData[
"pos_fk"];
1638 $statement = $ilDB->manipulateF(
'
1639 DELETE FROM frm_posts_tree
1640 WHERE lft BETWEEN %s AND %s
1642 array(
'integer',
'integer',
'integer'),
1643 array($a_node[
'lft'], $a_node[
'rgt'], $a_node[
'tree']));
1647 $statement = $ilDB->manipulateF(
'
1648 UPDATE frm_posts_tree
1660 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
1661 array($a_node[
'lft'], $diff, $a_node[
'lft'], $diff, $a_node[
'tree']));
1677 $checkTime = time() - (60*60);
1679 if (
$_SESSION[
"frm_visit_".$this->dbTable.
"_".$ID] < $checkTime)
1682 $_SESSION[
"frm_visit_".$this->dbTable.
"_".$ID] = time();
1683 $query =
'UPDATE '.$this->dbTable.
' SET visits = visits + 1 WHERE ';
1685 $data_type = array();
1686 $data_value = array();
1694 $res = $ilDB->queryf(
$query, $data_type, $data_value);
1706 public function prepareText($text, $edit=0, $quote_user =
'', $type =
'')
1710 if($type ==
'export')
1712 $this->replQuote1 =
"<blockquote class=\"quote\"><hr size=\"1\" color=\"#000000\">";
1713 $this->replQuote2 =
"<hr size=\"1\" color=\"#000000\"/></blockquote>";
1719 $lname = ($quote_user !=
"")
1720 ?
'="'.$quote_user.
'"'
1723 $text =
"[quote$lname]".$text.
"[/quote]";
1728 $startZ = substr_count ($text,
"[quote");
1729 $endZ = substr_count ($text,
"[/quote]");
1731 if ($startZ > 0 || $endZ > 0)
1734 if ($startZ > $endZ)
1736 $diff = $startZ - $endZ;
1738 for ($i = 0; $i < $diff; $i++)
1741 else $text .=
"[/quote]";
1744 elseif ($startZ < $endZ)
1746 $diff = $endZ - $startZ;
1748 for ($i = 0; $i < $diff; $i++)
1750 if ($type ==
'export') $text = $this->txtQuote1.$text;
1751 else $text =
"[quote]".$text;
1757 $ws=
"[ \t\r\f\v\n]*";
1759 $text = eregi_replace(
"\[(quote$ws=$ws\"([^\"]*)\"$ws)\]",
1760 $this->replQuote1.
'<div class="ilForumQuoteHead">'.$lng->txt(
"quote").
" (\\2)".
'</div>', $text);
1762 $text = str_replace(
"[quote]",
1763 $this->replQuote1.
'<div class="ilForumQuoteHead">'.$lng->txt(
"quote").
'</div>', $text);
1765 $text = str_replace(
"[/quote]", $this->replQuote2, $text);
1770 if($type !=
'export')
1781 $text = str_replace(
"{",
"{", $text);
1782 $text = str_replace(
"}",
"}", $text);
1799 $res = $ilDB->queryf(
'
1800 SELECT frm_data.* FROM frm_data, frm_posts
1802 AND pos_top_fk = top_pk',
1803 array(
'integer'), array($pos_pk));
1813 if(!is_array($a_ids))
1817 include_once
"./Modules/Forum/classes/class.ilFileDataForum.php";
1820 foreach($a_ids as $pos_id)
1822 $tmp_file_obj->setPosId($pos_id);
1823 $files = $tmp_file_obj->getFilesOfPost();
1824 foreach($files as
$file)
1826 $tmp_file_obj->unlinkFile($file[
"name"]);
1829 unset($tmp_file_obj);
1838 $parent_data = $this->
getOnePost($a_parent_pos);
1841 if($parent_data[
"notify"] && $parent_data[
"pos_usr_id"] != $ilUser->getId())
1844 include_once
"Services/Mail/classes/class.ilMail.php";
1845 include_once
'./Services/User/classes/class.ilObjUser.php';
1847 $tmp_user =&
new ilObjUser($parent_data[
"pos_usr_id"]);
1854 $tmp_mail_obj =
new ilMail(ANONYMOUS_USER_ID);
1855 $message = $tmp_mail_obj->sendMail($tmp_user->getLogin(),
"",
"",
1858 array(),array(
"system"));
1861 unset($tmp_mail_obj);
1875 include_once
"./Services/Object/classes/class.ilObjectFactory.php";
1879 $title = $frm_obj->getTitle();
1886 $message .= $this->lng->txt(
"forum_post_replied");
1887 $message .= $this->lng->txt(
"forum").
": ".
$title.
" -> ".$thread_data[
"thr_subject"].
"\n\n";
1889 $message .=
"\n------------------------------------------------------------\n";
1890 $message .= $post_data[
"pos_message"];
1891 $message .=
"\n------------------------------------------------------------\n";
1892 $message .= sprintf($this->lng->txt(
"forums_notification_show_post"),
"http://".$_SERVER[
"HTTP_HOST"].dirname($_SERVER[
"PHP_SELF"]).
"/goto.php?target=frm_".$post_data[
"ref_id"].
"_".$post_data[
"pos_thr_fk"].
'&client_id='.CLIENT_ID).
"\n\n";
1900 return $this->import_name;
1904 $this->import_name = $a_import_name;
1921 $res = $ilDB->queryf(
'
1922 SELECT frm_notification.thread_id FROM frm_data, frm_notification, frm_threads
1923 WHERE frm_notification.user_id = %s
1924 AND frm_notification.thread_id = frm_threads.thr_pk
1925 AND frm_threads.thr_top_fk = frm_data.top_pk
1926 AND frm_data.top_frm_fk = %s
1927 GROUP BY frm_notification.thread_id',
1928 array(
'integer',
'integer'),
1929 array($user_id, $this->
id));
1931 if (is_object(
$res) &&
$res->numRows() > 0)
1933 $thread_data = array();
1934 $thread_data_types = array();
1936 $query =
' DELETE FROM frm_notification
1938 AND thread_id IN (';
1940 array_push($thread_data, $user_id);
1941 array_push($thread_data_types,
'integer');
1945 while(
$row = $ilDB->fetchAssoc(
$res))
1947 if($counter < $res->numRows())
1950 array_push($thread_data,
$row[
'thread_id']);
1951 array_push($thread_data_types,
'integer');
1954 if($counter ==
$res->numRows())
1957 array_push($thread_data,
$row[
'thread_id']);
1958 array_push($thread_data_types,
'integer');
1964 $statement = $ilDB->manipulateF(
$query, $thread_data_types, $thread_data);
1969 $nextId = $ilDB->nextId(
'frm_notification');
1971 $statement = $ilDB->manipulateF(
'
1972 INSERT INTO frm_notification
1977 VALUES(%s, %s, %s)',
1978 array(
'integer',
'integer',
'integer'),
1979 array($nextId, $user_id, $this->
id));
1996 $statement = $ilDB->manipulateF(
'
1997 DELETE FROM frm_notification
2000 array(
'integer',
'integer'),
2001 array($user_id, $this->
id));
2016 $result = $ilDB->queryf(
'SELECT COUNT(*) cnt FROM frm_notification WHERE user_id = %s AND frm_id = %s',
2017 array(
'integer',
'integer'), array($user_id, $this->
id));
2019 while($record = $ilDB->fetchAssoc(
$result))
2021 return (
bool)$record[
'cnt'];
2040 $nextId = $ilDB->nextId(
'frm_notification');
2041 $statement = $ilDB->manipulateF(
'
2042 INSERT INTO frm_notification
2047 VALUES (%s, %s, %s)',
2048 array(
'integer',
'integer',
'integer'), array($nextId, $user_id, $thread_id));
2067 SELECT COUNT(*) cnt FROM frm_notification
2069 AND thread_id = %s',
2070 array(
'integer',
'integer'),
2071 array($user_id, $thread_id));
2074 while($record = $ilDB->fetchAssoc(
$result))
2076 return (
bool)$record[
'cnt'];
2084 global $ilDB, $ilAccess,
$lng;
2086 include_once
"Services/Mail/classes/class.ilMail.php";
2087 include_once
'./Services/User/classes/class.ilObjUser.php';
2091 SELECT thr_subject FROM frm_threads
2093 array(
'integer'), array($post_data[
'pos_thr_fk']));
2095 while($record = $ilDB->fetchAssoc(
$result))
2097 $post_data[
'thr_subject'] = $record[
'thr_subject'];
2105 if($post_data[
'pos_usr_id'])
2109 else if(strlen($post_data[
'pos_usr_alias']))
2111 $post_data[
'pos_usr_name'] = $post_data[
'pos_usr_alias'].
' ('.$lng->txt(
'frm_pseudonym').
')';
2114 if($post_data[
'pos_usr_name'] ==
'')
2116 $post_data[
'pos_usr_name'] = $this->lng->txt(
'forums_anonymous');
2120 $res = $ilDB->queryf(
'
2121 SELECT user_id FROM frm_notification
2122 WHERE thread_id = %s
2124 array(
'integer',
'integer'),
2125 array($post_data[
'pos_thr_fk'],
$_SESSION[
'AccountId']));
2132 $userLanguage =
$lng;
2136 $filesOfPost = $fileDataForum->getFilesOfPost();
2138 $attachments = array();
2139 foreach($filesOfPost as $attachment)
2141 $attachments[] = $attachment[
'name'];
2144 $mail_obj =
new ilMail(ANONYMOUS_USER_ID);
2145 while(
$row = $ilDB->fetchAssoc(
$res))
2149 foreach((array)$frm_references as
$ref_id)
2151 if($ilAccess->checkAccessOfUser(
$row[
'user_id'],
'read',
'',
$ref_id))
2160 $this->
setLanguage(self::_getLanguageInstanceByUsrId(
$row[
'user_id']));
2161 $mail_obj->sendMail(
2165 array(), array(
"system")
2178 include_once
"Services/Mail/classes/class.ilMail.php";
2179 include_once
'./Services/User/classes/class.ilObjUser.php';
2183 SELECT thr_subject FROM frm_threads
2186 array($post_data[
'pos_thr_fk']));
2188 while($record = $ilDB->fetchAssoc(
$result))
2190 $post_data[
'thr_subject'] = $record[
'thr_subject'];
2198 if($post_data[
'pos_usr_id'])
2202 else if(strlen($post_data[
'pos_usr_alias']))
2204 $post_data[
'pos_usr_name'] = $post_data[
'pos_usr_alias'].
' ('.$lng->txt(
'frm_pseudonym').
')';
2207 if($post_data[
'pos_usr_name'] ==
'')
2209 $post_data[
'pos_usr_name'] = $this->lng->txt(
'forums_anonymous');
2213 $res = $ilDB->queryf(
'
2214 SELECT frm_notification.user_id FROM frm_notification, frm_data
2215 WHERE frm_data.top_pk = %s
2216 AND frm_notification.frm_id = frm_data.top_frm_fk
2217 AND frm_notification.user_id <> %s
2218 GROUP BY frm_notification.user_id',
2219 array(
'integer',
'integer'),
2220 array($post_data[
'pos_top_fk'], $ilUser->getId()));
2227 $userLanguage =
$lng;
2231 $filesOfPost = $fileDataForum->getFilesOfPost();
2232 $attachments = array();
2233 foreach($filesOfPost as $attachment)
2235 $attachments[] = $attachment[
'name'];
2238 $mail_obj =
new ilMail(ANONYMOUS_USER_ID);
2239 while(
$row = $ilDB->fetchAssoc(
$res))
2243 foreach((array)$frm_references as
$ref_id)
2245 if($ilAccess->checkAccessOfUser(
$row[
'user_id'],
'read',
'',
$ref_id))
2254 $this->
setLanguage(self::_getLanguageInstanceByUsrId(
$row[
'user_id']));
2255 $mail_obj->sendMail(
2259 array(), array(
"system")
2280 $message .= $this->lng->txt(
'forums_post_activation_mail').
"\n\n";
2282 $message .= $this->lng->txt(
"forum").
": ".$post_data[
"top_name"].
"\n\n";
2283 $message .= $this->lng->txt(
"thread").
": ".$post_data[
"thr_subject"].
"\n\n";
2284 $message .= $this->lng->txt(
"new_post").
":\n------------------------------------------------------------\n";
2285 $message .= $this->lng->txt(
"author").
": ".$post_data[
"pos_usr_name"].
"\n";
2286 $message .= $this->lng->txt(
"date").
": ".$post_data[
"pos_date"].
"\n";
2287 $message .= $this->lng->txt(
"subject").
": ".$post_data[
"pos_subject"].
"\n\n";
2288 if ($post_data[
"pos_cens"] == 1)
2290 $message .= $post_data[
"pos_cens_com"].
"\n";
2294 $pos_message = $post_data[
'pos_message'];
2295 if(strip_tags($pos_message) != $pos_message)
2297 $pos_message = preg_replace(
"/\n/i",
"", $pos_message);
2298 $pos_message = preg_replace(
"/<br(\s*)(\/?)>/i",
"\n", $pos_message);
2299 $pos_message = preg_replace(
"/<p([^>]*)>/i",
"\n\n", $pos_message);
2300 $pos_message = preg_replace(
"/<\/p([^>]*)>/i",
'', $pos_message);
2302 $message .= strip_tags($pos_message).
"\n";
2304 $message .=
"------------------------------------------------------------\n";
2306 $message .= sprintf($this->lng->txt(
'forums_notification_show_post'), ILIAS_HTTP_PATH.
"/goto.php?target=frm_".$post_data[
"ref_id"].
"_".$post_data[
"pos_thr_fk"].
"_".$post_data[
"pos_pk"].
'&client_id='.CLIENT_ID).
"\n\n";
2307 $message .= sprintf($this->lng->txt(
'forums_notification_intro'),
2308 $this->ilias->ini->readVariable(
'client',
'name'),
2309 ILIAS_HTTP_PATH.
'/?client_id='.CLIENT_ID).
"\n\n";
2322 SELECT thr_subject FROM frm_threads
2325 array($post_data[
'pos_thr_fk']));
2327 while($record = $ilDB->fetchAssoc(
$result))
2329 $post_data[
'thr_subject'] = $record[
'thr_subject'];
2334 if($post_data[
'pos_usr_id'])
2338 else if(strlen($post_data[
'pos_usr_alias']))
2340 $post_data[
'pos_usr_name'] = $post_data[
'pos_usr_alias'].
' ('.$lng->txt(
'frm_pseudonym').
')';
2343 if($post_data[
'pos_usr_name'] ==
'')
2345 $post_data[
'pos_usr_name'] = $this->lng->txt(
'forums_anonymous');
2350 $userLanguage =
$lng;
2352 $mail_obj =
new ilMail(ANONYMOUS_USER_ID);
2353 foreach($moderators as $moderator)
2356 $this->
setLanguage(self::_getLanguageInstanceByUsrId($moderator));
2359 $mail_obj->sendMail(
2363 array(), array(
"system")
2378 return $this->lng->txt(
"forums_notification_subject").
' '.$post_data[
'top_name'];
2398 $message .= $this->lng->txt(
"forums_notification_subject").
" ".$post_data[
'top_name'].
"\n\n";
2400 $message .= $this->lng->txt(
"forum").
": ".$post_data[
"top_name"].
"\n\n";
2401 $message .= $this->lng->txt(
"thread").
": ".$post_data[
"thr_subject"].
"\n\n";
2402 $message .= $this->lng->txt(
"new_post").
":\n------------------------------------------------------------\n";
2403 $message .= $this->lng->txt(
"author").
": ".$post_data[
"pos_usr_name"].
"\n";
2404 $message .= $this->lng->txt(
"date").
": ".$post_data[
"pos_date"].
"\n";
2405 $message .= $this->lng->txt(
"subject").
": ".$post_data[
"pos_subject"].
"\n\n";
2407 if ($post_data[
"pos_cens"] == 1)
2409 $message .= $post_data[
"pos_cens_com"].
"\n";
2413 $pos_message = $post_data[
'pos_message'];
2414 if(strip_tags($pos_message) != $pos_message)
2416 $pos_message = preg_replace(
"/\n/i",
"", $pos_message);
2417 $pos_message = preg_replace(
"/<br(\s*)(\/?)>/i",
"\n", $pos_message);
2418 $pos_message = preg_replace(
"/<p([^>]*)>/i",
"\n\n", $pos_message);
2419 $pos_message = preg_replace(
"/<\/p([^>]*)>/i",
'', $pos_message);
2421 $message .= strip_tags($pos_message).
"\n";
2423 $message .=
"------------------------------------------------------------\n";
2425 if(count($attachments) > 0)
2427 foreach($attachments as $attachment)
2429 $message .= $this->lng->txt(
'attachment').
": ".$attachment.
"\n";
2431 $message .=
"\n------------------------------------------------------------\n";
2436 $message .= sprintf($this->lng->txt(
"forums_notification_show_post"), $ilIliasIniFile->readVariable(
"server",
"http_path").
"/goto.php?target=frm_".$post_data[
"ref_id"].
"_".$post_data[
"pos_thr_fk"].
"_".$post_data[
"pos_pk"].
'&client_id='.CLIENT_ID).
"\n\n";
2440 $message .= sprintf($this->lng->txt(
"forums_notification_show_post"), ILIAS_HTTP_PATH.
"/goto.php?target=frm_".$post_data[
"ref_id"].
"_".$post_data[
"pos_thr_fk"].
"_".$post_data[
"pos_pk"].
'&client_id='.CLIENT_ID).
"\n\n";
2445 $message .= sprintf($this->lng->txt(
"forums_notification_intro"),
2446 $this->ilias->ini->readVariable(
"client",
"name"),
2447 $ilIliasIniFile->readVariable(
"server",
"http_path").
'/?client_id='.CLIENT_ID).
"\n\n";
2451 $message .= sprintf($this->lng->txt(
"forums_notification_intro"),
2452 $this->ilias->ini->readVariable(
"client",
"name"),
2453 ILIAS_HTTP_PATH.
'/?client_id='.CLIENT_ID).
"\n\n";
2468 public static function _getThreads($a_obj_id,$a_sort_mode = self::SORT_DATE)
2472 switch($a_sort_mode)
2474 case self::SORT_DATE:
2478 case self::SORT_TITLE:
2480 $sort =
'thr_subject';
2484 $res = $ilDB->queryf(
'
2485 SELECT * FROM frm_threads
2486 JOIN frm_data ON top_pk = thr_top_fk
2487 WHERE top_frm_fk = %s
2489 array(
'integer',
'text'), array($a_obj_id, $sort));
2491 while(
$row = $ilDB->fetchObject(
$res))
2493 $threads[
$row->thr_pk] =
$row->thr_subject;
2495 return $threads ? $threads : array();
2502 $res = $ilDB->queryf(
'
2503 SELECT top_frm_fk FROM frm_data
2505 array(
'integer'), array($a_for_id));
2507 if ($fdata = $ilDB->fetchAssoc(
$res))
2509 return $fdata[
"top_frm_fk"];