Advertisement
Guest User

Untitled

a guest
Feb 15th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.98 KB | None | 0 0
  1. <?php
  2.  
  3. class Manager
  4. {
  5.  
  6. //Variaveis -> BD
  7. private $Id;
  8. private $UserName;
  9. private $Password;
  10. private $NomeCompleto;
  11. private $Morada;
  12. private $Email;
  13. private $Level;
  14. //Variaveis non-BD
  15. private $LoggedIn = null;
  16.  
  17. private $saltMD5Key = "h7h7h9y9g94yg94yg8478yg79g@@8349%$##%@3945u9";
  18.  
  19. public function __construct($params)
  20. {
  21.  
  22.  
  23. if($params != null){
  24. if(array_key_exists("Id",$params)){
  25. $this->Id = $params["Id"];
  26. }
  27. if(array_key_exists("UserName",$params)){
  28. $this->UserName = $params["UserName"];
  29. }
  30. if(array_key_exists("Password",$params)){
  31. $this->Password = $params["Password"];
  32. }
  33. if(array_key_exists("NomeCompleto",$params)){
  34. $this->NomeCompleto = $params["NomeCompleto"];
  35. }
  36. if(array_key_exists("Morada",$params)){
  37. $this->Morada = $params["Morada"];
  38. }
  39. if(array_key_exists("Email",$params)){
  40. $this->Email = $params["Email"];
  41. }
  42. if(array_key_exists("Level",$params)){
  43. $this->Level = $params["Level"];
  44. }
  45. }else{
  46. $username = null;
  47. $password = null;
  48. }
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55. public function testConnection(){
  56. $connection = new SQL();
  57.  
  58. $dbhost = $connection->getHost();
  59. $dbuser = $connection->getUsername();
  60. $dbpass = $connection->getPasswordinit7();
  61. $dbname = $connection->getDBname();
  62. $connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
  63. mysql_select_db($dbname) or die("Could not open the db '$dbname'");
  64. $test_query = "SHOW TABLES FROM $dbname";
  65. $result = mysql_query($test_query);
  66. $tblCnt = 0;
  67. while($tbl = mysql_fetch_array($result)) {
  68. $tblCnt++;
  69. #echo $tbl[0]."<br />\n";
  70. }
  71. if (!$tblCnt) {
  72. echo "There are no tables<br />\n";
  73. } else {
  74. echo "There are $tblCnt tables<br />\n";
  75. }
  76.  
  77. }
  78. /*
  79. *
  80. *selecionartabela
  81. */
  82. public function selectTable($alvotabela){
  83.  
  84.  
  85. /**********************
  86. * Database Connection *
  87. ***********************/
  88. $connection = new SQL();
  89.  
  90. $host = $connection->getHost();
  91. $dbusername = $connection->getUsername();
  92. $dbpassword = $connection->getPasswordinit7();
  93. $dbname = $connection->getDBname();
  94.  
  95.  
  96. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. if ($stmt = $link->prepare("SELECT * FROM ".$alvotabela)) { //WHERE ...
  104.  
  105.  
  106. // $stmt->bind_param("s",$alvotabela);
  107. $stmt->execute();
  108.  
  109. $meta = $stmt->result_metadata();
  110. while ($field = $meta->fetch_field())
  111. {
  112. $params[] = &$row[$field->name];
  113. }
  114.  
  115. call_user_func_array(array($stmt, 'bind_result'), $params);
  116.  
  117. while ($stmt->fetch()) {
  118. foreach($row as $key => $val)
  119. {
  120. $c[$key] = $val;
  121. }
  122. $result[] = $c;
  123. }
  124.  
  125. $stmt->close();
  126. }
  127. $link->close();
  128.  
  129. return $result;
  130. /*if($result == NULL){
  131. return false;
  132. }else{
  133. return true;
  134. }*/
  135. // return $result;
  136.  
  137. //end scan
  138.  
  139.  
  140.  
  141.  
  142. mysqli_close($link);
  143. throw new Exception('Failed to connect to the database.');
  144. return False;
  145.  
  146.  
  147. }
  148.  
  149. public function selectTable_where1_limitoffset($alvotabela,$whereparam,$paramequals,$limit,$offset){
  150.  
  151.  
  152. /**********************
  153. * Database Connection *
  154. ***********************/
  155. $connection = new SQL();
  156.  
  157. $host = $connection->getHost();
  158. $dbusername = $connection->getUsername();
  159. $dbpassword = $connection->getPasswordinit7();
  160. $dbname = $connection->getDBname();
  161.  
  162.  
  163. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. if ($stmt = $link->prepare("SELECT * FROM ".$alvotabela." WHERE ".$whereparam." = ? LIMIT ".$limit." OFFSET ".$offset)) { //WHERE ...
  171.  
  172.  
  173. $stmt->bind_param("s",$paramequals);
  174. $stmt->execute();
  175.  
  176. $meta = $stmt->result_metadata();
  177. while ($field = $meta->fetch_field())
  178. {
  179. $params[] = &$row[$field->name];
  180. }
  181.  
  182. call_user_func_array(array($stmt, 'bind_result'), $params);
  183.  
  184. while ($stmt->fetch()) {
  185. foreach($row as $key => $val)
  186. {
  187. $c[$key] = $val;
  188. }
  189. $result[] = $c;
  190. }
  191.  
  192. $stmt->close();
  193. }
  194. $link->close();
  195.  
  196. return $result;
  197. /*if($result == NULL){
  198. return false;
  199. }else{
  200. return true;
  201. }*/
  202. // return $result;
  203.  
  204. //end scan
  205.  
  206.  
  207.  
  208.  
  209. mysqli_close($link);
  210. throw new Exception('Failed to connect to the database.');
  211. return False;
  212.  
  213.  
  214. }
  215.  
  216.  
  217. public function selectTable_where2_limitoffset($alvotabela,$whereparam,$paramequals,$whereparam2,$paramequals2,$limit,$offset){
  218.  
  219.  
  220. /**********************
  221. * Database Connection *
  222. ***********************/
  223. $connection = new SQL();
  224.  
  225. $host = $connection->getHost();
  226. $dbusername = $connection->getUsername();
  227. $dbpassword = $connection->getPasswordinit7();
  228. $dbname = $connection->getDBname();
  229.  
  230.  
  231. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238. if ($stmt = $link->prepare("SELECT * FROM ".$alvotabela." WHERE ".$whereparam." = ? AND ".$whereparam2." LIKE '%".$paramequals2."%' LIMIT ".$limit." OFFSET ".$offset)) { //WHERE ...
  239.  
  240.  
  241. $stmt->bind_param("s",$paramequals);
  242. $stmt->execute();
  243.  
  244. $meta = $stmt->result_metadata();
  245. while ($field = $meta->fetch_field())
  246. {
  247. $params[] = &$row[$field->name];
  248. }
  249.  
  250. call_user_func_array(array($stmt, 'bind_result'), $params);
  251.  
  252. while ($stmt->fetch()) {
  253. foreach($row as $key => $val)
  254. {
  255. $c[$key] = $val;
  256. }
  257. $result[] = $c;
  258. }
  259.  
  260. $stmt->close();
  261. }
  262. $link->close();
  263.  
  264. return $result;
  265. /*if($result == NULL){
  266. return false;
  267. }else{
  268. return true;
  269. }*/
  270. // return $result;
  271.  
  272. //end scan
  273.  
  274.  
  275.  
  276.  
  277. mysqli_close($link);
  278. throw new Exception('Failed to connect to the database.');
  279. return False;
  280.  
  281.  
  282. }
  283. public function selectTable_where1($alvotabela,$whereparam,$paramequals){
  284.  
  285.  
  286. /**********************
  287. * Database Connection *
  288. ***********************/
  289. $connection = new SQL();
  290.  
  291. $host = $connection->getHost();
  292. $dbusername = $connection->getUsername();
  293. $dbpassword = $connection->getPasswordinit7();
  294. $dbname = $connection->getDBname();
  295.  
  296.  
  297. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304. if ($stmt = $link->prepare("SELECT * FROM ".$alvotabela." WHERE ".$whereparam." = ?")) { //WHERE ...
  305.  
  306.  
  307. $stmt->bind_param("s",$paramequals);
  308. $stmt->execute();
  309.  
  310. $meta = $stmt->result_metadata();
  311. while ($field = $meta->fetch_field())
  312. {
  313. $params[] = &$row[$field->name];
  314. }
  315.  
  316. call_user_func_array(array($stmt, 'bind_result'), $params);
  317.  
  318. while ($stmt->fetch()) {
  319. foreach($row as $key => $val)
  320. {
  321. $c[$key] = $val;
  322. }
  323. $result[] = $c;
  324. }
  325.  
  326. $stmt->close();
  327. }
  328. $link->close();
  329.  
  330. return $result;
  331. /*if($result == NULL){
  332. return false;
  333. }else{
  334. return true;
  335. }*/
  336. // return $result;
  337.  
  338. //end scan
  339.  
  340.  
  341.  
  342.  
  343. mysqli_close($link);
  344. throw new Exception('Failed to connect to the database.');
  345. return False;
  346.  
  347.  
  348. }
  349.  
  350. public function selectTable_where2($alvotabela,$whereparam,$paramequals,$whereparam2,$paramequals2){
  351.  
  352.  
  353. /**********************
  354. * Database Connection *
  355. ***********************/
  356. $connection = new SQL();
  357.  
  358. $host = $connection->getHost();
  359. $dbusername = $connection->getUsername();
  360. $dbpassword = $connection->getPasswordinit7();
  361. $dbname = $connection->getDBname();
  362.  
  363.  
  364. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371. if ($stmt = $link->prepare("SELECT * FROM ".$alvotabela." WHERE ".$whereparam." = ? AND ".$whereparam2." = ?")) { //WHERE ...
  372.  
  373.  
  374. $stmt->bind_param("ss",$paramequals,$paramequals2);
  375. $stmt->execute();
  376.  
  377. $meta = $stmt->result_metadata();
  378. while ($field = $meta->fetch_field())
  379. {
  380. $params[] = &$row[$field->name];
  381. }
  382.  
  383. call_user_func_array(array($stmt, 'bind_result'), $params);
  384.  
  385. while ($stmt->fetch()) {
  386. foreach($row as $key => $val)
  387. {
  388. $c[$key] = $val;
  389. }
  390. $result[] = $c;
  391. }
  392.  
  393. $stmt->close();
  394. }
  395. $link->close();
  396.  
  397. return $result;
  398. /*if($result == NULL){
  399. return false;
  400. }else{
  401. return true;
  402. }*/
  403. // return $result;
  404.  
  405. //end scan
  406.  
  407.  
  408.  
  409.  
  410. mysqli_close($link);
  411. throw new Exception('Failed to connect to the database.');
  412. return False;
  413.  
  414.  
  415. }
  416.  
  417. public function updateWhere_1($paramsToUpdate,$paramsWhere,$tabela){
  418. $connection = new SQL();
  419.  
  420. $host = $connection->getHost();
  421. $dbusername = $connection->getUsername();
  422. $dbpassword = $connection->getPasswordinit7();
  423. $dbname = $connection->getDBname();
  424.  
  425. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  426.  
  427. if($tabela == "kyriosusers"){
  428. $query = "UPDATE kyriosusers SET timestampLastUpdate = ? WHERE id = ?";
  429. $stmt = $link->prepare($query);
  430. if($stmt) {
  431. $stmt->bind_param("ss",$paramsToUpdate[0], $paramsWhere[0]);
  432. $stmt->execute();
  433. while ($stmt->fetch()) {
  434. }
  435. mysqli_close($link);
  436. return true;
  437. }
  438. }
  439.  
  440.  
  441. mysqli_close($link);
  442. return false;
  443.  
  444.  
  445. }
  446. public function deleteWhere_1($params,$tabela){
  447. $connection = new SQL();
  448. $host = $connection->getHost();
  449. $dbusername = $connection->getUsername();
  450. $dbpassword = $connection->getPasswordinit7();
  451. $dbname = $connection->getDBname();
  452. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  453.  
  454.  
  455.  
  456.  
  457. $query = "DELETE FROM ".$tabela." WHERE Id_KyriosUser = ?";
  458. $stmt = $link->prepare($query);
  459. if($stmt) {
  460. $stmt->bind_param("s", $params[0]);
  461. $stmt->execute();
  462. while ($stmt->fetch()) {
  463. }
  464.  
  465. mysqli_close( $link);
  466.  
  467.  
  468. return true;
  469. }
  470. else
  471. {
  472. mysqli_close( $link);
  473. return False;
  474. }
  475.  
  476.  
  477. return false;
  478.  
  479.  
  480. }
  481.  
  482. public function dataSize($alvotabela,$userid){
  483.  
  484.  
  485. /**********************
  486. * Database Connection *
  487. ***********************/
  488. $connection = new SQL();
  489.  
  490. $host = $connection->getHost();
  491. $dbusername = $connection->getUsername();
  492. $dbpassword = $connection->getPasswordinit7();
  493. $dbname = $connection->getDBname();
  494.  
  495.  
  496. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503. if ($stmt = $link->prepare("SELECT COUNT(*) FROM ".$alvotabela." WHERE Id_KyriosUser = ?")) { //WHERE ...
  504.  
  505.  
  506. $stmt->bind_param("s",$userid);
  507. $stmt->execute();
  508.  
  509. $meta = $stmt->result_metadata();
  510. while ($field = $meta->fetch_field())
  511. {
  512. $params[] = &$row[$field->name];
  513. }
  514.  
  515. call_user_func_array(array($stmt, 'bind_result'), $params);
  516.  
  517. while ($stmt->fetch()) {
  518. foreach($row as $key => $val)
  519. {
  520. $c[$key] = $val;
  521. }
  522. $result[] = $c;
  523. }
  524.  
  525. $stmt->close();
  526. }
  527. $link->close();
  528.  
  529. return $result;
  530. /*if($result == NULL){
  531. return false;
  532. }else{
  533. return true;
  534. }*/
  535. // return $result;
  536.  
  537. //end scan
  538.  
  539.  
  540.  
  541.  
  542. mysqli_close($link);
  543. throw new Exception('Failed to connect to the database.');
  544. return False;
  545.  
  546. }
  547. public function dataSize_where1($alvotabela,$userid,$whereparam,$paramequals){
  548.  
  549.  
  550. /**********************
  551. * Database Connection *
  552. ***********************/
  553. $connection = new SQL();
  554.  
  555. $host = $connection->getHost();
  556. $dbusername = $connection->getUsername();
  557. $dbpassword = $connection->getPasswordinit7();
  558. $dbname = $connection->getDBname();
  559.  
  560.  
  561. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568. if ($stmt = $link->prepare("SELECT COUNT(*) FROM ".$alvotabela." WHERE Id_KyriosUser = ? AND ".$whereparam." LIKE '%".$paramequals."%'")) { //WHERE ...
  569.  
  570.  
  571. $stmt->bind_param("s",$userid);
  572. $stmt->execute();
  573.  
  574. $meta = $stmt->result_metadata();
  575. while ($field = $meta->fetch_field())
  576. {
  577. $params[] = &$row[$field->name];
  578. }
  579.  
  580. call_user_func_array(array($stmt, 'bind_result'), $params);
  581.  
  582. while ($stmt->fetch()) {
  583. foreach($row as $key => $val)
  584. {
  585. $c[$key] = $val;
  586. }
  587. $result[] = $c;
  588. }
  589.  
  590. $stmt->close();
  591. }
  592. $link->close();
  593.  
  594. return $result;
  595. /*if($result == NULL){
  596. return false;
  597. }else{
  598. return true;
  599. }*/
  600. // return $result;
  601.  
  602. //end scan
  603.  
  604.  
  605.  
  606.  
  607. mysqli_close($link);
  608. throw new Exception('Failed to connect to the database.');
  609. return False;
  610.  
  611. }
  612.  
  613.  
  614. public function dataSizeGeneric_where0($alvotabela,$whereparam,$paramequals){
  615.  
  616.  
  617. /**********************
  618. * Database Connection *
  619. ***********************/
  620. $connection = new SQL();
  621.  
  622. $host = $connection->getHost();
  623. $dbusername = $connection->getUsername();
  624. $dbpassword = $connection->getPasswordinit7();
  625. $dbname = $connection->getDBname();
  626.  
  627.  
  628. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635. if ($stmt = $link->prepare("SELECT COUNT(*) FROM ".$alvotabela." WHERE ".$whereparam." = ?")) { //WHERE ...
  636.  
  637.  
  638. $stmt->bind_param("s",$paramequals);
  639. $stmt->execute();
  640.  
  641. $meta = $stmt->result_metadata();
  642. while ($field = $meta->fetch_field())
  643. {
  644. $params[] = &$row[$field->name];
  645. }
  646.  
  647. call_user_func_array(array($stmt, 'bind_result'), $params);
  648.  
  649. while ($stmt->fetch()) {
  650. foreach($row as $key => $val)
  651. {
  652. $c[$key] = $val;
  653. }
  654. $result[] = $c;
  655. }
  656.  
  657. $stmt->close();
  658. }
  659. $link->close();
  660.  
  661. return $result;
  662. /*if($result == NULL){
  663. return false;
  664. }else{
  665. return true;
  666. }*/
  667. // return $result;
  668.  
  669. //end scan
  670.  
  671.  
  672.  
  673.  
  674. mysqli_close($link);
  675. throw new Exception('Failed to connect to the database.');
  676. return False;
  677.  
  678. }
  679.  
  680. public function dataSizeGeneric_where1($alvotabela,$whereparam1,$paramequals1,$whereparam,$paramequals){
  681.  
  682.  
  683. /**********************
  684. * Database Connection *
  685. ***********************/
  686. $connection = new SQL();
  687.  
  688. $host = $connection->getHost();
  689. $dbusername = $connection->getUsername();
  690. $dbpassword = $connection->getPasswordinit7();
  691. $dbname = $connection->getDBname();
  692.  
  693.  
  694. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701. if ($stmt = $link->prepare("SELECT COUNT(*) FROM ".$alvotabela." WHERE ".$whereparam1." = ? AND ".$whereparam." LIKE '%".$paramequals."%'")) { //WHERE ...
  702.  
  703.  
  704. $stmt->bind_param("s",$paramequals1);
  705. $stmt->execute();
  706.  
  707. $meta = $stmt->result_metadata();
  708. while ($field = $meta->fetch_field())
  709. {
  710. $params[] = &$row[$field->name];
  711. }
  712.  
  713. call_user_func_array(array($stmt, 'bind_result'), $params);
  714.  
  715. while ($stmt->fetch()) {
  716. foreach($row as $key => $val)
  717. {
  718. $c[$key] = $val;
  719. }
  720. $result[] = $c;
  721. }
  722.  
  723. $stmt->close();
  724. }
  725. $link->close();
  726.  
  727. return $result;
  728. /*if($result == NULL){
  729. return false;
  730. }else{
  731. return true;
  732. }*/
  733. // return $result;
  734.  
  735. //end scan
  736.  
  737.  
  738.  
  739.  
  740. mysqli_close($link);
  741. throw new Exception('Failed to connect to the database.');
  742. return False;
  743.  
  744. }
  745. public function dataSize_kyriosusers($alvotabela){
  746.  
  747.  
  748. /**********************
  749. * Database Connection *
  750. ***********************/
  751. $connection = new SQL();
  752.  
  753. $host = $connection->getHost();
  754. $dbusername = $connection->getUsername();
  755. $dbpassword = $connection->getPasswordinit7();
  756. $dbname = $connection->getDBname();
  757.  
  758.  
  759. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766. if ($stmt = $link->prepare("SELECT COUNT(*) FROM ".$alvotabela)) { //WHERE ...
  767.  
  768.  
  769. // $stmt->bind_param("s",$userid);
  770. $stmt->execute();
  771.  
  772. $meta = $stmt->result_metadata();
  773. while ($field = $meta->fetch_field())
  774. {
  775. $params[] = &$row[$field->name];
  776. }
  777.  
  778. call_user_func_array(array($stmt, 'bind_result'), $params);
  779.  
  780. while ($stmt->fetch()) {
  781. foreach($row as $key => $val)
  782. {
  783. $c[$key] = $val;
  784. }
  785. $result[] = $c;
  786. }
  787.  
  788. $stmt->close();
  789. }
  790. $link->close();
  791.  
  792. return $result;
  793. /*if($result == NULL){
  794. return false;
  795. }else{
  796. return true;
  797. }*/
  798. // return $result;
  799.  
  800. //end scan
  801.  
  802.  
  803.  
  804.  
  805. mysqli_close($link);
  806. throw new Exception('Failed to connect to the database.');
  807. return False;
  808.  
  809. }
  810. public function insertData($params,$tabela){
  811.  
  812. $connection = new SQL();
  813.  
  814. $host = $connection->getHost();
  815. $dbusername = $connection->getUsername();
  816. $dbpassword = $connection->getPasswordinit7();
  817. $dbname = $connection->getDBname();
  818.  
  819. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  820.  
  821.  
  822. if($tabela == "kyriosusers"){
  823.  
  824. $timestamp = time();
  825.  
  826. $query = "INSERT INTO kyriosusers(email,timestampLastUpdate)
  827. VALUES(?,?)";
  828. $stmt = $link->prepare($query);
  829. if($stmt) {
  830. $stmt->bind_param("ss", $params[0],$timestamp);
  831. $stmt->execute();
  832. while ($stmt->fetch()) {
  833. }
  834.  
  835. }
  836. }
  837.  
  838. if($tabela == "batismos"){
  839.  
  840. $query = "INSERT INTO batismos(id,baptism_date,block_remove,curia_status,date,entity_description,serie_number,Id_KyriosUser)
  841. VALUES(?,?,?,?,?,?,?,?)";
  842. $stmt = $link->prepare($query);
  843. if($stmt) {
  844. $stmt->bind_param("ssssssss", $params[0],$params[1],$params[2],$params[3],$params[4],$params[5],$params[6],$params[7]);
  845. $stmt->execute();
  846. while ($stmt->fetch()) {
  847. }
  848.  
  849. }
  850.  
  851.  
  852.  
  853. mysqli_close( $link);
  854. return True;
  855. }
  856. else
  857. {
  858. mysqli_close( $link);
  859. return False;
  860. }
  861.  
  862. }
  863.  
  864.  
  865. //arrayTableKeys[k] com os campos da base de dados, paramsDeparams[j][k] com multipla informaçao para inserir, tabela - tabelaalvo
  866. public function GenericMultiple_insertData($arrayTableKeys, $paramsDeparams,$tabela){
  867.  
  868. $connection = new SQL();
  869.  
  870. $host = $connection->getHost();
  871. $dbusername = $connection->getUsername();
  872. $dbpassword = $connection->getPasswordinit7();
  873. $dbname = $connection->getDBname();
  874.  
  875. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  876.  
  877.  
  878. $valkeys = "";
  879. for($i=0;$i<count($arrayTableKeys);$i++){
  880. if($i != 0){
  881. $valkeys = $valkeys.",";
  882. }
  883.  
  884. $valkeys = $valkeys.$arrayTableKeys[$i];
  885.  
  886.  
  887. }
  888.  
  889.  
  890.  
  891. $query = "INSERT INTO ".$tabela."(".$valkeys.")";
  892. $values = "";
  893. for($i = 0; $i<count($paramsDeparams);$i++){
  894. if($i != 0){
  895. $values = $values.",";
  896. }
  897.  
  898.  
  899. $paramvalues = "";
  900. for($j = 0; $j<count($paramsDeparams[$i]); $j++){
  901.  
  902. if($j != 0){
  903. $paramvalues = $paramvalues.",";
  904. }
  905. $paramvalues = $paramvalues."'".$paramsDeparams[$i][$j]."'";
  906.  
  907. }
  908. $values = $values."
  909. (".$paramvalues.")";
  910.  
  911.  
  912. }
  913. $query = $query." VALUES".$values;
  914.  
  915.  
  916. $stmt = $link->prepare($query);
  917. if($stmt) {
  918. $stmt->execute();
  919. while ($stmt->fetch()) {
  920. }
  921.  
  922. }
  923.  
  924.  
  925.  
  926. mysqli_close( $link);
  927. return False;
  928.  
  929.  
  930.  
  931. }
  932.  
  933. public function Multiple_insertData($paramsDeparams,$tabela){
  934.  
  935. $connection = new SQL();
  936.  
  937. $host = $connection->getHost();
  938. $dbusername = $connection->getUsername();
  939. $dbpassword = $connection->getPasswordinit7();
  940. $dbname = $connection->getDBname();
  941.  
  942. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  943.  
  944.  
  945.  
  946. if($tabela == "batismos"){
  947.  
  948. $query = "INSERT INTO batismos(id,baptism_date,block_remove,curia_status,date,entity_description,serie_number,Id_KyriosUser)";
  949. $values = "";
  950. for($i = 0; $i<count($paramsDeparams);$i++){
  951. if($i != 0){
  952. $values = $values.",";
  953. }
  954.  
  955. $values = $values."
  956. ('".$paramsDeparams[$i][0]."','".$paramsDeparams[$i][1]."','".$paramsDeparams[$i][2]."','".$paramsDeparams[$i][3]."','".$paramsDeparams[$i][4]."','".$paramsDeparams[$i][5]."','".$paramsDeparams[$i][6]."','".$paramsDeparams[$i][7]."')";
  957.  
  958.  
  959. }
  960. $query = $query." VALUES".$values;
  961.  
  962. $stmt = $link->prepare($query);
  963. if($stmt) {
  964. $stmt->execute();
  965. while ($stmt->fetch()) {
  966. }
  967.  
  968. }
  969. }
  970. if($tabela == "paroquianos"){
  971.  
  972.  
  973. $query = "INSERT INTO paroquianos(id,block_remove,can_sign_documents,name,newsletter_subscriptor,entity__birth_date,entity__deceased,entity__is_catechized,entity__is_parishioner,entity__serie_number,entity_elder__elder,entity_elder__sick,entity_catechist__catechist,entity_mec__mec,entity_type__name,Id_KyriosUser)";
  974. $values = "";
  975. for($i = 0; $i<count($paramsDeparams);$i++){
  976. if($i != 0){
  977. $values = $values.",";
  978. }
  979.  
  980. $values = $values."
  981. ('".$paramsDeparams[$i][0]."','".$paramsDeparams[$i][1]."','".$paramsDeparams[$i][2]."','".$paramsDeparams[$i][3]."','".$paramsDeparams[$i][4]."','".$paramsDeparams[$i][5]."','".$paramsDeparams[$i][6]."','".$paramsDeparams[$i][7]."','".$paramsDeparams[$i][8]."','".$paramsDeparams[$i][9]."','".$paramsDeparams[$i][10]."','".$paramsDeparams[$i][11]."','".$paramsDeparams[$i][12]."','".$paramsDeparams[$i][13]."','".$paramsDeparams[$i][14]."','".$paramsDeparams[$i][15]."')";
  982.  
  983.  
  984. }
  985. $query = $query." VALUES".$values;
  986.  
  987. $stmt = $link->prepare($query);
  988. if($stmt) {
  989. $stmt->execute();
  990. while ($stmt->fetch()) {
  991. }
  992.  
  993. }
  994.  
  995. mysqli_close( $link);
  996. return True;
  997. }
  998.  
  999.  
  1000. mysqli_close( $link);
  1001. return False;
  1002.  
  1003.  
  1004.  
  1005. }
  1006. /*
  1007. *Atualizar user id
  1008. */
  1009. public function updateUser(){
  1010. $cId = $this->Id;
  1011. $connection = new SQL();
  1012.  
  1013. $host = $connection->getHost();
  1014. $dbusername = $connection->getUsername();
  1015. $dbpassword = $connection->getPasswordinit7();
  1016. $dbname = $connection->getDBname();
  1017.  
  1018. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  1019.  
  1020. $novonome = $this->NomeCompleto;
  1021. $novoemail = $this->Email;
  1022. $novaMorada = $this->Morada;
  1023. $novapassword = $this->Password;
  1024.  
  1025.  
  1026. $query = "UPDATE relatorios_gest SET NomeCompleto = ?,Email = ?, Morada = ?, Password = ? WHERE Id = ?";
  1027. $stmt = $link->prepare($query);
  1028. if($stmt) {
  1029. $stmt->bind_param("s",$cId);
  1030. $stmt->execute();
  1031. while ($stmt->fetch()) {
  1032. }
  1033. mysqli_close($link);
  1034. return true;
  1035. }
  1036.  
  1037.  
  1038.  
  1039. mysqli_close($link);
  1040. return false;
  1041.  
  1042. }
  1043.  
  1044. // TODO
  1045. public function listarUtilizadores(){
  1046.  
  1047.  
  1048. }
  1049.  
  1050. /*
  1051. * apagar o utilizador da BD
  1052. */
  1053. public function deleteUser(){
  1054. $cId = $this->Id;
  1055. // TODO
  1056. }
  1057.  
  1058. public function Login(){
  1059.  
  1060. /**********************
  1061. * Database Connection *
  1062. ***********************/
  1063. $connection = new SQL();
  1064.  
  1065. $host = $connection->getHost();
  1066. $dbusername = $connection->getUsername();
  1067. $dbpassword = $connection->getPasswordinit7();
  1068. $dbname = $connection->getDBname();
  1069. $cUserName = "";
  1070. $cPass = "";
  1071. $result = "";
  1072. $cUserName = $this->UserName;
  1073. $cPass = $this->Password;
  1074.  
  1075. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  1076.  
  1077.  
  1078.  
  1079. $tabletarget = "conta";
  1080.  
  1081.  
  1082. if ($stmt = $link->prepare("SELECT * FROM ".$tabletarget." WHERE UserName = ? AND Password = ?")) {
  1083.  
  1084.  
  1085. $stmt->bind_param("ss", $cUserName, $this->md5string($cPass));
  1086. $stmt->execute();
  1087.  
  1088. $meta = $stmt->result_metadata();
  1089. while ($field = $meta->fetch_field())
  1090. {
  1091. $params[] = &$row[$field->name];
  1092. }
  1093.  
  1094. call_user_func_array(array($stmt, 'bind_result'), $params);
  1095.  
  1096. while ($stmt->fetch()) {
  1097. foreach($row as $key => $val)
  1098. {
  1099. $c[$key] = $val;
  1100. }
  1101. $result[] = $c;
  1102. }
  1103.  
  1104. $stmt->close();
  1105. }
  1106. $link->close();
  1107.  
  1108. if(@$result[0]["UserName"] == $cUserName){
  1109. $this->LoggedIn = true;
  1110. }else{
  1111. $this->LoggedIn = false;
  1112. }
  1113. return $result;
  1114.  
  1115. $this->LoggedIn = false;
  1116. mysqli_close($link);
  1117. throw new Exception('Failed to connect to the database.');
  1118.  
  1119. return False;
  1120.  
  1121. }
  1122.  
  1123. public function Register(){
  1124. $connection = new SQL();
  1125.  
  1126. $host = $connection->getHost();
  1127. $dbusername = $connection->getUsername();
  1128. $dbpassword = $connection->getPasswordinit7();
  1129. $dbname = $connection->getDBname();
  1130.  
  1131. $link = new mysqli($host, $dbusername,$dbpassword,$dbname);
  1132.  
  1133. $cUserName = $this->UserName;
  1134. $cPass = $this->Password;
  1135. $cNome = $this->NomeCompleto;
  1136. $cMorada = $this->Morada;
  1137. $cEmail = $this->Email;
  1138. $cLevel = $this->Level;
  1139.  
  1140.  
  1141. $query = "INSERT INTO conta(UserName,Password,NomeCompleto,Morada,Email,Level)
  1142. VALUES(?,?,?,?,?,?)";
  1143. $stmt = $link->prepare($query);
  1144. if($stmt) {
  1145. $stmt->bind_param("ssssss", $cUserName,$this->md5string($cPass),$cNome,$cMorada,$cEmail,$cLevel);
  1146. $stmt->execute();
  1147. while ($stmt->fetch()) {
  1148. }
  1149. mysqli_close( $link);
  1150. return True;
  1151. }
  1152. else
  1153. {
  1154. mysqli_close( $link);
  1155. return False;
  1156. }
  1157.  
  1158.  
  1159. }
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166. }
  1167.  
  1168.  
  1169. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement