function testRenderAsEdit_owner()
    {
        $n = Notebook::getOneFromDb(['notebook_id' => 1001], $this->DB);
        global $USER;
        $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB);
        $n->loadPages();
        $canonical = '<div id="edit_rendered_notebook_1001" class="edit_rendered_notebook" data-notebook_id="1001" data-created_at="' . $n->created_at . '" data-updated_at="' . $n->updated_at . '" data-user_id="101" data-name="testnotebook1" data-notes="this is testnotebook1, owned by user 101" data-flag_workflow_published="0" data-flag_workflow_validated="0" data-flag_delete="0" data-can-edit="1">
<form action="' . APP_ROOT_PATH . '/app_code/notebook.php">
<div id="actions">
  <button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control"><i class="icon-ok-sign icon-white"></i> ' . util_lang('update', 'properize') . '</button>
  <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=view&notebook_id=1001"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a>
</div>
  <input type="hidden" name="action" value="update"/>
  <input type="hidden" name="notebook_id" value="1001"/>
  <h3 class="notebook_title">' . ucfirst(util_lang('notebook')) . ': <input id="notebook-name" type="text" name="name" value="testnotebook1"/></h3>
  <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($n->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($n->updated_at) . '</span></div>
  <div class="info-owner">' . util_lang('owned_by') . ' <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=101">' . $USER->screen_name . '</a></div>
<div class="control-workflows">  <span class="published_state workflow-control"><input id="notebook-workflow-publish-control" type="checkbox" name="flag_workflow_published" value="1" /> ' . util_lang('publish') . '</span>, <span class="verified_state verified_state_false workflow-info">' . util_lang('verified_false') . '</span></div>
  <div class="notebook_notes"><textarea id="notebook-notes" name="notes" rows="4" cols="120">this is testnotebook1, owned by user 101</textarea></div>
</form>
  <h4>' . ucfirst(util_lang('pages')) . '</h4>
  <ul id="list-of-notebook-pages" data-notebook-page-count="2">
    <li><a href="' . APP_ROOT_PATH . '/app_code/notebook_page.php?action=create&notebook_id=1001" id="btn-add-notebook-page" class="creation_link btn">+ Add Page / Entry +</a></li>
';
        $page_counter = 0;
        foreach ($n->pages as $p) {
            $page_counter++;
            $canonical .= '    ' . $p->renderAsListItem('notebook-page-item-' . $page_counter) . "\n";
        }
        $canonical .= '  </ul>
</div>';
        $rendered = $n->renderAsEdit();
        //            echo "<pre>\n".htmlentities($canonical)."\n-----------------\n".htmlentities($rendered)."\n</pre>";
        $this->assertEqual($canonical, $rendered);
        $this->assertNoPattern('/IMPLEMENTED/', $rendered);
    }
 function testViewNotEditable()
 {
     $this->doLoginBasic();
     $this->goToNotebookView(1004);
     $this->checkBasicAsserts();
     $n = Notebook::getOneFromDb(['notebook_id' => 1004], $this->DB);
     //        util_prePrintR($n);
     $ap1 = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5001], $this->DB);
     // page heading text
     $this->assertText(ucfirst(util_lang('notebook')));
     $this->assertText($n->name);
     $this->assertText($n->notes);
     // NO 'edit' control
     $this->assertNoLink(util_lang('edit'));
     // number of notebook pages
     $this->assertEltByIdHasAttrOfValue('list-of-notebook-pages', 'data-notebook-page-count', '1');
     $this->assertEltByIdHasAttrOfValue('notebook-page-item-1', 'data-notebook_page_id', '1104');
     $this->assertLink($ap1->renderAsShortText());
     // NO 'add page' control
     $this->assertNoLink(util_lang('add_notebook_page'));
 }
 function testCanActOnTarget_Pub_Verify()
 {
     $n2 = Notebook::getOneFromDb(['notebook_id' => 1003], $this->DB);
     // owned by 102
     $actions_list = Action::getAllFromDb([], $this->DB);
     $actions = [];
     foreach ($actions_list as $act_elt) {
         $actions[$act_elt->name] = $act_elt;
     }
     $rat = new Role_Action_Target(['last_user_id' => 110, 'role_id' => 3, 'action_id' => 1, 'target_type' => 'notebook', 'target_id' => 1003, 'DB' => $this->DB]);
     $rat->updateDb();
     $this->assertTrue($rat->matchesDb);
     // basic, field user
     $u = User::getOneFromDb(['user_id' => 101], $this->DB);
     $this->assertFalse($n2->flag_workflow_published);
     $this->assertFalse($n2->flag_workflow_validated);
     $this->assertFalse($u->canActOnTarget($actions['view'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $n2));
     $n2->flag_workflow_published = true;
     $n2->updateDb();
     $this->assertTrue($n2->matchesDb);
     $u->clearCaches();
     $this->assertFalse($u->canActOnTarget($actions['view'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $n2));
     $n2->flag_workflow_validated = true;
     $n2->updateDb();
     $this->assertTrue($n2->matchesDb);
     $u->clearCaches();
     $this->assertTrue($u->canActOnTarget($actions['view'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['edit'], $n2));
     $this->assertTrue($u->canActOnTarget($actions['create'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['delete'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['publish'], $n2));
     $this->assertFalse($u->canActOnTarget($actions['verify'], $n2));
 }
        $notebook = new Notebook(['DB' => $DB]);
        if (!$USER->canActOnTarget($ACTIONS['create'], $notebook)) {
            util_redirectToAppHome('failure', util_lang('no_notebooks_found'));
        }
    } else {
        $notebook = $all_accessible_notebooks[0];
    }
} else {
    //        if ((! isset($_REQUEST['notebook_id'])) || (! is_numeric($_REQUEST['notebook_id']))) {
    ////            util_redirectToAppHome('failure',util_lang('no_notebook_specified'));
    //            util_redirectToAppPage('app_code/notebook.php?action=list','failure',util_lang('no_notebook_specified'));
    //        }
    if ($_REQUEST['notebook_id'] == 'NEW') {
        $notebook = Notebook::createNewNotebookForUser($USER->user_id, $DB);
    } else {
        $notebook = Notebook::getOneFromDb(['notebook_id' => $_REQUEST['notebook_id']], $DB);
        if (!$notebook->matchesDb) {
            //            util_redirectToAppHome('failure',util_lang('no_notebook_found'));
            util_redirectToAppPage('app_code/notebook.php?action=list', 'failure', util_lang('no_notebook_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)) {
    //        util_redirectToAppHome('failure',util_lang('no_permission'));
    if ($action == 'edit') {
        util_redirectToAppPage('app_code/notebook.php?action=view&notebook_id=' . $notebook->notebook_id, 'failure', util_lang('no_permission'));
    }
    util_redirectToAppPage('app_code/notebook.php?action=list', 'failure', util_lang('no_permission'));
}
if ($action != 'delete') {
 function testBaseDataUpdate()
 {
     $this->doLoginBasic();
     $this->get('http://localhost/digitalfieldnotebooks/app_code/notebook.php?action=edit&notebook_id=1001');
     $this->checkBasicAsserts();
     //      NOTE: the identifier to use for setField is the value of the name attribute of the field
     $this->setField('name', 'new name for testnotebook1');
     //        NOTE: the identifier to use for form buttons is the value of the value attribute of the button, or the interior html of a button element
     $this->click('<i class="icon-ok-sign icon-white"></i> ' . util_lang('update', 'properize'));
     $this->checkBasicAsserts();
     $this->assertText('new name for testnotebook1');
     $n = Notebook::getOneFromDb(['notebook_id' => 1001], $this->DB);
     $this->assertEqual($n->name, 'new name for testnotebook1');
     //        util_prePrintR(htmlentities($this->getBrowser()->getContent()));
 }
 function testNewNotebookPage()
 {
     $n = Notebook::getOneFromDb(['notebook_id' => 1001], $this->DB);
     $this->doLoginBasic();
     $this->get('http://localhost/digitalfieldnotebooks/app_code/notebook.php?action=edit&notebook_id=1001');
     $this->checkBasicAsserts();
     $this->click(util_lang('add_notebook_page'));
     $this->checkBasicAsserts();
     $this->assertEltByIdHasAttrOfValue('form-edit-notebook-page-base-data', 'action', APP_ROOT_PATH . '/app_code/notebook_page.php');
     //        $this->showContent();
 }
 public function getNotebook()
 {
     return Notebook::getOneFromDb(['notebook_id' => $this->notebook_id], $this->dbConnection);
 }
 function testRenderAsListItemForNotebook()
 {
     $np = Notebook_Page::getOneFromDb(['notebook_page_id' => 1101], $this->DB);
     global $USER;
     $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB);
     $nb = Notebook::getOneFromDb(['notebook_id' => 1001], $this->DB);
     $rendered = $np->renderAsListItemForNotebook();
     $canonical = '<li data-notebook_page_id="1101" data-created_at="' . $np->created_at . '" data-updated_at="' . $np->updated_at . '" data-notebook_id="1001" data-authoritative_plant_id="5001" data-notes="testing notebook page the first in testnotebook1, owned by user 101" data-flag_workflow_published="0" data-flag_workflow_validated="0" data-flag_delete="0" data-can-edit="1"><a href="' . APP_ROOT_PATH . '/app_code/notebook_page.php?action=view&notebook_page_id=1101">' . util_lang('page_in_notebook') . ' ' . htmlentities($nb->name) . '</a></li>';
     //            echo "<pre>\n".htmlentities($canonical)."\n--------------\n".htmlentities($rendered)."\n</pre>";
     $this->assertEqual($canonical, $rendered);
 }
 public function getTargets()
 {
     switch ($this->target_type) {
         case 'global_notebook':
             return Notebook::getAllFromDb([], $this->dbConnection);
             break;
         case 'global_metadata':
             return Metadata_Structure::getAllFromDb([], $this->dbConnection);
             break;
         case 'global_plant':
             return Authoritative_Plant::getAllFromDb([], $this->dbConnection);
             break;
         case 'global_specimen':
             return Specimen::getAllFromDb([], $this->dbConnection);
             break;
         case 'notebook':
             return array(Notebook::getOneFromDb(['notebook_id' => $this->target_id], $this->dbConnection));
             break;
         case 'metadata_structure':
             return array(Metadata_Structure::getOneFromDb(['metadata_structure_id' => $this->target_id], $this->dbConnection));
             break;
         case 'plant':
             return array(Authoritative_Plant::getOneFromDb(['authoritative_id' => $this->target_id], $this->dbConnection));
             break;
         case 'specimen':
             return array(Specimen::getOneFromDb(['specimen_id' => $this->target_id], $this->dbConnection));
             break;
         default:
             return array();
     }
 }