Changeset 881 for trunk/admin
- Timestamp:
- Oct 8, 2005, 12:04:53 AM (19 years ago)
- Location:
- trunk/admin
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/cat_modify.php
r862 r881 68 68 if (isset($_POST['parent'])) 69 69 { 70 move_category($_GET['cat_id'], $_POST['parent']); 70 move_categories( 71 array($_GET['cat_id']), 72 $_POST['parent'] 73 ); 71 74 } 72 75 -
trunk/admin/include/functions.php
r880 r881 1338 1338 1339 1339 /** 1340 * change the parent category of the given categor y. The category is1340 * change the parent category of the given categories. The categories are 1341 1341 * supposed virtual. 1342 1342 * 1343 * @param int category identifier1343 * @param array category identifiers 1344 1344 * @param int parent category identifier 1345 1345 * @return void 1346 1346 */ 1347 function move_category($category_id, $new_parent = -1) 1348 { 1349 // verifies if the move is necessary 1350 $query = ' 1351 SELECT id_uppercat, status 1347 function move_categories($category_ids, $new_parent = -1) 1348 { 1349 global $page; 1350 1351 if (count($category_ids) == 0) 1352 { 1353 return; 1354 } 1355 1356 $new_parent = $new_parent < 1 ? 'NULL' : $new_parent; 1357 1358 $categories = array(); 1359 1360 $query = ' 1361 SELECT id, id_uppercat, status, uppercats 1352 1362 FROM '.CATEGORIES_TABLE.' 1353 WHERE id = '.$category_id.' 1354 ;'; 1355 list($old_parent, $status) = mysql_fetch_row(pwg_query($query)); 1356 1357 $old_parent = empty($old_parent) ? 'NULL' : $old_parent; 1358 $new_parent = $new_parent < 1 ? 'NULL' : $new_parent; 1359 1360 if ($new_parent == $old_parent) 1361 { 1362 // no need to move ! 1363 return; 1364 } 1363 WHERE id IN ('.implode(',', $category_ids).') 1364 ;'; 1365 $result = pwg_query($query); 1366 while ($row = mysql_fetch_array($result)) 1367 { 1368 $categories[$row['id']] = 1369 array( 1370 'parent' => empty($row['id_uppercat']) ? 'NULL' : $row['id_uppercat'], 1371 'status' => $row['status'], 1372 'uppercats' => $row['uppercats'] 1373 ); 1374 } 1375 1376 // is the movement possible? The movement is impossible if you try to move 1377 // a category in a sub-category or itself 1378 if ('NULL' != $new_parent) 1379 { 1380 $query = ' 1381 SELECT uppercats 1382 FROM '.CATEGORIES_TABLE.' 1383 WHERE id = '.$new_parent.' 1384 ;'; 1385 list($new_parent_uppercats) = mysql_fetch_row(pwg_query($query)); 1386 1387 foreach ($categories as $category) 1388 { 1389 // technically, you can't move a category with uppercats 12,125,13,14 1390 // into a new parent category with uppercats 12,125,13,14,24 1391 if (preg_match('/^'.$category['uppercats'].'/', $new_parent_uppercats)) 1392 { 1393 array_push( 1394 $page['errors'], 1395 l10n('You cannot move a category in its own sub category') 1396 ); 1397 return; 1398 } 1399 } 1400 } 1401 1402 $tables = 1403 array( 1404 USER_ACCESS_TABLE => 'user_id', 1405 GROUP_ACCESS_TABLE => 'group_id' 1406 ); 1365 1407 1366 1408 $query = ' 1367 1409 UPDATE '.CATEGORIES_TABLE.' 1368 1410 SET id_uppercat = '.$new_parent.' 1369 WHERE id = '.$category_id.'1411 WHERE id IN ('.implode(',', $category_ids).') 1370 1412 ;'; 1371 1413 pwg_query($query); … … 1392 1434 if ('private' == $parent_status) 1393 1435 { 1394 switch ($status) 1395 { 1396 case 'public' : 1397 { 1398 set_cat_status(array($category_id), 'private'); 1399 break; 1400 } 1401 case 'private' : 1402 { 1403 $subcats = get_subcat_ids(array($category_id)); 1404 1405 $tables = 1406 array( 1407 USER_ACCESS_TABLE => 'user_id', 1408 GROUP_ACCESS_TABLE => 'group_id' 1409 ); 1436 foreach ($categories as $cat_id => $category) 1437 { 1438 switch ($category['status']) 1439 { 1440 case 'public' : 1441 { 1442 set_cat_status(array($cat_id), 'private'); 1443 break; 1444 } 1445 case 'private' : 1446 { 1447 $subcats = get_subcat_ids(array($cat_id)); 1410 1448 1411 foreach ($tables as $table => $field)1412 {1413 $query = '1449 foreach ($tables as $table => $field) 1450 { 1451 $query = ' 1414 1452 SELECT '.$field.' 1415 1453 FROM '.$table.' 1416 WHERE cat egory_id = '.$category_id.'1417 ;'; 1418 $category_access = array_from_query($query, $field);1419 1420 $query = '1454 WHERE cat_id = '.$cat_id.' 1455 ;'; 1456 $category_access = array_from_query($query, $field); 1457 1458 $query = ' 1421 1459 SELECT '.$field.' 1422 1460 FROM '.$table.' 1423 WHERE cat egory_id = '.$new_parent.'1424 ;'; 1425 $parent_access = array_from_query($query, $field);1461 WHERE cat_id = '.$new_parent.' 1462 ;'; 1463 $parent_access = array_from_query($query, $field); 1426 1464 1427 $to_delete = array_diff($parent_access, $category_access);1465 $to_delete = array_diff($parent_access, $category_access); 1428 1466 1429 if (count($to_delete) > 0)1430 {1431 $query = '1467 if (count($to_delete) > 0) 1468 { 1469 $query = ' 1432 1470 DELETE FROM '.$table.' 1433 1471 WHERE '.$field.' IN ('.implode(',', $to_delete).') 1434 AND category_id IN ('.implode(',', $subcats).') 1435 ;'; 1436 pwg_query($query); 1472 AND cat_id IN ('.implode(',', $subcats).') 1473 ;'; 1474 pwg_query($query); 1475 } 1437 1476 } 1477 break; 1438 1478 } 1439 break; 1440 } 1441 } 1442 } 1479 } 1480 } 1481 } 1482 1483 array_push( 1484 $page['infos'], 1485 sprintf( 1486 l10n('%d categories moved'), 1487 count($categories) 1488 ) 1489 ); 1443 1490 } 1444 1491 ?>
Note: See TracChangeset
for help on using the changeset viewer.