@@ -20,43 +20,75 @@ class ConfigurationsController extends Controller
2020 public function index ()
2121 {
2222 $ configurations = Configuration::all ();
23- $ configurations_by_sections = ['init ' => [], 'email ' => [], 'tickets ' => [], 'perms ' => [], 'editor ' => [], 'other ' => []];
24- $ init_section = ['main_route ' , 'main_route_path ' , 'admin_route ' , 'admin_route_path ' , 'master_template ' , 'member_model_class ' , 'routes ' ];
25- $ email_section = ['status_notification ' , 'comment_notification ' , 'queue_emails ' , 'assigned_notification ' ,
23+ $ configurations_by_sections = ['init ' => [], 'table ' => [], 'features ' => [], 'email ' => [], 'tickets ' => [], 'perms ' => [], 'editor ' => [], 'other ' => []];
24+ $ init_section = ['main_route ' , 'main_route_path ' , 'admin_route ' , 'admin_route_path ' , 'master_template ' , 'member_model_class ' , 'routes ' , 'include_font_awesome ' , 'user_route ' , 'admin_button_text ' ];
25+ $ table_section = ['subject_content_column ' , 'list_text_max_length ' , 'check_last_update_seconds ' , 'length_menu ' , 'max_agent_buttons ' , 'calendar_month_filter ' , 'paginate_items ' ];
26+ $ features_section = ['departments_feature ' , 'departments_notices_feature ' , 'ticket_attachments_feature ' ];
27+ $ email_section = ['status_notification ' , 'comment_notification ' , 'queue_emails ' , 'assigned_notification ' ,
2628 'list_owner_notification ' , 'status_owner_notification ' ,
2729 'email.template ' , 'email.owner.newticket.template ' , 'email.header ' , 'email.signoff ' , 'email.signature ' , 'email.dashboard ' ,
2830 'email.google_plus_link ' , 'email.facebook_link ' , 'email.twitter_link ' , 'email.footer ' , 'email.footer_link ' ,
2931 'email.color_body_bg ' , 'email.color_header_bg ' , 'email.color_content_bg ' , 'email.color_footer_bg ' ,
3032 'email.color_button_bg ' , 'email.account.name ' , 'email.account.mailbox ' , 'custom_recipients ' ];
3133 $ tickets_section = ['default_priority_id ' , 'default_status_id ' , 'default_close_status_id ' , 'default_reopen_status_id ' ,
32- 'subject_content_column ' , ' paginate_items ' , ' attachments_ticket_max_size ' , 'attachments_ticket_max_files_num ' , 'attachments_mimes ' ,
33- 'attachments_path ' , 'thumbnails_path ' , 'oldest_year ' , 'user_route ' , ' html_replacements ' , 'list_text_max_length ' , 'use_default_status_id ' , 'check_last_update_seconds ' ];
34+ 'attachments_ticket_max_size ' , 'attachments_ticket_max_files_num ' , 'attachments_mimes ' ,
35+ 'attachments_path ' , 'thumbnails_path ' , 'oldest_year ' , 'html_replacements ' , 'use_default_status_id ' , 'delete_modal_type ' , 'new_ticket_autoassign ' ];
3436 $ perms_section = ['agent_restrict ' , 'close_ticket_perm ' , 'reopen_ticket_perm ' ];
3537 $ editor_section = ['editor_enabled ' , 'editor_html_highlighter ' , 'codemirror_theme ' ,
3638 'summernote_locale ' , 'summernote_options_json_file ' , 'summernote_options_user ' , 'purifier_config ' , ];
3739
40+ $ last_configuration = session ()->has ('last_configuration ' ) ? session ('last_configuration ' ) : '' ;
41+
3842 // Split them into configurations sections for tabs
3943 foreach ($ configurations as $ config_item ) {
4044 //trim long values (ex serialised arrays)
4145 $ config_item ->value = $ config_item ->getShortContent (25 , 'value ' );
4246 $ config_item ->default = $ config_item ->getShortContent (25 , 'default ' );
4347
4448 if (in_array ($ config_item ->slug , $ init_section )) {
45- $ configurations_by_sections ['init ' ][] = $ config_item ;
49+ $ section = 'init ' ;
50+
51+ } elseif (in_array ($ config_item ->slug , $ table_section )) {
52+ $ section = 'table ' ;
53+
54+ } elseif (in_array ($ config_item ->slug , $ features_section )) {
55+ $ section = 'features ' ;
56+
4657 } elseif (in_array ($ config_item ->slug , $ email_section )) {
47- $ configurations_by_sections ['email ' ][] = $ config_item ;
58+ $ section = 'email ' ;
59+
4860 } elseif (in_array ($ config_item ->slug , $ tickets_section )) {
49- $ configurations_by_sections ['tickets ' ][] = $ config_item ;
61+ $ section = 'tickets ' ;
62+
5063 } elseif (in_array ($ config_item ->slug , $ perms_section )) {
51- $ configurations_by_sections ['perms ' ][] = $ config_item ;
64+ $ section = 'perms ' ;
65+
5266 } elseif (in_array ($ config_item ->slug , $ editor_section )) {
53- $ configurations_by_sections ['editor ' ][] = $ config_item ;
67+ $ section = 'editor ' ;
68+
5469 } else {
55- $ configurations_by_sections ['other ' ][] = $ config_item ;
70+ $ section = 'other ' ;
71+ }
72+
73+ // Add item to its section array
74+ $ configurations_by_sections [$ section ][] = $ config_item ;
75+
76+ // If list is loaded after configuration update or delete, open it's related tab
77+ if ($ config_item ->slug == $ last_configuration ){
78+ $ last_tab = $ section ;
5679 }
5780 }
5881
59- return view ('panichd::admin.configuration.index ' , compact ('configurations ' , 'configurations_by_sections ' ));
82+
83+ if (session ()->has ('last_configuration ' ) and !isset ($ last_tab )){
84+ // If last configuration is not listed, has to belong to tab "other"
85+ $ last_tab = "other " ;
86+ }
87+
88+ // Default tab
89+ if (!isset ($ last_tab )) $ last_tab = "init " ;
90+
91+ return view ('panichd::admin.configuration.index ' , compact ('configurations ' , 'configurations_by_sections ' , 'last_tab ' ));
6092 }
6193
6294 /**
@@ -69,73 +101,103 @@ public function create()
69101 return view ('panichd::admin.configuration.create ' );
70102 }
71103
104+ /**
105+ * Store a newly created Configuration in storage.
106+ *
107+ * @param Request $request
108+ *
109+ * @return \Illuminate\Http\RedirectResponse
110+ */
111+ public function store (Request $ request )
112+ {
113+ $ input = $ request ->all ();
114+
115+ $ configuration = new Configuration ();
116+ $ configuration ->create ($ input );
117+
118+ Session::flash ('status ' , 'Setting saved successfully. ' );
119+ \Cache::forget ('panichd::settings ' ); // refresh cached settings
120+ return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
121+ }
122+
123+ /**
124+ * Show the form for editing the specified Configuration.
125+ *
126+ * @param int $id
127+ *
128+ * @return Response
129+ */
130+ public function edit ($ id )
131+ {
132+ $ configuration = Configuration::findOrFail ($ id );
133+ $ should_serialize = Setting::is_serialized ($ configuration ->value );
134+ $ default_serialized = Setting::is_serialized ($ configuration ->default );
135+
136+ return view ('panichd::admin.configuration.edit ' , compact ('configuration ' , 'should_serialize ' , 'default_serialized ' ));
137+ }
72138
73- /**
74- * Store a newly created Configuration in storage.
75- *
76- * @param Request $request
77- *
78- * @return \Illuminate\Http\RedirectResponse
79- */
80- public function store (Request $ request )
81- {
82- $ input = $ request ->all ();
83-
84- $ configuration = new Configuration ();
85- $ configuration ->create ($ input );
86-
87- Session::flash ('configuration ' , 'Setting saved successfully. ' );
88- \Cache::forget ('panichd::settings ' ); // refresh cached settings
89- return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
90- }
91-
92- /**
93- * Show the form for editing the specified Configuration.
94- *
95- * @param int $id
96- *
97- * @return Response
98- */
99- public function edit ($ id )
100- {
101- $ configuration = Configuration::findOrFail ($ id );
102- $ should_serialize = Setting::is_serialized ($ configuration ->value );
103- $ default_serialized = Setting::is_serialized ($ configuration ->default );
104-
105- return view ('panichd::admin.configuration.edit ' , compact ('configuration ' , 'should_serialize ' , 'default_serialized ' ));
106- }
107-
108- /**
109- * Update the specified Configuration in storage.
110- *
111- * @param int $id
112- * @param Request $request
113- *
114- * @return $this|\Illuminate\Http\RedirectResponse
115- */
116- public function update (Request $ request , $ id )
117- {
118- $ configuration = Configuration::findOrFail ($ id );
119-
120- $ value = $ request ->value ;
121-
122- if ($ request ->serialize ) {
123- //if(!Hash::check($request->password, auth()->user()->password)){
124- if (!Auth::attempt ($ request ->only ('password ' ), false , false )) {
125- return back ()->withErrors ([trans ('panichd::admin.config-edit-auth-failed ' )]);
126- }
127- if (false === eval ('$value = serialize( ' .$ value .'); ' )) {
128- return back ()->withErrors ([trans ('panichd::admin.config-edit-eval-error ' )]);
129- }
130- }
131-
132- $ configuration ->update (['value ' => $ value , 'lang ' => $ request ->lang ]);
133-
134- Session::flash ('configuration ' , trans ('panichd::admin.config-update-confirm ' , ['name ' => $ request ->name ]));
135- // refresh cached settings
136- \Cache::forget ('panichd::settings ' );
137- \Cache::forget ('panichd::settings. ' .$ configuration ->slug );
138-
139- return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
140- }
139+ /**
140+ * Update the specified Configuration in storage.
141+ *
142+ * @param int $id
143+ * @param Request $request
144+ *
145+ * @return $this|\Illuminate\Http\RedirectResponse
146+ */
147+ public function update (Request $ request , $ id )
148+ {
149+ $ configuration = Configuration::findOrFail ($ id );
150+
151+ $ value = $ request ->value ;
152+
153+ if ($ request ->serialize ) {
154+ //if(!Hash::check($request->password, auth()->user()->password)){
155+ if (!Auth::attempt ($ request ->only ('password ' ), false , false )) {
156+ return back ()->withErrors ([trans ('panichd::admin.config-edit-auth-failed ' )]);
157+ }
158+ if (false === eval ('$value = serialize( ' .$ value .'); ' )) {
159+ return back ()->withErrors ([trans ('panichd::admin.config-edit-eval-error ' )]);
160+ }
161+ }
162+
163+ $ configuration ->update (['value ' => $ value , 'lang ' => $ request ->lang ]);
164+
165+ Session::flash ('status ' , trans ('panichd::admin.config-update-confirm ' , ['name ' => $ configuration ->slug ]));
166+ // refresh cached settings
167+ \Cache::forget ('panichd::settings ' );
168+ \Cache::forget ('panichd::settings. ' .$ configuration ->slug );
169+
170+ // Pass configuration slug to open it's tab
171+ Session::flash ('last_configuration ' , $ configuration ->slug );
172+
173+ return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
174+ }
175+
176+ /**
177+ * Update the specified Configuration in storage.
178+ *
179+ * @param int $id
180+ * @param Request $request
181+ *
182+ * @return $this|\Illuminate\Http\RedirectResponse
183+ */
184+ public function destroy (Request $ request , $ id )
185+ {
186+ $ configuration = Configuration::findOrFail ($ id );
187+ $ clone = clone $ configuration ;
188+
189+ $ value = $ request ->value ;
190+
191+ $ configuration ->delete ();
192+
193+ Session::flash ('status ' , trans ('panichd::admin.config-delete-confirm ' , ['name ' => $ clone ->slug ]));
194+ // refresh cached settings
195+ \Cache::forget ('panichd::settings ' );
196+ \Cache::forget ('panichd::settings. ' .$ clone ->slug );
197+
198+ // Pass configuration slug to open it's tab
199+ Session::flash ('last_configuration ' , $ clone ->slug );
200+
201+ return redirect ()->action ('\PanicHD\PanicHD\Controllers\ConfigurationsController@index ' );
202+ }
141203}
0 commit comments