Tripal Plant PopGen Submit
submissions.inc
Go to the documentation of this file.
1 <?php
2 
27 function tpps_load_submission($accession, $state = TRUE) {
28  $result = db_select('tpps_submission', 's')
29  ->fields('s')
30  ->condition('accession', $accession)
31  ->range(0, 1)
32  ->execute()->fetchObject();
33 
34  if ($result) {
35  if ($state) {
36  return unserialize($result->submission_state);
37  }
38  return $result;
39  }
40 
41  // Search for alternative accessions.
42  $query = db_select('tpps_submission', 's');
43  $query->join('tpps_submission_dbxref', 's_dbx', 's.tpps_submission_id = s_dbx.tpps_submission_id');
44  $query->join('chado.dbxref', 'dbx', 'dbx.dbxref_id = s_dbx.dbxref_id');
45  $query->fields('s');
46  $query->condition('dbx.accession', $accession);
47  $query->condition('s.status', 'Approved');
48  $query->range(0, 1);
49  $query = $query->execute();
50  $result = $query->fetchObject();
51 
52  if ($result) {
53  if ($state) {
54  return unserialize($result->submission_state);
55  }
56  return $result;
57  }
58 
59  // Provide legacy support for older TPPS submissions.
60  global $user;
61  $state = variable_get('tpps_incomplete_' . $user->mail . $accession, NULL);
62  if (!empty($state)) {
63  return $state;
64  }
65  else {
66  return variable_get('tpps_complete_' . $user->mail . $accession, NULL);
67  }
68 }
69 
85 function tpps_load_submission_multiple(array $conditions = array(), $state = TRUE) {
86  $submissions = array();
87  $query = db_select('tpps_submission', 's')
88  ->fields('s');
89 
90  if (!empty($conditions)) {
91  foreach ($conditions as $key => $cond) {
92  if (!empty($cond)) {
93  if (!is_array($cond)) {
94  $query->condition($key, $cond);
95  }
96  else {
97  $or = db_or();
98  foreach ($cond as $item) {
99  $or->condition($key, $item);
100  }
101  $query->condition($or);
102  }
103  }
104  }
105  }
106 
107  $results = $query->execute();
108  while (($result = $results->fetchObject())) {
109  if ($state) {
110  $submissions[] = unserialize($result->submission_state);
111  continue;
112  }
113  $submissions[] = $result;
114  }
115  return $submissions;
116 }
117 
126 function tpps_create_submission(array $state, $uid) {
127  $values = array(
128  'uid' => $uid,
129  'status' => 'Incomplete',
130  'accession' => $state['accession'],
131  'dbxref_id' => $state['dbxref_id'],
132  'submission_state' => serialize($state),
133  );
134 
135  db_insert('tpps_submission')
136  ->fields($values)
137  ->execute();
138 
139  if ((!isset($state['tpps_type']) or $state['tpps_type'] != 'tppsc')) {
140  tpps_submission_add_tag($state['accession'], 'TPPS');
141  }
142  else {
143  tpps_submission_add_tag($state['accession'], 'TPPSc');
144  }
145 }
146 
157 function tpps_change_tgdr_number($old_accession, $new_accession, TripalJob $job = NULL) {
158  $job->logMessage('[INFO] Clearing database for study ' . $old_accession);
159  $job->setInterval(1);
160  // Clear the db of all data for the old study accession
161  tpps_submission_clear_db($old_accession);
162 
163  $job->logMessage('[INFO] Alter submission state data from ' . $old_accession . ' to ' . $new_accession);
164  // Update the form state data for the study
165  $submission = tpps_load_submission($old_accession, FALSE);
166  $state = unserialize($submission->submission_state);
167 
168  $job->logMessage('Original submission data for ' . $old_accession);
169  $job->logMessage(print_r($state, true));
170 
171  // Update the TGDR with the new_accession
172  // First encode to JSON before string replacement
173  $state_json = json_encode($state);
174 
175  // Now replace the old accession with the new accession
176  $state_json = str_replace($old_accession,$new_accession,$state_json);
177 
178  // Now convert JSON back to an array
179  $state = json_decode($state_json,true);
180 
181 
182 
183  $job->logMessage('New submission data for ' . $new_accession);
184  $job->logMessage(print_r($state, true));
185 
186  // This function will not work here because it tries to update
187  // a non existing TGDR (the new one has not been created as yet)
188  // The update SQL after this, will make it exist because
189  // it renames the old tgdr number to the new tgdr number
190  // So instead of this function tpps_update_submission, manually do it
191  // tpps_update_submission($state);
192 
193  $options['status'] = 'Approved';
194  $state['updated'] = time();
195  $options['submission_state'] = serialize($state);
196 
197  db_update('tpps_submission')
198  ->fields($options)
199  ->condition('accession', $old_accession)
200  ->execute();
201 
202 
203  $job->logMessage('[INFO] Update tpps_submission table study ' . $old_accession . ' to ' . $new_accession);
204  // Now change the accession number in the tpps_submission table
205  $transaction = db_transaction();
206  try {
207  chado_query('UPDATE tpps_submission SET accession = :new_accession WHERE accession = :old_accession', array(
208  ':new_accession' => $new_accession,
209  ':old_accession' => $old_accession
210  ));
211  }
212  catch (\Exception $e) {
213  $transaction->rollback();
214  throw $e;
215  }
216 
217  $job->logMessage('Completed! The next job in the queue should reimport the study data for ' . $new_accession);
218 }
219 
231 function tpps_update_submission(array $state, array $options = array()) {
232  if (empty($options['status']) and !empty($state['status'])) {
233  $options['status'] = $state['status'];
234  }
235  $state['updated'] = time();
236  $options['submission_state'] = serialize($state);
237 
238 
239  // dpm($options);
240  // dpm($state['accession']);
241 
242 
243  db_update('tpps_submission')
244  ->fields($options)
245  ->condition('accession', $state['accession'])
246  ->execute();
247 }
248 
257 function tpps_delete_submission($accession, $redirect = TRUE) {
258  global $user;
259  $submission = tpps_load_submission($accession, FALSE);
260  $dbxref_id = $submission->dbxref_id;
261  $state = unserialize($submission->submission_state);
262  db_delete('tpps_submission')
263  ->condition('accession', $accession)
264  ->execute();
265  if (empty($state['saved_values']['frontpage']['use_old_tgdr'])) {
266  db_delete('chado.dbxref')
267  ->condition('dbxref_id', $dbxref_id)
268  ->execute();
269  }
270  if ($redirect) {
271  drupal_goto("user/{$user->uid}/tpps");
272  }
273 }
274 
283 function tpps_submission_add_alternative_accession(array $state, $alt_accession) {
284  $tpps_local_db = variable_get('tpps_local_db');
285  if (!is_array($alt_accession)) {
286  $alt_accession = array($alt_accession);
287  }
288 
289  $state_id = tpps_load_submission($state['accession'], FALSE)->tpps_submission_id;
290 
291  // Remove the existing alternative accessions.
292  db_delete('tpps_submission_dbxref')
293  ->condition('tpps_submission_id', $state_id)
294  ->execute();
295 
296  foreach ($alt_accession as $acc) {
297  $dbx = chado_select_record('dbxref', array('*'), array(
298  'db_id' => $tpps_local_db->db_id,
299  'accession' => $acc,
300  ));
301  $dbxref_id = current($dbx)->dbxref_id ?? NULL;
302 
303  if (empty($dbxref_id)) {
304  $dbx = chado_insert_record('dbxref', array(
305  'db_id' => $tpps_local_db->db_id,
306  'accession' => $acc,
307  ));
308  $dbxref_id = $dbx['dbxref_id'];
309  }
310 
311  db_insert('tpps_submission_dbxref')
312  ->fields(array(
313  'tpps_submission_id' => $state_id,
314  'dbxref_id' => $dbxref_id,
315  ))
316  ->execute();
317  }
318 }
319 
327 
328  $query = db_select('tpps_tag', 't')
329  ->fields('t')
330  ->execute();
331 
332  $rows = array();
333  while (($result = $query->fetchObject())) {
334  $color = !empty($result->color) ? $result->color : 'white';
335  $edit_link = $result->static ? "" : "<a href=\"tpps-tag/edit/{$result->tpps_tag_id}\">edit</a>";
336  $rows[$result->tpps_tag_id] = array(
337  "<span class=\"tag\" style=\"background-color:$color\"><span class=\"tag-text\">{$result->name}</span></span>",
338  $result->name,
339  $color,
340  $edit_link,
341  );
342  }
343 
344  ksort($rows);
345 
346  $vars = array(
347  'header' => array(
348  'Tag',
349  'Name',
350  'Color',
351  '',
352  ),
353  'rows' => $rows,
354  'attributes' => array(
355  'class' => array('view'),
356  'id' => 'tpps_table_display',
357  ),
358  'caption' => '',
359  'colgroups' => NULL,
360  'sticky' => FALSE,
361  'empty' => '',
362  );
363 
364  $output = theme('table', $vars);
365 
366  drupal_add_js(drupal_get_path('module', 'tpps') . TPPS_JS_PATH);
367  drupal_add_css(drupal_get_path('module', 'tpps') . TPPS_CSS_PATH);
368 
369  return $output;
370 }
371 
383 function tpps_submission_tag_create(array $form, array &$form_state) {
384  // This will add the color picker to the TPPS submission tags edit-color
385  // field id.
386  drupal_add_js('https://cdnjs.cloudflare.com/ajax/libs/tinyColorPicker/1.1.1/jqColorPicker.min.js', 'external');
387  drupal_add_js(drupal_get_path('module', 'tpps') . '/js/tag_colorpicker.js');
388 
389  $form['name'] = array(
390  '#type' => 'textfield',
391  '#title' => t('Name'),
392  '#description' => t('The name of the new tag'),
393  '#required' => TRUE,
394  '#prefix' => '<a href="/tpps-tag">Back to TPPS Submission Tags page</a>',
395  );
396 
397  $form['color'] = array(
398  '#type' => 'textfield',
399  '#title' => t('Color'),
400  '#description' => t('The color of the new tag. Can be the name of a color, like "red" or "blue", or can be a hexidecimal color like "#FFFFFF" or "#A2C32F". Hexidecimal colors must start with the "#" character.'),
401  '#required' => TRUE,
402  '#suffix' => '<div id="color-picker"><a>Toggle Color Picker</a></div>',
403  );
404 
405  $form['submit'] = array(
406  '#type' => 'submit',
407  '#value' => t('Submit'),
408  );
409 
410  return $form;
411 }
412 
416 function tpps_submission_tag_create_validate(&$form, &$form_state) {
417  $result = db_select('tpps_tag', 't')
418  ->fields('t')
419  ->condition('name', $form_state['values']['name'], 'ILIKE')
420  ->range(0, 1)
421  ->execute()->fetchObject();
422  if (!empty($result)) {
423  form_set_error('name', t("A tag already exists with this name. Please select a different name or use the existing tag."));
424  }
425 }
426 
430 function tpps_submission_tag_create_submit($form, &$form_state) {
431  db_insert('tpps_tag')
432  ->fields(array(
433  'name' => $form_state['values']['name'],
434  'color' => $form_state['values']['color'],
435  ))
436  ->execute();
437  drupal_goto('tpps-tag');
438 }
439 
453 function tpps_submission_tag_edit(array $form, array &$form_state, $tag_id = NULL) {
454  if (empty($tag_id)) {
455  drupal_goto('tpps-tag');
456  }
457 
458  $tag = db_select('tpps_tag', 't')
459  ->fields('t')
460  ->condition('tpps_tag_id', $tag_id)
461  ->range(0, 1)
462  ->execute()->fetchObject();
463 
464  if (empty($tag) or $tag->static) {
465  drupal_goto('tpps-tag');
466  }
467 
468  $form = tpps_submission_tag_create($form, $form_state);
469 
470  $form['name']['#default_value'] = $tag->name;
471  $form['color']['#default_value'] = $tag->color;
472 
473  $form['id'] = array(
474  '#type' => 'hidden',
475  '#value' => $tag_id,
476  );
477 
478  return $form;
479 }
480 
484 function tpps_submission_tag_edit_validate(&$form, &$form_state) {
485  $result = db_select('tpps_tag', 't')
486  ->fields('t')
487  ->condition('name', $form_state['values']['name'], 'ILIKE')
488  ->condition('tpps_tag_id', $form_state['values']['id'], '!=')
489  ->range(0, 1)
490  ->execute()->fetchObject();
491  if (!empty($result)) {
492  form_set_error('name', t("A tag already exists with this name. Please select a different name or use the existing tag."));
493  }
494 }
495 
499 function tpps_submission_tag_edit_submit($form, &$form_state) {
500  db_update('tpps_tag')
501  ->fields(array(
502  'name' => $form_state['values']['name'],
503  'color' => $form_state['values']['color'],
504  ))
505  ->condition('tpps_tag_id', $form_state['values']['id'])
506  ->execute();
507  drupal_goto('tpps-tag');
508 }
509 
519 function tpps_submission_get_tags($accession) {
520  $query = db_select('tpps_submission_tag', 'st');
521  $query->join('tpps_submission', 's', 's.tpps_submission_id = st.tpps_submission_id');
522  $query->join('tpps_tag', 't', 't.tpps_tag_id = st.tpps_tag_id');
523  $query->fields('t');
524  $query->condition('s.accession', $accession);
525  $query = $query->execute();
526  $results = array();
527  while (($result = $query->fetchObject())) {
528  $results[$result->tpps_tag_id] = array(
529  'id' => $result->tpps_tag_id,
530  'name' => $result->name,
531  'color' => $result->color,
532  'static' => $result->static,
533  );
534  }
535  return $results;
536 }
537 
545  $tags = array(
546  'Genotype',
547  'Phenotype',
548  'Environment',
549  );
550  foreach ($tags as $tag) {
551  tpps_submission_remove_tag($accession, $tag);
552  }
553 }
554 
565 function tpps_submission_add_remove_tag($type, $accession, $tag) {
566  $result = db_select('tpps_tag', 't')
567  ->fields('t')
568  ->condition('tpps_tag_id', $tag)
569  ->range(0, 1)
570  ->execute()->fetchObject();
571 
572  if ($result->static) {
573  drupal_goto('tpps-tag');
574  }
575 
576  if ($type == 'add') {
577  tpps_submission_add_tag($accession, $tag);
578  }
579  if ($type == 'remove') {
580  tpps_submission_remove_tag($accession, $tag);
581  }
582 }
583 
592 function tpps_submission_add_tag($accession, $tag) {
593  if (gettype($tag) == 'string') {
594  $id = tpps_get_tag_id($tag);
595  if (!empty($id)) {
596  $tag = $id;
597  }
598  }
599 
600  $tags = tpps_submission_get_tags($accession);
601  if (!array_key_exists($tag, $tags)) {
602  db_insert('tpps_submission_tag')
603  ->fields(array(
604  'tpps_submission_id' => tpps_load_submission($accession, FALSE)->tpps_submission_id,
605  'tpps_tag_id' => $tag,
606  ))
607  ->execute();
608  }
609 }
610 
619 function tpps_submission_remove_tag($accession, $tag) {
620  if (gettype($tag) == 'string') {
621  $id = tpps_get_tag_id($tag);
622  if (!empty($id)) {
623  $tag = $id;
624  }
625  }
626  db_delete('tpps_submission_tag')
627  ->condition('tpps_submission_id', tpps_load_submission($accession, FALSE)->tpps_submission_id)
628  ->condition('tpps_tag_id', $tag)
629  ->execute();
630 }
631 
641 function tpps_get_tag_id($name) {
642  $result = db_select('tpps_tag', 't')
643  ->fields('t', array('tpps_tag_id'))
644  ->condition('name', $name)
645  ->range(0, 1)
646  ->execute()->fetchObject();
647 
648  if ($result) {
649  return $result->tpps_tag_id;
650  }
651  return FALSE;
652 }
653 
660 function tpps_submission_rename_files($accession) {
661  $state = tpps_load_submission($accession);
662  if (!empty($state['file_info'])) {
663  $state['files'] = array();
664  foreach ($state['file_info'] as $page_files) {
665  foreach ($page_files as $fid => $name) {
666  $state['files'][] = $fid;
667  if ($name === '#NO_RENAME') {
668  continue;
669  }
670  $old_file = file_load($fid);
671  if ($old_file->uri[0] != '/') {
672  $old_path = file_create_url($old_file->uri);
673  // Prepare new file_name.
674  $file_load = file_load($fid);
675  $new_filename = $accession .'_'.$name . "." . tpps_get_path_extension($file_load->uri);
676  if (!preg_match('/^(.*\/)(.*)$/', $new_name, $matches)) {
677  preg_match('/^(.*\/).*$/', $file->uri, $matches);
678  $new_filename = $matches[1] . $new_filename;
679  }
680  // Check if file already exists then return that file.
681  if ($new_filename != '') {
682  $result = db_query('SELECT f.fid
683  FROM {file_managed} f WHERE f.uri = :uri', array(':uri' => $new_filename));
684  $record = $result->fetchObject();
685  }
686 
687  if(isset($record)) {
688  $file = file_load($record->fid);
689  }
690  else {
691  $file = tpps_rename_file($fid, "{$accession}_{$name}");
692  $file->status = FILE_STATUS_PERMANENT;
693  $file = file_save($file);
694  }
695 
696  $new_path = file_create_url($file->uri);
697  chado_update_record('projectprop', array(
698  'project_id' => $state['ids']['project_id'],
699  'value' => $old_path,
700  ), array(
701  'value' => $new_path,
702  ));
703  }
704  if (!empty($state['revised_files'][$fid])) {
705  $rev_fid = $state['revised_files'][$fid];
706  $state['files'][] = $rev_fid;
707  $file = tpps_rename_file($rev_fid, "{$accession}_{$name}_revised");
708  $file->status = FILE_STATUS_PERMANENT;
709  file_save($file);
710  }
711  }
712  }
713  tpps_update_submission($state);
714  }
715 }
716 
730 function tpps_submission_clear_db($accession) {
731  $state = tpps_load_submission($accession);
732  $state['file_rank'] = 0;
733  $project_id = $state['ids']['project_id'] ?? NULL;
734  if (empty($project_id)) {
735  return FALSE;
736  }
737  if (empty($accession)) {
738  throw new Exception('Accession cannot be empty');
739  }
740 
741  $stocks_sql = "SELECT stock_id FROM chado.project_stock WHERE project_id = $project_id";
742  chado_query("UPDATE chado.project_dbxref SET is_current = FALSE WHERE project_id = $project_id");
743  chado_query("DELETE FROM chado.project_organism WHERE project_id = $project_id");
744  chado_query("DELETE FROM chado.project_pub WHERE project_id = $project_id");
745  chado_query("DELETE FROM chado.projectprop WHERE project_id = $project_id");
746  db_query("DELETE FROM public.tpps_project_file_managed WHERE project_id = $project_id");
747  chado_query("DELETE FROM chado.phenotype_cvterm WHERE phenotype_id IN (SELECT phenotype_id from chado.stock_phenotype WHERE stock_id in ($stocks_sql))");
748  chado_query("DELETE FROM chado.phenotype_to_synonym WHERE phenotype_id IN (SELECT phenotype_id FROM chado.stock_phenotype WHERE stock_id IN ($stocks_sql))");
749  chado_query("DELETE FROM chado.phenotype WHERE phenotype_id IN (SELECT phenotype_id FROM chado.stock_phenotype WHERE stock_id IN ($stocks_sql))");
750  chado_query("DELETE FROM chado.genotype_call WHERE project_id = $project_id");
751  chado_query("DELETE FROM chado.stock_genotype WHERE stock_id IN ($stocks_sql)");
752  chado_query("DELETE FROM chado.stock_phenotype WHERE stock_id IN ($stocks_sql)");
753  chado_query("DELETE FROM chado.stock WHERE stock_id IN ($stocks_sql)");
754  chado_query("DELETE FROM chado.phenotype WHERE uniquename LIKE '" . $accession ."-%';");
755  echo "FINISHED DB CLEAR DELETES\n";
756 
757  // Force delete stock just in case by study accession name
758  // Make sure to ensure $accession is properly populated before doing this
759  if(strpos($accession,'TGDR') !== FALSE && strlen($accession) >= 7) {
760  chado_query("DELETE FROM chado.stock WHERE uniquename LIKE :accession", [
761  ':accession' => $accession . '%'
762  ]);
763  }
764 
765  $state['ids'] = array('project_id' => $project_id);
766  tpps_update_submission($state);
767  return TRUE;
768 }
769 
776 function tpps_submission_update_all_stats(array &$form_state) {
777  for ($i = 1; $i <= 4; $i++) {
778  $form_state['values'] = $form_state['saved_values'][$i];
779  $form_state['stage'] = $i;
780  tpps_submission_update_stats($form_state);
781  }
782 }
783 
790 function tpps_submission_update_stats(array &$form_state) {
791  switch ($form_state['stage']) {
792  case TPPS_PAGE_1:
793  $form_state['stats']['author_count'] = $form_state['values']['publication']['secondaryAuthors']['number'] + 1;
794  if (!empty($form_state['values']['publication']['secondaryAuthors']['check'])) {
795  $form_state['stats']['author_count'] = tpps_file_len($form_state['values']['publication']['secondaryAuthors']['file']);
796  }
797 
798  $form_state['stats']['species_count'] = $form_state['values']['organism']['number'];
799  break;
800 
801  case TPPS_PAGE_2:
802  if (empty($form_state['tpps_type']) or $form_state['tpps_type'] == 'tpps') {
803  $start = new DateTime("{$form_state['values']['StartingDate']['year']}-{$form_state['values']['StartingDate']['month']}");
804  $end = new DateTime("{$form_state['values']['EndingDate']['year']}-{$form_state['values']['EndingDate']['month']}");
805  $dur = date_diff($start, $end);
806  $form_state['stats']['duration'] = $dur->format('%y years %m months');
807  }
808  break;
809 
810  case TPPS_PAGE_3:
811  $form_state['stats']['tree_count'] = 0;
812  for ($i = 1; $i <= $form_state['stats']['species_count']; $i++) {
813  $form_state['stats']['tree_count'] += tpps_file_len($form_state['values']['tree-accession']["species-$i"]['file']);
814  $form_state['stats']['tree_count'] += $form_state['values']['tree-accession']["species-$i"]['file-no-header'];
815  if ($form_state['stats']['species_count'] == 1 or empty($form_state['values']['tree-accession']['check'])) {
816  break;
817  }
818  }
819  break;
820 
821  case TPPS_PAGE_4:
822  $form_state['stats']['phenotype_count'] = 0;
823  $form_state['stats']['unique_phenotypes'] = 0;
824  for ($i = 1; $i <= $form_state['stats']['species_count']; $i++) {
825  $phenotype = $form_state['values']["organism-$i"]['phenotype'] ?? NULL;
826  $form_state['stats']['unique_phenotypes'] += $phenotype['phenotypes-meta']['number'] ?? 0;
827  if (!empty($phenotype['file']) and file_load($phenotype['file'])) {
828  $rows = tpps_file_len($phenotype['file']) + !empty($phenotype['file-no-header']);
829  if ($phenotype['format'] == 0) {
830  $phenotype_file_name_cols = $phenotype['file-groups']['Phenotype Data']['0'];
831  $form_state['stats']['phenotype_count'] += $rows * count($phenotype_file_name_cols);
832  }
833  else {
834  $form_state['stats']['phenotype_count'] += $rows;
835  }
836 
837  if (!empty($phenotype['metadata']) and file_load($phenotype['metadata'])) {
838  $form_state['stats']['unique_phenotypes'] += tpps_file_len($phenotype['metadata']) + !empty($phenotype['metadata-no-header']);
839  }
840 
841  continue;
842  }
843  if (!empty($phenotype['iso']) and file_load($phenotype['iso'])) {
844  $headers = tpps_file_headers($phenotype['iso']);
845  while (($k = array_search(NULL, $headers))) {
846  unset($headers[$k]);
847  }
848  $num_unique_columns = count(array_unique($headers)) - 1;
849  $rows = tpps_file_len($phenotype['iso']);
850  $form_state['stats']['phenotype_count'] += $rows * $num_unique_columns;
851  }
852  }
853  break;
854 
855  default:
856  break;
857  }
858 }
859 
873 function tpps_submission_edit_publication(array $form, array &$form_state, $accession = NULL) {
874  global $base_url;
875  $state = tpps_load_submission($accession);
876 
877  $form['accession'] = array(
878  '#type' => 'hidden',
879  '#value' => $accession,
880  );
881 
882  $form['status'] = array(
883  '#type' => 'select',
884  '#title' => t('Publication Status'),
885  '#options' => array(
886  0 => t('- Select -'),
887  'In Preparation or Submitted' => t('In Preparation or Submitted'),
888  'In Press' => t('In Press'),
889  'Published' => t('Published'),
890  ),
891  '#default_value' => $state['saved_values'][TPPS_PAGE_1]['publication']['status'],
892  '#required' => TRUE,
893  '#prefix' => "<a href=\"$base_url/tpps/details/$accession\">Back to TPPS Details Page</a>",
894  );
895 
896  $year_options = array(0 => '- Select -');
897  for ($i = 1990; $i <= date('Y'); $i++) {
898  $year_options[$i] = "$i";
899  }
900 
901  $form['year'] = array(
902  '#type' => 'select',
903  '#title' => t('Year of Publication'),
904  '#options' => $year_options,
905  '#description' => t('If your publication has not been published yet, please choose the expected year of publication.'),
906  '#default_value' => $state['saved_values'][TPPS_PAGE_1]['publication']['year'],
907  '#required' => TRUE,
908  );
909 
910  $form['journal'] = array(
911  '#type' => 'textfield',
912  '#title' => t('Journal'),
913  '#autocomplete_path' => 'tpps/autocomplete/journal',
914  '#default_value' => $state['saved_values'][TPPS_PAGE_1]['publication']['journal'],
915  '#required' => TRUE,
916  );
917 
918  $form['submit'] = array(
919  '#type' => 'submit',
920  '#value' => t('Submit'),
921  );
922 
923  return $form;
924 }
925 
929 function tpps_submission_edit_publication_validate(&$form, &$form_state) {
930  if (empty($form_state['values']['status'])) {
931  form_set_error('status', t('Publication Status: field is required.'));
932  }
933  if (empty($form_state['values']['year'])) {
934  form_set_error('year', t('Publication Year: field is required.'));
935  }
936 }
937 
941 function tpps_submission_edit_publication_submit($form, &$form_state) {
942  $accession = $form_state['values']['accession'];
943  $state = tpps_load_submission($accession);
944  $submit_job = FALSE;
945 
946  if ($state['saved_values'][TPPS_PAGE_1]['publication']['status'] != $form_state['values']['status']) {
947  $state['saved_values'][TPPS_PAGE_1]['publication']['status'] = $form_state['values']['status'];
948  $submit_job = TRUE;
949  }
950 
951  if ($state['saved_values'][TPPS_PAGE_1]['publication']['year'] != $form_state['values']['year']) {
952  $state['saved_values'][TPPS_PAGE_1]['publication']['year'] = $form_state['values']['year'];
953  $submit_job = TRUE;
954  }
955 
956  if ($state['saved_values'][TPPS_PAGE_1]['publication']['journal'] != $form_state['values']['journal']) {
957  $state['saved_values'][TPPS_PAGE_1]['publication']['journal'] = $form_state['values']['journal'];
958  $submit_job = TRUE;
959  }
960 
961  if ($submit_job) {
962  module_load_include('php', 'tpps', 'forms/submit/submit_all');
963 
964  $includes = array();
965  $includes[] = module_load_include('php', 'tpps', 'forms/submit/submit_all');
966  $includes[] = module_load_include('inc', 'tpps', 'includes/file_parsing');
967  $args = array($accession);
968  $jid = tripal_add_job("Update Publication Information - $accession", 'tpps', 'tpps_submit_all', $args, $state['submitting_uid'], 10, $includes, TRUE);
969  $state['job_id'] = $jid;
970  tpps_update_submission($state);
971  }
972 }
tpps_submission_get_tags($accession)
tpps_submission_add_alternative_accession(array $state, $alt_accession)
tpps_submission_clear_db($accession)
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_submission_edit_publication_validate(&$form, &$form_state)
tpps_submission_edit_publication(array $form, array &$form_state, $accession=NULL)
tpps_submission_tag_create_validate(&$form, &$form_state)
tpps_update_submission(array $state, array $options=array())
tpps_submission_tag_create_submit($form, &$form_state)
tpps_create_submission(array $state, $uid)
const TPPS_CSS_PATH
Definition: tpps.module:11
tpps_get_tag_id($name)
tpps_change_tgdr_number($old_accession, $new_accession, TripalJob $job=NULL)
const TPPS_JS_PATH
Definition: tpps.module:10
tpps_submission_edit_publication_submit($form, &$form_state)
tpps_submission_tag_edit_validate(&$form, &$form_state)
tpps_submission_remove_tag($accession, $tag)
tpps_submission_tag_create(array $form, array &$form_state)
tpps_submission_add_tag($accession, $tag)
tpps_get_path_extension($path)
Definition: file_utils.inc:661
tpps_file_len($fid)
Definition: file_utils.inc:65
tpps_submission_rename_files($accession)
tpps_file_headers($fid, $no_header=FALSE)
Definition: file_utils.inc:972
tpps_submission_clear_default_tags($accession)
tpps_delete_submission($accession, $redirect=TRUE)
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27
tpps_submission_tag_manage()
tpps_submission_update_all_stats(array &$form_state)
tpps_submission_update_stats(array &$form_state)
const TPPS_PAGE_4
Definition: tpps.module:15
tpps_submission_add_remove_tag($type, $accession, $tag)
tpps_load_submission_multiple(array $conditions=array(), $state=TRUE)
Definition: submissions.inc:85
tpps_submission_tag_edit(array $form, array &$form_state, $tag_id=NULL)
tpps_rename_file($fid, $new_name, array $options=array())
Definition: file_utils.inc:279
const TPPS_PAGE_3
Definition: tpps.module:14
const TPPS_PAGE_2
Definition: tpps.module:13
tpps_submission_tag_edit_submit($form, &$form_state)