public function delete() { $m_leads = M('Leads'); if ($this->isPost()) { $leads_ids = is_array($_POST['leads_id']) ? implode(',', $_POST['leads_id']) : ''; if ('' == $leads_ids) { alert('error', L('NOT CHOOSE ANY'), $_SERVER['HTTP_REFERER']); } else { $data = array('is_deleted' => 1, 'delete_role_id' => session('role_id'), 'delete_time' => time()); if ($m_leads->where('leads_id in (%s)', $leads_ids)->setField($data)) { foreach ($leads_ids as $value) { actionLog($value); } alert('success', L('DELETED SUCCESSFULLY'), $_SERVER['HTTP_REFERER']); } else { alert('error', L('DELETE FAILED CONTACT THE ADMINISTRATOR'), $_SERVER['HTTP_REFERER']); } } } elseif ($this->isGet()) { $leads_id = intval(trim($_GET['id'])); $leads = $m_leads->where('leads_id = %d', $leads_id)->find(); if (is_array($leads)) { if ($leads['owner_role_id'] == session('role_id') || session('?admin')) { $data = array('is_deleted' => 1, 'delete_role_id' => session('role_id'), 'delete_time' => time()); if ($m_leads->where('leads_id = %d', $leads_id)->setField($data)) { actionLog($leads_id); //判断线索是否属于线索池 $outdays = M('config')->where('name="leads_outdays"')->getField('value'); $outdate = empty($outdays) ? time() : time() - 86400 * $outdays; if ($leads['have_time'] < $outdate) { alert('success', L('DELETED SUCCESSFULLY'), U('Leads/index', 'by=public')); } else { alert('success', L('DELETED SUCCESSFULLY'), U('Leads/index')); } } else { alert('error', L('DELETE FAILED CONTACT THE ADMINISTRATOR'), $_SERVER['HTTP_REFERER']); } } else { alert('error', L('HAVE NOT PRIVILEGES'), $_SERVER['HTTP_REFERER']); } } else { alert('error', L('LEADS_DOES_NOT_EXIST'), $_SERVER['HTTP_REFERER']); } } }
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', L('INPUT_USER_NAME'), $_SERVER['HTTP_REFERER']); } elseif (!isset($_POST['email']) || $_POST['email'] == '') { alert('error', L('INPUT_EMAIL'), $_SERVER['HTTP_REFERER']); } elseif (!ereg('^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,4}$', $_POST['email'])) { alert('error', L('INVALIDATE_EMAIL'), $_SERVER['HTTP_REFERER']); } elseif ($m_user->where('email = "%s"', $_POST['email'])->find()) { alert('error', L('EMAIL_HAS_BEEN_BOUND'), $_SERVER['HTTP_REFERER']); } elseif (!isset($_POST['category_id']) || $_POST['category_id'] == '') { alert('error', L('PLEASE_SELECT_USER_CATEGORY'), $_SERVER['HTTP_REFERER']); } elseif (!session('?admin') && intval($_POST['category_id']) == 1) { alert('error', L('YOU_HAVE_NO_PERMISSION_TO_ADD_ADMIN'), $_SERVER['HTTP_REFERER']); } elseif (!isset($_POST['position_id']) || $_POST['position_id'] == '') { alert('error', L('SELECT_POSITION_TO_ADD_USER'), $_SERVER['HTTP_REFERER']); } elseif ($m_user->where('name = "%s"', $_POST['name'])->find()) { alert('error', L('USER_EXIST'), $_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 = L('ADD_USER_EMAIL_CONENT', array($_POST['name'], $url)); //echo $info['email'].$content; //die(); if (SendMail($info['email'], L('ADD_USER_INVITATION_FROM_5KCRM'), $content, L('5KCRM_ADMIN'))) { $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', L('ADD_SUCCESS_WAITING_TO_BE_ACTIVED'), U('user/index')); } } else { alert('error', L('CAN_NOT_SEND_INVITATION_CHECK_SMTP'), $_SERVER['HTTP_REFERER']); } } else { alert('error', L('ADDING FAILS CONTACT THE ADMINISTRATOR', array('')), $_SERVER['HTTP_REFERER']); } } else { //填写密码 if (!isset($_POST['name']) || $_POST['name'] == '') { alert('error', L('INPUT_USER_NAME'), $_SERVER['HTTP_REFERER']); } elseif (!isset($_POST['password']) || $_POST['password'] == '') { alert('error', L('INPUT_PASSWORD'), $_SERVER['HTTP_REFERER']); } elseif (!isset($_POST['category_id']) || $_POST['category_id'] == '') { alert('error', L('PLEASE_SELECT_USER_CATEGORY'), $_SERVER['HTTP_REFERER']); } elseif (!session('?admin') && intval($_POST['category_id']) == 1) { alert('error', L('YOU_HAVE_NO_PERMISSION_TO_ADD_ADMIN'), $_SERVER['HTTP_REFERER']); } elseif (!isset($_POST['position_id']) || $_POST['position_id'] == '') { alert('error', L('SELECT_POSITION_TO_ADD_USER'), $_SERVER['HTTP_REFERER']); } elseif ($m_user->where('name = "%s"', $_POST['name'])->find()) { alert('error', L('USER_EXIST'), $_SERVER['HTTP_REFERER']); } elseif (!session('?admin') && intval($_POST['category_id']) == 1) { alert('error', L('YOU_HAVE_NO_PERMISSION_TO_ADD_ADMIN'), $_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'] == L('ADD')) { alert('success', L('ADD_USER_SUCCESS_USER_CAN_LOGIN_NOW'), U('user/index')); } else { alert('success', L('ADD_USER_SUCCESS_USER_CAN_LOGIN_NOW'), U('user/add')); } } } else { alert('error', L('ADDING FAILS CONTACT THE ADMINISTRATOR', array('')), $_SERVER['HTTP_REFERER']); } } } else { $m_config = M('Config'); $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(); $position_id_array[] = session('position_id'); 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', L('YOU_HAVE_NO_PERMISSION_TO_ADD_USER'), $_SERVER['HTTP_REFERER']); } else { if (!$m_config->where('name = "smtp"')->find()) { alert('error', L('PLEASE_SET_SMTP_FIRST_TO_INVITATION_USER', array(U('setting/smtp')))); } $this->categoryList = $category->select(); $this->assign('department_list', $department_list); $this->alert = parseAlert(); $this->display(); } } }
public function delete() { $m_product = M('product'); $m_product_data = M('product_data'); $m_product_images = M('productImages'); $r_module = array('Log' => 'RLogProduct', 'File' => 'RFileProduct', 'rproductProduct', 'rContractProduct'); if ($this->isPost()) { $product_ids = is_array($_POST['product_id']) ? implode(',', $_POST['product_id']) : ''; if ('' == $product_ids) { alert('error', L('YOU_HAVE_NOT_CHOOSE_ANY_CONTENT'), $_SERVER['HTTP_REFERER']); } else { $productName = ''; foreach ($_POST['product_id'] as $k => $v) { $product = $m_product->where('product_id = %d', $v)->find(); if ($product) { $stock_count = M('stock')->where('product_id = %d', $product['product_id'])->sum('amounts'); if ($stock_count > 0) { $productName .= $product['name'] . ' '; } } } if (!empty($productName)) { alert('error', L('UNDER_THE_FOLLOWING_PRODUCTS_HAVE_IN_STOCK_YOU_CAN_NOT_DELETE', array($productName)), $_SERVER['HTTP_REFERER']); } if (!session('?admin')) { foreach ($_POST['product_id'] as $key => $value) { if (!$m_product->where('creator_role_id = %d and product_id = %d', session('role_id'), $value)->find()) { alert('error', L('YOU_DO_NOT_HAVE_PERMISSION_TO_OPERATE_ALL'), $_SERVER['HTTP_REFERER']); } } } $product_delete = $m_product->where('product_id in (%s)', $product_ids)->delete(); $product_data_delete = $m_product_data->where('product_id in (%s)', $product_ids)->delete(); if ($product_delete && $product_data_delete) { foreach ($_POST['product_id'] as $value) { actionLog($value); foreach ($r_module as $key2 => $value2) { $module_ids = M($value2)->where('product_id = %d', $value)->getField($key2 . '_id', true); M($value2)->where('product_id = %d', $value)->delete(); if (!is_int($key2)) { M($key2)->where($key2 . '_id in (%s)', implode(',', $module_ids))->delete(); } } //删除图片 $images_files = $m_product_images->where('product_id = %d', $value)->select(); foreach ($images_files as $files) { @unlink($files['path']); } $m_product_images->where('product_id = %d', $value)->delete(); } alert('success', L('DELETE_THE_SUCCESS'), U('product/index')); } else { alert('error', L('DELETE_FAILED_PLEASE_CONTACT_YOUR_ADMINISTRATOR'), $_SERVER['HTTP_REFERER']); } } } elseif ($_GET['id']) { $product_id = intval($_GET['id']); $product = $m_product->where('product_id = %d', $product_id)->find(); if (is_array($product)) { $stock_count = M('stock')->where('product_id = %d', $product['product_id'])->sum('amounts'); if ($stock_count > 0) { alert('error', L('THE_PRODUCT_IS_AVAILABLE_FROM_STOCK_AND_CAN_NOT_BE_DELETED'), $_SERVER['HTTP_REFERER']); } if (session('?admin') || $product['creator_role_id'] == session('role_id')) { if ($m_product->where('product_id = %d', $product_id)->delete()) { foreach ($r_module as $key2 => $value2) { if (!is_int($key2)) { $module_ids = M($value2)->where('product_id = %d', $product_id)->getField($key2 . '_id', true); M($value2)->where('product_id = %d', $product_id)->delete(); M($key2)->where($key2 . '_id in (%s)', implode(',', $module_ids))->delete(); } } //删除图片 $images_files = $m_product_images->where('product_id = %d', $product_id)->select(); foreach ($images_files as $files) { @unlink($files['path']); } $m_product_images->where('product_id = %d', $product_id)->delete(); alert('success', L('DELETE_THE_SUCCESS'), U('product/index')); } else { alert('error', L('DELETE_FAILED_PLEASE_CONTACT_YOUR_ADMINISTRATOR'), $_SERVER['HTTP_REFERER']); } } else { alert('error', L('YOU_HAVE_NO_PERMISSION'), $_SERVER['HTTP_REFERER']); } } else { alert('error', L('YOU_WANT_TO_DELETE_THE_RECORD_DOES_NOT_EXIST'), $_SERVER['HTTP_REFERER']); } } else { alert('error', L('PLEASE_SELECT_PRODUCT_TO_DELETE'), $_SERVER['HTTP_REFERER']); } }
/** *商机放入回收站 * **/ public function delete() { $m_business = M('business'); $business_ids = is_array($_REQUEST['business_id']) ? implode(',', $_REQUEST['business_id']) : $_REQUEST['id']; if ('' == $business_ids) { alert('error', L('YOU_DO_NOT_CHOOSE_ANY_CONTENT'), U('business/index')); } else { foreach ($_REQUEST['business_id'] as $v) { actionLog($v); } $data = array('is_deleted' => 1, 'delete_role_id' => session('role_id'), 'delete_time' => time()); $where['business_id'] = is_array($business_ids) ? array('in', $business_ids) : array('in', explode(',', $business_ids)); if ($m_business->where($where)->setField($data)) { alert('success', L('DELETE_THE_SUCCESS'), U('business/index')); } else { alert('error', L('DELETE_FAILED_PLEASE_CONTACT_YOUR_ADMINISTRATOR'), U('business/index')); } } }
/** * Send CURL post request * * @param $url * @param $data * @param string $action * * @param array $otherParams * @return mixed */ function sendPost($url, $data, $action = "", $otherParams = []) { $post_field_string = 'data=' . json_encode($data); if ($action != "") { $post_field_string .= '&action=' . $action; } if (count($otherParams)) { foreach ($otherParams as $param) { $post_field_string .= '&' . $param['key'] . '=' . $param['value']; } } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_field_string); curl_setopt($ch, CURLOPT_POST, true); $response = curl_exec($ch); curl_close($ch); // logger("API Request: ", ['Request' => $url, 'Data' => $data, 'Response' => $response]); actionLog($url, $data, $response); $jsonResponse = json_decode($response, true); /* if (!$jsonResponse) { return $response; } */ return $jsonResponse; }
public function edit() { if (!check_permission(intval($this->_request('id')), 'customer')) { $this->error(L('HAVE NOT PRIVILEGES')); } $customer = D('CustomerView')->where('customer.customer_id = %d', $this->_request('id'))->find(); if (!$customer) { alert('error', L('CUSTOMER_DOES_NOT_EXIST!'), $_SERVER['HTTP_REFERER']); } $customer['owner'] = D('RoleView')->where('role.role_id = %d', $customer['owner_role_id'])->find(); $customer['contacts_name'] = M('contacts')->where('contacts_id = %d', $customer['contacts_id'])->getField('name'); $field_list = M('Fields')->where('model = "customer"')->order('order_id')->select(); if ($this->isPost()) { $m_customer = D('Customer'); $m_customer_data = D('CustomerData'); foreach ($field_list as $v) { switch ($v['form_type']) { case 'address': $_POST[$v['field']] = implode(chr(10), $_POST[$v['field']]); break; case 'datetime': $_POST[$v['field']] = strtotime($_POST[$v['field']]); break; case 'box': eval('$field_type = ' . $v['setting'] . ';'); if ($field_type['type'] == 'checkbox') { $_POST[$v['field']] = implode(chr(10), $_POST[$v['field']]); } break; } } if ($m_customer->create()) { if ($m_customer_data->create() !== false) { $m_customer->update_time = time(); $a = $m_customer->where('customer_id =%s ', $customer['customer_id'])->save(); $b = $m_customer_data->where('customer_id =%s', $customer['customer_id'])->save(); if ($a !== false && $b !== false) { if ($_POST['contacts_id'] && $_POST['contacts_id'] != $customer['contacts_id']) { $rcc['contacts_id'] = intval($_POST['contacts_id']); $rcc['customer_id'] = $customer['customer_id']; if (!M('RContactsCustomer')->where($rcc)->find()) { M('RContactsCustomer')->add($rcc); } } actionLog($customer['customer_id']); alert('success', L('EDIT_CLIENTS_SUCCESS'), U('customer/index')); } else { alert('error', L('CUSTOMER_EDITING_FAILED!'), $_SERVER['HTTP_REFERER']); } } else { $this->error($m_customer_data->getError()); } } else { $this->error($m_customer->getError()); } } else { $alert = parseAlert(); $this->alert = $alert; $this->customer = $customer; $this->field_list = field_list_html("edit", "customer", $customer); $this->display(); } }
public function completedelete() { if (!session('?admin')) { alert('error', L('HAVE NOT PRIVILEGES'), $_SERVER['HTTP_REFERER']); } switch ($this->type) { case 'receivables': $receivables_ids = is_array($_REQUEST['receivables_id']) ? implode(',', $_REQUEST['receivables_id']) : $_REQUEST['id']; if ($receivables_ids == '') { alert('error', L('NOT CHOOSE ANY'), $_SERVER['HTTP_REFERER']); } $receivables = M('receivables'); if ($receivables->where('receivables_id in (%s)', $receivables_ids)->delete()) { $receivables_idsArr = explode(',', $receivables_ids); foreach ($receivables_idsArr as $v) { actionLog($v, 't=receivables'); } alert('success', L('DELETED SUCCESSFULLY'), $_SERVER['HTTP_REFERER']); } else { alert('error', L('DELETE FAILED CONTACT THE ADMINISTRATOR'), $_SERVER['HTTP_REFERER']); } break; case 'payables': $payables_ids = is_array($_REQUEST['payables_id']) ? implode(',', $_REQUEST['payables_id']) : $_REQUEST['id']; if ($payables_ids == '') { alert('error', '没有选中任何信息', $_SERVER['HTTP_REFERER']); } $payables = M('payables'); if ($payables->where('payables_id in (%s)', $payables_ids)->delete()) { $payables_idsArr = explode(',', $payables_ids); foreach ($payables_idsArr as $v) { actionLog($v, 't=payables'); } alert('success', L('DELETED SUCCESSFULLY'), $_SERVER['HTTP_REFERER']); } else { alert('error', L('DELETE FAILED CONTACT THE ADMINISTRATOR'), $_SERVER['HTTP_REFERER']); } break; case 'receivingorder': $receivingorder_ids = is_array($_REQUEST['receivingorder_id']) ? implode(',', $_REQUEST['receivingorder_id']) : $_REQUEST['id']; if ($receivingorder_ids == '') { alert('error', L('NOT CHOOSE ANY'), $_SERVER['HTTP_REFERER']); } $receivingorder = M('receivingorder'); if ($receivingorder->where('receivingorder_id in (%s)', $receivingorder_ids)->delete()) { $receivingorder_idsArr = explode(',', $receivingorder_ids); foreach ($receivingorder_idsArr as $v) { actionLog($v, 't=receivingorder'); } alert('success', L('DELETED SUCCESSFULLY'), $_SERVER['HTTP_REFERER']); } else { alert('error', L('DELETE FAILED CONTACT THE ADMINISTRATOR'), $_SERVER['HTTP_REFERER']); } break; case 'paymentorder': $paymentorder_ids = is_array($_REQUEST['paymentorder_id']) ? implode(',', $_REQUEST['paymentorder_id']) : $_REQUEST['id']; if ($paymentorder_ids == '') { alert('error', L('NOT CHOOSE ANY'), $_SERVER['HTTP_REFERER']); } $paymentorder = M('paymentorder'); if ($paymentorder->where('paymentorder_id in (%s)', $paymentorder_ids)->delete()) { $paymentorder_idsArr = explode(',', $paymentorder_ids); foreach ($paymentorder_idsArr as $v) { actionLog($v, 't=paymentorder'); } alert('success', L('DELETED SUCCESSFULLY'), $_SERVER['HTTP_REFERER']); } else { alert('error', L('DELETE FAILED CONTACT THE ADMINISTRATOR'), $_SERVER['HTTP_REFERER']); } break; } }
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')); } } }
public function log_delete() { $model = array("rLeadsLog", "rBusinessLog", "rLogProduct", "rCustomerLog", "rContactsLog", "rLogTask", "rEventLog", "rFinanceLog"); if ($_GET['id']) { $i = 0; $log_id = intval($_GET['id']); foreach ($model as $v) { if (M($v)->where('log_id = %d', $log_id)->delete()) { $i++; } } if ($i == 1) { if (M('log')->where('log_id = %d', $log_id)->delete()) { alert('success', L('DELETE_RELATED_LOG_SUCCESS'), U('log/anly')); } else { alert('error', L('DELETE_RELATED_LOG_FAILED'), $_SERVER['HTTP_REFERER']); } } elseif (M('log')->where('log_id = %d', $log_id)->delete()) { actionLog($log_id); alert('success', L('DELETED SUCCESSFULLY'), U('Log/index')); } } elseif (is_array($_POST['log_id'])) { $i = 0; foreach ($_POST['log_id'] as $v) { foreach ($model as $vv) { if (M($vv)->where('log_id = %d', $v)->delete()) { $i++; } } } if ($i >= 1) { $log_ids = implode(',', $_POST['log_id']); if (M('log')->where('log_id in (%s)', $log_ids)->delete()) { alert('success', L('DELETE_RELATED_LOG_SUCCESS'), U('Log/anly')); } else { alert('error', L('DELETE_RELATED_LOG_FAILED'), $_SERVER['HTTP_REFERER']); } } else { $log_ids = implode(',', $_POST['log_id']); if (M('log')->where('log_id in (%s)', $log_ids)->delete()) { alert('success', L('DELETE_RELATED_LOG_SUCCESS'), U('Log/index')); } else { alert('error', L('DELETE_RELATED_LOG_FAILED'), $_SERVER['HTTP_REFERER']); } } } else { alert('error', L('PLEASE SELECT DELETE ITEMS'), $_SERVER['HTTP_REFERER']); } }