示例#1
0
 public function registrar()
 {
     $this->pagina = 'registrar profesor';
     $this->titulo = 'Registrar profesor';
     $this->estilo = array('formulario', 'backend', 'jquery-te-1.3.3');
     $this->javascript = array('jquery-te-1.3.3.min', 'editor');
     $this->menu = 'menu_profesor';
     $this->form_validation->set_error_delimiters('<div class="text-error">', '</div>');
     $datos['backend'] = TRUE;
     $asignaturas = Asignatura_model::obtener('Nombre', 'asc');
     $datos['check'] = array();
     foreach ($asignaturas as $asignatura) {
         $aux = array();
         $aux = array('name' => "asignatura[{$asignatura->Codigo}]", 'id' => $asignatura->Nombre, 'value' => 'accept', 'checked' => FALSE);
         array_push($datos['check'], $aux);
     }
     $datos['formulario'] = array('nombre' => array('label' => array('accesskey' => 'M', 'name' => 'No<u>m</u>bre'), 'input' => array('class' => 'nombre', 'name' => 'nombre', 'id' => 'nombre', 'maxlength' => '30', 'size' => '35', 'autofocus' => 'autofocus', 'value' => $this->input->post('nombre')), 'requerido' => TRUE), 'apellido1' => array('label' => array('accesskey' => 'L', 'name' => 'Primer ape<u>l</u>lido'), 'input' => array('class' => 'apellidoP', 'name' => 'apellido1', 'id' => 'primerApellido', 'maxlength' => '60', 'size' => '35', 'value' => $this->input->post('apellido1')), 'requerido' => TRUE), 'apellido2' => array('label' => array('accesskey' => 'G', 'name' => 'Se<u>g</u>undo apellido'), 'input' => array('class' => 'apellidoM', 'name' => 'apellido2', 'id' => 'segundoApellido', 'maxlength' => '60', 'size' => '35', 'value' => $this->input->post('apellido2')), 'requerido' => TRUE), 'fechaNacimiento' => array('label' => array('accesskey' => 'A', 'name' => 'Fech<u>a</u> de nacimiento'), 'input' => array('class' => 'fechaN', 'name' => 'fechaNacimiento', 'id' => 'fNacimiento', 'maxlength' => '10', 'size' => '15', 'placeholder' => 'mm-dd-aaaa', 'value' => $this->input->post('fechaNacimiento')), 'requerido' => TRUE), 'email' => array('label' => array('accesskey' => 'E', 'name' => '<u>E</u>mail'), 'input' => array('class' => 'email', 'name' => 'email', 'id' => 'email', 'maxlength' => '50', 'size' => '35', 'value' => $this->input->post('email')), 'requerido' => TRUE), 'dni' => array('label' => array('accesskey' => 'D', 'name' => '<u>D</u>NI'), 'input' => array('class' => 'dni', 'name' => 'dni', 'id' => 'dni', 'maxlength' => '9', 'size' => '9', 'value' => $this->input->post('dni')), 'requerido' => TRUE), 'telefono' => array('label' => array('accesskey' => 'T', 'name' => '<u>T</u>eléfono'), 'input' => array('class' => 'telefono', 'name' => 'telefono', 'id' => 'telefono', 'maxlength' => '9', 'size' => '9', 'value' => $this->input->post('telefono')), 'requerido' => TRUE), 'ncc' => array('label' => array('accesskey' => 'N', 'name' => '<u>N</u>CC'), 'input' => array('class' => 'ncc', 'name' => 'ncc', 'id' => 'ncc', 'maxlength' => '24', 'size' => '35', 'value' => $this->input->post('ncc')), 'requerido' => TRUE), 'password' => array('label' => array('accesskey' => 'D', 'name' => 'Passwor<u>d</u>'), 'input' => array('class' => 'password', 'name' => 'pass', 'id' => 'pass', 'maxlength' => '20', 'size' => '15', 'autocomplete' => 'off'), 'requerido' => TRUE), 'passconf' => array('label' => array('accesskey' => 'F', 'name' => 'Con<u>f</u>irme el password'), 'input' => array('class' => 'passconf', 'name' => 'passconf', 'id' => 'passconf', 'maxlength' => '20', 'size' => '15', 'autocomplete' => 'off'), 'requerido' => TRUE), 'asignaturas' => array('label' => array('accesskey' => 'I', 'name' => '<u>I</u>mparte'), 'input' => array('class' => 'asig', 'name' => 'asignaturas', 'id' => 'asig'), 'requerido' => FALSE), 'texto' => array('label' => array('accesskey' => 'X', 'name' => 'Te<u>x</u>to'), 'input' => array('class' => 'editor', 'name' => 'texto', 'id' => 'texto', 'type' => 'text', 'value' => $this->input->post('texto')), 'requerido' => TRUE));
     $datos['boton'] = array('name' => 'button', 'id' => 'boton_registro', 'value' => 'Enviar', 'class' => 'btn btn-primary');
     $datos['imagen'] = '';
     if ($this->_validarRegistro()) {
         $profesor = new Profesor_model();
         $codigoImagen = '';
         $imagen = new Imagen_model();
         if (isset($_FILES['archivo']) && $_FILES['archivo']['error'] == 0) {
             if ($imagen->inicializar()) {
                 $codigoImagen = $imagen->codigo();
             }
         }
         if ($profesor->inicializar($codigoImagen)) {
             $codigoProfesor = $profesor->codigo($this->input->post('email'));
             foreach ($this->input->post('asignatura') as $key => $asig) {
                 $profesor->imparte($codigoProfesor, $key);
                 $asignaturas = Asignatura_model::obtener('Nombre', 'asc');
                 $datos['check'] = array();
                 foreach ($asignaturas as $asignatura) {
                     $aux = array();
                     $check = FALSE;
                     if ($asignatura->Codigo == $key) {
                         $check = TRUE;
                     }
                     $aux = array('name' => "asignatura[{$asignatura->Codigo}]", 'id' => $asignatura->Nombre, 'value' => 'accept', 'checked' => $check);
                     array_push($datos['check'], $aux);
                 }
             }
             $datos['mensaje'] = 'Los datos del profesor se han registrado satisfactoriamente';
         } else {
             $datos['error'] = 'No se ha podido registrar el profesor';
         }
     }
     $this->mostrar($datos);
 }