D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
realadss
/
www
/
partymaker.in
/
application
/
models
/
Filename :
Common_model.php
back
Copy
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Common_model extends CI_Model { public $data = array(); public function __construct() { parent::__construct(); $this->base_url = base_url(); $this->admin_session_name = 'admin_session'; $this->data_not_availabel ='N/A'; $this->last_insert_id = ''; $this->per_page = 50; $this->limit_per_page = 50; $this->path_logo = 'assets/uploads/logo/'; $this->path_gallery = 'assets/uploads/gallery/'; $this->path_home = 'assets/uploads/home/'; $this->path_blog = 'assets/uploads/blog/'; $this->path_banner = 'assets/uploads/banner/'; $this->path_cms = 'assets/uploads/cms_images/'; $this->path_home_gallery = 'assets/uploads/home_gallery/'; $this->path_slider_image = 'assets/uploads/slider_image/'; $this->path_service = 'assets/uploads/service/'; $this->path_games = 'assets/uploads/games/'; $this->path_artist = 'assets/uploads/artist/'; $this->path_resume = 'assets/uploads/resume/'; $this->common_setting = $this->get_count_data_manual('common_setting',array('id'=>1),1); } public function get_menu() { $menu_arr = array(); $this->db->join('cms_page','cms_page.id = menu.cms_page_id','left'); $menu = $this->get_count_data_manual('menu',array('menu.status'=>'Active'),2,'menu.*,cms_page.id as c_id,cms_page.status as c_status,cms_page.alias'); $this->db->join('cms_page','cms_page.id = submenu.cms_page_id','left'); $sub_menu = $this->get_count_data_manual('submenu',array('submenu.status'=>'Active'),2,'submenu.*,cms_page.id as c_id,cms_page.status as c_status,cms_page.alias'); $sub_menu_temp = array(); if(isset($sub_menu) && $this->is_array_count($sub_menu)) { foreach($sub_menu as $sub_menu_val) { if($sub_menu_val['c_status'] == 'Active' && $sub_menu_val['alias'] !='') { $sub_menu_temp[$sub_menu_val['menu_id']][] = $sub_menu_val; } } } if(isset($menu) && $this->is_array_count($menu)) { foreach($menu as $menu_val) { if(isset($sub_menu_temp[$menu_val['id']])) { $menu_val['sub_menu_arr'] = $sub_menu_temp[$menu_val['id']]; } $menu_arr[] = $menu_val; } } return $menu_arr; } public function check_login_admin() { $status = 'error'; $message = "Please try again"; $user_name = trim($this->input->post('username')); $password = md5(trim($this->input->post('password'))); $row_data = $this->common_model->get_count_data_manual('admin_user',array('password'=>$password,"(user_name='$user_name' or email_id='$user_name')"),1); if(isset($row_data) && $row_data !='' && is_array($row_data) && count($row_data) > 0) { $row_data['first_name'] = 'Admin'; $this->common_model->set_session_data_comm($this->common_model->admin_session_name,$row_data); $message = "Logged in successfully."; $status = 'success'; } else { $message = "Invalid User name or Password"; } $data = array('status'=>$status,'message'=>$message); return $data; } function get_ddr($name='') { $priority_arr = array(array('id'=>'High','priority_name'=>'High'),array('id'=>'Moderate','priority_name'=>'Moderate'),array('id'=>'Low','priority_name'=>'Low'),array('id'=>'Routine','priority_name'=>'Routine')); $issue_resolve_arr = array(array('id'=>'Yes'),array('id'=>'No'),array('id'=>'N/A')); if($$name) { return $$name; } else { return ''; } } function last_query() { return $this->db->last_query(); } public function checkLogin($type='redirect') { $admin_session_name = $this->session->userdata($this->admin_session_name); if(!$admin_session_name || $admin_session_name =="" && count($admin_session_name) ==0 ) { $base_url = base_url(); if($type == 'redirect') { redirect($base_url.'admin'); } else if($type == 'return') { return false; } } else { if($type == 'return') { return true; } } } public function checkLogin_dash() { $return = $this->checkLogin('return'); if($return == true ) { $base_url = base_url(); redirect($base_url.'admin/common_setting'); } } public function get_admin_data() { return $this->get_session_data_comm($this->admin_session_name); } public function get_session_data_comm($session_name = '') { $data_return = ''; if($session_name !='') { $data_return = $this->session->userdata($session_name); } return $data_return; } public function set_session_data_comm($session_name = '',$user_data='') { if($session_name !='' && $user_data !='') { $this->session->set_userdata($session_name,$user_data); } } function set_common_where($where_arra ='') { if($where_arra !='' && is_array($where_arra) && count($where_arra) >0) { foreach($where_arra as $key=>$val) { if(is_numeric($key)) { $this->db->where($val); } else { $this->db->where($key,$val); } } } else if($where_arra !='') { $this->db->where($where_arra); } } function getCurrentDate($dformat='Y-m-d H:i:s') { return date($dformat); } // for get Count data, single row, multiple row function get_count_data_manual($table,$where_arra='',$flag_count_data = 0,$select_f ='',$order_by='',$page='',$limit='',$is_delet_field = 1,$disp_query = "") { // flag_count_data 1 means 1 single row fetch // flag_count_data 2 for multiple row fetch // flag_count_data 0 for get count of total data if($table !='') { // set the where clouse for delete filed, check is deleted or not // set where condition $this->set_common_where($where_arra); if(isset($select_f) && $select_f !='') { $this->db->select($select_f); } if($flag_count_data == 0) { $query_generated_org = $this->db->get_compiled_select($table); $query = $this->db->query($query_generated_org); $count_data = $query->num_rows(); return $count_data; } else { // set for order by clouse if(isset($order_by) && $order_by !='') { $this->db->order_by($order_by); } // setting the limit of recourd if($flag_count_data==1) { $this->db->limit(1); } else { if($page !='' && $limit =="") { $limit = $this->limit_per_page; } //if($page !='' && $limit !='') if($page !='' && is_numeric($page) && $limit !='' && is_numeric($limit)) { $this->start = (($page - 1) * $limit); $this->db->limit($limit,$this->start); } } // for echo query if($disp_query ==1) { $this->db->get_compiled_select($table); } $query_generated = $this->db->get_compiled_select($table); $query = $this->db->query($query_generated); $count_data = $query->num_rows(); $temp_array = ''; if($count_data == 0) { return ''; } //$query = $this->db->get($table); else if($flag_count_data == 1) { unset($temp_array); $temp_array = $query->row_array(); } else { unset($temp_array); $temp_array = $query->result_array(); } return $temp_array; } } else { return ''; } } // for common insert, update and multiple insert function update_insert_data_common($table='',$data_array='',$where_arra='',$flag_update=1,$limit=1) { // flag_update 1 means update // flag_update 2 for multiple insert // flag_update 0 for single insert $return = false; if($table !='' && $data_array !='' && is_array($data_array) && count($data_array) > 0) { $db_debug = $this->db->db_debug; $this->db->db_debug = FALSE; $this->db->trans_start(); // for update code if($flag_update == 1) { // set where clouse if($where_arra !='' && is_array($where_arra) && count($where_arra) >0) { foreach($where_arra as $key=>$val) { if(is_numeric($key)) { $this->db->where($val); } else { $this->db->where($key,$val); } } } else if($where_arra !='') { $this->db->where($where_arra); } // set limit for update if($limit == 1) { $this->db->limit(1); } $return = $this->db->update($table,$data_array); } else { // for insert multiple record insert if($flag_update == 2) { $return = $this->db->insert_batch($table,$data_array); } else { // for single insert $return = $this->db->insert($table,$data_array); $this->last_insert_id = $this->db->insert_id(); } } $this->db->trans_complete(); $this->db->db_debug = $db_debug; } return $return; } // for delete common function function data_delete_common($table='',$where_arra='',$limit=0,$permenent_delete='') { $return = false; /*if($permenent_delete !='') { $this->permenent_delete = $permenent_delete; }*/ if($table !='') { // set where condition $this->set_common_where($where_arra); if($limit == 1) { $this->db->limit(1); } // if permenent delete no then update and not delete permenent delete /*if($this->is_delete_fild !='' && $this->permenent_delete =='no') { $data_array = array($this->is_delete_fild =>'Y'); $return = $this->db->update($table,$data_array); } else {*/ // permenent delete data $return = $this->db->delete($table); } return $return; } function displayDate($date = '',$dformat='F j, Y h:i A')// Y-m-d h:i:s { if($date =='0000-00-00' || $date =='0000-00-00 00:00:00') { return $this->data_not_availabel; } else if($date !='' && $dformat !='') { if(strlen($date) == 10) { $dformat = str_replace('h:i A','',$dformat); } $strtime = strtotime($date); $date_retuen = date($dformat,$strtime); return $date_retuen; } else { return $this->data_not_availabel; } } function array_to_ddr_str($data_arr=array(),$default_selected='',$display_col='',$id_col='id') { $return_str = ''; if(isset($data_arr) && $data_arr !='' && is_array($data_arr) && count($data_arr) > 0) { if($default_selected !='' && !is_array($default_selected)) { $default_selected = explode(',',$default_selected); } foreach($data_arr as $data_arr_val) { $selected = ''; if(isset($default_selected) && $default_selected !='' && is_array($default_selected) && in_array($data_arr_val[$id_col],$default_selected)) { $selected = 'selected'; } else if(isset($default_selected) && $default_selected !='' && $default_selected == $data_arr_val[$id_col]) { $selected = 'selected'; } $return_str.="<option ".$selected." value=\"".$data_arr_val[$id_col]."\">".$data_arr_val[$display_col]."</option>"; } } return $return_str; } function generate_dropdown($table_name='',$display_col='',$default_selected='',$id_col='id') { $return_str = ''; if($table_name!='' && $display_col !='' && $id_col !='') { $data_arr = $this->get_count_data_manual($table_name,'',2); if($default_selected !='' && !is_array($default_selected)) { $default_selected = explode(',',$default_selected); } if(isset($data_arr) && $data_arr !='' && is_array($data_arr) && count($data_arr) > 0) { foreach($data_arr as $data_arr_val) { $selected = ''; if(isset($default_selected) && $default_selected !='' && is_array($default_selected) && in_array($data_arr_val[$id_col],$default_selected)) { $selected = 'selected'; } else if(isset($default_selected) && $default_selected !='' && $default_selected == $data_arr_val[$id_col]) { $selected = 'selected'; } $return_str.="<option ".$selected." value='".$data_arr_val[$id_col]."'>".$data_arr_val[$display_col]."</option>"; } } } return $return_str; } public function rander_pagination($url='',$count=0,$set_limit = '') { $return_page = ''; if($set_limit=='') { $set_limitvar = $this->per_page; } else { $set_limitvar = $set_limit; } if($url !='' && $count !='' && $count > 0) { $this->load->library('pagination'); $config = array();//$this->getconfingValue('config_pag'); $config['cur_tag_open'] = '<li class="active page-item"><a href="#" class="page-link">'; $config['cur_tag_close'] = '</a></li>'; $config['full_tag_open'] = '<ul class="pagination">'; $config['cur_tag_open'] = '<li class="active page-item"><a href="#" class="page-link">'; $config['cur_tag_close'] = '</li>'; $config['first_tag_open'] = '<li class="page-item">'; $config['first_tag_close'] = '</li>'; $config['prev_tag_open'] = '<li class="page-item">'; $config['prev_tag_close'] = '</li>'; $config['num_tag_open'] = '<li class="page-item">'; $config['num_tag_close'] = '</li>'; $config['data_page_attr'] = 'class="page-link"'; $config['use_page_numbers'] = true; $config['next_tag_open'] = '<li class="page-item">'; $config['next_tag_close'] = '</li>'; $config['last_tag_open'] = '<li class="page-item">'; $config['last_tag_close'] = '</li>'; $config['base_url'] = $this->base_url.$url; $config['per_page'] = $set_limitvar; $config['total_rows'] = $count; $this->pagination->initialize($config); $return_page = $this->pagination->create_links(); $return_page ='<div style="margin-top:10px"><nav style="display:table;margin:0 auto;text-align:center">'.$return_page.'</nav></div>'; } return $return_page; } function valueFromId($table_name='',$arry_id='',$clm_value='',$id_clm='id',$return_type = 'str',$delimetor=',') { $return_arr =''; if($table_name !='' && $arry_id !='' && $clm_value !='' && $id_clm !='') { if(!is_array($arry_id)) { $arry_id = explode($delimetor,$arry_id); } $this->db->where_in($id_clm,$arry_id); $data_arr = $this->get_count_data_manual($table_name,'',2,$clm_value); if(isset($data_arr) && $data_arr !='' && is_array($data_arr) && count($data_arr) > 0) { $temp_arr = array(); foreach($data_arr as $data_arr_val) { $temp_arr[] = $data_arr_val[$clm_value]; } if($return_type =='str') { $return_arr = implode(', ',$temp_arr); } else { $return_arr = $temp_arr; } } } return $return_arr; } function is_local_url() { $host = $_SERVER['HTTP_HOST']; if($host =='localhost' || strpos($host,'localhost') !== false) { return true; } else { return false; } } public function common_send_email($to_array,$subject,$message,$cc_array= '',$bcc_array ='') { $config = array( 'protocol' => 'mail', 'mailtype' => 'html', 'charset' => 'iso-8859-1', 'wordwrap' => TRUE ); $this->load->library( 'email' ,$config);// , $config //for authenticate email $this->email->set_newline("\r\n"); $from_email = 'test@gmail.org'; $this->email->from($from_email); $this->email->to($to_array); if(isset($cc_array) && $cc_array !="") { $this->email->cc($cc_array); } if(isset($bcc_array) && $bcc_array !="") { $this->email->bcc($bcc_array); } if(isset($attachment) && $attachment !="") { $this->email->attach($attachment); } $this->email->subject($subject); $this->email->message($message); $msg = 'Email sent.'; $base_url = base_url(); if($this->is_local_url()) { $fp = fopen("text.txt","a+"); // fwrite($fp,$from_email); if(isset($to_array) && is_array($to_array)) { fwrite($fp,implode(',',$to_array)); } else { fwrite($fp,$to_array); } if(isset($bcc_array) && is_array($bcc_array)) { fwrite($fp,implode(',',$bcc_array)); } else { fwrite($fp,$bcc_array); } fwrite($fp,$subject); fwrite($fp,$message); fclose($fp); } else { if($this->email->send()) { $msg = 'Email sent.'; } else { $msg = $this->email->print_debugger(); // show_error($this->email->print_debugger()); } // $msg = $this->email->print_debugger(); } return $msg; } function doUpload($file='',$path ='',$allowed_type='jpg|jpeg|png|gif') { $config['upload_path'] = $path; $config['allowed_types'] = $allowed_type; $config['encrypt_name'] = TRUE; $data = array(); $this->load->library('upload', $config); if ( ! $this->upload->do_upload($file)) { $data = array('status'=>'error','error_message' => $this->upload->display_errors()); } else { $dataup = array('upload_data' => $this->upload->data()); $data = array('status'=>'success','file_name'=>$dataup['upload_data']['file_name']); } return $data; } public function change_password_process() { $status = 'error'; $message = "Please try again"; $old_password = md5(trim($this->input->post('old_password'))); $new_password = md5(trim($this->input->post('new_password'))); $confirm_password = md5(trim($this->input->post('confirm_password'))); $admin_row = $this->common_model->get_admin_data(); $user_id = $admin_row['id']; $table_name = 'admin_user'; $where = array('id'=>$user_id,'password'=>$old_password); $count = $this->common_model->get_count_data_manual($table_name,$where,0); if($count > 0) { $data_array = array( 'password'=>$new_password ); $where_ins = array('id'=>$user_id); $resp = $this->common_model->update_insert_data_common($table_name,$data_array,$where_ins,1); if($resp) { $message = "Password changed successfully."; $status = 'success'; } else { $message = "Some error Occured, please try again"; } } else { $message = "Old password is wrong"; } $data = array('status'=>$status,'message'=>$message); return $data; } public function is_array_count($arr = array()) { $return = false; if(isset($arr) && is_array($arr) && count($arr) > 0) { $return = true; } return $return; } }