/** * get html for the page navigation * @param string $page_type type of page * return string html containing page navigation */ function get_page_navigation($page_type) { global $logging; global $user; $highlight_class = "class=\"" . HTML_TAB_TYPE_HIGHLIGHT . " tab_content\""; $html_str = ""; $logging->trace("getting page_navigation (page_type={$page_type})"); $html_str .= "\n <div id=\"navigation_left\">\n"; # set only navigation links when page is not a login page if ($page_type != PAGE_TYPE_LOGIN) { # show portal page link clickable when this is not the portal page if ($page_type != PAGE_TYPE_PORTAL) { $content = get_href(get_query_onclick(ACTION_GET_PORTAL_PAGE, HTML_NO_LIST_PERMISSION_CHECK, "tab_portal_id", "below", "action=" . ACTION_GET_PORTAL_PAGE), translate("BUTTON_PORTAL"), ""); $html_str .= get_tab_navigation(HTML_TAB_TYPE_NORMAL, "tab_portal_id", $content); } else { $html_str .= get_tab_navigation(HTML_TAB_TYPE_HIGHLIGHT, "tab_portal_id", "<div {$highlight_class}>" . translate("BUTTON_PORTAL") . "</div>"); } # show create new list link clickable when this not the list builder page if ($page_type != PAGE_TYPE_LISTBUILDER) { $content = get_href(get_query_onclick(ACTION_GET_LISTBUILDER_PAGE, HTML_NO_LIST_PERMISSION_CHECK, "tab_listbuilder_id", "below", "action=" . ACTION_GET_LISTBUILDER_PAGE), translate("BUTTON_CREATE_NEW_LIST"), ""); $html_str .= get_tab_navigation(HTML_TAB_TYPE_NORMAL, "tab_listbuilder_id", $content); } else { $html_str .= get_tab_navigation(HTML_TAB_TYPE_HIGHLIGHT, "tab_listbuilder_id", "<div {$highlight_class}>" . translate("BUTTON_CREATE_NEW_LIST") . "</div>"); } # show list link non clickable but highlighted when this is list page if ($page_type == PAGE_TYPE_LIST) { $html_str .= get_tab_navigation(HTML_TAB_TYPE_HIGHLIGHT, "tab_list_id", "<div {$highlight_class}>" . translate("BUTTON_LIST") . "</div>"); } else { if (strlen($user->get_current_list_name()) > 0) { $content = get_href(get_query_onclick(ACTION_GET_LIST_PAGE, $user->get_current_list_name(), "tab_list_id", "below", "action=" . ACTION_GET_LIST_PAGE . "&list=" . $user->get_current_list_name()), translate("BUTTON_LIST"), ""); $html_str .= get_tab_navigation(HTML_TAB_TYPE_NORMAL, "tab_list_id", $content); } } # show the user list permissions only when this is a list page if ($page_type == PAGE_TYPE_LIST) { $content = get_href(get_query_onclick(ACTION_GET_USERLISTTABLEPERMISSIONS_PAGE, $user->get_current_list_name(), "tab_list_table_permissions_id", "below", "action=" . ACTION_GET_USERLISTTABLEPERMISSIONS_PAGE), translate("BUTTON_USERLISTTABLEPERMISSIONS"), ""); $html_str .= get_tab_navigation(HTML_TAB_TYPE_NORMAL, "tab_list_table_permissions_id", $content); } else { if ($page_type == PAGE_TYPE_USERLISTTABLEPERMISSIONS) { $html_str .= get_tab_navigation(HTML_TAB_TYPE_HIGHLIGHT, "tab_list_table_permissions_id", "<div {$highlight_class}>" . translate("BUTTON_USERLISTTABLEPERMISSIONS") . "</div>"); } } # show user admin link only when user has at least can_create_user permissions if ($user->is_login() && $user->get_can_create_user()) { # show user admin link clickable when this is not the user admin page if ($page_type != PAGE_TYPE_USER_ADMIN) { $content = get_href(get_query_onclick(ACTION_GET_USER_ADMIN_PAGE, HTML_NO_LIST_PERMISSION_CHECK, "tab_user_admin_id", "below", "action=" . ACTION_GET_USER_ADMIN_PAGE), translate("BUTTON_USER_ADMINISTRATION"), ""); $html_str .= get_tab_navigation(HTML_TAB_TYPE_NORMAL, "tab_user_admin_id", $content); } else { $html_str .= get_tab_navigation(HTML_TAB_TYPE_HIGHLIGHT, "tab_user_admin_id", "<div {$highlight_class}>" . translate("BUTTON_USER_ADMINISTRATION") . "</div>"); } } $html_str .= " </div> <!-- navigation_left -->\n"; $html_str .= " <div id=\"navigation_right\">\n"; # show user settings link non clickable but highlighted when this is the user settings page if ($page_type == PAGE_TYPE_USER_SETTINGS) { $html_str .= get_tab_navigation(HTML_TAB_TYPE_HIGHLIGHT, "tab_user_settings_id", "<div {$highlight_class}>" . translate("BUTTON_USER_SETTINGS") . "</div>"); } else { $content = get_href(get_query_onclick(ACTION_GET_USER_SETTINGS_PAGE, HTML_NO_LIST_PERMISSION_CHECK, "tab_user_settings_id", "left", "action=" . ACTION_GET_USER_SETTINGS_PAGE), translate("BUTTON_USER_SETTINGS"), ""); $html_str .= get_tab_navigation(HTML_TAB_TYPE_NORMAL, "tab_user_settings_id", $content); } $html_str .= " </div> <!-- navigation_right -->\n"; } $html_str .= " "; $logging->trace("got page_navigation"); return $html_str; }
/** * get html (use Result object) for the records of a databasetable * @param $database_table DatabaseTable database table object * @param $list_title string title of list * @param $order_by_field string name of field by which this list needs to be ordered * @param $page int page to be shown (show first page when 0 is given) * @param $result Result result object * @return void */ function get_content($database_table, $list_title, $order_by_field, $page, $result) { $html_str = ""; $field_names = $database_table->get_user_field_names(); $fields = $database_table->get_fields(); $user_fields = $database_table->get_user_fields(); $metadata_str = $database_table->get_metadata_str(); # get lines per page from session $lines_per_page = $this->_user->get_lines_per_page(); $this->_log->trace("get content (list_title={$list_title}, lines_per_page={$lines_per_page})"); # select entries $records = $database_table->select($order_by_field, $page); if (strlen($database_table->get_error_message_str()) > 0 && $database_table->get_error_message_str() != translate("ERROR_DATABASE_EXISTENCE")) { # only show an error when this is not the portal page if ($this->configuration[HTML_TABLE_PAGE_TYPE] != PAGE_TYPE_PORTAL) { $this->_handle_error($database_table, $result, MESSAGE_PANE_DIV); } # no return statement here because we want the complete page to be displayed } # get list_state properties $this->_user->get_list_state($database_table->get_table_name()); $total_pages = $this->_list_state->get_total_pages(); $order_by_field = $this->_list_state->get_order_by_field(); $order_ascending = $this->_list_state->get_order_ascending(); if ($total_pages == 0) { $total_records = 0; $current_page = 0; } else { $total_records = $this->_list_state->get_total_records(); $current_page = $this->_list_state->get_current_page(); } # add contents top $html_str .= "\n <div id=\"" . $this->configuration[HTML_TABLE_CSS_NAME_PREFIX] . "contents_top\">\n"; $html_str .= " <div class=\"corner top_left_normal\"></div>\n"; $html_str .= " <div class=\"corner top_right_normal\"></div>\n"; if ($page != DATABASETABLE_ALL_PAGES) { $archive_select = FALSE; $filter = FALSE; # add archive select mechanism only when list supports archived records if ($metadata_str[DATABASETABLE_METADATA_ENABLE_ARCHIVE] != DATABASETABLE_METADATA_FALSE) { $html_str .= $this->get_archive_select($database_table, $list_title); $archive_select = TRUE; } # add filter only for lists if ($this->configuration[HTML_TABLE_PAGE_TYPE] == PAGE_TYPE_LIST) { $html_str .= $this->get_filter($database_table, $list_title); $filter = TRUE; } if (!$archive_select && !$filter) { $html_str .= " \n"; } # add record summary if ($current_page == 0) { $first_record = 0; $last_record = 0; } else { $first_record = ((int) $current_page - 1) * $lines_per_page + 1; $last_record = $first_record + count($records) - 1; } $html_str .= " <div id=\"" . $this->configuration[HTML_TABLE_CSS_NAME_PREFIX] . "pages_top\">"; $html_str .= translate("LABEL_RECORDS") . " " . $first_record . " - "; $html_str .= $last_record . " " . translate("LABEL_OF") . " " . $total_records . " " . translate("LABEL_RECORDS") . "</div>\n"; } else { $html_str .= " \n"; } $html_str .= " </div> <!-- " . $this->configuration[HTML_TABLE_CSS_NAME_PREFIX] . "contents_top -->\n"; # start with the table definition # this is a different table when all pages have to be displayed $html_str .= " <table id=\"" . $this->configuration[HTML_TABLE_CSS_NAME_PREFIX] . "contents\" align=\"left\">\n"; # now the first record containing the field names $html_str .= " <thead>\n"; $html_str .= " <tr>\n"; $field_names_with_length = array(); foreach ($field_names as $field_name) { $db_field_name = $user_fields[$field_name]; # replace all space chars with   $field_name_replaced = str_replace(' ', ' ', $field_name); # translate field_name when this is not a list table if ($this->configuration[HTML_TABLE_PAGE_TYPE] != PAGE_TYPE_LIST) { $field_name_replaced = str_replace(' ', ' ', translate($field_name)); } else { if ($fields[$db_field_name][1] == FIELD_TYPE_DEFINITION_ATTACHMENTS) { $field_name_replaced = "@"; } } #$this->_log->info("showing field: $field_name, ".$fields[$db_field_name][3]); # only display field names that have a length if (strlen($field_name) > 0 && $fields[$db_field_name][3] != COLUMN_NO_SHOW) { $sort_name = $user_fields[$field_name]; # change names to sort by for automatic creator and modifier fields if ($fields[$sort_name][1] == FIELD_TYPE_DEFINITION_AUTO_CREATED) { $sort_name = DB_TS_CREATED_FIELD_NAME; } else { if ($fields[$sort_name][1] == FIELD_TYPE_DEFINITION_AUTO_MODIFIED) { $sort_name = DB_TS_MODIFIED_FIELD_NAME; } } # set class name to determine arrow image $class_name = "sort"; if ($order_by_field == $sort_name) { if ($order_ascending) { $class_name .= "_up"; } else { $class_name .= "_down"; } } $html_str .= " <th "; $action_get_str = "action_get_" . $this->configuration[HTML_TABLE_JS_NAME_PREFIX] . "content"; $html_str .= get_onclick($action_get_str, HTML_NO_PERMISSION_CHECK, "", "", "('{$list_title}', '{$sort_name}', {$current_page})"); $html_str .= "><div class=\"{$class_name}\">{$field_name_replaced}</div></th>\n"; array_push($field_names_with_length, $field_name); } } # add extra table header to compensate for extra button table data's $html_str .= " <th colspan=3></th>\n"; $html_str .= " </tr>\n"; $html_str .= " </thead>\n"; $html_str .= " <tbody>\n"; # now all the records $record_number = 0; foreach ($records as $record) { # build key string for this record $encoded_key_string = $database_table->_get_encoded_key_string($record); $key_values_string = $database_table->_get_key_values_string($record); $sum_record = FALSE; if ($key_values_string == "_0") { $sum_record = TRUE; } $html_str .= " <tr id=\"" . $key_values_string . "\">\n"; $col_number = 0; foreach ($field_names_with_length as $field_name) { $db_field_name = $user_fields[$field_name]; $value = $record[$db_field_name]; # sum row is not clickable if ($sum_record == TRUE) { if ($value != "") { $html_str .= " <td><strong>{$value}</strong></td>\n"; } else { $html_str .= " <td></td>\n"; } } else { # add onclick actions if ($this->configuration[HTML_TABLE_PAGE_TYPE] != PAGE_TYPE_PORTAL) { $action_str = "action_get_" . $this->configuration[HTML_TABLE_JS_NAME_PREFIX] . "record"; # use different function name when page type is list because we use more types of permissions with lists if ($this->configuration[HTML_TABLE_PAGE_TYPE] == PAGE_TYPE_LIST) { $action_str = "action_get_update_" . $this->configuration[HTML_TABLE_JS_NAME_PREFIX] . "record"; } $onclick_str = get_onclick($action_str, $list_title, $key_values_string, "below", "(%27" . $list_title . "%27, %27" . $encoded_key_string . "%27)"); } else { $onclick_str = get_onclick(ACTION_GET_LIST_PAGE, $record[LISTTABLEDESCRIPTION_TITLE_FIELD_NAME], $key_values_string, "below", "window.location.assign(%27index.php?action=" . ACTION_GET_LIST_PAGE . "&list=" . $record[LISTTABLEDESCRIPTION_TITLE_FIELD_NAME] . "%27)"); } # call function to convert value according to type of field $returned_str = $this->get_field_value($fields[$db_field_name][1], $fields[$db_field_name][2], $db_field_name, $record); $html_str .= " <td " . $onclick_str . ">{$returned_str}</td>\n"; } $col_number += 1; } # only add buttons when all pages do not need to be displayed at once if ($page != DATABASETABLE_ALL_PAGES && $sum_record == FALSE) { # define delete and archive buttons $js_button_archive = "action_archive_" . $this->configuration[HTML_TABLE_JS_NAME_PREFIX] . "record"; $js_button_activate = "action_activate_" . $this->configuration[HTML_TABLE_JS_NAME_PREFIX] . "record"; $js_button_delete = "action_delete_" . $this->configuration[HTML_TABLE_JS_NAME_PREFIX] . "record"; # add buttons for normal lists if ($this->configuration[HTML_TABLE_PAGE_TYPE] != PAGE_TYPE_PORTAL) { # add the archive button only when this record is not archived if ($metadata_str[DATABASETABLE_METADATA_ENABLE_ARCHIVE] != DATABASETABLE_METADATA_FALSE && strlen($record[DB_ARCHIVER_FIELD_NAME]) == 0) { $html_str .= " <td width=\"1%\">"; $html_str .= get_href(get_onclick($js_button_archive, $this->permissions_list_title, $key_values_string, "below", "(%27" . $list_title . "%27, %27" . $encoded_key_string . "%27)"), translate("BUTTON_ARCHIVE"), "icon_archive"); $html_str .= "</td>\n"; } # add the delete link when it should always be displayed if ($this->configuration[HTML_TABLE_DELETE_MODE] == HTML_TABLE_DELETE_MODE_ALWAYS) { $html_str .= " <td width=\"1%\">"; $html_str .= get_href(get_onclick($js_button_delete, $this->permissions_list_title, $key_values_string, "below", "(%27" . $list_title . "%27, %27" . $encoded_key_string . "%27)"), translate("BUTTON_DELETE"), "icon_delete"); $html_str .= "</td>\n"; } else { if ($this->configuration[HTML_TABLE_DELETE_MODE] == HTML_TABLE_DELETE_MODE_ARCHIVED && strlen($record[DB_ARCHIVER_FIELD_NAME]) > 0) { $html_str .= " <td width=\"1%\">"; $html_str .= get_href(get_onclick($js_button_activate, $this->permissions_list_title, $key_values_string, "below", "(%27" . $list_title . "%27, %27" . $encoded_key_string . "%27)"), translate("BUTTON_ACTIVATE"), "icon_unarchive"); $html_str .= "</td>\n"; $html_str .= " <td width=\"1%\">"; $html_str .= get_href(get_onclick($js_button_delete, $this->permissions_list_title, $key_values_string, "below", "(%27" . $list_title . "%27, %27" . $encoded_key_string . "%27)"), translate("BUTTON_DELETE"), "icon_delete"); $html_str .= "</td>\n"; } else { if ($this->configuration[HTML_TABLE_DELETE_MODE] == HTML_TABLE_DELETE_MODE_NEVER) { $html_str .= " <td width=\"1%\"> </td>\n"; } } } $html_str .= " </tr>\n"; } } else { if ($this->configuration[HTML_TABLE_PAGE_TYPE] == PAGE_TYPE_PORTAL && $sum_record == FALSE) { # add modify button $html_str .= " <td width=\"1%\">"; $html_str .= get_href(get_query_onclick(ACTION_GET_LISTBUILDER_PAGE, $record[LISTTABLEDESCRIPTION_TITLE_FIELD_NAME], $key_values_string, "below", "action=" . ACTION_GET_LISTBUILDER_PAGE . "&list=" . $record[LISTTABLEDESCRIPTION_TITLE_FIELD_NAME]), translate("BUTTON_MODIFY"), "icon_edit"); $html_str .= "</td>\n"; # add delete button $html_str .= " <td width=\"1%\">"; $html_str .= get_href(get_onclick_confirm(ACTION_DELETE_PORTAL_RECORD, $record[LISTTABLEDESCRIPTION_TITLE_FIELD_NAME], $key_values_string, "below", "handleFunction(%22" . ACTION_DELETE_PORTAL_RECORD . "%22, %22" . $record[LISTTABLEDESCRIPTION_TITLE_FIELD_NAME] . "%22)", translate("LABEL_CONFIRM_DELETE")), translate("BUTTON_DELETE"), "icon_delete"); $html_str .= "</td>\n </tr>\n"; } else { $html_str .= " <td width=\"1%\" colspan=\"3\"> </td>\n </tr>\n"; } } $record_number += 1; } if ($total_pages == 0) { $html_str .= " <tr>\n"; foreach ($field_names_with_length as $field_name) { $html_str .= " <td>" . translate("LABEL_MINUS") . "</td>\n"; } $html_str .= " <td width=\"1%\"> </td>\n"; $html_str .= " </tr>\n"; } # end table definition $html_str .= " </tbody>\n"; $html_str .= " </table>\n"; # add navigation links, except when all pages have to be shown or the number of records is exactly 0 $html_str .= " <div id=\"" . $this->configuration[HTML_TABLE_CSS_NAME_PREFIX] . "contents_bottom\">\n"; $html_str .= " <div class=\"corner bottom_left_normal\"></div>\n"; $html_str .= " <div class=\"corner bottom_right_normal\"></div>\n"; if ($page != DATABASETABLE_ALL_PAGES && $total_pages > 0) { $html_str .= " <div id=\"" . $this->configuration[HTML_TABLE_CSS_NAME_PREFIX] . "pages_bottom\">"; # display 1 pagenumber when there is only one page (or none) if ($total_pages == 0 || $total_pages == 1) { $html_str .= "<span class=\"current_page\">{$total_pages}</span>"; } else { $js_href_get = "action_get_" . $this->configuration[HTML_TABLE_JS_NAME_PREFIX] . "content"; # display previous page link if ($current_page > 1) { $html_str .= "<span class=\"navigation_button\">" . get_href(get_onclick($js_href_get, $list_title, "", "", "(%27" . $list_title . "%27, %27%27, " . ($current_page - 1) . ")"), "« " . translate("BUTTON_PREVIOUS_PAGE"), "") . "</span>"; } # display first pagenumber if ($current_page == 1) { $html_str .= "<span class=\"current_page\">1</span>"; } else { $html_str .= "<span class=\"navigation_page\">" . get_href(get_onclick($js_href_get, $list_title, "", "", "(%27" . $list_title . "%27, %27%27, 1)"), 1, "") . "</span>"; } # display middle pagenumbers for ($cnt = 2; $cnt < $total_pages; $cnt += 1) { if ($cnt == $current_page - 3) { $html_str .= " .... "; } else { if ($cnt == $current_page - 2 || $cnt == $current_page - 1) { $html_str .= "<span class=\"navigation_page\">" . get_href(get_onclick($js_href_get, $list_title, "", "", "(%27" . $list_title . "%27, %27%27, " . $cnt . ")"), $cnt, "") . "</span>"; } else { if ($cnt == $current_page) { $html_str .= "<span class=\"current_page\">{$cnt}</span>"; } else { if ($cnt == $current_page + 1 || $cnt == $current_page + 2) { $html_str .= "<span class=\"navigation_page\">" . get_href(get_onclick($js_href_get, $list_title, "", "", "(%27" . $list_title . "%27, %27%27, " . $cnt . ")"), $cnt, "") . "</span>"; } } } } if ($cnt == $current_page + 3) { $html_str .= " .... "; } } # display last pagenumber if ($current_page == $total_pages) { $html_str .= "<span class=\"current_page\">{$total_pages}</span>"; } else { $html_str .= "<span class=\"navigation_page\">" . get_href(get_onclick($js_href_get, $list_title, "", "", "(%27" . $list_title . "%27, %27%27, " . $total_pages . ")"), $total_pages, "") . "</span>"; } # display next page link if ($current_page < $total_pages) { $html_str .= "<span class=\"navigation_button\">" . get_href(get_onclick($js_href_get, $list_title, "", "", "(%27" . $list_title . "%27, %27%27, " . ($current_page + 1) . ")"), translate("BUTTON_NEXT_PAGE") . " »", "") . "</span>"; } } $html_str .= "</div>\n"; } else { $html_str .= " \n"; } $html_str .= " </div> <!-- " . $this->configuration[HTML_TABLE_CSS_NAME_PREFIX] . "contents_bottom -->\n "; $result->set_result_str($html_str); $this->_log->trace("got content"); }