--- /dev/null
+package zakegg
+
+import (
+ "fmt"
+ "math"
+)
+
+func Paginazione(start int, rows int, rows_x_page int, url string) string {
+ var page_start int
+ var page_end int
+ var page int
+ var pages int
+
+ if rows_x_page == 0 {
+ return ""
+ }
+
+ ret := ""
+
+ if rows > rows_x_page {
+ ret += `<nav>
+ <ul class="pagination justify-content-center">`
+
+ pages = rows /rows_x_page
+ if (pages * rows_x_page) < rows {
+ pages++
+ }
+ if start > 0 {
+ ret += fmt.Sprintf(`<li class="page-item">
+ <a class="page-link" href="%s" aria-label="Prima" title="Prima">
+ <span aria-hidden="true">«</span>
+ </a>
+ </li>`, url)
+ ret += fmt.Sprintf(`<li class="page-item">
+ <a class="page-link" href="%s/%d" aria-label="Precedente" title="Precedente">
+ <span aria-hidden="true">‹</span>
+ </a>
+ </li>`, url, start - rows_x_page)
+ } else {
+ ret += `<li class="page-item disabled">
+ <a class="page-link" href="#" aria-label="Prima" title="Prima">
+ <span aria-hidden="true">«</span>
+ </a>
+ </li>`
+ ret += `<li class="page-item disabled">
+ <a class="page-link" href="#" aria-label="Precedente" title="Predecente">
+ <span aria-hidden="true">‹</span>
+ </a>
+ </li>`
+ }
+
+ page_start = int(math.Max(0, float64(int(start / rows_x_page) - 5)))
+ page_end = page_start + 10
+ if page_end > pages {
+ page_end = pages
+ page_start = int(math.Max(0, float64(page_end - 10)))
+ }
+ for page = page_start; page < page_end; page++ {
+ if (start / rows_x_page) == page {
+ ret += fmt.Sprintf("<li class=\"page-item active\"><a class=\"page-link\" href=\"#\">%d</a></li>\n", page + 1)
+ } else {
+ ret += fmt.Sprintf("<li class=\"page-item\"><a class=\"page-link\" href=\"%s/%d\">%d</a></li>\n", url, page * rows_x_page, page + 1)
+ }
+ }
+
+ if start < int(rows / rows_x_page) * rows_x_page {
+ ret += fmt.Sprintf(`<li class="page-item">
+ <a class="page-link" href="%s/%d" aria-label="Successiva" title="Successiva">
+ <span aria-hidden="true">›</span>
+ </a>
+ </li>`, url, start + rows_x_page)
+ ret += fmt.Sprintf(`<li class="page-item">
+ <a class="page-link" href="%s/%d" aria-label="Ultima" title="Ultima">
+ <span aria-hidden="true">»</span>
+ </a>
+ </li>`, url, (rows / rows_x_page) * rows_x_page)
+ } else {
+ ret += `<li class="page-item disabled">
+ <a class="page-link" href="#" aria-label="Successiva" title="Successiva">
+ <span aria-hidden="true">›</span>
+ </a>
+ </li>`
+ ret += `<li class="page-item disabled">
+ <a class="page-link" href="#" aria-label="Ultima" title="Ultima">
+ <span aria-hidden="true">»</span>
+ </a>
+ </li>`
+ }
+
+ ret += `</ul>
+ </nav>`
+ }
+
+ return ret
+}