예제 #1
0
 public static function inserir($instituto)
 {
     if (is_null(InstitutoService::getByNome($instituto->getNome()))) {
         InstitutoDao::inserir($instituto);
         return 0;
     } else {
         return NULL;
     }
 }
예제 #2
0
 public static function exibeInstitutos()
 {
     $institutos = InstitutoService::getInstitutos();
     $table = "";
     $table .= "<form> Nome do Instituto <br> <input class='noEnter' id='criarinst' type='text'> </form>";
     $table .= "<button class='criar'> Criar </button><br><br>";
     $table .= "<table>";
     $table .= "<tr>";
     $table .= "<th>Nome</th>";
     $table .= "<th>Excluir</th>";
     $table .= "<th>Atualizar</th>";
     $table .= "</tr>";
     if ($institutos != null) {
         for ($i = 0; $i < sizeof($institutos); $i++) {
             $table .= "<tr id='tr" . $institutos[$i]->getId() . "'>";
             $table .= "<td>";
             $table .= $institutos[$i]->getNome();
             $table .= "</td>";
             $table .= "<td>";
             $table .= "<button id='e" . $institutos[$i]->getId() . "' class='excluir'>Excluir</button>";
             $table .= "</td>";
             $table .= "<td>";
             $table .= "<button id='a" . $institutos[$i]->getId() . "' class='atualizar'>Atualizar</button>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<form><input id='atualizar" . $institutos[$i]->getId() . "' class='atualizarinst' type='text'> </form>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<button id='c" . $institutos[$i]->getId() . "' class='confirmar'>Confirmar</button>";
             $table .= "</td>";
             $table .= "<td style='display:none'>";
             $table .= "<button id='can" . $institutos[$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/instituto.html");
     $output = str_replace("tabela", $table, $output);
     echo $output;
 }
                    $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;
                    }
                }
            }
        }
    }
}
                    $institutocriado = InstitutoService::getByNome($nomeinst);
                    $arrayretorno['nomeinst'] = $nomeinst;
                    $arrayretorno['idinst'] = $institutocriado->getId();
                    $retornoJSON = json_encode($arrayretorno);
                    echo $retornoJSON;
                } else {
                    $retornoJSON = json_encode(NULL);
                    echo $retornoJSON;
                }
            } else {
                if ($funcao == "atualizar") {
                    $novonome = $_POST['novonome'];
                    $idinst = $_POST['idinst'];
                    $pode = InstitutoService::getByNome($novonome);
                    if (is_null($pode)) {
                        $institutoatualizar = InstitutoService::getById($idinst);
                        $institutoatualizar->setNome($novonome);
                        InstitutoService::alterar($institutoatualizar);
                        $arrayretorno['novonome'] = $institutoatualizar->getNome();
                        $arrayretorno['idinst'] = $institutoatualizar->getId();
                        $retornoJSON = json_encode($arrayretorno);
                        echo $retornoJSON;
                    } else {
                        $retornoJSON = json_encode(NULL);
                        echo $retornoJSON;
                    }
                }
            }
        }
    }
}
예제 #5
0
 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;
 }