page($id)) { if($page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane); $ariane[] = $page; return $ariane; } return false; } function pages($params = array()) { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; $enabled = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null; $user = isset($params["user"]) ? $params["user"] : null; $order_by = isset($params["order_by"]) ? $params["order_by"] : null; $order = isset($params["order"]) ? $params["order"] : "ASC"; $start = isset($params["start"]) ? $params["start"] : null; $max = isset($params["max"]) ? $params["max"] : null; $sgbd = $this->sgbd(); $pages = array("list" => array(), "total" => 0); $SELECT = "SELECT * FROM #--pages"; $COUNT_SELECT = "SELECT count(*) as n FROM #--pages"; $WHERE = ""; $WHERE .= (isset($id_parent) ? ($WHERE ? " AND" : " WHERE")." id_parent".(strlen($id_parent) > 0 ? "=".$this->eq($id_parent) : " IS NULL") : ""); $WHERE .= (isset($enabled) ? ($WHERE ? " AND" : " WHERE")." enabled=".$this->eq($enabled) : ""); $WHERE .= (isset($user) ? ($WHERE ? " AND" : " WHERE")." user_creation=".$this->eq($user) : ""); $ORDER_BY = ( isset($order_by) ? " ORDER BY ".$order_by.(isset($order) ? " ".$order : "") : "" ); $LIMIT = isset($max) ? " LIMIT ".$max.(isset($start) ? " OFFSET ".$start : "") : ""; $sql = $COUNT_SELECT.$WHERE; $rst = $sgbd->query($sql); if(!isset($rst)) return false; if($v_rst = $sgbd->fetch_assoc($rst)) $pages["total"] = $v_rst["n"]; $sgbd->free_result($rst); if($pages["total"]) { $sql = $SELECT.$WHERE.$ORDER_BY.$LIMIT; $rst = $sgbd->query($sql); if(!isset($rst)) return false; while($v_rst = $sgbd->fetch_assoc($rst)) $pages["list"][$v_rst["id"]] = $v_rst; $sgbd->free_result($rst); } return $pages; } function pages_arbo($params = array()) { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; $enabled = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null; $user = isset($params["user"]) ? $params["user"] : null; $order_by = isset($params["order_by"]) ? $params["order_by"] : null; $order = isset($params["order"]) ? $params["order"] : "ASC"; $sgbd = $this->sgbd(); $arbo = array(); if(isset($id_parent)) { if($parent = $this->page($id_parent)) $arbo = $parent; else return false; } $arbo["subs"] = array(); $SELECT = "SELECT id FROM #--pages"; $WHERE = ""; $WHERE .= ($WHERE ? " AND" : " WHERE")." id_parent".(isset($id_parent) && $id_parent ? "=".$this->eq($id_parent) : " IS NULL"); $WHERE .= (isset($enabled) ? ($WHERE ? " AND" : " WHERE")." enabled=".$this->eq($enabled) : ""); $WHERE .= (isset($user) ? ($WHERE ? " AND" : " WHERE")." user_creation=".$this->eq($user) : ""); $ORDER_BY = ( isset($order_by) ? " ORDER BY ".$order_by.(isset($order) ? " ".$order : "") : "" ); $sql = $SELECT.$WHERE.$ORDER_BY; $rst = $sgbd->query($sql); if(!isset($rst)) return false; while($v_rst = $sgbd->fetch_assoc($rst)) { $params["id_parent"] = $v_rst["id"]; $arbo["subs"][] = $this->pages_arbo($params); } $sgbd->free_result($rst); return $arbo; } function page($id) { $page = array(); $sgbd = $this->sgbd(); $sql = "SELECT * FROM #--pages WHERE id=".$this->eq($id); $rst = $sgbd->query($sql); if(!isset($rst)) return false; if($v_rst = $sgbd->fetch_assoc($rst)) $page = $v_rst; return $page; } function add_page($params) { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null; $title = isset($params["title"]) ? $params["title"] : null; $content = isset($params["content"]) ? $params["content"] : null; $user = isset($params["user"]) ? $params["user"] : null; $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : 1; $position = isset($params["position"]) ? $params["position"] : 0; $sgbd = $this->sgbd(); $sql = "INSERT INTO #--pages" ."(id_parent, title, content, date_creation, user_creation, date_last_update, user_last_update, enabled, position)" ." VALUES" ."( ".$this->eq($id_parent) .", ".$this->eq($title) .", ".$this->eq($content) .", '".date("Y-m-d H:i:s")."'" .", ".$this->eq($user) .", '".date("Y-m-d H:i:s")."'" .", ".$this->eq($user) .", ".$this->eq($enabled) .", ".$this->eq($position) .")"; if($sgbd->query($sql)) return $sgbd->insert_id(); return false; } function set_page($id, $params, $RAZ = false) { if($page = $this->page($id)) { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : ($RAZ ? null : $page["id_parent"]); $title = isset($params["title"]) ? $params["title"] : ($RAZ ? null : $page["title"]); $content = isset($params["content"]) ? $params["content"] : ($RAZ ? null : $page["content"]); $user = isset($params["user"]) ? $params["user"] : null; $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : ($RAZ ? 1 : $page["enabled"]); $position = isset($params["position"]) ? $params["position"] : ($RAZ ? 0 : $page["position"]); $sgbd = $this->sgbd(); $sql = "UPDATE #--pages SET" ." id_parent=".$this->eq($id_parent) .", title=".$this->eq($title) .", content=".$this->eq($content) .", date_last_update='".date("Y-m-d H:i:s")."'" .", user_last_update=".$this->eq($user) .", enabled=".$this->eq($enabled) .", position=".$this->eq($position) ." WHERE id=".$this->eq($id); if($sgbd->query($sql)) return true; } return false; } function del_page($id) { $sgbd = $this->sgbd(); if($sgbd->query("DELETE FROM #--pages WHERE id=".$this->eq($id))) { return $sgbd->query("UPDATE #--pages SET id_parent=NULL WHERE id_parent=".$this->eq($id)) ? true : false; } return false; } } ?>