/** * Execute the action */ public function execute() { parent::execute(); // action to execute $action = SpoonFilter::getGetValue('action', array('delete'), ''); // form id $formId = SpoonFilter::getGetValue('form_id', null, '', 'int'); // no id's provided if (!isset($_GET['id'])) { $this->redirect(BackendModel::createURLForAction('index') . '&error=no-items-selected'); } elseif ($action == '') { $this->redirect(BackendModel::createURLForAction('index') . '&error=no-action-selected'); } elseif (!BackendFormBuilderModel::exists($formId)) { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } else { // redefine id's $ids = (array) $_GET['id']; // delete comment(s) if ($action == 'delete') { BackendFormBuilderModel::deleteData($ids); } // define report $report = count($ids) > 1 ? 'items-' : 'item-'; // init var if ($action == 'delete') { $report .= 'deleted'; } // redirect $this->redirect(BackendModel::createURLForAction('data') . '&id=' . $formId . '&report=' . $report); } }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $formId = trim(SpoonFilter::getPostValue('form_id', null, '', 'int')); $fieldId = trim(SpoonFilter::getPostValue('field_id', null, '', 'int')); // invalid form id if (!BackendFormBuilderModel::exists($formId)) { $this->output(self::BAD_REQUEST, null, 'form does not exist'); } // invalid fieldId if (!BackendFormBuilderModel::existsField($fieldId, $formId)) { $this->output(self::BAD_REQUEST, null, 'field does not exist'); } // get field $field = BackendFormBuilderModel::getField($fieldId); // submit button cannot be deleted if ($field['type'] == 'submit') { $this->output(self::BAD_REQUEST, null, 'submit button cannot be deleted'); } else { // delete field BackendFormBuilderModel::deleteField($fieldId); // success output $this->output(self::OK, null, 'field deleted'); } }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $formId = SpoonFilter::getPostValue('form_id', null, '', 'int'); $newIdSequence = trim(SpoonFilter::getPostValue('new_id_sequence', null, '', 'string')); // invalid form id if (!BackendFormBuilderModel::exists($formId)) { $this->output(self::BAD_REQUEST, null, 'form does not exist'); } // list id $ids = (array) explode(',', rtrim($newIdSequence, ',')); // loop id's and set new sequence foreach ($ids as $i => $id) { // redefine $id = (int) $id; // get field $field = BackendFormBuilderModel::getField($id); // from this form and not a submit button if (!empty($field) && $field['form_id'] == $formId && $field['type'] != 'submit') { BackendFormBuilderModel::updateField($id, array('sequence' => $i + 1)); } } // success output $this->output(self::OK, null, 'sequence updated'); }
/** * Get the data * * @return void */ private function getData() { // fetch data $this->data = BackendFormBuilderModel::getData($this->id); // fetch record $this->record = BackendFormBuilderModel::get($this->data['form_id']); }
/** * Execute the action. */ public function execute() { $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendFormBuilderModel::exists($this->id)) { parent::execute(); $this->setFilter(); $this->setItems(); BackendCSV::outputCSV(date('Ymd_His') . '.csv', $this->rows, $this->columnHeaders); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $formId = trim(SpoonFilter::getPostValue('form_id', null, '', 'int')); $fieldId = trim(SpoonFilter::getPostValue('field_id', null, '', 'int')); // invalid form id if (!BackendFormBuilderModel::exists($formId)) { $this->output(self::BAD_REQUEST, null, 'form does not exist'); } // invalid fieldId if (!BackendFormBuilderModel::existsField($fieldId, $formId)) { $this->output(self::BAD_REQUEST, null, 'field does not exist'); } // get field $field = BackendFormBuilderModel::getField($fieldId); // success output $this->output(self::OK, array('field' => $field)); }
/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendFormBuilderModel::exists($this->id)) { parent::execute(); // get all data for the item we want to edit $this->record = (array) BackendFormBuilderModel::get($this->id); // delete item BackendFormBuilderModel::delete($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // user was deleted, so redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['name'])); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $formId = trim(SpoonFilter::getGetValue('form_id', null, '', 'int')); $fieldId = trim(SpoonFilter::getGetValue('field_id', null, '', 'int')); // invalid form id if (!BackendFormBuilderModel::exists($formId)) { $this->output(self::BAD_REQUEST, null, 'form does not exist'); } // invalid fieldId if (!BackendFormBuilderModel::existsField($fieldId, $formId)) { $this->output(self::BAD_REQUEST, null, 'field does not exist'); } // get field $field = BackendFormBuilderModel::getField($fieldId); // success output $this->output(self::OK, array('field' => $field)); }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // shorten the fields $txtName = $this->frm->getField('name'); $txtEmail = $this->frm->getField('email'); $ddmMethod = $this->frm->getField('method'); $txtSuccessMessage = $this->frm->getField('success_message'); $txtIdentifier = $this->frm->getField('identifier'); $emailAddresses = (array) explode(',', $txtEmail->getValue()); // validate fields $txtName->isFilled(BL::getError('NameIsRequired')); $txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired')); if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') { $error = false; // check the addresses foreach ($emailAddresses as $address) { $address = trim($address); if (!SpoonFilter::isEmail($address)) { $error = true; break; } } // add error if ($error) { $txtEmail->addError(BL::getError('EmailIsInvalid')); } } // identifier if ($txtIdentifier->isFilled()) { // invalid characters if (!SpoonFilter::isValidAgainstRegexp('/^[a-zA-Z0-9\\.\\_\\-]+$/', $txtIdentifier->getValue())) { $txtIdentifier->setError(BL::getError('InvalidIdentifier')); } elseif (BackendFormBuilderModel::existsIdentifier($txtIdentifier->getValue(), $this->id)) { $txtIdentifier->setError(BL::getError('UniqueIdentifier')); } } if ($this->frm->isCorrect()) { // build array $values['name'] = $txtName->getValue(); $values['method'] = $ddmMethod->getValue(); $values['email'] = $ddmMethod->getValue() == 'database_email' ? serialize($emailAddresses) : null; $values['success_message'] = $txtSuccessMessage->getValue(true); $values['identifier'] = $txtIdentifier->isFilled() ? $txtIdentifier->getValue() : BackendFormBuilderModel::createIdentifier(); $values['edited_on'] = BackendModel::getUTCDate(); // insert the item $id = (int) BackendFormBuilderModel::update($this->id, $values); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $values)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($values['name']) . '&highlight=row-' . $id); } } }
/** * Get the data */ private function getData() { $this->record = BackendFormBuilderModel::get($this->id); }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $formId = SpoonFilter::getPostValue('form_id', null, '', 'int'); $fieldId = SpoonFilter::getPostValue('field_id', null, '', 'int'); $type = SpoonFilter::getPostValue('type', array('checkbox', 'dropdown', 'heading', 'paragraph', 'radiobutton', 'submit', 'textarea', 'textbox'), '', 'string'); $label = trim(SpoonFilter::getPostValue('label', null, '', 'string')); $values = trim(SpoonFilter::getPostValue('values', null, '', 'string')); $defaultValues = trim(SpoonFilter::getPostValue('default_values', null, '', 'string')); $required = SpoonFilter::getPostValue('required', array('Y', 'N'), 'N', 'string'); $requiredErrorMessage = trim(SpoonFilter::getPostValue('required_error_message', null, '', 'string')); $validation = SpoonFilter::getPostValue('validation', array('email', 'numeric'), '', 'string'); $validationParameter = trim(SpoonFilter::getPostValue('validation_parameter', null, '', 'string')); $errorMessage = trim(SpoonFilter::getPostValue('error_message', null, '', 'string')); // invalid form id if (!BackendFormBuilderModel::exists($formId)) { $this->output(self::BAD_REQUEST, null, 'form does not exist'); } // invalid fieldId if ($fieldId !== 0 && !BackendFormBuilderModel::existsField($fieldId, $formId)) { $this->output(self::BAD_REQUEST, null, 'field does not exist'); } // invalid type if ($type == '') { $this->output(self::BAD_REQUEST, null, 'invalid type provided'); } // init $errors = array(); // validate textbox if ($type == 'textbox') { if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($validation != '' && $errorMessage == '') { $errors['error_message'] = BL::getError('ErrorMessageIsRequired'); } } elseif ($type == 'textarea') { if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($validation != '' && $errorMessage == '') { $errors['error_message'] = BL::getError('ErrorMessageIsRequired'); } } elseif ($type == 'heading' && $values == '') { $errors['values'] = BL::getError('ValueIsRequired'); } elseif ($type == 'paragraph' && $values == '') { $errors['values'] = BL::getError('ValueIsRequired'); } elseif ($type == 'submit' && $values == '') { $errors['values'] = BL::getError('ValueIsRequired'); } elseif ($type == 'dropdown') { // values trim $values = trim($values, ','); // validate if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($values == '') { $errors['values'] = BL::getError('ValueIsRequired'); } } elseif ($type == 'radiobutton') { if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } if ($values == '') { $errors['values'] = BL::getError('ValueIsRequired'); } } elseif ($type == 'checkbox') { if ($label == '') { $errors['label'] = BL::getError('LabelIsRequired'); } if ($required == 'Y' && $requiredErrorMessage == '') { $errors['required_error_message'] = BL::getError('ErrorMessageIsRequired'); } } // got errors if (!empty($errors)) { $this->output(self::OK, array('errors' => $errors), 'form contains errors'); } // htmlspecialchars except for paragraphs if ($type != 'paragraph') { if ($values != '') { $values = SpoonFilter::htmlspecialchars($values); } if ($defaultValues != '') { $defaultValues = SpoonFilter::htmlspecialchars($defaultValues); } } // split if ($type == 'dropdown' || $type == 'radiobutton' || $type == 'checkbox') { $values = (array) explode('|', $values); } /** * Save! */ // settings $settings = array(); if ($label != '') { $settings['label'] = SpoonFilter::htmlspecialchars($label); } if ($values != '') { $settings['values'] = $values; } if ($defaultValues != '') { $settings['default_values'] = $defaultValues; } // build array $field = array(); $field['form_id'] = $formId; $field['type'] = $type; $field['settings'] = !empty($settings) ? serialize($settings) : null; // existing field if ($fieldId !== 0) { // update field BackendFormBuilderModel::updateField($fieldId, $field); // delete all validation (added again later) BackendFormBuilderModel::deleteFieldValidation($fieldId); } else { // sequence $field['sequence'] = BackendFormBuilderModel::getMaximumSequence($formId) + 1; // insert $fieldId = BackendFormBuilderModel::insertField($field); } // required if ($required == 'Y') { // build array $validate['field_id'] = $fieldId; $validate['type'] = 'required'; $validate['error_message'] = SpoonFilter::htmlspecialchars($requiredErrorMessage); // add validation BackendFormBuilderModel::insertFieldValidation($validate); // add to field (for parsing) $field['validations']['required'] = $validate; } // other validation if ($validation != '') { // build array $validate['field_id'] = $fieldId; $validate['type'] = $validation; $validate['error_message'] = SpoonFilter::htmlspecialchars($errorMessage); $validate['parameter'] = $validationParameter != '' ? SpoonFilter::htmlspecialchars($validationParameter) : null; // add validation BackendFormBuilderModel::insertFieldValidation($validate); // add to field (for parsing) $field['validations'][$type] = $validate; } // get item from database (i do this call again to keep the points of failure as low as possible) $field = BackendFormBuilderModel::getField($fieldId); // submit button isnt parsed but handled directly via javascript if ($type == 'submit') { $fieldHTML = ''; } else { $fieldHTML = FormBuilderHelper::parseField($field); } // success output $this->output(self::OK, array('field_id' => $fieldId, 'field_html' => $fieldHTML), 'field saved'); }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // shorten the fields $txtName = $this->frm->getField('name'); $txtEmail = $this->frm->getField('email'); $ddmMethod = $this->frm->getField('method'); $txtSuccessMessage = $this->frm->getField('success_message'); $txtIdentifier = $this->frm->getField('identifier'); $emailAddresses = (array) explode(',', $txtEmail->getValue()); // validate fields $txtName->isFilled(BL::getError('NameIsRequired')); $txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired')); if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') { $error = false; // check the addresses foreach ($emailAddresses as $address) { $address = trim($address); if (!SpoonFilter::isEmail($address)) { $error = true; break; } } // add error if ($error) { $txtEmail->addError(BL::getError('EmailIsInvalid')); } } // identifier if ($txtIdentifier->isFilled()) { // invalid characters if (!SpoonFilter::isValidAgainstRegexp('/^[a-zA-Z0-9\\.\\_\\-]+$/', $txtIdentifier->getValue())) { $txtIdentifier->setError(BL::getError('InvalidIdentifier')); } elseif (BackendFormBuilderModel::existsIdentifier($txtIdentifier->getValue())) { $txtIdentifier->setError(BL::getError('UniqueIdentifier')); } } if ($this->frm->isCorrect()) { // build array $values['language'] = BL::getWorkingLanguage(); $values['user_id'] = BackendAuthentication::getUser()->getUserId(); $values['name'] = $txtName->getValue(); $values['method'] = $ddmMethod->getValue(); $values['email'] = $ddmMethod->getValue() == 'database_email' ? serialize($emailAddresses) : null; $values['success_message'] = $txtSuccessMessage->getValue(true); $values['identifier'] = $txtIdentifier->isFilled() ? $txtIdentifier->getValue() : BackendFormBuilderModel::createIdentifier(); $values['created_on'] = BackendModel::getUTCDate(); $values['edited_on'] = BackendModel::getUTCDate(); // insert the item $id = BackendFormBuilderModel::insert($values); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $values)); // set frontend locale FL::setLocale(BL::getWorkingLanguage()); // create submit button $field['form_id'] = $id; $field['type'] = 'submit'; $field['settings'] = serialize(array('values' => SpoonFilter::ucfirst(FL::getLabel('Send')))); BackendFormBuilderModel::insertField($field); // everything is saved, so redirect to the editform $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $id . '&report=added&var=' . urlencode($values['name']) . '#tabFields'); } } }
/** * Execute the action. * * @return void */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendFormBuilderModel::exists($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // set filter $this->setFilter(); // set csv items $this->setItems(); // create csv $this->createCsv(); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }