Exemplo n.º 1
0
 /**
  * Add a new field. Parameters should be:
  *
  * - class
  * - name
  * - label
  * - type
  * - required
  * - options
  */
 public function post_add()
 {
     if (!isset($_POST['class'])) {
         return $this->error(__('Missing parameter: class'));
     }
     if (!class_exists($_POST['class'])) {
         return $this->error(__('Invalid class name.'));
     }
     if (!isset($_POST['name']) || empty($_POST['name'])) {
         return $this->error(__('Missing parameter: name'));
     }
     if (!isset($_POST['label']) || empty($_POST['label'])) {
         return $this->error(__('Missing parameter: label'));
     }
     if (!isset($_POST['type']) || empty($_POST['type'])) {
         return $this->error(__('Missing parameter: type'));
     }
     if (!isset($_POST['required'])) {
         return $this->error(__('Missing parameter: required'));
     }
     if (!isset($_POST['options'])) {
         return $this->error(__('Missing parameter: options'));
     }
     error_log(json_encode($_POST));
     error_log($_POST['class']);
     error_log($_POST['type']);
     error_log($_POST['name']);
     $_POST['sort'] = ExtendedFields::next_sort($_POST['class']);
     error_log($_POST['sort']);
     $obj = new ExtendedFields($_POST);
     if (!$obj->put()) {
         return $this->error(__('An unknown error occurred.'));
     }
     return $obj->orig();
 }