@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | + 'id_parent'; |
|
| 51 | 51 | |
| 52 | - $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 52 | + $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return void |
| 68 | 68 | **/ |
| 69 | 69 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 70 | - $not = $crit->not; |
|
| 71 | - $boucle = &$boucles[$idb]; |
|
| 72 | - $id = $boucle->primary; |
|
| 73 | - |
|
| 74 | - if ($not or !$id) { |
|
| 75 | - return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | - } |
|
| 77 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | - $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 70 | + $not = $crit->not; |
|
| 71 | + $boucle = &$boucles[$idb]; |
|
| 72 | + $id = $boucle->primary; |
|
| 73 | + |
|
| 74 | + if ($not or !$id) { |
|
| 75 | + return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | + } |
|
| 77 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | + $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -95,73 +95,73 @@ discard block |
||
| 95 | 95 | * @return void |
| 96 | 96 | **/ |
| 97 | 97 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 98 | - $boucle = &$boucles[$idb]; |
|
| 99 | - $primary = $boucle->primary; |
|
| 100 | - |
|
| 101 | - // la table nécessite une clé primaire, non composée |
|
| 102 | - if (!$primary or strpos($primary, ',')) { |
|
| 103 | - return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | - |
|
| 108 | - // le doublon s'applique sur un type de boucle (article) |
|
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | - |
|
| 111 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | - // on obtient $nom = "'article' . 'nom'" |
|
| 113 | - if (isset($crit->param[0])) { |
|
| 114 | - $nom .= "." . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | - |
|
| 121 | - // on crée un sql_in avec la clé primaire de la table |
|
| 122 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | - // $doublons et son index, ici $nom |
|
| 124 | - |
|
| 125 | - // debut du code "sql_in('articles.id_article', " |
|
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 130 | - |
|
| 131 | - // le debut complet du code des doublons |
|
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 133 | - |
|
| 134 | - // nom du doublon "('article' . 'nom')]" |
|
| 135 | - $fin_doub = "($nom)]"; |
|
| 136 | - |
|
| 137 | - // si on trouve un autre critère doublon, |
|
| 138 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | - foreach ($boucle->where as $k => $w) { |
|
| 140 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | - // fusionner le sql_in (du where) |
|
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | - $x = strpos($boucle->hash, $init_comment); |
|
| 145 | - $len = strlen($init_comment); |
|
| 146 | - $boucle->hash = |
|
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | - |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | - $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 155 | - |
|
| 156 | - // déclarer le doublon s'il n'existe pas encore |
|
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | - # {!doublons A}{doublons B} |
|
| 163 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 98 | + $boucle = &$boucles[$idb]; |
|
| 99 | + $primary = $boucle->primary; |
|
| 100 | + |
|
| 101 | + // la table nécessite une clé primaire, non composée |
|
| 102 | + if (!$primary or strpos($primary, ',')) { |
|
| 103 | + return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | + |
|
| 108 | + // le doublon s'applique sur un type de boucle (article) |
|
| 109 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | + |
|
| 111 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | + // on obtient $nom = "'article' . 'nom'" |
|
| 113 | + if (isset($crit->param[0])) { |
|
| 114 | + $nom .= "." . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | + |
|
| 121 | + // on crée un sql_in avec la clé primaire de la table |
|
| 122 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | + // $doublons et son index, ici $nom |
|
| 124 | + |
|
| 125 | + // debut du code "sql_in('articles.id_article', " |
|
| 126 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 130 | + |
|
| 131 | + // le debut complet du code des doublons |
|
| 132 | + $debut_doub = $debut_in . $debut_doub; |
|
| 133 | + |
|
| 134 | + // nom du doublon "('article' . 'nom')]" |
|
| 135 | + $fin_doub = "($nom)]"; |
|
| 136 | + |
|
| 137 | + // si on trouve un autre critère doublon, |
|
| 138 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | + foreach ($boucle->where as $k => $w) { |
|
| 140 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | + // fusionner le sql_in (du where) |
|
| 142 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | + $x = strpos($boucle->hash, $init_comment); |
|
| 145 | + $len = strlen($init_comment); |
|
| 146 | + $boucle->hash = |
|
| 147 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | + |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | + $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 155 | + |
|
| 156 | + // déclarer le doublon s'il n'existe pas encore |
|
| 157 | + $boucle->hash .= $init_comment . $init_code; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | + # {!doublons A}{doublons B} |
|
| 163 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | * @return void |
| 183 | 183 | **/ |
| 184 | 184 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 185 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | - $param = 'oui'; |
|
| 187 | - } |
|
| 188 | - if ($crit->not) { |
|
| 189 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | - } |
|
| 191 | - $boucle = &$boucles[$idb]; |
|
| 192 | - $boucle->lang_select = $param; |
|
| 185 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | + $param = 'oui'; |
|
| 187 | + } |
|
| 188 | + if ($crit->not) { |
|
| 189 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | + } |
|
| 191 | + $boucle = &$boucles[$idb]; |
|
| 192 | + $boucle->lang_select = $param; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -211,18 +211,18 @@ discard block |
||
| 211 | 211 | * @return void |
| 212 | 212 | **/ |
| 213 | 213 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 214 | - list($un, $deux) = $crit->param; |
|
| 215 | - $un = $un[0]->texte; |
|
| 216 | - $deux = $deux[0]->texte; |
|
| 217 | - if ($deux) { |
|
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 222 | - '"'; |
|
| 223 | - } else { |
|
| 224 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | - } |
|
| 214 | + list($un, $deux) = $crit->param; |
|
| 215 | + $un = $un[0]->texte; |
|
| 216 | + $deux = $deux[0]->texte; |
|
| 217 | + if ($deux) { |
|
| 218 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | + $un . |
|
| 220 | + '"]) . ",' . |
|
| 221 | + $deux . |
|
| 222 | + '"'; |
|
| 223 | + } else { |
|
| 224 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -256,57 +256,57 @@ discard block |
||
| 256 | 256 | **/ |
| 257 | 257 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 258 | 258 | |
| 259 | - $boucle = &$boucles[$idb]; |
|
| 260 | - // definition de la taille de la page |
|
| 261 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | - : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 263 | - |
|
| 264 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | - } else { |
|
| 267 | - $r = intval($r[2]); |
|
| 268 | - $pas = strval($r ? $r : 10); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Calcul du nommage de la pagination si il existe. |
|
| 272 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | - $type = "'$idb'"; |
|
| 275 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | - // Syntaxe {pagination 20, nom} |
|
| 277 | - if (isset($crit->param[0][1])) { |
|
| 278 | - $type = calculer_liste(array($crit->param[0][1]), $idb, $boucles, $boucle->id_parent); |
|
| 279 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | - elseif (isset($crit->param[1][0])) { |
|
| 281 | - $type = calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | - $partie = |
|
| 287 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | - . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | - . "\t}\n" |
|
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | - |
|
| 295 | - $boucle->hash .= ' |
|
| 259 | + $boucle = &$boucles[$idb]; |
|
| 260 | + // definition de la taille de la page |
|
| 261 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | + : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 263 | + |
|
| 264 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | + } else { |
|
| 267 | + $r = intval($r[2]); |
|
| 268 | + $pas = strval($r ? $r : 10); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Calcul du nommage de la pagination si il existe. |
|
| 272 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | + $type = "'$idb'"; |
|
| 275 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | + // Syntaxe {pagination 20, nom} |
|
| 277 | + if (isset($crit->param[0][1])) { |
|
| 278 | + $type = calculer_liste(array($crit->param[0][1]), $idb, $boucles, $boucle->id_parent); |
|
| 279 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | + elseif (isset($crit->param[1][0])) { |
|
| 281 | + $type = calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | + $partie = |
|
| 287 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | + . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | + . "\t}\n" |
|
| 293 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | + |
|
| 295 | + $boucle->hash .= ' |
|
| 296 | 296 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 297 | 297 | |
| 298 | - $boucle->total_parties = $pas; |
|
| 299 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | - // sauf si pas de primaire, ou si primaire composee |
|
| 302 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | - if ($boucle->primary |
|
| 305 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | - and !in_array($t, $boucle->select) |
|
| 307 | - ) { |
|
| 308 | - $boucle->select[] = $t; |
|
| 309 | - } |
|
| 298 | + $boucle->total_parties = $pas; |
|
| 299 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | + // sauf si pas de primaire, ou si primaire composee |
|
| 302 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | + if ($boucle->primary |
|
| 305 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | + and !in_array($t, $boucle->select) |
|
| 307 | + ) { |
|
| 308 | + $boucle->select[] = $t; |
|
| 309 | + } |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
@@ -328,24 +328,24 @@ discard block |
||
| 328 | 328 | **/ |
| 329 | 329 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 330 | 330 | |
| 331 | - $boucle = &$boucles[$idb]; |
|
| 331 | + $boucle = &$boucles[$idb]; |
|
| 332 | 332 | |
| 333 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 333 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 335 | 335 | |
| 336 | - return; |
|
| 337 | - } |
|
| 336 | + return; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (isset($crit->param[0])) { |
|
| 340 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | - } else { |
|
| 342 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | - } |
|
| 339 | + if (isset($crit->param[0])) { |
|
| 340 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | + } else { |
|
| 342 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | - $boucle->hash .= ' |
|
| 345 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | + $boucle->hash .= ' |
|
| 347 | 347 | // RECHERCHE' |
| 348 | - . ($crit->cond ? ' |
|
| 348 | + . ($crit->cond ? ' |
|
| 349 | 349 | if (!strlen(' . $quoi . ')){ |
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | 351 | } else' : '') . ' |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | - $boucle->select[] = $t; |
|
| 362 | - } # pour postgres, neuneu ici |
|
| 363 | - // jointure uniquement sur le serveur principal |
|
| 364 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | - if (!$boucle->sql_serveur) { |
|
| 366 | - $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | - } |
|
| 369 | - $boucle->select[] = '$rech_select'; |
|
| 370 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | - |
|
| 372 | - // et la recherche trouve |
|
| 373 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 359 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | + $boucle->select[] = $t; |
|
| 362 | + } # pour postgres, neuneu ici |
|
| 363 | + // jointure uniquement sur le serveur principal |
|
| 364 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | + if (!$boucle->sql_serveur) { |
|
| 366 | + $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | + } |
|
| 369 | + $boucle->select[] = '$rech_select'; |
|
| 370 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | + |
|
| 372 | + // et la recherche trouve |
|
| 373 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -387,25 +387,25 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | **/ |
| 389 | 389 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 390 | - $boucle = &$boucles[$idb]; |
|
| 391 | - $prim = $boucle->primary; |
|
| 392 | - $table = $boucle->id_table; |
|
| 393 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | - $boucle->where[] = |
|
| 396 | - array( |
|
| 397 | - "'OR'", |
|
| 398 | - array( |
|
| 399 | - "'AND'", |
|
| 400 | - array("'='", "'$table.id_trad'", 0), |
|
| 401 | - array("'='", "'$table.$prim'", $dprim) |
|
| 402 | - ), |
|
| 403 | - array( |
|
| 404 | - "'AND'", |
|
| 405 | - array("'>'", "'$table.id_trad'", 0), |
|
| 406 | - array("'='", "'$table.id_trad'", $arg) |
|
| 407 | - ) |
|
| 408 | - ); |
|
| 390 | + $boucle = &$boucles[$idb]; |
|
| 391 | + $prim = $boucle->primary; |
|
| 392 | + $table = $boucle->id_table; |
|
| 393 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | + $boucle->where[] = |
|
| 396 | + array( |
|
| 397 | + "'OR'", |
|
| 398 | + array( |
|
| 399 | + "'AND'", |
|
| 400 | + array("'='", "'$table.id_trad'", 0), |
|
| 401 | + array("'='", "'$table.$prim'", $dprim) |
|
| 402 | + ), |
|
| 403 | + array( |
|
| 404 | + "'AND'", |
|
| 405 | + array("'>'", "'$table.id_trad'", 0), |
|
| 406 | + array("'='", "'$table.id_trad'", $arg) |
|
| 407 | + ) |
|
| 408 | + ); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return void |
| 424 | 424 | **/ |
| 425 | 425 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 426 | - $boucle = &$boucles[$idb]; |
|
| 427 | - $prim = $boucle->primary; |
|
| 428 | - $table = $boucle->id_table; |
|
| 429 | - |
|
| 430 | - $c = |
|
| 431 | - array( |
|
| 432 | - "'OR'", |
|
| 433 | - array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | - array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | - ); |
|
| 436 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 426 | + $boucle = &$boucles[$idb]; |
|
| 427 | + $prim = $boucle->primary; |
|
| 428 | + $table = $boucle->id_table; |
|
| 429 | + |
|
| 430 | + $c = |
|
| 431 | + array( |
|
| 432 | + "'OR'", |
|
| 433 | + array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | + array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | + ); |
|
| 436 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -450,20 +450,20 @@ discard block |
||
| 450 | 450 | **/ |
| 451 | 451 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 452 | 452 | |
| 453 | - $boucle = &$boucles[$idb]; |
|
| 454 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | - 'id_parent'; |
|
| 458 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + $boucle = &$boucles[$idb]; |
|
| 454 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | + 'id_parent'; |
|
| 458 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 459 | 459 | |
| 460 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | - $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 460 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | + $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 462 | 462 | |
| 463 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | - else { |
|
| 465 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | - } |
|
| 463 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | + else { |
|
| 465 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -494,37 +494,37 @@ discard block |
||
| 494 | 494 | **/ |
| 495 | 495 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 496 | 496 | |
| 497 | - $not = $crit->not; |
|
| 498 | - $boucle = &$boucles[$idb]; |
|
| 499 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | - if (isset($crit->param[0])) { |
|
| 501 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | - // sinon on le prend chez une boucle parente |
|
| 503 | - } else { |
|
| 504 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - //Trouver une jointure |
|
| 508 | - $champ = "id_rubrique"; |
|
| 509 | - $desc = $boucle->show; |
|
| 510 | - //Seulement si necessaire |
|
| 511 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | - $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | - $decompose = decompose_champ_id_objet($champ); |
|
| 517 | - $champ = array_shift($decompose); |
|
| 518 | - $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | - } |
|
| 520 | - } else { |
|
| 521 | - $cle = $boucle->id_table; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 497 | + $not = $crit->not; |
|
| 498 | + $boucle = &$boucles[$idb]; |
|
| 499 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | + if (isset($crit->param[0])) { |
|
| 501 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | + // sinon on le prend chez une boucle parente |
|
| 503 | + } else { |
|
| 504 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + //Trouver une jointure |
|
| 508 | + $champ = "id_rubrique"; |
|
| 509 | + $desc = $boucle->show; |
|
| 510 | + //Seulement si necessaire |
|
| 511 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | + $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | + $decompose = decompose_champ_id_objet($champ); |
|
| 517 | + $champ = array_shift($decompose); |
|
| 518 | + $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | + } |
|
| 520 | + } else { |
|
| 521 | + $cle = $boucle->id_table; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | + . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -540,15 +540,15 @@ discard block |
||
| 540 | 540 | **/ |
| 541 | 541 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 542 | 542 | |
| 543 | - $boucle = &$boucles[$idb]; |
|
| 544 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | - $serveur = $boucle->sql_serveur; |
|
| 543 | + $boucle = &$boucles[$idb]; |
|
| 544 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | + $serveur = $boucle->sql_serveur; |
|
| 546 | 546 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | + $c = "sql_in('" . |
|
| 548 | + $boucle->id_table . '.' . $boucle->primary |
|
| 549 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 550 | 550 | |
| 551 | - $boucle->where[] = $c; |
|
| 551 | + $boucle->where[] = $c; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -570,31 +570,31 @@ discard block |
||
| 570 | 570 | * @return void |
| 571 | 571 | **/ |
| 572 | 572 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 573 | - if ($t = isset($crit->param[0])) { |
|
| 574 | - $t = $crit->param[0]; |
|
| 575 | - if ($t[0]->type == 'texte') { |
|
| 576 | - $t = $t[0]->texte; |
|
| 577 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | - $t = table_objet_sql($r[1]); |
|
| 579 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | - if ($t) { |
|
| 581 | - $t .= '.' . $r[2]; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - } else { |
|
| 585 | - $t = '".' |
|
| 586 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | - . '."'; |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - if ($t) { |
|
| 591 | - $boucles[$idb]->group[] = $t; |
|
| 592 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | - $boucles[$idb]->select[] = $t; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | - } |
|
| 573 | + if ($t = isset($crit->param[0])) { |
|
| 574 | + $t = $crit->param[0]; |
|
| 575 | + if ($t[0]->type == 'texte') { |
|
| 576 | + $t = $t[0]->texte; |
|
| 577 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | + $t = table_objet_sql($r[1]); |
|
| 579 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | + if ($t) { |
|
| 581 | + $t .= '.' . $r[2]; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + } else { |
|
| 585 | + $t = '".' |
|
| 586 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | + . '."'; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + if ($t) { |
|
| 591 | + $boucles[$idb]->group[] = $t; |
|
| 592 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | + $boucles[$idb]->select[] = $t; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | + } |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -631,45 +631,45 @@ discard block |
||
| 631 | 631 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 632 | 632 | */ |
| 633 | 633 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 634 | - if (isset($crit->param[0])) { |
|
| 635 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 636 | - $boucle = $boucles[$idb]; |
|
| 637 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | - $n = count($boucle->order); |
|
| 639 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | - if ( |
|
| 643 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | - OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | - ) { |
|
| 646 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | - } else { |
|
| 648 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } else { |
|
| 652 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | - } |
|
| 634 | + if (isset($crit->param[0])) { |
|
| 635 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 636 | + $boucle = $boucles[$idb]; |
|
| 637 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | + $n = count($boucle->order); |
|
| 639 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | + if ( |
|
| 643 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | + OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | + ) { |
|
| 646 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | + } else { |
|
| 648 | + $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } else { |
|
| 652 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | + } |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | 657 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | - $boucle = $boucles[$idb]; |
|
| 659 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | - $var = '$champs_' . $idb; |
|
| 661 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | - if (!$desc) { |
|
| 663 | - $desc = $boucle->show['field']; |
|
| 664 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | - } |
|
| 667 | - if ($desc) { |
|
| 668 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | - } |
|
| 670 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 671 | - |
|
| 672 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 658 | + $boucle = $boucles[$idb]; |
|
| 659 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | + $var = '$champs_' . $idb; |
|
| 661 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | + if (!$desc) { |
|
| 663 | + $desc = $boucle->show['field']; |
|
| 664 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | + } |
|
| 667 | + if ($desc) { |
|
| 668 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | + } |
|
| 670 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 671 | + |
|
| 672 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 709 | 709 | */ |
| 710 | 710 | function critere_par_dist($idb, &$boucles, $crit) { |
| 711 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 711 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | /** |
@@ -730,93 +730,93 @@ discard block |
||
| 730 | 730 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 731 | 731 | */ |
| 732 | 732 | function critere_parinverse($idb, &$boucles, $crit) { |
| 733 | - $boucle = &$boucles[$idb]; |
|
| 734 | - |
|
| 735 | - $sens = $collecte = ''; |
|
| 736 | - if ($crit->not) { |
|
| 737 | - $sens = " . ' DESC'"; |
|
| 738 | - } |
|
| 739 | - if (isset($boucle->modificateur['collate'])) { |
|
| 740 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // Pour chaque paramètre du critère |
|
| 744 | - foreach ($crit->param as $tri) { |
|
| 745 | - $order = $fct = ''; |
|
| 746 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | - if ($tri[0]->type != 'texte') { |
|
| 748 | - // calculer le order dynamique qui verifie les champs |
|
| 749 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | - } |
|
| 753 | - // tris textuels {par titre} |
|
| 754 | - else { |
|
| 755 | - $par = array_shift($tri); |
|
| 756 | - $par = $par->texte; |
|
| 757 | - |
|
| 758 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | - if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | - $expression = trim($m[1]); |
|
| 761 | - $champ = trim($m[2]); |
|
| 762 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | - } else { |
|
| 765 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | - // {par FONCTION(champ)} |
|
| 771 | - if (count($match) > 2) { |
|
| 772 | - $par = substr($match[2], 1, -1); |
|
| 773 | - $fct = $match[1]; |
|
| 774 | - } |
|
| 775 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | - if ($par == 'hasard') { |
|
| 777 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | - } else { |
|
| 781 | - // cas général {par champ}, {par table.champ}, ... |
|
| 782 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // on ne sait pas traiter… |
|
| 787 | - else { |
|
| 788 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | - if (is_array($order)) { |
|
| 793 | - return $order; |
|
| 794 | - } |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | - $t = $m[1]; |
|
| 799 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | - $boucle->select[] = $t; |
|
| 801 | - } |
|
| 802 | - } else { |
|
| 803 | - $sens = ''; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - if ($fct) { |
|
| 807 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | - } else { |
|
| 810 | - $order = "'$fct(' . $order . ')'"; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - $t = $order . $collecte . $sens; |
|
| 814 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | - $t = $r[1] . $r[2]; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - $boucle->order[] = $t; |
|
| 819 | - } |
|
| 733 | + $boucle = &$boucles[$idb]; |
|
| 734 | + |
|
| 735 | + $sens = $collecte = ''; |
|
| 736 | + if ($crit->not) { |
|
| 737 | + $sens = " . ' DESC'"; |
|
| 738 | + } |
|
| 739 | + if (isset($boucle->modificateur['collate'])) { |
|
| 740 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // Pour chaque paramètre du critère |
|
| 744 | + foreach ($crit->param as $tri) { |
|
| 745 | + $order = $fct = ''; |
|
| 746 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | + if ($tri[0]->type != 'texte') { |
|
| 748 | + // calculer le order dynamique qui verifie les champs |
|
| 749 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | + } |
|
| 753 | + // tris textuels {par titre} |
|
| 754 | + else { |
|
| 755 | + $par = array_shift($tri); |
|
| 756 | + $par = $par->texte; |
|
| 757 | + |
|
| 758 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | + if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | + $expression = trim($m[1]); |
|
| 761 | + $champ = trim($m[2]); |
|
| 762 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | + } else { |
|
| 765 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | + } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | + // {par FONCTION(champ)} |
|
| 771 | + if (count($match) > 2) { |
|
| 772 | + $par = substr($match[2], 1, -1); |
|
| 773 | + $fct = $match[1]; |
|
| 774 | + } |
|
| 775 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | + if ($par == 'hasard') { |
|
| 777 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | + $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | + } else { |
|
| 781 | + // cas général {par champ}, {par table.champ}, ... |
|
| 782 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // on ne sait pas traiter… |
|
| 787 | + else { |
|
| 788 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | + if (is_array($order)) { |
|
| 793 | + return $order; |
|
| 794 | + } |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | + $t = $m[1]; |
|
| 799 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | + $boucle->select[] = $t; |
|
| 801 | + } |
|
| 802 | + } else { |
|
| 803 | + $sens = ''; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + if ($fct) { |
|
| 807 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | + } else { |
|
| 810 | + $order = "'$fct(' . $order . ')'"; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + $t = $order . $collecte . $sens; |
|
| 814 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | + $t = $r[1] . $r[2]; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + $boucle->order[] = $t; |
|
| 819 | + } |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -830,13 +830,13 @@ discard block |
||
| 830 | 830 | * @return string Clause pour le Order by |
| 831 | 831 | */ |
| 832 | 832 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 833 | - $boucle = &$boucles[$idb]; |
|
| 834 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | - $parha = "rand() AS hasard"; |
|
| 836 | - if (!in_array($parha, $boucle->select)) { |
|
| 837 | - $boucle->select[] = $parha; |
|
| 838 | - } |
|
| 839 | - return "'hasard'"; |
|
| 833 | + $boucle = &$boucles[$idb]; |
|
| 834 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | + $parha = "rand() AS hasard"; |
|
| 836 | + if (!in_array($parha, $boucle->select)) { |
|
| 837 | + $boucle->select[] = $parha; |
|
| 838 | + } |
|
| 839 | + return "'hasard'"; |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -860,20 +860,20 @@ discard block |
||
| 860 | 860 | * @return string Clause pour le Order by |
| 861 | 861 | */ |
| 862 | 862 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 863 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | - if (is_array($_champ)) { |
|
| 865 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | - } |
|
| 867 | - $boucle = &$boucles[$idb]; |
|
| 868 | - $texte = '0+' . $_champ; |
|
| 869 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 870 | - if ($suite !== "''") { |
|
| 871 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | - } |
|
| 873 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | - $boucle->select[] = $texte . " AS $as"; |
|
| 875 | - $order = "'$as'"; |
|
| 876 | - return $order; |
|
| 863 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | + if (is_array($_champ)) { |
|
| 865 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | + } |
|
| 867 | + $boucle = &$boucles[$idb]; |
|
| 868 | + $texte = '0+' . $_champ; |
|
| 869 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 870 | + if ($suite !== "''") { |
|
| 871 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | + } |
|
| 873 | + $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | + $boucle->select[] = $texte . " AS $as"; |
|
| 875 | + $order = "'$as'"; |
|
| 876 | + return $order; |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | /** |
@@ -894,20 +894,20 @@ discard block |
||
| 894 | 894 | * @return string Clause pour le Order by |
| 895 | 895 | */ |
| 896 | 896 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 897 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | - if (is_array($_champ)) { |
|
| 899 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | - } |
|
| 901 | - $boucle = &$boucles[$idb]; |
|
| 902 | - $texte = '0+' . $_champ; |
|
| 903 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 904 | - if ($suite !== "''") { |
|
| 905 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | - } |
|
| 907 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | - $order = "'$as'"; |
|
| 910 | - return $order; |
|
| 897 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | + if (is_array($_champ)) { |
|
| 899 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | + } |
|
| 901 | + $boucle = &$boucles[$idb]; |
|
| 902 | + $texte = '0+' . $_champ; |
|
| 903 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 904 | + if ($suite !== "''") { |
|
| 905 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | + } |
|
| 907 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | + $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | + $order = "'$as'"; |
|
| 910 | + return $order; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | |
@@ -927,14 +927,14 @@ discard block |
||
| 927 | 927 | * @return string Clause pour le Order by |
| 928 | 928 | */ |
| 929 | 929 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 930 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | - if (is_array($_champ)) { |
|
| 932 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | - } |
|
| 934 | - $boucle = &$boucles[$idb]; |
|
| 935 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | - $order = "'multi'"; |
|
| 937 | - return $order; |
|
| 930 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | + if (is_array($_champ)) { |
|
| 932 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | + } |
|
| 934 | + $boucle = &$boucles[$idb]; |
|
| 935 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | + $order = "'multi'"; |
|
| 937 | + return $order; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /** |
@@ -953,56 +953,56 @@ discard block |
||
| 953 | 953 | * @return array|string |
| 954 | 954 | */ |
| 955 | 955 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 956 | - $boucle = &$boucles[$idb]; |
|
| 957 | - $desc = $boucle->show; |
|
| 958 | - |
|
| 959 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | - if (isset($desc['field'][$par])) { |
|
| 961 | - $par = $boucle->id_table . "." . $par; |
|
| 962 | - } |
|
| 963 | - // le champ est peut être une jointure |
|
| 964 | - else { |
|
| 965 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | - $champ = $par; |
|
| 967 | - |
|
| 968 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | - elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | - list(, $table, $champ) = $r; |
|
| 974 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | - $table = table_objet_sql($table); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | - $par = $infos['alias'] . "." . $champ; |
|
| 983 | - } elseif ( |
|
| 984 | - $boucle->jointures_explicites |
|
| 985 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | - ) { |
|
| 987 | - $par = $alias . "." . $champ; |
|
| 988 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | - $par = $alias . "." . $champ; |
|
| 990 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | - } elseif ( |
|
| 992 | - $table_alias |
|
| 993 | - and isset($boucle->from[$table_alias]) |
|
| 994 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | - ) { |
|
| 996 | - $par = $infos['alias'] . "." . $champ; |
|
| 997 | - } elseif ($table) { |
|
| 998 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | - } else { |
|
| 1001 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - return $raw ? $par : "'$par'"; |
|
| 956 | + $boucle = &$boucles[$idb]; |
|
| 957 | + $desc = $boucle->show; |
|
| 958 | + |
|
| 959 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | + if (isset($desc['field'][$par])) { |
|
| 961 | + $par = $boucle->id_table . "." . $par; |
|
| 962 | + } |
|
| 963 | + // le champ est peut être une jointure |
|
| 964 | + else { |
|
| 965 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | + $champ = $par; |
|
| 967 | + |
|
| 968 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | + elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | + list(, $table, $champ) = $r; |
|
| 974 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | + $table = table_objet_sql($table); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | + $par = $infos['alias'] . "." . $champ; |
|
| 983 | + } elseif ( |
|
| 984 | + $boucle->jointures_explicites |
|
| 985 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | + ) { |
|
| 987 | + $par = $alias . "." . $champ; |
|
| 988 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | + $par = $alias . "." . $champ; |
|
| 990 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | + } elseif ( |
|
| 992 | + $table_alias |
|
| 993 | + and isset($boucle->from[$table_alias]) |
|
| 994 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | + ) { |
|
| 996 | + $par = $infos['alias'] . "." . $champ; |
|
| 997 | + } elseif ($table) { |
|
| 998 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | + } else { |
|
| 1001 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + return $raw ? $par : "'$par'"; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1016,11 +1016,11 @@ discard block |
||
| 1016 | 1016 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1017 | 1017 | */ |
| 1018 | 1018 | function critere_par_joint($table, $champ, &$boucle) { |
| 1019 | - $t = array_search($table, $boucle->from); |
|
| 1020 | - if (!$t) { |
|
| 1021 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | - } |
|
| 1023 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1019 | + $t = array_search($table, $boucle->from); |
|
| 1020 | + if (!$t) { |
|
| 1021 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | + } |
|
| 1023 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
@@ -1045,143 +1045,143 @@ discard block |
||
| 1045 | 1045 | */ |
| 1046 | 1046 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1047 | 1047 | |
| 1048 | - $boucle = &$boucles[$idb]; |
|
| 1049 | - // Classement par ordre inverse |
|
| 1050 | - if ($crit->not) { |
|
| 1051 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | - } else { |
|
| 1053 | - $order = "' DESC'"; |
|
| 1054 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | - if (isset($crit->param[0])) { |
|
| 1056 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | - $order = "(($critere)?' DESC':'')"; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - $n = count($boucle->order); |
|
| 1061 | - if (!$n) { |
|
| 1062 | - if (isset($boucle->default_order[0])) { |
|
| 1063 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | - } else { |
|
| 1065 | - $boucle->default_order[] = ' DESC'; |
|
| 1066 | - } |
|
| 1067 | - } else { |
|
| 1068 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | - $t = $r[1] . $r[2]; |
|
| 1071 | - } |
|
| 1072 | - $boucle->order[$n - 1] = $t; |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1048 | + $boucle = &$boucles[$idb]; |
|
| 1049 | + // Classement par ordre inverse |
|
| 1050 | + if ($crit->not) { |
|
| 1051 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | + } else { |
|
| 1053 | + $order = "' DESC'"; |
|
| 1054 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | + if (isset($crit->param[0])) { |
|
| 1056 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | + $order = "(($critere)?' DESC':'')"; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + $n = count($boucle->order); |
|
| 1061 | + if (!$n) { |
|
| 1062 | + if (isset($boucle->default_order[0])) { |
|
| 1063 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | + } else { |
|
| 1065 | + $boucle->default_order[] = ' DESC'; |
|
| 1066 | + } |
|
| 1067 | + } else { |
|
| 1068 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | + $t = $r[1] . $r[2]; |
|
| 1071 | + } |
|
| 1072 | + $boucle->order[$n - 1] = $t; |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | // http://code.spip.net/@critere_agenda_dist |
| 1078 | 1078 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1079 | - $params = $crit->param; |
|
| 1080 | - |
|
| 1081 | - if (count($params) < 1) { |
|
| 1082 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - $boucle = &$boucles[$idb]; |
|
| 1086 | - $parent = $boucle->id_parent; |
|
| 1087 | - $fields = $boucle->show['field']; |
|
| 1088 | - |
|
| 1089 | - $date = array_shift($params); |
|
| 1090 | - $type = array_shift($params); |
|
| 1091 | - |
|
| 1092 | - // la valeur $type doit etre connue a la compilation |
|
| 1093 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1094 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1095 | - |
|
| 1096 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1097 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1098 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1099 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1100 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1101 | - $date = $date[0]->texte; |
|
| 1102 | - if (!isset($fields[$date])) { |
|
| 1103 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1104 | - } |
|
| 1105 | - } else { |
|
| 1106 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1107 | - $noms = array_keys($fields); |
|
| 1108 | - $defaut = $noms[0]; |
|
| 1109 | - $noms = join(" ", $noms); |
|
| 1110 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1111 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1112 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1113 | - } |
|
| 1114 | - $annee = $params ? array_shift($params) : ""; |
|
| 1115 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1117 | - ') ? $x : date("Y"))'; |
|
| 1118 | - |
|
| 1119 | - $mois = $params ? array_shift($params) : ""; |
|
| 1120 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1122 | - ') ? $x : date("m"))'; |
|
| 1123 | - |
|
| 1124 | - $jour = $params ? array_shift($params) : ""; |
|
| 1125 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1127 | - ') ? $x : date("d"))'; |
|
| 1128 | - |
|
| 1129 | - $annee2 = $params ? array_shift($params) : ""; |
|
| 1130 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1132 | - ') ? $x : date("Y"))'; |
|
| 1133 | - |
|
| 1134 | - $mois2 = $params ? array_shift($params) : ""; |
|
| 1135 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1137 | - ') ? $x : date("m"))'; |
|
| 1138 | - |
|
| 1139 | - $jour2 = $params ? array_shift($params) : ""; |
|
| 1140 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1142 | - ') ? $x : date("d"))'; |
|
| 1143 | - |
|
| 1144 | - $date = $boucle->id_table . ".$date"; |
|
| 1145 | - |
|
| 1146 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1147 | - if ($type == 'jour') { |
|
| 1148 | - $boucle->where[] = array( |
|
| 1149 | - "'='", |
|
| 1150 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1151 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1152 | - ); |
|
| 1153 | - } elseif ($type == 'mois') { |
|
| 1154 | - $boucle->where[] = array( |
|
| 1155 | - "'='", |
|
| 1156 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1157 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1158 | - ); |
|
| 1159 | - } elseif ($type == 'semaine') { |
|
| 1160 | - $boucle->where[] = array( |
|
| 1161 | - "'AND'", |
|
| 1162 | - array( |
|
| 1163 | - "'>='", |
|
| 1164 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1165 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1166 | - ), |
|
| 1167 | - array( |
|
| 1168 | - "'<='", |
|
| 1169 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1170 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1171 | - ) |
|
| 1172 | - ); |
|
| 1173 | - } elseif (count($crit->param) > 2) { |
|
| 1174 | - $boucle->where[] = array( |
|
| 1175 | - "'AND'", |
|
| 1176 | - array( |
|
| 1177 | - "'>='", |
|
| 1178 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1179 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1180 | - ), |
|
| 1181 | - array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1182 | - ); |
|
| 1183 | - } |
|
| 1184 | - // sinon on prend tout |
|
| 1079 | + $params = $crit->param; |
|
| 1080 | + |
|
| 1081 | + if (count($params) < 1) { |
|
| 1082 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + $boucle = &$boucles[$idb]; |
|
| 1086 | + $parent = $boucle->id_parent; |
|
| 1087 | + $fields = $boucle->show['field']; |
|
| 1088 | + |
|
| 1089 | + $date = array_shift($params); |
|
| 1090 | + $type = array_shift($params); |
|
| 1091 | + |
|
| 1092 | + // la valeur $type doit etre connue a la compilation |
|
| 1093 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1094 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1095 | + |
|
| 1096 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1097 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1098 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1099 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1100 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1101 | + $date = $date[0]->texte; |
|
| 1102 | + if (!isset($fields[$date])) { |
|
| 1103 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1104 | + } |
|
| 1105 | + } else { |
|
| 1106 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1107 | + $noms = array_keys($fields); |
|
| 1108 | + $defaut = $noms[0]; |
|
| 1109 | + $noms = join(" ", $noms); |
|
| 1110 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1111 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1112 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1113 | + } |
|
| 1114 | + $annee = $params ? array_shift($params) : ""; |
|
| 1115 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1117 | + ') ? $x : date("Y"))'; |
|
| 1118 | + |
|
| 1119 | + $mois = $params ? array_shift($params) : ""; |
|
| 1120 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1122 | + ') ? $x : date("m"))'; |
|
| 1123 | + |
|
| 1124 | + $jour = $params ? array_shift($params) : ""; |
|
| 1125 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1127 | + ') ? $x : date("d"))'; |
|
| 1128 | + |
|
| 1129 | + $annee2 = $params ? array_shift($params) : ""; |
|
| 1130 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1132 | + ') ? $x : date("Y"))'; |
|
| 1133 | + |
|
| 1134 | + $mois2 = $params ? array_shift($params) : ""; |
|
| 1135 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1137 | + ') ? $x : date("m"))'; |
|
| 1138 | + |
|
| 1139 | + $jour2 = $params ? array_shift($params) : ""; |
|
| 1140 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1142 | + ') ? $x : date("d"))'; |
|
| 1143 | + |
|
| 1144 | + $date = $boucle->id_table . ".$date"; |
|
| 1145 | + |
|
| 1146 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1147 | + if ($type == 'jour') { |
|
| 1148 | + $boucle->where[] = array( |
|
| 1149 | + "'='", |
|
| 1150 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1151 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1152 | + ); |
|
| 1153 | + } elseif ($type == 'mois') { |
|
| 1154 | + $boucle->where[] = array( |
|
| 1155 | + "'='", |
|
| 1156 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1157 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1158 | + ); |
|
| 1159 | + } elseif ($type == 'semaine') { |
|
| 1160 | + $boucle->where[] = array( |
|
| 1161 | + "'AND'", |
|
| 1162 | + array( |
|
| 1163 | + "'>='", |
|
| 1164 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1165 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1166 | + ), |
|
| 1167 | + array( |
|
| 1168 | + "'<='", |
|
| 1169 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1170 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1171 | + ) |
|
| 1172 | + ); |
|
| 1173 | + } elseif (count($crit->param) > 2) { |
|
| 1174 | + $boucle->where[] = array( |
|
| 1175 | + "'AND'", |
|
| 1176 | + array( |
|
| 1177 | + "'>='", |
|
| 1178 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1179 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1180 | + ), |
|
| 1181 | + array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1182 | + ); |
|
| 1183 | + } |
|
| 1184 | + // sinon on prend tout |
|
| 1185 | 1185 | } |
| 1186 | 1186 | |
| 1187 | 1187 | |
@@ -1206,33 +1206,33 @@ discard block |
||
| 1206 | 1206 | * @return void |
| 1207 | 1207 | **/ |
| 1208 | 1208 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1209 | - $boucle = &$boucles[$idb]; |
|
| 1210 | - $a1 = $crit->param[0]; |
|
| 1211 | - $a2 = $crit->param[1]; |
|
| 1212 | - $op = $crit->op; |
|
| 1213 | - |
|
| 1214 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1215 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1216 | - |
|
| 1217 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1218 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1219 | - } else { |
|
| 1220 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1221 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1222 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1223 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1224 | - $mode = (($op == '/') ? '/' : |
|
| 1225 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1226 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1227 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1228 | - $boucle->limit = |
|
| 1229 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1230 | - . ".','." |
|
| 1231 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1232 | - } else { |
|
| 1233 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1234 | - } |
|
| 1235 | - } |
|
| 1209 | + $boucle = &$boucles[$idb]; |
|
| 1210 | + $a1 = $crit->param[0]; |
|
| 1211 | + $a2 = $crit->param[1]; |
|
| 1212 | + $op = $crit->op; |
|
| 1213 | + |
|
| 1214 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1215 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1216 | + |
|
| 1217 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1218 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1219 | + } else { |
|
| 1220 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1221 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1222 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1223 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1224 | + $mode = (($op == '/') ? '/' : |
|
| 1225 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1226 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1227 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1228 | + $boucle->limit = |
|
| 1229 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1230 | + . ".','." |
|
| 1231 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1232 | + } else { |
|
| 1233 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1234 | + } |
|
| 1235 | + } |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | /** |
@@ -1260,63 +1260,63 @@ discard block |
||
| 1260 | 1260 | * @return void |
| 1261 | 1261 | **/ |
| 1262 | 1262 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1263 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1264 | - |
|
| 1265 | - preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1266 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1267 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1268 | - // {1/3} |
|
| 1269 | - if ($op1 == '/') { |
|
| 1270 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1271 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | - "($total_parties ? $total_parties : 1)"; |
|
| 1273 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1274 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1275 | - } else { |
|
| 1276 | - // cas {n-1,x} |
|
| 1277 | - if ($op1 == '-') { |
|
| 1278 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - // cas {x,n-1} |
|
| 1282 | - if ($op2 == '-') { |
|
| 1283 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | - ($total_parties . ' - 1')); |
|
| 1286 | - } else { |
|
| 1287 | - // {x,1} ou {pagination} |
|
| 1288 | - $fin = '$debut_boucle' |
|
| 1289 | - . (is_numeric($total_parties) ? |
|
| 1290 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | - ('+' . $total_parties . ' - 1')); |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1295 | - if ($op1 == 'p') { |
|
| 1296 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1297 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1298 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1299 | - } |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - // Notes : |
|
| 1303 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1304 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1305 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1306 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1307 | - |
|
| 1308 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1309 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1310 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1311 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1312 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1313 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1314 | - . "\n\tif (\$debut_boucle>0" |
|
| 1315 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1316 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1317 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1318 | - |
|
| 1319 | - $boucles[$id_boucle]->partie = " |
|
| 1263 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1264 | + |
|
| 1265 | + preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1266 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1267 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1268 | + // {1/3} |
|
| 1269 | + if ($op1 == '/') { |
|
| 1270 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1271 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | + "($total_parties ? $total_parties : 1)"; |
|
| 1273 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1274 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1275 | + } else { |
|
| 1276 | + // cas {n-1,x} |
|
| 1277 | + if ($op1 == '-') { |
|
| 1278 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + // cas {x,n-1} |
|
| 1282 | + if ($op2 == '-') { |
|
| 1283 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | + ($total_parties . ' - 1')); |
|
| 1286 | + } else { |
|
| 1287 | + // {x,1} ou {pagination} |
|
| 1288 | + $fin = '$debut_boucle' |
|
| 1289 | + . (is_numeric($total_parties) ? |
|
| 1290 | + (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | + ('+' . $total_parties . ' - 1')); |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1295 | + if ($op1 == 'p') { |
|
| 1296 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1297 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1298 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1299 | + } |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + // Notes : |
|
| 1303 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1304 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1305 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1306 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1307 | + |
|
| 1308 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1309 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1310 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1311 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1312 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1313 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1314 | + . "\n\tif (\$debut_boucle>0" |
|
| 1315 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1316 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1317 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1318 | + |
|
| 1319 | + $boucles[$id_boucle]->partie = " |
|
| 1320 | 1320 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1321 | 1321 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1322 | 1322 | } |
@@ -1333,26 +1333,26 @@ discard block |
||
| 1333 | 1333 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1334 | 1334 | **/ |
| 1335 | 1335 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1336 | - if ($param[0]->type != 'texte') { |
|
| 1337 | - $a1 = calculer_liste(array($param[0]), $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1338 | - if (isset($param[1]->texte)) { |
|
| 1339 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1340 | - |
|
| 1341 | - return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1342 | - } else { |
|
| 1343 | - return array("intval($a1)", 0); |
|
| 1344 | - } |
|
| 1345 | - } else { |
|
| 1346 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1347 | - $a1 = $m[1]; |
|
| 1348 | - if (empty($m[3])) { |
|
| 1349 | - return array($a1, 0); |
|
| 1350 | - } elseif (!empty($m[4])) { |
|
| 1351 | - return array($a1, $m[4]); |
|
| 1352 | - } else { |
|
| 1353 | - return array($a1, calculer_liste(array($param[1]), $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1336 | + if ($param[0]->type != 'texte') { |
|
| 1337 | + $a1 = calculer_liste(array($param[0]), $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1338 | + if (isset($param[1]->texte)) { |
|
| 1339 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1340 | + |
|
| 1341 | + return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1342 | + } else { |
|
| 1343 | + return array("intval($a1)", 0); |
|
| 1344 | + } |
|
| 1345 | + } else { |
|
| 1346 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1347 | + $a1 = $m[1]; |
|
| 1348 | + if (empty($m[3])) { |
|
| 1349 | + return array($a1, 0); |
|
| 1350 | + } elseif (!empty($m[4])) { |
|
| 1351 | + return array($a1, $m[4]); |
|
| 1352 | + } else { |
|
| 1353 | + return array($a1, calculer_liste(array($param[1]), $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | 1358 | |
@@ -1379,47 +1379,47 @@ discard block |
||
| 1379 | 1379 | * array : Erreur sur un des critères |
| 1380 | 1380 | **/ |
| 1381 | 1381 | function calculer_criteres($idb, &$boucles) { |
| 1382 | - $msg = ''; |
|
| 1383 | - $boucle = $boucles[$idb]; |
|
| 1384 | - $table = strtoupper($boucle->type_requete); |
|
| 1385 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1386 | - |
|
| 1387 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1388 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1389 | - if (!is_array($boucle->criteres)) { |
|
| 1390 | - return array(); |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - foreach ($boucle->criteres as $crit) { |
|
| 1394 | - $critere = $crit->op; |
|
| 1395 | - // critere personnalise ? |
|
| 1396 | - if ( |
|
| 1397 | - (!$serveur or |
|
| 1398 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1399 | - and (!function_exists($f = $f . "_dist")) |
|
| 1400 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1401 | - and (!function_exists($f = $f . "_dist")) |
|
| 1402 | - ) |
|
| 1403 | - ) |
|
| 1404 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1405 | - and (!function_exists($f = $f . "_dist")) |
|
| 1406 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1407 | - and (!function_exists($f = $f . "_dist")) |
|
| 1408 | - ) { |
|
| 1409 | - // fonction critere standard |
|
| 1410 | - $f = $defaut; |
|
| 1411 | - } |
|
| 1412 | - // compile le critere |
|
| 1413 | - $res = $f($idb, $boucles, $crit); |
|
| 1414 | - |
|
| 1415 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1416 | - if (is_array($res)) { |
|
| 1417 | - $msg = $res; |
|
| 1418 | - erreur_squelette($msg, $boucle); |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - return $msg; |
|
| 1382 | + $msg = ''; |
|
| 1383 | + $boucle = $boucles[$idb]; |
|
| 1384 | + $table = strtoupper($boucle->type_requete); |
|
| 1385 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1386 | + |
|
| 1387 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1388 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1389 | + if (!is_array($boucle->criteres)) { |
|
| 1390 | + return array(); |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + foreach ($boucle->criteres as $crit) { |
|
| 1394 | + $critere = $crit->op; |
|
| 1395 | + // critere personnalise ? |
|
| 1396 | + if ( |
|
| 1397 | + (!$serveur or |
|
| 1398 | + ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1399 | + and (!function_exists($f = $f . "_dist")) |
|
| 1400 | + and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1401 | + and (!function_exists($f = $f . "_dist")) |
|
| 1402 | + ) |
|
| 1403 | + ) |
|
| 1404 | + and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1405 | + and (!function_exists($f = $f . "_dist")) |
|
| 1406 | + and (!function_exists($f = "critere_" . $critere)) |
|
| 1407 | + and (!function_exists($f = $f . "_dist")) |
|
| 1408 | + ) { |
|
| 1409 | + // fonction critere standard |
|
| 1410 | + $f = $defaut; |
|
| 1411 | + } |
|
| 1412 | + // compile le critere |
|
| 1413 | + $res = $f($idb, $boucles, $crit); |
|
| 1414 | + |
|
| 1415 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1416 | + if (is_array($res)) { |
|
| 1417 | + $msg = $res; |
|
| 1418 | + erreur_squelette($msg, $boucle); |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + return $msg; |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1436,11 +1436,11 @@ discard block |
||
| 1436 | 1436 | * @return string Code compilé rééchappé |
| 1437 | 1437 | */ |
| 1438 | 1438 | function kwote($lisp, $serveur = '', $type = '') { |
| 1439 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1440 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1441 | - } else { |
|
| 1442 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1443 | - } |
|
| 1439 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1440 | + return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1441 | + } else { |
|
| 1442 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1443 | + } |
|
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | |
@@ -1459,85 +1459,85 @@ discard block |
||
| 1459 | 1459 | * @return void |
| 1460 | 1460 | **/ |
| 1461 | 1461 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1462 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1463 | - if (!$r) { |
|
| 1464 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1465 | - } |
|
| 1466 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1467 | - |
|
| 1468 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1469 | - |
|
| 1470 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1471 | - $where = $in; |
|
| 1472 | - if ($crit->cond) { |
|
| 1473 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1474 | - $where = array("'?'", $pred, $where, "''"); |
|
| 1475 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1476 | - { |
|
| 1477 | - $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1480 | - if ($crit->exclus) { |
|
| 1481 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1482 | - $where = array("'NOT'", $where); |
|
| 1483 | - } else |
|
| 1484 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1485 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1486 | - { |
|
| 1487 | - $where = array( |
|
| 1488 | - "'NOT'", |
|
| 1489 | - array( |
|
| 1490 | - "'IN'", |
|
| 1491 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1493 | - ) |
|
| 1494 | - ); |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - $boucles[$idb]->where[] = $where; |
|
| 1499 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1500 | - { |
|
| 1501 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1502 | - } |
|
| 1462 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1463 | + if (!$r) { |
|
| 1464 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1465 | + } |
|
| 1466 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1467 | + |
|
| 1468 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1469 | + |
|
| 1470 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1471 | + $where = $in; |
|
| 1472 | + if ($crit->cond) { |
|
| 1473 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1474 | + $where = array("'?'", $pred, $where, "''"); |
|
| 1475 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1476 | + { |
|
| 1477 | + $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + if ($crit->exclus) { |
|
| 1481 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1482 | + $where = array("'NOT'", $where); |
|
| 1483 | + } else |
|
| 1484 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1485 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1486 | + { |
|
| 1487 | + $where = array( |
|
| 1488 | + "'NOT'", |
|
| 1489 | + array( |
|
| 1490 | + "'IN'", |
|
| 1491 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1493 | + ) |
|
| 1494 | + ); |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + $boucles[$idb]->where[] = $where; |
|
| 1499 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1500 | + { |
|
| 1501 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1502 | + } |
|
| 1503 | 1503 | } |
| 1504 | 1504 | |
| 1505 | 1505 | // http://code.spip.net/@critere_IN_cas |
| 1506 | 1506 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1507 | - static $num = array(); |
|
| 1508 | - $descr = $boucles[$idb]->descr; |
|
| 1509 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1510 | - |
|
| 1511 | - $var = '$in' . $cpt++; |
|
| 1512 | - $x = "\n\t$var = array();"; |
|
| 1513 | - foreach ($val as $k => $v) { |
|
| 1514 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1515 | - // optimiser le traitement des constantes |
|
| 1516 | - if (is_numeric($r[2])) { |
|
| 1517 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1518 | - } else { |
|
| 1519 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1520 | - } |
|
| 1521 | - } else { |
|
| 1522 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1523 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1524 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1525 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1526 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | - } |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - $boucles[$idb]->in .= $x; |
|
| 1531 | - |
|
| 1532 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1533 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1534 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1535 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1536 | - if (!$crit2) { |
|
| 1537 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1507 | + static $num = array(); |
|
| 1508 | + $descr = $boucles[$idb]->descr; |
|
| 1509 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1510 | + |
|
| 1511 | + $var = '$in' . $cpt++; |
|
| 1512 | + $x = "\n\t$var = array();"; |
|
| 1513 | + foreach ($val as $k => $v) { |
|
| 1514 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1515 | + // optimiser le traitement des constantes |
|
| 1516 | + if (is_numeric($r[2])) { |
|
| 1517 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1518 | + } else { |
|
| 1519 | + $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1520 | + } |
|
| 1521 | + } else { |
|
| 1522 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1523 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1524 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1525 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1526 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | + } |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + $boucles[$idb]->in .= $x; |
|
| 1531 | + |
|
| 1532 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1533 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1534 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1535 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1536 | + if (!$crit2) { |
|
| 1537 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1541 | 1541 | } |
| 1542 | 1542 | |
| 1543 | 1543 | /** |
@@ -1553,22 +1553,22 @@ discard block |
||
| 1553 | 1553 | * @return void |
| 1554 | 1554 | */ |
| 1555 | 1555 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1556 | - $boucle = &$boucles[$idb]; |
|
| 1557 | - if (isset($crit->param[0])) { |
|
| 1558 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1559 | - } else { |
|
| 1560 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - if ($crit->cond) { |
|
| 1564 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - if ($crit->not) { |
|
| 1568 | - $_where = "array('NOT',$_where)"; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - $boucle->where[] = $_where; |
|
| 1556 | + $boucle = &$boucles[$idb]; |
|
| 1557 | + if (isset($crit->param[0])) { |
|
| 1558 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1559 | + } else { |
|
| 1560 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + if ($crit->cond) { |
|
| 1564 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + if ($crit->not) { |
|
| 1568 | + $_where = "array('NOT',$_where)"; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + $boucle->where[] = $_where; |
|
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | /** |
@@ -1596,31 +1596,31 @@ discard block |
||
| 1596 | 1596 | * @return void |
| 1597 | 1597 | */ |
| 1598 | 1598 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1599 | - /** @var Boucle $boucle */ |
|
| 1600 | - $boucle = $boucles[$idb]; |
|
| 1601 | - |
|
| 1602 | - $champs = lister_champs_id_conditionnel( |
|
| 1603 | - $boucle->show['table'], |
|
| 1604 | - $boucle->show, |
|
| 1605 | - $boucle->sql_serveur |
|
| 1606 | - ); |
|
| 1607 | - |
|
| 1608 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1609 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1610 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1611 | - } |
|
| 1612 | - // nous aider en mode debug. |
|
| 1613 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1614 | - $boucle->modificateur['id_'] = $champs; |
|
| 1615 | - |
|
| 1616 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1617 | - foreach ($champs as $champ) { |
|
| 1618 | - $critere_id_table = new Critere; |
|
| 1619 | - $critere_id_table->op = $champ; |
|
| 1620 | - $critere_id_table->cond = '?'; |
|
| 1621 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1622 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1623 | - } |
|
| 1599 | + /** @var Boucle $boucle */ |
|
| 1600 | + $boucle = $boucles[$idb]; |
|
| 1601 | + |
|
| 1602 | + $champs = lister_champs_id_conditionnel( |
|
| 1603 | + $boucle->show['table'], |
|
| 1604 | + $boucle->show, |
|
| 1605 | + $boucle->sql_serveur |
|
| 1606 | + ); |
|
| 1607 | + |
|
| 1608 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1609 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1610 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1611 | + } |
|
| 1612 | + // nous aider en mode debug. |
|
| 1613 | + $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1614 | + $boucle->modificateur['id_'] = $champs; |
|
| 1615 | + |
|
| 1616 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1617 | + foreach ($champs as $champ) { |
|
| 1618 | + $critere_id_table = new Critere; |
|
| 1619 | + $critere_id_table->op = $champ; |
|
| 1620 | + $critere_id_table->cond = '?'; |
|
| 1621 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1622 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1623 | + } |
|
| 1624 | 1624 | } |
| 1625 | 1625 | |
| 1626 | 1626 | /** |
@@ -1640,79 +1640,79 @@ discard block |
||
| 1640 | 1640 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1641 | 1641 | */ |
| 1642 | 1642 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1643 | - // calculer la description de la table |
|
| 1644 | - if (!is_array($desc)) { |
|
| 1645 | - $desc = description_table($table, $serveur); |
|
| 1646 | - } |
|
| 1647 | - if (!$desc) { |
|
| 1648 | - return []; |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - // Les champs id_xx de la table demandée |
|
| 1652 | - $champs = array_filter( |
|
| 1653 | - array_keys($desc['field']), |
|
| 1654 | - function($champ){ |
|
| 1655 | - return |
|
| 1656 | - strpos($champ, 'id_') === 0 |
|
| 1657 | - or (in_array($champ, array('objet'))); |
|
| 1658 | - } |
|
| 1659 | - ); |
|
| 1660 | - |
|
| 1661 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1662 | - if ( |
|
| 1663 | - in_array('id_rubrique', $champs) |
|
| 1664 | - and !in_array('id_secteur', $champs) |
|
| 1665 | - ) { |
|
| 1666 | - $champs[] = 'id_secteur'; |
|
| 1667 | - } |
|
| 1668 | - |
|
| 1669 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1670 | - if ($serveur) { |
|
| 1671 | - return $champs; |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - $primary = false; |
|
| 1675 | - $associable = false; |
|
| 1676 | - include_spip('action/editer_liens'); |
|
| 1677 | - |
|
| 1678 | - if (isset($desc['type'])) { |
|
| 1679 | - $primary = id_table_objet($desc['type']); |
|
| 1680 | - $associable = objet_associable($desc['type']); |
|
| 1681 | - } |
|
| 1682 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1683 | - $associable = true; |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - // liste de toutes les tables principales, sauf la notre |
|
| 1687 | - $tables = lister_tables_objets_sql(); |
|
| 1688 | - unset($tables[$table]); |
|
| 1689 | - |
|
| 1690 | - foreach ($tables as $_table => $_desc) { |
|
| 1691 | - if ( |
|
| 1692 | - $associable |
|
| 1693 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1694 | - or objet_associable($_desc['type']) |
|
| 1695 | - ) { |
|
| 1696 | - $champs[] = id_table_objet($_table); |
|
| 1697 | - } |
|
| 1698 | - } |
|
| 1699 | - $champs = array_values(array_unique($champs)); |
|
| 1700 | - |
|
| 1701 | - // Exclusions de certains id |
|
| 1702 | - $exclusions = pipeline( |
|
| 1703 | - 'exclure_id_conditionnel', |
|
| 1704 | - array( |
|
| 1705 | - 'args' => array( |
|
| 1706 | - 'table' => $table, |
|
| 1707 | - 'id_table_objet' => $primary, |
|
| 1708 | - 'associable' => $associable, |
|
| 1709 | - ), |
|
| 1710 | - 'data' => array(), |
|
| 1711 | - ) |
|
| 1712 | - ); |
|
| 1713 | - $champs = array_diff($champs, $exclusions); |
|
| 1714 | - |
|
| 1715 | - return $champs; |
|
| 1643 | + // calculer la description de la table |
|
| 1644 | + if (!is_array($desc)) { |
|
| 1645 | + $desc = description_table($table, $serveur); |
|
| 1646 | + } |
|
| 1647 | + if (!$desc) { |
|
| 1648 | + return []; |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + // Les champs id_xx de la table demandée |
|
| 1652 | + $champs = array_filter( |
|
| 1653 | + array_keys($desc['field']), |
|
| 1654 | + function($champ){ |
|
| 1655 | + return |
|
| 1656 | + strpos($champ, 'id_') === 0 |
|
| 1657 | + or (in_array($champ, array('objet'))); |
|
| 1658 | + } |
|
| 1659 | + ); |
|
| 1660 | + |
|
| 1661 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1662 | + if ( |
|
| 1663 | + in_array('id_rubrique', $champs) |
|
| 1664 | + and !in_array('id_secteur', $champs) |
|
| 1665 | + ) { |
|
| 1666 | + $champs[] = 'id_secteur'; |
|
| 1667 | + } |
|
| 1668 | + |
|
| 1669 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1670 | + if ($serveur) { |
|
| 1671 | + return $champs; |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + $primary = false; |
|
| 1675 | + $associable = false; |
|
| 1676 | + include_spip('action/editer_liens'); |
|
| 1677 | + |
|
| 1678 | + if (isset($desc['type'])) { |
|
| 1679 | + $primary = id_table_objet($desc['type']); |
|
| 1680 | + $associable = objet_associable($desc['type']); |
|
| 1681 | + } |
|
| 1682 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1683 | + $associable = true; |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + // liste de toutes les tables principales, sauf la notre |
|
| 1687 | + $tables = lister_tables_objets_sql(); |
|
| 1688 | + unset($tables[$table]); |
|
| 1689 | + |
|
| 1690 | + foreach ($tables as $_table => $_desc) { |
|
| 1691 | + if ( |
|
| 1692 | + $associable |
|
| 1693 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1694 | + or objet_associable($_desc['type']) |
|
| 1695 | + ) { |
|
| 1696 | + $champs[] = id_table_objet($_table); |
|
| 1697 | + } |
|
| 1698 | + } |
|
| 1699 | + $champs = array_values(array_unique($champs)); |
|
| 1700 | + |
|
| 1701 | + // Exclusions de certains id |
|
| 1702 | + $exclusions = pipeline( |
|
| 1703 | + 'exclure_id_conditionnel', |
|
| 1704 | + array( |
|
| 1705 | + 'args' => array( |
|
| 1706 | + 'table' => $table, |
|
| 1707 | + 'id_table_objet' => $primary, |
|
| 1708 | + 'associable' => $associable, |
|
| 1709 | + ), |
|
| 1710 | + 'data' => array(), |
|
| 1711 | + ) |
|
| 1712 | + ); |
|
| 1713 | + $champs = array_diff($champs, $exclusions); |
|
| 1714 | + |
|
| 1715 | + return $champs; |
|
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | 1718 | /** |
@@ -1767,27 +1767,27 @@ discard block |
||
| 1767 | 1767 | * @return void |
| 1768 | 1768 | */ |
| 1769 | 1769 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1770 | - $boucle = &$boucles[$idb]; |
|
| 1771 | - |
|
| 1772 | - // definition du champ par defaut |
|
| 1773 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1774 | - : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1775 | - $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1776 | - : calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1777 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1778 | - : calculer_liste(array($crit->param[2][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1779 | - |
|
| 1780 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1781 | - |
|
| 1782 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1783 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1784 | - |
|
| 1785 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1786 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1787 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1788 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1789 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1790 | - $boucle->hash .= " |
|
| 1770 | + $boucle = &$boucles[$idb]; |
|
| 1771 | + |
|
| 1772 | + // definition du champ par defaut |
|
| 1773 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1774 | + : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1775 | + $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1776 | + : calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1777 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1778 | + : calculer_liste(array($crit->param[2][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1779 | + |
|
| 1780 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1781 | + |
|
| 1782 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1783 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1784 | + |
|
| 1785 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1786 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1787 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1788 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1789 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1790 | + $boucle->hash .= " |
|
| 1791 | 1791 | \$senstri = ''; |
| 1792 | 1792 | \$tri = $_tri; |
| 1793 | 1793 | if (\$tri){ |
@@ -1795,8 +1795,8 @@ discard block |
||
| 1795 | 1795 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1796 | 1796 | }; |
| 1797 | 1797 | "; |
| 1798 | - $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1799 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1798 | + $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1799 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1800 | 1800 | } |
| 1801 | 1801 | |
| 1802 | 1802 | # Criteres de comparaison |
@@ -1813,20 +1813,20 @@ discard block |
||
| 1813 | 1813 | * @return void |
| 1814 | 1814 | **/ |
| 1815 | 1815 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1816 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1817 | - if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1818 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1819 | - } |
|
| 1820 | - |
|
| 1821 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1822 | - if (!$r) { |
|
| 1823 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1824 | - # if (!$crit->cond) { |
|
| 1825 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1826 | - # } |
|
| 1827 | - } else { |
|
| 1828 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1829 | - } |
|
| 1816 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1817 | + if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1818 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1819 | + } |
|
| 1820 | + |
|
| 1821 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1822 | + if (!$r) { |
|
| 1823 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1824 | + # if (!$crit->cond) { |
|
| 1825 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1826 | + # } |
|
| 1827 | + } else { |
|
| 1828 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1829 | + } |
|
| 1830 | 1830 | } |
| 1831 | 1831 | |
| 1832 | 1832 | |
@@ -1846,63 +1846,63 @@ discard block |
||
| 1846 | 1846 | * @return void |
| 1847 | 1847 | **/ |
| 1848 | 1848 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1849 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1850 | - |
|
| 1851 | - $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1852 | - |
|
| 1853 | - // inserer la negation (cf !...) |
|
| 1854 | - |
|
| 1855 | - if ($crit->not) { |
|
| 1856 | - $where = array("'NOT'", $where); |
|
| 1857 | - } |
|
| 1858 | - if ($crit->exclus) { |
|
| 1859 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1860 | - $where = array("'NOT'", $where); |
|
| 1861 | - } else |
|
| 1862 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1863 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1864 | - { |
|
| 1865 | - $where = array( |
|
| 1866 | - "'NOT'", |
|
| 1867 | - array( |
|
| 1868 | - "'IN'", |
|
| 1869 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1870 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1871 | - ) |
|
| 1872 | - ); |
|
| 1873 | - } |
|
| 1874 | - } |
|
| 1875 | - |
|
| 1876 | - // inserer la condition (cf {lang?}) |
|
| 1877 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1878 | - if ($crit->cond) { |
|
| 1879 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1880 | - if ($col == "date" or $col == "date_redac") { |
|
| 1881 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1882 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1883 | - } |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - if ($op == '=' and !$crit->not) { |
|
| 1887 | - $where = array( |
|
| 1888 | - "'?'", |
|
| 1889 | - "(is_array($pred))", |
|
| 1890 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1891 | - $where |
|
| 1892 | - ); |
|
| 1893 | - } |
|
| 1894 | - $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1895 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1896 | - { |
|
| 1897 | - $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1898 | - } |
|
| 1899 | - } |
|
| 1900 | - |
|
| 1901 | - $boucles[$idb]->where[] = $where; |
|
| 1902 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1903 | - { |
|
| 1904 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1905 | - } |
|
| 1849 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1850 | + |
|
| 1851 | + $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1852 | + |
|
| 1853 | + // inserer la negation (cf !...) |
|
| 1854 | + |
|
| 1855 | + if ($crit->not) { |
|
| 1856 | + $where = array("'NOT'", $where); |
|
| 1857 | + } |
|
| 1858 | + if ($crit->exclus) { |
|
| 1859 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1860 | + $where = array("'NOT'", $where); |
|
| 1861 | + } else |
|
| 1862 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1863 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1864 | + { |
|
| 1865 | + $where = array( |
|
| 1866 | + "'NOT'", |
|
| 1867 | + array( |
|
| 1868 | + "'IN'", |
|
| 1869 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1870 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1871 | + ) |
|
| 1872 | + ); |
|
| 1873 | + } |
|
| 1874 | + } |
|
| 1875 | + |
|
| 1876 | + // inserer la condition (cf {lang?}) |
|
| 1877 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1878 | + if ($crit->cond) { |
|
| 1879 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1880 | + if ($col == "date" or $col == "date_redac") { |
|
| 1881 | + if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1882 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1883 | + } |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + if ($op == '=' and !$crit->not) { |
|
| 1887 | + $where = array( |
|
| 1888 | + "'?'", |
|
| 1889 | + "(is_array($pred))", |
|
| 1890 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1891 | + $where |
|
| 1892 | + ); |
|
| 1893 | + } |
|
| 1894 | + $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1895 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1896 | + { |
|
| 1897 | + $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1898 | + } |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + $boucles[$idb]->where[] = $where; |
|
| 1902 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1903 | + { |
|
| 1904 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1905 | + } |
|
| 1906 | 1906 | } |
| 1907 | 1907 | |
| 1908 | 1908 | |
@@ -1943,167 +1943,167 @@ discard block |
||
| 1943 | 1943 | **/ |
| 1944 | 1944 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1945 | 1945 | |
| 1946 | - $boucle = &$boucles[$idb]; |
|
| 1947 | - $type = $boucle->type_requete; |
|
| 1948 | - $table = $boucle->id_table; |
|
| 1949 | - $desc = $boucle->show; |
|
| 1950 | - $col_vraie = null; |
|
| 1951 | - |
|
| 1952 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 1953 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1954 | - |
|
| 1955 | - $col_alias = $col; |
|
| 1956 | - $where_complement = false; |
|
| 1957 | - |
|
| 1958 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1959 | - if ($col == 'id_enfant') { |
|
| 1960 | - $col = $boucle->primary; |
|
| 1961 | - } |
|
| 1962 | - |
|
| 1963 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1964 | - if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1965 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1966 | - ) { |
|
| 1967 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1968 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1969 | - else { |
|
| 1970 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1971 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1972 | - } |
|
| 1973 | - |
|
| 1974 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1975 | - // sauf si exception declaree : sauter cette etape |
|
| 1976 | - else { |
|
| 1977 | - if ( |
|
| 1978 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1979 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1980 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1981 | - ) { |
|
| 1982 | - $e = decompose_champ_id_objet($col); |
|
| 1983 | - $col = array_shift($e); |
|
| 1984 | - $where_complement = primary_doublee($e, $table); |
|
| 1985 | - } // Cas particulier : expressions de date |
|
| 1986 | - else { |
|
| 1987 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1988 | - list($col, $col_vraie) = $c; |
|
| 1989 | - $table = ''; |
|
| 1990 | - } // table explicitée {mots.titre} |
|
| 1991 | - else { |
|
| 1992 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1993 | - list(, $table, $col) = $r; |
|
| 1994 | - $col_alias = $col; |
|
| 1995 | - |
|
| 1996 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1997 | - if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1998 | - and isset($desc['field'][$col]) |
|
| 1999 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2000 | - ) { |
|
| 2001 | - $table = $cle; |
|
| 2002 | - } else { |
|
| 2003 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 2004 | - } |
|
| 2005 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2006 | - if (!$table) { |
|
| 2007 | - return ''; |
|
| 2008 | - } |
|
| 2009 | - } |
|
| 2010 | - // si le champ n'est pas trouvé dans la table, |
|
| 2011 | - // on cherche si une jointure peut l'obtenir |
|
| 2012 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2013 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2014 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2015 | - $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2016 | - } |
|
| 2017 | - else { |
|
| 2018 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2019 | - if (!$r) { |
|
| 2020 | - return ''; |
|
| 2021 | - } |
|
| 2022 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2023 | - } |
|
| 2024 | - } |
|
| 2025 | - } |
|
| 2026 | - } |
|
| 2027 | - } |
|
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2031 | - // Dans tous les cas, |
|
| 2032 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2033 | - // et passer dans sql_quote avec le type si connu |
|
| 2034 | - // et int sinon si la valeur est numerique |
|
| 2035 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2036 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2037 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2038 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2039 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2040 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2041 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2042 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2043 | - } |
|
| 2044 | - // sinon expliciter les |
|
| 2045 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2046 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2047 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2048 | - // sans toucher aux |
|
| 2049 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2050 | - // sql_quote(truc,'','varchar') |
|
| 2051 | - elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2052 | - // si pas deja un type |
|
| 2053 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2054 | - ) { |
|
| 2055 | - $r = $r[1] |
|
| 2056 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2057 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2058 | - $val[0] = "sql_quote($r)"; |
|
| 2059 | - } |
|
| 2060 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2061 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2062 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2063 | - } |
|
| 2064 | - } |
|
| 2065 | - |
|
| 2066 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2067 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2068 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2069 | - } |
|
| 2070 | - |
|
| 2071 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2072 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2073 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2074 | - if ($table === $boucle->id_table) { |
|
| 2075 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2076 | - if ($col_alias != $col_vraie) { |
|
| 2077 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2078 | - } |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2082 | - // il faut alors interdire a la fonction de boucle |
|
| 2083 | - // de mettre ses propres criteres de statut |
|
| 2084 | - // http://www.spip.net/@statut (a documenter) |
|
| 2085 | - // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2086 | - if ($col == 'statut') { |
|
| 2087 | - $boucles[$idb]->statut = true; |
|
| 2088 | - } |
|
| 2089 | - |
|
| 2090 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2091 | - if ($table) { |
|
| 2092 | - if ($col[0] == "`") { |
|
| 2093 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2094 | - } else { |
|
| 2095 | - $arg = "$table.$col"; |
|
| 2096 | - } |
|
| 2097 | - } else { |
|
| 2098 | - $arg = $col; |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - // inserer la fonction SQL |
|
| 2102 | - if ($fct) { |
|
| 2103 | - $arg = "$fct($arg$args_sql)"; |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1946 | + $boucle = &$boucles[$idb]; |
|
| 1947 | + $type = $boucle->type_requete; |
|
| 1948 | + $table = $boucle->id_table; |
|
| 1949 | + $desc = $boucle->show; |
|
| 1950 | + $col_vraie = null; |
|
| 1951 | + |
|
| 1952 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 1953 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1954 | + |
|
| 1955 | + $col_alias = $col; |
|
| 1956 | + $where_complement = false; |
|
| 1957 | + |
|
| 1958 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1959 | + if ($col == 'id_enfant') { |
|
| 1960 | + $col = $boucle->primary; |
|
| 1961 | + } |
|
| 1962 | + |
|
| 1963 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1964 | + if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1965 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1966 | + ) { |
|
| 1967 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1968 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1969 | + else { |
|
| 1970 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1971 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1972 | + } |
|
| 1973 | + |
|
| 1974 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1975 | + // sauf si exception declaree : sauter cette etape |
|
| 1976 | + else { |
|
| 1977 | + if ( |
|
| 1978 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1979 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1980 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1981 | + ) { |
|
| 1982 | + $e = decompose_champ_id_objet($col); |
|
| 1983 | + $col = array_shift($e); |
|
| 1984 | + $where_complement = primary_doublee($e, $table); |
|
| 1985 | + } // Cas particulier : expressions de date |
|
| 1986 | + else { |
|
| 1987 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1988 | + list($col, $col_vraie) = $c; |
|
| 1989 | + $table = ''; |
|
| 1990 | + } // table explicitée {mots.titre} |
|
| 1991 | + else { |
|
| 1992 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1993 | + list(, $table, $col) = $r; |
|
| 1994 | + $col_alias = $col; |
|
| 1995 | + |
|
| 1996 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1997 | + if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1998 | + and isset($desc['field'][$col]) |
|
| 1999 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2000 | + ) { |
|
| 2001 | + $table = $cle; |
|
| 2002 | + } else { |
|
| 2003 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 2004 | + } |
|
| 2005 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2006 | + if (!$table) { |
|
| 2007 | + return ''; |
|
| 2008 | + } |
|
| 2009 | + } |
|
| 2010 | + // si le champ n'est pas trouvé dans la table, |
|
| 2011 | + // on cherche si une jointure peut l'obtenir |
|
| 2012 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2013 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2014 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2015 | + $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2016 | + } |
|
| 2017 | + else { |
|
| 2018 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2019 | + if (!$r) { |
|
| 2020 | + return ''; |
|
| 2021 | + } |
|
| 2022 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2023 | + } |
|
| 2024 | + } |
|
| 2025 | + } |
|
| 2026 | + } |
|
| 2027 | + } |
|
| 2028 | + } |
|
| 2029 | + |
|
| 2030 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2031 | + // Dans tous les cas, |
|
| 2032 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2033 | + // et passer dans sql_quote avec le type si connu |
|
| 2034 | + // et int sinon si la valeur est numerique |
|
| 2035 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2036 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2037 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2038 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2039 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2040 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2041 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2042 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2043 | + } |
|
| 2044 | + // sinon expliciter les |
|
| 2045 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2046 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2047 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2048 | + // sans toucher aux |
|
| 2049 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2050 | + // sql_quote(truc,'','varchar') |
|
| 2051 | + elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2052 | + // si pas deja un type |
|
| 2053 | + and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2054 | + ) { |
|
| 2055 | + $r = $r[1] |
|
| 2056 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2057 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2058 | + $val[0] = "sql_quote($r)"; |
|
| 2059 | + } |
|
| 2060 | + elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2061 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2062 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2063 | + } |
|
| 2064 | + } |
|
| 2065 | + |
|
| 2066 | + if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2067 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2068 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2069 | + } |
|
| 2070 | + |
|
| 2071 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2072 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2073 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2074 | + if ($table === $boucle->id_table) { |
|
| 2075 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2076 | + if ($col_alias != $col_vraie) { |
|
| 2077 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2078 | + } |
|
| 2079 | + } |
|
| 2080 | + |
|
| 2081 | + // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2082 | + // il faut alors interdire a la fonction de boucle |
|
| 2083 | + // de mettre ses propres criteres de statut |
|
| 2084 | + // http://www.spip.net/@statut (a documenter) |
|
| 2085 | + // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2086 | + if ($col == 'statut') { |
|
| 2087 | + $boucles[$idb]->statut = true; |
|
| 2088 | + } |
|
| 2089 | + |
|
| 2090 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2091 | + if ($table) { |
|
| 2092 | + if ($col[0] == "`") { |
|
| 2093 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2094 | + } else { |
|
| 2095 | + $arg = "$table.$col"; |
|
| 2096 | + } |
|
| 2097 | + } else { |
|
| 2098 | + $arg = $col; |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + // inserer la fonction SQL |
|
| 2102 | + if ($fct) { |
|
| 2103 | + $arg = "$fct($arg$args_sql)"; |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 2107 | 2107 | } |
| 2108 | 2108 | |
| 2109 | 2109 | |
@@ -2132,77 +2132,77 @@ discard block |
||
| 2132 | 2132 | **/ |
| 2133 | 2133 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2134 | 2134 | |
| 2135 | - $where = ''; |
|
| 2136 | - |
|
| 2137 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2138 | - // gestion par les plugins des jointures tordues |
|
| 2139 | - // pas automatiques mais necessaires |
|
| 2140 | - $table_sql = table_objet_sql($table); |
|
| 2141 | - if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2142 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2143 | - and |
|
| 2144 | - ( |
|
| 2145 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2146 | - or |
|
| 2147 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2148 | - ) |
|
| 2149 | - ) { |
|
| 2150 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2151 | - $index = isset($t[$col]) |
|
| 2152 | - ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2153 | - |
|
| 2154 | - if (count($index) == 3) { |
|
| 2155 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2156 | - } elseif (count($index) == 2) { |
|
| 2157 | - list($t, $col) = $t[$col]; |
|
| 2158 | - } elseif (count($index) == 1) { |
|
| 2159 | - list($calculer_critere_externe) = $index; |
|
| 2160 | - $t = $table; |
|
| 2161 | - } else { |
|
| 2162 | - $t = ''; |
|
| 2163 | - } // jointure non declaree. La trouver. |
|
| 2164 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2165 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2166 | - } else { |
|
| 2167 | - $t = ''; |
|
| 2168 | - } // jointure non declaree. La trouver. |
|
| 2169 | - |
|
| 2170 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2171 | - |
|
| 2172 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2173 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2174 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2175 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2176 | - $table = ""; |
|
| 2177 | - if ($boucle->jointures_explicites) { |
|
| 2178 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2179 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2180 | - } |
|
| 2181 | - |
|
| 2182 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2183 | - if (!$table) { |
|
| 2184 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2185 | - } |
|
| 2186 | - |
|
| 2187 | - if (!$table) { |
|
| 2188 | - return ''; |
|
| 2189 | - } |
|
| 2190 | - |
|
| 2191 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2192 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2193 | - |
|
| 2194 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2195 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2196 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2197 | - $e = decompose_champ_id_objet($col); |
|
| 2198 | - $col = array_shift($e); |
|
| 2199 | - $where = primary_doublee($e, $table); |
|
| 2200 | - } else { |
|
| 2201 | - $col = reset($cle); |
|
| 2202 | - } |
|
| 2203 | - } |
|
| 2204 | - |
|
| 2205 | - return array($col, $col_alias, $table, $where, $desc); |
|
| 2135 | + $where = ''; |
|
| 2136 | + |
|
| 2137 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2138 | + // gestion par les plugins des jointures tordues |
|
| 2139 | + // pas automatiques mais necessaires |
|
| 2140 | + $table_sql = table_objet_sql($table); |
|
| 2141 | + if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2142 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2143 | + and |
|
| 2144 | + ( |
|
| 2145 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2146 | + or |
|
| 2147 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2148 | + ) |
|
| 2149 | + ) { |
|
| 2150 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2151 | + $index = isset($t[$col]) |
|
| 2152 | + ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2153 | + |
|
| 2154 | + if (count($index) == 3) { |
|
| 2155 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2156 | + } elseif (count($index) == 2) { |
|
| 2157 | + list($t, $col) = $t[$col]; |
|
| 2158 | + } elseif (count($index) == 1) { |
|
| 2159 | + list($calculer_critere_externe) = $index; |
|
| 2160 | + $t = $table; |
|
| 2161 | + } else { |
|
| 2162 | + $t = ''; |
|
| 2163 | + } // jointure non declaree. La trouver. |
|
| 2164 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2165 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2166 | + } else { |
|
| 2167 | + $t = ''; |
|
| 2168 | + } // jointure non declaree. La trouver. |
|
| 2169 | + |
|
| 2170 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2171 | + |
|
| 2172 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2173 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2174 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2175 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2176 | + $table = ""; |
|
| 2177 | + if ($boucle->jointures_explicites) { |
|
| 2178 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2179 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2180 | + } |
|
| 2181 | + |
|
| 2182 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2183 | + if (!$table) { |
|
| 2184 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2185 | + } |
|
| 2186 | + |
|
| 2187 | + if (!$table) { |
|
| 2188 | + return ''; |
|
| 2189 | + } |
|
| 2190 | + |
|
| 2191 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2192 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2193 | + |
|
| 2194 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2195 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2196 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2197 | + $e = decompose_champ_id_objet($col); |
|
| 2198 | + $col = array_shift($e); |
|
| 2199 | + $where = primary_doublee($e, $table); |
|
| 2200 | + } else { |
|
| 2201 | + $col = reset($cle); |
|
| 2202 | + } |
|
| 2203 | + } |
|
| 2204 | + |
|
| 2205 | + return array($col, $col_alias, $table, $where, $desc); |
|
| 2206 | 2206 | } |
| 2207 | 2207 | |
| 2208 | 2208 | |
@@ -2223,10 +2223,10 @@ discard block |
||
| 2223 | 2223 | * - valeur |
| 2224 | 2224 | **/ |
| 2225 | 2225 | function primary_doublee($decompose, $table) { |
| 2226 | - $e1 = reset($decompose); |
|
| 2227 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2226 | + $e1 = reset($decompose); |
|
| 2227 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2228 | 2228 | |
| 2229 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2229 | + return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | 2232 | /** |
@@ -2257,56 +2257,56 @@ discard block |
||
| 2257 | 2257 | * Vide sinon. |
| 2258 | 2258 | */ |
| 2259 | 2259 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2260 | - // si on demande un truc du genre spip_mots |
|
| 2261 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2262 | - // et qu'on est la |
|
| 2263 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2264 | - if ($checkarrivee |
|
| 2265 | - and is_string($checkarrivee) |
|
| 2266 | - and $a = table_objet($checkarrivee) |
|
| 2267 | - and in_array($a . '_liens', $joints) |
|
| 2268 | - ) { |
|
| 2269 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2270 | - return $res; |
|
| 2271 | - } |
|
| 2272 | - } |
|
| 2273 | - foreach ($joints as $joint) { |
|
| 2274 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2275 | - // alias de table dans le from |
|
| 2276 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2277 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2278 | - $cols = $arrivee[2]; |
|
| 2279 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2280 | - if (count($cols) > 2) { |
|
| 2281 | - array_pop($cols); |
|
| 2282 | - } |
|
| 2283 | - if ($t) { |
|
| 2284 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2285 | - $joindre = false; |
|
| 2286 | - foreach ($cols as $col) { |
|
| 2287 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2288 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2289 | - $joindre = true; |
|
| 2290 | - } else { |
|
| 2291 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2292 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2293 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2294 | - $joindre = true; |
|
| 2295 | - } |
|
| 2296 | - } |
|
| 2297 | - } |
|
| 2298 | - if (!$joindre) { |
|
| 2299 | - return $t; |
|
| 2300 | - } |
|
| 2301 | - } |
|
| 2302 | - array_pop($arrivee); |
|
| 2303 | - if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2304 | - return $res; |
|
| 2305 | - } |
|
| 2306 | - } |
|
| 2307 | - } |
|
| 2308 | - |
|
| 2309 | - return ''; |
|
| 2260 | + // si on demande un truc du genre spip_mots |
|
| 2261 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2262 | + // et qu'on est la |
|
| 2263 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2264 | + if ($checkarrivee |
|
| 2265 | + and is_string($checkarrivee) |
|
| 2266 | + and $a = table_objet($checkarrivee) |
|
| 2267 | + and in_array($a . '_liens', $joints) |
|
| 2268 | + ) { |
|
| 2269 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2270 | + return $res; |
|
| 2271 | + } |
|
| 2272 | + } |
|
| 2273 | + foreach ($joints as $joint) { |
|
| 2274 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2275 | + // alias de table dans le from |
|
| 2276 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2277 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2278 | + $cols = $arrivee[2]; |
|
| 2279 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2280 | + if (count($cols) > 2) { |
|
| 2281 | + array_pop($cols); |
|
| 2282 | + } |
|
| 2283 | + if ($t) { |
|
| 2284 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2285 | + $joindre = false; |
|
| 2286 | + foreach ($cols as $col) { |
|
| 2287 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2288 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2289 | + $joindre = true; |
|
| 2290 | + } else { |
|
| 2291 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2292 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2293 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2294 | + $joindre = true; |
|
| 2295 | + } |
|
| 2296 | + } |
|
| 2297 | + } |
|
| 2298 | + if (!$joindre) { |
|
| 2299 | + return $t; |
|
| 2300 | + } |
|
| 2301 | + } |
|
| 2302 | + array_pop($arrivee); |
|
| 2303 | + if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2304 | + return $res; |
|
| 2305 | + } |
|
| 2306 | + } |
|
| 2307 | + } |
|
| 2308 | + |
|
| 2309 | + return ''; |
|
| 2310 | 2310 | |
| 2311 | 2311 | } |
| 2312 | 2312 | |
@@ -2333,29 +2333,29 @@ discard block |
||
| 2333 | 2333 | * Alias de la table de jointure (Lx) |
| 2334 | 2334 | */ |
| 2335 | 2335 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2336 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2337 | - |
|
| 2338 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2339 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2340 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2341 | - |
|
| 2342 | - if (!$intermediaire or !$arrivee) { |
|
| 2343 | - return ''; |
|
| 2344 | - } |
|
| 2345 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2346 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2347 | - |
|
| 2348 | - $res = fabrique_jointures($boucle, |
|
| 2349 | - array( |
|
| 2350 | - array( |
|
| 2351 | - $boucle->id_table, |
|
| 2352 | - $intermediaire, |
|
| 2353 | - array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2354 | - ), |
|
| 2355 | - array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2356 | - ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2357 | - |
|
| 2358 | - return $res; |
|
| 2336 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2337 | + |
|
| 2338 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2339 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2340 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2341 | + |
|
| 2342 | + if (!$intermediaire or !$arrivee) { |
|
| 2343 | + return ''; |
|
| 2344 | + } |
|
| 2345 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2346 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2347 | + |
|
| 2348 | + $res = fabrique_jointures($boucle, |
|
| 2349 | + array( |
|
| 2350 | + array( |
|
| 2351 | + $boucle->id_table, |
|
| 2352 | + $intermediaire, |
|
| 2353 | + array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2354 | + ), |
|
| 2355 | + array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2356 | + ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2357 | + |
|
| 2358 | + return $res; |
|
| 2359 | 2359 | } |
| 2360 | 2360 | |
| 2361 | 2361 | |
@@ -2372,17 +2372,17 @@ discard block |
||
| 2372 | 2372 | * false sinon. |
| 2373 | 2373 | **/ |
| 2374 | 2374 | function trouver_champ($champ, $where) { |
| 2375 | - if (!is_array($where)) { |
|
| 2376 | - return preg_match($champ, $where); |
|
| 2377 | - } else { |
|
| 2378 | - foreach ($where as $clause) { |
|
| 2379 | - if (trouver_champ($champ, $clause)) { |
|
| 2380 | - return true; |
|
| 2381 | - } |
|
| 2382 | - } |
|
| 2383 | - |
|
| 2384 | - return false; |
|
| 2385 | - } |
|
| 2375 | + if (!is_array($where)) { |
|
| 2376 | + return preg_match($champ, $where); |
|
| 2377 | + } else { |
|
| 2378 | + foreach ($where as $clause) { |
|
| 2379 | + if (trouver_champ($champ, $clause)) { |
|
| 2380 | + return true; |
|
| 2381 | + } |
|
| 2382 | + } |
|
| 2383 | + |
|
| 2384 | + return false; |
|
| 2385 | + } |
|
| 2386 | 2386 | } |
| 2387 | 2387 | |
| 2388 | 2388 | |
@@ -2408,128 +2408,128 @@ discard block |
||
| 2408 | 2408 | * - string $args_sql Suite des arguments du critère. ? |
| 2409 | 2409 | **/ |
| 2410 | 2410 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2411 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2412 | - if (count($crit->param) == 0) { |
|
| 2413 | - $op = '='; |
|
| 2414 | - $col = $val = $crit->op; |
|
| 2415 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2416 | - $val = $r[2]; |
|
| 2417 | - } |
|
| 2418 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2419 | - if ($val == 'lang') { |
|
| 2420 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2421 | - } else { |
|
| 2422 | - $defaut = null; |
|
| 2423 | - if ($val == 'id_parent') { |
|
| 2424 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2425 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2426 | - // pour eviter l'erreur SQL |
|
| 2427 | - $val = $boucles[$idb]->primary; |
|
| 2428 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2429 | - $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2430 | - } elseif ($val == 'id_enfant') { |
|
| 2431 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2432 | - // de la boucle superieure |
|
| 2433 | - $val = 'id_parent'; |
|
| 2434 | - } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2435 | - // un critere conditionnel sur date est traite a part |
|
| 2436 | - // car la date est mise d'office par SPIP, |
|
| 2437 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2438 | - } |
|
| 2439 | - |
|
| 2440 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2441 | - $val = array(kwote($val)); |
|
| 2442 | - } |
|
| 2443 | - } else { |
|
| 2444 | - // comparaison explicite |
|
| 2445 | - // le phraseur impose que le premier param soit du texte |
|
| 2446 | - $params = $crit->param; |
|
| 2447 | - $op = $crit->op; |
|
| 2448 | - if ($op == '==') { |
|
| 2449 | - $op = 'REGEXP'; |
|
| 2450 | - } |
|
| 2451 | - $col = array_shift($params); |
|
| 2452 | - $col = $col[0]->texte; |
|
| 2453 | - |
|
| 2454 | - $val = array(); |
|
| 2455 | - $parent = $boucles[$idb]->id_parent; |
|
| 2456 | - |
|
| 2457 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2458 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2459 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2460 | - if (count($params) == 1 |
|
| 2461 | - and count($params[0]) == 3 |
|
| 2462 | - and $params[0][0]->type == 'texte' |
|
| 2463 | - and $params[0][2]->type == 'texte' |
|
| 2464 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2465 | - and (($p == "'") or ($p == '"')) |
|
| 2466 | - and $params[0][1]->type == 'champ' |
|
| 2467 | - ) { |
|
| 2468 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2469 | - } else { |
|
| 2470 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2471 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2472 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2473 | - $val[] = $a; |
|
| 2474 | - } else { |
|
| 2475 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2476 | - } // toujours quoter en char ici |
|
| 2477 | - } |
|
| 2478 | - } |
|
| 2479 | - } |
|
| 2480 | - |
|
| 2481 | - $fct = $args_sql = ''; |
|
| 2482 | - // fonction SQL ? |
|
| 2483 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2484 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2485 | - $fct = $m[1]; |
|
| 2486 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2487 | - $col = $a[1]; |
|
| 2488 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2489 | - $col = $m[1]; |
|
| 2490 | - $args_sql = $m[2]; |
|
| 2491 | - } |
|
| 2492 | - $args_sql .= $a[2]; |
|
| 2493 | - } |
|
| 2494 | - |
|
| 2495 | - return array($fct, $col, $op, $val, $args_sql); |
|
| 2411 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2412 | + if (count($crit->param) == 0) { |
|
| 2413 | + $op = '='; |
|
| 2414 | + $col = $val = $crit->op; |
|
| 2415 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2416 | + $val = $r[2]; |
|
| 2417 | + } |
|
| 2418 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2419 | + if ($val == 'lang') { |
|
| 2420 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2421 | + } else { |
|
| 2422 | + $defaut = null; |
|
| 2423 | + if ($val == 'id_parent') { |
|
| 2424 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2425 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2426 | + // pour eviter l'erreur SQL |
|
| 2427 | + $val = $boucles[$idb]->primary; |
|
| 2428 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2429 | + $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2430 | + } elseif ($val == 'id_enfant') { |
|
| 2431 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2432 | + // de la boucle superieure |
|
| 2433 | + $val = 'id_parent'; |
|
| 2434 | + } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2435 | + // un critere conditionnel sur date est traite a part |
|
| 2436 | + // car la date est mise d'office par SPIP, |
|
| 2437 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2438 | + } |
|
| 2439 | + |
|
| 2440 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2441 | + $val = array(kwote($val)); |
|
| 2442 | + } |
|
| 2443 | + } else { |
|
| 2444 | + // comparaison explicite |
|
| 2445 | + // le phraseur impose que le premier param soit du texte |
|
| 2446 | + $params = $crit->param; |
|
| 2447 | + $op = $crit->op; |
|
| 2448 | + if ($op == '==') { |
|
| 2449 | + $op = 'REGEXP'; |
|
| 2450 | + } |
|
| 2451 | + $col = array_shift($params); |
|
| 2452 | + $col = $col[0]->texte; |
|
| 2453 | + |
|
| 2454 | + $val = array(); |
|
| 2455 | + $parent = $boucles[$idb]->id_parent; |
|
| 2456 | + |
|
| 2457 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2458 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2459 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2460 | + if (count($params) == 1 |
|
| 2461 | + and count($params[0]) == 3 |
|
| 2462 | + and $params[0][0]->type == 'texte' |
|
| 2463 | + and $params[0][2]->type == 'texte' |
|
| 2464 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2465 | + and (($p == "'") or ($p == '"')) |
|
| 2466 | + and $params[0][1]->type == 'champ' |
|
| 2467 | + ) { |
|
| 2468 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2469 | + } else { |
|
| 2470 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2471 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2472 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2473 | + $val[] = $a; |
|
| 2474 | + } else { |
|
| 2475 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2476 | + } // toujours quoter en char ici |
|
| 2477 | + } |
|
| 2478 | + } |
|
| 2479 | + } |
|
| 2480 | + |
|
| 2481 | + $fct = $args_sql = ''; |
|
| 2482 | + // fonction SQL ? |
|
| 2483 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2484 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2485 | + $fct = $m[1]; |
|
| 2486 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2487 | + $col = $a[1]; |
|
| 2488 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2489 | + $col = $m[1]; |
|
| 2490 | + $args_sql = $m[2]; |
|
| 2491 | + } |
|
| 2492 | + $args_sql .= $a[2]; |
|
| 2493 | + } |
|
| 2494 | + |
|
| 2495 | + return array($fct, $col, $op, $val, $args_sql); |
|
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | // compatibilite ancienne version |
| 2499 | 2499 | |
| 2500 | 2500 | // http://code.spip.net/@calculer_vieux_in |
| 2501 | 2501 | function calculer_vieux_in($params) { |
| 2502 | - $deb = $params[0][0]; |
|
| 2503 | - $k = count($params) - 1; |
|
| 2504 | - $last = $params[$k]; |
|
| 2505 | - $j = count($last) - 1; |
|
| 2506 | - $last = $last[$j]; |
|
| 2507 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2508 | - |
|
| 2509 | - if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2510 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2511 | - ) { |
|
| 2512 | - return $params; |
|
| 2513 | - } |
|
| 2514 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2515 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2516 | - $last = $params[$k][$j]; |
|
| 2517 | - $n = strlen($last->texte); |
|
| 2518 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2519 | - $newp = array(); |
|
| 2520 | - foreach ($params as $v) { |
|
| 2521 | - if ($v[0]->type != 'texte') { |
|
| 2522 | - $newp[] = $v; |
|
| 2523 | - } else { |
|
| 2524 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2525 | - $t = new Texte; |
|
| 2526 | - $t->texte = $x; |
|
| 2527 | - $newp[] = array($t); |
|
| 2528 | - } |
|
| 2529 | - } |
|
| 2530 | - } |
|
| 2531 | - |
|
| 2532 | - return $newp; |
|
| 2502 | + $deb = $params[0][0]; |
|
| 2503 | + $k = count($params) - 1; |
|
| 2504 | + $last = $params[$k]; |
|
| 2505 | + $j = count($last) - 1; |
|
| 2506 | + $last = $last[$j]; |
|
| 2507 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2508 | + |
|
| 2509 | + if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2510 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2511 | + ) { |
|
| 2512 | + return $params; |
|
| 2513 | + } |
|
| 2514 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2515 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2516 | + $last = $params[$k][$j]; |
|
| 2517 | + $n = strlen($last->texte); |
|
| 2518 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2519 | + $newp = array(); |
|
| 2520 | + foreach ($params as $v) { |
|
| 2521 | + if ($v[0]->type != 'texte') { |
|
| 2522 | + $newp[] = $v; |
|
| 2523 | + } else { |
|
| 2524 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2525 | + $t = new Texte; |
|
| 2526 | + $t->texte = $x; |
|
| 2527 | + $newp[] = array($t); |
|
| 2528 | + } |
|
| 2529 | + } |
|
| 2530 | + } |
|
| 2531 | + |
|
| 2532 | + return $newp; |
|
| 2533 | 2533 | } |
| 2534 | 2534 | |
| 2535 | 2535 | /** |
@@ -2548,89 +2548,89 @@ discard block |
||
| 2548 | 2548 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2549 | 2549 | **/ |
| 2550 | 2550 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2551 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2552 | - return ''; |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - $boucle = $boucles[$idb]; |
|
| 2556 | - $table = $boucle->show; |
|
| 2557 | - |
|
| 2558 | - // si c'est une colonne de la table, ne rien faire |
|
| 2559 | - if (isset($table['field'][$col])) { |
|
| 2560 | - return ''; |
|
| 2561 | - } |
|
| 2562 | - |
|
| 2563 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2564 | - return ''; |
|
| 2565 | - } |
|
| 2566 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2567 | - |
|
| 2568 | - $col = $regs[1]; |
|
| 2569 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2570 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2571 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2572 | - |
|
| 2573 | - if (isset($table['field']["date$suite"])) { |
|
| 2574 | - $date_orig = 'date' . $suite; |
|
| 2575 | - } else { |
|
| 2576 | - $date_orig = substr($suite, 1); |
|
| 2577 | - } |
|
| 2578 | - $pred = $date_orig; |
|
| 2579 | - } else { |
|
| 2580 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2581 | - $pred = 'date'; |
|
| 2582 | - } |
|
| 2583 | - } |
|
| 2584 | - |
|
| 2585 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2586 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2587 | - ") . '\""; |
|
| 2588 | - |
|
| 2589 | - $col_vraie = $date_orig; |
|
| 2590 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2591 | - |
|
| 2592 | - switch ($col) { |
|
| 2593 | - case 'date': |
|
| 2594 | - $col = $date_orig; |
|
| 2595 | - break; |
|
| 2596 | - case 'jour': |
|
| 2597 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2598 | - break; |
|
| 2599 | - case 'mois': |
|
| 2600 | - $col = "MONTH($date_orig)"; |
|
| 2601 | - break; |
|
| 2602 | - case 'annee': |
|
| 2603 | - $col = "YEAR($date_orig)"; |
|
| 2604 | - break; |
|
| 2605 | - case 'heure': |
|
| 2606 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2607 | - break; |
|
| 2608 | - case 'age': |
|
| 2609 | - $col = calculer_param_date("NOW()", $date_orig); |
|
| 2610 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2611 | - break; |
|
| 2612 | - case 'age_relatif': |
|
| 2613 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2614 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2615 | - break; |
|
| 2616 | - case 'jour_relatif': |
|
| 2617 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2618 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2619 | - break; |
|
| 2620 | - case 'mois_relatif': |
|
| 2621 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2622 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2623 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2624 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2625 | - break; |
|
| 2626 | - case 'annee_relatif': |
|
| 2627 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2628 | - $date_orig . ")"; |
|
| 2629 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2630 | - break; |
|
| 2631 | - } |
|
| 2632 | - |
|
| 2633 | - return array($col, $col_vraie); |
|
| 2551 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2552 | + return ''; |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + $boucle = $boucles[$idb]; |
|
| 2556 | + $table = $boucle->show; |
|
| 2557 | + |
|
| 2558 | + // si c'est une colonne de la table, ne rien faire |
|
| 2559 | + if (isset($table['field'][$col])) { |
|
| 2560 | + return ''; |
|
| 2561 | + } |
|
| 2562 | + |
|
| 2563 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2564 | + return ''; |
|
| 2565 | + } |
|
| 2566 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2567 | + |
|
| 2568 | + $col = $regs[1]; |
|
| 2569 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2570 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2571 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2572 | + |
|
| 2573 | + if (isset($table['field']["date$suite"])) { |
|
| 2574 | + $date_orig = 'date' . $suite; |
|
| 2575 | + } else { |
|
| 2576 | + $date_orig = substr($suite, 1); |
|
| 2577 | + } |
|
| 2578 | + $pred = $date_orig; |
|
| 2579 | + } else { |
|
| 2580 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2581 | + $pred = 'date'; |
|
| 2582 | + } |
|
| 2583 | + } |
|
| 2584 | + |
|
| 2585 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2586 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2587 | + ") . '\""; |
|
| 2588 | + |
|
| 2589 | + $col_vraie = $date_orig; |
|
| 2590 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2591 | + |
|
| 2592 | + switch ($col) { |
|
| 2593 | + case 'date': |
|
| 2594 | + $col = $date_orig; |
|
| 2595 | + break; |
|
| 2596 | + case 'jour': |
|
| 2597 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2598 | + break; |
|
| 2599 | + case 'mois': |
|
| 2600 | + $col = "MONTH($date_orig)"; |
|
| 2601 | + break; |
|
| 2602 | + case 'annee': |
|
| 2603 | + $col = "YEAR($date_orig)"; |
|
| 2604 | + break; |
|
| 2605 | + case 'heure': |
|
| 2606 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2607 | + break; |
|
| 2608 | + case 'age': |
|
| 2609 | + $col = calculer_param_date("NOW()", $date_orig); |
|
| 2610 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2611 | + break; |
|
| 2612 | + case 'age_relatif': |
|
| 2613 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2614 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2615 | + break; |
|
| 2616 | + case 'jour_relatif': |
|
| 2617 | + $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2618 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2619 | + break; |
|
| 2620 | + case 'mois_relatif': |
|
| 2621 | + $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2622 | + $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2623 | + ")-YEAR(" . $date_orig . "))"; |
|
| 2624 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2625 | + break; |
|
| 2626 | + case 'annee_relatif': |
|
| 2627 | + $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2628 | + $date_orig . ")"; |
|
| 2629 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2630 | + break; |
|
| 2631 | + } |
|
| 2632 | + |
|
| 2633 | + return array($col, $col_vraie); |
|
| 2634 | 2634 | } |
| 2635 | 2635 | |
| 2636 | 2636 | /** |
@@ -2649,16 +2649,16 @@ discard block |
||
| 2649 | 2649 | * de colonne SQL et une date. |
| 2650 | 2650 | **/ |
| 2651 | 2651 | function calculer_param_date($date_compare, $date_orig) { |
| 2652 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2653 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2654 | - $date_compare = '\'$x\''; |
|
| 2655 | - } else { |
|
| 2656 | - $init = $date_compare; |
|
| 2657 | - } |
|
| 2658 | - |
|
| 2659 | - return |
|
| 2660 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2661 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2652 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2653 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2654 | + $date_compare = '\'$x\''; |
|
| 2655 | + } else { |
|
| 2656 | + $init = $date_compare; |
|
| 2657 | + } |
|
| 2658 | + |
|
| 2659 | + return |
|
| 2660 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2661 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2662 | 2662 | } |
| 2663 | 2663 | |
| 2664 | 2664 | /** |
@@ -2676,18 +2676,18 @@ discard block |
||
| 2676 | 2676 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2677 | 2677 | */ |
| 2678 | 2678 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2679 | - $boucle = &$boucles[$idb]; |
|
| 2679 | + $boucle = &$boucles[$idb]; |
|
| 2680 | 2680 | |
| 2681 | - $args = array(); |
|
| 2682 | - foreach ($crit->param as &$param) { |
|
| 2683 | - array_push($args, |
|
| 2684 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 2685 | - } |
|
| 2681 | + $args = array(); |
|
| 2682 | + foreach ($crit->param as &$param) { |
|
| 2683 | + array_push($args, |
|
| 2684 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 2685 | + } |
|
| 2686 | 2686 | |
| 2687 | - $boucle->hash .= ' |
|
| 2687 | + $boucle->hash .= ' |
|
| 2688 | 2688 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2689 | 2689 | |
| 2690 | - $boucle->hash .= ' |
|
| 2690 | + $boucle->hash .= ' |
|
| 2691 | 2691 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2692 | 2692 | } |
| 2693 | 2693 | |
@@ -2704,8 +2704,8 @@ discard block |
||
| 2704 | 2704 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2705 | 2705 | */ |
| 2706 | 2706 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2707 | - $boucle = &$boucles[$idb]; |
|
| 2708 | - $boucle->hash .= ' |
|
| 2707 | + $boucle = &$boucles[$idb]; |
|
| 2708 | + $boucle->hash .= ' |
|
| 2709 | 2709 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2710 | 2710 | $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2711 | 2711 | } |
@@ -2725,8 +2725,8 @@ discard block |
||
| 2725 | 2725 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2726 | 2726 | */ |
| 2727 | 2727 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2728 | - $boucle = &$boucles[$idb]; |
|
| 2729 | - $boucle->hash .= ' |
|
| 2728 | + $boucle = &$boucles[$idb]; |
|
| 2729 | + $boucle->hash .= ' |
|
| 2730 | 2730 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2731 | 2731 | } |
| 2732 | 2732 | |
@@ -2742,12 +2742,12 @@ discard block |
||
| 2742 | 2742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2743 | 2743 | */ |
| 2744 | 2744 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2745 | - $boucle = &$boucles[$idb]; |
|
| 2746 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2747 | - foreach ($crit->param as $param) { |
|
| 2748 | - $boucle->hash .= ' |
|
| 2745 | + $boucle = &$boucles[$idb]; |
|
| 2746 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2747 | + foreach ($crit->param as $param) { |
|
| 2748 | + $boucle->hash .= ' |
|
| 2749 | 2749 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2750 | - } |
|
| 2750 | + } |
|
| 2751 | 2751 | } |
| 2752 | 2752 | |
| 2753 | 2753 | /** |
@@ -2764,12 +2764,12 @@ discard block |
||
| 2764 | 2764 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2765 | 2765 | */ |
| 2766 | 2766 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2767 | - $boucle = &$boucles[$idb]; |
|
| 2768 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2769 | - foreach ($crit->param as $param) { |
|
| 2770 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2771 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2772 | - } |
|
| 2767 | + $boucle = &$boucles[$idb]; |
|
| 2768 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2769 | + foreach ($crit->param as $param) { |
|
| 2770 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2771 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2772 | + } |
|
| 2773 | 2773 | } |
| 2774 | 2774 | |
| 2775 | 2775 | /** |
@@ -2794,12 +2794,12 @@ discard block |
||
| 2794 | 2794 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2795 | 2795 | */ |
| 2796 | 2796 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2797 | - $boucle = &$boucles[$idb]; |
|
| 2798 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2799 | - foreach ($crit->param as $param) { |
|
| 2800 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2801 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2802 | - } |
|
| 2797 | + $boucle = &$boucles[$idb]; |
|
| 2798 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2799 | + foreach ($crit->param as $param) { |
|
| 2800 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2801 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2802 | + } |
|
| 2803 | 2803 | } |
| 2804 | 2804 | |
| 2805 | 2805 | /** |
@@ -2814,11 +2814,11 @@ discard block |
||
| 2814 | 2814 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2815 | 2815 | */ |
| 2816 | 2816 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2817 | - $boucle = &$boucles[$idb]; |
|
| 2818 | - foreach ($crit->param as $param) { |
|
| 2819 | - $boucle->hash .= ' |
|
| 2817 | + $boucle = &$boucles[$idb]; |
|
| 2818 | + foreach ($crit->param as $param) { |
|
| 2819 | + $boucle->hash .= ' |
|
| 2820 | 2820 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2821 | - } |
|
| 2821 | + } |
|
| 2822 | 2822 | } |
| 2823 | 2823 | |
| 2824 | 2824 | |
@@ -2850,20 +2850,20 @@ discard block |
||
| 2850 | 2850 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2851 | 2851 | */ |
| 2852 | 2852 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2853 | - $boucle = &$boucles[$idb]; |
|
| 2854 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2855 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2856 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2857 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2858 | - if ($crit->param) { |
|
| 2859 | - foreach ($crit->param as $param) { |
|
| 2860 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2861 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2862 | - } |
|
| 2863 | - // interdire {si 0} aussi ! |
|
| 2864 | - } else { |
|
| 2865 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2866 | - } |
|
| 2853 | + $boucle = &$boucles[$idb]; |
|
| 2854 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2855 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2856 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2857 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2858 | + if ($crit->param) { |
|
| 2859 | + foreach ($crit->param as $param) { |
|
| 2860 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2861 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2862 | + } |
|
| 2863 | + // interdire {si 0} aussi ! |
|
| 2864 | + } else { |
|
| 2865 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2866 | + } |
|
| 2867 | 2867 | } |
| 2868 | 2868 | |
| 2869 | 2869 | /** |
@@ -2879,8 +2879,8 @@ discard block |
||
| 2879 | 2879 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2880 | 2880 | */ |
| 2881 | 2881 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2882 | - $boucle = &$boucles[$idb]; |
|
| 2883 | - $boucle->hash .= ' |
|
| 2882 | + $boucle = &$boucles[$idb]; |
|
| 2883 | + $boucle->hash .= ' |
|
| 2884 | 2884 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2885 | 2885 | $command[\'sourcemode\'] = \'table\';'; |
| 2886 | 2886 | } |
@@ -2901,29 +2901,29 @@ discard block |
||
| 2901 | 2901 | */ |
| 2902 | 2902 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2903 | 2903 | |
| 2904 | - $not = $crit->not; |
|
| 2905 | - $boucle = &$boucles[$idb]; |
|
| 2906 | - $primary = $boucle->primary; |
|
| 2904 | + $not = $crit->not; |
|
| 2905 | + $boucle = &$boucles[$idb]; |
|
| 2906 | + $primary = $boucle->primary; |
|
| 2907 | 2907 | |
| 2908 | - if (!$primary or strpos($primary, ',')) { |
|
| 2909 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2908 | + if (!$primary or strpos($primary, ',')) { |
|
| 2909 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2910 | 2910 | |
| 2911 | - return; |
|
| 2912 | - } |
|
| 2913 | - $table = $boucle->type_requete; |
|
| 2914 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2911 | + return; |
|
| 2912 | + } |
|
| 2913 | + $table = $boucle->type_requete; |
|
| 2914 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2915 | 2915 | |
| 2916 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2917 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2918 | - 'id_parent'; |
|
| 2916 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2917 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2918 | + 'id_parent'; |
|
| 2919 | 2919 | |
| 2920 | - $in = "IN"; |
|
| 2921 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2922 | - if ($not) { |
|
| 2923 | - $where = array("'NOT'", $where); |
|
| 2924 | - } |
|
| 2920 | + $in = "IN"; |
|
| 2921 | + $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2922 | + if ($not) { |
|
| 2923 | + $where = array("'NOT'", $where); |
|
| 2924 | + } |
|
| 2925 | 2925 | |
| 2926 | - $boucle->where[] = $where; |
|
| 2926 | + $boucle->where[] = $where; |
|
| 2927 | 2927 | } |
| 2928 | 2928 | |
| 2929 | 2929 | /** |
@@ -2939,8 +2939,8 @@ discard block |
||
| 2939 | 2939 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2940 | 2940 | */ |
| 2941 | 2941 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2942 | - $not = $crit->not; |
|
| 2943 | - $crit->not = $not ? false : true; |
|
| 2944 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2945 | - $crit->not = $not; |
|
| 2942 | + $not = $crit->not; |
|
| 2943 | + $crit->not = $not ? false : true; |
|
| 2944 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2945 | + $crit->not = $not; |
|
| 2946 | 2946 | } |