-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_directory.php
More file actions
executable file
·467 lines (389 loc) · 13.8 KB
/
print_directory.php
File metadata and controls
executable file
·467 lines (389 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
<?php
include ("php_library/comex_library.php");
include ("php_library/parametres.php");
include ("php_library/normalize.php");
include ("php_library/baselayout_head_template.php");
include ("php_library/baselayout_tail_template.php");
$meta = $html_head_inner;
$data = json_decode($_GET['query']);
// print_r('query here<br>');
// print_r($data);
// print_r('/query here<br>');
// this one after we got query data
include ("php_library/js_elements.php");
function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}
$data = objectToArray($data);
// REST query params
$categorya = $data["categorya"] ?? [];
$categoryb = $data["categoryb"] ?? [];
$countries = $data["countries"] ?? [];
$keywords = $data["keywords"] ?? [];
$laboratories = $data["laboratories"] ?? [];
$institutions = $data["institutions"] ?? [];
$tags = $data["tags"] ?? [];
// echo '<p style="color:grey">params: $categorya =====> "'. implode($categorya) .'"</p>';
// echo '<p style="color:grey">params: $categoryb =====> "'. implode($categoryb) .'"</p>';
// echo '<p style="color:grey">params: $countries =====> "'. implode($countries) .'"</p>';
// echo '<p style="color:grey">params: $keywords =====> "'. implode($keywords) .'"</p>';
// echo '<p style="color:grey">params: $laboratories =====> "'. implode($laboratories) .'"</p>';
// echo '<p style="color:grey">params: $institutions =====> "'. implode($institutions) .'"</p>';
// echo '<p style="color:grey">params: $tags =====> "'. implode($tags) .'"</p>';
$query_details='<ul>';
$f = "";// requête
$labfilter='';
// NB hashtags and keywords were additionally split on ',' before being transformed into constraints... we keep this mechanism here but fixed (in legacy version the $i used only in inner loop so 'OR' was missing)
// (1st array level: several inputs)
// (2nd array level: several words in one input)
// constraints <=> each elt of the 2nd level
if ($tags) {
// debug
// echo '<p style="color:white">MATCHING ON tags<p>';
if (sizeof($tags) > 0) {
$f .= 'AND (';
}
$query_details.='<li class="small-item"><strong>Community tags: </strong>';
$exploded_hts = [];
foreach ($tags as $ht) {
$subwords = explode(',', $ht);
foreach ($subwords as $subword) {
$subword = sanitize_input(trim(strtolower($subword)));
if ($subword == "") continue;
else array_push($exploded_hts, $subword);
}
}
$i = 0;
foreach($exploded_hts as $clean_subword) {
$query_details.=$clean_subword.', ';
if ($i > 0)
$f .= " OR ";
$f .= 'hashtags_list LIKE "%' . $clean_subword . '%" ';
$i++;
}
$f .= ") ";
$query_details .= "</li>";
}
if ($keywords) {
// debug
// echo '<p style="color:white">MATCHING ON keywords<p>';
if (sizeof($keywords) > 0) {
$f .= 'AND (';
}
$query_details.='<li class="small-item"><strong>Working on: </strong>';
$exploded_kws = [];
foreach ($keywords as $kw) {
$subwords = explode(',', $kw);
foreach ($subwords as $subword) {
$subword = sanitize_input(trim(strtolower($subword)));
if ($subword == "") continue;
else array_push($exploded_kws, $subword);
}
}
$i = 0;
foreach($exploded_kws as $clean_subword) {
$query_details.=$clean_subword.', ';
if ($i > 0)
$f .= " OR ";
$f .= 'keywords_list LIKE "%' . $clean_subword . '%" ';
$i++;
}
$f .= ") ";
$query_details .= "</li>";
}
if ($countries) {
// debug
// echo '<p style="color:white">MATCHING ON countries<p>';
if (sizeof($countries) > 0) {
$f .= 'AND (';
}
$query_details.='<li class="small-item"><strong>In the following country: </strong>';
$i = 0;
foreach ($countries as $country) {
//$country = sanitize_input(trim(strtolower($country)));
$country = sanitize_input(trim($country ));
if ($country == "") continue;
if ($i > 0)
$f .= " OR ";
$f .= 'country = "' . $country . '" ';
$query_details.=$country.', ';
$i++;
}
$f .= ") ";
$query_details .= "</li>";
}
if ($laboratories) {
// debug
// echo '<p style="color:white">MATCHING ON labs<p>';
if (sizeof($laboratories) > 0) {
$f .= 'AND (';
}
$query_details.='<li class="small-item"><strong>In the lab named : </strong>';
$i = 0;
foreach ($laboratories as $lab) {
$lab = sanitize_input(trim(strtolower($lab)));
if ($lab == "") continue;
if ($i > 0)
$f .= " OR ";
$f .= 'labs_list LIKE "%' . $lab . '%" ';
$query_details.=$lab.', ';
$i++;
}
$f .= ") ";
$query_details .= "</li>";
}
if ($institutions) {
// debug
// echo '<p style="color:white">MATCHING ON organizations<p>';
if (sizeof($institutions) > 0) {
$f .= 'AND (';
}
$query_details.='<li class="small-item"><strong>In the organization named : </strong>';
$i = 0;
foreach ($institutions as $inst) {
// echo '<p style="color:white">========> org =====> '. $inst ."<p>";
$inst = sanitize_input(trim(strtolower($inst)));
if ($inst == "") continue;
if ($i > 0)
$f .= " OR ";
$f .= 'insts_list LIKE "%' . $inst . '%" ';
$query_details.=$inst.', ';
$i++;
}
$f .= ") ";
$query_details .= "</li>";
}
$query_details.='</ul>';
// debug SQL filters
// print_r("query filters: ". $f);
$base = new PDO($dsn, $user, $pass, $opt);
$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
$scholarsIncluded = 0;
// liste des chercheurs
if (substr($f, 0,3)=='AND'){
$f=substr($f,3,-1);
}
if (substr($labfilter, 0,3)=='AND'){
$labfilter=substr($labfilter,3,-1);
}
$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='';
// error_log("=======> WHERE filters {$f}");
// filtered query
if (strlen($f)>0) {
$filter = "WHERE {$f}";
}
// unfiltered query
else {
$filter = "";
}
// about the query stucture cf. doc/cascade_full_scholar_info.sql
$sql = <<< END_QUERY
SELECT * FROM (
$sql_full_scholar_select
) AS full_scholars_info
{$filter}
ORDER BY full_scholars_info.last_name
END_QUERY;
// debug
// echo '<p style="color:grey;">query:<br>'. $sql ."<p>";
// liste des chercheurs
$scholars = array();
//$query = "SELECT * FROM scholars";
foreach ($base->query($sql) as $row) {
$info = array();
$info['unique_id'] = $row['luid'];
$info['doors_uid'] = $row['doors_uid'];
$info['first_name'] = esc_html($row['first_name']);
$info['mid_initial'] = (strlen($row['middle_name']) ? substr($row['middle_name'],0,1)."." : "");
$info['last_name'] = esc_html($row['last_name']);
$info['initials'] = esc_html($row['initials']);
// retrieved from secondary table and GROUP_CONCATenated
// $info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['nb_keywords'] = $row['keywords_nb'];
$info['keywords'] = $row['keywords_list'];
// $info['status'] = $row['status'];
$info['record_status'] = $row['record_status']; // TODO use this one
$info['country'] = esc_html($row['country']);
$info['homepage'] = $row['home_url'];
// recreated arrays
$info['labs'] = array_map("esc_html",
explode('%%%', $row['labs_list'] ?? "")
) ;
$info['institutions'] = array_map("esc_html",
explode('%%%', $row['insts_list'] ?? "")
) ;
$info['labs_ids'] = explode(',', $row['labs_ids'] ?? "") ;
$info['insts_ids'] = explode(',', $row['insts_ids'] ?? "") ;
$info['title'] = esc_html($row['hon_title']);
$info['position'] = esc_html($row['position']);
$info['pic_src'] = $row['pic_fname'] ? '/data/shared_user_img/'.$row['pic_fname'] : $row['pic_url'] ;
$info['interests'] = str_replace('%%%', '<br/>',
esc_html($row['interests_text'])
);
// $info['address'] = $row['address'];
// $info['city'] = $row['city'];
// $info['postal_code'] = $row['postal_code'];
// $info['phone'] = $row['phone'];
// $info['mobile'] = $row['mobile'];
// $info['fax'] = $row['fax'];
// $info['affiliation_acronym'] = $row['affiliation_acronym'];
$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];
$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 => the key becomes ""
// (useful for missing labs)
$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;
}
}
}
}
// both our stats have been filled
// var_dump($lab_counts) ;
// var_dump($inst_counts) ;
// var_dump($org_id_to_label) ;
// creates js for stats visualisations and counts (we re-use the orgs counts)
include ("php_library/stat-prep_from_array.php");
// debug
// $content .= var_dump($scholars) ;
// creates listing
include ("php_library/directory_content.php");
//////// Header
$header = '
<div class="row" id="welcome">
<div class="span12" align="justify">
<br/>
<h2 class="oldstyle maintitle">Complex Systems Scholars</h2>
<br/>
<div class="mini-hero">
<p>
This directory presents the profiles of <a href="#scholars">'. count($scholars).' scholars</a>, <a href="#labs">'. count($labs).' labs</a> and <a href="#orga">'.$orga_count.' organizations</a> in the field of Complex Systems';
if (strlen(trim($query_details))>3){
$header .= ': </p>'.$query_details;
}else{
$header .='.</p> ';
}
$header .='<p>Its aims are to foster interactions
between protagonists in the fields of Complex Systems science and Complexity
science, as well as to increase their visibility at the international scale.</p>
<ul>
<li class="small-item"><b><i>This directory is open</i></b>. Anybody can have her profile included
provided it is related to Complex Systems science and Complexity science. Personal data are given on a
voluntary basis and people are responsible for the validity and integrity of their data.</li>
<li class="small-item">This directory is edited by the ISCPIF. This initiative is supported by the <i>Complex Systems
Society</i> (<a href="http://cssociety.org">http://cssociety.org</a>).
Contributions and ideas are welcome to improve this directory.
<a href="mailto:sysop AT iscpif.fr">Please feedback</a></li>
</ul>
</div>
<br/>
<h2 class="oldstyle">Global statistics</h2>
<div class="container-fluid">
<div class="row chart-row">
<div class="col-lg-5 col-md-5 col-sm-12">
<div id="country" class="directory-piechart"></div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div id="title" class="directory-piechart"></div>
</div>
</div>
<div class="row chart-row">
<div class="col-lg-5 col-md-5 col-sm-12">
<div id="position" class="directory-piechart"></div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<!-- conditional display (cf. n_shown in stats-prep) -->
<div id="insts_div" class="directory-piechart"></div>
</div>
</div>
<div class="row chart-row">
<div class="col-lg-12 col-md-12 col-sm-12">
</div>
</div>
<div class="row chart-row">
<div class="col-lg-12 col-md-12 col-sm-12">
<!-- new: tagcloud -->
<h3 class=centered><i class="icon-tags"></i> Main keywords for this listing</h3>
<div id="kw_tagcloud_div"></div>
</div>
<!--
<div class="col-lg-6 col-md-6 col-sm-12">
<div id="labs_div" class="directory-piechart"></div>
</div>
-->
</div>
<div class="row smallspacerrow"> </div>
</div>
<br/>
<br/> <A NAME="scholars"> </A>
<h2 class="oldstyle">Scholars by alphabetical order</h2>
<br/>
<br/>
</div>
</div>';
echo $html_declaration;
echo '<head>';
echo $meta;
echo $stats;
echo '</head>';
echo '<body>';
echo $doors_connect_params;
echo '<div class="page container full-directory">';
// echo '<div class="hero-unit">';
echo $header;
echo '';
echo $content;
echo $footer;
// echo '</div>';
echo '</div>';
echo $html_tail_imports;
echo tagcloud_snippet($kw_counts_as_sorted_couples_array);
echo $rm_ads_snippet;
echo '</body>
</html>';
exit(0);
?>