Tripal Plant PopGen Submit
display.inc
Go to the documentation of this file.
1 <?php
2 
20 function tpps_flatten(array $state) {
21  $data = isset($state['saved_values']) ? $state['saved_values'] : NULL;
22 
23  if (!$data) {
24  return array();
25  }
26  unset($data['frontpage']);
27  unset($data['form_build_id']);
28 
29  $page_1 = &$data[TPPS_PAGE_1];
30  $pub = &$page_1['publication'];
31  $org = &$page_1['organism'];
32 
33  if (isset($page_1['#cleared']) and $page_1['#cleared']) {
34  $data['#page_1_cleared'] = TRUE;
35  }
36  else {
37  $data['#page_1_cleared'] = FALSE;
38  }
39  $data['#study_photo'] = $page_1['photo'] ?? NULL;
40  $data['Publication DOI'] = isset($page_1['doi']) ? $page_1['doi'] : NULL;
41  $data['Publication Title'] = isset($pub['title']) ? $pub['title'] : NULL;
42  $data['Primary Author'] = isset($page_1['primaryAuthor']) ? $page_1['primaryAuthor'] : NULL;
43  $data['Organization'] = isset($page_1['organization']) ? $page_1['organization'] : NULL;
44  $data['Publication Status'] = isset($pub['status']) ? $pub['status'] : NULL;
45  $data['Publication Year'] = isset($pub['year']) ? $pub['year'] : NULL;
46  $data['Publication Abstract'] = isset($pub['abstract']) ? $pub['abstract'] : NULL;
47  $data['Publication Journal'] = isset($pub['journal']) ? $pub['journal'] : NULL;
48 
49  if (isset($pub['secondaryAuthors']['number'])) {
50  $data['#number_secondary_authors'] = $pub['secondaryAuthors']['number'];
51  for ($i = 1; $i <= $data['#number_secondary_authors']; $i++) {
52  if (isset($pub['secondaryAuthors']["$i"]) and $pub['secondaryAuthors']["$i"] != '') {
53  $data["Secondary Author $i"] = $pub['secondaryAuthors']["$i"];
54  }
55  }
56  }
57 
58  if (isset($org['number'])) {
59  $data['#number_organisms'] = $org['number'];
60  for ($i = 1; $i <= $data['#number_organisms']; $i++) {
61  if (isset($org["$i"]['name']) and $org["$i"]['name'] != '') {
62  $data["Species $i"] = $org["$i"]['name'];
63  }
64  }
65  }
66  unset($data[TPPS_PAGE_1]);
67 
68  $page_2 = &$data[TPPS_PAGE_2];
69 
70  if (isset($page_2['#cleared']) and $page_2['#cleared']) {
71  $data['#page_2_cleared'] = TRUE;
72  }
73  else {
74  $data['#page_2_cleared'] = FALSE;
75  }
76  $data['Experiment Starting Month'] = !empty($page_2['StartingDate']['month']) ? $page_2['StartingDate']['month'] : NULL;
77  $data['Experiment Starting Year'] = !empty($page_2['StartingDate']['year']) ? $page_2['StartingDate']['year'] : NULL;
78  $data['Experiment Ending Month'] = !empty($page_2['EndingDate']['month']) ? $page_2['EndingDate']['month'] : NULL;
79  $data['Experiment Ending Year'] = !empty($page_2['EndingDate']['year']) ? $page_2['EndingDate']['year'] : NULL;
80  if (!empty($page_2['study_location'])) {
81  // Legacy support for old TPPS submissions.
82  $legacy_loc = &$page_2['study_location'];
83  $data['#location_type'] = (isset($legacy_loc['type']) and $legacy_loc['type']) ? $legacy_loc['type'] : NULL;
84 
85  if ($data['#location_type'] == '2' and isset($legacy_loc['custom'])) {
86  $data['Study Location'] = $legacy_loc['custom'];
87  }
88  elseif ($data['#location_type'] and isset($legacy_loc['coordinates'])) {
89  $data['Study Location'] = $legacy_loc['coordinates'];
90  }
91  }
92 
93  if (isset($page_2['data_type']) and $page_2['data_type']) {
94  $data['Data Type'] = $page_2['data_type'];
95  }
96 
97  if (isset($page_2['study_type']) and $page_2['study_type']) {
98  $study_type_options = array(
99  1 => 'Natural Population (Landscape)',
100  2 => 'Growth Chamber',
101  3 => 'Greenhouse',
102  4 => 'Experimental/Common Garden',
103  5 => 'Plantation',
104  );
105  if (isset($study_type_options[$page_2['study_type']])) {
106  $data['Study Type'] = $study_type_options[$page_2['study_type']];
107  }
108 
109  if (!empty($page_2['study_info']['season'])) {
110  $data['Seasons Assessed'] = implode($page_2['study_info']['season']);
111  }
112 
113  if (!empty($page_2['study_info']['assessions'])) {
114  $data['Average number of assessions'] = $page_2['study_info']['assessions'];
115  }
116 
117  $data['Average High Temperature'] = isset($page_2['study_info']['temp']['high']) ? $page_2['study_info']['temp']['high'] : NULL;
118  $data['Average Low Temperature'] = isset($page_2['study_info']['temp']['low']) ? $page_2['study_info']['temp']['low'] : NULL;
119 
120  $types = array(
121  'co2' => 'CO2',
122  'humidity' => 'Air Humidity',
123  'light' => 'Light Intensity',
124  'salinity' => 'Salinity',
125  );
126 
127  foreach ($types as $type => $label) {
128  if (!empty($page_2['study_info'][$type])) {
129  $set = $page_2['study_info'][$type];
130  if (!empty($set['option'])) {
131  $data["$label Control"] = ($set['option'] == '1') ? 'Controlled' : 'Uncontrolled';
132  if ($set['option'] == '1' and !empty($set['controlled'])) {
133  $data["$label Value"] = $set['controlled'];
134  }
135  elseif (!empty($set['uncontrolled'])) {
136  $data["$label Value"] = $set['uncontrolled'];
137  }
138  }
139  }
140  }
141 
142  if (!empty($page_2['study_info']['rooting']['option'])) {
143  $data['Rooting Type'] = $page_2['study_info']['rooting']['option'];
144 
145  if ($data['Rooting Type'] == 'Soil' and !empty($page_2['study_info']['rooting']['soil']['type'])) {
146  $soil = &$page_2['study_info']['rooting']['soil'];
147  $data['Soil Type'] = $soil['type'];
148 
149  if ($data['Soil Type'] == 'Other') {
150  $data['Custom Soil Type'] = $soil['other'];
151  }
152 
153  $data['Soil Container Type'] = isset($soil['container']) ? $soil['container'] : NULL;
154  }
155  }
156 
157  if (!empty($page_2['study_info']['rooting']['ph']['option'])) {
158  $set = $page_2['study_info']['rooting']['ph'];
159  $data['pH Control'] = ($set['option'] == '1') ? 'Controlled' : 'Uncontrolled';
160 
161  if ($set['option'] == '1' and !empty($set['controlled'])) {
162  $data["pH Value"] = $set['controlled'];
163  }
164  elseif (!empty($set['uncontrolled'])) {
165  $data["pH Value"] = $set['uncontrolled'];
166  }
167  }
168 
169  if (!empty($page_2['study_info']['rooting']['treatment'])) {
170  $treatment = $page_2['study_info']['rooting']['treatment'];
171  $selected = FALSE;
172  $description = FALSE;
173 
174  foreach ($treatment as $field => $value) {
175  if (!$description) {
176  $description = TRUE;
177  $selected = ($value) ? $field : FALSE;
178  continue;
179  }
180  elseif ($selected and !empty($value)) {
181  $data["Treatment: $selected description"] = $value;
182  }
183  $description = FALSE;
184  }
185  }
186 
187  if (!empty($page_2['study_info']['irrigation']) and !empty($page_2['study_info']['irrigation']['option'])) {
188  $data['Irrigation Type'] = $page_2['study_info']['irrigation']['option'];
189  if ($data['Irrigation Type'] == 'Other' and !empty($page_2['study_info']['irrigation']['other'])) {
190  $data['Custom Irrigation Type'] = $page_2['study_info']['irrigation']['other'];
191  }
192  }
193 
194  if (!empty($page_2['study_info']['biotic_env']['option'])) {
195  $biotic_envs = array();
196  foreach ($page_2['study_info']['biotic_env']['option'] as $key => $val) {
197  if ($val) {
198  $biotic_envs[] = $key;
199  }
200  }
201 
202  if (!empty($biotic_envs)) {
203  $data['Biotic Environment'] = implode(', ', $biotic_envs);
204  if (in_array('Other', $biotic_envs) and !empty($page_2['study_info']['biotic_env']['other'])) {
205  $data['Custom Biotic Environment'] = $page_2['study_info']['biotic_env']['other'];
206  }
207  }
208  }
209 
210  if (!empty($page_2['study_info']['treatment']['check'])) {
211  $treatment = &$page_2['study_info']['treatment'];
212  $selected = FALSE;
213  $description = FALSE;
214 
215  foreach ($treatment as $field => $value) {
216  if ($field != 'check') {
217  if (!$description) {
218  $description = TRUE;
219  $selected = ($value) ? $field : FALSE;
220  continue;
221  }
222  elseif ($selected and !empty($value)) {
223  $data["Treatment: $selected description"] = $value;
224  }
225  $description = FALSE;
226  }
227  }
228  }
229  }
230  unset($data[TPPS_PAGE_2]);
231 
232  $page_3 = &$data[TPPS_PAGE_3];
233 
234  if (isset($page_3['#cleared']) and $page_3['#cleared']) {
235  $data['#page_3_cleared'] = TRUE;
236  }
237  else {
238  $data['#page_3_cleared'] = FALSE;
239  }
240 
241  $data['#skip_loc'] = !empty($page_3['skip_validation']);
242  $loc = &$page_3['study_location'];
243  $data['#location_type'] = (isset($loc['type']) and $loc['type']) ? $loc['type'] : NULL;
244 
245  if ($data['#location_type'] == '2' and isset($loc['custom'])) {
246  $data['Study Location'] = $loc['custom'];
247  }
248  elseif ($data['#location_type'] and isset($loc['coordinates'])) {
249  $data['Study Location'] = $loc['coordinates'];
250  }
251  $page_3 = &$data[TPPS_PAGE_3]['tree-accession'];
252 
253  if (!empty($data['#number_organisms'])) {
254  for ($i = 1; $i <= $data['#number_organisms']; $i++) {
255  if (!empty($page_3["species-$i"]['file'])) {
256  $organism_name = $data["Species $i"] . ' Accession File';
257  if ($data['#number_organisms'] > 1 and empty($page_3['check'])) {
258  $organism_name = 'Plant Accession File';
259  }
260 
261  $data[$organism_name] = $page_3["species-$i"]['file'];
262  $loc_type = $page_3["species-$i"]['file-groups']['Location (latitude/longitude or country/state or population group)']['#type'] ?? NULL;
263  if (!empty($loc_type) and ($loc_type == "gps" or (array_search('gps', $loc_type) !== FALSE))) {
264  $fid = $page_3["species-$i"]['file'];
265  drupal_add_js(array(
266  'tpps' => array(
267  'accession_files' => array(
268  $fid => array(
269  'no_header' => $page_3["species-$i"]['file-no-header'] ?? '0',
270  'id_col' => $page_3["species-$i"]['file-groups']['Tree Id'][1],
271  'lat_col' => $page_3["species-$i"]['file-groups']['Location (latitude/longitude or country/state or population group)'][4],
272  'long_col' => $page_3["species-$i"]['file-groups']['Location (latitude/longitude or country/state or population group)'][5],
273  ),
274  ),
275  ),
276  ), 'setting');
277  }
278  }
279 
280  if (empty($page_3['check'])) {
281  break;
282  }
283  }
284  }
285 
286  $data["Total number of plants"] = $state['stats']['tree_count'] ?? NULL;
287  unset($data[TPPS_PAGE_3]);
288 
289  $page_4 = &$data[TPPS_PAGE_4];
290 
291  if (isset($page_4['#cleared']) and $page_4['#cleared']) {
292  $data['#page_4_cleared'] = TRUE;
293  }
294  else {
295  $data['#page_4_cleared'] = FALSE;
296  }
297  if (!empty($data['#number_organisms'])) {
298  for ($i = 1; $i <= $data['#number_organisms']; $i++) {
299  if (isset($page_4["organism-$i"])) {
300  $org = &$page_4["organism-$i"];
301  $org_name = isset($data["Species $i"]) ? $data["Species $i"] : NULL;
302 
303  if (isset($org['phenotype'])) {
304  $pheno = &$org['phenotype'];
305 
306  if (!empty($pheno['iso-check'])) {
307  $data["$org_name Phenotype Isotope/Mass Spectrometry File"] = $pheno['iso'];
308  }
309  else {
310  if (isset($pheno['phenotypes-meta']['number'])) {
311  $data['#number_phenotypes'] = $pheno['phenotypes-meta']['number'];
312  $pheno_meta = &$pheno['phenotypes-meta'];
313  for ($j = 1; $j <= $data['#number_phenotypes']; $j++) {
314  $fields = array(
315  'name' => 'Name',
316  'attribute' => 'Attribute',
317  'description' => 'Description',
318  'units' => 'Units',
319  );
320  if (isset($pheno_meta["$j"]['struct-check']) and $pheno_meta["$j"]['struct-check']) {
321  $fields['structure'] = 'Structure';
322  }
323  if (isset($pheno_meta["$j"]['val-check']) and $pheno_meta["$j"]['val-check']) {
324  $fields['min'] = 'Minimum Value';
325  $fields['max'] = 'Maximum Value';
326  }
327 
328  foreach ($fields as $field => $field_string) {
329  if (isset($pheno_meta["$j"][$field]) and $pheno_meta["$j"][$field] != '') {
330  $data["$org_name Phenotype $j $field_string"] = $pheno_meta[$j][$field];
331  }
332  }
333  }
334  }
335 
336  if (isset($pheno['check']) and $pheno['check'] and isset($pheno['metadata']) and $pheno['metadata']) {
337  $data["$org_name Phenotype Metadata File"] = $pheno['metadata'];
338  }
339 
340  if (isset($pheno['file']) and $pheno['file']) {
341  $data["$org_name Phenotype File"] = $pheno['file'];
342  }
343  $data["$org_name Phenotypes Assessed"] = isset($pheno['phenotype_count']) ? $pheno['phenotype_count'] : NULL;
344  }
345  }
346 
347  if (isset($org['genotype'])) {
348  $geno = &$org['genotype'];
349 
350  $marker_types = array();
351  foreach ($geno['marker-type'] as $key => $val) {
352  if ($val) {
353  $marker_types[] = $key;
354  }
355  }
356  $data["$org_name Genotype Marker Types"] = isset($marker_types) ? implode(', ', $marker_types) : NULL;
357 
358  if (isset($geno['marker-type']['SNPs']) and $geno['marker-type']['SNPs']) {
359  $snp = $geno['SNPs'];
360  if (isset($snp['genotyping-design']) and $snp['genotyping-design']) {
361  $geno_design_options = array(
362  1 => 'GBS',
363  2 => 'Targeted Capture',
364  3 => 'Whole Genome Resequencing',
365  4 => 'RNA-Seq',
366  5 => 'Genotyping Array',
367  );
368  if (isset($geno_design_options[$snp['genotyping-design']])) {
369  $data["$org_name Genotyping Design"] = $geno_design_options[$snp['genotyping-design']];
370  }
371 
372  if (isset($data["$org_name Genotyping Design"]) and $data["$org_name Genotyping Design"] == 'GBS' and isset($snp['GBS']) and $snp['GBS']) {
373  $gbs_options = array(
374  1 => 'RADSeq',
375  2 => 'ddRAD-Seq',
376  3 => 'NextRAD',
377  4 => 'RAPTURE',
378  5 => 'Other',
379  );
380  if (isset($gbs_options[$snp['GBS']])) {
381  $data["$org_name GBS Type"] = $gbs_options[$snp['GBS']];
382  }
383 
384  if (isset($data["$org_name GBS Type"]) and $data["$org_name GBS Type"] == 'Other' and isset($snp['GBS-other']) and $snp['GBS-other'] != '') {
385  $data["$org_name Custom GBS Type"] = $snp['GBS-other'];
386  }
387  }
388 
389  if (isset($data["$org_name Genotyping Design"]) and $data["$org_name Genotyping Design"] == 'Targeted Capture' and isset($snp['targeted-capture']) and $snp['targeted-capture']) {
390  $targeted_capture_options = array(
391  1 => 'Exome Capture',
392  2 => 'Other',
393  );
394  if (isset($targeted_capture_options[$snp['targeted-capture']])) {
395  $data["$org_name Targeted Capture Type"] = $targeted_capture_options[$snp['targeted-capture']];
396  }
397 
398  if (isset($data["$org_name Targeted Capture Type"]) and $data["$org_name Targeted Capture Type"] == 'Other' and isset($snp['targeted-capture-other']) and $snp['targeted-capture-other'] != '') {
399  $data["$org_name Custom Targeted Capture Type"] = $snp['targeted-capture-other'];
400  }
401  }
402  }
403  }
404  if (isset($geno['marker-type']['SSRs/cpSSRs']) and $geno['marker-type']['SSRs/cpSSRs'] and isset($geno['SSRs/cpSSRs']) and $geno['SSRs/cpSSRs'] != '') {
405  $data["$org_name SSRs/cpSSRs Type"] = $geno['SSRs/cpSSRs'];
406  }
407  if (isset($geno['marker-type']['Other']) and $geno['marker-type']['Other'] and isset($geno['other-marker']) and $geno['other-marker'] != '') {
408  $data["$org_name Other Marker Type"] = $geno['other-marker'];
409  }
410 
411  if (isset($geno['ref-genome']) and $geno['ref-genome'] === 'bio' and isset($geno['BioProject-id']) and $geno['BioProject-id'] != '') {
412  $data["$org_name BioProject Id"] = $geno['BioProject-id'];
413 
414  if (isset($geno['assembly-auto']) and gettype($geno['assembly-auto']) === 'array') {
415  $count = 1;
416  foreach ($geno['assembly-auto'] as $id => $check) {
417  if (isset($check) and $check) {
418  $data["$org_name Linked Accession $count"] = $id;
419  $count++;
420  }
421  }
422  }
423  }
424  elseif (isset($geno['ref-genome']) and ($geno['ref-genome'] === 'manual' or $geno['ref-genome'] === 'manual2') and isset($geno['tripal_fasta']['file']['file_upload']) and isset($geno['tripal_fasta']['file']['file_upload_existing']) and ($geno['tripal_fasta']['file']['file_upload'] or $geno['tripal_fasta']['file']['file_upload_existing'])) {
425  if ($geno['tripal_fasta']['file']['file_upload']) {
426  $data["$org_name Uploaded Reference File"] = $geno['tripal_fasta']['file']['file_upload'];
427  }
428  if ($geno['tripal_fasta']['file']['file_upload_existing']) {
429  $data["$org_name Reference File"] = $geno['tripal_fasta']['file']['file_upload_existing'];
430  }
431  }
432  elseif (isset($geno['ref-genome']) and $geno['ref-genome'] === 'url' and isset($geno['tripal_fasta']['file']['file_remote']) and $geno['tripal_fasta']['file']['file_remote']) {
433  $data["$org_name Website of reference file"] = $geno['tripal_fasta']['file']['file_remote'];
434  }
435  elseif (isset($geno['ref-genome']) and $geno['ref-genome']) {
436  $data["$org_name Reference Genome"] = $geno['ref-genome'];
437  }
438 
439  if (!empty($geno['files']['snps-assay'])) {
440  $data["$org_name SNPs Genotype Assay File"] = $geno['files']['snps-assay'];
441  }
442 
443  if (!empty($geno['files']['assay-design'])) {
444  $data["$org_name Assay Design File"] = $geno['files']['assay-design'];
445  }
446 
447  if (!empty($geno['files']['ssrs'])) {
448  $data["$org_name SSRs/cpSSRs Genotype File"] = $geno['files']['ssrs'];
449  }
450 
451  if (!empty($geno['files']['ssrs_extra'])) {
452  $data["$org_name SSRs/cpSSRs Additional Genotype File"] = $geno['files']['ssrs_extra'];
453  }
454 
455  if (!empty($geno['files']['indels'])) {
456  $data["$org_name Indel Genotype File"] = $geno['files']['indels'];
457  }
458 
459  if (!empty($geno['files']['other'])) {
460  $data["$org_name Other Marker Genotype File"] = $geno['files']['other'];
461  }
462 
463  if (!empty($geno['files']['vcf'])) {
464  $data["$org_name VCF File"] = $geno['files']['vcf'];
465  }
466  }
467 
468  if (isset($org['environment'])) {
469  $env = &$org['environment'];
470 
471  if (variable_get('tpps_cartogratree_env', FALSE)) {
472  $data["CartograPlant Layers"] = array();
473  foreach ($env['env_layers'] as $layer => $layer_id) {
474  if (!empty($layer_id)) {
475  $data["CartograPlant Layers"][] = $layer;
476  }
477  if (!empty($layer_id) and !empty($env['env_params'][$layer])) {
478  $params = array();
479  foreach ($env['env_params'][$layer] as $param => $param_id) {
480  if (!empty($param_id)) {
481  $params[] = $param;
482  }
483  }
484  $data["CartograPlant Layer: $layer Parameters"] = implode(', ', $params);
485  }
486  }
487  if (!empty($data["CartograPlant Layers"])) {
488  $data["CartograPlant Layers"] = implode(', ', $data["CartograPlant Layers"]);
489  }
490  else {
491  unset($data["CartograPlant Layers"]);
492  }
493  }
494  }
495  }
496  }
497  }
498  unset($data[TPPS_PAGE_4]);
499 
500  $sum_page = &$data['summarypage'];
501  if (!empty($sum_page['comments'])) {
502  $data["Additional Comments"] = $sum_page['comments'];
503  }
504  for ($i = 1; $i <= 10; $i++) {
505  if (!empty($sum_page['files'][$i])) {
506  $data["Supplemental File $i"] = $sum_page['files'][$i];
507  }
508  }
509  if (!empty($sum_page['tree_pictures'])) {
510  foreach ($sum_page['tree_pictures'] as $name => $fid) {
511  if (substr($name, -4) == '_url' or substr($name, -12) == '_attribution' or substr($name, -8) == '_license') {
512  continue;
513  }
514  if (!$fid) {
515  $data["$name species photo"] = t('None provided');
516  }
517  else {
518  $data["$name species photo"] = $fid;
519  }
520  }
521  }
522  unset($data['summarypage']);
523 
524  $data['#dbxref_id'] = isset($state['dbxref_id']) ? $state['dbxref_id'] : NULL;
525  $data['#accession'] = isset($state['accession']) ? $state['accession'] : NULL;
526  $data['#status'] = isset($state['status']) ? $state['status'] : NULL;
527 
528  foreach ($data as $key => $val) {
529  if (!isset($val)) {
530  unset($data[$key]);
531  }
532  }
533 
534  return $data;
535 }
536 
546 function tpps_table_display(array &$state, array $options = array()) {
547 
548  $flat = tpps_flatten($state);
549  $map_api_key = variable_get('tpps_maps_api_key', NULL);
550 
551  $rows = array();
552  $content = "";
553  foreach ($flat as $key => $val) {
554  if ($key[0] != '#') {
555  $key_str = filter_xss(check_plain($key));
556  $val_str = filter_xss(check_plain($val));
557 
558  if (preg_match('/File/', $key) and ($file = file_load($val))) {
559  // Create links to files.
560  $file_name = $file->filename;
561  $file_url = check_plain(file_create_url($file->uri));
562  $val_str = "<a href='$file_url' target='blank'>$file_name</a>";
563  if (!empty($state['revised_files'][$val]) and ($revised_file = file_load($state['revised_files'][$val]))) {
564  $val = $state['revised_files'][$val];
565  $file_url = check_plain(file_create_url($revised_file->uri));
566  $file_name = $revised_file->filename;
567  $val_str = "<a href='$file_url' target='blank'>$file_name</a> ( Revised from $val_str )";
568  }
569  $val_str .= "<br><input id=\"fid_$val\" class=\"preview_button\" type=\"button\" value=\"Preview file\"></input>";
570  if (tpps_access('administer tpps module')) {
571  $val_str .= "<br><input id=\"fid_$val\" class=\"preview_full_button\" type=\"button\" value=\"Show full file\"></input>";
572  }
573  if (preg_match('/^(.*)Accession File/', $key, $matches)) {
574  if (!$flat['#skip_loc']) {
575  $fid = $file->fid;
576  $wrapper_id = "{$fid}_map_wrapper";
577  $button_id = "{$fid}_map_button";
578  $val_str .= "<div id=\"$wrapper_id\"></div>"
579  . "<input id=\"$button_id\" type=\"button\" value=\"Click here to view plants on map!\"></input>";
580 
581  drupal_add_js(array(
582  'tpps' => array(
583  'map_buttons' => array(
584  $fid => array(
585  'wrapper' => $wrapper_id,
586  'button' => $button_id,
587  'fid' => $fid,
588  ),
589  ),
590  ),
591  ), 'setting');
592  }
593  else {
594  $val_str .= "<br>This submission was submitted without validating location information. As a result, we did not import location information for these plants.";
595  }
596  }
597 
598  if (!empty($options['files']['revision_destination'])) {
599  $val_str .= "<div id=\"file_{$file->fid}_options_dest\"></div>";
600  }
601  }
602  elseif (preg_match('/species photo/', $key) and (file_load($val)) and ($file_name = file_load($val)->filename)) {
603  $file_url = check_plain(file_create_url(file_load($val)->uri));
604  $val_str = "<img src='$file_url' width='100%'>";
605  $val_str .= "<br><a href='$file_url' target='blank'>$file_name</a>";
606  }
607  elseif (preg_match('/Month/', $key)) {
608  // Skip experiment start/end month.
609  continue;
610  }
611  elseif (preg_match('/^(.*)Year/', $key, $matches)) {
612  // Combine experiment start/end month + year.
613  if (isset($flat[$matches[1] . 'Month'])) {
614  $key_str = $matches[1] . 'Date';
615  $val_str = "{$flat[$matches[1] . 'Month']} $val_str";
616  }
617  else {
618  continue;
619  }
620  }
621  elseif (preg_match('/Study Location/', $key) and isset($flat['#location_type']) and $flat['#location_type']) {
622  // Add map capability to location.
623  if ($flat['#location_type'] == '2') {
624  $query = $val_str;
625  }
626  elseif ($flat['#location_type'] != '2' and ($standard = tpps_standard_coord($val_str))) {
627  $query = $standard;
628  }
629  $val_str = "<a id=\"sidebar_map\" style=\"cursor:pointer\">$val_str</a>";
630  if (isset($query)) {
631  $map = "<iframe frameborder=\\\"0\\\" style=\\\"border:0;width:100%;height:100%\\\" src=\\\"https://www.google.com/maps?q=$query&output=embed&key=AIzaSyDkeQ6KN6HEBxrIoiSCrCHFhIbipycqouY&z=5\\\" allowfullscreen> </iframe></div>";
632  $js = "jQuery(document).ready(function ($) {
633  jQuery(\"#sidebar_map\").click(function() {
634  jQuery(\"#sidebar_map_wrapper\").remove();
635  jQuery(\"#sidebar_map\").after( \"<br><div id=\\\"sidebar_map_wrapper\\\">$map</div>\" );
636  });
637  });";
638  drupal_add_js($js, 'inline');
639  }
640  }
641  elseif ($key == 'Publication Abstract' and strlen($val_str) > 50) {
642  $val_str = substr($val_str, 0, 47) . '...';
643  }
644  elseif ($key == 'Publication DOI') {
645  $link = preg_match('/https?:\/\//', $val_str) ? $val_str : "https://doi.org/$val_str";
646  $val_str = "<a href=\"$link\" target=\"blank\">$val_str</a>";
647  }
648  elseif (!empty($options['skip_phenotypes']) and preg_match('/Phenotype/', $key)) {
649  continue;
650  }
651 
652  $rows[] = array($key_str, $val_str);
653  }
654  elseif (preg_match('/^#(.*)accession_(.*)/', $key, $matches)) {
655  $val_str = filter_xss(check_plain($val));
656  $parts = explode(" ", substr($matches[0], 1));
657  $item_id = implode("_", $parts);
658  $content .= "<div id=\"$item_id\" style=\"display:none;\">$val_str</div>";
659  }
660  }
661  if (!empty($map_api_key)) {
662  $content .= "<script src=\"https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js\"></script><script src=\"https://maps.googleapis.com/maps/api/js?key=$map_api_key&callback=initMap\"
663  async defer></script>";
664  }
665 
666  $headers = array(
667  'Field',
668  'Value',
669  );
670 
671  $vars = array(
672  'header' => $headers,
673  'rows' => $rows,
674  'attributes' => array(
675  'class' => array('view'),
676  'id' => 'tpps_table_display',
677  ),
678  'caption' => '',
679  'colgroups' => NULL,
680  'sticky' => FALSE,
681  'empty' => '',
682  );
683 
684  $photo = "";
685  if (!empty($flat['#study_photo'])) {
686  $url = check_plain(file_create_url(file_load($flat['#study_photo'])->uri));
687  $photo = "<img src=\"$url\" style=\"display: block; margin-left: auto; margin-right: auto;\"></img>";
688  }
689 
690  $display = $photo . theme('table', $vars) . $content;
691 
692  return $display;
693 }
694 
704 function tpps_completed_display($accession = NULL) {
705 
706  global $base_url;
707  global $user;
708  $display = "";
709  $link = "$base_url/tpps/details/$accession";
710 
711  $old_form_state = tpps_load_submission($accession);
712  $values = $old_form_state['saved_values'];
713 
714  $css = "
715  .tgdr_complete_submission {
716  background: #ffffff;
717  border: 1px solid #cccccc;
718  border-radius: 4px;
719  padding: 0px 10px;
720  }
721  ";
722  drupal_add_css($css, 'inline');
723 
724  $display .= "<label for='tpps_$accession'>{$values[TPPS_PAGE_1]['publication']['title']}</label><p>You can view the TPPS Details page with completed and approved TPPS and TGDR data <a href=\"$link\">here</a></p>";
725  if ($values[TPPS_PAGE_1]['publication']['status'] != 'Published' and $user->uid == tpps_load_submission($accession, FALSE)->uid) {
726  $display .= "<a href=\"$base_url/tpps/$accession/edit-publication\">Edit publication information</a>";
727  }
728 
729  $display .= tpps_table_display($old_form_state);
730 
731  drupal_add_js(drupal_get_path('module', 'tpps') . TPPS_JS_PATH);
732  drupal_add_css(drupal_get_path('module', 'tpps') . TPPS_CSS_PATH);
733 
734  return render($display);
735 }
736 
749 function tpps_tab_create($uid) {
750 
751  $user = user_load($uid);
752  if (empty($user)) {
753  drupal_goto('user');
754  }
755 
756  global $base_url;
757  $params = drupal_get_query_parameters();
758 
759  if (isset($params['accession']) and isset($params['action']) and $params['action'] === 'DELETE') {
760  tpps_delete_submission($params['accession']);
761  }
762 
763  $states = tpps_load_submission_multiple(array(
764  'status' => 'Incomplete',
765  'uid' => $user->uid,
766  ));
767 
768  $rows = array();
769  foreach ($states as $state) {
770  $prefix = !empty($state['tpps_type']) ? $state['tpps_type'] : 'tpps';
771  $page_1 = &$state['saved_values'][TPPS_PAGE_1];
772  $title = $abstract = $accession_cell = NULL;
773 
774  if (isset($page_1['publication']['title'])) {
775  $title = "<a href='$base_url/$prefix/{$state['accession']}' style='text-decoration: underline;'>" . check_plain($page_1['publication']['title']) . "</a>";
776  }
777  else {
778  $title = "<a href='$base_url/$prefix/{$state['accession']}' style='text-decoration: underline;'>No Title</a>";
779  }
780 
781  if (isset($page_1['publication']['abstract'])) {
782  $abstract = check_plain($page_1['publication']['abstract']);
783  if (strlen($abstract) > 53) {
784  $abstract = substr($abstract, 0, 50) . "...";
785  }
786  }
787 
788  if (isset($state['accession'])) {
789  $accession_cell = "<input type='submit' id='delete-{$state['accession']}' onclick='";
790  $name = isset($page_1['publication']['title']) ? ' titled ' . $page_1['publication']['title'] : '';
791  $name = str_replace("'", "", $name); // remove single quotes
792  $name = str_replace('"', "", $name); // remove double quotes
793  $accession_cell .= "if (confirm(\"Attention! \\n\\nAre you sure you want to delete your submission{$name}?\\nThis action cannot be undone, and all of your data will be lost!\")){window.location.href = \"$base_url/tpps-submission/{$state['accession']}/delete\"}";
794  $accession_cell .= "' name='op' class='form-button' value='Delete'>";
795  }
796 
797  $rows[] = array(
798  $title,
799  isset($page_1['primaryAuthor']) ? $page_1['primaryAuthor'] : "",
800  isset($page_1['organism']['number']) ? $page_1['organism']['number'] : "",
801  isset($abstract) ? $abstract : "",
802  isset($page_1['publication']['journal']) ? $page_1['publication']['journal'] : "",
803  isset($accession_cell) ? $accession_cell : "",
804  );
805  }
806 
807  $headers = array(
808  'Title',
809  'Primary Author',
810  'Number of Species',
811  'Abstract',
812  'Journal',
813  );
814 
815  $vars = array(
816  'header' => $headers,
817  'rows' => $rows,
818  'attributes' => array(
819  'class' => array('view'),
820  'id' => 'tpps_incomplete_table',
821  ),
822  'caption' => '',
823  'colgroups' => NULL,
824  'sticky' => FALSE,
825  'empty' => '',
826  );
827 
828  $final = isset($state) ? "<div class='tpps_table'><label for='tpps_incomplete_table'>Incomplete Submissions</label>" . theme('table', $vars) . '</div>' : "";
829  $state = NULL;
830 
831  $states = tpps_load_submission_multiple(array(
832  'status' => array('Pending Approval', 'Approved'),
833  'uid' => $user->uid,
834  ));
835 
836  $rows = array();
837  foreach ($states as $state) {
838  $page_1 = &$state['saved_values'][TPPS_PAGE_1];
839  $title = $abstract = NULL;
840 
841  if (isset($page_1['publication']['title'])) {
842  $title = "<a href='$base_url/completed-submission/{$state['accession']}' style='text-decoration: underline;'>" . check_plain($page_1['publication']['title']) . "</a>";
843  }
844  else {
845  $title = "<a href='$base_url/completed-submission/{$state['accession']}' style='text-decoration: underline;'>No Title</a>";
846  }
847 
848  if (isset($page_1['publication']['abstract'])) {
849  $abstract = check_plain($page_1['publication']['abstract']);
850  if (strlen($abstract) > 103) {
851  $abstract = substr($abstract, 0, 100) . "...";
852  }
853  }
854 
855  $rows[] = array(
856  isset($title) ? $title : "",
857  isset($page_1['primaryAuthor']) ? $page_1['primaryAuthor'] : "",
858  isset($page_1['organism']['number']) ? $page_1['organism']['number'] : "",
859  isset($abstract) ? $abstract : "",
860  isset($page_1['publication']['journal']) ? $page_1['publication']['journal'] : "",
861  isset($state['status']) ? $state['status'] : "",
862  );
863  }
864 
865  $headers[] = 'Status';
866  $vars['header'] = $headers;
867  $vars['rows'] = $rows;
868  $vars['attributes']['id'] = 'tpps_complete_table';
869 
870  $final .= isset($state) ? "<div class='tpps_table'><label for='tpps_complete_table'>Complete Submissions</label>" . theme('table', $vars) . '</div>' : "";
871 
872  if (empty($final)) {
873  $final .= "<h2>Could not find any Submissions</h2>";
874  $final .= "<p>We could not find any incomplete TPPS Submissions or TPPS Submissions pending approval. If you would like to start a new TPPS Submission, you can start <a href=$base_url/tpps>here.</a></p>";
875  }
876 
877  drupal_add_css(drupal_get_path('module', 'tpps') . TPPS_CSS_PATH);
878  return $final;
879 }
880 
887 function tpps_preview_file() {
888  $params = drupal_get_query_parameters($_POST);
889  $no_header = FALSE;
890  $fid = $params['fid'] ?? NULL;
891  if (empty($fid)) {
892  return;
893  }
894  $rows = $params['rows'] ?? 3;
895  $file = file_load($fid);
896  $location = tpps_get_location($file->uri);
897  $extension = tpps_get_path_extension($location);
898 
899  if ($extension == 'vcf') {
900  $display = "";
901  $count = 0;
902  $vcf_content = gzopen($location, 'r');
903  while (($vcf_line = gzgets($vcf_content)) !== FALSE) {
904  $display .= $vcf_line . "<br>";
905  $count++;
906  if ($count > $rows) {
907  break;
908  }
909  }
910  print(render($display));
911  return;
912  }
913 
914  if ((file_load($fid))) {
915  $content = tpps_parse_file($fid, $rows, !empty($no_header));
916  $rows = array();
917  for ($i = 0; $i < count($content) - 1; $i++) {
918  $rows[] = $content[$i];
919  }
920  $vars = array(
921  'header' => $content['headers'],
922  'rows' => $rows,
923  'attributes' => array(
924  'class' => array(
925  'view',
926  "preview_$fid",
927  ),
928  'id' => 'tpps_table_display',
929  ),
930  'caption' => '',
931  'colgroups' => NULL,
932  'sticky' => FALSE,
933  'empty' => '',
934  );
935  $display = render(theme('table', $vars));
936  print($display);
937  return;
938  }
939 }
940 
954 function tpps_entity_link($id, $name, $label) {
955  global $base_url;
956  $bundle = tripal_load_bundle_entity(array('label' => $label));
957  if (empty($bundle)) {
958  return $name;
959  }
960  $entity_id = chado_get_record_entity_by_bundle($bundle, $id);
961  if (!empty($entity_id)) {
962  return "<a href=\"$base_url/bio_data/$entity_id\">$name</a>";
963  }
964  return $name;
965 }
966 
976 function tpps_show_tags(array $tags) {
977  $display = "";
978  foreach ($tags as $tag) {
979  $color = !empty($tag['color']) ? $tag['color'] : 'white';
980  $display .= "<span class=\"tag\" style=\"background-color:$color\"><span class=\"tag-text\">{$tag['name']}</span></span>";
981  }
982  return $display;
983 }
tpps_standard_coord($raw_coordinate)
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_flatten(array $state)
Definition: display.inc:20
const TPPS_CSS_PATH
Definition: tpps.module:11
const TPPS_JS_PATH
Definition: tpps.module:10
tpps_completed_display($accession=NULL)
Definition: display.inc:704
tpps_show_tags(array $tags)
Definition: display.inc:976
tpps_access()
Definition: tpps.module:341
tpps_entity_link($id, $name, $label)
Definition: display.inc:954
tpps_preview_file()
Definition: display.inc:887
tpps_get_path_extension($path)
Definition: file_utils.inc:661
tpps_tab_create($uid)
Definition: display.inc:749
tpps_delete_submission($accession, $redirect=TRUE)
tpps_table_display(array &$state, array $options=array())
Definition: display.inc:546
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27
const TPPS_PAGE_4
Definition: tpps.module:15
tpps_load_submission_multiple(array $conditions=array(), $state=TRUE)
Definition: submissions.inc:85
tpps_get_location($location)
Definition: file_utils.inc:640
const TPPS_PAGE_3
Definition: tpps.module:14
const TPPS_PAGE_2
Definition: tpps.module:13
tpps_parse_file($fid, $max_rows=0, $no_header=FALSE, $columns=NULL)
Definition: file_utils.inc:25