$oldpage = $curpage;
// Process the previous page
- if (!is_null($curpage)) {
- $page = $this->getPage($curpage);
+ if (Post::has('valid_page')) {
+ $page = $this->getPage(Post::i('valid_page'));
+ $curpage = Post::i('valid_page');
$next = $page->process();
$last = $curpage;
switch ($next) {
$smarty->assign('wiz_baseurl', $baseurl);
$smarty->assign('tab_width', (int)(99 / count($this->pages)));
$smarty->assign('wiz_page', $page->template());
+ $smarty->assign('xorg_no_errors', true);
$page->prepare($smarty);
}
}
background: inherit;
}
+input.error, textarea.error {
+ background-color: #faa;
+}
+
h1 {
background-color: inherit;
margin: 0.5em 0 0.5em -8px;
class ProfileNom implements ProfileSetting
{
private function matchWord($old, $new, $newLen) {
- return ($i = strpos($ancien, $nouveau)) !== false
+ return ($i = strpos($old, $new)) !== false
&& ($i == 0 || $old{$i-1} == ' ')
&& ($i + $newLen == strlen($old) || $old{$i + $newLen} == ' ');
}
parent::__construct($wiz);
$this->settings['nom'] = $this->settings['prenom']
= new ProfileNom();
- $this->settings['promo'] = $this->settings['promo_sortie']
- = $this->settings['nom_usage']
- = new ProfileFixed();
+ $this->settings['mobile_pub']
+ = $this->settings['web_pub']
+ = $this->settings['freetext_pub']
+ = new ProfilePub();
+ $this->settings['freetext']
+ = $this->settings['appli_id1']
+ = $this->settings['appli_id2']
+ = $this->settings['nick']
+ = null;
+ $this->settings['mobile'] = new ProfileTel();
+ $this->settings['web'] = new ProfileWeb();
+ }
+
+ protected function fetchData()
+ {
+ if (count($this->orig) > 0) {
+ $this->values = $this->orig;
+ return;
+ }
+ $res = XDB::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite,
+ q.profile_mobile as mobile, q.profile_mobile_pub as mobile_pub,
+ q.profile_web as web, q.profile_web_pub as web_pub,
+ q.profile_freetext as freetext, q.profile_freetext_pub as freetext_pub,
+ q.profile_nick as nick, q.profile_from_ax, u.matricule_ax,
+ IF(a1.aid IS NULL, -1, a1.aid) as appli_id1, a1.type as appli_type1,
+ IF(a2.aid IS NULL, -1, a2.aid) as appli_id2, a2.type as appli_type2
+ FROM auth_user_md5 AS u
+ INNER JOIN auth_user_quick AS q USING(user_id)
+ LEFT JOIN applis_ins AS a1 ON(a1.uid = u.user_id and a1.ordre = 0)
+ LEFT JOIN applis_ins AS a2 ON(a2.uid = u.user_id and a2.ordre = 1)
+ WHERE u.user_id = {?}", S::v('uid', -1));
+ $this->values = $res->fetchOneAssoc();
+ parent::fetchData();
+ }
+
+ protected function saveData()
+ {
+ parent::saveData();
+ XDB::execute("UPDATE auth_user_md5 SET nom={?}, prenom={?} WHERE user_id = {?}",
+ $this->values['nom'], $this->values['prenom'], S::v('uid'));
}
public function prepare(PlatalPage &$page)
public function save(ProfilePage &$page, $field, $new_value) { }
}
-class ProfileFixed extends ProfileNoSave
-{
- public function value(ProfilePage &$page, $field, $value, &$success)
- {
- $success = true;
- return isset($page->values[$field]) ? $page->values[$field] : S::v($field);
- }
-}
-
class ProfileWeb extends ProfileNoSave
{
public function value(ProfilePage &$page, $field, $value, &$success)
if (is_null($value)) {
return isset($page->values[$field]) ? $page->values[$field] : S::v($field);
}
- $success = strlen(strtok($value, '<>{}@&#~\/:;?,!§*_`[]|%$^=')) < strlen($value);
+ $success = strlen(strtok($value, '<>{}@&#~\/:;?,!§*_`[]|%$^=')) == strlen($value);
if (!$success) {
global $page;
$page->trig('Le numéro de téléphone contient un caractère interdit.');
}
}
+class ProfilePub extends ProfileNoSave
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $success = true;
+ if (is_null($value)) {
+ return isset($page->values[$field]) ? $page->values[$field] : S::v($field);
+ }
+ if (is_null($value) || !$value) {
+ $value = 'private';
+ } else if ($value == 'on') { // Checkbox
+ $value = 'public';
+ }
+ return $value;
+ }
+}
+
abstract class ProfilePage implements PlWizardPage
{
protected $wizard;
protected $pg_template;
protected $settings = array(); // A set ProfileSetting objects
+ protected $errors = array(); // A set of boolean with the value check errors
+ public $orig = array();
public $values = array();
public function __construct(PlWizard &$wiz)
protected function fetchData()
{
+ if (count($this->orig) > 0) {
+ $this->values = $this->orig;
+ return;
+ }
+ foreach ($this->settings as $field=>&$setting) {
+ $success = false;
+ if (!is_null($setting)) {
+ $this->values[$field] = $setting->value($this, $field, null, $success);
+ } else if (!isset($this->values[$field])) {
+ $this->values[$field] = S::v($field);
+ }
+ $this->errors[$field] = false;
+ }
+ $this->orig = $this->values;
}
protected function saveData()
{
+ foreach ($this->settings as $field=>&$setting) {
+ if (!is_null($setting)) {
+ $setting->save($this, $field, $this->values[$field]);
+ }
+ }
+ }
+
+ protected function checkChanges()
+ {
+ $newvalues = $this->values;
+ $this->values = array();
+ $this->fetchData();
+ $this->values = $newvalues;
+ foreach ($this->settings as $field=>&$setting) {
+ if ($this->orig[$field] != $this->values[$field]) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected function markChange()
+ {
}
public function template()
{
if (count($this->values) == 0) {
$this->fetchData();
- foreach ($this->settings as $field=>&$setting) {
- $success = false;
- $this->values[$field] = $setting->value($this, $field, null, $success);
- }
}
foreach ($this->values as $field=>&$value) {
$page->assign($field, $value);
}
$page->assign('profile_page', $this->pg_template);
+ $page->assign('errors', $this->errors);
}
public function process()
$this->fetchData();
foreach ($this->settings as $field=>&$setting) {
$success = false;
- $this->values[$field] = $setting->value($this, $field, Post::v($field), $success);
+ if (!is_null($setting)) {
+ $this->values[$field] = $setting->value($this, $field, Post::v($field), $success);
+ } else {
+ $success = true;
+ $this->values[$field] = Post::v($field);
+ }
+ $this->errors[$field] = !$success;
$global_success = $global_success && $success;
}
if ($global_success) {
- foreach ($this->settings as $field=>&$setting) {
- $setting->save($this, $field, $this->values[$field]);
+ if ($this->checkChanges()) {
+ $this->saveData();
+ $this->markChange();
}
- $this->saveData();
- return Post::has('valid_and_next') ? PlWizard::NEXT_PAGE : PlWizard::CURRENT_PAGE;
+ return Post::has('next_page') ? PlWizard::NEXT_PAGE : PlWizard::CURRENT_PAGE;
}
global $page;
- $page->trig("Certains champs n'ont pas pu être validés, merci de corriger les infos "
+ $page->trig("Certains champs n'ont pas pu être validés, merci de corriger les informations "
. "de ton profil et de revalider ta demande");
return PlWizard::CURRENT_PAGE;
}
<div style="clear: both"></div>
</div>
<div class="wiz_content" style="clear: both" class="center">
+ {foreach from=$xorg_errors item=err}
+ <div class="erreur">{$err|smarty:nodefaults}</div>
+ {/foreach}
{include file=$wiz_page}
</div>
</div>
{* *}
{**************************************************************************}
-<form action="{$wiz_baseurl}/{$lookup[$current]}" method="post">
+<form action="{$wiz_baseurl}/{$lookup[$current]}" method="post" id="prof_annu">
<div>
{include file=$profile_page}
</div>
- <div style="clear: both">
- <input type="submit" name="valid" value="Valider les modifications" />
- <input type="submit" name="valid_and_next" value="Valider et passer à la page suivante" />
+ <div style="clear: both" class="center">
+ <input type="hidden" name="valid_page" value="{$current}" />
+ <input type="submit" name="current_page" value="Valider les modifications" />
+ <input type="submit" name="next_page" value="Valider et passer à la page suivante" />
</div>
</form>
<span class="comm"></span>
</td>
<td class="cold">
- <input type='text' name='nom' value="{$nom}" />
+ <input type='text' name='nom' {if $errors.nom}class="error"{/if} value="{$nom}" />
</td>
</tr>
<tr>
<span class="comm"></span>
</td>
<td class="cold">
- <input type='text' name='prenom' value="{$prenom}" />
+ <input type='text' name='prenom' {if $errors.prenom}class="error"{/if} value="{$prenom}" />
</td>
</tr>
<tr>
<span class="titre">Surnom</span>
</td>
<td class="cold">
- <input type="text" size="35" maxlength="64" name="nickname" value="{$nickname}" />
+ <input type="text" size="35" maxlength="64"
+ {if $errors.nick}class="error"{/if} name="nick" value="{$nick}" />
</td>
</tr>
<tr>
</td>
<td class="cold">
<input type="text" size="18" maxlength="18" name="mobile"
- value="{$mobile}" />
+ {if $errors.mobile}class="error"{/if} value="{$mobile}" />
</td>
</tr>
<tr>
</td>
<td class="dcold">
<input type="text" size="35" maxlength="95" name="web"
- value="{$web}" />
+ {if $errors.web}class="error"{/if} value="{$web}" />
</td>
</tr>
<tr>
<td class="dcold">
{javascript name=ajax}
<div id="ft_preview" style="display: none"></div>
- <textarea name="freetext" id="freetext" rows="3" cols="29" >{$freetext}</textarea>
+ <textarea name="freetext" {if $errors.mobile}class="error"{/if} id="freetext" rows="3" cols="29" >{$freetext}</textarea>
<br/>
<span class="smaller">
<a href="wiki_help/notitle" class="popup3">
<br />
{/if}
+{if !$xorg_no_errors && !$xorg_failure}
{foreach from=$xorg_errors item=err}
<div class="erreur">{$err|smarty:nodefaults}</div>
{/foreach}
+{/if}
{if !$xorg_failure && $xorg_tpl}{include file=$xorg_tpl}{/if}