<?php

$Permissoes = User::getUser(true);

if ($Permissoes->FUN_TBL_BRINDES == 1) {

    class BrindesController extends GxController {

        var $help = 'Esta é a ajuda';

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

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


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

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

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

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


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

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

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

        public function actionDelete($id) {
            if (Yii::app()->getRequest()->getIsPostRequest()) {
                $this->loadModel($id, 'Brindes')->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 Brindes('search');
            $model->unsetAttributes();

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

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

    }

}