/**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $endereco_res = EnderecoResidencial::load(json_decode($model->endereco_residencial));
     if (isset($_POST["EnderecoResidencial"])) {
         $model->endereco_residencial = json_encode($_POST["EnderecoResidencial"]);
     }
     if (isset($_POST['Pessoa'])) {
         $model->attributes = $_POST['Pessoa'];
         if (isset($_POST['Pessoa']['projetos_atuante'])) {
             $connection = Yii::app()->db;
             $sql = "delete from projeto_pessoa_atuante where cod_pessoa = :cod_pessoa";
             $command = $connection->createCommand($sql);
             $command->bindParam(":cod_pessoa", $id, PDO::PARAM_STR);
             $command->execute();
             $model->projetos_atuante = $_POST['Pessoa']['projetos_atuante'];
         }
         if ($model->save()) {
             if (isset($_POST['Pessoa']['projetos_atuante'])) {
                 foreach ($model->projetos_atuante as $p) {
                     $ppa = new ProjetoPessoaAtuante();
                     $ppa->cod_pessoa = $model->cod_pessoa;
                     $ppa->cod_projeto = $p;
                     $ppa->save();
                     unset($ppa);
                 }
             }
             $this->redirect(array('view', 'id' => $model->cod_pessoa));
         }
     }
     $this->render('update', array('model' => $model, 'endereco_res' => $endereco_res));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     //Seta o layout
     $this->layout = '//layouts/column1';
     //Pasta onde as imagens serão salvas.
     $dir = Yii::getPathOfAlias('webroot.images.profiles');
     $model = $this->loadModel($id);
     $endereco_res = EnderecoResidencial::load(json_decode($model->endereco_residencial));
     //verifica se o usuario eh permitido para editar a pessoa
     if (!in_array(Yii::app()->user->name, $model->getPermited())) {
         throw new CHttpException(400, 'Permition Denied');
     }
     //Carrega informações de funções
     if (isset($_POST["Pessoa"]["categorias"])) {
         $model->categorias = $_POST["Pessoa"]["categorias"];
     }
     //Carreta informações dos GTs
     if (isset($_POST["Pessoa"]["gts"])) {
         $model->gts = $_POST["Pessoa"]["gts"];
     }
     if (isset($_POST["EnderecoResidencial"])) {
         $model->endereco_residencial = json_encode($_POST["EnderecoResidencial"]);
     }
     if (isset($_POST['Pessoa'])) {
         $model->attributes = $_POST['Pessoa'];
         if ($model->save()) {
             //Salva a imagem do usuário
             $this->saveImage($model);
             //Salva as categorias que esta pessoa pertence
             $this->saveCategory($model);
             //Atualiza os Grupos de trabalho do qual esta pessoa participa
             $this->saveGts($model);
             $this->redirect(array('view', 'id' => $model->cod_pessoa));
         }
     }
     $this->render('update', array('model' => $model, 'endereco_res' => $endereco_res));
 }