| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 | 
							- <?php
 
- require_once('../templates/templates.php');
 
- $cacheQuestions = array();
 
- $cacheChoices = array();
 
- function loadQuestionTemplate ($type) {
 
-    global $cacheQuestions;
 
-    if (!isset($cacheQuestions[$type])) {
 
-       $cacheQuestions[$type] = getTemplate(strtolower("question_$type.html"));
 
-    }
 
-    return $cacheQuestions[$type];
 
- }
 
- function loadChoicesTemplate ($type) {
 
-    global $cacheChoices;
 
-    if (!isset($cacheChoices[$type])) {
 
-       $cacheChoices[$type] = getTemplate(strtolower("choice_$type.html"));
 
-    }
 
-    return $cacheChoices[$type];
 
- }
 
- function generateFormHTML ($form) {
 
-    $pageCount = 1;
 
-    $formText = "";
 
-    $content = "";
 
-    $questions = $form['questions'];
 
-    $pageTemplate = getTemplate('form_page.html');
 
-    foreach ($questions as $question) {
 
-       if ($question->type === 'PAGEBREAK') {
 
-          if (strlen($content) > 0) {
 
-             $context = array('page_number'=>$pageCount,'questions'=>$content);
 
-             $formText = $formText . parseTemplate($pageTemplate, $context);
 
-             $pageCount++;
 
-             $content = "";
 
-          }
 
-          continue;
 
-       }
 
-       $questionTemplate = loadQuestionTemplate($question->type);
 
-       $required = "";
 
-       if (property_exists($question,'required')) {
 
-          $required = "required";
 
-       }
 
-       $context = array('id'=>$question->number,'text'=>$question->text, 'required'=>$required);
 
-       if (in_array($question->type, array('S','M'))) {
 
-          $context['choices'] = generateChoices($question);
 
-       }
 
-       $content = $content . parseTemplate($questionTemplate, $context);
 
-    }
 
-    if (strlen($content) > 0) {
 
-       $context = array('page_number'=>$pageCount,'questions'=>$content);
 
-       $formText = $formText . parseTemplate($pageTemplate, $context);
 
-    }
 
-    $formTemplate = getTemplate('form.html');
 
-    $context = ['title'=>$form['title'], 'description'=>$form['description'], 'pages'=>$formText, 'form_id'=>$form['id']];
 
-    return parseTemplate($formTemplate, $context);
 
- }
 
- function generateChoices ($question) {
 
-    $choices = $question->choices;
 
-    $content = "";
 
-    $template = loadChoicesTemplate($question->type);
 
-    for ($i = 0; $i < count($choices); $i++) {
 
-       $choice = $choices[$i];
 
-       $context = ['id' => $question->number, 'count' => $i, 'value'=>$choice->value, 'text'=>$choice->text];
 
-       $content = $content . parseTemplate($template, $context);
 
-    }
 
-    return $content;
 
- }
 
 
  |