diff --git a/routeSQL.php b/routeSQL.php index 278432f..62b609c 100644 --- a/routeSQL.php +++ b/routeSQL.php @@ -23,6 +23,8 @@ class routeSQL public $textDelete = ""; /** The Text to Edit */ public $textEdit = ""; + /** enable internal CSS */ + public $enableInternalCSS = true; /** The model file containing the database description */ private $model_file = ""; /** The model class included in the model file */ @@ -100,37 +102,104 @@ class routeSQL $nbentries is the total number of elements num is the number of elements displayed by page page is the page to display */ - private function paginator ($nbentries, $page, $num) + private function paginator ($nbentries, $page, $num, $search) { // The maximum of links available in the paginator $maxClickPaginator = 10; $prePage = false; $postPage = false; - $content = "
"; + $content = "
\n"; $displayedNumbers = 0; for ($i = 1 ; $i < ($nbentries/$num) ; $i++) { if ($i < ($page - $maxClickPaginator/2)) { if ($prePage === false) - $content .= "... "; + $content .= " ...\n"; $prePage = true; continue; } if ($displayedNumbers >= $maxClickPaginator) { if ($postPage === false) - $content .= "... "; + $content .= " ...\n"; $postPage = true; continue; } $displayedNumbers++; - $content .= "url_prefix. + "?page=$i&num=$num&search=".urlencode ($search)."'"; if ($page == $i) - $content .= "style='background-color:#FFFF66;'"; - $content .= ">$i "; + $content .= " class='selected'"; + $content .= ">$i\n"; } - $content .= "
"; + if ($displayedNumbers === 0) + { + $i = 1; + $content .= " displayActions) + { + $route = new route (); + $content .= "
\n"; + $content .= " " + .dgettext("domframework","Add new entry")."\n"; + $content .= "
\n"; + } + return $content; + } + + /** Display the select list to choose the number of displayed entries */ + private function listNumberDisplayedEntries ($num) + { + $route = new route (); + $content = ""; + $content .= "
\n"; + $content .= "
\n"; + $content .= " \n"; + $content .= "
\n"; + $content .= "
\n"; return $content; } @@ -144,8 +213,8 @@ class routeSQL $route->redirect ("/".$this->url_prefix, ""); }); - $route->get ($this->url_prefix."(\?({p1}={v1})(&{p2}={v2})?)?", - function ($p1, $v1, $p2, $v2) use ($route) + $route->get ($this->url_prefix."(\?({p1}={v1})(&{p2}={v2}(&{p3}={v3})?)?)?", + function ($p1, $v1, $p2, $v2, $p3, $v3) use ($route) { // LIST ALL THE OBJECTS OF THE TABLE // num is the number of elements displayed by page @@ -153,47 +222,104 @@ class routeSQL // Allow the parameters to be sent in any order if ($p1 === "num") $num = $v1; if ($p2 === "num") $num = $v2; + if ($p3 === "num") $num = $v3; if ($p1 === "page") $page = $v1; if ($p2 === "page") $page = $v2; + if ($p3 === "page") $page = $v3; + if ($p1 === "search") $search = $v1; + if ($p2 === "search") $search = $v2; + if ($p3 === "search") $search = $v3; + if (!isset ($num) || $num === null || $num === "") $num = 10; + if (!isset ($page) || $page === null || $page === "") $page = 1; + if (!isset ($search) || $search === null || $search === "") $search = ""; + $page = intval ($page); + $num = intval ($num); + $search = rawurldecode ($search); + //echo "PAGE=$page\n"; + //echo "NUM=$num\n"; + //echo "SEARCH=$search\n"; + //$route->debug=1; $this->connect(); $csrf = new csrf (); $token = $csrf->createToken (); - $datas = $this->objectDB->read (); $titles = $this->objectDB->titles (); - if (!isset ($page) || $page === null || $page === "") $page = 1; - if (!isset ($num) || $num === null || $num === "") $num = 10; - $page = intval ($page); - $num = intval ($num); + if ($search === "") + $datas = $this->objectDB->read (); + else + { + $criteria = array (); + foreach (array_keys($titles) as $column) + $criteria[] = array ($column, "%$search%", "LIKE"); + $datas = $this->objectDB->read ($criteria, null, null, true); + } if ($num > 1000) - $route->redirect ("/".$this->url_prefix."?page=$page&num=1000", ""); + $route->redirect ("/".$this->url_prefix. + "?page=$page&num=1000&search=$search", ""); if ($page < 1) - $route->redirect ("/".$this->url_prefix."?page=1&num=$num", ""); + $route->redirect ("/".$this->url_prefix. + "?page=1&num=$num&search=$search", ""); // Push on the last page if the values are too high - if ($page*$num > count ($datas)) + if (count ($datas) > 0 && ($page-1)*$num > count ($datas)) { $maxPage = intval(count ($datas)/$num); - $route->redirect ("/".$this->url_prefix."?page=$maxPage&num=$num", ""); + $route->redirect ("/".$this->url_prefix. + "?page=$maxPage&num=$num&search=$search", ""); } - - $content = "
\n"; + + $content = ""; + // Internal CSS + if ($this->enableInternalCSS === true) + { + $content .= "\n"; + } + + $content .= "
\n"; $content .= $this->showflash (); - if ($this->displayActions) - $content .= "". - dgettext("domframework","Add new entry")."\n"; - $content .= $this->paginator(count ($datas), $page, $num); - $content .= "\n"; - $content .= " \n"; + $content .= "
\n"; + $content .= $this->externalActions (); + $content .= $this->listNumberDisplayedEntries ($num); + $content .= $this->paginator(count ($datas), $page, $num, $search); + $content .= $this->searchArea ($search); + $content .= "
\n"; // End of topBar + $content .= "
\n"; + $content .= " \n"; if ($this->displayActions && $this->actionsAtEnd === false) - $content .= " \n"; + $content .= " \n"; foreach ($titles as $title) - $content .= " \n"; + $content .= " \n"; if ($this->displayActions && $this->actionsAtEnd !== false) - $content .= " \n"; - $content .= " \n"; - $content .= " \n"; + $content .= " \n"; + $content .= " \n"; + $content .= " \n"; if (count ($datas) === 0) { - $content .= " \n"; } @@ -208,14 +334,19 @@ class routeSQL $i++; continue; } - $content .= " "; + $content .= " "; if ($odd === "odd") $odd = "even"; else $odd = "odd"; - if ($this->displayActions && $this->actionsAtEnd === false) + if ($this->actionsAtEnd !== false) { - $content .= ""; + } + if ($this->displayActions) + { + $content .= ""; } - foreach ($line as $col) - $content .= ""; - if ($this->displayActions && $this->actionsAtEnd !== false) + if ($this->actionsAtEnd === false) { - $content .= ""; + foreach ($line as $col) + $content .= ""; } $content .= "\n"; $i++; } } - $content .= " \n"; - $content .= "
".dgettext("domframework","Actions")."".dgettext("domframework","Actions")."".htmlentities ($title)."".htmlentities ($title)."".dgettext("domframework","Actions")."
".dgettext("domframework","Actions")."
"; + // Add one column more for actions + $count = count($titles); + if ($this->displayActions) + $count++; + $content .= "
"; $content .= dgettext("domframework","No entry available"); $content .= "
"; + foreach ($line as $col) + $content .= "".htmlentities ($col).""; $content .= " ". + $line[$this->objectDB->primary]."' class='edit'>". $this->textEdit.""; $content .= " textDelete.""; + $content .= "class='delete'>".$this->textDelete.""; $content .= "".htmlentities ($col).""; - $content .= " ". - $this->textEdit.""; - $content .= " deleteConfirm) - $content .= " onclick=\"return confirm('". - dgettext("domframework", - "Are you sure to delete this entry?")."')\""; - $content .= ">".$this->textDelete.""; - $content .= "".htmlentities ($col)."
\n"; + $content .= " \n"; + $content .= " \n"; + $content .= "
\n"; + $content .= $this->externalActions (); + $content .= $this->listNumberDisplayedEntries ($num); + $content .= $this->paginator(count ($datas), $page, $num, $search); + $content .= $this->searchArea ($search); + $content .= "
\n"; // End of bottomBar $content .= "
\n"; echo $content; });