31 if (empty($accession)) {
38 drupal_add_js(drupal_get_path(
'module',
'tpps') .
TPPS_JS_PATH);
39 drupal_add_css(drupal_get_path(
'module',
'tpps') .
TPPS_CSS_PATH);
60 $status = $submission->status;
61 $submission_state = unserialize($submission->submission_state);
62 if (empty($submission_state[
'status'])) {
63 $submission_state[
'status'] = $status;
67 $display = l(t(
"Back to TPPS Admin Panel"),
"$base_url/tpps-admin-panel");
71 $results = db_query(
"SELECT * FROM public.tripal_jobs WHERE job_name LIKE 'TPPS Record Submission - $accession' ORDER BY submit_date DESC LIMIT 1;");
73 while($row_array = $results->fetchObject()) {
76 $job_id = $row_array->job_id;
79 $display .=
"<div style='padding: 10px;'>No log file exists for this study (resubmit this study to generate a log file if necessary)</div>";
82 $log_path = drupal_realpath(
'public://') .
'/tpps_job_logs/';
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>";
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>";
92 if ($status ==
"Pending Approval") {
93 $options[
'files'] = array(
94 'revision_destination' => TRUE,
96 $options[
'skip_phenotypes'] = TRUE;
98 foreach ($submission_state[
'file_info'] as $files) {
99 foreach ($files as $fid => $file_type) {
100 $file = file_load($fid) ?? NULL;
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\">",
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(),
117 ":input[name=\"edit_file_{$fid}_check\"]" => array(
'checked' => TRUE),
121 $form[
"edit_file_{$fid}_markup"] = array(
122 '#markup' =>
'</div>',
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'];
137 if ($phenotype[
'phenotypes-meta'][$j][
'attribute'] ===
'other') {
138 $new_cvterms[] = $phenotype[
'phenotypes-meta'][$j][
'attr-other'];
140 if ($phenotype[
'phenotypes-meta'][$j][
'units'] ===
'other') {
141 $new_cvterms[] = $phenotype[
'phenotypes-meta'][$j][
'unit-other'];
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> 155 $form[
'accession'] = array(
157 '#value' => $accession,
160 $form[
'form_table'] = array(
161 '#markup' => $display,
164 $form[
'file_diagnostics'] = array(
165 '#markup' =>
'<a class="btn btn-primary" target="_blank" href="file-diagnostics/' . $accession .
'">Files diagnostics</a><br /><br />',
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 />',
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')
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>";
189 $tags_markup .=
"</span>";
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')
196 ->condition(
'static', 0)
198 while (($result = $query->fetchObject())) {
199 $color = $result->color;
204 if (array_key_exists($result->tpps_tag_id, $submission_tags)) {
205 $style =
'display: none';
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>";
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>",
215 if ($status ==
"Pending Approval") {
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'];
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];
228 unset($form[
'study_location'][
'locations'][
'add']);
229 unset($form[
'study_location'][
'locations'][
'remove']);
231 $form[
'study_location'][
'#collapsed'] = TRUE;
234 $form[
'params'] = array(
235 '#type' =>
'fieldset',
236 '#title' =>
'Select Environmental parameter types:',
238 '#description' =>
'',
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);
251 $query = db_select(
'cartogratree_fields',
'f')
252 ->fields(
'f', array(
'display_name'))
253 ->condition(
'field_id', $param_id)
255 $result = $query->fetchObject();
256 $name = $result->display_name;
258 $form[
'params'][$param_id] = array(
260 '#title' =>
"Select Type for environmental layer parameter \"$name\":",
262 'attr_id' => t(
'@attr_id', array(
'@attr_id' =>
'attr_id')),
263 'cvterm' => t(
'@cvterm', array(
'@cvterm' =>
'cvterm')),
277 unset($form[
'params']);
280 if (preg_match(
'/P/', $submission_state[
'saved_values'][TPPS_PAGE_2][
'data_type'])) {
285 $form[
'approve-check'] = array(
286 '#type' =>
'checkbox',
287 '#title' => t(
'This submission has been reviewed and approved.'),
290 $form[
'reject-reason'] = array(
291 '#type' =>
'textarea',
292 '#title' => t(
'Reason for rejection:'),
294 'invisible' => array(
295 ':input[name="approve-check"]' => array(
'checked' => TRUE),
300 $form[
'REJECT'] = array(
302 '#value' => t(
'Reject'),
304 'invisible' => array(
305 ':input[name="approve-check"]' => array(
'checked' => TRUE),
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>',
320 if ($status ==
"Pending Approval") {
321 $form[
'APPROVE'] = array(
323 '#value' => t(
'Approve'),
326 ':input[name="approve-check"]' => array(
'checked' => TRUE),
332 if ($status !=
"Pending Approval") {
333 $form[
'SAVE_COMMENTS'] = array(
335 '#value' => t(
'Save Comments'),
337 'callback' =>
'tpps_save_admin_comments',
338 'wrapper' =>
'tpps-admin-comments',
343 $date = $submission_state[
'saved_values'][
'summarypage'][
'release-date'] ?? NULL;
345 $datestr =
"{$date['day']}-{$date['month']}-{$date['year']}";
346 if ($status !=
'Approved' or strtotime($datestr) > time()) {
347 $form[
'date'] = array(
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,
354 $form[
'CHANGE_DATE'] = array(
356 '#value' => t(
'Change Date'),
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']),
368 if ($status ==
"Approved") {
369 $alt_acc = $submission_state[
'alternative_accessions'] ??
'';
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.'),
378 $form[
'SAVE_ALTERNATIVE_ACCESSIONS'] = array(
380 '#value' => t(
'Save Alternative Accessions'),
385 $disable_vcf_import = 1;
386 if(!isset($submission_state[
'saved_values'][
TPPS_PAGE_1][
'disable_vcf_import'])) {
387 $disable_vcf_import = 0;
390 $disable_vcf_import = $submission_state[
'saved_values'][
TPPS_PAGE_1][
'disable_vcf_import'];
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,
400 $form[
'DISABLE_VCF_IMPORT_SAVE'] = array(
402 '#value' => t(
'Save VCF Import Setting'),
403 '#suffix' =>
'<div style="margin-bottom: 30px;"></div>' 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',
415 $form[
'CHANGE_OWNER'] = array(
417 '#value' => t(
'Change Submission Owner'),
420 $current_tpps_type =
'';
421 if($submission_state[
'tpps_type'] ==
'tppsc') {
422 $current_tpps_type =
'tppsc';
425 $current_tpps_type =
'tpps';
427 $form[
'CHANGE_TPPS_TYPE'] = array(
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).',
433 'tppsc' => t(
'TPPSc'),
436 '#default_value' => $current_tpps_type,
439 $form[
'CHANGE_TPPS_TYPE_SAVE'] = array(
441 '#value' => t(
'Change TPPS Type'),
444 $form[
'state-status'] = array(
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)),
450 'Incomplete' => t(
'Incomplete'),
451 'Pending Approval' => t(
'Pending Approval'),
452 'Submission Job Running' => t(
'Submission Job Running'),
454 '#default_value' => $status,
457 $form[
'CHANGE_STATUS'] = array(
459 '#value' => t(
'Change Status'),
461 'invisible' => array(
462 ':input[name="state-status"]' => array(
'value' => $status),
468 $form[
'GENERATE_POPSTRUCT_FROM_VCF'] = array(
470 '#prefix' =>
'<h2 style="margin-top: 30px;">Generate PopStruct FROM VCF</h2>',
471 '#value' => t(
"Generate PopStruct FROM VCF"),
475 $form[
'REFRESH_TPPS_CVTERMS_CACHE'] = array(
477 '#prefix' =>
'<h2 style="margin-top: 30px;">Refresh TPPS CVTERMS CACHE</h2>',
478 '#value' => t(
"Refresh TPPS cvterms cache"),
482 $form[
'REMOVE_STUDY_MARKERS_GENOTYPES'] = array(
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"),
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' =>
'',
497 $form[
'CHANGE_TGDR_NUMBER_SUBMIT'] = array(
499 '#value' => t(
"Change TGDR number"),
514 $form[
'phenotypes_edit'] = array(
515 '#type' =>
'fieldset',
516 '#title' => t(
'Admin Phenotype Editor'),
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.'),
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];
532 $attr_options = array();
536 'amount' =>
'Amount',
540 'circumference' =>
'Circumerence',
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',
564 'temperature' =>
'Temperature',
565 'texture' =>
'Texture',
566 'thickness' =>
'Thickness',
568 'volume' =>
'Volume',
569 'weight' =>
'Weight',
572 foreach ($terms as $term => $label) {
574 $attr_options[$attr_id] = $label;
576 $attr_options[
'other'] =
'My attribute term is not in this list';
578 $unit_options = array();
580 'boolean' =>
'Boolean (Binary)',
581 'centimeter' =>
'Centimeter',
582 'cubic_centimeter' =>
'Cubic Centimeter',
584 'degrees_celsius' =>
'Degrees Celsius',
585 'degrees_fahrenheit' =>
'Dgrees Fahrenheit',
586 'grams_per_square_meter' =>
'Grams per Square Meter',
588 'luminous_intensity_unit' =>
'Luminous Intensity Unit',
589 'kilogram' =>
'Kilogram',
590 'kilogram_per_cubic_meter' =>
'Kilogram per Cubic Meter',
592 'cubic_meter' =>
'Cubic Meter',
593 'pascal' =>
'Pascal',
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',
606 foreach ($terms as $term => $label) {
608 $unit_options[$unit_id] = $label;
610 $unit_options[
'other'] =
'My unit is not in this list';
612 $struct_options = array();
614 'whole plant' =>
'Whole Plant',
616 'branch' =>
'Branch',
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',
626 'leaf_rachis' =>
'Leaf Rachis',
627 'leaflet' =>
'Leaflet',
628 'nut_fruit' =>
'Nut Fruit (Acorn)',
630 'petiole' =>
'Petiole',
631 'phloem' =>
'Phloem',
632 'plant_callus' =>
'Plant Callus (Callus)',
633 'primary_thickening_meristem' =>
'Primary Thickening Meristem',
635 'secondary_xylem' =>
'Secondary Xylem (Wood)',
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)',
644 foreach ($terms as $term => $label) {
646 $struct_options[$struct_id] = $label;
648 $struct_options[
'other'] =
'My structure term is not in this list';
650 foreach ($phenotypes as $num => $info) {
651 $form[
'phenotypes_edit'][$num] = array(
652 '#type' =>
'fieldset',
653 '#title' => t(
'Phenotype @num (@name):', array(
655 '@name' => $info[
'name'],
657 '#collapsible' => TRUE,
658 '#collapsed' => TRUE,
660 '#type' =>
'textfield',
661 '#title' => t(
'Name'),
662 '#value' => $info[
'name'],
665 'description' => array(
666 '#type' =>
'textfield',
667 '#title' => t(
'Description'),
668 '#default_value' => $info[
'description'],
670 'attribute' => array(
672 '#title' => t(
'Attribute'),
673 '#options' => $attr_options,
674 '#default_value' => $info[
'attribute'],
676 'attr-other' => array(
677 '#type' =>
'textfield',
678 '#title' => t(
'Other Attribute'),
679 '#autocomplete_path' =>
'tpps/autocomplete/attribute',
682 ':input[name="phenotypes_edit[' . $num .
'][attribute]"]' => array(
'value' =>
'other'),
685 '#default_value' => $info[
'attr-other'],
687 'structure' => array(
689 '#title' => t(
'Structure'),
690 '#options' => $struct_options,
691 '#default_value' => $info[
'structure'],
693 'struct-other' => array(
694 '#type' =>
'textfield',
695 '#title' => t(
'Other Structure'),
696 '#autocomplete_path' =>
'tpps/autocomplete/structure',
699 ':input[name="phenotypes_edit[' . $num .
'][structure]"]' => array(
'value' =>
'other'),
702 '#default_value' => $info[
'struct-other'],
706 '#title' => t(
'Unit'),
707 '#options' => $unit_options,
708 '#default_value' => $info[
'units'],
710 'unit-other' => array(
711 '#type' =>
'textfield',
712 '#title' => t(
'Other Unit'),
713 '#autocomplete_path' =>
'tpps/autocomplete/unit',
716 ':input[name="phenotypes_edit[' . $num .
'][units]"]' => array(
'value' =>
'other'),
719 '#default_value' => $info[
'unit-other'],
738 $state[
'admin_comments'] = $form_state[
'values'][
'admin-comments'];
740 drupal_set_message(t(
'Comments saved successfully'),
'status');
741 return $form[
'admin-comments'];
757 $incomplete = array();
758 $unpublished_old = array();
760 $submitting_user_cache = array();
763 foreach ($submissions as $submission) {
764 $state = unserialize($submission->submission_state);
765 $status = $submission->status;
766 if (empty($state[
'status'])) {
767 $state[
'status'] = $status;
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'));
779 $query = $query->execute();
780 $name = $query->fetchObject()->name ?? NULL;
782 $submitting_user_cache[$submission->uid] = $name ?? $mail;
784 $submitting_user = $submitting_user_cache[$submission->uid] ?? NULL;
786 if (!empty($state)) {
787 switch ($state[
'status']) {
788 case 'Pending Approval':
790 l($state[
'accession'],
"$base_url/tpps-admin-panel/{$state['accession']}"),
792 $state[
'saved_values'][
TPPS_PAGE_1][
'publication'][
'title'],
793 !empty($state[
'completed']) ? date(
"F j, Y, g:i a", $state[
'completed']) :
"Unknown",
796 $pending[(int) substr($state[
'accession'], 4)] = $row;
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'));
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)
819 $entity = current(array_reverse(entity_load(
'TripalEntity', array_keys($results[
'TripalEntity']))));
820 $owner =
"<a href=\"$base_url/TripalContactProfile/{$entity->id}\">$submitting_user</a>";
823 $owner_mail = user_load($submission->uid)->mail;
824 if ($owner_mail != $owner) {
825 $owner =
"$submitting_user ($owner_mail)";
829 l($state[
'accession'],
"$base_url/tpps-admin-panel/{$state['accession']}"),
830 date(
"F j, Y", $state[
'loaded']) .
" (" . round($days_since_load) .
" days ago)",
834 if (
tpps_access(
'view own tpps submission', $state[
'accession'])) {
835 $row[] = l(t(
'Edit publication information'),
"tpps/{$state['accession']}/edit-publication");
837 $unpublished_old[(int) substr($state[
'accession'], 4)] = $row;
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);
849 l($state[
'accession'],
"$base_url/tpps-admin-panel/{$state['accession']}"),
851 $state[
'saved_values'][TPPS_PAGE_1][
'publication'][
'title'],
855 $approved[(int) substr($state[
'accession'], 4)] = $row;
859 switch ($state[
'stage']) {
861 $stage =
"Author and Species Information";
865 $stage =
"Experimental Conditions";
869 $stage =
"Plant Accession";
873 $stage =
"Submit Data";
877 $stage =
"Review Data and Submit";
886 l($state[
'accession'],
"$base_url/tpps-admin-panel/{$state['accession']}"),
888 $state[
'saved_values'][TPPS_PAGE_1][
'publication'][
'title'] ??
'Title not provided yet',
890 !empty($state[
'updated']) ? date(
"F j, Y, g:i a", $state[
'updated']) :
"Unknown",
893 $incomplete[(int) substr($state[
'accession'], 4)] = $row;
904 'attributes' => array(
905 'class' => array(
'view',
'tpps_table'),
913 $vars[
'header'] = array(
916 'Publication Status',
919 $vars[
'rows'] = $unpublished_old;
920 $unpublished_table = theme(
'table', $vars);
922 $vars[
'header'] = array(
929 $vars[
'rows'] = $pending;
930 $pending_table = theme(
'table', $vars);
932 $vars[
'header'] = array(
939 $vars[
'rows'] = $approved;
940 $approved_table = theme(
'table', $vars);
942 $vars[
'header'] = array(
950 $vars[
'rows'] = $incomplete;
951 $incomplete_table = theme(
'table', $vars);
953 if (!empty($unpublished_old)) {
954 $form[
'unpublished_old'] = array(
955 '#type' =>
'fieldset',
956 '#title' => t(
'Unpublished Approved TPPS Submissions'),
957 '#collapsible' => TRUE,
959 '#markup' => $unpublished_table,
964 if (!empty($pending)) {
965 $form[
'pending'] = array(
966 '#type' =>
'fieldset',
967 '#title' => t(
'Pending TPPS submissions'),
968 '#collapsible' => TRUE,
970 '#markup' => $pending_table,
975 if (!empty($approved)) {
976 $form[
'approved'] = array(
977 '#type' =>
'fieldset',
978 '#title' => t(
'Approved TPPS submissions'),
979 '#collapsible' => TRUE,
981 '#markup' => $approved_table,
986 if (!empty($incomplete)) {
987 $form[
'incomplete'] = array(
988 '#type' =>
'fieldset',
989 '#title' => t(
'Incomplete TPPS submissions'),
990 '#collapsible' => TRUE,
992 '#markup' => $incomplete_table,
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);
1010 if (!empty($to_resubmit)) {
1011 $vars[
'header'] = array(
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,
1021 '#markup' => $to_resubmit_table,
1026 $tpps_new_orgs = variable_get(
'tpps_new_organisms', NULL);
1027 $db = chado_get_db(array(
'name' =>
'NCBI Taxonomy'));
1030 $query = db_select(
'chado.organism',
'o');
1031 $query->fields(
'o', array(
'organism_id',
'genus',
'species'));
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();
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);
1045 "<a href=\"$base_url/bio_data/{$id}/edit\" target=\"_blank\">$org->genus $org->species</a>",
1050 "$org->genus $org->species",
1054 if (!empty($rows)) {
1058 'header' => $headers,
1060 'attributes' => array(
1061 'class' => array(
'view',
'tpps_table'),
1062 'id' =>
'new_species',
1065 'colgroups' => NULL,
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>";
1072 variable_set(
'tpps_new_organisms', $tpps_new_orgs);
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.'));
1088 if ($form_state[
'triggering_element'][
'#value'] ==
'Approve') {
1089 $accession = $form_state[
'values'][
'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.'));
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));
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.");
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.");
1119 $result = db_select(
'tpps_submission',
's')
1121 ->condition(
'accession', $acc)
1123 ->execute()->fetchObject();
1124 if (!empty($result)) {
1125 form_set_error(
'alternative_accessions',
"The accession, $acc is already in use.");
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'));
1137 drupal_add_js(drupal_get_path(
'module',
'tpps') .
TPPS_JS_PATH);
1138 drupal_add_css(drupal_get_path(
'module',
'tpps') .
TPPS_CSS_PATH);
1152 $type = $form_state[
'tpps_type'] ??
'tpps';
1153 $type_label = ($type ==
'tpps') ?
'TPPS' :
'TPPSC';
1155 $accession = $form_state[
'values'][
'accession'];
1157 $owner = user_load($submission->uid);
1159 $state = unserialize($submission->submission_state);
1160 $state[
'admin_comments'] = $form_state[
'values'][
'admin-comments'] ?? NULL;
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'] =
'';
1171 $params[
'headers'][] =
'MIME-Version: 1.0';
1172 $params[
'headers'][] =
'Content-type: text/html; charset=iso-8859-1';
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);
1180 switch ($form_state[
'triggering_element'][
'#value']) {
1181 case 'Save VCF Import Setting':
1183 if($form_state[
'values'][
'DISABLE_VCF_IMPORT'] == 1) {
1184 $state[
'saved_values'][
TPPS_PAGE_1][
'disable_vcf_import'] = 1;
1187 $state[
'saved_values'][
TPPS_PAGE_1][
'disable_vcf_import'] = 0;
1190 drupal_set_message(t(
'VCF disable import setting saved'),
'status');
1193 case "Remove this study's markers and genotypes":
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);
1203 case "Change TGDR number":
1207 if(!is_numeric($form_state[
'values'][
'CHANGE_TGDR_NUMBER'])) {
1208 drupal_set_message(t(
'You did not enter a valid number. Operation aborted.'));
1212 $new_accession =
'TGDR' . $form_state[
'values'][
'CHANGE_TGDR_NUMBER'];
1215 $results = chado_query(
'SELECT count(*) as c1 FROM public.tpps_submission WHERE accession = :new_accession', array(
1216 ':new_accession' => $new_accession
1218 $result_object = $results->fetchObject();
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.'));
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];
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);
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);
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;
1251 case "Generate PopStruct FROM VCF":
1253 $includes = array();
1254 $includes[] = module_load_include(
'php',
'tpps',
'forms/submit/submit_all');
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);
1261 $args = array($accession,$location);
1263 $jid = tripal_add_job(
"TPPS Generate PopStruct FROM VCF - $accession",
'tpps',
'tpps_generate_popstruct', $args, $user->uid, 10, $includes, TRUE);
1266 drupal_set_message(
"Could not find a VCF tied to organism-1, are you sure you linked a VCF file?");
1270 case "Refresh TPPS cvterms cache":
1272 $includes = array();
1273 $includes[] = module_load_include(
'php',
'tpps',
'forms/submit/submit_all');
1274 $includes[] = module_load_include(
'inc',
'tpps',
'includes/cvterm_utils');
1276 $jid = tripal_add_job(
"TPPS REFRESH CVTERMS CACHE",
'tpps',
'tpps_cvterms_clear_cache', $args, $user->uid, 10, $includes, TRUE);
1280 case 'Change TPPS Type':
1282 if($form_state[
'values'][
'CHANGE_TPPS_TYPE'] ==
'tppsc') {
1285 $state[
'tpps_type'] =
'tppsc';
1288 'uid' => $user->uid,
1293 $state[
'tpps_type'] =
'tpps';
1296 drupal_set_message(t(
'Updated study TPPS type: ') . $state[
'tpps_type'],
'status');
1300 drupal_mail($type,
'user_rejected', $to, user_preferred_language($owner), $params, $from, TRUE);
1301 $state[
'status'] =
'Incomplete';
1303 drupal_set_message(t(
'Submission Rejected. Message has been sent to user.'),
'status');
1304 drupal_goto(
'<front>');
1308 module_load_include(
'php',
'tpps',
'forms/submit/submit_all');
1311 $state[
'submitting_uid'] = $uid;
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);
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"];
1327 if (!empty($form_state[
'values'][
'phenotypes_edit'])) {
1328 $state[
'phenotypes_edit'] = $form_state[
'values'][
'phenotypes_edit'];
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];
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;
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;
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';
1364 $state[
'saved_values'][
'summarypage'][
'release-date'] = $form_state[
'values'][
'date'];
1368 case 'Change Status':
1369 $state[
'status'] = $form_state[
'values'][
'state-status'];
1371 dpm($state[
'status']);
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) {
1380 $state[
'alternative_accessions'] = $new_alt_acc;
1385 case 'Change Submission Owner':
1386 $new_user = user_load_by_mail($form_state[
'values'][
'change_owner']);
1387 $state[
'submitting_uid'] = $new_user->uid;
1389 'uid' => $new_user->uid,
tpps_submission_get_tags($accession)
tpps_submission_add_alternative_accession(array $state, $alt_accession)
tpps_admin_panel_submit($form, &$form_state)
tpps_manage_submission_form(array &$form, array &$form_state, $accession=NULL)
tpps_update_submission(array $state, array $options=array())
tpps_study_location(array &$form, array &$form_state)
tpps_show_tags(array $tags)
tpps_admin_panel_validate($form, &$form_state)
tpps_table_display(array &$state, array $options=array())
tpps_load_submission($accession, $state=TRUE)
tpps_admin_panel_top(array &$form)
tpps_phenotype_editor(array &$form, array &$form_state, array &$submission)
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)
tpps_load_submission_multiple(array $conditions=array(), $state=TRUE)
tpps_get_location($location)
tpps_save_admin_comments(array $form, array $form_state)
tpps_admin_panel(array $form, array &$form_state, $accession=NULL)