PHP-Code:
<?php if(!defined('TL_ROOT')) die('You can not access this file directly!');
class wdgSlidingPriceSpecial extends Widget {
protected $blnSubmitInput = true;
protected $strTemplate = 'wdg_SlidingPriceSpecial';
public function __construct($arrAttributes=false) {
parent::__construct($arrAttributes);
$this->decodeEntities = true;
}
public function __set($strKey, $varValue) {
switch ($strKey) {
case 'slidingPriceSpecial': {
$this->varValue = deserialize($varValue);
}
break;
default:
parent::__set($strKey, $varValue);
break;
}
}
protected function validator($varInput) {
if (is_array($varInput)) {
return parent::validator($varInput);
}
return parent::validator(trim($varInput));
}
public function generate() {
}
public function generateFormFields() {
$this->Import("Database", "Database");
$res = $this->Database->prepare("SELECT * from tl_warenwirtschaft_sp_numbers order by name ASC")->execute();
while($res->next())
{
$arrGroups[$res->id] = array("name" => $res->name, "id" => $res->id);
}
$arrFields = array();
$groupbox = "<option value=\"0\">0</option>";
foreach($arrGroups as $g) {
if($g["name"] == 1) continue;
$groupbox .= "<option value=\"". $g["id"] ."\">". $g["name"] ."</option>";
}
echo $this->vd($this->varValue);
if(is_array($this->varValue)) {
$arrG = $this->varValue["group"];
$arrV = $this->varValue["value"];
$arrS = $this->varValue["special"];
$arrNS = $this->varValue["nesos_spend"];
$arrNG = $this->varValue["nesos_get"];
$arrB = $this->varValue["baseprice"];
//$this->vd($this->varValue);
foreach($arrG as $index => $group) {
if($arrV[$index] == "") continue;
$groupbox = "<option value=\"0\">0</option>";
// Kill the -
foreach($arrGroups as $g) {
if($g["id"] == $group)
$add = " selected=\"selected\"";
else
$add = "";
$groupbox .= "<option value=\"". $g["id"] ."\"$add>". $g["name"] ."</option>";
}
$arrV[$index] = $this->formatSinglePrice($arrV[$index]);
if(!empty($arrS[$index]))
$arrS[$index] = $this->formatSinglePrice($arrS[$index]);
// Gewinn ermitteln und runden
$tempGewinn = floor($arrV[$index] - $arrB[$index]);
$res = $this->Database->prepare ( "SELECT profit, nesos, invest FROM tl_warenwirtschaft_nesos WHERE profit=?" )->limit(1)->execute($tempGewinn);
$arrNG[$index] = $res->nesos;
// NESOS Invest errechnen
$tempInvest = floor($arrV[$index]) * $res->invest;
$arrNS[$index] = $tempInvest;
$arrFields[] = sprintf('
<tr><td><select name="%s[group][]">%s</select></td>
<td><input type="text" name="%s[value][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td>
<td><input type="text" name="%s[special][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td>
<td><input type="text" name="%s[nesos_spend][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td>
<td><input type="text" name="%s[nesos_get][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td>
<td><input type="text" name="%s[baseprice][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td></tr>',
$this->strName,
$groupbox,
$this->strName,
$this->strId.'_'.$i,
specialchars($arrV[$index]),
$this->strName,
$this->strId.'_'.$i,
specialchars($arrS[$index]),
$this->strName,
$this->strId.'_'.$i,
specialchars($arrNS[$index]),
$this->strName,
$this->strId.'_'.$i,
specialchars($arrNG[$index]),
$this->strName,
$this->strId.'_'.$i,
specialchars($arrB[$index])
);
}
}
// Ausgabe der Eingabefelder
$groupbox = "<option value=\"0\">0</option>";
foreach($arrGroups as $g) {
$groupbox .= "<option value=\"". $g["id"] ."\">". $g["name"] ."</option>";
}
$arrFields[] = sprintf('
<tr><td><select name="%s[group][]">%s</select></td>
<td><input type="text" name="%s[value][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td>
<td><input type="text" name="%s[special][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td>
<td><input type="text" name="%s[nesos_spend][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td>
<td><input type="text" name="%s[nesos_get][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td>
<td><input type="text" name="%s[baseprice][]" id="ctrl_%s" class="tl_text_pricesspecial" value="%s" onfocus="Backend.getScrollOffset();" /></td></tr>',
$this->strName,
$groupbox,
$this->strName,
$this->strId.'_'.$i,
'',
$this->strName,
$this->strId.'_'.$i,
'',
$this->strName,
$this->strId.'_'.$i,
'',
$this->strName,
$this->strId.'_'.$i,
'',
$this->strName,
$this->strId.'_'.$i,
''
);
return sprintf('%s', implode(' ', $arrFields));
$i++;
}
public function formatSinglePrice($varValue) {
$c = explode(",", $varValue);
if(empty($c[1]))
return(number_format($varValue, 2, '.', ''));
else
return str_replace(',', '.', $varValue);
}
}
?>
Da man zwei Felder eigentlich nicht ändern darf habe ich diese als disabled gekennzeichnet (Also bei input type="text" usw.). Sobald diese aber als disabled gekennzeichnet sind, übernimmt mir Contao davon nicht die Werte und schreibt diese auch nicht in die Datenbank. Hab dann einmal mir das Array ausgeben lassen, was gespeichert werden soll und bei disabled input type="text" werden dann diese Werte tatsächlich nicht beachtet...
Lesezeichen