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