EVOLUTION-NINJA
Edit File: Master.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Master extends CI_Controller { public function __construct() { parent::__construct(); ini_set('max_execution_time', 30000); //$this->check_islogin(); //check user login session exist or not $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT'); $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); $this->output->set_header('Pragma: no-cache'); $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); $this->load->model('yarn_model'); $this->load->model('marketing_model'); $this->load->model('planning_yarn'); $this->load->model('planning_shade'); $this->load->model('madeups_model'); //$this->load->library('user_agent'); $this->load->model('vendor_model'); $this->load->model('outsource_model'); $this->load->model('store_model'); $this->load->model('pkg_list_model'); $this->load->model('design_weaving_model'); $this->load->model('country_model'); $this->load->library('form_validation'); date_default_timezone_set('asia/kolkata'); } public function log() { echo $_REQUEST['name'];exit; echo "login"; } public function add_print() { $this->load->view('master_new/add_print'); } public function index() { $this->load->view('master_new/addCountry'); } public function addCountry() { $data = array( 'country_name' => $this->input->post('country_name') ); // Call the add_country method from the CountryModel $result = $this->country_model->add_country($data); // Check the result and send a response if ($result) { $responseData = array('success' => true, 'data' => $data); echo json_encode($responseData); } else { $error = $this->db->error(); // Get the last database error log_message('error', 'Failed to add country. ' . $error['message']); // Log the error $responseData = array('success' => false, 'message' => 'Failed to add country. ' . $error['message']); echo json_encode($responseData); } } public function fetchCountries() { // Fetch countries from the model $countries = $this->country_model->get_all_countries(); // Convert the data to JSON and send it to the client echo json_encode($countries); } public function rex_change() { $id1=$this->input->post("as"); $table='country_table'; $where=array('id'=>$id1); $d = $this->vendor_model->get_customerdata($table,$where); if($d->rex == '1'){ $data=array('rex' =>'0'); $where=array('id'=>$id1); $this->marketing_model->update_data($where,$table,$data); echo 'Rex Removed Sucessfully...'; } else{ $data=array('rex' =>'1'); $where=array('id'=>$id1); $this->marketing_model->update_data($where,$table,$data); echo 'Rex Added Sucessfully...'; } } public function edit_country($countryId) { // Get country data by ID $countryData = $this->country_model->getCountryById($countryId); // Check if the property 'id' exists in the object if (isset($countryData->id)) { // Pass the data to the view $data['id'] = $countryData->id; // Load the view $this->load->view('master_new/edit_country',$data); } else { // Handle the case where 'id' is not defined show_error('Country ID not found.'); } } public function updateCountry() { $data = array( 'country_name' => $this->input->post('edited_country_name') ); $country_id = $this->input->post('id'); $result = $this->country_model->update_country($country_id, $data); if ($result) { echo json_encode(array('success' => true)); } else { echo json_encode(array('success' => false, 'error' => 'Failed to update country.')); } } public function deleteCountry($id) { // Handle the delete functionality based on the country ID $this->country_model->delete_country($id); echo json_encode(['status' => 'success']); } //Port public function addPort() { if ($_SERVER["REQUEST_METHOD"] == "POST") { // Form was submitted, handle the port addition $portName = $this->input->post('port_name'); $countryId = $this->input->post('country_id'); // Check if the port already exists if ($this->country_model->portExists($portName)) { $response = array('success' => false, 'message' => 'Port name already exists.'); } else { // Add the port if ($this->country_model->addPort($countryId, $portName)) { $response = array('success' => true, 'message' => 'Port added successfully!'); } else { $response = array('success' => false, 'message' => 'Error adding port.'); } } // Send the JSON response $this->output->set_content_type('application/json')->set_output(json_encode($response)); } else { // Load the view with the form $data['country'] = $this->country_model->get_all_countries(); $this->load->view('master_new/addPort', $data); } } // public function getPorts() { // $ports = $this->country_model->getPorts(); // Fetch ports from the model // $response = array('rows' => $ports); // echo json_encode($response); // } public function getPorts() { // Fetch ports from the model $ports = $this->country_model->getPorts(); $response = array('rows' => $ports); echo json_encode($response); } public function edit_port($port_id) { // Fetch the port details from the model $data['port'] = $this->country_model->get_port_by_id($port_id); // Load the view for editing $this->load->view('master_new/edit_port', $data); } public function update_port() { $portId = $this->input->post('port_id'); $portName = $this->input->post('port_name'); // Check if data is received if ($portId !== null && $portName !== null) { // Load the necessary model // Update the port in the model $this->country_model->update_port($portId, $portName); // Send a JSON response indicating success $response = array('success' => true, 'message' => 'Port updated successfully'); echo json_encode($response); } else { // Send a JSON response indicating failure $response = array('success' => false, 'error' => 'Data not received'); echo json_encode($response); } } public function deletePort($id) { // Assuming you have a model method to delete a port $result = $this->country_model->deletePort($id); // Check if the deletion was successful if ($result) { $response = array('success' => true, 'message' => 'Port deleted successfully'); } else { $response = array('success' => false, 'message' => 'Failed to delete port'); } // Return the response as JSON $this->output ->set_content_type('application/json') ->set_output(json_encode($response)); } //product category public function index1() { $this->load->view('master_new/product_category'); } public function insertCategory() { // Retrieve form data $data = array( 'product_type' => $this->input->post('productType'), 'product_category' => $this->input->post('productCategory'), 'hs_code' => $this->input->post('hsCode'), 'dbk_si' => $this->input->post('dbksi'), 'dbk_desc' => $this->input->post('dbkDescription') ); // Insert data into the database $result = $this->country_model->insertCategory($data); // Print the last executed query // echo "Last Query: " . $this->db->last_query(); if ($result) { // Record inserted successfully echo json_encode("successfully added"); } else { // Error inserting record echo "Error inserting record"; } } public function fetchproducts() { $data = $this->country_model->getProducts(); echo json_encode($data); } public function edit_product($rowId) { // Get product details based on $rowId $product = $this->country_model->get_product_by_id($rowId); // Check if the product exists if (!$product) { // Handle product not found, redirect to product list or show an error redirect('master/product_list'); } // Pass product data to the view $data['product'] = $product; // Load your edit_product view or perform necessary operations $this->load->view('master_new/edit_product', $data); } public function updateProduct() { // Get the POST data $postData = $this->input->post(); // Assuming you have validation and sanitation logic here // Example: You can use CodeIgniter form validation library $this->form_validation->set_rules('product_category', 'Product Category', 'required'); $this->form_validation->set_rules('product_type', 'Product Type', 'required'); $this->form_validation->set_rules('hs_code', 'HS Code', 'required'); $this->form_validation->set_rules('dbk_si', 'DBK SI', 'required'); $this->form_validation->set_rules('dbk_desc', 'DBK Description', 'required'); if ($this->form_validation->run() == FALSE) { // If validation fails, send an error message $response = array('success' => false, 'message' => validation_errors()); } else { // Update the product using the model $result = $this->country_model->updateProduct($postData); if ($result) { // If the update is successful, send a success message $response = array('success' => true, 'message' => 'Product updated successfully'); } else { // If the update fails, send an error message $response = array('success' => false, 'message' => 'Failed to update product'); } } // echo "Last Query: " . $this->db->last_query(); // Send the response as JSON $this->output->set_content_type('application/json')->set_output(json_encode($response)); } public function deleteProduct($productId) { // Call the model method to delete the product $deleteResult = $this->country_model->deleteProduct($productId); // Check if the deletion was successful if ($deleteResult) { // Send a success response $response = array('success' => true, 'message' => 'Data Deleted Successfully'); } else { // Send an error response $response = array('success' => false, 'message' => 'Error deleting data'); } // Return the JSON response echo json_encode($response); } }