File "madmin.php"

Full Path: /home/ichhrkpd/public_html/idcm_old/application/models/database/madmin.php
File size: 10.73 KB
MIME-type: text/x-php
Charset: utf-8

<?php 
			
/**
 * Version 1.0.0
 * Creation date: 15/Feb/2015
 * @Written By: S.M. Sarwar Hasan
 *     Genuity Systems
 */						
class Madmin extends GSModel{
	var $admin_pid;
	var $email;
	var $password;
	var $fname;
	var $lname;
	var $title;
	var $time_zone;
	var $short_bio;
	var $role;
	var $status;
	
	private $magic_quotes_active;
	private $real_escape_string_exists;
	
	//foreach($timezones as $key => $zone){
		function __construct() {
			parent::__construct ();
			$this->SetValidation();	
			$this->tableName="admin";
			$this->primaryKey="admin_pid";
			
			//$this->magic_quotes_active = get_magic_quotes_gpc();
			//$this->real_escape_string_exists = function_exists( "mysql_real_escape_string" );
		}
			
	 function Reset(){
		$this->admin_pid=$this->email=$this->password=$this->fname=$this->lname=$this->title=$this->time_zone=$this->short_bio=$this->role=$this->status=null;

	}

	public function escape_value( $value ) {
		if( $this->real_escape_string_exists ) { // PHP v4.3.0 or higher
			// undo any magic quote effects so mysql_real_escape_string can do the work
			if( $this->magic_quotes_active ) { $value = stripslashes( $value ); }
			$value = mysql_real_escape_string( $value );
		} else { // before PHP v4.3.0
			// if magic quotes aren't already on then add slashes manually
			if( !$this->magic_quotes_active ) { $value = addslashes( $value ); }
			// if magic quotes are active, then the slashes already exist
		}
		return $value;
	}
	
	public function authenticate($email="", $password=""){
		$this->email($email);
		if($this->Select()){
			//if($this->password==md5($password)){
			if($this->password==md5($password) && $this->status=="A"){	
				$this->SetAdminSession();
				return true;
			}			
		}
		return false;	
	}
	
	function SetAdminSession($data=null,$isLoggedIn=true){
		if(empty($data)){
			$data=$this;
		}
		/*
		[admin_pid] => 1
		[email] => test@gmail.com
		[password] => 123456
		[fname] => Walid
		[lname] => Islam
		[title] => Engg
		[time_zone] => -6.50
		[short_bio] => Oh my love
		[role] => A
		[status] => A	
		*/	
		
		$adses=new AdminSession();
		$adses->admin_pid=$data->admin_pid;
		$adses->email=$data->email;
		$adses->fname=$data->fname;
		$adses->lname=$data->lname;
		$adses->title=$data->title;
		$adses->role=$data->role;
		$adses->record_per_page=10;
		$adses->LoggedIn=$isLoggedIn;
		//var_dump($adses);die;public $record_per_page;
		if($data->role == 'V skipeed'){
			$this->session->SetVtrData($adses);
		} else {
			$this->session->SetAdminData($adses);
		}
		
	}
	
	function SetValidation(){
		$this->validations=array(
			"admin_pid"=>array("Text"=>"admin_pid", "Rule"=>"required|xss_clean"),
			"email"=>array("Text"=>"Email Address", "Rule"=>"required|xss_clean"),
			"password"=>array("Text"=>"Password", "Rule"=>"required|xss_clean"),
			"fname"=>array("Text"=>"First Name", "Rule"=>"required|xss_clean"),
			"lname"=>array("Text"=>"Last Name", "Rule"=>"required|xss_clean"),
			"title"=>array("Text"=>"Title", "Rule"=>"required|xss_clean"),
			//"time_zone"=>array("Text"=>"time_zone", "Rule"=>""),
			//"short_bio"=>array("Text"=>"short_bio", "Rule"=>""),
			//"role"=>array("Text"=>"role", "Rule"=>""),
			"status"=>array("Text"=>"status", "Rule"=>"")
		);
	}
	
	/*Use these time zones: Delete all others...
1. Eastern Standard Time
2. Pacific Standard Time
3. Mountain Standard Time
4. Central Standard Time
*/
	
	 function GetAddForm($isEdit,$label_col=5,$input_col=7,$mainobj=null){
	 	//$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);GPrint($tzlist);
	 	//http://stackoverflow.com/questions/1727077/generating-a-drop-down-list-of-timezones-with-php
	 	$timezonesArr = array (
	 			'-5' => '[UTC - 5] Eastern Standard Time',
	 			'-8' => '[UTC - 8] Pacific Standard Time',
	 			'-7' => '[UTC - 7] Mountain Standard Time',
	 			'-6' => '[UTC - 6] Central Standard Time'
	 	);	 	
		
				if(!$mainobj){
				$mainobj=$this;
				}
				
				$role = $this->session->GetAdminData ()->role;
				
					?>
					
			 <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="fname"><?php _e("First Name"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">                   			     	
		      		<input type="text" maxlength="50"  value="<?php echo  $mainobj->GetPostValue("fname");?>" class="form-control" id="fname" name="fname" placeholder="First Name" data-bv-notempty="true" 	data-bv-notempty-message="<?php  _e("First Name is required");?>">
		      	</div>
		      </div> 
			
			 <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="lname"><?php _e("Last Name"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">                   			     	
		      		<input type="text" maxlength="50"  value="<?php echo  $mainobj->GetPostValue("lname");?>" class="form-control" id="lname" name="lname" placeholder="Last Name" data-bv-notempty="true" 	data-bv-notempty-message="<?php  _e("Last Name is required");?>">
		      	</div>
		      </div> 
		      
		      
		      <?php if($role == 'S'){?>
		      <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="role"><?php _e("Role"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">
	      			<select name="role" class="form-control"> 
						<option <?php echo $mainobj->role=="V"?' selected="selected" ':"";?> value="V">Volunteer</option>
						<option <?php echo $mainobj->role=="A"?' selected="selected" ':"";?> value="A">Admin</option>
						<option <?php echo $mainobj->role=="S"?' selected="selected" ':"";?> value="S">Super Admin</option>
					</select>		      	
		      	</div>
		     </div>	
		     <?php }?>	
		     
		    <?php if($role == 'A'){?>
		      <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="role"><?php _e("Role"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">
	      			<select name="role" class="form-control"> 
						<option <?php echo $mainobj->role=="V"?' selected="selected" ':"";?> value="V">Volunteer</option>
					</select>		      	
		      	</div>
		     </div>	
		     <?php }?>					
			
			 <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="email"><?php _e("Email Address"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">                   			     	
		      		<input type="text" maxlength="50"  value="<?php echo  $mainobj->GetPostValue("email");?>" class="form-control" id="email" name="email" placeholder="Email Address" data-bv-notempty="true" 	data-bv-notempty-message="<?php  _e("Email Address is required");?>">
		      	</div>
		      </div> 
			
			 <?php if(!$isEdit){ ?>
			 <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="password"><?php _e("Password"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">                   			     	
		      		<input type="text" maxlength="32"  value="<?php echo  $mainobj->GetPostValue("password");?>" class="form-control" id="password" name="password" placeholder="Password" data-bv-notempty="true" 	data-bv-notempty-message="<?php  _e("Password is required");?>">
		      	</div>
		      </div> 
		      <?php }?>
			
			 <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="title"><?php _e("Title"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">                   			     	
		      		<input type="text" maxlength="50"  value="<?php echo  $mainobj->GetPostValue("title");?>" class="form-control" id="title" name="title" placeholder="Title" data-bv-notempty="true" 	data-bv-notempty-message="<?php  _e("Title is required");?>">
		      	</div>
		      </div> 
			
			 <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="time_zone"><?php _e("Time Zone"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">    
	      			<select name="time_zone" class="form-control">
						<?php foreach ($timezonesArr as $key => $zone) { ?>
							<option <?php echo $mainobj->time_zone==$key?' selected="selected" ':"";?>  value="<?php echo $key;?>"><?php echo $zone;?></option>
						<?php } ?>
					</select>		      	               			     	
		      	</div>
		      </div> 
			
			 <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="short_bio"><?php _e("Short Biography"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">                   			     	
		      		<textarea class="form-control" id="short_bio" name="short_bio" placeholder="Enter ..." rows="3" ><?php echo  $mainobj->GetPostValue("short_bio");?></textarea>
		      	</div>
		      </div> 
		      
		     <?php if($isEdit){ ?> 
			 <div class="form-group">
		      	<label class="control-label col-md-<?php echo $label_col;?>" for="status"><?php _e("Status"); ?></label>
		      	<div class="col-md-<?php echo $input_col;?>">
	      			<select name="status" class="form-control"> 
						<option <?php echo $mainobj->status=="A"?' selected="selected" ':"";?> value="A">Active</option>
						<option <?php echo $mainobj->status=="I"?' selected="selected" ':"";?> value="I">Inactive</option>
					</select>		      	
		      	</div>
		     </div>		      
			<?php }?>
		      
		      <div class="form-group">		      	
		      	
		      	<div class="col-md-9 text-right">			      	
					<div class="fileUpload btn btn-primary m-r-zero">
					    <span>Add photo</span>
					    <input id="uploadBtn" name="file_upload" type="file" class="upload" />
					</div>	
					<br/><input id="uploadFile" class="form-control" placeholder="Choose File" disabled="disabled" />	      	
		      	</div>	
		      	<div class="col-md-3 text-left">
		      		<?php 
		      			$image_link=base_url()."img/admin/user.png";
						if(file_exists(BASEPATH."../img/admin/".$mainobj->admin_pid.".jpg")){
							$image_link=base_url()."img/admin/".$mainobj->admin_pid.".jpg?v=".filemtime(BASEPATH."../img/admin/".$mainobj->admin_pid.".jpg");
						}
					?>
		      	<img id="inst_img" style="height:100px;" class="img-thumbnail" border="0" alt="<?php echo $mainobj->fname;?>" title="<?php echo $mainobj->fname;?>" src="<?php echo $image_link;?>">
		      	</div>
					
		      </div> 
			<script type="text/javascript">
				document.getElementById("uploadBtn").onchange = function () {
				    document.getElementById("uploadFile").value = this.value;
				    
				};
				$("#uploadBtn").change(function(){
				    readURL(this,"#inst_img");				  
				});
			</script>		      
			
			<?php 
	}

}


?>