/var/www/doncode.com.ua/www/libs
Edit: /var/www/doncode.com.ua/www/libs/class.model.php (3945B)
database = new database(DB_TYPE,DB_HOST,DB_NAME,DB_USER,DB_PASS,ENCODE);
$this->form = form::getInstance();
$this->mail = new mail();
}
private function getRolePerms($role_id) {
$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 (){
$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 =:uid";
$sth= $this->database->prepare($sql);
$sth->execute(array(':uid'=>session::get('id_user')));
while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$this->roles[$row["role_name"]] = $this->getRolePerms($row["role_id"]);
}
}
// Проверка установленных полномочий
private function hasPerm($permission) {
return isset($this->_permissions[$permission]);
}
final public function getPerm() {
$this->initRoles();
return $this->_permissions;
}
final public function hasPrivilege($perm) {
$this->initRoles();
foreach ($this->roles as $role) {
if ($this->hasPerm($perm)) {
return true;
}
}
return false;
}
final public function getUserExchanges (){
if(session::has('logedIn') ){
$sth = $this->database->prepare("SELECT er.`exchange_id`,e.*,c.city_name_ru as city,d.host,d.port,d.key
FROM `".DB_PREFIX."exchange_relations` er
INNER JOIN `".DB_PREFIX."exchange` e ON e.id=er.exchange_id
LEFT JOIN `".DB_PREFIX."dcc` d ON e.dcc_id=d.id
INNER JOIN `city_` c ON c.id_city=e.city_id
WHERE e.active='1' AND e.`deleted`='0' AND er.user_id=".session::get('id_user'));
$sth->execute();
if($sth->rowCount()>0){
$arr = $sth->fetchAll();
foreach($arr as $k => $v){
$newarr[$v['id']] = $v;
}
return $newarr;
}
}
return false;
}
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));
}
}
?>