require_once 'session.ppp' ;
require_once 'local.ppp' ;
require_once 'conf.ppp' ;
require_once 'baselib.ppp' ;
require_once 'wwwsec.ppp' ;
require_once 'librepo.ppp' ;
get_config () ;
$conn = db_connect_or_die () ;
assert_login () ;
if ( $ADM = GETVAR ( 'ADM' ) ) { switch_actv ( $ADM ) ; }
# $DEBUG = 2 ;
$TIT = REPO_TIT ( 'guests' ) ;
html_start ( $TIT ) ;
# echo "session_cache_expire " . session_cache_expire () ;
# echo ini_get ( "session.gc_maxlifetime" ) ;
# echo ini_get ( "session.save_path" ) ;
if ( ! $USER )
{ html_exit ( "repo guests : not authorised" ) ; }
elseif ( ! may_create_guest () )
{ echo BQ ( gen_guests_tab () ) ;
html_end () ;
exit ;
}
$ACT = GETVAR ( 'ACT' ) ;
$USER_GROUPS = user_group_ids () ;
$do_home = 0 ;
function gen_guests_tab ()
{ $users = get_repo_guests ( '', '', 'login' ) ;
$cnt = count ( $users ) ;
$cols = may_create_guest () || is_adm () ? 6 : 2 ;
$res = TR
( THA ( "COLSPAN=$cols", "$cnt guests" ) ) . repo_guests_info_head () ;
foreach ( $users as $user )
{ $res .= $user -> info_row () ; }
return TAB ( $res ) ;
}
function gen_guest_rights ( $guest )
{ $repos = $guest -> get_repos ( 'side,ownr,name' ) ;
if ( ! count ( $repos ) ) { return '' ; }
$trs = TR
( TH ( 'repo' )
. TH ( 'user' )
. TH ( 'access' )
. TH ( 'manager' )
. TH ( 'watcher' )
) ;
foreach ( $repos as $repo )
{ $name = $repo -> repo_name () ;
$rr = $repo -> root () -> rights [ $guest -> login ] ;
$trs .= TR
( TD
( ( $repo -> has_manager () or $repo -> has_reader () )
? $repo -> shw_url ( $name )
: $name
)
. TD ( $rr -> pid )
. TDc ( $rr -> repr ( 'mod' ) )
. TDc ( $rr -> repr ( 'man' ) )
. TDc ( $rr -> repr ( 'wat' ) )
) ;
}
return TAB ( $trs ) ;
}
function gen_guest_groups ( $guest )
{ $groups = $guest -> get_repo_groups ( 'name' ) ;
$list = array () ;
foreach ( $groups as $group )
{ $name = $group -> name ;
if ( $group -> is_manager () ) { $name = $group -> url ( $name ) ; }
$list [] = $name ;
}
return implode ( ",\n", $list ) ;
}
if ( $_POST [ 'CANCEL' ] )
{ $do_home = 1 ; }
elseif ( $ACT == 'NEW_USER_FORM' )
{ $repo_guest = new Repo_guest ;
$repo_guest -> set_defaults () ;
}
elseif ( $ACT == 'UPD_USER_FORM' )
{ $UID = GETVAR ( 'UID' ) ;
if ( ! $UID )
{ echo H2 ( RED ( 'error' ) ) ;
echo UL ( LI ( "no UID" ) ) ;
$do_home = 1 ;
}
else
{ $repo_guest = get_repo_guest ( $UID ) ;
$repo_guest -> assert_may_update () ;
}
}
elseif ( $ACT == 'GET_FORM' )
{ $ID = GETVAR ( 'ID' ) ;
if ( $ID )
{ $repo_guest = get_repo_guest ( $ID ) ;
$repo_guest -> assert_may_update () ;
}
else
{ $repo_guest = new Repo_guest ;
$repo_guest -> set_defaults () ;
}
if ( $err = $repo_guest -> get_form () )
{ echo H2 ( RED ( 'error' ) ) ;
echo RED ( $err ) ;
}
elseif ( $repo_guest -> id )
{ putlog ( "update guest ({$repo_guest->login})" ) ;
$res = $repo_guest -> update () ;
echo H4 ( 'updates' ) ;
echo RED ( $res ) ;
}
else
{ $res = $repo_guest -> insert () ;
putlog ( "create guest ({$repo_guest->login})" ) ;
echo H4 ( 'updates' ) ;
echo RED ( $res ) ;
$repo_guest = $repo_guest -> reget () ;
$login = $repo_guest -> login ;
echo UL
( LI ( "guest login is '$login'" )
. LI ( $repo_guest -> send_mail ( 1 ) )
) ;
}
}
elseif ( $ACT == 'DEL' )
{ $UID = GETVAR ( 'UID' ) ;
if ( ! $UID )
{ echo H2 ( RED ( 'error' ) ) ;
echo UL ( LI ( "no UID" ) ) ;
$do_home = 1 ;
}
else
{ $repo_guest = get_repo_guest ( $UID ) ;
$repo_guest -> assert_may_update () ;
putlog ( "delete guest ({$repo_guest->login})" ) ;
echo H4 ( 'updates' ) ;
echo $repo_guest -> delete () ;
$do_home = 1 ;
}
}
elseif ( $ACT == 'MAIL' )
{ $UID = GETVAR ( 'UID' ) ;
if ( ! $UID )
{ echo H2 ( RED ( 'error' ) ) ;
echo UL ( LI ( "no UID" ) ) ;
$do_home = 1 ;
}
else
{ $repo_guest = get_repo_guest ( $UID ) ;
$repo_guest -> assert_may_update () ;
echo H4 ( 'result' ) ;
echo BQ ( UL ( LI ( $repo_guest -> send_mail ( 1 ) ) ) ) ;
}
}
elseif ( $ACT )
{ echo BLD ( RED ( "unknown ACT ($ACT)" ) ) ;
$do_home = 1 ;
}
else
{ $do_home = 1 ; }
if ( $do_home )
{ echo UL ( LI ( new_repo_guest_url () ) ) ;
echo BQ ( gen_guests_tab () ) ;
}
else
{ $id = $repo_guest -> id ;
$name = $repo_guest -> name ;
echo H3 ( $id ? "update guest $name" : 'create a new guest' ) ;
if ( $repo_guest -> id )
{ echo UL
( LI ( $repo_guest -> mail_pwd_url
( "mail password to this guest" ) )
. LI ( $repo_guest -> del_url ( RED ( "delete this guest" ) ) )
) ;
}
$ms1 = ''
. 'the user_name is derived from full name, '
. 'when user_name is left as is.'
;
$ms2 = 'user_name is lowercased and white-space-stripped ;'
. '
so entering g_Frank Zappa yieds g_frankzappa.'
;
echo ULc ( ! $id, LI ( $ms1 ) . LI ( $ms2 ) ) ;
echo BQ ( $repo_guest -> gen_form_guest ( 'GET_FORM' ) ) ;
if ( $id )
{ if ( $rights = gen_guest_rights ( $repo_guest ) )
{ echo H4 ( 'user rights' ) ;
echo BQ ( $rights ) ;
}
if ( $grps = gen_guest_groups ( $repo_guest ) )
{ echo H4 ( 'group memberships' ) ;
echo BQ ( "$name is a member of : " . $grps ) ;
}
}
}
html_end () ;
# phpinfo() ;
?>