function testNewPageFieldForm()
 {
     $this->doLoginBasic();
     global $DB;
     $DB = $this->DB;
     $this->get('http://localhost/digitalfieldnotebooks/ajax_actions/notebook_page_field.php?action=create&unique=ABC123&notebook_page_id=1101');
     $this->checkBasicAsserts();
     $expected = Notebook_Page_Field::renderFormInteriorForNewNotebookPageField('ABC123');
     $results = json_decode($this->getBrowser()->getContent());
     $this->assertEqual('success', $results->status);
     $this->assertEqual($expected, $results->html_output);
 }
 function testRenderFormInteriorForNewNotebookPageField()
 {
     global $DB;
     $DB = $this->DB;
     $canonical = '';
     $canonical .= '<div class="notebook_page_field-label_metadata new-notebook-field-data">';
     $canonical .= '<div class="form-field-label">' . util_lang('metadata', 'properize') . '</div>';
     $canonical .= Metadata_Structure::renderControlSelectAllMetadataStructures('notebook_page_field-label_metadata_structure_id_ABC') . "\n";
     $canonical .= '</div>';
     $canonical .= '<div class="notebook_page_field-value_specific_metadata new-notebook-field-data">';
     $canonical .= '<div class="form-field-label">' . util_lang('metadata_specific_value', 'properize') . '</div>';
     $canonical .= '<select name="notebook_page_field-value_metadata_term_value_id_ABC" id="notebook_page_field-value_metadata_term_value_id_ABC" class="metadata_term_value_select_control">' . "\n";
     $canonical .= '  <option value="-1">-- ' . util_lang('nothing_from_the_list') . ' --</option>' . "\n";
     $canonical .= '</select>' . "\n";
     $canonical .= '</div>';
     $canonical .= '<div class="notebook_page_field-value_open_metadata new-notebook-field-data">';
     $canonical .= '<div class="form-field-label">' . util_lang('metadata_open_value', 'properize') . '</div>';
     $canonical .= '<input type="text" name="notebook_page_field-value_open_ABC" id="notebook_page_field-value_open_ABC" class="page_field_open_value" value=""/>' . "\n";
     $canonical .= '</div>';
     $rendered = Notebook_Page_Field::renderFormInteriorForNewNotebookPageField('ABC');
     //            echo "<pre>\n".htmlentities($canonical)."\n------------------\n".htmlentities($rendered)."\n</pre>";
     $this->assertEqual($canonical, $rendered);
     $this->assertNoPattern('/IMPLEMENTED/', $rendered);
 }
        foreach ($USER->cached_role_action_targets_hash_by_target_type_by_id['global_notebook'] as $glob_rat) {
            if ($glob_rat->action_id == $ACTIONS['create']->action_id || $glob_rat->action_id == $ACTIONS['edit']->action_id) {
                $has_permission = true;
                break;
            }
        }
    }
    // and if not that, then check specific perms
    if (!$has_permission) {
        $notebook_page = Notebook_Page::getOneFromDb(['notebook_page_id' => $notebook_page_id], $DB);
        if (!$notebook_page->matchesDb) {
            $results['note'] = util_lang('msg_record_missing') . ' : notebook_page ' . htmlentities($notebook_page_id);
            echo json_encode($results);
            exit;
        }
        $has_permission = $USER->canActOnTarget($ACTIONS['edit'], $notebook_page);
    }
}
if (!$has_permission) {
    $results['note'] = util_lang('no_permission');
    echo json_encode($results);
    exit;
}
# 3. branch behavior based on the action
#      create - return an appropriate form field set
if ($has_permission && $action == 'create') {
    $results['html_output'] = Notebook_Page_Field::renderFormInteriorForNewNotebookPageField($unique_str);
    $results['status'] = 'success';
}
echo json_encode($results);
exit;