Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00012 function tripal_views_integration_export_form($form_state, $setup_id) { 00013 $form = array(); 00014 00015 $defn_array = tripal_views_integration_export_entry($setup_id); 00016 00017 $t = var_export($defn_array, TRUE); 00018 $t = preg_replace("/\n\s+array/", "array", $t); // move array( to previous line 00019 $t = preg_replace("/true/", "TRUE", $t); // upper case true 00020 $t = preg_replace("/false/", "FALSE", $t); // upper case false 00021 $t = preg_replace("/array\(/", "array (", $t); // put a space between array and paren 00022 00023 $form['export'] = array( 00024 '#type' => 'textarea', 00025 '#title' => 'Export', 00026 '#description' => t('Simply copy the provided export into the Import text area on ' 00027 . 'another tripal views enabled website to port the integration between websites.'), 00028 '#rows' => 20, 00029 '#value' => $t, 00030 ); 00031 00032 return $form; 00033 } 00034 00038 function tripal_views_integration_import_form() { 00039 $form = array(); 00040 00041 $form['name'] = array( 00042 '#type' => 'textfield', 00043 '#title' => 'Name (optional)', 00044 '#description' => t('A human-readable name for your integration.') 00045 ); 00046 00047 $priorities = array(); 00048 foreach (range(-10, 10) as $v) { 00049 $priorities[$v] = (string) $v; 00050 } 00051 $form['views_type']['row_priority'] = array( 00052 '#type' => 'select', 00053 '#title' => t('Priority (optional)'), 00054 '#description' => t('The level of priority your Views integration has in relation to the ' 00055 .'default core and module definitions. The views integration definition with the ' 00056 .'lightest priority will be used. For example, if there is a definition created by ' 00057 .'core with a priority of 10 and another by a custom module of 5 and yours is -1 then ' 00058 .'you definition will be used for that table because -1 is lighter then both 5 and 10.'), 00059 '#options' => $priorities, 00060 '#default_value' => -1, 00061 ); 00062 00063 $form['import'] = array( 00064 '#type' => 'textarea', 00065 '#title' => 'Import', 00066 '#description' => t('Simply copy the provided export into the text area to port the integration between websites.'), 00067 '#rows' => 20, 00068 ); 00069 00070 $form['submit'] = array( 00071 '#type' => 'submit', 00072 '#value' => 'Submit' 00073 ); 00074 00075 return $form; 00076 } 00077 00081 function tripal_views_integration_import_form_submit($form, &$form_state) { 00082 00083 //$defn_array = unserialize($form_state['values']['import']); 00084 // convert the array into a real PHP array 00085 $defn_array = array(); 00086 eval("\$defn_array = " . $form_state['values']['import'] . ";"); 00087 00088 // Add optional parameters 00089 if ($form_state['values']['name']) { 00090 $defn_array['name'] = $form_state['values']['name']; 00091 } 00092 if ($form_state['values']['row_priority']) { 00093 $defn_array['priority'] = $form_state['values']['row_priority']; 00094 } 00095 00096 // Add the views integration 00097 $success = tripal_views_integration_add_entry($defn_array); 00098 if ($success) { 00099 drupal_set_message(t("Successfully imported %name Integration", array('%name' => $defn_array['name']))); 00100 } 00101 else { 00102 drupal_set_message(t("Unable to import %name Integration", array('%name' => $defn_array['name'])), 'error'); 00103 } 00104 }