Verified Commit 6f3233e8 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(public-forms) Make sure we have the right form and fix base

Make sure the data we loaded was for the same request URI to avoid
 showing the wrong form if another form was in session
Also tried to fix base selection when the object gets created

issue #5850
Showing with 31 additions and 10 deletions
+31 -10
......@@ -25,6 +25,26 @@ class publicFormPage extends standAlonePage
protected $invitation;
protected $template;
protected $done;
protected $request;
function __construct($interactive = TRUE)
{
parent::__construct($interactive);
$this->request = $_SERVER['REQUEST_URI'];
}
function init()
{
parent::init();
if ($_SERVER['REQUEST_URI'] != $this->request) {
/* Reset page if we’re called with a different token or form */
unset($this->form);
unset($this->registration);
unset($this->invitation);
unset($this->template);
$this->done = FALSE;
}
}
function readLdapConfig()
{
......@@ -138,15 +158,6 @@ class publicFormPage extends standAlonePage
['user' => ['base']]
);
/* TODO Remplir les champs depuis les headers HTTP */
/* Fill base depending on publicForm creation base and invitation base */
$base = $this->form['fdPublicFormCreationBase'];
if (isset($this->invitation)) {
$invitationBase = preg_replace('/'.preg_quote($config->current['BASE'], '/').'$/', '', dn2base($this->invitation['dn'], get_ou('invitationRDN')));
if (!empty($invitationBase)) {
$base = $invitationBase.','.$base;
}
}
$this->template->base = $base;
}
$this->template->save_object();
......@@ -154,8 +165,18 @@ class publicFormPage extends standAlonePage
if (isset($_POST['form_submit'])) {
// Save values for later
$values = $this->template->getValues();
// Apply the template and try to save the object
// Apply the template
$userTabObject = $this->template->apply();
/* Fill base depending on publicForm creation base and invitation base */
$base = $this->form['fdPublicFormCreationBase'];
if (isset($this->invitation)) {
$invitationBase = preg_replace('/'.preg_quote($config->current['BASE'], '/').'$/', '', dn2base($this->invitation['dn'], get_ou('invitationRDN')));
if (!empty($invitationBase)) {
$base = $invitationBase.','.$base;
}
}
$userTabObject->getBaseObject()->base = $base;
// Try to save the object
$errors = $userTabObject->save();
if (empty($errors)) {
$this->done = TRUE;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment