PHP Code:
<?php //much more above this
function displayproductoptions($grpnmstyle,$grpnmstyleend,&$optpricediff,$thetax,$isdetail,&$hasmulti){
global $rs,$prodoptions,$useStockManagement,$hideoptpricediffs,$pricezeromessage,$noprice,$OWSP,$xxPlsSel,$Count,$optionshavestock,$xxOpSkTx,$noshowoptionsinstock,$showinstock,$showtaxinclusive,$defimagejs,$multipurchasecolumns,$xxSelOpt,$xxClkHere,$startlink,$endlink;
$optpricediff = 0;
$optionshtml = '';
$hasmulti = FALSE;
foreach($prodoptions as $rowcounter => $theopt){
$opthasstock=false;
$sSQL='SELECT optID,'.getlangid('optName',32).','.getlangid('optGrpName',16).',' . $OWSP . 'optPriceDiff,optType,optFlags,optGrpSelect,optStock,optPriceDiff AS optDims,optDefault FROM options LEFT JOIN optiongroup ON options.optGroup=optiongroup.optGrpID WHERE optGroup=' . $theopt['poOptionGroup'] . ' ORDER BY optID';
$result = mysql_query($sSQL) or print(mysql_error());
if($rs2=mysql_fetch_array($result)){
if(abs((int)$rs2['optType'])==3){
$opthasstock=true;
$fieldHeight = round(((double)($rs2['optDims'])-(int)($rs2['optDims']))*100.0);
$optionshtml .= '<tr><td align="right" width="30%">' . $grpnmstyle . $rs2[getlangid('optGrpName',16)] . ':' . $grpnmstyleend . '</td><td align="left"> <input type="hidden" name="optn' . $rowcounter . '" value="' . $rs2["optID"] . '" />';
if($fieldHeight != 1){
$optionshtml .= '<textarea wrap="virtual" name="voptn' . $rowcounter . '" cols="' . (int)$rs2["optDims"] . '" rows="' . $fieldHeight . '">';
$optionshtml .= $rs2[getlangid('optName',32)] . '</textarea>';
}else
$optionshtml .= '<input maxlength="255" type="text" name="voptn' . $rowcounter . '" size="' . $rs2['optDims'] . '" value="' . str_replace('"','"',$rs2[getlangid('optName',32)]) . '" />';
$optionshtml .= '</td></tr>';
}elseif(abs((int)$rs2['optType'])==1){
$optionshtml .= '<tr><td align="right" valign="baseline" width="30%">' . $grpnmstyle . $rs2[getlangid('optGrpName',16)] . ':' . $grpnmstyleend . '</td><td align="left"> ';
do {
$optionshtml .= '<input type="radio" style="vertical-align:middle" onclick="updateoptimage('.$Count.','.$rowcounter.','.($isdetail?'1':'0').',1);' . (($rs['pPrice']==0 && @$pricezeromessage != '') || @$noprice==TRUE ?'dummyfunc':'updateprice' . $Count) . '();" name="optn' . $rowcounter . '" ';
if((int)$rs2['optDefault']!=0) $optionshtml .= 'checked ';
$optionshtml .= 'value="' . $rs2['optID'] . '" /><span ';
if($useStockManagement && $rs['pStockByOpts']!=0 && $rs2['optStock'] <= 0) $optionshtml .= ' class="oostock" '; else $opthasstock=true;
$optionshtml .= '>' . $rs2[getlangid('optName',32)];
if(@$hideoptpricediffs != TRUE && (double)($rs2['optPriceDiff']) != 0){
$optionshtml .= ' (';
if((double)($rs2['optPriceDiff']) > 0) $optionshtml .= '+';
if(($rs2['optFlags']&1)==1)$pricediff = ($rs['pPrice']*$rs2['optPriceDiff'])/100.0;else$pricediff = $rs2['optPriceDiff'];
if(@$showtaxinclusive===2 && ($rs['pExemptions'] & 2)!=2) $pricediff+=($pricediff*$thetax/100.0);
$optionshtml .= FormatEuroCurrency($pricediff) . ')';
if($rs2['optDefault']!=0) $optpricediff += $pricediff;
}
if($useStockManagement && @$showinstock==TRUE && @$noshowoptionsinstock != TRUE && (int)$rs["pStockByOpts"] != 0) $optionshtml .= str_replace('%s', $rs2['optStock'], $xxOpSkTx);
$optionshtml .= '</span>';
if(($rs2['optFlags'] & 4) != 4) $optionshtml .= "<br />\r\n";
} while($rs2=mysql_fetch_assoc($result));
$optionshtml .= '</td></tr>';
}elseif(abs((int)$rs2['optType'])==4){
if(@$multipurchasecolumns=='') $multipurchasecolumns=2;
$colwid=(int)(100/$multipurchasecolumns);
if((int)$rs2['optGrpSelect']!=0 && ! $isdetail){
$hasmulti = 2;
}else{
$index = 0;
do {
if($useStockManagement && $rs['pStockByOpts']!=0 && $rs2['optStock'] <= 0) $oostock=TRUE; else $oostock=FALSE;
if(($index % $multipurchasecolumns) == 0) $optionshtml .= '<tr>';
$optionshtml .= '<td width="'.$colwid.'%" align="left"> <input type="text" name="optn'.$rs2['optID'].'" size="1" '.($oostock?'style="background-color:#EBEBE4" disabled':'').'/>';
$optionshtml .= '<span class="multioption';
if($oostock) $optionshtml .= ' oostock"'; else{ $optionshtml .= '"'; $opthasstock=TRUE; }
$optionshtml .= '> - ' . $rs2[getlangid('optName',32)];
if(@$hideoptpricediffs != TRUE && (double)$rs2['optPriceDiff'] != 0){
$optionshtml .= ' (';
if((double)$rs2['optPriceDiff'] > 0) $optionshtml .= '+';
if(($rs2['optFlags']&1)==1)$pricediff = ($rs['pPrice']*$rs2['optPriceDiff'])/100.0;else $pricediff = $rs2['optPriceDiff'];
if(@$showtaxinclusive===2 && ($rs['pExemptions'] & 2)!=2) $pricediff+=($pricediff*$thetax/100.0);
$optionshtml .= FormatEuroCurrency($pricediff) . ')';
}
if($index==0) $optionshtml .= '<input type="hidden" name="ismulti" value="1" />';
$optionshtml .= '</span></td>';
$index++;
if(($index % $multipurchasecolumns) == 0) $optionshtml .= '</tr>';
} while($rs2=mysql_fetch_assoc($result));
if(($index % $multipurchasecolumns) != 0){
while(($index % $multipurchasecolumns) != 0){
if($index>=$multipurchasecolumns) $optionshtml .= '<td> </td>';
$index++;
}
if(($index % $multipurchasecolumns) == 0) $optionshtml .= '</tr>';
}
$hasmulti = 1;
}
}else{
$optionshtml .= '<tr><td align="right" width="30%">' . $grpnmstyle . $rs2[getlangid('optGrpName',16)] . ':' . $grpnmstyleend . '</td><td align="left"> <select class="prodoption" onchange="' . (($rs['pPrice']==0 && @$pricezeromessage != '') || @$noprice==TRUE ?'dummyfunc':'updateprice' . $Count) . '();updateoptimage('.$Count.','.$rowcounter.','.($isdetail?'1':'0').');" name="optn' . $rowcounter . '" size="1">';
$defimagejs .= 'updateoptimage('.$Count.','.$rowcounter.','.($isdetail?'1':'0').',2);';
$gotdefaultdiff = FALSE;
$firstpricediff = 0;
if((int)$rs2['optGrpSelect']!=0)
$optionshtml .= '<option value="">' . $xxPlsSel . '</option>';
else
if(($rs2['optFlags']&1)==1)$firstpricediff = ($rs['pPrice']*$rs2['optPriceDiff'])/100.0;else $firstpricediff = $rs2['optPriceDiff'];
do {
$optionshtml .= '<option ';
if($useStockManagement && $rs['pStockByOpts']!=0 && $rs2['optStock'] <= 0) $optionshtml .= 'class="oostock" '; else $opthasstock=true;
$optionshtml .= 'value="' . $rs2['optID'] . '"'.((int)$rs2['optDefault']!=0?' selected':'').'>' . $rs2[getlangid('optName',32)];
if(@$hideoptpricediffs != TRUE){
if((double)($rs2['optPriceDiff']) != 0){
$optionshtml .= ' (';
if((double)($rs2['optPriceDiff']) > 0) $optionshtml .= '+';
if(($rs2['optFlags']&1)==1)$pricediff = ($rs['pPrice']*$rs2['optPriceDiff'])/100.0;else $pricediff = $rs2['optPriceDiff'];
if(@$showtaxinclusive===2 && ($rs['pExemptions'] & 2)!=2) $pricediff+=($pricediff*$thetax/100.0);
$optionshtml .= FormatEuroCurrency($pricediff) . ')';
if($rs2['optDefault']!=0)$optpricediff += $pricediff;
}
if($rs2['optDefault']!=0)$gotdefaultdiff=TRUE;
}
if($useStockManagement && @$showinstock==TRUE && @$noshowoptionsinstock != TRUE && (int)$rs["pStockByOpts"] != 0) $optionshtml .= str_replace('%s', $rs2['optStock'], $xxOpSkTx);
$optionshtml .= "</option>\n";
} while($rs2=mysql_fetch_assoc($result));
if(@$hideoptpricediffs != TRUE && ! $gotdefaultdiff) $optpricediff += $firstpricediff;
$optionshtml .= '</select></td></tr>';
}
}
$optionshavestock = ($optionshavestock && $opthasstock);
}
return($optionshtml);
}
This is using arrays and loops for the different product option input types, right?