Exemple #1
0
function htmlFormElement($strName, $strType, $strValue, $strStyle, $strListQuery, $strMode = 'MODIFY', $strParentKey = NULL, $strTitle = "", $astrDefaults = array(), $astrAdditionalAttributes = '', $options = NULL)
{
    if ($astrAdditionalAttributes) {
        $astrAdditionalAttributes = " {$astrAdditionalAttributes}";
    }
    $strFormElement = '';
    $readOnly = $strMode == 'MODIFY' ? '' : ' readonly="readonly"';
    $disabled = $strMode == 'MODIFY' ? '' : ' disabled="disabled"';
    switch ($strType) {
        case 'TEXT':
            if (strstr($strStyle, 'hasDateRangePicker')) {
                $autocomplete = ' autocomplete="off"';
            } else {
                $autocomplete = '';
            }
            $strFormElement = "<input type=\"text\" class=\"{$strStyle}\"{$autocomplete} " . "id=\"{$strName}\" name=\"{$strName}\" value=\"" . htmlspecialchars($strValue) . "\"{$astrAdditionalAttributes}{$readOnly}>\n";
            break;
        case 'PASSWD':
            $strFormElement = "<input type=\"password\" class=\"{$strStyle}\" " . "id=\"{$strName}\" name=\"{$strName}\" value=\"\"{$astrAdditionalAttributes}{$readOnly}>\n";
            break;
        case 'CHECK':
            $strValue = $strValue ? 'checked' : '';
            $strFormElement = "<input type=\"checkbox\" id=\"{$strName}\" name=\"{$strName}\" value=\"1\" " . htmlspecialchars($strValue) . "{$astrAdditionalAttributes}{$disabled}>\n";
            break;
        case 'RADIO':
            $strChecked = $strValue ? 'checked' : '';
            $strFormElement = "<input type=\"radio\" id=\"{$strName}\" name=\"{$strName}\" value=\"" . htmlspecialchars($strValue) . "\"{$astrAdditionalAttributes}{$disabled}>\n";
            break;
        case 'INT':
            $hideZero = FALSE;
            if (strstr($strStyle, ' hidezerovalue')) {
                $strStyle = str_replace(' hidezerovalue', '', $strStyle);
                $hideZero = TRUE;
            }
            if ($hideZero && $strValue == 0) {
                $strValue = '';
            }
            $strFormElement = "<input type=\"text\" class=\"{$strStyle}\" " . "id=\"{$strName}\" name=\"{$strName}\" value=\"" . htmlspecialchars($strValue) . "\"{$astrAdditionalAttributes}{$readOnly}>\n";
            break;
        case 'INTDATE':
            $strFormElement = "<input type=\"text\" class=\"{$strStyle} hasCalendar\" " . "id=\"{$strName}\" name=\"{$strName}\" value=\"" . htmlspecialchars($strValue) . "\"{$astrAdditionalAttributes}{$readOnly}>\n";
            break;
        case 'HID_INT':
            $strFormElement = "<input type=\"hidden\" " . "id=\"{$strName}\" name=\"{$strName}\" value=\"" . htmlspecialchars($strValue) . "\">\n";
            break;
        case 'AREA':
            $strFormElement = "<textarea rows=\"24\" cols=\"80\" class=\"" . $strStyle . "\" " . "id=\"" . $strName . "\" name=\"" . $strName . "\"{$astrAdditionalAttributes}{$readOnly}>" . $strValue . "</textarea>\n";
            break;
        case 'RESULT':
            $strListQuery = str_replace("_ID_", $strValue, $strListQuery);
            $strFormElement = htmlspecialchars(mysqli_fetch_value(mysqli_query_check($strListQuery))) . "\n";
            break;
        case 'LIST':
            $translate = false;
            if (strstr($strStyle, ' translated')) {
                $translate = true;
                $strStyle = str_replace(' translated', '', $strStyle);
            }
            if ($strMode == "MODIFY") {
                $strFormElement = htmlSQLListBox($strName, $strListQuery, $strValue, $strStyle, false, $astrAdditionalAttributes, $translate);
            } else {
                $strFormElement = "<input type=\"text\" class=\"{$strStyle}\" " . "id=\"{$strName}\" name=\"{$strName}\" value=\"" . htmlspecialchars(getSQLListBoxSelectedValue($strListQuery, $strValue, $translate)) . "\"{$astrAdditionalAttributes}{$readOnly}>\n";
            }
            break;
        case 'SEARCHLIST':
            if ($strMode == "MODIFY") {
                $showEmpty = <<<EOT
      if (page == 1 && data.filter == '') {
        records.unshift({id: '', text: '-'});
      }

EOT;
                if (strstr($strStyle, ' noemptyvalue')) {
                    $strStyle = str_replace(' noemptyvalue', '', $strStyle);
                    $showEmpty = '';
                }
                $strValue = htmlspecialchars($strValue);
                $onchange = $astrAdditionalAttributes ? ".on(\"change\", {$astrAdditionalAttributes})" : '';
                $strFormElement = <<<EOT
<input type="hidden" class="{$strStyle}" id="{$strName}" name="{$strName}" value="{$strValue}"/>
<script type="text/javascript">
\$(document).ready(function() {
  \$("#{$strName}").select2({
    placeholder: "",
    ajax: {
      url: "json.php?func=get_selectlist&{$strListQuery}",
      dataType: 'json',
      quietMillis: 200,
      data: function (term, page) { // page is the one-based page number tracked by Select2
        return {
          q: term, //search term
          pagelen: 50, // page size
          page: page, // page number
        };
      },
      results: function (data, page) {
        var records = data.records;
  {$showEmpty}
        return {results: records, more: data.moreAvailable};
      }
    },
    initSelection: function(element, callback) {
      var id = \$(element).val();
      if (id !== "") {
        \$.ajax("json.php?func=get_selectlist&{$strListQuery}&id=" + id, {
          dataType: "json"
        }).done(function(data) { callback(data.records[0]); });
      }
    },
    dropdownCssClass: "bigdrop",
    dropdownAutoWidth: true,
    escapeMarkup: function (m) { return m; },
    width: "element"
  }){$onchange}
});
</script>
EOT;
            } else {
                $strFormElement = "<input type=\"text\" class=\"{$strStyle}\" " . "id=\"{$strName}\" name=\"{$strName}\" value=\"" . htmlspecialchars(getSQLListBoxSelectedValue($strListQuery, $strValue, $translate)) . "\"{$astrAdditionalAttributes}{$readOnly}>\n";
            }
            break;
        case 'SELECT':
            $translate = false;
            if (strstr($strStyle, ' translated')) {
                $translate = true;
                $strStyle = str_replace(' translated', '', $strStyle);
            }
            if ($strMode == "MODIFY") {
                $strFormElement = htmlListBox($strName, $options, $strValue, $strStyle, false, $astrAdditionalAttributes, $translate);
            } else {
                $strFormElement = "<input type=\"text\" class=\"{$strStyle}\" " . "id=\"{$strName}\" name=\"{$strName}\" value=\"" . htmlspecialchars(getListBoxSelectedValue($options, $strValue, $translate)) . "\"{$astrAdditionalAttributes}{$readOnly}>\n";
            }
            break;
        case 'BUTTON':
            $strListQuery = str_replace("_ID_", $strValue, $strListQuery);
            switch ($strStyle) {
                case 'custom':
                    $strListQuery = str_replace("'", "", $strListQuery);
                    $strHref = $strListQuery;
                    $strOnClick = "";
                    break;
                case 'redirect':
                    $strHref = "#";
                    $strOnClick = "onclick=\"save_record('{$strListQuery}', 'redirect'); return false;\"";
                    break;
                case 'openwindow':
                    $strHref = "#";
                    $strOnClick = "onclick=\"save_record('{$strListQuery}', 'openwindow'); return false;\"";
                    break;
                default:
                    switch ($strStyle) {
                        case 'tiny':
                            $strHW = "height=1,width=1,";
                            break;
                        case 'small':
                            $strHW = "height=200,width=200,";
                            break;
                        case 'medium':
                            $strHW = "height=400,width=400,";
                            break;
                        case 'large':
                            $strHW = "height=600,width=600,";
                            break;
                        case 'xlarge':
                            $strHW = "height=800,width=650,";
                            break;
                        case 'full':
                            $strHW = "";
                            break;
                        default:
                            $strHW = "";
                            break;
                    }
                    $strHref = "#";
                    $strOnClick = "onclick=\"window.open(" . $strListQuery . ",'" . $strHW . "menubar=no,scrollbars=no," . "status=no,toolbar=no'); return false;\"";
                    break;
            }
            $strFormElement = "<a class=\"formbuttonlink\" href=\"{$strHref}\" {$strOnClick}{$astrAdditionalAttributes}>" . htmlspecialchars($strTitle) . "</a>\n";
            break;
        case 'JSBUTTON':
            if (strstr($strListQuery, '_ID_') && !$strValue) {
                $strFormElement = $GLOBALS['locSaveFirst'];
            } else {
                if ($strValue) {
                    $strListQuery = str_replace('_ID_', $strValue, $strListQuery);
                }
                $strOnClick = "onClick=\"{$strListQuery}\"";
                $strFormElement = "<a class=\"formbuttonlink\" href=\"#\" {$strOnClick}{$astrAdditionalAttributes}>" . htmlspecialchars($strTitle) . "</a>\n";
            }
            break;
        case 'IMAGE':
            $strListQuery = str_replace("_ID_", $strValue, $strListQuery);
            $strFormElement = "<img class=\"{$strStyle}\" src=\"{$strListQuery}\" title=\"" . htmlspecialchars($strTitle) . "\"></div>\n";
            break;
        default:
            $strFormElement = "&nbsp;\n";
    }
    return $strFormElement;
}
Exemple #2
0
            echo $strOperator;
            ?>
  </td>
						</tr>
<?php 
        }
        ?>
<tr class="search_row">
							<td class="label">
    <?php 
        echo $astrFormElements[$j]['label'];
        ?>
  </td>
							<td class="field">
    <?php 
        echo htmlListBox('searchmatch_' . $astrFormElements[$j]['name'], $comparisonValues, $strSearchMatch, '', 0);
        ?>
  </td>
							<td class="field">
    <?php 
        echo htmlFormElement($astrFormElements[$j]['name'], $astrFormElements[$j]['type'], $astrValues[$astrFormElements[$j]['name']], $astrFormElements[$j]['style'], $astrFormElements[$j]['listquery'], 'MODIFY', $astrFormElements[$j]['parent_key'], '', [], '', isset($astrFormElements[$j]['options']) ? $astrFormElements[$j]['options'] : NULL);
        ?>
  </td>
							<td><input type="hidden"
								name="delete_<?php 
        echo $astrFormElements[$j]['name'];
        ?>
_x"
								value="0"> <a class="tinyactionlink" href="#"
								title="<?php 
        echo $GLOBALS['locDelRow'];