controller.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. class Controller
  3. {
  4. public function template($name = '')
  5. {
  6. global $_W;
  7. $style = ES_STYLE;
  8. $basicset = $this->basicset();
  9. $style = $basicset['template'];
  10. $source = ES_TEMPLATE_PATH . $style . '/' . $name . '.html';
  11. if (!is_file($source)) {
  12. $source = ES_TEMPLATE_PATH . ES_STYLE . '/' . $name . '.html';
  13. }
  14. if (!is_file($source)) {
  15. trigger_error('Template <b>' . $name . '</b> Not Found!');
  16. exit();
  17. }
  18. $compile = IA_ROOT . '/data/tpl/web/ewei_shop_web/' . ES_STYLE . ('/' . $name . '.tpl.php');
  19. if (DEVELOPMENT || !is_file($compile) || filemtime($compile) < filemtime($source)) {
  20. template_compile($source, $compile, true);
  21. }
  22. return $compile;
  23. }
  24. public function basicset()
  25. {
  26. global $_W;
  27. $basicset = pdo_fetch('select * from ' . tablename('ewei_shop_system_site') . ' where `type`=:type', array(':type' => 'set'));
  28. $data = iunserializer($basicset['content'], true);
  29. return $data;
  30. }
  31. public function pagination($total, $pageIndex, $pageSize = 15, $url = '', $context = array('before' => 5, 'after' => 4, 'ajaxcallback' => '', 'callbackfuncname' => ''))
  32. {
  33. global $_W;
  34. $pdata = array('tcount' => 0, 'tpage' => 0, 'cindex' => 0, 'findex' => 0, 'pindex' => 0, 'nindex' => 0, 'lindex' => 0, 'options' => '');
  35. if ($context['ajaxcallback']) {
  36. $context['isajax'] = true;
  37. }
  38. $pdata['tcount'] = $total;
  39. $pdata['tpage'] = ceil($total / $pageSize);
  40. if ($pdata['tpage'] <= 1) {
  41. return '';
  42. }
  43. $cindex = $pageIndex;
  44. $cindex = min($cindex, $pdata['tpage']);
  45. $cindex = max($cindex, 1);
  46. $pdata['cindex'] = $cindex;
  47. $pdata['findex'] = 1;
  48. $pdata['pindex'] = 1 < $cindex ? $cindex - 1 : 1;
  49. $pdata['nindex'] = $cindex < $pdata['tpage'] ? $cindex + 1 : $pdata['tpage'];
  50. $pdata['lindex'] = $pdata['tpage'];
  51. if ($context['isajax']) {
  52. if (!$url) {
  53. $url = $_W['script_name'] . '?' . http_build_query($_GET);
  54. }
  55. $pdata['faa'] = 'href="javascript:;" page="' . $pdata['findex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $_W['script_name'] . $url . '\', \'' . $pdata['findex'] . '\', this);return false;"' : '');
  56. $pdata['paa'] = 'href="javascript:;" page="' . $pdata['pindex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $_W['script_name'] . $url . '\', \'' . $pdata['pindex'] . '\', this);return false;"' : '');
  57. $pdata['naa'] = 'href="javascript:;" page="' . $pdata['nindex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $_W['script_name'] . $url . '\', \'' . $pdata['nindex'] . '\', this);return false;"' : '');
  58. $pdata['laa'] = 'href="javascript:;" page="' . $pdata['lindex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $_W['script_name'] . $url . '\', \'' . $pdata['lindex'] . '\', this);return false;"' : '');
  59. }
  60. else if ($url) {
  61. $pdata['faa'] = 'href="?' . str_replace('*', $pdata['findex'], $url) . '"';
  62. $pdata['paa'] = 'href="?' . str_replace('*', $pdata['pindex'], $url) . '"';
  63. $pdata['naa'] = 'href="?' . str_replace('*', $pdata['nindex'], $url) . '"';
  64. $pdata['laa'] = 'href="?' . str_replace('*', $pdata['lindex'], $url) . '"';
  65. }
  66. else {
  67. $_GET['page'] = $pdata['findex'];
  68. $pdata['faa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
  69. $_GET['page'] = $pdata['pindex'];
  70. $pdata['paa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
  71. $_GET['page'] = $pdata['nindex'];
  72. $pdata['naa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
  73. $_GET['page'] = $pdata['lindex'];
  74. $pdata['laa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
  75. }
  76. $html = '<div class="list-page">';
  77. if (1 < $pdata['cindex']) {
  78. $html .= '<a ' . $pdata['faa'] . ' class="pager-nav">首页</a>';
  79. $html .= '<a ' . $pdata['paa'] . ' class="pager-nav">上一页</a>';
  80. }
  81. if (!$context['before'] && $context['before'] != 0) {
  82. $context['before'] = 5;
  83. }
  84. if (!$context['after'] && $context['after'] != 0) {
  85. $context['after'] = 4;
  86. }
  87. if ($context['after'] != 0 && $context['before'] != 0) {
  88. $range = array();
  89. $range['start'] = max(1, $pdata['cindex'] - $context['before']);
  90. $range['end'] = min($pdata['tpage'], $pdata['cindex'] + $context['after']);
  91. if ($range['end'] - $range['start'] < $context['before'] + $context['after']) {
  92. $range['end'] = min($pdata['tpage'], $range['start'] + $context['before'] + $context['after']);
  93. $range['start'] = max(1, $range['end'] - $context['before'] - $context['after']);
  94. }
  95. $i = $range['start'];
  96. while ($i <= $range['end']) {
  97. if ($context['isajax']) {
  98. $aa = 'href="javascript:;" page="' . $i . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $_W['script_name'] . $url . '\', \'' . $i . '\', this);return false;"' : '');
  99. }
  100. else if ($url) {
  101. $aa = 'href="?' . str_replace('*', $i, $url) . '"';
  102. }
  103. else {
  104. $_GET['page'] = $i;
  105. $aa = 'href="?' . http_build_query($_GET) . '"';
  106. }
  107. $html .= $i == $pdata['cindex'] ? '<a href="javascript:void(0);" class="active">' . $i . '</a>' : '<a ' . $aa . '>' . $i . '</a>';
  108. ++$i;
  109. }
  110. }
  111. if ($pdata['cindex'] < $pdata['tpage']) {
  112. $html .= '<a ' . $pdata['naa'] . ' class="pager-nav">下一页</a>';
  113. $html .= '<a ' . $pdata['laa'] . ' class="pager-nav">尾页</a>';
  114. }
  115. $html .= '</div>';
  116. return $html;
  117. }
  118. public function message($msg, $redirect = '', $type = '')
  119. {
  120. global $_W;
  121. global $_GPC;
  122. if ($redirect == 'refresh') {
  123. $redirect = $_W['script_name'] . '?' . $_SERVER['QUERY_STRING'];
  124. }
  125. if ($redirect == 'referer') {
  126. $redirect = referer();
  127. }
  128. if ($redirect == '') {
  129. $type = in_array($type, array('success', 'error', 'info', 'warning', 'ajax', 'sql')) ? $type : 'info';
  130. }
  131. else {
  132. $type = in_array($type, array('success', 'error', 'info', 'warning', 'ajax', 'sql')) ? $type : 'success';
  133. }
  134. if ($_W['isajax'] || !empty($_GET['isajax']) || $type == 'ajax') {
  135. if ($type != 'ajax' && !empty($_GPC['target'])) {
  136. exit('
  137. <script type="text/javascript">
  138. parent.require([\'jquery\', \'util\'], function($, util){
  139. var url = ' . (!empty($redirect) ? 'parent.location.href' : '\'\'') . ';
  140. var modalobj = util.message(\'' . $msg . '\', \'\', \'' . $type . '\');
  141. if (url) {
  142. modalobj.on(\'hide.bs.modal\', function(){$(\'.modal\').each(function(){if($(this).attr(\'id\') != \'modal-message\') {$(this).modal(\'hide\');}});top.location.reload()});
  143. }
  144. });
  145. </script>');
  146. }
  147. else {
  148. $vars = array();
  149. $vars['message'] = $msg;
  150. $vars['redirect'] = $redirect;
  151. $vars['type'] = $type;
  152. exit(json_encode($vars));
  153. }
  154. }
  155. if (empty($msg) && !empty($redirect)) {
  156. header('location: ' . $redirect);
  157. }
  158. $label = $type;
  159. if ($type == 'error') {
  160. $label = 'danger';
  161. }
  162. if ($type == 'ajax' || $type == 'sql') {
  163. $label = 'warning';
  164. }
  165. include $this->template('common/message');
  166. exit();
  167. }
  168. }
  169. if (!defined('ES_PATH')) {
  170. exit('Access Denied');
  171. }
  172. ?>