2
0
mirror of https://github.com/boostorg/website.git synced 2026-01-23 18:12:16 +00:00
Files
website/common/code/webnotes/core/enum_api.php
Rene Rivera 1d41a5cc39 *** empty log message ***
[SVN r49]
2006-01-10 07:16:17 +00:00

68 lines
2.2 KiB
PHP

<?php
# phpWebNotes - a php based note addition system
# Copyright (C) 2000-2002 Webnotes Team - webnotes-devel@sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the files README and LICENSE for details
# --------------------------------------------------------
# $Id$
# --------------------------------------------------------
# --------------------
# Get the string associated with the $p_enum value
function get_enum_to_string( $p_enum_string, $p_num ) {
$t_arr = enum_explode_string( $p_enum_string );
$enum_count = count( $t_arr );
for ($i=0;$i<$enum_count;$i++) {
$t_s = enum_explode_array( $t_arr[$i] );
if ( $t_s[0] == $p_num ) {
return $t_s[1];
}
}
return '@null@';
}
# --------------------
# Breaks up an enum string into num:value elements
function enum_explode_string( $p_enum_string ) {
return explode( ',', $p_enum_string );
}
# --------------------
# Given one num:value pair it will return both in an array
# num will be first (element 0) value second (element 1)
function enum_explode_array( $p_enum_elem ) {
return explode( ':', $p_enum_elem );
}
# --------------------
# Given a enum string and num, return the appropriate string
function enum_get_element( $p_enum_name, $p_val ) {
$config_var = config_get( $p_enum_name.'_enum_string' );
$string_var = lang_get( $p_enum_name.'_enum_string' );
# use the global enum string to search
$t_arr = enum_explode_string( $config_var );
$t_arr_count = count( $t_arr );
for ( $i=0;$i<$t_arr_count;$i++ ) {
$elem_arr = enum_explode_array( $t_arr[$i] );
if ( $elem_arr[0] == $p_val ) {
# now get the appropriate translation
return get_enum_to_string( $string_var, $p_val );
}
}
return '@null@';
}
# --------------------
# Get enum ids (returns an array of all ids in an enumeration)
function enum_get_ids_array( $p_enum_name ) {
$config_var = config_get( $p_enum_name . '_enum_string' );
# use the global enum string to search
$ids = array();
$t_arr = enum_explode_string( $config_var );
for ( $i = 0; $i < count($t_arr); $i++ ) {
$elem_arr = enum_explode_array( $t_arr[$i] );
$ids[] = $elem_arr[0];
}
return $ids;
}
?>