You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

170 lines
4.3 KiB

  1. <?php
  2. if (!defined('IN_CB')) { die('You are not allowed to access to this page.'); }
  3. $imageKeys = array();
  4. function registerImageKey($key, $value) {
  5. global $imageKeys;
  6. $imageKeys[$key] = $value;
  7. }
  8. function getImageKeys() {
  9. global $imageKeys;
  10. return $imageKeys;
  11. }
  12. function getElementHtml($tag, $attributes, $content = false) {
  13. $code = '<' . $tag;
  14. foreach ($attributes as $attribute => $value) {
  15. $code .= ' ' . $attribute . '="' . htmlentities(stripslashes($value), ENT_COMPAT) . '"';
  16. }
  17. if ($content === false || $content === null) {
  18. $code .= ' />';
  19. } else {
  20. $code .= '>' . $content . '</' . $tag . '>';
  21. }
  22. return $code;
  23. }
  24. function getInputTextHtml($name, $currentValue, $attributes = array()) {
  25. $defaultAttributes = array(
  26. 'id' => $name,
  27. 'name' => $name
  28. );
  29. $finalAttributes = array_merge($defaultAttributes, $attributes);
  30. if ($currentValue !== null) {
  31. $finalAttributes['value'] = $currentValue;
  32. }
  33. return getElementHtml('input', $finalAttributes, false);
  34. }
  35. function getOptionGroup($options, $currentValue) {
  36. $content = '';
  37. foreach ($options as $optionKey => $optionValue) {
  38. if (is_array($optionValue)) {
  39. $content .= '<optgroup label="' . $optionKey . '">' . getOptionGroup($optionValue, $currentValue) . '</optgroup>';
  40. } else {
  41. $optionAttributes = array();
  42. if ($currentValue == $optionKey) {
  43. $optionAttributes['selected'] = 'selected';
  44. }
  45. $content .= getOptionHtml($optionKey, $optionValue, $optionAttributes);
  46. }
  47. }
  48. return $content;
  49. }
  50. function getOptionHtml($value, $content, $attributes = array()) {
  51. $defaultAttributes = array(
  52. 'value' => $value
  53. );
  54. $finalAttributes = array_merge($defaultAttributes, $attributes);
  55. return getElementHtml('option', $finalAttributes, $content);
  56. }
  57. function getSelectHtml($name, $currentValue, $options, $attributes = array()) {
  58. $defaultAttributes = array(
  59. 'size' => 1,
  60. 'id' => $name,
  61. 'name' => $name
  62. );
  63. $finalAttributes = array_merge($defaultAttributes, $attributes);
  64. $content = getOptionGroup($options, $currentValue);
  65. return getElementHtml('select', $finalAttributes, $content);
  66. }
  67. function getCheckboxHtml($name, $currentValue, $attributes = array()) {
  68. $defaultAttributes = array(
  69. 'type' => 'checkbox',
  70. 'id' => $name,
  71. 'name' => $name,
  72. 'value' => isset($attributes['value']) ? $attributes['value'] : 'On'
  73. );
  74. $finalAttributes = array_merge($defaultAttributes, $attributes);
  75. if ($currentValue == $finalAttributes['value']) {
  76. $finalAttributes['checked'] = 'checked';
  77. }
  78. return getElementHtml('input', $finalAttributes, false);
  79. }
  80. function getButton($value, $output = null) {
  81. $escaped = false;
  82. $finalValue = $value[0] === '&' ? $value : htmlentities($value);
  83. if ($output === null) {
  84. $output = $value;
  85. } else {
  86. $escaped = true;
  87. }
  88. $code = '<input type="button" value="' . $finalValue . '" data-output="' . $output . '"' . ($escaped ? ' data-escaped="true"' : '') . ' />';
  89. return $code;
  90. }
  91. /**
  92. * Returns the fonts available for drawing.
  93. *
  94. * @return string[]
  95. */
  96. function listfonts($folder) {
  97. $array = array();
  98. if (($handle = opendir($folder)) !== false) {
  99. while (($file = readdir($handle)) !== false) {
  100. if(substr($file, -4, 4) === '.ttf') {
  101. $array[$file] = $file;
  102. }
  103. }
  104. }
  105. closedir($handle);
  106. array_unshift($array, 'No Label');
  107. return $array;
  108. }
  109. /**
  110. * Returns the barcodes present for drawing.
  111. *
  112. * @return string[]
  113. */
  114. function listbarcodes() {
  115. include_once('barcode.php');
  116. $availableBarcodes = array();
  117. foreach ($supportedBarcodes as $file => $title) {
  118. if (file_exists($file)) {
  119. $availableBarcodes[$file] = $title;
  120. }
  121. }
  122. return $availableBarcodes;
  123. }
  124. function findValueFromKey($haystack, $needle) {
  125. foreach ($haystack as $key => $value) {
  126. if (strcasecmp($key, $needle) === 0) {
  127. return $value;
  128. }
  129. }
  130. return null;
  131. }
  132. function convertText($text) {
  133. $text = stripslashes($text);
  134. if (function_exists('mb_convert_encoding')) {
  135. $text = mb_convert_encoding($text, 'ISO-8859-1', 'UTF-8');
  136. }
  137. return $text;
  138. }
  139. ?>