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 = '
{|Druckerspezifische Einstellungen|} '; } if($oneCol){ $html .= ''; } } $tag = !empty($val['tag'])?$val['tag']:''; $placeholder = !empty($val['placeholder'])?$val['placeholder']:''; $size = !empty($val['size'])?$val['size']:''; $rows = !empty($val['rows'])?$val['rows']:''; if(isset($val['replace'])) { switch($val['replace']) { case 'lieferantennummer': $json[$name] = $this->app->erp->ReplaceLieferantennummer(0,$json[$name],0); if($target !== 'return') { $this->app->YUI->AutoComplete($name, 'lieferant', 1); } break; case 'lagerplatz': $json[$name] = $this->app->erp->ReplaceLagerPlatz(0, $json[$name], 0); if($target !== 'return') { $this->app->YUI->AutoComplete($name, 'lagerplatz', 0); } break; case 'artikelnummer': $json[$name] = $this->app->erp->ReplaceArtikel(0,$json[$name],0); if($target !== 'return') { $this->app->YUI->AutoComplete($name, 'artikelnummer', 1); } break; case 'shop': $json[$name] .= ($json[$name]?' '.$this->app->DB->Select("SELECT bezeichnung FROM shopexport WHERE id = '".(int)$json[$name]."'"):''); if($target !== 'return') { $this->app->YUI->AutoComplete($name, 'shopnameid'); } break; case 'etiketten': if($target !== 'return') { $this->app->YUI->AutoComplete($name, 'etiketten'); } break; } } switch($typ) { case 'textarea': $html .= ''; break; case 'checkbox': $html .= ''; break; case 'select': $html .= ''; break; case 'submit': if(isset($val['text'])) { $html .= '
'; } break; case 'custom': if(isset($val['function'])) { $tmpfunction = $val['function']; if(method_exists($this, $tmpfunction)) { $html .= $this->$tmpfunction(); } } break; case 'hidden': $html .= ''; break; default: if($typ === 'time' || $typ === 'zeit') { $this->app->YUI->TimePicker($name); } elseif($typ === 'date' || $typ === 'datum') { $this->app->YUI->DatePicker($name); } $html .= ''; break; } if(isset($val['info']) && $val['info']) { $html .= ' '.$val['info'].''; } if($typ === 'hidden') { continue; } $html .= '
'; $first = false; } if($target !== 'return'){ $this->app->Tpl->Add($target, $html); } return $html; } }
'; }else{ $html = ''; } $json = $this->app->DB->Select("SELECT json FROM drucker WHERE id = '$id' LIMIT 1"); if(!empty($json)) { $json = json_decode($json, true); } else { $json = null; } foreach($struktur as $name => $val) { $changed = false; if(isset($val['default']) && !isset($json[$name])) { $changed = true; $json[$name] = $val['default']; } } if(!empty($changed)) { $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"); } $first = true; foreach($struktur as $name => $val) { $tdtag = !empty($val['tdtag'])?$val['tdtag']:''; $oneCol = !empty($val['onecol']); $typ = 'text'; if(!empty($val['typ'])) { $typ = $val['typ']; } if($typ === 'hidden') { } else{ if(isset($val['heading'])){ $html .= '
' . html_entity_decode($val['heading']) . '
' . ($first ? '' : '') . (empty($val['bezeichnung']) ? $name : $val['bezeichnung']) . '
'; }else{ $html .= '
' . ($first ? '' : '') . (empty($val['bezeichnung']) ? $name : $val['bezeichnung']) . '