From 9c99e119426f0fcb567d7b1ada476b573b8b47ff Mon Sep 17 00:00:00 2001 From: Enrique Ponce De Leon Date: Fri, 8 Apr 2011 12:16:46 -0400 Subject: [PATCH] BUG 6684 Solved. Grid View Mode Fixed. --- gulliver/js/grid/core/grid.js | 9 +- gulliver/system/class.xmlform.php | 619 ++++++++++++++++++------------ 2 files changed, 381 insertions(+), 247 deletions(-) diff --git a/gulliver/js/grid/core/grid.js b/gulliver/js/grid/core/grid.js index db869a7d4..73a75995c 100644 --- a/gulliver/js/grid/core/grid.js +++ b/gulliver/js/grid/core/grid.js @@ -293,7 +293,8 @@ var G_Grid = function(oForm, sGridName){ aObjects[0].value = defaultValue; break; case 'hidden': //HIDDEN - aObjects[0].value = defaultValue; + if ((attributes.gridtype != 'yesno' && attributes.gridtype != 'dropdown') || typeof attributes.gridtype == 'undefined') + aObjects[0].value = defaultValue; break; } } @@ -393,6 +394,12 @@ var G_Grid = function(oForm, sGridName){ //TODO: Implement Default Value and Dependent Fields Trigger for grid dropdowns } } + aObjects = oNewRow.getElementsByTagName('td')[i].getElementsByTagName('input'); + if (aObjects.length > 0){ + newID = aObjects[0].id.replace(/\[1\]/g, '\[' + currentRow + '\]'); + aObjects[0].id = newID; + aObjects[0].name = newID; + } aObjects = null; break; case 'a': //LINKS diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php index 55299ac17..1c850c320 100644 --- a/gulliver/system/class.xmlform.php +++ b/gulliver/system/class.xmlform.php @@ -826,6 +826,7 @@ class XmlForm_Field_SimpleText extends XmlForm_Field var $mask = ''; /* Additional events */ var $onkeypress = ''; + var $renderMode = ''; /** * Function render * @author David S. Callizaya S. @@ -860,33 +861,33 @@ class XmlForm_Field_SimpleText extends XmlForm_Field */ function renderGrid($values = array(), $owner) { - // Note added by Gustavo Cruz - // set the variable isRequired if the needs to be validated - // - if ($this->required){ - $isRequired = '1'; - } else { - $isRequired = '0'; - } $result = array (); $r = 1; - if( ! isset($owner->modeGrid)) $owner->modeGrid = ''; - // Note added by Gustavo Cruz - // also the fields rendered in a grid needs now have an attribute required set to 0 or 1 - // that it means not required or required respectively. - $this->mode = $this->modeForGrid; - + if ($owner->mode != 'view') $this->renderMode = $this->modeForGrid; + foreach ( $values as $v ) { - if ($this->mode === 'edit' && $owner->modeGrid != 'view') { - if ($this->readOnly) - $result [] = 'NSRequiredValue().' readOnly="readOnly" style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" '.$this->NSDefaultValue().' '.$this->NSGridType().' '.$this->NSGridLabel().'/>'; - else - $result [] = 'NSRequiredValue().' style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" '.$this->NSDefaultValue().' '.$this->NSGridType().' '.$this->NSGridLabel().'/>'; - } elseif ($this->mode === 'view' || $owner->modeGrid === 'view') { - $result [] = 'NSRequiredValue().' style="display:none;' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" '.$this->NSDefaultValue().' '.$this->NSGridType().' '.$this->NSGridLabel().'/>' . htmlentities ( $v, ENT_COMPAT, 'utf-8' ); - } else { - $result [] = $this->htmlentities ( $v, ENT_COMPAT, 'utf-8' ); + $html = ''; + if ($this->renderMode === 'edit'){ //EDIT MODE + $readOnlyText = ($this->readOnly == 1 || $this->readOnly == '1') ? 'readOnly="readOnly"' : ''; + $html .= 'name.']['.$r.']['.$this->name.']" '; + $html .= 'name="form['.$owner->name.']['.$r.']['.$this->name.']" '; + $html .= 'type="text" size="'.$this->size.'" maxlength="'.$this->maxLength.'" '; + $html .= 'value="'.$this->htmlentities($v, ENT_QUOTES, 'utf-8').'" '; + $html .= 'style="'.$this->htmlentities($this->style, ENT_COMPAT, 'utf-8').'" '; + $html .= $this->NSDefaultValue().' '; + $html .= $this->NSRequiredValue().' '; + $html .= $this->NSGridType().' '; + $html .= $this->NSGridLabel().' '; + $html .= '/>'; + }else{ //VIEW MODE + $html .= $this->htmlentities($v, ENT_QUOTES, 'utf-8'); + $html .= 'name.']['.$r.']['.$this->name.']" '; + $html .= 'name="form['.$owner->name.']['.$r.']['.$this->name.']" '; + $html .= 'type="hidden" value="'.$this->htmlentities($v, ENT_QUOTES, 'utf-8').'" />'; } + $result [] = $html; $r ++; } return $result; @@ -919,6 +920,7 @@ class XmlForm_Field_Text extends XmlForm_Field_SimpleText var $function = ''; var $replaceTags = 0; var $hint; + var $renderMode = ''; /** @@ -931,6 +933,7 @@ class XmlForm_Field_Text extends XmlForm_Field_SimpleText */ function render($value = NULL, $owner = NULL) { + if ($this->renderMode =='') $this->renderMode = $this->mode; if (($this->pmconnection != '') && ($this->pmfield != '') && $value == NULL) { $value = $this->getPMTableValue($owner); } @@ -942,33 +945,44 @@ class XmlForm_Field_Text extends XmlForm_Field_SimpleText } //NOTE: string functions must be in G class - if ($this->strTo === 'UPPER') - $value = strtoupper ( $value ); - if ($this->strTo === 'LOWER') - $value = strtolower ( $value ); - //if ($this->strTo==='CAPITALIZE') $value = strtocapitalize($value); + if ($this->strTo === 'UPPER') $value = strtoupper ( $value ); + if ($this->strTo === 'LOWER') $value = strtolower ( $value ); + //if ($this->strTo==='CAPITALIZE') $value = strtocapitalize($value); $onkeypress = G::replaceDataField ( $this->onkeypress, $owner->values ); if ($this->replaceTags == 1) { $value = G::replaceDataField ( $value, $owner->values ); - } - if ($this->mode === 'edit') { - if ($this->readOnly){ - $html = 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' readOnly="readOnly" style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>'; - } else { - $html = 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>'; - } - if($this->hint){ - $html .= ' + } + + $html = ''; + if ($this->renderMode == 'edit'){ //EDIT MODE + $readOnlyText = ($this->readOnly == 1 || $this->readOnly == '1') ? 'readOnly="readOnly"': ''; + $html .= 'name . ']" '; + $html .= 'name="form[' . $this->name . ']" '; + $html .= 'type="text" size="' . $this->size . '" maxlength="' . $this->maxLength . '" '; + $html .= 'value="'.$this->htmlentities ($value, ENT_QUOTES, 'utf-8').'" '; + $html .= 'style="'.$this->htmlentities($this->style, ENT_COMPAT, 'utf-8').'" '; + $html .= 'onkeypress="'.$this->htmlentities($onkeypress, ENT_COMPAT, 'utf-8').'" '; + $html .= $this->NSDefaultValue().' '; + $html .= $this->NSRequiredValue().' '; + $html .= '/>'; + }else{ //VIEW MODE + $html .= $this->htmlentities($value, ENT_QUOTES, 'utf-8'); + $html .= 'name . ']" '; + $html .= 'name="form[' . $this->name . ']" '; + $html .= 'type="hidden" value="'.$this->htmlentities($value, ENT_QUOTES, 'utf-8').'" />'; + } + + if($this->hint){ + $html .= ' '; - } - return $html; - } elseif ($this->mode === 'view') { - return 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' style="display:none;' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>' . $this->htmlentities ( $value, ENT_COMPAT, 'utf-8' ); - } else { - return $this->htmlentities ( $value, ENT_QUOTES, 'utf-8' ); } + + return $html; } + /** * Function renderGrid * @author David S. Callizaya S. @@ -981,19 +995,8 @@ class XmlForm_Field_Text extends XmlForm_Field_SimpleText { $result = $aux = array (); $r = 1; - if( ! isset($owner->modeGrid)) $owner->modeGrid = ''; - // Note added by Gustavo Cruz -// set the variable isRequired if the needs to be validated - if ($this->required){ - $isRequired = '1'; - } else { - $isRequired = '0'; - } - - // Note added by Gustavo Cruz - // also the fields rendered in a grid needs now have an attribute required set to 0 or 1 - // that it means not required or required respectively. - $this->mode = $this->modeForGrid; + if ($owner->mode != 'view') $this->renderMode = $this->modeForGrid; + foreach ( $values as $v ) { $this->executeSQL ( $owner, $r ); $firstElement = key ( $this->sqlOption ); @@ -1003,17 +1006,31 @@ class XmlForm_Field_Text extends XmlForm_Field_SimpleText $v = G::replaceDataField ( $v, $owner->values ); } $aux [$r] = $v; - $v =($v!='')?$v:$this->defaultValue; - if ($this->mode === 'edit' && $owner->modeGrid != 'view') { - if ($this->readOnly) - $result [] = 'NSDefaultValue().' '.$this->NSGridLabel().'/>'; - else - $result [] = 'NSDefaultValue().' '.$this->NSGridLabel().'/>'; - } elseif ($this->mode === 'view' || $owner->modeGrid === 'view') { - $result [] = 'NSDefaultValue().' '.$this->NSGridLabel().'/>' . htmlentities ( $v, ENT_COMPAT, 'utf-8' ); - } else { - $result [] = $this->htmlentities ( $v, ENT_COMPAT, 'utf-8' ); + + $html = ''; + if ($this->renderMode == 'edit'){ //EDIT MODE + $readOnlyText = ($this->readOnly == 1 || $this->readOnly == '1') ? 'readOnly="readOnly"': ''; + $html .= 'name.']['.$r.']['.$this->name.']" '; + $html .= 'name="form['.$owner->name.']['.$r.']['.$this->name.']" '; + $html .= 'type="text" size="' . $this->size . '" maxlength="' . $this->maxLength . '" '; + $html .= 'value="'.$this->htmlentities ($v, ENT_QUOTES, 'utf-8').'" '; + $html .= 'style="'.$this->htmlentities($this->style, ENT_COMPAT, 'utf-8').'" '; + $html .= $this->NSDefaultValue().' '; + $html .= $this->NSRequiredValue().' '; + $html .= $this->NSGridLabel().' '; + $html .= $this->NSGridType().' '; + $html .= $this->NSDependentFields().' '; + $html .= '/>'; + }else{ //VIEW MODE + $html .= $this->htmlentities($v, ENT_QUOTES, 'utf-8'); + $html .= 'name.']['.$r.']['.$this->name.']" '; + $html .= 'name="form['.$owner->name.']['.$r.']['.$this->name.']" '; + $html .= 'type="hidden" value="'.$this->htmlentities($v, ENT_QUOTES, 'utf-8').'" />'; } + + $result [] = $html; $r ++; } $this->options = $aux; @@ -1378,6 +1395,7 @@ class XmlForm_Field_Textarea extends XmlForm_Field { var $wrap = 'OFF'; var $hint = ''; var $className; + var $renderMode = ''; /** @@ -1388,6 +1406,7 @@ class XmlForm_Field_Textarea extends XmlForm_Field { * @return string */ function render($value = NULL, $owner) { + if (($this->pmconnection != '') && ($this->pmfield != '') && $value == NULL) { $value = $this->getPMTableValue($owner); } @@ -1400,24 +1419,40 @@ class XmlForm_Field_Textarea extends XmlForm_Field { } $className = isset($this->className) ? $this->className : 'module_app_input___gray'; - - if ($this->mode === 'edit') { - if ($this->readOnly) - return ''; - else{ - $html = ''; - if($this->hint){ - $html .= ' + + if ($this->renderMode == '') $this->renderMode = $this->mode; + + $html = ''; + if ($this->renderMode == 'edit'){ //EDIT MODE + $readOnlyText = ($this->readOnly == 1 || $this->readOnly == '1')? 'readOnly="readOnly"':''; + $html .= ''; + }else{ //VIEW MODE + $html .= ''; + } + + if($this->hint){ + $html .= ' '; - } - return $html; - } - } elseif ($this->mode === 'view') { - return ''; - } else { - return ''; } + + return $html; } /** * Function renderGrid @@ -1429,44 +1464,39 @@ class XmlForm_Field_Textarea extends XmlForm_Field { */ function renderGrid($values = NULL, $owner) { $this->gridFieldType = 'textarea'; - // Note added by Gustavo Cruz - // set the variable isRequired if the needs to be validated - if ($this->required){ - $isRequired = '1'; - } else { - $isRequired = '0'; - } + if ($owner->mode != 'view') $this->renderMode = $this->modeForGrid; - // Note added by Gustavo Cruz - // also the fields rendered in a grid needs now have an attribute required set to 0 or 1 - // that it means not required or required respectively. $result = array (); $r = 1; - if( ! isset($owner->modeGrid)) $owner->modeGrid = ''; - $this->mode = $this->modeForGrid; + foreach ( $values as $v ) { - if ($this->mode === 'edit' && $owner->modeGrid != 'view') { - if (is_null($v)) $v = $this->defaultValue; - if ($this->readOnly) - $result [] = ''; - else - $result [] = ''; - } elseif ($this->mode === 'view' || $owner->modeGrid === 'view') { - - if (stristr ( $_SERVER ['HTTP_USER_AGENT'], 'iPhone' )) { - //$result[] = '
'.$this->htmlentities( $v , ENT_COMPAT, 'utf-8').'
'; - - $result [] = $this->htmlentities ( $v, ENT_COMPAT, 'utf-8' ); - } else { //start add Alvaro - $varaux = ''; - $result [] = $this->htmlentities ( $v, ENT_COMPAT, 'utf-8' ).'
'.$varaux.'
'; - //end add Alvaro - } - - } else { - $result [] = $this->htmlentities ( $v, ENT_COMPAT, 'utf-8' ); + $html = ''; + if ($this->renderMode == 'edit'){ //EDIT MODE + $readOnlyText = ($this->readOnly == 1 || $this->readOnly == '1')? 'readOnly="readOnly"':''; + $html .= ''; + }else{ //VIEW MODE + $html .= ''; } + $result[] = $html; $r ++; } return $result; @@ -1501,31 +1531,42 @@ class XmlForm_Field_Currency extends XmlForm_Field_SimpleText { * @return */ function render( $value = NULL, $owner = NULL) { - //$this->gridFieldType = 'currency'; - + + if ($this->renderMode == '') $this->renderMode = $this->mode; $onkeypress = G::replaceDataField ( $this->onkeypress, $owner->values ); - if ($this->mode === 'edit') { - if ($this->readOnly) - return 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' readOnly="readOnly" style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '" '.$this->NSRequiredValue().' '.$this->NSDefaultValue().' '.$this->NSGridType().'/>'; - else { - - $html = 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '" '.$this->NSRequiredValue().' '.$this->NSDefaultValue().' '.$this->NSGridType().'/>'; - - if($this->hint){ - $html .= ' + + $html = ''; + + if ($this->renderMode == 'edit'){ //EDIT MODE + $readOnlyText = ($this->readOnly == 1 || $this->readOnly == '1') ? 'readOnly="readOnly"' : ''; + $html .= 'name . ']" '; + $html .= 'name="form[' . $this->name . ']" '; + $html .= 'type="text" size="'.$this->size.'" maxlength="'.$this->maxLength.'" '; + $html .= 'value="'.$this->htmlentities($value, ENT_QUOTES, 'utf-8').'" '; + $html .= 'style="'.$this->htmlentities($this->style, ENT_COMPAT, 'utf-8').'" '; + $html .= 'onkeypress="'.$this->htmlentities($onkeypress, ENT_COMPAT, 'utf-8').'" '; + $html .= $this->NSDefaultValue().' '; + $html .= $this->NSRequiredValue().' '; + $html .= $this->NSGridType().' '; + $html .= '/>'; + }else{ //VIEW MODE + $html .= $this->htmlentities($value, ENT_COMPAT, 'utf-8'); + $html .= 'name . ']" '; + $html .= 'name="form[' . $this->name . ']" '; + $html .= 'type="hidden" value="'.$this->htmlentities($value, ENT_COMPAT, 'utf-8').'" />'; + } + + if($this->hint){ + $html .= ' '; - } - - return $html; - } - } elseif ($this->mode === 'view') { - return 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' style="display:none;' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>' . $this->htmlentities ( $value, ENT_COMPAT, 'utf-8' ); - } else { - return $this->htmlentities ( $value, ENT_QUOTES, 'utf-8' ); } - } + + return $html; + } } /*DEPRECATED*/ @@ -1564,27 +1605,61 @@ class XmlForm_Field_Percentage extends XmlForm_Field_SimpleText { var $gridFieldType = 'percentage'; function render( $value = NULL, $owner = NULL) { + + if ($this->renderMode == '') $this->renderMode = $this->mode; $onkeypress = G::replaceDataField ( $this->onkeypress, $owner->values ); - if ($this->mode === 'edit') { - if ($this->readOnly) - return 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' readOnly="readOnly" style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>'; - else { - - $html = 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>'; - - if($this->hint){ - $html .= ' + + $html = ''; + + if ($this->renderMode == 'edit'){ //EDIT MODE + $readOnlyText = ($this->readOnly == 1 || $this->readOnly == '1') ? 'readOnly="readOnly"' : ''; + $html .= 'name . ']" '; + $html .= 'name="form[' . $this->name . ']" '; + $html .= 'type="text" size="'.$this->size.'" maxlength="'.$this->maxLength.'" '; + $html .= 'value="'.$this->htmlentities($value, ENT_QUOTES, 'utf-8').'" '; + $html .= 'style="'.$this->htmlentities($this->style, ENT_COMPAT, 'utf-8').'" '; + $html .= 'onkeypress="'.$this->htmlentities($onkeypress, ENT_COMPAT, 'utf-8').'" '; + $html .= $this->NSDefaultValue().' '; + $html .= $this->NSRequiredValue().' '; + $html .= '/>'; + }else{ //VIEW MODE + $html .= $this->htmlentities($value, ENT_COMPAT, 'utf-8'); + $html .= 'name . ']" '; + $html .= 'name="form[' . $this->name . ']" '; + $html .= 'type="hidden" value="'.$this->htmlentities($value, ENT_COMPAT, 'utf-8').'" />'; + } + + if($this->hint){ + $html .= ' '; - } - - return $html; - } - } elseif ($this->mode === 'view') { - return 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' style="display:none;' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>' . $this->htmlentities ( $value, ENT_COMPAT, 'utf-8' ); - } else { - return $this->htmlentities ( $value, ENT_QUOTES, 'utf-8' ); } + + return $html; + +// $onkeypress = G::replaceDataField ( $this->onkeypress, $owner->values ); +// if ($this->mode === 'edit') { +// if ($this->readOnly) +// return 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' readOnly="readOnly" style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>'; +// else { +// +// $html = 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' style="' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>'; +// +// if($this->hint){ +// $html .= ' +// +// '; +// } +// +// return $html; +// } +// } elseif ($this->mode === 'view') { +// return 'htmlentities ( $value, ENT_QUOTES, 'utf-8' ) . '\' style="display:none;' . htmlentities ( $this->style, ENT_COMPAT, 'utf-8' ) . '" onkeypress="' . htmlentities ( $onkeypress, ENT_COMPAT, 'utf-8' ) . '"/>' . $this->htmlentities ( $value, ENT_COMPAT, 'utf-8' ); +// } else { +// return $this->htmlentities ( $value, ENT_QUOTES, 'utf-8' ); +// } } @@ -1838,6 +1913,7 @@ class XmlForm_Field_YesNo extends XmlForm_Field var $required = false; var $readonly = false; var $hint; + var $renderMode = ''; /** * Function render * @author David S. Callizaya S. @@ -1850,22 +1926,39 @@ class XmlForm_Field_YesNo extends XmlForm_Field if (($this->pmconnection != '') && ($this->pmfield != '') && $value == NULL) { $value = $this->getPMTableValue($owner); } - - if($this->readonly == true){ - $readOnlyField = "disabled"; - } else $readOnlyField = ""; - - $html = ($this->mode == 'view' ? ($value === '0' ? 'NO' : 'YES') : '') . ''; + if ($value == '') $value = '0'; + if ($this->renderMode = '') $this->renderMode = $this->mode; + $html = ''; + if ($this->renderMode == 'edit'){ //EDIT MODE + $readOnlyText = ($this->readonly == 1 || $this->readonly == '1') ? 'disabled' : ''; + $html .= ''; + if ($readOnlyText != ''){ + $html .= 'name.']" '; + $html .= 'name="form['.$this->name.']" '; + $html .= 'type="hidden" value="'.(($value==='0')? '0':'1').'" />'; + } + }else{ //VIEW MODE + $html .= ($value==='0') ? G::LoadTranslation('ID_NO_VALUE') : G::LoadTranslation('ID_YES_VALUE'); + $html .= 'name.']" '; + $html .= 'name="form['.$this->name.']" '; + $html .= 'type="hidden" value="'.(($value==='0')? '0':'1').'" />'; + } if($this->hint){ - $html .= ' + $html .= ' '; } - return $html; } @@ -1879,13 +1972,38 @@ class XmlForm_Field_YesNo extends XmlForm_Field $this->gridFieldType = 'yesno'; $result = array (); $r = 1; + if ($owner->mode != 'view') $this->renderMode = $this->modeForGrid; - $this->mode = $this->modeForGrid; foreach ( $values as $v ) { - $html = (($this->mode == 'view' || $owner->modeGrid == 'view')? ($v === '0' ? 'NO' : 'YES') : '') . ''; + $html = ''; + if ($v == '') $v = '0'; + if ($this->renderMode == 'edit'){ //EDIT MODE + $readOnlyText = ($this->readonly == 1 || $this->readonly == '1') ? 'disabled' : ''; + $html .= ''; + if ($readOnlyText != ''){ + $html .= 'name.']['.$r.']['.$this->name.']" '; + $html .= 'name="form['.$owner->name.']['.$r.']['.$this->name.']" '; + $html .= 'type="hidden" value="'.(($v==='0')? '0':'1').'" />'; + } + }else{ //VIEW MODE + $html .= ($v==='0') ? G::LoadTranslation('ID_NO_VALUE') : G::LoadTranslation('ID_YES_VALUE'); + $html .= 'name.']['.$r.']['.$this->name.']" '; + $html .= 'name="form['.$owner->name.']['.$r.']['.$this->name.']" '; + $html .= $this->NSGridType().' '; + $html .= 'type="hidden" value="'.(($v==='0')? '0':'1').'" />'; + } $result [] = $html; $r ++; } @@ -2389,6 +2507,7 @@ class XmlForm_Field_Dropdown extends XmlForm_Field { var $saveLabel = 0; var $hint; var $modeGridDrop = ''; + var $renderMode = ''; function validateValue($value, &$owner) { /*$this->executeSQL( $owner ); @@ -2406,9 +2525,11 @@ class XmlForm_Field_Dropdown extends XmlForm_Field { */ function render($value = NULL, $owner = NULL, $rowId = '', $onlyValue = false, $row = -1, $therow = -1) { + //Returns value from a PMTable when it is exists. if (($this->pmconnection != '') && ($this->pmfield != '') && $value == NULL) { $value = $this->getPMTableValue($owner); } + //Recalculate SQL options if $therow is not defined or the row id equal if ($therow == - 1) { $this->executeSQL ( $owner, $row ); } else { @@ -2416,75 +2537,100 @@ class XmlForm_Field_Dropdown extends XmlForm_Field { $this->executeSQL ( $owner, $row ); } } + $html = ''; - // Note added by Gustavo Cruz - // set the variable isRequired if the needs to be validated - // - if ($this->required){ - $isRequired = '1'; - } else { - $isRequired = '0'; - } - //end - - // added by Gustavo Cruz - if($this->readonly == true || $this->modeGridDrop === 'view'){ - $readOnlyField = "disabled"; - } else $readOnlyField = ""; - // added end - if (! $onlyValue) { - if ($this->mode === 'edit') { - $html = 'style) ? 'style="' . $this->style . '"' : '') . '>'; + + if ($this->renderMode == '') $this->renderMode = $this->mode; + + if (!$onlyValue){ //Render Field if not defined onlyValue + if ($this->renderMode == 'edit'){ //EDIT MODE + $readOnlyField = ($this->readonly == 1 || $this->readonly == '1') ? 'disabled' : ''; + $html = ''; + if ($readOnlyField != ''){ + $html .= 'name . ']" '; + $html .= 'name="form' . $rowId . '[' . $this->name . ']" '; + $html .= 'value="'.(($findValue != '') ? $findValue : $firstValue).'" />'; + } + }else{ //VIEW MODE + $findValue = ''; + $firstValue = ''; + $firstName = ''; + foreach ($this->option as $optValue => $optName ){ + settype($optValue,'string'); + if ($optValue === $value){ + $html .= $this->htmlentities($optName, ENT_COMPAT, 'utf-8'); + $findValue = $optValue; + } + if ($firstValue == '') { + $firstValue = $optValue; + $firstName = $optName; + } + } + foreach ($this->sqlOption as $optValue => $optName ){ + settype($optValue,'string'); + if ($optValue === $value){ + $html .= $this->htmlentities($optName, ENT_COMPAT, 'utf-8'); + $findValue = $optValue; + } + if ($firstValue == '') { + $firstValue = $optValue; + $firstName = $optName; + } + } + if ($html == '' && $firstValue != '' && $findValue == ''){ + $html = $this->htmlentities($firstName,ENT_COMPAT, 'utf-8'); + $findValue = $firstValue; + } + $html .= 'name . ']" '; + $html .= 'name="form' . $rowId . '[' . $this->name . ']" '; + $html .= $this->NSGridType().' '; + $html .= 'value="'.$findValue.'" />'; } - foreach ( $this->option as $optionName => $option ) { - // if change the type with the settype function then compare "0" == "" so both can be diferentiated - settype($optionName,'string'); - $html .= ''; - } - foreach ( $this->sqlOption as $optionName => $option ) { - // if change the type with the settype function then compare "0" == "" so both can be diferentiated - settype($optionName,'string'); - $html .= ''; - } - $html .= ''; - } else { - foreach ( $this->option as $optionName => $option ) { - if ($optionName == $value) { - $html = $option; + }else{ //Render Field showing only value; + foreach ($this->option as $optValue => $optName) { + if ($optValue == $value) { + $html = $optName; } } - foreach ( $this->sqlOption as $optionName => $option ) { - if ($optionName == $value) { - $html = $option; + foreach ($this->sqlOption as $optValue => $optName) { + if ($optValue == $value) { + $html = $optName; } } } + if($this->hint){ - $html .= ' + $html .= ' '; - } -//add by alvaro - if($this->readonly){ - $readOnlyField = ""; - $html1 = ''; - $html.='
'.$html1.'
'; - } -//end add + } + return $html; } @@ -2497,21 +2643,17 @@ class XmlForm_Field_Dropdown extends XmlForm_Field { */ function renderGrid($values = array(), $owner = NULL, $onlyValue = false, $therow = -1) { - $this->gridFieldType = 'dropdown'; $result = array (); $r = 1; - if(! isset($owner->modeGrid)) $owner->modeGrid = ''; - $this->modeGridDrop = $owner->modeGrid; - - $this->mode = $this->modeForGrid; + if ($owner->mode != 'view') $this->renderMode = $this->modeForGrid; + foreach ( $values as $v ) { $result [] = $this->render ( $v, $owner, '[' . $owner->name . '][' . $r . ']', $onlyValue, $r, $therow ); $r ++; } return $result; } - } /** * Class XmlForm_Field_Listbox @@ -2892,7 +3034,6 @@ class XmlForm_Field_Grid extends XmlForm_Field */ function renderGrid($values, $owner = NULL, $therow = -1) { - //g::pr($values); $this->id = $this->owner->id . $this->name; $using_template = "grid"; @@ -4477,17 +4618,3 @@ class XmlForm_Field_Image extends XmlForm_Field $value = date($tmp); return $value; } - - /** - * Returns if the current dynaform is new or reopened - * @author Enrique Ponce de Leon - * @package gulliver.system - */ -// function isNewDynaform($owner){ -// if (isset($_SESSION['NEW_CASE'])){ -// $sw = ($_SESSION['NEW_CASE']=='New')? '1' : '0'; -// }else{ -// $sw = '0'; -// } -// return $sw; -// }