Commit 86d73c9d authored by dockx thibault's avatar dockx thibault
Browse files

Merge branch '6241-private-form-must-not-be-related-to-the-plugin-invitations-2' into 'dev'

Resolve "Private form must not be related to the plugin invitations"

See merge request fusiondirectory/fd-plugins!1008
Showing with 56 additions and 25 deletions
+56 -25
......@@ -79,13 +79,13 @@ class publicFormPage extends standAlonePage
$registrations = objects::ls(
'registration',
[
'dn' => 'raw',
'fdRegistrationEmailAddress' => 1,
'fdRegistrationInvitationDN' => 1,
'fdRegistrationState' => 1,
'dn' => 'raw',
'fdRegistrationEmailAddress' => 1,
'fdRegistrationInvitationDN' => 1,
'fdRegistrationState' => 1,
],
NULL,
'(fdRegistrationToken='.ldap_escape_f($_GET['token']).')'
'(fdRegistrationToken=' . ldap_escape_f($_GET['token']) . ')'
);
if (count($registrations) <= 0) {
throw new FusionDirectoryException(sprintf(_('Could not find any invitation matching token "%s"'), $_GET['token']));
......@@ -99,8 +99,8 @@ class publicFormPage extends standAlonePage
$invitations = objects::ls(
'invitation',
[
'dn' => 'raw',
'fdInvitationFormDN' => 1
'dn' => 'raw',
'fdInvitationFormDN' => 1
],
$this->registration['fdRegistrationInvitationDN'],
'', FALSE, 'base'
......@@ -151,7 +151,7 @@ class publicFormPage extends standAlonePage
'fdPublicFormAlteredAttributes' => '*',
],
NULL,
'(cn='.ldap_escape_f($_GET['form']).')'
'(cn=' . ldap_escape_f($_GET['form']) . ')'
);
$formName = $_GET['form'];
} else {
......@@ -180,15 +180,14 @@ class publicFormPage extends standAlonePage
}
}
protected function prepareTemplateObject ()
{
$this->template = new template($this->form['fdPublicFormTemplateType'], $this->form['fdPublicFormTemplateDN']);
$this->alteredAttributes = [[],[],[]];
$this->providedAttributes = [];
$this->alteredAttributes = [[], [], []];
$this->providedAttributes = [];
$this->providedMultiValueAttributes = [];
foreach ($this->form['fdPublicFormAlteredAttributes'] as $alteredAttribute) {
list($attribute, $mandatory, $readonly, $imported, $hidden) = explode('|', $alteredAttribute, 5);
......@@ -196,6 +195,9 @@ class publicFormPage extends standAlonePage
if ($mandatory) {
$this->alteredAttributes[0][$tab][] = $attribute;
}
if (isset($this->form['fdPublicFormPrivate']) && ($this->form['fdPublicFormPrivate'] == 'TRUE')) {
$this->prefill = TRUE;
}
if ($this->prefill) {
if ($readonly) {
$this->alteredAttributes[1][$tab][] = $attribute;
......@@ -256,27 +258,27 @@ class publicFormPage extends standAlonePage
// Save values for later
$values = $this->template->getValues();
// Apply the template
$userTabObject = $this->template->apply();
$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')));
$invitationBase = preg_replace('/,?' . preg_quote($config->current['BASE'], '/') . '$/', '', dn2base($this->invitation['dn'], get_ou('invitationRDN')));
if (!empty($invitationBase)) {
$base = $invitationBase.','.$base;
$base = $invitationBase . ',' . $base;
}
}
$userTabObject->getBaseObject()->base = $base;
// Try to save the object
$errors = $userTabObject->save();
$errors = $userTabObject->save();
if (empty($errors)) {
$this->done = TRUE;
if (isset($this->registration)) {
$tabObject = objects::open($this->registration['dn'], 'registration');
$tabObject = objects::open($this->registration['dn'], 'registration');
$baseObject = $tabObject->getBaseObject();
$baseObject->fdRegistrationUserDN = $userTabObject->dn;
$baseObject->fdRegistrationState = 'filled';
$baseObject->fdRegistrationLastChange = date('c').'|'.$ui->dn;
$baseObject->fdRegistrationUserDN = $userTabObject->dn;
$baseObject->fdRegistrationState = 'filled';
$baseObject->fdRegistrationLastChange = date('c') . '|' . $ui->dn;
$messages = $tabObject->save();
msg_dialog::displayChecks($messages);
......@@ -291,8 +293,37 @@ class publicFormPage extends standAlonePage
}
}
protected function getPrefilledValuesTest ($values = [])
{
if (isset($this->form['fdPublicFormPrivate']) && ($this->form['fdPublicFormPrivate'] == 'TRUE')) {
$this->prefill = TRUE;
}
if ($this->prefill) {
/* Fill fields from HTTP headers */
foreach ($this->providedAttributes as list($class, $attr)) {
if (isset($_SERVER['HTTP_AUTH_' . strtoupper($attr)])) {
if (!isset($values[$class])) {
$values[$class] = [];
}
if (in_array($attr, $this->providedMultiValueAttributes)) {
if (empty($_SERVER['HTTP_AUTH_' . strtoupper($attr)])) {
/* Avoid having an array with an empty string inside */
$values[$class][$attr] = [];
} else {
$values[$class][$attr] = explode('; ', $_SERVER['HTTP_AUTH_' . strtoupper($attr)]);
}
} else {
$values[$class][$attr] = $_SERVER['HTTP_AUTH_' . strtoupper($attr)];
}
}
}
}
return $values;
}
protected function getPrefilledValues ($values = [])
{
$values = $this->getPrefilledValuesTest();
if (isset($this->registration['fdRegistrationEmailAddress']) && !isset($values['mailAccount']['mail'])) {
/* Fill email field with target email if empty */
if (!isset($values['mailAccount'])) {
......@@ -320,7 +351,7 @@ class publicFormPage extends standAlonePage
try {
$this->fetchForm();
} catch (FusionDirectoryException $e) {
$this->done = TRUE;
$this->done = TRUE;
$this->errorMessage = $e->getMessage();
return;
}
......@@ -393,20 +424,20 @@ class publicFormPage extends standAlonePage
}
}
$smarty->assign('done', $this->done);
$smarty->assign('done', $this->done);
$smarty->assign('errorMessage', $this->errorMessage);
$smarty->assign('form', $this->form);
$smarty->append('css_files', get_template_path('login.css'));
$smarty->append('css_files', get_template_path('login.css'));
if (isset($this->form['fdPublicFormTitle'])) {
$smarty->assign('title', sprintf(_('Form - %s'), $this->form['fdPublicFormTitle']));
$smarty->assign('title', sprintf(_('Form - %s'), $this->form['fdPublicFormTitle']));
} else {
$smarty->assign('title', _('Form'));
$smarty->assign('title', _('Form'));
}
$smarty->display(get_template_path('headers.tpl'));
$smarty->assign('activated', $this->activated);
$smarty->assign('activated', $this->activated);
$smarty->display(get_template_path('public-form.tpl'));
}
}
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