mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Documentation, formatting (#7630)
* Documentation, formatting * Updated formatting to remove alignment * Updated spacing in the quoted script
This commit is contained in:
@@ -24,18 +24,34 @@
|
|||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate pagination links and controls.
|
||||||
|
*
|
||||||
|
* @param int $num_rows Total number of rows.
|
||||||
|
* @param string $param URL parameters to sanitize.
|
||||||
|
* @param int $rows_per_page Number of rows per page.
|
||||||
|
* @param bool $mini Whether to display mini pagination (default: false).
|
||||||
|
* @param int $result_count Result count for last page handling.
|
||||||
|
*
|
||||||
|
* @return array Array containing pagination links and controls.
|
||||||
|
*/
|
||||||
function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count = 0) {
|
function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count = 0) {
|
||||||
|
|
||||||
//validate the data
|
//validate the data
|
||||||
if (!is_numeric($num_rows)) { $num_rows = 0; }
|
if (!is_numeric($num_rows)) {
|
||||||
if (!is_numeric($rows_per_page)) { $rows_per_page = 100; }
|
$num_rows = 0;
|
||||||
if (!is_numeric($result_count)) { $result_count = 0; }
|
}
|
||||||
|
if (!is_numeric($rows_per_page)) {
|
||||||
|
$rows_per_page = 100;
|
||||||
|
}
|
||||||
|
if (!is_numeric($result_count)) {
|
||||||
|
$result_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// if $_get['page'] defined, use it as page number
|
// if $_get['page'] defined, use it as page number
|
||||||
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
|
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
|
||||||
$page_number = $_GET['page'];
|
$page_number = $_GET['page'];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$page_number = 0;
|
$page_number = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +67,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
if ($key === 'order_by' && !empty($value)) {
|
if ($key === 'order_by' && !empty($value)) {
|
||||||
//validate order by
|
//validate order by
|
||||||
$sanitized_parameters .= "&order_by=" . preg_replace('#[^a-zA-Z0-9_\-]#', '', $value);
|
$sanitized_parameters .= "&order_by=" . preg_replace('#[^a-zA-Z0-9_\-]#', '', $value);
|
||||||
}
|
} elseif ($key == 'order' && !empty($value)) {
|
||||||
else if ($key == 'order' && !empty($value)) {
|
|
||||||
//validate order
|
//validate order
|
||||||
switch ($value) {
|
switch ($value) {
|
||||||
case 'asc':
|
case 'asc':
|
||||||
@@ -62,11 +77,9 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
$sanitized_parameters .= "&order=desc";
|
$sanitized_parameters .= "&order=desc";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} elseif (!empty($value) && is_numeric($value)) {
|
||||||
else if (!empty($value) && is_numeric($value)) {
|
|
||||||
$sanitized_parameters .= "&" . $key . "=" . $value;
|
$sanitized_parameters .= "&" . $key . "=" . $value;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$sanitized_parameters .= "&" . $key . "=" . urlencode($value ?? '');
|
$sanitized_parameters .= "&" . $key . "=" . urlencode($value ?? '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,8 +89,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
//how many pages we have when using paging
|
//how many pages we have when using paging
|
||||||
if ($num_rows > 0) {
|
if ($num_rows > 0) {
|
||||||
$max_page = ceil($num_rows / $rows_per_page);
|
$max_page = ceil($num_rows / $rows_per_page);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$max_page = 1;
|
$max_page = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,8 +103,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
for ($page = 1; $page <= $max_page; $page++) {
|
for ($page = 1; $page <= $max_page; $page++) {
|
||||||
if ($page == $page_number) {
|
if ($page == $page_number) {
|
||||||
$nav .= " $page "; // no need to create a link to current page
|
$nav .= " $page "; // no need to create a link to current page
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$nav .= " <a href='" . $self . "?page=" . $page . "'>" . $page . "</a> \n";
|
$nav .= " <a href='" . $self . "?page=" . $page . "'>" . $page . "</a> \n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,8 +112,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
$page = $page_number - 1;
|
$page = $page_number - 1;
|
||||||
$prev = button::create(['type' => 'button', 'label' => $text['button-back'], 'icon' => 'chevron-left', 'link' => $self . "?page=" . $page . $sanitized_parameters, 'title' => $text['label-page'] . ' ' . ($page + 1)]);
|
$prev = button::create(['type' => 'button', 'label' => $text['button-back'], 'icon' => 'chevron-left', 'link' => $self . "?page=" . $page . $sanitized_parameters, 'title' => $text['label-page'] . ' ' . ($page + 1)]);
|
||||||
$first = button::create(['type' => 'button', 'label' => $text['button-next'], 'icon' => 'chevron-left', 'link' => $self . "?page=1" . $sanitized_parameters]);
|
$first = button::create(['type' => 'button', 'label' => $text['button-next'], 'icon' => 'chevron-left', 'link' => $self . "?page=1" . $sanitized_parameters]);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$prev = button::create(['type' => 'button', 'label' => $text['button-back'], 'icon' => 'chevron-left', 'onclick' => "return false;", 'title' => '', 'style' => 'opacity: 0.4; -moz-opacity: 0.4; cursor: default;']);
|
$prev = button::create(['type' => 'button', 'label' => $text['button-back'], 'icon' => 'chevron-left', 'onclick' => "return false;", 'title' => '', 'style' => 'opacity: 0.4; -moz-opacity: 0.4; cursor: default;']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,8 +120,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
$page = $page_number + 1;
|
$page = $page_number + 1;
|
||||||
$next = button::create(['type' => 'button', 'label' => $text['button-next'], 'icon' => 'chevron-right', 'link' => $self . "?page=" . $page . $sanitized_parameters, 'title' => $text['label-page'] . ' ' . ($page + 1)]);
|
$next = button::create(['type' => 'button', 'label' => $text['button-next'], 'icon' => 'chevron-right', 'link' => $self . "?page=" . $page . $sanitized_parameters, 'title' => $text['label-page'] . ' ' . ($page + 1)]);
|
||||||
$last = button::create(['type' => 'button', 'label' => $text['button-back'], 'icon' => 'chevron-right', 'link' => $self . "?page=" . $max_page . $sanitized_parameters]);
|
$last = button::create(['type' => 'button', 'label' => $text['button-back'], 'icon' => 'chevron-right', 'link' => $self . "?page=" . $max_page . $sanitized_parameters]);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$last = button::create(['type' => 'button', 'label' => $text['button-next'], 'icon' => 'chevron-right', 'link' => $self . "?page=" . $max_page . $sanitized_parameters]);
|
$last = button::create(['type' => 'button', 'label' => $text['button-next'], 'icon' => 'chevron-right', 'link' => $self . "?page=" . $max_page . $sanitized_parameters]);
|
||||||
$next = button::create(['type' => 'button', 'label' => $text['button-next'], 'icon' => 'chevron-right', 'onclick' => "return false;", 'title' => '', 'style' => 'opacity: 0.4; -moz-opacity: 0.4; cursor: default;']);
|
$next = button::create(['type' => 'button', 'label' => $text['button-next'], 'icon' => 'chevron-right', 'onclick' => "return false;", 'title' => '', 'style' => 'opacity: 0.4; -moz-opacity: 0.4; cursor: default;']);
|
||||||
}
|
}
|
||||||
@@ -121,7 +130,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
$next = button::create(['type' => 'button', 'label' => (!$mini ? $text['button-next'] : null), 'icon' => 'chevron-right', 'onclick' => "return false;", 'title' => '', 'style' => 'opacity: 0.4; -moz-opacity: 0.4; cursor: default;']);
|
$next = button::create(['type' => 'button', 'label' => (!$mini ? $text['button-next'] : null), 'icon' => 'chevron-right', 'onclick' => "return false;", 'title' => '', 'style' => 'opacity: 0.4; -moz-opacity: 0.4; cursor: default;']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$array = array();
|
$array = [];
|
||||||
$code = '';
|
$code = '';
|
||||||
if ($max_page > 1) {
|
if ($max_page > 1) {
|
||||||
//define javascript to include
|
//define javascript to include
|
||||||
@@ -154,7 +163,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
" }\n" .
|
" }\n" .
|
||||||
|
|
||||||
" if (do_action) {\n" .
|
" if (do_action) {\n" .
|
||||||
"// action to peform when enter is hit\n".
|
" // action to perform when enter is hit\n" .
|
||||||
" if (page_num < 1) { page_num = 1; }\n" .
|
" if (page_num < 1) { page_num = 1; }\n" .
|
||||||
" if (page_num > " . $max_page . ") { page_num = " . $max_page . "; }\n" .
|
" if (page_num > " . $max_page . ") { page_num = " . $max_page . "; }\n" .
|
||||||
" document.location.href = '" . $self . "?page='+(--page_num)+'" . $sanitized_parameters . "';\n" .
|
" document.location.href = '" . $self . "?page='+(--page_num)+'" . $sanitized_parameters . "';\n" .
|
||||||
@@ -165,8 +174,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
//determine size
|
//determine size
|
||||||
if ($mini) {
|
if ($mini) {
|
||||||
$code = "<span style='white-space: nowrap;'>" . $prev . $next . "</span>\n" . $script;
|
$code = "<span style='white-space: nowrap;'>" . $prev . $next . "</span>\n" . $script;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$code .= "<center style='white-space: nowrap;'>";
|
$code .= "<center style='white-space: nowrap;'>";
|
||||||
$code .= " " . $prev;
|
$code .= " " . $prev;
|
||||||
$code .= " ";
|
$code .= " ";
|
||||||
@@ -181,8 +189,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
|
|
||||||
//add to array
|
//add to array
|
||||||
$array[] = $code;
|
$array[] = $code;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$array[] = "";
|
$array[] = "";
|
||||||
}
|
}
|
||||||
$array[] = $rows_per_page;
|
$array[] = $rows_per_page;
|
||||||
@@ -190,5 +197,3 @@ function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count
|
|||||||
return $array;
|
return $array;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user