|
From: Jon O. <jon...@us...> - 2005-09-22 10:26:38
|
Update of /cvsroot/mxbb/mx_import_tools/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11758/modules/mx_import_tools/includes Modified Files: functions_mod_user.php Log Message: updates Index: functions_mod_user.php =================================================================== RCS file: /cvsroot/mxbb/mx_import_tools/includes/functions_mod_user.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** functions_mod_user.php 9 Jan 2005 21:39:39 -0000 1.1 --- functions_mod_user.php 22 Sep 2005 10:26:27 -0000 1.2 *************** *** 130,137 **** function validate_user() { $name_check = validate_username( stripslashes( str_replace( "''", "\'", $this->username ) ) ); if ( $name_check['error'] ) { ! return false; } --- 130,144 ---- function validate_user() { + $return_msg = array(); + $return_msg['is_ok'] = true; + $return_msg['username_ok'] = true; + $return_msg['mail_ok'] = true; + $name_check = validate_username( stripslashes( str_replace( "''", "\'", $this->username ) ) ); if ( $name_check['error'] ) { ! echo('<br><b>username validation failed</b>: ' . $this->username ); ! $return_msg['username_ok'] = false; ! $return_msg['is_ok'] = false; } *************** *** 139,145 **** if ( $email_check['error'] ) { ! return false; } ! return true; } // This is the function which actually inserts the user into the database --- 146,154 ---- if ( $email_check['error'] ) { ! echo('<br><b>mail validation failed</b>: ' . $this->username ); ! $return_msg['mail_ok'] = false; ! $return_msg['is_ok'] = false; } ! return $return_msg; } // This is the function which actually inserts the user into the database *************** *** 172,189 **** --- 181,205 ---- $sql = "INSERT INTO " . USERS_TABLE . " (user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_avatar_type, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey, user_posts, user_realname) "; $sql .= "VALUES (" . $this->user_id . ", '" . $this->username . "', '" . $this->user_fields['user_regdate'] . "', '" . $this->user_password . "', '" . $this->user_email . "', '" . $this->user_fields['user_icq'] . "', '" . $this->user_fields['user_website'] . "', '" . $this->user_fields['user_occ'] . "', '" . $this->user_fields['user_from'] . "', '" . $this->user_fields['user_interests'] . "', '" . $this->user_fields['user_sig'] . "', '" . $this->user_fields['user_sig_bbcode_uid'] . "', '" . $this->user_fields['user_avatar'] . "', '" . $this->user_fields['user_avatar_type'] . "', " . $this->user_fields['user_viewemail'] . ", '" . str_replace( ' ', '+', $this->user_fields['user_aim'] ) . "', '" . $this->user_fields['user_yim'] . "', '" . $this->user_fields['user_msnm'] . "', " . $this->user_fields['user_attachsig'] . ", " . $this->user_fields['user_allowsmile'] . ", " . $this->user_fields['user_allowhtml'] . ", " . $this->user_fields['user_allowbbcode'] . ", " . $this->user_fields['user_allow_viewonline'] . ", " . $this->user_fields['user_notify'] . ", " . $this->user_fields['user_notify_pm'] . ", " . $this->user_fields['user_popup_pm'] . ", " . $this->user_fields['user_timezone'] . ", '" . $this->user_fields['user_dateformat'] . "', '" . $this->user_fields['user_lang'] . "', " . $this->user_fields['user_style'] . ", " . $this->user_fields['user_level'] . ", 1, 1, '', '" . $this->user_fields['user_posts'] . "', '" . $this->user_fields['user_realname'] . "')"; + // Insert the user + if ( !( $result = $db->sql_query( $sql, BEGIN_TRANSACTION ) ) ) { $error = true; } + // Insert the personal group $sql = "INSERT INTO " . GROUPS_TABLE . " (group_name, group_description, group_single_user, group_moderator) VALUES ('', 'Personal User', 1, 0)"; + if ( !( $result = $db->sql_query( $sql ) ) ) { + echo('error - couldn\'t insert user: ' . $this->username ); $error = true; } + $group_id = $db->sql_nextid(); + // Insert the user_group entry $sql = "INSERT INTO " . USER_GROUP_TABLE . " (user_id, group_id, user_pending) *************** *** 191,196 **** --- 207,214 ---- if ( !( $result = $db->sql_query( $sql, END_TRANSACTION ) ) ) { + echo('error - couldn\'t insert user group: ' . $this->username ); $error = true; } + // Add the user to any applicable groups for ( $i = 0; $i < count( $this->groups ); $i++ ) *************** *** 200,208 **** --- 218,332 ---- if ( !( $result = $db->sql_query( $sql ) ) ) { + echo('error - couldn\'t insert user speciell group: ' . $this->username ); + $error = true; + } + } + + return ( $error == true ) ? false : true; + } + + // Returns true on success, false otherwise + function move_user() + { + global $db; + // Get the user_id if one has not already been set + if ( $this->user_id == '' ) + { + $sql = "SELECT user_id + FROM " . USERS_TABLE . " + WHERE username = '" . $this->username . "'" ; + + if ( !( $result = $db->sql_query( $sql ) ) ) + { + message_die( GENERAL_ERROR, 'Could not obtain user_id information', '', __LINE__, __FILE__, $sql ); + } + + if ( !( $row = $db->sql_fetchrow( $result ) ) ) + { + message_die( GENERAL_ERROR, 'Could not obtain user_id information', '', __LINE__, __FILE__, $sql ); + } + $this->user_id = $row['user_id']; + } + + // Add the user to any applicable groups + for ( $i = 0; $i < count( $this->groups ); $i++ ) + { + + // + // First check if user is already in group + // + $sql = "SELECT * + FROM " . USER_GROUP_TABLE . " + WHERE user_id = '" . $this->user_id . "' + AND group_id = '" . $this->groups[$i] . "'" ; + + if ( !( $result = $db->sql_query( $sql ) ) ) + { + message_die( GENERAL_ERROR, 'Could not obtain user_id information', '', __LINE__, __FILE__, $sql ); + } + + if ( ( $row = $db->sql_fetchrow( $result ) ) ) + { + echo('warning: user is already in this group'); + continue; + } + + // + // Move user to new group + // + $sql = "INSERT INTO " . USER_GROUP_TABLE . " (user_id, group_id, user_pending) + VALUES (" . $this->user_id . ", " . $this->groups[$i] . ", 0)"; + + if ( !( $result = $db->sql_query( $sql ) ) ) + { + echo('error - couldn\'t insert user speciell group: ' . $this->username ); $error = true; } } + return ( $error == true ) ? false : true; } + + // Returns true on success, false otherwise + function update_user() + { + global $db; + // Get the user_id if one has not already been set + if ( $this->user_id == '' ) + { + $sql = "SELECT user_id + FROM " . USERS_TABLE . " + WHERE username = '" . $this->username . "'" ; + + if ( !( $result = $db->sql_query( $sql ) ) ) + { + message_die( GENERAL_ERROR, 'Could not obtain user_id information', '', __LINE__, __FILE__, $sql ); + } + + if ( !( $row = $db->sql_fetchrow( $result ) ) ) + { + message_die( GENERAL_ERROR, 'Could not obtain user_id information', '', __LINE__, __FILE__, $sql ); + } + $this->user_id = $row['user_id']; + } + + $sql = "UPDATE " . USERS_TABLE . " + SET user_password = '" . $this->user_password . "' + WHERE user_id = '" . $this->user_id . "'"; + + $error = false; + + // + // Update the user + // + if ( !( $result = $db->sql_query( $sql, BEGIN_TRANSACTION ) ) ) + { + $error = true; + } + + return ( $error == true ) ? false : true; + } + + } // Now we have a few wrapper functions for those who don't need the full power *************** *** 254,258 **** global $db; ! $sql = "SELECT group_id, group_name FROM " . GROUPS_TABLE; --- 378,382 ---- global $db; ! $sql = "SELECT group_id, group_name, group_description FROM " . GROUPS_TABLE; *************** *** 276,280 **** $status = ''; } ! $grouplist .= '<option value="' . $row['group_id'] . '" ' . $status . '>' . $row['group_name'] . '</option>'; } } --- 400,404 ---- $status = ''; } ! $grouplist .= '<option value="' . $row['group_id'] . '" ' . $status . '>' . $row['group_name'] . ' (' . $row['group_description'] . ')' . '</option>'; } } |