Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00011 function tripal_views_elements() { 00012 00013 $type['file_upload_combo'] = array( 00014 '#input' => TRUE, 00015 '#process' => array('expand_file_upload_combo'), 00016 '#element_validate' => array('file_upload_combo_validate'), 00017 ); 00018 00019 $type['sequence_combo'] = array( 00020 '#input' => TRUE, 00021 '#process' => array('expand_sequence_combo'), 00022 '#element_validate' => array('sequence_combo_validate'), 00023 ); 00024 00025 return $type; 00026 } 00027 00032 function expand_file_upload_combo($element, $edit, $form_state, $complete_form) { 00033 00034 // set the default values for each field 00035 if (empty($element['#value'])) { 00036 $element['#value'] = array( 00037 'items' => '', 00038 'items_file' => '', 00039 'file_path' => '', 00040 ); 00041 } 00042 00043 $element['#tree'] = TRUE; 00044 00045 // add items text area element 00046 $parents = $element['#parents']; 00047 $parents[] = 'items'; 00048 $element['items'] = array( 00049 '#type' => 'textarea', 00050 '#default_value' => $element['#value']['items'], 00051 ); 00052 00053 // add file upload element 00054 $parents = $element['#parents']; 00055 $parents[] = 'items_file'; 00056 $element['items_file'] = array( 00057 '#type' => 'file', 00058 '#title' => 'File upload', 00059 '#default_value' => $element['#value']['items_file'], 00060 ); 00061 00062 // add hidden elelment 00063 $parents = $element['#parents']; 00064 $parents[] = 'file_path'; 00065 $element['file_path'] = array( 00066 '#type' => 'hidden', 00067 '#default_value' => $element['#value']['file_path'], 00068 ); 00069 00070 return $element; 00071 } 00075 function expand_sequence_combo($element, $edit, $form_state, $complete_form) { 00076 00077 // set the default values for each field 00078 if (empty($element['#value'])) { 00079 $element['#value'] = array( 00080 'upstream' => '', 00081 'downstream' => '', 00082 ); 00083 } 00084 00085 $element['#tree'] = TRUE; 00086 00087 // add the upstream box 00088 $parents = $element['#parents']; 00089 $parents[] = 'upstream'; 00090 $element['upstream'] = array( 00091 '#type' => 'textfield', 00092 '#title' => t('Get Upstream Bases'), 00093 '#description' => t('Specify the number of upstream bases to include in the sequnce'), 00094 '#default_value' => $element['#value']['upstream'], 00095 ); 00096 // add the downstream box 00097 $parents = $element['#parents']; 00098 $parents[] = 'downstream'; 00099 $element['downstream'] = array( 00100 '#type' => 'textfield', 00101 '#prefix' => '<br>', 00102 '#title' => t('Get Downstream Bases'), 00103 '#description' => t('Specify the number of downstream bases to include in the sequnce'), 00104 '#default_value' => $element['#value']['downstream'], 00105 ); 00106 return $element; 00107 } 00108 00112 function theme_file_upload_combo($element) { 00113 return theme('form_element', $element, '<div class="container-inline">' . $element['#children'] . '</div>'); 00114 } 00115 00119 function theme_sequence_combo($element) { 00120 return theme('form_element', $element, '<div class="container-inline">' . $element['#children'] . '</div>'); 00121 } 00122 00126 function file_upload_combo_validate($element, &$form) { 00127 $file = file_save_upload($element['#name'], array()); 00128 if ($file) { 00129 $form['values'][$element['#name']]['file_path'] = $file->filepath; 00130 // we need to add our file path to the $_GET element as if it were 00131 // submitted along with the rest of the form 00132 $_GET[$element['#name']]['file_path'] = $file->filepath; 00133 } 00134 } 00135 00139 function sequence_combo_validate($element, &$form) { 00140 $upstream = $form['values'][$element['#name']]['upstream']; 00141 $downstream = $form['values'][$element['#name']]['downstream']; 00142 00143 00144 if ($upstream < 0) { 00145 form_set_error($element['#name'], 'Please provide a positive number for upstream bases'); 00146 } 00147 if ($upstream and !preg_match('/^\d+$/', $upstream)) { 00148 form_set_error($element['#name'], 'Please provide a decimal number for upstream bases'); 00149 } 00150 00151 if ($downstream < 0) { 00152 form_set_error($element['#name'], 'Please provide a positive number for downstream bases'); 00153 } 00154 if ($downstream and !preg_match('/^\d+$/', $downstream)) { 00155 form_set_error($element['#name'], 'Please provide a decimal number for downstream bases'); 00156 } 00157 }