Location: PHPKode > scripts > phpMyAccess > phpmyaccess-1.5.3/phpmyaccess/pma-fieldinc.php
<?php

// should we use these vars and set them for different languages ?
// $yeartxt  = "year";
// $monthtxt = "month";
// $daytxt   = "day";


/*
 Use defined defaults for calculating start/end/number of years, if given
 If
*/
function CheckYear($field) {
  if (!$GLOBALS['fdd'][$field]['yearstart']) {
     $GLOBALS['opt']['ystart'] = $GLOBALS['opt']['ydefault'];
  } else {
     $GLOBALS['opt']['ystart'] = $GLOBALS['fdd'][$field]['yearstart'];
  }
  if (!$GLOBALS['fdd'][$field]['yearend']) {
     $GLOBALS['opt']['yend'] = $GLOBALS['opt']['ystart']+$GLOBALS['opt']['ydefnum'];
  } else {
     $GLOBALS['opt']['yend'] = $GLOBALS['fdd'][$field]['yearend'];
  }
  if ($yend <= $ystart) {
     $GLOBALS['opt']['yend'] = $GLOBALS['opt']['ystart'] + $GLOBALS['opt']['ydefnum'];
  }
}

function DoDatefieldEdit($field, $rowfld) {
  CheckYear($field);
  // get the year / month /day from table
  // assumes default yyyy-mm-dd format
  if ($rowfld) {
     list($ymod, $mmod, $dmod) = explode("-",$rowfld);
  }
  // select year
  $tmp .=  "    <!--// DoDatefieldEdit //--!>\n";
  $tmp .=  '    <td><Select name="' . $field . "year" .'" size="1">'."\n";
  $tmp .=  '           <option value="0000">0000</option>'."\n";
  for ($l=$GLOBALS['opt']['ystart']; $l <= $GLOBALS['opt']['yend']; $l++) {
      $tmp .=  '              <option value="' . $l . '" ' ;
      if ($l == $ymod) {
        $tmp .=  ' selected';
      }
      $tmp .=  ' >' . $l .'</option>'."\n";
  }
  $tmp .=  '        </select>'."\n";
  // select month
  $tmp .=  '    <select name="' . $field . "month" . '" size="1">'."\n";
  $tmp .=  '           <option value="00">00</option>'."\n";
  for ($l=1; $l<=12; $l++) {
     $tmp .=  '              <option value="' . $l . '" ';
     if ($l == $mmod) {
        $tmp .=  'selected';
     }
     $tmp .=  ' >' . $l .'</option>'."\n";
  }
  $tmp .=  '        </select>'."\n";
  // select day
  $tmp .=  '    <select name="' . $field . "day" . '" size="1">'."\n";
  $tmp .=  '           <option value="00">00</option>'."\n";
  for ($l=1; $l<=31; $l++) {
     $tmp .=  '              <option value="' . $l . '" ';
     if ($l == $dmod) {
        $tmp .=  'selected';
     }
     $tmp .=  ' >' . $l .'</option>'."\n";
  }
  $tmp .=  '        </select></td>'."\n";
  return $tmp;
}

function DoRangeCheck($field) {
  // trick with positive/negative/non-integer number ranges and steps
  // are not really covered, one assumes the application builder takes care
  if (!$GLOBALS['fdd'][$field]['rangestart']) {
     $GLOBALS['opt']['rstart'] = $GLOBALS['opt']['rdefstart'];
  } else {
     $GLOBALS['opt']['rstart'] = $GLOBALS['fdd'][$field]['rangestart'];
  }
  if (!$GLOBALS['fdd'][$field]['rangestep']) {
     $GLOBALS['opt']['rstep'] = $GLOBALS['opt']['rdefstep'];
  } else {
     $GLOBALS['opt']['rstep'] = $GLOBALS['fdd'][$field]['rangestep'];
  }
  if (!$GLOBALS['fdd'][$field]['rangesteps']) {
     $GLOBALS['opt']['rnosteps'] = $GLOBALS['opt']['rdefnosteps'];
  } else {
     $GLOBALS['opt']['rnosteps'] = $GLOBALS['fdd'][$field]['rangesteps'];
  }
  if ($GLOBALS['opt']['rnosteps'] < 1 ) {
     $GLOBALS['opt']['rnosteps'] = $GLOBALS['opt']['rdefsteps'];
  }
}

function DoRangeEdit($field,$rowfld) {
  DoRangeCheck($field);
  $rmod = $GLOBALS['opt']['rstart'];
  $tmp .=  "    <!--// DoRangeEdit //--!>\n";
  $tmp .=  '    <td><Select name="' . $field . '" size="1">'."\n";
  $tmp .=  '           <option value="0">0</option>'."\n";
  for ($l=1; $l <= $GLOBALS['opt']['rnosteps']; $l++) {
     $tmp .=  '              <option value="' . $rmod . '" ' ;
     if ($rmod==$rowfld) {
        $tmp .=  ' selected';
     }
     $tmp .=  ' >' . $rmod .'</option>'."\n";
     $rmod += $GLOBALS['opt']['rstep'];
  }
  $tmp .=  '        </select>'."\n";
  return $tmp;
}

function DoStaticRangeEdit($field, $rowfld) {
   $tmp .=  "    <!--// DoStaticRangeEdit //--!>\n";
   $tmp .=  '    <td><select name="'.$field.'" size="1">'."\n";
   for ($l=0; $l<count($GLOBALS['fdd'][$field]['values']); $l++) {
      if ($GLOBALS['fdd'][$field]['values'][$l] == $rowfld) {
         $w = ' selected';
      } else {
         $w = '';
      }
      $tmp .=  '          <option'.$w.'>'.$GLOBALS['fdd'][$field]['values'][$l].'</option>'."\n";
   }
   $tmp .=  "        </select></td>"."\n";
   return $tmp;
}

function DoTextBlockEdit($field, $rowfld) {
   $tmp .=  "    <!--// DoTextBlockEdit //--!>\n";
//  Textarea block
   $tmp .=  '    <td><textarea ';
   if (isset($GLOBALS['fdd'][$field]['textarea']['rows'])) {
      $tmp .=  'rows="'.$GLOBALS['fdd'][$field]['textarea']['rows'].'" ';
   }
   if (isset($GLOBALS['fdd'][$field]['textarea']['cols'])) {
      $tmp .=  'cols="'.$GLOBALS['fdd'][$field]['textarea']['cols'].'" ';
   }
   $tmp .=  'name="'.$field.'">'.htmlentities($rowfld).'</textarea></td>'."\n";
   return $tmp;
}

function SetLinkOpt($field, $select=1) {
// set some globals that make the table dropdowns and stuff look less messy
  if (isset($GLOBALS['fdd'][$field]['values']['table'])) {
     $GLOBALS['opt']['ttable'] =  $GLOBALS['fdd'][$field]['values']['table'];
     $GLOBALS['opt']['tcolumn'] =  $GLOBALS['fdd'][$field]['values']['column'];
     if ($GLOBALS['fdd'][$field]['values']['selectview'] && $select) {
        $GLOBALS['opt']['tview'] = $GLOBALS['fdd'][$field]['values']['selectview'];
     } else if ($GLOBALS['fdd'][$field]['values']['description']) {
         $GLOBALS['opt']['tview'] = $GLOBALS['fdd'][$field]['values']['description'];
     } else {
         unset ($GLOBALS['opt']['tview']);
      }
  } else {
     unset($GLOBALS['opt']['ttable']);
     unset($GLOBALS['opt']['tcolumn']);
  }
}

function DoLinkTableDisp ($field, $deflt) {
  $tmp .=  "    <!--// DoLinkTableDisp =$deflt= //--!>\n";
  $tmp .=  "    <td><select name=\"".$field.'" size="1">'."\n";
  $x=set_values_from_table($GLOBALS['opt']['db'],$GLOBALS['opt']['ttable'],$GLOBALS['opt']['tcolumn'],$GLOBALS['opt']['tview']);
  for ($l=0; $l<count($x['option']); $l++) {
    $tmp .=  '          <option ';
    if ($x['option'][$l]==$deflt) {
        $tmp .=  " selected='selected' ";
    }
    $tmp .=  'value="'. $x['option'][$l] . '">' . $x['value'][$l] . '</option>' . "\n";
  }
  $tmp .=  '        </select></td>'."\n";
  return $tmp;
}

function DoLinkTable ($field, $deflt) {
  $tmp .=  "    <!--// DoLinkTable //--!>\n";
  $tmp .=  '    <td><select name="'.$field.'" size="1">'."\n";
  $x=set_values_from_table($GLOBALS['opt']['db'],$GLOBALS['opt']['ttable'], $GLOBALS['opt']['tcolumn']);
    for ($l=0; $l<count($x['option']); $l++) {
    $tmp .=  '          <option'.$x['option'][$l].'</option>'."\n";
  }
  $tmp .=  '        </select></td>'."\n";
  return $tmp;
}

function DoLinkedVal($field, $rowfld) {
  $tmp .=  "    <!--// DoLinkedVal //--!>\n";
  $ltable = $GLOBALS['fdd'][$field]['values']['table'];
  $lsel = $GLOBALS['fdd'][$field]['values']['description'];
  $lkey = $GLOBALS['fdd'][$field]['values']['column'];
  // may have to revisit this, as numerical fields don't seem to like ""
  // Not likely to happen really,  but it could
  $lval = '"' .$rowfld . '"';
  $linkval = get_linked_val($GLOBALS['opt']['db'],$ltable,$lsel,$lkey,$lval);
  $tmp .=  '  <input type="hidden" name="'.$field. '" value="'.nl2br(htmlentities($rowfld)).'" />'."\n";
  $tmp .=  '    <td> '.htmlentities($linkval).' </td>'."\n";
  return $tmp;
}

function DoTableSelectIndirect($field, $rowfld) {
  $tmp .=  "    <!--// DoTableSelectIndirect //--!>\n";
  $tmp .=  '    <td><select name="'.$field.'" size="1">'."\n";
  $x=set_values_from_table($GLOBALS['opt']['db'],$GLOBALS['opt']['ttable'],$GLOBALS['opt']['tcolumn'],$GLOBALS['opt']['tview']);
  for ($l=0; $l<count($x['option']); $l++) {
     if ($x['option'][$l] == $rowfld) {
        $w = ' selected';
     } else {
        $w = '';
     }
     $tmp .=  '          <option'.$w.' value="'.$x['option'][$l].'">'.$x['value'][$l].'</option>'."\n";
  }
  $tmp .=  '        </select></td>'."\n";
  return $tmp;
}

function DoDistinctTableFieldSelect($col, $tb, $curval) {
  $tmp .=  "    <!--// DoDistinctFieldSelect //--!>\n";
  $tmp .=  '    <td><select name="'.$col.'" size="1">'."\n";
  $x=get_distinct_values_sorted_from_table($GLOBALS['opt']['db'],$tb,$col);
  for ($l=0; $l<count($x); $l++) {
     if ($x[$l] == $curval) {
        $w = ' selected';
     } else {
        $w = '';
     }
     $tmp .=  '          <option'.$w.' value="'.$x[$l].'">'.$x[$l].'</option>'."\n";
  }
  $tmp .=  '        </select>Enter New value here: '."\n";
  if (isset($GLOBALS['fdd'][$col]['length'])) {
     $fwidth = $GLOBALS['fdd'][$col]['length'];
     $fdispwidth = $fwidth;
     if ($fdispwidth > $GLOBALS['opt']['maxdisp']) {
        $fdispwidth = $GLOBALS['opt']['maxdisp'];
     }
     $tmp .=  '    <input type="text" size="' . $fdispwidth . '" maxlength="' . $fwidth .
                      '" name="'.$col.'_new" value="" /></td>'."\n";
  } else {
     $tmp .=  '    <input type="text" name="'.$col.'_new" value="" /></td>'."\n";
  }
  return $tmp;
}

function DoBooleanEdit($field, $rowfld) {
  $tmp .=  "    <!--// DoBooleanEdit //--!>\n";
  $tmp .=  '    <td><input type="checkbox" name="'.$field . '" value="1" ';
  if ($rowfld) {
     $tmp .=  " checked";
  }
  $tmp .=  "></td>\n";
  return $tmp;
}

function DoBooleanSelectDropDown($field, $value) {
  $tmp= '    <td><select name="'. $field .'">'."\n";
  if ($value == '0') {
      $tmp .= "      <option value=\"\"></option>\n";
      $tmp .= "      <option value=\"1\">" . $GLOBALS['opt']['booltrue'] ."</option>\n";
      $tmp .= "      <option selected value=\"0\">" . $GLOBALS['opt']['boolfalse'] ."</option>\n";
  } elseif ($value == '1') {
      $tmp .= "      <option value=\"\"></option>\n";
      $tmp .= "      <option selected value=\"1\">" . $GLOBALS['opt']['booltrue'] ."</option>\n";
      $tmp .= "      <option value=\"0\">" . $GLOBALS['opt']['boolfalse'] ."</option>\n";
  } else {
      $tmp .= "      <option selected value=\"\"></option>\n";
      $tmp .= "      <option value=\"1\">" . $GLOBALS['opt']['booltrue'] ."</option>\n";
      $tmp .= "      <option value=\"0\">" . $GLOBALS['opt']['boolfalse'] ."</option>\n";
  }
  $tmp .= "    </select></td>"."\n";
  return $tmp;
}

function DoSearchTextField($field, $value, $maxlength) {
  $tmp  = '      <td><input type="text" name="'.$field.'"';
  $tmp .= ' value="'.$value.'"';
  if ($GLOBALS['opt']['SearchFieldSize'] > $maxlength) {
      $tmp .= ' size="' .$maxlength. '" maxlength="'.$maxlength.'" /></td>'."\n";
  } else {
      $tmp .= ' size="' .$GLOBALS['opt']['SearchFieldSize']. '" maxlength="'.$maxlength.'" /></td>'."\n";
  }
  return $tmp;
}

function DoTableSelectDirect($field, $rowfld) {
  $tmp .=  "    <!--// DoTableSelectDirect //--!>\n";
  $tmp .=  '    <td><select name="'.$field.'" size="1">'."\n";
  $x=set_values_from_table($GLOBALS['opt']['db'],$GLOBALS['opt']['ttable'],$GLOBALS['opt']['tcolumn']);
  for ($l=0; $l<count($x['option']); $l++) {
     if ($x['option'][$l] == $rowfld) {
        $w = ' selected';
     } else {
        $w = '';
     }
     $tmp .=  '          <option'.$w.'>'.$x['option'][$l].'</option>'."\n";
  }
  $tmp .=  '        </select></td>'."\n";
  return $tmp;
}

function DoNotEditable($field, $rowfld) {
   $tmp .=  "    <!--// DoNotEditable //--!>\n";
   if (isset($GLOBALS['opt']['ttable']) and isset($GLOBALS['opt']['tcolumn']) and isset($GLOBALS['opt']['tview'])) {
      $tmpval = get_table_val($GLOBALS['opt']['db'], $GLOBALS['opt']['ttable'], $GLOBALS['opt']['tcolumn'], $GLOBALS['opt']['tview'], $rowfld);
      $tmp .=  '  <input type="hidden" name="'.$field.'" value="'.$tmpval.'" />'."\n";
      $tmp .=  '    <td> '. $tmpval .' </td>'."\n";
   } else {
      $tmp .=  '    <td> '.htmlentities($rowfld).' </td>'."\n";
      $tmp .=  '  <input type="hidden" name="'.$field. '" value="'.nl2br(htmlentities($rowfld)).'" />'."\n";
   }
   return $tmp;
}

?>
Return current item: phpMyAccess