From 6fc390c771618c19a6af41c70ec5aa8f197e8bf0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Wed, 8 Dec 2010 11:42:49 +0100 Subject: [PATCH] Prevents profile's subitems to be more public than the item they belong to (client side). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- htdocs/javascript/profile.js | 64 ++++++++++++++++++++++++++++------ modules/profile.php | 7 +++- templates/include/emails.combobox.tpl | 7 +++- templates/include/flags.radio.tpl | 6 ++-- templates/profile/adresses.address.tpl | 17 ++++----- templates/profile/general.tpl | 2 +- templates/profile/jobs.job.tpl | 27 ++++++++------ templates/profile/phone.tpl | 8 +++-- 8 files changed, 101 insertions(+), 37 deletions(-) diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index dcd3fec..a173e4b 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -45,7 +45,7 @@ function wizPage_onLoad(id) } break; case 'emploi': - if ($('#job_0').find("[name='jobs[0][name]']").val() == '') { + if ($('#jobs_0').find("[name='jobs[0][name]']").val() == '') { registerEnterpriseAutocomplete(0); } break; @@ -58,6 +58,12 @@ var educationDegreeName; var subgrades; var names; +// Publicity follows the following ordering: private < ax < public. +var publicity = []; +publicity['private'] = 0; +publicity['ax'] = 1; +publicity['public'] = 2; + // Names {{{1 function toggleNamesAdvanced() @@ -339,7 +345,7 @@ function validGeoloc(prefid, id, geoloc) // {{{1 Phones -function addTel(prefid, prefname) +function addTel(prefid, prefname, subField, mainField, mainId) { var i = 0; var prefix = prefid + '_'; @@ -347,7 +353,7 @@ function addTel(prefid, prefname) i++; } $('#' + prefix + 'add').before('
'); - Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i); + Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i + '/' + subField + '/' + mainField + '/' + mainId); } function removeTel(prefname, prefid, id) @@ -519,7 +525,7 @@ function makeAddJob(id) function addJob() { var i = 0; - while ($('#job_' + i).length != 0) { + while ($('#jobs_' + i).length != 0) { ++i; } $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i)); @@ -547,23 +553,23 @@ function addJobTerm(jobid, jtid, full_name) jobid = ''; formvarname = 'terms'; } else { - parentpath = '#job_'+jobid+' '; + parentpath = '#jobs_'+jobid+' '; formvarname = 'jobs['+jobid+'][terms]'; } - var lastJobTerm = $(parentpath + '.job_term:last'); + var lastJobTerm = $(parentpath + '.jobs_term:last'); if (lastJobTerm.length != 0) { termid = parseInt(lastJobTerm.children('input').attr('name').replace(/^(jobs\[[0-9]+\]\[terms\]|terms)\[([0-9]+)\]\[jtid\]/, '$2')) + 1; if ($('#job'+jobid+'_term'+jtid).length > 0) { return false; } } - var newdiv = '
'+ + var newdiv = '
'+ ''+full_name+''+ ''+ 'retirer'+ '
'; if (lastJobTerm.length == 0) { - $(parentpath + '.job_terms').prepend(newdiv); + $(parentpath + '.jobs_terms').prepend(newdiv); } else { lastJobTerm.after(newdiv); } @@ -611,7 +617,7 @@ function selectJobTerm(li) if (jobid < 0) { search_input = $('.term_search')[0]; } else { - search_input = $('#job_'+jobid+' .term_search')[0]; + search_input = $('#jobs_'+jobid+' .term_search')[0]; } if (li.extra[0] >= 0) { search_input.value = ''; @@ -632,7 +638,7 @@ function toggleJobTermsTree(jobid, textfilter) if (jobid < 0) { treepath = ''; } else { - treepath = '#job_'+jobid+' '; + treepath = '#jobs_'+jobid+' '; } treepath += '.term_tree'; if ($(treepath + ' ul').length > 0) { @@ -733,4 +739,42 @@ function removeElement(cat, id) updateElement(cat); } +function updateSubPublicity(subFieldId, name, mainPub) +{ + var subPub = $(subFieldId).find("[name='" + name + "']:checked").val(); + if (publicity[subPub] > publicity[mainPub]) { + $(subFieldId).find("[name='" + name + "']:checked").removeAttr('checked'); + $(subFieldId).find('[value=' + mainPub + ']').attr('checked', 'checked'); + } +} + +function updatePublicity(mainField, mainId, subField, subId) +{ + var mainFieldId = '#' + mainField + '_' + mainId; + var mainPub = $(mainFieldId).find("[name='" + mainField + "[" + mainId + "][pub]']:checked").val(); + if (subId == -1) { + var subFields = subField.split(','); + for (var i =0; i < subFields.length; ++i) { + var subFieldBaseId = mainFieldId + '_' + subFields[i]; + var name = mainField + '[' + mainId + '][' + subFields[i] + ']'; + if ($(subFieldBaseId).length != 0) { + updateSubPublicity(subFieldBaseId, name + '[pub]', mainPub); + updateSubPublicity(subFieldBaseId, mainField + '[' + mainId + '][' + subFields[i] + '_pub]', mainPub); + } + subId = 0; + while ($(subFieldBaseId + '_' + subId).length != 0) { + updateSubPublicity(subFieldBaseId + '_' + subId, name + '[' + subId + '][pub]', mainPub); + ++subId; + } + } + } else { + if (subId == '') { + updateSubPublicity(mainFieldId + '_' + subField, mainField + '[' + mainId + '][' + subField + '_pub]', mainPub); + updateSubPublicity(mainFieldId + '_' + subField, mainField + '[' + mainId + '][' + subField + '][pub]', mainPub); + } else { + updateSubPublicity(mainFieldId + '_' + subField + '_' + subId, mainField + '[' + mainId + '][' + subField + '][' + subId + '][pub]', mainPub); + } + } +} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/modules/profile.php b/modules/profile.php index 1c1d61a..5a23f80 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -401,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); @@ -410,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) diff --git a/templates/include/emails.combobox.tpl b/templates/include/emails.combobox.tpl index f0b1067..518bda8 100644 --- a/templates/include/emails.combobox.tpl +++ b/templates/include/emails.combobox.tpl @@ -22,7 +22,7 @@ {assign var=new value="new"|cat:$i} {assign var=combobox value="combobox"|cat:$i} - + {if $name eq "email_directory"} Email annuaire AX @@ -89,8 +89,13 @@ {icon name="flag_orange" title="Visible sur l'annuaire"} {elseif $name neq "email"} + {if t($mainField)} + {include file="include/flags.radio.tpl" name="`$jobpref`[`$prefix`email_pub]" val=$pub + mainField=$mainField mainId=$mainId subField=$subField subId=$subId} + {else} {include file="include/flags.radio.tpl" name="`$jobpref`[`$prefix`email_pub]" val=$pub} {/if} + {/if}
{/if} diff --git a/templates/include/flags.radio.tpl b/templates/include/flags.radio.tpl index 0cbd313..6059b43 100644 --- a/templates/include/flags.radio.tpl +++ b/templates/include/flags.radio.tpl @@ -24,15 +24,15 @@ {/if} {if !t($val)}{assign var=val value='ax'}{/if} {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/profile/adresses.address.tpl b/templates/profile/adresses.address.tpl index 207b1e0..69ebf09 100644 --- a/templates/profile/adresses.address.tpl +++ b/templates/profile/adresses.address.tpl @@ -59,7 +59,7 @@
- {include file="include/flags.radio.tpl" name="`$prefname`[pub]" val=$address.pub} + {include file="include/flags.radio.tpl" name="`$prefname`[pub]" val=$address.pub mainField='addresses' mainId=$i subField='phones' subId=-1}
@@ -119,18 +119,19 @@ {foreach from=$address.phones key=t item=tel} -
- {include file="profile/phone.tpl" prefname="`$prefname`[phones]" - prefid="`$prefid`_tel" telid=$t tel=$tel} +
+ {include file="profile/phone.tpl" prefname="`$prefname`[phones]" prefid="`$prefid`_phones" telid=$t tel=$tel + subField='phones' mainField='addresses' mainId=$i}
{/foreach} {if $address.phones|@count eq 0} -
- {include file="profile/phone.tpl" prefname="`$prefname`[phones]" prefid="`$prefid`_tel" telid=0 tel=0} +
+ {include file="profile/phone.tpl" prefname="`$prefname`[phones]" prefid="`$prefid`_phones" telid=0 tel=0 + subField='phones' mainField='addresses' mainId=$i}
{/if} -
- + diff --git a/templates/profile/general.tpl b/templates/profile/general.tpl index 38beb25..5636c15 100644 --- a/templates/profile/general.tpl +++ b/templates/profile/general.tpl @@ -281,7 +281,7 @@
{/if} diff --git a/templates/profile/jobs.job.tpl b/templates/profile/jobs.job.tpl index 0fbb748..a1836c8 100644 --- a/templates/profile/jobs.job.tpl +++ b/templates/profile/jobs.job.tpl @@ -22,7 +22,7 @@ -{assign var=jobid value="job_"|cat:$i} +{assign var=jobid value="jobs_"|cat:$i} {assign var=jobpref value="jobs[`$i`]"} {assign var=sector_text value="sector_text_"|cat:$i} {assign var=sector value="sector_"|cat:$i} @@ -52,7 +52,8 @@
- {include file="include/flags.radio.tpl" name="`$jobpref`[pub]" val=$job.pub disabled=$hiddenjob} + {include file="include/flags.radio.tpl" name="`$jobpref`[pub]" val=$job.pub disabled=$hiddenjob + mainField='jobs' mainId=$i subField='w_address,w_email,w_phone' subId=-1}
Entreprise n°{$i+1} : {if $hiddenjob} @@ -121,7 +122,7 @@ Mots-clefs - + {icon name="table" title="Tous les mots-clefs"}