id = $id + 0;
$this->fetch_data();
}
}
protected function fetch_data () {
if ($this->id) {
$query = " SELECT contribution_area_equation_id, contribution_area_equation_name, contribution_area_equation_type, contribution_area_equation_query, contribution_area_equation_human_query
FROM contribution_area_equations
WHERE contribution_area_equation_id = '". $this->id ."'";
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
if ($row = pmb_mysql_fetch_object($result)) {
$this->name = $row->contribution_area_equation_name;
$this->type = $row->contribution_area_equation_type;
$this->query = $row->contribution_area_equation_query;
$this->human_query = $row->contribution_area_equation_human_query;
}
}
}
}
public static function show_list(){
global $msg;
global $charset;
static::get_list();
print "
".$msg['noti_statut_libelle']." |
".$msg['admin_contribution_area_equation_type']." |
";
$i=0;
foreach(static::$equations as $id => $equation){
if ($i % 2) {
$pair_impair = "even";
} else {
$pair_impair = "odd";
}
print "
".htmlentities($equation['name'], ENT_QUOTES, $charset)." |
".htmlentities($equation['type_name'], ENT_QUOTES, $charset)." |
";
$i++;
}
print "
";
}
public static function get_list(){
global $dbh;
if(!static::$equations_fetched){
static::$equations = array();
$query = " SELECT contribution_area_equation_id, contribution_area_equation_name, contribution_area_equation_type, contribution_area_equation_query, contribution_area_equation_human_query
FROM contribution_area_equations
ORDER BY contribution_area_equation_name";
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
$pmb_entities = static::get_pmb_entities();
while($row = pmb_mysql_fetch_object($result)){
static::$equations[$row->contribution_area_equation_id] = array(
'name' => $row->contribution_area_equation_name,
'type' => $row->contribution_area_equation_type,
'type_name' => $pmb_entities[$row->contribution_area_equation_type],
'query' => unserialize($row->contribution_area_equation_query),
'human_query' => $row->contribution_area_equation_human_query
);
}
}
static::$equations_fetched = true;
}
}
public static function show_form($id){
global $msg,$charset;
global $admin_contribution_area_status_form;
static::get_list();
$id+=0;
$form = $admin_contribution_area_status_form;
if(isset(static::$equations[$id])){
$form_title = $msg['118'];
$statut = static::$equations[$id];
}else{
$form_title = $msg['115'];
$statut = array(
'label' => "",
'class_html' => "statutnot1",
'available_for' => array()
);
}
$form = str_replace("!!form_title!!", $form_title, $form);
for ($i=1;$i<=20; $i++) {
if ($statut['class_html'] == "statutnot".$i){
$checked = "checked";
}
else {
$checked = "";
}
$couleur[$i]="
";
if ($i==10) $couleur[10].="
";
elseif ($i!=20) $couleur[$i].="|";
}
$couleurs=implode("",$couleur);
$form = str_replace("!!class_html!!", $couleurs, $form);
$form = str_replace("!!gestion_libelle!!", htmlentities($statut['label'],ENT_QUOTES,$charset),$form);
if($id == 1 || !isset(static::$equations[$id])){
$form = str_replace("!!bouton_supprimer!!","",$form);
}else{
$form = str_replace("!!bouton_supprimer!!","",$form); ;
}
$entities_list = static::get_pmb_entities();
$i=0;
foreach($entities_list as $value => $name){
if($i!= 0 && $i % 5 == 0){
$pmb_entities.= "
";
}
$pmb_entities.= " $name";
$i++;
}
$form = str_replace("!!list_entities!!", $pmb_entities, $form);
$form.=confirmation_delete("./modelling.php?categ=contribution_area&sub=status&action=del&id=");
$form = str_replace('!!libelle_suppr!!', addslashes($statut['label']), $form);
$form = str_replace("!!id!!",$id,$form);
print $form;
}
public function get_from_from(){
global $id,$contribution_area_equation_name,$contribution_area_equation_type;
global $contribution_area_equation_query, $contribution_area_equation_human_query;
return array(
'id' => stripslashes($id + 0),
'name' => stripslashes($contribution_area_equation_name),
'type' => stripslashes($contribution_area_equation_type),
'query' => stripslashes($contribution_area_equation_query),
'human_query' => stripslashes($contribution_area_equation_human_query)
);
}
public function save($equation){
global $dbh;
$equation['id'] += 0;
if($equation['name'] != ""){
if($equation['id'] != 0){
$query = " update contribution_area_equations set ";
$where = "where contribution_area_equation_id = '".$equation['id']."'";
}else{
$query = " insert into contribution_area_equations set ";
$where = "";
}
$query.="
contribution_area_equation_name = '".addslashes($equation['name'])."',
contribution_area_equation_type = '".addslashes($equation['type'])."',
contribution_area_equation_query = '".addslashes($equation['query'])."',
contribution_area_equation_human_query = '".addslashes($equation['human_query'])."' ";
$result = pmb_mysql_query($query.$where,$dbh);
if($result){
static::$equations_fetched = false;
}else{
return false;
}
}
return true;
}
public static function delete($id) {
global $dbh;
$id+=0;
if(!count($used = static::check_used($id))){
$query = "delete from contribution_area_equations where contribution_area_equation_id = ".$id;
pmb_mysql_query($query,$dbh);
return true;
}
return false;
}
/**
* Fonction qui controle si le status de contribution est utilisé
* @param integer $id
* @return array:
*/
public static function check_used($id){
global $dbh,$msg;
global $base_path;
$id+=0;
$used = array();
return $used;
}
private static function get_pmb_entities(){
return contribution_area::get_pmb_entities();
}
/**
* Fonction permettant de générer le selecteur des equations définis pour un type d'autorité
* @param integer $auth_type Constante type d'autorité (ou 1000+id authperso)
* @param integer $contribution_area_id Identifiant du statut enregistré pour l'autorité courante
* @param boolean $selector_search Sélécteur affiché dans la page de recherche
* @return string
*/
public static function get_form_for($pmb_entity, $contribution_area_id, $search=false){
global $msg;
$id+=0;
$equations_defined = static::get_status_for($pmb_entity);
$on_change='';
if($search){
$on_change='onchange="if(this.form) this.form.submit();"';
}
$selector = '';
return $selector;
}
public function add(){
global $msg,$base_path, $pmb_opac_url,$lang,$equation_type ;
//type par defaut
$type = 'record';
if ($equation_type) {
$type = $equation_type;
}elseif ($this->type) {
$type = $this->type;
}
$this->set_properties_form_type($type);
$my_search=new $this->search_class_name(false,$this->xml_file_name);
$form = "".$msg['admin_contribution_area_equation_type']."
";
$form .= $this->get_pmb_entities_selector();
$form.= $my_search->show_form("./modelling.php?categ=contribution_area&sub=equation&action=build&equation_type=".$type."&id=".$this->id,
"","","./modelling.php?categ=contribution_area&sub=equation&action=form&equation_type=".$type."&id=".$this->id);
print $form;
}
public function get_pmb_entities_selector() {
global $equation_type;
$selected_type = '';
if($equation_type) {
$selected_type = $equation_type;
}elseif ($this->type) {
$selected_type = $this->type;
}
$on_change='onchange="document.location=\'./modelling.php?categ=contribution_area&sub=equation§ion=liste&action=build&equation_type=\'+this.value+\'&id='.$this->id.'\'"';
$selector = '';
return $selector;
}
protected function load_xml($file_name) {
global $pmb_opac_url,$lang,$base_path;
// Recherche du fichier lang de l'opac
$url=$pmb_opac_url."includes/messages/$lang.xml";
$fichier_xml=$base_path."/temp/opac_lang.xml";
curl_load_opac_file($url,$fichier_xml);
$url=$pmb_opac_url."includes/search_queries/".$file_name.".xml";
$fichier_xml="$base_path/temp/".$file_name."_opac.xml";
curl_load_opac_file($url,$fichier_xml);
}
protected function set_properties_form_type($type) {
//recherche sur le type d'equation
switch ($type) {
case 'record' :
$this->set_xml_file_name("search_fields");
$this->set_search_class_name("search");
break;
default:
$this->set_xml_file_name("search_fields_authorities");
$this->set_search_class_name("search_authorities");
break;
}
return $this;
}
public function set_xml_file_name($file_name) {
$this->xml_file_name = $file_name;
return $this;
}
public function set_search_class_name($search_class_name) {
$this->search_class_name = $search_class_name;
return $this;
}
public function get_xml_file_name() {
return $this->xml_file_name;
}
protected function get_search_class_name() {
return $this->search_class_name;
}
public function do_form () {
global $msg,$tpl_contribution_area_equation_form,$charset,$base_path, $equation_type;
global $thesaurus_liste_trad;
global $id_equation;
$type = $equation_type ?? $this->type;
if (!empty($type)) {
$this->set_properties_form_type($type);
}else {
$this->set_properties_form_type("record");
}
// titre formulaire
$my_search=new $this->search_class_name(false,$this->xml_file_name);
if($this->id) {
$libelle = $msg["admin_contribution_area_equation_edit"];
$link_delete="";
$button_modif_requete = "id.".submit();\">";
//Mémorisation de recherche prédéfinie en édition
if ($id_equation) {
$this->query=$my_search->serialize_search();
$my_search->unserialize_search($this->query);
} else {
$my_search->unserialize_search($this->query);
$this->query=$my_search->serialize_search();
}
$form_modif_requete = $this->make_hidden_search_form();
} else {
$libelle=$msg["admin_contribution_area_equation_add"];
$link_delete="";
$button_modif_requete = "";
$form_modif_requete = "";
$this->query=$my_search->serialize_search();
}
$this->human_query = $my_search->make_human_query();
$type_equation = "record";
if ($equation_type) {
$type_equation = $equation_type;
} elseif ($this->type) {
$type_equation = $this->type;
}
$pmb_entities = static::get_pmb_entities();
$tpl_contribution_area_equation_form = str_replace('!!id!!', htmlentities($this->id,ENT_QUOTES,$charset), $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!name!!', htmlentities($this->name,ENT_QUOTES,$charset), $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!type_label!!', $pmb_entities[$type_equation], $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!type!!', $type_equation, $tpl_contribution_area_equation_form);
$action="./modelling.php?categ=contribution_area&sub=equation&action=save&id=".$this->id;
$tpl_contribution_area_equation_form = str_replace('!!action!!', $action, $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!delete!!', $link_delete, $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!libelle!!',htmlentities($libelle,ENT_QUOTES,$charset) , $tpl_contribution_area_equation_form);
$link_annul = "onClick=\"unload_off();history.go(-1);\"";
$tpl_contribution_area_equation_form = str_replace('!!annul!!', $link_annul, $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!query!!', htmlentities($this->query,ENT_QUOTES,$charset), $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!requete_human!!', $this->human_query, $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!human_query!!', htmlentities($this->human_query,ENT_QUOTES,$charset), $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!bouton_modif_requete!!', $button_modif_requete, $tpl_contribution_area_equation_form);
$tpl_contribution_area_equation_form = str_replace('!!form_modif_requete!!', $form_modif_requete, $tpl_contribution_area_equation_form);
return $tpl_contribution_area_equation_form;
}
// pour maj de requete de recherche prédéfinie
public function make_hidden_search_form() {
global $search;
global $charset;
$url = "./modelling.php?categ=contribution_area&sub=equation&action=add&id=".$this->id ;
$r="";
return $r;
}
public static function get_list_by_type($type){
global $dbh;
$equations = array();
$query = " SELECT contribution_area_equation_id, contribution_area_equation_name, contribution_area_equation_type, contribution_area_equation_query, contribution_area_equation_human_query
FROM contribution_area_equations ";
if ($type) {
$query .="WHERE contribution_area_equation_type = '". $type ."' ";
}
$query .=" ORDER BY contribution_area_equation_name";
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
while($row = pmb_mysql_fetch_object($result)){
$equations[$row->contribution_area_equation_id] = array(
'name' => $row->contribution_area_equation_name,
'type' => $row->contribution_area_equation_type,
'query' => unserialize($row->contribution_area_equation_query),
'human_query' => $row->contribution_area_equation_human_query
);
}
}
return $equations;
}
}