PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/output/classes/controls/CheckboxField.php

https://gitlab.com/Lidbary/PHPRunner
PHP | 132 lines | 97 code | 25 blank | 10 comment | 72 complexity | 8eac3537f625d71217137b86fe656d66 MD5 | raw file
  1. <?php
  2. class CheckboxField extends EditControl
  3. {
  4. function CheckboxField($field, $pageObject, $id, $connection)
  5. {
  6. parent::EditControl($field, $pageObject, $id, $connection);
  7. $this->format = EDIT_FORMAT_CHECKBOX;
  8. }
  9. function buildControl($value, $mode, $fieldNum, $validate, $additionalCtrlParams, $data)
  10. {
  11. parent::buildControl($value, $mode, $fieldNum, $validate, $additionalCtrlParams, $data);
  12. if($mode == MODE_ADD || $mode == MODE_INLINE_ADD || $mode == MODE_EDIT || $mode == MODE_INLINE_EDIT)
  13. {
  14. $checked = "";
  15. if( $this->connection->dbType == nDATABASE_PostgreSQL && ($value === "t" || $value != "" && $value != 0 ) || $this->connection->dbType != nDATABASE_PostgreSQL && ($value != "" && $value != 0 ))
  16. $checked=" checked";
  17. echo '<input id="'.$this->ctype.'" type="hidden" name="'.$this->ctype.'" value="checkbox">';
  18. echo '<input id="'.$this->cfield.'" type="Checkbox" '
  19. .(($mode == MODE_INLINE_EDIT || $mode == MODE_INLINE_ADD) && $this->is508==true ? 'alt="'.$this->strLabel.'" ' : '')
  20. .'name="'.$this->cfield.'" '.$checked.'>';
  21. }
  22. else
  23. {
  24. echo '<input id="'.$this->ctype.'" type="hidden" name="'.$this->ctype.'" value="checkbox">';
  25. echo '<select id="'.$this->cfield.'" '.(($mode == MODE_INLINE_EDIT || $mode == MODE_INLINE_ADD) && $this->is508==true ? 'alt="'
  26. .$this->strLabel.'" ' : '').'name="'.$this->cfield.'">';
  27. $val = array( "" => array(), "True" => array("on", "1"), "False" => array("off", "0") );
  28. $optval = array("", "on", "off");
  29. $show = array("", "True", "False");
  30. foreach($show as $key => $shownValue)
  31. {
  32. $sel = in_array( $value, $val[ $shownValue] ) ? " selected" : "";
  33. echo '<option value="'.$optval[$key].'"'.$sel.'>'.$shownValue.'</option>';
  34. }
  35. echo "</select>";
  36. }
  37. $this->buildControlEnd($validate);
  38. }
  39. function SQLWhere($SearchFor, $strSearchOption, $SearchFor2, $etype, $isSuggest)
  40. {
  41. $baseResult = $this->baseSQLWhere($strSearchOption);
  42. if($baseResult === false)
  43. return "";
  44. if($baseResult != "")
  45. return $baseResult;
  46. if($SearchFor == "none" || $SearchFor != "on" && $SearchFor != "off")
  47. return "";
  48. $fullFieldName = $this->getFieldSQLDecrypt();
  49. $bNeedQuotes = NeedQuotes($this->type);
  50. return CheckboxField::constructFieldWhere($fullFieldName, $bNeedQuotes, $SearchFor == "on", $this->type, $this->connection->dbType);
  51. }
  52. /**
  53. * Get the WHERE clause condition for the checkbox field basing on
  54. * the field and the database type.
  55. * @param String fullFieldName
  56. * @param Boolean strNeedQuotes
  57. * @param Boolean checked The flag indicating if the condition is
  58. * @param Number fieldType
  59. * @param Number dbType
  60. * designed to search checked values or not
  61. */
  62. static function constructFieldWhere($fullFieldName, $bNeedQuotes, $checked, $fieldType, $dbType)
  63. {
  64. if($bNeedQuotes)
  65. {
  66. if($checked)
  67. {
  68. $whereStr = "(".$fullFieldName."<>'0' ";
  69. if( $dbType != nDATABASE_Oracle )
  70. $whereStr .= " and ".$fullFieldName."<>'' ";
  71. $whereStr .= " and ".$fullFieldName." is not null)";
  72. if( $dbType == nDATABASE_Oracle )
  73. $whereStr .= " and abs(case when LENGTH(TRIM(TRANSLATE(".$fullFieldName.", ' +-.0123456789', ' '))) is null then cast(".$fullFieldName." as integer) else 0 end) > 0";
  74. if( $dbType == nDATABASE_MSSQLServer )
  75. $whereStr .= " and ABS(case WHEN ISNUMERIC(".$fullFieldName.") = 1 THEN convert(integer, ".$fullFieldName.") else 0 end) > 0";
  76. if( $dbType == nDATABASE_MySQL )
  77. $whereStr .= " and abs(cast(".$fullFieldName." as signed)) > 0";
  78. if( $dbType == nDATABASE_PostgreSQL )
  79. $whereStr .= " and abs(case textregexeq(".$fullFieldName.", '^(\-)?[[:digit:]]+(\.[[:digit:]]+)?$') when true then to_number(".$fullFieldName.", '999999999') else 0 end) > 0";
  80. return $whereStr;
  81. }
  82. $whereStr = "(".$fullFieldName."='0' ";
  83. if( $dbType != nDATABASE_Oracle )
  84. $whereStr .= " or ".$fullFieldName."='' ";
  85. $whereStr .= " or ".$fullFieldName." is null)";
  86. if( $dbType == nDATABASE_Oracle )
  87. $whereStr .= " or abs(case when LENGTH(TRIM(TRANSLATE(".$fullFieldName.", ' +-.0123456789', ' '))) is null then cast(".$fullFieldName." as integer) else 0 end) = 0";
  88. if( $dbType == nDATABASE_MSSQLServer )
  89. $whereStr .= " or ABS(case WHEN ISNUMERIC(".$fullFieldName.") = 1 THEN convert(integer, ".$fullFieldName.") else 0 end) = 0";
  90. if( $dbType == nDATABASE_MySQL )
  91. $whereStr .= " or cast(".$fullFieldName." as unsigned) = 0";
  92. if( $dbType == nDATABASE_PostgreSQL )
  93. $whereStr .= " or abs(case textregexeq(".$fullFieldName.", '^(\-)?[[:digit:]]+(\.[[:digit:]]+)?$') when true then to_number(".$fullFieldName.", '999999999') else 0 end) = 0";
  94. return $whereStr;
  95. }
  96. $falseval = 0;
  97. if( $dbType == nDATABASE_PostgreSQL )
  98. {
  99. if ($fieldType == 11)
  100. $falseval = 'false';
  101. }
  102. if($checked)
  103. return "(".$fullFieldName."<>".$falseval." and ".$fullFieldName." is not null)";
  104. return "(".$fullFieldName."=".$falseval." or ".$fullFieldName." is null)";
  105. }
  106. }
  107. ?>