public function agregarAction() { $this->view->subtitle = $this->info->sitio->usuarios->agregar->titulo; if ($this->_request->isPost()) { Zend_Loader::loadClass('Zend_Filter_StripTags'); $filter = new Zend_Filter_StripTags(); $usuario = trim($filter->filter($this->_request->getPost('usuario'))); $password = trim($filter->filter($this->_request->getPost('password'))); $nombre = trim($filter->filter($this->_request->getPost('nombre'))); $apellido = trim($filter->filter($this->_request->getPost('apellido'))); $mail = trim($filter->filter($this->_request->getPost('mail'))); $estado = trim($filter->filter($this->_request->getPost('estado'))); $creado = date("Y-m-d H:i:s"); if ($usuario != '' && $password != '' && $nombre != '' && $apellido != '' && $mail != '') { $data = array('usuario' => strtolower($usuario), 'password' => md5($password), 'nombre' => $nombre, 'apellido' => $apellido, 'mail' => $mail, 'estado' => $estado, 'creado' => $creado, 'id_sitio' => $this->session->sitio->id); $usuario = new Usuarios(); $usuario->insert($data); $this->_redirect('/admin/usuarios/'); return; } else { $this->view->message = "Deben llenarse todos los campos"; } } $this->view->usuario = new stdClass(); $this->view->usuario->id = null; $this->view->usuario->usuario = ''; $this->view->usuario->password = ''; $this->view->usuario->nombre = ''; $this->view->usuario->apellido = ''; $this->view->usuario->mail = ''; $this->view->usuario->estado = 0; $this->view->action = $this->info->sitio->usuarios->agregar->action; $this->view->buttonText = $this->info->sitio->usuarios->agregar->buttonText; $this->render(); }
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <div class="container"> <?php $usuario = new Usuarios(); if (isset($_POST['cadastrar'])) { $nome = $_POST['nome']; $email = $_POST['email']; $usuario->setNome($nome); $usuario->setEmail($email); # Insert if ($usuario->insert()) { echo "Inserido com sucesso!"; } } ?> <header class="masthead"> <h1 class="muted">PHP OO</h1> <nav class="navbar"> <div class="navbar-inner"> <div class="container"> <ul class="nav"> <li class="active"><a href="index.php">Página inicial</a></li> </ul> </div> </div> </nav>
$result = null; $users = new Usuarios("userFunctions"); $am = new AuthManager("userFunctions"); $operation = http_request("Operation", "s", null); $id = http_request("ID", "i", 0); $user = http_request("Username", "s", null); $pass = http_request("Password", "s", null); $sid = http_request("Session", "i", 0); $sk = http_request("SessionKey", "s", ""); if ($operation === null) { throw new Exception("Call to userFunctions without 'Operation' requested"); } switch ($operation) { case "insert": $am->access(PERMS_ADMIN); $result = $users->insert(); break; case "update": $am->access(PERMS_ADMIN); $result = $users->update($id); break; case "delete": $am->access(PERMS_ADMIN); $result = $users->delete($id); break; case "password": $result = $am->setPassword($id, $pass, $sk); break; // access checks are done inside method // access checks are done inside method case "selectbyid":
<?php require_once 'variaveis.php'; require_once 'core/Usuarios.php'; $user = new Usuarios(); if (isset($_GET['del'])) { $user->setId_usuario($_GET['del']); $user->delete(); } if (isset($_GET['edit'])) { $user->setUsuario($_GET['edit']); $user->update(); } if (isset($_POST['usuario']) and isset($_POST['nome']) and isset($_POST['senha']) and isset($_POST['tipo']) and !isset($_GET['editar'])) { $user->setNome($_POST['nome']); $user->setUsuario($_POST['usuario']); $user->setSenha(md5($_POST['senha'])); $user->setId_tipo($_POST['tipo']); $user->insert(); } $smarty->assign("lista", $user->select()); $smarty->assign("nome", "Usuários"); $smarty->display("usuarios.tpl");