phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc/class.accounts.inc.php, 1.11


From: nomail
Subject: [Phpgroupware-cvs] phpgwapi/inc/class.accounts.inc.php, 1.11
Date: Fri, 25 Jun 2004 10:17:37 +0200

Update of /phpgwapi/inc
Modified Files:
        Branch: 
          class.accounts.inc.php

date: 2004/06/25 08:17:37;  author: fipsfuchs;  state: Exp;  lines: +610 -1

Log Message:
inheritance like in 0.9.16
fields for accounts data generalized
=====================================================================
Index: phpgwapi/inc/class.accounts.inc.php
diff -u phpgwapi/inc/class.accounts.inc.php:1.10 
phpgwapi/inc/class.accounts.inc.php:1.11
--- phpgwapi/inc/class.accounts.inc.php:1.10    Sun Sep 23 19:08:44 2001
+++ phpgwapi/inc/class.accounts.inc.php Fri Jun 25 08:17:37 2004
@@ -11,5 +11,614 @@
                }
        }
        include(PHPGW_API_INC . '/class.accounts_' . 
$GLOBALS['phpgw_info']['server']['account_repository'] . '.inc.php');
-       include(PHPGW_API_INC . '/class.accounts_shared.inc.php');
+       
+       /**
+       * @internal Moved again at least temporarily since sql and ldap use it.
+       */
+       $GLOBALS['phpgw_info']['server']['global_denied_users'] = array(
+               'root'     => True, 'bin'      => True, 'daemon'   => True,
+               'adm'      => True, 'lp'       => True, 'sync'     => True,
+               'shutdown' => True, 'halt'     => True, 'ldap'     => True,
+               'mail'     => True, 'news'     => True, 'uucp'     => True,
+               'operator' => True, 'games'    => True, 'gopher'   => True,
+               'nobody'   => True, 'xfs'      => True, 'pgsql'    => True,
+               'mysql'    => True, 'postgres' => True, 'oracle'   => True,
+               'ftp'      => True, 'gdm'      => True, 'named'    => True,
+               'alias'    => True, 'web'      => True, 'sweep'    => True,
+               'cvs'      => True, 'qmaild'   => True, 'qmaill'   => True,
+               'qmaillog' => True, 'qmailp'   => True, 'qmailq'   => True,
+               'qmailr'   => True, 'qmails'   => True, 'rpc'      => True,
+               'rpcuser'  => True, 'amanda'   => True, 'apache'   => True,
+               'pvm'      => True, 'squid'    => True, 'ident'    => True,
+               'nscd'     => True, 'mailnull' => True, 'cyrus'    => True,
+               'backup'    => True
+       );
+
+       $GLOBALS['phpgw_info']['server']['global_denied_groups'] = array(
+               'root'      => True, 'bin'       => True, 'daemon'    => True,
+               'sys'       => True, 'adm'       => True, 'tty'       => True,
+               'disk'      => True, 'lp'        => True, 'mem'       => True,
+               'kmem'      => True, 'wheel'     => True, 'mail'      => True,
+               'uucp'      => True, 'man'       => True, 'games'     => True,
+               'dip'       => True, 'ftp'       => True, 'nobody'    => True,
+               'floppy'    => True, 'xfs'       => True, 'console'   => True,
+               'utmp'      => True, 'pppusers'  => True, 'popusers'  => True,
+               'slipusers' => True, 'slocate'   => True, 'mysql'     => True,
+               'dnstools'  => True, 'web'       => True, 'named'     => True,
+               'dba'       => True, 'oinstall'  => True, 'oracle'    => True,
+               'gdm'       => True, 'sweep'     => True, 'cvs'       => True,
+               'postgres'  => True, 'qmail'     => True, 'nofiles'   => True,
+               'ldap'      => True, 'backup'    => True
+       );
+
+       class accounts_
+       {
+               var $memberships = Array();
+               var $members = Array();
+
+               var $fields = array(0  => 'account_id',
+                                   1  => 'account_lid',
+                                   2  => 'firstname',
+                                   3  => 'lastname',
+                                   4  => 'passwd',
+                                   5  => 'type',
+                                   6  => 'status',
+                                   7  => 'expires',
+                                   8  => 'homedirectory',
+                                   9  => 'loginshell',
+                                   10 => 'groups'
+                                  );
+
+               
/**************************************************************************\
+               * Standard constructor for setting $this->account_id            
           *
+               * This constructor sets the account id, if string is sent, 
converts to id  *
+               * I might move this to the accounts_shared if it stays around   
           *
+               
\**************************************************************************/
+               function accounts_($account_id = '', $account_type='')
+               {
+                       if($account_id != '')
+                       {
+                               $this->account_id = get_account_id($account_id);
+                               $this->data[$this->fields[0]] = 
get_account_id($account_id);
+                       }
+
+                       if($account_type != '')
+                       {
+                               $this->account_type = $account_type;
+                               $this->data[$this->fields[5]] = $account_type;
+                       }
+               }
+
+               function is_expired()
+               {
+                       if($this->data['expires'] != -1 && 
$this->data['expires'] < time())
+                       {
+                               return True;
+                       }
+                       else
+                       {
+                               return False;
+                       }
+               }
+
+               function read()
+               {
+                       if(count($this->data) == 0)
+                       {
+                               $this->read_repository();
+                       }
+
+                       reset($this->data);
+                       return $this->data;
+               }
+
+               // this is more a replace_data
+               function update_data($data)
+               {
+                       reset($data);
+                       $this->data = Array();
+                       $this->data = $data;
+
+                       reset($this->data);
+                       return $this->data;
+               }
+
+               function membership($accountid = '')
+               {
+                       $account_id = get_account_id($accountid);
+
+                       $security_equals = Array();
+                       $security_equals = 
$GLOBALS['phpgw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id);
+
+                       if($security_equals == False)
+                       {
+                               return False;
+                       }
+
+                       $this->memberships = Array();
+
+                       for($idx=0; $idx<count($security_equals); $idx++)
+                       {
+                               $groups = intval($security_equals[$idx]);
+                               $this->memberships[] = Array('account_id' => 
$groups, 'account_name' => $this->id2name($groups));
+                       }
+
+                       return $this->memberships;
+               }
+
+               function member($accountid = '')
+               {
+                       $account_id = get_account_id($accountid);
+
+                       $security_equals = Array();
+                       $acl = CreateObject('phpgwapi.acl');
+                       $security_equals = 
$acl->get_ids_for_location($account_id, 1, 'phpgw_group');
+                       unset($acl);
+
+                       if($security_equals == False)
+                       {
+                               return False;
+                       }
+
+                       for($idx=0; $idx<count($security_equals); $idx++)
+                       {
+                               $name = 
$this->id2name(intval($security_equals[$idx]));
+                               $this->members[] = Array('account_id' => 
intval($security_equals[$idx]), 'account_name' => $name);
+                       }
+
+                       return $this->members;
+               }
+
+               /*!
+               @function get_nextid
+               @abstract Using the common functions next_id and last_id, find 
the next available account_id
+               @param $account_type (optional, default to 'u')
+               */
+               function get_nextid($account_type='u')
+               {
+                       $min = 
$GLOBALS['phpgw_info']['server']['account_min_id'] ? 
$GLOBALS['phpgw_info']['server']['account_min_id'] : 0;
+                       $max = 
$GLOBALS['phpgw_info']['server']['account_max_id'] ? 
$GLOBALS['phpgw_info']['server']['account_max_id'] : 0;
+
+                       if($account_type == 'g')
+                       {
+                               $type = 'groups';
+                       }
+                       else
+                       {
+                               $type = 'accounts';
+                       }
+                       $nextid = 
intval($GLOBALS['phpgw']->common->last_id($type,$min,$max));
+
+                       /* Loop until we find a free id */
+                       $free = 0;
+                       while(!$free)
+                       {
+                               $account_lid = '';
+                               //echo '<br>calling search for id: '.$nextid;
+                               if($this->exists($nextid))
+                               {
+                                       $nextid = 
intval($GLOBALS['phpgw']->common->next_id($type,$min,$max));
+                               }
+                               else
+                               {
+                                       $account_lid = $this->id2name($nextid);
+                                       /* echo '<br>calling search for lid: 
'.$account_lid . '(from account_id=' . $nextid . ')'; */
+                                       if ($this->exists($account_lid))
+                                       {
+                                               $nextid = 
intval($GLOBALS['phpgw']->common->next_id($type,$min,$max));
+                                       }
+                                       else
+                                       {
+                                               $free = True;
+                                       }
+                               }
+                       }
+                       if($GLOBALS['phpgw_info']['server']['account_max_id'] &&
+                               ($nextid > 
$GLOBALS['phpgw_info']['server']['account_max_id']))
+                       {
+                               return False;
+                       }
+                       /* echo '<br>using'.$nextid;exit; */
+                       return $nextid;
+               }
+
+               /*!
+               @function return_members
+               @abstract returns an array of users and groups seperated, 
including all members of groups, which i.e. have acl access for an application
+               @param $app_users (array, default to 0)
+               */
+               function return_members($app_users = 0)
+               {
+                       for ($i = 0;$i<count($app_users);$i++)
+                       {
+                               $type = 
$GLOBALS['phpgw']->accounts->get_type($app_users[$i]);
+                               if($type == 'g')
+                               {
+                                       $add_users['groups'][] = $app_users[$i];
+                                       $members[] = 
$GLOBALS['phpgw']->acl->get_ids_for_location($app_users[$i],1,'phpgw_group');
+                               }
+                               else
+                               {
+                                       $add_users['users'][] = $app_users[$i];
+                               }
+                       }
+
+                       $i = count($add_users['users']);
+
+                       while(is_array($members) && list(,$mem) = 
each($members))
+                       {
+                               for($j=0;$j<count($mem);$j++)
+                               {
+                                       $add_users['users'][$i] = $mem[$j];
+                                       $i++;
+                               }
+                       }
+                       return $add_users;
+               }
+
+               function java_script($app = '')
+               {
+                       if(!$app)
+                       {
+                               $app = 
$GLOBALS['phpgw_info']['user']['current_app'];
+                       }
+
+                       switch($app)
+                       {
+                               case 'calendar':
+                                       $select_name = "participants[]'][0]";
+                                       break;
+                               case 'admin':
+                                       $select_name = "account_user[]']";
+                                       break;
+                               case 'admin_acl':
+                                       $select_name = 
"account_addressmaster[]']";
+                                       break;
+                               case 'projects':
+                                       $select_name = "values[coordinator]']";
+                                       break;
+                               case 'e_projects':
+                                       $select_name = "employees[]']";
+                                       break;
+                       }
+
+                       $script = 'var userSelectBox = 
opener.document.forms["app_form"].elements[\'' . $select_name . "\n";
+                       $script .= 'function ExchangeAccountSelect(thisform)' . 
"\n";
+                       $script .= '{' . "\n";
+                       $script .= 'NewEntry = new 
Option(thisform.elements[1].value,thisform.elements[0].value,false,true);'. 
"\n";
+                       $script .= 'userSelectBox.options[userSelectBox.length] 
= NewEntry;'. "\n";
+                       $script .= '}'. "\n";
+                       $script .= '</script>'. "\n";
+                       $script .= '<script LANGUAGE="JavaScript">'. "\n";
+                       $script .= 'function ExchangeAccountText(thisform)'. 
"\n";
+                       $script .= '{'. "\n";
+                       $script .= 'opener.document.app_form.accountid.value = 
thisform.elements[0].value;'. "\n";
+                       $script .= 'opener.document.app_form.accountname.value 
= thisform.elements[1].value;'. "\n";
+                       $script .= '}'. "\n";
+                       return $script;
+               }
+
+               function accounts_popup($app)
+               {
+                       $GLOBALS['phpgw_info']['flags']['headonly'] = True;
+                       $GLOBALS['phpgw_info']['flags']['xslt_app'] = True;
+
+                       
$GLOBALS['phpgw']->xslttpl->add_file($GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default')
 . SEP . 'accounts_popup');
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('select accounts');
+
+                       $group_id = get_var('group_id',array('GET','POST'));
+
+                       /*if(isset($_GET['group_id']))
+                       {
+                               $group_id = $_GET['group_id'];
+                       }*/
+
+                       if(isset($_POST['query']))
+                       {
+                               $GLOBALS['query'] = $_POST['query'];
+                       }
+                       
+                       if(isset($_POST['start']))
+                       {
+                               $start = intval($_POST['start']);
+                       }
+                       else
+                       {
+                               $start = 0;
+                       }
+
+                       if(isset($_GET['order']))
+                       {
+                               $order = $_GET['order'];
+                       }
+                       else
+                       {
+                               $order = 'account_lid';
+                       }
+                       
+                       if(isset($_GET['sort']))
+                       {
+                               $sort = $_GET['sort'];
+                       }
+                       else
+                       {
+                               $sort = 'ASC';
+                       }
+
+                       $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
+
+                       switch($app)
+                       {
+                               case 'calendar':
+                                       $action                 = 
'calendar.uicalendar.accounts_popup';
+                                       $select_name    = "participants[]'][0]";
+                                       $js_function    = 
'ExchangeAccountSelect';
+                                       break;
+                               case 'admin':
+                                       $action                 = 
'admin.uiaccounts.accounts_popup';
+                                       $js_function    = 
'ExchangeAccountSelect';
+                                       break;
+                               case 'admin_acl':
+                                       $action                 = 
'admin.uiaclmanager.accounts_popup';
+                                       $app                    = 'addressbook';
+                                       $js_function    = 
'ExchangeAccountSelect';
+                                       break;
+                               case 'projects':
+                                       $action                 = 
'projects.uiprojects.accounts_popup';
+                                       $js_function    = 'ExchangeAccountText';
+                                       break;
+                               case 'e_projects':
+                                       $action                 = 
'projects.uiprojects.e_accounts_popup';
+                                       $app                    = 'projects';
+                                       $js_function    = 
'ExchangeAccountSelect';
+                                       break;
+                       }
+
+                       $link_data = array
+                       (
+                               'menuaction'    => $action,
+                               'group_id'              => $group_id
+                       );
+
+                       $app_groups = array();
+
+                       if ($app != 'admin')
+                       {
+                               $my_groups      = 
$this->membership($this->account);
+                               $aclusers       = 
$GLOBALS['phpgw']->acl->get_ids_for_location('run',1,$app);
+                               $acl_users      = 
$this->return_members($aclusers);
+                               $app_user       = $acl_users['users'];
+                               $app_groups     = $acl_users['groups'];
+                       }
+                       else
+                       {
+                               $all_groups     = $this->get_list('groups');
+                               $all_user       = $this->get_list('accounts');
+
+                               while(is_array($all_groups) && list(,$agroup) = 
each($all_groups))
+                               {
+                                       $user_groups[] = array
+                                       (
+                                               'account_id'    => 
$agroup['account_id'],
+                                               'account_name'  => 
$agroup['account_firstname']
+                                       );
+                               }
+
+                               for($j=0;$j<count($user_groups);$j++)
+                               {
+                                       $app_groups[$i] = 
$user_groups[$j]['account_id'];
+                                       $i++;
+                               }
+
+                               for($j=0;$j<count($all_user);$j++)
+                               {
+                                       $app_user[$i] = 
$all_user[$j]['account_id'];
+                                       $i++;
+                               }
+                       }
+
+                       while (is_array($my_groups) && list(,$group) = 
each($my_groups))
+                       {
+                               if (in_array($group['account_id'],$app_groups))
+                               {
+                                       //$link_data['group_id'] = 
$group['account_id'];
+                                       $user_groups[] = array
+                                       (
+                                               'link_user_group'       => 
$GLOBALS['phpgw']->link('/index.php','menuaction=' . $action . '&group_id=' . 
$group['account_id']),
+                                               'name_user_group'       => 
$group['account_name'],
+                                               'account_display'       => 
$GLOBALS['phpgw']->common->grab_owner_name($group['account_id']),
+                                               'accountid'                     
=> $group['account_id'],
+                                               'img'                           
=> $GLOBALS['phpgw']->common->image('phpgwapi','select'),
+                                               'js_function'           => 
$js_function,
+                                               'lang_select_group'     => 
lang('Select group')
+                                       );
+
+                                       switch($app)
+                                       {
+                                               case 'addressbook':
+                                               case 'calendar':        
$group_select = 'yes'; break;
+                                               default:                        
$group_other = 'yes'; break;
+                                       }
+                               }
+                               else
+                               {
+                                       if ($app != 'admin')
+                                       {
+                                               $all_groups[] = array
+                                               (
+                                                       'link_all_group'        
=> $GLOBALS['phpgw']->link('/index.php','menuaction=' . $action . '&group_id=' 
. $group['account_id']),
+                                                       'name_all_group'        
=> $group['account_name'],
+                                                       'accountid'             
        => $group['account_id']
+                                               );
+                                       }
+                               }
+                       }
+
+                       //_debug_array($user_groups);
+                       //exit;
+
+                       if (!$GLOBALS['query'])
+                       {
+                               if (isset($group_id) && !empty($group_id))
+                               {
+                                       //echo 'GROUP_ID: ' . $group_id;
+                                       $users = 
$GLOBALS['phpgw']->acl->get_ids_for_location($group_id,1,'phpgw_group');
+
+                                       for ($i=0;$i<count($users);$i++)
+                                       {
+                                               if 
(in_array($users[$i],$app_user))
+                                               {
+                                                       
$GLOBALS['phpgw']->accounts->account_id = $users[$i];
+                                                       
$GLOBALS['phpgw']->accounts->read_repository();
+
+                                                       switch ($order)
+                                                       {
+                                                               case 
'account_firstname':
+                                                                       $id = 
$GLOBALS['phpgw']->accounts->data['firstname'];
+                                                                       break;
+                                                               case 
'account_lastname':
+                                                                       $id = 
$GLOBALS['phpgw']->accounts->data['lastname'];
+                                                                       break;
+                                                               case 
'account_lid':
+                                                               default:
+                                                                       $id = 
$GLOBALS['phpgw']->accounts->data['account_lid'];
+                                                                       break;
+                                                       }
+                                                       $id .= 
$GLOBALS['phpgw']->accounts->data['lastname'];   // default sort-order
+                                                       $id .= 
$GLOBALS['phpgw']->accounts->data['firstname'];
+                                                       $id .= 
$GLOBALS['phpgw']->accounts->data['account_id']; // make our index unique
+
+                                                       $val_users[$id] = array
+                                                       (
+                                                               'account_id'    
        => $GLOBALS['phpgw']->accounts->data['account_id'],
+                                                               'account_lid'   
        => $GLOBALS['phpgw']->accounts->data['account_lid'],
+                                                               
'account_firstname'     => $GLOBALS['phpgw']->accounts->data['firstname'],
+                                                               
'account_lastname'      => $GLOBALS['phpgw']->accounts->data['lastname']
+                                                       );
+                                               }
+                                       }
+
+                                       if (is_array($val_users))
+                                       {
+                                               if ($sort != 'DESC')
+                                               {
+                                                       ksort($val_users);
+                                               }
+                                               else
+                                               {
+                                                       krsort($val_users);
+                                               }
+                                       }
+                                       $val_users = array_values($val_users);  
// get a numeric index
+                               }
+                               $total = count($val_users);
+                       }
+                       else
+                       {
+                               switch($app)
+                               {
+                                       case 'calendar':        $select = 
'both'; break;
+                                       default:                        $select 
= 'accounts'; break;
+                               }
+                               $entries        = 
$this->get_list($select,$start,$sort,$order,$GLOBALS['query']);
+                               $total          = $this->total;
+                               for ($i=0;$i<count($entries);$i++)
+                               {
+                                       if 
(in_array($entries[$i]['account_id'],$app_user))
+                                       {
+                                               $val_users[] = array
+                                               (
+                                                       'account_id'            
=> $entries[$i]['account_id'],
+                                                       'account_lid'           
=> $entries[$i]['account_lid'],
+                                                       'account_firstname'     
=> $entries[$i]['account_firstname'],
+                                                       'account_lastname'      
=> $entries[$i]['account_lastname']
+                                               );
+                                       }
+                               }
+                       }
+
+                       $stop = $start + $this->nextmatchs->maxmatches;
+                       for ($i=$start;$i<count($val_users)&&$i<$stop;$i++)
+                       {
+                               $content[] = array
+                               (
+                                       'lid'                           => 
$val_users[$i]['account_lid'],
+                                       'firstname'                     => 
$val_users[$i]['account_firstname'],
+                                       'lastname'                      => 
$val_users[$i]['account_lastname'],
+                                       'accountid'                     => 
$val_users[$i]['account_id'],
+                                       'account_display'       => 
$GLOBALS['phpgw']->common->grab_owner_name($val_users[$i]['account_id']),
+                                       'img'                           => 
$GLOBALS['phpgw']->common->image('phpgwapi','select'),
+                                       'lang_select_user'      => lang('Select 
user'),
+                                       'js_function'           => $js_function
+                               );
+                       }
+
+                       $table_close = array
+                       (
+                               'lang_close'    => lang('close window'),
+                               'start'                 => $start,
+                               'sort'                  => $sort,
+                               'order'                 => $order,
+                               'query'                 => $GLOBALS['query'],
+                               'group_id'              => $group_id,
+                       );
+
+                       $table_header = array
+                       (
+                               'sort_lid'                      => 
$this->nextmatchs->show_sort_order(array
+                                                                               
(
+                                                                               
        'sort'  => $this->sort,
+                                                                               
        'var'   => 'account_lid',
+                                                                               
        'order' => $this->order,
+                                                                               
        'extra' => $link_data
+                                                                               
)),
+                               'lang_lid'                      => lang('lid'),
+                               'sort_lastname'         => 
$this->nextmatchs->show_sort_order(array
+                                                                               
(
+                                                                               
        'sort'  => $this->sort,
+                                                                               
        'var'   => 'account_lastname',
+                                                                               
        'order' => $this->order,
+                                                                               
        'extra' => $link_data
+                                                                               
)),
+                               'lang_lastname'         => lang('lastname'),
+                               'sort_firstname'        => 
$this->nextmatchs->show_sort_order(array
+                                                                               
(
+                                                                               
        'sort'  => $this->sort,
+                                                                               
        'var'   => 'account_firstname',
+                                                                               
        'order' => $this->order,
+                                                                               
        'extra' => $link_data
+                                                                               
)),
+                               'lang_firstname'        => lang('firstname'),
+                               'lang_groups'           => lang('user groups'),
+                               'lang_accounts'         => lang('user 
accounts'),
+                               'lang_perm'                     => 
($app=='admin'?lang('group name'):lang('Groups with permission for 
%1',lang($app))),
+                               'withoutperm'           => 
($app=='admin'?'no':'yes'),
+                               'lang_nonperm'          => lang('Groups without 
permission for %1',lang($app)),
+                               'group_select'          => $group_select,
+                               'group_other'           => $group_other,
+                               'user_groups'           => $user_groups,
+                               'all_groups'            => $all_groups,
+                               'values'                        => $content,
+                               'table_close'           => $table_close
+                       );
+
+                       $nm = array
+                       (
+                               'start_record'  => $start,
+                               'num_records'   => count($val_users),
+                               'all_records'   => $total,
+                               'link_data'             => $link_data
+                       );
+
+                       $data = array
+                       (
+                               'nm_data'               => 
$this->nextmatchs->xslt_nm($nm),
+                               'search_data'   => 
$this->nextmatchs->xslt_search(array('query' => $GLOBALS['query'],'link_data' 
=> $link_data)),
+                               'table_header'  => $table_header
+                       );
+
+                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list' => $data));
+               }
+       }
 ?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]