Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (! defined('BASEPATH')) exit('No direct script access allowed');
- class Admin2 extends CI_Controller
- {
- public $data = array();
- public $data2 = array();
- public $data3 = array();
- function __construct ()
- {
- parent::__construct();
- $this->load->helper('url');
- $this->load->helper('form');
- $this->load->model('folio_model');
- $this->load->library('form_validation');
- $this->load->library('pagination');
- //$this->load->spark('markdown-extra/0.0.0');
- $this->data['message'] = '';
- $this->data['error'] = '';
- $this->data['title'] = 'Control Panel';
- $this->data['body_title'] = '';
- $this->data['body_content'] = '';
- $this->data['records'][0]['title'] = '';
- $this->data['records'][0]['title_url'] = '';
- $this->data['records'][0]['description'] = '';
- $this->data['records'][0]['version'] = 0;
- $this->data['records'][0]['stage'] = '';
- $this->data['records'][0]['last_update_yr'] = 0;
- $this->data['records'][0]['last_update_mo'] = '';
- $this->data['records'][0]['last_update_dy'] = 0;
- $this->data['records'][0]['date_started_yr'] = 0;
- $this->data['records'][0]['date_started_mo'] = '';
- $this->data['records'][0]['date_started_dy'] = 0;
- $this->data['records'][0]['date_finished_yr'] = 0;
- $this->data['records'][0]['date_finished_mo'] = '';
- $this->data['records'][0]['date_finished_dy'] = 0;
- $this->data['records'][0]['photo_url'] = '';
- $this->data['records'][0]['video_url'] = '';
- $this->data['records'][0]['technology'] = '';
- $this->data['records'][0]['buy'] = '';
- $this->data['records'][0]['document'] = '';
- $this->data['records'][0]['demo'] = '';
- $this->data['records'][0]['download'] = '';
- $this->data['records'][0]['changelog'] = '';
- }
- //Display Admin Login form page
- function index()
- {
- //$this->data['body_title'] = '';
- //$this->data['body_content'] = '<br><br><br><br><br><center><h2>jazPortfolio</h2></center><br><br><br><br><br><br><br><br>';
- //$this->load->view('admin2/cpanel', $this->data);
- $this->data['password_header'] = $this->load->view('admin2/password_header', $this->data, TRUE);
- $this->load->view('admin2/password', $this->data);
- }
- function about_admin()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'About';
- $this->data['body_content'] = $this->load->view('admin2/about', $this->data, TRUE);
- $this->load->view('admin2/cpanel', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- //main page
- function login_page()
- {
- $this->data['message'] = $this->session->flashdata('message');
- $this->data['password_header'] = $this->load->view('admin2/password_header', $this->data, TRUE);
- $this->load->view('admin2/password', $this->data);
- }
- function login(){
- //Capture data and validate
- $this->form_validation->set_rules('username', 'Username', 'required');
- $this->form_validation->set_rules('password', 'Password', 'required');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->index();
- }
- else
- {
- //If form validation has no error catch $username and $password
- //Call login method
- $user = $this->input->post('username', TRUE);
- $pass = $this->input->post('password', TRUE);
- //store username and password to session.
- $this->session->set_userdata('username', $user);
- $this->session->set_userdata('password', $pass);
- if($this->folio_model->login($user, $pass))
- {
- //If everything is okay redirect to Admin Conrol Panel.
- $this->data['body_title'] = '';
- $this->data['body_content'] = '<br><br><br><br><br><center><h2>jazPortfolio</h2></center><br><br><br><br><br><br><br><br>';
- $this->data['cpanel_header'] = $this->load->view('admin2/cpanel_header', $this->data, TRUE);
- //$this->load->view('admin/admincpanel', $this->data);
- $this->load->view('admin2/cpanel', $this->data);
- }
- else
- {
- //If login failed display error message.
- $this->session->set_flashdata('message', 'Invalid username or password.');
- redirect('admin/admin2/login_page');
- }
- }
- }
- /***********************************************************************************
- * Settings methods
- ***********************************************************************************/
- function follow_links()
- {
- if($this->compare_user_pass())
- {
- $this->data['error'] = ' ';
- $this->data['body_title'] = 'Follow Links';
- $this->load->view('admin2/follow_links_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function follow_links_proc()
- {
- //Capture data and validate
- $this->form_validation->set_rules('home', 'Home', '');
- $this->form_validation->set_rules('about', 'About', '');
- $this->form_validation->set_rules('blog', 'Blog', '');
- $this->form_validation->set_rules('linkedin', 'Linkedin', '');
- $this->form_validation->set_rules('facebook', 'FaceBook', '');
- $this->form_validation->set_rules('twitter', 'Twitter', '');
- $this->form_validation->set_rules('googleplus', 'Google+', '');
- $this->form_validation->set_rules('rss', 'RSS', '');
- $this->form_validation->set_rules('youtube', 'YouTube', '');
- $this->form_validation->set_rules('contact', 'Contact Us', '');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->follow_links();
- }
- else
- {
- //If form validation has no error catch $username and $new_username data
- $home = $this->input->post('home', TRUE);
- $about = $this->input->post('about', TRUE);
- $blog = $this->input->post('blog', TRUE);
- $linkedin = $this->input->post('linkedin', TRUE);
- $facebook = $this->input->post('facebook', TRUE);
- $twitter = $this->input->post('twitter', TRUE);
- $googleplus = $this->input->post('googleplus', TRUE);
- $rss = $this->input->post('rss', TRUE);
- $youtube = $this->input->post('youtube', TRUE);
- $contact = $this->input->post('contact', TRUE);
- if($home == 'yes')
- {
- $home = base_url();
- }
- if($about == 'yes')
- {
- $about = base_url('front/about/');
- }
- if($contact == 'yes')
- {
- $contact = base_url('front/contact/');
- }
- if($this->folio_model->save_follow_links($home, $facebook, $twitter, $rss, $youtube, $contact, $about, $blog, $linkedin, $googleplus))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = '<b>Follow Links successfully saved</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = '<b>Saving Follow Links failed</b><br><b>Or you submitted all the fields empty.</b>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- function follow_links_reset()
- {
- if($this->folio_model->reset_follow_links())
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = '<b>Reset successful.</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = '<b>Reset failed</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- //Not in use, just for future reference
- function change_banner_mark_down()
- {
- $this->data['body_title'] = 'Change Banner';
- $md = file_get_contents(APPPATH . 'views/admin2/change_banner_form.php');
- $this->data['body_content'] = parse_markdown_extra($md);
- $this->load->view('admin2/cpanel', $this->data);
- }
- function change_banner()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Change Banner';
- $this->data['error'] = $this->session->userdata('error_msg');
- $this->load->view('admin2/change_banner_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function change_banner_proc()
- {
- $config['upload_path'] = './images/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = '2048';
- $config['max_width'] = '1170';
- $config['max_height'] = '200';
- $this->load->library('upload', $config);
- if (!$this->upload->do_upload())
- {
- //If file upload fail display form again with error message.
- $this->data['error_msg'] = $this->upload->display_errors();
- $this->load->view('admin2/error_upload', $this->data);
- }
- else
- {
- //If file upload is successful dispaly success message
- $data = array('upload_data' => $this->upload->data());
- //catch uploaded filename.
- $uploaded_filename = $data['upload_data']['file_name'];
- //Delete banner.jpg
- unlink('./images/banner.jpg');
- //rename uploaded file to banner.jpg
- $uploaded_filename_inside_images = './images/'.$uploaded_filename;
- rename($uploaded_filename_inside_images, "./images/banner.jpg");
- //Display success page
- $this->data['error_msg'] = 'File Upload successful.';
- //$this->load->view('admin2/error_upload', $this->data);
- }
- }
- //Set banner to default
- function banner_default()
- {
- if($this->compare_user_pass())
- {
- //Delete current banner.jpg
- unlink('./images/banner.jpg');
- //rename banner_default.jpg to banner.jpg
- if(copy("./images/banner_default.jpg", "./images/banner.jpg"))
- {
- $this->data['error_msg'] = 'Banner photo successfully set to default.';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function change_skin()
- {
- $this->data['msg'] = '<h3>Coming soon...</h3>';
- $this->load->view('admin/message', $this->data);
- }
- function footer()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Change Footer';
- $this->data['error'] = ' ';
- $this->data['content'] = ' ';
- $this->load->view('admin2/change_footer_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function footer_edit()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Edit About';
- $this->data['error'] = ' ';
- $this->data['content'] = $this->folio_model->get_footer_content();
- $this->load->view('admin2/change_footer_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function footer_proc()
- {
- //Capture data and validate
- $this->form_validation->set_rules('content', 'Footer Texts', 'required');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->change_footer();
- }
- else
- {
- //If form validation has no error catch $footer_text
- $texts = $this->input->post('content', TRUE);
- if($this->folio_model->change_footer($texts))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = 'Success changing footer texts';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = 'Changing footer texts failed';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- function number_records()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Number of Records';
- $this->data['error'] = ' ';
- $this->data['content'] = '';
- $this->load->view('admin2/number_records_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function number_records_proc()
- {
- $this->form_validation->set_rules('numrec', 'Number of Records', 'required');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->number_records();
- }
- else
- {
- //If form validation has no error catch $content
- $numrec = $this->input->post('numrec', TRUE);
- $data = array(
- 'number' => $numrec
- );
- if($this->folio_model->save_number($data))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = '<b>Number per page successfully saved.</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = '<b>Saving number per page failed</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- function about()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'About';
- $this->data['error'] = ' ';
- $this->data['content'] = '';
- $this->load->view('admin2/about_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function about_edit()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Edit About';
- $this->data['error'] = ' ';
- $this->data['content'] = $this->folio_model->get_about_content();
- $this->load->view('admin2/about_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function about_proc()
- {
- //Capture data and validate
- $this->form_validation->set_rules('content', 'Content', 'required');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->about();
- }
- else
- {
- //If form validation has no error catch $content
- $texts = $this->input->post('content', TRUE);
- $data = array(
- 'content' => $texts
- );
- if($this->folio_model->save_content($data))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = '<b>Content texts successfully saved.</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = '<b>Saving content message failed</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- function skin()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Skin';
- $this->data['error'] = ' ';
- $this->data['content'] = '';
- $this->load->view('admin2/skin_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function skin_proc()
- {
- //Capture data and validate
- $this->form_validation->set_rules('skin', 'Skin', '');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->skin();
- }
- else
- {
- //If form validation has no error catch $content
- $skin = 'template/'. $this->input->post('skin', TRUE);
- $skin2 = $skin. '2';
- $data = array(
- 'skin1' => $skin,
- 'skin2' => $skin2,
- );
- if($this->folio_model->save_skin($data))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = '<b>Skin successfully saved.</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = '<b>Saving skin failed</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- /***********************************************************************************
- * Manage Portfolio Methods
- ***********************************************************************************/
- function document()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Document';
- $this->data['error'] = ' ';
- $this->load->view('admin2/document_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function document_proc()
- {
- //Capture data and validate
- $this->form_validation->set_rules('document', 'Document', 'required');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->document();
- }
- else
- {
- //If form validation has no error catch $footer_text
- $texts = $this->input->post('document', TRUE);
- if($this->folio_model->save_document_url($texts))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = 'Success saving document URL.';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = 'Saving failed';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- function changelog()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Change Log';
- $this->data['error'] = ' ';
- $this->load->view('admin2/document_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function changelog_proc()
- {
- }
- function download()
- {
- $this->data['body_title'] = 'Download';
- $this->data['error'] = ' ';
- $this->load->view('admin2/document_form', $this->data);
- }
- function download_proc()
- {
- }
- function add_record()
- {
- if($this->compare_user_pass())
- {
- $this->session->set_userdata('action', 'add');
- $this->data['body_title'] = 'Add Record';
- $this->data['error'] = ' ';
- $this->load->view('admin2/add_record_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function edit_record()
- {
- //store to session
- //fetch id segment
- $rec_id = $this->uri->segment(4, 0);
- $this->session->set_userdata('rec_id', $rec_id);
- $this->session->set_userdata('action', 'edit');
- $this->data['body_title'] = 'Edit Record';
- //fech record by id segment
- $this->data['records'] = $this->folio_model->get_record_by_id($rec_id);
- if($this->compare_user_pass())
- {
- //Display Edit form
- //$this->load->view('admin2/edit_record_form', $this->data);
- $this->load->view('admin2/add_record_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function add_record_proc()
- {
- //Capture session data
- $rec_id = $this->session->userdata('rec_id');
- $action = $this->session->userdata('action');
- //Capture data and validate
- if($action == 'add') {
- $this->form_validation->set_rules('title', 'Title', 'trim|required|is_unique[portfolio.title]');
- }
- if($action == 'edit') {
- $this->form_validation->set_rules('title', 'Title', 'trim|required');
- }
- $this->form_validation->set_rules('url', 'Site URL', 'trim|required');
- //$this->form_validation->set_rules('description', 'Description', 'required');
- $this->form_validation->set_rules('photo_url', 'Photo', 'trim');
- $this->form_validation->set_rules('video_url', 'Video', 'trim');
- $this->form_validation->set_rules('technology', 'Technology', 'trim');
- $this->form_validation->set_rules('buy', 'Buy', 'trim');
- $this->form_validation->set_rules('document', 'Document', 'trim');
- $this->form_validation->set_rules('demo', 'Demo', 'trim');
- $this->form_validation->set_rules('download', 'Download', 'trim');
- if(isset($_POST['submit'])) {
- //if($userfile != '' || $userfile != 0) {
- //Copy filename to photo_url column into DB
- $this->data3['photo_url'] = $this->input->post('userfile', TRUE);
- //Upload file config
- $config['upload_path'] = './images/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = '2048';
- $config['max_width'] = '1000';
- $config['max_height'] = '700';
- $this->load->library('upload', $config);
- //Process upload file
- if (!$this->upload->do_upload())
- {
- //If file upload fail just do nothing.
- //$error = array('error' => $this->upload->display_errors());
- //echo $error;
- //$this->data['error_msg'] = $this->upload->display_errors();
- //$this->load->view('admin2/error_upload', $this->data);
- }
- else
- {
- //If file upload is successful capture data
- $data_file = array('upload_data' => $this->upload->data());
- $this->data3['photo_url'] = $data_file['upload_data']['file_name'];
- }
- }
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- if($action == 'add') {
- $this->add_record();
- //redirect('admin/admin2/add_record/', 'refresh');
- }
- if($action == 'edit') {
- //fech record by id segment
- $this->data['records'] = $this->folio_model->get_record_by_id($rec_id);
- $this->load->view('admin2/add_record_form', $this->data);
- }
- }
- else
- {
- //If form validation has no error catch data
- //date('Y-m-d H:i:s');
- $this->data3['title'] = $this->input->post('title', TRUE);
- $this->data3['title_url'] = $this->input->post('url', TRUE);
- $this->data3['description'] = $this->input->post('description', TRUE);
- $this->data3['version'] = $this->input->post('version', TRUE);
- $this->data3['stage'] = $this->input->post('stage', TRUE);
- $this->data3['date_started_yr'] = $this->input->post('date_started_yr', TRUE);
- $this->data3['date_started_mo'] = $this->input->post('date_started_mo', TRUE);
- $this->data3['date_started_dy'] = $this->input->post('date_started_dy', TRUE);
- $this->data3['last_update_yr'] = $this->input->post('last_update_yr', TRUE);
- $this->data3['last_update_mo'] = $this->input->post('last_update_mo', TRUE);
- $this->data3['last_update_dy'] = $this->input->post('last_update_dy', TRUE);
- $this->data3['date_finished_yr'] = $this->input->post('date_finished_yr', TRUE);
- $this->data3['date_finished_mo'] = $this->input->post('date_finished_mo', TRUE);
- $this->data3['date_finished_dy'] = $this->input->post('date_finished_dy', TRUE);
- $this->data3['video_url'] = $this->input->post('video_url', TRUE);
- $this->data3['technology'] = $this->input->post('technology', TRUE);
- $this->data3['buy'] = $this->input->post('buy', TRUE);
- $this->data3['document'] = $this->input->post('document', TRUE);
- $this->data3['demo'] = $this->input->post('demo', TRUE);
- $this->data3['download'] = $this->input->post('download', TRUE);
- $this->data3['changelog'] = $this->input->post('changelog', TRUE);
- if($action == 'add') {
- if($this->folio_model->save_record($this->data3))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = '<b>Portfolio successfully saved.</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = '<b>Saving Portfolio failed</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- if($action == 'edit') {
- $this->data3['id'] = $rec_id;
- //check photo_upload if empty insert current filename;
- if($this->data3['photo_url'] == '' || $this->data3['photo_url'] == '0') {
- $this->data3['photo_url'] = $this->folio_model->get_image_name($rec_id);
- }
- if($this->folio_model->update_record($this->data3))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = '<b>Portfolio successfully updated.</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = '<b>Updating Portfolio failed</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- }
- function ed_record()
- {
- if($this->compare_user_pass())
- {
- $this->data['records'] = $this->folio_model->get_records2();
- $this->data['body_title'] = 'Edit and Delete Record';
- $this->data['error'] = ' ';
- $this->load->view('admin2/ed_record_page', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function delete_record()
- {
- //fetch id segment
- $rec_id = $this->uri->segment(4, 0);
- //get image name
- $image_name = $this->folio_model->get_image_name($rec_id);
- //delete image filename
- if($image_name != '') {
- $this->delete_image_name($image_name);
- }
- //Delete record
- if($this->folio_model->del_rec($rec_id))
- {
- //If everything is okay.
- //$this->data['error_msg'] = '<b>The record successfully deleted.</b>';
- //$this->load->view('admin2/error_page', $this->data);
- redirect('/admin/admin2/ed_record/', 'refresh');
- }
- else
- {
- //If somehting goes wrong.
- $this->data['error_msg'] = '<b>Record Deletion failed.</b>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- function delete_image_name($image_name){
- $path_of_image = './images/' . $image_name;
- if (file_exists($path_of_image)) {
- unlink($path_of_image);
- }
- else
- {
- return false;
- }
- }
- /***********************************************************************************
- * Admin Login methods
- ***********************************************************************************/
- function change_user()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Change Username';
- $this->data['error'] = ' ';
- $this->load->view('admin2/change_user_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function change_user_proc()
- {
- //Capture data and validate
- $this->form_validation->set_rules('username', 'Username', 'required');
- $this->form_validation->set_rules('new_username', 'New username', 'required');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->change_user();
- }
- else
- {
- //If form validation has no error catch $username and $new_username data
- $user = $this->input->post('username', TRUE);
- $new_user = $this->input->post('new_username', TRUE);
- if($this->folio_model->change_username($user, $new_user))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = '<b>Username successfully changed</b><br> New username: ' . $new_user;
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = '<b>Changing username failed</b><br><b>Or username doesn\'t exist.</b>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- function change_pass()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Change Password';
- $this->data['error'] = ' ';
- $this->load->view('admin2/change_pass_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function change_pass_proc()
- {
- //Capture data and validate
- $this->form_validation->set_rules('username', 'Username', 'required');
- $this->form_validation->set_rules('new_password', 'New password', 'required');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->change_pass();
- }
- else
- {
- //If form validation has no error catch $username and $new_username data
- $user = $this->input->post('username', TRUE);
- $new_pass = $this->input->post('new_password', TRUE);
- $salted_pass = $this->folio_model->encrypt_pass($new_pass);
- if($this->folio_model->change_password($user, $salted_pass))
- {
- $this->data['error_msg'] = '<b>Password successfully changed</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- $this->data['error_msg'] = '<b>Changing password failed</b><br><b>Or username doesn\'t exist.</b>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- function change_email()
- {
- if($this->compare_user_pass())
- {
- $this->data['body_title'] = 'Change Email';
- $this->data['error'] = ' ';
- $this->load->view('admin2/change_email_form', $this->data);
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function change_email_proc()
- {
- //Capture data and validate
- $this->form_validation->set_rules('username', 'Username', 'required');
- $this->form_validation->set_rules('new_email', 'New Email', 'required');
- if ($this->form_validation->run() == FALSE)
- {
- //If validation has error display form again with error messages.
- $this->change_email();
- }
- else
- {
- //If form validation has no error catch $username and $new_username data
- $user = $this->input->post('username', TRUE);
- $new_email = $this->input->post('new_email', TRUE);
- if($this->folio_model->change_email($user, $new_email))
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = '<b>Email successfully changed</b><br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //Else display fail message.
- $this->data['error_msg'] = '<b>Changing Email failed</b><br><b>Or username doesn\'t exist.</b>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- }
- //This method will set the username and password to default.
- function set_default_up()
- {
- if($this->compare_user_pass())
- {
- if($this->folio_model->set_default_user_pass())
- {
- //If everything is okay, display success message
- $this->data['error_msg'] = 'Username and Password is successfully changed to default.<br>Username: admin <br>Password: pass <br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- else
- {
- //If failed display fail message
- $this->data['error_msg'] = 'Setting username and password to default failed. <br>Or the username and password is already set to default. <br>';
- $this->load->view('admin2/error_page', $this->data);
- }
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- /********************************************************************
- * Utility Methods. *
- ********************************************************************/
- function getprogress() {
- if (isset($_GET['uid'])) {
- // Fetch the upload progress data
- $status = uploadprogress_get_info($_GET['uid']);
- if ($status) {
- // Calculate the current percentage
- echo round($status['bytes_uploaded']/$status['bytes_total']*100);
- }
- else {
- // If there is no data, assume it's done
- echo 100;
- }
- }
- }
- function logout() {
- if($this->compare_user_pass())
- {
- $this->session->sess_destroy();
- $this->index();
- }
- else
- {
- //Display error message
- $this->error_access();
- }
- }
- function error_access() {
- $this->data['error_msg'] = 'Sorry no direct access.';
- $this->load->view('admin2/error_access', $this->data);
- }
- function compare_user_pass() {
- //retrieve username and password from session
- $user_ses = $this->session->userdata('username');
- $pass_ses = $this->session->userdata('password');
- //add salt to $pass_ses
- $pass_ses = $this->folio_model->encrypt_pass($pass_ses);
- //retrieve username and password from database
- $user_pass = $this->folio_model->get_user_pass();
- $user_db = $user_pass[0]['username'];
- $pass_db = $user_pass[0]['password'];
- //compare username and password from session versus database
- if($user_ses == $user_db && $pass_ses == $pass_db)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- /********************************************************************
- * Methods for testings. *
- ********************************************************************/
- function show_user_pass()
- {
- $user_pass = $this->folio_model->get_user_pass();
- //echo 'user: ' .$user_pass[0]['username']. '<br>';
- //echo 'pass: ' .$user_pass[0]['password'];
- }
- //Testing of ultramegatech.com uploadprogress
- function uploadprogress()
- {
- /*
- $this->data['body_title'] = 'File Upload Test';
- $this->data['error'] = $this->session->userdata('error_msg');
- $this->load->view('admin2/change_banner_form2', $this->data);
- */
- }
- function uploadprogress_proc()
- {
- $config['upload_path'] = './images/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = '2048';
- $config['max_width'] = '1200';
- $config['max_height'] = '1000';
- $this->load->library('upload', $config);
- if (!$this->upload->do_upload())
- {
- //If file upload fail display form again with error message.
- $this->data['error_msg'] = $this->upload->display_errors();
- $this->load->view('admin2/error_upload', $this->data);
- }
- else
- {
- //If file upload is successful dispaly success message
- $this->data['error_msg'] = 'File Upload successful.';
- $this->load->view('admin2/error_upload', $this->data);
- }
- }
- function saraan_test($userfile) {
- $data = array(
- 'username' => 'XXXXX',
- 'location' => 'XXXXX',
- 'filename' => $userfile,
- );
- $this->folio_model->save_saraan($data);
- }
- function show_cpanel()
- {
- $this->data['cpanel_header'] = $this->load->view('admin/cpanel_header', $this->data, TRUE);
- $this->load->view('admin/admincpanel', $this->data);
- }
- }
- //End of Admin class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement