[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/workflow/inc/ -> class.ui_adminroles.inc.php (source)

   1  <?php
   2  
   3      require_once(dirname(__FILE__) . SEP . 'class.workflow.inc.php');
   4  
   5      class ui_adminroles extends workflow
   6      {
   7          var $public_functions = array(
   8              'form'    => true
   9          );
  10  
  11          var $process_manager;
  12  
  13          var $activity_manager;
  14  
  15  		function ui_adminroles()
  16          {
  17              parent::workflow();
  18  
  19                       //regis: acl check
  20              if ( !(($GLOBALS['egw']->acl->check('run',1,'admin')) || ($GLOBALS['egw']->acl->check('admin_workflow',1,'workflow'))) )
  21              {
  22                  $GLOBALS['egw']->common->egw_header();
  23                  echo parse_navbar();
  24                  echo lang('access not permitted');
  25                  $GLOBALS['egw']->log->message('F-Abort, Unauthorized access to workflow.ui_adminroles');
  26                  $GLOBALS['egw']->log->commit();
  27                  $GLOBALS['egw']->common->egw_exit();
  28              }
  29  
  30              $this->process_manager    =& CreateObject('workflow.workflow_processmanager');
  31              $this->activity_manager    =& CreateObject('workflow.workflow_activitymanager');
  32              $this->role_manager    =& CreateObject('workflow.workflow_rolemanager');
  33              
  34          }
  35  
  36  		function form()
  37          {
  38              $GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps']['workflow']['title'] . ' - ' . lang('Admin Process Roles');
  39              $GLOBALS['egw']->common->egw_header();
  40              echo parse_navbar();
  41  
  42              $this->t->set_file('admin_roles', 'admin_roles.tpl');
  43  
  44              $this->order        = get_var('order', 'GET', 'wf_name');
  45              $this->sort            = get_var('sort', 'GET', 'asc');
  46              $this->sort_mode    = $this->order . '__'. $this->sort;
  47              $sort_mode2            = get_var('sort_mode2', 'any', 'wd_name__asc');
  48              $role_id                = (int)get_var('role_id', 'any', 0);
  49  
  50              if (!$this->wf_p_id) die(lang('No process indicated'));
  51              
  52              //do we need to check validity, warning high load on database
  53              $checkvalidity=false;
  54  
  55              // save new role
  56              if (isset($_POST['save']))
  57              {
  58                  $this->save_role($role_id, $_POST['name'], $_POST['description']);
  59                  $checkvalidity = true;
  60              }
  61  
  62              // save new mapping
  63              if (isset($_POST['save_map']))
  64              {
  65                  $this->save_mapping($_POST['user'], $_POST['role']);
  66                  $this->message[] = lang('New mapping added');
  67                  $checkvalidity = true;
  68              }
  69  
  70              // delete roles
  71              if (isset($_POST['delete_roles']))
  72              {
  73                  $this->delete_roles(array_keys($_POST['role']));
  74                  $checkvalidity = true;
  75              }
  76              
  77              // delete mappings
  78              if (isset($_POST['delete_map'])) 
  79              {
  80                  $this->delete_maps(array_keys($_POST['map']));
  81              }
  82  
  83              // retrieve process info
  84              $proc_info = $this->process_manager->get_process($this->wf_p_id);
  85  
  86              // check process validity and show errors if necessary
  87              if ($checkvalidity) $proc_info['isValid'] = $this->show_errors($this->activity_manager, $error_str);
  88  
  89              // fill proc_bar
  90              $this->t->set_var('proc_bar', $this->fill_proc_bar($proc_info));
  91              
  92              // retrieve role info
  93              if ($role_id || isset($_POST['new_role']))
  94              {
  95                  $role_info = $this->role_manager->get_role($this->wf_p_id, $_GET['role_id']);
  96              }
  97              else
  98              {
  99                  $role_info = array(
 100                      'name'            => '',
 101                      'description'    => '',
 102                      'role_id'        => 0
 103                  );
 104              }
 105  
 106              // retrieve all roles info
 107              $all_roles = $this->role_manager->list_roles($this->wf_p_id, 0, -1, 'wf_name__asc', '');
 108              //echo "all_roles: <pre>";print_r($all_roles);echo "</pre>";
 109              
 110              //collect some messages from used objects
 111              $this->message[] = $this->activity_manager->get_error(false, _DEBUG);
 112              $this->message[] = $this->process_manager->get_error(false, _DEBUG);
 113              $this->message[] = $this->role_manager->get_error(false, _DEBUG);
 114  
 115  
 116              // fill the general varibles of the template
 117              $this->t->set_var(array(
 118                  'message'                => implode('<br>', array_filter($this->message)),
 119                  'errors'                => $error_str,
 120                  'form_action_adminroles'    => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminroles.form'),
 121                  'role_info_role_id'        => $role_info['wf_role_id'],
 122                  'role_info_name'        => $role_info['wf_name'],
 123                  'role_info_description'    => $role_info['wf_description'],
 124                  'p_id'                    => $this->wf_p_id,
 125                  'start'                    => $this->start,
 126              ));
 127  
 128              $this->show_process_roles_list($all_roles['data']);
 129  
 130              // build users and roles multiple select boxes
 131              $this->show_users_roles_selects($all_roles['data']);
 132  
 133              // retrieve and show mappings
 134              $this->show_mappings();
 135  
 136              $this->translate_template('admin_roles');
 137              $this->t->pparse('output', 'admin_roles');
 138              $GLOBALS['egw']->common->egw_footer();
 139          }
 140  
 141  		function save_role($role_id, $name, $description)
 142          {
 143              $vars = array(
 144                  'wf_name'            => $name,
 145                  'wf_description'    => $description,
 146              );
 147              if ($this->role_manager->replace_role($this->wf_p_id, $role_id, $vars))
 148              {
 149                  $this->message[] = lang('Role saved');
 150              }
 151              else
 152              {
 153                  $this->message[] = lang('Role not saved (maybe a name collision)');
 154              }
 155              
 156          }
 157  
 158  		function delete_roles($roles_ids)
 159          {
 160              foreach ($roles_ids as $role_id)
 161              {
 162                  $this->role_manager->remove_role($this->wf_p_id, $role_id);
 163              }
 164              $this->message[] = lang('Roles deleted');
 165          }
 166          
 167  		function delete_maps($mappings)
 168          {
 169                          foreach($mappings as $map)
 170                          {
 171                                       $pos = strpos($map,":::");
 172                                       $user=substr($map,0,$pos);
 173                                       $role_id=substr($map,$pos+3);
 174                                       $this->role_manager->remove_mapping($user,$role_id);
 175                          }
 176              $this->message[] = lang('Mappings deleted');
 177          }
 178          
 179  		function show_mappings()
 180          {
 181              $this->t->set_block('admin_roles', 'block_list_mappings', 'list_mappings');
 182              $mappings = $this->role_manager->list_mappings($this->wf_p_id, $this->start, -1, $this->sort_mode, '');
 183              //echo "mappings: <pre>";print_r($mappings);echo "</pre>";
 184              if (!count($mappings['data'])) {
 185                  $this->t->set_var('list_mappings', '<tr><td colspan="3" align="center">'. lang('There are no mappings defined for this process')  .'</td></tr>');
 186              }
 187              else {    
 188                  foreach ($mappings['data'] as $mapping)
 189                  {
 190                      $GLOBALS['egw']->accounts->get_account_name($mapping['wf_user'], $lid, $fname, $lname);
 191                      $this->t->set_var(array(
 192                          'map_user_id'    => $mapping['wf_user'],
 193                          'map_role_id'    => $mapping['wf_role_id'],
 194                          'map_role_name'    => $mapping['wf_name'],
 195                          'map_user_name'    => $fname . ' ' . $lname,
 196                      ));
 197                      $this->t->parse('list_mappings', 'block_list_mappings', true);
 198                  }
 199              }
 200          }
 201  
 202  		function save_mapping($users, $roles)
 203          {
 204              foreach ($users as $user)
 205              {
 206                  $account_type   = $user{0};
 207                  $user           = substr($user, 1);
 208                  foreach ($roles as $role)
 209                  {
 210                      $this->role_manager->map_user_to_role($this->wf_p_id, $user, $role, $account_type);
 211                  }
 212              }
 213          }
 214  
 215  		function show_users_roles_selects($all_roles_data)
 216          {
 217              $this->t->set_block('admin_roles', 'block_select_users', 'select_users');
 218              $users =& $GLOBALS['egw']->accounts->get_list('accounts');
 219              //_debug_array($users);
 220              $groups =& $GLOBALS['egw']->accounts->get_list('groups');
 221              //_debug_array($groups);
 222              foreach ($users as $user)
 223              {
 224                  $this->t->set_var(array(
 225                      'account_id'    => 'u'.$user['account_id'],
 226                      'account_name'    => $user['account_firstname'] . ' ' . $user['account_lastname'],
 227                  ));
 228                  $this->t->parse('select_users', 'block_select_users', true);
 229              }
 230              foreach ($groups as $group)
 231              {
 232                  $this->t->set_var(array(
 233                      'account_id'    => 'g'.$group['account_id'],
 234                      'account_name'    => $group['account_firstname'] . ' ' . lang('Group'),
 235                  ));
 236                  $this->t->parse('select_users', 'block_select_users', true);
 237              }
 238  
 239              $this->t->set_block('admin_roles', 'block_select_roles', 'select_roles');
 240              foreach ($all_roles_data as $role)
 241              {
 242                  $this->t->set_var(array(
 243                      'select_role_id'        => $role['wf_role_id'],
 244                      'select_role_name'    => $role['wf_name']
 245                  ));
 246                  $this->t->parse('select_roles', 'block_select_roles', true);
 247              }
 248          }
 249  
 250  		function show_process_roles_list($all_roles_data)
 251          {
 252              $this->t->set_block('admin_roles', 'block_process_roles_list', 'process_roles_list');
 253              $this->translate_template('block_process_roles_list');
 254  
 255              foreach ($all_roles_data as $role)
 256              {
 257                  $this->t->set_var(array(
 258                      'all_roles_role_id'        => $role['wf_role_id'],
 259                      'all_roles_href'        => $GLOBALS['egw']->link('/index.php', 'menuaction=workflow.ui_adminroles.form&sort_mode='. $this->sort_mode .'&start='. $this->start .'&find='. $find .'&p_id='. $this->wf_p_id .'&sort_mode2='. $sort_mode2 .'&role_id='. $role['wf_role_id']),
 260                      'all_roles_name'        => $role['wf_name'],
 261                      'all_roles_description'    => $role['wf_description'],
 262                      'color_line'            => $this->nextmatchs->alternate_row_color($tr_color),
 263                  ));
 264                  $this->t->parse('process_roles_list', 'block_process_roles_list', true);
 265              }
 266              if (!count($all_roles_data)) $this->t->set_var('process_roles_list', '<tr><td colspan="3">'. lang('There are no roles defined for this process') .'</td></tr>');
 267  
 268          }
 269      }
 270  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7