aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2005-04-11 20:31:50 +0000
committerplegall <plg@piwigo.org>2005-04-11 20:31:50 +0000
commit8549bee38a9c7d1ace16bc99c292e7a66c125eba (patch)
tree41d714c1699272c6c74318adc57a6e6029936485
parentfdc5ce0a556df37b126d759ccdd0800115306998 (diff)
- functions get_day_list and get_month_list moved from search.php to
include/functions.inc.php : these functions are now also used in admin/element_set_global.php - elements batch management improved : ability to set the number of elements to display per line, ability to set {author, name, creation date} fields, ability to add and remove keywords, ability to take selected elements out of caddie git-svn-id: http://piwigo.org/svn/trunk@762 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/element_set_global.php243
-rw-r--r--doc/ChangeLog11
-rw-r--r--include/functions.inc.php56
-rw-r--r--search.php55
-rw-r--r--template/default/admin/element_set_global.tpl155
5 files changed, 435 insertions, 85 deletions
diff --git a/admin/element_set_global.php b/admin/element_set_global.php
index 01a03a19e..720ab0c13 100644
--- a/admin/element_set_global.php
+++ b/admin/element_set_global.php
@@ -30,8 +30,6 @@
* user caddie.
*
*/
-
-$user['nb_image_line'] = 6; // temporary
if (!defined('PHPWG_ROOT_PATH'))
{
@@ -40,15 +38,81 @@ if (!defined('PHPWG_ROOT_PATH'))
include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
// +-----------------------------------------------------------------------+
-// | empty caddie |
+// | functions |
// +-----------------------------------------------------------------------+
-if (isset($_GET['empty']))
+
+/**
+ * returns the list of uniq keywords among given elements
+ *
+ * @param array element_ids
+ */
+function get_elements_keywords($element_ids)
{
+ if (0 == count($element_ids))
+ {
+ return array();
+ }
+
+ $keywords = array();
+
$query = '
+SELECT keywords
+ FROM '.IMAGES_TABLE.'
+ WHERE id IN ('.implode(',', $element_ids).')
+;';
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
+ {
+ if (isset($row['keywords']) and !empty($row['keywords']))
+ {
+ $keywords = array_merge($keywords, explode(',', $row['keywords']));
+ }
+ }
+ return array_unique($keywords);
+}
+
+// +-----------------------------------------------------------------------+
+// | caddie management |
+// +-----------------------------------------------------------------------+
+if (isset($_POST['submit_caddie']))
+{
+ if (isset($_POST['caddie_action']))
+ {
+ switch ($_POST['caddie_action'])
+ {
+ case 'empty_all' :
+ {
+ $query = '
DELETE FROM '.CADDIE_TABLE.'
WHERE user_id = '.$user['id'].'
;';
- pwg_query($query);
+ pwg_query($query);
+ break;
+ }
+ case 'empty_selected' :
+ {
+ if (isset($_POST['selection']) and count($_POST['selection']) > 0)
+ {
+ $query = '
+DELETE
+ FROM '.CADDIE_TABLE.'
+ WHERE element_id IN ('.implode(',', $_POST['selection']).')
+ AND user_id = '.$user['id'].'
+;';
+ pwg_query($query);
+ }
+ else
+ {
+ // TODO : add error
+ }
+ break;
+ }
+ }
+ }
+ else
+ {
+ // TODO : add error
+ }
}
// +-----------------------------------------------------------------------+
@@ -61,7 +125,7 @@ if (isset($_POST['submit']))
$collection = array();
// echo '<pre>';
-// print_r($_POST['selection']);
+// print_r($_POST);
// echo '</pre>';
// exit();
@@ -99,6 +163,7 @@ SELECT image_id
;';
$associated = array_from_query($query, 'image_id');
+ // TODO : if $associable array is empty, no further actions
$associable = array_diff($collection, $associated);
foreach ($associable as $item)
@@ -136,6 +201,111 @@ DELETE FROM '.IMAGE_CATEGORY_TABLE.'
update_category(array($_POST['dissociate']));
}
+
+ $datas = array();
+ $dbfields = array('primary' => array('id'), 'update' => array());
+
+ if (!empty($_POST['add_keywords']) or $_POST['remove_keyword'] != '0')
+ {
+ array_push($dbfields['update'], 'keywords');
+ }
+
+ $formfields = array('author', 'name', 'date_creation');
+ foreach ($formfields as $formfield)
+ {
+ if ($_POST[$formfield.'_action'] != 'leave')
+ {
+ array_push($dbfields['update'], $formfield);
+ }
+ }
+
+ // updating elements is useful only if needed...
+ if (count($dbfields['update']) > 0)
+ {
+ $query = '
+SELECT id, keywords
+ FROM '.IMAGES_TABLE.'
+ WHERE id IN ('.implode(',', $collection).')
+;';
+ $result = pwg_query($query);
+
+ while ($row = mysql_fetch_array($result))
+ {
+ $data = array();
+ $data['id'] = $row['id'];
+
+ if (!empty($_POST['add_keywords']))
+ {
+ $data['keywords'] =
+ implode(
+ ',',
+ array_unique(
+ array_merge(
+ get_keywords(empty($row['keywords']) ? '' : $row['keywords']),
+ get_keywords($_POST['add_keywords'])
+ )
+ )
+ );
+ }
+
+ if ($_POST['remove_keyword'] != '0')
+ {
+ if (!isset($data['keywords']))
+ {
+ $data['keywords'] = empty($row['keywords']) ? '' : $row['keywords'];
+ }
+
+ $data['keywords'] =
+ implode(
+ ',',
+ array_unique(
+ array_diff(
+ get_keywords($data['keywords']),
+ array($_POST['remove_keyword'])
+ )
+ )
+ );
+
+ if ($data['keywords'] == '')
+ {
+ unset($data['keywords']);
+ }
+ }
+
+ if ('set' == $_POST['author_action'])
+ {
+ $data['author'] = $_POST['author'];
+
+ if ('' == $data['author'])
+ {
+ unset($data['author']);
+ }
+ }
+
+ if ('set' == $_POST['name_action'])
+ {
+ $data['name'] = $_POST['name'];
+
+ if ('' == $data['name'])
+ {
+ unset($data['name']);
+ }
+ }
+
+ if ('set' == $_POST['date_creation_action'])
+ {
+ $data['date_creation'] =
+ $_POST['date_creation_year']
+ .'-'.$_POST['date_creation_month']
+ .'-'.$_POST['date_creation_day']
+ ;
+ }
+
+ array_push($datas, $data);
+ }
+ echo '<pre>'; print_r($datas); echo '</pre>';
+ mass_updates(IMAGES_TABLE, $dbfields, $datas);
+ }
}
// +-----------------------------------------------------------------------+
@@ -144,15 +314,17 @@ DELETE FROM '.IMAGE_CATEGORY_TABLE.'
$template->set_filenames(
array('element_set_global' => 'admin/element_set_global.tpl'));
-$form_action = PHPWG_ROOT_PATH.'admin.php?page=element_set_global';
+$base_url = PHPWG_ROOT_PATH.'admin.php';
+
+// $form_action = $base_url.'?page=element_set_global';
$template->assign_vars(
array(
'L_SUBMIT'=>$lang['submit'],
- 'U_EMPTY_CADDIE'=>add_session_id($form_action.'&amp;empty=1'),
+ 'U_ELEMENTS_LINE'=>$base_url.get_query_string_diff(array('display')),
- 'F_ACTION'=>add_session_id($form_action)
+ 'F_ACTION'=>$base_url.get_query_string_diff(array()),
)
);
// +-----------------------------------------------------------------------+
@@ -201,10 +373,61 @@ SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
;';
display_select_cat_wrapper($query, array(), $blockname, true);
+$blockname = 'remove_keyword_option';
+
+$template->assign_block_vars(
+ $blockname,
+ array('VALUE'=> 0,
+ 'OPTION' => '------------'
+ ));
+
+$query = '
+SELECT element_id
+ FROM '.CADDIE_TABLE.'
+ WHERE user_id = '.$user['id'].'
+;';
+$keywords = get_elements_keywords(array_from_query($query, 'element_id'));
+
+foreach ($keywords as $keyword)
+{
+ $template->assign_block_vars(
+ $blockname,
+ array('VALUE'=> $keyword,
+ 'OPTION' => $keyword
+ ));
+}
+
+// creation date
+$day =
+empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
+get_day_list('date_creation_day', $day);
+
+if (!empty($_POST['date_creation_month']))
+{
+ $month = $_POST['date_creation_month'];
+}
+else
+{
+ $month = date('n');
+}
+get_month_list('date_creation_month', $month);
+
+if (!empty($_POST['date_creation_year']))
+{
+ $year = $_POST['date_creation_year'];
+}
+else
+{
+ $year = date('Y');
+}
+$template->assign_vars(array('DATE_CREATION_YEAR_VALUE'=>$year));
+
// +-----------------------------------------------------------------------+
// | global mode thumbnails |
// +-----------------------------------------------------------------------+
+$page['nb_image_line'] = !empty($_GET['display']) ? $_GET['display'] : 5;
+
$query = '
SELECT element_id,path,tn_ext
FROM '.IMAGES_TABLE.' INNER JOIN '.CADDIE_TABLE.' ON id=element_id
@@ -239,7 +462,7 @@ while ($row = mysql_fetch_array($result))
);
// create a new line ?
- if (++$row_number == $user['nb_image_line'])
+ if (++$row_number == $page['nb_image_line'])
{
$template->assign_block_vars('thumbnails.line', array());
$row_number = 0;
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 4994ae99f..399723591 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,14 @@
+2005-04-11 Pierrick LE GALL <pierrick /at/ phpwebgallery {dot} net>
+
+ * functions get_day_list and get_month_list moved from search.php
+ to include/functions.inc.php : these functions are now also used
+ in admin/element_set_global.php
+
+ * elements batch management improved : ability to set the number
+ of elements to display per line, ability to set {author, name,
+ creation date} fields, ability to add and remove keywords, ability
+ to take selected elements out of caddie
+
2005-03-31 Pierrick LE GALL <pierrick at phpwebgallery dot net>
* apply category name and element name separation in calendar
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 282c196ac..d3fd3aee9 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -639,4 +639,60 @@ function array_from_query($query, $fieldname)
return $array;
}
+
+/**
+ * instantiate number list for days in a template block
+ *
+ * @param string blockname
+ * @param string selection
+ */
+function get_day_list($blockname, $selection)
+{
+ global $template;
+
+ $template->assign_block_vars(
+ $blockname, array('SELECTED' => '', 'VALUE' => 0, 'OPTION' => '--'));
+
+ for ($i = 1; $i <= 31; $i++)
+ {
+ $selected = '';
+ if ($i == (int)$selection)
+ {
+ $selected = 'selected="selected"';
+ }
+ $template->assign_block_vars(
+ $blockname, array('SELECTED' => $selected,
+ 'VALUE' => $i,
+ 'OPTION' => str_pad($i, 2, '0', STR_PAD_LEFT)));
+ }
+}
+
+/**
+ * instantiate month list in a template block
+ *
+ * @param string blockname
+ * @param string selection
+ */
+function get_month_list($blockname, $selection)
+{
+ global $template, $lang;
+
+ $template->assign_block_vars(
+ $blockname, array('SELECTED' => '',
+ 'VALUE' => 0,
+ 'OPTION' => '------------'));
+
+ for ($i = 1; $i <= 12; $i++)
+ {
+ $selected = '';
+ if ($i == (int)$selection)
+ {
+ $selected = 'selected="selected"';
+ }
+ $template->assign_block_vars(
+ $blockname, array('SELECTED' => $selected,
+ 'VALUE' => $i,
+ 'OPTION' => $lang['month'][$i]));
+ }
+}
?>
diff --git a/search.php b/search.php
index 4bf65c5be..e731477ca 100644
--- a/search.php
+++ b/search.php
@@ -133,61 +133,6 @@ if (isset($_POST['submit']) and count($errors) == 0)
redirect($url);
}
//----------------------------------------------------- template initialization
-/**
- * instantiate number list for days in a template block
- *
- * @param string blockname
- * @param string selection
- */
-function get_day_list($blockname, $selection)
-{
- global $template;
-
- $template->assign_block_vars(
- $blockname, array('SELECTED' => '', 'VALUE' => 0, 'OPTION' => '--'));
-
- for ($i = 1; $i <= 31; $i++)
- {
- $selected = '';
- if ($i == (int)$selection)
- {
- $selected = 'selected="selected"';
- }
- $template->assign_block_vars(
- $blockname, array('SELECTED' => $selected,
- 'VALUE' => $i,
- 'OPTION' => str_pad($i, 2, '0', STR_PAD_LEFT)));
- }
-}
-
-/**
- * instantiate month list in a template block
- *
- * @param string blockname
- * @param string selection
- */
-function get_month_list($blockname, $selection)
-{
- global $template, $lang;
-
- $template->assign_block_vars(
- $blockname, array('SELECTED' => '',
- 'VALUE' => 0,
- 'OPTION' => '------------'));
-
- for ($i = 1; $i <= 12; $i++)
- {
- $selected = '';
- if ($i == (int)$selection)
- {
- $selected = 'selected="selected"';
- }
- $template->assign_block_vars(
- $blockname, array('SELECTED' => $selected,
- 'VALUE' => $i,
- 'OPTION' => $lang['month'][$i]));
- }
-}
// start date
get_day_list('start_day', @$_POST['start_day']);
diff --git a/template/default/admin/element_set_global.tpl b/template/default/admin/element_set_global.tpl
index c693ff53a..9af80caac 100644
--- a/template/default/admin/element_set_global.tpl
+++ b/template/default/admin/element_set_global.tpl
@@ -1,26 +1,123 @@
-<p style="text-align:center"><a href="{U_EMPTY_CADDIE}">Empty caddie</a></p>
-
<form action="{F_ACTION}" method="post">
- associate to
- <select style="width:400px" name="associate" size="1">
- <!-- BEGIN associate_option -->
- <option {associate_option.SELECTED} value="{associate_option.VALUE}">{associate_option.OPTION}</option>
- <!-- END associate_option -->
- </select>
-
- <br />dissociate from
- <select style="width:400px" name="dissociate" size="1">
- <!-- BEGIN dissociate_option -->
- <option {dissociate_option.SELECTED} value="{dissociate_option.VALUE}">{dissociate_option.OPTION}</option>
- <!-- END dissociate_option -->
- </select>
-
- <br />target
- <input type="radio" name="target" value="all" /> all
- <input type="radio" name="target" value="selection" /> selection
+<fieldset>
+
+ <legend>Caddie management</legend>
+
+ <ul style="list-style-type:none;">
+ <li><input type="radio" name="caddie_action" value="empty_all" /> Empty caddie</li>
+ <li><input type="radio" name="caddie_action" value="empty_selected" /> Take selected elements out of caddie</li>
+ </ul>
+
+ <p style="text-align:center;"><input type="submit" value="{L_SUBMIT}" name="submit_caddie" class="bouton" /></p>
+
+</fieldset>
+
+<fieldset>
+
+ <legend>Form</legend>
+
+ <table>
+
+ <tr>
+ <td>associate to category</td>
+ <td>
+ <select style="width:400px" name="associate" size="1">
+ <!-- BEGIN associate_option -->
+ <option {associate_option.SELECTED} value="{associate_option.VALUE}">{associate_option.OPTION}</option>
+ <!-- END associate_option -->
+ </select>
+ </td>
+ </tr>
+
+ <tr>
+ <td>dissociate from category</td>
+ <td>
+ <select style="width:400px" name="dissociate" size="1">
+ <!-- BEGIN dissociate_option -->
+ <option {dissociate_option.SELECTED} value="{dissociate_option.VALUE}">{dissociate_option.OPTION}</option>
+ <!-- END dissociate_option -->
+ </select>
+ </td>
+ </tr>
+
+ <tr>
+ <td>add keywords</td>
+ <td><input type="text" name="add_keywords" value="" /></td>
+ </tr>
+
+ <tr>
+ <td>remove keyword</td>
+ <td>
+ <select name="remove_keyword">
+ <!-- BEGIN remove_keyword_option -->
+ <option value="{remove_keyword_option.VALUE}">{remove_keyword_option.OPTION}</option>
+ <!-- END remove_keyword_option -->
+ </select>
+ </td>
+ </tr>
+
+ <tr>
+ <td>author</td>
+ <td>
+ <input type="radio" name="author_action" value="leave" checked="checked" /> leave unchanged
+ <input type="radio" name="author_action" value="unset" /> unset
+ <input type="radio" name="author_action" value="set" id="author_action_set" /> set to
+ <input onmousedown="document.getElementById('author_action_set').checked = true;" type="text" name="author" value="" />
+ </td>
+ </tr>
+
+ <tr>
+ <td>title</td>
+ <td>
+ <input type="radio" name="name_action" value="leave" checked="checked" /> leave unchanged
+ <input type="radio" name="name_action" value="unset" /> unset
+ <input type="radio" name="name_action" value="set" id="name_action_set" /> set to
+ <input onmousedown="document.getElementById('name_action_set').checked = true;" type="text" name="name" value="" />
+ </td>
+ </tr>
+
+ <tr>
+ <td>creation date</td>
+ <td>
+ <input type="radio" name="date_creation_action" value="leave" checked="checked" /> leave unchanged
+ <input type="radio" name="date_creation_action" value="unset" /> unset
+ <input type="radio" name="date_creation_action" value="set" id="date_creation_action_set" /> set to
+ <select onmousedown="document.getElementById('date_creation_action_set').checked = true;" name="date_creation_day">
+ <!-- BEGIN date_creation_day -->
+ <option {date_creation_day.SELECTED} value="{date_creation_day.VALUE}">{date_creation_day.OPTION}</option>
+ <!-- END date_creation_day -->
+ </select>
+ <select onmousedown="document.getElementById('date_creation_action_set').checked = true;" name="date_creation_month">
+ <!-- BEGIN date_creation_month -->
+ <option {date_creation_month.SELECTED} value="{date_creation_month.VALUE}">{date_creation_month.OPTION}</option>
+ <!-- END date_creation_month -->
+ </select>
+ <input onmousedown="document.getElementById('date_creation_action_set').checked = true;"
+ name="date_creation_year"
+ type="text"
+ size="4"
+ maxlength="4"
+ value="{DATE_CREATION_YEAR_VALUE}" />
+ </td>
+ </tr>
+
+ </table>
+
+ <p style="text-align:center;">
+ target
+ <input type="radio" name="target" value="all" /> all
+ <input type="radio" name="target" value="selection" checked="checked" /> selection
+ </p>
+
- <br /><input type="submit" value="{L_SUBMIT}" name="submit" class="bouton" />
+ <p style="text-align:center;"><input type="submit" value="{L_SUBMIT}" name="submit" class="bouton" /></p>
+
+</fieldset>
+
+<fieldset>
+
+ <legend>Elements</legend>
<!-- BEGIN thumbnails -->
<table valign="top" align="center" class="thumbnail">
@@ -41,4 +138,22 @@
</table>
<!-- END thumbnails -->
+</fieldset>
+
+<fieldset>
+
+ <legend>Display options</legend>
+
+ <p>elements per line :
+ <a href="{U_ELEMENTS_LINE}&amp;display=4">4</a>
+ | <a href="{U_ELEMENTS_LINE}&amp;display=5">5</a>
+ | <a href="{U_ELEMENTS_LINE}&amp;display=6">6</a>
+ | <a href="{U_ELEMENTS_LINE}&amp;display=7">7</a>
+ | <a href="{U_ELEMENTS_LINE}&amp;display=8">8</a>
+ | <a href="{U_ELEMENTS_LINE}&amp;display=9">9</a>
+ | <a href="{U_ELEMENTS_LINE}&amp;display=10">10</a>
+ </p>
+
+</fieldset>
+
</form>