Advertisement
Guest User

OnceBuilder users module.php

a guest
Mar 20th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.05 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Version: 1.0, 31.05.2012
  4.  * by Adam Wysocki, goldpaid777@gmail.com
  5.  *
  6.  * Copyright (c) 2012 Adam Wysocki
  7.  *
  8.  *  This is core connector class
  9.  *
  10. */
  11.  
  12. class once extends core{
  13.     function bulk_action(){
  14.         // used varibles
  15.         $obj['errors'] =  array();
  16.         $obj['error'] = 0 ;
  17.                
  18.         if($this->once_permission_check()){
  19.             if($this->once_csrf_token_check($this->data['csrf_token'])){
  20.                 // Prepare statements to star selected id.
  21.                 $stmt1 = $this->pdo->prepare("UPDATE edit_users SET stars = 1 WHERE id=:id");
  22.                
  23.                 // Prepare statements to unstar selected id.
  24.                 $stmt2 = $this->pdo->prepare("UPDATE edit_users SET stars = 0 WHERE id=:id");
  25.                
  26.                 // Prepare statements to delete selected id.
  27.                 $stmt3 = $this->pdo->prepare("DELETE FROM edit_users WHERE id=:id");
  28.                    
  29.                 // Loop bulk items and make action
  30.                 foreach ($this->data['ids'] as $position => $item){
  31.                     $obj['pages'][]=$position;
  32.                     // Check action type then do it
  33.                     if($this->data['action']=='star'){
  34.                         $stmt1->bindParam(':id', $position, PDO::PARAM_INT);
  35.                         $stmt1->execute();
  36.                     }else if($this->data['action']=='unstar'){
  37.                         $stmt2->bindParam(':id', $position, PDO::PARAM_INT);
  38.                         $stmt2->execute();
  39.                     }else if($this->data['action']=='delete' && $position!=1){
  40.                         $stmt3->bindParam(':id', $position, PDO::PARAM_INT);
  41.                         $stmt3->execute();
  42.                     }
  43.                 }
  44.                 $obj['status']='ok';
  45.             }else{
  46.                 $obj['errors'][]='CSFR token invalid!';
  47.                 $obj['error']++;
  48.             }
  49.         }else{
  50.             $obj['errors'][]='You don\'t have permission!';
  51.             $obj['error']++;
  52.         }
  53.        
  54.         // Return depends on type
  55.         if($this->data['ajax']){
  56.             // Print JSON object
  57.             echo json_encode($obj);
  58.         }else{
  59.             // Return JSON object
  60.             return $obj;
  61.         }
  62.     }
  63.     function set_limit(){
  64.         // Update page limit with once
  65.         $this->once_page_limit('users');
  66.         $obj['status']='ok';
  67.        
  68.         // Return depends on type
  69.         if($this->data['ajax']){
  70.             // Print JSON object
  71.             echo json_encode($obj);
  72.         }else{
  73.             // Return JSON object
  74.             return $obj;
  75.         }
  76.     }
  77.     function get_user_informations(){
  78.         // Prepare statements to get user information.
  79.         $stmt = $this->pdo->prepare("SELECT * FROM edit_users_informations WHERE user_id=:user_id LIMIT 1");
  80.         $stmt->bindParam(':user_id', $this->data['id'], PDO::PARAM_STR, 50);
  81.         $stmt->execute();
  82.  
  83.         $obj['item'] = $stmt->fetch(PDO::FETCH_ASSOC);
  84.  
  85.         // Check if snippet exist.
  86.         if($obj['item']){
  87.             return $obj;
  88.         }else{
  89.             return false;
  90.         }
  91.     }
  92.     function get_user_socials(){
  93.         // Prepare statements to get user information.
  94.         $stmt = $this->pdo->prepare("SELECT * FROM edit_users_socials WHERE user_id=:user_id LIMIT 1");
  95.         $stmt->bindParam(':user_id', $this->data['id'], PDO::PARAM_STR, 50);
  96.         $stmt->execute();
  97.  
  98.         $obj['item'] = $stmt->fetch(PDO::FETCH_ASSOC);
  99.  
  100.         // Check if snippet exist.
  101.         if($obj['item']){
  102.             return $obj;
  103.         }else{
  104.             return false;
  105.         }
  106.     }
  107.    
  108.  
  109.     function item_delete(){
  110.         // used varibles
  111.         $obj['errors'] =  array();
  112.         $obj['error'] = 0 ;
  113.                
  114.         if($this->once_permission_check()){
  115.             if($this->once_csrf_token_check($this->data['csrf_token'])){
  116.                 if($this->data['id']!=1){
  117.                     // Use once to delete item
  118.                     $obj=$this->once_delete_item('users');
  119.                    
  120.                     if($obj['result']){
  121.                         // Set status ok
  122.                         $obj['status']='ok';
  123.                     }
  124.                 }else{
  125.                     $obj['errors'][]='You can\'t delete creator!';
  126.                     $obj['error']++;
  127.                 }
  128.             }else{
  129.                 $obj['errors'][]='CSFR token invalid!';
  130.                 $obj['error']++;
  131.             }
  132.         }else{
  133.             $obj['errors'][]='You don\'t have permission!';
  134.             $obj['error']++;
  135.         }
  136.        
  137.         // Return depends on type
  138.         if($this->data['ajax']){
  139.             // Print JSON object
  140.             echo json_encode($obj);
  141.         }else{
  142.             // Return JSON object
  143.             return $obj;
  144.         }
  145.     }
  146.     function item_edit(){
  147.         // used varibles
  148.         $obj['errors'] =  array();
  149.         $obj['error'] = 0 ;
  150.        
  151.         if($this->once_permission_check()){
  152.             if($this->once_csrf_token_check($this->data['csrf_token'])){
  153.                 // Check if user exist
  154.                 $stmt = $this->pdo->prepare("SELECT * FROM edit_users WHERE id=:id LIMIT 1");
  155.                 $stmt->bindParam(':id', $this->data['id'], PDO::PARAM_INT);
  156.                 $stmt->execute();
  157.                
  158.                 // Get count of returned records
  159.                 $obj['count']=$stmt->rowCount();
  160.                 if($obj['count']){
  161.                     $obj['item']=$stmt->fetch(PDO::FETCH_ASSOC);
  162.  
  163.                     if($this->data['password']!='')
  164.                     $sql="password=:password,";
  165.                     else $sql = '';
  166.                    
  167.                     $stmt = $this->pdo->prepare("UPDATE edit_users SET login=:login, $sql username=:username, type_id=:type_id, email=:email, referer_id=:referer_id WHERE id=:id LIMIT 1");
  168.                     $stmt->bindParam(':id', $this->data['id'], PDO::PARAM_INT);
  169.                     $stmt->bindParam(':login', $this->data['login'], PDO::PARAM_STR, 255);
  170.                    
  171.                     if($this->data['password']!='')
  172.                     $stmt->bindParam(':password', md5($this->data['password']), PDO::PARAM_STR, 32);
  173.                
  174.                     $stmt->bindParam(':username', $this->data['username'], PDO::PARAM_STR, 16);
  175.                     $stmt->bindParam(':type_id', $this->data['type_id'], PDO::PARAM_INT);
  176.                     $stmt->bindParam(':email', $this->data['email'], PDO::PARAM_STR, 32);
  177.                     $stmt->bindParam(':referer_id', $this->data['referer_id'], PDO::PARAM_INT);
  178.                     $stmt->execute();
  179.                    
  180.                     if($stmt->rowCount()){
  181.                         // Set status ok
  182.                         $obj['status']='ok';
  183.                     }else{
  184.                         $obj['errors'][]='Cant save';
  185.                         $obj['error']++;
  186.                     }
  187.                 }else{
  188.                     $obj['errors'][]='user not exist';
  189.                     $obj['error']++;
  190.                 }
  191.             }else{
  192.                 $obj['errors'][]='CSFR token invalid!';
  193.                 $obj['error']++;
  194.             }
  195.         }
  196.        
  197.         // Return depends on type
  198.         if($this->data['ajax']){
  199.             // Print JSON object
  200.             echo json_encode($obj);
  201.         }else{
  202.             // Return JSON object
  203.             return $obj;
  204.         }
  205.     }
  206.     function item_edit_contact(){
  207.         // used varibles
  208.         $obj['errors'] =  array();
  209.         $obj['error'] = 0 ;
  210.                
  211.         if($this->once_permission_check()){
  212.             if($this->once_csrf_token_check($this->data['csrf_token'])){
  213.                 // Check if user exist
  214.                 $stmt = $this->pdo->prepare("SELECT * FROM edit_users WHERE id=:id LIMIT 1");
  215.                 $stmt->bindParam(':id', $this->data['id'], PDO::PARAM_INT);
  216.                 $stmt->execute();
  217.                
  218.                 // Get count of returned records
  219.                 $obj['count']=$stmt->rowCount();
  220.                 if($obj['count']){
  221.                     $obj['item']=$stmt->fetch(PDO::FETCH_ASSOC);
  222.  
  223.                     // Prepare statements to get user information.
  224.                     $stmt = $this->pdo->prepare("SELECT * FROM edit_users_informations WHERE user_id=:user_id LIMIT 1");
  225.                     $stmt->bindParam(':user_id', $this->data['id'], PDO::PARAM_INT);
  226.                     $stmt->execute();
  227.  
  228.                     $obj['item'] = $stmt->fetch(PDO::FETCH_ASSOC);
  229.  
  230.                     // Check if snippet exist.
  231.                     if($obj['item']){
  232.                         // Prepare statements to update user information.
  233.                         $stmt = $this->pdo->prepare("
  234.                             UPDATE edit_users_informations SET firstname=:firstname, lastname=:lastname, email=:email, website=:website, company=:company, address=:address, address2=:address2, city=:city, phone=:phone, zip=:zip, province=:province, country=:country
  235.                             WHERE user_id=:user_id LIMIT 1");
  236.                        
  237.                         $stmt->bindParam(':user_id', $this->data['id'], PDO::PARAM_INT);
  238.                         $stmt->bindParam(':firstname', $this->data['firstname'], PDO::PARAM_STR, 50);
  239.                         $stmt->bindParam(':lastname', $this->data['lastname'], PDO::PARAM_STR, 50);
  240.                         $stmt->bindParam(':email', $this->data['email'], PDO::PARAM_STR, 50);
  241.                         $stmt->bindParam(':website', $this->data['website'], PDO::PARAM_STR, 2000);
  242.                         $stmt->bindParam(':company', $this->data['company'], PDO::PARAM_STR, 100);
  243.                         $stmt->bindParam(':address', $this->data['address'], PDO::PARAM_STR, 100);
  244.                         $stmt->bindParam(':address2', $this->data['address2'], PDO::PARAM_STR, 100);
  245.                         $stmt->bindParam(':city', $this->data['city'], PDO::PARAM_STR, 100);
  246.                         $stmt->bindParam(':phone', $this->data['phone'], PDO::PARAM_STR, 15);
  247.                         $stmt->bindParam(':zip', $this->data['zip'], PDO::PARAM_STR, 10);
  248.                         $stmt->bindParam(':province', $this->data['province'], PDO::PARAM_STR, 100);
  249.                         $stmt->bindParam(':country', $this->data['country'], PDO::PARAM_STR, 100);
  250.                         $stmt->execute();
  251.                        
  252.                         if($stmt->rowCount()){
  253.                             // Set status ok
  254.                             $obj['status']='ok';
  255.                         }else{
  256.                             $obj['errors'][]='Cant save';
  257.                             $obj['error']++;
  258.                         }
  259.                     }else{
  260.                         // Prepare statements to insert user information.
  261.                         $stmt = $this->pdo->prepare("
  262.                             INSERT INTO edit_users_informations (id, user_id, firstname, lastname, email, website, company, address, address2, city, phone, zip, province, country)
  263.                             VALUES ('', :user_id, :firstname, :lastname, :email, :website, :company, :address, :address2, :city, :phone, :zip, :province, :country)
  264.                         ");
  265.                        
  266.                         $stmt->bindParam(':user_id', $this->data['id'], PDO::PARAM_INT);
  267.                         $stmt->bindParam(':firstname', $this->data['firstname'], PDO::PARAM_STR, 50);
  268.                         $stmt->bindParam(':lastname', $this->data['lastname'], PDO::PARAM_STR, 50);
  269.                         $stmt->bindParam(':email', $this->data['email'], PDO::PARAM_STR, 254);
  270.                         $stmt->bindParam(':website', $this->data['website'], PDO::PARAM_STR, 2000);
  271.                         $stmt->bindParam(':company', $this->data['company'], PDO::PARAM_STR, 100);
  272.                         $stmt->bindParam(':address', $this->data['address'], PDO::PARAM_STR, 100);
  273.                         $stmt->bindParam(':address2', $this->data['address2'], PDO::PARAM_STR, 100);
  274.                         $stmt->bindParam(':city', $this->data['city'], PDO::PARAM_STR, 100);
  275.                         $stmt->bindParam(':phone', $this->data['phone'], PDO::PARAM_STR, 15);
  276.                         $stmt->bindParam(':zip', $this->data['zip'], PDO::PARAM_STR, 10);
  277.                         $stmt->bindParam(':province', $this->data['province'], PDO::PARAM_STR, 100);
  278.                         $stmt->bindParam(':country', $this->data['country'], PDO::PARAM_STR, 100);
  279.                         $stmt->execute();
  280.                        
  281.                         if($stmt->rowCount()){
  282.                         // Set status ok
  283.                             $obj['status']='ok';
  284.                         }else{
  285.                             $obj['errors'][]='Cant insert';
  286.                             $obj['error']++;
  287.                         }
  288.                     }
  289.                 }else{
  290.                     $obj['errors'][]='user not exist';
  291.                     $obj['error']++;
  292.                 }
  293.             }else{
  294.                 $obj['errors'][]='CSFR token invalid!';
  295.                 $obj['error']++;
  296.             }
  297.         }
  298.        
  299.         // Return depends on type
  300.         if($this->data['ajax']){
  301.             // Print JSON object
  302.             echo json_encode($obj);
  303.         }else{
  304.             // Return JSON object
  305.             return $obj;
  306.         }
  307.     }
  308.     function item_edit_social(){
  309.         // used varibles
  310.         $obj['errors'] =  array();
  311.         $obj['error'] = 0 ;
  312.                
  313.         if($this->once_permission_check()){
  314.             if($this->once_csrf_token_check($this->data['csrf_token'])){
  315.                 // Check if user exist
  316.                 $stmt = $this->pdo->prepare("SELECT * FROM edit_users WHERE id=:id LIMIT 1");
  317.                 $stmt->bindParam(':id', $this->data['id'], PDO::PARAM_INT);
  318.                 $stmt->execute();
  319.                
  320.                 // Get count of returned records
  321.                 $obj['count']=$stmt->rowCount();
  322.                 if($obj['count']){
  323.                     $obj['item']=$stmt->fetch(PDO::FETCH_ASSOC);
  324.  
  325.                     // Prepare statements to get user information.
  326.                     $stmt = $this->pdo->prepare("SELECT * FROM edit_users_socials WHERE user_id=:user_id LIMIT 1");
  327.                     $stmt->bindParam(':user_id', $this->data['id'], PDO::PARAM_INT);
  328.                     $stmt->execute();
  329.  
  330.                     $obj['item'] = $stmt->fetch(PDO::FETCH_ASSOC);
  331.  
  332.                     // Check if snippet exist.
  333.                     if($obj['item']){
  334.                         // Prepare statements to update user socials.
  335.                         $stmt = $this->pdo->prepare("
  336.                             UPDATE edit_users_socials SET facebook=:facebook, twitter=:twitter, youtube=:youtube, linkedin=:linkedin, dribbble=:dribbble, github=:github, google=:google, behance=:behance, codepen=:codepen
  337.                             WHERE user_id=:user_id LIMIT 1");
  338.                        
  339.                         $stmt->bindParam(':user_id', $this->data['id'], PDO::PARAM_INT);
  340.                         $stmt->bindParam(':facebook', $this->data['facebook'], PDO::PARAM_STR, 50);
  341.                         $stmt->bindParam(':twitter', $this->data['twitter'], PDO::PARAM_STR, 50);
  342.                         $stmt->bindParam(':youtube', $this->data['youtube'], PDO::PARAM_STR, 2000);
  343.                         $stmt->bindParam(':linkedin', $this->data['linkedin'], PDO::PARAM_STR, 100);
  344.                         $stmt->bindParam(':dribbble', $this->data['dribbble'], PDO::PARAM_STR, 100);
  345.                         $stmt->bindParam(':github', $this->data['github'], PDO::PARAM_STR, 100);
  346.                         $stmt->bindParam(':google', $this->data['google'], PDO::PARAM_STR, 100);
  347.                         $stmt->bindParam(':behance', $this->data['behance'], PDO::PARAM_STR, 100);
  348.                         $stmt->bindParam(':codepen', $this->data['codepen'], PDO::PARAM_STR, 100);
  349.                         $stmt->execute();
  350.                        
  351.                         if($stmt->rowCount()){
  352.                             // Set status ok
  353.                             $obj['status']='ok';
  354.                         }else{
  355.                             $obj['errors'][]='Cant save';
  356.                             $obj['error']++;
  357.                         }
  358.                     }else{
  359.                         // Prepare statements to insert user social.
  360.                         $stmt = $this->pdo->prepare("
  361.                             INSERT INTO edit_users_socials (id, user_id, facebook, twitter, youtube, linkedin, dribbble, github, google, behance, codepen)
  362.                             VALUES ('', :user_id, :facebook, :twitter, :youtube, :linkedin, :dribbble, :github, :google, :behance, :codepen)
  363.                         ");
  364.                        
  365.                         $stmt->bindParam(':user_id', $this->data['id'], PDO::PARAM_INT);
  366.                         $stmt->bindParam(':facebook', $this->data['facebook'], PDO::PARAM_STR, 50);
  367.                         $stmt->bindParam(':twitter', $this->data['twitter'], PDO::PARAM_STR, 50);
  368.                         $stmt->bindParam(':youtube', $this->data['youtube'], PDO::PARAM_STR, 2000);
  369.                         $stmt->bindParam(':linkedin', $this->data['linkedin'], PDO::PARAM_STR, 100);
  370.                         $stmt->bindParam(':dribbble', $this->data['dribbble'], PDO::PARAM_STR, 100);
  371.                         $stmt->bindParam(':github', $this->data['github'], PDO::PARAM_STR, 100);
  372.                         $stmt->bindParam(':google', $this->data['google'], PDO::PARAM_STR, 100);
  373.                         $stmt->bindParam(':behance', $this->data['behance'], PDO::PARAM_STR, 100);
  374.                         $stmt->bindParam(':codepen', $this->data['codepen'], PDO::PARAM_STR, 100);
  375.                         $stmt->execute();
  376.                        
  377.                         if($stmt->rowCount()){
  378.                         // Set status ok
  379.                             $obj['status']='ok';
  380.                         }else{
  381.                             $obj['errors'][]='Cant insert';
  382.                             $obj['error']++;
  383.                         }
  384.                     }
  385.                 }else{
  386.                     $obj['errors'][]='user not exist';
  387.                     $obj['error']++;
  388.                 }
  389.             }else{
  390.                 $obj['errors'][]='CSFR token invalid!';
  391.                 $obj['error']++;
  392.             }
  393.         }
  394.        
  395.         // Return depends on type
  396.         if($this->data['ajax']){
  397.             // Print JSON object
  398.             echo json_encode($obj);
  399.         }else{
  400.             // Return JSON object
  401.             return $obj;
  402.         }
  403.     }
  404.     function item_new(){
  405.         // used varibles
  406.         $obj['errors'] =  array();
  407.         $obj['error'] = 0 ;
  408.                
  409.         if($this->once_permission_check()){
  410.             if($this->once_csrf_token_check($this->data['csrf_token'])){
  411.                 // Prepare statements to get selected id.
  412.                 $stmt = $this->pdo->prepare("INSERT INTO edit_users (id, type_id, data) VALUES('', '".$this->data['type_id']."', NOW())");
  413.                 $stmt->execute();
  414.                
  415.                 // Get item object
  416.                 $obj['item']=array(
  417.                     "id" => $this->pdo->lastInsertId(),
  418.                     "type_id" => 0
  419.                 );
  420.                
  421.                 if($obj['item']['id']){
  422.                     // Set status ok
  423.                     $obj['status']='ok';
  424.                 }else{
  425.                     // Return error if item not created
  426.                     $obj['errors'][]='can\'t insert item to: users';
  427.                     $obj['error']++;
  428.                 }
  429.             }else{
  430.                 $obj['errors'][]='CSFR token invalid!';
  431.                 $obj['error']++;
  432.             }
  433.         }else{
  434.             $obj['errors'][]='You don\'t have permission!';
  435.             $obj['error']++;
  436.         }
  437.        
  438.         // Return depends on type
  439.         if($this->data['ajax']){
  440.             // Print JSON object
  441.             echo json_encode($obj);
  442.         }else{
  443.             // Return JSON object
  444.             return $obj;
  445.         }
  446.     }
  447.     function item_star(){
  448.         // used varibles
  449.         $obj['errors'] =  array();
  450.         $obj['error'] = 0 ;
  451.                
  452.         if($this->once_permission_check()){
  453.             if($this->once_csrf_token_check($this->data['csrf_token'])){
  454.                 // Prepare statements to get all layers
  455.                 $stmt = $this->pdo->prepare("SELECT * FROM edit_users WHERE id=:id LIMIT 1");
  456.                 $stmt->bindParam(':id', $this->data['id'], PDO::PARAM_INT);
  457.                 $stmt->execute();
  458.                
  459.                 if($stmt->rowCount()){
  460.                     $row=$stmt->fetch(PDO::FETCH_ASSOC);
  461.                     // Check if its stars/unstars then unstar/star
  462.                     if($row['stars']==1){
  463.                         $stmt = $this->pdo->prepare("UPDATE edit_users SET stars=0 WHERE id=:id LIMIT 1");
  464.                         $stmt->bindParam(':id', $this->data['id'], PDO::PARAM_INT);
  465.                         $stmt->execute();
  466.                     }else{
  467.                         $stmt = $this->pdo->prepare("UPDATE edit_users SET stars=1 WHERE id=:id LIMIT 1");
  468.                         $stmt->bindParam(':id', $this->data['id'], PDO::PARAM_INT);
  469.                         $stmt->execute();
  470.                     }
  471.                     $obj['status']='ok';
  472.                 }else{
  473.                     $obj['errors'][]='Page not exist';
  474.                     $obj['error']++;
  475.                 }
  476.             }else{
  477.                 $obj['errors'][]='CSFR token invalid';
  478.                 $obj['error']++;
  479.             }
  480.         }else{
  481.             $obj['errors'][]='You don\'t have permission';
  482.             $obj['error']++;
  483.         }
  484.         // Return depends on type
  485.         if($this->data['ajax']){
  486.             // Print JSON object
  487.             echo json_encode($obj);
  488.         }else{
  489.             // Return JSON object
  490.             return $obj;
  491.         }
  492.     }
  493.    
  494.     function upload_image(){
  495.         // used varibles
  496.         $obj['errors'] =  array();
  497.         $obj['error'] = 0 ;
  498.                
  499.         if($this->once_csrf_token_check($this->data['csrf_token'])){
  500.             // Prepare statements to get selected user
  501.             $stmt = $this->pdo->prepare("SELECT * FROM edit_users WHERE id=:id LIMIT 1");
  502.             $stmt->bindParam(':id', $this->data['user_id'], PDO::PARAM_INT);
  503.             $stmt->execute();
  504.            
  505.             // Get count of returned records
  506.             $obj['count']=$stmt->rowCount();
  507.             if($obj['count']){
  508.                 if(!$this->data["image"]["error"]){
  509.                     //extract extension
  510.                     $image_extensions_allowed = array('jpg', 'jpeg', 'png', 'gif');
  511.                     $extension = strtolower(substr($this->data["image"]['name'], strrpos($this->data["image"]['name'], '.') + 1));
  512.                    
  513.                     // Check extension
  514.                     if(in_array($extension, $image_extensions_allowed)){
  515.                         $image_mimes_allowed = array("image/gif","image/png","image/jpeg","image/pjpeg");
  516.                         $imageinfo = getimagesize($this->data["image"]['tmp_name']);
  517.                            
  518.                         // Check mime
  519.                         if(isset($imageinfo) && in_array($imageinfo['mime'], $image_mimes_allowed)){
  520.                             // Check size up to 1MB
  521.                             if($this->data["image"]["size"]<= 1000000) {
  522.                                 // Make dirs and generate files
  523.                                 @mkdir("../uploads");
  524.                                 @mkdir("../uploads/".$this->data['id']."");
  525.                                 chmod("../uploads/".$this->data['id']."", 0777);
  526.                                    
  527.                                 // Move uploaded file to upload dir
  528.                                 move_uploaded_file($this->data["image"]["tmp_name"],'../uploads/'.$this->data['id'].'/photo.png');
  529.                                
  530.                                 // Resize image
  531.                                 $this->once_image_resize('../uploads/'.$this->data['id'].'/photo.png',170,170);
  532.  
  533.                                 // Set fields to update
  534.                                 $obj['item']=array(
  535.                                     "id" => $this->data['id']
  536.                                 );
  537.                                
  538.                                 $obj['status']='ok';
  539.                             }else{
  540.                                 $obj['errors'][]='We only accept images up to 1MB';
  541.                                 $obj['error']++;
  542.                             }
  543.                         }else{
  544.                             $obj['errors'][]='We only accept GIF and JPEG images';
  545.                             $obj['error']++;
  546.                         }
  547.                     }else{
  548.                         $obj['errors'][]='Extension not allowed';
  549.                         $obj['error']++;
  550.                     }
  551.                 }else{
  552.                     $obj['errors'][]='Upload error';
  553.                     $obj['error']++;
  554.                 }
  555.             }else{
  556.                 $obj['errors'][]='User not exist';
  557.                 $obj['error']++;
  558.             }
  559.         }else{
  560.             $obj['errors'][]='CSFR token invalid!';
  561.             $obj['error']++;
  562.         }
  563.  
  564.         // Return depends on type
  565.         if($this->data['ajax']){
  566.             // Print JSON object
  567.             echo json_encode($obj);
  568.         }else{
  569.             // Return JSON object
  570.             return $obj;
  571.         }
  572.     }
  573. }
  574. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement