Ejemplo n.º 1
0
 public function insertar1()
 {
     session_start();
     if (isset($_SESSION['user_id'])) {
     } else {
         header('Location:  index.php?ctl=login');
     }
     if ($_SESSION['user_id'] == 2 || $_SESSION['user_id'] == 3 || $_SESSION['user_id'] == 5) {
         $m = new EmpleadosModel(Config::$mvc_bd_nombre, Config::$mvc_bd_usuario, Config::$mvc_bd_clave, Config::$mvc_bd_hostname);
         $params = array('nombre' => '', 'apellido_p' => '', 'apellido_m' => '', 'proyectos' => $m->dameProyectos(), 'sexo' => '', 'estado_civil' => '', 'nacionalidad' => '', 'curp' => '', 'rfc' => '', 'f_nacimiento' => '', 'l_nacimiento' => '', 'correo_personal' => '', 'cel_personal' => '', 'tel_personal' => '', 'dir_calle' => '', 'dir_colonia' => '', 'dir_cp' => '', 'dir_municipio' => '', 'dir_entidad' => '', 'pais' => '', 'razon_social_id' => '', 'area_id' => '', 'departamento_id' => '', 'puesto' => '', 'estudios' => '', 'exp_prof' => '', 'su_aut' => '', 'sd' => '', 'su_neg' => '', 'su_sem' => '', 'su_sem_fiscal' => '', 'su_sem_efectivo' => '', 'imss_num' => '', 'imss_desc' => '', 'infonavit' => '', 'isr_desc' => '', 'fecha_ingreso' => '', 'num_cta_ban' => '', 'cta_ban_clabe' => '', 'cta_ban_id' => '', 'no_banco' => '', 'bono' => '');
         $m = new EmpleadosModel(Config::$mvc_bd_nombre, Config::$mvc_bd_usuario, Config::$mvc_bd_clave, Config::$mvc_bd_hostname);
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $target_dir = "./web/uploads/";
             //<--directorio destino
             $target_file = $target_dir . $m->generateRandomString(2) . basename($_FILES["fileToUpload"]["name"]);
             $uploadOk = 1;
             $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
             // Check if image file is a actual image or fake image
             if (isset($_POST["submit"])) {
                 $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
                 if ($check !== false) {
                     //    echo "File is an image - " . $check["mime"] . ".";
                     //    $uploadOk = 1;
                 } else {
                     //    echo "File is not an image.";
                     //    $uploadOk = 0;
                 }
             }
             // Check if file already exists
             if (file_exists($target_file)) {
                 // echo "Sorry, file already exists.";
                 // $uploadOk = 0;
             }
             /*
             // Check file size
             if ($_FILES["fileToUpload"]["size"] > 500000) {
                 echo "Sorry, your file is too large.";
                 $uploadOk = 0;
             }
             */
             // Allow certain file formats
             if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
                 // echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
                 //$uploadOk = 0;
             }
             // Check if $uploadOk is set to 0 by an error
             if ($uploadOk == 0) {
                 //  echo "Sorry, your file was not uploaded.";
                 // if everything is ok, try to upload file
             } else {
                 if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
                     // echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
                 } else {
                     // echo "Sorry, there was an error uploading your file.";
                 }
             }
             // comprobar campos formulario
             $empleado_new = $_POST;
             $empleado_new['foto'] = $target_file;
             if ($m->validarDatos1($empleado_new)) {
                 //usamos metodo del modelo*/
                 $id = $m->insertarEmpleado($empleado_new);
                 $m->postinsertEmpleado($empleado_new, $id);
                 //echo $id;
                 header('Location:  index.php?ctl=activos');
                 //redirect
             } else {
                 $params = array('nombre' => $_POST['nombre'], 'apellido_p' => $_POST['apellido_p'], 'apellido_m' => $_POST['apellido_m'], 'sexo' => $_POST['sexo'], 'proyectos' => $m->dameProyectos(), 'estado_civil' => $_POST['estado_civil'], 'nacionalidad' => $_POST['nacionalidad'], 'curp' => $_POST['curp'], 'rfc' => $_POST['rfc'], 'f_nacimiento' => $_POST['f_nacimiento'], 'l_nacimiento' => $_POST['l_nacimiento'], 'correo_personal' => $_POST['correo_personal'], 'cel_personal' => $_POST['cel_personal'], 'tel_personal' => $_POST['tel_personal'], 'dir_calle' => $_POST['dir_calle'], 'dir_colonia' => $_POST['dir_colonia'], 'dir_cp' => $_POST['dir_cp'], 'dir_municipio' => $_POST['dir_municipio'], 'dir_entidad' => $_POST['dir_entidad'], 'pais' => $_POST['pais'], 'razon_social_id' => $_POST['razon_social_id'], 'area_id' => $_POST['area_id'], 'departamento_id' => $_POST['departamento_id'], 'puesto' => $_POST['puesto'], 'estudios' => $_POST['estudios'], 'exp_prof' => $_POST['exp_prof'], 'su_aut' => $_POST['su_aut'], 'sd' => $_POST['sd'], 'su_neg' => $_POST['su_neg'], 'su_sem' => $_POST['su_sem'], 'su_sem_fiscal' => $_POST['su_sem_fiscal'], 'su_sem_efectivo' => $_POST['su_sem_efectivo'], 'imss_num' => $_POST['imss_num'], 'imss_desc' => $_POST['imss_desc'], 'infonavit' => $_POST['infonavit'], 'bono' => $_POST['bono'], 'fecha_ingreso' => $_POST['fecha_ingreso'], 'num_cta_ban' => $_POST['num_cta_ban'], 'cta_ban_clabe' => $_POST['cta_ban_clabe'], 'cta_ban_id' => $_POST['cta_ban_id'], 'no_banco' => $_POST['no_banco'], 'mensaje' => 'No se ha podido insertar el Empleado. Revisa el formulario');
                 //$params['mensaje'] = 'No se ha podido insertar el Empleado. Revisa el formulario';
             }
         }
         require __DIR__ . '/templates/Empleado/formInsertar.php';
     } else {
         header('Location:  index.php?ctl=listar');
     }
 }