web.php 15 KB

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