"Det_Session",
"auth" => "Det_No_Auth",
"perm" => "Det_Perm",
"user" => "Det_User"
));
// Autres choix: newton\php3\phplib\det_fundp.inc
// Exemple: Challenge_Crypt_Auth
// permissions à avoir pour accéder à cette page
// $perm->check("utilisateur");
// Autres choix: admin,... cfr det_fundp.inc
// valeur initiales
if(!isset($joujou)) { $joujou=0; } else {}
// retenir les variables
// $sess->register("joujou");
// Infos de debug ? ("" pour faux, "1" pour vrai, par exemple)
$gibdebug= "0";
?>
v1..cn=>vn), ci, vi urldecoded
function qs_2tbl($qs) {
$termes = split('&', $qs);
$i = 0;
$tmp = array();
while ( $i < count($termes) ) {
if ($termes[$i] != "") {
$tbl = split('=', $termes[$i]);
$k = urldecode($tbl[0]);
$v = urldecode($tbl[1]);
// cas des $k1=$v1 répétés (tableaux)
if ( ereg("(.*)(\[\])", $k, $regs) ) {
$tmp[$regs[1]][] = $v;
} else {
$tmp[$k] = $v;
}
} else {}
$i++;
}
if ($gibdebug) {
printtabrec($tmp);
} else {}
return $tmp;
}
#---------------------------------------------------------------
# string qs_fromTbl ($tbl)
#---------------------------------------------------------------
// in: array(k1=>v1..kn=>vn) (urldecoded)
// out: query_string k1=v1&..kn=vn (urlencoded)
function qs_fromTbl ($tbl) {
$tmp = "";
while ( list($k,$v) = each($tbl) ) {
if (gettype($v)=="array") {
while ( list($k2,$v2) = each($v) ) {
$tmp .= urlencode($k) . '[]=' . urlencode($v2) . '&';
}
} elseif ( $v != "" ) {
$tmp = $tmp . urlencode($k) . '=' . urlencode($v) . '&';
} else {}
}
return $tmp;
} // qs_fromTbl
#---------------------------------------------------------------
# string qs_update ($qs, $key, $val)
#---------------------------------------------------------------
// in: query_string qs = 'c1=v1&..&cn=vn'
// out: $qs[$key/$val] ie c1=v1&..&cn=vn where ck=key and vk=val
// example: $qs2= qs_update( $QUERY_STRING, "row", "3" );
function qs_update ($qs, $key, $val) {
return ereg_replace ( "(.*)&$key=([^&]*)(&.*)$", "\\1&$key=$val\\3", $qs);
}
#---------------------------------------------------------------
# string qs_updateTbl
#---------------------------------------------------------------
// in: query_string $qs: c1=v1&..&cn=vn,
// tbl(a1=>b1..an=>bn)
// out: $qs[ai/bi]
// example: $qs2= qs_updateTbl( $QUERY_STRING, array("row"=>"3","npp"=>"5") );
function qs_updateTbl ($qs,$tbl) {
$tmp = $qs;
while ( list($k,$v) = each($tbl) ) {
$tmp = qs_update ($tmp, $k, $v);
}
return $tmp;
}
#===============================================================
# Auxiliary useful/debug functions
#===============================================================
#---------------------------------------------------------------
# html printtab ($tab)
#---------------------------------------------------------------
// in: array(k1=>v1..kn=>vn)
// out: html "(k1,v1)
\n..(kn,vn)
\n"
function printtab ($tab) {
while ( list($k,$v) = each($tab) ) {
echo "($k,$v)
\n";
}
} // printtab
#---------------------------------------------------------------
# html printtabrec ($tab)
#---------------------------------------------------------------
// idem printtab, even if ki is another array
function printtabrec ($tab) {
while ( list($k,$v) = each($tab) ) {
if ( gettype($v) == "array" ) {
echo "($k, ";
while ( list($k2,$v2) = each($v) ) {
echo "[$k2,$v2] ";
}
echo " )
\n";
} else {
echo "($k,$v)
\n";
}
}
}
// TODO
#---------------------------------------------------------------
# string quote_correct_1 ($str)
#---------------------------------------------------------------
// out: all "\'" to "x" in $str
function quote_correct_1 ($str) {
echo "$str[1] OO
";
// écarteler les
$tab = split ("'", $str);
printtab ($tab); //KK
// joindre avec '
$tmp = join ("?", $tab);
print $tmp;
return $tmp;
}
#---------------------------------------------------------------
# bool in_tbl ($tbl, $val)
#---------------------------------------------------------------
function in_tbl ($tbl, $val) {
$found = "";
while ( list($k, $v) = each ($tbl) ) {
if ($v == $val) {
$found = '1';
break;
} else {}
}
return $found;
}
#===============================================================
# SQL utility functions
#===============================================================
#---------------------------------------------------------------
# string SQL_whereconv($ch, $op, $val, $withcase)
#---------------------------------------------------------------
function SQL_whereconv($ch, $op, $val, $withcase) {
if (! $withcase) {
// La fonction SQL 'Upper' devient 'Ucase' chez Micro$oft :-(
$champ = "upper($ch)";
// Chez M$, ca ne marche que d'un côté : PHP fait le reste
$valeur = strtoupper($val);
} else {
$champ = $ch;
$valeur = $val;
}
switch($op) {
case 'commence':
return $champ . " LIKE '" . $valeur . "%' "; break;
case 'contient':
return $champ . " LIKE '%" . $valeur . "%' "; break;
case 'egal':
return $champ . " = '" . $valeur . "' "; break;
case 'inf':
return $champ . " <= '" . $valeur . "' "; break;
case 'sup':
return $champ . " >= '" . $valeur . "' "; break;
}
}
#---------------------------------------------------------------
# array SQL_titre ($affchamps, $new_1, $new_2)
#---------------------------------------------------------------
function SQL_titre ($affchamps, $new_1, $new_2) {
$tmp = array();
while ( list($k, $v) = each ($affchamps) ) {
if ($v == 'titre') {
$tmp[] = $new_1;
$tmp[] = $new_2;
} else {
$tmp[] = $v;
}
}
return $tmp;
}
#---------------------------------------------------------------
# array aff_modifs ($affchamps)
#---------------------------------------------------------------
# Exemple: ajouter un nombre.
#---------------------------------------------------------------
function aff_modifs ($affchamps) {
global $gibdebug;
$tmp = array();
$tmp[0] = 'num';
while ( list($k, $v) = each ($affchamps) ) {
if ($gibdebug && ($v == 'titre')) {
# Afficher les titre-i en mode debug
$tmp[] = 'titre1';
$tmp[] = 'titre2';
$tmp[] = 'titre';
} else {
# Afficher titre ou autre
$tmp[] = $v;
}
}
return $tmp;
}
#---------------------------------------------------------------
# string SQL_print ($select, $from, $where, $order)
#---------------------------------------------------------------
function SQL_print ($select, $from, $where, $order) {
echo "SELECT $select\n
FROM $from\n
WHERE $where\n
$order
";
}
#---------------------------------------------------------------
# string SQL_makequery ($ch, $op, $term, $order, $sortkey, $asc, $withcase)
#---------------------------------------------------------------
function SQL_makequery ($ch, $op, $term, $order, $sortkey, $asc, $withcase) {
// in: $ch, $op, $term
// out: SQL SELECT (from document table)
global $affchamps, $gibdebug;
// $affchamps = array('auteurs', 'titre1', 'titre2', 'd.nodoc', 'site');
$select_q = $affchamps;
// Bug: M$ SQL_jet KO if sortkey not in fields names :-(
if ( $order and !in_tbl($affchamps, $sortkey) ) {
$select_q[]= $sortkey;
$affchamps[]= $sortkey;
} else {}
// Add Titre (as titre1 . titre2)
$select_q = SQL_titre ($select_q, 'titre1', 'titre2');
$from_q = 'document AS d, exempla AS e';
// Concat sometimes inconsistent in M$ SQL_Jet
// M$: concatenation "str1 || str2" de SQL devient "str1 & str2" :-(
$champ_q = ($ch == 'titre') ? 'titre1 || titre2' : $ch;
$where_q = SQL_whereconv($champ_q, $op, $term, $withcase);
$where_q .= " AND d.nodoc = e.nodoc ";
if ($order) {
$order_q = " ORDER BY ";
if ($sortkey == 'titre') { // sort by titre1, titre2
$order_q .= 'titre1 ';
$order_q .= ($asc == "") ? "ASC" : $asc;
$order_q .= ', titre2 ';
$order_q .= ($asc == "") ? "ASC" : $asc;
} else {
$order_q .= $sortkey . " ";
$order_q .= ($asc == "") ? "ASC" : $asc;
}
} else {
$order_q = "";
}
// ajout de 'DISTINCT' car duplicats sans raison
$SQL_query = sprintf ('SELECT DISTINCT %s FROM %s WHERE %s %s',
join(', ', $select_q),
$from_q,
$where_q,
$order_q );
if ($gibdebug) {
SQL_print ( join(', ', $select_q), $from_q, $where_q, $order_q );
} else {}
return $SQL_query;
}
#===============================================================
# Auxiliary (dynamic) HTML functions
#===============================================================
#---------------------------------------------------------------
# int borne_sup ($i, $npp, $n)
#---------------------------------------------------------------
function borne_sup ($i, $npp, $n) {
return ($i+$npp-1 <= $n) ? $i+$npp-1 : $n;
}
#---------------------------------------------------------------
# array prev_bornes ($i, $npp, $n)
#---------------------------------------------------------------
function prev_bornes ($i, $npp, $n) {
$tmp = array();
if ($i >= $npp+1) {
$tmp[0] = $i - $npp;
$tmp[1] = $i - 1;
} else {
$tmp[0] = 0;
$tmp[1] = 0;
}
return $tmp;
}
#---------------------------------------------------------------
# array next_bornes ($i, $npp, $n)
#---------------------------------------------------------------
function next_bornes ($i, $npp, $n) {
$tmp = array();
if ($i+$npp <= $n) {
$tmp[0] = $i + $npp;
$tmp[1] = borne_sup($i+$npp,$npp, $n);
} else {
$tmp[0] = 0;
$tmp[1] = 0;
}
return $tmp;
}
#---------------------------------------------------------------
# string url_from_tbl ($tbl)
#---------------------------------------------------------------
// in: array $tbl (query_string)
// out: html url (with session id and new query_string)
// warning: $QUERY_STRING value overridden
function url_from_tbl ($tbl) {
global $QUERY_STRING, $sess;
$QUERY_STRING = qs_fromTbl($tbl);
if ($gibdebug) { print "
$QUERY_STRING
\n"; } else {}
// return $PHP_SELFURL;
return $sess->self_url();
}
#---------------------------------------------------------------
# string make_url_page ($qs_tbl, $j, $npp, $nbrow)
#---------------------------------------------------------------
function make_url_page ($qs_tbl, $j, $npp, $nbrow) {
$borne0 = 1+($j-1)*$npp;
$borne1 = borne_sup ($borne0, $npp, $nbrow);
$qs_tbl["row"] = $borne0;
$tmp = "" . $j . "\n";
return $tmp;
}
#---------------------------------------------------------------
# string make_situ ($i, $npp, $n)
#---------------------------------------------------------------
function make_situ ($i, $npp, $n) {
$bs = borne_sup($i, $npp, $n);
return "Résultats actuels : de $i à $bs (parmi $n)
\n";
}
#---------------------------------------------------------------
# string make_pages ($qs_tbl, $i, $npp, $nbrow)
#---------------------------------------------------------------
function make_pages ($qs_tbl, $i, $npp, $nbrow) {
$thispage = 1 + (int) (($i-1)/$npp);
$maxpage = 1 + (int) (($nbrow-1)/$npp);
$tmp = "";
for ($j=1; $j<=$maxpage; $j++) {
if ($j == $thispage) {
$tmp .= "$thispage ";
} else {
$tmp .= make_url_page($qs_tbl, $j, $npp, $nbrow) . " ";
}
}
return "$maxpage page(s) de $npp résultats : " . $tmp . "\n
\n";
}
#---------------------------------------------------------------
# array make_prev_next ($qs_tbl, $i, $npp, $n)
#---------------------------------------------------------------
function make_prev_next ($qs_tbl, $i, $npp, $n) {
global $gibdebug;
$prev_next = "Résultats ";
$tmp = prev_bornes ($i, $npp, $n);
if ($tmp[0] == 0) {
$prev_next .= "précédents";
} else {
$qs_tbl["row"] = $tmp[0];
$prev_next .= "précédents"
. " ($tmp[0] à $tmp[1])\n";
if ($gibdebug) { echo url_from_tbl($qs_tbl) . "
\n"; } else {}
}
$prev_next .= " ou \n";
$tmp = next_bornes ($i, $npp, $n);
if ($tmp[0] == 0) {
$prev_next .= "suivants";
} else {
$qs_tbl["row"] = $tmp[0];
$prev_next .= "suivants"
. " ($tmp[0] à $tmp[1])\n";
if ($gibdebug) { echo url_from_tbl($qs_tbl) . "
\n"; } else {}
}
return $prev_next .= "
\n";
}
#---------------------------------------------------------------
# html affreload($qs_tbl, $formname)
#---------------------------------------------------------------
function affreload($qs_tbl, $formname) {
$qs_tbl["etape"] = "reinit";
echo '
Plan du site
|
FUNDP > DET > CeFIS > BIBLIOTHEQUE > RECHERCHE > RESULTATS |
|
RESULTATS DE LA RECHERCHE\"$nomchamps[$champ1]\""; // don't display "l\'enfant"... $theterm = ereg_replace ("\\\'", "'", $term1); echo " $nomop[$oper1] \"$theterm\""; if (! $withcase) { echo " (\"" . strtoupper($tmp) . "\" en majuscules)\n"; } else { echo " \n"; } echo "Triés selon " . $nomchamps[$sortkey] . ""; echo " par ordre " . $nomtri[$asc] . " \n"; // init for all links below $qs_tbl = $qs_tbl0; // Btn "search again" affreload($qs_tbl, "again1"); // Query DataBase with generated SQL $db = new DB_Gibus; $myquery = SQL_makequery ($champ1, $oper1, $term1, $order, $sortkey, $asc, $withcase); $queryid = $db->query( $myquery ); $nbrows = $db->num_rows(); if ($nbrows == 0) { // No result found print " Désolé, aucun livre ne correspondait "; } else { // Nb of results print "$nbrows résultat(s) trouvé(s) "; global $HTTP_GET_VARS; // for the fun ? $npp = $HTTP_GET_VARS["npp"]; if ($gibdegug) { echo "npp: $npp\n"; } else {} // correct user data and print results if ($npp == "" || $npp <= 0) { $npp = 10; } else {} if ($split) { // print page by page if ($npp > 100) { $npp = 100; } else {} affresult_page($qs_tbl, $row, $npp, $nbrows); } else { // print all results in same page affresult(); } } // Nb of results print " $nbrows résultat(s) trouvé(s) "; // Btn "search again" affreload($qs_tbl, "again2"); ?> |
||
|
|