Index: trunk/include/ws_functions.inc.php
===================================================================
--- trunk/include/ws_functions.inc.php	(revision 1756)
+++ trunk/include/ws_functions.inc.php	(revision 1757)
@@ -33,8 +33,8 @@
  * 
  * - Args  
- * $params: is where clauses
- * $img_tbl: indicates if phpwebgallery_images is selected
+ * $method: is the requested method
  * $partner: is the key
  * $tbl_name: is the alias_name in the query (sometimes called correlation name)
+ *            null if !getting picture informations 
  * - Logic
  * Access_control is not active: Return 
@@ -46,24 +46,64 @@
  * The additionnal in-where-clause is return
  */       
-function ws_add_controls( $params, $img_tbl=false, $partner='', $tbl_name='' )
-{
-  global $conf;
+function ws_add_controls( $method, $tbl_name )
+{
+  global $conf, $partner;
   if ( !$conf['ws_access_control'] )
   {
     return ' 1 = 1 '; // No controls are requested 
   }
-  // Step 1 - Found Partner
+  
+// Is it an active Partner? 
   $query = '
-SELECT FROM '.WEB_SERVICES_ACCESS_TABLE."
- WHERE `name` = '$partner';";
+SELECT * FROM '.WEB_SERVICES_ACCESS_TABLE."
+ WHERE `name` = '$partner'
+   AND NOW() <= end; ";
 $result = pwg_query($query);
-  if ( mysql_num_rows( pwg_query($query) ) = 0 )
+  if ( mysql_num_rows( $result ) = 0 )
   {     
-    return ' 0 = 1 '; // Unknown partner
-  }
-  // Step 2 - Clauses / Request matching
-  //     Restrict Request has to be redefined first
-  // Step 3 - Target restrict
-  return $addings;
+    return ' 0 = 1 '; // Unknown partner or Obsolate agreement
+  }
+  
+  $row = mysql_fetch_array($result);
+
+// Method / Request matching
+// Generic is not ready 
+// For generic you can say... tags. or categories. or images. maybe?
+  $filter = $row['request'];
+  $request_method = substr($method, 0, strlen($filter)) ;
+  if ( $filter !== $filter_method )
+  {
+    return ' 0 = 1'; // Unauthorized method request
+  }
+
+// Target restrict
+// 3 cases: list, cat or tag
+// Behind / we could found img-ids, cat-ids or tag-ids
+  $target = $row['access'];
+  list($type, $str_ids) = explode('/',$target); // Find type list
+
+  $ids = explode( ',',$str_ids );
+// (array) 1,2,21,3,22,4,5,9-12,6,11,12,13,2,4,6,
+  $arr_ids = expand_id_list( $ids );
+  $addings = implode(',', $arr_ids); 
+// (string) 1,2,3,4,5,6,9,10,11,12,13,21,22, 
+  if ( $type = 'list')
+  {
+    return $tbl_name . 'id IN ( ' . $addings . ' ) ';
+  }
+  
+  if ( $type = 'cat' )
+  {
+    $addings = implode(',', get_image_ids_for_cats($arr_ids));
+    return $tbl_name . 'id IN ( ' . $addings . ' ) ';
+  }
+  
+  if ( $type = 'tag' )
+  { 
+    $addings = implode(',', get_image_ids_for_tags($arr_ids, 'OR'));
+    return $tbl_name . 'id IN ( ' . $addings . ' ) ';
+  }
+  // Unmanaged new type?
+  return ' 0 = 1 '; // ??? 
 }
 
@@ -191,4 +231,7 @@
 function ws_getVersion($params, &$service)
 {
+//  Needed for security reason... Maybe???
+//  $where_clause[] = 
+//          ws_add_controls( 'getVersion', null );
   return PHPWG_VERSION;
 }
@@ -250,7 +293,7 @@
       .')';
 
-// example of ws_add_controls call   
+//  Mandatory 
 //  $where_clause[] = 
-//          ws_add_controls call( $params, true, $partner, $tbl_name='i.' );
+//          ws_add_controls( 'categories.getImages', 'i.' );
     
     $order_by = ws_std_image_sql_order($params, 'i.');
@@ -372,4 +415,9 @@
   }
 
+// To ONLY build external links maybe ???  
+//  $where_clause[] = 
+//          ws_add_controls( 'categories.getList', null );
+// Making links in a Blog...
+
   $query = '
 SELECT id, name, uppercats, global_rank,
@@ -417,4 +465,7 @@
     return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
   }
+// Mandatory (No comment)  
+//  $where_clause[] = 
+//          ws_add_controls( 'images.getInfo', '' );  
   $query='
 SELECT * FROM '.IMAGES_TABLE.'
@@ -649,5 +700,5 @@
   $image_ids = array();
   $image_tag_map = array();
-
+  
   if ( !empty($tag_ids) )
   { // build list of image ids with associated tags per image
@@ -687,4 +738,8 @@
       );
     $where_clauses[] = 'id IN ('.implode(',',$image_ids).')';
+// Mandatory  
+//  $where_clause[] = 
+//          ws_add_controls( 'tags.getImages', '' );  
+
     $order_by = ws_std_image_sql_order($params);
     if (empty($order_by))
