Changeset 11276


Ignore:
Timestamp:
Jun 9, 2011, 3:52:13 PM (13 years ago)
Author:
cljosse
Message:

[extensions] set_plugins Storing the state of the fields

Location:
extensions/set_plugins
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/set_plugins/admin.tpl

    r11249 r11276  
    1010{else}
    1111 var no_affiche = false;
    12  {/if}
     12{/if}
    1313</script>
    14 <div>   
     14{if !isset($liste_plugins)}
     15<div class="infos"></div>
     16<div class="errors"></div>
     17{/if}
    1518{if isset($liste_plugins)}
    1619{foreach from=$plugin_states item=plugin_state}
    1720{if $plugin_state==$state}
    18 </div>
    1921<fieldset >
    2022    <legend>   
    21     {if $plugin_state == 'active'} {'Last '|@translate} {'Active Plugins'|@translate}
    22     {elseif $plugin_state == 'inactive'} {'Last '|@translate} {'Inactive Plugins'|@translate}
     23    {if $plugin_state == 'active'}
     24    {'Last '|@translate} {'Active Plugins'|@translate}
     25    {elseif $plugin_state == 'inactive'}
     26    {'Last '|@translate} {'Inactive Plugins'|@translate}
    2327    {/if}
    24 
    25     </legend>
     28</legend>
    2629  <form action="{$action}" method="post" name="form_set_plugins" id="form_set_plugins">
    2730    <input name="unset_plugins" type="submit" value="{'Deactivate'|@translate}" />
    2831    <input name="set_plugins" type="submit" value="{'Activate'|@translate}" />
    2932    <input name="nb" type="text" value="{$nb}" />
     33    <input name="list_visible" id="list_visible" type="hidden" value="{$list_visible}" />
    3034    </form>
    3135  <p>
    32 </p>
    33     {foreach from=$liste_plugins item=plugin name=plugins_loop}
    34       {if $plugin.STATE == $plugin_state}
    3536
    36     <div class="pluginBox">
    37       <table>
    38         <tr>
    39           <td name="plugins_name" class="pluginBoxNameCell{if $plugin.INCOMPATIBLE} warning" title="{'WARNING! This plugin does not seem to be compatible with this version of Piwigo.'|@translate|@escape:'html'}{/if}">
    40             {$plugin.NAME}
    41           </td>
    42           <td>{$plugin.DESC}</td>
    43         </tr>
    44         <tr>
    45           <td>
    46       {if $plugin.STATE == 'active'}
    47             <a href="{$plugin.U_ACTION}&amp;action=deactivate">{'Deactivate'|@translate}</a>
     37  {foreach from=$liste_plugins item=plugin name=plugins_loop}
     38      <div class="pluginBox" id="{$plugin.NAME}">
     39 <table width="100%"  >    <tr>
     40<td width="50%" align="left" name="plugins_name" rel="actif" class="pluginBoxNameCell" >
     41    {if $plugin.STATE == 'active'}
     42{$plugin.NAME}
     43{else}
     44{/if}
     45</td>       
    4846
    49       {elseif $plugin_state == 'inactive'}
    50             <a href="{$plugin.U_ACTION}&amp;action=activate" {if $plugin.INCOMPATIBLE}class="incompatible"{/if}>{'Activate'|@translate}</a>
    51             | <a href="{$plugin.U_ACTION}&amp;action=uninstall" onclick="return confirm('{'Are you sure?'|@translate|@escape:'javascript'}');">{'Uninstall'|@translate}</a>
     47        <td width="50%" align="left" name="plugins_name" rel="inactif"  class="pluginBoxNameCell">
     48          {if $plugin.STATE == 'inactive'}
     49              {$plugin.NAME}
     50      {else}
     51      {/if}
     52</td> 
     53</tr>
     54<tr>
    5255
     56        <td width="50%" align="left" rel="actif">
     57          {if $plugin.STATE == 'active'}         
     58            <a href="{$plugin.U_ACTION}&amp;action=deactivate">
     59            {'Deactivate'|@translate}</a>
     60          {else} {/if}
     61        </td>
     62        <td width="50%" align="left" rel="inactif">
     63          {if $plugin.STATE == 'inactive'}
     64            <a href="{$plugin.U_ACTION}&amp;action=activate" >{'Activate'|@translate}</a>
     65           
     66             {else}  {/if}
     67        </td>
     68      </tr>
     69   
     70</table>
    5371
    54       {/if}
    55           </td>
    56           <td>
    57             {'Version'|@translate} {$plugin.VERSION}
    58       {if not empty($plugin.AUTHOR)}
    59         {if not empty($plugin.AUTHOR_URL)}
    60           {assign var='author' value='<a href="%s">%s</a>'|@sprintf:$plugin.AUTHOR_URL:$plugin.AUTHOR}
    61         {else}
    62           {assign var='author' value=$plugin.AUTHOR}
    63         {/if}
    64             | {'By %s'|@translate|@sprintf:$author}
    65       {/if}
    66 
    67       {if not empty($plugin.VISIT_URL)}
    68             | <a class="externalLink" href="{$plugin.VISIT_URL}">{'Visit plugin site'|@translate}</a>
    69       {/if}
    70           </td>
    71         </tr>
    72       </table>
    73     </div>
    74    
    75       {/if}
    76     {/foreach}
     72</div> 
     73{/foreach}
     74  </p>
     75 
    7776  </fieldset>
    7877{/if}
  • extensions/set_plugins/include/affiche.php

    r11249 r11276  
    11<?php 
    22//=================================================================================================
    3 global $conf ;
    4 $nb="10";
     3global $conf ;
     4global $list_visible, $val_state,$liste_plugins,$nb,$infos_message,$erreur_message,$page;
     5
    56if (isset($conf['set_plugins']))
    67$set_plugins_parametres =  unserialize($conf['set_plugins']);
    78
     9$nb="10";
    810if(isset($set_plugins_parametres) && isset($set_plugins_parametres['nb']))
    911    $nb=$set_plugins_parametres['nb'];
     12    $nb=isset($_POST['nb'])?$_POST['nb']:$nb ;   
     13
    1014    $liste=array();
    11 if(isset($set_plugins_parametres['list']))
    12   $liste=$set_plugins_parametres['list'];
     15  if(isset($set_plugins_parametres['list']))
     16    $liste=$set_plugins_parametres['list'];
     17    $liste=isset($_POST['liste'])?$_POST['liste']:$liste ;   
    1318
     19  $state="active";
    1420  if(isset($set_plugins_parametres['state']))
    1521   $state =$set_plugins_parametres['state'];
     22   $state=isset($_POST['state'])?$_POST['state']:$state ;   
    1623
    17  $state=isset($state)?$state:"active";
     24   $list_visible="on,on,on,on";
     25     if(isset($set_plugins_parametres['list_visible']))
     26      $list_visible =$set_plugins_parametres['list_visible'];
     27      $list_visible=(isset($_POST['list_visible']))?$_POST['list_visible']:$list_visible ;
    1828
    19 $set=isset($_POST['set'])?$_POST['set']:"true";
    20  $list="test1,test2,test2";
     29  $set=isset($_POST['set'])?$_POST['set']:"true";
    2130
    22   $template->assign( array( 'list'=>$list,
    23                    'nb' => isset($_POST['nb'])?$_POST['nb']:$nb,
    24                    'state' => $state ,
    25                         'set' => $set,                     
    26                         'cl_plugins' => $cl_set_plugins_plugin ,
    27                         'cl_version' => $cl_set_plugins_plugin['version'] ,
    28                         'name' => $cl_set_plugins_plugin['name'] ,
    29                         'Version_pwg' => PHPWG_VERSION,
    30                         'SET_PLUGINS_PATH' => SET_PLUGINS_PATH
     31   $liste_plugins=$set=isset($_POST['liste_plugins'])?$_POST['liste_plugins']:$liste;
     32
     33
     34
     35 
     36
     37 if (isset($_POST['set']) || isset($_POST['list_visible']) || isset($_POST['nb'])){
     38    save_config();
     39 }
     40  $template->assign( array( 
     41                    'nb' => $nb,
     42                    'state' => $state ,
     43                    'set' => $set,                     
     44                    'cl_plugins' => $cl_set_plugins_plugin ,
     45                    'cl_version' => $cl_set_plugins_plugin['version'] ,
     46                    'name' => $cl_set_plugins_plugin['name'] ,
     47                    'Version_pwg' => PHPWG_VERSION,
     48                    'SET_PLUGINS_PATH' => SET_PLUGINS_PATH,
     49                    'list_visible' => $list_visible
    3150                                                                                        )
    3251                                                                        );               
     
    4867}
    4968
     69//==========================================================
     70$liste_tpl=array();
    5071
    51 
    52 $liste_tpl=array();
    53 //==========================================================
    5472foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) {   
    5573//==== test si $plugin_id fait partie de $liste_plugins ============== 
     
    100118                         
    101119                                                                                        )
    102                                                                         );               
    103    
     120                                                                        );             
     121
     122//================================================================
     123if (!isset($infos_message)){
     124                  $infos_message = "";
     125                }                 
     126                if  ($infos_message != "")  {
     127                   array_push($page['infos'],  $infos_message);
     128                   $infos_message="";
     129                 }
     130                if (!isset($erreur_message)){
     131                  $erreur_message = "";
     132                }               
     133                if  ($erreur_message != "")  {
     134       
     135                  array_push($page['errors'], $erreur_message);
     136                  $erreur_message="";
     137       
     138                 
     139                 }               
     140                 
     141//================================================================
     142function save_config(){
     143  global $list_visible, $val_state,$liste_plugins,$nb,$page ;
     144  global $infos_message;
     145  $infos_message=l10n("save_config");
     146  $config=array();
     147  $config = array(
     148                'list_visible' => $list_visible,
     149                'state' => $val_state,
     150                'list'=>$liste_plugins,
     151                'nb' =>$nb
     152            );
     153        conf_update_param('set_plugins', pwg_db_real_escape_string(serialize($config)));
     154    }
    104155//==========================================================================================
    105156?>
  • extensions/set_plugins/js/field_set.js

    r11249 r11276  
     1jQuery("fieldset").hide();
     2jQuery(document).ready(function () {
     3  jQuery(window).unload(function () {
     4    // jQuery("#form_set_plugins").submit();
     5  });
     6
     7  if (typeof plus_path == "undefined") {
     8    var plus_path = './plugins/set_plugins/js/icon/plus.png';
     9    var minus_path = './plugins/set_plugins/js/icon/minus.png';
     10  }
     11  var h_min = 0;
     12
     13  jQuery(window).load(function () {
     14    if (jQuery("fieldset").length >= 1) {
     15
     16      jQuery("div.titrePage h2").parent().hide();
     17
     18      var reg = new RegExp("[,]", "g");
     19      liste_visible = jQuery("input[name=list_visible]").val();
     20      n1 = liste_visible;
     21      liste = n1.split(reg);
     22      reg = new RegExp("['off']", "g");
     23      jQuery("fieldset").each(
     24        function (i) {
     25
     26          id0 = jQuery(this).attr("id");
     27          if (id0 == "") jQuery(this).attr("id", "fieldset_" + i);
     28          jQuery(this).attr("rel", i);
     29
     30          if (!jQuery(this).hasClass("field_set"))
     31            jQuery(this).addClass("field_set");
    132
    233
     34          if (liste[i] == "off") {
     35            liste[i] = "off";
    336
    4 jQuery(document).ready(function () {
    5   if (jQuery("fieldset").length >= 1) {
    6     jQuery("div .titrePage h2").remove();
     37           h_min = jQuery("#" + this.id + ' legend').height();
     38            jQuery(this).height(h_min + 5);
    739
    8     jQuery("fieldset").each(
    9               function (i) {
    10                 id0 = jQuery(this).attr("id");
    11                 if (id0 == "") jQuery(this).attr("id", "fieldset_" + i);
    12                 if (!jQuery(this).hasClass("field_set"))
    13                   jQuery(this).addClass("field_set");
    14                 if (i > 0)
    15                   jQuery(this).height(0);
    16                 else
    17                   jQuery(this).addClass("visible");
    18                 jQuery("#" + this.id + ' legend').css('cursor', 'pointer');
    19                 id0 = jQuery(this).attr("id");
     40            jQuery("#" + this.id + ' legend').prepend(
     41          '<img alt = "" title = ""' +
     42          'src = "' + plus_path + '"' + '>&nbsp;'
     43        );
     44          } else {
     45            liste[i] = "on";
     46            jQuery(this).addClass("visible");
     47            jQuery("#" + this.id + ' legend').prepend(
     48          '<img alt = "" title = ""' +
     49          'src = "' + minus_path + '"' + '>&nbsp;'
     50        );
     51          }
    2052
    21                 jQuery("#" + this.id + ' legend').click(function (event) {
    22                   n = jQuery(this).parent().hasClass("visible");
    23 
    24                   if (n) {
    25                     jQuery(this).parent().height(0);
    26                     jQuery(this).parent().removeClass("visible");
    27                   }
    28                   else {
    29                     jQuery(this).parent().css("height", "auto");
    30                     jQuery(this).parent().addClass("visible");
    31                   }
    32                 });
    33               })
    34 
    35   }
     53          jQuery("#" + this.id + ' legend').css('cursor', 'pointer');
    3654
    3755
     56          id0 = jQuery(this).attr("id");
     57          jQuery("#" + id0 + ' legend').click(function (event) {
    3858
    39   jQuery(document).ready(function () {
    40     if (jQuery(".field_set").length >= 1)
    41       jQuery(".field_set").each(
    42                 function (i) {
     59            n = jQuery(this).parent().hasClass("visible");
     60            jQuery(this).css("color", "red");
    4361
    44                   id0 = jQuery(this).attr("id");
     62            i = jQuery(jQuery(this).parent()).attr("rel");
     63            liste_visible = jQuery("input[name=list_visible]").val();
     64            liste = liste_visible.split(",");
     65            if (n) {
     66              jQuery(this).parent().height(h_min + 5);
     67              jQuery(this).parent().removeClass("visible");
     68              liste[i] = "off";
     69            }
     70            else {
     71              jQuery(this).parent().css("height", "auto");
     72              jQuery(this).parent().addClass("visible");
     73              liste[i] = "on";
     74            }
    4575
    4676
     77            val = liste.join(",");
     78            jQuery("input[name=list_visible]").val(val);
    4779
    48                 });
     80            jQuery.ajax({
     81              type: "POST",
     82              async: true,
     83              data: "list_visible=" + val,
     84              success: function (msg) {
     85                jQuery("#form_set_plugins").submit();
     86              }
     87            });
    4988
    50   });
     89          }); // click
    5190
    5291
     92        }); //each
     93      var liste_action = { active: "", deactive: "" };
     94
     95      jQuery(".pluginBox a").each(
     96        function (i) {
     97          jQuery(this).click(function (event) {
     98            jQuery(this).css("color", "red");
     99            action = jQuery(this).attr('rel');
     100            if (action == "Deactivate")
     101              liste_plugins = jQuery(this).parent().parent().text();
     102            else if (action == "Activate")
     103              liste_plugins = jQuery(this).parent().parent().text();
     104
     105          }); // click
     106
     107        }); //each
     108
     109      jQuery("input[name=list_visible]").val(liste.join(","));
     110      jQuery("fieldset").show();
     111    } // fielset
     112    //====================================================================
     113    jQuery("td a").click(function (event) {
     114      l1 = jQuery('#liste').text();
     115      l = l1.split(new RegExp("\n", "g"));
     116
     117      list = jQuery('liste_plugins');
     118
     119      var reg = new RegExp("[?]", "g");
     120      ret_args = new Array;
     121      var args = event.target.href.split(reg)[1];
     122      reg = new RegExp("[&]", "g");
     123      var tableau = args.split(reg);
     124      for (i = 0; i < tableau.length; i++) {
     125        vals = tableau[i].split("=");
     126        ret_args[vals[0]] = vals[1];
     127      }
     128      if (ret_args['action'] == "deactivate") {
     129
     130        list = jQuery('list');
     131        n = 1;
     132      } else if (ret_args['action'] == "activate") {
     133
     134        list = jQuery('liste_plugins');
     135        n = 0;
     136      }
    53137
    54138
     139    })
    55140
    56 
    57   jQuery("td a").click(function (event) {
    58     l1 = jQuery('td[name="plugins_name"]');
    59 
    60     var reg = new RegExp("[&]", "g");
    61     var tableau = event.target.href.split(reg);
    62 
    63 
    64     if (event.target.nameProp.match(RegExp("deactivate", "g"))) {
    65       n = 1;
    66     } else if (event.target.nameProp.match(RegExp("activate", "g"))) {
    67       n = 0;
    68     }
    69 
    70 
    71 
    72   })
    73 })
    74 
    75              
     141  }); // load
     142});                     //ready           
    76143           
  • extensions/set_plugins/main.inc.php

    r11249 r11276  
    5151 if ($page['tab']!="installed") return ;
    5252  Affiche_set_plugins();
    53 
    5453        break;
    5554
     
    7069  global $user, $template, $val,$page,$conf;
    7170    include_once(SET_PLUGINS_PATH."include/constants.php");       
    72     include_once(SET_PLUGINS_PATH.'include/affiche.php');
    73     $all_tpl_vars = $template->get_template_vars('plugins');
    74  
    75     if(!$all_tpl_vars)  return;     
    76  
    77 $val_state="";
    7871
    79 if(  isset($_POST['unset_plugins']) || isset($_POST['set_plugins'])  ){
    80  if(isset($_POST['unset_plugins'])  )
     72    $all_tpl_vars = $template->get_template_vars('plugins'); 
     73    if(!$all_tpl_vars)  return;   
     74
     75    include_once(SET_PLUGINS_PATH.'include/affiche.php');     
     76    $val_state="";
     77    if(  isset($_POST['unset_plugins']) || isset($_POST['set_plugins'])  ){
     78     if(isset($_POST['unset_plugins'])  )
    8179                    $val_state='inactive';
    8280      elseif(isset($_POST['set_plugins'])  )
    8381        $val_state='active';
    84       $nb=isset($_POST['nb'])?$_POST['nb']:$nb ;
    85    
     82   
     83
    8684    if($val_state!=""){ 
    87     if($val_state=="activate")
    88         $sens ="DESC";
    89     else
    90         $sens="ASC";
    91 
     85      if($val_state=="activate")
     86          $sens ="DESC";
     87      else
     88          $sens="ASC";
    9289    //==== pré-liste ===
    9390      $query = 'SELECT *
     
    9794           LIMIT '.$nb.'
    9895      ';
    99           $result = pwg_query($query);
    100    
    101 
    102  
     96          $result = pwg_query($query);
     97       
    10398      $query = '
    10499      UPDATE '.PLUGINS_TABLE.'
     
    106101      WHERE `state` NOT LIKE "'.$val_state. '" AND id!="' . "set_plugins" . '"
    107102      ORDER BY `id`  '.$sens.'
    108        LIMIT '.$nb.'
    109       ;';
     103      LIMIT '.$nb.';';
     104      pwg_query($query);
     105 //=====================================
    110106
    111        pwg_query($query);
    112  
    113     $data = array();
    114     if($result)
    115     while ($row = pwg_db_fetch_assoc($result))
    116     {
    117  
    118      $url =  $row['id'] ;$vers= $row['version'];
    119       array_push($data, array('plugin' => $url,'version'=>$vers) );
     107      $liste_plugins = array();
     108      if($result)
     109        while ($row = pwg_db_fetch_assoc($result)) {
     110       
     111         $url =  $row['id'] ;
     112         $vers= $row['version'];
     113         $state=$row['state'];
     114         array_push($liste_plugins, array('plugin' => $url,'version'=>$vers,'state' =>$state ) );
     115        }   
     116  //=====================================       
     117       
     118       
     119        $redirect_url = get_root_url().'admin.php?page='.$_GET['page'];
     120        save_config(); 
     121        unset ($_POST);
     122        redirect($redirect_url);
     123      }
    120124    }
    121      
    122       unset ($_POST);
    123         $redirect_url = get_root_url().'admin.php?page='.$_GET['page'];
    124          $config=array();
    125              $config = array(
    126                           'state' => $val_state,
    127                           'list'=>$data,
    128                           'nb' =>$nb
    129                       );
    130 
    131         conf_update_param('set_plugins', pwg_db_real_escape_string(serialize($config)));
    132         redirect($redirect_url);
    133     }
    134 }
    135  
    136 
    137125               $template->set_filenames(
    138126                array(
Note: See TracChangeset for help on using the changeset viewer.