public function processRequest($request)
 {
     $db = new WPAM_Data_DataAccess();
     $affiliateFields = $db->getAffiliateFieldRepository()->loadMultipleBy(array('enabled' => true), array('order' => 'asc'));
     if (isset($request['action']) && $request['action'] == 'saveInfo') {
         $validator = new WPAM_Validation_Validator();
         $validator->addValidator('ddBountyType', new WPAM_Validation_SetValidator(array('fixed', 'percent')));
         if ($request['ddBountyType'] === 'fixed') {
             $validator->addValidator('txtBountyAmount', new WPAM_Validation_MoneyValidator());
         } else {
             if ($request['ddBountyType'] === 'percent') {
                 $validator->addValidator('txtBountyAmount', new WPAM_Validation_NumberValidator());
             }
         }
         $affiliateHelper = new WPAM_Util_AffiliateFormHelper();
         $vr = $affiliateHelper->validateForm($validator, $request, $affiliateFields);
         if ($vr->getIsValid()) {
             $model = $affiliateHelper->getNewAffiliate();
             $affiliateHelper->setModelFromForm($model, $affiliateFields, $request);
             $affiliateHelper->setPaymentFromForm($model, $request);
             //send email etc.
             $userHandler = new WPAM_Util_UserHandler();
             if (get_option(WPAM_PluginConfig::$AutoAffiliateApproveIsEnabledOption) == 1) {
                 $userHandler->AutoapproveAffiliate($model, $request['ddBountyType'], $request['txtBountyAmount']);
             } else {
                 $userHandler->approveAffiliate($model, $request['ddBountyType'], $request['txtBountyAmount'], false);
             }
             return new WPAM_Pages_TemplateResponse('admin/affiliate_new_success');
         } else {
             return $this->getForm($affiliateFields, $request, $vr);
         }
     }
     return $this->getForm($affiliateFields, $request);
 }
 public function processRequest($request)
 {
     $db = new WPAM_Data_DataAccess();
     $affiliateFields = $db->getAffiliateFieldRepository()->loadMultipleBy(array('enabled' => true), array('order' => 'asc'));
     if (isset($request['action']) && $request['action'] == 'submit') {
         $form_validated = false;
         $affiliateHelper = new WPAM_Util_AffiliateFormHelper();
         $vr = $affiliateHelper->validateForm(new WPAM_Validation_Validator(), $request, $affiliateFields);
         if ($vr->getIsValid()) {
             $form_validated = true;
         }
         $output = apply_filters('wpam_validate_registration_form_submission', '', $request);
         if (!empty($output)) {
             $form_validated = false;
         }
         if ($form_validated) {
             $model = $affiliateHelper->getNewAffiliate();
             $affiliateHelper->setModelFromForm($model, $affiliateFields, $request);
             //Fire the action hook
             do_action('wpam_front_end_registration_form_submitted', $model, $request);
             //Check if automatic affiliate approval option is enabled
             if (get_option(WPAM_PluginConfig::$AutoAffiliateApproveIsEnabledOption) == 1) {
                 $userHandler = new WPAM_Util_UserHandler();
                 $userHandler->AutoapproveAffiliate($model);
                 return new WPAM_Pages_TemplateResponse('aff_app_submitted_auto_approved');
             }
             //Do the non auto approval process
             $db = new WPAM_Data_DataAccess();
             $id = $db->getAffiliateRepository()->insert($model);
             if ($id == 0) {
                 if (WPAM_DEBUG) {
                     echo '<pre>', var_export($model, true), '</pre>';
                 }
                 wp_die(__('Error submitting your details to the database. This is a bug, and your application was not submitted.', 'affiliates-manager'));
             }
             $mailer = new WPAM_Util_EmailHandler();
             //Notify admin that affiliate has registered
             $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
             $message = sprintf(__('New affiliate registration on your site %s:', 'affiliates-manager'), $blogname) . "\r\n\r\n";
             $message .= sprintf(__('Name: %s %s', 'affiliates-manager'), $request['_firstName'], $request['_lastName']) . "\r\n";
             $message .= sprintf(__('Email: %s', 'affiliates-manager'), $request['_email']) . "\r\n";
             $message .= sprintf(__('Company: %s', 'affiliates-manager'), $request['_companyName']) . "\r\n";
             $message .= sprintf(__('Website: %s', 'affiliates-manager'), $request['_websiteUrl']) . "\r\n\r\n";
             $message .= sprintf(__('View Application: %s', 'affiliates-manager'), admin_url('admin.php?page=wpam-affiliates&viewDetail=' . $id)) . "\r\n";
             $mailer->mailAffiliate(get_option('admin_email'), __('New Affiliate Registration', 'affiliates-manager'), $message);
             //Notify affiliate of their application
             $affsubj = sprintf(__('Affiliate application for %s', 'affiliates-manager'), $blogname);
             $affmessage = WPAM_MessageHelper::GetMessage('affiliate_application_submitted_email');
             $mailer->mailAffiliate($request['_email'], $affsubj, $affmessage);
             return new WPAM_Pages_TemplateResponse('affiliate_application_submitted');
         } else {
             return $this->getForm($affiliateFields, $request, $vr);
         }
     }
     //else
     return $this->getForm($affiliateFields);
 }
 public function processRequest($request)
 {
     $db = new WPAM_Data_DataAccess();
     if (isset($request['viewDetail']) && is_numeric($request['viewDetail'])) {
         $affiliateFields = $db->getAffiliateFieldRepository()->loadMultipleBy(array('enabled' => true), array('order' => 'asc'));
         $id = (int) $request['viewDetail'];
         $model = $db->getAffiliateRepository()->load($id);
         if ($model == null) {
             wp_die("Invalid affiliate ID.");
         }
         if (isset($request['action']) && $request['action'] == 'saveInfo') {
             $validator = new WPAM_Validation_Validator();
             //validate bounty type & amount if they're in the appropriate status
             if (!$model->isPending() && !$model->isBlocked() && !$model->isDeclined()) {
                 $validator->addValidator('ddBountyType', new WPAM_Validation_SetValidator(array('fixed', 'percent')));
                 if ($request['ddBountyType'] === 'fixed') {
                     $validator->addValidator('txtBountyAmount', new WPAM_Validation_MoneyValidator());
                 } else {
                     if ($request['ddBountyType'] === 'percent') {
                         $validator->addValidator('txtBountyAmount', new WPAM_Validation_NumberValidator());
                     }
                 }
                 $validator->addValidator('ddPaymentMethod', new WPAM_Validation_SetValidator(array('check', 'paypal')));
                 if ($request['ddPaymentMethod'] === 'paypal') {
                     $validator->addValidator('txtPaypalEmail', new WPAM_Validation_EmailValidator());
                 }
             }
             $affiliateHelper = new WPAM_Util_AffiliateFormHelper();
             $vr = $affiliateHelper->validateForm($validator, $request, $affiliateFields, TRUE);
             if ($vr->getIsValid()) {
                 $affiliateHelper->setModelFromForm($model, $affiliateFields, $request);
                 $affiliateHelper->setPaymentFromForm($model, $request);
                 $db->getAffiliateRepository()->update($model);
             } else {
                 return $this->getDetailForm($affiliateFields, $model, $request, $vr);
             }
         }
         return $this->getDetailForm($affiliateFields, $model, $request);
     } else {
         //Show all the affiliates list.
         //Lets include the affiliates_list.php file
         $response = new WPAM_Pages_TemplateResponse('admin/affiliates_list');
     }
     return $response;
 }
 protected function doContactInfo($request, $affiliate)
 {
     add_action('wp_footer', array($this, 'onFooter'));
     $db = new WPAM_Data_DataAccess();
     $affiliateFields = $db->getAffiliateFieldRepository()->loadMultipleBy(array('enabled' => true), array('order' => 'asc'));
     $response = new WPAM_Pages_TemplateResponse('affiliate_cp_contactinfo');
     $response->viewData['affiliateFields'] = $affiliateFields;
     $affiliateHelper = new WPAM_Util_AffiliateFormHelper();
     $response->viewData['paymentMethods'] = $affiliateHelper->getPaymentMethods();
     $response->viewData['paymentMethod'] = isset($request['ddPaymentMethod']) ? $request['ddPaymentMethod'] : $affiliate->paymentMethod;
     $response->viewData['paypalEmail'] = isset($request['txtPaypalEmail']) ? $request['txtPaypalEmail'] : $affiliate->paypalEmail;
     $user = wp_get_current_user();
     if (isset($request['action']) && $request['action'] == 'saveInfo') {
         $validator = new WPAM_Validation_Validator();
         $validator->addValidator('ddPaymentMethod', new WPAM_Validation_SetValidator(array('check', 'paypal')));
         if ($request['ddPaymentMethod'] === 'paypal') {
             $validator->addValidator('txtPaypalEmail', new WPAM_Validation_EmailValidator());
         }
         $vr = $affiliateHelper->validateForm($validator, $request, $affiliateFields, TRUE);
         if ($vr->getIsValid()) {
             //#79 hackery to do the "normal" WP email approval process
             require_once ABSPATH . 'wp-admin/includes/ms.php';
             $_POST['email'] = $request['_email'];
             $_POST['user_id'] = $user->ID;
             unset($request['_email']);
             global $errors;
             //*try* to save email
             send_confirmation_on_profile_email();
             if (!empty($errors->errors)) {
                 $vr->addError(new WPAM_Validation_ValidatorError('_email', $_POST['email'] . " " . $errors->get_error_message('user_email')));
                 $response->viewData['validationResult'] = $vr;
                 $response->viewData['affiliate'] = $affiliate;
                 //save for form validation in the footer
                 $this->response = $response;
                 return $response;
             }
             $affiliateHelper->setModelFromForm($affiliate, $affiliateFields, $request);
             $affiliateHelper->setPaymentFromForm($affiliate, $request);
             $db->getAffiliateRepository()->update($affiliate);
         } else {
             $response->viewData['validationResult'] = $vr;
         }
     }
     $new_email = get_option($user->ID . '_new_email');
     if ($new_email && $new_email != $user->user_email) {
         $response->viewData['newEmail'] = $new_email;
         $response->viewData['userId'] = $user->ID;
     }
     $response->viewData['affiliate'] = $affiliate;
     //save for form validation in the footer
     $this->response = $response;
     return $response;
 }
 public function processRequest($request)
 {
     $db = new WPAM_Data_DataAccess();
     if (isset($request['viewDetail']) && is_numeric($request['viewDetail'])) {
         $affiliateFields = $db->getAffiliateFieldRepository()->loadMultipleBy(array('enabled' => true), array('order' => 'asc'));
         $id = (int) $request['viewDetail'];
         $model = $db->getAffiliateRepository()->load($id);
         if ($model == null) {
             wp_die("Invalid affiliate ID.");
         }
         if (isset($request['action']) && $request['action'] == 'saveInfo') {
             $validator = new WPAM_Validation_Validator();
             //validate bounty type & amount if they're in the appropriate status
             if (!$model->isPending() && !$model->isBlocked() && !$model->isDeclined()) {
                 $validator->addValidator('ddBountyType', new WPAM_Validation_SetValidator(array('fixed', 'percent')));
                 if ($request['ddBountyType'] === 'fixed') {
                     $validator->addValidator('txtBountyAmount', new WPAM_Validation_MoneyValidator());
                 } else {
                     if ($request['ddBountyType'] === 'percent') {
                         $validator->addValidator('txtBountyAmount', new WPAM_Validation_NumberValidator());
                     }
                 }
                 $validator->addValidator('ddPaymentMethod', new WPAM_Validation_SetValidator(array('check', 'paypal')));
                 if ($request['ddPaymentMethod'] === 'paypal') {
                     $validator->addValidator('txtPaypalEmail', new WPAM_Validation_EmailValidator());
                 }
             }
             $affiliateHelper = new WPAM_Util_AffiliateFormHelper();
             $vr = $affiliateHelper->validateForm($validator, $request, $affiliateFields, TRUE);
             if ($vr->getIsValid()) {
                 $affiliateHelper->setModelFromForm($model, $affiliateFields, $request);
                 $affiliateHelper->setPaymentFromForm($model, $request);
                 $db->getAffiliateRepository()->update($model);
             } else {
                 return $this->getDetailForm($affiliateFields, $model, $request, $vr);
             }
         }
         return $this->getDetailForm($affiliateFields, $model, $request);
     } else {
         if (isset($_GET['orderby'])) {
             $current_orderby = $_GET['orderby'];
         } else {
             $current_orderby = 'affiliateId';
         }
         if (isset($_GET['order']) && 'desc' == $_GET['order']) {
             $current_order = 'desc';
         } else {
             $current_order = 'asc';
         }
         $orderBy = array($current_orderby => $current_order);
         $filterWhere = array();
         $minPayout = NULL;
         if (!isset($request['statusFilter'])) {
             $request['statusFilter'] = 'all_active';
         }
         if ($request['statusFilter'] !== 'all') {
             switch ($request['statusFilter']) {
                 case 'all_active':
                     $filterWhere['status'] = array('NOT IN', array('declined', 'blocked', 'inactive'));
                     break;
                 case 'all':
                     break;
                 case 'active':
                 case 'applied':
                 case 'approved':
                 case 'confirmed':
                 case 'declined':
                 case 'blocked':
                 case 'inactive':
                     $filterWhere['status'] = $request['statusFilter'];
                 default:
                     break;
             }
         }
         if (isset($request['overPayout']) && $request['overPayout'] === 'true') {
             $minPayout = get_option(WPAM_PluginConfig::$MinPayoutAmountOption);
         }
         $models = $db->getAffiliateRepository()->loadAffiliateSummary($filterWhere, $minPayout, $orderBy);
         $response = new WPAM_Pages_TemplateResponse('admin/affiliates_list');
         $response->viewData['minPayoutAmount'] = get_option(WPAM_PluginConfig::$MinPayoutAmountOption);
         $response->viewData['affiliates'] = $models;
         $response->viewData['request'] = $request;
         $response->viewData['statusFilters'] = array('all_active' => __('All Active', 'wpam'), 'all' => __('All (Including Closed)', 'wpam'), '---' => '---', 'active' => __('Status: Active', 'wpam'), 'applied' => __('Status: Applied', 'wpam'), 'approved' => __('Status: Approved', 'wpam'), 'confirmed' => __('Status: Confirmed', 'wpam'), 'declined' => __('Status: Declined', 'wpam'), 'blocked' => __('Status: Blocked', 'wpam'), 'inactive' => __('Status: Inactive', 'wpam'));
         $response->viewData['current_orderby'] = $current_orderby;
         $response->viewData['current_order'] = $current_order;
     }
     return $response;
 }