Tripal Plant PopGen Submit
panel.php File Reference

Go to the source code of this file.

Functions

 tpps_admin_panel (array $form, array &$form_state, $accession=NULL)
 
 tpps_admin_panel_submit ($form, &$form_state)
 
 tpps_admin_panel_top (array &$form)
 
 tpps_admin_panel_validate ($form, &$form_state)
 
 tpps_manage_submission_form (array &$form, array &$form_state, $accession=NULL)
 
 tpps_phenotype_editor (array &$form, array &$form_state, array &$submission)
 
 tpps_save_admin_comments (array $form, array $form_state)
 

Detailed Description

Defines contents of TPPS administrative panel.

Site administrators will use this form to approve or reject completed TPPS submissions.

Definition in file panel.php.

Function Documentation

◆ tpps_admin_panel()

tpps_admin_panel ( array  $form,
array &  $form_state,
  $accession = NULL 
)

Creates the administrative panel form.

If the administrator is looking at one specific TPPS submission, they are provided with options to reject the submission and leave a reason for the rejection, or to approve the submission and start loading the data into the database. If the submission includes CartograPlant layers with environmental parameters, the administrator will need to select the kind of parameter the user has selected - an attr_id, or a cvterm. This will be important when the submission is recording the environmental data of the plants.

Parameters
array$formThe form being created.
array$form_stateThe state of the form being created.
Returns
array The administrative panel form.

Definition at line 30 of file panel.php.

30  {
31  if (empty($accession)) {
32  tpps_admin_panel_top($form);
33  }
34  else {
35  tpps_manage_submission_form($form, $form_state, $accession);
36  }
37 
38  drupal_add_js(drupal_get_path('module', 'tpps') . TPPS_JS_PATH);
39  drupal_add_css(drupal_get_path('module', 'tpps') . TPPS_CSS_PATH);
40 
41  return $form;
42 }
tpps_manage_submission_form(array &$form, array &$form_state, $accession=NULL)
Definition: panel.php:57
const TPPS_CSS_PATH
Definition: tpps.module:11
const TPPS_JS_PATH
Definition: tpps.module:10
tpps_admin_panel_top(array &$form)
Definition: panel.php:750

◆ tpps_admin_panel_submit()

tpps_admin_panel_submit (   $form,
$form_state 
)

Implements hook_form_submit().

Either rejects or approves the TPPS submission, and notifies the user of the status update via email. If the submission was approved, starts a tripal job for file parsing.

Definition at line 1149 of file panel.php.

1149  {
1150 
1151  global $base_url;
1152  $type = $form_state['tpps_type'] ?? 'tpps';
1153  $type_label = ($type == 'tpps') ? 'TPPS' : 'TPPSC';
1154 
1155  $accession = $form_state['values']['accession'];
1156  $submission = tpps_load_submission($accession, FALSE);
1157  $owner = user_load($submission->uid);
1158  $to = $owner->mail;
1159  $state = unserialize($submission->submission_state);
1160  $state['admin_comments'] = $form_state['values']['admin-comments'] ?? NULL;
1161  $params = array();
1162 
1163  $from = variable_get('site_mail', '');
1164  $params['subject'] = "$type_label Submission Rejected: {$state['saved_values'][TPPS_PAGE_1]['publication']['title']}";
1165  $params['uid'] = $owner->uid;
1166  $params['reject-reason'] = $form_state['values']['reject-reason'] ?? NULL;
1167  $params['base_url'] = $base_url;
1168  $params['title'] = $state['saved_values'][TPPS_PAGE_1]['publication']['title'];
1169  $params['body'] = '';
1170 
1171  $params['headers'][] = 'MIME-Version: 1.0';
1172  $params['headers'][] = 'Content-type: text/html; charset=iso-8859-1';
1173 
1174  if (isset($form_state['values']['params'])) {
1175  foreach ($form_state['values']['params'] as $param_id => $type) {
1176  variable_set("tpps_param_{$param_id}_type", $type);
1177  }
1178  }
1179 
1180  switch ($form_state['triggering_element']['#value']) {
1181  case 'Save VCF Import Setting':
1182  // dpm($form_state['values']);
1183  if($form_state['values']['DISABLE_VCF_IMPORT'] == 1) {
1184  $state['saved_values'][TPPS_PAGE_1]['disable_vcf_import'] = 1;
1185  }
1186  else {
1187  $state['saved_values'][TPPS_PAGE_1]['disable_vcf_import'] = 0;
1188  }
1189  tpps_update_submission($state);
1190  drupal_set_message(t('VCF disable import setting saved'), 'status');
1191  break;
1192 
1193  case "Remove this study's markers and genotypes":
1194  global $user;
1195  $includes = array();
1196  # $includes[] = module_load_include('php', 'tpps', 'forms/submit/submit_all');
1197  $includes[] = module_load_include('inc', 'tpps', 'includes/markers_genotypes_utils');
1198  $args = array($accession);
1199  $jid = tripal_add_job("TPPS REMOVE all study markers and genotypes - $accession", 'tpps', 'tpps_remove_all_markers_genotypes', $args, $user->uid, 10, $includes, TRUE);
1200  // drupal_set_message(t('Tripal Job created to remove all study markers and genotypes from ' . $accession), 'status');
1201  break;
1202 
1203  case "Change TGDR number":
1204  // dpm($form_state['values']);
1205 
1206  // Check if a valid tgdr number was supplied
1207  if(!is_numeric($form_state['values']['CHANGE_TGDR_NUMBER'])) {
1208  drupal_set_message(t('You did not enter a valid number. Operation aborted.'));
1209  break;
1210  }
1211 
1212  $new_accession = 'TGDR' . $form_state['values']['CHANGE_TGDR_NUMBER'];
1213  // Check if the new tgdr number does not exist in the database
1214  // if it exists, abort the mission
1215  $results = chado_query('SELECT count(*) as c1 FROM public.tpps_submission WHERE accession = :new_accession', array(
1216  ':new_accession' => $new_accession
1217  ));
1218  $result_object = $results->fetchObject();
1219  // dpm($result_object);
1220  $result_count = $result_object->c1;
1221  if($result_count > 0) {
1222  drupal_set_message(t('It seems the TGDR number you wanted to change to is already in use. Operation aborted due to safety concerns.'));
1223  break;
1224  }
1225 
1226  // dpm($state); // this doesn't even load on the browser (too big!)
1227 
1228  global $user;
1229  $includes = array();
1230  # $includes[] = module_load_include('php', 'tpps', 'forms/submit/submit_all');
1231  $includes[] = module_load_include('inc', 'tpps', 'includes/markers_genotypes_utils');
1232  $includes[] = module_load_include('inc', 'tpps', 'includes/submissions');
1233  $args = [$accession];
1234  // Job to remove genotype information and features
1235  $jid = tripal_add_job("TPPS REMOVE all study markers and genotypes - $accession", 'tpps', 'tpps_remove_all_markers_genotypes', $args, $user->uid, 10, $includes, TRUE);
1236 
1237  // Job to change the TGDR number to the new TGDR number
1238  $args = [$accession, $new_accession];
1239  $jid = tripal_add_job("TPPS rename $accession to $new_accession", 'tpps', 'tpps_change_tgdr_number', $args, $user->uid, 10, $includes, TRUE);
1240 
1241 
1242  // Now run the new import for the new accession TGDR number
1243  $includes[] = module_load_include('php', 'tpps', 'forms/submit/submit_all');
1244  $includes[] = module_load_include('inc', 'tpps', 'includes/file_parsing');
1245  $args = array($new_accession);
1246  $jid = tripal_add_job("TPPS Record Submission - $new_accession", 'tpps', 'tpps_submit_all', $args, $state['submitting_uid'], 10, $includes, TRUE);
1247  $state['job_id'] = $jid;
1248  tpps_update_submission($state);
1249  break;
1250 
1251  case "Generate PopStruct FROM VCF":
1252  global $user;
1253  $includes = array();
1254  $includes[] = module_load_include('php', 'tpps', 'forms/submit/submit_all');
1255 
1256  // dpm($state['saved_values'][4]['organism-1']['genotype']['files']['vcf']);
1257  if(!empty($state['saved_values'][4]['organism-1']['genotype']['files']['vcf'])) {
1258  $vcf_fid = $state['saved_values'][4]['organism-1']['genotype']['files']['vcf'];
1259  $vcf_file = file_load($vcf_fid);
1260  $location = tpps_get_location($vcf_file->uri);
1261  $args = array($accession,$location);
1262  // dpm($args);
1263  $jid = tripal_add_job("TPPS Generate PopStruct FROM VCF - $accession", 'tpps', 'tpps_generate_popstruct', $args, $user->uid, 10, $includes, TRUE);
1264  }
1265  else {
1266  drupal_set_message("Could not find a VCF tied to organism-1, are you sure you linked a VCF file?");
1267  }
1268  break;
1269 
1270  case "Refresh TPPS cvterms cache":
1271  global $user;
1272  $includes = array();
1273  $includes[] = module_load_include('php', 'tpps', 'forms/submit/submit_all');
1274  $includes[] = module_load_include('inc', 'tpps', 'includes/cvterm_utils');
1275  $args = array();
1276  $jid = tripal_add_job("TPPS REFRESH CVTERMS CACHE", 'tpps', 'tpps_cvterms_clear_cache', $args, $user->uid, 10, $includes, TRUE);
1277  // drupal_set_message(t('Tripal Job created to remove all study markers and genotypes from ' . $accession), 'status');
1278  break;
1279 
1280  case 'Change TPPS Type':
1281  // dpm($form_state['values']);
1282  if($form_state['values']['CHANGE_TPPS_TYPE'] == 'tppsc') {
1283  // $state['saved_values'][TPPS_PAGE_1]['disable_vcf_import'] = 1;
1284  // Set the state tpps_type to tppsc
1285  $state['tpps_type'] = 'tppsc';
1286  global $user;
1287  tpps_update_submission($state, array(
1288  'uid' => $user->uid,
1289  ));
1290  }
1291  else {
1292  // $state['saved_values'][TPPS_PAGE_1]['disable_vcf_import'] = 0;
1293  $state['tpps_type'] = 'tpps';
1294  }
1295  tpps_update_submission($state);
1296  drupal_set_message(t('Updated study TPPS type: ') . $state['tpps_type'], 'status');
1297  break;
1298 
1299  case 'Reject':
1300  drupal_mail($type, 'user_rejected', $to, user_preferred_language($owner), $params, $from, TRUE);
1301  $state['status'] = 'Incomplete';
1302  tpps_update_submission($state);
1303  drupal_set_message(t('Submission Rejected. Message has been sent to user.'), 'status');
1304  drupal_goto('<front>');
1305  break;
1306 
1307  case 'Approve':
1308  module_load_include('php', 'tpps', 'forms/submit/submit_all');
1309  global $user;
1310  $uid = $user->uid;
1311  $state['submitting_uid'] = $uid;
1312 
1313  $params['subject'] = "$type_label Submission Approved: {$state['saved_values'][TPPS_PAGE_1]['publication']['title']}";
1314  $params['accession'] = $state['accession'];
1315  drupal_set_message(t('Submission Approved! Message has been sent to user.'), 'status');
1316  drupal_mail($type, 'user_approved', $to, user_preferred_language(user_load_by_name($to)), $params, $from, TRUE);
1317 
1318  $state['revised_files'] = $state['revised_files'] ?? array();
1319  foreach ($state['file_info'] as $files) {
1320  foreach ($files as $fid => $file_type) {
1321  if (!empty($form_state['values']["edit_file_{$fid}_check"])) {
1322  $state['revised_files'][$fid] = $form_state['values']["edit_file_{$fid}_file"];
1323  }
1324  }
1325  }
1326 
1327  if (!empty($form_state['values']['phenotypes_edit'])) {
1328  $state['phenotypes_edit'] = $form_state['values']['phenotypes_edit'];
1329  }
1330 
1331  if (!empty($form_state['values']['study_location'])) {
1332  $state['saved_values'][TPPS_PAGE_3]['study_location']['type'] = $form_state['values']['study_location']['type'];
1333  for ($i = 1; $i <= $form_state['values']['study_location']['locations']['number']; $i++) {
1334  $state['saved_values'][TPPS_PAGE_3]['study_location']['locations'][$i] = $form_state['values']['study_location']['locations'][$i];
1335  }
1336  }
1337 
1338  $includes = array();
1339  $includes[] = module_load_include('php', 'tpps', 'forms/submit/submit_all');
1340  $includes[] = module_load_include('inc', 'tpps', 'includes/file_parsing');
1341  $args = array($accession);
1342  if ($state['saved_values']['summarypage']['release']) {
1343  $jid = tripal_add_job("$type_label Record Submission - $accession", 'tpps', 'tpps_submit_all', $args, $state['submitting_uid'], 10, $includes, TRUE);
1344  $state['job_id'] = $jid;
1345  }
1346  else {
1347  $date = $state['saved_values']['summarypage']['release-date'];
1348  $time = strtotime("{$date['year']}-{$date['month']}-{$date['day']}");
1349  if (time() > $time) {
1350  $jid = tripal_add_job("$type_label Record Submission - $accession", 'tpps', 'tpps_submit_all', $args, $state['submitting_uid'], 10, $includes, TRUE);
1351  $state['job_id'] = $jid;
1352  }
1353  else {
1354  $delayed_submissions = variable_get('tpps_delayed_submissions', array());
1355  $delayed_submissions[$accession] = $accession;
1356  variable_set('tpps_delayed_submissions', $delayed_submissions);
1357  $state['status'] = 'Approved - Delayed Submission Release';
1358  }
1359  }
1360  tpps_update_submission($state);
1361  break;
1362 
1363  case 'Change Date':
1364  $state['saved_values']['summarypage']['release-date'] = $form_state['values']['date'];
1365  tpps_update_submission($state);
1366  break;
1367 
1368  case 'Change Status':
1369  $state['status'] = $form_state['values']['state-status'];
1370  tpps_update_submission($state);
1371  dpm($state['status']);
1372  break;
1373 
1374  case 'Save Alternative Accessions':
1375  $old_alt_acc = $state['alternative_accessions'] ?? '';
1376  $new_alt_acc = $form_state['values']['alternative_accessions'];
1377  if ($old_alt_acc != $new_alt_acc) {
1378  tpps_submission_add_alternative_accession($state, explode(',', $new_alt_acc));
1379 
1380  $state['alternative_accessions'] = $new_alt_acc;
1381  tpps_update_submission($state);
1382  }
1383  break;
1384 
1385  case 'Change Submission Owner':
1386  $new_user = user_load_by_mail($form_state['values']['change_owner']);
1387  $state['submitting_uid'] = $new_user->uid;
1388  tpps_update_submission($state, array(
1389  'uid' => $new_user->uid,
1390  ));
1391  break;
1392 
1393  default:
1394  break;
1395  }
1396 }
tpps_submission_add_alternative_accession(array $state, $alt_accession)
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_update_submission(array $state, array $options=array())
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27
tpps_get_location($location)
Definition: file_utils.inc:640
const TPPS_PAGE_3
Definition: tpps.module:14

◆ tpps_admin_panel_top()

tpps_admin_panel_top ( array &  $form)

Create tables for pending, approved, and incomplete TPPS Submissions.

Parameters
array$formThe form element of the TPPS admin panel page.

Definition at line 750 of file panel.php.

750  {
751  global $base_url;
752 
753  $submissions = tpps_load_submission_multiple(array(), FALSE);
754 
755  $pending = array();
756  $approved = array();
757  $incomplete = array();
758  $unpublished_old = array();
759 
760  $submitting_user_cache = array();
761  $mail_cvterm = tpps_load_cvterm('email')->cvterm_id;
762 
763  foreach ($submissions as $submission) {
764  $state = unserialize($submission->submission_state);
765  $status = $submission->status;
766  if (empty($state['status'])) {
767  $state['status'] = $status;
768  tpps_update_submission($state);
769  }
770 
771  if (empty($submitting_user_cache[$submission->uid])) {
772  $mail = user_load($submission->uid)->mail;
773  $query = db_select('chado.contact', 'c');
774  $query->join('chado.contactprop', 'cp', 'cp.contact_id = c.contact_id');
775  $query->condition('cp.value', $mail);
776  $query->condition('cp.type_id', $mail_cvterm);
777  $query->fields('c', array('name'));
778  $query->range(0, 1);
779  $query = $query->execute();
780  $name = $query->fetchObject()->name ?? NULL;
781 
782  $submitting_user_cache[$submission->uid] = $name ?? $mail;
783  }
784  $submitting_user = $submitting_user_cache[$submission->uid] ?? NULL;
785 
786  if (!empty($state)) {
787  switch ($state['status']) {
788  case 'Pending Approval':
789  $row = array(
790  l($state['accession'], "$base_url/tpps-admin-panel/{$state['accession']}"),
791  $submitting_user,
792  $state['saved_values'][TPPS_PAGE_1]['publication']['title'],
793  !empty($state['completed']) ? date("F j, Y, g:i a", $state['completed']) : "Unknown",
794  tpps_show_tags(tpps_submission_get_tags($state['accession'])),
795  );
796  $pending[(int) substr($state['accession'], 4)] = $row;
797  break;
798 
799  case 'Approved':
800  $status_label = !empty($state['loaded']) ? "Approved - load completed on " . date("F j, Y, \a\\t g:i a", $state['loaded']) : "Approved";
801  if (!empty($state['loaded'])) {
802  $days_since_load = (time() - $state['loaded']) / (60 * 60 * 24);
803  $unpublished_threshold = variable_get('tpps_unpublished_days_threshold', 180);
804  $pub_status = $state['saved_values'][TPPS_PAGE_1]['publication']['status'] ?? NULL;
805  if (!empty($pub_status) and $pub_status != 'Published' and $days_since_load >= $unpublished_threshold) {
806  $owner = $submitting_user;
807  $contact_bundle = tripal_load_bundle_entity(array('label' => 'Tripal Contact Profile'));
808 
809  // If Tripal Contact Profile is available, we want to link to the
810  // profile of the owner instead of just displaying the name.
811  if ($contact_bundle) {
812  $owner_mail = user_load($submission->uid)->mail;
813  $query = new EntityFieldQuery();
814  $results = $query->entityCondition('entity_type', 'TripalEntity')
815  ->entityCondition('bundle', $contact_bundle->name)
816  ->fieldCondition('local__email', 'value', $owner_mail)
817  ->range(0, 1)
818  ->execute();
819  $entity = current(array_reverse(entity_load('TripalEntity', array_keys($results['TripalEntity']))));
820  $owner = "<a href=\"$base_url/TripalContactProfile/{$entity->id}\">$submitting_user</a>";
821  }
822  else {
823  $owner_mail = user_load($submission->uid)->mail;
824  if ($owner_mail != $owner) {
825  $owner = "$submitting_user ($owner_mail)";
826  }
827  }
828  $row = array(
829  l($state['accession'], "$base_url/tpps-admin-panel/{$state['accession']}"),
830  date("F j, Y", $state['loaded']) . " (" . round($days_since_load) . " days ago)",
831  $pub_status,
832  $owner,
833  );
834  if (tpps_access('view own tpps submission', $state['accession'])) {
835  $row[] = l(t('Edit publication information'), "tpps/{$state['accession']}/edit-publication");
836  }
837  $unpublished_old[(int) substr($state['accession'], 4)] = $row;
838  }
839  }
840  case 'Submission Job Running':
841  $status_label = $status_label ?? (!empty($state['approved']) ? ("Submission Job Running - job started on " . date("F j, Y, \a\t g:i a", $state['approved'])) : "Submission Job Running");
842  case 'Approved - Delayed Submission Release':
843  if (empty($status_label)) {
844  $release = $state['saved_values']['summarypage']['release-date'] ?? NULL;
845  $release = strtotime("{$release['day']}-{$release['month']}-{$release['year']}");
846  $status_label = "Approved - Delayed Submission Release on " . date("F j, Y", $release);
847  }
848  $row = array(
849  l($state['accession'], "$base_url/tpps-admin-panel/{$state['accession']}"),
850  $submitting_user,
851  $state['saved_values'][TPPS_PAGE_1]['publication']['title'],
852  $status_label,
853  tpps_show_tags(tpps_submission_get_tags($state['accession'])),
854  );
855  $approved[(int) substr($state['accession'], 4)] = $row;
856  break;
857 
858  default:
859  switch ($state['stage']) {
860  case TPPS_PAGE_1:
861  $stage = "Author and Species Information";
862  break;
863 
864  case TPPS_PAGE_2:
865  $stage = "Experimental Conditions";
866  break;
867 
868  case TPPS_PAGE_3:
869  $stage = "Plant Accession";
870  break;
871 
872  case TPPS_PAGE_4:
873  $stage = "Submit Data";
874  break;
875 
876  case 'summarypage':
877  $stage = "Review Data and Submit";
878  break;
879 
880  default:
881  $stage = "Unknown";
882  break;
883  }
884 
885  $row = array(
886  l($state['accession'], "$base_url/tpps-admin-panel/{$state['accession']}"),
887  $submitting_user,
888  $state['saved_values'][TPPS_PAGE_1]['publication']['title'] ?? 'Title not provided yet',
889  $stage,
890  !empty($state['updated']) ? date("F j, Y, g:i a", $state['updated']) : "Unknown",
891  tpps_show_tags(tpps_submission_get_tags($state['accession'])),
892  );
893  $incomplete[(int) substr($state['accession'], 4)] = $row;
894  break;
895  }
896  }
897  }
898 
899  krsort($pending);
900  krsort($approved);
901  krsort($incomplete);
902 
903  $vars = array(
904  'attributes' => array(
905  'class' => array('view', 'tpps_table'),
906  ),
907  'caption' => '',
908  'colgroups' => NULL,
909  'sticky' => FALSE,
910  'empty' => '',
911  );
912 
913  $vars['header'] = array(
914  'Accession Number',
915  'Approval date',
916  'Publication Status',
917  'Submission Owner',
918  );
919  $vars['rows'] = $unpublished_old;
920  $unpublished_table = theme('table', $vars);
921 
922  $vars['header'] = array(
923  'Accession Number',
924  'Submitting User',
925  'Title',
926  'Date Submitted',
927  'Tags',
928  );
929  $vars['rows'] = $pending;
930  $pending_table = theme('table', $vars);
931 
932  $vars['header'] = array(
933  'Accession Number',
934  'Submitting User',
935  'Title',
936  'Status',
937  'Tags',
938  );
939  $vars['rows'] = $approved;
940  $approved_table = theme('table', $vars);
941 
942  $vars['header'] = array(
943  'Accession Number',
944  'Submitting User',
945  'Title',
946  'Stage',
947  'Last Updated',
948  'Tags',
949  );
950  $vars['rows'] = $incomplete;
951  $incomplete_table = theme('table', $vars);
952 
953  if (!empty($unpublished_old)) {
954  $form['unpublished_old'] = array(
955  '#type' => 'fieldset',
956  '#title' => t('Unpublished Approved TPPS Submissions'),
957  '#collapsible' => TRUE,
958  'table' => array(
959  '#markup' => $unpublished_table,
960  ),
961  );
962  }
963 
964  if (!empty($pending)) {
965  $form['pending'] = array(
966  '#type' => 'fieldset',
967  '#title' => t('Pending TPPS submissions'),
968  '#collapsible' => TRUE,
969  'table' => array(
970  '#markup' => $pending_table,
971  ),
972  );
973  }
974 
975  if (!empty($approved)) {
976  $form['approved'] = array(
977  '#type' => 'fieldset',
978  '#title' => t('Approved TPPS submissions'),
979  '#collapsible' => TRUE,
980  'table' => array(
981  '#markup' => $approved_table,
982  ),
983  );
984  }
985 
986  if (!empty($incomplete)) {
987  $form['incomplete'] = array(
988  '#type' => 'fieldset',
989  '#title' => t('Incomplete TPPS submissions'),
990  '#collapsible' => TRUE,
991  'table' => array(
992  '#markup' => $incomplete_table,
993  ),
994  );
995  }
996 
997  $subquery = db_select('tpps_submission', 's');
998  $subquery->fields('s', array('accession'));
999  $query = db_select('chado.dbxref', 'dbx');
1000  $query->join('chado.project_dbxref', 'pd', 'pd.dbxref_id = dbx.dbxref_id');
1001  $query->condition('dbx.accession', $subquery, 'NOT IN');
1002  $query->condition('dbx.accession', 'TGDR%', 'ILIKE');
1003  $query->fields('dbx', array('accession'));
1004  $query->orderBy('dbx.accession');
1005  $query = $query->execute();
1006  $to_resubmit = array();
1007  while (($result = $query->fetchObject())) {
1008  $to_resubmit[] = array($result->accession);
1009  }
1010  if (!empty($to_resubmit)) {
1011  $vars['header'] = array(
1012  'Accession',
1013  );
1014  $vars['rows'] = $to_resubmit;
1015  $to_resubmit_table = theme('table', $vars);
1016  $form['resubmit'] = array(
1017  '#type' => 'fieldset',
1018  '#title' => "<img src='$base_url/misc/message-16-warning.png'> " . t('Old TGDR Submissions to be resubmitted'),
1019  '#collapsible' => TRUE,
1020  'table' => array(
1021  '#markup' => $to_resubmit_table,
1022  ),
1023  );
1024  }
1025 
1026  $tpps_new_orgs = variable_get('tpps_new_organisms', NULL);
1027  $db = chado_get_db(array('name' => 'NCBI Taxonomy'));
1028  if (!empty($db)) {
1029  $rows = array();
1030  $query = db_select('chado.organism', 'o');
1031  $query->fields('o', array('organism_id', 'genus', 'species'));
1032 
1033  $query_e = db_select('chado.organism_dbxref', 'odb');
1034  $query_e->join('chado.dbxref', 'd', 'd.dbxref_id = odb.dbxref_id');
1035  $query_e->condition('d.db_id', $db->db_id)
1036  ->where('odb.organism_id = o.organism_id');
1037  $query->notExists($query_e);
1038  $query = $query->execute();
1039 
1040  $org_bundle = tripal_load_bundle_entity(array('label' => 'Organism'));
1041  while (($org = $query->fetchObject())) {
1042  $id = chado_get_record_entity_by_bundle($org_bundle, $org->organism_id);
1043  if (!empty($id)) {
1044  $rows[] = array(
1045  "<a href=\"$base_url/bio_data/{$id}/edit\" target=\"_blank\">$org->genus $org->species</a>",
1046  );
1047  continue;
1048  }
1049  $rows[] = array(
1050  "$org->genus $org->species",
1051  );
1052  }
1053 
1054  if (!empty($rows)) {
1055  $headers = array();
1056 
1057  $vars = array(
1058  'header' => $headers,
1059  'rows' => $rows,
1060  'attributes' => array(
1061  'class' => array('view', 'tpps_table'),
1062  'id' => 'new_species',
1063  ),
1064  'caption' => '',
1065  'colgroups' => NULL,
1066  'sticky' => FALSE,
1067  'empty' => '',
1068  );
1069 
1070  $form['new_species']['#markup'] = "<div class='tpps_table'><label for='new_species'>New Species: the species listed below likely need to be updated, because they do not have NCBI Taxonomy identifiers in the database.</label>" . theme('table', $vars) . "</div>";
1071  }
1072  variable_set('tpps_new_organisms', $tpps_new_orgs);
1073  }
1074 }
tpps_submission_get_tags($accession)
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_update_submission(array $state, array $options=array())
tpps_show_tags(array $tags)
Definition: display.inc:976
tpps_access()
Definition: tpps.module:341
const TPPS_PAGE_4
Definition: tpps.module:15
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)
tpps_load_submission_multiple(array $conditions=array(), $state=TRUE)
Definition: submissions.inc:85
const TPPS_PAGE_3
Definition: tpps.module:14
const TPPS_PAGE_2
Definition: tpps.module:13

◆ tpps_admin_panel_validate()

tpps_admin_panel_validate (   $form,
$form_state 
)

Implements hook_form_validate().

Checks that the reject reason has been filled out if the submission was rejected.

Definition at line 1082 of file panel.php.

1082  {
1083  if ($form_state['submitted'] == '1') {
1084  if (isset($form_state['values']['reject-reason']) and $form_state['values']['reject-reason'] == '' and $form_state['triggering_element']['#value'] == 'Reject') {
1085  form_set_error('reject-reason', t('Please explain why the submission was rejected.'));
1086  }
1087 
1088  if ($form_state['triggering_element']['#value'] == 'Approve') {
1089  $accession = $form_state['values']['accession'];
1090  $state = tpps_load_submission($accession);
1091  foreach ($state['file_info'] as $files) {
1092  foreach ($files as $fid => $file_type) {
1093  if (!empty($form_state['values']["edit_file_{$fid}_check"]) and empty($form_state['values']["edit_file_{$fid}_file"])) {
1094  form_set_error("edit_file_{$fid}_file", t('Please upload a revised version fo the user-provided file.'));
1095  }
1096  if (!empty($form_state['values']["edit_file_{$fid}_file"])) {
1097  $file = file_load($form_state['values']["edit_file_{$fid}_file"]);
1098  file_usage_add($file, 'tpps', 'tpps_project', substr($accession, 4));
1099  }
1100  }
1101  }
1102 
1103  if (!empty($form_state['values']['study_location'])) {
1104  for ($i = 1; $i <= $form_state['values']['study_location']['locations']['number']; $i++) {
1105  if (empty($form_state['values']['study_location']['locations'][$i])) {
1106  form_set_error("study_location][locations][$i", "Study location $i: field is required.");
1107  }
1108  }
1109  }
1110  }
1111 
1112  if ($form_state['triggering_element']['#value'] == 'Save Alternative Accessions') {
1113  $alt_acc = explode(',', $form_state['values']['alternative_accessions']);
1114  foreach ($alt_acc as $acc) {
1115  if (!preg_match('/^TGDR\d{3,}$/', $acc)) {
1116  form_set_error('alternative_accessions', "The accession, $acc is not a valid TGDR### accession number.");
1117  continue;
1118  }
1119  $result = db_select('tpps_submission', 's')
1120  ->fields('s')
1121  ->condition('accession', $acc)
1122  ->range(0, 1)
1123  ->execute()->fetchObject();
1124  if (!empty($result)) {
1125  form_set_error('alternative_accessions', "The accession, $acc is already in use.");
1126  }
1127  }
1128  }
1129 
1130  if ($form_state['triggering_element']['#value'] == 'Change Submission Owner') {
1131  $new_user = user_load_by_mail($form_state['values']['change_owner']);
1132  if (empty($new_user)) {
1133  form_set_error('change_owner', t('Invalid user account'));
1134  }
1135  }
1136 
1137  drupal_add_js(drupal_get_path('module', 'tpps') . TPPS_JS_PATH);
1138  drupal_add_css(drupal_get_path('module', 'tpps') . TPPS_CSS_PATH);
1139  }
1140 }
const TPPS_CSS_PATH
Definition: tpps.module:11
const TPPS_JS_PATH
Definition: tpps.module:10
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27

◆ tpps_manage_submission_form()

tpps_manage_submission_form ( array &  $form,
array &  $form_state,
  $accession = NULL 
)

Build form to manage TPPS submissions from admin panel.

This includes options to change the status or release date of the submission, as well as options to upload revised versions of files.

Parameters
array$formThe form element to be populated.
array$form_stateThe state of the form element to be populated.
string$accessionThe accession number of the submission being managed.

Definition at line 57 of file panel.php.

57  {
58  global $base_url;
59  $submission = tpps_load_submission($accession, FALSE);
60  $status = $submission->status;
61  $submission_state = unserialize($submission->submission_state);
62  if (empty($submission_state['status'])) {
63  $submission_state['status'] = $status;
64  tpps_update_submission($submission_state);
65  }
66  $options = array();
67  $display = l(t("Back to TPPS Admin Panel"), "$base_url/tpps-admin-panel");
68 
69  // Check for log file
70  // Step 1 - Look for the last tripal job that has the accession
71  $results = db_query("SELECT * FROM public.tripal_jobs WHERE job_name LIKE 'TPPS Record Submission - $accession' ORDER BY submit_date DESC LIMIT 1;");
72  $job_id = -1;
73  while($row_array = $results->fetchObject()) {
74  // dpm($row_array);
75  // $display .= print_r($row_array, true);
76  $job_id = $row_array->job_id;
77  }
78  if($job_id == -1) {
79  $display .= "<div style='padding: 10px;'>No log file exists for this study (resubmit this study to generate a log file if necessary)</div>";
80  }
81  else {
82  $log_path = drupal_realpath('public://') . '/tpps_job_logs/';
83  // dpm($log_path . $accession . "_" . $job_id . ".txt");
84  if(file_exists($log_path . $accession . "_" . $job_id . ".txt")) {
85  $display .= "<div style='padding: 10px;background: #e9f9ef;border: 1px solid #90bea9;font-size: 18px;'><a target='_blank' href='../tpps-admin-panel-logs/" . $accession . "_" . $job_id . "'>Latest job log file ($accession - $job_id)</a></div>";
86  }
87  else {
88  $display .= "<div style='padding: 10px;'>Could not find job log file (this can happen if the log file was deleted - resubmit study if necessary to regenerate log file)</div>";
89  }
90  }
91 
92  if ($status == "Pending Approval") {
93  $options['files'] = array(
94  'revision_destination' => TRUE,
95  );
96  $options['skip_phenotypes'] = TRUE;
97 
98  foreach ($submission_state['file_info'] as $files) {
99  foreach ($files as $fid => $file_type) {
100  $file = file_load($fid) ?? NULL;
101 
102  $form["edit_file_{$fid}_check"] = array(
103  '#type' => 'checkbox',
104  '#title' => t('I would like to upload a revised version of this file'),
105  '#prefix' => "<div id=\"file_{$fid}_options\">",
106  );
107 
108  $form["edit_file_{$fid}_file"] = array(
109  '#type' => 'managed_file',
110  '#title' => 'Upload new file',
111  '#upload_location' => dirname($file->uri),
112  '#upload_validators' => array(
113  'file_validate_extensions' => array(),
114  ),
115  '#states' => array(
116  'visible' => array(
117  ":input[name=\"edit_file_{$fid}_check\"]" => array('checked' => TRUE),
118  ),
119  ),
120  );
121  $form["edit_file_{$fid}_markup"] = array(
122  '#markup' => '</div>',
123  );
124  }
125  }
126  }
127  $display .= tpps_table_display($submission_state, $options);
128 
129  if ($status == 'Pending Approval' and preg_match('/P/', $submission_state['saved_values'][TPPS_PAGE_2]['data_type'])) {
130  $new_cvterms = array();
131  for ($i = 1; $i <= $submission_state['saved_values'][TPPS_PAGE_1]['organism']['number']; $i++) {
132  $phenotype = $submission_state['saved_values'][TPPS_PAGE_4]["organism-$i"]['phenotype'];
133  for ($j = 1; $j <= $phenotype['phenotypes-meta']['number']; $j++) {
134  if ($phenotype['phenotypes-meta'][$j]['structure'] === 'other') {
135  $new_cvterms[] = $phenotype['phenotypes-meta'][$j]['struct-other'];
136  }
137  if ($phenotype['phenotypes-meta'][$j]['attribute'] === 'other') {
138  $new_cvterms[] = $phenotype['phenotypes-meta'][$j]['attr-other'];
139  }
140  if ($phenotype['phenotypes-meta'][$j]['units'] === 'other') {
141  $new_cvterms[] = $phenotype['phenotypes-meta'][$j]['unit-other'];
142  }
143  }
144  }
145  // @todo get new/custom cvterms from metadata file.
146  if (count($new_cvterms) > 0) {
147  $message = 'This submission will create the following new local cvterms: ' . implode(', ', $new_cvterms);
148  $display .= "<div class=\"alert alert-block alert-dismissible alert-warning messages warning\">
149  <a class=\"close\" data-dismiss=\"alert\" href=\"#\">×</a>
150  <h4 class=\"element-invisible\">Warning message</h4>
151  {$message}</div>";
152  }
153  }
154 
155  $form['accession'] = array(
156  '#type' => 'hidden',
157  '#value' => $accession,
158  );
159 
160  $form['form_table'] = array(
161  '#markup' => $display,
162  );
163 
164  $form['file_diagnostics'] = array(
165  '#markup' => '<a class="btn btn-primary" target="_blank" href="file-diagnostics/' . $accession . '">Files diagnostics</a><br /><br />',
166  );
167 
168  $form['state_compare'] = array(
169  '#markup' => '<a class="btn btn-primary" target="_blank" href="state-compare/' . $accession . '/' . $accession . '">Submission state compare</a><br /><br />',
170  );
171  // https://treegenesdb.org/tpps-admin-panel/state-compare/
172 
173  $submission_tags = tpps_submission_get_tags($submission_state['accession']);
174 
175  // Show current tags.
176  $tags_markup = "<label class=\"control-label\">Current Tags:</label><br>";
177  $image_path = drupal_get_path('module', 'tpps') . '/images/';
178  $query = db_select('tpps_tag', 't')
179  ->fields('t')
180  ->execute();
181  while (($result = $query->fetchObject())) {
182  $color = !empty($result->color) ? $result->color : 'white';
183  $style = !array_key_exists($result->tpps_tag_id, $submission_tags) ? "display: none" : "";
184  $tooltip = $result->static ? "This tag cannot be removed" : "";
185  $tags_markup .= "<span title=\"$tooltip\" class=\"tag\" style=\"background-color:$color; $style\"><span class=\"tag-text\">{$result->name}</span>";
186  if (!$result->static) {
187  $tags_markup .= "<span id=\"{$submission_state['accession']}-tag-{$result->tpps_tag_id}-remove\" class=\"tag-close\"><img src=\"/{$image_path}remove.png\"></span>";
188  }
189  $tags_markup .= "</span>";
190  }
191 
192  // Show available tags.
193  $tags_markup .= "<br><label class=\"control-label\">Available Tags (click to add):</label><br><div id=\"available-tags\">";
194  $query = db_select('tpps_tag', 't')
195  ->fields('t')
196  ->condition('static', 0)
197  ->execute();
198  while (($result = $query->fetchObject())) {
199  $color = $result->color;
200  if (empty($color)) {
201  $color = 'white';
202  }
203  $style = "";
204  if (array_key_exists($result->tpps_tag_id, $submission_tags)) {
205  $style = 'display: none';
206  }
207  $tags_markup .= "<span id=\"{$submission_state['accession']}-tag-{$result->tpps_tag_id}-add\" class=\"tag add-tag\" style=\"background-color:{$color}; $style\"><span class=\"tag-text\">{$result->name}</span></span>";
208  }
209  $tags_markup .= "</div>";
210  $tags_markup .= "<a href=\"/tpps-tag\">Manage TPPS Submission Tags</a>";
211  $form['tags'] = array(
212  '#markup' => "<div id=\"tags\">$tags_markup</div>",
213  );
214 
215  if ($status == "Pending Approval") {
216 
217  if ($submission_state['saved_values'][TPPS_PAGE_2]['study_type'] != 1) {
218  module_load_include('php', 'tpps', 'forms/build/page_3_helper');
219  module_load_include('php', 'tpps', 'forms/build/page_3_ajax');
220  $submission_state['values'] = $form_state['values'] ?? $submission_state['values'];
221  $submission_state['complete form'] = $form_state['complete form'] ?? $submission_state['complete form'];
222  tpps_study_location($form, $submission_state);
223  $study_location = $submission_state['saved_values'][TPPS_PAGE_3]['study_location'];
224  $form['study_location']['type']['#default_value'] = $study_location['type'] ?? NULL;
225  for ($i = 1; $i <= $study_location['locations']['number']; $i++) {
226  $form['study_location']['locations'][$i]['#default_value'] = $study_location['locations'][$i];
227  }
228  unset($form['study_location']['locations']['add']);
229  unset($form['study_location']['locations']['remove']);
230 
231  $form['study_location']['#collapsed'] = TRUE;
232  }
233 
234  $form['params'] = array(
235  '#type' => 'fieldset',
236  '#title' => 'Select Environmental parameter types:',
237  '#tree' => TRUE,
238  '#description' => '',
239  );
240 
241  $orgamism_num = $submission_state['saved_values'][TPPS_PAGE_1]['organism']['number'];
242  $show_layers = FALSE;
243  for ($i = 1; $i <= $orgamism_num; $i++) {
244  if (!empty($submission_state['saved_values'][TPPS_PAGE_4]["organism-$i"]['environment'])) {
245  foreach ($submission_state['saved_values'][TPPS_PAGE_4]["organism-$i"]['environment']['env_layers'] as $layer => $layer_id) {
246  if (!empty($layer_id)) {
247  foreach ($submission_state['saved_values'][TPPS_PAGE_4]["organism-$i"]['environment']['env_params'][$layer] as $param_id) {
248  if (!empty($param_id)) {
249  $type = variable_get("tpps_param_{$param_id}_type", NULL);
250  if (empty($type)) {
251  $query = db_select('cartogratree_fields', 'f')
252  ->fields('f', array('display_name'))
253  ->condition('field_id', $param_id)
254  ->execute();
255  $result = $query->fetchObject();
256  $name = $result->display_name;
257 
258  $form['params'][$param_id] = array(
259  '#type' => 'radios',
260  '#title' => "Select Type for environmental layer parameter \"$name\":",
261  '#options' => array(
262  'attr_id' => t('@attr_id', array('@attr_id' => 'attr_id')),
263  'cvterm' => t('@cvterm', array('@cvterm' => 'cvterm')),
264  ),
265  '#required' => TRUE,
266  );
267  $show_layers = TRUE;
268  }
269  }
270  }
271  }
272  }
273  }
274  }
275 
276  if (!$show_layers) {
277  unset($form['params']);
278  }
279 
280  if (preg_match('/P/', $submission_state['saved_values'][TPPS_PAGE_2]['data_type'])) {
281  tpps_phenotype_editor($form, $form_state, $submission_state);
282  }
283 
284 
285  $form['approve-check'] = array(
286  '#type' => 'checkbox',
287  '#title' => t('This submission has been reviewed and approved.'),
288  );
289 
290  $form['reject-reason'] = array(
291  '#type' => 'textarea',
292  '#title' => t('Reason for rejection:'),
293  '#states' => array(
294  'invisible' => array(
295  ':input[name="approve-check"]' => array('checked' => TRUE),
296  ),
297  ),
298  );
299 
300  $form['REJECT'] = array(
301  '#type' => 'submit',
302  '#value' => t('Reject'),
303  '#states' => array(
304  'invisible' => array(
305  ':input[name="approve-check"]' => array('checked' => TRUE),
306  ),
307  ),
308  );
309  }
310 
311 
312  $form['admin-comments'] = array(
313  '#type' => 'textarea',
314  '#title' => t('Additional comments (administrator):'),
315  '#default_value' => $submission_state['admin_comments'] ?? NULL,
316  '#prefix' => '<div id="tpps-admin-comments">',
317  '#suffix' => '</div>',
318  );
319 
320  if ($status == "Pending Approval") {
321  $form['APPROVE'] = array(
322  '#type' => 'submit',
323  '#value' => t('Approve'),
324  '#states' => array(
325  'visible' => array(
326  ':input[name="approve-check"]' => array('checked' => TRUE),
327  ),
328  ),
329  );
330  }
331 
332  if ($status != "Pending Approval") {
333  $form['SAVE_COMMENTS'] = array(
334  '#type' => 'button',
335  '#value' => t('Save Comments'),
336  '#ajax' => array(
337  'callback' => 'tpps_save_admin_comments',
338  'wrapper' => 'tpps-admin-comments',
339  ),
340  );
341  }
342 
343  $date = $submission_state['saved_values']['summarypage']['release-date'] ?? NULL;
344  if (!empty($date)) {
345  $datestr = "{$date['day']}-{$date['month']}-{$date['year']}";
346  if ($status != 'Approved' or strtotime($datestr) > time()) {
347  $form['date'] = array(
348  '#type' => 'date',
349  '#title' => t('Change release date'),
350  '#description' => t('You can use this field and the button below to change the release date of a submission.'),
351  '#default_value' => $date,
352  );
353 
354  $form['CHANGE_DATE'] = array(
355  '#type' => 'submit',
356  '#value' => t('Change Date'),
357  '#states' => array(
358  'invisible' => array(
359  ':input[name="date[day]"]' => array('value' => $date['day']),
360  ':input[name="date[month]"]' => array('value' => $date['month']),
361  ':input[name="date[year]"]' => array('value' => $date['year']),
362  ),
363  ),
364  );
365  }
366  }
367 
368  if ($status == "Approved") {
369  $alt_acc = $submission_state['alternative_accessions'] ?? '';
370 
371  $form['alternative_accessions'] = array(
372  '#type' => 'textfield',
373  '#title' => t('Alternative accessions'),
374  '#default_value' => $alt_acc,
375  '#description' => t('Please provide a comma-delimited list of alternative accessions you would like to assign to this submission.'),
376  );
377 
378  $form['SAVE_ALTERNATIVE_ACCESSIONS'] = array(
379  '#type' => 'submit',
380  '#value' => t('Save Alternative Accessions'),
381  );
382 
383  }
384 
385  $disable_vcf_import = 1;
386  if(!isset($submission_state['saved_values'][TPPS_PAGE_1]['disable_vcf_import'])) {
387  $disable_vcf_import = 0;
388  }
389  else {
390  $disable_vcf_import = $submission_state['saved_values'][TPPS_PAGE_1]['disable_vcf_import'];
391  }
392 
393  $form['DISABLE_VCF_IMPORT'] = array(
394  '#type' => 'checkbox',
395  '#prefix' => '<h2 style="margin-top: 30px;">Disable VCF import</h2>',
396  '#title' => 'Disable VCF Import in Tripal Job Submission',
397  '#default_value' => $disable_vcf_import,
398  );
399 
400  $form['DISABLE_VCF_IMPORT_SAVE'] = array(
401  '#type' => 'submit',
402  '#value' => t('Save VCF Import Setting'),
403  '#suffix' => '<div style="margin-bottom: 30px;"></div>'
404  );
405 
406  $submitting_user = user_load($submission_state['submitting_uid']);
407  $form['change_owner'] = array(
408  '#type' => 'textfield',
409  '#prefix' => '<h2 style="margin-top: 30px;">Change owner</h2>',
410  '#title' => t('Choose a new owner for the submission'),
411  '#default_value' => $submitting_user->mail,
412  '#autocomplete_path' => 'tpps/autocomplete/user',
413  );
414 
415  $form['CHANGE_OWNER'] = array(
416  '#type' => 'submit',
417  '#value' => t('Change Submission Owner'),
418  );
419 
420  $current_tpps_type = '';
421  if($submission_state['tpps_type'] == 'tppsc') {
422  $current_tpps_type = 'tppsc';
423  }
424  else {
425  $current_tpps_type = 'tpps';
426  }
427  $form['CHANGE_TPPS_TYPE'] = array(
428  '#type' => 'select',
429  '#title' => 'Change this study\'s TPPS type',
430  '#prefix' => '<h2 style="margin-top: 30px;">Change TPPS type</h2>',
431  '#description' => 'Warning: This will also override the original submitter owner so you become the owner of the study (you can change the owner back to the original owner but you will have to keep note of the original owner).',
432  '#options' => array(
433  'tppsc' => t('TPPSc'),
434  'tpps' => t('TPPS'),
435  ),
436  '#default_value' => $current_tpps_type,
437  );
438 
439  $form['CHANGE_TPPS_TYPE_SAVE'] = array(
440  '#type' => 'submit',
441  '#value' => t('Change TPPS Type'),
442  );
443 
444  $form['state-status'] = array(
445  '#type' => 'select',
446  '#prefix' => '<h2 style="margin-top: 30px;">Change state</h2>',
447  '#title' => t('Change state status'),
448  '#description' => t('Warning: This feature is experimental and may cause unforseen issues. Please do not change the status of this submission unless you are willing to risk the loss of existing data. The current status of the submission is @status.', array('@status' => $status)),
449  '#options' => array(
450  'Incomplete' => t('Incomplete'),
451  'Pending Approval' => t('Pending Approval'),
452  'Submission Job Running' => t('Submission Job Running'),
453  ),
454  '#default_value' => $status,
455  );
456 
457  $form['CHANGE_STATUS'] = array(
458  '#type' => 'submit',
459  '#value' => t('Change Status'),
460  '#states' => array(
461  'invisible' => array(
462  ':input[name="state-status"]' => array('value' => $status),
463  ),
464  ),
465  );
466 
467  // GENERATE_POPSTRUCT_FROM_VCF
468  $form['GENERATE_POPSTRUCT_FROM_VCF'] = array(
469  '#type' => 'submit',
470  '#prefix' => '<h2 style="margin-top: 30px;">Generate PopStruct FROM VCF</h2>',
471  '#value' => t("Generate PopStruct FROM VCF"),
472  );
473 
474  // REFRESH TPPS CVTERMS CACHE
475  $form['REFRESH_TPPS_CVTERMS_CACHE'] = array(
476  '#type' => 'submit',
477  '#prefix' => '<h2 style="margin-top: 30px;">Refresh TPPS CVTERMS CACHE</h2>',
478  '#value' => t("Refresh TPPS cvterms cache"),
479  );
480 
481  // Remove this study's markers and genotypes
482  $form['REMOVE_STUDY_MARKERS_GENOTYPES'] = array(
483  '#type' => 'submit',
484  '#prefix' => '<h2 style="margin-top: 30px;">Clear markers and genotypes</h2>Warning: This will clear all markers and genotypes for this study. You will need to resubmit the study to import back this data.',
485  '#value' => t("Remove this study's markers and genotypes"),
486  );
487 
488 
489  $form['CHANGE_TGDR_NUMBER'] = array(
490  '#type' => 'textfield',
491  '#prefix' => '<h2 style="margin-top: 30px;">Change TGDR number</h2>Warning: This will clear all data from the database and reimport as a new study.',
492  '#title' => t('Specify the new TGDR number only (do not include TGDR)'),
493  '#default_value' => '',
494  );
495 
496  // Remove this study's markers and genotypes
497  $form['CHANGE_TGDR_NUMBER_SUBMIT'] = array(
498  '#type' => 'submit',
499  '#value' => t("Change TGDR number"),
500  );
501 }
tpps_submission_get_tags($accession)
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_update_submission(array $state, array $options=array())
tpps_study_location(array &$form, array &$form_state)
tpps_table_display(array &$state, array $options=array())
Definition: display.inc:546
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27
tpps_phenotype_editor(array &$form, array &$form_state, array &$submission)
Definition: panel.php:513
const TPPS_PAGE_4
Definition: tpps.module:15
const TPPS_PAGE_3
Definition: tpps.module:14
const TPPS_PAGE_2
Definition: tpps.module:13

◆ tpps_phenotype_editor()

tpps_phenotype_editor ( array &  $form,
array &  $form_state,
array &  $submission 
)

Build form for administrators to edit phenotypes.

Parameters
array$formThe form element to be populated.
array$form_stateThe state of the form element to be populated.
array$submissionThe submission being managed.

Definition at line 513 of file panel.php.

513  {
514  $form['phenotypes_edit'] = array(
515  '#type' => 'fieldset',
516  '#title' => t('Admin Phenotype Editor'),
517  '#tree' => TRUE,
518  '#collapsible' => TRUE,
519  '#collapsed' => TRUE,
520  '#description' => t('Note: The phenotype editor does not have any validation measures in place. This means that fields in this section that are left blank will be accepted by TPPS, and they will override any user selections. Please be careful when editing information in this section.'),
521  );
522 
523  $phenotypes = array();
524  for ($i = 1; $i <= $submission['saved_values'][TPPS_PAGE_1]['organism']['number']; $i++) {
525  $phenotype = $submission['saved_values'][TPPS_PAGE_4]["organism-$i"]['phenotype'];
526  for ($j = 1; $j <= $phenotype['phenotypes-meta']['number']; $j++) {
527  $phenotypes[$j] = $phenotype['phenotypes-meta'][$j];
528  }
529  }
530 
531  // @todo get phenotypes from metadata file.
532  $attr_options = array();
533  $terms = array(
534  'age' => 'Age',
535  'alive' => 'Alive',
536  'amount' => 'Amount',
537  'angle' => 'Angle',
538  'area' => 'Area',
539  'bent' => 'Bent',
540  'circumference' => 'Circumerence',
541  'color' => 'Color',
542  'composition' => 'Composition',
543  'concentration_of' => 'Concentration of',
544  'damage' => 'Damage',
545  'description' => 'Description',
546  'diameter' => 'Diameter',
547  'distance' => 'Distance',
548  'growth_quality_of_occurrent' => 'Growth Quality of Occurrent',
549  'growth_rate' => 'Growth Rate',
550  'has_number_of' => 'Has number of',
551  'height' => 'Height',
552  'humidity_level' => 'Humidity Level',
553  'intensity' => 'Intensity',
554  'length' => 'Length',
555  'lesioned' => 'Lesioned',
556  'maturity' => 'Maturity',
557  'position' => 'Position',
558  'pressure' => 'Pressure',
559  'proportionality_to' => 'Proportionality to',
560  'rate' => 'Rate',
561  'rough' => 'Rough',
562  'shape' => 'Shape',
563  'size' => 'Size',
564  'temperature' => 'Temperature',
565  'texture' => 'Texture',
566  'thickness' => 'Thickness',
567  'time' => 'Time',
568  'volume' => 'Volume',
569  'weight' => 'Weight',
570  'width' => 'Width',
571  );
572  foreach ($terms as $term => $label) {
573  $attr_id = tpps_load_cvterm($term)->cvterm_id;
574  $attr_options[$attr_id] = $label;
575  }
576  $attr_options['other'] = 'My attribute term is not in this list';
577 
578  $unit_options = array();
579  $terms = array(
580  'boolean' => 'Boolean (Binary)',
581  'centimeter' => 'Centimeter',
582  'cubic_centimeter' => 'Cubic Centimeter',
583  'day' => 'Day',
584  'degrees_celsius' => 'Degrees Celsius',
585  'degrees_fahrenheit' => 'Dgrees Fahrenheit',
586  'grams_per_square_meter' => 'Grams per Square Meter',
587  'gram' => 'Gram',
588  'luminous_intensity_unit' => 'Luminous Intensity Unit',
589  'kilogram' => 'Kilogram',
590  'kilogram_per_cubic_meter' => 'Kilogram per Cubic Meter',
591  'liter' => 'Liter',
592  'cubic_meter' => 'Cubic Meter',
593  'pascal' => 'Pascal',
594  'meter' => 'Meter',
595  'milligram' => 'Milligram',
596  'milliliter' => 'Milliliter',
597  'millimeter' => 'Millimeter',
598  'micrometer' => 'Micrometer',
599  'percent' => 'Percent',
600  'qualitative' => 'Qualitative',
601  'square_micrometer' => 'Square Micrometer',
602  'square_millimeter' => 'Square Millimeter',
603  'watt_per_square_meter' => 'Watt per Square Meter',
604  'year' => 'Year',
605  );
606  foreach ($terms as $term => $label) {
607  $unit_id = tpps_load_cvterm($term)->cvterm_id;
608  $unit_options[$unit_id] = $label;
609  }
610  $unit_options['other'] = 'My unit is not in this list';
611 
612  $struct_options = array();
613  $terms = array(
614  'whole plant' => 'Whole Plant',
615  'bark' => 'Bark',
616  'branch' => 'Branch',
617  'bud' => 'Bud',
618  'catkin_inflorescence' => 'Catkin Inflorescence',
619  'endocarp' => 'Endocarp',
620  'floral_organ' => 'Floral Organ',
621  'flower' => 'Flower',
622  'flower_bud' => 'Flower Bud',
623  'flower_fascicle' => 'Flower Fascicle',
624  'fruit' => 'Fruit',
625  'leaf' => 'Leaf',
626  'leaf_rachis' => 'Leaf Rachis',
627  'leaflet' => 'Leaflet',
628  'nut_fruit' => 'Nut Fruit (Acorn)',
629  'petal' => 'Petal',
630  'petiole' => 'Petiole',
631  'phloem' => 'Phloem',
632  'plant_callus' => 'Plant Callus (Callus)',
633  'primary_thickening_meristem' => 'Primary Thickening Meristem',
634  'root' => 'Root',
635  'secondary_xylem' => 'Secondary Xylem (Wood)',
636  'seed' => 'Seed',
637  'shoot_system' => 'Shoot System (Crown)',
638  'stem' => 'Stem (Trunk, Primary Stem)',
639  'stomatal_complex' => 'Stomatal Complex (Stomata)',
640  'strobilus' => 'Strobilus',
641  'terminal_bud' => 'Terminal Bud',
642  'vascular_leaf' => 'Vascular Leaf (Needle)',
643  );
644  foreach ($terms as $term => $label) {
645  $struct_id = tpps_load_cvterm($term)->cvterm_id;
646  $struct_options[$struct_id] = $label;
647  }
648  $struct_options['other'] = 'My structure term is not in this list';
649 
650  foreach ($phenotypes as $num => $info) {
651  $form['phenotypes_edit'][$num] = array(
652  '#type' => 'fieldset',
653  '#title' => t('Phenotype @num (@name):', array(
654  '@num' => $num,
655  '@name' => $info['name'],
656  )),
657  '#collapsible' => TRUE,
658  '#collapsed' => TRUE,
659  'name' => array(
660  '#type' => 'textfield',
661  '#title' => t('Name'),
662  '#value' => $info['name'],
663  '#disabled' => TRUE,
664  ),
665  'description' => array(
666  '#type' => 'textfield',
667  '#title' => t('Description'),
668  '#default_value' => $info['description'],
669  ),
670  'attribute' => array(
671  '#type' => 'select',
672  '#title' => t('Attribute'),
673  '#options' => $attr_options,
674  '#default_value' => $info['attribute'],
675  ),
676  'attr-other' => array(
677  '#type' => 'textfield',
678  '#title' => t('Other Attribute'),
679  '#autocomplete_path' => 'tpps/autocomplete/attribute',
680  '#states' => array(
681  'visible' => array(
682  ':input[name="phenotypes_edit[' . $num . '][attribute]"]' => array('value' => 'other'),
683  ),
684  ),
685  '#default_value' => $info['attr-other'],
686  ),
687  'structure' => array(
688  '#type' => 'select',
689  '#title' => t('Structure'),
690  '#options' => $struct_options,
691  '#default_value' => $info['structure'],
692  ),
693  'struct-other' => array(
694  '#type' => 'textfield',
695  '#title' => t('Other Structure'),
696  '#autocomplete_path' => 'tpps/autocomplete/structure',
697  '#states' => array(
698  'visible' => array(
699  ':input[name="phenotypes_edit[' . $num . '][structure]"]' => array('value' => 'other'),
700  ),
701  ),
702  '#default_value' => $info['struct-other'],
703  ),
704  'units' => array(
705  '#type' => 'select',
706  '#title' => t('Unit'),
707  '#options' => $unit_options,
708  '#default_value' => $info['units'],
709  ),
710  'unit-other' => array(
711  '#type' => 'textfield',
712  '#title' => t('Other Unit'),
713  '#autocomplete_path' => 'tpps/autocomplete/unit',
714  '#states' => array(
715  'visible' => array(
716  ':input[name="phenotypes_edit[' . $num . '][units]"]' => array('value' => 'other'),
717  ),
718  ),
719  '#default_value' => $info['unit-other'],
720  ),
721  );
722  }
723 }
const TPPS_PAGE_1
Definition: tpps.module:12
const TPPS_PAGE_4
Definition: tpps.module:15
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)

◆ tpps_save_admin_comments()

tpps_save_admin_comments ( array  $form,
array  $form_state 
)

Ajax callback to save admin comments.

Parameters
array$formThe admin panel form element.
array$form_stateThe state of the admin panel form element.
Returns
array The updated form element.

Definition at line 736 of file panel.php.

736  {
737  $state = tpps_load_submission($form_state['values']['accession']);
738  $state['admin_comments'] = $form_state['values']['admin-comments'];
739  tpps_update_submission($state);
740  drupal_set_message(t('Comments saved successfully'), 'status');
741  return $form['admin-comments'];
742 }
tpps_update_submission(array $state, array $options=array())
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27