예제 #1
0
 public static function editar()
 {
     $evento = new Evento();
     $evento->selecionarPorId($_GET['id']);
     if (!empty($_POST)) {
         if (!empty($_FILES["Event"]["name"]["imagem"])) {
             $imagem = $_FILES["Event"]["name"]["imagem"];
             $imagem = strtolower(str_replace(" ", "-", $_POST['Event']['nome'])) . md5(date('YmdHis')) . '.' . pathinfo($imagem, PATHINFO_EXTENSION);
             move_uploaded_file($_FILES['Event']['tmp_name']['imagem'], __DIR__ . '/../imagens_evento/' . $imagem);
             unlink(__DIR__ . '/../imagens_evento/' . $_POST['Event']['imagem_antiga']);
         }
         unset($_POST['Event']['imagem_antiga']);
         foreach ($_POST['Event'] as $atributo => $valor) {
             $evento->{$atributo} = $valor;
         }
         $evento->imagem = $imagem;
         $idEvento = $evento->salvar();
         self::redirecionar(Configuracao::$baseUrl . 'evento/listar' . Configuracao::$extensaoPadrao);
     }
     $ingresso = new Ingresso();
     $ingressos = $ingresso->listarPorIdEvento($evento->id);
     $organizador = new Organizador();
     $organizadores = $organizador->listarPorIdEvento($evento->id);
     self::$variaveis = array('evento' => $evento, 'ingressos' => $ingressos, 'organizadores' => $organizadores);
     self::$corpo = "editar";
     self::renderizar(self::$viewController);
 }
예제 #2
0
 public function adicionar()
 {
     $objeto = new Evento();
     if (isset($_GET['id'])) {
         $objeto->load($_GET['id']);
     }
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         Form::salvar();
         if (!$objeto->settipoevento_id("{$_POST[tipoevento_id]}")) {
             redirecionar('', 'Informe o campo tipoevento_id');
         }
         if (!$objeto->setevento_nome("{$_POST[evento_nome]}")) {
             redirecionar('', 'Informe o campo evento_nome');
         }
         if (!$objeto->setevento_datainicio(Formatacao::datatosql($_POST[evento_datainicio]) . ' ' . $_POST['evento_horainicio'])) {
             redirecionar('', 'Informe o campo evento_datainicio');
         }
         if (!$objeto->setevento_datafim(Formatacao::datatosql($_POST[evento_datafim]) . ' ' . $_POST['evento_horafim'])) {
             redirecionar('', 'Informe o campo evento_datafim');
         }
         if (!$objeto->setcliente_cpf_cnpj("{$_POST[cliente_cpf_cnpj]}")) {
             redirecionar('', 'Informe o campo cliente_cpf_cnpj');
         }
         if (!$objeto->setlocal_id("{$_POST[local_id]}")) {
             redirecionar('', 'Informe o campo local_id');
         }
         Form::limpar();
         if ($objeto->salvar()) {
             //infra estritiras
             DB::getConexao()->query("DELETE from eventoinfraest WHERE evento_id = {$objeto->getEvento_id()}");
             DB::getConexao()->query("DELETE from contratoservico WHERE evento_id = {$objeto->getEvento_id()}");
             DB::getConexao()->query("DELETE from eventopatrocinador WHERE evento_id = {$objeto->getEvento_id()}");
             foreach ($_POST['ie_id'] as $infraestrutura) {
                 DB::getConexao()->query("INSERT INTO eventoinfraest(evento_id,ie_id) values({$objeto->getEvento_id()},{$infraestrutura})");
             }
             foreach ($_POST['servico_id'] as $servico) {
                 DB::getConexao()->query("INSERT INTO contratoservico(evento_id,servico_id) values({$objeto->getEvento_id()},{$servico})");
             }
             foreach ($_POST['patrocinador_id'] as $patrocinador_id) {
                 DB::getConexao()->query("INSERT INTO eventopatrocinador(evento_id,patrocinador_id) values({$objeto->getEvento_id()},{$patrocinador_id})");
             }
             redirecionar("?pagina=evento&acao=editar&id={$objeto->getevento_id()}", 'registro salvo com sucesso!');
         } else {
             redirecionar('', 'falha ao salvar registro!');
         }
     } else {
         $template = new Template();
         $template->assignParam('objeto', $objeto);
         return $template->render("evento/editar.phtml");
     }
 }