Guest User

Untitled

a guest
May 4th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.18 KB | None | 0 0
  1. $perfil = new Perfil();
  2. class Perfil {
  3. private $db_connection = null;
  4. private $name;
  5. private $email;
  6. private $phone;
  7. private $website;
  8. private $password;
  9. private $password_confirmation;
  10.  
  11. private $country;
  12. private $state;
  13. private $city;
  14. private $typereg;
  15. private $typebrand;
  16. private $brandlabel;
  17. private $file;
  18.  
  19. private $file_max_size = '10000000';
  20.  
  21.  
  22. private $provider;
  23.  
  24. /**
  25. * @var array Collection of error messages
  26. */
  27. public $errors = array();
  28. /**
  29. * @var array Collection of success / neutral messages
  30. */
  31. public $messages = array();
  32.  
  33. private $formats = array("image/jpeg", "image/png", "image/gif", "image/jpg");
  34.  
  35. public function __contruction() {
  36. if(isset($_POST) && !empty($_POST)) {
  37. if($_POST['view'] == 'perfil') {
  38. $this->perfil();
  39. }
  40. }
  41. }
  42.  
  43. public function perfil() {
  44. // create a database connection, using the constants from includes/config.php
  45. $this->db_connection = new mysqli(WOONKLY_HOST,WOONKLY_USER,WOONKLY_PASS,WOONKLY_MYDB);
  46. if (!$this->db_connection->connect_errno) {
  47. if($_POST['password'] === $_POST['confirm_password']){
  48. // escape the POST stuff
  49. $this->id = $this->db_connection->real_escape_string($_POST['id']);
  50. $this->name = $this->db_connection->real_escape_string($_POST['name']);
  51. $this->email = $this->db_connection->real_escape_string($_POST['email']);
  52. $this->phone = $this->db_connection->real_escape_string($_POST['phone']);
  53. $this->website = $this->db_connection->real_escape_string($_POST['website']);
  54. $this->password = $this->db_connection->real_escape_string($_POST['password']);
  55. $this->password_confirmation = $this->db_connection->real_escape_string($_POST['confirm_password']);
  56. $this->password = md5($this->password);
  57. $this->country = $this->db_connection->real_escape_string($_POST['country']);
  58. $this->state = $this->db_connection->real_escape_string($_POST['state']);
  59. $this->city = $this->db_connection->real_escape_string($_POST['city']);
  60. $this->typereg = $this->db_connection->real_escape_string($_POST['$typereg']);
  61. $this->typebrand = $this->db_connection->real_escape_string($_POST['typebrand']);
  62. $this->brandlabel = $this->db_connection->real_escape_string($_POST['brandlabel']);
  63. //$this->file = $this->db_connection->real_escape_string($_FILE['file']);
  64. $this->provider = $this->db_connection->real_escape_string($_POST['provider']);
  65. // Check if exist provider.
  66. if($this->provider === ''){
  67. // database query, getting all the info of the selected user.
  68. $checkuser = $this->db_connection->query("SELECT id, avatar FROM wk_usuarios WHERE id = '{$this->id}' ");
  69. // if this user exists
  70. if($checkuser->num_rows == 1){
  71. $result_row = $checkuser->fetch_object();
  72. if (!empty($result_row->avatar) && isset($result_row->avatar)){
  73. //Check if exist file in server or directory
  74. if(file_exists(DIR_DEST.$result_row->avatar)){
  75. if(unlink(DIR_DEST.$result_row->avatar)){
  76. $this->file = $this->Loadimage();
  77. //echo "Elimino el archivo y esta listo para subir el nuevo";
  78. }else{
  79. //echo "No esiste el archivo y listo para subir";
  80. $this->file = $this->Loadimage();
  81. }
  82. }else{
  83. //echo "Ho hay en la sb $result_row->avatar and ".DIR_DEST;
  84. $this->file = $this->Loadimage();
  85. }
  86. }else{
  87. $this->file = $this->Loadimage();
  88. }
  89. // Write new date of user.
  90. $query_update_user = $this->db_connection->query("UPDATE wk_usuarios SET nombre = '{$this->name}', email = '{$this->email}',
  91. telefono = '{$this->phone}', ref = '{$this->website}', pass = '{$this->password}', pais = '{$this->country}', estado = '{$this->state}',
  92. ciudad = '{$this->city}', tipo = '{$this->typereg}', marca_tipo = '{$this->typebrand}', avatar = '{$this->file}' WHERE id = '{$this->id}' ");
  93.  
  94. if($query_update_user){
  95. echo '1';
  96. //echo json_encode($_FILES);
  97. //echo json_encode($_FILES);
  98. //var_dump($_POST, json_encode($_POST));
  99. //print_r($_POST);
  100. }else{
  101. $this->errors[] = "No se actualizaron los datos";
  102. }
  103.  
  104. }else{
  105. $this->errors[] = "El usuario no exite";
  106. }
  107. }else{
  108. // database query, getting all the info of the selected user.
  109. $checkuser = $this->db_connection->query("SELECT id FROM wk_social_users WHERE id = '{$this->id}' ");
  110. // if this user exists
  111. if($checkuser->num_rows == 1){
  112. // Write new date of user.
  113. $query_update_user = $this->db_connection->query("UPDATE wk_social_users SET first_name = '{$this->name}',
  114. email = '{$this->email}', phone = '{$this->phone}', link = '{$this->website}', modified = NOW() WHERE id = '{$this->id}' ");
  115.  
  116. if($query_update_user){
  117. echo json_encode($_POST);
  118. echo json_encode($_FILES);
  119.  
  120. }else{
  121. $this->errors[] = "No se actualizaron los datos provider";
  122. }
  123.  
  124. }else{
  125. $this->errors[] = "El usuario no exite provider";
  126. }
  127. }
  128.  
  129. }
  130. }else{
  131. $this->errors[] = "Error conection a db";
  132. }
  133. }
  134.  
  135. public function LoadImage(){
  136. if (in_array($_FILES['file']['type'], $this->formats)){
  137. $this->file = $_FILES['file']['name'];
  138. $uploadcheck = move_uploaded_file($_FILES['file']['tmp_name'], DIR_DEST.$this->file);
  139. if ($uploadcheck){
  140. //echo "La imagen fue guardo correctamente.";
  141. return $this->file;
  142. }else{
  143. //echo "La imagen no se pudo subir correctamente.";
  144. //var_dump($_FILES);
  145. }
  146. }else{
  147. //echo "EL formato no esta permitido";
  148. //var_dump($_FILES);
  149. }
  150. }
Add Comment
Please, Sign In to add comment