Пример #1
0
    /**
     * Edit an action
     *
     * This method is invoked whenever an action has to be edited from the
     * administration panel.
     *
     * An action is edited by it's id/hash
     *
     * @return Zend_View
     */
    public function editAction()
    {
        $request = $this->getRequest();
        $this->view->id = $id = $request->getParam('id');
        if ($id === null) {
            $this->addErrorMessage($this->tr->_('ACTION_MISSING_ID'));
            return;
        }

        $data = $request->getParams();

        $form  = new Default_Form_Action;
        $model = new Default_Model_Action;

        $actionData = $model->get($id);
        $params     = array();

        if (isset($actionData['parameters']) && !empty($actionData['parameters'])) {
            $params = $actionData['parameters'];
        }

        if (isset($params['parameter']) && !isset($params['parameter'][0])) {
            $params['parameter'] = array($params['parameter']);
        }

        $this->view->data = $params;

        $model = new Default_Model_Action;
        if ($request->isPost()) {
            if ($form->isValid($request->getPost())) {
                // Save data
                // This is xss right there.
                try {
                    $model->update($request->getParams(), $id) ;
                    $this->addMessage($this->tr->_('ACTION_UPDATE_SUCCESS') . ': '  . $request->getParam('name'));
                    $this->_redirect('/action/edit/id/' . $id);
                } catch (RuntimeException $e) {
                    $this->addErrorMessage($this->tr->_('ACTION_UPDATE_FAIL') . ': ' . $request->getParam('name') .
                        '. ' . $e->getMessage());
                }
            }
        } else {
            $actionData = $model->get($id);

            $form->populate($actionData);
        }

        $this->view->form = $form;
    }
Пример #2
0
 public function editAction()
 {
     $request = $this->getRequest();
     $this->view->id = $id = $request->getParam('id');
     if ($id === null) {
         $this->addErrorMessage('ID parameter is missing.');
         return;
     }
     $data = $request->getParams();
     $form = new Default_Form_Action();
     $model = new Default_Model_Action();
     $actionData = $model->get($id);
     $params = array();
     if (isset($actionData['parameters']) && !empty($actionData['parameters'])) {
         $params = $actionData['parameters'];
     }
     if (isset($params['parameter']) && !isset($params['parameter'][0])) {
         $params['parameter'] = array($params['parameter']);
     }
     $this->view->data = $params;
     $model = new Default_Model_Action();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             // Save data
             // This is xss right there.
             $model->update($request->getParams(), $id);
             $this->addMessage('Action ' . $request->getParam('name') . ' updated.');
             $this->_redirect('/action/edit/id/' . $id);
         }
     } else {
         $actionData = $model->get($id);
         $actionData['use_custom_route'] = isset($actionData['route']) ? 1 : 0;
         $form->populate($actionData);
     }
     $this->view->form = $form;
 }