Changeset 10987 for extensions/typetags


Ignore:
Timestamp:
May 22, 2011, 12:52:49 PM (13 years ago)
Author:
mistic100
Message:

code cleanup

Location:
extensions/typetags
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/typetags/admin.php

    r9863 r10987  
    66function get_color_text($color)
    77{
    8         if (strlen($color) == 7)
    9         {
    10                 $rgb[] = hexdec(substr($color, 1, 2))/255;
    11                 $rgb[] = hexdec(substr($color, 3, 2))/255;
    12                 $rgb[] = hexdec(substr($color, 5, 2))/255;
    13         }
    14         else if (strlen($color) == 4)
    15         {
    16                 $rgb[] = hexdec(substr($color, 1, 1))/15;
    17                 $rgb[] = hexdec(substr($color, 2, 1))/15;
    18                 $rgb[] = hexdec(substr($color, 3, 1))/15;
    19         }
    20         $l = (min($rgb) + max($rgb)) / 2;
    21         return $l > 0.45 ? '#000' : '#fff';
     8  if (strlen($color) == 7)
     9  {
     10    $rgb[] = hexdec(substr($color, 1, 2))/255;
     11    $rgb[] = hexdec(substr($color, 3, 2))/255;
     12    $rgb[] = hexdec(substr($color, 5, 2))/255;
     13  }
     14  else if (strlen($color) == 4)
     15  {
     16    $rgb[] = hexdec(substr($color, 1, 1))/15;
     17    $rgb[] = hexdec(substr($color, 2, 1))/15;
     18    $rgb[] = hexdec(substr($color, 3, 1))/15;
     19  }
     20  $l = (min($rgb) + max($rgb)) / 2;
     21  return $l > 0.45 ? '#000' : '#fff';
    2222}
    2323
     
    2828if (isset($_POST['edittypetag']) and (empty($_POST['typetag_name']) or empty($_POST['typetag_color'])))
    2929{
    30         $edited_typetag = array(
    31                 'id' => $_POST['edited_typetag'],
    32                 'name' => $_POST['typetag_name'],
    33                 'color' => $_POST['typetag_color'],
    34         );
    35         $page['errors'][] = l10n('typetag_error');
     30  $edited_typetag = array(
     31    'id' => $_POST['edited_typetag'],
     32    'name' => $_POST['typetag_name'],
     33    'color' => $_POST['typetag_color'],
     34  );
     35  $page['errors'][] = l10n('typetag_error');
    3636}
    3737else if (isset($_POST['edittypetag']))
    3838{
    39         $typetag = mysql_escape_string($_POST['edited_typetag']);
    40         $typetag_name = mysql_escape_string($_POST['typetag_name']);
    41         $typetag_color = mysql_escape_string($_POST['typetag_color']);
    42 
    43         $all_typetags = pwg_query("
    44                 SELECT
    45                         id,
    46                         name,
    47                         color
    48                 FROM  `". typetags_TABLE ."`;
    49         ");
    50        
    51         while ($row = mysql_fetch_array($all_typetags))
    52         {
    53                 $existing_names[] = $row['name'];
    54                 if ($typetag == $row['id'])
    55                 {
    56                         $current_name = $row['name'];
    57                         $current_color = $row['color'];
    58                 }
    59         }
    60 
    61         // we must not rename typetag with an already existing name
    62         if ($typetag_name != $current_name AND in_array($typetag_name, $existing_names))
    63         {
    64                 $edited_typetag = array(
    65                         'id' => $typetag,
    66                         'name' => $typetag_name,
    67                         'color' => $typetag_color,
    68                 );
    69                
    70                 $page['errors'][] = l10n('typetag_already_exists');
    71         }
    72         else
    73         {
    74                 pwg_query("
    75                         UPDATE `". typetags_TABLE ."` SET
    76                                 `name` = '". $typetag_name ."',
    77                                 `color` = '". $typetag_color ."'
    78                         WHERE `id` = ". $typetag .";
    79                 ");
    80                
    81                 $page['infos'][] = l10n('typetag_saved');
    82         }
     39  $typetag = mysql_escape_string($_POST['edited_typetag']);
     40  $typetag_name = mysql_escape_string($_POST['typetag_name']);
     41  $typetag_color = mysql_escape_string($_POST['typetag_color']);
     42
     43  $all_typetags = pwg_query("
     44    SELECT
     45      id,
     46      name,
     47      color
     48    FROM  `". typetags_TABLE ."`;
     49  ");
     50 
     51  while ($row = mysql_fetch_array($all_typetags))
     52  {
     53    $existing_names[] = $row['name'];
     54    if ($typetag == $row['id'])
     55    {
     56      $current_name = $row['name'];
     57      $current_color = $row['color'];
     58    }
     59  }
     60
     61  // we must not rename typetag with an already existing name
     62  if ($typetag_name != $current_name AND in_array($typetag_name, $existing_names))
     63  {
     64    $edited_typetag = array(
     65      'id' => $typetag,
     66      'name' => $typetag_name,
     67      'color' => $typetag_color,
     68    );
     69   
     70    $page['errors'][] = l10n('typetag_already_exists');
     71  }
     72  else
     73  {
     74    pwg_query("
     75      UPDATE `". typetags_TABLE ."` SET
     76        `name` = '". $typetag_name ."',
     77        `color` = '". $typetag_color ."'
     78      WHERE `id` = ". $typetag .";
     79    ");
     80   
     81    $page['infos'][] = l10n('typetag_saved');
     82  }
    8383}
    8484
     
    8989if (isset($_GET['deletetypetag']))
    9090{
    91         $query = "
    92                 SELECT name
    93                 FROM `". typetags_TABLE ."`
    94                 WHERE id = ". $_GET['deletetypetag'] .";
    95         ";
    96         $typetag_name = array_from_query($query, 'name');
    97        
    98         if (count($typetag_name) != 0)
    99         {
    100                 pwg_query("
    101                         UPDATE `". TAGS_TABLE ."`
    102                         SET id_typetags = NULL
    103                         WHERE id_typetags = ". $_GET['deletetypetag'] .";
    104                 ");
    105 
    106                 pwg_query("
    107                         DELETE FROM `". typetags_TABLE ."`
    108                         WHERE id = ". $_GET['deletetypetag'] .";
    109                 ");
    110 
    111                 $page['infos'][] = l10n('typetag_suppr').' : '.$typetag_name[0];
    112         }
    113         else
    114         {
    115                 $page['errors'][] = l10n('typetag_unknown').' : '.$_GET['deletetypetag'];
    116         }
     91  $query = "
     92    SELECT name
     93    FROM `". typetags_TABLE ."`
     94    WHERE id = ". $_GET['deletetypetag'] .";
     95  ";
     96  $typetag_name = array_from_query($query, 'name');
     97 
     98  if (count($typetag_name) != 0)
     99  {
     100    pwg_query("
     101      UPDATE `". TAGS_TABLE ."`
     102      SET id_typetags = NULL
     103      WHERE id_typetags = ". $_GET['deletetypetag'] .";
     104    ");
     105
     106    pwg_query("
     107      DELETE FROM `". typetags_TABLE ."`
     108      WHERE id = ". $_GET['deletetypetag'] .";
     109    ");
     110
     111    $page['infos'][] = l10n('typetag_suppr').' : '.$typetag_name[0];
     112  }
     113  else
     114  {
     115    $page['errors'][] = l10n('typetag_unknown').' : '.$_GET['deletetypetag'];
     116  }
    117117}
    118118
     
    123123if (isset($_POST['addtypetag']) and (empty($_POST['typetag_name']) or empty($_POST['typetag_color'])))
    124124{
    125         $template->assign('typetag', array(
    126                 'NAME' => isset($_POST['typetag_name']) ? $_POST['typetag_name'] : '',
    127                 'COLOR' => isset($_POST['typetag_color']) ? $_POST['typetag_color'] : '',
    128         ));
    129        
    130         $page['errors'][] = l10n('typetag_error');
     125  $template->assign('typetag', array(
     126    'NAME' => isset($_POST['typetag_name']) ? $_POST['typetag_name'] : '',
     127    'COLOR' => isset($_POST['typetag_color']) ? $_POST['typetag_color'] : '',
     128  ));
     129 
     130  $page['errors'][] = l10n('typetag_error');
    131131}
    132132else if (isset($_POST['addtypetag']))
    133133{
    134         $typetag_name = $_POST['typetag_name'];
    135         $typetag_color = $_POST['typetag_color'];
    136 
    137         // does the tag already exists?
    138         $query = "
    139                 SELECT id
    140                 FROM `". typetags_TABLE ."`
    141                 WHERE name = '". $typetag_name ."';
    142         ";
    143         $existing_tags = array_from_query($query, 'id');
    144 
    145         if (count($existing_tags) == 0)
    146         {
    147                 pwg_query("
    148                         INSERT INTO `". typetags_TABLE ."`(
    149                                 `name`,
    150                                 `color`
    151                         )
    152                         VALUES(
    153                                 '". $typetag_name ."',
    154                                 '". $typetag_color ."'
    155                         );
    156                 ");
    157 
    158                 $page['infos'][] = l10n('typetag_saved');
    159         }
    160         else
    161         {
    162                 $template->assign('typetag', array(
    163                         'NAME' => $typetag_name,
    164                         'COLOR' => $typetag_color,
    165                 ));
    166                
    167                 $page['errors'][] = l10n('typetag_already_exists');
    168         }
     134  $typetag_name = $_POST['typetag_name'];
     135  $typetag_color = $_POST['typetag_color'];
     136
     137  // does the tag already exists?
     138  $query = "
     139    SELECT id
     140    FROM `". typetags_TABLE ."`
     141    WHERE name = '". $typetag_name ."';
     142  ";
     143  $existing_tags = array_from_query($query, 'id');
     144
     145  if (count($existing_tags) == 0)
     146  {
     147    pwg_query("
     148      INSERT INTO `". typetags_TABLE ."`(
     149        `name`,
     150        `color`
     151      )
     152      VALUES(
     153        '". $typetag_name ."',
     154        '". $typetag_color ."'
     155      );
     156    ");
     157
     158    $page['infos'][] = l10n('typetag_saved');
     159  }
     160  else
     161  {
     162    $template->assign('typetag', array(
     163      'NAME' => $typetag_name,
     164      'COLOR' => $typetag_color,
     165    ));
     166   
     167    $page['errors'][] = l10n('typetag_already_exists');
     168  }
    169169}
    170170
     
    175175if (isset($_POST['delete_all_assoc']))
    176176{
    177         pwg_query("UPDATE `". TAGS_TABLE ."` SET id_typetags = NULL;");
    178         $page['infos'][] = l10n('All associations have been removed');
     177  pwg_query("UPDATE `". TAGS_TABLE ."` SET id_typetags = NULL;");
     178  $page['infos'][] = l10n('All associations have been removed');
    179179
    180180}
    181181else if (isset($_POST['associations']))
    182182{
    183                 // beautify the parameters array
    184                 $string = preg_replace('#[;]$#', '', $_POST['associations']);
    185                 $associations = array();
    186                 $a = explode(';', $string);
    187                
    188                 foreach ($a as $s)
    189                 {
    190                    $v = explode(':', $s);
    191                    $associations[ltrim($v[0],'t-')] = ltrim($v[1],'tt-');
    192                 }
    193 
    194                 // save associations
    195                 foreach ($associations AS $tag => $typetag)
    196                 {
    197                         pwg_query("
    198                                 UPDATE `". TAGS_TABLE ."`
    199                                 SET id_typetags = ". $typetag ."
    200                                 WHERE id = ". $tag .";
    201                         ");
    202                 }
    203                
    204                 $page['infos'][] = l10n('typetags_associated');
     183    // beautify the parameters array
     184    $string = preg_replace('#[;]$#', '', $_POST['associations']);
     185    $associations = array();
     186    $a = explode(';', $string);
     187   
     188    foreach ($a as $s)
     189    {
     190       $v = explode(':', $s);
     191       $associations[ltrim($v[0],'t-')] = ltrim($v[1],'tt-');
     192    }
     193
     194    // save associations
     195    foreach ($associations AS $tag => $typetag)
     196    {
     197      pwg_query("
     198        UPDATE `". TAGS_TABLE ."`
     199        SET id_typetags = ". $typetag ."
     200        WHERE id = ". $tag .";
     201      ");
     202    }
     203   
     204    $page['infos'][] = l10n('typetags_associated');
    205205}
    206206
     
    214214// Récupère tous les tags
    215215$all_tags = pwg_query("
    216         SELECT
    217                 t.id as tagid,
    218                 t.name as tagname,
    219                 tt.id as typetagid,
    220                 tt.name as typetagname
    221         FROM `". TAGS_TABLE ."` as t
    222         LEFT JOIN `". typetags_TABLE ."` as tt
    223         ON  t.id_typetags = tt.id
    224         ORDER BY t.name ASC;
     216  SELECT
     217    t.id as tagid,
     218    t.name as tagname,
     219    tt.id as typetagid,
     220    tt.name as typetagname
     221  FROM `". TAGS_TABLE ."` as t
     222  LEFT JOIN `". typetags_TABLE ."` as tt
     223  ON  t.id_typetags = tt.id
     224  ORDER BY t.name ASC;
    225225");
    226226
    227227while ($row = pwg_db_fetch_assoc($all_tags)) {
    228         if ($row['typetagname'] == null) $row['typetagid'] = 'NULL';
    229         $template->append('typetags_association', $row);
     228  if ($row['typetagname'] == null) $row['typetagid'] = 'NULL';
     229  $template->append('typetags_association', $row);
    230230}
    231231
     
    235235while ($row = mysql_fetch_assoc($all_typetags))
    236236{
    237         $row['color_text'] = get_color_text($row['color']);
    238         $row['u_edit'] = typetags_ADMIN . '&edittypetag=' . $row['id'];
    239         $row['u_delete'] = typetags_ADMIN . '&deletetypetag=' . $row['id'];
    240        
    241         $template->append('typetags_selection', $row);
     237  $row['color_text'] = get_color_text($row['color']);
     238  $row['u_edit'] = typetags_ADMIN . '&edittypetag=' . $row['id'];
     239  $row['u_delete'] = typetags_ADMIN . '&deletetypetag=' . $row['id'];
     240 
     241  $template->append('typetags_selection', $row);
    242242}
    243243
    244244// formualire d'édition
    245245if (isset($_GET['edittypetag'])) {
    246         $edited_typetag['id'] = $_GET['edittypetag'];
     246  $edited_typetag['id'] = $_GET['edittypetag'];
    247247}
    248248
    249249if (isset($edited_typetag['id']))
    250250{
    251         $template->assign('edited_typetag', $edited_typetag['id']);
    252 
    253         $tag = pwg_query("
    254                 SELECT
    255                         id,
    256                         name,
    257                         color
    258                 FROM `". typetags_TABLE ."`
    259                 WHERE id = ".$edited_typetag['id'].";
    260         ");
    261         $row = pwg_db_fetch_assoc($tag);
    262 
    263         $template->assign('typetag', array(
    264                 'ID' => $row['id'],
    265                 'OLD_NAME' => $row['name'],
    266                 'OLD_COLOR' => $row['color'],
    267                 'COLOR_TEXT' => get_color_text($row['color']),
    268                 'NAME' => isset($edited_typetag['name']) ? $edited_typetag['name'] : $row['name'],
    269                 'COLOR'=> isset($edited_typetag['color']) ? $edited_typetag['color'] : $row['color'],
    270         ));
     251  $template->assign('edited_typetag', $edited_typetag['id']);
     252
     253  $tag = pwg_query("
     254    SELECT
     255      id,
     256      name,
     257      color
     258    FROM `". typetags_TABLE ."`
     259    WHERE id = ".$edited_typetag['id'].";
     260  ");
     261  $row = pwg_db_fetch_assoc($tag);
     262
     263  $template->assign('typetag', array(
     264    'ID' => $row['id'],
     265    'OLD_NAME' => $row['name'],
     266    'OLD_COLOR' => $row['color'],
     267    'COLOR_TEXT' => get_color_text($row['color']),
     268    'NAME' => isset($edited_typetag['name']) ? $edited_typetag['name'] : $row['name'],
     269    'COLOR'=> isset($edited_typetag['color']) ? $edited_typetag['color'] : $row['color'],
     270  ));
    271271}
    272272
  • extensions/typetags/admin/typetags_admin.tpl

    r9970 r10987  
    77{footer_script}
    88{literal}
    9         $(document).ready(function(){
    10                 // colorpicker
    11                 $('#colorpicker').farbtastic('#hexval');
     9  $(document).ready(function(){
     10    // colorpicker
     11    $('#colorpicker').farbtastic('#hexval');
    1212
    13                 // déplace chaque élément dans la bonne case
    14                 jQuery('ul#tt-NULL li').each(function() {
    15                         var $target = jQuery('ul#' + jQuery(this).attr('title'));
    16                         jQuery(this).appendTo($target).css('float', 'left');
    17                 });
    18                
    19                 // initialise les déplacement
    20                 jQuery("li").draggable({
    21                         revert: "invalid",
    22                         helper: "clone",
    23                         cursor: "move"
    24                 });
     13    // déplace chaque élément dans la bonne case
     14    jQuery('ul#tt-NULL li').each(function() {
     15      var $target = jQuery('ul#' + jQuery(this).attr('title'));
     16      jQuery(this).appendTo($target).css('float', 'left');
     17    });
     18   
     19    // initialise les déplacement
     20    jQuery("li").draggable({
     21      revert: "invalid",
     22      helper: "clone",
     23      cursor: "move"
     24    });
    2525
    26                 // initialise le dépôt
    27                 jQuery('.tt-container').droppable({
    28                         accept: "li",
    29                         hoverClass: "active",
    30                         drop: function(event, ui) {
    31                                 var $gallery = this;
    32                                 ui.draggable.fadeOut(function() {
    33                                         jQuery(this).appendTo($gallery).fadeIn();
    34                                         equilibrate(); // on rééquilibre les colonnes à chaque déplacement
    35                                 });                     
    36                         }
    37                 });
    38                
    39                 // équilibrage des colonnes
    40                 equilibrate();
    41         });
    42                        
    43         function equilibrate() {
    44                 jQuery("#associations").each(function(){
    45                         var h=0;
    46                         jQuery("> ul", this).css('height', 'auto')
    47                                 .each(function(){ h=Math.max(h,jQuery(this).height()); })
    48                                 .css({'height': h+'px'});
    49                 });
    50         }
    51        
    52         // génération des couples tag:typetag avant de valider le formulaire
    53         function save_datas(form) {
    54                 var out = '';
    55                
    56                 jQuery(".tt-container").each(function(){
    57                         var section = jQuery(this).attr('id');
    58                         jQuery("> li", this).each(function(){
    59                                 out += jQuery(this).attr('id') + ':' + section + ';';
    60                         });
    61                 });
    62                
    63                 jQuery('#assoc-input').val(out);
    64                 submit(form);
    65         }
     26    // initialise le dépôt
     27    jQuery('.tt-container').droppable({
     28      accept: "li",
     29      hoverClass: "active",
     30      drop: function(event, ui) {
     31        var $gallery = this;
     32        ui.draggable.fadeOut(function() {
     33          jQuery(this).appendTo($gallery).fadeIn();
     34          equilibrate(); // on rééquilibre les colonnes à chaque déplacement
     35        });     
     36      }
     37    });
     38   
     39    // équilibrage des colonnes
     40    equilibrate();
     41  });
     42     
     43  function equilibrate() {
     44    jQuery("#associations").each(function(){
     45      var h=0;
     46      jQuery("> ul", this).css('height', 'auto')
     47        .each(function(){ h=Math.max(h,jQuery(this).height()); })
     48        .css({'height': h+'px'});
     49    });
     50  }
     51 
     52  // génération des couples tag:typetag avant de valider le formulaire
     53  function save_datas(form) {
     54    var out = '';
     55   
     56    jQuery(".tt-container").each(function(){
     57      var section = jQuery(this).attr('id');
     58      jQuery("> li", this).each(function(){
     59        out += jQuery(this).attr('id') + ':' + section + ';';
     60      });
     61    });
     62   
     63    jQuery('#assoc-input').val(out);
     64    submit(form);
     65  }
    6666{/literal}
    6767{/footer_script}
    6868
    6969<div class="titrePage">
    70         <h2>TypeT@gs</h2>
     70  <h2>TypeT@gs</h2>
    7171</div>
    7272
    7373<form action="{$typetags_ADMIN}" method="post" name="form">
    74         <fieldset>
    75         {if isset($edited_typetag)}
    76                 <legend>{'Edit typetag'|@translate}</legend>
    77                 <input type="hidden" name="edited_typetag" value="{$edited_typetag}" />
    78                 <div class="edit-container">
    79                         <div id="colorpicker" style="float:right;"></div>
    80                         <p><b>{'Edited TypeTag'|@translate} : <input type="text" readonly="readonly" size="18" style="background-color:{$typetag.OLD_COLOR};color:{$typetag.COLOR_TEXT};" value="{$typetag.OLD_NAME}"></b></p>
    81                         <p>&nbsp;</p>
    82                         <p>{'New name'|@translate} : <input type="text" size="18" name="typetag_name" value="{$typetag.NAME}"/></p>
    83                         <p>{'New color'|@translate} : <input type="text" id="hexval" name="typetag_color" size="7" maxlength="7" value="{$typetag.COLOR}"/></p>
    84                         <p>&nbsp;</p>
    85                         <p>
    86                                 <input class="submit" type="submit" name="edittypetag" value="{'Modify'|@translate}"/>
    87                                 <input class="submit" type="submit" name="cancel" value="{'Reset'|@translate}"/>
    88                         </p>
    89                 </div>
    90         {else}
    91                 <legend>{'Create a Typetag'|@translate}</legend>
    92                 <div class="edit-container">
    93                         <div id="colorpicker" style="float:right;"></div>
    94                         <p>&nbsp;</p>
    95                         <p>{'New TypeTag'|@translate} : <input type="text" size="18" name="typetag_name" value="{if isset($typetag.NAME)}{$typetag.NAME}{/if}"/></p>
    96                         <p>{'Color TypeTag'|@translate} : <input type="text" id="hexval" name="typetag_color" size="7" maxlength="7" value="{if isset($typetag.COLOR)}{$typetag.COLOR}{else}#444444{/if}"/></p>
    97                         <p>&nbsp;</p>
    98                         <p>
    99                                 <input class="submit" type="submit" name="addtypetag" value="{'Create a Typetag'|@translate}"/>
    100                         </p>
    101                 </div>
    102         {/if}
    103         </fieldset>
     74  <fieldset>
     75  {if isset($edited_typetag)}
     76    <legend>{'Edit typetag'|@translate}</legend>
     77    <input type="hidden" name="edited_typetag" value="{$edited_typetag}" />
     78    <div class="edit-container">
     79      <div id="colorpicker" style="float:right;"></div>
     80      <p><b>{'Edited TypeTag'|@translate} : <input type="text" readonly="readonly" size="18" style="background-color:{$typetag.OLD_COLOR};color:{$typetag.COLOR_TEXT};" value="{$typetag.OLD_NAME}"></b></p>
     81      <p>&nbsp;</p>
     82      <p>{'New name'|@translate} : <input type="text" size="18" name="typetag_name" value="{$typetag.NAME}"/></p>
     83      <p>{'New color'|@translate} : <input type="text" id="hexval" name="typetag_color" size="7" maxlength="7" value="{$typetag.COLOR}"/></p>
     84      <p>&nbsp;</p>
     85      <p>
     86        <input class="submit" type="submit" name="edittypetag" value="{'Modify'|@translate}"/>
     87        <input class="submit" type="submit" name="cancel" value="{'Reset'|@translate}"/>
     88      </p>
     89    </div>
     90  {else}
     91    <legend>{'Create a Typetag'|@translate}</legend>
     92    <div class="edit-container">
     93      <div id="colorpicker" style="float:right;"></div>
     94      <p>&nbsp;</p>
     95      <p>{'New TypeTag'|@translate} : <input type="text" size="18" name="typetag_name" value="{if isset($typetag.NAME)}{$typetag.NAME}{/if}"/></p>
     96      <p>{'Color TypeTag'|@translate} : <input type="text" id="hexval" name="typetag_color" size="7" maxlength="7" value="{if isset($typetag.COLOR)}{$typetag.COLOR}{else}#444444{/if}"/></p>
     97      <p>&nbsp;</p>
     98      <p>
     99        <input class="submit" type="submit" name="addtypetag" value="{'Create a Typetag'|@translate}"/>
     100      </p>
     101    </div>
     102  {/if}
     103  </fieldset>
    104104</form>
    105105
    106         {if !empty($typetags_selection)}
    107         <fieldset>
    108                 <legend>{'TypeTag selection'|@translate}</legend>
    109                 <ul class="tagSelection">
    110                         {foreach from=$typetags_selection item=typetag}
    111                         <li>
    112                                 <input type="text" readonly="readonly" style="background-color:{$typetag.color};color:{$typetag.color_text};margin:5px 0;" value="{$typetag.name}">
    113                                 <a href="{$typetag.u_edit}" title="{'edit'|@translate}"><img src="{$themeconf.icon_dir}/edit.png" class="button" alt="{'edit'|@translate}"/></a>
    114                                 <a href="{$typetag.u_delete}" title="{'delete'|@translate}" onclick="return confirm('{'Are you sure?'|@translate}');"><img src="{$themeconf.admin_icon_dir}/plug_delete.png" class="button" alt="{'delete'|@translate}"/></a>
    115                         </li>
    116                         {/foreach}
    117                 </ul>
    118         </fieldset>
    119         {/if}
     106  {if !empty($typetags_selection)}
     107  <fieldset>
     108    <legend>{'TypeTag selection'|@translate}</legend>
     109    <ul class="tagSelection">
     110      {foreach from=$typetags_selection item=typetag}
     111      <li>
     112        <input type="text" readonly="readonly" style="background-color:{$typetag.color};color:{$typetag.color_text};margin:5px 0;" value="{$typetag.name}">
     113        <a href="{$typetag.u_edit}" title="{'edit'|@translate}"><img src="{$themeconf.icon_dir}/edit.png" class="button" alt="{'edit'|@translate}"/></a>
     114        <a href="{$typetag.u_delete}" title="{'delete'|@translate}" onclick="return confirm('{'Are you sure?'|@translate}');"><img src="{$themeconf.admin_icon_dir}/plug_delete.png" class="button" alt="{'delete'|@translate}"/></a>
     115      </li>
     116      {/foreach}
     117    </ul>
     118  </fieldset>
     119  {/if}
    120120
    121121<form action="{$typetags_ADMIN}" method="post" name="form" onsubmit="save_datas(this);">
    122         {if !empty($typetags_association) and !empty($typetags_selection)}
    123         <fieldset>
    124                 <legend>{'TypeTag association'|@translate}</legend>
    125                
    126                 <ul id="tt-NULL" class="tt-container NULL">
    127                         <h5>Non associés</h5>
    128                         {foreach from=$typetags_association item=tag}
    129                         <li id="t-{$tag.tagid}" title="tt-{$tag.typetagid}">
    130                                 {$tag.tagname}
    131                         </li>
    132                         {/foreach}
    133                 </ul>
    134                
    135                 <div id="associations">
    136                 {foreach from=$typetags_selection item=typetag}
    137                         <ul id="tt-{$typetag.id}" class="tt-container" style="box-shadow:inset 0 0 5px {$typetag.color};">
    138                                 <h5 style="background-color:{$typetag.color};color:{$typetag.color_text};">{$typetag.name}</h5>
    139                         </ul>
    140                 {/foreach}
    141                 </div>
    142                
    143                 <p style="clear:both;">
    144                         <input type="hidden" name="associations" id="assoc-input"/>
    145                         <input class="submit" type="submit" name="associate" value="{'Validate'|@translate}"/>
    146                         <input class="submit" type="submit" name="delete_all_assoc" value="{'Delete all associations'|@translate}" onclick="return confirm('{'Are you sure?'|@translate}');"/>
    147                 </p>
    148         </fieldset>
    149         {/if}
     122  {if !empty($typetags_association) and !empty($typetags_selection)}
     123  <fieldset>
     124    <legend>{'TypeTag association'|@translate}</legend>
     125   
     126    <ul id="tt-NULL" class="tt-container NULL">
     127      <h5>Non associés</h5>
     128      {foreach from=$typetags_association item=tag}
     129      <li id="t-{$tag.tagid}" title="tt-{$tag.typetagid}">
     130        {$tag.tagname}
     131      </li>
     132      {/foreach}
     133    </ul>
     134   
     135    <div id="associations">
     136    {foreach from=$typetags_selection item=typetag}
     137      <ul id="tt-{$typetag.id}" class="tt-container" style="box-shadow:inset 0 0 5px {$typetag.color};">
     138        <h5 style="background-color:{$typetag.color};color:{$typetag.color_text};">{$typetag.name}</h5>
     139      </ul>
     140    {/foreach}
     141    </div>
     142   
     143    <p style="clear:both;">
     144      <input type="hidden" name="associations" id="assoc-input"/>
     145      <input class="submit" type="submit" name="associate" value="{'Validate'|@translate}"/>
     146      <input class="submit" type="submit" name="delete_all_assoc" value="{'Delete all associations'|@translate}" onclick="return confirm('{'Are you sure?'|@translate}');"/>
     147    </p>
     148  </fieldset>
     149  {/if}
    150150</form>
  • extensions/typetags/admin/typetags_style.css

    r9970 r10987  
    11.edit-container {
    2         width: 500px;
    3         margin: auto;
     2  width: 500px;
     3  margin: auto;
    44}
    55
    66ul.tagSelection li {
    7         width:170px !important;
     7  width:170px !important;
    88}
    99.tagSelection input {
    10         width:120px;
     10  width:120px;
    1111}
    1212
    1313.tt-container {
    14         float:left;
    15         width:150px;
    16         min-height:50px;
    17         height:auto;
    18         margin:5px !important;
    19         padding:0 5px 5px 5px;
    20         list-style:none;
    21         background-color:#888;
    22         border-radius:5px;
     14  float:left;
     15  width:150px;
     16  min-height:50px;
     17  height:auto;
     18  margin:5px !important;
     19  padding:0 5px 5px 5px;
     20  list-style:none;
     21  background-color:#888;
     22  border-radius:5px;
    2323}
    2424.tt-container li {
    25         display:inline;
    26         float:none;
    27         padding:2px 8px;
    28         margin:5px;
    29         background-color:#ddd;
    30         box-shadow:1px 1px 0px #fff;
    31         border-radius:5px;
    32         cursor:move;
     25  display:inline;
     26  float:none;
     27  padding:2px 8px;
     28  margin:5px;
     29  background-color:#ddd;
     30  box-shadow:1px 1px 0px #fff;
     31  border-radius:5px;
     32  cursor:move;
    3333}
    3434.tt-container li:hover {
    35         background-color:#c2f5c2;
    36         opacity:0.8;
     35  background-color:#c2f5c2;
     36  opacity:0.8;
    3737}
    3838.tt-container h5 {
    39         margin:0 -5px;
    40         border-radius:5px 5px 0 0;
    41         padding:2px 0;
    42         text-align:center;
    43         font-size:12px;
    44         letter-spacing:0.5em;
    45         font-weight:normal;
     39  margin:0 -5px;
     40  border-radius:5px 5px 0 0;
     41  padding:2px 0;
     42  text-align:center;
     43  font-size:12px;
     44  letter-spacing:0.5em;
     45  font-weight:normal;
    4646}
    4747.active {
    48         background-color:#7cba0f;
     48  background-color:#7cba0f;
    4949}
    5050
    5151.tt-container.NULL {
    52         width:98%;
    53         box-shadow:inset 0 0 5px #bbb;
    54         padding-bottom:10px;
     52  width:98%;
     53  box-shadow:inset 0 0 5px #bbb;
     54  padding-bottom:10px;
    5555}
    5656.tt-container.NULL h5 {
    57         background-color:#bbb;
    58         font-weight:bold;
     57  background-color:#bbb;
     58  font-weight:bold;
    5959}
  • extensions/typetags/language/it_IT/plugin.lang.php

    r10286 r10987  
    33/* section */
    44$lang['Create a Typetag'] = 'Creare un TypeTag';
    5 $lang['Edit typetag'] = 'Modificare il TypeTag';
    6 $lang['TypeTag selection'] = 'Modificare - Cancellare dei TypeTags';
    7 $lang['TypeTag association'] = 'Associare - Dissociare dei TypeTags';
     5$lang['Edit typetag'] = 'Modificare i TypeTag';
     6$lang['TypeTag selection'] = 'Modificare - Cancellare i TypeTags';
     7$lang['TypeTag association'] = 'Associare - Dissociare i TypeTags';
    88
    99/* fields */
     
    1616/* buttons */
    1717$lang['Modify'] = 'Modificare';
    18 $lang['Delete all associations'] = 'Cancellare tutte le associazzioni';
     18$lang['Delete all associations'] = 'Delete all associations';
    1919
    2020/* messages */
     
    2222$lang['typetag_saved'] = 'TypeTag registrato';
    2323$lang['typetag_suppr'] = 'TypeTag cancellato';
    24 $lang['typetag_unknown'] = 'TypeTag sconoscuto';
     24$lang['typetag_unknown'] = 'Unknown TypeTag';
    2525$lang['typetag_error'] = 'Dovete inserire tutti campi (nome e colore)';
    26 $lang['All associations have been removed'] = 'Tutte le associazioni sono state cancellate';
     26$lang['All associations have been removed'] = 'All associations have been removed';
    2727$lang['typetags_associated'] = 'TypeTag associato';
    2828
  • extensions/typetags/main.inc.php

    r9970 r10987  
    22/*
    33Plugin Name: TypeT@gs
    4 Version: 2.2.a
     4Version: auto
    55Description: Allow to manage color of tags, as you want...
    66Plugin URI: http://piwigo.org/ext/extension_view.php?eid=166
  • extensions/typetags/maintain.inc.php

    r9863 r10987  
    44function plugin_install()
    55{
    6         global $prefixeTable;
     6  global $prefixeTable;
    77
    8         $query = 'SHOW FULL COLUMNS FROM ' . TAGS_TABLE . ';';
    9         $result = array_from_query($query, 'Field');
    10         if (!in_array('id_typetags', $result))
    11         {
    12                 pwg_query('ALTER TABLE '.TAGS_TABLE.' ADD COLUMN `id_typetags` SMALLINT(5)');
    13         }
     8  $query = 'SHOW FULL COLUMNS FROM ' . TAGS_TABLE . ';';
     9  $result = array_from_query($query, 'Field');
     10  if (!in_array('id_typetags', $result))
     11  {
     12    pwg_query('ALTER TABLE '.TAGS_TABLE.' ADD COLUMN `id_typetags` SMALLINT(5)');
     13  }
    1414
    15         $result = pwg_query('SHOW TABLES LIKE "' . $prefixeTable .'typetags"');
    16         if (!mysql_fetch_row($result))
    17         {
    18                 $q = 'CREATE TABLE '. $prefixeTable .'typetags(
    19                         id smallint(5) unsigned NOT NULL auto_increment,
    20                         name VARCHAR(255) NOT NULL,
    21                         color VARCHAR(255) NOT NULL,
    22                         PRIMARY KEY  (id));';
    23                 pwg_query($q);
    24         }
     15  $result = pwg_query('SHOW TABLES LIKE "' . $prefixeTable .'typetags"');
     16  if (!mysql_fetch_row($result))
     17  {
     18    $q = 'CREATE TABLE '. $prefixeTable .'typetags(
     19      id smallint(5) unsigned NOT NULL auto_increment,
     20      name VARCHAR(255) NOT NULL,
     21      color VARCHAR(255) NOT NULL,
     22      PRIMARY KEY  (id));';
     23    pwg_query($q);
     24  }
    2525}
    2626
    2727function plugin_uninstall()
    2828{
    29         global $prefixeTable;
     29  global $prefixeTable;
    3030
    31         $q = ' ALTER TABLE '.TAGS_TABLE.' DROP COLUMN `id_typetags`';
    32         pwg_query( $q );
     31  $q = ' ALTER TABLE '.TAGS_TABLE.' DROP COLUMN `id_typetags`';
     32  pwg_query( $q );
    3333
    34         $q = ' DROP TABLE '. $prefixeTable .'typetags;';
    35         pwg_query($q);
     34  $q = ' DROP TABLE '. $prefixeTable .'typetags;';
     35  pwg_query($q);
    3636}
    3737
Note: See TracChangeset for help on using the changeset viewer.