public static function inserir($departamento)
 {
     $departamentoexiste = DepartamentoService::getByNome($departamento->getNome());
     if (is_null($departamentoexiste)) {
         DepartamentoDao::inserir($departamento);
         return 0;
     } else {
         return NULL;
     }
 }
                if ($funcao == "atualizar") {
                    $novonome = $_POST['novonome'];
                    $idcurs = $_POST['idcurs'];
                    $novodept = $_POST['novodept'];
                    $novadura = $_POST['novadura'];
                    $novocred = $_POST['novocred'];
                    $pode = CursoService::getByNome($novonome);
                    if (is_null($pode)) {
                        $cursoatualizar = CursoService::getById($idcurs);
                        $cursoatualizar->setNome($novonome);
                        $cursoatualizar->setDept_id(DepartamentoService::getByNome($novodept)->getId());
                        $cursoatualizar->setDuracao($novadura);
                        $cursoatualizar->setCred_form($novocred);
                        CursoService::alterar($cursoatualizar);
                        $arrayretorno['novonome'] = $cursoatualizar->getNome();
                        $arrayretorno['idcurs'] = $cursoatualizar->getId();
                        $arrayretorno['iddept'] = $cursoatualizar->getDept_id();
                        $arrayretorno['duracao'] = $cursoatualizar->getDuracao();
                        $arrayretorno['creditos'] = $cursoatualizar->getCred_form();
                        $arrayretorno['novodept'] = DepartamentoService::getByNome($novodept)->getNome();
                        $retornoJSON = json_encode($arrayretorno);
                        echo $retornoJSON;
                    } else {
                        $retornoJSON = json_encode(NULL);
                        echo $retornoJSON;
                    }
                }
            }
        }
    }
}
                    $retornoJSON = json_encode($arrayretorno);
                    echo $retornoJSON;
                } else {
                    $retornoJSON = json_encode(NULL);
                    echo $retornoJSON;
                }
            } else {
                if ($funcao == "atualizar") {
                    $novonome = $_POST['novonome'];
                    $iddept = $_POST['iddept'];
                    $novoinst = $_POST['novoinst'];
                    $pode = DepartamentoService::getByNome($novonome);
                    if (is_null($pode)) {
                        $departamentoatualizar = DepartamentoService::getById($iddept);
                        $departamentoatualizar->setNome($novonome);
                        $departamentoatualizar->setInst_id(InstitutoService::getByNome($novoinst)->getId());
                        DepartamentoService::alterar($departamentoatualizar);
                        $arrayretorno['novonome'] = $departamentoatualizar->getNome();
                        $arrayretorno['iddept'] = $departamentoatualizar->getId();
                        $arrayretorno['novoinst'] = InstitutoService::getByNome($novoinst)->getNome();
                        $retornoJSON = json_encode($arrayretorno);
                        echo $retornoJSON;
                    } else {
                        $retornoJSON = json_encode(NULL);
                        echo $retornoJSON;
                    }
                }
            }
        }
    }
}
 public static function exibeDepartamentos()
 {
     $departamentos = DepartamentoService::getDepartamentos();
     $institutos = InstitutoService::getInstitutos();
     $table = "";
     $table .= "<form> Nome do Departamento|Instituto <br> <input class='noEnter' id='criardept' type='text'>";
     $table .= "<select class='institutos' style='display:inline'>";
     if ($institutos != null) {
         for ($i = 0; $i < sizeof($institutos); $i++) {
             $table .= "<option value='" . $institutos[$i]->getId() . "'>" . $institutos[$i]->getNome() . "</option>";
         }
     }
     $table .= "</select>";
     $table .= "</form>";
     $table .= "<button class='criar'> Criar </button><br><br>";
     $table .= "<table>";
     $table .= "<tr>";
     $table .= "<th>Nome</th>";
     $table .= "<th>Instituto</th>";
     $table .= "<th>Excluir</th>";
     $table .= "<th>Atualizar</th>";
     $table .= "</tr>";
     if ($departamentos != null) {
         for ($i = 0; $i < sizeof($departamentos); $i++) {
             $instituto = InstitutoService::getById($departamentos[$i]->getInst_id());
             $table .= "<tr id='tr" . $departamentos[$i]->getId() . "'>";
             $table .= "<td>";
             $table .= $departamentos[$i]->getNome();
             $table .= "</td>";
             $table .= "<td>";
             $table .= $instituto->getNome();
             $table .= "</td>";
             $table .= "<td>";
             $table .= "<button id='e" . $departamentos[$i]->getId() . "' class='excluir'>Excluir</button>";
             $table .= "</td>";
             $table .= "<td>";
             $table .= "<button id='a" . $departamentos[$i]->getId() . "' class='atualizar'>Atualizar</button>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<form><input id='atualizar" . $departamentos[$i]->getId() . "' class='atualizardept' type='text'></form>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<select id='drop" . $departamentos[$i]->getId() . "' class='dropatu'>";
             if ($institutos != null) {
                 for ($j = 0; $j < sizeof($institutos); $j++) {
                     $table .= "<option value='" . $institutos[$j]->getId() . "'";
                     if ($institutos[$j]->getNome() == $instituto->getNome()) {
                         $table .= " selected";
                     }
                     $table .= ">" . $institutos[$j]->getNome() . "</option>";
                 }
             }
             $table .= "</select>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<button id='c" . $departamentos[$i]->getId() . "' class='confirmar'>Confirmar</button>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<button id='can" . $departamentos[$i]->getId() . "' class='cancelar'>Cancelar</button>";
             $table .= "</td>";
             $table .= "</tr>";
         }
     }
     $table .= "</table>";
     $table .= "<br>";
     $table .= "<button class='instbut nav'>Institutos</button>";
     $table .= "<button class='deptbut nav'>Departamentos</button>";
     $table .= "<button class='cursbut nav'>Cursos</button>";
     $output = file_get_contents("/var/www/html/Projeto Final BD/Codigo/exibicao/html/departamento.html");
     $output = str_replace("tabela", $table, $output);
     echo $output;
 }
Beispiel #5
0
 public static function exibeCursos()
 {
     $cursos = CursoService::getCursos();
     $departamentos = DepartamentoService::getDepartamentos();
     $table = "";
     $table .= "<form> Nome do Curso|Duração|Créditos|Departamento <br> <input class='noEnter' id='criarcurs' type='text'>";
     $table .= "<select class='criarduracao style='display:inline'>";
     $table .= "<option value='4'>4</option>";
     $table .= "<option value='8'>8</option>";
     $table .= "<option value='10'>10</option>";
     $table .= "</select>";
     $table .= "<input class='creditoscriar' type='number' min='80' max='500'>";
     $table .= "<select class='departamentos' style='display:inline'>";
     if ($departamentos != null) {
         for ($i = 0; $i < sizeof($departamentos); $i++) {
             $table .= "<option value='" . $departamentos[$i]->getId() . "'>" . $departamentos[$i]->getNome() . "</option>";
         }
     }
     $table .= "</select>";
     $table .= "</form>";
     $table .= "<button class='criar'> Criar </button><br><br>";
     $table .= "<table>";
     $table .= "<tr>";
     $table .= "<th>Nome</th>";
     $table .= "<th>Departamento</th>";
     $table .= "<th>Duração</th>";
     $table .= "<th>Créditos</th>";
     $table .= "<th>Excluir</th>";
     $table .= "<th>Atualizar</th>";
     $table .= "</tr>";
     if ($cursos != null) {
         for ($i = 0; $i < sizeof($cursos); $i++) {
             $departamento = DepartamentoService::getById($cursos[$i]->getDept_id());
             $table .= "<tr id='tr" . $cursos[$i]->getId() . "'>";
             $table .= "<td>";
             $table .= $cursos[$i]->getNome();
             $table .= "</td>";
             $table .= "<td>";
             $table .= $departamento->getNome();
             $table .= "</td>";
             $table .= "<td>";
             $table .= $cursos[$i]->getDuracao();
             $table .= "</td>";
             $table .= "<td>";
             $table .= $cursos[$i]->getCred_form();
             $table .= "</td>";
             $table .= "<td>";
             $table .= "<button id='e" . $cursos[$i]->getId() . "' class='excluir'>Excluir</button>";
             $table .= "</td>";
             $table .= "<td>";
             $table .= "<button id='a" . $cursos[$i]->getId() . "' class='atualizar'>Atualizar</button>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<form><input id='atualizar" . $cursos[$i]->getId() . "' class='atualizarcurs' type='text'></form>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<select id='atualizardura" . $cursos[$i]->getId() . "'>";
             $table .= "<option value='4'>4</option>";
             $table .= "<option value='8'>8</option>";
             $table .= "<option value='10'>10</option>";
             $table .= "</select>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<input id='creditosatu" . $cursos[$i]->getId() . "' type='number' min='80' max='500'>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<select id='drop" . $cursos[$i]->getId() . "' class='dropatu'>";
             if ($departamentos != null) {
                 for ($j = 0; $j < sizeof($departamentos); $j++) {
                     $table .= "<option value='" . $departamentos[$j]->getId() . "'";
                     if ($departamentos[$j]->getNome() == $departamento->getNome()) {
                         $table .= " selected";
                     }
                     $table .= ">" . $departamentos[$j]->getNome() . "</option>";
                 }
             }
             $table .= "</select>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<button id='c" . $cursos[$i]->getId() . "' class='confirmar'>Confirmar</button>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<button id='can" . $cursos[$i]->getId() . "' class='cancelar'>Cancelar</button>";
             $table .= "</td>";
             $table .= "</tr>";
         }
     }
     $table .= "</table>";
     $table .= "<br>";
     $table .= "<button class='instbut nav'>Institutos</button>";
     $table .= "<button class='deptbut nav'>Departamentos</button>";
     $table .= "<button class='cursbut nav'>Cursos</button>";
     $output = file_get_contents("/var/www/html/Projeto Final BD/Codigo/exibicao/html/curso.html");
     $output = str_replace("tabela", $table, $output);
     echo $output;
 }