aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/cat_modify.php23
-rw-r--r--admin/include/functions.php41
-rw-r--r--admin/update.php16
-rw-r--r--language/en_UK.iso-8859-1/admin.lang.php1
-rw-r--r--template/default/admin/cat_modify.tpl8
5 files changed, 67 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.= '&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;
}
diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php
index 8f0e09d41..de76c8fc0 100644
--- a/language/en_UK.iso-8859-1/admin.lang.php
+++ b/language/en_UK.iso-8859-1/admin.lang.php
@@ -344,4 +344,5 @@ $lang['cat_list_update_metadata'] = 'Synchronize<br />metadata';
$lang['cat_list_update_metadata_confirmation'] = 'files metadata updated';
$lang['cat_list_virtual_category_added'] = 'virtual category added';
$lang['cat_list_virtual_category_deleted'] = 'virtual category deleted';
+$lang['set_random_representant'] = 'set new random representant';
?> \ No newline at end of file
diff --git a/template/default/admin/cat_modify.tpl b/template/default/admin/cat_modify.tpl
index 7dea3c4bd..c9b9749b3 100644
--- a/template/default/admin/cat_modify.tpl
+++ b/template/default/admin/cat_modify.tpl
@@ -5,6 +5,14 @@
<div class="admin">{CATEGORIES_NAV}</div>
<form action="{F_ACTION}" method="POST">
<table style="width:100%;">
+ <!-- BEGIN representant -->
+ <tr>
+ <td style="width:50%;" align="center">
+ <a href="{representant.URL}"><img src="{representant.SRC}" alt="" class="miniature" /></a>
+ </td>
+ <td class="row1"><input type="submit" name="set_random_representant" value="{L_SET_RANDOM_REPRESENTANT}" class="bouton" /></td>
+ </tr>
+ <!-- END representant -->
<!-- BEGIN server -->
<tr>
<td style="width:50%;"><strong>{L_REMOTE_SITE}</strong></td>