community.egroupware.org: Community wiki

  
Community wiki
review of the third day and a step beyond
the day before | Up | the day after


We had a couple of days to rest and review what we had accomplished by then. As things happen we were nosy what would come, and fiddeled around a bit with the eTemplate. As we explored the site we tested DB-Tools.

As we finished our third day, we had a fairly basic application where we could type in some content, send it to ourself and get the stuff we did send presented to us just above our input field.
Not very fancy, nor impressive to look at - I had to admit.

I wanted something more like that:
to type in a name, a firstname, choose a type, have the possipility to clear the form, debug the data behind the form, and of course present the stuff I typed in.
The result was:

Within the eTemplate editor the whole thing looked like this:


I exported the thing as XML and the output looked like that:
You can see nicely the widgets that I have used (groupbox, grid, hrule and checkbox), how the widgets nest into each other (groupbox with a grid), how a grid is defined, etc. ...
The stuff I learned at the third day enabled me to do that.
You have to fiddle around a bit, the adding of widgets before or after a widget is tricky. There is alot, like copying stuff into another widget and converting a widget to another type of widget, and still having the stuff that was in there before. There are eTemplateUseNotes.
I learned, that, if something is disabled, you cannot see it, not even within the editor, but you can see it, if you export to XML. And you can navigate to that element using the navigation arrows in the path section of the cell-editor

Sure thing I had to modify my class.test_ui.inc.php file.


<?php
    require_once(EGW_INCLUDE_ROOT.'/test/inc/class.test_bo.inc.php');
    class test_ui extends test_bo
    {
        var $public_functions = array(
            'testinterface' => True,
            'index'    => True,
        );
        /**
        * instantiation of the etemplate as classenvariable
        *
        * @var etemplate
        */
        var $tmpl;

        /**
        * constructor of the class test_ui
        */
        function test_ui()
        {
            $GLOBALS['egw_info']['flags']['app_header']='test-Application';
            // instantiation of etemplate as class variable
            $this->tmpl =& CreateObject('etemplate.etemplate');
            $this->html =& $GLOBALS['egw']->html;
            /*
            * since we extend the boclass, we do not have to instantiate an object of the boclass.
            * none the less, we have to call the constructor of that class, to ensure, everything 
            * done there is done as we call the test_ui class
            */
            //$this->bo   =& CreateObject('test.test_bo');
            $this->test_bo();

            if(!@is_object($GLOBALS['egw']->js))
            {
	            $GLOBALS['egw']->js =& CreateObject('phpgwapi.javascript');
            }
        }

        /**
        * function create_header
        * this is creating the header for our non e-template approach
        */
        public function create_header ()
        {
            common::egw_header();
            echo parse_navbar();
        }

        /**
        * function create_footer
        * this is creating the footer for our non e-template approach
        */
        public function create_footer ()
        {
        	common::egw_footer();
        }

        /**
        * function testinterface
        * our original , non eTemplate approach
        * Form with two inputfields, which is switched to a greeting form if there is some input in fname or sname
        * two links at the bottom of the form to switch to the eTemplate Version of the application, or to
        * reload the form, via href/link.
        */
        function testinterface ()
        {
            $this->create_header();
            if (trim($_POST['fname'].$_POST['sname'])!='')
            {
                //echo ''.$_SERVER['PHP_SELF'].'<br>';
                echo "<br>Hello ".$_POST['fname']." ".$_POST['sname']."<br>";
                echo "<form action='".$GLOBALS['egw']->link('/index.php',array(
                'menuaction' => 'test.test_ui.testinterface','message'=>'YES'))."' method='post'>
                <input type='submit' value=' Reload '>
                </form>";
            }
            else
            {
                echo "Type a name to be greeted accordingly <br>";
                echo "<form action='".$GLOBALS['egw']->link('/index.php',array(
                'menuaction' => 'test.test_ui.testinterface','message'=>'NO'))."' method='post'>
                  <p>first name:<br><input name='fname' type='text' size='30' maxlength='30'></p>
                  <p>name:<br><input name='sname' type='text' size='30' maxlength='40'></p>
                        <input type='submit' value=' Submit '>
                        <input type='reset' value=' Cancel'>
                </form>";
            }
            echo "<br><a href='".$GLOBALS['egw']->link('/index.php',array('menuaction' => 'test.test_ui.testinterface','message'=>'YES'))."'> Test Application </a><br>";
            echo "<a href='".$GLOBALS['egw']->link('/index.php',array('menuaction' => 'test.test_ui.index'))."'> Call the eTemplate version  </a> <br>";
            $this->create_footer();
        }
        /**
        * function call index
        * the eTemplate version of the application. basically the same 
        * a form with two  input-fields an additional selectbox and a checkbox to enable content-debugging within a predefined area of the 
        * eTemplate
        * The function handles the behavior of the eTemplate in accordance to the content of the content array
        * If the data-handling part is completed, the eTemplate is read and executed with content and select-option arrays.
        */
        function index($content=null)
        {
            if ($content['clear'])
            {
                //$content=array();
                $content['debug']=0;
                $content['who']='';
                $content['test_name']='';
                $content['test_firstname']='';
            }
            $debug=$content['debug'];
            $sel_options = array(
                'test_property' => $this->types
            	);

            if (is_array($content) && !$content['clear']){
                // after submit
                $content['debug']=$debug;
                $content['message']=print_r($sel_options,true).print_r($content,true);
                $content['datetime']=time();
                if (trim($content['test_firstname'].$content['test_name'])!='')
                {
                    $content['who']=$content['test_firstname']." ".$content['test_name'] ;
                }
                $content['test_name']='';
                $content['test_firstname']='';
            } else {
                // first call
                /*
                $content=array(
                    'who'=>', please type a name ...',
                	);
                */
            }
            //$tmpl=new etemplate('test.index'); //this is discarded since we do that while constructing the class
            $this->tmpl->read('test.index');
            $this->tmpl->set_cell_attribute('debuginfo','disabled',!$debug);
            $this->tmpl->exec('test.test_ui.index',$content,$sel_options);
            // the debug info will be displayed at the very end of the page
            //_debug_array($content);
        }
    }




You have seen the result at the beginning of the chapter. I was - kind of - pleased with the result. But I wanted more. I thought that a person, that types in a name, should be able to store that in the database. Not a sophisticated approach, but nice and simple enough to meet the needs of a beginner, who wants to test at least some database functionality.

So I called DB-Tools.
If you call DB-Tools, first thing you do, is
  • select an application.
  • Since I did not have any table associated to my application, I wanted to add one.
    • So I typed in a name for my new table egw_test - seemed to be a good idea at that time.
    • Clicked on add table
  • next thing for a propper table is columns
    • so I clicked on add column
    • I wanted an id column, so I named it test_id, choosed auto as type, checked NOT NULL and primary key
    • more columns are needed for name, first-name and the property
      • so I clicked on add column
      • name-> I named it test_name, type varchar, precision 40
      • then I clicked on add column
      • firstname-> I named it test_firstname, type varchar, precision 40
      • and I clicked on add column
      • property-> I named it test_property, type varchar, precision 10
    • being pleased, I clicked on write table

After that, I checked with the database, for my new table. It was not there.
Why?
  • DB-Tools writes php-files, with the definition of a database table, not the database table itself.
  • a file test/setup/tables_current.inc.php was created
  • a line was added to my test/setup/setup.inc.php
So what is needed to get my table into the eGroupware? You guess correctly:
  • log out
  • log in into the Setup/Config Admin Login (at egroupware/setup)
  • manage application
  • uninstall test - application,
    • since the setup manager does not know how to transform from no table to a table this step is needed
    • it will do no harm to our application, so proceed
  • install our test - application
  • return to user-login
  • log in as a user with admin-rights
  • apply sufficient rights to a group or user, in order to assure that you can use the application test
After completing all this, I checked with the database, and found my egw_test table.

Go back in time to the first day, to the second day,
to the third day or advance to the fourth day
Back to Code Corner
You are here