aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2003-09-19 21:40:52 +0000
committerz0rglub <z0rglub@piwigo.org>2003-09-19 21:40:52 +0000
commit26452aed650f879803d9211968457696970d44d0 (patch)
tree55a210cc1f6ac25f9ca79bb5ed9e290bdfd62e2d
parentb7a5a44944fcf0f20a8e4ab26143962ec8d0a86e (diff)
A category can have its representative picture
git-svn-id: http://piwigo.org/svn/trunk@133 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/include/functions.php29
-rw-r--r--admin/picture_modify.php49
-rw-r--r--include/functions_category.inc.php3
-rw-r--r--language/francais.php1
-rw-r--r--template/default/admin/picture_modify.vtp2
5 files changed, 80 insertions, 4 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 2763c890e..0f35c2798 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -291,7 +291,8 @@ function check_favorites( $user_id )
}
// update_category updates calculated informations about a category :
-// date_last and nb_images
+// date_last and nb_images. It also verifies that the representative picture
+// is really linked to the category.
function update_category( $id = 'all' )
{
if ( $id == 'all' )
@@ -333,6 +334,32 @@ function update_category( $id = 'all' )
$query.= ' WHERE id = '.$id;
$query.= ';';
mysql_query( $query );
+ // updating the representative_picture_id : if the representative
+ // picture of the category is not any more linked to the category, we
+ // have to set representative_picture_id to NULL
+ $query = 'SELECT representative_picture_id';
+ $query.= ' FROM '.PREFIX_TABLE.'categories';
+ $query.= ' WHERE id = '.$id;
+ $row = mysql_fetch_array( mysql_query( $query ) );
+ // if the category has no representative picture (ie
+ // representative_picture_id == NULL) we don't update anything
+ if ( $row['representative_picture_id'] != '' )
+ {
+ $query = 'SELECT image_id';
+ $query.= ' FROM '.PREFIX_TABLE.'image_category';
+ $query.= ' WHERE category_id = '.$id;
+ $query.= ' AND image_id = '.$row['representative_picture_id'];
+ $query.= ';';
+ $result = mysql_query( $query );
+ if ( mysql_num_rows( $result ) == 0 )
+ {
+ $query = 'UPDATE '.PREFIX_TABLE.'categories';
+ $query.= ' SET representative_picture_id = NULL';
+ $query.= ' WHERE id = '.$id;
+ $query.= ';';
+ mysql_query( $query );
+ }
+ }
}
}
diff --git a/admin/picture_modify.php b/admin/picture_modify.php
index 804cc8e2c..3eaa0748e 100644
--- a/admin/picture_modify.php
+++ b/admin/picture_modify.php
@@ -73,6 +73,39 @@ if ( isset( $_POST['submit'] ) )
$query.= ' WHERE id = '.$_GET['image_id'];
$query.= ';';
mysql_query( $query );
+ // make the picture representative of a category ?
+ $query = 'SELECT DISTINCT(category_id) as category_id';
+ $query.= ',representative_picture_id';
+ $query.= ' FROM '.PREFIX_TABLE.'image_category AS ic';
+ $query.= ', '.PREFIX_TABLE.'categories AS c';
+ $query.= ' WHERE c.id = ic.category_id';
+ $query.= ' AND image_id = '.$_GET['image_id'];
+ $query.= ';';
+ $result = mysql_query( $query );
+ while ( $row = mysql_fetch_array( $result ) )
+ {
+ // if the user ask the picture to be the representative picture of its
+ // category, the category is updated in the database (without wondering
+ // if this picture was already the representative one)
+ if ( $_POST['representative-'.$row['category_id']] == 1 )
+ {
+ $query = 'UPDATE '.PREFIX_TABLE.'categories';
+ $query.= ' SET representative_picture_id = '.$_GET['image_id'];
+ $query.= ' WHERE id = '.$row['category_id'];
+ $query.= ';';
+ mysql_query( $query );
+ }
+ // if the user ask this picture to be not any more the representative,
+ // we have to set the representative_picture_id of this category to NULL
+ else if ( $row['representative_picture_id'] == $_GET['image_id'] )
+ {
+ $query = 'UPDATE '.PREFIX_TABLE.'categories';
+ $query.= ' SET representative_picture_id = NULL';
+ $query.= ' WHERE id = '.$row['category_id'];
+ $query.= ';';
+ mysql_query( $query );
+ }
+ }
// associate with a new category ?
if ( $_POST['associate'] != '-1' )
{
@@ -111,7 +144,7 @@ $tpl = array( 'submit','errors_title','picmod_update','picmod_back',
'default','file','size','filesize','registration_date',
'author','creation_date','keywords','comment', 'upload_name',
'dissociate','categories','infoimage_associate',
- 'cat_image_info' );
+ 'cat_image_info','category_representative' );
templatize_array( $tpl, 'lang', $sub );
$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
//-------------------------------------------------------------- errors display
@@ -205,9 +238,16 @@ if ( !$result['visible'] )
$invisible_string.= $lang['cat_invisible'].'</span>';
$vtp->setVar( $sub, 'linked_category.invisible', $invisible_string );
}
+$vtp->setVar( $sub, 'linked_category.id', $row['storage_category_id'] );
+if ( $result['representative_picture_id'] == $_GET['image_id'] )
+{
+ $vtp->setVar( $sub, 'linked_category.representative_checked',
+ ' checked="checked"' );
+}
$vtp->closeSession( $sub, 'linked_category' );
// retrieving all the linked categories
$query = 'SELECT DISTINCT(category_id) as category_id,status,visible';
+$query.= ',representative_picture_id';
$query.= ' FROM '.PREFIX_TABLE.'image_category';
$query.= ','.PREFIX_TABLE.'categories';
$query.= ' WHERE image_id = '.$_GET['image_id'];
@@ -218,6 +258,7 @@ $result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
$vtp->addSession( $sub, 'linked_category' );
+ $vtp->setVar( $sub, 'linked_category.id', $row['category_id'] );
$vtp->addSession( $sub, 'checkbox' );
$vtp->setVar( $sub, 'checkbox.id', $row['category_id'] );
@@ -249,6 +290,12 @@ while ( $row = mysql_fetch_array( $result ) )
$vtp->setVar( $sub, 'linked_category.invisible', $invisible_string );
}
+ if ( $row['representative_picture_id'] == $_GET['image_id'] )
+ {
+ $vtp->setVar( $sub, 'linked_category.representative_checked',
+ ' checked="checked"' );
+ }
+
$vtp->closeSession( $sub, 'linked_category' );
}
// if there are linked category other than the storage category, we show
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 8e08a17d9..a691140d6 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -288,7 +288,7 @@ function get_cat_info( $id )
$cat = array();
$query = 'SELECT nb_images,id_uppercat,comment,site_id,galleries_url,dir';
- $query.= ',date_last,uploadable,status,visible';
+ $query.= ',date_last,uploadable,status,visible,representative_picture_id';
$query.= ' FROM '.PREFIX_TABLE.'categories AS a';
$query.= ', '.PREFIX_TABLE.'sites AS b';
$query.= ' WHERE a.id = '.$id;
@@ -303,6 +303,7 @@ function get_cat_info( $id )
$cat['uploadable'] = get_boolean( $row['uploadable'] );
$cat['status'] = $row['status'];
$cat['visible'] = get_boolean( $row['visible'] );
+ $cat['representative_picture_id'] = $row['representative_picture_id'];
$cat['name'] = array();
diff --git a/language/francais.php b/language/francais.php
index e3572546f..6cfbc3055 100644
--- a/language/francais.php
+++ b/language/francais.php
@@ -33,6 +33,7 @@ $lang['errors_title'] = 'Erreurs';
$lang['infos_title'] = 'Informations';
$lang['default'] = 'défaut';
$lang['comments'] = 'commentaires';
+$lang['category_representative'] = 'représentant';
// end version 1.3
// page diapo
diff --git a/template/default/admin/picture_modify.vtp b/template/default/admin/picture_modify.vtp
index 8af2074dd..d20272fee 100644
--- a/template/default/admin/picture_modify.vtp
+++ b/template/default/admin/picture_modify.vtp
@@ -65,7 +65,7 @@
<table>
<!--VTP_linked_category-->
<tr>
- <td><!--VTP_checkbox--><input type="checkbox" name="dissociate-{#id}" value="1" /><!--/VTP_checkbox--><a href="{#url}">{#name}</a> [ <a href="{#infos_images_link}">{#cat_image_info}</a> ] {#private} {#invisible}
+ <td><!--VTP_checkbox--><input type="checkbox" name="dissociate-{#id}" value="1" /><!--/VTP_checkbox--><a href="{#url}">{#name}</a> [ <a href="{#infos_images_link}">{#cat_image_info}</a> ] {#private} {#invisible} [ <input type="checkbox" name="representative-{#id}" value="1"{#representative_checked} /> {#category_representative} ]
</tr>
<!--/VTP_linked_category-->
<!--VTP_dissociate-->