Пример #1
0
 public function applyAction()
 {
     $text = Wpjb_Project::getInstance()->conf("seo_apply", __("Apply for position: {job_title} (ID: {id})", WPJB_DOMAIN));
     $param = array('job_title' => $this->getObject()->job_title, 'id' => $this->getObject()->id);
     $this->_setTitle($text, $param);
     $job = $this->getObject();
     $this->view->job = $job;
     if (!$this->isMember() && Wpjb_Project::getInstance()->conf("front_apply_members_only", false)) {
         $this->view->members_only = true;
         $this->view->_flash->addError(__("Only registered members can apply for jobs.", WPJB_DOMAIN));
         return;
     }
     if ($job->job_source == 3) {
         wp_redirect($job->company_website);
     }
     $form = new Wpjb_Form_Apply();
     if ($this->isPost()) {
         if ($form->isValid($this->getRequest()->getAll())) {
             // send
             $var = $form->getValues();
             $job = $this->getObject();
             $form->setJobId($job->getId());
             $form->setUserId(Wpjb_Model_Resume::current()->user_id);
             $form->save();
             $files = $form->getFiles();
             $application = $form->getObject();
             $mail = new Wpjb_Model_Email(6);
             $append = array("applicant_email" => $var['email'], "applicant_cv" => $var['resume'], "applicant_name" => $var['applicant_name']);
             list($title, $body) = Wpjb_Utility_Messanger::parse($mail, $job, $append);
             $add = $form->getAdditionalText();
             if (!empty($add)) {
                 $body .= "\r\n--- --- ---\r\n";
             }
             foreach ($add as $field) {
                 if (!$form->hasElement($field)) {
                     continue;
                 }
                 $opt = $form->getElement($field)->getOptions();
                 if (!empty($opt)) {
                     foreach ($opt as $o) {
                         if ($o["value"] == $form->getElement($field)->getValue()) {
                             $fValue = $o["desc"];
                         }
                     }
                 } else {
                     $fValue = $form->getElement($field)->getValue();
                 }
                 $body .= $form->getElement($field)->getLabel() . ": ";
                 $body .= $fValue . "\r\n";
             }
             $headers = "From: " . $var["applicant_name"] . " <" . $var["email"] . ">\r\n";
             $email = $var["email"];
             $title = trim($title);
             if (empty($title)) {
                 $title = __("[Application] ", WPJB_DOMAIN) . $var["name"];
             }
             if (apply_filters("wpjb_job_apply", $form) !== true) {
                 wp_mail($job->company_email, $title, $body, $headers, $files);
             }
             $form->reinit();
             $job->stat_apply++;
             $job->save();
             $this->view->application_sent = true;
             $this->view->_flash->addInfo(__("Your application has been sent.", WPJB_DOMAIN));
             Wpjb_Utility_Messanger::send(8, $job, array('applicant_email' => $var['email']));
         } else {
             $this->view->_flash->addError(__("There are errors in your form.", WPJB_DOMAIN));
         }
     } elseif (Wpjb_Model_Resume::current()->id > 0) {
         $resume = Wpjb_Model_Resume::current();
         if ($form->hasElement("email")) {
             $form->getElement("email")->setValue($resume->email);
         }
         if ($form->hasElement("applicant_name")) {
             $form->getElement("applicant_name")->setValue($resume->firstname . " " . $resume->lastname);
         }
     }
     $this->view->form = $form;
 }