<?php
 class Tariff2DB extends ADO { public function __construct( $app, $dburi, $debug=false, $tmode=true, $dformat='') { $this->owner = $app; if ( !empty($dburi)) $this->dburi = $dburi; return parent::__construct( $this->dburi, $debug, $tmode, $dformat); } public function get_ssid_list() { if (empty($GLOBALS['PROVIDER'])) $GLOBALS['PROVIDER'] = 1; return $this->GetAll("SELECT sk_service_set.service_set_id, sk_service.title||' / '||sk_currency.sign as title FROM sk_service_set, sk_currency, sk_service WHERE sk_service.service_id=sk_service_set.service_id AND sk_currency.currency_id=sk_service_set.currency_id AND sk_service_set.service_id=1 AND sk_service_set.provider_id=".$GLOBALS['PROVIDER']); } public function get_records($lines_per_page, $page=0) { $res = $this->GetAll("SELECT count(*) FROM sk_packets"); $ext = ''; if ( $page >= 0) { $low = $page*$lines_per_page; $high = $lines_per_page; $ext = " OFFSET ".$low." LIMIT ".$high; } $allRecs = $this->GetAll("SELECT gid, packet, tos, fixed, deposit, credit, activation_time, blocked, direction, fixed_cost, users_col, cos FROM sk_packets".$ext); return array($res[0][0], $allRecs); } public function get_records_for_provider($lines_per_page, $page=0) { $res = $this->GetAll("SELECT count(*) FROM sk_packets, sk_service_set WHERE sk_packets.service_set_id=sk_service_set.service_set_id AND sk_service_set.provider_id='".$GLOBALS['PROVIDER']."'"); $ext = ''; if ( $page >= 0) { $low = $page*$lines_per_page; $high = $lines_per_page; $ext = " OFFSET ".$low." LIMIT ".$high; } $allRecs = $this->GetAll("SELECT sk_packets.gid, sk_packets.packet, sk_packets.tos, sk_packets.fixed, sk_packets.deposit, sk_packets.credit, sk_packets.activation_time, sk_packets.blocked, sk_packets.direction, sk_packets.fixed_cost, sk_packets.users_col, sk_packets.cos FROM sk_packets, sk_service_set WHERE sk_packets.service_set_id=sk_service_set.service_set_id AND sk_service_set.provider_id='".$GLOBALS['PROVIDER']."'".$ext); return array($res[0][0], $allRecs); } public function get_records_for_provider_spec($lines_per_page, $page=0, $id=0) { $res = $this->GetAll("SELECT count(*) FROM sk_packets, sk_service_set WHERE sk_packets.service_set_id=sk_service_set.service_set_id AND sk_service_set.provider_id='".$GLOBALS['PROVIDER']."'"); $ext = ''; if ( $page >= 0) { $low = $page*$lines_per_page; $high = $lines_per_page; $ext = " OFFSET ".$low." LIMIT ".$high; } $allRecs = $this->GetAll("SELECT sk_packets.gid, sk_packets.packet, sk_packets.tos, sk_packets.fixed, sk_packets.deposit, sk_packets.credit, sk_packets.activation_time, sk_packets.blocked, sk_packets.direction, sk_packets.fixed_cost, sk_packets.users_col, sk_packets.cos FROM sk_packets, sk_service_set WHERE sk_packets.service_set_id=sk_service_set.service_set_id AND sk_service_set.provider_id='".$GLOBALS['PROVIDER']."'".$ext); return array($res[0][0], $allRecs); } public function get_records_for_operator($lines_per_page, $page=0) { $res = $this->GetAll("SELECT count(*)FROM sk_packets, sk_group_tracker  WHERE sk_packets.gid=sk_group_tracker.gid AND sk_group_tracker.obj_id='".$GLOBALS['SSXID']."'"); $ext = ''; if ( $page >= 0) { $low = $page*$lines_per_page; $high = $lines_per_page; $ext = " OFFSET ".$low." LIMIT ".$high; } $allRecs = $this->GetAll("SELECT sk_packets.gid, sk_packets.packet, sk_packets.tos, sk_packets.fixed, sk_packets.deposit, sk_packets.credit, sk_packets.activation_time, sk_packets.blocked, sk_packets.direction, sk_packets.fixed_cost, sk_packets.users_col, sk_packets.cos FROM sk_packets, sk_group_tracker  WHERE sk_packets.gid=sk_group_tracker.gid AND sk_group_tracker.obj_id='".$GLOBALS['SSXID']."'".$ext); return array($res[0][0], $allRecs); } public function insert_from_globals() { $date = $this->owner->now(); if (empty($GLOBALS['service_set_id'])) $GLOBALS['service_set_id'] = 1; $query = "INSERT INTO sk_packets (service_set_id, packet, deposit, credit,
		tos, do_with_tos, direction, fixed, fixed_cost, activated, 
		activation_time, blocked, total_time_limit, month_time_limit, 
		week_time_limit, day_time_limit, total_traffic_limit, 
		month_traffic_limit, week_traffic_limit, day_traffic_limit, 
		total_money_limit, month_money_limit, week_money_limit, 
		day_money_limit, login_time, simultaneous_use, port_limit, session_timeout, idle_timeout, 
		allowed_servers, framed_ip, framed_mask, no_pass, no_acct, 
		allow_callback, other_params, up, down, framed_route, cos)
		VALUES ('".$GLOBALS['service_set_id']."', '".$GLOBALS['tariff_name']."', '".$GLOBALS['deposit']."', '". $GLOBALS['credit']."', '".$GLOBALS['tos']."', '".$GLOBALS['do_with_tos']."', '". $GLOBALS['direction']."', '".$GLOBALS['fixed']."', '".$GLOBALS['fixed_cost']."', '". (isset($GLOBALS['activated']) ? 1 : 0)."', '".(86400*$GLOBALS['activation_time'])."', '". (isset($GLOBALS['blocked']) ? 1 : 0)."', '".(60*$GLOBALS['total_time_limit'])."', '". (60*$GLOBALS['month_time_limit'])."', '".(60*$GLOBALS['week_time_limit'])."', '". (60*$GLOBALS['day_time_limit'])."', '".(1048576*$GLOBALS['total_traffic_limit'])."', '". (1048576*$GLOBALS['month_traffic_limit'])."', '".(1048576*$GLOBALS['week_traffic_limit'])."', '". (1048576*$GLOBALS['day_traffic_limit'])."', '".$GLOBALS['total_money_limit']."', '". $GLOBALS['month_money_limit']."', '".$GLOBALS['week_money_limit']."', '". $GLOBALS['day_money_limit']."', '".$GLOBALS['login_time']."', '". $GLOBALS['simultaneous_use']."', '". $GLOBALS['port_limit']."', '".(60*$GLOBALS['session_timeout'])."', '". (60*$GLOBALS['idle_timeout'])."', '".$GLOBALS['allowed_servers']."', '". $GLOBALS['framed_ip']."', '".$GLOBALS['framed_mask']."', '". (isset($GLOBALS['no_pass']) ? 1 : 0)."', '".(isset($GLOBALS['no_acct']) ? 1 : 0)."', '".(isset($GLOBALS['allow_callback']) ? 1 : 0)."', '". $GLOBALS['other_params']."', '".$GLOBALS['up']."', '".$GLOBALS['down']."', '".$GLOBALS['framed_route']."', '".(isset($GLOBALS['cos']) ? $GLOBALS['cos'] : 0)."')"; $this->BeginTrans(); if ( $this->Execute($query)) { $this->CommitTrans(); $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf(STR_GRP_ADDED, $GLOBALS['tariff_name'], $date)); return true; } else { $this->RollbackTrans(); $this->owner->log(CMMN_ERROR, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_GRP_ADDED_ERR, $GLOBALS['tariff_name'])); } return false; } public function delete_from_globals() { if ( isset($GLOBALS['id'])) { $this->BeginTrans(); $res = $this->Execute("DELETE FROM sk_packets WHERE sk_packets.gid='".$GLOBALS['id']."'"); if ( $res) { $this->CommitTrans(); $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_GRP_DELETED, $GLOBALS['id'])); return true; } else { $this->RollbackTrans(); $this->owner->log(CMMN_ERROR, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_GRP_DELETED_ERR, $GLOBALS['id'])); } } return false; } public function modify_from_globals() { $date = $this->owner->now(); $query = "UPDATE sk_packets SET 
		packet='".$GLOBALS['tariff_name']."', deposit='".$GLOBALS['deposit']. "', credit='".$GLOBALS['credit']."', tos='".$GLOBALS['tos']. "', do_with_tos='".$GLOBALS['do_with_tos']."', direction='". $GLOBALS['direction']."', fixed='".$GLOBALS['fixed']."', fixed_cost='". $GLOBALS['fixed_cost']."', activated='".(isset($GLOBALS['activated']) ? 1 : 0)."', activation_time='". ($GLOBALS['activation_time']*86400)."', blocked='".(isset($GLOBALS['blocked']) ? 1 : 0). "', total_time_limit='".($GLOBALS['total_time_limit']*60)."', month_time_limit='". ($GLOBALS['month_time_limit']*60)."', week_time_limit='".($GLOBALS['week_time_limit']*60). "', day_time_limit='".($GLOBALS['day_time_limit']*60)."', total_traffic_limit='". ($GLOBALS['total_traffic_limit']*1048576)."', month_traffic_limit='". ($GLOBALS['month_traffic_limit']*1048576)."', week_traffic_limit='". ($GLOBALS['week_traffic_limit']*1048576)."', day_traffic_limit='". ($GLOBALS['day_traffic_limit']*1048576)."', total_money_limit='". $GLOBALS['total_money_limit']."', month_money_limit='".$GLOBALS['month_money_limit']. "', week_money_limit='".$GLOBALS['week_money_limit']."', day_money_limit='". $GLOBALS['day_money_limit']."', login_time='".$GLOBALS['login_time']."', simultaneous_use='".$GLOBALS['simultaneous_use']."', port_limit='". $GLOBALS['port_limit']."', session_timeout='".($GLOBALS['session_timeout']*60). "', idle_timeout='".($GLOBALS['idle_timeout']*60)."', framed_ip='".$GLOBALS['framed_ip']. "', framed_mask='".$GLOBALS['framed_mask']."', no_pass='".(isset($GLOBALS['no_pass']) ? 1 : 0)."', no_acct='".(isset($GLOBALS['no_acct']) ? 1 : 0). "', allow_callback='".(isset($GLOBALS['allow_callback'])? 1 : 0)."', other_params='".$GLOBALS['other_params']."', up='".$GLOBALS['up']."', down='".$GLOBALS['down']."', framed_route='".$GLOBALS['framed_route']."', cos='".(isset($GLOBALS['cos']) ? $GLOBALS['cos'] : 0)."' WHERE gid='".$GLOBALS['id']."'"; $this->BeginTrans(); if ( $this->Execute($query)) { $this->CommitTrans(); $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf(STR_GRP_EDITED, $GLOBALS['tariff_name'], $date)); return true; } else { $this->RollbackTrans(); $this->owner->log(CMMN_ERROR, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_GRP_EDITED_ERR, $GLOBALS['tariff_name'])); } return false; } public function get_record( $obj) { if ( ($a = $this->GetAll(sprintf("SELECT * FROM sk_packets WHERE gid='%s'", $obj)))) return $a[0]; else return array(); } public function add_to_group_tracker() { if ( isset($GLOBALS['id']) && isset($GLOBALS['gid'])) { $this->BeginTrans(); if ( $this->Execute("INSERT INTO sk_group_tracker (obj_id, gid) VALUES('".$GLOBALS['id']."', '".$GLOBALS['gid']."')")) { $this->CommitTrans(); $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_GRP_EDITED, $GLOBALS['gid'])); return true; } else { $this->RollbackTrans(); $this->owner->log(CMMN_ERROR, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_GRP_EDITED_ERR, $GLOBALS['gid'])); } } return false; } public function del_from_group_tracker() { if ( isset($GLOBALS['id']) && isset($GLOBALS['gid'])) { $this->BeginTrans(); if ( $this->Execute("DELETE FROM sk_group_tracker WHERE gid='".$GLOBALS['gid']."' AND obj_id='".$GLOBALS['id']."'")) { $this->CommitTrans(); $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_GRP_EDITED, $GLOBALS['gid'])); return true; } else { $this->RollbackTrans(); $this->owner->log(CMMN_ERROR, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_GRP_EDITED_ERR, $GLOBALS['gid'])); } } return false; } } ?>
