id = $id+0; $this->reverse_instance = $reverse_instance; $this->fetch_data(); } /** * Data */ protected function fetch_data() { $this->num_notice = 0; $this->linked_notice = 0; $this->relation_type = ''; $this->rank = 0; $this->direction = ''; $this->num_reverse_link = 0; $this->niveau_biblio = ''; $this->niveau_hierar = ''; $this->to_delete = false; $this->serial_id = 0; if($this->id) { $query = "select num_notice, linked_notice, relation_type, rank, direction, num_reverse_link, niveau_biblio, niveau_hierar from notices_relations join notices on notice_id=num_notice where id_notices_relations = ".$this->id; $result = pmb_mysql_query($query); $row = pmb_mysql_fetch_object($result); $this->num_notice = $row->num_notice; $this->linked_notice = $row->linked_notice; $this->relation_type = $row->relation_type; $this->rank = $row->rank; $this->direction = $row->direction; $this->num_reverse_link = $row->num_reverse_link; $this->niveau_biblio = $row->niveau_biblio; $this->niveau_hierar = $row->niveau_hierar; if($this->num_reverse_link && $this->reverse_instance) { $this->reverse_notice_relation = new notice_relation($this->num_reverse_link, false); } if($this->niveau_biblio == 'b') { $query = 'select bulletin_notice from bulletins where num_notice ='.$this->num_notice; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)) { $row = pmb_mysql_fetch_object($result); $this->serial_id = $row->bulletin_notice; } } } } public function get_form($n_rel, $niveau_biblio='m', $from_duplicate_form = false) { global $charset; global $notice_relations_link_tpl; if($this->linked_notice) { $query = "select niveau_biblio from notices where notice_id=".$this->linked_notice; $result = pmb_mysql_query($query); $row = pmb_mysql_fetch_object($result); switch ($row->niveau_biblio) { case 's': $called_class = 'serial'; break; case 'b': $called_class = 'bulletinage'; break; case 'a': $called_class = 'analysis'; break; case 'm': $called_class = 'notice'; break; } } //Selection du template $form=$notice_relations_link_tpl; //Construction du textbox $form=str_replace("!!notice_relations_id!!",$this->linked_notice,$form); $form=str_replace("!!notice_relations_libelle!!",($this->linked_notice ? htmlentities($called_class::get_notice_title($this->linked_notice),ENT_QUOTES,$charset) : ''),$form); $form=str_replace("!!n_rel!!",$n_rel,$form); $form=str_replace("!!linked_notice_is_disabled!!",($this->id ? "disabled='disabled'" : ""),$form); $form=str_replace("!!linked_notice_button_is_hidden!!",($this->id ? "style='display:none'" : ""),$form); //Construction du combobox de type de lien $add_reverse_link_checked = ''; if($this->id) { $selector = $this->get_selector_from_relation('f_rel_type_'.$n_rel, 'update_rel_reverse_type(this, '.$n_rel.');'); if ($this->num_reverse_link) { $add_reverse_link_checked = "checked='checked'"; } } else { $deflt_relation = notice_relations::get_default_relation_type($niveau_biblio); $selector = notice_relations::get_selector('f_rel_type_'.$n_rel, $deflt_relation, 'update_rel_reverse_checked(this, '.$n_rel.'); update_rel_reverse_type(this, '.$n_rel.');'); $deflt_relation_type=explode('-', $deflt_relation)[0]; $deflt_direction=explode('-', $deflt_relation)[1]; if(notice_relations::$liste_type_relation[$deflt_direction]->attributes[$deflt_relation_type]['REVERSE_CODE_DEFAULT_CHECKED']=='YES') { $add_reverse_link_checked = "checked='checked'"; } } $form=str_replace("!!relations_links_selector!!", $selector, $form); $form=str_replace("!!add_reverse_link!!", $add_reverse_link_checked, $form); if ($add_reverse_link_checked) { $form=str_replace("!!checked_dflt_reverse_link!!", "checkbox_f_rel0_add_reverse_link.setAttribute('checked','checked');", $form); } else { $form=str_replace("!!checked_dflt_reverse_link!!", "", $form); } //Construction du combobox de type de lien associé if(isset($this->reverse_notice_relation)) { $reverse_selector = $this->reverse_notice_relation->get_selector_from_relation('f_rel_reverse_type_'.$n_rel); $form = str_replace('!!f_rel_add_reverse_link_action!!',' onChange = \'update_add_reverse_link_action('.$n_rel.', this.checked);\'',$form); } else { if ($this->id) { $reverse_selector = notice_relations::get_selector('f_rel_reverse_type_'.$n_rel, notice_relations::$liste_type_relation[$this->direction]->attributes[$this->relation_type]['REVERSE_CODE'].'-'.notice_relations::$liste_type_relation[$this->direction]->attributes[$this->relation_type]['REVERSE_DIRECTION']); } else { $reverse_selector = notice_relations::get_selector('f_rel_reverse_type_'.$n_rel, notice_relations::get_default_reverse_relation_type($niveau_biblio)); } $form = str_replace('!!f_rel_add_reverse_link_action!!','',$form); } $form = str_replace('!!del_action!!','raz_existing_rel('.$n_rel.');',$form); $form=str_replace("!!relations_reverse_links_selector!!", $reverse_selector, $form); //Champs cachés if (!$from_duplicate_form) { $form=str_replace("!!id_notices_relations!!", $this->id, $form); $form=str_replace("!!num_reverse_link!!", $this->num_reverse_link, $form); } else { $form=str_replace("!!id_notices_relations!!", 0, $form); $form=str_replace("!!num_reverse_link!!", 0, $form); } return $form; } protected function get_selector_options($direction='') { $options = ''; if ($this->num_notice) { foreach(notice_relations::$liste_type_relation[$direction]->table as $key=>$val){ $reverse_code = notice_relations::$liste_type_relation[$direction]->attributes[$key]['REVERSE_CODE']; $reverse_direction = notice_relations::$liste_type_relation[$direction]->attributes[$key]['REVERSE_DIRECTION']; if(preg_match('/^'.$key.'/', $this->relation_type) && $this->direction==$direction){ $options.=''; }else{ $options.=''; } } } else { $default_relation_type = notice_relations::get_default_relation_type($this->parent_niveau_biblio); foreach(notice_relations::$liste_type_relation[$direction]->table as $key=>$val){ $reverse_code = notice_relations::$liste_type_relation[$direction]->attributes[$key]['REVERSE_CODE']; $reverse_direction = notice_relations::$liste_type_relation[$direction]->attributes[$key]['REVERSE_DIRECTION']; if($key.'-'.$direction == $default_relation_type){ $options.=''; }else{ $options.=''; } } } return $options; } public function get_selector_from_relation($name='', $on_change='') { global $msg; $tmp = explode("_",$name); unset($tmp[count($tmp)-1]); $select = " "; return $select; } public function set_properties_from_form($i) { $f_rel_id="f_rel_id_".$i; $f_rel="f_rel_type_".$i; $f_rel_add_reverse_link="f_rel_add_reverse_link_".$i; $f_rel_reverse="f_rel_reverse_type_".$i; $f_rel_id_notices_relations="f_rel_id_notices_relations_".$i; $f_rel_num_reverse_link="f_rel_num_reverse_link_".$i; $f_rel_delete_link="f_rel_delete_link_".$i; global ${$f_rel_id}; global ${$f_rel}; global ${$f_rel_add_reverse_link}; global ${$f_rel_reverse}; global ${$f_rel_id_notices_relations}; global ${$f_rel_num_reverse_link}; global ${$f_rel_delete_link}; $relation_type=explode('-', ${$f_rel})[0]; $direction=explode('-', ${$f_rel})[1]; $relation_type_reverse=explode('-', ${$f_rel_reverse})[0]; $direction_reverse=explode('-', ${$f_rel_reverse})[1]; $this->linked_notice = ${$f_rel_id}; $this->relation_type = $relation_type; $this->direction = $direction; $this->num_reverse_link = ${$f_rel_num_reverse_link}; $this->rank = $i; $this->rank = notice_relations::$rank_by_type[$this->direction]++; if(${$f_rel_add_reverse_link}) { if(!isset($this->reverse_notice_relation)) { $this->reverse_notice_relation = new notice_relation($this->num_reverse_link, false); $this->reverse_notice_relation->set_rank(notice_relations::get_next_rank($this->linked_notice, $direction_reverse)); } $this->reverse_notice_relation->set_num_notice($this->linked_notice); $this->reverse_notice_relation->set_linked_notice($this->num_notice); $this->reverse_notice_relation->set_relation_type($relation_type_reverse); $this->reverse_notice_relation->set_direction($direction_reverse); if ($this->id) { $this->reverse_notice_relation->set_num_reverse_link($this->id); } } else { if(isset($this->reverse_notice_relation)) { $this->num_reverse_link = 0; $this->reverse_notice_relation->set_num_reverse_link(0); } } } public function save() { if(isset($this->reverse_notice_relation)) { if($this->reverse_notice_relation->get_to_delete()) { $this->reverse_notice_relation->delete(); $this->set_num_reverse_link(0); } else { $on_create = false; if (!$this->reverse_notice_relation->get_id()) { $on_create = true; } $this->reverse_notice_relation->save(); if ($on_create) { $this->set_num_reverse_link($this->reverse_notice_relation->get_id()); } } } if($this->id) { $query = "update notices_relations "; $where = "where id_notices_relations=".$this->id; } else { $query = "insert into notices_relations "; $where = ""; } $query .= "set num_notice = '".$this->num_notice."', linked_notice = '".$this->linked_notice."', relation_type = '".addslashes($this->relation_type)."', rank = '".$this->rank."', direction = '".addslashes($this->direction)."', num_reverse_link = ".$this->num_reverse_link." ".$where; pmb_mysql_query($query); if(!$this->id) { $this->id = pmb_mysql_insert_id(); if($this->num_reverse_link) { pmb_mysql_query("update notices_relations set num_reverse_link=".$this->id." where id_notices_relations=".$this->num_reverse_link); } } } public function delete() { if (isset($this->reverse_notice_relation) && $this->reverse_notice_relation->get_to_delete()) { $this->reverse_notice_relation->delete(); } $query = "delete from notices_relations where id_notices_relations = ".$this->id; pmb_mysql_query($query); pmb_mysql_query("update notices_relations set num_reverse_link=0 where num_reverse_link=".$this->id); } protected function get_drag_template($id_elt, $tit1='') { global $charset; switch ($this->direction) { case 'up': $dragtype = 'parents'; $recepttype = 'parents'; break; case 'down': $dragtype = 'childs'; $recepttype = 'childs'; break; case 'both': $dragtype = 'pairs'; $recepttype = 'pairs'; break; } $drag_link = "
relation_type."\" >"; $drag_link .= ""; return $drag_link; } public function get_display_link($print_mode, $show_explnum, $show_statut, $show_opac_hidden_fields, $anti_loop=array(), $force_display_level=false) { global $base_path; global $sort_children; global $pmb_notice_fille_format; global $link_explnum_serial; global $link_serial,$link_analysis, $link_bulletin; $display_link = ''; //Pour avoir le lien par défaut if (!$print_mode && (SESSrights & CATALOGAGE_AUTH)) $link_parent=notice::get_pattern_link(); else $link_parent=""; if($link_parent && $this->niveau_biblio=='b' && $this->niveau_hierar=='2'){ $requete="SELECT bulletin_id FROM bulletins WHERE num_notice='".$this->linked_notice."'"; $res=pmb_mysql_query($requete); if(pmb_mysql_num_rows($res)){ $link_parent=bulletinage::get_permalink(pmb_mysql_result($res,0,0)); } } if($this->direction == 'up') { $display_level = 0; $link_expl = ''; $link_explnum = ""; } else { if($pmb_notice_fille_format || $force_display_level) $display_level = 0; else $display_level = 6; $link_expl = $base_path.'/catalog.php?categ=edit_expl&id=!!notice_id!!&cb=!!expl_cb!!&expl_id=!!expl_id!!'; $link_explnum = $base_path.'/catalog.php?categ=edit_explnum&id=!!notice_id!!&explnum_id=!!explnum_id!!'; } $link_serial_sub = serial::get_permalink($this->linked_notice); if(!$link_analysis){ $link_analysis=analysis::get_pattern_link(); } if ($this->parent_niveau_biblio=='s' && $this->parent_niveau_hierar=='1') { $parent_notice = new serial_display($this->linked_notice, $display_level, $link_serial_sub, $link_analysis, $link_bulletin, "", $link_explnum_serial, 0, $print_mode, $show_explnum, $show_statut, $show_opac_hidden_fields, 1, 1, $anti_loop); } else if ($this->parent_niveau_biblio=='a' && $this->parent_niveau_hierar=='2') { $parent_notice = new serial_display($this->linked_notice, $display_level, $link_serial, $link_analysis, $link_bulletin, "", $link_explnum_serial, 0, $print_mode, $show_explnum, $show_statut, $show_opac_hidden_fields, 1, 1, $anti_loop); } else { $parent_notice=new mono_display($this->linked_notice,$display_level,$link_parent, 1, $link_expl, "", $link_explnum, 1, $print_mode, $show_explnum, $show_statut, $anti_loop, 1, false, $show_opac_hidden_fields, 1, 1); } if($this->direction == 'up') { if ($sort_children) { $id_elt = $parent_notice->notice_id.($parent_notice->anti_loop?"_p".implode("_",$parent_notice->anti_loop):""); $display_link .= $this->get_drag_template($id_elt, $parent_notice->tit1); $display_link .= $parent_notice->header; $display_link .= "
"; } else { $display_link .= $parent_notice->header; } } else { if((count($parent_notice->anti_loop) == 1) && $sort_children) { $id_elt = $parent_notice->notice_id.($parent_notice->anti_loop?"_p".implode("_",$parent_notice->anti_loop):""); $display_link .= $this->get_drag_template($id_elt, $parent_notice->tit1); $display_link .= $parent_notice->result; $display_link .= ""; } else { $display_link .= ($pmb_notice_fille_format ? "
  • ".$parent_notice->result."
  • " : $parent_notice->result); } } return $display_link; } public function get_id() { return $this->id; } public function get_num_notice() { return $this->num_notice; } public function set_num_notice($num_notice) { $this->num_notice = $num_notice; } public function get_linked_notice() { return $this->linked_notice; } public function set_linked_notice($linked_notice) { $this->linked_notice = $linked_notice; } public function get_relation_type() { return $this->relation_type; } public function set_relation_type($relation_type) { $this->relation_type = $relation_type; } public function get_rank() { return $this->rank; } public function set_rank($rank) { $this->rank = $rank; } public function get_direction() { return $this->direction; } public function set_direction($direction) { $this->direction = $direction; } public function get_num_reverse_link() { return $this->num_reverse_link; } public function set_num_reverse_link($num_reverse_link) { $this->num_reverse_link = $num_reverse_link; } public function get_niveau_biblio() { return $this->niveau_biblio; } public function get_niveau_hierar() { return $this->niveau_hierar; } public function get_reverse_notice_relation() { return $this->reverse_notice_relation; } public function set_parent_niveau_biblio($parent_niveau_biblio='m') { $this->parent_niveau_biblio = $parent_niveau_biblio; } public function set_parent_niveau_hierar($parent_niveau_hierar='0') { $this->parent_niveau_hierar = $parent_niveau_hierar; } public function get_to_delete() { return $this->to_delete; } public function set_to_delete($to_delete=false) { $this->to_delete = $to_delete; } public function get_serial_id() { return $this->serial_id; } }