FabioFratini 7 ay önce
ebeveyn
işleme
f6542334a0

+ 268 - 247
app/Http/Controllers/NewsController.php

@@ -12,6 +12,8 @@ use Illuminate\Support\Facades\File;
 use Illuminate\Support\Facades\Auth;
 use App\Notifications\FacebookPost;
 use App\Notifications\TwitterPost;
+use Illuminate\Support\Facades\Log;
+
 class NewsController extends Controller
 {
 
@@ -27,14 +29,11 @@ class NewsController extends Controller
         // Se stavo modificando una news metto a null il campo
         if ($request->session()->has('current_news')) {
             $news_id = session('current_news', 0);
-            if ($news_id > 0)
-            {
+            if ($news_id > 0) {
                 $n = News::where('id', '=', $news_id)->take(1000)->get();
-                if ($n->count() > 0)
-                {
+                if ($n->count() > 0) {
                     $n = $n->first();
-                    if ($n->user_id == Auth::user()->id)
-                    {
+                    if ($n->user_id == Auth::user()->id) {
                         $n->user_id = null;
                         $n->save();
                     }
@@ -43,16 +42,16 @@ class NewsController extends Controller
             }
         }
 
-        $news = News::orderBy('date', 'DESC')->take(1000)->get();//->paginate(50);
+        $news = News::orderBy('date', 'DESC')->take(1000)->get(); //->paginate(50);
 
-        return view('news.index',compact('news'))
+        return view('news.index', compact('news'))
             ->with('i', (request()->input('page', 1) - 1) * 5);
     }
 
     public function load_json()
     {
         $start = $_GET["start"];
-        $end = 50;//$_GET["length"];
+        $end = 50; //$_GET["length"];
         $total = News::count();
         $filtered = $total;
 
@@ -92,44 +91,34 @@ class NewsController extends Controller
 
         $search = $_GET["search"]["value"];
 
-        if ($sort == '3')
-        {
+        if ($sort == '3') {
             $news = News::with(['section' => function ($query) use ($sort_by, $sort_by_dir) {
                 $query->orderBy($sort_by, $sort_by_dir);
             }]);
-        }
-        else if ($sort == '4')
-        {
+        } else if ($sort == '4') {
             $news = News::with(['region_1' => function ($query) use ($sort_by, $sort_by_dir) {
                 $query->orderBy($sort_by, $sort_by_dir);
             }]);
-        }
-        else if ($sort == '5')
-        {
+        } else if ($sort == '5') {
             $news = News::with(['region_2' => function ($query) use ($sort_by, $sort_by_dir) {
                 $query->orderBy($sort_by, $sort_by_dir);
             }]);
-        }
-        else if ($sort == '6')
-        {
+        } else if ($sort == '6') {
             $news = News::with(['event' => function ($query) use ($sort_by, $sort_by_dir) {
                 $query->orderBy($sort_by, $sort_by_dir);
             }]);
-        }
-        else
+        } else
             $news = News::orderBy($sort_by, $sort_by_dir);
 
-        if ($search != '')
-        {
+        if ($search != '') {
             $news = $news->where('title', 'LIKE', '%' . $search . '%');
             $filtered = $news->count();
         }
 
-        $news = $news->limit($end)->offset($start)->get();//->paginate(50);
+        $news = $news->limit($end)->offset($start)->get(); //->paginate(50);
 
         $aData = array();
-        foreach($news as $n)
-        {
+        foreach ($news as $n) {
             $x = array();
             $x[] = $n->date;
             if ($n->image != '')
@@ -138,15 +127,15 @@ class NewsController extends Controller
                 $x[] = '';
             $x[] = $n->title;
             $section = @$n->section->name;
-            if($n->section)
+            if ($n->section)
                 $section .= '<br>' . isset($n->section) ? $n->section->position($n->id) : '';
             $x[] = $section;
             $region_1 = @$n->region_1->name;
-            if($n->region_1)
+            if ($n->region_1)
                 $region_1 .= '<br>' . isset($n->region_1) ? $n->region_1->position($n->id) : '';
             $x[] = $region_1;
             $region_2 = @$n->region_2->name;
-            if($n->region_2)
+            if ($n->region_2)
                 $region_2 .= '<br>' . isset($n->region_2) ? $n->region_2->position($n->id) : '';
             $x[] = $region_2;
             //$x[] = @$n->event->title;
@@ -187,19 +176,16 @@ class NewsController extends Controller
         $first = '';
         $aFirst = array();
         $home = Home::first();
-        if ($home != null)
-        {
+        if ($home != null) {
             $pos = '';
             $home->loadData();
             if (isset($home->slide1) && $home->slide1 != '')
                 $aFirst[] = $home->slide1->title . " (immagine grande)";
-            for($a=1;$a<=5;$a++)
-            {
+            for ($a = 1; $a <= 5; $a++) {
                 if (isset($home["left" . $a]) && $home["left" . $a] != '')
                     $aFirst[] = $home["left" . $a]["title"] . " (slide sinistra)";
             }
-            for($a=1;$a<=5;$a++)
-            {
+            for ($a = 1; $a <= 5; $a++) {
                 if (isset($home["right" . $a]) && $home["right" . $a] != '')
                     $aFirst[] = $home["right" . $a]["title"] . " (slide destra)";
             }
@@ -215,165 +201,220 @@ class NewsController extends Controller
      * @param  \Illuminate\Http\Request  $request
      * @return \Illuminate\Http\Response
      */
+
     public function store(Request $request)
     {
-        $request->validate($this->rules);
+        Log::info('=== NEWS STORE METHOD START ===');
+        Log::info('Request data:', $request->all());
+        Log::info('Request method:', [$request->method()]);
 
-        $input = $request->all();
-
-        if(request()->image)
-        {
+        try {
+            $request->validate($this->rules);
+            Log::info('Validation passed');
 
-            $file = request()->image;
-            $filename  = time() . '_' . $file->getClientOriginalName();
-
-            if (! File::exists(public_path()."/files/news"))
-                File::makeDirectory(public_path()."/files/news");
-
-            $path = public_path('files/news');
+            $input = $request->all();
+            Log::info('Input data:', $input);
 
-            request()->image->move($path, $filename);
-
-            $input["image"] = $filename;
-
-        }
-        else
-        {
-            if (isset($_POST["filename"]))
-                $input["image"] = $_POST["filename"];
-        }
-
-        for($i=1;$i<=5;$i++)
-        {
-            if(isset($input["image" . $i]))
-            {
+            // Check which button was clicked
+            if (isset($input['save'])) {
+                Log::info('SAVE button clicked');
+            }
+            if (isset($input['save_exit'])) {
+                Log::info('SAVE_EXIT button clicked');
+            }
+            if (isset($input['publish'])) {
+                Log::info('PUBLISH button clicked');
+            }
+            if (isset($input['unpublish'])) {
+                Log::info('UNPUBLISH button clicked');
+            }
 
-                $file = $input["image" . $i];
+            // Image handling
+            if (request()->image) {
+                Log::info('Processing main image upload');
+                $file = request()->image;
                 $filename  = time() . '_' . $file->getClientOriginalName();
 
-                if (! File::exists(public_path()."/files/news"))
-                    File::makeDirectory(public_path()."/files/news");
+                if (! File::exists(public_path() . "/files/news"))
+                    File::makeDirectory(public_path() . "/files/news");
 
                 $path = public_path('files/news');
-
-                $input["image" . $i]->move($path, $filename);
-
-                $input["image" . $i] = $filename;
-
+                request()->image->move($path, $filename);
+                $input["image"] = $filename;
+                Log::info('Main image uploaded:', [$filename]);
+            } else {
+                if (isset($input["filename"])) {
+                    $input["image"] = $input["filename"];
+                    Log::info('Using existing filename:', [$input["filename"]]);
+                }
             }
-        }
-
-        if(request()->pdf)
-        {
 
-            $file = request()->pdf;
-            $filename  = time() . '_' . $file->getClientOriginalName();
-
-            if (! File::exists(public_path()."/files/news"))
-                File::makeDirectory(public_path()."/files/news");
-
-            $path = public_path('files/news');
-
-            request()->pdf->move($path, $filename);
+            // Handle additional images
+            for ($i = 1; $i <= 5; $i++) {
+                if (isset($input["image" . $i])) {
+                    Log::info("Processing image{$i} upload");
+                    $file = $input["image" . $i];
+                    $filename  = time() . '_' . $file->getClientOriginalName();
 
-            $input["pdf"] = $filename;
-
-        }
-
-        $final_date = null;
-        if ($input["date"] != '')
-        {
-            list($dt, $time) = explode(" ", $input["date"]);
-            list($day, $month, $year) = explode("/", $dt);
-            $final_date = $year . "-" . $month . "-" . $day . " " . $time;
-        }
-        $input["date"] = $final_date;
-
-        $input["online"] = false;
-        $input["homepage"] = isset($input["homepage"]) ? ($input["homepage"] == 'on' ? true : false) : false;
-        $input["live"] = isset($input["live"]) ? ($input["live"] == 'on' ? true : false) : false;
-        $input["breaking_news"] = isset($input["breaking_news"]) ? ($input["breaking_news"] == 'on' ? true : false) : false;
+                    if (! File::exists(public_path() . "/files/news"))
+                        File::makeDirectory(public_path() . "/files/news");
 
-        $news = News::create($input);
+                    $path = public_path('files/news');
+                    $input["image" . $i]->move($path, $filename);
+                    $input["image" . $i] = $filename;
+                    Log::info("Image{$i} uploaded:", [$filename]);
+                }
+            }
 
-        if (isset($input['publish']))
-        {
-            $news->online = true;
-            $news->save();
+            // Handle PDF
+            if (request()->pdf) {
+                Log::info('Processing PDF upload');
+                $file = request()->pdf;
+                $filename  = time() . '_' . $file->getClientOriginalName();
 
-            // Posiziono la notizia se la data non è
-            if ($final_date <= date("Y-m-d H:i:s"))
-            {
+                if (! File::exists(public_path() . "/files/news"))
+                    File::makeDirectory(public_path() . "/files/news");
 
-                if ($_POST["section_position"] != '')
-                {
-                    $s = Section::findOrFail($input["section_id"]);
-                    $s[$_POST["section_position"]] = $news->id;
-                    $s->save();
-                    $news->section_position = '';
+                $path = public_path('files/news');
+                request()->pdf->move($path, $filename);
+                $input["pdf"] = $filename;
+                Log::info('PDF uploaded:', [$filename]);
+            }
 
+            // Date processing
+            $final_date = null;
+            if ($input["date"] != '') {
+                list($dt, $time) = explode(" ", $input["date"]);
+                list($day, $month, $year) = explode("/", $dt);
+                $final_date = $year . "-" . $month . "-" . $day . " " . $time;
+                Log::info('Date processed:', [$input["date"], $final_date]);
+            }
+            $input["date"] = $final_date;
+
+            // Handle checkboxes
+            $input["online"] = false;
+            $input["homepage"] = isset($input["homepage"]) ? ($input["homepage"] == 'on' ? true : false) : false;
+            $input["live"] = isset($input["live"]) ? ($input["live"] == 'on' ? true : false) : false;
+            $input["breaking_news"] = isset($input["breaking_news"]) ? ($input["breaking_news"] == 'on' ? true : false) : false;
+            $input["no_social"] = isset($input["no_social"]) ? ($input["no_social"] == 'on' ? true : false) : false;
+
+            Log::info('Checkbox values:', [
+                'homepage' => $input["homepage"],
+                'live' => $input["live"],
+                'breaking_news' => $input["breaking_news"],
+                'no_social' => $input["no_social"]
+            ]);
+
+            Log::info('About to create news record');
+            $news = News::create($input);
+            Log::info('News created with ID:', [$news->id]);
+
+            // Handle publish action
+            if (isset($input['publish'])) {
+                Log::info('Processing publish action');
+                $news->online = true;
+                $news->save();
+                Log::info('News set to online');
+
+                // Position the news if date is not in future
+                if ($final_date <= date("Y-m-d H:i:s")) {
+                    Log::info('Date is not in future, processing positions');
+
+                    if ($input["section_position"] != '') {
+                        Log::info('Processing section position:', [$input["section_position"]]);
+                        $s = Section::findOrFail($input["section_id"]);
+                        $s[$input["section_position"]] = $news->id;
+                        $s->save();
+                        $news->section_position = '';
+                    }
+                    if ($input["region_1_position"] != '') {
+                        Log::info('Processing region_1 position:', [$input["region_1_position"]]);
+                        $s = Section::findOrFail($input["region_1_id"]);
+                        $s[$input["region_1_position"]] = $news->id;
+                        $s->save();
+                        $news->region_1_position = '';
+                    }
+                    if ($input["region_2_position"] != '') {
+                        Log::info('Processing region_2 position:', [$input["region_2_position"]]);
+                        $s = Section::findOrFail($input["region_2_id"]);
+                        $s[$input["region_2_position"]] = $news->id;
+                        $s->save();
+                        $news->region_2_position = '';
+                    }
                 }
-                if ($_POST["region_1_position"] != '')
-                {
-                    $s = Section::findOrFail($input["region_1_id"]);
-                    $s[$_POST["region_1_position"]] = $news->id;
-                    $s->save();
-                    $news->region_1_position = '';
-                }
-                if ($_POST["region_2_position"] != '')
-                {
-                    $s = Section::findOrFail($input["region_2_id"]);
-                    $s[$_POST["region_2_position"]] = $news->id;
-                    $s->save();
-                    $news->region_2_position = '';
+
+                // Handle social media posting
+                if (!isset($input['no_social'])) {
+                    Log::info('Processing social media notifications');
+                    try {
+                        @$news->notify(new FacebookPost());
+                        $news->notify(new TwitterPost());
+                        $news->published = true;
+                        $news->save();
+                        Log::info('Social media notifications sent');
+                    } catch (\Exception $e) {
+                        Log::error('Error sending social notifications:', [$e->getMessage()]);
+                    }
+                } else {
+                    Log::info('Skipping social media (no_social flag set)');
                 }
+            }
 
+            if (isset($input['unpublish'])) {
+                Log::info('Processing unpublish action');
+                $news->online = false;
+                $news->save();
             }
-            if (isset($input['no_social']))
-            {
+
+            // Handle homepage position
+            if ($input["homepage_position"] != '' && $news->online) {
+                Log::info('Processing homepage position:', [$input["homepage_position"]]);
+                $home = Home::first();
+                if ($home != null) {
+                    $home->fill([
+                        $input["homepage_position"] => $news->id
+                    ]);
+                    $home->save();
+                    Log::info('Homepage position saved');
+                }
             }
-            else
-            {
-                @$news->notify(new FacebookPost());
-                $news->notify(new TwitterPost());
-                $news->published = true;
-                $news->save();
+
+            // Determine redirect based on action
+            Log::info('=== DETERMINING REDIRECT ===');
+
+            if (isset($input['publish'])) {
+                Log::info('Redirecting after publish to news.index');
+                return redirect()->route('news.index')->with('success', 'News published successfully');
             }
 
-        }
-        if (isset($input['unpublish']))
-        {
-            $news->online = false;
-            $news->save();
-        }
+            if (isset($input['unpublish'])) {
+                Log::info('Redirecting after unpublish to news.index');
+                return redirect()->route('news.index')->with('success', 'News unpublished successfully');
+            }
 
-        if ($_POST["homepage_position"] != '' && $news->online)
-        {
-            $home = Home::first();
-            if ($home != null)
-            {
-                $home->fill([
-                    $_POST["homepage_position"] => $news->id
-                ]);
-                $home->save();
+            if (isset($input['save'])) {
+                Log::info('Redirecting after save to news.edit');
+                return redirect()->route('news.edit', $news->id)->with('success', 'News saved successfully');
             }
-        }
 
-        if (isset($input['publish']))
-            return redirect()->route('news.index')->with('success','News updated successfully');
+            if (isset($input['save_exit'])) {
+                Log::info('Redirecting after save_exit to news.index');
+                return redirect()->route('news.index')->with('success', 'News saved successfully');
+            }
 
-        if (isset($input['unpublish']))
-            return redirect()->route('news.index')->with('success','News updated successfully');
+            Log::info('No specific action, redirecting to news.index');
+            return redirect()->route('news.index')->with('success', 'News created successfully');
+        } catch (\Exception $e) {
+            Log::error('=== ERROR IN STORE METHOD ===');
+            Log::error('Error message:', [$e->getMessage()]);
+            Log::error('Error file:', [$e->getFile()]);
+            Log::error('Error line:', [$e->getLine()]);
+            Log::error('Stack trace:', [$e->getTraceAsString()]);
 
-        if (isset($input['save']))
-        {
-            return redirect()->route('news.edit', $news->id)->with('success','News updated successfully');
-        }
-        if (isset($input['save_exit']))
-        {
-            return redirect()->route('news.index')->with('success','News updated successfully');
+            return redirect()->back()
+                ->withInput()
+                ->with('error', 'An error occurred while saving the news: ' . $e->getMessage());
         }
-
     }
 
     /**
@@ -384,7 +425,7 @@ class NewsController extends Controller
      */
     public function show(News $news)
     {
-        return view('news.show',compact('news'));
+        return view('news.show', compact('news'));
     }
 
     /**
@@ -397,8 +438,7 @@ class NewsController extends Controller
     {
 
         // Aggiorno l'utente che sta guardando la news
-        if ($news->user_id == null)
-        {
+        if ($news->user_id == null) {
             session(['current_news' => $news->id]);
             $news->user_id = Auth::user()->id;
             $news->save();
@@ -410,8 +450,7 @@ class NewsController extends Controller
         $events = Event::orderBy('title')->pluck('title', 'id')->toArray();;
         $pages = Page::where('online', '=', true)->orderBy('title')->pluck('title', 'id')->toArray();;
         $final_date = null;
-        if ($news->date != null)
-        {
+        if ($news->date != null) {
             list($dt, $time) = explode(" ", $news->date);
             list($year, $month, $day) = explode("-", $dt);
             $final_date = $day . "/" . $month . "/" . $year . " " . $time;
@@ -423,8 +462,7 @@ class NewsController extends Controller
         $first = '';
         $aFirst = array();
         $home = Home::first();
-        if ($home != null)
-        {
+        if ($home != null) {
             $pos = '';
             if ($home->slide1 == $news->id)
                 $news->homepage_position = "slide1";
@@ -443,14 +481,11 @@ class NewsController extends Controller
             $home->loadData();
             if (isset($home->slide1) && $home->slide1 != '')
                 $aFirst[] = $home->slide1->title . " (immagine grande)";
-            for($a=1;$a<=5;$a++)
-            {
+            for ($a = 1; $a <= 5; $a++) {
                 if (isset($home["left" . $a]) && $home["left" . $a] != '')
                     $aFirst[] = $home["left" . $a]["title"] . " (slide sinistra)";
-
             }
-            for($a=1;$a<=5;$a++)
-            {
+            for ($a = 1; $a <= 5; $a++) {
                 if (isset($home["right" . $a]) && $home["right" . $a] != '')
                     $aFirst[] = $home["right" . $a]["title"] . " (slide destra)";
             }
@@ -460,7 +495,7 @@ class NewsController extends Controller
 
         $news->date = $final_date;
 
-        return view('news.edit',compact('news', 'sections', 'regions', 'pages', 'events', 'layouts', 'section_position', 'region_1_position', 'region_2_position', 'first'));
+        return view('news.edit', compact('news', 'sections', 'regions', 'pages', 'events', 'layouts', 'section_position', 'region_1_position', 'region_2_position', 'first'));
     }
 
     /**
@@ -472,7 +507,11 @@ class NewsController extends Controller
      */
     public function update(Request $request, News $news)
     {
+        Log::info('=== NEWS UPDATE METHOD START ===');
+        Log::info('News ID:', [$news->id]);
+        Log::info('Request data:', $request->all());
         $request->validate($this->rules);
+        Log::info('Validation passed');
 
         $input = $request->all();
 
@@ -483,8 +522,7 @@ class NewsController extends Controller
         $old_event_id = $news->event_id;
 
         $section_position = '';
-        if ($news->section_id > 0)
-        {
+        if ($news->section_id > 0) {
             if ($news->section->big == $news->id)
                 $section_position = 'big';
             if ($news->section->small1 == $news->id)
@@ -502,12 +540,9 @@ class NewsController extends Controller
 
             if ($section_position == null)
                 $section_position = $news->section_position;
-
-
         }
         $region_1_position = '';
-        if ($news->region_1_id > 0)
-        {
+        if ($news->region_1_id > 0) {
             if ($news->region_1->big == $news->id)
                 $region_1_position = 'big';
             if ($news->region_1->small1 == $news->id)
@@ -525,11 +560,9 @@ class NewsController extends Controller
 
             if ($region_1_position == '')
                 $region_1_position = $news->region_1_position;
-
         }
         $region_2_position = '';
-        if ($news->region_2_id > 0)
-        {
+        if ($news->region_2_id > 0) {
             if ($news->region_2->big == $news->id)
                 $region_2_position = 'big';
             if ($news->region_2->small1 == $news->id)
@@ -547,7 +580,6 @@ class NewsController extends Controller
 
             if ($region_2_position == '')
                 $region_2_position = $news->region_2_position;
-
         }
 
         if ($old_section_id == $input["section_id"] && $section_position == $input["section_position"])
@@ -559,69 +591,62 @@ class NewsController extends Controller
         if ($old_region_2_id == $input["region_2_id"] && $region_2_position == $input["region_2_position"])
             unset($input["region_2_position"]);
 
-        if(request()->image)
-        {
+        if (request()->image) {
+            Log::info('Processing image update');
 
             $file = request()->image;
             $filename  = time() . '_' . $file->getClientOriginalName();
 
-            if (! File::exists(public_path()."/files/news"))
-                File::makeDirectory(public_path()."/files/news");
+            if (! File::exists(public_path() . "/files/news"))
+                File::makeDirectory(public_path() . "/files/news");
 
             $path = public_path('files/news');
 
             request()->image->move($path, $filename);
 
             $input["image"] = $filename;
-
         }
-        for($i=1;$i<=5;$i++)
-        {
-            if(isset($input["image" . $i]))
-            {
+        for ($i = 1; $i <= 5; $i++) {
+            if (isset($input["image" . $i])) {
 
                 $file = $input["image" . $i];
                 $filename  = time() . '_' . $file->getClientOriginalName();
 
-                if (! File::exists(public_path()."/files/news"))
-                    File::makeDirectory(public_path()."/files/news");
+                if (! File::exists(public_path() . "/files/news"))
+                    File::makeDirectory(public_path() . "/files/news");
 
                 $path = public_path('files/news');
 
                 $input["image" . $i]->move($path, $filename);
 
                 $input["image" . $i] = $filename;
-
             }
         }
 
-        if (isset($input["remove_pdf"]))
-        {
+        if (isset($input["remove_pdf"])) {
             $input["pdf"] = '';
         }
-        if(request()->pdf)
-        {
+        if (request()->pdf) {
 
             $file = request()->pdf;
             $filename  = time() . '_' . $file->getClientOriginalName();
 
-            if (! File::exists(public_path()."/files/news"))
-                File::makeDirectory(public_path()."/files/news");
+            if (! File::exists(public_path() . "/files/news"))
+                File::makeDirectory(public_path() . "/files/news");
 
             $path = public_path('files/news');
 
             request()->pdf->move($path, $filename);
 
             $input["pdf"] = $filename;
-
         }
 
         $final_date = null;
-        if ($input["date"] != '')
-        {
+        if ($input["date"] != '') {
             list($dt, $time) = explode(" ", $input["date"]);
             list($day, $month, $year) = explode("/", $dt);
             $final_date = $year . "-" . $month . "-" . $day . " " . $time;
+            Log::info('Date processed for update:', [$input["date"], $final_date]);
         }
         $input["date"] = $final_date;
 
@@ -630,42 +655,36 @@ class NewsController extends Controller
         $input["live"] = isset($input["live"]) ? ($input["live"] == 'on' ? true : false) : false;
         $input["breaking_news"] = isset($input["breaking_news"]) ? ($input["breaking_news"] == 'on' ? true : false) : false;
 
+        Log::info('About to update news record');
         $news->update($input);
+        Log::info('News updated');
 
         $news->user_id = null;
         $news->save();
         $request->session()->forget('current_news');
 
-        if (isset($input['publish']))
-        {
+        if (isset($input['publish'])) {
 
             $news->online = true;
             $news->save();
 
-            if (isset($input['no_social']))
-            {
+            if (isset($input['no_social'])) {
                 // Non pubblico sui social
-            }
-            else
-            {
+            } else {
 
                 $news->published = true;
                 $news->save();
             }
-
         }
-        if (isset($input['unpublish']))
-        {
+        if (isset($input['unpublish'])) {
             $news->online = false;
 
             $news->save();
         }
 
-        if ($_POST["homepage_position"] != '' && $news->online)
-        {
+        if ($_POST["homepage_position"] != '' && $news->online) {
             $home = Home::first();
-            if ($home != null)
-            {
+            if ($home != null) {
                 $home->fill([
                     $_POST["homepage_position"] => $news->id
                 ]);
@@ -673,11 +692,9 @@ class NewsController extends Controller
             }
         }
 
-        if ($news->event_id != $old_event_id)
-        {
+        if ($news->event_id != $old_event_id) {
             $e = Event::where('id', '=', $old_event_id)->first();
-            if ($e)
-            {
+            if ($e) {
                 if ($e->big == $news->id)
                     $e->big = '';
                 if ($e->small1 == $news->id)
@@ -692,28 +709,35 @@ class NewsController extends Controller
             }
         }
 
-        if (isset($input['publish']))
-        {
+        Log::info('=== DETERMINING REDIRECT FOR UPDATE ===');
 
-            return redirect()->route('news.index')->with('success','News updated successfully');
+        if (isset($input['publish'])) {
+            Log::info('Redirecting after publish to news.index');
+            return redirect()->route('news.index')->with('success', 'News published successfully');
         }
-        if (isset($input['crop']))
-        {
+
+        if (isset($input['crop'])) {
+            Log::info('Redirecting to crop page');
             return redirect('/admin/news/crop?news_id=' . $news->id);
         }
-        if (isset($input['unpublish']))
-        {
-            return redirect()->route('news.index')->with('success','News updated successfully');
+
+        if (isset($input['unpublish'])) {
+            Log::info('Redirecting after unpublish to news.index');
+            return redirect()->route('news.index')->with('success', 'News unpublished successfully');
         }
-        if (isset($input['save']))
-        {
-            return redirect()->route('news.edit', $news->id)->with('success','News updated successfully');
+
+        if (isset($input['save'])) {
+            Log::info('Redirecting after save to news.edit');
+            return redirect()->route('news.edit', $news->id)->with('success', 'News updated successfully');
         }
-        if (isset($input['save_exit']))
-        {
-            return redirect()->route('news.index')->with('success','News updated successfully');
+
+        if (isset($input['save_exit'])) {
+            Log::info('Redirecting after save_exit to news.index');
+            return redirect()->route('news.index')->with('success', 'News updated successfully');
         }
 
+        Log::info('No specific action, redirecting to news.edit');
+        return redirect()->route('news.edit', $news->id)->with('success', 'News updated successfully');
     }
 
     /**
@@ -725,24 +749,21 @@ class NewsController extends Controller
     public function destroy(News $news)
     {
         $section = null;
-        if (isset($news->section))
-        {
+        if (isset($news->section)) {
             $section = $news->section;
         }
         $region_1 = null;
-        if (isset($news->region_1))
-        {
+        if (isset($news->region_1)) {
             $region_1 = $news->region_1;
         }
         $region_2 = null;
-        if (isset($news->region_2))
-        {
+        if (isset($news->region_2)) {
             $region_2 = $news->region_2;
         }
 
         $news->delete();
 
         return redirect()->route('news.index')
-                        ->with('success','News deleted successfully');
+            ->with('success', 'News deleted successfully');
     }
 }

+ 9 - 9
resources/views/events_advs/index.blade.php

@@ -9,7 +9,7 @@
 @section('content')
 
     @foreach($aDatas as $idx => $data)
-    <div class="row"> 
+    <div class="row">
     <div class="col-xs-2">
       <h2>{{$idx}}</h2>
      </div>
@@ -49,11 +49,11 @@
                         <a href="{{ route('events.advs.edit', array($event, $adv->id)) }}" type="button" class="btn btn-w-m btn-primary">Modifica</a>
                     </td>
                     <td>
-                      <form class="form-inline" method="POST" action="{{ route('events.advs.destroy', $event, $adv->id) }}">
-    @csrf
-    @method('DELETE')
+                        <form class="form-inline" method="POST" action="{{ route('events.advs.destroy', [$event, $adv->id]) }}">
+                            @csrf
+                            @method('DELETE')
                           <button type="submit" class="btn btn-w-m btn-danger" onclick="return confirm('Sei sicuro?')">Elimina</button>
-                      </form>
+                        </form>
                     </td>
                 	</tr>
                 @endforeach
@@ -67,12 +67,12 @@
      </div>
         @endforeach
 
-        
-        
-      
+
+
+
 
         <div class="col-xs-2" style="margin-top:50px">
-          
+
         <a href="{{ route('events.index') }}" class="btn btn-info">Elenco eventi</a>
       </div>
 @stop

+ 76 - 295
resources/views/news/_form.blade.php

@@ -1,4 +1,4 @@
-{{ csrf_field() }}
+@csrf
 <div class="box box-primary">
     <div class="box-header with-border">
         <h3 class="box-title"></h3>
@@ -208,10 +208,68 @@
                         @endif
                     </div>
                 </div>
-                <!-- Continue with other image inputs... -->
+                <div class="col-md-4">
+                    <div class="form-group">
+                        <label for="image2">Immagine 2:</label><br>
+                        <div class="custom-file-upload">
+                            <input type="file" name="image2" id="image2" class="form-control">
+                        </div>
+                        @if (isset($news) && $news->image2 != '')
+                            <br><img src="/files/news/{{ $news->image2 }}" style="max-width:150px" />
+                        @endif
+                    </div>
+                </div>
+            </div>
+            <div class="row">
+                <div class="col-md-4">
+                    <div class="form-group">
+                        <label for="image3">Immagine 3:</label><br>
+                        <div class="custom-file-upload">
+                            <input type="file" name="image3" id="image3" class="form-control">
+                        </div>
+                        @if (isset($news) && $news->image3 != '')
+                            <br><img src="/files/news/{{ $news->image3 }}" style="max-width:150px" />
+                        @endif
+                    </div>
+                </div>
+                <div class="col-md-4">
+                    <div class="form-group">
+                        <label for="image4">Immagine 4:</label><br>
+                        <div class="custom-file-upload">
+                            <input type="file" name="image4" id="image4" class="form-control">
+                        </div>
+                        @if (isset($news) && $news->image4 != '')
+                            <br><img src="/files/news/{{ $news->image4 }}" style="max-width:150px" />
+                        @endif
+                    </div>
+                </div>
+                <div class="col-md-4">
+                    <div class="form-group">
+                        <label for="image5">Immagine 5:</label><br>
+                        <div class="custom-file-upload">
+                            <input type="file" name="image5" id="image5" class="form-control">
+                        </div>
+                        @if (isset($news) && $news->image5 != '')
+                            <br><img src="/files/news/{{ $news->image5 }}" style="max-width:150px" />
+                        @endif
+                    </div>
+                </div>
+            </div>
+            <div class="row">
+                <div class="col-md-6">
+                    <div class="form-group">
+                        <label for="pdf">PDF:</label><br>
+                        <div class="custom-file-upload">
+                            <input type="file" name="pdf" id="pdf" class="form-control">
+                        </div>
+                        @if (isset($news) && $news->pdf != '')
+                            <br><a href="/files/news/{{ $news->pdf }}" target="_blank">{{ $news->pdf }}</a>
+                            <br><input type="checkbox" name="remove_pdf" value="1"> Rimuovi PDF
+                        @endif
+                    </div>
+                </div>
             </div>
         @endif
-        <!-- No social checkbox -->
         <div class="row">
             <div class="col-md-12">
                 <div class="form-group">
@@ -220,299 +278,22 @@
                 </div>
             </div>
         </div>
-        <!-- Submit buttons -->
-        <div class="box-footer">
-            @if(isset($news) && $news->user_id > 0 && $news->user_id != Auth::user()->id)
-                <span style="color:red; font-weight:bold">ATTENZIONE : l'utente {{ $news->user->name }} sta modificando questa news</span><br><br>
-            @endif
-            <button type="submit" class="btn btn-success saved" name="save">{{ $submit_text }}</button>
-            <button type="submit" class="btn btn-success saved" name="save_exit">Salva ed esci</button>
-            @if(isset($news))
-                @if(!$news->online)
-                    <button type="submit" class="btn btn-success saved" name="publish">Pubblica</button>
-                @else
-                    <button type="submit" class="btn btn-success saved" name="unpublish">Torna bozza</button>
-                @endif
+    </div>
+    <div class="box-footer">
+        @if(isset($news) && $news->user_id > 0 && $news->user_id != Auth::user()->id)
+            <span style="color:red; font-weight:bold">ATTENZIONE : l'utente {{ $news->user->name }} sta modificando questa news</span><br><br>
+        @endif
+        <button type="submit" class="btn btn-success saved" name="save" value="1">{{ $submit_text }}</button>
+        <button type="submit" class="btn btn-success saved" name="save_exit" value="1">Salva ed esci</button>
+        @if(isset($news))
+            @if(!$news->online)
+                <button type="submit" class="btn btn-success saved" name="publish" value="1">Pubblica</button>
             @else
-                <button type="submit" class="btn btn-success saved" name="publish">Pubblica</button>
+                <button type="submit" class="btn btn-success saved" name="unpublish" value="1">Torna bozza</button>
             @endif
-            <a href="{{ route('news.index') }}" class="btn btn-info">Annulla</a>
-        </div>
+        @else
+            <button type="submit" class="btn btn-success saved" name="publish" value="1">Pubblica</button>
+        @endif
+        <a href="{{ route('news.index') }}" class="btn btn-info">Annulla</a>
     </div>
 </div>
-
-@section('extra_css')
-
-    <link rel="stylesheet" href="/backend/plugins/daterangepicker/daterangepicker.css">
-
-@stop
-
-@section('extra_js')
-
-    <script src="/backend/plugins/input-mask/jquery.inputmask.js"></script>
-    <script src="/backend/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
-    <script src="/backend/plugins/input-mask/jquery.inputmask.extensions.js"></script>
-
-    <script src="/backend/plugins/moment/moment.min.js"></script>
-    <script src="/backend/plugins/daterangepicker/daterangepicker.js"></script>
-
-    <script>
-
-        $(function () {
-
-            $('form').on('submit', function(e){
-                if($("#page_id").val() == '')
-                {
-                    if (!confirm("Attenzione, stai salvando una news senza pagina web, confermi?"))
-                    {
-                        e.preventDefault();
-                    }
-                }
-                else
-                {
-                    $(".saved").click(function(){
-                        $(".saved").each(function(){
-                            $(this).hide();
-                        });
-                    });
-                }
-            });
-
-            var layouts = [];
-            @foreach($layouts as $i => $l)
-                layouts[{{$i}}] = '{{$l}}';
-            @endforeach
-
-            $('.js-editor').summernote({
-                height: 300,
-                lang: 'it-IT'
-            });
-
-            $("[name='date']").daterangepicker({ singleDatePicker: true, timePicker: true, timePicker24Hour: true, locale: { format: 'DD/MM/YYYY HH:mm' }})
-
-            @if(!isset($news))
-                $(".title").keyup(function(){
-                    var Text = $(this).val();
-                    Text = Text.toLowerCase();
-                    Text = Text.replace(/[^a-zA-Z0-9]+/g,'-');
-                    $(".slug").val(Text);
-                });
-            @endif
-
-            $('.title').on("keyup change", function () {
-
-                const max = 100;
-                const len = $(this).val().length;
-
-                if (len >= max)
-                {
-                $('#chars').text("0 caratteri rimanenti");
-                }
-                else
-                {
-
-                  const char = max - len;
-                  $('#chars').text(char + '  caratteri rimanenti');
-                }
-              });
-
-              $('.title_region_1').on("keyup change", function () {
-
-                const max = 100;
-                const len = $(this).val().length;
-
-                if (len >= max)
-                {
-                $('#chars_region_1').text("0 caratteri rimanenti");
-                }
-                else
-                {
-
-                  const char = max - len;
-                  $('#chars_region_1').text(char + '  caratteri rimanenti');
-                }
-              });
-
-              $('.title_region_2').on("keyup change", function () {
-
-                const max = 100;
-                const len = $(this).val().length;
-
-                if (len >= max)
-                {
-                $('#chars_region_2').text("0 caratteri rimanenti");
-                }
-                else
-                {
-
-                  const char = max - len;
-                  $('#chars_region_2').text(char + '  caratteri rimanenti');
-                }
-              });
-
-              $(".section_id_change").change(function(){
-                var layout = layouts[this.value];
-                loadLayoutSection(layout, 'section');
-                $("#section_position").val('');
-              });
-
-              $(".region_1_id_change").change(function(){
-                  if(this.value != "" && this.value == $(".region_2_id_change").val())
-                  {
-                      alert('Attenzione, la regione selezionata è già associata a REGIONE2');
-                      $(".region_1_id_change").val('');
-                      loadLayoutSection('', 'region_1');
-                      $("#region_1_position").val('');
-                  }
-                  else
-                  {
-                    var layout = layouts[this.value];
-                    loadLayoutSection(layout, 'region_1');
-                    $("#region_1_position").val('');
-                  }
-              });
-
-              $(".region_2_id_change").change(function(){
-                if(this.value != "" && this.value == $(".region_1_id_change").val())
-                {
-                    alert('Attenzione, la regione selezionata è già associata a REGIONE1');
-                    $(".region_2_id_change").val('');
-                    loadLayoutSection('', 'region_2');
-                    $("#region_2_position").val('');
-                }
-                else
-                {
-                    var layout = layouts[this.value];
-                    loadLayoutSection(layout, 'region_2');
-                    $("#region_2_position").val('');
-                }
-              });
-
-              $(document). on("click", ".btSelect" , function() {
-                var where = $(this).attr('data-where');
-                $(".boxLayout." + where).attr('style', 'border:1px solid gray; padding:10px;background-color: white !important');
-                $(this).parent().attr('style', 'border:1px solid gray; padding:10px;background-color: red !important');
-                $("#" + where + "_position").val($(this).attr('data-position'));
-              });
-
-            @if(isset($news))
-                @if(($news->section_id > 0 && $news->section_position != '') || (!$news->online && $news->section_id > 0))
-                    var layout = layouts[{{$news->section_id}}];
-                    loadLayoutSection(layout, 'section');
-                @endif
-                @if(($news->region_1_id > 0 && $news->region_1_position != '') || (!$news->online && $news->region_1_id > 0))
-                    var layout = layouts[{{$news->region_1_id}}];
-                    loadLayoutSection(layout, 'region_1');
-                @endif
-                @if(($news->region_2_id > 0 && $news->region_2_position != '') || (!$news->online && $news->region_2_id > 0))
-                    var layout = layouts[{{$news->region_2_id}}];
-                    loadLayoutSection(layout, 'region_2');
-                @endif
-            @endif
-
-            @if($section_position != '')
-                $( "input[data-where='section'][data-position='{{$section_position}}']" ).parent().attr('style', 'border:1px solid gray; padding:10px;background-color: red !important');
-            @endif
-            @if($region_1_position != '')
-                $( "input[data-where='region_1'][data-position='{{$region_1_position}}']" ).parent().attr('style', 'border:1px solid gray; padding:10px;background-color: red !important');
-            @endif
-            @if($region_2_position != '')
-                $( "input[data-where='region_2'][data-position='{{$region_2_position}}']" ).parent().attr('style', 'border:1px solid gray; padding:10px;background-color: red !important');
-            @endif
-
-        });
-
-        function loadLayoutSection(layout, position)
-        {
-
-            if (layout != '')
-            {
-
-                var html = '<div class="col-md-10" style="margin-left:20px;margin-right:20px">';
-
-                if (layout == 'layout_1')
-                {
-                    html += '<div class="row"><div class="col-md-12 text-center boxLayout ' + position + '" style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="big" value="SEL."></div></div>';
-                    html += '<div class="row">';
-                        html += '<div class="col-md-4 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small1" value="SEL."></div>';
-                        html += '<div class="col-md-4 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small2" value="SEL."></div>';
-                        html += '<div class="col-md-4 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small3" value="SEL."></div>';
-                    html += '</div>';
-                }
-                if (layout == 'layout_2')
-                {
-                    html += '<div class="row"><div class="col-md-12 text-center boxLayout ' + position + '" style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="big" value="SEL."></div></div>';
-                    html += '<div class="row">';
-                        html += '<div class="col-md-4 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small1" value="SEL."></div>';
-                        html += '<div class="col-md-4 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small2" value="SEL."></div>';
-                        html += '<div class="col-md-4 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small3" value="SEL."></div>';
-                    html += '</div>';
-                }
-                if (layout == 'layout_3')
-                {
-                    html += '<div class="row"><div class="col-md-12 text-center boxLayout ' + position + '" style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="big" value="SEL."></div></div>';
-                    html += '<div class="row">';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small1" value="SEL."></div>';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small2" value="SEL."></div>';
-                    html += '</div>';
-                    html += '<div class="row">';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small3" value="SEL."></div>';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small4" value="SEL."></div>';
-                    html += '</div>';
-                }
-                if (layout == 'layout_4')
-                {
-                    html += '<div class="row"><div class="col-md-12 text-center boxLayout ' + position + '" style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="big" value="SEL."></div></div>';
-                    html += '<div class="row">';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small1" value="SEL."></div>';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small2" value="SEL."></div>';
-                    html += '</div>';
-                    html += '<div class="row">';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small3" value="SEL."></div>';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small4" value="SEL."></div>';
-                    html += '</div>';
-                    html += '<div class="row">';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small5" value="SEL."></div>';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small6" value="SEL."></div>';
-                    html += '</div>';
-                }
-                if (layout == 'layout_5')
-                {
-                    html += '<div class="row"><div class="col-md-12 text-center boxLayout ' + position + '" style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="big" value="SEL."></div></div>';
-                    html += '<div class="row">';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small1" value="SEL."></div>';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small2" value="SEL."></div>';
-                    html += '</div>';
-                    html += '<div class="row">';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small3" value="SEL."></div>';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small4" value="SEL."></div>';
-                    html += '</div>';
-                }
-                if (layout == 'layout_6')
-                {
-                    html += '<div class="row">';
-                        html += '<div class="col-md-6 text-center boxLayout ' + position + '" style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="big" value="SEL."></div>';
-                        html += '<div class="col-md-6">';
-                            html += '<div class="col-md-12 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small1" value="SEL."></div>';
-                            html += '<div class="col-md-12 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small2" value="SEL."></div>';
-                            html += '<div class="col-md-12 text-center boxLayout ' + position + '"  style="border:1px solid gray; padding:10px;"><input type="button" class="btSelect" data-where="' + position + '" data-position="small3" value="SEL."></div>';
-                        html += '</div>';
-                    html += '</div>';
-                }
-
-                html += "</div>";
-
-                $("#layout_" + position).html(html);
-                $("#layout_" + position).show();
-
-            }
-            else
-            {
-                $("#layout_" + position).html('');
-            }
-
-
-        }
-
-    </script>
-@stop

+ 1 - 1
resources/views/news/create.blade.php

@@ -11,7 +11,7 @@
 	<div class="row">
         <div class="col-lg-12">
             <form method="POST" action="{{ route('news.store') }}" enctype="multipart/form-data" autocomplete="off">
-    @csrf
+                @csrf
                 @include('news/_form', ['submit_text' => 'Salva'])
             </form>
         </div>

+ 1 - 1
resources/views/pages_advs/create.blade.php

@@ -10,7 +10,7 @@
 
 	<div class="row">
         <div class="col-lg-12">
-            <form method="POST" action="{{ route('pages.advs.store') }}" enctype="multipart/form-data" autocomplete="off">
+<form method="POST" action="{{ route('pages.advs.store', $page) }}" enctype="multipart/form-data" autocomplete="off">
     @csrf
                 @include('pages_advs/_form', ['submit_text' => 'Salva'])
             </form>

+ 70 - 85
resources/views/pages_advs/index.blade.php

@@ -1,110 +1,95 @@
 @extends('layouts.admin')
 
 @section('title')
-
   Pubblicità Pagina {{$page->name}}
-
 @stop
 
 @section('content')
 
-    @foreach($aDatas as $idx => $data)
-    <div class="row"> 
+@foreach($aDatas as $idx => $data)
+  <div class="row">
     <div class="col-xs-2">
       <h2>{{$idx}}</h2>
-     </div>
-     <div class="col-xs-10 text-right">
+    </div>
+    <div class="col-xs-10 text-right">
       <br><a href="{{ route('pages.advs.create', $page) }}?position={{$idx}}" class="btn btn-success">Aggiungi</a>
-     </div>
     </div>
-    <div class="row">
-     <div class="col-xs-2">
-       <img src="/images/{{str_replace(" ", "", $idx)}}.png" style="max-width:180px">
-     </div>
-     <div class="col-xs-10">
-	      <div class="col-xs-12">
-          <div class="box">
-
-            <div class="box-body table-responsive no-padding">
-              <table class="table table-striped table-hover">
-                <tr>
-                  <th>Nome</th>
-                  <th>Google</th>
-                  <th>Immagine</th>
-                  <th>Online</th>
-                  <th width="50"></th>
-                  <th width="50"></th>
+  </div>
+  <div class="row">
+    <div class="col-xs-2">
+      <img src="/images/{{str_replace(" ", "", $idx)}}.png" style="max-width:180px">
+    </div>
+    <div class="col-xs-10">
+      <div class="col-xs-12">
+        <div class="box">
+          <div class="box-body table-responsive no-padding">
+            <table class="table table-striped table-hover">
+              <tr>
+                <th>Nome</th>
+                <th>Google</th>
+                <th>Immagine</th>
+                <th>Online</th>
+                <th width="50"></th>
+                <th width="50"></th>
+              </tr>
+              <tbody>
+              @foreach($data as $adv)
+                <tr class="adv_row" data-id="{{$adv->id}}" style="cursor:move">
+                  <td>{{$adv->name}}</td>
+                  <td>{{$adv->google_code}}</td>
+                  <td>
+                    @if($adv->image != '')
+                      <img src="/files/adv/{{$adv->image}}" style="max-width:250px" />
+                    @endif
+                  </td>
+                  <td>{{$adv->online ? 'Si' : 'No'}}</td>
+                  <td>
+                      <a href="{{ route('pages.advs.edit', array($page, $adv->id)) }}" type="button" class="btn btn-w-m btn-primary">Modifica</a>
+                  </td>
+                  <td>
+                    <form class="form-inline" method="POST" action="{{ route('pages.advs.destroy', [$page, $adv]) }}">
+                        @csrf
+                        @method('DELETE')
+                        <button type="submit" class="btn btn-w-m btn-danger" onclick="return confirm('Sei sicuro?')">Elimina</button>
+                    </form>
+                  </td>
                 </tr>
-                <tbody>
-                @foreach($data as $adv)
-                  <tr class="adv_row" data-id="{{$adv->id}}" style="cursor:move">
-                    <td>{{$adv->name}}</td>
-                    <td>{{$adv->google_code}}</td>
-                    <td>
-                      @if($adv->image != '')
-                        <img src="/files/adv/{{$adv->image}}" style="max-width:250px" />
-                      @endif
-                    </td>
-                    <td>{{$adv->online ? 'Si' : 'No'}}</td>
-                    <td>
-                        <a href="{{ route('pages.advs.edit', array($page, $adv->id)) }}" type="button" class="btn btn-w-m btn-primary">Modifica</a>
-                    </td>
-                    <td>
-                      {!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('pages.advs.destroy', array($page, $adv)))) !!}
-                          <button type="submit" class="btn btn-w-m btn-danger" onclick="return confirm('Sei sicuro?')">Elimina</button>
-                      </form>
-                    </td>
-                	</tr>
-                @endforeach
-                </tbody>
-              </table>
-            </div>
-
+              @endforeach
+              </tbody>
+            </table>
           </div>
-
         </div>
       </div>
-     </div>
-        @endforeach
+    </div>
+  </div>
+@endforeach
 
-        
-        
-      
+<div class="col-xs-2" style="margin-top:50px">
+  <a href="{{ route('pages.index') }}" class="btn btn-info">Elenco pagine</a>
+</div>
 
-        <div class="col-xs-2" style="margin-top:50px">
-          
-        <a href="{{ route('pages.index') }}" class="btn btn-info">Elenco pagine</a>
-      </div>
 @stop
 
 @section('extra_js')
-
 <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
 
-
-    <script>
-        
-        $(function () {
-
-          $('tbody').sortable({
-            cursor: "move",
-            stop: function( ) {
-                var ids = '';
-                $(".adv_row").each(function()
-                {
-                  var id = $(this).attr("data-id");
-                  ids += (ids != '' ? ',' : '') + id;
-                });
-                $.ajax('/admin/adv/sort/' + ids,
-                    {
-                      success: function (data, status, xhr) {// success callback function
-                            $('p').append(data);
-                      }
-                });
-            }
+<script>
+  $(function () {
+    $('tbody').sortable({
+      cursor: "move",
+      stop: function( ) {
+        var ids = '';
+        $(".adv_row").each(function() {
+          var id = $(this).attr("data-id");
+          ids += (ids != '' ? ',' : '') + id;
         });
-            
+        $.ajax('/admin/adv/sort/' + ids, {
+          success: function (data, status, xhr) {
+            $('p').append(data);
+          }
         });
-
-    </script>
-@stop
+      }
+    });
+  });
+</script>
+@stop

+ 21 - 22
resources/views/users/_form.blade.php

@@ -1,55 +1,54 @@
-{{ csrf_field() }}
 <div class="box box-primary">
     <div class="box-header with-border">
         <h3 class="box-title"></h3>
     </div>
-
     <div class="box-body">
         <div class="row">
-            <div class="col-md-12">
+            <div class="col-md-6">
                 <div class="form-group">
                     <label for="name">Nome:</label>
-                    <input type="text" name="name" class="form-control" value="{{ old('name') }}">
-                </div>                
+                    <input type="text" name="name" class="form-control" value="{{ old('name', $user->name ?? '') }}">
+                </div>
             </div>
         </div>
         <div class="row">
-            <div class="col-md-12">
+            <div class="col-md-6">
                 <div class="form-group">
                     <label for="email">Email:</label>
-                    <input type="text" name="email" class="form-control" value="{{ old('email') }}">
-                </div>                
+                    <input type="text" name="email" class="form-control" value="{{ old('email', $user->email ?? '') }}">
+                </div>
             </div>
         </div>
         <div class="row">
-            <div class="col-md-12">
+            <div class="col-md-6">
                 <div class="form-group">
                     <label for="password">Password:</label> (lasciare vuoto per non cambiarla)
-                    <input type="text" name="password" class="form-control" value="{{ old('password', '') }}">
-                </div>                
+                    <input type="text" name="password" value="" class="form-control">
+                </div>
             </div>
         </div>
         <div class="row">
             <div class="col-md-6">
                 <div class="form-group">
                     <label for="level">Livello:</label>
-                    {!! Form::select('level', [0 => 'Amministratore', 1 => 'Autore'] , null, array('class' => 'form-control')) !!}
-                </div>                
+                    <select name="level" class="form-control">
+                        <option value="0" {{ old('level', $user->level ?? '') == '0' ? 'selected' : '' }}>Amministratore</option>
+                        <option value="1" {{ old('level', $user->level ?? '') == '1' ? 'selected' : '' }}>Autore</option>
+                    </select>
+                </div>
             </div>
+        </div>
+        <div class="row">
             <div class="col-md-6">
                 <div class="form-group">
                     <label for="disabled">Disabilitato:</label><br>
-                    <input type="checkbox" name="disabled" value="on" {{ old('disabled') ? 'checked' : '' }}>
-                </div>                
+                    <input type="checkbox" name="disabled" value="on" {{ old('disabled', $user->disabled ?? '') == 'on' ? 'checked' : '' }}>
+                </div>
             </div>
-        </div>   
-
+        </div>
     </div>
-
     <div class="box-footer">
-        @if(Auth::user()->only_read == false)
-            <button type="submit" class="btn btn-success">{{ $submit_text }}</button>
-        @endif
+        <button type="submit" class="btn btn-success">{{ $submit_text }}</button>
         <a href="{{ route('users.index') }}" class="btn btn-info">Annulla</a>
     </div>
-</div>
+</div>