app = $app;
$this->id = $id;
$this->getSettings();
}
/**
* @return mixed|null
*/
public function getSettings()
{
if($this->id <= 0) {
return null;
}
$this->printerdata = $this->app->DB->SelectRow('SELECT * FROM drucker WHERE id = ' . $this->id);
if(!empty($this->printerdata['json'])) {
$this->settings = @json_decode($this->printerdata['json'], true);
}
elseif(!empty($this->stucture)){
foreach($this->stucture as $name => $val) {
if(isset($val['default'])) {
$this->settings[$name] = $val['default'];
}
}
}
if(empty($this->settings)) {
$this->settings = null;
}
return $this->settings;
}
/**
* @param string $name
* @param mixed $value
*
* @return mixed|null
*/
public function setSetting($name, $value) {
$this->getSettings();
$this->settings[$name] = $value;
$this->app->DB->Update(
sprintf(
'UPDATE drucker SET json = \'%s\' WHERE id = %d LIMIT 1',
$this->app->DB->real_escape_string(json_encode($this->settings)), $this->id
)
);
return $this->getSettings();
}
/**
* @return array
*/
public function getPrinterData()
{
if(empty($this->printerdata)) {
$this->getSettings();
}
return $this->printerdata;
}
/**
* @return null
*/
public function SettingsStructure()
{
return null;
}
/**
* @return array|null
*/
public function getStructure()
{
$this->stucture = $this->SettingsStructure();
return $this->stucture;
}
/**
* @param string $target
* @param null|array $struktur
*
* @return string|null
*/
public function Settings($target = 'return', $struktur = null)
{
if(!$this->id)
{
return null;
}
if($struktur === null){
$struktur = $this->getStructure();
} else {
$this->stucture = $struktur;
}
$this->getSettings();
if($this->app->Secure->GetPOST('anbindung')) {
$printer = $this->printerdata;
$json = $this->settings;
$modul = $printer['anbindung'];
if(!empty($struktur)) {
foreach ($struktur as $name => $val) {
if($modul === $this->app->Secure->GetPOST('anbindung')){
$json[$name] = $this->app->Secure->GetPOST($name, '', '', 1);
}
if(isset($val['replace'])){
switch ($val['replace']) {
case 'lieferantennummer':
$json[$name] = $this->app->erp->ReplaceLieferantennummer(1, $json[$name], 1);
break;
case 'shop':
$json[$name] = explode(' ', $json[$name]);
$json[$name] = reset($json[$name]);
break;
case 'lagerplatz':
$json[$name] = $this->app->erp->ReplaceLagerPlatz(1, $json[$name], 1);
break;
case 'artikelnummer':
$tmp = trim($json[$name]);
$rest = explode(' ',$tmp);
$rest = $rest[0];
$json[$name] = $this->app->DB->Select(
sprintf(
"SELECT id
FROM artikel
WHERE nummer='%s' AND nummer!='' AND geloescht=0
ORDER BY projekt = %d DESC
LIMIT 1",
$rest, $this->printerdata['projekt']
)
);
break;
}
}
}
}
$json_str = $this->app->DB->real_escape_string(json_encode($json));
$this->app->DB->Update("UPDATE drucker SET json = '$json_str' WHERE id = '".$this->id."' LIMIT 1");
}
$id = $this->id;
if(!empty($struktur)) {
$html = '