// déclaration variables
var base,data,Les_Questions,Les_Reponses:string;
categorie,questions:TStringList;
i,j,row:integer;
FAQ_LISTE,HCategorie,HQuestion,Mask_Categorie,Mask_Question,CR,Rubrique: string;
css_faq,css_categorie,css_question,css_reponse,sortby: string;
SortSens:boolean;
Bloc_Faq,Bloc_Categorie,Bloc_Question,Bloc_Reponse,End_bloc: string;
MASK_Lien_Top,Texte_Lien_top,css_link_top:string;
id_faq:string;

begin
HCategorie := 'h2';
HQuestion := 'h3';
Mask_Categorie := '<<ICB(FAQ-CAT-%s)>><<WEB(')>>+HCategorie+<<FNT(STRING.-,-,-,-:')>>%s<<WEB(/')>>+HCategorie+<<FNT(STRING.-,-,-,-:')>>';
Mask_Question := '<<ICB(FAQ-Q-%s)>><<WEB(')>>+HQuestion +<<FNT(STRING.-,-,-,-:')>>%s<<WEB(/')>>+HQuestion +<<FNT(STRING.-,-,-,-:')>>';

if GetParam('Numeroter','true')='true' then
FAQ_LISTE := 'ol' else FAQ_LISTE := 'ul';


Rubrique := GetTitreReel;

if GetParam('Add-Link-Top','true')='true' then
Mask_Lien_top := '<<MCR(JI(qchPath,`')>>+Rubrique+<<FNT(STRING.-,-,-,-:'>FAQ-TOP')>>+<<FNT(NUMBER.-,-,-,-:#39)>>+<<FNT(STRING.-,-,-,-:'):')>>+GetParam(<<FNT(STRING.-,-,-,-:'Text-Link-Top')>>,<<FNT(STRING.-,-,-,-:'Retour en haut de page')>>)+<<FNT(STRING.-,-,-,-:')>>'
else Mask_Lien_top := '';

css_faq := GetParam('css-faq','');
css_categorie := GetParam('css-categorie','');
css_question := GetParam('css-question','');
css_reponse := GetParam('css-reponse','');
css_link_top := GetParam('css-link-top','');

SortBy := GetParam('SortBy','ordre');
SortSens := GetParam('SortSens','croissant')='croissant';

id_Faq := trim(GetParam('id-FAQ',''));


Base := GetParam('Base-Faq','');

if not Condition('_HTML_') then
begin
CR := chr(13)+chr(10);
Bloc_Faq := '<<ICB(FAQ-TOP)>>';
Bloc_Categorie := '';
Bloc_Question := '';
Bloc_Reponse := '';
End_bloc := cr;

if css_categorie<>'' then Mask_Categorie := '<<ICB(FAQ-CAT-%s)>><<FNT(')>>+css_categorie+<<FNT(STRING.-,-,-,-:'.-,-,-,-:%s)>>';
if css_question <>'' then Mask_Question := '<<ICB(FAQ-Q-%s)>><<FNT(')>>+css_question+<<FNT(STRING.-,-,-,-:'.-,-,-,-:%s)>>';

if Mask_Lien_top<>'' then
Mask_Lien_top := '<<ALIGNE : ')>>+css_link_top+<<FNT(STRING.-,-,-,-:',Droite>>'+Mask_Lien_top+ '<<¶>>';
end else begin
CR := '';
Bloc_Faq := '<<ICB(FAQ-TOP)>><<WEB(<div')>>;
<<FNT(KEYWORD.-,-,-,-:if)>> id_faq <><<FNT(STRING.-,-,-,-:'')>> <<FNT(KEYWORD.-,-,-,-:then)>> Bloc_Faq := Bloc_Faq+<<FNT(STRING.-,-,-,-:' id="')>>+id_faq+<<FNT(STRING.-,-,-,-:'"')>>;
<<FNT(KEYWORD.-,-,-,-:if)>> css_faq<><<FNT(STRING.-,-,-,-:'')>> <<FNT(KEYWORD.-,-,-,-:then)>> Bloc_Faq := Bloc_Faq+<<FNT(STRING.-,-,-,-:' class="')>>+css_faq+<<FNT(STRING.-,-,-,-:'"')>>;
Bloc_Faq := Bloc_Faq+<<FNT(STRING.-,-,-,-:'>)>>'
;

Bloc_Categorie := '<<WEB(<div')>>;
<<FNT(KEYWORD.-,-,-,-:if)>> css_categorie<><<FNT(STRING.-,-,-,-:'')>> <<FNT(KEYWORD.-,-,-,-:then)>> Bloc_Categorie := Bloc_Categorie+<<FNT(STRING.-,-,-,-:' class="')>>+css_categorie+<<FNT(STRING.-,-,-,-:'"')>>;
Bloc_Categorie := Bloc_CAtegorie+<<FNT(STRING.-,-,-,-:'>)>>'
;

Bloc_Question := '<<WEB(<div')>>;
<<FNT(KEYWORD.-,-,-,-:if)>> css_Question<><<FNT(STRING.-,-,-,-:'')>> <<FNT(KEYWORD.-,-,-,-:then)>> Bloc_Question := Bloc_Question+<<FNT(STRING.-,-,-,-:' class="')>>+css_Question+<<FNT(STRING.-,-,-,-:'"')>>;
Bloc_Question := Bloc_Question+<<FNT(STRING.-,-,-,-:'>)>>'
;

Bloc_Reponse := '<<WEB(<div')>>;
<<FNT(KEYWORD.-,-,-,-:if)>> css_Reponse<><<FNT(STRING.-,-,-,-:'')>> <<FNT(KEYWORD.-,-,-,-:then)>> Bloc_Reponse := Bloc_Reponse+<<FNT(STRING.-,-,-,-:' class="')>>+css_Reponse+<<FNT(STRING.-,-,-,-:'"')>>;
Bloc_Reponse := Bloc_Reponse+<<FNT(STRING.-,-,-,-:'>)>>'
;

End_bloc := ' <<WEB(</div>)>>';

if Mask_Lien_top<>'' then
begin
if css_link_top<>'' then css_link_top:=' class="'+css_link_top+'"';
Mask_Lien_top := '<<WEB(<p')>>+css_link_top+<<FNT(STRING.-,-,-,-:'>)>>'+Mask_Lien_top+ '<<WEB(</p)>)>>';
end;
end;






dbGo(base,1);
// on va maintenant extraire toute les catégories;
categorie := TStringList.create;
// nombre de ligne
row := dbRowCount(base);
for i:=1 to row do
begin
// on se positionne sur la ligne
dbGo(base,i);
data := dbGetData(base,'categorie');
// on évite les doublons
if Categorie.indexof(data)=-1 then Categorie.add(data);
end;
// on trie nos catégories
Categorie.sort;

Questions := TStringList.create;
Les_Questions := '';
Les_Reponses := '';
// pour chaque catégorie on va extraire les questions
for i:=0 to categorie.count-1 do
begin
Les_Questions := Les_Questions+Format(Mask_Categorie,[categorie.strings[i],categorie.strings[i]])+CR;
Les_Reponses := Les_Reponses+Bloc_categorie+'<<WEB(')>>+HCategorie+<<FNT(STRING.-,-,-,-:')>>'+categorie.strings[i]+ '<<WEB(/')>>+HCategorie+<<FNT(STRING.-,-,-,-:')>>'+CR;
// on filtre sur le champ 'categorie'
dbFind(base,dbFindField('categorie','=',categorie.strings[i]));

// on effectue le trie voulu (sur le champ ordre ou date, croissant ou decroissant)
dbFindSortNumeric(base,SortBy,SortSens);
// pour chaque question
row := dbFindRowCount(base);
if row>0 then
begin
Les_Questions := Les_Questions+'<<WEB(')>>+FAQ_LISTE+<<FNT(STRING.-,-,-,-:')>>'+CR;
Questions.clear;
for j:=1 to row do
begin
// on se positionne sur la ligne
dbFindGo(base,j);
data := dbFindGetData(base,'question');
Les_Questions := Les_Questions+'<<WEB(li)>> <<MCR(JI(qchPath,`')>>+Rubrique+<<FNT(STRING.-,-,-,-:'>FAQ-Q-')>>+data+<<FNT(NUMBER.-,-,-,-:#39)>>+<<FNT(STRING.-,-,-,-:'):')>>+data+<<FNT(STRING.-,-,-,-:')>><<WEB(</li>)>>'+CR;
Questions.add(data);

end;


// extraire les réponses pour chaque question
Les_Reponses := Les_Reponses+Bloc_Question+CR;
for j:=0 to Questions.count-1 do
begin
// on trouve la réponse en filtrant sur les champs 'categorie' et 'question'
dbFind(base,dbFindField('categorie','=',categorie.strings[i])+' AND '+dbFindField('question','=',Questions.strings[j]));

Les_Reponses := Les_reponses+Format(Mask_Question,[questions.strings[j],questions.strings[j]])+CR;
Les_Reponses := Les_Reponses+Bloc_Reponse+CR;
dbFindGo(base,1);
data := dbFindGetData(base,'reponse');

Les_Reponses := Les_Reponses+data+Mask_Lien_top+End_Bloc+CR;
end;
Les_Reponses := Les_Reponses+End_Bloc;
Les_Questions := Les_Questions+'<<WEB(/')>>+FAQ_LISTE+<<FNT(STRING.-,-,-,-:')>>'+CR;
end;
Les_Reponses := Les_Reponses+End_Bloc+CR;
end;

Writeln(Bloc_Faq);
writeln(Les_Questions);
writeln(Les_Reponses);
Writeln(End_Bloc);

Questions.free;
categorie.free;
end;
end.

Sommaire