/**
* Creates a message if form has been submitted or renders the creation/update form
*/
public function actionCreate()
{
if (isset($_POST['Message'])) {
$resp = array('color' => '#FF6600', 'background_color' => '#FFFFCC', 'position' => 'top', 'removebutton' => 0);
$model = new Message();
$model->setAttributes($_POST['Message']);
if ($model->save()) {
$resp['message'] = Yii::t('translate', 'Message successfully saved');
$resp['id'] = $model->id;
} else {
$errors = $this->errors($model);
$resp['message'] = Yii::t('translate', '<p>Unable to save the message. Something went wrong!<p/>' . implode('<br/>', $errors));
}
echo $this->je($resp);
Yii::app()->end();
}
$id = (int) Yii::app()->request->getParam('id');
$lang = Yii::app()->request->getParam('lang');
if ($id && $lang) {
$model = MessageSource::model()->findByPk($id);
if ($model) {
$message = $model->loadMessage();
$message->id = $model->id;
$message->language = $lang;
$this->renderPartial('form', array('model' => $message));
} else {
throw new CHttpException(400);
}
} else {
throw new CHttpException(404, 'The requested page does not exist.');
}
}