0 ) $error[$i++] = $lang['reg_err_login5']; } // given password must be the same as the confirmation if ( $password != $password_conf ) $error[$i++] = $lang['reg_err_pass']; $error_mail_address = validate_mail_address( $mail_address ); if ( $error_mail_address != '' ) $error[$i++] = $error_mail_address; // if no error until here, registration of the user if ( sizeof( $error ) == 0 ) { // 1. retrieving default values, the ones of the user "guest" $infos = array( 'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight', 'expand', 'show_nb_comments', 'recent_period', 'template', 'forbidden_categories' ); $query = 'SELECT '; for ( $i = 0; $i < sizeof( $infos ); $i++ ) { if ( $i > 0 ) $query.= ','; $query.= $infos[$i]; } $query.= ' FROM '.USERS_TABLE; $query.= " WHERE username = 'guest'"; $query.= ';'; $row = mysql_fetch_array( pwg_query( $query ) ); // 2. adding new user $query = 'INSERT INTO '.USERS_TABLE; $query.= ' ('; $query.= ' username,password,mail_address,status'; for ( $i = 0; $i < sizeof( $infos ); $i++ ) { $query.= ','.$infos[$i]; } $query.= ') values ('; $query.= " '".$login."'"; $query.= ",'".md5( $password )."'"; if ( $mail_address != '' ) $query.= ",'".$mail_address."'"; else $query.= ',NULL'; $query.= ",'".$status."'"; foreach ( $infos as $info ) { $query.= ','; if ( !isset( $row[$info] ) ) $query.= 'NULL'; else $query.= "'".$row[$info]."'"; } $query.= ');'; pwg_query( $query ); // 3. retrieving the id of the newly created user $query = 'SELECT id'; $query.= ' FROM '.USERS_TABLE; $query.= " WHERE username = '".$login."';"; $row = mysql_fetch_array( pwg_query( $query ) ); $user_id = $row['id']; // 4. adding access to the new user, the same as the user "guest" $query = 'SELECT cat_id'; $query.= ' FROM '.PREFIX_TABLE.'user_access as ua'; $query.= ','.PREFIX_TABLE.'users as u '; $query.= ' where u.id = ua.user_id'; $query.= " and u.username = 'guest';"; $result = pwg_query( $query ); while( $row = mysql_fetch_array( $result ) ) { $query = 'INSERT INTO '.PREFIX_TABLE.'user_access'; $query.= ' (user_id,cat_id) VALUES'; $query.= ' ('.$user_id.','.$row['cat_id'].');'; pwg_query ( $query ); } // 5. associate new user to the same groups that the guest $query = 'SELECT group_id'; $query.= ' FROM '.PREFIX_TABLE.'user_group AS ug'; $query.= ', '.PREFIX_TABLE.'users AS u'; $query.= " WHERE u.username = 'guest'"; $query.= ' AND ug.user_id = u.id'; $query.= ';'; $result = pwg_query( $query ); while( $row = mysql_fetch_array( $result ) ) { $query = 'INSERT INTO '.PREFIX_TABLE.'user_group'; $query.= ' (user_id,group_id) VALUES'; $query.= ' ('.$user_id.','.$row['group_id'].')'; $query.= ';'; pwg_query ( $query ); } } return $error; } function update_user( $user_id, $mail_address, $status, $use_new_password = false, $password = '' ) { $error = array(); $i = 0; $error_mail_address = validate_mail_address( $mail_address ); if ( $error_mail_address != '' ) { $error[$i++] = $error_mail_address; } if ( sizeof( $error ) == 0 ) { $query = 'UPDATE '.USERS_TABLE; $query.= " SET status = '".$status."'"; if ( $use_new_password ) { $query.= ", password = '".md5( $password )."'"; } $query.= ', mail_address = '; if ( $mail_address != '' ) { $query.= "'".$mail_address."'"; } else { $query.= 'NULL'; } $query.= ' WHERE id = '.$user_id; $query.= ';'; pwg_query( $query ); } return $error; } function check_login_authorization() { global $user,$lang,$conf,$page; if ( $user['is_the_guest']) { if ( $conf['access'] == 'restricted' || (isset($page['cat']) && $page['cat'] == 'fav' ) ) { echo '