/** * Execute the action */ public function execute() { parent::execute(); // get parameters $id = \SpoonFilter::getPostValue('id', null, '', 'int'); $name = trim(\SpoonFilter::getPostValue('value', null, '', 'string')); // validate if ($name == '') { $this->output(self::BAD_REQUEST, null, 'no name provided'); } else { // get existing id $existingId = BackendMailmotorModel::getCampaignId($name); // validate if ($existingId !== 0 && $id !== $existingId) { $this->output(self::ERROR, array('id' => $existingId, 'error' => true), BL::err('CampaignExists', $this->getModule())); } else { // build array $item = array(); $item['id'] = $id; $item['name'] = $name; $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // get page $rows = BackendMailmotorModel::updateCampaign($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'edited_campaign', array('item' => $item)); // output if ($rows !== 0) { $this->output(self::OK, array('id' => $id), BL::msg('CampaignEdited', $this->getModule())); } else { $this->output(self::ERROR, null, BL::err('CampaignNotEdited', $this->getModule())); } } } }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // shorten fields $txtName = $this->frm->getField('name'); // validate fields if ($txtName->isFilled(BL::err('NameIsRequired'))) { if ($txtName->getValue() != $this->record['name'] && BackendMailmotorModel::existsCampaignByName($txtName->getValue())) { $txtName->addError(BL::err('CampaignExists')); } } // no errors? if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['name'] = $txtName->getValue(); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // update the item BackendMailmotorModel::updateCampaign($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_campaign', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Campaigns') . '&report=edited&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']); } } }