%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class ImageGallery extends CI_Controller { /** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/<method_name> * @see https://codeigniter.com/user_guide/general/urls.html */ function __construct() { parent::__construct(); if((!isset($_SESSION['is_logged']))||($_SESSION['is_logged']==false)) { $_SESSION['redirect'] = base_url()."admin/Testimonial/view_testimonials"; redirect(base_url().'admin/login'); } //$this->load->model('gallery_category_model', 'category'); //$this->load->model('gallery_model', 'gallery'); $this->load->model('Common_Model'); } public function index() { $this->view_photos(); } public function do_upload($field_name, $upload_path= '', $file_name= '') { if($upload_path!=''){ $config['upload_path'] = $upload_path; } else{ $config['upload_path'] = './uploads'; } $config['allowed_types'] = 'jpeg|jpg|png|JPEG|JPG|PNG'; $config['max_size'] = '1500'; $config['max_width'] = '1024'; $config['max_height'] = '1024'; if($file_name!=''){ $config['file_name'] = $file_name; } $this->upload->initialize($config); if ( ! $this->upload->do_upload($field_name)) { $error = array('error' => $this->upload->display_errors()); // $this->load->view('upload_form', $error); return 0; } else { $data = array('upload_data' => $this->upload->data()); return $this->upload->data('file_name'); } } //**************************************************** CATEGORY **************************************************** public function add_category($id=0) { $data = array(); $data['data_string'] = ''; $categoryID = $id; echo '<script>console.log("add categroy")</script>'; if($id){ $records = $this->Common_Model->getSingleRecord('SH_GalleryCategories','*',array('GalleryCategoryID'=>$id)); echo '<script>console.log("update Gallery")</script>'; if(!$records){ show_404(); } else{ $data = array( 'GalleryCategoryID' => $records['GalleryCategoryID'], 'GalleryCategoryName' => $records['GalleryCategoryName'], 'GalleryCategoryOverview' => $records['GalleryCategoryOverview'], 'GalleryCategoryPriorityOrder' => $records['GalleryCategoryPriorityOrder'], 'Status' => $records['Status'], 'GalleryCategoryPageURL' => $records['GalleryCategoryPageURL'] ); } } $post=$this->input->post(); if($post){ echo '<script>console.log("post")</script>'; $this->form_validation->set_rules('GalleryCategoryName', 'Gallery Category Title', 'required'); $this->form_validation->set_rules('GalleryCategoryOverview', 'Gallery Category Overview', 'required'); $this->form_validation->set_rules('GalleryCategoryPageURL', 'Slug', 'required'); if ($this->form_validation->run() == FALSE) { echo '<script>console.log("Error in validating category")</script>'; //console.log("Error in validating doctor"); $this->load->view('admin/AddGalleryCategory'); exit; } else { if(isset($post['GalleryCategoryID'])){ $categoryID = $post['GalleryCategoryID']; } $insert_data = array( 'GalleryCategoryName' => $post['GalleryCategoryName'], 'GalleryCategoryOverview' => $post['GalleryCategoryOverview'], 'GalleryCategoryPriorityOrder' => $post['GalleryCategoryPriorityOrder'], 'Status' => $post['Status'], 'GalleryCategoryPageURL' => $post['GalleryCategoryPageURL'] ); $success = ''; echo '<script>console.log("'.$categoryID.'")</script>'; if($categoryID){ $success = $this->Common_Model->update_info('SH_GalleryCategories',$insert_data,'GalleryCategoryID',$categoryID); } else{ $success = $this->Common_Model->save_info('SH_GalleryCategories',$insert_data); echo '<script>console.log("'.$success.'")</script>'; } if($success){ redirect(base_url()."admin/ImageGallery/view_categories"); } } } $this->load->view('admin/AddGalleryCategory',$data); } public function update_category($id){ $this->add_category($id); } public function view_categories() { $data = array(); $data['records'] = $this->Common_Model->getCommonQuery('SH_GalleryCategories'); if(!$data){ show_404(); } $this->load->view('admin/ViewGalleryCategories',$data); } //**************************************************** ALBUM **************************************************** public function add_album($id=0) { $data = array(); $data['data_string'] = ''; $albumID = $id; echo '<script>console.log("add album")</script>'; if($id){ $records = $this->Common_Model->getSingleRecord('SH_GalleryAlbums','*',array('GalleryAlbumID'=>$id)); echo '<script>console.log("update Album")</script>'; if(!$records){ show_404(); } else{ $data = array( 'GalleryAlbumID' => $records['GalleryAlbumID'], 'GalleryAlbumName' => $records['GalleryAlbumName'], 'GalleryAlbumDescription' => $records['GalleryAlbumDescription'], 'GalleryAlbumCategory' => $records['GalleryAlbumCategory'], 'GalleryAlbumCover' => $records['GalleryAlbumCover'], 'GalleryAlbumPriorityOrder' => $records['GalleryAlbumPriorityOrder'], 'Status' => $records['Status'], 'GalleryAlbumPageURL' => $records['GalleryAlbumPageURL'] ); } } $post=$this->input->post(); if($post){ echo '<script>console.log("post")</script>'; $this->form_validation->set_rules('GalleryAlbumName', 'Gallery Album Title', 'required'); $this->form_validation->set_rules('GalleryAlbumOverview', 'Gallery Album Overview', ''); $this->form_validation->set_rules('GalleryAlbumPageURL', 'Slug', 'required'); if ($this->form_validation->run() == FALSE) { echo '<script>console.log("Error in validating album")</script>'; //console.log("Error in validating doctor"); $data['error'] = "Error in validating album"; $data['categories'] = $this->Common_Model->getCommonQuery('SH_GalleryCategories'); $this->load->view('admin/AddAlbum',$data); } else { $cover_pic =''; if($_FILES['GalleryAlbumCover']['name']){ $cover_pic = $this->do_upload('GalleryAlbumCover', './uploads/gallery', 'cover_'.$post['GalleryAlbumPageURL']); $data['error'] = array('error' => $this->upload->display_errors()); echo '<script>console.log("'.implode(',',$data['error']).'")</script>'; } if(($_FILES['GalleryAlbumCover']['name'])&&(!$cover_pic)){ $data['error'] = "Unable to upload Cover picture"; $data['categories'] = $this->Common_Model->getCommonQuery('SH_GalleryCategories'); $this->load->view('admin/AddAlbum',$data); echo '<script>console.log("Unable to upload Cover picture")</script>'; exit; } else { if(isset($post['GalleryAlbumID'])){ $albumID = $post['GalleryAlbumID']; } $insert_data = array( 'GalleryAlbumName' => $post['GalleryAlbumName'], 'GalleryAlbumDescription' => $post['GalleryAlbumDescription'], 'GalleryAlbumCategory' => $post['GalleryAlbumCategory'], 'GalleryAlbumPriorityOrder' => $post['GalleryAlbumPriorityOrder'], 'Status' => $post['Status'], 'GalleryAlbumPageURL' => $post['GalleryAlbumPageURL'] ); if($cover_pic!=''){ $insert_data['GalleryAlbumCover'] = $cover_pic; } $success = ''; echo '<script>console.log("'.$albumID.'")</script>'; if($albumID){ $success = $this->Common_Model->update_info('SH_GalleryAlbums',$insert_data,'GalleryAlbumID',$albumID); } else{ $success = $this->Common_Model->save_info('SH_GalleryAlbums',$insert_data); if (!file_exists('./uploads/gallery/album-'.$success)) { mkdir('./uploads/gallery/album-'.$success, 0777, true); } echo '<script>console.log("'.$success.'")</script>'; } if($success){ redirect(base_url()."admin/ImageGallery/view_albums"); } } } } $data['categories'] = $this->Common_Model->getCommonQuery('SH_GalleryCategories'); $this->load->view('admin/AddAlbum',$data); } public function update_album($id){ $this->add_album($id); } public function view_albums() { $data = array(); $data['records'] = $this->Common_Model->getAlbums('SH_GalleryAlbums'); if(!$data){ show_404(); } $this->load->view('admin/ViewAlbums',$data); } //**************************************************** PHOTOS **************************************************** public function add_photos() { $data = array(); $data['data_string'] = ''; echo '<script>console.log("add photos")</script>'; $post=$this->input->post(); if(($post)&&(!empty($_FILES['photos']['name']))){ echo '<script>console.log("post")</script>'; $this->form_validation->set_rules('GalleryPhotoAlbum', 'Gallery Album', 'required'); if ($this->form_validation->run() == FALSE) { echo '<script>console.log("Error in validating album")</script>'; //console.log("Error in validating doctor"); $data['error'] = "Error in validating album"; //$data['albums'] = $this->gallery->get_gallery_albums('GalleryAlbumID, GalleryAlbumName','GalleryAlbumPageURL'); $data['albums'] = $this->Common_Model->getCommonQuery('SH_GalleryAlbums','GalleryAlbumID, GalleryAlbumName,GalleryAlbumPageURL'); $this->load->view('admin/AddPhotos'); } else { $album = $this->Common_Model->getCommonQuery('SH_GalleryAlbums','*',array('GalleryAlbumID'=>$post['GalleryPhotoAlbum'])); echo '<script>console.log("album fields: '.$album['GalleryAlbumID'].','.$album['GalleryAlbumName'].'")</script>'; $filesCount = count($_FILES['photos']['name']); echo '<script>console.log("album fields: '.$filesCount.'")</script>'; $data['not_uploaded'] = array(); $data['error'] = array(); $data['photo_id'] = array(); $upload_path = './uploads/gallery/album-'.$album['GalleryAlbumID']; echo '<script>console.log("'.$upload_path.'")</script>'; if (!file_exists($upload_path)) { mkdir($upload_path, 0777, true); echo '<script>console.log("created")</script>'; } for($i = 0; $i < $filesCount; $i++){ $_FILES['photo']['name'] = $_FILES['photos']['name'][$i]; $_FILES['photo']['type'] = $_FILES['photos']['type'][$i]; $_FILES['photo']['tmp_name'] = $_FILES['photos']['tmp_name'][$i]; $_FILES['photo']['error'] = $_FILES['photos']['error'][$i]; $_FILES['photo']['size'] = $_FILES['photos']['size'][$i]; if($_FILES['photo']['name']){ echo '<script>console.log("tmp file created")</script>'; $file_name = $this->do_upload('photo',$upload_path,'photo_'.$album['GalleryAlbumID'].'_'.date('Y-m-d').'_'.($i+1)); if(!$file_name){ $data['not_uploaded'][] = $_FILES['photo']['name']; $data['error'][] = array('error' => $_FILES['photo']['name'].': '.$this->upload->display_errors()); } else{ $insert_data = array( 'GalleryPhotoAlbum' => $post['GalleryPhotoAlbum'], 'GalleryPhotoPageURL' => $file_name, 'GalleryPhotoTitle' => $album['GalleryAlbumName'], 'GalleryPhotoCaption' => '', 'Status' => $post['Status'], ); $data['photo_id'][] = $this->Common_Model->save_info(' SH_GalleryPhotos',$insert_data); } } } if(!empty($data['not_uploaded'])&&($filesCount==count($data['not_uploaded']))){ $data['albums'] = $this->Common_Model->getCommonQuery('SH_GalleryAlbums','GalleryAlbumID, GalleryAlbumName,GalleryAlbumPageURL'); $this->load->view('admin/AddPhotos',$data); exit; } else{ $data['album_details'] = $this->Common_Model->getCommonQuery('SH_GalleryAlbums','*',array('GalleryAlbumID'=>$post['GalleryPhotoAlbum'])); $data['photos'] = $this->Common_Model->getCommonQuery('SH_GalleryPhotos','*',array('GalleryPhotoAlbum'=>$post['GalleryPhotoAlbum'])); $data['records'] = $this->Common_Model->getCommonQuery('SH_GalleryAlbums'); $this->load->view('admin/ViewAlbums',$data); exit; // redirect(base_url()."admin/ImageGallery/view_album/".$post['GalleryAlbumID']); } } } $data['albums'] = $this->Common_Model->getCommonQuery('SH_GalleryAlbums','GalleryAlbumID, GalleryAlbumName,GalleryAlbumPageURL'); echo '<script>console.log("'.count($data['albums']).'")</script>'; $this->load->view('admin/AddPhotos',$data); } public function update_photo($id){ $data = array(); $records = $this->Common_Model->getSingleRecord('SH_GalleryPhotos','*',array('GalleryPhotoID'=>$id)); $post=$this->input->post(); if($post&&$records){ $this->form_validation->set_rules('GalleryPhotoAlbum', 'Gallery Album', 'required'); $this->form_validation->set_rules('GalleryPhotoTitle', 'Photo Title', 'required'); if ($this->form_validation->run() == FALSE) { echo '<script>console.log("Error in validating album")</script>'; //console.log("Error in validating doctor"); $data = $this->Common_Model->getSingleRecord('SH_GalleryPhotos','*',array('GalleryPhotoID'=>$id)); $data['error'] = "Error in validating photo"; $this->load->view('admin/UpdatePhoto',$data); } else{ if($post['GalleryPhotoCaption']==''){ $post['GalleryPhotoCaption']=$post['GalleryPhotoTitle']; } if($post['GalleryPhotoAlternateName']==''){ $post['GalleryPhotoAlternateName']=$post['GalleryPhotoTitle']; } $update_data = array( 'GalleryPhotoAlbum' => $post['GalleryPhotoAlbum'], 'GalleryPhotoTitle' => $post['GalleryPhotoTitle'], 'GalleryPhotoCaption' => $post['GalleryPhotoCaption'], 'GalleryPhotoAlternateName' => $post['GalleryPhotoAlternateName'], 'GalleryPhotoPriorityOrder' => $post['GalleryPhotoPriorityOrder'], 'Status' => $post['Status'], ); if($id){ $success = $this->Common_Model->update_info('SH_GalleryPhotos',$update_data,'GalleryPhotoID',$id); } if($success){ redirect(base_url()."admin/ImageGallery/view_photos"); }; } } if($records){ $data = array( 'GalleryPhotoID' => $records['GalleryPhotoID'], 'GalleryAlbumName' => $records['GalleryAlbumName'], 'GalleryPhotoAlbum' => $records['GalleryPhotoAlbum'], 'GalleryPhotoTitle' => $records['GalleryPhotoTitle'], 'GalleryPhotoPageURL' => $records['GalleryPhotoPageURL'], 'GalleryPhotoPriorityOrder' => $records['GalleryPhotoPriorityOrder'], 'GalleryPhotoAlternateName' => $records['GalleryPhotoAlternateName'], 'GalleryPhotoCaption' => $records['GalleryPhotoCaption'], 'Status' => $records['Status'], ); } $data['albums'] = $this->Common_Model->getCommonQuery('SH_GalleryAlbums','GalleryAlbumID, GalleryAlbumName,GalleryAlbumPageURL'); $this->load->view('admin/UpdatePhoto',$data); } public function view_photos() { $data = array(); $data['records'] = $this->Common_Model->getPhotos('SH_GalleryPhotos'); if(!$data){ show_404(); } $this->load->view('admin/ViewPhotos',$data); } public function remove_photo() { $data = array(); if($this->Common_Model->delete_doctor('SH_GalleryPhotos',$id,'GalleryPhotoID')){ $data['msg'] = 'Photo deleted succesfully'; } else{ $data['msg'] = 'Photo could not be deleted'; } $data['records'] = $this->Common_Model->getCommonQuery('SH_GalleryPhotos'); if(!$data){ show_404(); } $this->load->view('admin/ViewPhotos',$data); } }