>

Thursday, November 10, 2016

CI_gallery_controller

<?php

class Gallery_controller extends CI_Controller {

        public function index()
        {        
 
        }

   public function __construct() {

parent::__construct();
if(! $this->session->userdata('session_username'))
redirect();

}

public function galleryAdmin()
        {
$this->load->model('gallery_model');
$data['user_list'] = $this->gallery_model->get_dropdown_list();
$this->load->view('admin/galleryAdmin_view', $data);
}

public function user_userdata()
{  
   $userid = $this->input->post('userid');

        $this->load->model('gallery_model');
        $data['r'] = $this->gallery_model->gallery_data($userid);
echo json_encode($data);

//$this->load->view('admin/galleryAdmin_view2', $data);
}

public function createGallery()
        {   $this->load->model('gallery_model');
$data['user_list'] = $this->gallery_model->get_dropdown_list();
$this->load->view('admin/createGallery',$data);
}

public function createGallery_insert()
        {  
$userid = $this->input->post('userid');
if($userid == 0 || $userid == null || $userid == '')
{
$this->load->model('gallery_model');
$data['user_list'] = $this->gallery_model->get_dropdown_list();
$this->load->view('admin/createGallerySelectuser',$data);
}
else
{
            $username = $this->input->post('username1'); //for directory creation
   $galleryname = $this->input->post('galleryname');
$eventdate = $this->input->post('eventdate');
$totalphoto = "";
$selectedphoto = "";
$glock="";
/* already write at start function so skip here$userid
$userid = $this->input->post('userid'); */

$data = array(
                'gname' => trim($galleryname),
                'eventdate' => trim($eventdate),
'totalphoto' =>$totalphoto,
'selectedphoto' => $selectedphoto,
'glock' =>$glock,
'userid' => $userid
);
         
$this->load->model('gallery_model');
$data['user_list'] = $this->gallery_model->insert_gallery($data);

// create "gallername" folder under userlist/username folder
$path="./userlist/".$username."/".$galleryname;
mkdir($path,0777,true);
header('Location:'.base_url().'admin_cont/adminpage');
            //echo "insert successfully";
//$this->load->view('admin/createGallery',$data);
//$this->load->view('admin/galleryAdmin_view');
            }

}

public function EditGallery($galleryid)
        {
  $this->load->model('gallery_model');
  $row=$this->gallery_model->getonerow_edit($galleryid);
  $data['r']=$row;
  $this->load->view('admin/editgallery',$data);
}

public function EditGallery_insert()
        {  
   $galleryid=$this->input->post('galleryid');

   $data= array(
'gname' => trim($this->input->post('gname')),
'eventdate' => trim($this->input->post('eventdate')),
   );

$this->load->model('gallery_model');
   //$row=$this->gallery_model->EditGalleryModel_insert($data); same thinf in if else but give return
if($this->gallery_model->EditGalleryModel_insert($data)){
//Successfull insertion
header('Location:'.base_url().'admin_cont/gallery_controller/galleryAdmin');
}
else
//not Successfull insertion
header('Location:'.base_url().'admin_cont/gallery_controller/galleryAdmin');
}

//For View -> galleryphotos
public function galleryphotos($galleryid)
        {   //$username = $this->input->post('username1');
    $this->load->model('gallery_model');
    $row=$this->gallery_model->getonerow_edit($galleryid);
$data['r']=$row;

$userid= $row->userid;

$this->load->model('gallery_model');
$row1=$this->gallery_model->getonerow_edit_login($userid);
    $data['r1']=$row1;

    $this->load->view('admin/galleryphotos',$data);
}

//gallery_photos function => Use for galleryAdmin_view
public function gallery_photos()
{  
   $galleryid = $this->input->post('galleryid');


        $this->load->model('gallery_model');
        $data['r'] = $this->gallery_model->gallery_photos($galleryid);
echo json_encode($data);

//$this->load->view('admin/galleryAdmin_view2', $data);
}


//Call from view->galleryphotos on deleteMe function
public function Photo_delete()
{  
   $this->load->model('gallery_model');
        $galleryid = $this->gallery_model->Photo_del();
header('Location:'.base_url().'admin_cont/gallery_controller/galleryphotos/'.$galleryid);
//header('Location:'.base_url().'admin_cont/gallery_controller/galleryAdmin');
}

public function AllPhoto_delete()
{  
   $this->load->model('gallery_model');
        $galleryid = $this->gallery_model->AllPhoto_del();
header('Location:'.base_url().'admin_cont/gallery_controller/galleryphotos/'.$galleryid);
//header('Location:'.base_url().'admin_cont/gallery_controller/galleryAdmin');
}

}