<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class db_menu extends CI_Model {
	function activated_menu($idmenu){
		try {
			$this->db->query("UPDATE sys_menus SET published='1' WHERE id IN (".$idmenu.");");
			if($idmenu=='254,149,132' OR $idmenu=='257,134,148' OR $idmenu=='151,133,256'){
				if($this->isPerdataActive()){
					$this->db->query("UPDATE sys_menus SET published='1' WHERE id IN (146);");
				}
			}
			return TRUE;
		} catch (Exception $e) {
			return FALSE;
		}
	}

	function deactivated_menu($idmenu){
		try {
			$this->db->query("UPDATE sys_menus SET published='0' WHERE id IN (".$idmenu.");");
			if($idmenu=='254,149,132' OR $idmenu=='257,134,148' OR $idmenu=='151,133,256'){
				if($this->isPerdatainActive()){
					$this->db->query("UPDATE sys_menus SET published='0' WHERE id IN (146);");
				}
			}
			return TRUE;
		} catch (Exception $e) {
			return FALSE;
		}
	}

	function get_status_menu(){
		try {
			return $this->db->query("SELECT id,IF(published=1,'Active','Inactive') AS st FROM sys_menus WHERE id IN (149,148,151,156,155,154,6000);");
		} catch (Exception $e) {
			return FALSE;
		}
	}

	
	function isPerdatainActive(){
		try {
			$result = $this->db->query("SELECT id AS st FROM sys_menus WHERE published=1 AND id IN (149,148,151);");
			if($result!=''){
				if($result->num_rows>0)
					return FALSE;
				else
					return TRUE;
			}
		} catch (Exception $e) {
			
		}
	}

	function isPerdataActive(){
		try {
			$result = $this->db->query("SELECT id AS st FROM sys_menus WHERE published=1 AND id IN (149,148,151);");
			if($result->num_rows>0)
				return TRUE;
			else
				return FALSE;
		} catch (Exception $e) {
			
		}
	}
}