/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Montaje();
     $tra_montaje = new TraMontaje();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Montaje'])) {
         $model->attributes = $_POST['Montaje'];
         $model->imagen = "0";
         //echo count($_FILES['imagen']['name']);
         if ($model->validate() and count($_FILES['imagen']['name']) >= 1) {
             $idexpo = $model->idexposicion;
             $idiomaid = $model->idiomaid;
             $directorio = 'images/montaje/originals/';
             $porciones = explode("<br>", $model->descripcion);
             $porciones_tra = explode("<br>", $model->text_language);
             $i = 0;
             while ($i < count($_FILES['imagen']['name'])) {
                 if ($i != 0) {
                     $model = new Montaje();
                     $tra_montaje = new TraMontaje();
                 }
                 $model->idiomaid = $idiomaid;
                 // solo para que no valide al momento de insertar en el for.
                 $model->text_language = "auxiliar";
                 $nombre = $this->NewGuid();
                 if ($_FILES['imagen']['type'][$i] == "image/jpeg") {
                     $tipo = "jpg";
                 } else {
                     $tipo = "png";
                 }
                 $destino = $directorio . $nombre . '.' . $tipo;
                 $model->imagen = $nombre . '.' . $tipo;
                 $model->idexposicion = $idexpo;
                 move_uploaded_file($_FILES['imagen']['tmp_name'][$i], $destino);
                 !empty($porciones[$i]) ? $model->descripcion = $porciones[$i] : ($model->descripcion = "");
                 $model->save();
                 $tra_montaje->idiomaid = $idiomaid;
                 $tra_montaje->montajeid = $model->idmontaje;
                 !empty($porciones_tra[$i]) ? $tra_montaje->descripcion = $porciones_tra[$i] : ($tra_montaje->descripcion = "");
                 $tra_montaje->save();
                 $i++;
             }
             $this->redirect(array('admin'));
         }
     }
     $this->render('create', array('model' => $model));
 }