/** * Render the JSON outbut for a submit action to be used by ExtJS Form submit * @param \GO\Base\Db\ActiveRecord $$data['model'] * @return \GO\Base\Data\JsonResponse Response object */ public function renderSubmit($data) { $response = array('feedback' => '', 'success' => true, 'validationErrors' => array(), 'data' => array()); //Init data array foreach ($data as $modelName => $model) { if (is_array($model)) { $response['data'][$modelName] = $model; } else { $response['data'][$modelName] = $model->getAttributes(); } // $modelName cannot be the same as the reserved results if ($modelName == 'feedback' || $modelName == 'success' || $modelName == 'validationErrors') { throw new \Exception('Cannot use "' . $modelName . '" as key for your data. Please change the key.'); } if (is_a($model, "\\GO\\Base\\Model")) { //$ret = $this->beforeSubmit($response, $model, $params); //$modifiedAttributes = $model->getModifiedAttributes(); if (!$model->hasValidationErrors() && !$model->isNew) { //model was saved $response['id'] = $model->pk; //If the model has it's own ACL id then we return the newly created ACL id. //The model automatically creates it. if ($model->aclField() && !$model->isJoinedAclField) { $response[$model->aclField()] = $model->{$model->aclField()}; } //TODO: move the link saving to the model someday if (!empty(\GO::request()->post['link']) && $model->hasLinks()) { //a link is sent like \GO\Notes\Model\Note:1 //where 1 is the id of the model $linkProps = explode(':', \GO::request()->post['link']); $linkModel = \GO::getModel($linkProps[0])->findByPk($linkProps[1]); $model->link($linkModel); } } else { // model was not saved $response['success'] = false; //can't use <br /> tags in response because this goes wrong with the extjs fileupload hack with an iframe. $response['feedback'] = sprintf(\GO::t('validationErrorsFound'), strtolower($model->localizedName)) . "\n\n" . implode("\n", $model->getValidationErrors()) . "\n"; if (\GO\Base\Util\Http::isAjaxRequest(false)) { $response['feedback'] = nl2br($response['feedback']); } $response['errors'] = array(sprintf(\GO::t('validationErrorsFound'), strtolower($model->localizedName)) . "\n\n" . implode("\n", $model->getValidationErrors()) . "\n"); $response['validationErrors'][$modelName] = $model->getValidationErrors(); } } else { $response[$modelName] = $model; } } return new \GO\Base\Data\JsonResponse($response); }
/** * Render the JSON outbut for a submit action to be used by ExtJS Form submit * @param \GO\Base\Db\ActiveRecord $model * @return \GO\Base\Data\JsonResponse Response object */ public function renderSubmit($model) { $response = array('feedback' => '', 'success' => true); //$ret = $this->beforeSubmit($response, $model, $params); //$modifiedAttributes = $model->getModifiedAttributes(); if (!$model->hasValidationErrors() && !$model->isNew) { //model was saved $response['id'] = $model->pk; //If the model has it's own ACL id then we return the newly created ACL id. //The model automatically creates it. if ($model->aclField() && !$model->isJoinedAclField) { $response[$model->aclField()] = $model->{$model->aclField()}; } if ($model->aclOverwrite()) { $response[$model->aclOverwrite()] = $model->{$model->aclOverwrite()}; } //TODO: move the link saving to the model someday if (!empty($_POST['link']) && $model->hasLinks()) { //a link is sent like \GO\Notes\Model\Note:1 //where 1 is the id of the model $linkProps = explode(':', $_POST['link']); $linkModel = \GO::getModel($linkProps[0])->findByPk($linkProps[1]); $model->link($linkModel); } } else { // model was not saved $response['success'] = false; //can't use <br /> tags in response because this goes wrong with the extjs fileupload hack with an iframe. $response['feedback'] = sprintf(\GO::t('validationErrorsFound'), strtolower($model->localizedName)) . "\n\n" . implode("\n", $model->getValidationErrors()) . "\n"; if (\GO\Base\Util\Http::isAjaxRequest(false)) { $response['feedback'] = nl2br($response['feedback']); } $response['validationErrors'] = $model->getValidationErrors(); } $this->fireEvent('submit', array(&$this, &$response, &$model)); return new \GO\Base\Data\JsonResponse($response); }
<?php if (\GO\Base\Util\Http::isAjaxRequest()) { echo $data['response']; } elseif (PHP_SAPI == 'cli') { echo "ERROR: " . trim($data['response']['feedback']) . "\n\n"; if (\GO::config()->debug) { echo $data['response']['exception'] . "\n\n"; } } else { require "externalHeader.php"; echo '<h1>' . \GO::t('strError') . '</h1>'; echo '<p style="color:red">' . $data['response']['feedback'] . '</p>'; if (\GO::config()->debug) { unset($data['response']['feedback']); echo '<h2>Debug info:</h2>'; echo '<pre>'; var_dump($data['response']); echo '</pre>'; } require "externalFooter.php"; }
protected function actionLogin($params) { if (!empty($params["login_language"])) { GO::language()->setLanguage($params["login_language"]); } if (!empty($params['domain'])) { $params['username'] .= $params['domain']; } $response = array(); if (!$this->fireEvent('beforelogin', array(&$params, &$response))) { $response['success'] = false; if (!isset($response['feedback'])) { $response['feedback'] = GO::t('badLogin'); } return $response; } $user = \GO::session()->login($params['username'], $params['password']); $response['success'] = $user != false; if (!$response['success']) { $response['feedback'] = \GO::t('badLogin'); } else { if (!empty($params['remind'])) { $encUsername = \GO\Base\Util\Crypt::encrypt($params['username']); if (!$encUsername) { $encUsername = $params['username']; } $encPassword = \GO\Base\Util\Crypt::encrypt($params['password']); if (!$encPassword) { $encPassword = $params['password']; } \GO\Base\Util\Http::setCookie('GO_UN', $encUsername); \GO\Base\Util\Http::setCookie('GO_PW', $encPassword); } $response['groupoffice_version'] = \GO::config()->version; $response['user_id'] = $user->id; $response['security_token'] = \GO::session()->values["security_token"]; $response['sid'] = session_id(); if (!empty($params['return_user_info'])) { $response['modules'] = array(); foreach (\GO::modules()->getAllModules() as $module) { $response['modules'][] = $module->id; } $response['user'] = \GO::user()->getAttributes(); } if (!empty($params["login_language"])) { GO::language()->setLanguage($params["login_language"]); \GO::user()->language = \GO::language()->getLanguage(); \GO::user()->save(); } } // return $response; if (\GO\Base\Util\Http::isAjaxRequest()) { return $response; } else { $this->redirect(); } }
/** * Default headers to send. */ protected function headers() { //iframe hack for file uploads fails with application/json if (!\GO\Base\Util\Http::isAjaxRequest(false) || \GO\Base\Util\Http::isMultipartRequest()) { header('Content-Type: text/html; charset=UTF-8'); } else { header('Content-Type: application/json; charset=UTF-8'); } foreach (\GO::config()->extra_headers as $header) { header($header); } }