<?php
 class prov_tardef { var $owner; var $classname = 'prov_tardef'; var $can_access = false; var $can_add = false; var $can_edit = false; var $can_remove = false; var $dbs = array(); public function __construct( $app) { $this->owner = $app; $this->owner->set_help( $this->classname); $this->can_access = ValidateLevel( $this->owner->config['SECURITY']['PROVIDER_OPERATORS']); $this->can_add = ValidateLevel( $this->owner->config['SECURITY']['PROVIDER_OPERATORS']+LVL_ADD); $this->can_edit = ValidateLevel( $this->owner->config['SECURITY']['PROVIDER_OPERATORS']+LVL_EDIT); $this->can_remove = ValidateLevel( $this->owner->config['SECURITY']['PROVIDER_OPERATORS']+LVL_REMOVE); } public function get_from_db() { return json_decode($this->owner->db->get_value('default_tariff_config', $GLOBALS['PROVIDER']), true); } public function save_to_db($a=array()) { return $this->owner->db->store_value('default_tariff_config',json_encode($a), $GLOBALS['PROVIDER']); } public function config() { if ( !$this->can_access) { $this->owner->permission_denied(); return; } $sign = false; if (empty($GLOBALS['PROVIDER'])) { $sign = true; $GLOBALS['PROVIDER'] = 1; } $a = $this->owner->db->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']."'"); if (!is_array($a) || ($a[0][0] == 0)) { $this->owner->continue_msg(STR_TARDEF_SETUP_TARIFF_FIRST, (($sign)?'q=rad.Tariff2.table_view':'q=rad.ProvTariff2.table_view')); return; } $t = $this->owner->load_template_resource(array('hForm'=>'prov_tardef')); $t->set_block('hForm', 'list', 'hList'); $t->set_block('hForm', 'func', 'hFunc'); $t->set_block('hForm', 'payment', 'hPayment'); $t->set_var('hList', ''); $t->set_var('hFunc', ''); $t->set_var('hPayment', ''); $t->set_var('VAL_FORMACTION', Linkage('', 'q=rad.prov_tardef.save')); $cp = $this->get_from_db(); $this->owner->page_title = STR_TARDEF_CONFIG; $this->owner->page_comments = STR_CMMN_HIGHLIGHTEDNOTE; $t->set_var('LS_PATH', $this->owner->get_ls_path()); $t->set_var('BTN_SAVE', STR_CMMN_SAVE); $t->set_var('BTN_RESET', STR_CMMN_RESET); $t->set_var('TXT_RULES', STR_TARDEF_RULES); $t->set_var('TXT_COMMENTS', STR_TARDEF_COMMENTS); $t->set_var('TXT_DEFAULT', STR_TARDEF_DEFAULT); $t->set_var('TXT_TARIFFS', STR_TARDEF_TARIFFS); $t->set_var('TXT_PAYMENTS', STR_TARDEF_PAYMENTS); $t->set_var('HIDDEN_VARS', ''); if ( isset( $cp['default'])) $t->set_var('VAL_DEFAULT', Selector('default',$this->owner->db->get_tariff_list($GLOBALS['PROVIDER']), $cp['default'])); else $t->set_var('VAL_DEFAULT', Selector('default',$this->owner->db->get_tariff_list($GLOBALS['PROVIDER']), 0)); if ( isset($this->owner->config['webauth'])) { foreach($this->owner->config['webauth'] as $k=>$v) { $t->set_var('TXT_WEBAUTH_DEFAULT', sprintf(STR_TARDEF_WEBAUTH_DEFAULT, $k)); $t->set_var('TXT_ENABLE', sprintf(STR_TARDEF_WEBAUTH_ENABLE, $k)); $t->set_var('VAL_WA_METHOD', $k); if ( isset( $cp[$k])) { $t->set_var('VAL_CHECKED', 'checked="checked"'); $t->set_var('VAL_WEBAUTH_DEFAULT', Selector('webauth_'.$k,$this->owner->db->get_tariff_list($GLOBALS['PROVIDER']), $cp[$k])); } else { $t->set_var('VAL_WEBAUTH_DEFAULT', Selector('webauth_'.$k,$this->owner->db->get_tariff_list($GLOBALS['PROVIDER']), 0)); $t->set_var('VAL_CHECKED', ''); } $t->parse('hList', 'list', true); $t->parse('hFunc', 'func', true); } } if ( isset($this->owner->config['payments'])) { foreach($this->owner->config['payments'] as $k=>$v) { $t->set_var('TXT_ENABLE_PAYOP', sprintf(STR_TARDEF_PAYMENT_ENABLE, $k)); $t->set_var('VAL_PAY_METHOD', $k); if ( isset( $cp['payments'][$k])) $t->set_var('VAL_CHECKED', 'checked="checked"'); else $t->set_var('VAL_CHECKED', ''); $t->parse('hPayment', 'payment', true); } } $t->pparse('out', 'hForm'); } public function save() { if ( !$this->can_edit) { $this->owner->permission_denied(); return; } if (empty($GLOBALS['PROVIDER'])) $GLOBALS['PROVIDER'] = 1; $cp = array(); if ( isset( $GLOBALS['default'])) $cp['default'] = $GLOBALS['default']; $arr = parse_globals_by_prefix('webauth_'); foreach($arr as $key=>$value) $cp[$key] = $value; $arr = parse_globals_by_prefix('payment_'); foreach($arr as $key=>$value) $cp['payments'][$key] = 1; if ( $this->save_to_db($cp)) { Refresh('q=rad.prov_tardef.config'); } else $this->owner->error_msg(STR_CMMN_ERROR); } } ?>
