@@ -1242,52 +1242,48 @@ function(reponse) {
12421242 if (!api_is_allowed_to_edit (null , true )) {
12431243 api_not_allowed (true );
12441244 }
1245- $ courseId = api_get_course_int_id ();
1246- $ sessionId = api_get_session_id ();
1247- $ catOrder = isset ($ _POST ['order ' ]) ? (array ) $ _POST ['order ' ] : [];
1245+ $ courseId = api_get_course_int_id ();
12481246 $ tableCategory = Database::get_course_table (TABLE_LP_CATEGORY );
12491247
1250- Database::query ('START TRANSACTION ' );
1248+ $ catOrder = isset ($ _POST ['order ' ]) ? (array ) $ _POST ['order ' ] : [];
1249+
12511250 $ pos = 1 ;
1252- foreach ($ catOrder as $ catId ) {
1253- $ catId = (int )$ catId ;
1254- if ($ catId > 0 ) {
1255- $ catSessionId = (int ) learnpath::getCategorySessionId ($ catId );
1256- if ($ catSessionId !== 0 && $ catSessionId !== $ sessionId ) {
1257- continue ;
1258- }
1251+ foreach ($ catOrder as $ catIid ) {
1252+ $ catIid = (int ) $ catIid ;
1253+ if ($ catIid <= 0 ) {
1254+ continue ;
12591255 }
1260- $ sql = "UPDATE $ tableCategory SET position = $ pos WHERE c_id = $ courseId AND id = $ catId " ;
1256+
1257+ $ sql = "UPDATE $ tableCategory
1258+ SET position = $ pos
1259+ WHERE c_id = $ courseId
1260+ AND iid = $ catIid " ;
12611261 Database::query ($ sql );
12621262 $ pos ++;
12631263 }
1264- Database:: query ( ' COMMIT ' );
1264+
12651265 header ('Content-Type: application/json ' );
12661266 echo json_encode (['ok ' => true ]);
12671267 exit ;
1268- break ;
1269-
12701268 case 'reorder_lps ' :
12711269 if (!api_is_allowed_to_edit (null , true )) {
12721270 api_not_allowed (true );
12731271 }
12741272 $ courseId = api_get_course_int_id ();
12751273 $ sessionId = api_get_session_id ();
1276- $ tableLp = Database::get_course_table (TABLE_LP_MAIN );
1274+ $ tableLp = Database::get_course_table (TABLE_LP_MAIN );
12771275
12781276 $ lists = isset ($ _POST ['lists ' ]) ? (array ) $ _POST ['lists ' ] : [];
12791277
1280- if (!empty ($ sessionId )) {
1281- api_not_allowed (true );
1282- }
1283-
1284- Database::query ('START TRANSACTION ' );
1285-
12861278 foreach ($ lists as $ categoryIdStr => $ lpIds ) {
1287- $ categoryId = (int )$ categoryIdStr ;
1279+ $ categoryId = (int ) $ categoryIdStr ;
12881280 $ pos = 1 ;
1289- foreach ((array )$ lpIds as $ lpId ) {
1290- $ lpId = (int )$ lpId ;
1281+
1282+ foreach ((array ) $ lpIds as $ lpId ) {
1283+ $ lpId = (int ) $ lpId ;
1284+ if ($ lpId <= 0 ) {
1285+ continue ;
1286+ }
12911287 $ sql = "UPDATE $ tableLp
12921288 SET category_id = " .($ categoryId ?: 0 ).", display_order = $ pos
12931289 WHERE c_id = $ courseId AND id = $ lpId " ;
@@ -1296,11 +1292,9 @@ function(reponse) {
12961292 }
12971293 }
12981294
1299- Database::query ('COMMIT ' );
13001295 header ('Content-Type: application/json ' );
13011296 echo json_encode (['ok ' => true ]);
13021297 exit ;
1303- break ;
13041298 case 'edit ' :
13051299 if (!$ is_allowed_to_edit ) {
13061300 api_not_allowed (true );
0 commit comments