public function init() { parent::init(); if (!$this->_user->isLogined()) { return $this->json(false, $this->lang['login_timeout']); } Tudu_AddressBook::getInstance()->setCache($this->cache); $this->lang = Tudu_Lang::getInstance()->load(array('common', 'tudu')); Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_MD => $this->multidb->getDefaultDb(), Tudu_Dao_Manager::DB_TS => $this->getTsDb())); $resourceManager = new Tudu_Model_ResourceManager_Registry(); $resourceManager->setResource(Tudu_Model::RESOURCE_CONFIG, $this->bootstrap->getOptions()); Tudu_Model::setResourceManager($resourceManager); }
/** * */ protected function _initApplication() { //$defaultDb = $this->multidb->getDb(); //Oray_Db_Helper::getInstance()->set('tudu-md', $defaultDb); Oray_Dao_Abstract::setDefaultAdapter($this->multidb->getDb()); Oray_Dao_Abstract::registerErrorHandler(array($this, 'daoErrorHandler')); Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_MD => $this->multidb->getDb('md'))); Tudu_User::setMemcache($this->getResource('memcache')); $resourceManager = new Tudu_Model_ResourceManager_Registry(); $resourceManager->setResource('config', $this->_options); Tudu_Model::setResourceManager($resourceManager); //set_error_handler(array($this, 'errorHandler')); }
/** * 删除回复 */ public function deleteAction() { $tuduId = $this->_request->getParam('tuduid'); $postId = $this->_request->getParam('postid'); if (!$tuduId) { throw new TuduX_OpenApi_Exception('Missing or invalid value of parameter "tuduid"', TuduX_OpenApi_ResponseCode::MISSING_PARAMETER); } if (!$postId) { throw new TuduX_OpenApi_Exception('Missing or invalid value of parameter "postid"', TuduX_OpenApi_ResponseCode::MISSING_PARAMETER); } /* @var $modelManage Model_Tudu_Manager_Tudu */ $modelManage = Tudu_Model::factory('Model_Tudu_Manager_Tudu'); $params = array('tuduid' => $tuduId, 'postid' => $postId); try { $modelManage->deletePost($params); } catch (Model_Tudu_Exception $e) { switch ($e->getCode()) { case Model_Tudu_Exception::INVALID_USER: $code = TuduX_OpenApi_ResponseCode::MISSING_AUTHORIZE; break; case Model_Tudu_Manager_Tudu::CODE_INVALID_TUDUID: case Model_Tudu_Manager_Tudu::CODE_INVALID_POSTID: $code = TuduX_OpenApi_ResponseCode::MISSING_PARAMETER; break; case Model_Tudu_Manager_Tudu::CODE_POST_NOTEXISTS: $code = TuduX_OpenApi_ResponseCode::RESOURCE_NOT_EXISTS; break; case Model_Tudu_Manager_Tudu::CODE_POST_FIRST: $code = TuduX_OpenApi_ResponseCode::CONTENT_POST_FIRST; break; case Model_Tudu_Manager_Tudu::CODE_DENY_ROLE: $code = TuduX_OpenApi_ResponseCode::ACCESS_DENIED; break; case Model_Tudu_Manager_Tudu::CODE_SAVE_FAILED: default: $code = TuduX_OpenApi_ResponseCode::OPERATE_FAILED; break; } throw new TuduX_OpenApi_Exception($e->getMessage(), $code); } $this->view->code = TuduX_OpenApi_ResponseCode::SUCCESS; }
/** * 认领图度 */ public function claimAction() { $tuduId = trim($this->_request->getParam('tid')); $resourceManager = new Tudu_Model_ResourceManager_Registry(); $resourceManager->setResource(Tudu_Model::RESOURCE_CONFIG, $this->bootstrap->getOptions()); Tudu_Model::setResourceManager($resourceManager); $model = new Model_Tudu_Manager_Tudu(); try { $model->claim(array('tuduid' => $tuduId)); } catch (Model_Tudu_Exception $e) { $err = $this->lang['tudu_claim_failed']; switch ($e->getCode()) { case Model_Tudu_Manager_Tudu::CODE_INVALID_TUDUID: $err = $this->lang['tudu_not_exists']; break; case Model_Tudu_Manager_Tudu::CODE_STEP_NOTCLAIM: $err = $this->lang['step_not_claim']; break; case Model_Tudu_Manager_Tudu::CODE_STEP_CLAIM_FINISH: $err = $this->lang['tudu_has_already_claim']; break; } return $this->json(false, $err); } return $this->json(true, $this->lang['tudu_claim_success']); }
/** * 标签操作 */ public function labelAction() { $tuduIds = explode(',', $this->_request->getParam('tuduid')); //$fun = $this->_request->getParam('fun'); //$labelId = explode(',', $this->_request->getParam('labelid')); $addLabels = explode(',', $this->_request->getParam('add')); $delLabels = explode(',', $this->_request->getParam('del')); if (empty($tuduIds)) { throw new TuduX_OpenApi_Exception('Missing or invalid value of parameter "tid"', TuduX_OpenApi_ResponseCode::MISSING_PARAMETER); } if (empty($addLabels) || empty($delLabels)) { throw new TuduX_OpenApi_Exception('Missing or invalid value of parameter "lid"', TuduX_OpenApi_ResponseCode::MISSING_PARAMETER); } $labels = array(); if (!empty($addLabels)) { foreach ($addLabels as $item) { $labels[$item] = 'add'; } } if (!empty($delLabels)) { foreach ($delLabels as $item) { $labels[$item] = 'delete'; } } $tuduManager = Tudu_Model::factory('Model_Tudu_Manage'); foreach ($tuduIds as $tuduId) { try { $tuduManager->label($tuduId, $labels); } catch (Model_Tudu_Exception $e) { $exception = $this->getException($e); throw new TuduX_OpenApi_Exception($exception['message'], $exception['code']); } } $this->view->code = TuduX_OpenApi_ResponseCode::SUCCESS; }
/** * 更新权限组成员 */ public function updateMemberAction() { /* @var $daoRole Dao_Md_User_Role */ $daoRole = $this->getDao('Dao_Md_User_Role'); /* @var $daoOrg Dao_Md_Org_Org */ $daoOrg = $this->getDao('Dao_Md_Org_Org'); $roleId = $this->_request->getPost('roleid'); $members = (array) $this->_request->getPost('userid'); if (!$roleId) { return $this->json(false, $this->lang['invalid_params_roleid']); } $role = $daoRole->getRole(array('orgid' => $this->_orgId, 'roleid' => $roleId)); if (null === $role) { return $this->json(false, $this->lang['role_not_exists']); } $users = $daoRole->getUserIds($this->_orgId, $roleId); /* @var $modelRole Model_User_Role*/ $modelRole = Tudu_Model::factory('Model_User_Role'); try { $modelRole->doUpdateMember(array('orgid' => $this->_orgId, 'roleid' => $roleId, 'users' => $members, 'isverify' => true)); } catch (Model_User_Exception $e) { switch ($e->getCode()) { case Model_User_Role::CODE_INVALID_ORGID: $message = '缺少参数[orgid]'; break; case Model_User_Role::CODE_INVALID_ROLEID: $message = '缺少参数[roleid]'; break; case Model_User_Role::CODE_ROLE_NOTEXISTS: $message = $this->lang['role_not_exists']; break; case Model_User_Role::CODE_SAVE_FAILED: $message = '更新权限组成员失败'; break; } return $this->json(false, $message); } $userIds = array_unique(array_merge($users, $members)); $this->_clearCache($userIds); //if ($roleId == '^admin') { //$removeAdmin = array_diff($users, $members); /*foreach ($removeAdmin as $userId) { $daoOrg->deleteAdmin($this->_orgId, $userId); }*/ /*foreach ($members as $userId) { $daoOrg->addAdmin($this->_orgId, $userId, 'SA', 3); }*/ //} $this->_createLog('role', 'update', 'member', $roleId, array('rolename' => $role->roleName)); return $this->json(true, '更新权限组成员成功'); }
/** * 删除用户 */ public function delete(array $params) { // 组织ID必须有 if (empty($params['orgid'])) { require_once 'Model/User/Exception.php'; throw new Model_User_Exception('Missing or invalid value of parameter "orgid"', self::CODE_INVALID_ORGID); } $orgId = $params['orgid']; /* @var $daoUser Dao_Md_User_User */ $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD); // 用户名 if (empty($params['userid'])) { require_once 'Model/User/Exception.php'; throw new Model_User_Exception('Missing the value of parameter "userid"', self::CODE_MISSING_UID); } $userIds = is_array($params['userid']) ? $params['userid'] : (array) $params['userid']; $ret = true; $uniqueIds = array(); foreach ($userIds as $userId) { $cuser = $daoUser->getUser(array('orgid' => $orgId, 'userid' => $userId)); $infouser = $daoUser->getUserInfo(array('orgid' => $orgId, 'userid' => $userId)); // 用户已不存在 if (null == $cuser) { continue; } // 是否超级管理员 if ($daoUser->isAdmin($orgId, $userId)) { require_once 'Model/User/Exception.php'; throw new Model_User_Exception('Can not delete super administrator "' . $userId . '@' . $orgId . '"', self::CODE_DELETE_SUPER_ADMIN); } if (!$daoUser->deleteUser($orgId, $userId)) { $ret = false; continue; } $uniqueIds[] = $cuser->uniqueId; // 添加操作日志 if (!empty($params['operator']) && !empty($params['clientip'])) { $params['local'] = empty($params['local']) ? null : $params['local']; $this->_createLog(Dao_Md_Log_Oplog::MODULE_USER, Dao_Md_Log_Oplog::OPERATION_DELETE, null, array('orgid' => $orgId, 'operator' => $params['operator'], 'clientip' => $params['clientip'], 'local' => $params['local']), implode(':', array($cuser->orgId, $cuser->userName, $cuser->uniqueId)), array('truename' => $infouser->trueName, 'account' => $cuser->userName)); } } if (!$ret) { require_once 'Model/User/Exception.php'; throw new Model_User_Exception('Delete user failed', self::CODE_SAVE_FAILED); } // 发送通知,插入消息队列 if (Tudu_Model::hasResource(Tudu_Model::RESOURCE_CONFIG)) { $config = Tudu_Model::getResource(Tudu_Model::RESOURCE_CONFIG); if ($config['httpsqs']) { $options = $config['httpsqs']; $httpsqs = new Oray_Httpsqs($options['host'], $options['port'], $options['charset'], $options['name']); $data = implode(' ', array(Dao_Md_Log_Oplog::MODULE_DEPT, Dao_Md_Log_Oplog::OPERATION_DELETE, null, implode(':', array($orgId, implode(',', $uniqueIds))))); $httpsqs->put($data); } } }
/** * 删除用户 */ public function deleteAction() { $userId = $this->_request->getPost('userid'); if (!$userId) { return $this->json(false, $this->lang['invalid_params_userid']); } $userIds = explode(',', $userId); $clientIp = isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $this->_request->getClientIp(); $local = !empty($this->_session->auth['local']) ? $this->_session->auth['local'] : null; /* @var $modelUser Model_User_User */ $modelUser = Tudu_Model::factory('Model_User_User'); $params = array('orgid' => $this->_orgId, 'userid' => $userIds, 'operator' => $this->_user->userId, 'clientip' => $clientIp, 'local' => $local); try { $modelUser->doDelete($params); foreach ($userIds as $userId) { // 清除相关缓存 $this->_clearUserCache($userId . '@' . $this->_orgId); } // 清空组织用户列表cache $this->_bootstrap->memcache->delete('TUDU-USER-LIST-' . $this->_orgId); } catch (Model_User_Exception $e) { $message = $this->lang['user_delete_failure']; switch ($e->getCode()) { case Model_User_User::CODE_INVALID_ORGID: $message = '缺少参数[orgid]'; break; case Model_User_User::CODE_MISSING_UID: $message = $this->lang['invalid_params_userid']; break; case Model_User_User::CODE_DELETE_SUPER_ADMIN: $message = '不能删除超级管理员帐号'; break; case Model_User_User::CODE_SAVE_FAILED: $message = $this->lang['user_delete_failure']; break; } return $this->json(false, $message); } $this->json(true, $this->lang['user_delete_success']); }
/** * 审批 */ public function reviewAction() { $post = $this->_request->getParams(); require_once 'Model/Tudu/Tudu.php'; $tudu = new Model_Tudu_Tudu(); $this->_formatParams($tudu, $post); $tudu->setAttributes(array('orgid' => $this->_user->orgId, 'uniqueid' => $this->_user->uniqueId, 'poster' => $this->_user->trueName, 'isagree' => $this->_request->getParam('agree', true), 'operation' => 'review')); try { /* @var $modelCompose Model_Tudu_Compose_Forward */ $modelCompose = Tudu_Model::factory('Model_Tudu_Compose_Review'); $params = array(&$tudu); $modelCompose->execute('compose', $params); // 考勤流程 if ($tudu->fromTudu->appId == 'attend' && $tudu->stepId == '^end') { $mtudu = new Tudu_Model_Tudu_Entity_Tudu($tudu->getAttributes()); Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_APP => $this->_bootstrap->multidb->getDb('app'))); $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP); $apply = $daoApply->getApply(array('tuduid' => $tudu->tuduId)); if (null !== $apply) { $mapply = new Tudu_Model_App_Attend_Tudu_Apply($apply->toArray()); $model = new Tudu_Model_App_Attend_Tudu_Extension_Apply(); $model->onReview($mtudu, $mapply); } } $config = $this->_bootstrap->getOption('httpsqs'); $tuduconf = $this->_bootstrap->getOption('tudu'); $sendType = isset($tuduconf['send']) ? ucfirst($tuduconf['send']['class']) : 'Common'; $sendClass = 'Model_Tudu_Send_' . $sendType; $modelSend = new $sendClass(array('httpsqs' => $config)); $modelSend->send(&$tudu); /*$config = $this->_bootstrap->getOption('httpsqs'); $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']); $action = 'review'; $sqsParam = array( 'tsid' => $this->_user->tsId, 'tuduid' => $tudu->tuduId, 'from' => $this->_user->userName, 'uniqueid' => $this->_user->uniqueId, 'server' => $this->_request->getServer('HTTP_HOST'), 'type' => $tudu->type, 'stepid' => $tudu->fromTudu->stepId, 'stepstatus' => $tudu->stepId && $tudu->fromTudu->stepId != $tudu->stepId && 0 !== strpos($tudu->stepId, '^'), 'nstepid' => $tudu->stepId, 'flowid' => $tudu->flowId, 'agree' => $this->_request->getParam('agree', true), 'ischangedCc' => ($action == 'update' && $tudu->cc) ? (boolean) $tudu->cc : false ); $httpsqs->put(implode(' ', array( 'tudu', $action, '', http_build_query($sqsParam) )), 'tudu');*/ } catch (Model_Tudu_Exception $e) { throw new TuduX_OpenApi_Exception('Tudu review failed', TuduX_OpenApi_ResponseCode::TUDU_SEND_FAILED); } $this->view->tuduid = $tudu->tuduId; $this->view->code = TuduX_OpenApi_ResponseCode::SUCCESS; }
/** * 删除logo */ public function logoDeleteAction() { /* @var $modelOrg Model_Org_Org*/ $modelOrg = Tudu_Model::factory('Model_Org_Org'); try { $modelOrg->execute('updateOrg', array(array('orgid' => $this->_orgId, 'logo' => null))); } catch (Model_Org_Exception $e) { switch ($e->getCode()) { case Model_Org_Org::CODE_INVALID_ORGID: $message = '缺少参数[orgid]'; break; case Model_Org_Org::CODE_ORG_NOTEXISTS: $message = '组织不存在或已被删除'; break; case Model_Org_Org::CODE_SAVE_FAILED: $message = '还原默认Logo失败'; break; } return $this->json(false, $message); } return $this->json(true, $this->lang['logo_revert_success']); }
/** * 排序 */ public function sortAction() { $deptId = str_replace('_', '^', $this->_request->getPost('deptid')); $type = $this->_request->getPost('type'); $clientIp = isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $this->_request->getClientIp(); $local = !empty($this->_session->auth['local']) ? $this->_session->auth['local'] : null; /* @var $modelDept Model_Department_Department */ $modelDept = Tudu_Model::factory('Model_Department_Department'); $params = array('orgid' => $this->_orgId, 'deptid' => $deptId, 'operator' => $this->_user->userId, 'clientip' => $clientIp, 'local' => $local); try { $modelDept->addAction('update', array($modelDept, 'sort'), 1, array($this->_orgId, $deptId, $type, $params), false); $modelDept->execute('update', array($params)); } catch (Model_Department_Exception $e) { $message = '排序失败,请刷新页面后重试'; switch ($e->getCode()) { case Model_Department_Department::CODE_INVALID_DEPTID: $message = '缺少参数[deptid]'; break; case Model_Department_Department::CODE_INVALID_ORGID: $message = '缺少参数[orgid]'; break; case Model_Department_Department::CODE_SAVE_FAILED: $message = '排序失败,请刷新页面后重试'; break; } return $this->json(false, $message); } return $this->json(true); }
/** * 创建图度组织 */ public function createOrg() { if (empty($this->_orgParams)) { require_once 'Tudu/Install/Exception.php'; throw new Tudu_Install_Exception('empty org params'); } if (empty($this->_configs['mysql'])) { require_once 'Tudu/Install/Exception.php'; throw new Tudu_Install_Exception('empty configs database'); } $this->_configs['mysql'] = array_merge($this->_configs['mysql'], array('charset' => 'utf8')); require_once 'Zend/Db.php'; require_once 'Zend/Db/Exception.php'; $db = Zend_Db::factory('pdo_mysql', $this->_configs['mysql']); require_once 'Tudu/Dao/Manager.php'; Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_MD => $db, Tudu_Dao_Manager::DB_TS => $db)); if (!empty($this->_dataPath)) { $dataPath = array('data' => array('path' => $this->_dataPath)); require_once 'Tudu/Model.php'; require_once 'Tudu/Model/ResourceManager/Registry.php'; $resourceManager = new Tudu_Model_ResourceManager_Registry(); $resourceManager->setResource('config', $dataPath); Tudu_Model::setResourceManager($resourceManager); } require_once 'Model/Org/Org.php'; require_once 'Model/Org/Exception.php'; /* @var $modelOrg Model_Org_Org */ $modelOrg = Tudu_Model::factory('Model_Org_Org'); try { $modelOrg->addAction('create', array($modelOrg, 'createAdmin'), 10); $modelOrg->addAction('create', array($modelOrg, 'active'), 9); $modelOrg->execute('create', array(array('orgid' => $this->_orgParams['orgid'], 'orgname' => $this->_orgParams['orgname'], 'userid' => $this->_orgParams['userid'], 'password' => $this->_orgParams['password'], 'truename' => $this->_orgParams['userid'], 'domain' => $this->_orgParams['domain']))); } catch (Model_Org_Exception $e) { require_once 'Tudu/Install/Exception.php'; throw new Tudu_Install_Exception($e->getMessage()); } }
/** * 获取资源 * * @param string $name * @return mixed */ public function getResource($name) { return Tudu_Model::getResource($name); }
/** * 确认图度 * * 必传参数: * tuduid|uniqueid|username|orgid|userinfo|tsid * isdone不传值为false * score不传值为0 */ public function done(array $params) { if (empty($params['tuduid'])) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Missing or invalid value of parameter "tuduid"', self::CODE_INVALID_TUDUID); } $uniqueId = $this->_user->uniqueId; $userName = $this->_user->userName; $tuduIds = !is_array($params['tuduid']) ? (array) $params['tuduid'] : $params['tuduid']; $isDone = !empty($params['isdone']) ? true : false; $score = !empty($params['score']) ? (int) $params['score'] : 0; $manager = $this->getManager(); $success = 0; //用于计数操作成功个数 foreach ($tuduIds as $tuduId) { $tudu = $manager->getTuduById($tuduId, $uniqueId); // 图度必须存在 if (null == $tudu) { continue; } // 图度不能是已确定状态 if ($tudu->isDone && $isDone) { continue; } // 操作人必须为图度发起人 if ($tudu->sender != $userName) { continue; } // 图度不能是“未开始”,“进行中”等状态 if (($tudu->type != 'task' || $tudu->status < 2) && $isDone) { continue; } if (!$isDone) { $score = 0; } // 执行确认/取消确认图度操作 $ret = $manager->doneTudu($tuduId, $isDone, $score, false, $tudu->parentId != null, $tudu->type); if ($ret) { $success++; // 添加操作日志 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, $isDone ? Dao_Td_Log_Log::ACTION_TUDU_DONE : Dao_Td_Log_Log::ACTION_TUDU_UNDONE, array('orgid' => $this->_user->orgId, 'uniqueid' => $uniqueId, 'userinfo' => $this->_user->userInfo), array('isdone' => $isDone, 'score' => $score)); // 发送通知,插入消息队列 if (Tudu_Model::hasResource(Tudu_Model::RESOURCE_CONFIG)) { $config = Tudu_Model::getResource(Tudu_Model::RESOURCE_CONFIG); if ($config['httpsqs']) { $options = $config['httpsqs']; $httpsqs = new Oray_Httpsqs($options['host'], $options['port'], $options['charset'], $options['name']); $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $this->_user->tsId, 'tuduid' => $tuduId, 'uniqueid' => $uniqueId, 'to' => '', 'act' => 'confirm')))); $httpsqs->put($data, 'send'); } } } } if ($success <= 0) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Append to inbox failed', self::CODE_SAVE_FAILED); } }
/** * 部门成员 * * @param string $orgId * @param string $deptId * @param array $member * @param array $params */ public function updateMember($orgId, $deptId, array $member, array $params) { /* @var $daoDept Dao_Md_Department_Department */ $daoDept = Tudu_Dao_Manager::getDao('Dao_Md_Department_Department', Tudu_Dao_Manager::DB_MD); if (empty($deptId)) { require_once 'Model/Department/Exception.php'; throw new Model_Department_Exception('Invalid or missing parameter "deptid"', self::CODE_INVALID_DEPTID); } if (empty($orgId)) { require_once 'Model/Department/Exception.php'; throw new Model_Department_Exception('Invalid or missing params "orgid"', self::CODE_INVALID_ORGID); } $department = $daoDept->getDepartment(array('orgid' => $orgId, 'deptid' => $deptId)); if (!$department) { require_once 'Model/Department/Exception.php'; throw new Model_Department_Exception('Parent department not exists', self::CODE_DEPARTMENT_NOTEXISTS); } $ret = $daoDept->removeUser($orgId, $deptId); if (!$ret) { require_once 'Model/Department/Exception.php'; throw new Model_Department_Exception('Update department failed', self::CODE_SAVE_FAILED); } if (!empty($member)) { $ret = $daoDept->addUser($orgId, $deptId, $member); if (!$ret) { require_once 'Model/Department/Exception.php'; throw new Model_Department_Exception('Update department failed', self::CODE_SAVE_FAILED); } /* @var $daoCast Dao_Md_User_Cast */ $daoCast = Tudu_Dao_Manager::getDao('Dao_Md_User_Cast', Tudu_Dao_Manager::DB_MD); foreach ($member as $userId) { $daoCast->updateCastDept($orgId, $userId, $deptId); } } // 添加后台操作日志 if (!empty($params['operator']) && !empty($params['clientip'])) { $params['local'] = empty($params['local']) ? null : $params['local']; $this->_createLog(Dao_Md_Log_Oplog::MODULE_DEPT, Dao_Md_Log_Oplog::OPERATION_UPDATE, 'user', array('orgid' => $orgId, 'operator' => $params['operator'], 'clientip' => $params['clientip'], 'local' => $params['local']), implode(':', array($orgId, $deptId)), array('deptname' => $department->deptName)); } // 发送通知 if (Tudu_Model::hasResource(Tudu_Model::RESOURCE_CONFIG)) { $config = Tudu_Model::getResource(Tudu_Model::RESOURCE_CONFIG); if ($config['httpsqs']) { $options = $config['httpsqs']; $httpsqs = new Oray_Httpsqs($options['host'], $options['port'], $options['charset'], $options['name']); $data = implode(' ', array(Dao_Md_Log_Oplog::MODULE_USER, Dao_Md_Log_Oplog::OPERATION_UPDATE, null, implode(':', array($orgId, $deptId)))); $ret = $httpsqs->put($data); } } }
/** * 向群组添加成员 */ public function addMemberAction() { /* @var @daoGroup Dao_Md_User_Group */ $daoGroup = $this->getDao('Dao_Md_User_Group'); /* @var $daoOrg Dao_Md_Org_Org */ $daoOrg = $this->getDao('Dao_Md_Org_Org'); $groupId = $this->_request->getParam('groupid'); $key = (array) $this->_request->getParam('key'); $message = ''; /* @var $modelGroup Model_User_Group*/ $modelGroup = Tudu_Model::factory('Model_User_Group'); try { $modelGroup->doAddUser(array('orgid' => $this->_orgId, 'groupid' => $groupId, 'userid' => $key)); } catch (Model_User_Exception $e) { switch ($e->getCode()) { case Model_User_Group::CODE_INVALID_ORGID: $message = '缺少参数[orgid]'; break; case Model_User_Group::CODE_INVALID_GROUPID: $message = $this->lang['invalid_params_groupid']; break; case Model_User_Group::CODE_INVALID_UID: $message = '缺少群组成员'; break; case Model_User_Group::CODE_GROUP_NOTEXISTS: $message = '该群组不存在或已被删除'; break; case Model_User_Group::CODE_SAVE_FAILED: $message = $this->lang['group_member_failure']; break; } return $this->json(false, $message); } foreach ($key as $userId) { if (!$userId) { continue; } $this->_clearUserCache($userId . '@' . $this->_orgId); } $this->setUpdateCastTime(); return $this->json(true, $this->lang['operate_success']); }
/** * 创建组织超级管理员 * * @param array $params */ public function createAdmin(array $params) { //echo 'create admin', "\n"; /* @var $daoUser Dao_Md_User_User */ $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD); if (empty($params['userid'])) { require_once 'Model/Org/Exception.php'; throw new Model_Org_Exception('Missing or invalid value of parameter "uid"', self::CODE_INVALID_UID); } if (empty($params['orgid'])) { require_once 'Model/Org/Exception.php'; throw new Model_Org_Exception('Missing or invalid value of parameter "orgid"', self::CODE_INVALID_ORGID); } if (empty($params['password'])) { require_once 'Model/Org/Exception.php'; throw new Model_Org_Exception('Missing or invalid value of parameter "password"', self::CODE_INVALID_PWD); } $orgId = $params['orgid']; $userId = $params['userid']; $password = $params['password']; $trueName = $params['truename']; $uniqueId = Dao_Md_User_User::getUniqueId($orgId, $userId); /* @var $daoUser Dao_Md_User_User */ $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD); /* @var $daoGroup Dao_Md_User_Group */ $daoGroup = Tudu_Dao_Manager::getDao('Dao_Md_User_Group', Tudu_Dao_Manager::DB_MD); /* @var $daoRole Dao_Md_User_Role */ $daoRole = Tudu_Dao_Manager::getDao('Dao_Md_User_Role', Tudu_Dao_Manager::DB_MD); /* @var $daoOrg Dao_Md_Org_Org*/ $daoOrg = Tudu_Dao_Manager::getDao('Dao_Md_Org_Org', Tudu_Dao_Manager::DB_MD); $org = $daoOrg->getOrgById($orgId); if (!$org) { require_once 'Model/Org/Exception.php'; throw new Model_Org_Exception('Org id "' . $orgId . '" not exists', self::CODE_ORG_NOTEXISTS); } // 创建超级管理员用户 $user = array('orgid' => $orgId, 'userid' => $userId, 'uniqueid' => $uniqueId, 'status' => 1, 'isshow' => 1); $userInfo = array('orgid' => $orgId, 'userid' => $userId, 'truename' => $trueName, 'ismd5' => true, 'password' => $password); $ret = $daoUser->createUser($user); if (!$ret) { require_once 'Model/Org/Exception.php'; throw new Model_Org_Exception('Create user data failed', self::CODE_SAVE_FAILED); } $ret = $daoUser->createUserInfo($userInfo); if (!$ret) { require_once 'Model/Org/Exception.php'; throw new Model_Org_Exception('Create user info failed', self::CODE_SAVE_FAILED); } // 添加群组 - 全体员工 $daoGroup->addUser($orgId, '^all', $userId); // 添加权限 - 管理员 $daoRole->addUsers($orgId, '^admin', $userId); // 添加管理员 $daoOrg->addAdmin($orgId, $userId, 'SA', 3); if (!empty($params['email'])) { // 绑定邮箱 $daoUser->createEmail(array('orgid' => $orgId, 'userid' => $userId, 'email' => $params['email'])); } /* @var $daoCast Dao_Md_User_Cast */ $daoCast = Tudu_Dao_Manager::getDao('Dao_Md_User_Cast', Tudu_Dao_Manager::DB_MD); // 看到自己 $daoCast->addUser($orgId, $userId, $userId); // 看到根部门 $daoCast->addDepartment($orgId, $userId, '^root'); // 创建欢迎公告 try { $config = Tudu_Model::getResource('config'); if (!empty($config['path']['data']) || !empty($config['data']['path'])) { $tplFile = !empty($config['path']['data']) ? $config['path']['data'] : $config['data']['path']; $content = @file_get_contents($tplFile . '/templates/tudu/welcome.tpl'); if (!empty($content)) { require_once 'Tudu/Deliver.php'; $deliver = new Tudu_Deliver(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS)); $tudu = array('orgid' => $orgId, 'tuduid' => md5($orgId . '-welcome'), 'boardid' => '^system', 'uniqueid' => '^system', 'type' => 'notice', 'subject' => '欢迎使用图度工作管理系统!!', 'email' => '*****@*****.**', 'from' => '^system 图度系统', 'to' => null, 'cc' => null, 'priority' => 0, 'privacy' => 0, 'issend' => 1, 'status' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'content' => $content, 'poster' => '图度系统', 'posterinfo' => '', 'lastposter' => '图度系统', 'lastposttime' => time(), 'createtime' => time(), 'attachment' => array()); $deliver->createTudu($tudu); $deliver->sendTudu($tudu['tuduid'], array()); if (!empty($uniqueId)) { $deliver->addRecipient($tudu['tuduid'], $uniqueId); $deliver->addLabel($tudu['tuduid'], $uniqueId, '^all'); $deliver->addLabel($tudu['tuduid'], $uniqueId, '^i'); $deliver->addLabel($tudu['tuduid'], $uniqueId, '^n'); } } } } catch (Exception $e) { } }