Guest User

Untitled

a guest
Oct 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. <?php
  2.  
  3. include_once 'config.php';
  4. global $pdo;
  5.  
  6. //Here you can see the fields in the student table: nome, fone and email.
  7. And only one field in the pay table that is: situacao_aluno
  8.  
  9. $sql = "select * from alunos left join pagamentos on id_alunos =
  10. pagamentos.alunos_id order by nome";
  11. $sql = $pdo->query($sql);
  12.  
  13. if ($sql->rowCount() > 0) {
  14. foreach ($sql->fetchAll() as $aluno):
  15. ?>
  16.  
  17. <tr>
  18. <td> <?php echo $aluno['nome']; ?> </td>
  19. <td> <?php echo $aluno['fone']; ?> </td>
  20. <td> <?php echo $aluno['email']; ?> </td>
  21. <td> <?php echo $aluno['situacao_aluno']; ?> </td>
  22.  
  23. <?php
  24. echo "<td><a href='editar.php?id_alunos=" . $aluno['id_alunos'] . "'
  25. class='btn btn-dark' role='button'>Update</a></td>";
  26.  
  27. echo "<td><a href='delete_submit.php?id_alunos=" . $aluno['id_alunos'] .
  28. "' class='btn btn-danger'>Delete</a></td>";
  29. echo "</tr>";
  30.  
  31. ?>
  32.  
  33. <?php
  34. include_once 'includes/header.inc.php';
  35. include_once 'includes/menu.inc.php';
  36. include_once 'config.php';
  37. ?>
  38.  
  39. <?php
  40.  
  41. $id_alunos = (isset($_GET['id_alunos'])) ? $_GET['id_alunos'] : '';
  42.  
  43. if (!empty($id_alunos) && filter_var($id_alunos, FILTER_VALIDATE_INT)):
  44.  
  45. $ret = array();
  46.  
  47. global $pdo;
  48. $sql = "select * from alunos left join pagamentos on alunos.id_alunos =
  49. pagamentos.alunos_id where alunos.id_alunos = $id_alunos";
  50.  
  51. $sql = $pdo->query($sql);
  52. if ($sql->rowCount() > 0):
  53. $ret = $sql->fetchAll()[0];
  54. endif;
  55.  
  56. if(empty($ret)) {
  57. header('Location: home.php');
  58.  
  59. exit(0);
  60. }
  61. endif;
  62.  
  63. ?>
  64.  
  65. <?php
  66. require 'config.php';
  67. require 'class/crud.php';
  68.  
  69. $id_alunos = (isset($_POST['id_alunos'])) ? $_POST['id_alunos'] : 0;
  70. if(empty($id_alunos)){
  71. header('Location: home.php');
  72. exit(0);
  73. }
  74.  
  75. $altera = new Alunos();
  76.  
  77. $nome = addslashes($_POST['nome']);
  78. $rg = addslashes($_POST['rg']);
  79. $cpf = addslashes($_POST['cpf']);
  80. $nascimento = addslashes($_POST['nascimento']);
  81. $sexo = addslashes($_POST['sexo']);
  82. $fone = addslashes($_POST['fone']);
  83. $email = addslashes($_POST['email']);
  84. $endereco = addslashes($_POST['endereco']);
  85. $bairro = addslashes($_POST['bairro']);
  86. $cidade = addslashes($_POST['cidade']);
  87. $estado = addslashes($_POST['estado']);
  88. $cep = addslashes($_POST['cep']);
  89. $situacao_aluno = addslashes($_POST['situacao_aluno']);
  90. $vencimento_plano = addslashes($_POST['vencimento_plano']);
  91. $planos = addslashes($_POST['planos']);
  92. $vencimento = addslashes($_POST['vencimento']);
  93. $cpf_amigo = addslashes($_POST['cpf_amigo']);
  94. $forma_pagamento = addslashes($_POST['forma_pagamento']);
  95. $data_matricula = addslashes($_POST['data_matricula']);
  96. $numero_documento = addslashes($_POST['numero_documento']);
  97. $data_documento = addslashes($_POST['data_documento']);
  98. $valor = addslashes($_POST['valor']);
  99.  
  100. $altera->UpdateAlunos($id_alunos, $nome, $rg ,$cpf, $nascimento, $sexo,
  101. $fone, $email, $endereco, $bairro, $cidade, $estado, $cep);
  102.  
  103. $altera->UpdatePagamentos($id_alunos, $email, $situacao_aluno,
  104. $vencimento_plano, $planos,$vencimento, $cpf_amigo, $forma_pagamento,
  105. $data_matricula, $numero_documento, $data_documento, $valor);
  106.  
  107. header('Location: editar.php?id_alunos='.$id_alunos);
  108. ?>
  109.  
  110. //Here in the case I will only show the UPDATE,
  111.  
  112. /*
  113. * class UpdateAlunos()
  114. * edit the table students
  115. */
  116.  
  117. public function UpdateAlunos($id_alunos, $nome, $rg, $cpf, $nascimento,
  118. $sexo, $fone, $email, $endereco, $bairro, $cidade, $estado, $cep)
  119. {
  120.  
  121. global $pdo;
  122.  
  123.  
  124. $sql = $pdo->prepare("update alunos set nome=:nome, rg=:rg, cpf=:cpf,
  125. nascimento=:nascimento, sexo=:sexo, fone=:fone, email=:email,
  126. endereco=:endereco, bairro=:bairro, cidade=:cidade, estado=:estado, cep=:cep
  127. where id_alunos = '$id_alunos'");
  128.  
  129. $sql->bindValue(":nome", $nome);
  130. $sql->bindValue(":rg", $rg);
  131. $sql->bindValue(":cpf", $cpf);
  132. $sql->bindValue(":nascimento", $nascimento);
  133. $sql->bindValue(":sexo", $sexo);
  134. $sql->bindValue(":fone", $fone);
  135. $sql->bindValue(":email", $email);
  136. $sql->bindValue(":endereco", $endereco);
  137. $sql->bindValue(":bairro", $bairro);
  138. $sql->bindValue(":cidade", $cidade);
  139. $sql->bindValue(":estado", $estado);
  140. $sql->bindValue(":cep", $cep);
  141. $sql->execute();
  142.  
  143. }
  144.  
  145. /*
  146. * class UpdatePagamentos()
  147. * edit the payments table
  148. */
  149.  
  150. public function UpdatePagamentos($situacao_aluno, $vencimento_plano,
  151. $planos, $vencimento, $cpf_amigo, $forma_pagamento, $data_matricula,
  152. $numero_documento, $data_documento, $valor)
  153. {
  154.  
  155. global $pdo;
  156.  
  157.  
  158. $sql = $pdo->prepare("update pagamentos set situacao_aluno=:situacao_aluno,
  159. vencimento_plano=:vencimento_plano, planos=:planos, vencimento=:vencimento,
  160. cpf_amigo=:cpf_amigo, forma_pagamento=:forma_pagamento,
  161. data_matricula=:data_matricula, numero_documento=:numero_documento,
  162. data_documento=:data_documento, valor=:valor where alunos_id =
  163. '$id_alunos'");
  164. $sql->bindValue(":situacao_aluno", $situacao_aluno);
  165. $sql->bindValue(":vencimento_plano", $vencimento_plano);
  166. $sql->bindValue(":planos", $planos);
  167. $sql->bindValue(":vencimento", $vencimento);
  168. $sql->bindValue(":cpf_amigo", $cpf_amigo);
  169. $sql->bindValue(":forma_pagamento", $forma_pagamento);
  170. $sql->bindValue(":data_matricula", $data_matricula);
  171. $sql->bindValue(":numero_documento", $numero_documento);
  172. $sql->bindValue(":data_documento", $data_documento);
  173. $sql->bindValue(":valor", $valor);
  174. $sql->execute();
  175.  
  176. }
Add Comment
Please, Sign In to add comment