commit 81df545fae5f086f2adae8daff5b433574018e8a
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Wed Jun 25 16:03:19 2008 +0000

diff --git a/modules/cdm_dataportal/cdm_api/cdm_api.module b/modules/cdm_dataportal/cdm_api/cdm_api.module
index 608401cc..56f659d8 100644
--- a/modules/cdm_dataportal/cdm_api/cdm_api.module
+++ b/modules/cdm_dataportal/cdm_api/cdm_api.module
@@ -174,10 +174,11 @@ function cdm_api_cron() {
  * @return String of HTML 
  */
 function cdm_taggedtext2html(array &$taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()){
-  $out = '';
+   $out = '';
+   $i = 0;
    foreach($taggedtxt as $tt){
-     if(!in_array($tt->type, $skiptags)){
-      $out .= (strlen($out) > 0 ? $glue : '').'<'.$tag.' class="'.$tt->type.'">'.$tt->text.'</'.$tag.'>';
+     if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
+      $out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.' class="'.$tt->type.'">'.$tt->text.'</'.$tag.'>';
      }
    }
    return $out;
@@ -562,7 +563,7 @@ define('CDM_WS_TYPE_DESIGNATIONS', 'types');
  * parameter taxonUuid. If the taxon specified by taxonUuid is itself the
  * accepted taxon, this one will be returned.
  */
-define('CDM_WS_ACCEPTED_TAXON', 'accepted');
+define('CDM_WS_ACCEPTED_TAXON', 'simple/taxon/acceptedfor');
 
 /**
  * Web Service Arguments: {secUuid}
diff --git a/modules/cdm_dataportal/cdm_dataportal.css b/modules/cdm_dataportal/cdm_dataportal.css
index 11dfd404..01757c79 100644
--- a/modules/cdm_dataportal/cdm_dataportal.css
+++ b/modules/cdm_dataportal/cdm_dataportal.css
@@ -9,7 +9,7 @@ div.debug{
   overflow: auto;
 }
 
-.taxonname .name{
+.name{
   font-style: italic;
 }
 
diff --git a/modules/cdm_dataportal/cdm_dataportal.module b/modules/cdm_dataportal/cdm_dataportal.module
index 31085da7..61f6709a 100644
--- a/modules/cdm_dataportal/cdm_dataportal.module
+++ b/modules/cdm_dataportal/cdm_dataportal.module
@@ -226,12 +226,25 @@ function cdm_dataportal_search_taxon_form(){
     '#attributes' => array('title' => t('Enter the name or part of a name you wish to search for.')),
     '#default_value' => (isset($_SESSION['cdm']['search']['queryString']) ? $_SESSION['cdm']['search']['queryString'] : ''),
   );
-  $form['onlyAccepted'] = array(
+  $form['mode'] =  array(
+    '#type' => 'select',
+    '#title' => t('Search Mode'),
+    '#options' => array(
+        'EXACT' => t('Exact'),
+        'BEGINNING' => t('Beginning'),
+        'ANYWHERE' => t('Anywhere')
+        ),
+    '#description'   => t('* can always be used as wildcard'),
+    '#default_value' => (isset($_SESSION['cdm']['search']['mode']) ? $_SESSION['cdm']['search']['mode'] : 'start'),
+  );
+  
+  /*$form['onlyAccepted'] = array(
     '#type' => 'checkbox',
     '#title' => t('Only Accepted'),
     '#attributes' => array('title' => t('Search only for taxa which are accepted by the current treatment.')),
     '#default_value' => isset($_SESSION['cdm']['search']['onlyAccepted']) && $_SESSION['cdm']['search']['onlyAccepted'],
   );
+  */
   /*
   $form['vernacular'] = array(
     '#type' => 'checkbox',
@@ -271,7 +284,7 @@ function cdm_dataportal_search_taxon_form(){
   return $form;
 }
 
-
+//TODO is this function REACHABLE and thus in use??
 function cdm_dataportal_search_process($form) {
   unset($form['form_id']);
   unset($form['form_token']);
@@ -284,17 +297,18 @@ function cdm_dataportal_search_process($form) {
  */
 function cdm_dataportal_search_form_request(){
   // keys map $REQUEST Keys values are optional default parameters if not null
-  static $search_form_params = array('queryString'=>null, 'onlyAccepted' =>'0', 'page'=>null);
+  static $search_form_params = array('queryString'=>null, 'onlyAccepted' =>'0', 'page'=>null,  'pagesize'=>15, 'mode'=>null);
   
   $form_params = array();
   foreach($search_form_params as $key=>$default ){
     $form_params[$key] = ( isset($_REQUEST[$key]) && $_REQUEST[$key] != '' ? $_REQUEST[$key] : $default);
   }
+  $_SESSION['cdm']['search'] = $form_params;
   return $form_params;
 }
   
 
-/*
+/* UNREACHABLE since action of form directly links to view
 function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
   
   $_SESSION['cdm']['search'] = $form_values;
@@ -470,8 +484,6 @@ function cdm_dataportal_view_search_taxon(){
   
   $request_params = cdm_dataportal_search_form_request();
   $sw_params = array_replace_key($request_params, array('queryString'=> 10 ));
-  //FIXME remove debug code:
-  $sw_params['page'] = '1'; // DEBUG code
   $resultPageSTO = cdm_ws_get(CDM_WS_FIND_TAXA, $sw_params);
   $resultPageSTO->pageNumber = $request_params['page'];
   return theme('cdm_search_results', $resultPageSTO, 'cdm_dataportal/search/taxon', $request_params);
@@ -576,6 +588,11 @@ function _cdm_dataportal_currentSecRef_array(){
   return  $_SESSION['cdm']['currentSecRef'];
 }
 
+function _cdm_dataportal_acceptetByCurrentView($taxonTO){
+  $current_secref = _cdm_dataportal_currentSecRef_array();
+  
+  return $current_secref->uuid == $taxonTO->secuuid && $taxonTO->accepted;
+}
 
 /**
  * @param $str the string to truncate
diff --git a/modules/cdm_dataportal/cdm_dataportal.theme.php b/modules/cdm_dataportal/cdm_dataportal.theme.php
index 23e95178..610774f6 100644
--- a/modules/cdm_dataportal/cdm_dataportal.theme.php
+++ b/modules/cdm_dataportal/cdm_dataportal.theme.php
@@ -49,7 +49,7 @@ function tagNameParts($name, $numOfNameTokens){
 function theme_cdm_name($nameTO, $displayNomRef = true){
   
     //TODO: - take the different subtypes of eu.etaxonomy.cdm.model.name.TaxonNameBase into account?
-    $class = 'name'; //($nameTO->secUuid ? 'taxon' : 'taxonname');  
+    $class = ''; //name'; //($nameTO->secUuid ? 'taxon' : 'taxonname');  
   
 
     if(!$nameTO){
@@ -57,11 +57,12 @@ function theme_cdm_name($nameTO, $displayNomRef = true){
     }
 
     $hasNomRef = $nameTO->nomenclaturalReference->fullCitation;
+    //FIXME class="'.$class.' below seems to be unused
     if(!$nameTO->taggedName || !count($nameTO->taggedName)){
       $out .= '<span class="'.$class.'">'.$nameTO->fullname.'</span>';
     } else {
       $skip = $hasNomRef ? array('reference') : array();
-      $out .= '<span class="'.$class.'">'.cdm_taggedtext2html($nameTO->taggedName, 'span', '', $skip).'</span>';
+      $out .= '<span class="'.$class.'">'.cdm_taggedtext2html($nameTO->taggedName, 'span', ' ', $skip).'</span>';
     }
         
     if($displayNomRef && $hasNomRef){
@@ -108,7 +109,7 @@ function theme_cdm_taxon($taxonTO, $displayNomRef = true, $noSecundum = true, $e
 	  //TODO:   .$ptaxon->namePhrase; 
 	  
     if($enclosingTag){
-        $out = '<'.$enclosingTag.' class="taxon'.($taxonTO->isAccepted === true ? ' accepted':'').'">'.$out.'</'.$enclosingTag.'>';
+        $out = '<'.$enclosingTag.' class="taxon'.($taxonTO->accepted === true ? ' accepted':'').'">'.$out.'</'.$enclosingTag.'>';
     }
 
     return $out;    
@@ -119,13 +120,13 @@ function theme_cdm_taxon($taxonTO, $displayNomRef = true, $noSecundum = true, $e
  *
  * @param TaxonTO $taxon
  */
-function theme_cdm_taxon_link($taxonTO, $fragment = NULL, $showNomRef = false){
+function theme_cdm_taxon_link($taxonTO, $fragment = NULL, $showNomRef = true){
     
     if($fragment){
         $fragment = '#'.$fragment;
     }
 
-    if(!$taxon->isAccepted) { 
+    if(!$taxon->accepted) { 
         $out = 'ERROR: theme_cdm_taxon_link() - taxon is not accepted';
     }
     
@@ -133,7 +134,7 @@ function theme_cdm_taxon_link($taxonTO, $fragment = NULL, $showNomRef = false){
     $out = l($name_html, cdm_dataportal_taxon_path($taxonTO->uuid), array('class'=>'accepted'), '', $fragment, FALSE, TRUE);
     
     if($showNomRef){
-       $out .=' '.theme('cdm_nomRef', $taxonTO);
+       $out .=' '.theme('cdm_nomenclaturalReferenceSTO', $taxonTO->name->nomenclaturalReference);
     }
 	
 	return $out;
@@ -214,12 +215,11 @@ function theme_cdm_listof_taxa($taxonSTOs){
   drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
   
   $out = '<ul class="cdm_names" style="background-image: none;">';
-  $currentSecRef = _cdm_dataportal_currentSecRef_array();
   foreach($taxonSTOs as $taxon){
-    if($taxon->isAccepted && $taxon->secUuid == $currentSecRef['uuid']){
+    if(_cdm_dataportal_acceptetByCurrentView($taxon)){
       $out .= '<li>'.theme('cdm_taxon_link', $taxon).'</li>';
     } else {
-      $out .= theme('cdm_dynabox', theme('cdm_name', $taxon->name), cdm_compose_url(CDM_WS_ACCEPTED_TAXON, array($taxon->uuid)), 'cdm_taxon_link');
+      $out .= theme('cdm_dynabox', theme('cdm_name', $taxon->name), cdm_compose_url(CDM_WS_ACCEPTED_TAXON, array($taxon->uuid)), 'cdm_listof_taxa');
     }
   }
   $out .= '</ul>';
@@ -400,14 +400,15 @@ function theme_cdm_taxonRelations($TaxonRelationshipTOs){
   foreach($TaxonRelationshipTOs as $taxonRelation){
     if(true || $taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR ){
       
-      $sensu_reference = cdm_ws_get(CDM_WS_SIMPLE_REFERENCE ,$taxonRelation->secUuid);
-      $name = $taxonRelation->name->fullname;
+      $sensu_reference_list = cdm_ws_get(CDM_WS_SIMPLE_REFERENCE ,$taxonRelation->taxon->secUuid);
+      $sensu_reference = $sensu_reference_list[0];
+      $name = $taxonRelation->taxon->name->fullname;
       if(!isset($misapplied[$name])){
-        $misapplied[$name] = '<span class="misapplied">'.theme('cdm_related_taxon',$taxonRelation, UUID_MISAPPLIED_NAME_FOR, false).'</span>';
+        $misapplied[$name] = '<span class="misapplied">'.theme('cdm_related_taxon',$taxonRelation->taxon, UUID_MISAPPLIED_NAME_FOR, false).'</span>';
       } else {
         $misapplied[$name] .= ';';
       }
-      $misapplied[$name] .= '&nbsp;<span class="sensu cluetip no-print" title="|sensu '.theme('cdm_fullreference',$sensu_reference ).'|">sensu '
+      $misapplied[$name] .= '&nbsp;<span class="sensu cluetip no-print" title="|sensu '.htmlspecialchars(theme('cdm_fullreference',$sensu_reference )).'|">sensu '
       .$sensu_reference->authorship.'</span>'
       .'<span class="reference only-print">sensu '.theme('cdm_fullreference',$sensu_reference ).'</span>'
       ;
@@ -428,14 +429,14 @@ function theme_cdm_typedesignations($specimenTypeDesignations, $nameTypeDesignat
   $out = '<ul class="typeDesignations">';
 
   foreach($nameTypeDesignations as $ntd){
-    $out .= '<li class="nameTypeDesignation"><span class="status">'.$ntd->status->value.'</span> - '.theme('cdm_name', $ntd->typeSpecies, false);
+    $out .= '<li class="nameTypeDesignation"><span class="status">'.$ntd->status->text.'</span> - '.theme('cdm_name', $ntd->typeSpecies, false);
     $out .= theme('cdm_typedesignations', $ntd->typeSpecimens);
     $out .= '</li>';
   }    
   
   foreach($specimenTypeDesignations as $std){
     $out .= '<li class="specimenTypeDesignation">';
-    $out .= '<span class="status">'.$std->status->value.'</span> - '.$std->typeSpecimen->specimenLabel;
+    $out .= '<span class="status">'.$std->status->text.'</span> - '.$std->typeSpecimen->specimenLabel;
     $out .= theme('cdm_specimen', $std->typeSpecimen);
     $out .= '</li>';
   }
@@ -451,10 +452,11 @@ function theme_cdm_specimen($specimen){
   //$specimen->specimenLabel
   //$specimen->uuid
   
+  
   _add_js_thickbox();
   
   $out = '';
-  if(is_array($specimen->mediaURI)){
+  if(isset($specimen->media[0])){
     
     $image_url = drupal_get_path('module', 'cdm_dataportal').'/images/external_link.gif';
     // thickbox has problems reading the first url parameter, so a litte hack is needed here:
@@ -467,35 +469,45 @@ function theme_cdm_specimen($specimen){
     $media_row = '<tr class="media_data">';
     $meta_row = '<tr class="meta_data">';
     
-    foreach($specimen->mediaURI as $uri){
-      
-      // get media uri conversion rules if the module is installed and activated
-      if(module_exists('cdm_mediauri')){
-        $muris = cdm_mediauri_conversion($uri->value);
-      }
-      // --- handle media preview rules
-      if(isset($muris['preview'])){    
+    foreach($specimen->media as $media){
+      foreach($media->representations as $representation){
         
-        $a_child = '<img src="'.$muris['preview']['uri'].'" class="preview"'
-          .($muris['preview']['size_x'] ? 'width="'.$muris['preview']['size_x'].'"' : '')
-          .($muris['preview']['size_y'] ? 'width="'.$muris['preview']['size_y'].'"' : '')
-          .'/>';
-      } else {
-        $a_child = '<img src="'.$image_url.'" />';
-      }
-      
-      // --- handle web application rules
-      $webapp = '';
-      if(isset($muris['webapp'])){
-        if($muris['webapp']['embed_html']){
-          // embed in same page
-          $webapp = $muris['webapp']['embed_html'];  
-        } else {
-          $webapp = l(t('web application'), $muris['webapp']['uri']);            
-        }
-      }
-      $media_row .= '<td><a href="'.$uri->value.'" target="'.$uri->uuid.'">'.$a_child.'</a></td>';
-      $meta_row .= '<td><span class="label">'.check_plain($specimen->specimenLabel).'</span><div class="webapp">'.$webapp.'</div></td>';
+        //TODO this this is PART 2/2 of a HACK - select preferred representation by mimetype and size
+        //      
+        if(true || $representation->mimeType == 'image/jpeg'){
+          foreach($representation->representationParts as $part){
+            // get media uri conversion rules if the module is installed and activated
+            if(module_exists('cdm_mediauri')){
+              $muris = cdm_mediauri_conversion($part->uri);
+            }
+            // --- handle media preview rules
+            if(isset($muris['preview'])){    
+              
+              $a_child = '<img src="'.$muris['preview']['uri'].'" class="preview" '
+                .($muris['preview']['size_x'] ? 'width="'.$muris['preview']['size_x'].'"' : '')
+                .($muris['preview']['size_y'] ? 'width="'.$muris['preview']['size_y'].'"' : '')
+                .'/>';
+            } else {
+              $a_child = '<img src="'.$image_url.'" />';
+            }
+            
+            // --- handle web application rules
+            $webapp = '';
+            if(isset($muris['webapp'])){
+              if($muris['webapp']['embed_html']){
+                // embed in same page
+                $webapp = $muris['webapp']['embed_html'];  
+              } else {
+                $webapp = l(t('web application'), $muris['webapp']['uri']);            
+              }
+            }
+            $media_row .= '<td><a href="'.$part->uri.'" target="'.$part->uuid.'">'.$a_child.'</a></td>';
+            $meta_row .= '<td><span class="label">'.check_plain($specimen->specimenLabel).'</span><div class="webapp">'.$webapp.'</div></td>';
+          } // END parts
+          //TODO this is PART 2/2 of a hack
+          break;
+        } // END representations
+      } // END media
     }
     $out .= $media_row.'</tr>';
     $out .= $meta_row.'</tr>';
diff --git a/modules/cdm_dataportal/cdm_mediauri/cdm_mediauri.module b/modules/cdm_dataportal/cdm_mediauri/cdm_mediauri.module
index 170859cc..897a4ddd 100644
--- a/modules/cdm_dataportal/cdm_mediauri/cdm_mediauri.module
+++ b/modules/cdm_dataportal/cdm_mediauri/cdm_mediauri.module
@@ -4,6 +4,7 @@
 /*
  * @file
  * cdm_mediauri.module
+ * 
  *
  * Copyright (C) 2007 EDIT
  * European Distributed Institute of Taxonomy
diff --git a/modules/cdm_dataportal/cdm_taxontree/cdm_taxontree.module b/modules/cdm_dataportal/cdm_taxontree/cdm_taxontree.module
index 3f1dd9c6..6567ad78 100644
--- a/modules/cdm_dataportal/cdm_taxontree/cdm_taxontree.module
+++ b/modules/cdm_dataportal/cdm_taxontree/cdm_taxontree.module
@@ -26,7 +26,7 @@ function cdm_taxontree_menu($may_cache) {
     );
     
      $items[] = array(
-      //'path' => 'cdm_dataportal/filter', 
+
       'path' => 'cdm_taxontree/filter', 
       'callback' => 'cdm_taxontree_view_filter',
       'access' => true,
@@ -34,7 +34,6 @@ function cdm_taxontree_menu($may_cache) {
     );
     
     $items[] = array(
-      //'path' => 'cdm_dataportal/filter', 
       'path' => 'cdm_taxontree/taxonomy/children', 
       'callback' => 'cdm_taxontree_taxonomy_children',
       'access' => true,
@@ -706,7 +705,7 @@ function theme_cdm_taxontree_node_reference(&$node){
  * @param unknown_type $taxonUuid
  * @return unknown
  */
-function cdm_dataportal_view_filter($op, $taxonUuid = null){
+function cdm_taxontree_view_filter($op, $taxonUuid = null){
   
   if(!isset($_SESSION['cdm']['filters'])){
     $_SESSION['cdm']['filters'] = array();
@@ -714,13 +713,13 @@ function cdm_dataportal_view_filter($op, $taxonUuid = null){
   if($taxonUuid || $op == 'list'){
     switch($op){
       case 'add':
-        cdm_dataportal_filters_add($taxonUuid);
+        cdm_taxontree_filters_add($taxonUuid);
         break;
       case 'remove':
-        cdm_dataportal_filters_remove($taxonUuid);
+        cdm_taxontree_filters_remove($taxonUuid);
         break;
       case 'list':
-        //TODO put in theme!!!
+        //TODO put in cdm_dataportal_theme to decouple both modules by this!!!
         $out = '<ul>';
         foreach($_SESSION['cdm']['filters'] as $uuid=>$node){
           $out .= '<li>'.cdm_dataportal_shortname_of($node).' '.l('[x]', 'cdm_dataportal/filter/remove/'.$uuid, array(), drupal_get_destination()).'</li>';
