/** * Execute the console command. * * @return mixed */ public function handle() { $_key = $this->argument('key'); $_blueprint = $this->argument('blueprint'); $_file = $this->argument('file'); $_creator = $this->argument('creator'); $_header = escapeshellarg($this->argument('header')); $blueprint = Blueprint::find($_blueprint); if (!$blueprint) { Log::error("la encuesta con id: {$_blueprint} no se encontró"); return; } $blueprint->sending_emails = 1; $blueprint->update(); $counter = 0; Excel::load("storage/app/" . $_key . ".xlsx", function ($reader) use($blueprint, $counter, $_key, $_header) { $reader->each(function ($row) use($blueprint, $counter, $_key, $_header) { if (trim($row->correo) != "" && filter_var($row->correo, FILTER_VALIDATE_EMAIL)) { $form_key = str_replace("/", "", Hash::make('blueprint' . $blueprint->id . $row->correo)); $applicant = Applicant::firstOrCreate(["blueprint_id" => $blueprint->id, "form_key" => $form_key, "user_email" => $row->correo, "temporal_key" => $_key]); $path = base_path(); exec("php {$path}/artisan email:send {$applicant->id} {$_header} > /dev/null &"); $update = $blueprint->emails + 1; $blueprint->emails = $update; $blueprint->update(); } }); })->first(); $total = Applicant::where("temporal_key", $_key)->count(); $mailgun = new MailgunEmail(["blueprint" => $blueprint->id, "emails" => $total]); $mailgun->save(); $blueprint->sending_emails = 0; $blueprint->update(); }
public function saveAnswer(Request $request) { if ($request->input('is_test') != 1) { $applicant = Applicant::where('form_key', $request->input('form_key'))->first(); $blueprint = Blueprint::find($applicant->blueprint_id); $question = Question::find($request->input('question_id')); $answer = Answer::firstOrCreate(["blueprint_id" => $blueprint->id, "question_id" => $question->id, "form_key" => $applicant->form_key]); if ($question->type == "integer" || $question->type == "number") { $answer->num_value = $request->input('question_value'); $answer->text_value = null; } else { $answer->num_value = null; $answer->text_value = $request->input('question_value'); } $answer->update(); $answer->question_value = $request->input('question_value'); $answer->new_token = csrf_token(); } else { $question = Question::find($request->input('question_id')); $answer = new Answer(["blueprint_id" => $question->blueprint->id, "question_id" => $question->id, "form_key" => "xxx"]); $answer->num_value = $question->type == "number" ? $request->input('question_value') : null; $answer->text_value = $question->type != "number" ? $request->input('question_value') : null; $answer->question = $question; //$answer->update(); $answer->question_value = $request->input('question_value'); $answer->new_token = csrf_token(); } return response()->json($answer)->header('Access-Control-Allow-Origin', '*'); }
public function saveRule(Request $request) { // [1] CHECK IF THE BLUEPRINT EXIST AND THE USER CAN CHANGE IT $user = Auth::user(); $blueprint = Blueprint::find($request->input('blueprint_id')); if (!$blueprint) { if ($user->level == 3) { abort(404, 'El formulario no existe!'); } else { abort(403, 'El formulario no pertenece al usuario'); } } // [2] CREATE THE RULE OBJECT $rule = new Rule(); $rule->blueprint_id = $blueprint->id; $rule->section_id = (int) $request->input("section_id"); $rule->question_id = (int) $request->input("question_id"); $rule->value = $request->input("value"); $rule->save(); // [4] GENERATE A NEW TOKEN TO PREVENT TOKEN MISSMATCH $rule->new_token = csrf_token(); // [5] RETURN THE JSON return response()->json($rule)->header('Access-Control-Allow-Origin', '*'); }
public function getFullXLSX($id) { $user = Auth::user(); if ($user->level > 2) { $blueprint = Blueprint::find($id); } else { $blueprint = $user->blueprints()->find($id); } if ($blueprint) { //return response()->file(storage_path('app') . "/" . $blueprint->csv_file . ".xlsx"); $file = storage_path('app') . "/" . $blueprint->csv_file . ".xlsx"; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($file) . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } else { return redirect("dashboard/encuestas"); } }