Commit 326c2ed8 authored by Romain Loth's avatar Romain Loth

restore labs_list detailed infos for print_directory (contact, institution,...

restore labs_list detailed infos for print_directory (contact, institution, search links if no homepage)
parent 26992806
...@@ -46,4 +46,44 @@ $resultat=mysql_query($sql); ...@@ -46,4 +46,44 @@ $resultat=mysql_query($sql);
} }
return $out; return $out;
} }
// prepend scheme to homepage
// NB well-formedness not tested, should be done before recording
function homepage_to_alink($somelinkstr) {
$www = '';
if (substr($somelinkstr, 0, 3) === 'www') {
$www = ' <a href="'.trim('http://'.$somelinkstr).'" target=blank >' ;
$www .= $somelinkstr ;
$www .= '</a ><br/>';
}
elseif (substr($somelinkstr, 0, 4) === 'http') {
$www =' <a href="'.$somelinkstr.'" target=blank > ' ;
$www .= $somelinkstr ;
$www .= '</a ><br/>';
}
return $www ;
}
// search on ISCPIF's local search engine
function web_search($a_query_string, $exact=false) {
if ($exact) {
$a_query_string = '"'.$a_query_string.'"' ;
}
return 'https://search.iscpif.fr/?q='.urlencode($a_query_string);
}
// replace '@' and dots to avoid the email being harvested by robots/spiders
function safe_email($email_str) {
return preg_replace(
'/\./', '[dot]',
preg_replace(
'/@/', '[at]',
$email_str
)
);
}
?> ?>
This diff is collapsed.
...@@ -11,6 +11,11 @@ foreach ($labs as $lab) { ...@@ -11,6 +11,11 @@ foreach ($labs as $lab) {
set_time_limit(20); set_time_limit(20);
} }
$loop+=1; $loop+=1;
if ($lab['name'] == '_NULL') {
continue;
}
$content.= '<div class="row"> $content.= '<div class="row">
<div class="span12"> <div class="span12">
<div class="row"> <div class="row">
...@@ -18,46 +23,60 @@ foreach ($labs as $lab) { ...@@ -18,46 +23,60 @@ foreach ($labs as $lab) {
$content .= '<div>'; $content .= '<div>';
$content .= '<h2 >' . $lab['name']; $content .= '<h2 >' . $lab['name'];
if ($lab['acronym'] != null){ if (strlen($lab['acronym'])){
$content.=' ('.$lab['acronym'].')'; $content.=' (<b>'.$lab['acronym'].'</b>)';
} }
$content.=' <small> - ' . $lab['country'] . '</small></h2>'; $content.=' <small> - ' . $lab['locname'] . '</small></h2>';
// var_dump($lab); // var_dump($lab);
$www = ''; $www = '';
if (array_key_exists('homepage', $lab)) { if (array_key_exists('homepage', $lab) && strlen($lab['homepage'])) {
if (substr($lab['homepage'], 0, 3) === 'www') { $www = homepage_to_alink($lab['homepage']);
$www.=' <a href=' . trim(str_replace('&', ' and ', 'http://' . $lab['homepage'])) . ' target=blank > ' . trim(str_replace('&', ' and ', 'http://' . $lab['homepage'])) . ' </a ><br/>'; $content .= '<dl><dd><i class="icon-home"></i>'.$www.'</dd></dl>';
} elseif (substr($lab['homepage'], 0, 4) === 'http') { }
$www.=' <a href=' . trim(str_replace('&', ' and ', $lab['homepage'])) . ' target=blank > ' . trim(str_replace('&', ' and ', $lab['homepage'])) . ' </a ><br/>'; else {
$search_elements = array();
foreach($lab as $key => $val) {
if ($key == 'unique_id' || $key == 'admin') {
continue;
}
elseif ($key == 'related_insts' && count($lab['related_insts'])) {
// we use only the most frequent one for search context
$search_elements[] = $lab['related_insts'][0];
}
else {
// ... and we add all other strings (name, acro, lab_code, loc)
if ($val && strlen($val) > 2) {
$search_elements[] = $val;
}
}
} }
// print_r($search_elements) ;
$www = web_search(implode(', ', $search_elements));
if (strcmp($www, '') != 0) { // print_r($www);
$content .= '<dl><dd><i class="icon-home"></i>' . $www . '</dd></dl> ';
}
}
if ($lab['organization'] != null) { $content .= '<dl><dd><a href="'.$www.'"><small>search</small></a><i class="icon-search"></i></dd></dl>';
$content .= '<dl>
<dt>Institutions:</dt>';
} }
$lab_code = '';
if ($lab['organization'] != null) { if (array_key_exists('lab_code', $lab) && strlen($lab['lab_code'])) {
$content .= '<dd>' . $lab['organization'] . '</dd> '; $exact_search = 'https://search.iscpif.fr/?q='.urlencode('"'.$lab['lab_code'].'"');
} $content .= '<dl><dd><i class="icon-flag"></i>' ;
if (array_key_exists('organization2', $lab) && $lab['organization2'] != null) { $content .= '<a href="'.web_search($lab['lab_code'], true).'">';
$content .= '<dd>' . $lab['organization2'] . '</dd> '; $content .= $lab['lab_code'].'</a></dd></dl>';
} }
if (($lab['organization'] != null) $n_related_insts = count($lab['related_insts']);
|| (array_key_exists('organization2', $lab) && $lab['organization2'] != null)) { if ($n_related_insts) {
$content .= '<br/>'; $content .= '<dl>
} <dt>Institutions:</dt>';
foreach ($lab['related_insts'] as $rinstitution) {
$content .= '<dd class="parent-org">' . $rinstitution . '</dd> ';
}
if ($lab['organization'] != null) {
$content .= '</dl>'; $content .= '</dl>';
} }
...@@ -65,60 +84,28 @@ foreach ($labs as $lab) { ...@@ -65,60 +84,28 @@ foreach ($labs as $lab) {
$content .= '</div>'; $content .= '</div>';
// LABS MORE INFOS: object, methods, director, keywords, address, phone // LABS MORE INFOS: admin (ie contact person),
// // keywords (not used but POSS if orgs_kwid map)
// if ((trim($lab['object']) != null) || ($lab['methods'] != null)) {
// $content .= '<div><p>';
// if (trim($lab['methods']) != null) {
// $content .= '<b>Methods: </b> ' . str_replace('%%%', ', ',clean_exp($lab['methods'])) . '<br/><br/>';
// }
//
// if (trim($lab['object']) != null) {
// $content .= '<b>Objects: </b> ' .str_replace('%%%', ', ',clean_exp($lab['object'])) . '<br/><br/>';
// }
// $content .= '</p></div>';
// }
// if ($lab['director'] != null) {
// $content .= '<div>';
// $content .= $content .= '<i class="icon-user"></i> ' . $lab['director'] . '<br/><br/>';
// $content .= '</div>';
// }
// $content .= '</div>';
//
// if (($lab['keywords'] != null) || ($lab['address'] != null) || ($lab['phone'] != null)) {
// $content .= '<div class="span3" align="justify">';
//
// if ($lab['keywords'] != null) {
//
// $content .= '<i class="icon-tags"></i> ' . $lab['keywords'] . '<br/><br/>';
// }
//
//
//
// if ($lab['admin'] != null) {
// $content .= '<address><i class="icon-info-sign"></i> Administrative contact: ' . ucwords($lab['admin']) . '<br/></address>';
// }
// if ($lab['address'] != null) {
// $content .= '<address><i class="icon-envelope"></i> ' . $lab['address'] . '<br/></address>';
// }
//
//
// if (($lab['phone'] != null)||($lab['fax'] != null)) {
// $content .= '<address><strong>Phone</strong>: '.$lab['phone'] . '<br/>';
// if ($lab['fax'] != null) {
// $content .='<strong>Fax</strong>: '.$lab['fax'] . '<br/>';
// }
// }
//
// $content .= '</div>';
// }
$has_admin = array_key_exists('admin', $lab) && strlen($lab['admin']);
$has_kws = array_key_exists('keywords', $lab) && strlen($lab['keywords']);
if ($has_admin || $has_kws) {
$content .= '<div class="span3" align="justify">';
if ($has_kws) {
$content .= '<i class="icon-tags"></i> ' . $lab['keywords'] . '<br/><br/>';
}
if ($has_admin) {
$content .= '<address><i class="icon-info-sign"></i> Administrative contact:<br>' . $lab['admin'] . '<br></address>';
}
$content .= '</div>';
}
$content .= '</div></div></div>'; $content .= '</div></div></div>';
$content .= ' $content .= '
<center><img src="static/img/bar.png"></center>'; <center><img src="static/img/bar.png"></center>';
$content .= '<br/>'; $content .= '<br/>';
$content .= '<br/>'; $content .= '<br/>';
// fin du profil // fin du profil de labo
} }
?> ?>
<?php <?php
// NOT USED ANYMORE: duplicate with labs_list
$content .='<br/> $content .='<br/>
...@@ -35,14 +34,10 @@ foreach ($organiz as $orga) { ...@@ -35,14 +34,10 @@ foreach ($organiz as $orga) {
$www = ''; $www = '';
if (substr($orga['homepage'], 0, 3) === 'www') { if (array_key_exists('homepage', $lab) && strlen($lab['homepage'])) {
$www.=' <a href=' . trim(str_replace('&', ' and ', 'http://' . $orga['homepage'])) . ' target=blank > ' . trim(str_replace('&', ' and ', 'http://' . $orga['homepage'])) . ' </a ><br/>'; $www = homepage_to_alink($lab['homepage']);
} elseif (substr($orga['homepage'], 0, 4) === 'http') {
$www.=' <a href=' . trim(str_replace('&', ' and ', $orga['homepage'])) . ' target=blank > ' . trim(str_replace('&', ' and ', $orga['homepage'])) . ' </a ><br/>';
}
if (strcmp($www, '') != 0) { $content .= '<dl><dd><span class="glyphicon glyphicon-home"></span>'.$www.'</dd></dl>';
$content .= '<dl><dd><i class="icon-home"></i>' . $www . '</dd></dl> ';
} }
......
...@@ -15,8 +15,11 @@ $MIN_DISTINCT_INSTS = 4 ; ...@@ -15,8 +15,11 @@ $MIN_DISTINCT_INSTS = 4 ;
$country_list = array(); $country_list = array();
$position_list = array(); $position_list = array();
$title_list = array(); $title_list = array();
$labs_list = array();
$insts_list = array();
// not needed already factorized in lab_counts, inst_counts
// $labs_list = array();
// $insts_list = array();
$other_country = 0; $other_country = 0;
$other_title = 0; $other_title = 0;
...@@ -112,41 +115,6 @@ foreach ($scholars as $row) { ...@@ -112,41 +115,6 @@ foreach ($scholars as $row) {
$title_list[$title] = 1; $title_list[$title] = 1;
} }
} }
// split et recensement des organismes de rattachement
// 1- labos
foreach ($row['labs'] as $lab) {
$lab = trim($lab);
// POSS ideally restore NON NULL labs
// but some users never provided any
if (strcmp($lab, "") == 0 || preg_match('/^_NULL/', $lab)) {
$missing_labs+=1;
}
else {
// >> $labs_list counts
if (array_key_exists($lab, $labs_list)) {
$labs_list[$lab]+=1;
} else {
$labs_list[$lab] = 1;
}
}
}
// 2 - same for institutions
foreach ($row['institutions'] as $inst) {
$inst = trim($inst);
if (strcmp($inst, "") == 0 || preg_match('/^_NULL/', $inst)) {
$missing_insts+=1;
}
else {
// >> $insts_list counts
if (array_key_exists($inst, $insts_list)) {
$insts_list[$inst]+=1;
} else {
$insts_list[$inst] = 1;
}
}
}
} }
...@@ -154,8 +122,8 @@ foreach ($scholars as $row) { ...@@ -154,8 +122,8 @@ foreach ($scholars as $row) {
asort($country_list); asort($country_list);
asort($position_list); asort($position_list);
asort($title_list); asort($title_list);
asort($labs_list); asort($lab_counts);
asort($insts_list); asort($inst_counts);
...@@ -237,9 +205,9 @@ $title_data.=']'; ...@@ -237,9 +205,9 @@ $title_data.=']';
// données des institutions/affiliations // données des institutions/affiliations
$labs_data = "data: ["; $labs_data = "data: [";
$n_labs = count($labs_list); $n_labs = count($lab_counts);
$n_shown_labs = 0 ; $n_shown_labs = 0 ;
foreach ($labs_list as $key => $value) { foreach ($lab_counts as $key => $value) {
$key = addslashes($key); $key = addslashes($key);
if ($value > min(9, $n_labs / 15)) { if ($value > min(9, $n_labs / 15)) {
...@@ -263,9 +231,9 @@ $labs_data.=']'; ...@@ -263,9 +231,9 @@ $labs_data.=']';
$insts_data = "data: ["; $insts_data = "data: [";
$n_insts = count($insts_list); $n_insts = count($inst_counts);
$n_shown_insts = 0 ; $n_shown_insts = 0 ;
foreach ($insts_list as $key => $value) { foreach ($inst_counts as $key => $value) {
$key = addslashes($key); $key = addslashes($key);
if ($value > min(9, $n_insts / 15)) { if ($value > min(9, $n_insts / 15)) {
......
...@@ -257,6 +257,14 @@ if (substr($labfilter, 0,3)=='AND'){ ...@@ -257,6 +257,14 @@ if (substr($labfilter, 0,3)=='AND'){
$imsize = 150; $imsize = 150;
// these stats are useful BOTH in stat-prep and directory_content
// => should be prepared right now (the label mapping contain all orgs ie both labs and institutions)
$lab_counts = array();
$inst_counts = array();
$org_id_to_label = array();
// MAIN HTML CONTENT
$content=''; $content='';
// error_log("=======> WHERE filters {$f}"); // error_log("=======> WHERE filters {$f}");
...@@ -279,17 +287,18 @@ SELECT * FROM ( ...@@ -279,17 +287,18 @@ SELECT * FROM (
FROM ( FROM (
SELECT SELECT
scholars_and_orgs.*, scholars_and_orgs.*,
GROUP_CONCAT(kwstr) AS keywords_list GROUP_CONCAT(kwstr) AS keywords_list,
COUNT(keywords.kwid) AS keywords_nb
FROM ( FROM (
SELECT SELECT
scholars_and_labs.*, scholars_and_labs.*,
-- GROUP_CONCAT(insts.orgid SEPARATOR ',') AS insts_ids, GROUP_CONCAT(insts.orgid SEPARATOR ',') AS insts_ids,
GROUP_CONCAT(insts.tostring SEPARATOR '%%%') AS insts_list GROUP_CONCAT(insts.tostring SEPARATOR '%%%') AS insts_list
FROM ( FROM (
SELECT SELECT
scholars.*, scholars.*,
-- GROUP_CONCAT(labs.orgid SEPARATOR ',') AS labs_ids, GROUP_CONCAT(labs.orgid SEPARATOR ',') AS labs_ids,
GROUP_CONCAT(labs.tostring SEPARATOR '%%%') AS labs_list GROUP_CONCAT(labs.tostring SEPARATOR '%%%') AS labs_list
FROM scholars FROM scholars
LEFT JOIN sch_org AS map_labs LEFT JOIN sch_org AS map_labs
...@@ -359,10 +368,15 @@ foreach ($base->query($sql) as $row) { ...@@ -359,10 +368,15 @@ foreach ($base->query($sql) as $row) {
$info['labs'] = explode('%%%', $row['labs_list'] ?? "") ; $info['labs'] = explode('%%%', $row['labs_list'] ?? "") ;
$info['institutions'] = explode('%%%', $row['insts_list'] ?? "") ; $info['institutions'] = explode('%%%', $row['insts_list'] ?? "") ;
$info['labs_ids'] = explode(',', $row['labs_ids'] ?? "") ;
$info['insts_ids'] = explode(',', $row['insts_ids'] ?? "") ;
$info['title'] = $row['hon_title']; $info['title'] = $row['hon_title'];
$info['position'] = $row['position']; $info['position'] = $row['position'];
$info['pic_src'] = $row['pic_fname'] ? '/data/shared_user_img/'.$row['pic_fname'] : $row['pic_url'] ; $info['pic_src'] = $row['pic_fname'] ? '/data/shared_user_img/'.$row['pic_fname'] : $row['pic_url'] ;
$info['interests'] = $row['interests_text']; $info['interests'] = $row['interests_text'];
// $info['address'] = $row['address']; // $info['address'] = $row['address'];
// $info['city'] = $row['city']; // $info['city'] = $row['city'];
// $info['postal_code'] = $row['postal_code']; // $info['postal_code'] = $row['postal_code'];
...@@ -371,8 +385,52 @@ foreach ($base->query($sql) as $row) { ...@@ -371,8 +385,52 @@ foreach ($base->query($sql) as $row) {
// $info['fax'] = $row['fax']; // $info['fax'] = $row['fax'];
// $info['affiliation_acronym'] = $row['affiliation_acronym']; // $info['affiliation_acronym'] = $row['affiliation_acronym'];
$scholars[$row['luid']] = $info; $scholars[$row['luid']] = $info;
// we prepare the agregated lab stats in this loop too
foreach ( array(
array('labs','labs_ids', &$lab_counts),
array('institutions','insts_ids', &$inst_counts)
) as $cat) {
// var_dump($cat);
$namekey = $cat[0];
$idkey = $cat[1];
$counthash_ref = &$cat[2];
// £TODO_ORGS we'll need a missing_labs
$j = -1 ;
foreach ($info[$idkey] as $org_id) {
$j++;
$org_label = $info[$namekey][$j];
$org_label = trim($org_label);
if (strcmp($org_label, "") == 0) {
$org_label = null;
} else {
$org_label = weedout_alt_nulls($org_label);
}
// all non-values are there as null
$org_id_to_label[$org_id] = $org_label;
if (array_key_exists($org_id, $counthash_ref)) {
$counthash_ref[$org_id]+=1;
} else {
$counthash_ref[$org_id] = 1;
}
}
}
} }
// creates js for stats visualisations
// both our stats have been filled
// var_dump($lab_counts) ;
// var_dump($inst_counts) ;
// creates js for stats visualisations and counts (we re-use the orgs counts)
include ("php_library/stat-prep_from_array.php"); include ("php_library/stat-prep_from_array.php");
// debug // debug
...@@ -383,8 +441,6 @@ include ("php_library/directory_content.php"); ...@@ -383,8 +441,6 @@ include ("php_library/directory_content.php");
$content .= '</div>'; $content .= '</div>';
$content .= '</div> $content .= '</div>
<footer style="color:white"> <footer style="color:white">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment