Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $perfil = new Perfil();
- class Perfil {
- private $db_connection = null;
- private $name;
- private $email;
- private $phone;
- private $website;
- private $password;
- private $password_confirmation;
- private $country;
- private $state;
- private $city;
- private $typereg;
- private $typebrand;
- private $brandlabel;
- private $file;
- private $file_max_size = '10000000';
- private $provider;
- /**
- * @var array Collection of error messages
- */
- public $errors = array();
- /**
- * @var array Collection of success / neutral messages
- */
- public $messages = array();
- private $formats = array("image/jpeg", "image/png", "image/gif", "image/jpg");
- public function __contruction() {
- if(isset($_POST) && !empty($_POST)) {
- if($_POST['view'] == 'perfil') {
- $this->perfil();
- }
- }
- }
- public function perfil() {
- // create a database connection, using the constants from includes/config.php
- $this->db_connection = new mysqli(WOONKLY_HOST,WOONKLY_USER,WOONKLY_PASS,WOONKLY_MYDB);
- if (!$this->db_connection->connect_errno) {
- if($_POST['password'] === $_POST['confirm_password']){
- // escape the POST stuff
- $this->id = $this->db_connection->real_escape_string($_POST['id']);
- $this->name = $this->db_connection->real_escape_string($_POST['name']);
- $this->email = $this->db_connection->real_escape_string($_POST['email']);
- $this->phone = $this->db_connection->real_escape_string($_POST['phone']);
- $this->website = $this->db_connection->real_escape_string($_POST['website']);
- $this->password = $this->db_connection->real_escape_string($_POST['password']);
- $this->password_confirmation = $this->db_connection->real_escape_string($_POST['confirm_password']);
- $this->password = md5($this->password);
- $this->country = $this->db_connection->real_escape_string($_POST['country']);
- $this->state = $this->db_connection->real_escape_string($_POST['state']);
- $this->city = $this->db_connection->real_escape_string($_POST['city']);
- $this->typereg = $this->db_connection->real_escape_string($_POST['$typereg']);
- $this->typebrand = $this->db_connection->real_escape_string($_POST['typebrand']);
- $this->brandlabel = $this->db_connection->real_escape_string($_POST['brandlabel']);
- //$this->file = $this->db_connection->real_escape_string($_FILE['file']);
- $this->provider = $this->db_connection->real_escape_string($_POST['provider']);
- // Check if exist provider.
- if($this->provider === ''){
- // database query, getting all the info of the selected user.
- $checkuser = $this->db_connection->query("SELECT id, avatar FROM wk_usuarios WHERE id = '{$this->id}' ");
- // if this user exists
- if($checkuser->num_rows == 1){
- $result_row = $checkuser->fetch_object();
- if (!empty($result_row->avatar) && isset($result_row->avatar)){
- //Check if exist file in server or directory
- if(file_exists(DIR_DEST.$result_row->avatar)){
- if(unlink(DIR_DEST.$result_row->avatar)){
- $this->file = $this->Loadimage();
- //echo "Elimino el archivo y esta listo para subir el nuevo";
- }else{
- //echo "No esiste el archivo y listo para subir";
- $this->file = $this->Loadimage();
- }
- }else{
- //echo "Ho hay en la sb $result_row->avatar and ".DIR_DEST;
- $this->file = $this->Loadimage();
- }
- }else{
- $this->file = $this->Loadimage();
- }
- // Write new date of user.
- $query_update_user = $this->db_connection->query("UPDATE wk_usuarios SET nombre = '{$this->name}', email = '{$this->email}',
- telefono = '{$this->phone}', ref = '{$this->website}', pass = '{$this->password}', pais = '{$this->country}', estado = '{$this->state}',
- ciudad = '{$this->city}', tipo = '{$this->typereg}', marca_tipo = '{$this->typebrand}', avatar = '{$this->file}' WHERE id = '{$this->id}' ");
- if($query_update_user){
- echo '1';
- //echo json_encode($_FILES);
- //echo json_encode($_FILES);
- //var_dump($_POST, json_encode($_POST));
- //print_r($_POST);
- }else{
- $this->errors[] = "No se actualizaron los datos";
- }
- }else{
- $this->errors[] = "El usuario no exite";
- }
- }else{
- // database query, getting all the info of the selected user.
- $checkuser = $this->db_connection->query("SELECT id FROM wk_social_users WHERE id = '{$this->id}' ");
- // if this user exists
- if($checkuser->num_rows == 1){
- // Write new date of user.
- $query_update_user = $this->db_connection->query("UPDATE wk_social_users SET first_name = '{$this->name}',
- email = '{$this->email}', phone = '{$this->phone}', link = '{$this->website}', modified = NOW() WHERE id = '{$this->id}' ");
- if($query_update_user){
- echo json_encode($_POST);
- echo json_encode($_FILES);
- }else{
- $this->errors[] = "No se actualizaron los datos provider";
- }
- }else{
- $this->errors[] = "El usuario no exite provider";
- }
- }
- }
- }else{
- $this->errors[] = "Error conection a db";
- }
- }
- public function LoadImage(){
- if (in_array($_FILES['file']['type'], $this->formats)){
- $this->file = $_FILES['file']['name'];
- $uploadcheck = move_uploaded_file($_FILES['file']['tmp_name'], DIR_DEST.$this->file);
- if ($uploadcheck){
- //echo "La imagen fue guardo correctamente.";
- return $this->file;
- }else{
- //echo "La imagen no se pudo subir correctamente.";
- //var_dump($_FILES);
- }
- }else{
- //echo "EL formato no esta permitido";
- //var_dump($_FILES);
- }
- }
Add Comment
Please, Sign In to add comment