fork download
  1. <?php
  2. Class Action {
  3. private $db;
  4.  
  5. public function __construct() {
  6. include 'db_connect.php';
  7.  
  8. $this->db = $conn;
  9. }
  10. function __destruct() {
  11. $this->db->close();
  12. }
  13.  
  14. function login(){
  15. extract($_POST);
  16. $qry = $this->db->query("SELECT * FROM users where email = '".$email."' and password = '".md5($password)."' ");
  17. if($qry->num_rows > 0){
  18. foreach ($qry->fetch_array() as $key => $value) {
  19. if($key != 'passwors' && !is_numeric($key))
  20. $_SESSION['login_'.$key] = $value;
  21. }
  22. return 1;
  23. }else{
  24. return 3;
  25. }
  26. }
  27. function logout(){
  28. foreach ($_SESSION as $key => $value) {
  29. unset($_SESSION[$key]);
  30. }
  31. header("location:login.php");
  32. }
  33. function signup(){
  34. extract($_POST);
  35. $data = " firstname = '$firstname' ";
  36. $data .= ", lastname = '$lastname' ";
  37. $data .= ", middlename = '$middlename' ";
  38. $data .= ", contact = '$contact' ";
  39. $data .= ", address = '$address' ";
  40. $data .= ", email = '$email' ";
  41. $data .= ", password = '".md5($password)."' ";
  42. $chk = $this->db->query("SELECT * FROM users where email = '$email' ")->num_rows;
  43. if($chk > 0){
  44. return 2;
  45. }
  46. $save = $this->db->query("INSERT INTO users set ".$data);
  47. if($save){
  48. $login = $this->login();
  49. if($login == 1)
  50. return 1;
  51. }
  52. }
  53.  
  54. function save_upload(){
  55. extract($_POST);
  56. $ids= array();
  57. for($i = 0 ; $i< count($img);$i++){
  58. $img[$i]= str_replace('data:image/jpeg;base64,', '', $img[$i] );
  59. $img[$i] = base64_decode($img[$i]);
  60. $fname = strtotime(date('Y-m-d H:i'))."_".$imgName[$i];
  61. $upload = file_put_contents("assets/img/uploads/".$fname,$img[$i]);
  62. $data = " file_path = 'img/uploads/".$fname."' ";
  63. $data .= ", user_id = '".$_SESSION['login_id']."' ";
  64. $save[] = $this->db->query("INSERT INTO file_uploads set".$data);
  65. $ids[] = $this->db->insert_id;
  66. }
  67. if(isset($save)){
  68. if($type == 1){
  69. $data = " user_id = '".$_SESSION['login_id']."' ";
  70. $data .= ", content = '$content' ";
  71. $data .= ", file_ids = '".implode(",",$ids)."' ";
  72. $save = $this->db->query("INSERT INTO posts set".$data);
  73. }
  74. return 1;
  75. }
  76. }
  77. function save_comment(){
  78. extract($_POST);
  79.  
  80. $data = " post_id = $post_id ";
  81. $data .= ", user_id = ".$_SESSION['login_id']." ";
  82. $data .= ", comment = '$comment' ";
  83.  
  84. $save = $this->db->query("INSERT INTO comments set ".$data);
  85. if($save){
  86. $id = $this->db->insert_id;
  87. $data = $this->db->query("SELECT c.*,concat(u.firstname,' ',u.middlename,' ',u.lastname) as uname FROM comments c inner join users u on u.id = c.user_id where c.id = $id ")->fetch_array();
  88. foreach($data as $k=>$v){
  89. if(!is_numeric($k))
  90. $c[$k] = $v;
  91. }
  92. $d['user'] = ucwords($c['uname']);
  93. $d['comment'] = $comment;
  94. $d['date'] = date("M d,Y",strtotime($c['date_created']));
  95. return json_encode(array("status"=>1,"data"=>$d));
  96. }
  97. }
  98. function save_posts(){
  99. extract($_POST);
  100.  
  101. $data = " user_id = ".$_SESSION['login_id']." ";
  102. $data .= ", content = '$content' ";
  103. $data .= ", file_ids = '$file_id' ";
  104.  
  105. $save = $this->db->query("INSERT INTO posts set ".$data);
  106. if($save){
  107. return 1;
  108. }
  109. }
  110. }
Success #stdin #stdout 0.04s 25564KB
stdin
Standard input is empty
stdout
Standard output is empty