From 93553cea371ce061dce9dfc34825b7b98a6ded34 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 26 Aug 2007 16:59:54 +0200 Subject: [PATCH] A nearly working version of the general page Signed-off-by: Florent Bruneau --- classes/plwizard.php | 6 ++- htdocs/css/keynote.css | 4 ++ modules/profile/general.inc.php | 45 ++++++++++++++++++-- modules/profile/page.inc.php | 90 ++++++++++++++++++++++++++++++--------- templates/core/plwizard.tpl | 3 ++ templates/profile/base.tpl | 9 ++-- templates/profile/general.tpl | 13 +++--- templates/skin/common.content.tpl | 2 + 8 files changed, 136 insertions(+), 36 deletions(-) diff --git a/classes/plwizard.php b/classes/plwizard.php index 23a47e1..b5affd1 100644 --- a/classes/plwizard.php +++ b/classes/plwizard.php @@ -148,8 +148,9 @@ class PlWizard $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) { @@ -201,6 +202,7 @@ class PlWizard $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); } } diff --git a/htdocs/css/keynote.css b/htdocs/css/keynote.css index 94fa8aa..1672ed6 100644 --- a/htdocs/css/keynote.css +++ b/htdocs/css/keynote.css @@ -101,6 +101,10 @@ p.smaller { background: inherit; } +input.error, textarea.error { + background-color: #faa; +} + h1 { background-color: inherit; margin: 0.5em 0 0.5em -8px; diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 7d5c873..115636c 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -22,7 +22,7 @@ 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} == ' '); } @@ -73,9 +73,46 @@ class ProfileGeneral extends ProfilePage 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) diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index f7e2f3e..aef1c62 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -43,15 +43,6 @@ abstract class ProfileNoSave implements ProfileSetting 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) @@ -76,7 +67,7 @@ class ProfileTel extends ProfileNoSave 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.'); @@ -85,12 +76,31 @@ class ProfileTel extends ProfileNoSave } } +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) @@ -100,10 +110,47 @@ abstract class ProfilePage implements PlWizardPage 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() @@ -115,15 +162,12 @@ abstract class ProfilePage implements PlWizardPage { 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() @@ -132,18 +176,24 @@ abstract class ProfilePage implements PlWizardPage $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; } diff --git a/templates/core/plwizard.tpl b/templates/core/plwizard.tpl index 1ea6727..138bc3f 100644 --- a/templates/core/plwizard.tpl +++ b/templates/core/plwizard.tpl @@ -33,6 +33,9 @@
+ {foreach from=$xorg_errors item=err} +
{$err|smarty:nodefaults}
+ {/foreach} {include file=$wiz_page}
diff --git a/templates/profile/base.tpl b/templates/profile/base.tpl index 765205f..6be0a17 100644 --- a/templates/profile/base.tpl +++ b/templates/profile/base.tpl @@ -20,13 +20,14 @@ {* *} {**************************************************************************} -
+
{include file=$profile_page}
-
- - +
+ + +
diff --git a/templates/profile/general.tpl b/templates/profile/general.tpl index b515d4d..38f7e43 100644 --- a/templates/profile/general.tpl +++ b/templates/profile/general.tpl @@ -50,7 +50,7 @@ - + @@ -59,7 +59,7 @@ - + @@ -256,7 +256,8 @@ Surnom - + @@ -294,7 +295,7 @@ + {if $errors.mobile}class="error"{/if} value="{$mobile}" /> @@ -320,7 +321,7 @@ + {if $errors.web}class="error"{/if} value="{$web}" /> @@ -348,7 +349,7 @@ {javascript name=ajax} - +
diff --git a/templates/skin/common.content.tpl b/templates/skin/common.content.tpl index 7f6ac58..ecf08f4 100644 --- a/templates/skin/common.content.tpl +++ b/templates/skin/common.content.tpl @@ -37,9 +37,11 @@ Nous conseillons très vivement d'utiliser des navigateurs récents, tels
{/if} +{if !$xorg_no_errors && !$xorg_failure} {foreach from=$xorg_errors item=err}
{$err|smarty:nodefaults}
{/foreach} +{/if} {if !$xorg_failure && $xorg_tpl}{include file=$xorg_tpl}{/if} -- 2.1.4