Esempio n. 1
0
 public function login()
 {
     $inputs['username'] = array('type' => 'input', 'label' => 'Username', 'rules' => 'required');
     $inputs['password'] = array('type' => 'password', 'label' => 'Password', 'rules' => 'required');
     if (rbt_valid_post($inputs)) {
         $this->load->model('users');
         $response = $this->users->login($this->input->post('username'), $this->input->post('password'));
         if ($response['status']) {
             toshout(array($response['message'] => 'success'));
             redirect('dashboard/index');
         } else {
             toshout(array($response['message'] => 'danger'));
         }
         // show_sess();
     }
     $data['inputs'] = $inputs;
     $this->load->view('umum_login', $data);
 }
Esempio n. 2
0
function rbt_valid_post($inputs)
{
    //dumper($inputs);
    /***********************************
    		Self-Notes: 
    		Next thing to do here ->
    		Need to make sure if only upload form
    		is there, the validation still can be
    		run as usual. Right now need to make
    		workaroud by adding hidden input form
    		with nonsense value.
    		***********************************/
    $CI =& get_instance();
    $CI->load->library('form_validation');
    //only on post
    if ($CI->input->post()) {
        foreach ($inputs as $name => $input) {
            //prep and test for normal input fields
            if (array_key_exists('rules', $input) && $input['type'] != 'upload') {
                $CI->form_validation->set_rules($name, $input['display'], $input['rules']);
            }
            //prepare and test for uploads data from upload fields
            if ($input['type'] == 'upload') {
                $uploads[$name] = $input;
            }
        }
        ///Validate all form inputs data except uploads form
        if ($CI->form_validation->run() != FALSE) {
            $ret_form = TRUE;
        } else {
            $ret_form = FALSE;
        }
        $ret_upload = TRUE;
        //check validation for uploads
        if (count($_FILES) > 0) {
            foreach ($uploads as $name => $upload) {
                if ($_FILES[$name]['size'] > 0) {
                    //create rules
                    $rules_raw = explode('|', $upload['rules']);
                    foreach ($rules_raw as $value) {
                        $exp = explode(':', $value);
                        if (count($exp) == 1) {
                            $to_check[$exp[0]] = TRUE;
                        } else {
                            $upload_config[$exp[0]] = str_replace(',', '|', $exp[1]);
                        }
                    }
                    //dumper($upload_config);
                    $CI->load->library('upload', $upload_config);
                    if (!$CI->upload->do_upload($name)) {
                        // if error
                        $upload_error = $CI->upload->display_errors();
                        $ret_upload = FALSE;
                        toshout(array($upload_error => 'error'));
                    } else {
                        //if success
                        //set $_POST to filename
                        $data = $CI->upload->data();
                        $_POST[$name] = $data['file_name'];
                    }
                }
            }
        }
        if (count($_FILES) > 0) {
            $ret = ($ret_form and $ret_upload);
        } else {
            $ret = $ret_form;
        }
        return $ret;
    }
}
Esempio n. 3
0
 function delete()
 {
     $seg = $this->uri->segment_array();
     $table = $seg[3];
     $column = $seg[4];
     $key = $seg[5];
     unset($seg[1]);
     unset($seg[2]);
     unset($seg[3]);
     unset($seg[4]);
     unset($seg[5]);
     $red = implode('/', $seg);
     $this->db->where(array($column => $key));
     $this->db->delete($table);
     toshout('The data has been deleted!', 'success');
     redirect($this->input->server('HTTP_REFERER'));
 }
Esempio n. 4
0
 function test_acl()
 {
     if ($this->uri->segment(1)) {
         //kalau xder site url means home. Home is ok
         if ($this->uri->segment(1)) {
             $site_url = $this->uri->segment(1);
         }
         if ($this->uri->segment(2)) {
             $site_url .= '/' . $this->uri->segment(2);
         }
         $root = false;
         if ($this->session->userdata('tags_id') && $this->session->userdata('id')) {
             //kalau login
             //kalau tag_id = 0 => developer => bagi semua!
             if (array_search(1, $this->session->userdata('tags_id')) !== FALSE) {
                 $root = true;
             }
             //kalau bukan root, filter features by public, private and controlled
             if (!$root) {
                 foreach ($this->session->userdata('tags_id') as $tags_id) {
                     $where[] = "(`type`='tags' AND `type_id`=" . $tags_id . ")";
                 }
                 $where[] = "(`type`='users' AND `type_id`=" . $this->session->userdata('id') . ")";
                 $this->db->select('feature_id');
                 $this->db->where(implode(' OR ', $where));
                 $qcontrolled_id = $this->db->get('access');
                 $where = array();
                 foreach ($qcontrolled_id->result_array() as $ids) {
                     $this->db->or_where("(`access`=3 AND `id`=" . $ids['feature_id'] . ')');
                 }
                 //$where = $controlled_id;
                 if (!$root) {
                     $this->db->or_where("(`access`=2)");
                 }
             }
         }
         if (!$root) {
             $this->db->or_where("(`access`=1)");
         }
         $qfeatures = $this->db->get('features');
         //dapatkan semua yang boleh masuk
         $class_match = false;
         $url_match = false;
         //dumper($this->db->last_query());
         foreach ($qfeatures->result_array() as $rows) {
             $oks[$rows['id']] = $rows['site_url'];
             //if($rows['dashboard']) $dash[$rows['id']] = $rows;
             if ($rows['site_url'] == $this->uri->segment(1)) {
                 $class_match = TRUE;
             }
             //show on dashboard
             if ($rows['dashboard']) {
                 $board[$rows['id']] = $rows['site_url'];
             }
         }
         $dash['dashboard'] = $board;
         //check class
         if (array_search($site_url, $oks)) {
             $url_match = TRUE;
         }
         if (!($class_match or $url_match or $root)) {
             //if no match, tendang dia!
             //kalau x login suh dia login
             if ($this->session->userdata('tags_id') && $this->session->userdata('id')) {
                 toshout(array("Access denied. Please login:"******"Access denied. Please check your access card." => 'error'));
                 //redirect('main/404');
             }
         } else {
             $this->session->set_userdata($dash);
             //show_sess();
         }
     }
 }
Esempio n. 5
0
 public function new_data()
 {
     $inputs['datetime'] = array('type' => 'input', 'label' => 'Date & Time (Y-m-d H:m:s)', 'rules' => 'required');
     $inputs['weight'] = array('type' => 'input', 'label' => 'Weight (kg)', 'rules' => 'required|decimal');
     $inputs['fat'] = array('type' => 'input', 'label' => 'Fat (%)', 'rules' => 'required|decimal');
     $inputs['water'] = array('type' => 'input', 'label' => 'Water (%)', 'rules' => 'required|decimal');
     $inputs['muscle'] = array('type' => 'input', 'label' => 'Muscle (%)', 'rules' => 'required|decimal');
     $inputs['bone'] = array('type' => 'input', 'label' => 'Bone (%)', 'rules' => 'required|decimal');
     $inputs['kcal'] = array('type' => 'input', 'label' => 'KCal (kcal)', 'rules' => 'required|integer');
     $inputs['waist'] = array('type' => 'input', 'label' => 'Waist (cm)', 'rules' => 'required|integer');
     $defaults = array('datetime' => date('Y-m-d H:i:s'));
     if (rbt_valid_post($inputs)) {
         $user = $this->session->userdata('user');
         $_POST['user_id'] = $user['id'];
         // dumper($this->input->post());
         $this->db->insert('data', $this->input->post());
         toshout(array('Your data has been saved' => 'success'));
         redirect('dashboard/data');
     }
     $data['inputs'] = $inputs;
     $data['title'] = 'New Data';
     $data['defaults'] = $defaults;
     $this->load->view('dashboard_form', $data);
 }
Esempio n. 6
0
 public function proof_of_payment()
 {
     $purchase_key = $this->uri->segment(3);
     $method = $this->uri->segment(4);
     // $purchase_id = base64_decode($purchase_key.'==');
     if ($purchase_key !== null) {
         // $purchase_id = robot($purchase_key);
         $param = $_GET;
         // $param['purchase_key'] = $purchase_key;
         $param['purchase_key'] = $purchase_key;
         $param['method'] = $method;
         $this->session->set_flashdata('payment_param', $param);
         // dumper($param);
         redirect('umum/proof_of_payment');
     } else {
         $param = $this->session->flashdata('payment_param');
         // dumper('processing');
         // dumper($param);
         // check, kalau amount sama, then it is true
         $this->load->model('Purchase');
         $purchase = $this->Purchase->get_details($param['purchase_key']);
         if ($purchase['item_price'] == $param['amt'] && strtolower($param['st']) == 'completed') {
             $this->Purchase->approve_payment($param);
             // send mixpanel data
             $this->load->model('Mxtracker');
             // set mx_status: paid
             // set rm
             $this->Mxtracker->identify($purchase['device_id']);
             $this->Mxtracker->people_set($purchase['device_id'], array('mx_status' => 'close_sale', 'rm' => $purchase['item_price']));
             $this->Mxtracker->trackcharge($purchase['device_id'], $purchase['item_price'], date('Y-m-d H:i:s'));
             // $this->Mxtracker->track('close_sale');
             $this->Mxtracker->track('paypal_sale');
             $this->load->model('Despatch');
             $this->Purchase->email_download_link($param['purchase_key']);
             toshout(array('Download Email has been sent. Check your email (' . $purchase['order_email'] . ')' => 'success'));
         } else {
             toshout(array('Payments not approved. Something is wrong with your data. Please contact admin' => 'error'));
         }
         // show_sess();
         // shout();
         // redirect('umum/purchase/'.$param['purchase_key']);
         redirect('bayar/' . $param['purchase_key']);
     }
 }
Esempio n. 7
0
 function delete_author()
 {
     $this->db->where(array('id' => $this->uri->segment(3)));
     $this->db->delete('users');
     $this->db->where(array('user_id' => $this->uri->segment(3)));
     $this->db->delete('users_data');
     toshout(array('Maklumat penulis tersebut telah berjaya dipadam.' => 'notice'));
     redirect('user/author');
 }