Exemple #1
0
function requireLogin()
{
    session_start();
    if (isset($_SESSION['uid'])) {
        return $_SESSION['uid'];
    } else {
        redirect("/login.php?redirect=" . here());
    }
}
Exemple #2
0
<?
    require_once '../lib/util.php';
    $myid = requireLogin();
    if (isset($_POST['content'])) {
        sql("INSERT INTO posts (uid, content) VALUES ({$myid}, '{$_POST['content']}');");
        redirect(here());
    }
?>
<html>
    <head><title>Forum</title></head>
    <body>
        <div align=center width=500>
            <h3> This is where all the cool people hang out and discuss their ideas </h3>
            <p> Welcome, <? sql("SELECT username FROM users WHERE uid={$myid};"); $uname = getrow(); print $uname['username'] ?> </p>
            <small> <a href='/logout.php'>Logout, if you really must (please dont!)</a> </small>
            <table border=2>
                <th>Author</th><th>Post</th>
                <? sql("select uid, username, content from users natural join posts;") ?>
                <? while ($row = getrow()) { ?>
                    <? if (isset($row['uid']) && isset($row['username'])) {
                        $row['username'] = "******";
                        unset($row['uid']);
                    } ?>
                    <tr>
                        <? foreach ($row as $value) { ?>
                            <td> <?php 
echo $value;
?>
 </td>
                        <? } ?>
                    </tr>
Exemple #3
0
 /**
  * Handle the checkout process
  *
  * @access	public
  * @return	void
  *
  **/
 public function index()
 {
     if (!$this->_can_checkout()) {
         $this->session->set_flashdata('error', '<strong>Sorry,</strong> you can\'t checkout right now: ' . $this->data['error']);
         redirect(app_setting('url', 'shop') . 'basket');
         return;
     }
     // --------------------------------------------------------------------------
     if ($this->user_model->is_logged_in() || $this->input->get('guest')) {
         //	Continue, user is logged in or is checking out as a guest
         if ($this->input->get('guest')) {
             $this->data['guest'] = TRUE;
         } else {
             $this->data['guest'] = FALSE;
         }
         // --------------------------------------------------------------------------
         //	Check the order to see if we need to take shipping information
         $this->data['requires_shipping'] = FALSE;
         foreach ($this->data['basket']->items as $item) {
             if ($item->type->requires_shipping) {
                 $this->data['requires_shipping'] = TRUE;
                 break;
             }
         }
         // --------------------------------------------------------------------------
         //	If there's no shipping and only one payment gateway then skip this page
         //	entirely - simples! Unless they are a guest, in which case we need to take
         //	some personal details
         if (!$this->data['guest'] && !$this->data['requires_shipping'] && (count($this->data['payment_gateways']) == 1 || $this->data['basket']->totals->grand == 0)) {
             //	Save payment gateway info to the session
             if ($this->data['basket']->totals->grand != 0) {
                 $this->shop_basket_model->add_payment_gateway($this->data['payment_gateways'][0]->id);
             } else {
                 $this->shop_basket_model->remove_payment_gateway();
             }
             //	... and redirect to confirm
             $_uri = app_setting('url', 'shop') . 'checkout/confirm';
             $_uri .= $this->data['guest'] ? '?guest=true' : '';
             redirect($_uri);
             return;
         }
         // --------------------------------------------------------------------------
         //	If there's post data, then deal with that. If shipping is required then verify shipping info
         //	If not then punt onto shop/checkout/confirm
         if ($this->input->post()) {
             //	Validate
             $this->load->library('form_validation');
             if ($this->data['guest']) {
                 $this->form_validation->set_rules('first_name', 'First Name', 'xss_clean|required');
                 $this->form_validation->set_rules('last_name', 'Surname', 'xss_clean|required');
                 $this->form_validation->set_rules('email', 'Email', 'xss_clean|required|valid_email');
             }
             // --------------------------------------------------------------------------
             if ($this->data['requires_shipping']) {
                 $this->form_validation->set_rules('addressee', 'Addressee', 'xss_clean|required');
                 $this->form_validation->set_rules('line_1', 'Line_1', 'xss_clean|required');
                 $this->form_validation->set_rules('line_2', 'Line_2', 'xss_clean|required');
                 $this->form_validation->set_rules('town', 'Town', 'xss_clean|required');
                 $this->form_validation->set_rules('postcode', 'Postcode', 'xss_clean|required');
                 $this->form_validation->set_rules('country', 'Country', 'xss_clean|required');
                 //	If country is USA then us_state is required
                 if ($this->input->post('country') == 'ID OF USA') {
                     $this->form_validation->set_rules('us_state', 'State', 'xss_clean|required');
                 } else {
                     $this->form_validation->set_rules('us_state', 'State', 'xss_clean');
                 }
                 //	If country is AUSTRALIA then aus_state is required
                 if ($this->input->post('country') == 'ID OF AUSTRALIA') {
                     $this->form_validation->set_rules('aus_state', 'State', 'xss_clean|required');
                 } else {
                     $this->form_validation->set_rules('aus_state', 'State', 'xss_clean');
                 }
             }
             // --------------------------------------------------------------------------
             //	Payment gateway
             if ($this->data['basket']->totals->grand > 0) {
                 $this->form_validation->set_rules('payment_gateway', 'Payment Gateway', 'xss_clean|required|is_natural');
             }
             // --------------------------------------------------------------------------
             //	Set messages
             $this->form_validation->set_message('required', lang('fv_required'));
             $this->form_validation->set_message('is_natural', lang('fv_required'));
             $this->form_validation->set_message('valid_email', lang('fv_valid_email'));
             if ($this->form_validation->run()) {
                 //	Save personal info to session
                 if ($this->data['guest']) {
                     $_details = new stdClass();
                     $_details->first_name = $this->input->post('first_name');
                     $_details->last_name = $this->input->post('last_name');
                     $_details->email = $this->input->post('email');
                     $this->shop_basket_model->add_personal_details($_details);
                 } else {
                     //	In case it's already there for some reason
                     $this->shop_basket_model->remove_personal_details();
                 }
                 // --------------------------------------------------------------------------
                 //	Save shipping info to the session
                 if ($this->data['requires_shipping']) {
                     $_details = new stdClass();
                     $_details->addressee = $this->input->post('addressee');
                     $_details->line_1 = $this->input->post('line_1');
                     $_details->line_2 = $this->input->post('line_2');
                     $_details->town = $this->input->post('town');
                     $_details->postcode = $this->input->post('postcode');
                     $_details->country = $this->input->post('country');
                     if ($this->input->post('country') == 'ID OF USA') {
                         $_details->state = $this->input->post('us_state');
                     } elseif ($this->input->post('country') == 'ID OF AUSTRALIA') {
                         $_details->state = $this->input->post('aus_state');
                     } else {
                         $_details->state = '';
                     }
                     $this->shop_basket_model->add_shipping_details($_details);
                 } else {
                     //	In case it's already there for some reason
                     $this->shop_basket_model->remove_shipping_details();
                 }
                 // --------------------------------------------------------------------------
                 //	Redirect to the appropriate payment gateway. If there's only one, then
                 //	bump straight along to that one
                 if ($this->data['basket']->totals->grand > 0 && count($this->data['payment_gateways']) == 1) {
                     //	Save payment gateway info to the session
                     $this->shop_basket_model->add_payment_gateway($this->data['payment_gateways'][0]->id);
                     //	... and confirm
                     $_uri = app_setting('url', 'shop') . 'checkout/confirm';
                     $_uri .= $this->data['guest'] ? '?guest=true' : '';
                     redirect($_uri);
                 } elseif ($this->data['basket']->totals->grand > 0 && count($this->data['payment_gateways']) >= 1) {
                     foreach ($this->data['payment_gateways'] as $pg) {
                         if ($pg->id == $this->input->post('payment_gateway')) {
                             //	Save payment gateway info to the session
                             $this->shop_basket_model->add_payment_gateway($pg->id);
                             //	... and confirm
                             $_uri = app_setting('url', 'shop') . 'checkout/confirm';
                             $_uri .= $this->data['guest'] ? '?guest=true' : '';
                             redirect($_uri);
                             break;
                         }
                     }
                 } elseif ($this->data['basket']->totals->grand == 0) {
                     //	Incase it's already there for some reason
                     $this->shop_basket_model->remove_payment_gateway();
                     // --------------------------------------------------------------------------
                     $_uri = app_setting('url', 'shop') . 'checkout/confirm';
                     $_uri .= $this->data['guest'] ? '?guest=true' : '';
                     redirect($_uri);
                 }
                 // --------------------------------------------------------------------------
                 here();
                 //	Something went wrong.
                 $this->data['error'] = '<strong>Sorry,</strong> we couldn\'t verify your payment option. Please try again.';
             } else {
                 $this->data['error'] = lang('fv_there_were_errors');
             }
         }
         // --------------------------------------------------------------------------
         //	Set appropriate title
         $_titles = array();
         if ($this->data['guest']) {
             $_titles[] = 'Personal Details';
         }
         if ($this->data['requires_shipping']) {
             $_titles[] = 'Shipping Details';
         }
         if (count($this->data['payment_gateways']) > 1) {
             $_titles[] = 'Payment Options';
         }
         $this->data['page']->title = 'Checkout &rsaquo; ' . str_lreplace(', ', ' &amp; ', implode(', ', $_titles));
         // --------------------------------------------------------------------------
         //	Load veiws
         $this->load->view('structure/header', $this->data);
         $this->load->view('shop/' . $this->_skin->dir . '/checkout/checkout', $this->data);
         $this->load->view('structure/footer', $this->data);
     } else {
         $this->data['page']->title = 'Checkout &rsaquo; Please Sign In';
         // --------------------------------------------------------------------------
         $this->lang->load('auth/auth');
         // --------------------------------------------------------------------------
         $this->load->view('structure/header', $this->data);
         $this->load->view('shop/' . $this->_skin->dir . '/checkout/signin', $this->data);
         $this->load->view('structure/footer', $this->data);
     }
 }