X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile.php;h=5a23f8057bb1b930f9f9b06e398f4b683eacfad6;hb=723d4c6b7736df20e07d2c6e32e4c37c6c80ca05;hp=e3239d28a59d05636759c9cc36e39317fa9c77f5;hpb=1c4a1d0a32c52851e9ffbbf585bb206c9a472dc9;p=platal.git diff --git a/modules/profile.php b/modules/profile.php index e3239d2..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()); @@ -310,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'); @@ -387,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); @@ -396,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) @@ -595,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(); @@ -675,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();