'profile/private' => $this->make_hook('profile', AUTH_COOKIE),
'profile/ax' => $this->make_hook('ax', AUTH_COOKIE, 'admin'),
'profile/edit' => $this->make_hook('p_edit', AUTH_MDP),
+ 'profile/ajax/address' => $this->make_hook('ajax_address', AUTH_PUBLIC, 'user', NO_AUTH),
+ 'profile/ajax/tel' => $this->make_hook('ajax_tel', AUTH_COOKIE, 'user', NO_AUTH),
'profile/orange' => $this->make_hook('p_orange', AUTH_MDP),
'profile/usage' => $this->make_hook('p_usage', AUTH_MDP),
// Misc checks
// TODO: Block if birth date is missing ?
+ $page->addJsLink('ajax.js');
+ $page->addJsLink('jquery.js');
$wiz = new PlWizard('Profil', 'core/plwizard.tpl', true);
require_once dirname(__FILE__) . '/profile/page.inc.php';
$wiz->addPage('ProfileGeneral', 'Général', 'general');
$page->assign('xorg_title', 'Polytechnique.org - Mon Profil');
}
+ function handler_ajax_address(&$page, $adid)
+ {
+ $page->changeTpl('profile/adresses.address.tpl', NO_SKIN);
+ $page->assign('i', $adid);
+ $page->assign('adr', array());
+ $page->assign('ajaxadr', true);
+ }
+
+ function handler_ajax_tel(&$page, $adid, $telid)
+ {
+ $page->changeTpl('profile/adresses.tel.tpl', NO_SKIN);
+ $page->assign('i', $adid);
+ $page->assign('adid', "addresses_$adid");
+ $page->assign('adpref', "addresses[$adid]");
+ $page->assign('t', $telid);
+ $page->assign('tel', array());
+ $page->assign('ajaxtel', true);
+ }
+
function handler_p_orange(&$page)
{
$page->changeTpl('profile/orange.tpl');
$address['datemaj'] = time();
}
foreach ($address['tel'] as $t=>&$tel) {
- if (@$tel['removed']) {
+ if (@$tel['removed'] || !trim($tel['tel'])) {
unset($address['tel'][$t]);
} else {
$tel['pub'] = $this->pub->value($page, 'pub', $tel['pub'], $success);
if (!$init) {
$success = $success && $s;
}
+ if (!trim($adr['text'])) {
+ unset($value[$key]);
+ }
}
return $value;
}
{/if}
<textarea name="{$name}[text]" cols="30" rows="4"
onchange="form['{$name}[changed]'].value=1"
- {if !$adr.cityid}class="error"{/if}
+ {if !$adr.cityid && $adr.datemaj}class="error"{/if}
>{$adr.text}</textarea>
{if $adr.geoloc}
<textarea cols="30" rows="4"
<input type="radio" name="{$name}" value="ax" {if $val eq 'ax'}checked="checked"{/if} />
</td>
<td class="rouge">
- <input type="radio" name="{$name}" value="private" {if $val eq 'private'}checked="checked"{/if} />
+ <input type="radio" name="{$name}" value="private" {if $val eq 'private' || !$val}checked="checked"{/if} />
</td>
{elseif $display eq "div"}
<span class="vert">
<input type="radio" name="{$name}" value="ax" {if $val eq 'ax'}checked="checked"{/if} />
</span>
<span class="rouge">
- <input type="radio" name="{$name}" value="private" {if $val eq 'private'}checked="checked"{/if} />
+ <input type="radio" name="{$name}" value="private" {if $val eq 'private' || !$val}checked="checked"{/if} />
</span>
{else}
{if !$notable}
transmis à l'AX
</td>
<td class="rouge">
- <input type="radio" name="{$name}" value="private" {if $val eq 'private'}checked="checked"{/if} />
+ <input type="radio" name="{$name}" value="private" {if $val eq 'private' || !$val}checked="checked"{/if} />
</td>
<td class="texte">
privé
--- /dev/null
+{**************************************************************************}
+{* *}
+{* 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 *}
+{* *}
+{**************************************************************************}
+
+{if $ajaxadr}
+<?xml version="1.0" encoding="utf-8"?>
+{/if}
+{assign var=adpref value="addresses[$i]"}
+{assign var=adid value="addresses_$i"}
+<input type="hidden" name="{$adpref}[removed]" value="0"/>
+<input type="hidden" name="{$adpref}[datemaj]" value="{$adr.datemaj}"/>
+<table class="bicol" style="margin-bottom: 1em">
+ <tr>
+ <th>
+ <div style="float: left">
+ <input name="{$adpref}[current]" type="radio" value="1" {if $adr.current}checked="checked"{/if}
+ id="{$adid}_current" onchange="checkCurrentAddress(this); return true" />
+ <label for="{$adid}_current" 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 style="clear: both"></div>
+ <div style="float: left">{include file="geoloc/form.address.tpl" name=$adpref id=$adid adr=$adr}</div>
+ <div style="float: right">
+ <div>
+ <input type="radio" name="{$adpref}[temporary]" id="{$adid}_temp_0" value="0"
+ {if !$adr.temporary}checked="checked"{/if} /><label for="{$adid}_temp_0">permanente</label>
+ <input type="radio" name="{$adpref}[temporary]" id="{$adid}_temp_1" value="1"
+ {if $adr.temporary}checked="checked"{/if} /><label for="{$adid}_temp_1">temporaire</label>
+ </div>
+ <div>
+ <input type="radio" name="{$adpref}[secondaire]" id="{$adid}_sec_0" value="0"
+ {if !$adr.secondaire}checked="checked"{/if} /><label for="{$adid}_sec_0">ma résidence principale</label>
+ <input type="radio" name="{$adpref}[secondaire]" id="{$adid}_sec_1" value="1"
+ {if $adr.secondaire}checked="checked"{/if} /><label for="{$adid}_sec_1">une résidence secondaire</label>
+ </div>
+ <div>
+ <input type="checkbox" name="{$adpref}[mail]" id="{$adid}_mail"
+ {if $adr.mail}checked="checked"{/if} />
+ <label for="{$adid}_mail">on peut m'y envoyer du courrier par la poste</label>
+ </div>
+ </div>
+ </td>
+ </tr>
+ <tr class="pair">
+ <td>
+ {foreach from=$adr.tel key=t item=tel}
+ <div id="{"`$adid`_tel_`$t`"}" style="clear: both">
+ {include file="profile/adresses.tel.tpl" t=$t tel=$tel}
+ </div>
+ {/foreach}
+ {if $adr.tel|@count eq 0}
+ <div id="{"`$adid`_tel_0"}" style="clear: both">
+ {include file="profile/adresses.tel.tpl" t=0 tel=0}
+ </div>
+ {/if}
+ <div id="{$adid}_add_tel" class="center" style="clear: both">
+ <a href="javascript:addTel({$i})">
+ {icon name=add title="Ajouter un numéro de téléphone"} Ajouter un numéro de téléphone
+ </a>
+ </div>
+ </td>
+ </tr>
+</table>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
--- /dev/null
+{**************************************************************************}
+{* *}
+{* 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 *}
+{* *}
+{**************************************************************************}
+
+{if $ajaxtel}
+<?xml version="1.0" encoding="utf-8"?>
+{/if}
+{assign var=telpref value="`$adpref`[tel][`$t`]"}
+{assign var=telid value="`$adid`_tel_`$t`"}
+<div style="float: right" class="flags">
+ {include file="include/flags.radio.tpl" name="`$telpref`[pub]" val=$tel.pub display="div"}
+</div>
+<span class="titre">N°{$t+1}</span>
+<input type="hidden" name="{$telpref}[removed]" value="0" />
+<input type="text" size="10" maxlength="30" name="{$telpref}[type]" value="{$tel.type|default:"Tél."}" />
+<input type="text" size="19" maxlength="28" name="{$telpref}[tel]" value="{$tel.tel}" />
+<a href="javascript:removeObject('{$telid}', '{$telpref}')">
+ {icon name=cross title="Supprimer ce numéro de téléphone"}
+</a>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
document.forms.prof_annu[pref + "[removed]"].value = "1";
}
+function getAddressElement(adrid, adelement)
+{
+ return document.forms.prof_annu["addresses[" + adrid + "][" + adelement + "]"];
+}
+
+function checkCurrentAddress(newCurrent)
+{
+ var hasCurrent = false;
+ var i = 0;
+ while (getAddressElement(i, 'pub') != null) {
+ var radio = getAddressElement(i, 'current');
+ var removed = getAddressElement(i, 'removed');
+ if (removed.value == "1" && radio.checked) {
+ radio.checked = false;
+ } else if (radio.checked && radio != newCurrent) {
+ radio.checked = false;
+ } else if (radio.checked) {
+ hasCurrent = true;
+ }
+ i++;
+ }
+ if (!hasCurrent) {
+ i = 0;
+ while (getAddressElement(i, 'pub') != null) {
+ var radio = getAddressElement(i, 'current');
+ var removed = getAddressElement(i, 'removed');
+ if (removed.value != "1") {
+ radio.checked= true;
+ return;
+ }
+ i++;
+ }
+ }
+}
+
+function removeAddress(id, pref)
+{
+ removeObject(id, pref);
+ checkCurrentAddress(null);
+}
+
+function addAddress()
+{
+ var i = 0;
+ while (getAddressElement(i, 'pub') != null) {
+ i++;
+ }
+ $("#add_adr").before('<div id="addresses_' + i + '"></div>');
+ Ajax.update_html('addresses_' + i, 'profile/ajax/address/' + i, checkCurrentAddress);
+}
+
+function addTel(id)
+{
+ var i = 0;
+ var adid = 'addresses_' + id;
+ var tel = adid + '_tel_';
+ while (document.getElementById(tel + i) != null) {
+ i++;
+ }
+ $('#' + adid + '_add_tel').before('<div id="' + tel + i + '" style="clear: both"></div>');
+ Ajax.update_html(tel + i, 'profile/ajax/tel/' + id + '/' + i);
+}
+
{/literal}
//]]></script>
{foreach key=i item=adr from=$addresses}
-{assign var=adpref value="addresses[$i]"}
-{assign var=adid value="addresses_$i"}
-<input type="hidden" name="{$adpref}[removed]" value="0"/>
-<input type="hidden" name="{$adpref}[datemaj]" value="{$adr.datemaj}"/>
-<table class="bicol" id="{$adid}" style="margin-bottom: 1em">
- <tr>
- <th>
- <div style="float: left">
- <input name="{$adpref}[current]" type="radio" value="1" {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:removeObject('{$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 style="clear: both"></div>
- <div style="float: left">{include file="geoloc/form.address.tpl" name=$adpref id=$adid adr=$adr}</div>
- <div style="float: right">
- <div>
- <input type="radio" name="{$adpref}[temporary]" id="{$adid}_temp_0" value="0"
- {if !$adr.temporary}checked="checked"{/if} /><label for="{$adid}_temp_0">permanente</label>
- <input type="radio" name="{$adpref}[temporary]" id="{$adid}_temp_1" value="1"
- {if $adr.temporary}checked="checked"{/if} /><label for="{$adid}_temp_1">temporaire</label>
- </div>
- <div>
- <input type="radio" name="{$adpref}[secondaire]" id="{$adid}_sec_0" value="0"
- {if !$adr.secondaire}checked="checked"{/if} /><label for="{$adid}_sec_0">ma résidence principale</label>
- <input type="radio" name="{$adpref}[secondaire]" id="{$adid}_sec_1" value="1"
- {if $adr.secondaire}checked="checked"{/if} /><label for="{$adid}_sec_1">une résidence secondaire</label>
- </div>
- <div>
- <input type="checkbox" name="{$adpref}[mail]" id="{$adid}_mail"
- {if $adr.mail}checked="checked"{/if} />
- <label for="{$adid}_mail">on peut m'y envoyer du courrier par la poste</label>
- </div>
- </div>
- </td>
- </tr>
- <tr class="pair">
- <td>
- {foreach from=$adr.tel key=t item=tel}
- {assign var=telpref value="`$adpref`[tel][`$t`]"}
- {assign var=telid value="`$adid`_tel_`$t`"}
- <div id="{$telid}" style="clear: both">
- <div style="float: right" class="flags">
- {include file="include/flags.radio.tpl" name="`$telpref`[pub]" val=$tel.pub display="div"}
- </div>
- <span class="titre">N°{$t}</span>
- <input type="hidden" name="{$telpref}[removed]" value="0" />
- <input type="text" size="10" maxlength="30" name="{$telpref}[type]" value="{$tel.type}" />
- <input type="text" size="19" maxlength="28" name="{$telpref}[tel]" value="{$tel.tel}" />
- <a href="javascript:removeObject('{$telid}', '{$telpref}')">
- {icon name=cross title="Supprimer ce numéro de téléphone"}
- </a>
- </div>
- {/foreach}
- </td>
- </tr>
-</table>
+<div id="{"addresses_$i"}">
+{include file="profile/adresses.address.tpl" i=$i adr=$adr}
+</div>
{/foreach}
+{if $addresses|@count eq 0}
+<div id="addresses_0">
+{include file="profile/adresses.address.tpl" i=0 adr=0}
+</div>
+{/if}
+
+<div id="add_adr" class="center">
+ <a href="javascript:addAddress()">
+ {icon name=add title="Ajouter une adresse"} Ajouter une adresse
+ </a>
+</div>
{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}