Enables access to profile edition pages without providing hrpid, or providing hrpid...
authorStéphane Jacob <sj@m4x.org>
Wed, 27 Oct 2010 12:23:20 +0000 (14:23 +0200)
committerStéphane Jacob <sj@m4x.org>
Wed, 27 Oct 2010 13:23:45 +0000 (15:23 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
modules/profile.php

index e3239d2..be8648e 100644 (file)
@@ -139,25 +139,25 @@ class ProfileModule extends PLModule
         exit;
     }
 
-    /** Tries to return the correct user from given hrpid
-     * Will redirect to $returnurl$hrpid if $hrpid was empty
+    /** Tries to return the correct profile from a given hrpid.
      */
-    private function findProfile($returnurl, $hrpid = null)
+    private function findProfile($hrpid = null)
     {
         if (is_null($hrpid)) {
             $user = S::user();
             if (!$user->hasProfile()) {
                 return PL_NOT_FOUND;
             } else {
-                pl_redirect($returnurl . $user->profile()->hrid());
+                $profile = $user->profile();
             }
         } else {
             $profile = Profile::get($hrpid);
-            if (!$profile) {
-                return PL_NOT_FOUND;
-            } else if (!S::user()->canEdit($profile) && Platal::notAllowed()) {
-                return PL_FORBIDDEN;
-            }
+        }
+
+        if (!$profile) {
+            return PL_NOT_FOUND;
+        } else if (!S::user()->canEdit($profile) && Platal::notAllowed()) {
+            return PL_FORBIDDEN;
         }
         return $profile;
     }
@@ -165,10 +165,13 @@ class ProfileModule extends PLModule
     function handler_photo_change(&$page, $hrpid = null)
     {
         global $globals;
-        $profile = $this->findProfile('photo/change/', $hrpid);
+        $profile = $this->findProfile($hrpid);
         if (! ($profile instanceof Profile) && ($profile == PL_NOT_FOUND || $profile == PL_FORBIDDEN)) {
             return $profile;
         }
+        if (is_null($hrpid)) {
+            pl_redirect('photo/change/' . $profile->hrid());
+        }
 
         $page->changeTpl('profile/trombino.tpl');
         $page->assign('hrpid', $profile->hrid());
@@ -310,10 +313,19 @@ class ProfileModule extends PLModule
     {
         global $globals;
 
-        $profile = $this->findProfile('profile/edit/', $hrpid);
+        if (in_array($hrpid, array('general', 'adresses', 'emploi', 'poly', 'deco', 'skill', 'mentor'))) {
+            $aux = $opened_tab;
+            $opened_tab = $hrpid;
+            $hrpid = $aux;
+            $url_error = true;
+        }
+        $profile = $this->findProfile($hrpid);
         if (! ($profile instanceof Profile) && ($profile == PL_NOT_FOUND || $profile == PL_FORBIDDEN)) {
             return $profile;
         }
+        if (is_null($hrpid) || $url_error) {
+            pl_redirect('profile/edit/' . $profile->hrid() . (is_null($opened_tab) ? '' : '/' . $opened_tab));
+        }
 
         // Build the page
         $page->addJsLink('ajax.js');