function postUpload(Request $request) { $file = $request->file('file'); $input = $request->all(); $validator = Validator::make(['file' => $file, 'extension' => strtolower($file ? $file->getClientOriginalExtension() : 'sss')], ['file' => 'required', 'extension' => 'required|in:csv']); if ($validator->fails()) { return Redirect::action('MenusController@index')->withErrors($validator); } $data = []; if (Input::hasFile('file')) { if (array_key_exists('file', $input)) { if ($input['file']->isValid()) { $filename = 'aloha_' . date('Y_m_d_His') . '.' . $input['file']->getClientOriginalExtension(); $path = storage_path() . '/upload'; $input['file']->move($path, $filename); $file = Files::create(['filename' => $filename]); $data = $this->_import_csv($path, $file->filename); } } } return $data; }
/** * Update the specified resource in storage. * * @param Request $request * @return Redirect */ public function update($id, Request $request) { $item = Purchases::findOrFail($id); $input = $request->all(); if (array_key_exists('status', $input)) { $input['status'] = 1; $input['date_paid'] = date('Y-m-d H:i:s', time()); } else { $input['status'] = 0; } if ($input['category_id'] == 0) { $input['category_id'] = null; } if (array_key_exists('file', $input)) { if ($input['file']->isValid()) { $filename = 'invoice_' . date('Y_m_d_His') . '.' . $input['file']->getClientOriginalExtension(); $input['file']->move(storage_path() . '/upload', $filename); $file = Files::create(['filename' => $filename]); $input['invoice_id'] = $file->id; } } $currentPeriodId = array_key_exists('stock_period_id', $input) ? $input['stock_period_id'] : Helper::currentPeriodId(); $input['stock_period_id'] = $currentPeriodId; $item->update($input); $item->save(); Helper::add(DB::getPdo()->lastInsertId(), 'updated invoice ID ' . DB::getPdo()->lastInsertId()); return Redirect::action('ItemPurchasesController@index', $item->id); }
public function pages() { $id = $this->request->data['volume_number']; $volume_number = $id; $url = CWMG_VOLUMES_PATH . "\\v" . str_pad($id, 3, "0", STR_PAD_LEFT) . "-" . $this->roman($id) . "\\TXT"; $count = Pages::count(array('volume_number' => $id)); $numeric_vol = str_pad($id, 3, '0', STR_PAD_LEFT); $roman_vol = $this->roman($id); if ($count == 0) { $sortorder = 0; if (!empty($id)) { if ($handle = opendir($url)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { if (stristr($entry, "-B-")) { $is_roman = "1"; } else { $is_roman = "0"; } $page = str_replace(".txt", "", $entry); $page = str_replace("v" . $numeric_vol . "-" . $roman_vol, "", $page); $page = str_replace("-A-", "", $page); $page = str_replace("-B-", "", $page); $page = str_replace("-C-", "", $page); $page = str_replace("-D-", "", $page); $filename = str_replace(".txt", "", $entry); // echo "$page\n"; $contents = file_get_contents($url . "\\" . $entry); $data = array('volume_number' => $id, 'type.id' => '', 'type.no' => null, 'type.name' => null, 'description' => $this->clean_hex(str_replace('\\•', '', strip_tags($contents, '<p><i><ol><li><ul>'))), 'page_no' => $page, 'is_roman' => $is_roman, 'sort_order' => $sortorder + 1, 'filename' => $filename, 'updated' => "Y", 'updated_date' => gmdate('Y-m-d'), 'ip' => $_SERVER['REMOTE_ADDR']); $new_page = Pages::create($data)->save(); $newid = $pages->_id; // Import the file in fs.files $pdfurl = CWMG_VOLUMES_PATH . "\\v" . str_pad($id, 3, "0", STR_PAD_LEFT) . "-" . $this->roman($id) . "\\PDF\\"; $pdffilename = $filename . ".pdf"; $cmd = '"E:\\MongoDB\\bin\\Mongofiles.exe" -d CWMG put ' . $pdfurl . $pdffilename; // exec($cmd); // rename the file in fs.files $file = Files::create(); $data = array('filename' => $filename . ".pdf"); $dataFS = Files::find('all', array('conditions' => array('filename' => $pdfurl . $pdffilename)))->save($data); $sortorder++; } } } closedir($handle); } } else { $sortorder = 0; if ($handle = opendir($url)) { while (false !== ($entry = readdir($handle))) { $sortorder++; if ($entry != "." && $entry != "..") { if (stristr($entry, "-B-")) { $is_roman = "1"; } else { $is_roman = "0"; } $page = str_replace(".txt", "", $entry); $page = str_replace("v" . $numeric_vol . "-" . $roman_vol, "", $page); $page = str_replace("-A-", "", $page); $page = str_replace("-B-", "", $page); $page = str_replace("-C-", "", $page); $page = str_replace("-D-", "", $page); $filename = str_replace(".txt", "", $entry); $contents = file_get_contents($url . "\\" . $entry); $conditions = array('filename' => $filename); $page_id = Pages::find(array('fields' => '_id'), array('conditions' => array('filename' => $filename))); $data = array('description' => $this->clean_hex(str_replace('\\•', '', strip_tags($contents, '<p><i><ol><li><ul>'))), 'ip' => $_SERVER['REMOTE_ADDR']); $conditions = array('_id' => $page_id['_id']); // $new_page = Pages::update($data, $conditions); Pages::find(array('fields' => '_id'), array('conditions' => array('filename' => $filename)))->save($data); // print_r("volume_number"); } } closedir($handle); } } $count = Pages::count(array('conditions' => array('volume_number' => $id, 'type.id' => ''))); return compact('count', 'numeric_vol', 'roman_vol', 'volume_number'); }