AX enabled version of the first page of the profile edition.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 30 Sep 2010 12:15:09 +0000 (14:15 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 30 Sep 2010 12:20:47 +0000 (14:20 +0200)
If the profile editor does not have directory_private privileges, hide
private informations.

Note: use <input type="hidden" /> to hide some informations without
breaking the code of the backend. I know this does not hide anything
to somebody who knows html, but remember: this is for the secretaries
of the AX... We can certainly do better in the future, but this requires
some hacking in the php code for phones, networking, addresses, jobs and
I'm too lazy for it.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/phone.php
modules/profile/general.inc.php
modules/profile/page.inc.php
templates/include/flags.radio.tpl
templates/profile/base.tpl
templates/profile/general.networking.tpl
templates/profile/general.tpl
templates/profile/phone.tpl

index 46c1a9a..32eb168 100644 (file)
@@ -340,7 +340,7 @@ class Phone
         $phones = array();
         foreach ($data as $item) {
             $phone = new Phone($item);
-            $success = (($phone->isEmpty() || $phone->format()) && $success);
+            $success = (!$phone->error && ($phone->format() || $phone->isEmpty()) && $success);
             if (!$phone->isEmpty()) {
                 $phones[] = call_user_func(array($phone, $function));
             }
index 7e2bfff..66d94b3 100644 (file)
@@ -523,17 +523,9 @@ class ProfilePageGeneral extends ProfilePage
         $this->settings['search_names']
                                   = new ProfileSettingSearchNames();
         $this->settings['birthdate'] = new ProfileSettingDate();
-        if (!S::user()->isMe($this->owner)) {
-            $this->settings['deathdate'] = new ProfileSettingDate();
-        }
-        $this->settings['freetext_pub']
-                                  = $this->settings['photo_pub']
-                                  = new ProfileSettingPub();
-        $this->settings['freetext']
-                                  = $this->settings['nationality1']
+        $this->settings['nationality1']
                                   = $this->settings['nationality2']
                                   = $this->settings['nationality3']
-                                  = $this->settings['yourself']
                                   = $this->settings['promo_display']
                                   = null;
         $this->settings['email_directory']
@@ -544,10 +536,26 @@ class ProfilePageGeneral extends ProfilePage
         $this->settings['tels']   = new ProfileSettingPhones();
         $this->settings['edus']   = new ProfileSettingEdu();
         $this->settings['promo']  = new ProfileSettingPromo();
-        $this->watched= array('freetext' => true, 'tels' => true,
+        $this->watched= array('tels' => true,
                               'networking' => true, 'edus' => true,
                               'nationality1' => true, 'nationality2' => true,
                               'nationality3' => true, 'search_names' => true);
+
+        /* Some fields editable under condition */
+        if (!S::user()->isMe($this->owner)) {
+            $this->settings['deathdate'] = new ProfileSettingDate(true);
+        }
+        if (S::user()->checkPerms('directory_private')
+            || S::user()->isMyProfile($this->owner)) {
+            $this->settings['yourself']
+                                      = $this->settings['freetext']
+                                      = null;
+            $this->settings['freetext_pub']
+                                      = $this->settings['photo_pub']
+                                      = new ProfileSettingPub();
+            $this->watched['freetext'] = true;
+        }
+
     }
 
     protected function _fetchData()
index 1d9b728..d8c89de 100644 (file)
@@ -123,7 +123,7 @@ class ProfileSettingPhones implements ProfileSetting
             if (!$success) {
                 Platal::page()->trigError('Numéro de téléphone invalide');
             }
-            return $phone;
+            return $phones;
         }
     }
 
@@ -174,12 +174,23 @@ class ProfileSettingBool extends ProfileNoSave
 
 class ProfileSettingDate extends ProfileNoSave
 {
+    private $allowEmpty;
+
+    public function __construct($allowEmpty = false)
+    {
+        $this->allowEmpty = $allowEmpty;
+    }
+
     public function value(ProfilePage &$page, $field, $value, &$success)
     {
         $success = true;
         if (is_null($value)) {
             $value = preg_replace('/(\d{4})-(\d{2})-(\d{2})/', '\3/\2/\1', @$page->values[$field]);
         } else {
+            $value = trim($value);
+            if (empty($value) && $this->allowEmpty) {
+                return null;
+            }
             $success = preg_match('@(\d{2})/(\d{2})/(\d{4})@', $value, $matches);
             if (!$success) {
                 Platal::page()->trigError("Les dates doivent être au format jj/mm/aaaa");
@@ -378,14 +389,20 @@ abstract class ProfilePage implements PlWizardPage
             }
             return Post::has('next_page') ? PlWizard::NEXT_PAGE : PlWizard::CURRENT_PAGE;
         }
-        Platal::page()->trigError("Certains champs n'ont pas pu être validés, merci de corriger les informations "
-                                . "de ton profil et de revalider ta demande.");
+        $text = "Certains champs n'ont pas pu être validés, merci de corriger les informations "
+              . (S::user()->isMe($this->owner) ? "de ton profil et de revalider ta demande."
+                                               : "du profil et de revalider ta demande.");
+        Platal::page()->trigError($text);
         return PlWizard::CURRENT_PAGE;
     }
 
     public function success()
     {
-        return 'Ton profil a bien été mis à jour.';
+        if (S::user()->isMe($this->owner)) {
+            return 'Ton profil a bien été mis à jour.';
+        } else {
+            return 'Le profil a bien été mis à jour.';
+        }
     }
 }
 
index 2c2019a..4ea1998 100644 (file)
@@ -31,7 +31,7 @@
        {if t($disabled)}disabled="disabled"{/if} />
 {icon name="flag_orange" title="transmis à l'AX"}
 {if t($withtext)}<span class="texte">transmis à l'AX</span>{/if}</label>
-<label><input type="radio" name="{$name}" value="private"{if $val eq 'private' && !t($disabled)} checked="checked"{/if}
+<label><input type="radio" name="{$name}" value="private"{if $val eq 'private'} checked="checked"{/if}
        {if t($disabled)}disabled="disabled"{/if} />
 {icon name="flag_red" title="privé"}
 {if t($withtext)}<span class="texte">privé</span>{/if}</label>
index 286e8b2..53ba85e 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
+{assign var=isMe value=$smarty.session.user->isMyProfile($profile)}
+{if hasPerm('directory_private')}
+{assign var=viewPrivate value=true}
+{/if}
+
 <form action="{$wiz_baseurl}/{$lookup[$current]}" method="post" id="prof_annu">
   {xsrf_token_field}
   <div>
-    {icon name=information title="Voir ma fiche"} Tu peux consulter ta fiche telle que la
+    {icon name=information title="Voir ma fiche"} Tu peux consulter
+    {if $smarty.session.user->isMyProfile($profile)}ta{else}cette{/if} fiche telle que la
     voient <a class="popup2" href="profile/{$profile->hrpid}?view=public">n'importe quel internaute</a>,
-    <a class="popup2" href="profile/{$profile->hrpid}?view=ax">l'AX</a> ou
-    <a class="popup2" href="profile/{$profile->hrpid}">les X</a>.
+    <a class="popup2" href="profile/{$profile->hrpid}?view=ax">l'AX</a>{if hasPerm('directory_private')}ou
+    <a class="popup2" href="profile/{$profile->hrpid}">les X</a>{/if}.
   </div>
   <div class="flags">
-  {include file="include/flags.radio.tpl" disabled=true withtext=true name="profile_ex_pub"}
+  {include file="include/flags.radio.tpl" disabled=true withtext=true val="novalue" name="profile_ex_pub"}
   </div>
   <div style="margin-top: 1em">
     {include file=$profile_page}
index 6e5ed93..7636aee 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
+{if !hasPerm('directory_private') && ($nw.pub eq 'private') && !empty($nw.address|smarty:nodefaults)}
+{assign var=hiddennw value=true}
+{else}
+{assign var=hiddennw value=false}
+{/if}
+
 <tr id="networking_{$i}">
   <td colspan="2">
     <div style="float: left; width: 200px;">
       <span class="flags">
         <label><input type="checkbox"
           {if $nw.pub neq 'private'} checked="checked"{/if}
+          {if $hiddennw} disabled="disabled"{/if}
           name="networking[{$i}][pub]"/>
         {icon name="flag_green" title="site public"}</label>
       </span>&nbsp;
       <span style="">{$nw.name}</span>
     </div>
     <div style="float: left">
+      {if $hiddennw}
+      <input type="hidden" name="networking[{$i}][address]" value="{$nw.address}" />
+      (masqué)
+      {else}
       <input type="text" name="networking[{$i}][address]" value="{$nw.address}"
         {if $nw.error} class="error" {/if}
         size="30"/>
+      {/if}
       <a href="javascript:removeNetworking({$i})">
         {icon name=cross title="Supprimer cet élément"}
       </a>
index fbe27db..f38066b 100644 (file)
     <td id="public_name">
       {$public_name}
     </td>
-    <td rowspan="2">
+    <td>
       <a href="javascript:toggleNamesAdvanced();">
         {icon name="page_edit" title="Plus de détail"}
       </a>
     </td>
   </tr>
+  {if $viewPrivate}
   <tr>
     <td class="titre">
       {icon name="flag_red" title="site privé"}&nbsp;Affichage privé
     <td id="private_name">
       {$private_name}
     </td>
+    <td></td>
   </tr>
+  {/if}
+  {if $isMe}
   <tr>
     <td>
       <span class="titre">Comment t'appeller</span><br />
     </td>
     <td></td>
   </tr>
+  {/if}
   <tr class="names_advanced" {if !$errors.search_names}style="display: none"{/if}>
     <td colspan="3">
-      <span class="titre">Gestion de tes noms, prénoms, surnoms...</span>
-      <span class="smaller">Ils déterminent la façon dont ton nom apparaît sur les annuaires
+      <span class="titre">Gestion des noms, prénoms, surnoms...</span>
+      <span class="smaller">Ils déterminent la façon dont
+      {if $isMe}ton{else}son{/if} nom apparaît sur les annuaires
       en ligne et papier et ta fiche apparaitra quand on cherche un de ces noms. Pour plus
       d'explications sur l'icône suivante
       <a href="profile/name_info" class="popup3">{icon name="information" title="Plus d'infos"}</a>.</span><br/>
   </tr>
   <tr class="promotion_edition" style="display: none">
     <td colspan="2">
-      Afin de pouvoir être considéré{if $profile->isFemale()}e{/if} à la fois dans ta promotion d'origine et ta
+      {if $isMe}
+      Afin de pouvoir être considéré{""|sex:"e":$profile} à la fois dans ta promotion d'origine et ta
       ou tes promotions d'adoption tu peux entrer ici ta promotion d'adoption.
+      {else}
+      Afin que ce{""|sex:"tte":$profile} camarade soit considé{""|sex:"e":$profile} à la fois dans sa 
+      promotion d'origine et sa promotion d'adoption, tu peux enterr ici sa promotion d'adoption.
+      {/if}
       <br /><span class="smaller"><span class="titre">Attention&nbsp;:</span>
       cette modification ne sera prise en compte qu'après validation par les administrateurs du site.</span>
     </td>
     </td>
     <td><input type="text" {if $errors.birthdate}class="error"{/if} name="birthdate" value="{$birthdate}" /></td>
   </tr>
-  {if !$smarty.session.user->isMe($owner)}
+  {if !$isMe}
   <tr>
     <td>
       <span class="titre">Date de décès</span>
   </tr>
   <tr class="{$class}">
     <td class="center" colspan="2">
-      <small>Si ta formation ne figure pas dans la liste,
+      <small>Si la formation que tu cherches ne figure pas dans la liste,
       <a href="mailto:support@{#globals.mail.domain#}">contacte-nous</a>.</small>
     </td>
   </tr>
  </table>
 
+{if $viewPrivate || $isMe}
 <table class="bicol"  style="margin-bottom: 1em"
   summary="Profil&nbsp;: Trombinoscope">
   <tr>
   </tr>
   <tr>
     <td {if !$nouvellephoto}colspan="2"{/if} class="center" style="width: 49%">
-      <div class="titre">Ta photo actuelle</div>
+      <div class="titre">Photo actuelle</div>
       <img src="photo/{$profile->hrid()}" alt=" [ PHOTO ] " style="max-height: 250px; margin-top: 1em" />
     </td>
     {if $nouvellephoto}
     </td>
   </tr>
 </table>
+{/if}
 
 <table class="bicol" style="margin-bottom: 1em"
   summary="Profil&nbsp;: Divers">
       </div>
     </td>
   </tr>
+  {if $viewPrivate || $isMe}
   <tr class="pair">
     <td>
       <div>
                 id="freetext" rows="8" cols="50" >{$freetext}</textarea>
     </td>
   </tr>
+  {/if}
 </table>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index db5d919..c378102 100644 (file)
 
 {assign var=telpref value="`$prefname`[`$telid`]"}
 {assign var=id value="`$prefid`_`$telid`"}
+{if !hasPerm('directory_private') && ($tel.pub eq 'private') && !empty($tel.display)}
+{assign var=hiddentel value=true}
+{else}
+{assign var=hiddentel value=false}
+{/if}
 <div class="titre" style="float: left; width: 2.5em">N°{$telid+1}</div>
 <div style="float: left;">
+  {if $hiddentel}
+  Numéro {if $tel.type eq 'fixed'}fixe{elseif $tel.type eq 'mobile'}de mobile{else}de fax{/if} (masqué)
+  <input type="hidden" name="{$telpref}[type]" value="{$tel.type}" />
+  <input type="hidden" name="{$telpref}[display]" value="{$tel.display}" />
+  {else}
   <select name="{$telpref}[type]">
     <option value="fixed"{if $tel.type eq 'fixed'} selected="selected"{/if}>Fixe</option>
     <option value="mobile"{if $tel.type eq 'mobile'} selected="selected"{/if}>Mobile</option>
     <option value="fax"{if $tel.type eq 'fax'} selected="selected"{/if}>Fax</option>
   </select>
   <input type="text" size="19" maxlength="28" name="{$telpref}[display]" {if $tel.error}class="error"{/if} value="{$tel.display}" />
-  <a class="removeTel" href="javascript:removeTel('{$prefname}','{$prefid}','{$telid}')">
-    {icon name=cross title="Supprimer ce numéro de téléphone"}
-  </a>
   <a id="{$id}_addComment" href="javascript:addPhoneComment('{$id}')" {if $tel.comment neq ''}style="display:none" {/if}>
     {icon name=comments title="Ajouter un commentaire"}
   </a>
+  {/if}
+  <a class="removeTel" href="javascript:removeTel('{$prefname}','{$prefid}','{$telid}')">
+    {icon name=cross title="Supprimer ce numéro de téléphone"}
+  </a>
 </div>
 <div style="float: right" class="flags">
-  {include file="include/flags.radio.tpl" name="`$telpref`[pub]" val=$tel.pub}
+  {include file="include/flags.radio.tpl" name="`$telpref`[pub]"
+           val=$tel.pub disabled=$hiddentel}
 </div>
 <div id="{$id}_comment" style="clear: both;{if $tel.comment eq ''} display:none{/if}">
   Commentaire :