Beispiel #1
0
 /**
  * Move Form Field Up or Down
  * Positioning in layout
  */
 public function field_move()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     // Get the form id
     $form_id = (isset($_POST['form_id']) and intval($_POST['form_id']) > 0) ? intval($_POST['form_id']) : 0;
     // Get the field id
     $field_id = (isset($_POST['field_id']) and intval($_POST['field_id']) > 0) ? intval($_POST['field_id']) : 0;
     // Field position
     $field_position = isset($_POST['field_position']) ? $_POST['field_position'] : "";
     $return_content = "";
     if ($field_position == 'u' or $field_position == 'd') {
         // Load This Field
         $field = ORM::factory('form_field', $field_id);
         if ($field->loaded == TRUE) {
             // Get the total number of fields for the form
             $total_fields = ORM::factory('form_field')->where('form_id', $field->form_id)->count_all();
             // Get current position
             $current_position = $field->field_position;
             if ($field_position == 'u' and $current_position > 1) {
                 // Move down the fields whose position value is greater
                 // than that of the selected field
                 $sql = "UPDATE %sform_field SET field_position = %d WHERE field_position = %d";
                 $this->db->query(sprintf($sql, $this->table_prefix, $current_position, $current_position - 1));
                 // Move the selected field upwards
                 $field->field_position = $current_position - 1;
                 $field->save();
             } elseif ($field_position == 'd' and $current_position != $total_fields) {
                 // Move all other form fields upwards
                 $sql = "UPDATE %sform_field SET field_position = %d WHERE field_position = %d";
                 $this->db->query(sprintf($sql, $this->table_prefix, $current_position, $current_position + 1));
                 // Move the selected field downwards - increase its field position in the database
                 $field->field_position = $current_position + 1;
                 $field->save();
             }
         }
     }
     $return_content = customforms::get_current_fields($form_id, $this->user);
     echo json_encode(array("status" => "success", "response" => $return_content));
 }