load->model('Blog_model'); } function list_blog() { if($this->session->userdata('id')==""){redirect('admin/login');} $data['blo']=$this->Blog_model->list_blogs(); $this->load->view('admin/blog/list',$data); } function add_blog() { if($this->session->userdata('id')==""){redirect('admin/login');} if($this->input->post("add")) { $Title=$this->input->post("Title"); $tags=$this->input->post("tags"); $Detail=$this->input->post("Detail"); $tg =array(); foreach($tags as $key1=>$val1) { $tg[]=$tags[$key1]; } $tg_res= implode(', ', $tg); //make directory if (!is_dir('uploads/blog')) { mkdir('./uploads/blog', 0777, TRUE); } $valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions $path = 'uploads/blog/'; // upload directory if($_FILES['Image']) { $img = $_FILES['Image']['name']; $tmp = $_FILES['Image']['tmp_name']; // get uploaded file's extension $ext = strtolower(pathinfo($img, PATHINFO_EXTENSION)); // can upload same image using rand function $final_image = "Image".rand(1000,1000000).$img; // check's valid format if(in_array($ext, $valid_extensions)) { $path = $path.strtolower($final_image); if(move_uploaded_file($tmp,$path)) { $table="blog"; $rvalue=array( 'name'=>$Title, 'intro'=>$Detail, 'image'=>$path, 'tags'=>$tg_res, 'cdate'=>date('Y-m-d H:i:s'), 'cby'=>$this->session->userdata('id'), 'status'=>1); $result=$this->commonsql_model->insert_table($table,$rvalue); } } } if($result) { $this->session->set_userdata('suc','successfully added'); redirect('admin/blog'); } else { $this->session->set_userdata('err','Please try again'); redirect('admin/blog'); } } $this->load->view('admin/blog/add'); } function edit_blog($id) { if($this->session->userdata('id')==""){redirect('admin/login');} if($this->input->post("edit")) { $Title=$this->input->post("Title"); $tags=$this->input->post("tags"); $Detail=$this->input->post("Detail"); $oldimage=$this->input->post("old_image"); $Image=$this->input->post("Image"); $tg =array(); foreach($tags as $key1=>$val1) { $tg[]=$tags[$key1]; } $tg_res= implode(', ', $tg); if($Image=="") { $simage=$oldimage; } if (!is_dir('uploads/blog')) { mkdir('./uploads/blog', 0777, TRUE); } $valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions $path = 'uploads/blog/'; // upload directory if($_FILES['Image']['tmp_name']) { $img = $_FILES['Image']['name']; $tmp = $_FILES['Image']['tmp_name']; // get uploaded file's extension $ext = strtolower(pathinfo($img, PATHINFO_EXTENSION)); // can upload same image using rand function $final_image = "Image".rand(1000,1000000).$img; // check's valid format if(in_array($ext, $valid_extensions)) { $simage = $path.strtolower($final_image); if(move_uploaded_file($tmp,$simage)) {}} } $tblname="blog"; $wheredata=(array('id'=>$id)); $values=array( 'name'=>$Title, 'intro'=>$Detail, 'image'=>$simage, 'tags'=>$tg_res, 'udate'=>date('Y-m-d H:i:s'), 'uby'=>$this->session->userdata('id'), ); $result=$this->commonsql_model->updateTable($tblname,$wheredata,$values); if($result) { $this->session->set_userdata('suc','successfully Updated'); redirect('admin/blog'); } else { $this->session->set_userdata('err','Please try again'); redirect('admin/blog'); } } $data['blo']=$this->Blog_model->list_blogs($id); $this->load->view('admin/blog/edit',$data); } function check_uncheck_blog() { $id=$_POST['id']; $value=$_POST['val']; $tblname="blog"; $where=array('id'=>$id); $update=array('status'=>$value); $results=$this->commonsql_model->updateTable($tblname,$where,$update); if($results) { echo "1"; } else { echo "2"; } } } ?>