Object Oriented programming in phpGroupWare

Author: Christian Bac christian.bac at int-evry.fr

2. OO hello
2.1 index.php
2.2 class.hello.inc.php
2.3 setup
3. Simple hooking
4. Managing preferences
4.1 Templates modifications
4.2 New Hello class
4.2.1 Setting the face and size
4.2.2 Storing and retrieving the selected face and size
4.2.3 Allowing the user to choose
4.2.4 Preference.tpl file
4.2.5 Enabling the preferences method
4.3 Create the hook
5. Database and admin interface
5.1 Design and create the tables
5.2 Modify the preferences function
5.3 Create a function to add values in the table
5.4 And a function to call through the admin interface
5.5 Hook to the administrator interface
6. Separate the user interface from the back office
6.1 Sql Object class: class.hello_so.inc.php
6.2 Back Office class: class.hello_bo.inc.php
6.3 User Interface class: class.hello_ui.inc.php

2. OO Hello

This step creates a hello application directly from the simple hello example. It will group the functionnalities comming from the functions.inc.php file and index.php in a filed called inc/class.hello.inc.php.
The file tree will look like this.

|--oohello
|--inc
|  |--class.hello.inc.php
|--setup
|  |--setup.inc.php
|  |--phpgw_??.lang
|--templates
|  |--default
|  |  |--hello_form.tpl
|  |  |--hello_result.tpl
|--index.php
One of the main ideas in phpgroupware OO applications, is that the application may be called by phpgroupware index.php. When index.php is invoked with an argument named menuaction that has a value structured like: applicationName.className.methodName.
Where :
applicationName
is the name of the phpgroupware application,
className
is the name of the class that handles the functions for that application,
and methodName
is the name of the method you want to call.

In our example :

2.1 index.php

The new index.php, is used to call the object with its default function, in our case, say_hello().
So the new code for index.php is:
<?php
  $GLOBALS['phpgw_info']['flags'] = array(
     'currentapp' => 'oohello',
     'noheader'   => True,
     'nonavbar'   => True
   );
include('../header.inc.php');
$obj = CreateObject('oohello.hello');
$obj->say_hello();
$GLOBALS['phpgw']->common->phpgw_footer();
?>
Note that index.php creates the object and calls the say-hello() method.

2.2 class.hello.inc.php

The class contains a constructor and the say_hello() function that uses the templates to display the results.
As for the index.php file in the hello application, the say_hello() function is called either by a GET method from the index.php file or a POST method by itself.
To allow the function call by the index.php from phpgroupware, an array named public_functions must be initialised with the name of the functions and a boolean with the true value if the function is callable.
To share data in the object, we use attributes like the t attributes that refers to the template.
The major changes is the link that corresponds to the hello_action.
This link is initialised with /index.php and a menuaction argument.
<?php
class hello
{  
  var $t;     //template
  var $input='World'; 
  var $public_functions = array('say_hello'  => True); //callable functions
  // constructor
  function hello()
  {
    $this->t =& $GLOBALS['phpgw']->template;
    return True;
  }
  
  function say_hello()
  {
  // phpgroupware header and navigation bar 
    $GLOBALS['phpgw']->common->phpgw_header();
    echo parse_navbar();
    if(count($_POST)){ // if called by POST
      $this->input=get_var('input',array('POST'));
    }
  //Compute hello()
    $result = lang('hello').' '.$this->input.' !';
    //we will use two templates
    $this->t->set_file(array(
	       'result' => 'hello_result.tpl',
	       'form' => 'hello_form.tpl'
	       )
	 );
    //filling the first template
    $this->t->set_var('hello_input',htmlspecialchars($this->input));
    $this->t->set_var('hello_result',htmlspecialchars($result));

    //filling the second template
    $this->t->set_var('hello_action',$GLOBALS['phpgw']->link('/index.php','menuaction=oohello.hello.say_hello'));
    $this->t->set_var('hello_value',htmlspecialchars($this->input));
    $this->t->pparse('out','result');
    $this->t->pparse('out','form');
    return True;
  }
}
?>

2.3 setup

You have to modify the content of setup.inc.php by replacing the name of the application (hello) by oohello.
<?php
	$setup_info['oohello']['name']  = 'oohello';
	$setup_info['oohello']['title'] = 'Oohello';
	$setup_info['oohello']['version']  = '0.9.16';
	$setup_info['oohello']['app_order'] = 7;
	$setup_info['oohello']['tables']    = array();
	$setup_info['oohello']['enable']    = 1;
	$setup_info['oohello']['globals_checked']   = True;
	/* Dependancies for this app to work */
	$setup_info['oohello']['depends']= array(
           array('appname'  => 'phpgwapi', 'versions' => Array('0.9.16')),
	   array('appname'  => 'admin', 'versions' => Array('0.9.16')),
	   array('appname'  => 'preferences','versions' => Array(0.9.16')	
	   );
?>

3. Simple Hooking

Phpgroupware allows you to prepare hooks for your application.
Classical hooks relate to :
  1. information about the module,
  2. preferences for the module,
  3. administration of the module.

Hook files are located in inc directory and they must be referenced in setup.inc.php.

|-- oohello
    |--inc
    |  |--hook_about.inc.php
The hook_about.inc.php should contain something like this:
<?php
  function about_app($tpl,$handle)
  {
    $s = '<b>' . lang('hello') . '</b><p>' 
       .lang('written by:') . '&nbsp;Christian Bac<br>';
    return $s;
  }
?>
You also have to add the information into setup.inc.php saying that there is a hook for that application.
$setup_info['oohello']['hooks'][] = 'about';

4. Preferences

We will use the preference to select the application font size and the application font type. Preferences needs a more complex hook. For that we need:
  1. to modify the templates to add support for font_size and font_face;
  2. to modify the class.hello.inc.php
    1. to add support for font_size and font_face,
    2. and to insert a new function in class.hello.inc.php;
  3. to create the hook_preferences.inc.php and modify the setup.inc.php like in our previous step.

For this we create a phpgroupware module called oostep3. The directory tree of this module will look like the following:
|--oostep4
|  |--inc
|  |  |--class.hello.inc.php
|  |  |--hook_about.inc.php
|  |  |--hook_preferences.inc.php
|  |--setup
|  |  |--setup.inc.php
|  |  |--phpgw_??.lang
|  |--templates
|  |  |--default
|  |  |  |--hello_form.tpl
|  |  |  |--hello_result.tpl
|  |  |  |--preferences.tpl
|  |--index.php
You have to initialize the content of oostep3 hierarchy with files from oohello.

You also have to modify te content of setup.inc.php to modify the name of the module (replace oohello by oostep3).

4.1 Modification of the templates

The two templates are modified to add a font definition corresponding to font_size and font_face.
For example, hello_form.tpl becomes:
<font face="{font_face}" size="{font_size}">
<p>Type Here your text to hello()</p>
<form method="POST" action="{hello_action}">
<input type="text" name="input" value= "{hello_value}" >
<input type="submit" value="OK">
</form>
</font>
Hello_result.tpl must be modified accordingly.

4.2 Modifications in the hello class

Hello class should be modified in 4 different points:
  1. to set the font_face and font_size;
  2. to store and retrieve informations about the selected font face and size;
  3. to modify the user choice about font face and size;
  4. to allow been called by the preference page.

4.2.1 Setting the face and size

The face and size will be stored in an array called prefs and they will be used to initialise the values in the template by a function that we call setdef().

class hello
{
  var $t;  //template
  var $prefs; //programm preferences
...
  function setdef()
  {
    $this->t->set_var('font_face',$this->prefs['font_type']);
    $this->t->set_var('font_size',$this->prefs['font_size']);
    $this->t->set_var('lang_submit',lang('submit')); 
  }
...

4.2.2 Storing and retrieving the selected face and size

We also need to read and save the preferences. For that we will use phpgroupware preferences class.
The preferences are associated to the application name.

class hello
{
...
   function read_preferences()
   {
     $GLOBALS['phpgw']->preferences->read_repository();
     if($GLOBALS['phpgw_info']['user']['preferences']['oohello'])
       {
       $this->prefs['font_type'] =$GLOBALS['phpgw_info']['user']['preferences']['oohello']['font_type'];
       $this->prefs['font_size'] =$GLOBALS['phpgw_info']['user']['preferences']['oohello']['font_size'];
       }
     else
       {
       prefs=NULL;
       }
   }
   function save_preferences()
   {
     $GLOBALS['phpgw']->preferences->read_repository();
     if ($this->prefs)
      {
        $GLOBALS['phpgw']->preferences->change('oohello','font_type',$this->prefs['font_type']);
        $GLOBALS['phpgw']->preferences->change('oohello','font_size',$this->prefs['font_size']);
        $GLOBALS['phpgw']->preferences->save_repository(True);
      }
   }
...

4.2.3 Allowing the user to choose

This will be done in a function called preferences. This function will be called with a get method from the preference page and with a post method by itself.

 
...
  function preferences()
  {
    $submit = get_var('submit',array('POST'));
    $prefs  = get_var('prefs',array('POST'));
    if($submit)
      {
        $this->prefs=$prefs;
        $this->save_preferences();
        Header('Location: ' . $GLOBALS['phpgw']->link('/preferences/index.php'));
        $GLOBALS['phpgw']->common->phpgw_exit(); 
       }
    $GLOBALS['phpgw']->common->phpgw_header();
    echo parse_navbar(); 
    $this->t->set_file(array('preferences' =>'preferences.tpl'));
    $this->setdef(); 
    $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=oohello.hello.preferences')); 
    $this->t->set_var('lang_action',lang('preferences')); 
    $this->t->set_var('lang_select_font',lang('choose a font')); 
    $this->t->set_var('lang_select_size',lang('choose the font size'));
    $font_type_array=array( 
        'arial'=>'Arial,Helvetica,sans-serif', 
        'times' =>'Times New Roman,Times,serif',
        'verdana' => 'Verdana,Arial,Helvetica,sans-serif',
        'georgia' => 'Georgia,Times New Roman,Times,serif',
        'courier' => 'Courier New,Courier,mono',
        'tahoma' => 'Tahoma,Verdana,Arial,Helvetica,sans-serif'
       );
    $type_options ='';
    foreach($font_type_array as $alias => $font_name){ 
      $type_options .= '<option value="'.$font_name.'"';
      if($this->prefs['font_type']==$font_name){ 
        $type_options .= 'selected'; 
      } 
      $type_options .= '>' . lang($alias) .'</option>' . "\n";
    }
    $this->t->set_var('type_options',$type_options);
    $font_size_array=array( 
       1 => 'very small', 2=> 'small', 3 => 'medium',
       4 => 'large', 5 => 'very large'); 
    $size_options ='';
    foreach($font_size_array as $key => $size){ 
       $size_options .= '<option value="'.$key.'"'; 
       if($this->prefs['font_size']==$key){ 
         $size_options .= ' selected'; 
       }
       $size_options .= '>'.lang($size).'</option>\n';
    }
    $this->t->set_var('size_options',$size_options);
    $this->t->pfp('out','preferences'); 
  }
}
?> 

4.2.4 Preference.tpl file

<font face="{font_face}" size="{font_size}">
<center>
  <form method="POST" name="prefs_form" action="{actionurl}">
    <table width="70%" border="0" cellspacing="2" cellpadding="2">
     <tr>
      <td colspan="2" bgcolor="#c0c0c0" align="center"><b>{lang_action}</b></td>
     </tr>
     <tr>
       <td align="right">{lang_select_font}:</td>
       <td><select name="prefs[font_type]">{type_options}</select></font></td>
     </tr>
     <tr>
       <td align="right">{lang_select_size}:</td>
       <td><select name="prefs[font_size]">{size_options}</select></td>
     </tr>
     <tr valign="bottom">
       <td height="50"><input type="submit" name="submit" value="{lang_submit}">
     <td> </td>
     </tr>
    </table>
  </form></td>
</center>
</font>

4.2.5 Enabling the preferences method

You have to modify the public_functions array to enable the preferences method to be called.

  
  var $public_functions = array(
      'say_hello'  => True,
      'preferences' => True
      );

4.3 Create the hook

The file is called hook_preferences.inc.php in the inc directory.
<?php
  // Only Modify the $file and $title variables.....
  $title = $appname;
  $file = Array('Preferences' => $GLOBALS['phpgw']->link('/index.php','menuaction=oohello.hello.preferences'));
  //Do not modify below this line
  display_section($appname,$title,$file);
?>

5. Storing the font faces and size in the database

To store and retrieve this informations from the database, we must:
  1. design and create the tables;
  2. modify the preferences to access this table;
  3. create a function to add/remove entries in the tables;
  4. link this function to the admin interface.
To do this we will create a new phpgroupware module called oostep5, in which we will copy the files from the previous step.
|--oostep5
|  |--inc
|  |  |--class.hello.inc.php
|  |  |--hook_about.inc.php
|  |  |--hook_preferences.inc.php
|  |  |--hook_admin.inc.php
|  |--setup
|  |  |--setup.inc.php
|  |  |--tables_current.inc.php
|  |  |--phpgw_??.lang
|  |--templates
|  |  |--default
|  |  |  |--hello_form.tpl
|  |  |  |--hello_result.tpl
|  |  |  |--preferences.tpl
|  |--index.php

5.1 Design and create the tables

We need to create one table to describe the font faces and size.
The table contains 3 fields:
the type
can be a face or a size
the keyword
this keyword will be used to find the entry, for example small or times,
and the string value
this value is the complete name of the font
.
To describes the table, we create a file under setup that is called, tables_current.inc.php.

<?php
  $phpgw_baseline = array(
  	'phpgw_hellooptions' => array(
	    'fd' => array(
	    	    'hello_id' => array('type' => 'auto', 'nullable' => False),
		    'hello_type' => array('type' => 'varchar', 'precision'=>10),
		    'hello_key' => array('type' => 'varchar', 'precision' =>20),
		    'hello_value' => array('type' => 'varchar','precision' =>100)
		    ),
	    'pk' => array('hello_id'),
	    'fk' => array(),
	    'ix' => array(),
            'uc' => array('hello_type','hello_key')
	)
  );
?>
This table is read when you install the application.

5.2 Modify the preferences function

We have to modify the content of the preferences function to generate the select choices with the values comming from the database.
You also need to modify the public_functions in class.hello.inc.php and to initialize an attribute called db with $GLOBALS['phpgw']->db in the class constructor.

    $face_query='select * from phpgw_hellooptions where hello_type ='."'".'face'."';";
    $type_options ='';
    $this->db->query($face_query);
    while($this->db->next_record()){
      $type_options .= '<option value="'.$this->db->f('hello_value').'"';
      if($this->prefs['font_type']==$this->db->f('hello_value')){
	$type_options .= 'selected';
      }
      $type_options .= '>' . lang($this->db->f('hello_key')). '</option>' . "\n";
    }
    $this->t->set_var('type_options',$type_options);


    $size_query='select * from phpgw_hellooptions where hello_type ='."'".'size'."';";
    $size_options ='';
    $this->db->query($size_query);
    while($this->db->next_record()){
      $size_options .= '<option value="'.$this->db->f('hello_value').'"';
      if($this->prefs['font_size']==$this->db->f('hello_value')){
	$size_options .= 'selected';
      }
      $size_options .= '>' . lang($this->db->f('hello_key')). '</option>' . "\n";
    }

5.3 Create a function to add values in the table

  
function add_choice($type,$key,$value)
{
    if($type && $key && $value)
      {
      $face_query='select * from phpgw_hellooptions where hello_type ='."'".$type
      ."' And hello_key ='".$key. "';";
      $this->db->query($face_query);
      if($this->db->next_record())
        {	//looks like the record exist replace values
        }
      else
        {//insert new record
	$insert_query='insert into phpgw_hellooptions (hello_type, hello_key, hello_value) values ('
	  ."'".$type."','".$key. "','".$value."');";
	$this->db->query($insert_query);
      }
    }  
}

5.4 And a function to call through the admin interface

  
function admin(){
    $submit = get_var('submit',array('POST'));
    if ($submit)
      {
	$this->add_choice(get_var('type', array('POST')),
			  get_var('key',array('POST')),
			  get_var('value',array('POST')));
	Header('Location: ' . $GLOBALS['phpgw']->link('/admin/index.php'));
	$GLOBALS['phpgw']->common->phpgw_exit();
      }
    $GLOBALS['phpgw']->common->phpgw_header();
    echo parse_navbar();
    $this->t->set_file(array('hello_add' => 'add.tpl',
		     //			     'hello_del' => 'dell.tpl'
		     )
		     );
    $this->setdef();
    $type_choice='<option value="face" selected>face</option>'
      .'<option value="size">size</option>';
    $this->t->set_var('type_options',$type_choice);
    $this->t->set_var('lang_add_font_choice',lang('add a font choice'));
    $this->t->set_var('lang_key',lang('key'));
    $this->t->set_var('lang_value',lang('value'));
    $this->t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=oostep5.hello.admin'));
    $this->t->pparse('out','hello_add');
  }

5.5 Hook to the administrator interface

<?php
  $file['Site Configuration'] = 
    $GLOBALS['phpgw']->link('/index.php',
        array('menuaction' => 'oostep5.hello.admin'));
        display_section('oostep5',$file);
?>

6. Separate the user interface from the back office

In our hello class, we have mixed instructions that take care of the user interface, like computing the layout of a page with the templates. In this step we will separate the different parts by creating three class files:
The file tree will look like this.
|--oostep6
|  |--inc
|  |  |--class.hello_ui.inc.php
|  |  |--class.hello_bo.inc.php
|  |  |--class.hello_so.inc.php
|  |  |--hook_about.inc.php
|  |  |--hook_preferences.inc.php
|  |  |--hook_admin.inc.php
|  |--setup
|  |  |--setup.inc.php
|  |  |--tables_current.inc.php
|  |  |--phpgw_??.lang
|  |--templates
|  |  |--default
|  |  |  |--hello_form.tpl
|  |  |  |--hello_result.tpl
|  |  |  |--preferences.tpl
|  |--index.php
To do this we select the functions from hello class and decide if they can be put directly in one of the three new objects.

6.1 Sql Object class: class.hello_so.inc.php

To start from the simplest to the most complex class, we begin with the hello_so class.
This class contains calls to the sql database. Its functions are not calleable directly from the menuaction. They will be called by the bo class.
The add_choice function for example is a function that only manipulates the database, it has to be in the so class. We have decided to reference the table name in an attribute called option_table, to simplify the code to modify if we make different releases of this code.
The so object is used to retrieve the list of the available font faces and sizes and to add a choice in the table.

<?php
class hello_so
{
  var $db;  //phpgw db
  var $option_table;
  function hello_so()
  {
    $this->db=$GLOBALS['phpgw']->db;
    $this->option_table='phpgw_helloopts5';
    return True;
  }

  function get_faces_list(){
    $face_list=array();
    $face_query='select * from'.$this->option_table.' where hello_type =\'face\';';
    $this->db->query($face_query);
    while($this->db->next_record()){
      $value=$this->db->f('hello_value');
      $key=$this->db->f('hello_key');
      $face_list[$key]=$value;
    }
    return $face_list;  
  }
  
  function get_sizes_list(){
    $size_list=array();
    $size_query='select * from
'.$this->option_table.' where hello_type =\'size\';';
    $this->db->query($size_query);
    while($this->db->next_record()){
      $value=$this->db->f('hello_value');
      $key=$this->db->f('hello_key');
      $size_list[$key]=$value;
    }
    return $size_list;  
  }

  function add_choice($type,$key,$value){
    if($type && $key && $value){
      $where=' where hello_type =\''.$type.'\' And hello_key =\''.$key. '\';';
      $select_query='select * from '.$this->option_table.$where;
      $this->db->query($select_query);
      if($this->db->next_record()){
          //looks like the record exist replace values
          $mod_query='update '. $this->option_table.' set hello_value=\''
	  .$value.'\''. $where;
      }else{//insert new record
          $mod_query='insert into '. $this->option_table
	  .' (hello_type, hello_key, hello_value)
	  values (\''.$type.'\',\''.$key. '\',\''.$value.'\');';
      }
      $this->db->query($mod_query);
    }
  }
}
?>

6.2 Back Office class: class.hello_bo.inc.php

The bo class is used to manipulate the phpgroupware API appart from the user interface and to relay calls to the so object from the ui.
In our case, the hello_bo class, defines the functions to set and define the preferences. It stores the preferences in an attributes, that is initialised from the phpgroupware preferences for this application. The set_prefs also save the preferences to the phpgw framework.
The three functions add_choice, get_faces_list and get_sizes_list are just pass through function that call the so object.
<?php

class hello_bo
{
  var $so;    //link to so object
  var $prefs; //programm preferences

  function hello_bo()
  {
    $this->so=CreateObject('oostep6.hello_so');
    $this->read_preferences();
    return True;
  }

  function get_prefs()
  {
    return $this->prefs;
  }
  function set_prefs($prefs)
  {
    $this->prefs=$prefs;
    $this->save_preferences();
  }
  function read_preferences()
  {
  $GLOBALS['phpgw']->preferences->read_repository();
    if($GLOBALS['phpgw_info']['user']['preferences']['oostep6'])
      {
      $this->prefs['font_type'] = $GLOBALS['phpgw_info']['user']['preferences']['oostep6']['font_type'];
      $this->prefs['font_size'] = $GLOBALS['phpgw_info']['user']['preferences']['oostep6']['font_size'];
      }
    else
      {
      $this->prefs=NULL;
      }
  }

  function save_preferences()
  {
   $GLOBALS['phpgw']->preferences->read_repository();
   if ($this->prefs)
      {
       $GLOBALS['phpgw']->preferences->change('oostep6','font_type',$this->prefs['font_type']);
       $GLOBALS['phpgw']->preferences->change('oostep6','font_size',$this->prefs['font_size']);
       $GLOBALS['phpgw']->preferences->save_repository(True);
      }
  }
  function add_choice($type,$key,$value){
    $this->so->add_choice($type,$key,$value);
  }
  function get_faces_list(){
    return $this->so->get_faces_list();
  }

  function get_sizes_list(){
    return $this->so->get_sizes_list();
  }
}
?>

6.3 User Interface class: class.hello_ui.inc.php


The ui class is in charge of the templates manipulation and the call from the phpgroupware framework.

<?php

class hello_ui
{
  var $bo;    //back office object
  var $t;     //template
  var $input='World';
  var $public_functions = array
  (
   'say_hello'  => True,
   'preferences' => True,
   'admin' => True
   );
  
  function hello_ui()
  {
    $this->bo= CreateObject('oostep6.hello_bo');
    $this->t = $GLOBALS['phpgw']->tempate;
    return True;
  }

  function say_hello()
  {
    $GLOBALS['phpgw']->common->phpgw_header();
    echo parse_navbar();
    if(count($_POST)){
     $this->input=get_var('input',array('POST'));
    }
  //Compute hello()
    $result = lang('hello').' '.$this->input.' !';
   
    //we will use two templates
    $this->t->set_file(array( 
            'result' => 'hello_result.tpl',
            'form' => 'hello_form.tpl'
            )
         );
    $this->setdef();
    //filling the first template
    $this->t->set_var('hello_input',htmlspecialchars($this->input));
    $this->t->set_var('hello_result',htmlspecialchars($result));  
   
    //filling the second template
    $this->t->set_var('hello_action',$GLOBALS['phpgw']->link('/index.php','menuaction=oostep6.hello_ui.say_hello'));
   
$this->t->set_var('hello_value',htmlspecialchars($this->input));
   
    //parse and write out the templates
    $this->t->pparse('out','result');
    $this->t->pparse('out','form');
    return True;
  }
  function setdef(){
    $prefs=$this->bo->get_prefs();
    $this->t->set_var('font_face',$prefs['font_type']);
    $this->t->set_var('font_size',$prefs['font_size']);
    $this->t->set_var('lang_submit',lang('submit'));   
  }
  function preferences()
  {
    if (count($_POST))
      {
    $prefs = get_var('prefs',array('POST'));
    $this->bo->set_prefs($prefs);
    Header('Location: ' .$GLOBALS['phpgw']->link('/preferences/index.php'));
    $GLOBALS['phpgw']->common->phpgw_exit();
      }

    $GLOBALS['phpgw']->common->phpgw_header();
    echo parse_navbar();

    $this->t->set_file(array('preferences' =>'preferences.tpl'));
    $this->setdef();
   
$this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=oostep6.hello_ui.preferences'));
   
$this->t->set_var('lang_action',lang('preferences'));
   
$this->t->set_var('lang_select_font',lang('choose a font'));
   
$this->t->set_var('lang_select_size',lang('choose the font size'));
    $prefs=$this->bo->get_prefs();
    $face_list=$this->bo->get_faces_list();
    $type_options ='';
    foreach($face_list as $key => $value){
      $type_options .= '<option value="'.$value.'"';
      if($prefs['font_type']==$value){
          $type_options .= 'selected';
      }
      $type_options .= '>' . lang($key).'</option>' . "\n";
    }
    $this->t->set_var('type_options',$type_options);

    $size_list=$this->bo->get_sizes_list();
    $size_options ='';
    foreach($size_list as $key => $value){
      $size_options .= '<option value="'.$value.'"';
      if($prefs['font_size']==$value){
        $size_options .= 'selected';
      }
      $size_options .= '>' . lang($key).'</option>' . "\n";
    }
    $this->t->set_var('size_options',$size_options);
    $this->t->pfp('out','preferences');
  }

  function admin(){
    $submit = get_var('submit',array('POST'));
    if ($submit)
      {
      $this->bo->add_choice(get_var('type',array('POST')),
      get_var('key',array('POST')),
      get_var('value',array('POST')));
      Header('Location: ' .
      $GLOBALS['phpgw']->link('/admin/index.php'));
    $GLOBALS['phpgw']->common->phpgw_exit();
     }

    $GLOBALS['phpgw']->common->phpgw_header();
    echo parse_navbar();
    $this->t->set_file(array('hello_add' =>'add.tpl',
           //   'hello_del' => 'dell.tpl'
     ));
    $this->setdef();
    $type_choice='<option value="face" selected>face</option>'
      .'<option value="size">size</option>';
    $this->t->set_var('type_options',$type_choice);
   $this->t->set_var('lang_add_font_choice',
   lang('add a font choice'));
    $this->t->set_var('lang_key',lang('key'));
    $this->t->set_var('lang_value',lang('value'));
   
   $this->t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=oostep6.hello_ui.admin'));
    $this->t->pparse('out','hello_add');
  }
}
?>


PREV UP