public function run(&$params)
 {
     $module = MODULE_NAME;
     $controller = CONTROLLER_NAME;
     $action = ACTION_NAME;
     if (in_array($module, array('Wander', 'Api'))) {
         return;
     }
     session_start();
     $user = session('user');
     if (!empty($user)) {
         $session = array();
         $session['USER'] = array_change_key_case($user, CASE_UPPER);
         $acl = new Acl();
         $roles = $acl->getRoles();
         $roles = coll_key($roles, 'id');
         $role = $roles[$user['role']];
         if (empty($role)) {
             $role = $roles[0];
         }
         $role = coll_elements(array('id', 'title'), $role);
         $session['ROLE'] = array_change_key_case($role, CASE_UPPER);
         $session['ACL'] = array();
         C('SESSION', $session);
     }
     //无用户身份, 只能访问Wander
     if ((empty($session) || empty($session['USER'])) && !in_array($module, array('Wander', 'Api'))) {
         redirect(U('/wander/account/login?forward=' . base64_encode($_SERVER['REQUEST_URI'])));
         exit;
     }
 }
 public function rolesAction()
 {
     $roles = $this->acl->getRoles(true);
     $roles = coll_key($roles, 'id');
     $id = I('get.id');
     if (!empty($id)) {
         $id = intval($id);
         if ($id > 0) {
             $role = $roles[$id];
             $this->assign('entity', $role);
             if (!empty($role)) {
                 if (I('get.do') == 'delete') {
                     if ($this->acl->removeRole($id)) {
                         $this->success('成功删除用户组', U('control/acl/roles'));
                         exit;
                     } else {
                         $this->error('操作失败, 请稍后重试');
                     }
                 }
             }
         }
         if (IS_POST) {
             $input = coll_elements(array('title', 'status', 'remark'), I('post.'));
             $input['title'] = trim($input['title']);
             if (empty($input['title'])) {
                 $this->error('请输入用户组名称');
             }
             $input['status'] = $input['status'] == '-1' ? '-1' : '0';
             $input['parent'] = '0';
             if (!empty($role)) {
                 //编辑组
                 $ret = $this->acl->table('__USR_ROLES__')->data($input)->where("`id`={$id}")->save();
                 if (empty($ret)) {
                     $this->error('保存用户组失败, 请稍后重试');
                 } else {
                     $this->success('成功保存用户组', U('control/acl/roles'));
                     exit;
                 }
             } else {
                 //新增组
                 $ret = $this->acl->table('__USR_ROLES__')->data($input)->add();
                 if (empty($ret)) {
                     $this->error('保存新增用户组失败, 请稍后重试');
                 } else {
                     $this->success('成功新增用户组', U('control/acl/roles'));
                     exit;
                 }
             }
         }
     }
     $this->assign('roles', $roles);
     $this->display();
 }
 public function paymentAction()
 {
     $a = new Account();
     $accounts = array();
     $weixins = $a->table('__PLATFORM_WEIXIN__')->field('`id`, `appid`, `secret`')->where("`level`=2")->select();
     if (!empty($weixins)) {
         $weixins = coll_key($weixins, 'id');
         $ids = coll_neaten($weixins, 'id');
         $accounts = $a->table('__PLATFORMS__')->field('`id`,`title`')->where('`id` IN (' . implode(',', $ids) . ')')->select();
         foreach ($accounts as &$acc) {
             $acc['appid'] = $weixins[$acc['id']]['appid'];
             $acc['secret'] = $weixins[$acc['id']]['secret'];
         }
     }
     Pay::loadSettings();
     $setting = C('PAY');
     if (IS_POST) {
         $input = array();
         $input['alipay'] = I('post.alipay');
         $input['alipay']['enable'] = $input['alipay']['enable'] == 'true' ? 1 : 0;
         if (!empty($input['alipay']['enable'])) {
             if (empty($input['alipay']['partner']) || empty($input['alipay']['account']) || empty($input['alipay']['secret'])) {
                 $this->error('支付宝支付资料输入不完整');
             }
         }
         $setting[Pay::OPT_ALIPAY] = $input['alipay'];
         $input['weixin'] = I('post.weixin');
         $input['weixin']['enable'] = $input['weixin']['enable'] == 'true' ? 1 : 0;
         if (!empty($input['weixin']['enable'])) {
             if (empty($input['weixin']['partner']) || empty($input['weixin']['key']) || empty($input['weixin']['mchid'])) {
                 $this->error('微信支付资料输入不完整');
             }
         }
         $setting[Pay::OPT_WEIXIN] = $input['weixin'];
         if (Pay::saveSettings($setting)) {
             $this->success('操作成功');
             exit;
         } else {
             $this->error('操作失败, 请稍后重试');
         }
     }
     $pay = array();
     $pay['weixin'] = $setting[Pay::OPT_WEIXIN];
     $pay['alipay'] = $setting[Pay::OPT_ALIPAY];
     $this->assign('pay', $pay);
     $this->assign('accounts', $accounts);
     $this->display();
 }
예제 #4
0
 /**
  * 加载数据库配置项, 一般预留给模块封装调用, 控制器中不应该直接调用
  * @param $moduleName string 模块名称
  * @param $keys array 配置项名称
  * @return array
  */
 public static function loadSettings($moduleName, $keys)
 {
     $moduleName = strtoupper($moduleName);
     $m = new Model();
     $condition = '`key` IN (';
     foreach ($keys as &$key) {
         $key = strtoupper($key);
         $condition .= "'{$moduleName}:{$key}',";
     }
     unset($key);
     $condition = rtrim($condition, ',');
     $condition .= ')';
     $settings = $m->table('__CORE_SETTINGS__')->where($condition)->select();
     $settings = coll_key($settings, 'key');
     $s = array();
     foreach ($keys as $key) {
         $origKey = "{$moduleName}:{$key}";
         $s[$key] = unserialize($settings[$origKey]['value']);
     }
     return $s;
 }
 public function addonsAction()
 {
     $addons = array();
     $path = MB_ROOT . 'addons/';
     if (is_dir($path)) {
         if ($handle = opendir($path)) {
             while (false !== ($addonpath = readdir($handle))) {
                 if ($addonpath != '.' && $addonpath != '..') {
                     $define = Addon::getAddon($addonpath, true);
                     if (!is_error($define)) {
                         $addons[] = $define;
                     }
                 }
             }
         }
     }
     if (IS_POST) {
         $a = I('post.addon');
         $addons = coll_key($addons, 'name');
         $addon = $addons[$a];
         if (!empty($addon)) {
             $zip = new \ZipArchive();
             $tmpFile = ADDON_CURRENT_PATH . 'Data/package.zip';
             @unlink($tmpFile);
             $zip->open($tmpFile, \ZipArchive::CREATE);
             $root = MB_ROOT . "addons/{$a}";
             $files = File::tree($root);
             foreach ($files as $file) {
                 $local = substr($file, strlen($root));
                 if (substr($local, -4) == '.php') {
                     if (I('post.trim') != '') {
                         $content = $this->trimComments($file, I('post.license'));
                     }
                     $zip->addFromString("{$a}{$local}", $content);
                 } else {
                     $zip->addFile($file, "{$a}{$local}");
                 }
             }
             $zip->close();
             $version = MB_VERSION;
             $filename = "{$a}-v{$addon['version']} (for MB-{$version})";
             header('content-type: application/zip');
             header('content-disposition: attachment; filename="' . $filename . '.zip"');
             readfile($tmpFile);
             @unlink($tmpFile);
         }
     }
     $this->assign('addons', $addons);
     $this->display('addons');
 }
예제 #6
0
 private function validateForm($modify = false)
 {
     $input = coll_elements(array('username', 'password', 'role', 'status'), I('post.'));
     $input['username'] = trim($input['username']);
     if (empty($modify)) {
         if (empty($input['username']) || empty($input['password'])) {
             $this->error('请输入用户名及登陆密码');
         }
     }
     if ($input['role'] === false) {
         $this->error('必须指定用户组');
     }
     $roles = coll_key($this->roles, 'id');
     if (empty($roles[$input['role']])) {
         $input['role'] = '0';
     }
     $input['status'] = $input['status'] == '-1' ? '-1' : '0';
     return $input;
 }
 public function creditAction()
 {
     $do = I('get.do') == 'policy' ? 'policy' : 'list';
     Member::loadSettings();
     $setting = C('MS');
     $credits = $setting[Member::OPT_CREDITS];
     $credits = coll_key($credits, 'name');
     if ($do == 'list') {
         if (IS_POST) {
             $titles = I('post.title');
             $enableds = I('post.enabled');
             foreach ($titles as $key => $value) {
                 if ($key == 'credit1' || $key == 'credit2') {
                     $credits[$key]['enabled'] = '1';
                 } else {
                     $credits[$key]['enabled'] = isset($enableds[$key]) ? '1' : '0';
                 }
                 $credits[$key]['title'] = trim($value);
             }
             $activity = $setting[Member::OPT_CREDITPOLICY][Member::OPT_CREDITPOLICY_ACTIVITY];
             $currency = $setting[Member::OPT_CREDITPOLICY][Member::OPT_CREDITPOLICY_CURRENCY];
             if (empty($credits[$activity]['enabled']) || empty($credits[$currency]['enabled'])) {
                 $this->error('要禁用的积分被积分策略中使用, 请检查.', U('control/member/credit'));
             }
             $setting[Member::OPT_CREDITS] = $credits;
             if (Member::saveSettings($setting)) {
                 $this->success('积分信息更新成功!');
                 exit;
             } else {
                 $this->error('积分信息更新失败, 请稍后重试!');
             }
         }
         $this->assign('credits', $credits);
     }
     if ($do == 'policy') {
         if (IS_POST) {
             $activity = I('post.activity');
             $currency = I('post.currency');
             if ($activity == $currency) {
                 $this->error('营销积分和交易积分不能相同!');
             }
             if (empty($credits[$activity]['enabled']) || empty($credits[$currency]['enabled'])) {
                 $this->error('无效的积分选项');
             }
             $setting[Member::OPT_CREDITPOLICY][Member::OPT_CREDITPOLICY_ACTIVITY] = $activity;
             $setting[Member::OPT_CREDITPOLICY][Member::OPT_CREDITPOLICY_CURRENCY] = $currency;
             if (Member::saveSettings($setting)) {
                 $this->success('积分策略更新成功!');
                 exit;
             } else {
                 $this->error('积分策略更新失败, 请稍后重试!');
             }
         }
         $policy = $setting[Member::OPT_CREDITPOLICY];
         $this->assign('policy', $policy);
     }
     $this->assign('do', $do);
     C('FRAME_CURRENT', U('control/member/credit'));
     $this->display();
 }
 public function run(&$params)
 {
     Site::loadSettings();
     if (MODULE_NAME == 'Bench') {
         $theme = I('cookie.template_theme');
         $themes = array('cerulean', 'cyborg', 'simplex', 'darkly', 'lumen', 'slate', 'spacelab', 'united');
         if (!empty($theme) && in_array($theme, $themes)) {
             C('TMPL_PARSE_STRING.{__TEMPLATE_THEME__}', '-' . $theme);
         }
         $frames = $this->getBenchFrames();
         $name = C('FRAME_ACTIVE');
         $names = array();
         $names[] = 'summary';
         $names[] = 'cms';
         $names[] = 'uc';
         $names[] = 'extend';
         $names[] = 'addons';
         $names[] = 'analyze';
         $name = in_array($name, $names) ? $name : 'summary';
     }
     if (MODULE_NAME == 'Control') {
         $frames = $this->getControlFrames();
         $name = C('FRAME_ACTIVE');
         $names = array();
         $names[] = 'common';
         $names[] = 'webapp';
         $names[] = 'member';
         $names[] = 'access';
         $names[] = 'extend';
         $names[] = 'addons';
         $names[] = 'store';
         $name = in_array($name, $names) ? $name : 'common';
     }
     $allAddons = array();
     if ($name == 'extend') {
         $types = Addon::types();
         foreach ($types as $type) {
             $addons = Addon::getAddons($type['name']);
             $allAddons = array_merge($allAddons, coll_key($addons, 'name'));
             $items = array();
             if (!empty($addons)) {
                 foreach ($addons as $a) {
                     $addon = new Addon($a);
                     $entryType = strtolower(MODULE_NAME);
                     $entries = $addon->getEntries($entryType);
                     if (!empty($entries)) {
                         $addonName = parse_name($a['name']);
                         $items[] = array('icon' => 'plus', 'title' => $a['title'], 'url' => U("/{$entryType}/extend/{$addonName}"));
                     }
                 }
             }
             if (!empty($items)) {
                 $frames['extend'][] = array('title' => $type['title'], 'items' => $items);
             }
         }
     }
     if ($name == 'addons') {
         if (defined('ADDON_NAME')) {
             $a = C('ADDON_INSTANCE');
             $addon = $a->getCurrentAddon();
             $entries = $a->getEntries(strtolower(MODULE_NAME));
             $items = array();
             foreach ($entries as $entry) {
                 $items[] = array('icon' => 'plus', 'url' => $entry['url'], 'title' => $entry['title']);
             }
             $frames['addons'][] = array('title' => $addon['title'], 'items' => $items);
         }
     }
     C('FRAME_ACTIVE', $name);
     $set = $frames[$name];
     $url = C('FRAME_CURRENT');
     if (empty($url)) {
         $url = $_SERVER['REQUEST_URI'];
         C('FRAME_CURRENT', $url);
     }
     foreach ($set as &$row) {
         foreach ($row['items'] as &$item) {
             if ($item['url'] == $url) {
                 $item['current'] = true;
                 if (!C('FRAME_TITLE')) {
                     C('FRAME_TITLE', $item['title']);
                 }
             }
             if (!empty($item['items'])) {
                 foreach ($item['items'] as &$sub) {
                     if ($sub['url'] == $url) {
                         $sub['current'] = true;
                         if (!C('FRAME_TITLE')) {
                             C('FRAME_TITLE', $sub['title']);
                         }
                     }
                 }
             }
         }
     }
     C('FRAME_SETS', $set);
 }