$wua_str_snip_path = $modx->config['base_path'] . "assets/snippets/";
include_once $wua_str_snip_path."weblogin/weblogin.common.inc.php";
$wua_str_output = '';
// Access control
if ( !$modx->isMemberOfWebGroup( array( 'Administrator' ) ) ) {
return $wua_str_output;
}
// Do we have any probationary users?
$wua_arr_probationary_users = $modx->getIntTableRows( 'webuser', 'web_groups', 'webgroup=4' );
if ( count( $wua_arr_probationary_users ) == 0 ) {
unset( $wua_arr_probationary_users );
return $wua_str_output;
}
// Do we have entries to approve?
if ( count( $_POST ) > 1 ) {
$wua_arr_approved_users = array();
foreach( $wua_arr_probationary_users as $wua_arr_user ) {
if ( $_POST[$wua_arr_user['webuser'].'/approved'] ) {
$wua_arr_this_user = $modx->getWebUserInfo( $wua_arr_user['webuser'] );
// Update user membership
$modx->updIntTableRow( array( 'webgroup' => 1 ), 'web_groups', 'webuser='.$wua_arr_this_user['id'] );
// Generate password
$wua_str_password = webLoginGeneratePassword();
// Update user password
$wua_sql = "UPDATE ".$modx->getFullTableName( "web_users" )."
SET password=md5('".$wua_str_password."')
WHERE id=".$wua_arr_this_user['id'].";";
$wua_rs = $modx->db->query( $wua_sql );
if( !$wua_rs ) {
$wua_str_output .= webLoginAlert( "An error occured while attempting to update the password." );
unset( $wua_str_password );
unset( $wua_arr_approved_users );
unset( $wua_arr_this_user );
unset( $wua_arr_user );
return $wua_str_output;
}
// send email notification
$wua_rt = webUserApprovalSendNewPassword( $wua_arr_this_user['email'],
$wua_arr_this_user['username'],
$wua_str_password,
$wua_arr_this_user['fullname'] );
if ( $wua_rt !== true ) { // an error occured
$wua_str_output .= $wua_rt;
unset( $wua_str_password );
unset( $wua_arr_approved_users );
unset( $wua_arr_this_user );
unset( $wua_arr_user );
return $wua_str_output;
} $wua_arr_approved_users[] = $wua_arr_this_user['username'];
}
}
if ( count( $wua_arr_approved_users ) > 0 ) {
$wua_str_output .= '
<p>The following users have been approved as members: '.implode( ', ', $wua_arr_approved_users ).'</p>';
}
unset( $wua_str_password );
unset( $wua_arr_approved_users );
unset( $wua_arr_this_user );
unset( $wua_arr_user );
// Reload list
unset( $wua_arr_probationary_users );
$wua_arr_probationary_users = $modx->getIntTableRows( 'webuser', 'web_groups', 'webgroup=4' );
if ( count( $wua_arr_probationary_users ) == 0 ) {
unset( $wua_arr_probationary_users );
return $wua_str_output;
}
}
// Form with list of probationary users
$wua_str_output = '
<form id="WebRegisterForm" method="post" action="'.$modx->makeURL( $modx->documentIdentifier ).'">
<fieldset>
<legend>The following probationary users are awaiting approval:</legend>
<table>
<tr>
<th scope="col">Username</th>
<th scope="col">Real name</th>
<th scope="col">Email address</th>
</tr>';
foreach( $wua_arr_probationary_users as $wua_arr_user ) {
$wua_arr_this_user = $modx->getWebUserInfo( $wua_arr_user['webuser'] );
$wua_str_output .= '
<tr>
<th scope="row">'.$wua_arr_this_user['username'].'</th>
<td>'.$wua_arr_this_user['fullname'].'</td>
<td>'.$wua_arr_this_user['email'].'</td>
<td><input class="checkbox" type="checkbox" name="'.$wua_arr_this_user['id'].'/approved" /></td>
</tr>';
}
$wua_str_output .= '
</table>
</fieldset>
<p class="right">
<input class="button" type="submit" value="Submit" name="cmdwebapproval" />
<input class="button" type="reset" value="Reset" name="cmdreset" />
</p>
</form>';
unset( $wua_arr_this_user );
unset( $wua_arr_user );
unset( $wua_arr_probationary_users );
return $wua_str_output;