コード例 #1
0
 /**
  * add course - test / survey association
  * adds a course node that contains link to test / survey too
  *
  * @global db $dh
  *
  * @param int $id_test
  *
  * @return boolean
  */
 public function add($id_test)
 {
     $dh = $GLOBALS['dh'];
     $test = $dh->test_getNode($id_test);
     if ($dh->isError($test)) {
         return false;
     }
     //creo nodo di riferimento
     $last_node = explode('_', get_max_idFN($this->courseObj->id));
     $new_id = $last_node[1] + 1;
     $new_node_id = $this->courseObj->id . '_' . $new_id;
     $url = MODULES_TEST_HTTP . '/index.php?id_test=' . $id_test;
     $link = CDOMElement::create('a');
     $link->setAttribute('href', $url);
     $link->addChild(new CText($url));
     $nodo_test['id'] = $new_node_id;
     $nodo_test['id_node_author'] = $test['id_utente'];
     $nodo_test['title'] = $test['titolo'];
     $nodo_test['name'] = $test['titolo'];
     $nodo_test['text'] = $link->getHtml();
     $nodo_test['type'] = ADA_CUSTOM_EXERCISE_TEST;
     $nodo_test['parent_id'] = $this->courseObj->id . '_0';
     $nodo_test['order'] = 999;
     $nodo_test['creation_date'] = today_dateFN();
     $nodo_test['pos_x0'] = 0;
     $nodo_test['pos_y0'] = 0;
     $nodo_test['pos_x1'] = 0;
     $nodo_test['pos_y1'] = 0;
     $id_node = $dh->add_node($nodo_test);
     if (empty($id_node) || $dh->isError($id_node)) {
         return false;
     }
     $res = $dh->test_addCourseTest($this->courseObj->id, $id_test, $id_node);
     if (!$dh->isError($res)) {
         return false;
     } else {
         return true;
     }
 }
コード例 #2
0
ファイル: ama.inc.php プロジェクト: eguicciardi/ada
 protected function _add_node($node_ha)
 {
     ADALogger::log_db("entered _add_node");
     $db =& $this->getConnection();
     if (AMA_DB::isError($db)) {
         return $db;
     }
     // FIXME: l'id del nodo dovrebbe venire ottenuto qui e non passato nell'array $node_ha
     // Fixed by Graffio 08/11/2011
     //$id_node = $this->sql_prepared($node_ha['id']);
     $id_author = $node_ha['id_node_author'];
     $name = $this->sql_prepared($this->or_null(isset($node_ha['name']) ? $node_ha['name'] : null));
     $title = $this->sql_prepared($this->or_null(isset($node_ha['title']) ? $node_ha['title'] : null));
     $text = $this->sql_prepared(isset($node_ha['text']) ? $node_ha['text'] : null);
     $type = $this->sql_prepared($this->or_zero(isset($node_ha['type']) ? $node_ha['type'] : null));
     $creation_date = $this->date_to_ts($this->or_null(isset($node_ha['creation_date']) ? $node_ha['creation_date'] : ''));
     $parent_id = $this->sql_prepared(isset($node_ha['parent_id']) ? $node_ha['parent_id'] : null);
     $order = $this->sql_prepared($this->or_null(isset($node_ha['order']) ? $node_ha['order'] : null));
     $level = $this->sql_prepared($this->or_zero(isset($node_ha['level']) ? $node_ha['level'] : null));
     $version = $this->sql_prepared($this->or_zero(isset($node_ha['version']) ? $node_ha['version'] : null));
     $n_contacts = $this->sql_prepared($this->or_zero(isset($node_ha['n_contacts']) ? $node_ha['n_contacts'] : null));
     $icon = $this->sql_prepared($this->or_null(isset($node_ha['icon']) ? $node_ha['icon'] : null));
     // modified 7/7/01 ste
     // $color = $this->or_zero($node_ha['color']);
     $bgcolor = $this->sql_prepared($this->or_null(isset($node_ha['bgcolor']) ? $node_ha['bgcolor'] : null));
     $color = $this->sql_prepared($this->or_null(isset($node_ha['color']) ? $node_ha['color'] : null));
     // end
     $correctness = $this->sql_prepared($this->or_zero(isset($node_ha['correctness']) ? $node_ha['correctness'] : null));
     $copyright = $this->sql_prepared($this->or_zero(isset($node_ha['copyright']) ? $node_ha['copyright'] : null));
     // added 6/7/01 ste
     $id_position = $this->sql_prepared(isset($node_ha['id_position']) ? $node_ha['id_position'] : null);
     $lingua = $this->sql_prepared(isset($node_ha['lingua']) ? $node_ha['lingua'] : null);
     $pubblicato = $this->sql_prepared(isset($node_ha['pubblicato']) ? $node_ha['pubblicato'] : null);
     // end
     // added 24/7/02 ste
     //  $family = $this->date_to_ts($this->or_null($node_ha['family']));
     // end
     // added  2/4/03
     if (array_key_exists('id_instance', $node_ha)) {
         $id_instance = $this->sql_prepared($this->or_null($node_ha['id_instance']));
     } else {
         $id_instance = "''";
     }
     //end
     /******
      * graffio 08/11/2012
      * get the last id of the course.
      * If new course the first node of a course MUST be idCourse_0
      */
     if (isset($node_ha['id_course']) and $node_ha['parent_id'] == null || $node_ha['parent_id'] == '') {
         $new_node_id = $node_ha['id_course'] . '_' . '0';
     } else {
         $parentId = $node_ha['parent_id'];
         //             $regExp = '#^([1-9][0-9]+)_#';
         // giorgio 09/mag/2013
         // fixed bug in regexp, it mached two digits only and gived back no match for the first 9 courses!
         $regExp = '#^([1-9][0-9]*)_#';
         preg_match($regExp, $parentId, $stringFound);
         if (count($stringFound) > 0) {
             $idCourse = $stringFound[1];
             $last_node = get_max_idFN($idCourse);
             $tempAr = explode("_", $last_node);
             $newId = intval($tempAr[1]) + 1;
             $new_node_id = $idCourse . "_" . $newId;
         }
     }
     $id_node = $this->sql_prepared($new_node_id);
     /***************************/
     // verify key uniqueness on nodo
     // Modifica di Graffio del 03/12/01
     // Se il nodo c'e' gia va avanti
     // E' corretto?????
     /***************************/
     /*
             $sql = "select id_nodo from nodo where id_nodo = $id_node";
             ADALogger::log_db("Query: $sql");
             $id =  $db->getOne($sql);
             if(AMA_DB::isError($id)) {
        return new AMA_Error(AMA_ERR_GET);
             }
             ADALogger::log_db("Query result: $id");
     
             if (!empty($id)) {
        return new AMA_Error($this->errorMessage(AMA_ERR_UNIQUE_KEY) . " while in _add_node.");
             }
     *
     */
     /***************************/
     /*  + family
         $sql  = "insert into nodo (id_nodo, id_utente,id_posizione, nome, titolo, testo, tipo, data_creazione, id_nodo_parent, ordine, livello, versione, n_contatti, icona, colore_didascalia, colore_sfondo, correttezza, copyright, family)";
         $sql .= " values ($id_node,  $id_author, $id_position, $name, $title, $text, $type, $creation_date, $parent_id, $order, $level, $version, $n_contacts, $icon, $color, $bgcolor, $correctness, $copyright, $family)";
            */
     // insert a row into table nodo
     $sql = "insert into nodo (id_nodo, id_utente,id_posizione, nome, titolo, testo, tipo, data_creazione, id_nodo_parent, ordine, livello, versione, n_contatti, icona, colore_didascalia, colore_sfondo, correttezza, copyright, lingua, pubblicato, id_istanza)";
     $sql .= " values ({$id_node},  {$id_author}, {$id_position}, {$name}, {$title}, {$text}, {$type}, {$creation_date}, {$parent_id}, {$order}, {$level}, {$version}, {$n_contacts}, {$icon}, {$color}, {$bgcolor}, {$correctness}, {$copyright}, {$lingua}, {$pubblicato}, {$id_instance})";
     ADALogger::log_db("trying inserting the node: {$sql}");
     $res = $db->query($sql);
     // if an error is detected, an error is created and reported
     if (AMA_DB::isError($res)) {
         return new AMA_Error($this->errorMessage(AMA_ERR_ADD) . " while in _add_node." . AMA_SEP . ": " . $res->getMessage());
     }
     //return true;
     return $new_node_id;
 }
コード例 #3
0
ファイル: add_exercise.php プロジェクト: eguicciardi/ada
 $esercizio['text'] = $_SESSION['add_exercise']['question'];
 //$esercizio['type']=$_SESSION['add_exercise']['exercise_family'].$_SESSION['add_exercise']['exercise_interaction'].$_SESSION['add_exercise']['test_mode'];
 $esercizio['type'] = $_SESSION['add_exercise']['exercise_family'] . $_SESSION['add_exercise']['exercise_interaction'] . $_SESSION['add_exercise']['test_mode'] . $_SESSION['add_exercise']['test_simplification'] . $_SESSION['add_exercise']['test_barrier'];
 $esercizio['parent_id'] = $_SESSION['add_exercise']['parent_node'];
 $esercizio['order'] = $order + 1;
 $esercizio['creation_date'] = today_dateFN();
 $esercizio['pos_x0'] = 0;
 $esercizio['pos_y0'] = 0;
 $esercizio['pos_x1'] = 0;
 $esercizio['pos_y1'] = 0;
 $result = $dh->add_node($esercizio);
 // esercizio
 ##### eventuali risposte
 if (sizeof($_SESSION['add_exercise']['answers']) > 0) {
     foreach ($_SESSION['add_exercise']['answers'] as $answer) {
         $last_node = get_max_idFN($id_course[0]);
         $tempAr = explode("_", $last_node);
         $new_id = $tempAr[1];
         // get only the part of node
         $new_id = $new_id + 1;
         $node_risp = $id_course[0] . "_" . $new_id;
         $risp['id'] = $node_risp;
         $risp['id_node_author'] = $_SESSION['sess_id_user'];
         $risp['title'] = "";
         $risp['name'] = $answer['answer'];
         //					if ( isset( $answer['comment'] ) )
         //					{
         //					    $risp['text'] = $answer['comment'];
         //					}
         //					else
         //					{
コード例 #4
0
 /**
  * Adds a test / survey node
  *
  * @global db $dh
  *
  * @return array an array with 'html' and 'path' keys
  */
 public function add()
 {
     $dh = $GLOBALS['dh'];
     $nodo = new Node($_GET['id_node']);
     if (!AMATestDataHandler::isError($nodo)) {
         $path = $nodo->findPathFN();
     }
     if ($_POST) {
         $data = $_POST;
     } else {
         $data = null;
     }
     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) {
         $_POST['consegna'] = Node::prepareInternalLinkMediaForDatabase($_POST['consegna']);
         $_POST['testo'] = Node::prepareInternalLinkMediaForDatabase($_POST['testo']);
         if ($form->isValid()) {
             //crea nuovo test con i dati del form
             $this->setTipo();
             $id_corso = explode('_', $nodo->id);
             $id_corso = $id_corso[0];
             $data = array('id_corso' => $id_corso, 'id_utente' => $_SESSION['sess_id_user'], 'id_istanza' => $nodo->instance, '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']);
             $id_test = $dh->test_addNode($data);
             unset($data);
             if (!AMATestDataHandler::isError($id_test)) {
                 //crea nuovo nodo contenente link al test
                 $last_node = explode('_', get_max_idFN($id_corso));
                 $new_id = $last_node[1] + 1;
                 $new_node_id = $id_corso . '_' . $new_id;
                 $order = $dh->get_ordine_max_val($nodo->id);
                 $url = MODULES_TEST_HTTP . '/index.php?id_test=' . $id_test;
                 $link = CDOMElement::create('a');
                 $link->setAttribute('href', $url);
                 $link->addChild(new CText($url));
                 $link = $link->getHtml();
                 $text = $_POST['testo'] . '<br />' . $link;
                 $nodo_test['id'] = $new_node_id;
                 $nodo_test['id_node_author'] = $_SESSION['sess_id_user'];
                 $nodo_test['title'] = $_POST['titolo'];
                 $nodo_test['name'] = $_POST['nome'];
                 $nodo_test['text'] = $text;
                 $nodo_test['type'] = ADA_CUSTOM_EXERCISE_TEST;
                 $nodo_test['parent_id'] = $nodo->id;
                 $nodo_test['order'] = $order + 1;
                 $nodo_test['creation_date'] = today_dateFN();
                 $nodo_test['pos_x0'] = 0;
                 $nodo_test['pos_y0'] = 0;
                 $nodo_test['pos_x1'] = 0;
                 $nodo_test['pos_y1'] = 0;
                 $id_nodo_riferimento = $dh->add_node($nodo_test);
                 if (!AMATestDataHandler::isError($id_nodo_riferimento)) {
                     $data = array('id_nodo_riferimento' => $id_nodo_riferimento);
                     $res = true;
                     if ($this->mode == ADA_TYPE_SURVEY) {
                         //aggiungo record nella tabella dei sondaggi-corsi per lo switcher
                         $res = $dh->test_addCourseTest($id_corso, $id_test, $id_nodo_riferimento);
                     }
                     if ($res && $dh->test_updateNode($id_test, $data)) {
                         redirect(MODULES_TEST_HTTP . '/index.php?id_test=' . $id_test);
                     } else {
                         $html = sprintf(translateFN('Errore durante la creazione del %s'), $this->what);
                     }
                 } else {
                     $html = sprintf(translateFN('Errore durante la creazione del %s'), $this->what);
                 }
             } else {
                 $html = sprintf(translateFN('Errore durante la creazione del %s'), $this->what);
             }
         } else {
             $html = $form->getHtml();
         }
     } else {
         $html = $form->getHtml();
     }
     return array('html' => $html, 'path' => $path);
 }
コード例 #5
0
 public static function addAnswer($exercise, $answer_data = array())
 {
     $dh = $GLOBALS['dh'];
     $tmpAr = array();
     $tmpAr = explode('_', $exercise->getId());
     $id_course = $tmpAr[0];
     $last_node = get_max_idFN($id_course);
     $tmpAr = array();
     $tempAr = explode('_', $last_node);
     $new_id = $tempAr[1] + 1;
     $new_node = $id_course . '_' . $new_id;
     $node_to_add = array('id' => $new_node, 'parent_id' => $exercise->getId(), 'id_node_author' => $exercise->getAuthorId(), 'level' => $exercise->getExerciseLevel(), 'order' => $answer_data['position'], 'version' => 0, 'creation_date' => isset($ymdhms) ?: null, 'icon' => '', 'type' => ADA_LEAF_TYPE, 'pos_x0' => 100, 'pos_y0' => 100, 'pos_x1' => 200, 'pos_y1' => 200, 'name' => $answer_data['answer'], 'title' => '', 'text' => $answer_data['comment'], 'bg_color' => '#FFFFFF', 'color' => '', 'correctness' => $answer_data['correctness'], 'copyright' => '');
     $result = $dh->add_node($node_to_add);
     if (AMA_DataHandler::isError($result)) {
         $errObj = new ADA_Error($result, 'Error while adding a new answer');
     }
     return TRUE;
 }