/var/www/myprog.com.ua/cashcontrol/libs
NameSizeModeActions
class.ajax.php7940644editdlrm
class.Barcode.php459360644editdlrm
class.BarcodeEAN.php24320644editdlrm
class.BarcodeI25.php21710644editdlrm
class.barcode_code_39.php33610644editdlrm
class.bootstrap.php132900644editdlrm
class.command.php5680644editdlrm
class.controller.php10610644editdlrm
class.cron.php8440644editdlrm
class.database.php20670644editdlrm
class.dcu_api.php28310644editdlrm
class.form.php29090644editdlrm
class.gd.php89770644editdlrm
class.hash.php2100644editdlrm
class.mail.php44730644editdlrm
class.model.php67990644editdlrm
class.num_to_string.php40160644editdlrm
class.order.php46560644editdlrm
class.payment.php14060644editdlrm
class.session.php11780644editdlrm
class.transfer_scales.php106260644editdlrm
class.validate.php25840644editdlrm
class.view.php11960644editdlrm
Edit: /var/www/myprog.com.ua/cashcontrol/libs/class.model.php (6799B)
database = new database(DB_TYPE,DB_HOST,DB_NAME,DB_USER,DB_PASS,ENCODE); $this->form = form::getInstance(); $this->mail = new mail(); $this->_redirect = (isset($_SERVER['HTTP_REFERER']) && strlen($_SERVER['HTTP_REFERER'])>0)?$_SERVER['HTTP_REFERER']:URL; } public function getClientIdByClientKey($client_key){ try{ //$this->database->log("getClientIdByClientKey ",$client_key); $sth = $this->database->prepare("SELECT ak.client_id, u.login FROM api_keys ak INNER JOIN users u ON u.id=ak.client_id WHERE ak.activated='1' AND ak.client_key='".$client_key."' LIMIT 1 "); $sth->execute(); $data = $sth->fetchAll(PDO::FETCH_ASSOC); if(!isset($data[0]))return null; $this->client_id = $data[0]['client_id']; $this->login = $data[0]['login']; if($this->hasPrivilege('menu_admin')){ $this->su = true; } return $this->client_id; }catch(PDOException $e){ return $e->getMessage(); } } private function getRolePerms($role_id) { $this->_permissions = array(); $sql = "SELECT p.alias FROM `role_perm` AS rp INNER JOIN `permissions` as p ON(rp.perm_id=p.perm_id) WHERE rp.role_id= :role"; $sth = $this->database->prepare($sql); $sth->execute(array(':role'=>$role_id)); while($row = $sth->fetch() ){ $this->_permissions[$row["alias"]] = true; //session::set('perm_'.$row["alias"],true); } return $this->_permissions; } private function initRoles (){ if($this->roles_init){ return false; } if($this->client_id==0){ $this->client_id = session::get('id_user'); } if(!$this->client_id>0){ return false; } $sql = "SELECT ur.role_id, r.role_name FROM `user_role` AS ur INNER JOIN `roles` AS r ON(ur.role_id=r.role_id) WHERE ur.user_id =".$this->client_id; $sth= $this->database->prepare($sql); $sth->execute(); while($row = $sth->fetch(PDO::FETCH_ASSOC)) { $this->roles[$row["role_name"]] = $this->getRolePerms($row["role_id"]); $role_id = $row["role_id"]; //session::set('role_id',$role_id); } $this->roles_init = true; } // Проверка установленных полномочий final public function hasPerm($permission) { return isset($this->_permissions[$permission]); } final public function getPerm() { $this->initRoles(); return $this->_permissions; } final public function getRoles() { $sql = "SELECT r.* FROM `roles` AS r WHERE r.`deleted`='0'"; $sth= $this->database->prepare($sql); $sth->execute(); $res = $sth->fetchAll(PDO::FETCH_ASSOC); return $res; } final public function getPermissions() { $sql = "SELECT r.* FROM `permissions` AS r"; $sth= $this->database->prepare($sql); $sth->execute(); $res = $sth->fetchAll(PDO::FETCH_ASSOC); return $res; } final public function hasPrivilege($perm) { $this->initRoles(); foreach ($this->roles as $role) { if ($this->hasPerm($perm)) { return true; } } return false; } final public function getConf(){ $data = array(); try{ $sth = $this->database->prepare("SELECT c.* FROM `config` c"); $sth->execute(); $res = $sth->fetchAll(PDO::FETCH_ASSOC); foreach($res as $v){ $data[$v['key']] = $v['value']; } }catch(PDOException $e){ return $e->getMessage(); } //var_export($data);exit; return $data; } final public function getCompanys2 ($ajax=false){ // BUH MODE if(session::get('selected_login_id')==0 && $this->hasPrivilege('buh')){ $superuser = ' ';//AND ub.user_id='.session::get('selected_login_id').' '; $sth=$this->database->prepare("SELECT c.* FROM company c LEFT JOIN bills b ON c.id=b.company_id LEFT JOIN user_bills ub ON ub.bill_id=b.id WHERE c.deleted='0' ".$superuser .' GROUP BY c.id'); } // ADMIN MODE if($this->hasPrivilege('menu_admin')){ $superuser = ' '; $sth=$this->database->prepare("SELECT c.* FROM company c LEFT JOIN bills b ON c.id=b.company_id LEFT JOIN user_bills ub ON ub.bill_id=b.id WHERE c.deleted='0' ".$superuser .' GROUP BY c.id'); }else{ if(session::get('selected_login_id')>0){ $superuser = ' AND b.owner_user_id='.session::get('selected_login_id').' '; $sth=$this->database->prepare("SELECT c.* FROM company c LEFT JOIN bills b ON c.id=b.company_id WHERE c.deleted='0' ".$superuser .' GROUP BY c.id'); } } if(isset($sth)){ $sth->execute(); $data = $sth->fetchAll(); if ($ajax){ echo json_encode($data); }else{ return $data; } } } final public function json_encode__($string) { $arrayUtf = array('\u0410', '\u0430', '\u0411', '\u0431', '\u0412', '\u0432', '\u0413', '\u0433', '\u0414', '\u0434', '\u0415', '\u0435', '\u0401', '\u0451', '\u0416', '\u0436', '\u0417', '\u0437', '\u0418', '\u0438', '\u0419', '\u0439', '\u041a', '\u043a', '\u041b', '\u043b', '\u041c', '\u043c', '\u041d', '\u043d', '\u041e', '\u043e', '\u041f', '\u043f', '\u0420', '\u0440', '\u0421', '\u0441', '\u0422', '\u0442', '\u0423', '\u0443', '\u0424', '\u0444', '\u0425', '\u0445', '\u0426', '\u0446', '\u0427', '\u0447', '\u0428', '\u0448', '\u0429', '\u0449', '\u042a', '\u044a', '\u042b', '\u044b', '\u042c', '\u044c', '\u042d', '\u044d', '\u042e', '\u044e', '\u042f', '\u044f'); $arrayCyr = array('А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е', 'Ё', 'ё', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'Й', 'й', 'К', 'к', 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Ш', 'ш', 'Щ', 'щ', 'Ъ', 'ъ', 'Ы', 'ы', 'Ь', 'ь', 'Э', 'э', 'Ю', 'ю', 'Я', 'я'); return str_replace($arrayUtf,$arrayCyr,json_encode($string)); } } ?>