Example #1
0
 function registrar()
 {
     $email = strtolower(trim($_POST['email']));
     $passw = trim($_POST['password']);
     $pass2 = trim($_POST['password2']);
     $nombr = trim($_POST['nombres']);
     $apell = trim($_POST['apellidos']);
     $websi = trim($_POST['website']);
     $sexo = trim($_POST['sexo']);
     $_SESSION['email'] = $email;
     $_SESSION['nombres'] = $nombr;
     $_SESSION['apellidos'] = $apell;
     $_SESSION['website'] = $websi;
     if (!$email) {
         $this->reportarVacio($email, 'Correo Electrónico', 'nuevo-registro', 'm');
     }
     if (!$passw) {
         $this->reportarVacio($passw, 'Contraseña', 'nuevo-registro', 'f');
     }
     if (!$nombr) {
         $this->reportarVacio($nombr, 'Nombre', 'nuevo-registro', 'm');
     }
     if (!$apell) {
         $this->reportarVacio($apell, 'Apellido', 'nuevo-registro', 'm');
     }
     $query = "SELECT * FROM `aRecurso_usuarios` WHERE `email`='{$email}'";
     $res = mysql_query($query);
     $n = mysql_num_rows($res);
     if ($n > 0) {
         $_SESSION['mensajeError'] = "Ya existe un usuario registrado con la dirección {$email}.";
         header("Location: ?p=nuevo-registro");
         exit;
     }
     if ($passw != $pass2) {
         $_SESSION['mensajeError'] = "Las contraseñas no coinciden.";
         header("Location: ?p=nuevo-registro");
         exit;
     }
     $passw = crypt($passw, 'crp');
     $query = "INSERT INTO `aRecurso_usuarios` (`nombres`, `apellidos`, `email`, `password`, `website`, `id_perfil`, `sexo`, `fecha_registro`) VALUES('{$nombr}', '{$apell}', '{$email}', '{$passw}', '{$websi}', '0','{$sexo}', NOW())";
     $res = mysql_query($query);
     $id = mysql_insert_id();
     //************
     if ($_POST['etiquetas'] != "") {
         $arreglo = explode(',', $_POST['etiquetas']);
         for ($j = 0; $j < count($arreglo); $j++) {
             if (formatoTag($arreglo[$j]) != "") {
                 //buscar si la etiqueta ya existe
                 $query = "SELECT `id` FROM `kControl_etiquetas` WHERE `nombre` LIKE '" . formatoTag($arreglo[$j]) . "' LIMIT 1";
                 $res = mysql_query($query);
                 echo mysql_error();
                 $r = mysql_fetch_array($res);
                 $n = mysql_num_rows($res);
                 $id_tag = $r['id'];
                 //si no existe, guardarla en kControl_etiquetas y tomar el id
                 if ($n == 0) {
                     $query = "INSERT INTO `kControl_etiquetas` (`nombre`) VALUES('" . formatoTag($arreglo[$j]) . "')";
                     $res = mysql_query($query);
                     echo mysql_error();
                     $id_tag = mysql_insert_id();
                 }
                 //verificar que no se dupliquen las etiquetas en el diccionario
                 $query = "SELECT * FROM `kControl_diccionario_etiquetas_usuarios` WHERE `id_etiqueta` LIKE '" . $id_tag . "' AND `id_usuario` LIKE '" . $id . "' LIMIT 1";
                 $res = mysql_query($query);
                 echo mysql_error();
                 $r = mysql_fetch_array($res);
                 $n = mysql_num_rows($res);
                 //si no hay etiquetas duplicadas, entonces incrementamos las etiquetas del grupo de trabajo
                 if ($n == 0) {
                     //guardar los datos en el diccionario de etiquetas
                     $query = "INSERT INTO `kControl_diccionario_etiquetas_usuarios` (`id_usuario`,`id_etiqueta`) VALUES('" . $id . "','" . $id_tag . "')";
                     $res = mysql_query($query);
                     echo mysql_error();
                 }
             }
             //termina validación if tag = nil
         }
     }
     //************
     //----------
     if (!mysql_error()) {
         $_SESSION['mensaje'] = "La cuenta ha sido creada exitosamente. Podr&aacute; iniciar sesi&oacute;n cuando un usuario autorice su ingreso.";
         $_SESSION['mensajeError'] = "";
         rss::newUserMAILTO($email, "Registro de usuario", 1);
     }
     setcookie('auto-CICESERep', '');
     header("Location: ?p=iniciar-sesion");
     exit;
 }