<?php namespace App\Models\Admin;

class CommonModel{
	protected $db;
	protected $session;
	protected $project;
	
    public function __construct(){
        $this->db = \Config\Database::connect();
		$this->session = session();
		$this->project = config('Config\\Project');
    }
	
	public function get_user_type_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$opt_arr = ['Admin', 'User'];
		foreach($opt_arr as $opt_val){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_val.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_val.'</option>';
			}
		}
		return $opt_str;
	}
	
	public function get_blog_type_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$opt_arr = ['Blog', 'Media'];
		foreach($opt_arr as $opt_val){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_val.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_val.'</option>';
			}
		}
		return $opt_str;
	}
	
	public function get_banner_type_options($default="",$only_default=false){
		$opt_str = '';
		$opt_arr = ['Image', 'Video'];
		foreach($opt_arr as $opt_val){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_val.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_val.'</option>';
			}
		}
		return $opt_str;
	}
	
	public function get_district_taluka_options($district_id,$default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$opt_arr = $this->get_district_taluka_list($district_id,$default,$only_default);
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['taluka_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['taluka_id'].'" selected>'.$opt_dtl['name'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['taluka_id'].'">'.$opt_dtl['name'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_state_district_options($state_id, $default="", $only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get district list
		$opt_arr = $this->get_state_district_list($state_id,$default,$only_default);
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['district_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['district_id'].'" selected>'.$opt_dtl['name'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['district_id'].'">'.$opt_dtl['name'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_id_proof_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$builder = $this->db->table('id_proof AS ip');
		$builder->select('ipl.id_proof_id, ipl.name')
			->join('id_proof_ln AS ipl',"ipl.id_proof_id=ip.id_proof_id AND ipl.language_code='".$this->session->get('language_code')."'",'inner')
			->where('ip.status','Active')
			->where('ip.is_deleted','No')
			->orderBy('ipl.name');
		if($only_default && $default!=""){
			$builder->where('ipl.id_proof_id',$default);
		}
		$query = $builder->get();
		$opt_arr = $query->getResultArray();
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['id_proof_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['id_proof_id'].'" selected>'.$opt_dtl['name'].'</option>';
				}else{
					$opt_str .= '<option value="'.$opt_dtl['id_proof_id'].'">'.$opt_dtl['name'].'</option>';
				}				
			}
		}
		return $opt_str;
	}
	
	public function get_state_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get state list
		$opt_arr = $this->get_state_list($default, $only_default);
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['state_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['state_id'].'" selected>'.$opt_dtl['name'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['state_id'].'">'.$opt_dtl['name'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_state_list($default="",$only_default=false){
		$builder = $this->db->table('state_district_taluka');
		$builder->select('id AS state_id, state_district_taluka_name AS name')
			->where('district_code','00')
			->where('taluka_code','0000')
			->where('status','Active')
			->where('is_deleted','No')				
			->orderBy('state_district_taluka_name','ASC');
		if($only_default && $default!=""){
			$builder->where('id',$default);
		}
		$query = $builder->get();
		return $query->getResultArray();
	}
	
	public function get_state_district_list($state_id,$default="",$only_default=false){
		$rec_list = [];
		// Get State Detail
		$state_dtl = $this->get_row('state_district_taluka','id',$state_id);
		// get state district list
		if($state_dtl){
			$builder = $this->db->table('state_district_taluka');
			$builder->select('id AS district_id, state_district_taluka_name AS name')
				->where('state_code',$state_dtl['state_code'])
				->where('district_code!=','00')
				->where('taluka_code','0000')
				->where('status','Active')
				->where('is_deleted','No')
				->groupBy('district_code')
				->orderBy('state_district_taluka_name','ASC');
			if($only_default && $default!=""){
				$builder->where('id',$default);
			}
			$query = $builder->get();
			$rec_list = $query->getResultArray();
		}
		return $rec_list;
	}
	
	public function get_district_taluka_list($district_id,$default="",$only_default=false){
		$rec_list = [];
		// Get District Detail
		$district_dtl = $this->get_row('state_district_taluka','id',$district_id);
		if($district_dtl){
			// get district taluka list
			$builder = $this->db->table('state_district_taluka');
			$builder->select('id AS taluka_id, state_district_taluka_name AS name')
				->where('state_code',$district_dtl['state_code'])
				->where('district_code',$district_dtl['district_code'])
				->where('taluka_code!=','0000')
				->where('status','Active')
				->where('is_deleted','No')
				->orderBy('state_district_taluka_name','ASC');
			if($only_default && $default!=""){
				$builder->where('id',$default);
			}
			$query = $builder->get();
			$rec_list = $query->getResultArray();
		}
		return $rec_list;
	}
	
	public function get_country_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get country list
		$builder = $this->db->table('country');
		$query = $builder->orderBy('name','ASC')->get();
		$opt_arr = $query->getResultArray();
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['country_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['country_id'].'" selected>'.$opt_dtl['name'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['country_id'].'">'.$opt_dtl['name'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_user_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get user list
		$builder = $this->db->table('user');
		$query = $builder->orderBy('name','ASC')
						 ->where('is_deleted','No')
						 ->where('status','Active')
						 ->where('user_type','User')
						 ->get();
		$opt_arr = $query->getResultArray();
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['user_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['user_id'].'" selected>'.$opt_dtl['name'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['user_id'].'">'.$opt_dtl['name'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	public function get_album_title_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get photo_album list
		$builder = $this->db->table('photo_album');
		$query = $builder->orderBy('title','ASC')
						 ->where('is_deleted','No')
						 ->where('status','Active')
						 ->get();
		$opt_arr = $query->getResultArray();
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['photo_album_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['photo_album_id'].'" selected>'.$opt_dtl['title'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['photo_album_id'].'">'.$opt_dtl['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	public function get_video_album_title_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get video_album list
		$builder = $this->db->table('video_album AS mt');
		$query = $builder->join('video_album_ln AS ln',"mt.video_album_id=ln.video_album_id AND ln.language_code='".$this->project->default_lang_code."'","inner")
				->select('mt.video_album_id,ln.title')
				->orderBy('ln.title','ASC')
				->where('mt.is_deleted','No')
				->where('mt.status','Active')
				->get();
		$opt_arr = $query->getResultArray();
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['video_album_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['video_album_id'].'" selected>'.$opt_dtl['title'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['video_album_id'].'">'.$opt_dtl['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	public function get_yes_no_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$opt_arr = ['No', 'Yes'];
		foreach($opt_arr as $opt_val){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_val.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_val.'</option>';
			}
		}
		return $opt_str;
	}
	
	public function get_status_options($default="",$only_default=false){
		$default = $default ?: 'Active';
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$opt_arr = ['Active', 'Inactive'];
		foreach($opt_arr as $opt_val){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_val.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_val.'</option>';
			}
		}
		return $opt_str;
	}
	
	public function get_department_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get department list
		$builder = $this->db->table('department');
		$query = $builder->orderBy('name','ASC')
						 ->where('is_deleted','No')
						 ->where('status','Active')
						 ->get();
		$opt_arr = $query->getResultArray();
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['department_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['department_id'].'" selected>'.$opt_dtl['name'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['department_id'].'">'.$opt_dtl['name'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_company_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get list
		$builder = $this->db->table('company');
		$query = $builder->orderBy('name','ASC')
						 ->where('is_deleted','No')
						 ->where('status','Active')
						 ->get();
		$opt_arr = $query->getResultArray();
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['company_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['company_id'].'" selected>'.$opt_dtl['name'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['company_id'].'">'.$opt_dtl['name'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	function get_company_detail($company_id){
		$builder = $this->db->table('company');
		$query = $builder->where('company_id',$company_id)
					->get();
		return $query->getRowArray();
	}
	
	public function get_status_type($default="",$only_default=false){
		$default = $default ?: 'Active';
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$opt_arr = ['Active', 'Inactive'];
		foreach($opt_arr as $opt_val){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_val.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_val.'</option>';
			}
		}
		return $opt_str;
	}
	//for the sort position
	public function get_banner_sort_options($default="",$only_default=false,$except_banner_id=""){
		$opt_str = $only_default ? '' : '<option value="0">At the beginning</option>';
		                           
		// Get title list
		$builder = $this->db->table('banner');
		if($except_banner_id!=""){
			$builder->where('banner_id!=',$except_banner_id);
		}
		$builder->orderBy('sort_order','ASC');		
		$query = $builder->get();
		$opt_arr = $query->getResultArray();
		
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['banner_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['banner_id'].'" selected>'.'After '.$opt_dtl['title'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['banner_id'].'">'.'After '.$opt_dtl['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_parent_site_menu_options($action,$rec_list,$default="",$disabled=""){
		$opt_str = '<option value="">Select</option>';
		if($rec_list){
			foreach($rec_list as $id => $title){
				if($id==$default){
					$opt_str .= '<option value="'.$id.'" selected>'.$title.'</option>';
				}else if($action=="edit" && $id==$disabled){
					$opt_str .= '<option value="'.$id.'" disabled>'.$title.'</option>';
				}else{
					$opt_str .= '<option value="'.$id.'">'.$title.'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_position_options($default=""){
		$opt_arr = ['before'=>'Before','after'=>'After'];
		$opt_str = '<option value="">Select Position</option>';
		if($opt_arr){
			foreach($opt_arr as $opt_val => $opt_txt){
				if($opt_val==$default){
					$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_txt.'</option>';
				}else {
					$opt_str .= '<option value="'.$opt_val.'">'.$opt_txt.'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_content_type_options($default=""){
		$builder = $this->db->table('content_type');		
		$query = $builder->where('status','Active')
			->where('is_deleted','No')
			->orderBy('title','ASC')
			->get();
		$opt_arr = $query->getResultArray();
		
		$opt_str = '';
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['content_type_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['content_type_id'].'" selected>'.$opt_dtl['title'].'</option>';
				}else{
					$opt_str .= '<option value="'.$opt_dtl['content_type_id'].'">'.$opt_dtl['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_content_type_site_menu_options($content_type_id, $default=""){
		$builder = $this->db->table('site_menu');
		$query = $builder->where('status','Active')
			->where('is_deleted','No')
			->where('content_type_id',$content_type_id)
			->orderBy('title','ASC')
			->get();
		$opt_arr = $query->getResultArray();
		
		$opt_str = '<option value="">Select</option>';
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['site_menu_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['site_menu_id'].'" selected>'.$opt_dtl['title'].'</option>';
				}else{
					$opt_str .= '<option value="'.$opt_dtl['site_menu_id'].'">'.$opt_dtl['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_language_options($default=""){
		$builder = $this->db->table('language');
		$query = $builder->where('status','Active')
			->where('is_deleted','No')
			->orderBy('name','ASC')
			->get();
		$opt_arr = $query->getResultArray();
		$opt_str = '<option value="">Select</option>';
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['code']==$default){
					$opt_str .= '<option value="'.$opt_dtl['code'].'" selected>'.$opt_dtl['name'].'</option>';
				}else{
					$opt_str .= '<option value="'.$opt_dtl['code'].'">'.$opt_dtl['name'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function send_sms($sms_id, $mobile_no, $msg_var_arr=[]){
		$builder = $this->db->table('sms');
		$query = $builder->where('sms_id',$sms_id)
			->where('status','Active')
			->get();
		$sms_dtl = $query->getRowArray();
		if($sms_dtl){
			$msg = $sms_dtl['message_template'];
			if($msg_var_arr){
				foreach($msg_var_arr as $var_name => $var_value){
					$msg = str_replace($var_name,$var_value,$msg);
				}
			}
			$url = $sms_dtl['base_url']."&".
			   $sms_dtl['mobile_no_param_name']."=".$mobile_no."&".
			   $sms_dtl['message_param_name']."=".urlencode($msg);
			  //rawurlencode($msg)
			$ch = curl_init($url); 
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
			$curl_scraped_page = curl_exec($ch); 
			curl_close($ch);
		}		
	}	
	
	public function get_email_object($from_email="",$from_name=""){
		$email = \Config\Services::email();
		$config['protocol'] = 'sendmail';
		$config['mailPath'] = '/usr/sbin/sendmail';
		$config['charset']  = 'utf-8';
		$config['wordWrap'] = false;
		$config['mailType'] = 'html';
		$email->initialize($config);
		$from_email = $from_email ?: 'noreply@support.dhumal.com';
		$from_name = $from_name ?: 'support.dhumal.com';
		$email->setFrom($from_email, $from_name);
		return $email;
	}
	
	public function get_row($table,$pk_column,$pk_value){
		$builder = $this->db->table($table);
		$query = $builder->where($pk_column,$pk_value)
					->get();
		return $query->getRowArray();
	}
	
	public function get_builder($table){
		return $this->db->table($table);
	}
	
	public function get_language_list(){
		$builder = $this->db->table('language');
		$query = $builder->select('language_id, code, name, is_default')
			->where('status','Active')
			->where('is_deleted','No')
			->orderBy('is_default','DESC')
			->get();
		return $query->getResultArray();
	}
	
	public function get_default_language(){
		$builder = $this->db->table('language');
		$query = $builder->where('is_default','Yes')
			->where('status','Active')
			->where('is_deleted','No')
			->get();
		return $query->getRowArray();
	}
	
	public function get_review_type_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$opt_arr = ['Google Review', 'Facebook Review'];
		foreach($opt_arr as $opt_val){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_val.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_val.'</option>';
			}
		}
		return $opt_str;
	}
	 
	public function get_upload_type_options($default="",$only_default=false){
		$opt_arr = [''=>'Select','File'=>'File','URL'=>'URL'];
		$opt_str = '';
		foreach($opt_arr as $opt_val => $opt_txt){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_txt.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_txt.'</option>';
			}
		}
		return $opt_str;
	}
	
	public function get_icon_options($default=""){
		$builder = $this->db->table('icon');
		$query = $builder->where('status','Active')
			->where('is_deleted','No')
			->orderBy('name','ASC')
			->get();
		$opt_arr = $query->getResultArray();
		$opt_str = '<option value="">Select</option>';
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['icon_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['icon_id'].'" selected>'.$opt_dtl['name'].'</option>';
				}else{
					$opt_str .= '<option value="'.$opt_dtl['icon_id'].'">'.$opt_dtl['name'].'</option>';
				}
			}
		}
		return $opt_str;
	}
// for News Category dropdownlist
	public function get_news_category_type_options($default="",$only_default=false){
		//echo $default;

		$builder = $this->db->table('news_category AS mt');
		$query = $builder->join('news_category_ln AS ln',"mt.news_category_id=ln.news_category_id AND ln.language_code='".$this->project->default_lang_code."'","inner")
				->select('mt.news_category_id,ln.title')
				->orderBy('ln.title','ASC')
				->where('mt.is_deleted','No')
				->where('mt.status','Active')
				->get();

		$opt_arr = $query->getResultArray();
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
	
		if ($opt_arr) {
			foreach($opt_arr as $opt_val){
				if($opt_val['news_category_id']==$default){
					$opt_str .= '<option value="'.$opt_val['news_category_id'].'" selected="selected">'.$opt_val['title'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_val['news_category_id'].'">'.$opt_val['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_photo_album_options($default="",$only_default=false){
		//echo $default;

		$builder = $this->db->table('photo_album AS mt');
		$query = $builder->join('photo_album_ln AS ln',"mt.photo_album_id=ln.photo_album_id AND ln.language_code='".$this->project->default_lang_code."'","inner")
				->select('mt.photo_album_id,ln.title')
				->orderBy('ln.title','ASC')
				->where('mt.is_deleted','No')
				->where('mt.status','Active')
				->get();

		$opt_arr = $query->getResultArray();
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
	
		if ($opt_arr) {
			foreach($opt_arr as $opt_val){
				if($opt_val['photo_album_id']==$default){
					$opt_str .= '<option value="'.$opt_val['photo_album_id'].'" selected="selected">'.$opt_val['title'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_val['photo_album_id'].'">'.$opt_val['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
		public function get_job_type_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$opt_arr = ['Full Time', 'Part Time'];
		foreach($opt_arr as $opt_val){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_val.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_val.'</option>';
			}
		}
		return $opt_str;
	}
// new news category add on master
public function get_news_category_title_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get photo_album list
		$builder = $this->db->table('news_category AS mt');
		$query = $builder->join('news_category_ln AS ln',"mt.news_category_id=ln.news_category_id AND ln.language_code='".$this->project->default_lang_code."'","inner")
				->select('mt.news_category_id,ln.title')
				->orderBy('ln.title','ASC')
				->where('mt.is_deleted','No')
				->where('mt.status','Active')
				->get();
		$opt_arr = $query->getResultArray();
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['news_category_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['news_category_id'].'" selected>'.$opt_dtl['title'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['news_category_id'].'">'.$opt_dtl['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	// breaking news type yes no
	public function get_breaking_news_type_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		$opt_arr = ['No', 'Yes'];
		foreach($opt_arr as $opt_val){
			if($opt_val==$default){
				$opt_str .= '<option value="'.$opt_val.'" selected>'.$opt_val.'</option>';
			}else if( ! $only_default){
				$opt_str .= '<option value="'.$opt_val.'">'.$opt_val.'</option>';
			}
		}
		return $opt_str;
	}
	
	public function get_property_type_options($default="",$only_default=false){
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
		// Get  list
		$builder = $this->db->table('property_type');
		$query = $builder->select('property_type_id, title')
				->orderBy('title','ASC')
				->where('is_deleted','No')
				->where('status','Active')
				->get();
		$opt_arr = $query->getResultArray();
		if($opt_arr){
			foreach($opt_arr as $opt_dtl){
				if($opt_dtl['property_type_id']==$default){
					$opt_str .= '<option value="'.$opt_dtl['property_type_id'].'" selected>'.$opt_dtl['title'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_dtl['property_type_id'].'">'.$opt_dtl['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_product_category_options($default="",$only_default=false){
		//echo $default;
		$builder = $this->db->table('product_category AS mt');
		$query = $builder->join('product_category_ln AS ln',"mt.product_category_id=ln.product_category_id AND ln.language_code='".$this->project->default_lang_code."'","inner")
				->select('mt.product_category_id,ln.title')
				->orderBy('ln.title','ASC')
				->where('mt.is_deleted','No')
				->where('mt.status','Active')
				->get();

		$opt_arr = $query->getResultArray();
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
	
		if ($opt_arr) {
			foreach($opt_arr as $opt_val){
				if($opt_val['product_category_id']==$default){
					$opt_str .= '<option value="'.$opt_val['product_category_id'].'" selected="selected">'.$opt_val['title'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_val['product_category_id'].'">'.$opt_val['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
	
	public function get_download_category_options($default="",$only_default=false){
		//echo $default;
		$builder = $this->db->table('download_category AS mt');
		$query = $builder->join('download_category_ln AS ln',"mt.download_category_id=ln.download_category_id AND ln.language_code='".$this->project->default_lang_code."'","inner")
				->select('mt.download_category_id,ln.title')
				->orderBy('ln.title','ASC')
				->where('mt.is_deleted','No')
				->where('mt.status','Active')
				->get();

		$opt_arr = $query->getResultArray();
		$opt_str = $only_default ? '' : '<option value="">Select</option>';
	
		if ($opt_arr) {
			foreach($opt_arr as $opt_val){
				if($opt_val['download_category_id']==$default){
					$opt_str .= '<option value="'.$opt_val['download_category_id'].'" selected="selected">'.$opt_val['title'].'</option>';
				}else if( ! $only_default){
					$opt_str .= '<option value="'.$opt_val['download_category_id'].'">'.$opt_val['title'].'</option>';
				}
			}
		}
		return $opt_str;
	}
}	