public function submit_upload_file() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["permisos"] = Session::get('permisos'); if (in_array('side_nuevo_evento', $data["permisos"])) { // Validate the info, create rules for the inputs $attributes = array('archivo' => 'Documento'); $messages = array(); $rules = array('archivo' => 'required|max:15360|mimes:pdf,doc,docx,xls,xlsx,ppt,pptx'); // Run the validation rules on the inputs from the form $validator = Validator::make(Input::all(), $rules, $messages, $attributes); // If the validator fails, redirect back to the form $ideventos = Input::get('ideventos'); if ($validator->fails()) { return Redirect::to('eventos/upload_file/' . $ideventos)->withErrors($validator)->withInput(Input::all()); } else { if (Input::hasFile('archivo')) { $archivo = Input::file('archivo'); $rutaDestino = 'files/eventos/'; $nombreArchivo = $archivo->getClientOriginalName(); $nombreArchivoEncriptado = Str::random(27) . '.' . pathinfo($nombreArchivo, PATHINFO_EXTENSION); $peso = $archivo->getSize(); $uploadSuccess = $archivo->move($rutaDestino, $nombreArchivoEncriptado); /* Creo el documento */ $documento = new Documento(); $documento->titulo = $nombreArchivo; $documento->idtipo_documentos = 1; // ¡Que viva el hardcode! $documento->nombre_archivo = $nombreArchivoEncriptado; $documento->ruta = $rutaDestino; $documento->peso = $peso; $documento->save(); /* Creo la relación de evento con documento */ $documentos_evento = new DocumentosEvento(); $documentos_evento->ideventos = $ideventos; $documentos_evento->iddocumentos = $documento->iddocumentos; $documentos_evento->save(); /* Envio las notificaciones via e-mail a los voluntarios */ $evento = Evento::find($ideventos); $emails_voluntarios = Asistencia::getUsersPorEvento($evento->ideventos)->get(); $emails = array(); foreach ($emails_voluntarios as $email_voluntario) { $emails[] = $email_voluntario->email; } Mail::send('emails.eventDocumento', array('evento' => $evento, 'documento' => $documento), function ($message) use($emails, $evento) { $message->to($emails)->subject('Se subió un nuevo documento de AFI Perú.'); }); //Enviar las push notifications a los voluntarios $voluntarios = Asistencia::getUserPushInfoByEvento($evento->ideventos)->get(); foreach ($voluntarios as $voluntario) { if ($voluntario->push_documents && $voluntario->uuid) { $message = 'Se subió un nuevo documento de AFI Perú.'; Helpers::pushAPNS($voluntario->uuid, $message, 3); } } // Enviar las push notifications (android) a los voluntarios $gcm_tokens = Asistencia::getUsersToNotificateDocumentUploaded($ideventos)->get()->lists('gcm_token'); $title = 'AFI Perú - Nuevo documento'; $message = 'Se subió un nuevo documento de AFI Perú: ' . $documento->titulo; $type = 3; $m = ['title' => $title, 'message' => $message, 'type' => $type]; Helpers::pushGCM($gcm_tokens, $m); // Llamo a la función para registrar el log de auditoria $descripcion_log = "Se subió el documento con id {{$documento->iddocumentos}}"; Helpers::registrarLog(7, $descripcion_log); } Session::flash('message', 'Se subió correctamente el archivo.'); return Redirect::to('eventos/upload_file/' . $ideventos); } } else { // Llamo a la función para registrar el log de auditoria $descripcion_log = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registrarLog(10, $descripcion_log); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }