Exemple #1
0
 /**
  * 添加新商户
  */
 public function add()
 {
     /* 只允许root和管理员执行 */
     if (!role::is_root()) {
         role::check('manage_merchant');
         $manager = Mymanager::instance($this->manager_id)->get();
         if (!$manager['is_admin']) {
             remind::set(Kohana::lang('o_manage.only_admin_do'), 'manage/manager');
         }
     }
     $next_flow = site::next_flow(self::CURRENT_FLOW);
     if ($_POST) {
         //echo "<pre>";print_r($this->input->post());die();
         $role_id = intval($this->input->post('role_id'));
         $submit_target = intval($this->input->post('submit_target'));
         //标签过滤
         tool::filter_strip_tags($_POST);
         $password1 = $this->input->post('password1');
         $password2 = $this->input->post('password2');
         $username = $this->input->post('username');
         $email = $this->input->post('email');
         $manager = Mymanager::instance()->get_by_username($username);
         if ($manager['id']) {
             remind::set(Kohana::lang('o_manage.name_has_exist'), 'manage/manager/add');
         }
         $manager = Mymanager::instance()->get_by_email($email);
         if ($manager['id']) {
             remind::set(Kohana::lang('o_manage.email_has_exist'), 'manage/manager/add');
         }
         //验证两次密码是否相同
         if ($password1 != $password2) {
             remind::set(Kohana::lang('o_manage.two_pwd_not_valid'), 'manage/manager/add');
         } else {
             $_POST['password'] = $password1;
         }
         $_POST['parent_id'] = $this->manager_id;
         if (Mymanager::instance()->add($_POST)) {
             //判断添加成功去向
             switch ($submit_target) {
                 case 1:
                     remind::set(Kohana::lang('o_global.add_success'), 'manage/manager/add', 'success');
                 case 2:
                     remind::set(Kohana::lang('o_global.add_success_into') . $next_flow['name'], $next_flow['url'], 'success');
                 case 3:
                 default:
                     if ($role_id == 0) {
                         $id = Mymanager::instance()->get('id');
                         remind::set(Kohana::lang('o_global.add_success'), 'manage/manager/rule/' . $id, 'success');
                     }
                     remind::set(Kohana::lang('o_global.add_success'), 'manage/manager', 'success');
             }
         } else {
             $error = Mysite::instance()->error();
             remind::set(Kohana::lang('o_global.add_error') . $error, 'manage/manager/add');
         }
     }
     $where = array();
     $where['type'] = 0;
     $where['active'] = 1;
     //zhu add
     //在添加商家帐号时候只能显示一级的用户级别
     $where['level_depth'] = 1;
     $roles = Myrole::instance()->roles($where);
     $this->template->content = new View("manage/manager_add");
     $this->template->content->roles = $roles;
     //show next flow button
     $this->template->content->next_flow_btn = site::next_flow_btn(self::CURRENT_FLOW);
 }