'; //error_reporting(E_ALL); //ini_set('display_errors','1'); //ini_set("log_errors", 1); //ini_set("error_log", '/home/www/u34119/mail.log'); //ini_set('error_log'); //ini_set('mail.log','/home/www/u34119/mail.log'); class User { public $id; public $db; public $email; public $pass; public $phone; public $role; public $first_name; public $last_name; public $nick; public $company; public static $tbname='user'; public static $currency_name; public static $currency_rate; public static $location=""; public function __construct($id=0) { //echo 'controller construct call'. memory_get_usage().'
'; //exit; if (isset($_SESSION['user'])) { $this->id = $_SESSION['user']['id']; } if (isset($this->id)) { $array = $this->db->get(array('where'=>'id:'.$this->id),self::$tbname); if ($array) { foreach($array[0] as $k=>$v) { if (property_exists(__CLASS__,$k)) { $this->$k = $v; } } } } if (self::$location=="") { $ip = $_SERVER['REMOTE_ADDR']; //$ip="37.190.36.56"; //$json = file_get_contents("http://www.codehelper.io/api/ips/?callback=getIP&ip=".$ip."");//http://api.easyjquery.com/ips/?ip= $json = file_get_contents("http://www.geoplugin.net/php.gp?ip=".$ip.""); $data = unserialize($json); //out($data); //exit; //$data = json_decode($json); //out($data); //exit; self::$location = array(); if (is_array($data)) foreach ($data as $k=>$v) { self::$location[$k]=$v; } } } public static function exchange($amount) { if (self::$location['geoplugin_currencyCode'] && self::$location['geoplugin_currencyCode']!='EUR') return '('.$amount * self::$currency_rate.' '.self::$currency_name.')'; else return ""; } public function registration() { $errorMessage = array(); $matches = $this->db->get(array('where'=>'email:'.$this->email.',phone:'.$this->phone,'cond'=>'or'),self::$tbname); if($matches) { $errorMessage[]="Почта ". $this->email." или номер телефона уже зарегестрирован"; } // $this->pass= User::generatePass(); $host = $_SERVER['HTTP_HOST']; if(empty($errorMessage)) { $this->phone =User::formatPhone($this->phone); $params = array( 'email'=>$this->email, 'phone'=>$this->phone, 'first_name'=>$this->first_name, 'last_name'=>$this->last_name, 'pass'=>User::encode($this->pass) ); $message=" Подтверждение регистрации

Здравствуйте ".$this->first_name."

На этот почтовый адрес был зарегестрирован аккаунт в ".$host."

      
      
      	Логин:".$this->email."
      
      
      	Пароль:".$this->pass."
      
      
      
"; $this->sendEmail($this->email,$message); // out($params);exit; $this->db->insert($params,self::$tbname); $user =$this->db->get(array('what'=>'id','where'=>'email:'.$this->email),self::$tbname); if(!empty($user)) { $company = new Companies; $company->createCompany('Моя Компания',$user[0]['id']); } } return $errorMessage; } public function init($array=array()) { if(empty($array)) { return false; } foreach($array as $k=>$v) { if(property_exists(__CLASS__,$k)) { $this->$k = $v; } } } public static function encode($str,$mode="md5",$salt="") { return $str; // return $mode($mode($mode($str.$salt))); } public function is_logged() { if(isset($_SESSION['user'])){ return true; } return false; } public static function resizeImage($file,$destination,$width="",$height="",$mode='mini') { if(empty($file) | empty($destination)) { return false; } $image = new SimpleImage; $image->load($file); if(empty($height) && empty($width)) { $height = $image->getHeight(); $width = $image->getWidth(); } switch($mode) { case "mini": break; } $image->resize($width,$height); $image->save($destination); } public function profile() { if(!$this->is_logged()) { $this->redirect('user/login'); } $country_list = $this->db->get(array(),'country'); // out($country_list);exit; $this->render('user/index',array('user'>$this,'country_list'=>$country_list)); } public function __authorize(){ $errorMessage = array(); $this->pass=User::encode($this->pass); $data = $this->db->get(array('where'=>'email:'.$this->email.',pass:'.$this->pass),self::$tbname); // out($this);exit; if($data) { // out($data);exit; // if($login){ foreach($data[0] as $k=>$v){ if(property_exists(__CLASS__,$k)) { $this->$k = $v; } } $_SESSION['user'] = array('id'=>$this->id,'email'=>$this->email); // } return true; } return false; } public function logout() { unset($_SESSION['user']); // unset($_COOKIE['user']['email']); $time = time()+ (3600*24*365); setcookie("user",false, time() - 3600); setcookie("user[pass]",'xxxxxxxx', $time); $this->id=""; // $this->name=""; out($_SESSION); out($_COOKIE); // exit; $this->redirect('Index/login'); } public function sendEmail($to="",$message="",$from="noreply@megaindex.ru",$subject="") { $host = $_SERVER['HTTP_HOST']; if($subject==""){ $subject = "Регистрация на ".$host; } $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; // Additional headers $headers .= 'To: <'.$to.'>' . "\r\n"; $headers .= 'From: Megandex-перевозки<'.$from.'>' . "\r\n"; mail($to, $subject, $message, $headers); } public static function generatePass() { $source = "abcdefghi012345jklmnopqrs6789tuvwxyz"; $g =""; $length = rand(6,15); for($i=0;$i<$length;$i++) { $g .= $source{rand(0,(strlen($source)-1))}; } return $g; } public function __validate() { if(!filter_var($this->email,FILTER_VALIDATE_EMAIL)) { return false; } if($this->pass=="") { return false; } return true; } public function loginByPhone() { // $this->phone = "+".trim(trim($this->phone," "),"+"); $this->phone = User::formatPhone($this->phone); $params =array('where'=>'phone:'.$this->phone.',pass:'.User::encode($this->pass)); $user =$this->db->get($params,'user'); return $user; } public function userExists($key,$val) { if($key=="" || $val==""){ return false; } $params = array('where'=>"$key:$val"); // out($params);exit; return $this->db->get($params,self::$tbname); } public static function formatPhone($phone) { $phone = trim(trim(str_replace("-","",str_replace(" ","",$phone))," "),"+"); return str_replace("(","",str_replace(")","",$phone)); } public function updatePass($newPass) { $pass =User::encode($newPass); $this->db->insert(array('pass'=>$pass,'where'=>'id:'.$this->id),self::$tbname,'update'); return true; } public function reminder() { // out($_POST);exit; // phpinfo();exit; // out($_SERVER['DOCUMENT_ROOT']);exit; if(!isset($_POST['reminder_data'])){ $this->redirect($this->returnUrl); exit; } $data = $_POST['reminder_data']; $errorMessage=array(); if(!$this->userExists($data['type'],$data[$data['type']])){ $errorMessage[]='Пользователь с '.($data['type']=='email'?"почтой ":'номером телефона '). $data[$data['type']].' не найден.'; $errorMessage[] = "Попробуйте снова"; } if(empty($errorMessage)){ $newPass= User::generatePass(); switch($data['type']) { case "email": $message ="

Смена Пароля

Из сайта ".$_SERVER['HTTP_HOST']." поступил запрос на смену пароля

,

      
      
      	Новый пароль:".$newPass."
      
      
      

"; $this->sendEmail('kandragoth@gmail.com',$message,"noreply@megaindex.ru",'Смена Пароля I-Perevozki'); // exit; $this->updatePass($newPass); break; case "phone": break; } } } public function ForgotPAss() { $this->render('forgotPass'); } public function update($data=array()){ if(!isset($data)){ return false; } $id = $data['id']; unset($data['id']); $data['where']='id:'.$id; // out($data);exit; $this->db->insert($data,self::$tbname,'update'); return true; } public function Settings(){ $companies = array('0'=>array('id'=>$this->company->id,'name'=>$this->company->name)); $this->render('user/settings',array('companies'=>$companies)); } public function getMyOrders($params = array()){ $order = new Order; $order->driver_id = $this->id; return $order->getDriverOrders($params); } public function login(){ return $this->db->get(array('where'=>'phone:'.User::formatPhone($this->phone).',pass:'.User::encode($this->pass)),'user'); } }?>data = file_get_contents($this->xml_path); } public function getCurrencyValue($value) { $xml = simplexml_load_string($this->data); $arr = $xml->Cube->Cube->Cube; foreach($xml->Cube->Cube->Cube as $item) { $item = (array)$item; if ($item['@attributes']['currency']==$value) { return $item['@attributes']['rate']; } } } } ?>