Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- include("includes/smtpvalidateclass.php");
- class Pagination {
- /* EDITATI datele din acest array daca paginati randuri din tabel MySQ
- Adaugati datele dv. pentru conectare la baza de date MySQL (serverul MySQL, utilizator, parola, baza_de_date) */
- protected $mysql = array(
- 'host' => 'localhost',
- 'user' => 'root',
- 'pass' => '',
- 'dbname' => ''
- );
- public $table = 'registration_info'; // AICI adaugati numele tabelului MySQL
- // properties
- public $rowsperpage = 10; // numarul de randuri (elemente array) adaugate in pagina
- public $txtchr = 800; // numarul maxim de caractwere, cand se face paginarea unui continut text
- public $txtpieces = 0; // numarul de parti /pagini, cand se face paginarea unui continut text
- public $range = 4; // numarul de link-uri afisate in jurul celui curent
- protected $conn = false; // va retine conexiunea mysql
- protected $idpage = 0; // indexul paginii curente
- protected $totalpages = 1; // numarul total de pagini
- protected $pag; // retine numele fisierului care foloseste clasa ($_SERVER['PHP_SELF'])
- // Constructor
- public function __construct() {
- // seteaza proprietatile $pag si $idpage (intreg, pozitiv)
- $this->pag = $_SERVER['PHP_SELF'];
- $this->idpage = isset($_GET['pg']) ? intval(abs($_GET['pg'] - 1)) : 0;
- // $this->rowsperpage = $_GET['rnump'];
- if ($_GET['rnump'] == 0) {
- $this->rowsperpage = $_GET['rnump'] + 10;
- } else {
- $this->rowsperpage = $_GET['rnump'];
- }
- }
- // metoda pt crearea conectarii la baza de date MySQL
- public function setConn() {
- // daca se realizeaza cu succes conectarea la baza de date, o retine in perroprietatea $conn
- if ($conn = new mysqli($this->mysql['host'], $this->mysql['user'], $this->mysql['pass'], $this->mysql['dbname'])) {
- $sql = "SET NAMES 'utf8'";
- if ($conn->query($sql))
- $this->conn = $conn;
- }
- return $this->conn;
- }
- // Selecteaza randurile din tabelul mysql pentru pagina curenta. Returneaza un sir cu acestea, cu cod html
- public function getMysqlRows() {
- $this->setConn(); // apeleaza metoda setConn() pt. a crea conexiunea la MySQL
- $startrow = $this->idpage * $this->rowsperpage; // randul de la care incepe selectarea continutului
- $re_cnt = ''; // variabila ce va fi returnata
- // daca e creata conectarea la baza de date MySQL
- if ($this->conn !== false) {
- // SELECT pt. a afla numarul total de pagini ($totalpages)
- $sql = "SELECT COUNT(*) FROM `$this->table` WHERE `archive`=0";
- // efectueaza interogarea, apoi vor fi selectate randurile
- if ($resql = $this->conn->query($sql)) {
- // daca $resql contine cel putin un rand, le preia si seteaza $totalpages
- if ($resql->num_rows > 0) {
- $row = $resql->fetch_row();
- $this->totalpages = ceil($row[0] / $this->rowsperpage);
- // Definire SELECT care preia randurile pt. pagina curenta
- // LIMIT $startrow, $this->rowsperpage ; specifica sa fie selectate doar randurile paginii curente
- $sql = "SELECT * FROM `$this->table` WHERE `archive`=0 LIMIT $startrow, $this->rowsperpage";
- ?>
- <div class="container-fluid">
- <div class="row">
- <div class="col-md-6">
- <div class="dropdown">
- <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
- Records per page
- <span class="caret"></span>
- </button>
- <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
- <li><a href="business.php?rnump=10">10</a></li>
- <li><a href="business.php?rnump=25">25</a></li>
- <li><a href="business.php?rnump=50">50</a></li>
- <li><a href="business.php?rnump=100">100</a></li>
- </ul>
- </div>
- </div>
- <div class="col-md-4 pull-right">
- <form method="post" action="search.php">
- <div class="input-group">
- <input name="search" type="text" class="form-control" placeholder="Search for...">
- <span class="input-group-btn">
- <input class="btn btn-primary" type="submit" value="Search">
- </span>
- </div><!-- /input-group -->
- </form>
- </div><!-- /.col-lg-6 -->
- </div>
- </div>
- <?php
- if ($resql = $this->conn->query($sql)) {
- // daca $resql contine cel putin un rand
- if ($resql->num_rows > 0) {
- ?>
- <div class="panel panel-default">
- <div class="panel-heading">
- Business List
- </div>
- <!-- /.panel-heading -->
- <div class="panel-body">
- <div class="table-responsive">
- <table class="table table-striped table-bordered table-hover">
- <thead>
- <tr>
- <th>SLNo</th>
- <th>Customer Name</th>
- <th>Email</th>
- <th>Phone</th>
- <th>Fax</th>
- <th>Action</th>
- <th>Status</th>
- </tr>
- </thead>
- <tbody>
- <?php
- while ($row = $resql->fetch_assoc()) {
- $i++;
- // $emails_cust = $row['email'];
- // // the email to validate
- // $emails = array($emails_cust);
- // // an optional sender
- // $sender = 'sandyk@onlinebusinessconcierge.com';
- // $SMTP_Valid = new SMTP_validateEmail();
- // $result_verification = $SMTP_Valid->validate($emails);
- // print_r($result_verification);
- ?>
- <tr class="odd gradeX">
- <td><?php echo $i; ?></td>
- <td><?php echo $row['cust_name']; ?></td>
- <td>
- <?php echo $row['email']; ?>
- <?php //echo ' is '.($result_verification ? 'valid' : 'invalid')."\n"; ?>
- <?php if($row['account_status'] == '0') { ?>
- <img src="img/not-ok-icon.png" title="Account not confirmed">
- <?php } else { ?>
- <img src="img/ok-icon.png" title="Account confirmed">
- <?php } ?>
- <a class="btn btn-primary" href="send_mail.php?id=<?php echo $row['int_cust_id'] ?>" data-toggle="modal" data-target="#myModal">
- <i class="fa fa-envelope" aria-hidden="true"></i>
- </a></td>
- <td><?php echo $row['phone']; ?></td>
- <td><?php echo $row['fax']; ?></td>
- <td>
- <?php
- // $user = $db->line("SELECT * from tbl_customer_login where int_cust_id = '" . $result['int_cust_id'] . "'");
- ?>
- <div class="form-group">
- <div class="">
- <div class="input-group">
- <div id="radioBtn" class="btn-group">
- <a title="Export CSV" target="_blank" href="complete_data.php?id=<?php echo $row['int_cust_id']; ?>&name=<?php
- $name = str_replace(" ", "_", $row['cust_name']);
- echo $name;
- ?>">
- <button class="btn btn-default btn-default" type="button">
- <i class="fa fa-download fa-fw"></i>
- </button>
- </a>
- <a title="Send Login Details" href="action.php?id=<?php echo $row['int_cust_id']; ?>&action=send_details">
- <button class="btn btn-default btn-default" type="button">
- <i class="fa fa-mail-forward fa-fw"></i>
- </button>
- </a>
- <a title="Delete" onclick="return confirm('Delete Record');" href="action.php?id=<?php echo $row['int_cust_id']; ?>&action=delete">
- <button class="btn btn-default btn-default" type="button">
- <i class="fa fa-trash-o fa-fw"></i>
- </button>
- </a>
- <a title="Details" href="questionairs.php?id=<?php echo $row['int_cust_id']; ?>">
- <button class="btn btn-default btn-default" type="button">
- <i class="fa fa-file-text fa-fw"></i>
- </button>
- </a>
- <a title="Archive" href="action.php?id=<?php echo $row['int_cust_id']; ?>&action=archive">
- <button class="btn btn-default btn-default" type="button">
- <i class="fa fa-archive fa-fw"></i>
- </button>
- </a>
- <a title="Export Registration" target="_blank" href="export_registration_data.php?id=<?php echo $row['int_cust_id']; ?>&name=<?php
- $name = str_replace(" ", "_", $row['cust_name']);
- echo $name;
- ?>">
- <button class="btn btn-default btn-default" type="button">
- <i class="fa fa-download fa-fw"></i>
- </button>
- </a>
- </div>
- </div>
- </div>
- </div>
- </td>
- <td><?php
- // if ($this->conn !== false) {
- // $question1 = $sql("SELECT * FROM register1 WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
- // }
- $sql1 = mysql_query("SELECT * FROM register1 WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
- $sql2 = mysql_query("SELECT * FROM edit_table_form_2 WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
- $sql3 = mysql_query("SELECT * FROM questionaire_3n WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
- $sql4 = mysql_query("SELECT * FROM tform5_a WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
- $sql5 = mysql_query("SELECT * FROM tform5_b WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
- while ($row = mysql_fetch_assoc($sql1)) {
- if ($row['completed'] == "0") {
- echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 1 is not filled'>1</span>";
- } elseif ($row['completed'] == "1") {
- echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 1 is filled'>1</span>";
- }
- }
- while ($row = mysql_fetch_assoc($sql2)) {
- if ($row['completed'] == "0") {
- echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 2 is not filled'>2</span>";
- } elseif ($row['completed'] == "1") {
- echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 2 is filled'>2</span>";
- }
- }
- while ($row = mysql_fetch_assoc($sql3)) {
- if ($row['completed'] == "0") {
- echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 3 is not filled'>3</span>";
- } elseif ($row['completed'] == "1") {
- echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 3 is filled'>3</span>";
- }
- }
- while ($row = mysql_fetch_assoc($sql4)) {
- if ($row['completed'] == "0") {
- echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 5a is not filled'>4</span>";
- } elseif ($row['completed'] == "1") {
- echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 5a is filled'>4</span>";
- }
- }
- while ($row = mysql_fetch_assoc($sql5)) {
- if ($row['completed'] == "0") {
- echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 5b is not filled'>5</span>";
- } elseif ($row['completed'] == "1") {
- echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 5b is filled'>5</span>";
- }
- }
- // $question2 = $sql("SELECT * FROM edit_table_form_2 WHERE int_cust_id = '" . $result['int_cust_id'] . "'");
- // $question3 = $db->line("SELECT * FROM questionaire_3n WHERE int_cust_id = '" . $result['int_cust_id'] . "'");
- // $question4 = $db->line("SELECT * FROM tform5_a WHERE int_cust_id = '" . $result['int_cust_id'] . "'");
- // $question5 = $db->line("SELECT * FROM tform5_b WHERE int_cust_id = '" . $result['int_cust_id'] . "'");
- //
- // if ($question2['deactive'] == "1") {
- // echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 2 is not filled'>2</span>";
- // } elseif ($question2['deactive'] == "0") {
- // echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 2 is filled'>2</span>";
- // }
- //
- // if ($question3['deactive'] == "1") {
- // echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 3 is not filled'>3</span>";
- // } elseif ($question3['deactive'] == "0") {
- // echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 3 is filled'>3</span>";
- // }
- //
- // if ($question4['deactive'] == "1") {
- // echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 4 is not filled'>4</span>";
- // } elseif ($question4['deactive'] == "0") {
- // echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 4 is filled'>4</span>";
- // }
- //
- // if ($question5['deactive'] == "1") {
- // echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 5 is not filled'>5</span>";
- // } elseif ($question5['deactive'] == "0") {
- // echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 5 is filled'>5</span>";
- // }
- ?>
- </td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- </div>
- <!-- /.table-responsive -->
- </div>
- <!-- /.panel-body -->
- <?php
- // AICI MODIFICATI numele coloanelor si creati codul HTML
- // while ($row = $resql->fetch_assoc()) {
- // $re_cnt .= '<h3>'. $row['cust_name']. '</h3>'. $row['int_cust_id']. '<div class="content">'. $row['email']. '</div>';
- // echo $row['cust_name'];
- // }
- } else
- $re_cnt .= '0 rezultate';
- } else
- $re_cnt .= '0 inregistrari in table';
- }
- } else
- $re_cnt .= 'Eroare: ' . $this->conn->error;
- $this->conn->close();
- } else
- $re_cnt .= 'Nu exista connectare la baza de date MySQL ' . mysqli_connect_error();
- return $re_cnt;
- }
- // primeste un Arry cu continutul ce trebuie paginat. Returneaza un sir cu elementele pt. pagina curenta
- public function getArrRows($arr) {
- $startrow = $this->idpage * $this->rowsperpage; // elementul de la care incepe preluarea
- $ar_page = array_slice($arr, $startrow, $this->rowsperpage); // preia elementele pt. pagina curenta
- $nre = count($ar_page);
- $this->totalpages = ceil(count($arr) / $this->rowsperpage); // seteaza numar total de pagini
- $re_cnt = ''; // variabila ce va fi returnata
- // AICI ADAUGATI CODUL HTML PT REZULTATUL CE CONTINE FIECARE ELEMENT
- for ($i = 0; $i < $nre; $i++) {
- $re_cnt .= '<div class="content">' . $ar_page[$i] . '</div>';
- }
- return $re_cnt;
- }
- // metoda pt paginare text, imparte sirul in functie de numarul de caractere ($txtchr), sau nr. parti (txtpieces)
- public function getText($text) {
- // daca $txtpieces e mai mare decat 0, imparte $text intr-un numar de parti /pagini specificat in $txtpieces
- // altfel, imparte textul in functie de numarul maxim de caractere din $txtchr
- if ($this->txtpieces > 0) {
- $this->txtchr = ceil(strlen($text) / $this->txtpieces); // seteaza $txtchr in functie de nr. parti
- }
- // imparte textul si creaza un Array cu partile obtinute. Returneaza sirul pt. pagina curenta
- $newtext = wordwrap($text, $this->txtchr, '#|#');
- $ar_text = explode('#|#', $newtext);
- $nr_pieces = count($ar_text);
- // daca paginarea e dupa numarul de parti, si sunt prea multe segmente - uneste pe ultimile doua
- if ($this->txtpieces > 0 && $nr_pieces > $this->txtpieces) {
- $ar_text[$nr_pieces - 2] .= ' ' . $ar_text[$nr_pieces - 1];
- unset($ar_text[$nr_pieces - 1]);
- }
- $this->totalpages = count($ar_text); // seteaza nr. total de pagini
- if ($this->idpage > $this->totalpages)
- $this->idpage = $this->totalpages;
- // seteaza un sir care sa fie adaugat la sfarsitul continutului text, daca nu e ultima pagina
- $end = ($this->idpage + 1) < $this->totalpages ? ' ...[<i> Continuare in pagina urmatoarte</i>].' : '';
- return $ar_text[$this->idpage] . $end;
- }
- // metoda ce seteaza link-urile
- public function getLinks() {
- $re_links = ''; // variabila ce va contine randurile returnate
- $currentpage = $this->idpage + 1; // deoarece indexul paginii incepe de la 0, adauga 1 ca sa seteze pagina curenta
- $pag_get = '?pg='; // numele pt valoarea GET adaugata in URL
- // daca $totalpages>0 si nr total pagini e mai mare sau egal cu pagina curenta
- if ($this->totalpages > 0 && $this->totalpages >= $currentpage) {
- // Link-uri inapoi, daca pagina curenta nu e prima
- if ($currentpage > 1) {
- // adauga << pentru link la prima pagina
- // $re_links .= ' <li><a href="' . $this->pag . '" title="Link 1"><span aria-hidden="true">«</span></a> </li> ';
- $prevpage = $currentpage - 1; // pagina anterioara
- // adauga < pt link la pagina anterioara, daca nu e 1
- if ($prevpage > 0)
- $re_links .= ' <li><a href="' . $this->pag . $pag_get . $prevpage . '&rnump=' . $this->rowsperpage . '" title="Link ' . $prevpage . '"><span aria-hidden="true">«</span></a> </li>';
- }else {
- $prevpage = $currentpage - 1;
- $re_links .= ' <li class="disabled"><a href="' . $this->pag . $pag_get . $prevpage . '&rnump=' . $this->rowsperpage . '" title="Link ' . $prevpage . '"><span aria-hidden="true">«</span></a> </li>';
- }
- // seteaza link-urile din jurul paginii curente
- for ($x = ($currentpage - $this->range); $x <= ($currentpage + $this->range); $x++) {
- // daca e un numar intre prima si ultima pagina
- if (($x > 0) && ($x <= $this->totalpages)) {
- // daca e nr. pagina curenta, afiseaza fara link, altfel adauga link
- if ($x == $currentpage)
- $re_links .= ' <li class="active"><a href="#">' . $x . '</a></li> ';
- else
- $re_links .= ' <li><a href="' . $this->pag . $pag_get . $x . '&rnump=' . $this->rowsperpage . '" title="Link ' . $x . '">' . $x . '</a></li> ';
- }
- }
- // Daca pagina curenta nu e ultima, adauga link pentru pagina urmatoare si ultima
- if ($currentpage != $this->totalpages) {
- $nextpage = $currentpage + 1; // obtine pagina urmatoare
- // adauga > pt. pagina urmatoare (daca e mai mare decat $this->range si mai mica decat $totalpages)
- if ($nextpage > 1 && $nextpage < $this->totalpages)
- $re_links .= ' <li><a href="' . $this->pag . $pag_get . $nextpage . '&rnump=' . $this->rowsperpage . '" title="Link ' . $nextpage . '"><span aria-hidden="true">»</span></a></li> ';
- // adauga >> pentru ultima pagina, daca e mai mare decat $this->range
- // if ($this->totalpages > $this->range)
- // $re_links .= ' <a href="' . $this->pag . $pag_get . $this->totalpages . '" title="Link ' . $this->totalpages . '">>> Ultima pagina (' . $this->totalpages . ')</a> ';
- }
- }
- // adauga link-urile intr-un DIV si-l returneaza
- if (strlen($re_links) > 1)
- $re_links = '<nav><ul class="pagination pull-right">' . $re_links . '</nav></div>';
- return $re_links;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement