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 Folio_model extends CI_Model {
- /**
- * The database table to use.
- * @var string
- */
- public $table_name = '';
- /**
- * Primary key field
- * @var string
- */
- public $primary_key = '';
- /**
- * Order by fields. Default order for this model.
- * @var string
- */
- public $order_by = '';
- public $salt = 'b8idea';
- function __construct() {
- parent::__construct();
- }
- /*****************************************************
- * Front page
- *****************************************************/
- public function login($username, $password)
- {
- //check for emptiness.
- if(empty($username) || empty($password)) {
- return FALSE;
- }
- $salted_pass = $this->encrypt_pass($password);
- //Check if username and password exist in users table.
- //select record where username = $username
- $q = $this->db->select('id, username, password')
- ->from('login')
- ->where('username', $username)
- ->where('password', $salted_pass)
- ->where('id', 1)
- ->limit(1)
- ->get();
- if ($q->num_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- //record not found.
- return FALSE;
- }
- }
- function get_records($per_page)
- {
- $query = $this->db->select('*')
- ->from('portfolio')
- ->limit($per_page, $this->uri->segment(3))
- ->order_by('id', 'DESC')
- ->get();
- if ($query->num_rows() > 0)
- {
- return $query->result_array();
- } else {
- return FALSE;
- }
- }
- //get all records with out limits
- function get_records2()
- {
- $query = $this->db->select('*')
- ->from('portfolio')
- ->order_by('id', 'DESC')
- ->get();
- if ($query->num_rows() > 0)
- {
- return $query->result_array();
- } else {
- return FALSE;
- }
- }
- function total_records()
- {
- //Get all total records of portfolio table
- return $this->db->count_all('portfolio');
- }
- function get_user_pass()
- {
- //fetch email address from
- $query = $this->db->select('username, password')
- ->where('id', 1)
- ->get('login');
- if ($query->num_rows() > 0)
- {
- return $query->result_array();
- } else {
- return FALSE;
- }
- }
- function get_about_content()
- {
- //fetch email address from
- $query = $this->db->select('content')
- ->where('id', 1)
- ->get('about');
- if($query->num_rows() > 0)
- {
- $row = $query->row();
- return $row->content;
- }
- else
- {
- return FALSE;
- }
- }
- function get_footer_content()
- {
- //fetch email address from
- $query = $this->db->select('footer_msg')
- ->where('id', 1)
- ->get('settings');
- if($query->num_rows() > 0)
- {
- $row = $query->row();
- return $row->footer_msg;
- }
- else
- {
- return FALSE;
- }
- }
- /*****************************************************
- * Settings Methods
- *****************************************************/
- function change_footer($texts)
- {
- //update username.
- $this->db->where('id', 1)
- ->set('footer_msg', $texts)
- ->update('settings');
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function read_footer_text()
- {
- //fetch footer_msg
- $query = $this->db->select('footer_msg')
- ->where('id', 1)
- ->get('settings');
- if ($query->num_rows() > 0)
- {
- $row = $query->row();
- return $row->footer_msg;
- }
- }
- function save_content($data = array())
- {
- //Update about table
- $this->db->where('id', 1)
- ->update('about', $data);
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function save_skin($data = array())
- {
- //Update about table
- $this->db->where('id', 1)
- ->update('skin', $data);
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function get_skin()
- {
- $query = $this->db->select('id, skin1, skin2')
- ->from('skin')
- ->where('id', 1)
- ->order_by('id', 'DESC')
- ->get();
- if ($query->num_rows() > 0)
- {
- return $query->result_array();
- } else {
- return FALSE;
- }
- }
- function save_number($data = array())
- {
- //Update about table
- $this->db->where('id', 1)
- ->update('recordpage', $data);
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function get_number_records()
- {
- //fetch footer_msg
- $query = $this->db->select('number')
- ->where('id', 1)
- ->get('recordpage');
- if ($query->num_rows() > 0)
- {
- $row = $query->row();
- return $row->number;
- }
- }
- /*****************************************************
- * Menu Methods
- *****************************************************/
- function save_follow_links($home, $facebook, $twitter, $rss, $youtube, $contact, $about, $blog, $linkedin, $googleplus)
- {
- $save_some_data = FALSE;
- if(!empty($home))
- {
- $this->db->where('idfollow', 1)
- ->set('home', $home)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- if(!empty($facebook))
- {
- $this->db->where('idfollow', 1)
- ->set('facebook', $facebook)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- if(!empty($twitter))
- {
- $this->db->where('idfollow', 1)
- ->set('twitter', $twitter)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- if(!empty($rss))
- {
- $this->db->where('idfollow', 1)
- ->set('rss', $rss)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- if(!empty($youtube))
- {
- $this->db->where('idfollow', 1)
- ->set('youtube', $youtube)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- if(!empty($contact))
- {
- $this->db->where('idfollow', 1)
- ->set('contact', $contact)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- if(!empty($about))
- {
- $this->db->where('idfollow', 1)
- ->set('about', $about)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- if(!empty($blog))
- {
- $this->db->where('idfollow', 1)
- ->set('blog', $blog)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- if(!empty($linkedin))
- {
- $this->db->where('idfollow', 1)
- ->set('linkedin', $linkedin)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- if(!empty($googleplus))
- {
- $this->db->where('idfollow', 1)
- ->set('googleplus', $googleplus)
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- $save_some_data = TRUE;
- }
- }
- return ($save_some_data) ? TRUE : FALSE;
- }
- function reset_follow_links()
- {
- $this->db->where('idfollow', 1)
- ->set('home', '')
- ->set('blog', '')
- ->set('linkedin', '')
- ->set('facebook', '')
- ->set('twitter', '')
- ->set('googleplus', '')
- ->set('rss', '')
- ->set('youtube', '')
- ->set('contact', '')
- ->set('about', '')
- ->update('followlinks');
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function get_follow_links()
- {
- //fetch content of followlinks table and store them into array.
- $query = $this->db->select('home, facebook, twitter, rss, youtube, contact, about, blog, linkedin, googleplus')
- ->where('idfollow', 1)
- ->get('followlinks');
- if($query->num_rows() > 0)
- {
- return $query->result_array();
- }
- }
- function get_owner_email()
- {
- //fetch email address from
- $query = $this->db->select('email')
- ->get('login');
- if ($query->num_rows() > 0)
- {
- $row = $query->row();
- return $row->email;
- }
- }
- /*****************************************************
- * Manage Portfolio
- *****************************************************/
- function save_record($data = array())
- {
- //convert every data into lower case first.
- $this->db->insert('portfolio', $data);
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function update_record($data = array())
- {
- //convert every data into lower case first.
- $this->db->where('id', $data['id'])
- ->update('portfolio', $data);
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function del_rec($rec_id)
- {
- $this->db->delete('portfolio', array('id' => $rec_id));
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function get_image_name($rec_id)
- {
- //fetch email address from
- $query = $this->db->select('photo_url')
- ->where('id', $rec_id)
- ->get('portfolio');
- if($query->num_rows() > 0)
- {
- $row = $query->row();
- return $row->photo_url;
- }
- else
- {
- return FALSE;
- }
- }
- function get_record_by_id($rec_id)
- {
- $query = $this->db->select('*')
- ->from('portfolio')
- ->where('id', $rec_id)
- ->get();
- if ($query->num_rows() > 0)
- {
- return $query->result_array();
- } else {
- return FALSE;
- }
- }
- function get_changelog($id)
- {
- $query = $this->db->select('changelog')
- ->from('portfolio')
- ->where('id', $id)
- ->get();
- if ($query->num_rows() > 0)
- {
- $row = $query->row();
- return $row->changelog;
- }
- }
- /*****************************************************
- * Admin Login Methods
- *****************************************************/
- function change_username($user, $new_user)
- {
- //update username.
- $this->db->where('username', $user)
- ->set('username', $new_user)
- ->update('login');
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function change_password($user, $salted_pass)
- {
- //update username.
- $this->db->where('username', $user)
- ->set('password', $salted_pass)
- ->update('login');
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function change_email($user, $new_email)
- {
- //update username.
- $this->db->where('username', $user)
- ->set('email', $new_email)
- ->update('login');
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function set_default_user_pass()
- {
- $encrypted_pass = $this->encrypt_pass('pass');
- $this->db->where('id', 1)
- ->set('username', 'admin')
- ->set('password', $encrypted_pass)
- ->update('login');
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- /******************************************************
- * Utility methods
- ******************************************************/
- function encrypt_pass($pass)
- {
- $pass = sha1($pass);
- $salted_pass = $pass.$this->salt;
- return $salted_pass;
- }
- /******************************************************
- * Below are for testing methods only
- ******************************************************/
- function save_saraan($data = array())
- {
- $this->db->insert('saraan', $data);
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function save_malsup_form($data = array()) {
- //Insert malsup table
- $this->db->insert('malsup', $data);
- if($this->db->affected_rows() > 0)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- }
- //End of Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement