aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
Diffstat (limited to 'admin')
-rw-r--r--admin/include/functions.php32
-rw-r--r--admin/remote_site.php15
-rw-r--r--admin/update.php16
3 files changed, 58 insertions, 5 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 63f59471b..2b28f6784 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -486,8 +486,8 @@ SELECT id, representative_picture_id
WHERE representative_picture_id IS NOT NULL
AND id IN ('.implode(',', $cat_ids).')
;';
- $result = pwg_query( $query );
- while ( $row = mysql_fetch_array( $result ) )
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
{
$query = '
SELECT image_id
@@ -495,15 +495,37 @@ SELECT image_id
WHERE category_id = '.$row['id'].'
AND image_id = '.$row['representative_picture_id'].'
;';
- $result = pwg_query( $query );
- if (mysql_num_rows($result) == 0)
+ $sub_result = pwg_query($query);
+ if (mysql_num_rows($sub_result) == 0)
{
+ // set a new representative element for this category
$query = '
+SELECT image_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE category_id = '.$row['id'].'
+ ORDER BY RAND()
+ LIMIT 0,1
+;';
+ $sub_sub_result = pwg_query($query);
+ if (mysql_num_rows($sub_sub_result) > 0)
+ {
+ list($representative) = mysql_fetch_array(pwg_query($query));
+ $query = '
+UPDATE '.CATEGORIES_TABLE.'
+ SET representative_picture_id = '.$representative.'
+ WHERE id = '.$row['id'].'
+;';
+ pwg_query($query);
+ }
+ else
+ {
+ $query = '
UPDATE '.CATEGORIES_TABLE.'
SET representative_picture_id = NULL
WHERE id = '.$row['id'].'
;';
- pwg_query( $query );
+ pwg_query($query);
+ }
}
}
}
diff --git a/admin/remote_site.php b/admin/remote_site.php
index 082658ab0..19db458b4 100644
--- a/admin/remote_site.php
+++ b/admin/remote_site.php
@@ -432,6 +432,21 @@ INSERT INTO '.IMAGE_CATEGORY_TABLE.'
$query.= '
;';
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);
}
}
// +-----------------------------------------------------------------------+
diff --git a/admin/update.php b/admin/update.php
index 817a67aae..10813349e 100644
--- a/admin/update.php
+++ b/admin/update.php
@@ -514,6 +514,22 @@ INSERT INTO '.IMAGE_CATEGORY_TABLE.'
'.implode(',', $ids).'
;';
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);
}
return $output;
}