Index: extensions/lmt/lmt_aip.class.inc.php
===================================================================
--- extensions/lmt/lmt_aip.class.inc.php	(revision 6703)
+++ extensions/lmt/lmt_aip.class.inc.php	(revision 7560)
@@ -17,11 +17,10 @@
 include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTranslate.class.inc.php');
 include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php');
+include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
 include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/genericjs.class.inc.php');
-include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCPagesNavigation.class.inc.php');
 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
 
 class LMT_AIP extends LMT_root
 {
-  protected $google_translate;
   protected $tabsheet;
 
@@ -42,4 +41,7 @@
                           l10n('lmt_manageaut'),
                           $this->getAdminLink()."&amp;f_tabsheet=manageaut");
+    $this->tabsheet->add('search',
+                          l10n('lmt_search'),
+                          $this->getAdminLink()."&amp;f_tabsheet=search");
     $this->tabsheet->add('config',
                           l10n('lmt_config'),
@@ -48,20 +50,8 @@
                           l10n('lmt_help'),
                           $this->getAdminLink()."&amp;f_tabsheet=help");
-
-
-    // don't create the google_translate object everytime, otherwise google's js
-    // code is always included in the header even if translation functionalities
-    // aren't needed
-    // translation is needed only if we are in a ajax request
-    /*if((isset($_POST['fmypolls_gomodify_translation'])||isset($_POST['fmypolls_goadd_translation'])))
-    {
-      $this->google_translate = new GPCTranslate();
-    }
-    */
   }
 
   public function __destruct()
   {
-    unset($this->google_translate);
     unset($this->tabsheet);
     parent::__destruct();
@@ -74,6 +64,15 @@
   {
     parent::initEvents();
+
+    if(isset($_REQUEST['f_tabsheet']) and $_REQUEST['f_tabsheet']=='search')
+    {
+      // load request builder JS only on the search page
+      GPCRequestBuilder::loadJSandCSS();
+    }
+
     add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS'));
     add_event_handler('loc_end_page_header', array(&$this->css_icn, 'applyCSS'));
+
+    GPCCss::applyGpcCss();
   }
 
@@ -84,6 +83,4 @@
   {
     global $template;
-
-    $this->return_ajax_content();
 
     $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/lmt_admin.tpl");
@@ -108,4 +105,7 @@
         $this->display_managedoc_page();
         break;
+      case 'search':
+        $this->displaySearch();
+        break;
       case 'help':
         $this->display_help_page();
@@ -127,29 +127,4 @@
     $template->assign('plugin', $template_plugin);
     $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
-  }
-
-
-  /*
-    return ajax content
-  */
-  protected function return_ajax_content()
-  {
-    global $ajax, $template;
-
-    if(isset($_REQUEST['ajaxfct']))
-    {
-      //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']);
-      $result="<p class='errors'>An error has occured</p>";
-      switch($_REQUEST['ajaxfct'])
-      {
-        case 'img_list':
-          $result=$this->ajax_img_list($_REQUEST['numpage']);
-          break;
-        case 'manage_list':
-          $result=$this->ajax_manage_list($_REQUEST['numpage']);
-          break;
-      }
-      GPCAjax::returnResult($result);
-    }
   }
 
@@ -233,9 +208,9 @@
 
     $datas=array(
-      "LMT_AJAX_URL_LIST" =>  $this->getAdminLink().'&ajaxfct=img_list&numpage='
+      "LMT_AJAX_URL_LIST" =>  $this->getAdminLink('ajax')
     );
 
     $filter_list_selected = '';
-    $filter_list_values = array_slice($this->licences,0,count($this->licences)-1);
+    $filter_list_values = array_slice(LMT_root::$licences,0,count(LMT_root::$licences)-1);
     $filter_list_labels = array();
     foreach($filter_list_values as $key=>$val)
@@ -369,5 +344,5 @@
 
     $datas=array(
-      "LMT_AJAX_URL_LIST" =>  $this->getAdminLink().'&ajaxfct=manage_list&numpage='
+      "LMT_AJAX_URL_LIST" =>  $this->getAdminLink('ajax')
     );
 
@@ -395,5 +370,5 @@
 
     $licences_list_values = array();
-    $licences_list_values = $this->licences;
+    $licences_list_values = self::$licences;
     $licences_list_labels = array();
     foreach($licences_list_values as $key=>$val)
@@ -459,5 +434,5 @@
 
     $datas['lmt_redirect_urls']=array();
-    $lmt_licence_default_values = array_slice($this->licences,0,count($this->licences)-1);
+    $lmt_licence_default_values = array_slice(self::$licences,0,count(self::$licences)-1);
     $lmt_licence_default_labels = array();
 
@@ -540,4 +515,21 @@
 
 
+  /**
+   * display the search page
+   *
+   */
+  protected function displaySearch()
+  {
+    global $template;
+
+    $template->set_filename('body_page',
+                dirname($this->getFileLocation()).'/admin/lmt_search.tpl');
+
+    $template->assign('lmt_search_page', GPCRequestBuilder::displaySearchPage($this->getPluginName()));
+
+    $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page');
+  }
+
+
 
   /*
@@ -555,5 +547,4 @@
       $_REQUEST['id']="";
     }
-
 
     /* ------------------------------------------------------------------------
@@ -780,5 +771,5 @@
                   dirname($this->getFileLocation()).'/admin/lmt_js.tpl');
 
-    $lmt_licence_default_values=array_slice($this->licences,0,count($this->licences)-1);
+    $lmt_licence_default_values=array_slice(self::$licences,0,count(self::$licences)-1);
     $datas['shortlicencetext']=array();
     foreach($lmt_licence_default_values as $key=>$val)
@@ -795,29 +786,4 @@
   }
 
-  protected function make_image_data($tmp, $imageId)
-  {
-    $tmp2=array();
-    foreach($tmp['id'] as $key=>$val)
-    {
-      $tmp2[]=array(
-        'id' => $tmp['id'][$key],
-        'name' => $tmp['name'][$key],
-        'type' => $tmp['type'][$key],
-        'plinks' => $tmp['plinks'][$key],
-        'link'=> make_picture_url(
-                  array(
-                    'image_id' => $imageId,
-                    'category' => array
-                      (
-                        'id' => $tmp['id'][$key],
-                        'name' => $tmp['name'][$key],
-                        'permalink' => $tmp['plinks'][$key]
-                      )
-                  )
-                )
-      );
-    }
-    return($tmp2);
-  }
 
   /* ---------------------------------------------------------------------------
@@ -826,209 +792,4 @@
 
 
-
-
-
-  /* ---------------------------------------------------------------------------
-    ajax functions
-  --------------------------------------------------------------------------- */
-
-  protected function ajax_img_list($pagenum)
-  {
-    global $conf;
-
-    $local_tpl = new Template(LMT_PATH."admin/", "");
-    $local_tpl->set_filename('body_page',
-                  dirname($this->getFileLocation()).'/admin/plugin_admin_listitems.tpl');
-
-    if(!isset($_REQUEST['filter']) ||
-       !($_REQUEST['filter']=="BY" ||
-         $_REQUEST['filter']=="BY-SA" ||
-         $_REQUEST['filter']=="BY-ND" ||
-         $_REQUEST['filter']=="BY-NC-ND" ||
-         $_REQUEST['filter']=="BY-NC-SA" ||
-         $_REQUEST['filter']=="BY-NC" ||
-         $_REQUEST['filter']=="CRIGHT" ||
-         $_REQUEST['filter']=="CLEFT"
-      ))
-    {
-      $_REQUEST['filter']='';
-    }
-
-    $img_ids=array();
-    $img_liste = array();
-    $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']!="")
-    {
-      $sql.=" AND lmti.licence_type='".$_REQUEST['filter']."'";
-    }
-
-    $sql.=" GROUP BY lmti.image_id ORDER BY cat.id, img.id ";
-
-    if($this->config['lmt_list_maxitems']>0)
-    {
-      $refdbt = ($pagenum-1)*$this->config['lmt_list_maxitems'];
-      $sql.=" LIMIT ".$refdbt.", ".$this->config['lmt_list_maxitems'];
-    }
-
-    $result=pwg_query($sql);
-    if($result)
-    {
-      while($row = pwg_db_fetch_assoc($result))
-      {
-        $filenfo = pathinfo($row['path']);
-        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, $row['image_id']);
-
-        $img_ids[]=$row['image_id'];
-        $img_liste[]=array(
-          'id' => $row['image_id'],
-          'licence' => ($row['licence_type']=="CRIGHT")?l10n("lmt_lbl_cc_s-".strtolower($row['licence_type'])):"",
-          'licencei' => LMT_PATH."img/".strtolower($row['licence_type'])."_80x15.png",
-          'aut_text1' => $row['text1'],
-          'aut_text2' => $row['text2'],
-          'file' => $row['file'],
-          'cat' => $tmpcat,
-          'thumb' => $filenfo["dirname"]."/thumbnail/".$conf["prefix_thumbnail"].$filenfo["filename"].".".$row["tn_ext"]
-        );
-      }
-    }
-
-    $sql="select FOUND_ROWS()";
-    $result=pwg_query($sql);
-    $nb=pwg_db_fetch_row($result);
-
-    $GPCPagesNavigation = new GPCPagesNavigation();
-    $GPCPagesNavigation->setNbItems($nb[0]);
-    $GPCPagesNavigation->setNbItemsPerPage($this->config['lmt_list_maxitems']);
-    $GPCPagesNavigation->setCurrentPage($pagenum);
-    $GPCPagesNavigation->setOptions(array(
-      "text_prev" => l10n("lmt_nav_prev"),
-      "text_next" => l10n("lmt_nav_next"),
-      "text_first" => l10n("lmt_nav_first"),
-      "text_last" => l10n("lmt_nav_last")
-    ));
-    $navbar=$GPCPagesNavigation->makeNavigation("loadpage");
-    if($navbar!="")
-    {
-      $navbar=", ".$navbar;
-    }
-
-    $local_tpl->assign('imgliste', $img_liste);
-    return($nb[0]."&nbsp;".l10n("lmt_lst_nb_photos").$navbar."#".$local_tpl->parse('body_page', true));
-  }
-
-  protected function ajax_manage_list($pagenum)
-  {
-    global $conf, $user;
-
-    $local_tpl = new Template(LMT_PATH."admin/", "");
-    $local_tpl->set_filename('body_page',
-                  dirname($this->getFileLocation()).'/admin/plugin_admin_manageitems.tpl');
-
-    if(!isset($_REQUEST['select']))
-    {
-      $_REQUEST['select']="caddie";
-    }
-
-    $img_liste = array();
-    $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 ".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 ";
-
-    if($this->config['lmt_list_maxitems']>0)
-    {
-      $refdbt = ($pagenum-1)*$this->config['lmt_list_maxitems'];
-      $sql.=" LIMIT ".$refdbt.", ".$this->config['lmt_list_maxitems'];
-    }
-
-    $result=pwg_query($sql);
-
-    if($result)
-    {
-      while($row = pwg_db_fetch_assoc($result))
-      {
-        $filenfo = pathinfo($row['path']);
-        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, $row['image_id']);
-
-        $img_liste[]=array(
-          'id' => $row['image_id'],
-          'licence' => ($row['licence_type']=="")?"DEFAULT":$row['licence_type'],
-          'licencei' => ($row['licence_type']=="")?"":LMT_PATH."img/".strtolower($row['licence_type'])."_80x15.png",
-          'aut_text1' => $row['text1'],
-          'aut_text2' => $row['text2'],
-          'file' => $row['file'],
-          'cat' => $tmpcat,
-          'thumb' => $filenfo["dirname"]."/thumbnail/".$conf["prefix_thumbnail"].$filenfo["filename"].".".$row["tn_ext"]
-        );
-      }
-    }
-
-    $sql="select FOUND_ROWS()";
-    $result=pwg_query($sql);
-    $nb=pwg_db_fetch_row($result);
-
-    $GPCPagesNavigation = new GPCPagesNavigation();
-    $GPCPagesNavigation->setNbItems($nb[0]);
-    $GPCPagesNavigation->setNbItemsPerPage($this->config['lmt_list_maxitems']);
-    $GPCPagesNavigation->setCurrentPage($pagenum);
-    $GPCPagesNavigation->setOptions(array(
-      "text_prev" => l10n("lmt_nav_prev"),
-      "text_next" => l10n("lmt_nav_next"),
-      "text_first" => l10n("lmt_nav_first"),
-      "text_last" => l10n("lmt_nav_last")
-    ));
-    $navbar=$GPCPagesNavigation->makeNavigation("loadpage");
-    if($navbar!="")
-    {
-      $navbar=", ".$navbar;
-    }
-
-    $local_tpl->assign('imgliste', $img_liste);
-    return($nb[0]."&nbsp;".l10n("lmt_lst_nb_photos").$navbar."#".$local_tpl->parse('body_page', true));
-  }
-
 } //class
 
