source: trunk/spip/esqueleto-redcta/plugins/magusine/exec/avance.php @ 80

Last change on this file since 80 was 80, checked in by guille, 15 years ago

el plugin completo

File size: 9.6 KB
Line 
1<?php
2
3if (!defined("_ECRIRE_INC_VERSION")) return;
4include_spip('inc/presentation');
5include_spip('inc/layer');
6include_spip('inc/getdocument');
7include_spip('inc/upload-image');
8include_spip('inc/extra');
9
10include_spip('inc/arty_selecteur');
11include_spip('inc/user_session');
12
13function exec_avance() {
14
15global $connect_statut;
16  if ($connect_statut != "0minirezo" ) {
17         echo "<p><b>"._T('magusine:acces_a_la_page')."</b></p>";
18         fin_page();
19         exit;
20  }
21
22$message_upload = traiter_post();
23
24traiter_get();
25
26
27echo debut_page();
28   echo barre_onglets("arty", "avance"); //affiche la barre des onglets du groupe "magusine", l'onglet courant est "avance".
29    echo debut_gauche();
30    if ($message_upload && $message_upload != "arty:upload_reussi") {
31      echo debut_cadre_relief(_DIR_PLUGIN_ARTY.'/images/emblem-important.png', true, "", _T('arty:erreur'));
32      echo "<p style='font-weight:bold; color:red;'>"._T($message_upload)."</p>";
33          echo fin_cadre_relief(true);
34    }
35    echo debut_cadre_relief(_DIR_PLUGIN_ARTY.'/images/aide.png', true, "", _T('arty:info'));
36    echo _T("arty:sideinfo_avance");
37        echo fin_cadre_relief(true);
38  echo debut_droite();
39 
40gros_titre(_T("arty:gestion_bloc_libre"));
41   
42  echo debut_cadre_trait_couleur(_DIR_PLUGIN_ARTY."/images/config.png", true, "", _T('arty:creer_un_bloc_libre'));
43  echo "<div style='padding-left:5px;'>";
44  echo "<br />";
45  echo _T('arty:entrez_donnees_nouveau_bloc');
46  echo "<form action='".generer_url_ecrire('avance')."' method='post' enctype=\"multipart/form-data\" name='formulaire' id='formulaire'>\n";
47  echo "<input type='hidden' name='action' value='nouveaubloc' />\n";
48  echo "<input type='text' name='titre' style='width:90%; color:#666; font-weight:bold;' value='"._T('arty:titre')."' onfocus='if(this.value==\""._T('arty:titre')."\"){this.value=&#34;&#34;;}' maxlength='255' size='50' />\n";
49  echo "<textarea name='texte' style='width:90%; color:#444;' cols='50' rows='4' id='texte1'></textarea>\n"; 
50  echo "<br /><br />"._T('arty:bloc_lien')."<br />\n";
51  echo "<input type='text' name='lien' value='http://' maxlength='255'  style='width:90%' size='50' />\n";
52    echo "<br /><br />"._T('arty:bloc_image')."<br />\n";
53
54  echo "<input type=\"file\" name=\"illu_bloc_libre\" size=\"55\"  style='width:95%' /><br />\n";
55  echo "<br /><input type='submit' value='"._T("arty:enregistrer")."' class='fondo' />\n";
56  echo "</form>\n";
57  echo "</div>\n";
58  echo fin_cadre_trait_couleur();
59        $tousblocs = spip_query("SELECT * FROM spip_arty_bloclibre");
60       
61        while ($row=spip_fetch_array($tousblocs)) {
62                echo debut_cadre_trait_couleur(_DIR_PLUGIN_ARTY."/images/config.png", true, "", htmlspecialchars($row['titre']));
63                echo "<a name='".$row['id_bloc_libre']."'></a>";
64        $chem = creer_repertoire_documents("illu-bloc-libre");
65       
66        $chem=_DIR_DOC."illu-bloc-libre/";
67  $handle = @opendir($chem); 
68  $logo = false;
69  while($fichier = @readdir($handle)) {
70
71    if (ereg("^illu_bloc_libre-".$row['id_bloc_libre']."\.(jpg|png|gif)$", $fichier)) {
72      $logo = $fichier;
73    }
74  }
75  if ($logo){
76    // le nombre aléatoire permet d'éviter que le navigateur affiche la version en cache de l'image.
77        $image = "<div style='padding-left:5px'><p>"._T("arty:logo_actuel").":</p><img width=\"190\" src=\""._DIR_DOC."illu-bloc-libre/$logo?".uniqid(rand())."\" />";
78         $image .="<form style='display:inline;' action='".generer_url_ecrire('avance')."' method='post'>\n"
79                ."<input type='hidden' name='action' value='supprimerillu' />"
80                ."<input type='hidden' name='id_bloc' value='".$row['id_bloc_libre']."' />"
81                ."<input type='submit' title='"._T("arty:supprimer_illu")."' value='X' class='fondo' style='position:relative; border-color:red; background-color:red; left:-30px; font-size:10px;' /><br /><br />"
82                ."</form>";
83  } else {
84        $image="";
85  }
86   
87                $texte = $image."<form action='".generer_url_ecrire('avance')."' method='post' enctype=\"multipart/form-data\">\n"
88                ."<input type='hidden' name='action' value='modifierbloc' />"
89                ."<input type='hidden' name='id_bloc' value='".$row['id_bloc_libre']."' />"
90                .(isset($_POST['retour']) ? "<input type='hidden' name='retour' value='".$_POST['retour']."' />" : "")
91                ."<input type='text' name='titre' value='".htmlspecialchars($row['titre'], ENT_QUOTES)."' maxlength='255' size='50' style='width:90%; color:#666; font-weight:bold;' />"
92                ."<textarea name='texte' cols='50' style='width:90%; color:#444;' rows='4'>".htmlspecialchars($row['contenu'])."</textarea>"
93                ."<br /><br />"._T('arty:bloc_lien')."<br />"
94                ."<input type='text' name='lien' value='".htmlspecialchars($row['lien'], ENT_QUOTES)."' maxlength='255' size='50' style='width:90%' />"
95                ."<br /><br />"._T('arty:bloc_image')."<br />"
96                ."<input type=\"file\" name=\"illu_bloc_libre\" size=\"55\" style='width:90%' /><br /><br /><br />"
97      ."<input type='submit' value='".(isset($_POST['retour']) ? _T("arty:modifier_et_retour") : _T("arty:enregistrer") )."' class='fondo' style='float:right; margin-right:45px;' />"
98      ._T("arty:attention_modif_globale")."<br />"
99                ."</form>"
100                  ."<form action='".generer_url_ecrire('avance')."' method='post'>\n"
101                ."<input type='hidden' name='action' value='supprimerbloc' />"
102                ."<input type='hidden' name='id_bloc' value='".$row['id_bloc_libre']."' />"
103                ."<br /><div style='text-align:center;'><input type='submit' value='"._T("arty:supprimer_ce_bloc")."' class='fondo' style='background-color:red; border-color:red; font-size:9px; font-weight:normal; margin:10px auto;' /></div>"
104                ."</form></div>";               
105               
106                $visible = ($_POST['bloc'] == $row['id_bloc_libre']) ? true : false;
107               
108                echo block_parfois_visible("bloc".$row['id_bloc_libre'], _T('arty:modifier_ce_bloc'), $texte, '', $visible);
109                echo fin_cadre_trait_couleur();
110        }
111 
112  echo fin_gauche();
113
114echo fin_page();
115
116}
117
118
119function traiter_post() {
120  $message_upload = "";
121       
122        if ($_POST['action']=='nouveaubloc' && isset($_POST['titre']) && isset($_POST['texte']) ) {
123                $titre=trim(addslashes($_POST['titre']));
124                $texte=trim(addslashes($_POST['texte']));
125                $lien=trim(addslashes($_POST['lien']));
126               
127                if($lien=="http://") { $lien=""; }
128
129                if ($titre!="") { // && $texte!="") {
130                        spip_query("INSERT INTO spip_arty_bloclibre(titre, contenu,lien) VALUES('$titre', '$texte', '$lien')");
131                         $result = spip_query("SELECT LAST_INSERT_ID();");
132                         if ($result){
133                                $arr = spip_fetch_array($result);
134                                $id = (int) current($arr);
135                               
136                        if (!is_nan($id)){
137                                $message_upload = traiter_upload_image('illu_bloc_libre','illu-bloc-libre',$id);
138                                        }
139                                        }               
140                }
141        }
142       
143        if ($_POST['action']=='supprimerbloc' && isset($_POST['id_bloc'])) {
144               
145                $id_bloc=(int) $_POST['id_bloc'];
146
147                if (!is_nan($id_bloc)) {
148                        spip_query("DELETE FROM spip_arty_bloclibre WHERE id_bloc_libre= $id_bloc");
149                        supprimer_illu_bloc($id_bloc);
150                       
151                        // supprimer les associations
152                        spip_query("DELETE FROM spip_arty_bloclibreassoc WHERE id_bloc_libre= $id_bloc");
153                }
154        }
155       
156        if ($_POST['action']=='supprimerillu' && isset($_POST['id_bloc'])) {
157               
158                $id_bloc=(int) $_POST['id_bloc'];
159
160                if (!is_nan($id_bloc)) {
161                        //spip_query("DELETE FROM spip_arty_bloclibre WHERE id_bloc_libre= $id_bloc");
162                        supprimer_illu_bloc($id_bloc);
163                }
164        }
165
166       
167        if ($_POST['action']=='modifierbloc' && isset($_POST['id_bloc']) && isset($_POST['titre']) && isset($_POST['texte']) ) {
168       
169        //print_r($_POST);
170                $id_bloc=(int) $_POST['id_bloc'];
171                $titre=trim(addslashes($_POST['titre']));
172                $texte=trim(addslashes($_POST['texte']));
173                $lien=trim(addslashes($_POST['lien']));
174                if($lien=="http://") { $lien=""; }
175
176                if ($titre!="" && !is_nan($id_bloc)) {
177                        spip_query("UPDATE spip_arty_bloclibre SET titre='$titre', contenu='$texte', lien='$lien' WHERE id_bloc_libre=$id_bloc");
178                        $message_upload = traiter_upload_image('illu_bloc_libre','illu-bloc-libre',$id_bloc);
179                }
180               
181                //redirection vers la page d'origine
182                if (isset($_POST['retour'])) {
183      header('Location: '.$_POST['retour']);
184    }
185               
186        }
187
188        return $message_upload;
189
190}
191
192
193function supprimer_illu_bloc($id_bloc) {
194        //$chem = creer_repertoire_documents("illu-bloc-libre");
195        $chem = _DIR_DOC."illu-bloc-libre/";
196      $handle = @opendir($chem);       
197      while($fichier = @readdir($handle)) {
198        if (!$id_bloc) {
199          if (ereg("^illu_bloc_libre\.(jpg|png|gif)$", $fichier)){
200            @unlink($chem.$fichier);
201          }
202        } else {
203          if (ereg("^illu_bloc_libre-$id_bloc\.(jpg|png|gif)$", $fichier)){
204            @unlink($chem.$fichier);
205          }
206        }
207      } 
208}
209
210function traiter_get() {
211        //print_r($_GET);
212       
213        $param_accepte=array('edito');
214       
215if(isset($_GET['ajouter']) && isset($_GET['verif'])){
216        $param=$_GET['ajouter'];
217        if(in_array($param, $param_accepte) && $_GET['verif']==$_SESSION['id_check']) {
218               
219                        if(isset($_GET['id_rubrique'])) {
220                        $id_rubrique=(int) $_GET['id_rubrique'];
221                       
222                        if(is_numeric($id_rubrique)){
223                                $resultat = spip_query("SELECT * FROM spip_arty_paramassoc WHERE param = '$param' AND id_rubrique = $id_rubrique");
224                                if(!spip_num_rows($resultat)) {
225                                        spip_query("INSERT INTO spip_arty_paramassoc (param, id_rubrique) VALUES ('$param', $id_rubrique)");
226                                        }
227                                       
228                                }
229                       
230                        } elseif(isset($_GET['id_article'])) {
231                        $id_article=(int) $_GET['id_article'];
232                       
233                        if(is_numeric($id_article)){
234                                $resultat = spip_query("SELECT * FROM spip_arty_paramassoc WHERE param = '$param' AND id_article = $id_article");
235                                if(!spip_num_rows($resultat)) {
236                                        spip_query("INSERT INTO spip_arty_paramassoc (param, id_article) VALUES ('$param', $id_article)");
237                                        }
238                                       
239                                }
240                       
241                        }
242                       
243               
244                }
245       
246        } 
247       
248        if(isset($_GET['supprimer']) && isset($_GET['verif'])){
249                $id_assoc=(int) $_GET['supprimer'];
250                if( is_numeric($id_assoc) && $_GET['verif']==$_SESSION['id_check']) {
251                        spip_query("DELETE FROM spip_arty_paramassoc WHERE id_assoc = $id_assoc");
252                }
253        }
254       
255        }
256       
257
258?>
Note: See TracBrowser for help on using the repository browser.