2001-01-23 14:40:42 +01:00
< ? php
/************************************************************************** \
2001-02-19 13:14:25 +01:00
* phpGroupWare - Calendar *
2001-01-23 14:40:42 +01:00
* http :// www . phpgroupware . org *
* -------------------------------------------- *
* This program is free software ; you can redistribute it and / or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation ; either version 2 of the License , or ( at your *
* option ) any later version . *
\ **************************************************************************/
/* $Id$ */
2001-02-19 13:14:25 +01:00
$phpgw_flags = Array (
'currentapp' => 'addressbook' ,
'enable_nextmatchs_class' => True ,
'noappheader' => True ,
'noappfooter' => True
);
2001-02-13 04:20:33 +01:00
2001-02-19 13:14:25 +01:00
$phpgw_info [ 'flags' ] = $phpgw_flags ;
include ( '../header.inc.php' );
2001-02-13 04:20:33 +01:00
2001-02-19 13:14:25 +01:00
$private_acl = True ;
2001-02-13 04:20:33 +01:00
2001-02-19 13:14:25 +01:00
if ( $private_acl == True )
{
define ( PHPGW_ACL_PRIVATE , 16 );
}
function check_acl ( $label , $id , $acl , $rights , $right )
{
global $phpgw_info , $p ;
$p -> set_var ( $acl , $label . $phpgw_info [ 'flags' ][ 'currentapp' ] . '[' . $id . '][' . $right . ']' );
if ( $rights & $right )
{
$p -> set_var ( $acl . '_selected' , ' checked' );
}
else
{
$p -> set_var ( $acl . '_selected' , '' );
}
}
2001-01-23 14:40:42 +01:00
2001-02-19 13:14:25 +01:00
function display_row ( $bg_color , $label , $id , $name )
{
global $phpgw_info , $acl , $private_acl , $p ;
2001-01-23 14:40:42 +01:00
2001-02-19 13:14:25 +01:00
$p -> set_var ( 'row_color' , $bg_color );
$p -> set_var ( 'user' , $name );
$rights = $acl -> get_rights ( $id , $phpgw_info [ 'flags' ][ 'currentapp' ]);
2001-02-13 04:20:33 +01:00
2001-02-19 13:14:25 +01:00
check_acl ( $label , $id , 'read' , $rights , PHPGW_ACL_READ );
2001-02-13 04:20:33 +01:00
2001-02-19 13:14:25 +01:00
check_acl ( $label , $id , 'add' , $rights , PHPGW_ACL_ADD );
2001-02-13 04:20:33 +01:00
2001-02-19 13:14:25 +01:00
check_acl ( $label , $id , 'edit' , $rights , PHPGW_ACL_EDIT );
2001-02-13 04:20:33 +01:00
2001-02-19 13:14:25 +01:00
check_acl ( $label , $id , 'delete' , $rights , PHPGW_ACL_DELETE );
2001-02-13 04:20:33 +01:00
2001-02-19 13:14:25 +01:00
if ( $private_acl == True )
{
check_acl ( $label , $id , 'private' , $rights , PHPGW_ACL_PRIVATE );
}
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
$p -> parse ( 'row' , 'acl_row' , True );
}
2001-01-23 14:40:42 +01:00
2001-02-19 13:14:25 +01:00
if ( ! isset ( $owner ) || ! $phpgw_info [ 'user' ][ 'apps' ][ 'admin' ])
{
$owner = $phpgw_info [ 'user' ][ 'account_id' ];
}
$acct = CreateObject ( 'phpgwapi.accounts' , $owner );
$groups = $acct -> memberships ( $owner );
unset ( $acct );
$acl = CreateObject ( 'phpgwapi.acl' , intval ( $owner ));
$acl -> read_repository ();
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
if ( $submit )
{
$to_remove = unserialize ( urldecode ( $processed ));
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
for ( $i = 0 ; $i < count ( $to_remove ); $i ++ )
{
$acl -> delete ( $phpgw_info [ 'flags' ][ 'currentapp' ], $to_remove [ $i ]);
}
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
// Group records
$group_variable = 'g_' . $phpgw_info [ 'flags' ][ 'currentapp' ];
2001-03-16 05:28:23 +01:00
if ( ! $$group_variable )
{
$$group_variable = array ();
}
2001-02-19 13:14:25 +01:00
@ reset ( $$group_variable );
while ( list ( $group_id , $acllist ) = each ( $$group_variable ))
{
$totalacl = 0 ;
while ( list ( $right , $permission ) = each ( $acllist ))
{
$totalacl += $right ;
}
$acl -> add ( $phpgw_info [ 'flags' ][ 'currentapp' ], $group_id , $totalacl );
}
// User records
$user_variable = 'u_' . $phpgw_info [ 'flags' ][ 'currentapp' ];
2001-01-24 04:45:00 +01:00
2001-03-16 05:28:23 +01:00
if ( ! $$user_variable )
{
$$user_variable = array ();
}
2001-02-19 13:14:25 +01:00
@ reset ( $$user_variable );
while ( list ( $user_id , $acllist ) = each ( $$user_variable ))
{
$totalacl = 0 ;
while ( list ( $right , $permission ) = each ( $acllist ))
{
$totalacl += $right ;
}
$acl -> add ( $phpgw_info [ 'flags' ][ 'currentapp' ], $user_id , $totalacl );
}
$acl -> save_repository ();
}
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
$processed = Array ();
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
$total = 0 ;
2001-02-10 14:59:13 +01:00
2001-02-19 13:14:25 +01:00
if ( ! isset ( $start ))
{
$start = 0 ;
}
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
if ( ! $start )
{
$s_groups = 0 ;
$s_users = 0 ;
}
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
if ( ! isset ( $s_groups ))
{
$s_groups = 0 ;
}
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
if ( ! isset ( $s_users ))
{
$s_users = 0 ;
}
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
if ( ! isset ( $query ))
{
$query = " " ;
}
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
if ( ! isset ( $maxm ))
{
$maxm = $phpgw_info [ 'user' ][ 'preferences' ][ 'common' ][ 'maxmatchs' ];
}
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
if ( ! isset ( $totalentries ))
{
$totalentries = count ( $groups );
$db = $phpgw -> db ;
$db -> query ( " SELECT count(*) FROM phpgw_accounts WHERE account_type='u' " );
$db -> next_record ();
$totalentries += intval ( $db -> f ( 0 ));
}
2001-01-23 14:40:42 +01:00
2001-02-19 13:14:25 +01:00
$p = CreateObject ( 'phpgwapi.Template' , $phpgw_info [ 'server' ][ 'app_tpl' ]);
if ( $private_acl == True )
{
$templates = Array (
2001-03-18 09:52:38 +01:00
'preferences' => 'preference_acl.tpl' ,
'row_colspan' => 'preference_colspan_private.tpl' ,
'acl_row' => 'preference_acl_row_private.tpl'
2001-02-19 13:14:25 +01:00
);
2001-02-13 04:20:33 +01:00
}
else
{
2001-02-19 13:14:25 +01:00
$templates = Array (
2001-03-18 09:52:38 +01:00
'preferences' => 'preference_acl.tpl' ,
'row_colspan' => 'preference_colspan.tpl' ,
'acl_row' => 'preference_acl_row.tpl'
2001-02-19 13:14:25 +01:00
);
2001-02-13 04:20:33 +01:00
}
2001-01-23 14:40:42 +01:00
2001-02-19 13:14:25 +01:00
$p -> set_file ( $templates );
// $p->set_var('errors','<p><center><b>This does nothing at this time!<br>Strictly as a template for use!</b></center>');
$common_hidden_vars = ' <input type="hidden" name="s_groups" value="' . $s_groups . '">' . " \n "
2001-03-18 09:52:38 +01:00
. ' <input type="hidden" name="s_users" value="' . $s_users . '">' . " \n "
. ' <input type="hidden" name="maxm" value="' . $maxm . '">' . " \n "
. ' <input type="hidden" name="totalentries" value="' . $totalentries . '">' . " \n "
. ' <input type="hidden" name="start" value="' . $start . '">' . " \n "
. ' <input type="hidden" name="query" value="' . $query . '">' . " \n "
. ' <input type="hidden" name="owner" value="' . $owner . '">' . " \n " ;
2001-02-19 13:14:25 +01:00
$var = Array (
2001-03-18 09:52:38 +01:00
'errors' => '' ,
'title' => '<p><b>' . lang ( $phpgw_info [ 'flags' ][ 'currentapp' ] . ' preferences' ) . ' - ' . lang ( 'acl' ) . ':</b><hr><p>' ,
'action_url' => $phpgw -> link ( '/addressbook/acl_preferences.php' ),
'bg_color' => $phpgw_info [ 'theme' ][ 'th_bg' ],
'submit_lang' => lang ( 'submit' ),
'common_hidden_vars_form' => $common_hidden_vars
2001-02-19 13:14:25 +01:00
);
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
$p -> set_var ( $var );
if ( isset ( $query_result ) && $query_result )
{
$common_hidden_vars .= '<input type="hidden" name="query_result" value="' . $query_result . '">' . " \n " ;
}
$p -> set_var ( 'common_hidden_vars' , $common_hidden_vars );
$var = Array (
2001-03-18 09:52:38 +01:00
'read_lang' => lang ( 'Read' ),
'add_lang' => lang ( 'Add' ),
'edit_lang' => lang ( 'Edit' ),
'delete_lang' => lang ( 'Delete' )
2001-02-19 13:14:25 +01:00
);
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
$p -> set_var ( $var );
2001-02-13 04:20:33 +01:00
2001-02-19 13:14:25 +01:00
if ( $private_acl == True )
{
$p -> set_var ( 'private_lang' , lang ( 'Private' ));
}
2001-01-23 14:40:42 +01:00
2001-02-19 13:14:25 +01:00
if ( intval ( $s_groups ) <> count ( $groups ))
{
$p -> set_var ( 'string' , lang ( 'Groups' ));
$p -> parse ( 'row' , 'row_colspan' , True );
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
reset ( $groups );
for ( $k = 0 ; $k < count ( $groups ); $k ++ )
{
$group = $groups [ $k ];
$go = True ;
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
if ( $query )
{
if ( ! strpos ( ' ' . $group [ 'account_id' ] . ' ' , $query ))
{
$go = False ;
}
}
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
if ( $go )
{
$tr_color = $phpgw -> nextmatchs -> alternate_row_color ( $tr_color );
display_row ( $tr_color , 'g_' , $group [ 'account_id' ], $group [ 'account_name' ]);
$s_groups ++ ;
$processed [] = $group [ 'account_id' ];
$total ++ ;
if ( $total == $maxm )
{
break ;
}
}
}
}
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
if ( $total <> $maxm )
{
if ( ! is_object ( $db ))
{
$db = $phpgw -> db ;
}
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
$db -> query ( " select account_id, account_firstname, account_lastname, account_lid FROM phpgw_accounts WHERE account_type='u' ORDER BY account_lastname, account_firstname, account_lid " . $db -> limit ( intval ( $s_users ), $maxm ), __LINE__ , __FILE__ );
$users = $db -> num_rows ();
if ( $total <> $maxm )
{
if ( $users )
{
$p -> set_var ( 'string' , ucfirst ( lang ( 'Users' )));
$p -> parse ( 'row' , 'row_colspan' , True );
$tr_color = $phpgw -> nextmatchs -> alternate_row_color ( $tr_color );
while ( $db -> next_record ())
{
$go = True ;
if ( $query )
{
$name = ' ' . $db -> f ( 'account_firstname' ) . ' ' . $db -> f ( 'account_lastname' ) . ' ' . $db -> f ( 'account_lid' ) . ' ' ;
if ( ! strpos ( $name , $query ))
{
$go = False ;
}
}
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
if ( $go )
{
$tr_color = $phpgw -> nextmatchs -> alternate_row_color ( $tr_color );
$id = $db -> f ( 'account_id' );
display_row ( $tr_color , 'u_' , $id , $phpgw -> common -> grab_owner_name ( $id ));
$s_users ++ ;
$processed [] = $id ;
$total ++ ;
if ( $total == $maxm )
{
break ;
}
}
}
}
}
}
$extra_parms = '&s_users=' . $s_users . '&s_groups=' . $s_groups . '&maxm=' . $maxm . '&totalentries=' . $totalentries . '&total=' . ( $start + $total ) . '&owner=' . $owner ;
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
$var = Array (
2001-03-18 09:52:38 +01:00
'nml' => $phpgw -> nextmatchs -> left ( '' , $start , $totalentries , $extra_parms ),
'nmr' => $phpgw -> nextmatchs -> right ( '' , $start , $totalentries , $extra_parms ),
'search_value' => ( isset ( $query ) && $query ? $query : '' ),
'search' => lang ( 'search' ),
'processed' => urlencode ( serialize ( $processed ))
2001-02-19 13:14:25 +01:00
);
2001-03-18 09:52:38 +01:00
2001-02-19 13:14:25 +01:00
$p -> set_var ( $var );
2001-02-01 05:20:27 +01:00
2001-02-19 13:14:25 +01:00
$p -> pparse ( 'out' , 'preferences' );
$phpgw -> common -> phpgw_footer ();
2001-01-23 14:40:42 +01:00
?>