getAll($SQL); $SQL = "SELECT count(*) FROM atraf_vitamin WHERE parent_id=0"; $tpl->assign("nopages", floor($dbh->getOne($SQL)/THREADS_PER_PAGE)); $tpl->assign("currentpage", $tpl->_tpl_vars["nopages"] - $skip); $tpl->assign("skip", $skip); $startpagelist = $tpl->_tpl_vars["currentpage"] + 5; if ($startpagelist > $tpl->_tpl_vars["nopages"]) $startpagelist=$tpl->_tpl_vars["nopages"]; $tpl->assign("startpagelist", $startpagelist); for ($i=$startpagelist; $i>$startpagelist-11; $i--) $pagelist[] = $i; $tpl->assign("pagelist", $pagelist); // return an array of parent and all his kids, and do it recursively function parentandchildren($parent) { global $dbh; $out[] = $parent; $SQL = "SELECT * FROM atraf_vitamin WHERE parent_id=".$parent["msg_id"].""; foreach ($dbh->getAll($SQL) as $child) $out = array_merge($out, parentandchildren($child)); return $out; } $threads = array(); foreach ($threadlist as $t) $threads = array_merge($threads, parentandchildren($t)); /* $threads = array(); foreach ($threadlist as $thread) { $t = $thread["thread_id"]; $SQL = "SELECT * FROM atraf_vitamin WHERE thread_id=$t ORDER BY msg_id"; $threads = array_merge($threads, $dbh->getAll($SQL)); } */ /* old code to display in PHP */ /* $hier=array(); $last_id=0; $last_parent=-1; foreach ($threads as $t) { // take care of hierarchy stuff if ($t["parent_id"] != $last_parent) if ($t["parent_id"] == $last_id) { $last_parent = $t["parent_id"]; echo ""; } $last_parent = $t["parent_id"]; } // use the right atraf icon if ($t["parent_id"]==0) $icon="origMsg"; elseif ($t["content"]=="") $icon="emptyMsg"; else $icon="MsgReply"; // echo "
  • msg_id:" . $t["msg_id"] . " parent_id:".$t["parent_id"] ." ".$t["subject"] . "
  • \n"; echo " ".$t["subject"] . "
    \n"; $last_id = $t["msg_id"]; } */ function ago($then, $now=0) { if (!$now) $now=time(); $diff = $now - $then - 60*60*date("G",0); // timezone correction, back to GMT list($months,$days,$hours,$minutes) = sscanf(date("m d G i", $diff), "%d %d %d %d"); foreach(array('months','days') as $what) $$what--; // echo "months:$months days:$days hours:$hours minutes:$minutes"; $out = "לפני "; if ($months) $out .= ($months>1?"$months חודשים":"חודש"); elseif ($days) $out .= ($days>1?"$days ימים":"יום"); elseif ($hours) $out .= ($hours>1?"$hours שעות":"שעה"); elseif ($minutes) $out .= ($minutes>1?"$minutes דקות":"דקה"); else $out .= "פחות מדקה"; return $out . ""; } //echo ago(time()-60*60*24*1); exit; if (isset($_REQUEST["update"])) { setcookie("from_time", $_COOKIE["update_time"], time()+60*60*24*30); setcookie("from_msgid", $_COOKIE["update_msgid"], time()+60*60*24*30); $_COOKIE["from_time"] = $_COOKIE["update_time"]; $_COOKIE["from_msgid"] = $_COOKIE["update_msgid"]; setcookie("update_time", time(), time()+60*60*24*30); $_COOKIE["update_time"] = time(); setcookie("update_msgid", $dbh->getOne("select max(msg_id) from atraf_vitamin")); } if (isset($_COOKIE["from_msgid"])) { $from_msgid = $_COOKIE["from_msgid"]; $tpl->assign("ago", ago($_COOKIE["from_time"])); } else { $SQL = "SELECT msg_id FROM atraf_vitamin WHERE ctime < date_sub(now(),interval 1 day) ORDER BY ctime desc LIMIT 1"; $from_msgid = $dbh->getOne($SQL); setcookie("update_time", time(), time()+60*60*24*30); setcookie("update_msgid", $dbh->getOne("select max(msg_id) from atraf_vitamin")); } $tpl->assign("from_msgid", $from_msgid); //$tpl->assign("update_time", isset($_COOKIE["update_time"]) ? $_COOKIE["update_time"] : time()); //$new_messages=0; foreach ($threads as $id => $t) { if ($t["parent_id"]==0) { $icon="origMsg"; $icon_alt="הודעה מקורית"; } elseif ($t["content"]=="") $icon="emptyMsg"; else $icon="MsgReply"; $threads[$id]["icon"] = $icon; if ($t["attach"]) $threads[$id]["fileext"] = strtoupper(substr($t["href"], -3, 3)); //$threads[$id]["content"] = preg_replace("/
    /","

    ",$t["content"]); $threads[$id]["level"]++; if ($t["msg_id"] > $from_msgid) { // $new_messages++; // $last_new_message = $t["msg_id"]; } } $tpl->assign("local", "http://" . $_SERVER["HTTP_HOST"] . "/"); $tpl->assign("threads", $threads); //$tpl->assign("new_messages", $new_messages); //$tpl->assign("last_new_message", $last_new_message); $tpl->assign("new_messages", $dbh->getOne("SELECT count(*) FROM atraf_vitamin WHERE msg_id > '" . $from_msgid . "'")); $tpl->assign("last_new_message", $dbh->getOne("SELECT max(msg_id) as mid FROM atraf_vitamin WHERE msg_id > '$from_msgid' GROUP BY thread_id ORDER BY mid ASC LIMIT 1")); tpl_display(); ?>