Changeset 4389


Ignore:
Timestamp:
Nov 29, 2009, 4:49:03 PM (14 years ago)
Author:
grum
Message:

[AMM] Users need to give a visibilty level for each menu items - mantis feature 1278

Location:
extensions/AMenuManager
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/AMenuManager/admin/amm_sections.tpl

    r4382 r4389  
    33
    44<div id="containerMenu">
    5   {foreach from=$sections item=section}
     5  {foreach from=$sections item=sectionName key=section}
    66  <div id="containerMenu_{$section}" class="containerMenuSection">
    7     <h3>{$section}</h3>
     7    <h3>{$sectionName|@translate}</h3>
    88    <ul class="connectedSortable categoryUl" id="menu_{$section}">
    99    {foreach from=$items item=data key=id}
    1010      {if $data.container==$section}
    1111        <li class="categoryLi menuItem {if $id=='qsearch'}menuItemDisabled{/if}" id="i{$id}">
     12          {if $id=="qsearch"}
     13          {else}
    1214          <img src="{$themeconf.admin_icon_dir}/cat_move.png" class="button drag_button" alt="{'Drag to re-order'|@translate}" title="{'Drag to re-order'|@translate}"/>
     15          {/if}
    1316          {$data.translation|@translate}
     17          <a  onclick="switchVisibility('i{$id}_visibility');">
     18          <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/permissions.png"  class="button drag_button" alt="{'g002_click_to_manage_rights'|@translate}" title="{'g002_click_to_manage_rights'|@translate}"
     19                style="float:right;"/></a>
     20          <div id="i{$id}_visibility" class="visibility">
     21            {$data.visibilityForm}
     22          </div>
    1423        </li>
    1524      {/if}
     
    1827  </div>
    1928  {/foreach}
    20 
    21   <input type="button" value="{'cancel'|@translate}" onclick="resetMenu('cancel');"/>
    22   <input type="button" value="{'piwigo_default'|@translate}" onclick="resetMenu('default');"/>
    23   <p><input type="button" value="{'apply_changes'|@translate}" onclick="submitChanges();"></p>
     29  <br/>
     30  <input type="button" value="{'g002_cancel'|@translate}" onclick="resetMenu('cancel');"/>
     31  <input type="button" value="{'g002_piwigo_default'|@translate}" onclick="resetMenu('default');"/>
     32  <p><input type="button" value="{'g002_apply_changes'|@translate}" onclick="submitChanges();"></p>
    2433  <form id="submitForm" method="POST" action="">
    2534    <input type="hidden" name="fList" id="iList" value=""/>
    2635  </form>
    2736</div>
    28 
    29 
    3037
    3138
     
    3946  // initialization for cancel et reset functions
    4047  {foreach from=$defaultValues item=value key=id}
    41     resetValues[0].push( {literal} { {/literal} id:"{$id}", section:"{$value.container}", order:{$value.order}  {literal} } {/literal} );
     48    resetValues[0].push( {literal} { {/literal} id:"{$id}", section:"{$value.container}", order:{$value.order}, visibility:"{$value.visibility}" {literal} } {/literal} );
    4249  {/foreach}
    4350  {foreach from=$items item=value key=id}
    44     resetValues[1].push( {literal} { {/literal} id:"{$id}", section:"{$value.container}", order:{$value.order}  {literal} } {/literal} );
     51    resetValues[1].push( {literal} { {/literal} id:"{$id}", section:"{$value.container}", order:{$value.order}, visibility:"{$value.visibility}" {literal} } {/literal} );
    4552  {/foreach}
    4653  {literal}
     
    6370    {
    6471      $("#menu_"+resetValues[key][i].section).get(0).appendChild($("#i"+resetValues[key][i].id).get(0));
     72
     73      {/literal}
     74      {foreach from=$visibility.users item=value}
     75      $("#i"+resetValues[key][i].id+"_vis_user_{$value.id}").get(0).checked=/(.*,|^){$value.id}(?!\w)(\/)?/.test(resetValues[key][i].visibility);
     76      {/foreach}
     77
     78      {foreach from=$visibility.groups item=value}
     79      $("#i"+resetValues[key][i].id+"_vis_group_{$value.id}").get(0).checked=/(\/.*,|\/){$value.id}(?!\w)(\/)?/.test(resetValues[key][i].visibility);
     80      {/foreach}
     81      {literal}
     82
    6583    }
    6684  }
     
    7391    for(i=0;i<items.length;i++)
    7492    {
    75       datas+=items.get(i).id.substr(1)+",menu,"+i+",();";
     93      datas+=items.get(i).id.substr(1)+",menu,"+i+"#"+makeVisibility(items.get(i).id)+";";
    7694    }
    7795
     
    7997    for(i=0;i<items.length;i++)
    8098    {
    81       datas+=items.get(i).id.substr(1)+",special,"+i+",();";
     99      datas+=items.get(i).id.substr(1)+",special,"+i+"#"+makeVisibility(items.get(i).id)+";";
    82100    }
    83101
     
    86104  }
    87105
     106  function switchVisibility(id)
     107  {
     108    if($("#"+id).css('display')!='none')
     109    {
     110      $("#"+id).css({display:'none'});
     111    }
     112    else
     113    {
     114      $("#"+id).css({display:'block'});
     115    }
     116  }
     117
     118  function makeVisibility(id)
     119  {
     120    {/literal}
     121    returned="";
     122    {foreach from=$visibility.users item=value}
     123    returned+=($("#"+id+"_vis_user_{$value.id}").get(0).checked)?((returned=="")?"":",")+"{$value.id}":"";
     124    {/foreach}
     125
     126    returned2="";
     127    {foreach from=$visibility.groups item=value}
     128    returned2+=($("#"+id+"_vis_group_{$value.id}").get(0).checked)?((returned2=="")?"":",")+"{$value.id}":"";
     129    {/foreach}
     130    {literal}
     131
     132    return(returned+"/"+returned2);
     133  }
     134
    88135</script>
    89136{/literal}
  • extensions/AMenuManager/amm.css

    r4382 r4389  
    44table.littlefont td { text-align:left; padding:0px;padding-left:3px;padding-right:3px; }
    55
    6 .containerMenuSection { width:250px;  margin:auto; padding:10px; }
     6.containerMenuSection { width:250px;  margin:auto; padding:10px; display:inline-block; vertical-align:top; }
    77li.menuItem { padding:4px; width:230px; cursor:move;}
    88li.menuItemDisabled { cursor:defaut;}
     9div.visibility { width:100%;overflow:hidden;display:none;margin-left:30px; }
     10
     11div.visibility p { margin:0px; }
     12div.visibility input { margin-right:8px; }
     13div.visibility h3 { position:relative; font-size:14px; height:auto; margin:5px 0px 0px;padding:0px;text-align:left;}
  • extensions/AMenuManager/amm_aip.class.inc.php

    r4382 r4389  
    2828  protected $tabsheet;
    2929  protected $ajax;
    30   protected $sectionsId=array('menu', 'special');
     30  protected $sectionsId=array('menu' => 'title_menu', 'special' => 'special_categories');
    3131
    3232  protected $urls_modes=array(0 => 'new_window', 1 => 'current_window');
     
    501501      for($i=0;$i<count($items)-1;$i++)
    502502      {
    503         $properties=explode(",", $items[$i]);
    504         $this->my_config['amm_sections_items'][$properties[0]]['container']=$properties[1];
    505         $this->my_config['amm_sections_items'][$properties[0]]['order']=$properties[2];
    506         $this->my_config['amm_sections_items'][$properties[0]]['visibility']=$properties[3];
     503        $properties=explode("#", $items[$i]);
     504        $properties[0]=explode(",", $properties[0]);
     505        $this->my_config['amm_sections_items'][$properties[0][0]]['container']=$properties[0][1];
     506        $this->my_config['amm_sections_items'][$properties[0][0]]['order']=$properties[0][2];
     507        $this->my_config['amm_sections_items'][$properties[0][0]]['visibility']=$properties[1];
    507508      }
    508509      $this->sortSectionsItems();
    509510      if($this->save_config())
    510511      {
    511         array_push($page['infos'], l10n('AMM_config_saved'));
     512        array_push($page['infos'], l10n('g002_config_saved'));
    512513      }
    513514      else
    514515      {
    515         array_push($page['errors'], l10n('AMM_adviser_not_authorized'));
    516       }
    517     }
    518 
     516        array_push($page['errors'], l10n('g002_adviser_not_allowed'));
     517      }
     518    }
     519
     520    foreach($this->my_config['amm_sections_items'] as $key=>$val)
     521    {
     522      $this->my_config['amm_sections_items'][$key]['visibilityForm'] = $this->makeVisibility($val['visibility'], $key);
     523      $this->defaultMenus[$key]['visibilityForm'] = $this->makeVisibility("guest,generic,normal,admin/", $key);
     524    }
     525
     526    $users=new users("");
     527    $groups=new groups("");
     528
     529
     530    $template->assign("visibility", Array('users' => $users->access_list, 'groups' => $groups->access_list));
    519531    $template->assign("sections", $this->sectionsId);
    520532    $template->assign("defaultValues", $this->defaultMenus);
     
    732744
    733745
     746  /* this function returns an HTML FORM to use with each menu items
     747   * $visibility is a formatted string looking this :
     748   *   users type1(,users typeX)/(groupId0)(,groupIdX))
     749  */
     750  private function makeVisibility($visibility, $id)
     751  {
     752    $local_tpl = new Template(AMM_PATH."admin/", "");
     753    $local_tpl->set_filename('body_page',
     754                  dirname($this->filelocation).'/admin/amm_sections_visibility.tpl');
     755
     756
     757    $parameters=explode("/", $visibility);
     758
     759    $users=new users(str_replace(",", "/", $parameters[0]));
     760    $users->set_allowed('admin', true);
     761    $groups=new groups(str_replace(",", "/", $parameters[1]));
     762
     763    $local_tpl->assign('name', $id);
     764    $local_tpl->assign('users', $users->access_list);
     765    $local_tpl->assign('groups', $groups->access_list);
     766
     767    return($local_tpl->parse('body_page', true));
     768  }
     769
    734770
    735771
     
    747783    return(false);
    748784  }
     785
     786
    749787
    750788  /* ---------------------------------------------------------------------------
     
    823861  }
    824862
     863
     864
    825865  /* ---------------------------------------------------------------------------
    826866    functions to manage sections tables
     
    883923    return(0);
    884924  }
     925
     926
     927
    885928
    886929
     
    9971040
    9981041
    999 
    1000 /*
    1001  *
    1002   // return a html formatted list of special menu sections items
    1003   private function ajax_amm_setmenu_mod_section_list($menuname)
    1004   {
    1005 
    1006 
    1007 
    1008     $local_tpl = new Template(AMM_PATH."admin/", "");
    1009     $local_tpl->set_filename('body_page',
    1010                   dirname($this->filelocation).'/admin/amm_sectionsmod_detail.tpl');
    1011 
    1012     $template_datas = array('LIST' => array());
    1013     foreach($this->my_config[$menuname] as $key => $val)
    1014     {
    1015       $template_datas['LIST'][] = array(
    1016         'ID' => base64_encode($key),
    1017         'LABEL' => $labels[$menuname][$key],
    1018         'VISIBLE' => 'g002_yesno_'.$val
    1019       );
    1020     }
    1021 
    1022     $local_tpl->assign('datas', $template_datas);
    1023     $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
    1024 
    1025     return($local_tpl->parse('body_page', true));
    1026   }
    1027 
    1028 
    1029   // move item to the specified position
    1030   private function ajax_amm_setmenu_mod_section_showhide($menuname, $urlid)
    1031   {
    1032     $switchvisible=array('y'=>'n', 'n'=>'y');
    1033 
    1034     $this->my_config[$menuname][base64_decode($urlid)]=$switchvisible[$this->my_config[$menuname][base64_decode($urlid)]];
    1035     $this->save_config();
    1036 
    1037     return($this->ajax_amm_setmenu_mod_section_list($menuname));
    1038   }
    1039   * */
    1040 
    1041 
    10421042} // AMM_AIP class
    10431043
  • extensions/AMenuManager/amm_pip.class.inc.php

    r4382 r4389  
    141141
    142142
    143     /*
    144       hide items from special & menu sections
     143    /* manage items from special & menu sections
     144     *  reordering items
     145     *  grouping items
     146     *  managing rights to access
    145147    */
    146148    $blocks=Array();
     
    154156    $blocks['special']->data=Array();
    155157
     158    $users=new users("");
     159    $groups=new groups("");
     160    $user_groups=$this->get_user_groups($user['id']);
     161
    156162    foreach($this->my_config['amm_sections_items'] as $key => $val)
    157163    {
    158164      if(isset($menuItems[$key]))
    159165      {
    160         $blocks[$val['container']]->data[$key]=$menuItems[$key];
     166        $access=explode("/",$val['visibility']);
     167        $users->set_alloweds(str_replace(",", "/", $access[0]));
     168        $groups->set_alloweds(str_replace(",", "/", $access[1]));
     169
     170        /* test if user status is allowed to access the menu item
     171         * if access is managed by group, the user have to be associated with an allowed group to access the menu item
     172        */
     173        if($users->is_allowed($user['status']) && (
     174            ($access[1]=='') ||
     175            (($access[1]!='') && $groups->are_allowed($user_groups)))
     176        )
     177        {
     178          $blocks[$val['container']]->data[$key]=$menuItems[$key];
     179        }
    161180      }
    162181    }
    163182    if(count($blocks['menu']->data)==0) $menu->hide_block('mbMenu');
    164183    if(count($blocks['special']->data)==0) $menu->hide_block('mbSpecials');
     184  }
     185
     186
     187  protected function get_user_groups($user_id)
     188  {
     189    $returned=array();
     190    $sql="SELECT group_id FROM ".USER_GROUP_TABLE."
     191          WHERE user_id = ".$user_id." ";
     192    $result=pwg_query($sql);
     193    if($result)
     194    {
     195      while($row=mysql_fetch_assoc($result))
     196      {
     197        array_push($returned, $row['group_id']);
     198      }
     199    }
     200    return($returned);
    165201  }
    166202
  • extensions/AMenuManager/amm_root.class.inc.php

    r4382 r4389  
    1818
    1919include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/common_plugin.class.inc.php');
     20include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/users_groups.class.inc.php');
    2021include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/css.class.inc.php');
    2122
     
    2526  protected $css;   //the css object
    2627  protected $defaultMenus = array(
    27     'favorites' => array('container' => 'special', 'visibility' => '', 'order' => 0, 'translation' => 'favorite_cat'),
    28     'most_visited' => array('container' => 'special', 'visibility' => '', 'order' => 1, 'translation' => 'most_visited_cat'),
    29     'best_rated' => array('container' => 'special', 'visibility' => '', 'order' => 2, 'translation' => 'best_rated_cat'),
    30     'random' => array('container' => 'special', 'visibility' => '', 'order' => 3, 'translation' => 'random_cat'),
    31     'recent_pics' => array('container' => 'special', 'visibility' => '', 'order' => 4, 'translation' => 'recent_pics_cat'),
    32     'recent_cats' => array('container' => 'special', 'visibility' => '', 'order' => 5, 'translation' => 'recent_cats_cat'),
    33     'calendar' => array('container' => 'special', 'visibility' => '', 'order' => 6, 'translation' => 'calendar'),
    34     'qsearch' => array('container' => 'menu', 'visibility' => '', 'order' => 0, 'translation' => 'qsearch'),
    35     'tags' => array('container' => 'menu', 'visibility' => '', 'order' => 1, 'translation' => 'Tags'),
    36     'search' => array('container' => 'menu', 'visibility' => '', 'order' => 2, 'translation' => 'Search'),
    37     'comments' => array('container' => 'menu', 'visibility' => '', 'order' => 3, 'translation' => 'comments'),
    38     'about' => array('container' => 'menu', 'visibility' => '', 'order' => 4, 'translation' => 'About'),
    39     'rss' => array('container' => 'menu', 'visibility' => '', 'order' => 5, 'translation' => 'Notification')
     28    'favorites' => array('container' => 'special', 'visibility' => 'guest,generic,normal,admin/', 'order' => 0, 'translation' => 'favorite_cat'),
     29    'most_visited' => array('container' => 'special', 'visibility' => 'guest,generic,normal,admin/', 'order' => 1, 'translation' => 'most_visited_cat'),
     30    'best_rated' => array('container' => 'special', 'visibility' => 'guest,generic,normal,admin/', 'order' => 2, 'translation' => 'best_rated_cat'),
     31    'random' => array('container' => 'special', 'visibility' => 'guest,generic,normal,admin/', 'order' => 3, 'translation' => 'random_cat'),
     32    'recent_pics' => array('container' => 'special', 'visibility' => 'guest,generic,normal,admin/', 'order' => 4, 'translation' => 'recent_pics_cat'),
     33    'recent_cats' => array('container' => 'special', 'visibility' => 'guest,generic,normal,admin/', 'order' => 5, 'translation' => 'recent_cats_cat'),
     34    'calendar' => array('container' => 'special', 'visibility' => 'guest,generic,normal,admin/', 'order' => 6, 'translation' => 'calendar'),
     35    'qsearch' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,admin/', 'order' => 0, 'translation' => 'qsearch'),
     36    'tags' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,admin/', 'order' => 1, 'translation' => 'Tags'),
     37    'search' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,admin/', 'order' => 2, 'translation' => 'Search'),
     38    'comments' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,admin/', 'order' => 3, 'translation' => 'comments'),
     39    'about' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,admin/', 'order' => 4, 'translation' => 'About'),
     40    'rss' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,admin/', 'order' => 5, 'translation' => 'Notification')
    4041  );
    4142
  • extensions/AMenuManager/language/en_UK/plugin.lang.php

    r4383 r4389  
    9898$lang['g002_config_saved'] = "The configuration is saved";
    9999$lang['g002_adviser_not_allowed'] = "Adviser is not allowed to make changes";
     100$lang['g002_click_to_manage_rights'] = "Rights management";
    100101
    101102?>
  • extensions/AMenuManager/language/fr_FR/plugin.lang.php

    r4383 r4389  
    9898$lang['g002_config_saved'] = "Configuration sauvegardée";
    9999$lang['g002_adviser_not_allowed'] = "Le conseiller n'est pas autorisé à effectuer des modifications";
     100$lang['g002_click_to_manage_rights'] = "Gérer les droits d'accès";
    100101
    101102
  • extensions/AMenuManager/main.inc.php

    r4382 r4389  
    2828|         |            | * bug resolved : random image block is displayed only
    2929|         |            |   if user have accessibility to more than 0 images
    30 |         |            |   random images are choosen in the accessible images for
    31 |         |            |   a user (permission + level)
     30|         |            |   random images are choosen in the accessible images
     31|         |            |   for a user (permission + level)
    3232|         |            |   (cf. post:107877 on french forum)
    3333|         |            |   (cf. topic:14374 on french forum)
    34 | 2.1.1   | 2009/07/27 | * random picture is preloaded before the first ajax call
    35 |         |            |   assuming the display of a thumbnail even if javascript
    36 |         |            |   is disabled on the browser
     34| 2.1.1   | 2009/07/27 | * random picture is preloaded before the first ajax
     35|         |            |   call assuming the display of a thumbnail even if
     36|         |            |   javascript is disabled on the browser
    3737|         |            |   (cf. post:116807 on french forum)
    3838|         |            | * give the possibility to choose between an automatic
     
    4444|         |            |    - es_ES
    4545|         |            |    - hu_HU (thx to sámli)
    46 | 2.1.3   | 2009/11/24 | * mantis:1285
     46| 2.1.3   | 2009/11/24 | * mantis: feature 1285
    4747|         |            |   move the js for "random image" in the the footer
    4848|         |            |   (having the js inside the <dl> tag was not w3c
    4949|         |            |   compliant)
    50 |         |            | * mantis:1132
    51 |         |            |   Allowing order management for items in Piwigo's core blocks
    52 |         |            | * mantis:1133
     50|         |            | * mantis: feature 1132
     51|         |            |   Allowing order management for items in Piwigo's core
     52|         |            |   blocks
     53|         |            | * mantis: feature 1133
    5354|         |            |   Allowing to group content from Piwigo's core blocks
    54 |         |            |
     55|         |            | * mantis: feature 1278
     56|         |            |   Allowing to manage access to menu items with a right
     57|         |            |   management system
    5558|         |            |
    5659|         |            |
     
    8487define('AMM_PATH' , PHPWG_PLUGINS_PATH . AMM_DIR . '/');
    8588
    86 define('AMM_VERSION' , '2.1.3'); // => ne pas oublier la version dans l'entête !!
     89define('AMM_VERSION' , '2.1.3'); //=> ne pas oublier la version dans l'entête !!
    8790
    8891global $prefixeTable, $page;
Note: See TracChangeset for help on using the changeset viewer.