X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile.php;h=5a23f8057bb1b930f9f9b06e398f4b683eacfad6;hb=723d4c6b7736df20e07d2c6e32e4c37c6c80ca05;hp=b737ac61b832835bde8dd58b5e937bb8c180b2ee;hpb=245923e335d0da5bec9495991a7846be9f0563ab;p=platal.git diff --git a/modules/profile.php b/modules/profile.php index b737ac6..5a23f80 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -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()); @@ -232,17 +235,6 @@ class ProfileModule extends PLModule if (is_null($id)) { return PL_NOT_FOUND; } - $pid = (!is_numeric($id) || S::admin()) ? Profile::getPID($id) : null; - if (is_null($pid)) { - if (S::logged()) { - $page->trigError($id . " inconnu dans l'annuaire."); - } - return PL_NOT_FOUND; - } - - // Now that we know this is an existing profile, we can switch to the - // appropriate template. - $page->changeTpl('profile/profile.tpl', SIMPLE); // Determines the access level at which the profile will be displayed. if (!S::logged() || !S::user()->checkPerms('directory_ax') || Env::v('view') == 'public') { @@ -258,10 +250,30 @@ class ProfileModule extends PLModule $page->assign('with_pending_pic', true); } - // Fetches profile's and profile's owner information and redirects to - // marketing if the owner has not subscribed and the requirer has logged in. - $profile = Profile::get($pid, Profile::FETCH_ALL, $view); - $owner = $profile->owner(); + $pid = (!is_numeric($id) || S::admin()) ? Profile::getPID($id) : null; + if (is_null($pid)) { + $owner = User::getSilent($id); + if ($owner) { + $profile = $owner->profile(true, Profile::FETCH_ALL, $view); + if ($profile) { + $pid = $profile->id(); + } + } + } else { + // Fetches profile's and profile's owner information and redirects to + // marketing if the owner has not subscribed and the requirer has logged in. + $profile = Profile::get($pid, Profile::FETCH_ALL, $view); + $owner = $profile->owner(); + } + if (is_null($pid)) { + if (S::logged()) { + $page->kill($id . " inconnu dans l'annuaire."); + } + return PL_NOT_FOUND; + } + // Now that we know this is an existing profile, we can switch to the + // appropriate template. + $page->changeTpl('profile/profile.tpl', SIMPLE); // Profile view are logged. if (S::logged()) { @@ -301,10 +313,21 @@ 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; + } else { + $url_error = false; + } + $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'); @@ -378,7 +401,7 @@ class ProfileModule extends PLModule $page->assign('address', array()); } - function handler_ajax_tel(&$page, $prefid, $prefname, $telid) + function handler_ajax_tel(&$page, $prefid, $prefname, $telid, $subField, $mainField, $mainId) { pl_content_headers("text/html"); $page->changeTpl('profile/phone.tpl', NO_SKIN); @@ -387,6 +410,11 @@ class ProfileModule extends PLModule $page->assign('telid', $telid); $phone = new Phone(); $page->assign('tel', $phone->toFormArray()); + if ($mainField) { + $page->assign('subField', $subField); + $page->assign('mainField', $mainField); + $page->assign('mainId', $mainId); + } } function handler_ajax_edu(&$page, $eduid, $class) @@ -586,8 +614,9 @@ class ProfileModule extends PLModule } $res .= "\n"; } - XDB::query('REPLACE INTO search_autocomplete - VALUES ({?}, {?}, {?}, NOW())', + XDB::query('INSERT INTO search_autocomplete (name, query, result, generated) + VALUES ({?}, {?}, {?}, NOW()) + ON DUPLICATE KEY UPDATE result = VALUES(result), generated = VALUES(generated)', $type, $q_normalized, $res); echo $res; exit(); @@ -666,13 +695,14 @@ class ProfileModule extends PLModule S::assert_xsrf_token(); $data = file_get_contents($_FILES['userfile']['tmp_name']); - list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']); - $mimetype = substr($_FILES['userfile']['type'], 6); - unlink($_FILES['userfile']['tmp_name']); - XDB::execute( - "REPLACE INTO profile_photos SET pid={?}, attachmime = {?}, attach={?}, x={?}, y={?}", - $user->profile()->id(), $mimetype, $data, $x, $y); - break; + list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']); + $mimetype = substr($_FILES['userfile']['type'], 6); + unlink($_FILES['userfile']['tmp_name']); + XDB::execute('INSERT INTO profile_photos (pid, attachmime, attach, x, y) + VALUES ({?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)', + $user->profile()->id(), $mimetype, $data, $x, $y); + break; case "delete": S::assert_xsrf_token();