491 // Get ID of the group |
490 // Get ID of the group |
492 $edit_id = intval($_POST['pg_id']); |
491 $edit_id = intval($_POST['pg_id']); |
493 if ( !$edit_id ) |
492 if ( !$edit_id ) |
494 { |
493 { |
495 $return = array('mode' => 'error', 'text' => 'Hack attempt'); |
494 $return = array('mode' => 'error', 'text' => 'Hack attempt'); |
496 echo $json->encode($return); |
495 echo enano_json_encode($return); |
497 return; |
496 return; |
498 } |
497 } |
499 |
498 |
500 // Run some validation - check that page exists and that it's not already in the group |
499 // Run some validation - check that page exists and that it's not already in the group |
501 $page = $_POST['new_page']; |
500 $page = $_POST['new_page']; |
502 if ( empty($page) ) |
501 if ( empty($page) ) |
503 { |
502 { |
504 $return = array('mode' => 'error', 'text' => 'Please enter a page title.'); |
503 $return = array('mode' => 'error', 'text' => 'Please enter a page title.'); |
505 echo $json->encode($return); |
504 echo enano_json_encode($return); |
506 return; |
505 return; |
507 } |
506 } |
508 |
507 |
509 /* |
508 /* |
510 // We're gonna allow adding nonexistent pages for now |
509 // We're gonna allow adding nonexistent pages for now |
511 if ( !isPage($page) ) |
510 if ( !isPage($page) ) |
512 { |
511 { |
513 $return = array('mode' => 'error', 'text' => 'The page you are trying to add (' . htmlspecialchars($page) . ') does not exist.'); |
512 $return = array('mode' => 'error', 'text' => 'The page you are trying to add (' . htmlspecialchars($page) . ') does not exist.'); |
514 echo $json->encode($return); |
513 echo enano_json_encode($return); |
515 return; |
514 return; |
516 } |
515 } |
517 */ |
516 */ |
518 |
517 |
519 list($page_id, $namespace) = RenderMan::strToPageID($page); |
518 list($page_id, $namespace) = RenderMan::strToPageID($page); |
520 $page_id = sanitize_page_id($page_id); |
519 $page_id = sanitize_page_id($page_id); |
521 |
520 |
522 if ( !isset($paths->namespace[$namespace]) ) |
521 if ( !isset($paths->namespace[$namespace]) ) |
523 { |
522 { |
524 $return = array('mode' => 'error', 'text' => 'Invalid namespace return from RenderMan::strToPageID()'); |
523 $return = array('mode' => 'error', 'text' => 'Invalid namespace return from RenderMan::strToPageID()'); |
525 echo $json->encode($return); |
524 echo enano_json_encode($return); |
526 return; |
525 return; |
527 } |
526 } |
528 |
527 |
529 $q = $db->sql_query('SELECT "x" FROM '.table_prefix.'page_group_members WHERE pg_id=' . $edit_id . ' AND page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $namespace . '\';'); |
528 $q = $db->sql_query('SELECT "x" FROM '.table_prefix.'page_group_members WHERE pg_id=' . $edit_id . ' AND page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $namespace . '\';'); |
530 if ( !$q ) |
529 if ( !$q ) |
531 { |
530 { |
532 $return = array('mode' => 'error', 'text' => $db->get_error()); |
531 $return = array('mode' => 'error', 'text' => $db->get_error()); |
533 echo $json->encode($return); |
532 echo enano_json_encode($return); |
534 return; |
533 return; |
535 } |
534 } |
536 if ( $db->numrows() > 0 ) |
535 if ( $db->numrows() > 0 ) |
537 { |
536 { |
538 $return = array('mode' => 'error', 'text' => 'The page you are trying to add is already in this group.'); |
537 $return = array('mode' => 'error', 'text' => 'The page you are trying to add is already in this group.'); |
539 echo $json->encode($return); |
538 echo enano_json_encode($return); |
540 return; |
539 return; |
541 } |
540 } |
542 |
541 |
543 $q = $db->sql_query('INSERT INTO '.table_prefix.'page_group_members(pg_id, page_id, namespace) VALUES(' . $edit_id . ', \'' . $db->escape($page_id) . '\', \'' . $namespace . '\');'); |
542 $q = $db->sql_query('INSERT INTO '.table_prefix.'page_group_members(pg_id, page_id, namespace) VALUES(' . $edit_id . ', \'' . $db->escape($page_id) . '\', \'' . $namespace . '\');'); |
544 if ( !$q ) |
543 if ( !$q ) |
545 { |
544 { |
546 $return = array('mode' => 'error', 'text' => $db->get_error()); |
545 $return = array('mode' => 'error', 'text' => $db->get_error()); |
547 echo $json->encode($return); |
546 echo enano_json_encode($return); |
548 return; |
547 return; |
549 } |
548 } |
550 |
549 |
551 $title = "($namespace) " . get_page_title($paths->nslist[$namespace] . $page_id); |
550 $title = "($namespace) " . get_page_title($paths->nslist[$namespace] . $page_id); |
552 |
551 |
553 $return = array('mode' => 'info', 'text' => 'The page has been added to the specified group.', 'successful' => true, 'title' => $title, 'member_id' => $db->insert_id()); |
552 $return = array('mode' => 'info', 'text' => 'The page has been added to the specified group.', 'successful' => true, 'title' => $title, 'member_id' => $db->insert_id()); |
554 |
553 |
555 echo $json->encode($return); |
554 echo enano_json_encode($return); |
556 return; |
555 return; |
557 } |
556 } |
558 |
557 |
559 if ( isset($_POST['action']['edit_save']) && isset($_POST['pg_name']) ) |
558 if ( isset($_POST['action']['edit_save']) && isset($_POST['pg_name']) ) |
560 { |
559 { |