diff options
author | plegall <plg@piwigo.org> | 2007-02-14 22:53:02 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2007-02-14 22:53:02 +0000 |
commit | aabdb3e9295474760b2d3fd5d76d2c235970fe16 (patch) | |
tree | a2ced85a4923136c28fd963f52b28f8348cd830f | |
parent | 58a359e3c17b711be1663985e5e7801407eb50ed (diff) |
New: history logs high quality access via action.php. A new column
#history.is_high was added. Filter was added on administration history
detail view.
Modification: function get_sql_condition_FandF was slightly refactored for
presentation improvement.
git-svn-id: http://piwigo.org/svn/trunk@1817 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | action.php | 24 | ||||
-rw-r--r-- | admin/history.php | 101 | ||||
-rw-r--r-- | admin/include/functions.php | 101 | ||||
-rw-r--r-- | include/functions.inc.php | 4 | ||||
-rw-r--r-- | include/functions_user.inc.php | 43 | ||||
-rw-r--r-- | install/db/51-database.php | 61 | ||||
-rw-r--r-- | install/phpwebgallery_structure.sql | 1 | ||||
-rw-r--r-- | template/yoga/admin/history.tpl | 42 |
8 files changed, 340 insertions, 37 deletions
diff --git a/action.php b/action.php index 586d730a3..73ac6d72b 100644 --- a/action.php +++ b/action.php @@ -61,17 +61,17 @@ function do_error( $code, $str ) } -if ( !isset($_GET['id']) or !is_numeric($_GET['id']) +if (!isset($_GET['id']) + or !is_numeric($_GET['id']) or !isset($_GET['part']) or !in_array($_GET['part'], array('t','e','i','h') ) ) { do_error(400, 'Invalid request - id/part'); } -$id = $_GET['id']; $query = ' SELECT * FROM '. IMAGES_TABLE.' - WHERE id='.$id.' + WHERE id='.$_GET['id'].' ;'; $result = pwg_query($query); @@ -84,11 +84,14 @@ if ( empty($element_info) ) // $filter['visible_categories'] and $filter['visible_images'] // are not used because it's not necessary (filter <> restriction) $query=' -SELECT id FROM '.CATEGORIES_TABLE.' - INNER JOIN '.IMAGE_CATEGORY_TABLE.' - ON category_id=id - WHERE image_id='.$id.' -'.get_sql_condition_FandF(array('forbidden_categories' => 'category_id'), 'AND').' +SELECT id + FROM '.CATEGORIES_TABLE.' + INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON category_id = id + WHERE image_id = '.$_GET['id'].' +'.get_sql_condition_FandF( + array('forbidden_categories' => 'category_id'), + ' AND' + ).' LIMIT 1 ;'; if ( mysql_num_rows(pwg_query($query))<1 ) @@ -123,6 +126,11 @@ if ( empty($file) ) do_error(404, 'Requested file not found'); } +if ($_GET['part'] == 'h') { + $is_high = true; + pwg_log($_GET['id'], $is_high); +} + $http_headers = array(); $ctype = null; diff --git a/admin/history.php b/admin/history.php index ea7add177..516e940cf 100644 --- a/admin/history.php +++ b/admin/history.php @@ -94,6 +94,9 @@ if (isset($_POST['submit'])) ); } + $search['fields']['pictures'] = $_POST['pictures']; + $search['fields']['high'] = $_POST['high']; + // echo '<pre>'; print_r($search); echo '</pre>'; if (!empty($search)) @@ -181,6 +184,46 @@ SELECT rules ); } + if (isset($page['search']['fields']['pictures'])) + { + $clause = null; + + if ($page['search']['fields']['pictures'] == 'no') + { + $clause = 'image_id IS NULL'; + } + + if ($page['search']['fields']['pictures'] == 'only') + { + $clause = 'image_id IS NOT NULL'; + } + + if (isset($clause)) + { + array_push($clauses, $clause); + } + } + + if (isset($page['search']['fields']['high'])) + { + $clause = null; + + if ($page['search']['fields']['high'] == 'no') + { + $clause = "is_high IS NULL or is_high = 'false'"; + } + + if ($page['search']['fields']['high'] == 'only') + { + $clause = "is_high = 'true'"; + } + + if (isset($clause)) + { + array_push($clauses, $clause); + } + } + $clauses = prepend_append_array_items($clauses, '(', ')'); $where_separator = @@ -198,7 +241,16 @@ SELECT COUNT(*) list($page['nb_lines']) = mysql_fetch_row(pwg_query($query)); $query = ' -SELECT date, time, user_id, IP, section, category_id, tag_ids, image_id +SELECT + date, + time, + user_id, + IP, + section, + category_id, + tag_ids, + image_id, + is_high FROM '.HISTORY_TABLE.' WHERE '.$where_separator.' LIMIT '.$page['start'].', '.$conf['nb_logs_page'].' @@ -298,6 +350,18 @@ SELECT id, IF(name IS NULL, file, name) AS label 'T_CLASS' => ($i++ % 2) ? 'row1' : 'row2', ) ); + + if (isset($line['image_id'])) + { + if ($line['is_high'] == 'true') + { + $template->assign_block_vars('detail.high', array()); + } + else + { + $template->assign_block_vars('detail.no_high', array()); + } + } } } @@ -351,11 +415,14 @@ if (isset($page['search'])) if (isset($page['search']['fields']['date-before'])) { $tokens = explode('-', $page['search']['fields']['date-before']); - - (int)$tokens[0]; - (int)$tokens[1]; - (int)$tokens[2]; + + $form['end_year'] = (int)$tokens[0]; + $form['end_month'] = (int)$tokens[1]; + $form['end_day'] = (int)$tokens[2]; } + + $form['pictures'] = $page['search']['fields']['pictures']; + $form['high'] = $page['search']['fields']['high']; } else { @@ -364,6 +431,8 @@ else $form['start_year'] = $form['end_year'] = date('Y'); $form['start_month'] = $form['end_month'] = date('n'); $form['start_day'] = $form['end_day'] = date('j'); + $form['pictures'] = 'yes'; + $form['high'] = 'yes'; } // start date @@ -379,6 +448,28 @@ $template->assign_vars( 'END_YEAR' => @$form['end_year'], ) ); + +foreach (array('pictures', 'high') as $block) +{ + foreach (array('yes', 'no', 'only') as $item) + { + $selected = ''; + + if ($item == $form[$block]) + { + $selected = 'selected="selected"'; + } + + $template->assign_block_vars( + $block.'_option', + array( + 'VALUE' => $item, + 'CONTENT' => l10n($item), + 'SELECTED' => $selected, + ) + ); + } +} // +-----------------------------------------------------------------------+ // | html code display | diff --git a/admin/include/functions.php b/admin/include/functions.php index 4c56dc20f..ad493f877 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -606,7 +606,7 @@ function mass_updates($tablename, $dbfields, $datas) UPDATE '.$tablename.' SET '; $is_first = true; - foreach ($dbfields['update'] as $num => $key) + foreach ($dbfields['update'] as $key) { if (!$is_first) { @@ -625,13 +625,16 @@ function mass_updates($tablename, $dbfields, $datas) } $query.= ' WHERE '; - foreach ($dbfields['primary'] as $num => $key) + + $is_first = true; + foreach ($dbfields['primary'] as $key) { - if ($num > 1) + if (!$is_first) { $query.= ' AND '; } $query.= $key.' = \''.$data[$key].'\''; + $is_first = false; } $query.= ' ;'; @@ -1902,6 +1905,97 @@ SELECT image_id } /** + * Create an XML file with PhpWebGallery informations about a list of + * pictures. + * + * The goal of the export feature is to make easier the reading of + * informations related to pictures outside of PhpWebGallery. + * + * @param array image_ids + */ +function export_pwg_data($image_ids) +{ + global $conf; + + if (count($image_ids) == 0) + { + return; + } + + $fp = fopen($conf['export_file'], 'w'); + $xml_string = '<export>'."\n"; + + $query = ' +SELECT tag_id, + image_id + FROM '.IMAGE_TAG_TABLE.' + WHERE image_id IN ('.implode(',', $image_ids).') +;'; + $result = pwg_query($query); + $tags_of = array(); + $all_tag_ids = array(); + $tag_name_of = array(); + + if (mysql_num_rows($result)) + { + while ($row = mysql_fetch_array($result)) + { + array_push($all_tag_ids, $row['tag_id']); + + if (!isset($tags_of[ $row['image_id'] ])) { + $tags_of[ $row['image_id'] ] = array(); + } + + array_push( + $tags_of[ $row['image_id'] ], + $row['tag_id'] + ); + } + + $all_tag_ids = array_unique($all_tag_ids); + + $query = ' +SELECT id, + name + FROM '.TAGS_TABLE.' + WHERE id IN ('.implode(',', $all_tag_ids).') +;'; + $result = pwg_query($query); + + while ($row = mysql_fetch_array($result)) + { + $tag_name_of[ $row['id'] ] = $row['name']; + } + } + + $query = ' +SELECT id, + path + FROM '.IMAGES_TABLE.' + WHERE id IN ('.implode(',', $image_ids).') +;'; + $result = pwg_query($query); + + while ($row = mysql_fetch_array($result)) + { + $xml_string.= " <photo>\n"; + $xml_string.= " <id>".$row['id']."</id>\n"; + $xml_string.= " <path>".$row['path']."</path>\n"; + + foreach ($tags_of[ $row['id'] ] as $tag_id) + { + $xml_string.= " <tag>".$tag_name_of[$tag_id]."</tag>\n"; + } + + $xml_string.= " </photo>\n"; + } + + $xml_string.= '</export>'; + fwrite($fp, $xml_string); + fclose($fp); +} + +/** * Check configuration and add notes on problem * * @param void @@ -1937,7 +2031,6 @@ function check_conf() ); } } - /** * Refer main PhpWebGallery URLs (currently PHPWG_DOMAIN domain) * diff --git a/include/functions.inc.php b/include/functions.inc.php index 42e54415c..c52fa5457 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -410,7 +410,7 @@ function replace_search( $string, $search ) return $string; } -function pwg_log($image_id = null) +function pwg_log($image_id = null, $is_high = false) { global $conf, $user, $page; @@ -468,6 +468,7 @@ INSERT INTO '.HISTORY_TABLE.' section, category_id, image_id, + is_high, tag_ids ) VALUES @@ -483,6 +484,7 @@ INSERT INTO '.HISTORY_TABLE.' '.(isset($page['section']) ? "'".$page['section']."'" : 'NULL').', '.(isset($page['category']) ? $page['category'] : 'NULL').', '.(isset($image_id) ? $image_id : 'NULL').', + '.(isset($image_id) ? "'".boolean_to_string($is_high)."'" : 'NULL').', '.(isset($tags_string) ? "'".$tags_string."'" : 'NULL').' ) ;'; diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index bf514ed31..b1ddddf0f 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -1089,22 +1089,20 @@ function get_email_address_as_display_text($email_address) } /* - * Compute sql where condition with restrict and filter data + * Compute sql where condition with restrict and filter data. "FandF" means + * Forbidden and Filters. * - * FandF: Forbidden and Filters - * - * @param $condition_fields array: - * keys are condition to aply and - * values are sql field to use - * array('forbidden_categories' => 'ic.category_id') - * $prefix_condition string: - * this value are concatenated if sql is not empty - * $force_one_condition: - * if there are not condition , use this condition "1 = 1" + * @param array condition_fields: read function body + * @param string prefix_condition: prefixes sql if condition is not empty + * @param boolean force_one_condition: use at least "1 = 1" * * @return string sql where/conditions */ -function get_sql_condition_FandF($condition_fields, $prefix_condition = null, $force_one_condition = false) +function get_sql_condition_FandF( + $condition_fields, + $prefix_condition = null, + $force_one_condition = false + ) { global $user, $filter; @@ -1115,30 +1113,37 @@ function get_sql_condition_FandF($condition_fields, $prefix_condition = null, $f switch($condition) { case 'forbidden_categories': + { if (!empty($user['forbidden_categories'])) { - $sql_list[] = $field_name.' NOT IN ('.$user['forbidden_categories'].')'; + $sql_list[] = + $field_name.' NOT IN ('.$user['forbidden_categories'].')'; } break; - + } case 'visible_categories': + { if (!empty($filter['visible_categories'])) { - $sql_list[] = $field_name.' IN ('.$filter['visible_categories'].')'; + $sql_list[] = + $field_name.' IN ('.$filter['visible_categories'].')'; } break; - + } case 'visible_images': + { if (!empty($filter['visible_images'])) { - $sql_list[] = $field_name.' IN ('.$filter['visible_images'].')'; + $sql_list[] = + $field_name.' IN ('.$filter['visible_images'].')'; } break; - + } default: + { die('Unknow condition'); break; - + } } } diff --git a/install/db/51-database.php b/install/db/51-database.php new file mode 100644 index 000000000..21b22d18b --- /dev/null +++ b/install/db/51-database.php @@ -0,0 +1,61 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $Id: 45-database.php 1741 2007-01-22 21:47:03Z vdigital $ +// | last update : $Date: 2007-01-22 22:47:03 +0100 (lun., 22 janv. 2007) $ +// | last modifier : $Author: vdigital $ +// | revision : $Revision: 1741 $ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +if (!defined('PHPWG_ROOT_PATH')) +{ + die('Hacking attempt!'); +} + +$upgrade_description = 'Add #history.is_high column'; + +include_once(PHPWG_ROOT_PATH.'include/constants.php'); + +// +-----------------------------------------------------------------------+ +// | Upgrade content | +// +-----------------------------------------------------------------------+ + +$query = " +ALTER TABLE ".HISTORY_TABLE." + ADD COLUMN is_high ENUM('true', 'false') DEFAULT NULL +;"; +pwg_query($query); + +$query = " +UPDATE ".HISTORY_TABLE." + SET is_high = 'false' + WHERE image_id IS NOT NULL + AND is_high IS NULL +;"; +pwg_query($query); + +echo +"\n" +.'"'.$upgrade_description.'"'.', ended' +."\n" +; + +?> diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql index 52c671eba..0b39c9018 100644 --- a/install/phpwebgallery_structure.sql +++ b/install/phpwebgallery_structure.sql @@ -126,6 +126,7 @@ CREATE TABLE `phpwebgallery_history` ( `tag_ids` varchar(50) default NULL, `image_id` mediumint(8) default NULL, `summarized` enum('true','false') default 'false', + `is_high` enum('true','false') default NULL, PRIMARY KEY (`id`), KEY `history_i1` (`summarized`) ) TYPE=MyISAM; diff --git a/template/yoga/admin/history.tpl b/template/yoga/admin/history.tpl index 746890ab8..f0d364d6f 100644 --- a/template/yoga/admin/history.tpl +++ b/template/yoga/admin/history.tpl @@ -49,6 +49,39 @@ </li> </ul> + <ul> + <li><label></label></li> + <li></li> + </ul> + + <label> + {lang:Pictures} + <select name="pictures"> + <!-- BEGIN pictures_option --> + <option + value="{pictures_option.VALUE}" + {pictures_option.SELECTED} + > + {pictures_option.CONTENT} + </option> + <!-- END pictures_option --> + </select> + </label> + + <label> + {lang:High quality} + <select name="high"> + <!-- BEGIN high_option --> + <option + value="{high_option.VALUE}" + {high_option.SELECTED} + > + {high_option.CONTENT} + </option> + <!-- END high_option --> + </select> + </label> + <input class="submit" type="submit" name="submit" value="{lang:submit}" {TAG_INPUT_ENABLED}/> </fieldset> </form> @@ -68,6 +101,7 @@ <th>{lang:user}</th> <th>{lang:IP}</th> <th>{lang:image}</th> + <th>{lang:high quality}</th> <th>{lang:section}</th> <th>{lang:category}</th> <th>{lang:tags}</th> @@ -79,6 +113,14 @@ <td>{detail.USER}</td> <td>{detail.IP}</td> <td>{detail.IMAGE}</td> + <td> + <!-- BEGIN high --> + <img src="{themeconf:icon_dir}/check.png" alt="{lang:yes}"> + <!-- END high --> + <!-- BEGIN no_high --> + <img src="{themeconf:icon_dir}/uncheck.png" alt="{lang:no}"> + <!-- END no_high --> + </td> <td>{detail.SECTION}</td> <td>{detail.CATEGORY}</td> <td>{detail.TAGS}</td> |