First version of the addresses page
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 27 Aug 2007 15:32:54 +0000 (17:32 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 27 Aug 2007 15:32:54 +0000 (17:32 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
htdocs/css/keynote.css
modules/profile.php
modules/profile/addresses.inc.php [new file with mode: 0644]
modules/profile/page.inc.php
modules/profile/tabs.inc.php [deleted file]
templates/core/plwizard.tpl
templates/geoloc/form.address.tpl
templates/include/flags.radio.tpl
templates/profile/adresses.tpl

index 1672ed6..deac8c4 100644 (file)
@@ -105,6 +105,14 @@ input.error, textarea.error {
     background-color: #faa;
 }
 
+input.valid, textarea.valid {
+    background-color: #afa;
+}
+
+input.warning, textarea.warning {
+    background-color: #fda;
+}
+
 h1 {
     background-color: inherit;
     margin: 0.5em 0 0.5em -8px;
index 5a3f125..b649045 100644 (file)
@@ -313,7 +313,7 @@ class ProfileModule extends PLModule
         $wiz = new PlWizard('Profil', 'core/plwizard.tpl', true);
         require_once dirname(__FILE__) . '/profile/page.inc.php';
         $wiz->addPage('ProfileGeneral', 'Général', 'general');
-        $wiz->addPage('ProfileAddress', 'Adresses personnelles', 'adresses');
+        $wiz->addPage('ProfileAddresses', 'Adresses personnelles', 'adresses');
         $wiz->addPage('ProfileGroups', 'Groupes X - Binets', 'poly');
         $wiz->addPage('ProfileDeco', 'Décorations - Medals', 'deco');
         $wiz->addPage('ProfilePro', 'Informations professionnelles', 'emploi');
diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php
new file mode 100644 (file)
index 0000000..1ea8869
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+class ProfileAddress extends ProfileNoSave
+{
+    public function value(ProfilePage &$page, $field, $value, &$success)
+    {
+        $success = true;
+        if (is_null($value)) {
+            return $page->values['addresses'];
+        }
+        foreach ($value as $key=>&$adr) {
+            if ($adr['removed']) {
+                unset($value[$key]);
+            }
+        }
+        return $value;
+    }
+}
+
+class ProfileAddresses extends ProfilePage
+{
+    protected $pg_template = 'profile/adresses.tpl';
+
+    public function __construct(PlWizard &$wiz)
+    {
+        parent::__construct($wiz);
+        $this->settings['addresses'] = new ProfileAddress();
+    }
+
+    protected function fetchData()
+    {
+        if (count($this->orig) > 0) {
+            $this->values = $this->orig;
+            return;
+        }
+        // Build the addresses tree
+        $res = XDB::query("SELECT  adrid AS id, adr1, adr2, adr3,
+                                   postcode, city, cityid, region, regiontxt,
+                                   fax, glat, glng, datemaj, pub,
+                                   FIND_IN_SET('res-secondaire', statut) AS secondaire,
+                                   FIND_IN_SET('courrier', statut) AS mail,
+                                   FIND_IN_SET('temporary', statut) AS temporary,
+                                   FIND_IN_SET('active', statut) AS current,
+                                   FIND_IN_SET('coord-checked', statut) AS checked,
+                                   FIND_IN_SET('coord-valid', statut) AS valid
+                             FROM  adresses
+                            WHERE  uid = {?}
+                         ORDER BY  adrid",
+                           S::i('uid'));
+        $this->values['addresses'] = $res->fetchAllAssoc();
+
+        $res = XDB::iterRow("SELECT  adrid, telid, tel_type, tel_pub, tel
+                               FROM  tels
+                              WHERE  uid = {?}
+                           ORDER BY  adrid",
+                            S::i('uid'));
+        $i = 0;
+        while (list($adrid, $telid, $type, $pub, $tel) = $res->next()) {
+            while ($this->values['addresses'][$i]['id'] < $adrid) {
+                $i++;
+            }
+            $address =& $this->values['addresses'][$i];
+            if (!isset($address['tel'])) {
+                $address['tel'] = array();
+            }
+            if ($address['id'] == $adrid) {
+                $address['tel'][] = array('id'   => $telid,
+                                          'type' => $type,
+                                          'pub'  => $pub,
+                                          'tel'  => $tel);
+            }
+        }
+        parent::fetchData();
+    }
+
+    protected function saveData()
+    {
+        parent::saveData();
+    }
+
+    public function prepare(PlatalPage &$page)
+    {
+        parent::prepare($page);
+    }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index d014989..d85bfce 100644 (file)
@@ -224,6 +224,7 @@ abstract class ProfilePage implements PlWizardPage
 }
 
 require_once dirname(__FILE__) . '/general.inc.php';
+require_once dirname(__FILE__) . '/addresses.inc.php';
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
diff --git a/modules/profile/tabs.inc.php b/modules/profile/tabs.inc.php
deleted file mode 100644 (file)
index 34b74ae..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  This program is free software; you can redistribute it and/or modify   *
- *  it under the terms of the GNU General Public License as published by   *
- *  the Free Software Foundation; either version 2 of the License, or      *
- *  (at your option) any later version.                                    *
- *                                                                         *
- *  This program is distributed in the hope that it will be useful,        *
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
- *  GNU General Public License for more details.                           *
- *                                                                         *
- *  You should have received a copy of the GNU General Public License      *
- *  along with this program; if not, write to the Free Software            *
- *  Foundation, Inc.,                                                      *
- *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
- ***************************************************************************/
-
-
-$GLOBALS['tabname_array'] = Array(
-    "general"  => "Général",
-    "adresses" => "Adresses\npersonnelles",
-    "poly"     => "Groupes X\nBinets",
-    "deco"     => "Décorations\nMédailles",
-    "emploi"   => "Informations\nprofessionnelles",
-    "skill"    => "Compétences\ndiverses",
-    "mentor"   => "Mentoring"
-);
-
-$page->assign('onglets', $GLOBALS['tabname_array']);
-
-function get_next_tab($tabname) {
-    $tabname_array = $GLOBALS['tabname_array'];
-
-    reset ($tabname_array);
-    while (list($current_tab, ) = each($tabname_array)) {
-        if ($current_tab == $tabname){
-            $res = key($tabname_array);// each() sets key to the next element
-            if (is_null($res)) {
-                reset($tabname_array);
-                return key($tabname_array);
-            }
-            return $res;
-        }
-    }
-
-    return null;
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
index 138bc3f..3a0d2ad 100644 (file)
@@ -32,7 +32,7 @@
     {/foreach}
     <div style="clear: both"></div>
   </div>
-  <div class="wiz_content" style="clear: both" class="center">
+  <div class="wiz_content" style="clear: both">
     {foreach from=$xorg_errors item=err}
     <div class="erreur">{$err|smarty:nodefaults}</div>
     {/foreach}
index 4a14a05..ef72a4c 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-    {if $adr.geoloc}
-    <tr>
-      <td class="cold" colspan="5">
-        <input type="hidden" name="change{$adrid}" value="0"/>
-       <span class="erreur">La geolocalisation n'a pas donné un résultat certain, valide la nouvelle adresse ou modifie l'ancienne pour que ton adresse puisse être prise en compte.</span><br />
-       <script type="text/javascript">setTimeout("document.location += '#adr{$adrid}'", 10);</script>
-        <textarea name="txt[{$adrid}]" cols="30" rows="4" onchange="form.change{$adrid}.value=1"
-       {if !$adr.cityid}style="background:#FAA"{/if}
-       >{$adr.txt}</textarea>
-         <textarea cols="30" rows="4"
-         style="border:inherit;background:#AFA"
-         onclick="blur()"
-       >{$adr.geoloc}</textarea><p class="right">
-       [<a href="profile/edit/{$onglet}?parsevalid[{$adrid}]=1&amp;modifier=1">Valider</a>]
-       </p>
-    {else}
-    <tr class="center">
-      <td class="cold" colspan="5">
-        <input type="hidden" name="change{$adrid}" />
-        <textarea name="txt[{$adrid}]" cols="43" rows="4" onchange="form.change{$adrid}.value=1"
-       {if $adr.nouvelle != 'new' && !$adr.cityid}style="background:#FAA"{/if}
-       >{$adr.txt}</textarea>
-       {/if}
-        <input type="hidden" name="cityid[{$adrid}]" value="{$adr.cityid}" />
-        <input type="hidden" name="adr1[{$adrid}]" value="{$adr.adr1}" />
-        <input type="hidden" name="adr2[{$adrid}]" value="{$adr.adr2}" />
-        <input type="hidden" name="adr3[{$adrid}]" value="{$adr.adr3}" />
-        <input type="hidden" name="postcode[{$adrid}]" value="{$adr.postcode}"/>
-        <input type="hidden" name="city[{$adrid}]" value="{$adr.city}" />
-        <input type="hidden" name="country[{$adrid}]" value="{$adr.country}" />
-        <input type="hidden" name="region[{$adrid}]" value="{$adr.region}" />
-      </td>
-    </tr>
+<input type="hidden" name="{$name}[changed]" value="0"/>
+{if $adr.geoloc}
+<div class="erreur">
+  La geolocalisation n'a pas donné un résultat certain, valide la nouvelle adresse
+  ou modifie l'ancienne pour que ton adresse puisse être prise en compte.
+</div>
+<script type="text/javascript">setTimeout("document.location += '#{$adid}'", 10);</script>
+{/if}
+<textarea name="{$name}[text]" cols="30" rows="4"
+          onchange="form['{$name}[changed]'].value=1"
+          {if !$adr.cityid}class="error"{/if}
+          >{$adr.text}</textarea>
+{if $adr.geoloc}
+<textarea cols="30" rows="4"
+          class="valid"
+          onclick="blur()"
+          >{$adr.geoloc}</textarea>
+<p class="center">
+  <input type="submit" name="{$name}[parsevalid]" value="Valider l'adresse" />
+</p>
+{/if}
+<input type="hidden" name="{$name}[cityid]" value="{$adr.cityid}" />
+<input type="hidden" name="{$name}[adr1]" value="{$adr.adr1}" />
+<input type="hidden" name="{$name}[adr2]" value="{$adr.adr2}" />
+<input type="hidden" name="{$name}[adr3]" value="{$adr.adr3}" />
+<input type="hidden" name="{$name}[postcode]" value="{$adr.postcode}"/>
+<input type="hidden" name="{$name}[city]" value="{$adr.city}" />
+<input type="hidden" name="{$name}[country]" value="{$adr.country}" />
+<input type="hidden" name="{$name}[region]" value="{$adr.region}" />
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index ab32d54..55cb846 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 {if $display neq "mini"}
+  {if !$notable}
     <tr>
       <td colspan="5" class="pflags">
+  {/if}
         <table class="flags" summary="Flags" cellpadding="0" cellspacing="0">
           <tr>
             <td class="vert">
             </td>
           </tr>
         </table>
+  {if !$notable}
       </td>
     </tr>
+  {/if}
 {else}
             <td class="vert">
               <input type="radio" name="{$name}" value="public" {if $val eq 'public'}checked="checked"{/if} />
index 2f7b9da..4146af5 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
+<script type="text/javascript">//<![CDATA[
+{literal}
+function removeAddress(id, pref)
+{
+  document.getElementById(id).style.display = "none";
+  document.forms.prof_annu[pref + "[removed]"].value = "1";
+}
 
-<div class="blocunite_tab">
-  <table class="bicol" cellspacing="0" cellpadding="0" summary="Profil: Adresses personnelles">
-    <tr>
-      <th colspan="5">
-        Adresses personnelles
-      </th>
-    </tr>
+{/literal}
+//]]></script>
 
+{foreach key=i item=adr from=$addresses}
+{assign var=adpref value="addresses[$i]"}
+{assign var=adid value="addresses_$i"}
+<table class="bicol" id="{$adid}" style="margin-bottom: 1em">
+  <tr>
+    <th>
+      <div style="float: left">
+        <input name="{$adpref}[active]" type="radio" value="{$adr.id}" {if $adr.current}checked="checked"{/if}
+               id="{$adid}_active"/>
+        <label for="{$adid}_active" class="smaller" style="font-weight: normal">actuelle</label>
+      </div>
+      <div style="float: right">
+        <a href="javascript:removeAddress('{$adid}', '{$adpref}')">{icon name=cross title="Supprimer l'adresse"}</a>
+      </div>
+      Adresse n°{$i + 1}
+    </th>
+  </tr>
+  <tr>
+    <td>
+      <div>{include file="include/flags.radio.tpl" name="$adpref[pub]" notable=true val=$adr.pub}</div>
+      <div {if !$adr.geoloc}class="center"{/if}>{include file="geoloc/form.address.tpl" name=$adpref id=$adid adr=$adr}</div>
+    </td>
+  </tr>
+</table>
+<input type="hidden" name="{$adpref}[removed]" value="0"/>
+{/foreach}
+
+{*
     {section name=i loop=$nb_adr start=1 max=$nb_adr}
-    {*
-    $adrid = $ordre_adrid[$i];
-    $adr = &$adresses[$adrid];
-    *}
     {assign var='adrid' value=$ordre_adrid[i]}
     {assign var='adr' value=$adresses.$adrid}
-    <tr>
-      <th colspan="5">
-        <a id='adr{$adrid}'></a>
-        {if $adr.nouvelle != 'new'}Adresse n°{$smarty.section.i.index}{else}Rentre ici une nouvelle adresse{/if}
-        <input type="hidden" name="adrid[{$adrid}]" value="{$adrid}" />
-        {if $adr.nouvelle == 'new'}
-        <input type="hidden" name="numero_formulaire[{$adrid}]" value="0" />
-        {else}
-        <input type="hidden" name="numero_formulaire[{$adrid}]" value="{$smarty.section.i.index}" />
-        {/if}
-        {if $adr.nouvelle != 'new'}
-        <a href="profile/edit/{$onglet}?adrid_del[{$adrid}]=1" style="color:inherit">{icon name=cross title="Supprimer cette adresse"}</a>
-        {/if}
-      </th>
-    </tr>
-    {include file="include/flags.radio.tpl" name="pub[$adrid]" val=$adr.pub}
-    <tr>
-      <td class="left">
-        &nbsp;
-      </td>
-      <td colspan="4" class="right">
-        <em>c'est à cette adresse que je suis actuellement</em>
-        <input name="adrid_active" type="radio" value="{$adrid}" {if $adr.active}checked="checked"{/if} />
-      </td>
-    </tr>
-    {if $adr.nouvelle != 'new'}
-    {assign var="titre" value="Adresse n°`$smarty.section.i.index`&nbsp;:"}
-    {else}
-    {assign var="titre" value="Nouvelle adresse&nbsp;:"}
-    {/if}
     {include file="geoloc/form.address.tpl" adr=$adr titre=$titre}
     <tr>
       <td class="colg">
     {/section}
     <tr><td colspan="5">&nbsp;</td></tr>
   </table>
-</div>
-
+*}
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}