defined('BASEPATH') OR exit('No direct script access allowed'); class MY_Controller extends CI_Controller { protected $the_view = ''; protected $data1 = array(); protected $template; public function __construct() { parent::__construct(); //$this->render('vwIndex'); $this->load->model('Common_function_model', 'common'); $this->load->model('Site_settings_model', 'siteSettings'); $this->data['is_CKEditor'] = FALSE; $this->data['is_GRID'] = TRUE; $this->load->model('Site_settings_model', 'setting'); $this->data['setting'] = $this->setting->get(1); /* Get a site setting */ $this->load->model('Main_category_model', 'main_category'); $this->data['main_categorys'] = $this->main_category->get_main_category(); $this->load->model('Product_model', 'product'); $this->data['menus']=$this->product->get_all_products_menu(); $this->data['siteSettings'] = $this->siteSettings->get_site_by_id(1,'*'); $this->autologin(); $this->data['totalItem']=0; $this->data['totalAmount']=0; $product_data = array(); if($this->session->userdata('f_id')) { $product_data = $this->common->check_to_cart($this->session->userdata('f_id')); } else { if(isset($_COOKIE['cart_items'])) { $product_data = unserialize($_COOKIE['cart_items']); } } $total_cost=0; $gran_total=0; if($product_data!="") { foreach ($product_data as $product) { $total_cost = $product['price']* $product['quantity']; /* $total_cost = $product['shipping_cost']; $total_cost = $product['price']* $product['quantity']; if($total_cost < 300) { $total_cost = $total_cost+$product['shipping_cost']; }*/ $gran_total= $gran_total+$total_cost; //($total_cost*1.05); } } $this->data['totalAmount'] =$gran_total; $this->data['totalItem'] = count($product_data); //$this->data['recaptcha'] = $this->recaptcha->getWidget(); //$this->data['recaptcha_script'] = $this->recaptcha->getScriptTag(); } protected function render($the_view = NULL, $template = 'front_master') { // if ($the_view == "vwHome") // { // $template="index_master"; // } if ($template == 'json' || $this->input->is_ajax_request()) { $this->output->set_content_type("application/json")->set_status_header(200)->set_output($this->data); } elseif (is_null($template)) { $this->load->view($the_view, $this->data); } else { $this->data['view_content'] = (is_null($the_view)) ? '' : $this->load->view($the_view, $this->data, TRUE); $this->load->view('templates/' . $template . '_view', $this->data); } } /** set a page title */ public function setPageTitle($page_title) { $this->data['page_title'] = $page_title; } // protected function getSql() // { // return $sql_details = array( // 'user' => $this->db->username, // 'pass' => $this->db->password, // 'db' => $this->db->database, // 'host' => $this->db->hostname // ); // } public function autologin() { if (!$this->session->userdata('f_id')) { $email = $this->input->cookie('user_email'); $pass = $this->input->cookie('user_password'); $remember_me = $this->input->cookie('remember_me'); if ($remember_me) { $result = $this->db->get_where('user', array( 'email' => $email, 'is_active' => 1 ))->result_object(); if (!empty($result) && count($result)) { $result = $result[0]; $dbPass = $this->encryption->decrypt($result->password); if ($dbPass == $pass) { $user_data = array( 'f_id' => $result->id, 'f_name' => $result->first_name, 'f_email' => $result->email, 'f_phone_number' => $result->phone_number, 'f_is_login' => true ); $this->session->set_userdata($user_data); } } } } } } class Auth_Controller extends MY_Controller { //protected $data = array(); public function __construct() { parent::__construct(); $this->load->library('form_validation'); $this->load->model('Site_settings_model', 'setting'); /** get iste setting */ $this->data['setting'] = $this->setting->get(1); /* Get a site setting */ } protected function render($the_view = NULL, $template = 'admin_master') { parent::render($the_view, $template); } } class Admin_Controller extends MY_Controller { protected $data = array(); public function __construct() { parent::__construct(); if(!$this->ion_auth->logged_in()) { redirect('admin','refresh'); } $this->load->library('form_validation'); $this->load->model('Site_settings_model', 'setting'); /** get iste setting */ $this->data['setting'] = $this->setting->get(1); /* Get a site setting */ } protected function render($the_view = NULL, $template = 'admin_master') { parent::render($the_view, $template); } } if (!defined('BASEPATH')) exit('No direct script access allowed'); class Home extends My_Controller { public function __construct() { parent::__construct(); date_default_timezone_set('Asia/Dubai'); } public function index() { $pageInfo = get_page('Home'); $this->data['title'] = $pageInfo->page_title; $this->data['mTitle'] = $pageInfo->meta_title; $this->data['keyword'] = $pageInfo->meta_keyword; $this->data['desc'] = $pageInfo->meta_description; $this->data['banners'] = $this->db->order_by('display_order', 'asc')->get_where('banner', array('is_active' => 1))->result_object(); $this->render('vwHome'); } public function aboutUs() { $pageInfo = get_page('About Us'); $this->data['title'] = $pageInfo->page_title; $this->data['mTitle'] = $pageInfo->meta_title; $this->data['keyword'] = $pageInfo->meta_keyword; $this->data['desc'] = $pageInfo->meta_description; $this->data['about'] = $pageInfo; $this->data['teams'] = $this->db->order_by('display_order', 'asc')->get_where('team', array('is_active' => 1))->result_object(); $this->data['clients'] = $this->db->order_by('display_order', 'asc')->get_where('clients', array('is_active' => 1))->result_object(); $this->render('vwAboutUs'); } public function news($slug='') { if (!empty($slug)) { /* display news detail page & check if slug is correct */ $newsDetail = $this->db->get_where('news', array('is_active' => 1, 'blog_slug' => $slug))->row(); if (!empty($newsDetail)) { $this->data['title'] = $newsDetail->blog_title; $this->data['mTitle'] = $newsDetail->meta_title; $this->data['keyword'] = $newsDetail->meta_keyword; $this->data['desc'] = $newsDetail->meta_description; $this->data['news'] = $newsDetail; $this->render('vwNewsDetail'); } else { redirect(base_url('news'),'refresh'); } } else { //display news listing page $pageInfo = get_page('News'); $this->data['title'] = $pageInfo->page_title; $this->data['mTitle'] = $pageInfo->meta_title; $this->data['keyword'] = $pageInfo->meta_keyword; $this->data['desc'] = $pageInfo->meta_description; $this->data['news'] = $this->db->order_by('blog_date', 'desc')->get_where('news', array('is_active' => 1))->result_object(); $this->render('vwNewsListing'); } } public function contact() { $pageInfo = get_page('Contact Us'); $this->data['title'] = $pageInfo->page_title; $this->data['mTitle'] = $pageInfo->meta_title; $this->data['keyword'] = $pageInfo->meta_keyword; $this->data['desc'] = $pageInfo->meta_description; $this->render('vwContact'); } public function careers() { $pageInfo = get_page('Careers'); $this->data['title'] = $pageInfo->page_title; $this->data['mTitle'] = $pageInfo->meta_title; $this->data['keyword'] = $pageInfo->meta_keyword; $this->data['desc'] = $pageInfo->meta_description; $this->data['careers'] = $pageInfo; $this->render('vwCareer'); } public function contactEnquiry() { $status = array(); if ($this->input->is_ajax_request()) { $this->form_validation->set_rules('name', 'name', 'trim|required|xss_clean'); $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email|xss_clean'); $this->form_validation->set_rules('number', 'number', 'trim|required|numeric|xss_clean'); $this->form_validation->set_rules('message', 'message', 'trim|required|xss_clean'); // $this->form_validation->set_rules('g-recaptcha-response', 'google recaptcha', 'trim|xss_clean|required|callback_check_captcha'); if ($this->form_validation->run() === FALSE) { $status = array('error' => true, 'type' => 'field'); $status = array_merge($this->form_validation->error_array(), $status); } else { $object = array( 'enquiry_name' => $this->input->post('name'), 'email' => $this->input->post('email'), 'phone_number' => $this->input->post('number'), 'message' => $this->input->post('message'), 'created_at' => date('Y-m-d H:i:s'), ); $this->db->insert('enquiry', $object); if ($this->db->affected_rows()) { $isMailSend = $this->Email_sending->contact(); $status = array( 'error' => false, 'mail' => $isMailSend, 'msg' => 'Thank you! We will revert back to you asap.' ); } else { $status = array( 'error' => true, 'type' => 'final', 'msg' => 'Something went wrong' ); } } } else { $status = array( 'error' => true, 'type' => 'final', 'msg' => 'Something went wrong' ); } echo json_encode($status); } public function careerEnquiry() { $status = array(); if ($this->input->is_ajax_request()) { $this->form_validation->set_rules('name', 'name', 'trim|required|xss_clean'); $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email|xss_clean'); $this->form_validation->set_rules('phone', 'phone', 'trim|required|numeric|xss_clean'); $this->form_validation->set_rules('uploadcv', 'cv', 'trim|xss_clean|callback_check_upload_cv'); $this->form_validation->set_rules('message', 'message', 'trim|required|xss_clean'); // $this->form_validation->set_rules('g-recaptcha-response', 'google recaptcha', 'trim|xss_clean|required|callback_check_captcha'); if ($this->form_validation->run() === FALSE) { $status = array('error' => true, 'type' => 'field'); $status = array_merge($this->form_validation->error_array(), $status); } else { $object = array( 'name' => $this->input->post('name'), 'email' => $this->input->post('email'), 'phone_number' => $this->input->post('phone'), 'message' => $this->input->post('message'), 'created_at' => date('Y-m-d H:i:s'), ); $uploadPath = './uploads/cv'; if ($_FILES['uploadcv']['size']) { $fileName = 'cv_'.time().'.'.pathinfo($_FILES['uploadcv']['name'], PATHINFO_EXTENSION); if (move_uploaded_file($_FILES['uploadcv']['tmp_name'], $uploadPath.'/'.$fileName)) { $object['cv_path'] = $uploadPath.'/'.$fileName; } } $this->db->insert('careers_enquiry', $object); if ($this->db->affected_rows()) { $isMailSend = $this->Email_sending->career($object['cv_path']); $status = array( 'error' => false, 'mail' => $isMailSend, 'msg' => 'Thank you! We will revert back to you asap.' ); } else { $status = array( 'error' => true, 'type' => 'final', 'msg' => 'Something went wrong' ); } } } else { $status = array( 'error' => true, 'type' => 'final', 'msg' => 'Something went wrong' ); } echo json_encode($status); } public function newsletter() { $status = array(); if ($this->input->is_ajax_request()) { $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email|xss_clean'); // $this->form_validation->set_rules('g-recaptcha-response', 'google recaptcha', 'trim|xss_clean|required|callback_check_captcha'); if ($this->form_validation->run() === FALSE) { $status = array('error' => true, 'type' => 'field'); $status = array_merge($this->form_validation->error_array(), $status); } else { //check if email exist $email = $this->input->post('email'); $isEmailExist = $this->db->get_where('subscription', array('email_address' => $email))->num_rows(); if (!$isEmailExist) { $object = array( 'email_address' => $this->input->post('email'), 'is_active' => 1, 'created_at' => date('Y-m-d H:i:s'), ); $this->db->insert('subscription', $object); if ($this->db->affected_rows()) { //$isMailSend = $this->Email_sending->contact(); $isMailSend = true; $status = array( 'error' => false, 'mail' => $isMailSend, 'msg' => 'Thank you for subscribing.' ); } else { $status = array( 'error' => true, 'type' => 'final', 'msg' => 'Something went wrong' ); } } else { $status = array( 'error' => true, 'type' => 'final', 'msg' => 'Email is already subscribed' ); } } } else { $status = array( 'error' => true, 'type' => 'final', 'msg' => 'Something went wrong' ); } echo json_encode($status); } public function services() { $pageInfo = get_page('Services'); $this->data['title'] = $pageInfo->page_title; $this->data['mTitle'] = $pageInfo->meta_title; $this->data['keyword'] = $pageInfo->meta_keyword; $this->data['desc'] = $pageInfo->meta_description; $this->data['servicePage'] = $pageInfo; $this->data['serviceCat'] = $this->db->query("SELECT a.*, (SELECT count(*) FROM services as b WHERE b.service_id = a.id) as totalCount FROM service_categories as a WHERE a.is_active = 1 HAVING totalCount > 0 ORDER BY display_order")->result_object(); $this->render('vwServices'); } public function check_upload_cv() { // $allowedExts = array("jpeg", "jpg", "png", "JPG", "JPEG", "PNG"); // $allowedTypes = array(IMAGETYPE_PNG, IMAGETYPE_JPEG); $allowedExts = array("pdf", "PDF", "doc", "DOC", "docx", "DOCX"); $allowedTypes = array('application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'); if ($_FILES['uploadcv']['size']) { //if image selected $extension = pathinfo($_FILES["uploadcv"]["name"], PATHINFO_EXTENSION); $detectedType = mime_content_type($_FILES['uploadcv']['tmp_name']); $type = $_FILES['uploadcv']['type']; if (!in_array($detectedType, $allowedTypes)) { $this->form_validation->set_message('check_upload_cv', 'The CV content is invalid'); return FALSE; } elseif (filesize($_FILES['uploadcv']['tmp_name']) > 2000000) { $this->form_validation->set_message('check_upload_cv', 'The CV file size shoud not exceed 2MB!'); return FALSE; } elseif (!in_array($extension, $allowedExts)) { $this->form_validation->set_message('check_upload_cv', "The CV file extension is invalid"); return FALSE; } else { return TRUE; } } else { $this->form_validation->set_message('check_upload_cv', "Please select your CV"); return FALSE; } } public function check_captcha($str) { $secret = captcha_secret_key; $verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$str}"); $captcha_success=json_decode($verify); if ($captcha_success->success==false) { $this->form_validation->set_message('check_captcha', "Please select captcha again"); return FALSE; } else { return TRUE; } } /*public function send_email() { $res = $this->Email_sending->test(array( 'to' => 'alfaizm19@gmail.com', 'from' => 'alfaizm19@gmail.com', 'name' => "Alfaiz", 'email' => 'alfaizm19@gmail.com', 'phone' => '9876543210', 'msg' => 'test msg' )); echo "
";
print_r($res);
}*/
}
?>
if (!defined('BASEPATH'))
exit('No direct script access allowed');
if (!function_exists('get_css')) {
/**
* Create a link from a js array or string
* HTTP_ASSETS_PATH_ADMIN_CSS set a base path of js folder ex assets/client/js admin or client as u want
* @param Array $css accept a array
* @param Sting $css accept a signal string
* @param String $prifix use both of them admin and client admin/client as u want
* @return void
*/
function get_css($css = NULL, $prifix = 'client') {
// $CI =& get_instance();
$get_css = "";
//$path = ($prifix == 'admin') ? HTTP_ASSETS_PATH_ADMIN_CSS : HTTP_ASSETS_PATH_CLIENT_CSS ;
$ci = & get_instance();
$ci->config->load('assets', TRUE);
$path = $ci->config->item($prifix);
if (isset($css) && !empty($css) && !is_null($path)) {
if (is_array($css)) {
foreach ($css as $css_key => $css_value) {
$get_css .= '' . "\n";
}
} else {
$get_css .= '' . "\n";
}
}
return $get_css;
}
}
if (!function_exists('get_js')) {
/**
* Create a link from a js array or string
* HTTP_ASSETS_PATH_ADMIN_JS set a base path of js folder ex assets/client/js admin or client as u want
* @param Array $js accept a array
* @param Sting $js accept a signal string
* @param String $prifix use both of them admin and client admin/client as u want
* @return void
*/
function get_js($js = NULl, $prifix = 'client') {
// $CI =& get_instance();
$get_js = "";
//$path = ($prifix == 'admin') ? HTTP_ASSETS_PATH_ADMIN_JS : HTTP_ASSETS_PATH_CLIENT_JS ;
$ci = & get_instance();
$ci->config->load('assets', TRUE);
$path = $ci->config->item($prifix);
if (isset($js) && !empty($js)) {
if (is_array($js)) {
foreach ($js as $js_key => $js_value) {
$get_js .= '' . "\n";
}
} else {
$get_js .= '' . "\n";
}
}
return $get_js;
}
}
if (!function_exists('get_input')) {
/**
* When server side validation is used , redirect to curent page to refill to input value to used
* postdata key to use a session
* @param String $key input name
* @param string $default input defalult value
*/
function get_input($key = NULl, $default = '') {
$ci = & get_instance();
$ci->load->library('session');
$poatdata = $ci->session->flashdata('postdata');
if (array_key_exists($key, $ci->input->post())) {
return $ci->input->post($key);
}
if ($key !== NULL AND ! empty($poatdata)) {
if (array_key_exists($key, $poatdata)) {
return $poatdata[$key];
}
}
return $default;
}
}
if (!function_exists('get_checkbox')) {
/**
* Rechecked a check box
* @param String $key input name
* @param string $value checkbox box value
* @return void
*/
function get_checkbox($key = NULl, $value = '', $default = '') {
$ci = & get_instance();
$ci->load->library('session');
$poatdata = $ci->session->flashdata('postdata');
if ($default) {
return "checked";
}
if (!isset($poatdata[$key]) && !isset($_POST[$key])) {
return FALSE;
}
if ((is_array($poatdata[$key]) && in_array($value, $poatdata[$key], TRUE) ) OR isset($_POST[$key])) {
return "checked";
} else {
if ($key !== NULL AND ! empty($poatdata)) {
if (array_key_exists($key, $poatdata) AND $poatdata[$key] !== "" AND ! is_array($poatdata[$key])) {
return "checked";
}
}
}
/** if $default is true then is checked */
return $default;
}
}
if (!function_exists('has_error')) { /**
* Check a server side form validation and input need to display a error
* @param String $key as input name
* @param String $default
* @return NUll
*/
function has_error($key = NULl, $default = NULL) {
$ci = & get_instance();
$ci->load->library('session');
$errors = $ci->session->flashdata('error');
if (is_array($errors) && !empty($errors)) {
if (array_key_exists($key, $errors)) {
return $errors[$key];
}
}
return $default;
}
}
if (!function_exists('display_flash')) {
/**
* Get a flash message from name
* @param String $name
* @return void
*/
function display_flash($name) {
$CI = & get_instance();
if ($CI->session->flashdata($name)) {
$flash = $CI->session->flashdata($name);
if (is_array($flash['message'])) {
$msg = '';
} else {
return '';
}
}
}
}
if (!function_exists('set_flash')) {
/**
* set a falsh message
* @param String $name
* @param String $message_type calss name ex danger,success,info,warning
* @param String $message Only singale OR multipal as array message
* @param Array $message Only singale string OR multipal as array message
* @return void
*/
function set_flash($name, $message_type, $message) {
$CI = & get_instance();
$CI->session->set_flashdata($name, array('message_type' => $message_type, 'message' => $message));
}
}
if (!function_exists('is_menu_active')) {
/**
* Set a active class fore curen controller
* @param String $controller
* @return void
*/
function is_menu_active($controller, $class = NUll) {
$CI = & get_instance();
if (is_array($controller) && in_array($CI->router->fetch_class(), $controller)) {
$controller_class = $CI->router->fetch_class();
return ($controller_class == array_key_exists($controller_class, $controller)) ? config_item('active_class') . ' ' . $class : '';
}
$controller_class = $CI->router->fetch_class();
return ($controller_class == $controller) ? config_item('active_class') . ' ' . $class : '';
}
}
if (!function_exists('get_subnav')) {
/**
* Set a active class fore curen controller
* @param String $controller
* @return void
*/
function get_subnav($method, $text = NUll) {
$CI = & get_instance();
$controller_class = $CI->router->fetch_class();
$li = '
Severity: echo $severity; ?>
Message: echo $message; ?>
Filename: echo $filepath; ?>
Line Number: echo $line; ?>
if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>Backtrace:
foreach (debug_backtrace() as $error): ?> if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
File: echo $error['file'] ?>
Line: echo $error['line'] ?>
Function: echo $error['function'] ?>
Severity: echo $severity; ?>
Message: echo $message; ?>
Filename: echo $filepath; ?>
Line Number: echo $line; ?>
if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>Backtrace:
foreach (debug_backtrace() as $error): ?> if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
File: echo $error['file'] ?>
Line: echo $error['line'] ?>
Function: echo $error['function'] ?>