get_global_value($name); $selector = ""; return $selector; } protected function gen_selector_asc_desc($name='') { global $msg, $charset; $selected = $this->get_global_value($name); $selector = ""; return $selector; } public function get_already_selected() { global $msg, $charset; global $add_field; global $delete_field; global $fields; //Affichage des champs deja saisis $r=""; $n=0; $r.="\n"; if (!empty($fields) && is_array($fields)) { for ($i=0; $i";//Colonne 1 $r.=""; $r.=""; $r.=""; $r.=""; $r.="";//Colonne 6 $r.="\n"; $n++; } } } $r.="
";//Colonne 2 if ($f[0]=="f") { if($f[2] && isset(self::$fields[$this->type]["FIELD"][$f[1]]["TABLE"]) && isset($msg[self::$fields[$this->type]["FIELD"][$f[1]]["TABLE"][0]["TABLEFIELD"][$f[2]]["NAME"]])) { $r.=htmlentities($msg[self::$fields[$this->type]["FIELD"][$f[1]]["TABLE"][0]["TABLEFIELD"][$f[2]]["NAME"]],ENT_QUOTES,$charset); } elseif (isset($msg[self::$fields[$this->type]["FIELD"][$f[1]]["NAME"]])) { $r.=htmlentities($msg[self::$fields[$this->type]["FIELD"][$f[1]]["NAME"]],ENT_QUOTES,$charset); } else { $r.=htmlentities(self::$fields[$this->type]["FIELD"][$f[1]]["NAME"],ENT_QUOTES,$charset); } } elseif(array_key_exists($f[0],static::$pp)) { $r.=htmlentities(static::$pp[$f[0]]->t_fields[$f[2]]["TITRE"],ENT_QUOTES,$charset); } $r.="";//Colonne 3 $r.=$this->gen_selector_asc_desc("asc_desc_".$n."_".$fields[$i]); $r.="";//Colonne 4 $r.=$this->gen_selector_type("type_".$n."_".$fields[$i]); $r.="
"; return $r; } public function format_fields() { global $fields; $to_format=array(); for ($i=0; $iget_global_value("asc_desc_".$i."_".$fields[$i]); $to_format[$i]["TYPE"]=$this->get_global_value("type_".$i."_".$fields[$i]); } return $to_format; } public function unformat_fields($to_unformat) { global $fields; $fields=array(); for ($i=0; $iset_global_value("asc_desc_".$i."_".$fields[$i], $to_unformat[$i]["ASC_DESC"]); $this->set_global_value("type_".$i."_".$fields[$i], $to_unformat[$i]["TYPE"]); } } public static function get_types() { return array( "alpha" => "msg:frbr_sort_field_alpha", "num" => "msg:frbr_sort_field_num", "date" => "msg:frbr_sort_field_date", ); } public static function get_directions() { return array( "asc" => "msg:tri_croissant", "desc" => "msg:tri_decroissant" ); } public function get_human_query($fields) { global $msg; global $charset; if (!is_array($fields)) { $fields = encoding_normalize::json_decode($fields, true); } $human_query = ""; foreach ($fields as $field) { $f=explode("_",$field['NAME']); $title = ""; if ($f[0] == "authperso") { $groups = $this->grouped(); foreach($groups as $group) { foreach ($group as $id => $label) { if ($id == $field['NAME']) { $title = $label; break; } } } }else if($f[2] && isset(static::$fields[$this->type]["FIELD"][$f[1]]["TABLE"])) { $title = $msg[static::$fields[$this->type]["FIELD"][$f[1]]["TABLE"][0]["TABLEFIELD"][$f[2]]["NAME"]]; } elseif (isset($msg[static::$fields[$this->type]["FIELD"][$f[1]]["NAME"]])) { $title = $msg[static::$fields[$this->type]["FIELD"][$f[1]]["NAME"]]; } else { $title = static::$fields[$this->type]["FIELD"][$f[1]]["NAME"]; } if ($human_query) { $human_query .= ", "; } $human_query .= " ".htmlentities($title,ENT_QUOTES,$charset)." ".htmlentities(get_msg_to_display(static::get_types()[$field['TYPE']]),ENT_QUOTES,$charset)." (".htmlentities(get_msg_to_display(static::get_directions()[$field['ASC_DESC']]),ENT_QUOTES,$charset).") "; } return $human_query; } public function sort_data($data=array(), $offset = 0, $limit = 0, $use_authority_id = false) { global $fields; $limit = intval($limit); $offset = intval($offset); $sub_query=""; if (count($data)) { switch ($this->type) { case "authorities": $sub_query ="SELECT DISTINCT ".($use_authority_id ? "id_authority" : "num_object")." AS ".$this->field_keyName." FROM authorities WHERE ".($use_authority_id ? "id_authority" : "num_object")." in (".implode(",",$data).") AND type_object = ".$this->sub_type; break; default: $sub_query = "SELECT DISTINCT ".$this->field_keyName." FROM ".$this->field_tableName." WHERE ".$this->field_keyName." IN (".implode(",",$data).")"; break; } } $temporary_table_name = "tempo_".str_replace([" ","."],"_",microtime()); $query = "CREATE TEMPORARY TABLE $temporary_table_name ENGINE=MyISAM ($sub_query)"; pmb_mysql_query($query); $query = "ALTER TABLE $temporary_table_name ADD PRIMARY KEY (" . $this->field_keyName.")"; pmb_mysql_query($query); $orderby = ''; for ($i=0; $iget_global_value("asc_desc_".$i."_".$fields[$i]); $type = $this->get_global_value("type_".$i."_".$fields[$i]); //on ajoute la colonne au orderby $orderby .= $fields[$i]." ".$asc_desc.","; //on ajoute la colonne à la table temporaire $this->add_colum_temporary_table($temporary_table_name, $fields[$i], $type); $this->add_values_temporary_table($temporary_table_name, $fields[$i], $type, $data, $use_authority_id); } if ($orderby!="") { //on enleve la derniere virgule $orderby = substr($orderby, 0, strlen($orderby) - 1); $query = "SELECT " . $this->field_keyName . " FROM " . $temporary_table_name; $query .= " ORDER BY " . $orderby . ""; if (!empty($limit)) { $query .= " LIMIT $offset, $limit"; } $result = pmb_mysql_query($query); if($result) { if(pmb_mysql_num_rows($result)) { $data = array(); while ($row = pmb_mysql_fetch_object($result)) { $data[] = $row->{$this->field_keyName}; } } } } return $data; } }