/** * Saves the design of all the fields in the module. * * If the request parameter "id" is null or 0, the function will add a new module, * if the "id" is an existing module, the function will update it. * * The save action will try to add or update the module table itself and the database_manager. * * REQUIRES request parameters: * <pre> * - integer <b>id</b> id of the module to save. * - string <b>designerData</b> Data of the fields. * - string <b>name</b> Name of the module. * - string <b>label</b> Display of the module. * </pre> * * The return is a string in JSON format with: * <pre> * - type => 'success' or 'error'. * - message => Success or error message. * - id => id of the module. * </pre> * * @throws Zend_Controller_Action_Exception On error in the action save. * * @return void */ public function jsonSaveAction() { $id = (int) $this->getRequest()->getParam('id'); $data = $this->getRequest()->getParam('designerData'); $saveType = (int) $this->getRequest()->getParam('saveType'); $model = null; $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('name', null)); $this->setCurrentProjectId(); if (empty($module)) { $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('label')); } $module = ucfirst(str_replace(" ", "", $module)); $this->getRequest()->setParam('name', $module); if ($id > 0) { $model = Phprojekt_Loader::getModel($module, $module); } $message = $this->_handleDatabaseChange($model, $module, $data, $saveType, $id); if (!is_null($message)) { Phprojekt_Converter_Json::echoConvert($message); return; } $this->setCurrentProjectId(); $message = ''; if (empty($id)) { $model = new Phprojekt_Module_Module(); $message = Phprojekt::getInstance()->translate('The module was added correctly'); } else { $model = new Phprojekt_Module_Module(); $model = $model->find($id); $message = Phprojekt::getInstance()->translate('The module was edited correctly'); } $model->saveModule($this->getRequest()->getParams()); Phprojekt_Module::clearCache(); $return = array('type' => 'success', 'message' => $message, 'id' => $model->id); Phprojekt_Converter_Json::echoConvert($return); }