<?php
require 'common.php';
// If extension is not available, use script implementation
if (!extension_loaded('template'))
    include(
'../include/template.php');

$categories 3;
$questions 5;
$options 10;

$tpl = new Template('advanced.tpl');

// Set some fields
$tpl->setField('SCRIPT_FILE''advanced.php');
$tpl->setField('CATEGORIES'$categories);
$tpl->setFieldGlobal('QUESTIONS'$questions);
$tpl->setField('OPTIONS'$options);

// Focus on category section
$tpl->selectSection('CATEGORY');

// Add categories to document
for ($i=1$i<=$categories$i++)
{
    
// Number in category title
    
$tpl->setField('CATEGORY_NR'$i);

    
$tpl->selectSection('QUESTION');

    
// Insert questions in this category
    
for ($j=1$j<=$questions$j++)
    {
        
// Set different style for even and odd rows
        
$tpl->setField('TYPE'$j%2);

        
// Set question name (to a number)
        
$tpl->setField('QUESTION_NR'$j+($i-1)*$questions);

        
// Fill out options for this question
        
$tpl->selectSection('OPTION');
        for (
$k=1$k<=$options$k++)
        {
            
// Set option value and name (to a number)
            
$tpl->setField('OPTION_VAL'$k+($j+($i-1)*$questions-1)*$options);
            
$tpl->appendSection();
            
        }
        
// Go back to parent template
        
$tpl->deselectSection();

        
$tpl->appendSection();
    }
    
$tpl->deselectSection();
    
$tpl->appendSection();
}
$tpl->deselectSection();

// Write document to browser
echo $tpl->getContent();
?>