1 | <?php |
---|
2 | |
---|
3 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
4 | |
---|
5 | /* |
---|
6 | * Inserer des elements supplementaires |
---|
7 | * |
---|
8 | * @return $flux |
---|
9 | */ |
---|
10 | |
---|
11 | function panier_options_recuperer_fond($flux){ |
---|
12 | |
---|
13 | // surcharge la configuration du panier |
---|
14 | if ($flux['args']['fond'] == 'formulaires/configurer_paniers'){ |
---|
15 | include_spip('inc/config'); |
---|
16 | $flux['args']['contexte']['code_avantage'] = lire_config("paniers/panier_options/code_avantage"); |
---|
17 | $flux['args']['contexte']['pourcentage_avantage'] = lire_config("paniers/panier_options/pourcentage_avantage"); |
---|
18 | |
---|
19 | $option_champ = recuperer_fond('formulaires/configurer_paniers_options', $flux['args']['contexte']); |
---|
20 | $flux['data']['texte'] = str_replace('<!--extra-->', '<!--extra-->' . $option_champ, $flux['data']['texte']); |
---|
21 | } |
---|
22 | |
---|
23 | // surcharge le formulaire du panier |
---|
24 | if ($flux['args']['fond'] == 'formulaires/panier'){ |
---|
25 | |
---|
26 | include_spip('inc/config'); |
---|
27 | $pourcentage_avantage = lire_config("paniers/panier_options/pourcentage_avantage"); |
---|
28 | $code_avantage = lire_config("paniers/panier_options/code_avantage"); |
---|
29 | |
---|
30 | //seulement si l'option est configurée |
---|
31 | if($pourcentage_avantage && $code_avantage){ |
---|
32 | $flux['args']['contexte']['_pourcentage_avantage'] = $pourcentage_avantage; |
---|
33 | $code_valide=false; |
---|
34 | |
---|
35 | //est-ce que l'avantage est déjà validé ? |
---|
36 | if (!$id_panier) { |
---|
37 | include_spip('inc/paniers'); |
---|
38 | $id_panier = paniers_id_panier_encours(); |
---|
39 | } |
---|
40 | $avantage_valide = sql_getfetsel('options','spip_paniers',array('id_panier = '.sql_quote($id_panier))); |
---|
41 | if($avantage_valide=="avantage_valide") $code_valide=true; |
---|
42 | |
---|
43 | //sinon tester si votre_code_avantage est le bon |
---|
44 | if($code_valide==false){ |
---|
45 | $config_code_avantage = lire_config("paniers/panier_options/code_avantage"); |
---|
46 | $request_code_avantage=_request('votre_code_avantage'); |
---|
47 | if($request_code_avantage==$config_code_avantage)$code_valide=true; |
---|
48 | } |
---|
49 | if($code_valide){ |
---|
50 | //afficher le formulaire avec l'avantage calculé |
---|
51 | $option_calculer = recuperer_fond('formulaires/avantage_calculer_total', $flux['args']['contexte']); |
---|
52 | $flux['data']['texte'] = preg_replace('%(<tr class="total_ttc(.*?)</tr>)%is', ' '."\n".$option_calculer, $flux['data']['texte']); |
---|
53 | } |
---|
54 | |
---|
55 | //affiche le champ input votre_code_avantage |
---|
56 | $option_champ = recuperer_fond('formulaires/avantage_option_input', $flux['args']['contexte']); |
---|
57 | $flux['data']['texte'] = str_replace('</table>', '</table>' . $option_champ, $flux['data']['texte']); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | return $flux; |
---|
63 | } |
---|
64 | |
---|
65 | function panier_options_formulaire_charger($flux){ |
---|
66 | |
---|
67 | if ($flux['args']['form'] == 'panier'){ |
---|
68 | $flux['data']['_forcer_request'] = true; // forcer la prise en compte du post |
---|
69 | } |
---|
70 | return $flux; |
---|
71 | } |
---|
72 | |
---|
73 | function panier_options_formulaire_verifier($flux){ |
---|
74 | if ($flux['args']['form'] == 'configurer_paniers'){ |
---|
75 | //verifier le intval |
---|
76 | } |
---|
77 | if ($flux['args']['form'] == 'panier'){ |
---|
78 | include_spip('inc/config'); |
---|
79 | $code_valide=false; |
---|
80 | $config_code_avantage = lire_config("paniers/panier_options/code_avantage"); |
---|
81 | $request_code_avantage=_request('votre_code_avantage'); |
---|
82 | if($request_code_avantage==$config_code_avantage){$code_valide=true;}; |
---|
83 | |
---|
84 | if($request_code_avantage!='' && $code_valide==false){ |
---|
85 | $flux['data']['votre_code_avantage']=_T('panier_options:code_avantage_invalide'); |
---|
86 | } |
---|
87 | |
---|
88 | } |
---|
89 | return $flux; |
---|
90 | } |
---|
91 | |
---|
92 | function panier_options_formulaire_traiter($flux){ |
---|
93 | |
---|
94 | if ($flux['args']['form'] == 'configurer_paniers'){ |
---|
95 | include_spip('inc/config'); |
---|
96 | $code_avantage = _request("code_avantage"); |
---|
97 | $pourcentage_avantage = _request("pourcentage_avantage"); |
---|
98 | ecrire_config("paniers/panier_options/code_avantage",$code_avantage); |
---|
99 | ecrire_config("paniers/panier_options/pourcentage_avantage",$pourcentage_avantage); |
---|
100 | |
---|
101 | } |
---|
102 | if ($flux['args']['form'] == 'panier'){ |
---|
103 | include_spip('inc/config'); |
---|
104 | if (!$id_panier) $id_panier = session_get('id_panier'); |
---|
105 | //spip_log("dans formulaire_charger du panier".$id_panier,"formulaires_pipelines"); |
---|
106 | //tester si le code est bon |
---|
107 | $code_valide=false; |
---|
108 | $config_code_avantage = lire_config("paniers/panier_options/code_avantage"); |
---|
109 | $request_code_avantage=_request('votre_code_avantage'); |
---|
110 | if($request_code_avantage==$config_code_avantage){$code_valide=true;}; |
---|
111 | if($code_valide) { |
---|
112 | sql_updateq('spip_paniers',array('options'=>'avantage_valide'),'id_panier = '.$id_panier ); |
---|
113 | $flux['data']['message_ok'] = _T('panier_options:panier_modifie_ok'); |
---|
114 | } |
---|
115 | |
---|
116 | } |
---|
117 | return $flux; |
---|
118 | } |
---|