<?php
$o['table'] = configs::get('db', 'table_prefix').'tickets';
$o['struct']= Array('key' => 'key',
'realm' => 'realm',
'host' => 'host',
'uid' => 'uid',
'status' => 'status',
'create' => 'creat_date',
'chaldate' => 'chal_date',
'update' => 'last_date',
'chaldata' => 'chaldata'
//intkeys //tablefield
);
$o['mysql'] = Array('isticket' => Array ('ispresent', "SELECT COUNT(*) FROM `%table%` WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'ischallenged' => Array ('ispresent', "SELECT COUNT(*) FROM `%table%` WHERE `%struct_chaldate%`<>'0' AND `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'isactif' => Array ('ispresent', "SELECT COUNT(*) FROM `%table%` WHERE `%struct_chaldate%`<>'0' AND `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_status%`='1' AND `%struct_host%`='%arg_host%'"),
'isgranted' => Array ('ispresent', "SELECT COUNT(*) FROM `%table%` WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_uid%`<>'' AND `%struct_host%`='%arg_host%'"),
'create_time' => Array ('getonefield',"SELECT `%struct_create%` FROM `%table%` WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'grant_time' => Array ('getonefield',"SELECT `%struct_chaldate%` FROM `%table%` WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'mark_challenged' => Array ('update', "UPDATE `%table%` SET `%struct_status%`='0', `%struct_chaldate%`='%arg_time%' WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'mark_active' => Array ('update', "UPDATE `%table%` SET `%struct_status%`='1', `%struct_key%`='%arg_new%', `%struct_uid%`='%arg_uid%', `%struct_update%`='%arg_time%' WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%' AND `%struct_chaldate%`<>'0'"),
'mark_passive' => Array ('update', "UPDATE `%table%` SET `%struct_status%`=NULL, `%struct_key%`='%arg_new%', `%struct_update%`='%arg_time%' WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'ticket_update' => Array ('update', "UPDATE `%table%` SET `%struct_update%`='%arg_time%' WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'get_grantimeout' => Array ('fetchfield', "SELECT `%struct_key%` FROM `%table%` WHERE `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%' AND `%struct_chaldate%`<>'0' AND `%struct_status%`<>'0' AND `%struct_update%`<'%arg_timeout%'"),
'get_grantexpire' => Array ('fetchfield', "SELECT `%struct_key%` FROM `%table%` WHERE `%struct_realm%`='%arg_realm%' AND `%struct_chaldate%`<>'0' AND `%struct_status%`<>'0' AND `%struct_create%`<'%arg_lifetime%'"),
'get_failedexpire' => Array ('fetchfield', "SELECT `%struct_key%` FROM `%table%` WHERE `%struct_realm%`='%arg_realm%' AND `%struct_chaldate%`<>'0' AND `%struct_status%`='0' AND `%struct_create%`<'%arg_lifetime%'"),
'get_unchaltimeout' => Array ('fetchfield', "SELECT `%struct_key%` FROM `%table%` WHERE `%struct_realm%`='%arg_realm%' AND `%struct_chaldate%`='0' AND `%struct_create%`<'%arg_chalto%'"),
'drop_ticket' => Array ('delete', "DELETE FROM `%table%` WHERE `%struct_realm%`='%arg_realm%' AND `%struct_key%`='%arg_ticket%' LIMIT 1"),
'create_ticket' => Array ('insert', "INSERT INTO `%table%` ( `%struct_key%`, `%struct_realm%`, `%struct_status%`, `%struct_chaldata%`, `%struct_host%`, `%struct_create%` ) VALUES ('%arg_ticket%', '%arg_realm%', '0', '%arg_chaldata%', '%arg_host%', '%arg_time%')"),
'ticket_chaldata' => Array ('getonefield',"SELECT `%struct_chaldata%` FROM `%table%` WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_status%`='0' AND `%struct_host%`='%arg_host%'"),
'ticket_uid' => Array ('getonefield',"SELECT `%struct_uid%` FROM `%table%` WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'count_granted' => Array('getcount', "SELECT COUNT(*) FROM `%table%` WHERE `%struct_chaldate%`<>'0' AND `%struct_status%`<>'0' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'count_challenged' => Array('getcount', "SELECT COUNT(*) FROM `%table%` WHERE `%struct_chaldate%`<>'0' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'count_ticket' => Array('getcount', "SELECT COUNT(*) FROM `%table%` WHERE `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%'"),
'count_account' => Array('getcount', "SELECT COUNT(*) FROM `%table%` WHERE `%struct_realm%`='%arg_realm%' AND `%struct_uid%`='%arg_uid%'")
);
$o['sqlite'] = Array('isticket' => Array ('ispresent', "SELECT COUNT(*) FROM %table% WHERE \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'ischallenged' => Array ('ispresent', "SELECT COUNT(*) FROM %table% WHERE \"%struct_chaldate%\"<>'0' AND \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'isactif' => Array ('ispresent', "SELECT COUNT(*) FROM %table% WHERE \"%struct_chaldate%\"<>'0' AND \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_status%\"='1' AND \"%struct_host%\"='%arg_host%'"),
'isgranted' => Array ('ispresent', "SELECT COUNT(*) FROM %table% WHERE \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_uid%\"<>'' AND \"%struct_host%\"='%arg_host%'"),
'create_time' => Array ('getonefield',"SELECT \"%struct_create%\" FROM %table% WHERE \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'grant_time' => Array ('getonefield',"SELECT \"%struct_chaldate%\" FROM %table% WHERE \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'mark_challenged' => Array ('update', "UPDATE %table% SET \"%struct_status%\"='0', \"%struct_chaldate%\"='%arg_time%' WHERE \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'mark_active' => Array ('update', "UPDATE %table% SET \"%struct_status%\"='1', `%struct_key%`='%arg_new%', `%struct_uid%`='%arg_uid%', `%struct_update%`='%arg_time%' WHERE `%struct_key%`='%arg_ticket%' AND `%struct_realm%`='%arg_realm%' AND `%struct_host%`='%arg_host%' AND `%struct_chaldate%`<>'0'"),
'mark_passive' => Array ('update', "UPDATE %table% SET \"%struct_status%\"=NULL, \"%struct_key%\"='%arg_new%', \"%struct_update%\"='%arg_time%' WHERE \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'get_grantimeout' => Array ('fetchfield', "SELECT \"%struct_key%\" FROM %table% WHERE \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%' AND \"%struct_chaldate%\"<>'0' AND \"%struct_status%\"<>'0' AND \"%struct_update%\"<'%arg_timeout%'"),
'get_grantexpire' => Array ('fetchfield', "SELECT \"%struct_key%\" FROM %table% WHERE \"%struct_realm%\"='%arg_realm%' AND \"%struct_chaldate%\"<>'0' AND \"%struct_status%\"<>'0' AND \"%struct_create%\"<'%arg_lifetime%'"),
'get_failedexpire' => Array ('fetchfield', "SELECT \"%struct_key%\" FROM %table% WHERE \"%struct_realm%\"='%arg_realm%' AND \"%struct_chaldate%\"<>'0' AND \"%struct_status%\"='0' AND \"%struct_create%\"<'%arg_lifetime%'"),
'get_unchaltimeout' => Array ('fetchfield', "SELECT \"%struct_key%\" FROM %table% WHERE \"%struct_realm%\"='%arg_realm%' AND \"%struct_chaldate%\"='0' AND \"%struct_create%\"<'%arg_chalto%'"),
'drop_ticket' => Array ('delete', "DELETE FROM %table% WHERE \"%struct_realm%\"='%arg_realm%' AND \"%struct_key%\"='%arg_ticket%' LIMIT 1"),
'create_ticket' => Array ('insert', "INSERT INTO %table% ( \"%struct_key%\", \"%struct_realm%\", \"%struct_status%\", \"%struct_chaldata%\", \"%struct_host%\", \"%struct_create%\" ) VALUES ('%arg_ticket%', '%arg_realm%', '0', '%arg_chaldata%', '%arg_host%', '%arg_time%')"),
'ticket_chaldata' => Array ('getonefield',"SELECT \"%struct_chaldata%\" FROM %table% WHERE \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_status%\"='0' AND \"%struct_host%\"='%arg_host%'"),
'ticket_uid' => Array ('getonefield',"SELECT \"%struct_uid%\" FROM %table% WHERE \"%struct_key%\"='%arg_ticket%' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'count_granted' => Array('getcount', "SELECT COUNT(*) FROM %table% WHERE \"%struct_chaldate%\"<>'0' AND \"%struct_status%\"<>'0' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'count_challenged' => Array('getcount', "SELECT COUNT(*) FROM %table% WHERE \"%struct_chaldate%\"<>'0' AND \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'count_ticket' => Array('getcount', "SELECT COUNT(*) FROM %table% WHERE \"%struct_realm%\"='%arg_realm%' AND \"%struct_host%\"='%arg_host%'"),
'count_account' => Array('getcount', "SELECT COUNT(*) FROM %table% WHERE \"%struct_realm%\"='%arg_realm%' AND \"%struct_uid%\"='%arg_uid%'")
);
$o['create']['mysql'] = "CREATE TABLE `%table%` (
`%struct_key%` varchar(32) NOT NULL,
`%struct_realm%` varchar(32) NOT NULL,
`%struct_host%` varchar(32) NOT NULL,
`%struct_uid%` varchar(255) NOT NULL,
`%struct_status%` tinyint(1) default NULL,
`%struct_create%` int(16) NOT NULL,
`%struct_chaldate%` int(16) default '0',
`%struct_update%` int(16) NOT NULL,
`%struct_chaldata%` text NOT NULL )
ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$o['create']['sqlite'] = "CREATE TABLE %table% (
\"%struct_key%\" TEXT,
\"%struct_realm%\" TEXT,
\"%struct_host%\" TEXT,
\"%struct_uid%\" TEXT,
\"%struct_status%\" NUMERIC,
\"%struct_create%\" NUMERIC,
\"%struct_chaldate%\" NUMERIC,
\"%struct_update%\" NUMERIC,
\"%struct_chaldata%\" TEXT )";
return $o;