<?php

class Forzar_model extends Databases {

    private $db = DB_NAME_HEAD;
    protected $token = false;

    function __construct() {
        parent::__construct();
    }

    function setUrgencia($locales, $funciones) {
        if ($locales == 'todos') {
            $sql = "SELECT EMP FROM APAREMP WHERE EMP!=0";
            $data = parent::query($sql);
            $str = implode(",", $funciones);
            foreach ($data as $value) {
                $sql = "DELETE IDEBO_SETTINGS WHERE EMP=" . $value['EMP'] . "";
                $data = parent::query($sql);
                $sql = "INSERT INTO IDEBO_SETTINGS (EMP,FUNCION_ID) VALUES ('" . $value['EMP'] . "','" . $str . "')";
                $data = parent::query($sql);
            }
        } else {
            $str = implode(",", $funciones);
            if (count($locales) > 0) {
                foreach ($locales as $value) {
                    $sql = "DELETE IDEBO_SETTINGS WHERE EMP=" . $value . "";
                    $data = parent::query($sql);
                    $sql = "INSERT INTO IDEBO_SETTINGS (EMP,FUNCION_ID) VALUES ('" . $value . "','" . $str . "')";
                    $data = parent::query($sql);
                }
            } else {
                return false;
            }
        }
        return true;
    }

    function getFunciones() {
        $sql = "Select * from idebo_funciones where hab=1";
        $data = parent::query($sql);
        if ($data) {
            return $data;
        } else {
            return false;
        }
    }

}
