Hi! I'm Neel, a Freelance Web Developer based in Melbourne

Code Examples

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_account extends MY_Controller {

private $user;
 private $expired;
 private $errors = array();

public function __construct()
 {
 parent::__construct();
 // $this->template->meta['keywords'] = '';
 // $this->template->meta['description'] = '';
 $user = $this->session->userdata('user');

 if(!$user)
 redirect('');
 $this->user = $user;

&nbsp;

$this->load->helper(array('form', 'url'));
 $this->load->library('form_validation');
 }

public function index()
 {
 // Default to devlivery
 $this->my_details();

 }

public function my_details()
 {
 $user = $this->model->getUser($this->user->member_id);
 $user = $user[0];
 $data['state'] = $this->model->getState();
 $data['user'] = $user;

$this->template->add_page('my_account/my_details');
 $this->template->render($data);
 }

public function save_my_details(){
 //form validations
 $config = array(
 array('field' => 'first_name',
 'label' => 'First Name',
 'rules' => 'trim|required'
 ),
 array('field' => 'last_name',
 'label' => 'Last Name',
 'rules' => 'trim|required'
 ),
 array(
 'field' => 'email',
 'label' => 'Email',
 'rules' => 'trim|required|valid_email|callback__email_check'
 ),
 array(
 'field' => 'password',
 'label' => 'Password',
 'rules' => 'trim|matches[repeat_password]|min_length[6]'
 ),
 array(
 'field' => 'repeat_password',
 'label' => 'Repeat Password',
 'rules' => 'trim|'
 ),
 array(
 'field' => 'address1',
 'label' => 'Address 1',
 'rules' => 'trim|required'
 ),
 array(
 'field' => 'address2',
 'label' => 'Address 2',
 'rules' => 'trim'
 ),
 array(
 'field' => 'city',
 'label' => 'City',
 'rules' => 'trim|required'
 ),
 array(
 'field' => 'state',
 'label' => 'State',
 'rules' => 'trim|required'
 ),
 array(
 'field' => 'postcode',
 'label' => 'Postcode',
 'rules' => 'trim|required'
 ),
 array(
 'field' => 'phone',
 'label' => 'Phone',
 'rules' => 'trim|required'
 ),
 array(
 'field' => 'mobile',
 'label' => 'Mobile',
 'rules' => 'trim|required'
 ),
 array(
 'field' => 'fax',
 'label' => 'Fax',
 'rules' => 'trim'
 ),
 );

 $this->form_validation->set_rules($config);
 $this->form_validation->set_message('_email_check', 'A record with the same %s already exists in our system. Please try a different one');
 if ($this->form_validation->run($this) == TRUE){
 //insert into db
 $post = $this->input->post();
 unset($post['repeat_password']);
 if($post['password'] != "")
 $post['password'] = md5($post['password']);
 else
 unset($post['password']);
 if($this->model->updateMember($post,$this->user->member_id)){
 $data['success'] = true;
 }else{
 $data['error'] = true;
 }

 }else{
 $this->my_details();
 return;
 }

$this->template->add_page('my_account/my_details');
 $this->template->render($data);
 }

public function documents_and_cecs()
 {
 $data['cec'] = $this->model->getCECTotal($this->user->member_id);
 $data['active_cec'] = $this->model->getActiveCEC($this->user->member_id);

$data['cec'] = $data['cec']->cec_total > 0 ? $data['cec']->cec_total : 0;

 $data['documents'] = $this->model->getMemberDocuments();
 $this->template->add_page('my_account/documents_and_cecs');
 $this->template->render($data);
 }

public function log_cec_for_approval(){
 $data=array();
 $data['errors'] = $this->errors;
 $this->template->add_page('my_account/log_cec_for_approval');
 $this->template->render($data);
 }

public function submit_cec_approval(){

$config = array(
 array('field' => 'program_name',
 'label' => 'Program Name',
 'rules' => 'trim|required'
 ),
 array('field' => 'provider',
 'label' => 'Provider',
 'rules' => 'trim|required'
 ),
 array('field' => 'presenter_name',
 'label' => 'Presenter Name',
 'rules' => 'trim|required'
 ),
 array('field' => 'program_date',
 'label' => 'Program Date',
 'rules' => 'trim|required'
 ),
 array('field' => 'program_code',
 'label' => 'Program Code',
 'rules' => 'trim|required'
 ),
 array('field' => 'cec_request',
 'label' => 'CEC Attained',
 'rules' => 'trim|required|numeric'
 ),
 array('field' => 'comments',
 'label' => 'Comments',
 'rules' => 'trim'
 ),
 array(
 'field' => 'agreeTerms',
 'label' => 'Terms & Conditions',
 'rules' => 'trim|required'
 )
 );

 $this->form_validation->set_rules($config);
 if ($this->form_validation->run($this) == TRUE){

 $files = $this->do_upload();

 if(!$files){
 $this->log_cec_for_approval();
 return;
 }

//insert into db
 $post = $this->input->post();
 $post['file1'] = $files['file1'];
 $post['file2'] = $files['file2'];
 $post['file3'] = $files['file3'];
 $post['member_id'] = $this->user->member_id;
 unset($post['agreeTerms']);

 if($this->model->saveCEC($post)){
 $data['success'] = true;
 }else{
 $data['error'] = true;
 }

 $this->template->add_page('my_account/log_cec_for_approval');
 $this->template->render($data);
 }else{
 $this->log_cec_for_approval();
 }
 }

function do_upload($file_count = 3)
 {

 $config['upload_path'] = APPPATH.'../uploads/';
 $config['allowed_types'] = 'pdf|doc|docx|xls|xlsx|ppt|pptx|png|jpeg|jpg|tif|gif';
 $config['max_size'] = '5120'; //5MB
 $config['encrypt_name'] = TRUE;
 $this->load->library('upload', $config);

$error = false;
 $errors = $files = array();
 foreach(range(1,$file_count) as $i){
 $file = 'file'.$i;
 if($_FILES[$file]['name'] == ""){
 $files[$file] = "";
 continue;
 }
 if ( ! $this->upload->do_upload($file)){
 $files[$file] = "";
 $error = true;

}else{
 //file upload successfull
 $file_array = $this->upload->data();
 $files[$file] = '/uploads/'.$file_array['file_name'];
 }
 }
 if($error)
 $this->errors = $this->upload->display_errors("");
 //if erros go back to page

 if(count($this->errors) > 0){
 return false;
 }
 return $files;
 }

public function my_education(){
 $data['my_education'] = $this->model->getMyEducation($this->user->member_id);
 $this->template->add_page('my_account/my_education');
 $this->template->render($data);
 }
 public function my_membership(){
 $user = $this->model->getUser($this->user->member_id);
 $data['user'] = $user[0];
 $data['membership_levels'] = $this->model->getMembLevels();
 $data['cec'] = $this->model->getCECTotal($this->user->member_id);
 $data['cec'] = $data['cec']->cec_total > 0 ? $data['cec']->cec_total : 0;

&nbsp;

$this->template->add_page('my_account/my_membership');
 $this->template->render($data);
 }

public function renew_upgrade_membership()
 {

$type = $this->input->post('type');
 $member_level_id = $this->input->post('member_level_id');
 $member_currentlevel_id = $this->input->post('member_currentlevel_id');
 $data['currentlevel'] = $this->model->getMembLevels($member_currentlevel_id);
 $data['currentlevel'] = $data['currentlevel'][0];

$data['level'] = $this->model->getMembLevels($member_level_id);
 $data['level'] = $data['level'][0];
 $data['level_fee'] = $this->model->getMembFee($member_level_id);
 $data['year_expiry'] = date('m')>6 ? '2014' : '2013';

$data['renew'] = $type == 'RENEW' ? 1 : 0;
 $data['errors'] = $this->errors;
 $this->template->add_page('my_account/renew_upgrade_membership');
 $this->template->render($data);
 }

function upgrade_membership_save(){
 $config = array(
 array('field' => 'card_name',
 'label' => 'Name on Card',
 'rules' => 'trim|required'
 ),
 array('field' => 'card_type',
 'label' => 'Card Type',
 'rules' => 'trim|required'
 ),
 array('field' => 'card_number',
 'label' => 'Card Number',
 'rules' => 'trim|required'
 ),
 array('field' => 'expiry_month',
 'label' => 'Expiry Month',
 'rules' => 'trim|required'
 ),
 array('field' => 'expiry_year',
 'label' => 'Expiry Year',
 'rules' => 'trim|required'
 )
 );

 $this->form_validation->set_rules($config);

if ($this->form_validation->run($this) == TRUE){

$files = $this->do_upload(6);
 if(!$files){
 $this->renew_upgrade_membership();
 return;
 }

 $post = $this->input->post();
 //do ccr payment
 $post['trans_ref'] = '0000';
 //insert into db

 unset($post['card_name'],$post['card_type'],$post['card_number'],$post['expiry_month'],$post['expiry_year']);
 $post['type'] = $post['current_level'] == $post['new_level'] ? 'Renewal' : 'Change';
 $post['status'] = 'Pending';
 $post['member_id'] = $this->user->member_id;

foreach(range(1,6) as $i)
 $post['file'.$i] = $files['file'.$i];

if($this->model->saveRenewUpgradeMemb($post)){
 $data['success'] = true;

$text = $post['type'] == 'Renewal' ? 'RENEWING' : 'CHANGING';

$member = $this->model->getUser($post['member_id']);
 $member = $member[0];
 $current_level = $this->model->getMembLevels($post['current_level']);
 $current_level = $current_level[0];
 $new_level = $this->model->getMembLevels($post['new_level']);
 $new_level = $new_level[0];

$table1 = array(
 'Name' => $member->first_name.' '.$member->last_name,
 'Email' => $member->email,
 'Phone' => $member->phone,
 'Type' => $text == 'RENEWING' ? 'Membership Renewal' : 'Membership Change',
 'Current Level' => $current_level->name,
 'New Level' => $new_level->name,
 'Comments' => $post['comments'],
 'Receipt #' => $post['trans_ref'],
 'Amount Paid' => '$'.number_format($post['paid'],2),
 );

$data['table1'] = $table1;

 $data['title'] = "THANK YOU FOR ".$text." YOUR MEMBERSHIP";
 $data['desc'] = "Thank you for ".strtolower($text)." you membership with the following details below.";
 $message = $this->load->view('email_templates/layout/header_view', $data, true);
 $message .= $this->load->view('email_templates/contact_view', $data, true);
 $message .= $this->load->view('email_templates/layout/footer_view', $data, true);

&nbsp;

include_once(APPPATH . 'libraries/phpmailer.php');
 $mail = new PHPMailer(true);

try {

$mail->AddReplyTo(SITE_EMAIL, SITE_NAME);
 $mail->AddAddress(SITE_EMAIL, SITE_NAME);
 $mail->SetFrom(SITE_EMAIL, SITE_NAME);
 $mail->Subject = 'Website Enquiry';
 /*$mail->AddEmbeddedImage('assets/images/email/logo.jpg','logo', 'logo.jpg');*/ # Add logo.jpg to assets/images/email/logo.jpg
 //$mail->AddEmbeddedImage('assets/images/email/footer.png','footer', 'footer.png');
 $mail->MsgHTML( $message );
 $mail->Send();
 $response['status'] = 1;
 } catch (phpmailerException $e) {
 //Pretty error messages from PHPMailer
 $response['status'] = 2;
 $response['message'] = $e->errorMessage();
 } catch (Exception $e) {
 //Boring error messages from anything else!
 $response['status'] = 2;
 $response['message'] = $e->getMessage();
 }
 }else{
 $data['error'] = true;
 }

 $this->template->add_page('my_account/log_cec_for_approval');
 $this->template->render($data);

 }else{
 $this->renew_upgrade_membership();
 }
 }
 public function _email_check($email){

 if($this->model->emailExists($email,$this->user->member_id)){

 return true;
 }
 return false;
 }
}
<pre>