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/serbaantik.com/public_html/application/controllers/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/serbaantik.com/public_html/application/controllers/admin/Brands.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Brands extends Admin_Controller 
{
		//this property is used for validating existing brand title on call back edit brand
		private $brand_current_id = NULL; 

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

			if (!in_array('partners', $this->allowed_sections)) redirect('admin/dashboard'); 

			$this->load->model('brand_m');
			$this->load->model('product_m'); 
		}
			
		//this is to list all brands
		public function index() 
		{
				if (isset($_POST['submit'])) 
				{
						//store image information to configuration table
						$data = array(
								'brand_title' => $this->security->xss_clean($this->input->post('brand_title')),
						);
						$this->db->where('id_configuration', 1);
						$this->db->update('configuration', $data); 

						$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Partnes Landing Page Edit Successful</p>');
				}

				//get landingpage banner image, description and link
				$this->db->select('brand_title')->from('configuration')->where('id_configuration', 1);
				$this->data['brand_landingpage'] = $this->db->get()->row();

				//pagination in action. 100 results per page
				$this->load->library('pagination');

				$config = array();
				$this->load->helper('pagination_helper');
				$config = pagination_format();
				$config['base_url'] = base_url() . 'admin/brands/index';
				$config['total_rows'] = $this->brand_m->record_count(); 
				$config['per_page'] = 100;
				$config['uri_segment'] = 4;

				$this->pagination->initialize($config);
				$this->data['brands'] = $this->brand_m->get_all_brands($config['per_page'], 
				$this->uri->segment($config['uri_segment']));  

				//load view
				$this->data['subview'] = 'admin/brands/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 brand 
		public function add() 
		{
				$this->data['brands'] = $this->brand_m->get_new();

				//get ordering number and display at add form
				$this->db->select_max('priority')->from('brands');
				$current_priority = $this->db->get()->row()->priority;
				if($current_priority == NULL) 
				{
						$this->data['brands']->priority = 1;	
				} 
				else 
				{
						$this->data['brands']->priority = $current_priority + 1;
				}
				
				//validation in action
				//validation check in action 
				$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

				$config = $this->brand_m->rules;
				$this->form_validation->set_rules($config); 

				//add $this because we use hmvc
				if($this->form_validation->run($this) == TRUE) 
				{
						$logo_filename = $this->logo_processing($_FILES['userfile2']['size']);

						$data = $this->table_data_processing(
							$this->input->post('brand_name'), 
							$this->input->post('status'), 
							$logo_filename, 
							$this->input->post('priority'), 
							$this->input->post('banner_link'));

						$this->brand_m->add_brand($data);

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

						redirect('admin/brands');
				} 
				
				$this->data['subview'] = 'admin/brands/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 edit brand in admin
		public function edit($id = NULL) 
		{
				if ($id == NULL) { show_404(); }

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

				$this->data['brands'] = $this->brand_m->get($id);	

				$this->brand_current_id = (int) $id;

				//validation check in action
				$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
				
				$config = $this->brand_m->rules;
				$this->form_validation->set_rules($config); 

				if($this->form_validation->run($this) == TRUE) 
				{	
						$logo_filename = $this->logo_processing($_FILES['userfile2']['size']);

						$data = $this->table_data_processing(
							$this->input->post('brand_name'), 
							$this->input->post('status'), 
							$logo_filename, 
							$this->input->post('priority'), 
							$this->input->post('banner_link'));

						$this->brand_m->edit_brand($id, $data); 

						$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Partner Edit Successful</p>');
						
						redirect('admin/brands/edit/' . $id);
				} 
			
				$this->data['subview'] = 'admin/brands/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->brand_m->count_exist($id);
				
				if ($count == 0) 
				{ 
						//page not exist
						show_404();
				}		

				//delete image from server
				//check if there is an existing image
				$this->db->select('image')->from('brands')->where('id_brands', (int) $id);
				$image = $this->db->get()->row();
				
				if ($image->image != '' || $image->image != NULL) 
				{	
						//Delete the actual image file from server. FCPATH is codeigniter base path
						unlink(FCPATH .'/uploads/brand/'. $image->image);
				}

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

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

		//logo upload processing
		private function logo_processing($logo_file_size) 
		{
				//check & processing image banner upload files	
				if ($logo_file_size !== 0) 
				{  	
						$config['upload_path'] = './uploads/brand/'; 
						$config['allowed_types'] = '*';  
						// $config['allowed_types'] = 'jpg|png|jpeg|webp'; 
						$config['max_size']	= '300';
						
						$this->load->library('upload', $config); 

						if ( ! $this->upload->do_upload('userfile2')) 
						{
								//echo $this->upload->display_errors(); die();
									
								$this->session->set_flashdata('logo_error', '<br>
									<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');

								if ($this->brand_current_id != NULL) {
									redirect('admin/brands/edit/' . $this->brand_current_id);
								} else {
									redirect('admin/brands/add');
								}
						} 
						else 
						{
								$logo = $this->upload->data();
								$logo_filename = $logo['file_name']; 	 

								return $logo_filename; 
						}	
				}
		}

		private function table_data_processing($brand_name, $status, $logo_filename, $priority, $banner_link) 
		{
				$data = array(
						'brand' 			=> $this->security->xss_clean($brand_name),
						'status' 			=> $status,
						'priority' 		=> $priority,
						'banner_link'	=> $this->security->xss_clean($banner_link)
				);

				//logo upload
				if (isset($logo_filename)) {
					$data['logo'] = $logo_filename; 
				} 

				return $data; 
		}

		//callback function validation add new brand
		//make it private by adding _
		public function _cek_existing_brand_title($str) {

			$num_rows = $this->brand_m->cek_existing_brand_title($str, $this->brand_current_id);  
			
			if ($num_rows != 0 ) {  
				$this->form_validation->set_message('_cek_existing_brand_title', 'Brand name already exist!');
				return FALSE;
			} else {
				return TRUE;  
			}
		}

		//To delete brand logo file from server, and from database
		public function delete_logo($id = NULL) 
		{ 
				$count = $this->brand_m->count_exist($id);

				if ($id == NULL || $count == 0) {	  
					redirect('admin/brands');
				}

				//get logo file name for deletion
				$this->db->select('logo')->from('brands')->where('id_brands', (int) $id);
				$image = $this->db->get()->row();

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

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

				$this->db->where('id_brands', (int) $id);
				$this->db->update('brands', $data);	

				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Logo Delete Successful</p>');
				
				redirect('admin/brands/edit/' . $id); 
		} 	
}

https://t.me/RX1948 - 2025