0

Hello friends,

I am a new babie to codeigniter. I am working on a maintenace task.And I am getting the error as frontend_make_url_name this function not found.

Can anybody is there to help me?

For helping I am pasting my code below.

<?php
class User extends Controller
{
	var $forbidden_array;
	var $phone_forbidden_array;
	var $address_forbidden_array;
	var $alpha_array;

	function __construct()
	{
		parent::__construct();	
		$this->load->model('UserModel');
		$this->load->model('ProductModel');
		$this->load->model('CategoryModel');
		$this->load->library(array('feditor', 'form_validation', 'masterpage', 'messages', 'common_functions', 'image_lib', 'adminmessages'));
		$this->load->helper(array('url', 'form'));
		$this->load->plugin('captcha');
		$this->phone_forbidden_array = array("!", "'", "@", "#", "$", "%", "^", "\"", "&", "*", "(", ")", "_", "+", "=", "{", "[", "}", "]", "|", "\\", ":", ";", "<", ">", ".", "?", "/", "~", "`", "\,", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
		$this->forbidden_array = array("!", "'", "@", "#", "$", "%", "^", "\"", "&", "*", "(", ")", "_", "+", "=", "{", "[", "}", "]", "|", "\\", ":", ";", "<", ">", ".", "?", "/", "~", "`", "\,");
		$this->address_forbidden_array = array("!", "'", "@", "#", "$", "%", "^", "\"", "&", "*", "(", ")", "_", "+", "=", "{", "[", "}", "]", "|", "\\", ":", ";", "<", ">", ".", "?", "/", "~", "`", "\,");
		$this->alpha_array = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
		$this->number_array = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0');
		$this->content_forbidden_array = array("!", "@", "$", "%", "^", "*", "+", "|", "~", "`");
		$this->admin_search_content_forbidden_array = array("(", ")", "{", "}", "[", "]", "!", "@", "#", "$", "%", "^", "*", "+", "|", "~", "`", "_");
		@set_time_limit(900);
		session_start();
	}
	
	function index()
	{
		//
	}

	/**
	* Input Parameter: $redirect: redirect to here on registering.
	*/
	function register()
	{
		$this->masterpage->setMasterPage('masterpage_frontend');

		$details["meta_details"]["meta_keywords"] = "";
		$details["meta_details"]["meta_description"] = "";
		$details["meta_details"]["title"] = WEBSITE_TITLE;
		$this->masterpage->addContentPage('meta_details', 'metatags', $details);

		$details["how_did_you_hear_options"] = $this->UserModel->get_how_did_you_hear_options();

		$details["product"]["menu_details"] = $this->common_functions->menu_config("");

		$this->form_validation->set_rules('first_name', 'First Name', 'trim|required|max_length[25]|xss_clean|callback_field_value_validity_check');
		$this->form_validation->set_rules('last_name', 'Last Name', 'trim|max_length[25]|xss_clean|callback_field_value_validity_check');
		$this->form_validation->set_rules('email_id', 'Email Id', 'trim|required|max_length[150]|xss_clean|valid_email|callback_is_new_user_email_id_unique');
		$this->form_validation->set_rules('company', 'Company', 'trim|max_length[50]|xss_clean|callback_content_value_validity_check');
		$this->form_validation->set_rules('street_addr', 'Street Address', 'trim|max_length[150]|xss_clean|callback_content_value_validity_check');
		$this->form_validation->set_rules('city', 'City', 'trim|max_length[25]|xss_clean|callback_content_value_validity_check');
		$this->form_validation->set_rules('state', 'State', 'trim|max_length[25]|xss_clean|callback_content_value_validity_check');
		$this->form_validation->set_rules('country', 'Country', 'trim|max_length[25]|xss_clean|callback_content_value_validity_check');
		$this->form_validation->set_rules('zip_code', 'Zip/Post Code', 'trim|numeric');
		$this->form_validation->set_rules('passwrd', 'Password', 'trim|alpha_numeric|required|matches[passwrd_cnfrm]|max_length[10]|min_length[6]');
		$this->form_validation->set_rules('passwrd_cnfrm', 'Password Confirmation', 'alpha_numeric|max_length[10]|min_length[6]');
		$this->form_validation->set_rules('cpti', 'Captcha Verification', 'trim|numeric|required|matches[key]');
		//$this->form_validation->set_rules('cptih', 'Image', '');
		$this->form_validation->set_rules('key', 'Image', '');

		if(isset($_POST["user_register_button_x"]) && !empty($_POST["user_register_button_x"])){
			if ($this->form_validation->run() == TRUE){
				//Create Hash
				$email_hash = md5(U_REGN_HASH_KEY . $_POST["email_id"]);

				if(isset($_POST["last_name"]) && !empty($_POST["last_name"])){
					$last_name = $_POST["last_name"];
				}else{
					$last_name = "";
				}

				if(isset($_POST["email_id"]) && !empty($_POST["email_id"])){
					$email_id = $_POST["email_id"];
				}else{
					$email_id = "";
				}

				if(isset($_POST["street_addr"]) && !empty($_POST["street_addr"])){
					$street1 = $_POST["street_addr"];
				}else{
					$street1 = "";
				}

				if(isset($_POST["city"]) && !empty($_POST["city"])){
					$city = $_POST["city"];
				}else{
					$city = "";
				}

				if(isset($_POST["zip_code"]) && !empty($_POST["zip_code"])){
					$zipcode = $_POST["zip_code"];
				}else{
					$zipcode = "";
				}

				$password = md5($_POST["passwrd"]);

				if(isset($_POST["country"]) && !empty($_POST["country"])){
					$country = $_POST["country"];
				}else{
					$country = "";
				}

				if(isset($_POST["state"]) && !empty($_POST["state"])){
					$state = $_POST["state"];
				}else{
					$state = "";
				}

				if(isset($_POST["company"]) && !empty($_POST["company"])){
					$company = $_POST["company"];
				}else{
					$company = "";
				}

				if(isset($_POST["how_did_u_hear"]) && !empty($_POST["how_did_u_hear"])){
					$source = $_POST["how_did_u_hear"];
				}else{
					$source = 0;
				}

				if(isset($_POST["would_you_like"]) && !empty($_POST["would_you_like"])){
					$receive_emails = $_POST["would_you_like"];
				}else{
					$receive_emails = 0;
				}

				$admin_approved = 0;
				$ip_address = $_SERVER["REMOTE_ADDR"];

				$this->UserModel->add_user_details($_POST["first_name"], $last_name, $email_id, $street1, $city, $zipcode, 0, $password, $email_hash, $country, $state, $company, $source, $receive_emails, $admin_approved, $ip_address);
					
				/*Invitation: Send confirmation email only if Admin accepts request, 22 Sep 09 -- AP*/											
				//$this->_send_confirmation_email($_POST["email_id"], $email_hash, $state, $country);

				/*Changes for Registration by Invitation, 21 Sep 09 --AP*/
				$this->_send_admin_noti_email($_POST["first_name"], $last_name, $email_id, $state, $country, $company);

				$conf["switch_case"] = "message";
				
				$conf["message_id"] = 21;
						
				$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

				header("location: " . $red_url);

				//redirect("user/reg_success_screen/21");
			}else{
				$vals = array('img_path' => CAPTCHA_IMAGE_DIR, 'img_url' => CAPTCHA_IMAGE_PATH);
				$cap = create_captcha($vals);
				$details["cpti"] = $cap;

				$details["mode"] = "add";
				$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);
				$this->masterpage->addContentPage('register', 'content', $details);
				$this->masterpage->show();
				exit;				
			}
		}elseif(isset($_POST["user_reset_button_x"]) && !empty($_POST["user_reset_button_x"])){
			$_POST = array();

			$vals = array('img_path' => CAPTCHA_IMAGE_DIR, 'img_url' => CAPTCHA_IMAGE_PATH);
			$cap = create_captcha($vals);
			$details["cpti"] = $cap;

			$details["mode"] = "add";
			$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);
			$this->masterpage->addContentPage('register', 'content', $details);
			$this->masterpage->show();
			exit;
		}else{
			$this->common_functions->set_logged_in_tokens("", "", "", "");

			$vals = array('img_path' => CAPTCHA_IMAGE_DIR, 'img_url' => CAPTCHA_IMAGE_PATH);
			$cap = create_captcha($vals);
			$details["cpti"] = $cap;

			$details["mode"] = "add";
			$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);
			$this->masterpage->addContentPage('register', 'content', $details);
			$this->masterpage->show();
			exit;
		}
	}

	/**
	* Input Parameter: $redirect: redirect to here on registering.
	*/
	function edit_profile($id)
	{
		if($this->common_functions->is_member_logged_in()){
			if($id == $_SESSION["user_user_id"]){
				$this->masterpage->setMasterPage('masterpage_frontend');

				$details["meta_details"]["meta_keywords"] = "";
				$details["meta_details"]["meta_description"] = "";
				$details["meta_details"]["title"] = WEBSITE_TITLE;
				$this->masterpage->addContentPage('meta_details', 'metatags', $details);
				
				$details["user_details"] = $this->UserModel->get_user_details($id, "id");
				$details["product"]["menu_details"] = $this->common_functions->menu_config("");

				$this->form_validation->set_rules('first_name', 'First Name', 'trim|required|max_length[25]|xss_clean|callback_field_value_validity_check');
				$this->form_validation->set_rules('last_name', 'Last Name', 'trim|max_length[25]|xss_clean|callback_field_value_validity_check');
				$this->form_validation->set_rules('company', 'Company', 'trim|max_length[50]|xss_clean|callback_content	_value_validity_check');
				$this->form_validation->set_rules('street_addr', 'Street Address', 'trim|max_length[150]|xss_clean|callback_content_value_validity_check');
				$this->form_validation->set_rules('city', 'City', 'trim|max_length[25]|xss_clean|callback_address_value_validity_check');
				$this->form_validation->set_rules('state', 'State', 'trim|max_length[25]|xss_clean|callback_address_value_validity_check');
				$this->form_validation->set_rules('country', 'Country', 'trim|max_length[25]|xss_clean|callback_address_value_validity_check');
				$this->form_validation->set_rules('zip_code', 'Zip/Post Code', 'trim|numeric');
				
				if(isset($_POST["user_register_button_x"]) && !empty($_POST["user_register_button_x"])){
					if ($this->form_validation->run() == TRUE){
						
						if(isset($_POST["last_name"]) && !empty($_POST["last_name"])){
							$last_name = $_POST["last_name"];
						}else{
							$last_name = "";
						}

						if(isset($_POST["street_addr"]) && !empty($_POST["street_addr"])){
							$street1 = $_POST["street_addr"];
						}else{
							$street1 = "";
						}

						if(isset($_POST["city"]) && !empty($_POST["city"])){
							$city = $_POST["city"];
						}else{
							$city = "";
						}

						if(isset($_POST["zip_code"]) && !empty($_POST["zip_code"])){
							$zipcode = $_POST["zip_code"];
						}else{
							$zipcode = "";
						}

						if(isset($_POST["country"]) && !empty($_POST["country"])){
							$country = $_POST["country"];
						}else{
							$country = "";
						}

						if(isset($_POST["state"]) && !empty($_POST["state"])){
							$state = $_POST["state"];
						}else{
							$state = "";
						}

						if(isset($_POST["company"]) && !empty($_POST["company"])){
							$company = $_POST["company"];
						}else{
							$company = "";
						}

						if(isset($_POST["would_you_like"]) && !empty($_POST["would_you_like"])){
							$receive_emails = $_POST["would_you_like"];
						}else{
							$receive_emails = 0;
						}

						$this->UserModel->update_user_details($id, $_POST["first_name"], $last_name, $street1, $city, $zipcode, $country, $state, $company, $receive_emails);

						$_SESSION["user_user_name"] = $_POST["first_name"];

						$conf["switch_case"] = "message";
					
						$conf["message_id"] = 22;
								
						$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

						header("location: " . $red_url);
																	
						//redirect("user/reg_success_screen/22");
					}else{
						$details["mode"] = "edit";
						$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);
						$this->masterpage->addContentPage('register', 'content', $details);
						$this->masterpage->show();
						exit;				
					}
				}elseif(isset($_POST["user_reset_button_x"]) && !empty($_POST["user_reset_button_x"])){
					$_POST = array();
					$details["mode"] = "edit";
					$details["user_id"] = $details["user_details"][0]["user_id"];
					$details["user_details"] = array();
					$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);
					$this->masterpage->addContentPage('register', 'content', $details);
					$this->masterpage->show();
					exit;
				}else{
					$details["mode"] = "edit";
					$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);
					$this->masterpage->addContentPage('register', 'content', $details);
					$this->masterpage->show();
					exit;
				}

			}else{
				$conf["switch_case"] = "message";
					
				$conf["message_id"] = 27;
						
				$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

				header("location: " . $red_url);
			}
		}else{
			$_SESSION["login_redirect"] = $_SERVER["PHP_SELF"];

			$conf["switch_case"] = "login";
						
			$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

			header("location: " . $red_url);
		}
	}

	/**
	*Input Parameters: $redirect: redirect to this after successfully logging in.
	*/
	function login($message = 0)
	{	
		if(!$this->common_functions->is_member_logged_in()){

			//if(isset($_SERVER["HTTP_REFERER"]) && !empty($_SERVER["HTTP_REFERER"]) && empty($_SESSION["login_redirect"]) && !isset($_SESSION["login_redirect"])){
			//	$_SESSION["login_redirect"] = $_SERVER["HTTP_REFERER"];
			//}

			$this->form_validation->set_rules('email_id', 'E - Mail Address', 'trim|required|valid_email|max_length[150]|xss_clean');
			$this->form_validation->set_rules('pwd', 'Password', 'trim|alpha_numeric|required|max_length[10]|min_length[6]');

			//If form is successfully validated.
			if($this->form_validation->run() == TRUE){
				$user_exists_array = $this->UserModel->check_user_exists(trim($_POST["email_id"]), md5(trim($_POST["pwd"])));

				//Check if user with supplied email id and password combination exists.
				if(!empty($user_exists_array) && count($user_exists_array) > 0){
					/*Changes for Registraton by Invitation, 21 Sep 09 -- AP*/
					if($user_exists_array[0]["status"] == 1 && $user_exists_array[0]["admin_approved"] == 1){
						//Set the cookies on successful authentication
						//These cookies are used to check whether user is logged in or not.
						
						$this->_set_logged_in_tokens(trim($_POST["email_id"]), trim(ucwords(strtolower($user_exists_array[0]["first_name"]))), $user_exists_array[0]["user_id"]);

						if(isset($_SESSION["login_redirect"]) && !empty($_SESSION["login_redirect"])){
							//echo "hi1";exit;
							$temp_sess = $_SESSION["login_redirect"];
							unset($_SESSION["login_redirect"]);
							header("location: " . $this->common_functions->get_redirect_url_segment($temp_sess));
						}elseif(isset($_SESSION["from_product"]) && !empty($_SESSION["from_product"])){
							//echo "hi2";exit;
							$temp_sess = $_SESSION["from_product"];
							$_SESSION["from_product"] = "";
							unset($_SESSION["from_product"]);
							header("location: " . $this->common_functions->get_redirect_url_segment($temp_sess));
							//SKU and Price on Category Page Changes, 7 Nov 2009 --AP
						}elseif(isset($_SESSION["from_category_for_sku_price"]) && !empty($_SESSION["from_category_for_sku_price"])){
							//print_r($_SESSION["from_category_for_sku_price"]);
							//echo "-----";
							//echo "hi3";
							//exit;
							$temp_sess = $_SESSION["from_category_for_sku_price"];
							$_SESSION["from_category_for_sku_price"] = "";
							unset($_SESSION["from_category_for_sku_price"]);
							header("location: " . $this->common_functions->get_redirect_url_segment($temp_sess));	
						}else{
							//echo "hi4";exit;
							//$conf["switch_case"] = "message";
					
							//$conf["message_id"] = 20;
									
							//$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

							//header("location: " . $red_url);

							header("location: " . base_url());
						}
					}elseif($user_exists_array[0]["admin_approved"] != 1){
						
						$this->common_functions->set_logged_in_tokens("", "", "", "");

						$conf["switch_case"] = "message";
					
						$conf["message_id"] = 37;
								
						$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

						header("location: " . $red_url);
					
					}elseif($user_exists_array[0]["admin_approved"] == 1 && $user_exists_array[0]["status"] != 1){
						$this->common_functions->set_logged_in_tokens("", "", "", "");

						$conf["switch_case"] = "message";
					
						$conf["message_id"] = 26;
								
						$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

						header("location: " . $red_url);
					}
				}else{
					//Logout
					$this->common_functions->set_logged_in_tokens("", "", "", "");
				
					//$conf["switch_case"] = "message";
				
					//$conf["message_id"] = 10;
							
					//$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

					//header("location: " . $red_url);

					//redirect("user/reg_success_screen/10");

					$this->masterpage->setMasterPage('masterpage_frontend');
					$details["error"] = $this->messages->messages[10];
					$this->masterpage->addContentPage('error_div', 'errordiv', $details);

					$details["meta_details"]["meta_keywords"] = "";
					$details["meta_details"]["meta_description"] = "";
					$details["meta_details"]["title"] = WEBSITE_TITLE;
					$this->masterpage->addContentPage('meta_details', 'metatags', $details);

					$details = array();

					$details["product"]["menu_details"] = $this->common_functions->menu_config("");

					$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);

					$this->masterpage->addContentPage('login', 'content', $details);
					$this->masterpage->show();
				}
			}else{
				//Logout
				$this->common_functions->set_logged_in_tokens("", "", "", "");
				
				$this->masterpage->setMasterPage('masterpage_frontend');

				$details["meta_details"]["meta_keywords"] = "";
				$details["meta_details"]["meta_description"] = "";
				$details["meta_details"]["title"] = WEBSITE_TITLE;
				$this->masterpage->addContentPage('meta_details', 'metatags', $details);

				$details = array();

				$details["product"]["menu_details"] = $this->common_functions->menu_config("");

				$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);

				$this->masterpage->addContentPage('login', 'content', $details);
				$this->masterpage->show();
			}
		}else{
			$conf["switch_case"] = "message";
				
			$conf["message_id"] = 23;
					
			$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

			header("location: " . $red_url);

			//redirect("user/reg_success_screen/23");
		}
	}

	/**
	* 
	*/
	function change_password($message =  0)
	{
		$details = array();
		$details["product"]["menu_details"] = $this->common_functions->menu_config("");
		//echo "<pre>";print_r($_COOKIE);echo "</pre>";
		if($this->common_functions->is_member_logged_in()){
			$this->form_validation->set_rules('opw', 'Old Password', 'trim|alpha_numeric|required|max_length[10]|min_length[6]|callback_is_old_password_correct');
			$this->form_validation->set_rules('npw', 'New Password', 'trim|alpha_numeric|required|max_length[10]|min_length[6]|matches[npwr]');
			$this->form_validation->set_rules('npwr', 'Repeat New Password', 'trim|alpha_numeric|required');

			if($this->form_validation->run() == TRUE){
				$user_exists_array = $this->UserModel->check_user_exists(trim($_SESSION["email_id"]), md5(trim($_POST["opw"])));
				
				//Check if user for combination of email id and old password exists.
				if(!empty($user_exists_array) && count($user_exists_array) > 0){
					$this->UserModel->update_user_password($user_exists_array[0]["user_id"], $_POST["npw"], "");
					$this->common_functions->set_logged_in_tokens("", "", "", "");

					$conf["switch_case"] = "message";
				
					$conf["message_id"] = 12;
							
					$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

					$_SESSION["login_redirect"] = base_url();

					header("location: " . $red_url);
				}
			}else{
				$this->masterpage->setMasterPage('masterpage_frontend');

				$details["meta_details"]["meta_keywords"] = "";
				$details["meta_details"]["meta_description"] = "";
				$details["meta_details"]["title"] = WEBSITE_TITLE;
				$this->masterpage->addContentPage('meta_details', 'metatags', $details);

				if($message > 0){
					$details["message"] = $message;
				}

				$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);

				$this->masterpage->addContentPage('change_password', 'content', $details);
				$this->masterpage->show();
			}

		}else{
			$_SESSION["login_redirect"] = $_SERVER["PHP_SELF"];

			$conf["switch_case"] = "login";
						
			$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

			header("location: " . $red_url);
		}
	}

	/**
	* Callback Function for validation
	*/
	function field_value_validity_check($string)
	{
		$string = trim($string);
		for($i=0;$i<strlen($string);$i++){
			if(in_array($string[$i], $this->forbidden_array)){
				$this->form_validation->set_message('field_value_validity_check', 'The %s field can not contain special characters.');
				return FALSE;
			}
		}
		return TRUE;
	}

	/**
	* Callback Function for validation
	*/
	function phone_value_validity_check($string)
	{
		$string = trim($string);
		for($i=0;$i<strlen($string);$i++){
			if(in_array($string[$i], $this->phone_forbidden_array)){
				$this->form_validation->set_message('phone_value_validity_check', 'The %s field can not contain special characters.');
				return FALSE;
			}
		}
		return TRUE;
	}

	/**
	* Callback Function for validation
	*/
	function address_value_validity_check($string)
	{
		$string = trim($string);
		for($i=0;$i<strlen($string);$i++){
			if(in_array($string[$i], $this->address_forbidden_array)){
				$this->form_validation->set_message('address_value_validity_check', 'The %s field can not contain special characters.');
				return FALSE;
			}
		}
		return TRUE;
	}

	/**
	* Callback Function for validation
	*/
	function content_value_validity_check($string)
	{
		$string = trim($string);
		for($i=0;$i<strlen($string);$i++){
			if(in_array($string[$i], $this->content_forbidden_array)){
				$this->form_validation->set_message('content_value_validity_check', 'The %s field can not contain special characters.');
				return FALSE;
			}
		}
		return TRUE;
	}

	/**
	* Callback Function for validation
	*/
	function is_member_email_id_unique($string)
	{
		$email_arr = $this->UserModel->is_member_emailid_unique($string);
		$member_details = $this->UserModel->get_user_details($_SESSION["emailid"], "emailid");
		if(empty($email_arr)){
			return TRUE;
		}elseif((count($email_arr) == 1) && (trim($email_arr[0]["id"]) == trim($member_details[0]["id"]))){
				return TRUE;
		}else{
			$this->form_validation->set_message('is_member_email_id_unique', 'A User Is Already Registered With This Email.');
			return FALSE;
		}
	}

	/**
	* 
	*/
	function forgot_password($message = 0)
	{
		$this->common_functions->set_logged_in_tokens("", "", "", "");

		$this->form_validation->set_rules('email_id', 'Email Id', 'trim|required|max_length[150]|xss_clean|valid_email');

		if($this->form_validation->run() == TRUE){
			$unique_flag = $this->UserModel->is_member_emailid_unique(trim($_POST["email_id"]));

			//If unique ACTIVATED user with this email id is found.
			if(isset($unique_flag) && count($unique_flag) > 0){
				$password = $this->_generate_password();

				//Send password to user emailid.
				$this->_send_fp_email(trim($_POST["email_id"]), $password);

				//Update password for the user.
				$this->UserModel->update_user_password("", $password, trim($_POST["email_id"]));
				
				$conf["switch_case"] = "message";
				
				$conf["message_id"] = 24;
						
				$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

				header("location: " . $red_url);
				
				//redirect("user/reg_success_screen/24");
				exit;
			}else{
				$conf["switch_case"] = "message";
				
				$conf["message_id"] = 18;
						
				$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

				header("location: " . $red_url);

				//redirect("user/reg_success_screen/18");
				exit;
			}
		}else{
			$this->common_functions->set_logged_in_tokens("", "", "", "");

			$this->masterpage->setMasterPage('masterpage_frontend');

			$details["meta_details"]["meta_keywords"] = "";
			$details["meta_details"]["meta_description"] = "";
			$details["meta_details"]["title"] = WEBSITE_TITLE;
			$this->masterpage->addContentPage('meta_details', 'metatags', $details);

			if($message > 0){
				$details["message"] = $message;
			}

			$details["product"]["menu_details"] = $this->common_functions->menu_config("");

			$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);

			$this->masterpage->addContentPage('forgot_password', 'content', $details);
			$this->masterpage->show();
		}
	}

	/**
	* Return Value: System Generated Password.
	*/
	function _generate_password()
	{
		$password = "";

		//Four times, select randomly alphabet and append to $password
		for($i=0;$i<4;$i++){
			$password .= $this->alpha_array[rand(0, 51)];
		}

		//Twice, select randomly number and append to $password
		for($i=0;$i<2;$i++){
			$password .= $this->number_array[rand(0, 9)];
		}

		return $password;
	}

	/**
	* Input Parameters: $email_id: Email id of the user who forgot password.
	*                   $password: System generated password.
	*/
	function _send_fp_email($email_id, $password)
	{
		//Send Email
		$config['mailtype'] = 'html';
		$this->email->initialize($config);
		$this->email->from(CONFIRMATION_FROM_EMAIL, CONFIRMATION_FROM_EMAIL_SENDER_NAME);
		$this->email->subject("Your New Password");
		$details["password"] = $password;
		ob_start();
		$this->load->view("user_fp_email", $details);
		$message = ob_get_clean();
		$this->email->message($message);
		$this->email->to(trim($email_id)); 
		$this->email->send();
	}

	function is_old_password_correct($string)
	{
		$user_exists_array = $this->UserModel->check_user_exists(trim($_SESSION["email_id"]), md5(trim($string)));
		
		//Check if user for combination of email id and old password exists.
		if(!empty($user_exists_array) && count($user_exists_array) > 0){
			return TRUE;
		}else{
			$this->form_validation->set_message('is_old_password_correct', 'The Old Password is not correct.');
			return FALSE;
		}
	}

	/**
	* Callback Function for validation
	*/
	function is_new_user_email_id_unique($string)
	{
		$flag_arr = $this->UserModel->is_emailid_unique($string);
		if(isset($flag_arr[0]["Y"]) && ($flag_arr[0]["Y"] == 1)){
			return TRUE;
		}elseif(isset($flag_arr[0]["N"]) && ($flag_arr[0]["N"] == 0)){
			$this->form_validation->set_message('is_new_user_email_id_unique', 'A User Is Already Registered With This Email.');
			return FALSE;
		}
	}

	/**
	* Input Paremeters: $email: Email id of the user registering.
	*                   $email_hash: Hash stored in the DB of the email of the user registering.
	*/
	function confirm_email($email, $email_hash)
	{
		$email = str_replace("~", "@", $email);
		if(md5(U_REGN_HASH_KEY . $email) == $email_hash){
			$not_act_member_details = $this->UserModel->get_not_activated_user_id($email_hash);
			
			if(!empty($not_act_member_details[0]["user_id"])){
				$not_act_member_id = $not_act_member_details[0]["user_id"];
			}

			if(count($not_act_member_details) > 0 && !empty($not_act_member_id)){
				$this->UserModel->activate_user($not_act_member_id);
				
				//Login Member
				$email_id_hash = md5(U_LOGIN_HASH_KEY . $email);
				
				/*Changes for Registration by Invitation, 21 Sep 09 --AP*/
				//$this->common_functions->set_logged_in_tokens($email, $email_id_hash, $not_act_member_details[0]["first_name"], $not_act_member_details[0]["user_id"]);

				//$this->UserModel->update_last_login($not_act_member_id);

				$conf["switch_case"] = "message";
				
				$conf["message_id"] = 36;
						
				$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

				header("location: " . $red_url);

				//redirect("user/reg_success_screen/20");
			}else{
				$conf["switch_case"] = "message";
				
				$conf["message_id"] = 18;
						
				$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

				header("location: " . $red_url);
					
				//redirect("user/reg_success_screen/18");
				exit;
			}
		}else{
			$conf["switch_case"] = "message";
				
			$conf["message_id"] = 19;
					
			$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

			header("location: " . $red_url);
				
			//redirect("user/reg_success_screen/19");
			exit;
		}
	}

	/**
	* Input Paremeters: $email_id: Email id of the user registering.
	*                   $email_hash: Hash stored in the DB of the email of the user registering.
	*/
	function _send_confirmation_email($email_id, $email_hash, $first_name, $state, $country)
	{
		//Send Email
		$details["email_url"] = str_replace("@", "~", $email_id);
		$details["email_hash"] = $email_hash;
		$details["first_name"] = $first_name;
		$details["state"] = $state;
		$details["country"] = $country;
		$config['mailtype'] = 'html';
		$this->email->initialize($config);
		$this->email->from(CONFIRMATION_FROM_EMAIL, CONFIRMATION_FROM_EMAIL_SENDER_NAME);
		$this->email->subject("MD Antiques: Account Registration Confirmation");
		ob_start();
		$this->load->view("user_confirmation_email", $details);
		$message = ob_get_clean();
		$this->email->message($message);
		$this->email->to(trim($email_id)); 
		$this->email->send();
	}

	function reg_success_screen($message = "")
	{
		$this->masterpage->setMasterPage('masterpage_frontend');

		$details["meta_details"]["meta_keywords"] = "";
		$details["meta_details"]["meta_description"] = "";
		$details["meta_details"]["title"] = WEBSITE_TITLE;
		$this->masterpage->addContentPage('meta_details', 'metatags', $details);

		$details["product"]["menu_details"] = $this->common_functions->menu_config("");

		if(!empty($message)){
			$details["message"] = $message;
		}

		$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);
		$this->masterpage->addContentPage('reg_success_message', 'content', $details);
		$this->masterpage->show();
		exit;
	}

	/**
	* Input Param: $email_id: Email Id(User) for which login tokens are to be set.
	*/
	function _set_logged_in_tokens($email_id, $user_name, $user_id)
	{
		$user_name_hash = md5(U_LOGIN_HASH_KEY . $email_id);
		$time = time();
		$duration = $time + (60*60*24*30);
		$this->common_functions->set_logged_in_tokens($email_id, $user_name_hash, $user_name, $user_id);
	}

	/**
	* Input Parameter: $redirect: redirect here after logging out.
	*/
	function logout($message = 0)
	{
		$this->common_functions->set_logged_in_tokens("", "", "", "");

		unset($_SESSION["login_redirect"]);
		
		$conf["switch_case"] = "login";
					
		$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

		header("location: " . $red_url);
	}

	function portfolio($user_id, $pagination = 0)
	{
		while(($pagination % PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE) != 0){
			$pagination = $pagination + 1;
		}

		if($this->common_functions->is_member_logged_in()){
			if($user_id == $_SESSION["user_user_id"]){
				$details["user_portfolio_count"] = $this->UserModel->get_user_portfolio_count($user_id);

				if($details["user_portfolio_count"][0]["PORTCOUNT"] <= 0){
					$conf["switch_case"] = "message";
					
					$conf["message_id"] = 30;
							
					$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

					header("location: " . $red_url);
					
					exit;
				}

				$conf = array();

				$pagi_arr = $this->common_functions->pagination($pagination, $details["user_portfolio_count"][0]["PORTCOUNT"], PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE, 'user/portfolio/' . $user_id, PAGINATION_PORTFOLIO_PRODUCT_URI_SEGMENT);
				$config = $pagi_arr["config"];
				$start = $pagi_arr["start"];
				$details["total_links"] = $config["num_links"];
				$details["pagination"] = $pagi_arr["start"];
				
				$details["product"]["menu_details"] = $this->common_functions->menu_config("");

				if($start < 0){
					$start = 0;
				}

				$details["portfolio_details"] = $this->UserModel->get_user_portfolio($user_id, $start, PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE);

				if($start > 0){
					$first_conf["switch_case"] = "portfolio";
					$first_conf["user_id"] = $details["portfolio_details"][0]["USERID"];
					$first_conf["pagination"] = 0;

					$la_conf["switch_case"] = "portfolio";
					$la_conf["user_id"] = $details["portfolio_details"][0]["USERID"];
					$la_conf["pagination"] = $start - PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE;
					$details["temp_title"] = $start/PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE;
				}

				for($i = 1; $i <= $details["total_links"]; $i++){
					if($i != ($start/PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE) + 1){
						$conf[$i]["switch_case"] = "portfolio";
						$conf[$i]["user_id"] = $details["portfolio_details"][0]["USERID"];
						$conf[$i]["pagination"] = ($i - 1) * PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE;
					}
				}

				if((($details["total_links"] * PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE) - $start) > PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE){
					$ra_conf["switch_case"] = "portfolio";
					$ra_conf["user_id"] = $details["portfolio_details"][0]["USERID"];
					$ra_conf["pagination"] = $start + PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE;
					$details["temp_title"] = ($start/PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE) + 2;
					
					$last_conf["switch_case"] = "portfolio";
					$last_conf["user_id"] = $details["portfolio_details"][0]["USERID"];
					$last_conf["pagination"] = ($details["total_links"] - 1) * PAGINATION_PORTFOLIO_PRODUCT_PER_PAGE;
				}
				
				$details["conf"] = $conf;
				
				if(isset($la_conf)){
					$details["la_conf"] = $la_conf;
				}

				if(isset($ra_conf)){
					$details["ra_conf"] = $ra_conf;
				}

				if(isset($last_conf)){
					$details["last_conf"] = $last_conf;
				}

				if(isset($first_conf)){
					$details["first_conf"] = $first_conf;
				}

				$this->masterpage->setMasterPage('masterpage_frontend');

				$details["meta_details"]["meta_keywords"] = "";
				$details["meta_details"]["meta_description"] = "";
				$details["meta_details"]["title"] = WEBSITE_TITLE;
				$this->masterpage->addContentPage('meta_details', 'metatags', $details);

				$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);
				$this->masterpage->addContentPage('portfolio', 'content', $details);
				$this->masterpage->show();
			}else{
				$conf["switch_case"] = "message";
					
				$conf["message_id"] = 33;
						
				$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

				header("location: " . $red_url);

				exit;
			}
		}else{
			$_SESSION["login_redirect"] = $_SERVER["PHP_SELF"];

			$conf["switch_case"] = "login";
						
			$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

			header("location: " . $red_url);

			exit;
		}
	}

	function my_account($user_id)
	{
		$details = array();
		$details["product"]["menu_details"] = $this->common_functions->menu_config("");
		$details["user_id"] = $user_id;
		
		if($this->common_functions->is_member_logged_in()){
			if($user_id == $_SESSION["user_user_id"]){
				$this->masterpage->setMasterPage('masterpage_frontend');

				$details["meta_details"]["meta_keywords"] = "";
				$details["meta_details"]["meta_description"] = "";
				$details["meta_details"]["title"] = WEBSITE_TITLE;
				$this->masterpage->addContentPage('meta_details', 'metatags', $details);

				$this->masterpage->addContentPage('left_menu', 'leftmenu', $details);

				$this->masterpage->addContentPage('my_account', 'content', $details);
				$this->masterpage->show();
			}else{
				$conf["switch_case"] = "message";
					
				$conf["message_id"] = 32;
						
				$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

				header("location: " . $red_url);
			}
		}else{
			$_SESSION["login_redirect"] = $_SERVER["PHP_SELF"];

			$conf["switch_case"] = "login";
						
			$red_url = base_url(). $this->common_functions->frontend_make_url_name($conf);

			header("location: " . $red_url);
		}
	}

	function user_admin_list($admin_user_search_field = 1, $admin_user_search_flag = 1, $admin_user_search_phrase = "no-search", $pagination = 0, $message = 0)
	{
		$this->form_validation->set_rules('admin_user_search_phrase', 'Search', 'trim|required|max_length[100]|xss_clean|callback_is_user_name_valid');

		$details["how_did_you_hear_options"] = $this->UserModel->get_how_did_you_hear_options();

		foreach($details["how_did_you_hear_options"] as $opt_key => $opt_val){
			$hdyho[$opt_val["id"]] = $opt_val["option"];
		}

		//if(!empty($_POST)){echo "<pre>";print_r($_POST);echo "</pre>";exit;}
		if($this->common_functions->is_admin_member_logged_in()){
			if(isset($_POST["admin_user_search_phrase"]) && !empty($_POST["admin_user_search_phrase"])){
				if ($this->form_validation->run() == TRUE){
					$admin_user_search_field = $_POST["admin_user_search_field"];
					$admin_user_search_flag = $_POST["admin_user_search_flag"];
					$admin_user_search_phrase = $_POST["admin_user_search_phrase"];

					/*Admin Search, 30 Sep 2009 --AP*/
					$listDetails["user_cnt"] = $this->UserModel->get_admin_user_search_count($admin_user_search_field, $admin_user_search_flag, $admin_user_search_phrase);

					if($listDetails["user_cnt"][0]["USER_COUNT"] == 0){
						redirect("user/user_admin_list/1/1/no-search/0/25");
						exit;
					}
				}else{
					$listDetails["user_cnt"] = $this->UserModel->get_user_count("all");
				}

			}elseif(isset($admin_user_search_phrase) && !empty($admin_user_search_phrase) && ($admin_user_search_phrase != "no-search")){
				$admin_user_search_field = $admin_user_search_field;
				$admin_user_search_flag = $admin_user_search_flag;
				$admin_user_search_phrase = $admin_user_search_phrase;

				/*Admin Search, 30 Sep 2009 --AP*/
				$listDetails["user_cnt"] = $this->UserModel->get_admin_user_search_count($admin_user_search_field, $admin_user_search_flag, $admin_user_search_phrase);
			}else{
				$listDetails["user_cnt"] = $this->UserModel->get_user_count("all");
			}
	
			if($admin_user_search_phrase != "no-search"){
				if($admin_user_search_flag == 1){
					$flag_text_val = "containing";
				}elseif($admin_user_search_flag == 2){
					$flag_text_val = "beginning with";
				}elseif($admin_user_search_flag == 3){
					$flag_text_val = "ending with";
				}

				if($admin_user_search_field == 1){
					$field_text_val = "First name";
				}elseif($admin_user_search_field == 2){
					$field_text_val = "Last name";
				}elseif($admin_user_search_field == 3){
					$field_text_val = "Email id";
				}

				$listDetails["count_message"] = "Your search for \"" . $field_text_val . " " . $flag_text_val . " '" . $admin_user_search_phrase . "' \" returned " . $listDetails["user_cnt"][0]["USER_COUNT"] . " results.";		
			}
			
			$pagi_arr = $this->common_functions->pagination_admin($pagination, $listDetails["user_cnt"][0]["USER_COUNT"], ADMIN_PAGINATION_USER_PER_PAGE, 'user/user_admin_list/' . $admin_user_search_field . "/" . $admin_user_search_flag . "/" . $admin_user_search_phrase . '/', ADMIN_PAGINATION_USER_URI_SEGMENT);
			$config = $pagi_arr["config"];
			$start = $pagi_arr["start"];

			$this->pagination->initialize($config);


			/*Admin Search, 30 Sep 2009 --AP*/
			if(isset($admin_user_search_phrase) && !empty($admin_user_search_phrase) && ($admin_user_search_phrase != "no-search")){
				$listDetails["details"] = $this->UserModel->get_admin_user_search($admin_user_search_field, $admin_user_search_flag, $admin_user_search_phrase, $start, ADMIN_PAGINATION_USER_PER_PAGE);

				/*After deleting all records on a page do not come back to that same page, 1 Oct 2009 --AP*/
				if(count($listDetails["details"]) == 0){
					redirect("user/user_admin_list/" . $admin_user_search_field . "/" . $admin_user_search_flag . "/" . $admin_user_search_phrase . "/0/");
					exit;
				}
			}else{
				$listDetails["details"] = $this->UserModel->get_user("all", $start, ADMIN_PAGINATION_USER_PER_PAGE);

				if(count($listDetails["details"]) == 0){
					redirect("user/user_admin_list/1/1/no-search/0");
					exit;
				}
			}

			$this->masterpage->setMasterPage('masterpage_admin');
			
			if($message > 0){
				$listDetails["message"] = $message;
			}

			$listDetails["pagination"] = $pagination;
			
			/*Registration by Invitation only Changes, 21 Sep 09 -- AP*/
			if(isset($_POST["edit_multiple_user"]) && !empty($_POST["edit_multiple_user"])){
				if(isset($_POST["user_row"]) && !empty($_POST["user_row"])){
					foreach($_POST["user_row"] as $multi_post_key => $multi_post_val){
						$app_user_details = $this->UserModel->get_user_details($multi_post_key, "id");

						if($_POST["status_row_" . $multi_post_key] == 1){
							if($app_user_details[0]["admin_approved"] == 0){
								$this->UserModel->approve_user($multi_post_key, 1);

								/*Invitation: Send confirmation email only if Admin accepts request, 22 Sep 09 -- AP*/
								//$this->_send_user_invited_email($app_user_details);
								$email_hash = md5(U_REGN_HASH_KEY . $app_user_details[0]["email_id"]);
								$this->_send_confirmation_email($app_user_details[0]["email_id"], $email_hash, $app_user_details[0]["first_name"], $app_user_details[0]["state"], $app_user_details[0]["country"]);
							}
						}else{
							$this->UserModel->approve_user($multi_post_key, 0);
						}
					}

					/*Admin Search, 30 Sep 2009 --AP*/
					redirect("user/user_admin_list/" . $admin_user_search_field . "/" . $admin_user_search_flag . "/" . $admin_user_search_phrase . "/" . $pagination . "/24");
					exit;
				}	
			}
			
			/*Admin Search, 30 Sep 2009 --AP*/

			/*On Searching should go to first page, no matter where it was initially, 1 Oct 09 --AP*/
			if((isset($_POST["admin_user_search_but"]) && !empty($_POST["admin_user_search_but"])) || (isset($_POST["admin_user_search_phrase"]) && !empty($_POST["admin_user_search_phrase"]))){
				redirect("user/user_admin_list/" . $admin_user_search_field . "/" . $admin_user_search_flag . "/" . $admin_user_search_phrase . "/0");
				exit;
			}

			$listDetails["admin_user_search_field"] = $admin_user_search_field;
			$listDetails["admin_user_search_flag"] = $admin_user_search_flag;
			$listDetails["admin_user_search_phrase"] = $admin_user_search_phrase;
			$listDetails["pagination"] = $pagination;
			$listDetails["hdyho"] = $hdyho;

			$this->masterpage->addContentPage('user_admin_list', 'content', $listDetails);
			$this->masterpage->show();
		}else{
			$_SESSION["admin_login_redirect"] = $_SERVER["PHP_SELF"];
			redirect("admin/login");
		}
	}

	function _send_admin_noti_email($first_name, $last_name, $email_id, $state, $country, $company)
	{
		//Send Email
		$details["first_name"] = $first_name;
		$details["last_name"] = $last_name;
		$details["email_id"] = $email_id;
		$details["state"] = $state; 
		$details["country"] = $country;  
		$details["company"] = $company;

		$config['mailtype'] = 'html';
		$this->email->initialize($config);
		$this->email->from(CONFIRMATION_FROM_EMAIL, CONFIRMATION_FROM_EMAIL_SENDER_NAME);
		$this->email->subject("New User: " . $first_name . " " . $last_name . " (" . $email_id . ")");
		ob_start();
		$this->load->view("user_admin_noti_email", $details);
		$message = ob_get_clean();
		$this->email->message($message);
		$this->email->to(trim(CONFIRMATION_FROM_EMAIL)); 
		$this->email->send();
	}

	function _send_user_invited_email($user_details)
	{
		//Send Email
		$config['mailtype'] = 'html';
		$user_details["user_details"] = $user_details;
		$this->email->initialize($config);
		$this->email->from(CONFIRMATION_FROM_EMAIL, CONFIRMATION_FROM_EMAIL_SENDER_NAME);
		$this->email->subject("MD Antiques: Registration Request Approval");
		ob_start();
		$this->load->view("user_invited_email", $user_details["user_details"]);
		$message = ob_get_clean();
		$this->email->message($message);
		$this->email->to(trim($user_details[0]["email_id"])); 
		$this->email->send();
	}

	function is_user_name_valid($string)
	{
		$string = trim($string);
		for($i=0;$i<strlen($string);$i++){
			if(in_array($string[$i], $this->admin_search_content_forbidden_array)){
				$this->form_validation->set_message('is_user_name_valid', 'The %s field can not contain special characters.');
				return FALSE;
			}
		}

		return TRUE;
	}
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by vaultdweller123
0

hehe nice one... you want us to debug every single line of your code then get the answer with no sweat. I think there's no one here that would eagerly read every line of code you got there... take note your code is so long... gives me headache... the only thing i can help you is go to codeignigter site and go to support or help page.... there you can find your answers there.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.