Changeset 25560 in spip-zone
- Timestamp:
- Dec 27, 2008, 8:10:26 PM (12 years ago)
- Location:
- _plugins_/_dev_/champs_extras
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/_dev_/champs_extras/core/inc/cextras.php
r25559 r25560 8 8 var $type = 'textarea'; // type (input/textarea) 9 9 var $sql = ''; // declaration sql (text NOT NULL DEFAULT '') 10 11 var $_id = ''; // identifiant de ce champ extra 10 12 11 13 // constructeur … … 26 28 } 27 29 } 30 // calculer l'id du champ extra 31 $this->make_id(); 28 32 } 29 33 … … 36 40 } 37 41 38 // transformer en tableau PHP les variable de la classe. 42 // creer l'id du champ extra : 43 function make_id(){ 44 // creer un hash 45 $hash = array(); 46 foreach ($this as $cle=>$val) { 47 if ($cle[0]!=='_') { 48 $hash[] = $val; 49 } 50 } 51 $this->_id = substr(md5(serialize($hash)),0,6); 52 } 53 54 // determiner un identifiant 55 function get_id(){ 56 if (!$this->_id) $this->make_id(); 57 return $this->_id; 58 } 59 60 // transformer en tableau PHP les variable publiques de la classe. 39 61 function toArray(){ 40 62 $extra = array(); 41 63 foreach ($this as $cle=>$val) { 42 $extra[$cle] = $val; 64 if ($cle[0]!=='_') { 65 $extra[$cle] = $val; 66 } 43 67 } 68 $extra['id_extra'] = $this->get_id(); 44 69 return $extra; 45 70 } -
_plugins_/_dev_/champs_extras/extensions/interface/action/iextras.php
r25559 r25560 15 15 } 16 16 17 list($arg, $id ) = explode ('/', $arg);17 list($arg, $id_extra) = explode ('/', $arg); 18 18 19 19 // actions possibles … … 26 26 27 27 // cas de suppression 28 if ($ arg == 'supprimer_extra'){28 if ($id_extra and ($arg == 'supprimer_extra')){ 29 29 include_spip('inc/iextras'); 30 30 $extras = iextras_get_extras(); 31 if ($id = intval($id)) { 32 // $id a 1 de plus 33 $extra = $extras[--$id]; 34 unset($extras[$id]); 35 iextras_set_extras($extras); 36 37 extras_log("Suppression d'un champ par auteur n°".$GLOBALS['auteur_session']['id_auteur'],true); 38 extras_log($extra, true); 39 $table = table_objet_sql($extra->table); 40 sql_alter("TABLE $table DROP ".$extra->champ); 31 foreach($extras as $i=>$e) { 32 if ($e->get_id() == $id_extra) { 33 extras_log("Suppression d'un champ par auteur ".$GLOBALS['auteur_session']['id_auteur'],true); 34 extras_log($extra, true); 35 36 $table = table_objet_sql($extra->table); 37 sql_alter("TABLE $table DROP ".$extra->champ); 38 39 unset($extras[$i]); 40 iextras_set_extras($extras); 41 break; 42 } 41 43 } 42 44 } -
_plugins_/_dev_/champs_extras/extensions/interface/exec/iextras_edit.php
r25554 r25560 39 39 40 40 // contenu 41 $id_extra = intval(_request('id_extra'));41 $id_extra = _request('id_extra'); 42 42 $id_extra = $id_extra ? $id_extra : 'new' ; 43 43 echo recuperer_fond('prive/editer/champs_extras', array( 44 'id_extra' =>$id_extra,45 'titre' =>$id_extra=='new' ? _T('iextras:info_nouveau_champ_extra') : _T('iextras:info_modifier_champ_extra'),46 'redirect' =>generer_url_ecrire("iextras"),47 'icone_retour' =>icone_inline(_T('icone_retour'), generer_url_ecrire('iextras'), find_in_path("images/iextras-24.png"), "rien.gif",$GLOBALS['spip_lang_left']),44 'id_extra' => $id_extra, 45 'titre' => $id_extra=='new' ? _T('iextras:info_nouveau_champ_extra') : _T('iextras:info_modifier_champ_extra'), 46 'redirect' => generer_url_ecrire("iextras"), 47 'icone_retour' => icone_inline(_T('icone_retour'), generer_url_ecrire('iextras'), find_in_path("images/iextras-24.png"), "rien.gif",$GLOBALS['spip_lang_left']), 48 48 )); 49 49 -
_plugins_/_dev_/champs_extras/extensions/interface/formulaires/editer_champ_extra.html
r25554 r25560 85 85 [(#REM) ajouter les saisies supplementaires : extra et autre, a cet endroit ] 86 86 <!--extra--> 87 <p class='boutons'><input type='submit' class='submit' value='[(#ENV{ id_extra}|intval|?{<:bouton_modifier:>,<:bouton_ajouter:>})]' /></p>87 <p class='boutons'><input type='submit' class='submit' value='[(#ENV{new}|?{<:bouton_ajouter:>,<:bouton_modifier:>})]' /></p> 88 88 </div></form> 89 89 </BOUCLE_si_editable> -
_plugins_/_dev_/champs_extras/extensions/interface/formulaires/editer_champ_extra.php
r25559 r25560 5 5 6 6 function formulaires_editer_champ_extra_charger_dist($id_extra='new', $redirect=''){ 7 // nouveau ? 8 $new = ($id_extra == 'new') ? ' ': ''; 9 7 10 // valeur par defaut 8 11 $valeurs = array( … … 13 16 'sql' => "text NOT NULL DEFAULT ''", 14 17 'id_extra' => $id_extra, 15 'new' => intval($id_extra)?'':' ',18 'new' => $new, 16 19 'redirect' => $redirect, 17 20 ); … … 19 22 // si un extra est demande (pour edition) 20 23 // remplir les valeurs avec infos de celui-ci 21 if ( intval($id_extra)) {24 if (!$new) { 22 25 $extras = iextras_get_extras(); 23 // $id_extra = 1, mais l'entree reelle est 0 dans le tableau 24 if ($extra = $extras[--$id_extra]) { 25 $valeurs = array_merge($valeurs, $extra->toArray()); 26 foreach($extras as $extra) { 27 if ($extra->get_id() == $id_extra) { 28 $valeurs = array_merge($valeurs, $extra->toArray()); 29 break; 30 } 26 31 } 27 32 } … … 32 37 function formulaires_editer_champ_extra_verifier_dist($id_extra='new', $redirect=''){ 33 38 $erreurs = array(); 39 40 // nouveau ? 41 $new = ($id_extra == 'new') ? ' ': ''; 34 42 35 43 // recuperer les valeurs postees … … 54 62 // n'existe pas deja sur la meme table 55 63 $extras = iextras_get_extras(); 56 if (!intval($id_extra) 57 // $id_extra = 1, mais l'entree reelle est 0 dans le tableau 58 OR ($extras[--$id_extra]->champ !== $champ)) { 59 foreach ($extras as $i=>$e) { 60 if (($i !== $id_extra) 61 and ($e->champ == $champ) 62 and ($e->table == $extra['table'])) { 63 $erreurs['champ'] = _T('iextras:champ_deja_existant'); 64 foreach ($extras as $e) { 65 if ($new OR ($e->get_id() !== $id_extra)) { 66 if (($e->champ == $champ) and ($e->table == $extra['table'])) { 67 $erreurs['champ'] = _T('iextras:champ_deja_existant'); 68 break; 64 69 } 65 70 } 66 71 } 72 67 73 68 74 return $erreurs; … … 71 77 72 78 function formulaires_editer_champ_extra_traiter_dist($id_extra='new', $redirect=''){ 73 79 // nouveau ? 80 $new = ($id_extra == 'new') ? ' ': ''; 81 74 82 // recuperer les valeurs postees 75 83 $extra = iextras_post_formulaire(); … … 77 85 // recreer le tableau de stockage des extras 78 86 $extras = iextras_get_extras(); 79 $new = false; 80 if (intval($id_extra)) {81 // $id_extra = 1, mais l'entree reelle est 0 dans le tableau82 $extras[ --$id_extra] = new ChampExtra($extra);87 88 // ajout du champ ou modification du champ extra de meme id. 89 if ($new) { 90 $extras[] = new ChampExtra($extra); 83 91 } else { 84 $extras[] = new ChampExtra($extra); 85 $new = true; 92 foreach($extras as $i=>$e) { 93 if ($e->get_id() == $id_extra) { 94 $extras[$i] = new ChampExtra($extra); 95 break; 96 } 97 } 86 98 } 99 87 100 // l'enregistrer 88 101 iextras_set_extras($extras); … … 92 105 include_spip('base/create'); 93 106 $table = table_objet_sql($extra['table']); 94 extras_log("Creation d'un nouveau champ par auteur n°".$GLOBALS['auteur_session']['id_auteur'],true);107 extras_log("Creation d'un nouveau champ par auteur ".$GLOBALS['auteur_session']['id_auteur'],true); 95 108 extras_log($extra, true); 96 109 maj_tables($table); -
_plugins_/_dev_/champs_extras/extensions/interface/inc/iextras.php
r25559 r25560 22 22 $extras = iextras_get_extras(); 23 23 $tables = array(); 24 foreach($extras as $ i=>$e) {24 foreach($extras as $e) { 25 25 if (!isset($tables[$e->table])) { 26 26 $tables[$e->table] = array(); 27 27 } 28 $tables[$e->table][ $i] = $e->toArray();28 $tables[$e->table][] = $e->toArray(); 29 29 } 30 30 return $tables; -
_plugins_/_dev_/champs_extras/extensions/interface/prive/contenu/champs_extras.html
r25554 r25560 8 8 <li> 9 9 [(#VALEUR|table_valeur{champ})] 10 | <a href="[(#URL_ECRIRE{iextras_edit}|parametre_url{id_extra,# CLE|plus{1}})]"><:iextras:action_modifier:></a>11 | <a href="[(#URL_ACTION_AUTEUR{iextras, [supprimer_extra/(# CLE|plus{1})], #SELF})]" class="supprimer"><:iextras:action_supprimer:></a>10 | <a href="[(#URL_ECRIRE{iextras_edit}|parametre_url{id_extra,#VALEUR|table_valeur{id_extra}})]"><:iextras:action_modifier:></a> 11 | <a href="[(#URL_ACTION_AUTEUR{iextras, [supprimer_extra/(#VALEUR|table_valeur{id_extra})], #SELF})]" class="supprimer"><:iextras:action_supprimer:></a> 12 12 </li> 13 13 </BOUCLE_extras>
Note: See TracChangeset
for help on using the changeset viewer.