Project

General

Profile

« Previous | Next » 

Revision 95944919

Added by Andreas Kohlbecker almost 13 years ago

fixing #2532 (Don't show file name for images if descritpion is given.)

View differences:

modules/cdm_dataportal/cdm_dataportal.module
32 32
require_once('classes/renderhints.php');
33 33

  
34 34
function _add_js_progressbar(){
35
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.progressbar/js/jquery.progressbar.js');
35
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.progressbar/js/jquery.progressbar.js');
36 36
}
37 37

  
38 38
function _add_js_treeselector(){
39
	//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js');
40
	drupal_add_js("
41
		if (Drupal.jsEnabled) {
42
		  $(document).ready(function() {
43
		      $('#cdm-taxonomictree-selector-form #edit-val').change(function () {
44
		          $('#cdm-taxonomictree-selector-form').submit();
45
		      });
46

  
47
		  });
48
		}", 'inline');
39
  //drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js');
40
  drupal_add_js("
41
    if (Drupal.jsEnabled) {
42
      $(document).ready(function() {
43
          $('#cdm-taxonomictree-selector-form #edit-val').change(function () {
44
              $('#cdm-taxonomictree-selector-form').submit();
45
          });
46

  
47
      });
48
    }", 'inline');
49 49
}
50 50

  
51 51
function _add_js_openlayers_map(){
52 52

  
53
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
54
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/openlayers_map.js');
55

  
56
	$gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
57

  
58
	$baseLayers = variable_get('baselayers', array());
59
	if(!is_array($baseLayers) || count($baseLayers) == 0){
60
		$baseLayers = array('metacarta_vmap0' => 'Metacarta Vmap0', 'PREFERRED' => 'metacarta_vmap0');
61
	}
62
	$layerNames = '';
63
	foreach($baseLayers as $layerName => $layerLabel){
64
		if($layerName == 'PREFERRED'){
65
			$preferredLayer = $baseLayers['PREFERRED'];
66
		} else {
67
			$layerNames .= ($layerNames ? ', ': '') . "'$layerName'";
68
		}
69
	}
70

  
71
	if( isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb']) ){
72
	  drupal_set_html_head('<script src=http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key='.$gmap_api_key.'" type="text/javascript"></script>');
73
	  drupal_set_html_head('<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1" type="text/javascript"></script>');
74
	}
75

  
76
	drupal_add_js("
53
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
54
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/openlayers_map.js');
55

  
56
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
57

  
58
  $baseLayers = variable_get('baselayers', array());
59
  if(!is_array($baseLayers) || count($baseLayers) == 0){
60
    $baseLayers = array('metacarta_vmap0' => 'Metacarta Vmap0', 'PREFERRED' => 'metacarta_vmap0');
61
  }
62
  $layerNames = '';
63
  foreach($baseLayers as $layerName => $layerLabel){
64
    if($layerName == 'PREFERRED'){
65
      $preferredLayer = $baseLayers['PREFERRED'];
66
    } else {
67
      $layerNames .= ($layerNames ? ', ': '') . "'$layerName'";
68
    }
69
  }
70

  
71
  if( isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb']) ){
72
    drupal_set_html_head('<script src=http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key='.$gmap_api_key.'" type="text/javascript"></script>');
73
    drupal_set_html_head('<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1" type="text/javascript"></script>');
74
  }
75

  
76
  drupal_add_js("
77 77
        if (Drupal.jsEnabled) {
78 78
          $(document).ready(function() {
79 79
              $('#openlayers_map').cdm_openlayers_map('"
......
95 95

  
96 96
function get_openlayers_map($width, $occurrenceQuery = false, $distributionQuery = false, $legendFormatQuery = false, $map_caption = false ){
97 97

  
98
	_add_js_openlayers_map();
99

  
100
	$out = '<div id="openlayers">';
101
	$out .= '<div id="openlayers_map" class="smallmap"';
102
	$out .= ' style="width: ' . $width . 'px; height:'.( $width / 2).'px"';
103
	if($occurrenceQuery){
104

  
105
		//fix $occurrenceQuery
106
		$occurrenceQuery .= '&ms=400,350';
107
		$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
108
		$occurrenceQuery .= '&legend=0'; //TODO add to cdm service?
109

  
110
		$out .= ' occurrenceQuery="'.$occurrenceQuery.'"';
111
	}
112
	if($distributionQuery){
113
		$out .= ' distributionQuery="'.$distributionQuery.'"';
114
	}
115
	if($legendFormatQuery){
116
		$out .= ' legendFormatQuery="'.$legendFormatQuery.'"';
117
	}
118
	$out .= '></div></div>';
119

  
120
	// showing map caption
121
	if($map_caption){
122
		$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; //FIXME: replace <br> by according css style
123
		$out .= '</div>';
124
	}
125
	return $out;
98
  _add_js_openlayers_map();
99

  
100
  $out = '<div id="openlayers">';
101
  $out .= '<div id="openlayers_map" class="smallmap"';
102
  $out .= ' style="width: ' . $width . 'px; height:'.( $width / 2).'px"';
103
  if($occurrenceQuery){
104

  
105
    //fix $occurrenceQuery
106
    $occurrenceQuery .= '&ms=400,350';
107
    $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
108
    $occurrenceQuery .= '&legend=0'; //TODO add to cdm service?
109

  
110
    $out .= ' occurrenceQuery="'.$occurrenceQuery.'"';
111
  }
112
  if($distributionQuery){
113
    $out .= ' distributionQuery="'.$distributionQuery.'"';
114
  }
115
  if($legendFormatQuery){
116
    $out .= ' legendFormatQuery="'.$legendFormatQuery.'"';
117
  }
118
  $out .= '></div></div>';
119

  
120
  // showing map caption
121
  if($map_caption){
122
    $out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; //FIXME: replace <br> by according css style
123
    $out .= '</div>';
124
  }
125
  return $out;
126 126
}
127 127

  
128 128
/* ====================== hook implementations ====================== */
......
135 135
 * @return array An array of valid permissions for the portfolio module
136 136
 */
137 137
function cdm_dataportal_perm() {
138
	return array(
139
    	'administer cdm_dataportal',
138
  return array(
139
      'administer cdm_dataportal',
140 140
      'cdm_dataportal view notes',
141
	//TODO which else permission are required? -> check the WP6 requirements document
142
	);
141
  //TODO which else permission are required? -> check the WP6 requirements document
142
  );
143 143
}
144 144

  
145 145

  
......
147 147
 * Implementation of hook_menu()
148 148
 */
149 149
function cdm_dataportal_menu($may_cache) {
150
	$items = array();
150
  $items = array();
151 151

  
152
	cdm_dataportal_menu_admin($may_cache, $items);
153
	cdm_dataportal_menu_help($may_cache, $items);
152
  cdm_dataportal_menu_admin($may_cache, $items);
153
  cdm_dataportal_menu_help($may_cache, $items);
154 154

  
155
	if ($may_cache) {
155
  if ($may_cache) {
156 156

  
157
	 $items[] = array(
158
	    'path' => 'cdm_dataportal/names',
159
	    'callback' => 'cdm_dataportal_view_names',
160
	    'access' => true,
161
	    'type' => MENU_CALLBACK,
162
		);
163
		// optional callback arguments: page
157
   $items[] = array(
158
      'path' => 'cdm_dataportal/names',
159
      'callback' => 'cdm_dataportal_view_names',
160
      'access' => true,
161
      'type' => MENU_CALLBACK,
162
    );
163
    // optional callback arguments: page
164 164

  
165
		$items[] = array(
165
    $items[] = array(
166 166
      'path' => 'cdm_dataportal/taxon',
167 167
      'callback' => 'cdm_dataportal_taxon_page_view',
168 168
      'access' => true,
169 169
      'type' => MENU_CALLBACK,
170
		// expected callback arguments: uuid
171
		);
170
    // expected callback arguments: uuid
171
    );
172 172

  
173
		$items[] = array(
173
    $items[] = array(
174 174
      'path' => 'cdm_dataportal/name',
175 175
      'callback' => 'cdm_dataportal_name_page_view',
176 176
      'access' => true,
177 177
      'type' => MENU_CALLBACK,
178
		// expected callback arguments: uuid
179
		);
178
    // expected callback arguments: uuid
179
    );
180 180

  
181
		$items[] = array(
181
    $items[] = array(
182 182
      'path' => 'cdm_dataportal/reference',
183 183
      'callback' => 'cdm_dataportal_view_reference',
184 184
      'access' => true,
185 185
      'type' => MENU_CALLBACK,
186
		// expected callback arguments: uuid
187
		);
186
    // expected callback arguments: uuid
187
    );
188 188

  
189
		$items[] = array(
189
    $items[] = array(
190 190
      'path' => 'cdm_dataportal/reference/list',
191 191
      'callback' => 'cdm_dataportal_view_reference_list',
192 192
      'access' => true,
193 193
      'type' => MENU_CALLBACK,
194
		// expected callback arguments: uuid
195
		);
194
    // expected callback arguments: uuid
195
    );
196 196

  
197
		$items[] = array(
197
    $items[] = array(
198 198
      'path' => 'cdm_dataportal/media',
199 199
      'callback' => 'cdm_dataportal_view_media',
200 200
      'access' => true,
201 201
      'type' => MENU_CALLBACK,
202
		// expected callback arguments: uuid, mediarepresentation_uuid, part_uuid or part#
203
		);
202
    // expected callback arguments: uuid, mediarepresentation_uuid, part_uuid or part#
203
    );
204 204

  
205
		$items[] = array(
205
    $items[] = array(
206 206
      'path' => 'cdm_dataportal/polytomousKey',
207 207
      'callback' => 'cdm_dataportal_view_polytomousKey',
208 208
      'access' => true,
......
210 210
    // expected callback arguments: polytomousKey->uuid
211 211
    );
212 212

  
213
		$items[] = array(
213
    $items[] = array(
214 214
      'path' => 'cdm_dataportal/search',
215 215
      'callback' => 'cdm_dataportal_view_search_advanced',
216 216
      'access' => true,
217 217
      'type' => MENU_CALLBACK,
218
		);
218
    );
219 219

  
220
		$items[] = array(
220
    $items[] = array(
221 221
      'path' => 'cdm_dataportal/search/taxon',
222 222
      'callback' => 'cdm_dataportal_view_search_taxon',
223 223
      'access' => true,
224 224
      'type' => MENU_CALLBACK,
225
		);
225
    );
226 226

  
227
		$items[] = array(
227
    $items[] = array(
228 228
      'path' => 'cdm/xml2json',
229 229
      'callback' => 'cdm_view_xml2json',
230 230
      'access' => true,
231 231
      'type' => MENU_CALLBACK,
232
		);
232
    );
233 233

  
234
	}elseif (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid)) {
235
		//user configuration of cdm_dataportal
236
		$items[] = array('path' => 'user/'.$uid.'/cdm_dataportal',
234
  }elseif (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid)) {
235
    //user configuration of cdm_dataportal
236
    $items[] = array('path' => 'user/'.$uid.'/cdm_dataportal',
237 237
        'title' => t('cdm_dataportal'),
238 238
        'access' => TRUE,
239 239
        'callback' => 'drupal_get_form',
......
241 241
        'type' => MENU_LOCAL_TASK,
242 242
        'weight' => 10,
243 243
      );
244
	} else {
245
		// may not cache
246
		// --- local tasks for Taxon
247
		$items[] = array(
244
  } else {
245
    // may not cache
246
    // --- local tasks for Taxon
247
    $items[] = array(
248 248
      'path' => 'cdm_dataportal/name/'.arg(2),
249
		//'callback' => 'cdm_dataportal_view_name',
250
		  'callback' => 'cdm_dataportal_name_page_view',
249
    //'callback' => 'cdm_dataportal_view_name',
250
      'callback' => 'cdm_dataportal_name_page_view',
251 251
      'callback arguments' => array(arg(2), arg(3), arg(4)),
252 252
      'access' => true,
253 253
      'type' => MENU_CALLBACK,
254
		);
254
    );
255 255

  
256
		if(variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
256
    if(variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
257 257

  
258
			$items[] = array(
258
      $items[] = array(
259 259
      'path' => 'cdm_dataportal/taxon/'.arg(2),
260 260
      'title' => theme('cdm_taxonpage_tab', 'General'),
261 261
      'callback' => 'cdm_dataportal_taxon_page_view',
......
263 263
      'type' => MENU_CALLBACK,
264 264
      'weight' => 1,
265 265
      'callback arguments' => array(arg(2), "description")
266
			// expected callback arguments: name_uuid
267
			);
266
      // expected callback arguments: name_uuid
267
      );
268 268

  
269
			$items[] = array(
269
      $items[] = array(
270 270
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/all',
271 271
      'title' => theme('cdm_taxonpage_tab', 'General'),
272 272
      'callback' => 'cdm_dataportal_taxon_page_view',
......
274 274
      'type' => MENU_CALLBACK,
275 275
      'weight' => 2,
276 276
      'callback arguments' => array(arg(2), "all")
277
			// expected callback arguments: name_uuid
278
			);
277
      // expected callback arguments: name_uuid
278
      );
279 279

  
280
			$items[] = array(
280
      $items[] = array(
281 281
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/description',
282 282
      'title' => theme('cdm_taxonpage_tab', 'General'),
283 283
      'callback' => 'cdm_dataportal_taxon_page_view',
......
285 285
      'type' => MENU_DEFAULT_LOCAL_TASK,
286 286
      'weight' => 2,
287 287
      'callback arguments' => array(arg(2), "description")
288
			// expected callback arguments: name_uuid
289
			);
288
      // expected callback arguments: name_uuid
289
      );
290 290

  
291
			$items[] = array(
291
      $items[] = array(
292 292
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/synonymy',
293 293
      'title' => theme('cdm_taxonpage_tab', 'Synonymy'),
294 294
      'callback' => 'cdm_dataportal_taxon_page_view',
......
296 296
      'type' => MENU_LOCAL_TASK,
297 297
      'weight' => 4,
298 298
      'callback arguments' => array(arg(2), "synonymy", arg(4))
299
			// expected callback arguments: name_uuid
300
			);
301
			$items[] = array(
299
      // expected callback arguments: name_uuid
300
      );
301
      $items[] = array(
302 302
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/images',
303 303
      'title' => theme('cdm_taxonpage_tab', 'Images'),
304 304
      'callback' => 'cdm_dataportal_taxon_page_view',
......
306 306
      'type' => MENU_LOCAL_TASK,
307 307
      'weight' => 5,
308 308
      'callback arguments' => array(arg(2), "images")
309
			// expected callback arguments: name_uuid
310
			);
311

  
312
		 $items[] = array(
313
		 'path' => 'cdm_dataportal/taxon/'.arg(2).'/specimens',
314
		 'title' => theme('cdm_taxonpage_tab', 'Specimens'),
315
		 'callback' => 'cdm_dataportal_taxon_page_view',
316
		 'access' => true,
317
		 'type' => MENU_LOCAL_TASK,
318
		 'weight' => 6,
319
		 'callback arguments' => array(arg(2), "specimens")
320
		 // expected callback arguments: name_uuid
321
		 );
322

  
323
		 $items[] = array(
309
      // expected callback arguments: name_uuid
310
      );
311

  
312
     $items[] = array(
313
     'path' => 'cdm_dataportal/taxon/'.arg(2).'/specimens',
314
     'title' => theme('cdm_taxonpage_tab', 'Specimens'),
315
     'callback' => 'cdm_dataportal_taxon_page_view',
316
     'access' => true,
317
     'type' => MENU_LOCAL_TASK,
318
     'weight' => 6,
319
     'callback arguments' => array(arg(2), "specimens")
320
     // expected callback arguments: name_uuid
321
     );
322

  
323
     $items[] = array(
324 324
     'path' => 'cdm_dataportal/taxon/'.arg(2).'/keys',
325 325
     'title' => theme('cdm_taxonpage_tab', 'Keys'),
326 326
     'callback' => 'cdm_dataportal_taxon_page_view',
......
330 330
     'callback arguments' => array(arg(2), "keys")
331 331
     // expected callback arguments: name_uuid
332 332
     );
333
		}
334
	}
333
    }
334
  }
335 335

  
336
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
337
	//drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
338
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
336
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
337
  //drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
338
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
339 339

  
340
	return $items;
340
  return $items;
341 341

  
342 342
}
343 343
/**
......
345 345
 */
346 346
function cdm_dataportal_user_form() {
347 347

  
348
	global $user;
348
  global $user;
349 349
    $checkbox_value = 'cdm_dataportal_' .$user->uid . '_default_tab_active';
350 350

  
351
	$form['check'] = array
351
  $form['check'] = array
352 352
    (
353 353
    '#type'            => 'checkbox',
354 354
    '#title'         => t('Activate user default configuration'),
......
356 356
    '#description' => t('Check this if you want configure your own default tab from the below menu.')
357 357
    );
358 358

  
359
	$form['cdm_dataportal_user_form'] =  array(
359
  $form['cdm_dataportal_user_form'] =  array(
360 360
      '#type'          => 'select',
361 361
      '#title'         => t('Default tab to display'),
362
	    '#default_value' => get_default_taxon_tab(true),
362
      '#default_value' => get_default_taxon_tab(true),
363 363
      '#options'       => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
364 364
      '#description'   => t('<p>Select the default tab to display when visiting a taxon page. Only available if Tabbed Taxon Page is enable.</p>
365 365
              <strong>Note:</strong> After performing a search and clicking in any synonym, the taxon tab
366 366
              to be renderized will be the synonymy of the accepted taxon and not the above selected tab.'),
367
	);
367
  );
368 368

  
369
	$form['submit'] = array(
370
	  '#type' => 'submit',
371
	  '#value' => t('Submit')
372
	);
369
  $form['submit'] = array(
370
    '#type' => 'submit',
371
    '#value' => t('Submit')
372
  );
373 373

  
374
	return $form;
374
  return $form;
375 375
}
376 376

  
377 377
/**
......
380 380
 * @param unknown_type $form_values
381 381
 */
382 382
function cdm_dataportal_user_form_submit($form, $form_values) {
383
	global $user;
384
	$msg_type = 'status';
385
	$username = $user->name;
386
	$variable_to_use = 'cdm_dataportal_' .$user->uid . '_default_tab';
387

  
388
	//if is the right user the variables are setted
389
	if (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid) && $user->uid==$uid){
390
		$variable = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
391
		variable_set($variable_to_use . '_active', $form_values['check']);
392
		variable_set($variable_to_use, $form_values['cdm_dataportal_user_form']);
393
		if ($form_values['check']){
394
			drupal_set_message('The user default tab will be used for the next taxon site visit.');
395
			drupal_set_message('The user default tab have been changed to: '
383
  global $user;
384
  $msg_type = 'status';
385
  $username = $user->name;
386
  $variable_to_use = 'cdm_dataportal_' .$user->uid . '_default_tab';
387

  
388
  //if is the right user the variables are setted
389
  if (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid) && $user->uid==$uid){
390
    $variable = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
391
    variable_set($variable_to_use . '_active', $form_values['check']);
392
    variable_set($variable_to_use, $form_values['cdm_dataportal_user_form']);
393
    if ($form_values['check']){
394
      drupal_set_message('The user default tab will be used for the next taxon site visit.');
395
      drupal_set_message('The user default tab have been changed to: '
396 396
            . $variable[variable_get($variable_to_use, 0)]
397 397
            . ' for the user ' . $username, $msg_type);
398
		}else{
399
			drupal_set_message('The user default tab wont be used for the next taxon site, check the box if you want to use the user default configuration.');
400
		}
401
	//problem with the user id => variables wont be saved
402
	}else{
403
		$msg_type = 'warning';
404
		drupal_set_message('Default tab have not been saved due to user id problems', $msg_type);
405
	}
398
    }else{
399
      drupal_set_message('The user default tab wont be used for the next taxon site, check the box if you want to use the user default configuration.');
400
    }
401
  //problem with the user id => variables wont be saved
402
  }else{
403
    $msg_type = 'warning';
404
    drupal_set_message('Default tab have not been saved due to user id problems', $msg_type);
405
  }
406 406
}
407 407

  
408 408
/**
......
415 415
 * @param int $delta
416 416
 */
417 417
function cdm_dataportal_block($op='list', $delta=0) {
418
	// listing of blocks, such as on the admin/block page
419
	if ($op == "list") {
420
		//$block[0]["info"] = t("CDM DataPortal DevLinks");
421
		//		$block[1]["info"] = t("CDM DataPortal Credits");
422
		$block[2]["info"] = t("CDM Search Taxa");
423
		//$block[3]["info"] = t("CDM Filters");
424
		$block[4]["info"] = t("CDM Dataportal Print");
425
		$block["keys"]["info"] = t("CDM identification keys");
426
		return $block;
427
	}
428
	else if ($op == 'view') {
429
		switch($delta){
430
			//			case 1:
431
			//				$block['subject'] = t('Credits');
432
			//				$block['content'] = theme('cdm_credits');
433
			//				return $block;
434
			case 2:
435
				$block['subject'] = t('Search taxa');
436
				$block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
437
				if (variable_get('cdm_dataportal_show_advanced_search', 1)){
438
				    $block['content'] .= '<div>'.l('Advanced Search', '/cdm_dataportal/search').'</div>';
439
				}
440
				return $block;
441
			case 4:
442
				$block['subject'] = t('<none>');
443
				$block['content'] = theme('cdm_print_button');;
444
				return $block;
445
			case "keys":
446
				$block['subject'] = t('Identification Keys');
418
  // listing of blocks, such as on the admin/block page
419
  if ($op == "list") {
420
    //$block[0]["info"] = t("CDM DataPortal DevLinks");
421
    //		$block[1]["info"] = t("CDM DataPortal Credits");
422
    $block[2]["info"] = t("CDM Search Taxa");
423
    //$block[3]["info"] = t("CDM Filters");
424
    $block[4]["info"] = t("CDM Dataportal Print");
425
    $block["keys"]["info"] = t("CDM identification keys");
426
    return $block;
427
  }
428
  else if ($op == 'view') {
429
    switch($delta){
430
      //			case 1:
431
      //				$block['subject'] = t('Credits');
432
      //				$block['content'] = theme('cdm_credits');
433
      //				return $block;
434
      case 2:
435
        $block['subject'] = t('Search taxa');
436
        $block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
437
        if (variable_get('cdm_dataportal_show_advanced_search', 1)){
438
            $block['content'] .= '<div>'.l('Advanced Search', '/cdm_dataportal/search').'</div>';
439
        }
440
        return $block;
441
      case 4:
442
        $block['subject'] = t('<none>');
443
        $block['content'] = theme('cdm_print_button');;
444
        return $block;
445
      case "keys":
446
        $block['subject'] = t('Identification Keys');
447 447
        $block['content'] = theme('cdm_block_IdentificationKeys');
448 448
        return $block;
449
		}
450
	}
449
    }
450
  }
451 451
}
452 452

  
453 453

  
......
472 472

  
473 473
function cdm_dataportal_search_taxon_form($advancedForm = false){
474 474

  
475
	$preset_query = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
476
	$preset_doTaxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
477
	$preset_doSynonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
478
	$preset_doTaxaByCommonNames = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
479
	$tdwg_level_select =  (isset($_SESSION['cdm']['search']['tdwg_level_select']) ? $_SESSION['cdm']['search']['tdwg_level_select'] : 2);
480
	$selected_areas =  (isset($_SESSION['cdm']['search']['area']) ? $_SESSION['cdm']['search']['area'] : false);
475
  $preset_query = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
476
  $preset_doTaxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
477
  $preset_doSynonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
478
  $preset_doTaxaByCommonNames = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
479
  $tdwg_level_select =  (isset($_SESSION['cdm']['search']['tdwg_level_select']) ? $_SESSION['cdm']['search']['tdwg_level_select'] : 2);
480
  $selected_areas =  (isset($_SESSION['cdm']['search']['area']) ? $_SESSION['cdm']['search']['area'] : false);
481 481

  
482
	$url = 'cdm_dataportal/search/taxon';
483
	$form['#method'] = 'get';
484
	$form['#process'] = array('cdm_dataportal_search_process' => array());
485
	$form['#action'] = url($url, NULL, NULL, true);
482
  $url = 'cdm_dataportal/search/taxon';
483
  $form['#method'] = 'get';
484
  $form['#process'] = array('cdm_dataportal_search_process' => array());
485
  $form['#action'] = url($url, NULL, NULL, true);
486 486

  
487
	$form['query'] = array(
487
  $form['query'] = array(
488 488
    '#delta' => 0,
489 489
    '#type' => 'textfield',
490 490
    '#size' => 20,
491 491
    '#attributes' => array('title' => t('Enter the name or part of a name you wish to search for. The asterisk  character * can always be used as wildcard')),
492 492
    '#value' => $preset_query,
493
	);
493
  );
494 494

  
495
	$form['search'] = array(
495
  $form['search'] = array(
496 496
      '#delta' => 1,
497 497
      '#tree' => true,
498
	//'#type' => $advancedForm ? 'fieldset': 'hidden',
498
  //'#type' => $advancedForm ? 'fieldset': 'hidden',
499 499
      '#title' => t('Options')
500
	);
500
  );
501 501

  
502
	$form['search']['tree'] = array(
502
  $form['search']['tree'] = array(
503 503
    '#delta' => -1,
504 504
    '#type' => 'hidden',
505 505
    '#value' => get_taxonomictree_uuid_selected()
506
	);
506
  );
507 507

  
508 508

  
509
	// clean URL get forms breaks if we don't give it a 'q'.
510
	if (!(bool)variable_get('clean_url', '0')) {
511
		$form['search']['q'] = array(
509
  // clean URL get forms breaks if we don't give it a 'q'.
510
  if (!(bool)variable_get('clean_url', '0')) {
511
    $form['search']['q'] = array(
512 512
      '#delta' => -1,
513 513
      '#type' => 'hidden',
514 514
      '#value' => $url,
515 515
      '#name' => 'q',
516
		);
517
	}
516
    );
517
  }
518 518

  
519
	$form['search']['pageSize'] = array(
519
  $form['search']['pageSize'] = array(
520 520
      '#delta' => -1,
521 521
      '#type' => 'hidden',
522 522
      '#value' => variable_get('cdm_dataportal_search_items_on_page', 25)
523
	);
523
  );
524 524

  
525
	$form['search']['pageNumber'] = array(
525
  $form['search']['pageNumber'] = array(
526 526
      '#delta' => -1,
527 527
      '#type' => 'hidden',
528 528
      '#value' => 0
529 529
  );
530 530

  
531
	if($advancedForm){
532
		// general search parameters
533
		$form['search']['doTaxa'] = array(
531
  if($advancedForm){
532
    // general search parameters
533
    $form['search']['doTaxa'] = array(
534 534
      '#delta' => 2,
535 535
      '#type' => 'checkbox',
536 536
      '#title' => t('Search for accepted taxa'),
537 537
      '#value' => $preset_doTaxa
538
		);
539
		$form['search']['doSynonyms'] = array(
538
    );
539
    $form['search']['doSynonyms'] = array(
540 540
      '#delta' => 3,
541 541
      '#type' => 'checkbox',
542 542
      '#title' => t('Search for synonyms'),
543 543
      '#value' => $preset_doSynonyms
544
		);
545
		$form['search']['doTaxaByCommonNames'] = array(
544
    );
545
    $form['search']['doTaxaByCommonNames'] = array(
546 546
      '#delta' => 4,
547 547
      '#type' => 'checkbox',
548 548
      '#title' => t('Search for common names'),
549 549
      '#value' => $preset_doTaxaByCommonNames
550
		);
550
    );
551 551

  
552
		// Geographic Range
553
		$form['search']['geographic_range'] = array(
552
    // Geographic Range
553
    $form['search']['geographic_range'] = array(
554 554
      '#type' => 'fieldset',
555 555
      '#delta' => 5,
556 556
      '#tree' => true,
557 557
      '#title' => t('Geographic range'),
558
		);
558
    );
559 559

  
560
		$form['search']['geographic_range']['tdwg_level_select'] = array(
560
    $form['search']['geographic_range']['tdwg_level_select'] = array(
561 561
    '#type' => 'radios',
562 562
    '#title' => t('Select a TDWG distribution level and code'),
563 563
    '#default_value' => $tdwg_level_select,
564 564
    '#options' => array(
565
		t('TDWG level-1, i.e. a continent'),
566
		t('TDWG level-2'),
567
		t('TDWG level-3, i.e. a country'),
568
		t('TDWG level-4')
569
		)
570
		);
571
		$tdwg[1] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '1');
572
		$tdwg[2] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '2');
573
		$tdwg[3] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '3');
574
		$tdwg[4] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '4');
575

  
576
		$tdwg_js = '';
577
		foreach($tdwg as $key=>$tdwg_level){
578
			$tdwgOptions = array();
579
			$tdwgOptionsSelected = array();
580
			foreach($tdwg_level as $area){
581
				$representation = $area->representations[0];
582
				$tdwgOptions[$representation->abbreviatedLabel] = $area->representation_L10n;
583
				if(is_array($selected_areas) && in_array($representation->abbreviatedLabel, $selected_areas)){
584
					$tdwgOptionsSelected[] = $representation->abbreviatedLabel; //$area->uuid;
585
				}
586
			}
587
			asort($tdwgOptions);
588
			$form['search']['geographic_range']['tdwg_level_'.$key] = array(
565
    t('TDWG level-1, i.e. a continent'),
566
    t('TDWG level-2'),
567
    t('TDWG level-3, i.e. a country'),
568
    t('TDWG level-4')
569
    )
570
    );
571
    $tdwg[1] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '1');
572
    $tdwg[2] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '2');
573
    $tdwg[3] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '3');
574
    $tdwg[4] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '4');
575

  
576
    $tdwg_js = '';
577
    foreach($tdwg as $key=>$tdwg_level){
578
      $tdwgOptions = array();
579
      $tdwgOptionsSelected = array();
580
      foreach($tdwg_level as $area){
581
        $representation = $area->representations[0];
582
        $tdwgOptions[$representation->abbreviatedLabel] = $area->representation_L10n;
583
        if(is_array($selected_areas) && in_array($representation->abbreviatedLabel, $selected_areas)){
584
          $tdwgOptionsSelected[] = $representation->abbreviatedLabel; //$area->uuid;
585
        }
586
      }
587
      asort($tdwgOptions);
588
      $form['search']['geographic_range']['tdwg_level_'.$key] = array(
589 589
        '#type' => 'select',
590 590
        '#title'         => t('TDWG level').' '.$key,
591 591
        '#default_value' => $tdwgOptionsSelected,
592 592
        '#multiple' => TRUE,
593 593
        '#options' => $tdwgOptions
594
			);
595
			$tdwg_js .= "$('#edit-search-geographic-range-tdwg-level-$key').parent()".($tdwg_level_select + 1 == $key ?  '.show()' : '.hide()'). ";\n";
596
		}
594
      );
595
      $tdwg_js .= "$('#edit-search-geographic-range-tdwg-level-$key').parent()".($tdwg_level_select + 1 == $key ?  '.show()' : '.hide()'). ";\n";
596
    }
597 597

  
598
		drupal_add_js(
598
    drupal_add_js(
599 599
    "$(document).ready(function(){
600 600

  
601 601
      $(\"input[@name='search[geographic_range][tdwg_level_select]']\").change(
......
618 618
    });",
619 619
    'inline');
620 620

  
621
	} else {
622
		$form['search']['doTaxa'] = array(
623
	      '#delta' => -2,
624
	      '#type' => 'hidden',
625
	      '#value' => 1
626
		);
627
		$form['search']['doSynonyms'] = array(
628
	      '#delta' => -3,
629
	      '#type' => 'hidden',
630
	      '#value' => 1
631
		);
632
		$form['search']['doTaxaByCommonNames'] = array(
633
	      '#delta' => -4,
634
	      '#type' => 'hidden',
635
	      '#value' => 0
636
		);
637
	}
638

  
639
	$form['submit'] = array(
640
	  '#delta' => 9,
641
	  '#type' => 'submit',
642
	  '#name' => '',
643
	  '#value' => t('Search')
644
	);
645

  
646
	return $form;
621
  } else {
622
    $form['search']['doTaxa'] = array(
623
        '#delta' => -2,
624
        '#type' => 'hidden',
625
        '#value' => 1
626
    );
627
    $form['search']['doSynonyms'] = array(
628
        '#delta' => -3,
629
        '#type' => 'hidden',
630
        '#value' => 1
631
    );
632
    $form['search']['doTaxaByCommonNames'] = array(
633
        '#delta' => -4,
634
        '#type' => 'hidden',
635
        '#value' => 0
636
    );
637
  }
638

  
639
  $form['submit'] = array(
640
    '#delta' => 9,
641
    '#type' => 'submit',
642
    '#name' => '',
643
    '#value' => t('Search')
644
  );
645

  
646
  return $form;
647 647
}
648 648

  
649 649
function cdm_dataportal_search_taxon_form_advanced(){
650
	return cdm_dataportal_search_taxon_form(true);
650
  return cdm_dataportal_search_taxon_form(true);
651 651
}
652 652

  
653 653
function cdm_taxonomictree_selector(){
654
	_add_js_treeselector();
654
  _add_js_treeselector();
655 655

  
656
	$out = drupal_get_form('cdm_taxonomictree_selector_form');
656
  $out = drupal_get_form('cdm_taxonomictree_selector_form');
657 657

  
658
	return $out;
658
  return $out;
659 659
}
660 660

  
661 661

  
662 662
function cdm_taxonomictree_selector_form(){
663 663

  
664
	$url = url('cdm_api/setvalue/session', null);
665
	$form['#action'] = $url;
664
  $url = url('cdm_api/setvalue/session', null);
665
  $form['#action'] = $url;
666 666

  
667
	$form['var'] = array(
667
  $form['var'] = array(
668 668
        '#delta' => -3,
669 669
        '#type' => 'hidden',
670 670
        '#value' => '[cdm][taxonomictree_uuid]'
671 671
        );
672 672

  
673 673
        $form['destination'] = array(
674
	   '#delta' => -3,
675
	   '#type' => 'hidden',
676
	   '#value' => substr(drupal_get_destination(), strlen('destination='))
674
     '#delta' => -3,
675
     '#type' => 'hidden',
676
     '#value' => substr(drupal_get_destination(), strlen('destination='))
677 677
        );
678 678

  
679 679
        $form['val'] = array(
......
695 695
 * @return unknown_type
696 696
 */
697 697
function cdm_dataportal_search_process($form) {
698
	unset($form['form_id']);
699
	unset($form['form_token']);
700
	return $form;
698
  unset($form['form_id']);
699
  unset($form['form_token']);
700
  return $form;
701 701
}
702 702

  
703 703
/**
......
707 707
function cdm_dataportal_search_form_request(){
708 708

  
709 709

  
710
	$form_params = array();
711
	array_deep_copy($_REQUEST['search'], $form_params);
712
	$form_params['query'] =  trim($_REQUEST['query']);
710
  $form_params = array();
711
  array_deep_copy($_REQUEST['search'], $form_params);
712
  $form_params['query'] =  trim($_REQUEST['query']);
713 713

  
714
	// split of  geographic range
715
	if(isset($_REQUEST['search']['geographic_range'])){
716
		$geographicRange = $_REQUEST['search']['geographic_range'];
717
		// remove
718
		unset($form_params['geographic_range']);
719
	}
714
  // split of  geographic range
715
  if(isset($_REQUEST['search']['geographic_range'])){
716
    $geographicRange = $_REQUEST['search']['geographic_range'];
717
    // remove
718
    unset($form_params['geographic_range']);
719
  }
720 720

  
721
	// add geographic range
722
	if($geographicRange){
723
		$form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
724
		for($i = 1; $i < 5; $i++){
725
			if(isset($geographicRange['tdwg_level_'.$i])){
726
				$form_params['area'] = $geographicRange['tdwg_level_'.$i];
727
			}
728
		}
729
	}
721
  // add geographic range
722
  if($geographicRange){
723
    $form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
724
    for($i = 1; $i < 5; $i++){
725
      if(isset($geographicRange['tdwg_level_'.$i])){
726
        $form_params['area'] = $geographicRange['tdwg_level_'.$i];
727
      }
728
    }
729
  }
730 730

  
731
	// store in session
732
	$_SESSION['cdm']['search'] = $form_params;
731
  // store in session
732
  $_SESSION['cdm']['search'] = $form_params;
733 733

  
734
	return $form_params;
734
  return $form_params;
735 735
}
736 736

  
737 737

  
......
751 751

  
752 752
function cdm_dataportal_form_alter($form_id, &$form) {
753 753

  
754
	static $comment_node_disabled =  0;
755
	static $comment_node_read_only =  1;
756
	static $comment_node_read_write =  2;
754
  static $comment_node_disabled =  0;
755
  static $comment_node_read_only =  1;
756
  static $comment_node_read_write =  2;
757 757

  
758 758

  
759
	if ($form_id == 'node_type_form'
760
	&& isset($form['identity']['type'])
761
	&& array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
762
	) {
763
		$form['workflow']['comment'] = array(
759
  if ($form_id == 'node_type_form'
760
  && isset($form['identity']['type'])
761
  && array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
762
  ) {
763
    $form['workflow']['comment'] = array(
764 764
      '#type' => 'radios',
765 765
      '#title' => t('Default comment setting'),
766 766
      '#default_value' => variable_get('comment_'. $form['#node_type']->type, $comment_node_disabled),
767 767
      '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
768 768
      '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
769
		);
770
	}
769
    );
770
  }
771 771
}
772 772

  
773 773

  
774 774

  
775 775
function cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed, $form_description = ''){
776 776
//TODO move into settings.php
777
	$form[$form_name] = array(
777
  $form[$form_name] = array(
778 778
    '#type' => 'fieldset',
779 779
    '#title' => t($form_tittle),
780 780
    '#collapsible' => TRUE,
781 781
    '#collapsed' => $collapsed,
782 782
    '#tree' => true,
783
	'#description' => t($form_description),
784
	);
785

  
786
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
787
	$gallery_settings = variable_get($form_name, $default_values);
788
	//$test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
789

  
790
	if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
791
		/* TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
792
		 $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
793
		 '#type' => 'textfield',
794
		 '#title' => t('Search Page Size'),
795
		 '#default_value' => $test,
796
		 '#description' => t('Number of Names to display per page in search results.')
797
		 );
798
		 */
799
		$form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
783
  '#description' => t($form_description),
784
  );
785

  
786
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
787
  $gallery_settings = variable_get($form_name, $default_values);
788
  //$test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
789

  
790
  if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
791
    /* TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
792
     $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
793
     '#type' => 'textfield',
794
     '#title' => t('Search Page Size'),
795
     '#default_value' => $test,
796
     '#description' => t('Number of Names to display per page in search results.')
797
     );
798
     */
799
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
800 800
      '#type' => 'checkbox',
801 801
      '#title' => t('Show media thumbnails for accepted taxa'),
802 802
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
803
		);
803
    );
804 804

  
805
		$form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
805
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
806 806
      '#type' => 'checkbox',
807 807
      '#title' => t('Show media thumbnails for synonyms'),
808 808
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
809 809
      '#description' => t('')
810
		);
811
	}
810
    );
811
  }
812 812

  
813
	//$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
814
	$form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
813
  //$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
814
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
815 815
    '#type' => 'checkbox',
816 816
    '#title' => t('Show captions under thumbnails'),
817 817
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
818 818
    '#description' => t('')
819
	);
819
  );
820 820

  
821
	$form[$form_name]['cdm_dataportal_media_maxextend'] = array(
821
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
822 822
    '#type' => 'textfield',
823 823
    '#title' => t('Thumbnail size'),
824 824
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
825 825
    '#description' => t('Select the size of each individual thumbnail.')
826
	);
826
  );
827 827

  
828
	if($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME){
829
	   $form[$form_name]['cdm_dataportal_media_cols'] = array(
828
  if($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME){
829
     $form[$form_name]['cdm_dataportal_media_cols'] = array(
830 830
        '#type' => 'textfield',
831 831
        '#title' => t('Number of columns'),
832 832
        '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
833 833
        '#description' => t('Group the thumbnails in columns: select how many columns should the gallery display.')
834
	   );
835
	}
834
     );
835
  }
836 836

  
837
	if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
838
		$form[$form_name]['cdm_dataportal_media_maxRows'] = array(
837
  if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
838
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
839 839
      '#type' => 'textfield',
840 840
      '#title' => t('Maximum number of rows'),
841 841
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
842 842
      '#description' => t('You can group the thumbnails in rows, select in how many rows should be the thumbnails grouped.<br>
843 843
                           <b>Note:</b> If you want an unlimited number of rows please set to 0')
844
		);
845
	}
844
    );
845
  }
846 846

  
847
	return $form;
847
  return $form;
848 848
}
849 849

  
850 850

  
......
857 857
 */
858 858
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
859 859

  
860
	$request_params  = array(
860
  $request_params  = array(
861 861
    'q' => $beginsWith,
862
	//'sec' = '',
863
	//'higherTaxa' => getFiters(),
864
	// 'matchAnywhere' => false, // default is false
862
  //'sec' = '',
863
  //'higherTaxa' => getFiters(),
864
  // 'matchAnywhere' => false, // default is false
865 865
    'page' => $page,
866 866
    'onlyAccepted' => $onlyAccepted,
867 867
    'pagesize' => 20  /*$_SESSION['cdm']['namelist_pagesize'] */);
868 868

  
869
	$taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
870
	/*
871
	 * FIXME the filter for accepted names will be a form element, thus this widget
872
	 * should be generated via form api preferably as block
873
	 */
874
	//$out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
875
	//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
876
	$out .= theme('cdm_listof_taxa', $taxonPager);
877
	return $out;
869
  $taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
870
  /*
871
   * FIXME the filter for accepted names will be a form element, thus this widget
872
   * should be generated via form api preferably as block
873
   */
874
  //$out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
875
  //$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
876
  $out .= theme('cdm_listof_taxa', $taxonPager);
877
  return $out;
878 878
}
879 879

  
880 880
function cdm_dataportal_view_reference($uuid, $arg2 = null){
881
	$reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
882
	return theme('cdm_reference_page', $reference);
881
  $reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
882
  return theme('cdm_reference_page', $reference);
883 883
}
884 884

  
885 885
function cdm_dataportal_view_reference_list($pageNumber){
886
	$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
887
	return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
886
  $referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
887
  return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
888 888
}
889 889

  
890 890
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
891
	$media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
892
	return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
891
  $media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
892
  return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
893 893
}
894 894

  
895 895
function _load_taxonBase(&$taxonBase){
896
	if(isset($taxonBase->uuid)){
897
	    $taxonBase->name = cdm_ws_get(CDM_WS_TAXON, array($taxonBase->uuid, "name"));
898
	    $taxonBase->name->taggedName = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "taggedName"));
899
	    $taxonBase->name->nomenclaturalReference = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "nomenclaturalReference"));
900
	  }
896
  if(isset($taxonBase->uuid)){
897
      $taxonBase->name = cdm_ws_get(CDM_WS_TAXON, array($taxonBase->uuid, "name"));
898
      $taxonBase->name->taggedName = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "taggedName"));
899
      $taxonBase->name->nomenclaturalReference = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "nomenclaturalReference"));
900
    }
901 901
}
902 902

  
903 903
/**
......
927 927
 */
928 928
function _load_polytomousKeySubGraph(&$polytomousKeyNode){
929 929

  
930
	if(!$polytomousKeyNode){
931
		return;
932
	}
933
	if($polytomousKeyNode->class != "PolytomousKeyNode"){
934
		drupal_set_message("_load_polytomousKeySubGraph() invalid type given.", "error");
935
		return;
936
	}
930
  if(!$polytomousKeyNode){
931
    return;
932
  }
933
  if($polytomousKeyNode->class != "PolytomousKeyNode"){
934
    drupal_set_message("_load_polytomousKeySubGraph() invalid type given.", "error");
935
    return;
936
  }
937 937
  if(!is_uuid($polytomousKeyNode->uuid)){
938 938
    drupal_set_message("_load_polytomousKeySubGraph() invalid type given.", "error");
939 939
    return;
940 940
  }
941 941

  
942
	$polytomousKeyNode = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
942
  $polytomousKeyNode = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
943 943

  
944 944
  if(!$polytomousKeyNode){
945
  	//drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
946
  	return;
945
    //drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
946
    return;
947 947
  }
948 948

  
949 949
  // load children
......
992 992
 * @return unknown_type
993 993
 */
994 994
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all', $synonym_uuid = null){
995
	// display the page for the taxon defined by $uuid
996
	set_last_taxon_page_tab(arg(3));
997
	$taxonpage = cdm_dataportal_taxon_view($uuid, $chapter, $synonym_uuid);
998
	return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
995
  // display the page for the taxon defined by $uuid
996
  set_last_taxon_page_tab(arg(3));
997
  $taxonpage = cdm_dataportal_taxon_view($uuid, $chapter, $synonym_uuid);
998
  return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
999 999
}
1000 1000

  
1001 1001
/**
......
1005 1005
 * @return unknown_type
1006 1006
 */
1007 1007
function cdm_dataportal_taxon_view($uuid, $chapter = 'all', $synonym_uuid = null){
1008
	$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1009
	if(!$taxon){
1010
		drupal_set_title(t('Taxon does not exist'));
1011
		return false;
1012
	}
1013

  
1014
	$taxonpage->title = theme('cdm_taxon_page_title', $taxon, $uuid, $synonym_uuid);
1015

  
1016
	// check if the taxon id contained in the currently selected tree
1017
	$taxon_in_current_tree = taxon_in_current_tree($uuid);
1018
	$taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $uuid);
1019
	if(!$taxon_in_current_tree){
1020
		if(count($taxon_nodes) == 0){
1021
			drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained any classification.'
1022
			,'warning');
1023
		} else {
1024
			$trees = '';
1025
			foreach($taxon_nodes as $node){
1026
				$trees .= ($trees?', ':'').'<strong>'.$node->classification->titleCache.'</strong>';
1027

  
1028
			}
1029
			drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained in the currently chosen classification, but in '
1030
			.(count($taxon_nodes) > 1? ' one of these: ' : ' this one: ') . $trees
1031
			, 'warning');
1032
		}
1033
	}
1034

  
1035
	// render the taxon page
1036
	$taxonpage->content = theme('cdm_taxon_page', $taxon, $chapter);
1037

  
1038
	return $taxonpage;
1008
  $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1009
  if(!$taxon){
1010
    drupal_set_title(t('Taxon does not exist'));
1011
    return false;
1012
  }
1013

  
1014
  $taxonpage->title = theme('cdm_taxon_page_title', $taxon, $uuid, $synonym_uuid);
1015

  
1016
  // check if the taxon id contained in the currently selected tree
1017
  $taxon_in_current_tree = taxon_in_current_tree($uuid);
1018
  $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $uuid);
1019
  if(!$taxon_in_current_tree){
1020
    if(count($taxon_nodes) == 0){
1021
      drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained any classification.'
1022
      ,'warning');
1023
    } else {
1024
      $trees = '';
1025
      foreach($taxon_nodes as $node){
1026
        $trees .= ($trees?', ':'').'<strong>'.$node->classification->titleCache.'</strong>';
1027

  
1028
      }
1029
      drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained in the currently chosen classification, but in '
1030
      .(count($taxon_nodes) > 1? ' one of these: ' : ' this one: ') . $trees
1031
      , 'warning');
1032
    }
1033
  }
1034

  
1035
  // render the taxon page
1036
  $taxonpage->content = theme('cdm_taxon_page', $taxon, $chapter);
1037

  
1038
  return $taxonpage;
1039 1039
}
1040 1040

  
1041 1041
/**
......
1046 1046
 * @return The formatted name page as node
1047 1047
 */
1048 1048
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
1049
	$taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
1050
	return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
1049
  $taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
1050
  return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
1051 1051
}
1052 1052

  
1053 1053
/**
......
1057 1057
 * @return the object with the page content and title
1058 1058
 */
1059 1059
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
1060
	//getting the full taxonname object from the server
1061
	$taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1062
	if(!$taxon_name){
1063
		drupal_set_title(t('Taxon name does not exist'));
1064
		return false;
1065
	}
1066
	//searching for all the taxa connected with the taxon name on the tree in used
1067
	$name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1068
	$request_params = array();
1069
	$request_params['query'] = $name_cache;
1070
	$request_params['tree'] = get_taxonomictree_uuid_selected();
1071
	$request_params['doTaxa'] = 1;
1072
	$request_params['doSynonyms'] = 1;
1073
	$request_params['doTaxaByCommonNames'] = 0;
1074
	$request_params['matchMode'] = "EXACT";
1075
	$taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1076

  
1077
	//removing the name where we come from and
1078
	foreach($taxon_pager->records as $k=>&$taxon){
1079
		if($taxon->uuid == $taxon_to_hide_uuid){
1080
			unset($taxon_pager->records[$k]);
1081
		}
1082
	}
1083
	//show the taxa list or go to the singular taxon
1084
	if (sizeof($taxon_pager->records) == 1){ //sigle taxon case
1085
		reset($taxon_pager->records);
1086
		$first_key = key($taxon_pager->records);
1087
		if($taxon_pager->records[$first_key]->class != "Taxon"){
1088
			$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($taxon_pager->records[$first_key]->uuid, get_taxonomictree_uuid_selected()));
1089
			if($synonym_uuid){
1090
				drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
1091
			}else{
1092
				drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid);
1093
			}
1094
		}else{
1095
			if($synonym_uuid){
1096
				drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid . '/synonymy',
1060
  //getting the full taxonname object from the server
1061
  $taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1062
  if(!$taxon_name){
1063
    drupal_set_title(t('Taxon name does not exist'));
1064
    return false;
1065
  }
1066
  //searching for all the taxa connected with the taxon name on the tree in used
1067
  $name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1068
  $request_params = array();
1069
  $request_params['query'] = $name_cache;
1070
  $request_params['tree'] = get_taxonomictree_uuid_selected();
1071
  $request_params['doTaxa'] = 1;
1072
  $request_params['doSynonyms'] = 1;
1073
  $request_params['doTaxaByCommonNames'] = 0;
1074
  $request_params['matchMode'] = "EXACT";
1075
  $taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1076

  
1077
  //removing the name where we come from and
1078
  foreach($taxon_pager->records as $k=>&$taxon){
1079
    if($taxon->uuid == $taxon_to_hide_uuid){
1080
      unset($taxon_pager->records[$k]);
1081
    }
1082
  }
1083
  //show the taxa list or go to the singular taxon
1084
  if (sizeof($taxon_pager->records) == 1){ //sigle taxon case
1085
    reset($taxon_pager->records);
1086
    $first_key = key($taxon_pager->records);
1087
    if($taxon_pager->records[$first_key]->class != "Taxon"){
1088
      $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($taxon_pager->records[$first_key]->uuid, get_taxonomictree_uuid_selected()));
1089
      if($synonym_uuid){
1090
        drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
1091
      }else{
1092
        drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid);
1093
      }
1094
    }else{
1095
      if($synonym_uuid){
1096
        drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid . '/synonymy',
1097 1097
                      'highlite=' . $synonym_uuid);
1098
			}else{
1099
				drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid);
1100
			}
1101
			//drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid);
1102
		}
1103
	}else{ //more than one taxa case
1104
		$taxon_name_page->title = theme('cdm_name_page_title', $taxon_name);
1105
		if($taxon_pager->records){
1106
			$taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, false);
1107
		}else{
1108
			$taxon_name_page->content = 'This name has no taxa';
1109
		}
1110
		return $taxon_name_page;
1111
	}
1098
      }else{
1099
        drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid);
1100
      }
1101
      //drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid);
1102
    }
1103
  }else{ //more than one taxa case
1104
    $taxon_name_page->title = theme('cdm_name_page_title', $taxon_name);
1105
    if($taxon_pager->records){
1106
      $taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, false);
1107
    }else{
1108
      $taxon_name_page->content = 'This name has no taxa';
1109
    }
1110
    return $taxon_name_page;
1111
  }
1112 1112
}
1113 1113

  
1114 1114
function cdm_dataportal_view_search_advanced(){
1115 1115

  
1116
	drupal_set_title(t('Advanced search'));
1116
  drupal_set_title(t('Advanced search'));
1117 1117

  
1118
	$searchForm = cdm_dataportal_search_taxon_form(true);
1118
  $searchForm = cdm_dataportal_search_taxon_form(true);
1119 1119

  
1120
	return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1120
  return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1121 1121

  
1122 1122
}
1123 1123

  
......
1131 1131
 */
1132 1132
function cdm_dataportal_view_search_taxon(){
1133 1133

  
1134
	$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
1134
  $_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
1135 1135

  
1136
	$request_params = cdm_dataportal_search_form_request();
1137
	$taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1136
  $request_params = cdm_dataportal_search_form_request();
1137
  $taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1138 1138

  
1139
	$search_params = $_REQUEST;
1140
	unset($search_params['q']);
1141
	return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
1139
  $search_params = $_REQUEST;
1140
  unset($search_params['q']);
1141
  return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
1142 1142
}
1143 1143

  
1144 1144

  
1145 1145
function cdm_view_xml2json(){
1146
	$file = arg(2);
1147
	$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
1148
	return  xml2json::transformXmlStringToJson($datastr);
1146
  $file = arg(2);
1147
  $datastr = get_content(variable_get('cdm_webservice_url', '').$file);
1148
  return  xml2json::transformXmlStringToJson($datastr);
1149 1149
}
1150 1150

  
1151 1151
/* ====================== other functions ====================== */
......
1158 1158
 * @return the URL
1159 1159
 */
1160 1160
function path_to_taxon($uuid, $no_tab = false){
1161
	$tab = get_default_taxon_tab();
1162
	$values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
1163

  
1164
	if(!$uuid) return false;
1165

  
1166
	if (!$tab){
1167
		return 'cdm_dataportal/taxon/'.$uuid;
1168
	}elseif(get_last_taxon_page_tab() &&
1169
	   $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]){
1170
		return 'cdm_dataportal/taxon/'.$uuid . '/' . get_last_taxon_page_tab();
1171
	} else {
1172
		return 'cdm_dataportal/taxon/'.$uuid . '/' . strtolower($tab);
1173
	}
1161
  $tab = get_default_taxon_tab();
1162
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
1163

  
1164
  if(!$uuid) return false;
1165

  
1166
  if (!$tab){
1167
    return 'cdm_dataportal/taxon/'.$uuid;
1168
  }elseif(get_last_taxon_page_tab() &&
1169
     $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]){
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff