Пример #1
0
 function invite_friend()
 {
     //SESSION LOGGED DATA
     $logged_main_group_id = $this->session->userdata('user_group_id');
     //CONFIG ITEM
     $group_id_user = $this->config->item('group_id_user');
     if ($logged_main_group_id == $group_id_user) {
         //LOGGED CORRECT
         $data['message'] = $this->session->flashdata('message');
         //POST SUBMIT
         if ($this->input->post()) {
             //LOGGED
             $logged_user_id = $this->session->userdata('user_id');
             $where_read_user = array('id' => $logged_user_id);
             $query_read_user = $this->albert_model->read_user($where_read_user);
             $logged_user_email = $query_read_user->row()->email;
             //INPUT POST
             $input_email = $this->input->post('email');
             //VALIDATION
             $this->form_validation->set_rules('email', 'E-mail Address', 'required|valid_email');
             if ($this->form_validation->run() == true) {
                 //VALIDATION SUCCESS
                 $current_month = date("n");
                 $current_year = date("Y");
                 //READ USER_INVITE_FRIEND
                 $where_user_invite_friend = array('user_id' => $logged_user_id, 'friend_email' => $input_email);
                 $query_user_invite_friend = $this->albert_model->read_user_invite_friend($where_user_invite_friend);
                 $num_rows_user_invite_friend = $query_user_invite_friend->num_rows();
                 if ($num_rows_user_invite_friend > 0) {
                     //DUPLICATED DATA
                     $this->session->set_flashdata('message', "You had already invited '{$input_email}'");
                 } else {
                     //QUERY CANDIE BALANCE
                     $where_candie_balance = array('user_id' => $logged_user_id, 'month_id' => $current_month, 'year' => $current_year);
                     $query_candie_balance = $this->albert_model->read_candie_balance($where_candie_balance);
                     $num_rows_candie_balance = $query_candie_balance->num_rows();
                     if ($this->invite_friend_send_email($input_email, $logged_user_email)) {
                         if ($num_rows_candie_balance > 0) {
                             //UPDATE CANDIE BALANCE
                             $where_candie_balance_invite_friend_count_increment = array('user_id' => $logged_user_id, 'month_id' => $current_month, 'year' => $current_year);
                             $this->albert_model->update_candie_balance_invite_friend_count_increment($where_candie_balance_invite_friend_count_increment);
                             if ($this->db->affected_rows() == 0) {
                                 //INSERT FAIL
                                 $this->session->set_flashdata('message', 'Update fail for candie');
                             }
                         } else {
                             $data_candie_balance = array('user_id' => $logged_user_id, 'month_id' => $current_month, 'year' => $current_year, 'month_last_date' => displayDate(displayLastDay($current_year, $current_month), 0, 1));
                             $this->albert_model->insert_candie_balance($data_candie_balance);
                             if ($this->db->affected_rows() == 0) {
                                 //INSERT FAIL
                                 $this->session->set_flashdata('message', 'Insert fail for candie');
                             }
                             $query_candie_balance = $this->albert_model->read_candie_balance($where_candie_balance);
                         }
                         //INSERT USER_INVITE_FRIEND
                         $data_user_invite_friend = array('user_id' => $logged_user_id, 'friend_email' => $input_email);
                         $this->albert_model->insert_user_invite_friend($data_user_invite_friend);
                         if ($this->db->affected_rows() == 0) {
                             //INSERT FAIL
                             $this->session->set_flashdata('message', 'Insert fail for invite friend');
                         }
                         //INSERT SUCCESS
                         $this->session->set_flashdata('message', 'Invitation email sent');
                         //GIVE USER CANDIE FOR THE FIRST 5 INVITATION MONTHLY
                         $invitation_send_current_month = $query_candie_balance->row_array();
                         $user_max_invitation_get_candie_per_month = $this->m_custom->web_setting_get('user_max_invitation_get_candie_per_month');
                         if ($invitation_send_current_month['invite_friend_count'] <= $user_max_invitation_get_candie_per_month) {
                             $this->m_user->candie_history_insert(6, $invitation_send_current_month['balance_id'], 'candie_balance', 1);
                         }
                     }
                 }
                 redirect('user/invite_friend', 'refresh');
             } else {
                 //VALIDATION FAIL
                 $this->session->set_flashdata('message', validation_errors());
                 redirect('user/invite_friend', 'refresh');
             }
         }
     } else {
         //LOGGED INCORRECT
         redirect('/', 'refresh');
     }
     $data['page_path_name'] = 'user/invite_friend';
     $this->load->view('template/index', $data);
 }
Пример #2
0
 public function explode_year_month($year_month)
 {
     $pieces = explode("-", $year_month);
     $return = array('year' => $pieces[0], 'month' => $pieces[1], 'month_text' => $this->m_custom->display_static_option($pieces[1]), 'month_year_text' => $this->m_custom->display_static_option($pieces[1]) . ' ' . $pieces[0], 'month_first_date' => displayDate(displayFirstDay($pieces[0], $pieces[1]), 0, 1), 'month_last_date' => displayDate(displayLastDay($pieces[0], $pieces[1]), 0, 1));
     return $return;
 }
Пример #3
0
 public function merchant_balance_update($merchant_id, $month_id = NULL, $year = NULL)
 {
     $search_date = date_for_db_search($month_id, $year);
     if (empty($month_id)) {
         $month_id = get_part_of_date('month');
     }
     if (empty($year)) {
         $year = get_part_of_date('year');
     }
     $history_condition = "trans_time like '%" . $search_date . "%'";
     $history_search_data = array('merchant_id' => $merchant_id);
     $this->db->where($history_condition);
     $history_query = $this->db->get_where('transaction_history', $history_search_data);
     $history_result = $history_query->result_array();
     if ($history_query->num_rows() != 0) {
         $monthly_balance = 0;
         foreach ($history_result as $history_row) {
             $monthly_balance = $monthly_balance + $history_row['amount_plus'] - $history_row['amount_minus'];
         }
         $balance_search_data = array('merchant_id' => $merchant_id, 'month_id' => $month_id, 'year' => $year);
         $balance_query = $this->db->get_where('merchant_balance', $balance_search_data);
         if ($balance_query->num_rows() == 0) {
             $insert_data = array('merchant_id' => $merchant_id, 'balance' => $monthly_balance, 'month_id' => $month_id, 'year' => $year, 'month_last_date' => displayDate(displayLastDay($year, $month_id), 0, 1));
             $this->db->insert('merchant_balance', $insert_data);
         } else {
             $balance_result = $balance_query->row_array();
             $update_data = array('balance' => $monthly_balance);
             $this->db->where('balance_id', $balance_result['balance_id']);
             $this->db->update('merchant_balance', $update_data);
         }
     }
 }
Пример #4
0
 function displayLastDayTime($year = '', $month = '', $until_today = 0)
 {
     $the_date = displayLastDay($year, $month, $until_today);
     $return_date = displayDate($the_date, 0, 1);
     return $return_date . " 23:59:59";
 }