web.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php
  2. use App\Http\Livewire\Report;
  3. use Illuminate\Support\Facades\Route;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Log;
  8. /*
  9. |--------------------------------------------------------------------------
  10. | Web Routes
  11. |--------------------------------------------------------------------------
  12. |
  13. | Here is where you can register web routes for your application. These
  14. | routes are loaded by the RouteServiceProvider and all of them will
  15. | be assigned to the "web" middleware group. Make something great!
  16. |
  17. */
  18. Route::get('/', function () {
  19. return view('login');
  20. })->name('login');
  21. Route::post('/logout', function (Request $request) {
  22. Auth::logout();
  23. $request->session()->invalidate();
  24. $request->session()->regenerateToken();
  25. return redirect('/');
  26. });
  27. Route::post('/login', function (Request $request) {
  28. $credentials = $request->validate([
  29. 'email' => 'required|email',
  30. 'password' => 'required|string|min:6',
  31. ]);
  32. if (Auth::attempt($credentials)) {
  33. $request->session()->regenerate();
  34. $user = Auth::user();
  35. $isAdmin = false; // Default value
  36. // Clear previous session values to avoid stale data
  37. session()->forget(['user_group_id', 'user_group_name', 'is_admin']);
  38. $userGroup = \App\Models\UserUserGroup::where('user_id', $user->id)->first();
  39. if ($userGroup) {
  40. $group = \App\Models\UserGroup::find($userGroup->group_id);
  41. if ($group) {
  42. session(['user_group_id' => $group->id]);
  43. session(['user_group_name' => $group->name]);
  44. $isAdmin = ($group->name === 'Amministrazione');
  45. session(['is_admin' => $isAdmin]);
  46. Log::info('User logged in with group', [
  47. 'user_id' => $user->id,
  48. 'group_id' => $group->id,
  49. 'group_name' => $group->name,
  50. 'isAdmin' => $isAdmin
  51. ]);
  52. } else {
  53. Log::warning('User group_id references non-existent group', [
  54. 'user_id' => $user->id,
  55. 'group_id' => $userGroup->group_id
  56. ]);
  57. }
  58. } else {
  59. Log::warning('User has no group assigned', ['user_id' => $user->id]);
  60. session(['is_admin' => false]);
  61. }
  62. return redirect()->intended('/reports');
  63. }
  64. Log::info('Failed login attempt', ['email' => $request->email]);
  65. return back()->withErrors([
  66. 'message' => 'Dati di accesso errati',
  67. ]);
  68. });
  69. Route::group(['middleware' => 'auth'],function(){
  70. Route::get('/dashboard', \App\Http\Livewire\Dashboard::class);
  71. Route::get('/accertatore-grado', \App\Http\Livewire\AccertatoreGrado::class);
  72. Route::get('/ausilio-altri-enti', \App\Http\Livewire\AusilioAltriEnti::class);
  73. Route::get('/assicurazioni', \App\Http\Livewire\Compagnia::class);
  74. Route::get('/condizioni-strada', \App\Http\Livewire\CondizioneStrada::class);
  75. Route::get('/condizioni-atmosferiche', \App\Http\Livewire\CondizioniAtmosferiche::class);
  76. Route::get('/condizioni-luce', \App\Http\Livewire\CondizioniLuce::class);
  77. Route::get('/fondo-stradale', \App\Http\Livewire\FondoStradale::class);
  78. Route::get('/marche', \App\Http\Livewire\MarcaVeicolo::class);
  79. Route::get('/modelli', \App\Http\Livewire\ModelloVeicolo::class);
  80. Route::get('/materiale-recuperato', \App\Http\Livewire\MaterialeRecuperato::class);
  81. Route::get('/nomenclatura-strada', \App\Http\Livewire\NomenclaturaStrada::class);
  82. Route::get('/particolarita-strada', \App\Http\Livewire\ParticolaritaStrada::class);
  83. Route::get('/pavimentazione-strada', \App\Http\Livewire\PavimentazioneStrada::class);
  84. Route::get('/rilievi', \App\Http\Livewire\Rilievi::class);
  85. Route::get('/segnalazione-pervenuta-da', \App\Http\Livewire\SegnalazionePervenutaDa::class);
  86. Route::get('/segnalazione-verticale', \App\Http\Livewire\SegnalazioneVerticale::class);
  87. Route::get('/segnalazione-orizzontale', \App\Http\Livewire\SegnalazioneOrizzontale::class);
  88. Route::get('/stradario', \App\Http\Livewire\Stradario::class);
  89. Route::get('/tipo-segnalazione', \App\Http\Livewire\TipoSegnalazione::class);
  90. Route::get('/tipo-strada', \App\Http\Livewire\TipoStrada::class);
  91. Route::get('/entita-danno', \App\Http\Livewire\EntitaDanno::class);
  92. Route::get('/effetto-danno', \App\Http\Livewire\EffettoDanno::class);
  93. Route::get('/tipo-danno', \App\Http\Livewire\TipoDanno::class);
  94. Route::get('/tipo-urto', \App\Http\Livewire\TipoUrto::class);
  95. Route::get('/parte-macchina', \App\Http\Livewire\ParteMacchina::class);
  96. Route::get('/tipo-veicolo', \App\Http\Livewire\TipoVeicolo::class);
  97. Route::get('/users', \App\Http\Livewire\User::class);
  98. Route::get('/vpn', \App\Http\Livewire\VpnManagement::class);
  99. Route::get('/reports', \App\Http\Livewire\Report::class);
  100. Route::get('/istat', \App\Http\Livewire\Istat::class);
  101. Route::get('/print', Report::class);
  102. Route::get('/stradario_api', function(){
  103. if (isset($_GET["q"]))
  104. $stradario = \App\Models\Stradario::where('descrizione', 'like', '%' . $_GET["q"] . '%')->orderBy('descrizione')->get();
  105. else
  106. $stradario = \App\Models\Stradario::orderBy('descrizione')->get();
  107. $data = array();
  108. foreach($stradario as $s)
  109. {
  110. $data[] = array("id" => $s->id, "text" => $s->TOPONIMO . " " . $s->DESCRIZIONE);
  111. }
  112. return array("results" => $data);
  113. });
  114. Route::get('/anagrafica', function() {
  115. if (isset($_GET["q"])) {
  116. $anagrafica = \App\Models\Anagrafica::where('lastname', 'like', '%' . $_GET["q"] . '%')
  117. ->orWhere('firstname', 'like', '%' . $_GET["q"] . '%')
  118. ->orWhere('rag_soc', 'like', '%' . $_GET["q"] . '%')
  119. ->orderBy('lastname')
  120. ->orderBy('firstname')
  121. ->get();
  122. } else {
  123. $anagrafica = \App\Models\Anagrafica::orderBy('lastname')
  124. ->orderBy('firstname')
  125. ->get();
  126. }
  127. $data = [];
  128. foreach ($anagrafica as $a) {
  129. $text = (empty($a->lastname) && empty($a->firstname))
  130. ? $a->rag_soc // Use company name if names are empty
  131. : trim($a->lastname . ' ' . $a->firstname);
  132. $data[] = ["id" => $a->id, "text" => $text];
  133. }
  134. return ["results" => $data];
  135. });
  136. Route::get('/localita', function(){
  137. if (isset($_GET["q"]))
  138. $localita = \App\Models\LocationTown::where('title', 'like', '%' . $_GET["q"] . '%')->orderBy('title')->get();
  139. else
  140. $localita = \App\Models\LocationTown::orderBy('title')->get();
  141. $data = array();
  142. foreach($localita as $l)
  143. {
  144. $data[] = array("id" => $l->id, "text" => $l->title);
  145. }
  146. return array("results" => $data);
  147. });
  148. Route::get('/veicoli', function(){
  149. if (isset($_GET["q"]))
  150. {
  151. $value = $_GET["q"];
  152. $veicoli = \App\Models\Vehicle::with('marca')->with('modello')->whereHas('marca', function ($q) use ($value) {
  153. $q->where('name', "LIKE", '%' . $value . '%');
  154. })->orWhereHas('modello', function ($q) use ($value) {
  155. $q->where('name', "LIKE", '%' . $value . '%');
  156. })->get()->sortBy('marca.name',SORT_REGULAR,false);
  157. }
  158. else
  159. $veicoli = \App\Models\Vehicle::with('marca')->with('modello')->get()->sortBy('marca.name',SORT_REGULAR,false);
  160. $data = array();
  161. foreach($veicoli as $v)
  162. {
  163. $data[] = array("id" => $v->id, "text" => ($v->marca ? $v->marca->name : '') . " " . ($v->modello ? $v->modello->name : '') . " " . $v->targa);
  164. }
  165. return array("results" => $data);
  166. });
  167. Route::get('/accertatori', function(){
  168. if (isset($_GET["q"]))
  169. {
  170. $value = $_GET["q"];
  171. $accertatori = DB::table('fcf_users')
  172. ->leftjoin('fcf_user_user_groups','fcf_user_user_groups.user_id','=','fcf_users.id')
  173. ->selectRaw('fcf_users.*')
  174. ->where('fcf_user_user_groups.group_id', 2)
  175. ->where(function ($query) {
  176. $query->where('fcf_users.lastname', 'like', '%' . $_GET["q"] . '%')
  177. ->orWhere('fcf_users.firstname', 'like', '%' . $_GET["q"] . '%');
  178. })
  179. ->orderBy('fcf_users.lastname')
  180. ->get();
  181. }
  182. else
  183. $accertatori = DB::table('fcf_users')
  184. ->leftjoin('fcf_user_user_groups','fcf_user_user_groups.user_id','=','fcf_users.id')
  185. ->selectRaw('fcf_users.*')
  186. ->where('fcf_user_user_groups.group_id', 2)
  187. ->orderBy('fcf_users.lastname')
  188. ->get();
  189. $data = array();
  190. foreach($accertatori as $a)
  191. {
  192. $data[] = array("id" => $a->id, "text" => $a->lastname . " " . $a->firstname);
  193. }
  194. return array("results" => $data);
  195. });
  196. Route::get('/polizze', function(){
  197. if (isset($_GET["q"]))
  198. {
  199. $value = $_GET["q"];
  200. $polizze = \App\Models\Polizza::with('compagnia')->with('anagrafica')->where('agenzia', 'LIKE', '%' . $_GET["q"] . '%')
  201. ->orWhereHas('compagnia', function ($q) use ($value) {
  202. $q->where('name', "LIKE", '%' . $value . '%');
  203. })->orWhereHas('anagrafica', function ($q) use ($value) {
  204. $q->where('lastname', "LIKE", '%' . $value . '%')->orWhere('firstname', "LIKE", '%' . $value . '%');
  205. })->get()->sortBy('marca.name',SORT_REGULAR,false);
  206. }
  207. else
  208. $polizze = \App\Models\Polizza::with('compagnia')->with('anagrafica')->get()->sortBy('agenzia',SORT_REGULAR,false);
  209. $data = array();
  210. foreach($polizze as $p)
  211. {
  212. $data[] = array("id" => $p->id, "text" => $p->agenzia . " " . ($p->compagnia ? $p->compagnia->name : '') . " " . ($p->anagrafica ? ($p->anagrafica->lastname . " " . $p->anagrafica->firstname) : ''));
  213. }
  214. return array("results" => $data);
  215. });
  216. });
  217. Route::get('/test_targa/{targa}', function ($targa) {
  218. try
  219. {
  220. $wd = "dettaglioAutoveicoloBase";
  221. $wd = "datiCartaCircolazioneAutoveicoloProprietario";
  222. $url = 'https://www.ilportaledellautomobilista.it/Info-ws/services';
  223. $client = new \SoapClient($url . '/' . $wd . '/' . $wd . '.wsdl', array(
  224. 'stream_context' => stream_context_create(array(
  225. 'ssl' => array(
  226. 'verify_peer' => false,
  227. 'verify_peer_name' => false,
  228. 'allow_self_signed' => true
  229. )
  230. )),
  231. 'trace'=>1
  232. ));
  233. $utente = 'CMRM001301';
  234. $password = '2PMPM*86';
  235. $xml = '<wsse:Security
  236. xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
  237. SOAP-ENV:mustUnderstand="1">
  238. <wsse:UsernameToken
  239. xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
  240. wsu:Id="XWSSGID-1253605895203984534550">
  241. <wsse:Username>' . $utente . '</wsse:Username>
  242. <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' . $password . '</wsse:Password>
  243. </wsse:UsernameToken>
  244. </wsse:Security>';
  245. $header = new \SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
  246. 'Security',
  247. new \SoapVar($xml, XSD_ANYXML),
  248. true
  249. );
  250. $client->__setSoapHeaders($header);
  251. $classe = "dettaglioAutoveicoloBase";
  252. $classe = "dettaglioCartaCircolazioneProprietarioAutoveicolo";
  253. try
  254. {
  255. // Run the function
  256. $obj = $client->__soapCall($classe, array(
  257. $classe . "Request" => array(
  258. "login" => array(
  259. ),
  260. //"dettaglioAutoveicoloBaseInput" => array(
  261. "targa" => array("numeroTarga" => $targa),
  262. //),
  263. "pdf" => false
  264. )
  265. ));
  266. print "<pre>";
  267. print_r($obj);
  268. print "</pre>";
  269. }
  270. catch(\SoapFault $fault)
  271. {
  272. print $fault;
  273. // <xmp> tag displays xml output in html
  274. //echo 'Request : <br/><xmp>',
  275. //$client->__getLastRequest(),
  276. //'</xmp><br/><br/> Error Message : <br/>',
  277. //$fault->getMessage();
  278. }
  279. }
  280. catch(Exception $ex)
  281. {
  282. print "QUA5";
  283. print $ex;
  284. }
  285. });
  286. Route::get('/print-pdf/{id}', [Report::class, 'print'])->name('print.pdf');
  287. Route::get('/countries', function() {
  288. $search = request()->get('search');
  289. $query = \App\Models\LocationCountry::query();
  290. if($search) {
  291. $query->where('name', 'like', "%{$search}%");
  292. }
  293. $countries = $query->get()->map(function($country) {
  294. return [
  295. 'id' => $country->id,
  296. 'text' => $country->name
  297. ];
  298. });
  299. return response()->json([
  300. 'results' => $countries
  301. ]);
  302. });
  303. Route::get('/compagnie', function(){
  304. if (isset($_GET["q"]))
  305. $compagnie = \App\Models\Compagnia::where('name', 'like', '%' . $_GET["q"] . '%')->orderBy('name')->get();
  306. else
  307. $compagnie = \App\Models\Compagnia::orderBy('name')->get();
  308. $data = array();
  309. foreach($compagnie as $c)
  310. {
  311. $data[] = array("id" => $c->id, "text" => $c->name);
  312. }
  313. return array("results" => $data);
  314. });
  315. Route::get('/polizze/agenzie', function(Request $request) {
  316. $query = \App\Models\Polizza::query();
  317. if ($request->has('q')) {
  318. $query->where('agenzia', 'like', '%' . $request->q . '%');
  319. }
  320. // Get unique agenzie
  321. $agenzie = $query->distinct()
  322. ->whereNotNull('agenzia')
  323. ->where('agenzia', '!=', '')
  324. ->pluck('agenzia');
  325. return [
  326. 'results' => $agenzie->map(function($agenzia) {
  327. return [
  328. 'id' => $agenzia,
  329. 'text' => $agenzia
  330. ];
  331. })
  332. ];
  333. });