-- MySQL Administrator dump 1.4
--
-- ------------------------------------------------------
-- Server version	5.0.51a


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;


--
-- Create schema alarmdispatch
--

CREATE DATABASE IF NOT EXISTS alarmdispatch;
USE alarmdispatch;

--
-- Definition of table `alarmi`
--

DROP TABLE IF EXISTS `alarmi`;
CREATE TABLE `alarmi` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `ime` text NOT NULL,
  `opis` text NOT NULL,
  `dodatenopis` text NOT NULL,
  `skupinaA` text NOT NULL,
  `skupinaB` text NOT NULL,
  `opis1` text,
  `dodatenopis1` text,
  `opis2` text,
  `dodatenopis2` text,
  `opis3` text,
  `dodatenopis3` text,
  `opis4` text,
  `dodatenopis4` text,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=627 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `alarmi`
--

/*!40000 ALTER TABLE `alarmi` DISABLE KEYS */;
/*!40000 ALTER TABLE `alarmi` ENABLE KEYS */;


--
-- Definition of table `info`
--

DROP TABLE IF EXISTS `info`;
CREATE TABLE `info` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `ime` text NOT NULL,
  `tag` text NOT NULL,
  `sms` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `info`
--

/*!40000 ALTER TABLE `info` DISABLE KEYS */;
/*!40000 ALTER TABLE `info` ENABLE KEYS */;


--
-- Definition of table `infopodatki`
--

DROP TABLE IF EXISTS `infopodatki`;
CREATE TABLE `infopodatki` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `ime` text NOT NULL,
  `vrednost` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `infopodatki`
--

/*!40000 ALTER TABLE `infopodatki` DISABLE KEYS */;
/*!40000 ALTER TABLE `infopodatki` ENABLE KEYS */;


--
-- Definition of table `nastavitve`
--

DROP TABLE IF EXISTS `nastavitve`;
CREATE TABLE `nastavitve` (
  `folder` text NOT NULL,
  `vrata` text NOT NULL,
  `hitrost` text NOT NULL,
  `servirajVsakih` text NOT NULL,
  `posljiObvestilo` text NOT NULL,
  `posljiObvestiloOb` text NOT NULL,
  `posljiObvestiloNa` text NOT NULL,
  `id` int(10) unsigned NOT NULL,
  `posljiSmsPreko` text NOT NULL,
  `SMSCNaslov` text NOT NULL,
  `waitForAcknowledge` text NOT NULL,
  `mailFrom` text NOT NULL,
  `mailHost` text NOT NULL,
  `mailUser` text NOT NULL,
  `mailPass` text NOT NULL,
  `mailPort` text NOT NULL,
  `nacinPotrjevanja` int(10) unsigned NOT NULL,
  `jakostSignala` int(10) unsigned NOT NULL,
  `maxDogodekId` int(10) unsigned NOT NULL,
  `repeatsms` int(10) unsigned NOT NULL default '1',
  `repeatcall` int(10) unsigned NOT NULL default '1',
  `fromphonenum` varchar(45) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `nastavitve`
--

/*!40000 ALTER TABLE `nastavitve` DISABLE KEYS */;
INSERT INTO `nastavitve` (`folder`,`vrata`,`hitrost`,`servirajVsakih`,`posljiObvestilo`,`posljiObvestiloOb`,`posljiObvestiloNa`,`id`,`posljiSmsPreko`,`SMSCNaslov`,`waitForAcknowledge`,`mailFrom`,`mailHost`,`mailUser`,`mailPass`,`mailPort`,`nacinPotrjevanja`,`jakostSignala`,`maxDogodekId`,`repeatsms`,`repeatcall`,`fromphonenum`) VALUES 
 ('c:\\sms','COM2','9600','15','false','9','049700605',1,'Modem','192.168.0.1:444','true','scada@ipko.com','smtp.ipko.com','scada','5c@d@5@','25',0,66,812,1,1,'');
/*!40000 ALTER TABLE `nastavitve` ENABLE KEYS */;


--
-- Definition of table `reporti`
--

DROP TABLE IF EXISTS `reporti`;
CREATE TABLE `reporti` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `ime` varchar(100) NOT NULL,
  `perioda` int(10) unsigned NOT NULL,
  `vse` int(10) unsigned NOT NULL,
  `lasttime` datetime default NULL,
  `ura` int(10) unsigned default NULL,
  `dan` int(10) unsigned default NULL,
  `datum` int(10) unsigned default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `reporti`
--

/*!40000 ALTER TABLE `reporti` DISABLE KEYS */;
/*!40000 ALTER TABLE `reporti` ENABLE KEYS */;


--
-- Definition of table `reportialarmi`
--

DROP TABLE IF EXISTS `reportialarmi`;
CREATE TABLE `reportialarmi` (
  `reportid` int(10) unsigned NOT NULL,
  `alarmid` int(10) unsigned NOT NULL,
  `id` int(10) unsigned NOT NULL auto_increment,
  PRIMARY KEY  USING BTREE (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `reportialarmi`
--

/*!40000 ALTER TABLE `reportialarmi` DISABLE KEYS */;
/*!40000 ALTER TABLE `reportialarmi` ENABLE KEYS */;


--
-- Definition of table `reportiuporabniki`
--

DROP TABLE IF EXISTS `reportiuporabniki`;
CREATE TABLE `reportiuporabniki` (
  `reportid` int(10) unsigned NOT NULL,
  `uporabnikid` int(10) unsigned NOT NULL,
  `id` int(10) unsigned NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `reportiuporabniki`
--

/*!40000 ALTER TABLE `reportiuporabniki` DISABLE KEYS */;
/*!40000 ALTER TABLE `reportiuporabniki` ENABLE KEYS */;


--
-- Definition of table `skupine`
--

DROP TABLE IF EXISTS `skupine`;
CREATE TABLE `skupine` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `Ime` varchar(45) NOT NULL,
  `CasPotrdila` int(10) unsigned NOT NULL,
  `CasDostava` int(10) unsigned NOT NULL,
  `SteviloVsehPonovitev` int(10) unsigned NOT NULL,
  `CasMedPonovitvamiSMS` int(10) unsigned NOT NULL,
  `SteviloPonovitevSMS` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`Id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `skupine`
--

/*!40000 ALTER TABLE `skupine` DISABLE KEYS */;
/*!40000 ALTER TABLE `skupine` ENABLE KEYS */;


--
-- Definition of table `skupinealarmi`
--

DROP TABLE IF EXISTS `skupinealarmi`;
CREATE TABLE `skupinealarmi` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `skupinaid` int(10) unsigned NOT NULL,
  `alarmid` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=640 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `skupinealarmi`
--

/*!40000 ALTER TABLE `skupinealarmi` DISABLE KEYS */;
/*!40000 ALTER TABLE `skupinealarmi` ENABLE KEYS */;


--
-- Definition of table `skupineinfo`
--

DROP TABLE IF EXISTS `skupineinfo`;
CREATE TABLE `skupineinfo` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `skupinaid` int(10) unsigned NOT NULL,
  `infoid` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `skupineinfo`
--

/*!40000 ALTER TABLE `skupineinfo` DISABLE KEYS */;
/*!40000 ALTER TABLE `skupineinfo` ENABLE KEYS */;


--
-- Definition of table `skupinepravice`
--

DROP TABLE IF EXISTS `skupinepravice`;
CREATE TABLE `skupinepravice` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `skupinaid` int(10) unsigned NOT NULL,
  `uporabnikid` int(10) unsigned NOT NULL,
  `beri` tinyint(1) NOT NULL default '0',
  `pisi` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `skupinepravice`
--

/*!40000 ALTER TABLE `skupinepravice` DISABLE KEYS */;
INSERT INTO `skupinepravice` (`id`,`skupinaid`,`uporabnikid`,`beri`,`pisi`) VALUES 
 (7,5,2,1,1),
 (9,6,2,1,1),
 (10,6,5,1,1),
 (11,6,6,1,1),
 (12,5,7,1,1),
 (13,6,8,1,1),
 (14,5,9,1,1),
 (15,7,2,1,1),
 (16,5,10,1,1);
/*!40000 ALTER TABLE `skupinepravice` ENABLE KEYS */;


--
-- Definition of table `skupineuporabniki`
--

DROP TABLE IF EXISTS `skupineuporabniki`;
CREATE TABLE `skupineuporabniki` (
  `skupinaId` int(10) unsigned NOT NULL,
  `uporabnikId` int(10) unsigned NOT NULL,
  `pozicija` int(10) unsigned NOT NULL,
  `email` varchar(45) NOT NULL,
  `report` varchar(45) NOT NULL,
  `id` int(10) unsigned NOT NULL auto_increment,
  `sms` varchar(45) NOT NULL,
  `zvoni` varchar(45) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `skupineuporabniki`
--

/*!40000 ALTER TABLE `skupineuporabniki` DISABLE KEYS */;
/*!40000 ALTER TABLE `skupineuporabniki` ENABLE KEYS */;


--
-- Definition of table `skupineurniki`
--

DROP TABLE IF EXISTS `skupineurniki`;
CREATE TABLE `skupineurniki` (
  `skupinaId` int(10) unsigned NOT NULL,
  `uporabnikId` int(10) unsigned NOT NULL,
  `urnikId` int(10) unsigned NOT NULL,
  `id` int(10) unsigned NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `skupineurniki`
--

/*!40000 ALTER TABLE `skupineurniki` DISABLE KEYS */;
/*!40000 ALTER TABLE `skupineurniki` ENABLE KEYS */;


--
-- Definition of table `smsposlji`
--

DROP TABLE IF EXISTS `smsposlji`;
CREATE TABLE `smsposlji` (
  `Datum` datetime NOT NULL default '0000-00-00 00:00:00',
  `Prejemnik` varchar(20) NOT NULL,
  `Naslovnik` varchar(250) NOT NULL,
  `CasPotrditev` int(10) unsigned NOT NULL,
  `CasDostava` int(10) unsigned NOT NULL,
  `SteviloPonovitevSMSa` int(10) unsigned NOT NULL,
  `SteviloKompletnihPonovitev` int(10) unsigned NOT NULL,
  `CasMedPonovitvamiSMSa` int(10) unsigned NOT NULL,
  `Glava` varchar(250) NOT NULL,
  `Tekst` varchar(160) NOT NULL,
  `Zvonenje` tinyint(3) unsigned NOT NULL,
  PRIMARY KEY  (`Datum`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1250;

--
-- Dumping data for table `smsposlji`
--

/*!40000 ALTER TABLE `smsposlji` DISABLE KEYS */;
/*!40000 ALTER TABLE `smsposlji` ENABLE KEYS */;


--
-- Definition of table `uporabniki`
--

DROP TABLE IF EXISTS `uporabniki`;
CREATE TABLE `uporabniki` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `ime` varchar(45) NOT NULL,
  `firma` varchar(45) NOT NULL,
  `gsm` varchar(45) NOT NULL,
  `email` varchar(45) NOT NULL,
  `canLogin` tinyint(1) NOT NULL,
  `zgoR` tinyint(1) default NULL,
  `nasR` tinyint(1) default NULL,
  `nasW` tinyint(1) default NULL,
  `upoR` tinyint(1) default NULL,
  `upoW` tinyint(1) default NULL,
  `urnR` tinyint(1) default NULL,
  `urnW` tinyint(1) default NULL,
  `porR` tinyint(1) default NULL,
  `porW` tinyint(1) default NULL,
  `infR` tinyint(1) default NULL,
  `infW` tinyint(1) default NULL,
  `skuR` tinyint(1) default NULL,
  `skuW` tinyint(1) default NULL,
  `user` varchar(45) default NULL,
  `pass` varchar(45) default NULL,
  `alaR` tinyint(1) default NULL,
  `alaW` tinyint(1) default NULL,
  `zgoW` tinyint(1) default NULL,
  `jezik` varchar(45) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `uporabniki`
--

/*!40000 ALTER TABLE `uporabniki` DISABLE KEYS */;
/*!40000 ALTER TABLE `uporabniki` ENABLE KEYS */;


--
-- Definition of table `urniki`
--

DROP TABLE IF EXISTS `urniki`;
CREATE TABLE `urniki` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `ime` varchar(45) NOT NULL,
  `ponod` datetime NOT NULL default '0000-00-00 00:00:00',
  `pondo` datetime NOT NULL default '0000-00-00 00:00:00',
  `torod` datetime NOT NULL default '0000-00-00 00:00:00',
  `tordo` datetime NOT NULL default '0000-00-00 00:00:00',
  `sreod` datetime NOT NULL default '0000-00-00 00:00:00',
  `sredo` datetime NOT NULL default '0000-00-00 00:00:00',
  `cetod` datetime NOT NULL default '0000-00-00 00:00:00',
  `cetdo` datetime NOT NULL default '0000-00-00 00:00:00',
  `petod` datetime NOT NULL default '0000-00-00 00:00:00',
  `petdo` datetime NOT NULL default '0000-00-00 00:00:00',
  `sobod` datetime NOT NULL default '0000-00-00 00:00:00',
  `sobdo` datetime NOT NULL default '0000-00-00 00:00:00',
  `nedod` datetime NOT NULL default '0000-00-00 00:00:00',
  `neddo` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `urniki`
--

/*!40000 ALTER TABLE `urniki` DISABLE KEYS */;
/*!40000 ALTER TABLE `urniki` ENABLE KEYS */;


--
-- Definition of table `zgodovina`
--

DROP TABLE IF EXISTS `zgodovina`;
CREATE TABLE `zgodovina` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `DatumDogodka` datetime NOT NULL,
  `OpisDogodka` text NOT NULL,
  `Data` text NOT NULL,
  `skupinaId` int(10) unsigned default NULL,
  `alarmId` int(10) unsigned default NULL,
  `skupinaIme` text,
  `alarmIme` text,
  `dogodekid` int(10) unsigned default NULL,
  `zgodovinaLevel` int(10) unsigned default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1266164 DEFAULT CHARSET=utf8;

--
-- Dumping data for table `zgodovina`
--

/*!40000 ALTER TABLE `zgodovina` DISABLE KEYS */;
/*!40000 ALTER TABLE `zgodovina` ENABLE KEYS */;


--
-- Definition of procedure `spAlarmiDelete`
--

DROP PROCEDURE IF EXISTS `spAlarmiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spAlarmiDelete`(IN a_id int)
BEGIN
 DELETE from alarmi where id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spAlarmiGetByIme`
--

DROP PROCEDURE IF EXISTS `spAlarmiGetByIme`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spAlarmiGetByIme`(
  IN a_ime text
)
BEGIN
  SELECT * FROM alarmi WHERE ime=a_ime;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spAlarmiGetByOpis`
--

DROP PROCEDURE IF EXISTS `spAlarmiGetByOpis`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spAlarmiGetByOpis`(
 IN a_opis text
)
BEGIN
    SELECT * from alarmi where opis = a_opis;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spAlarmiGetSkupinaA`
--

DROP PROCEDURE IF EXISTS `spAlarmiGetSkupinaA`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spAlarmiGetSkupinaA`()
BEGIN
    select distinct skupinaA from alarmi;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spAlarmiGetSkupinaB`
--

DROP PROCEDURE IF EXISTS `spAlarmiGetSkupinaB`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spAlarmiGetSkupinaB`()
BEGIN
 select distinct skupinaB from alarmi;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spAlarmiInsert`
--

DROP PROCEDURE IF EXISTS `spAlarmiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spAlarmiInsert`(
IN a_ime text,
IN a_opis text,
IN a_dodatenopis text,
IN a_skupinaA text,
IN a_skupinaB text,
IN a_opis1 text,
IN a_dodatenopis1 text,
IN a_opis2 text,
IN a_dodatenopis2 text,
IN a_opis3 text,
IN a_dodatenopis3 text,
IN a_opis4 text,
IN a_dodatenopis4 text
)
BEGIN
    INSERT into alarmi(ime, opis, dodatenopis, skupinaA, skupinaB, opis1, dodatenopis1, opis2, dodatenopis2, opis3, dodatenopis3, opis4, dodatenopis4)
           values (a_ime, a_opis, a_dodatenopis, a_skupinaA, a_skupinaB, a_opis1, a_dodatenopis1, a_opis2, a_dodatenopis2, a_opis3, a_dodatenopis3, a_opis4, a_dodatenopis4);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spAlarmiSelect`
--

DROP PROCEDURE IF EXISTS `spAlarmiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spAlarmiSelect`(
IN a_skupinaA text,
IN a_skupinaB text
)
BEGIN
     SELECT * from alarmi WHERE (skupinaA = a_skupinaA or a_skupinaA = 'none') and
                                (skupinaB = a_skupinaB or a_skupinaB = 'none');
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spAlarmiUpdate`
--

DROP PROCEDURE IF EXISTS `spAlarmiUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spAlarmiUpdate`(
IN a_id int,
IN a_ime text,
IN a_opis text,
IN a_dodatenopis text,
IN a_skupinaA text,
IN a_skupinaB text,
IN a_opis1 text,
IN a_dodatenopis1 text,
IN a_opis2 text,
IN a_dodatenopis2 text,
IN a_opis3 text,
IN a_dodatenopis3 text,
IN a_opis4 text,
IN a_dodatenopis4 text
)
BEGIN
    UPDATE alarmi SET id = a_id, ime = a_ime, opis = a_opis, dodatenopis = a_dodatenopis,
                      skupinaA = a_skupinaA, skupinaB = a_skupinaB, opis1 = a_opis1, dodatenopis1 = a_dodatenopis1,
                      opis2 = a_opis2, dodatenopis2 = a_dodatenopis2, opis3 = a_opis3, dodatenopis3 = a_dodatenopis3,
                      opis4 = a_opis4, dodatenopis4 = a_dodatenopis4 where id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spInfoDelete`
--

DROP PROCEDURE IF EXISTS `spInfoDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spInfoDelete`(
  IN a_id int
)
BEGIN
  delete from skupineinfo where infoid = a_id;
  delete from info where id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spInfoInsert`
--

DROP PROCEDURE IF EXISTS `spInfoInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spInfoInsert`(
  IN a_ime text,
  in a_sms text,
  in a_tag text
)
BEGIN
  insert into info (ime, sms, tag) values (a_ime, a_sms, a_tag);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spInfoPodatkiSelect`
--

DROP PROCEDURE IF EXISTS `spInfoPodatkiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spInfoPodatkiSelect`()
BEGIN
select * from infoPodatki;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spInfoSelect`
--

DROP PROCEDURE IF EXISTS `spInfoSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spInfoSelect`()
BEGIN
  select * from info;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spInfoSelectBy`
--

DROP PROCEDURE IF EXISTS `spInfoSelectBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spInfoSelectBy`(
  IN a_tag text
)
BEGIN
  SELECT * FROM info where tag = a_tag;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spInfoUpdate`
--

DROP PROCEDURE IF EXISTS `spInfoUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spInfoUpdate`(
  IN a_ime text,
  in a_sms text,
  in a_tag text,
  IN a_id int
)
BEGIN
  UPDATE Info Set ime = a_ime, tag = a_tag, sms = a_sms where id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spNastavitveDogodekId`
--

DROP PROCEDURE IF EXISTS `spNastavitveDogodekId`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spNastavitveDogodekId`()
BEGIN
  UPDATE nastavitve SET maxDogodekId = (maxDogodekId+1) WHERE id = 1;
  SELECT maxDogodekId from nastavitve where id = 1;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spNastavitveGet`
--

DROP PROCEDURE IF EXISTS `spNastavitveGet`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spNastavitveGet`()
BEGIN
        SELECT * from nastavitve ;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spNastavitveUpdate`
--

DROP PROCEDURE IF EXISTS `spNastavitveUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spNastavitveUpdate`(
   IN a_folder TEXT,
   IN a_vrata TEXT,
   IN a_hitrost TEXT,
   IN a_servirajVsakih TEXT,
   IN a_posljiObvestilo TEXT,
   IN a_posljiObvestiloOb TEXT,
   IN a_posljiObvestiloNa TEXT,
   IN a_posljiSmsPreko TEXT,
   IN a_SMSCNaslov TEXT,
   IN a_waitForAcknowledge TEXT,
   IN a_mailFrom TEXT,
   IN a_mailHost TEXT,
   IN a_mailPort TEXT,
   IN a_mailUser TEXT,
   IN a_mailPass TEXT,
   IN a_NacinPotrjevanja INT,
   IN a_repeatsms INT,
   IN a_repeatcall INT,
   IN a_fromphonenum VARCHAR(45)
)
BEGIN
      UPDATE nastavitve SET folder = a_folder, vrata = a_vrata, hitrost = a_hitrost,
                            servirajVsakih = a_servirajVsakih, posljiObvestilo = a_posljiObvestilo,
                            posljiObvestiloOb = a_posljiObvestiloOb, posljiObvestiloNa = a_posljiObvestiloNa,
                            posljiSmsPreko = a_posljiSmsPreko, SMSCNaslov = a_SMSCNaslov,
                            waitForAcknowledge = a_waitForAcknowledge, mailFrom = a_mailFrom,
                            mailHost = a_mailHost, mailPort = a_mailPort, mailUser = a_mailUser,
                            mailPass = a_mailPass, nacinPotrjevanja = a_NacinPotrjevanja,
                            repeatsms = a_repeatsms, repeatcall = a_repeatcall, fromphonenum = a_fromphonenum
                        WHERE  id = 1;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spNastavitveUpdateDogodekId`
--

DROP PROCEDURE IF EXISTS `spNastavitveUpdateDogodekId`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spNastavitveUpdateDogodekId`(IN a_maxDogodekId int)
BEGIN
  UPDATE nastavitve SET maxDogodekId = a_maxDogodekId WHERE id = 1;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spNastavitveUpdateJakostSignala`
--

DROP PROCEDURE IF EXISTS `spNastavitveUpdateJakostSignala`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spNastavitveUpdateJakostSignala`( IN a_jakostSignala int )
BEGIN
  UPDATE nastavitve SET jakostSignala = a_jakostSignala WHERE id = 1;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiAlarmiDelete`
--

DROP PROCEDURE IF EXISTS `spReportiAlarmiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiAlarmiDelete`(IN a_id int)
BEGIN
 DELETE FROM ReportiAlarmi WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiAlarmiInsert`
--

DROP PROCEDURE IF EXISTS `spReportiAlarmiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiAlarmiInsert`(
 IN a_reportid int,
 IN a_alarmid int
)
BEGIN
 INSERT INTO ReportiAlarmi(reportid, alarmid) VALUES(a_reportid, a_alarmid);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiAlarmiSelect`
--

DROP PROCEDURE IF EXISTS `spReportiAlarmiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiAlarmiSelect`()
BEGIN
 SELECT * FROM ReportiAlarmi;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiAlarmiSelectBy`
--

DROP PROCEDURE IF EXISTS `spReportiAlarmiSelectBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiAlarmiSelectBy`(
IN a_alarmid int,
IN a_reportid int
)
BEGIN
select reportialarmi.id, reportialarmi.reportid, reportialarmi.alarmid, reporti.ime from
        reportialarmi left join reporti on reporti.id = reportialarmi.reportid where
        (reportialarmi.reportid = a_reportid or a_reportid = 0) and
        (reportialarmi.alarmid = a_alarmid or a_alarmid = 0);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiAlarmiUpdate`
--

DROP PROCEDURE IF EXISTS `spReportiAlarmiUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiAlarmiUpdate`(
 IN a_id int,
 IN a_reportid int,
 IN a_alarmid int
)
BEGIN
 UPDATE ReportiAlarmi SET reportid = a_reportid, alarmid = a_alarmid WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiDelete`
--

DROP PROCEDURE IF EXISTS `spReportiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiDelete`(
 IN a_id int
)
BEGIN
DELETE FROM ReportiUporabniki WHERE reportid = a_id;
DELETE FROM ReportiAlarmi WHERE reportid = a_id;
DELETE FROM Reporti WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiInsert`
--

DROP PROCEDURE IF EXISTS `spReportiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiInsert`(
 IN a_ime varchar(100),
 IN a_perioda int,
 IN a_vse int,
 IN a_lasttime datetime,
 IN a_ura int,
 IN a_dan int,
 IN a_datum int
)
BEGIN
 INSERT INTO Reporti(ime, perioda, vse, lasttime, ura, dan, datum) VALUES(a_ime, a_perioda, a_vse, a_lasttime, a_ura, a_dan, a_datum);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiSelect`
--

DROP PROCEDURE IF EXISTS `spReportiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiSelect`()
BEGIN
SELECT * from Reporti;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiUpdate`
--

DROP PROCEDURE IF EXISTS `spReportiUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiUpdate`(
 IN a_id int,
 IN a_ime varchar(100),
 IN a_perioda int,
 IN a_vse int,
 IN a_lasttime datetime,
 IN a_ura int,
 IN a_dan int,
 IN a_datum int
)
BEGIN
 UPDATE Reporti SET ime = a_ime, perioda = a_perioda, vse = a_vse, lasttime = a_lasttime,
                    ura = a_ura, dan = a_dan, datum = a_datum WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiUporabnikiDelete`
--

DROP PROCEDURE IF EXISTS `spReportiUporabnikiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiUporabnikiDelete`(
 IN a_id int
)
BEGIN
 DELETE FROM ReportiUporabniki WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiUporabnikiInsert`
--

DROP PROCEDURE IF EXISTS `spReportiUporabnikiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiUporabnikiInsert`(
 IN a_reportid int,
 IN a_uporabnikid int
)
BEGIN
 INSERT INTO ReportiUporabniki(reportid, uporabnikid) VALUES(a_reportid, a_uporabnikid);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiUporabnikiSelect`
--

DROP PROCEDURE IF EXISTS `spReportiUporabnikiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiUporabnikiSelect`()
BEGIN
 SELECT * from ReportiUporabniki;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiUporabnikiSelectBy`
--

DROP PROCEDURE IF EXISTS `spReportiUporabnikiSelectBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiUporabnikiSelectBy`(IN a_reportid int)
BEGIN
 SELECT ReportiUporabniki.id, ReportiUporabniki.reportid, ReportiUporabniki.uporabnikid, Uporabniki.ime, Uporabniki.email
 FROM ReportiUporabniki
 LEFT JOIN Uporabniki ON uporabniki.id = ReportiUporabniki.uporabnikid
 WHERE ReportiUporabniki.reportid = a_reportid;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spReportiUporabnikiUpdate`
--

DROP PROCEDURE IF EXISTS `spReportiUporabnikiUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spReportiUporabnikiUpdate`(
 IN a_id int,
 IN a_uporabnikid int,
 IN a_reportid int
)
BEGIN
 UPDATE ReportiUporabniki SET uporabnikid = a_uporabnikid, reportid = a_reportid WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineAlarmiDelete`
--

DROP PROCEDURE IF EXISTS `spSkupineAlarmiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineAlarmiDelete`(IN a_id int)
BEGIN
 delete from skupinealarmi where id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineAlarmiGetByAlarmName`
--

DROP PROCEDURE IF EXISTS `spSkupineAlarmiGetByAlarmName`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineAlarmiGetByAlarmName`(
 IN a_name text
)
BEGIN
    SELECT skupinealarmi.id, skupinealarmi.skupinaid, skupinealarmi.alarmid, skupine.ime FROM skupinealarmi
    INNER JOIN alarmi ON alarmi.id = skupinealarmi.alarmid
    LEFT JOIN skupine ON skupine.id = skupinealarmi.skupinaid
    WHERE alarmi.ime = a_name;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineAlarmiInsert`
--

DROP PROCEDURE IF EXISTS `spSkupineAlarmiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineAlarmiInsert`(
IN a_skupinaid int,
IN a_alarmid int
)
BEGIN
      INSERT into skupinealarmi (skupinaid, alarmid) values (a_skupinaid, a_alarmid);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineAlarmiNewSelect`
--

DROP PROCEDURE IF EXISTS `spSkupineAlarmiNewSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineAlarmiNewSelect`()
BEGIN

SELECT skupinealarmi.id, alarmi.id as aid,skupinaid, alarmid, EXISTS(SELECT * FROM skupinealarmi WHERE alarmid=alarmi.id) as skupinaexists,  ime FROM skupinealarmi  RIGHT JOIN alarmi ON alarmi.id = skupinealarmi.alarmid HAVING skupinaid=1 or skupinaid is null;

END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineAlarmiSelect`
--

DROP PROCEDURE IF EXISTS `spSkupineAlarmiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineAlarmiSelect`()
BEGIN
   select * from skupinealarmi;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineAlarmiSelectBy`
--

DROP PROCEDURE IF EXISTS `spSkupineAlarmiSelectBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineAlarmiSelectBy`(
IN a_alarmid int,
IN a_skupinaid int
)
BEGIN
 select skupinealarmi.id, skupinealarmi.skupinaid, skupinealarmi.alarmid, skupine.ime from
        skupinealarmi left join skupine on skupine.id = skupinealarmi.skupinaid where
        (skupinealarmi.skupinaid = a_skupinaid or a_skupinaid = 0) and
        (skupinealarmi.alarmid = a_alarmid or a_alarmid = 0);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineAlarmiUpdate`
--

DROP PROCEDURE IF EXISTS `spSkupineAlarmiUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineAlarmiUpdate`(
IN a_id int,
IN a_skupinaid int,
IN a_alarmid int
)
BEGIN
     UPDATE skupinaalarmi SET skupinaid = a_skupinaid, alarmid = a_alarmid where id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineDelete`
--

DROP PROCEDURE IF EXISTS `spSkupineDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineDelete`(IN a_id int)
BEGIN
       DELETE FROM skupineAlarmi WHERE skupinaid = a_id;
       DELETE FROM skupineUporabniki WHERE skupinaid = a_id;
       DELETE FROM skupineUrniki WHERE skupinaid = a_id;
       DELETE FROM skupineinfo WHERE skupinaId = a_Id;
       DELETE FROM skupinepravice WHERE skupinaId = a_Id;
       DELETE FROM skupine WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineInfoDelete`
--

DROP PROCEDURE IF EXISTS `spSkupineInfoDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineInfoDelete`(IN a_Id int)
BEGIN
  delete from skupineinfo where id=a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineInfoInsert`
--

DROP PROCEDURE IF EXISTS `spSkupineInfoInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineInfoInsert`(
  IN a_SkupinaId int,
  IN a_InfoId int

)
BEGIN
INSERT into skupineinfo (skupinaid, infoid) values (a_SkupinaId, a_InfoId);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineInfoSelect`
--

DROP PROCEDURE IF EXISTS `spSkupineInfoSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineInfoSelect`()
BEGIN
SELECT skupineinfo.id, skupinaid, infoid, info.ime as ime FROM SKUPINEINFO
      LEFT JOIN info ON info.id = infoid;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineInfoSelectBy`
--

DROP PROCEDURE IF EXISTS `spSkupineInfoSelectBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineInfoSelectBy`(
  IN a_SkupinaId int,
  IN a_InfoId  int
)
BEGIN
  SELECT skupineinfo.id, skupinaid, infoid, info.ime as ime FROM skupineinfo
  LEFT JOIN info ON info.id = infoid WHERE
  (skupinaId = a_SkupinaId || a_SkupinaId = -1) &&
  (infoId = a_InfoId || a_InfoId = -1);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineInfoUpdate`
--

DROP PROCEDURE IF EXISTS `spSkupineInfoUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineInfoUpdate`(
  IN a_Id int,
  IN a_SkupinaId int,
  IN a_InfoId int
)
BEGIN
  UPDATE SKUPINEINFO SET skupinaId = a_SkupinaId, infoId = a_InfoId where id = a_Id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineInsert`
--

DROP PROCEDURE IF EXISTS `spSkupineInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineInsert`(
IN a_ime VARCHAR(45),
IN a_casPotrdila int,
IN a_CasDostava int,
IN a_SteviloVsehPonovitev int,
IN a_CasMedPonovitvamiSMS int,
IN a_SteviloPonovitevSMS int
)
BEGIN
    INSERT INTO skupine (ime,casPotrdila, CasDostava, SteviloVsehPonovitev, CasMedPonovitvamiSMS, SteviloPonovitevSMS)
      VALUES(a_ime,a_casPotrdila, a_CasDostava, a_SteviloVsehPonovitev, a_CasMedPonovitvamiSMS, a_SteviloPonovitevSMS);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupinePraviceDelete`
--

DROP PROCEDURE IF EXISTS `spSkupinePraviceDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupinePraviceDelete`(IN a_id int)
BEGIN
  delete from skupinepravice where id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupinePraviceInsert`
--

DROP PROCEDURE IF EXISTS `spSkupinePraviceInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupinePraviceInsert`(
 IN a_skupinaid int,
  IN a_uporabnikid int,
  IN a_beri boolean,
  IN a_pisi boolean
)
BEGIN
  INSERT into skupinepravice (skupinaid, uporabnikid, beri, pisi)
          values (a_skupinaid, a_uporabnikid, a_beri, a_pisi);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupinePraviceSelect`
--

DROP PROCEDURE IF EXISTS `spSkupinePraviceSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupinePraviceSelect`()
BEGIN
  select * from skupinepravice;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupinePraviceSelectBy`
--

DROP PROCEDURE IF EXISTS `spSkupinePraviceSelectBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupinePraviceSelectBy`(
 IN a_skupinaid int,
 IN a_uporabnikid int
)
BEGIN
select * from skupinepravice where (skupinaid = a_skupinaid || a_skupinaid = 0)
        AND (uporabnikid = a_uporabnikid || a_uporabnikid = 0);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupinePraviceUpdate`
--

DROP PROCEDURE IF EXISTS `spSkupinePraviceUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupinePraviceUpdate`(
IN a_id int,
  IN a_skupinaid int,
  IN a_uporabnikid int,
  IN a_beri boolean,
  IN a_pisi boolean
)
BEGIN
  UPDATE skupinepravice SET skupinaid = a_skupinaid, uporabnikid = a_uporabnikid,
  beri = a_beri, pisi = a_pisi WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineSelect`
--

DROP PROCEDURE IF EXISTS `spSkupineSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineSelect`()
BEGIN
           SELECT Id,ime,casPotrdila, CasDostava, SteviloVsehPonovitev, CasMedPonovitvamiSMS, SteviloPonovitevSMS FROM skupine;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUpdate`
--

DROP PROCEDURE IF EXISTS `spSkupineUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUpdate`(
IN a_id int,
IN a_ime VARCHAR(45),
IN a_casPotrdila int,
IN a_CasDostava int,
IN a_SteviloVsehPonovitev int,
IN a_CasMedPonovitvamiSMS int,
IN a_SteviloPonovitevSMS int
)
BEGIN
    UPDATE skupine SET ime = a_ime, casPotrdila = a_casPotrdila, CasDostava = a_CasDostava,
                      SteviloVsehPonovitev = a_SteviloVsehPonovitev,
                      CasMedPonovitvamiSMS = a_CasMedPonovitvamiSMS,
                      SteviloPonovitevSMS = a_SteviloPonovitevSMS WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUporabnikiDelete`
--

DROP PROCEDURE IF EXISTS `spSkupineUporabnikiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUporabnikiDelete`(IN a_id int)
BEGIN
 DELETE FROM skupineuporabniki WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUporabnikiInsert`
--

DROP PROCEDURE IF EXISTS `spSkupineUporabnikiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUporabnikiInsert`(
IN a_skupinaid int,
IN a_uporabnikid int,
IN a_pozicija int,
IN a_sms VARCHAR(45),
IN a_zvoni VARCHAR(45),
IN a_email VARCHAR(45),
IN a_report VARCHAR(45)
)
BEGIN
       INSERT INTO skupineuporabniki (skupinaid, uporabnikid, pozicija, sms, zvoni, email, report)
       VALUES (a_skupinaid, a_uporabnikid, a_pozicija,
        IF (a_sms <> '0', "true", "false"),
         IF (a_zvoni <> '0', "true", "false"),
         IF (a_email <> '0', "true", "false"),
         IF (a_report <> '0', "true", "false"));
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUporabnikiSelect`
--

DROP PROCEDURE IF EXISTS `spSkupineUporabnikiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUporabnikiSelect`()
BEGIN
     SELECT id, skupinaid, uporabnikid, pozicija, sms, zvoni, email, report FROM skupineuporabniki;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUporabnikiSelectBy`
--

DROP PROCEDURE IF EXISTS `spSkupineUporabnikiSelectBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUporabnikiSelectBy`(IN a_skupinaid int)
BEGIN
 SELECT skupineuporabniki.id, skupineuporabniki.skupinaid, skupineuporabniki.uporabnikid,
        uporabniki.ime, skupineuporabniki.pozicija, skupineuporabniki.sms, skupineuporabniki.zvoni ,
        skupineuporabniki.email, skupineuporabniki.report from skupineuporabniki
 LEFT JOIN uporabniki on uporabniki.id = uporabnikid
 where skupinaid = a_skupinaid order by skupineuporabniki.pozicija;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUporabnikiUpdate`
--

DROP PROCEDURE IF EXISTS `spSkupineUporabnikiUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUporabnikiUpdate`(
IN a_id int,
IN a_skupinaid int,
IN a_uporabnikid int,
IN a_pozicija int,
IN a_sms VARCHAR(45),
IN a_zvoni VARCHAR(45),
IN a_email VARCHAR(45),
IN a_report VARCHAR(45)
)
BEGIN
     UPDATE skupineuporabniki SET
        skupinaid = a_skupinaid, uporabnikid = a_uporabnikid, pozicija = a_pozicija,
        sms =  IF (a_sms <> '0', "true", "false"),
        zvoni = IF (a_zvoni <> '0', "true", "false"),
        email = IF (a_email <> '0', "true", "false"),
        report = IF (a_report <> '0', "true", "false")
     WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUrnikiDelete`
--

DROP PROCEDURE IF EXISTS `spSkupineUrnikiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUrnikiDelete`(IN a_id int)
BEGIN
   DELETE FROM skupineurniki WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUrnikiInsert`
--

DROP PROCEDURE IF EXISTS `spSkupineUrnikiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUrnikiInsert`(IN a_skupinaid int, IN a_uporabnikid int, IN a_urnikid int)
BEGIN
       INSERT INTO skupineurniki (skupinaid, uporabnikid, urnikid) VALUES (a_skupinaid ,a_uporabnikid ,a_urnikid);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUrnikiSelect`
--

DROP PROCEDURE IF EXISTS `spSkupineUrnikiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUrnikiSelect`()
BEGIN
    SELECT skupineurniki.id, skupineurniki.skupinaid, skupineurniki.uporabnikid,
         skupineurniki.urnikid ,urniki.ime FROM skupineurniki
    LEFT JOIN urniki on urniki.id = urnikid;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUrnikiSelectBy`
--

DROP PROCEDURE IF EXISTS `spSkupineUrnikiSelectBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUrnikiSelectBy`(IN a_skupinaid int, IN a_uporabnikid int)
BEGIN
 SELECT skupineurniki.id, skupineurniki.skupinaid, skupineurniki.uporabnikid,
         skupineurniki.urnikid, urniki.ime FROM skupineurniki
 LEFT JOIN urniki on urniki.id = urnikid
 where (skupinaid = a_skupinaid and uporabnikid = a_uporabnikid);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSkupineUrnikiUpdate`
--

DROP PROCEDURE IF EXISTS `spSkupineUrnikiUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSkupineUrnikiUpdate`(IN a_id int, IN a_skupinaid int, IN a_uporabnikid int, IN a_urnikid int)
BEGIN
     UPDATE skupineurniki SET  skupinaid = a_skupinaid ,uporabnikid = a_uporabnikid ,urnikid = a_urnikid
     WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSmsPosljiDelete`
--

DROP PROCEDURE IF EXISTS `spSmsPosljiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSmsPosljiDelete`(
 IN a_Datum DATETIME,
 IN a_Prejemnik VARCHAR(20),
 IN a_Naslovnik VARCHAR(250),
 IN a_Glava VARCHAR(250),
 IN a_Tekst VARCHAR(160)
)
BEGIN
        delete from smsposlji where Datum = a_Datum AND Prejemnik = a_Prejemnik AND Naslovnik = a_Naslovnik AND Glava = a_Glava AND Tekst = a_Tekst;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSmsPosljiInsert`
--

DROP PROCEDURE IF EXISTS `spSmsPosljiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSmsPosljiInsert`(
 IN a_Datum DATETIME,
 IN a_Prejemnik VARCHAR(20),
 IN a_Naslovnik VARCHAR(250),
 IN a_CasPotrditev INTEGER,
 IN a_CasDostava  INTEGER,
 IN a_SteviloPonovitevSMSa INTEGER,
 IN a_CasMedPonovitvamiSMSa INTEGER,
 IN a_Glava VARCHAR(250),
 IN a_Tekst VARCHAR(160),
 IN a_Zvonenje TINYINT
)
BEGIN
    insert into smsposlji(Datum, Prejemnik, Naslovnik, CasPotrditev, CasDostava, SteviloPonovitevSMSa, CasMedPonovitvamiSMSa, Glava, Tekst, Zvonenje)
    values (a_Datum, a_Prejemnik, a_Naslovnik, a_CasPotrditev, a_CasDostava, a_SteviloPonovitevSMSa, a_CasMedPonovitvamiSMSa, a_Glava, a_Tekst, a_Zvonenje);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spSmsPosljiSelect`
--

DROP PROCEDURE IF EXISTS `spSmsPosljiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spSmsPosljiSelect`()
BEGIN
         select * from smsposlji;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUporabnikiDelete`
--

DROP PROCEDURE IF EXISTS `spUporabnikiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUporabnikiDelete`(
      IN a_id int
)
BEGIN

    DELETE FROM skupineuporabniki WHERE uporabnikId = a_id;
    DELETE FROM skupineurniki WHERE uporabnikId = a_id;
    DELETE FROM reportiuporabniki WHERE uporabnikId = a_id;
    DELETE FROM skupinepravice WHERE uporabnikId = a_id;
    DELETE FROM uporabniki WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUporabnikiInsert`
--

DROP PROCEDURE IF EXISTS `spUporabnikiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUporabnikiInsert`(
      IN a_ime VARCHAR(45),
      IN a_firma VARCHAR(45),
      IN a_gsm VARCHAR(45),
      IN a_email VARCHAR(45),
      IN a_canLogin BOOLEAN,
      IN a_zgoR  BOOLEAN,
      IN a_zgoW  BOOLEAN,
      IN a_nasR  BOOLEAN,
      IN a_nasW  BOOLEAN,
      IN a_upoR  BOOLEAN,
      IN a_upoW  BOOLEAN,
      IN a_urnR  BOOLEAN,
      IN a_urnW  BOOLEAN,
      IN a_porR  BOOLEAN,
      IN a_porW  BOOLEAN,
      IN a_infR  BOOLEAN,
      IN a_infW  BOOLEAN,
      IN a_skuR  BOOLEAN,
      IN a_skuW  BOOLEAN,
      IN a_alaR  BOOLEAN,
      IN a_alaW  BOOLEAN,
      IN a_user  VARCHAR(45),
      IN a_pass  VARCHAR(45),
      IN a_jezik VARCHAR(45)
)
BEGIN
    INSERT INTO uporabniki (ime, firma, gsm, email, canLogin, zgoR, zgoW, nasR, nasW, upoR, upoW, urnR, urnW, porR, porW, infR, infW, skuR, skuW, user, pass, alaW, alaR, jezik)
    VALUES(a_ime, a_firma, a_gsm, a_email, a_canLogin, a_zgoR, a_zgoW, a_nasR, a_nasW, a_upoR, a_upoW, a_urnR, a_urnW, a_porR, a_porW, a_infR, a_infW, a_skuR, a_skuW, a_user, a_pass, a_alaW, a_alaR, a_jezik);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUporabnikiSelect`
--

DROP PROCEDURE IF EXISTS `spUporabnikiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUporabnikiSelect`()
BEGIN
          SELECT * FROM uporabniki;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUporabnikiUpdate`
--

DROP PROCEDURE IF EXISTS `spUporabnikiUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUporabnikiUpdate`(
      IN a_id int,
      IN a_ime VARCHAR(45),
      IN a_firma VARCHAR(45),
      IN a_gsm VARCHAR(45),
      IN a_email VARCHAR(45),
      IN a_canLogin BOOLEAN,
      IN a_zgoR  BOOLEAN,
      IN a_zgoW  BOOLEAN,
      IN a_nasR  BOOLEAN,
      IN a_nasW  BOOLEAN,
      IN a_upoR  BOOLEAN,
      IN a_upoW  BOOLEAN,
      IN a_urnR  BOOLEAN,
      IN a_urnW  BOOLEAN,
      IN a_porR  BOOLEAN,
      IN a_porW  BOOLEAN,
      IN a_infR  BOOLEAN,
      IN a_infW  BOOLEAN,
      IN a_skuR  BOOLEAN,
      IN a_skuW  BOOLEAN,
      IN a_alaR  BOOLEAN,
      IN a_alaW  BOOLEAN,
      IN a_user  VARCHAR(45),
      IN a_pass  VARCHAR(45),
      IN a_jezik VARCHAR(45)
)
BEGIN
     UPDATE uporabniki SET ime = a_ime, firma = a_firma, gsm = a_gsm, email = a_email,
     canLogin = a_canLogin, zgoR = a_zgoR, zgoW = a_zgoW, upoR = a_upoR, upoW = a_upoW,
     urnR = a_urnR, urnW = a_urnW, porR = a_porR, porW = a_porW,
     infR = a_infR, infW = a_infW, skuR = a_skuR, skuW = a_skuW,
     user = a_user, pass = a_pass, alaR = a_alaR, alaW = a_alaW,
     nasR = a_nasR, nasW = a_nasW, jezik = a_jezik WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUrnikiDelete`
--

DROP PROCEDURE IF EXISTS `spUrnikiDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUrnikiDelete`(IN a_id int)
BEGIN

       DELETE FROM skupineurniki WHERE urnikId = a_id;
DELETE FROM urniki WHERE id=a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUrnikiInsert`
--

DROP PROCEDURE IF EXISTS `spUrnikiInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUrnikiInsert`(
IN a_ime VARCHAR(45),
IN a_ponod datetime,
IN a_pondo datetime,
IN a_torod datetime,
IN a_tordo datetime,
IN a_sreod datetime,
IN a_sredo datetime,
IN a_cetod datetime,
IN a_cetdo datetime,
IN a_petod datetime,
IN a_petdo datetime,
IN a_sobod datetime,
IN a_sobdo datetime,
IN a_nedod datetime,
IN a_neddo datetime
)
BEGIN
    INSERT INTO urniki ( ime, ponod, pondo, torod, tordo, sreod, sredo, cetod, cetdo, petod, petdo, sobod, sobdo, nedod, neddo)
     VALUES( a_ime, a_ponod, a_pondo, a_torod, a_tordo, a_sreod, a_sredo, a_cetod, a_cetdo, a_petod, a_petdo, a_sobod, a_sobdo, a_nedod, a_neddo );
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUrnikiSelect`
--

DROP PROCEDURE IF EXISTS `spUrnikiSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUrnikiSelect`()
BEGIN
     SELECT id, ime, ponod, pondo, torod, tordo, sreod, sredo, cetod, cetdo, petod, petdo, sobod, sobdo, nedod, neddo from urniki;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUrnikiUpdate`
--

DROP PROCEDURE IF EXISTS `spUrnikiUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUrnikiUpdate`(
IN a_id int,
IN a_ime VARCHAR(45),
IN a_ponod datetime,
IN a_pondo datetime,
IN a_torod datetime,
IN a_tordo datetime,
IN a_sreod datetime,
IN a_sredo datetime,
IN a_cetod datetime,
IN a_cetdo datetime,
IN a_petod datetime,
IN a_petdo datetime,
IN a_sobod datetime,
IN a_sobdo datetime,
IN a_nedod datetime,
IN a_neddo datetime
)
BEGIN
     UPDATE urniki SET
            ime = a_ime,
            ponod = a_ponod,
            pondo = a_pondo,
            torod = a_torod,
            tordo = a_tordo,
            sreod = a_sreod,
            sredo = a_sredo,
            cetod = a_cetod,
            cetdo = a_cetdo,
            petod = a_petod,
            petdo = a_petdo,
            sobod = a_sobod,
            sobdo = a_sobdo,
            nedod = a_nedod,
            neddo = a_neddo
            WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUsersDelete`
--

DROP PROCEDURE IF EXISTS `spUsersDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUsersDelete`(
 IN a_id int
)
BEGIN
     delete from users where id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUsersGet`
--

DROP PROCEDURE IF EXISTS `spUsersGet`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUsersGet`()
BEGIN
      select * from users;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUsersInsert`
--

DROP PROCEDURE IF EXISTS `spUsersInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUsersInsert`(
 IN a_name varchar(45),
 IN a_pass varchar(45),
 IN a_admin boolean
)
BEGIN
     insert into users ( name, pass, admin) values (a_name, a_pass, a_admin);
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spUsersUpdate`
--

DROP PROCEDURE IF EXISTS `spUsersUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUsersUpdate`(
 IN a_id int,
 IN a_name varchar(45),
 IN a_pass varchar(45),
 IN a_admin boolean
)
BEGIN
     update users set  name = a_name, pass = a_pass, admin = a_admin where id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spZgodovinaBackup`
--

DROP PROCEDURE IF EXISTS `spZgodovinaBackup`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spZgodovinaBackup`(
  IN a_DatumDogodka datetime,
  IN a_filename  text
)
BEGIN

  set @myvar = concat('CREATE TABLE ',a_filename,' SELECT * FROM zgodovina WHERE DatumDogodka<','"',a_DatumDogodka,'"') ;
  PREPARE stmt1 FROM @myvar;
  EXECUTE stmt1;
  Deallocate prepare stmt1;

END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spZgodovinaDelete`
--

DROP PROCEDURE IF EXISTS `spZgodovinaDelete`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spZgodovinaDelete`(IN a_id int)
BEGIN
  DELETE from zgodovina WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spZgodovinaDeleteBy`
--

DROP PROCEDURE IF EXISTS `spZgodovinaDeleteBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spZgodovinaDeleteBy`(
  IN a_DatumDogodka datetime
)
BEGIN
  DELETE FROM zgodovina WHERE DatumDogodka<a_DatumDogodka;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spZgodovinaInsert`
--

DROP PROCEDURE IF EXISTS `spZgodovinaInsert`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spZgodovinaInsert`(
IN a_DatumDogodka datetime,
IN a_OpisDogodka text,
IN a_Data text,
IN a_skupinaId int,
IN a_alarmId int,
IN a_skupinaIme text,
IN a_alarmIme text,
IN a_dogodekId int,
IN a_zgodovinaLevel int
)
BEGIN
   INSERT into zgodovina (DatumDogodka, OpisDogodka, Data, skupinaId, alarmId, skupinaIme, alarmIme, dogodekId, zgodovinaLevel)
          values (a_DatumDogodka, a_OpisDogodka, a_Data, a_skupinaId, a_alarmId, a_skupinaIme, a_alarmIme, a_dogodekId, a_zgodovinaLevel);
   
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spZgodovinaSelect`
--

DROP PROCEDURE IF EXISTS `spZgodovinaSelect`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spZgodovinaSelect`(
  IN a_DatumDogodkaOd datetime,
  IN a_DatumDogodkaDo datetime
)
BEGIN
     SELECT  * from zgodovina WHERE zgodovinaLevel = 50 and
                  (DatumDogodka >= a_DatumDogodkaOd OR a_DatumDogodkaOd = null) and
                  (DatumDogodka <= a_DatumDogodkaDo OR a_DatumDogodkaDo = null)
     ORDER BY zgodovina.id DESC;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spZgodovinaSelectBy`
--

DROP PROCEDURE IF EXISTS `spZgodovinaSelectBy`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spZgodovinaSelectBy`(
IN a_Od datetime,
IN a_Do datetime,
IN a_OpisDogodka text,
IN a_Data text,
IN a_skupinaId int,
IN a_alarmId int,
IN a_skupinaIme text,
IN a_alarmIme text,
IN a_dogodekId int,
IN a_zgodovinaLevel int
)
BEGIN
  SELECT * FROM zgodovina WHERE
    (DatumDogodka > a_Od AND DatumDogodka < a_Do) AND
    (OpisDogodka = a_OpisDogodka OR a_OpisDogodka = 'none') AND
    (Data = a_Data OR a_Data = 'none') AND
    (skupinaId = a_skupinaId OR a_skupinaId = 0) AND
    (alarmId = a_alarmId or a_alarmId = 0) AND
    (skupinaIme = a_skupinaIme or a_skupinaIme = 'none') AND
    (alarmIme = a_alarmIme or a_alarmIme = 'none') AND
    (dogodekId = a_dogodekId or a_dogodekId = 0) AND
    (zgodovinaLevel = a_zgodovinaLevel or a_zgodovinaLevel = 0)
    ORDER BY zgodovina.id DESC;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;



--
-- Definition of procedure `spZgodovinaUpdate`
--

DROP PROCEDURE IF EXISTS `spZgodovinaUpdate`;



/*!50003 SET @TEMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
CREATE DEFINER=`root`@`localhost` PROCEDURE `spZgodovinaUpdate`(
IN a_id int,
IN a_DatumDogodka datetime,
IN a_OpisDogodka text,
IN a_Data text,
IN a_skupinaId int,
IN a_alarmId int,
IN a_skupinaIme text,
IN a_alarmIme text,
IN a_dogodekId int,
IN a_zgodovinaLevel int
)
BEGIN
    UPDATE zgodovina SET  DatumDogodka = a_DatumDogodka, OpisDogodka = a_OpisDogodka,
                          Data = a_Data, skupinaId = a_skupinaId, alarmId = a_alarmId,
                          skupinaIme = a_skupinaIme, alarmIme = a_alarmIme,
                          dogodekId = a_dogodekId, zgodovinaLevel = a_zgodovinaLevel
           WHERE id = a_id;
END ;
/*!50003 SET SESSION SQL_MODE=@TEMP_SQL_MODE */  ;





/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;


