Advertisement
isandu

Untitled

May 24th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.30 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. include("includes/smtpvalidateclass.php");
  4.  
  5. class Pagination {
  6. /* EDITATI datele din acest array daca paginati randuri din tabel MySQ
  7. Adaugati datele dv. pentru conectare la baza de date MySQL (serverul MySQL, utilizator, parola, baza_de_date) */
  8.  
  9. protected $mysql = array(
  10. 'host' => 'localhost',
  11. 'user' => 'root',
  12. 'pass' => '',
  13. 'dbname' => ''
  14. );
  15. public $table = 'registration_info'; // AICI adaugati numele tabelului MySQL
  16. // properties
  17. public $rowsperpage = 10; // numarul de randuri (elemente array) adaugate in pagina
  18. public $txtchr = 800; // numarul maxim de caractwere, cand se face paginarea unui continut text
  19. public $txtpieces = 0; // numarul de parti /pagini, cand se face paginarea unui continut text
  20. public $range = 4; // numarul de link-uri afisate in jurul celui curent
  21. protected $conn = false; // va retine conexiunea mysql
  22. protected $idpage = 0; // indexul paginii curente
  23. protected $totalpages = 1; // numarul total de pagini
  24. protected $pag; // retine numele fisierului care foloseste clasa ($_SERVER['PHP_SELF'])
  25.  
  26. // Constructor
  27.  
  28. public function __construct() {
  29. // seteaza proprietatile $pag si $idpage (intreg, pozitiv)
  30. $this->pag = $_SERVER['PHP_SELF'];
  31. $this->idpage = isset($_GET['pg']) ? intval(abs($_GET['pg'] - 1)) : 0;
  32. // $this->rowsperpage = $_GET['rnump'];
  33. if ($_GET['rnump'] == 0) {
  34. $this->rowsperpage = $_GET['rnump'] + 10;
  35. } else {
  36. $this->rowsperpage = $_GET['rnump'];
  37. }
  38. }
  39.  
  40. // metoda pt crearea conectarii la baza de date MySQL
  41. public function setConn() {
  42. // daca se realizeaza cu succes conectarea la baza de date, o retine in perroprietatea $conn
  43. if ($conn = new mysqli($this->mysql['host'], $this->mysql['user'], $this->mysql['pass'], $this->mysql['dbname'])) {
  44. $sql = "SET NAMES 'utf8'";
  45. if ($conn->query($sql))
  46. $this->conn = $conn;
  47. }
  48. return $this->conn;
  49. }
  50.  
  51. // Selecteaza randurile din tabelul mysql pentru pagina curenta. Returneaza un sir cu acestea, cu cod html
  52. public function getMysqlRows() {
  53. $this->setConn(); // apeleaza metoda setConn() pt. a crea conexiunea la MySQL
  54. $startrow = $this->idpage * $this->rowsperpage; // randul de la care incepe selectarea continutului
  55. $re_cnt = ''; // variabila ce va fi returnata
  56. // daca e creata conectarea la baza de date MySQL
  57. if ($this->conn !== false) {
  58. // SELECT pt. a afla numarul total de pagini ($totalpages)
  59. $sql = "SELECT COUNT(*) FROM `$this->table` WHERE `archive`=0";
  60.  
  61. // efectueaza interogarea, apoi vor fi selectate randurile
  62. if ($resql = $this->conn->query($sql)) {
  63. // daca $resql contine cel putin un rand, le preia si seteaza $totalpages
  64. if ($resql->num_rows > 0) {
  65. $row = $resql->fetch_row();
  66. $this->totalpages = ceil($row[0] / $this->rowsperpage);
  67. // Definire SELECT care preia randurile pt. pagina curenta
  68. // LIMIT $startrow, $this->rowsperpage ; specifica sa fie selectate doar randurile paginii curente
  69. $sql = "SELECT * FROM `$this->table` WHERE `archive`=0 LIMIT $startrow, $this->rowsperpage";
  70. ?>
  71. <div class="container-fluid">
  72. <div class="row">
  73. <div class="col-md-6">
  74. <div class="dropdown">
  75. <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
  76. Records per page
  77. <span class="caret"></span>
  78. </button>
  79. <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
  80. <li><a href="business.php?rnump=10">10</a></li>
  81. <li><a href="business.php?rnump=25">25</a></li>
  82. <li><a href="business.php?rnump=50">50</a></li>
  83. <li><a href="business.php?rnump=100">100</a></li>
  84. </ul>
  85. </div>
  86. </div>
  87. <div class="col-md-4 pull-right">
  88. <form method="post" action="search.php">
  89. <div class="input-group">
  90.  
  91. <input name="search" type="text" class="form-control" placeholder="Search for...">
  92.  
  93. <span class="input-group-btn">
  94. <input class="btn btn-primary" type="submit" value="Search">
  95. </span>
  96.  
  97. </div><!-- /input-group -->
  98. </form>
  99. </div><!-- /.col-lg-6 -->
  100. </div>
  101. </div>
  102. <?php
  103. if ($resql = $this->conn->query($sql)) {
  104. // daca $resql contine cel putin un rand
  105. if ($resql->num_rows > 0) {
  106. ?>
  107. <div class="panel panel-default">
  108. <div class="panel-heading">
  109. Business List
  110. </div>
  111.  
  112.  
  113. <!-- /.panel-heading -->
  114. <div class="panel-body">
  115. <div class="table-responsive">
  116. <table class="table table-striped table-bordered table-hover">
  117. <thead>
  118. <tr>
  119. <th>SLNo</th>
  120. <th>Customer Name</th>
  121. <th>Email</th>
  122. <th>Phone</th>
  123. <th>Fax</th>
  124. <th>Action</th>
  125. <th>Status</th>
  126. </tr>
  127. </thead>
  128. <tbody>
  129. <?php
  130. while ($row = $resql->fetch_assoc()) {
  131. $i++;
  132. // $emails_cust = $row['email'];
  133. // // the email to validate
  134. // $emails = array($emails_cust);
  135. // // an optional sender
  136. // $sender = 'sandyk@onlinebusinessconcierge.com';
  137. // $SMTP_Valid = new SMTP_validateEmail();
  138. // $result_verification = $SMTP_Valid->validate($emails);
  139. // print_r($result_verification);
  140. ?>
  141.  
  142. <tr class="odd gradeX">
  143. <td><?php echo $i; ?></td>
  144. <td><?php echo $row['cust_name']; ?></td>
  145. <td>
  146. <?php echo $row['email']; ?>
  147. <?php //echo ' is '.($result_verification ? 'valid' : 'invalid')."\n"; ?>
  148. <?php if($row['account_status'] == '0') { ?>
  149. <img src="img/not-ok-icon.png" title="Account not confirmed">
  150. <?php } else { ?>
  151. <img src="img/ok-icon.png" title="Account confirmed">
  152. <?php } ?>
  153. <a class="btn btn-primary" href="send_mail.php?id=<?php echo $row['int_cust_id'] ?>" data-toggle="modal" data-target="#myModal">
  154. <i class="fa fa-envelope" aria-hidden="true"></i>
  155. </a></td>
  156. <td><?php echo $row['phone']; ?></td>
  157. <td><?php echo $row['fax']; ?></td>
  158. <td>
  159. <?php
  160. // $user = $db->line("SELECT * from tbl_customer_login where int_cust_id = '" . $result['int_cust_id'] . "'");
  161. ?>
  162.  
  163. <div class="form-group">
  164.  
  165. <div class="">
  166. <div class="input-group">
  167. <div id="radioBtn" class="btn-group">
  168. <a title="Export CSV" target="_blank" href="complete_data.php?id=<?php echo $row['int_cust_id']; ?>&name=<?php
  169. $name = str_replace(" ", "_", $row['cust_name']);
  170. echo $name;
  171. ?>">
  172. <button class="btn btn-default btn-default" type="button">
  173. <i class="fa fa-download fa-fw"></i>
  174.  
  175. </button>
  176. </a>
  177.  
  178. <a title="Send Login Details" href="action.php?id=<?php echo $row['int_cust_id']; ?>&action=send_details">
  179. <button class="btn btn-default btn-default" type="button">
  180. <i class="fa fa-mail-forward fa-fw"></i>
  181. </button>
  182. </a>
  183.  
  184. <a title="Delete" onclick="return confirm('Delete Record');" href="action.php?id=<?php echo $row['int_cust_id']; ?>&action=delete">
  185. <button class="btn btn-default btn-default" type="button">
  186. <i class="fa fa-trash-o fa-fw"></i>
  187. </button>
  188. </a>
  189.  
  190. <a title="Details" href="questionairs.php?id=<?php echo $row['int_cust_id']; ?>">
  191. <button class="btn btn-default btn-default" type="button">
  192. <i class="fa fa-file-text fa-fw"></i>
  193. </button>
  194. </a>
  195.  
  196. <a title="Archive" href="action.php?id=<?php echo $row['int_cust_id']; ?>&action=archive">
  197. <button class="btn btn-default btn-default" type="button">
  198. <i class="fa fa-archive fa-fw"></i>
  199. </button>
  200. </a>
  201.  
  202. <a title="Export Registration" target="_blank" href="export_registration_data.php?id=<?php echo $row['int_cust_id']; ?>&name=<?php
  203. $name = str_replace(" ", "_", $row['cust_name']);
  204. echo $name;
  205. ?>">
  206. <button class="btn btn-default btn-default" type="button">
  207. <i class="fa fa-download fa-fw"></i>
  208.  
  209. </button>
  210. </a>
  211.  
  212. </div>
  213.  
  214. </div>
  215. </div>
  216. </div>
  217. </td>
  218. <td><?php
  219. // if ($this->conn !== false) {
  220. // $question1 = $sql("SELECT * FROM register1 WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
  221. // }
  222. $sql1 = mysql_query("SELECT * FROM register1 WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
  223. $sql2 = mysql_query("SELECT * FROM edit_table_form_2 WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
  224. $sql3 = mysql_query("SELECT * FROM questionaire_3n WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
  225. $sql4 = mysql_query("SELECT * FROM tform5_a WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
  226. $sql5 = mysql_query("SELECT * FROM tform5_b WHERE int_cust_id = '" . $row['int_cust_id'] . "'");
  227. while ($row = mysql_fetch_assoc($sql1)) {
  228. if ($row['completed'] == "0") {
  229. echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 1 is not filled'>1</span>";
  230. } elseif ($row['completed'] == "1") {
  231. echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 1 is filled'>1</span>";
  232. }
  233. }
  234.  
  235.  
  236. while ($row = mysql_fetch_assoc($sql2)) {
  237. if ($row['completed'] == "0") {
  238. echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 2 is not filled'>2</span>";
  239. } elseif ($row['completed'] == "1") {
  240. echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 2 is filled'>2</span>";
  241. }
  242. }
  243.  
  244. while ($row = mysql_fetch_assoc($sql3)) {
  245. if ($row['completed'] == "0") {
  246. echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 3 is not filled'>3</span>";
  247. } elseif ($row['completed'] == "1") {
  248. echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 3 is filled'>3</span>";
  249. }
  250. }
  251. while ($row = mysql_fetch_assoc($sql4)) {
  252. if ($row['completed'] == "0") {
  253. echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 5a is not filled'>4</span>";
  254. } elseif ($row['completed'] == "1") {
  255. echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 5a is filled'>4</span>";
  256. }
  257. }
  258.  
  259. while ($row = mysql_fetch_assoc($sql5)) {
  260. if ($row['completed'] == "0") {
  261. echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 5b is not filled'>5</span>";
  262. } elseif ($row['completed'] == "1") {
  263. echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 5b is filled'>5</span>";
  264. }
  265. }
  266.  
  267. // $question2 = $sql("SELECT * FROM edit_table_form_2 WHERE int_cust_id = '" . $result['int_cust_id'] . "'");
  268. // $question3 = $db->line("SELECT * FROM questionaire_3n WHERE int_cust_id = '" . $result['int_cust_id'] . "'");
  269. // $question4 = $db->line("SELECT * FROM tform5_a WHERE int_cust_id = '" . $result['int_cust_id'] . "'");
  270. // $question5 = $db->line("SELECT * FROM tform5_b WHERE int_cust_id = '" . $result['int_cust_id'] . "'");
  271. //
  272. // if ($question2['deactive'] == "1") {
  273. // echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 2 is not filled'>2</span>";
  274. // } elseif ($question2['deactive'] == "0") {
  275. // echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 2 is filled'>2</span>";
  276. // }
  277. //
  278. // if ($question3['deactive'] == "1") {
  279. // echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 3 is not filled'>3</span>";
  280. // } elseif ($question3['deactive'] == "0") {
  281. // echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 3 is filled'>3</span>";
  282. // }
  283. //
  284. // if ($question4['deactive'] == "1") {
  285. // echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 4 is not filled'>4</span>";
  286. // } elseif ($question4['deactive'] == "0") {
  287. // echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 4 is filled'>4</span>";
  288. // }
  289. //
  290. // if ($question5['deactive'] == "1") {
  291. // echo "<span class='inactive' data-toggle='tooltip' data-placement='top' title='Questionnaire 5 is not filled'>5</span>";
  292. // } elseif ($question5['deactive'] == "0") {
  293. // echo "<span class='active' data-toggle='tooltip' data-placement='top' title='Questionnaire 5 is filled'>5</span>";
  294. // }
  295. ?>
  296. </td>
  297. </tr>
  298.  
  299. <?php } ?>
  300.  
  301. </tbody>
  302. </table>
  303. </div>
  304. <!-- /.table-responsive -->
  305.  
  306. </div>
  307. <!-- /.panel-body -->
  308.  
  309. <?php
  310. // AICI MODIFICATI numele coloanelor si creati codul HTML
  311. // while ($row = $resql->fetch_assoc()) {
  312. // $re_cnt .= '<h3>'. $row['cust_name']. '</h3>'. $row['int_cust_id']. '<div class="content">'. $row['email']. '</div>';
  313. // echo $row['cust_name'];
  314. // }
  315. } else
  316. $re_cnt .= '0 rezultate';
  317. } else
  318. $re_cnt .= '0 inregistrari in table';
  319. }
  320. } else
  321. $re_cnt .= 'Eroare: ' . $this->conn->error;
  322.  
  323. $this->conn->close();
  324. } else
  325. $re_cnt .= 'Nu exista connectare la baza de date MySQL ' . mysqli_connect_error();
  326.  
  327. return $re_cnt;
  328. }
  329.  
  330. // primeste un Arry cu continutul ce trebuie paginat. Returneaza un sir cu elementele pt. pagina curenta
  331. public function getArrRows($arr) {
  332. $startrow = $this->idpage * $this->rowsperpage; // elementul de la care incepe preluarea
  333. $ar_page = array_slice($arr, $startrow, $this->rowsperpage); // preia elementele pt. pagina curenta
  334. $nre = count($ar_page);
  335. $this->totalpages = ceil(count($arr) / $this->rowsperpage); // seteaza numar total de pagini
  336. $re_cnt = ''; // variabila ce va fi returnata
  337. // AICI ADAUGATI CODUL HTML PT REZULTATUL CE CONTINE FIECARE ELEMENT
  338. for ($i = 0; $i < $nre; $i++) {
  339. $re_cnt .= '<div class="content">' . $ar_page[$i] . '</div>';
  340. }
  341.  
  342. return $re_cnt;
  343. }
  344.  
  345. // metoda pt paginare text, imparte sirul in functie de numarul de caractere ($txtchr), sau nr. parti (txtpieces)
  346. public function getText($text) {
  347. // daca $txtpieces e mai mare decat 0, imparte $text intr-un numar de parti /pagini specificat in $txtpieces
  348. // altfel, imparte textul in functie de numarul maxim de caractere din $txtchr
  349. if ($this->txtpieces > 0) {
  350. $this->txtchr = ceil(strlen($text) / $this->txtpieces); // seteaza $txtchr in functie de nr. parti
  351. }
  352.  
  353. // imparte textul si creaza un Array cu partile obtinute. Returneaza sirul pt. pagina curenta
  354. $newtext = wordwrap($text, $this->txtchr, '#|#');
  355. $ar_text = explode('#|#', $newtext);
  356. $nr_pieces = count($ar_text);
  357.  
  358. // daca paginarea e dupa numarul de parti, si sunt prea multe segmente - uneste pe ultimile doua
  359. if ($this->txtpieces > 0 && $nr_pieces > $this->txtpieces) {
  360. $ar_text[$nr_pieces - 2] .= ' ' . $ar_text[$nr_pieces - 1];
  361. unset($ar_text[$nr_pieces - 1]);
  362. }
  363.  
  364. $this->totalpages = count($ar_text); // seteaza nr. total de pagini
  365. if ($this->idpage > $this->totalpages)
  366. $this->idpage = $this->totalpages;
  367.  
  368. // seteaza un sir care sa fie adaugat la sfarsitul continutului text, daca nu e ultima pagina
  369. $end = ($this->idpage + 1) < $this->totalpages ? ' ...[<i> Continuare in pagina urmatoarte</i>].' : '';
  370.  
  371. return $ar_text[$this->idpage] . $end;
  372. }
  373.  
  374. // metoda ce seteaza link-urile
  375. public function getLinks() {
  376. $re_links = ''; // variabila ce va contine randurile returnate
  377. $currentpage = $this->idpage + 1; // deoarece indexul paginii incepe de la 0, adauga 1 ca sa seteze pagina curenta
  378. $pag_get = '?pg='; // numele pt valoarea GET adaugata in URL
  379. // daca $totalpages>0 si nr total pagini e mai mare sau egal cu pagina curenta
  380. if ($this->totalpages > 0 && $this->totalpages >= $currentpage) {
  381.  
  382. // Link-uri inapoi, daca pagina curenta nu e prima
  383. if ($currentpage > 1) {
  384. // adauga << pentru link la prima pagina
  385. // $re_links .= ' <li><a href="' . $this->pag . '" title="Link 1"><span aria-hidden="true">&laquo;</span></a> </li>&nbsp; ';
  386.  
  387. $prevpage = $currentpage - 1; // pagina anterioara
  388. // adauga < pt link la pagina anterioara, daca nu e 1
  389. if ($prevpage > 0)
  390. $re_links .= ' <li><a href="' . $this->pag . $pag_get . $prevpage . '&rnump=' . $this->rowsperpage . '" title="Link ' . $prevpage . '"><span aria-hidden="true">&laquo;</span></a> &nbsp;</li>';
  391. }else {
  392. $prevpage = $currentpage - 1;
  393. $re_links .= ' <li class="disabled"><a href="' . $this->pag . $pag_get . $prevpage . '&rnump=' . $this->rowsperpage . '" title="Link ' . $prevpage . '"><span aria-hidden="true">&laquo;</span></a> &nbsp;</li>';
  394. }
  395.  
  396. // seteaza link-urile din jurul paginii curente
  397. for ($x = ($currentpage - $this->range); $x <= ($currentpage + $this->range); $x++) {
  398. // daca e un numar intre prima si ultima pagina
  399. if (($x > 0) && ($x <= $this->totalpages)) {
  400. // daca e nr. pagina curenta, afiseaza fara link, altfel adauga link
  401. if ($x == $currentpage)
  402. $re_links .= ' <li class="active"><a href="#">' . $x . '</a></li> ';
  403. else
  404. $re_links .= ' <li><a href="' . $this->pag . $pag_get . $x . '&rnump=' . $this->rowsperpage . '" title="Link ' . $x . '">' . $x . '</a></li> ';
  405. }
  406. }
  407.  
  408. // Daca pagina curenta nu e ultima, adauga link pentru pagina urmatoare si ultima
  409. if ($currentpage != $this->totalpages) {
  410. $nextpage = $currentpage + 1; // obtine pagina urmatoare
  411. // adauga > pt. pagina urmatoare (daca e mai mare decat $this->range si mai mica decat $totalpages)
  412. if ($nextpage > 1 && $nextpage < $this->totalpages)
  413. $re_links .= '&nbsp; <li><a href="' . $this->pag . $pag_get . $nextpage . '&rnump=' . $this->rowsperpage . '" title="Link ' . $nextpage . '"><span aria-hidden="true">&raquo;</span></a></li> ';
  414. // adauga >> pentru ultima pagina, daca e mai mare decat $this->range
  415. // if ($this->totalpages > $this->range)
  416. // $re_links .= ' &nbsp; <a href="' . $this->pag . $pag_get . $this->totalpages . '" title="Link ' . $this->totalpages . '">&gt;&gt; Ultima pagina (' . $this->totalpages . ')</a> ';
  417. }
  418. }
  419.  
  420. // adauga link-urile intr-un DIV si-l returneaza
  421. if (strlen($re_links) > 1)
  422. $re_links = '<nav><ul class="pagination pull-right">' . $re_links . '</nav></div>';
  423. return $re_links;
  424. }
  425.  
  426. }
  427. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement