Location: PHPKode > scripts > Facebook 2011 For PhpBB > Facebook_2011/root/includes/ucp/ucp_fb2011.php
<?php
/**
 * @package		Facebook 2011
 * @author      Damien Keitel <hide@address.com>
 * @license 	http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link        http://forums.damienkeitel.com
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
 * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 */

if (!defined('IN_PHPBB'))
{
	exit;
}

class ucp_fb2011
{
	var $p_master;
	var $u_action;

	function ucp_fb2011(&$p_master)
	{
		$this->p_master = &$p_master;
	}

	function main($id, $mode)
	{
		global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
		
		// Include the fb2011 functions.
		include_once($phpbb_root_path . 'includes/functions_fb2011.' . $phpEx);
		
		// Include the AL language files.
		$user->add_lang('mods/info_ucp_fb2011');
		$user->add_lang('mods/fb2011');
		$user->add_lang('ucp');

		$submit = isset($_POST['submit']) ? true : false;

		// Get the users current AL settings.
		$fb2011_get_user_settings		= get_fb2011_user_settings($user->data['user_id']);
		
		$fb2011_user_settings 		= get_fb2011_settings($fb2011_get_user_settings);
		
		if($submit)
		{
			switch ($mode)
			{				
				case 'facebook':
				
					if(confirm_box(true))
					{
						$sql = 'DELETE FROM ' . FB2011_USER_DATA
								. " WHERE user_id = '{$user->data['user_id']}'";
									
						$result = $db->sql_query($sql);
							
						if(!$result)
						{
							trigger_error($user->lang['FB2011_PHPBB_DB_FAILURE']);
						}
							
						$sql = 'SELECT user_id, username, user_permissions, user_email, user_jabber, user_notify_type, user_type, user_lang, user_inactive_reason
							FROM ' . USERS_TABLE . "
							WHERE user_email = '" . $db->sql_escape($user->data['user_email']) . "'
							AND username_clean = '" . $db->sql_escape(utf8_clean_string($user->data['username'])) . "'";
						$result = $db->sql_query($sql);
						$user_row = $db->sql_fetchrow($result);
						$db->sql_freeresult($result);
					
						if (!$user_row)
						{
							trigger_error('NO_EMAIL_USER');
						}
					
						if ($user_row['user_type'] == USER_IGNORE)
						{
							trigger_error('NO_USER');
						}
					
						if ($user_row['user_type'] == USER_INACTIVE)
						{
							if ($user_row['user_inactive_reason'] == INACTIVE_MANUAL)
							{
								trigger_error('ACCOUNT_DEACTIVATED');
							}
							else
							{
								trigger_error('ACCOUNT_NOT_ACTIVATED');
							}
						}
						$auth2 = new auth();
						$auth2->acl($user_row);
							
						if (!$auth2->acl_get('u_chgpasswd'))
						{
							trigger_error('NO_AUTH_PASSWORD_REMINDER');
						}
							
						$server_url = generate_board_url();
							
						$key_len = 54 - strlen($server_url);
						$key_len = max(6, $key_len); // we want at least 6
						$key_len = ($config['max_pass_chars']) ? min($key_len, $config['max_pass_chars']) : $key_len; // we want at most $config['max_pass_chars']
						$user_actkey = substr(gen_rand_string(10), 0, $key_len);
						$user_password = gen_rand_string(8);
						
						$sql = 'UPDATE ' . USERS_TABLE . "
							SET user_newpasswd = '" . $db->sql_escape(phpbb_hash($user_password)) . "', user_actkey = '" . $db->sql_escape($user_actkey) . "'
							WHERE user_id = " . $user_row['user_id'];
						$db->sql_query($sql);
							
						include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
								
						$messenger = new messenger(false);
								
						$messenger->template('user_activate_passwd', $user_row['user_lang']);
							
						$messenger->to($user_row['user_email'], $user_row['username']);
						$messenger->im($user_row['user_jabber'], $user_row['username']);
								
						$messenger->assign_vars(array(
							'USERNAME'		=> htmlspecialchars_decode($user_row['username']),
							'PASSWORD'		=> htmlspecialchars_decode($user_password),
							'U_ACTIVATE'	=> "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
						);
								
						$messenger->send($user_row['user_notify_type']);
						
						meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
								
						$message = $user->lang['PASSWORD_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
										
						trigger_error($message);

					}
					else
					{
						confirm_box(false, sprintf($user->lang['UCP_FB2011_UNLINK'], $user->lang['FACEBOOK']), build_hidden_fields(array(
										'i'						=> $id,
										'mode'					=> $mode,
										'submit'				=> true)));
					}
				
				break;
								
			}
		}
		
		$template->assign_vars(array(		
			'S_MODE_FACEBOOK'				=> ($mode == 'facebook') ? true : false,
			'S_FACEBOOK_LOGIN_ENABLED' 		=> $fb2011_user_settings[FB2011_FACEBOOK_LOGIN],
			'S_UCP_FACEBOOK_DESCRIPTION'	=> $fb2011_user_settings[FB2011_FACEBOOK_LOGIN] ? sprintf($user->lang['UCP_DISABLE_FB2011_DESCRIPTION'], $user->lang['FACEBOOK']) : sprintf($user->lang['UCP_ENABLE_FB2011_DESCRIPTION'], $user->lang['FACEBOOK']),
			'FB2011_PATH'						=> $phpbb_root_path . $config['fb2011_path'],		
			'S_HIDDEN_FIELDS'				=> (isset($s_hidden_fields)) ? $s_hidden_fields : '',
			'S_UCP_ACTION'					=> $this->u_action,
		));

		// Set desired template
		$this->tpl_name = 'ucp_fb2011';
		$this->page_title = 'UCP_FB2011';
	}
}

?>
Return current item: Facebook 2011 For PhpBB