summaryrefslogtreecommitdiff
path: root/adodb-lib.inc.php
diff options
context:
space:
mode:
authorDamien Regad <dregad@mantisbt.org>2019-05-07 18:02:55 +0200
committerDamien Regad <dregad@mantisbt.org>2019-11-24 01:51:00 +0100
commitfdce0e92feec579269883dbe0ef952a71f6b744a (patch)
treefb1d8d370af063fae8230d6321a3c484a1d1a0fd /adodb-lib.inc.php
parent44cacdc45d3208fdb3ae349a644b8ea516cf1973 (diff)
downloadadodb-fdce0e92feec579269883dbe0ef952a71f6b744a.tar.gz
adodb-fdce0e92feec579269883dbe0ef952a71f6b744a.tar.bz2
adodb-fdce0e92feec579269883dbe0ef952a71f6b744a.zip
Code cleanup for _adodb_getmenu()/_adodb_getmenu_gp()
- Whitespace - Coding guidelines - Remove unused variables - Remove empty if statements - Optimization
Diffstat (limited to 'adodb-lib.inc.php')
-rw-r--r--adodb-lib.inc.php140
1 files changed, 69 insertions, 71 deletions
diff --git a/adodb-lib.inc.php b/adodb-lib.inc.php
index 2f94b51d..bf2c2b69 100644
--- a/adodb-lib.inc.php
+++ b/adodb-lib.inc.php
@@ -217,49 +217,49 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
{
global $ADODB_FETCH_MODE;
- $hasvalue = false;
-
- if (is_array($name))
- {
- /*
- * Reserved for future use
- */
- }
-
if ($multiple or is_array($defstr)) {
- if ($size==0) $size=5;
- $attr = ' multiple size="'.$size.'"';
- if (!strpos($name,'[]')) $name .= '[]';
- } else if ($size) $attr = ' size="'.$size.'"';
- else $attr ='';
+ if ($size == 0 ) {
+ $size = 5;
+ }
+ $attr = ' multiple size="' . $size . '"';
+ if (!strpos($name,'[]')) {
+ $name .= '[]';
+ }
+ } elseif ($size) {
+ $attr = ' size="' . $size . '"';
+ } else {
+ $attr ='';
+ }
$s = '<select name="'.$name.'"'.$attr.' '.$selectAttr.'>';
- if ($blank1stItem)
- {
+ if ($blank1stItem) {
if (is_string($blank1stItem)) {
$barr = explode(':',$blank1stItem);
- if (sizeof($barr) == 1) $barr[] = '';
+ if (sizeof($barr) == 1) {
+ $barr[] = '';
+ }
$s .= "\n<option value=\"".$barr[0]."\">".$barr[1]."</option>";
}
- else
+ else {
$s .= "\n<option></option>";
+ }
+ }
+
+ $hasvalue = $zthis->FieldCount() > 1;
+ if (!$hasvalue) {
+ $compareFields0 = true;
}
- if ($zthis->FieldCount() > 1) $hasvalue=true;
- else $compareFields0 = true;
$value = '';
- $optgroup = null;
- $firstgroup = true;
- $fieldsize = $zthis->FieldCount();
while(!$zthis->EOF) {
$zval = rtrim(reset($zthis->fields));
- if ($blank1stItem && $zval=="") {
+ if ($blank1stItem && $zval == "") {
$zthis->MoveNext();
continue;
}
- if ($fieldsize > 1) {
+ if ($hasvalue) {
if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC) {
// Get 2nd field's value regardless of its name
$zval2 = current(array_slice($zthis->fields, 1, 1));
@@ -268,25 +268,21 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
$zval2 = $zthis->fields[1];
}
$zval2 = trim($zval2);
+ $value = ' value="' . htmlspecialchars($zval2) . '"';
}
- $selected = ($compareFields0) ? $zval : $zval2;
-
- if ($hasvalue)
- $value = " value='".htmlspecialchars($zval2)."'";
-
- if (is_array($defstr))
- {
+ $selected = $compareFields0 ? $zval : $zval2;
- if (in_array($selected,$defstr))
- $s .= "\n<option selected='selected'$value>".htmlspecialchars($zval).'</option>';
+ if (is_array($defstr)) {
+ if (in_array($selected, $defstr))
+ $s .= "\n<option selected=\"selected\"$value>" . htmlspecialchars($zval) . '</option>';
else
- $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>';
+ $s .= "\n<option".$value.'>' . htmlspecialchars($zval) . '</option>';
}
else {
if (strcasecmp($selected,$defstr)==0)
- $s .= "\n<option selected='selected'$value>".htmlspecialchars($zval).'</option>';
+ $s .= "\n<option selected='selected'$value>" . htmlspecialchars($zval) . '</option>';
else
- $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>';
+ $s .= "\n<option".$value.'>' . htmlspecialchars($zval) . '</option>';
}
$zthis->MoveNext();
} // while
@@ -299,80 +295,82 @@ function _adodb_getmenu_gp(&$zthis, $name,$defstr='',$blank1stItem=true,$multipl
{
global $ADODB_FETCH_MODE;
- $hasvalue = false;
-
- if (is_array($name))
- {
- /*
- * Reserved for future use
- */
- }
-
if ($multiple or is_array($defstr)) {
- if ($size==0) $size=5;
- $attr = ' multiple size="'.$size.'"';
- if (!strpos($name,'[]')) $name .= '[]';
- } else if ($size) $attr = ' size="'.$size.'"';
- else $attr ='';
+ if ($size == 0) {
+ $size = 5;
+ }
+ $attr = ' multiple size="' . $size . '"';
+ if (!strpos($name,'[]')) {
+ $name .= '[]';
+ }
+ } elseif ($size) {
+ $attr = ' size="' . $size . '"';
+ } else {
+ $attr = '';
+ }
$s = '<select name="'.$name.'"'.$attr.' '.$selectAttr.'>';
if ($blank1stItem)
if (is_string($blank1stItem)) {
$barr = explode(':',$blank1stItem);
- if (sizeof($barr) == 1) $barr[] = '';
+ if (sizeof($barr) == 1) {
+ $barr[] = '';
+ }
$s .= "\n<option value=\"".$barr[0]."\">".$barr[1]."</option>";
- } else $s .= "\n<option></option>";
+ } else {
+ $s .= "\n<option></option>";
+ }
- if ($zthis->FieldCount() > 1) $hasvalue=true;
- else $compareFields0 = true;
+ $hasvalue = $zthis->FieldCount() > 1;
+ $hasgroup = $zthis->FieldCount() > 2;
+ if (!$hasvalue) {
+ $compareFields0 = true;
+ }
$value = '';
$optgroup = null;
$firstgroup = true;
- $fieldsize = sizeof($zthis->fields);
while(!$zthis->EOF) {
$zval = rtrim(reset($zthis->fields));
+ $group = '';
if ($blank1stItem && $zval=="") {
$zthis->MoveNext();
continue;
}
- if ($fieldsize > 1) {
+ if ($hasvalue) {
if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC) {
// Get 2nd field's value regardless of its name
- $zval2 = current(array_slice($zthis->fields, 1, 1));
+ $fields = array_slice($zthis->fields, 1);
+ $zval2 = current($fields);
+ if ($hasgroup) {
+ $group = trim(next($fields));
+ }
} else {
// With NUM or BOTH fetch modes, we have a numeric index
$zval2 = $zthis->fields[1];
+ if ($hasgroup) {
+ $group = trim($zthis->fields[2]);
+ }
}
$zval2 = trim($zval2);
+ $value = " value='".htmlspecialchars($zval2)."'";
}
- $selected = ($compareFields0) ? $zval : $zval2;
-
- $group = '';
-
- if (isset($myFields[2])) {
- $group = $myFields[2];
- }
+ $selected = $compareFields0 ? $zval : $zval2;
if ($optgroup != $group) {
$optgroup = $group;
if ($firstgroup) {
$firstgroup = false;
- $s .="\n<optgroup label='". htmlspecialchars($group) ."'>";
} else {
$s .="\n</optgroup>";
- $s .="\n<optgroup label='". htmlspecialchars($group) ."'>";
}
+ $s .="\n<optgroup label='". htmlspecialchars($group) ."'>";
}
- if ($hasvalue)
- $value = " value='".htmlspecialchars($zval2)."'";
-
if (is_array($defstr)) {
-
if (in_array($selected,$defstr))
$s .= "\n<option selected='selected'$value>".htmlspecialchars($zval).'</option>';
else