global $sATC;
global $sOOS;
global $sProdRef;
global $sInvalidPermutation;
$sATC = '';
$sOOS = '';
$sProdRef = '';
$sInvalidPermutation = '';
//
// Code inside a PHP block will be rendered first in the standard way, i.e. variable references are substituted, content lists are looped.
// After that the result of standard rendering will be executed as a PHP script.
// The output of the PHP script will be the rendered result of this markup code block
//
//
// As this is an attribute design, we are inside an attribute list
// Store the index of current attribute, as we render the next N attribute in the button grid
//
$nBaseAttributeIdx = ;
//
// Get the number of attribute in Columns and number of attributes in Rows from local variables
//
$nAttributeCount = ;
$nAttribs = min( , $nAttributeCount);
$n1 = round($nAttribs / 2);
$n2 = $nAttribs - $n1;
if ( $nAttribs == 1 )
{
$nXAttributeCount = 1;
$nYAttributeCount = 0;
}
else
{
if ($n1 > $n2)
{
$nYAttributeCount = $n1;
$nXAttributeCount = $n2;
}
else
{
$nYAttributeCount = $n2;
$nXAttributeCount = $n1;
}
}
//
// Now loop through all the attributes of the given product and collect all informatiuon for rendering in vectors
// We need to loop through all the attributes, as we can't loop content lists for a given range only
//
// This is a special in-place content list rendering.
// The block loops thorough all attributes of the current product, renders the enclosed block for each attribute, and concatenates the results
// In this case the output is intended to be a valid PHP code of course
//
unset( $listHeaderDesigns );
$listHeaderDesigns = array();
//
// Store current list index for PHP
//
$nAttributeListIdx = ;
//
// Remember attribute widget (e.g. v_9_2, which means 2nd attribute of product "ref=9"
//
$listAttributeWidgets[$nAttributeListIdx] = '';
//
// Loop through all the choices of current attribute and render COLUMN/ROW HEADERS
//
$listHeaderDesigns[$nAttributeListIdx][0] = "";
$nChoiceListIdx = 1;
//
// Render Column/Row header for current choice
//
$listHeaderDesigns[$nAttributeListIdx][$nChoiceListIdx] = <<
FREE_MARKUP_CODE_BLOCK;
//
// Remember Choice ID as well
//
$listChoiceIds[$nAttributeListIdx][$nChoiceListIdx][0] = ;
$listChoiceIds[$nAttributeListIdx][$nChoiceListIdx][1] = ;
$nChoiceListIdx++;
//
// Fill the array of permutations
//
$listPermutations = array();
$IsProductInStock = array();
$nPermutationListIdx = ;
$nChoiceListIdx = ;
$listPermutations[ $nPermutationListIdx ][ 0 ][ $nChoiceListIdx - 1 ] = ;
$listPermutations[ $nPermutationListIdx ][ 1 ] = ;
$IsProductInStock[ $nPermutationListIdx ] = ;
//
// Validate parameters
//
if (($nYAttributeCount < 0) ||
($nYAttributeCount > 100))
{
echo ' Wrong y attribute count ';
exit(0);
}
if (($nXAttributeCount < 0) ||
($nXAttributeCount > 100))
{
echo ' Wrong x attribute count ';
exit(0);
}
//
// Check if we have enough attributes to display
//
if (($nBaseAttributeIdx - 1 + $nYAttributeCount + $nXAttributeCount) > count($listHeaderDesigns))
{
echo ' There are not enough attributes for displaying the object ';
exit(0);
}
//
// If we have 1 or 2 attributes, then display attribute name in cell (0,0)
//
$sHeaderDesign = "";
if ($nXAttributeCount + $nYAttributeCount <= 2)
{
$sHeaderDesign .= "";
for ($nAttributeIdx = count($listHeaderDesigns); $nAttributeIdx >= $nBaseAttributeIdx; $nAttributeIdx--)
{
$sHeaderDesign .= $listHeaderDesigns[$nAttributeIdx][0];
if ($nAttributeIdx > $nBaseAttributeIdx)
{
$sHeaderDesign .= "";
}
}
$sHeaderDesign .= "";
}
//
// Start putting the table together
//
//
// We need hidden input fields so that scripts can identify the selected choice-combination
// However as initially we don't know which grid-cell will be selected, leave the value of these fields empty
// We will fill-in the values by JavaScript when a button is pressed
//
for ($nAttributeIdxOffset = 1; $nAttributeIdxOffset <= $nXAttributeCount + $nYAttributeCount; $nAttributeIdxOffset++)
{
echo "";
}
//
// If there is only a single row, then display column header here
//
if ($nYAttributeCount == 0 && $nXAttributeCount == 1)
{
echo $sHeaderDesign;
echo "";
}
//
// Output table start tag
//
echo '
';
//
// Draw table header rows
// Loop through Y-attributes and render a row for each of them
// Fields in second row are repeated by the number of choices in first row,
// Fields in third row are repeated by the number of choices in first row and second row
//
$nRepeatChoicesBy = 1; // we clone the content of a row this times
for ($nColumnIdx = 1; $nColumnIdx <= $nYAttributeCount; $nColumnIdx++)
{
//
// Row start tag
//
echo "";
//
// (0,0) cell is exceptional, it's a big merged cell with no choice
//
if ($nColumnIdx == 1)
{
echo $sHeaderDesign;
}
//
// Get number of choices of current Y-attribute
//
$nAttributeChoiceCount = count($listHeaderDesigns[$nBaseAttributeIdx + $nColumnIdx - 1]) - 1;
//
// Determine table cell offset, i.e. how many columns this choice occupies
//
$nColSpan = 1;
for ($nAttributeIdx = $nColumnIdx + 1; $nAttributeIdx <= $nYAttributeCount; $nAttributeIdx++)
{
$nColSpan *= (count($listHeaderDesigns[$nBaseAttributeIdx + $nAttributeIdx - 1]) - 1);
}
//
// Draw header table cells - one for each choice
//
for ($nRepeat = 1; $nRepeat <= $nRepeatChoicesBy; $nRepeat++)
{
for ($nChoiceIdx = 1; $nChoiceIdx <= $nAttributeChoiceCount; $nChoiceIdx++)
{
echo $listHeaderDesigns[$nBaseAttributeIdx + $nColumnIdx - 1][$nChoiceIdx];
}
}
//
// Content of the next row should be repeated for each choice in this row
//
$nRepeatChoicesBy = $nRepeatChoicesBy * $nAttributeChoiceCount;
//
// Row end tag
//
echo "";
}
//
// Draw table rows
//
$listCellChoiceIndices = array();
$nAttributeIdx = 1;
$sRowHeader = "";
drawRows($nAttributeIdx, $listCellChoiceIndices, $sRowHeader);
//
// Close table tag
//
echo "