page($id)){ if(isset($page["id_parent"]) && $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); $res = array(); if($rst = $sgbd->open_data("pages")){ while($v_rst = $sgbd->fetch_data($rst)){ if(isset($v_rst)) $res[$v_rst["id"]] = $v_rst; else{ $res = false; break; } } $sgbd->close_data($rst); if($res !== false){ if(isset($order_by)) $res = $this->ordonne($res, "position", isset($order) ? $order : "ASC"); foreach($res as $id_res => $v_rst){ $MATCH = true; if(isset($id_parent)){ $MATCH = ( ($id_parent && isset($v_rst["id_parent"]) && ($id_parent == $v_rst["id_parent"])) || ($id_parent == "" && (!isset($v_rst["id_parent"]) || !$v_rst["id_parent"])) ); } if($MATCH){ if(isset($enabled)){ $MATCH = ($v_rst["enabled"] == $enabled); } } if($MATCH){ if(isset($user)){ $MATCH = ($v_rst["user_creation"] == $user); } } if($MATCH){ $pages["total"]++; $MATCH = !isset($start) || !$max || ($pages["total"] > $start && $pages["total"] <= ($start + $max)); } if($MATCH) $pages["list"][$v_rst["id"]] = $v_rst; } } } else return false; return $pages; } function pages_arbo($params = array()){ $params["id_parent"] = isset($params["id_parent"]) ? $params["id_parent"] : ""; $params["enabled"] = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null; $params["user"] = isset($params["user"]) ? $params["user"] : null; $params["order_by"] = isset($params["order_by"]) ? $params["order_by"] : null; $params["order"] = isset($params["order"]) ? $params["order"] : "ASC"; $sgbd = $this->sgbd(); $arbo = array(); if($params["id_parent"]){ if($parent = $this->page($params["id_parent"])) $arbo = $parent; else return false; } $arbo["subs"] = array(); if(($subs = $this->pages($params)) !== false){ foreach($subs["list"] as $id_sub => $sub){ $params["id_parent"] = $sub["id"]; $arbo["subs"][] = $this->pages_arbo($params); } } return $arbo; } function page($id){ $sgbd = $this->sgbd(); return ($page = $sgbd->get_data("pages", $id)) ? $page : false; } 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(); return ( ( $id_page = $sgbd->add_data( "pages", array ( "id_parent" => $id_parent, "title" => $title, "content" => $content, "date_creation" => date("Y-m-d H:i:s"), "user_creation" => $user, "date_last_update" => date("Y-m-d H:i:s"), "user_last_update" => $user, "enabled" => $enabled, "position" => $position ) ) ) ? $id_page : false ); } function set_page($id, $params, $RAZ = false){ if($page = $this->page($id)){ $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : ($RAZ ? null : (isset($page["id_parent"]) ? $page["id_parent"] : null)); $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(); return $sgbd->set_data( "pages", $id, array( "id_parent" => $id_parent, "title" => $title, "content" => $content, "date_creation" => $page["date_creation"], "user_creation" => $page["user_creation"], "date_last_update" => date("Y-m-d H:i:s"), "user_last_update" => $user, "enabled" => $enabled, "position" => $position ) ); } return false; } function del_page($id){ $sgbd = $this->sgbd(); if($sgbd->del_data("pages", $id)){ $OK = true; if($rst = $sgbd->open_data("pages")){ while($v_rst = $sgbd->fetch_data($rst)){ if(isset($v_rst)){ if(isset($v_rst["id_parent"]) && isset($v_rst["id"]) && $v_rst["id_parent"] == $id){ unset($v_rst["id_parent"]); if(!$sgbd->set_data("pages", $v_rst["id"], $v_rst)){ $OK = false; break; } } } else $OK = false; } $sgbd->close_data($rst); } return $OK; } return false; } } ?>