<?php

$Permissoes = User::getUser(true);

if ($Permissoes->FUN_TBL_RDM == 1 or $Permissoes->FUN_IDSETOR == 5) {

    class RdmCausasController extends GxController {

        var $help = 'Esta é a ajuda';

        public function actionView($id) {
            $this->render('view', array(
                'model' => $this->loadModel($id, 'RdmCausas'),
            ));
        }

        public function actionCreate() {
            $model = new RdmCausas;


            if (isset($_POST['RdmCausas'])) {
                $model->setAttributes($_POST['RdmCausas']);

                if ($model->save()) {
                    if (Yii::app()->getRequest()->getIsAjaxRequest())
                        Yii::app()->end();
                    else
                        $this->redirect(array('view', 'id' => $model->RDC_IDCAUSA));
                }
            }

            $this->render('create', array('model' => $model));
        }

        public function actionUpdate($id) {
            $model = $this->loadModel($id, 'RdmCausas');


            if (isset($_POST['RdmCausas'])) {
                $model->setAttributes($_POST['RdmCausas']);

                if ($model->save()) {
                    $this->redirect(array('view', 'id' => $model->RDC_IDCAUSA));
                }
            }

            $this->render('update', array(
                'model' => $model,
            ));
        }

        public function actionDelete($id) {
            if (Yii::app()->getRequest()->getIsPostRequest()) {
                $this->loadModel($id, 'RdmCausas')->delete();

                if (!Yii::app()->getRequest()->getIsAjaxRequest())
                    $this->redirect(array('admin'));
            } else
                throw new CHttpException(400, 'Sua solicitação é inválida.');
        }

        public function actionAdmin() {
            $model = new RdmCausas('search');
            $model->unsetAttributes();

            if (isset($_GET['RdmCausas']))
                $model->setAttributes($_GET['RdmCausas']);

            $this->render('admin', array(
                'model' => $model,
            ));
        }

    }

}