$res2["term"], "comment" => $res2["comment"]); return $r; } function getTermsDetailed() { $r = array(); $sql = "SELECT * FROM forum_terms ORDER BY term DESC"; $res = mysql_query_c($sql); if ($res == NULL || mysql_num_rows($res) == 0) return $r; while ($res2 = mysql_fetch_assoc($res)) { $q = mysql_query_c("SELECT COUNT(*) FROM forum_texts WHERE term_id = ".$res2["id"]); if ($a = mysql_fetch_row($q)) $posts = $a[0]; else $posts = 0; $q = mysql_query_c("SELECT COUNT(*) FROM forum_texts WHERE term_id = ".$res2["id"]." AND parent = 0"); if ($a = mysql_fetch_row($q)) $topics = $a[0]; else $topics = 0; $r[$res2["id"]] = array("term" => $res2["term"], "comment" => $res2["comment"], "topics" => $topics, "posts" => $posts); } return $r; } function getTermName($id) { $q = mysql_query_c("SELECT * FROM forum_terms WHERE id = $id"); if ($a = mysql_fetch_assoc($q)) return $a["term"]; } function addTerm($term,$comment) { $term = preg_replace("/\n|\r/","",$term); $term=preg_replace('/\\\"/',"\"",$term); $term=preg_replace("/'/","\"",$term); $comment = preg_replace("/\n|\r/","",$comment); $comment=preg_replace('/\\\"/',"\"",$comment); $comment=preg_replace("/'/","\"",$comment); $sql = "insert into forum_terms values('$term','$comment')"; $res = mysql_query_c($sql); } function deleteTerm($term) { $sql = "delete from forum_terms where term='$term'"; $res = mysql_query_c($sql); } function readItem($id) { $empty = array(); $sql = "SELECT * FROM forum_texts where id=$id"; $res = mysql_query_c($sql); if ($res == NULL || mysql_num_rows($res) == 0) return $empty; while($res2 = mysql_fetch_array($res)) $empty = $res2; return $empty; } function getItemName($id) { $q = mysql_query_c("SELECT id, title FROM forum_texts WHERE id = $id"); if ($a = mysql_fetch_assoc($q)) return $a["title"]; else return ""; } function readChilds($id,$term,$period,$sort) { $empty = array(); $sql = "SELECT * FROM forum_texts where parent=$id"; if ($term!="") $sql.=" AND term_id='$term'"; if ($period>0) $sql.=" AND TO_DAYS(NOW())-TO_DAYS(date)<=$period"; if ($sort) $sql.=" order by date desc,time desc"; $res = mysql_query_c($sql); if ($res == NULL || mysql_num_rows($res) == 0) return $empty; while($res2 = mysql_fetch_array($res)) { $res3 = mysql_query_c("select count(*) from forum_texts where parent=".$res2[0]); // echo "select count(*) from forum_texts where parent=".$res2[0]; if ($rw = mysql_fetch_array($res3)) $res2['replies']=$rw[0]; else $res2['replies']=0; // echo "cnt=".$res2['replies']."
"; $empty[] = $res2; } return $empty; } function countItems($term,$period) { $sql = "SELECT replies FROM forum_texts where parent=0 "; if ($term!="") $sql.=" AND term_id='$term'"; if ($period>0) $sql.=" AND TO_DAYS(NOW())-TO_DAYS(date)<=$period"; $res = mysql_query_c($sql); if ($res == NULL || mysql_num_rows($res) == 0) return 0; return mysql_num_rows($res); } function deleteChilds($id,$rep) { $sql = "delete FROM forum_texts where id=$id"; $res = mysql_query_c($sql); $sql = "SELECT id FROM forum_texts where parent=$id"; $res = mysql_query_c($sql); while($res2 = mysql_fetch_array($res)) $rep = deleteChilds($res2[0],$rep); return $rep+1; } function getPostsDetailed($term) { $r = array(); $q = mysql_query_c("SELECT * FROM forum_texts WHERE parent = 0".($term > 0 ? " AND term_id = $term" : "")." ORDER BY date DESC, time DESC"); while ($a = mysql_fetch_assoc($q)) { $r[$a["id"]] = $a; } return $r; } function getTerm($id) { $empty = array(); $sql = "SELECT term_id FROM forum_texts id=$id"; $res = mysql_query_c($sql); if ($res == NULL || mysql_num_rows($res) == 0) return ""; if ($res2 = mysql_fetch_array($res)) return $res2[0]; return ""; } function delTags($s) { $tags = array("img","table","tr","td","th"); for ($i=0;$i]*>/"," ",$s); $s = preg_replace("/<\/".$tags[$i]."[^>]*>/"," ",$s); } $s = preg_replace("/\r/","",$s); $s = preg_replace("/\n\s*\n\s*\n\s*\n\s*\n\s*\n/","





",$s); $s = preg_replace("/\n\s*\n\s*\n\s*\n\s*\n/","



",$s); $s = preg_replace("/\n\s*\n\s*\n\s*\n/","


",$s); $s = preg_replace("/\n\s*\n\s*\n/","

",$s); $s = preg_replace("/\n\s*\n/","
",$s); $s = preg_replace("/\n/"," ",$s); $s=preg_replace('/\\\"/',"\"",$s); $s=preg_replace("/'/","\"",$s); $s=preg_replace("/ +/"," ",$s); return $s; } function addItem($title,$text,$author_id, $parent, $term,$item_id) { $title = preg_replace("/<[^>]*>/"," ",$title); $title=delTags($title); $text=delTags($text); $text = substr($text,0,2000); // $author=delTags($author); $d = date("Y-m-d",time()); $t = date("H:i:s",time()); if ($item_id>0) { $sql = "select * from forum_texts where item_id=$item_id"; $res = mysql_query_c($sql); if ($rw = mysql_fetch_array($res)) return $rw['id']; } /* $q = mysql_query_c("SELECT id FROM forum_auth WHERE name = '$author'"); if (mysql_num_rows($q)) { $a = mysql_fetch_assoc($q); $uid = $a["id"]; } else $uid = 55; */ $uid=$author_id; $tid = $term; $term = getTermName($tid); $sql = "insert into forum_texts(parent, term_id, term, title, text, user_id, date, time, replies, write_date, write_time, item_id)". "values($parent, $tid, '$term','$title','$text',$uid,'$d','$t',0,'$d','$t',$item_id)"; $res = mysql_query_c($sql); $id = mysql_insert_id(); $sql = "UPDATE forum_auth SET last_date = '$d', last_time = '$t', user_msgs = user_msgs+1 WHERE id = $uid"; $res = mysql_query_c($sql); while ($parent>0) { $sql = "update forum_texts set date='$d',time='$t',replies = replies+1 where id=$parent"; $res = mysql_query_c($sql); $sql = "select parent from forum_texts where id=$parent"; $res = mysql_query_c($sql); if ($rw = mysql_fetch_array($res)) $parent = $rw[0]; } return $id; } function printTree($rw,$count,$pwd,$print,$pspan) { global $out,$template1,$template2; if ($template1 == "") { $f = fopen("item1.html","rt"); $template1 = fread($f,filesize("item1.html")); fclose($f); } if ($template2 == "") { $f = fopen("item2.html","rt"); $template2 = fread($f,filesize("item2.html")); fclose($f); } if ($print>0) $pspan = printForumItem($rw,$pwd,$pspan,$template1); $count++; $childs = readChilds($rw['id'],"",0,0); if (count($childs)>0) { for ($i=0;$i0) $img = "images/arrowup.gif"; else $img = "images/arrowdown.gif"; if ($rw['replies']>0) { $open = ""; $onclick="onclick='openDiv(ftdiv".$rw['id'].",null)' ondblclick='openDiv(fdiv".$rw['id'].",fimg".$rw['id'].")'"; } else { $open = "Ответов нет"; $onclick="onclick='openDiv(ftdiv".$rw['id'].",null)'"; } $dmas = split("-",$rw['date']); $tmas = split(":",$rw['time']); $tmas2 = split(":",$rw['write_time']); $date = $dmas[2].".".$dmas[1].".".$dmas[0]; $dmas2 = split("-",$rw['write_date']); $date2 = $dmas2[2].".".$dmas2[1].".".$dmas2[0]; if ($rw['parent'] > 0) { $date = $date2." ".$rw['write_time']; $span = mktime($tmas2[0],$tmas2[1],$tmas2[2],$dmas2[1],$dmas2[2],$dmas2[0]); } else { $span = mktime($tmas[0],$tmas[1],$tmas[2],$dmas[1],$dmas[2],$dmas[0]); $date = $date." ".$rw['time']; } $new = ""; $pspan = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); if ($pspan-$span<24*60*60) $new = "  "; if ($pwd>0) $delete = "    delete"; $out.= "
$open $new".$rw['title']."".$rw['term']."".$rw['name']."$date".$rw['replies']."Ответить $delete
"; if ($rw['replies']>0) $line = ""; else $line = ""; if ($rw['parent'] == 0) $date2="
".$date2." ".$rw['write_time']."
"; else $date2 = ""; $out.= "$line
".$rw['text'].$date2."
"; $out.= "
";*/ $tmas = split(":",$rw['write_time']); $time = $tmas[0].":".$tmas[1]; $dmas = split("-",$rw['write_date']); if ($dmas[0]>2000) $dmas[0]-=2000; $date = $dmas[2].".".$dmas[1].".".($dmas[0]>10?"":"0").$dmas[0]; $temp = str_replace("",$rw['title'],$temp); // $temp = str_replace("", $rw['term'], $temp); $temp = str_replace("", $rw['term_id'], $temp); $temp = str_replace("",$rw['text'],$temp); $temp = str_replace("", getUserName($rw['user_id']),$temp); $temp = str_replace("",$date,$temp); $temp = str_replace("",$time,$temp); $temp = str_replace("",$rw['id'],$temp); $temp = str_replace("", getUserInfo($rw['user_id']), $temp); $out.=$temp; return $span; } function printOnlyItem($rw) { global $out; $dmas = split("-",$rw['date']); $date = $dmas[2].".".$dmas[1].".".$dmas[0]; $date = $date." ".$rw['time']; $out.= "".$rw['title']."".$rw['term']."".$date."".$rw['replies'].""; } function get_user($id) { global $users; if ($users[$id]) return $users[$id]; else { $q = mysql_query_c("SELECT * FROM forum_auth WHERE id = $id"); return ($users[$id] = mysql_fetch_array($q)); } } function getUserInfo($id) { if ($id != 0) { $a = get_user($id); $name = $a["name"]; } else { $name = "Admin"; $id = 0; } $r = "
". "". ""; $q = mysql_query_c("SELECT count(*), MAX(write_date), MIN(write_date) FROM forum_texts WHERE user_id = $id"); // $q = mysql_query_c("SELECT user_msgs, last_date, join_date FROM forum_auth WHERE id = $id"); echo mysql_error(); if ($a = mysql_fetch_row($q)) { $dmas = split("-", $a[1]); if ($dmas[0]>2000) $dmas[0]-=2000; $datea = $dmas[2].".".$dmas[1].".".($dmas[0]>10?"":"0").$dmas[0]; $dmas = split("-", $a[2]); if ($dmas[0]>2000) $dmas[0]-=2000; $dateb = $dmas[2].".".$dmas[1].".".($dmas[0]>10?"":"0").$dmas[0]; $r .= "". "". ""; } $r .= "
$name
Сообщений ".$a[0]."
Последнее сообщение $datea
Первое сообщение $dateb
"; // $sql = "UPDATE forum_auth SET join_date = '".$a[2]."', last_date = '".$a[1]."', user_msgs = ".$a[0]." WHERE id = $id"; // mysql_query_c($sql); return $r; } function getUserName($id) { global $users; if ($id != 0) { $a = get_user($id); $name = $a["name"]; } else $name = "Admin"; return $name; } function getUserId($login, $cpwd) { $q = mysql_query_c("SELECT * FROM forum_auth WHERE login = '$login'"); if ($a = mysql_fetch_assoc($q)) if (crypt($a["pwd"]) == $cpwd) return $a["id"]; return -1; } function getTermId($n) { $q = mysql_query_c("SELECT id FROM forum_terms WHERE term = '$n'"); if ($a = mysql_fetch_assoc($q)) $id = $a["id"]; return $id; } function get_forum_text($tid,$id) { global $forum_texts; if ($forum_texts[$tid][$id]) return $forum_texts[$tid][$id]; $res = mysql_query_c("select * from forum_texts where term_id=".$tid." order by parent asc"); while ($rw = mysql_fetch_array($res)) { $rw[root] = $rw[parent]; if ($forum_texts[$rw[term_id]][$rw[parent]][root]) $rw[root] = $forum_texts[$rw[term_id]][$rw[parent]][root]; $forum_texts[$rw[term_id]][$rw[id]] = $rw; } return $forum_texts[$tid][$id]; } function getMsgParent($tid, $fid) { $a = get_forum_text($tid,$fid); if ($a[root]>0) return $a[root]; else return $a[id]; } function getLastMsgInfo($tid, $fid = 0) { global $users; $r = ""; if ($fid == 0) { $q = mysql_query_c("SELECT id, title, user_id, write_date, write_time FROM forum_texts WHERE term_id = $tid ORDER BY write_date DESC, write_time DESC LIMIT 1"); if ($a = mysql_fetch_assoc($q)) { $pid = getMsgParent($tid, $a["id"]); if ($pid > 0) { $tmas = split(":", $a["write_time"]); $time = $tmas[0].":".$tmas[1]; $dmas = split("-", $a["write_date"]); if ($dmas[0]>2000) $dmas[0]-=2000; $date = $dmas[2].".".$dmas[1].".".($dmas[0]>10?"":"0").$dmas[0]; $r = "".substr($a["title"], 0, 30).(strlen($a["title"]) > 30 ? "..." : "")."
". "$time $date
". "".getUserName($a["user_id"]).""; $users[$a["user_id"]]++; } } } else { echo ""; $aa = get_forum_text($tid,$fid); $pid = getMsgParent($tid, $fid); $a = get_forum_text($tid,$pid); $tmas = split(":", $a["write_time"]); $time = $tmas[0].":".$tmas[1]; $dmas = split("-", $a["write_date"]); if ($dmas[0]>2000) $dmas[0]-=2000; $date = $dmas[2].".".$dmas[1].".".($dmas[0]>10?"":"0").$dmas[0]; $r = "".substr($a["title"], 0, 30).(strlen($a["title"]) > 30 ? "..." : "")."
". "$time $date
". "".getUserName($a["user_id"]).""; $users[$a["user_id"]]++; } return $r; } ?>