/**
  * edits a record
  */
 public function mod()
 {
     $question =& $this->_r;
     $nodo = new Node($this->test['id_nodo_riferimento']);
     if (!AMATestDataHandler::isError($nodo)) {
         $path = $nodo->findPathFN();
     }
     if ($_POST) {
         $data = $_POST;
     } else {
         $data = array('nome' => $question['nome'], 'titolo' => $question['titolo'], 'consegna' => $question['consegna'], 'testo' => $question['testo'], 'commento' => $question['tipo'][2], 'didascalia' => $question['didascalia'], 'titolo_dragdrop' => $question['titolo_dragdrop'], 'id_nodo_parent' => $question['id_nodo_parent'], 'correttezza' => $question['correttezza']);
         switch ($question['tipo'][1]) {
             case ADA_STANDARD_TEST_TYPE:
             case ADA_MULTIPLE_CHECK_TEST_TYPE:
                 $data['variant'] = $question['tipo'][3];
                 break;
             case ADA_CLOZE_TEST_TYPE:
                 switch ($question['tipo'][3]) {
                     case ADA_SELECT_TEST_SIMPLICITY:
                         $data['cloze_sinonimi'] = $question['tipo'][4];
                         break;
                     case ADA_DRAGDROP_TEST_SIMPLICITY:
                     case ADA_SLOT_TEST_SIMPLICITY:
                         $data['box_position'] = $question['tipo'][4];
                         break;
                     case ADA_ERASE_TEST_SIMPLICITY:
                         $data['variant'] = $question['tipo'][4];
                         $data['cloze_apostrofo'] = $question['tipo'][5];
                         break;
                     case ADA_MULTIPLE_TEST_SIMPLICITY:
                         $data['box_position'] = $question['tipo'][4];
                         $data['cloze_apostrofo'] = $question['tipo'][5];
                         break;
                 }
                 break;
         }
     }
     unset($_SESSION['new_question'][$data['id_nodo_parent']]);
     require_once MODULES_TEST_PATH . '/include/forms/questionFormTest.inc.php';
     $form = $this->instantiateObject($question['id_nodo_radice'], $data, $question['id_nodo_parent'], $question['tipo'][1], $question['tipo'][3]);
     if ($_POST) {
         if ($form->isValid()) {
             //crea nuovo test con i dati del form
             $this->setTipo();
             $data = array('nome' => $_POST['nome'], 'titolo' => $_POST['titolo'], 'consegna' => Node::prepareInternalLinkMediaForDatabase($_POST['consegna']), 'testo' => Node::prepareInternalLinkMediaForDatabase($_POST['testo']), 'id_nodo_parent' => $_POST['id_nodo_parent'], 'tipo' => $this->getTipo(), 'didascalia' => $_POST['didascalia'], 'titolo_dragdrop' => $_POST['titolo_dragdrop'], 'correttezza' => $_POST['correttezza']);
             if ($this->saveQuestion($data, $question['id_nodo'])) {
                 $get_topic = isset($_GET['topic']) ? '&topic=' . $_GET['topic'] : '';
                 redirect(MODULES_TEST_HTTP . '/index.php?id_test=' . $question['id_nodo_radice'] . $get_topic . '#liQuestion' . $question['id_nodo']);
             } else {
                 $html = sprintf(translateFN('Errore durante la modifica del %s'), $this->what);
             }
         } else {
             $html = $form->getHtml();
         }
     } else {
         $html = $form->getHtml();
     }
     return array('html' => $html, 'path' => $path);
 }
 /**
  * modifies a topic node
  *
  * @global db $dh
  *
  * @return array an array with 'html' and 'path' keys
  */
 public function mod()
 {
     $dh = $GLOBALS['dh'];
     $topic =& $this->_r;
     $test = $dh->test_getNode($topic['id_nodo_radice']);
     $nodo = new Node($test['id_nodo_riferimento']);
     if (!AMATestDataHandler::isError($nodo)) {
         $path = $nodo->findPathFN();
     }
     if ($_POST) {
         $data = $_POST;
     } else {
         $data = array('nome' => $topic['nome'], 'titolo' => $topic['titolo'], 'testo' => $topic['testo'], 'durata' => round($topic['durata'] / 60, 2), 'random' => $topic['tipo'][1], 'random_number' => $topic['livello'], 'id_nodo_parent' => $topic['id_nodo_parent']);
     }
     require_once MODULES_TEST_PATH . '/include/forms/topicFormTest.inc.php';
     $form = new TopicFormTest($topic['id_nodo_radice'], $data, $topic['id_nodo_parent']);
     if ($_POST) {
         if ($form->isValid()) {
             //crea nuovo test con i dati del form
             $this->setTipo();
             $data = array('nome' => $_POST['nome'], 'titolo' => $_POST['titolo'], 'testo' => Node::prepareInternalLinkMediaForDatabase($_POST['testo']), 'id_nodo_parent' => $_POST['id_nodo_parent'], 'tipo' => $this->getTipo(), 'livello' => $_POST['random_number'], 'durata' => $_POST['durata'] * 60);
             if ($dh->test_updateNode($topic['id_nodo'], $data)) {
                 $get_topic = isset($_GET['topic']) ? '&topic=' . $_GET['topic'] : '';
                 redirect(MODULES_TEST_HTTP . '/index.php?id_test=' . $test['id_nodo'] . $get_topic);
             } else {
                 $html = sprintf(translateFN('Errore durante la modifica del %s'), $this->what);
             }
         } else {
             $html = $form->getHtml();
         }
     } else {
         $html = $form->getHtml();
     }
     return array('html' => $html, 'path' => $path);
 }
 /**
  * modifies test / survey node
  *
  * @global db $dh
  *
  * @return array an array with 'html' and 'path' keys
  */
 public function mod()
 {
     $dh = $GLOBALS['dh'];
     $test =& $this->_r;
     $nodo = new Node($test['id_nodo_riferimento']);
     if (!AMATestDataHandler::isError($nodo)) {
         $path = $nodo->findPathFN();
     }
     if ($_POST) {
         $data = $_POST;
     } else {
         $data = array('nome' => $test['nome'], 'consegna' => $test['consegna'], 'titolo' => $test['titolo'], 'consegna' => Node::prepareInternalLinkMediaForDatabase($test['consegna']), 'testo' => Node::prepareInternalLinkMediaForDatabase($test['testo']), 'livello' => $test['livello'], 'min_level' => $test['durata'], 'return' => $test['tipo'][1], 'feedback' => $test['tipo'][2], 'suddivisione' => $test['tipo'][3], 'barriera' => $test['tipo'][4], 'ripetibile' => $test['tipo'][5], 'correttezza' => $test['correttezza']);
     }
     require_once MODULES_TEST_PATH . '/include/forms/rootFormTest.inc.php';
     if (get_class($this) == 'TestManagementTest') {
         require_once MODULES_TEST_PATH . '/include/forms/testFormTest.inc.php';
         $form = new TestFormTest($data);
     } else {
         if (get_class($this) == 'SurveyManagementTest') {
             require_once MODULES_TEST_PATH . '/include/forms/surveyFormTest.inc.php';
             $form = new SurveyFormTest($data);
         }
     }
     if ($_POST) {
         if ($form->isValid()) {
             //crea nuovo test con i dati del form
             $this->setTipo();
             $data = array('nome' => $_POST['nome'], 'titolo' => $_POST['titolo'], 'consegna' => $_POST['consegna'], 'testo' => $_POST['testo'], 'tipo' => $this->getTipo(), 'livello' => $_POST['livello'], 'durata' => $_POST['min_level'], 'correttezza' => $_POST['correttezza']);
             if ($dh->test_updateNode($test['id_nodo'], $data)) {
                 redirect(MODULES_TEST_HTTP . '/index.php?id_test=' . $test['id_nodo']);
             } else {
                 $html = sprintf(translateFN('Errore durante la modifica del %s'), $this->what);
             }
         } else {
             $html = $form->getHtml();
         }
     } else {
         $html = $form->getHtml();
     }
     return array('html' => $html, 'path' => $path);
 }
 /**
  * Function that executes answer logic (add / mod)
  *
  * @global db $dh
  * 
  * @return string
  */
 protected function action()
 {
     $dh = $GLOBALS['dh'];
     $tmp = $dh->test_getNodesByParent($this->question['id_nodo']);
     $risposte = array();
     if (!empty($tmp)) {
         foreach ($tmp as $k => $v) {
             $risposte[] = array('other_answer' => $v['tipo'][1], 'answer' => $v['testo'], 'value' => $v['correttezza'], 'case_sensitive' => $v['tipo'][2], 'record' => $v['id_nodo'], 'ordine' => $v['ordine']);
         }
     }
     $case_sensitive = false;
     $open_cloze = array(ADA_NORMAL_TEST_SIMPLICITY, ADA_MEDIUM_TEST_SIMPLICITY);
     if ($this->question['tipo'][1] == ADA_OPEN_AUTOMATIC_TEST_TYPE || $this->question['tipo'][1] == ADA_CLOZE_TEST_TYPE && in_array($this->question['tipo'][3], $open_cloze)) {
         $case_sensitive = true;
     }
     $open_answer = false;
     if (in_array($this->question['tipo'][1], array(ADA_STANDARD_TEST_TYPE, ADA_MULTIPLE_CHECK_TEST_TYPE))) {
         $open_answer = true;
     }
     $form = $this->instantiateObject($risposte, $this->question, $case_sensitive, $open_answer);
     if ($_POST) {
         //hack to capture ajax calls from ADA_CLOZE_TEST_TYPE -> ADA_MULTIPLE_TEST_SIMPLICITY
         if ($this->question['tipo'][3] == ADA_MULTIPLE_TEST_SIMPLICITY) {
             require_once MODULES_TEST_PATH . '/include/nodeTest.class.inc.php';
             $questionObj = nodeTest::readNode($this->question['id_nodo']);
             $questionObj->updateAnswerTable($_POST[QuestionMultipleClozeTest::postVariable]);
         }
         if ($form->isValid()) {
             //crea nuove risposte con i dati del form
             $post = array();
             foreach ($_POST['answer'] as $k => $v) {
                 $post[] = array('answer' => $_POST['answer'][$k], 'value' => intval($_POST['value'][$k]), 'case_sensitive' => $_POST['case_sensitive'][$k] == 1 ? true : false, 'other_answer' => $_POST['other_answer'][$k] == 1 ? true : false, 'record' => $_POST['record'][$k], 'ordine' => $_POST['ordine'][$k]);
             }
             $result = true;
             $tipo = ADA_LEAF_ANSWER . ADA_NO_OPEN_TEST_ANSWER . ADA_CASE_SENSITIVE_TEST . '000';
             foreach ($post as $k => $v) {
                 $t = $tipo;
                 $t[1] = $v['other_answer'] ? ADA_OPEN_TEST_ANSWER : ADA_NO_OPEN_TEST_ANSWER;
                 $t[2] = $v['case_sensitive'] ? ADA_CASE_INSENSITIVE_TEST : ADA_CASE_SENSITIVE_TEST;
                 $data = array('id_corso' => $this->test['id_corso'], 'id_utente' => $_SESSION['sess_id_user'], 'id_istanza' => $this->test['id_istanza'], 'nome' => $v['answer'], 'testo' => Node::prepareInternalLinkMediaForDatabase($v['answer']), 'correttezza' => $v['value'], 'tipo' => $t, 'id_nodo_parent' => $this->question['id_nodo'], 'id_nodo_radice' => $this->test['id_nodo'], 'ordine' => $v['ordine'] ? $v['ordine'] : $k + 1);
                 if (intval($v['record']) > 0) {
                     $res = $dh->test_updateNode(intval($v['record']), $data);
                 } else {
                     $res = $dh->test_addNode($data);
                 }
                 if (AMATestDataHandler::isError($res)) {
                     $result = false;
                     $html = translateFN('Errore durante la creazione delle risposte');
                     break;
                 }
                 unset($data);
             }
             if ($result) {
                 $get_topic = isset($_GET['topic']) ? '&topic=' . $_GET['topic'] : '';
                 if ($_POST['return'] == 'here') {
                     redirect(MODULES_TEST_HTTP . '/edit_answers.php?id_question=' . $this->question['id_nodo'] . $get_topic);
                 } else {
                     redirect(MODULES_TEST_HTTP . '/index.php?id_test=' . $this->test['id_nodo'] . $get_topic . '#liQuestion' . $this->question['id_nodo']);
                 }
             }
         }
     } else {
         $html = $form->getHtml();
         $div = CDOMElement::create('div', 'id:insertImage,class:hide');
         $div->setAttribute('title', translateFN('Inserisci Immagine'));
         $div->setAttribute('style', 'text-align:right;');
         $labelUrl = CDOMElement::create('label', 'for:inputUrl');
         $labelUrl->addChild(new CText(translateFN('Url') . ':'));
         $inputUrl = CDOMElement::create('text', 'id:inputUrl');
         $div->addChild($labelUrl);
         $div->addChild($inputUrl);
         $div->addChild(new CText('<br />'));
         $labelTitle = CDOMElement::create('label', 'for:inputTitle');
         $labelTitle->addChild(new CText(translateFN('Titolo') . ':'));
         $inputTitle = CDOMElement::create('text', 'id:inputTitle');
         $div->addChild($labelTitle);
         $div->addChild($inputTitle);
         $div->addChild(new CText('<br />'));
         $labelRadio = CDOMElement::create('label');
         $labelRadio->addChild(new CText(translateFN('Permetti zoom') . ':'));
         $labelYes = CDOMElement::create('label', 'for:radioPopupYes');
         $labelYes->addChild(new CText(translateFN('Si')));
         $labelNo = CDOMElement::create('label', 'for:radioPopupNo');
         $labelNo->addChild(new CText(translateFN('No')));
         $radioYes = CDOMElement::create('radio', 'id:radioPopupYes,name:radioPopup');
         $radioYes->setAttribute('checked', '');
         $radioNo = CDOMElement::create('radio', 'id:radioPopupNo,name:radioPopup');
         $div->addChild($labelRadio);
         $div->addChild($radioYes);
         $div->addChild($labelYes);
         $div->addChild($radioNo);
         $div->addChild($labelNo);
         $div->addChild(new CText('<br />'));
         $labelWidth = CDOMElement::create('label', 'for:inputWidth');
         $labelWidth->addChild(new CText(translateFN('Larghezza') . ':'));
         $inputWidth = CDOMElement::create('text', 'id:inputWidth,size:4,value:75');
         $labelHeight = CDOMElement::create('label', 'for:inputHeight');
         $labelHeight->addChild(new CText(translateFN('Altezza') . ':'));
         $inputHeight = CDOMElement::create('text', 'id:inputHeight,size:4,value:75');
         $div->addChild($labelWidth);
         $div->addChild($inputWidth);
         $div->addChild($labelHeight);
         $div->addChild($inputHeight);
         $html .= $div->getHtml();
     }
     return $html;
 }