Last active
February 6, 2019 07:20
-
-
Save bablukpik/8cd1a1f2b8c3dcbc2539359bd8ab18f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$this->db->query("alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'"); | |
echo $this->db->last_query(); | |
//Date Save like dd/mm/yy to database as follows: | |
$date = str_replace('/', '-', $this->input->post('tender_date')); | |
$date = date('Y-m-d', strtotime($date)); | |
$data['tender_date'] = date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('tender_date')))); | |
//Show date like 24th Nov 18, 9:52 AM as follows: | |
echo date("jS M y, G:i A", strtotime($row1->CRE_DT)) | |
//Data Display | |
<?php echo date('d/m/Y', strtotime($tbl_job_circular_a->circular_pub_date));?> | |
//admin_login.php | |
class Admin_login extends CI_Controller { | |
static $model = array('myModel'); | |
//static $helper = array('url','generalauthentication','userauthentication'); | |
const Title = 'Bablu Space'; | |
public function __construct(){ | |
parent:: __construct(); | |
$this->load->model(self::$model); | |
//$this->load->helper(self::$helper); | |
$this->load->library('form_validation'); | |
$this->load->library('upload'); | |
$this->load->library('image_lib'); | |
$admin_email_address = $this->session->userdata('admin_email_address'); | |
if($admin_email_address != NULL){ | |
redirect('super_admin'); | |
} | |
} | |
public function index() | |
{ | |
$this->load->view('admin/login'); | |
} | |
public function check_login(){ | |
$admin_email_address = $this->input->post('admin_email_address'); | |
$admin_password = $this->input->post('admin_password'); | |
$result = $this->myModel->check_login_info($admin_email_address, $admin_password); | |
if ($result) { | |
/* | |
echo "<pree>"; | |
print_r ($result); | |
exit; | |
*/ | |
$sdata['admin_name'] = $result->admin_name; | |
$sdata['admin_email_address'] = $result->admin_email_address; | |
$sdata['admin_password'] = $result->admin_password; | |
$this->session->set_userdata($sdata); | |
redirect('super_admin'); | |
}else{ | |
$sdata['message'] = 'Username or password invalid'; | |
$this->session->set_userdata($sdata); | |
redirect('admin_login'); | |
} | |
} | |
} | |
//super_admin.php | |
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Super_admin extends CI_Controller { | |
public function __construct(){ | |
parent:: __construct(); | |
$admin_email_address = $this->session->userdata('admin_email_address'); | |
if($admin_email_address == NULL){ | |
redirect('admin_login'); | |
} | |
} | |
public function index() | |
{ | |
$this->load->view("admin/admin_master"); | |
} | |
public function logout() | |
{ | |
$this->session->unset_userdata("admin_name"); | |
$this->session->unset_userdata("admin_email_address"); | |
$this->session->unset_userdata("admin_password"); | |
$sdata["message"] = "You are successfully logout"; | |
$this->session->set_userdata($sdata); | |
redirect("admin_login"); | |
} | |
public function add_category() | |
{ | |
$data["add_category_form"] = $this->load->view("admin/add_category_form", "", true); | |
$this->load->view("admin/admin_master", $data); | |
} | |
public function save_category() | |
{ | |
if (!empty($this->input->post("categategory_name"))) { | |
$data["categategory_name"] = $this->input->post("categategory_name"); | |
}else{ | |
$sdata["message"] = "<span style='color:red;'>Please give categategory name</span>"; | |
$this->session->set_userdata($sdata); | |
redirect("super_admin/add_category"); | |
} | |
$data["category_description"] = $this->input->post("category_description"); | |
$data["category_status"] = $this->input->post("category_status"); | |
$result = $this->myModel->save_category_info($data); | |
if ($result) { | |
$sdata["message"] = "Category added successfully"; | |
$this->session->set_userdata($sdata); | |
redirect("super_admin/add_category"); | |
}else{ | |
$sdata["message"] = "Category not added"; | |
$this->session->set_userdata($sdata); | |
redirect("super_admin/add_category"); | |
} | |
} | |
} | |
//01// | |
public function chck(){ | |
$oldpass = $this->input->post('oldpass'); | |
$where = array("pass" => $oldpass); | |
$result = $this->M_organize_profile_manage->findorgallByUser('data_admin', $where); | |
if($result){ | |
echo TRUE; | |
}else{ | |
echo FALSE; | |
} | |
} | |
//02// | |
public function passwordupdate (){ | |
$logInUser = $this->session->userdata('name'); | |
$data['pass'] = $this->input->post('newpassword'); | |
$where = array('name' => $logInUser); | |
$this->db->update('data_admin', $data, $where); | |
redirect('form/view'); | |
} | |
//03// | |
public function login(){ | |
$name = $this->input->post('name'); | |
$pass = $this->input->post('pass'); | |
$logInDetails = $this->M_organize_profile_manage->login('data_admin', $name); | |
if( !empty($logInDetails) && $logInDetails->pass == $pass){ | |
$this->session->set_userdata(array('name' => $name)); | |
redirect('form/view'); | |
}else{ | |
$this->session->set_userdata(array('msg' => "You are not valid user")); | |
redirect('form/panel'); | |
} | |
} | |
//04// | |
public function logout (){ | |
$this->session->set_userdata(array('name' => "")); | |
redirect('form/panel'); | |
} | |
//05// | |
public function store(){ | |
$data['name'] = $this->input->post('name'); | |
$data['mobile_no'] = $this->input->post('mobile'); | |
$data['interested_country'] = $this->input->post('country'); | |
$data['purposes'] = $this->input->post('purpose'); | |
$data['interested_course'] = $this->input->post('course'); | |
$data['city'] = $this->input->post('city'); | |
$data['dhaka_dist'] = $this->input->post('dhaka_dist'); | |
$data['chittagong_dist'] = $this->input->post('chittagong_dist'); | |
$data['sylhet_dist'] = $this->input->post('sylhet_dist'); | |
$data['rangpur_dist'] = $this->input->post('rangpur_dist'); | |
$data['rajshahi_dist'] = $this->input->post('rajshahi_dist'); | |
$data['khulna_dist'] = $this->input->post('khulna_dist'); | |
$data['barisal_dist'] = $this->input->post('barisal_dist'); | |
$data['mymensingh_dist'] = $this->input->post('mymensingh_dist'); | |
$data['edu_qualification'] = $this->input->post('education'); | |
//$data['fil_up_date'] = date('Y-m-d H:i:s'); | |
$dt = new DateTime('now', new DateTimezone('Asia/Dhaka')); | |
$data['fil_up_date'] = $dt->format('Y-m-d g:i:s'); | |
$this->session->set_userdata(array('alert' =>"<h2 align='center' style='color:#00a9e7'>Your data has been submitted successfully!</h2>")); | |
$result = $this->M_organize_profile_manage->save('student_form', $data); | |
if($result){ | |
redirect('form/success'); | |
}else{ | |
redirect('form/failure'); | |
} | |
} | |
//06// Array pass to view | |
$data['notification_data']['user_name'] = isset($user_name)?$user_name:''; | |
$data['notification_data']['user_type'] = isset($user_type)?$user_type:''; | |
$data['notification_data']['user_fullname'] = isset($user_fullname)?$user_fullname:''; | |
//OR | |
$collection = $this->mongo_model->selectCollectiondb(); | |
$collection= iterator_to_array($collection); | |
$user_list = array(); | |
foreach ($collection as $users) { | |
$data['_id']=$users['_id']; | |
$data['firstname']=$users['firstname']; | |
$data['lastname']=$users['lastname']; | |
$data['email']=$users['email']; | |
$data['password']=$users['password']; | |
$user_list[$users['_id']]['firstname'] = $users['firstname']; | |
$user_list[$users['_id']]['lastname'] = $users['lastname']; | |
$user_list[$users['_id']]['email'] = $users['email']; | |
$user_list[$users['_id']]['password'] = $users['password']; | |
} | |
$data['user_list'] = $user_list; | |
print_r($data); | |
$this->load->view('show_user',$data); | |
//OR | |
$data_part13['header3_item'][] = (object) array('title' => 'first image 1' , 'img' => 'https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQoshslL3aMNzG50708domqPSA4ouPjk_wA7jCpVRUH3k8zVdn9' ); | |
$this->load->view('part_1_3', $data_part13); | |
//How to set an array in session in codeigniter? | |
// this code: | |
$used_questions=$questions_for_test[$difficulty_level][$question_id]; | |
$this->session->set_userdata('used_questions',$used_questions); | |
// is the same as this code | |
$this->session->set_userdata('used_questions',$questions_for_test[$difficulty_level][$question_id]); | |
//In view | |
// fetch the stored copy first. | |
$used_questions = $this->session->userdata('used_questions'); | |
if(!is_array($used_questions)) $used_questions = array(); | |
// note the [] | |
$used_questions[] = $questions_for_test[$difficulty_level][$question_id]; | |
$this->session->set_userdata('used_questions',$used_questions); | |
//v.03 | |
public function postUpdate() | |
{ | |
$id = $this->input->post('id'); | |
$data['title'] = $this->input->post('title'); | |
$data['image_title'] = $this->input->post('image_title'); | |
$data['date_and_time'] = $this->input->post('date_and_time'); | |
$data['description'] = $this->input->post('description'); | |
$config['upload_path'] = './Images/Post_image/'; | |
$config['allowed_types'] = 'gif|jpg|png'; | |
$config['max_size'] = '0'; | |
$config['max_width'] = '0'; | |
$config['max_height'] = '0'; | |
$config['file_name'] = time(); | |
$file_field = 'image'; | |
/// IMAGE UPLOAD ACTION | |
$this->upload->initialize($config); | |
if ($this->upload->do_upload($file_field)) | |
{ | |
/// ERORR SHOW FOR IMAGE UPLOAD | |
$image_data = $this->upload->data(); | |
$data['image'] = $image_data['file_name']; | |
$source_image = 'Images/Post_image/'.$data['image']; | |
$destination = 'Images/Post_image500_347/'.$data['image']; | |
$frame_width = 500; | |
$frame_height = 347; | |
resize_with_white_space($source_image, $destination, $frame_width, $frame_height); | |
$model = $this->M_user_post_manage->findById($id); | |
$only_image = $model->image; | |
if(!empty($only_image)){ | |
unlink('./Images/Post_image/'.$only_image); | |
unlink('./Images/Post_image500_347/'.$only_image); | |
} | |
} | |
$this->M_user_post_manage->update($data, $id); | |
$blogDetails = $this->M_user_post_manage->findById($id); | |
$datas['blog_title'] = $blogDetails->title; | |
$blogDetailsChk = $this->M_search_table->findByBlogId($id); | |
if(!empty($blogDetailsChk)){ | |
$this->M_search_table->updateBlog($datas, $id); | |
} else{ | |
$datas['blog_id'] = $id; | |
$datas['blog_user_id'] = $blogDetails->user_id; | |
$this->M_search_table->save($datas); | |
} | |
redirect('generalUserHome/addPost'); | |
} | |
//v.04 | |
public function postDelete($id) | |
{ | |
$model = $this->M_user_post_manage->findById($id); | |
$only_image = $model->image; | |
if(!empty($only_image)){ | |
unlink('./Images/Post_image/'.$only_image); | |
unlink('./Images/Post_image500_347/'.$only_image); | |
} | |
$this->M_user_post_manage->destroy($id); | |
$this->M_search_table->destroyByBlockId($id); | |
redirect('generalUserHome/addPost'); | |
} | |
//Date Save to Database | |
$data['tender_date'] = date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('tender_date')))); | |
//File Upload using Upload Library with Manupulation | |
v.01 | |
public function insert_customer() { | |
$data=array(); | |
$this->load->library('upload'); | |
$config['upload_path'] = './uploads/Customerbiodata/'; | |
$config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|doc|docx'; | |
$config['max_size'] = '10000'; | |
$this->upload->initialize($config); | |
$data['Customer_Code']= $this->input->post('Customer_id', TRUE); | |
$data['Customer_Name']= $this->input->post('cus_name', TRUE); | |
$data['Customer_Type']= $this->input->post('type', TRUE); | |
$data['Customer_Address']= $this->input->post('address', TRUE); | |
$data['Gurantor_Name']= $this->input->post('gur_name', TRUE); | |
$data['Gurantor_Contact']= $this->input->post('gur_contact', TRUE); | |
$data['Gurantor_Address']= $this->input->post('gur_address', TRUE); | |
$data['permanent_address']= $this->input->post('praddress', TRUE); | |
$data['disttrict']= $this->input->post('district', TRUE); | |
$data['Country_SlNo']= $this->input->post('country', TRUE); | |
$data['Customer_Phone']= $this->input->post('phone', TRUE); | |
$data['Customer_Mobile']= $this->input->post('mobile',true); | |
$data['Customer_OfficePhone']= $this->input->post('office_phone',true); | |
$data['Customer_Email']= $this->input->post('email',true); | |
$data['Customer_Web']= $this->input->post('web',true); | |
$data['Customer_Credit_Limit']= $this->input->post('credit',true); | |
$data['Customer_brunchid']= $this->session->userdata("BRANCHid"); | |
$data['AddBy']= $this->session->userdata("FullName"); | |
$data['AddTime']= date("Y-m-d h:i:s"); | |
$data['notes']= $this->input->post('notes',true); | |
//Image Resize | |
if ($this->upload->do_upload('photo')){ | |
$images1 = $this->upload->data(); | |
$data['customerpic'] = $images1['file_name']; | |
$config['image_library'] = 'gd2'; | |
$config['source_image'] = $images1['full_path']; //get original image | |
$config['maintain_ratio'] = FALSE; | |
$config['width'] = 113; | |
$config['height'] = 142; | |
$this->load->library('image_lib', $config); | |
if (!$this->image_lib->resize()) { | |
$this->handle_error($this->image_lib->display_errors()); | |
} | |
} | |
$this->upload->do_upload('biodata'); | |
$images = $this->upload->data(); | |
$data['biodata'] = $images['file_name']; | |
$this->mt->save_data('tbl_customer',$data); | |
$this->load->view('Administrator/ajax/customer'); | |
} | |
v.02 | |
//Image Resize / Manupulation with thumb | |
if ( $this->upload->do_upload('em_photo')){ | |
$images = $this->upload->data(); | |
$data['Employee_Pic_org'] = $images['file_name']; | |
$config['image_library'] = 'gd2'; | |
$config['source_image'] = $this->upload->upload_path.$this->upload->file_name; | |
$config['new_image'] = 'uploads/'.'employeePhoto_thum/'.$this->upload->file_name; | |
$config['maintain_ratio'] = FALSE; | |
$config['width'] = 115; | |
$config['height'] = 137; | |
$this->load->library('image_lib', $config); | |
$this->image_lib->resize(); | |
$data['Employee_Pic_thum'] = $this->upload->file_name; | |
} | |
$this->mt->save_data('tbl_employee', $data); | |
//End upload library | |
//Batch insert | |
public function save_renterFM_data($renterFMData){ | |
for($i = 0; $i < count($renterFMData['family_member_name']); $i++) | |
$batch[] = array( "renter_id" =>$renterFMData['renter_id'], | |
"family_member_name" => $renterFMData['family_member_name'][$i], | |
"family_member_age" => $renterFMData['family_member_age'][$i], | |
"family_member_job" => $renterFMData['family_member_job'][$i], | |
"family_member_phone" => $renterFMData['family_member_phone'][$i] | |
); | |
return $this->db->insert_batch(self::$renter_familymember, $batch); | |
} | |
//Batch Update | |
$this->db->update_batch('mytable', $data, 'title'); | |
N.B, The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key. | |
i.e, | |
//renter_familymember Table | |
$renterFMData['family_member_id'] = $this->input->post('family_member_id'); | |
$renterFMData['family_member_name'] = $this->input->post('family_member_name'); | |
$renterFMData['family_member_age'] = $this->input->post('family_member_age'); | |
$renterFMData['family_member_job'] = $this->input->post('family_member_job'); | |
$renterFMData['family_member_phone'] = $this->input->post('family_member_phone'); | |
//Form array type data fetch | |
for($i = 0; $i < count($renterFMData['family_member_name']); $i++) { | |
$batch[] = array( | |
"family_member_id" => $renterFMData['family_member_id'][$i], | |
"family_member_name" => $renterFMData['family_member_name'][$i], | |
"family_member_age" => $renterFMData['family_member_age'][$i], | |
"family_member_job" => $renterFMData['family_member_job'][$i], | |
"family_member_phone" => $renterFMData['family_member_phone'][$i] | |
); | |
} | |
//die(var_dump($batch)); | |
$renterFMInsertId = $this->MyModel->updateByBatch('renter_familymember','family_member_id',$batch); | |
And Model: | |
//Batch Update | |
public function updateByBatch($table, $where, $batch){ | |
return $this->db->update_batch($table, $batch, $where); | |
} | |
//Update OR Save | |
//v.01 | |
$response = $this->mt->findById('rawPurchaseReturn','rawPuPID', $data1['rawPuPID']); | |
if ($response){ | |
$insert_id = $this->mt->update('rawPurchaseReturn', 'rawPuPID', $data1['rawPuPID'], $data1); | |
}else{ | |
$insert_id = $this->mt->save('rawPurchaseReturn', $data1); | |
} | |
//Get URL Parameter | |
class="<?php echo (current_url()==base_url()) ? 'active':''?>" | |
class="<?=(current_url()==base_url('home/contact')) ? 'active':''?>" | |
class="<?php if($this->uri->segment(1)=="publicity"){echo "active";}?>" | |
//Delete | |
$this->db->delete(); | |
$this->db->_error_message(); | |
$this->db->affected_rows(); | |
i.e, | |
$this->db->delete($this->table,array('id'=>$id)); | |
if ($this->db->_error_message()) { | |
$result = 'Error! ['.$this->db->_error_message().']'; | |
} else if (!$this->db->affected_rows()) { | |
$result = 'Error! ID ['.$id.'] not found'; | |
} else { | |
$result = 'Success'; | |
} | |
//Image unlink | |
if(!empty($renter_photo)){ | |
$reterData['renter_photo'] = $renter_photo; | |
//unlink the file | |
$result = $this->MyModel->FindById('renter','renter_id', $renter_id); | |
if($result){ | |
unlink('uploads/'.$result->renter_photo); | |
//unlink('publicity/images/publicity_img/'.str_replace("_thumb","", $result->publicity_photo)); | |
} | |
} | |
//Insert Method Manual | |
function insertDataB($data, $tableName) | |
{ | |
// values | |
$arr_values = array_map(function($v){ | |
return "'$v'"; | |
}, array_values($data)); | |
$values = implode(", ",$arr_values); | |
// fields | |
$fields = implode(',', array_keys($data)); | |
// query | |
$sql = "INSERT INTO $tableName ($fields) VALUES ($values)"; | |
return $this->db->query($sql); | |
} | |
// Update Method Manual | |
function updateDataBablu($tableName, $data, $condition) | |
{ | |
// data | |
$arr_data = array_map(function($k, $v){ | |
return "$k='$v'"; | |
}, array_keys($data), array_values($data)); | |
$data_str = implode(", ",$arr_data); | |
// condition | |
$arr_con = array_map(function($k, $v){ | |
return "$k='$v'"; | |
}, array_keys($condition), array_values($condition)); | |
$con_str = implode(" AND ",$arr_con); | |
// query | |
$sql = "UPDATE $tableName SET $data_str WHERE $con_str"; | |
return $this->db->query($sql); | |
} | |
//Group Concate | |
$checkExist = $this->db->query("SELECT GROUP_CONCAT(TRIM(leading 0 FROM s.OFFICIALNUMBER))OFFICIALNUMBER | |
FROM overweight ov LEFT JOIN sailor s ON ov.SAILOR_ID = s.SAILORID | |
WHERE ov.DATE_OF_RETURN = '$dateOfReturn' AND ov.SAILOR_ID IN ($sailors)")->row("OFFICIALNUMBER"); | |
//--------------------------------Bootstrap Alert Message-------------------------------- | |
/** | |
* @method Bootstrap Alert Message | |
* @access public | |
* @author Bablu <[email protected]> | |
* @return Alert Message | |
*/ | |
function alert_message($type = '', $msg = '', $msg_prefix = '') | |
{ | |
$alert = ''; | |
if($type == 'success' and $msg) | |
{ | |
$alert = '<div class="alert alert-success alert-dismissible fade in"> | |
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> | |
<p><strong>' .($msg_prefix ? $msg_prefix : 'Success!'). '</strong> ' .$msg. '.</p> | |
</div>'; | |
} | |
else if($type == 'info' and $msg) | |
{ | |
$alert = '<div class="alert alert-info alert-dismissible fade in"> | |
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> | |
<p><strong>' .($msg_prefix ? $msg_prefix : 'Info!'). '</strong> ' .$msg. '.</p> | |
</div>'; | |
} | |
else if($type == 'warning' and $msg) | |
{ | |
$alert = '<div class="alert alert-warning alert-dismissible fade in"> | |
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> | |
<p><strong>' .($msg_prefix ? $msg_prefix : 'Warning!'). '</strong> ' .$msg. '.</p> | |
</div>'; | |
} | |
else if($type == 'danger' and $msg) | |
{ | |
$alert = '<div class="alert alert-danger alert-dismissible fade in"> | |
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> | |
<p><strong>' .($msg_prefix ? $msg_prefix : 'Failure!'). '</strong> ' .$msg. '.</p> | |
</div>'; | |
} | |
else | |
{ | |
$alert = '<div class="alert alert-info alert-dismissible fade in"> | |
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> | |
<p><strong>Alert!</strong> The Alert Type & Message parameters are required.</p> | |
</div>'; | |
} | |
return $alert; | |
} | |
//--------------------------------End Bootstrap Alert Message-------------------------------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment