Skip to content

Commit

Permalink
Use the default value instead of null value
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoguidotti committed Jul 8, 2013
1 parent d7c910e commit 67fc662
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
34 changes: 16 additions & 18 deletions library/dbmng/dbmng.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,21 @@ function dbmng_get_form_array($id_table){
{
if($fld->pk == 1)
$aForm['primary_key'] = $fld->field_name;
//if(strpos($fld->field_name, "id_") !== false )
// $aForm['primary_key'] = "id_test";




$aFields[$fld->field_name] = array('label' => $fld->field_label,
'type' => $fld->id_field_type,
'value' => null,
'nullable' => $fld->nullable,
'default' => $fld->default_value,
'field_function' => $fld->field_function);
if(($fld->default_value)!=null){
$aFields[$fld->field_name]['default']=$fld->default_value;
}
}


if(!array_key_exists('primary_key', $aForm)){
$aForm['primary_key']='id_'.$aForm['table_name'];
}
$aForm['fields']=$aFields;
print_r($aFields);

return $aForm;
}

Expand Down Expand Up @@ -206,8 +199,8 @@ function dbmng_create_form($aForm, $aParam)
$html .= "<input name='" . $x . "' ";
$html .= "id='$x' ";

if( isset($x_value['default']) && !isset($_GET["upd_" . $aForm['table_name']]) )
$html .= "value='" . $x_value['default']. "'";
if( !is_null($x_value['default']) && !isset($_GET["upd_" . $aForm['table_name']]) )
$html .= "value='" . $x_value['default']. "' ";
else{
;
}
Expand Down Expand Up @@ -361,23 +354,28 @@ function dbmng_create_form_update($aForm)
}
}

/////////////////////////////////////////////////////////////////////////////
// dbmng_value_prepare
// ======================
/// This function prepare the value from the POST request to insert it in the database
/**
\param $x_value The associative array with the field meta-variables
\param $sValue The value obtained by the request
*/
function dbmng_value_prepare($x_value, $sValue){
$sVal='';
$sType=$x_value['type'];

$df=null;
if(isset($x_value['default'])){
$df=$x_value['default'];
}
//echo($sType.'|'.$sValue.'|'.is_null($x_value['default']).'|<br/>');

echo($sType.'|'.$sValue.'|'.($df==null).'|<br/>');
if(strlen($sValue)==0 && $df==null)
//if exists a default value use the default values instead of null
if(strlen($sValue)==0 && is_null($x_value['default']) )
{
$sVal .= "NULL, ";
}
else{
if(strlen($sValue)==0){
$sValue=$df;
$sValue=$x_value['default'];
}
switch ($sType)
{
Expand Down
2 changes: 1 addition & 1 deletion library/dbmng/dbmng_extend_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ function dbmng_id_test()
}


?>
?>
2 changes: 1 addition & 1 deletion tests/enpimodule/enpimodule.module
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function say_hello_world() {
$id_table = $_REQUEST['tbl'];
$aForm = dbmng_get_form_array($id_table);

//the param array stores sone variabble used by the renderer
//the param array stores some custom variable used by the renderer
$aParam = array();
//hidden_vars are some hidden variables used by the form creation
$aParam['hidden_vars']=array();
Expand Down

0 comments on commit 67fc662

Please sign in to comment.