public function getDatabaseName() { $data = Farmbook::where('id', '=', $this->farmbook)->first(); if (is_null($data)) { $data = "No database"; } else { $data = $data->name; } return $data; }
/** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { $username = Auth::user()->name; $user = User::where('name', '=', $username)->first(); $user_farmbooks = $user->farmbooks()->get(); $user_farmbooks = array_pluck($user_farmbooks, 'id'); // dd($user_farmbooks,$array); $farmbooks = Farmbook::lists('name', 'id'); // $p->farmbooks()->attach([1,2]); // dd($user,$p); //$user_farmbooks = [1,2]; return view('settings', compact('user', 'farmbooks', 'user_farmbooks')); }
/** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function store(Request $request, $id) { // current timestamp $now = Carbon\Carbon::now('Africa/Cairo')->toDateTimeString(); // get inpute $id = $request->input('id'); $name = $request->input('name'); $database = $request->input('database'); $suburbs = $request->input('suburbs'); //dd($suburbs); //$type = $request->input('type'); Farmbook::where('id', $id)->update(array('name' => $name, 'database' => $database, 'updated_at' => $now)); $farmbook = Farmbook::where('id', '=', $id)->first(); // store the deed suburbs $farmbook->suburbs()->sync($suburbs); // dd("user controller Store ",$id,,$farmbooks); Session::flash('flash_message', 'Updated ' . $name . ' at ' . $now); Session::flash('flash_type', 'alert-success'); return Redirect::back(); }
public function createdatabase(Request $request) { $file = storage_path() . '/databases/dummy_database.sql'; $file2 = storage_path() . '/databases/dummy_database.sql'; // check if the file exists if (file_exists($file)) { $sqldump = file_get_contents($file); } else { $file = "not found"; $message = 'missing dummy_database'; Session::flash('flash_message', $message); Session::flash('flash_type', 'alert-danger'); return Redirect::back()->with('flash_message', $message); } $database = $request->input('database'); $type = $request->input('type'); $database = $database . '_' . $type . '_farmbook2'; //dd($database); $servername = config('database.connections.mysql.host'); $username = config('database.connections.mysql.username'); $password = config('database.connections.mysql.password'); // dd('make database',$database); $dbname = 'tmp'; // connect to tmp database $otf = new \App\Database\OTF(['database' => $dbname]); $db = DB::connection($dbname); $sql = "CREATE DATABASE " . $database; //set created to false $created = false; try { // created database successfully $db->getpdo()->exec($sql); $created = true; } catch (Exception $ex) { // dd( $ex->getMessage()); // error creating database $message = $ex->getMessage(); } // database created success if ($created == true) { $Farmbook = Farmbook::where('database', '=', $database); $normal_name = str_replace('_', ' ', $database); $normal_name = str_replace('farmbook2', ' ', $normal_name); if ($Farmbook->count() > 0) { $Farmbook = Farmbook::where('database', '=', $database)->update(['database' => $database]); } else { // add to farmbooks $Farmbook = new Farmbook(); $Farmbook->name = $normal_name; $Farmbook->database = $database; $Farmbook->type = 0; $Farmbook->save(); } // connect to the new database $otf = new \App\Database\OTF(['database' => $database]); $db = DB::connection($database); // creates tables with dummy $db->getpdo()->exec($sqldump); $message = $database . ' created successfully.'; Session::flash('flash_message', $message); Session::flash('flash_type', 'alert-success'); } else { Session::flash('flash_message', $message); Session::flash('flash_type', 'alert-danger'); } return Redirect::back()->with('flash_message', $message); }
public function adduser() { $farmbooks = Farmbook::orderBy('name')->lists('name', 'id'); return view('auth.adduser', compact('farmbooks')); }
public function globContacts(Request $request) { $start = \Carbon\Carbon::now('Africa/Johannesburg'); echo 'Start : ' . $start . '<br>'; // get all farmbook databases $farmbooks = Farmbook::orderBy('name')->get(); $email = Auth::user()->email; //log $action = 'GLOBAL UPDATE'; $comment = 'Contacts'; $append = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString() . ', ' . trim($email) . ', ' . $action . ',' . $comment; Storage::append('logfile.txt', $append); // loop through databases for ($x = 0; $x < $farmbooks->count(); $x++) { $error = 0; $database = $farmbooks[$x]->database; try { //change database $own = new Owner(); $own->changeConnection($database); // fetch records with missing info for te numbers and email $owners = Owner::on($database)->select('*')->where('strHomePhoneNo', '')->orWhere('strWorkPhoneNo', '')->orWhere('strCellPhoneNo', '')->orWhere('EMAIL', '')->get(); $noinfoowners = Owner::on($database)->select('*')->where('strHomePhoneNo', '')->Where('strWorkPhoneNo', '')->Where('strCellPhoneNo', '')->Where('EMAIL', '')->get(); $allowners = Owner::on($database)->select('*')->get(); //dd($owners); } catch (Exception $ex) { // echo "<br> ------------------------------------------------------------------" . "<br>"; // echo $x . ". " . $farmbooks[$x]->database . " <br>"; // echo " ** PROBLEM ** " . $ex->getMessage() . "<br>"; // echo " ------------------------------------------------------------------" . "<br>"; $error = 1; //dd(); } //dd($prop); if ($error == 0) { // check it has the farmbook2 ext $found = strpos($database, 'farmbook2'); // echo "<br> ------------------------------------------------------------------" . "<br>"; // if ($found == 0) { // echo "** ALERT ** Database has not got correct naming convention - farmbook2" . " <br>"; // } echo "<br> ------------------------------------------------------------------" . "<br>"; echo $x . ". Farmbook : " . $database . "<br><br>"; echo 'Local Owners : ' . $allowners->count() . "<br>"; echo 'Missing some info : ' . $owners->count() . "<br>"; echo 'Missing all info : ' . $noinfoowners->count() . "<br>"; if ($owners->count() > 0) { // echo " ------------------------------------------------------------------" . "<br>"; // $users = $farmbooks[$x]->users; $new = 0; $canupdate = 0; $can = 0; $canupdateRow = 0; $strHomePhoneNo = 0; $strWorkPhoneNo = 0; $strCellPhoneNo = 0; $EMAIL = 0; foreach ($owners as $owner) { //[0] echo " - " . $owner->NAME . " | " . $owner->strHomePhoneNo . " | " . $owner->strWorkPhoneNo . " | " . $owner->strCellPhoneNo . " | " . $owner->EMAIL . " | " . " <br>"; $found = Contact::select('*')->where('strIDNumber', $owner->strIDNumber)->get(); if ($found->count() > 0) { $new++; $can = 0; if ($owner->strHomePhoneNo == "" && $found[0]->strHomePhoneNo != "") { $canupdate++; $can++; $strHomePhoneNo++; $owner->strHomePhoneNo = $found[0]->strHomePhoneNo; } if ($owner->strWorkPhoneNo == "" && $found[0]->strWorkPhoneNo != "") { $canupdate++; $can++; $strWorkPhoneNo++; $owner->strWorkPhoneNo = $found[0]->strWorkPhoneNo; } if ($owner->strCellPhoneNo == "" && $found[0]->strCellPhoneNo != "") { $canupdate++; $can++; $strCellPhoneNo++; $owner->strCellPhoneNo = $found[0]->strCellPhoneNo; } if ($owner->EMAIL == "" && $found[0]->EMAIL != "") { $canupdate++; $can++; $EMAIL++; $owner->EMAIL = $found[0]->EMAIL; } if ($can > 0) { $canupdateRow++; $owner->update(); } } } echo ' Found in admin contacts : ' . $new . '<br><br>'; echo ' Can update fields : ' . $canupdate . '<br>'; echo ' Can update record : ' . $canupdateRow . '<br><br>'; echo 'strHomePhoneNo updates : ' . $strHomePhoneNo . '<br>'; echo 'strWorkPhoneNo updates : ' . $strWorkPhoneNo . '<br>'; echo 'strCellPhoneNo updates : ' . $strCellPhoneNo . '<br>'; echo 'EMAIL updates : ' . $EMAIL . '<br><br>'; //dd("end of first data"); } } } $end = \Carbon\Carbon::now('Africa/Johannesburg'); echo '<br><br>End : ' . $end . '<br><br>'; echo 'Time : ' . $end->diffForHumans($start); dd("The End"); }