<?php
/***************************************************************************
- * Copyright (C) 2003-2011 Polytechnique.org *
+ * Copyright (C) 2003-2014 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
{
return array(
'photo' => $this->make_hook('photo', AUTH_PUBLIC),
- 'photo/change' => $this->make_hook('photo_change', AUTH_MDP),
+ 'photo/change' => $this->make_hook('photo_change', AUTH_PASSWD, 'user'),
'fiche.php' => $this->make_hook('fiche', AUTH_PUBLIC),
'profile' => $this->make_hook('profile', AUTH_PUBLIC),
- 'profile/private' => $this->make_hook('profile', AUTH_COOKIE),
+ 'profile/private' => $this->make_hook('profile', AUTH_COOKIE, 'user'),
'profile/ax' => $this->make_hook('ax', AUTH_COOKIE, 'admin,edit_directory'),
- 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP),
+ 'profile/edit' => $this->make_hook('p_edit', AUTH_PASSWD, 'user'),
'profile/ajax/address' => $this->make_hook('ajax_address', AUTH_COOKIE, 'user', NO_AUTH),
- 'profile/ajax/address/del' => $this->make_hook('ajax_address_del', AUTH_MDP),
+ 'profile/ajax/address/del' => $this->make_hook('ajax_address_del', AUTH_PASSWD, 'user'),
'profile/ajax/tel' => $this->make_hook('ajax_tel', AUTH_COOKIE, 'user', NO_AUTH),
'profile/ajax/edu' => $this->make_hook('ajax_edu', AUTH_COOKIE, 'user', NO_AUTH),
'profile/ajax/medal' => $this->make_hook('ajax_medal', AUTH_COOKIE, 'user', NO_AUTH),
'profile/ajax/buildnames' => $this->make_hook('ajax_buildnames', AUTH_COOKIE, 'user', NO_AUTH),
'profile/ajax/tree/jobterms' => $this->make_hook('ajax_tree_job_terms', AUTH_COOKIE, 'user', NO_AUTH),
'profile/jobterms' => $this->make_hook('jobterms', AUTH_COOKIE, 'user', NO_AUTH),
- 'javascript/education.js' => $this->make_hook('education_js', AUTH_COOKIE),
- 'javascript/grades.js' => $this->make_hook('grades_js', AUTH_COOKIE),
+ 'javascript/education.js' => $this->make_hook('education_js', AUTH_COOKIE, 'user'),
+ 'javascript/grades.js' => $this->make_hook('grades_js', AUTH_COOKIE, 'user'),
'profile/medal' => $this->make_hook('medal', AUTH_PUBLIC),
- 'referent' => $this->make_hook('referent', AUTH_COOKIE),
+ 'referent' => $this->make_hook('referent', AUTH_COOKIE, 'user'),
'referent/country' => $this->make_hook('ref_country', AUTH_COOKIE, 'user', NO_AUTH),
'referent/autocomplete' => $this->make_hook('ref_autocomplete', AUTH_COOKIE, 'user', NO_AUTH),
- 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE),
+ 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE, 'groups'),
'groupes-x/logo' => $this->make_hook('xnetlogo', AUTH_PUBLIC),
'vcard' => $this->make_hook('vcard', AUTH_COOKIE, 'user', NO_HTTPS),
- 'admin/binets' => $this->make_hook('admin_binets', AUTH_MDP, 'admin'),
- 'admin/medals' => $this->make_hook('admin_medals', AUTH_MDP, 'admin'),
- 'admin/education' => $this->make_hook('admin_education', AUTH_MDP, 'admin'),
- 'admin/education_field' => $this->make_hook('admin_education_field', AUTH_MDP, 'admin'),
- 'admin/education_degree' => $this->make_hook('admin_education_degree', AUTH_MDP, 'admin'),
- 'admin/education_degree_set' => $this->make_hook('admin_education_degree_set', AUTH_MDP, 'admin'),
- 'admin/sections' => $this->make_hook('admin_sections', AUTH_MDP, 'admin'),
- 'admin/networking' => $this->make_hook('admin_networking', AUTH_MDP, 'admin'),
- 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP, 'admin'),
- 'admin/corps_enum' => $this->make_hook('admin_corps_enum', AUTH_MDP, 'admin'),
- 'admin/corps_rank' => $this->make_hook('admin_corps_rank', AUTH_MDP, 'admin'),
+ 'admin/binets' => $this->make_hook('admin_binets', AUTH_PASSWD, 'admin'),
+ 'admin/medals' => $this->make_hook('admin_medals', AUTH_PASSWD, 'admin'),
+ 'admin/education' => $this->make_hook('admin_education', AUTH_PASSWD, 'admin'),
+ 'admin/education_field' => $this->make_hook('admin_education_field', AUTH_PASSWD, 'admin'),
+ 'admin/education_degree' => $this->make_hook('admin_education_degree', AUTH_PASSWD, 'admin'),
+ 'admin/education_degree_set' => $this->make_hook('admin_education_degree_set', AUTH_PASSWD, 'admin'),
+ 'admin/sections' => $this->make_hook('admin_sections', AUTH_PASSWD, 'admin'),
+ 'admin/networking' => $this->make_hook('admin_networking', AUTH_PASSWD, 'admin'),
+ 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_PASSWD, 'admin'),
+ 'admin/corps_enum' => $this->make_hook('admin_corps_enum', AUTH_PASSWD, 'admin'),
+ 'admin/corps_rank' => $this->make_hook('admin_corps_rank', AUTH_PASSWD, 'admin'),
);
}
if (!$user->hasProfile()) {
return PL_NOT_FOUND;
} else {
- $profile = $user->profile();
+ $profile = $user->profile(false,0,Visibility::get(Visibility::VIEW_ADMIN));
}
} else {
- $profile = Profile::get($hrpid);
+ $profile = Profile::get($hrpid,0,Visibility::get(Visibility::VIEW_ADMIN));
}
if (!$profile) {
}
// Determines the access level at which the profile will be displayed.
- if (!S::logged() || !S::user()->checkPerms('directory_ax') || Env::v('view') == 'public') {
- $view = 'public';
- } else if (!S::user()->checkPerms('directory_private') || Env::v('view') == 'ax') {
- $view = 'ax';
+ // Note: VIEW_HIDDEN can NOT be selected. The admins who want to read
+ // information need to use the "edit profile" pages instead.
+ if (Env::v('view') == 'public') {
+ $view = Visibility::VIEW_PUBLIC;
+ } else if (Env::v('view') == 'ax') {
+ $view = Visibility::VIEW_AX;
} else {
- $view = 'private';
+ $view = Visibility::VIEW_PRIVATE;
}
+ $visibility = Visibility::defaultForRead($view);
// Display pending picture
if (S::logged() && Env::v('modif') == 'new') {
if (is_null($pid)) {
$owner = User::getSilent($id);
if ($owner) {
- $profile = $owner->profile(true, Profile::FETCH_ALL, $view);
+ $profile = $owner->profile(true, Profile::FETCH_ALL, $visibility);
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);
+ $profile = Profile::get($pid, Profile::FETCH_ALL, $visibility);
$owner = $profile->owner();
}
if (is_null($pid)) {
}
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);
$page->setTitle($profile->fullName());
// Determines and displays the virtual alias.
- if (!is_null($owner) && $profile->alias_pub == 'public') {
+ if (!is_null($owner) && $profile->isVisible($profile->alias_pub)) {
$page->assign('virtualalias', $owner->emailAlias());
}
$page->assign_by_ref('profile', $profile);
$page->assign_by_ref('owner', $owner);
- $page->assign('view', $view);
+ $page->assign('view', $visibility);
$page->assign('logged', S::logged());
header('Last-Modified: ' . date('r', strtotime($profile->last_change)));
if (!$user->ax_id) {
$page->kill("Le matricule AX de {$user->hrid()} est inconnu");
}
- http_redirect("http://www.polytechniciens.com/?page=AX_FICHE_ANCIEN&ancc_id=" . $user->ax_id);
+ http_redirect("http://kx.polytechniciens.com/?page=AX_FICHE_ANCIEN&ancc_id=" . $user->ax_id);
}
function handler_p_edit($page, $hrpid = null, $opened_tab = null, $mode = null, $success = null)
{
global $globals;
- if (in_array($hrpid, array('general', 'adresses', 'emploi', 'poly', 'deco', 'skill', 'mentor', 'deltaten'))) {
+ if (in_array($hrpid, array('general', 'adresses', 'emploi', 'poly', 'deco', 'mentor', 'deltaten'))) {
$aux = $opened_tab;
$opened_tab = $hrpid;
$hrpid = $aux;
}
// Build the page
+ $page->addJsLink('jquery.ui.xorg.js');
$page->addJsLink('education.js', true, false); /* dynamic content */
$page->addJsLink('grades.js', true, false); /* dynamic content */
$page->addJsLink('profile.js');
$wiz->addPage('ProfilePageGeneral', 'Général', 'general');
$wiz->addPage('ProfilePageAddresses', 'Adresses personnelles', 'adresses');
$wiz->addPage('ProfilePageJobs', 'Informations professionnelles', 'emploi');
- if (S::user()->checkPerms(User::PERM_DIRECTORY_PRIVATE)) {
+ $viewPrivate = S::user()->checkPerms(User::PERM_DIRECTORY_PRIVATE);
+ if ($viewPrivate) {
$wiz->addPage('ProfilePageGroups', 'Groupes X - Binets', 'poly');
}
$wiz->addPage('ProfilePageDecos', 'Décorations - Medailles', 'deco');
- if (S::user()->checkPerms(User::PERM_DIRECTORY_PRIVATE)) {
- $wiz->addPage('ProfilePageSkills', 'Compétences diverses', 'skill');
+ if ($viewPrivate) {
$wiz->addPage('ProfilePageMentor', 'Mentoring', 'mentor');
}
- if (S::user()->checkPerms(User::PERM_DIRECTORY_PRIVATE) && $profile->isDeltatenEnabled(Profile::DELTATEN_OLD)) {
+ if ($viewPrivate && $profile->isDeltatenEnabled(Profile::DELTATEN_OLD)) {
$wiz->addPage('ProfilePageDeltaten', 'Opération N N-10', 'deltaten');
}
$wiz->apply($page, 'profile/edit/' . $profile->hrid(), $opened_tab, $mode);
$page->setTitle('Mon Profil');
$page->assign('hrpid', $profile->hrid());
+ $page->assign('viewPrivate', $viewPrivate);
+ $page->assign('isMe', S::user()->isMyProfile($profile));
if (isset($success) && $success) {
$page->trigSuccess('Ton profil a bien été mis à jour.');
}
function handler_education_js($page)
{
- pl_cached_content_headers("text/javascript", "utf-8");
+ pl_cached_dynamic_content_headers('text/javascript', 'utf-8');
$page->changeTpl('profile/education.js.tpl', NO_SKIN);
require_once 'education.func.inc.php';
}
pl_content_headers("text/html");
$page->changeTpl('profile/adresses.address.tpl', NO_SKIN);
$page->assign('i', $id);
- $page->assign('address', array());
+ $page->assign('address', array('mail' => true));
$page->assign('profile', Profile::get($pid));
$page->assign('isMe', true);
$page->assign('geocoding_removal', true);
{
pl_content_headers("text/html");
$page->changeTpl('profile/deco.medal.tpl', NO_SKIN);
+ list($valid, $has_levels) = XDB::fetchOneRow("SELECT NOT FIND_IN_SET('validation', flags), FIND_IN_SET('has_levels', flags)
+ FROM profile_medal_enum
+ WHERE id = {?}",
+ $id);
$page->assign('id', $i);
- $page->assign('medal', array('id' => $id, 'grade' => 0, 'valid' => 0));
+ $page->assign('medal', array('id' => $id, 'grade' => 0, 'valid' => $valid, 'has_levels' => $has_levels));
}
function handler_ajax_job($page, $id, $pid)
return PL_NOT_FOUND;
}
+ // Referent view are logged.
+ if (S::logged()) {
+ S::logger()->log('view_referent', $pf->hrid());
+ }
+
$page->assign_by_ref('profile', $pf);
// Retrieves referents' countries.
{
pl_content_headers("text/plain");
- $q = Env::v('q').'%';
+ $q = Env::v('term') . '%';
$tokens = JobTerms::tokenize($q);
if (count($tokens) == 0) {
exit;
sort($tokens);
$q_normalized = implode(' ', $tokens);
- // try to look in cached results
+ // Try to look in cached results.
+ $cached = false;
$cache = XDB::query('SELECT result
FROM search_autocomplete
- WHERE name = {?} AND
- query = {?} AND
- generated > NOW() - INTERVAL 1 DAY',
- $type, $q_normalized);
- if ($res = $cache->fetchOneCell()) {
- echo $res;
- die();
- }
-
- $joins = JobTerms::token_join_query($tokens, 'e');
- if ($type == 'mentor') {
- $count = ', COUNT(DISTINCT pid) AS nb';
- $countjoin = ' INNER JOIN profile_job_term_relation AS r ON(r.jtid_1 = e.jtid) INNER JOIN profile_mentor_term AS m ON(r.jtid_2 = m.jtid)';
- $countorder = 'nb DESC, ';
+ WHERE name = {?} AND query = {?} AND generated > NOW() - INTERVAL 1 DAY',
+ $type, $q_normalized);
+
+ if ($cache->numRows() > 0) {
+ $cached = true;
+ $data = explode("\n", $cache->fetchOneCell());
+ $list = array();
+ foreach ($data as $line) {
+ if ($line != '') {
+ $aux = explode("\t", $line);
+ if ($type == 'mentor') {
+ $item = array(
+ 'field' => $aux[0],
+ 'nb' => $aux[1],
+ 'id' => $aux[2]
+ );
+ $item['value'] = SearchModule::format_autocomplete($item);
+ } else {
+ $item = array(
+ 'value' => $aux[0],
+ 'id' => $aux[1]
+ );
+ }
+ array_push($list, $item);
+ }
+ }
} else {
- $count = $countjoin = $countorder = '';
- }
- $list = XDB::iterator('SELECT e.jtid AS id, e.full_name AS field'.$count.'
- FROM profile_job_term_enum AS e '.$joins.$countjoin.'
- GROUP BY e.jtid
- ORDER BY '.$countorder.'field
- LIMIT 11');
- $nbResults = 0;
- $res = '';
- while ($result = $list->next()) {
- $nbResults++;
- if ($nbResults == 11) {
- $res .= $q."|-1\n";
+ $joins = JobTerms::token_join_query($tokens, 'e');
+ if ($type == 'mentor') {
+ $count = ', COUNT(DISTINCT pid) AS nb';
+ $countjoin = ' INNER JOIN profile_job_term_relation AS r ON(r.jtid_1 = e.jtid) INNER JOIN profile_mentor_term AS m ON(r.jtid_2 = m.jtid)';
+ $countorder = 'nb DESC, ';
+ } else {
+ $count = $countjoin = $countorder = '';
+ }
+ $list = XDB::fetchAllAssoc('SELECT e.jtid AS id, e.full_name AS field' . $count . '
+ FROM profile_job_term_enum AS e ' . $joins . $countjoin . '
+ GROUP BY e.jtid
+ ORDER BY ' . $countorder . 'field
+ LIMIT ' . DirEnumeration::AUTOCOMPLETE_LIMIT);
+ $to_cache = '';
+ if ($type == 'mentor') {
+ foreach ($list as &$item) {
+ $to_cache .= $item['field'] . "\t" . $item['nb'] . "\t" . $item['id'] . "\n";
+ $item['value'] = SearchModule::format_autocomplete($item);
+ }
} else {
- $res .= $result['field'].'|';
- if ($count) {
- $res .= $result['nb'].'|';
+ foreach ($list as &$item) {
+ $to_cache .= $item['field'] . "\t" . $item['id'] . "\n";
+ $item['value'] = $item['field'];
}
- $res .= $result['id'];
}
- $res .= "\n";
}
- 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;
+
+ if (count($list) == DirEnumeration::AUTOCOMPLETE_LIMIT && $type == 'nomentor') {
+ $list[] = array(
+ 'value' => '… parcourir les résultats dans un arbre …',
+ 'field' => '',
+ 'id' => -1
+ );
+ }
+
+ if (!$cached) {
+ 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, $to_cache);
+ }
+ echo json_encode($list);
exit();
}
$table_editor->add_join_table('profile_education', 'eduid', true);
$table_editor->add_join_table('profile_education_degree', 'eduid', true);
$table_editor->describe('name', 'intitulé', true);
- $table_editor->describe('url', 'site web', false);
+ $table_editor->describe('url', 'site web', false, true);
$table_editor->apply($page, $action, $id);
}
function handler_admin_education_field($page, $action = 'list', $id = null) {
$page->assign('title', 'Gestion des types de networking');
$table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'nwid');
$table_editor->describe('name', 'intitulé', true);
- $table_editor->describe('icon', 'nom de l\'icône', false);
+ $table_editor->describe('icon', 'nom de l\'icône', false, true);
$table_editor->describe('filter', 'filtre', true);
$table_editor->describe('link', 'lien web', true);
$table_editor->apply($page, $action, $id);
$page->assign('title', 'Gestion des Distinctions');
$table_editor = new PLTableEditor('admin/medals','profile_medal_enum','id');
$table_editor->describe('text', 'intitulé', true);
- $table_editor->describe('img', 'nom de l\'image', false);
+ $table_editor->describe('img', 'nom de l\'image', false, true);
$table_editor->describe('flags', 'valider', true);
$table_editor->apply($page, $action, $id);
if ($id && $action == 'edit') {
}
}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
?>