コード例 #1
0
ファイル: class-ajax.php プロジェクト: ediamin/wp-erp
 /**
  * Add/edit work experience
  *
  * @return void
  */
 public function employee_work_experience_create()
 {
     $this->verify_nonce('erp-work-exp-form');
     // TODO: permission check
     $employee_id = isset($_POST['employee_id']) ? intval($_POST['employee_id']) : 0;
     $exp_id = isset($_POST['exp_id']) ? intval($_POST['exp_id']) : 0;
     $company_name = isset($_POST['company_name']) ? strip_tags($_POST['company_name']) : '';
     $job_title = isset($_POST['job_title']) ? strip_tags($_POST['job_title']) : '';
     $from = isset($_POST['from']) ? strip_tags($_POST['from']) : '';
     $to = isset($_POST['to']) ? strip_tags($_POST['to']) : '';
     $description = isset($_POST['description']) ? strip_tags($_POST['description']) : '';
     // some basic validations
     $requires = ['company_name' => __('Company Name', 'wp-erp'), 'job_title' => __('Job Title', 'wp-erp'), 'from' => __('From date', 'wp-erp'), 'to' => __('To date', 'wp-erp')];
     foreach ($requires as $var_name => $label) {
         if (!${$var_name}) {
             $this->send_error(sprintf(__('%s is required', 'wp-erp'), $label));
         }
     }
     $fields = ['employee_id' => $employee_id, 'company_name' => $company_name, 'job_title' => $job_title, 'from' => $from, 'to' => $to, 'description' => $description];
     if (!$exp_id) {
         Work_Experience::create($fields);
     } else {
         Work_Experience::find($exp_id)->update($fields);
     }
     $this->send_success();
 }