예제 #1
0
function getSubPosition($array, $position_id, $sub_level = 1)
{
    $sub_position = searchArrayById($array, $position_id, "cpheadmancpid", "cpid");
    $padding_left = 2 * intval($sub_level);
    $text = "";
    foreach ($sub_position as $row) {
        $text .= "<tr>\n\t\t\t\t\t<td style='padding-left:" . $padding_left . "em;'>" . $row["cpname"] . "</td>\n\t\t\t\t\t<td class='right-align'>\n\t\t\t\t\t\t<a href='" . site_url('admin/Company/position/edit/' . $row["cpid"]) . "' \n\t\t\t\t\t\tclass='btn-floating btn-small waves-effect waves-light blue'>\n\t\t\t\t\t\t\t<i class='material-icons'>edit</i>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t\t<a href='javascript:void(0);'\n\t\t\t\t\t\tdata-id='" . $row["cpid"] . "' \n\t\t\t\t\t\tclass='btn-floating btn-small waves-effect waves-light red'\n\t\t\t\t\t\tonclick=\"deleteThis(this,'position/delete','" . $row['cpid'] . "');\">\n\t\t\t\t\t\t\t<i class='material-icons'>delete</i>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
        $text .= getSubPosition($array, $row["cpid"], $sub_level + 1);
    }
    return $text;
}
예제 #2
0
 public function roleEdit()
 {
     if ($_GET['auth']) {
         $per['position_id'] = intval($_GET['position_id']);
         $per['name'] = trim($_GET['name']);
         $per['description'] = trim($_GET['description']);
         $per['department_id'] = intval($_GET['department_id']);
         $per['parent_id'] = intval($_GET['parent_id']);
         $m_position = M('Position');
         if ($m_position->create($per)) {
             if ($m_position->save()) {
                 $this->ajaxReturn(L('EDIT SUCCESSFULLY'), 'info', 1);
             } else {
                 $this->ajaxReturn(L('DATA_NOT_CHANGED_EDIT_FAILED'), 'info', 1);
             }
         } else {
             $this->ajaxReturn(L('EDIT_FAILED_CONTACT_THE_ADMIN'), 'info', 1);
         }
     } elseif ($_GET['id']) {
         $m_position = M('position');
         $department_list = M('RoleDepartment')->select();
         $position_list = $m_position->select();
         $this->assign('position', $m_position->where('position_id=%d', $_GET['id'])->find());
         $this->assign('departmentList', getSubDepartment(0, $department_list, ''));
         $this->assign('positionList', getSubPosition(0, $position_list, ''));
         $this->display();
     } else {
         $this->error(L('PARAMETER_ERROR'));
     }
 }
예제 #3
0
function getSubPosition($position_id, $position, $separate)
{
    $array = array();
    foreach ($position as $key => $value) {
        if ($position_id == $value['parent_id']) {
            $m_department = M('Department');
            $department_name = $m_department->where('department_id = %d', $value['department_id'])->getField('name');
            $array[] = array('position_id' => $value['position_id'], 'name' => $separate . $department_name . ' | ' . $value['name'], 'description' => $value['description']);
            $array = array_merge($array, getSubPosition($value['position_id'], $position, $separate . ' -- '));
        }
    }
    return $array;
}
예제 #4
0
    public function add()
    {
        $m_role = M('Role');
        $m_user = D('User');
        if ($this->isPost()) {
            $m_user->create();
            // echo $m_user->name;
            if ($_POST['radio_type'] == 'email') {
                //邮箱激活
                if (!isset($_POST['name']) || $_POST['name'] == '') {
                    alert('error', '请输入用户名', $_SERVER['HTTP_REFERER']);
                } elseif (!isset($_POST['email']) || $_POST['email'] == '') {
                    alert('error', '请输入邮箱', $_SERVER['HTTP_REFERER']);
                } elseif (!ereg('^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,4}$', $_POST['email'])) {
                    alert('error', '邮箱格式不正确', $_SERVER['HTTP_REFERER']);
                } elseif ($m_user->where('email = "%s"', $_POST['email'])->find()) {
                    alert('error', '此邮箱已绑定用户!', $_SERVER['HTTP_REFERER']);
                } elseif (!isset($_POST['category_id']) || $_POST['category_id'] == '') {
                    alert('error', '请选择用户类别!', $_SERVER['HTTP_REFERER']);
                } elseif (!session('?admin') && intval($_POST['category_id']) == 1) {
                    alert('error', '你没有添加管理员用户的权利!', $_SERVER['HTTP_REFERER']);
                } elseif (!isset($_POST['position_id']) || $_POST['position_id'] == '') {
                    alert('error', '请选择要添加用户的岗位!', $_SERVER['HTTP_REFERER']);
                } elseif ($m_user->where('name = "%s"', $_POST['name'])->find()) {
                    alert('error', '该用户已存在!', $_SERVER['HTTP_REFERER']);
                }
                $m_user->status = 0;
                //为用户设置默认导航(根据系统菜单设置中的位置)
                $m_navigation = M('navigation');
                $navigation_list = $m_navigation->order('listorder asc')->select();
                $menu = array();
                foreach ($navigation_list as $val) {
                    if ($val['postion'] == 'top') {
                        $menu['top'][] = $val['id'];
                    } elseif ($val['postion'] == 'user') {
                        $menu['user'][] = $val['id'];
                    } else {
                        $menu['more'][] = $val['id'];
                    }
                }
                $navigation = serialize($menu);
                $m_user->navigation = $navigation;
                if ($re_id = $m_user->add()) {
                    // echo $m_user->getLastSql();
                    // die();
                    $time = time();
                    $info = $m_user->where('user_id = %d', $re_id)->find();
                    $m_user->where('user_id = %d' . $info['user_id'])->setField('reg_time', $time);
                    $verify_code = md5(md5($time) . $info['salt']);
                    C(F('smtp'), 'smtp');
                    import('@.ORG.Mail');
                    $url = U('user/active', array('user_id' => $info['user_id'], 'verify_code' => $verify_code), '', '', true);
                    $content = '尊敬的' . $_POST['name'] . ':<br/><br/>您好!您的CRM管理员已经给您发送了邀请,请查收!
			请点击下面的链接完成注册:<br/><br/>' . $url . '<br/><br/>如果以上链接无法点击,请将上面的地址复制到你的浏览器(如IE)的地址栏进入网站。<br/><br/>--悟空CRM管理员(这是一封自动产生的email,请勿回复。)';
                    //echo $info['email'].$content;
                    //die();
                    if (SendMail($info['email'], '从悟空CRM添加用户邀请', $content, '悟空CRM管理员')) {
                        $data['position_id'] = $_POST['position_id'];
                        $data['user_id'] = $re_id;
                        if ($role_id = $m_role->add($data)) {
                            $m_user->where('user_id = %d', $re_id)->setField('role_id', $role_id);
                            actionLog($re_id);
                            alert('success', '添加成功,等待被邀请用户激活!', U('user/index'));
                        }
                    } else {
                        alert('error', '无法发送邀请,请检查smtp设置信息!', $_SERVER['HTTP_REFERER']);
                    }
                } else {
                    alert('error', '添加失败,请联系管理员!', $_SERVER['HTTP_REFERER']);
                }
            } else {
                //填写密码
                if (!isset($_POST['name']) || $_POST['name'] == '') {
                    alert('error', '请输入用户名', $_SERVER['HTTP_REFERER']);
                } elseif (!isset($_POST['password']) || $_POST['password'] == '') {
                    alert('error', '请输入密码', $_SERVER['HTTP_REFERER']);
                } elseif (!isset($_POST['category_id']) || $_POST['category_id'] == '') {
                    alert('error', '请选择用户类别!', $_SERVER['HTTP_REFERER']);
                } elseif (!session('?admin') && intval($_POST['category_id']) == 1) {
                    alert('error', '你没有添加管理员用户的权利!', $_SERVER['HTTP_REFERER']);
                } elseif (!isset($_POST['position_id']) || $_POST['position_id'] == '') {
                    alert('error', '请选择要添加用户的岗位!', $_SERVER['HTTP_REFERER']);
                } elseif ($m_user->where('name = "%s"', $_POST['name'])->find()) {
                    alert('error', '该用户已存在!', $_SERVER['HTTP_REFERER']);
                } elseif (!session('?admin') && intval($_POST['category_id']) == 1) {
                    alert('error', '你没有添加管理员用户的权利!', $_SERVER['HTTP_REFERER']);
                }
                $m_user->status = 1;
                //为用户设置默认导航(根据系统菜单设置中的位置)
                $m_navigation = M('navigation');
                $navigation_list = $m_navigation->order('listorder asc')->select();
                $menu = array();
                foreach ($navigation_list as $val) {
                    if ($val['postion'] == 'top') {
                        $menu['top'][] = $val['id'];
                    } elseif ($val['postion'] == 'user') {
                        $menu['user'][] = $val['id'];
                    } else {
                        $menu['more'][] = $val['id'];
                    }
                }
                $navigation = serialize($menu);
                $m_user->navigation = $navigation;
                if ($re_id = $m_user->add()) {
                    $data['position_id'] = $_POST['position_id'];
                    $data['user_id'] = $re_id;
                    if ($role_id = $m_role->add($data)) {
                        $m_user->where('user_id = %d', $re_id)->setField('role_id', $role_id);
                        actionLog($re_id);
                        if ($_POST['submit'] == '添加') {
                            alert('success', '添加成功,该用户已可以登录系统!', U('user/index'));
                        } else {
                            alert('success', '添加成功,该用户已可以登录系统!', U('user/add'));
                        }
                    }
                } else {
                    alert('error', '添加失败,请联系管理员!', $_SERVER['HTTP_REFERER']);
                }
            }
        } else {
            $m_config = M('Config');
            if ($m_config->where('name = "smtp"')->find()) {
                $category = M('user_category');
                $m_position = M('position');
                if (!session('?admin')) {
                    $department_list = getSubDepartment2(session('department_id'), M('role_department')->select(), 1);
                } else {
                    $department_list = M('role_department')->select();
                }
                $where['department_id'] = session('department_id');
                $position_list = getSubPosition(session('position_id'), $m_position->where($where)->select());
                $position_id_array = array();
                foreach ($position_list as $k => $v) {
                    $position_id_array[] = $v['position_id'];
                }
                $where['position_id'] = array('in', implode(',', $position_id_array));
                $role_list = $m_position->where($where)->select();
                if (empty($role_list) && !session('?admin')) {
                    alert('error', '您没有添加用户的权限!', U('setting/smtp'));
                } else {
                    $this->categoryList = $category->select();
                    $this->assign('department_list', $department_list);
                    $this->alert = parseAlert();
                    $this->display();
                }
            } else {
                alert('error', '请先设置smtp用于邀请用户', U('setting/smtp'));
            }
        }
    }