<?xml version="1.0"?>
<record><wiki id="wiki?page_id=25">
	<page_name>conf.ini_file</page_name>
	<page_id>25</page_id>
	<page_title>conf.ini_file</page_title>
	<content>==conf.ini File==

[[toc]]

The conf.ini file is where most of the application-level configuration information is stored for a Xataface application.  It contains information such as:

* database connection information
* which tables should appear in the tables menu.
* [[preferences|preference settings]]
* [[authentication]] settings
* which add-on [[modules]] are to be used
* output caching settings
* history/undo settings
* other misc settings.

Every conf.ini file must contain at least the following sections:


{| class=&quot;listing listing2&quot;
|-
! Name
! Description
! Version
|-
| _database
| Contains database connection info.
| all
|-
| _tables
| Contains a list of tables that are to be included in the navigation menu of the application.
| all
|}


The following optional sections may also be included:

{| class=&quot;listing listing2&quot;
|-
! Name
! Description
! Version
|-
| [http://xataface.com/documentation/how-to/disallow_tables _allowed_tables]
| Specifies tables that should be explicitly allowed to override disallowed tables listed or matched in the [http://xataface.com/documentation/how-to/disallow_tables _disallowed_tables] section.
| 0.7
|-
| [[_auth]]
| Contains information about [[authentication]].
| 0.6
|-
| [http://xataface.com/documentation/how-to/disallow_tables _disallowed_tables]
| A list of tables or patterns that match tables that should be blocked from being accessed directly through the application.  By default any table beginning with an underscore, &apos;dataface_&apos;, or ending in &apos;__history&apos; are blocked.  This prevents unintended access to some of the automatically created tables in Xataface.
| 0.7
|-
| _feed
| Configuration options for [[Introduction_to_RSS_Feeds_in_Xataface|RSS feeds]] that are generated by the application.
| 1.0
|-
| _history
| Settings pertaining to the [http://xataface.com/documentation/how-to/history-howto history feature] (e.g. whether it has been enabled).
| 0.7
|-
| _index
| Settings for the full site search indexing.
| 1.0
|-
| _modules
| A list of [[modules]] that are enabled for this application.
| 1.0
|-
| [[_output_cache]]
| Output cache settings.  Using output caching can dramatically improve performance for busier sites.
| 0.8
|-
| _themes
| A list of the themes that are to be applied to the application.
| 0.8
|}

===Stand-alone Attributes===

Stand-alone attributes for an INI file must appear at the beginning of the INI file (before any of the sections).  The conf.ini may contain the following stand-alone attributes.

{| class=&quot;listing listing2&quot;
|-
! Name
! Description
! Values
! Version
|-
| cache_queries
| Enables query caching.  Enabling this feature can yield drastic performance improvements especially on busy sites with large databases.
| boolean (0 or 1)
| 1.2

|-
| cache_queries_log
| Enables logging of query caching to the file /tmp/querylog.log so that you can tell whether your queries are being cached, and which ones are being cached.
| boolean (0 or 1)
| 1.2

|-
| default_action
| The default action to be performed if it is not explicitly specified in the query (e.g. &apos;list&apos;, &apos;find&apos;, &apos;edit&apos;).  Default is &apos;list&apos;.
| string
| 0.6
|-
| debug
| If this is set to 1, then the application will run in debug mode which displays the available slots and blocks on the screen, along with some other debug information.
| 0 or 1 (default is 0)
| 0.6

|-
| default_browse_action
| The default action to perform in the details tab.  E.g. When you click on the &quot;details&quot; tab there are a number of sub-tabs including &apos;view&apos;, &apos;edit&apos;, etc... .   The default value for this directive is &apos;view&apos;.  If you want to go directly to the edit form when clicking on a record in list view, you would set &apos;&apos;default_browse_action&apos;&apos; to &apos;edit&apos;.
| string
| 0.6
|-
| default_language
| The default language to use.  This is the 2-digit ISO language code.  If this value is not specified it defaults to the first language listed in the &apos;&apos;[languages]&apos;&apos; section.
| string (2-digit ISO language code)
| 0.6
|-
| default_limit
| The default limit (i.e. the number of records to show per page) if none is explicitly specified in the query.  Default is 30.
| int
| 0.6
|-
| default_table
| The default table to show if none is specified by the query.  If you do not define this value, then the first table in the &apos;&apos;[_tables]&apos;&apos; section is used.
| string
|0.6
|-
| disable_session_ip_check
| Default behaviour automatically tracks the IP address of the user when they log in.  If a request is made for a session from a different IP then the session is automatically destroyed and the user is logged out.
| boolean
| 1.3rc4

|-
| title
| A title for the application (appears in the browser title bar).
| string
| 0.6
|-
| usage_mode
| The usage mode of the application.  If this value is set to &apos;&apos;edit&apos;&apos;, then ajax inline editing is enabled (i.e. you can click on any value in the application to edit it inline.
| &apos;view&apos; or &apos;edit&apos;
| 0.6
|}

===Example 1: A simple conf.ini file===

&lt;code&gt;
[_database]
	host=&quot;localhost&quot;
	name=&quot;mydb&quot;
	user=&quot;mydbuser&quot;
	password=&quot;foo&quot;
	
[_tables]
webpage_sites=&quot;Websites&quot;
translations = &quot;Translations&quot;
packages=&quot;Packages&quot;
users=Users
proof_jobs=&quot;Jobs&quot;
webpage_status=&quot;Webpages Status&quot;

&lt;/code&gt;

===Example 2: A more complex conf.ini file===

&lt;code&gt;
;debug=1
;default_action=home
;google_translate_url=&quot;http://weblite-dns2.com/proxy.php&quot;
google_translate_url=&quot;http://ec2-75-101-244-123.compute-1.amazonaws.com/proxy.php&quot;
title=&quot;Web Lite Translate&quot;
default_price_per_word=0.15

;;Configuration settings for application
title=&quot;translation_weblite_ca&quot;
scriptUrl=&quot;http://translation.weblite.ca/index.php&quot;
multilingual_content=1


[_database]
	host=&quot;localhost&quot;
	name=&quot;mydb&quot;
	user=&quot;mydbuser&quot;
	password=&quot;foo&quot;
	
[_tables]
    webpage_sites=&quot;Websites&quot;
    translations = &quot;Translations&quot;
    packages=&quot;Packages&quot;
    users=Users
    proof_jobs=&quot;Jobs&quot;
    webpage_status=&quot;Webpages Status&quot;


[_auth]
	users_table=users
	username_column=username
	password_column=password
	secret_code=&quot;ljkasdfjkldsafliasdoiudsfoi&quot;
	allow_register=1
	session_timeout=999999999
	
[_modules]
	modules_ShoppingCart=&quot;modules/ShoppingCart/ShoppingCart.php&quot;

[ShoppingCart_taxes]
	;; This section is necessary to declare that we have NO taxes.
	
[metatags]
	keywords = &quot;translation, translate&quot;
	description = &quot;Good translation service&quot;
	
;[_output_cache]
;	enabled=1

[_mail]
	func=mail2
	
&lt;/code&gt;

</content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=82">
	<page_name>Creating_Printable_Reports</page_name>
	<page_id>82</page_id>
	<page_title>Creating a Custom Printable Report</page_title>
	<content>==Creating a Printable Report==

[[toc]]

It is often useful to provide your users with a printable report that is generated from your database.  Although Xataface doesn&apos;t include an explicit reporting module to allow the end users to create their own reports, you (the developer) can still quite easily produce a report by creating a custom action.  

This report will be subject to the user&apos;s sorting and searching preferences.  E.g. if the user searches for only books about &quot;frogs&quot;, then when he clicks on your printable report it will only display those records that match the query (i.e. only books about frogs).

===Requirements for our report===

# Report will be run against the &quot;products&quot; table (using the WebAuction application).
# Report should be accessible by clicking an icon in the top right of the list view (i.e. the resultlist actions).
# Report should display the product ID, product name, photo, and description.  One product per page.


===Adding the Icon to our Application===

We&apos;ll start out by finding an appropriate icon to use for our action.  There are loads of free icons that you can download (please observe and respect the license agreement of any icon library that you use).  Two good free icon libraries include:

# [http://www.famfamfam.com/lab/icons/silk/ FamFamFam Silk Icons]
# [http://tango.freedesktop.org/Tango_Icon_Library Tango Icon Library]

Once you have found the icon you want to use, just upload it somewhere inside your application&apos;s directory.  It might be a good idea to create a directory to store your images if you haven&apos;t already.  An appropriate name might by &apos;&apos;images&apos;&apos;.  For this example, we&apos;ll use the [[Image:http://dev.weblite.ca/phpimageserver/photos/icons/printer.png]] icon from the FamFamFam icon library.  So we upload this icon to
 %APPLICATION_PATH%/images/printer.png

Next we need to create an entry in our application&apos;s [[actions.ini file]] so that Xataface knows about our action, and where we want its icon to be displayed.  We&apos;ll start out with a basic definition that just specifies the icon for the action, and the &apos;&apos;category&apos;&apos; of the action.

&lt;code&gt;
[printable_report]
    icon=&quot;{$site_url}/images/printer.png&quot;
    category=result_list_actions
    description=&quot;See this product list in a printable format&quot;
&lt;/code&gt;

The &apos;&apos;result_list_actions&apos;&apos; category setting means that the icon for our action will be included along with the result list actions, which are located in the top right corner in the list tab.  Now if we reload our application and look at the &quot;list&quot; tab, you&apos;ll see that the icon group in the top right now includes our icon:

[[Image:http://media.weblite.ca/files/photos/Picture%20-5.png?max_width=640]]

If you don&apos;t see this icon, but see the text &quot;printable_report&quot; instead, then you have entered an incorrect path to the icon in the &apos;&apos;icon&apos;&apos; directive.  If you don&apos;t see an icon at all or any text, then your &apos;&apos;category&apos;&apos; directive may be incorrect.  Check that it is exactly &quot;result_list_actions&quot;.

If you mouse over your icon you&apos;ll see the text that you specified as your &apos;&apos;description&apos;&apos; directive for the action:

[[Image:http://media.weblite.ca/files/photos/Picture%20-6.png?max_width=640]]

You&apos;ll notice, if you try to click on your icon, that nothing happens.  This is because we haven&apos;t yet specified a URL for your action.  We&apos;ll wait to specify our URL, until we&apos;ve built the back-end of our action (i.e. the actual report).

===Creating the Actual Report===

Most reports involve the following pieces:

# Fetch the found set of records from the database.
# Loop through the found set and output some information about each record.
# Optionally use a template to integrate the report into your application&apos;s look and feel.

All reports will be placed in the framework of a custom Xataface action.  In our case we add a file to our application &apos;&apos;actions&apos;&apos; directory named after our action:
 %APPLICATION_PATH%/actions/printable_report.php

with the following contents:

&lt;code&gt;
&lt;?php
class actions_printable_report {
    function handle(&amp;$params){
    	echo &quot;Hello world!!!&quot;;
    }
}
&lt;/code&gt;

Please note the following about this snippet:

# The action was placed in a file &apos;&apos;actions/printable_report.php&apos;&apos; because the action is named &apos;&apos;printable_report&apos;&apos; (referring to our definition in the &apos;&apos;[[actions.ini file]]&apos;&apos;.  If the action was named &apos;&apos;foo&apos;&apos;, then we would place our action in file &apos;&apos;actions/foo.php&apos;&apos;.
# The &apos;&apos;printable_report.php&apos;&apos; file contains a single class named &apos;&apos;actions_printable_report&apos;&apos; after the name of the action.
# The action class contains a single method &apos;&apos;handle&apos;&apos; which handles the request for the action (i.e. outputs the report the way we like).  This method must exist and me named exactly &apos;&apos;handle&apos;&apos;.
# The &apos;&apos;handle&apos;&apos; method takes a single &apos;&apos;&amp;$params&apos;&apos; parameter which contains some parameters that may be passed to the action.  We won&apos;t be dealing with these in this example.


Before proceeding, let&apos;s try accessing our action just to make sure that we&apos;re on the right track.  Point your browser to 
 http://example.com/yourapplication/index.php?-action=printable_report

Note that you don&apos;t point our web browser directly to your action php file (in the &apos;&apos;actions&apos;&apos; directory.  Rather you point it to your application&apos;s entry point (index.php file), and specify the action via the &apos;&apos;-action&apos;&apos; GET parameter.  Your web browser should display something like:

[[Image:http://media.weblite.ca/files/photos/Picture%204.png?max_width=640]]

If you get a blank white screen, then you should check your error log to see where the error is occuring.  See [[Troubleshooting]] for general Xataface troubleshooting strategies in this case.

Now that we have all of the formalities out of the way, we can proceed to meat of our report.

====Retrieving the Found Set====

Let&apos;s build onto our action now.  First we will load the found set of records as follows:

&lt;code&gt;
&lt;?php
class actions_printable_report {
    function handle(&amp;$params){
    	$app =&amp; Dataface_Application::getInstance();
    	$query =&amp; $app-&gt;getQuery();
    	
    	if ( $query[&apos;-table&apos;] != &apos;products&apos; ){
    		return PEAR::raiseError(&apos;This action can only be called on the Products table.&apos;);
    	}
    	
    	$products = df_get_records_array(&apos;products&apos;, $query);
    	
    }
}
&lt;/code&gt;

Things to note in this snippet:

# We start be loading a reference to the &apos;&apos;Dataface_Application&apos;&apos; object.
# We then use the &apos;&apos;Dataface_Application&apos;&apos; object to load the current query.  This is essentially an associative array of all of the GET parameters, but with some guaranteed attributes such as &apos;&apos;-table&apos;&apos; and &apos;&apos;-action&apos;&apos;.
# In our particular action we are designing it to only work for the &apos;&apos;products&apos;&apos; table so we do a check on the query parameters to make sure that this is the case.  If someone tries to run this action from outside the products table (e.g. if -action=foo) then an error will be displayed.
# We use the df_get_records_array() function to return all matching records on the products table.  It returns an array of [[Dataface_Record]] objects.


====Overriding -skip and -limit====

Xataface allows the user to specify the number of records to display and the position in the found set to start from by adding the &apos;&apos;-skip&apos;&apos; and &apos;&apos;-limit&apos;&apos; GET parameters to a request.  If these are omitted, then default values of 0 and 30 are used respectively.  You may notice that if you click &quot;Next&quot; in list view, you see &apos;-skip&apos; and &apos;-limit&apos; parameters automatically added to the URL.

&apos;&apos;df_get_records_array&apos;&apos; respects the -limit and -skip parameters that are specified in the query.  I.e. if -skip and -limit are omitted it will return only the first 30 records from the found set.  If -skip=1 and -limit=10 then it will return 10 records starting from the 2nd record (2nd becuase -skip=0 would point to the first record).  This may be desired behavior for your report, but in some reports you may want to print off the entire found set.  If this is the case, you will want to explicitly set the -skip and -limit parameters in the &apos;&apos;$query&apos;&apos; array before passing it to &apos;&apos;df_get_records_array&apos;&apos;.  E.g.:

&lt;code&gt;
$query =&amp; $app-&gt;getQuery();
$query[&apos;-skip&apos;] = 0;
$query[&apos;-limit&apos;] = 10000;
$products = df_get_records_array(&apos;products&apos;, $query);
&lt;/code&gt;


====Looping through and Printing Product Info====

Now comes the fun part.  We&apos;re just going to loop through our found set and print off the product information:

&lt;code&gt;


foreach ($products as $p){
	

	echo &apos;&lt;table&gt;&apos;
		.&apos;&lt;tr&gt;&lt;th&gt;Product ID&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_id&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
		.&apos;&lt;tr&gt;&lt;th&gt;Product Name&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_name&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
		.&apos;&lt;tr&gt;&lt;th&gt;Description&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_description&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
		.&apos;&lt;tr&gt;&lt;th&gt;Photo&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_image&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
		.&apos;&lt;/table&gt;&apos;;
}

&lt;/code&gt;


The entire action at this point will look like:

&lt;code&gt;

&lt;?php
class actions_printable_report {
    function handle(&amp;$params){
    	$app =&amp; Dataface_Application::getInstance();
    	$query =&amp; $app-&gt;getQuery();
    	$query[&apos;-skip&apos;] = 0;
		$query[&apos;-limit&apos;] = 10000;
		
    	if ( $query[&apos;-table&apos;] != &apos;products&apos; ){
    		return PEAR::raiseError(&apos;This action can only be called on the Products table.&apos;);
    	}
    	
    	$products = df_get_records_array(&apos;products&apos;, $query);
    	foreach ($products as $p){
	

			echo &apos;&lt;table&gt;&apos;
				.&apos;&lt;tr&gt;&lt;th&gt;Product ID&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_id&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
				.&apos;&lt;tr&gt;&lt;th&gt;Product Name&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_name&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
				.&apos;&lt;tr&gt;&lt;th&gt;Description&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_description&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
				.&apos;&lt;tr&gt;&lt;th&gt;Photo&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_image&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
				.&apos;&lt;/table&gt;&apos;;
		}
    	
    }
}
&lt;/code&gt;

Now we refresh our action in the web browser, or point the browser again to:
 http://example.com/yourapplication/index.php?-action=printable_report&amp;-table=products
 
It should display something like:

[[Image:http://media.weblite.ca/files/photos/Picture%205.png?max_width=640]]

If you get a blank white screen, please check out the [[Troubleshooting]] section for general Xataface troubleshooting strategies.

====Adding a Little Style====

It is a good idea to at least provide the proper HTML HEAD and BODY tags for your report.  And to help make things a little nicer looking we&apos;re going to add some CSS styles to:

# Make the table field labels vertically aligned to the top.
# Change the font to helvetica.

This is easy to do with simple echo statements:

&lt;code&gt;
echo &apos;&lt;html&gt;&lt;head&gt;&apos;
	.&apos;&lt;title&gt;Printable Report&lt;/title&gt;&apos;
	.&apos;&lt;style type=&quot;text/css&quot;&gt;&apos;
	.&apos;	th { vertical-align: top}&apos;
	.&apos;&lt;/style&gt;&apos;
	.&apos;&lt;/head&gt;&apos;
	.&apos;&lt;body&gt;&apos;;
	
	//...
	


&lt;/code&gt;

So our finished action looks like:


&lt;code&gt;
&lt;?php
class actions_printable_report {
    function handle(&amp;$params){
    	$app =&amp; Dataface_Application::getInstance();
    	$query =&amp; $app-&gt;getQuery();
    	$query[&apos;-skip&apos;] = 0;
		$query[&apos;-limit&apos;] = 10000;
		
    	if ( $query[&apos;-table&apos;] != &apos;products&apos; ){
    		return PEAR::raiseError(&apos;This action can only be called on the Products table.&apos;);
    	}
    	
    	$products = df_get_records_array(&apos;products&apos;, $query);
    	
    	
    	
    	echo &apos;&lt;html&gt;&lt;head&gt;&apos;
			.&apos;&lt;title&gt;Printable Report&lt;/title&gt;&apos;
			.&apos;&lt;style type=&quot;text/css&quot;&gt;&apos;
			.&apos;	th { vertical-align: top}&apos;
			.&apos;&lt;/style&gt;&apos;
			.&apos;&lt;/head&gt;&apos;
			.&apos;&lt;body&gt;&apos;;
    	foreach ($products as $p){
	

			echo &apos;&lt;table&gt;&apos;
				.&apos;&lt;tr&gt;&lt;th&gt;Product ID&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_id&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
				.&apos;&lt;tr&gt;&lt;th&gt;Product Name&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_name&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
				.&apos;&lt;tr&gt;&lt;th&gt;Description&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_description&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
				.&apos;&lt;tr&gt;&lt;th&gt;Photo&lt;/th&gt;&lt;td&gt;&apos;.$p-&gt;htmlValue(&apos;product_image&apos;).&apos;&lt;/td&gt;&lt;/tr&gt;&apos;
				.&apos;&lt;/table&gt;&apos;;
		}
		
		echo &apos;&lt;/body&gt;&lt;/html&gt;&apos;;
    	
    }
}
&lt;/code&gt;



===Connecting the Icon to the Action===

FInally it is time to connect our Icon to our Action.  We do this by adding a &apos;&apos;url&apos;&apos; directive for the action in the &apos;&apos;[[actions.ini file]]&apos;&apos;:


&lt;code&gt;
[printable_report]
    icon=&quot;{$site_url}/images/printer.png&quot;
    category=result_list_actions
    description=&quot;See this product list in a printable format&quot;
    url=&quot;{$app-&gt;url(&apos;-action=printable_report&apos;)}&quot;
&lt;/code&gt;

Explanation of the &apos;&apos;url&apos;&apos; directive in this snippet:

* The &apos;&apos;url&apos;&apos; method of the &apos;&apos;[[Dataface_Application]]&apos;&apos; object is used to generate a URL with the user&apos;s current query settings, but with the &apos;&apos;-action&apos;&apos; parameter set to &apos;&apos;printable_report&apos;&apos;.

Now if we reload our application, go to the list tab of the &apos;&apos;products&apos;&apos; table and click on our icon, it should take us to our action:

[[Image:http://media.weblite.ca/files/photos/Picture%207.png?max_width=640]]

===Trying out the action on different found sets with different sort orders===

One of the cool things about this action is that it is tied directly into the Xataface find settings so that th user is able to search for a subset of products and run our report on only those products that were found.  The user can also perform a sort on any column and this sort will be respected by our report.

===Hiding Icon from Other Tables===

Since our action is only intended to operate on the &apos;&apos;products&apos;&apos; table it probably isn&apos;t a good idea to make the icon visible for every other table.  For example, if you go to the list view of the &apos;&apos;users&apos;&apos; table, you&apos;ll see the printer icon in the top right just like it appears for the &apos;&apos;products&apos;&apos; table.  Clicking on it should display our error:

[[Image:http://media.weblite.ca/files/photos/Picture%206.png?max_width=640]]

We will use a &apos;&apos;condition&apos;&apos; directive for our action to hide it from tables other than the &apos;&apos;products&apos;&apos; table as follows:

 condition=&quot;$query[&apos;-table&apos;] == &apos;products&apos;&quot;
 
So our action will now look like:

&lt;code&gt;
[printable_report]
    icon=&quot;{$site_url}/images/printer.png&quot;
    category=result_list_actions
    description=&quot;See this product list in a printable format&quot;
    url=&quot;{$app-&gt;url(&apos;-action=printable_report&apos;)}&quot;
    condition=&quot;$query[&apos;-table&apos;] == &apos;products&apos;&quot;
&lt;/code&gt;

Now if you reload the list for the &apos;&apos;users&apos;&apos; table you&apos;ll notice that the printer icon is now gone.  But returning to the &apos;&apos;products&apos;&apos; table shows our action still alive and well.

===Locking Down our Action with Permissions===

In our case we don&apos;t want our action to be accessible to all users.  Only administrators.  Xataface permissions and all its possibilities are beyond the scope of this tutorial, but we still want to demonstrate how to lock down this action.  The WebAuction application into which this action is being installed defines a permission called &apos;&apos;reports&apos;&apos; which only administrators have.  We will use this permission to limit access to this action as follows in the actions.ini file:
 permission=reports

So the actions.ini file will now look like:
&lt;code&gt;
[printable_report]
    icon=&quot;{$site_url}/images/printer.png&quot;
    category=result_list_actions
    description=&quot;See this product list in a printable format&quot;
    url=&quot;{$app-&gt;url(&apos;-action=printable_report&apos;)}&quot;
    condition=&quot;$query[&apos;-table&apos;] == &apos;products&apos;&quot;
    permission=reports
&lt;/code&gt;

Now only administrators will see our icon, and if non-administrators attempt to access out action by typing in its URL directly, they will receive an &quot;Access Denied&quot; message.

</content>
	<keywords></keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=74">
	<page_name>GettingStarted:first_application</page_name>
	<page_id>74</page_id>
	<page_title>Creating your First Application</page_title>
	<content>==Creating Your First Application==

Build a simple Xataface application.

For our first Xataface application we will try to build a web site for Faculty of Widgetry (From the example in the &quot;Why Use Xataface&quot; page). The web site needs to store information about programs and courses. An entity-relationship diagram (ERD) for this website is included below:

[[Image:http://xataface.com/documentation/tutorial/getting_started/er-diagram.png]]

As the ERD shows, our database will need 2 tables (Course and Program). Our next step is to build this database. You can use any MySQL database administration tool to builld the database. My personal tool of choice is PHPMyAdmin.

===Step 1: Creating the database using PHPMyAdmin===

The following steps describe the procedure for creating this database using PHPMyAdmin.

# At the main menu of PHPMyAdmin, type &apos;FacultyOfWidgetry&apos; into the &apos;Create new database field&apos; as follows: &lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt;[[Image:http://xataface.com/documentation/tutorial/getting_started/new_database.gif]] &lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt;Then click &apos;Create&apos;.
# First we will create the &apos;Course&apos; table to hold course information. In the &apos;FacultyOfWidgetry&apos; page, fill in the &apos;Create new table text field as follows: &lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt;[[Image:http://xataface.com/documentation/tutorial/getting_started/create_table.gif]] &lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt; Then click &apos;Go&apos;.
# This should bring up a form to specify the fields for the course table: &lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt;[[Image:http://xataface.com/documentation/tutorial/getting_started/course-table-def-small.gif]] &lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt; Then click &quot;Save&quot;. The resulting SQL to create the Course table is as follows:&lt;code&gt;
CREATE TABLE `Course` (
 `CourseID` int(11) NOT NULL auto_increment,
 `ProgramID` int(11),
 `CourseTitle` varchar(64) NOT NULL default &apos;&apos;,
 `CourseDescription` text NOT NULL,
 `HTMLOutline` text NOT NULL,
 `PDFOutline` longblob NOT NULL,
 `PDFOutline_mimetype` varchar(64),
 `Subject` varchar(128) NOT NULL default &apos;&apos;,
 `CourseNumber` varchar(10) NOT NULL default &apos;&apos;,
 `Credits` int(5) NOT NULL default &apos;0&apos;,
 `LastModified` timestamp NOT NULL default CURRENT_TIMESTAMP,
 PRIMARY KEY (`CourseID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT=&apos;Store courses&apos; AUTO_INCREMENT=1 ;
&lt;/code&gt;
#In a similar fashion, create the Program table. The resulting SQL for this table is:&lt;code&gt;
CREATE TABLE `Program` (
 `ProgramID` int(11) NOT NULL auto_increment,
 `ProgramName` varchar(64) NOT NULL default &apos;&apos;,
 `ProgramDescription` text NOT NULL,
 `HTMLOutline` text NOT NULL,
 `PDFOutline` longblob NOT NULL,
 `PDFOutline_mimetype` varchar(32),
 `AdmissionDeadline` date NOT NULL default &apos;0000-00-00&apos;,
 `LastModified` timestamp NOT NULL default CURRENT_TIMESTAMP,
 PRIMARY KEY (`ProgramID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT=&apos;Academic Program&apos; AUTO_INCREMENT=1 ;
&lt;/code&gt;
# The database has been created with 2 tables: Program and Course. We can now move on to building the Xataface application.

===Step 2: Create Xataface Application===

Our Xataface application will provide a user-friendly front-end to our database. A basic application consists of a directory with a configuration file and an entry page (PHP file). Xataface comes with a PHP setup script (called makesite) to create the skeleton for your application. Alternatively you can set up the application manually.

Note: For the following instructions and examples, my Daface installation is located at /Users/shannah/Sites/dataface and the URL for the installation is http://localhost/~shannah/dataface.

====Method 1: Setting up application with the &apos;makesite&apos; script====

# From the command prompt, navigate to the dataface directory. (in my case &apos;&apos;/Users/shannah/Sites/dataface&apos;&apos;).
# This directory contains a file named &apos;makesite&apos;. It is a PHP script that can be used to build a website powered by Xataface. To find out the usage options for this script you can simply call the script with no parameters. E.g.,&lt;code&gt; 
stevepbook:~/Sites/dataface shannah$ ./makesite
&lt;/code&gt;
# This will give you usage instructions for the script as follows:&lt;code&gt;
makesite: invalid options entered.

 Usage: makesite &lt;site_path&gt; &lt;db_user&gt;:&lt;db_pass&gt;@&lt;db_host&gt;/&lt;db_name&gt; &lt;dataface_url&gt;
 or
 php makesite &lt;site_path&gt; &lt;db_user&gt;:&lt;db_pass&gt;@&lt;db_host&gt;/&lt;db_name&gt; &lt;dataface_url&gt;
 where 
 &lt;site_path&gt; = The path (absolute or relative) to your application directory.
 &lt;db_user&gt; = The MySQL username to connect to the database
 &lt;db_pass&gt; = The User&apos;s password to connect to the database
 &lt;db_host&gt; = The MySQL host name.
 &lt;db_name&gt; = The name of the mysql database for the application.
 &lt;dataface_url&gt; = The URL to the Xataface installation

 Examples:

 makesite ../FacultyOfWidgetry root:password@localhost/FacultyOfWidgetry /dataface

 The above command would create a site at ../FacultyOfWidgetry (i.e., the Faculty of 
 Widgetry directory in the parent directory. The database used for this site is 
 located at localhost, and the database name is FacultyOfWidgetry. The username
 to connect to the database is root and his password is password.
&lt;/code&gt;
# We create our FacultyOfWidgetry site using the following command:&lt;code&gt;
./makesite ../FacultyOfWidgetry \
    root@localhost/FacultyOfWidgetry \
    http://localhost/~shannah/dataface
&lt;/code&gt;
# This will create our application in the FacultyOfWidgetry folder if everything worked ok. The contents of the folder will look like: &lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt;[[Image:http://xataface.com/documentation/tutorial/getting_started/directory-structure-1.gif]]

You may be wondering what these files. Here is the short version (Read the next section &quot;Creating applications manually&quot; for more detailed information about the contents of these files.

The index.php file is the entry point for your application (i.e., you point the web browser at this file to use the application. 
The conf.ini file contains database connection settings and some other minor settings, like what should appear in the navigation menu.
The tables/Program (tables/Course) directory can contain configuration files specific to the Program (Course) table. More on that later. 

# Point your web browser to the FacultyOfWidgetry directory to see the application: &lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt;[[Image:http://xataface.com/documentation/tutorial/getting_started/basic-application-1.gif]]
#Your application is now created. It will enable you to add, edit, delete, and find records in either the Course table or the Program table. There will be more on the basics of using this application in the next section.	

====Method 2: Setting up application manually====

Using the makesite script as described above is the recommended way to set up an application because it saves time. However, it is very easy to set up the application manually. Just follow these steps:

# Create a directory for the application somewhere in your web site (preferably outside your xataface directory). We will call our directory &apos;FacultyOfWidgetry&apos;. ):&lt;code&gt;
mkdir FacultyOfWidgetry
&lt;/code&gt;
# Create a PHP file to serve as the access point for the application. Generally we will name this file &apos;index.php&apos;, but you can name it anything. Place the following contents in the index.php file:&lt;code&gt;
&lt;?
require_once &apos;/path/to/dataface/dataface-public-api.php&apos;;
df_init(__FILE__, &apos;http://yourdomain.com/dataface&apos;);
$app =&amp; Dataface_Application::getInstance();
$app-&gt;display();
&lt;/code&gt;&lt;nowiki&gt;&lt;p&gt;OK, I guess some explanations are in order.&lt;/p&gt;&lt;p&gt;
The first line imports the all of the public functions for dataface from the dataface-public-api.php file.&lt;/p&gt;&lt;p&gt;
The second line initializes the application for the current directory and specifies the URL to the dataface installation.&lt;/p&gt;&lt;p&gt;
The third line obtains an instance to the Application object - the core of your Dataface application.&lt;/p&gt;&lt;p&gt;
The fourth line simply displays the application.&lt;/p&gt;&lt;/nowiki&gt;
# Create a file named &apos;conf.ini&apos; to contain database connection information. Its contents should be:&lt;code&gt;
[_database]
	host = &quot;localhost&quot;
	user = &quot;dbuser&quot;
	password = &quot;secret&quot;
	name = &quot;FacultyOfWidgetry&quot;

[_tables]
	Course = &quot;Course&quot;
	Program = &quot;Program&quot;
&lt;/code&gt;&lt;nowiki&gt;&lt;p&gt;&lt;b&gt;Explanations:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;There are 2 sections in this INI file: &apos;_database&apos;, and &apos;_tables&apos;.&lt;/p&gt;&lt;p&gt;
The &apos;_database&apos; section specifies the database connection information for the MySQL database.&lt;/p&gt;&lt;p&gt;
The &apos;_tables&apos; section specifies which tables will be included in the navigation menu for the application.&lt;/p&gt;&lt;/nowiki&gt;
# At this point, the application is functional. However there is one more thing that should be done for security reasons. The conf.ini file contains sensitive password information and should not be served to the web. We will create an .htaccess file to tell Apache NOT to serve this (or any) .ini file. The .htaccess file should contain:&lt;code&gt;
&lt;FilesMatch &quot;\.ini$&quot;&gt;
	Deny from all
&lt;/FilesMatch&gt;&lt;/code&gt;
# The directory structure of your application will now look like: &lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt;[[Image:http://xataface.com/documentation/tutorial/getting_started/basic-app-dir-structure-manual-1.gif]]&lt;nowiki&gt;&lt;p&gt;
Note, however, that there is also an .htaccess file that is hidden from this image.&lt;/p&gt;&lt;p&gt;You may be wondering why there is no &apos;tables&apos; directory like the directory structure that was generated by the makesite script. The &apos;tables&apos; directory is not required for the application to be functional. It will be required later on when we start to decorate the database.&lt;/p&gt;&lt;/nowiki&gt;
# The application is now ready to go. Point your web browser to the index.php file that you created. It will look like:&lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt;[[Image:http://xataface.com/documentation/tutorial/getting_started/basic-application-1.gif]]

===Download source files===

[[File:http://xataface.com/documentation/tutorial/getting_started/facultyofwidgetry-4-tar.gz|Download the source files]] for this application at a tar.gz archive.
These files reflect the state of the application at this point of the tutorial. As later sections make changes to the application you will be able to download those versions also.</content>
	<keywords>htaccess first application installation</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=57">
	<page_name>Creating_a_Dashboard</page_name>
	<page_id>57</page_id>
	<page_title>Creating_a_Dashboard</page_title>
	<content>==Creating a Dashboard for your Users==

[[toc]]

Xataface allows you to build powerful data-driven applications quickly, but these applications may be daunting to your users if they don&apos;t know what they can do with the application.  Most applications provide some sort of dashboard or control panel with some introductory instructions and links to commonly used actions in the application.  This makes the application more intuitive for users so that they can start using it right away, even without instruction from the developer.

===Characteristics of a Dashboard===

# Should be the default page when someone visits the application.
# Should be customized to show menus and content that are relevant to the current user.  (i.e. different users may see different links and content on their dashboard).
# Should contain at least some basic instructions so that the user understands what the application does when he visits the dashboard for the first time.
# Should contain links to frequently used actions.

===Strategies: 8 ways to skin the cat===

There are many viable strategies for adding a dashboard to your Xataface application.  This article presents only one.  It has been chosen because it satisfies all of the desired characteristics of a dashboard listed above, and it is easy to implement.

This strategy involves the following components:

# Create a dummy &apos;&apos;dashboard&apos;&apos; table.
# Create a dashboard action and associated template.
# Make sure our dashboard action is the default action for our application (more complex than just using the [[default_action]] directive in the [[conf.ini file]].

==Our Sample Application==

Consider our sample application, a publications management system for professors and research groups at a university.  It allows users to manage their publications using either BibTex format or a web-based form, and embed those publications into their webpage in a slick sortable format.  Currently, when the user accesses the application for the first time, they are shown the &apos;&apos;list&apos;&apos; tab of the &apos;&apos;bibliographies&apos;&apos; table.  This isn&apos;t all that informative and it may not be obvious to the user that their first step should be to create a new bibliography via the &apos;&apos;new record&apos;&apos; button.  Ideally we would like the user to go directly to a dashboard page with options to:

# Add New Bibliography
# Edit an Existing Bibliography
# Embed a Bibliography into their Webpage

And we want some basic instructions so that the user knows what to do when they first access the page.

==The Steps==

To create this dashboard we will follow the steps listed below (and mentioned above in the &apos;&apos;strategies&apos;&apos; section.

===Step 1: Create a dummy &apos;&apos;dashboard&apos;&apos; table===

This may seem unorthodox but it just happens to make our lives easier in the long run.  By creating a dummy table we are able to cause that table to be listed first in the &apos;&apos;_tables&apos;&apos; section of the [[conf.ini file]] and thus be the default table when users visit our application.

&lt;code&gt;
CREATE TABLE dashboard (
    dashboard_id int(11) not null auto_increment primary key
);
INSERT INTO dashboard values (1);
&lt;/code&gt;

===Step 2: Make &apos;&apos;dashboard&apos;&apos; table default===

We now modify the conf.ini file to list the &apos;&apos;dashboard&apos;&apos; table first:
&lt;code&gt;
[_tables]
    dashboard=Dashboard
    bibliographies=Bibliographies
&lt;/code&gt;

===Step 3: Create a Dashboard action and associated template===

This is the step where we actually create our dashboard action.  There are three parts to this story:

====Creating Action PHP Class====

The actual action will be located in the &apos;&apos;actions/dashboard.php&apos;&apos; file of our application, and looks like:

&lt;code&gt;
&lt;?php
class actions_dashboard {
    function handle(&amp;$params){
        $bibs = df_get_records_array(&apos;bibliographies&apos;, array());
        df_display(array(&apos;bibliographies&apos;=&gt;$bibs), &apos;dashboard.html&apos;);
    }
}
&lt;/code&gt;

All this does is loads the &apos;&apos;bibliographies&apos;&apos; records owned by the current user. Elsewhere we are using security filters so that the user can only see &apos;&apos;his&apos;&apos; bibliographies, which is why we don&apos;t need to specify any query here in the &apos;&apos;df_get_records_array&apos;&apos; function.

It then passes those bibliographies to the &apos;&apos;dashboard.html&apos;&apos; template that we create next.

====Creating the Action&apos;s Template====

The template for our action is located in the &apos;&apos;templates/dashboard.html&apos;&apos; file:
&lt;code&gt;
{use_macro file=&quot;Dataface_Main_Template.html&quot;}
    {fill_slot name=&quot;main_column&quot;}
        &lt;h1&gt;Welcome to the BibTeX Publication Management System (BPMS)&lt;/h1&gt;
        
        &lt;p&gt;This system allows you to manage your publications and publish
        them on the web.  Some common actions you may perform with this system
        include:
            &lt;ul&gt;
                &lt;li&gt;&lt;img src=&quot;{$ENV.DATAFACE_URL}/images/add_icon.gif&quot;/&gt;
                    &lt;a href=&quot;{$ENV.DATAFACE_SITE_HREF}?-table=bibliographies&amp;-action=new&quot;&gt;
                        Create New Bibliography&lt;/a&gt;
                &lt;/li&gt;
                &lt;li&gt;&lt;img src=&quot;{$ENV.DATAFACE_URL}/images/edit.gif&quot;/&gt; 
                   Edit existing bibliography: 
                   &lt;select onchange=&quot;window.location.href=this.options[this.selectedIndex].value&quot;&gt;
                    &lt;option value=&quot;&quot;&gt;Select ...&lt;/option&gt;
                    {foreach from=$bibliographies item=bibliography}
                        &lt;option value=&quot;{$bibliography-&gt;getURL(&apos;-action=edit&apos;)}&quot;&gt;
                            {$bibliography-&gt;getTitle()}
                        &lt;/option&gt;
                    
                    {/foreach}
                &lt;/select&gt;
                &lt;/li&gt;
                &lt;li&gt;&lt;img src=&quot;{$ENV.DATAFACE_URL}/images/file.gif&quot;/&gt; 
                    Embed your bibliography in a webpage:
                    &lt;select onchange=&quot;window.location.href=this.options[this.selectedIndex].value&quot;&gt;
                    &lt;option value=&quot;&quot;&gt;Select ...&lt;/option&gt;
                    {foreach from=$bibliographies item=bibliography}
                        &lt;option value=&quot;{$bibliography-&gt;getURL(&apos;-action=view&apos;)}#embed&quot;&gt;
                            {$bibliography-&gt;getTitle()}
                        &lt;/option&gt;
                    
                {/foreach}
                &lt;/select&gt;
                &lt;/li&gt;
                
            &lt;/ul&gt;
    {/fill_slot}
{/use_macro}
&lt;/code&gt;

A few key things to notice in this template:

# It extends the &apos;&apos;Dataface_Main_Template.html&apos;&apos; template placing its content in the &apos;&apos;main_column&apos;&apos; slot.  This allows our action to still display within the header and footer of our application.
# It makes use of the {$ENV.DATAFACE_SITE_URL} and {$ENV.DATAFACE_SITE_HREF} variables to refer to the site&apos;s base url and create links to the desired common actions.
# It provides a direct link to the &apos;&apos;new bibliography record&apos;&apos; form.
# It uses some slick javascript combined with select lists to allow the user to select any of his current bibliogaphies and edit them, or embed them into a webpage.

====Adding entry to the actions.ini file====

Currently our dashboard action has no permissions attached to it so users can see it whether they are logged in or not.  In this particular application we want to require users to log in, and we have set permissions for all logged in users to NO_ACCESS().  Unfortunately this permission setting is only helpful if our action requires a particular permission to access it.  We&apos;ll require the &apos;view&apos; permission for this action, by adding the following to the actions.ini file:

&lt;code&gt;
[dashboard]
    permission=view
&lt;/code&gt;


===Step 4: Specify permissions===

We still want to specify permissions for our &apos;&apos;dashboard&apos;&apos; table to ensure that only logged in users can access the dashboard.  So we create a delegate class for the &apos;&apos;dashboard&apos;&apos; table at &apos;&apos;tables/dashboard/dashboard.php&apos;&apos; with the following contents:

&lt;code&gt;
&lt;?php
class tables_dashboard {
    function getPermissions(&amp;$record){
        if ( getUser() ){
            return Dataface_PermissionsTool::ALL();
        }
        return null;
    }
}
&lt;/code&gt;

&apos;&apos;&apos;Note that we have defined the getUser() function elsewhere as a means of obtaining the current user and checking if a user is indeed logged in.&apos;&apos;&apos;

Notice that this [[getPermissions]] method returns all permissions only if the user is logged in.  Otherwise it returns null, which means that it should use the same permissions as the rest of the application as defined in the [[Application Delegate Class]].

===Step 6: Make &apos;&apos;dashboard&apos;&apos; the default action for the &apos;&apos;dashboard&apos;&apos; table===

Now we just have one more detail that needs to be taken care of.  We want the &apos;&apos;dashboard&apos;&apos; action to be the default action for the &apos;&apos;dashboard&apos;&apos; table only.  By default we would see the &apos;&apos;list&apos;&apos; action which isn&apos;t helpful at all, so we will want to add a rule in our application delegate class to ensure that the user only sees our custom &apos;&apos;dashboard&apos;&apos; action if they access the &apos;&apos;dashboard&apos;&apos; table.  We define a beforeHandleRequest() method in our conf/ApplicationDelegate.php (the application delegate class) file for this purpose:

&lt;code&gt;
&lt;?php
class conf_ApplicationDelegate {
    
...
    function beforeHandleRequest(){
        ...
        $app =&amp; Dataface_Application::getInstance();
	$query =&amp; $app-&gt;getQuery();
	if ( $query[&apos;-table&apos;] == &apos;dashboard&apos; and ($query[&apos;-action&apos;] == &apos;browse&apos; or $query[&apos;-action&apos;] == &apos;list&apos;) ){
	    $query[&apos;-action&apos;] = &apos;dashboard&apos;;
	}
        
        
    }
    
    ...
}
&lt;/code&gt;

This simply checks to see if the table is &apos;&apos;dashboard&apos;&apos; and changes the current action to &apos;&apos;dashboard&apos;&apos; if so.

===Step 7: Try it out===

At this point, we are ready to try out our new dashboard to see how it works.  When we load our application it should now go to the dashboard action that we created.  We should also see &apos;&apos;Dashboard&apos;&apos; listed as the first table in the tables menu.

This dashboard presents a major improvement to our application as it is now much more user friendly.

&lt;nowiki&gt;
&lt;img src=&quot;http://media.weblite.ca/files/photos/pub-dashboard.png?max_width=640&quot;/&gt;
&lt;/nowiki&gt;</content>
	<keywords>dashboard</keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=76">
	<page_name>GettingStarted:customizing</page_name>
	<page_id>76</page_id>
	<page_title>Customizing Field labels, descriptions, and widgets</page_title>
	<content>==Customizing Field labels, descriptions, and widgets==

Using simple INI configuration files, you can customize the look and feel of your application. You can change widgets, labels, field descriptions, and more.
In the previous 2 sections we learned how to create a simple application by desiging a database and then installing the basic directory structure to make our application operational. Now it is time to &quot;decorate&quot; the application a little bit. Decoration occurs by way of simple configuration files that are placed in strategic locations in the application. We can customize such things as:

* Widget types (e.g., use a select list for a field rather than a text field)
* Labels (e.g., The ProgramName field&apos;s label can say &quot;Program Name&quot; instead of just &quot;ProgramName&quot;)
* Field Descriptions . You can add descriptions to fields to help explain their meaning and how to use the application.
* HTML attributes. (e.g., Make a text field 50 characters wide)

===Table Configuration Directories===

You will recall, that when we used the &apos;makesite&apos; script to generate the directory structure for our web application, it created a directory named &apos;tables&apos;, with subdirectories named after each of the tables in our database. The directory structure of the application looked like:

[[Image:http://xataface.com/documentation/tutorial/getting_started/directory-structure-1.gif]]

The &apos;tables/Program&apos; and &apos;tables/Course&apos; are refered to as &quot;table configuration directories&quot; . All of the configuration files a table in a Xataface application are stored in its associated table configuration directory. For example all configuration files for the &apos;Program&apos; table are located in the &apos;tables/Program&apos; directory.

There are 4 main files that are generally contained in a table&apos;s configuration directory:

* &apos;&apos;&apos;fields.ini&apos;&apos;&apos; - Contains configuration for the fields of the table (e.g., field labels, descriptions, widget types, etc...)
* &apos;&apos;valuelists.ini&apos;&apos;&apos; - Contains value lists (vocabularies) that can be used in the table to limit input into certain fields like select lists.
* &apos;&apos;&apos;relationships.ini&apos;&apos;&apos; - Defines the relationships between this table and other tables in the application.
* &apos;&apos;&apos;&lt;TableName&gt;.php&apos;&apos;&apos; (where &lt;TableName&gt; is the name of the table. - A delegate PHP class that allows you to further customize the behavior of the application with respect to this table. May contain custom fields, importing/exporting functionality, permissions information, and more...

===Customizing Labels and Descriptions===

We will start off by adding custom labels and descriptions to the &apos;Program&apos; table of our &apos;FacultyOfWidgetry&apos; application. This sort of customization settings are placed in a file named &apos;fields.ini&apos; inside the table&apos;s configuration directory.

# Create the &apos;fields.ini&apos; file in the Program table configuration directory (i.e., tables/Programs/fields.ini).
# Add the following to this file:&lt;code&gt;
[ProgramName]
	widget:label = &quot;Program Name&quot;
	widget:description = &quot;Enter the name of the program&quot;
&lt;/code&gt;&lt;nowiki&gt;&lt;br&gt;&lt;/nowiki&gt;Now look at the &quot;Edit Record&quot; form in the Xataface application:

[[Image:http://xataface.com/documentation/tutorial/getting_started/program-name-label-1.gif]]


Notice how the label for the &quot;ProgramName&quot; now says &quot;Program Name&quot; (note the space between &quot;Program&quot; and &quot;Name&quot;). And its description matches the description specified in the fields.ini file.

The widget:label and widget:description attributes can be defined for any field in any table of the application.

===Using different widgets===

If no widgets are defined in the fields.ini file, a Xataface application will make a best guess at the type of widget that should be used to edit the value in a field. In general, the widgets used by default are as follows:

* VARCHAR, CHAR, INT : html text field
* DATE, DATETIME fields: calendar widget
* TEXT fields : html text area
* BLOB fields : html file upload field
* INT Fields with &quot;AUTO INCREMENT&quot; : html hidden field
* VARCHAR or CHAR fields with &quot;Password&quot; or &quot;password&quot; as part of the name : html password field
* ENUM fields : html select list
* SET fields : html checkbox group (not yet supported as of this writing).

You can change the widget that is used to edit a field by specifying a &quot;widget:type&quot; attribute for the field in the fields.ini file. For more information about the available widgets, see [[widget:type]].

====Example: Using HTML Editor to edit the HTMLOutline field====

Clearly the HTMLOutline field in the Program table is intended to store HTML content. By default our application only provides a text area to do the editing so the user is expected to enter the HTML markup by hand. It would be much better to provide the user with a WYSIWYG (What you see is what you get) HTML editor widget. That is exactly what we are going to do.
We will add a section to the fields.ini file so that it now looks like: &lt;code&gt;
[ProgramName]
	widget:label = &quot;Program Name&quot;
	widget:description = &quot;Enter the name of the program&quot;

[HTMLOutline]
	widget:type = &quot;htmlarea&quot;
&lt;/code&gt;

Now refresh the Xataface application in your web browser and look at the edit form for a record of the Program table:

[[Image:http://xataface.com/documentation/tutorial/getting_started/htmlarea-1.gif]]

As you can see, the HTMLOutline field now has an HTML Editor widget for editing. Most users will find this much nicer to work with than a normal text area. Xataface uses FCKEditor for its html editor widget.

There are a number of widgets that can be specified in the [[widget:type]] parameter:

* &apos;&apos;&apos;[[checkbox]]&apos;&apos;&apos; - An HTML checkbox (or checkbox group depending on context).
* &apos;&apos;&apos;[[date]]&apos;&apos;&apos; - Month/Day/Year select lists for selecting dates.
* &apos;&apos;&apos;[[calendar]]&apos;&apos;&apos; - A text field with a button that opens a small calendar widget when clicked.
* &apos;&apos;&apos;[[group]]&apos;&apos;&apos; - A complex widget type for editing multiple values as a group (useful for XML fields)
* &apos;&apos;&apos;[[hidden]]&apos;&apos;&apos; - a hidden field
* &apos;&apos;&apos;[[password]]&apos;&apos;&apos; - An HTML password widget
* &apos;&apos;&apos;[[select]]&apos;&apos;&apos; - An HTML select list (requires the &apos;vocabulary&apos; attribute)
* &apos;&apos;&apos;[[static]]&apos;&apos;&apos; - an uneditable field
* &apos;&apos;&apos;[[table]]&apos;&apos;&apos; - A complex widget type for editing multiple values in a tabular format (Useful for XML fields)
* &apos;&apos;&apos;[[text]]&apos;&apos;&apos; - an html text field
* &apos;&apos;&apos;[[textarea]]&apos;&apos;&apos; - an html text area

===Changing HTML attributes of widgets===

Sometimes you may want even finer grained control of your widgets&apos; appearance than to just specify the type, label, and desription. Perhaps you want to make a text field 50 characters wide, or to set the CSS class of the html element. This can be done using the &apos;widget:atts:&apos; parameter for a field. A short example is the easiest way to explain how this works.

Modify the fields.ini for the Program table so it looks like:&lt;code&gt;
[ProgramName]
widget:label = &quot;Program Name&quot;
widget:description = &quot;Enter the name of the program&quot;
widget:atts:size = 50
widget:atts:style = &quot;font-size: 24pt; font-family: Apple Chancery&quot;

[HTMLOutline]
widget:type = htmlarea
&lt;/code&gt;

We have added 2 lines:&lt;code&gt;
widget:atts:size = 50
widget:atts:style = &quot;font-size: 24pt; font-family: Apple Chancery&quot;
&lt;/code&gt;

What this does is add the html attributes size=&quot;50&quot; and style=&quot;font-size: 24pt; font-family: Apple Chancery&quot; to the html text field that is used to edit the ProgramName field.
Look at the results:

[[Image:http://xataface.com/documentation/tutorial/getting_started/widget-atts-1.gif]]

The HTML tag for the text field now looks like:&lt;code&gt;
&lt;input class=&quot;default&quot; id=&quot;ProgramName&quot; name=&quot;ProgramName&quot; 
	type=&quot;text&quot; size=&quot;50&quot; 
	style=&quot;font-size: 24pt; 
		font-family: Apple Chancery&quot; 
	value=&quot;Basic Widgetry&quot; 
/&gt;	
&lt;/code&gt;
In fact you can add arbitrary attributes to any of the fields using the same convention. Some useful examples are:

* &apos;&apos;&apos;[[widget:atts:rows]]&apos;&apos;&apos; for text areas to set the number of rows of text they should display.
* &apos;&apos;&apos;[[widget:atts:cols]]&apos;&apos;&apos; for text areas to set the number of columns (1 character = 1 column)
You can even use javascript calls in here if you like:
* &apos;&apos;&apos;[[widget:atts:onclick]]&apos;&apos;&apos; = &quot;doJsFunction();&quot;

===Download source files===

[http://xataface.com/documentation/tutorial/getting_started/facultyofwidgetry-6-tar.gz Download the source files] for this application as a tar.gz archive
These source files reflect the state of the application at the current point of the tutorial. As changes are made to the application in later sections, downloads of those versions are made available for download also.

===Summary===
In this section we learned how to change the labels, descriptions, and widgets for fields. We also learned how to add HTML attributes to the widgets to achieve very fine-grained control over the display of our forms.</content>
	<keywords>widget labels descriptions onclick handlers</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=103">
	<page_name>Customizing_Theme_Based_on_IP_Address</page_name>
	<page_id>103</page_id>
	<page_title>Customizing Theme Based on IP Address</page_title>
	<content>This article deals with the following topics:

# Using [[field__pullValue]]/[[field__pushValue]] methods to customize how a field is edited and stored in the database.
# Using [[beforeHandleRequest]] to modify the application settings based on the user&apos;s IP address
# Storing ranges of IP addresses in the database.

Last week I set up a site that needed to have slightly different behavior depending on the IP address of the remote user.  E.g.  If a user is connecting from an IP address between 192.168.0.0 to 192.168.0.255 we would use a different theme than if they were connecting from a different block.  In addition to different themes, we also to use different types of authentication depending on which IP block the user is visiting from.

This requirement is actually common for systems that are syndicated by different organizations and should behave slightly differently depending on which organization the user belongs to (assuming they are connecting from that organization&apos;s network).

To implement this behavior we need to solve one issue.

&apos;&apos;&apos;How do we store a range of IP addresses in the database so that they can be queried easily to match if the user&apos;s IP address falls in that range.&apos;&apos;&apos;
	
It turns out that this is quite easy to do, since IP addresses are actually just a 4 digit number (base 256).  So we can easily convert this number to base 10 and store it as a regular unsigned integer in the database.  In addition, both PHP and MySQL provide functions to convert from an IP address to an integer and back.

The PHP functions are called [http://ca3.php.net/long2ip long2ip] and [http://ca3.php.net/ip2long ip2long] respectively.

So we have stored a start IP address and an end IP address as integers, we could simply query the database to see if a given IP address falls in that range as follows:

&lt;code&gt;
$intIP = ip2long($_SERVER[&apos;REMOTE_ADDR&apos;]);
$sql = sprintf(&apos;select * from ip_blocks where start_ip&lt;=%u and end_ip&gt;=%u&apos;, $intIP, $intIP);
... etc....
&lt;/code&gt;

&apos;&apos;&apos;It is important to note that you need to use the sprintf() function for converting $intIP into a string because PHP will convert it to an integer which could overflow if you leave it to do a default conversion.&apos;&apos;&apos;
	
For the above query, we assuming a table with a definition like:

&lt;code&gt;
create table ip_blocks (
    ip_block_id int(11) not null primary key,
    start_ip unsigned int(11) not null
    end_ip unsigned int(11),
    key (start_ip),
    key (end_ip)
)
&lt;/code&gt;
	
Now if we attach some information to the IP block, like the theme that should be used, we can check the user IP address against the available IP blocks at the beginning of each request to set the theme for that request.  We will use the [[beforeHandleRequest]] method of the [[Application Delegate Class]] to house this because it allows us to set things like the theme or change the user&apos;s action.

e.g.

&lt;code&gt;
class conf_ApplicationDelegate {
	function beforeHandleRequest(){
		$app = Dataface_Application::getInstance();
		
		// Get a reference to the current query so we can
		// alter it if necessary.
		$query =&amp; $app-&gt;getQuery();
		
		
		// Get the user&apos;s IP address and covert it to a long int.
		$intIP = ip2long($_SERVER[&apos;REMOTE_ADDR&apos;]);
		$sql = sprintf(&apos;select `theme` from ip_blocks where start_ip&lt;=%u and end_ip&gt;=%u&apos;, $intIP, $intIP);
		
		$res = mysql_query($sql, df_db());
		if ( !$res ) throw new Exception(mysql_error(df_db()));
		
		$row = mysql_fetch_row($res);
		
		// If we didn&apos;t find any valid IP ranges, let&apos;s redirect the
		// user to a different action to let them know that
		// they&apos;re not welcome here.
		if ( !$row ){
			$query[&apos;-action&apos;] = &apos;not_welcome&apos;;
				// This assumes that we have defined an action
				// called &quot;not_welcome&quot;
				
			return;
		}
		
		$theme = $row[0];
		$themePath = &apos;themes/&apos;.basename($theme);
		// Check that the theme exists.
		if ( $theme and file_exists($themePath) ){
			df_register_skin($theme, $themePath);
		}
	}
}
&lt;/code&gt;

The above snippet makes use of the [[df_register_skin]] method that registers a theme to be used dynamically.  The first parameter is the theme name, and the second parameter is the path to the theme.


This code works great if we already have IP addresses stored properly as integers in our database, but how do we make it so users can work with the IP addresses as IP addresses and not integers?  We need to be able to transform from integer to IP address to display in the edit record form, and then convert the resulting IP address back to an integer for storage in the database.  Xataface provides two delegate class methods precisely for this purpose:

# [[field__pullValue]] - Transforms a value as stored in the database to a format that is preferred in the edit form.
# [[field__pushValue]] - Transforms a value entered into the edit form into a format that is preferred by the database.

So, in our delegate class we would have:

&lt;code&gt;
&lt;?php
class tables_ip_blocks {

	/**
	 * @param Dataface_Record $record The record we are pushing the value
	 *		into
	 * @param HTML_QuickForm_element $el The QuickForm widget that we are 
	 *      retrieving the value from.
	 */
	function start_ip__pushValue($record, $el){
		$val = ip2long($el-&gt;getValue());
		if ( $val !== false ){
			return sprintf(&apos;%u&apos;, $val );
		}
		return null;
	}
	
	function start_ip__pullValue($record, $el){
		$val = $record-&gt;val(&apos;start_ip&apos;);
		if ( $val )
			return long2ip($val);
		return $val;
	}
	
	function end_ip__pushValue($record, $el){
		$val = ip2long($el-&gt;getValue());
		if ( $val !== false ){
			return sprintf(&apos;%u&apos;, $val );
		}
		return null;
	}
	
	function end_ip__pullValue($record, $el){
		$val = $record-&gt;val(&apos;end_ip&apos;);
		if ($val){
			return long2ip($val);
		}
		return $val;
	}
	
	
}
&lt;/code&gt;

The [[field__pullValue]] and [[field__pushValue]] method should be inverses of each other.

&apos;&apos;&apos;Note that support for [[field__pullValue]] and [[field__pushValue]] are supported by Xataface since version 0.6, however support for them with the grid widget was not added until Xataface version 1.3.&apos;&apos;&apos;
	

Now, on the edit form, users can enter and edit IP addresses in the normal format, but they will be converted to unsigned integers for storage in the database.

There is only one thing remaining, though.  In the list view still shows the integer version of the IP addresses. We want them to show them as regular IP addresses.  So we add [[field__display]] methods to our delegate class:

&lt;code&gt;
function start_ip__display($record){
	$val = $record-&gt;val(&apos;start_ip&apos;);
	if ( $val )
		return long2ip($val);
	return $val;
}

function end_ip__display($record){
	$val = $record-&gt;val(&apos;end_ip&apos;);
	if ($val){
		return long2ip($val);
	}
	return $val;
}
&lt;/code&gt;

==References==

* [http://xataface.com/documentation/how-to/how-to-define-custom-serialization-for-fields How to define custom serialization for fields]
</content>
	<keywords>ip address, pullValue, pushValue, beforeHandleRequest</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=62">
	<page_name>Customizing_the_look_and_feel_of_a_row_or_a_cell</page_name>
	<page_id>62</page_id>
	<page_title>Customizing_the_look_and_feel_of_a_row_or_a_cell</page_title>
	<content>==How to customize the look and feel of elements in the list view==

===Create a method in a delegate class===

In the delegate class, the method &apos;&apos;css__tableRowClass&apos;&apos; is implemented, like in this example :

&lt;code&gt;class tables_journal_interventions {
function css__tableRowClass(&amp;$record){
    if ( !$record-&gt;val(&apos;fermeture&apos;)){
        return &apos;intervention_close&apos;;
    }
    else return &apos;&apos;;
} 
}
&lt;/code&gt;

Here the function tests a condition : is there a value in the field &apos;&apos;fermeture&apos;&apos; ?

===Add the class in a CSS stylesheet===

Now the class is created in a CSS stylesheet.

&lt;code&gt;td.intervention_close {
        background-color: #FFE6E6 !important;
    } &lt;/code&gt;

This is a class for each cell, the &lt;td&gt; tag. The &apos;&apos;!important&apos;&apos;  attribute is added to be sure that this information has precedence over all the others. It is better to add this class in a [http://xataface.com/documentation/how-to/custom_javascripts custom CSS stylesheet].

===Remarks===

Beware that some versions of IE don&apos;t respect the background-color property on the &lt;tr&gt; tag, so it is probably better to write:

&lt;code&gt;

    tr.intervention_close td {
        background-color: #FFE6E6;
    }&lt;/code&gt;

i.e. to apply the background color to the individual cells. </content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=32">
	<page_name>DataGrid</page_name>
	<page_id>32</page_id>
	<page_title>DataGrid</page_title>
	<content>==Xataface DataGrid Module==

Created by Steve Hannah, [http://weblite.ca Web Lite Solutions Corp.]

===Synopsis===

The Xataface DataGrid module uses the Ext DataGrid component (http://extjs.com) to add an editable grid component to your Xataface application.

[[toc collapse=0]]

===Requirements===

* PHP 4.3+
* MySQL 4.1+
* Xataface 0.8+

===License===

This module is distributed with ExtJS 2.2, which is distributed under the GPL v 3 (http://extjs.com/products/license.php).

In order to be compatible with the ExtJS license, this module is also distributed under the terms of the GPL v3 (http://www.gnu.org/copyleft/gpl.html).

===Demo Video===

&lt;nowiki&gt;
&lt;embed src=&quot;http://media.weblite.ca/lib/flvplayer.swf&quot; width=&quot;640&quot; height=&quot;500&quot; bgcolor=&quot;#FFFFFF&quot; type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; flashvars=&quot;file=http%3A%2F%2Fs3.amazonaws.com%2Fweblite_media%2FDataGrid-640x480.flv&amp;image=http%3A%2F%2Fmedia.weblite.ca%2Ffiles%2Fphotos%2FDataGrid-640x480.flv.jpg&amp;showdigits=true&amp;autostart=false&quot; /&gt;
&lt;/nowiki&gt;

===Screenshots===

Click on image to enlarge

&lt;nowiki&gt;
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;http://media.weblite.ca/index.php?-action=gallery&amp;-table=files&amp;categories=8&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;-photo_max_width=640&amp;--format=js&quot;&gt;&lt;/script&gt;

&lt;div style=&quot;clear:both&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;/nowiki&gt;


===Demo===

# LibrarianDB Demo: http://demo.weblite.ca/apps/librariandb/index.php?-table=books&amp;-action=DataGrid_view , &apos;&apos;&apos;Log in with username &quot;admin&quot; and password &quot;password&quot;&apos;&apos;&apos;

===Download===

* [https://sourceforge.net/project/platformdownload.php?group_id=250381 DataGrid-0.2]
* SVN Repository: http://weblite.ca/svn/dataface/modules/DataGrid

===Installation===

# Download and extract the DataGrid directory into your xataface/modules directory.
# Add the following line to the [_modules] section of your application&apos;s [[conf.ini file]]:&lt;code&gt;
modules_DataGrid=modules/DataGrid/DataGrid.php
&lt;/code&gt;
# Ensure that your [[permissions]] are set up appropriately to allow your users to access the grid action (see next section).

===Setting Up Permissions===

This module defines the following [[permissions]]:

* DataGrid:view_grid  	- Permission to view the data grid for a table.
* DataGrid:create_grid	- Permission to create a new data grid
* DataGrid:edit_grid		- Permission to edit an existing data grid
* DataGrid:update			- Permission to update records via the grid
* DataGrid:manage_grids	- Permission to access the datagrid control panel

In order for a user to access/use the grid he must be granted at least the Datagrid:view_grid and DataGrid:update [[permissions]].  Both of these [[permissions]] are included in the following system roles by default:

* EDIT
* EDIT AND DELETE
* DELETE
* ADMIN
* MANAGER

And of course these [[permissions]] are included with the call to Dataface_PermissionsTool::ALL() .

If you have assigned your own custom roles and want to enable access to the grid, you can simply add the following to your role definition in your [[permissions.ini file]]:
&lt;code&gt;
[MY ROLE]
    DataGrid:view_grid=1
    DataGrid:update=1
&lt;/code&gt;

If you want to explicitly disable the grid for a role, you can extend the role and deny those same [[permissions]]:
&lt;code&gt;
[MY ROLE extends MY ROLE]
	DataGrid:view_grid=0
	DataGrid:update=0
&lt;/code&gt;

	
===Usage===

Once installed, log in as a user that has permission to access the grid. You should notice a new tab along with &quot;details&quot;, &quot;list&quot;, and &quot;find&quot;, called &quot;grid&quot;. Click on the &quot;grid&quot; tab to access the grid.

You can double click on any field to edit it.  Modified fields will be marked in red, and automatically saved every 5 seconds - after the changes are saved the field is no longer marked in red.

===Limitations===

Currently only fields with the following widget types are available to be edited in the grid:

# text
# textarea
# select
# date/datetime/time

Other types of fields will simply not be included in the grid.

===Support/Questions===

Visit the Xataface forum at http://xataface.com/forum
	

</content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=141">
	<page_name>field__fieldname</page_name>
	<page_id>141</page_id>
	<page_title>Defining Calculated Fields</page_title>
	<content>Return to [[Delegate class methods]]

Xataface allows you to define calculated fields using the delegate class.  These fields won&apos;t be visible in the UI by default, but they will be accessible to some modules (e.g. the HTML Reports Module) and they are always accessible to you via the API.

E.g.  If you define a calculated field named &apos;&apos;year&apos;&apos;, you would be able to access this value using the regular Dataface_Record syntax:

&lt;code&gt;
$record-&gt;val(&apos;year&apos;);
&lt;/code&gt;

You could also define any number of filter methods and permissions on this field just as you can on regular fields.

e.g. &lt;code&gt;
function year__permissions($record){
    // Return special permissions on the year field.
}
&lt;/code&gt;

or &lt;code&gt;
function year__display($record){
    // Override how the year is displayed in the UI.
    return $record-&gt;val(&apos;year&apos;).&apos; A.D.&apos;;
}
&lt;/code&gt;

==How to Define a Calculated Field==

In the delegate class you simply create a method with the following naming convention:
&lt;code&gt;
function field__fieldname(Dataface_Record $record);
&lt;/code&gt;

where the return value is the value that the given record should have for the field &apos;&apos;filedname&apos;&apos;.

E.g.

&lt;code&gt;
function field__year($record){
    $time = trtotime($record-&gt;strval(&apos;date&apos;));
    if ( $time ){
        return date(&apos;Y&apos;, $time));
    } else {
        return &apos;&apos;;
    }
}
&lt;/code&gt;</content>
	<keywords>calculated fields, field__fieldname</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=80">
	<page_name>GettingStarted:delegate_classes</page_name>
	<page_id>80</page_id>
	<page_title>Delegate Classes</page_title>
	<content>==Delegate Classes==

Use Delegate classes to add permissions, custom serialization, display filters, calculated fields, import/export functionality, and other custom functionality to your application.

For many applications, the configuration files provide sufficient to make them fit the requirements. However, in some cases you may feel the need to &quot;extend&quot; or &quot;bend&quot; your application even more. For these situations, there are delegate classes.

===What is a delegate class?===

A delegate class is a PHP class that defines custom behavior, functions, and fields for a table in a Xataface application. A table may have only 1 delegate class.

What kinds of things can a delegate class do?

* Define permission rules for tables, records, and relationships.
* Define calculated fields.
* Define custom serialization/deserialization of fields (useful for XML storage)
* Define custom event handlers (actions to be performed when certain events take place)
* Define import / export filters.
* Define custom titles for records
* more ...

===How to create a delegate class===

I will describe the creation process with an example. 

Referring back to our FacultyOfWidgetry application, let&apos;s add a delegate class for the &apos;Program&apos; table. This is done as follows:

# Create a file named &apos;Program.php&apos; in the Program table configuration directory (i.e., &apos;tables/Program/Program.php). Your application directory structure should now look like:&lt;nowiki&gt;&lt;br/&gt;&lt;/nowiki&gt;[[Image:http://framework.weblite.ca/documentation/tutorial/getting_started/delegate-class-fs-1.gif]]
# Add the following contents to your newly created &apos;Program.php&apos; file:&lt;code&gt;&lt;?
class tables_Program {}
&lt;/code&gt;&lt;nowiki&gt;&lt;p&gt;
In other words, you are creating a class named &apos;tables_Program&apos;. The above delegate class doesn&apos;t do anything yet, but it is a start.
The fun part doesn&apos;t start until you start defining methods in your delegate class. There are prescribed interfaces that you will need to implement to make this work.&lt;/p&gt;&lt;/nowiki&gt;


===Example 1: Creating a custom title for records===
The &quot;Title&quot; of a record is a string that represents the record. It is used by Xataface in the navigation controller (forward and back buttons) and in the &quot;Jump&quot; menu as well as various places around the interface for referring to that record. As an example, take a look at this partial screen shot of the &apos;details&apos; tab in a Xataface application.

[[Image:http://framework.weblite.ca/documentation/tutorial/getting_started/getTitle-1.gif]]

I have circled the parts of the interface that use a record&apos;s title in some way. (1), (2), and (4) show the title of the current record and (3) shows the title of the next record in the found set. You will notice that the title is just the value of the first field in the Program record. In fact, the way that Xataface generates titles is by selecting the first VARCHAR or CHAR field in the table to be the Title for records of that table. In the above example this seems like a good choice, but it may not always be what you want.

We can use our delegate class to customize the way that these titles are generated. By defining a method named getTitle(), we can customize the way that titles are generated. Let&apos;s add such a method to our delegate class as follows:
&lt;code&gt;
&lt;?
class tables_Program {

	function getTitle(&amp;$record){
		return $record-&gt;val(&apos;ProgramName&apos;).&apos; Program&apos;;
	}
}
&lt;/code&gt;

OK, you are probably wondering what this $record object is. The $record object is a Dataface_Record object that represents a record of the &apos;Program&apos; table (if you want to take a look at the source code for this class it can be found in the &apos;Dataface/Record.php&apos; file). This object allows you to access all of the information about the record so that you can generate a title for the record. 

The &apos;val&apos; method simply returns the value of a field in the record.
In the above example, we are telling Xataface that the title of all records of the &apos;Program&apos; table is the value of the ProgramName field with the string &apos;Program&apos; appended to it. For example, if the ProgramName of a record was &apos;Foo&apos;, then its title woud be &apos;Foo Program&apos;.

Lets take a look at our application now to see the changes that we have made.

[[Image:http://framework.weblite.ca/documentation/tutorial/getting_started/getTitle-2.gif]]

Notice that the (1) now has &apos;Program&apos; appended to the end of the title, but (2) and (3) do not. This is because (2) and (3) are part of the result controller (for navigating through results in the table) and it needs to be able to load hundreds of record titles at a time, but the getTitle() method requires that the entire record be loaded into memory for it to work which would be unfeasible when we need the title of hundreds of records. The result controller titles can also be customized, however, using the titleColumn() method, which simply returns the name of the column that should be used as the title. It can also return MySQL clauses that are equivalent to a column name (e.g., CONCAT(&apos;FirstName&apos;, &apos; &apos;, &apos;LastName&apos;) would be valid).

Okay, let&apos;s add a titleColumn() method to our delegate class so that we can customize the way our records are represented in the result controller:

&lt;code&gt;
&lt;?
class tables_Program {

	function getTitle(&amp;$record){
		return $record-&gt;val(&apos;ProgramName&apos;).&apos; Program&apos;;
	}
	
	function titleColumn(){
		return &apos;AdmissionDeadline&apos;;
	}
}
&lt;/code&gt;


All that the titleColumn method does is return the name of a column to be used as the title for records of the &apos;Program&apos; table. In this case, we making the &apos;AdmissionDeadline&apos; field the title column which results in the result controller looking like this:

[[Image:http://framework.weblite.ca/documentation/tutorial/getting_started/titleColumn-1.gif]]


This was a simple example, but it is possible to do more with the titleColumn() method than just specify the name of a column. Any valid MySQL calculation that can be placed in a SELECT list can be returned here. For example, we can make use of the MySQL &apos;CONCAT&apos; function to append the string &apos;Program&apos; to the &apos;ProgramName&apos; field and achieve the same results as our previous getTitle() method:

&lt;code&gt;
&lt;?
class tables_Program {

	function getTitle(&amp;$record){
		return $record-&gt;val(&apos;ProgramName&apos;).&apos; Program&apos;;
	}
	
	function titleColumn(){
		return &quot;CONCAT(ProgramName, &apos; Program&apos;)&quot;;
	}
}

&lt;/code&gt;

And now we can see the changes in our application:

[[Image:http://framework.weblite.ca/documentation/tutorial/getting_started/titleColumn-2.gif]]

It may seem a little bit inconvenient to have to define 2 methods to effectively customize the title of a record. Future versions may attempt to address this issue so that one or the other can be implemented, but for now, both methods must be implemented to effectively customize the title. In addition, future versions will likely add the &apos;titleColumn&apos; functionality to an INI file since it is more or less static.

===Summary===

In this section we learned how to add a delegate class to our tables to customize the behavior of our applications. Delegate class become more important when you need very fine-grained customizations to your application, as you will see in later sections. One important feature of delegate classes is the ability to add security permissions to tables and records to limit who can view, edit, and delete certain records. This will be covered in the next section.

</content>
	<keywords>delegate classes,getTitle,getPermissions</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=7">
	<page_name>Delegate_class_methods</page_name>
	<page_id>7</page_id>
	<page_title>Delegate_class_methods</page_title>
	<content>==Delegate Class Reference==

[[toc]]

A delegate class is a PHP class that complements a particular table with custom bahaviors.  Basic table metadata can be supplied using the [[fields.ini file]], however some things are better customized using PHP.

===Delegate Class Location===

The delegate class should be located in a file named TABLENAME.php (where TABLENAME is the name of the table with which the delegate class is associated) inside the table&apos;s [[table configuration directory|configuration directory]].  E.g. given a table named &quot;people&quot;, you would place the delegate class in the file &quot;tables/people/people.php&quot;

===Basic Delegate Class===

&lt;code&gt;
&lt;?php
class tables_people {}
?&gt;
&lt;/code&gt;

===Available Methods===

====Table Settings====

{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[sql delegate method|__sql__]]
| Defines the SQL query that can be used to fetch records of this table.  This is identical to the [[fields.ini file]] [[__sql__]] directive, except that by defining it in the delegate class you have more flexibility.
| 1.0
|}

====Permissions====

{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[getPermissions]]
| Returns the permissions available for a given record.
| 0.6
|-
| getRoles
| Returns the roles allowed for a given record.
| 1.0
|-
| [[__field__permissions]]
| Returns the default permissions for a field of a given record.
| 1.0
|-
| __field__roles
| Returns the default roles for a field of a given record.
| 1.0
|-
| [[fieldname__permissions]]
| Returns the permissions that are allowed for the field &quot;fieldname&quot; on a given record.
| 0.7
|-
| fieldname__roles
| Returns the roles that are allowed for the field &quot;fieldname&quot; on a given record.
| 1.0
|-
| rel_relationshipname__permissions
| Returns the permissions pertaining to the relationship &apos;&apos;relationshipname&apos;&apos; on a given record.
| 1.0
|-
| rel_relationshipname__roles
| Returns the role or roles pertaining to the relationship &apos;&apos;relationshipname&apos;&apos; on a given record.
| 1.0
|}

====Triggers====

{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[after_action_edit]]
| Trigger called after the edit action is succesfully completed.
| 0.7
|-
| [[after_action_new]]
| Trigger called after the new action is successfully completed.
| 0.7
|-
| [[after_action_delete]]
| Trigger called after the delete action is successfully completed.
| 0.7
|-
| [[afterAddExistingRelatedRecord]]
| Trigger called after an existing related record is added.
| 0.5
|-
| [[aftereAddNewRelatedRecord]]
| Trigger called after a new related record is added.
| 0.5
|-
| [[afterCopy]]
| Trigger called after a record is copied.
| 1.3
|-
| [[afterDelete]]
| Trigger called after a record is deleted.
|0.5
|-
| [[afterAddRelatedRecord]]
| Trigger called after a related record of this table is added (either an existing record or a new record).
| 0.5
|-
| [[afterRemoveRelatedRecord]]
| Trigger called after a related record is removed from a relationship.
| 1.1.6
|-
| [[afterInsert]]
| Trigger called after a given record is inserted.
| 0.5
|-
| [[afterSave]]
| Trigger called after a given record is saved (insert or update).
| 0.5
|-
| [[afterUpdate]]
| Trigger called after a given record is updated.
| 0.5
|-
| [[beforeAddExistingRelatedRecord]]
| Trigger called before an existing related record is added.
| 0.5
|-
| [[beforeAddNewRelatedRecord]]
| Trigger called before a new related record is added.
| 0.5
|-
| [[beforeAddRelatedRecord]]
| Trigger called before a related record of this table is added (either an existing record or a new record).
| 0.5
|-
| [[beforeCopy]]
| Trigger called before a record is copied.
| 1.3
|-
| [[beforeDelete]]
| Trigger called before a record is deleted.
| 0.5
|-
| [[beforeRemoveRelatedRecord]]
| Trigger called before a related record is removed.
| 1.1.6
|-
| [[beforeSave]]
| Trigger called before a given record is saved (insert or update).
| 0.5
|-
| [[beforeInsert]]
| Trigger called before a given record is inserted.
| 0.5
|-
| [[beforeUpdate]]
| Trigger called before a given record is updated.
| 0.5
|-
| [[init]]
| This method is called the first time the table is loaded.  It allows you to specify initialization details.
| 0.8
|}


====Field Filters====

{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| fieldname__htmlValue
| Returns the value of the field &quot;fieldname&quot; for a given record as HTML.
| 0.5
|-
| fieldname__display
| Returns the value of the field &quot;fieldname&quot; appropriate for displaying.
| 0.5
|-
| [[fieldname__default]]
| Returns the default value for the field &apos;&apos;fieldname&apos;&apos;.  New record forms will be prepopulated with this value.
| 0.7
|-
| [[fieldname__validate]]
| Validates the input for the field &apos;&apos;fieldname&apos;&apos;.
| 0.6
|-
| fieldname__parse
| Parses the input value for the field &apos;&apos;fieldname&apos;&apos;.  This is called by Xataface inside the setValue() method or each record to normalize input values before they are stored in the object (not the database).
| 0.5
|-
| fieldname__toString
| Converts the value of the field &apos;&apos;fieldname&apos;&apos; to a string.  This string representation is used as the basis for most higher level data retrieval methods (such as serialize and display).  This could be treated as an inverse to the [[fieldname__parse]] method.
| 0.5
|-
| fieldname__serialize
| Converts a value of the field &apos;&apos;fieldname&apos;&apos; to be saved in the database.  This should return a string representation of the value that is suitable for database storage.
| 0.5
|-
| fieldname__link
| A link that appears beside the field &apos;&apos;fieldname&apos;&apos; on the edit form.
| 0.6
|-
| [[field__pushValue]]
| Converts form input for field &apos;&apos;fieldname&apos;&apos; to be ready to store in a Dataface_Record.
| 0.6
|-
| [[field__pullValue]]
| Converts a value for field &apos;&apos;fieldname&apos;&apos; in a Dataface_Record object to be ready to be inserted as a value on an HTML form.
| 0.6
|-
| [[field__fieldname]]
| Effectively creates a calculated field named &quot;fieldname&quot; available on the given record.
| 0.6
|-
| [[no_access_text]]
| Replace the default NO ACCESS permission text with another text.
| 1.1.6
|-
| [[no_access_link]]
| Replace the default link of the NO ACCESS permission link with another link.
| 1.1.6
|}

====Template Customization====
{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[block__blockname]]
| Outputs content that is meant to override a slot or a block named &quot;blockname&quot;.
| 0.6
|}

====List Tab Customization====

{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| css__tableHeaderCellClass
| Returns a custom CSS class for a table header cell (th tag) in the list view.  Takes the name of a table column as a parameter.
| 2.0alpha2
|-
| css__tableRowClass
| Returns a custom CSS class for a table row (tr tag) in list view.  Takes a Dataface record as a parameter.
| 1.2
|-
| fieldname__renderCell
| Overrides the table cell content for the &quot;fieldname&quot; field in list view with custom HTML.
| 1.0
|-
| renderRow
| Overrides the the html used for a row in list view for the given record.
| 0.7
|-
| renderRowHeader
| Overrides the header for the table in list view.
| 0.7
|-
| renderRelatedRow
| Overrides the html used for a row in a related record list for a given related record.
| 1.0 beta 4
|-
| renderRelatedRowHeader
| Overrides the html used for the header in a related list.
| 1.0 beta 4
|}

====Record Metadata====
{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[getBreadCrumbs]]
| Returns the bread crumbs (i.e. you are here) for a given record as an associative array of path parts.
| 0.6
|-
| [[getChildren]]
| Returns a list of Dataface_Record objects that are to be considered children of the given record.
| 0.8
|-
| [[getCreated]]
| Returns a unix timestamp marking the date that a record was created. 
| 0.9
|-
| getDescription
| Returns a string description summary of this record.  This is used for indexing, RSS feeds, and anywhere that a brief summary of a record is appropriate.
| 0.7
|-
| getPublicLink
| Returns the public URL of this record (in case it is different than the standard URL).
| 0.8
|-
| getTitle
| Returns the title for a given record.  The title is used in various parts of the application to represent the record.
| 0.5
|-
| [[getURL]]
| Overrides the getURL() method for a record.  Returns the URL that should be used to display the given record.
| 0.6
|-
| titleColumn
| Returns a string SQL select expression that is used to describe the title of records.
| 0.5
|}

====View Tab Customization====

{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[How_to_Add_Custom_Sections_to_View_Tab|section__sectionname]]
| Defines a section to be displayed in the view tab for the given record.
| 0.7
|}


====Search Setup====
{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| getSearchableText
| If [[_index|Indexing]] is turned on, then this returns the text that should be stored in the index for this record for searchability.
| 1.0
|}

====RSS Feed Customization====
{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[getFeedItem]]
| For RSS Feeds, overrides the defaults and returns an associative array with feed elements for a particular record
| 1.0
|-
| [[getFeed]]
| For RSS feeds, overrides the default feed for a query, returning an array of feed items.
| 1.0
|-
| getFeedSource
| Overrides the default feed source parameter for an RSS feed.
| 1.0
|-
| [[getRelatedFeed]]
| For RSS feeds, overrides the default feed for a related feed.
| 1.0
|-
| getRSSDescription
| Overrides the default generated RSS description for a record.
| 1.0
|}

===XML Output Customization===
{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[toXML]]
| Overrides the default XML produced for a record in the [[export xml]] action.  Returns an XML string.
| 1.2.7
|-
| [[getXMLHead]]
| Returns a string to be included at the beginning of XML output for a particular record. (just inside the opening tag).
| 1.2.7
|-
| [[xmlTail]]
| Returns a string to be included at the end of XML output for a particular record. (just inside the closing tag).
| 1.2.7
|}

====Valuelist Customization====
{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[valuelist__valuelistname]]
| Defines a valuelist named &apos;&apos;valuelistname&apos;&apos;.
| 0.7
|}


====Importing Records====
{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| [[__import__filtername]]
| Defines an import filter to named &apos;&apos;filtername&apos;&apos; which is used to import records into the table.
| 0.7
|}
</content>
	<keywords>RSS,Feeds,delegate classes, triggers</keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=70">
	<page_name>documentation_guide</page_name>
	<page_id>70</page_id>
	<page_title>Documentation Guide</page_title>
	<content>Xataface uses a wiki to manage its online documentation which can be edited by anyone.  All you have to do is [http://xataface.com/wiki/index.php?-action=login login with your forum username and password] ([http://xataface.com/forum/profile.php?mode=register register for the forum here]).  Then when you are browsing a page of the wiki, you&apos;ll see an &apos;Edit&apos; tab along the top.  Click on this tab to start editing the page in your browser.  Wiki markup is a little simpler than HTML and a little more complex than plain text.  It is easy to get a handle on once you get started.  If you aren&apos;t sure how to format it exactly how you want, don&apos;t worry.  Someone may come by after you and improve on your formatting.  That&apos;s what the community approach is all about.

==The Documentation Team==

Join the Xataface documentation team to help participate in the planning of the documentation.  If you want to help out, contact [mailto:steve@weblite.ca Steve Hannah] and he&apos;ll add you to the documentation group where you can access the private documentation forums and meet the rest of the team.

==Using the Wiki==

The following is a brief guide in using the Xataface Wiki.  All following instructions assume that you are already [http://xataface.com/wiki/index.php?-action=login logged in] to the wiki.  You can use your forum username and password to login.

===Editing an Existing Page===

# Navigate to the page that you want to edit
# Click on the &quot;Edit&quot; tab along the top.
# Make changes to your page.
# Save the changes.

===Adding a New Page===

====Method 1: Add a link from an existing page===

# Navigate to an existing page that you want to link to your new page.
# Click on the &quot;Edit&quot; tab along the top.
# Somewhere in the content of the page, add a link to your new page (which doesn&apos;t exist yet), by adding the following markup&lt;code&gt;
[[The name of your new page]]
&lt;/code&gt;
# Save your changes.
# Click on the &quot;view&quot; tab along the top and find the place where you added your link.  It should be displayed with a &apos;?&apos; right after it.  Click on the &apos;?&apos; and it will bring you to the &quot;new page form&quot;.
# fill in the form with your page contents and click save.

====Method 2: Accessing new page form directly====

# Access the [http://xataface.com/wiki/index.php?-action=new&amp;-table=wiki new page form] directly.


===Uploading Images===

Image can be uploaded at [http://media.weblite.ca The Web Lite Media Manager].  You&apos;ll need an account to access this site.  If you are a member of the documentation team you can request an account from [mailto:steve@weblite.ca Steve Hannah] so that you can upload images here.

Steps:

# Log into [http://media.weblite.ca the Web Lite Media Manager].
# Click on &quot;Add New File&quot; in the menu on the left.
# Select a name for the file, and browse to the image you want to upload in the file upload field.  You don&apos;t need to check any category boxes.  Press save.
# Click on the &quot;View&quot; tab for your newly uploaded image.
# Copy the embed code for the image from the &quot;Embed Code&quot; field.
# In the wiki page add the embed code where you want your image to appear as follows:&lt;code&gt;
[[Image:EMBED_CODE]]
&lt;/code&gt; Where EMBED_CODE is the URL for the image as you copied and pasted out of the media manager.
# Save your changes.

===Uploading Video===

===Adding Source Code Snippets===</content>
	<keywords>documentation wiki</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=39">
	<page_name>Drag_and_Drop_Reordering_of_Relationships</page_name>
	<page_id>39</page_id>
	<page_title>Drag_and_Drop_Reordering_of_Relationships</page_title>
	<content>==Drag and Drop Reordering of Related Records in Xataface==

One powerful aspect of Xataface is its abstraction of relationships between tables.  Once you define a relationship users can browse related records, add new and existing related records, and delete related records to or from the relationship.  For example, suppose you have a &apos;&apos;people&apos;&apos; table and a &apos;&apos;publications&apos;&apos;, you could define a relationship from &apos;&apos;people&apos;&apos; to &apos;&apos;publications&apos;&apos; to identify publications that belong to a particular person.  The table&apos;s might look something like:

===people table===

{| class=&quot;listing listing2&quot;
! person_id
! person_name
|-
| 1
| John Smith
|-
| 2
| Ben Stein
|-
| 3
| Harley Davidson
|-
| 4
| Trevor Linden
|}


===publications table===

{| class=&quot;listing listing2&quot;
! publication_id
! owner_id
! pub_title
|-
| 1
| 2
| Introduction to widgetry
|-
| 2
| 2
| Intermediate Widgetry
|-
| 3
| 2
| Advanced Widgetry
|-
| 4
| 3
| How to play the violin
|}


See http://xataface.com/documentation/tutorial/getting_started/relationships for an introduction to relationships in Xataface, and how to define them.

Our relationship definition in the  &apos;&apos;people&apos;&apos; table&apos;s [[relationships.ini file]] might look something like:

&lt;code&gt;
[my_pubications]
    publications.owner_id=&quot;$person_id&quot;
&lt;/code&gt;

This indicates that any publication whose &apos;&apos;owner_id&apos;&apos; column matches the current &apos;&apos;people&apos;&apos; record&apos;s &apos;&apos;person_id&apos;&apos; field is considered part of the relationship.  Using our example data above, this would mean that Ben Stein&apos;s &apos;&apos;my_publications&apos;&apos; relationship would contain 3 records: &quot;Introduction to Widgetry&quot;, &quot;Intermediate Widgetry&quot;, and &quot;Advanced Widgetry&quot;.  In our Xataface application this means that in the &quot;Details&quot; tab for the &quot;Ben Stein&quot; record, we would see a sub-tab &apos;&apos;My Publications&apos;&apos; which would contain a list of Ben Stein&apos;s publications.

===Adding Publication Order===

Now that we have our relationship, what if Ben Stein wants his publications to appear in a particular order whenever they are displayed to the user.  Xataface allows us to specify an &quot;order&quot; column for our relationship, which will cause the related records to be orderable by drag and drop (if the user has appropriate permissions).

# Add a field to the &apos;&apos;publications&apos;&apos; table named &quot;pub_order&quot;
# Change the relationship definition in the people table&apos;s [[relationships.ini file]] to tell Xataface to use the pub_order field for sorting:&lt;code&gt;
[my_pubications]
    publications.owner_id=&quot;$person_id&quot;
    metafields:order=&quot;pub_order&quot;
&lt;/code&gt;

Now load up your application and navigate to the &quot;My Publications&quot; tab for the &quot;Ben Stein&quot; record. Now you&apos;re able to drag and drop rows in your application to reorder them.

===Permission to Reorder Records===

Only users who have been assigned the &apos;&apos;reorder_related_records&apos;&apos; permission for a record&apos;s relationship are allowed to reorder records of that relationship.  By default the &apos;&apos;EDIT&apos;&apos; role contains this permission, as does any role that permits the user to edit the parent record of the relationship.  The &apos;&apos;READ ONLY&apos;&apos; role does not contain this permission.  If you want to explicitly deny this permission for all relationships in a record, you can simply set this permission to 0 in the associated role within your application&apos;s [[permissions.ini file]]:

&lt;code&gt;
[MY ROLE]
     reorder_related_records=0
&lt;/code&gt;

For more information about permssions see:

* [[permissions.ini file|The Permissions.ini file reference]]
* [http://xataface.com/documentation/tutorial/getting_started/permissions Introduction to Permissions]

===Loading Related Records using the Xataface API===

The ordering that is set via this drag and drop method is also honoured by the Xataface API when fetching related records.  You can load related records using the [http://dataface.weblite.ca/getRelatedRecordObjects getRelatedRecordObjects] method of the [http://dataface.weblite.ca/Dataface_Record Dataface_Record] class. E.g.

&lt;code&gt;
$benStein = df_get_record(&apos;people&apos;, array(&apos;person_id&apos;=&gt;2));
$pubs = $benStein-&gt;getRelatedRecordObjects(&apos;my_publications&apos;);
foreach ($pubs as $pub){
    echo $pub-&gt;val(&apos;pub_title&apos;).&apos;&lt;br/&gt;&apos;;
}
&lt;/code&gt;
This will list up to the first 30 publications of Ben stein in the order prescribed by our drag and drop ordering scheme.
</content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=54">
	<page_name>Email</page_name>
	<page_id>54</page_id>
	<page_title>Email</page_title>
	<content>==Xataface Email Module==

[[toc]]

The Xataface Email module allows you to convert your database into a mailing list so that you can easily send email to any found set of records, as long as the records contain an email address to send to.

==Features==

* Send email to any found set.
* Mail merge macros
* HTML Email support (uses NicEdit WYSIWYG editor for email editing).
* Opt out support (allows recipients to opt out of your mailing list).

==Requirements==

* Xataface 1.0+
* MySQL 4.1+
* PHP 5+

==Download==

https://sourceforge.net/project/platformdownload.php?group_id=253820

==Installation==

# Download and extract Email directory so that it is located inside the xataface/modules directory (i.e. xataface/modules/Email)
# Add the following to the &apos;&apos;[_modules]&apos;&apos; section of your application&apos;s conf.ini file:&lt;code&gt;
modules_Email=&quot;modules/Email/Email.php&quot;
&lt;/code&gt;
# Configure the [email] action in your application&apos;s actions.ini file.  See the section called &apos;Configuration&apos; for configuration details.
# Add a line to your crontab file to send out pending email periodically.  The line should look like:&lt;code&gt;
* * * * * /usr/bin/php &lt;cronpath&gt; &lt;indexpath&gt; &lt;indexurl&gt; mail

where &lt;cronpath&gt; is the absolute path to the cron.php script.
      &lt;indexpath&gt; is the absolute path to your application&apos;s index.php script.
      &lt;indexurl&gt; is the absolute url to your application&apos;s index.php script.
		
For example:

* * * * * /usr/bin/php /var/www/xataface/modules/Email/cron.php \
		/var/www/myapp/index.php \
		http://example.com/myapp/index.php \
		mail
&lt;/code&gt; If you want to see what this line should be like for your server, you can simply point your browser to the email_install action of your application (i.e. http://example.com/yourapp/index.php?-action=email_install) and it will generate this line to copy and paste into your crontab.  Note that the /usr/bin/php portion of this line may vary according to your environment.  It represents the path to your PHP binary.
# That&apos;s it!  You&apos;re ready to send email.  See the &apos;&apos;Usage&apos;&apos; section to see how to send email from your application.

==Configuration==

Though the email action may work out of the box, you will likely have to configure it to work the way you want.  Some examples of things you will want to configure include:

# Limit the email action to only be available for certain tables.
# Apply permissions to the action so that only administrators can send email.
# Set the name of the column that contains email address (default is &apos;email&apos;).
# Change the name of the table that is used to store sent email messages.

===Overriding the &apos;&apos;[email]&apos;&apos; action===

The first thing you need to do to configure the email action is override it in your appliation&apos;s actions.ini file.  You can do this by adding the following to your [[actions.ini file]]:
&lt;code&gt;
[email &gt; email]
&lt;/code&gt;

Now any directives you add in this section will override the email action.

====Examples:====

=====Limiting email action to certain tables=====

In your appliation&apos;s [[actions.ini file]]:
&lt;code&gt;		
[email &gt; email]
    condition=&quot;$query[&apos;-table&apos;] == &apos;Pledge&apos; or $query[&apos;-table&apos;] == &apos;User&apos;&quot;
&lt;/code&gt;


=====Limiting email action by permission=====

By default your users require the &apos;&apos;email&apos;&apos; permission in order to have access to the email form.  This permission is not included with any roles by default so you&apos;ll need to extend any roles that you want to have access to the email access and explicitly add the &apos;&apos;email&apos;&apos; permission.  The exception to this rule is if you have assigned your users the &apos;&apos;Dataface_PermissionsTool::ALL()&apos;&apos; permissions in your &apos;&apos;getPermissions()&apos;&apos; method.

Suppose you want the &apos;&apos;READ ONLY&apos;&apos; role to have access to the email action, you could add the following to your application&apos;s [[permissions.ini file]]:
&lt;code&gt;
[READ ONLY extends READ ONLY]
     email=1
&lt;/code&gt;   			

=====Changing the name of the email address column=====

By default, the Email module will try to guess which column contains the email address for a table.  Generally it looks for a column named &apos;&apos;email&apos;&apos;.  You can override this setting to explicitly tell the module which column contains the email address by overriding the &apos;&apos;email_column&apos;&apos; directive of the &apos;&apos;email&apos;&apos; action in your application&apos;s [[actions.ini file]]:
&lt;code&gt;
[email &gt; email]
    email_column = &quot;emailAddress&quot;
&lt;/code&gt;

=====Changing the name of the table that stores the sent email====

Xataface automatically stores each sent email for your records.  By default it stores these emails in a table named &apos;&apos;newsletters&apos;&apos;.  You can override this table name with the &apos;&apos;email_table&apos;&apos; directive in your application&apos;s [[actions.ini file]].  This table will be automatically created by Xataface when email is sent out.
&lt;code&gt;
[email &gt; email]
    email_table = &quot;newsletters&quot;
&lt;/code&gt;
	
=====Altogether=====

&lt;code&gt;
[email &gt; email]
    condition=&quot;$query[&apos;-table&apos;] == &apos;Pledge&apos; or $query[&apos;-table&apos;] == &apos;User&apos;&quot;
    permission=email
    email_column = &quot;emailAddress&quot;
    email_table = &quot;newsletters&quot;
&lt;/code&gt;


==Usage:==

===Sending Email to All Records of a Table===

# Navigate to a table for which your email module is enabled, and click on the &apos;&apos;list&apos;&apos; tab.
# Click on the &quot;Email&quot; icon in the upper right corner.  This should display an email form.&lt;nowiki&gt;
&lt;img src=&quot;http://media.weblite.ca/files/photos/email_icons.png&quot;/&gt;
&lt;/nowiki&gt;
# Fill in the email form and press Save.&lt;nowiki&gt;
&lt;div&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/email_form.png?max_width=500&quot;/&gt;&lt;/div&gt;
&lt;/nowiki&gt;
# You should receive a message saying that the email has been queued for delivery.  Your cron script will automatically begin sending emails the next time around.  So make sure that you have yoru cron script set up properly.

===Opting Out of the Email List===

If you have received an email that was sent via the email module you can easily opt out of the mailing list by clicking on the link at the end of the email.  This link will bring you to a webpage that asks you to confirm that you no longer wish to receive email from this list.



==Using a View to add Email Action to Related Record List==

You can simulate a many-to-many [[relationships.ini file|relationship]] in a mysql view by creating a view with all possible combinations. 

e.g. If you have a Many to Many [[relationships.ini file|relationship]] between books and authors your [[relationships.ini file|relationship]] from the books table might be something like: 

&lt;code&gt;

[authors] 
__sql__ = &quot;select * from authors a inner join book_authors ab on a.author_id=ab.author_id where ab.book_id=&apos;$book_id&apos;&quot; 

&lt;/code&gt;

And your relationship from the authors table would be something like: 
&lt;code&gt;
[books] 
__sql__ = &quot;select * from books b inner join book_authors ab on b.book_id=ab.book_id where ab.author_id=&apos;$author_id&apos;&quot; 
&lt;/code&gt;

Now if our goal was to be able to send email to all authors of a particular book (i.e. send to the authors relationship), we could create a view: 
&lt;code&gt;
create view book_authors_maillist as 
select * from authors a inner join book_authors ab on a.author_id=ab.author_id 
&lt;/code&gt;

This view can now be used in xataface like a regular table (if you add a [[fields.ini file]] for it and [[Key|mark the primary key columns]]). If you wanted to find all authors for a certain book you would just do: 

index.php?-action=list&amp;-table=book_authors_maillist&amp;book_id=10 

So you could easily create an action in the [[actions.ini file]] that would like to the mail action on the book_authors_maillist table with the parameters you wanted. 

e.g. 

&lt;code&gt;
[related_authors_mail] 
    category=related_list_actions 
    url=&quot;{$site_href}?-action=email&amp;-table=book_authors_maillist&amp;book_id={$record-&gt;val(&apos;book_id&apos;)}&quot; 
    icon=&quot;{$dataface_url}/images/mail_icon.gif&quot; 
    url_condition=&quot;$record&quot; 
    condition=&quot;$query[&apos;-table&apos;]==&apos;books&apos; and $query[&apos;-relationship&apos;] == &apos;authors&apos;&quot; 
    permission=&quot;email&quot; 
&lt;/code&gt;


This action would send mail to only the authors related to the current books. It would be made available in the icons in the upper right on the related list view of only the authors of a book.

===Mail Merge===

The &apos;Embed Macro&apos; shown above the email form lists the fields which may be included in the email.

Say you have a field called &apos;email_firstname&apos;. You would type this into the message area like this: %email_firstname%

When the email is sent, this is substituted for the record of that recipient.

Eg. Dear %email_firstname% would be received by email as Dear Tom

If the particular record of the field you are merging is blank, then (in this case) the first name will not be shown.</content>
	<keywords>Email,Email module,Sending Email,Maillist</keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=29">
	<page_name>encryption</page_name>
	<page_id>29</page_id>
	<page_title>encryption</page_title>
	<content>==encryption [[fields.ini file]] directive==

The &apos;&apos;&apos;encryption&apos;&apos;&apos; directive is meant to be used on password fields only.  It specifies that a certain type of encryption is to be used in the storing of values in this field.  For example, many PHP/MySQL applications use MD5 encryption to store their passwords.  If you want your Xataface application to be able to use the same users tables, then you&apos;ll need to specify the &apos;&apos;&apos;encryption&apos;&apos;&apos; directive for the password field.

===Possible Values===

{| class=&quot;listing listing2&quot;
|-
! Value
! Meaning
! Version
|-
| md5
| MD5 encryption
| 0.6
|-
| sha1
| SHA1 encryption
| 1.0
|-
| encrypt
| MySQL encrypt function
| 1.0
|-
| password
| MySQL password encryption
| 1.0
|}


===E.g. in the users table [[fields.ini file]]===

&lt;code&gt;
[password]
   encryption=md5
&lt;/code&gt;
    </content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=34">
	<page_name>examples</page_name>
	<page_id>34</page_id>
	<page_title>examples</page_title>
	<content>==Xataface Examples==

[[toc]]

This section includes concrete examples of how Xataface has been used in the past.

===Demo Applications===

{| class=&quot;listing listing2&quot;
|-
! Screenshot
! Title/Description
! Developed by
|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://demo.weblite.ca/apps/librariandb/]]
| &apos;&apos;&apos;Librarian DB&apos;&apos;&apos;

A searchable database of library books.  Useful for small libraries (e.g. Church Libraries).

Log in with:
username: admin
password: password

[http://demo.weblite.ca/apps/librariandb/ Try the app]
| [http://solutions.weblite.ca Web Lite Solutions Corp.]

|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://demo.weblite.ca/apps/webauction/]]
| &apos;&apos;&apos;Web Auction&apos;&apos;&apos;

A simple web-based auction application for organizations to hold auctions.

Login with:
username: admin
password: password

[http://demo.weblite.ca/apps/webauction/ Try the app]
| [http://solutions.weblite.ca Web Lite Solutions Corp.]


|}

===Websites Powered by Xataface===

{| class=&quot;listing listing2&quot;
|-
! Screenshot
! Title/Description
! Developed by
|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://fueleconomydb.com]]
| &apos;&apos;&apos;Fuel Economy Database&apos;&apos;&apos; - A searchable database of gas mileage and fuel economy statistics for automobiles from 1986 to present.

[http://fueleconomydb.com Visit the site]
| [http://solutions.weblite.ca Web Lite Solutions Corp.]
|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://physics.sfu.ca]]
| &apos;&apos;&apos;Department of Physics, Simon Fraser University&apos;&apos;&apos;
This website is completely powered by Xataface.  It is backed by a MySQL database that stores faculty members, research groups, news, events, and more.  Faculty members are able to update their personal profiles and research profiles through a Xataface administration console.

[http://physics.sfu.ca Visit the site]
| [http://fas.sfu.ca/ SFU Faculty of Applied Sciences]

|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://science.ca]]
| &apos;&apos;&apos;Science.ca&apos;&apos;&apos;

The source for science in Canada.  Includes profiles for prominent scientists as well as other useful science-related information.  Xataface is used to power the bilingual (English/French) capabilities of this site.  It includes web-based administrative console for the administrator to manage all content, and for translators to translate the content.

[http://science.ca Visit the site]
| Science.ca web team

|-

| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://translation.weblite.ca]]
| &apos;&apos;&apos;Simple Website Translation Engine&apos;&apos;&apos;

A service that allows website owners to easily convert their website into multiple languages.  Support human and machine translation.  This service is powered by Xataface, and provides an administrative console for users to manage their website translations.

[http://translation.weblite.ca Visit the Site]

[http://swete.weblite.ca More about this service]

| [http://translation.weblite.ca Web Lite Translation Corp.]

|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://www.credituniondb.com]]
| &apos;&apos;&apos;Credit Union Database&apos;&apos;&apos;

A database of credit unions in the United States.  This site is powered by Xataface.

[http://www.credituniondb.com Visit the site]

| Vlad

|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://ierg.net/lessonplans/unit_plans.php]]
| &apos;&apos;&apos;IERG Lesson Plans Database&apos;&apos;&apos;

A searchable database of lesson plans created by the Imaginative Education Research Group.  This database is managed by Xataface.  It provides researchers with a web-based control panel to manage their lesson plans.

[http://ierg.net/lessonplans/unit_plans.php Visit the site]

| [http://solutions.weblite.ca Web Lite Solutions Corp.]

|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://ierg.net/people/]]
| &apos;&apos;&apos;IERG People Database&apos;&apos;&apos;

A simple database to manage the contributors and associates of the Imaginative Education Research Group.  Administrators have a web-based control panel to manage the people profiles in this database.

[http://ierg.net/people/ Visit the site]

| [http://solutions.weblite.ca Web Lite Solutions Corp.]

|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://sustain-gradnetwork.envr.sfu.ca/]]
| &apos;&apos;&apos;Sustainability Research Database&apos;&apos;&apos;

A database at Simon Fraser University for grad students to post and share research profiles.

[http://sustain-gradnetwork.envr.sfu.ca/ Visit the site]

| [http://fas.sfu.ca Faculty of Applied Sciences Web Team]

|-
| [[Image:http://images.websnapr.com/?size=150&amp;key=40f0knTakb1b&amp;url=http://apps.weblite.ca/]]
| &apos;&apos;&apos;Web Lite Applications Catalog&apos;&apos;&apos;

A catalog of applications available through Web Lite Solutions.  Allows users to set up their own online applications on Web Lite&apos;s servers.  This site is completely powered by Xataface.

[http://apps.weblite.ca/ Visit the site]

| [http://solutions.weblite.ca Web Lite Solutions Corp.]
|}


</content>
	<keywords>examples, samples</keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=51">
	<page_name>fieldgroup_template</page_name>
	<page_id>51</page_id>
	<page_title>fieldgroup_template</page_title>
	<content>==Using a custom template for a field group on the edit form==

[[toc]]

Xataface allows you to partition your fields into &apos;&apos;groups&apos;&apos; so that similar fields are grouped together on the edit form.  The default layout of the fields remains simply vertical, but you can customize this layout (on a per-group basis) by creating a custom template and then assigning this template to the field group with the &apos;&apos;template&apos;&apos; directive.


===Example===

For example, in your [[fields.ini file]] if you wanted to group your address fields together you might have:
&lt;code&gt;
[fieldgroup:address]
    label=&quot;Address Information&quot;
    template=&quot;AddressInformationGroup.html&quot;

[address_1]
    group=address

[city]
    group=address

[state]
    group=address
&lt;/code&gt;

Then you would add the a template named &apos;&apos;AddressInformationGroup.html&apos;&apos; to your application&apos;s &apos;&apos;templates&apos;&apos; directory to display how the fields are laid out:
&lt;code&gt;
&lt;table width=&quot;100%&quot;&gt;
    &lt;tr&gt;&lt;th&gt;Address 1:&lt;/th&gt;
    &lt;td&gt;{$elements.address_1.html}&lt;/td&gt;

    &lt;th&gt;City:&lt;/th&gt;
    &lt;td&gt;{$elements.city.html}&lt;/td&gt;

    &lt;th&gt;State:&lt;/th&gt;
    &lt;td&gt;{$elements.state.html}&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;
&lt;/code&gt;
This would display all of the fields in this group in a single row (horizontally) instead of vertically.

Note that this is an over-simplified example that doesn&apos;t take account for display error messages, required notices, grouped fields, and other information that you can obtain from the {$elements} array.</content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=133">
	<page_name>fieldname__default</page_name>
	<page_id>133</page_id>
	<page_title>fieldname__default Delegate Class Method</page_title>
	<content>Return to [[Delegate class methods]]

[[toc]]

===Synopsis===

Xataface allows you to pre-populate any particular field in a table by adding a fieldname__default method to the table&apos;s delegate class of the form:
&lt;code&gt;
function fieldname__default(){
    return value;
}&lt;/code&gt;

Returns the default value for the field fieldname. New record forms will be prepopulated with this value.

===Examples===

&lt;code&gt;
function minimum_bid__default(){
    return 100;
}&lt;/code&gt;

&lt;code&gt;
function mydatecol__default(){
    return date(&apos;Y-m-d&apos;);
}&lt;/code&gt;

&lt;code&gt;
function owner_id__default(){
    $auth =&amp; Dataface_AuthenticationTool::getInstance();
    $user =&amp; $auth-&gt;getLoggedInUser();
    if ( isset($user) ) return $user-&gt;val(&apos;userid&apos;);
    return null;
}&lt;/code&gt;

===See Also===

* [http://xataface.com/forum/viewtopic.php?t=5028 Pre-entered Data] (forum thread) - setting defaults field values on general fields using the fieldname__default delegate class function
* [http://xataface.com/forum/viewtopic.php?t=4004 How to initialize a Date field to today&apos;s date?] (forum thread) - alternate methods to use specifically with a date/time field
* [http://xataface.com/forum/viewtopic.php?t=3988 Setting default select setting from users table] (forum thread) - solution to populate the current user</content>
	<keywords>default, initialize, populate, pre-populate, delegate class default</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=53">
	<page_name>fieldname__permissions</page_name>
	<page_id>53</page_id>
	<page_title>fieldname__permissions</page_title>
	<content>==fieldname__permissions() method==

[[toc]]

The fieldname__permissions() methods will allow you to define custom permissions on a particular field in the [[delegate class]].  For example to specify permissions on a field named &apos;&apos;foo&apos;&apos; you would define the &apos;&apos;foo__permissions()&apos;&apos; method, and to define permissions on a field named &apos;&apos;role&apos;&apos; you would define the &apos;&apos;role__permissions()&apos;&apos; method.


==Example #1==

(Note this example needs to be refined to be more clear)

&lt;code&gt;
function approval_level__permissions(&amp;$record){
	return array(&apos;edit&apos;=&gt;0); //this is will merge with what the permissions for the normal record
}
&lt;/code&gt;

Here we are targeting the &apos;&apos;approval_level&apos;&apos; field of the [[delegate class]].  The permissions method takes a return value an array of permissions.  So for example:

&lt;code&gt;
$permissions[&apos;new&apos;] = 0;
$permissions[&apos;edit&apos;] = 0;
&lt;/code&gt;

Would be an example of an array of permissions which the key being the permission name and the value being a boolean to specify whether they have (1) or don&apos;t (0) have permissions to that field.  We don&apos;t have to specify a complete array of permissions (ie. permission of edit, new, readonly, etc, etc), but rather only the ones we want specifically.  The reason being that the permissions array in the return value gets merged with the permissions that this record normally gets from the record permissions.

So if the record normally gives the permissions new=0, edit=1.  Then the return value from approval_level will merge with the original permissions to produce an array like this:

&lt;code&gt;
$permissions[&apos;new&apos;] = 0;
$permissions[&apos;edit&apos;] = 1;
&lt;/code&gt;

=== Also See: ===

* [[How_to_granulate_permissions_on_each_field]]
* [[__field__permissions]]</content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=94">
	<page_name>fieldname__validate</page_name>
	<page_id>94</page_id>
	<page_title>fieldname__validate Delegate Class Method</page_title>
	<content>Return to [[Delegate class methods]]

[[toc]]

===Synopsis===

Xataface allows you to add validation on any particular field in table by adding a fieldname__validate method to the table&apos;s delegate class of the form:
&lt;code&gt;
function myfield__validate(&amp;$record, $value, &amp;$params){
    if ( $value != &apos;Steve&apos; ){
        $params[&apos;message&apos;] = &apos;Sorry you must enter &quot;Steve&quot;&apos;;
        return false;
    }
    return true;
}
&lt;/code&gt;

===Parameters===

* &amp;$record : A [http://dataface.weblite.ca/Dataface_Record Dataface_Record] object encapsulating the record we are validating.  Note that the values of this object correspond with the submitted values from the form, and not necessarily the actual values of the record in the database.
* $value : The value that is being inserted.
* &amp;$params : An output array that can be used to pass back a message if validation fails.  You would set this array&apos;s &apos;message&apos; parameter to be a message.

===Returns===

Returns a boolean value.  True if the value is ok and false if validation failed.

===See Also===

* [[validators]] - For simple validation rules you can use the [[validators|validator:VALIDATOR_NAME]] directive of the [[fields.ini file]].
* [http://xataface.com/documentation/tutorial/getting_started/validation Form Validation] - Section on form validation in the Getting Started tutorial.

</content>
	<keywords>validate, validation, delegate class validation, custom validator</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=83">
	<page_name>Key</page_name>
	<page_id>83</page_id>
	<page_title>fields.ini Directive: Key</page_title>
	<content>The &apos;&apos;&apos;Key&apos;&apos;&apos; directive is used only when the table is a view and you need to explicitly define which columns are part of the primary key.  For example, if we created a view on the books table to only show books in a given year as follows:
&lt;code&gt;
create view books_2000 as
select * from books where year=&apos;2000&apos;
&lt;/code&gt;

And we wanted to use this view as a table in our Xataface application we would need to tell it that the primary key of this view is the book_id field.  So in the fields.ini file we would add:

&lt;code&gt;
[book_id]
    Key=PRI
&lt;/code&gt;

Note that this is case sensitive.  key=PRI will not work.

===Compound Primary Keys===

For primary keys comprising multiple columns we would add this directive for each field in the key.  E.g. if our books_2000 view had 2 fields in the primary key, say author_id and book_index, we would have in the books_2000 fields.ini file:
&lt;code&gt;
[author_id]
    Key=PRI

[book_index]
    Key=PRI
&lt;/code&gt;

Links:
* [http://xataface.com/forum/viewtopic.php?f=4&amp;t=6723 Lookup widget on view with compound primary key]

Return to [[fields.ini file]]</content>
	<keywords>Key, Views, MySQL Views, Create View, PRI, Primary Keys</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=3">
	<page_name>fields.ini_file</page_name>
	<page_id>3</page_id>
	<page_title>fields.ini_file</page_title>
	<content>==fields.ini File Reference==

[[toc]]

===Overview===

The fields.ini file is a configuration file which is associated with a single table of a database application.  It provides metadata about the table&apos;s fields to help Xataface dictate how they should be included in the application.  This includes metadata such as

* [[widget:type|Widget type]] - To specify the type of widget that should be used to edit content in the field (e.g. text, select, checkbox).
* [[widget:label|Label]] - The labels that can be used in column headers and on forms.
* [[widget:description|Help text]] - for forms to inform the user how data should be entered.
* [[group|Field Groupings]]
* [[widget:atts|widget:atts]] - To use javascripts in event handlers
* and more

Although a table doesn&apos;t need to have an associated fields.ini file in order for the application to work, each table can have one; and it is always located in the [[table configuration directory]].  For example, the fields.ini file for the [[people]] table would be located at [[Site Root]]/tables/people/fields.ini file.

===Syntax===

The fields.ini file uses [[standard INI syntax]] (just like the php.ini file), where each section corresponds to a column in the table. 

For example, consider a table &quot;people&quot; with columns &quot;first_name&quot;, &quot;last_name&quot;, and &quot;age&quot;.  The fields.ini file for the people table could then contain sections for each of its columns as follows:

&lt;code&gt;
[first_name]

[last_name]

[age]
&lt;/code&gt;

In this example the sections are empty (i.e. they have no directives, but we could easily add some directives:

&lt;code&gt;
[first_name]
    widget:description=&quot;Please enter your first name&quot;
    widget:label=&quot;Given Name&quot;

...etc...
&lt;/code&gt;

Here we have told Xataface that the first name field should include some help text (using the [[widget:description]] directive) on its edit form.

===Example fields.ini file===
&lt;code&gt;

;; Global directives applied to every field (requires Xataface 1.2.6)
[__global__]
	visibility:list=hidden

[isbn]
widget:label = ISBN
visibility:list=visible


[copyright_year]
widget:label = &quot;Year&quot;
widget:atts:size=4
visibility:list=visible

[categories]
widget:type=checkbox
vocabulary = book_categories

[media]
widget:type=checkbox
vocabulary = book_media

[borrower_id]
widget:type=select
vocabulary=users

[due_date]
widget:description = &quot;The date that the book is due to be returned to the library&quot;
visibility:list=visible


[cover_art_url_small]
visibility:browse=hidden


[cover_art_url_medium]
;visibility:browse=hidden


[cover_art_url_large]
visibility:browse=hidden
visibility:find=hidden

[amazon_description]
widget:label = Description


[amazon_reviews]


[amazon_url]

[amazon_refresh_timestamp]
widget:type=static

[date_created]
timestamp=insert
widget:type = static


[date_modified]
timestamp=update
widget:type=static


[created_by]
widget:type=static


[modified_by]
widget:type=static

[notes]

&lt;/code&gt;

This is an example from the [http://apps.weblite.ca/index.php?-action=view&amp;-table=packages&amp;package_id=%3D2 Library DB] application for the books table. 


===Field Directives===

The following directives may be added to a field&apos;s section of the fields.ini file to customize the field&apos;s behavior.  Some directives are not applicable to all fields.

{| class=&quot;listing listing2&quot;
|-
! Name
! Description
! Version
|-
| [[column:label]]
| Specifies a custom label to use in list view for the column.  If this is not specified, then the value of [[widget:label]] will be used.
| 1.3
|-
| [[column:legend]]
| Adds a small amount of help text to the column header for this field in list view.  Default is blank.  E.g. &lt;nowiki&gt;&lt;br/&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Screen%20shot%202011-02-08%20at%205.05.55%20PM.png?max_width=640&quot;/&gt;&lt;br/&gt;&lt;/nowiki&gt;In this photo it shows the text &quot;*Paper Uploaded&quot; set as the [[column:legend]] for &quot;field 1&quot;.
| 1.3
|-
| [[date_format]]
| Specifies how the field should be formatted when displayed.  Takes same parameters as PHP [http://php.net/strftime strftime] function.
| 2.0
|-
| [[display]]
| Specifies the layout of the field on the edit form.  Most fields have an implicit value of &quot;inline&quot; meaning the widget and its label appear on the same line.  Textareas and htmlareas have an implicit value of &quot;block&quot; meaning that the label and widget appear in separate rows (label above the widget).  You can set this value explicitly also to override the layout of a field.
| 0.8
|-
| [[display_format]]
| A pattern that can be used to define the display format of the field.  This takes the same parameters as the PHP [http://php.net/sprintf sprintf] function.
| 2.0
|-
| [[encryption]]
| Primarily used with password fields, indicates the type of encryption that should be used to save the field.  Supports &quot;md5&quot;, &quot;sha1&quot;, &quot;encrypt&quot;, and &quot;password&quot;.
| 0.6
|-
| event.date
| For use by the [[Calendar Action]].  Indicates that the field stores the date of the record when interpreted as an event.  Possible values &quot;0&quot; or &quot;1&quot;.
| 1.0
|-
| event.start
| For use by the [[Calendar Action]].  Indicates that the field stores the start time of the record when interpreted as an event.  Possible values &quot;0&quot; or &quot;1&quot;.
| 1.0
|-
| event.end
| For use by the [[Calendar Action]]. Indicates that the field stores the end time of the record when interpreted as an event.  Possible values &quot;0&quot; or &quot;1&quot;.
| 1.0
|-
| event.location
| For use by the [[Calendar Action]].  Indicates that the field stores the location of a record when interpreted as an event.  Possible values &quot;0&quot; or &quot;1&quot;.
| 1.0
|-
| [[filter]]
| Boolean value (0 or 1) indicating whether this field should be [[filterable]] in [[list view]].
| 0.8
|-
| [[frozen_description]]
| The field description shown when the widget is frozen (i.e. uneditable).  If this is not specified, no field description is shown in this case.
| 1.2
|-
| [[group]]
| The name of the field group that this field belongs to.  Fields with the same &quot;group&quot; value will be rendered in the same field group on the form.
| 0.5
|-
| [[Key]]
| If you are using a View for the table you need to explicitly mark the fields that comprise the primary key.  E.g. Key=PRI
| 0.6

|-
| [[label_link]]
| An optional URL for the field label to link to.  This would usually be some &quot;help&quot; page that explains what the field is for.  The link will be a link in both the view and edit tabs.
| 1.1.3
|-
| [[ignore]]
| Boolean value (0 or 1) indicating whether this field should be ignored on the edit form.  This is handy if the field is going to be constantly updated in the background (via a cron job perhaps) and you don&apos;t want the edit form to interfere.
| 1.0
|-
| [[logo]]
| Boolean value (0 or 1) to indicate if this field should be treated as a logo field.  Logo fields are displayed in the upper left of the [[view tab]] for a record, and are assumed to contain an image.  If no logo field is explicitly specified, Xataface will make a best guess as to which field should be used.
| 0.7
|-
| [[money_format]]
| For fields containing monetary amounts, this specifies the format.  Takes same parameters as PHP [http://php.net/money_format money_format] function.
| 2.0
|-
| [[noLinkFromListView]]
| Boolean value (0 or 1) to indicate if this field should be linked when in list view (or in a related list).  Default value is 0 to indicate that the field IS linked.  It is common to use this directive when using a custom xxx__renderCell() method that contains its own links.
| 1.1
|-
| [[not_findable]]
| A flag to indicate that this field can not be used as part of a query. This is helpful if you want a field to remain completely confidential to prevent people from finding records based on the value of this field.  This flag is even necessary if the permissions for the field don&apos;t permit viewing the value of the field.
| 1.1
|-
| [[number_format]]
| For numeric fields, this indicates the number of decimal places to display when displaying this field.  E.g. 2
| 2.0
|-
| [[order]]
| The order of the field when laid out on forms and lists.  Can contain any floating point number or integer (e.g. 0, 10, -10, 235.4)
| 0.6
|-
| [[relationship]]
| Used only with complex fields that involve editing related records (e.g. [[grid]]).  This is the name of the relationship that the field should be edited.
| 0.8
|-
| [[repeat]]
| Boolean value (0 or 1) used in conjunction with a select widget to indicate whether to enable a multi-select.
| ?
|-
| [[section]]
| The name of the section that this field should belong to in the [[view tab]].
| 0.7
|-
| [[secure]]
| A boolean flag for use with [[container fields]] to indicate that it should use secure URLs for the file downloads (i.e. it will obey the application permissions).  Without this directives, uploaded files are served directly by apache and don&apos;t obey the Xataface permissions defined per record.
| 1.3
|-
| [[struct]]
| A boolean (0 or 1) value indicating whether this field is considered a structure.  A value of 1 indicates that this field is a structure and should not be truncated under any circumstances.  Normally fields are truncated at 255 chars in list view.  This is useful if the field contains XML or other structured data so that attempts to truncate it would destroy integrity.
| 1.1.2
|-
| [[tab]]
| If tabbed forms are enabled, then this specifies the name of the tab that this field belongs to on the edit form.
| 0.8
|-
| [[timestamp]]
| Indicates when a timestamp should be set in the field (only applicable for date and time fields).  Possible values are &quot;insert&quot; and &quot;update&quot;
| 0.7
|}

{| class=&quot;listing listing2&quot;
|-
! Name
! Description
! Version
|-
| [[title]]
| Boolean value (0 or 1) indicating whether this field should be treated as a title field.
| 0.7
|-
| [[transient]]
| Boolean value (0 or 1) indicating whether this field is a transient field or not.  A transient field is a field that is defined in the fields.ini file but not in the database.  Hence the values that are input into this field on the edit form are not saved to the database.
| 0.8
|-
| [[Type]]
| The data type of the field (note the capital &quot;T&quot; as Xataface is case sensitive).  This value is only overridden for [[container]] fields, however its value can be accessed programmatically for any field.
| 0.5
|-
| [[validators|validators:VALIDATOR_NAME]]
| A prefix for a validation type on the current field. (Replace &quot;VALIDATOR_NAME&quot; with the name of the validator to be used. e.g. required). There are many validators available to be used.
| 0.5
|-
| [[validators:VALIDATOR_NAME:message]]
| The message the should be displayed if the form fails to validator due to the &quot;VALIDATION_NAME&quot; validation rule.
| 0.5
|-
| [[viewgroup]]
| The name of the field grouping that this field will belong to in the view tab.  If this is not present, then it will be grouped according to the [[group]] directive.
| 1.0
|-
| [[visibility:browse]]
| Indicates whether the field should be visible in browse mode (i.e. in the &quot;view&quot; tab).  Possible values are &quot;visible&quot; and &quot;hidden&quot;.
| 0.6
|-
| [[visibility:csv]]
| Indicates whether the field should be included in CSV exports.  Possible values are &quot;visible&quot; and &quot;hidden&quot;. (1.0 beta 4)
| 1.0b4
|-
| [[visibility:find]]
| Indicates whether the field should be visible in find mode.  Possible values are &quot;visible&quot; and &quot;hidden&quot;
| 1.0
|-
| [[visibility:list]]
| Indicates whether the field should be visible in list view.  Possible values are &quot;visible&quot; and &quot;hidden&quot;.
| 0.6
|-
| [[visibility:update]]
| Indicates whether the field should be included in update and copy/replace forms.  Possible values are &quot;visible&quot; and &quot;hidden&quot;.
| 1.3
|-
| [[vocabulary]]
| The [[valuelist]] that should be used as the options to select.  This is only applicable for fields that have options to select like a select list or a checkbox group.
| 0.5
|-
| [[widget:atts]]
| A namespace for attributes that should be added to the HTML widget.  This allows you to specify things like javascript events, styles, widget size, etc..
| 0.5
|-
| [[widget:columns]]
| For checkbox groups, this specifies the number of columns to use for laying out the checkboxes.
| 1.0
|-
| [[widget:description]]
| Help text to give the user a hint about how to edit the field&apos;s content.
| 0.1
|-
| [[widget:editor]]
| The type of HTML editor that should be used.  This is used only when [[widget:type]] is set to [[widget:type htmlarea|htmlarea]]

Acceptable values include:

* [http://www.fckeditor.net/ fckeditor] (default)
* [http://tinymce.moxiecode.com/ tinymce]  (version 0.6 or higher)
* [http://www.nicedit.com/ nicedit] (version 1.0 or higher)
| all
|-
| [[widget:editvalues]]
| Used with select lists to allow users to add values to the select list.  E.g. widget:editvalues=1
| 0.8
|-
| widget:focus
| Sets default focus. 0 or 1. (Javascript focus in a form)
| 0.6
|-
| [[widget:label]]
| The label that should be used for the current field on edit forms, column headings, and other relevant locations.
| 0.1
|-
| [[widget:question]]
| Text displayed just before the widget.  This is almost the same as [[widget:description]] except that this text is guaranteed to be displayed before the widget, whereas [[widget:description]] may be displayed below or beside the widget.
| 0.1
|-
| [[widget:type]]
| The type of widget that should be used (e.g. checkbox, select, text, etc..)
| 0.1
|-
| [[xml]]
| A flag for use with calculated fields (i.e. fields defined in the [[delegate class]] via the [[field__fieldname]] method) that will include the field in XML output produced by the [[export xml action]].  Default is 0, but setting this value to 1 wil cause the field to be included.
| 1.2.7
|}

===Applying Directives to All fields (__global__)===

Xataface 1.2.6 includes support for a [[__global__]] section that allows you to specify directives that should be applied to all fields.  These directives can be overridden on a field by field basis.  The [[__global__]] section can take all the same directives that a normal field section takes.


===widget:atts:class Values===

The widget:atts:class directive allows you to assign a CSS class to a field&apos;s widget.  There
are certain CSS classes that have meaning to Xataface and will cause additional functionality
to automatically be added to the field.  These built-in classes are listed below:

{| class=&quot;listing listing2&quot;
|-
! Name
! Description
! Version
|-
| [[passwordTwice]]
| Applicable only to password fields.  If you set widget:atts:class=passwordTwice, then this will convert the password field into two fields whereby both fields need to match in order for submission to continue on the edit form. This operates as a password verification field.&quot;
| 1.3rc2
|}



===Global Directives===

The following directives can be added to the beginning of the fields.ini file (before any field sections) to customize field groups and the table as a whole.

{| class=&quot;listing listing2&quot;
|-
! Name
! Description
! Version
|-
| [[__dependencies__]]
| A comma-delimited list of tables that this table is dependent upon for caching purposes.  E.g. if any table in this list is modified, then the query cache is cleared for queries on this table.  See this [http://xataface.blogspot.com/2009/06/using-query-caching-in-xataface.html blog article] for more information about query caching.
| 1.2
|-
| [[__isa__]]
| The name of the parent table of the current table.  This directive allows you to have a heirarchical structure amongst the tables in your application.
| 0.8
|-
| [[__source_tables__]]
| A comma-delimited list of tables that this table/view is derived from.  This is used with the query caching feature and is necessary to use this directive if the table is actually a view.  If this directive is not set, then any queries involving this view will not use the query cache because Xataface would have no way to discern the update time of the view.  See this [http://xataface.blogspot.com/2009/06/using-query-caching-in-xataface.html blog article] for more information about query caching.
| 1.2
|-
| [[__sql__]]
| Defines a custom select query to override the default select query for the current table.  (The default select query is generally &quot;select * from tablename&quot;).
| 0.7
|-
| [[__prefs__]]
| Sets preferences for this table and its records.
| 1.0b4
|}


===Field Groups===

The [[group]] directive allows you to group multiple fields together so that they will be rendered in the same field group on forms.  
You can also configure these groups as a whole by defining a section named &quot;[fieldgroup:GROUPNAME]&quot; (where GROUPNAME is the name of the field group, corresponding to the [[group]] directive values for the fields)
in the fields.ini file.  This section provides a few basic directives to customize some aspects of the field group:

* label
* order
* description
* template
* more...

The most common use of these sections is to customize the label or order of groups, especially when there are multiple field groups in the table.
For example, suppose we have a table &quot;people&quot; with fields &quot;first_name&quot;, &quot;last_name&quot;, &quot;phone&quot;, &quot;fax&quot;, &quot;email&quot;, &quot;address&quot;, &quot;city&quot;, and &quot;country&quot;. 
Suppose these fields are grouped as follows:

* &quot;first_name&quot; and &quot;last_name&quot;
* &quot;phone&quot;, &quot;fax&quot;, and &quot;email&quot;
* &quot;address&quot;, &quot;city&quot;, and &quot;country&quot;

so that the fields.ini file looks like:

&lt;code&gt;
[first_name]
    group=name
    
[last_name]
    group=last_name
    
[phone]
    group=contact
    
[fax]
    group=contact
[email]
    group=contact
    
[address]
    group=address
    
[city]
    group=address
    
[country]
    group=address

&lt;/code&gt;

By default, the &quot;name&quot; group will appear first in the form, followed by &quot;contact&quot; and &quot;address&quot;.  If we want to place &quot;address&quot; first we could add the following section to our fields.ini file:

&lt;code&gt;
[fieldgroup:address]
    order=-1
&lt;/code&gt;

Since the default order value is 0 on other groups, setting the &quot;order&quot; parameter to -1 will place the &quot;address&quot; group before all others.

====Field Group Directives====

The following directives are applicable in a fieldgroup section:

{| class=&quot;listing listing2&quot;
|-
! name
! description
! version
|-
| [[fieldgroup order|order]]
| Specifies the order of the group with respect to other groups on the form.  Accepts any numerical value (e.g. 0, 1, -1, 25.43), with lower values appearing first.  Default value is 0.
| 0.6
|-
| [[fieldgroup label|label]]
| Specifies the label that should be used for the field group.
| 0.6
|-
| [[label_link]]
| Specifies a URL that the field group label should link to.
| 1.1.3
|- 
| [[fieldgroup template|template]]
| The path to a custom template that should be used to render the fields of the field group.
| 1.0
|-
| [[fieldgroup collapsed|collapsed]]
| Boolean value (0 or 1) indicating whether the field group should be collapsed by default (user can expand it).  
| 1.0
|}
</content>
	<keywords>fields.ini directives </keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=104">
	<page_name>field__pullValue</page_name>
	<page_id>104</page_id>
	<page_title>field__pullValue delegate class method</page_title>
	<content>[[toc]]

The field__pullValue() delegate class method can be used to transform database from the database for use in an edit/new record form.  Sometimes it is the case that we want users to be able to work with data differently than it is stored in the database.

This method should always be accompanied by a corresponding [[field__pushValue]] method which performs the inverse operation and is used to transform the value in an edit form into a format that can be stored in the database.

===Example===

Given a field &apos;&apos;start_ip&apos;&apos; that stores an IP address in the database as an unsigned INT, we want to be able to work with the data on the edit form in a friendlier format - the standard IP address dot notation, so we define pullValue and pushValue methods for the field in the table&apos;s delegate class.

&lt;code&gt;
class tables_ip_blocks {

	/**
	 * @param Dataface_Record $record The record we are pushing the value
	 *		into
	 * @param HTML_QuickForm_element $el The QuickForm widget that we are 
	 *      retrieving the value from.
	 */
	function start_ip__pushValue($record, $el){
		$val = ip2long($el-&gt;getValue());
		if ( $val !== false ){
			return sprintf(&apos;%u&apos;, $val );
		}
		return null;
	}
	
	function start_ip__pullValue($record, $el){
		$val = $record-&gt;val(&apos;start_ip&apos;);
		if ( $val )
			return long2ip($val);
		return $val;
	}
}
&lt;/code&gt;

==References==

* [[Delegate class methods]]
* [[Application Delegate Class]]
* [[http://dataface.weblite.ca/Dataface_Record Dataface_Record API docs]
* [http://xataface.com/documentation/how-to/how-to-define-custom-serialization-for-fields How to define custom serialization for fields] - A how-to document.
</content>
	<keywords>pushValue, pullValue</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=27">
	<page_name>filter</page_name>
	<page_id>27</page_id>
	<page_title>filter</page_title>
	<content>==The filter attribute of the [[fields.ini file]]==

The filter attribute with a value of 1 specifies that a field should be used as a filter field in list view.  In list view, any filter fields will provide a select list with all of the possible values in that field.  Selecting one of the items in this list will filter the results to only show records of that value.

===Example 1: Year, Make, Model===

The Fuel Economy Database has three fields with filter=1 : Year, Make, and Model.  I.e., in their fields.ini file we have something like:

&lt;code&gt;
[Year]
    filter=1

[Make]
    filter=1

[Model]
    filter=1
&lt;/code&gt;

This causes 3 select lists to appear in list view.  See the application [http://fueleconomydb.com/index.php?-action=list here] and notice the select lists for Year, Make, and Model just above the list of results.

If you are filtering on a field where an ID is stored in the DB but you are using a vocabulary to associate it with a value, then it will still be sorted on the ID.

If you want to sort on value then you should add a [[Grafted fields|grafted field]] with the value using the __sql__ directive of the fields.ini file, then use that grafted field as your filter field, like the following:

&lt;code&gt;
__sql__ = &quot;select a.*, b.foo_name from a left join b on a.foo_id=b.foo_id&quot;

[foo_name]
filter=1
&lt;/code&gt;
</content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=79">
	<page_name>GettingStarted:validation</page_name>
	<page_id>79</page_id>
	<page_title>Form Validation</page_title>
	<content>==Form Validation==

Xataface allows you to add validation rules to fields using the fields.ini file
A common requirement for forms is to have some validation rules. Here are some example validation rules:

* The Username field is required.
* The Username must be between 6 and 16 characters long.
* The password must have at least one letter and one digit.
* The Email field must contain a valid email address.

There is no end to the types of things that you will need to validate. Xataface takes care of most of this for you with both client-side (javascript) and server-side validation. All you have to do is define some validation rules in the fields.ini file.

===Example 1: Make &apos;Username&apos; a required field===
&lt;code&gt;
[Username]
	validators:required = true
	validators:required:message = &quot;Username is required&quot;
&lt;/code&gt;

Placing the above inside the fields.ini file will cause the Username field to be a required field.

===Example 2: Username must be between 6 and 16 characters long===

For this rule we will use a regular expression.
&lt;code&gt;
[Username]
	validators:regex = &quot;/^.{6,16}$/&quot;
	validators:regex:message = &quot;Username must be between 6 and 16 characters long&quot;
&lt;/code&gt;

===Example 3: Email field must contain a valid email address===

&lt;code&gt;
[Email]
	validators:email = true
	validators:regex:message = &quot;Email must contain a valid email address&quot;
&lt;/code&gt;

===Available validation rules===

Xataface uses the PEAR library HTML_Quickform for validation, so any of the validators available in this package will be available in Xataface. Some of the available validation rules include:

* required
* maxlength
* rangelength
* regex
* email
* emailorblank
* lettersonly
* alphanumeric
* numeric
* nopunctuation
* nonzero

===Default validation rules===

There are certain validation rules that are automatically applied to fields of with certain characteristics. For example, any field designated NOT NULL in the SQL table definition will automatically be a &apos;required&apos; field. At the time of this writing, that is the only &apos;default&apos; validation rule applied, but more may be added in the future if their addition makes sense.

</content>
	<keywords>form validation,required field,validation rules</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=126">
	<page_name>getChildren</page_name>
	<page_id>126</page_id>
	<page_title>getChildren Delegate Class Method</page_title>
	<content>Return to [[Delegate class methods]]

[[toc]]

The getChildren() method can be implemented in a table&apos;s delegate class to specify the logical &quot;child&quot; records of a given record which can be used when creating hierarchical applications.  This method will effectively override the output of the Dataface_Record::getChildren() method for records of this table.

===Signature===

&lt;code&gt;
function getChildren( Dataface_Record $record) : Dataface_Record[]
&lt;/code&gt;

===Parameters===

# &apos;&apos;&apos;$record&apos;&apos;&apos; - The Dataface_Record that is the subject of the query 

===Returns===

This method should return an array of Dataface_Record objects that are considered to be children of the subject record.

===Examples===

&lt;code&gt;
function getChildren($record){
    return df_get_records(&apos;webpages&apos;, 
        array(
            &apos;parent_id&apos;=&gt;&apos;=&apos;.$record-&gt;val(&apos;webpage_id&apos;)
        )
    );
}
&lt;/code&gt;


==See Also==

* &apos;&apos;&apos;[[getParent]]&apos;&apos;&apos; - A Delegate class method to return the logical parent of a given record.</content>
	<keywords>getChildren Delegate class method</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=42">
	<page_name>getFeed</page_name>
	<page_id>42</page_id>
	<page_title>getFeed</page_title>
	<content>==getFeed() Delegate Class Method==

[[toc]]

===Synopsis:===

The getFeed() method of a table [[Delegate class methods|delegate class]] or [[Application Delegate Class|application delegate class]] returns an associative array of parameters to configure the [[Introduction_to_RSS_Feeds_in_Xataface|RSS feed]] for a particular table .  An RSS feed consists of the following components:

# &apos;&apos;&apos;title&apos;&apos;&apos; - The title of the RSS feed as it should appear in the subscribers&apos; feed list.
# &apos;&apos;&apos;description&apos;&apos;&apos; - Describes the RSS feed.
# &apos;&apos;&apos;link&apos;&apos;&apos; - A link to the RSS feed
# &apos;&apos;&apos;syndicationURL&apos;&apos;&apos; - The URL to this RSS feed&apos;s site.

===Parameters===

# &apos;&apos;&apos;array&apos;&apos;&apos; $query - The HTTP query.  Contains information like the current table, current action, and search parameters.  This allows you to customize your RSS feed depending on the user&apos;s query parameters.

===Return Value===

The getFeed() method returns an associative array with the components of the RSS feed.  This array does not need to contain all possible keys, or even any keys.  Any keys that are omitted will simply use default values in the RSS feed.  The array may contain the following keys:

{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| title
| The title for the RSS feed.  If this omitted, it will try to use the &apos;&apos;title&apos;&apos; directive of the &apos;&apos;[_feed]&apos;&apos; section of the [[conf.ini file]].  Failing that, it will try to generate an appropriate title for the feed depending on the current query.
| 1.0
|-
| description
| A Description for this RSS feed.  If this is omitted, it will try to use the &apos;&apos;description&apos;&apos; directive of the &apos;&apos;[_feed]&apos;&apos; section of the [[conf.ini file]].
| 1.0
|-
| link
| A link to the source page of the RSS feed.  If this is omitted, it will try to use the &apos;&apos;link&apos;&apos; directive of the &apos;&apos;[_feed]&apos;&apos; section of the [[conf.ini file]].
| 1.0
|-
| syndicationURL
| A link to the source page of the RSS feed.  If this is omitted, it will try to use the &apos;&apos;syndicationURL&apos;&apos; directive of the &apos;&apos;[_feed]&apos;&apos; section of the [[conf.ini file]].
| 1.0
|}

===Example===

&lt;code&gt;
function getFeed(&amp;$query){
    return array(
        &apos;title&apos; =&gt; &quot;RSS feed for the &quot;.$query[&apos;-table&apos;].&quot; table.&quot;,
        &apos;description&apos; =&gt; &quot;News and updates for automobiles&quot;,
        &apos;link&apos; =&gt; df_absolute_url(DATAFACE_SITE_HREF),
        &apos;syndicationURL&apos; =&gt; df_absolute_url(DATAFACE_SITE_HREF)
    );
}

&lt;/code&gt;

&apos;&apos;&apos;Note that RSS feeds will work perfectly well without defining this method.  This just allows you to customize one or more parameters of the RSS feed&apos;&apos;&apos;.

===See Also:===

* &apos;&apos;&apos;[[getFeedItem]]&apos;&apos;&apos; - A delegate class method available to both the [[Delegate class methods|table delegate classes]] to configure parameters for the particular items of the RSS feed.
* &apos;&apos;&apos;[[getRelatedFeed]]&apos;&apos;&apos; - A [[Delegate class methods|delegate class method]] available to both the [[Application Delegate Class|application delegate class]] and the [[Delegate class methods|table delegate classes]] to configure the [[Introduction to RSS Feeds in Xataface|RSS feed]] for a related records list.
* &apos;&apos;&apos;[[getRSSDescription]]&apos;&apos;&apos; - A delegate class method to override the description that appears for a particular record in an RSS feed.  (The same as the &apos;&apos;description&apos;&apos; parameter of the [[getFeedItem]] method.
* &apos;&apos;&apos;[[Introduction to RSS Feeds in Xataface]]&apos;&apos;&apos; - An overview of Xataface&apos;s RSS feed support.</content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=41">
	<page_name>getFeedItem</page_name>
	<page_id>41</page_id>
	<page_title>getFeedItem</page_title>
	<content>==getFeedItem() Delegate Class Method==

[[toc]]

===Synopsis:===

The getFeedItem() method of a table [[Delegate class methods|delegate class]] returns an associative array of parameters for a record as it should appear as part of an [[Introduction_to_RSS_Feeds_in_Xataface|RSS feed]].  An RSS feed item consists of the following components:

# &apos;&apos;&apos;title&apos;&apos;&apos; - The title of the record as it appears in the RSS feed.
# &apos;&apos;&apos;description&apos;&apos;&apos; - The description of the record for the RSS feed.  This is really the body of the RSS feed item.
# &apos;&apos;&apos;link&apos;&apos;&apos; - The linkback URL if users want to know more about the record.
# &apos;&apos;&apos;date&apos;&apos;&apos; - The date that the record was posted/modified.
# &apos;&apos;&apos;author&apos;&apos;&apos; - The name of the person who posted this record.
# &apos;&apos;&apos;source&apos;&apos;&apos; - URL to the site where record originated from.

===Parameters===

# &apos;&apos;&apos;Dataface_Record&apos;&apos;&apos; &amp;$record - The record that is being represented in an RSS feed.

===Return Value===

The getFeedItem() method returns an associative array with the components of the RSS feed.  This array does not need to contain all possible keys, or even any keys.  Any keys that are omitted will simply use default values in the RSS feed.  The array may contain the following keys:

{| class=&quot;listing listing2&quot;
! Name
! Description
! Version
|-
| title
| The record title as it appears in RSS feeds.  If this is omitted, the RSS feed will simply use the output of [http://dataface.weblite.ca/Dataface_Record Dataface_Record&apos;s] [http://dataface.weblite.ca/getTitle getTitle()] method.
| 1.0
|-
| description
| The record description.  This is used in the main body of the RSS feed.   If this is omitted, the RSS feed will use an HTML table that shows all of the field data in the record.  This value can also be overridden using the [[getRSSDescription]] method of the delegate class.
| 1.0
|-
| link
| The URL to this record.  If this is omitted it just points to the &apos;&apos;view&apos;&apos; tab for this record.  However you can direct it anywhere you like.  When the user clicks on the &quot;More Info&quot; link in his RSS reader it will direct him to this link.
| 1.0
|-
| date
| The date that this record was posted or last modified.  This is the date that an RSS reader will use to decide if it has already loaded the record yet.  If this is omitted it will try the [http://dataface.weblite.ca/Dataface_Record Dataface_Record&apos;s] [http://dataface.weblite.ca/getLastModified getLastModified()] method to obtain the last modified date of the record.  Failing that, it will use [http://dataface.weblite.ca/Dataface_Record Dataface_Record&apos;s] [http://dataface.weblite.ca/getCreated getCreated()] method to try to obtain the creation date of the record.  This date should be a unix timestamp.
| 1.0
|-
| author
| The name of the user who posted this record.  If this is omitted, then it will try to use [http://dataface.weblite.ca/Dataface_Record Dataface_Record&apos;s] [http://dataface.weblite.ca/getCreator getCreator()] method.  Failing that, it will use the value of the &apos;&apos;default_author&apos;&apos; parameter in the &apos;&apos;[_feed]&apos;&apos; section of the [[conf.ini file]].  If that is not defined, then it simply uses the string &quot;Site Administrator&quot;.
| 1.0
|-
| source
| The source URL where the feed is to have originated.  If none is specified, then it will use the value of the &apos;&apos;source&apos;&apos; parameter in the &apos;&apos;[_feed]&apos;&apos; section of the [[conf.ini file]].  Failing that, it will simply use the URL to the application.

Note that you can alternatively define this value using the [[getFeedSource]] method.
| 1.0
|}

===Example===

&lt;code&gt;
function getFeedItem(&amp;$record){
    return array(
        &apos;title&apos; =&gt; &quot;News Item: &quot;.$record-&gt;getTitle(),
        &apos;description&apos; =&gt; $record-&gt;display(&apos;News Body&apos;),
        &apos;link&apos; =&gt; $record-&gt;getPublicLink(),
        &apos;date&apos; =&gt; strtotime($record-&gt;val(&apos;last_modified&apos;)),
        &apos;author&apos; =&gt; $record-&gt;val(&apos;posted_by&apos;),
        &apos;source&apos; =&gt; &apos;http://www.example.com&apos;
    );
}

&lt;/code&gt;

&apos;&apos;&apos;Note that RSS feeds will work perfectly well without defining this method.  This just allows you to customize one or more parameters of the RSS feed&apos;&apos;&apos;.

===See Also:===

* &apos;&apos;&apos;[[getFeed]]&apos;&apos;&apos; - A delegate class method available to both the [[Application Delegate Class]] and the [[Delegate class methods|table delegate classes]] to configure the RSS feed as a whole (not just for an individual item in the RSS feed.
* &apos;&apos;&apos;[[getRelatedFeed]]&apos;&apos;&apos; - A [[Delegate class methods|delegate class method]] available to both the [[Application Delegate Class|application delegate class]] and the [[Delegate class methods|table delegate classes]] to configure the [[Introduction to RSS Feeds in Xataface|RSS feed]] for a related records list.
* &apos;&apos;&apos;[[getRSSDescription]]&apos;&apos;&apos; - A delegate class method to override the description that appears for a particular record in an RSS feed.  (The same as the &apos;&apos;description&apos;&apos; parameter of the [[getFeedItem]] method.
* &apos;&apos;&apos;[[Introduction to RSS Feeds in Xataface]]&apos;&apos;&apos; - An overview of Xataface&apos;s RSS feed support.</content>
	<keywords></keywords>
	<language>en</language>
	<original_page>0</original_page>
</wiki>
<wiki id="wiki?page_id=125">
	<page_name>getNavItem</page_name>
	<page_id>125</page_id>
	<page_title>getNavItem Application Delegate Class Method</page_title>
	<content>Return to [[Application Delegate Class]]

[[toc]]

===Synopsis===

The getNavItem() method of the application delegate class can be used to override the items that appear in the navigation menu (i.e. the menu that allows users to select the table via either tabs along the top or items along the side).  It should return an associative array with characteristics of the navigation item including the href (i.e. link), label, and selected status.

Using this method it is now possible to have non-table navigation items as well.  You would just add these items to the \[_tables\] section of the [[conf.ini file]] then override the item using this method.

&apos;&apos;&apos;Since 1.3&apos;&apos;&apos;

====How the Nav Menu Is Built====

Xataface builds the navigation menu by looping through each item in the [_tables] section of the conf.ini file, passing it to the getNavItem() method, and adding the resulting navigation item to the menu.  If getNavItem() returns null, then that item will be skipped.  If getNavItem throws an exception, then the default rendering for the menu item will take place.

===Signature===

&lt;code&gt;
function mixed getNavItem( string $key, string $label ) throws Exception
&lt;/code&gt;

===Parameters===

* &apos;&apos;&apos;$key&apos;&apos;&apos; - The key of the nav item.  In the case of a table, this would be the table name.
* &apos;&apos;&apos;$label&apos;&apos;&apos; - The label of the nav item (may be overridden).

===Returns===

This method should return either:

# An associative array with the properties of the nav item.
# null to indicate that this nav item should be omitted altogether.  (e.g. if the user shouldn&apos;t have permission for it).

If returning an associative array, it should contain the following keys:

* &apos;&apos;&apos;href&apos;&apos;&apos; - (String) The URL where this nav item should point.
* &apos;&apos;&apos;label&apos;&apos;&apos; - (String) The label of this nav item.
* &apos;&apos;&apos;selected&apos;&apos;&apos; - (Boolean) True if the nav item is currently selected.  False otherwise.

===Throws===

If you want to signal Xataface to just use default rendering for the current navigation item you can just throw an exception.  The default rendering will link to the table named &apos;&apos;$key&apos;&apos;, and the item&apos;s label will be the same as &apos;&apos;$label&apos;&apos;.


==Examples==

Given the following conf.ini file:

&lt;code&gt;
...
[_tables]
   people=People
   books=Books
   accounts=Accounts
   reports=Reports

...
&lt;/code&gt;

Suppose we want the navigation menu to only show the &apos;&apos;people&apos;&apos; and &apos;&apos;books&apos;&apos; options for regular users.  Admin users can see all options.

In addition, the &apos;reports&apos; option doesn&apos;t correspond with a table of the database.  Instead we are just going to link it to a custom action named &apos;reports&apos;.

Our getNavItem() method will look something like this:
&lt;code&gt;
function getNavItem($key, $label){
    if (!isAdmin() ){
        switch ($key){
            case &apos;people&apos;:
            case &apos;books&apos;:
                // non-admin users can see these
                throw new Exception(&quot;Use default rendering&quot;);
        }
        // Non-admin users can&apos;t see any other table.
        return null;
 
    } else {

        //Admin users can see everything..
        $query =&amp; Dataface_Application::getInstance()-&gt;getQuery();
        switch ($key){
            case &apos;reports&apos;:
                // reports is not a table so we need to return custom properties.
                return array(
                    &apos;href&apos; =&gt; DATAFACE_SITE_HREF.&apos;?-action=reports&apos;,
                    &apos;label&apos; =&gt; $label,
                    &apos;selected&apos; =&gt; ($query[&apos;-action&apos;] == &apos;reports&apos;)
                );
            
        }
        

        // For other actions we need to make sure that they aren&apos;t selected
        // if the current action is reports because we want the &apos;reports&apos;
        // tab to be selected only in that case.
        return array(
            &apos;selected&apos; =&gt; ($query[&apos;-table&apos;] == $key and $query[&apos;-action&apos;] != &apos;reports&apos;)
        );
    }
}
&lt;/code&gt;


===See Also===

* [[isNavItemSelected]] - Overrides default behavior of whether a navigation item is currently selected.
   </content>
	<keywords>getNavItem, navigation menu</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki>
<wiki id="wiki?page_id=121">
	<page_name>getPasswordChangedEmailInfo</page_name>
	<page_id>121</page_id>
	<page_title>getPasswordChangedEmailInfo Application Delegate Class Method</page_title>
	<content>Return to [[Application Delegate Class]]

[[toc]]

===Synopsis===

Optional method to define the settings for the email that is sent to the user upon successful resetting of their password using the password reset function. 

Introduced in Xataface 1.3.  Exists in 1.3 or higher.


===Signature===

&lt;code&gt;
function getPasswordChangedEmailInfo(Dataface_Record $user, string $password){}
&lt;/code&gt;

===Parameters===

* &apos;&apos;&apos;$user&apos;&apos;&apos; - The Dataface_Record of the user whose password has been changed.
* &apos;&apos;&apos;$password&apos;&apos;&apos; - The new temporary password that has been assigned to the user.

===Returns===

This method should return an associative array with 0 or more of the following keys:

* &apos;&apos;&apos;subject&apos;&apos;&apos; - The subject line of the email.
* &apos;&apos;&apos;message&apos;&apos;&apos; - The message content of the email.
* &apos;&apos;&apos;headers&apos;&apos;&apos; - The Email headers (as a string).
* &apos;&apos;&apos;parameters&apos;&apos;&apos; - Extra parameters for the mail function.

==See Also==

* [[getResetPasswordEmailInfo]] - A delegate class method to define the email that is sent to the user when they request a password reset.  This is the step that immediately precedes the Password Changed email step.</content>
	<keywords>forgot password, reset password</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki></record>