aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2004-12-04 17:42:07 +0000
committerplegall <plg@piwigo.org>2004-12-04 17:42:07 +0000
commitb3336f57d5d61eaa5d465b816962b12ea16c24ae (patch)
treefcaba01eccc65bfdec84fce49c6c4faf54a0fad1 /admin
parenta383f3148cb7c9a23dadbdcd12ede4e1de274af5 (diff)
- shows the element representing a non empty category in cat_modify
- possibility to set a random representing element for a category - bug fixed : update_category function could not update nb_images - bug fixed : mass_updates was inserting in the wrong table git-svn-id: http://piwigo.org/svn/trunk@633 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/cat_modify.php23
-rw-r--r--admin/include/functions.php41
-rw-r--r--admin/update.php16
3 files changed, 58 insertions, 22 deletions
diff --git a/admin/cat_modify.php b/admin/cat_modify.php
index 00f52abd4..fc54301d1 100644
--- a/admin/cat_modify.php
+++ b/admin/cat_modify.php
@@ -80,6 +80,10 @@ if ( isset( $_POST['submit'] ) )
$template->assign_block_vars('confirmation' ,array());
}
+else if (isset($_POST['set_random_representant']))
+{
+ set_random_representant(array($_GET['cat_id']));
+}
$query = '
SELECT *
@@ -157,10 +161,27 @@ $template->assign_vars(array(
'L_YES'=>$lang['yes'],
'L_NO'=>$lang['no'],
'L_SUBMIT'=>$lang['submit'],
+ 'L_SET_RANDOM_REPRESENTANT'=>$lang['set_random_representant'],
'F_ACTION'=>add_session_id($form_action)
));
-
+
+if ($category['nb_images'] > 0)
+{
+ $query = '
+SELECT tn_ext,path
+ FROM '.IMAGES_TABLE.'
+ WHERE id = '.$category['representative_picture_id'].'
+;';
+ $row = mysql_fetch_array(pwg_query($query));
+ $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
+ $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
+ $url.= '&amp;image_id='.$category['representative_picture_id'];
+ $template->assign_block_vars('representant',
+ array('SRC' => $src,
+ 'URL' => $url));
+}
+
if (!empty($category['dir']))
{
$template->assign_block_vars('storage' ,array());
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 7a12be755..8ae7929ae 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -453,7 +453,9 @@ function update_category($id = 'all')
$cat_ids = array();
$query = '
-SELECT category_id, COUNT(image_id) AS count, max(date_available) AS date_last
+SELECT category_id,
+ COUNT(image_id) AS nb_images,
+ MAX(date_available) AS date_last
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
if (is_numeric($id))
@@ -471,10 +473,10 @@ SELECT category_id, COUNT(image_id) AS count, max(date_available) AS date_last
array_push($cat_ids, $row['category_id']);
array_push($datas, array('id' => $row['category_id'],
'date_last' => $row['date_last'],
- 'count' => $row['count']));
+ 'nb_images' => $row['nb_images']));
}
$fields = array('primary' => array('id'),
- 'update' => array('date_last', 'count'));
+ 'update' => array('date_last', 'nb_images'));
mass_updates(CATEGORIES_TABLE, $fields, $datas);
if (count($cat_ids) > 0)
@@ -839,11 +841,10 @@ function mass_updates($tablename, $dbfields, $datas)
// update queries
$query = 'SELECT VERSION() AS version;';
$row = mysql_fetch_array(pwg_query($query));
- if (version_compare($row['version'],'4.0.4') < 0)
+ if (count($datas) < 10 or version_compare($row['version'],'4.0.4') < 0)
{
// MySQL is prior to version 4.0.4, multi table update feature is not
// available
- echo 'MySQL is prior to version 4.0.4, multi table update feature is not available<br />';
foreach ($datas as $data)
{
$query = '
@@ -914,7 +915,7 @@ PRIMARY KEY (id)
)
;';
pwg_query($query);
- mass_inserts($tablename, $all_fields, $datas);
+ mass_inserts($tablename.'_temporary', $all_fields, $datas);
// update of images table by joining with temporary table
$query = '
UPDATE '.$tablename.' AS t1, '.$tablename.'_temporary AS t2
@@ -1092,4 +1093,32 @@ UPDATE '.CATEGORIES_TABLE.'
pwg_query($query);
}
}
+
+/**
+ * set a new random representant to the categories
+ *
+ * @param array categories
+ */
+function set_random_representant($categories)
+{
+ $datas = array();
+ foreach ($categories as $category_id)
+ {
+ $query = '
+SELECT image_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE category_id = '.$category_id.'
+ ORDER BY RAND()
+ LIMIT 0,1
+;';
+ list($representative) = mysql_fetch_array(pwg_query($query));
+ $data = array('id' => $category_id,
+ 'representative_picture_id' => $representative);
+ array_push($datas, $data);
+ }
+
+ $fields = array('primary' => array('id'),
+ 'update' => array('representative_picture_id'));
+ mass_updates(CATEGORIES_TABLE, $fields, $datas);
+}
?>
diff --git a/admin/update.php b/admin/update.php
index 45bef3bce..aca5307ea 100644
--- a/admin/update.php
+++ b/admin/update.php
@@ -515,21 +515,7 @@ INSERT INTO '.IMAGE_CATEGORY_TABLE.'
;';
pwg_query($query);
- // set a new representative element for this category
- $query = '
-SELECT image_id
- FROM '.IMAGE_CATEGORY_TABLE.'
- WHERE category_id = '.$category_id.'
- ORDER BY RAND()
- LIMIT 0,1
-;';
- list($representative) = mysql_fetch_array(pwg_query($query));
- $query = '
-UPDATE '.CATEGORIES_TABLE.'
- SET representative_picture_id = '.$representative.'
- WHERE id = '.$category_id.'
-;';
- pwg_query($query);
+ set_random_representant(array($category_id));
}
return $output;
}