if (isset($_REQUEST['action']) && in_array($_REQUEST['action'], Action::$VALID_ACTIONS)) {
    $action = $_REQUEST['action'];
}
# 2. figure out which notebook page is being acted on (if none specified then redirect to home page)
$notebook_page = '';
if ($action == 'create') {
    if (!isset($_REQUEST['notebook_id']) || !is_numeric($_REQUEST['notebook_id'])) {
        util_redirectToAppPage('app_code/notebook.php?action=list', 'failure', util_lang('no_notebook_specified'));
    }
    //        $notebook_page = new Notebook_Page(['notebook_id' => $_REQUEST['notebook_id'],'DB'=>$DB]);
    //        $notebook_page->notebook_page_id = 'NEW';
    //
    $notebook_page = Notebook_Page::createNewNotebookPageForNotebook($_REQUEST['notebook_id'], $DB);
} else {
    if ($_REQUEST['notebook_page_id'] == 'NEW') {
        $notebook_page = Notebook_Page::createNewNotebookPageForNotebook($_REQUEST['notebook_id'], $DB);
    } else {
        if (!isset($_REQUEST['notebook_page_id']) || !is_numeric($_REQUEST['notebook_page_id'])) {
            util_redirectToAppPage('app_code/notebook.php?action=list', 'failure', util_lang('no_notebook_page_specified'));
        }
        $notebook_page = Notebook_Page::getOneFromDb(['notebook_page_id' => $_REQUEST['notebook_page_id']], $DB);
        if (!$notebook_page->matchesDb) {
            util_redirectToAppPage('app_code/notebook.php?action=list', 'failure', util_lang('no_notebook_page_found'));
        }
    }
}
# 3. confirm that the user is allowed to take that action on that object (if not, redirect them to the home page with an appropriate warning)
if (!$USER->canActOnTarget($ACTIONS[$action], $notebook_page)) {
    //        util_prePrintR("action is $action");
    if ($action != 'view' && isset($_REQUEST['notebook_page_id']) && is_numeric($_REQUEST['notebook_page_id'])) {
        util_redirectToAppPage('app_code/notebook_page.php?action=view&notebook_page_id=' . $notebook_page->notebook_page_id, 'failure', util_lang('no_permission'));
 function testDoDelete()
 {
     $np = Notebook_Page::getOneFromDb(['notebook_page_id' => 1101], $this->DB);
     $np->loadSpecimens();
     $np->loadPageFields();
     $this->assertTrue($np->matchesDb);
     $this->assertTrue($np->page_fields[0]->matchesDb);
     $this->assertTrue($np->page_fields[1]->matchesDb);
     $this->assertTrue($np->page_fields[2]->matchesDb);
     $this->assertTrue($np->page_fields[3]->matchesDb);
     $this->assertTrue($np->specimens[0]->matchesDb);
     $this->assertTrue($np->specimens[1]->matchesDb);
     //***********
     $np->doDelete();
     //***********
     $np2 = Notebook_Page::createNewNotebookPageForNotebook(1001, $this->DB);
     $this->assertFalse($np2->matchesDb);
     $npf = Notebook_Page_Field::getOneFromDb(['notebook_page_field_id' => 1201], $this->DB);
     $this->assertFalse($npf->matchesDb);
     $npf = Notebook_Page_Field::getOneFromDb(['notebook_page_field_id' => 1202], $this->DB);
     $this->assertFalse($npf->matchesDb);
     $npf = Notebook_Page_Field::getOneFromDb(['notebook_page_field_id' => 1203], $this->DB);
     $this->assertFalse($npf->matchesDb);
     $npf = Notebook_Page_Field::getOneFromDb(['notebook_page_field_id' => 1204], $this->DB);
     $this->assertFalse($npf->matchesDb);
     $s = Specimen::getOneFromDb(['specimen_id' => 8002], $this->DB);
     $this->assertFalse($s->matchesDb);
     $s = Specimen::getOneFromDb(['specimen_id' => 8003], $this->DB);
     $this->assertFalse($s->matchesDb);
     $si = Specimen_Image::getOneFromDb(['specimen_image_id' => 8103], $this->DB);
     $this->assertFalse($si->matchesDb);
     $si = Specimen_Image::getOneFromDb(['specimen_image_id' => 8104], $this->DB);
     $this->assertFalse($si->matchesDb);
 }