<?php 
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."CRM/_CRM_config.php");
include_once(PATH_TO_ROOT."init.php");

 class Permissions {
 
 	private $db;
 
 	function __construct($db) { 
 		$this->db = $db; 
	}
	
	function hasPremission($onlyInput){
		$sql = "SELECT * FROM ".DB_WARPIT_WEBCATI_BASE."._group_link gl, ".DB_WARPIT_WEBCATI_BASE."._groups g
		WHERE gl.id = ".$_SESSION['UserInfo']['id']. " AND gl.id_group = ".$onlyInput." AND gl.id_type = 0";
		$res = $this->db->SQLexecute($sql);
		return $this->db->NumRows($res) == 0;
	}
	
	function hasCRMPermission($p){
		$sql = "SELECT permission_id FROM ".WARPIT_CRM."._PermissionLink WHERE permission_id = ".$p." AND GroupId = ".$_SESSION['UserInfo']['id']." AND active = 1";
		$res = $this->db->SQLexecute($sql);
		return $this->db->NumRows($res) != 0;
	}
 } 