Esempio n. 1
0
 public function send_access_key_step()
 {
     global $wpdb;
     $errors = array();
     $form = array('ad_email' => awpcp_post_param('ad_email'), 'attempts' => (int) awpcp_post_param('attempts', 0));
     if ($form['attempts'] == 0 && get_awpcp_option('enable-user-panel') == 1) {
         $url = admin_url('admin.php?page=awpcp-panel');
         $message = __('You are currently not logged in, if you have an account in this website you can log in and go to the Ad Management panel to edit your Ads.', 'AWPCP');
         $message = sprintf('%s <a href="%s">%s</a>', $message, $url, __('Click here', 'AWPCP'));
         $this->messages[] = $message;
     }
     if (empty($form['ad_email'])) {
         $errors['ad_email'] = __('Please enter the email address you used when you created your Ad.', 'AWPCP');
     } else {
         if (!is_email($form['ad_email'])) {
             $errors['ad_email'] = __('Please enter a valid email address.', 'AWPCP');
         }
     }
     $ads = array();
     if (empty($errors)) {
         $ads = AWPCP_Ad::find_by_email($form['ad_email']);
         if (empty($ads)) {
             $errors[] = __('The email address you entered does not match any of the Ads in our system.', 'AWPCP');
         }
     } else {
         if ($form['attempts'] == 0) {
             $errors = array();
         }
     }
     // if $ads is non-empty then $errors is empty
     if (!empty($ads)) {
         $access_keys_sent = $this->send_access_keys($ads, $errors);
     } else {
         $access_keys_sent = false;
     }
     if (!$access_keys_sent) {
         $send_access_key_url = add_query_arg(array('step' => 'send-access-key'), $this->url());
         $messages = $this->messages;
         $hidden = array('attempts' => $form['attempts'] + 1);
         $params = compact('form', 'hidden', 'messages', 'errors', 'send_access_key_url');
         $template = AWPCP_DIR . '/frontend/templates/page-edit-ad-send-access-key-step.tpl.php';
         return $this->render($template, $params);
     } else {
         return $this->enter_email_and_key_step(false);
     }
 }