getdirections.admin.inc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. // optionally using version 3 googlemaps API
  3. /**
  4. * @file
  5. * getdirections module administration functions.
  6. */
  7. /**
  8. * Function to display the getdirections admin settings form
  9. * @return
  10. * Returns the form.
  11. */
  12. function getdirections_settings_form() {
  13. drupal_add_js(GETDIRECTIONS_PATH . '/js/getdirections_admin.js');
  14. $form = array();
  15. // api3
  16. $apikey = variable_get('getdirections_api3_key', '');
  17. $form['api3'] = array(
  18. '#type' => 'fieldset',
  19. '#title' => t('Google API key'),
  20. '#description' => t('This key is currently not required by Google.'),
  21. '#collapsible' => TRUE,
  22. #'#collapsed' => ($apikey ? TRUE : FALSE),
  23. '#collapsed' => TRUE,
  24. );
  25. $form['api3']['getdirections_api3_key'] = array(
  26. '#type' => 'textfield',
  27. '#title' => t('Your Google maps API Version 3 key'),
  28. '#default_value' => $apikey,
  29. '#description' => t('For more information about this key see this !u', array('!u' => l(t('page on google'), 'http://code.google.com/apis/maps/documentation/javascript/tutorial.html#api_key', array('attributes' => array('target' => '_blank'))))),
  30. '#size' => 95,
  31. '#required' => FALSE,
  32. );
  33. // preview
  34. $form['getdirections_preview'] = array(
  35. '#type' => 'fieldset',
  36. '#title' => t('Getdirections Preview'),
  37. '#description' => t('A preview of the current map settings.') . '<br />' . t('You can adjust the default Map center, Zoom and Default map type by changing the map.') . '<br />' . t('For all other changes use the form. Remember to Save configuration when you are done.'),
  38. // This will store all the defaults in one variable.
  39. '#tree' => FALSE,
  40. );
  41. $form['getdirections_preview']['preview_map'] = array('#markup' => '');
  42. // default settings
  43. $form['getdirections_default'] = array(
  44. '#type' => 'fieldset',
  45. '#title' => t('Get directions map settings'),
  46. // This will store all the defaults in one variable.
  47. '#tree' => TRUE,
  48. );
  49. $getdirections_defaults = getdirections_defaults();
  50. $form['getdirections_default'] += getdirections_default_settings($getdirections_defaults);
  51. // return link
  52. $getdirections_returnlink_defaults = getdirections_returnlink_defaults();
  53. $returnlinkform = getdirections_returnlink_settings($getdirections_returnlink_defaults);
  54. if ($returnlinkform) {
  55. $form['getdirections_returnlink'] = array(
  56. '#type' => 'fieldset',
  57. '#title' => t('Links back to page'),
  58. '#description' => t("Enable and format 'Return to page' links."),
  59. // This will store all the defaults in one variable.
  60. '#tree' => TRUE,
  61. );
  62. $form['getdirections_returnlink'] += $returnlinkform;
  63. }
  64. if (module_exists('colorbox')) {
  65. $form['getdirections_colorbox'] = array(
  66. '#type' => 'fieldset',
  67. '#title' => t('Colorbox settings'),
  68. // This will store all the defaults in one variable.
  69. '#tree' => TRUE,
  70. );
  71. $getdirections_colorbox_defaults = getdirections_colorbox_defaults();
  72. $form['getdirections_colorbox'] += getdirections_colorbox_settings($getdirections_colorbox_defaults);
  73. }
  74. // misc
  75. $form['getdirections_misc'] = array(
  76. '#type' => 'fieldset',
  77. '#title' => t('Other settings'),
  78. // This will store all the defaults in one variable.
  79. '#tree' => TRUE,
  80. );
  81. $getdirections_misc_defaults = getdirections_misc_defaults();
  82. $getdirections_misc_defaults['use_advanced'] = $getdirections_defaults['use_advanced'];
  83. $form['getdirections_misc'] += getdirections_misc_settings($getdirections_misc_defaults);
  84. // user agent string
  85. $form['getdirections_ua'] = array(
  86. '#type' => 'fieldset',
  87. '#title' => t('User Agent detection'),
  88. '#description' => t('For advanced users who want to edit the User Agent detection string.'),
  89. '#collapsible' => TRUE,
  90. '#collapsed' => TRUE,
  91. // This will store all the defaults in one variable.
  92. '#tree' => TRUE,
  93. );
  94. $getdirections_ua = getdirections_ua_get();
  95. $form['getdirections_ua']['ua_string'] = array(
  96. '#type' => 'textfield',
  97. '#title' => t('User Agent detection'),
  98. '#description' => t('User Agent detection is used to determine wether the browser is on a mobile device. Edit this regular expression with care.'),
  99. '#size' => 60,
  100. '#maxlength' => 255,
  101. '#default_value' => $getdirections_ua['ua_string'],
  102. '#required' => TRUE,
  103. );
  104. // getdirections_paths
  105. $getdirections_paths = getdirections_paths_get();
  106. $form['getdirections_paths'] = array(
  107. '#type' => 'fieldset',
  108. '#title' => t('Javascript paths'),
  109. '#description' => t('For advanced users who want to supply their own javascript.'),
  110. '#collapsible' => TRUE,
  111. '#collapsed' => TRUE,
  112. // This will store all the defaults in one variable.
  113. '#tree' => TRUE,
  114. );
  115. $form['getdirections_paths']['getdirections_v3_path'] = array(
  116. '#type' => 'textfield',
  117. '#title' => t('Path to getdirections v3 javascript file'),
  118. '#default_value' => $getdirections_paths['getdirections_v3_path'],
  119. '#size' => 60,
  120. '#description' => t('Where the getdirections v3 javascript file is located.')
  121. );
  122. $form['getdirections_paths']['getdirections_v3a_path'] = array(
  123. '#type' => 'textfield',
  124. '#title' => t('Path to getdirections v3 advanced javascript file'),
  125. '#default_value' => $getdirections_paths['getdirections_v3a_path'],
  126. '#size' => 60,
  127. '#description' => t('Where the getdirections v3 advanced javascript file is located.')
  128. );
  129. $form['getdirections_paths']['getdirections_v3b_path'] = array(
  130. '#type' => 'textfield',
  131. '#title' => t('Path to getdirections v3 alternate javascript file'),
  132. '#default_value' => $getdirections_paths['getdirections_v3b_path'],
  133. '#size' => 60,
  134. '#description' => t('Where the getdirections v3 alternate javascript file is located.')
  135. );
  136. $form['getdirections_paths']['getdirections_preview_path'] = array(
  137. '#type' => 'textfield',
  138. '#title' => t('Path to getdirections preview javascript file'),
  139. '#default_value' => $getdirections_paths['getdirections_preview_path'],
  140. '#size' => 60,
  141. '#description' => t('Where the getdirections preview javascript file is located.')
  142. );
  143. $form['getdirections_paths']['reset'] = array(
  144. '#type' => 'checkbox',
  145. '#title' => t('Reset'),
  146. '#description' => t('Reset the paths to the defaults.'),
  147. '#default_value' => 0,
  148. '#return_value' => 1,
  149. );
  150. unset($form['#theme']);
  151. $form['#theme'] = 'getdirections_settings_form';
  152. $form['#validate'][] = 'getdirections_settings_validate';
  153. return system_settings_form($form);
  154. }
  155. function getdirections_settings_validate($form, &$form_state) {
  156. if ( ! is_numeric($form_state['values']['getdirections_default']['to_width']) || $form_state['values']['getdirections_default']['to_width'] < 1) {
  157. form_set_error('getdirections_default][to_width', t('Width of To box must be a positive number'));
  158. }
  159. if ( ! is_numeric($form_state['values']['getdirections_default']['from_width']) || $form_state['values']['getdirections_default']['from_width'] < 1) {
  160. form_set_error('getdirections_default][from_width', t('Width of From box must be a positive number'));
  161. }
  162. if (isset($form_state['values']['getdirections_returnlink']['page_link'])) {
  163. if ( empty($form_state['values']['getdirections_returnlink']['page_link'])) {
  164. form_set_error('getdirections_returnlink][page_link', t('Text of return link cannot be empty'));
  165. }
  166. }
  167. if (isset($form_state['values']['getdirections_returnlink']['user_link'])) {
  168. if ( empty($form_state['values']['getdirections_returnlink']['user_link'])) {
  169. form_set_error('getdirections_returnlink][user_link', t('Text of return link cannot be empty'));
  170. }
  171. }
  172. if (isset($form_state['values']['getdirections_returnlink']['term_link'])) {
  173. if ( empty($form_state['values']['getdirections_returnlink']['term_link'])) {
  174. form_set_error('getdirections_returnlink][term_link', t('Text of return link cannot be empty'));
  175. }
  176. }
  177. if (isset($form_state['values']['getdirections_returnlink']['comment_link'])) {
  178. if ( empty($form_state['values']['getdirections_returnlink']['comment_link'])) {
  179. form_set_error('getdirections_returnlink][comment_link', t('Text of return link cannot be empty'));
  180. }
  181. }
  182. if ( isset($form_state['values']['use_advanced']) && ! $form_state['values']['use_advanced']) {
  183. $form_state['values']['advanced_alternate'] = 0;
  184. $form_state['values']['advanced_autocomplete'] = 0;
  185. $form_state['values']['advanced_autocomplete_bias'] = 0;
  186. }
  187. $list = array('Map', 'Satellite', 'Hybrid', 'Physical');
  188. $found = 0;
  189. foreach ($list AS $maptype) {
  190. if (isset($form_state['values']['getdirections_default']['maptype'])
  191. && $form_state['values']['getdirections_default']['maptype'] == $maptype
  192. && isset($form_state['values']['getdirections_default']['baselayers'][$maptype])
  193. && $form_state['values']['getdirections_default']['baselayers'][$maptype]
  194. ) {
  195. $found = 1;
  196. break;
  197. }
  198. }
  199. if (! $found) {
  200. // force a setting
  201. $form_state['values']['getdirections_default']['maptype'] = 'Map';
  202. $form_state['values']['getdirections_default']['baselayers']['Map'] = 1;
  203. }
  204. $reset = $form_state['values']['getdirections_paths']['reset'];
  205. unset($form_state['values']['getdirections_paths']['reset']);
  206. if ($reset) {
  207. $form_state['values']['getdirections_paths'] = getdirections_paths_get(TRUE);
  208. }
  209. }