Merge branch 'master' into fronkdev
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class ADBHausnummer extends mfBaseModel {
|
||||
protected $forcestr = ["oaid","adrcd","subcd","extref","hausnummer","zusatz","grund_nr","gdaeigenschaft","meridian","rollout_info","rimo_fcp_name"];
|
||||
private $netzgebiet;
|
||||
private $ortschaft;
|
||||
private $strasse;
|
||||
@@ -85,28 +86,22 @@ class ADBHausnummer extends mfBaseModel {
|
||||
}
|
||||
|
||||
if($name == "netzgebiet") {
|
||||
$this->netzgebiet = new ADBNetzgebiet($this->netzgebiet_id);
|
||||
$this->netzgebiet = mfValuecache::singleton()->getMfObject("ADBNetzgebiet", $this->netzgebiet_id);
|
||||
return $this->netzgebiet;
|
||||
}
|
||||
|
||||
if($name == "ortschaft") {
|
||||
$this->ortschaft = new ADBOrtschaft($this->ortschaft_id);
|
||||
$this->ortschaft = mfValuecache::singleton()->getMfObject("ADBOrtschaft", $this->ortschaft_id);
|
||||
return $this->ortschaft;
|
||||
}
|
||||
|
||||
if($name == "strasse") {
|
||||
$this->strasse = new ADBStrasse($this->strasse_id);
|
||||
$this->strasse = mfValuecache::singleton()->getMfObject("ADBStrasse", $this->strasse_id);
|
||||
return $this->strasse;
|
||||
}
|
||||
|
||||
if($name == "plz") {
|
||||
$this->plz = mfValuecache::singleton()->get("adbplz-".$this->plz_id);
|
||||
if($this->plz === null) {
|
||||
$this->plz = new ADBPlz($this->plz_id);
|
||||
if($this->plz->id) {
|
||||
mfValuecache::singleton()->set("adplz-".$this->plz_id, $this->plz);
|
||||
}
|
||||
}
|
||||
$this->plz = mfValuecache::singleton()->getMfObject("ADBPlz", $this->plz_id);
|
||||
return $this->plz;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +71,8 @@ class ADBHausnummerModel {
|
||||
ORDER BY netzgebiet_id,Gemeinde.id,ortschaft_id,strasse_id,LENGTH(hausnummer), hausnummer
|
||||
LIMIT 1";
|
||||
|
||||
//mfLoghandler::singleton()->debug($where);
|
||||
$res = $db->select("Hausnummer", "*", "$where ORDER BY strasse_id,hausnummer LIMIT 1");
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new ADBHausnummer($data);
|
||||
@@ -135,7 +135,6 @@ class ADBHausnummerModel {
|
||||
WHERE $where
|
||||
ORDER BY netzgebiet_id,Gemeinde.id,ortschaft_id,strasse_id,LENGTH(hausnummer), hausnummer";
|
||||
|
||||
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'];
|
||||
@@ -312,9 +311,9 @@ class ADBHausnummerModel {
|
||||
}
|
||||
|
||||
if(array_key_exists("hausnummer%", $filter)) {
|
||||
$hausnummer = FronkDB::singleton()->escape($filter['hausnummer']);
|
||||
$hausnummer = FronkDB::singleton()->escape($filter['hausnummer%']);
|
||||
if($hausnummer) {
|
||||
$where .= " AND Hausnummer.`hausnummer` like '%$hausnummer%'";
|
||||
$where .= " AND Hausnummer.`hausnummer` like '$hausnummer%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,15 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
$bcode = $this->getProperty("hausnummer")->oaid;
|
||||
//var_dump($bcode);
|
||||
if(!$bcode) {
|
||||
return false;
|
||||
$hausnummer = $this->getProperty("hausnummer");
|
||||
$hausnummer->oaid = $hausnummer->getNewOAID();
|
||||
if(!$hausnummer->oaid) {
|
||||
return false;
|
||||
}
|
||||
if(!$hausnummer->save()) {
|
||||
return false;
|
||||
}
|
||||
$bcode = $hausnummer->oaid;
|
||||
}
|
||||
|
||||
$codes = [];
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class ADBWohneinheitController extends mfBaseController {
|
||||
|
||||
}
|
||||
@@ -3,6 +3,9 @@
|
||||
class AddressDB {
|
||||
private $db;
|
||||
private $log;
|
||||
|
||||
public $validation_error = [];
|
||||
|
||||
public static $wohneinheit_query = "select `Netzgebiet`.`id` AS `netzgebiet_id`,
|
||||
`Netzgebiet`.`name` AS `netzgebiet`,
|
||||
`Netzgebiet`.`extref` AS `netzgebiet_extref`,
|
||||
@@ -204,6 +207,20 @@ class AddressDB {
|
||||
$hausnummer_data['strasse_id'] = $strasse->id;
|
||||
$hausnummer_data['hausnummer'] = $data['hausnummer'];
|
||||
$hausnummer_data['grund_nr'] = $data['grund_nr'];
|
||||
$hausnummer_data['gdaeigenschaft'] = $data['gdaeigenschaft'];
|
||||
$hausnummer_data['meridian'] = $data['meridian'];
|
||||
$hausnummer_data['rw'] = ($data['rw']) ? str_replace(",",".", $data['rw']) : null;
|
||||
$hausnummer_data['hw'] = ($data['hw']) ? str_replace(",",".", $data['hw']) : null;
|
||||
|
||||
if($data['rw'] && !is_numeric($hausnummer_data['rw'])) {
|
||||
$hausnummer_data['rw'] = null;
|
||||
$this->validation_error[] = "RW nicht gespeichert: Keine Zahl";
|
||||
}
|
||||
if($data['hw'] && !is_numeric($hausnummer_data['hw'])) {
|
||||
$hausnummer_data['hw'] = null;
|
||||
$this->validation_error[] = "HW nicht gespeichert: Keine Zahl";
|
||||
}
|
||||
|
||||
$hausnummer_data['gps_lat'] = ($data['gps_lat']) ? str_replace(",", ".", $data['gps_lat']) : null;
|
||||
$hausnummer_data['gps_long'] = ($data['gps_long']) ? str_replace(",", ".", $data['gps_long']) : null;
|
||||
$hausnummer_data['rollout'] = (trim($data['rollout'])) ? trim($data['rollout']) : null;
|
||||
|
||||
@@ -18,14 +18,22 @@ class AddressDBController extends mfBaseController {
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("AddressDB/Index");
|
||||
|
||||
$rfilter = $this->request->filter;
|
||||
iF(!is_array($rfilter)) {
|
||||
$rfilter = [];
|
||||
if($this->request->resetFilter) {
|
||||
unset($_SESSION[MFAPPNAME.'-AddressDB-filter']);
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $rfilter);
|
||||
|
||||
$filter = $this->getPreparedFilter($rfilter);
|
||||
$filter = [];
|
||||
if(is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
$_SESSION[MFAPPNAME.'-AddressDB-filter'] = $filter;
|
||||
} else {
|
||||
if(array_key_exists(MFAPPNAME.'-AddressDB-filter', $_SESSION) && count($_SESSION[MFAPPNAME.'-AddressDB-filter'])) {
|
||||
$filter = $_SESSION[MFAPPNAME.'-AddressDB-filter'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $filter);
|
||||
$filter = $this->getPreparedFilter($filter);
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
@@ -73,7 +81,7 @@ class AddressDBController extends mfBaseController {
|
||||
$this->layout()->set("my_networks", ADBNetzgebietModel::getAll());
|
||||
$this->layout()->set("my_adb_networks", $my_adb_networks);
|
||||
//var_dump($addressdb_filter);exit;
|
||||
|
||||
//var_dump($addressdb_filter);exit;
|
||||
if($filter['netzgebiet_id'] === "null") {
|
||||
$addressdb_filter['netzgebiet_id'] = 0;
|
||||
$pagination['maxItems'] = ADBHausnummerModel::count($addressdb_filter);
|
||||
@@ -107,13 +115,18 @@ class AddressDBController extends mfBaseController {
|
||||
unset($filter['street']);
|
||||
}
|
||||
|
||||
if(array_key_exists("hausnummer", $filter) && $filter['hausnummer']) {
|
||||
$new_filter['hausnummer%'] = $filter['hausnummer'];
|
||||
unset($filter['hausnummer']);
|
||||
}
|
||||
|
||||
if(array_key_exists("adrcd", $filter) && $filter['adrcd']) {
|
||||
$new_filter['adrcd%'] = $filter['adrcd'];
|
||||
unset($filter['adrcd']);
|
||||
}
|
||||
|
||||
if(array_key_exists("oaid", $filter) && $filter['oaid']) {
|
||||
$new_filter['oaid%'] = $filter['oaid'];
|
||||
$new_filter['oaid%'] = "%".$filter['oaid'];
|
||||
unset($filter['oaid']);
|
||||
}
|
||||
|
||||
@@ -149,6 +162,7 @@ class AddressDBController extends mfBaseController {
|
||||
unset($filter['ortschaft_id']);
|
||||
}
|
||||
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
if(strlen($value) > 0) $new_filter[$name] = $value;
|
||||
@@ -188,7 +202,6 @@ class AddressDBController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
$this->layout()->setFlash("Adresse nicht gefunden", "error");
|
||||
@@ -231,12 +244,11 @@ class AddressDBController extends mfBaseController {
|
||||
}
|
||||
|
||||
$required = ['netzgebiet_id','strasse','hausnummer','plz','ortschaft','gemeinde'];
|
||||
foreach(['adrcd','extref','netzgebiet_id','strasse','hausnummer','plz','ortschaft','gemeinde','grund_nr','gps_lat','gps_long','unit_count'] as $field) {
|
||||
foreach(['adrcd','extref','netzgebiet_id','strasse','hausnummer','plz','ortschaft','gemeinde','grund_nr','gdaeigenschaft','meridian','rw','hw','gps_lat','gps_long','unit_count'] as $field) {
|
||||
if(in_array($field, $required)) {
|
||||
if(!trim($r->$field)) {
|
||||
$this->layout()->setFlash("'".ucfirst($field)."' darf nicht leer sein!", "error");
|
||||
return $this->addAction();
|
||||
//$this->redirect("AddressDB", $mode, ['id' => $id]);
|
||||
}
|
||||
}
|
||||
$address_data[$field] = $this->db()->escape(trim($r->$field));
|
||||
@@ -289,39 +301,61 @@ class AddressDBController extends mfBaseController {
|
||||
|
||||
$adb = new AddressDB();
|
||||
$hausnummer_id = $adb->createUpdateHausnummer($address_data);
|
||||
if(is_array($adb->validation_error) && count($adb->validation_error)) {
|
||||
$this->layout()->setFlash(implode("<br />\n",$adb->validation_error), "warning");
|
||||
}
|
||||
if(!$hausnummer_id) {
|
||||
$this->layout()->setFlash("Fehler beim Erstellen der Adresse!", "error");
|
||||
return $this->addAction();
|
||||
//$this->redirect("AddressDB");
|
||||
}
|
||||
|
||||
if($mode == "add") {
|
||||
|
||||
|
||||
/*
|
||||
* Wohneinheiten erstellen
|
||||
*/
|
||||
if(is_numeric($r->unit_count) && $r->unit_count) {
|
||||
$unit_count = $r->unit_count;
|
||||
$hausnummer = new ADBHausnummer($hausnummer_id);
|
||||
|
||||
/*
|
||||
* Wohneinheiten erstellen
|
||||
*/
|
||||
if($r->unit_count > 0) {
|
||||
for($i = 1; $i <= $r->unit_count; $i++) {
|
||||
$unit = ADBWohneinheitModel::create([
|
||||
'hausnummer_id' => $hausnummer_id,
|
||||
'num' => $i,
|
||||
]);
|
||||
$unit_id = $unit->save();
|
||||
if(!$unit_id) {
|
||||
$this->log->debug(__CLASS__."::".__METHOD__.": Cannot save Woneinheit");
|
||||
continue;
|
||||
$existing_units_count = ADBWohneinheitModel::count(['hausnummer_id' => $hausnummer->id]);
|
||||
//var_dump($hausnummer,$existing_units_count);exit;
|
||||
if($existing_units_count < $unit_count) {
|
||||
$new_units_count = $unit_count - $existing_units_count;
|
||||
$last_unit_num = 0;
|
||||
|
||||
foreach(ADBWohneinheitModel::search(['hausnummer_id' => $hausnummer->id]) as $tmp_unit) {
|
||||
if($tmp_unit->num > $last_unit_num) {
|
||||
$last_unit_num = $tmp_unit->num;
|
||||
}
|
||||
$unit->oaid = $unit->getNewOAID();
|
||||
$unit->save();
|
||||
}
|
||||
|
||||
// create wohneinheiten
|
||||
for($i = 1; $i <= $new_units_count; $i++) {
|
||||
$num = $last_unit_num + $i;
|
||||
//echo "$existing_units_count create wohneinheit $num\n";
|
||||
$unit_data = [
|
||||
'hausnummer_id' => $hausnummer->id,
|
||||
'num' => $num,
|
||||
];
|
||||
$wohneinheit = ADBWohneinheitModel::create($unit_data);
|
||||
$wohneinheit_id = $wohneinheit->save();
|
||||
if(!$wohneinheit_id) {
|
||||
$this->layout()->setFlash("Fehler beim Erstellen einer Wohneinheit!", "warning");
|
||||
return $this->addAction();
|
||||
}
|
||||
$wohneinheit->oaid = $wohneinheit->getNewOAID();
|
||||
$wohneinheit->save();
|
||||
$w++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$qs = http_build_query(['filter' => ['oaid' => $hausnummer->oaid]]);
|
||||
//$qs = http_build_query(['filter' => ['oaid' => $hausnummer->oaid]]);
|
||||
//var_dump($qs);exit;
|
||||
$this->layout()->setFlash("Adresse erfolgreich gespeichert", "success");
|
||||
$this->redirect("AddressDB", "Index", $qs);
|
||||
$this->redirect("AddressDB");
|
||||
|
||||
}
|
||||
|
||||
@@ -547,6 +581,7 @@ class AddressDBController extends mfBaseController {
|
||||
foreach($units as $unit) {
|
||||
$u = [];
|
||||
$u['id'] = $unit->id;
|
||||
$u['extref'] = $unit->extref;
|
||||
$u['zip'] = $unit->hausnummer->plz->plzstring;
|
||||
$u['city'] = $unit->hausnummer->ortschaft->name;
|
||||
$u['street'] = $unit->hausnummer->strasse->name;
|
||||
|
||||
@@ -31,6 +31,13 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
protected function authenticated() {
|
||||
$campaignApiusers = PreordercampaignApiuserModel::search(["worker_id" => $this->me->id]);
|
||||
|
||||
if(!$campaignApiusers) {
|
||||
$cau = new PreordercampaignApiuser();
|
||||
$cau->preordercampaign_id = 1;
|
||||
$campaignApiusers = [$cau];
|
||||
}
|
||||
|
||||
|
||||
foreach($campaignApiusers as $campaignApiuser) {
|
||||
$campaign = new Preordercampaign($campaignApiuser->preordercampaign_id);
|
||||
if($campaign) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
class DeviceApicontroller extends mfBaseApicontroller
|
||||
{
|
||||
protected function init()
|
||||
{
|
||||
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$this->addRoute("/device/getDevices", "getDevices", "GET");
|
||||
|
||||
}
|
||||
|
||||
protected function getDevices()
|
||||
{
|
||||
$devices = DeviceModel::getAll();
|
||||
foreach ($devices as $key => $device) {
|
||||
$deviceReturn[$key]['id'] = $device->id;
|
||||
$deviceReturn[$key]['name'] = $device->name;
|
||||
$deviceReturn[$key]['ip'] = $device->ip;
|
||||
$deviceReturn[$key]['serial'] = $device->serial;
|
||||
$deviceReturn[$key]['manufactor'] = $device->devicetype->devicemanufactor->name;
|
||||
}
|
||||
|
||||
return mfResponse::Ok($deviceReturn);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -311,6 +311,13 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$unit_search[$key] = trim($this->post['address']->$key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ignore unit_string if the specific fields were provided
|
||||
if($unit_search['block'] || $unit_search['stiege'] || $unit_search['stock'] || $unit_search['tuer']) {
|
||||
unset($unit_search['unit_string']);
|
||||
}
|
||||
|
||||
if($zusatz) {
|
||||
$unit_search['zusatz'] = $zusatz;
|
||||
}
|
||||
@@ -334,6 +341,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
*/
|
||||
$where = "1=1 ";
|
||||
foreach($address_search as $field => $value) {
|
||||
if($field == "ortschaft" || $field == "gemeinde") continue;
|
||||
$where .= " AND `$field` = '$value'";
|
||||
}
|
||||
|
||||
@@ -346,7 +354,35 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
if(!$this->db()->num_rows($res)) {
|
||||
return mfResponse::NotFound(['message' => "Adresse nicht gefunden"]);
|
||||
// try with Ortschaft in front of strasse (liezen gwr issue)
|
||||
$where = "1=1 ";
|
||||
foreach($address_search as $field => $value) {
|
||||
if($field == "ortschaft" || $field == "gemeinde") continue;
|
||||
|
||||
if($field == "strasse") {
|
||||
$prefix = ($address_search['ortschaft']) ? $address_search['ortschaft'] : $address_search['gemeinde'];
|
||||
if(strpos($value, "$prefix ") === 0) {
|
||||
$str = substr($value, strlen($prefix)+1);
|
||||
} else {
|
||||
$str = $value;
|
||||
}
|
||||
$where .= " AND `strasse` = '$str'";
|
||||
} else {
|
||||
$where .= " AND `$field` = '$value'";
|
||||
}
|
||||
}
|
||||
|
||||
// filter salesclusters
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(',', $this->filter_salescluster_ids).")";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM view_hausnummer WHERE $where";
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
if(!$this->db()->num_rows($res)) {
|
||||
return mfResponse::NotFound(['message' => "Adresse nicht gefunden"]);
|
||||
}
|
||||
}
|
||||
|
||||
$address = $this->db()->fetch_object($res);
|
||||
@@ -592,6 +628,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get units excluding unavailable units
|
||||
$where = "hausnummer_id=".$address->hausnummer_id;
|
||||
$where .= " AND ( block = '' OR block IS NULL)";
|
||||
|
||||
@@ -411,10 +411,10 @@ class BuildingController extends mfBaseController {
|
||||
$building_term['status'] = "none";
|
||||
|
||||
//$this->log->debug("building status: ".print_r($building->status,true));
|
||||
if($term->status->code == TT_TERMSTATUS_CONNECTED) {
|
||||
if($term->status->code >= TT_TERMSTATUS_CONNECTED) {
|
||||
$building_term['status'] = "connected";
|
||||
$data->status = "connected";
|
||||
} elseif($building->status->code == TT_BUILDINGSTATUS_CONNECTED) {
|
||||
} elseif($building->status->code >= TT_BUILDINGSTATUS_CONNECTED) {
|
||||
$building_term['status'] = "pipework-done";
|
||||
if($data->status != "connected") $data->status = "pipework-done";
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
class Contract extends mfBaseModel {
|
||||
protected $forcestr = ["product_name","product_info","matchcode"];
|
||||
|
||||
private $owner;
|
||||
private $billingaddress;
|
||||
private $product;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class ContractconfigController extends mfBaseController {
|
||||
public $hook_errors;
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
@@ -68,13 +69,23 @@ class ContractconfigController extends mfBaseController {
|
||||
|
||||
$error_items = [];
|
||||
|
||||
$old_values = [];
|
||||
|
||||
foreach($r->itemvalues as $item_id => $itemvalue) {
|
||||
//var_dump($item_id, $itemvalue); continue;
|
||||
|
||||
$item = new ContractconfigItem($item_id);
|
||||
if(!$item->id) {
|
||||
$this->log->warn("Tried to save non-existant ContractconfigItem $item_id");
|
||||
continue;
|
||||
}
|
||||
$item->setContractId($contract_id);
|
||||
|
||||
/*if(!array_key_exists($item->name, $old_values)) {
|
||||
$old_values[$item->name] = [];
|
||||
}*/
|
||||
$old_values[$item->name] = $item->getValue();
|
||||
|
||||
if(!$item->value->set($itemvalue)) {
|
||||
$error_items[$item->id] = $item->name;
|
||||
continue;
|
||||
@@ -85,6 +96,7 @@ class ContractconfigController extends mfBaseController {
|
||||
return $this->editAction();
|
||||
}
|
||||
}
|
||||
//exit;
|
||||
|
||||
if(count($error_items)) {
|
||||
$this->layout()->set("error_items", array_keys($error_items));
|
||||
@@ -94,12 +106,74 @@ class ContractconfigController extends mfBaseController {
|
||||
}
|
||||
|
||||
// run custom productgroup hooks
|
||||
|
||||
if(!$this->runAfterSaveHooks($contract)) {
|
||||
$errors = [];
|
||||
foreach($this->hook_errors as $item_name => $item_errors) {
|
||||
if(is_array($item_errors) && count($item_errors)) {
|
||||
foreach($item_errors as $error_string) {
|
||||
$errors[] = "[$item_name] $error_string";
|
||||
}
|
||||
//var_dump($old_values[$item_name]);
|
||||
// on error restore old values
|
||||
if(array_key_exists($item_name, $old_values)) {
|
||||
$old_item = ContractconfigItemModel::getFirst(["name" => $item_name]);
|
||||
$old_item->setContractId($contract_id);
|
||||
$old_item->value->set($old_values[$item_name]);
|
||||
$old_item->value->save();
|
||||
//var_dump($old_item->value->json);exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//var_dump($errors);exit;
|
||||
|
||||
|
||||
$this->layout()->setFlash(implode("<br />", $errors), "error");
|
||||
$this->redirect("Contract", "view", ['id' => $contract_id]);
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Konfiguration gespeichert", "success");
|
||||
$this->redirect("Contract", "view", ['id' => $contract_id]);
|
||||
|
||||
}
|
||||
|
||||
private function runAfterSaveHooks(Contract $contract) {
|
||||
if(!$contract || !$contract->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$folderpath = APPDIR."/Contractconfig/hooks/";
|
||||
$dir = opendir($folderpath);
|
||||
while($filename = readdir($dir)) {
|
||||
if(substr($filename, 0, 1) == ".") {
|
||||
continue;
|
||||
}
|
||||
if($filename == "Contractconfig_Hook.php") continue;
|
||||
if(substr($filename, -4) != ".php") continue;
|
||||
|
||||
$hook_type = basename($filename, ".php");
|
||||
$classname = "Contractconfig_Hook_$hook_type";
|
||||
$hook_class_filename = $folderpath.$filename;
|
||||
require_once $hook_class_filename;
|
||||
|
||||
if(!class_exists($classname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hook = new $classname($contract);
|
||||
if($hook->isResponsible()) {
|
||||
$this->log->debug("Running {$classname}->afterSave() for Contract id ".$contract->id);
|
||||
$hook->afterSave();
|
||||
if($hook->errors) {
|
||||
$this->hook_errors = $hook->errors;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
abstract class Contractconfig_Hook {
|
||||
protected $log;
|
||||
|
||||
protected $required_product_attributes = [];
|
||||
protected $contract;
|
||||
protected $items;
|
||||
@@ -17,11 +19,13 @@ abstract class Contractconfig_Hook {
|
||||
abstract public function beforeSave();
|
||||
abstract public function afterSave();
|
||||
|
||||
abstract public function beforeDelete();
|
||||
abstract public function afterDelete();
|
||||
abstract public function beforeCancel();
|
||||
abstract public function afterCancel();
|
||||
|
||||
|
||||
public function __construct(Contract $contract) {
|
||||
$this->log = mfLoghandler::singleton();
|
||||
|
||||
$this->contract = $contract;
|
||||
|
||||
if($contract->product) {
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__."/Contractconfig_Hook.php";
|
||||
|
||||
/*
|
||||
* Contractconfig Hooks for
|
||||
*/
|
||||
class Contractconfig_Hook_Voicenumberblock extends Contractconfig_Hook {
|
||||
protected $required_product_attributes = ["needs_number"];
|
||||
private $voip_routing;
|
||||
|
||||
|
||||
private $create_numbers = [];
|
||||
/*
|
||||
* Checks to determine if class needs to work on contract.
|
||||
*/
|
||||
@@ -24,101 +29,152 @@ class Contractconfig_Hook_Voicenumberblock extends Contractconfig_Hook {
|
||||
}
|
||||
|
||||
public function init() {
|
||||
$this->errors["voicenumberblock_voicenumber"] = [];
|
||||
|
||||
|
||||
// get voip routing for number
|
||||
$this->getVoipRouting();
|
||||
|
||||
}
|
||||
|
||||
private function getVoipRouting() {
|
||||
if(is_array($this->contract->configvalues)) {
|
||||
// look in contract config
|
||||
if(array_key_exists("voip_routing",$this->contract->configvalues) && $this->contract->configvalues['voip_routing']->value->string) {
|
||||
$this->voip_routing = $this->contract->configvalues['voip_routing']->value->string;
|
||||
} else {
|
||||
// else take first value (default)
|
||||
$typedata = $this->voip_routing = $this->contract->configvalues['voip_routing']->getTypedataArray();
|
||||
$typedata = $this->contract->configvalues['voip_routing']->getTypedataArray();
|
||||
$this->voip_routing = $typedata[0];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->voip_routing;
|
||||
}
|
||||
|
||||
public function beforeSave() {
|
||||
|
||||
return $this->checkNewNumbers();
|
||||
}
|
||||
|
||||
public function afterSave() {
|
||||
// check if number was saved
|
||||
if(!array_key_exists("voicenumber", $this->configitems)) {
|
||||
echo "configitem voicenumber does not exists\n";
|
||||
return true;
|
||||
}
|
||||
echo "configitem voicenumber exists\n";
|
||||
$item = $this->configitems['voicenumber'];
|
||||
$number = $item->value->string;
|
||||
if(!$number) {
|
||||
echo "Keine nummer gespeichert\n";
|
||||
return true;
|
||||
}
|
||||
echo "Nummer: $number\n";
|
||||
$this->checkNewNumbers();
|
||||
// load voip routing again, in case it changed with the same config update
|
||||
$this->getVoipRouting();
|
||||
|
||||
// check if Voicenumber exists
|
||||
$voicenumberblock = Voicenumberblock::findBlock($number);
|
||||
if(!$voicenumberblock) {
|
||||
$this->errors[] = "Ungültige Rufnummer: Kein aktiver Rufnummernblock gefunden";
|
||||
echo "Voicenumberblock für $number nicht gefunden\n";
|
||||
}
|
||||
|
||||
if(!$voicenumberblock->isNumberInBlock($number)) {
|
||||
$this->errors[] = "Ungültige Rufnummer: Bitte Rufnummernlänge kontrollieren! Block erlaubt ".$voicenumberblock->first ." bis ".$voicenumberblock->last;
|
||||
echo "Voicenumber $number not in Block ".$voicenumberblock->prefix."\n";
|
||||
if(count($this->errors["voicenumberblock_voicenumber"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$voicenumber = VoicenumberModel::getFirst(['number' => $number]);
|
||||
if($voicenumber) {
|
||||
// check if number belongs to another contract
|
||||
if($voicenumber->contract_id) {
|
||||
if($voicenumber->contract_id == $this->contract->id) {
|
||||
// belongs to our contract already => no changes needed
|
||||
return true;
|
||||
foreach($this->create_numbers as $voicenumberblock_id => $numbers) {
|
||||
foreach($numbers as $number){
|
||||
$voicenumber = VoicenumberModel::getFirst(['number' => $number]);
|
||||
|
||||
if(!$voicenumber) {
|
||||
$this->log->debug("creating voicenumber $number in block ".$voicenumberblock->prefix);
|
||||
$voicenumber = VoicenumberModel::create([
|
||||
'voicenumberblock_id' => $voicenumberblock_id,
|
||||
"contract_id" => $this->contract->id,
|
||||
'active' => 1,
|
||||
'activated_date' => date('U'),
|
||||
'routing' => $this->voip_routing,
|
||||
'number' => $number,
|
||||
'disabled' => 0
|
||||
]);
|
||||
if(!$voicenumber->save()) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Error saving new number $number";
|
||||
}
|
||||
}
|
||||
$this->errors[] = "Ungültige Rufnummer: Rufnummer gehört zu bestehendem contract ".$voicenumber->contract_id;
|
||||
return false;
|
||||
}
|
||||
// check if number is locked
|
||||
if($voicenumber->disabled) {
|
||||
$this->errors[] = "Ungültige Rufnummer: Rufnummer ist gesperrt ".$voicenumber->contract_id;
|
||||
return false;
|
||||
}
|
||||
// check if number was ported out
|
||||
if($voicenumber->ported_out) {
|
||||
$this->errors[] = "Ungültige Rufnummer: Rufnummer wurde rausportiert ".$voicenumber->contract_id;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
echo "creating voicenumber $number in block ".$voicenumberblock->prefix."\n";
|
||||
$voicenumber = VoicenumberModel::create([
|
||||
'voicenumberblock_id' => $voicenumberblock->id,
|
||||
"contract_id" => $this->contract->id,
|
||||
'active' => 1,
|
||||
'activated_date' => date('U'),
|
||||
'routing' => $this->voip_routing,
|
||||
'number' => $number,
|
||||
'disabled' => 0
|
||||
]);
|
||||
if(!$voicenumber->save()) {
|
||||
echo "Error saving new number\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(count($this->errors["voicenumberblock_voicenumber"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Check if contract was canceled, then set lock and lock_reason to reserved
|
||||
* => should go into beforeCancel event
|
||||
*/
|
||||
public function checkNewNumbers() {
|
||||
$this->log->debug(":: In Contractconfig_Hook_Voicenumberblock->afterSave()");
|
||||
// check if number was saved
|
||||
if(!array_key_exists("voicenumber", $this->configitems)) {
|
||||
$this->log->debug("configitem voicenumber does not exists");
|
||||
return true;
|
||||
}
|
||||
|
||||
$item = $this->configitems['voicenumber'];
|
||||
//var_dump($item);exit;
|
||||
if($item->value->json) {
|
||||
$numbers = json_decode($item->value->json);
|
||||
}
|
||||
|
||||
if(!is_array($numbers) || !count($numbers)) {
|
||||
return true;
|
||||
}
|
||||
foreach($numbers as $number) {
|
||||
if(!$number) {
|
||||
$this->log->debug("Keine nummer gespeichert");
|
||||
continue;
|
||||
}
|
||||
$this->log->debug("Nummer: $number");
|
||||
|
||||
// check if Voicenumber exists
|
||||
$voicenumberblock = Voicenumberblock::findBlock($number);
|
||||
if(!$voicenumberblock) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Kein aktiver Rufnummernblock gefunden";
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$voicenumberblock->isNumberInBlock($number)) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Bitte Rufnummernlänge kontrollieren! Block erlaubt ".$voicenumberblock->first ." bis ".$voicenumberblock->last;
|
||||
continue;
|
||||
}
|
||||
|
||||
$voicenumber = VoicenumberModel::getFirst(['number' => $number]);
|
||||
if($voicenumber) {
|
||||
// check if number belongs to another contract
|
||||
if($voicenumber->contract_id) {
|
||||
if($voicenumber->contract_id == $this->contract->id) {
|
||||
// belongs to our contract already => no changes needed
|
||||
continue;
|
||||
}
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Rufnummer gehört zu bestehendem contract ".$voicenumber->contract_id;
|
||||
continue;
|
||||
}
|
||||
// check if number is locked
|
||||
if($voicenumber->disabled) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Rufnummer ist gesperrt ".$voicenumber->contract_id;
|
||||
continue;
|
||||
}
|
||||
// check if number was ported out
|
||||
if($voicenumber->ported_out) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Rufnummer wurde rausportiert ".$voicenumber->contract_id;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if(!array_key_exists($voicenumberblock->id, $this->create_numbers)) {
|
||||
$this->create_numbers[$voicenumberblock->id] = [];
|
||||
}
|
||||
$this->create_numbers[$voicenumberblock->id][] = $number;
|
||||
}
|
||||
}
|
||||
|
||||
if(count($this->errors["voicenumberblock_voicenumber"])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function beforeDelete() {
|
||||
public function beforeCancel() {
|
||||
|
||||
}
|
||||
|
||||
public function afterDelete() {
|
||||
public function afterCancel() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@ class ContractconfigItem extends mfBaseModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($this->multiple) {
|
||||
return json_decode($value->json);
|
||||
}
|
||||
if($this->type == "int") {
|
||||
return $value->int;
|
||||
}
|
||||
@@ -56,7 +59,7 @@ class ContractconfigItem extends mfBaseModel {
|
||||
$value->contract_id = $this->contract_id;
|
||||
$value->create_by = $me->id;
|
||||
}
|
||||
|
||||
//var_dump($value);exit;
|
||||
$this->value = $value;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ class ContractconfigItemController extends mfBaseController {
|
||||
$item_data['name'] = $r->name;
|
||||
$item_data['displayname'] = $r->displayname;
|
||||
$item_data['description'] = $r->description;
|
||||
$item_data['multiple'] = ($r->multiple) ? 1 : 0;
|
||||
|
||||
$item_data['typedata'] = "";
|
||||
$item_data['pattern'] = "";
|
||||
@@ -54,7 +55,7 @@ class ContractconfigItemController extends mfBaseController {
|
||||
$item_data['type'] = "decimal";
|
||||
break;
|
||||
default:
|
||||
$this->layout()->setFlash("Ungültiger Datentyp!");
|
||||
$this->layout()->setFlash("Ungültiger Datentyp!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ class ContractconfigItemController extends mfBaseController {
|
||||
$item_id = $item->save();
|
||||
|
||||
if(!$item_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern!");
|
||||
$this->layout()->setFlash("Fehler beim Speichern!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
@@ -79,5 +80,35 @@ class ContractconfigItemController extends mfBaseController {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function deleteAction() {
|
||||
$r = $this->request;
|
||||
|
||||
$id = $r->id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
$this->layout()->setFlash("Config Element nicht gefunden!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
$item = new ContractconfigItem($id);
|
||||
if(!$item->id) {
|
||||
$this->layout()->setFlash("Config Element nicht gefunden!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
if(ContractconfigValueModel::getFirst(["item_id" => $id])) {
|
||||
$this->layout()->setFlash("Config Element kann nicht gelöscht werden, das es in Verwendung ist!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
if(!$item->delete()) {
|
||||
$this->layout()->setFlash("Fehler beim Löschen!", "error");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Config Element erfolgreich gelöscht!", "success");
|
||||
$this->redirect("Contractconfiggroup");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ class ContractconfigItemModel {
|
||||
public $order;
|
||||
public $contractconfiggroup_id;
|
||||
public $type;
|
||||
public $multiple;
|
||||
public $name;
|
||||
public $displayname;
|
||||
public $description;
|
||||
@@ -53,7 +54,7 @@ class ContractconfigItemModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
@@ -4,20 +4,36 @@ class ContractconfigValue extends mfBaseModel {
|
||||
private $item;
|
||||
|
||||
public function set($new_value) {
|
||||
$item = $this->getProperty("item");
|
||||
// explicitly load item, because we might not have an id yet
|
||||
$item = new ContractconfigItem($this->item_id);
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->edit_by = $me->id;
|
||||
|
||||
if($new_value === null || strlen($new_value) == 0) {
|
||||
if(!is_array($new_value) && ($new_value === null || strlen($new_value) == 0)) {
|
||||
$this->int = null;
|
||||
$this->number = null;
|
||||
$this->string = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if($item->type == "int") {
|
||||
|
||||
if($item->multiple) {
|
||||
if(!is_array($new_value)) {
|
||||
$new_value = [$new_vale];
|
||||
}
|
||||
|
||||
$json_array = [];
|
||||
|
||||
foreach($new_value as $v) {
|
||||
if($v) {
|
||||
$json_array[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$this->json = json_encode($json_array);
|
||||
} elseif($item->type == "int") {
|
||||
if(!is_numeric($new_value)) return false;
|
||||
$this->int = $new_value;
|
||||
} elseif($item->type == "decimal") {
|
||||
|
||||
@@ -1,266 +1,290 @@
|
||||
<?php
|
||||
|
||||
class CpeprovisioningController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("Cpeprovisioning/Index");
|
||||
$cpeproducts = [];
|
||||
|
||||
$this->layout->set("filter", $this->request->filter);
|
||||
$filter = $this->getPreparedFilter($this->request->filter);
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 20;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
$order_filter = $filter;
|
||||
//var_dump($filter);exit;
|
||||
/*
|
||||
* Get orderproducts in need of sending a CPE
|
||||
*/
|
||||
//var_dump($order_filter);exit;
|
||||
$orders = OrderModel::search($order_filter);
|
||||
|
||||
foreach($orders as $order) {
|
||||
if($order_filter["hide_delayed_finish"] && $order->finish_after) {
|
||||
// show at most 4 weeks before finish_after date
|
||||
//$after_ts = Layout::dateToInt($order->finish_after);
|
||||
if($order->finish_after > date("U") + (31 * 86400)) {
|
||||
$this->log->debug("Before 4 weeks before finish_after oid ".$order->id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($order->terminations) && count($order->terminations)) {
|
||||
if(!$order->cpeprovisioning_enabled && $order->terminations[0]->status->code < TT_TERMSTATUS_CONNECTED) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($order->products as $orderproduct) {
|
||||
if($orderproduct->cpeprovisioning->routerconfig_finished == 1) {
|
||||
if(!$filter['routerconfig_finished']) continue;
|
||||
} else {
|
||||
if($filter['routerconfig_finished']) continue;
|
||||
}
|
||||
$product = $orderproduct->product;
|
||||
|
||||
if(is_array($product->attributes) && count($product->attributes)) {
|
||||
// filter out products without bras_type
|
||||
if(array_key_exists("bras_type", $product->attributes) && $product->attributes['bras_type']->value) {
|
||||
$cpeproducts[] = $orderproduct;
|
||||
} else {
|
||||
$this->log->debug("no bras_type oid ".$order->id);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// ignore products without attributes
|
||||
$this->log->debug("no attributes oid ".$order->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->set("products", $cpeproducts);
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(!is_array($filter)) $filter = [];
|
||||
|
||||
if(array_key_exists("hide_delayed_finish", $filter)) {
|
||||
if($filter["hide_delayed_finish"] == "1") {
|
||||
$new_filter["hide_delayed_finish"] = true;
|
||||
} else {
|
||||
$new_filter["hide_delayed_finish"] = false;
|
||||
}
|
||||
unset($filter["hide_delayed_finish"]);
|
||||
} else {
|
||||
$new_filter["hide_delayed_finish"] = true;
|
||||
}
|
||||
|
||||
if(array_key_exists("routerconfig_finished", $filter)) {
|
||||
if($filter["routerconfig_finished"] == "1") {
|
||||
$new_filter["routerconfig_finished"] = true;
|
||||
$new_filter["hide_delayed_finish"] = false;
|
||||
} else {
|
||||
$new_filter["routerconfig_finished"] = false;
|
||||
$order_filter["finish_date"] = null;
|
||||
}
|
||||
unset($filter["routerconfig_finished"]);
|
||||
} else {
|
||||
$new_filter["routerconfig_finished"] = false;
|
||||
$order_filter["finish_date"] = null;
|
||||
}
|
||||
|
||||
$new_filter['upgrade'] = 0;
|
||||
|
||||
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
//var_dump($new_filter);exit;
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r);exit;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$cpeprovisioning = new Cpeprovisioning($id);
|
||||
if(!$cpeprovisioning->id) {
|
||||
$this->layout()->setFlash("Eintrag nicht gefunden", "error");
|
||||
$this->redirect("Cpeprovisioning");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$order_id = $r->order_id;
|
||||
$termination_id = $r->termination_id;
|
||||
if(!(is_numeric($termination_id) && $termination_id > 0) && !(is_numeric($order_id) && $order_id > 0)) {
|
||||
$this->layout()->setFlash("Anschluss oder Bestellung nicht gefunden", "error");
|
||||
$this->redirect("Cpeprovisioning");
|
||||
}
|
||||
|
||||
$orderproduct = OrderProductModel::getFirst(["order_id" => $order_id, "termination_id" => $termination_id]);
|
||||
if(!$orderproduct) {
|
||||
$this->layout()->setFlash("Anschluss gehört nicht zur Bestellung", "error");
|
||||
$this->redirect("Cpeprovisioning");
|
||||
}
|
||||
|
||||
$prov_data = [];
|
||||
$prov_data["termination_id"] = ($r->termination_id) ? $r->termination_id : null;
|
||||
$prov_data["order_id"] = $r->order_id;
|
||||
$prov_data["orderproduct_id"] = $r->orderproduct_id;
|
||||
$prov_data["routerconfig_finished"] = ($r->routerconfig_finished) ? 1 : 0;
|
||||
$prov_data["routertype"] = $r->routertype;
|
||||
$prov_data["shipping"] = ($r->shipping) ? 1 : 0;
|
||||
$prov_data["wifi_ssid"] = $r->wifi_ssid;
|
||||
$prov_data["wifi_pass"] = $r->wifi_pass;
|
||||
$prov_data["mac"] = $r->mac;
|
||||
$prov_data["vlan_public"] = (strlen($r->vlan_public)) ? $r->vlan_public : null;
|
||||
$prov_data["vlan_nat"] = (strlen($r->vlan_nat)) ? $r->vlan_nat : null;
|
||||
$prov_data["vlan_ipv6"] = (strlen($r->vlan_ipv6)) ? $r->vlan_ipv6 : null;
|
||||
$prov_data["ship_weight"] = (strlen($r->ship_weight)) ? $r->ship_weight : null;
|
||||
$prov_data["ship_length"] = (strlen($r->ship_length)) ? $r->ship_length : null;
|
||||
$prov_data["ship_width"] = (strlen($r->ship_width)) ? $r->ship_width : null;
|
||||
$prov_data["ship_height"] = (strlen($r->ship_height)) ? $r->ship_height : null;
|
||||
$prov_data["note"] = $r->note;
|
||||
|
||||
$prov_data["edit_by"] = $this->me->id;
|
||||
|
||||
if($mode == "add") {
|
||||
$prov_data["create_by"] = $this->me->id;
|
||||
$cpeprovisioning = CpeprovisioningModel::create($prov_data);
|
||||
} else {
|
||||
$cpeprovisioning->update($prov_data);
|
||||
}
|
||||
|
||||
//var_dump($prov_data);exit;
|
||||
$new_id = $cpeprovisioning->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->redirect("Cpeprovisioning");
|
||||
}
|
||||
|
||||
// saved successfully, if routerconfig_finished make Journal entry in Order
|
||||
|
||||
if($cpeprovisioning->routerconfig_finished) {
|
||||
$order_product = new OrderProduct($r->orderproduct_id);
|
||||
|
||||
if($cpeprovisioning->shipping) {
|
||||
$text = "CPE zu Produkt \"".$order_product->product->name."\" zum Versand vorbereitet.\n\n";
|
||||
} else {
|
||||
$text = "CPE zu Produkt \"".$order_product->product->name."\" vorbereitet für Techniker zur Vorortinstallation.\n\n";
|
||||
}
|
||||
$text .= "Router: ".$cpeprovisioning->routertype."\n";
|
||||
$text .= "Zugangstyp: ".$order_product->product->attributes['bras_type']->value."\n";
|
||||
if($cpeprovisioning->vlan_public) {
|
||||
$text .= "Vlan Public: ".$cpeprovisioning->vlan_public."\n";
|
||||
}
|
||||
if($cpeprovisioning->vlan_nat) {
|
||||
$text .= "Vlan NAT: ".$cpeprovisioning->vlan_nat."\n";
|
||||
}
|
||||
if($cpeprovisioning->vlan_ipv6) {
|
||||
$text .= "Vlan IPv6: ".$cpeprovisioning->vlan_ipv6."\n";
|
||||
}
|
||||
class CpeprovisioningController extends mfBaseController
|
||||
{
|
||||
protected function init()
|
||||
{
|
||||
$this->needlogin = true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me", $me);
|
||||
|
||||
$journal = new OrderJournal();
|
||||
$journal->order_id = $order_id;
|
||||
$journal->text = $text;
|
||||
$journal->create_by = $this->me->id;
|
||||
$journal->edit_by = $this->me->id;
|
||||
|
||||
$journal_id = $journal->save();
|
||||
if(!$journal_id) {
|
||||
$this->layout()->setFlash("Konnte nicht ins Bestelljournal schreiben!", "warning");
|
||||
} else {
|
||||
$cpeprovisioning->order_journal_id = $journal_id;
|
||||
$cpeprovisioning->save();
|
||||
}
|
||||
}
|
||||
|
||||
// save ONT sn
|
||||
if($r->ont_sn) {
|
||||
$termination = new Termination($termination_id);
|
||||
$orig_sn = $termination->getWorkflowvalue("ont_sn", "string");
|
||||
|
||||
if($orig_sn === null) {
|
||||
|
||||
$sn_item = WorkflowitemModel::getFirst(["name" => "ont_sn", "object_type" => "termination"]);
|
||||
//var_dump($sn_item);exit;
|
||||
//var_dump(mfValuecache::singleton()->get("wfItemvalue-item-".$sn_item->id."-object-".$termination_id));exit;
|
||||
if(!$sn_item->id) {
|
||||
$this->log->error("ont_sn workflow item not found");
|
||||
} else {
|
||||
$sn_item->setObjectId($termination_id);
|
||||
$termination->workflowitems["ont_sn"] = $sn_item;
|
||||
//$sn_item->value->setValue($r->ont_sn);
|
||||
|
||||
//$sn_item->value->save();
|
||||
if (!$me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($r->ont_sn != $orig_sn) {
|
||||
$termination->workflowitems["ont_sn"]->value->setValue($r->ont_sn);
|
||||
$termination->workflowitems["ont_sn"]->value->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$query = [];
|
||||
if(is_numeric($this->request->s) && $this->request->s > 0) {
|
||||
$query["s"] = $this->request->s;
|
||||
|
||||
protected function indexAction()
|
||||
{
|
||||
$cpecounter = 0;
|
||||
$r = $this->request;
|
||||
$page = $r->s;
|
||||
|
||||
$this->layout()->setTemplate("Cpeprovisioning/Index");
|
||||
$cpeproducts = [];
|
||||
|
||||
$this->layout->set("filter", $this->request->filter);
|
||||
$filter = $this->getPreparedFilter($this->request->filter);
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = $page;
|
||||
$pagination['count'] = 25;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
$order_filter = $filter;
|
||||
//var_dump($filter);exit;
|
||||
/*
|
||||
* Get orderproducts in need of sending a CPE
|
||||
*/
|
||||
//var_dump($order_filter);exit;
|
||||
$orders = OrderModel::search($order_filter);
|
||||
$orderproductsprefetch = OrderProductModel::precache();
|
||||
|
||||
|
||||
foreach ($orders as $order) {
|
||||
if ($order_filter["hide_delayed_finish"] && $order->finish_after) {
|
||||
|
||||
// show at most 4 weeks before finish_after date
|
||||
//$after_ts = Layout::dateToInt($order->finish_after);
|
||||
if ($order->finish_after > date("U") + (31 * 86400)) {
|
||||
$this->log->debug("Before 4 weeks before finish_after oid " . $order->id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (is_array($orderproductsprefetch['terminations'][$order->id]) && count($orderproductsprefetch['terminations'][$order->id])) {
|
||||
|
||||
if (!$order->cpeprovisioning_enabled && $orderproductsprefetch['terminations'][$order->id][0]['statuscode'] < TT_TERMSTATUS_CONNECTED) {
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($orderproductsprefetch[$order->id] as $orderproduct) {
|
||||
|
||||
|
||||
if ($orderproduct['routerconfig_finished'] == 1) {
|
||||
if (!$filter['routerconfig_finished']) continue;
|
||||
} else {
|
||||
if ($filter['routerconfig_finished']) continue;
|
||||
}
|
||||
|
||||
|
||||
$productattributes = $orderproduct['attributes'];
|
||||
|
||||
|
||||
if (is_array($productattributes) && count($productattributes)) {
|
||||
// filter out products without bras_type
|
||||
|
||||
if (array_key_exists("bras_type", $productattributes) && $productattributes) {
|
||||
$pagination['maxItems']++;
|
||||
if ($pagination['maxItems'] >= $pagination['start']+1 && $pagination['maxItems'] <= $pagination['start'] + $pagination['count']) {
|
||||
$cpeproducts[] = OrderProductModel::getOne($orderproduct['id']);
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->log->debug("no bras_type oid " . $order->id);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// ignore products without attributes
|
||||
$this->log->debug("no attributes oid " . $order->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
$this->layout()->set("products", $cpeproducts);
|
||||
}
|
||||
if (is_array($this->request->filter)) {
|
||||
$query["filter"] = $this->request->filter;
|
||||
|
||||
private function getPreparedFilter($filter)
|
||||
{
|
||||
$new_filter = [];
|
||||
|
||||
if (!is_array($filter)) $filter = [];
|
||||
|
||||
if (array_key_exists("hide_delayed_finish", $filter)) {
|
||||
if ($filter["hide_delayed_finish"] == "1") {
|
||||
$new_filter["hide_delayed_finish"] = true;
|
||||
} else {
|
||||
$new_filter["hide_delayed_finish"] = false;
|
||||
}
|
||||
unset($filter["hide_delayed_finish"]);
|
||||
} else {
|
||||
$new_filter["hide_delayed_finish"] = true;
|
||||
}
|
||||
|
||||
if (array_key_exists("routerconfig_finished", $filter)) {
|
||||
if ($filter["routerconfig_finished"] == "1") {
|
||||
$new_filter["routerconfig_finished"] = true;
|
||||
$new_filter["hide_delayed_finish"] = false;
|
||||
} else {
|
||||
$new_filter["routerconfig_finished"] = false;
|
||||
$order_filter["finish_date"] = null;
|
||||
}
|
||||
unset($filter["routerconfig_finished"]);
|
||||
} else {
|
||||
$new_filter["routerconfig_finished"] = false;
|
||||
$order_filter["finish_date"] = null;
|
||||
}
|
||||
|
||||
$new_filter['upgrade'] = 0;
|
||||
|
||||
|
||||
foreach ($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
//var_dump($new_filter);exit;
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
$qs = http_build_query($query);
|
||||
|
||||
$this->layout()->setFlash("Eintrag erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Cpeprovisioning","Index", $qs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function saveAction()
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r);exit;
|
||||
if (is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$cpeprovisioning = new Cpeprovisioning($id);
|
||||
if (!$cpeprovisioning->id) {
|
||||
$this->layout()->setFlash("Eintrag nicht gefunden", "error");
|
||||
$this->redirect("Cpeprovisioning");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$order_id = $r->order_id;
|
||||
$termination_id = $r->termination_id;
|
||||
if (!(is_numeric($termination_id) && $termination_id > 0) && !(is_numeric($order_id) && $order_id > 0)) {
|
||||
$this->layout()->setFlash("Anschluss oder Bestellung nicht gefunden", "error");
|
||||
$this->redirect("Cpeprovisioning");
|
||||
}
|
||||
|
||||
$orderproduct = OrderProductModel::getFirst(["order_id" => $order_id, "termination_id" => $termination_id]);
|
||||
if (!$orderproduct) {
|
||||
$this->layout()->setFlash("Anschluss gehört nicht zur Bestellung", "error");
|
||||
$this->redirect("Cpeprovisioning");
|
||||
}
|
||||
|
||||
$prov_data = [];
|
||||
$prov_data["termination_id"] = ($r->termination_id) ? $r->termination_id : null;
|
||||
$prov_data["order_id"] = $r->order_id;
|
||||
$prov_data["orderproduct_id"] = $r->orderproduct_id;
|
||||
$prov_data["routerconfig_finished"] = ($r->routerconfig_finished) ? 1 : 0;
|
||||
$prov_data["routertype"] = $r->routertype;
|
||||
$prov_data["shipping"] = ($r->shipping) ? 1 : 0;
|
||||
$prov_data["wifi_ssid"] = $r->wifi_ssid;
|
||||
$prov_data["wifi_pass"] = $r->wifi_pass;
|
||||
$prov_data["mac"] = $r->mac;
|
||||
$prov_data["vlan_public"] = (strlen($r->vlan_public)) ? $r->vlan_public : null;
|
||||
$prov_data["vlan_nat"] = (strlen($r->vlan_nat)) ? $r->vlan_nat : null;
|
||||
$prov_data["vlan_ipv6"] = (strlen($r->vlan_ipv6)) ? $r->vlan_ipv6 : null;
|
||||
$prov_data["ship_weight"] = (strlen($r->ship_weight)) ? $r->ship_weight : null;
|
||||
$prov_data["ship_length"] = (strlen($r->ship_length)) ? $r->ship_length : null;
|
||||
$prov_data["ship_width"] = (strlen($r->ship_width)) ? $r->ship_width : null;
|
||||
$prov_data["ship_height"] = (strlen($r->ship_height)) ? $r->ship_height : null;
|
||||
$prov_data["note"] = $r->note;
|
||||
|
||||
$prov_data["edit_by"] = $this->me->id;
|
||||
|
||||
if ($mode == "add") {
|
||||
$prov_data["create_by"] = $this->me->id;
|
||||
$cpeprovisioning = CpeprovisioningModel::create($prov_data);
|
||||
} else {
|
||||
$cpeprovisioning->update($prov_data);
|
||||
}
|
||||
|
||||
//var_dump($prov_data);exit;
|
||||
$new_id = $cpeprovisioning->save();
|
||||
if (!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->redirect("Cpeprovisioning");
|
||||
}
|
||||
|
||||
// saved successfully, if routerconfig_finished make Journal entry in Order
|
||||
|
||||
if ($cpeprovisioning->routerconfig_finished) {
|
||||
$order_product = new OrderProduct($r->orderproduct_id);
|
||||
|
||||
if ($cpeprovisioning->shipping) {
|
||||
$text = "CPE zu Produkt \"" . $order_product->product->name . "\" zum Versand vorbereitet.\n\n";
|
||||
} else {
|
||||
$text = "CPE zu Produkt \"" . $order_product->product->name . "\" vorbereitet für Techniker zur Vorortinstallation.\n\n";
|
||||
}
|
||||
$text .= "Router: " . $cpeprovisioning->routertype . "\n";
|
||||
$text .= "Zugangstyp: " . $order_product->product->attributes['bras_type']->value . "\n";
|
||||
if ($cpeprovisioning->vlan_public) {
|
||||
$text .= "Vlan Public: " . $cpeprovisioning->vlan_public . "\n";
|
||||
}
|
||||
if ($cpeprovisioning->vlan_nat) {
|
||||
$text .= "Vlan NAT: " . $cpeprovisioning->vlan_nat . "\n";
|
||||
}
|
||||
if ($cpeprovisioning->vlan_ipv6) {
|
||||
$text .= "Vlan IPv6: " . $cpeprovisioning->vlan_ipv6 . "\n";
|
||||
}
|
||||
|
||||
$journal = new OrderJournal();
|
||||
$journal->order_id = $order_id;
|
||||
$journal->text = $text;
|
||||
$journal->create_by = $this->me->id;
|
||||
$journal->edit_by = $this->me->id;
|
||||
|
||||
$journal_id = $journal->save();
|
||||
if (!$journal_id) {
|
||||
$this->layout()->setFlash("Konnte nicht ins Bestelljournal schreiben!", "warning");
|
||||
} else {
|
||||
$cpeprovisioning->order_journal_id = $journal_id;
|
||||
$cpeprovisioning->save();
|
||||
}
|
||||
}
|
||||
|
||||
// save ONT sn
|
||||
if ($r->ont_sn) {
|
||||
$termination = new Termination($termination_id);
|
||||
$orig_sn = $termination->getWorkflowvalue("ont_sn", "string");
|
||||
|
||||
if ($orig_sn === null) {
|
||||
|
||||
$sn_item = WorkflowitemModel::getFirst(["name" => "ont_sn", "object_type" => "termination"]);
|
||||
//var_dump($sn_item);exit;
|
||||
//var_dump(mfValuecache::singleton()->get("wfItemvalue-item-".$sn_item->id."-object-".$termination_id));exit;
|
||||
if (!$sn_item->id) {
|
||||
$this->log->error("ont_sn workflow item not found");
|
||||
} else {
|
||||
$sn_item->setObjectId($termination_id);
|
||||
$termination->workflowitems["ont_sn"] = $sn_item;
|
||||
//$sn_item->value->setValue($r->ont_sn);
|
||||
|
||||
//$sn_item->value->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($r->ont_sn != $orig_sn) {
|
||||
$termination->workflowitems["ont_sn"]->value->setValue($r->ont_sn);
|
||||
$termination->workflowitems["ont_sn"]->value->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$query = [];
|
||||
if (is_numeric($this->request->s) && $this->request->s > 0) {
|
||||
$query["s"] = $this->request->s;
|
||||
}
|
||||
if (is_array($this->request->filter)) {
|
||||
$query["filter"] = $this->request->filter;
|
||||
}
|
||||
|
||||
$qs = http_build_query($query);
|
||||
|
||||
$this->layout()->setFlash("Eintrag erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Cpeprovisioning", "Index", $qs);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,8 +11,13 @@ class DashboardController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
if($this->me->is("preorderfront")) {
|
||||
$this->redirect("Preorder");
|
||||
}
|
||||
|
||||
$newss = NewsModel::getAll();
|
||||
$this->layout()->set("newss", $newss);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
class DeviceController extends mfBaseController
|
||||
{
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->needlogin = true;
|
||||
@@ -42,7 +41,9 @@ class DeviceController extends mfBaseController
|
||||
}
|
||||
|
||||
$this->layout()->setTemplate("Device/Detail");
|
||||
$devicesconfig = DeviceModel::getconifg($id);
|
||||
$devices = DeviceModel::getOne($id);
|
||||
$this->layout()->set("devicesconfig", $devicesconfig);
|
||||
$this->layout()->set("devices", $devices);
|
||||
|
||||
}
|
||||
@@ -60,13 +61,13 @@ class DeviceController extends mfBaseController
|
||||
$id = $this->request->id;
|
||||
|
||||
if (!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Gerät nicht gefunden", "error");
|
||||
$this->layout()->setFlash("Device nicht gefunden", "error");
|
||||
$this->redirect("Device");
|
||||
}
|
||||
|
||||
$device = new Device($id);
|
||||
if ($device->id != $id) {
|
||||
$this->layout()->setFlash("Gerät nicht gefunden", "error");
|
||||
$this->layout()->setFlash("Device nicht gefunden", "error");
|
||||
$this->redirect("Device");
|
||||
}
|
||||
|
||||
@@ -93,14 +94,44 @@ class DeviceController extends mfBaseController
|
||||
$data = [];
|
||||
$data['name'] = trim($r->name);
|
||||
$data['devicetype_id'] = $r->devicetype_id;
|
||||
if (trim($r->pop_id)=="0") {
|
||||
if (trim($r->pop_id) == "0") {
|
||||
$data['pop_id'] = NULL;
|
||||
} else {
|
||||
$data['pop_id'] = $r->pop_id;
|
||||
}
|
||||
if (!(trim($r->addr_street))) {
|
||||
$data['addr_street'] = NULL;
|
||||
$data['addr_number'] = NULL;
|
||||
$data['addr_extended'] = NULL;
|
||||
$data['addr_zip'] = NULL;
|
||||
$data['addr_city'] = NULL;
|
||||
} else {
|
||||
$data['addr_street'] = $r->addr_street;
|
||||
$data['addr_number'] = $r->addr_number;
|
||||
$data['addr_extended'] = $r->addr_extended;
|
||||
$data['addr_zip'] = $r->addr_zip;
|
||||
$data['addr_city'] = $r->addr_city;
|
||||
}
|
||||
if (!trim($r->gps_lat) || !trim($r->gps_long)) {
|
||||
$data['gps_lat'] = NULL;
|
||||
$data['gps_long'] = NULL;
|
||||
} else {
|
||||
$data['gps_lat'] = $r->gps_lat;
|
||||
$data['gps_long'] = $r->gps_long;
|
||||
}
|
||||
$data['ip'] = $r->ip;
|
||||
$data['mac'] = $r->mac;
|
||||
$data['serial'] = $r->serial;
|
||||
if (empty(trim($r->price))) {
|
||||
$data['price'] = "0.00";
|
||||
} else {
|
||||
$data['price'] = $r->price;
|
||||
}
|
||||
if (empty(trim($r->power))) {
|
||||
$data['power'] = "0.0";
|
||||
} else {
|
||||
$data['power'] = $r->power;
|
||||
}
|
||||
$data['comment'] = $r->comment;
|
||||
$ipv4_validation_regex = "/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/";
|
||||
|
||||
@@ -133,11 +164,8 @@ class DeviceController extends mfBaseController
|
||||
// exit;
|
||||
$id = $device->save();
|
||||
|
||||
if (!$id) {
|
||||
$this->layout()->setFlash("Device konnte nicht angelegt werden", "error");
|
||||
$this->redirect("Device");
|
||||
}
|
||||
$returnUrl="Device";
|
||||
|
||||
$returnUrl = "Device";
|
||||
$returnAction = "Index";
|
||||
$returnVariables = array();
|
||||
$returnAnker = "";
|
||||
@@ -163,6 +191,15 @@ class DeviceController extends mfBaseController
|
||||
}
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
$returnVariables['id'] = $r->id;
|
||||
if ($mode == "edit") {
|
||||
$this->layout()->setFlash("Device konnte nicht gespeichert werden", "error");
|
||||
} else if ($mode = "add") {
|
||||
$this->layout()->setFlash("Device konnte nicht angelegt werden", "error");
|
||||
}
|
||||
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
|
||||
}
|
||||
|
||||
if ($mode == "edit") {
|
||||
$this->layout()->setFlash("Device erfolgreich geändert", "success");
|
||||
@@ -171,4 +208,75 @@ class DeviceController extends mfBaseController
|
||||
}
|
||||
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
|
||||
}
|
||||
|
||||
protected function apiAction()
|
||||
{
|
||||
if (!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
$format = $this->request->format;
|
||||
$filename = $this->request->filename;
|
||||
$id = $this->request->id;
|
||||
$ip = $this->request->ip;
|
||||
|
||||
$data = [];
|
||||
|
||||
switch ($do) {
|
||||
case "getconfig":
|
||||
$return = $this->getConfig($id, $format, $filename);
|
||||
break;
|
||||
case "createconfig":
|
||||
$return = $this->createConfig($ip);
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function deleteAction()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
$device = new Device($id);
|
||||
if (!$device->id || $device->id != $id) {
|
||||
$this->layout()->setFlash("Gerätetyp nicht gefunden.", "error");
|
||||
$this->redirect("Device");
|
||||
}
|
||||
|
||||
$device->delete();
|
||||
$this->redirect("Device");
|
||||
}
|
||||
|
||||
private function getConfig($id, $format, $filename)
|
||||
{
|
||||
$configDownload = DeviceModel::getconifgdownload($id, $format);
|
||||
//
|
||||
|
||||
// header('Content-Type: application/octet-stream');
|
||||
header('Content-Type: text/plain');
|
||||
header('Content-disposition: attachment; filename="' . $filename . '"');
|
||||
echo $configDownload;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
private function createConfig($ip)
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
$createConfig = DeviceModel::configcreate($ip);
|
||||
if ($createConfig->success === "true") {
|
||||
$this->layout()->setFlash("Backup wurde erfolgreich erstellt", "success");
|
||||
} elseif (!TT_MBI_API_ENABLE) {
|
||||
$this->layout()->setFlash("Backup konnte nicht erstellt werden. <b>Fehler</b>: Schnittstellenserver wurde vom Admin deaktiviert.", "error");
|
||||
} else {
|
||||
$this->layout()->setFlash("Backup konnte nicht erstellt werden. <b>Fehler</b>: " . $createConfig->error, "error");
|
||||
}
|
||||
$returnUrl = "Device";
|
||||
$returnAction = "Detail";
|
||||
$returnVariables['id'] = $id;
|
||||
return $this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,27 +5,34 @@ class DeviceModel
|
||||
public $name = null;
|
||||
public $ip = null;
|
||||
public $mac = null;
|
||||
public $serial= null;
|
||||
public $comment= null;
|
||||
public $serial = null;
|
||||
public $comment = null;
|
||||
public $devicetype_id = null;
|
||||
public $pop_id = null;
|
||||
|
||||
|
||||
public $addr_street = null;
|
||||
public $addr_number = null;
|
||||
public $addr_extended = null;
|
||||
public $addr_zip = null;
|
||||
public $gps_lat = null;
|
||||
public $addr_city = null;
|
||||
public $gps_long = null;
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function find($data) {
|
||||
public static function find($data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function create(Array $data) {
|
||||
public static function create(array $data)
|
||||
{
|
||||
$model = new Device();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
if(substr($field, 0, 5) == "vlan_" && !$value) {
|
||||
foreach ($data as $field => $value) {
|
||||
if (property_exists(get_called_class(), $field)) {
|
||||
if (substr($field, 0, 5) == "vlan_" && !$value) {
|
||||
$model->$field = null;
|
||||
continue;
|
||||
}
|
||||
@@ -34,45 +41,47 @@ class DeviceModel
|
||||
}
|
||||
|
||||
$me = mfValuecache::singleton()->get("me");
|
||||
if(!$me) {
|
||||
if (!$me) {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
mfValuecache::singleton()->set("me", $me);
|
||||
}
|
||||
|
||||
if($model->create_by === null) {
|
||||
if ($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
if ($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
public static function getOne($id)
|
||||
{
|
||||
if (!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Device", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Device($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
public static function getAll()
|
||||
{
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Device", "*");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
$items[] = new Device($data);
|
||||
}
|
||||
}
|
||||
@@ -80,15 +89,16 @@ class DeviceModel
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst()
|
||||
{
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Device", "*", "$where ORDER BY name, network_id");
|
||||
if($db->num_rows($res)) {
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Device($data);
|
||||
if($item->id) {
|
||||
if ($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
@@ -97,26 +107,28 @@ class DeviceModel
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
public static function search($filter)
|
||||
{
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Device", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
$items[] = new Device($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
private static function getSqlFilter($filter)
|
||||
{
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("pop_id", $filter)) {
|
||||
if (array_key_exists("pop_id", $filter)) {
|
||||
$popid = $filter['pop_id'];
|
||||
if(is_numeric($popid)) {
|
||||
if (is_numeric($popid)) {
|
||||
$where .= " AND pop_id=$popid";
|
||||
}
|
||||
}
|
||||
@@ -124,4 +136,83 @@ class DeviceModel
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
public static function getconifg($id)
|
||||
{
|
||||
$response = "";
|
||||
if (TT_MBI_API_ENABLE) :
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => TT_MBI_API_URL . TT_MBI_API_VERSION . '/deviceconfigs/' . $id,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'GET',
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Authorization: Bearer ' . TT_MBI_API_KEY),
|
||||
));
|
||||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
endif;
|
||||
return json_decode($response);
|
||||
}
|
||||
|
||||
public static function getconifgdownload($id, $format)
|
||||
{
|
||||
$response = "";
|
||||
if (TT_MBI_API_ENABLE) :
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => TT_MBI_API_URL . TT_MBI_API_VERSION . '/deviceconfigsdownload/' . $id . '/' . $format,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'GET',
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Authorization: Bearer ' . TT_MBI_API_KEY),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
endif;
|
||||
return ($response);
|
||||
}
|
||||
|
||||
|
||||
public static function configcreate($ip)
|
||||
{
|
||||
$response = "";
|
||||
if (TT_MBI_API_ENABLE) :
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => TT_MBI_API_URL . TT_MBI_API_VERSION . '/deviceconfigscreate/' . $ip,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'GET',
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Authorization: Bearer ' . TT_MBI_API_KEY),
|
||||
));
|
||||
$response = curl_exec($curl);
|
||||
endif;
|
||||
return json_decode($response);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
class Devicemanufactor extends mfBaseModel
|
||||
{
|
||||
private $editor;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
class DevicemanufactorController extends mfBaseController
|
||||
{
|
||||
|
||||
@@ -68,6 +67,7 @@ class DevicemanufactorController extends mfBaseController
|
||||
|
||||
$data = [];
|
||||
$data['name'] = trim($r->name);
|
||||
$data['config_backup'] = trim($r->config_backup);
|
||||
|
||||
|
||||
if (!$data['name']) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
class DevicemanufactorModel {
|
||||
public $name = null;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ private $file;
|
||||
return $this->editor;
|
||||
}
|
||||
if($name == "histories") {
|
||||
$this->histories=FilestoreHistoryModel::search(["filestore_id="=>$this->id]);
|
||||
$this->histories=FilestoreHistoryModel::search(["filestore_id$filter"=>$this->id]);
|
||||
return $this->histories;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,26 +19,21 @@ class FilestoreController extends mfBaseController
|
||||
{
|
||||
$this->layout()->setTemplate("Filestore/Index");
|
||||
$files = FilestoreModel::getAll();
|
||||
$fileshistory = FilestoreHistoryModel::getAll();
|
||||
$networkaddress = NetworkAddressModel::getAll();
|
||||
|
||||
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 25;
|
||||
$pagination['maxItems'] = 0;
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
$pagination['maxItems'] = FilestoreModel::count();
|
||||
$this->layout()->set("files", $files);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
$this->layout()->set("fileshistory", $fileshistory);
|
||||
$this->layout()->set("networkaddresses", $networkaddress);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function addAction()
|
||||
{
|
||||
$this->layout()->set("networks", NetworkModel::getAll());
|
||||
$this->layout()->set("networkaddresses", NetworkAddressModel::getAll());
|
||||
$this->layout()->setTemplate("Filestore/Form");
|
||||
}
|
||||
|
||||
@@ -46,9 +41,12 @@ class FilestoreController extends mfBaseController
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
$editmode = $r->mode;
|
||||
|
||||
//var_dump($r->get());exit;
|
||||
if (is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
|
||||
$filestore = new Filestore($id);
|
||||
if (!$filestore->id) {
|
||||
$this->layout()->setFlash("Datei nicht gefunden", "error");
|
||||
@@ -59,23 +57,37 @@ class FilestoreController extends mfBaseController
|
||||
$dataHistory['name'] = $filestore->name;
|
||||
$dataHistory['description'] = $filestore->description;
|
||||
$dataHistory['file_id'] = $filestore->file_id;
|
||||
$dataHistory['network_id'] = $filestore->network_id;
|
||||
$dataHistory['filestore_id'] = $filestore->id;
|
||||
$dataHistory['create'] = $filestore->create;
|
||||
$dataHistory['create_by'] = $filestore->create_by;
|
||||
$dataHistory['edit'] = date("U");
|
||||
$dataHistory['edit_by'] = $filestore->edit_by;
|
||||
// $dataHistory['edit'] = date("U");
|
||||
$dataHistory['edit'] = $filestore->edit;
|
||||
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['name'] = trim($r->name);
|
||||
$data['description'] = trim($r->description);
|
||||
if ($editmode != "add-version" && $editmode != "edit-history") {
|
||||
$data['name'] = trim($r->name);
|
||||
$data['network_id'] = trim($r->network_id);
|
||||
}
|
||||
|
||||
if (!$data['name']) {
|
||||
$data['description'] = trim($r->description);
|
||||
$data['edit_by'] = trim($this->me->id);
|
||||
|
||||
if (!$data['name'] && $editmode != "add-version" && $editmode != "edit-history") {
|
||||
$this->layout()->setFlash("Name darf nicht leer sein", "error");
|
||||
$this->redirect("Filestore");
|
||||
}
|
||||
|
||||
if (!$data['network_id'] && $editmode != "add-version" && $editmode != "edit-history") {
|
||||
$this->layout()->setFlash("Netzgebiet darf nicht leer sein", "error");
|
||||
$this->redirect("Filestore");
|
||||
}
|
||||
|
||||
if (array_key_exists("filestore", $_FILES) && !$_FILES['filestore']['error']) {
|
||||
$upload_error = false;
|
||||
|
||||
@@ -113,14 +125,17 @@ class FilestoreController extends mfBaseController
|
||||
}
|
||||
$data['file_id'] = $file_id;
|
||||
|
||||
if ($mode == "edit") {
|
||||
|
||||
if ($mode == "edit" && $editmode == "add-version") {
|
||||
$fsh = FilestoreHistoryModel::create($dataHistory);
|
||||
}
|
||||
} else {
|
||||
if ($mode == "add") {
|
||||
if ($mode == "add" || $editmode == "add-version") {
|
||||
$this->layout()->setFlash("Keine Datei angegeben", "error");
|
||||
$this->redirect("Filestore", "add");
|
||||
if ($editmode == "add-version") {
|
||||
$this->redirect("Filestore");
|
||||
} else {
|
||||
$this->redirect("Filestore", "add");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -141,7 +156,7 @@ class FilestoreController extends mfBaseController
|
||||
$id = $filestore->save();
|
||||
|
||||
if (!$id) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen33", "error");
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "error");
|
||||
$this->redirect("Filestore");
|
||||
}
|
||||
if ($fsh) {
|
||||
@@ -155,19 +170,28 @@ class FilestoreController extends mfBaseController
|
||||
{
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r->get());exit;
|
||||
if ($r->mode) {
|
||||
$mode = $r->mode;
|
||||
} else {
|
||||
$mode = "";
|
||||
}
|
||||
if (!is_numeric($id) && $id < 1) {
|
||||
|
||||
$this->layout()->setFlash("Datei nicht gefunden", "error");
|
||||
$this->redirect("Filestore");
|
||||
|
||||
}
|
||||
$filestore = new Filestore($id);
|
||||
|
||||
$filestore = new Filestore($id);
|
||||
$filestorehistory = FilestoreHistoryModel::getAllhistory($id);;
|
||||
if (!$filestore->id) {
|
||||
$this->layout()->setFlash("Datei nicht gefunden", "error");
|
||||
$this->redirect("Filestore");
|
||||
}
|
||||
if ($mode) {
|
||||
$this->layout()->set("mode", $mode);
|
||||
}
|
||||
$this->layout()->set("filestorehistory", $filestorehistory);
|
||||
$this->layout()->set("file", $filestore);
|
||||
|
||||
return $this->addAction();
|
||||
@@ -187,11 +211,41 @@ class FilestoreController extends mfBaseController
|
||||
foreach ($filstore->histories as $h) {
|
||||
$h->file->delete();
|
||||
$h->delete();
|
||||
|
||||
}
|
||||
$filstore->file->delete();
|
||||
// check if Product is unused
|
||||
$filstore->delete();
|
||||
$this->redirect("Filestore");
|
||||
}
|
||||
|
||||
protected function apiAction()
|
||||
{
|
||||
if (!$this->me->is(["Admin", "netowner", "pipeplanner", "lineplanner", "pipeworker", "netoperator", "lineworker"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$id = $this->request->id;
|
||||
|
||||
$filestorehistory = FilestoreHistoryModel::getAllhistory($id);
|
||||
$counter = 0;
|
||||
foreach ($filestorehistory as $history) {
|
||||
$data[$counter]['id'] = $history->id;
|
||||
$data[$counter]['file_id'] = $history->data->file_id;
|
||||
$data[$counter]['name'] = $history->data->name;
|
||||
$data[$counter]['description'] = $history->data->description;
|
||||
$data[$counter]['workername'] = $history->data->workername;
|
||||
$data[$counter]['workerid'] = $history->data->workerid;
|
||||
$data[$counter]['edit'] = $history->edit;
|
||||
if (trim($this->me->id) == $history->data->workerid || $this->me->is(["Admin"])) {
|
||||
$data[$counter]['is_delete'] = 1;
|
||||
} else {
|
||||
$data[$counter]['is_delete'] = 0;
|
||||
}
|
||||
|
||||
|
||||
$counter++;
|
||||
}
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ class FilestoreModel
|
||||
{
|
||||
public $order_id;
|
||||
public $file_id;
|
||||
public $network_id;
|
||||
public $name;
|
||||
public $description;
|
||||
|
||||
@@ -54,11 +55,13 @@ class FilestoreModel
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
$sql = "SELECT Filestore.* FROM Filestore
|
||||
$sql = "SELECT Filestore.*,Network.name network,Network.id networkid FROM Filestore
|
||||
LEFT JOIN File ON (Filestore.file_id = File.id)
|
||||
LEFT JOIN Network ON (Filestore.network_id = Network.id)
|
||||
ORDER BY name";
|
||||
$res = $db->query($sql);
|
||||
if ($db->num_rows($res)) {
|
||||
|
||||
@@ -147,5 +147,19 @@ class FilestoreHistoryController extends mfBaseController
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
protected function deleteAction()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
|
||||
|
||||
$filstorehistory = new FilestoreHistory($id);
|
||||
|
||||
if (!$filstorehistory->id || $filstorehistory->id != $id) {
|
||||
$this->layout()->setFlash("Datei nicht gefunden.", "error");
|
||||
$this->redirect("Filestore");
|
||||
}
|
||||
$filstorehistory->delete();
|
||||
$this->redirect("Filestore");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,8 +58,28 @@ class FilestoreHistoryModel
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
$sql = "SELECT FilestoreHistory.* FROM FilestoreHistory
|
||||
|
||||
";
|
||||
$res = $db->query($sql);
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_array($res)) {
|
||||
$items[$data['filestore_id']] = 1;
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getAllhistory($id)
|
||||
{
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
$sql = "SELECT FilestoreHistory.*,Worker.name workername,Worker.id workerid FROM FilestoreHistory
|
||||
LEFT JOIN File ON (FilestoreHistory.file_id = File.id)
|
||||
ORDER BY name";
|
||||
INNER JOIN Worker ON (FilestoreHistory.edit_by=Worker.id)
|
||||
WHERE `filestore_id` ='" . $id . "'
|
||||
ORDER BY edit DESC";
|
||||
$res = $db->query($sql);
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
@@ -94,12 +114,10 @@ class FilestoreHistoryModel
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT FilestoreHistory.* FROM FilestoreHistory
|
||||
LEFT JOIN File ON (FilestoreHistory.file_id = File.id)
|
||||
WHERE $where
|
||||
ORDER BY name";
|
||||
|
||||
$res = $db->query($sql);
|
||||
|
||||
if ($db->num_rows($res)) {
|
||||
|
||||
@@ -1,145 +1,204 @@
|
||||
<?php
|
||||
|
||||
class OrderProductModel {
|
||||
public $order_id;
|
||||
public $product_id;
|
||||
public $termination_id;
|
||||
public $upgrade;
|
||||
public $amount;
|
||||
public $pos;
|
||||
public $description;
|
||||
public $price;
|
||||
public $price_setup;
|
||||
public $price_nne;
|
||||
public $price_nbe;
|
||||
public $billing_delay;
|
||||
public $billing_period;
|
||||
public $note;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
class OrderProductModel
|
||||
{
|
||||
public $order_id;
|
||||
public $product_id;
|
||||
public $termination_id;
|
||||
public $upgrade;
|
||||
public $amount;
|
||||
public $pos;
|
||||
public $description;
|
||||
public $price;
|
||||
public $price_setup;
|
||||
public $price_nne;
|
||||
public $price_nbe;
|
||||
public $billing_delay;
|
||||
public $billing_period;
|
||||
public $note;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new OrderProduct();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(array $data)
|
||||
{
|
||||
$model = new OrderProduct();
|
||||
|
||||
foreach ($data as $field => $value) {
|
||||
if (property_exists(get_called_class(), $field)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!array_key_exists("note", $data)) {
|
||||
$model->note = "";
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if ($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if ($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
if(!array_key_exists("note", $data)) {
|
||||
$model->note = "";
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("OrderProduct", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new OrderProduct($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("OrderProduct", "*", "1=1 ORDER BY order_id, pos, product_id, description");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new OrderProduct($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter = false) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("OrderProduct", "*", "$where ORDER BY order_id, pos, product_id, description");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new OrderProduct($data);
|
||||
if($item->id) {
|
||||
|
||||
public static function getOne($id)
|
||||
{
|
||||
if (!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("OrderProduct", "*", "id=$id LIMIT 1");
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new OrderProduct($data);
|
||||
}
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM OrderProduct WHERE $where ORDER BY order_id, pos, product_id, description";
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new OrderProduct($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("order_id", $filter)) {
|
||||
$order_id = $filter['order_id'];
|
||||
if(is_numeric($order_id)) {
|
||||
$where .= " AND order_id=$order_id";
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("OrderProduct", "*", "1=1 ORDER BY order_id, pos, product_id, description");
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
$items[] = new OrderProduct($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
if(array_key_exists("product_id", $filter)) {
|
||||
$product_id = $filter['product_id'];
|
||||
if(is_numeric($product_id)) {
|
||||
$where .= " AND order_id=$product_id";
|
||||
}
|
||||
|
||||
public static function getFirst($filter = false)
|
||||
{
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("OrderProduct", "*", "$where ORDER BY order_id, pos, product_id, description");
|
||||
if ($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new OrderProduct($data);
|
||||
if ($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if(array_key_exists("termination_id", $filter)) {
|
||||
$termination_id = $filter['termination_id'];
|
||||
if(is_numeric($termination_id)) {
|
||||
$where .= " AND termination_id=$termination_id";
|
||||
}
|
||||
|
||||
public static function search($filter)
|
||||
{
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM OrderProduct WHERE $where ORDER BY order_id, pos, product_id, description";
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if ($db->num_rows($res)) {
|
||||
while ($data = $db->fetch_object($res)) {
|
||||
$items[] = new OrderProduct($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
public static function precache()
|
||||
{
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$sql = "SELECT `OrderProduct`.`id`, `OrderProduct`.`order_id`, `OrderProduct`.`product_id`, `OrderProduct`.`termination_id`
|
||||
,`ProducttechAttribute`.`name` ProducttechAttributename,
|
||||
`routerconfig_finished`,
|
||||
`Termination`.`id` `terminationid`,
|
||||
`Terminationstatus`.`code` `statuscode`
|
||||
FROM `OrderProduct`
|
||||
INNER JOIN `Product` ON (`OrderProduct`.`product_id`=`Product`.`id`)
|
||||
INNER JOIN `Producttech` ON (`Producttech`.`id`=`Product`.`producttech_id`)
|
||||
INNER JOIN `ProductAttribute` ON (`ProductAttribute`.`product_id`=`Product`.`id`)
|
||||
INNER JOIN `ProducttechAttribute` ON (`ProductAttribute`.`producttechattribute_id`=`ProducttechAttribute`.`id`)
|
||||
LEFT JOIN `Termination` ON (`OrderProduct`.`termination_id`=`Termination`.`id`)
|
||||
LEFT JOIN `Terminationstatus` ON (`Terminationstatus`.`id` = `Termination`.`status_id`)
|
||||
LEFT JOIN `Cpeprovisioning` ON (`Cpeprovisioning`.`orderproduct_id`=`OrderProduct`.`id`)
|
||||
";
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if ($db->num_rows($res)) {
|
||||
$oldProduct = "";
|
||||
$oldOrder = "";
|
||||
while ($data = $db->fetch_array($res)) {
|
||||
if ($data['terminationid'])
|
||||
{
|
||||
$items['terminations'][$data['order_id']][]['statuscode']=$data['statuscode'];
|
||||
}
|
||||
if ($oldOrder != $data['order_id']) {
|
||||
$items[$data['order_id']]['statuscode'] = $data['statuscode'];
|
||||
}
|
||||
if ($oldProduct != $data['id']) {
|
||||
$items[$data['order_id']][$data['id']]['id'] = $data['id'];
|
||||
$items[$data['order_id']][$data['id']]['product_id'] = $data['product_id'];
|
||||
$items[$data['order_id']][$data['id']]['termination_id'] = $data['termination_id'];
|
||||
$items[$data['order_id']][$data['id']]['routerconfig_finished'] = $data['routerconfig_finished'];
|
||||
}
|
||||
if ($data['routerconfig_finished'] == 1) {
|
||||
$items[$data['order_id']][$data['id']]['routerconfig_finished'] = $data['routerconfig_finished'];
|
||||
}
|
||||
|
||||
$items[$data['order_id']][$data['id']]['attributes'][$data['ProducttechAttributename']] = $data['ProducttechAttributename'];
|
||||
$oldProduct = $data['id'];
|
||||
$oldOrder = $data['order_id'];
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter)
|
||||
{
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if (array_key_exists("order_id", $filter)) {
|
||||
$order_id = $filter['order_id'];
|
||||
if (is_numeric($order_id)) {
|
||||
$where .= " AND order_id=$order_id";
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists("product_id", $filter)) {
|
||||
$product_id = $filter['product_id'];
|
||||
if (is_numeric($product_id)) {
|
||||
$where .= " AND order_id=$product_id";
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists("termination_id", $filter)) {
|
||||
$termination_id = $filter['termination_id'];
|
||||
if (is_numeric($termination_id)) {
|
||||
$where .= " AND termination_id=$termination_id";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ class Preorder extends mfBaseModel {
|
||||
private $building;
|
||||
private $adb_hausnummer;
|
||||
private $adb_wohneinheit;
|
||||
private $attribute = [];
|
||||
|
||||
|
||||
public function afterLoad() {
|
||||
@@ -184,6 +185,14 @@ class Preorder extends mfBaseModel {
|
||||
|
||||
}
|
||||
|
||||
if($name == "attribute") {
|
||||
if(!$this->attributes) {
|
||||
return null;
|
||||
}
|
||||
$this->attribute = json_decode($this->attributes, true);
|
||||
return $this->attribute;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($user) {
|
||||
@@ -219,4 +228,35 @@ class Preorder extends mfBaseModel {
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
public function __clone() {
|
||||
$me = new User;
|
||||
$me->loadMe();
|
||||
|
||||
$old_id = $this->id;
|
||||
//$old_ucode = $this->ucode;
|
||||
$this->id = null;
|
||||
|
||||
$this->data = clone($this->data);
|
||||
$this->_old_data = new StdClass();
|
||||
|
||||
$this->status = null;
|
||||
$this->campaign = null;
|
||||
$this->partner = null;
|
||||
$this->building = null;
|
||||
$this->adb_hausnummer = null;
|
||||
$this->adb_wohneinheit;
|
||||
|
||||
// cleanup Preorder data
|
||||
$this->create_by = $me->id;
|
||||
$this->edit_by = $me->id;
|
||||
|
||||
$this->create = null;
|
||||
$this->edit = null;
|
||||
$this->saved = 0;
|
||||
$this->mode = "new";
|
||||
|
||||
//$this->save();
|
||||
$this->log->debug("Cloned Preorder $old_id");
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ class PreorderController extends mfBaseController {
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin", "netowner", "salespartner"])) {
|
||||
if(!$me->is(["Admin", "netowner", "salespartner", "preorderfront"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
$this->layout->set("filter", $rfilter);
|
||||
|
||||
$where = "";
|
||||
$filter = $this->getPreparedFilter($rfilter);
|
||||
|
||||
// pagination defaults
|
||||
@@ -37,7 +36,6 @@ class PreorderController extends mfBaseController {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$preorder_filter = $filter;
|
||||
$my_campaigns = [];
|
||||
$my_campaign_ids = [];
|
||||
|
||||
@@ -49,7 +47,20 @@ class PreorderController extends mfBaseController {
|
||||
}
|
||||
$this->layout()->set("my_campaigns", PreordercampaignModel::getAll());
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
if($this->me->is("preorderfront")) {
|
||||
$pns = json_decode($this->me->getFlag("preorder_networks"));
|
||||
if(is_array($pns) && count($pns)) {
|
||||
foreach($pns as $pn_id) {
|
||||
$my_networks[] = new Network($pn_id);
|
||||
}
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(['netowner','salespartner']);
|
||||
}
|
||||
|
||||
//var_dump($my_networks);exit;
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
}
|
||||
//var_dump($my_networks);exit;
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
@@ -70,6 +81,8 @@ class PreorderController extends mfBaseController {
|
||||
} else {
|
||||
$filter['preordercampaign_id'] = $my_campaign_ids;
|
||||
}
|
||||
|
||||
if(!$filter['preordercampaign_id']) $filter['preordercampaign_id'] = 0;
|
||||
}
|
||||
|
||||
if($filter['addon_services']) {
|
||||
@@ -101,14 +114,19 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
$new_filter['add-where'] = "";
|
||||
|
||||
if(array_key_exists("address", $filter)) {
|
||||
if(array_key_exists("address", $filter) && $filter["address"]) {
|
||||
$address = $this->db()->escape($filter['address']);
|
||||
$new_filter['add-where'] .= " AND (adb_hausnummer.gemeinde like '%$address%' OR adb_hausnummer.plz like '%$address%' OR adb_hausnummer.strasse like '%$address%')";
|
||||
}
|
||||
|
||||
if(array_key_exists("kunde", $filter)) {
|
||||
if(array_key_exists("hausnummer", $filter) && $filter["hausnummer"]) {
|
||||
$hausnummer = $this->db()->escape($filter['hausnummer']);
|
||||
$new_filter['hausnummer'] = $hausnummer;
|
||||
}
|
||||
|
||||
if(array_key_exists("kunde", $filter) && $filter["kunde"]) {
|
||||
$kunde = $this->db()->escape($filter['kunde']);
|
||||
$new_filter['add-where'] .= " AND (company like '%$kunde%' OR firstname like '%$kunde%' OR lastname like '%$kunde%' OR street like '%$kunde%' OR zip like '%$kunde%' OR city like '%$kunde%')";
|
||||
$new_filter['add-where'] .= " AND (company like '%$kunde%' OR firstname like '%$kunde%' OR lastname like '%$kunde%' OR concat(firstname, ' ', lastname) like '%$kunde%' OR concat(lastname, ' ', firstname) like '%$kunde%' OR street like '%$kunde%' OR zip like '%$kunde%' OR city like '%$kunde%')";
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +144,18 @@ class PreorderController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("unit_missing", $filter)) {
|
||||
if($filter['unit_missing'] == "yes") {
|
||||
$new_filter['adb_wohneinheit_id'] = null;
|
||||
} elseif($filter['unit_missing'] == "no") {
|
||||
$new_filter['adb_wohneinheit_id'] = true;
|
||||
}
|
||||
unset($filter['unit_missing']);
|
||||
}
|
||||
|
||||
if(array_key_exists("attributes", $filter) && count($filter['attributes'])) {
|
||||
|
||||
}
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
@@ -586,4 +616,185 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function exportAction() {
|
||||
$rfilter = $this->request->filter;
|
||||
if(!is_array($rfilter)) {
|
||||
$rfilter = [];
|
||||
}
|
||||
$filter = $this->getPreparedFilter($rfilter);
|
||||
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
$my_networks = NetworkModel::getAll();
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
}
|
||||
|
||||
$netzgebiet_ids = [];
|
||||
$my_adb_networks = [];
|
||||
foreach($my_networks as $network) {
|
||||
if($network->adb_netzgebiet_id && !in_array($network->adb_netzgebiet_id, $netzgebiet_ids)) {
|
||||
$netzgebiet_ids[] = $network->id;
|
||||
$my_adb_networks[$network->adb_netzgebiet_id] = new ADBNetzgebiet($network->adb_netzgebiet_id);
|
||||
}
|
||||
}
|
||||
|
||||
unset($filter['network_id']);
|
||||
$preorder_filter = $filter;
|
||||
|
||||
$campaign_ids = [];
|
||||
foreach(PreordercampaignModel::search(["network_id" => $netzgebiet_ids]) as $campaign) {
|
||||
if(!in_array($campaign->id, $campaign_ids)) {
|
||||
$campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("preordercampaign_id", $filter) && in_array($filter['preordercampaign_id'], $campaign_ids)) {
|
||||
$preorder_filter["preordercampaign_id"] = $filter['preordercampaign_id'];
|
||||
} else {
|
||||
$preorder_filter["preordercampaign_id"] = $campaign_ids;
|
||||
}
|
||||
|
||||
$preorder_filter['<status_code'] = 800;
|
||||
|
||||
// Get mysqli resource from Model, so layout can output data as it's retrieved
|
||||
// Works around lousy performance and horrendous memory usage
|
||||
$res = PreorderModel::search($preorder_filter, [], true);
|
||||
|
||||
$this->layout()->setTemplate("Preorder/export.csv");
|
||||
$this->layout()->set("res", $res);
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin","netowner","salespartner","preorderfront"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
switch($do) {
|
||||
case "saveAttribute":
|
||||
$return = $this->saveAttributeApi();
|
||||
break;
|
||||
case "getFilteredPreorders":
|
||||
$return = $this->getFilteredPreordersApi();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
|
||||
if(!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
}
|
||||
$data['status'] = "OK";
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
private function getFilteredPreordersApi() {
|
||||
$preorders = [];
|
||||
$filter = [];
|
||||
if(is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
}
|
||||
|
||||
$filter = $this->getPreparedFilter($filter);
|
||||
|
||||
$my_campaign_ids = [];
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
$my_networks = NetworkModel::getAll();
|
||||
} else {
|
||||
if($this->me->is("preorderfront")) {
|
||||
$pns = json_decode($this->me->getFlag("preorder_networks"));
|
||||
if(is_array($pns) && count($pns)) {
|
||||
foreach($pns as $pn_id) {
|
||||
$my_networks[] = new Network($pn_id);
|
||||
}
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(['netowner','salespartner']);
|
||||
}
|
||||
//var_dump($my_networks);exit;
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(['netowner','salespartner']);
|
||||
}
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
$my_campaigns[] = $campaign;
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("preordercampaign_id", $filter)) {
|
||||
if(!in_array($filter['preordercampaign_id'], $my_campaign_ids)) {
|
||||
$filter['preordercampaign_id'] = $my_campaign_ids;
|
||||
}
|
||||
} else {
|
||||
$filter['preordercampaign_id'] = $my_campaign_ids;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$filter['preordercampaign_id']) $filter['preordercampaign_id'] = 0;
|
||||
|
||||
//var_dump($filter);exit;
|
||||
$results = PreorderModel::search($filter);
|
||||
foreach($results as $preorder) {
|
||||
//$this->log->debug("building status: ".print_r($building->status,true));
|
||||
$data = clone($preorder->data);
|
||||
$data->id = $preorder->id;
|
||||
$data->status_code = $preorder->status->code;
|
||||
$data->adrcd = $preorder->adb_hausnummer->adrcd;
|
||||
$data->extref = $preorder->adb_hausnummer->extref;
|
||||
$data->adb_strasse = $preorder->adb_hausnummer->strasse->name;
|
||||
$data->adb_hausnummer = $preorder->adb_hausnummer->hausnummer;
|
||||
$data->adb_plz = $preorder->adb_hausnummer->plz->plz;
|
||||
$data->adb_ort = $preorder->adb_hausnummer->ortschaft->name;
|
||||
$data->adb_gemeinde = $preorder->adb_hausnummer->strasse->gemeinde->name;
|
||||
$data->gps_lat = $preorder->adb_hausnummer->gps_lat;
|
||||
$data->gps_long = $preorder->adb_hausnummer->gps_long;
|
||||
|
||||
$data->type_label = __($data->type, "preorder");
|
||||
$data->connection_type_label = __($data->connection_type, "preorder");
|
||||
|
||||
$preorders[] = $data;
|
||||
}
|
||||
|
||||
return ["preorders" => $preorders];
|
||||
}
|
||||
|
||||
private function saveAttributeApi() {
|
||||
$preorder_id = $this->request->id;
|
||||
if(!is_numeric($preorder_id) || $preorder_id < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$preorder = new Preorder($preorder_id);
|
||||
if(!$preorder->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$attribute = $this->request->attribute;
|
||||
if(!$attribute) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$value = $this->request->value;
|
||||
$attribs = $preorder->attribute;
|
||||
if(!$attribs) {
|
||||
$attribs = [];
|
||||
}
|
||||
|
||||
$attribs[$attribute] = $value ? 1 : 0;
|
||||
$preorder->attributes = json_encode($attribs);
|
||||
if($preorder->save()) {
|
||||
return ["id" => $preorder_id, "attribute" => $attribute, "update" => date("d.m.Y H:i", $preorder->edit)];
|
||||
} else {
|
||||
$this->returnJson(["status" => "error", "result" => ["id" => $preorder_id, "attribute" => $attribute]]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,6 +51,7 @@ class PreorderModel {
|
||||
public $shipping_address;
|
||||
public $addon_services;
|
||||
public $addon_data;
|
||||
public $attributes;
|
||||
public $submit_type;
|
||||
public $submit_request;
|
||||
|
||||
@@ -216,6 +217,7 @@ class PreorderModel {
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM `".FRONKDB_DBNAME."`.Preorder tt_preorder
|
||||
LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id)
|
||||
LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
WHERE $where
|
||||
";
|
||||
@@ -230,7 +232,7 @@ class PreorderModel {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
public static function search($filter, $limit = false, $returnDBRessource = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
@@ -255,6 +257,12 @@ class PreorderModel {
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
|
||||
// hack for Preorder::exportAction
|
||||
if($returnDBRessource) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Preorder($data);
|
||||
}
|
||||
@@ -364,6 +372,8 @@ class PreorderModel {
|
||||
$where .= " AND adb_wohneinheit_id IN (".implode(",",$adb_wohneinheit_id).")";
|
||||
} elseif($adb_wohneinheit_id === null) {
|
||||
$where .= " AND adb_wohneinheit_id IS NULL";
|
||||
} elseif($adb_wohneinheit_id === true) {
|
||||
$where .= " AND adb_wohneinheit_id IS NOT NULL AND adb_wohneinheit_id > 0";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,6 +410,15 @@ class PreorderModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("connection_count", $filter)) {
|
||||
$connection_count = $filter['connection_count'];
|
||||
if(intval($connection_count) === 1) {
|
||||
$where .= " AND connection_count = 1";
|
||||
} elseif(intval($connection_count) === 2) {
|
||||
$where .= " AND connection_count > 1";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ucode", $filter)) {
|
||||
$ucode = FronkDB::singleton()->escape($filter['ucode']);
|
||||
if($ucode) {
|
||||
@@ -442,6 +461,41 @@ class PreorderModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("hausnummer", $filter)) {
|
||||
$hausnummer = FronkDB::singleton()->escape($filter['hausnummer']);
|
||||
if($hausnummer) {
|
||||
$where .= " AND adb_hausnummer.hausnummer like '%$hausnummer%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("unit_count", $filter)) {
|
||||
$unit_count = $filter['unit_count'];
|
||||
if(intval($unit_count) === 1) {
|
||||
$where .= " AND adb_hausnummer.unit_count = 1";
|
||||
} elseif(intval($unit_count) === 2) {
|
||||
$where .= " AND adb_hausnummer.unit_count > 1";
|
||||
} elseif(strlen($unit_count) && intval($unit_count) === 0) {
|
||||
$where .= " AND adb_hausnummer.unit_count = 0 OR adb_hausnummer.unit_count IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("attributes", $filter)) {
|
||||
$attributes = FronkDB::singleton()->escape($filter['attributes']);
|
||||
if(is_array($attributes) && count($attributes)) {
|
||||
if(array_key_exists("bep_specified", $attributes)) {
|
||||
if($attributes['bep_specified']) {
|
||||
$where .= " AND JSON_EXTRACT(attributes, \"$.bep_specified\") = 1";
|
||||
}
|
||||
}
|
||||
if(array_key_exists("inhouse_cabling_supplied", $attributes)) {
|
||||
if($attributes['inhouse_cabling_supplied']) {
|
||||
$where .= " AND JSON_EXTRACT(attributes, \"$.inhouse_cabling_supplied\") = 1";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// custom where clause
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
|
||||
@@ -160,14 +160,14 @@ class PreordernotificationModel {
|
||||
}
|
||||
|
||||
if(array_key_exists("send_finish", $filter)) {
|
||||
$send_finish = $db->escape($filter['send_finish']);
|
||||
$send_finish = $filter['send_finish'];
|
||||
if($send_finish === null) {
|
||||
$where .= " AND Preordernotification.send_finish IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("send_lock", $filter)) {
|
||||
$send_lock = $db->escape($filter['send_lock']);
|
||||
$send_lock = $filter['send_lock'];
|
||||
if($send_lock === null) {
|
||||
$where .= " AND Preordernotification.send_lock IS NULL";
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ class Product extends mfBaseModel {
|
||||
private $attributes;
|
||||
|
||||
public function loadAttributes() {
|
||||
$this->attributes = [];
|
||||
|
||||
if(!$this->producttech_id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->attributes = [];
|
||||
|
||||
// get tech attribs
|
||||
$ptattribs = mfValuecache::singleton()->get("ProducttechAttributes-techid-".$this->producttech_id);
|
||||
if($ptattribs === null) {
|
||||
|
||||
@@ -120,11 +120,12 @@ class User extends mfBaseModel {
|
||||
|
||||
//var_dump($m);exit;
|
||||
|
||||
$abbr = "$firstname ";
|
||||
$abbr = substr($firstname, 0, 1). ". ";
|
||||
if($middlename) {
|
||||
$abbr .= substr($middlename, 0, 1). ". ";
|
||||
}
|
||||
$abbr .= substr($lastname, 0, 1). ". ";
|
||||
$abbr .= $lastname;
|
||||
|
||||
return $abbr;
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +178,22 @@ class UserController extends mfBaseController {
|
||||
$user->permissions->technician = "false";
|
||||
}
|
||||
|
||||
if($r->preorderfront == "true") {
|
||||
$user->permissions->preorderfront = "true";
|
||||
} else {
|
||||
$user->permissions->preorderfront = "false";
|
||||
}
|
||||
|
||||
$user->permissions->save();
|
||||
|
||||
// save networks
|
||||
$pn = $user->getFlag("preorder_networks");
|
||||
if($r->preorderfront == "true" && is_array($r->preorder_networks) && count($r->preorder_networks)) {
|
||||
$pn->value(json_encode($r->preorder_networks));
|
||||
$pn->save();
|
||||
} else {
|
||||
$pn->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Benutzer gespeichert.", "success");
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
class WorkerFlag {
|
||||
private $db;
|
||||
private $id;
|
||||
private $worker_id = null;
|
||||
private $name = null;
|
||||
private $value = null;
|
||||
private $user = null;
|
||||
|
||||
public function __construct($worker_id, $name) {
|
||||
$this->db = new FronkDB();
|
||||
|
||||
$user = new User($worker_id);
|
||||
$this->user = $user;
|
||||
|
||||
$name = $this->db->escape($name);
|
||||
$this->name = $name;
|
||||
|
||||
$res = $this->db->select("WorkerFlag", "*", "worker_id=".$this->user->id." AND name='$name'");
|
||||
if($this->db->num_rows($res)) {
|
||||
$data = $this->db->fetch_object($res);
|
||||
$this->id = $data->id;
|
||||
$this->value = $data->value;
|
||||
}
|
||||
}
|
||||
|
||||
public function value($value = null) {
|
||||
if($value !== null) {
|
||||
$this->value = $value;
|
||||
}
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function save() {
|
||||
$id = $this->id;
|
||||
|
||||
$values['worker_id'] = $this->user->id;
|
||||
$values['name'] = $this->name;
|
||||
$values['value'] = $this->value;
|
||||
$values['edit_by'] = $this->user->id;
|
||||
$values['edit'] = date('U');
|
||||
|
||||
if($id) {
|
||||
// update
|
||||
$this->db->update("WorkerFlag", $values, "id=$id");
|
||||
} else {
|
||||
// insert
|
||||
$values['create_by'] = $this->user->id;
|
||||
$values['create'] = date('U');
|
||||
$id = $this->db->insert("WorkerFlag", $values);
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
if($this->id) {
|
||||
$this->db->delete("WorkerFlag", "id=".$this->id, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return (string) $this->value;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ class WorkerPermission extends mfBaseModel {
|
||||
public $isAdmin = false;
|
||||
public $isTicketadmin = false;
|
||||
public $isTechnician = false;
|
||||
public $isPreorderfront = false;
|
||||
|
||||
public function loadByUserId($userid) {
|
||||
$res = $this->db->select($this->table,"*","worker_id=$userid");
|
||||
@@ -29,6 +30,9 @@ class WorkerPermission extends mfBaseModel {
|
||||
if($this->technician == 'true') {
|
||||
$this->isTechnician = true;
|
||||
}
|
||||
if($this->preorderfront == 'true') {
|
||||
$this->isPreorderfront= true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user