Source for file DBKeySelect.class.php
Documentation is available at DBKeySelect.class.php
* For including this file you have to define the constant "CLASSPATH".
* Because every include in the framework depends on the CLASSPATH definition.
* The CLASSPATH means the relative path to the folder that contains the
echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
require_once( CLASSPATH. "forms/items/HTMLSelect.class.php" );
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (C) 2005 Daniel Plücken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library 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 Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* @var array $label_fields
* @param string $name The name-attribute this select
* @param string $selectedValue The preselected value this select
* @param object|array$dbt Naturally you have to give the
* reference of an object of a
* database table or database view,
* how they can be found in package
* databases, as parameter $dbt.
* You can also give the parameter dbt
* If you use $dbt by array-syntax,
* you have to put the handle of the
* database connection at index zero,
* the source databasetable at index
* one and the database type
* ( e. g. "mysql" ) at index two.
* @param string|array$label_fields You can give one fieldname of the
* databasetable by string type or you
* can give more fieldnames as an
* array that contains them by string
* type. This fieldnames builds the
* labels of the option-tags they will
* be separated by a space.
* @param string $key_field This fieldname should be in best
* case a primary key to identify the
* @param string $where The where-clause of the db-query.
* @param string $onChangeOrder A javascript that should execute
* after changing a value of this
* @param string $preselect_field The dataset in which this field has
* the value of the parameter
* $preselected_value will be
* preselect if the parameter
* selectedValue is empty.
* @param string $preselected_value The value that the field, given
* $preselect_field, has to have to be
* preselect. The default value is 1.
is_a( $dbt, "ABSTDatabaseTable" )
|| is_a( $dbt, "ABSTView" )
!empty( $preselect_field )
&& empty( $selectedValue )
array( $preselect_field )
$res_arr = $dbt->getDatasetsWithFields(
for ( $i = 0; $i < count( $res_arr ); $i++ )
foreach ( $res_arr[$i] as $str_fieldidx => $str_fieldval )
$tmp .= ( empty( $tmp ) ? "" : " " ). $str_fieldval;
$valueArr[] = $res_arr[$i][0];
$tmp_matches_arr = array();
$str_operator = $tmp_matches_arr[1];
$str_value = $tmp_matches_arr[2];
!empty( $preselect_field )
&& !in_array( $selectedValue, $valueArr )
$res_arr[$i][ count( $label_fields ) + 1 ] == $preselected_value
|| preg_match( "/^(?:<=|<|>|>=|==|===|!=|!==)$/", $str_operator )
$res_arr[$i][ count( $label_fields ) + 1 ]. " "
. $str_operator. " ". $preselected_value
$selectedValue = $res_arr[$i][0];
// Use this item in conventional php kind.
$sql = "SELECT ". implode( ", ", $tmp_arr ). " "
$tmp .= ( $k == 0 ? "" : " " )
echo "<b>The given parameter is not a valid reference to a "
. "databasetable!</b>\r\n";
echo "<b>BACKTRACE DEBUG:</b>\r\n";
* Returns the last stored database query.
* @author Daniel Plücken <daniel@debakel.net>
{ return $this->dbt->getLastQuery(); }
} // end of class DBKeySelect
|