<?php
class emp extends CI_controller
{
function __construct()
{
parent::__construct();
$this->load->model('dbemp');
$this->load->library('upload');
$this->load->library('pagination');
}
function index()
{
$this->load->view('empform');
}
public function check_username_availablity()
{
//print_r('rakes');
// $get_result = $this->dbemp->check_username_availablity();
$username = $_POST['username'];
// echo "false";
$query = $this->db->query("SELECT username FROM registration WHERE username='$username'")->num_rows();
if($query>0 )
echo "false";
else
echo "true";
}
public function check_username_for_update()
{
//echo "false";
// print_r($_POST);
// die();
//$username = $_POST['upd_username'];
$username = 'vinod';
// echo "false";
$username_db = $this->db->query("SELECT username FROM registration")->result_array();
$statuts = 1;
foreach ($username_db as $value)
{
//echo "<pre>";
// print_r($value['username']);
echo "<pre>";
// print_r($username);
echo "Data base ".$value['username']."<br>";
echo "user ".$username."<br>";
if($username == $value['username'])
{
//echo " true";
$statuts=0;
}
else
{
//echo "false";
}
}
echo "status ".$statuts;
}
function set_upload()
{
$config = array();
$config['upload_path'] = 'upload/';
$config['allowed_types'] = 'png|jpg|jpeg|gif';
$config['max_size'] = '0';
$config['overwrite'] = FALSE;
return $config;
}
function insertdata()
{
//echo "array value";
// print_r($_POST);
$insert=array('username'=>$_POST['username'],
'password'=>$_POST['password'],
'address'=>$_POST['address'],
'contact'=>$_POST['contact'],
'email'=>$_POST['email'],
'gender'=>$_POST['gender'],
//'images'=>$img_file,
'city'=>$_POST['city'],
'hobby'=>implode(",",$_POST['hobby']));
$this->dbemp->insert($insert);
}
function getvalues()
{
echo "<h1>hello</h1><br>";
$this->load->model('dbemp');
$data['result'] = $this->dbemp->getAll();
// $this->load->view('empform',$data);
echo "<table border=1>";
echo "<th>id</th>";
echo "<th>Username</th>";
echo "<th>Password</th>";
echo "<th>Address</th>";
echo "<th>Contact</th>";
echo "<th>Email</th>";
echo "<th>Gender</th>";
echo "<th>City</th>";
echo "<th>Hobby</th>";
echo "<th colspan=2 >Action</th>";
$no=1;
$username_db = $this->db->query("SELECT username FROM registration")->result_array();
//echo $username_db[0]['username'];
//print_r($username_db);
foreach($data['result'] as $row)
{
?>
<tr id="row_<?php echo $row->id;?>">
<td><?php echo $no; $row->id;?></td>
<td><?php echo $row->username;?></td>
<td><?php echo $row->password;?></td>
<td><?php echo $row->address?></td>
<td><?php echo $row->contact;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->gender;?></td>
<td><?php echo $row->city;?></td>
<td><?php echo $row->hobby;?></td>
<td>
<a href="<?php echo base_url();?>emp/delete/<?php echo $row->id;?>">Delete</a></td>
<td><a href="javascript:void()"onclick="update('<?php echo $row->id;?>');">Update</a></td>
</tr>
<tr style="display:none;" id="input_row_<?php echo $row->id;?>">
<td><?php echo $no; $row->id;?></td>
<td><input type="text" name="upd_username" id="upd_username" value="<?php echo $row->username;?>">
<input type="hidden" name="upd_username1" id="upd_username1" value="<?php echo $row->username;?>">
</td>
<td><input type="text" name="password" id="password" value="<?php echo $row->password;?>"></td>
<td><input type="text" name="address" id="address" value="<?php echo $row->address;?>"></td>
<td><input type="text" name="contact" id="contact" value="<?php echo $row->contact;?>"></td>
<td><input type="text" name="email" id="email" value="<?php echo $row->email;?>"></td>
<td><input type="text" name="gender" id="gender" value="<?php echo $row->gender;?>"></td>
<td><input type="text" name="city" id="city" value="<?php echo $row->city;?>"></td>
<td><input type="text" name="hobby" id="hobby" value="<?php echo $row->hobby;?>"></td>
<td>
<a href="<?php echo base_url();?>emp/delete/<?php echo $row->id;?>">Delete</a></td>
<td><a href="<?php echo base_url();?>emp/<?php echo $row->id;?>" onclick="update('<?php echo $row->id;?>');" >Update</a>
</td>
<td><input type="submit" name="submit" id="submit" value="update"></td>
</tr>
<?php
$no++;
}
echo "</table>";
return $data;
}
function fetch()
{
$config['base_url']= base_url()."emp/fetch";
$config['total_rows']=$this->dbemp->getcount();
$config['per_page']=3;
$config['uri_segment']=3;
$this->pagination->initialize($config);
$page=($this->uri->segment(3))? $this->uri->segment(3):0;
$data['result']=$this->dbemp->getalldata($config["per_page"],$page);
$data['link']=$this->pagination->create_links();
$this->load->view('display',$data);
}
function search()
{
$config['base_url']= base_url()."emp/fetch";
$config['total_rows']=$this->dbemp->getcount();
$config['per_page']=3;
$config['uri_segment']=3;
$this->pagination->initialize($config);
$page=($this->uri->segment(3))? $this->uri->segment(3):0;
$data['result']=$this->dbemp->getsearch($config["per_page"],$page);
$data['link']=$this->pagination->create_links();
//$data['result']=$this->dbemp->getsearch();
$this->load->view('display',$data);
}
function delete($id)
{
$qur="select * from registration where id=".$id;
$res=$this->db->query($qur)->result_array();
echo "<pre>";
print_r($res);
echo "</pre>";
$img_array=explode(',', $res[0]['images']);
echo "<pre>";
print_r($img_array);
echo "</pre>";
foreach ($img_array as $img) {
unlink("upload/".$img);
}
$this->db->query("delete from registration where id=".$id);
//$abc=$this->dbemp->deleteimg($id);
//unlink("upload/".$abc->images);
//$this->dbemp->delete($id);
redirect('emp/fetch');
}
function delete_single($id,$image)
{ //for one image delete from one user's multiple delete folder..
unlink("upload/" .$image);
$qur=$this->db->query("select * from registration where id=".$id)->row_array();
$arysss=explode(',', $qur['images']);
$namee=$image;
$arysss = array_diff($arysss, array($namee));
$string = implode(',', $arysss);
$data = array('images'=>$string);
$this->db->where('id',$id);
$this->db->update('registration',$data);
redirect('emp/fetch');
}
function delete_all()
{
foreach($_POST['id'] as $id)
{
$this->dbemp->delete($id);
}
redirect('emp/fetch');
}
}
?>
class emp extends CI_controller
{
function __construct()
{
parent::__construct();
$this->load->model('dbemp');
$this->load->library('upload');
$this->load->library('pagination');
}
function index()
{
$this->load->view('empform');
}
public function check_username_availablity()
{
//print_r('rakes');
// $get_result = $this->dbemp->check_username_availablity();
$username = $_POST['username'];
// echo "false";
$query = $this->db->query("SELECT username FROM registration WHERE username='$username'")->num_rows();
if($query>0 )
echo "false";
else
echo "true";
}
public function check_username_for_update()
{
//echo "false";
// print_r($_POST);
// die();
//$username = $_POST['upd_username'];
$username = 'vinod';
// echo "false";
$username_db = $this->db->query("SELECT username FROM registration")->result_array();
$statuts = 1;
foreach ($username_db as $value)
{
//echo "<pre>";
// print_r($value['username']);
echo "<pre>";
// print_r($username);
echo "Data base ".$value['username']."<br>";
echo "user ".$username."<br>";
if($username == $value['username'])
{
//echo " true";
$statuts=0;
}
else
{
//echo "false";
}
}
echo "status ".$statuts;
}
function set_upload()
{
$config = array();
$config['upload_path'] = 'upload/';
$config['allowed_types'] = 'png|jpg|jpeg|gif';
$config['max_size'] = '0';
$config['overwrite'] = FALSE;
return $config;
}
function insertdata()
{
//echo "array value";
// print_r($_POST);
$insert=array('username'=>$_POST['username'],
'password'=>$_POST['password'],
'address'=>$_POST['address'],
'contact'=>$_POST['contact'],
'email'=>$_POST['email'],
'gender'=>$_POST['gender'],
//'images'=>$img_file,
'city'=>$_POST['city'],
'hobby'=>implode(",",$_POST['hobby']));
$this->dbemp->insert($insert);
}
function getvalues()
{
echo "<h1>hello</h1><br>";
$this->load->model('dbemp');
$data['result'] = $this->dbemp->getAll();
// $this->load->view('empform',$data);
echo "<table border=1>";
echo "<th>id</th>";
echo "<th>Username</th>";
echo "<th>Password</th>";
echo "<th>Address</th>";
echo "<th>Contact</th>";
echo "<th>Email</th>";
echo "<th>Gender</th>";
echo "<th>City</th>";
echo "<th>Hobby</th>";
echo "<th colspan=2 >Action</th>";
$no=1;
$username_db = $this->db->query("SELECT username FROM registration")->result_array();
//echo $username_db[0]['username'];
//print_r($username_db);
foreach($data['result'] as $row)
{
?>
<tr id="row_<?php echo $row->id;?>">
<td><?php echo $no; $row->id;?></td>
<td><?php echo $row->username;?></td>
<td><?php echo $row->password;?></td>
<td><?php echo $row->address?></td>
<td><?php echo $row->contact;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->gender;?></td>
<td><?php echo $row->city;?></td>
<td><?php echo $row->hobby;?></td>
<td>
<a href="<?php echo base_url();?>emp/delete/<?php echo $row->id;?>">Delete</a></td>
<td><a href="javascript:void()"onclick="update('<?php echo $row->id;?>');">Update</a></td>
</tr>
<tr style="display:none;" id="input_row_<?php echo $row->id;?>">
<td><?php echo $no; $row->id;?></td>
<td><input type="text" name="upd_username" id="upd_username" value="<?php echo $row->username;?>">
<input type="hidden" name="upd_username1" id="upd_username1" value="<?php echo $row->username;?>">
</td>
<td><input type="text" name="password" id="password" value="<?php echo $row->password;?>"></td>
<td><input type="text" name="address" id="address" value="<?php echo $row->address;?>"></td>
<td><input type="text" name="contact" id="contact" value="<?php echo $row->contact;?>"></td>
<td><input type="text" name="email" id="email" value="<?php echo $row->email;?>"></td>
<td><input type="text" name="gender" id="gender" value="<?php echo $row->gender;?>"></td>
<td><input type="text" name="city" id="city" value="<?php echo $row->city;?>"></td>
<td><input type="text" name="hobby" id="hobby" value="<?php echo $row->hobby;?>"></td>
<td>
<a href="<?php echo base_url();?>emp/delete/<?php echo $row->id;?>">Delete</a></td>
<td><a href="<?php echo base_url();?>emp/<?php echo $row->id;?>" onclick="update('<?php echo $row->id;?>');" >Update</a>
</td>
<td><input type="submit" name="submit" id="submit" value="update"></td>
</tr>
<?php
$no++;
}
echo "</table>";
return $data;
}
function fetch()
{
$config['base_url']= base_url()."emp/fetch";
$config['total_rows']=$this->dbemp->getcount();
$config['per_page']=3;
$config['uri_segment']=3;
$this->pagination->initialize($config);
$page=($this->uri->segment(3))? $this->uri->segment(3):0;
$data['result']=$this->dbemp->getalldata($config["per_page"],$page);
$data['link']=$this->pagination->create_links();
$this->load->view('display',$data);
}
function search()
{
$config['base_url']= base_url()."emp/fetch";
$config['total_rows']=$this->dbemp->getcount();
$config['per_page']=3;
$config['uri_segment']=3;
$this->pagination->initialize($config);
$page=($this->uri->segment(3))? $this->uri->segment(3):0;
$data['result']=$this->dbemp->getsearch($config["per_page"],$page);
$data['link']=$this->pagination->create_links();
//$data['result']=$this->dbemp->getsearch();
$this->load->view('display',$data);
}
function delete($id)
{
$qur="select * from registration where id=".$id;
$res=$this->db->query($qur)->result_array();
echo "<pre>";
print_r($res);
echo "</pre>";
$img_array=explode(',', $res[0]['images']);
echo "<pre>";
print_r($img_array);
echo "</pre>";
foreach ($img_array as $img) {
unlink("upload/".$img);
}
$this->db->query("delete from registration where id=".$id);
//$abc=$this->dbemp->deleteimg($id);
//unlink("upload/".$abc->images);
//$this->dbemp->delete($id);
redirect('emp/fetch');
}
function delete_single($id,$image)
{ //for one image delete from one user's multiple delete folder..
unlink("upload/" .$image);
$qur=$this->db->query("select * from registration where id=".$id)->row_array();
$arysss=explode(',', $qur['images']);
$namee=$image;
$arysss = array_diff($arysss, array($namee));
$string = implode(',', $arysss);
$data = array('images'=>$string);
$this->db->where('id',$id);
$this->db->update('registration',$data);
redirect('emp/fetch');
}
function delete_all()
{
foreach($_POST['id'] as $id)
{
$this->dbemp->delete($id);
}
redirect('emp/fetch');
}
}
?>
No comments:
Post a Comment