routeSQL : Redirection are now compatible with chained mode

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2025 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-03-13 13:10:23 +00:00
parent 156cf358ac
commit 37f0159ae8

View File

@@ -276,9 +276,10 @@ class routeSQL
/** Add HTML routes */
$route = new route ();
$route->allowSlashes=false;
$route->get ($this->url_prefix."/", function () use ($route)
$route->get ($this->url_prefix."/", function ($chain) use ($route)
{
$route->redirect ("/".$this->url_prefix, "");
$route->redirect ("/".str_replace ("{chain}", $chain, $this->url_prefix),
"");
});
$route->get ($this->url_prefix.
@@ -365,16 +366,16 @@ class routeSQL
}
$nbentries = count ($datas);
if ($num > 1000)
$route->redirect ("/".$this->url_prefix.
"?page=$page&num=1000&search=$search", "");
$route->redirect ("/".str_replace ("{chain}", $chain, $this->url_prefix)
."?page=$page&num=1000&search=$search", "");
if ($page < 1)
$route->redirect ("/".$this->url_prefix.
"?page=1&num=$num&search=$search", "");
$route->redirect ("/".str_replace ("{chain}", $chain, $this->url_prefix)
. "?page=1&num=$num&search=$search", "");
// Push on the last page if the values are too high
if ($nbentries > 0 && ($page-1)*$num > $nbentries)
{
$maxPage = intval ($nbentries/$num)+1;
$route->redirect ("/".$this->url_prefix.
$route->redirect ("/".str_replace("{chain}", $chain, $this->url_prefix).
"?page=$maxPage&num=$num&search=$search", "");
}
@@ -553,12 +554,16 @@ echo $content;
{
$csrf->checkToken ($token);
$this->objectDB->delete ($id);
$route->redirect ("/".$this->url_prefix, "");
$route->redirect ("/".
str_replace ("{chain}", $chain, $this->url_prefix),
"");
}
catch (Exception $e)
{
$renderer->flash ("ERROR", $e->getMessage());
$route->redirect ("/".$this->url_prefix, "");
$route->redirect ("/".
str_replace ("{chain}", $chain, $this->url_prefix),
"");
}
@@ -644,6 +649,11 @@ echo $content;
$field->mandatory = true;
if (in_array ("autoincrement", $this->objectDB->fields[$key]))
$field->type = "hidden";
if ($key === $this->chainedForeign)
{
$field->defaults = $chain;
$field->readonly = true;
}
$fields[] = $field;
unset ($field);
}
@@ -694,7 +704,9 @@ echo $content;
$this->objectDB->insert ($values);
$renderer = new renderer ();
$renderer->flash ("SUCCESS", _("Creation done"));
$route->redirect ("/".$this->url_prefix, "");
$route->redirect ("/".
str_replace ("{chain}", $chain, $this->url_prefix),
"");
}
catch (Exception $e)
{
@@ -712,7 +724,8 @@ echo $content;
// corrected
$_SESSION["domframework"]["routeSQL"]["errors"] = $errors;
$_SESSION["domframework"]["routeSQL"]["values"] = $values;
$route->redirect ("/".$this->url_prefix."/add", "");
$route->redirect ("/".str_replace("{chain}", $chain, $this->url_prefix).
"/add", "");
});
@@ -801,6 +814,11 @@ echo $content;
$field->type = "hidden";
if ($readonly === true || $this->readwriteAllowed === false)
$field->readonly = true;
if ($key === $this->chainedForeign)
{
$field->defaults = $chain;
$field->readonly = true;
}
$fields[] = $field;
unset ($field);
}
@@ -854,15 +872,24 @@ echo $content;
if ($values[$this->objectDB->primary] !== $id)
throw new Exception (dgettext("domframework",
"Can not change the primary key"), 403);
$errorsChain = array ();
if ($this->chainedForeign !== null &&
$values[$this->chainedForeign] !== $chain)
$errorsChain[$this->chainedForeign] =
array ("error", dgettext("domframework",
"Can not change the external key"));
$errors = $this->objectDB->verify ($values, $id);
if (count ($errors) == 0)
if (count ($errors) == 0 && count ($errorsChain) == 0)
{
try
{
$this->objectDB->update ($id, $values);
$renderer = new renderer ();
$renderer->flash ("SUCCESS", _("Update done"));
$route->redirect ("/".$this->url_prefix, "");
$route->redirect ("/".
str_replace ("{chain}", $chain, $this->url_prefix),
"");
}
catch (Exception $e)
{
@@ -875,12 +902,15 @@ echo $content;
$renderer = new renderer ();
foreach ($errors as $error)
$renderer->flash (strtoupper ($error[0]), $error[1]);
foreach ($errorsChain as $error)
$renderer->flash (strtoupper ($error[0]), $error[1]);
}
// If errors : save them and redirect to the page of editing to be
// corrected
$_SESSION["domframework"]["routeSQL"]["errors"] = $errors;
$_SESSION["domframework"]["routeSQL"]["values"] = $values;
$route->redirect ("/".$this->url_prefix."/$id", "");
$route->redirect ("/".str_replace ("{chain}", $chain, $this->url_prefix).
"/$id", "");
});
}