From e2ee204c128717069c84437e0aa75bf14b6b352a Mon Sep 17 00:00:00 2001 From: rvelices Date: Sat, 12 Jul 2008 00:30:27 +0000 Subject: [PATCH] - add to caddie on picture page done through ajax git-svn-id: http://piwigo.org/svn/trunk@2429 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/ws_functions.inc.php | 28 +++++++++++++++ template-common/scripts.js | 66 +++++++++++++++++------------------- template/yoga/picture.tpl | 22 ++++++++++-- ws.php | 6 ++++ 4 files changed, 85 insertions(+), 37 deletions(-) diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index 72540f2da..f115d7865 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -280,6 +280,34 @@ function ws_getVersion($params, &$service) return new PwgError(403, 'Forbidden'); } +function ws_caddie_add($params, &$service) +{ + if (!is_admin()) + { + return new PwgError(401, 'Access denied'); + } + if ( empty($params['image_id']) ) + { + return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id"); + } + global $user; + $query = ' +SELECT id + FROM '.IMAGES_TABLE.' LEFT JOIN '.CADDIE_TABLE.' ON id=element_id AND user_id='.$user['id'].' + WHERE id IN ('.implode(',',$params['image_id']).') + AND element_id IS NULL'; + $datas = array(); + foreach ( array_from_query($query, 'id') as $id ) + { + array_push($datas, array('element_id'=>$id, 'user_id'=>$user['id']) ); + } + if (count($datas)) + { + include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); + mass_inserts(CADDIE_TABLE, array('element_id','user_id'), $datas); + } + return count($datas); +} /** * returns images per category (web service method) diff --git a/template-common/scripts.js b/template-common/scripts.js index 452be1699..e7fa7e9b5 100644 --- a/template-common/scripts.js +++ b/template-common/scripts.js @@ -4,11 +4,11 @@ var len = formulaire.elements.length; var i=0; for( i = 0; i < len; i++) { - if ( formulaire.elements[i].type=='checkbox' - && formulaire.elements[i].name != 'copie') - { - formulaire.elements[i].checked = true; - } + if ( formulaire.elements[i].type=='checkbox' + && formulaire.elements[i].name != 'copie') + { + formulaire.elements[i].checked = true; + } } } @@ -18,11 +18,11 @@ var len = formulaire.elements.length; var i=0; for( i = 0; i < len; i++) { - if ( formulaire.elements[i].type=='checkbox' - && formulaire.elements[i].name != 'copie') - { + if ( formulaire.elements[i].type=='checkbox' + && formulaire.elements[i].name != 'copie') + { formulaire.elements[i].checked = false; - } + } } } @@ -32,44 +32,42 @@ var len = formulaire.elements.length; var i=0; for( i=0; i{'edit'|@translate} {/if} - {if isset($U_CADDIE) } - {'caddie'|@translate} - {/if} + {if isset($U_CADDIE) }{*caddie management BEGIN*} + + {'caddie'|@translate} + {/if}{*caddie management END*} {include file=$FILE_PICTURE_NAV_BUTTONS} diff --git a/ws.php b/ws.php index 45601a1cb..003e1df54 100644 --- a/ws.php +++ b/ws.php @@ -43,6 +43,12 @@ function ws_addDefaultMethods( $arr ) $service->addMethod('pwg.getVersion', 'ws_getVersion', null, 'retrieves the PWG version'); + $service->addMethod('pwg.caddie.add', 'ws_caddie_add', + array( + 'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ), + ), + 'adds the elements to the caddie'); + $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages', array( 'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY),