Commit c4489191a96868d09331476ed2dd236541b3e29f
1 parent
cb25f94c
Exists in
master
and in
7 other branches
Conversão do formulário de cadastro de usuários para bootstrap
Showing
7 changed files
with
100 additions
and
27 deletions
Show diff stats
admin/admin.db
No preview for this file type
admin1/dicionario/usuarios.js
admin1/usuarios/cadastro/exec.php
| ... | ... | @@ -32,7 +32,8 @@ $funcoesEdicao = array ( |
| 32 | 32 | "ADICIONARUSUARIO", |
| 33 | 33 | "ALTERARUSUARIO", |
| 34 | 34 | "ADICIONAPAPELUSUARIO", |
| 35 | - "EXCLUIRUSUARIO" | |
| 35 | + "EXCLUIRUSUARIO", | |
| 36 | + "ENVIARSENHA" | |
| 36 | 37 | ); |
| 37 | 38 | if (in_array ( strtoupper ( $funcao ), $funcoesEdicao )) { |
| 38 | 39 | if (verificaOperacaoSessao ( "admin/html/usuarios" ) == false) { |
| ... | ... | @@ -45,11 +46,10 @@ $funcao = strtoupper ( $funcao ); |
| 45 | 46 | // converte os parametros de definicao dos papeis em um array |
| 46 | 47 | if ($funcao == "ADICIONARUSUARIO" || $funcao == "ALTERARUSUARIO") { |
| 47 | 48 | $papeis = array (); |
| 48 | - $papeis [] = 1; // admin | |
| 49 | 49 | foreach ( array_keys ( $_POST ) as $k ) { |
| 50 | 50 | $teste = explode ( "-", $k ); |
| 51 | - if ($teste [0] == "id_papel") { | |
| 52 | - $papeis [] = $teste [1] * 1; | |
| 51 | + if ($teste[0] == "id_papel") { | |
| 52 | + $papeis[] = $teste[1] * 1; | |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | array_unique ( $papeis ); |
| ... | ... | @@ -64,6 +64,13 @@ switch ($funcao) { |
| 64 | 64 | header ( "HTTP/1.1 500 erro ao consultar banco de dados" ); |
| 65 | 65 | exit (); |
| 66 | 66 | } |
| 67 | + if(strtolower($enviaSenha) == "on"){ | |
| 68 | + if($senha == "" || $email == ""){ | |
| 69 | + $dados = header ( "HTTP/1.1 500 para enviar a senha é necessário preencher o valor de senha e e-mail" ); | |
| 70 | + } else { | |
| 71 | + $dados = enviarSenha( $senha, $email ); | |
| 72 | + } | |
| 73 | + } | |
| 67 | 74 | retornaJSON ( $dados ); |
| 68 | 75 | } else { |
| 69 | 76 | header ( "HTTP/1.1 500 erro ao consultar banco de dados" ); |
| ... | ... | @@ -83,6 +90,13 @@ switch ($funcao) { |
| 83 | 90 | header ( "HTTP/1.1 500 erro ao consultar banco de dados" ); |
| 84 | 91 | exit (); |
| 85 | 92 | } |
| 93 | + if(strtolower($enviaSenha) == "on"){ | |
| 94 | + if($senha == "" || $email == ""){ | |
| 95 | + $dados = header ( "HTTP/1.1 500 para enviar a senha é necessário preencher o valor de senha e e-mail" ); | |
| 96 | + } else { | |
| 97 | + $dados = enviarSenha( $senha, $email ); | |
| 98 | + } | |
| 99 | + } | |
| 86 | 100 | retornaJSON ( $dados ); |
| 87 | 101 | exit (); |
| 88 | 102 | break; |
| ... | ... | @@ -100,23 +114,23 @@ switch ($funcao) { |
| 100 | 114 | // pega os papeis registrados para cada operacao |
| 101 | 115 | $p = array (); |
| 102 | 116 | foreach ( $papeis as $papel ) { |
| 103 | - if ($papel ["id_usuario"] == $usuario ["id_usuario"]) { | |
| 104 | - $p [$papel ["id_papel"]] = $papel; | |
| 117 | + if ($papel["id_usuario"] == $usuario["id_usuario"]) { | |
| 118 | + $p[$papel["id_papel"]] = $papel; | |
| 105 | 119 | } |
| 106 | 120 | } |
| 107 | - $usuarios ["papeis"] = $p; | |
| 108 | - $o [] = $usuario; | |
| 121 | + $usuario["papeis"] = $p; | |
| 122 | + $o[] = $usuario; | |
| 109 | 123 | } |
| 110 | 124 | $papeis = pegaDados ( "SELECT * from " . $esquemaadmin . "i3geousr_papeis order by nome", $dbh ); |
| 111 | 125 | $dbhw = null; |
| 112 | 126 | $dbh = null; |
| 113 | 127 | if ($papeis == false) { |
| 114 | 128 | header ( "HTTP/1.1 500 erro ao consultar banco de dados" ); |
| 115 | - exit (); | |
| 129 | + exit(); | |
| 116 | 130 | } |
| 117 | 131 | retornaJSON ( array ( |
| 118 | 132 | "usuarios" => $o, |
| 119 | - "papeis" => $papeis | |
| 133 | + "papeis" => $papeis | |
| 120 | 134 | ) ); |
| 121 | 135 | break; |
| 122 | 136 | case "EXCLUIRUSUARIO" : |
| ... | ... | @@ -130,8 +144,28 @@ switch ($funcao) { |
| 130 | 144 | retornaJSON ( $id_usuario ); |
| 131 | 145 | exit (); |
| 132 | 146 | break; |
| 147 | + case "ENVIARSENHA" : | |
| 148 | + if($senha == "" || $email == ""){ | |
| 149 | + header ( "HTTP/1.1 500 erro ao enviar e-mail. Prrencha o valor de e-mail e senha" ); | |
| 150 | + exit (); | |
| 151 | + } | |
| 152 | + $retorna = enviarSenha ( $senha, $email ); | |
| 153 | + if ($retorna == false) { | |
| 154 | + header ( "HTTP/1.1 500 erro ao enviar e-mail $email" ); | |
| 155 | + exit (); | |
| 156 | + } | |
| 157 | + retornaJSON ( true ); | |
| 158 | + exit (); | |
| 159 | + break; | |
| 133 | 160 | } |
| 134 | 161 | cpjson ( $retorno ); |
| 162 | + | |
| 163 | +function enviarSenha( $senha, $email ){ | |
| 164 | + $to = $email; | |
| 165 | + $subject = 'senha i3geo criada em '. date('l jS \of F Y h:i:s A'); | |
| 166 | + $message = $senha; | |
| 167 | + return mail($to, $subject, $message); | |
| 168 | +} | |
| 135 | 169 | // $papeis deve ser um array |
| 136 | 170 | function adicionarUsuario($ativo, $data_cadastro, $email, $login, $nome_usuario, $senha, $papeis, $dbhw) { |
| 137 | 171 | global $esquemaadmin; |
| ... | ... | @@ -145,6 +179,7 @@ function adicionarUsuario($ativo, $data_cadastro, $email, $login, $nome_usuario, |
| 145 | 179 | "senha" => '' |
| 146 | 180 | ); |
| 147 | 181 | $id_usuario = i3GeoAdminInsertUnico ( $dbhw, "i3geousr_usuarios", $dataCol, "nome_usuario", "id_usuario" ); |
| 182 | + $data_cadastro = date('l jS \of F Y h:i:s A'); | |
| 148 | 183 | $retorna = alterarUsuario ( $id_usuario, $ativo, $data_cadastro, $email, $login, $nome_usuario, $senha, $papeis, $dbhw ); |
| 149 | 184 | return $retorna; |
| 150 | 185 | } catch ( PDOException $e ) { |
| ... | ... | @@ -161,10 +196,8 @@ function alterarUsuario($id_usuario, $ativo, $data_cadastro, $email, $login, $no |
| 161 | 196 | "nome_usuario" => $nome_usuario, |
| 162 | 197 | "login" => $login, |
| 163 | 198 | "email" => $email, |
| 164 | - "ativo" => $ativo, | |
| 165 | - "data_cadastro" => $data_cadastro | |
| 199 | + "ativo" => $ativo | |
| 166 | 200 | ); |
| 167 | - | |
| 168 | 201 | // se a senha foi enviada, ela sera trocada |
| 169 | 202 | if ($senha != "") { |
| 170 | 203 | $dataCol ["senha"] = md5 ( $senha ); |
| ... | ... | @@ -193,7 +226,7 @@ function adicionaPapelUsuario($id_usuario, $id_papel, $dbhw) { |
| 193 | 226 | global $esquemaadmin; |
| 194 | 227 | $dataCol = array ( |
| 195 | 228 | "id_usuario" => $id_usuario, |
| 196 | - "id_papel" => $id_papel | |
| 229 | + "id_papel" => $id_papel | |
| 197 | 230 | ); |
| 198 | 231 | $resultado = i3GeoAdminInsert ( $dbhw, "i3geousr_papelusuario", $dataCol ); |
| 199 | 232 | return $resultado; | ... | ... |
admin1/usuarios/cadastro/index.js
| ... | ... | @@ -42,6 +42,8 @@ function pegaUsuarios(){ |
| 42 | 42 | ) |
| 43 | 43 | .done( |
| 44 | 44 | function(data, status){ |
| 45 | + //valor do filtro atual | |
| 46 | + var filtro = valorFiltro(); | |
| 45 | 47 | //objeto json com os dados viondos do banco |
| 46 | 48 | var json = jQuery.parseJSON(data); |
| 47 | 49 | //template dos checkbox |
| ... | ... | @@ -58,6 +60,7 @@ function pegaUsuarios(){ |
| 58 | 60 | "salvar": $trad("salva",i3GEOadmin.core.dicionario), |
| 59 | 61 | "onSalvar": "salvarUsuarioDialogo",//funcao |
| 60 | 62 | "enviaSenha": $trad("enviaSenha",i3GEOadmin.usuarios.dicionario), |
| 63 | + "onEnviarSenha": "EnviarSenha",//funcao | |
| 61 | 64 | "usuario": $trad("usuario",i3GEOadmin.usuarios.dicionario), |
| 62 | 65 | "nome": $trad("nome",i3GEOadmin.usuarios.dicionario), |
| 63 | 66 | "labelDataCadastro": $trad("dataCadastro",i3GEOadmin.usuarios.dicionario), |
| ... | ... | @@ -111,12 +114,16 @@ function pegaUsuarios(){ |
| 111 | 114 | {"data":json["usuarios"]} |
| 112 | 115 | ); |
| 113 | 116 | $("#filtro").html("<option value='' >---</option>" + html); |
| 114 | - | |
| 117 | + if(filtro != ""){ | |
| 118 | + defineFiltro(filtro); | |
| 119 | + filtra(pegaFiltro()); | |
| 120 | + } | |
| 115 | 121 | //monta um template para o modal de inclusao de novo usuario |
| 116 | 122 | html = Mustache.to_html( |
| 117 | 123 | $("#templateUsuarios").html(), |
| 118 | 124 | { |
| 119 | 125 | "id_usuario": "modal", |
| 126 | + "enviaSenha": $trad("enviaSenha",i3GEOadmin.usuarios.dicionario), | |
| 120 | 127 | "excluir": $trad("cancelar",i3GEOadmin.core.dicionario), |
| 121 | 128 | "onExcluir": "fechaModalGeral",//funcao |
| 122 | 129 | "salvar": $trad("salva",i3GEOadmin.core.dicionario), |
| ... | ... | @@ -238,8 +245,18 @@ function salvarUsuario(id_usuario){ |
| 238 | 245 | } |
| 239 | 246 | ); |
| 240 | 247 | } |
| 241 | -function filtra(obj,id){ | |
| 242 | - $("#" + id + " .panel").each( | |
| 248 | +function pegaFiltro(){ | |
| 249 | + return $i("filtro"); | |
| 250 | +} | |
| 251 | +function valorFiltro(){ | |
| 252 | + return pegaFiltro().value; | |
| 253 | +} | |
| 254 | +function defineFiltro(valor){ | |
| 255 | + pegaFiltro().value = valor; | |
| 256 | +} | |
| 257 | +function filtra(obj){ | |
| 258 | + | |
| 259 | + $("#corpo .panel").each( | |
| 243 | 260 | function(i,el){ |
| 244 | 261 | if(obj.value == ""){ |
| 245 | 262 | $(el).show(); |
| ... | ... | @@ -253,3 +270,4 @@ function filtra(obj,id){ |
| 253 | 270 | $("#"+obj.value).show(); |
| 254 | 271 | } |
| 255 | 272 | } |
| 273 | + | ... | ... |
admin1/usuarios/cadastro/index.php
| ... | ... | @@ -27,7 +27,7 @@ include "../../head.php"; |
| 27 | 27 | <!-- aqui entra o filtro --> |
| 28 | 28 | <div class="form-group"> |
| 29 | 29 | <label class="control-label">{{{filtro}}}</label> |
| 30 | - <select onchange="filtra(this,'corpo')" id="filtro" class="form-control input-lg"> | |
| 30 | + <select onchange="filtra(this)" id="filtro" class="form-control input-lg"> | |
| 31 | 31 | </select> |
| 32 | 32 | </div> |
| 33 | 33 | <div class="row pull-right"> |
| ... | ... | @@ -81,7 +81,7 @@ include "../../head.php"; |
| 81 | 81 | <div class="form-group form-group-lg"> |
| 82 | 82 | <label class="col-md-2 control-label" for="novasenha">{{{labelNovaSenha}}}</label> |
| 83 | 83 | <div class="col-md-10"> |
| 84 | - <input type="password" value="" class="form-control" name="novasenha" > | |
| 84 | + <input type="password" value="" class="form-control" name="senha" > | |
| 85 | 85 | </div> |
| 86 | 86 | </div> |
| 87 | 87 | <div class="form-group form-group-lg"> |
| ... | ... | @@ -93,7 +93,7 @@ include "../../head.php"; |
| 93 | 93 | <div class="form-group form-group-lg"> |
| 94 | 94 | <label class="col-md-2 control-label" for="data_cadastro">{{{labelDataCadastro}}}</label> |
| 95 | 95 | <div class="col-md-10"> |
| 96 | - <input type="date" value="{{{email}}}" class="form-control" name="data_cadastro"> | |
| 96 | + <input disabled="" type="text" value="{{{data_cadastro}}}" class="form-control" name="data_cadastro"> | |
| 97 | 97 | </div> |
| 98 | 98 | </div> |
| 99 | 99 | <div class="form-group form-group-lg"> |
| ... | ... | @@ -105,12 +105,19 @@ include "../../head.php"; |
| 105 | 105 | </select> |
| 106 | 106 | </div> |
| 107 | 107 | </div> |
| 108 | + <div class="form-group form-group-lg"> | |
| 109 | + <div class="col-md-2"></div> | |
| 110 | + <div class="checkbox col-md-10"> | |
| 111 | + <label> | |
| 112 | + <input type="checkbox" checked name="enviaSenha" /> {{{enviaSenha}}} | |
| 113 | + </label> | |
| 114 | + </div> | |
| 115 | + </div> | |
| 108 | 116 | </div> |
| 109 | 117 | </div> |
| 110 | 118 | </form> |
| 111 | 119 | <div class="pull-right"> |
| 112 | 120 | <a href="javascript:void(0)" onclick="{{onExcluir}}('{{id_usuario}}')" class="btn btn-danger" role="button">{{excluir}}</a> |
| 113 | - <a href="javascript:void(0)" onclick="{{onEnviarSenha}}('{{id_usuario}}')" class="btn btn-default" role="button">{{{enviaSenha}}}</a> | |
| 114 | 121 | <a href="javascript:void(0)" onclick="{{onSalvar}}('{{id_usuario}}')" class="btn btn-primary" role="button">{{salvar}}</a> |
| 115 | 122 | </div> |
| 116 | 123 | </div> | ... | ... |
admin1/usuarios/operacoes/index.js
| ... | ... | @@ -46,6 +46,8 @@ function pegaOperacoes(){ |
| 46 | 46 | ) |
| 47 | 47 | .done( |
| 48 | 48 | function(data, status){ |
| 49 | + //valor do filtro atual | |
| 50 | + var filtro = valorFiltro(); | |
| 49 | 51 | //objeto json com os dados viondos do banco |
| 50 | 52 | var json = jQuery.parseJSON(data); |
| 51 | 53 | //template dos checkbox |
| ... | ... | @@ -94,7 +96,10 @@ function pegaOperacoes(){ |
| 94 | 96 | {"data":json["operacoes"]} |
| 95 | 97 | ); |
| 96 | 98 | $("#filtro").html("<option value='' >---</option>" + html); |
| 97 | - | |
| 99 | + if(filtro != ""){ | |
| 100 | + defineFiltro(filtro); | |
| 101 | + filtra(pegaFiltro()); | |
| 102 | + } | |
| 98 | 103 | //monta um template para o modal de inclusao de nova operacao |
| 99 | 104 | html = Mustache.to_html( |
| 100 | 105 | $("#templateOperacoes").html(), |
| ... | ... | @@ -204,7 +209,7 @@ function salvarOperacao(id_operacao){ |
| 204 | 209 | modalAguarde(true); |
| 205 | 210 | $.post( |
| 206 | 211 | "exec.php?funcao=alterarOperacao", |
| 207 | - "id_operacao="+ id_operacao+"&"+parametros | |
| 212 | + "id_operacao="+ id_operacao +"&"+parametros | |
| 208 | 213 | ) |
| 209 | 214 | .done( |
| 210 | 215 | function(data, status){ |
| ... | ... | @@ -220,8 +225,18 @@ function salvarOperacao(id_operacao){ |
| 220 | 225 | } |
| 221 | 226 | ); |
| 222 | 227 | } |
| 223 | -function filtra(obj,id){ | |
| 224 | - $("#" + id + " .panel").each( | |
| 228 | +function pegaFiltro(){ | |
| 229 | + return $i("filtro"); | |
| 230 | +} | |
| 231 | +function valorFiltro(){ | |
| 232 | + return pegaFiltro().value; | |
| 233 | +} | |
| 234 | +function defineFiltro(valor){ | |
| 235 | + pegaFiltro().value = valor; | |
| 236 | +} | |
| 237 | +function filtra(obj){ | |
| 238 | + | |
| 239 | + $("#corpo .panel").each( | |
| 225 | 240 | function(i,el){ |
| 226 | 241 | if(obj.value == ""){ |
| 227 | 242 | $(el).show(); | ... | ... |
admin1/usuarios/operacoes/index.php
| ... | ... | @@ -27,7 +27,7 @@ include "../../head.php"; |
| 27 | 27 | <!-- aqui entra o filtro --> |
| 28 | 28 | <div class="form-group"> |
| 29 | 29 | <label class="control-label">{{{filtro}}}</label> |
| 30 | - <select onchange="filtra(this,'corpo')" id="filtro" class="form-control input-lg"> | |
| 30 | + <select onchange="filtra(this)" id="filtro" class="form-control input-lg"> | |
| 31 | 31 | </select> |
| 32 | 32 | </div> |
| 33 | 33 | <div class="row pull-right"> | ... | ... |