aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2011-02-11 22:57:23 +0000
committerplegall <plg@piwigo.org>2011-02-11 22:57:23 +0000
commite79538be5ce50fe552c0180c169cfb275aa4ec07 (patch)
tree6640d1748fb5450e21211a94c8904217ee2103e1 /include
parentcc88f221110378648abd70f6141e2db07933ebfc (diff)
feature 2189 added: ability to update a photo (the JPEG/PNG file) with
pwg.images.addSimple, simply by adding an $image_id as argument. git-svn-id: http://piwigo.org/svn/trunk@9191 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/ws_functions.inc.php47
1 files changed, 34 insertions, 13 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index d0b550a2a..be453b6f7 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -1352,10 +1352,28 @@ function ws_images_addSimple($params, &$service)
{
return new PwgError(405, "This method requires HTTP POST");
}
+
+ $params['image_id'] = (int)$params['image_id'];
+ if ($params['image_id'] > 0)
+ {
+ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+
+ $query='
+SELECT *
+ FROM '.IMAGES_TABLE.'
+ WHERE id = '.$params['image_id'].'
+;';
+
+ $image_row = pwg_db_fetch_assoc(pwg_query($query));
+ if ($image_row == null)
+ {
+ return new PwgError(404, "image_id not found");
+ }
+ }
// category
$params['category'] = (int)$params['category'];
- if ($params['category'] <= 0)
+ if ($params['category'] <= 0 and $params['image_id'] <= 0)
{
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
}
@@ -1366,8 +1384,9 @@ function ws_images_addSimple($params, &$service)
$image_id = add_uploaded_file(
$_FILES['image']['tmp_name'],
$_FILES['image']['name'],
- array($params['category']),
- 8
+ $params['category'] > 0 ? array($params['category']) : null,
+ 8,
+ $params['image_id'] > 0 ? $params['image_id'] : null
);
$info_columns = array(
@@ -1415,23 +1434,25 @@ function ws_images_addSimple($params, &$service)
add_tags($tag_ids, array($image_id));
}
- $query = '
+ $url_params = array('image_id' => $image_id);
+
+ if ($params['category'] > 0)
+ {
+ $query = '
SELECT id, name, permalink
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$params['category'].'
;';
- $result = pwg_query($query);
- $category = pwg_db_fetch_assoc($result);
+ $result = pwg_query($query);
+ $category = pwg_db_fetch_assoc($result);
+
+ $url_params['section'] = 'categories';
+ $url_params['category'] = $category;
+ }
return array(
'image_id' => $image_id,
- 'url' => make_picture_url(
- array(
- 'image_id' => $image_id,
- 'section' => 'categories',
- 'category' => $category
- )
- ),
+ 'url' => make_picture_url($url_params),
);
}