<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>Creating_Printable_Reports[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D82&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Wed, 22 May 2013 02:49:05 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>Creating_Printable_Reports</title>
            <link>http://www.xataface.com/wiki/Creating_Printable_Reports</link>
            <description>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page name&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;Creating_Printable_Reports&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page id&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;82&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page title&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;Creating a Custom Printable Report&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Content&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;
&lt;h2 id=&quot;toc0&quot;&gt;Creating a Printable Report&lt;/h2&gt;
&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tr&gt;&lt;td&gt;
&lt;div id=&quot;toc&quot;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;
	&lt;div style=&quot;margin-left: 0em;&quot;&gt;&lt;a href=&quot;#toc0&quot;&gt;Creating a Printable Report&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc1&quot;&gt;Requirements for our report&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc2&quot;&gt;Adding the Icon to our Application&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc3&quot;&gt;Creating the Actual Report&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc4&quot;&gt;Retrieving the Found Set&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc5&quot;&gt;Overriding -skip and -limit&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc6&quot;&gt;Looping through and Printing Product Info&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc7&quot;&gt;Adding a Little Style&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc8&quot;&gt;Connecting the Icon to the Action&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc9&quot;&gt;Trying out the action on different found sets with different sort orders&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc10&quot;&gt;Hiding Icon from Other Tables&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc11&quot;&gt;Locking Down our Action with Permissions&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;It is often useful to provide your users with a printable report that is generated from your database.  Although Xataface doesn'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.&lt;/p&gt;

&lt;p&gt;This report will be subject to the user's sorting and searching preferences.  E.g. if the user searches for only books about &amp;quot;frogs&amp;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).&lt;/p&gt;


&lt;h3 id=&quot;toc1&quot;&gt;Requirements for our report&lt;/h3&gt;
&lt;ol&gt;
    &lt;li&gt; Report will be run against the &amp;quot;products&amp;quot; table (using the WebAuction application).&lt;/li&gt;
    &lt;li&gt; Report should be accessible by clicking an icon in the top right of the list view (i.e. the resultlist actions).&lt;/li&gt;
    &lt;li&gt; Report should display the product ID, product name, photo, and description.  One product per page.&lt;/li&gt;
&lt;/ol&gt;


&lt;h3 id=&quot;toc2&quot;&gt;Adding the Icon to our Application&lt;/h3&gt;
&lt;p&gt;We'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:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; &lt;a href=&quot;http://www.famfamfam.com/lab/icons/silk/&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;FamFamFam Silk Icons&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;http://tango.freedesktop.org/Tango_Icon_Library&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;Tango Icon Library&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once you have found the icon you want to use, just upload it somewhere inside your application's directory.  It might be a good idea to create a directory to store your images if you haven't already.  An appropriate name might by &lt;em&gt;images&lt;/em&gt;.  For this example, we'll use the &lt;img src=&quot;http://dev.weblite.ca/phpimageserver/photos/icons/printer.png&quot; alt=&quot;http://dev.weblite.ca/phpimageserver/photos/icons/printer.png&quot; width=&quot;16&quot; height=&quot;16&quot; /&gt; icon from the FamFamFam icon library.  So we upload this icon to &lt;pre&gt; %APPLICATION_PATH%/images/printer.png
&lt;/pre&gt; Next we need to create an entry in our application's &lt;a href=&quot;/wiki/actions.ini_file&quot;&gt;actions.ini file&lt;/a&gt; so that Xataface knows about our action, and where we want its icon to be displayed.  We'll start out with a basic definition that just specifies the icon for the action, and the &lt;em&gt;category&lt;/em&gt; of the action.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[printable_report]
    icon=&amp;quot;{$site_url}/images/printer.png&amp;quot;
    category=result_list_actions
    description=&amp;quot;See this product list in a printable format&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;em&gt;result_list_actions&lt;/em&gt; 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 &amp;quot;list&amp;quot; tab, you'll see that the icon group in the top right now includes our icon:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%20-5.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%20-5.png?max_width=640&quot; width=&quot;135&quot; height=&quot;34&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If you don't see this icon, but see the text &amp;quot;printable_report&amp;quot; instead, then you have entered an incorrect path to the icon in the &lt;em&gt;icon&lt;/em&gt; directive.  If you don't see an icon at all or any text, then your &lt;em&gt;category&lt;/em&gt; directive may be incorrect.  Check that it is exactly &amp;quot;result_list_actions&amp;quot;.&lt;/p&gt;

&lt;p&gt;If you mouse over your icon you'll see the text that you specified as your &lt;em&gt;description&lt;/em&gt; directive for the action:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%20-6.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%20-6.png?max_width=640&quot; width=&quot;241&quot; height=&quot;65&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You'll notice, if you try to click on your icon, that nothing happens.  This is because we haven't yet specified a URL for your action.  We'll wait to specify our URL, until we've built the back-end of our action (i.e. the actual report).&lt;/p&gt;


&lt;h3 id=&quot;toc3&quot;&gt;Creating the Actual Report&lt;/h3&gt;
&lt;p&gt;Most reports involve the following pieces:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; Fetch the found set of records from the database.&lt;/li&gt;
    &lt;li&gt; Loop through the found set and output some information about each record.&lt;/li&gt;
    &lt;li&gt; Optionally use a template to integrate the report into your application's look and feel.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All reports will be placed in the framework of a custom Xataface action.  In our case we add a file to our application &lt;em&gt;actions&lt;/em&gt; directory named after our action: &lt;pre&gt; %APPLICATION_PATH%/actions/printable_report.php
&lt;/pre&gt; with the following contents:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;&amp;lt;?php
class actions_printable_report {
    function handle(&amp;amp;$params){
        echo &amp;quot;Hello world!!!&amp;quot;;
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Please note the following about this snippet:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; The action was placed in a file &lt;em&gt;actions/printable_report.php&lt;/em&gt; because the action is named &lt;em&gt;printable_report&lt;/em&gt; (referring to our definition in the &lt;em&gt;&lt;a href=&quot;/wiki/actions.ini_file&quot;&gt;actions.ini file&lt;/a&gt;&lt;/em&gt;.  If the action was named &lt;em&gt;foo&lt;/em&gt;, then we would place our action in file &lt;em&gt;actions/foo.php&lt;/em&gt;.&lt;/li&gt;
    &lt;li&gt; The &lt;em&gt;printable_report.php&lt;/em&gt; file contains a single class named &lt;em&gt;actions_printable_report&lt;/em&gt; after the name of the action.&lt;/li&gt;
    &lt;li&gt; The action class contains a single method &lt;em&gt;handle&lt;/em&gt; which handles the request for the action (i.e. outputs the report the way we like).  This method must exist and me named exactly &lt;em&gt;handle&lt;/em&gt;.&lt;/li&gt;
    &lt;li&gt; The &lt;em&gt;handle&lt;/em&gt; method takes a single &lt;em&gt;&amp;amp;$params&lt;/em&gt; parameter which contains some parameters that may be passed to the action.  We won't be dealing with these in this example.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before proceeding, let's try accessing our action just to make sure that we're on the right track.  Point your browser to  &lt;pre&gt; http://example.com/yourapplication/index.php?-action=printable_report
&lt;/pre&gt; Note that you don't point our web browser directly to your action php file (in the &lt;em&gt;actions&lt;/em&gt; directory.  Rather you point it to your application's entry point (index.php file), and specify the action via the &lt;em&gt;-action&lt;/em&gt; GET parameter.  Your web browser should display something like:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%204.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%204.png?max_width=640&quot; width=&quot;175&quot; height=&quot;66&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If you get a blank white screen, then you should check your error log to see where the error is occuring.  See &lt;a href=&quot;/wiki/Troubleshooting&quot;&gt;Troubleshooting&lt;/a&gt; for general Xataface troubleshooting strategies in this case.&lt;/p&gt;

&lt;p&gt;Now that we have all of the formalities out of the way, we can proceed to meat of our report.&lt;/p&gt;


&lt;h4 id=&quot;toc4&quot;&gt;Retrieving the Found Set&lt;/h4&gt;
&lt;p&gt;Let's build onto our action now.  First we will load the found set of records as follows:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;&amp;lt;?php
class actions_printable_report {
    function handle(&amp;amp;$params){
        $app =&amp;amp; Dataface_Application::getInstance();
        $query =&amp;amp; $app-&amp;gt;getQuery();
        
        if ( $query['-table'] != 'products' ){
            return PEAR::raiseError('This action can only be called on the Products table.');
        }
        
        $products = df_get_records_array('products', $query);
        
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Things to note in this snippet:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; We start be loading a reference to the &lt;em&gt;Dataface_Application&lt;/em&gt; object.&lt;/li&gt;
    &lt;li&gt; We then use the &lt;em&gt;Dataface_Application&lt;/em&gt; 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 &lt;em&gt;-table&lt;/em&gt; and &lt;em&gt;-action&lt;/em&gt;.&lt;/li&gt;
    &lt;li&gt; In our particular action we are designing it to only work for the &lt;em&gt;products&lt;/em&gt; 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.&lt;/li&gt;
    &lt;li&gt; We use the df_get_records_array() function to return all matching records on the products table.  It returns an array of Dataface_Record&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=Dataface_Record&quot;&gt;?&lt;/a&gt; objects.&lt;/li&gt;
&lt;/ol&gt;


&lt;h4 id=&quot;toc5&quot;&gt;Overriding -skip and -limit&lt;/h4&gt;
&lt;p&gt;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 &lt;em&gt;-skip&lt;/em&gt; and &lt;em&gt;-limit&lt;/em&gt; 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 &amp;quot;Next&amp;quot; in list view, you see '-skip' and '-limit' parameters automatically added to the URL.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;df_get_records_array&lt;/em&gt; 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 &lt;em&gt;$query&lt;/em&gt; array before passing it to &lt;em&gt;df_get_records_array&lt;/em&gt;.  E.g.:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$query =&amp;amp; $app-&amp;gt;getQuery();
$query['-skip'] = 0;
$query['-limit'] = 10000;
$products = df_get_records_array('products', $query);&lt;/code&gt;&lt;/pre&gt;


&lt;h4 id=&quot;toc6&quot;&gt;Looping through and Printing Product Info&lt;/h4&gt;
&lt;p&gt;Now comes the fun part.  We're just going to loop through our found set and print off the product information:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
foreach ($products as $p){
    

    echo '&amp;lt;table&amp;gt;'
        .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Product ID&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_id').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
        .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Product Name&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_name').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
        .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_description').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
        .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Photo&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_image').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
        .'&amp;lt;/table&amp;gt;';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The entire action at this point will look like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
&amp;lt;?php
class actions_printable_report {
    function handle(&amp;amp;$params){
        $app =&amp;amp; Dataface_Application::getInstance();
        $query =&amp;amp; $app-&amp;gt;getQuery();
        $query['-skip'] = 0;
        $query['-limit'] = 10000;
        
        if ( $query['-table'] != 'products' ){
            return PEAR::raiseError('This action can only be called on the Products table.');
        }
        
        $products = df_get_records_array('products', $query);
        foreach ($products as $p){
    

            echo '&amp;lt;table&amp;gt;'
                .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Product ID&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_id').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
                .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Product Name&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_name').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
                .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_description').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
                .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Photo&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_image').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
                .'&amp;lt;/table&amp;gt;';
        }
        
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we refresh our action in the web browser, or point the browser again to: &lt;pre&gt; http://example.com/yourapplication/index.php?-action=printable_report&amp;-table=products
 &lt;/pre&gt; It should display something like:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%205.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%205.png?max_width=640&quot; width=&quot;541&quot; height=&quot;483&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If you get a blank white screen, please check out the &lt;a href=&quot;/wiki/Troubleshooting&quot;&gt;Troubleshooting&lt;/a&gt; section for general Xataface troubleshooting strategies.&lt;/p&gt;


&lt;h4 id=&quot;toc7&quot;&gt;Adding a Little Style&lt;/h4&gt;
&lt;p&gt;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're going to add some CSS styles to:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; Make the table field labels vertically aligned to the top.&lt;/li&gt;
    &lt;li&gt; Change the font to helvetica.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is easy to do with simple echo statements:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;echo '&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;'
    .'&amp;lt;title&amp;gt;Printable Report&amp;lt;/title&amp;gt;'
    .'&amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;'
    .'    th { vertical-align: top}'
    .'&amp;lt;/style&amp;gt;'
    .'&amp;lt;/head&amp;gt;'
    .'&amp;lt;body&amp;gt;';
    
    //...
    
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So our finished action looks like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;&amp;lt;?php
class actions_printable_report {
    function handle(&amp;amp;$params){
        $app =&amp;amp; Dataface_Application::getInstance();
        $query =&amp;amp; $app-&amp;gt;getQuery();
        $query['-skip'] = 0;
        $query['-limit'] = 10000;
        
        if ( $query['-table'] != 'products' ){
            return PEAR::raiseError('This action can only be called on the Products table.');
        }
        
        $products = df_get_records_array('products', $query);
        
        
        
        echo '&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;'
            .'&amp;lt;title&amp;gt;Printable Report&amp;lt;/title&amp;gt;'
            .'&amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;'
            .'    th { vertical-align: top}'
            .'&amp;lt;/style&amp;gt;'
            .'&amp;lt;/head&amp;gt;'
            .'&amp;lt;body&amp;gt;';
        foreach ($products as $p){
    

            echo '&amp;lt;table&amp;gt;'
                .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Product ID&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_id').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
                .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Product Name&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_name').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
                .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_description').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
                .'&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Photo&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;'.$p-&amp;gt;htmlValue('product_image').'&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;'
                .'&amp;lt;/table&amp;gt;';
        }
        
        echo '&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;';
        
    }
}&lt;/code&gt;&lt;/pre&gt;


&lt;h3 id=&quot;toc8&quot;&gt;Connecting the Icon to the Action&lt;/h3&gt;
&lt;p&gt;FInally it is time to connect our Icon to our Action.  We do this by adding a &lt;em&gt;url&lt;/em&gt; directive for the action in the &lt;em&gt;&lt;a href=&quot;/wiki/actions.ini_file&quot;&gt;actions.ini file&lt;/a&gt;&lt;/em&gt;:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[printable_report]
    icon=&amp;quot;{$site_url}/images/printer.png&amp;quot;
    category=result_list_actions
    description=&amp;quot;See this product list in a printable format&amp;quot;
    url=&amp;quot;{$app-&amp;gt;url('-action=printable_report')}&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Explanation of the &lt;em&gt;url&lt;/em&gt; directive in this snippet:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt; The &lt;em&gt;url&lt;/em&gt; method of the &lt;em&gt;Dataface_Application&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=Dataface_Application&quot;&gt;?&lt;/a&gt;&lt;/em&gt; object is used to generate a URL with the user's current query settings, but with the &lt;em&gt;-action&lt;/em&gt; parameter set to &lt;em&gt;printable_report&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now if we reload our application, go to the list tab of the &lt;em&gt;products&lt;/em&gt; table and click on our icon, it should take us to our action:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%207.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%207.png?max_width=640&quot; width=&quot;448&quot; height=&quot;528&quot; /&gt;&lt;/p&gt;


&lt;h3 id=&quot;toc9&quot;&gt;Trying out the action on different found sets with different sort orders&lt;/h3&gt;
&lt;p&gt;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.&lt;/p&gt;


&lt;h3 id=&quot;toc10&quot;&gt;Hiding Icon from Other Tables&lt;/h3&gt;
&lt;p&gt;Since our action is only intended to operate on the &lt;em&gt;products&lt;/em&gt; table it probably isn't a good idea to make the icon visible for every other table.  For example, if you go to the list view of the &lt;em&gt;users&lt;/em&gt; table, you'll see the printer icon in the top right just like it appears for the &lt;em&gt;products&lt;/em&gt; table.  Clicking on it should display our error:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%206.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%206.png?max_width=640&quot; width=&quot;640&quot; height=&quot;167&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We will use a &lt;em&gt;condition&lt;/em&gt; directive for our action to hide it from tables other than the &lt;em&gt;products&lt;/em&gt; table as follows:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt; condition=&quot;$query['-table'] == 'products'&quot;
 &lt;/pre&gt; So our action will now look like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[printable_report]
    icon=&amp;quot;{$site_url}/images/printer.png&amp;quot;
    category=result_list_actions
    description=&amp;quot;See this product list in a printable format&amp;quot;
    url=&amp;quot;{$app-&amp;gt;url('-action=printable_report')}&amp;quot;
    condition=&amp;quot;$query['-table'] == 'products'&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now if you reload the list for the &lt;em&gt;users&lt;/em&gt; table you'll notice that the printer icon is now gone.  But returning to the &lt;em&gt;products&lt;/em&gt; table shows our action still alive and well.&lt;/p&gt;


&lt;h3 id=&quot;toc11&quot;&gt;Locking Down our Action with Permissions&lt;/h3&gt;
&lt;p&gt;In our case we don'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 &lt;em&gt;reports&lt;/em&gt; which only administrators have.  We will use this permission to limit access to this action as follows in the actions.ini file: &lt;pre&gt; permission=reports
&lt;/pre&gt; So the actions.ini file will now look like: 
&lt;pre&gt;&lt;code&gt;[printable_report]
    icon=&amp;quot;{$site_url}/images/printer.png&amp;quot;
    category=result_list_actions
    description=&amp;quot;See this product list in a printable format&amp;quot;
    url=&amp;quot;{$app-&amp;gt;url('-action=printable_report')}&amp;quot;
    condition=&amp;quot;$query['-table'] == 'products'&amp;quot;
    permission=reports&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;

&lt;p&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 &amp;quot;Access Denied&amp;quot; message.&lt;/p&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Language&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;en&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description>
            <author>Creating_Printable_Reports</author>
        </item>
    </channel>
</rss>
