DIR : /home/kozerus/public_html/dgs/dgs/code_examples/form_example2.php

/home/kozerus/public_html/dgs/dgs/code_examples

<?php
/*
Dragon Go Server
Copyright (C) 2001-  Erik Ouchterlony, Rod Ival, Jens-Uwe Gaspar

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * Code example using area-layout of Form-class.
 *
 * Usage: open its URL in browser
 */

chdir("../");
require_once 'include/std_functions.php';
require_once 'include/form_functions.php';
chdir("code_examples/");

/* init vars */

$arr_layouts = array(
   array( 'layout' => 'Standard' ),
   array( 'layout' => '1,2,3,4,5' ),
   array( 'layout' => '1|2|3|4|5' ),
   array( 'layout' => '1,2,(3),4,5' ),
   array( 'layout' => '1|2|(3)|4|5' ),
   array( 'layout' => '1,2,(((3))),4,5' ),
   array( 'layout' => '1,2|3|4,5' ),
   array( 'layout' => '1|2,3,4|5' ),
   array( 'layout' => '1,(2|3|4),5' ),
   array( 'layout' => '1|(2,3,4)|5' ),
   array( 'layout' => '1,2|(3,4)|5' ),
   array( 'layout' => '1|(2,(3)|(4,5))' ),
   array( 'layout' => '5,4,3,2|1' ),
   array( 'layout' => '4|5,3|5,2|5,1|5' ),
   array( 'layout' => '(4,5)|(3,5)|(2,5)|(1,5)' ),
);
$form_layouts = array(); # for action-form
foreach ( $arr_layouts as $idx => $arr )
   $form_layouts[$idx] = $arr['layout'] . "  ";

$col1 = 'grey';
$col2 = 'green';
$col3 = 'blue';
$col4 = 'red';
$col5 = 'magenta';
function ff( $col, $msg ) {
   return "<font color=\"$col\">$msg</font>";
}

$layout = (int)get_request_arg('layout', '1');
if ( !isset($arr_layouts[$layout]) )
   $layout = 1;
$align = (int)@$_REQUEST['align'];
$center = (bool)@$_REQUEST['center'];
if ( $center ) $align= 0;
$border = (bool)@$_REQUEST['border'];
$title = (bool)@$_REQUEST['title'];



/* define local style */

$page_style ='
table.FormClass {border-color: red;}
td.FormClassV,
table.FormClassV {border-color: blue;}
td.FormClassH,
table.FormClassH {border-color: orange;}
td.FormClassC,
table.FormClassC {border-color: green;}

table.FormClass,
table.FormClassV,
table.FormClassH,
table.FormClassC {border-style: dashed; border-width: 1px;
 border-spacing: 4px; border-collapse: separate;}

td.FormClassV,
td.FormClassH,
td.FormClassC {border-style: solid; border-width: 1px;
 padding: 8px; margin: 0px; vertical-align: top;}

td.FormClassC {padding: 6px 30px;}

td.FormClassC span.Rubric {font-weight: bold;}

#tblWarn1 {background: #c0ffc0;}
table.TblWarn2 {background: #c0c0ff;}
';
if ( !$border )
   $page_style.='
table.FormClass,
table.FormClassV,
table.FormClassH,
table.FormClassC {border-width: 0px;
 border-spacing: 0px; border-collapse: collapse;}
td.FormClassV,
td.FormClassH,
td.FormClassC {border-width: 0px;}
';
if ( $align > 0 )
{ //right align
   $page_style.='
table.FormClass,
table.FormClassV,
table.FormClassH,
table.FormClassC {margin: 0px 0px 0px auto;}

td.FormClassV,
td.FormClassH,
td.FormClassC {text-align: right;}
';
}
else if ( $align < 0 )
{ //left align
   $page_style.='
table.FormClass,
table.FormClassV,
table.FormClassH,
table.FormClassC {margin: 0px auto 0px 0px;}

td.FormClassV,
td.FormClassH,
td.FormClassC {text-align: left;}
';
}
else
{ //center align
   $page_style.='
table.FormClass,
table.FormClassV,
table.FormClassH,
table.FormClassC {margin: 0px auto 0px auto;}

td.FormClassV,
td.FormClassH,
td.FormClassC {text-align: center;}
';
}

loc_start_html( $page_style);



/* control-form to select layout for area-layouted form */

# select layout
$actform = new Form( "myname", "form_example2.php", FORM_POST );
$actform->add_row( array(
      'DESCRIPTION',  'Layout',
      'SELECTBOX',    'layout', 1, $form_layouts, $layout, false,
      'SUBMITBUTTON', 'action', 'Choose Layout',
      'RADIOBUTTONS', 'align', array(-1=>'left', 0=>'center', 1=>'right'), (int)$align,
      'CHECKBOX',     'border', '1', 'table-borders', (bool)$border,
      'CHECKBOX',     'title', '1', 'table-titles', (bool)$title,
      ));
$actform->echo_string();



/* build area-layouted form */

$the_form = new Form( "myname", "form_example2.php", FORM_POST );

// set layout
if ( $layout )
   $the_form->set_layout( FLAYOUT_GLOBAL, $arr_layouts[$layout]['layout'] );

// set config for layout
/*
$the_form->set_layout( FLAYOUT_AREACONF, FAREA_ALL,
   array(
      FAC_TABLE    => ($border) ? 'border=1' : '',
      FAC_ENVTABLE => ($center) ? 'align=center' : '',
   ) );
*/

// setup form with areas
#$the_form->set_area( 1 );  # default-area is 1
$the_form->add_row( array(
   'TEXT', ff($col1, 'Area 1 - Row 1 - Col 1'),
   'TD',
   'TEXT', ff($col1, 'Area 1 - Row 1 - Col 2'), ) );
$the_form->add_row( array(
   'TEXT', ff($col1, 'Area 1 - Row 2 - Col 1'),
   'TD',
   'TEXT', ff($col1, 'Area 1 - Row 2 - Col 2'), ) );
if ( $title )
$the_form->set_layout( FLAYOUT_AREACONF, 1,
   array(
      'title' => 'Title 1',
   ) );

if ( $layout ) $the_form->set_area( 2 );
$the_form->add_row( array( 'TEXT', ff($col2, 'Area 2 - Row 1') ) );
$the_form->add_row( array( 'TEXT', ff($col2, 'Area 2 - Row 2') ) );
$the_form->add_row( array( 'TEXT', ff($col2, 'Area 2 - Row 3') ) );
$the_form->add_row( array( 'TEXT', ff($col2, 'Area 2 - Row 4') ) );
$the_form->set_layout( FLAYOUT_AREACONF, 2,
   array(
      'title' => ( $title ?'Title 2' :'' ),
      FAC_TABLE => 'id=tblWarn1',
   ) );

if ( $layout ) $the_form->set_area( 3 );
$the_form->add_row( array( 'TEXT', ff($col3, 'Area 3 - Row 1') ) );
$the_form->add_row( array( 'TEXT', ff($col3, 'Area 3 - Row 2') ) );
$the_form->add_row( array( 'TEXT', ff($col3, 'Area 3 - Row 3') ) );
$the_form->set_layout( FLAYOUT_AREACONF, 3,
   array(
      ( $title ?'title' :'dummy' )=> 'Title 3',
      FAC_TABLE => 'class=TblWarn2',
   ) );

if ( $layout ) $the_form->set_area( 4 );
$the_form->add_row( array( 'TEXT', ff($col4, 'Area 4 - Row 1') ) );
$the_form->add_row( array( 'TEXT', ff($col4, 'Area 4 - Row 2') ) );
$the_form->set_layout( FLAYOUT_AREACONF, 4,
   array(
      'title' => ( $title ?'Title 4' :'' ),
      FAC_TABLE => 'bgcolor="#ffc0c0"',
   ) );

if ( $layout ) $the_form->set_area( 5 );
$the_form->add_row( array( 'TEXT', ff($col5, 'Area 5 - Row 1') ) );
$the_form->add_row( array( 'TEXT', ff($col5, 'Area 5 - Row 2') ) );
$the_form->add_row( array( 'TEXT', ff($col5, 'Area 5 - Row 3') ) );
if ( $title )
$the_form->set_layout( FLAYOUT_AREACONF, 5,
   array(
      'title' => 'Title 5',
   ) );

$the_form->echo_string();


// present some internal vars from Form
Form::echo_internal_layout($the_form);

loc_end_html();
exit;

//-----------

function loc_start_html( $style_string='')
{
   $encoding_used = 'utf-8';
   header('Content-Type: text/html;charset='.$encoding_used);

   echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'
         .' "http://www.w3.org/TR/html4/loose.dtd">';

   echo "\n<HTML>\n<HEAD>";

   if ( $style_string )
      echo "\n <STYLE TYPE=\"text/css\">\n" .$style_string . "\n </STYLE>";

   echo "\n</HEAD>\n<BODY>\n";
}

function loc_end_html()
{
   echo "\n</BODY>\n</HTML>";
}

?>
//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer