<?php
 class Card2DB 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_records($lines_per_page, $page=0) { $res = $this->GetAll("SELECT count(*) FROM sk_card_series"); if ( $page >= 0) { $low = $page*$lines_per_page; $high = $lines_per_page; $allRecs = $this->GetAll("SELECT sk_card_series.sid, sk_card_series.url, sk_card_series.cost, sk_card_series.date_add, sk_card_series.cards_col, sk_card_series.gid, sk_card_series.descr, sk_card_series.card_type FROM sk_card_series ORDER by sk_card_series.sid OFFSET ".$low." LIMIT ".$high); } else $allRecs = $this->GetAll("SELECT sk_card_series.sid, sk_card_series.url, sk_card_series.cost, sk_card_series.date_add, sk_card_series.cards_col, sk_card_series.gid, sk_card_series.descr, sk_card_series.card_type FROM sk_card_series ORDER by sk_card_series.sid"); return array($res[0][0], $allRecs); } public function insert_from_globals() { if (isset($_FILES['file'])) { require_once(dirname(__FILE__)."/../../../class.upload.inc.php"); $u=new uploader('/opt/stasoft/www/app/suite/files/'); $url=$u->upload("file"); } if ( empty($url)) $url = '/share/img/card.png'; else $url = str_replace('/opt/stasoft/www', '', $url); $add_time = $this->owner->now(); $user_prefix = $GLOBALS['user_prefix']; $password_len = isset($this->owner->config['SECURITY']['password_len'])?$this->owner->config['SECURITY']['password_len']:8; $login_len = isset($this->owner->config['SECURITY']['login_len'])?$this->owner->config['SECURITY']['login_len']:4; $a = json_decode($this->owner->db->get_value('SECURITY', $GLOBALS['PROVIDER']), true); if ( is_array($a)) { if ( isset($a['password_len'])) $password_len = $a['password_len']; if ( isset($a['login_len'])) $login_len = $a['login_len']; } if ( empty($user_prefix)) $user_prefix = uniq_gen($login_len).'%s'; else $user_prefix .= '%s'; $start_user = $GLOBALS['start_user']; $num_users = $GLOBALS['num_users']; $users_deposit = $GLOBALS['users_deposit']; $gid = $GLOBALS['gid']; $descr = $GLOBALS['card_descr']; $query = "INSERT INTO sk_card_series (cost, descr, card_type, url, date_add, gid) VALUES( '".$users_deposit."', '".$descr."', 0, '".$url."', '".$add_time."', '".$gid."')"; $this->BeginTrans(); $res = $this->Execute($query); if ( $res) { $query = "SELECT MAX(sid) AS sid FROM sk_card_series"; $result = $this->GetAll($query); if ( $result) { $sid = $result[0][0]; $result = $this->GetAll(sprintf("SELECT * FROM sk_packets WHERE gid = %s", $gid)); if ( $result) { $result[0]['add_date'] = ($result[0]['activated'] == 1) ? $add_time : '1970-01-01'; $i = $start_user; $j = 0; while ( $j < $num_users) { $user = ''; $res = $this->GetAll("SELECT max(uid) FROM sk_users"); if ( !empty($result[0]['no_pass'])) { $user = uniq_gen($password_len); $passwd = ''; } elseif ( $res && $res[0][0] ) { $user = sprintf($user_prefix, $res[0][0]); $passwd = uniq_gen($password_len); } $i ++; $query_users = "INSERT INTO sk_users (username, password, gid, deposit, add_date, blocked, activated, sid,
						total_time_limit, total_money_limit, total_traffic_limit, month_time_limit, month_money_limit, month_traffic_limit,
						day_time_limit, day_money_limit, day_traffic_limit,
						framed_ip, framed_mask, other_params,
						no_pass, no_acct, allow_callback,
						login_time, huntgroup_name, port_limit,
						simultaneous_use, session_timeout, idle_timeout,
						tos, do_with_tos, direction,
						activation_time
) VALUES ('".$user."', '".$passwd."', $gid, $users_deposit, '".$this->owner->now()."', 0, 0, '".$sid."', '".$result[0]['total_time_limit']."', '".$result[0]['total_money_limit']."', '".$result[0]['total_traffic_limit']."'
, '".$result[0]['month_time_limit']."', '".$result[0]['month_money_limit']."', '".$result[0]['month_traffic_limit']."'
, '".$result[0]['day_time_limit']."', '".$result[0]['day_money_limit']."', '".$result[0]['day_traffic_limit']."'
, '".$result[0]['framed_ip']."', '".$result[0]['framed_mask']."', '".$result[0]['other_params']."'
, '".$result[0]['no_pass']."', '".$result[0]['no_acct']."', '".$result[0]['allow_callback']."'
, '".$result[0]['login_time']."', '".$result[0]['huntgroup_name']."', '".$result[0]['port_limit']."'
, '".$result[0]['simultaneous_use']."', '".$result[0]['session_timeout']."', '".$result[0]['idle_timeout']."'
, '".$result[0]['tos']."', '".$result[0]['do_with_tos']."', '".$result[0]['direction']."'
, '".$result[0]['activation_time']."' )"; $res = $this->Execute($query_users); if ( !$res) break; $j ++; } } else $res = false; } else $res = false; } if ( $res) { $this->CommitTrans(); $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf(STR_CRD_ADDED, $descr, $add_time)); return true; } else { $this->RollbackTrans(); $this->owner->log(CMMN_ERROR, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_CRD_ADDED_ERR, $descr)); } return false; } public function delete_from_globals() { if ( isset($GLOBALS['sid'])) { $this->BeginTrans(); if ( $this->Execute("DELETE FROM sk_card_series WHERE sid='".$GLOBALS['sid']."'")) { $this->CommitTrans(); $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_CRD_DELETED, $GLOBALS['sid'])); return true; } else { $this->RollbackTrans(); $this->owner->log(CMMN_ERROR, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_CRD_DELETED_ERR, $GLOBALS['sid'])); } } return false; } public function unlock_from_globals() { if ( isset($GLOBALS['sid'])) { $this->BeginTrans(); $res = $this->Execute("UPDATE sk_card_series SET card_type='0' WHERE sid='".$GLOBALS['sid']."'"); if ( $res) $res = $this->Execute("UPDATE sk_users SET blocked='0' WHERE sid='".$GLOBALS['sid']."'"); if ( $res) { $this->CommitTrans(); $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_CRD_EDITED, $GLOBALS['sid'])); return true; } else { $this->RollbackTrans(); $this->owner->log(CMMN_ERROR, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_CRD_EDITED_ERR, $GLOBALS['sid'])); } } return false; } public function lock_from_globals() { if ( isset($GLOBALS['sid'])) { $this->BeginTrans(); $res = $this->Execute("UPDATE sk_card_series SET card_type='1' WHERE sid='".$GLOBALS['sid']."'"); if ( $res) $res = $this->Execute("UPDATE sk_users SET blocked='1' WHERE sid='".$GLOBALS['sid']."'"); if ( $res) { $this->CommitTrans(); $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_CRD_EDITED, $GLOBALS['sid'])); return true; } else { $this->RollbackTrans(); $this->owner->log(CMMN_ERROR, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_CRD_EDITED_ERR, $GLOBALS['sid'])); } } return false; } public function modify_from_globals() { if ( isset($GLOBALS['sid'])) { $res = $this->GetAll("SELECT uid, deposit, activation_time, gid, username, password, account_id FROM sk_users WHERE activated=0 AND blocked=0 AND sid='".$GLOBALS['sid']."' ORDER BY uid"); if ( $res && count($res)>0) { $add_time = $res[0][2]; if ( $add_time == 0) { $garr = $this->GetAll("SELECT activation_time FROM sk_packets WHERE blocked=0 AND gid='".$res[0][3]."'"); if ( $garr) $add_time = $garr[0][0]; else return false; } $this->BeginTrans(); $date = date( $this->owner->date_format, time()+$add_time); $res1 = $this->Execute("UPDATE sk_users SET activated='1', expired='".$date."' WHERE uid='".$res[0][0]."'"); if ( $res1) { require_once(dirname(__FILE__).'/../../../../class.PayOp.inc.php'); $obj = new PayOp( $this->owner, $res[0][6], $res[0][1], '', $GLOBALS['RESELLER'], $GLOBALS['SSXID'], $GLOBALS['sid'], 'Print and sell'); $res1 = $obj->process(); } if ( $res1) { $this->CommitTrans(); $GLOBALS['uid'] = $res[0][0]; $GLOBALS['nickname'] = $res[0][4]; $GLOBALS['password'] = $res[0][5]; $this->owner->log(CMMN_INFO, $_SERVER['REMOTE_ADDR'], $_SERVER['PHP_SELF'], $GLOBALS['USER'], '', sprintf( STR_CRD_EDITED, $GLOBALS['sid'])); return true; } else $this->RollbackTrans(); } } return false; } public function get_record( $obj) { if ( ($a = $this->GetAll(sprintf("SELECT * FROM sk_card_series WHERE sid='%s'", $obj)))) return $a[0]; else return array(); } public function get_records_for_provider($lines_per_page, $page=0) { $res = $this->GetAll("SELECT count(*) FROM sk_card_series, sk_service_set, sk_packets WHERE sk_card_series.gid=sk_packets.gid AND sk_packets.service_set_id=sk_service_set.service_set_id AND sk_service_set.provider_id='".$GLOBALS['PROVIDER']."'"); if ( $page >= 0) { $low = $page*$lines_per_page; $high = $lines_per_page; $allRecs = $this->GetAll("SELECT sk_card_series.sid, sk_card_series.url, sk_card_series.cost, sk_card_series.date_add, sk_card_series.cards_col, sk_card_series.gid, sk_card_series.descr, sk_card_series.card_type FROM sk_card_series, sk_service_set, sk_packets WHERE sk_card_series.gid=sk_packets.gid AND sk_packets.service_set_id=sk_service_set.service_set_id AND sk_service_set.provider_id='".$GLOBALS['PROVIDER']."' ORDER by sk_card_series.sid OFFSET ".$low." LIMIT ".$high); } else $allRecs = $this->GetAll("SELECT sk_card_series.sid, sk_card_series.url, sk_card_series.cost, sk_card_series.date_add, sk_card_series.cards_col, sk_card_series.gid, sk_card_series.descr, sk_card_series.card_type FROM sk_card_series, sk_service_set, sk_packets WHERE sk_card_series.gid=sk_packets.gid AND sk_packets.service_set_id=sk_service_set.service_set_id AND sk_service_set.provider_id='".$GLOBALS['PROVIDER']."' ORDER by sk_card_series.sid"); return array($res[0][0], $allRecs); } public function get_records_for_operator($lines_per_page, $page=0) { $res = $this->GetAll("SELECT count(*) FROM sk_card_series, sk_group_tracker WHERE sk_card_series.gid=sk_group_tracker.gid AND sk_group_tracker.obj_id='".$GLOBALS['SSXID']."'"); if ( $page >= 0) { $low = $page*$lines_per_page; $high = $lines_per_page; $allRecs = $this->GetAll("SELECT sk_card_series.sid, sk_card_series.url, sk_card_series.cost, sk_card_series.date_add, sk_card_series.cards_col, sk_card_series.gid, sk_card_series.descr, sk_card_series.card_type FROM sk_card_series, sk_group_tracker WHERE sk_card_series.gid=sk_group_tracker.gid AND sk_group_tracker.obj_id='".$GLOBALS['SSXID']."' OFFSET ".$low." LIMIT ".$high); } else $allRecs = $this->GetAll("SELECT sk_card_series.sid, sk_card_series.url, sk_card_series.cost, sk_card_series.date_add, sk_card_series.cards_col, sk_card_series.gid, sk_card_series.descr, sk_card_series.card_type FROM sk_card_series, sk_group_tracker WHERE sk_card_series.gid=sk_group_tracker.gid AND sk_group_tracker.obj_id='".$GLOBALS['SSXID']."'"); return array($res[0][0], $allRecs); } public function get_records_for_lowlevel($lines_per_page, $page=0) { $res = $this->GetAll("SELECT count(*) FROM sk_card_series, sk_group_tracker WHERE sk_card_series.gid=sk_group_tracker.gid AND sk_group_tracker.obj_id='".$GLOBALS['SSXID']."'"); if ( $page >= 0) { $low = $page*$lines_per_page; $high = $lines_per_page; $allRecs = $this->GetAll("SELECT sk_card_series.sid, sk_card_series.url, sk_card_series.cost, sk_card_series.date_add, sk_card_series.gid, sk_card_series.descr, sk_card_series.cards_col FROM sk_card_series, sk_group_tracker WHERE sk_card_series.gid=sk_group_tracker.gid AND sk_group_tracker.obj_id='".$GLOBALS['SSXID']."' OFFSET ".$low." LIMIT ".$high); } else $allRecs = $this->GetAll("SELECT sk_card_series.sid, sk_card_series.url, sk_card_series.cost, sk_card_series.date_add, sk_card_series.gid, sk_card_series.descr, sk_card_series.cards_col FROM sk_card_series, sk_group_tracker WHERE sk_card_series.gid=sk_group_tracker.gid AND sk_group_tracker.obj_id='".$GLOBALS['SSXID']."'"); return array($res[0][0], $allRecs); } } ?>
