BUG 6860 Solved. Fix save_label option for multiples dropdowns

This commit is contained in:
Enrique Ponce De Leon
2011-05-12 16:34:37 -04:00
parent 9d50c86eda
commit 587a0f67be

View File

@@ -299,128 +299,103 @@ class Form extends XmlForm
{ {
//$values = $this->values; //$values = $this->values;
$values = array(); $values = array();
foreach($this->fields as $k => $v){ foreach($this->fields as $k => $v){ //Buque 1
//echo $v->type.'<br>';
if (($v->type != 'submit')) { if (($v->type != 'submit')) {
if ($v->type != 'file') { if ($v->type != 'file') {
if ( array_key_exists($k,$newValues) ) { if ( array_key_exists($k,$newValues) ) {
if ( is_array($newValues[$k]) ) { switch($v->type){
if (($v->type == 'checkgroup') || ($v->type == 'listbox')) { case 'checkgroup': case 'listbox':
$values[$k] = implode('|', $newValues[$k]); $values[$k] = implode('|', $newValues[$k]);
} else { break;
case 'dropdown':
if ($v->saveLabel == 1) {
if(isset($v->options[$newValues[$k]])){
$values[$k . '_label'] = $v->options[$newValues[$k]];
}else{
$query = G::replaceDataField($this->fields[$k]->sql,$newValues);
//we do the query to the external connection and we've got the label
$con = Propel::getConnection($this->fields[$k]->sqlConnection);
$stmt = $con->prepareStatement($query);
$rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
while ($rs->next()){
$row = $rs->getRow();
$rowId = $row['0'];
$rowContent = $row['1'];
if ($newValues[$k]==$rowId){
$values[$k . '_label'] = $rowContent;
break;
}
}
}
}
break;
case 'grid':
foreach( $newValues[$k] as $j => $item ) { foreach( $newValues[$k] as $j => $item ) {
if(is_array($item)){ if(is_array($item)){
$i=0; $i=0;
// the variable fieldIsSet checks if a dropdown label has been saved so the values cannot be rewritted again. $values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this );
$fieldIsSet = false;
foreach($item as $kk => $vv){ foreach($item as $kk => $vv){
//we need to know which fields are dropdowns //we need to know which fields are dropdowns
if($this->fields[$k]->fields[$kk]->type == 'dropdown'){ if($this->fields[$k]->fields[$kk]->type == 'dropdown'){
if(($this->fields[$k]->fields[$kk]->saveLabel)==1){ if(($this->fields[$k]->fields[$kk]->saveLabel)==1){
if ($this->fields[$k]->validateValue($newValues[$k][$j], $this )){ if ($this->fields[$k]->validateValue($newValues[$k][$j], $this )){
// also we need to know if the $values array has dropdown labels added if (isset($this->fields[$k]->fields[$kk]->options[$vv])){
if(!$fieldIsSet) { $values[$k][$j][$kk. '_label'] = $this->fields[$k]->fields[$kk]->options[$vv];
$values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this ); }else{
if (isset($this->fields[$k]->fields[$kk]->options[$vv])){ $query = G::replaceDataField($this->fields[$k]->fields[$kk]->sql,$values[$k][$j]);
$values[$k][$j][$kk. '_label'] = $this->fields[$k]->fields[$kk]->options[$vv]; $con = Propel::getConnection('workflow');
$fieldIsSet = true; $stmt = $con->prepareStatement($query);
}else{ $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
$query = G::replaceDataField($this->fields[$k]->fields[$kk]->sql,$values[$k][$j]); while ($rs->next()){
$con = Propel::getConnection('workflow'); // from the query executed we only need certain elements
$stmt = $con->prepareStatement($query); $row = $rs->getRow();
$rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM); $rowId = $row['0'];
while ($rs->next()){ $rowContent = $row['1'];
// from the query executed we only need certain elements if ($vv==$rowId){
$row = $rs->getRow(); $values[$k][$j][$kk. '_label'] = $rowContent;
$rowId = $row['0']; break;
$rowContent = $row['1'];
if ($vv==$rowId){
$values[$k][$j][$kk. '_label'] = $rowContent;
$fieldIsSet = true;
break;
}
} }
} }
} else {
// if a dropdown label been set there is no need to load the default values.
if(isset($this->fields[$k]->fields[$kk]->options[$vv]))
$values[$k][$j][$kk. '_label'] = $this->fields[$k]->fields[$kk]->options[$vv];
} }
} }
}else{ }/*else{
if ($this->fields[$k]->validateValue($newValues[$k][$j], $this )){ if ($this->fields[$k]->validateValue($newValues[$k][$j], $this )){
// if there is a dropdown but with a savelabel set to 0 this checks if a previous dropdown has been setted // if there is a dropdown but with a savelabel set to 0 this checks if a previous dropdown has been setted
// so if its true then the $values cannot be rewritted // so if its true then the $values cannot be rewritted
if (!$fieldIsSet){ //$values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this );//print_r($values[$k][$j]);print'<hr>';
$values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this );//print_r($values[$k][$j]);print'<hr>';
}
} }
} }*/
} else { }/* else {
if (!$fieldIsSet){ // if there are no dropdowns previously setted and the evaluated field is not a dropdown
// if there are no dropdowns previously setted and the evaluated field is not a dropdown // only then rewritte the $values
// only then rewritte the $values //$values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this );
$values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this ); }*/
}
}
$i++; $i++;
} }
}else{ }/*else{
if ($this->fields[$k]->validateValue($newValues[$k][$j], $this )) if ($this->fields[$k]->validateValue($newValues[$k][$j], $this ))
$values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this );//print_r($values[$k][$j]);print'<hr>'; $values[$k][$j] = $this->fields[$k]->maskValue( $newValues[$k][$j], $this );//print_r($values[$k][$j]);print'<hr>';
} }*/
} }
if ((sizeof($values[$k])===1) && ($v->type!=='grid') && ($this->type!=='grid')){ break;
$values[$k] = $values[$k][0]; default:
} if ($this->fields[$k]->validateValue($newValues[$k], $this ))
if (sizeof($values[$k])===0)
$values[$k] = '';
}
} else {
if ($this->fields[$k]->validateValue($newValues[$k], $this ))
$values[$k] = $this->fields[$k]->maskValue( $newValues[$k], $this ); $values[$k] = $this->fields[$k]->maskValue( $newValues[$k], $this );
} }
if ($v->type == 'dropdown') {
if ($v->saveLabel == 1) {
if(isset($v->option[$newValues[$k]])){
$values[$k . '_label'] = $v->option[$newValues[$k]];
}else{
$query = G::replaceDataField($this->fields[$k]->sql,$newValues);
//we do the query to the external connection and we've got the label
$con = Propel::getConnection($this->fields[$k]->sqlConnection);
$stmt = $con->prepareStatement($query);
$rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
while ($rs->next()){
$row = $rs->getRow();
$rowId = $row['0'];
$rowContent = $row['1'];
if ($newValues[$k]==$rowId){
$values[$k . '_label'] = $rowContent;
break;
}
}
}
}
}
} }
/* else{
if ($v->type == 'checkbox') {
$values[$k]=$v->falseValue;
}
else {
if ($v->type != 'javascript' && $v->type !='title') {
$values[$k] = null;
}
}
}*/
} }
else { else {
if (isset($_FILES['form']['name'][$k])) { if (isset($_FILES['form']['name'][$k])) {
$values[$k] = $_FILES['form']['name'][$k]; $values[$k] = $_FILES['form']['name'][$k];
} }
/** /**
* FIXED for multiple inputs documents related to file type field * FIXED for multiple inputs documents related to file type field
* By Erik Amaru Ortiz <erik@colosa.com> * By Erik Amaru Ortiz <erik@colosa.com>
* Nov 24th, 2009 * Nov 24th, 2009
*/ */
if ( isset($v->input) && $v->input != ''){ if ( isset($v->input) && $v->input != ''){
$_POST['INPUTS'][$k] = $v->input; $_POST['INPUTS'][$k] = $v->input;
@@ -429,11 +404,12 @@ class Form extends XmlForm
} }
} }
} }
foreach ($newValues as $k => $v) { foreach ($newValues as $k => $v) {
if (strpos($k, 'SYS_GRID_AGGREGATE_') !== false) { if (strpos($k, 'SYS_GRID_AGGREGATE_') !== false) {
$values[$k] = $v; $values[$k] = $v;
} }
}//die; }
return $values; return $values;
} }