public function manage($model, $service, $request, $params)
 {
     if (!isset($request->req['form_name'])) {
         Form::clearErrors('rm_form_quick_add');
     }
     $sort_by = isset($request->req['rm_sortby']) ? $request->req['rm_sortby'] : null;
     $descending = isset($request->req['rm_descending']) ? false : true;
     $req_page = isset($request->req['rm_reqpage']) && $request->req['rm_reqpage'] > 0 ? $request->req['rm_reqpage'] : 1;
     $items_per_page = 9;
     $forms = $service->get_all(null, ($req_page - 1) * $items_per_page, $items_per_page, '*', $sort_by, $descending);
     $i = 0;
     $data = array();
     if (is_array($forms) || is_object($forms)) {
         foreach ($forms as $form) {
             $data[$i] = new stdClass();
             $data[$i]->form_id = $form->form_id;
             $data[$i]->form_name = $form->form_name;
             $data[$i]->count = $service->count(RM_Submissions::get_identifier(), array('form_id' => $form->form_id));
             if ($data[$i]->count > 0) {
                 $data[$i]->submissions = $service->get(RM_Submissions::get_identifier(), array('form_id' => $form->form_id), array('%d'), 'results', 0, 3, '*', 'submitted_on', true);
                 $j = 0;
                 foreach ($data[$i]->submissions as $submission) {
                     $data[$i]->submissions[$j++]->gravatar = get_avatar($submission->user_email);
                 }
             }
             $data[$i]->field_count = $service->count(RM_Fields::get_identifier(), array('form_id' => $form->form_id));
             $data[$i]->last_sub = $service->get(RM_Submissions::get_identifier(), array('form_id' => $form->form_id), array('%d'), 'var', 0, 1, 'submitted_on', 'submitted_on', true);
             //$data[$i]->last_sub = date('H',strtotime($this->service->get(RM_Submissions::get_identifier(), array('form_id' => $data_single->form_id), array('%d'), 'var', 0, 1, 'submitted_on', 'submitted_on', true)));
             $data[$i]->expiry_details = $service->get_form_expiry_stats($form, false);
             $i++;
         }
     }
     $total_forms = $service->count($model->get_identifier(), 1);
     //New object to consolidate data for view.
     $view_data = new stdClass();
     $view_data->data = $data;
     $view_data->curr_page = $req_page;
     $view_data->total_pages = (int) ($total_forms / $items_per_page) + ($total_forms % $items_per_page == 0 ? 0 : 1);
     $view_data->rm_slug = $request->req['page'];
     $view_data->sort_by = $sort_by;
     $view_data->descending = $descending;
     $view_data->done_with_review_banner = $service->get_setting('done_with_review_banner') === 'no' ? false : true;
     $view_data->def_form_id = $service->get_setting('default_form_id');
     if (function_exists('is_multisite') && is_multisite()) {
         $nl_subscribed = get_site_option('rm_option_newsletter_subbed', false);
     } else {
         $nl_subscribed = get_site_option('rm_option_newsletter_subbed', false);
     }
     if (!$nl_subscribed) {
         $view_data->newsletter_sub_link = RM_UI_Strings::get('NEWSLETTER_SUB_MSG');
     } else {
         $view_data->newsletter_sub_link = null;
     }
     $view = $this->mv_handler->setView('form_manager');
     $view->render($view_data);
 }
 public function get_fields($form_id)
 {
     $where = array("form_id" => $form_id);
     $data_specifier = array("%s", "%d");
     $email_fields = RM_DBManager::get(RM_Fields::get_identifier(), $where, $data_specifier, $result_type = 'results', $offset = 0, $limit = 1000, $column = '*', $sort_by = null, $descending = false);
     $fields = array();
     foreach ($email_fields as $field) {
         if ($field->field_type != 'Price' && $field->field_type != 'HTMLH' && $field->field_type != 'File' && $field->field_type != 'HTMLP' && $field->field_type != 'Terms') {
             $fields[] = $field;
         }
     }
     return $fields;
 }
 public function duplicate_field($field_id, $form_id)
 {
     $model = new RM_Fields();
     $model->load_from_db($field_id, false);
     $model->set_form_id($form_id);
     $model->insert_into_db();
 }
 public function add($model, $service, $request, $params)
 {
     $valid = $is_checked = false;
     if ($this->mv_handler->validateForm("rm_form_add")) {
         $model->set($request->req);
         $valid = $model->validate_model();
         $is_checked = true;
     }
     if ($valid) {
         if (isset($request->req['form_id'])) {
             $valid = $service->update($request->req['form_id']);
         } else {
             $service->add_user_form();
         }
         RM_Utilities::redirect(admin_url('/admin.php?page=' . $params['xml_loader']->request_tree->success));
     } else {
         $data = new stdClass();
         /*
          * Loading all fields related this form
          */
         $data->all_fields = array("_0" => RM_UI_Strings::get('SELECT_DEFAULT_OPTION'));
         $data->email_fields = array("_0" => RM_UI_Strings::get('SELECT_DEFAULT_OPTION'));
         // Edit for request
         if (isset($request->req['rm_form_id'])) {
             if (!$is_checked) {
                 $model->load_from_db($request->req['rm_form_id']);
             }
             $all_field_objects = $service->get_all_form_fields($request->req['rm_form_id']);
             if (is_array($all_field_objects) || is_object($all_field_objects)) {
                 foreach ($all_field_objects as $obj) {
                     $data->all_fields[$obj->field_type . '_' . $obj->field_id] = $obj->field_label;
                 }
             }
             $data_specifier = array("%s", "%d");
             $where = array("field_type" => "Email", "form_id" => $request->req['rm_form_id']);
             $email_fields = RM_DBManager::get(RM_Fields::get_identifier(), $where, $data_specifier, $result_type = 'results', $offset = 0, $limit = 1000, $column = '*', $sort_by = null, $descending = false);
             if (is_array($email_fields) || is_object($email_fields)) {
                 foreach ($email_fields as $field) {
                     $data->email_fields[$field->field_type . '_' . $field->field_id] = $field->field_label;
                 }
             }
         }
         $data->model = $model;
         //By default make it registration type
         if (!isset($request->req['rm_form_id'])) {
             $data->model->set_form_type(1);
         }
         $user_roles_dd = RM_Utilities::user_role_dropdown(true);
         $data->roles = array('subscriber' => $user_roles_dd['subscriber']);
         $data->wp_pages = RM_Utilities::wp_pages_dropdown();
         if ($service->get_setting('enable_mailchimp') == 'yes') {
             $data->mailchimp_list = $service->get_mailchimp_list();
         } else {
             $data->mailchimp_list = array();
         }
         //echo "<pre>",var_dump($data->model);//die;
         $view = $this->mv_handler->setView("form_add");
         $view->render($data);
     }
 }
Example #5
0
 public function isValid($value)
 {
     $valid = true;
     $name_explode = explode("_", $this->name);
     $field_id = $name_explode[1];
     $field = new RM_Fields();
     $gopts = new RM_Options();
     $field->load_from_db($field_id);
     //Sanitize value before use, remove white space, trim extra pipes.
     $fv = explode("|", trim(preg_replace('/\\s+/', '', $field->get_field_value()), '|'));
     $allowed_types = array();
     $multiple = $gopts->get_value_of('allow_multiple_file_uploads');
     if (!$fv || count($fv) === 1 && $fv[0] == "") {
         $allowed_types = explode("|", $gopts->get_value_of('allowed_file_types'));
     } else {
         foreach ($fv as $key => $value) {
             $fv[$key] = strtolower($value);
         }
         $allowed_types = $fv;
     }
     //die;
     if ($multiple == "yes") {
         if (isset($_FILES[$this->name]) && !empty($_FILES[$this->name])) {
             foreach ($_FILES[$this->name]['name'] as $filename) {
                 if ($filename == "") {
                     if (!$this->isRequiredFileField) {
                         return true;
                     } else {
                         $this->message = " %element% " . RM_UI_Strings::get('ERROR_REQUIRED');
                         return false;
                     }
                 } elseif (strpos($filename, '.') === 0) {
                     return false;
                 } elseif (strpos($filename, '.') === false) {
                     return false;
                 } else {
                     $arrx = explode('.', $filename);
                     $ext = $arrx[count($arrx) - 1];
                     if ($ext == "") {
                         return false;
                     }
                     $ext = strtolower($ext);
                     if (!in_array($ext, $allowed_types)) {
                         return false;
                     }
                 }
             }
             return true;
         }
         return true;
     } else {
         if (isset($_FILES[$this->name]) && !empty($_FILES[$this->name])) {
             $filename = $_FILES[$this->name]['name'];
             if ($filename == "") {
                 if (!$this->isRequiredFileField) {
                     return true;
                 } else {
                     $this->message = " %element% " . RM_UI_Strings::get('ERROR_REQUIRED');
                     return false;
                 }
             } elseif (strpos($filename, '.') === 0) {
                 return false;
             } elseif (strpos($filename, '.') === false) {
                 return false;
             } else {
                 $arrx = explode('.', $filename);
                 $ext = $arrx[count($arrx) - 1];
                 if ($ext == "") {
                     return false;
                 }
                 if (!in_array($ext, $allowed_types)) {
                     return false;
                 }
             }
             return true;
         }
         return true;
     }
     return false;
 }
 public function save_form($request, $params, $register_user = true, $redirect_as_well = true)
 {
     if (isset($params['is_payment_form']) && $params['is_payment_done']) {
         //user already activated in 'ipn' case, do nothing.
         //register user if it was a 'zero_amount case'.
         if (isset($params['za_user_id']) && $params['za_user_id']) {
             $gopt = new RM_Options();
             $this->user_service->activate_user_by_id($params['za_user_id']);
         }
         $this->after_submission_proc($params);
         return;
     }
     $user_error = false;
     $form_fields = parent::get_all_form_fields($params['form']->form_id);
     $valid_field_ids = $profile_field_id = array();
     $form_type = $params['form']->form_type;
     $is_auto_generate = parent::get_setting('auto_generated_password');
     $email = null;
     $profile = array();
     $reg_data = new stdClass();
     $reg_data->submission_id = null;
     $reg_data->user_id = null;
     foreach ($form_fields as $form_field) {
         $valid_field_ids[] = $form_field->field_id;
         if ($form_field->field_type === 'Email' && $form_field->is_field_primary == 1) {
             $profile_field_id['email'] = $form_field->field_id;
         }
         if ($form_type == 1) {
             if ($form_field->field_type === 'Textbox' && $form_field->is_field_primary == 1) {
                 $profile_field_id['username'] = $form_field->field_id;
             }
             if ($form_field->field_type === 'Password' && $form_field->is_field_primary == 1) {
                 $profile_field_id['password'] = $form_field->field_id;
             }
         }
     }
     $submissions_data = array();
     $attachment = new RM_Attachment_Service();
     $att_ids = $attachment->attach();
     //var_dump($att_ids);
     foreach ($request->req as $key => $value) {
         $key_parts = explode('_', $key);
         $count_parts = count($key_parts);
         if (($count_parts === 2 || $count_parts === 3) && in_array($key_parts[1], $valid_field_ids, true)) {
             $field = new RM_Fields();
             $field->load_from_db($key_parts[1]);
             if ($field->field_type === $key_parts[0]) {
                 if ($field->field_type === "Password") {
                     if ($is_auto_generate === 'yes') {
                         $value = wp_generate_password(8, false);
                     }
                     //$value = md5($value);
                 } elseif ($field->field_type === "Fname" || $field->field_type === "Lname" || $field->field_type === "BInfo") {
                     $profile[$field->field_type] = $value;
                 } else {
                     if ($field->field_type === "File") {
                         $value = null;
                         foreach ($att_ids as $field_name => $att_id) {
                             $value = array();
                             if ($field_name == $key) {
                                 $value['rm_field_type'] = 'File';
                                 if (is_array($att_id)) {
                                     foreach ($att_id as $abc) {
                                         $value[] = $abc;
                                     }
                                 } else {
                                     $value[] = $att_id;
                                 }
                             }
                         }
                     }
                 }
                 if ($field->field_type === "Price") {
                     $paypal_field = new RM_PayPal_Fields();
                     $prices = array();
                     $item_names = array();
                     $paypal_field->load_from_db((int) $key_parts[2]);
                     switch ($paypal_field->get_type()) {
                         case "fixed":
                         case "userdef":
                             $submission_field_rows[] = array('field_id' => $key_parts[1], 'value' => $value, 'form_id' => $params['form']->form_id);
                             $submissions_data[$field->field_id] = new stdClass();
                             $submissions_data[$field->field_id]->label = $field->field_label;
                             $submissions_data[$field->field_id]->value = $value;
                             break;
                         case "multisel":
                             $tmp_v = maybe_unserialize($paypal_field->get_option_price());
                             $tmp_l = maybe_unserialize($paypal_field->get_option_label());
                             $gopt = new RM_Options();
                             $val_arr = array();
                             if ($value) {
                                 foreach ($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];
                                     $val_arr[] = $tmp_l[$index] . " (" . $gopt->get_formatted_amount($tmp_v[$index]) . ")";
                                 }
                                 $value = $val_arr;
                             }
                             $submission_field_rows[] = array('field_id' => $key_parts[1], 'value' => $value, 'form_id' => $params['form']->form_id);
                             $submissions_data[$field->field_id] = new stdClass();
                             $submissions_data[$field->field_id]->label = $field->field_label;
                             $submissions_data[$field->field_id]->value = $value;
                             break;
                         case "dropdown":
                             $tmp_v = maybe_unserialize($paypal_field->get_option_price());
                             $tmp_l = maybe_unserialize($paypal_field->get_option_label());
                             $gopt = new RM_Options();
                             if ($value) {
                                 $index = (int) substr($value, 1);
                                 if (!isset($tmp_v[$index])) {
                                     break;
                                 }
                                 $prices[] = $tmp_v[$index];
                                 $item_names[] = $tmp_l[$index];
                                 $value = $tmp_l[$index] . " (" . $gopt->get_formatted_amount($tmp_v[$index]) . ")";
                             }
                             $submission_field_rows[] = array('field_id' => $key_parts[1], 'value' => $value, 'form_id' => $params['form']->form_id);
                             $submissions_data[$field->field_id] = new stdClass();
                             $submissions_data[$field->field_id]->label = $field->field_label;
                             $submissions_data[$field->field_id]->value = $value;
                             break;
                     }
                 } else {
                     if ($field->get_field_type() !== 'HTMLH' && $field->get_field_type() !== 'HTMLP') {
                         $submission_field_rows[] = array('field_id' => $key_parts[1], 'value' => $value, 'form_id' => $params['form']->form_id);
                         $submissions_data[$field->field_id] = new stdClass();
                         $submissions_data[$field->field_id]->label = $field->field_label;
                         $submissions_data[$field->field_id]->value = $value;
                     }
                 }
                 foreach ($profile_field_id as $key => $id) {
                     if ($key_parts[1] === $id) {
                         if ($key == 'email') {
                             $email = $value;
                         }
                     }
                 }
             }
         }
     }
     /*
      * Register the user if form is registration type (FormType value is 1)
      */
     if ($form_type == 1 && !is_user_logged_in()) {
         if (isset($params['is_payment_form'])) {
             if ($params['is_payment_done']) {
                 //user already activated in 'ipn' case, do nothing.
             } else {
                 //create user but keep deactivated
                 $user_id = $this->register_user($request, $params['form'], $is_auto_generate, false);
                 $this->update_user_profile($user_id, $profile);
                 $reg_data->user_id = $user_id;
             }
         } else {
             $user_id = $this->register_user($request, $params['form'], $is_auto_generate);
             $this->update_user_profile($user_id, $profile);
             $reg_data->user_id = $user_id;
         }
     } else {
         $this->update_user_profile($email, $profile, true);
     }
     //if ($form_type == 1)
     /*
      * Check if any attachment was with submission only if there is no form error
      */
     $submission_row = array('form_id' => $params['form']->form_id, 'data' => $submissions_data, 'user_email' => $email);
     $submissions = new RM_Submissions();
     $submissions->set($submission_row);
     $submission_id = $submissions->insert_into_db();
     if ($submission_field_rows) {
         foreach ($submission_field_rows as $submission_field_row) {
             $submission_field_row['submission_id'] = $submission_id;
             $submission_field = new RM_Submission_Fields();
             $submission_field->set($submission_field_row);
             //If submission is already in the table update it. (for PayPal cases.)
             if ($submission_field->insert_into_db() === false) {
                 $submission_field->update_into_db();
             }
             unset($submission_field);
         }
     }
     /*
      * Send email notification to admin and other receivers
      */
     $submissions->load_from_db($submission_id);
     $email = $this->prepare_email('to_admin', $submissions, $params['form']);
     RM_Utilities::send_mail($email);
     /*
      * If auto reply option enabled
      */
     if ($params['form']->get_form_should_send_email() == "1") {
         $email = $this->prepare_email('to_registrar', $submissions, $params['form'], $request);
         RM_Utilities::send_mail($email);
     }
     /*
      * Redirecting user as per form configuration after submission
      */
     if ($redirect_as_well) {
         $this->after_submission_proc($params);
     }
     /* echo $params['form']->form_options->form_success_message!=""?$params['form']->form_options->form_success_message:$params['form']->form_name." Submitted ";
     
     
               if(isset($params['form']->form_redirect) && $params['form']->form_redirect!="none" && $params['form']->form_redirect!=""){
               if($params['form']->form_redirect=="page"){
               RM_Utilities::redirect(null,true,$params['form']->get_form_redirect_to_page(),true);
               }else{
               RM_Utilities::redirect($params['form']->get_form_redirect_to_url(),false,0,true);
               }
               }
              */
     //if(isset($request->req['stat_id']))
     $reg_data->submission_id = $submission_id;
     return $reg_data;
 }