public function renderAsEdit()
 {
     $this->loadPageFields();
     $this->loadSpecimens();
     $n = $this->getNotebook();
     $ap = '';
     if ($this->notebook_page_id != 'NEW') {
         $ap = $this->getAuthoritativePlant();
     }
     //            util_prePrintR('TO BE IMPLEMENTED: handle auth plant for new pages (i.e. where auth plant id == 0)');
     //            util_prePrintR($this);
     global $USER, $ACTIONS;
     $actions_attribs = '';
     //            $add_field_button_li = '';
     if ($USER->canActOnTarget($ACTIONS['edit'], $this)) {
         $actions_attribs .= ' data-can-edit="1"';
         //                $add_field_button_li = '    <li><a href="" id="btn-add-notebook-page-field" class="creation_link btn">'.util_lang('add_notebook_page_field').'</a></li>'."\n";
     }
     $owner = $USER;
     if ($n->user_id != $USER->user_id) {
         $owner = $n->getUser();
     }
     $rendered = '<div id="rendered_notebook_page_' . $this->notebook_page_id . '" class="rendered_notebook_page edit_rendered_notebook_page" ' . $this->fieldsAsDataAttribs() . $actions_attribs . ">\n" . '<form id="form-edit-notebook-page-base-data" action="' . APP_ROOT_PATH . '/app_code/notebook_page.php">' . "\n" . '  <input type="hidden" name="action" value="update"/>' . "\n" . '  <input type="hidden" id="notebook_page_id" name="notebook_page_id" value="' . $this->notebook_page_id . '"/>' . "\n" . '  <input type="hidden" id="notebook_id" name="notebook_id" value="' . $this->notebook_id . '"/>' . "\n";
     $rendered .= '  <div id="actions">';
     $rendered .= '<button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control" value="update"><i class="icon-ok-sign icon-white"></i> ' . util_lang($this->notebook_page_id != 'NEW' ? 'update' : 'save', 'properize') . '</button>' . "\n";
     if ($this->notebook_page_id != 'NEW') {
         $rendered .= '  <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook_page.php?action=view&notebook_page_id=' . $this->notebook_page_id . '"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a>';
         $rendered .= '  <a id="edit-delete-notebook-page-control" class="btn btn-danger" href="' . APP_ROOT_PATH . '/app_code/notebook_page.php?action=delete&notebook_page_id=' . $this->notebook_page_id . '"><i class="icon-trash icon-white"></i> ' . util_lang('delete', 'properize') . '</a>';
     } else {
         $rendered .= '  <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=edit&notebook_id=' . $this->notebook_id . '"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a>';
     }
     $rendered .= '</div>' . "\n";
     $rendered .= '<h4>' . util_lang('page_in_notebook', 'ucfirst') . ' <a href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=view&notebook_id=' . $n->notebook_id . '" id="parent-notebook-link">' . htmlentities($n->name) . '</a></h4>' . "\n";
     if ($this->notebook_page_id != 'NEW') {
         $rendered .= '<a class="show-hide-control" href="#" data-for_elt_id="select_new_authoritative_plant_' . $this->notebook_page_id . '">' . util_lang('change_authoritative_plant') . '</a>';
         $rendered .= '  <div id="select_new_authoritative_plant_' . $this->notebook_page_id . '" class="select_new_authoritative_plant">' . Authoritative_Plant::renderControlSelectAllAuthoritativePlants($this->notebook_page_id != 'NEW' ? $ap->authoritative_plant_id : 0) . '</div>' . "\n";
         $rendered .= '  ' . $ap->renderAsViewEmbed() . "\n";
     } else {
         $rendered .= '  <div id="select_new_authoritative_plant_' . $this->notebook_page_id . '" class="NEW_select_new_authoritative_plant">' . Authoritative_Plant::renderControlSelectAllAuthoritativePlants(0) . '</div>' . "\n";
     }
     $rendered .= '  <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($this->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($this->updated_at) . "</span></div>\n" . '  <div class="info-owner">' . util_lang('owned_by') . ' <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=' . $owner->user_id . '">' . htmlentities($owner->screen_name) . '</a></div>' . "\n";
     $rendered .= '<div class="control-workflows">';
     if ($this->notebook_page_id != 'NEW') {
         if ($USER->canActOnTarget('publish', $this)) {
             $rendered .= '  <span class="published_state workflow-control"><input id="notebook-page-workflow-publish-control" type="checkbox" name="flag_workflow_published" value="1"' . ($this->flag_workflow_published ? ' checked="checked"' : '') . ' /> ' . util_lang('publish') . '</span>,';
         } else {
             $rendered .= '  <span class="published_state workflow-info">' . ($this->flag_workflow_published ? util_lang('published_true') : util_lang('published_false')) . '</span>,';
         }
         if ($USER->canActOnTarget('verify', $this)) {
             $rendered .= '  <span class="verified_state verified_state_' . ($this->flag_workflow_validated ? 'true' : 'false') . ' workflow-control"><input id="notebook-page-workflow-validate-control" type="checkbox" name="flag_workflow_validated" value="1"' . ($this->flag_workflow_validated ? ' checked="checked"' : '') . ' /> ' . util_lang('verify') . '</span>';
         } else {
             $rendered .= ' <span class="verified_state verified_state_' . ($this->flag_workflow_validated ? 'true' : 'false') . ' workflow-info">' . ($this->flag_workflow_validated ? util_lang('verified_true') : util_lang('verified_false')) . '</span>';
         }
         $rendered .= '<br/>' . "\n";
     } else {
         $rendered .= '  <span class="published_state workflow-info">' . ($this->flag_workflow_published ? util_lang('published_true') : util_lang('published_false')) . '</span>,';
         $rendered .= ' <span class="verified_state verified_state_' . ($this->flag_workflow_validated ? 'true' : 'false') . ' workflow-info">' . ($this->flag_workflow_validated ? util_lang('verified_true') : util_lang('verified_false')) . '</span>';
     }
     $rendered .= "</div>\n";
     $rendered .= '  <div class="notebook_page_notes"><textarea id="notebook-page-notes" name="notes" rows="4" cols="120">' . htmlentities($this->notes) . '</textarea></div>' . "\n";
     if ($this->notebook_page_id != 'NEW') {
         $rendered .= '  <h4>' . ucfirst(util_lang('metadata')) . "</h4>\n";
         $rendered .= '  <ul class="notebook-page-fields">' . "\n";
         $rendered .= '    <li><a href="#" id="add_new_notebook_page_field_button" class="btn">' . util_lang('add_notebook_page_field') . '</a></li>' . "\n";
         if ($this->page_fields) {
             $prev_pf_structure_id = $this->page_fields[0]->label_metadata_structure_id;
             foreach ($this->page_fields as $pf) {
                 $spacer_class = '';
                 if ($pf->label_metadata_structure_id != $prev_pf_structure_id) {
                     $spacer_class = 'spacing-list-item';
                 }
                 $rendered .= '    ' . $pf->renderAsListItemEdit('list_item-notebook_page_field_' . $pf->notebook_page_field_id, [$spacer_class]) . "\n";
                 $prev_pf_structure_id = $pf->label_metadata_structure_id;
             }
         } else {
             $rendered .= '<li>' . util_lang('no_metadata', 'ucfirst') . '</li>' . "\n";
         }
         $rendered .= '  </ul>' . "\n";
         $rendered .= Specimen::renderSpecimenListBlock($this->specimens);
         //                $rendered .= '  <h4>'.ucfirst(util_lang('specimens'))."</h4>\n".
         //                    '  <ul class="specimens">'."\n";
         //                $rendered .= '    <li><a href="#" id="add_new_specimen_button" class="btn">'.util_lang('add_specimen').'</a></li>'."\n";
         //                if ($this->specimens) {
         //                    foreach ($this->specimens as $specimen) {
         //                        $rendered .= '    <li id="list_item-specimen_'.$specimen->specimen_id.'">'.$specimen->renderAsEditEmbed()."</li>\n";
         //                    }
         //                } else {
         //                    $rendered .= '<li>'.util_lang('no_metadata','ucfirst').'</li>'."\n";
         //                }
         //                $rendered .= "  </ul>\n";
         $rendered .= '<input type="hidden" id="initial_page_field_ids" name="initial_page_field_ids" value="' . implode(',', Db_Linked::arrayOfAttrValues($this->page_fields, 'notebook_page_field_id')) . '"/>' . "\n";
         $rendered .= '<input type="hidden" id="created_page_field_ids" name="created_page_field_ids" value=""/>' . "\n";
         $rendered .= '<input type="hidden" id="deleted_page_field_ids" name="deleted_page_field_ids" value=""/>' . "\n";
         $rendered .= '<input type="hidden" id="initial_specimen_ids" name="initial_specimen_ids" value="' . implode(',', Db_Linked::arrayOfAttrValues($this->specimens, 'specimen_id')) . '"/>' . "\n";
         $rendered .= '<input type="hidden" id="created_specimen_ids" name="created_specimen_ids" value=""/>' . "\n";
         $rendered .= '<input type="hidden" id="deleted_specimen_ids" name="deleted_specimen_ids" value=""/>' . "\n";
     }
     $rendered .= '</form>' . "\n";
     $rendered .= "</div>";
     return $rendered;
 }
 function testRenderControlSelectAllAuthoritativePlants()
 {
     $aps = Authoritative_Plant::getAllFromDb(['flag_active' => true, 'flag_delete' => false], $this->DB);
     usort($aps, 'Authoritative_Plant::cmp');
     $canonical_base = '<select name="authoritative_plant_id" id="authoritative-plant-id">' . "\n";
     global $DB;
     $DB = $this->DB;
     //-------
     // no default select
     $canonical = $canonical_base;
     foreach ($aps as $ap) {
         $canonical .= '  ' . $ap->renderAsOption() . "\n";
     }
     $canonical .= '</select>';
     $rendered = Authoritative_Plant::renderControlSelectAllAuthoritativePlants();
     $this->assertEqual($canonical, $rendered);
     $this->assertNoPattern('/IMPLEMENTED/', $rendered);
     //-------
     // default select using an id number
     $canonical = $canonical_base;
     foreach ($aps as $ap) {
         $canonical .= '  ' . $ap->renderAsOption($ap->authoritative_plant_id == 5005) . "\n";
     }
     $canonical .= '</select>';
     $rendered = Authoritative_Plant::renderControlSelectAllAuthoritativePlants(5005);
     $this->assertEqual($canonical, $rendered);
     $this->assertNoPattern('/IMPLEMENTED/', $rendered);
     //-------------
     // default select using an object
     $default_ap = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5003], $this->DB);
     $canonical = $canonical_base;
     foreach ($aps as $ap) {
         $canonical .= '  ' . $ap->renderAsOption($ap->authoritative_plant_id == $default_ap->authoritative_plant_id) . "\n";
     }
     $canonical .= '</select>';
     $rendered = Authoritative_Plant::renderControlSelectAllAuthoritativePlants($default_ap);
     $this->assertEqual($canonical, $rendered);
     $this->assertNoPattern('/IMPLEMENTED/', $rendered);
 }
    function testRenderAsEdit_newNotebookPage()
    {
        $np = Notebook_Page::createNewNotebookPageForNotebook(1001, $this->DB);
        $n = $np->getNotebook();
        global $USER, $DB;
        $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB);
        $DB = $this->DB;
        $canonical = '<div id="rendered_notebook_page_NEW" class="rendered_notebook_page edit_rendered_notebook_page" ' . $np->fieldsAsDataAttribs() . ' data-can-edit="1">
<form id="form-edit-notebook-page-base-data" action="' . APP_ROOT_PATH . '/app_code/notebook_page.php">
  <input type="hidden" name="action" value="update"/>
  <input type="hidden" id="notebook_page_id" name="notebook_page_id" value="NEW"/>
  <input type="hidden" id="notebook_id" name="notebook_id" value="1001"/>
  <div id="actions"><button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control" value="update"><i class="icon-ok-sign icon-white"></i> Save</button>
  <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=edit&notebook_id=1001"><i class="icon-remove"></i> Cancel</a></div>
<h4>In notebook <a href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=view&notebook_id=1001" id="parent-notebook-link">testnotebook1</a></h4>
  <div id="select_new_authoritative_plant_NEW" class="NEW_select_new_authoritative_plant">' . Authoritative_Plant::renderControlSelectAllAuthoritativePlants() . '</div>
  <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($np->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($np->updated_at) . '</span></div>
  <div class="info-owner">owned by <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=101">' . htmlentities($USER->screen_name) . '</a></div>
<div class="control-workflows">  <span class="published_state workflow-info">' . util_lang('published_false') . '</span>, <span class="verified_state verified_state_false workflow-info">' . util_lang('verified_false') . '</span></div>
  <div class="notebook_page_notes"><textarea id="notebook-page-notes" name="notes" rows="4" cols="120">' . util_lang('new_notebook_page_notes') . '</textarea></div>
</form>
</div>';
        $rendered = $np->renderAsEdit();
        //            echo "<pre>
        //-----------
        //".htmlentities($canonical)."
        //-----------
        //".htmlentities($rendered)."
        //-----------
        //</pre>";
        $this->assertEqual($canonical, $rendered);
        $this->assertNoPattern('/IMPLEMENTED/', $rendered);
    }