web.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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('/vpn/status', [\App\Http\Controllers\VpnController::class, 'getStatus'])->name('vpn.status');
  100. Route::get('/reports', \App\Http\Livewire\Report::class);
  101. Route::get('/istat', \App\Http\Livewire\Istat::class);
  102. Route::get('/prefettura', \App\Http\Livewire\Prefettura::class);
  103. Route::get('/print', Report::class);
  104. Route::get('/stradario_api', function(){
  105. if (isset($_GET["q"]))
  106. $stradario = \App\Models\Stradario::where('descrizione', 'like', '%' . $_GET["q"] . '%')->orderBy('descrizione')->get();
  107. else
  108. $stradario = \App\Models\Stradario::orderBy('descrizione')->get();
  109. $data = array();
  110. foreach($stradario as $s)
  111. {
  112. $data[] = array("id" => $s->id, "text" => $s->TOPONIMO . " " . $s->DESCRIZIONE);
  113. }
  114. return array("results" => $data);
  115. });
  116. Route::get('/residenza', function(){
  117. if (isset($_GET["q"]))
  118. $stradario = \App\Models\Stradario::where('descrizione', 'like', '%' . $_GET["q"] . '%')->orderBy('descrizione')->get();
  119. else
  120. $stradario = \App\Models\Stradario::orderBy('descrizione')->get();
  121. $data = array();
  122. foreach($stradario as $s)
  123. {
  124. $data[] = array("id" => $s->TOPONIMO . " " . $s->DESCRIZIONE, "text" => $s->TOPONIMO . " " . $s->DESCRIZIONE);
  125. }
  126. return array("results" => $data);
  127. });
  128. Route::get('/anagrafica', function() {
  129. if (isset($_GET["q"])) {
  130. $anagrafica = \App\Models\Anagrafica::where('lastname', 'like', '%' . $_GET["q"] . '%')
  131. ->orWhere('firstname', 'like', '%' . $_GET["q"] . '%')
  132. ->orWhere('rag_soc', 'like', '%' . $_GET["q"] . '%')
  133. ->orderBy('lastname')
  134. ->orderBy('firstname')
  135. ->get();
  136. } else {
  137. $anagrafica = \App\Models\Anagrafica::orderBy('lastname')
  138. ->orderBy('firstname')
  139. ->get();
  140. }
  141. $data = [];
  142. foreach ($anagrafica as $a) {
  143. $text = (empty($a->lastname) && empty($a->firstname))
  144. ? $a->rag_soc // Use company name if names are empty
  145. : trim($a->lastname . ' ' . $a->firstname);
  146. $data[] = ["id" => $a->id, "text" => $text];
  147. }
  148. return ["results" => $data];
  149. });
  150. Route::get('/localita', function(){
  151. if (isset($_GET["q"]))
  152. $localita = \App\Models\LocationTown::where('title', 'like', '%' . $_GET["q"] . '%')->orderBy('title')->get();
  153. else
  154. $localita = \App\Models\LocationTown::orderBy('title')->get();
  155. $data = array();
  156. foreach($localita as $l)
  157. {
  158. if (strtoupper(trim($l->title)) == 'ROMA')
  159. array_unshift($data, array("id" => $l->id, "text" => $l->title));
  160. else
  161. $data[] = array("id" => $l->id, "text" => $l->title);
  162. }
  163. return array("results" => $data);
  164. });
  165. Route::get('/veicoli', function(){
  166. if (isset($_GET["q"]))
  167. {
  168. $value = $_GET["q"];
  169. $veicoli = \App\Models\Vehicle::with('marca')->with('modello')->whereHas('marca', function ($q) use ($value) {
  170. $q->where('name', "LIKE", '%' . $value . '%');
  171. })->orWhereHas('modello', function ($q) use ($value) {
  172. $q->where('name', "LIKE", '%' . $value . '%');
  173. })->get()->sortBy('marca.name',SORT_REGULAR,false);
  174. }
  175. else
  176. $veicoli = \App\Models\Vehicle::with('marca')->with('modello')->get()->sortBy('marca.name',SORT_REGULAR,false);
  177. $data = array();
  178. foreach($veicoli as $v)
  179. {
  180. $data[] = array("id" => $v->id, "text" => ($v->marca ? $v->marca->name : '') . " " . ($v->modello ? $v->modello->name : '') . " " . $v->targa);
  181. }
  182. return array("results" => $data);
  183. });
  184. Route::get('/accertatori', function(){
  185. if (isset($_GET["q"]))
  186. {
  187. $value = $_GET["q"];
  188. $accertatori = DB::table('fcf_users')
  189. ->leftjoin('fcf_user_user_groups','fcf_user_user_groups.user_id','=','fcf_users.id')
  190. ->selectRaw('fcf_users.*')
  191. ->where('fcf_user_user_groups.group_id', 2)
  192. ->where(function ($query) {
  193. $query->where('fcf_users.lastname', 'like', '%' . $_GET["q"] . '%')
  194. ->orWhere('fcf_users.firstname', 'like', '%' . $_GET["q"] . '%');
  195. })
  196. ->orderBy('fcf_users.lastname')
  197. ->get();
  198. }
  199. else
  200. $accertatori = DB::table('fcf_users')
  201. ->leftjoin('fcf_user_user_groups','fcf_user_user_groups.user_id','=','fcf_users.id')
  202. ->selectRaw('fcf_users.*')
  203. ->where('fcf_user_user_groups.group_id', 2)
  204. ->orderBy('fcf_users.lastname')
  205. ->get();
  206. $data = array();
  207. foreach($accertatori as $a)
  208. {
  209. $data[] = array("id" => $a->id, "text" => $a->lastname . " " . $a->firstname);
  210. }
  211. return array("results" => $data);
  212. });
  213. Route::get('/polizze', function(){
  214. if (isset($_GET["q"]))
  215. {
  216. $value = $_GET["q"];
  217. $polizze = \App\Models\Polizza::with('compagnia')->with('anagrafica')->where('agenzia', 'LIKE', '%' . $_GET["q"] . '%')
  218. ->orWhereHas('compagnia', function ($q) use ($value) {
  219. $q->where('name', "LIKE", '%' . $value . '%');
  220. })->orWhereHas('anagrafica', function ($q) use ($value) {
  221. $q->where('lastname', "LIKE", '%' . $value . '%')->orWhere('firstname', "LIKE", '%' . $value . '%');
  222. })->get()->sortBy('marca.name',SORT_REGULAR,false);
  223. }
  224. else
  225. $polizze = \App\Models\Polizza::with('compagnia')->with('anagrafica')->get()->sortBy('agenzia',SORT_REGULAR,false);
  226. $data = array();
  227. foreach($polizze as $p)
  228. {
  229. $data[] = array("id" => $p->id, "text" => $p->agenzia . " " . ($p->compagnia ? $p->compagnia->name : '') . " " . ($p->anagrafica ? ($p->anagrafica->lastname . " " . $p->anagrafica->firstname) : ''));
  230. }
  231. return array("results" => $data);
  232. });
  233. });
  234. Route::get('/test_targa/{targa}', function ($targa) {
  235. try
  236. {
  237. $wd = "dettaglioAutoveicoloBase";
  238. $wd = "datiCartaCircolazioneAutoveicoloProprietario";
  239. $url = 'https://www.ilportaledellautomobilista.it/Info-ws/services';
  240. $client = new \SoapClient($url . '/' . $wd . '/' . $wd . '.wsdl', array(
  241. 'stream_context' => stream_context_create(array(
  242. 'ssl' => array(
  243. 'verify_peer' => false,
  244. 'verify_peer_name' => false,
  245. 'allow_self_signed' => true
  246. )
  247. )),
  248. 'trace'=>1
  249. ));
  250. $utente = 'CMRM001301';
  251. $password = '2PMPM*86';
  252. $xml = '<wsse:Security
  253. xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
  254. SOAP-ENV:mustUnderstand="1">
  255. <wsse:UsernameToken
  256. xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
  257. wsu:Id="XWSSGID-1253605895203984534550">
  258. <wsse:Username>' . $utente . '</wsse:Username>
  259. <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' . $password . '</wsse:Password>
  260. </wsse:UsernameToken>
  261. </wsse:Security>';
  262. $header = new \SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
  263. 'Security',
  264. new \SoapVar($xml, XSD_ANYXML),
  265. true
  266. );
  267. $client->__setSoapHeaders($header);
  268. $classe = "dettaglioAutoveicoloBase";
  269. $classe = "dettaglioCartaCircolazioneProprietarioAutoveicolo";
  270. try
  271. {
  272. // Run the function
  273. $obj = $client->__soapCall($classe, array(
  274. $classe . "Request" => array(
  275. "login" => array(
  276. ),
  277. //"dettaglioAutoveicoloBaseInput" => array(
  278. "targa" => array("numeroTarga" => $targa),
  279. //),
  280. "pdf" => false
  281. )
  282. ));
  283. print "<pre>";
  284. print_r($obj);
  285. print "</pre>";
  286. }
  287. catch(\SoapFault $fault)
  288. {
  289. print $fault;
  290. // <xmp> tag displays xml output in html
  291. //echo 'Request : <br/><xmp>',
  292. //$client->__getLastRequest(),
  293. //'</xmp><br/><br/> Error Message : <br/>',
  294. //$fault->getMessage();
  295. }
  296. }
  297. catch(Exception $ex)
  298. {
  299. print "QUA5";
  300. print $ex;
  301. }
  302. });
  303. Route::get('/print-pdf/{id}/{type?}', [Report::class, 'print'])->name('print.pdf');
  304. Route::get('/countries', function() {
  305. $search = request()->get('search');
  306. $query = \App\Models\LocationCountry::query();
  307. if($search) {
  308. $query->where('name', 'like', "%{$search}%");
  309. }
  310. $countries = $query->get()->map(function($country) {
  311. return [
  312. 'id' => $country->id,
  313. 'text' => $country->name
  314. ];
  315. });
  316. return response()->json([
  317. 'results' => $countries
  318. ]);
  319. });
  320. Route::get('/compagnie', function(){
  321. if (isset($_GET["q"]))
  322. $compagnie = \App\Models\Compagnia::where('name', 'like', '%' . $_GET["q"] . '%')->orderBy('name')->get();
  323. else
  324. $compagnie = \App\Models\Compagnia::orderBy('name')->get();
  325. $data = array();
  326. foreach($compagnie as $c)
  327. {
  328. $data[] = array("id" => $c->id, "text" => $c->name);
  329. }
  330. return array("results" => $data);
  331. });
  332. Route::get('/polizze/agenzie', function(Request $request) {
  333. $query = \App\Models\Polizza::query();
  334. if ($request->has('q')) {
  335. $query->where('agenzia', 'like', '%' . $request->q . '%');
  336. }
  337. // Get unique agenzie
  338. $agenzie = $query->distinct()
  339. ->whereNotNull('agenzia')
  340. ->where('agenzia', '!=', '')
  341. ->pluck('agenzia');
  342. return [
  343. 'results' => $agenzie->map(function($agenzia) {
  344. return [
  345. 'id' => $agenzia,
  346. 'text' => $agenzia
  347. ];
  348. })
  349. ];
  350. });