public function remove($model, RM_Services $service, $request, $params)
 {
     $selected = isset($request->req['rm_selected']) ? $request->req['rm_selected'] : null;
     $remove = json_decode($selected);
     $service->remove($remove);
     $service->remove_form_fields($remove);
     $service->remove_form_submissions($remove);
     $service->remove_form_payment_logs($remove);
     $service->remove_form_stats($remove);
     $service->remove_form_notes($remove);
     $this->manage($model, $service, $request, $params);
 }
 public function remove($model, RM_Services $service, $request, $params)
 {
     $selected = isset($request->req['rm_selected']) ? $request->req['rm_selected'] : null;
     if ($selected != null) {
         $service->remove_submissions($selected);
         $service->remove_submission_notes($selected);
         $service->remove_submission_payment_logs($selected);
     }
     RM_Utilities::redirect('?page=rm_submission_manage');
 }
 public function remove($model, RM_Services $service, $request, $params)
 {
     $selected = isset($request->req['rm_selected']) ? $request->req['rm_selected'] : null;
     $service->remove($selected);
     $this->manage($model, $service, $request, $params);
 }
 public function get_all($model_identifier = null, $offset = 0, $limit = 15, $column = '*', $sort_by = '', $descending = false)
 {
     return parent::get_all($model_identifier, $offset, $limit, $column, $sort_by, $descending);
 }
 public function process_payment($form_id, $reg_data, $service, $request)
 {
     //echo "<pre>"; var_dump($_GET); die;
     $payment_fields = array();
     foreach ($request->req as $field_name => $field_value) {
         if (substr($field_name, 0, 5) === 'Price') {
             $payment_fields[$field_name] = $field_value;
         }
     }
     //echo "<br>id= ".explode("_", $field_name)[2];
     //var_dump($payment_fields);
     //die;
     $sandbox = parent::get_setting('paypal_test_mode');
     $paypal_email = parent::get_setting('paypal_email');
     $currency = parent::get_setting('currency');
     $paypal_page_style = parent::get_setting('paypal_page_style');
     require_once plugin_dir_path(plugin_dir_path(__FILE__)) . 'external/PayPal/paypal.php';
     $p = new paypal_class();
     // paypal class
     if ($sandbox == 'yes') {
         $p->toggle_sandbox(true);
     } else {
         $p->toggle_sandbox(false);
     }
     $p->admin_mail = get_option('admin_email');
     // set notification email
     if (isset($request->req['rm_pproc'])) {
         switch ($request->req['rm_pproc']) {
             case 'success':
                 if (isset($request->req['rm_pproc_id'])) {
                     $log_id = $request->req['rm_pproc_id'];
                     $log = RM_DBManager::get_row('PAYPAL_LOGS', $log_id);
                     if ($log) {
                         if ($log->log) {
                             $paypal_log = maybe_unserialize($log->log);
                             $payment_status = $paypal_log['payment_status'];
                             if ($payment_status == 'Completed') {
                                 echo '<div id="rmform">';
                                 echo "<div class='rminfotextfront'>" . RM_UI_Strings::get("MSG_PAYMENT_SUCCESS") . "</br>";
                                 echo '</div></div>';
                                 return 'success';
                             } else {
                                 if ($payment_status == 'Denied' || $payment_status == 'Failed' || $payment_status == 'Refunded' || $payment_status == 'Reversed' || $payment_status == 'Voided') {
                                     echo '<div id="rmform">';
                                     echo "<div class='rminfotextfront'>" . RM_UI_Strings::get("MSG_PAYMENT_FAILED") . "</br>";
                                     echo '</div></div>';
                                     return 'failed';
                                 } else {
                                     if ($payment_status == 'In-Progress' || $payment_status == 'Pending' || $payment_status == 'Processed') {
                                         echo '<div id="rmform">';
                                         echo "<div class='rminfotextfront'>" . RM_UI_Strings::get("MSG_PAYMENT_PENDING") . "</br>";
                                         echo '</div></div>';
                                         return 'pending';
                                     } else {
                                         if ($payment_status == 'Canceled_Reversal') {
                                             return 'canceled_reversal';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 return false;
             case 'cancel':
                 echo '<div id="rmform">';
                 echo "<div class='rminfotextfront'>" . RM_UI_Strings::get("MSG_PAYMENT_CANCEL") . "</br>";
                 echo '</div></div>';
                 return;
             case 'ipn':
                 $trasaction_id = $_POST["txn_id"];
                 $payment_status = $_POST["payment_status"];
                 $cstm = $_POST["custom"];
                 $abcd = explode("|", $cstm);
                 $user_id = (int) $abcd[1];
                 $acbd = explode("|", $cstm);
                 $log_entry_id = (int) $acbd[0];
                 //$_POST["custom"];
                 $log_array = maybe_serialize($_POST);
                 $curr_date = RM_Utilities::get_current_time();
                 // date_i18n(get_option('date_format'));
                 RM_DBManager::update_row('PAYPAL_LOGS', $log_entry_id, array('status' => $payment_status, 'txn_id' => $trasaction_id, 'posted_date' => $curr_date, 'log' => $log_array), array('%s', '%s', '%s', '%s'));
                 if ($p->validate_ipn()) {
                     //IPN is valid, check payment status and process logic
                     if ($payment_status == 'Completed') {
                         if ($user_id) {
                             $gopt = new RM_Options();
                             $this->user_service->activate_user_by_id($user_id);
                         }
                         return 'success';
                     } else {
                         if ($payment_status == 'Denied' || $payment_status == 'Failed' || $payment_status == 'Refunded' || $payment_status == 'Reversed' || $payment_status == 'Voided') {
                             return 'failed';
                         } else {
                             if ($payment_status == 'In-Progress' || $payment_status == 'Pending' || $payment_status == 'Processed') {
                                 return 'pending';
                             } else {
                                 if ($payment_status == 'Canceled_Reversal') {
                                     return 'canceled_reversal';
                                 }
                             }
                         }
                     }
                     //Send mail notifications about payment success.
                     /* $recipients = parent::get_setting('admin_email');
                     
                                               if ($recipients)
                                               {
                                               $recipients = explode(',', $recipients);
                     
                                               foreach ($recipients as $recipient)
                                               {
                                               $p->send_report($recipient);
                                               }
                                               } */
                     return 'unknown';
                 }
                 return 'invalid_ipn';
         }
         //return;
     }
     $paypal_field = new RM_PayPal_Fields();
     $prices = array();
     $item_names = array();
     foreach ($payment_fields as $pf_name => $pf_value) {
         $abe = explode("_", $pf_name);
         $paypal_field->load_from_db((int) $abe[2]);
         switch ($paypal_field->get_type()) {
             case "fixed":
                 $prices[] = $paypal_field->get_value();
                 $item_names[] = $paypal_field->get_name();
                 break;
             case "userdef":
                 if ($pf_value == "") {
                     break;
                 }
                 $prices[] = $pf_value;
                 $item_names[] = $paypal_field->get_name();
                 break;
             case "multisel":
                 $tmp_v = maybe_unserialize($paypal_field->get_option_price());
                 $tmp_l = maybe_unserialize($paypal_field->get_option_label());
                 foreach ($pf_value as $pf_single_val) {
                     $index = (int) substr($pf_single_val, 1);
                     if (!isset($tmp_v[$index])) {
                         continue;
                     }
                     $prices[] = $tmp_v[$index];
                     $item_names[] = $tmp_l[$index];
                 }
                 break;
             case "dropdown":
                 $tmp_v = maybe_unserialize($paypal_field->get_option_price());
                 $tmp_l = maybe_unserialize($paypal_field->get_option_label());
                 //Check whether dropdown was not submitted
                 if (!$pf_value) {
                     break;
                 }
                 $index = (int) substr($pf_value, 1);
                 if (!isset($tmp_v[$index])) {
                     break;
                 }
                 $prices[] = $tmp_v[$index];
                 $item_names[] = $tmp_l[$index];
                 break;
         }
     }
     /*
      echo "<br><br>========  names =============<br><br>";
      var_dump($item_names);
      echo "<br><br>========  prices =============<br><br>";
      var_dump($prices);
      die;
     */
     $this_script = get_permalink();
     $sign = strpos($this_script, '?') ? '&' : '?';
     $i = 1;
     foreach ($item_names as $item_name) {
         $p->add_field('item_name_' . $i, $item_name);
         $i++;
     }
     $i = 1;
     $total_amount = 0.0;
     foreach ($prices as $price) {
         $p->add_field('amount_' . $i, $price);
         $total_amount += floatval($price);
         $i++;
     }
     $invoice = (string) date("His") . rand(1234, 9632);
     $p->add_field('business', $paypal_email);
     // Call the facilitator eaccount
     $p->add_field('cmd', '_cart');
     // cmd should be _cart for cart checkout
     $p->add_field('upload', '1');
     $p->add_field('return', $this_script . $sign . 'rm_pproc=success&rm_pproc_id=');
     // return URL after the transaction got over
     $p->add_field('cancel_return', $this_script . $sign . 'rm_pproc=cancel');
     // cancel URL if the trasaction was cancelled during half of the transaction
     $p->add_field('notify_url', $this_script . $sign . 'rm_pproc=ipn');
     // Notify URL which received IPN (Instant Payment Notification)
     $p->add_field('currency_code', $currency);
     $p->add_field('invoice', $invoice);
     $p->add_field('page_style', $paypal_page_style);
     //Insert into PayPal log table
     $curr_date = RM_Utilities::get_current_time();
     //date_i18n(get_option('date_format'));
     if ($total_amount <= 0.0) {
         $log_entry_id = RM_DBManager::insert_row('PAYPAL_LOGS', array('submission_id' => $reg_data->submission_id, 'form_id' => $form_id, 'invoice' => $invoice, 'status' => 'Completed', 'total_amount' => $total_amount, 'currency' => $currency, 'posted_date' => $curr_date), array('%d', '%d', '%s', '%s', '%f', '%s', '%s'));
         return 'zero_amount';
     } else {
         $log_entry_id = RM_DBManager::insert_row('PAYPAL_LOGS', array('submission_id' => $reg_data->submission_id, 'form_id' => $form_id, 'invoice' => $invoice, 'status' => 'Pending', 'total_amount' => $total_amount, 'currency' => $currency, 'posted_date' => $curr_date), array('%d', '%d', '%s', '%s', '%f', '%s', '%s'));
     }
     $p->add_field('custom', $log_entry_id . "|" . $reg_data->user_id);
     $p->add_field('return', $this_script . $sign . 'rm_pproc=success&rm_pproc_id=' . $log_entry_id);
     // return URL after the transaction got over
     $p->add_field('cancel_return', $this_script . $sign . 'rm_pproc=cancel&rm_pproc_id=' . $log_entry_id);
     // cancel URL if the trasaction was cancelled during half of the transaction
     $p->add_field('notify_url', $this_script . $sign . 'rm_pproc=ipn');
     // Notify URL which received IPN (Instant Payment Notification)
     $p->submit_paypal_post();
     // POST it to paypal
     //$p->dump_fields();
 }
 public function get_fab_icon()
 {
     $rm_services = new RM_Services();
     $icon_src = RM_IMG_URL . "user.png";
     $fab_icon = $rm_services->get_setting('fab_icon');
     if ($fab_icon) {
         $src = wp_get_attachment_image_url($fab_icon);
         if ($src) {
             $icon_src = $src;
         }
     }
     return $icon_src;
 }
 public function mc_field_mapping($form, $form_options, $list = null)
 {
     if (!$list) {
         $list = $form_options->mailchimp_list;
     }
     $mailchimp = new RM_MailChimp_Service();
     $details = $this->get_list_field($list);
     $service = new RM_Services();
     $all_field_objects = $service->get_all_form_fields($form);
     if (is_array($all_field_objects) || is_object($all_field_objects)) {
         $form_fields = '';
     }
     $form_fields_email = '';
     $field_type_array = array();
     $field_type_array['text'] = array();
     $field_type_array['number'] = array();
     $field_type_array['dropdown'] = array();
     $field_type_array['radio'] = array();
     $field_type_array['date'] = array();
     foreach ($all_field_objects as $obj) {
         if ($obj->field_type == 'Email') {
             $form_type_id = $obj->field_type . '_' . $obj->field_id;
             //
             if ($form_type_id == $form_options->mailchimp_mapped_email) {
                 $form_fields_email .= '<option value=' . $form_type_id . ' selected>' . $obj->field_label . '</option>';
             } else {
                 $form_fields_email .= '<option value=' . $form_type_id . '>' . $obj->field_label . '</option>';
             }
             //$data->all_fields[$obj->field_type . '_' . $obj->field_id] = $obj->field_label;
         }
         $field_type = $obj->field_type;
         switch ($field_type) {
             case 'Textbox':
             case 'HTMLP':
             case 'Country':
             case 'Terms':
             case 'Fname':
             case 'Lname':
             case 'BInfo':
             case 'Email':
                 $field_type = 'text';
                 $form_type_id = $obj->field_type . '_' . $obj->field_id;
                 //
                 $field_type_array[$field_type][$form_type_id] = $obj->field_label;
                 break;
             case 'Select':
                 $field_type = 'dropdown';
                 $form_type_id = $obj->field_type . '_' . $obj->field_id;
                 //
                 $field_type_array[$field_type][$form_type_id] = $obj->field_label;
                 break;
             case 'Radio':
                 $field_type = 'radio';
                 $form_type_id = $obj->field_type . '_' . $obj->field_id;
                 //
                 $field_type_array[$field_type][$form_type_id] = $obj->field_label;
                 break;
             case 'jQueryUIDate':
                 $field_type = 'date';
                 $form_type_id = $obj->field_type . '_' . $obj->field_id;
                 //
                 $field_type_array[$field_type][$form_type_id] = $obj->field_label;
                 break;
             case 'Number':
                 $field_type = 'number';
                 $form_type_id = $obj->field_type . '_' . $obj->field_id;
                 //
                 $field_type_array[$field_type][$form_type_id] = $obj->field_label;
                 break;
             case 'Price':
                 $field_type = 'text';
                 $form_type_id = $obj->field_type . '_' . $obj->field_id;
                 //
                 $field_type_array[$field_type][$form_type_id] = $obj->field_label;
                 break;
         }
         //$data->all_fields[$obj->field_type . '_' . $obj->field_id] = $obj->field_label;
     }
     $content = '<div class="rmrow">
                         <div class="rmfield">
                                  <label> <b>Email</b></label>
                                  </div>
                         <div class="rminput">
                                  <Select name="email" selected="' . $form_options->mailchimp_mapped_email . '"><option value="">' . RM_UI_Strings::get('SELECT_FIELD') . '</option>' . $form_fields_email . '</Select>' . '</div>' . '</div>';
     if ($details && isset($details['merge_fields'])) {
         foreach ($details['merge_fields'] as $det) {
             $options = '<option value="">' . RM_UI_Strings::get('SELECT_FIELD') . '</option>';
             foreach ($field_type_array as $type => $fld) {
                 if ($fld != null && $type == $det['type']) {
                     foreach ($fld as $field_type_id => $field_type_value) {
                         if ($field_type_id == $form_options->mailchimp_relations->{$list . '_' . $det['tag']}) {
                             $options .= '<option value="' . $field_type_id . '" selected>' . $field_type_value . '</option>';
                         } else {
                             $options .= '<option value="' . $field_type_id . '">' . $field_type_value . '</option>';
                         }
                     }
                 }
             }
             $content .= '<div class="rmrow">
                         <div class="rmfield">
                                  <label> <b>' . $det['name'] . '</b></label>
                         </div>
                         <div class="rminput">
                                  <Select name="' . $list . '_' . $det['tag'] . '">' . $options . '</Select>' . '</div>' . '</div>';
         }
     }
     return $content;
 }
 public function send_user($email, $username, $password, $content)
 {
     $send_details = parent::get_setting('send_password');
     //echo $content;
     if ($send_details == "yes") {
         RM_Utilities::send_email($email, $content);
     }
 }