Changeset 4247


Ignore:
Timestamp:
Nov 10, 2009, 10:20:34 PM (11 years ago)
Author:
LucMorizur
Message:

[Event Cats] Continue duplication management using cat_perm.php and cat_perm.tpl codes

Location:
extensions/event_cats
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/event_cats/admin/duplication.inc.php

    r4233 r4247  
    88$template->assign('ec_conf', $ec_conf);
    99
     10
     11
     12
     13
     14
     15// A lot of below code has simply been copied-pasted from file cat_perm.php .
     16// Many thanks to people who wrote it !
     17
     18// +-----------------------------------------------------------------------+
     19// |                          form construction                            |
     20// +-----------------------------------------------------------------------+
     21
     22// groups denied are the groups not granted. So we need to find all groups
     23// minus groups granted to find groups denied.
     24
     25$groups = array();
     26
     27$query = '
     28SELECT id, name
     29  FROM '.GROUPS_TABLE.'
     30  ORDER BY name ASC
     31;';
     32$groups = simple_hash_from_query($query, 'id', 'name');
     33$template->assign('all_groups', $groups);
     34
     35// groups granted to access the category
     36$query = "
     37SELECT `arg1`
     38  FROM ".EVNTCATS_TABLE."
     39  WHERE `code` IS NULL
     40    AND `arg1` IS NOT NULL
     41;";
     42$group_granted_ids = array_from_query($query, 'arg1');
     43$group_granted_ids = order_by_name($group_granted_ids, $groups);
     44$template->assign('group_granted_ids', $group_granted_ids);
     45
     46
     47// groups denied
     48$template->assign('group_denied_ids',
     49    order_by_name(array_diff(array_keys($groups), $group_granted_ids), $groups)
     50  );
     51
     52// users...
     53$users = array();
     54
     55$query = "
     56SELECT ".$conf['user_fields']['id']." AS id,
     57       ".$conf['user_fields']['username']." AS username
     58  FROM ".USERS_TABLE."
     59;";
     60$users = simple_hash_from_query($query, 'id', 'username');
     61$template->assign('all_users', $users);
     62
     63
     64$query = "
     65SELECT `arg2`
     66  FROM ".EVNTCATS_TABLE."
     67  WHERE `code` IS NULL
     68    AND `arg2` IS NOT NULL
     69;";
     70$user_granted_direct_ids = array_from_query($query, 'arg2');
     71$user_granted_direct_ids = order_by_name($user_granted_direct_ids, $users);
     72$template->assign('user_granted_direct_ids', $user_granted_direct_ids);
     73
     74
     75
     76$user_granted_indirect_ids = array();
     77if (count($group_granted_ids) > 0)
     78{
     79  $granted_groups = array();
     80
     81  $query = "
     82SELECT user_id, group_id
     83  FROM ".USER_GROUP_TABLE."
     84  WHERE group_id IN (".implode(',', $group_granted_ids).")
     85";
     86  $result = pwg_query($query);
     87  while ($row = mysql_fetch_array($result))
     88  {
     89    if (!isset($granted_groups[$row['group_id']]))
     90    {
     91      $granted_groups[$row['group_id']] = array();
     92    }
     93    array_push($granted_groups[$row['group_id']], $row['user_id']);
     94  }
     95
     96  $user_granted_by_group_ids = array();
     97
     98  foreach ($granted_groups as $group_users)
     99  {
     100    $user_granted_by_group_ids = array_merge($user_granted_by_group_ids,
     101                                             $group_users);
     102  }
     103  $user_granted_by_group_ids = array_unique($user_granted_by_group_ids);
     104 
     105 
     106  $user_granted_indirect_ids = array_diff($user_granted_by_group_ids,
     107                                          $user_granted_direct_ids);
     108  $user_granted_indirect_ids =
     109    order_by_name($user_granted_indirect_ids, $users); 
     110  foreach ($user_granted_indirect_ids as $user_id)
     111  {
     112    foreach ($granted_groups as $group_id => $group_users)
     113    {
     114      if (in_array($user_id, $group_users))
     115      {
     116        $template->append(
     117          'user_granted_indirects',
     118          array(
     119            'USER'=>$users[$user_id],
     120            'GROUP'=>$groups[$group_id]
     121            )
     122          );
     123        break;
     124      }
     125    }
     126  }
     127}
     128
     129$user_denied_ids = array_diff(array_keys($users),
     130                              $user_granted_indirect_ids,
     131                              $user_granted_direct_ids);
     132$user_denied_ids = order_by_name($user_denied_ids, $users);
     133$template->assign('user_denied_ids', $user_denied_ids);
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146/* */
     147
     148
    10149?>
  • extensions/event_cats/admin/evntcats_admin.php

    r4239 r4247  
    5555
    5656include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     57include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
    5758include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
    5859include_once(PHPWG_ROOT_PATH.'include/functions_url.inc.php');
  • extensions/event_cats/admin/template/duplication.tpl

    r4233 r4247  
    44
    55{* <!-- Available soon... --> *}
    6 
    76<p>Bientôt disponible :-] !</p>
    87
    9 <form class = "titrePage">
     8<!-- Aknowledgement ------------------------------------------------------
     9A lot of below code has simply been copied-pasted from file cat_perm.tpl .
     10Many thanks to people who wrote it !
     11------------------------------------------------------------------------->
     12
     13{* <!-- Duplication configuration parameters --> *}
     14<form class = "titrePage" name = "ec_duplic_conf">
    1015  <fieldset>
    1116    <legend>{'ec_duplication_config'|@translate}</legend>
     
    4954</form>
    5055
    51 {*
    52 
    53 <form action = "{$F_ACTION}" method = "post" id = "categoryPermissions">
     56{* <!-- Duplication settings by groups / user ids --> *}
     57<form action = "" method = "post" name = "ec_duplic_set" id="categoryPermissions">
    5458
    5559  <h4>{'Groups'|@translate}</h4>
     
    6266      {/foreach}
    6367    </ul>
    64     <input class = "submit" type = "submit" name = "deny_groups_submit" value = "{'Deny selected groups'|@translate}" {$TAG_INPUT_ENABLED}/>
     68    <input class = "submit" type = "submit" name = "deny_groups_submit" value = "{'Deny selected groups'|@translate}" />
    6569  </fieldset>
    6670
     
    7276      {/foreach}
    7377    </ul>
    74     <input class = "submit" type = "submit" name = "grant_groups_submit" value = "{'Grant selected groups'|@translate}" {$TAG_INPUT_ENABLED}/>
     78    <input class = "submit" type = "submit" name = "grant_groups_submit" value = "{'Grant selected groups'|@translate}" />
    7579  </fieldset>
    7680
     
    8488      {/foreach}
    8589    </ul>
    86     <input class = "submit" type = "submit" name = "deny_users_submit" value = "{'Deny selected users'|@translate}" {$TAG_INPUT_ENABLED}/>
     90    <input class = "submit" type = "submit" name = "deny_users_submit" value = "{'Deny selected users'|@translate}" />
    8791  </fieldset>
    8892
     
    105109      {/foreach}
    106110    </ul>
    107     <input class = "submit" type = "submit" name = "grant_users_submit" value = "{'Grant selected users'|@translate}" {$TAG_INPUT_ENABLED}/>
     111    <input class = "submit" type = "submit" name = "grant_users_submit" value = "{'Grant selected users'|@translate}" />
    108112  </fieldset>
    109113
    110114</form>
    111115
    112 
    113 *}
    114116
    115117
  • extensions/event_cats/admin/template/header.inc.tpl

    r4228 r4247  
    2424    <hr width = 75% size = 3 />
    2525  </p>
    26 {* {else}
    27   <br> *}
    2826{/if}
  • extensions/event_cats/include/evntcats_main_funcs.inc.php

    r4239 r4247  
    274274function build_ec_lists() {
    275275 
    276   global $ec_ap_ok, $template, $ec_lists;
     276  global $ec_ap_ok, $template, $ec_lists, $conf;
    277277 
    278278  $ec_lists = array();
     
    295295  $ec_lists['user_ids'] = array();
    296296  $q = pwg_query("
    297     SELECT `id`,`username`
     297    SELECT
     298      ".$conf['user_fields']['id']." AS id,
     299      ".$conf['user_fields']['username']." AS username
    298300    FROM `".USERS_TABLE."`
    299     WHERE `id` > 2
     301    WHERE id > 2
    300302  ");
    301303  while ($r = mysql_fetch_assoc($q))
  • extensions/event_cats/main.inc.php

    r4239 r4247  
    100100  $ec_img = NULL;
    101101
     102  // For compatibility ; must be removed
     103  if (isset($_GET['log'])) $_GET['autolog'] = $_GET['log'];
     104  // For compatibility ; must be removed
     105 
    102106  if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) {
    103107    if (!is_a_guest()) {
Note: See TracChangeset for help on using the changeset viewer.