示例#1
0
文件: sort.class.php 项目: hogsim/PMB
 /**
  * Parse les fichiers XML de parametres
  * il y a un fichier par type de tris
  */
 function parse()
 {
     global $include_path;
     global ${$params_name};
     global $charset;
     global $dbh;
     $params_name = $this->dSort->sortName . "_params";
     $params = ${$params_name};
     if ($params) {
         $this->params = $params;
     } else {
         $nomfichier = $include_path . "/sort/" . $this->dSort->sortName . "/sort.xml";
         if (file_exists($include_path . "/sort/" . $this->dSort->sortName . "/sort_subst.xml")) {
             $nomfichier = $include_path . "/sort/" . $this->dSort->sortName . "/sort_subst.xml";
             $fp = fopen($nomfichier, "r");
         } else {
             if (file_exists($nomfichier)) {
                 $fp = fopen($nomfichier, "r");
             }
         }
         if ($fp) {
             //un fichier est ouvert donc on le lit
             $xml = fread($fp, filesize($nomfichier));
             //on le ferme
             fclose($fp);
             //on le parse pour le transformer en tableau
             $params = _parser_text_no_function_($xml, "SORT");
             //on le stocke dans la classe
             $this->params = $params;
         } else {
             $this->error = true;
             $this->error_message = "Can't open definition file";
         }
     }
     //tri perso
     $p_perso = new parametres_perso("notices");
     foreach ($p_perso->t_fields as $key => $t_field) {
         if ($t_field['OPAC_SHOW'] && $t_field['OPAC_SORT']) {
             $param = _parser_text_no_function_("<?xml version='1.0' encoding='" . $charset . "'?>\n" . $t_field['OPTIONS'], "OPTIONS");
             switch ($t_field['TYPE']) {
                 case "comment":
                 case "text":
                     if ($param['REPETABLE'][0]['value']) {
                         $tablefield = "group_concat(" . $p_perso->prefix . "_custom_" . $t_field['DATATYPE'] . " separator ' ')";
                         $groupby = "group by notice_id";
                     } else {
                         $tablefield = $p_perso->prefix . "_custom_" . $t_field['DATATYPE'];
                         $groupby = "";
                     }
                     $p_tri = array('SOURCE' => "cp", 'TYPEFIELD' => "select", 'ID' => "cp" . $key, 'TYPE' => "text", 'NAME' => $t_field['NAME'], 'LABEL' => $t_field['TITRE'], 'TABLEFIELD' => array('value' => $tablefield), 'REQ_SUITE' => "left join " . $p_perso->prefix . "_custom_values on notices.notice_id = " . $p_perso->prefix . "_custom_values." . $p_perso->prefix . "_custom_origine where " . $p_perso->prefix . "_custom_values." . $p_perso->prefix . "_custom_champ = '" . $key . "' " . $groupby);
                     break;
                 case "list":
                     if ($param['MULTIPLE'][0]['value']) {
                         $tablefield = "group_concat(" . $p_perso->prefix . "_custom_list_lib separator ' ')";
                         $groupby = "group by notice_id";
                     } else {
                         $tablefield = $p_perso->prefix . "_custom_list_lib";
                         $groupby = "";
                     }
                     $p_tri = array('SOURCE' => "cp", 'TYPEFIELD' => "select", 'ID' => "cp" . $key, 'TYPE' => "text", 'NAME' => $t_field['NAME'], 'LABEL' => $t_field['TITRE'], 'TABLEFIELD' => array('value' => $tablefield), 'REQ_SUITE' => "left join " . $p_perso->prefix . "_custom_values on notices.notice_id = " . $p_perso->prefix . "_custom_values." . $p_perso->prefix . "_custom_origine \nleft join " . $p_perso->prefix . "_custom_lists on " . $p_perso->prefix . "_custom_" . $t_field['DATATYPE'] . " = " . $p_perso->prefix . "_custom_list_value \nwhere " . $p_perso->prefix . "_custom_lists." . $p_perso->prefix . "_custom_champ ='" . $key . "' and " . $p_perso->prefix . "_custom_values." . $p_perso->prefix . "_custom_champ ='" . $key . "'  " . $groupby);
                     break;
                 case "date_box":
                     $p_tri = array('SOURCE' => "cp", 'TYPEFIELD' => "select", 'ID' => "cp" . $key, 'TYPE' => "text", 'NAME' => $t_field['NAME'], 'LABEL' => $t_field['TITRE'], 'TABLEFIELD' => array('value' => $p_perso->prefix . "_custom_" . $t_field['DATATYPE']), 'REQ_SUITE' => "left join " . $p_perso->prefix . "_custom_values on notices.notice_id = " . $p_perso->prefix . "_custom_values." . $p_perso->prefix . "_custom_origine where " . $p_perso->prefix . "_custom_values." . $p_perso->prefix . "_custom_champ = '" . $key . "'");
                     break;
                 case "query_list":
                     $tableid = "";
                     $tablefield = "";
                     $tablename = "";
                     if ($param['MULTIPLE'][0]['value']) {
                         if ($param['QUERY'][0]['value']) {
                             $res = pmb_mysql_query($param['QUERY'][0]['value'], $dbh);
                             if ($res) {
                                 $tableid = pmb_mysql_field_name($res, 0);
                                 $tablefield = "group_concat(" . pmb_mysql_field_name($res, 1) . " separator ' ')";
                                 $tablename = pmb_mysql_field_table($res, 0);
                             }
                         }
                         $groupby = "group by notice_id";
                     } else {
                         if ($param['QUERY'][0]['value']) {
                             $res = pmb_mysql_query($param['QUERY'][0]['value'], $dbh);
                             if ($res) {
                                 $tableid = pmb_mysql_field_name($res, 0);
                                 $tablefield = pmb_mysql_field_name($res, 1);
                                 $tablename = pmb_mysql_field_table($res, 0);
                             }
                         }
                         $groupby = "";
                     }
                     $p_tri = array('SOURCE' => "cp", 'TYPEFIELD' => "select", 'ID' => "cp" . $key, 'TYPE' => "text", 'NAME' => $t_field['NAME'], 'LABEL' => $t_field['TITRE'], 'TABLEFIELD' => array('value' => $tablefield), 'REQ_SUITE' => "left join " . $p_perso->prefix . "_custom_values on notices.notice_id = " . $p_perso->prefix . "_custom_values." . $p_perso->prefix . "_custom_origine\nleft join " . $tablename . " on " . $p_perso->prefix . "_custom_" . $t_field['DATATYPE'] . " = " . $tableid . "\t\t\t\t\t\t \nwhere " . $p_perso->prefix . "_custom_values." . $p_perso->prefix . "_custom_champ ='" . $key . "' " . $groupby);
                     break;
                 default:
                     $p_tri = array();
                     break;
             }
             if ($p_tri) {
                 $this->params['FIELD'][] = $p_tri;
             }
         }
     }
 }
 function gen_xml($requete, $champ_pivot)
 {
     global $msg;
     $execute_query = pmb_mysql_query($requete);
     $ret = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
     $ret .= "<fields>";
     $table = pmb_mysql_field_table($execute_query, $champ_pivot);
     $header = "<reference dynamicfields=\"\" prefixname=\"\">" . $table . "</reference>";
     $header .= "<referencekey>" . $champ_pivot . "</referencekey>";
     $i = 0;
     while ($i < pmb_mysql_num_fields($execute_query)) {
         $meta = pmb_mysql_fetch_field($execute_query);
         if ($meta) {
             $fields .= "<field name=\"" . $meta->name . "\" type=\"" . $meta->type . "\" value=\"\" id=\"" . $i . "\" filterable=\"yes\" sortable=\"yes\" displayable=\"yes\" defaultvalue=\"\">";
             $fields .= "<tablefield>" . $meta->name . "</tablefield>";
         } else {
             $fields .= "<field>";
             $this->error = true;
             $this->error_message = str_replace('%s', $i, $msg["erreur_detail_champ"]);
             $ret .= str_replace('%s', $i, $msg["erreur_detail_champ"]);
         }
         $fields .= "</field>";
     }
     $fields .= "<specialfields></specialfields>";
     $ret .= $header . $fields . "</fields>";
     $ret = htmlspecialchars($ret);
     return $ret;
 }