├── 1crud-generator-php ├── LICENSE ├── README.md ├── assets │ ├── css │ │ ├── bootstrap.min.css │ │ └── style.css │ └── tip.txt ├── db_my.sql ├── db_pg.sql ├── delete.php ├── fetch_data.php ├── footer.php ├── functions │ ├── connection.txt │ └── crud.php ├── header.php ├── index.php ├── insert.php ├── install.php ├── search.php └── update.php ├── 3crud-generator-mvc ├── Classes │ ├── Connection.php │ ├── Controller.php │ ├── Model.php │ └── Utils.php ├── LICENSE ├── README.md ├── assets │ ├── css │ │ ├── bootstrap.min.css │ │ └── style.css │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ ├── images │ │ ├── ajax-loader.gif │ │ ├── crud.png │ │ ├── form_my.png │ │ └── form_pg.png │ ├── js │ │ ├── bootstrap.min.js │ │ ├── jquery-1.10.2.min.js │ │ └── jquery.bootpag.min.js │ └── tip.txt ├── config.php ├── db_my.sql ├── db_pg.sql ├── index.php ├── install.php └── views │ ├── delete.php │ ├── fetch_data.php │ ├── insert.php │ ├── search.php │ ├── templates │ ├── footer.php │ └── header.php │ └── update.php ├── 4crud-generator-mvc-static ├── Classes │ ├── Connection.php │ ├── Controller.php │ ├── Model.php │ └── Utils.php ├── LICENSE ├── README.md ├── assets │ ├── css │ │ ├── bootstrap.min.css │ │ └── style.css │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ ├── images │ │ ├── ajax-loader.gif │ │ ├── crud.png │ │ ├── form_my.png │ │ └── form_pg.png │ ├── js │ │ ├── bootstrap.min.js │ │ ├── jquery-1.10.2.min.js │ │ └── jquery.bootpag.min.js │ └── tip.txt ├── config.php ├── db_my.sql ├── db_pg.sql ├── index.php ├── install.php └── views │ ├── delete.php │ ├── fetch_data.php │ ├── insert.php │ ├── search.php │ ├── templates │ ├── footer.php │ └── header.php │ └── update.php ├── README.md ├── db_my.sql ├── db_pg.sql └── images ├── crud-generator.png └── form.png /1crud-generator-php/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ribamar FS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /1crud-generator-php/README.md: -------------------------------------------------------------------------------- 1 | # Gerador de CRUDs em PHP 2 | 3 | Eu tinha um crud-generator, que é para Laravel. Se estiver procurando por este ele fica em 4 | 5 | https://github.com/ribafs/laravel-crud-generator 6 | 7 | ## Recursos 8 | 9 | - PHP estruturado 10 | - PDO 11 | - Bootstrap 3 12 | - Paginação com Bootpag 13 | - Busca 14 | - Funções úteis 15 | - Boa prática 16 | - Tabela do MySQL com dados de teste gerada pela biblioteca Faker: 17 | - https://github.com/ribafs/faker-dados 18 | - https://github.com/ribafs/FakerRestaurantBr 19 | - https://github.com/fzaninotto/Faker 20 | 21 | ## Requisitos: 22 | - Apache2 23 | - PHP 5.5.9+ 24 | - MySQL 5.5+ ou PostgreSQL 8+ 25 | 26 | ## SGBD testados 27 | 28 | - MySQL 29 | - PostgreSQL 30 | 31 | ## Esta fase 32 | 33 | Esta é a fase inicial deste gerador. Ele tem 4 fases, esta que é em PHP estruturado. A próxima que é em PHPOO. A seguinte usa MVC e a final que usa MVC com classes estáticas. A intenção aqui é mostrar a conversão de um aplicativo em PHP estruturado para PHPOO. Depois converter PHPOO para MVC simples e finalmente converter o aplicativo com MVC para MVC com classes estáticas, como gostam de usar os grandes frameworks. 34 | 35 | ## Instalação 36 | 37 | Somente no primeiro acesso será mostrado o form de instalação. 38 | 39 | - Download de https://github.com/ribafs/auto-crud 40 | - Descompacte para seu diretório web na pasta gerador (exemplo0 41 | - Crie um banco dedados no MySQL 42 | - Acesse 43 | 44 | http://localhost/gerador 45 | 46 | Entre com oa dados no form 47 | 48 | ## MySQL 49 | 50 | ![](assets/images/form_my.png) 51 | 52 | ## PostgreSQL 53 | 54 | ![](assets/images/form_pg.png) 55 | 56 | Então será levado para o CRUD com PDO, Bootstrap, Paginação e Busca, com suporte a MySQL e PostgreSQL garantidos e ainda outros via PDO populado com os registros da tabela indicada. 57 | 58 | ![](assets/images/crud.png) 59 | 60 | Pode e idealmente deve testar com os scripts existentes para mysql e para postgresql: db_my.sql e db_pg.sql. 61 | 62 | ## Customizações 63 | 64 | O código com a paginação está basicamente no arquivo index.php ao final. É uma paginação com o plugin da jQuery Bootpag (https://botmonster.com/jquery-bootpag/). A lib está em assets/js. 65 | 66 | A customização pode ser feita no arquivo index.php 67 | 68 | ## Objetivo principal 69 | 70 | O principal objetivo deste pequeno software é o de facilitar a vida de quem não programa e nem está pensando em aprender e quer apenas criar algo rápido, como uma agenda ou um cadastro simples. 71 | 72 | ## Referências 73 | 74 | - https://www.kodingmadesimple.com/2017/01/simple-ajax-pagination-in-jquery-php-pdo-mysql.html 75 | - https://www.codingcage.com/2015/10/create-pagination-script-using-php-jquery.html 76 | - https://www.bipmedia.com/blog/tutorial/pagination-script-using-php-pdo-with-jquery 77 | 78 | ## Licença 79 | 80 | MIT 81 | 82 | 83 | -------------------------------------------------------------------------------- /1crud-generator-php/assets/css/style.css: -------------------------------------------------------------------------------- 1 | .top{ 2 | padding-top: 5px; 3 | } 4 | 5 | .footer{ 6 | background-color:#e6e6e6; 7 | width:85%; 8 | font-size:11px; 9 | text-align:center; 10 | } 11 | 12 | .header{ 13 | text-align:center; 14 | background-color:#8ad3f7; 15 | padding-top: 10px; 16 | padding-bottom: 10px; 17 | } 18 | -------------------------------------------------------------------------------- /1crud-generator-php/assets/tip.txt: -------------------------------------------------------------------------------- 1 | Glyphicons: 2 | https://www.w3schools.com/bootstrap/bootstrap_ref_comp_glyphs.asp 3 | -------------------------------------------------------------------------------- /1crud-generator-php/delete.php: -------------------------------------------------------------------------------- 1 |
"; 12 | } 13 | } 14 | ?> 15 | -------------------------------------------------------------------------------- /1crud-generator-php/fetch_data.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM $table ORDER BY id DESC LIMIT $start, $regsPerPage"); 18 | }else if($sgbd == 'pgsql'){ 19 | $results = $pdo->prepare("SELECT * FROM $table ORDER BY id DESC LIMIT $regsPerPage OFFSET $start"); 20 | } 21 | 22 | $results->execute(); 23 | $nr = $results->rowCount(); 24 | 25 | if($nr > 0){ 26 | 27 | while($row = $results->fetch(PDO::FETCH_ASSOC)) { 28 | echo "" . rowFields($row); 29 | 30 | $id = $row['id']; 31 | $name = $row['name']; 32 | ?> 33 | 34 | 35 | "; 38 | } 39 | 40 | }else{ 41 | echo '

None register found!

'; 42 | } 43 | -------------------------------------------------------------------------------- /1crud-generator-php/footer.php: -------------------------------------------------------------------------------- 1 | 4 |
5 | 6 | 7 | -------------------------------------------------------------------------------- /1crud-generator-php/functions/connection.txt: -------------------------------------------------------------------------------- 1 | 2 | $regsPerPage = 8; // Registros por página 3 | $linksPerPage = 23; 4 | $appName = 'Gerador de CRUDs com PHPOO'; 5 | 6 | function connection(){ 7 | global $sgbd,$host,$db,$port,$user,$pass; 8 | switch ($sgbd){ 9 | case 'mysql': 10 | try { 11 | $dsn = $sgbd.':host='.$host.';dbname='.$db.';port='.$port; 12 | $pdo = new PDO($dsn, $user, $pass); 13 | // Boa exibição de erros 14 | $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); 15 | $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 16 | 17 | $pdo->query('SET NAMES utf8'); 18 | return $pdo; 19 | 20 | }catch(PDOException $e){ 21 | // Usar estas linhas no catch apenas em ambiente de testes/desenvolvimento. Em produção apenas o exit() 22 | echo '

Código: '.$e->getCode().'

'; 23 | echo 'Mensagem: '. $e->getMessage().'
'; 24 | echo 'Arquivo: '.$e->getFile().'
'; 25 | echo 'Linha: '.$e->getLine().'
'; 26 | exit(); 27 | } 28 | break; 29 | 30 | case 'pgsql': 31 | try { 32 | $dsn = $sgbd.':host='.$host.';dbname='.$db.';port='.$port; 33 | $pdo = new PDO($dsn, $user, $pass); 34 | 35 | // Boa exibição de erros 36 | $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); 37 | $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 38 | 39 | return $pdo; 40 | 41 | }catch(PDOException $e){ 42 | echo '

Código: '.$e->getCode().'

'; 43 | echo 'Mensagem: '. $e->getMessage().'
'; 44 | echo 'Arquivo: '.$e->getFile().'
'; 45 | echo 'Linha: '.$e->getLine().'
'; 46 | exit(); 47 | } 48 | break; 49 | 50 | case 'sqlite': 51 | try { 52 | $pdo = new PDO('sqlite:/db/sqlite3.db'); // Caminho do banco em sqlite 53 | 54 | // Boa exibição de erros 55 | $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); 56 | $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 57 | 58 | return $pdo; 59 | 60 | }catch(PDOException $e){ 61 | echo '

Código: '.$e->getCode().'

'; 62 | echo 'Mensagem: '. $e->getMessage().'
'; 63 | echo 'Arquivo: '.$e->getFile().'
'; 64 | echo 'Linha: '.$e->getLine().'
'; 65 | exit(); 66 | } 67 | break; 68 | case 'default': 69 | break; 70 | } 71 | } 72 | 73 | // Copiar uma pasta com todos os arquivos e subpastas recursivamente 74 | // Crédito - https://stackoverflow.com/questions/2050859/copy-entire-contents-of-a-directory-to-another-using-php#2050909 75 | function copyDir($src,$dst) { 76 | $dir = opendir($src); 77 | mkdir($dst); 78 | while(false !== ( $file = readdir($dir)) ) { 79 | if (( $file != '.' ) && ( $file != '..' )) { 80 | if ( is_dir($src . '/' . $file) ) { 81 | recurse_copy($src . '/' . $file,$dst . '/' . $file); 82 | } 83 | else { 84 | copy($src . '/' . $file,$dst . '/' . $file); 85 | } 86 | } 87 | } 88 | closedir($dir); 89 | } 90 | // Caso a pasta de destino não exista será criada 91 | // copyDir('j381/installation', 'joomla3/installation'); 92 | 93 | // Nomes das tabelas do banco atual 94 | function tableNames(){ 95 | try { 96 | if($sgbd=='mysql'){ 97 | $sql="SHOW TABLES"; 98 | }elseif($sgbd=='pgsql'){ 99 | $sql="SELECT relname FROM pg_class WHERE relname !~ '^(pg_|sql_)' AND relkind = 'r';"; 100 | }elseif($sgbd=='sqlite'){ 101 | $sql='SELECT name FROM sqlite_master WHERE type = "table"'; 102 | } 103 | $tableList = array(); 104 | $res = $pdo->prepare($sql); 105 | $res->execute(); 106 | while($cRow = $res->fetch()) 107 | { 108 | $tableList[] = $cRow[0]; 109 | } 110 | return $tableList;// array 111 | }catch (PDOException $p){ 112 | print $p->getMessage(); 113 | exit; 114 | } 115 | } 116 | 117 | -------------------------------------------------------------------------------- /1crud-generator-php/functions/crud.php: -------------------------------------------------------------------------------- 1 | query($sql); 10 | $num_campos = $sth->columnCount(); 11 | return $num_campos; 12 | } 13 | 14 | // Field name from number $x 15 | function fieldName($x){ 16 | global $pdo, $table; 17 | $sql = 'SELECT * FROM '.$table.' LIMIT 1'; 18 | $sth = $pdo->query($sql); 19 | $meta = $sth->getColumnMeta($x); 20 | $field = $meta['name']; 21 | return $field; 22 | } 23 | 24 | // Return this: 25 | // Name 26 | function formFields(){ 27 | $fields = ''; 28 | 29 | for($x=1;$x < numFields();$x++){ 30 | $field = fieldName($x); 31 | 32 | if($x < numFields()){ 33 | $fields .= ''.ucFirst($field).''."\n"; 34 | } 35 | } 36 | return $fields; 37 | } 38 | 39 | // Return this: /* "" . $row['id'] . "" . */ 40 | function rowFields($row){ 41 | $fields = ''; 42 | $fld = ''; 43 | 44 | for($x=0;$x < numFields();$x++){ 45 | $fld = fieldName($x); 46 | 47 | if($x < numFields() -1){ 48 | $fields .= '' . $row["$fld"] . ''."\n"; 49 | }else{ 50 | $fields .= '' . $row["$fld"] . ''; 51 | } 52 | } 53 | return $fields; 54 | } 55 | 56 | // Return this: ID 57 | function thFields(){ 58 | $fields = ''; 59 | 60 | for($x=0;$x < numFields();$x++){ 61 | $field = fieldName($x); 62 | 63 | if($x < numFields()){ 64 | $fields .= ''.ucFirst($field).''."\n"; 65 | } 66 | } 67 | return $fields; 68 | } 69 | 70 | // Retur all field names: id,name,email,birthday 71 | function fields(){ 72 | $fields = ''; 73 | 74 | for($x=0;$x < numFields();$x++){ 75 | $field = fieldName($x); 76 | 77 | if($x < numFields() -1){ 78 | $fields .= "$field,"."\n"; 79 | }else{ 80 | $fields .= "$field"; 81 | } 82 | } 83 | return $fields; 84 | } 85 | 86 | // Return this: /* Name */ 87 | function fieldsUpdate($reg){ 88 | $fields = ''; 89 | 90 | for($x=1;$x < numFields();$x++){ 91 | $field = fieldName($x); 92 | ?> 93 | "> 94 | prepare($sql); 148 | 149 | for($x=1;$x < numFields();$x++){ 150 | $field = fieldName($x); 151 | $sth->bindParam(":$field", $_POST["$field"], PDO::PARAM_INT); 152 | } 153 | $execute = $sth->execute(); 154 | 155 | if($execute){ 156 | return true; 157 | }else{ 158 | return false; 159 | } 160 | } 161 | } 162 | 163 | // Delete 164 | function delete($id){ 165 | global $pdo, $table; 166 | if(isset($_GET['id'])){ 167 | $id = $_GET['id']; 168 | 169 | $sql = "DELETE FROM {$table} WHERE id = :id"; 170 | $sth = $pdo->prepare($sql); 171 | $sth->bindParam(':id', $id, PDO::PARAM_INT); 172 | 173 | if( $sth->execute()){ 174 | return true; 175 | }else{ 176 | return false; 177 | } 178 | } 179 | } 180 | 181 | // Update 182 | function update(){ 183 | global $pdo, $table; 184 | $updateSet = updateSet(); 185 | $sql = "UPDATE {$table} SET {$updateSet} WHERE id = :id"; 186 | $sth = $pdo->prepare($sql); 187 | 188 | for($x=0;$x < numFields();$x++){ 189 | $field = fieldName($x); 190 | $sth->bindParam(":$field", $_POST["$field"], PDO::PARAM_STR); 191 | } 192 | 193 | if($sth->execute()){ 194 | return true; 195 | }else{ 196 | return false; 197 | } 198 | } 199 | 200 | -------------------------------------------------------------------------------- /1crud-generator-php/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PHP Automatic Applications 5 | 6 | 7 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /1crud-generator-php/index.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT COUNT(*) FROM {$table}"); 12 | $stmt->execute(); 13 | $rows = $stmt->fetch(); 14 | 15 | // get total no. of pages 16 | $totalPages = ceil($rows[0]/$regsPerPage); 17 | ?> 18 | 19 | 20 | 21 |
22 |
23 |

24 |
25 | 26 | 27 | 32 | 33 | 34 |
35 |
36 |
37 | 38 | 42 |   43 | 44 |
45 |
46 |
47 |
48 | 49 | 50 | 51 | 52 | 55 | 56 | 57 | 58 | 59 | 60 |
Actions
61 | 64 |
65 |
66 | 67 | 68 | 69 | 70 | 71 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /1crud-generator-php/insert.php: -------------------------------------------------------------------------------- 1 | 6 | 7 |
8 |
9 |


(Adicionar)

10 |
11 | 12 |
13 |
14 | 15 | 16 | 17 | 20 | 21 | 23 | 24 |
    22 |
25 |
26 |
27 |
28 | 29 | 41 | 42 | -------------------------------------------------------------------------------- /1crud-generator-php/install.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PHP Automatic Application 5 | 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 |

Gerador de CRUDs

14 |
15 |
16 | 17 |
18 |
19 |
20 |

Entre com os dados do banco

21 |
22 |
23 | 24 |
25 |
26 | 27 |
28 |
29 | 30 |
31 |
32 | 33 |
34 |
35 | 36 |
37 |
38 | 39 |
40 |
41 | 42 |
43 | 44 |
45 |
46 |
47 |


48 |
By RibaFS 49 | 50 | 51 | 52 | alert('O diretório functions requer permissão de leitura para o web server!')"; 81 | exit; 82 | } 83 | 84 | $content .=$content2; 85 | 86 | if(is_writable('./functions')){ 87 | $fp = fopen('./functions/connection.php', "w"); 88 | fwrite($fp, $content); 89 | fclose($fp); 90 | }else{ 91 | echo ""; 92 | exit(); 93 | } 94 | 95 | header('location: index.php'); 96 | } 97 | ?> 98 | -------------------------------------------------------------------------------- /1crud-generator-php/search.php: -------------------------------------------------------------------------------- 1 | prepare($sql); 12 | $sth->bindValue(":keyword", $keyword."%"); 13 | $sth->execute(); 14 | //$nr = $sth->rowCount(); 15 | $rows =$sth->fetchAll(PDO::FETCH_ASSOC); 16 | } 17 | ?> 18 |
19 |
20 |

21 |

Registro(s) encontrado(s): '.count($rows).' com '.$keyword.'

'; 23 | 24 | if(count($rows) > 0){ 25 | ?> 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | " . rowFields($row); 40 | } 41 | echo "
"; 42 | 43 | }else{ 44 | print '

None Register fund!

45 |
'; 46 | } 47 | ?> 48 | 49 |
50 |
51 |
52 | 53 | -------------------------------------------------------------------------------- /1crud-generator-php/update.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT {$fields} from $table WHERE id = :id"); 7 | $sth->bindValue(':id', $id, PDO::PARAM_STR); 8 | $sth->execute(); 9 | 10 | $reg = $sth->fetch(PDO::FETCH_ASSOC); 11 | 12 | require_once('./header.php'); 13 | ?> 14 |
15 |
16 |


Atualizar

17 |
18 |
19 |
20 |
21 | 22 | 25 | 26 | 28 |
        27 |
29 |
30 | 31 |
32 |
33 |
34 | 35 |
"; 43 | } 44 | } 45 | ?> 46 | 47 | -------------------------------------------------------------------------------- /3crud-generator-mvc/Classes/Connection.php: -------------------------------------------------------------------------------- 1 | sgbd){ 17 | case 'mysql': 18 | try { 19 | $dsn = $this->sgbd.':host='.$this->host.';dbname='.$this->db.';port='.$this->port; 20 | $this->pdo = new PDO($dsn, $this->user, $this->pass); 21 | // Boa exibição de erros 22 | $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); 23 | $this->pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 24 | 25 | $this->pdo->query('SET NAMES utf8'); 26 | return $this->pdo; 27 | 28 | }catch(PDOException $e){ 29 | // Usar estas linhas no catch apenas em ambiente de testes/desenvolvimento. Em produção apenas o exit() 30 | if($e->getCode() == 1049) { 31 | print '

Favor criar o banco de dados antes e configurá-lo em Classes/Connection.php

'; 32 | exit; 33 | }elseif($e->getCode() == 1045){ 34 | print '

Favor corrigir a senha do banco de dados antes em Classes/Connection.php

'; 35 | exit; 36 | }else{ 37 | echo '

Código: '.$e->getCode().'

'; 38 | echo 'Mensagem: '. $e->getMessage().'
'; 39 | echo 'Arquivo: '.$e->getFile().'
'; 40 | echo 'Linha: '.$e->getLine().'
'; 41 | exit(); 42 | } 43 | echo '

Código: '.$e->getCode().'

'; 44 | echo 'Mensagem: '. $e->getMessage().'
'; 45 | echo 'Arquivo: '.$e->getFile().'
'; 46 | echo 'Linha: '.$e->getLine().'
'; 47 | exit(); 48 | } 49 | break; 50 | 51 | case 'pgsql': 52 | try { 53 | $dsn = $this->sgbd.':host='.$this->host.';dbname='.$this->db.';port='.$this->port; 54 | $this->pdo = new PDO($dsn, $this->user, $this->pass); 55 | 56 | // Boa exibição de erros 57 | $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); 58 | $this->pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 59 | 60 | return $this->pdo; 61 | 62 | }catch(PDOException $e){ 63 | echo '

Código: '.$e->getCode().'

'; 64 | echo 'Mensagem: '. $e->getMessage().'
'; 65 | echo 'Arquivo: '.$e->getFile().'
'; 66 | echo 'Linha: '.$e->getLine().'
'; 67 | exit(); 68 | } 69 | break; 70 | 71 | case 'default': 72 | break; 73 | } 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /3crud-generator-mvc/Classes/Controller.php: -------------------------------------------------------------------------------- 1 | model 14 | - Assim podemos chamar Model nesta classe usando $this->model 15 | */ 16 | 17 | class Controller { 18 | 19 | private $model; 20 | 21 | public function __construct($model) 22 | { 23 | $this->model = $model; 24 | } 25 | 26 | public function insert(){ 27 | if(isset($_POST['send'])){ 28 | if($this->model->insert()){ 29 | return true; 30 | }else{ 31 | return false; 32 | } 33 | } 34 | } 35 | 36 | public function update($id){ 37 | if(isset($_POST['send'])){ 38 | 39 | if($this->model->update($id)){ 40 | return true; 41 | }else{ 42 | return false; 43 | } 44 | } 45 | } 46 | 47 | public function delete($id){ 48 | if(isset($_GET['id'])){ 49 | $id = $_GET['id']; 50 | 51 | if($this->model->delete($id)){ 52 | return true; 53 | }else{ 54 | return false; 55 | } 56 | } 57 | return false; 58 | } 59 | 60 | // Return this: 61 | // Name 62 | public function formFields(){ 63 | $fields = ''; 64 | 65 | for($x=1;$x < $this->model->numFields();$x++){ 66 | $field = $this->model->fieldName($x); 67 | 68 | if($x < $this->model->numFields()){ 69 | $fields .= ''.ucFirst($field).''."\n"; 70 | } 71 | } 72 | return $fields; 73 | } 74 | 75 | // Return this: /* "" . $row['id'] . "" . */ 76 | public function rowFields($row){ 77 | $fields = ''; 78 | $fld = ''; 79 | 80 | for($x=0;$x < $this->model->numFields();$x++){ 81 | $fld = $this->model->fieldName($x); 82 | 83 | if($x < $this->model->numFields() -1){ 84 | $fields .= '' . $row["$fld"] . ''."\n"; 85 | }else{ 86 | $fields .= '' . $row["$fld"] . ''; 87 | } 88 | } 89 | return $fields; 90 | } 91 | 92 | // Return this: ID 93 | public function thFields(){ 94 | $fields = ''; 95 | 96 | for($x=0;$x < $this->model->numFields();$x++){ 97 | $field = $this->model->fieldName($x); 98 | 99 | if($x < $this->model->numFields()){ 100 | $fields .= ''.ucFirst($field).''."\n"; 101 | } 102 | } 103 | return $fields; 104 | } 105 | 106 | // Return this: /* Name */ 107 | public function fieldsUpdate($reg){ 108 | $fields = ''; 109 | 110 | for($x=1;$x < $this->model->numFields();$x++){ 111 | $field = $this->model->fieldName($x); 112 | ?> 113 | "> 114 | table; // $table estará disponível aqui e também para todos que incluirem Model.php 8 | 9 | class Model extends Connection { 10 | 11 | // public $pdo; 12 | public $table; 13 | 14 | /** 15 | * __construct 16 | * Construtor da classe Model 17 | * usage: não precisa chamar, pois em cada instanciação ele é executado automaticamente 18 | * @return void 19 | */ 20 | public function __construct($table) 21 | { 22 | parent::__construct(); // Usado somente em classes filhas 23 | // $this->pdo = $pdo; 24 | $this->table = $table; 25 | } 26 | 27 | public function paging($start, $regsPerPage){ 28 | if($this->sgbd == 'mysql'){ 29 | $results = $this->pdo->prepare("SELECT * FROM $this->table ORDER BY id DESC LIMIT $start, $regsPerPage"); 30 | }else if($this->sgbd == 'pgsql'){ 31 | $results = $this->pdo->prepare("SELECT * FROM $this->table ORDER BY id DESC LIMIT $regsPerPage OFFSET $start"); 32 | } 33 | return $results; 34 | } 35 | 36 | public function search($keyword){ 37 | $sql = "select * from {$this->table} WHERE LOWER({$this->fieldName(1)}) LIKE :keyword order by id"; 38 | $sth = $this->pdo->prepare($sql); 39 | $sth->bindValue(":keyword", $keyword."%"); 40 | $sth->execute(); 41 | //$nr = $sth->rowCount(); 42 | $rows =$sth->fetchAll(PDO::FETCH_ASSOC); 43 | 44 | return $rows; 45 | } 46 | 47 | // Retur all field names: id,name,email,birthday 48 | public function fields(){ 49 | $fields = ''; 50 | 51 | for($x=0;$x < $this->numFields();$x++){ 52 | $field = $this->fieldName($x); 53 | 54 | if($x < $this->numFields() -1){ 55 | $fields .= "$field,"."\n"; 56 | }else{ 57 | $fields .= "$field"; 58 | } 59 | } 60 | return $fields; 61 | } 62 | 63 | public function register($id){ 64 | $sth = $this->pdo->prepare("SELECT {$this->fields()} from $this->table WHERE id = :id"); 65 | $sth->bindValue(':id', $id, PDO::PARAM_INT); 66 | $sth->execute(); 67 | $reg = $sth->fetch(PDO::FETCH_ASSOC); 68 | 69 | return $reg; 70 | } 71 | 72 | // Amount fields current table 73 | public function numFields(){ 74 | $sql = 'SELECT * FROM '.$this->table.' LIMIT 1'; 75 | $sth = $this->pdo->query($sql); 76 | $num_campos = $sth->columnCount(); 77 | return $num_campos; 78 | } 79 | 80 | // Field name from number $x 81 | public function fieldName($x){ 82 | $sql = 'SELECT * FROM '.$this->table.' LIMIT 1'; 83 | $sth = $this->pdo->query($sql); 84 | $meta = $sth->getColumnMeta($x); 85 | $field = $meta['name']; 86 | return $field; 87 | } 88 | 89 | // Return the string to insert(): (name, email, birthday) values (:name, :email, :birthday) 90 | private function inserirStr(){ 91 | $fields = ''; 92 | $values = ''; 93 | 94 | for($x=1;$x < $this->numFields();$x++){ 95 | $field = $this->fieldName($x); 96 | 97 | // Este if gera o seguinte código para a variável $fields = "nome, email, data_nasc, cpf" (exemplo para clientes) 98 | // E também para a variável $values = ":nome, :email, :data_nasc, cpf" 99 | if($x < $this->numFields()-1){ 100 | $fields .= "$field,"; 101 | $values .= ":$field, "; 102 | }else{ 103 | $fields .= "$field"; 104 | $values .= ":$field"; 105 | } 106 | } 107 | $inserirStr = "($fields) VALUES ($values)"; 108 | return $inserirStr; 109 | } 110 | 111 | // Insert 112 | public function insert(){ 113 | if(isset($_POST['send'])){ 114 | $sql = "INSERT INTO $this->table {$this->inserirStr()}"; 115 | $sth = $this->pdo->prepare($sql); 116 | 117 | for($x=1;$x < $this->numFields();$x++){ 118 | $field = $this->fieldName($x); 119 | $sth->bindParam(":$field", $_POST["$field"], PDO::PARAM_INT); 120 | } 121 | $execute = $sth->execute(); 122 | 123 | if($execute){ 124 | return true; 125 | }else{ 126 | return false; 127 | } 128 | } 129 | } 130 | 131 | // Delete 132 | public function delete($id){ 133 | if(isset($_GET['id'])){ 134 | $id = $_GET['id']; 135 | $sql = "DELETE FROM {$this->table} WHERE id = :id"; 136 | $sth = $this->pdo->prepare($sql); 137 | $sth->bindParam(':id', $id, PDO::PARAM_INT); 138 | 139 | if( $sth->execute()){ 140 | return true; 141 | }else{ 142 | return false; 143 | } 144 | } 145 | } 146 | 147 | // Return the string with $set for eath field on Update() 148 | private function updateSet(){ 149 | $set=''; 150 | 151 | for($x=0;$x < $this->numFields();$x++){ 152 | $field = $this->fieldName($x); 153 | // A linha abaixo gerará a linha: $nome = 'Nome do cliente'; 154 | $$field = $_POST[$field]; 155 | 156 | // Este if gerará a variável $set contendo "$nome = :$nome, $email = :$email, ..."; 157 | if($x<$this->numFields()-1){ 158 | if($x==0) continue;// Não contar o campo id 159 | $set .= "$field = :$field,"; 160 | }else{ 161 | if($x==0) continue; 162 | $set .= "$field = :$field"; 163 | } 164 | } 165 | return $set; 166 | } 167 | 168 | // Update 169 | public function update(){ 170 | $sql = "UPDATE {$this->table} SET {$this->updateSet()} WHERE id = :id"; 171 | $sth = $this->pdo->prepare($sql); 172 | 173 | for($x=0;$x < $this->numFields();$x++){ 174 | $field = $this->fieldName($x); 175 | $sth->bindParam(":$field", $_POST["$field"], PDO::PARAM_STR); 176 | } 177 | 178 | if($sth->execute()){ 179 | return true; 180 | }else{ 181 | return false; 182 | } 183 | } 184 | 185 | /** 186 | * nrRegsTable 187 | * Consultar uma tabela e retorna a quantidade de registro da mesma 188 | * usage: return nrRegsTable( ); 189 | * @return int 190 | */ 191 | public function nrRegsTable(){ 192 | $stmt = $this->pdo->prepare( "SELECT COUNT(*) AS nr FROM {$this->table}" ); 193 | $stmt->execute(); 194 | $rows = $stmt->fetch(); 195 | $ret = $rows[ 'nr' ]; 196 | return $ret; 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /3crud-generator-mvc/Classes/Utils.php: -------------------------------------------------------------------------------- 1 | 3)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){if(a(b.target).is(this))return b.handleObj.handler.apply(this,arguments)}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.7",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a("#"===f?[]:f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.7",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c).prop(c,!0)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c).prop(c,!1))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target).closest(".btn");b.call(d,"toggle"),a(c.target).is('input[type="radio"], input[type="checkbox"]')||(c.preventDefault(),d.is("input,button")?d.trigger("focus"):d.find("input:visible,button:visible").first().trigger("focus"))}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=null,this.sliding=null,this.interval=null,this.$active=null,this.$items=null,this.options.keyboard&&this.$element.on("keydown.bs.carousel",a.proxy(this.keydown,this)),"hover"==this.options.pause&&!("ontouchstart"in document.documentElement)&&this.$element.on("mouseenter.bs.carousel",a.proxy(this.pause,this)).on("mouseleave.bs.carousel",a.proxy(this.cycle,this))};c.VERSION="3.3.7",c.TRANSITION_DURATION=600,c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0,keyboard:!0},c.prototype.keydown=function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.prev();break;case 39:this.next();break;default:return}a.preventDefault()}},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.getItemForDirection=function(a,b){var c=this.getItemIndex(b),d="prev"==a&&0===c||"next"==a&&c==this.$items.length-1;if(d&&!this.options.wrap)return b;var e="prev"==a?-1:1,f=(c+e)%this.$items.length;return this.$items.eq(f)},c.prototype.to=function(a){var b=this,c=this.getItemIndex(this.$active=this.$element.find(".item.active"));if(!(a>this.$items.length-1||a<0))return this.sliding?this.$element.one("slid.bs.carousel",function(){b.to(a)}):c==a?this.pause().cycle():this.slide(a>c?"next":"prev",this.$items.eq(a))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){if(!this.sliding)return this.slide("next")},c.prototype.prev=function(){if(!this.sliding)return this.slide("prev")},c.prototype.slide=function(b,d){var e=this.$element.find(".item.active"),f=d||this.getItemForDirection(b,e),g=this.interval,h="next"==b?"left":"right",i=this;if(f.hasClass("active"))return this.sliding=!1;var j=f[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:h});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,g&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(f)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:h});return a.support.transition&&this.$element.hasClass("slide")?(f.addClass(b),f[0].offsetWidth,e.addClass(h),f.addClass(h),e.one("bsTransitionEnd",function(){f.removeClass([b,h].join(" ")).addClass("active"),e.removeClass(["active",h].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(c.TRANSITION_DURATION)):(e.removeClass("active"),f.addClass("active"),this.sliding=!1,this.$element.trigger(m)),g&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this};var e=function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""));if(f.hasClass("carousel")){var g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}};a(document).on("click.bs.carousel.data-api","[data-slide]",e).on("click.bs.carousel.data-api","[data-slide-to]",e),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){var c,d=b.attr("data-target")||(c=b.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"");return a(d)}function c(b){return this.each(function(){var c=a(this),e=c.data("bs.collapse"),f=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b);!e&&f.toggle&&/show|hide/.test(b)&&(f.toggle=!1),e||c.data("bs.collapse",e=new d(this,f)),"string"==typeof b&&e[b]()})}var d=function(b,c){this.$element=a(b),this.options=a.extend({},d.DEFAULTS,c),this.$trigger=a('[data-toggle="collapse"][href="#'+b.id+'"],[data-toggle="collapse"][data-target="#'+b.id+'"]'),this.transitioning=null,this.options.parent?this.$parent=this.getParent():this.addAriaAndCollapsedClass(this.$element,this.$trigger),this.options.toggle&&this.toggle()};d.VERSION="3.3.7",d.TRANSITION_DURATION=350,d.DEFAULTS={toggle:!0},d.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},d.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b,e=this.$parent&&this.$parent.children(".panel").children(".in, .collapsing");if(!(e&&e.length&&(b=e.data("bs.collapse"),b&&b.transitioning))){var f=a.Event("show.bs.collapse");if(this.$element.trigger(f),!f.isDefaultPrevented()){e&&e.length&&(c.call(e,"hide"),b||e.data("bs.collapse",null));var g=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[g](0).attr("aria-expanded",!0),this.$trigger.removeClass("collapsed").attr("aria-expanded",!0),this.transitioning=1;var h=function(){this.$element.removeClass("collapsing").addClass("collapse in")[g](""),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return h.call(this);var i=a.camelCase(["scroll",g].join("-"));this.$element.one("bsTransitionEnd",a.proxy(h,this)).emulateTransitionEnd(d.TRANSITION_DURATION)[g](this.$element[0][i])}}}},d.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse in").attr("aria-expanded",!1),this.$trigger.addClass("collapsed").attr("aria-expanded",!1),this.transitioning=1;var e=function(){this.transitioning=0,this.$element.removeClass("collapsing").addClass("collapse").trigger("hidden.bs.collapse")};return a.support.transition?void this.$element[c](0).one("bsTransitionEnd",a.proxy(e,this)).emulateTransitionEnd(d.TRANSITION_DURATION):e.call(this)}}},d.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()},d.prototype.getParent=function(){return a(this.options.parent).find('[data-toggle="collapse"][data-parent="'+this.options.parent+'"]').each(a.proxy(function(c,d){var e=a(d);this.addAriaAndCollapsedClass(b(e),e)},this)).end()},d.prototype.addAriaAndCollapsedClass=function(a,b){var c=a.hasClass("in");a.attr("aria-expanded",c),b.toggleClass("collapsed",!c).attr("aria-expanded",c)};var e=a.fn.collapse;a.fn.collapse=c,a.fn.collapse.Constructor=d,a.fn.collapse.noConflict=function(){return a.fn.collapse=e,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(d){var e=a(this);e.attr("data-target")||d.preventDefault();var f=b(e),g=f.data("bs.collapse"),h=g?"toggle":e.data();c.call(f,h)})}(jQuery),+function(a){"use strict";function b(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function c(c){c&&3===c.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=b(d),f={relatedTarget:this};e.hasClass("open")&&(c&&"click"==c.type&&/input|textarea/i.test(c.target.tagName)&&a.contains(e[0],c.target)||(e.trigger(c=a.Event("hide.bs.dropdown",f)),c.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger(a.Event("hidden.bs.dropdown",f)))))}))}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.7",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=b(e),g=f.hasClass("open");if(c(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(document.createElement("div")).addClass("dropdown-backdrop").insertAfter(a(this)).on("click",c);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger(a.Event("shown.bs.dropdown",h))}return!1}},g.prototype.keydown=function(c){if(/(38|40|27|32)/.test(c.which)&&!/input|textarea/i.test(c.target.tagName)){var d=a(this);if(c.preventDefault(),c.stopPropagation(),!d.is(".disabled, :disabled")){var e=b(d),g=e.hasClass("open");if(!g&&27!=c.which||g&&27==c.which)return 27==c.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find(".dropdown-menu"+h);if(i.length){var j=i.index(c.target);38==c.which&&j>0&&j--,40==c.which&&jdocument.documentElement.clientHeight;this.$element.css({paddingLeft:!this.bodyIsOverflowing&&a?this.scrollbarWidth:"",paddingRight:this.bodyIsOverflowing&&!a?this.scrollbarWidth:""})},c.prototype.resetAdjustments=function(){this.$element.css({paddingLeft:"",paddingRight:""})},c.prototype.checkScrollbar=function(){var a=window.innerWidth;if(!a){var b=document.documentElement.getBoundingClientRect();a=b.right-Math.abs(b.left)}this.bodyIsOverflowing=document.body.clientWidth
',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},c.prototype.init=function(b,c,d){if(this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d),this.$viewport=this.options.viewport&&a(a.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):this.options.viewport.selector||this.options.viewport),this.inState={click:!1,hover:!1,focus:!1},this.$element[0]instanceof document.constructor&&!this.options.selector)throw new Error("`selector` option must be specified when initializing "+this.type+" on the window.document object!");for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},c.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},c.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusin"==b.type?"focus":"hover"]=!0),c.tip().hasClass("in")||"in"==c.hoverState?void(c.hoverState="in"):(clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show())},c.prototype.isInStateTrue=function(){for(var a in this.inState)if(this.inState[a])return!0;return!1},c.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);if(c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusout"==b.type?"focus":"hover"]=!1),!c.isInStateTrue())return clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide()},c.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(b);var d=a.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]);if(b.isDefaultPrevented()||!d)return;var e=this,f=this.tip(),g=this.getUID(this.type);this.setContent(),f.attr("id",g),this.$element.attr("aria-describedby",g),this.options.animation&&f.addClass("fade");var h="function"==typeof this.options.placement?this.options.placement.call(this,f[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,j=i.test(h);j&&(h=h.replace(i,"")||"top"),f.detach().css({top:0,left:0,display:"block"}).addClass(h).data("bs."+this.type,this),this.options.container?f.appendTo(this.options.container):f.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var k=this.getPosition(),l=f[0].offsetWidth,m=f[0].offsetHeight;if(j){var n=h,o=this.getPosition(this.$viewport);h="bottom"==h&&k.bottom+m>o.bottom?"top":"top"==h&&k.top-mo.width?"left":"left"==h&&k.left-lg.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;jg.right&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){if(!this.$tip&&(this.$tip=a(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),b?(c.inState.click=!c.inState.click,c.isInStateTrue()?c.enter(c):c.leave(c)):c.tip().hasClass("in")?c.leave(c):c.enter(c)},c.prototype.destroy=function(){var a=this;clearTimeout(this.timeout),this.hide(function(){a.$element.off("."+a.type).removeData("bs."+a.type),a.$tip&&a.$tip.detach(),a.$tip=null,a.$arrow=null,a.$viewport=null,a.$element=null})};var d=a.fn.tooltip;a.fn.tooltip=b,a.fn.tooltip.Constructor=c,a.fn.tooltip.noConflict=function(){return a.fn.tooltip=d,this}}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof b&&b;!e&&/destroy|hide/.test(b)||(e||d.data("bs.popover",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.init("popover",a,b)};if(!a.fn.tooltip)throw new Error("Popover requires tooltip.js");c.VERSION="3.3.7",c.DEFAULTS=a.extend({},a.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:''}),c.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content").children().detach().end()[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},c.prototype.hasContent=function(){return this.getTitle()||this.getContent()},c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};var d=a.fn.popover;a.fn.popover=b,a.fn.popover.Constructor=c,a.fn.popover.noConflict=function(){return a.fn.popover=d,this}}(jQuery),+function(a){"use strict";function b(c,d){this.$body=a(document.body),this.$scrollElement=a(a(c).is(document.body)?window:c),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||"")+" .nav li > a",this.offsets=[],this.targets=[],this.activeTarget=null,this.scrollHeight=0,this.$scrollElement.on("scroll.bs.scrollspy",a.proxy(this.process,this)),this.refresh(),this.process()}function c(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})}b.VERSION="3.3.7",b.DEFAULTS={offset:10},b.prototype.getScrollHeight=function(){return this.$scrollElement[0].scrollHeight||Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight)},b.prototype.refresh=function(){var b=this,c="offset",d=0;this.offsets=[],this.targets=[],this.scrollHeight=this.getScrollHeight(),a.isWindow(this.$scrollElement[0])||(c="position",d=this.$scrollElement.scrollTop()),this.$body.find(this.selector).map(function(){var b=a(this),e=b.data("target")||b.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[c]().top+d,e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){b.offsets.push(this[0]),b.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.getScrollHeight(),d=this.options.offset+c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(this.scrollHeight!=c&&this.refresh(),b>=d)return g!=(a=f[f.length-1])&&this.activate(a);if(g&&b=e[a]&&(void 0===e[a+1]||b .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.7",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return e=a-d&&"bottom"},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); -------------------------------------------------------------------------------- /3crud-generator-mvc/assets/js/jquery.bootpag.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | bootpag - jQuery plugin for dynamic pagination 4 | 5 | Copyright (c) 2015 botmonster@7items.com 6 | 7 | Licensed under the MIT license: 8 | http://www.opensource.org/licenses/mit-license.php 9 | 10 | Project home: 11 | http://botmonster.com/jquery-bootpag/ 12 | 13 | Version: 1.0.7 14 | 15 | */ 16 | (function(h,q){h.fn.bootpag=function(p){function m(c,b){b=parseInt(b,10);var d,e=0==a.maxVisible?1:a.maxVisible,k=1==a.maxVisible?0:1,n=Math.floor((b-1)/e)*e,f=c.find("li");a.page=b=0>b?0:b>a.total?a.total:b;f.removeClass(a.activeClass);d=1>b-1?1:a.leaps&&b-1>=a.maxVisible?Math.floor((b-1)/e)*e:b-1;a.firstLastUse&&f.first().toggleClass(a.disabledClass,1===b);e=f.first();a.firstLastUse&&(e=e.next());e.toggleClass(a.disabledClass,1===b).attr("data-lp",d).find("a").attr("href",g(d));k=1==a.maxVisible? 17 | 0:1;d=b+1>a.total?a.total:a.leaps&&b+1