人人商城

controller.php 7.0KB

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