Merge branch 'master' into 'devbyspi'

# Conflicts:
#   Layout/default/Device/Detail.php
#   Layout/default/Device/Form.php
#   Layout/default/Device/Index.php
#   application/Device/DeviceController.php
#   application/Device/DeviceModel.php
#   public/assets/css/datatables-std.css
This commit is contained in:
Frank Schubert
2023-03-22 14:36:13 +00:00
99 changed files with 60682 additions and 831 deletions
+5 -10
View File
@@ -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;
}
@@ -11,6 +11,10 @@ class ADBHausnummerModel {
public $hausnummer;
public $zusatz;
public $grund_nr;
public $gdaeigenschaft;
public $rw;
public $hw;
public $meridian;
public $unit_count;
public $gps_lat;
public $gps_long;
@@ -0,0 +1,5 @@
<?php
class ADBWohneinheitController extends mfBaseController {
}
+8
View File
@@ -10,6 +10,7 @@ class Address extends mfBaseModel {
private $attributes;
private $permissions;
private $contracts;
private $active_contracts;
private $phoneparts;
@@ -190,6 +191,13 @@ class Address extends mfBaseModel {
return $this->contracts;
}
if($name == "active_contracts") {
$owning = ContractModel::searchActive(['owner_id' => $this->id]);
$billing = ContractModel::searchActive(['billingaddress_id' => $this->id]);
$this->contracts = array_merge($owning, $billing);
return $this->contracts;
}
/*
if($name == "links_to") {
$links = AddressLinkModel::search(['address_id' => $this->id]);
+17
View File
@@ -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;
@@ -231,7 +231,7 @@ 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");
@@ -278,7 +278,7 @@ class AddressDBController extends mfBaseController {
if(trim($r->rollout_info)) {
$rollout_info = trim($r->rollout_info);
}
if(!$rollout_info) {
if(!$rollout && !$rollout_info) {
$rollout_info = "unscheduled";
}
@@ -289,6 +289,9 @@ 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();
+86 -11
View File
@@ -19,6 +19,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
protected function init() {
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$this->addRoute("/preorder/open", "getOpenPreorders", "GET");
$this->addRoute("/preorder", "submitPreorder", "POST");
$this->addRoute("/preorder/:code", "getPreorder", "GET");
$this->addRoute("/preorder/:code", "cancelPreorder", "DELETE");
@@ -79,20 +80,67 @@ class PreorderApicontroller extends mfBaseApicontroller {
//var_dump($campaign, $this->allowed_origins);exit;
}
protected function getOpenPreorders() {
$ts = $this->get['ts'];
$update_ts = 0;
if($ts) {
if(is_numeric($ts)) {
$update_ts = $ts;
} else {
$update_date = new DateTime($ts);
if($update_date) {
$update_ts = $update_date->format('U');
}
}
}
// nicht auf cluster einschränken, sondern auf partner_id
/*
$preorder_search = [];
if(count($this->filter_salescluster_ids)) {
$preorder_search['netzgebiet_id'] = $this->filter_salescluster_ids;
}*/
$preorder_search = [];
$preorder_search['partner_id'] = $this->me->address_id;
if($update_ts) {
$preorder_search['add-where'] = "AND tt_preorder.`edit` > $update_ts";
} else {
// if no timestamp, return only open orders (500 == finished)
$preorder_search['<status_code'] = 500;
}
$return = [];
foreach(PreorderModel::search($preorder_search) as $preorder) {
$return[] = $preorder->getApiArray();
}
return mfResponse::Ok(["preorders" => $return]);
}
protected function getPreorder($code) {
$code = trim(strtoupper($code));
$code = trim($code);
if(!$code) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
}
$preorder = PreorderModel::getFirst(['ucode' => $code]);
$preorder = PreorderModel::getFirst(['ucode' => strtoupper($code), 'partner_id' => $this->me->address_id]);
if(!$preorder) {
// try oan id
$preorder = PreorderModel::getFirst(['oaid' => $code]);
if(!$preorder) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
}
$preorder = PreorderModel::getFirst(['oaid' => strtolower($code), 'partner_id' => $this->me->address_id]);
}
if(!$preorder) {
// try as extref
$preorder = PreorderModel::getFirst(['extref' => $code, 'partner_id' => $this->me->address_id]);
}
if(!$preorder) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
}
if($preorder->partner_id != $this->me->address_id) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
@@ -103,12 +151,12 @@ class PreorderApicontroller extends mfBaseApicontroller {
return mfResponse::NotFound(["message" => "Preorder not found"]);
}
return mfResponse::Ok($return);
}
protected function cancelPreorder($code) {
/*
$code = trim(strtoupper($code));
if(!$code) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
@@ -121,6 +169,24 @@ class PreorderApicontroller extends mfBaseApicontroller {
if(!$preorder) {
return mfResponse::NotFound(["message" => "Preorder not found or cancelled already"]);
}
}*/
$code = trim($code);
if(!$code) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
}
$preorder = PreorderModel::getFirst(['ucode' => strtoupper($code), 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
if(!$preorder) {
// try oan id
$preorder = PreorderModel::getFirst(['oaid' => strtolower($code), 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
}
if(!$preorder) {
// try as extref
$preorder = PreorderModel::getFirst(['extref' => $code, 'partner_id' => $this->me->address_id, 'deleted' => 0, '<status_code' => 800]);
}
if(!$preorder) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
}
// check if user owns preorder
@@ -412,8 +478,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
} else {
$preorder_data['is_additional_order'] = 0;
}
$preorder_data['technology'] = ($this->post['technology']) ? $this->post['technology'] : null;
$preorder_data['patchposition'] = ($this->post['patchposition']) ? $this->post['patchposition'] : null;
$preorder_data['extref'] = (trim($this->post['extref'])) ? trim($this->post['extref']) : null;
$preorder_data['technology'] = (trim($this->post['technology'])) ? trim($this->post['technology']) : null;
$preorder_data['patchposition'] = (trim($this->post['patchposition'])) ? trim($this->post['patchposition']) : null;
/*
* setup price
@@ -458,7 +525,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
*/
foreach(['company','uid','firstname','lastname','street','housenumber','zip','city','phone','email','block','stiege','stock','tuer', 'unit_string'] as $key) {
if(property_exists($customer, $key)) {
$preorder_data[$key] = ($customer->$key) ? $customer->$key : null;
$preorder_data[$key] = (trim($customer->$key)) ? trim($customer->$key) : null;
}
}
@@ -611,12 +678,20 @@ class PreorderApicontroller extends mfBaseApicontroller {
$return = ["code" => $preorder->ucode];
if($preorder->oaid) {
$return ['oaid'] = $preorder->oaid;
$return['oaid'] = $preorder->oaid;
}
if($preorder->extref) {
$return['extref'] = $preorder->extref;
}
if($addon_data) {
$return["additionalData"] = $addon_data;
}
$return['created'] = date("c", $preorder->create);
$return['created_ts'] = (int)$preorder->create;
$return['updated'] = date("c", $preorder->edit);
$return['updated_ts'] = (int)$preorder->edit;
return mfResponse::Ok($return);
}
+23 -3
View File
@@ -1,6 +1,8 @@
<?php
class Contract extends mfBaseModel {
protected $forcestr = ["product_name","product_info","matchcode"];
private $owner;
private $billingaddress;
private $product;
@@ -10,7 +12,9 @@ class Contract extends mfBaseModel {
private $contractConfigGroups;
private $contractConfigItems;
private $configgroups;
private $configvalues;
private $isCancelled;
private $journals;
private $links;
private $linkFrom;
private $linkTo;
@@ -160,11 +164,11 @@ class Contract extends mfBaseModel {
return $this->orderproduct;
}
if($name == "contractConfigGroups") {
/*if($name == "contractConfigGroups") {
$product = $this->getProperty("product");
$this->contractConfigGroups = ContractconfigGroupModel::search(['producttech_id' => $product->producttech_id]);
return $this->contractConfigGroups;
}
}*/
if($name == "configgroups") {
$product = $this->getProperty("product");
@@ -173,10 +177,21 @@ class Contract extends mfBaseModel {
$ccpg->contractconfiggroup->setContractId($this->id);
$this->configgroups[] = $ccpg->contractconfiggroup;
}
return $this->configgroups;
}
if($name == "contractConfigItems") {
if($name == "configvalues") {
foreach($this->getProperty("configgroups") as $group) {
foreach($group->items as $item) {
$this->configvalues[$item->name] = $item;
}
}
return $this->configvalues;
}
/*if($name == "contractConfigItems") {
$product = $this->getProperty("product");
$this->contractConfigItems = [];
@@ -186,6 +201,11 @@ class Contract extends mfBaseModel {
}
return $this->contractConfigItems;
}*/
if($name == "journals") {
$this->journals = array_reverse(ContractjournalModel::search(["contract_id" => $this->id]));
return $this->journals;
}
if($name == "links") {
+28 -1
View File
@@ -379,6 +379,7 @@ class ContractController extends mfBaseController {
}
$this->layout()->set("contract", $contract);
//var_dump($contract->owner);exit;
if($this->request->f == "view") $this->layout()->set("f", "view");
if($this->request->f != "view") $this->layout()->set("f", "index");
@@ -428,6 +429,7 @@ class ContractController extends mfBaseController {
$contract_data['price_nbe'] = (float)$r->price_nbe;
$contract_data['billing_period'] = (int)$r->billing_period;
$contract_data['billing_delay'] = (int)$r->billing_delay;
$contract_data['order_date'] = ($r->order_date) ? $this->dateToTimestamp($r->order_date) : null;
$contract_data['finish_date'] = ($r->finish_date) ? $this->dateToTimestamp($r->finish_date) : null;
$contract_data['cancel_date'] = ($r->cancel_date) ? $this->dateToTimestamp($r->cancel_date) : null;
$contract_data['note'] = $r->note;
@@ -474,6 +476,16 @@ class ContractController extends mfBaseController {
return $this->addAction();
}
// create journal
if($mode == "add") {
$journal = ContractjournalModel::create([
'contract_id' => $contract_id,
'type' => "created_from",
'value' => "manual"
]);
$journal->save();
}
$this->layout()->setFlash("Vertrag erfolgreich gespeichert.", "success");
/*
@@ -487,7 +499,22 @@ class ContractController extends mfBaseController {
'origin_contract_id' => $origin->id,
'type' => 'link'
]);
$link->save();
$link_id = $link->save();
if($link_id) {
$journal = ContractjournalModel::create([
'contract_id' => $contract_id,
'type' => "link",
'value' => $origin->id
]);
$journal->save();
$ojournal = ContractjournalModel::create([
'contract_id' => $origin->id,
'type' => "link",
'value' => $contract_id
]);
$ojournal->save();
}
}
}
+36
View File
@@ -116,6 +116,42 @@ class ContractModel {
return 0;
}
public static function searchActive($filter, $limit = false) {
//var_dump($filter);exit;
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT Contract.* FROM Contract
LEFT JOIN Address ON (Contract.owner_id = Address.id)
LEFT JOIN OrderProduct ON (Contract.orderproduct_id = OrderProduct.id)
LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id)
LEFT JOIN Product ON (Contract.product_id = Product.id)
WHERE $where
AND (cancel_date IS NULL OR cancel_date > UNIX_TIMESTAMP())
GROUP BY Contract.id
ORDER BY Contract.owner_id,Contract.`create`";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($count)) {
$sql .= " LIMIT ".$limit['count'];
}
}
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[$data->id] = new Contract($data);
}
}
return $items;
}
public static function search($filter, $limit = false) {
//var_dump($filter);exit;
$items = [];
@@ -0,0 +1,5 @@
<?php
class ContractFile extends mfBaseModel {
}
@@ -0,0 +1,149 @@
<?php
class ContractFileModel {
public $contract_id;
public $file_id;
public $name;
public $description;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new ContractFile();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model ->$field = $value;
}
}
$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("ContractFile", "*", "id=$id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new ContractFile($data);
}
return $item;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("ContractFile", "*", "1=1 ORDER BY contract_id, `create`");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ContractFile($data);
}
}
return $items;
}
public static function getFirst() {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("ContractFile", "*", "$where ORDER BY contract_id, `create`");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new ContractFile($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT ContractFile.* FROM ContractFile
LEFT JOIN File ON (ContractFile.file_id = File.id)
WHERE $where
ORDER BY contract_id, `create`";
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ContractFile($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("file_id", $filter)) {
$file_id = $filter['file_id'];
if(is_numeric($file_id)) {
$where .= " AND file_id=$file_id";
}
}
if(array_key_exists("contract_id", $filter)) {
$contract_id = $filter['contract_id'];
if(is_numeric($contract_id)) {
$where .= " AND contract_id=$contract_id";
}
}
//var_dump($filter);exit;
if(array_key_exists("name", $filter)) {
$name = FronkDB::singleton()->escape($filter['name']);
if($name) {
$where .= " AND name='$name'";
}
}
if(array_key_exists("filename", $filter)) {
$filename = FronkDB::singleton()->escape($filter['filename']);
if($filename) {
$where .= " AND File.filename='$filename'";
}
}
if(array_key_exists("subfolder", $filter)) {
$subfolder = FronkDB::singleton()->escape($filter['subfolder']);
if($subfolder) {
$where .= " AND File.subfolder='$subfolder'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}
@@ -1,6 +1,7 @@
<?php
class ContractconfigController extends mfBaseController {
public $hook_errors;
protected function init() {
$this->needlogin=true;
@@ -55,6 +56,12 @@ class ContractconfigController extends mfBaseController {
$this->redirect("Contract");
}
$contract = new Contract($contract_id);
if(!$contract->id) {
$this->layout()->setFlash("Contract ID nicht gefunden.","error");
$this->redirect("Contract");
}
if(!is_array($r->itemvalues) || !count($r->itemvalues)) {
$this->layout()->setFlash("Keine Änderungen.","info");
$this->redirect("Contract");
@@ -62,13 +69,24 @@ 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;
@@ -79,6 +97,7 @@ class ContractconfigController extends mfBaseController {
return $this->editAction();
}
}
//exit;
if(count($error_items)) {
$this->layout()->set("error_items", array_keys($error_items));
@@ -87,10 +106,75 @@ class ContractconfigController extends mfBaseController {
return $this->editAction();
}
// 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;
}
}
@@ -0,0 +1,99 @@
<?php
abstract class Contractconfig_Hook {
protected $log;
protected $required_product_attributes = [];
protected $contract;
protected $items;
protected $product;
protected $product_attributes = [];
protected $config_prefix;
protected $configitems = [];
public $errors = [];
abstract public function beforeSave();
abstract public function afterSave();
abstract public function beforeDelete();
abstract public function afterDelete();
public function __construct(Contract $contract) {
$this->log = mfLoghandler::singleton();
$this->contract = $contract;
if($contract->product) {
$this->product = $contract->product;
if(is_array($this->product->attributes) && count($this->product->attributes)) {
$this->product_attributes = $this->product->attributes;
}
}
$this->loadConfigItems();
if(method_exists($this, "init")) {
$this->init();
}
}
private function loadConfigItems() {
$m = [];
if(preg_match('/^Contractconfig_Hook_(.+)$/', get_class($this), $m)) {
if($m[1]) {
$this->config_prefix = strtolower($m[1]);
}
} else {
return false;
}
foreach($this->contract->configgroups as $configgroup) {
foreach($configgroup->items as $item) {
if(strpos($item->name, $this->config_prefix) === 0) {
$short_name = substr($item->name, strlen($this->config_prefix)+1);
//var_dump($short_name);
$this->configitems[$short_name] = $item;
}
}
}
return true;
}
public function isResponsible() {
if(!$this->contract) return false;
if(!$this->product) return false;
if(!$this->product_attributes) return false;
// only work on contracts with our producttech attributes
if(!$this->testMyProductAttributes()) {
return false;
}
return true;
}
private function testMyProductAttributes() {
if(!$this->product_attributes) return false;
//var_dump($this->product_attributes);exit;
//var_dump($this->required_product_attributes);exit;
foreach($this->required_product_attributes as $needed_attribute) {
// every needed attribute must exist in product
if(!array_key_exists($needed_attribute, $this->product_attributes)) {
return false;
}
}
return true;
}
}
@@ -0,0 +1,168 @@
<?php
require_once __DIR__."/Contractconfig_Hook.php";
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.
*/
public function isResponsible() {
/*
* Test for standard checks
* (Only Producttech attributes for now)
*/
if(!parent::isResponsible()) {
return false;
}
// do additional checks
//$contract = $this->contract;
return true;
}
public function init() {
$this->errors["voicenumberblock_voicenumber"] = [];
// get voip routing for number
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();
$this->voip_routing = $typedata[0];
}
}
}
public function beforeSave() {
return $this->checkNewNumbers();
}
public function afterSave() {
$this->checkNewNumbers();
if(count($this->errors["voicenumberblock_voicenumber"])) {
return false;
}
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";
}
}
}
}
if(count($this->errors["voicenumberblock_voicenumber"])) {
return false;
}
return true;
}
/*
* TODO: Check if contract was canceled, then set lock and lock_reason to reserved
*/
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 afterDelete() {
}
}
@@ -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;
}
@@ -30,9 +30,11 @@ class ContractconfigItemController extends mfBaseController {
}
$item_data['contractconfiggroup_id'] = $r->group_id;
$item_data['order'] = ($r->order && is_numeric($r->order)) ? $r->order : null;
$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'] = "";
@@ -53,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");
}
@@ -68,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");
}
@@ -78,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);
@@ -10,14 +10,29 @@ class ContractconfigValue extends mfBaseModel {
$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") {
@@ -0,0 +1,59 @@
<?php
class Contractjournal extends mfBaseModel {
private $contract;
private $contractfile;
private $creator;
private $editor;
public function getProperty($name) {
if($this->$name == null) {
if($name == "contractfile") {
if(!is_numeric($this->value)) return null;
$this->contractfile = new ContractFile($this->value);
return $this->contractfile;
}
if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($this->creator === null) {
$this->creator = new User($this->create_by);
if($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
}
}
return $this->creator;
}
if($name == "editor") {
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
if($this->editor === null) {
$this->editor = new User($this->edit_by);
if($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
}
}
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}
@@ -0,0 +1,86 @@
<?php
class ContractjournalController 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 saveAction() {
$r = $this->request;
//var_dump($r->get());exit;
$contract_id = $r->contract_id;
if(!is_numeric($contract_id) || $contract_id < 1) {
$this->layout()->setFlash("Contract nicht gefunden", "error");
$this->redirect("Contract");
}
$contract = new Contract($contract_id);
if(!$contract->id) {
$this->layout()->setFlash("Contract nicht gefunden", "error");
$this->redirect("Contract");
}
$journal_data = [];
$journal_data["contract_id"] = $contract_id;
$journal_data["text"] = ($r->text) ? $r->text : null;
$journal_data["type"] = "text";
if($r->type == "phone") $journal_data["type"] = "phone";
if($r->type == "file") $journal_data["type"] = "file";
if(in_array($r->type, ["text", "phone"])) {
if(!$journal_data['text']) {
$this->layout()->setFlash("Journaleintrag darf nicht leer sein", "error");
$this->redirect("Contract", "view", ['contract_id' => $contract_id]);
}
}
if($r->type == "file") {
try {
// returns File object or throws Exception on error
$file = mfUpload::handleFormUpload("journal_file");
} catch (Exception $ex) {
$this->layout()->setFlash("Fehler beim Dateiupload: ".$ex->getMessage(), "error");
$this->redirect("Contract", "view", ['contract_id' => $contract_id]);
}
$cf = ContractFileModel::create([
'contract_id' => $contract_id,
'file_id' => $file->id,
'name' => $file->name,
]);
$contractfile_id = $cf->save();
if(!$contractfile_id) {
$this->layout()->setFlash("Fehler beim Speichern der hochgeladenen Datei", "error");
$this->redirect("Contract", "view", ['contract_id' => $contract_id]);
}
$journal_data['type'] = "file";
$journal_data['value'] = $contractfile_id;
}
$journal = ContractjournalModel::create($journal_data);
$journal_id = $journal->save();
if(!$journal_id) {
$this->layout()->setFlash("Fehler beim Speichern des Journaleintrags", "error");
$this->redirect("Contract", "view", ['contract_id' => $contract_id]);
}
$this->layout()->setFlash("Journaleintrag erfolgreich gespeichert", "success");
$this->redirect("Contract", "view", ['contract_id' => $contract_id]);
}
}
@@ -0,0 +1,128 @@
<?php
class ContractjournalModel {
public $contract_id;
public $type;
public $value;
public $text;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new Contractjournal();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model ->$field = $value;
}
}
$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 getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Contractjournal", "*", "1=1 ORDER BY contract_id,`create`");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Contractjournal($data);
}
}
return $items;
}
public static function getFirst($filter = false) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Contractjournal", "*", "$where ORDER BY contract_id,`create`");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Contractjournal($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function search($filter) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
/*
$sql = "SELECT Contractjournal.* FROM Contractjournal
LEFT JOIN File ON (Contractjournal.file_id = File.id)
WHERE $where
ORDER BY order_id, name";
$res = $db->query($sql);
*/
$res = $db->select("Contractjournal", "*", $where);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Contractjournal($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("contract_id", $filter)) {
$contract_id = $filter['contract_id'];
if(is_numeric($contract_id)) {
$where .= " AND contract_id=$contract_id";
}
}
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("type", $filter)) {
$type = FronkDB::singleton()->escape($filter['type']);
if($type) {
$where .= " AND type='$type'";
}
}
if(array_key_exists("value", $filter)) {
$value = FronkDB::singleton()->escape($filter['value']);
if($value) {
$where .= " AND value='$value'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}
@@ -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);
}
+27 -59
View File
@@ -95,7 +95,7 @@ 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;
@@ -181,6 +181,32 @@ class DeviceController extends mfBaseController
}
$this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
}
$returnUrl="Device";
$returnAction = "Index";
$returnVariables = array();
$returnAnker = "";
if ($this->request->returnto) {
if (strpos($this->request->returnto, "-") !== false) {
$urls = explode('-', $this->request->returnto);
$urlCounter = 0;
$returnUrlGen = "";
foreach ($urls as $url) {
if ($urlCounter > 0) {
$returnUrlGen .= "/";
}
$returnUrlGen .= ucfirst($url);
$urlCounter++;
}
$returnAction = "";
$returnVariables['id'] = $id;
$returnUrl = $returnUrlGen;
} else {
$returnUrl = ucfirst($this->request->returnto);
}
}
if ($mode == "edit") {
$this->layout()->setFlash("Device erfolgreich geändert", "success");
@@ -190,62 +216,4 @@ 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;
}
}
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");
}
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);
}
}
+4 -4
View File
@@ -108,8 +108,8 @@ class DeviceModel
$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);
}
}
@@ -121,9 +121,9 @@ class DeviceModel
$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";
}
}
+32
View File
@@ -227,6 +227,38 @@ class Order extends mfBaseModel {
}
}
public function sendExtBillNbeInfoEmail() {
// TODO template rendern auslagern nach Emailtempate klasse
$tpl = new Layout();
$tpl->setTemplate("Emailtemplates/order/exernal_product_nbe_billing");
$tpl->set("order", $this);
$body = $tpl->render();
$values = $tpl->getReturnedValue();
//var_dump($values); echo "<pre class='text-monospace'>".$body."</pre>"; exit;
$subject = $values['subject'];
$from = $values['from_email'];
$from_name = $values['from_email_name'];
$to = TT_INTERNAL_BILLING_EMAIL_TO;
if(!$subject || !$from || !$from_name || !$to) {
$this->log->warn("Billing NBE Email not sent. (subject: '$subject', from: '$from', from_email: '$from_name', to: '$to')");
return false;
} else {
$email = new Emailnotification();
$email->setSubject($subject);
$email->setBody($body);
$email->setFrom($from, $from_name);
$email->setTo($to);
$email->setHeader("X-".MFAPPNAME."-oid", $this->id);
$email->send();
return true;
}
}
public function sendFileuploadEmail(OrderFile $file) {
$filetype = $file->name;
+29 -5
View File
@@ -364,9 +364,11 @@ class OrderController extends mfBaseController {
// TODO: filter by network permissions
$this->layout()->setTemplate("Order/Form");
$products = [];
if($this->me->is("Admin")) {
//$this->layout()->set("addresses", AddressModel::search(['parents_only' => 1]));
$this->layout()->set("products", ProductModel::getAll());
//$this->layout()->set("products", ProductModel::getActive());
$products = ProductModel::getActive();
$this->layout()->set("terminations", TerminationModel::getAll());
} else {
// get all salespartner addresses of my networks
@@ -396,13 +398,25 @@ class OrderController extends mfBaseController {
// get products assigned to my networks
$products = [];
foreach(ProductNetworkModel::search(["network_id" => $network_ids]) as $pn) {
if(!array_key_exists($pn->product_id, $products))
if(!$pn->product->active) continue;
if(!array_key_exists($pn->product_id, $products)) {
$products[$pn->product_id] = $pn->product;
}
}
$this->layout()->set("products", $products);
}
$order = $this->layout()->get("order");
if($order) {
foreach($order->products as $op) {
if(!$op->product->active) {
$products[$op->product_id] = $op->product;
}
}
}
$this->layout()->set("products", $products);
if($this->request->filter) {
$this->layout()->set("filter", $this->request->filter);
}
@@ -811,6 +825,8 @@ class OrderController extends mfBaseController {
$ext_products = false;
$int_products = false;
$ext_products_nbe = 0;
//var_dump($r->products);exit;
// validate and add products
if(is_array($r->products) && count($r->products)) {
@@ -849,7 +865,7 @@ class OrderController extends mfBaseController {
} else {
$product_data["price_nne"] = $prod->price_nne;
}
if($this->me->is("Admin") && $p["price_nbe"]) {
if($this->me->is("Admin") && strlen($p["price_nbe"])) {
$product_data["price_nbe"] = Layout::commaToDot($p["price_nbe"]);
} else {
$product_data["price_nbe"] = $prod->price_nbe;
@@ -894,6 +910,7 @@ class OrderController extends mfBaseController {
if($prod->external) {
$ext_products = true;
$ext_product_owner_id = $prod->external_id;
$ext_products_nbe += $product_data["price_nbe"];
} else {
$int_products = true;
@@ -1006,6 +1023,13 @@ class OrderController extends mfBaseController {
if(!$order->sendExtBillinfoEmail(new Address($ext_product_owner_id))) {
$this->layout()->setFlash("Beim Senden der externen Billing Benachrichtigung ist ein Fehler aufgetreten.", "warning");
}
if($ext_products_nbe) {
// only send nbe mail if there is nbe
if(!$order->sendExtBillNbeInfoEmail(new Address($ext_product_owner_id))) {
//$this->layout()->setFlash("Beim Senden der internen Billing NBE Benachrichtigung ist ein Fehler aufgetreten.", "warning");
}
}
}
if($int_products) {
@@ -1015,7 +1039,7 @@ class OrderController extends mfBaseController {
}
if($int_products && $ext_products) {
$this->layout()->setFlash("Eigene und Fremdprodukte gefunden, nur interne Billing Benachrichtigung verschickt.", "warning");
//$this->layout()->setFlash("Eigene und Fremdprodukte gefunden, nur interne Billing Benachrichtigung verschickt.", "warning");
}
}
+15
View File
@@ -8,6 +8,7 @@ class Preorder extends mfBaseModel {
private $building;
private $adb_hausnummer;
private $adb_wohneinheit;
private $attribute = [];
public function afterLoad() {
@@ -48,6 +49,7 @@ class Preorder extends mfBaseModel {
$a = [];
$a['code'] = strtoupper($this->ucode);
$a['oaid'] = $this->oaid;
$a['extref'] = $this->extref;
$a['status'] = $this->getProperty("status")->getApiArray();
$a['connectionType'] = $this->connection_type;
$a['connectionCount'] = ($this->connection_count) ? (int)$this->connection_count : 1;
@@ -119,6 +121,11 @@ class Preorder extends mfBaseModel {
}
}
$a['created'] = date("c", $this->create);
$a['created_ts'] = (int)$this->create;
$a['updated'] = date("c", $this->edit);
$a['updated_ts'] = (int)$this->edit;
return $a;
}
@@ -178,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) {
+205 -7
View File
@@ -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,16 @@ 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"));
foreach($pns as $pn_id) {
$my_networks[] = new Network($pn_id);
}
//var_dump($my_networks);exit;
} else {
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
}
//var_dump($my_networks);exit;
foreach($my_networks as $network) {
@@ -101,14 +108,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 +138,9 @@ class PreorderController extends mfBaseController {
}
}
if(array_key_exists("attributes", $filter) && count($filter['attributes'])) {
}
if(is_array($filter) && count($filter)) {
foreach($filter as $name => $value) {
@@ -155,6 +170,7 @@ class PreorderController extends mfBaseController {
$products = [];
foreach(ProductNetworkModel::search(["network_id" => $campaign->network_id]) as $pn) {
if(!$pn->product->active) continue;
if(!array_key_exists($pn->product_id, $products)) {
if(is_array($pn->product->attributes) && !array_key_exists("presales", $pn->product->attributes)) {
$products[$pn->product_id] = $pn->product;
@@ -585,4 +601,186 @@ 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->adb_netzgebiet_id;
$my_adb_networks[$network->adb_netzgebiet_id] = new ADBNetzgebiet($network->adb_netzgebiet_id);
}
}
/*if(array_key_exists("network_id", $filter) && $filter['network_id']) {
if($this->me->is("Admin")) {
$filter['netzgebiet_id'] = $filter['network_id'];
} else {
if(in_array($filter['network_id'], $netzgebiet_ids)) {
$filter['netzgebiet_id'] = $filter['network_id'];
}
}
}*/
unset($filter['network_id']);
$preorder_filter = $filter;
/*if(!array_key_exists("netzgebiet_id", $preorder_filter)) {
$preorder_filter['netzgebiet_id'] = $netzgebiet_ids;
}*/
$campaign_ids = [];
foreach(PreordercampaignModel::search(["netzgebiet_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;
//var_dump($filter, $preorder_filter);exit;
// 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"])) {
$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 {
$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;
}
}
}
//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]]);
}
}
}
+40 -1
View File
@@ -7,6 +7,7 @@ class PreorderModel {
public $adb_hausnummer_id;
public $adb_wohneinheit_id;
public $oaid;
public $extref;
public $address_district;
public $address_info;
public $building_id;
@@ -50,6 +51,7 @@ class PreorderModel {
public $shipping_address;
public $addon_services;
public $addon_data;
public $attributes;
public $submit_type;
public $submit_request;
@@ -215,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
";
@@ -229,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();
@@ -254,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);
}
@@ -413,6 +422,13 @@ class PreorderModel {
}
}
if(array_key_exists("extref", $filter)) {
$extref = FronkDB::singleton()->escape($filter['extref']);
if($extref) {
$where .= " AND tt_preorder.extref = '$extref'";
}
}
if(array_key_exists("gemeinde", $filter)) {
$gemeinde = FronkDB::singleton()->escape($filter['gemeinde']);
if($gemeinde) {
@@ -434,6 +450,29 @@ 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("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'];
@@ -54,9 +54,9 @@ class Preordercampaign extends mfBaseModel {
$activation_products = [];
$reorder_products = [];
$provisions = ProductModel::search(["attributename" => "presales", "attributevalue" => "provision"]);
$activations = ProductModel::search(["attributename" => "presales", "attributevalue" => "activation"]);
$reorders = ProductModel::search(["attributename" => "presales", "attributevalue" => "reorder"]);
$provisions = ProductModel::search(["active" => 1, "attributename" => "presales", "attributevalue" => "provision"]);
$activations = ProductModel::search(["active" => 1, "attributename" => "presales", "attributevalue" => "activation"]);
$reorders = ProductModel::search(["active" => 1, "attributename" => "presales", "attributevalue" => "reorder"]);
foreach($provisions as $p) {
if(ProductNetworkModel::search(['product_id' => $p->id, "network_id" => $this->network_id])) {
+7
View File
@@ -1,6 +1,7 @@
<?php
class Product extends mfBaseModel {
private $owner;
private $productgroup;
private $producttech;
private $sla;
@@ -45,6 +46,12 @@ class Product extends mfBaseModel {
public function getProperty($name) {
if($this->$name == null) {
if($name == "owner") {
if(!$this->external_id) return null;
$this->owner = new Address($this->external_id);
return $this->owner;
}
if($name == "networks") {
$this->networks = [];
$productNetworks = ProductNetworkModel::search(['product_id' => $this->id]);
+32 -7
View File
@@ -19,16 +19,23 @@ class ProductController extends mfBaseController {
$this->redirect("Dashboard");
}
if($this->request->resetFilter) {
unset($_SESSION[MFAPPNAME.'-Product-filter']);
}
$filter = [];
if(is_array($this->request->filter)) {
$filter = $this->request->filter;
$_SESSION[MFAPPNAME.'-Product-filter'] = $filter;
} else {
if(array_key_exists(MFAPPNAME.'-Product-filter', $_SESSION) && count($_SESSION[MFAPPNAME.'-Product-filter'])) {
$filter = $_SESSION[MFAPPNAME.'-Product-filter'];
}
}
$this->layout->set("filter", $filter);
$filter = $this->getPreparedFilter($filter);
if($filter) {
$filter = $this->getPreparedFilter($filter);
}
// pagination defaults
$pagination = [];
@@ -55,6 +62,15 @@ class ProductController extends mfBaseController {
unset($filter['name']);
}
if(array_key_exists("active", $filter)) {
if($filter['active'] != "all") {
$new_filter['active'] = $filter['active'];
}
unset($filter['active']);
} else {
$new_filter['active'] = 1;
}
foreach($filter as $name => $value) {
$new_filter[$name] = $value;
}
@@ -128,7 +144,11 @@ class ProductController extends mfBaseController {
}
$data['external_id'] = $r->external_id;
}
//var_dump($data);exit;
$data['active'] = 1;
if(!$r->active) {
$data['active'] = 0;
}
$data['price_nne'] = ($r->price_nne) ? Layout::commaToDot($r->price_nne) : 0;
$data['price_nbe'] = ($r->price_nbe) ? Layout::commaToDot($r->price_nbe) : 0;
@@ -229,7 +249,12 @@ class ProductController extends mfBaseController {
}
$this->layout()->setFlash("Produkt erfolgreich gespeichert.", "success");
$this->redirect("Product", "Edit", ['id' => $new_id]);
if($r->return == "index") {
$this->redirect("Product");
} else {
$this->redirect("Product", "Edit", ['id' => $new_id]);
}
}
protected function deleteAction() {
@@ -310,14 +335,14 @@ class ProductController extends mfBaseController {
$products = [];
if(is_numeric($search)) {
$pnumbers = ProductModel::search(["id" => $search]);
$pnumbers = ProductModel::search(["active" => 1, "id" => $search]);
if($pnumbers) {
$products = array_merge($products, $pnumbers);
}
}
$products = array_merge($products, ProductModel::search(["name%" => $search]));
$products = array_merge($products, ProductModel::search(["active" => 1, "name%" => $search]));
if(!is_array($products) && !count($products)) {
return false;
+33
View File
@@ -75,6 +75,21 @@ class ProductModel {
}
public static function getActive() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Product", "*", "active = 1 ORDER BY name,producttech_id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Product($data);
}
}
return $items;
}
public static function getFirst() {
$db = FronkDB::singleton();
@@ -162,6 +177,15 @@ class ProductModel {
}
}
if(array_key_exists("active", $filter)) {
$active = $filter['active'];
if($active) {
$where .= " AND Product.`active` = 1";
} else {
$where .= " AND Product.`active` = 0";
}
}
if(array_key_exists("productgroup_id", $filter)) {
$productgroup_id = $filter['productgroup_id'];
if(is_numeric($productgroup_id)) {
@@ -204,6 +228,15 @@ class ProductModel {
}
}
if(array_key_exists("external_id", $filter)) {
$external_id = $filter['external_id'];
if(is_numeric($external_id)) {
$where .= " AND external_id=$external_id";
} elseif(is_array($external_id) && count($external_id)) {
$where .= " AND Product.external_id IN (". implode(",", $external_id).")";
}
}
if(array_key_exists("external", $filter)) {
$external = $filter['external'];
if(is_numeric($external)) {
+15
View File
@@ -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");
+8 -13
View File
@@ -7,19 +7,12 @@ class Voicenumber extends mfBaseModel {
public function loadFromBlock(Voicenumberblock $block) {
$this->voicenumberblock_id = $block->id;
$this->countrycode = $block->countrycode;
$this->areacode = $block->areacode;
$this->number_prepend_zero = $block->number_prepend_zero;
//$this->countrycode = $block->countrycode;
//$this->areacode = $block->areacode;
//$this->number_prepend_zero = $block->number_prepend_zero;
return true;
}
public function getFullNumber() {
$number = $this->countrycode.$this->areacode.$this->number;
return $number;
}
public function beforeSave() {
if($this->ported_from && $this->port_in_date) {
$this->ported_in = 1;
@@ -32,9 +25,11 @@ class Voicenumber extends mfBaseModel {
} else {
$this->ported_out = 0;
}
if($this->active == 1 && !$this->_old_data->active) {
$this->activated_date = date("U");
//var_dump($this);exit;
if(is_array($this->_old_data) && count($this->_old_data)) {
if($this->active == 1 && !$this->_old_data->active) {
$this->activated_date = date("U");
}
}
}
@@ -47,7 +47,6 @@ class VoicenumberController extends mfBaseController {
$number->number = $num;
$mode = "add";
}
//var_dump($number);exit;
$this->layout()->setTemplate("Voicenumber/Form");
$this->layout()->set("number", $number);
@@ -57,7 +56,7 @@ class VoicenumberController extends mfBaseController {
protected function saveAction() {
$r = $this->request;
//var_dump($r);
//var_dump($r);exit;
$block_id = $r->block_id;
if(!is_numeric($block_id) || !$block_id) {
$this->layout()->setFlash("Rufnummer nicht gefunden1", "error");
@@ -96,7 +95,7 @@ class VoicenumberController extends mfBaseController {
$number_data = [];
$number_data['contract_id'] = $r->contract_id;
$number_data['contract_id'] = ($r->contract_id) ? $r->contract_id : null;
if($r->active === "1") {
$number_data['active'] = 1;
} else {
@@ -141,10 +140,15 @@ class VoicenumberController extends mfBaseController {
$number_data['disabled_reason'] = "reserved";
}
} else {
$number_data['disabled'] = 0;
$number_data['disabled_reason'] = null;
}
if($r->enable_on_date) {
$number_data['enable_on_date'] = self::dateToTimestamp($r->enable_on_date);
} else {
$number_data['enable_on_date'] = null;
}
$number_data['comment'] = $r->comment;
$number_data['edit_by'] = $this->me->id;
+19 -20
View File
@@ -1,12 +1,23 @@
<?php
class VoicenumberModel {
public $name;
public $voicenumberblock_id;
public $orderproduct_id;
public $contract_id;
public $active;
public $activated_date;
public $routing;
public $number;
public $countrycode;
public $areacode;
public $first;
public $last;
public $number_prepend_zero;
public $ported_from;
public $ported_to;
public $port_in_date;
public $port_out_date;
public $ported_in;
public $ported_out;
public $disabled;
public $disabled_reason;
public $enable_on_date;
public $comment;
public $create_by;
@@ -146,21 +157,9 @@ class VoicenumberModel {
}
if(array_key_exists("number", $filter)) {
$add_zero = false;
$number = $filter['number'];
mfLoghandler::singleton()->debug($number);
if(substr($number,0, 1) === "0") {
$add_zero = true;
$number = substr($number, 1);
}
if(is_numeric($number)) {
$where .= " AND number = $number";
if($add_zero) {
$where .= " AND number_prepend_zero = 1";
}
$number = $db->escape($filter['number']);
if($number) {
$where .= " AND number = '$number'";
}
}
@@ -5,46 +5,36 @@ class Voicenumberblock extends mfBaseModel {
private $number_first;
private $number_last;
private $base;
private $short_prefix;
private $short_first;
private $short_last;
private $files;
private $numbers;
private function getFullNumber($last = false) {
if($last) {
$number = $this->countrycode.$this->areacode.$this->getLast();
} else {
$number = $this->countrycode.$this->areacode.$this->getFirst();
}
return $number;
}
public function getFirst() {
if($this->number_prepend_zero) {
return "0".$this->first;
}
return $this->first;
}
public function getLast() {
if($this->number_prepend_zero) {
return "0".$this->last;
}
return $this->last;
}
public function getBaseNumber() {
$base = floor($this->first / pow(10, ceil(log10($this->last - $this->first))));
if($this->number_prepend_zero) {
return "0".$base;
}
return $base;
}
public function isNumberInBlock($number) {
return ($number >= $this->first && $number <= $this->last);
}
public static function findBlock($number) {
// resolve number from right to left to find fitting block
$minLength = 4;
$try = $number;
while(strlen($try) >= $minLength) {
$block = VoicenumberblockModel::getFirst(['prefix' => $try]);
if($block) {
break;
}
$try = substr($try, 0, strlen($try)-1);
}
if(!$block) {
return false;
}
return $block;
}
public function getProperty($name) {
if($this->$name == null) {
@@ -58,16 +48,17 @@ class Voicenumberblock extends mfBaseModel {
return $this->numbers;
}
if($name == "number_first") {
return $this->getFullNumber();
if($name == "short_prefix") {
$this->short_prefix = substr($this->prefix, strlen($this->countrycode.$this->areacode));
return $this->short_prefix;
}
if($name == "number_last") {
return $this->getFullNumber(true);
if($name == "short_first") {
$this->short_first = substr($this->first, strlen($this->countrycode.$this->areacode));
return $this->short_first;
}
if($name == "base") {
return $this->getBaseNumber();
if($name == "short_last") {
$this->short_last = substr($this->last, strlen($this->countrycode.$this->areacode));
return $this->short_last;
}
$classname = ucfirst($name);
@@ -4,9 +4,9 @@ class VoicenumberblockModel {
public $name;
public $countrycode;
public $areacode;
public $prefix;
public $first;
public $last;
public $number_prepend_zero;
public $comment;
public $create_by;
@@ -52,7 +52,7 @@ class VoicenumberblockModel {
}
public static function getFirst() {
public static function getFirst($filter = false) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
@@ -137,57 +137,32 @@ class VoicenumberblockModel {
}
}
if(array_key_exists("first", $filter)) {
$add_zero = false;
$first = $filter['first'];
mfLoghandler::singleton()->debug($first);
if(substr($first,0, 1) === "0") {
$add_zero = true;
$first = substr($first, 1);
if(array_key_exists("prefix", $filter)) {
$prefix = $filter['prefix'];
if(is_numeric($prefix)) {
$where .= " AND prefix = '$prefix'";
}
}
if(array_key_exists("first", $filter)) {
$first = $filter['first'];
if(is_numeric($first)) {
$where .= " AND first like '%$first%'";
if($add_zero) {
$where .= " AND number_prepend_zero = 1";
}
$where .= " AND first = '$first'";
}
}
if(array_key_exists("last", $filter)) {
$add_zero = false;
$last = $filter['last'];
mfLoghandler::singleton()->debug($last);
if(substr($last,0, 1) === "0") {
$add_zero = true;
$last = substr($last, 1);
}
if(is_numeric($last)) {
$where .= " AND last like '%$last%'";
$where .= " AND last = '$last'";
}
}
if(array_key_exists("number", $filter)) {
$add_zero = false;
$number = $filter['number'];
mfLoghandler::singleton()->debug($number);
if(substr($number,0, 1) === "0") {
$add_zero = true;
$number = substr($number, 1);
}
if(is_numeric($number)) {
$where .= " AND first <= $number AND last >= $number";
if($add_zero) {
$where .= " AND number_prepend_zero = 1";
}
}
}
+67
View File
@@ -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;
}
}
}