Commit 29744782 authored by Romain Loth's avatar Romain Loth

new MySQL connectors for comex directory/filter operations

parent 0d619851
### List of features that where deactivated
During rewrite we deactivated some retrieval to match the new sql tables from registration:
- tables organizations, labs don't exist => TODO RESTORE in `directory_content.php` (and therefore empty arrays are passed to `labs_list.php` and `orga_list.php`)
- in `search_scholar.php`, column nb_keywords doesn't exist (and now keywords are never 0) => TODO RESTORE
- in `print_directory.php`, all the following columns are now ignored: 'nb_keywords', 'css_voter', 'css_member', 'keywords_ids', 'status', 'homepage', 'lab2', 'affiliation2', 'homepage', **'position'** (used in `stats_prep_from_array.php`), 'photo_url', 'address', 'city', 'postal_code', 'phone', 'mobile', 'fax', 'affiliation_acronym' => TODO RESTORE
- in `print_scholar_directory.php`
- similar changes as above
- additional change to keywords_ids search in old "scholars2terms" table => becomes `LIKE` search in keywords: TODO index
...@@ -16,6 +16,8 @@ function clean_exp($string){ ...@@ -16,6 +16,8 @@ function clean_exp($string){
} }
} }
// NB actually (2016-12) this is unused TODO use !!!
function get_value($cle_value,$table='data',$cle='cle',$valeur='valeur'){ function get_value($cle_value,$table='data',$cle='cle',$valeur='valeur'){
// renvoie la valeur correspondant à la clé $cle dans la table data // renvoie la valeur correspondant à la clé $cle dans la table data
......
...@@ -40,7 +40,51 @@ foreach ($scholars as $scholar) { ...@@ -40,7 +40,51 @@ foreach ($scholars as $scholar) {
$content .= '<div>'; $content .= '<div>';
if ($scholar['photo_url'] != null) { if ($scholar['photo_url'] != null) {
$content .= '<img style="margin: 7px 10px 10px 0px" src="http://main.csregistry.org/' . $scholar['photo_url'] . '" width="' . $imsize . 'px" align="left">'; $content .= '<img style="margin: 7px 10px 10px 0px" src="http://main.csregistry.org/' . $scholar['photo_url'] . '" width="' . $imsize . 'px" align="left">';
} else { }
// raw binary picture
elseif ($scholar['pic_file'] != null) {
// create temp file
// -----------------
$finfo = finfo_open(FILEINFO_MIME_TYPE);
// $mimetype = finfo_buffer($finfo, base64_encode(convert_uudecode($scholar['pic_file'])));
// $mimetype = finfo_buffer($finfo, convert_uudecode($scholar['pic_file']));
$mimetype = finfo_buffer($finfo, $scholar['pic_file']);
finfo_close($finfo);
// £TODO more experiments to fix display here
// find format
$raw_beginning = substr($scholar['pic_file'], 0,8);
$mimeguess = null;
$JPEG = "/^xffxd8xf/";
$GIF = "/^GIF/";
$PNG = "/^x89PNG/";
if (preg_match ($JPEG, $raw_beginning)) {
// echo "<p>got JPEG</p>";
$mimeguess="image/jpeg";
}
else if (preg_match ($GIF, $raw_beginning)) {
// echo "<p>got GIF</p>";
$mimeguess="image/gif";
}
else if (preg_match ($PNG, $raw_beginning)) {
// echo "<p>got PNG</p>";
$mimeguess="image/png";
}
else {
// echo "<p>no match :(</p>";
}
echo "<p>mimetype:".$mimeguess."</p>";
$content .= '<img style="margin: 7px 10px 10px 0px" src="data:'.$mimeguess.';base64,'.$perhaps_decoded.'"/>';
}
else {
if (count($scholars) < 2000) { if (count($scholars) < 2000) {
$im_id = floor(rand(0, 11)); $im_id = floor(rand(0, 11));
$content .= '<img style="margin: 7px 10px 10px 0px" src="img/' . $im_id . '.png" width="' . $imsize . 'px" align="left">'; $content .= '<img style="margin: 7px 10px 10px 0px" src="img/' . $im_id . '.png" width="' . $imsize . 'px" align="left">';
...@@ -77,43 +121,42 @@ foreach ($scholars as $scholar) { ...@@ -77,43 +121,42 @@ foreach ($scholars as $scholar) {
} }
$affiliation2 = ''; // $affiliation2 = '';
if ($scholar['lab2'] != null) { // if ($scholar['lab2'] != null) {
$affiliation2.=$scholar['lab2'] . ', '; // $affiliation2.=$scholar['lab2'] . ', ';
$lab_list[]=$scholar['lab2']; // $lab_list[]=$scholar['lab2'];
} // }
if ($scholar['affiliation2'] != null) { // if ($scholar['affiliation2'] != null) {
$affiliation2.=$scholar['affiliation2']; // $affiliation2.=$scholar['affiliation2'];
$orga_list[]=$scholar['affiliation2']; // $orga_list[]=$scholar['affiliation2'];
//echo $scholar['affiliation2'].'<br/>'; // //echo $scholar['affiliation2'].'<br/>';
} // }
if (($scholar['affiliation2'] != null) | ($scholar['lab2'] != null)) { // if (($scholar['affiliation2'] != null) | ($scholar['lab2'] != null)) {
$content .= '<dd><i>Second affiliation: </i>' . clean_exp($affiliation2) . '</dd>'; // $content .= '<dd><i>Second affiliation: </i>' . clean_exp($affiliation2) . '</dd>';
} // }
//
if ((strcmp($affiliation2, '') != 0) | (strcmp($affiliation, '') != 0)) { // if ((strcmp($affiliation2, '') != 0) | (strcmp($affiliation, '') != 0)) {
$content .= '<br/>'; // $content .= '<br/>';
} // }
$www = ''; // $www = '';
if (substr($scholar['homepage'], 0, 3) === 'www') { // if (substr($scholar['homepage'], 0, 3) === 'www') {
$www.=' <a href=' . trim(str_replace('&', ' and ', 'http://' . $scholar['homepage'])) . ' target=blank > ' . trim(str_replace('&', ' and ', 'http://' . $scholar['homepage'])) . ' </a ><br/>'; // $www.=' <a href=' . trim(str_replace('&', ' and ', 'http://' . $scholar['homepage'])) . ' target=blank > ' . trim(str_replace('&', ' and ', 'http://' . $scholar['homepage'])) . ' </a ><br/>';
} elseif (substr($scholar['homepage'], 0, 4) === 'http') { // } elseif (substr($scholar['homepage'], 0, 4) === 'http') {
$www.=' <a href=' . trim(str_replace('&', ' and ', $scholar['homepage'])) . ' target=blank > ' . trim(str_replace('&', ' and ', $scholar['homepage'])) . ' </a ><br/>'; // $www.=' <a href=' . trim(str_replace('&', ' and ', $scholar['homepage'])) . ' target=blank > ' . trim(str_replace('&', ' and ', $scholar['homepage'])) . ' </a ><br/>';
} // }
//
if (strcmp($www, '') != 0) { // if (strcmp($www, '') != 0) {
$content .= '<dd><i class="icon-home"></i>' . $www . '</dd> '; // $content .= '<dd><i class="icon-home"></i>' . $www . '</dd> ';
} // }
//
if ($scholar['css_member'] === 'Yes') { // if ($scholar['css_member'] === 'Yes') {
if ($scholar['css_voter'] === 'Yes') { // if ($scholar['css_voter'] === 'Yes') {
$content .= '<dd><i class="icon-user"></i> CSS Voting Member</dd> '; // $content .= '<dd><i class="icon-user"></i> CSS Voting Member</dd> ';
} else { // } else {
$content .= '<dd><i class="icon-user"></i> CSS Member</dd> '; // $content .= '<dd><i class="icon-user"></i> CSS Member</dd> ';
} // }
// }
}
if (($scholar['position'] != null)||($scholar['lab'] != null)||($scholar['affiliation'] != null)) { if (($scholar['position'] != null)||($scholar['lab'] != null)||($scholar['affiliation'] != null)) {
$content .= '</dl>'; $content .= '</dl>';
...@@ -139,20 +182,20 @@ foreach ($scholars as $scholar) { ...@@ -139,20 +182,20 @@ foreach ($scholars as $scholar) {
$content .= '<i class="icon-tags"></i> ' . clean_exp($scholar['keywords']). '.<br/><br/>'; $content .= '<i class="icon-tags"></i> ' . clean_exp($scholar['keywords']). '.<br/><br/>';
} }
if ($scholar['address'] != null) { // if ($scholar['address'] != null) {
$content .= '<address><i class="icon-envelope"></i> ' . $scholar['address'] . '<br/>' . $scholar['city'] . '<br/>' . $scholar['postal_code'] . '<br/></address>'; // $content .= '<address><i class="icon-envelope"></i> ' . $scholar['address'] . '<br/>' . $scholar['city'] . '<br/>' . $scholar['postal_code'] . '<br/></address>';
} // }
//
//
if ($scholar['phone'] != null) { // if ($scholar['phone'] != null) {
$content .= '<address><strong>Phone</strong>: '.$scholar['phone'] . '<br/>'; // $content .= '<address><strong>Phone</strong>: '.$scholar['phone'] . '<br/>';
if ($scholar['mobile'] != null) { // if ($scholar['mobile'] != null) {
$content .='<strong>Mobile</strong>: '.$scholar['mobile']. '<br/>'; // $content .='<strong>Mobile</strong>: '.$scholar['mobile']. '<br/>';
} // }
if ($scholar['fax'] != null) { // if ($scholar['fax'] != null) {
$content .='<strong>Fax</strong>: '.$scholar['fax'] . '<br/>'; // $content .='<strong>Fax</strong>: '.$scholar['fax'] . '<br/>';
} // }
} // }
$content .= '</div>'; $content .= '</div>';
} }
...@@ -181,38 +224,39 @@ if (strcmp(substr($orga_query, 0,2),'OR')==0){ ...@@ -181,38 +224,39 @@ if (strcmp(substr($orga_query, 0,2),'OR')==0){
// liste des labs //////// // liste des labs ////////
////////////////////////// //////////////////////////
$labs = array(); $labs = array();
sort($lab_list); // TODO RESTORE
// sort($lab_list);
foreach ($lab_list as $name) {
if ((trim($name)) != NULL) { // foreach ($lab_list as $name) {
$sql = 'SELECT * FROM labs where name="' . $name . '" OR acronym="' . $name . '"'; // if ((trim($name)) != NULL) {
//echo $sql.'<br/>'; // $sql = 'SELECT * FROM labs where name="' . $name . '" OR acronym="' . $name . '"';
foreach ($base->query($sql) as $row) { // //echo $sql.'<br/>';
//echo 'toto'; // foreach ($base->query($sql) as $row) {
$info = array(); // //echo 'toto';
$info['unique_id'] = $row['id']; // $info = array();
$info['name'] = $row['name']; // $info['unique_id'] = $row['id'];
$info['acronym'] = $row['acronym']; // $info['name'] = $row['name'];
$info['homepage'] = $row['homepage']; // $info['acronym'] = $row['acronym'];
$info['keywords'] = $row['keywords']; // $info['homepage'] = $row['homepage'];
$info['country'] = $row['country']; // $info['keywords'] = $row['keywords'];
$info['address'] = $row['address']; // $info['country'] = $row['country'];
$info['organization'] = $row['organization']; // $info['address'] = $row['address'];
$info['organization2'] = $row['organization2']; // $info['organization'] = $row['organization'];
$orga_list[] = $row['organization']; // $info['organization2'] = $row['organization2'];
$orga_list[] = $row['organization2']; // $orga_list[] = $row['organization'];
$info['object'] = $row['object']; // $orga_list[] = $row['organization2'];
$info['methods'] = $row['methods']; // $info['object'] = $row['object'];
$info['director'] = $row['director']; // $info['methods'] = $row['methods'];
$info['admin'] = $row['admin']; // $info['director'] = $row['director'];
$info['phone'] = $row['phone']; // $info['admin'] = $row['admin'];
$info['fax'] = $row['fax']; // $info['phone'] = $row['phone'];
$info['login'] = $row['login']; // $info['fax'] = $row['fax'];
//print_r($info); // $info['login'] = $row['login'];
$labs[$row['id']] = $info; // //print_r($info);
} // $labs[$row['id']] = $info;
} // }
} // }
// }
//print_r($labs); //print_r($labs);
...@@ -222,37 +266,38 @@ foreach ($lab_list as $name) { ...@@ -222,37 +266,38 @@ foreach ($lab_list as $name) {
// liste des organizations //////// // liste des organizations ////////
////////////////////////// //////////////////////////
$organiz = array(); $organiz = array();
sort($orga_list); // TODO RESTORE
foreach ($orga_list as $name) { // sort($orga_list);
if ((trim($name))!=NULL){ // foreach ($orga_list as $name) {
$sql = "SELECT * FROM organizations where name='" . $name. "' OR acronym='".$name."'"; // if ((trim($name))!=NULL){
// $sql = "SELECT * FROM organizations where name='" . $name. "' OR acronym='".$name."'";
$temp=true; //
foreach ($base->query($sql) as $row) { // $temp=true;
if ($temp){ // foreach ($base->query($sql) as $row) {
$info = array(); // if ($temp){
$info['unique_id'] = $row['id']; // $info = array();
$info['name'] = $row['name']; // $info['unique_id'] = $row['id'];
$info['acronym'] = $row['acronym']; // $info['name'] = $row['name'];
$info['homepage'] = $row['homepage']; // $info['acronym'] = $row['acronym'];
$info['keywords'] = $row['keywords']; // $info['homepage'] = $row['homepage'];
$info['country'] = $row['country']; // $info['keywords'] = $row['keywords'];
$info['street'] = $row['street']; // $info['country'] = $row['country'];
$info['city'] = $row['city']; // $info['street'] = $row['street'];
$info['state'] = $row['state']; // $info['city'] = $row['city'];
$info['postal_code'] = $row['postal_code']; // $info['state'] = $row['state'];
$info['fields'] = $row['fields']; // $info['postal_code'] = $row['postal_code'];
$info['admin'] = $row['admin']; // $info['fields'] = $row['fields'];
$info['phone'] = $row['phone']; // $info['admin'] = $row['admin'];
$info['fax'] = $row['fax']; // $info['phone'] = $row['phone'];
$info['login'] = $row['login']; // $info['fax'] = $row['fax'];
$organiz[$row['id']] = $info; // $info['login'] = $row['login'];
$temp=false; // $organiz[$row['id']] = $info;
} // $temp=false;
} // }
} // }
// }
} //
// }
...@@ -261,6 +306,8 @@ foreach ($orga_list as $name) { ...@@ -261,6 +306,8 @@ foreach ($orga_list as $name) {
$content .='<br/> <A NAME="labs"> </A> $content .='<br/> <A NAME="labs"> </A>
<h1>Labs by alphabetical order</h1> <h1>Labs by alphabetical order</h1>
<p><i>List of labs to which scholars are affiliated</i></p>'; <p><i>List of labs to which scholars are affiliated</i></p>';
// TODO RESTORE
include('labs_list.php'); include('labs_list.php');
...@@ -271,6 +318,7 @@ $content .= '<br/> <A NAME="orga"> </A> ...@@ -271,6 +318,7 @@ $content .= '<br/> <A NAME="orga"> </A>
<h1>Organizations by alphabetical order</h1> <h1>Organizations by alphabetical order</h1>
<br/> <br/>
<p><i>List of organizations to which scholars are affiliated</i></p>'; <p><i>List of organizations to which scholars are affiliated</i></p>';
// TODO RESTORE
include('orga_list.php'); include('orga_list.php');
/// ajout des organisations /// ajout des organisations
......
<?php <?php
/* /* liste de parametres */
list de parametres.
*/
$dbname='/home/jbilcke/databases/scholar_test_data.db';
$dbname='community.db'; $dbname='community.db';
//$dbname='scholar_test_data.db';
//$scholars_db ="raw_scholars";
$fichier = "CSSscholars20Oct2011.csv";
$fichier = "CSSscholars2Oct2011.csv";
$lab_csv="CSLabs13Fev2012.csv";
$orga_csv='';
$min_num_friends=0;// nombre minimal de voisin que doit avoir un scholar pour être affiché $min_num_friends=0;// nombre minimal de voisin que doit avoir un scholar pour être affiché
//$fichier = "Scholars13Sept2011.csv"; // $compress='No';
//$fichier = "test2.csv";
$drop_tables=true; // on efface les tables
$language='english';
$file_sep=',';
//$scholar_filter=" where country='France' AND status='o'";
//$scholar_filter=" where country='France' AND want_whoswho='Yes' AND css_member='Yes'";
//$scholar_filter=" where css_member='Yes' AND want_whoswho='Yes'";
//$scholar_filter=" where css_member='Yes' OR want_whoswho='Yes'";
$scholar_filter="where css_member='Yes'";
//$scholar_filter="";
//$scholar_filter=" where country='France' AND want_whoswho='Yes'";
//$scholar_filter=" where country='France'";
$compress='No';
/* parametres externes: nom de l'hôte SQL*/
$params = parse_ini_file("parametres_comex.ini");
/* tout pour le MySQL */
$host = $params['SQL_HOST'];
$db = 'comex_shared';
$user = 'root';
$pass = 'very-safe-pass';
$charset = 'utf8';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
?> ?>
...@@ -103,11 +103,21 @@ $laboratories = $data["laboratories"]; ...@@ -103,11 +103,21 @@ $laboratories = $data["laboratories"];
$organizations = $data["organizations"]; $organizations = $data["organizations"];
$tags = $data["tags"]; $tags = $data["tags"];
// echo '<p style="color:white">params: $categorya =====> '. var_dump($categorya) ."<p>";
// echo '<p style="color:white">params: $categoryb =====> '. var_dump($categoryb)."<p>";
// echo '<p style="color:white">params: $countries =====> '. var_dump($countries) ."<p>";
// echo '<p style="color:white">params: $keywords =====> '. var_dump($keywords) ."<p>";
// echo '<p style="color:white">params: $laboratories =====> '. var_dump($laboratories) ."<p>";
// echo '<p style="color:white">params: $organizations =====> '. var_dump($organizations) ."<p>";
// echo '<p style="color:white">params: $tags =====> '. var_dump($tags) ."<p>";
$query_details='<ul>'; $query_details='<ul>';
$f = "";// requête $f = "";// requête
$labfilter=''; $labfilter='';
if ($tags) { if ($tags) {
echo '<p style="color:white">MATCHING ON tags<p>';
if (sizeof($tags) > 0) { if (sizeof($tags) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
...@@ -129,6 +139,7 @@ if ($tags) { ...@@ -129,6 +139,7 @@ if ($tags) {
} }
if ($keywords) { if ($keywords) {
echo '<p style="color:white">MATCHING ON keywords<p>';
if (sizeof($keywords) > 0) { if (sizeof($keywords) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
...@@ -149,7 +160,7 @@ if ($keywords) { ...@@ -149,7 +160,7 @@ if ($keywords) {
$f .= ") "; $f .= ") ";
} }
if ($countries) { if ($countries) {
echo '<p style="color:white">MATCHING ON countries<p>';
if (sizeof($countries) > 0) { if (sizeof($countries) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
...@@ -168,7 +179,7 @@ if ($countries) { ...@@ -168,7 +179,7 @@ if ($countries) {
$f .= ") "; $f .= ") ";
} }
if ($laboratories) { if ($laboratories) {
echo '<p style="color:white">MATCHING ON labs<p>';
if (sizeof($laboratories) > 0) { if (sizeof($laboratories) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
...@@ -179,7 +190,7 @@ if ($laboratories) { ...@@ -179,7 +190,7 @@ if ($laboratories) {
if ($lab == "") continue; if ($lab == "") continue;
if ($i > 0) if ($i > 0)
$f .= " OR "; $f .= " OR ";
$f .= 'lab LIKE "%' . $lab . '%" '; $f .= 'team_lab LIKE "%' . $lab . '%" ';
$query_details.=$lab.', '; $query_details.=$lab.', ';
$i++; $i++;
} }
...@@ -187,18 +198,19 @@ if ($laboratories) { ...@@ -187,18 +198,19 @@ if ($laboratories) {
} }
if ($organizations) { if ($organizations) {
echo '<p style="color:white">MATCHING ON organizations<p>';
if (sizeof($organizations) > 0) { if (sizeof($organizations) > 0) {
$f .= 'AND ('; $f .= 'AND (';
} }
$query_details.='<li><strong>In the organization named : </strong>'; $query_details.='<li><strong>In the organization named : </strong>';
$i = 0; $i = 0;
foreach ($organizations as $org) { foreach ($organizations as $org) {
// echo '<p style="color:white">========> org =====> '. $org ."<p>";
$org = sanitize_input(trim(strtolower($org))); $org = sanitize_input(trim(strtolower($org)));
if ($org == "") continue; if ($org == "") continue;
$query_details.=$org.', '; $query_details.=$org.', ';
$f .= 'affiliation LIKE "%' . $org . '%" OR affiliation2 LIKE "%' . $org . '%" '; $f .= 'institution LIKE "%' . $org . '%" ';
//'affiliation LIKE "%' . $org . '% OR affiliation2 LIKE "%' . $org . '%"'; //'affiliation LIKE "%' . $org . '% OR affiliation2 LIKE "%' . $org . '%"';
$i++; $i++;
} }
...@@ -207,12 +219,11 @@ if ($organizations) { ...@@ -207,12 +219,11 @@ if ($organizations) {
$query_details.='</ul>'; $query_details.='</ul>';
$base = new PDO("sqlite:" . $dbname); $base = new PDO($dsn, $user, $pass, $opt);
$termsMatrix = array(); // liste des termes présents chez les scholars avec leurs cooc avec les autres termes $termsMatrix = array(); // liste des termes présents chez les scholars avec leurs cooc avec les autres termes
$scholarsMatrix = array(); // liste des scholars avec leurs cooc avec les autres termes $scholarsMatrix = array(); // liste des scholars avec leurs cooc avec les autres termes
$scholarsIncluded = 0; $scholarsIncluded = 0;
// liste des chercheurs // liste des chercheurs
if (substr($f, 0,3)=='AND'){ if (substr($f, 0,3)=='AND'){
$f=substr($f,3,-1); $f=substr($f,3,-1);
...@@ -226,12 +237,13 @@ $imsize = 150; ...@@ -226,12 +237,13 @@ $imsize = 150;
$content=''; $content='';
if (strlen($f)>0){ if (strlen($f)>0){
$sql = "SELECT * FROM scholars where " . " " . $f.' ORDER BY last_name'; $sql = "SELECT * FROM comex_registrations where " . " " . $f.' ORDER BY last_name';
}else{ }else{
$sql = "SELECT * FROM scholars ORDER BY last_name"; $sql = "SELECT * FROM comex_registrations ORDER BY last_name";
} }
//echo $sql.'<br/>'; //echo $sql.'<br/>';
echo '<p style="color:white">query:'. $sql ."<p>";
// liste des chercheurs // liste des chercheurs
$scholars = array(); $scholars = array();
...@@ -239,43 +251,46 @@ $scholars = array(); ...@@ -239,43 +251,46 @@ $scholars = array();
//$query = "SELECT * FROM scholars"; //$query = "SELECT * FROM scholars";
foreach ($base->query($sql) as $row) { foreach ($base->query($sql) as $row) {
// TODO RESTORE
$info = array(); $info = array();
$info['unique_id'] = $row['unique_id']; $info['unique_id'] = $row['doors_uid'];
$info['first_name'] = $row['first_name']; $info['first_name'] = $row['first_name'];
$info['initials'] = $row['initials']; $info['initials'] = $row['initials'];
$info['last_name'] = $row['last_name']; $info['last_name'] = $row['last_name'];
$info['nb_keywords'] = $row['nb_keywords'];
$info['css_voter'] = $row['css_voter']; // => TODO RESTORE
$info['css_member'] = $row['css_member']; // $info['nb_keywords'] = $row['nb_keywords'];
$info['keywords_ids'] = explode(',', $row['keywords_ids']); // $info['css_voter'] = $row['css_voter'];
// $info['css_member'] = $row['css_member'];
// $info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['keywords'] = $row['keywords']; $info['keywords'] = $row['keywords'];
$info['status'] = $row['status']; // $info['status'] = $row['status'];
$info['country'] = $row['country']; $info['country'] = $row['country'];
$info['homepage'] = $row['homepage']; // $info['homepage'] = $row['homepage'];
$info['lab'] = $row['lab']; $info['lab'] = $row['team_lab'];
$info['affiliation'] = $row['affiliation']; $info['affiliation'] = $row['institution'];
$info['lab2'] = $row['lab2']; // $info['lab2'] = $row['lab2'];
$info['affiliation2'] = $row['affiliation2']; // $info['affiliation2'] = $row['affiliation2'];
$info['homepage'] = $row['homepage']; // $info['homepage'] = $row['homepage'];
$info['title'] = $row['title']; $info['title'] = $row['jobtitle'];
$info['position'] = $row['position']; $info['position'] = $row['jobtitle'];
$info['photo_url'] = $row['photo_url']; // $info['photo_url'] = $row['photo_url'];
$info['interests'] = $row['interests']; $info['pic_file'] = $row['pic_file'];
$info['address'] = $row['address']; $info['interests'] = $row['interests_text'];
$info['city'] = $row['city']; // $info['address'] = $row['address'];
$info['postal_code'] = $row['postal_code']; // $info['city'] = $row['city'];
$info['phone'] = $row['phone']; // $info['postal_code'] = $row['postal_code'];
$info['mobile'] = $row['mobile']; // $info['phone'] = $row['phone'];
$info['fax'] = $row['fax']; // $info['mobile'] = $row['mobile'];
$info['affiliation_acronym'] = $row['affiliation_acronym']; // $info['fax'] = $row['fax'];
$scholars[$row['unique_id']] = $info; // $info['affiliation_acronym'] = $row['affiliation_acronym'];
$scholars[$row['doors_uid']] = $info;
} }
/// stats /// stats
//$base = new PDO('sqlite:' . $dbname);
include ('stat-prep_from_array.php');/// include ('stat-prep_from_array.php');///
include ("directory_content.php"); include ("directory_content.php");
// liste des chercheurs // liste des chercheurs
......
...@@ -72,76 +72,85 @@ function is_utf8($string) { ...@@ -72,76 +72,85 @@ function is_utf8($string) {
$login = $_GET['query']; $login = $_GET['query'];
$base = new PDO("sqlite:" . $dbname); // $base = new PDO("sqlite:" . $dbname);
$base = new PDO($dsn, $user, $pass, $opt);
if ($login) { if ($login) {
if (sizeof($login) > 0) { if (sizeof($login) > 0) {
// liste des chercheurs // liste des chercheurs
$sql = "SELECT keywords_ids,last_name,first_name FROM scholars where unique_id='" . $login . "'"; $sql = "SELECT keywords,last_name,first_name FROM comex_registrations WHERE doors_uid='" . $login . "'";
foreach ($base->query($sql) as $row) { foreach ($base->query($sql) as $row) {
$keywords_ids = explode(',', $row['keywords_ids']); $keywords = explode(',', $row['keywords']);
$scholar_array = array(); $scholar_array = array();
$target_name=$row['first_name'].' '.$row['last_name']; $target_name=$row['first_name'].' '.$row['last_name'];
foreach ($keywords_ids as $keywords_id) { foreach ($keywords as $keyword) {
$sql2 = "SELECT * FROM scholars2terms where term_id=" . trim($keywords_id); if (strlen($keyword) > 0) {
#pt($sql2);
// TODO RESTORE index keywords
// $sql2 = "SELECT * FROM scholars2terms where term_id=" . trim($keywords_id);
$sql2 = "SELECT doors_uid FROM comex_registrations WHERE keywords LIKE \"%" . trim($keyword)."%\"";
// echo($sql2."<br/>");
foreach ($base->query($sql2) as $row) { foreach ($base->query($sql2) as $row) {
if (array_key_exists($row['scholar'], $scholar_array)){ if (array_key_exists($row['doors_uid'], $scholar_array)){
$scholar_array[$row['scholar']] += 1; $scholar_array[$row['doors_uid']] += 1;
}else{ }else{
$scholar_array[$row['scholar']] = 1; $scholar_array[$row['doors_uid']] = 1;
} }
} }
} }
} }
}
} }
} }
// les scholars sont affichés par ordre de pertinence // les scholars sont affichés par ordre de pertinence
arsort($scholar_array); arsort($scholar_array);
$scholar_id_array=array_keys($scholar_array);
// echo var_dump($scholar_id_array)."<br/>" ;
$scholar_id_array=array_keys($scholar_array);
// liste des chercheurs // liste des chercheurs
$scholars = array(); $scholars = array();
//
foreach ($scholar_id_array as $scholar_id){ foreach ($scholar_id_array as $scholar_id){
$sql = "SELECT * FROM scholars where unique_id='" . $scholar_id. "'"; $sql = "SELECT * FROM comex_registrations where doors_uid='" . $scholar_id. "'";
// echo var_dump($scholar_id)."<br/>" ;
//$query = "SELECT * FROM scholars"; //$query = "SELECT * FROM scholars";
foreach ($base->query($sql) as $row) { foreach ($base->query($sql) as $row) {
$info = array(); $info = array();
$info['unique_id'] = $row['unique_id']; $info['unique_id'] = $row['doors_uid'];
$info['first_name'] = $row['first_name']; $info['first_name'] = $row['first_name'];
$info['initials'] = $row['initials']; $info['initials'] = $row['initials'];
$info['last_name'] = $row['last_name']; $info['last_name'] = $row['last_name'];
$info['nb_keywords'] = $row['nb_keywords']; // $info['nb_keywords'] = $row['nb_keywords'];
$info['css_voter'] = $row['css_voter']; // $info['css_voter'] = $row['css_voter'];
$info['css_member'] = $row['css_member']; // $info['css_member'] = $row['css_member'];
$info['keywords_ids'] = explode(',', $row['keywords_ids']); // $info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['keywords'] = $row['keywords']; $info['keywords'] = $row['keywords'];
$info['status'] = $row['status']; // $info['status'] = $row['status'];
$info['country'] = $row['country']; $info['country'] = $row['country'];
$info['homepage'] = $row['homepage']; // $info['homepage'] = $row['homepage'];
$info['lab'] = $row['lab']; $info['lab'] = $row['team_lab'];
$info['affiliation'] = $row['affiliation']; $info['affiliation'] = $row['institution'];
$info['lab2'] = $row['lab2']; // $info['lab2'] = $row['lab2'];
$info['affiliation2'] = $row['affiliation2']; // $info['affiliation2'] = $row['affiliation2'];
$info['homepage'] = $row['homepage']; // $info['homepage'] = $row['homepage'];
$info['title'] = $row['title']; $info['title'] = $row['jobtitle'];
$info['position'] = $row['position']; $info['position'] = $row['jobtitle'];
$info['photo_url'] = $row['photo_url']; // $info['photo_url'] = $row['photo_url'];
$info['interests'] = $row['interests']; $info['pic_file'] = $row['pic_file'];
$info['address'] = $row['address']; $info['interests'] = $row['interests_text'];
$info['city'] = $row['city']; // $info['address'] = $row['address'];
$info['postal_code'] = $row['postal_code']; // $info['city'] = $row['city'];
$info['phone'] = $row['phone']; // $info['postal_code'] = $row['postal_code'];
$info['mobile'] = $row['mobile']; // $info['phone'] = $row['phone'];
$info['fax'] = $row['fax']; // $info['mobile'] = $row['mobile'];
$info['affiliation_acronym'] = $row['affiliation_acronym']; // $info['fax'] = $row['fax'];
$scholars[$row['unique_id']] = $info; // $info['affiliation_acronym'] = $row['affiliation_acronym'];
$scholars[$row['doors_uid']] = $info;
} }
} }
...@@ -210,7 +219,7 @@ Contributions and ideas are welcome to improve this directory. ...@@ -210,7 +219,7 @@ Contributions and ideas are welcome to improve this directory.
echo $meta.' '.$stats.'</head>'; echo $meta.' '.$stats.'</head>';
if (count($scholars)==0){ if (count($scholars)==0){
echo '<h2>Sorry, '.$target_name.' did not mentioned any keywords ... we cannot process it\'s network.</h2><br/> echo '<h2>Sorry, '.$target_name.' did not mention any keywords ... we cannot process its network.</h2><br/>
If you are '.$target_name.', you can <a href="http://main.csregistry.org/Whoswhodata" target="_BLANK">modify your profile</a> and see your If you are '.$target_name.', you can <a href="http://main.csregistry.org/Whoswhodata" target="_BLANK">modify your profile</a> and see your
network in few minutes.'; network in few minutes.';
}else{ }else{
......
<?php <?php
/* /*
* Génère le gexf des scholars à partir de la base sqlite * Génère le gexf des scholars à partir de la base mysql
*/ */
include("parametres.php"); include("parametres.php");
//include("../common/library/fonctions_php.php"); //include("../common/library/fonctions_php.php");
include("normalize.php"); include("normalize.php");
$base = new PDO("sqlite:" . $dbname); $base = new PDO($dsn, $user, $pass, $opt);
$category = trim(strtolower($_GET['category'])); $category = trim(strtolower($_GET['category']));
$term = trim(strtolower($_GET['term'])); $term = trim(strtolower($_GET['term']));
...@@ -20,7 +20,10 @@ if ($category == 'country' || $category == 'countries') { ...@@ -20,7 +20,10 @@ if ($category == 'country' || $category == 'countries') {
$cat = "country"; $cat = "country";
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'organization' || $category == 'organizations') { } elseif ($category == 'organization' || $category == 'organizations') {
$cat = "affiliation";
// POSSIBLE: `concat(institution, ", ", IFNULL(team_lab, ""))``
// (change in $cat here and in print_directory args downstream)
$cat = 'institution';
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'keyword' || $category == 'keywords') { } elseif ($category == 'keyword' || $category == 'keywords') {
$cat = "keywords"; $cat = "keywords";
...@@ -29,7 +32,7 @@ if ($category == 'country' || $category == 'countries') { ...@@ -29,7 +32,7 @@ if ($category == 'country' || $category == 'countries') {
$cat = "tags"; $cat = "tags";
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'labs' || $category == 'laboratories' || $category == 'laboratory') { } elseif ($category == 'labs' || $category == 'laboratories' || $category == 'laboratory') {
$cat = "lab"; $cat = "team_lab";
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} else { } else {
echo ("ERROR"); echo ("ERROR");
...@@ -44,14 +47,15 @@ function filter_word($value) { ...@@ -44,14 +47,15 @@ function filter_word($value) {
return ! in_array(strtolower($value),$filtered); return ! in_array(strtolower($value),$filtered);
} }
$req = "SELECT ".$cat." AS key, count(".$cat.") AS value FROM scholars WHERE ".$cat." ".$query." GROUP BY ".$cat." ORDER BY value DESC"; $req = "SELECT ".$cat." AS clef, count(".$cat.") AS value FROM comex_registrations WHERE ".$cat." ".$query." GROUP BY ".$cat." ORDER BY value DESC";
// echo $req;
$results = array(); $results = array();
$i = 0; $i = 0;
foreach ($base->query($req) as $row) { foreach ($base->query($req) as $row) {
$nb = $row['value']; $nb = $row['value'];
if ($cat == "keywords" || $cat == "tags") { if ($cat == "keywords" || $cat == "tags") {
//echo "in keywords\n"; //echo "in keywords\n";
$words = explode(",", $row["key"]); $words = explode(",", $row["clef"]);
foreach ($words as $word) { foreach ($words as $word) {
$pos = strpos($word,$term); $pos = strpos($word,$term);
...@@ -69,7 +73,7 @@ foreach ($base->query($req) as $row) { ...@@ -69,7 +73,7 @@ foreach ($base->query($req) as $row) {
} }
} }
} else { } else {
$word = $row["key"]; $word = $row["clef"];
if ($cat == "country") { if ($cat == "country") {
$word = normalize_country($word); $word = normalize_country($word);
} }
......
...@@ -8,79 +8,114 @@ include("parametres.php"); ...@@ -8,79 +8,114 @@ include("parametres.php");
include("normalize.php"); include("normalize.php");
$base = new PDO("sqlite:" . $dbname);
$category = trim(strtolower($_GET['category'])); // ===================== SQL connect =====================
$login = trim(strtolower($_GET['login'])); $base = new PDO($dsn, $user, $pass, $opt);
$q = "%".sanitize_input($login)."%"; // ==================== /SQL connect =====================
//echo "category: ".$category.";";
//echo "login: ".$login.";";
//echo "q: ".$q.";";
$cat = '';
$query = '';
if ($category == 'login') {
$cat = "unique_id";
$query = 'unique_id LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'firstname') {
$cat = "firstname";
$query = 'first_name LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'lastname') {
$cat = "lastname";
$query = 'last_name LIKE upper(\''.strtoupper($q).'\')';
} else {
echo ("ERROR");
exit();
}
$filtered = array ( // ==================== new retrieval ======================
"yes", "1", "0", "nvgfpmeilym", "no", "mr", "ms", "", " ", " " $login = trim(strtolower($_GET['login']));
); $q = "%".sanitize_input($login)."%";
function filter_word($value) {
if ($value == null) return true;
return ! in_array(strtolower($value),$filtered);
}
$req = "SELECT unique_id, first_name, last_name,nb_keywords FROM scholars WHERE ".$query." GROUP BY unique_id"; $query = 'concat(first_name, " ", IFNULL(middle_name,""), " ", last_name) LIKE "%'.$q.'%"';
#echo "req: ".$req.";";
$req = "SELECT doors_uid, email, first_name, last_name, keywords FROM comex_registrations WHERE ".$query." GROUP BY doors_uid";
// echo "req: ".$req.";";
$results = array(); $results = array();
$i = 0; $i = 0;
$res = $base->query($req); $res = $base->query($req);
foreach ($res as $row) {
if ($row["nb_keywords"]==0){
$row["nb_keywords"]=' (no keyword to map)';
} else {
$row["nb_keywords"]='';
}
array_push($results,$row);
}
$nbresults = sizeof($results);
$results = array_slice($results,0,20);
$nbresults2 = sizeof($results);
$completion = array( $completion = array(
"results" => array() "results" => array(),
"query" => $login
); );
foreach($res as $row) {
foreach($results as $row) {
array_push($completion["results"], array( array_push($completion["results"], array(
'id' => $row["unique_id"], 'id' => $row["doors_uid"],
'term' => $login, 'term' => $login,
'firstname' => $row["first_name"], 'firstname' => $row["first_name"],
'lastname' => $row["last_name"].$row["nb_keywords"], 'lastname' => $row["last_name"],
'score' => 1,
// F*** it, I'll put the meta data here...
'category' => $cat,
"size" => $nbresults2,
"total" => $nbresults,
"remaining" => ($nbresults - $nbresults2)
)); ));
} }
$i = 0; // ==================== /new retrieval =====================
// $base = new PDO("sqlite:" . $dbname);
//
// $category = trim(strtolower($_GET['category']));
// $login = trim(strtolower($_GET['login']));
// $q = "%".sanitize_input($login)."%";
//
// //echo "category: ".$category.";";
// //echo "login: ".$login.";";
// //echo "q: ".$q.";";
//
// $cat = '';
// $query = '';
// if ($category == 'login') {
// $cat = "unique_id";
// $query = 'unique_id LIKE upper(\''.strtoupper($q).'\')';
// } elseif ($category == 'firstname') {
// $cat = "firstname";
// $query = 'first_name LIKE upper(\''.strtoupper($q).'\')';
// } elseif ($category == 'lastname') {
// $cat = "lastname";
// $query = 'last_name LIKE upper(\''.strtoupper($q).'\')';
// } else {
// echo ("ERROR");
// exit();
// }
//
// $filtered = array (
// "yes", "1", "0", "nvgfpmeilym", "no", "mr", "ms", "", " ", " "
// );
// function filter_word($value) {
// if ($value == null) return true;
// return ! in_array(strtolower($value),$filtered);
// }
//
// $req = "SELECT unique_id, first_name, last_name,nb_keywords FROM scholars WHERE ".$query." GROUP BY unique_id";
// #echo "req: ".$req.";";
// $results = array();
// $i = 0;
// $res = $base->query($req);
//
// foreach ($res as $row) {
// if ($row["nb_keywords"]==0){
// $row["nb_keywords"]=' (no keyword to map)';
// } else {
// $row["nb_keywords"]='';
// }
// array_push($results,$row);
// }
//
// $nbresults = sizeof($results);
// $results = array_slice($results,0,20);
// $nbresults2 = sizeof($results);
// $completion = array(
// "results" => array()
// );
//
//
// foreach($results as $row) {
// array_push($completion["results"], array(
// 'id' => $row["unique_id"],
// 'term' => $login,
// 'firstname' => $row["first_name"],
// 'lastname' => $row["last_name"].$row["nb_keywords"],
// 'score' => 1,
//
// // TODO change: general metadata is uselessly copied x nbresults
// // F*** it, I'll put the meta data here...
// 'category' => $cat,
// "size" => $nbresults2,
// "total" => $nbresults,
// "remaining" => ($nbresults - $nbresults2)
// ));
// }
// $i = 0;
echo json_encode($completion); echo json_encode($completion);
?> ?>
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