publiclib.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. use HtmlBuilder\HtmlElement as Html;
  3. class Connection {
  4. private function __construct() {
  5. }
  6. public static function open($connection_info = null) {
  7. $user = isset($connection_info['user']) ? $connection_info['user'] : NULL;
  8. $pass = isset($connection_info['pass']) ? $connection_info['pass'] : NULL;
  9. $name = isset($connection_info['name']) ? $connection_info['name'] : NULL;
  10. $host = isset($connection_info['host']) ? $connection_info['host'] : NULL;
  11. $driver = isset($connection_info['driver']) ? $connection_info['driver'] : NULL;
  12. $port = isset($connection_info['port']) ? $connection_info['port'] : NULL;
  13. $prefix = isset($connection_info['prefix']) ? $connection_info['prefix'] : '';
  14. switch ($driver) {
  15. case 'pgsql':
  16. $port = $port ? $port : '5432';
  17. $conn = new PDO("pgsql:dbname={$name}; user={$user}; password={$pass};host=$host;port={$port}");
  18. break;
  19. case 'mysql':
  20. $port = $port ? $port : '3306';
  21. $conn = new PDO("mysql:host={$host};port={$port};dbname={$name}", $user, $pass);
  22. break;
  23. case 'sqlite':
  24. $conn = new PDO("sqlite:{$name}");
  25. break;
  26. case 'ibase':
  27. $conn = new PDO("firebird:dbname={$name}", $user, $pass);
  28. break;
  29. case 'oci8':
  30. $conn = new PDO("oci:dbname={$name}", $user, $pass);
  31. break;
  32. case 'mssql':
  33. $conn = new PDO("mssql:host={$host},1433;dbname={$name}", $user, $pass);
  34. break;
  35. }
  36. $conn->prefix = $prefix;
  37. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  38. return $conn;
  39. }
  40. }
  41. function is_ajax_request() {
  42. if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
  43. return true;
  44. } else {
  45. return false;
  46. }
  47. }
  48. function build_input_wrap($label, $element) {
  49. return Html::instance('div')
  50. ->add_property('class', 'form-group col-xs-12')
  51. ->add_child(Html::instance('label')->content($label))
  52. ->add_child($element);
  53. }
  54. function build_input_text($label, $name, $value = '') {
  55. return Html::instance('div')
  56. ->add_property('class', 'form-group col-xs-12')
  57. ->add_child(Html::instance('label')->content($label))
  58. ->add_child(Html::instance('input')
  59. ->add_property('type', 'text')
  60. ->add_property('name', $name)
  61. ->add_property('value', $value)
  62. ->add_property('class', 'form-control'));
  63. }
  64. function build_input_password($label, $name) {
  65. return Html::instance('div')
  66. ->add_property('class', 'form-group col-xs-12')
  67. ->add_child(Html::instance('label')->content($label))
  68. ->add_child(Html::instance('input')
  69. ->add_property('type', 'password')
  70. ->add_property('name', $name)
  71. ->add_property('class', 'form-control'));
  72. }
  73. function build_select($name, $values, $selected = '') {
  74. $select = Html::instance('select')
  75. ->add_property('class', 'form-control')
  76. ->add_property('name', $name);
  77. if ($selected == '') {
  78. $select->add_child(
  79. Html::instance('option')
  80. ->add_property('value', '0')
  81. ->content('Selecione')
  82. ->add_property('selected', 'selected')
  83. );
  84. } else {
  85. $select->add_child(
  86. Html::instance('option')
  87. ->add_property('value', '0')
  88. ->content('Selecione')
  89. );
  90. }
  91. foreach ($values as $value) {
  92. if ($value->id == $selected) {
  93. $select->add_child(
  94. Html::instance('option')
  95. ->add_property('value', $value->id)
  96. ->content($value->content)
  97. ->add_property('selected', 'selected')
  98. );
  99. } else {
  100. $select->add_child(
  101. Html::instance('option')
  102. ->add_property('value', $value->id)
  103. ->content($value->content)
  104. );
  105. }
  106. }
  107. return $select;
  108. }
  109. function build_remote_popup($relay = '', $action = '', $name = '', $label = '', $value = false) {
  110. $label = Html::instance('label')->content($label);
  111. $first_section = Html::instance('div')->add_property('class', 'col-xs-12 col-md-3');
  112. $first_section_input = Html::instance('div')->add_property('class', 'input-group');
  113. if($value){
  114. $first_section_input->add_child(Html::instance('input')
  115. ->add_property('class', 'form-control remote-popup-number')
  116. ->add_property('value', $value));
  117. }else{
  118. $first_section_input->add_child(Html::instance('input')
  119. ->add_property('class', 'form-control remote-popup-number'));
  120. }
  121. $button_input = Html::instance('span')
  122. ->add_property('class', 'input-group-btn')
  123. ->add_child(Html::instance('button')
  124. ->add_property('class', 'btn btn-default')
  125. ->add_child(Html::instance('i')
  126. ->add_property('class', 'fa fa-search')));
  127. $first_section_input->add_child($button_input);
  128. $first_section->add_child($first_section_input);
  129. $second_section = Html::instance('div')
  130. ->add_property('class', 'col-xs-12 col-md-9')
  131. ->add_child(Html::instance('input')
  132. ->add_property('class', 'form-control remote-popup-label')
  133. ->add_property('type', 'text')
  134. ->add_property('disabled', 'true'));
  135. $wrapper = Html::instance('div')
  136. ->add_property('class', 'form-group col-xs-12 remote-popup')
  137. ->add_property('data-relay', $relay)
  138. ->add_property('data-mode', $action)
  139. ->add_child($label)
  140. ->add_child(Html::instance('br'))
  141. ->add_child($first_section)
  142. ->add_child($second_section);
  143. return $wrapper->build();
  144. }
  145. function last_class() {
  146. $class = get_declared_classes()[sizeof(get_declared_classes()) - 1];
  147. return new $class;
  148. }
  149. global $_LANG;
  150. $_LANG = Array();
  151. class Lang {
  152. public static function get_string($string = '', $module = null, $lang = null) {
  153. global $_LANG;
  154. if($lang == null){
  155. $lang = APP_LANG;
  156. }
  157. if (isset($_LANG[$lang][$string]) && is_string($_LANG[$lang][$string])) {
  158. return $_LANG[$lang][$string];
  159. }
  160. if (isset($_LANG[$lang][$module][$string])) {
  161. return $_LANG[$lang][$module][$string];
  162. }
  163. return $string;
  164. }
  165. public static function build_strings() {
  166. global $_LANG;
  167. if (isset($_SESSION['cache']['strings'])) {
  168. $_LANG = $_SESSION['cache']['strings'];
  169. return;
  170. }
  171. $rdi = new RecursiveDirectoryIterator(DIR_APPLICATION);
  172. foreach (new RecursiveIteratorIterator($rdi) as $file) {
  173. if (preg_match("/lang\/.*\.php$/", $file)) {
  174. $included_lang = explode('/', $file);
  175. $included_lang = end($included_lang);
  176. $included_lang = str_replace('.php', '', $included_lang);
  177. $lang = Array();
  178. include_once $file;
  179. $_LANG[$included_lang] = $lang;
  180. $lang = Array();
  181. }
  182. }
  183. }
  184. }
  185. abstract class Controller {
  186. }
  187. /*function load_view($name, $values = null, $location = null) {
  188. if (!$location) {
  189. $segments = explode('/', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)[0]['file']);
  190. array_pop($segments);
  191. $location = implode('/', $segments) . '/views/';
  192. }
  193. if (is_array($values) && count($values) > 0) {
  194. extract($values, EXTR_PREFIX_SAME, 'data');
  195. }
  196. $location .= $name;
  197. if( strpos('.php', $location) == 0){
  198. $location .= '.php';
  199. }
  200. if (!file_exists($location)) {
  201. //return require_once GENERAL_VIEW_FOLDER . 'errors/404.php';
  202. }
  203. return require_once( $location );
  204. }*/