public function featurepayment($page = '0', $id = '')
 {
     $this->load->helper('date');
     $datestring = "%Y-%m-%d";
     $time = time();
     $request_date = mdate($datestring, $time);
     $package_id = $this->input->post('package_id');
     $this->load->model('admin/package_model');
     $package = $this->package_model->get_package_by_id($package_id);
     $post_id = $this->session->userdata('feature_post_id');
     if ($post_id == FALSE) {
         $this->session->set_flashdata('msg', '<div class="alert alert-danger">' . lang_key('invalid_post') . '</div>');
         redirect(site_url('admin/classified/allposts'));
     }
     $payment_data = array();
     $payment_data['unique_id'] = uniqid();
     $payment_data['post_id'] = $post_id;
     $payment_data['package_id'] = $package_id;
     $payment_data['amount'] = $package->price;
     $payment_data['request_date'] = $request_date;
     $payment_data['is_active'] = 2;
     #pending
     $payment_data['status'] = 1;
     #active
     if ($this->session->userdata('feature_post_type') == 'renew') {
         $payment_data['payment_type'] = 'feature_renew';
     } else {
         $payment_data['payment_type'] = 'feature';
     }
     $payment_data['payment_medium'] = 'paypal';
     $this->load->model('user/payment_model');
     $unique_id = $this->payment_model->insert_property_payment_data($payment_data);
     $this->session->set_userdata('invoice_id', $unique_id);
     $this->session->set_userdata('amount', $package->price);
     $value['package'] = $package;
     if ($this->session->userdata('feature_post_type') == 'renew') {
         $value['renew'] = 'renew';
     }
     $value['unique_id'] = $payment_data['unique_id'];
     if ($value['package']->price <= 0) {
         $activation_date = mdate($datestring, $time);
         $expirtion_date = strtotime('+' . $package->expiration_time . ' days', $time);
         $expirtion_date = mdate($datestring, $expirtion_date);
         $data = array();
         $data['is_active'] = 1;
         $data['activation_date'] = $activation_date;
         $data['expiration_date'] = $expirtion_date;
         $data['response_log'] = 'Success with free featured package';
         $this->payment_model->update_post_payment_data_by_unique_id($data, $unique_id);
         $this->load->model('user/post_model');
         if (isset($value['renew']) && $value['renew'] == 'renew') {
             if ($this->post_model->increment_featured_date($package->expiration_time, $post_id) == TRUE) {
                 $this->session->set_flashdata('msg', '<div class="alert alert-success">' . lang_key('feature_renewed') . '</div>');
             } else {
                 $this->session->set_flashdata('msg', '<div class="alert alert-danger">Error! Feature not renewed.</div>');
             }
         } else {
             $data = array();
             $data['featured_expiration_date'] = $expirtion_date;
             $data['featured'] = 1;
             $this->post_model->update_post($data, $post_id);
             $this->session->set_flashdata('msg', '<div class="alert alert-success">' . lang_key('post_featured') . '</div>');
         }
         $this->session->unset_userdata('feature_post_id');
         $this->session->unset_userdata('feature_post_type');
         redirect(site_url('admin/classified/allposts'));
     } else {
         $email_info = array();
         $email_info['user_name'] = $this->session->userdata('user_name');
         $email_info['user_email'] = $this->session->userdata('user_email');
         if (isset($value['renew']) && $value['renew'] == 'renew') {
             $email_info['link'] = site_url('admin/classified/resume_feature_payment/' . 'u_id=' . $unique_id . '+renew=renew');
         } else {
             $email_info['link'] = site_url('admin/classified/resume_feature_payment/' . 'u_id=' . $unique_id);
         }
         send_payment_confirmation_email($email_info);
         $data['content'] = load_admin_view('packages/feature_payment_confirmation_view', $value, TRUE);
         load_admin_view('template/template_view', $data);
     }
 }
 public function save_renew_payment_history($post_id)
 {
     if (get_settings('package_settings', 'enable_pricing', 'Yes') == 'Yes' && $this->session->userdata('selected_renew_package') == FALSE || $this->session->userdata('selected_renew_package') == '') {
         $this->session->set_flashdata('msg', '<div class="alert alert-danger">Invalid data!</div>');
         redirect(site_url('admin/business/allposts'));
     }
     $this->load->helper('date');
     $datestring = "%Y-%m-%d";
     $time = time();
     $request_date = mdate($datestring, $time);
     $package_id = $this->session->userdata('selected_renew_package');
     $this->session->set_userdata('selected_renew_package', '');
     $this->load->model('admin/package_model');
     $package = $this->package_model->get_package_by_id($package_id);
     $payment_data = array();
     $payment_data['unique_id'] = uniqid();
     $payment_data['post_id'] = $post_id;
     $payment_data['package_id'] = $package_id;
     $payment_data['amount'] = $package->price;
     $payment_data['request_date'] = $request_date;
     $payment_data['is_active'] = 2;
     #pending
     $payment_data['status'] = 1;
     #active
     $payment_data['payment_type'] = 'post_renew';
     $payment_data['payment_medium'] = 'paypal';
     $unique_id = $this->payment_model->insert_property_payment_data($payment_data);
     $value = array();
     $value['package'] = $package;
     $value['unique_id'] = $unique_id;
     if ($value['package']->price <= 0) {
         $this->load->helper('date');
         $format = 'DATE_RFC822';
         $time = time();
         $activation_date = mdate($datestring, $time);
         $expirtion_date = strtotime('+' . $package->expiration_time . ' days', $time);
         $expirtion_date = mdate($datestring, $expirtion_date);
         $data = array();
         $data['is_active'] = 1;
         $data['activation_date'] = $activation_date;
         $data['expiration_date'] = $expirtion_date;
         $data['response_log'] = 'Free package';
         $this->payment_model->update_post_payment_data_by_unique_id($data, $uniqid);
         //we don't check for admin approval for renew package of a post
         $data = array();
         $data['expirtion_date'] = $expirtion_date;
         $data['activation_date'] = $activation_date;
         $data['last_update_time'] = $time;
         $data['status'] = 1;
         $this->load->model('admin/business_model');
         // echo "<pre>";
         // die(print_r($data));
         $this->business_model->update_post_by_id($data, $post_id);
         $this->session->set_flashdata('msg', '<div class="alert alert-success">' . lang_key('post_package_renewed') . '</div>');
         redirect(site_url('edit-business/0/' . $post_id));
     } else {
         $email_info = array();
         $email_info['user_name'] = $this->session->userdata('user_name');
         $email_info['user_email'] = $this->session->userdata('user_email');
         $email_info['link'] = site_url('user/payment/resume_payment/' . 'u_id=' . $unique_id . '+renew=renew');
         send_payment_confirmation_email($email_info);
         $value['renew'] = 'renew';
         $data['content'] = load_view('confirmation_view', $value, TRUE);
         load_template($data, $this->active_theme);
     }
 }