session->set_userdata('top_menu', 'System Settings'); $this->session->set_userdata('sub_menu', 'admin/print_headerfooter'); $data['title'] = 'SMS Config List'; $data['result'] = $this->setting_model->get_printheader(); $this->load->view('layout/header', $data); $this->load->view('admin/print_headerfooter/print_headerfooter', $data); $this->load->view('layout/footer', $data); } public function edit() { $message = ""; if (isset($_POST['type'])) { $is_required = $this->setting_model->check_haederimage($_POST['type']); $this->form_validation->set_rules('header_image', $this->lang->line('header') . " " . $this->lang->line('image'), 'trim|xss_clean|callback_handle_upload[' . $is_required . ']'); if ($_POST['type'] == 'staff_payslip') { $this->form_validation->set_rules('message', $this->lang->line('message'), 'required|trim|xss_clean'); $message = 'message'; }else if ($_POST['type'] == 'online_admission_receipt') { $this->form_validation->set_rules('admission_message', $this->lang->line('message'), 'required|trim|xss_clean'); $message = 'admission_message'; } else { $this->form_validation->set_rules('message1', $this->lang->line('message'), 'required|trim|xss_clean'); $message = 'message1'; } } if ($this->form_validation->run() == FALSE) { } else { if (isset($_FILES["header_image"]) && !empty($_FILES['header_image']['name'])) { $fileInfo = pathinfo($_FILES["header_image"]["name"]); $img_name = 'header_image.' . $fileInfo['extension']; if ($_POST['type'] == 'student_receipt') { $path = $this->setting_model->unlink_receiptheader(); $path1 = "uploads/print_headerfooter/student_receipt/" . $path; $url = FCPATH . $path1; if (file_exists($url)) { unlink($url); } move_uploaded_file($_FILES["header_image"]["tmp_name"], "./uploads/print_headerfooter/student_receipt/" . $img_name); } else if($_POST['type'] == 'online_admission_receipt') { $path = $this->setting_model->unlink_onlinereceiptheader(); $path1 = "uploads/print_headerfooter/online_admission_receipt/" . $path; $url = FCPATH . $path1; if (file_exists($url)) { unlink($url); } move_uploaded_file($_FILES["header_image"]["tmp_name"], "./uploads/print_headerfooter/online_admission_receipt/" . $img_name); } else { $path = $this->setting_model->unlink_payslipheader(); $path1 = "uploads/print_headerfooter/staff_payslip/" . $path; $url = FCPATH . $path1; if (file_exists($url)) { unlink($url); } move_uploaded_file($_FILES["header_image"]["tmp_name"], "./uploads/print_headerfooter/staff_payslip/" . $img_name); } $data = array('print_type' => $_POST['type'], 'header_image' => $img_name, 'footer_content' => $_POST[$message], 'created_by' => $this->customlib->getStaffID()); $this->setting_model->add_printheader($data); } $data = array('print_type' => $_POST['type'], 'footer_content' => $_POST[$message], 'created_by' => $this->customlib->getStaffID()); $this->setting_model->add_printheader($data); $this->session->set_flashdata('msg', '
' . $this->lang->line('success_message') . '
'); } redirect('admin/print_headerfooter'); } public function handle_upload($str, $is_required) { $image_validate = $this->config->item('image_validate'); $result = $this->filetype_model->get(); if (isset($_FILES["header_image"]) && !empty($_FILES['header_image']['name']) && $_FILES["header_image"]["size"] > 0) { $file_type = $_FILES["header_image"]['type']; $file_size = $_FILES["header_image"]["size"]; $file_name = $_FILES["header_image"]["name"]; $allowed_extension = array_map('trim', array_map('strtolower', explode(',', $result->image_extension))); $allowed_mime_type = array_map('trim', array_map('strtolower', explode(',', $result->image_mime))); $ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); $finfo = finfo_open(FILEINFO_MIME_TYPE); $mtype = finfo_file($finfo, $_FILES['header_image']['tmp_name']); finfo_close($finfo); if (!in_array($mtype, $allowed_mime_type)) { $this->form_validation->set_message('handle_upload', 'File Type Not Allowed'); return false; } if (!in_array($ext, $allowed_extension) || !in_array($file_type, $allowed_mime_type)) { $this->form_validation->set_message('handle_upload', 'Extension Not Allowed'); return false; } if ($file_size > $result->image_size) { $this->form_validation->set_message('handle_upload', $this->lang->line('file_size_shoud_be_less_than') . number_format($image_validate['upload_size'] / 1048576, 2) . " MB"); return false; } return true; } else { if ($is_required == 0) { $this->form_validation->set_message('handle_upload', 'Please choose a file to upload.'); return false; } else { return true; } } } }