Skip to content

Instantly share code, notes, and snippets.

@jlebrech
Created October 26, 2010 09:10
Show Gist options
  • Save jlebrech/646576 to your computer and use it in GitHub Desktop.
Save jlebrech/646576 to your computer and use it in GitHub Desktop.
<?php
class Contact extends Controller {
function Contact()
{
parent::Controller();
$this->load->helper(array('form','url','html','email'));
$this->load->library(array('tank_auth','Jquery_pagination','form_validation'));
}
function index()
{
ob_start();
$this->ajax_page( 0 );
$initial_content = ob_get_contents();
ob_end_clean();
$data['loggedin'] = $this->tank_auth->is_logged_in();
if ($data['loggedin']){
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$data["contacts"] = $this->db->get('contacts')->result();
$data['table'] = "<div id='content'>" . $initial_content . "</div>" ;
$this->load->view('contact/index', $data);
} else {
redirect("contact/create");
}
}
function ajax_page($offset = 0)
{
$this->load->model('contact');
$this->load->library('Jquery_pagination');
$config['base_url'] = site_url('test/ajax_page/');
/* Here i am indicating to the url from where the pagination links and the table section will be fetched */
$config['div'] = '#content';
/* CSS selector for the AJAX content */
$config['total_rows'] = $this->model->num_rows();
$config['per_page'] = 20;
$this->jquery_pagination->initialize($config);
$this->load->library('table');
$html = $this->jquery_pagination->create_links() . br(1)
. $this->table->generate($this->model->content( $limit, $offset));
echo $html;
}
function create(){
$this->load->view('contact/new');
}
function add()
{
$this->form_validation->set_rules('emailaddress', 'Email',
'required|valid_email|callback_emailaddress_unique');
if ($this->form_validation->run() == FALSE){
$this->load->view('contact/new');
} else {
$this->db->insert('contacts', $_POST);
$this->load->view('contact/success');
$message = "The following person has registered their interest".
$_POST["firstname"] . " " . $_POST["lastname"] . " \n" .
$_POST["emailaddress"];
//send_email('joseph@nublue.co.uk','New Registration','emailaddress');
}
}
function emailaddress_unique($str)
{
$this->db->where('emailaddress',$str);
$query = $this->db->from('contacts');
$numresults = $this->db->count_all_results();
if ($numresults){
$this->form_validation->set_message('emailaddress_unique', $str. ' is already taken');
return FALSE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment