/** * Stores Labs data * * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function store() { $input = Request::all(); $rules = ['name_pt' => 'required', 'name_en' => 'required', 'description_pt' => 'required', 'description_en' => 'required', 'tags' => 'required', 'duration' => 'required', 'target' => 'required', 'subject' => 'required', 'difficulty' => 'required', 'interaction' => 'required', 'thumbnail' => 'required', 'package' => 'required']; $validator = Validator::make($input, $rules); if ($validator->fails() or empty($input['package'])) { // get the error messages from the validator $messages = $validator->messages(); // redirect our user back to the form with the errors from the validator return redirect('labs/create')->withInput()->withErrors($validator); } else { //return var_dump($input); //Image handling $tmp_path = $input['thumbnail']->getRealPath(); $extension = $input['thumbnail']->getClientOriginalExtension(); $path = '/img/exp/' . uniqid() . '.' . $extension; Image::make($tmp_path)->save(base_path() . '/public' . $path); //Image::make($tmp_path)->resize(240, 180)->save(base_path().'/public'.$path); $input['thumbnail'] = $path; //Array $input['target'] = arrayToString($input['target']); $input['subject'] = arrayToString($input['subject']); $input['id'] = getLastLabId(); //Package unzipLab($input['package']->getRealPath(), getLastLabId()); if (array_key_exists("maintenance", $input)) { $input['maintenance'] == 'on' ? $input['maintenance'] = '1' : ($input['maintenance'] = '0'); } else { $input['maintenance'] = '0'; } if (array_key_exists("queue", $input)) { $input['queue'] == 'on' ? $input['queue'] = '1' : ($input['queue'] = '0'); } else { $input['queue'] = '1'; } Labs::create($input); return redirect('labs'); } }
} page_footer(); break; /************************************************************************* * Labs: import * *************************************************************************/ /************************************************************************* * Labs: import * *************************************************************************/ case 'lab_import': ini_set('max_execution_time', '180'); ini_set('memory_limit', '64M'); page_header('Manage'); if (isset($_POST['action']) && $_POST['action'] == 'Import Labs') { // Get last id on labs and configs $lab_offset = getLastLabId(); $cfg_offset = getLastConfigId(); $img_offset = getLastImageId(); try { global $db; $file_tmp = $_POST["file"]; $query = "ATTACH '" . $file_tmp . "' AS import_db;"; $db->query($query); // Importing Labs if (isset($_POST['labs'])) { $db->beginTransaction(); foreach ($_POST['labs'] as $lab) { $query = "INSERT OR REPLACE INTO main.labs (lab_id, lab_name, lab_description, lab_info, lab_netmap, folder_id, lab_diagram, lab_time, lab_points) SELECT lab_id + " . $lab_offset . ", lab_name, lab_description, lab_info, lab_netmap, '" . $_POST['labs_folder'][$lab] . "', lab_diagram, lab_time, lab_points FROM import_db.labs WHERE lab_id='" . $lab . "';"; $db->query($query); $query = "INSERT OR REPLACE INTO main.devices (dev_id, lab_id, dev_name, bin_name, dev_ram, dev_nvram, dev_ethernet, dev_serial, dev_picture, cfg_id, dev_top, dev_left, dev_l2keepalive, dev_watchdog) SELECT dev_id, lab_id + '" . $lab_offset . "', dev_name, bin_name, dev_ram, dev_nvram, dev_ethernet, dev_serial, dev_picture, cfg_id + '" . $cfg_offset . "', dev_top, dev_left, dev_l2keepalive, dev_watchdog FROM import_db.devices WHERE lab_id='" . $lab . "';"; $db->query($query);