Advertisement
Guest User

Untitled

a guest
May 19th, 2017
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.61 KB | None | 0 0
  1. <?php
  2.     class agenda {
  3.        
  4.         var $nome;
  5.         var $email;
  6.         var $telefone;
  7.         function inserir (/*&$a1=array(), &$a2=array(), &$a3=array(),*/ $texto1, $texto2, $texto3) {           
  8.             $this->nome[]=$texto1;
  9.             $this->telefone[]=$texto2;
  10.             $this->email[]=$texto3;
  11.         }
  12.  
  13.    
  14.         function exibir (/*&$a1, &$a2, &$a3*/) {
  15.             if((count(/*$a1*/$this->nome)!=count(/*$a2*/$this->telefone))||(count(/*$a1*/$this->nome)!=count(/*$a3*/$this->email))||(count(/*$a2*/$this->telefone)!=count(/*$a3*/$this->email)))
  16.                 print "erro na database";
  17.             else
  18.                 for($i=0;$i<count($this->nome);$i++) {
  19.                     print "<li>Nome: ".$this->nome[$i]." - Telefone: ".$this->telefone[$i]." - Email: ".$this->email[$i]." - <a href=\"agenda.php?acao=editar&id=$i\">Editar</a> - <a href=\"agenda.php?acao=remover&id=$i\">Remover</a></li>";
  20.                 }
  21.             print "<hr>";
  22.         }
  23.         function remover ($dado) {
  24.             if((count(/*$a1*/$this->nome)!=count(/*$a2*/$this->telefone))||(count(/*$a1*/$this->nome)!=count(/*$a3*/$this->email))||(count(/*$a2*/$this->telefone)!=count(/*$a3*/$this->email)))
  25.                 print "erro na database";
  26.             else
  27.                 for($i=0;$i<count($a1);$i++) {
  28.                     if($a1[$i]==$dado) {
  29.                         $temp=$dado;
  30.                         //$a1[$i]="";
  31.                         //$a2[$i]="";
  32.                         //$a3[$i]="";
  33.                         unset($a1[$i]);
  34.                         unset($a2[$i]);
  35.                         unset($a3[$i]);
  36.                         $a1=array_values($a1);
  37.                         $a2=array_values($a2);
  38.                         $a3=array_values($a3);
  39.                         print "$temp removido com sucesso";
  40.                        
  41.                     }
  42.                 }
  43.             print "<hr>";
  44.  
  45.         }
  46.         function procurarnome ($dado) {
  47.             if((count(/*$a1*/$this->nome)!=count(/*$a2*/$this->telefone))||(count(/*$a1*/$this->nome)!=count(/*$a3*/$this->email))||(count(/*$a2*/$this->telefone)!=count(/*$a3*/$this->email)))
  48.                 print "erro na database";
  49.             else
  50.                 for($i=0;$i<count($a1);$i++) {
  51.                     if($a1[$i]==$dado) {
  52.                         print "<li>Nome: ".$a1[$i]." - Telefone: ".$a2[$i]." - Email: ".$a3[$i]."</li>";
  53.                         break;
  54.                     } else {
  55.                         print "Contato nao encontrado";
  56.                         break;
  57.                     }
  58.                 }
  59.             print "<hr>";
  60.  
  61.         }
  62.         function procurartelefone ($dado) {
  63.             if((count(/*$a1*/$this->nome)!=count(/*$a2*/$this->telefone))||(count(/*$a1*/$this->nome)!=count(/*$a3*/$this->email))||(count(/*$a2*/$this->telefone)!=count(/*$a3*/$this->email)))
  64.                 print "erro na database";
  65.             else
  66.                 for($i=0;$i<count($a1);$i++) {
  67.                     if($a2[$i]==$dado) {
  68.                         print "<li>Nome: ".$a1[$i]." - Telefone: ".$a2[$i]." - Email: ".$a3[$i]."</li>";
  69.                         break;
  70.                     } else {
  71.                         print "Contato nao encontrado";
  72.                         break;
  73.                     }
  74.                 }
  75.             print "<hr>";
  76.  
  77.         }
  78.         function sair () {
  79.             print "<script>close();</script>";
  80.         }
  81.  
  82.     }
  83.     /*$agenda->exibir($nome, $telefone, $email);
  84.     $agenda->inserir($nome, $telefone, $email, "ratio", "1323123", "haha@gov.sssov.br");
  85.     $agenda->inserir($nome, $telefone, $email, "landei", "113223123", "haha@gasdsagov.br");
  86.     $agenda->inserir($nome, $telefone, $email, "zeca", "1116565123", "haha@goasdasdov.gov.br");
  87.     $agenda->exibir($nome, $telefone, $email);
  88.     $agenda->procurarnome($nome, $telefone, $email, "juao");
  89.     $agenda->procurartelefone($nome, $telefone, $email, "72153765213");
  90.     $agenda->remover($nome, $telefone, $email, "tiao");
  91.     $agenda->exibir($nome, $telefone, $email);
  92.     $agenda->sair();
  93.  
  94. */
  95. ?>
  96.  
  97. <?php
  98.     $agenda=new agenda();
  99.     //$nome=array(); $telefone=array(); $email=array();
  100.     $agenda->inserir(/*$nome, $telefone, $email,*/ "jao", "72153765213", "zip@net.com");
  101.     $agenda->inserir(/*$nome, $telefone, $email,*/ "tiao", "365123513", "tiao@pass.com.br");
  102.     $agenda->inserir(/*$nome, $telefone, $email,*/ "juao", "87287367612", "teste3@spress.com.br");
  103.     $agenda->inserir(/*$nome, $telefone, $email,*/ "tina-chan", "1111123123", "haha@gov.gov.gov.br");
  104.     $menu=array(" <a href=\"agenda.php?acao=adicionar\">Adicionar</a> | ",
  105.             " <a href=\"agenda.php?acao=exibir\">Exibir</a> | ",
  106.             " <a href=\"agenda.php?acao=procurar&id=nome\">Procurar por nome</a> | ",
  107.             " <a href=\"agenda.php?acao=procurar&id=telefone\">Procurar por telefone</a> | ",
  108.             " <a href=\"agenda.php?acao=creditos\">Creditos</a> | ",
  109.             " <a href=\"agenda.php?acao=sair\">Sair</a>"
  110.             );
  111.  
  112.     if(isset($_GET['acao'])&&$_GET['acao']=='adicionar') {
  113.         $agenda->inserir("ticarana","87287367612",6515"teste3@spress.com.br");     
  114.         print "add";
  115.     }
  116. ?>
  117. <html>
  118. <head>
  119. <title>Agenda</head>
  120. </head>
  121. <body>
  122. <frame width="100%" height="30" frameborder="1" marginheight="0"><h2>Agenda em PHP</h2><?php foreach($menu as $exibir) print $exibir; ?><hr></frame>
  123. <?php
  124.     //$agenda->exibir($nome, $telefone, $email);
  125.     $agenda->inserir("zeca", "87287367612", "teste3@spress.com.br");
  126.  
  127.     if($_GET['acao']=='exibir') {
  128.         $agenda->exibir();
  129.     }
  130.    
  131. ?>
  132.  
  133. </body>
  134. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement