module_path = str_replace(basename(__FILE__),"",__FILE__); parent::__construct($id); } public function get_manage_form(){ global $base_path; //variables persos... global $metadatas; $form="

".$this->format_text($this->msg['cms_module_metadatas_manage_title'])."

"; if($this->managed_datas['module']['metadatas']){ foreach($this->managed_datas['module']['metadatas'] as $key => $group_metadatas){ $form.="

".$this->format_text($group_metadatas['name'])."   ".$this->format_text($this->msg[

"; } } $form.=" ".$this->format_text($this->msg['cms_module_metadatas_add_metadatas'])." "; $form.="
"; if($metadatas){ $form.=$this->get_managed_form_start(array('metadatas'=>$metadatas)); $form.=$this->get_managed_metadatas_form($metadatas); $form.=$this->get_managed_form_end(); } $form.="
"; return $form; } public function get_metas_list(){ $struct = array(); /* $struct[] = array( * 'prefix' => "..", * 'name' => "..", * 'items' => array( * 'cle' => array( * 'label' => "..", * 'desc' => "..", * 'default_template' => "{{..}}" * ), * ), * 'separator' => ":", * 'group_template' => "" * ); * * */ if (count($this->managed_datas['module']['metadatas'])) { foreach ($this->managed_datas['module']['metadatas'] as $key_metadatas=>$group_metadatas) { $struct[$key_metadatas] = $group_metadatas; } } return $struct; } protected function get_managed_metadatas_form($metadatas){ global $opac_url_base; global $base_path; if($metadatas != "new"){ $infos = $this->managed_datas['module']['metadatas'][$metadatas]; } else { $infos = array( 'name' => '', 'prefix' => '', 'separator' => '', 'group_template' => '', 'replace' => '' ); } $form="
"; //nom du groupe de méta-données $form.="
format_text($infos['replace']) ? "checked" : "")." />
"; if($metadatas!="new"){ //sélecteur de méta $form.="
format_text($this->msg['cms_module_metadatas_group_bt_add_line'])."\" onclick=\"load_metadata_form()\"/>

 
"; //composition du groupe de méta-données... $form.="

!!item_list!!
".$this->format_text($this->msg['cms_module_metadatas_group_key_metadata'])." ".$this->format_text($this->msg['cms_module_metadatas_group_label_metadata'])." ".$this->format_text($this->msg['cms_module_metadatas_group_desc_metadata'])." ".$this->format_text($this->msg['cms_module_metadatas_group_default_template_metadata'])."
".$this->format_text($this->msg['cms_module_metadatas_manage_form_advertisements'])."
"; $elt_tpl=" format_text($this->msg['cms_module_metadatas_group_edit_metadata'])."\" alt=\"".$this->format_text($this->msg['cms_module_metadatas_group_edit_metadata'])."\" onclick=\"load_metadata_form('!!item_key!!');\" /> !!item_key!! !!item_label!! !!item_desc!! !!item_default_template!! "; $item_list = ""; if(count($infos['items'])) { foreach($infos['items'] as $key=>$item){ $tpl_item=$elt_tpl; $tpl_item=str_replace('!!item_key!!',$this->format_text($key), $tpl_item); $tpl_item=str_replace('!!item_label!!',$this->format_text($item["label"]), $tpl_item); $tpl_item=str_replace('!!item_desc!!',$this->format_text($item["desc"]), $tpl_item); $tpl_item=str_replace('!!item_default_template!!',$this->format_text($item["default_template"]), $tpl_item); $item_list.=$tpl_item; } } $form = str_replace('!!item_list!!', $item_list, $form); } return $form; } public function execute_ajax(){ global $charset; global $do; global $metadatas; $response = array(); switch($do){ case "get_tab" : global $get_element; $response['content'] = json_encode($this->managed_datas['module']['metadatas'][$metadatas]['items'][$get_element]); $response['content-type'] = "application/json"; break; case "del_tab" : global $suppr_element; if (!isset($this->managed_datas['module']['metadatas'][$metadatas]['items'])) { $items = array( 'identifier' => 'id', 'label' => 'title', 'items' => array() ); } else { $items = array( 'identifier' => 'id', 'label' => 'title', 'items' => $this->managed_datas['module']['metadatas'][$metadatas]['items'] ); } if($charset != 'utf-8'){ $suppr_element = utf8_encode($suppr_element); } if ($suppr_element) { if (count($items['items'])) { if (array_key_exists($suppr_element, $items['items'])) { array_splice($items['items'],$key_exists,1); } } } $this->managed_datas['module']['metadatas'][$metadatas]['items'] = $items["items"]; $query = "replace into cms_managed_modules set managed_module_name = '".addslashes($this->class_name)."', managed_module_box = '".$this->addslashes(serialize($this->managed_datas))."'"; pmb_mysql_query($query); $response['content'] = "OK"; $response['content-type'] = "application/json"; break; case "save_tab" : global $elements; if(!isset($this->managed_datas['module']['metadatas'][$metadatas]) || !isset($this->managed_datas['module']['metadatas'][$metadatas]['items'])){ $items = array( 'identifier' => 'id', 'label' => 'title', 'items' => array() ); }else { $items = array( 'identifier' => 'id', 'label' => 'title', 'items' => $this->managed_datas['module']['metadatas'][$metadatas]['items'] ); } if($charset != 'utf-8'){ $elements = utf8_encode($elements); } // \s matches any whitespace character (equal to [\r\n\t\f\v ]) $text = preg_replace("/\r|\n/", "", $elements); $elements = encoding_normalize::json_decode(stripslashes($text), true); if (!empty($elements) && count($elements)) { foreach ($elements as $key=>$value) { $items['items'][$key] = array( 'label' => $value['label'], 'desc' => $value['desc'], 'default_template' => $value['default_template'] ); } } $this->managed_datas['module']['metadatas'][$metadatas]['items'] = $items["items"]; $query = "replace into cms_managed_modules set managed_module_name = '".addslashes($this->class_name)."', managed_module_box = '".$this->addslashes(serialize($this->managed_datas))."'"; pmb_mysql_query($query); $response['content'] = "OK"; $response['content-type'] = "application/json"; break; default : $response = parent::execute_ajax(); break; } return $response; } public function get_next_item_id($metadatas){ $max = $this->_get_max_item_id($this->managed_datas['module']['metadatas'][$metadatas]['items'],0)+1; return $max; } public function _get_max_item_id($items,$max){ if(is_array($items)){ foreach($items as $item){ if(isset($item['children']) && count($item['children'])){ $max = $this->_get_max_item_id($item['children'],$max); } if(isset($item['id']) && $item['id'] > $max){ $max = $item['id']; } } } return $max; } public function save_manage_form(){ global $metadatas; global $metadatas_delete; global $cms_module_metadatas_group_name; global $cms_module_metadatas_group_prefix; global $cms_module_metadatas_group_separator; global $cms_module_metadatas_group_template; global $cms_module_metadatas_replace; $params = $this->managed_datas['module']; if($metadatas_delete){ unset($params['metadatas'][$metadatas_delete]); }else{ //ajout d'un groupe de méta-données if($metadatas == "new"){ $metadatas_infos = array( 'name' => stripslashes($cms_module_metadatas_group_name), 'prefix' => stripslashes($cms_module_metadatas_group_prefix), 'separator' => stripslashes($cms_module_metadatas_group_separator), 'group_template' => stripslashes($cms_module_metadatas_group_template), 'replace' => $cms_module_metadatas_replace, 'items' => array() ); $params['metadatas']['metadatas'.(self::get_max_metadatas_id($this->managed_datas['module']['metadatas'])+1)] = $metadatas_infos; }else{ //sinon on réécrit juste l'élément $params['metadatas'][$metadatas]['name'] = stripslashes($cms_module_metadatas_group_name); $params['metadatas'][$metadatas]['prefix'] = stripslashes($cms_module_metadatas_group_prefix); $params['metadatas'][$metadatas]['separator'] = stripslashes($cms_module_metadatas_group_separator); $params['metadatas'][$metadatas]['group_template'] = stripslashes($cms_module_metadatas_group_template); $params['metadatas'][$metadatas]['replace'] = $cms_module_metadatas_replace; } } return $params; } protected function get_max_metadatas_id($datas){ $max = 0; if(count($datas)){ foreach ($datas as $key => $val){ $key = str_replace("metadatas","",$key)*1; if($key>$max) $max = $key; } } return $max; } }