1{*
2* 2007-2016 PrestaShop
3*
4* NOTICE OF LICENSE
5*
6* This source file is subject to the Academic Free License (AFL 3.0)
7* that is bundled with this package in the file LICENSE.txt.
8* It is also available through the world-wide-web at this URL:
9* http://opensource.org/licenses/afl-3.0.php
10* If you did not receive a copy of the license and are unable to
11* obtain it through the world-wide-web, please send an email
12* to license@prestashop.com so we can send you a copy immediately.
13*
14* DISCLAIMER
15*
16* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17* versions in the future. If you wish to customize PrestaShop for your
18* needs please refer to http://www.prestashop.com for more information.
19*
20*  @author PrestaShop SA <contact@prestashop.com>
21*  @copyright  2007-2016 PrestaShop SA
22*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
23*  International Registered Trademark & Property of PrestaShop SA
24*}
25<script type="text/javascript">
26  $(document).ready(function () {
27
28    var id_tab_parentmodule = {$id_tab_parentmodule|intval};
29    var id_tab_module = {$id_tab_module|intval};
30
31    $('tr.child-' + id_tab_parentmodule + ' > td > input.view.' + id_tab_module).change(function () {
32
33      if (!$(this).prop('checked')) {
34        $('#table_module_2 thead th:eq(1) input').trigger('click');
35        if ($('#table_module_2 thead th:eq(1) input').prop('checked'))
36          $('#table_module_2 thead th:eq(1) input').trigger('click');
37      }
38    });
39
40    $('tr.child-' + id_tab_parentmodule + ' > td > input.edit.' + id_tab_module).change(function () {
41
42      if (!$(this).prop('checked')) {
43        $('#table_module_2 thead th:eq(2) input').trigger('click');
44        if ($('#table_module_2 thead th:eq(2) input').prop('checked'))
45          $('#table_module_2 thead th:eq(2) input').trigger('click');
46      }
47    });
48
49    $('div.productTabs').find('a').each(function () {
50      $(this).attr('href', '#');
51    });
52
53    $('div.productTabs a').click(function () {
54      var id = $(this).attr('id');
55      $('.nav-profile').removeClass('selected');
56      $(this).addClass('selected active');
57      $(this).siblings().removeClass('active');
58      $('.tab-profile').hide();
59      $('.' + id).show();
60    });
61
62    $('.ajaxPower').change(function () {
63      var tout = $(this).data('rel').split('||');
64      var id_tab = tout[0];
65      var id_profile = tout[1];
66      var perm = tout[2];
67      var enabled = $(this).is(':checked') ? 1 : 0;
68      var tabsize = tout[3];
69      var tabnumber = tout[4];
70      var table = 'table#table_' + id_profile;
71
72      if (perm == 'all' && $(this).parent().parent().hasClass('parent')) {
73        if (enabled)
74          $(this).parent().parent().parent().find('.child-' + id_tab + ' input[type=checkbox]').attr('checked', 'checked');
75        else
76          $(this).parent().parent().parent().find('.child-' + id_tab + ' input[type=checkbox]').removeAttr('checked');
77        $.ajax({
78          url: "{$link->getAdminLink('AdminAccess')|escape:'javascript':'UTF-8'}",
79          cache: false,
80          data: {
81            ajaxMode: '1',
82            id_tab: id_tab,
83            id_profile: id_profile,
84            perm: perm,
85            enabled: enabled,
86            submitAddAccess: '1',
87            addFromParent: '1',
88            action: 'updateAccess',
89            ajax: '1',
90            token: '{getAdminToken tab='AdminAccess'}'
91          },
92          success: function (res, textStatus, jqXHR) {
93            try {
94              if (res == 'ok')
95                showSuccessMessage("{l s='Update successful' js=1}");
96              else
97                showErrorMessage("{l s='Update error' js=1}");
98            } catch (e) {
99              jAlert('Technical error');
100            }
101          }
102        });
103      }
104      perfect_access_js_gestion(this, perm, id_tab, tabsize, tabnumber, table);
105
106      $.ajax({
107        url: "{$link->getAdminLink('AdminAccess')|addslashes}",
108        cache: false,
109        data: {
110          ajaxMode: '1',
111          id_tab: id_tab,
112          id_profile: id_profile,
113          perm: perm,
114          enabled: enabled,
115          submitAddAccess: '1',
116          action: 'updateAccess',
117          ajax: '1',
118          token: '{getAdminToken tab='AdminAccess'}'
119        },
120        success: function (res, textStatus, jqXHR) {
121          try {
122            if (res == 'ok')
123              showSuccessMessage("{l s='Update successful' js=1}");
124            else
125              showErrorMessage("{l s='Update error' js=1}");
126          }
127          catch (e) {
128            jAlert('Technical error');
129          }
130        }
131      });
132    });
133
134    $(".changeModuleAccess").change(function () {
135      var tout = $(this).data('rel').split('||');
136      var id_module = tout[0];
137      var perm = tout[1];
138      var id_profile = tout[2];
139      var enabled = $(this).is(':checked') ? 1 : 0;
140      var enabled_attr = $(this).is(':checked') ? true : false;
141      var table = 'table#table_module_' + id_profile;
142
143      if (id_module == -1)
144        $(table + ' .ajax-ma-' + perm).each(function (key, value) {
145          $(this).attr("checked", enabled_attr);
146        });
147      else if (!enabled)
148        $(table + ' #ajax-ma-' + perm + '-master').each(function (key, value) {
149          $(this).attr("checked", enabled_attr);
150        });
151
152      $.ajax({
153        url: "{$link->getAdminLink('AdminAccess')|addslashes}",
154        cache: false,
155        data: {
156          ajaxMode: '1',
157          id_module: id_module,
158          perm: perm,
159          enabled: enabled,
160          id_profile: id_profile,
161          changeModuleAccess: '1',
162          action: 'updateModuleAccess',
163          ajax: '1',
164          token: '{getAdminToken tab='AdminAccess'}'
165        },
166        success: function (res, textStatus, jqXHR) {
167          try {
168            if (res == 'ok')
169              showSuccessMessage("{l s='Update successful' js=1}");
170            else
171              showErrorMessage("{l s='Update error' js=1}");
172          }
173          catch (e) {
174            jAlert('Technical error');
175          }
176        }
177      });
178    });
179
180  });
181</script>
182{if $show_toolbar}
183  {include file="toolbar.tpl" toolbar_btn=$toolbar_btn toolbar_scroll=$toolbar_scroll title=$title}
184  <div class="leadin">{block name="leadin"}{/block}</div>
185{/if}
186<div class="row">
187  <div class="productTabs col-lg-2">
188    <div class="tab list-group">
189      {foreach $profiles as $profile}
190        <a class="list-group-item nav-profile {if $profile.id_profile == $current_profile}active{/if}"
191           id="profile-{$profile.id_profile|intval}"
192           href="{$current|escape:'html':'UTF-8'}&amp;token={$token|escape:'html':'UTF-8'}&amp;id_profile={$profile.id_profile|intval}">{$profile.name|escape:'htmlall':'UTF-8'}</a>
193      {/foreach}
194    </div>
195  </div>
196  <form id="{$table}_form" class="defaultForm form-horizontal col-lg-10"
197        action="{$current|escape:'html':'UTF-8'}&amp;{$submit_action|escape:'htmlall':'UTF-8'}=1&amp;token={$token|escape:'html':'UTF-8'}"
198        method="post" enctype="multipart/form-data">
199    {if $form_id}
200      <input type="hidden" name="{$identifier|escape:'htmlall':'UTF-8'}" id="{$identifier|escape:'htmlall':'UTF-8'}" value="{$form_id|escape:'htmlall':'UTF-8'}"/>
201    {/if}
202    {assign var=tabsize value=count($tabs)}
203    {foreach $tabs AS $tab}
204      {if $tab.id_tab > $tabsize}
205        {assign var=tabsize value=$tab.id_tab}
206      {/if}
207    {/foreach}
208    {foreach $profiles as $profile}
209      <div class="profile-{$profile.id_profile|intval} tab-profile"
210           style="display:{if $profile.id_profile != $current_profile}none{/if}">
211        <div class="row">
212          {if $profile.id_profile != $admin_profile}
213            <div class="col-lg-6">
214              <div class="panel">
215                <h3>{l s='Menu'}</h3>
216                <table class="table" id="table_{$profile.id_profile|intval}">
217                  <thead>
218                    <tr>
219                      <th></th>
220                      <th>
221                        <input type="checkbox" name="1"
222                               class="viewall ajaxPower"{if $access_edit == 1} data-rel="-1||{$profile.id_profile|intval}||view||{$tabsize|intval}||{count($tabs)|intval}"{else} disabled="disabled"{/if}/>
223                        {l s='View'}
224                      </th>
225                      <th>
226                        <input type="checkbox" name="1"
227                               class="addall ajaxPower"{if $access_edit == 1} data-rel="-1||{$profile.id_profile|intval}||add||{$tabsize|intval}||{count($tabs)|intval}"{else} disabled="disabled"{/if}/>
228                        {l s='Add'}
229                      </th>
230                      <th>
231                        <input type="checkbox" name="1"
232                               class="editall ajaxPower"{if $access_edit == 1} data-rel="-1||{$profile.id_profile|intval}||edit||{$tabsize|intval}||{count($tabs)|intval}"{else} disabled="disabled"{/if}/>
233                        {l s='Edit'}
234                      </th>
235                      <th>
236                        <input type="checkbox" name="1"
237                               class="deleteall ajaxPower"{if $access_edit == 1} data-rel="-1||{$profile.id_profile|intval}||delete||{$tabsize|intval}||{count($tabs)|intval}"{else} disabled="disabled"{/if}/>
238                        {l s='Delete'}
239                      </th>
240                      <th>
241                        <input type="checkbox" name="1"
242                               class="allall ajaxPower"{if $access_edit == 1} data-rel="-1||{$profile.id_profile|intval}||all||{$tabsize|intval}||{count($tabs)|intval}"{else} disabled="disabled"{/if}/>
243                        {l s='All'}
244                      </th>
245                    </tr>
246                  </thead>
247                  <tbody>
248                    {if !count($tabs)}
249                      <tr>
250                        <td colspan="6">{l s='No menu'}</td>
251                      </tr>
252                    {else}
253                      {foreach $tabs AS $tab}
254                        {assign var=access value=$accesses[$profile.id_profile]}
255                        {if isset($access[$tab.id_tab])}
256                          {if !$tab.id_parent || $tab.id_parent == -1}
257                            {assign var=is_child value=false}
258                            {assign var=result_accesses value=0}
259                            <tr{if !$is_child} class="parent"{/if}>
260                              <td{if !$is_child} class="bold"{/if}>{if $is_child} &raquo; {/if}
261                                <strong>{$tab.name|escape:'htmlall':'UTF-8'}</strong></td>
262                              {foreach $perms as $perm}
263                                {if $access_edit == 1}
264                                  <td>
265                                    <input type="checkbox"
266                                           data-rel="{$access[$tab.id_tab]['id_tab']|intval}||{$profile.id_profile|intval}||{$perm}||{$tabsize|intval}||{count($tabs)|intval}"
267                                           class="ajaxPower {$perm|escape:'htmlall':'UTF-8'} {$access[$tab.id_tab]['id_tab']|intval}"{if $access[$tab.id_tab][$perm] == 1} checked="checked"{/if}/>
268                                  </td>
269                                {else}
270                                  <td>
271                                    <input type="checkbox"
272                                           disabled="disabled"{if $access[$tab.id_tab][$perm] == 1} checked="checked"{/if}/>
273                                  </td>
274                                {/if}
275                                {assign var=result_accesses value=$result_accesses + $access[$tab.id_tab][$perm]}
276                              {/foreach}
277                              <td>
278                                <input type="checkbox"{if $access_edit == 1} data-rel="{$access[$tab.id_tab]['id_tab']|intval}||{$profile.id_profile|intval}||all||{$tabsize|intval}||{count($tabs)|intval}" class="ajaxPower all {$access[$tab.id_tab]['id_tab']|intval}"{else} class="all {$access[$tab.id_tab]['id_tab']|intval}" disabled="disabled"{/if}{if $result_accesses == 4} checked="checked"{/if}/>
279                              </td>
280                            </tr>
281                            {foreach $tabs AS $child}
282                              {if $child.id_parent === $tab.id_tab}
283                                {if isset($access[$child.id_tab])}
284                                  {assign var=is_child value=true}
285                                  {assign var=result_accesses value=0}
286                                  <tr class="child-{$child.id_parent}">
287                                    <td{if !$is_child} class="bold"{/if}>{if $is_child} &raquo; {/if}{$child.name|escape:'htmlall':'UTF-8'}</td>
288                                    {foreach $perms as $perm}
289                                      {if $access_edit == 1}
290                                        <td>
291                                          <input type="checkbox"
292                                                 data-rel="{$access[$child.id_tab]['id_tab']|intval}||{$profile.id_profile|intval}||{$perm|escape:'htmlall':'UTF-8'}||{$tabsize|intval}||{count($tabs)|intval}"
293                                                 class="ajaxPower {$perm} {$access[$child.id_tab]['id_tab']|intval}"{if $access[$child.id_tab][$perm] == 1} checked="checked"{/if}/>
294                                        </td>
295                                      {else}
296                                        <td>
297                                          <input type="checkbox"
298                                                 disabled="disabled"{if $access[$child.id_tab][$perm] == 1} checked="checked"{/if}/>
299                                        </td>
300                                      {/if}
301                                      {assign var=result_accesses value=$result_accesses + $access[$child.id_tab][$perm]}
302                                    {/foreach}
303                                    <td>
304                                      <input type="checkbox"{if $access_edit == 1} data-rel="{$access[$child.id_tab]['id_tab']|intval}||{$profile.id_profile|intval}||all||{$tabsize|intval}||{count($tabs)|intval}" class="ajaxPower all {$access[$child.id_tab]['id_tab']|intval}"{else} class="all {$access[$child.id_tab]['id_tab']|intval}" disabled="disabled"{/if}{if $result_accesses == 4} checked="checked"{/if}/>
305                                    </td>
306                                  </tr>
307                                {/if}
308                              {/if}
309                            {/foreach}
310                          {/if}
311                        {/if}
312                      {/foreach}
313                    {/if}
314                  </tbody>
315                </table>
316              </div>
317            </div>
318            <div class="col-lg-6">
319              <div class="panel">
320                <h3>{l s='Modules'}</h3>
321                <table class="table" id="table_module_{$profile.id_profile|intval}">
322                  <thead>
323                    <tr>
324                      <th></th>
325                      <th>
326                        <input type="checkbox"{if $access_edit == 1} class="changeModuleAccess" data-rel="-1||view||{$profile.id_profile|intval}"{else} disabled="disabled"{/if}/> {l s='View'}
327                      </th>
328                      <th>
329                        <input type="checkbox"{if $access_edit == 1} class="changeModuleAccess" data-rel="-1||configure||{$profile.id_profile|intval}"{else} disabled="disabled"{/if}/> {l s='Configure'}
330                      </th>
331                      <th>
332                        <input type="checkbox"{if $access_edit == 1} class="changeModuleAccess" data-rel="-1||uninstall||{$profile.id_profile|intval}"{else} disabled="disabled"{/if}/> {l s='Uninstall'}
333                      </th>
334                    </tr>
335                  </thead>
336                  <tbody>
337                    {if !count($modules)}
338                      <tr>
339                        <td colspan="3">{l s='No modules are installed'}</td>
340                      </tr>
341                    {else}
342                      {foreach $modules[$profile.id_profile] AS $module}
343                        <tr>
344                          <td>&raquo; {$module.name|escape:'htmlall':'UTF-8'}</td>
345                          <td>
346                            <input type="checkbox"
347                                   value="1"{if $module.view == true} checked="checked"{/if}{if $access_edit == 1} class="ajax-ma-view changeModuleAccess" data-rel="{$module.id_module|intval}||view||{$profile.id_profile|intval}"{else} class="ajax-ma-view" disabled="disabled"{/if}/>
348                          </td>
349                          <td>
350                            <input type="checkbox"
351                                   value="1"{if $module.configure == true} checked="checked"{/if}{if $access_edit == 1} class="ajax-ma-configure changeModuleAccess" data-rel="{$module.id_module|intval}||configure||{$profile.id_profile|intval}"{else} class="ajax-ma-configure" disabled="disabled"{/if}/>
352                          </td>
353                          <td>
354                            <input type="checkbox"
355                                   value="1"{if $module.uninstall == true} checked="checked"{/if}{if $access_edit == 1} class="ajax-ma-uninstall changeModuleAccess" data-rel="{$module.id_module|intval}||uninstall||{$profile.id_profile|intval}"{else} class="ajax-ma-uninstall" disabled="disabled"{/if}/>
356                          </td>
357                        </tr>
358                      {/foreach}
359                    {/if}
360                  </tbody>
361                </table>
362              </div>
363            </div>
364          {else}
365            <div class="col-lg-12">
366              <div class="panel">
367                {l s='Administrator permissions cannot be modified.'}
368              </div>
369            </div>
370          {/if}
371        </div>
372      </div>
373    {/foreach}
374  </form>
375</div>
376