diff --git a/main/css/blue_lagoon/default.css b/main/css/blue_lagoon/default.css index 7ffc173428..806dbcdffb 100755 --- a/main/css/blue_lagoon/default.css +++ b/main/css/blue_lagoon/default.css @@ -3024,7 +3024,8 @@ a.read { } .message-group-date { color:#666; - float:right; + width:100%; + text-align:right; } .view-message-content { line-height:150%; @@ -3185,6 +3186,13 @@ a.read { .profile_grid_element_1 { width:170px; float:left; text-align:left; margin-bottom:1px; } +/* pagination grid sortable */ +.sub_header {width:100%} +.grid_selectbox {float:left;width:35%} +.grid_title {float:left;width:30%;text-align:center} +.grid_nav {float:left;width:35%;text-align:right} + + /* Groups boxes */ .group_invitation_grid_container { width:100%;} diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 0b26b673c1..ef4121f113 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -321,10 +321,39 @@ class Display { if (is_array($query_vars)) { $table->set_additional_parameters($query_vars); } - $table->display_simple_grid($vibility_options, $paging_options['hide_navigation']); + echo $table->display_simple_grid($vibility_options, $paging_options['hide_navigation']); } - + /** + * gets a nice grid in html string + * @param string grid name (important to create css) + * @param array header content + * @param array array with the information to show + * @param array $paging_options Keys are: + * 'per_page_default' = items per page when switching from + * full- list to per-page-view + * 'per_page' = number of items to show per page + * 'page_nr' = The page to display + * 'hide_navigation' = true to hide the navigation + * @param array $query_vars Additional variables to add in the query-string + * @param array $form actions Additional variables to add in the query-string + * @param mixed An array with bool values to know which columns show. i.e: $vibility_options= array(true, false) we will only show the first column + * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing + * @param bool true for sorting data or false otherwise + * @return string html grid + */ + public static function return_sortable_grid ($name, $header, $content, $paging_options = array (), $query_vars = null, $form_actions=array(), $vibility_options = true, $sort_data = true) { + global $origin; + $column = 0; + $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20; + $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name); + + if (is_array($query_vars)) { + $table->set_additional_parameters($query_vars); + } + //var_dump($table->get_additional_url_paramstring()); + return $table->display_simple_grid($vibility_options, $paging_options['hide_navigation'], $paging_options['per_page'], $sort_data); + } /** * Display a table with a special configuration diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 4081493d2f..02624b2864 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -836,9 +836,13 @@ class MessageManager $rows = self::get_messages_by_group($group_id); $rows = self::calculate_children($rows); $group_info = GroupPortalManager::get_group_data($group_id); - $current_user_id = api_get_user_id(); + $current_user_id = api_get_user_id(); + $topics_per_page = 5; + $items_per_page = 3; $count_items = 0; - $html = ''; + $html_messages = ''; + $query_vars = array('id'=>$group_id,'topics_page_nr'=>0); + if (is_array($rows) && count($rows)> 0) { // prepare array for topics with its items @@ -852,25 +856,12 @@ class MessageManager $topics[$x]['items'][] = $value; } } - uasort($topics,array('MessageManager','order_desc_date')); - - // pager - $page = isset($_GET['page_nr'])?intval($_GET['page_nr']):1; - $total_topics = count($topics); - $topics_per_page = 5; - $pager = self::get_pager_for_message_group($group_id,$page,$total_topics,$topics_per_page); - + uasort($topics,array('MessageManager','order_desc_date')); - // topics and items - $parents = array_keys(self::get_messages_by_parent(0,$group_id,$page,$topics_per_page)); - $html .= '
'; - $html .= '
- -
 '.$pager['details'].''.$pager['links'].'
'; + $param_names = array_keys($_GET); + $array_html = array(); foreach ($topics as $index => $topic) { - - if (!in_array($index,$parents)) continue; - + $html = ''; // topics $indent = 0; $user_sender_info = UserManager::get_user_info_by_id($topic['user_sender_id']); @@ -880,179 +871,91 @@ class MessageManager $html .= '
'; $html .= '
'.Display::return_icon('content-post-group1.jpg').'
'; $html .= ''; + $array_html[] = array($html); } - $html .= '
'; + // grids for items and topics with paginations - /* - // pager - $html .= '
- -
  '.$pager['links'].'
'; - */ - } - return $html; - } - - /** - * Get pager for messages of group - * @param int group id - * @param int current page - * @param int total rows - * @param int rows per page - * @return array pager with details and links - */ - public static function get_pager_for_message_group($group_id,$page,$num_rows,$rows_per_page,$pager_items = false,$div_content='') { - - $link = ''; - $details = ''; - $pager = array(); - $group_id = intval($group_id); - $page = intval($page); - $num_rows = intval($num_rows); - $first_page = 1; - $last_page = ceil($num_rows/$rows_per_page); - - // get details - if ($page == $first_page) { - $details = $page.' - '.($page*$rows_per_page).' / '.$num_rows; - } else if ($page > $first_page && $page < $last_page) { - $details = ((($page-1)*$rows_per_page)+1).' - '.($page*$rows_per_page).' / '.$num_rows; - } else { - $details = ((($page-1)*$rows_per_page)+1).' - '.($num_rows).' / '.$num_rows; - } - $pager['details'] = $details; - - - // get links for pager - $href = api_get_path(WEB_CODE_PATH).'social/groups.php?id='.$group_id; - - if ($pager_items) { - $page_topic = isset($_GET['page_nr'])?intval($_GET['page_nr']):1; - $param_name_page_nr = '&page_nr='.$page_topic.'&div_id='.$div_content.'&page_item_nr='; - } else { - $param_name_page_nr = '&page_nr='; + $html_messages .= '
'; + $html_messages .= Display::return_sortable_grid('topics', array(), $array_html, array('hide_navigation'=>false, 'per_page' => $topics_per_page), $query_vars, false, array(true, true, true,false), false); + $html_messages .= '
'; } - if ($page > 1) { - $link .= ''; - $link .= Display::return_icon('first.png',get_lang('FirstPage'),array('style'=>'vertical-align: middle')); - $link .= ''; - $link .= ''; - $link .= Display::return_icon('prev.png',get_lang('PreviousPage'),array('style'=>'vertical-align: middle')); - $link .= ''; - } - $link .= $page.'/'.$last_page; - - if ($page < $last_page) { - $link .= ''; - $link .= Display::return_icon('next.png',get_lang('NextPage'),array('style'=>'vertical-align: middle')); - $link .= ''; - $link .= ''; - $link .= Display::return_icon('last.png',get_lang('PreviousPage'),array('style'=>'vertical-align: middle')); - $link .= ''; - } - $pager['links'] = $link; - return $pager; + return $html_messages; } - /** * Add children to messages by id is used for nested view messages diff --git a/main/inc/lib/sortabletable.class.php b/main/inc/lib/sortabletable.class.php index dcc55ea62d..9d40d12b24 100755 --- a/main/inc/lib/sortabletable.class.php +++ b/main/inc/lib/sortabletable.class.php @@ -429,7 +429,16 @@ class SortableTable extends HTML_Table { echo $html; } - public function display_simple_grid($vibility_options, $hide_navigation) { + /** + * This function return the content of a table in a grid + * Should not be use to edit information (edit/delete rows) only. + * @param array options of visibility + * @param bool hide navigation optionally + * @param int content per page when show navigation (optional) + * @param bool sort data optionally + * @return string grid html + */ + public function display_simple_grid($vibility_options, $hide_navigation = true, $per_page = 0, $sort_data = true) { global $charset; $empty_table = false; $html = ''; @@ -448,19 +457,21 @@ class SortableTable extends HTML_Table { if (!$empty_table) { //if we show the pagination - if ($hide_navigation == false ) { - $form = $this->get_page_select_form(); - $nav = $this->get_navigation_html(); - + if ($hide_navigation == false ) { + $form = ' '; + if ($per_page > 10) { + $form = $this->get_page_select_form(); + } + $nav = $this->get_navigation_html(); //this also must be moved - $html = '
'; - $html .= '
'.$form.'
'; + $html = '
'; + $html .= '
'.$form.'
'; $html .= '
'.$this->get_table_title().'
'; $html .= '
'.$nav.'
'; $html .= '
'; } - //$html .= '
'; + $html .= '
'; if (count($this->form_actions) > 0) { $script= ''; $htmlHeadXtra[] = ''; +// prepare anchor for message group topic +$anchor = ''; +if (isset($_GET['anchor_topic'])) { + $anchor = Security::remove_XSS($_GET['anchor_topic']); +} else { + $match = 0; + $param_names = array_keys($_GET); + foreach ($param_names as $param) { + if (preg_match('/^items_(\d)_page_nr$/', $param, $match)) { + break; + } + } + $anchor = 'topic_'.$match[1]; +} + $htmlHeadXtra[] = '