/**
  * Appel les fonctions static get_form et articule le formulaire de l'item courant
  *
  * on itère sur les propriétés de l'onto_class, on envoi aussi le datatype si présent
  * 
  * @param string $prefix_url  Préfixe de l'url de soumission du formulaire
  * @param string $flag  Nom du flag à utiliser pour limiter aux champs concernés
  *  
  * @return string
  * @access public
  */
 public function get_form($prefix_url = "", $flag = "", $action = "save")
 {
     global $msg, $charset, $ontology_tpl;
     $temp_datatype_tab = $this->order_datatypes();
     $form = $ontology_tpl['form_body'];
     $form = str_replace("!!uri!!", $this->uri, $form);
     $form = str_replace("!!onto_form_scripts!!", $ontology_tpl['form_scripts'], $form);
     $form = str_replace("!!caller!!", rawurlencode(onto_common_uri::get_name_from_uri($this->uri, $this->onto_class->pmb_name)), $form);
     $form = str_replace("!!onto_form_id!!", onto_common_uri::get_name_from_uri($this->uri, $this->onto_class->pmb_name), $form);
     $form = str_replace("!!onto_form_action!!", $prefix_url . "&action=" . $action, $form);
     $form = str_replace("!!onto_form_title!!", htmlentities($this->onto_class->label, ENT_QUOTES, $charset), $form);
     $content = '';
     $valid_js = "";
     if (sizeof($this->onto_class->get_properties())) {
         $index = 0;
         foreach ($this->onto_class->get_properties() as $uri_property) {
             $property = $this->onto_class->get_property($uri_property);
             if (!$flag || in_array($flag, $property->flags)) {
                 $datatype_class_name = $this->resolve_datatype_class_name($property);
                 $datatype_ui_class_name = $this->resolve_datatype_ui_class_name($datatype_class_name, $property, $this->onto_class->get_restriction($uri_property));
                 // On encapsule dans des divs movables pour l'édition de la grille de saisie
                 $movable_div = $ontology_tpl['form_movable_div'];
                 $movable_div = str_replace('!!movable_index!!', $index, $movable_div);
                 $movable_div = str_replace('!!movable_property_label!!', htmlentities($property->label, ENT_QUOTES, $charset), $movable_div);
                 $movable_div = str_replace('!!datatype_ui_form!!', $datatype_ui_class_name::get_form($this->uri, $property, $this->onto_class->get_restriction($uri_property), $temp_datatype_tab[$uri_property][$datatype_ui_class_name], onto_common_uri::get_name_from_uri($this->uri, $this->onto_class->pmb_name), $flag), $movable_div);
                 $content .= $movable_div;
                 if ($valid_js) {
                     $valid_js .= ",";
                 }
                 $valid_js .= $datatype_ui_class_name::get_validation_js($this->uri, $property, $this->onto_class->get_restriction($uri_property), $temp_datatype_tab[$uri_property][$datatype_ui_class_name], onto_common_uri::get_name_from_uri($this->uri, $this->onto_class->pmb_name), $flag);
                 $index++;
             }
         }
     }
     $form = str_replace("!!onto_form_content!!", $content, $form);
     $form = str_replace("!!onto_form_submit!!", '<input type="button" class="bouton" onclick="submit_onto_form();" value="' . htmlentities($msg['77'], ENT_QUOTES, $charset) . '"/>', $form);
     $form = str_replace("!!onto_form_history!!", '<input type="button" class="bouton" onclick="history.go(-1);" value="' . htmlentities($msg['76'], ENT_QUOTES, $charset) . '"/>', $form);
     if (!onto_common_uri::is_temp_uri($this->uri)) {
         $script = "\n\t\t\t\t\tfunction confirmation_delete() {\n        \t\t\t\tresult = confirm(\"" . $msg['confirm_suppr'] . "?\");\n        \t\t\t\tif(result) document.location = \"{$prefix_url}\"+'&action=confirm_delete';\n   \t\t\t\t}";
         $form = str_replace("!!onto_form_del_script!!", $script, $form);
         $form = str_replace("!!onto_form_delete!!", '<input type="button" class="bouton" onclick=\'confirmation_delete();\' value="' . htmlentities($msg['63'], ENT_QUOTES, $charset) . '"/>	', $form);
     } else {
         $form = str_replace("!!onto_form_del_script!!", '', $form);
         $form = str_replace("!!onto_form_delete!!", '', $form);
     }
     $valid_js = "var validations = [" . $valid_js . "];";
     $form = str_replace("!!onto_datasource_validation!!", $valid_js, $form);
     $form = str_replace("!!onto_form_name!!", onto_common_uri::get_name_from_uri($this->uri, $this->onto_class->pmb_name), $form);
     return $form;
 }
 public function replace_temp_uri()
 {
     if (onto_common_uri::is_temp_uri($this->get_uri())) {
         $this->uri = onto_common_uri::replace_temp_uri($this->get_uri(), $this->onto_class->uri, $this->onto_class->get_base_uri() . "#" . $this->onto_class->pmb_name);
     }
 }
예제 #3
0
 /**
  * Supprime et recrée les déclarations de l'instance passée en paramètre
  *
  * @param onto_common_item $item Instance à sauvegarder
  * 
  * @return bool
  * 
  * @access public
  */
 public function save($item)
 {
     if ($item->check_values()) {
         if (onto_common_uri::is_temp_uri($item->get_uri())) {
             $item->replace_temp_uri();
         }
         $assertions = $item->get_assertions();
         $nb_assertions = count($assertions);
         $i = 0;
         // On commence par supprimer ce qui existe
         $query = "delete {\n\t\t\t\t<" . $item->get_uri() . "> ?prop ?obj\n\t\t\t\t}";
         $this->data_store->query($query);
         if ($errs = $this->data_store->get_errors()) {
             print "<br>Erreurs: <br>";
             print "<pre>";
             print_r($errs);
             print "</pre><br>";
         }
         // On peut y aller
         $query = "insert into <pmb> {\n\t\t\t\t";
         foreach ($assertions as $assertion) {
             if ($assertion->offset_get_object_property("type") == "literal") {
                 $object = "'" . addslashes($assertion->get_object()) . "'";
                 $object_properties = $assertion->get_object_properties();
                 if ($object_properties['lang']) {
                     $object .= "@" . $object_properties['lang'];
                 }
             } else {
                 $object = "<" . addslashes($assertion->get_object()) . ">";
             }
             $query .= "<" . addslashes($assertion->get_subject()) . "> <" . addslashes($assertion->get_predicate()) . "> " . $object;
             $i++;
             if ($i < $nb_assertions) {
                 $query .= " .";
             }
             $query .= "\n";
         }
         $query .= "}";
         $this->data_store->query($query);
         if ($errs = $this->data_store->get_errors()) {
             print "<br>Erreurs: <br>";
             print "<pre>";
             print_r($errs);
             print "</pre><br>";
         } else {
             $index = new onto_index();
             $index->set_handler($this);
             $index->maj(0, $item->get_uri());
         }
     } else {
         return $item->get_checking_errors();
     }
     return true;
 }