@@ -85,24 +85,27 @@ function _connect() {
8585 * handle profile saving/deleting
8686 */
8787 function handle () {
88- if (isset ($ _REQUEST ['prf ' ]) && is_array ($ _REQUEST ['prf ' ])) {
89- if (isset ($ _REQUEST ['sync__delete ' ]) && $ this ->profno !== false ) {
90- // delete profile
91- unset($ this ->profiles [$ this ->profno ]);
92- $ this ->profiles = array_values ($ this ->profiles ); //reindex
93- $ this ->profno = '' ;
88+ global $ INPUT ;
89+
90+ $ profile = $ INPUT ->arr ('prf ' );
91+ if (!$ profile ) return ;
92+
93+ if (!checkSecurityToken ()) return ;
94+
95+ try {
96+ if ($ INPUT ->has ('sync__delete ' ) && $ this ->profno !== false ) {
97+ // profile deletion
98+ $ this ->profileManager ->deleteProfileConfig ($ this ->profno );
99+ $ this ->profno = false ;
100+ $ INPUT ->remove ('prf ' );
101+ msg ('profile deleted ' , 1 );
94102 } else {
95- // add/edit profile
96- if ($ this ->profno === '' ) $ this ->profno = count ($ this ->profiles );
97- if (!isset ($ _REQUEST ['prf ' ]['timeout ' ]) || !is_numeric ($ _REQUEST ['prf ' ]['timeout ' ])) {
98- $ _REQUEST ['prf ' ]['timeout ' ] = $ this ->defaultTimeout ;
99- }
100- $ this ->profiles [$ this ->profno ] = $ _REQUEST ['prf ' ];
103+ // profile add/edit
104+ $ this ->profno = $ this ->profileManager ->setProfileConfig ($ this ->profno , $ profile );
105+ msg ('profile saved ' , 1 );
101106 }
102- $ this ->_profileSave ();
103-
104- // reset the client
105- $ this ->client = null ;
107+ } catch (\dokuwiki \plugin \sync \SyncException $ e ) {
108+ msg (hsc ($ e ->getMessage ()), -1 );
106109 }
107110 }
108111
@@ -211,7 +214,7 @@ protected function profileDropdown() {
211214 $ profiles ['' ] = $ this ->getLang ('newprofile ' );
212215
213216 $ form ->addFieldsetOpen ($ this ->getLang ('profile ' ));
214- $ form ->addDropdown ('no ' , $ profiles );
217+ $ form ->addDropdown ('no ' , $ profiles )-> val ( $ this -> profno ) ;
215218 $ form ->addButton ('' , $ this ->getLang ('select ' ));
216219 $ form ->addFieldsetClose ();
217220
@@ -226,6 +229,7 @@ protected function profileForm() {
226229 [
227230 'action ' => wl ('' , ['do ' => 'admin ' , 'page ' => 'sync ' ], false , '& ' ),
228231 'method ' => 'POST ' ,
232+ 'class ' => 'sync_profile ' ,
229233 ]
230234 );
231235
@@ -238,15 +242,15 @@ protected function profileForm() {
238242 }
239243
240244 $ depths = [
241- 0 => $ this ->getLang ('level0 ' ),
242- 1 => $ this ->getLang ('level1 ' ),
243- 2 => $ this ->getLang ('level2 ' ),
244- 3 => $ this ->getLang ('level3 ' ),
245+ [ ' label ' => $ this ->getLang ('level0 ' ), ' attr ' => [ ' value ' => ' 0 ' ]] ,
246+ [ ' label ' => $ this ->getLang ('level1 ' ), ' attr ' => [ ' value ' => ' 1 ' ]] ,
247+ [ ' label ' => $ this ->getLang ('level2 ' ), ' attr ' => [ ' value ' => ' 2 ' ]] ,
248+ [ ' label ' => $ this ->getLang ('level3 ' ), ' attr ' => [ ' value ' => ' 3 ' ]] ,
245249 ];
246250 $ types = [
247- 0 => $ this ->getLang ('type0 ' ),
248- 1 => $ this ->getLang ('type1 ' ),
249- 2 => $ this ->getLang ('type2 ' ),
251+ [ ' label ' => $ this ->getLang ('type0 ' ), ' attr ' => [ ' value ' => ' 0 ' ]] ,
252+ [ ' label ' => $ this ->getLang ('type1 ' ), ' attr ' => [ ' value ' => ' 1 ' ]] ,
253+ [ ' label ' => $ this ->getLang ('type2 ' ), ' attr ' => [ ' value ' => ' 2 ' ]] ,
250254 ];
251255
252256 $ form ->addFieldsetOpen ($ legend );
@@ -261,9 +265,9 @@ protected function profileForm() {
261265 $ form ->addDropdown ('prf[type] ' , $ types , $ this ->getLang ('type ' ))->val ($ profile ['type ' ]);
262266 $ form ->addButton ('' , $ this ->getLang ('save ' ))->attr ('type ' , 'submit ' );
263267
264- // if($no !== '' && $this->profiles[$no][ 'ltime']) {
265- // echo '<small>' . $this->getLang('changewarn') . '</small>';
266- // }
268+ if ($ this -> profno !== false && ! empty ( $ profile [ 'ltime ' ]) ) {
269+ echo '<small> ' . $ this ->getLang ('changewarn ' ) . '</small> ' ;
270+ }
267271
268272 $ form ->addFieldsetClose ();
269273
0 commit comments