Index: extensions/lmt/lmt_aip.class.inc.php
===================================================================
--- extensions/lmt/lmt_aip.class.inc.php	(revision 3412)
+++ extensions/lmt/lmt_aip.class.inc.php	(revision 3666)
@@ -260,5 +260,13 @@
     if(isset($_POST["submit_add_to_caddie"]) || isset($_POST["submit_replace_caddie"]))
     {
-      $sql="REPLACE INTO ".CADDIE_TABLE." SELECT '".$user['id']."', id FROM ".IMAGES_TABLE." WHERE id IN (".implode(",", $img_ids).");";
+
+      $sql="REPLACE INTO ".CADDIE_TABLE." 
+        SELECT '".$user['id']."', it.id FROM ".IMAGES_TABLE." it, ".$this->tables["images"]." lmti  
+        WHERE it.id = lmti.image_id";
+      if($_REQUEST['filter']!="")
+      {
+        $sql.=" AND lmti.licence_type='".$_REQUEST['filter']."'";
+      }
+
       $result=pwg_query($sql);
       if((!$results)||(!$result))
@@ -784,4 +792,26 @@
   }
 
+  protected function make_image_data($tmp)
+  {
+    $tmp2=array();
+    for($i=0;$i<count($tmp['id']);$i++)
+    {
+      $tmp2[]=array(
+        'id' => $tmp['id'][$i],
+        'name' => $tmp['name'][$i],
+        'type' => $tmp['type'][$i],
+        'plinks' => $tmp['plinks'][$i],
+        'link'=> make_index_url(
+                          array(
+                            'category' => array(
+                              'id' => $tmp['id'][$i],
+                              'name' => $tmp['name'][$i],
+                              'permalink' => $tmp['plinks'][$i])
+                          )
+                        )
+      );
+    }
+    return($tmp2);
+  }
 
   /* ---------------------------------------------------------------------------
@@ -821,7 +851,15 @@
     $img_ids=array();
     $img_liste = array();
-    $sql="SELECT SQL_CALC_FOUND_ROWS lmti.*, img.file, img.path, img.tn_ext, cat.id as catid, cat.name as catname, cat.permalink, lmtla.text1, lmtla.text2   
-          FROM ".$this->tables["images"]." lmti LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla ON lmtla.id = lmti.author_id, 
-               ".IMAGES_TABLE." img LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON img.storage_category_id = cat.id
+    $sql="SELECT SQL_CALC_FOUND_ROWS lmti.*, img.file, img.path, img.tn_ext, 
+                  GROUP_CONCAT(cat.id) AS catid, 
+                  GROUP_CONCAT(CASE WHEN cat.name IS NULL THEN '' ELSE cat.name END SEPARATOR '@sep@') AS catname,
+                  GROUP_CONCAT(CASE WHEN cat.permalink IS NULL THEN '' ELSE cat.permalink END SEPARATOR '@sep@') AS catpermalink,
+                  GROUP_CONCAT(CASE WHEN cat.dir IS NULL THEN 'V' ELSE 'P' END) AS cattype,
+                  lmtla.text1, lmtla.text2   
+          FROM ".$this->tables["images"]." lmti 
+                  LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla ON lmtla.id = lmti.author_id, 
+               ".IMAGES_TABLE." img 
+                  LEFT OUTER JOIN ".IMAGE_CATEGORY_TABLE." imgcat ON img.id = imgcat.image_id
+                  LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON imgcat.category_id = cat.id
           WHERE lmti.image_id = img.id ";
     if($_REQUEST['filter']!="")
@@ -830,6 +868,6 @@
     }
 
-    $sql.=" ORDER BY cat.id, img.id ";
-  
+    $sql.=" GROUP BY lmti.image_id ORDER BY cat.id, img.id ";
+
     if($this->my_config['lmt_list_maxitems']>0)
     {
@@ -846,4 +884,13 @@
         preg_match("/(.*)\./i", $filenfo["basename"], $tmp);
         $filenfo['filename'] = $tmp[1];
+
+        $tmp=array(
+              'id'=>explode(',',$row['catid']),
+              'name'=>explode('@sep@',$row['catname']),
+              'type'=>explode(',',$row['cattype']),
+              'plinks'=>explode('@sep@',$row['catpermalink']),
+              'link'=>array()
+            );
+        $tmpcat=$this->make_image_data($tmp);
 
         $img_ids[]=$row['image_id'];
@@ -855,20 +902,12 @@
           'aut_text2' => $row['text2'],
           'file' => $row['file'],
-          'catname' => $row['catname'],
-          'catlink' => make_index_url(
-                          array(
-                            'category' => array(
-                              'id' => $row['catid'],
-                              'name' => $row['catname'],
-                              'permalink' => $row['permalink'])
-                          )
-                        ),
+          'cat' => $tmpcat,
           'imglink' => make_picture_url(
                           array(
                             'image_id' => $row['image_id'],
                             'category' => array(
-                              'id' => $row['catid'],
-                              'name' => $row['catname'],
-                              'permalink' => $row['permalink'])
+                              'id' => $tmp['id'][0],
+                              'name' => $tmp['name'][0],
+                              'permalink' => $tmp['plinks'][0])
                           )
                         ),
@@ -916,14 +955,19 @@
 
     $img_liste = array();
-    $sql="SELECT SQL_CALC_FOUND_ROWS img.id as image_id, img.file, img.path, img.tn_ext, cat.id as catid, cat.name as catname, cat.permalink,
+    $sql="SELECT SQL_CALC_FOUND_ROWS img.id as image_id, img.file, img.path, img.tn_ext, 
+                  GROUP_CONCAT(cat.id) AS catid, 
+                  GROUP_CONCAT(CASE WHEN cat.name IS NULL THEN '' ELSE cat.name END SEPARATOR '@sep@') AS catname,
+                  GROUP_CONCAT(CASE WHEN cat.permalink IS NULL THEN '' ELSE cat.permalink END SEPARATOR '@sep@') AS catpermalink,
+                  GROUP_CONCAT(CASE WHEN cat.dir IS NULL THEN 'V' ELSE 'P' END) AS cattype,
                  lmti.licence_type, lmtla.text1, lmtla.text2 
-          FROM ".CADDIE_TABLE." caddie, (".IMAGES_TABLE." img 
-            LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON img.storage_category_id = cat.id)
-            LEFT OUTER JOIN ".$this->tables["images"]." AS lmti
-              ON img.id = lmti.image_id  
-            LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla 
-              ON lmtla.id = lmti.author_id
+          FROM ".CADDIE_TABLE." caddie, 
+              (".IMAGES_TABLE." img 
+                  LEFT OUTER JOIN ".IMAGE_CATEGORY_TABLE." imgcat ON img.id = imgcat.image_id
+                  LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON imgcat.category_id = cat.id)
+                LEFT OUTER JOIN ".$this->tables["images"]." AS lmti ON img.id = lmti.image_id  
+                LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla  ON lmtla.id = lmti.author_id
           WHERE img.id = caddie.element_id
             AND caddie.user_id = '".$user['id']."'
+          GROUP BY img.id
           ORDER BY cat.id, img.id ";
 
@@ -943,4 +987,13 @@
         preg_match("/(.*)\./i", $filenfo["basename"], $tmp);
         $filenfo['filename'] = $tmp[1];
+
+        $tmp=array(
+              'id'=>explode(',',$row['catid']),
+              'name'=>explode('@sep@',$row['catname']),
+              'type'=>explode(',',$row['cattype']),
+              'plinks'=>explode('@sep@',$row['catpermalink']),
+              'link'=>array()
+            );
+        $tmpcat=$this->make_image_data($tmp);
 
         $img_liste[]=array(
@@ -951,15 +1004,13 @@
           'aut_text2' => $row['text2'],
           'file' => $row['file'],
-          'catname' => $row['catname'],
-          'catlink' => make_index_url(
+          'cat' => $tmpcat,
+          'imglink' => make_picture_url(
                           array(
+                            'image_id' => $row['image_id'],
                             'category' => array(
-                              'id' => $row['catid'],
-                              'name' => $row['catname'],
-                              'permalink' => $row['permalink'])
+                              'id' => $tmp['id'][0],
+                              'name' => $tmp['name'][0],
+                              'permalink' => $tmp['plinks'][0])
                           )
-                        ),
-          'imglink' => make_picture_url(
-                          array('image_id' => $row['image_id'])
                         ),
           'thumb' => $filenfo["dirname"]."/thumbnail/".$conf["prefix_thumbnail"].$filenfo["filename"].".".$row["tn_ext"]
