From de11ff8e7bf6bac35ef9d3fecca5a94252463606 Mon Sep 17 00:00:00 2001 From: Nigel Osborne Date: Sun, 20 Feb 2011 21:14:22 +0000 Subject: Bug #722090 Sort Errors in recent changes module --- includes/functions/functions_print_lists.php | 337 ++++++++++++++++----------- modules/recent_changes/help_text.php | 6 + modules/recent_changes/module.php | 278 ++++++++++++---------- 3 files changed, 362 insertions(+), 259 deletions(-) diff --git a/includes/functions/functions_print_lists.php b/includes/functions/functions_print_lists.php index f14dc66f6a..4283d97a89 100644 --- a/includes/functions/functions_print_lists.php +++ b/includes/functions/functions_print_lists.php @@ -1321,149 +1321,212 @@ function format_surname_list($surnames, $style, $totals, $type) { } +/** + * print a list of recent changes + * + * @param array $change_ids contain records that were extracted from the database. + * @param string $sort determines what to sort + * @param bool $show_parents + */ +function print_changes_list($change_ids, $sort, $show_parents=false) { + global $SHOW_MARRIED_NAMES, $TEXT_DIRECTION, $WT_IMAGES; + define('NMAX', 1000); + $n = 0; + foreach ($change_ids as $change_id) { + if ($n >= NMAX) + break; + $record = WT_GedcomRecord::getInstance($change_id); + if (!$record || !$record->canDisplayDetails()) { + continue; + } + // setup sorting parameters + $arr[$n]['record'] = $record; + $arr[$n]['jd'] = ($sort == 'name') ? 1 : $n; + $arr[$n]['anniv'] = strtotime(str_replace('-', '', $record->LastChangeTimestamp(false))); + $arr[$n++]['fact'] = $record->getSortName(); // in case two changes have same timestamp + } + + switch ($sort) { + case 'name': + uasort($arr, 'event_sort_name'); + break; + case 'date_asc': + uasort($arr, 'event_sort'); + $arr = array_reverse($arr); + break; + case 'date_desc': + uasort($arr, 'event_sort'); + } + $return = ''; + foreach ($arr as $value) { + $return .= "getHtmlUrl() . "' class='list_item name2' dir='" . $TEXT_DIRECTION . "'>" . PrintReady($value['record']->getFullName()) . ""; + $return .= "
"; + if ($value['record']->getType() == 'INDI') { + if ($value['record']->getAddName()) { + $return .= "getHtmlUrl() . "' class='list_item'>" . PrintReady($value['record']->getAddName()) . ""; + } + if ($SHOW_MARRIED_NAMES) { + foreach ($value['record']->getAllNames() as $name) { + if ($name['type'] == '_MARNM') { + $return .= "
getHtmlUrl() . "' class='list_item'>" . PrintReady($name['full']) . "
"; + } + } + } + if ($show_parents) { + $return .= $value['record']->getPrimaryParentsNames('details1'); + } + } + $return .= "
"; + //-- Last change date/time & user + $return .= WT_I18N::translate("Changed on %s by %s", $value['record']->LastChangeTimestamp(empty($SEARCH_SPIDER)), $value['record']->LastChangeUser()); + $return .= "
"; // class='indent' + $return .= "
"; + } + $return .= WT_I18N::translate('Showing 1 to %d of %d entries', $n,$n); + if ($n >= NMAX) { + $return .= "
" . WT_I18N::translate('Total changes exceed limit (%d)', NMAX) . "
"; + } + return $return; +} + /** * print a sortable table of recent changes - * also called by mediaviewer to list records linked to a media * - * @param array $datalist contain records that were extracted from the database. + * @param array $change_ids contain records that were extracted from the database. + * @param string $sort determines what to sort + * @param bool $show_parents */ -function print_changes_table($change_ids) { - global $SHOW_MARRIED_NAMES, $TEXT_DIRECTION, $WT_IMAGES; - if (!$change_ids) return; -// require_once WT_ROOT.'js/sorttable.js.htm'; - $table_id = "ID".floor(microtime()*1000000); // sorttable requires a unique ID - echo WT_JS_START.'var table_id = "'.$table_id.'"'.WT_JS_END; - ?> - - - ', - '', - ' ', - '', WT_I18N::translate('Record'), '', - 'GIVN', - '', translate_fact('CHAN'), '', - '', translate_fact('_WT_USER'), '', - ''; - //-- table body - echo ''; - $n = 0; - $NMAX = 1000; - $indi = false; - foreach ($change_ids as $change_id) { - if ($n>=$NMAX) break; - $record=WT_GedcomRecord::getInstance($change_id); - if (!$record || !$record->canDisplayDetails()) { - continue; - } - //-- Counter - echo - '', - ''; - switch ($record->getType()) { - case "INDI": - echo $record->getSexImage('small', '', '', false); - $indi=true; - break; - case "FAM": - echo ''; - $indi = false; - break; - case "OBJE": - echo ''; - $indi = false; - break; - case "NOTE": - echo ''; - $indi = false; - break; - case "SOUR": - echo ''; - $indi = false; - break; - case "REPO": - echo ''; - $indi = false; - break; - default: - $indi = false; - break; - } - echo ''; - ++$n; - //-- Record name(s) - $name = $record->getFullName(); - echo - '', - '', PrintReady($name), ''; - $addname=$record->getAddName(); - if ($addname) { - echo '
', PrintReady($addname), ''; - } - if ($indi) { - if ($SHOW_MARRIED_NAMES) { - foreach ($record->getAllNames() as $name) { - if ($name['type']=='_MARNM') { - echo '
', PrintReady($name['full']), ''; - } - } - } - echo $record->getPrimaryParentsNames("parents_$table_id details1", "none"); - } - echo ''; - //-- GIVN - echo ''; - $exp = explode(",", str_replace('<', ',', $name).","); - echo $exp[1]; - echo ''; - //-- Last change date/time - echo '', $record->LastChangeTimestamp(empty($SEARCH_SPIDER)), ''; - //-- Last change user - echo '', $record->LastChangeUser(empty($SEARCH_SPIDER)), ''; - echo ''; - } - echo ''; - //-- table footer - echo - '', - ''; - if ($n>1 && $indi) { - echo ' ', translate_fact('GIVN'), '
'; - } - if ($indi) { - echo "
"; - } - echo WT_I18N::translate('Total changes'), ': ', $n; - if ($n>=$NMAX) echo '
', WT_I18N::translate('Recent changes'), ' > ', $NMAX, ''; - echo - '', - 'GIVN', - '', - '', - '', - ''; +function print_changes_table($change_ids, $sort, $show_parents=false) { + global $SHOW_MARRIED_NAMES, $TEXT_DIRECTION, $WT_IMAGES; + define('NMAX', 1000); + $return = ''; + $n = 0; + $table_id = "ID" . floor(microtime() * 1000000); // sorttable requires a unique ID + switch ($sort) { + case 'name': //name + $aaSorting = "[5,'asc'], [4,'desc']"; + break; + case 'date_asc': //date ascending + $aaSorting = "[4,'asc'], [5,'asc']"; + break; + case 'date_desc': //date descending + $aaSorting = "[4,'desc'], [5,'asc']"; + } + echo WT_JS_START . 'var table_id = "' . $table_id . '"' . WT_JS_END; +?> + + +"; + $return .= ""; + $return .= ""; + $return .= "" . WT_I18N::translate('Record') . ""; + $return .= "" . translate_fact('CHAN') . ""; + $return .= "" . translate_fact('_WT_USER') . ""; + $return .= "DATE"; //hidden by datatables code + $return .= "SORTNAME"; //hidden by datatables code + $return .= ""; + //-- table body + + foreach ($change_ids as $change_id) { + if ($n >= NMAX) + break; + $record = WT_GedcomRecord::getInstance($change_id); + if (!$record || !$record->canDisplayDetails()) { + continue; + } + $return .= ""; + $indi = false; + switch ($record->getType()) { + case "INDI": + $return .= $record->getSexImage('small', '', '', false); + $indi = true; + break; + case "FAM": + $return .= ''; + break; + case "OBJE": + $return .= ''; + break; + case "NOTE": + $return .= ''; + break; + case "SOUR": + $return .= ''; + break; + case "REPO": + $return .= ''; + break; + default: + break; + } + $return .= ""; + ++$n; + //-- Record name(s) + $name = $record->getFullName(); + $return .= ""; + $return .= "" . PrintReady($name) . ""; + if ($indi) { + $return .= "
"; + $addname = $record->getAddName(); + if ($addname) { + $return .= "" . PrintReady($addname) . ""; + } + if ($SHOW_MARRIED_NAMES) { + foreach ($record->getAllNames() as $name) { + if ($name['type'] == '_MARNM') { + $return .= "
" . PrintReady($name['full']) . "
"; + } + } + } + if ($show_parents) { + $return .= $record->getPrimaryParentsNames("parents_$table_id details1"); + } + $return .= "
"; //class='indent' + } + $return .= ""; + //-- Last change date/time + $return .= "" . $record->LastChangeTimestamp(empty($SEARCH_SPIDER)) . ""; + //-- Last change user + $return .= "" . $record->LastChangeUser() . ""; + //-- change date (sortable) hidden by datatables code + $return .= "" . strtotime(str_replace('-', '', $record->LastChangeTimestamp(false))) . ""; + //-- names (sortable) hidden by datatables code + $return .= "" . $record->getSortName() . ""; + } + + //-- table footer + $return .= ""; + $return .= ""; + $return .= WT_I18N::translate('Showing 1 to %d of %d entries', $n, $n); + if ($n >= NMAX) { + $return .= "
" . WT_I18N::translate('Total changes exceed limit (%d)', NMAX) . "
"; + } + return $return; } + /** * print a sortable table of events * and generates hCalendar records diff --git a/modules/recent_changes/help_text.php b/modules/recent_changes/help_text.php index 0904064675..99a3538625 100644 --- a/modules/recent_changes/help_text.php +++ b/modules/recent_changes/help_text.php @@ -38,6 +38,12 @@ case 'recent_changes': $text.=WT_I18N::translate('Number of days to show: This is the number of days that webtrees should use when searching for events'); $text.=' ('.WT_I18N::plural('maximum %d day', 'maximum %d days', 30, 30).').'; $text.='
  • '; + $text.=WT_I18N::translate('Presentation Style: Display as a list or in a table.'); + $text.='
  • '; + $text.=WT_I18N::translate('Display Parents: Select whether to display the person\'s parents.'); + $text.='
  • '; + $text.=WT_I18N::translate('Sort Style: Only used when viewing a list; for table view, click on the table headings to sort.'); + $text.='
  • '; $text.=WT_I18N::translate('Should this block be hidden when it is empty?: Provides the option to hide the block if there are no changes to display.'); $text.='
  • '; break; diff --git a/modules/recent_changes/module.php b/modules/recent_changes/module.php index 60f74e553a..7e92c18a8c 100644 --- a/modules/recent_changes/module.php +++ b/modules/recent_changes/module.php @@ -1,4 +1,5 @@ getName().$block_id; - $title=''; - if ($ctype=="gedcom" && WT_USER_GEDCOM_ADMIN || $ctype=='user') { - if ($ctype=="gedcom") { - $name = WT_GEDCOM; - } else { - $name = WT_USER_NAME; - } - $title .= ""; - $title .= "\"".WT_I18N::translate('Configure')."\""; - } - $title.= WT_I18N::translate('Recent changes').help_link('recent_changes', $this->getName()); - - $content = ""; - // Print block content - if (count($found_facts)==0) { - $content .= WT_I18N::translate('There have been no changes within the last %s days.', $days); - } else { - $content .= WT_I18N::translate('Changes made within the last %s days', $days); - // sortable table - require_once WT_ROOT.'includes/functions/functions_print_lists.php'; - ob_start(); - print_changes_table($found_facts); - $content .= ob_get_clean(); - } - - if ($template) { - if ($block) { - require WT_THEME_DIR.'templates/block_small_temp.php'; - } else { - require WT_THEME_DIR.'templates/block_main_temp.php'; - } - } else { - return $content; - } - } - - // Implement class WT_Module_Block - public function loadAjax() { - return true; - } - - // Implement class WT_Module_Block - public function isUserBlock() { - return true; - } - - // Implement class WT_Module_Block - public function isGedcomBlock() { - return true; - } - - // Implement class WT_Module_Block - public function configureBlock($block_id) { - if (safe_POST_bool('save')) { - set_block_setting($block_id, 'days', safe_POST_integer('days', 1, 30, 7)); - set_block_setting($block_id, 'hide_empty', safe_POST_bool('hide_empty')); - set_block_setting($block_id, 'block', safe_POST_bool('block')); - echo WT_JS_START, 'window.opener.location.href=window.opener.location.href;window.close();', WT_JS_END; - exit; - } - - require_once WT_ROOT.'includes/functions/functions_edit.php'; - - $days=get_block_setting($block_id, 'days', 7); - echo ''; - echo WT_I18N::translate('Number of days to show'); - echo ''; - echo ''; - echo ' ', WT_I18N::plural('maximum %d day', 'maximum %d days', 30, 30) ,''; - echo ''; - - $hide_empty=get_block_setting($block_id, 'hide_empty', true); - echo ''; - echo WT_I18N::translate('Should this block be hidden when it is empty?'); - echo ''; - echo edit_field_yes_no('hide_empty', $hide_empty); - echo ''; - echo ''; - echo '', WT_I18N::translate('If you hide an empty block, you will not be able to change its configuration until it becomes visible by no longer being empty.'), ''; - echo ''; - - $block=get_block_setting($block_id, 'block', true); - echo ''; - echo /* I18N: label for a yes/no option */ WT_I18N::translate('Add a scrollbar when block contents grow'); - echo ''; - echo edit_field_yes_no('block', $block); - echo ''; - } + + // Extend class WT_Module + public function getTitle() { + return WT_I18N::translate('Recent changes'); + } + + // Extend class WT_Module + public function getDescription() { + return WT_I18N::translate('This block lists the changes that have been made to all family trees within a specified number of days.'); + } + + // Implement class WT_Module_Block + public function getBlock($block_id, $template=true, $cfg=null) { + global $ctype, $WT_IMAGES; + + $days = get_block_setting($block_id, 'days', 7); + $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); + $show_parents = get_block_setting($block_id, 'show_parents', false); + $sortStyle = get_block_setting($block_id, 'sortStyle', 'datea'); + $hide_empty = get_block_setting($block_id, 'hide_empty', false); + $block = get_block_setting($block_id, 'block', true); + if ($cfg) { + foreach (array('days', 'infoStyle', 'show_parents', 'sortStyle', 'hide_empty', 'block') as $name) { + if (array_key_exists($name, $cfg)) { + $$name = $cfg[$name]; + } + } + } + + $found_facts = get_recent_changes(WT_CLIENT_JD - $days); + + if (empty($found_facts) && $hide_empty) { + return; + } + // Print block header + $id = $this->getName() . $block_id; + $title = ''; + if ($ctype == "gedcom" && WT_USER_GEDCOM_ADMIN || $ctype == 'user') { + if ($ctype == "gedcom") { + $name = WT_GEDCOM; + } else { + $name = WT_USER_NAME; + } + $title .= ""; + $title .= "\"""; + } + $title.= WT_I18N::translate('Last %s days changes', $days) . help_link('recent_changes', $this->getName()); + $content = ""; + // Print block content + if (count($found_facts) == 0) { + $content .= WT_I18N::translate('There have been no changes within the last %s days.', $days); + } else { + ob_start(); + switch ($infoStyle) { + case 'list': + $content .= print_changes_list($found_facts, $sortStyle, $show_parents); + break; + case 'table': + // sortable table + $content .= print_changes_table($found_facts, $sortStyle, $show_parents); + break; + } + $content .= ob_get_clean(); + } + + if ($template) { + if ($block) { + require WT_THEME_DIR . 'templates/block_small_temp.php'; + } else { + require WT_THEME_DIR . 'templates/block_main_temp.php'; + } + } else { + return $content; + } + } + + // Implement class WT_Module_Block + public function loadAjax() { + return true; + } + + // Implement class WT_Module_Block + public function isUserBlock() { + return true; + } + + // Implement class WT_Module_Block + public function isGedcomBlock() { + return true; + } + + // Implement class WT_Module_Block + public function configureBlock($block_id) { + if (safe_POST_bool('save')) { + set_block_setting($block_id, 'days', safe_POST_integer('days', 1, 30, 7)); + set_block_setting($block_id, 'infoStyle', safe_POST('infoStyle', array('list', 'table'), 'table')); + set_block_setting($block_id, 'show_parents', safe_POST_bool('show_parents')); + set_block_setting($block_id, 'sortStyle', safe_POST('sortStyle', array('name', 'date_asc', 'date_desc'), 'date_asc')); + set_block_setting($block_id, 'hide_empty', safe_POST_bool('hide_empty')); + set_block_setting($block_id, 'block', safe_POST_bool('block')); + echo WT_JS_START, 'window.opener.location.href=window.opener.location.href;window.close();', WT_JS_END; + exit; + } + + require_once WT_ROOT . 'includes/functions/functions_edit.php'; + + $days = get_block_setting($block_id, 'days', 7); + echo ''; + echo WT_I18N::translate('Number of days to show'); + echo ''; + echo ''; + echo ' ', WT_I18N::plural('maximum %d day', 'maximum %d days', 30, 30), ''; + echo ''; + + $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); + echo ''; + echo WT_I18N::translate('Presentation style'); //, help_link('style'); + echo ''; + echo select_edit_control('infoStyle', array('list' => WT_I18N::translate('List'), 'table' => WT_I18N::translate('Table')), null, $infoStyle, ''); + echo ''; + + $sortStyle = get_block_setting($block_id, 'sortStyle', 'date'); + echo ''; + echo WT_I18N::translate('Sort Style'); //, help_link('sort_style'); + echo ''; + echo select_edit_control('sortStyle', array('name' => WT_I18N::translate('Alphabetically'), 'date_asc' => WT_I18N::translate('By Date (ascending)'), 'date_desc' => WT_I18N::translate('By Date (descending)')), null, $sortStyle, ''); + echo ''; + + $show_parents = get_block_setting($block_id, 'show_parents', true); + echo ''; + echo WT_I18N::translate('Show Parents?'); + echo ''; + echo edit_field_yes_no('show_parents', $show_parents); + echo ''; + + $block = get_block_setting($block_id, 'block', true); + echo ''; + echo /* I18N: label for a yes/no option */ WT_I18N::translate('Add a scrollbar when block contents grow'); + echo ''; + echo edit_field_yes_no('block', $block); + echo ''; + + $hide_empty = get_block_setting($block_id, 'hide_empty', true); + echo ''; + echo WT_I18N::translate('Should this block be hidden when it is empty?'); + echo ''; + echo edit_field_yes_no('hide_empty', $hide_empty); + echo ''; + echo ''; + echo '', WT_I18N::translate('If you hide an empty block, you will not be able to change its configuration until it becomes visible by no longer being empty.'), ''; + echo ''; + } + } -- cgit v1.3