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/Home_centerbanners_hotel.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home_centerbanners_hotel extends Admin_Controller {
		
	function __construct() {

		parent::__construct();

		//admin role module check
		$this->check_admin_role('home & promotion banner'); //method from Admin_controller
		
		$this->load->model('home_centerbanner_hotel_m');	
	} 
		
	//this is to list all home_centerbanners_hotel
	public function index() {
		$hotel_id = $this->session->userdata('hotel_id');
		$this->edit($hotel_id);
    }
	
	//to edit brand in admin
	public function edit($id = NULL) {
		
		// Get hotel_id from session
		$hotel_id = $this->session->userdata('hotel_id');
		
		//check if record exists for this hotel
		$count = $this->home_centerbanner_hotel_m->count_exist_by_hotel($hotel_id); 
		
		if ($count == 0) {
			//record not exist for this hotel
			$this->data['home_centerbanners_hotel'] = $this->home_centerbanner_hotel_m->get_new();	
		}else{
			$this->data['home_centerbanners_hotel'] = $this->home_centerbanner_hotel_m->get_byidhotel($hotel_id);	
		}		

		
		//validation check in action - dynamic validation for all fields
		$fields = array(
			'hotel_id', 'hero_title', 'intro_title', 'intro_subtitle', 'room_title', 'room_subtitle',
			'promotion_title', 'promotion_subtitle', 'facilities_tag', 'facilities_title', 'facilities_subtitle',
			'facilities1_title', 'facilities1_subtitle', 'facilities1_url', 'facilities2_title', 'facilities2_subtitle', 'facilities2_url',
			'facilities3_title', 'facilities3_subtitle', 'facilities3_url', 'facilities4_title', 'facilities4_subtitle', 'facilities4_url',
			'testimony_tag', 'testimony_title', 'testimony_subtitle', 'faq_tag', 'faq_title', 'faq_subtitle',
			'faq1_q', 'faq1_a', 'faq2_q', 'faq2_a', 'faq3_q', 'faq3_a', 'faq4_q', 'faq4_a', 'faq5_q', 'faq5_a', 'faq6_q', 'faq6_a',
			'news_tag', 'news_title', 'news_subtitle', 'cta_tag', 'cta_title', 'cta_subtitle', 'cta_email', 'cta_phone', 'cta_address'
		);
		
		$config = array();
		foreach ($fields as $field) {
			$config[] = array(
				'field' => $field,
				'label' => ucfirst(str_replace('_', ' ', $field)),
				'rules' => 'trim'
			);
		} 
 

		$this->load->library('form_validation');
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled	
		$this->form_validation->set_rules($config); 

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

				// Define all fields including image fields
				$all_fields = array(
					'hotel_id', 'hero_title', 'hero_image', 'intro_title', 'intro_subtitle', 'intro_image1', 'intro_image2', 'intro_image3',
					'room_title', 'room_subtitle', 'room_image', 'promotion_title', 'promotion_subtitle',
					'facilities_tag', 'facilities_title', 'facilities_subtitle',
					'facilities1_title', 'facilities1_subtitle', 'facilities1_image', 'facilities1_url',
					'facilities2_title', 'facilities2_subtitle', 'facilities2_image', 'facilities2_url',
					'facilities3_title', 'facilities3_subtitle', 'facilities3_image', 'facilities3_url',
					'facilities4_title', 'facilities4_subtitle', 'facilities4_image', 'facilities4_url',
					'testimony_tag', 'testimony_title', 'testimony_subtitle',
					'faq_tag', 'faq_title', 'faq_subtitle',
					'faq1_q', 'faq1_a', 'faq2_q', 'faq2_a', 'faq3_q', 'faq3_a', 'faq4_q', 'faq4_a', 'faq5_q', 'faq5_a', 'faq6_q', 'faq6_a',
					'news_tag', 'news_title', 'news_subtitle',
					'gallery1_image', 'gallery2_image', 'gallery3_image', 'gallery4_image', 'gallery5_image',
					'gallery6_image', 'gallery7_image', 'gallery8_image', 'gallery9_image',
					'cta_tag', 'cta_title', 'cta_subtitle', 'cta_email', 'cta_phone', 'cta_address', 'cta_image'
				);

				// Initialize data array
				$data = array();

				// Process each field
				foreach ($all_fields as $field) {
					$is_image_field = strpos($field, 'image') !== false;
					
					if ($is_image_field) {
						// Handle image upload
						if (isset($_FILES[$field]) && $_FILES[$field]['size'] > 0) {
							$upload_config = array(
								'upload_path' => './uploads/page/',
								'allowed_types' => 'jpg|jpeg|png|gif',
								'max_size' => 2048, // 2MB
								'encrypt_name' => TRUE
							);
							
							$this->load->library('upload', $upload_config);
							$this->upload->initialize($upload_config);
							
							if ($this->upload->do_upload($field)) {
								$upload_data = $this->upload->data();
								$data[$field] = $upload_data['file_name'];
								// $this->resize_promo_banners('800', '500', 'page/', $upload_data['file_name']);
							} else {
								$this->session->set_flashdata('error', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Error uploading ' . $field . ': ' . $this->upload->display_errors() . '</p>');
								redirect('admin/home_centerbanners_hotel/edit/' . $id);
							}
						}
					} else {
						// Handle regular text fields
						$data[$field] = $this->input->post($field);
					}
				} 

				/* echo '<pre>';
				print_r($data);
				echo '</pre>';
				exit(); */

				if ($count == 0) {
					$this->home_centerbanner_hotel_m->add_home_centerbanners_hotel($data); 
				} else { 
					$this->home_centerbanner_hotel_m->edit_home_centerbanners_hotel_by_hotel($hotel_id, $data);
				}


				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Home center Banner Berhasil di Edit</p>');
				
				redirect('admin/home_centerbanners_hotel');
			
			}
		} 
		
		$this->data['subview'] = 'admin/home_centerbanners_hotel/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 brand
	public function delete($id) {

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

		//delete brand
		$this->home_centerbanner_hotel_m->delete($id); 

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

	public function delete_image($field_name = NULL) {

		if($field_name == NULL) { show_404(); }

		// Get hotel_id from session
		$hotel_id = $this->session->userdata('hotel_id');
		
		//get image file name for deletion
		$this->db->select($field_name)->from('home_centerbanners_hotel')->where('hotel_id', $hotel_id);
		$result = $this->db->get()->row();
		
		if($result && isset($result->$field_name)) {
			$image = $result->$field_name;
			
			//Delete the actual image file from server. FCPATH is codeigniter base path
			if(file_exists(FCPATH .'/uploads/page/'. $image)) {
				unlink(FCPATH .'/uploads/page/'. $image);
			}

			//Delete image field from database
			$data = array( 
				$field_name => '',
			);

			$this->db->where('hotel_id', $hotel_id);
			$this->db->update('home_centerbanners_hotel', $data);	

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Gambar Berhasil di Hapus</p>');
		} else {
			$this->session->set_flashdata('error', '<br><p style="background:red; color:white; padding:5px; font-weight:bold;">Gambar tidak ditemukan</p>');
		}
		
		redirect('admin/home_centerbanners_hotel'); 
	}

	public function delete_static_banner($image_number = NULL) {

		if($image_number == NULL) { show_404(); }

		//get image file name for deletion
		$this->db->select('banner1_image, banner2_image, banner3_image, banner4_image, banner5_image, banner6_image, banner7_image, banner8_image, banner9_image, banner10_image, banner11_image, banner12_image, banner13_image, banner14_image');
		$this->db->from('home_centerbanners_hotel');
		$this->db->where('id_home_centerbanners_hotel', 1);
		$this->db->where("hotel_id",$this->session->userdata('hotel_id'));
		switch($image_number) {
			case '1':
				$image = $this->db->get()->row()->banner1_image; 
				break;	
			case '2':
				$image = $this->db->get()->row()->banner2_image; 
				break;	
			case '3':
				$image = $this->db->get()->row()->banner3_image; 
				break;	
			case '4':
				$image = $this->db->get()->row()->banner4_image; 
				break;	
			case '5':
				$image = $this->db->get()->row()->banner5_image; 
				break;	
			case '6':
				$image = $this->db->get()->row()->banner6_image; 
				break;	
			case '7':
				$image = $this->db->get()->row()->banner7_image; 
				break;	
			case '8':
				$image = $this->db->get()->row()->banner8_image; 
				break;	
		}


		//Delete the actual image file from server. FCPATH is codeigniter base path
		unlink(FCPATH .'/uploads/page/'. $image);

		//Delete image field from database
		$data = array( 
			'banner' . $image_number . '_image' => '',
		);

		$this->db->where('id_home_centerbanners_hotel', 1);
		$this->db->where("hotel_id",$this->session->userdata('hotel_id'));
		$this->db->update('home_centerbanners_hotel', $data);	

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


	}

	//admin resize images
	private function resize_promo_banners($width, $height, $upload_path, $image_name) { 

		 $this->load->library('image_lib');
         //image resizing (SMALL IMAGE)
         $config['image_library'] = 'gd2';
         $config['source_image'] = './uploads/'. $upload_path . $image_name;
         $config['new_image'] = './uploads/'. $upload_path;
         $config['create_thumb'] = FALSE;
         $config['maintain_ratio'] = TRUE;
         $config['width'] = $width;
         //$config['height'] = $height;
         $this->image_lib->initialize($config);
         $this->image_lib->resize();
	}
		
}

https://t.me/RX1948 - 2025