@@ -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,12 +43,12 @@ 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 = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 49 | 49 | |
| 50 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 50 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | * @return void|array |
| 66 | 66 | **/ |
| 67 | 67 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 68 | - $not = $crit->not; |
|
| 69 | - $boucle = &$boucles[$idb]; |
|
| 70 | - $id = $boucle->primary; |
|
| 71 | - |
|
| 72 | - if ($not or !$id) { |
|
| 73 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 74 | - } |
|
| 75 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 68 | + $not = $crit->not; |
|
| 69 | + $boucle = &$boucles[$idb]; |
|
| 70 | + $id = $boucle->primary; |
|
| 71 | + |
|
| 72 | + if ($not or !$id) { |
|
| 73 | + return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 74 | + } |
|
| 75 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -93,73 +93,73 @@ discard block |
||
| 93 | 93 | * @return void|array |
| 94 | 94 | **/ |
| 95 | 95 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 96 | - $boucle = &$boucles[$idb]; |
|
| 97 | - $primary = $boucle->primary; |
|
| 98 | - |
|
| 99 | - // la table nécessite une clé primaire, non composée |
|
| 100 | - if (!$primary or strpos($primary, ',')) { |
|
| 101 | - return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | - |
|
| 106 | - // le doublon s'applique sur un type de boucle (article) |
|
| 107 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | - |
|
| 109 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | - // on obtient $nom = "'article' . 'nom'" |
|
| 111 | - if (isset($crit->param[0])) { |
|
| 112 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | - |
|
| 119 | - // on crée un sql_in avec la clé primaire de la table |
|
| 120 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | - // $doublons et son index, ici $nom |
|
| 122 | - |
|
| 123 | - // debut du code "sql_in('articles.id_article', " |
|
| 124 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | - |
|
| 129 | - // le debut complet du code des doublons |
|
| 130 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | - |
|
| 132 | - // nom du doublon "('article' . 'nom')]" |
|
| 133 | - $fin_doub = "($nom)]"; |
|
| 134 | - |
|
| 135 | - // si on trouve un autre critère doublon, |
|
| 136 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | - foreach ($boucle->where as $k => $w) { |
|
| 138 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | - // fusionner le sql_in (du where) |
|
| 140 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | - $x = strpos($boucle->hash, $init_comment); |
|
| 143 | - $len = strlen($init_comment); |
|
| 144 | - $boucle->hash = |
|
| 145 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | - |
|
| 147 | - return; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | - |
|
| 154 | - // déclarer le doublon s'il n'existe pas encore |
|
| 155 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | - # {!doublons A}{doublons B} |
|
| 161 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 96 | + $boucle = &$boucles[$idb]; |
|
| 97 | + $primary = $boucle->primary; |
|
| 98 | + |
|
| 99 | + // la table nécessite une clé primaire, non composée |
|
| 100 | + if (!$primary or strpos($primary, ',')) { |
|
| 101 | + return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | + |
|
| 106 | + // le doublon s'applique sur un type de boucle (article) |
|
| 107 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + |
|
| 109 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | + // on obtient $nom = "'article' . 'nom'" |
|
| 111 | + if (isset($crit->param[0])) { |
|
| 112 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | + |
|
| 119 | + // on crée un sql_in avec la clé primaire de la table |
|
| 120 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | + // $doublons et son index, ici $nom |
|
| 122 | + |
|
| 123 | + // debut du code "sql_in('articles.id_article', " |
|
| 124 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | + |
|
| 129 | + // le debut complet du code des doublons |
|
| 130 | + $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + |
|
| 132 | + // nom du doublon "('article' . 'nom')]" |
|
| 133 | + $fin_doub = "($nom)]"; |
|
| 134 | + |
|
| 135 | + // si on trouve un autre critère doublon, |
|
| 136 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | + foreach ($boucle->where as $k => $w) { |
|
| 138 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | + // fusionner le sql_in (du where) |
|
| 140 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | + $x = strpos($boucle->hash, $init_comment); |
|
| 143 | + $len = strlen($init_comment); |
|
| 144 | + $boucle->hash = |
|
| 145 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | + |
|
| 154 | + // déclarer le doublon s'il n'existe pas encore |
|
| 155 | + $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | + # {!doublons A}{doublons B} |
|
| 161 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * @return void |
| 181 | 181 | **/ |
| 182 | 182 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 183 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | - $param = 'oui'; |
|
| 185 | - } |
|
| 186 | - if ($crit->not) { |
|
| 187 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | - } |
|
| 189 | - $boucle = &$boucles[$idb]; |
|
| 190 | - $boucle->lang_select = $param; |
|
| 183 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | + $param = 'oui'; |
|
| 185 | + } |
|
| 186 | + if ($crit->not) { |
|
| 187 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | + } |
|
| 189 | + $boucle = &$boucles[$idb]; |
|
| 190 | + $boucle->lang_select = $param; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -209,15 +209,15 @@ discard block |
||
| 209 | 209 | * @return void |
| 210 | 210 | **/ |
| 211 | 211 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 212 | - [$un, $deux] = $crit->param; |
|
| 213 | - $un = $un[0]->texte; |
|
| 214 | - $deux = $deux[0]->texte; |
|
| 215 | - if ($deux) { |
|
| 216 | - $boucles[$idb]->limit = |
|
| 217 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | - } else { |
|
| 219 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | - } |
|
| 212 | + [$un, $deux] = $crit->param; |
|
| 213 | + $un = $un[0]->texte; |
|
| 214 | + $deux = $deux[0]->texte; |
|
| 215 | + if ($deux) { |
|
| 216 | + $boucles[$idb]->limit = |
|
| 217 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | + } else { |
|
| 219 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | + } |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | |
@@ -251,58 +251,58 @@ discard block |
||
| 251 | 251 | **/ |
| 252 | 252 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 253 | 253 | |
| 254 | - $boucle = &$boucles[$idb]; |
|
| 255 | - // definition de la taille de la page |
|
| 256 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | - |
|
| 259 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | - } else { |
|
| 262 | - $r = intval($r[2]); |
|
| 263 | - $pas = strval($r ?: 10); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Calcul du nommage de la pagination si il existe. |
|
| 267 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | - $type = "'$idb'"; |
|
| 270 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | - // Syntaxe {pagination 20, nom} |
|
| 272 | - if (isset($crit->param[0][1])) { |
|
| 273 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | - elseif (isset($crit->param[1][0])) { |
|
| 276 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | - $partie = |
|
| 282 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | - . "\t}\n" |
|
| 288 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | - |
|
| 290 | - $boucle->hash .= ' |
|
| 254 | + $boucle = &$boucles[$idb]; |
|
| 255 | + // definition de la taille de la page |
|
| 256 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | + |
|
| 259 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | + } else { |
|
| 262 | + $r = intval($r[2]); |
|
| 263 | + $pas = strval($r ?: 10); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Calcul du nommage de la pagination si il existe. |
|
| 267 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | + $type = "'$idb'"; |
|
| 270 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | + // Syntaxe {pagination 20, nom} |
|
| 272 | + if (isset($crit->param[0][1])) { |
|
| 273 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | + elseif (isset($crit->param[1][0])) { |
|
| 276 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | + $partie = |
|
| 282 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | + . "\t}\n" |
|
| 288 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | + |
|
| 290 | + $boucle->hash .= ' |
|
| 291 | 291 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 292 | 292 | |
| 293 | - $boucle->total_parties = $pas; |
|
| 294 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | - // sauf si pas de primaire, ou si primaire composee |
|
| 297 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | - if ( |
|
| 300 | - $boucle->primary |
|
| 301 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | - and !in_array($t, $boucle->select) |
|
| 303 | - ) { |
|
| 304 | - $boucle->select[] = $t; |
|
| 305 | - } |
|
| 293 | + $boucle->total_parties = $pas; |
|
| 294 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | + // sauf si pas de primaire, ou si primaire composee |
|
| 297 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | + if ( |
|
| 300 | + $boucle->primary |
|
| 301 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | + and !in_array($t, $boucle->select) |
|
| 303 | + ) { |
|
| 304 | + $boucle->select[] = $t; |
|
| 305 | + } |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | |
@@ -324,24 +324,24 @@ discard block |
||
| 324 | 324 | **/ |
| 325 | 325 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 326 | 326 | |
| 327 | - $boucle = &$boucles[$idb]; |
|
| 327 | + $boucle = &$boucles[$idb]; |
|
| 328 | 328 | |
| 329 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 329 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 331 | 331 | |
| 332 | - return; |
|
| 333 | - } |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - if (isset($crit->param[0])) { |
|
| 336 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | - } else { |
|
| 338 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | - } |
|
| 335 | + if (isset($crit->param[0])) { |
|
| 336 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | + } else { |
|
| 338 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | - $boucle->hash .= ' |
|
| 341 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | + $boucle->hash .= ' |
|
| 343 | 343 | // RECHERCHE' |
| 344 | - . ($crit->cond ? ' |
|
| 344 | + . ($crit->cond ? ' |
|
| 345 | 345 | if (!strlen(' . $quoi . ')){ |
| 346 | 346 | list($rech_select, $rech_where) = array("0 as points",""); |
| 347 | 347 | } else' : '') . ' |
@@ -352,21 +352,21 @@ discard block |
||
| 352 | 352 | '; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | - $boucle->select[] = $t; |
|
| 358 | - } # pour postgres, neuneu ici |
|
| 359 | - // jointure uniquement sur le serveur principal |
|
| 360 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | - if (!$boucle->sql_serveur) { |
|
| 362 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | - } |
|
| 365 | - $boucle->select[] = '$rech_select'; |
|
| 366 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | - |
|
| 368 | - // et la recherche trouve |
|
| 369 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 355 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | + $boucle->select[] = $t; |
|
| 358 | + } # pour postgres, neuneu ici |
|
| 359 | + // jointure uniquement sur le serveur principal |
|
| 360 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | + if (!$boucle->sql_serveur) { |
|
| 362 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | + } |
|
| 365 | + $boucle->select[] = '$rech_select'; |
|
| 366 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | + |
|
| 368 | + // et la recherche trouve |
|
| 369 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -383,25 +383,25 @@ discard block |
||
| 383 | 383 | * @return void |
| 384 | 384 | **/ |
| 385 | 385 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 386 | - $boucle = &$boucles[$idb]; |
|
| 387 | - $prim = $boucle->primary; |
|
| 388 | - $table = $boucle->id_table; |
|
| 389 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | - $boucle->where[] = |
|
| 392 | - [ |
|
| 393 | - "'OR'", |
|
| 394 | - [ |
|
| 395 | - "'AND'", |
|
| 396 | - ["'='", "'$table.id_trad'", 0], |
|
| 397 | - ["'='", "'$table.$prim'", $dprim] |
|
| 398 | - ], |
|
| 399 | - [ |
|
| 400 | - "'AND'", |
|
| 401 | - ["'>'", "'$table.id_trad'", 0], |
|
| 402 | - ["'='", "'$table.id_trad'", $arg] |
|
| 403 | - ] |
|
| 404 | - ]; |
|
| 386 | + $boucle = &$boucles[$idb]; |
|
| 387 | + $prim = $boucle->primary; |
|
| 388 | + $table = $boucle->id_table; |
|
| 389 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | + $boucle->where[] = |
|
| 392 | + [ |
|
| 393 | + "'OR'", |
|
| 394 | + [ |
|
| 395 | + "'AND'", |
|
| 396 | + ["'='", "'$table.id_trad'", 0], |
|
| 397 | + ["'='", "'$table.$prim'", $dprim] |
|
| 398 | + ], |
|
| 399 | + [ |
|
| 400 | + "'AND'", |
|
| 401 | + ["'>'", "'$table.id_trad'", 0], |
|
| 402 | + ["'='", "'$table.id_trad'", $arg] |
|
| 403 | + ] |
|
| 404 | + ]; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | * @return void |
| 420 | 420 | **/ |
| 421 | 421 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 422 | - $boucle = &$boucles[$idb]; |
|
| 423 | - $prim = $boucle->primary; |
|
| 424 | - $table = $boucle->id_table; |
|
| 425 | - |
|
| 426 | - $c = |
|
| 427 | - [ |
|
| 428 | - "'OR'", |
|
| 429 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | - ]; |
|
| 432 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 422 | + $boucle = &$boucles[$idb]; |
|
| 423 | + $prim = $boucle->primary; |
|
| 424 | + $table = $boucle->id_table; |
|
| 425 | + |
|
| 426 | + $c = |
|
| 427 | + [ |
|
| 428 | + "'OR'", |
|
| 429 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | + ]; |
|
| 432 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
@@ -446,17 +446,17 @@ discard block |
||
| 446 | 446 | **/ |
| 447 | 447 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 448 | 448 | |
| 449 | - $boucle = &$boucles[$idb]; |
|
| 450 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | - |
|
| 454 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | - else { |
|
| 458 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 459 | - } |
|
| 449 | + $boucle = &$boucles[$idb]; |
|
| 450 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + |
|
| 454 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | + else { |
|
| 458 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 459 | + } |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
@@ -487,37 +487,37 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 489 | 489 | |
| 490 | - $not = $crit->not; |
|
| 491 | - $boucle = &$boucles[$idb]; |
|
| 492 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | - if (isset($crit->param[0])) { |
|
| 494 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | - // sinon on le prend chez une boucle parente |
|
| 496 | - } else { |
|
| 497 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - //Trouver une jointure |
|
| 501 | - $champ = 'id_rubrique'; |
|
| 502 | - $desc = $boucle->show; |
|
| 503 | - //Seulement si necessaire |
|
| 504 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | - $decompose = decompose_champ_id_objet($champ); |
|
| 510 | - $champ = array_shift($decompose); |
|
| 511 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | - } |
|
| 513 | - } else { |
|
| 514 | - $cle = $boucle->id_table; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 490 | + $not = $crit->not; |
|
| 491 | + $boucle = &$boucles[$idb]; |
|
| 492 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | + if (isset($crit->param[0])) { |
|
| 494 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | + // sinon on le prend chez une boucle parente |
|
| 496 | + } else { |
|
| 497 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + //Trouver une jointure |
|
| 501 | + $champ = 'id_rubrique'; |
|
| 502 | + $desc = $boucle->show; |
|
| 503 | + //Seulement si necessaire |
|
| 504 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | + $decompose = decompose_champ_id_objet($champ); |
|
| 510 | + $champ = array_shift($decompose); |
|
| 511 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | + } |
|
| 513 | + } else { |
|
| 514 | + $cle = $boucle->id_table; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 535 | 535 | |
| 536 | - $boucle = &$boucles[$idb]; |
|
| 537 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | - $serveur = $boucle->sql_serveur; |
|
| 536 | + $boucle = &$boucles[$idb]; |
|
| 537 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | + $serveur = $boucle->sql_serveur; |
|
| 539 | 539 | |
| 540 | - $c = "sql_in('" . |
|
| 541 | - $boucle->id_table . '.' . $boucle->primary |
|
| 542 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 540 | + $c = "sql_in('" . |
|
| 541 | + $boucle->id_table . '.' . $boucle->primary |
|
| 542 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 543 | 543 | |
| 544 | - $boucle->where[] = $c; |
|
| 544 | + $boucle->where[] = $c; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -563,31 +563,31 @@ discard block |
||
| 563 | 563 | * @return void|array |
| 564 | 564 | **/ |
| 565 | 565 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 566 | - if ($t = isset($crit->param[0])) { |
|
| 567 | - $t = $crit->param[0]; |
|
| 568 | - if ($t[0]->type == 'texte') { |
|
| 569 | - $t = $t[0]->texte; |
|
| 570 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | - $t = table_objet_sql($r[1]); |
|
| 572 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | - if ($t) { |
|
| 574 | - $t .= '.' . $r[2]; |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } else { |
|
| 578 | - $t = '".' |
|
| 579 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | - . '."'; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - if ($t) { |
|
| 584 | - $boucles[$idb]->group[] = $t; |
|
| 585 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | - $boucles[$idb]->select[] = $t; |
|
| 587 | - } |
|
| 588 | - } else { |
|
| 589 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 590 | - } |
|
| 566 | + if ($t = isset($crit->param[0])) { |
|
| 567 | + $t = $crit->param[0]; |
|
| 568 | + if ($t[0]->type == 'texte') { |
|
| 569 | + $t = $t[0]->texte; |
|
| 570 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | + $t = table_objet_sql($r[1]); |
|
| 572 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | + if ($t) { |
|
| 574 | + $t .= '.' . $r[2]; |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } else { |
|
| 578 | + $t = '".' |
|
| 579 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | + . '."'; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + if ($t) { |
|
| 584 | + $boucles[$idb]->group[] = $t; |
|
| 585 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | + $boucles[$idb]->select[] = $t; |
|
| 587 | + } |
|
| 588 | + } else { |
|
| 589 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | * @return void |
| 608 | 608 | **/ |
| 609 | 609 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 610 | - $boucles[$idb]->group = []; |
|
| 610 | + $boucles[$idb]->group = []; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -644,44 +644,44 @@ discard block |
||
| 644 | 644 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 645 | 645 | */ |
| 646 | 646 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 647 | - if (isset($crit->param[0])) { |
|
| 648 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | - $boucle = $boucles[$idb]; |
|
| 650 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | - if ( |
|
| 656 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | - ) { |
|
| 659 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | - } else { |
|
| 661 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | - } |
|
| 647 | + if (isset($crit->param[0])) { |
|
| 648 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | + $boucle = $boucles[$idb]; |
|
| 650 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | + if ( |
|
| 656 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | + ) { |
|
| 659 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | + } else { |
|
| 661 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | + } |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 670 | - $boucle = $boucles[$idb]; |
|
| 671 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | - $var = '$champs_' . $idb; |
|
| 673 | - $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | - if (!$desc) { |
|
| 675 | - $desc = $boucle->show['field']; |
|
| 676 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | - } |
|
| 679 | - if ($desc) { |
|
| 680 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | - } |
|
| 682 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | - |
|
| 684 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 670 | + $boucle = $boucles[$idb]; |
|
| 671 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | + $var = '$champs_' . $idb; |
|
| 673 | + $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | + if (!$desc) { |
|
| 675 | + $desc = $boucle->show['field']; |
|
| 676 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | + } |
|
| 679 | + if ($desc) { |
|
| 680 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | + } |
|
| 682 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | + |
|
| 684 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 721 | 721 | */ |
| 722 | 722 | function critere_par_dist($idb, &$boucles, $crit) { |
| 723 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 723 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -742,93 +742,93 @@ discard block |
||
| 742 | 742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 743 | 743 | */ |
| 744 | 744 | function critere_parinverse($idb, &$boucles, $crit) { |
| 745 | - $boucle = &$boucles[$idb]; |
|
| 746 | - |
|
| 747 | - $sens = $collecte = ''; |
|
| 748 | - if ($crit->not) { |
|
| 749 | - $sens = " . ' DESC'"; |
|
| 750 | - } |
|
| 751 | - if (isset($boucle->modificateur['collate'])) { |
|
| 752 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - // Pour chaque paramètre du critère |
|
| 756 | - foreach ($crit->param as $tri) { |
|
| 757 | - $order = $fct = ''; |
|
| 758 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | - if ($tri[0]->type != 'texte') { |
|
| 760 | - // calculer le order dynamique qui verifie les champs |
|
| 761 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | - } |
|
| 765 | - // tris textuels {par titre} |
|
| 766 | - else { |
|
| 767 | - $par = array_shift($tri); |
|
| 768 | - $par = $par->texte; |
|
| 769 | - |
|
| 770 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | - $expression = trim($m[1]); |
|
| 773 | - $champ = trim($m[2]); |
|
| 774 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | - } else { |
|
| 777 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | - // {par FONCTION(champ)} |
|
| 783 | - if (isset($match) and count($match) > 2) { |
|
| 784 | - $par = substr($match[2], 1, -1); |
|
| 785 | - $fct = $match[1]; |
|
| 786 | - } |
|
| 787 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | - if ($par == 'hasard') { |
|
| 789 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | - } else { |
|
| 793 | - // cas général {par champ}, {par table.champ}, ... |
|
| 794 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // on ne sait pas traiter… |
|
| 799 | - else { |
|
| 800 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | - if (is_array($order)) { |
|
| 805 | - return $order; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | - $t = $m[1]; |
|
| 811 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | - $boucle->select[] = $t; |
|
| 813 | - } |
|
| 814 | - } else { |
|
| 815 | - $sens = ''; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($fct) { |
|
| 819 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | - } else { |
|
| 822 | - $order = "'$fct(' . $order . ')'"; |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - $t = $order . $collecte . $sens; |
|
| 826 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | - $t = $r[1] . $r[2]; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $boucle->order[] = $t; |
|
| 831 | - } |
|
| 745 | + $boucle = &$boucles[$idb]; |
|
| 746 | + |
|
| 747 | + $sens = $collecte = ''; |
|
| 748 | + if ($crit->not) { |
|
| 749 | + $sens = " . ' DESC'"; |
|
| 750 | + } |
|
| 751 | + if (isset($boucle->modificateur['collate'])) { |
|
| 752 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + // Pour chaque paramètre du critère |
|
| 756 | + foreach ($crit->param as $tri) { |
|
| 757 | + $order = $fct = ''; |
|
| 758 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | + if ($tri[0]->type != 'texte') { |
|
| 760 | + // calculer le order dynamique qui verifie les champs |
|
| 761 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | + } |
|
| 765 | + // tris textuels {par titre} |
|
| 766 | + else { |
|
| 767 | + $par = array_shift($tri); |
|
| 768 | + $par = $par->texte; |
|
| 769 | + |
|
| 770 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | + $expression = trim($m[1]); |
|
| 773 | + $champ = trim($m[2]); |
|
| 774 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | + } else { |
|
| 777 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | + // {par FONCTION(champ)} |
|
| 783 | + if (isset($match) and count($match) > 2) { |
|
| 784 | + $par = substr($match[2], 1, -1); |
|
| 785 | + $fct = $match[1]; |
|
| 786 | + } |
|
| 787 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | + if ($par == 'hasard') { |
|
| 789 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | + } else { |
|
| 793 | + // cas général {par champ}, {par table.champ}, ... |
|
| 794 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // on ne sait pas traiter… |
|
| 799 | + else { |
|
| 800 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | + if (is_array($order)) { |
|
| 805 | + return $order; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | + $t = $m[1]; |
|
| 811 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | + $boucle->select[] = $t; |
|
| 813 | + } |
|
| 814 | + } else { |
|
| 815 | + $sens = ''; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($fct) { |
|
| 819 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | + } else { |
|
| 822 | + $order = "'$fct(' . $order . ')'"; |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + $t = $order . $collecte . $sens; |
|
| 826 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | + $t = $r[1] . $r[2]; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $boucle->order[] = $t; |
|
| 831 | + } |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -842,13 +842,13 @@ discard block |
||
| 842 | 842 | * @return string Clause pour le Order by |
| 843 | 843 | */ |
| 844 | 844 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 845 | - $boucle = &$boucles[$idb]; |
|
| 846 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | - $parha = 'rand() AS hasard'; |
|
| 848 | - if (!in_array($parha, $boucle->select)) { |
|
| 849 | - $boucle->select[] = $parha; |
|
| 850 | - } |
|
| 851 | - return "'hasard'"; |
|
| 845 | + $boucle = &$boucles[$idb]; |
|
| 846 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | + $parha = 'rand() AS hasard'; |
|
| 848 | + if (!in_array($parha, $boucle->select)) { |
|
| 849 | + $boucle->select[] = $parha; |
|
| 850 | + } |
|
| 851 | + return "'hasard'"; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | /** |
@@ -872,24 +872,24 @@ discard block |
||
| 872 | 872 | * @return string|array Clause pour le Order by (array si erreur) |
| 873 | 873 | */ |
| 874 | 874 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 875 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | - if (is_array($_champ)) { |
|
| 877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | - } |
|
| 879 | - $boucle = &$boucles[$idb]; |
|
| 880 | - $texte = '0+' . $_champ; |
|
| 881 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | - if ($suite !== "''") { |
|
| 883 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | - } |
|
| 885 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | - |
|
| 888 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | - $orderassinum = trim($orderassinum, "'"); |
|
| 890 | - |
|
| 891 | - $order = "'$orderassinum, $asnum'"; |
|
| 892 | - return $order; |
|
| 875 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | + if (is_array($_champ)) { |
|
| 877 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | + } |
|
| 879 | + $boucle = &$boucles[$idb]; |
|
| 880 | + $texte = '0+' . $_champ; |
|
| 881 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | + if ($suite !== "''") { |
|
| 883 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | + } |
|
| 885 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | + |
|
| 888 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | + $orderassinum = trim($orderassinum, "'"); |
|
| 890 | + |
|
| 891 | + $order = "'$orderassinum, $asnum'"; |
|
| 892 | + return $order; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -910,35 +910,35 @@ discard block |
||
| 910 | 910 | * @return string|array Clause pour le Order by (array si erreur) |
| 911 | 911 | */ |
| 912 | 912 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 913 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | - if (is_array($_champ)) { |
|
| 915 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | - } |
|
| 917 | - $boucle = &$boucles[$idb]; |
|
| 918 | - $texte = '0+' . $_champ; |
|
| 919 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | - if ($suite !== "''") { |
|
| 921 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - $as = false; |
|
| 925 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | - foreach ($boucle->select as $s) { |
|
| 927 | - if (strpos($s, $select) === 0) { |
|
| 928 | - $as = trim(substr($s, strlen($select))); |
|
| 929 | - if (!preg_match(',\W,', $as)) { |
|
| 930 | - break; |
|
| 931 | - } |
|
| 932 | - $as = false; |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - if (!$as) { |
|
| 937 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | - $boucle->select[] = $select . $as; |
|
| 939 | - } |
|
| 940 | - $order = "'$as'"; |
|
| 941 | - return $order; |
|
| 913 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | + if (is_array($_champ)) { |
|
| 915 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | + } |
|
| 917 | + $boucle = &$boucles[$idb]; |
|
| 918 | + $texte = '0+' . $_champ; |
|
| 919 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | + if ($suite !== "''") { |
|
| 921 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + $as = false; |
|
| 925 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | + foreach ($boucle->select as $s) { |
|
| 927 | + if (strpos($s, $select) === 0) { |
|
| 928 | + $as = trim(substr($s, strlen($select))); |
|
| 929 | + if (!preg_match(',\W,', $as)) { |
|
| 930 | + break; |
|
| 931 | + } |
|
| 932 | + $as = false; |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + if (!$as) { |
|
| 937 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | + $boucle->select[] = $select . $as; |
|
| 939 | + } |
|
| 940 | + $order = "'$as'"; |
|
| 941 | + return $order; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | |
@@ -958,14 +958,14 @@ discard block |
||
| 958 | 958 | * @return string|array Clause pour le Order by (array si erreur) |
| 959 | 959 | */ |
| 960 | 960 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | - if (is_array($_champ)) { |
|
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | - } |
|
| 965 | - $boucle = &$boucles[$idb]; |
|
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | - $order = "'multi'"; |
|
| 968 | - return $order; |
|
| 961 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | + if (is_array($_champ)) { |
|
| 963 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | + } |
|
| 965 | + $boucle = &$boucles[$idb]; |
|
| 966 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | + $order = "'multi'"; |
|
| 968 | + return $order; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -984,56 +984,56 @@ discard block |
||
| 984 | 984 | * @return array|string |
| 985 | 985 | */ |
| 986 | 986 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 987 | - $boucle = &$boucles[$idb]; |
|
| 988 | - $desc = $boucle->show; |
|
| 989 | - |
|
| 990 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | - if (isset($desc['field'][$par])) { |
|
| 992 | - $par = $boucle->id_table . '.' . $par; |
|
| 993 | - } |
|
| 994 | - // le champ est peut être une jointure |
|
| 995 | - else { |
|
| 996 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | - $champ = $par; |
|
| 998 | - |
|
| 999 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | - [, $table, $champ] = $r; |
|
| 1005 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | - $table = table_objet_sql($table); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | - } elseif ( |
|
| 1015 | - $boucle->jointures_explicites |
|
| 1016 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | - ) { |
|
| 1018 | - $par = $alias . '.' . $champ; |
|
| 1019 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | - $par = $alias . '.' . $champ; |
|
| 1021 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | - } elseif ( |
|
| 1023 | - $table_alias |
|
| 1024 | - and isset($boucle->from[$table_alias]) |
|
| 1025 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | - ) { |
|
| 1027 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | - } elseif ($table) { |
|
| 1029 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | - } else { |
|
| 1032 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - return $raw ? $par : "'$par'"; |
|
| 987 | + $boucle = &$boucles[$idb]; |
|
| 988 | + $desc = $boucle->show; |
|
| 989 | + |
|
| 990 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | + if (isset($desc['field'][$par])) { |
|
| 992 | + $par = $boucle->id_table . '.' . $par; |
|
| 993 | + } |
|
| 994 | + // le champ est peut être une jointure |
|
| 995 | + else { |
|
| 996 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | + $champ = $par; |
|
| 998 | + |
|
| 999 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | + [, $table, $champ] = $r; |
|
| 1005 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | + $table = table_objet_sql($table); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | + } elseif ( |
|
| 1015 | + $boucle->jointures_explicites |
|
| 1016 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | + ) { |
|
| 1018 | + $par = $alias . '.' . $champ; |
|
| 1019 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | + $par = $alias . '.' . $champ; |
|
| 1021 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | + } elseif ( |
|
| 1023 | + $table_alias |
|
| 1024 | + and isset($boucle->from[$table_alias]) |
|
| 1025 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | + ) { |
|
| 1027 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | + } elseif ($table) { |
|
| 1029 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | + } else { |
|
| 1032 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + return $raw ? $par : "'$par'"; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | /** |
@@ -1047,11 +1047,11 @@ discard block |
||
| 1047 | 1047 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1048 | 1048 | */ |
| 1049 | 1049 | function critere_par_joint($table, $champ, &$boucle) { |
| 1050 | - $t = array_search($table, $boucle->from); |
|
| 1051 | - if (!$t) { |
|
| 1052 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | - } |
|
| 1054 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1050 | + $t = array_search($table, $boucle->from); |
|
| 1051 | + if (!$t) { |
|
| 1052 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | + } |
|
| 1054 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
@@ -1076,33 +1076,33 @@ discard block |
||
| 1076 | 1076 | */ |
| 1077 | 1077 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1078 | 1078 | |
| 1079 | - $boucle = &$boucles[$idb]; |
|
| 1080 | - // Classement par ordre inverse |
|
| 1081 | - if ($crit->not) { |
|
| 1082 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | - } else { |
|
| 1084 | - $order = "' DESC'"; |
|
| 1085 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | - if (isset($crit->param[0])) { |
|
| 1087 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | - $order = "(($critere)?' DESC':'')"; |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | - if (!$n) { |
|
| 1093 | - if (isset($boucle->default_order[0])) { |
|
| 1094 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | - } else { |
|
| 1096 | - $boucle->default_order[] = ' DESC'; |
|
| 1097 | - } |
|
| 1098 | - } else { |
|
| 1099 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | - $t = $r[1] . $r[2]; |
|
| 1102 | - } |
|
| 1103 | - $boucle->order[$n - 1] = $t; |
|
| 1104 | - } |
|
| 1105 | - } |
|
| 1079 | + $boucle = &$boucles[$idb]; |
|
| 1080 | + // Classement par ordre inverse |
|
| 1081 | + if ($crit->not) { |
|
| 1082 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | + } else { |
|
| 1084 | + $order = "' DESC'"; |
|
| 1085 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | + if (isset($crit->param[0])) { |
|
| 1087 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | + $order = "(($critere)?' DESC':'')"; |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | + if (!$n) { |
|
| 1093 | + if (isset($boucle->default_order[0])) { |
|
| 1094 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | + } else { |
|
| 1096 | + $boucle->default_order[] = ' DESC'; |
|
| 1097 | + } |
|
| 1098 | + } else { |
|
| 1099 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | + $t = $r[1] . $r[2]; |
|
| 1102 | + } |
|
| 1103 | + $boucle->order[$n - 1] = $t; |
|
| 1104 | + } |
|
| 1105 | + } |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1114,139 +1114,139 @@ discard block |
||
| 1114 | 1114 | * @return void|array |
| 1115 | 1115 | */ |
| 1116 | 1116 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1117 | - $boucle = &$boucles[$idb]; |
|
| 1117 | + $boucle = &$boucles[$idb]; |
|
| 1118 | 1118 | |
| 1119 | - $sens = $collecte = ''; |
|
| 1120 | - if ($crit->not) { |
|
| 1121 | - $sens = " . ' DESC'"; |
|
| 1122 | - } |
|
| 1119 | + $sens = $collecte = ''; |
|
| 1120 | + if ($crit->not) { |
|
| 1121 | + $sens = " . ' DESC'"; |
|
| 1122 | + } |
|
| 1123 | 1123 | |
| 1124 | - $crit2 = clone $crit; |
|
| 1125 | - $crit2->not = false; |
|
| 1126 | - $crit2->param = [reset($crit->param)]; |
|
| 1127 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1124 | + $crit2 = clone $crit; |
|
| 1125 | + $crit2->not = false; |
|
| 1126 | + $crit2->param = [reset($crit->param)]; |
|
| 1127 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1128 | 1128 | |
| 1129 | - // erreur ? |
|
| 1130 | - if (is_array($res)) { |
|
| 1131 | - return $res; |
|
| 1132 | - } |
|
| 1129 | + // erreur ? |
|
| 1130 | + if (is_array($res)) { |
|
| 1131 | + return $res; |
|
| 1132 | + } |
|
| 1133 | 1133 | |
| 1134 | - $_order = array_pop($boucle->order); |
|
| 1134 | + $_order = array_pop($boucle->order); |
|
| 1135 | 1135 | |
| 1136 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1137 | 1137 | |
| 1138 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1139 | - $boucle->order[] = $order; |
|
| 1138 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1139 | + $boucle->order[] = $order; |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | |
| 1143 | 1143 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1144 | - $params = $crit->param; |
|
| 1145 | - |
|
| 1146 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1147 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - $boucle = &$boucles[$idb]; |
|
| 1151 | - $parent = $boucle->id_parent; |
|
| 1152 | - $fields = $boucle->show['field']; |
|
| 1153 | - |
|
| 1154 | - $date = array_shift($params); |
|
| 1155 | - $type = array_shift($params); |
|
| 1156 | - |
|
| 1157 | - // la valeur $type doit etre connue a la compilation |
|
| 1158 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1159 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1160 | - |
|
| 1161 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1162 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1163 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1164 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1165 | - if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1166 | - $date = $date[0]->texte; |
|
| 1167 | - if (!isset($fields[$date])) { |
|
| 1168 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1169 | - } |
|
| 1170 | - } else { |
|
| 1171 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1172 | - $noms = array_keys($fields); |
|
| 1173 | - $defaut = $noms[0]; |
|
| 1174 | - $noms = join(' ', $noms); |
|
| 1175 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1176 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1177 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1178 | - } |
|
| 1179 | - $annee = $params ? array_shift($params) : ''; |
|
| 1180 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1181 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1182 | - ') ? $x : date("Y"))'; |
|
| 1183 | - |
|
| 1184 | - $mois = $params ? array_shift($params) : ''; |
|
| 1185 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1186 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1187 | - ') ? $x : date("m"))'; |
|
| 1188 | - |
|
| 1189 | - $jour = $params ? array_shift($params) : ''; |
|
| 1190 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1191 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1192 | - ') ? $x : date("d"))'; |
|
| 1193 | - |
|
| 1194 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1195 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1196 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1197 | - ') ? $x : date("Y"))'; |
|
| 1198 | - |
|
| 1199 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1200 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1201 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1202 | - ') ? $x : date("m"))'; |
|
| 1203 | - |
|
| 1204 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1205 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1206 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1207 | - ') ? $x : date("d"))'; |
|
| 1208 | - |
|
| 1209 | - $date = $boucle->id_table . ".$date"; |
|
| 1210 | - |
|
| 1211 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1212 | - if ($type == 'jour') { |
|
| 1213 | - $boucle->where[] = [ |
|
| 1214 | - "'='", |
|
| 1215 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1216 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1217 | - ]; |
|
| 1218 | - } elseif ($type == 'mois') { |
|
| 1219 | - $boucle->where[] = [ |
|
| 1220 | - "'='", |
|
| 1221 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1222 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1223 | - ]; |
|
| 1224 | - } elseif ($type == 'semaine') { |
|
| 1225 | - $boucle->where[] = [ |
|
| 1226 | - "'AND'", |
|
| 1227 | - [ |
|
| 1228 | - "'>='", |
|
| 1229 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1230 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1231 | - ], |
|
| 1232 | - [ |
|
| 1233 | - "'<='", |
|
| 1234 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1235 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1236 | - ] |
|
| 1237 | - ]; |
|
| 1238 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1239 | - $boucle->where[] = [ |
|
| 1240 | - "'AND'", |
|
| 1241 | - [ |
|
| 1242 | - "'>='", |
|
| 1243 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1244 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1245 | - ], |
|
| 1246 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1247 | - ]; |
|
| 1248 | - } |
|
| 1249 | - // sinon on prend tout |
|
| 1144 | + $params = $crit->param; |
|
| 1145 | + |
|
| 1146 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1147 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + $boucle = &$boucles[$idb]; |
|
| 1151 | + $parent = $boucle->id_parent; |
|
| 1152 | + $fields = $boucle->show['field']; |
|
| 1153 | + |
|
| 1154 | + $date = array_shift($params); |
|
| 1155 | + $type = array_shift($params); |
|
| 1156 | + |
|
| 1157 | + // la valeur $type doit etre connue a la compilation |
|
| 1158 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1159 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1160 | + |
|
| 1161 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1162 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1163 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1164 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1165 | + if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1166 | + $date = $date[0]->texte; |
|
| 1167 | + if (!isset($fields[$date])) { |
|
| 1168 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1169 | + } |
|
| 1170 | + } else { |
|
| 1171 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1172 | + $noms = array_keys($fields); |
|
| 1173 | + $defaut = $noms[0]; |
|
| 1174 | + $noms = join(' ', $noms); |
|
| 1175 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1176 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1177 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1178 | + } |
|
| 1179 | + $annee = $params ? array_shift($params) : ''; |
|
| 1180 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1181 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1182 | + ') ? $x : date("Y"))'; |
|
| 1183 | + |
|
| 1184 | + $mois = $params ? array_shift($params) : ''; |
|
| 1185 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1186 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1187 | + ') ? $x : date("m"))'; |
|
| 1188 | + |
|
| 1189 | + $jour = $params ? array_shift($params) : ''; |
|
| 1190 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1191 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1192 | + ') ? $x : date("d"))'; |
|
| 1193 | + |
|
| 1194 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1195 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1196 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1197 | + ') ? $x : date("Y"))'; |
|
| 1198 | + |
|
| 1199 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1200 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1201 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1202 | + ') ? $x : date("m"))'; |
|
| 1203 | + |
|
| 1204 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1205 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1206 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1207 | + ') ? $x : date("d"))'; |
|
| 1208 | + |
|
| 1209 | + $date = $boucle->id_table . ".$date"; |
|
| 1210 | + |
|
| 1211 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1212 | + if ($type == 'jour') { |
|
| 1213 | + $boucle->where[] = [ |
|
| 1214 | + "'='", |
|
| 1215 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1216 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1217 | + ]; |
|
| 1218 | + } elseif ($type == 'mois') { |
|
| 1219 | + $boucle->where[] = [ |
|
| 1220 | + "'='", |
|
| 1221 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1222 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1223 | + ]; |
|
| 1224 | + } elseif ($type == 'semaine') { |
|
| 1225 | + $boucle->where[] = [ |
|
| 1226 | + "'AND'", |
|
| 1227 | + [ |
|
| 1228 | + "'>='", |
|
| 1229 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1230 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1231 | + ], |
|
| 1232 | + [ |
|
| 1233 | + "'<='", |
|
| 1234 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1235 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1236 | + ] |
|
| 1237 | + ]; |
|
| 1238 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1239 | + $boucle->where[] = [ |
|
| 1240 | + "'AND'", |
|
| 1241 | + [ |
|
| 1242 | + "'>='", |
|
| 1243 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1244 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1245 | + ], |
|
| 1246 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1247 | + ]; |
|
| 1248 | + } |
|
| 1249 | + // sinon on prend tout |
|
| 1250 | 1250 | } |
| 1251 | 1251 | |
| 1252 | 1252 | |
@@ -1271,33 +1271,33 @@ discard block |
||
| 1271 | 1271 | * @return void |
| 1272 | 1272 | **/ |
| 1273 | 1273 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1274 | - $boucle = &$boucles[$idb]; |
|
| 1275 | - $a1 = $crit->param[0]; |
|
| 1276 | - $a2 = $crit->param[1]; |
|
| 1277 | - $op = $crit->op; |
|
| 1278 | - |
|
| 1279 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1280 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1281 | - |
|
| 1282 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1283 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1284 | - } else { |
|
| 1285 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1286 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1287 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1288 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1289 | - $mode = (($op == '/') ? '/' : |
|
| 1290 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1291 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1292 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1293 | - $boucle->limit = |
|
| 1294 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1295 | - . ".','." |
|
| 1296 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1297 | - } else { |
|
| 1298 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1299 | - } |
|
| 1300 | - } |
|
| 1274 | + $boucle = &$boucles[$idb]; |
|
| 1275 | + $a1 = $crit->param[0]; |
|
| 1276 | + $a2 = $crit->param[1]; |
|
| 1277 | + $op = $crit->op; |
|
| 1278 | + |
|
| 1279 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1280 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1281 | + |
|
| 1282 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1283 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1284 | + } else { |
|
| 1285 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1286 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1287 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1288 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1289 | + $mode = (($op == '/') ? '/' : |
|
| 1290 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1291 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1292 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1293 | + $boucle->limit = |
|
| 1294 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1295 | + . ".','." |
|
| 1296 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1297 | + } else { |
|
| 1298 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1299 | + } |
|
| 1300 | + } |
|
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | 1303 | /** |
@@ -1325,63 +1325,63 @@ discard block |
||
| 1325 | 1325 | * @return void |
| 1326 | 1326 | **/ |
| 1327 | 1327 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1328 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1329 | - |
|
| 1330 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1331 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1332 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1333 | - // {1/3} |
|
| 1334 | - if ($op1 == '/') { |
|
| 1335 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1336 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1337 | - "($total_parties ? $total_parties : 1)"; |
|
| 1338 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1339 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1340 | - } else { |
|
| 1341 | - // cas {n-1,x} |
|
| 1342 | - if ($op1 == '-') { |
|
| 1343 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - // cas {x,n-1} |
|
| 1347 | - if ($op2 == '-') { |
|
| 1348 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1349 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1350 | - ($total_parties . ' - 1')); |
|
| 1351 | - } else { |
|
| 1352 | - // {x,1} ou {pagination} |
|
| 1353 | - $fin = '$debut_boucle' |
|
| 1354 | - . (is_numeric($total_parties) ? |
|
| 1355 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1356 | - ('+' . $total_parties . ' - 1')); |
|
| 1357 | - } |
|
| 1358 | - |
|
| 1359 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1360 | - if ($op1 == 'p') { |
|
| 1361 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1362 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1363 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1364 | - } |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - // Notes : |
|
| 1368 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1369 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1370 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1371 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1372 | - |
|
| 1373 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1374 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1375 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1376 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1377 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1378 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1379 | - . "\n\tif (\$debut_boucle>0" |
|
| 1380 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1381 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1382 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1383 | - |
|
| 1384 | - $boucles[$id_boucle]->partie = " |
|
| 1328 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1329 | + |
|
| 1330 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1331 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1332 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1333 | + // {1/3} |
|
| 1334 | + if ($op1 == '/') { |
|
| 1335 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1336 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1337 | + "($total_parties ? $total_parties : 1)"; |
|
| 1338 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1339 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1340 | + } else { |
|
| 1341 | + // cas {n-1,x} |
|
| 1342 | + if ($op1 == '-') { |
|
| 1343 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + // cas {x,n-1} |
|
| 1347 | + if ($op2 == '-') { |
|
| 1348 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1349 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1350 | + ($total_parties . ' - 1')); |
|
| 1351 | + } else { |
|
| 1352 | + // {x,1} ou {pagination} |
|
| 1353 | + $fin = '$debut_boucle' |
|
| 1354 | + . (is_numeric($total_parties) ? |
|
| 1355 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1356 | + ('+' . $total_parties . ' - 1')); |
|
| 1357 | + } |
|
| 1358 | + |
|
| 1359 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1360 | + if ($op1 == 'p') { |
|
| 1361 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1362 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1363 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1364 | + } |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + // Notes : |
|
| 1368 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1369 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1370 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1371 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1372 | + |
|
| 1373 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1374 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1375 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1376 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1377 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1378 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1379 | + . "\n\tif (\$debut_boucle>0" |
|
| 1380 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1381 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1382 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1383 | + |
|
| 1384 | + $boucles[$id_boucle]->partie = " |
|
| 1385 | 1385 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1386 | 1386 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1387 | 1387 | } |
@@ -1398,26 +1398,26 @@ discard block |
||
| 1398 | 1398 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1399 | 1399 | **/ |
| 1400 | 1400 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1401 | - if ($param[0]->type != 'texte') { |
|
| 1402 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1403 | - if (isset($param[1]->texte)) { |
|
| 1404 | - preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1405 | - |
|
| 1406 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1407 | - } else { |
|
| 1408 | - return ["intval($a1)", 0]; |
|
| 1409 | - } |
|
| 1410 | - } else { |
|
| 1411 | - preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1412 | - $a1 = $m[1]; |
|
| 1413 | - if (empty($m[3])) { |
|
| 1414 | - return [$a1, 0]; |
|
| 1415 | - } elseif (!empty($m[4])) { |
|
| 1416 | - return [$a1, $m[4]]; |
|
| 1417 | - } else { |
|
| 1418 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1401 | + if ($param[0]->type != 'texte') { |
|
| 1402 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1403 | + if (isset($param[1]->texte)) { |
|
| 1404 | + preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1405 | + |
|
| 1406 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1407 | + } else { |
|
| 1408 | + return ["intval($a1)", 0]; |
|
| 1409 | + } |
|
| 1410 | + } else { |
|
| 1411 | + preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1412 | + $a1 = $m[1]; |
|
| 1413 | + if (empty($m[3])) { |
|
| 1414 | + return [$a1, 0]; |
|
| 1415 | + } elseif (!empty($m[4])) { |
|
| 1416 | + return [$a1, $m[4]]; |
|
| 1417 | + } else { |
|
| 1418 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | 1421 | } |
| 1422 | 1422 | |
| 1423 | 1423 | |
@@ -1444,47 +1444,47 @@ discard block |
||
| 1444 | 1444 | * array : Erreur sur un des critères |
| 1445 | 1445 | **/ |
| 1446 | 1446 | function calculer_criteres($idb, &$boucles) { |
| 1447 | - $msg = ''; |
|
| 1448 | - $boucle = $boucles[$idb]; |
|
| 1449 | - $table = strtoupper($boucle->type_requete); |
|
| 1450 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1451 | - |
|
| 1452 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1453 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1454 | - if (!is_array($boucle->criteres)) { |
|
| 1455 | - return []; |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - foreach ($boucle->criteres as $crit) { |
|
| 1459 | - $critere = $crit->op; |
|
| 1460 | - // critere personnalise ? |
|
| 1461 | - if ( |
|
| 1462 | - (!$serveur or |
|
| 1463 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1464 | - and (!function_exists($f = $f . '_dist')) |
|
| 1465 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1466 | - and (!function_exists($f = $f . '_dist')) |
|
| 1467 | - ) |
|
| 1468 | - ) |
|
| 1469 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1470 | - and (!function_exists($f = $f . '_dist')) |
|
| 1471 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1472 | - and (!function_exists($f = $f . '_dist')) |
|
| 1473 | - ) { |
|
| 1474 | - // fonction critere standard |
|
| 1475 | - $f = $defaut; |
|
| 1476 | - } |
|
| 1477 | - // compile le critere |
|
| 1478 | - $res = $f($idb, $boucles, $crit); |
|
| 1479 | - |
|
| 1480 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1481 | - if (is_array($res)) { |
|
| 1482 | - $msg = $res; |
|
| 1483 | - erreur_squelette($msg, $boucle); |
|
| 1484 | - } |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - return $msg; |
|
| 1447 | + $msg = ''; |
|
| 1448 | + $boucle = $boucles[$idb]; |
|
| 1449 | + $table = strtoupper($boucle->type_requete); |
|
| 1450 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1451 | + |
|
| 1452 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1453 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1454 | + if (!is_array($boucle->criteres)) { |
|
| 1455 | + return []; |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + foreach ($boucle->criteres as $crit) { |
|
| 1459 | + $critere = $crit->op; |
|
| 1460 | + // critere personnalise ? |
|
| 1461 | + if ( |
|
| 1462 | + (!$serveur or |
|
| 1463 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1464 | + and (!function_exists($f = $f . '_dist')) |
|
| 1465 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1466 | + and (!function_exists($f = $f . '_dist')) |
|
| 1467 | + ) |
|
| 1468 | + ) |
|
| 1469 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1470 | + and (!function_exists($f = $f . '_dist')) |
|
| 1471 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1472 | + and (!function_exists($f = $f . '_dist')) |
|
| 1473 | + ) { |
|
| 1474 | + // fonction critere standard |
|
| 1475 | + $f = $defaut; |
|
| 1476 | + } |
|
| 1477 | + // compile le critere |
|
| 1478 | + $res = $f($idb, $boucles, $crit); |
|
| 1479 | + |
|
| 1480 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1481 | + if (is_array($res)) { |
|
| 1482 | + $msg = $res; |
|
| 1483 | + erreur_squelette($msg, $boucle); |
|
| 1484 | + } |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + return $msg; |
|
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | 1490 | /** |
@@ -1499,11 +1499,11 @@ discard block |
||
| 1499 | 1499 | * @return string Code compilé rééchappé |
| 1500 | 1500 | */ |
| 1501 | 1501 | function kwote($lisp, $serveur = '', $type = '') { |
| 1502 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1503 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1504 | - } else { |
|
| 1505 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1506 | - } |
|
| 1502 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1503 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1504 | + } else { |
|
| 1505 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1506 | + } |
|
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | |
@@ -1522,81 +1522,81 @@ discard block |
||
| 1522 | 1522 | * @return void|array |
| 1523 | 1523 | **/ |
| 1524 | 1524 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1525 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1526 | - if (!$r) { |
|
| 1527 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1528 | - } |
|
| 1529 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1530 | - |
|
| 1531 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1532 | - |
|
| 1533 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1534 | - $where = $in; |
|
| 1535 | - if ($crit->cond) { |
|
| 1536 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1537 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1538 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1539 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1540 | - } |
|
| 1541 | - } |
|
| 1542 | - if ($crit->exclus) { |
|
| 1543 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1544 | - $where = ["'NOT'", $where]; |
|
| 1545 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1546 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1547 | - { |
|
| 1548 | - $where = [ |
|
| 1549 | - "'NOT'", |
|
| 1550 | - [ |
|
| 1551 | - "'IN'", |
|
| 1552 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1553 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1554 | - ] |
|
| 1555 | - ]; |
|
| 1556 | - } |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - $boucles[$idb]->where[] = $where; |
|
| 1560 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1561 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1562 | - } |
|
| 1525 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1526 | + if (!$r) { |
|
| 1527 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1528 | + } |
|
| 1529 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1530 | + |
|
| 1531 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1532 | + |
|
| 1533 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1534 | + $where = $in; |
|
| 1535 | + if ($crit->cond) { |
|
| 1536 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1537 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1538 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1539 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1540 | + } |
|
| 1541 | + } |
|
| 1542 | + if ($crit->exclus) { |
|
| 1543 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1544 | + $where = ["'NOT'", $where]; |
|
| 1545 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1546 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1547 | + { |
|
| 1548 | + $where = [ |
|
| 1549 | + "'NOT'", |
|
| 1550 | + [ |
|
| 1551 | + "'IN'", |
|
| 1552 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1553 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1554 | + ] |
|
| 1555 | + ]; |
|
| 1556 | + } |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + $boucles[$idb]->where[] = $where; |
|
| 1560 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1561 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1562 | + } |
|
| 1563 | 1563 | } |
| 1564 | 1564 | |
| 1565 | 1565 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1566 | - static $num = []; |
|
| 1567 | - $descr = $boucles[$idb]->descr; |
|
| 1568 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1569 | - |
|
| 1570 | - $var = '$in' . $cpt++; |
|
| 1571 | - $x = "\n\t$var = array();"; |
|
| 1572 | - foreach ($val as $k => $v) { |
|
| 1573 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1574 | - // optimiser le traitement des constantes |
|
| 1575 | - if (is_numeric($r[2])) { |
|
| 1576 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1577 | - } else { |
|
| 1578 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1579 | - } |
|
| 1580 | - } else { |
|
| 1581 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1582 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1583 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1584 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1585 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1586 | - } |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - $boucles[$idb]->in .= $x; |
|
| 1590 | - |
|
| 1591 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1592 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1593 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1594 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1595 | - if (!$crit2) { |
|
| 1596 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1566 | + static $num = []; |
|
| 1567 | + $descr = $boucles[$idb]->descr; |
|
| 1568 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1569 | + |
|
| 1570 | + $var = '$in' . $cpt++; |
|
| 1571 | + $x = "\n\t$var = array();"; |
|
| 1572 | + foreach ($val as $k => $v) { |
|
| 1573 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1574 | + // optimiser le traitement des constantes |
|
| 1575 | + if (is_numeric($r[2])) { |
|
| 1576 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1577 | + } else { |
|
| 1578 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1579 | + } |
|
| 1580 | + } else { |
|
| 1581 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1582 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1583 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1584 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1585 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1586 | + } |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + $boucles[$idb]->in .= $x; |
|
| 1590 | + |
|
| 1591 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1592 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1593 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1594 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1595 | + if (!$crit2) { |
|
| 1596 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | 1602 | /** |
@@ -1612,22 +1612,22 @@ discard block |
||
| 1612 | 1612 | * @return void |
| 1613 | 1613 | */ |
| 1614 | 1614 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1615 | - $boucle = &$boucles[$idb]; |
|
| 1616 | - if (isset($crit->param[0])) { |
|
| 1617 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1618 | - } else { |
|
| 1619 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - if ($crit->cond) { |
|
| 1623 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - if ($crit->not) { |
|
| 1627 | - $_where = "array('NOT',$_where)"; |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - $boucle->where[] = $_where; |
|
| 1615 | + $boucle = &$boucles[$idb]; |
|
| 1616 | + if (isset($crit->param[0])) { |
|
| 1617 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1618 | + } else { |
|
| 1619 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1620 | + } |
|
| 1621 | + |
|
| 1622 | + if ($crit->cond) { |
|
| 1623 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + if ($crit->not) { |
|
| 1627 | + $_where = "array('NOT',$_where)"; |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + $boucle->where[] = $_where; |
|
| 1631 | 1631 | } |
| 1632 | 1632 | |
| 1633 | 1633 | /** |
@@ -1655,31 +1655,31 @@ discard block |
||
| 1655 | 1655 | * @return void |
| 1656 | 1656 | */ |
| 1657 | 1657 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1658 | - /** @var Boucle $boucle */ |
|
| 1659 | - $boucle = $boucles[$idb]; |
|
| 1660 | - |
|
| 1661 | - $champs = lister_champs_id_conditionnel( |
|
| 1662 | - $boucle->show['table'], |
|
| 1663 | - $boucle->show, |
|
| 1664 | - $boucle->sql_serveur |
|
| 1665 | - ); |
|
| 1666 | - |
|
| 1667 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1668 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1669 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1670 | - } |
|
| 1671 | - // nous aider en mode debug. |
|
| 1672 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1673 | - $boucle->modificateur['id_'] = $champs; |
|
| 1674 | - |
|
| 1675 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1676 | - foreach ($champs as $champ) { |
|
| 1677 | - $critere_id_table = new Critere(); |
|
| 1678 | - $critere_id_table->op = $champ; |
|
| 1679 | - $critere_id_table->cond = '?'; |
|
| 1680 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1681 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1682 | - } |
|
| 1658 | + /** @var Boucle $boucle */ |
|
| 1659 | + $boucle = $boucles[$idb]; |
|
| 1660 | + |
|
| 1661 | + $champs = lister_champs_id_conditionnel( |
|
| 1662 | + $boucle->show['table'], |
|
| 1663 | + $boucle->show, |
|
| 1664 | + $boucle->sql_serveur |
|
| 1665 | + ); |
|
| 1666 | + |
|
| 1667 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1668 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1669 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1670 | + } |
|
| 1671 | + // nous aider en mode debug. |
|
| 1672 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1673 | + $boucle->modificateur['id_'] = $champs; |
|
| 1674 | + |
|
| 1675 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1676 | + foreach ($champs as $champ) { |
|
| 1677 | + $critere_id_table = new Critere(); |
|
| 1678 | + $critere_id_table->op = $champ; |
|
| 1679 | + $critere_id_table->cond = '?'; |
|
| 1680 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1681 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1682 | + } |
|
| 1683 | 1683 | } |
| 1684 | 1684 | |
| 1685 | 1685 | /** |
@@ -1699,75 +1699,75 @@ discard block |
||
| 1699 | 1699 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1700 | 1700 | */ |
| 1701 | 1701 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1702 | - // calculer la description de la table |
|
| 1703 | - if (!is_array($desc)) { |
|
| 1704 | - $desc = description_table($table, $serveur); |
|
| 1705 | - } |
|
| 1706 | - if (!$desc) { |
|
| 1707 | - return []; |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - // Les champs id_xx de la table demandée |
|
| 1711 | - $champs = array_filter( |
|
| 1712 | - array_keys($desc['field']), |
|
| 1713 | - fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1714 | - ); |
|
| 1715 | - |
|
| 1716 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1717 | - if ( |
|
| 1718 | - in_array('id_rubrique', $champs) |
|
| 1719 | - and !in_array('id_secteur', $champs) |
|
| 1720 | - ) { |
|
| 1721 | - $champs[] = 'id_secteur'; |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1725 | - if ($serveur) { |
|
| 1726 | - return $champs; |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - $primary = false; |
|
| 1730 | - $associable = false; |
|
| 1731 | - include_spip('action/editer_liens'); |
|
| 1732 | - |
|
| 1733 | - if (isset($desc['type'])) { |
|
| 1734 | - $primary = id_table_objet($desc['type']); |
|
| 1735 | - $associable = objet_associable($desc['type']); |
|
| 1736 | - } |
|
| 1737 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1738 | - $associable = true; |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - // liste de toutes les tables principales, sauf la notre |
|
| 1742 | - $tables = lister_tables_objets_sql(); |
|
| 1743 | - unset($tables[$table]); |
|
| 1744 | - |
|
| 1745 | - foreach ($tables as $_table => $_desc) { |
|
| 1746 | - if ( |
|
| 1747 | - $associable |
|
| 1748 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1749 | - or objet_associable($_desc['type']) |
|
| 1750 | - ) { |
|
| 1751 | - $champs[] = id_table_objet($_table); |
|
| 1752 | - } |
|
| 1753 | - } |
|
| 1754 | - $champs = array_values(array_unique($champs)); |
|
| 1755 | - |
|
| 1756 | - // Exclusions de certains id |
|
| 1757 | - $exclusions = pipeline( |
|
| 1758 | - 'exclure_id_conditionnel', |
|
| 1759 | - [ |
|
| 1760 | - 'args' => [ |
|
| 1761 | - 'table' => $table, |
|
| 1762 | - 'id_table_objet' => $primary, |
|
| 1763 | - 'associable' => $associable, |
|
| 1764 | - ], |
|
| 1765 | - 'data' => [], |
|
| 1766 | - ] |
|
| 1767 | - ); |
|
| 1768 | - $champs = array_diff($champs, $exclusions); |
|
| 1769 | - |
|
| 1770 | - return $champs; |
|
| 1702 | + // calculer la description de la table |
|
| 1703 | + if (!is_array($desc)) { |
|
| 1704 | + $desc = description_table($table, $serveur); |
|
| 1705 | + } |
|
| 1706 | + if (!$desc) { |
|
| 1707 | + return []; |
|
| 1708 | + } |
|
| 1709 | + |
|
| 1710 | + // Les champs id_xx de la table demandée |
|
| 1711 | + $champs = array_filter( |
|
| 1712 | + array_keys($desc['field']), |
|
| 1713 | + fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1714 | + ); |
|
| 1715 | + |
|
| 1716 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1717 | + if ( |
|
| 1718 | + in_array('id_rubrique', $champs) |
|
| 1719 | + and !in_array('id_secteur', $champs) |
|
| 1720 | + ) { |
|
| 1721 | + $champs[] = 'id_secteur'; |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1725 | + if ($serveur) { |
|
| 1726 | + return $champs; |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + $primary = false; |
|
| 1730 | + $associable = false; |
|
| 1731 | + include_spip('action/editer_liens'); |
|
| 1732 | + |
|
| 1733 | + if (isset($desc['type'])) { |
|
| 1734 | + $primary = id_table_objet($desc['type']); |
|
| 1735 | + $associable = objet_associable($desc['type']); |
|
| 1736 | + } |
|
| 1737 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1738 | + $associable = true; |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + // liste de toutes les tables principales, sauf la notre |
|
| 1742 | + $tables = lister_tables_objets_sql(); |
|
| 1743 | + unset($tables[$table]); |
|
| 1744 | + |
|
| 1745 | + foreach ($tables as $_table => $_desc) { |
|
| 1746 | + if ( |
|
| 1747 | + $associable |
|
| 1748 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1749 | + or objet_associable($_desc['type']) |
|
| 1750 | + ) { |
|
| 1751 | + $champs[] = id_table_objet($_table); |
|
| 1752 | + } |
|
| 1753 | + } |
|
| 1754 | + $champs = array_values(array_unique($champs)); |
|
| 1755 | + |
|
| 1756 | + // Exclusions de certains id |
|
| 1757 | + $exclusions = pipeline( |
|
| 1758 | + 'exclure_id_conditionnel', |
|
| 1759 | + [ |
|
| 1760 | + 'args' => [ |
|
| 1761 | + 'table' => $table, |
|
| 1762 | + 'id_table_objet' => $primary, |
|
| 1763 | + 'associable' => $associable, |
|
| 1764 | + ], |
|
| 1765 | + 'data' => [], |
|
| 1766 | + ] |
|
| 1767 | + ); |
|
| 1768 | + $champs = array_diff($champs, $exclusions); |
|
| 1769 | + |
|
| 1770 | + return $champs; |
|
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | 1773 | /** |
@@ -1822,28 +1822,28 @@ discard block |
||
| 1822 | 1822 | * @return void |
| 1823 | 1823 | */ |
| 1824 | 1824 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1825 | - $boucle = &$boucles[$idb]; |
|
| 1826 | - |
|
| 1827 | - // definition du champ par defaut |
|
| 1828 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1829 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1830 | - $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1831 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1832 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1833 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1834 | - |
|
| 1835 | - $_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):'')"; |
|
| 1836 | - |
|
| 1837 | - $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1838 | - $_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)"; |
|
| 1839 | - |
|
| 1840 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1841 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1842 | - $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1843 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1844 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1845 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1846 | - $boucle->hash .= " |
|
| 1825 | + $boucle = &$boucles[$idb]; |
|
| 1826 | + |
|
| 1827 | + // definition du champ par defaut |
|
| 1828 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1829 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1830 | + $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1831 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1832 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1833 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1834 | + |
|
| 1835 | + $_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):'')"; |
|
| 1836 | + |
|
| 1837 | + $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1838 | + $_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)"; |
|
| 1839 | + |
|
| 1840 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1841 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1842 | + $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1843 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1844 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1845 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1846 | + $boucle->hash .= " |
|
| 1847 | 1847 | \$senstri = ''; |
| 1848 | 1848 | \$tri = $_tri; |
| 1849 | 1849 | if (\$tri){ |
@@ -1851,8 +1851,8 @@ discard block |
||
| 1851 | 1851 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1852 | 1852 | }; |
| 1853 | 1853 | "; |
| 1854 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1855 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1854 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1855 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1856 | 1856 | } |
| 1857 | 1857 | |
| 1858 | 1858 | # Criteres de comparaison |
@@ -1869,20 +1869,20 @@ discard block |
||
| 1869 | 1869 | * @return void|array |
| 1870 | 1870 | **/ |
| 1871 | 1871 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1872 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1873 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1874 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1878 | - if (!$r) { |
|
| 1879 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1880 | - # if (!$crit->cond) { |
|
| 1881 | - return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1882 | - # } |
|
| 1883 | - } else { |
|
| 1884 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1885 | - } |
|
| 1872 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1873 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1874 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1878 | + if (!$r) { |
|
| 1879 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1880 | + # if (!$crit->cond) { |
|
| 1881 | + return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1882 | + # } |
|
| 1883 | + } else { |
|
| 1884 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1885 | + } |
|
| 1886 | 1886 | } |
| 1887 | 1887 | |
| 1888 | 1888 | |
@@ -1902,62 +1902,62 @@ discard block |
||
| 1902 | 1902 | * @return void |
| 1903 | 1903 | **/ |
| 1904 | 1904 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1905 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1906 | - |
|
| 1907 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1908 | - |
|
| 1909 | - // inserer la negation (cf !...) |
|
| 1910 | - |
|
| 1911 | - if ($crit->not) { |
|
| 1912 | - $where = ["'NOT'", $where]; |
|
| 1913 | - } |
|
| 1914 | - if ($crit->exclus) { |
|
| 1915 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1916 | - $where = ["'NOT'", $where]; |
|
| 1917 | - } else { |
|
| 1918 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1919 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1920 | - $where = [ |
|
| 1921 | - "'NOT'", |
|
| 1922 | - [ |
|
| 1923 | - "'IN'", |
|
| 1924 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1925 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1926 | - ] |
|
| 1927 | - ]; |
|
| 1928 | - } |
|
| 1929 | - } |
|
| 1930 | - |
|
| 1931 | - // inserer la condition (cf {lang?}) |
|
| 1932 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1933 | - if ($crit->cond) { |
|
| 1934 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1935 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1936 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1937 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1938 | - } |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - if ($op === '=' and !$crit->not) { |
|
| 1942 | - $where = [ |
|
| 1943 | - "'?'", |
|
| 1944 | - "(is_array($pred))", |
|
| 1945 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1946 | - $where |
|
| 1947 | - ]; |
|
| 1948 | - } |
|
| 1949 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1950 | - if ($where_complement) { |
|
| 1951 | - // condition annexe du type "AND (objet='article')" |
|
| 1952 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1953 | - } |
|
| 1954 | - } |
|
| 1955 | - |
|
| 1956 | - $boucles[$idb]->where[] = $where; |
|
| 1957 | - if ($where_complement) { |
|
| 1958 | - // condition annexe du type "AND (objet='article')" |
|
| 1959 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1960 | - } |
|
| 1905 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1906 | + |
|
| 1907 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1908 | + |
|
| 1909 | + // inserer la negation (cf !...) |
|
| 1910 | + |
|
| 1911 | + if ($crit->not) { |
|
| 1912 | + $where = ["'NOT'", $where]; |
|
| 1913 | + } |
|
| 1914 | + if ($crit->exclus) { |
|
| 1915 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1916 | + $where = ["'NOT'", $where]; |
|
| 1917 | + } else { |
|
| 1918 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1919 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1920 | + $where = [ |
|
| 1921 | + "'NOT'", |
|
| 1922 | + [ |
|
| 1923 | + "'IN'", |
|
| 1924 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1925 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1926 | + ] |
|
| 1927 | + ]; |
|
| 1928 | + } |
|
| 1929 | + } |
|
| 1930 | + |
|
| 1931 | + // inserer la condition (cf {lang?}) |
|
| 1932 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1933 | + if ($crit->cond) { |
|
| 1934 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1935 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1936 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1937 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1938 | + } |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + if ($op === '=' and !$crit->not) { |
|
| 1942 | + $where = [ |
|
| 1943 | + "'?'", |
|
| 1944 | + "(is_array($pred))", |
|
| 1945 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1946 | + $where |
|
| 1947 | + ]; |
|
| 1948 | + } |
|
| 1949 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1950 | + if ($where_complement) { |
|
| 1951 | + // condition annexe du type "AND (objet='article')" |
|
| 1952 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1953 | + } |
|
| 1954 | + } |
|
| 1955 | + |
|
| 1956 | + $boucles[$idb]->where[] = $where; |
|
| 1957 | + if ($where_complement) { |
|
| 1958 | + // condition annexe du type "AND (objet='article')" |
|
| 1959 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1960 | + } |
|
| 1961 | 1961 | } |
| 1962 | 1962 | |
| 1963 | 1963 | |
@@ -1998,165 +1998,165 @@ discard block |
||
| 1998 | 1998 | **/ |
| 1999 | 1999 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2000 | 2000 | |
| 2001 | - $boucle = &$boucles[$idb]; |
|
| 2002 | - $type = $boucle->type_requete; |
|
| 2003 | - $table = $boucle->id_table; |
|
| 2004 | - $desc = $boucle->show; |
|
| 2005 | - $col_vraie = null; |
|
| 2006 | - |
|
| 2007 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2008 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2009 | - |
|
| 2010 | - $col_alias = $col; |
|
| 2011 | - $where_complement = false; |
|
| 2012 | - |
|
| 2013 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2014 | - if ($col == 'id_enfant') { |
|
| 2015 | - $col = $boucle->primary; |
|
| 2016 | - } |
|
| 2017 | - |
|
| 2018 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2019 | - if ( |
|
| 2020 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2021 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2022 | - ) { |
|
| 2023 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2024 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2025 | - else { |
|
| 2026 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2027 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2031 | - // sauf si exception declaree : sauter cette etape |
|
| 2032 | - else { |
|
| 2033 | - if ( |
|
| 2034 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2035 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2036 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2037 | - ) { |
|
| 2038 | - $e = decompose_champ_id_objet($col); |
|
| 2039 | - $col = array_shift($e); |
|
| 2040 | - $where_complement = primary_doublee($e, $table); |
|
| 2041 | - } // Cas particulier : expressions de date |
|
| 2042 | - else { |
|
| 2043 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2044 | - [$col, $col_vraie] = $c; |
|
| 2045 | - $table = ''; |
|
| 2046 | - } // table explicitée {mots.titre} |
|
| 2047 | - else { |
|
| 2048 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2049 | - [, $table, $col] = $r; |
|
| 2050 | - $col_alias = $col; |
|
| 2051 | - |
|
| 2052 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2053 | - if ( |
|
| 2054 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2055 | - and isset($desc['field'][$col]) |
|
| 2056 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2057 | - ) { |
|
| 2058 | - $table = $cle; |
|
| 2059 | - } else { |
|
| 2060 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2061 | - } |
|
| 2062 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2063 | - if (!$table) { |
|
| 2064 | - return ''; |
|
| 2065 | - } |
|
| 2066 | - } |
|
| 2067 | - // si le champ n'est pas trouvé dans la table, |
|
| 2068 | - // on cherche si une jointure peut l'obtenir |
|
| 2069 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2070 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2071 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2072 | - $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2073 | - } |
|
| 2074 | - else { |
|
| 2075 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2076 | - if (!$r) { |
|
| 2077 | - return ''; |
|
| 2078 | - } |
|
| 2079 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2080 | - } |
|
| 2081 | - } |
|
| 2082 | - } |
|
| 2083 | - } |
|
| 2084 | - } |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2088 | - // Dans tous les cas, |
|
| 2089 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2090 | - // et passer dans sql_quote avec le type si connu |
|
| 2091 | - // et int sinon si la valeur est numerique |
|
| 2092 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2093 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2094 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2095 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2096 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2097 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2098 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2099 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2100 | - } |
|
| 2101 | - // sinon expliciter les |
|
| 2102 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2103 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2104 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2105 | - // sans toucher aux |
|
| 2106 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2107 | - // sql_quote(truc,'','varchar') |
|
| 2108 | - elseif ( |
|
| 2109 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2110 | - // si pas deja un type |
|
| 2111 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2112 | - ) { |
|
| 2113 | - $r = $r[1] |
|
| 2114 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2115 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2116 | - $val[0] = "sql_quote($r)"; |
|
| 2117 | - } |
|
| 2118 | - elseif ( |
|
| 2119 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2120 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2121 | - ) { |
|
| 2122 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2123 | - } |
|
| 2124 | - } |
|
| 2125 | - |
|
| 2126 | - if ( |
|
| 2127 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2128 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2129 | - ) { |
|
| 2130 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2131 | - } |
|
| 2132 | - |
|
| 2133 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2134 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2135 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2136 | - if ($table === $boucle->id_table) { |
|
| 2137 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2138 | - if ($col_alias != $col_vraie) { |
|
| 2139 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2140 | - } |
|
| 2141 | - } |
|
| 2142 | - |
|
| 2143 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2144 | - if ($table) { |
|
| 2145 | - if ($col[0] == '`') { |
|
| 2146 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2147 | - } else { |
|
| 2148 | - $arg = "$table.$col"; |
|
| 2149 | - } |
|
| 2150 | - } else { |
|
| 2151 | - $arg = $col; |
|
| 2152 | - } |
|
| 2153 | - |
|
| 2154 | - // inserer la fonction SQL |
|
| 2155 | - if ($fct) { |
|
| 2156 | - $arg = "$fct($arg$args_sql)"; |
|
| 2157 | - } |
|
| 2158 | - |
|
| 2159 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2001 | + $boucle = &$boucles[$idb]; |
|
| 2002 | + $type = $boucle->type_requete; |
|
| 2003 | + $table = $boucle->id_table; |
|
| 2004 | + $desc = $boucle->show; |
|
| 2005 | + $col_vraie = null; |
|
| 2006 | + |
|
| 2007 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2008 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2009 | + |
|
| 2010 | + $col_alias = $col; |
|
| 2011 | + $where_complement = false; |
|
| 2012 | + |
|
| 2013 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2014 | + if ($col == 'id_enfant') { |
|
| 2015 | + $col = $boucle->primary; |
|
| 2016 | + } |
|
| 2017 | + |
|
| 2018 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2019 | + if ( |
|
| 2020 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2021 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2022 | + ) { |
|
| 2023 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2024 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2025 | + else { |
|
| 2026 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2027 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2028 | + } |
|
| 2029 | + |
|
| 2030 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2031 | + // sauf si exception declaree : sauter cette etape |
|
| 2032 | + else { |
|
| 2033 | + if ( |
|
| 2034 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2035 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2036 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2037 | + ) { |
|
| 2038 | + $e = decompose_champ_id_objet($col); |
|
| 2039 | + $col = array_shift($e); |
|
| 2040 | + $where_complement = primary_doublee($e, $table); |
|
| 2041 | + } // Cas particulier : expressions de date |
|
| 2042 | + else { |
|
| 2043 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2044 | + [$col, $col_vraie] = $c; |
|
| 2045 | + $table = ''; |
|
| 2046 | + } // table explicitée {mots.titre} |
|
| 2047 | + else { |
|
| 2048 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2049 | + [, $table, $col] = $r; |
|
| 2050 | + $col_alias = $col; |
|
| 2051 | + |
|
| 2052 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2053 | + if ( |
|
| 2054 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2055 | + and isset($desc['field'][$col]) |
|
| 2056 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2057 | + ) { |
|
| 2058 | + $table = $cle; |
|
| 2059 | + } else { |
|
| 2060 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2061 | + } |
|
| 2062 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2063 | + if (!$table) { |
|
| 2064 | + return ''; |
|
| 2065 | + } |
|
| 2066 | + } |
|
| 2067 | + // si le champ n'est pas trouvé dans la table, |
|
| 2068 | + // on cherche si une jointure peut l'obtenir |
|
| 2069 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2070 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2071 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2072 | + $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2073 | + } |
|
| 2074 | + else { |
|
| 2075 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2076 | + if (!$r) { |
|
| 2077 | + return ''; |
|
| 2078 | + } |
|
| 2079 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2080 | + } |
|
| 2081 | + } |
|
| 2082 | + } |
|
| 2083 | + } |
|
| 2084 | + } |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2088 | + // Dans tous les cas, |
|
| 2089 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2090 | + // et passer dans sql_quote avec le type si connu |
|
| 2091 | + // et int sinon si la valeur est numerique |
|
| 2092 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2093 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2094 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2095 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2096 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2097 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2098 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2099 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2100 | + } |
|
| 2101 | + // sinon expliciter les |
|
| 2102 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2103 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2104 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2105 | + // sans toucher aux |
|
| 2106 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2107 | + // sql_quote(truc,'','varchar') |
|
| 2108 | + elseif ( |
|
| 2109 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2110 | + // si pas deja un type |
|
| 2111 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2112 | + ) { |
|
| 2113 | + $r = $r[1] |
|
| 2114 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2115 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2116 | + $val[0] = "sql_quote($r)"; |
|
| 2117 | + } |
|
| 2118 | + elseif ( |
|
| 2119 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2120 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2121 | + ) { |
|
| 2122 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2123 | + } |
|
| 2124 | + } |
|
| 2125 | + |
|
| 2126 | + if ( |
|
| 2127 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2128 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2129 | + ) { |
|
| 2130 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2131 | + } |
|
| 2132 | + |
|
| 2133 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2134 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2135 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2136 | + if ($table === $boucle->id_table) { |
|
| 2137 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2138 | + if ($col_alias != $col_vraie) { |
|
| 2139 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2140 | + } |
|
| 2141 | + } |
|
| 2142 | + |
|
| 2143 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2144 | + if ($table) { |
|
| 2145 | + if ($col[0] == '`') { |
|
| 2146 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2147 | + } else { |
|
| 2148 | + $arg = "$table.$col"; |
|
| 2149 | + } |
|
| 2150 | + } else { |
|
| 2151 | + $arg = $col; |
|
| 2152 | + } |
|
| 2153 | + |
|
| 2154 | + // inserer la fonction SQL |
|
| 2155 | + if ($fct) { |
|
| 2156 | + $arg = "$fct($arg$args_sql)"; |
|
| 2157 | + } |
|
| 2158 | + |
|
| 2159 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2160 | 2160 | } |
| 2161 | 2161 | |
| 2162 | 2162 | |
@@ -2185,77 +2185,77 @@ discard block |
||
| 2185 | 2185 | **/ |
| 2186 | 2186 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2187 | 2187 | |
| 2188 | - $where = ''; |
|
| 2189 | - |
|
| 2190 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2191 | - // gestion par les plugins des jointures tordues |
|
| 2192 | - // pas automatiques mais necessaires |
|
| 2193 | - $table_sql = table_objet_sql($table); |
|
| 2194 | - if ( |
|
| 2195 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2196 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2197 | - and |
|
| 2198 | - ( |
|
| 2199 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2200 | - or |
|
| 2201 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2202 | - ) |
|
| 2203 | - ) { |
|
| 2204 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2205 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2206 | - |
|
| 2207 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2208 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2209 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2210 | - [$t, $col] = $t[$col]; |
|
| 2211 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2212 | - [$calculer_critere_externe] = $index; |
|
| 2213 | - $t = $table; |
|
| 2214 | - } else { |
|
| 2215 | - $t = ''; |
|
| 2216 | - } // jointure non declaree. La trouver. |
|
| 2217 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2218 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2219 | - } else { |
|
| 2220 | - $t = ''; |
|
| 2221 | - } // jointure non declaree. La trouver. |
|
| 2222 | - |
|
| 2223 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2224 | - |
|
| 2225 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2226 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2227 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2228 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2229 | - $table = ''; |
|
| 2230 | - if ($boucle->jointures_explicites) { |
|
| 2231 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2232 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2233 | - } |
|
| 2234 | - |
|
| 2235 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2236 | - if (!$table) { |
|
| 2237 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - if (!$table) { |
|
| 2241 | - return ''; |
|
| 2242 | - } |
|
| 2243 | - |
|
| 2244 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2245 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2246 | - |
|
| 2247 | - if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2248 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2249 | - if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2250 | - $e = decompose_champ_id_objet($col); |
|
| 2251 | - $col = array_shift($e); |
|
| 2252 | - $where = primary_doublee($e, $table); |
|
| 2253 | - } else { |
|
| 2254 | - $col = reset($cle); |
|
| 2255 | - } |
|
| 2256 | - } |
|
| 2257 | - |
|
| 2258 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2188 | + $where = ''; |
|
| 2189 | + |
|
| 2190 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2191 | + // gestion par les plugins des jointures tordues |
|
| 2192 | + // pas automatiques mais necessaires |
|
| 2193 | + $table_sql = table_objet_sql($table); |
|
| 2194 | + if ( |
|
| 2195 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2196 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2197 | + and |
|
| 2198 | + ( |
|
| 2199 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2200 | + or |
|
| 2201 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2202 | + ) |
|
| 2203 | + ) { |
|
| 2204 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2205 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2206 | + |
|
| 2207 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2208 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2209 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2210 | + [$t, $col] = $t[$col]; |
|
| 2211 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2212 | + [$calculer_critere_externe] = $index; |
|
| 2213 | + $t = $table; |
|
| 2214 | + } else { |
|
| 2215 | + $t = ''; |
|
| 2216 | + } // jointure non declaree. La trouver. |
|
| 2217 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2218 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2219 | + } else { |
|
| 2220 | + $t = ''; |
|
| 2221 | + } // jointure non declaree. La trouver. |
|
| 2222 | + |
|
| 2223 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2224 | + |
|
| 2225 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2226 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2227 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2228 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2229 | + $table = ''; |
|
| 2230 | + if ($boucle->jointures_explicites) { |
|
| 2231 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2232 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2233 | + } |
|
| 2234 | + |
|
| 2235 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2236 | + if (!$table) { |
|
| 2237 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + if (!$table) { |
|
| 2241 | + return ''; |
|
| 2242 | + } |
|
| 2243 | + |
|
| 2244 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2245 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2246 | + |
|
| 2247 | + if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2248 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2249 | + if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2250 | + $e = decompose_champ_id_objet($col); |
|
| 2251 | + $col = array_shift($e); |
|
| 2252 | + $where = primary_doublee($e, $table); |
|
| 2253 | + } else { |
|
| 2254 | + $col = reset($cle); |
|
| 2255 | + } |
|
| 2256 | + } |
|
| 2257 | + |
|
| 2258 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2259 | 2259 | } |
| 2260 | 2260 | |
| 2261 | 2261 | |
@@ -2276,10 +2276,10 @@ discard block |
||
| 2276 | 2276 | * - valeur |
| 2277 | 2277 | **/ |
| 2278 | 2278 | function primary_doublee($decompose, $table) { |
| 2279 | - $e1 = reset($decompose); |
|
| 2280 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2279 | + $e1 = reset($decompose); |
|
| 2280 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2281 | 2281 | |
| 2282 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2282 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2283 | 2283 | } |
| 2284 | 2284 | |
| 2285 | 2285 | /** |
@@ -2310,57 +2310,57 @@ discard block |
||
| 2310 | 2310 | * Vide sinon. |
| 2311 | 2311 | */ |
| 2312 | 2312 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2313 | - // si on demande un truc du genre spip_mots |
|
| 2314 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2315 | - // et qu'on est la |
|
| 2316 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2317 | - if ( |
|
| 2318 | - $checkarrivee |
|
| 2319 | - and is_string($checkarrivee) |
|
| 2320 | - and $a = table_objet($checkarrivee) |
|
| 2321 | - and in_array($a . '_liens', $joints) |
|
| 2322 | - ) { |
|
| 2323 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2324 | - return $res; |
|
| 2325 | - } |
|
| 2326 | - } |
|
| 2327 | - foreach ($joints as $joint) { |
|
| 2328 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2329 | - // alias de table dans le from |
|
| 2330 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2331 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2332 | - $cols = $arrivee[2]; |
|
| 2333 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2334 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2335 | - array_pop($cols); |
|
| 2336 | - } |
|
| 2337 | - if ($t) { |
|
| 2338 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2339 | - $joindre = false; |
|
| 2340 | - foreach ($cols as $col) { |
|
| 2341 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2342 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2343 | - $joindre = true; |
|
| 2344 | - } else { |
|
| 2345 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2346 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2347 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2348 | - $joindre = true; |
|
| 2349 | - } |
|
| 2350 | - } |
|
| 2351 | - } |
|
| 2352 | - if (!$joindre) { |
|
| 2353 | - return $t; |
|
| 2354 | - } |
|
| 2355 | - } |
|
| 2356 | - array_pop($arrivee); |
|
| 2357 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2358 | - return $res; |
|
| 2359 | - } |
|
| 2360 | - } |
|
| 2361 | - } |
|
| 2362 | - |
|
| 2363 | - return ''; |
|
| 2313 | + // si on demande un truc du genre spip_mots |
|
| 2314 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2315 | + // et qu'on est la |
|
| 2316 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2317 | + if ( |
|
| 2318 | + $checkarrivee |
|
| 2319 | + and is_string($checkarrivee) |
|
| 2320 | + and $a = table_objet($checkarrivee) |
|
| 2321 | + and in_array($a . '_liens', $joints) |
|
| 2322 | + ) { |
|
| 2323 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2324 | + return $res; |
|
| 2325 | + } |
|
| 2326 | + } |
|
| 2327 | + foreach ($joints as $joint) { |
|
| 2328 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2329 | + // alias de table dans le from |
|
| 2330 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2331 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2332 | + $cols = $arrivee[2]; |
|
| 2333 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2334 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2335 | + array_pop($cols); |
|
| 2336 | + } |
|
| 2337 | + if ($t) { |
|
| 2338 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2339 | + $joindre = false; |
|
| 2340 | + foreach ($cols as $col) { |
|
| 2341 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2342 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2343 | + $joindre = true; |
|
| 2344 | + } else { |
|
| 2345 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2346 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2347 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2348 | + $joindre = true; |
|
| 2349 | + } |
|
| 2350 | + } |
|
| 2351 | + } |
|
| 2352 | + if (!$joindre) { |
|
| 2353 | + return $t; |
|
| 2354 | + } |
|
| 2355 | + } |
|
| 2356 | + array_pop($arrivee); |
|
| 2357 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2358 | + return $res; |
|
| 2359 | + } |
|
| 2360 | + } |
|
| 2361 | + } |
|
| 2362 | + |
|
| 2363 | + return ''; |
|
| 2364 | 2364 | } |
| 2365 | 2365 | |
| 2366 | 2366 | /** |
@@ -2386,35 +2386,35 @@ discard block |
||
| 2386 | 2386 | * Alias de la table de jointure (Lx) |
| 2387 | 2387 | */ |
| 2388 | 2388 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2389 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2390 | - |
|
| 2391 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2392 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2393 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2394 | - |
|
| 2395 | - if (!$intermediaire or !$arrivee) { |
|
| 2396 | - return ''; |
|
| 2397 | - } |
|
| 2398 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2399 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2400 | - |
|
| 2401 | - $res = fabrique_jointures( |
|
| 2402 | - $boucle, |
|
| 2403 | - [ |
|
| 2404 | - [ |
|
| 2405 | - $boucle->id_table, |
|
| 2406 | - $intermediaire, |
|
| 2407 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2408 | - ], |
|
| 2409 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2410 | - ], |
|
| 2411 | - $cond, |
|
| 2412 | - $desc, |
|
| 2413 | - $boucle->id_table, |
|
| 2414 | - [$col] |
|
| 2415 | - ); |
|
| 2416 | - |
|
| 2417 | - return $res; |
|
| 2389 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2390 | + |
|
| 2391 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2392 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2393 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2394 | + |
|
| 2395 | + if (!$intermediaire or !$arrivee) { |
|
| 2396 | + return ''; |
|
| 2397 | + } |
|
| 2398 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2399 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2400 | + |
|
| 2401 | + $res = fabrique_jointures( |
|
| 2402 | + $boucle, |
|
| 2403 | + [ |
|
| 2404 | + [ |
|
| 2405 | + $boucle->id_table, |
|
| 2406 | + $intermediaire, |
|
| 2407 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2408 | + ], |
|
| 2409 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2410 | + ], |
|
| 2411 | + $cond, |
|
| 2412 | + $desc, |
|
| 2413 | + $boucle->id_table, |
|
| 2414 | + [$col] |
|
| 2415 | + ); |
|
| 2416 | + |
|
| 2417 | + return $res; |
|
| 2418 | 2418 | } |
| 2419 | 2419 | |
| 2420 | 2420 | |
@@ -2431,17 +2431,17 @@ discard block |
||
| 2431 | 2431 | * false sinon. |
| 2432 | 2432 | **/ |
| 2433 | 2433 | function trouver_champ($champ, $where) { |
| 2434 | - if (!is_array($where)) { |
|
| 2435 | - return preg_match($champ, $where); |
|
| 2436 | - } else { |
|
| 2437 | - foreach ($where as $clause) { |
|
| 2438 | - if (trouver_champ($champ, $clause)) { |
|
| 2439 | - return true; |
|
| 2440 | - } |
|
| 2441 | - } |
|
| 2442 | - |
|
| 2443 | - return false; |
|
| 2444 | - } |
|
| 2434 | + if (!is_array($where)) { |
|
| 2435 | + return preg_match($champ, $where); |
|
| 2436 | + } else { |
|
| 2437 | + foreach ($where as $clause) { |
|
| 2438 | + if (trouver_champ($champ, $clause)) { |
|
| 2439 | + return true; |
|
| 2440 | + } |
|
| 2441 | + } |
|
| 2442 | + |
|
| 2443 | + return false; |
|
| 2444 | + } |
|
| 2445 | 2445 | } |
| 2446 | 2446 | |
| 2447 | 2447 | |
@@ -2467,129 +2467,129 @@ discard block |
||
| 2467 | 2467 | * - string $args_sql Suite des arguments du critère. ? |
| 2468 | 2468 | **/ |
| 2469 | 2469 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2470 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2471 | - if (count($crit->param) == 0) { |
|
| 2472 | - $op = '='; |
|
| 2473 | - $col = $val = $crit->op; |
|
| 2474 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2475 | - $val = $r[2]; |
|
| 2476 | - } |
|
| 2477 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2478 | - if ($val == 'lang') { |
|
| 2479 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2480 | - } else { |
|
| 2481 | - $defaut = null; |
|
| 2482 | - if ($val == 'id_parent') { |
|
| 2483 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2484 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2485 | - // pour eviter l'erreur SQL |
|
| 2486 | - $val = $boucles[$idb]->primary; |
|
| 2487 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2488 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2489 | - } elseif ($val == 'id_enfant') { |
|
| 2490 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2491 | - // de la boucle superieure |
|
| 2492 | - $val = 'id_parent'; |
|
| 2493 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2494 | - // un critere conditionnel sur date est traite a part |
|
| 2495 | - // car la date est mise d'office par SPIP, |
|
| 2496 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2497 | - } |
|
| 2498 | - |
|
| 2499 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2500 | - $val = [kwote($val)]; |
|
| 2501 | - } |
|
| 2502 | - } else { |
|
| 2503 | - // comparaison explicite |
|
| 2504 | - // le phraseur impose que le premier param soit du texte |
|
| 2505 | - $params = $crit->param; |
|
| 2506 | - $op = $crit->op; |
|
| 2507 | - if ($op == '==') { |
|
| 2508 | - $op = 'REGEXP'; |
|
| 2509 | - } |
|
| 2510 | - $col = array_shift($params); |
|
| 2511 | - $col = $col[0]->texte; |
|
| 2512 | - |
|
| 2513 | - $val = []; |
|
| 2514 | - $parent = $boucles[$idb]->id_parent; |
|
| 2515 | - |
|
| 2516 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2517 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2518 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2519 | - if ( |
|
| 2520 | - count($params) == 1 |
|
| 2521 | - and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2522 | - and $params[0][0]->type == 'texte' |
|
| 2523 | - and $params[0][2]->type == 'texte' |
|
| 2524 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2525 | - and (($p == "'") or ($p == '"')) |
|
| 2526 | - and $params[0][1]->type == 'champ' |
|
| 2527 | - ) { |
|
| 2528 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2529 | - } else { |
|
| 2530 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2531 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2532 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2533 | - $val[] = $a; |
|
| 2534 | - } else { |
|
| 2535 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2536 | - } // toujours quoter en char ici |
|
| 2537 | - } |
|
| 2538 | - } |
|
| 2539 | - } |
|
| 2540 | - |
|
| 2541 | - $fct = $args_sql = ''; |
|
| 2542 | - // fonction SQL ? |
|
| 2543 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2544 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2545 | - $fct = $m[1]; |
|
| 2546 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2547 | - $col = $a[1]; |
|
| 2548 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2549 | - $col = $m[1]; |
|
| 2550 | - $args_sql = $m[2]; |
|
| 2551 | - } |
|
| 2552 | - $args_sql .= $a[2]; |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2470 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2471 | + if (count($crit->param) == 0) { |
|
| 2472 | + $op = '='; |
|
| 2473 | + $col = $val = $crit->op; |
|
| 2474 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2475 | + $val = $r[2]; |
|
| 2476 | + } |
|
| 2477 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2478 | + if ($val == 'lang') { |
|
| 2479 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2480 | + } else { |
|
| 2481 | + $defaut = null; |
|
| 2482 | + if ($val == 'id_parent') { |
|
| 2483 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2484 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2485 | + // pour eviter l'erreur SQL |
|
| 2486 | + $val = $boucles[$idb]->primary; |
|
| 2487 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2488 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2489 | + } elseif ($val == 'id_enfant') { |
|
| 2490 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2491 | + // de la boucle superieure |
|
| 2492 | + $val = 'id_parent'; |
|
| 2493 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2494 | + // un critere conditionnel sur date est traite a part |
|
| 2495 | + // car la date est mise d'office par SPIP, |
|
| 2496 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2497 | + } |
|
| 2498 | + |
|
| 2499 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2500 | + $val = [kwote($val)]; |
|
| 2501 | + } |
|
| 2502 | + } else { |
|
| 2503 | + // comparaison explicite |
|
| 2504 | + // le phraseur impose que le premier param soit du texte |
|
| 2505 | + $params = $crit->param; |
|
| 2506 | + $op = $crit->op; |
|
| 2507 | + if ($op == '==') { |
|
| 2508 | + $op = 'REGEXP'; |
|
| 2509 | + } |
|
| 2510 | + $col = array_shift($params); |
|
| 2511 | + $col = $col[0]->texte; |
|
| 2512 | + |
|
| 2513 | + $val = []; |
|
| 2514 | + $parent = $boucles[$idb]->id_parent; |
|
| 2515 | + |
|
| 2516 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2517 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2518 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2519 | + if ( |
|
| 2520 | + count($params) == 1 |
|
| 2521 | + and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2522 | + and $params[0][0]->type == 'texte' |
|
| 2523 | + and $params[0][2]->type == 'texte' |
|
| 2524 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2525 | + and (($p == "'") or ($p == '"')) |
|
| 2526 | + and $params[0][1]->type == 'champ' |
|
| 2527 | + ) { |
|
| 2528 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2529 | + } else { |
|
| 2530 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2531 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2532 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2533 | + $val[] = $a; |
|
| 2534 | + } else { |
|
| 2535 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2536 | + } // toujours quoter en char ici |
|
| 2537 | + } |
|
| 2538 | + } |
|
| 2539 | + } |
|
| 2540 | + |
|
| 2541 | + $fct = $args_sql = ''; |
|
| 2542 | + // fonction SQL ? |
|
| 2543 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2544 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2545 | + $fct = $m[1]; |
|
| 2546 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2547 | + $col = $a[1]; |
|
| 2548 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2549 | + $col = $m[1]; |
|
| 2550 | + $args_sql = $m[2]; |
|
| 2551 | + } |
|
| 2552 | + $args_sql .= $a[2]; |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2556 | 2556 | } |
| 2557 | 2557 | |
| 2558 | 2558 | // compatibilite ancienne version |
| 2559 | 2559 | |
| 2560 | 2560 | function calculer_vieux_in($params) { |
| 2561 | - $deb = $params[0][0]; |
|
| 2562 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2563 | - $last = $params[$k]; |
|
| 2564 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2565 | - $last = $last[$j]; |
|
| 2566 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2567 | - |
|
| 2568 | - if ( |
|
| 2569 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2570 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2571 | - ) { |
|
| 2572 | - return $params; |
|
| 2573 | - } |
|
| 2574 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2575 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2576 | - $last = $params[$k][$j]; |
|
| 2577 | - $n = strlen($last->texte); |
|
| 2578 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2579 | - $newp = []; |
|
| 2580 | - foreach ($params as $v) { |
|
| 2581 | - if ($v[0]->type != 'texte') { |
|
| 2582 | - $newp[] = $v; |
|
| 2583 | - } else { |
|
| 2584 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2585 | - $t = new Texte(); |
|
| 2586 | - $t->texte = $x; |
|
| 2587 | - $newp[] = [$t]; |
|
| 2588 | - } |
|
| 2589 | - } |
|
| 2590 | - } |
|
| 2591 | - |
|
| 2592 | - return $newp; |
|
| 2561 | + $deb = $params[0][0]; |
|
| 2562 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2563 | + $last = $params[$k]; |
|
| 2564 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2565 | + $last = $last[$j]; |
|
| 2566 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2567 | + |
|
| 2568 | + if ( |
|
| 2569 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2570 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2571 | + ) { |
|
| 2572 | + return $params; |
|
| 2573 | + } |
|
| 2574 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2575 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2576 | + $last = $params[$k][$j]; |
|
| 2577 | + $n = strlen($last->texte); |
|
| 2578 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2579 | + $newp = []; |
|
| 2580 | + foreach ($params as $v) { |
|
| 2581 | + if ($v[0]->type != 'texte') { |
|
| 2582 | + $newp[] = $v; |
|
| 2583 | + } else { |
|
| 2584 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2585 | + $t = new Texte(); |
|
| 2586 | + $t->texte = $x; |
|
| 2587 | + $newp[] = [$t]; |
|
| 2588 | + } |
|
| 2589 | + } |
|
| 2590 | + } |
|
| 2591 | + |
|
| 2592 | + return $newp; |
|
| 2593 | 2593 | } |
| 2594 | 2594 | |
| 2595 | 2595 | /** |
@@ -2608,95 +2608,95 @@ discard block |
||
| 2608 | 2608 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2609 | 2609 | **/ |
| 2610 | 2610 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2611 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2612 | - return ''; |
|
| 2613 | - } |
|
| 2614 | - |
|
| 2615 | - $boucle = $boucles[$idb]; |
|
| 2616 | - $table = $boucle->show; |
|
| 2617 | - |
|
| 2618 | - // si c'est une colonne de la table, ne rien faire |
|
| 2619 | - if (isset($table['field'][$col])) { |
|
| 2620 | - return ''; |
|
| 2621 | - } |
|
| 2622 | - |
|
| 2623 | - // Le type de critère à prendre en compte |
|
| 2624 | - $col = $regs[1]; |
|
| 2625 | - |
|
| 2626 | - // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2627 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2628 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2629 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2630 | - if (isset($table['field']["date$suite"])) { |
|
| 2631 | - $date_orig = 'date' . $suite; |
|
| 2632 | - } else { |
|
| 2633 | - $date_orig = substr($suite, 1); |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - $pred = $date_orig; |
|
| 2637 | - } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2638 | - // Si aucune déclaration trouvée, on quitte |
|
| 2639 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2640 | - return ''; |
|
| 2641 | - } |
|
| 2642 | - // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2643 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2644 | - |
|
| 2645 | - // Si c'est pour du relatif |
|
| 2646 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2647 | - $pred = 'date'; |
|
| 2648 | - } |
|
| 2649 | - } |
|
| 2650 | - |
|
| 2651 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2652 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2653 | - ") . '\""; |
|
| 2654 | - |
|
| 2655 | - $col_vraie = $date_orig; |
|
| 2656 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2657 | - |
|
| 2658 | - switch ($col) { |
|
| 2659 | - case 'date': |
|
| 2660 | - $col = $date_orig; |
|
| 2661 | - break; |
|
| 2662 | - case 'jour': |
|
| 2663 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2664 | - break; |
|
| 2665 | - case 'mois': |
|
| 2666 | - $col = "MONTH($date_orig)"; |
|
| 2667 | - break; |
|
| 2668 | - case 'annee': |
|
| 2669 | - $col = "YEAR($date_orig)"; |
|
| 2670 | - break; |
|
| 2671 | - case 'heure': |
|
| 2672 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2673 | - break; |
|
| 2674 | - case 'age': |
|
| 2675 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2676 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2677 | - break; |
|
| 2678 | - case 'age_relatif': |
|
| 2679 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | - break; |
|
| 2682 | - case 'jour_relatif': |
|
| 2683 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2684 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | - break; |
|
| 2686 | - case 'mois_relatif': |
|
| 2687 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2688 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2689 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2690 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2691 | - break; |
|
| 2692 | - case 'annee_relatif': |
|
| 2693 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2694 | - $date_orig . ')'; |
|
| 2695 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | - break; |
|
| 2697 | - } |
|
| 2698 | - |
|
| 2699 | - return [$col, $col_vraie]; |
|
| 2611 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2612 | + return ''; |
|
| 2613 | + } |
|
| 2614 | + |
|
| 2615 | + $boucle = $boucles[$idb]; |
|
| 2616 | + $table = $boucle->show; |
|
| 2617 | + |
|
| 2618 | + // si c'est une colonne de la table, ne rien faire |
|
| 2619 | + if (isset($table['field'][$col])) { |
|
| 2620 | + return ''; |
|
| 2621 | + } |
|
| 2622 | + |
|
| 2623 | + // Le type de critère à prendre en compte |
|
| 2624 | + $col = $regs[1]; |
|
| 2625 | + |
|
| 2626 | + // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2627 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2628 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2629 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2630 | + if (isset($table['field']["date$suite"])) { |
|
| 2631 | + $date_orig = 'date' . $suite; |
|
| 2632 | + } else { |
|
| 2633 | + $date_orig = substr($suite, 1); |
|
| 2634 | + } |
|
| 2635 | + |
|
| 2636 | + $pred = $date_orig; |
|
| 2637 | + } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2638 | + // Si aucune déclaration trouvée, on quitte |
|
| 2639 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2640 | + return ''; |
|
| 2641 | + } |
|
| 2642 | + // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2643 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2644 | + |
|
| 2645 | + // Si c'est pour du relatif |
|
| 2646 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2647 | + $pred = 'date'; |
|
| 2648 | + } |
|
| 2649 | + } |
|
| 2650 | + |
|
| 2651 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2652 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2653 | + ") . '\""; |
|
| 2654 | + |
|
| 2655 | + $col_vraie = $date_orig; |
|
| 2656 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2657 | + |
|
| 2658 | + switch ($col) { |
|
| 2659 | + case 'date': |
|
| 2660 | + $col = $date_orig; |
|
| 2661 | + break; |
|
| 2662 | + case 'jour': |
|
| 2663 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2664 | + break; |
|
| 2665 | + case 'mois': |
|
| 2666 | + $col = "MONTH($date_orig)"; |
|
| 2667 | + break; |
|
| 2668 | + case 'annee': |
|
| 2669 | + $col = "YEAR($date_orig)"; |
|
| 2670 | + break; |
|
| 2671 | + case 'heure': |
|
| 2672 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2673 | + break; |
|
| 2674 | + case 'age': |
|
| 2675 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2676 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2677 | + break; |
|
| 2678 | + case 'age_relatif': |
|
| 2679 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2680 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | + break; |
|
| 2682 | + case 'jour_relatif': |
|
| 2683 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2684 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | + break; |
|
| 2686 | + case 'mois_relatif': |
|
| 2687 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2688 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2689 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2690 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2691 | + break; |
|
| 2692 | + case 'annee_relatif': |
|
| 2693 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2694 | + $date_orig . ')'; |
|
| 2695 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | + break; |
|
| 2697 | + } |
|
| 2698 | + |
|
| 2699 | + return [$col, $col_vraie]; |
|
| 2700 | 2700 | } |
| 2701 | 2701 | |
| 2702 | 2702 | /** |
@@ -2715,16 +2715,16 @@ discard block |
||
| 2715 | 2715 | * de colonne SQL et une date. |
| 2716 | 2716 | **/ |
| 2717 | 2717 | function calculer_param_date($date_compare, $date_orig) { |
| 2718 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2719 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2720 | - $date_compare = '\'$x\''; |
|
| 2721 | - } else { |
|
| 2722 | - $init = $date_compare; |
|
| 2723 | - } |
|
| 2724 | - |
|
| 2725 | - return |
|
| 2726 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2727 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2718 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2719 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2720 | + $date_compare = '\'$x\''; |
|
| 2721 | + } else { |
|
| 2722 | + $init = $date_compare; |
|
| 2723 | + } |
|
| 2724 | + |
|
| 2725 | + return |
|
| 2726 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2727 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2728 | 2728 | } |
| 2729 | 2729 | |
| 2730 | 2730 | /** |
@@ -2742,20 +2742,20 @@ discard block |
||
| 2742 | 2742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2743 | 2743 | */ |
| 2744 | 2744 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2745 | - $boucle = &$boucles[$idb]; |
|
| 2746 | - |
|
| 2747 | - $args = []; |
|
| 2748 | - foreach ($crit->param as &$param) { |
|
| 2749 | - array_push( |
|
| 2750 | - $args, |
|
| 2751 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2752 | - ); |
|
| 2753 | - } |
|
| 2745 | + $boucle = &$boucles[$idb]; |
|
| 2754 | 2746 | |
| 2755 | - $boucle->hash .= ' |
|
| 2747 | + $args = []; |
|
| 2748 | + foreach ($crit->param as &$param) { |
|
| 2749 | + array_push( |
|
| 2750 | + $args, |
|
| 2751 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2752 | + ); |
|
| 2753 | + } |
|
| 2754 | + |
|
| 2755 | + $boucle->hash .= ' |
|
| 2756 | 2756 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2757 | 2757 | |
| 2758 | - $boucle->hash .= ' |
|
| 2758 | + $boucle->hash .= ' |
|
| 2759 | 2759 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2760 | 2760 | } |
| 2761 | 2761 | |
@@ -2773,8 +2773,8 @@ discard block |
||
| 2773 | 2773 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2774 | 2774 | */ |
| 2775 | 2775 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2776 | - $boucle = &$boucles[$idb]; |
|
| 2777 | - $boucle->hash .= ' |
|
| 2776 | + $boucle = &$boucles[$idb]; |
|
| 2777 | + $boucle->hash .= ' |
|
| 2778 | 2778 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2779 | 2779 | } |
| 2780 | 2780 | |
@@ -2790,12 +2790,12 @@ discard block |
||
| 2790 | 2790 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2791 | 2791 | */ |
| 2792 | 2792 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2793 | - $boucle = &$boucles[$idb]; |
|
| 2794 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2795 | - foreach ($crit->param as $param) { |
|
| 2796 | - $boucle->hash .= ' |
|
| 2793 | + $boucle = &$boucles[$idb]; |
|
| 2794 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2795 | + foreach ($crit->param as $param) { |
|
| 2796 | + $boucle->hash .= ' |
|
| 2797 | 2797 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2798 | - } |
|
| 2798 | + } |
|
| 2799 | 2799 | } |
| 2800 | 2800 | |
| 2801 | 2801 | /** |
@@ -2812,16 +2812,16 @@ discard block |
||
| 2812 | 2812 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2813 | 2813 | */ |
| 2814 | 2814 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2815 | - $boucle = &$boucles[$idb]; |
|
| 2816 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2817 | - foreach ($crit->param as $param) { |
|
| 2818 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2819 | - $param, |
|
| 2820 | - $idb, |
|
| 2821 | - $boucles, |
|
| 2822 | - $boucles[$idb]->id_parent |
|
| 2823 | - ) . ";\n"; |
|
| 2824 | - } |
|
| 2815 | + $boucle = &$boucles[$idb]; |
|
| 2816 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2817 | + foreach ($crit->param as $param) { |
|
| 2818 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2819 | + $param, |
|
| 2820 | + $idb, |
|
| 2821 | + $boucles, |
|
| 2822 | + $boucles[$idb]->id_parent |
|
| 2823 | + ) . ";\n"; |
|
| 2824 | + } |
|
| 2825 | 2825 | } |
| 2826 | 2826 | |
| 2827 | 2827 | /** |
@@ -2846,16 +2846,16 @@ discard block |
||
| 2846 | 2846 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2847 | 2847 | */ |
| 2848 | 2848 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2849 | - $boucle = &$boucles[$idb]; |
|
| 2850 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2851 | - foreach ($crit->param as $param) { |
|
| 2852 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2853 | - $param, |
|
| 2854 | - $idb, |
|
| 2855 | - $boucles, |
|
| 2856 | - $boucles[$idb]->id_parent |
|
| 2857 | - ) . ";\n"; |
|
| 2858 | - } |
|
| 2849 | + $boucle = &$boucles[$idb]; |
|
| 2850 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2851 | + foreach ($crit->param as $param) { |
|
| 2852 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2853 | + $param, |
|
| 2854 | + $idb, |
|
| 2855 | + $boucles, |
|
| 2856 | + $boucles[$idb]->id_parent |
|
| 2857 | + ) . ";\n"; |
|
| 2858 | + } |
|
| 2859 | 2859 | } |
| 2860 | 2860 | |
| 2861 | 2861 | /** |
@@ -2870,11 +2870,11 @@ discard block |
||
| 2870 | 2870 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2871 | 2871 | */ |
| 2872 | 2872 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2873 | - $boucle = &$boucles[$idb]; |
|
| 2874 | - foreach ($crit->param as $param) { |
|
| 2875 | - $boucle->hash .= ' |
|
| 2873 | + $boucle = &$boucles[$idb]; |
|
| 2874 | + foreach ($crit->param as $param) { |
|
| 2875 | + $boucle->hash .= ' |
|
| 2876 | 2876 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2877 | - } |
|
| 2877 | + } |
|
| 2878 | 2878 | } |
| 2879 | 2879 | |
| 2880 | 2880 | |
@@ -2906,20 +2906,20 @@ discard block |
||
| 2906 | 2906 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2907 | 2907 | */ |
| 2908 | 2908 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2909 | - $boucle = &$boucles[$idb]; |
|
| 2910 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2911 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2912 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2913 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2914 | - if ($crit->param) { |
|
| 2915 | - foreach ($crit->param as $param) { |
|
| 2916 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2917 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2918 | - } |
|
| 2919 | - // interdire {si 0} aussi ! |
|
| 2920 | - } else { |
|
| 2921 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2922 | - } |
|
| 2909 | + $boucle = &$boucles[$idb]; |
|
| 2910 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2911 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2912 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2913 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2914 | + if ($crit->param) { |
|
| 2915 | + foreach ($crit->param as $param) { |
|
| 2916 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2917 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2918 | + } |
|
| 2919 | + // interdire {si 0} aussi ! |
|
| 2920 | + } else { |
|
| 2921 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2922 | + } |
|
| 2923 | 2923 | } |
| 2924 | 2924 | |
| 2925 | 2925 | /** |
@@ -2936,8 +2936,8 @@ discard block |
||
| 2936 | 2936 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2937 | 2937 | */ |
| 2938 | 2938 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2939 | - $boucle = &$boucles[$idb]; |
|
| 2940 | - $boucle->hash .= ' |
|
| 2939 | + $boucle = &$boucles[$idb]; |
|
| 2940 | + $boucle->hash .= ' |
|
| 2941 | 2941 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2942 | 2942 | $command[\'sourcemode\'] = \'table\';'; |
| 2943 | 2943 | } |
@@ -2958,27 +2958,27 @@ discard block |
||
| 2958 | 2958 | */ |
| 2959 | 2959 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2960 | 2960 | |
| 2961 | - $not = $crit->not; |
|
| 2962 | - $boucle = &$boucles[$idb]; |
|
| 2963 | - $primary = $boucle->primary; |
|
| 2961 | + $not = $crit->not; |
|
| 2962 | + $boucle = &$boucles[$idb]; |
|
| 2963 | + $primary = $boucle->primary; |
|
| 2964 | 2964 | |
| 2965 | - if (!$primary or strpos($primary, ',')) { |
|
| 2966 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2965 | + if (!$primary or strpos($primary, ',')) { |
|
| 2966 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2967 | 2967 | |
| 2968 | - return; |
|
| 2969 | - } |
|
| 2970 | - $table = $boucle->type_requete; |
|
| 2971 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2968 | + return; |
|
| 2969 | + } |
|
| 2970 | + $table = $boucle->type_requete; |
|
| 2971 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2972 | 2972 | |
| 2973 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2973 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2974 | 2974 | |
| 2975 | - $in = 'IN'; |
|
| 2976 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2977 | - if ($not) { |
|
| 2978 | - $where = ["'NOT'", $where]; |
|
| 2979 | - } |
|
| 2975 | + $in = 'IN'; |
|
| 2976 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2977 | + if ($not) { |
|
| 2978 | + $where = ["'NOT'", $where]; |
|
| 2979 | + } |
|
| 2980 | 2980 | |
| 2981 | - $boucle->where[] = $where; |
|
| 2981 | + $boucle->where[] = $where; |
|
| 2982 | 2982 | } |
| 2983 | 2983 | |
| 2984 | 2984 | /** |
@@ -2994,8 +2994,8 @@ discard block |
||
| 2994 | 2994 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2995 | 2995 | */ |
| 2996 | 2996 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2997 | - $not = $crit->not; |
|
| 2998 | - $crit->not = $not ? false : true; |
|
| 2999 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3000 | - $crit->not = $not; |
|
| 2997 | + $not = $crit->not; |
|
| 2998 | + $crit->not = $not ? false : true; |
|
| 2999 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3000 | + $crit->not = $not; |
|
| 3001 | 3001 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $boucle = &$boucles[$idb]; |
| 48 | 48 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 49 | 49 | |
| 50 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 50 | + $c = ["'='", "'$boucle->id_table."."$id_parent'", 0]; |
|
| 51 | 51 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | $id = $boucle->primary; |
| 71 | 71 | |
| 72 | 72 | if ($not or !$id) { |
| 73 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 73 | + return ['zbug_critere_inconnu', ['critere' => $not.$crit->op]]; |
|
| 74 | 74 | } |
| 75 | 75 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 76 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 76 | + $boucle->where[] = ["'!='", "'$boucle->id_table."."$id'", $arg]; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | $not = ($crit->not ? '' : 'NOT'); |
| 105 | 105 | |
| 106 | 106 | // le doublon s'applique sur un type de boucle (article) |
| 107 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 107 | + $nom = "'".$boucle->type_requete."'"; |
|
| 108 | 108 | |
| 109 | 109 | // compléter le nom avec un nom précisé {doublons nom} |
| 110 | 110 | // on obtient $nom = "'article' . 'nom'" |
| 111 | 111 | if (isset($crit->param[0])) { |
| 112 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 112 | + $nom .= '.'.calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | // $doublons et son index, ici $nom |
| 122 | 122 | |
| 123 | 123 | // debut du code "sql_in('articles.id_article', " |
| 124 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 124 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 125 | 125 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 126 | 126 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 127 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 127 | + $debut_doub = '$doublons['.(!$not ? '' : ($boucle->doublons.'[]= ')); |
|
| 128 | 128 | |
| 129 | 129 | // le debut complet du code des doublons |
| 130 | - $debut_doub = $debut_in . $debut_doub; |
|
| 130 | + $debut_doub = $debut_in.$debut_doub; |
|
| 131 | 131 | |
| 132 | 132 | // nom du doublon "('article' . 'nom')]" |
| 133 | 133 | $fin_doub = "($nom)]"; |
@@ -137,22 +137,22 @@ discard block |
||
| 137 | 137 | foreach ($boucle->where as $k => $w) { |
| 138 | 138 | if (strpos($w[0], $debut_doub) === 0) { |
| 139 | 139 | // fusionner le sql_in (du where) |
| 140 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 140 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 141 | 141 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 142 | 142 | $x = strpos($boucle->hash, $init_comment); |
| 143 | 143 | $len = strlen($init_comment); |
| 144 | 144 | $boucle->hash = |
| 145 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 145 | + substr($boucle->hash, 0, $x + $len).$init_code.substr($boucle->hash, $x + $len); |
|
| 146 | 146 | |
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 152 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 152 | + $boucle->where[] = [$debut_doub.$fin_doub.", '".$not."')"]; |
|
| 153 | 153 | |
| 154 | 154 | // déclarer le doublon s'il n'existe pas encore |
| 155 | - $boucle->hash .= $init_comment . $init_code; |
|
| 155 | + $boucle->hash .= $init_comment.$init_code; |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | 158 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | $deux = $deux[0]->texte; |
| 215 | 215 | if ($deux) { |
| 216 | 216 | $boucles[$idb]->limit = |
| 217 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 217 | + 'intval($Pile[0]["debut'.$un.'"]) . ",'.$deux.'"'; |
|
| 218 | 218 | } else { |
| 219 | 219 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
| 220 | 220 | } |
@@ -276,26 +276,26 @@ discard block |
||
| 276 | 276 | $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 279 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr($type, 1)); |
|
| 280 | 280 | $boucle->modificateur['debut_nom'] = $type; |
| 281 | 281 | $partie = |
| 282 | 282 | // tester si le numero de page demande est de la forme '@yyy' |
| 283 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 283 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 284 | 284 | . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
| 285 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 285 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 286 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 287 | 287 | . "\t}\n" |
| 288 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 288 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 289 | 289 | |
| 290 | 290 | $boucle->hash .= ' |
| 291 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 291 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 292 | 292 | |
| 293 | 293 | $boucle->total_parties = $pas; |
| 294 | 294 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 295 | 295 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 296 | 296 | // sauf si pas de primaire, ou si primaire composee |
| 297 | 297 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 298 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 298 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 299 | 299 | if ( |
| 300 | 300 | $boucle->primary |
| 301 | 301 | and !preg_match('/[,\s]/', $boucle->primary) |
@@ -342,24 +342,24 @@ discard block |
||
| 342 | 342 | $boucle->hash .= ' |
| 343 | 343 | // RECHERCHE' |
| 344 | 344 | . ($crit->cond ? ' |
| 345 | - if (!strlen(' . $quoi . ')){ |
|
| 345 | + if (!strlen(' . $quoi.')){ |
|
| 346 | 346 | list($rech_select, $rech_where) = array("0 as points",""); |
| 347 | - } else' : '') . ' |
|
| 347 | + } else' : '').' |
|
| 348 | 348 | { |
| 349 | 349 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 350 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 350 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 351 | 351 | } |
| 352 | 352 | '; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 355 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 356 | 356 | if (!in_array($t, $boucles[$idb]->select)) { |
| 357 | 357 | $boucle->select[] = $t; |
| 358 | 358 | } # pour postgres, neuneu ici |
| 359 | 359 | // jointure uniquement sur le serveur principal |
| 360 | 360 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 361 | 361 | if (!$boucle->sql_serveur) { |
| 362 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 362 | + $boucle->join['resultats'] = ["'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"]; |
|
| 363 | 363 | $boucle->from['resultats'] = 'spip_resultats'; |
| 364 | 364 | } |
| 365 | 365 | $boucle->select[] = '$rech_select'; |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | $c = |
| 427 | 427 | [ |
| 428 | 428 | "'OR'", |
| 429 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 429 | + ["'='", "'$table."."id_trad'", "'$table.$prim'"], |
|
| 430 | 430 | ["'='", "'$table.id_trad'", "'0'"] |
| 431 | 431 | ]; |
| 432 | 432 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
@@ -449,13 +449,13 @@ discard block |
||
| 449 | 449 | $boucle = &$boucles[$idb]; |
| 450 | 450 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 451 | 451 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 452 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 452 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 453 | 453 | |
| 454 | 454 | if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 455 | 455 | $boucle->where[] = ["'='", "'$mparent'", $arg]; |
| 456 | 456 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 457 | 457 | else { |
| 458 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 458 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$boucle->type_requete]]; |
|
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
@@ -508,16 +508,15 @@ discard block |
||
| 508 | 508 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 509 | 509 | $decompose = decompose_champ_id_objet($champ); |
| 510 | 510 | $champ = array_shift($decompose); |
| 511 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 511 | + $boucle->where[] = ["'='", _q($cle.'.'.reset($decompose)), '"'.sql_quote(end($decompose)).'"']; |
|
| 512 | 512 | } |
| 513 | 513 | } else { |
| 514 | 514 | $cle = $boucle->id_table; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 517 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 518 | + . ($not ? ", 'NOT'" : '').')'; |
|
| 519 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 521 | 520 | } |
| 522 | 521 | |
| 523 | 522 | /** |
@@ -537,9 +536,9 @@ discard block |
||
| 537 | 536 | $not = ($crit->not ? 'NOT' : ''); |
| 538 | 537 | $serveur = $boucle->sql_serveur; |
| 539 | 538 | |
| 540 | - $c = "sql_in('" . |
|
| 541 | - $boucle->id_table . '.' . $boucle->primary |
|
| 542 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 539 | + $c = "sql_in('". |
|
| 540 | + $boucle->id_table.'.'.$boucle->primary |
|
| 541 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 543 | 542 | |
| 544 | 543 | $boucle->where[] = $c; |
| 545 | 544 | } |
@@ -571,7 +570,7 @@ discard block |
||
| 571 | 570 | $t = table_objet_sql($r[1]); |
| 572 | 571 | $t = array_search($t, $boucles[$idb]->from); |
| 573 | 572 | if ($t) { |
| 574 | - $t .= '.' . $r[2]; |
|
| 573 | + $t .= '.'.$r[2]; |
|
| 575 | 574 | } |
| 576 | 575 | } |
| 577 | 576 | } else { |
@@ -586,7 +585,7 @@ discard block |
||
| 586 | 585 | $boucles[$idb]->select[] = $t; |
| 587 | 586 | } |
| 588 | 587 | } else { |
| 589 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 588 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 590 | 589 | } |
| 591 | 590 | } |
| 592 | 591 | |
@@ -656,25 +655,25 @@ discard block |
||
| 656 | 655 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 657 | 656 | or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 658 | 657 | ) { |
| 659 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 658 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 660 | 659 | } else { |
| 661 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 660 | + $boucle->order[$n - 1] .= ' . '.$boucle->modificateur['collate']; |
|
| 662 | 661 | } |
| 663 | 662 | } |
| 664 | 663 | } else { |
| 665 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 664 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.(is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | 665 | } |
| 667 | 666 | } |
| 668 | 667 | |
| 669 | 668 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 670 | 669 | $boucle = $boucles[$idb]; |
| 671 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | - $var = '$champs_' . $idb; |
|
| 670 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 671 | + $var = '$champs_'.$idb; |
|
| 673 | 672 | $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
| 674 | 673 | if (!$desc) { |
| 675 | 674 | $desc = $boucle->show['field']; |
| 676 | 675 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 677 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 676 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.');'; |
|
| 678 | 677 | } |
| 679 | 678 | if ($desc) { |
| 680 | 679 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -749,7 +748,7 @@ discard block |
||
| 749 | 748 | $sens = " . ' DESC'"; |
| 750 | 749 | } |
| 751 | 750 | if (isset($boucle->modificateur['collate'])) { |
| 752 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 751 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 753 | 752 | } |
| 754 | 753 | |
| 755 | 754 | // Pour chaque paramètre du critère |
@@ -771,14 +770,14 @@ discard block |
||
| 771 | 770 | if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
| 772 | 771 | $expression = trim($m[1]); |
| 773 | 772 | $champ = trim($m[2]); |
| 774 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 773 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 775 | 774 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 776 | 775 | } else { |
| 777 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 776 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 778 | 777 | } |
| 779 | 778 | |
| 780 | 779 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 781 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 780 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^'.CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 782 | 781 | // {par FONCTION(champ)} |
| 783 | 782 | if (isset($match) and count($match) > 2) { |
| 784 | 783 | $par = substr($match[2], 1, -1); |
@@ -788,7 +787,7 @@ discard block |
||
| 788 | 787 | if ($par == 'hasard') { |
| 789 | 788 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 790 | 789 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 791 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 790 | + $order = "'".$boucle->id_table.'.'.$boucle->show['date']."'"; |
|
| 792 | 791 | } else { |
| 793 | 792 | // cas général {par champ}, {par table.champ}, ... |
| 794 | 793 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -797,7 +796,7 @@ discard block |
||
| 797 | 796 | |
| 798 | 797 | // on ne sait pas traiter… |
| 799 | 798 | else { |
| 800 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 799 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 801 | 800 | } |
| 802 | 801 | |
| 803 | 802 | // En cas d'erreur de squelette retournée par une fonction |
@@ -817,14 +816,14 @@ discard block |
||
| 817 | 816 | |
| 818 | 817 | if ($fct) { |
| 819 | 818 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 820 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 819 | + $order = "'$fct(".$r[1].")'"; |
|
| 821 | 820 | } else { |
| 822 | 821 | $order = "'$fct(' . $order . ')'"; |
| 823 | 822 | } |
| 824 | 823 | } |
| 825 | - $t = $order . $collecte . $sens; |
|
| 824 | + $t = $order.$collecte.$sens; |
|
| 826 | 825 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 827 | - $t = $r[1] . $r[2]; |
|
| 826 | + $t = $r[1].$r[2]; |
|
| 828 | 827 | } |
| 829 | 828 | |
| 830 | 829 | $boucle->order[] = $t; |
@@ -874,16 +873,16 @@ discard block |
||
| 874 | 873 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 875 | 874 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 876 | 875 | if (is_array($_champ)) { |
| 877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 876 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." num $champ"]]; |
|
| 878 | 877 | } |
| 879 | 878 | $boucle = &$boucles[$idb]; |
| 880 | - $texte = '0+' . $_champ; |
|
| 879 | + $texte = '0+'.$_champ; |
|
| 881 | 880 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 882 | 881 | if ($suite !== "''") { |
| 883 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 882 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 884 | 883 | } |
| 885 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 884 | + $asnum = 'num'.($boucle->order ? count($boucle->order) : ''); |
|
| 885 | + $boucle->select[] = $texte." AS $asnum"; |
|
| 887 | 886 | |
| 888 | 887 | $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
| 889 | 888 | $orderassinum = trim($orderassinum, "'"); |
@@ -912,13 +911,13 @@ discard block |
||
| 912 | 911 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 913 | 912 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 914 | 913 | if (is_array($_champ)) { |
| 915 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 914 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." sinum $champ"]]; |
|
| 916 | 915 | } |
| 917 | 916 | $boucle = &$boucles[$idb]; |
| 918 | - $texte = '0+' . $_champ; |
|
| 917 | + $texte = '0+'.$_champ; |
|
| 919 | 918 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 920 | 919 | if ($suite !== "''") { |
| 921 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 920 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 922 | 921 | } |
| 923 | 922 | |
| 924 | 923 | $as = false; |
@@ -934,8 +933,8 @@ discard block |
||
| 934 | 933 | } |
| 935 | 934 | |
| 936 | 935 | if (!$as) { |
| 937 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | - $boucle->select[] = $select . $as; |
|
| 936 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ''); |
|
| 937 | + $boucle->select[] = $select.$as; |
|
| 939 | 938 | } |
| 940 | 939 | $order = "'$as'"; |
| 941 | 940 | return $order; |
@@ -960,10 +959,10 @@ discard block |
||
| 960 | 959 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | 960 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 962 | 961 | if (is_array($_champ)) { |
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 962 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." multi $champ"]]; |
|
| 964 | 963 | } |
| 965 | 964 | $boucle = &$boucles[$idb]; |
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 965 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 967 | 966 | $order = "'multi'"; |
| 968 | 967 | return $order; |
| 969 | 968 | } |
@@ -989,7 +988,7 @@ discard block |
||
| 989 | 988 | |
| 990 | 989 | // le champ existe dans la table, pas de souci (le plus commun) |
| 991 | 990 | if (isset($desc['field'][$par])) { |
| 992 | - $par = $boucle->id_table . '.' . $par; |
|
| 991 | + $par = $boucle->id_table.'.'.$par; |
|
| 993 | 992 | } |
| 994 | 993 | // le champ est peut être une jointure |
| 995 | 994 | else { |
@@ -1010,24 +1009,24 @@ discard block |
||
| 1010 | 1009 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 1011 | 1010 | // Si la table est déjà dans le from, on la réutilise. |
| 1012 | 1011 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 1013 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1012 | + $par = $infos['alias'].'.'.$champ; |
|
| 1014 | 1013 | } elseif ( |
| 1015 | 1014 | $boucle->jointures_explicites |
| 1016 | 1015 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 1017 | 1016 | ) { |
| 1018 | - $par = $alias . '.' . $champ; |
|
| 1017 | + $par = $alias.'.'.$champ; |
|
| 1019 | 1018 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 1020 | - $par = $alias . '.' . $champ; |
|
| 1019 | + $par = $alias.'.'.$champ; |
|
| 1021 | 1020 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 1022 | 1021 | } elseif ( |
| 1023 | 1022 | $table_alias |
| 1024 | 1023 | and isset($boucle->from[$table_alias]) |
| 1025 | 1024 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 1026 | 1025 | ) { |
| 1027 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1026 | + $par = $infos['alias'].'.'.$champ; |
|
| 1028 | 1027 | } elseif ($table) { |
| 1029 | 1028 | // On avait table + champ, mais on ne les a pas trouvés |
| 1030 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1029 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 1031 | 1030 | } else { |
| 1032 | 1031 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1033 | 1032 | } |
@@ -1051,7 +1050,7 @@ discard block |
||
| 1051 | 1050 | if (!$t) { |
| 1052 | 1051 | $t = trouver_jointure_champ($champ, $boucle); |
| 1053 | 1052 | } |
| 1054 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1053 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1055 | 1054 | } |
| 1056 | 1055 | |
| 1057 | 1056 | /** |
@@ -1096,9 +1095,9 @@ discard block |
||
| 1096 | 1095 | $boucle->default_order[] = ' DESC'; |
| 1097 | 1096 | } |
| 1098 | 1097 | } else { |
| 1099 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1098 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1100 | 1099 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1101 | - $t = $r[1] . $r[2]; |
|
| 1100 | + $t = $r[1].$r[2]; |
|
| 1102 | 1101 | } |
| 1103 | 1102 | $boucle->order[$n - 1] = $t; |
| 1104 | 1103 | } |
@@ -1135,7 +1134,7 @@ discard block |
||
| 1135 | 1134 | |
| 1136 | 1135 | $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
| 1137 | 1136 | |
| 1138 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1137 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'".$boucle->sql_serveur."')) ? \$zl : '0').')'$sens"; |
|
| 1139 | 1138 | $boucle->order[] = $order; |
| 1140 | 1139 | } |
| 1141 | 1140 | |
@@ -1144,7 +1143,7 @@ discard block |
||
| 1144 | 1143 | $params = $crit->param; |
| 1145 | 1144 | |
| 1146 | 1145 | if ((is_countable($params) ? count($params) : 0) < 1) { |
| 1147 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1146 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1148 | 1147 | } |
| 1149 | 1148 | |
| 1150 | 1149 | $boucle = &$boucles[$idb]; |
@@ -1165,7 +1164,7 @@ discard block |
||
| 1165 | 1164 | if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
| 1166 | 1165 | $date = $date[0]->texte; |
| 1167 | 1166 | if (!isset($fields[$date])) { |
| 1168 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1167 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$date]]; |
|
| 1169 | 1168 | } |
| 1170 | 1169 | } else { |
| 1171 | 1170 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1177,38 +1176,38 @@ discard block |
||
| 1177 | 1176 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1178 | 1177 | } |
| 1179 | 1178 | $annee = $params ? array_shift($params) : ''; |
| 1180 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1181 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1180 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1182 | 1181 | ') ? $x : date("Y"))'; |
| 1183 | 1182 | |
| 1184 | 1183 | $mois = $params ? array_shift($params) : ''; |
| 1185 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1186 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1185 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1187 | 1186 | ') ? $x : date("m"))'; |
| 1188 | 1187 | |
| 1189 | 1188 | $jour = $params ? array_shift($params) : ''; |
| 1190 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1191 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1190 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1192 | 1191 | ') ? $x : date("d"))'; |
| 1193 | 1192 | |
| 1194 | 1193 | $annee2 = $params ? array_shift($params) : ''; |
| 1195 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1196 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1195 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1197 | 1196 | ') ? $x : date("Y"))'; |
| 1198 | 1197 | |
| 1199 | 1198 | $mois2 = $params ? array_shift($params) : ''; |
| 1200 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1201 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1200 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1202 | 1201 | ') ? $x : date("m"))'; |
| 1203 | 1202 | |
| 1204 | 1203 | $jour2 = $params ? array_shift($params) : ''; |
| 1205 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1206 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1205 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1207 | 1206 | ') ? $x : date("d"))'; |
| 1208 | 1207 | |
| 1209 | - $date = $boucle->id_table . ".$date"; |
|
| 1208 | + $date = $boucle->id_table.".$date"; |
|
| 1210 | 1209 | |
| 1211 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1210 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1212 | 1211 | if ($type == 'jour') { |
| 1213 | 1212 | $boucle->where[] = [ |
| 1214 | 1213 | "'='", |
@@ -1280,14 +1279,13 @@ discard block |
||
| 1280 | 1279 | [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1281 | 1280 | |
| 1282 | 1281 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1283 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1282 | + $boucle->limit = $a11.','.$a21; |
|
| 1284 | 1283 | } else { |
| 1285 | 1284 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1286 | 1285 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1287 | 1286 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1288 | 1287 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1289 | - $mode = (($op == '/') ? '/' : |
|
| 1290 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1291 | 1289 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1292 | 1290 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
| 1293 | 1291 | $boucle->limit = |
@@ -1333,8 +1331,7 @@ discard block |
||
| 1333 | 1331 | // {1/3} |
| 1334 | 1332 | if ($op1 == '/') { |
| 1335 | 1333 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1336 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1337 | - "($total_parties ? $total_parties : 1)"; |
|
| 1334 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1338 | 1335 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1339 | 1336 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1340 | 1337 | } else { |
@@ -1345,15 +1342,13 @@ discard block |
||
| 1345 | 1342 | |
| 1346 | 1343 | // cas {x,n-1} |
| 1347 | 1344 | if ($op2 == '-') { |
| 1348 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1349 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1350 | - ($total_parties . ' - 1')); |
|
| 1345 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1346 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1351 | 1347 | } else { |
| 1352 | 1348 | // {x,1} ou {pagination} |
| 1353 | 1349 | $fin = '$debut_boucle' |
| 1354 | 1350 | . (is_numeric($total_parties) ? |
| 1355 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1356 | - ('+' . $total_parties . ' - 1')); |
|
| 1351 | + (($total_parties == 1) ? '' : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1357 | 1352 | } |
| 1358 | 1353 | |
| 1359 | 1354 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1371,11 +1366,11 @@ discard block |
||
| 1371 | 1366 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1372 | 1367 | |
| 1373 | 1368 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1374 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1369 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1375 | 1370 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1376 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1377 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1378 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1371 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1372 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1373 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1379 | 1374 | . "\n\tif (\$debut_boucle>0" |
| 1380 | 1375 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1381 | 1376 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1460,16 +1455,16 @@ discard block |
||
| 1460 | 1455 | // critere personnalise ? |
| 1461 | 1456 | if ( |
| 1462 | 1457 | (!$serveur or |
| 1463 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1464 | - and (!function_exists($f = $f . '_dist')) |
|
| 1465 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1466 | - and (!function_exists($f = $f . '_dist')) |
|
| 1458 | + ((!function_exists($f = 'critere_'.$serveur.'_'.$table.'_'.$critere)) |
|
| 1459 | + and (!function_exists($f = $f.'_dist')) |
|
| 1460 | + and (!function_exists($f = 'critere_'.$serveur.'_'.$critere)) |
|
| 1461 | + and (!function_exists($f = $f.'_dist')) |
|
| 1467 | 1462 | ) |
| 1468 | 1463 | ) |
| 1469 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1470 | - and (!function_exists($f = $f . '_dist')) |
|
| 1471 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1472 | - and (!function_exists($f = $f . '_dist')) |
|
| 1464 | + and (!function_exists($f = 'critere_'.$table.'_'.$critere)) |
|
| 1465 | + and (!function_exists($f = $f.'_dist')) |
|
| 1466 | + and (!function_exists($f = 'critere_'.$critere)) |
|
| 1467 | + and (!function_exists($f = $f.'_dist')) |
|
| 1473 | 1468 | ) { |
| 1474 | 1469 | // fonction critere standard |
| 1475 | 1470 | $f = $defaut; |
@@ -1500,9 +1495,9 @@ discard block |
||
| 1500 | 1495 | */ |
| 1501 | 1496 | function kwote($lisp, $serveur = '', $type = '') { |
| 1502 | 1497 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1503 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1498 | + return $r[1].'"'.sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type).'"'; |
|
| 1504 | 1499 | } else { |
| 1505 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1500 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1506 | 1501 | } |
| 1507 | 1502 | } |
| 1508 | 1503 | |
@@ -1524,7 +1519,7 @@ discard block |
||
| 1524 | 1519 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1525 | 1520 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1526 | 1521 | if (!$r) { |
| 1527 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1522 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1528 | 1523 | } |
| 1529 | 1524 | [$arg, $op, $val, $col, $where_complement] = $r; |
| 1530 | 1525 | |
@@ -1549,8 +1544,8 @@ discard block |
||
| 1549 | 1544 | "'NOT'", |
| 1550 | 1545 | [ |
| 1551 | 1546 | "'IN'", |
| 1552 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1553 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1547 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1548 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1554 | 1549 | ] |
| 1555 | 1550 | ]; |
| 1556 | 1551 | } |
@@ -1567,22 +1562,22 @@ discard block |
||
| 1567 | 1562 | $descr = $boucles[$idb]->descr; |
| 1568 | 1563 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1569 | 1564 | |
| 1570 | - $var = '$in' . $cpt++; |
|
| 1565 | + $var = '$in'.$cpt++; |
|
| 1571 | 1566 | $x = "\n\t$var = array();"; |
| 1572 | 1567 | foreach ($val as $k => $v) { |
| 1573 | 1568 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1574 | 1569 | // optimiser le traitement des constantes |
| 1575 | 1570 | if (is_numeric($r[2])) { |
| 1576 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1571 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1577 | 1572 | } else { |
| 1578 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1573 | + $x .= "\n\t$var".'[]= '.sql_quote($r[2]).';'; |
|
| 1579 | 1574 | } |
| 1580 | 1575 | } else { |
| 1581 | 1576 | // Pour permettre de passer des tableaux de valeurs |
| 1582 | 1577 | // on repere l'utilisation brute de #ENV**{X}, |
| 1583 | 1578 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1584 | 1579 | // et on deballe mais en rajoutant l'anti XSS |
| 1585 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1580 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1586 | 1581 | } |
| 1587 | 1582 | } |
| 1588 | 1583 | |
@@ -1596,7 +1591,7 @@ discard block |
||
| 1596 | 1591 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1597 | 1592 | } |
| 1598 | 1593 | |
| 1599 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1594 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : '').')'; |
|
| 1600 | 1595 | } |
| 1601 | 1596 | |
| 1602 | 1597 | /** |
@@ -1669,7 +1664,7 @@ discard block |
||
| 1669 | 1664 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1670 | 1665 | } |
| 1671 | 1666 | // nous aider en mode debug. |
| 1672 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1667 | + $boucle->debug[] = 'id_ : '.implode(', ', $champs); |
|
| 1673 | 1668 | $boucle->modificateur['id_'] = $champs; |
| 1674 | 1669 | |
| 1675 | 1670 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1921,8 +1916,8 @@ discard block |
||
| 1921 | 1916 | "'NOT'", |
| 1922 | 1917 | [ |
| 1923 | 1918 | "'IN'", |
| 1924 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1925 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1919 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1920 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1926 | 1921 | ] |
| 1927 | 1922 | ]; |
| 1928 | 1923 | } |
@@ -1933,7 +1928,7 @@ discard block |
||
| 1933 | 1928 | if ($crit->cond) { |
| 1934 | 1929 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1935 | 1930 | if ($col === 'date' or $col === 'date_redac') { |
| 1936 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1931 | + if ($pred === "\$Pile[0]['".$col."']") { |
|
| 1937 | 1932 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1938 | 1933 | } |
| 1939 | 1934 | } |
@@ -2096,7 +2091,7 @@ discard block |
||
| 2096 | 2091 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2097 | 2092 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2098 | 2093 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2099 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2094 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2100 | 2095 | } |
| 2101 | 2096 | // sinon expliciter les |
| 2102 | 2097 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2112,14 +2107,14 @@ discard block |
||
| 2112 | 2107 | ) { |
| 2113 | 2108 | $r = $r[1] |
| 2114 | 2109 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2115 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2110 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2116 | 2111 | $val[0] = "sql_quote($r)"; |
| 2117 | 2112 | } |
| 2118 | 2113 | elseif ( |
| 2119 | 2114 | strpos($val[0], '@@defaultcast@@') !== false |
| 2120 | 2115 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2121 | 2116 | ) { |
| 2122 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2117 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2123 | 2118 | } |
| 2124 | 2119 | } |
| 2125 | 2120 | |
@@ -2127,7 +2122,7 @@ discard block |
||
| 2127 | 2122 | strpos($val[0], '@@defaultcast@@') !== false |
| 2128 | 2123 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2129 | 2124 | ) { |
| 2130 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2125 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2131 | 2126 | } |
| 2132 | 2127 | |
| 2133 | 2128 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2143,7 +2138,7 @@ discard block |
||
| 2143 | 2138 | // inserer le nom de la table SQL devant le nom du champ |
| 2144 | 2139 | if ($table) { |
| 2145 | 2140 | if ($col[0] == '`') { |
| 2146 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2141 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2147 | 2142 | } else { |
| 2148 | 2143 | $arg = "$table.$col"; |
| 2149 | 2144 | } |
@@ -2277,9 +2272,9 @@ discard block |
||
| 2277 | 2272 | **/ |
| 2278 | 2273 | function primary_doublee($decompose, $table) { |
| 2279 | 2274 | $e1 = reset($decompose); |
| 2280 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2275 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2281 | 2276 | |
| 2282 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2277 | + return ["'='", "'$table.".$e1."'", $e2]; |
|
| 2283 | 2278 | } |
| 2284 | 2279 | |
| 2285 | 2280 | /** |
@@ -2318,7 +2313,7 @@ discard block |
||
| 2318 | 2313 | $checkarrivee |
| 2319 | 2314 | and is_string($checkarrivee) |
| 2320 | 2315 | and $a = table_objet($checkarrivee) |
| 2321 | - and in_array($a . '_liens', $joints) |
|
| 2316 | + and in_array($a.'_liens', $joints) |
|
| 2322 | 2317 | ) { |
| 2323 | 2318 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2324 | 2319 | return $res; |
@@ -2338,12 +2333,12 @@ discard block |
||
| 2338 | 2333 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2339 | 2334 | $joindre = false; |
| 2340 | 2335 | foreach ($cols as $col) { |
| 2341 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2336 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2342 | 2337 | if (trouver_champ($c, $boucle->where)) { |
| 2343 | 2338 | $joindre = true; |
| 2344 | 2339 | } else { |
| 2345 | 2340 | // mais ca peut etre dans le FIELD pour le Having |
| 2346 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2341 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2347 | 2342 | if (trouver_champ($c, $boucle->select)) { |
| 2348 | 2343 | $joindre = true; |
| 2349 | 2344 | } |
@@ -2389,7 +2384,7 @@ discard block |
||
| 2389 | 2384 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2390 | 2385 | |
| 2391 | 2386 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2392 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2387 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee.'_liens'); |
|
| 2393 | 2388 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2394 | 2389 | |
| 2395 | 2390 | if (!$intermediaire or !$arrivee) { |
@@ -2493,7 +2488,7 @@ discard block |
||
| 2493 | 2488 | } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
| 2494 | 2489 | // un critere conditionnel sur date est traite a part |
| 2495 | 2490 | // car la date est mise d'office par SPIP, |
| 2496 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2491 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2497 | 2492 | } |
| 2498 | 2493 | |
| 2499 | 2494 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2525,7 +2520,7 @@ discard block |
||
| 2525 | 2520 | and (($p == "'") or ($p == '"')) |
| 2526 | 2521 | and $params[0][1]->type == 'champ' |
| 2527 | 2522 | ) { |
| 2528 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2523 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2529 | 2524 | } else { |
| 2530 | 2525 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2531 | 2526 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2541,7 +2536,7 @@ discard block |
||
| 2541 | 2536 | $fct = $args_sql = ''; |
| 2542 | 2537 | // fonction SQL ? |
| 2543 | 2538 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2544 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2539 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2545 | 2540 | $fct = $m[1]; |
| 2546 | 2541 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2547 | 2542 | $col = $a[1]; |
@@ -2628,7 +2623,7 @@ discard block |
||
| 2628 | 2623 | # Recherche de l'existence du champ date_xxxx, |
| 2629 | 2624 | # si oui choisir ce champ, sinon choisir xxxx |
| 2630 | 2625 | if (isset($table['field']["date$suite"])) { |
| 2631 | - $date_orig = 'date' . $suite; |
|
| 2626 | + $date_orig = 'date'.$suite; |
|
| 2632 | 2627 | } else { |
| 2633 | 2628 | $date_orig = substr($suite, 1); |
| 2634 | 2629 | } |
@@ -2648,12 +2643,12 @@ discard block |
||
| 2648 | 2643 | } |
| 2649 | 2644 | } |
| 2650 | 2645 | |
| 2651 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2652 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2646 | + $date_compare = "\"' . normaliser_date(". |
|
| 2647 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2653 | 2648 | ") . '\""; |
| 2654 | 2649 | |
| 2655 | 2650 | $col_vraie = $date_orig; |
| 2656 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2651 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2657 | 2652 | |
| 2658 | 2653 | switch ($col) { |
| 2659 | 2654 | case 'date': |
@@ -2673,26 +2668,26 @@ discard block |
||
| 2673 | 2668 | break; |
| 2674 | 2669 | case 'age': |
| 2675 | 2670 | $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
| 2676 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2671 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2677 | 2672 | break; |
| 2678 | 2673 | case 'age_relatif': |
| 2679 | 2674 | $col = calculer_param_date($date_compare, $date_orig); |
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2681 | 2676 | break; |
| 2682 | 2677 | case 'jour_relatif': |
| 2683 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2684 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2678 | + $col = '(TO_DAYS('.$date_compare.')-TO_DAYS('.$date_orig.'))'; |
|
| 2679 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2685 | 2680 | break; |
| 2686 | 2681 | case 'mois_relatif': |
| 2687 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2688 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2689 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2690 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | + $col = 'MONTH('.$date_compare.')-MONTH('. |
|
| 2683 | + $date_orig.')+12*(YEAR('.$date_compare. |
|
| 2684 | + ')-YEAR('.$date_orig.'))'; |
|
| 2685 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2691 | 2686 | break; |
| 2692 | 2687 | case 'annee_relatif': |
| 2693 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2694 | - $date_orig . ')'; |
|
| 2695 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2688 | + $col = 'YEAR('.$date_compare.')-YEAR('. |
|
| 2689 | + $date_orig.')'; |
|
| 2690 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2696 | 2691 | break; |
| 2697 | 2692 | } |
| 2698 | 2693 | |
@@ -2753,10 +2748,10 @@ discard block |
||
| 2753 | 2748 | } |
| 2754 | 2749 | |
| 2755 | 2750 | $boucle->hash .= ' |
| 2756 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2751 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2757 | 2752 | |
| 2758 | 2753 | $boucle->hash .= ' |
| 2759 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2754 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2760 | 2755 | } |
| 2761 | 2756 | |
| 2762 | 2757 | /** |
@@ -2775,7 +2770,7 @@ discard block |
||
| 2775 | 2770 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2776 | 2771 | $boucle = &$boucles[$idb]; |
| 2777 | 2772 | $boucle->hash .= ' |
| 2778 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2773 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2779 | 2774 | } |
| 2780 | 2775 | |
| 2781 | 2776 | |
@@ -2794,7 +2789,7 @@ discard block |
||
| 2794 | 2789 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2795 | 2790 | foreach ($crit->param as $param) { |
| 2796 | 2791 | $boucle->hash .= ' |
| 2797 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2792 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2798 | 2793 | } |
| 2799 | 2794 | } |
| 2800 | 2795 | |
@@ -2813,14 +2808,14 @@ discard block |
||
| 2813 | 2808 | */ |
| 2814 | 2809 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2815 | 2810 | $boucle = &$boucles[$idb]; |
| 2816 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2811 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2817 | 2812 | foreach ($crit->param as $param) { |
| 2818 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2813 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste( |
|
| 2819 | 2814 | $param, |
| 2820 | 2815 | $idb, |
| 2821 | 2816 | $boucles, |
| 2822 | 2817 | $boucles[$idb]->id_parent |
| 2823 | - ) . ";\n"; |
|
| 2818 | + ).";\n"; |
|
| 2824 | 2819 | } |
| 2825 | 2820 | } |
| 2826 | 2821 | |
@@ -2847,14 +2842,14 @@ discard block |
||
| 2847 | 2842 | */ |
| 2848 | 2843 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2849 | 2844 | $boucle = &$boucles[$idb]; |
| 2850 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2845 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2851 | 2846 | foreach ($crit->param as $param) { |
| 2852 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2847 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste( |
|
| 2853 | 2848 | $param, |
| 2854 | 2849 | $idb, |
| 2855 | 2850 | $boucles, |
| 2856 | 2851 | $boucles[$idb]->id_parent |
| 2857 | - ) . ";\n"; |
|
| 2852 | + ).";\n"; |
|
| 2858 | 2853 | } |
| 2859 | 2854 | } |
| 2860 | 2855 | |
@@ -2873,7 +2868,7 @@ discard block |
||
| 2873 | 2868 | $boucle = &$boucles[$idb]; |
| 2874 | 2869 | foreach ($crit->param as $param) { |
| 2875 | 2870 | $boucle->hash .= ' |
| 2876 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2871 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2877 | 2872 | } |
| 2878 | 2873 | } |
| 2879 | 2874 | |
@@ -2914,7 +2909,7 @@ discard block |
||
| 2914 | 2909 | if ($crit->param) { |
| 2915 | 2910 | foreach ($crit->param as $param) { |
| 2916 | 2911 | $boucle->hash .= "\t\$command['si'][] = " |
| 2917 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2912 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2918 | 2913 | } |
| 2919 | 2914 | // interdire {si 0} aussi ! |
| 2920 | 2915 | } else { |
@@ -2938,7 +2933,7 @@ discard block |
||
| 2938 | 2933 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2939 | 2934 | $boucle = &$boucles[$idb]; |
| 2940 | 2935 | $boucle->hash .= ' |
| 2941 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2936 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2942 | 2937 | $command[\'sourcemode\'] = \'table\';'; |
| 2943 | 2938 | } |
| 2944 | 2939 | |
@@ -2973,7 +2968,7 @@ discard block |
||
| 2973 | 2968 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 2974 | 2969 | |
| 2975 | 2970 | $in = 'IN'; |
| 2976 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2971 | + $where = ["'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2977 | 2972 | if ($not) { |
| 2978 | 2973 | $where = ["'NOT'", $where]; |
| 2979 | 2974 | } |