Configuring Dataface

A place for users and developers of the Xataface to discuss and receive support.

Postby zopemgr » Sun Apr 16, 2006 2:04 am

Hi,

I have just discovered Dataface, and it looks very interesting. However I have a few questions (of course!)

Is it possible to configure Dataface so that, for example, only the edit capability is present? The reason why is that I have some tables that are configuration information for other applications, but I don't want anyone to be able to delete or add or even search for records - just edit them.

Another question - is is it possible to not display fields from a table? Can you somehow mark them as "invisible" so they can't be edited?

And one more - is there a way to enter times in a data entry field, and not just dates? I see you can check for valid dates, and even pop up a calendar, but can you do something similar with times?

I'm sure I'll think of a few more once I get going!

Andy
zopemgr
 
Posts: 66
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Sun Apr 16, 2006 2:45 pm

>Is it possible to configure Dataface so that, for example, only the edit capability is present?

Yes this is possible and there is more than one way to do it. It sounds like you may just want to use the api directly to just create an edit form. Alternatively you can manipulate the request query at the beginning of your index.php file to force the dataface application to perform only the specified action. I will give examples of both below.

>is is it possible to not display fields from a table? Can you somehow mark them as "invisible" so they can't be edited?

Yes. You can do this either with permissions, or, if you use the api to create the edit form, you can specify which fields should be included in the form.

> is there a way to enter times in a data entry field, and not just dates?
Not at this time. However this would be a very easy thing to add if you think it would be useful. What kind of interface would you suggest for inputing time: pull-downs for hour/minute/second, or something else?

Working with the API:

There are a few entry points to work with the api located in the dataface-public-api.php file. Some of the more useful functions include:
df_create_new_record_form() : builds a form to insert new records into a table.
df_create_edit_record_form() : builds a form to edit an existing record.
df_create_new_related_record_form() : builds a form to add a new record to a relationship
df_create_existing_record_form() : builds a form to add an existing record to a relationship
df_get_record() : loads a record from the database

Here is a code sample of a page that would display a form to edit a record:

Assume that we have a table named 'Profiles' with the following schema:
ProfileID INT(11) Primary key
FirstName VARCHAR(64),
LastName VARCHAR(64),
Blurb TEXT)

Code: Select all
require_once '/path/to/dataface-public-api.php';
df_init(__FILE__, '/url/to/dataface');

//load a record to edit
$query = array('ProfileID'=>10);
$record =& df_get_record('Profiles', $query);
    // loads the Profile with ProfileID=10

$form =& df_create_edit_record_form($record);
    // Builds a form to edit the record
if ( $form->validate() ){
    // the form is validated
    $res = $form->process(array(&$form, 'save'), true);
        // process the form using the form's save() method (defined by Dataface)
    if ( PEAR::isError($res) ){
        trigger_error($res->toString(), E_USER_ERROR);
    }

    header('Location: '.$_SERVER['PHP_SELF']);
    exit;
}

// if we are here then either the form did not validate or it was not submitted..
// display the form
$form->display();





This is the general idea. Note that the Dataface_QuickForm extends the HTML_QuickForm class (http://pear.php.net/package/html_quickform) so you can work with it the same way as any QuickForm.

Also note that the call to df_create_edit_record_form() takes an optional 2nd parameter that is an array of field names to include in the form. Without this argument it will include all of the fields (for which permission is defined).

e.g.:
Code: Select all
$form =& df_create_edit_record_form($record, array('FirstName'));
    // creates form with only the FirstName field
$form =& df_create_edit_record_form($record, array('FirstName', 'Blurb'));
    // creates form with only the FirstName and Blurb fields.
//etc...




Now you can also use delegate classes to define permissions on fields to make them visible, editable, or invisible. For example, if we want to make the FirstName and LastName fields read only we could define the following methods in the delegate class for the Profiles table:

Code: Select all





The permissions will apply whether you are using the Dataface Application for display or if you use the API.

Now, suppose you would rather continue to use the full Dataface Application (instead of using the API to create the form). You can do this with a mix of conf.ini settings and manipulation in the REQUEST variables of your index.php file (for your application).

First, if you add any of the following directives to the beginning of the conf.ini file, you can effectively hide portions of the application:

Code: Select all
hide_table_result_stats = true  ;; Hides the part that says "Found x or y records in table z"
hide_result_controller = true ;; Hides the next and previous buttons and jump menu
hide_search = true ;; hides the search in the upper right
hide_view_tabs = true ;; Hides the "Details", "List", "Find" tabs.
hide_nav_menu = true ;; Hides the Navigation menu (to choose which table you want to edit.



This will just hide these options from the interface - they won't prevent people from accessing these things by going directly to the url.

The last thing that you can do (at the beginning of your index.php file for your application) is manipulate the GET / POST requests so that the Edit action is ALWAYS specified. (However the following bit will change in future versions so use this method at your own risk knowing that you may have to make changes come version 0.6.

Code: Select all

$_REQUEST['-action'] = 'browse';//
$_GET['-action'] = 'browse';  //  forces the action to "browse" so that only editing is allowed.
if ( isset($_REQUEST['-new']) ){
    unset( $_REQUEST['-new']);
    unset( $_GET['-new']);    // disables creation of new records
}


The reason that the contents of this post are not documented well yet, is because I am close to releasing version 0.6 which is intended to be the first release of Dataface that is designed to be a full-fledged application framework, and I don't want to document anything that may change. As it stands, everything in this post will continue to be supported (except possibly the last code snippet about the modification of request variables.

Hope this helps.

Best regards

Steve Hannah
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby zopemgr » Mon Apr 17, 2006 4:42 am

Steve,

Thanks for the very comprehensive reply!

I'll try some of the things you suggested.

As for the time field, I would suggest a drop down, with the possibility of defining a granularity - e.g. 10 second intervals instead of 1 second, etc.

Many Thanks

Andy
zopemgr
 
Posts: 66
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 21 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved