public function postCreate(Request $request)
 {
     $validator = Validator::make($request->all(), array('firstName' => 'required', 'lastName' => 'required', 'username' => 'required|max:20|min:3|unique:users', 'password' => 'required|min:6', 'email' => 'required|max:50|email|unique:users', 'roleId' => 'integer|min:1'));
     if ($validator->fails()) {
         return redirect()->route('admin-users-create')->withErrors($validator)->withInput();
     } else {
         $user = User::create(array('firstName' => $request->get('firstName'), 'lastName' => $request->get('lastName'), 'username' => $request->get('username'), 'password' => Hash::make($request->get('password')), 'email' => $request->get('email'), 'active' => $request->has('active') ? true : false, 'mobile' => $request->get('mobile'), 'roleId' => $request->get('roleId')));
         $arr = array('id' => $user->id, 'firstName' => $user->firstName, 'lastName' => $user->lastName, 'username' => $user->username, 'email' => $user->email, 'active' => $user->active, 'mobile' => $user->mobile);
         if ($user) {
             //$message = trans('language.USER-CREATED');
             $message = 'User has been created.';
             //Logging::created('User', $arr);
         } else {
             //$message = trans('language.USER-NOT-CREATED');
             $message = 'User can not be created, please try again.';
             //Logging::not_created('User', $arr);
         }
         $copy1 = copy('output/crops.xlsx', 'uploads/' . $user->id . '$crops.xlsx');
         $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . $user->id . '$crops.xlsx', 'crop', $user->id);
         if ($copy1 == true and strpos($result, 'Uploaded') !== false) {
             $state = '1';
         } else {
             $state = '0';
         }
         $copy2 = copy('output/soils.xlsx', 'uploads/' . $user->id . '$soils.xlsx');
         $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . $user->id . '$soils.xlsx', 'soil', $user->id);
         if ($copy2 == true and strpos($result, 'Uploaded') !== false) {
             $state .= '-1';
         } else {
             $state .= '-0';
         }
         $copy3 = copy('output/efficiency.xlsx', 'uploads/' . $user->id . '$efficiency.xlsx');
         $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . $user->id . '$efficiency.xlsx', 'efficiency', $user->id);
         if ($copy3 == true and strpos($result, 'Uploaded') !== false) {
             $state .= '-1';
         } else {
             $state .= '-0';
         }
         $copy4 = copy('output/yield.xlsx', 'uploads/' . $user->id . '$yield.xlsx');
         $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . $user->id . '$yield.xlsx', 'yield', $user->id);
         if ($copy4 == true and strpos($result, 'Uploaded') !== false) {
             $state .= '-1';
         } else {
             $state .= '-0';
         }
         $state .= '-0-0-0-0-0-0';
         $upload = Upload::create(array('userId' => $user->id, 'state' => $state));
         if ($copy1 == true) {
             $upload->crop = 'crops.xlsx';
             $upload->crop_at = date('Y-m-d H:i:s');
             $upload->save();
         }
         if ($copy2 == true) {
             $upload->soil = 'soils.xlsx';
             $upload->soil_at = date('Y-m-d H:i:s');
             $upload->save();
         }
         if ($copy3 == true) {
             $upload->efficiency = 'efficiency.xlsx';
             $upload->efficiency_at = date('Y-m-d H:i:s');
             $upload->save();
         }
         if ($copy4 == true) {
             $upload->yield = 'yield.xlsx';
             $upload->yield_at = date('Y-m-d H:i:s');
             $upload->save();
         }
     }
     return redirect()->route('admin-users-list')->with('global', $message);
 }
 public function runModel()
 {
     $uploads = Upload::getUploads();
     $upload = $uploads->first();
     $state_arr = explode('-', $upload->state);
     /*
             for($i=0; $i<=7; $i++) {
                 if($i==5) continue;
                 else if($state_arr[$i]==0) {
                     switch ($i) {
                         case 0: return json_encode(array('type'=>'Crop', 'state'=>$state_arr[$i])); break;
                         case 1: return json_encode(array('type'=>'Soil', 'state'=>$state_arr[$i])); break;
                         case 2: return json_encode(array('type'=>'Irrigation Efficiency', 'state'=>$state_arr[$i])); break;
                         case 3: return json_encode(array('type'=>'Crop Yield', 'state'=>$state_arr[$i])); break;
                         case 4: return json_encode(array('type'=>'Climate Model', 'state'=>$state_arr[$i])); break;
                         case 5: return json_encode(array('type'=>'Weather Data', 'state'=>$state_arr[$i])); break;
                         case 6: return json_encode(array('type'=>'Model Type', 'state'=>$state_arr[$i])); break;
                         case 7: return json_encode(array('type'=>'Model Type', 'state'=>$state_arr[$i])); break;
                     }
                 }
             }*/
     for ($i = 0; $i <= 7; $i++) {
         if ($i == 5 && $upload->climate_model != 'SelfSuppliedStation') {
             continue;
         } else {
             if ($state_arr[$i] == 0) {
                 switch ($i) {
                     case 0:
                         return json_encode(array('type' => 'Crop', 'state' => $state_arr[$i]));
                         break;
                     case 1:
                         return json_encode(array('type' => 'Soil', 'state' => $state_arr[$i]));
                         break;
                     case 2:
                         return json_encode(array('type' => 'Irrigation Efficiency', 'state' => $state_arr[$i]));
                         break;
                     case 3:
                         return json_encode(array('type' => 'Crop Yield', 'state' => $state_arr[$i]));
                         break;
                     case 4:
                         return json_encode(array('type' => 'Climate Model', 'state' => $state_arr[$i]));
                         break;
                     case 5:
                         return json_encode(array('type' => 'Weather Data', 'state' => $state_arr[$i]));
                         break;
                     case 6:
                         return json_encode(array('type' => 'Model Type', 'state' => $state_arr[$i]));
                         break;
                     case 7:
                         return json_encode(array('type' => 'Model Type', 'state' => $state_arr[$i]));
                         break;
                 }
             }
         }
     }
     $state_arr[8] = 1;
     $state = $state_arr[0];
     for ($j = 1; $j < count($state_arr); $j++) {
         $state .= '-' . $state_arr[$j];
     }
     $upload->state = $state;
     $upload->save();
     $result = Upload::uploadInputFile(Config::getUploadBaseDirectory() . 'uploads/' . User::getSignedInUserId() . "\$" . "IC_ClimIn.txt", 'run_model', User::getSignedInUserId());
     return json_encode(array('state' => -1));
 }