Allow edition of the death date in the profile edition page.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 28 Sep 2010 13:32:42 +0000 (15:32 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 28 Sep 2010 13:53:10 +0000 (15:53 +0200)
Note: for ethical reasons, the user cannot edit his own death date.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
core
modules/profile/general.inc.php
modules/profile/page.inc.php
templates/profile/general.tpl

diff --git a/core b/core
index a2efe30..792e460 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit a2efe30f0470b8150e70189e6f8d9d7d8601ea87
+Subproject commit 792e4607bafa557ff5bde3b4e4da9406cfbc3111
index 981d985..7e2bfff 100644 (file)
@@ -523,6 +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();
@@ -552,7 +555,8 @@ class ProfilePageGeneral extends ProfilePage
         // Checkout all data...
         $res = XDB::query("SELECT  p.nationality1, p.nationality2, p.nationality3, p.birthdate,
                                    p.email_directory as email_directory, pd.promo AS promo_display,
-                                   p.freetext, p.freetext_pub, p.ax_id AS matricule_ax, pd.yourself
+                                   p.freetext, p.freetext_pub, p.ax_id AS matricule_ax, pd.yourself,
+                                   p.deathdate
                              FROM  profiles              AS p
                        INNER JOIN  profile_display       AS pd ON (pd.pid = p.pid)
                             WHERE  p.pid = {?}", $this->pid());
@@ -615,7 +619,7 @@ class ProfilePageGeneral extends ProfilePage
                                   freetext = {?}, freetext_pub = {?}, email_directory = {?}
                            WHERE  pid = {?}",
                           $this->values['nationality1'], $this->values['nationality2'], $this->values['nationality3'],
-                          preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values['birthdate']),
+                          ProfileSettingDate::toSQLDate($this->values['birthdate']),
                           $this->values['freetext'], $this->values['freetext_pub'], $new_email, $this->pid());
         }
         if ($this->changed['photo_pub']) {
@@ -649,6 +653,25 @@ class ProfilePageGeneral extends ProfilePage
                 }
             }
         }
+        if ($this->changed['deathdate']) {
+            XDB::execute('UPDATE  profiles
+                             SET  deathdate = {?}, deathdate_rec = NOW()
+                           WHERE  pid = {?} AND deathdate_rec IS NULL',
+                         ProfileSettingDate::toSQLDate($this->values['deathdate']), $this->pid());
+            if (XDB::affectedRows() > 0) {
+                $this->profile->clear();
+                if ($this->owner) {
+                    $this->owner->clear(true);
+                }
+            } else {
+                /* deathdate_rec was not NULL, this is just an update of the death date
+                 */
+                XDB::execute('UPDATE  profiles
+                                 SET  deathdate = {?}
+                               WHERE  pid = {?}',
+                             ProfileSettingDate::toSQLDate($this->values['deathdate']), $this->pid());
+            }
+        }
     }
 
     public function _prepare(PlPage &$page, $id)
index 3117b29..9ea18d9 100644 (file)
@@ -190,6 +190,11 @@ class ProfileSettingDate extends ProfileNoSave
         }
         return $value;
     }
+
+    public static function toSQLDate($value)
+    {
+        return preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $value);
+    }
 }
 
 abstract class ProfilePage implements PlWizardPage
index 28d3946..fbe27db 100644 (file)
     </td>
     <td><input type="text" {if $errors.birthdate}class="error"{/if} name="birthdate" value="{$birthdate}" /></td>
   </tr>
+  {if !$smarty.session.user->isMe($owner)}
+  <tr>
+    <td>
+      <span class="titre">Date de décès</span>
+    </td>
+    <td><input type="text" {if $errors.deathdate}class="error"{/if} name="deathdate" value="{$deathdate}" /></td>
+  </tr>
+  {/if}
   <tr>
     <td>
       <span class="titre">Nationalité</span>