WIP Ivt Import 2024-05-02
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a>
|
||||
</li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Admin")?>">Admin</a></li>
|
||||
<li class="breadcrumb-item active">IVT Contract Import</li>
|
||||
</ol>
|
||||
@@ -23,7 +24,7 @@
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-8">
|
||||
<div class="col-12">
|
||||
|
||||
<div class="card border-top-primary">
|
||||
<div class="card-body">
|
||||
@@ -32,33 +33,55 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Kunde</th>
|
||||
<th>IVT Kunde</th>
|
||||
<th>IVT Produkt</th>
|
||||
<th>Produkt</th>
|
||||
<th>Preis Setup</th>
|
||||
<th>Preis</th>
|
||||
<th>Rech. Interval</th>
|
||||
<th>Herstellungsd.</th>
|
||||
<th>Aktion</th>
|
||||
<th>Bestellung</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($data['contracts'] as $d): ?>
|
||||
<tr>
|
||||
<td><?=$d["customer"]->getCompanyOrName()?></td>
|
||||
<td><?=$d["customer"]->getCompanyOrName()?>
|
||||
(<?=$d["customer"]->customer_number?>)
|
||||
</td>
|
||||
<td><?=$d["ivtcustomer"]->id?></td>
|
||||
<td><?=$d["ivtproduct"]->name?></td>
|
||||
<td><?=$d["product"]->name?></td>
|
||||
<td><?=$d["contract"]->price_setup?></td>
|
||||
<td><?=$d["contract"]->price?></td>
|
||||
<td>
|
||||
<?=$d["contract"]->billing_period?> (<?=($d["contract"]->billing_period == 1) ? "Monatlich" : ""?><?=($d["contract"]->billing_period == 12) ? "Jährlich" : ""?><?=($d["contract"]->billing_period == 24) ? "Zweijährlich" : ""?><?=($d["contract"]->billing_period == 36) ? "Dreijährlich" : ""?>)
|
||||
<?=$d["contract"]->billing_period?>
|
||||
(
|
||||
<?=($d["contract"]->billing_period == 1) ? "Monatlich" : ""?>
|
||||
<?=($d["contract"]->billing_period == 12) ? "Jährlich" : ""?>
|
||||
<?=($d["contract"]->billing_period == 24) ? "Zweijährlich" : ""?>
|
||||
<?=($d["contract"]->billing_period == 36) ? "Dreijährlich" : ""?>
|
||||
)
|
||||
</td>
|
||||
<td><?=date("d.m.Y H:i", $d["contract"]->finish_date)?></td>
|
||||
<td><?=$d["action"]?></td>
|
||||
<td>
|
||||
<?php if(array_key_exists("orderproduct", $d) && $d["orderproduct"] && $d["orderproduct"]->order_id): ?>
|
||||
<a href="<?=self::getUrl("Order", "", ["id" => $d["orderproduct"]->order_id])?>" target="_blank"><?=$d["orderproduct"]->order_id?></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div>
|
||||
<a href="<?=self::getUrl("Admin", "ivtAdminImport", ["doit" => 1])?>"><button class="btn btn-primary" id="doitbutton"><i class="far fa-fw fa-exclamation-circle"></i> Jetzt importieren</button></a>
|
||||
<a href="<?=self::getUrl("Admin", "ivtAdminImport", ["doit" => 1])?>">
|
||||
<button class="btn btn-primary" id="doitbutton"><i
|
||||
class="far fa-fw fa-exclamation-circle"></i> Jetzt importieren
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -67,7 +90,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="<?= self::getResourcePath() ?>assets/js/datatables-std.js?<?= date('U') ?>"></script>
|
||||
<script type="text/javascript"
|
||||
src="<?=self::getResourcePath()?>assets/js/datatables-std.js?<?=date('U')?>"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$("#doitbutton").click(function () {
|
||||
|
||||
@@ -79,6 +79,11 @@ class Address extends mfBaseModel {
|
||||
if($this->company) $name_search[] = $this->company;
|
||||
if($this->lastname) $name_search[] = $this->lastname;
|
||||
|
||||
$country = new Country($this->country_id);
|
||||
if(!$country) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fibumerge = XinonFibuMergeModel::getFirst(["old_custnum" => $old_custnum, "name" => $name_search]);
|
||||
if(!$fibumerge) {
|
||||
// create fibu merge
|
||||
@@ -91,6 +96,7 @@ class Address extends mfBaseModel {
|
||||
"strasse" => $this->street,
|
||||
"plz" => $this->zip,
|
||||
"ort" => $this->city,
|
||||
"land" => $country->isocode,
|
||||
"create_by" => 1,
|
||||
"edit_by" => 1
|
||||
]);
|
||||
|
||||
@@ -127,7 +127,7 @@ class AdminController extends mfBaseController {
|
||||
$products = [];
|
||||
|
||||
foreach($ivtproducts as $product) {
|
||||
$active_count = IvtCustomerProductModel::count(['pid' => $product->id]);
|
||||
$active_count = IvtCustomerTelephoneNrModel::count(['pid' => $product->id]);
|
||||
if(!$active_count) continue;
|
||||
|
||||
$new_product = [];
|
||||
@@ -136,7 +136,7 @@ class AdminController extends mfBaseController {
|
||||
$new_product["customer"] = false;
|
||||
|
||||
if($active_count == 1) {
|
||||
$cp = IvtCustomerProductModel::getFirst(["pid" => $product->id]);
|
||||
$cp = IvtCustomerTelephoneNrModel::getFirst(["pid" => $product->id]);
|
||||
//var_dump($cp);exit;
|
||||
$customer = $cp->customer;
|
||||
//var_dump($customer);exit;
|
||||
@@ -151,7 +151,7 @@ class AdminController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function ivtContractImportAction() {
|
||||
exit;
|
||||
//exit;
|
||||
$doit = false;
|
||||
if($this->request->doit == 1) {
|
||||
$doit = true;
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
class Admin_IvtContractImport {
|
||||
private $request;
|
||||
private $log;
|
||||
|
||||
public function __construct($request) {
|
||||
$this->request = $request;
|
||||
$this->log = mfLoghandler::singleton();
|
||||
}
|
||||
|
||||
public function run($doit = false) {
|
||||
@@ -12,7 +14,14 @@ class Admin_IvtContractImport {
|
||||
$data = [];
|
||||
$data['ignore'] = 0;
|
||||
$data["contracts"] = [];
|
||||
foreach(IvtCustomerProductModel::getAll() as $ivt_contract) {
|
||||
$i = 0;
|
||||
foreach(IvtCustomerTelephoneNrModel::getAll("cid") as $ivt_contract) {
|
||||
if($i > 100) break;
|
||||
$i++;
|
||||
$neu = [];
|
||||
$orderproduct = false;
|
||||
$orderproduct_id = false;
|
||||
|
||||
$ivt_customer = $ivt_contract->customer;
|
||||
$ivt_product = $ivt_contract->product;
|
||||
|
||||
@@ -28,22 +37,26 @@ class Admin_IvtContractImport {
|
||||
}
|
||||
|
||||
|
||||
if(!$this->checkIvtProduct($productMatch->ivtproduct)) {
|
||||
if(!$this->checkIvtProduct($productMatch->ivtproduct, $doit)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$customer = AddressModel::getFirst(["customer_number" => $ivt_contract->cid]);
|
||||
$ip = $productMatch->ivtproduct;
|
||||
$product = $productMatch->product;
|
||||
/*if($ivt_contract->id == 3035) {
|
||||
var_dump($ivt_contract->cid, $customer);
|
||||
}*/
|
||||
|
||||
if(!$customer->id) {
|
||||
echo "Kein thetool Kunde zu IVT customer ".$ivt_contract->cid." gefunden -> wird angelegt<br />\n";
|
||||
if(!$customer) {
|
||||
$this->log->debug("Kein thetool Kunde zu IVT customer " . $ivt_contract->cid . " gefunden -> wird angelegt");
|
||||
$customer = $this->createAddressFromIvtCustomer($ivt_contract->customer);
|
||||
if(!$customer) {
|
||||
echo "Fehler beim anlegen der Adresse<br />\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$ip = $productMatch->ivtproduct;
|
||||
$product = $productMatch->product;
|
||||
/*
|
||||
// check if contract was imported already
|
||||
$existing_contract = ContractModel::getFirst(["imported_from" => "ivt", "imported_data" => $ivt_contract->id]);
|
||||
@@ -54,16 +67,22 @@ class Admin_IvtContractImport {
|
||||
*/
|
||||
|
||||
|
||||
|
||||
$finish_date = new DateTime($ivt_contract->created);
|
||||
$finish_date->modify("+2 hours");
|
||||
|
||||
|
||||
$contract_data = [];
|
||||
$contract_data['owner_id'] = $customer->id;
|
||||
//$contract_data['billingaddress_id'] = $customer->id;
|
||||
$contract_data['billingaddress_id'] = $customer->id;
|
||||
$contract_data['product_id'] = $product->id;
|
||||
$contract_data['product_name'] = $ip->name;
|
||||
$contract_data['matchcode'] = "";
|
||||
$contract_data['amount'] = 1;
|
||||
$contract_data['price'] = $ip->price;
|
||||
$contract_data['price_setup'] = 0;
|
||||
$contract_data['finish_date'] = mktime(2,0,0,date("m"),1,date("Y"));
|
||||
$contract_data['price_nne'] = 0;
|
||||
$contract_data['price_nbe'] = 0;
|
||||
$contract_data['finish_date'] = $finish_date->getTimestamp();
|
||||
$contract_data['finish_date_by'] = 1;
|
||||
$contract_data['imported_from'] = "ivt";
|
||||
$contract_data['imported_data'] = $ivt_contract->id;
|
||||
@@ -79,8 +98,10 @@ class Admin_IvtContractImport {
|
||||
|
||||
|
||||
$neu["customer"] = $customer;
|
||||
$neu["ivtcustomer"] = $ivt_customer;
|
||||
$neu["ivtproduct"] = $ip;
|
||||
$neu["product"] = $product;
|
||||
$neu["orderproduct"] = false;
|
||||
$neu['action'] = "import";
|
||||
$ignore = false;
|
||||
|
||||
@@ -92,7 +113,39 @@ class Admin_IvtContractImport {
|
||||
$ignore = true;
|
||||
}
|
||||
|
||||
// find thetool Order
|
||||
$order = OrderModel::getFirst(["owner_id" => $customer->id]);
|
||||
/*if($ivt_contract->id == 3035) {
|
||||
var_dump($order);
|
||||
}*/
|
||||
|
||||
/*if($ivt_contract->id == 3035) {
|
||||
var_dump($order);exit;
|
||||
}*/
|
||||
|
||||
if($order) {
|
||||
foreach($order->products as $orderproduct) {
|
||||
if($orderproduct->product_id == $product->id) {
|
||||
$orderproduct_id = $orderproduct->id;
|
||||
}
|
||||
}
|
||||
if($orderproduct_id) {
|
||||
$contract_data["orderproduct_id"] = $orderproduct->id;
|
||||
$neu["orderproduct"] = $orderproduct;
|
||||
} else {
|
||||
$this->log->debug("Kein Orderproduct gefunden in Order ".$order->id." für Ivt customer_product ".$ivt_contract->id);
|
||||
}
|
||||
} else {
|
||||
//$this->log->debug("Keine thetool order für ivt customer_product ".$ivt_contract->id);
|
||||
}
|
||||
/*if($ivt_contract->id == 3035) {
|
||||
var_dump($order, $orderproduct);
|
||||
}*/
|
||||
$contract = ContractModel::create($contract_data);
|
||||
$contract->matchcode = $contract->generateMatchcode();
|
||||
/*if($ivt_contract->id == 3035) {
|
||||
var_dump($contract);
|
||||
}*/
|
||||
$neu["contract"] = $contract;
|
||||
|
||||
if($doit && !$ignore) {
|
||||
@@ -102,6 +155,7 @@ class Admin_IvtContractImport {
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
// create journal entry
|
||||
$journal = ContractjournalModel::create([
|
||||
'contract_id' => $contract_id,
|
||||
@@ -116,27 +170,98 @@ class Admin_IvtContractImport {
|
||||
}
|
||||
|
||||
// import Contractconfig
|
||||
$this->importContractconfig($ivt_customer, $ivt_product, $contract);
|
||||
|
||||
|
||||
}
|
||||
$contractconfig = $this->importContractconfig($ivt_customer, $ivt_product, $contract, ($doit && !$ignore));
|
||||
var_dump($contractconfig);exit;
|
||||
|
||||
$data["contracts"][] = $neu;
|
||||
if($neu['action'] == "ignore") {
|
||||
$data['ignore']++;
|
||||
}
|
||||
|
||||
/*if($ivt_contract->id == 3035) {
|
||||
var_dump($neu);exit;
|
||||
}*/
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function checkIvtCustomer($customer) {
|
||||
private function checkIvtCustomer($ivt_customer, $doit = false) {
|
||||
$return = [];
|
||||
// create customer if not exists
|
||||
$old_custnum = $customer->id;
|
||||
if(!$old_custnum) return false;
|
||||
$ivt_custnum = $ivt_customer->id;
|
||||
if(!$ivt_custnum) return false;
|
||||
|
||||
// sync billing address
|
||||
$owner = AddressModel::getFirst(["customer_number" => $ivt_custnum]);
|
||||
if(!$owner) {
|
||||
die("Address $ivt_custnum not found!");
|
||||
}
|
||||
|
||||
// find order
|
||||
$order_count = OrderModel::count(["owner_id" => $owner->id, "finish_date" => true]);
|
||||
if($order_count > 1) {
|
||||
die("Mehr als eine Bestellung für ivt_customer $ivt_custnum gefunden.\n".print_r($owner, true));
|
||||
}
|
||||
$order = OrderModel::getFirst(["owner_id" => $owner->id, "finish_date" => true]);
|
||||
if(!$order) {
|
||||
$this->log->debug(__METHOD__.": No order for ivt customer $ivt_custnum");
|
||||
return true;
|
||||
}
|
||||
|
||||
// look for billingaddress_id in order and use it
|
||||
if($order->billingaddress_id) {
|
||||
if($order->billingaddress_id == $ivt_custnum) {
|
||||
$return["billingaddress_id"] = $order->billingaddress_id;
|
||||
} else {
|
||||
$billingaddress = new Address($order->billingaddress_id);
|
||||
if(!$billingaddress->id) {
|
||||
die("Billingaddress " . $order->billingaddress_id . " does not exist (order " . $order->id . "; ivt customer $ivt_custnum)");
|
||||
}
|
||||
$return["billingaddress_id"] = $billingaddress->id;
|
||||
}
|
||||
}
|
||||
|
||||
// if no billingaddress_id in order, compare address of Address and ivt_customer and
|
||||
// create new billingaddress if nessecary
|
||||
|
||||
$new_billing = [];
|
||||
foreach(["company", "firstname", "lastname", "street", "zip", "city", "phone", "email", "uid", "billing_type", "billing_delivery",
|
||||
"bank_account_bank", "bank_account_owner", "bank_account_iban", "bank_account_bic"] as $field) {
|
||||
$new_billing[$field] = $owner->$field;
|
||||
}
|
||||
|
||||
if($ivt_customer->company) {
|
||||
if($ivt_customer->company != $owner->company) $new_billing["company"] = $ivt_customer->company;
|
||||
} else {
|
||||
if($ivt_customer->firstname != $owner->firstname) $new_billing["firstname"] = $ivt_customer->firstname;
|
||||
if($ivt_customer->surname != $owner->lastname) $new_billing["lastname"] = $ivt_customer->surname;
|
||||
}
|
||||
|
||||
if($ivt_customer->UID != $owner->uid) $new_billing["uid"] = $ivt_customer->UID;
|
||||
if($ivt_customer->zip != $owner->zip) $new_billing["zip"] = $ivt_customer->zip;
|
||||
if($ivt_customer->location != $owner->city) $new_billing["city"] = $ivt_customer->location;
|
||||
if($ivt_customer->street." ".$ivt_customer->housenumber != $owner->street) $new_billing["street"] = $ivt_customer->street." ".$ivt_customer->housenumber;
|
||||
if($ivt_customer->phone != $owner->phone) $new_billing["phone"] = $ivt_customer->phone;
|
||||
if($ivt_customer->email != $owner->email) $new_billing["email"] = $ivt_customer->email;
|
||||
|
||||
$new_billing["billing_type"] = ($ivt_customer->payment == 1) ? "invoice" : "sepa";
|
||||
$new_billing["billing_delivery"] = ($ivt_customer->paper_invoice == 1) ? "paper" : "email";
|
||||
|
||||
if($ivt_customer->bank_account_bank != $owner->bank_account_bank) $new_billing["bank_account_bank"] = $ivt_customer->bank_account_bank;
|
||||
if($ivt_customer->bank_account_owner != $owner->bank_account_owner) $new_billing["bank_account_owner"] = $ivt_customer->bank_account_owner;
|
||||
if($ivt_customer->bank_account_iban != $owner->bank_account_iban) $new_billing["bank_account_iban"] = $ivt_customer->bank_account_iban;
|
||||
if($ivt_customer->bank_account_bic != $owner->bank_account_bic) $new_billing["bank_account_bic"] = $ivt_customer->bank_account_bic;
|
||||
|
||||
$billingaddress = AddressModel::create($new_billing);
|
||||
|
||||
|
||||
|
||||
// TODO: sync bank data
|
||||
|
||||
return true;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function checkIvtProduct($product) {
|
||||
@@ -151,11 +276,13 @@ class Admin_IvtContractImport {
|
||||
return true;
|
||||
}
|
||||
|
||||
private function importContractconfig($ivt_customer, $ivt_product, $contract) {
|
||||
var_dump($contract, $contract->product, $contract->configgroups);
|
||||
private function importContractconfig($ivt_customer, $ivt_product, &$contract, $doit = false) {
|
||||
//return true;
|
||||
//var_dump($contract, $contract->product, $contract->configgroups);
|
||||
|
||||
|
||||
if(!is_array($contract->configgroups) || !count($contract->configgroups)) {
|
||||
echo "no contract config";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -166,17 +293,23 @@ class Admin_IvtContractImport {
|
||||
}
|
||||
|
||||
// lookup radius data
|
||||
$radius_data = $this->getRadiusUser($ivt_customer, $ivt_product, $contract);
|
||||
$ruser = $this->getRadiusUser($ivt_customer, $ivt_product, $contract);
|
||||
// lookup voip data
|
||||
$voip_data = $this->getVoipData($ivt_customer, $ivt_product, $contract);
|
||||
|
||||
foreach($contract->configgroups as $cgroup) {
|
||||
|
||||
$items = $cgroup->items;
|
||||
var_dump($cgroup);
|
||||
/*var_dump($cgroup);
|
||||
var_dump($items);
|
||||
exit;*/
|
||||
|
||||
foreach($items as $i) {
|
||||
/** @var ContractconfigItem $i */
|
||||
if(!$i->contract_id) {
|
||||
$i->setContractId($contract->id);
|
||||
}
|
||||
//var_dump($i, $i->value);exit;
|
||||
switch($i->name) {
|
||||
case "bandwidth_down":
|
||||
$i->value->set($product->attributes["bw_down"]->value);
|
||||
@@ -188,28 +321,44 @@ class Admin_IvtContractImport {
|
||||
break;
|
||||
|
||||
case "radiususer_username":
|
||||
$i->value->set($radius_data["username"]);
|
||||
$i->value->sav();
|
||||
$i->value->set($ruser->username);
|
||||
$i->value->save();
|
||||
break;
|
||||
case "radiususer_password":
|
||||
$i->value->set($radius_data["username"]);
|
||||
$i->value->sav();
|
||||
$i->value->set($ruser->getPassword());
|
||||
$i->value->save();
|
||||
break;
|
||||
case "radiususer_ipaddress":
|
||||
$i->value->set($radius_data["ipaddress"]);
|
||||
$i->value->sav();
|
||||
$i->value->set($ruser->getAttribute("Framed-IP-Address"));
|
||||
$i->value->save();
|
||||
break;
|
||||
case "radiususer_ipprefix":
|
||||
$i->value->set($radius_data["subnetmask"]);
|
||||
$i->value->sav();
|
||||
case "radiususer_netmask":
|
||||
$i->value->set($ruser->getAttribute("Framed-IP-Netmask"));
|
||||
$i->value->save();
|
||||
break;
|
||||
|
||||
|
||||
case "radiususer_iproute":
|
||||
$i->value->set($ruser->getAttribute("Framed-Route"));
|
||||
$i->value->save();
|
||||
break;
|
||||
case "radiususer_dns1":
|
||||
$i->value->set($ruser->getAttribute("MS-Primary-DNS-Server"));
|
||||
$i->value->save();
|
||||
break;
|
||||
case "radiususer_dns2":
|
||||
$i->value->set($ruser->getAttribute("MS-Secondary-DNS-Server"));
|
||||
$i->value->save();
|
||||
break;
|
||||
default:
|
||||
$this->log->debug(__METHOD__.": ".$ivt_customer->id.": Kein Wert für Configgroupitem ".$i->name." gefunden");
|
||||
}
|
||||
//var_dump($i, $i->value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
var_dump($contract->configgroups);
|
||||
exit;
|
||||
|
||||
/*
|
||||
@@ -226,13 +375,44 @@ class Admin_IvtContractImport {
|
||||
}
|
||||
|
||||
private function getRadiusUser($ivt_customer, $ivt_product, $contract) {
|
||||
// find radius user
|
||||
// find radius user (kundennummer in radius info feld
|
||||
$radius = new RadiusDB_Client();
|
||||
|
||||
$user_count = 0;
|
||||
$user = $radius->getUserByCustnum($ivt_customer->id);
|
||||
if(!$user) {
|
||||
$this->log->debug("User in Radius nicht gefunden Kundennummer ".$ivt_customer->id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
||||
// return data
|
||||
}
|
||||
|
||||
private function getVoipData($ivt_customer, $ivt_product, $contract) {
|
||||
// find voice number in ivt
|
||||
$ivtnum = IvtCustomerTelephoneNrModel::getFirst(["cid" => $ivt_customer->id]);
|
||||
if(!$ivtnum) return true;
|
||||
|
||||
$number = preg_replace('/^0043/', '43', $ivtnum->number);
|
||||
if(!$number) return true;
|
||||
|
||||
// find number in block
|
||||
$voicenumberblock = Voicenumberblock::findBlock($number);
|
||||
if(!$voicenumberblock) return false;
|
||||
|
||||
if(!$voicenumberblock->isNumberInBlock($number)) {
|
||||
die("Block für Nummer $number enthält nummer nicht.");
|
||||
}
|
||||
|
||||
$voicenumber = $voicenumberblock->getVoicenumber($number);
|
||||
if(!$voicenumber) {
|
||||
die("Nummer $number gehört nicht in Block ".$voicenumberblock->id);
|
||||
}
|
||||
|
||||
// return voicenumber object
|
||||
return $voicenumber;
|
||||
}
|
||||
|
||||
private function createAddressFromIvtCustomer(IvtCustomer $cust) {
|
||||
|
||||
@@ -232,14 +232,6 @@ class Contract extends mfBaseModel {
|
||||
return $this->orderproduct;
|
||||
}
|
||||
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*if($name == "contractConfigGroups") {
|
||||
$product = $this->getProperty("product");
|
||||
$this->contractConfigGroups = ContractconfigGroupModel::search(['producttech_id' => $product->producttech_id]);
|
||||
@@ -267,6 +259,19 @@ class Contract extends mfBaseModel {
|
||||
return $this->configvalues;
|
||||
}
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*if($name == "contractConfigItems") {
|
||||
$product = $this->getProperty("product");
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class ContractconfigItem extends mfBaseModel {
|
||||
private $value;
|
||||
private $contract_id;
|
||||
public $contract_id;
|
||||
|
||||
public function setContractId($contract_id) {
|
||||
if(!is_numeric($contract_id)) {
|
||||
|
||||
@@ -3,15 +3,19 @@
|
||||
class IvtCustomerProductModel {
|
||||
|
||||
|
||||
public static function getAll() {
|
||||
public static function getAll($order = false) {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$res = $db->select("customer_product", "*", "1=1 ORDER BY id");
|
||||
if(!$order) {
|
||||
$order = "id";
|
||||
}
|
||||
|
||||
$res = $db->select("customer_product", "*", "1=1 ORDER BY $order");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtCustomerProduct($data);
|
||||
$items[] = new IvtCustomerTelephoneNr($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
@@ -24,7 +28,7 @@ class IvtCustomerProductModel {
|
||||
$res = $db->select("customer_product", "*", "$where ORDER BY id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new IvtCustomerProduct($data);
|
||||
$item = new IvtCustomerTelephoneNr($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
@@ -67,7 +71,7 @@ class IvtCustomerProductModel {
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtCustomerProduct($data);
|
||||
$items[] = new IvtCustomerTelephoneNr($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
class IvtCustomerTelephoneNr extends mfBaseModel {
|
||||
protected $forcestr = [];
|
||||
private $customer;
|
||||
|
||||
/**
|
||||
* Takes ID or DB row as arguments
|
||||
* @param id or table row $_
|
||||
*/
|
||||
public function __construct($_ = NULL) {
|
||||
$this->log = mfLoghandler::singleton();
|
||||
$this->data = new stdClass();
|
||||
$this->table = "products";
|
||||
|
||||
$this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
if(is_numeric($_)) {
|
||||
$this->fetch($_);
|
||||
} elseif(is_object($_)) {
|
||||
$this->load($_);
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "customer") {
|
||||
$ivtcustomer = new IvtCustomer($this->cid);
|
||||
if($ivtcustomer->id) {
|
||||
$this->ivtcustomer = $ivtcustomer;
|
||||
}
|
||||
return $this->ivtcustomer;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name . "_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
|
||||
public function __debugInfo() {
|
||||
$vars = get_object_vars($this);
|
||||
if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)";
|
||||
if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)';
|
||||
return $vars;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
class IvtCustomerTelephoneNrModel {
|
||||
|
||||
|
||||
public static function getAll($order = false) {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
if(!$order) {
|
||||
$order = "id";
|
||||
}
|
||||
|
||||
$res = $db->select("customer_telephone_nr", "*", "1=1 ORDER BY $order");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtCustomerTelephoneNr($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("customer_telephone_nr", "*", "$where ORDER BY id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new IvtCustomerTelephoneNr($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) cnt FROM customer_telephone_nr WHERE $where ORDER by id";
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM customer_telephone_nr WHERE $where ORDER by cid,pid,sid,id";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new IvtCustomerTelephoneNr($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("cid", $filter)) {
|
||||
$cid = $filter['cid'];
|
||||
if(is_numeric($cid)) {
|
||||
$where .= " AND cid=$cid";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("pid", $filter)) {
|
||||
$pid = $filter['pid'];
|
||||
if(is_numeric($pid)) {
|
||||
$where .= " AND pid=$pid";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("number", $filter)) {
|
||||
$number = (string)FronkDB::singleton()->escape($filter['number']);
|
||||
if($number) {
|
||||
$where .= " AND number='$number'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("number%", $filter)) {
|
||||
$number = (string)FronkDB::singleton()->escape($filter['number']);
|
||||
if($number) {
|
||||
$where .= " AND number LIKE '%$number%'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -288,7 +288,7 @@ class Order extends mfBaseModel {
|
||||
$to = $values['to'];
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn("Order Fileupload Email not sent. (subject: '$subject', from: '$from', from_email: '$from_email', to: '$to')");
|
||||
$this->log->warn("Order Fileupload Email not sent. (subject: '$subject', from: '$from_name', from_email: '$from', to: '$to')");
|
||||
} else {
|
||||
$filepath = MFUPLOAD_FILE_SAVE_PATH;
|
||||
if($file->file->subfolder) {
|
||||
|
||||
@@ -1236,7 +1236,6 @@ class OrderController extends mfBaseController {
|
||||
$order->deletePositions();
|
||||
|
||||
|
||||
// TODO: check if Product is unused
|
||||
$order->delete();
|
||||
$this->layout()->setFlash("Bestellung gelöscht", "success");
|
||||
$this->redirect("Order");
|
||||
|
||||
@@ -35,6 +35,22 @@ class Voicenumberblock extends mfBaseModel {
|
||||
return $block;
|
||||
}
|
||||
|
||||
public function getVoicenumber($number) {
|
||||
if(!$this->isNumberInBlock($number)) return false;
|
||||
|
||||
$vn = VoicenumberModel::getFirst(["number" => $number]);
|
||||
if(!$vn) {
|
||||
$vn = VoicenumberModel::create([
|
||||
"voicenumberblock_id" => $this->id,
|
||||
"active" => 1,
|
||||
"activated_date" => date("U"),
|
||||
"number" => $number
|
||||
]);
|
||||
}
|
||||
|
||||
return $vn;
|
||||
}
|
||||
|
||||
public function getFreeNumbers() {
|
||||
if(!$this->id) return false;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ class XinonFibuMergeModel {
|
||||
public $strasse;
|
||||
public $plz;
|
||||
public $ort;
|
||||
public $land;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
@@ -41,11 +42,14 @@ class XinonFibuMergeModel {
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getFirst($filter = []) {
|
||||
public static function getFirst($filter = [], $order = false) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
if(!$order) {
|
||||
$order = "old_custnum";
|
||||
}
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("XinonFibuMerge", "*", "$where ORDER BY old_custnum LIMIT 1");
|
||||
$res = $db->select("XinonFibuMerge", "*", "$where ORDER BY $order LIMIT 1");
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new XinonFibuMerge($data);
|
||||
@@ -58,12 +62,16 @@ class XinonFibuMergeModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
public static function getAll($order = false) {
|
||||
$items = [];
|
||||
|
||||
if(!$order) {
|
||||
$order = "old_custnum";
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("XinonFibuMerge", "*", "1=1 ORDER BY old_custnum");
|
||||
$res = $db->select("XinonFibuMerge", "*", "1=1 ORDER BY $order");
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
$items[] = new XinonFibuMerge($data);
|
||||
@@ -88,20 +96,25 @@ class XinonFibuMergeModel {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter = [], $limit = false) {
|
||||
public static function search($filter = [], $limit = false, $order = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
if(!$order) {
|
||||
$order = "old_custnum";
|
||||
}
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM XinonFibuMerge
|
||||
WHERE $where
|
||||
ORDER BY old_custnum";
|
||||
ORDER BY $order";
|
||||
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if (is_array($limit) && count($limit)) {
|
||||
if (is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT " . $limit['start'] . ", " . $limit['count'];
|
||||
} elseif (is_numeric($count)) {
|
||||
} elseif (is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT " . $limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
78
lib/RadiusDB/Client.php
Normal file
78
lib/RadiusDB/Client.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
class RadiusDB_Client {
|
||||
private $db;
|
||||
|
||||
public function __construct($host=false,$user=false,$pass=false,$dbname=false) {
|
||||
if(!$host) $host=RADIUSDB_DBHOST;
|
||||
if(!$user) $user=RADIUSDB_DBUSER;
|
||||
if(!$pass) $pass=RADIUSDB_DBPASS;
|
||||
if(!$dbname) $dbname=RADIUSDB_DBNAME;
|
||||
|
||||
$this->db = new FronkDB($host,$user,$pass,$dbname);
|
||||
}
|
||||
|
||||
public function getUser($username) {
|
||||
$user = new RadiusDB_User($this->db);
|
||||
$user->load($username);
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function searchUsers($search, $exact=false) {
|
||||
$users = array();
|
||||
$search = $this->db->escape($search);
|
||||
if($exact) {
|
||||
$res = $this->db->select("radcheck", "username", "username='$search' GROUP BY username ORDER BY LENGTH(username), username");
|
||||
} else {
|
||||
$res = $this->db->select("radcheck", "username", "username like '$search' GROUP BY username ORDER BY LENGTH(username), username");
|
||||
}
|
||||
if($this->db->num_rows($res)) {
|
||||
while($data = $this->db->fetch_object($res)) {
|
||||
$users[] = $data->username;
|
||||
}
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
|
||||
public function searchUsersByIp($ip) {
|
||||
$users = array();
|
||||
$ip = $this->db->escape($ip);
|
||||
$res = $this->db->select("radreply", "username", "attribute='Framed-IP-Address' AND value='$ip' GROUP BY username ORDER BY username");
|
||||
if($this->db->num_rows($res)) {
|
||||
while($data = $this->db->fetch_object($res)) {
|
||||
$users[] = $data->username;
|
||||
}
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
|
||||
public function getUserByCustnum($custnum, $e = false) {
|
||||
$users = array();
|
||||
$search = $this->db->escape($custnum);
|
||||
$field = "Custnum";
|
||||
if($e) {
|
||||
$field = "Custnume";
|
||||
}
|
||||
$res = $this->db->select("Hotspot_Usersettings", "Username", "$field = '$custnum' GROUP BY Username ORDER BY Username LIMIT 1");
|
||||
if($this->db->num_rows($res)) {
|
||||
$data = $this->db->fetch_object($res);
|
||||
$user = $this->getUser($data->Username);
|
||||
if($user->username) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getNas($nasname) {
|
||||
$nas = new RadiusDB_Nas($this->db);
|
||||
$nas->load($nasname);
|
||||
return $nas;
|
||||
}
|
||||
|
||||
public function restartRadiusServer() {
|
||||
exec("/usr/bin/sudo /usr/sbin/service freeradius restart");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
69
lib/RadiusDB/Nas.php
Normal file
69
lib/RadiusDB/Nas.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
class RadiusDB_Nas {
|
||||
private $db;
|
||||
public $id;
|
||||
public $nasname;
|
||||
public $intaddress;
|
||||
public $shortname;
|
||||
public $type;
|
||||
public $secret;
|
||||
public $description;
|
||||
|
||||
public function __construct($db) {
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function load($nasname) {
|
||||
//var_dump($this->db);
|
||||
$nasname = $this->db->escape($nasname);
|
||||
|
||||
$res = $this->db->select("nas", "*", "nasname='$nasname'");
|
||||
if(!$this->db->num_rows($res)) {
|
||||
$this->type = "other";
|
||||
$this->secret = Helper::getNewPassword(24);
|
||||
return true;
|
||||
}
|
||||
$nas = $this->db->fetch_object($res);
|
||||
|
||||
$this->id = $nas->id;
|
||||
$this->nasname = $nas->nasname;
|
||||
$this->intaddress = $nas->intaddress;
|
||||
$this->shortname = $nas->shortname;
|
||||
$this->type = $nas->type;
|
||||
$this->secret = $nas->secret;
|
||||
$this->description = $nas->description;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if(!$this->nasname) {
|
||||
return false;
|
||||
}
|
||||
if(!$this->secret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->id) {
|
||||
$id = $this->id;
|
||||
}
|
||||
$values['nasname'] = $this->nasname;
|
||||
$values['intaddress'] = $this->nasname; // is supposed to be the same as nasname
|
||||
$values['shortname'] = $this->shortname;
|
||||
$values['type'] = $this->type;
|
||||
$values['secret'] = $this->secret;
|
||||
$values['description'] = $this->description;
|
||||
|
||||
if($id) {
|
||||
if(!$this->db->update("nas", $values, "id=$id")) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(!$id = $this->db->insert("nas", $values)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
275
lib/RadiusDB/User.php
Normal file
275
lib/RadiusDB/User.php
Normal file
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
|
||||
class RadiusDB_User {
|
||||
private $db;
|
||||
|
||||
private $username;
|
||||
private $Usergroup;
|
||||
private $Checks;
|
||||
private $Attributes;
|
||||
private $AllowedNas;
|
||||
private $Info;
|
||||
|
||||
private $_oldUsergroup;
|
||||
private $_oldChecks;
|
||||
private $_oldAttributes;
|
||||
private $_oldAllowedNas;
|
||||
private $_oldInfo;
|
||||
|
||||
private $checkop = ':=';
|
||||
private $attribop = '=';
|
||||
|
||||
public function __construct($db) {
|
||||
$this->db = $db;
|
||||
$this->Checks = array();
|
||||
$this->Attributes = array();
|
||||
$this->AllowedNas = array();
|
||||
$this->Info = false;
|
||||
$this->_oldChecks = array();
|
||||
$this->_oldAttributes = array();
|
||||
$this->_oldAllowedNas = array();
|
||||
$this->_oldInfo = false;
|
||||
}
|
||||
|
||||
public function load($username) {
|
||||
if(!$username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->username = $username;
|
||||
|
||||
$res = $this->db->select("radcheck","*","username='$username'");
|
||||
if($this->db->num_rows($res)) {
|
||||
while($radcheck = $this->db->fetch_object($res)) {
|
||||
$this->Checks[$radcheck->attribute] = $radcheck->value;
|
||||
}
|
||||
} else {
|
||||
$this->setPassword("");
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->db->select("radreply","*","username='$username'");
|
||||
if($this->db->num_rows($res)) {
|
||||
while($radreply = $this->db->fetch_object($res)) {
|
||||
$this->Attributes[$radreply->attribute] = $radreply->value;
|
||||
}
|
||||
}
|
||||
|
||||
$res = $this->db->select("radusergroup", "*", "username='$username'");
|
||||
if($this->db->num_rows($res)) {
|
||||
$radusergroup = $this->db->fetch_object($res);
|
||||
$this->Usergroup = $radusergroup->groupname;
|
||||
}
|
||||
|
||||
$res = $this->db->select("radnascheck", "*", "username='$username'");
|
||||
if($this->db->num_rows($res)) {
|
||||
while($nascheck = $this->db->fetch_object($res)) {
|
||||
$this->AllowedNas[] = $nascheck->nasname;
|
||||
}
|
||||
}
|
||||
|
||||
$this->Info = new RadiusDB_UserInfo($username);
|
||||
|
||||
$this->_oldUsergroup = $this->Usergroup;
|
||||
$this->_oldChecks = $this->Checks;
|
||||
$this->_oldAttributes = $this->Attributes;
|
||||
$this->_oldAllowedNas = $this->AllowedNas;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getCheck($name) {
|
||||
if(isset($this->Checks[$name])) {
|
||||
return $this->Checks[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAttribute($name) {
|
||||
if(isset($this->Attributes[$name])) {
|
||||
return $this->Attributes[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setCheck($name, $value) {
|
||||
$this->Checks[$name] = $value;
|
||||
}
|
||||
|
||||
public function setAttribute($name, $value) {
|
||||
$this->Attributes[$name] = $value;
|
||||
}
|
||||
|
||||
public function getPassword() {
|
||||
return $this->getCheck("Cleartext-Password");
|
||||
}
|
||||
public function setPassword($password) {
|
||||
$this->setCheck("Cleartext-Password", $password);
|
||||
}
|
||||
public function getUsergroup() {
|
||||
return $this->Usergroup;
|
||||
}
|
||||
public function setUsergroup($groupname) {
|
||||
$this->Usergroup = $groupname;
|
||||
}
|
||||
|
||||
public function isNasAllowed($nas_ip) {
|
||||
if(in_array($nas_ip, $this->AllowedNas)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addAllowedNas($nas_ip) {
|
||||
if(!in_array($nas_ip, $this->AllowedNas,true)) {
|
||||
$this->AllowedNas[] = $nas_ip;
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAllowedNas($nas_ip) {
|
||||
if(in_array($nas_ip, $this->AllowedNas, true) !== false) {
|
||||
unset($this->AllowedNas[array_search($nas_ip, $this->AllowedNas)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function unset($name) {
|
||||
if($name == "usergroup") {
|
||||
$this->Usergroup = false;
|
||||
}
|
||||
|
||||
if(isset($this->Checks[$name])) {
|
||||
unset($this->Checks[$name]);
|
||||
return true;
|
||||
}
|
||||
if(isset($this->Attributes[$name])) {
|
||||
unset($this->Attributes[$name]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if(!$this->username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$username = $this->username;
|
||||
|
||||
$error = false;
|
||||
|
||||
$this->db->query("START TRANSACTION"); // XXX should be put moved to a FronkDB function
|
||||
// check queries
|
||||
foreach($this->Checks as $attribute => $value) {
|
||||
if(isset($this->_oldChecks[$attribute])) {
|
||||
if(!$this->db->update("radcheck", ['value' => $value], "username='$username' AND attribute='$attribute'")) {
|
||||
$error = true;
|
||||
}
|
||||
} else {
|
||||
if(!$this->db->insert("radcheck", ['username' => $username, 'attribute' => $attribute, 'op' => $this->checkop, 'value' => $value])) {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// attribute queries
|
||||
foreach($this->Attributes as $attribute => $value) {
|
||||
if(isset($this->_oldAttributes[$attribute])) {
|
||||
if(!$this->db->update("radreply", ['value' => $value], "username='$username' AND attribute='$attribute'")) {
|
||||
$error = true;
|
||||
}
|
||||
} else {
|
||||
if(!$this->db->insert("radreply", ['username' => $username, 'attribute' => $attribute, 'op' => $this->attribop, 'value' => $value])) {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update usergroup
|
||||
if($this->Usergroup) {
|
||||
if($this->_oldUsergroup) {
|
||||
if(!$this->db->update("radusergroup", ['groupname' => $this->Usergroup], "username='$username'")) {
|
||||
$error = true;
|
||||
}
|
||||
} else {
|
||||
if(!$this->db->insert("radusergroup", ['username' => $username, 'groupname' => $this->Usergroup, 'priority' => 1])) {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update Nascheck
|
||||
foreach($this->AllowedNas as $nas) {
|
||||
if(!in_array($nas, $this->_oldAllowedNas, true)) {
|
||||
|
||||
if(!$this->db->insert("radnascheck", ['username' => $username, 'nasname' => $nas])) {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// delete attributes
|
||||
|
||||
foreach($this->_oldChecks as $attribute => $value) {
|
||||
if(!isset($this->Checks[$attribute])) {
|
||||
if(!$this->db->delete("radcheck", "username='$username' AND attribute='$attribute'")) {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->_oldAttributes as $attribute => $old) {
|
||||
if(!isset($this->Attributes[$attribute])) {
|
||||
if(!$this->db->delete("radreply", "username='$username' AND attribute='$attribute'")) {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->_oldUsergroup && !$this->Usergroup) {
|
||||
if(!$this->db->delete("radusergroup", "username='$username'")) {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->_oldAllowedNas as $oldnas) {
|
||||
if(!in_array($oldnas, $this->AllowedNas, true)) {
|
||||
if(!$this->db->delete("radnascheck", "username='$username' AND nasname='$oldnas'")) {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($error) {
|
||||
$this->db->query("ROLLBACK");
|
||||
return false;
|
||||
} else {
|
||||
$this->db->query("COMMIT");
|
||||
}
|
||||
|
||||
// reinitialize _old* values
|
||||
$this->_oldUsergroup = $this->Usergroup;
|
||||
$this->_oldChecks = $this->Checks;
|
||||
$this->_oldAttributes = $this->Attributes;
|
||||
$this->_oldAllowedNas = $this->AllowedNas;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function __get($name) {
|
||||
if($name === "username") {
|
||||
return $this->username;
|
||||
}
|
||||
if(in_array($name, array_keys($this->Checks))) {
|
||||
return $this->getCheck($name);
|
||||
}
|
||||
if(in_array($name, array_keys($this->Attributes))) {
|
||||
return $this->getAttribute($name);
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return (string) $this->username;
|
||||
}
|
||||
}
|
||||
43
lib/RadiusDB/UserInfo.php
Normal file
43
lib/RadiusDB/UserInfo.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class RadiusDB_UserInfo {
|
||||
private $id;
|
||||
private $Username;
|
||||
private $custnum;
|
||||
private $custnume;
|
||||
private $ContractUp;
|
||||
private $ContractDown;
|
||||
private $Duraction;
|
||||
private $Info;
|
||||
private $Wifikey;
|
||||
private $ont_sn;
|
||||
|
||||
public function __construct($db) {
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function load($username) {
|
||||
if(!$username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->username = $username;
|
||||
|
||||
$res = $this->db->select("Hotspot_Usersettings", "*", "Username='$username'");
|
||||
if($this->db->num_rows($res)) {
|
||||
$rad = $this->db->fetch_object($res);
|
||||
|
||||
$this->id = $rad->id;
|
||||
$this->Username = $rad->Username;
|
||||
$this->Custnum = $rad->Custnum;
|
||||
$this->Custnume = $rad->Custnume;
|
||||
$this->ContractUp = $rad->ContratUp;
|
||||
$this->ContractDown = $rad->ContractDown;
|
||||
$this->Duration = $rad->Duration;
|
||||
$this->Info = $rad->Info;
|
||||
$this->Wifikey = $rad->Wifikey;
|
||||
$this->ont_sn = $rad->ont_sn;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user