コード例 #1
0
ファイル: Category.php プロジェクト: bjtenao/tudu-web
 /**
  * 编辑考勤分类
  */
 public function modifyAction()
 {
     $categoryId = $this->_request->getQuery('categoryid');
     if ($categoryId) {
         /* @var $daoCategory Dao_App_Attend_Category */
         $daoCategory = Tudu_Dao_Manager::getDao('Dao_App_Attend_Category', Tudu_Dao_Manager::DB_APP);
         $condition = array('categoryid' => $categoryId, 'orgid' => $this->_user->orgId);
         $category = $daoCategory->getCategory($condition);
         if (null === $category) {
             /**
              * @see Oray_Function
              */
             require_once 'Oray/Function.php';
             Oray_Function::alert($this->lang['category_not_exists'], '/app/attend/category/index');
         }
         $category = $category->toArray();
         foreach ($category['flowsteps'] as $key => &$step) {
             if (isset($step['sections'])) {
                 $step['users'] = $this->_formatStepSection($step['sections']);
             }
             if (isset($step['branches'])) {
                 foreach ($step['branches'] as &$branch) {
                     if (isset($branch['sections'])) {
                         $branch['users'] = $this->_formatStepSection($branch['sections']);
                     }
                 }
             }
         }
         $this->view->category = $category;
         $this->view->action = self::ACTION_UPDATE;
     } else {
         $this->view->action = self::ACTION_CREATE;
     }
 }
コード例 #2
0
ファイル: InfoController.php プロジェクト: bjtenao/tudu-web
 /**
  * 保存设置
  */
 public function saveAction()
 {
     $action = $this->_request->getPost('action');
     $post = $this->_request->getPost();
     if (empty($post['orgname'])) {
         return $this->json(false, '请输入组织简称');
     }
     if (!empty($post['intro']) && Oray_Function::strLen($post['intro']) > 300) {
         return $this->json(false, '组织简介长度请控制在300字符以内');
     }
     /* @var $modelOrg Model_Org_Org*/
     $modelOrg = Tudu_Model::factory('Model_Org_Org');
     try {
         $modelOrg->execute('info', array(array('orgid' => $this->_orgId, 'entirename' => $post['entirename'])));
         $modelOrg->execute('updateOrg', array(array('orgid' => $this->_orgId, 'orgname' => $post['orgname'], 'intro' => $post['intro'])));
     } 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_INVALID_ORGNAME:
                 $message = '请输入组织简称';
                 break;
             case Model_Org_Org::CODE_SAVE_FAILED:
                 $message = '更新组织信息失败';
                 break;
         }
         return $this->json(false, $message);
     }
     $this->_cleanCache();
     return $this->json(true, '更新企业信息成功');
 }
コード例 #3
0
ファイル: Abstract.php プロジェクト: bjtenao/tudu-web
 /**
  * 验证APP
  */
 public function checkApp()
 {
     /* @var $daoApp Dao_App_App_App */
     $daoApp = Tudu_Dao_Manager::getDao('Dao_App_App_App', Tudu_Dao_Manager::DB_APP);
     $app = $daoApp->getApp(array('orgid' => $this->_user->orgId, 'appid' => $this->_appId));
     if ($app === null) {
         Oray_Function::alert($this->lang['warn_app_not_exists']);
     }
     if ($app->status == 0) {
         Oray_Function::alert($this->lang['warn_app_initialization']);
     }
     if ($app->status == 2) {
         Oray_Function::alert($this->lang['warn_app_status_stop']);
     }
     if ($app->activeTime === null || $app->activeTime > time()) {
         Oray_Function::alert($this->lang['warn_app_active_time']);
     }
     $this->_settings = $app->settings;
 }
コード例 #4
0
 /**
  * 登录验证
  */
 public function preDispatch()
 {
     $action = strtolower($this->_request->getActionName());
     if (!$this->_user->isAdminLogined()) {
         if (in_array($action, array('save'))) {
             return $this->json(false, '登陆超时,请重新登陆');
         } else {
             $this->destroySession();
             $this->referer($this->_request->getBasePath() . '/login/');
         }
     }
     if (!$this->_user->isOwner()) {
         if (in_array($action, array('save'))) {
             return $this->json(false, '非超级管理员帐户不能进行该操作');
         } else {
             Oray_Function::alert('非超级管理员帐户不能进行该操作');
         }
     }
 }
コード例 #5
0
ファイル: Cycle.php プロジェクト: bjtenao/tudu-web
 /**
  * 格式化周期任务参数
  *
  * @param array  $params
  * @param string $suffix
  * @return array
  */
 public function formatParams($params, $suffix = '')
 {
     $cycle = array();
     if (!empty($params['cycleid' . $suffix])) {
         $cycle['cycleid'] = $params['cycleid' . $suffix];
     } else {
         $cycle['cycleid'] = Dao_Td_Tudu_Cycle::getCycleId();
     }
     $cycle['mode'] = $params['mode' . $suffix];
     $cycle['endtype'] = $params['endtype' . $suffix];
     $cycle['displaydate'] = $params['displaydate' . $suffix];
     // 重复范围
     if ($cycle['endtype'] == Dao_Td_Tudu_Cycle::END_TYPE_COUNT) {
         $cycle['endcount'] = (int) $params['endcount' . $suffix];
     } elseif ($cycle['endtype'] == Dao_Td_Tudu_Cycle::END_TYPE_DATE) {
         $cycle['enddate'] = @strtotime($params['enddate' . $suffix]);
     } else {
         $cycle['endtype'] = Dao_Td_Tudu_Cycle::END_TYPE_NONE;
     }
     if ($cycle['displaydate'] == 1 && empty($params['starttime' . $suffix])) {
         $params['starttime'] = time();
     }
     $cycle['type'] = (int) $params['type' . '-' . $cycle['mode'] . $suffix];
     $prefix = $cycle['mode' . $suffix] . '-' . $cycle['type' . $suffix] . '-';
     $cycle['day'] = isset($params[$prefix . 'day' . $suffix]) ? (int) $params[$prefix . 'day' . $suffix] : 0;
     $cycle['week'] = isset($params[$prefix . 'week' . $suffix]) ? (int) $params[$prefix . 'week' . $suffix] : 0;
     $cycle['month'] = isset($params[$prefix . 'month' . $suffix]) ? (int) $params[$prefix . 'month' . $suffix] : 0;
     $cycle['iskeepattach'] = !empty($params['iskeepattach' . $suffix]) ? 1 : 0;
     if (isset($params[$prefix . 'weeks'])) {
         $cycle['weeks'] = implode(',', $params[$prefix . 'weeks' . $suffix]);
     }
     if (isset($params[$prefix . 'at'])) {
         $cycle['at'] = (int) $params[$prefix . 'at' . $suffix];
     }
     if (isset($params[$prefix . 'what'])) {
         $cycle['what'] = $params[$prefix . 'what' . $suffix];
     }
     if (!empty($params['starttime' . $suffix]) && !empty($params['endtime' . $suffix])) {
         $cycle['period'] = Oray_Function::dateDiff('d', strtotime($params['starttime' . $suffix]), strtotime($params['endtime' . $suffix]));
     }
     return $cycle;
 }
コード例 #6
0
 /**
  * 输出临时图片文件(只输出未关联到任何回复的附件,主要用于编辑器新上传的图片显示)
  */
 public function imgAction()
 {
     $this->_helper->viewRenderer->setNeverRender();
     $fid = $this->_request->getQuery('aid');
     /* @var $file Dao_Td_Attachment_Record_File */
     $file = $this->getDao('Dao_Td_Attachment_File')->getFile(array('fileid' => $fid));
     if (null === $file || $file->tuduId || $file->uniqueId != $this->_user['uniqueid']) {
         return;
     }
     $sid = Zend_Session::getId();
     $auth = md5($sid . $fid . $this->_session->auth['logintime']);
     $url = $this->_options['sites']['file'] . $this->_options['upload']['cgi']['download'] . "?sid={$sid}&fid={$fid}&auth={$auth}&email={$this->_session->auth['address']}&action=view";
     $content = Oray_Function::httpRequest($url);
     $this->_response->setHeader('Content-Length', strlen($content));
     $this->_response->setHeader('Content-Type', $file->type);
     $this->_response->sendHeaders();
     echo $content;
     // 取消输出
     $this->getFrontController()->returnResponse(true);
 }
コード例 #7
0
ファイル: Admin.php プロジェクト: bjtenao/tudu-web
 /**
  * 显示设置页面
  */
 public function indexAction()
 {
     $daoAppUser = Tudu_Dao_Manager::getDao('Dao_App_App_User', Tudu_Dao_Manager::DB_APP);
     $daoApp = Tudu_Dao_Manager::getDao('Dao_App_App_App', Tudu_Dao_Manager::DB_APP);
     $app = $daoApp->getApp(array('orgid' => $this->_user->orgId, 'appid' => $this->_appId));
     // 没安装或过期
     if (null === $app || $app->expireDate && $app->expireDate < time()) {
         return Oray_Function::alert('您还没有安装该应用或已过期');
     }
     $users = $daoAppUser->getAppUsers(array('orgid' => $this->_user->orgId, 'appid' => $this->_appId))->toArray();
     $roles = array();
     foreach ($users as $user) {
         $roles[$user['role']][] = $user['itemid'];
     }
     $app = $app->toArray();
     $settings = $app['settings'];
     if (empty($settings) || !isset($settings['checkoutremind'])) {
         $app['settings']['checkoutremind'] = 1;
     }
     $this->view->roles = $roles;
     $this->view->app = $app;
 }
コード例 #8
0
ファイル: Oplog.php プロジェクト: bjtenao/tudu-web
 /**
  * Get record page
  *
  * @param array $condition
  * @param mixed $sort
  * @param int $page
  * @param int $pageSize
  * @return Oray_Dao_Recordset
  */
 public function getAdminLogPage(array $condition = null, $sort = null, $page = null, $pageSize = null)
 {
     $table = 'md_op_log';
     $columns = 'org_id AS orgid, user_id AS userid, module, action, sub_action AS subaction, ' . 'target, ip, local, create_time AS createtime, detail';
     $primary = 'create_time';
     $recordClass = "Dao_Md_Log_Record_Oplog";
     $where = array();
     $order = array();
     if (!empty($condition['userid'])) {
         $where[] = 'user_id = ' . $this->_db->quote($condition['userid']);
     }
     if (!empty($condition['orgid'])) {
         $where[] = 'org_id = ' . $this->_db->quote($condition['orgid']);
     }
     if (!empty($condition['module'])) {
         $where[] = 'module = ' . $this->_db->quote($condition['module']);
     }
     /*if (!empty($condition['starttime']) && !empty($condition['endtime'])) {
                 $where[] = 'create_time >= UNIX_TIMESTAMP(' . $this->_db->quote($condition['starttime']) . ') AND create_time <= UNIX_TIMESTAMP(' . $this->_db->quote($condition['endtime']) . ')';
             }
     
             if (!empty($condition['starttime']) && empty($condition['endtime'])) {
                 $where[] = 'create_time >= UNIX_TIMESTAMP(' . $this->_db->quote($condition['starttime']) . ')';
             }
     
             if (empty($condition['starttime']) && !empty($condition['endtime'])) {
                 $where[] = 'create_time <= UNIX_TIMESTAMP(' . $this->_db->quote($condition['endtime']) . ')';
             }*/
     if (isset($condition['createtime'])) {
         if (is_int($condition['createtime'])) {
             $where[] = 'create_time = ' . $condition['createtime'];
         } elseif (is_array($condition['createtime'])) {
             $arr = $condition['createtime'];
             if (isset($arr[0]) && is_int($arr[0])) {
                 $where[] = 'create_time >= ' . $arr[0];
             }
             if (isset($arr[1]) && is_int($arr[1])) {
                 $where[] = 'create_time <=' . $arr[1];
             }
         }
     }
     if (!empty($condition['keywords']) && Oray_Function::isByte($condition['keywords'])) {
         $keyword = $this->_db->quote('%' . $condition['keywords'] . '%');
         $where[] = "(user_id LIKE {$keyword} OR ip LIKE {$keyword})";
     }
     // WHERE
     $where = implode(' AND ', $where);
     // 格式化排序参数
     $sort = $this->_formatSort($sort);
     foreach ($sort as $key => $val) {
         switch ($key) {
             case 'createtime':
                 $key = 'create_time';
                 break;
             default:
                 continue 2;
                 break;
         }
         $order[] = $key . ' ' . $val;
     }
     // ORDER
     $order = implode(', ', $order);
     // 使用默认的分页大小
     if (null === $pageSize) {
         $pageSize = self::$_defaultPageSize;
     }
     /**
      * @see Oray_Db_Paginator
      */
     require_once 'Oray/Db/Paginator.php';
     // 初始化分页器
     $paginator = new Oray_Db_Paginator(array(Oray_Db_Paginator::ADAPTER => $this->_db, Oray_Db_Paginator::RECORD_CLASS => $recordClass, Oray_Db_Paginator::PAGE_SIZE => $pageSize, Oray_Db_Paginator::TABLE => $table, Oray_Db_Paginator::PRIMARY => $primary, Oray_Db_Paginator::COLUMNS => $columns, Oray_Db_Paginator::WHERE => $where, Oray_Db_Paginator::ORDER => $order));
     // 返回查询结果
     return $paginator->query($page);
 }
コード例 #9
0
ファイル: TuduController.php プロジェクト: bjtenao/tudu-web
 /**
  * 回复编辑页面
  */
 public function postAction()
 {
     $postId = $this->_request->getQuery('pid');
     $post = array();
     $access = array('upload' => true, 'progress' => $this->_user['role'] == Dao_Td_Tudu_Tudu::ROLE_ACCEPTER);
     $content = $this->_request->getPost('content');
     if (!empty($content)) {
         $post['content'] = $content;
     }
     if ($postId) {
         /* @var $daoPost Dao_Td_Tudu_Post */
         $daoPost = $this->getDao('Dao_Td_Tudu_Post');
         $post = $daoPost->getPost(array('tuduid' => $this->_tudu->tuduId, 'postid' => $postId));
         if ($post === null) {
             return Oray_Function::alert($this->lang['post_not_exists']);
         }
         // 不是回复者时,读取版主的权限
         if ($post->uniqueId !== $this->_user->uniqueId) {
             Oray_Function::alert($this->lang['perm_deny_update_post']);
         }
         if ($post->attachNum > 0) {
             /* @var $daoFile Dao_Td_Attachment_File */
             $daoFile = $this->getDao('Dao_Td_Attachment_File');
             $attachments = $daoFile->getFiles(array('tuduid' => $post->tuduId, 'postid' => $post->postId));
             $post->attachments = $attachments->toArray();
         }
         $access['progress'] = $post->isLog && in_array($this->_user->email, $tudu->accepter) && $tudu->selfTuduStatus < Dao_Td_Tudu_Tudu::STATUS_DONE;
         $post = $post->toArray();
     }
     $cookies = $this->_request->getCookie();
     $this->view->registModifier('tudu_format_content', array($this, 'formatContent'));
     $upload = $this->_options['upload'];
     $upload['cgi']['upload'] .= '?authtype=foreign&' . session_name() . '=' . $this->_sessionId . '&email=' . $this->_user['email'];
     $this->view->upload = $upload;
     $this->view->cookies = serialize($cookies);
     $this->view->post = $post;
     $this->view->tudu = $this->_tudu->toArray();
     $this->view->access = $access;
     $this->render('modify_post');
 }
コード例 #10
0
ファイル: Send.php プロジェクト: bjtenao/tudu-web
 /**
  * 外发会议
  *
  * @param array $params
  */
 public function sendMeeting($params)
 {
     if (empty($params['tuduid']) || empty($params['tsid']) || empty($params['uniqueid']) || empty($params['from']) || empty($params['content']) || empty($params['location'])) {
         return;
     }
     $tuduId = $params['tuduid'];
     $uniqueId = $params['uniqueid'];
     $tsId = $params['tsid'];
     $to = !empty($params['to']) ? explode(',', $params['to']) : null;
     $sender = $params['from'];
     $content = $params['content'];
     $location = $params['location'];
     /* @var $manager Tudu_Tudu_Manager */
     $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     $tudu = $manager->getTuduById($tuduId, $uniqueId);
     if (null == $tudu) {
         $this->getLogger()->warn("Tudu id:{$tuduId} is not exists");
         return;
     }
     // 获取接收人
     $receivers = $manager->getTuduUsers($tudu->tuduId);
     $emails = array();
     /* @var $daoContact Dao_Td_Contact_Contact */
     $daoContact = Tudu_Dao_Manager::getDao('Dao_Td_Contact_Contact', Tudu_Dao_Manager::DB_TS);
     // 处理接收人数据
     foreach ($receivers as $receiver) {
         $info = explode(' ', $receiver['accepterinfo'], 3);
         $email = $info[0];
         $name = !empty($info[1]) ? $info[1] : null;
         $contactId = isset($info[2]) ? $info[2] : null;
         if ($name == null && $email) {
             $arr = explode('@', $email);
             $name = array_shift($arr);
         }
         if (!$email && !$name) {
             continue;
         }
         if (!empty($to) && !in_array($email, $to)) {
             continue;
         }
         if ($receiver['isforeign']) {
             $auth = $receiver['authcode'];
             if (Oray_Function::isEmail($email) && $uniqueId != $receiver['uniqueid']) {
                 $array = array('address' => $email, 'name' => $name, 'authinfo' => '', 'url' => 'http://' . $tudu->orgId . '.com/foreign/tudu?ts=' . $tsId . '&tid=' . $tudu->tuduId . '&fid=' . $receiver['uniqueid']);
                 if ($auth) {
                     $array['authinfo'] = '<p style="margin:10px 0">打开任务链接后需要输入以下验证码:<strong style="color:#f00">' . $auth . '</strong></p>';
                 }
                 $emails[] = $array;
             }
         }
     }
     // 执行外发
     $tpl = $this->_options['data']['path'] . '/templates/tudu/mail_meeting_notify.tpl';
     if (!file_exists($tpl) || !is_readable($tpl)) {
         $this->getLogger()->warn("Tpl file:\"mail_meeting_notify.tpl\" is not exists");
         return;
     }
     // 公用信息
     $common = array('subject' => $tudu->subject, 'sender' => $sender, 'lastupdate' => date('Y-m-d H:i:s', $tudu->lastPostTime), 'content' => mb_substr(strip_tags($content), 0, 20, 'utf-8'), 'type' => $this->_typeNames[$tudu->type]);
     $mailTransport = $this->getMailTransport($this->_balancer->select());
     $template = $this->_assignTpl(file_get_contents($tpl), $common);
     foreach ($emails as $email) {
         try {
             $mail = new Zend_Mail('utf-8');
             $mail->setFrom($this->_options['smtp']['from']['alert'], urldecode($this->_options['smtp']['fromname']));
             $mail->addTo($email['address'], $email['name']);
             $mail->addHeader('tid', $tudu->tuduId);
             $mail->setSubject("图度{$this->_typeNames[$tudu->type]}——" . $tudu->subject . '[会议提醒]');
             $mail->setBodyHtml($this->_assignTpl($template, $email));
             $mail->send($mailTransport);
         } catch (Zend_Mail_Exception $ex) {
             $this->getLogger()->warn("[Failed] Email send type:{$this->_typeNames[$tudu->type]} TuduId:{$tuduId} retry\n{$ex}");
             continue;
         }
     }
     $this->getLogger()->debug("Send Meeting id:{$tuduId} done");
 }
コード例 #11
0
ファイル: TuduController.php プロジェクト: bjtenao/tudu-web
 /**
  * 导出投票数据
  */
 public function exportVoteAction()
 {
     $this->_helper->viewRenderer->setNeverRender();
     $tuduId = $this->_request->getParam('tid');
     $voteId = $this->_request->getParam('voteid');
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = $this->getDao('Dao_Td_Tudu_Tudu');
     $tudu = $daoTudu->getTuduById($this->_user->uniqueId, $tuduId, array());
     $isSender = in_array($tudu->sender, array($this->_user->address, $this->_user->userName), true);
     /* @var $daoVote Dao_Td_Tudu_Vote */
     $daoVote = $this->getDao('Dao_Td_Tudu_Vote');
     $vote = $daoVote->getVote(array('tuduid' => $tuduId, 'voteid' => $voteId));
     $vote->getOptions();
     $vote = $vote->toArray();
     $filename = Oray_Function::utf8ToGbk(sprintf($this->lang['vote_info'], $vote['title']) . '.csv');
     $data = array();
     // 准备导出数据的列名
     $columns = array(Oray_Function::utf8ToGbk($this->lang['vote_option']), Oray_Function::utf8ToGbk($this->lang['vote_result']), Oray_Function::utf8ToGbk($this->lang['vote_percent']));
     // 创建人可见投票参与人
     if ($vote['anonymous'] && $isSender) {
         $vote['privacy'] = true;
     }
     // 公开参与人
     if ($vote['privacy']) {
         $columns[] = Oray_Function::utf8ToGbk($this->lang['vote_voter']);
     }
     $data[] = implode(',', $columns);
     foreach ($vote['options'] as $optionId => $option) {
         // 公开参与人
         if ($vote['privacy']) {
             $voters = array();
             if (!empty($option['voters'])) {
                 foreach ($option['voters'] as $voter) {
                     if (trim($voter)) {
                         $voter = explode(' ', $voter);
                         $voters[] = $voter[1];
                     }
                 }
             }
             $voters = !empty($voters) ? implode('、', $voters) : '-';
         }
         $percent = $option['votecount'] / $vote['votecount'] * 100;
         $optionItem = array(Oray_Function::utf8ToGbk($option['text']), $option['votecount'], $percent . '%');
         // 公开参与人
         if ($vote['privacy']) {
             $optionItem[] = Oray_Function::utf8ToGbk($voters);
         }
         $data[] = implode(',', $optionItem);
     }
     header("Content-type:text/csv");
     header("Content-Disposition:attachment;filename=" . $filename);
     header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
     header('Expires:0');
     header('Pragma:public');
     echo implode("\n", $data);
 }
コード例 #12
0
ファイル: User.php プロジェクト: bjtenao/tudu-web
 /**
  * 获取用户分页数据
  *
  * @param array $condition
  * @param mixed $sort
  * @param int   $page
  * @param int   $pageSize
  * @return Dao_User_Record_Users
  */
 public function getUserPage(array $condition, $sort = null, $page = null, $pageSize = null)
 {
     $table = 'md_user AS U LEFT JOIN md_user_info AS UI ON U.org_id = UI.org_id AND U.user_id = UI.user_id ' . 'LEFT JOIN md_department AS D ON U.org_id = D.org_id AND U.dept_id = D.dept_id ' . 'LEFT JOIN md_user_role AS R ON R.org_id = U.org_id AND R.user_id = U.user_id ' . 'LEFT JOIN md_user_group AS G ON G.org_id = U.org_id AND G.user_id = U.user_id';
     $columns = 'U.org_id AS orgid, U.user_id AS userid, U.unique_id AS uniqueid, ' . 'U.dept_id AS deptid, U.status, UI.gender, GROUP_CONCAT(DISTINCT(G.group_id)) AS groups, ' . 'D.dept_name AS deptname, UI.true_name AS truename, U.create_time AS createtime, U.unlock_time AS unlocktime, ' . 'GROUP_CONCAT(DISTINCT(R.role_id)) AS roles';
     $where = array();
     $order = array();
     $primary = 'U.user_id';
     $recordClass = 'Dao_Md_User_Record_UserPage';
     if (!empty($condition['orgid'])) {
         $where[] = 'U.org_id = ' . $this->_db->quote($condition['orgid']);
     }
     if (!empty($condition['userid'])) {
         $where[] = 'U.user_id = ' . $this->_db->quote($condition['userid']);
     }
     if (!empty($condition['domain'])) {
         $where[] = 'DM.domain_name = ' . $this->_db->quote($condition['domain']);
     }
     if (!empty($condition['domainid'])) {
         $where[] = 'U.domain_id = ' . $this->_db->quote($condition['domainid']);
     }
     if (!empty($condition['deptid'])) {
         if (is_array($condition['deptid'])) {
             $condition['deptid'] = array_map(array($this->_db, 'quote'), $condition['deptid']);
             $where[] = 'U.dept_id IN (' . implode(',', $condition['deptid']) . ')';
         } else {
             $where[] = 'U.dept_id = ' . $this->_db->quote($condition['deptid']);
         }
     }
     if (!empty($condition['groupid'])) {
         $table .= 'LEFT JOIN md_user_group AS G ON U.org_id = G.org_id AND U.user_id = G.user_id ';
         $where[] = 'G.group_id = ' . $this->_db->quote($condition['groupid']);
     }
     if (isset($condition['status']) && is_int($condition['status'])) {
         $where[] = 'U.status = ' . $condition['status'];
     }
     if (!empty($condition['keyword'])) {
         $keyword = $this->_db->quote('%' . $condition['keyword'] . '%');
         $str = "UI.true_name LIKE {$keyword} OR UI.nick LIKE {$keyword}";
         if (Oray_Function::isByte($condition['keyword'])) {
             $str .= " OR U.user_id LIKE {$keyword} OR UI.pinyin LIKE {$keyword}";
         }
         $where[] = '(' . $str . ')';
     }
     if (isset($condition['createtime'])) {
         if (is_array($condition['createtime'])) {
             $w = array();
             if (isset($condition['createtime']['start'])) {
                 $w[] = 'create_time >= ' . $condition['starttime'];
             }
             if (isset($condition['createtime']['end'])) {
                 $w[] = 'create_time <= ' . $condition['endtime'];
             }
             if ($w) {
                 $where[] = '(' . implode(' AND ', $w) . ')';
             }
         } elseif (is_int($condition['createtime'])) {
             $where[] = 'create_time >= ' . $condition['starttime'];
         }
     }
     if (!$where) {
         return new Oray_Dao_Recordset();
     }
     // WHERE
     //$where = implode(' AND ', $where);
     $where = ' WHERE ' . implode(' AND ', $where);
     // 排序
     $sort = $this->_formatSort($sort);
     foreach ($sort as $key => $val) {
         switch ($key) {
             case 'userid':
                 $key = 'U.user_id';
                 break;
             case 'createtime':
                 $key = 'U.create_time';
                 break;
             case 'ordernum':
                 $key = 'U.order_num';
                 break;
             case 'deptid':
                 $key = 'U.dept_id';
                 break;
             case 'status':
                 $key = 'U.status';
                 break;
             default:
                 continue 2;
                 break;
         }
         $order[] = $key . ' ' . $val;
     }
     // ORDER
     $order = implode(', ', $order);
     if ($order) {
         $order = 'ORDER BY ' . $order;
     }
     $limit = '';
     if (null !== $page) {
         // 使用默认的分页大小
         if (null === $pageSize) {
             $pageSize = self::$_defaultPageSize;
         }
         $offset = ($page - 1) * $pageSize;
         $limit = "LIMIT {$offset}, {$pageSize}";
     }
     $sql = "SELECT {$columns} FROM {$table} {$where} GROUP BY U.org_id, U.user_id {$order} {$limit}";
     $records = $this->_db->fetchAll($sql);
     return new Oray_Dao_Recordset($records, $recordClass);
     /**
      * @see Oray_Db_Paginator
      */
     //require_once 'Oray/Db/Paginator.php';
     /*$paginator = new Oray_Db_Paginator(array(
                 Oray_Db_Paginator::ADAPTER   => $this->_db,
                 Oray_Db_Paginator::TABLE     => $table,
                 Oray_Db_Paginator::COLUMNS   => $columns,
                 Oray_Db_Paginator::ORDER     => $order,
                 Oray_Db_Paginator::PRIMARY   => $primary,
                 Oray_Db_Paginator::WHERE     => $where,
                 Oray_Db_Paginator::PAGE_SIZE => $pageSize,
     
                 Oray_Db_Paginator::RECORD_CLASS => $recordClass
             ));*/
     //return $paginator->query($page);
 }
コード例 #13
0
ファイル: Contact.php プロジェクト: bjtenao/tudu-web
 /**
  * 读取用户列表
  * SELECT contact_id AS contactid, unique_id AS uniqueid, true_name AS truename, pinyin, email, mobile,
  * affinity, last_contact_time AS lastcontacttime, groups
  * FROM td_contact
  * WHERE ..
  * ORDER BY
  * LIMIT ..
  *
  * @param $condition
  * @param $filter
  * @param $sort
  * @param $maxCount
  */
 public function getContacts(array $condition, $filter = null, $sort = null, $maxCount = null)
 {
     $table = 'td_contact AS c ';
     $columns = 'c.contact_id AS contactid, c.unique_id AS uniqueid, true_name AS truename, pinyin, email, mobile, ' . 'affinity, last_contact_time AS lastcontacttime, groups, from_user AS fromuser, ISNULL(c.avatars) AS isavatars';
     $where = array();
     $order = '';
     $limit = '';
     $recordClass = 'Dao_Td_Contact_Record_Contact';
     if (!empty($condition['contactid'])) {
         $where[] = 'c.contact_id = ' . $this->_db->quote($condition['contactid']);
     }
     if (!empty($condition['uniqueid'])) {
         $where[] = 'c.unique_id = ' . $this->_db->quote($condition['uniqueid']);
     }
     if (!empty($condition['keyword'])) {
         $keyword = $this->_db->quote("%{$condition['keyword']}%");
         $like[] = "true_name LIKE {$keyword}";
         if (!Oray_Function::hasCnChar($keyword)) {
             $like[] = "pinyin LIKE {$keyword}";
             $like[] = "email LIKE {$keyword}";
         }
         $where[] = '(' . implode(' OR ', $like) . ')';
     }
     if (!empty($condition['pinyin'])) {
         $keyword = $this->_db->quote($condition['pinyin'] . '%');
         $where[] = "(true_name LIKE {$keyword} OR pinyin LIKE {$keyword})";
     }
     if (array_key_exists('groupid', $condition)) {
         if (!empty($condition['groupid'])) {
             $table .= ' LEFT JOIN td_contact_group_member AS gm ON c.contact_id = gm.contact_id AND c.unique_id = gm.unique_id';
             $where[] = 'gm.group_id = ' . $this->_db->quote($condition['groupid']);
         } else {
             $where[] = 'c.groups = \'\'';
         }
     }
     if (isset($filter['isshow'])) {
         if (null !== $condition['isshow']) {
             $where[] = 'c.is_show = ' . $condition['isshow'] ? 1 : 0;
         }
     } else {
         $where[] = 'c.is_show = 1';
     }
     // WHERE
     $where = implode(' AND ', $where);
     if ($where) {
         $where = 'WHERE ' . $where;
     }
     // 格式化排序参数
     $sort = $this->_formatSort($sort);
     foreach ($sort as $key => $val) {
         switch ($key) {
             case 'lastcontacttime':
                 $key = 'last_contact_time';
                 break;
             case 'affinity':
             default:
                 continue 2;
                 break;
         }
         $order[] = $key . ' ' . $val;
     }
     if ($order) {
         $order = 'ORDER BY ' . implode(', ', $order);
     }
     if (is_int($maxCount) && $maxCount > 0) {
         $limit = 'LIMIT ' . $maxCount;
     }
     $sql = "SELECT {$columns} FROM {$table} {$where} {$order} {$limit}";
     try {
         $records = $this->_db->fetchAll($sql);
         return new Oray_Dao_Recordset($records, $recordClass);
     } catch (Zend_Db_Exception $e) {
         $this->_catchException($e, __METHOD__);
         return false;
     }
 }
コード例 #14
0
ファイル: BoardController.php プロジェクト: bjtenao/tudu-web
 /**
  *
  * 编辑
  */
 public function modifyAction()
 {
     $boardId = $this->_request->getQuery('bid');
     $board = array();
     $action = 'create';
     $daoBoard = $this->getDao('Dao_Td_Board_Board');
     $daoTemplate = $this->getDao('Dao_Td_Tudu_Template');
     if ($boardId) {
         $board = $daoBoard->getBoard(array('orgid' => $this->_user->orgId, 'boardid' => $boardId));
         $templates = $daoTemplate->getTemplatesByBoardId($this->_user->orgId, $boardId, null, 'ordernum ASC');
         if (null === $board) {
             return Oray_Function::alert($this->lang['board_not_exists']);
         }
         $board = $board->toArray();
         $action = 'update';
         $daoClass = $this->getDao('Dao_Td_Tudu_Class');
         $classes = $daoClass->getClassesByBoardId($this->_user->orgId, $board['boardid'], 'ordernum ASC');
         if ($templates) {
             $this->view->templates = $templates->toArray();
         }
         $this->view->classes = $classes->toArray();
     } else {
         if (!$this->_user->getAccess()->assertEquals(Tudu_Access::PERM_CREATE_BOARD, true)) {
             Oray_Function::alert($this->lang['perm_deny_create'], '/board/');
         }
     }
     $zones = $daoBoard->getBoards(array('orgid' => $this->_user->orgId, 'type' => 'zone'));
     // 权限
     $access = array('discuss' => $this->_user->getAccess()->assertEquals(Tudu_Access::PERM_CREATE_DISCUSS, true), 'notice' => $this->_user->getAccess()->assertEquals(Tudu_Access::PERM_CREATE_NOTICE, true), 'task' => $this->_user->getAccess()->assertEquals(Tudu_Access::PERM_CREATE_TUDU, true), 'meeting' => $this->_user->getAccess()->assertEquals(Tudu_Access::PERM_CREATE_MEETING, true), 'board' => $this->_user->getAccess()->assertEquals(Tudu_Access::PERM_CREATE_BOARD, true), 'upload' => $this->_user->getAccess()->assertEquals(Tudu_Access::PERM_UPLOAD_ATTACH, true), 'meeting' => $this->_user->getAccess()->assertEquals(Tudu_Access::PERM_CREATE_MEETING, true));
     //$uploadOpt = $this->bootstrap->getOption('upload');
     $this->view->board = $board;
     $this->view->zones = $zones->toArray();
     $this->view->action = $action;
     $this->view->newwin = (bool) $this->_request->getQuery('newwin');
     $this->view->access = $access;
 }
コード例 #15
0
ファイル: GroupTudus.php プロジェクト: bjtenao/tudu-web
 /**
  * Construct
  *
  * @param array $record
  */
 public function __construct(array $record)
 {
     $this->orgId = $record['orgid'];
     $this->boardId = $record['boardid'];
     $this->tuduId = $record['tuduid'];
     $this->classId = $record['classid'];
     $this->className = $record['classname'];
     $this->type = $record['type'];
     $this->subject = $record['subject'];
     $this->from = Dao_Td_Tudu_Tudu::formatAddress($record['from'], true);
     $this->to = Dao_Td_Tudu_Tudu::formatAddress($record['to']);
     $this->cc = Dao_Td_Tudu_Tudu::formatAddress($record['cc']);
     $this->priority = $this->_toInt($record['priority']);
     $this->privacy = $this->_toInt($record['privacy']);
     $this->attachNum = $this->_toInt($record['attachnum']);
     $this->lastPostTime = $this->_toTimestamp($record['lastposttime']);
     $this->lastPoster = $record['lastposter'];
     $this->posterInfo = $record['posterinfo'];
     $this->viewNum = $record['viewnum'];
     $this->replyNum = $this->_toInt($record['replynum']);
     $this->logNum = $this->_toInt($record['lognum']);
     $this->startTime = $this->_toTimestamp($record['starttime']);
     $this->endTime = $this->_toTimestamp($record['endtime']);
     $this->acceptTime = $this->_toTimestamp($record['accepttime']);
     $this->createTime = $this->_toTimestamp($record['createtime']);
     $this->percent = $this->_toInt($record['percent']);
     $this->status = $this->_toInt($record['status']);
     $this->special = $this->_toInt($record['special']);
     $this->uniqueId = $record['uniqueid'];
     $this->isRead = $this->_toBoolean($record['isread']);
     $this->isForward = $this->_toBoolean($record['isforward']);
     $this->isDone = $this->_toBoolean($record['isdone']);
     $this->labels = $this->_toArray($record['labels']);
     $this->nodeType = isset($record['nodetype']) ? $record['nodetype'] : null;
     $this->parentId = isset($record['parentid']) ? $record['parentid'] : null;
     $this->isTuduGroup = in_array($this->nodeType, array(Dao_Td_Tudu_Group::TYPE_NODE, Dao_Td_Tudu_Group::TYPE_ROOT));
     $this->selfPercent = isset($record['selfpercent']) ? $this->_toInt($record['selfpercent']) : null;
     $this->role = !empty($record['role']) ? $record['role'] : null;
     $this->selfTuduStatus = isset($record['selftudustatus']) ? $this->_toInt($record['selftudustatus']) : null;
     $this->selfAcceptTime = isset($record['selfaccepttime']) ? $this->_toTimestamp($record['selfaccepttime']) : null;
     $this->isExpired = $this->endTime && $this->status <= Dao_Td_Tudu_Tudu::STATUS_DOING && Oray_Function::dateDiff('d', $this->endTime, time()) > 0;
     if (isset($this->from[3])) {
         $this->sender = $this->from[3];
     }
     $this->accepter = !empty($this->to) ? array_keys($this->to) : array();
     if (isset($record['forwardinfo']) || isset($record['lastforward'])) {
         $forwardInfo = count($this->accepter) > 1 ? $record['forwardinfo'] : $record['lastforward'];
         $array = explode("\n", $forwardInfo);
         if (count($array) == 2) {
             $this->lastForwarder = $array[0];
             $this->lastForwardTime = $this->_toInt($array[1]);
         }
     }
     parent::__construct();
 }
コード例 #16
0
 /**
  * 保存邮箱
  */
 public function savemailboxAction()
 {
     $post = $this->_request->getPost();
     $bind = false;
     $daoUser = $this->getMdDao('Dao_Md_User_User');
     $mailBox = $daoUser->getMailbox($this->_user->orgId, $this->_user->userId);
     if (!empty($post['address']) || !empty($post['password']) || !empty($post['imaphost'])) {
         $bind = true;
         if (empty($post['address']) || !Oray_Function::isEmail($post['address'])) {
             return $this->json(false, $this->lang['invalid_email_address']);
         }
         if (empty($post['password']) && !$mailBox) {
             return $this->json(false, $this->lang['missing_email_password']);
         }
         if (!empty($post['imaphost']) && (!Oray_Function::isDomainName($post['imaphost']) && !Oray_Function::isIp($post['imaphost']))) {
             return $this->json(false, $this->lang['invalid_imap_host']);
         }
         if ($post['port'] != '') {
             if ((int) $post['port'] <= 0 || (int) $post['port'] > 65535) {
                 return $this->json(false, $this->lang['invalid_imap_port']);
             }
         }
     }
     if ($bind) {
         $isSsl = isset($post['isssl']) && $post['isssl'] == 1 ? 1 : 0;
         $type = isset($post['type']) ? (int) $post['type'] : 0;
         if (null !== $mailBox) {
             $params = array('address' => $post['address'], 'imaphost' => $post['imaphost'], 'port' => (int) $post['port'] > 0 ? (int) $post['port'] : null, 'isssl' => $isSsl, 'type' => $type);
             if (!empty($post['password'])) {
                 $params['password'] = $post['password'];
             }
             $ret = $daoUser->updateMailbox($this->_user->orgId, $this->_user->userId, $params);
         } else {
             $ret = $daoUser->addMailbox(array('orgid' => $this->_user->orgId, 'userid' => $this->_user->userId, 'address' => $post['address'], 'imaphost' => $post['imaphost'], 'password' => $post['password'], 'port' => (int) $post['port'] > 0 ? (int) $post['port'] : null, 'isssl' => $isSsl, 'type' => $type));
         }
     } else {
         $ret = $daoUser->removeMailbox($this->_user->orgId, $this->_user->userId);
     }
     if (!$ret) {
         return $this->json(false, $this->lang['update_mailbox_failure']);
     }
     return $this->json(true, $this->lang['update_mailbox_success']);
 }
コード例 #17
0
ファイル: Review.php プロジェクト: bjtenao/tudu-web
 /**
  * 修改应用范围页面
  */
 public function applyAction()
 {
     $flowId = $this->_request->getQuery('flowid');
     /* @var $daoFlow Dao_App_Attend_Flow */
     $daoFlow = Tudu_Dao_Manager::getDao('Dao_App_Attend_Flow', Tudu_Dao_Manager::DB_APP);
     $condition = array('flowid' => $flowId, 'orgid' => $this->_user->orgId);
     $flow = $daoFlow->getFlow($condition);
     if (null === $flow) {
         Oray_Function::alert($this->lang['flow_not_exists'], '/app/attend/review/index');
     }
     /* @var $daoCategory Dao_App_Attend_Category */
     $daoCategory = Tudu_Dao_Manager::getDao('Dao_App_Attend_Category', Tudu_Dao_Manager::DB_APP);
     $categories = $daoCategory->getCategories(array('orgid' => $this->_user->orgId), null, 'status DESC, issystem DESC, createtime DESC');
     $this->view->categories = $categories->toArray();
     $this->view->flow = $flow->toArray();
 }
コード例 #18
0
ファイル: Tudu.php プロジェクト: bjtenao/tudu-web
 /**
  * 执行图度规则过滤
  *
  * 遍历所有接收人所有可用规则,并执行过滤
  * @param $params
  */
 public function filterTudu($params)
 {
     if (empty($params['tuduid']) || empty($params['tsid'])) {
         return;
     }
     $tuduId = $params['tuduid'];
     $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     /** @var $daoRule Dao_Td_Rule_Rule */
     $daoRule = Tudu_Dao_Manager::getDao('Dao_Td_Rule_Rule', Tudu_Dao_Manager::DB_TS);
     $users = $manager->getTuduUsers($tuduId);
     if (!$users) {
         $this->getLogger()->warn("Tudu id:{$tuduId} Users are not exists");
         return;
     }
     $tudu = $manager->getTuduById($tuduId, $users[0]['uniqueid']);
     if (null === $tudu) {
         $this->getLogger()->warn("Tudu id: {$tuduId} is not exists");
         return;
     }
     $tudu = $tudu->toArray();
     $expire = 3600 * 24;
     //定义Memcache过期时间: 一天
     // 获取接收用户规则过滤
     foreach ($users as $user) {
         $unId = $user['uniqueid'];
         $rules = $this->_memcache->loadCache(array($daoRule, 'getRulesByUniqueId'), array($unId, array('isvalid' => true)), $expire);
         if ($rules->count() <= 0) {
             continue;
         }
         foreach ($rules as $rule) {
             $filters = $rule->getFilters();
             $filterCount = $filters->count();
             $matchCount = 0;
             if ($filterCount <= 0) {
                 continue;
             }
             foreach ($filters as $filter) {
                 $contain = false;
                 switch ($filter->what) {
                     // 发起人
                     case 'from':
                         if (is_array($filter->value)) {
                             foreach ($filter->value as $item) {
                                 $item = str_replace(array('oray.com', 'tudu.com'), array('oray', ''), $item);
                                 if ($item == $tudu['from'][3]) {
                                     $contain = true;
                                     break;
                                 }
                             }
                         }
                         break;
                         // 接收人,抄送人
                     // 接收人,抄送人
                     case 'to':
                     case 'cc':
                         if (is_array($filter->value)) {
                             $count = 0;
                             $match = 0;
                             foreach ($filter->value as $item) {
                                 $count++;
                                 $item = str_replace(array('oray.com', 'tudu.com'), array('oray', ''), $item);
                                 if (isset($tudu[$filter->what][$item])) {
                                     $match++;
                                 }
                             }
                             if ($count == $match) {
                                 $contain = true;
                             }
                         }
                         break;
                     case 'subject':
                         $contain = false !== strpos($tudu['subject'], $filter->value);
                         break;
                 }
                 if ($filter->type == 'contain' && $contain || $filter->type == 'exclusive' && !$contain) {
                     $matchCount++;
                 }
             }
             // 匹配过滤条件,执行规则操作
             if ($matchCount == $filterCount) {
                 // 标签
                 if ($rule->operation == 'label') {
                     $manager->addLabel($tuduId, $unId, $rule->value);
                     // 忽略
                 } elseif ($rule->operation == 'ignore') {
                     $manager->deleteLabel($tuduId, $unId, '^i');
                     $manager->addLabel($tuduId, $unId, '^g');
                     // 星标
                 } elseif ($rule->operation == 'starred') {
                     $manager->addLabel($tuduId, $unId, '^t');
                 }
                 // 是否需要邮件提醒
                 if (!empty($rule->mailRemind)) {
                     $mailRemind = $rule->mailRemind;
                     // 邮件提醒可用且图度在指定的板块的
                     if ($mailRemind['isvalid'] && !empty($mailRemind['boards']) && !empty($mailRemind['mailbox']) && is_array($mailRemind['boards']) && in_array($tudu['boardid'], $mailRemind['boards'])) {
                         $emails = array();
                         foreach ($mailRemind['mailbox'] as $email) {
                             // 必须是邮箱
                             if (Oray_Function::isEmail($email)) {
                                 $emails[] = $email;
                             }
                         }
                         if (!empty($emails)) {
                             $remind = array('tuduid' => $tudu['tuduid'], 'tsid' => $params['tsid'], 'emails' => $emails, 'subject' => $tudu['subject'], 'sender' => $tudu['from'][0], 'lastupdate' => date('Y-m-d H:i:s', $tudu['lastposttime']), 'content' => mb_substr(strip_tags($tudu['content']), 0, 20, 'utf-8'), 'type' => $this->_typeNames[$tudu['type']], 'url' => 'http://' . $tudu['orgid'] . '.tudu.com/tudu/view?tid=' . $tudu['tuduid']);
                             $this->getLogger()->warn("Send Email notify to:" . implode(',', $emails));
                             // 发送邮件提醒请求
                             $data = implode(' ', array('send', 'email', '', http_build_query($remind)));
                             $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['send']);
                         }
                     }
                 }
             }
         }
     }
     $this->getLogger()->debug("Tudu id:{$tuduId} done");
 }
コード例 #19
0
ファイル: EmailController.php プロジェクト: bjtenao/tudu-web
 /**
  * 更新绑定邮箱
  */
 public function updateAction()
 {
     $post = $this->_request->getPost();
     $address = isset($post['address']) ? $post['address'] : null;
     $password = trim($post['password']);
     $port = !empty($post['port']) ? $post['port'] : null;
     if (!trim($post['host'])) {
         return $this->json(false, $this->lang['missing_email_host'], array('advance' => true));
     }
     if (!Oray_Function::isDomainName($post['host']) && !Oray_Function::isIp($post['host'])) {
         return $this->json(false, sprintf($this->lang['invalid_imap_host'], strtoupper($post['protocol'])), array('advance' => true));
     }
     if ($port != null) {
         if ($port <= 0 || $port > 65535) {
             return $this->json(false, sprintf($this->lang['invalid_imap_port'], strtoupper($post['protocol'])));
         }
     }
     $email = $this->_daoEmail->getEmailByAddress($this->_user->orgId, $this->_user->userId, $address);
     if (null === $email) {
         return $this->json(false, $this->lang['mailbox_not_exists']);
     }
     $checkPwd = $email->password;
     $isSsl = isset($post['isssl']) && $post['isssl'] == 1 ? 1 : 0;
     $type = isset($post['type']) ? (int) $post['type'] : 0;
     $params = array('protocol' => $post['protocol'], 'host' => $post['host'], 'port' => (int) $post['port'] > 0 ? (int) $post['port'] : null, 'isssl' => $isSsl, 'type' => $type);
     if (!empty($password)) {
         $params['password'] = $password;
         $checkPwd = $password;
     }
     /**
      * 验证邮箱密码
      */
     if (!$this->_validMailbox($address, $checkPwd, $params['host'], $params['port'], (bool) $isSsl, $post['protocol'])) {
         return $this->json(false);
     }
     $ret = $this->_daoEmail->updateEmail($this->_user->orgId, $this->_user->userId, $address, $params);
     if (!$ret) {
         return $this->json(false, $this->lang['update_mailbox_failure']);
     }
     return $this->json(true, $this->lang['update_mailbox_success']);
 }
コード例 #20
0
ファイル: Api.php プロジェクト: bjtenao/tudu-web
 /**
  * 
  * @param string $url
  * @param mixed $headers
  * @param array $data
  * @return string
  */
 private function _request($url, $content = '', $headers = null)
 {
     return Oray_Function::httpRequest($url, $content, $headers);
 }
コード例 #21
0
 /**
  * /compose/send
  *
  * 图度发送统一接口
  * 接管保存,发送,更新,转发,申请审批等操作
  *
  */
 public function sendAction()
 {
     $post = $this->_request->getPost();
     // 当前操作类型
     $action = self::ACTION_SEND;
     // 图度类型
     $type = isset($post['type']) ? $post['type'] : 'task';
     // 操作的保存图度列表
     // array('tuduid' => $params ...)
     $tuduList = array();
     // 提交主任务ID
     $tuduId = isset($post['ftid']) ? $post['ftid'] : null;
     // 图度组根任务ID
     $rootId = null;
     // 是否包含分工
     $hasDivide = isset($post['chidx']) && is_array($post['chidx']);
     // 日志详细信息
     $logDetails = array();
     // 返回数据
     $returnData = array();
     // 是否重开讨论
     $isReopen = isset($post['isclose']) && $type == 'discuss';
     if (!empty($post['action']) && $post['action'] == 'save') {
         $action = self::ACTION_SAVE;
     }
     if (!empty($post['forward'])) {
         $action = self::ACTION_FORWARD;
     } elseif (!empty($post['invite'])) {
         $action = self::ACTION_INVITE;
     } elseif (!empty($post['divide'])) {
         $action = self::ACTION_DIVIDE;
     } elseif (!empty($post['review'])) {
         $action = self::ACTION_REVIEW;
     } elseif (!empty($post['apply'])) {
         $action = self::ACTION_APPLY;
     }
     /* @var $manager Tudu_Tudu_Manager */
     $manager = Tudu_Tudu_Manager::getInstance();
     /* @var $storage Tudu_Tudu_Storage */
     $storage = Tudu_Tudu_Storage::getInstance();
     $Indexes = array('');
     if ($type == 'task' && $hasDivide && $action != self::ACTION_FORWARD && $action != self::ACTION_APPLY) {
         $Indexes = array_merge($Indexes, $post['chidx']);
     }
     // 周期任务
     if (($type == 'task' || $type == 'meeting') && $tuduId && !Tudu_Tudu_Extension::isRegistered('cycle')) {
         Tudu_Tudu_Extension::registerExtension('cycle', 'Tudu_Tudu_Extension_Cycle');
     }
     // 需要图度组
     if ($type == 'task') {
         Tudu_Tudu_Extension::registerExtension('group', 'Tudu_Tudu_Extension_Group');
     }
     // 需要流程
     if (($type == 'task' || $type == 'notice') && !Tudu_Tudu_Extension::isRegistered('flow')) {
         Tudu_Tudu_Extension::registerExtension('flow', 'Tudu_Tudu_Extension_Flow');
     }
     // 版块列表
     $boards = $this->getBoards(false);
     // 遍历提交图度参数,填充图度列表
     $children = array();
     foreach ($Indexes as $suffix) {
         if ('' !== $suffix) {
             $suffix = '-' . $suffix;
         }
         // 获取已存在图度数据
         $fromTudu = null;
         if (!empty($post['ftid' . $suffix])) {
             $tid = $post['ftid' . $suffix];
             $fromTudu = $manager->getTuduById($tid, $this->_user->uniqueId);
             if (null === $fromTudu) {
                 return $this->json(false, $this->lang['tudu_not_exists']);
             }
         }
         // 创建图度
         if (null === $fromTudu) {
             // 转发、分工等图度不存在
             if ($action != self::ACTION_SEND && $action != self::ACTION_SAVE && $action != self::ACTION_DIVIDE || $action == self::ACTION_DIVIDE && '' === $suffix) {
                 return $this->json(false, $this->lang['tudu_not_exists']);
             }
             // 创建权限
             if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_TUDU)) {
                 return $this->json(false, $this->lang['perm_deny_create_tudu']);
             }
         } else {
             // 非草稿状态下的分工,没有修改则不进行后续更新操作
             if (!empty($suffix) && empty($post['ismodified' . $suffix]) && !($fromTudu->isDraft && $action != self::ACTION_SAVE)) {
                 $idx = str_replace('-', '', $suffix);
                 $children[$idx] = $fromTudu->tuduId;
                 continue;
             }
             // 保存草稿,图度必须为草稿状态
             if ($action == self::ACTION_SAVE) {
                 if (!$fromTudu->isDraft) {
                     return $this->json(false, $this->lang['forbid_save_sent']);
                 }
             } else {
                 $isSender = true;
                 $isAccepter = in_array($this->_user->address, $fromTudu->accepter, true) || in_array($this->_user->userName, $fromTudu->accepter, true);
                 switch ($action) {
                     // 更新,权限,发起人/版主/分区负责人
                     case self::ACTION_SEND:
                         // 更新权限
                         if ($fromTudu && !$fromTudu->isDraft && !$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_TUDU)) {
                             return $this->json(false, $this->lang['perm_deny_update_tudu']);
                         }
                         // 权限
                         $board = $boards[$fromTudu->boardId];
                         $isModerator = array_key_exists($this->_user->userId, $board['moderators']);
                         $isSuperModerator = !empty($board['parentid']) && array_key_exists($this->_user->userId, $boards[$board['parentid']]['moderators']);
                         if (!$isSender && !$isModerator && !$isSuperModerator) {
                             return $this->json(false, $this->lang['perm_deny_update_tudu']);
                         }
                         break;
                         // 转发,权限,任务,已发送,执行人,非图度组
                     // 转发,权限,任务,已发送,执行人,非图度组
                     case self::ACTION_FORWARD:
                         // 转发权限
                         if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_FORWARD_TUDU)) {
                             return $this->json(false, $this->lang['perm_deny_forward_tudu']);
                         }
                         // 图度组
                         if ($fromTudu->isTuduGroup) {
                             return $this->json(false, $this->lang['deny_forward_tudugroup']);
                         }
                         // 不是执行人
                         if (!$isAccepter) {
                             return $this->json(false, $this->lang['forbid_non_accepter_forward']);
                         }
                         $isSender = $fromTudu->sender == $this->_user->userName;
                         break;
                         // 分工,任务,已发送,执行人,有分工
                     // 分工,任务,已发送,执行人,有分工
                     case self::ACTION_DIVIDE:
                         if (empty($post['chidx'])) {
                             return $this->json(false, $this->lang['no_divide_tudu']);
                         }
                         if ($fromTudu->isDraft) {
                             return $this->json(false, $this->lang['tudu_not_exists']);
                         }
                         $isSender = $fromTudu->sender == $this->_user->userName;
                         break;
                         // 邀请,必须为会议,已经发送
                     // 邀请,必须为会议,已经发送
                     case self::ACTION_INVITE:
                         if ($fromTudu->type != 'meeting') {
                             return $this->json(false, null);
                         }
                         if ($fromTudu->isDraft) {
                             return $this->json(false, $this->lang['tudu_not_exists']);
                         }
                         $isSender = $fromTudu->sender == $this->_user->userName;
                         break;
                         // 申请审批,必须为任务,已发送,执行人,非图度组
                     // 申请审批,必须为任务,已发送,执行人,非图度组
                     case self::ACTION_APPLY:
                         // 图度组不能参与审批
                         if ($fromTudu->isTuduGroup) {
                             return $this->json(false, $this->lang['tudu_group_review']);
                         }
                         // 非图度执行人不能进行申请审批操作
                         if (!$isAccepter) {
                             return $this->json(false, $this->lang['no_accepter_apply']);
                         }
                         // 审批人为空
                         if (empty($post['reviewer' . $suffix])) {
                             return $this->json(false, $this->lang['no_reviewer']);
                         }
                         $isSender = $fromTudu->sender == $this->_user->userName;
                         break;
                         // 审批,审批步骤,审批人是当前用户
                     // 审批,审批步骤,审批人是当前用户
                     case self::ACTION_REVIEW:
                         if (!$fromTudu->stepId || false !== strpos('^', $fromTudu->stepId)) {
                             return $this->json(false, $this->lang['disable_review']);
                         }
                         $flow = Tudu_Tudu_Extension::getExtension('flow');
                         $reviewer = $flow->getStepUser($fromTudu->tuduId, $fromTudu->stepId, $this->_user->uniqueId);
                         if (!$reviewer || $reviewer['type'] != Dao_Td_Tudu_Step::TYPE_EXAMINE || $reviewer['status'] != 1) {
                             return $this->json(false, $this->lang['disable_review']);
                         }
                         $isSender = $fromTudu->sender == $this->_user->userName;
                         break;
                 }
                 if ($action != self::ACTION_SEND && $fromTudu->isDraft) {
                     return $this->json(false, $this->lang['forbid_save_sent']);
                 }
             }
         }
         $params = $this->_formatTuduParams($post, $suffix);
         $params['action'] = $action;
         if (null === $fromTudu) {
             // 发起人参数
             $params['from'] = $this->_user->userName . ' ' . $this->_user->trueName;
             $params['email'] = $this->_user->userName;
             $params['sender'] = $this->_user->userName;
         } else {
             if (!empty($params['flowid']) && $action != self::ACTION_REVIEW && $action != self::ACTION_FORWARD) {
                 unset($params['to']);
             }
             if (!$fromTudu->isDraft) {
                 $params['lastmodify'] = implode(chr(9), array($this->_user->uniqueId, time(), $this->_user->trueName));
             }
         }
         // 创建时间
         if (null === $fromTudu || $fromTudu->isDraft) {
             $params['createtime'] = time();
         }
         // 转发,没有编辑权限,去除保存参数
         $isClearModify = false;
         if ($action == self::ACTION_FORWARD) {
             // 权限
             $board = $boards[$fromTudu->boardId];
             $isModerator = array_key_exists($this->_user->userId, $board['moderators']);
             $isSuperModerator = !empty($board['parentid']) && array_key_exists($this->_user->userId, $boards[$board['parentid']]['moderators']);
             if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_TUDU) || !$isSender && !$isModerator && !$isSuperModerator) {
                 $isClearModify = true;
             }
         }
         if ($action == self::ACTION_REVIEW || $action == self::ACTION_APPLY) {
             $isClearModify = true;
         }
         if ($isClearModify) {
             unset($params['classid'], $params['subject'], $params['privacy'], $params['password'], $params['priority'], $params['isauth'], $params['needconfirm'], $params['notifyall']);
         }
         try {
             $tudu = $storage->prepareTudu($params, $fromTudu);
         } catch (Tudu_Tudu_Exception $e) {
             switch ($e->getCode()) {
                 case Tudu_Tudu_Exception::CODE_FLOW_STEP_NULL:
                     $this->json(false, $this->lang['missing_flow_steps']);
                     break;
                 case Tudu_Tudu_Exception::CODE_NOT_EXISTS_UPPER:
                     $this->json(false, $this->lang['missing_flow_steps_upper_reviewer']);
                     break;
                 case Tudu_Tudu_Exception::CODE_NOT_EXISTS_USER:
                     $this->json(false, $this->lang['missing_flow_steps_receiver']);
                     break;
                     /*
                                         case Tudu_Tudu_Exception::MISSING_VOTE_TITLE:
                     $this->json(false, $this->lang['missing_vote_title']);
                     break;
                                         case Tudu_Tudu_Exception::MISSING_VOTE_OPTIONS:
                     $this->json(false, $this->lang['missing_vote_option']);
                     break;
                     */
             }
         }
         if ('' === $suffix) {
             $tuduId = $tudu->tuduId;
             $rootId = $tudu->rootId ? $tudu->rootId : $tudu->tuduId;
         }
         // 返回投票数据参数
         if ($tudu->type == 'discuss' && $tudu->vote) {
             $vote = $tudu->vote;
             if ($vote && !empty($vote['newoptions'])) {
                 foreach ($vote['newoptions'] as $item) {
                     $returnData['votes'][$item['index']] = $item['optionid'];
                 }
             }
         }
         // 部分操作不需要继承原文内容
         if ('' == $suffix && $action != self::ACTION_REVIEW && $action != self::ACTION_FORWARD && $action != self::ACTION_INVITE) {
             if ($fromTudu && !$fromTudu->isDraft) {
                 $tudu->boardId = $tudu->boardId ? $tudu->boardId : $fromTudu->boardId;
                 $tudu->content = $tudu->content ? $tudu->content : $fromTudu->content;
                 $tudu->startTime = isset($post['starttime' . $suffix]) ? $tudu->startTime : $fromTudu->startTime;
                 $tudu->endTime = isset($post['endtime' . $suffix]) ? $tudu->endTime : $fromTudu->endTime;
             }
         }
         // 设置子任务的父级ID
         if ('' !== $suffix && $type == 'task') {
             $tudu->parentId = $tuduId;
             $tudu->rootId = $rootId;
             $tudu->nodeType = $tudu->nodeType ? $tudu->nodeType : Dao_Td_Tudu_Group::TYPE_LEAF;
             $parent = $tuduList[$tuduId];
             if (!$fromTudu) {
                 $tudu->boardId = $tudu->boardId ? $tudu->boardId : $parent->boardId;
                 $tudu->classId = $tudu->classId ? $tudu->classId : $parent->classId;
                 //$tudu->content  = $tudu->content ? $tudu->content : $parent->content;
                 $tudu->startTime = $tudu->startTime ? $tudu->startTime : $parent->startTime;
                 $tudu->endTime = $tudu->endTime ? $tudu->endTime : $parent->endTime;
                 $content = trim(strip_tags($tudu->content, 'img'));
                 if (!$content) {
                     $tudu->content = $parent->content;
                 }
             } else {
                 $tudu->boardId = $tudu->boardId ? $tudu->boardId : $fromTudu->boardId;
                 $tudu->content = $tudu->content ? $tudu->content : $fromTudu->content;
                 $tudu->startTime = $tudu->startTime ? $tudu->startTime : $fromTudu->startTime;
                 $tudu->endTime = $tudu->endTime ? $tudu->endTime : $fromTudu->endTime;
             }
             $returnData['children'][(string) str_replace('-', '', $suffix)] = $tudu->tuduId;
             $idx = str_replace('-', '', $suffix);
             $children[$idx] = $tudu->tuduId;
         }
         if ('' === $suffix && $hasDivide && $type == 'task') {
             $tudu->rootId = $rootId;
             $tudu->nodeType = Dao_Td_Tudu_Group::TYPE_NODE;
         }
         // 没有分工
         if (!$hasDivide && $tuduId == $tudu->tuduId && $fromTudu && $fromTudu->nodeType && $manager->getChildrenCount($tudu->tuduId) <= 0) {
             $tudu->nodeType = Dao_Td_Tudu_Group::TYPE_LEAF;
         }
         // 未发送,更新创建时间
         /*if (!$fromTudu || $fromTudu->isDraft) {
               $tudu->createTime = time();
           }*/
         // 空内容
         if ($action != self::ACTION_REVIEW && $action != self::ACTION_SAVE && !$tudu->content) {
             return $this->json(false, $this->lang['params_invalid_content']);
         }
         // 转发
         if ($action == self::ACTION_FORWARD || $action == self::ACTION_INVITE) {
             // 输入用户已经是执行人
             $to = $tudu->to;
             foreach ($to as $k => $item) {
                 /*if (is_string($item['email']) && in_array($item['email'], $fromTudu->accepter, true)) {
                       return $this->json(false, sprintf($this->lang['user_is_accepter'], $item['truename']));
                   }*/
                 if ($action == self::ACTION_FORWARD && $fromTudu->selfPercent < 100) {
                     $to[$k]['percent'] = $fromTudu->selfPercent;
                 }
             }
             $tudu->to = $to;
             $to = array();
             foreach ($fromTudu->to as $k => $item) {
                 if ($k != $this->_user->userName) {
                     $to[] = $k . ' ' . $item[0];
                 }
             }
             $tudu->to = array_merge($tudu->to, Tudu_Tudu_Storage::formatRecipients(implode("\n", $to)));
         }
         // 邀请 || 100% 转发 加上自己
         if ($action == self::ACTION_INVITE || $action == self::ACTION_FORWARD && $fromTudu->selfPercent >= 100) {
             $tudu->to = array_merge($tudu->to, array($this->_user->userName => array('email' => $this->_user->userName, 'truename' => $this->_user->trueName, 'percent' => $fromTudu->selfPercent)));
         }
         // 执行人 -- 自己
         if ($action == self::ACTION_APPLY) {
             $tudu->to = Tudu_Tudu_Storage::formatRecordRecipients($fromTudu->to);
         }
         // 暂时不能输入自己 - 界面交互有问题不能支持
         if ($action == self::ACTION_REVIEW && $tudu->reviewer) {
             if (array_key_exists($this->_user->address, $tudu->reviewer) || array_key_exists($this->_user->userName, $tudu->reviewer)) {
                 return $this->json(false, $this->lang['add_reviewer_self']);
             }
         }
         $tuduList[$tudu->tuduId] = $tudu;
         $act = $tudu->tuduId == $tuduId ? $action : 'send';
         if ($act == 'send') {
             $act = $fromTudu && !$fromTudu->isDraft ? 'update' : 'send';
         }
         $detail = $this->_getLogDetail($params, $fromTudu);
         if (in_array($action, array(self::ACTION_REVIEW, self::ACTION_APPLY, self::ACTION_FORWARD, self::ACTION_INVITE))) {
             unset($detail['content']);
         }
         $logDetails[$tudu->tuduId] = array('action' => $act, 'detail' => $detail);
     }
     foreach ($tuduList as $tid => $item) {
         $prevId = $item->prevTuduId;
         if ($prevId && strpos($prevId, 'child-') !== false) {
             $prevId = (int) str_replace('child-', '', $prevId);
             if (isset($children[$prevId])) {
                 $item->prevTuduId = $children[$prevId];
             }
         }
     }
     // 遍历图度列表保存
     foreach ($tuduList as $tid => $tudu) {
         // 主任务按照操作处理
         // 处理审批流程
         if ($action == self::ACTION_REVIEW) {
             $agree = $this->_request->getPost('agree');
             $storage->reviewTudu($tudu, $agree);
             // 其他操作
         } else {
             if ($tid == $tuduId) {
                 $func = $action == 'send' ? 'save' : $action;
                 $func .= 'Tudu';
             } else {
                 $func = 'saveTudu';
             }
             $ret = $storage->{$func}($tudu);
             if (!$ret) {
                 return $this->json(false, $this->lang['save_failure']);
             }
         }
         $returnData['tuduid'] = $tuduId;
     }
     //Tudu_Tudu_Deliver::initAddressBook($this->multidb->getDefaultDb());
     $deliver = Tudu_Tudu_Deliver::getInstance();
     // 遍历图度列表发送图度
     if ($action !== self::ACTION_SAVE) {
         $config = $this->bootstrap->getOption('httpsqs');
         $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']);
         foreach ($tuduList as $tid => $tudu) {
             // 发送到接收人
             $recipients = $deliver->prepareRecipients($this->_user->uniqueId, $this->_user->userId, $tudu);
             if ($action == self::ACTION_REVIEW && $tudu->type == 'notice' && !$this->_request->getPost('agree')) {
                 $recipients = array();
                 $addressBook = $deliver->getAddressBook();
                 $fromSender = $addressBook->searchUser($tudu->orgId, $tudu->sender);
                 if (!empty($fromSender)) {
                     $fromSender['accepterinfo'] = $fromSender['email'] . ' ' . $fromSender['truename'];
                     $fromSender['issender'] = $fromSender['email'] == $tudu->sender;
                     $recipients[$fromSender['uniqueid']] = $fromSender;
                 }
             }
             // 公告(含审批时),过滤接收人
             if ($tudu->type == 'notice' && $tudu->reviewer) {
                 $users = array();
                 foreach ($tudu->reviewer as $item) {
                     foreach ($item as $reviewer) {
                         $users[] = $reviewer['email'];
                     }
                 }
                 // 过滤非审批人的接收用户
                 foreach ($recipients as $uniqueId => $recipient) {
                     if (!in_array($recipient['email'], $users)) {
                         unset($recipients[$uniqueId]);
                     }
                 }
             }
             // 移除原执行人
             if (($tudu->type == 'meeting' || $tudu->type == 'task' && !$tudu->reviewer) && !$tudu->isDraft()) {
                 $accepters = $manager->getTuduAccepters($tudu->tuduId);
                 $to = $tudu->to;
                 foreach ($accepters as $item) {
                     list($email, ) = explode(' ', $item['accepterinfo'], 2);
                     // 移除执行人角色,我执行标签
                     if (!empty($to) && !array_key_exists($email, $to) && $manager->getChildrenCount($tudu->tuduId, $item['uniqueid']) <= 0) {
                         $deliver->removeAccepter($tudu->tuduId, $item['uniqueid']);
                         $manager->deleteLabel($tudu->tuduId, $item['uniqueid'], '^a');
                         $manager->deleteLabel($tudu->tuduId, $item['uniqueid'], '^td');
                     }
                     // 过滤外发执行人 避免重复发送
                     if ($action != self::ACTION_SEND) {
                         foreach ($recipients as $uniqueId => $recipient) {
                             if (!empty($recipient['isforeign']) && !empty($to) && array_key_exists($recipient['email'], $to)) {
                                 unset($recipients[$uniqueId]);
                             }
                         }
                     }
                     // 转发,继续之前的用户进度
                     if ($action == self::ACTION_FORWARD && isset($recipients[$item['uniqueid']])) {
                         $recipients[$item['uniqueid']]['tudustatus'] = (int) $item['tudustatus'];
                     }
                     // 审批,继续之前的用户进度
                     if ($action == self::ACTION_REVIEW && isset($recipients[$item['uniqueid']])) {
                         $recipients[$item['uniqueid']]['percent'] = (int) $item['percent'];
                     }
                 }
             }
             foreach ($recipients as $key => $recipient) {
                 // 需要验证
                 if (!empty($recipient['isforeign'])) {
                     $recipients[$key]['authcode'] = $tudu->isAuth ? Oray_Function::randKeys(4) : null;
                 }
                 // 标记转发
                 // 进度小于 100%是继承进度,100%时为0
                 if ($action == self::ACTION_FORWARD || $action == self::ACTION_INVITE) {
                     $newAccepter = $this->_getReceiver($post, 'to');
                     $fromTudu = $tudu->getFromTudu();
                     if (isset($recipient['role']) && $recipient['role'] == 'to' && array_key_exists($recipient['email'], $newAccepter)) {
                         $recipients[$key]['forwardinfo'] = $this->_user->trueName . "\n" . time();
                         $recipients[$key]['percent'] = $fromTudu->selfPercent < 100 ? $fromTudu->selfPercent : 0;
                         $recipients[$key]['tudustatus'] = $fromTudu->selfTuduStatus < 2 ? $fromTudu->selfTuduStatus : 0;
                     }
                 }
                 if ($tudu->flowId && isset($recipient['role']) && $recipient['role'] == 'to') {
                     $recipients[$key]['tudustatus'] = 1;
                     $recipients[$key]['percent'] = 0;
                 }
             }
             // 过滤外发人 避免重复发送
             /*if ($action != self::ACTION_SEND) {
                   $fromTudu = $tudu->getFromTudu();
                   foreach ($recipients as $uniqueId => $recipient) {
                       if (!empty($recipient['isforeign'])
                           && (($fromTudu->to && array_key_exists($recipient['email'], $fromTudu->to))
                               || ($fromTudu->cc && array_key_exists($recipient['email'], $fromTudu->cc))
                               || ($fromTudu->bcc && array_key_exists($recipient['email'], $fromTudu->bcc))))
                       {
                           unset($recipients[$uniqueId]);
                       }
                   }
               }*/
             // 标记当前用户已转发
             if ($action == self::ACTION_FORWARD) {
                 $manager->markForward($tudu->tuduId, $this->_user->uniqueId);
             }
             // 加上当前用户(发起人)
             if ((!$tudu->isFromTudu() || $tudu->isDraft()) && !isset($recipients[$this->_user->uniqueId])) {
                 $recipients[$this->_user->uniqueId] = array('uniqueid' => $this->_user->uniqueId, 'role' => 'from', 'issender' => true);
             }
             // 发送图度到接收人
             $deliver->sendTudu($tudu, $recipients);
             $flowPercent = null;
             // 计算进度
             if ($tudu->flowId) {
                 if ($tudu->isChange('stepid')) {
                     $progress = $manager->updateFlowProgress($tudu->tuduId, null, $tudu->stepId, null, $flowPercent);
                 }
             } else {
                 $progress = $manager->updateProgress($tudu->tuduId, null, null);
             }
             // 需要计算父任务进度
             if ($tudu->parentId) {
                 $manager->calParentsProgress($tudu->tuduId);
                 // 小于100%的分工从图度箱移除
                 if (!$tudu->flowId) {
                     if ($progress < 100 && !array_key_exists($this->_user->address, $tudu->to)) {
                         $manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^i');
                         $manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^td');
                         $manager->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^c');
                     }
                 }
             }
             // 自己接受当前任务
             if ($action == self::ACTION_SEND || $action == self::ACTION_DIVIDE) {
                 if (($tudu->type == 'task' || $tudu->type == 'meeting') && !$tudu->flowId) {
                     if ($tudu->to && array_key_exists($this->_user->userName, $tudu->to) || $recipients && array_key_exists($this->_user->uniqueId, $recipients) && !$tudu->acceptMode) {
                         $manager->acceptTudu($tudu->tuduId, $this->_user->uniqueId, null);
                     }
                 }
             }
             // 转发操作,添加我转发标签,其他则添加到已发送
             if ($action == self::ACTION_FORWARD) {
                 $manager->addLabel($tuduId, $this->_user->uniqueId, '^w');
             } else {
                 if ($action != self::ACTION_REVIEW) {
                     $manager->addLabel($tuduId, $this->_user->uniqueId, '^f');
                 }
             }
             // 审批标签
             if ($action == self::ACTION_REVIEW) {
                 $manager->deleteLabel($tuduId, $this->_user->uniqueId, '^e');
                 $manager->deleteLabel($tuduId, $this->_user->uniqueId, '^td');
                 $manager->addLabel($tuduId, $this->_user->uniqueId, '^v');
                 $fromTudu = $tudu->getFromTudu();
                 if (null != $fromTudu) {
                     if (is_array($tudu->to) && array_key_exists($fromTudu->sender, $tudu->to) && $tudu->stepId != '^head' && $tudu->stepId != '^break' && !$tudu->flowId && !$tudu->acceptMode) {
                         $addressBook = Tudu_AddressBook::getInstance();
                         $user = $addressBook->searchUser($this->_user->orgId, $fromTudu->sender);
                         if (null !== $user) {
                             $manager->acceptTudu($tudu->tuduId, $user['uniqueid'], null);
                         }
                     }
                 }
             }
             // 移除草稿
             if ($tudu->isDraft()) {
                 $manager->deleteLabel($tuduId, $this->_user->uniqueId, '^r');
             }
             if (isset($logDetails[$tid])) {
                 // 图度日志
                 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tid, $logDetails[$tid]['action'], $logDetails[$tid]['detail'], 0);
             }
             // 记录私密密码
             if ($tudu->password) {
                 $this->session->privacy[$tudu->tuduId] = $tudu->password;
             }
             // 标记所有人未读状态
             $manager->markAllUnRead($tudu->tuduId);
             // 重开讨论
             if ($isReopen) {
                 $manager->closeTudu($tudu->tuduId, 0);
             }
             // 工作流执行人自动接受任务
             if ($tudu->flowId) {
                 $daoStep = $this->getDao('Dao_Td_Tudu_Step');
                 $step = $daoStep->getStep(array('tuduid' => $tudu->tuduId, 'stepid' => $tudu->stepId));
                 if (null !== $step) {
                     $stepUsers = $daoStep->getUsers($tudu->tuduId, $tudu->stepId);
                     if ($step->type == Dao_Td_Tudu_Step::TYPE_EXECUTE && !empty($stepUsers) && $tudu->stepId != '^head' && $tudu->stepId != '^break') {
                         foreach ($stepUsers as $item) {
                             $manager->acceptTudu($tudu->tuduId, $item['uniqueid'], null);
                         }
                         $manager->updateTudu($tudu->tuduId, array('acceptmode' => 0));
                         // 认领模式
                     } else {
                         if ($step->type == Dao_Td_Tudu_Step::TYPE_CLAIM) {
                             $manager->updateTudu($tudu->tuduId, array('acceptmode' => 1, 'accepttime' => null));
                         }
                     }
                 }
                 if ($flowPercent == 100 && !$tudu->needConfirm) {
                     $manager->doneTudu($tudu->tuduId, true, 0);
                     // 添加操作日志
                     $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tudu->tuduId, Dao_Td_Log_Log::ACTION_TUDU_DONE, array('percent' => $flowPercent), false, true);
                 }
             }
             // 记录外发人员
             $contacts = array();
             foreach ($recipients as $item) {
                 if (!empty($item['isforeign'])) {
                     $contacts[] = $item['uniqueid'];
                 }
             }
             if ($contacts) {
                 $this->session->tuduContact[$tudu->tuduId] = $contacts;
             }
             $sqsAction = !$tudu->isFromTudu() || $tudu->isDraft() ? 'create' : 'update';
             $isChangedCc = $tudu->isChange('cc') || $tudu->isChange('bcc');
             $sqsParam = array('tsid' => $this->_user->tsId, 'tuduid' => $tid, 'from' => $this->_user->userName, 'uniqueid' => $this->_user->uniqueId, 'server' => $this->_request->getServer('HTTP_HOST'), 'type' => $type, 'ischangedCc' => $sqsAction == 'update' && $isChangedCc ? $isChangedCc : false);
             if ($action == self::ACTION_SEND && $tudu->flowId && $sqsAction == 'create') {
                 $sqsParam['nstepid'] = $tudu->stepId;
                 $sqsParam['flowid'] = $tudu->flowId;
             }
             if ($action == self::ACTION_REVIEW) {
                 $sqsAction = 'review';
                 $sqsParam['stepid'] = $tudu->getFromTudu()->stepId;
                 $sqsParam['agree'] = $this->_request->getPost('agree');
                 if ($tudu->flowId) {
                     $sqsParam['nstepid'] = $tudu->stepId;
                     $sqsParam['flowid'] = $tudu->flowId;
                     $sqsParam['stepstatus'] = $tudu->currentStepStatus;
                 }
                 if ($tudu->type == 'notice' && ($tudu->stepId = '^end')) {
                     $sqsAction = 'create';
                 }
             }
             $httpsqs->put(implode(' ', array('tudu', $sqsAction, '', http_build_query($sqsParam))), 'tudu');
         }
         // 保存到发起人草稿箱
     } else {
         foreach ($tuduList as $tid => $tudu) {
             if (!$tudu->parentId) {
                 $deliver->saveDraft($tudu);
             }
         }
     }
     $message = $action !== self::ACTION_SAVE ? $this->lang['send_success'] : $this->lang['save_success'];
     Tudu_Tudu_Extension::unRegisterAll();
     return $this->json(true, $message, $returnData);
 }
コード例 #22
0
 /**
  * 下载附件
  */
 public function indexAction()
 {
     $this->_helper->viewRenderer->setNeverRender();
     $act = $this->_request->getParam('act', $this->_request->getQuery('action'));
     $fileId = $this->_request->getQuery('fid', $this->_request->getQuery('aid'));
     $mod = $this->_request->getParam('mod', self::UPLOAD_ATTACHMENT);
     if ($mod == self::UPLOAD_ATTACHMENT) {
         /* @var $file Dao_Td_Attachment_Record_File */
         $file = $this->getDao('Dao_Td_Attachment_File')->getFile(array('fileid' => $fileId));
         if (null === $file || !$file->tuduId && $file->uniqueId != $this->_user->uniqueId) {
             Oray_Function::alert($this->lang['file_not_exists']);
             return false;
         }
         if ($file->tuduId) {
             $tudu = $this->getDao('Dao_Td_Tudu_Tudu')->getTuduById($this->_user->uniqueId, $file->tuduId);
             $boards = $this->getBoards(false);
             $board = $boards[$tudu->boardId];
             $isModerators = array_key_exists($this->_user->userId, $board['moderators']);
             $inGroups = (bool) sizeof(array_uintersect($this->_user->groups, $board['groups'], "strcasecmp"));
             $isSuperModerator = !empty($board['parentid']) && array_key_exists($this->_user->userId, $boards[$board['parentid']]['moderators']);
             // 禁止访问
             if (null === $tudu || !$tudu->uniqueId && !$isModerators && !$isSuperModerator && !$inGroups) {
                 Oray_Function::alert($this->lang['file_deny_access']);
                 return false;
             }
         }
     } elseif ($mod == self::UPLOAD_NETDISK) {
         /* @var $daoFile Dao_Td_Netdisk_File */
         $daoFile = $this->getDao('Dao_Td_Netdisk_File');
         $ownerId = $this->_request->getQuery('ownerid');
         $file = $daoFile->getFile(array('uniqueid' => $ownerId, 'fileid' => $fileId));
         if (null === $file) {
             Oray_Function::alert($this->lang['file_not_exists']);
             return false;
         }
         /* @var $daoShare Dao_Td_Netdisk_Share */
         $daoShare = $this->getDao('Dao_Td_Netdisk_Share');
         $share = $daoShare->getShare(array('objectid' => $fileId, 'targetid' => $this->_user->userName, 'ownerid' => $ownerId));
         if (null === $file) {
             Oray_Function::alert($this->lang['file_not_exists']);
             return false;
         }
     } else {
         Oray_Function::alert($this->lang['file_not_exists']);
         return false;
     }
     $option = $this->bootstrap->getOption('upload');
     $path = $option['path'] . '/' . $file->path . '/' . $file->fileId;
     if (!file_exists($path)) {
         return Oray_Function::alert($this->lang['file_not_exists']);
     }
     $this->_response->setHeader('Content-Type', $file->type . ', charset=utf-8');
     $this->_response->setHeader('Content-Length', $file->size);
     $type = $act == 'view' ? 'inline' : 'attachment';
     // FF Only
     if (false !== strpos(strtolower($this->_request->getServer('HTTP_USER_AGENT')), 'firefox')) {
         $this->_response->setHeader('Content-Disposition', $type . ';filename*=UTF-8\'\'' . urlencode($file->fileName));
         // Other
     } else {
         $this->_response->setHeader('Content-Disposition', $type . ';filename=' . urlencode($file->fileName));
     }
     $this->_response->sendHeaders();
     $fp = fopen($path, 'rb');
     while (!feof($fp)) {
         echo fread($fp, 4096);
         @flush();
         @ob_flush();
     }
     fclose($fp);
     // 取消输出 - 主要避免再次输出文件头,两种方式,第一种比较直接
     $this->getFrontController()->returnResponse(true);
     //$this->_response->clearAllHeaders();
 }
コード例 #23
0
 /**
  * 接收参数,通过接口方 OpenApi 进行验证
  * 登录图度
  */
 public function indexAction()
 {
     $query = $this->_request->getQuery();
     $config = $this->getInvokeArg('bootstrap')->getOptions();
     $multidb = $this->getInvokeArg('bootstrap')->getResource('multidb');
     $time = time();
     Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_TS => $multidb->getDb('ts1')));
     // 缺少验证接口标识参数
     if (empty($query['from'])) {
         return $this->_redirect('http://www.tudu.com/');
     }
     $from = $query['from'];
     $className = 'Model_OpenApi_' . ucfirst($query['from']);
     $classFile = 'Model/OpenApi/' . ucfirst($query['from']) . '.php';
     // 缺少配置参数
     if (empty($config['openapi'][strtolower($from)])) {
         return $this->_redirect('http://www.tudu.com/');
     }
     $params = array_merge($config['openapi'][strtolower($from)], $query);
     header('P3P: CP=”CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR”');
     try {
         require_once $classFile;
         // 进行登录验证
         call_user_func(array($className, 'auth'), $params);
         // 查找应用组织关联表
         $daoAssociate = Tudu_Dao_Manager::getDao('Dao_Md_Org_Associate', Tudu_Dao_Manager::DB_MD);
         // 获取用户信息
         $params = array_merge($config['openapi'][strtolower($from)], array('uid' => $query['uu_id']));
         $userInfo = call_user_func(array($className, 'getUserInfo'), $params);
         $orgId = $daoAssociate->getOrgIdByUid($from, $userInfo['uid']);
         if (false === $orgId) {
             $orgId = $this->_getOrgId($from);
             // 创建组织
             require_once 'Model/Org/Org.php';
             Model_Org_Org::setResource('config', $config);
             Model_Org_Org::createOrg($orgId, array('userid' => 'admin', 'password' => md5(Oray_Function::randKeys(16)), 'truename' => $userInfo['truename'], 'orgname' => $userInfo['orgname']));
             // 创建关联
             $daoAssociate->createAssociate(array('orgid' => $orgId, 'from' => $from, 'uid' => $userInfo['uid'], 'truename' => $userInfo['truename'], 'email' => $userInfo['email'], 'mobile' => $userInfo['mobile'], 'tel' => $userInfo['tel'], 'createtime' => time()));
         }
         // 获取用户信息
         $adapter = new Tudu_Auth_Adapter_User(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_MD));
         $adapter->setUsername('admin@' . $orgId)->setAuto(true);
         $result = $adapter->authenticate();
         $names = $config['cookies'];
         if (!$result->isValid()) {
             $this->_setCookies(array($names['auth'] => false, $names['username'] => false));
             return $this->_redirect('http://www.tudu.com/');
         }
         $identity = $result->getIdentity();
         // 登录
         if (Zend_Session::isStarted()) {
             session_unset();
             Zend_Session::namespaceUnset(self::SESSION_NAMESPACE);
             Zend_Session::regenerateId();
         }
         $session = new Zend_Session_Namespace(self::SESSION_NAMESPACE, true);
         $session->auth = array_merge($identity, array('logintime' => $time));
         $session->auth['appinvoker'] = $from;
         // 验证相关的Cookies
         $this->_setCookies(array($names['username'] => $identity['username'], $names['server'] => $orgId . '.tudu.com'), null);
         // 其它场合要用到的Cookies,永久。
         $this->_setCookies(array($names['track'] => base64_encode('http://www.tudu.com/login')), $time + 86400 * 365);
         // 同时要登录后台
         $adapter = new Tudu_Auth_Adapter_Admin(array('db' => Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_MD)));
         $adapter->setUsername($identity['username'])->setAuto(true);
         $result = $adapter->authenticate();
         if ($result->isValid()) {
             $session->admin = array_merge($result->getIdentity(), array('logintime' => $time));
         }
         // 操作失败
     } catch (Exception $e) {
         return $this->_redirect('http://www.tudu.com/');
     }
     return $this->_redirect('http://online-app.tudu.com/frame-inc/');
 }
コード例 #24
0
ファイル: Helper.php プロジェクト: bjtenao/tudu-web
 /**
  * Zend_Db::factory的封装,主要进行密码转换
  * 
  * 非密码加密形式的,请直接使用Zend_Db::factory
  * 
  * @param array $params
  * @return Zend_Db_Adapter_Abstract
  */
 public static function factory(array $params)
 {
     $adapter = $params['adapter'];
     $config = $params['params'];
     $config['password'] = Oray_Function::decryptString($config['password']);
     return Zend_Db::factory($adapter, $config);
 }
コード例 #25
0
ファイル: UpdateController.php プロジェクト: bjtenao/tudu-web
 /**
  * 在线升级
  */
 public function indexAction()
 {
     $operation = $this->_request->getParam('operation');
     $this->view->operation = $operation;
     $this->view->tuduversion = TUDU_VERSION;
     if (empty($operation)) {
         return $this->render('index');
     }
     if ($operation == 'check') {
         // 检查是否有新版本
         $check = Oray_Function::httpRequest($this->_upgradeUrl);
         $upgrade = json_decode($check, true);
         if (empty($upgrade['lastest'])) {
             $this->view->unupgrade = true;
             return $this->render('index');
         }
         $lastest = $upgrade['lastest'];
         if (TUDU_VERSION == $lastest['version'] && TUDU_RELEASE == $lastest['release']) {
             $this->view->islastest = true;
             return $this->render('index');
         }
         // WWW_ROOT目录是否可写
         if (!$this->dirWriteable(WWW_ROOT)) {
             $this->view->diswriteable = true;
             $this->view->rootpath = WWW_ROOT;
             return $this->render('index');
         }
         $this->view->checkfinsh = true;
         $this->view->lastest = $lastest;
     } elseif ($operation == 'upgrade') {
         $downloadUrl = $this->_request->getParam('fileurl');
         $lastestMd5 = $this->_request->getParam('filemd5');
         $upgradeFile = $this->downloadFile($downloadUrl, 120);
         if ($upgradeFile == 'empty_url' || $upgradeFile == 'timeout' || $upgradeFile == 'mkdir_error') {
             return $this->showMsg($upgradeFile);
         }
         // 验证MD5
         if (md5_file($upgradeFile) != $lastestMd5) {
             return $this->showMsg('md5_error');
         }
         // 解压缩
         $ret = $this->unZip($upgradeFile);
         if (!$ret['success']) {
             return $this->showMsg('unzip_error');
         }
         // 判断目录文件是否有相应的文件
         $dirs = $this->getDirs($this->_updatePath, true);
         $errorPerm = array();
         foreach ($dirs as $item) {
             if ($item['path'] == $upgradeFile) {
                 continue;
             }
             $destDir = WWW_ROOT . DIRECTORY_SEPARATOR . $item['entry'];
             if (!$this->checkPerm($destDir, $item['type'])) {
                 $errorPerm[] = $destDir;
             }
         }
         if (!empty($errorPerm)) {
             return $this->showMsg('error_perm', $errorPerm);
         }
         // 复制替换目录文件
         $dirs = $this->getDirs($this->_updatePath);
         foreach ($dirs as $item) {
             $this->copyDir($item['path'], WWW_ROOT . DIRECTORY_SEPARATOR . $item['entry']);
         }
         // 完成,删除更新的目录;清除smarty模板编译缓存
         $this->rmdirs($this->_updatePath);
         $this->clearSmartyCache();
         return $this->showMsg('upgrade_finish');
     }
 }
コード例 #26
0
ファイル: Apply.php プロジェクト: bjtenao/tudu-web
 /**
  * 显示图度内容
  */
 public function viewAction()
 {
     $tuduId = $this->_request->getQuery('tid');
     $newwin = (bool) $this->_request->getQuery('newwin');
     if (null === $tuduId) {
     }
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $daoApply = Tudu_Dao_Manager::getDao('Dao_App_Attend_Apply', Tudu_Dao_Manager::DB_APP);
     $tudu = $daoTudu->getTuduById($this->_user->uniqueId, $tuduId);
     if (null === $tudu) {
         return Oray_Function('');
     }
     if ($newwin) {
         $daoOrg = Tudu_Dao_Manager::getDao('Dao_Md_Org_Org', Tudu_Dao_Manager::DB_MD);
         $org = $daoOrg->getOrg(array('orgid' => $this->_user->orgId));
         $this->view->org = $org->toArray();
     }
     $apply = $daoApply->getApply(array('tuduid' => $tuduId));
     if (null === $apply) {
         Oray_Function::alert('考勤申请不存在或已被删除');
     }
     $isSender = $this->_user->uniqueId == $apply->senderId;
     $isTarget = $this->_user->uniqueId == $apply->uniqueId;
     $access = array('view' => $tudu->uniqueId == $this->_user->uniqueId && !empty($tudu->labels), 'reply' => $this->_user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_POST), 'modify' => $this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_TUDU) && $isSender, 'delete' => false, 'upload' => $this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPLOAD_ATTACH), 'cancel' => ($isSender || $isTarget) && !$tudu->isDone, 'confirm' => $isSender && !$tudu->isDone, 'undone' => $isSender && $tudu->isDone, 'ignore' => true, 'target' => $isTarget, 'sender' => $isSender, 'agree' => false, 'disagree' => false);
     if ($tudu->isDone) {
         $access['reply'] = false;
         $access['modify'] = false;
     }
     // 回复内容
     $page = (int) $this->_request->getQuery('page');
     $pageSize = max(20, (int) $this->_user->option['replysize']);
     $uniqueId = $this->_request->getQuery('unid');
     $back = $this->_request->getQuery('back');
     $recordCount = $tudu->replyNum + 1;
     $labels = $this->_this->getLabels();
     $isInvert = (bool) $this->_request->getQuery('invert', isset($this->_user->option['postsort']) && $this->_user->option['postsort'] == 1);
     $query = array('tid' => $tudu->tuduId, 'back' => $back, 'invert' => $isInvert ? 1 : 0);
     $condition = array('tuduid' => $tudu->tuduId);
     // 已关联用户,设置已读状态
     if ($tudu->uniqueId == $this->_user->uniqueId) {
         if (!$tudu->isRead) {
             $daoTudu->markRead($tuduId, $this->_user->uniqueId);
         }
         // 增加到关联用户,解决版块中的已读未读状态问题(!!会导致重新发送的不会投递到用户图度箱)
     } else {
         $daoTudu->addUser($tuduId, $this->_user->uniqueId, array('isread' => true));
     }
     // 增加浏览次数
     $daoTudu->hit($tudu->tuduId);
     /* @var $daoPost Dao_Td_Tudu_Post */
     $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS);
     if ($uniqueId) {
         $condition['uniqueid'] = $uniqueId;
         $query['unid'] = $uniqueId;
         $recordCount = $daoPost->getPostCount($tudu->tuduId, $uniqueId);
     }
     $pageCount = intval(($recordCount - 1) / $pageSize) + 1;
     $isLast = false;
     if ($page == 'last') {
         $page = $pageCount;
         $isLast = true;
     } else {
         $page = min($pageCount, max(1, (int) $page));
     }
     $postSort = $isInvert ? 'createtime DESC' : 'createtime ASC';
     // 获取回复内容
     $posts = $daoPost->getPostPage($condition, $postSort, $page, $pageSize)->toArray();
     // 回复者的在线状态
     $status = array();
     // 回复的相关权限
     $postAccess = array('modify' => $this->_user->getAccess()->isAllowed(Tudu_Access::PERM_UPDATE_POST), 'delete' => $this->_user->getAccess()->isAllowed(Tudu_Access::PERM_DELETE_POST));
     foreach ($posts as $key => $post) {
         // 读取回复的附件信息
         if ($post['attachnum'] > 0) {
             $files = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS)->getFiles(array('tuduid' => $tudu->tuduId, 'postid' => $post['postid']));
             $posts[$key]['attachment'] = $files->toArray();
         }
         // 权限
         if (!$post['isfirst'] && !$tudu->isDone) {
             $posts[$key]['access'] = array('modify' => $postAccess['modify'] && $post['uniqueid'] == $this->_user->uniqueId, 'delete' => $postAccess['delete'] && $post['uniqueid'] == $this->_user->uniqueId);
         }
         if ($post['header']) {
             $posts[$key]['header'] = $this->formatPostHeader($post['header']);
         }
         if ($post['email']) {
             if (!array_key_exists($post['email'], $status)) {
                 $status[$post['email']] = false;
             }
             $posts[$key]['imstatus'] =& $status[$post['email']];
         }
     }
     if ($tudu->stepId && strpos($tudu->stepId, '^') !== 0) {
         /* @var $daoStep Dao_Td_Tudu_Step */
         $daoStep = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Step', Tudu_Dao_Manager::DB_TS);
         $step = $daoStep->getCurrentStep($tuduId, $tudu->stepId, $this->_user->uniqueId);
         if (null !== $step && $step['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE) {
             $this->view->isreview = true;
         }
         if (null !== $step && $step['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE) {
             if ($step['uniqueid'] == $this->_user->uniqueId && $step['status'] == 1 && !$tudu->isDone) {
                 $access['agree'] = true;
                 $access['disagree'] = true;
             }
             $access['forward'] = false;
             $access['divide'] = false;
             $access['accept'] = false;
             $access['reject'] = false;
             $access['progress'] = false;
             $access['review'] = false;
         }
     }
     // 获取联系人的IM在线信息
     $config = $this->_this->bootstrap->getOption('im');
     $im = new Oray_Im_Client($config['host'], $config['port']);
     $imStatus = $im->getUserStatus(array_keys($status));
     foreach ($imStatus as $email => $_status) {
         if (isset($status[$email])) {
             $status[$email] = $_status;
         }
     }
     //$daoStep = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Step', Tudu_Dao_Manager::DB_TS);
     $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS);
     $flow = $daoFlow->getFlow(array('tuduid' => $tudu->tuduId));
     if ($flow) {
         $steps = $flow->steps;
         foreach ($steps as $sid => $step) {
             if ($sid == $flow->currentStepId) {
                 $section = $step['section'][$step['currentSection']];
                 if (count($section) > 1) {
                     $this->view->samereview = true;
                 }
                 foreach ($section as $u) {
                     if ($u['uniqueid'] == $this->_user->uniqueId && $u['status'] == 1) {
                         $access['agree'] = $access['disagree'] = true;
                     }
                 }
             }
         }
         $this->view->steps = $steps;
     }
     /*
             $users   = $daoStep->getTuduStepUsers($tudu->tuduId);
             $accepters = $daoTudu->getAccepters($tuduId);
     
             $isDisagreed = false;
             $steps = array();
             $isExceed = false;
             $processIndex = null;
             $sameReview = false;
             $currentUser = array();
             $currentIndex = null;
             foreach ($users as &$user) {
                 $info = explode(' ', $user['userinfo']);
                 $user['email']    = $info[0];
                 $user['truename'] = $info[1];
     
                 if ($user['type'] == Dao_Td_Tudu_Step::TYPE_EXECUTE && $user['stepid'] == $tudu->stepId && !empty($accepters)) {
                     foreach ($accepters as $accepter) {
                         if ($accepter['uniqueid'] == $user['uniqueid']) {
                             $user['percent'] = $accepter['percent'];
                         }
                     }
                 }
     
                 $processIndex = $user['processindex'];
     
                 if (!$isExceed && $user['stepid'] == $tudu->stepId) {
                     $isExceed = true;
                 }
     
                 if ($isExceed && ($user['stepid'] != $tudu->stepId || ($user['type'] == 1 && $user['status'] < 1))) {
                     $user['future'] = true;
                 }
     
                 $steps[$user['ordernum']]['users'][]    = $user;
                 $steps[$user['ordernum']]['stepid']     = $user['stepid'];
                 $steps[$user['ordernum']]['type']       = $user['type'];
                 $steps[$user['ordernum']]['stepstatus'] = $user['stepstatus'];
                 $steps[$user['ordernum']]['future']     = !empty($user['future']);
     
                 if ($user['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE && $user['status'] > 2) {
                     $isDisagreed = true;
                 }
     
                 if ($tudu->flowId && $user['stepid'] == $tudu->stepId) {
                     if (null === $currentIndex && $user['status'] < 2) {
                         $currentIndex = $user['processindex'];
                     }
                     if ($currentIndex == $user['processindex']) {
                         $currentUser[] = $user['userinfo'];
                     }
     
                     if ($user['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE) {
                         $steptype = 1;
                     } else {
                         $steptype = 0;
                     }
                     $this->view->steptype = $steptype;
                 }
             }
             // 判断是否同时审批
             $index = null;
             foreach ($users as $item) {
     
                 if ($item['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE && $item['stepid'] == $tudu->stepId) {
                     if ($index == $item['processindex']) {
                         $sameReview = true;
                     }
                     $index = $item['processindex'];
                 }
             }
     
             if ($sameReview) {
                 foreach ($users as $item) {
                     if ($tudu->flowId && $item['stepid'] == $tudu->stepId) {
                         $currentUser[] = $item['userinfo'];
                     }
                 }
             }
     
             ksort($steps);
     
             if (!empty($currentUser)) {
                 $tudu->to = Dao_Td_Tudu_Tudu::formatAddress(implode("\n", array_unique($currentUser)));
             }
     
             if ($isDisagreed && count($steps)) {
                 if ($tudu->flowId) {
                     $access['accept'] = false;
                     if (strpos($tudu->stepId, '^') === 0) {
                         $access['reject'] = false;
                     }
                 } else {
                     $lastStep = end($steps);
     
                     if ($lastStep['type'] == 0) {
                         $arrTo = array();
                         foreach ($lastStep['users'] as $u) {
                             $arrTo[$u['email']] = array($u['truename'], null, null, $u['email']);
                         }
     
                         $tudu->to = $arrTo;
     
                         if (!isset($arrTo[$this->_user->userName])) {
                             $access['accept'] = false;
                             $access['reject'] = false;
                         }
                     }
     
                     reset($steps);
                 }
             }
     
             if ($sameReview) {
                 $this->view->samereview = $sameReview;
             }
     
             if (count($steps) > 0) {
                 $this->view->steps = $steps;
             }*/
     if ($access['upload']) {
         $upload = $this->_this->options['upload'];
         $upload['cgi']['upload'] .= '?' . session_name() . '=' . Zend_Session::getId() . '&email=' . $this->_user->address;
         $this->view->upload = $upload;
     }
     $this->view->registModifier('tudu_format_content', array($this, 'formatContent'));
     $this->view->registModifier('tudu_get_attachment_url', array($this, 'getAttachmentUrl'));
     $this->view->registFunction('format_label', array($this, 'formatLabels'));
     $this->view->access = $access;
     $this->view->tudu = $tudu->toArray();
     $this->view->apply = $apply->toArray();
     $this->view->posts = $posts;
     $this->view->pageinfo = array('currpage' => $page, 'pagecount' => $pageCount, 'pagesize' => $pageSize, 'recordcount' => $recordCount, 'query' => $query, 'url' => '/tudu/view');
     $this->view->cookies = serialize($this->_request->getCookie());
     $this->view->query = $query;
     $this->view->labels = $labels;
     $this->view->newwin = $newwin;
     $this->view->imstatus = $imStatus;
     $this->view->isinvert = $isInvert;
 }
コード例 #27
0
    /**
     * 转发图度
     *
     */
    public function sendAction()
    {
        $post = $this->_request->getPost();
        $post = array_merge(array('to' => '', 'cc' => ''), $post);
        $action = $post['action'];
        $type = $post['type'];
        // 判断操作,默认为发送
        if (!in_array($action, array('send', 'save'))) {
            $action = 'send';
        }
        // 判断类型,默认为任务
        if (!in_array($type, array('task', 'discuss', 'notice'))) {
            $type = 'task';
        }
        // 当前用户唯一ID
        $uniqueId = $this->_user['uniqueid'];
        // 是否现在发送
        $isSend = true;
        // 是否已经发送过,可判读来源的图度是否发送过,已发送过的不允许保存为草稿
        $isSent = false;
        // 是否转发
        $isForward = !empty($post['forward']);
        // 是否来源于草稿
        $isFromDraft = false;
        // 是否发起人
        $isSender = false;
        // 是否执行人
        $isAccpter = false;
        // 是否通知所有关联人员
        $notifyAll = !empty($post['notifyall']);
        // 需要发送提醒的人
        $notifyTo = array();
        // 抄送人加入自己
        $post['cc'] .= "\n" . $this->_user['email'] . ' ' . $this->_user['truename'];
        // 需要发送的地址,可能为空
        $address = array('to' => $this->_formatRecipients($post['to']), 'cc' => $this->_formatRecipients($post['cc'], true));
        // 需要发送的执行人,方便后面调用
        $accepters = $address['to'];
        // 需要投递的联系人数据,保存用户唯一ID
        // uniqueid => array(isaccepter => {boolean}, accepterinfo => {string})
        $recipients = array();
        // 需要移除接受人的用户唯一ID
        $removeAccepters = array();
        if (null === $this->_tudu) {
            return $this->json(false, $this->lang['tudu_not_exists']);
        }
        $fromTudu = $this->_tudu;
        // 日志记录内容
        $tuduLog = array('action' => 'create', 'detail' => array());
        $postLog = array('action' => 'create', 'detail' => array());
        ////////////////////////////
        // 操作及参数判断
        // 发送操作
        if ('send' == $action) {
            $isAccpter = array_key_exists($this->_user['email'], $accepters);
            // 如果是转发
            if ($isForward) {
                // 转发时,必须有图度存在
                if (!$fromTudu) {
                    $this->json(false, $this->lang['tudu_not_exists']);
                }
                // 图度组不能转发
                if ($fromTudu->isTuduGroup) {
                    $this->json(false, $this->lang['deny_forward_tudugroup']);
                }
                // 非图度执行人不能转发图度
                if (!in_array($this->_user['email'], $fromTudu->accepter)) {
                    $this->json(false, $this->lang['forbid_non_accepter_forward']);
                }
                // 执行人不能转发给自己
                if ($isAccpter) {
                    $this->json(false, $this->lang['forbid_forward_myself']);
                }
                foreach ($address['to'] as $a => $n) {
                    if (in_array($a, $fromTudu->accepter, true)) {
                        $this->json(false, sprintf($this->lang['user_is_accepter'], $n));
                    }
                }
                $tuduLog['action'] = Dao_Td_Log_Log::ACTION_TUDU_FORWARD;
            }
            // 保存图度
        } else {
            if ('save' == $action) {
                $this->json(false);
            }
        }
        // 发送时参数判断,1.检查必须的参数,2.检查联系人是否存在。保存草稿时不需要这些判断
        if ($isSend) {
            if ('task' == $type) {
                if (empty($address['to']) && (!$fromTudu || !$fromTudu->isTuduGroup)) {
                    $this->json(false, $this->lang['missing_to']);
                }
            } else {
                if (empty($address['cc'])) {
                    $this->json(false, $this->lang['missing_cc']);
                }
            }
            if (!$isForward && empty($post['subject'])) {
                $this->json(false, $this->lang['missing_subject']);
            }
            if (empty($post['content'])) {
                $this->json(false, $this->lang['missing_content']);
            }
            /* @var $daouser Dao_Td_Contact_Contact */
            $daoContact = $this->getDao('Dao_Td_Contact_Contact');
            /* @var $daoUser Dao_Md_User_User */
            $daoUser = Oray_Dao::factory('Dao_Md_User_User');
            $forwardInfo = array();
            //被转发用户继承转发用户进度
            if ($isForward) {
                $forwardInfo = array('forwardinfo' => $this->_user['truename'] . "\n" . time(), 'percent' => isset($post['percent']) ? (int) $post['percent'] : $fromTudu->selfPercent);
            }
            $users = $this->_deliver->getTuduUsers($this->_tudu->tuduId);
            $isAuth = $fromTudu->isAuth;
            // 外部联系人转发,仅从当前图度相关用户中检查
            foreach ($address['to'] as $a => $name) {
                foreach ($users as $u) {
                    if ($u['email'] == $a && $u['truename'] == $name) {
                        $unId = $u['uniqueid'];
                        $recipients[$unId] = array_merge(array('uniqueid' => $unId, 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'accepterinfo' => $a . ' ' . $name, 'percent' => 0, 'tudustatus' => 0, 'isforeign' => $u['isforeign'], 'authcode' => $u['isforeign'] && $isAuth ? Oray_Function::randKeys(4) : null), $forwardInfo);
                        continue 2;
                    }
                }
                $unId = Dao_Td_Contact_Contact::getContactId();
                $info = Oray_Function::isEmail($a) ? $a . ' ' . $name : $name;
                $recipients[$unId] = array_merge(array('uniqueid' => $unId, 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'accepterinfo' => $info, 'percent' => 0, 'tudustatus' => 0, 'isforeign' => 1, 'authcode' => $isAuth ? Oray_Function::randKeys(4) : null), $forwardInfo);
            }
            // 去除原有执行人
            if ($fromTudu) {
                $fromAccepter = $this->_deliver->getTuduAccepters($fromTudu->tuduId);
                $removeInfos = array();
                $to = array();
                foreach ($fromAccepter as $acpter) {
                    if ($isForward) {
                        if ($acpter['uniqueid'] == $uniqueId) {
                            $removeAccepters[] = $this->_user['uniqueid'];
                            $removeInfos[$this->_user['uniqueid']] = $acpter['accepterinfo'];
                            continue;
                        }
                    } elseif (!isset($recipients[$acpter['uniqueid']]) || !is_array($recipients[$acpter['uniqueid']])) {
                        $removeAccepters[] = $acpter['uniqueid'];
                        $removeInfos[$acpter['uniqueid']] = $acpter['accepterinfo'];
                        continue;
                    }
                    if (isset($recipients[$acpter['uniqueid']]['tudustatus'])) {
                        $recipients[$acpter['uniqueid']]['percent'] = (int) $acpter['percent'];
                        if (!$isForward && $acpter['tudustatus'] != 3) {
                            $recipients[$acpter['uniqueid']]['tudustatus'] = $acpter['tudustatus'];
                        }
                    }
                    $to[] = $acpter['accepterinfo'];
                    $acceptInfo = explode(' ', $acpter['accepterinfo']);
                    $notifyTo[] = $acceptInfo[0];
                }
                $post['to'] = array_unique(array_merge($to, explode("\n", $post['to'])));
                $post['to'] = implode("\n", $post['to']);
                if ($fromTudu->isTuduGroup && !empty($removeAccepters)) {
                    /** @var $daoGroup Dao_Td_Tudu_Group */
                    $daoGroup = $this->getDao('Dao_Td_Tudu_Group');
                    foreach ($removeAccepters as $unId) {
                        if ($daoGroup->getChildrenCount($fromTudu->tuduId, $unId) > 0) {
                            $this->json(false, sprintf($this->lang['user_has_divide'], $removeInfos[$unId]));
                        }
                    }
                }
            }
            // 处理抄送人
            $arrCC = array();
            // 外部联系人转发,仅从当前图度相关用户中检查
            foreach ($address['cc'] as $a => $name) {
                foreach ($users as $u) {
                    if ($u['email'] == $a && $u['truename'] == $name) {
                        $unId = $u['uniqueid'];
                        $recipients[$unId] = array('uniqueid' => $unId, 'role' => Dao_Td_Tudu_Tudu::ROLE_CC, 'accepterinfo' => $a . ' ' . $name, 'isforeign' => $u['isforeign'], 'authcode' => $u['isforeign'] && $isAuth ? Oray_Function::randKeys(4) : null);
                        continue 2;
                    }
                }
                $unId = Dao_Td_Contact_Contact::getContactId();
                $recipients[$unId] = array('uniqueid' => $unId, 'role' => Dao_Td_Tudu_Tudu::ROLE_CC, 'accepterinfo' => $a . ' ' . $name, 'isforeign' => 1, 'authcode' => $isAuth ? Oray_Function::randKeys(4) : null);
            }
            // 编辑/转发,合并原有转发人信息
            if (null !== $fromTudu) {
                $fromCC = array();
                foreach ($fromTudu->cc as $addr => $cc) {
                    if (!array_key_exists($addr, $address['cc'])) {
                        $fromCC[] = $addr . ' ' . $cc[0];
                    }
                }
                $post['cc'] = implode("\n", $fromCC) . "\n" . $post['cc'];
            }
            // 通知所有人
            if (in_array($type, array('notice', 'discuss')) || $notifyAll) {
                $notifyTo = array_merge($notifyTo, $arrCC);
            }
            if ($fromTudu) {
                $users = $this->_deliver->getTuduUsers($fromTudu->tuduId);
                foreach ($users as $item) {
                    $labels = explode(',', $item['labels']);
                    if (in_array('^t', $labels) && !in_array('^n', $labels)) {
                        $user = $daoUser->getUser(array('uniqueid' => $item['uniqueid']));
                        $notifyTo[] = $user->address;
                    }
                }
            }
            // 通知跳过当前操作用户(如果有)
            $notifyTo = array_unique(array_diff($notifyTo, array($this->_user['email'])));
            if ($type == 'notice' && !isset($post['remind'])) {
                $notifyTo = null;
            }
            //$recipients = array_unique($recipients);
            //var_dump($address);
            //var_dump($recipients);
        }
        ////////////////////////////////
        // 参数构造逻辑
        // 基本参数
        $params = array('orgid' => $this->_tudu->orgId, 'boardid' => $fromTudu ? $fromTudu->boardId : $post['bid'], 'email' => $this->_user['email'], 'type' => $type, 'subject' => isset($post['subject']) ? $post['subject'] : $fromTudu->subject, 'to' => $post['to'], 'cc' => $post['cc'], 'priority' => empty($post['priority']) ? 0 : (int) $post['priority'], 'privacy' => empty($post['privacy']) ? 0 : (int) $post['privacy'], 'status' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'lastposttime' => $this->_timestamp, 'content' => $post['content'], 'attachment' => !empty($post['attach']) ? (array) $post['attach'] : array(), 'file' => !empty($post['file']) ? (array) $post['file'] : array());
        if (isset($post['starttime'])) {
            $params['starttime'] = !empty($post['starttime']) ? strtotime($post['starttime']) : null;
        }
        if (isset($post['endtime'])) {
            $params['endtime'] = !empty($post['endtime']) ? strtotime($post['endtime']) : null;
        }
        if (isset($post['totaltime']) && is_numeric($post['totaltime'])) {
            $params['totaltime'] = round((double) $post['totaltime'], 2) * 3600;
        }
        if (isset($post['percent'])) {
            $params['percent'] = min(100, (int) $post['percent']);
        }
        if (isset($post['classid'])) {
            $params['classid'] = $post['classid'];
        }
        if (!empty($post['notifyall'])) {
            $params['notifyall'] = $post['notifyall'];
        }
        // 公告置顶
        if ($type == 'notice' && !empty($params['endtime']) && $params['endtime'] >= strtotime('today')) {
            $params['istop'] = 1;
        } else {
            $params['istop'] = 0;
        }
        // 仅当草稿发送时更新创建时间
        if (!$fromTudu || $isFromDraft && $isSend) {
            $params['createtime'] = $this->_timestamp;
        }
        // 更新图度操作时,一些参数设置
        if (!isset($params['percent'])) {
            $params['percent'] = $fromTudu->percent;
        }
        if (isset($params['percent'])) {
            if (100 === $params['percent']) {
                $params['status'] = Dao_Td_Tudu_Tudu::STATUS_DONE;
                $params['cycle'] = null;
            } elseif ($params['percent'] > 0) {
                $params['status'] = Dao_Td_Tudu_Tudu::STATUS_DOING;
            }
        }
        // 处理日志记录内容
        $tuduLog['detail'] = $params;
        $postLog['detail'] = array('content' => $params['content']);
        unset($tuduLog['detail']['cycle'], $tuduLog['detail']['vote'], $tuduLog['detail']['email'], $tuduLog['detail']['content'], $tuduLog['detail']['attachment'], $tuduLog['detail']['file'], $tuduLog['detail']['poster'], $tuduLog['detail']['posterinfo']);
        $logPrivacy = !$isSend;
        ///////////////////////////////////
        // 保存图度数据
        $tuduId = $fromTudu->tuduId;
        $postId = $fromTudu->postId;
        // 内容的参数
        $postParams = array('content' => $params['content'], 'lastmodify' => implode(chr(9), array($uniqueId, $this->_timestamp, $this->_user['truename'])), 'createtime' => $this->_timestamp, 'attachment' => $params['attachment'], 'isforeign' => 1, 'file' => !empty($post['file']) ? (array) $post['file'] : array());
        // 从未发送时(草稿),相关的数据初始化(时效性的数据清除)
        if (!$isSent) {
            // 创建时间可相当于最先发送的时间
            $params['createtime'] = $this->_timestamp;
            // 未发送过,不存在最后编辑
            unset($postParams['lastmodify']);
        }
        // 不变更发起人
        unset($params['from']);
        if ($isForward) {
            // 转发,更新最后转发人信息,不更新图度元数据,新建回复内容
            unset($postParams['lastmodify']);
            $params['subject'] = $fromTudu->subject;
            $params['content'] = $fromTudu->content;
            $params['status'] = Dao_Td_Tudu_Tudu::STATUS_UNSTART;
            $params['accepttime'] = null;
            $params['lastforward'] = implode("\n", array($this->_user['truename'], time()));
            // 先发送新的回复
            $postParams = array_merge($postParams, array('orgid' => $this->_tudu->orgId, 'boardid' => $fromTudu->boardId, 'tuduid' => $tuduId, 'uniqueid' => $this->_user['uniqueid'], 'poster' => $this->_user['truename'], 'email' => $this->_user['email']));
            $postId = $this->_deliver->createPost($postParams);
            if (!$postId) {
                $this->json(false, $this->lang['save_failure']);
            }
            $this->getDao('Dao_Td_Tudu_Post')->sendPost($tuduId, $postId);
            $postLog['detail'] = $postParams;
            // 工作流程
            $steps = $this->_manager->getSteps($tuduId)->toArray('stepid');
            if (!empty($steps) && ($type = 'task')) {
                $currentStep = $this->_tudu->stepId && false === strpos($this->_tudu->stepId, '^') ? $steps[$this->_tudu->stepId] : array_pop($steps);
                // 当前为审批步骤
                $stepNum = count($steps);
                $newSteps = array();
                $currentTo = array_keys($this->_formatStepRecipients($params['to']));
                $fromTo = array_keys($this->_tudu->to);
                $fromCount = count($fromTo);
                $isChangeTo = count($currentTo) != $fromCount || count(array_uintersect($fromTo, $currentTo, "strcasecmp")) != $fromCount;
                if ($isChangeTo) {
                    $prevId = $currentStep['stepid'];
                    $orderNum = $currentStep['ordernum'];
                    $stepId = Dao_Td_Tudu_Step::getStepId();
                    $newSteps[$stepId] = array('orgid' => $this->_tudu->orgId, 'tuduid' => $tuduId, 'stepid' => $stepId, 'uniqueid' => $uniqueId, 'prevstepid' => $prevId, 'nextstepid' => '^end', 'type' => $this->_tudu->acceptMode ? Dao_Td_Tudu_Step::TYPE_CLAIM : Dao_Td_Tudu_Step::TYPE_EXECUTE, 'ordernum' => ++$orderNum, 'createtime' => time(), 'users' => $this->_formatStepRecipients($params['to']));
                    $params['stepid'] = $stepId;
                }
                // 移除后随未开始执行的步骤
                foreach ($steps as $step) {
                    if ($step['ordernum'] > $currentStep['ordernum']) {
                        $this->_manager->deleteStep($tuduId, $step['stepid']);
                        $stepNum--;
                    }
                }
                foreach ($newSteps as $step) {
                    if ($this->_manager->createStep($step)) {
                        var_dump($step['users']);
                        $recipients = $this->_prepareStepRecipients($this->_tudu->orgId, $uniqueId, $step['users']);
                        $processIndex = $step['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE ? 0 : null;
                        $this->_manager->addStepUsers($tuduId, $step['stepid'], $recipients, $processIndex);
                        $stepNum++;
                    }
                }
                $params['stepnum'] = $stepNum;
            }
            // 更新图度
            if (!$this->_deliver->updateTudu($tuduId, $params)) {
                $this->json(false, $this->lang['save_failure']);
            }
        }
        // 过滤日志变更内容参数
        if ($fromTudu) {
            $arrFromTudu = $fromTudu->toArray();
            foreach ($tuduLog['detail'] as $k => $val) {
                // 记录增加抄送人
                if ($k == 'cc') {
                    $arr = explode("\n", $val);
                    foreach ($arr as $idx => $v) {
                        $ccArr = explode(' ', $v);
                        if (array_key_exists($ccArr[0], $fromTudu->cc)) {
                            unset($arr[$idx]);
                        }
                    }
                    if (!$arr) {
                        unset($tuduLog['detail']['cc']);
                    } else {
                        $tuduLog['detail']['cc'] = implode("\n", $arr);
                    }
                    continue;
                }
                // 过滤未更新字段
                if (array_key_exists($k, $arrFromTudu) && $val == $arrFromTudu[$k]) {
                    unset($tuduLog['detail'][$k]);
                }
            }
            // 内容没有变更
            if (!$isForward) {
                if ($postLog['detail']['content'] == $fromTudu->content) {
                    unset($postLog['detail']);
                } else {
                    if (isset($postParams['lastmodify'])) {
                        $postLog['detail']['lastmodify'] = $postParams['lastmodify'];
                    }
                    $postLog['detail']['createtime'] = $postParams['createtime'];
                }
            }
            if (empty($tuduLog['detail']['cc'])) {
                unset($tuduLog['detail']['cc']);
            }
            unset($tuduLog['detail']['from']);
        }
        // 写入操作日志
        $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, $tuduLog['action'], $tuduLog['detail'], $logPrivacy);
        if (!empty($postLog['detail'])) {
            $this->_writeLog(Dao_Td_Log_Log::TYPE_POST, $postId, $postLog['action'], $postLog['detail'], $logPrivacy);
        }
        $sendParams = array();
        if ($type != 'task') {
            $sendParams['notice'] = $type == 'notice';
            $sendParams['discuss'] = $type == 'discuss';
        }
        // 删除需要移除的接受人
        if ($removeAccepters) {
            if (!$this->_deliver->removeTuduAccepter($tuduId, $removeAccepters)) {
                $this->json(false, $this->lang['send_failure']);
            }
        }
        // 发送图度
        if (!$this->_deliver->sendTudu($tuduId, $recipients, $sendParams)) {
            $this->json(false, $this->lang['send_failure']);
        }
        // 已发送的任务更新时,设置所有人为未读状态
        if ($isSent) {
            $this->_manager->markAllUnread($tuduId);
        }
        // 转发任务时,设置当前关联用户为转发状态
        if ($isForward) {
            $this->_manager->markForward($tuduId, $uniqueId);
            // 更新转发编辑后的任务进度
            $this->_deliver->updateProgress($tuduId, $uniqueId, null);
            // 更新转发后的任务接受状态
            $this->_deliver->updateLastAcceptTime($tuduId, $uniqueId, null);
            // 移除“我执行”标签
            $this->_manager->deleteLabel($tuduId, $uniqueId, '^a');
        }
        // 重新计算父级图度进度
        if ($fromTudu && $fromTudu->parentId) {
            $this->_deliver->calParentsProgress($fromTudu->parentId);
        }
        if ('task' == $type) {
            // 发起人为当前执行人
            if ($isAccpter) {
                // 自动接受任务
                $this->_deliver->acceptTudu($tuduId, $uniqueId, null);
                // 添加我执行
                $this->_deliver->addLabel($tuduId, $uniqueId, '^a');
                // 接受添加日志
                $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, Dao_Td_Log_Log::ACTION_TUDU_ACCEPT, array('status' => Dao_Td_Tudu_Tudu::STATUS_DOING, 'accepttime' => time()));
                // 非当前执行人
            } else {
                // 设为已读
                $this->_deliver->markRead($tuduId, $uniqueId);
            }
        }
        $config = $this->_bootstrap->getOption('httpsqs');
        // 插入消息队列
        $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']);
        // 收发规则过滤
        $data = implode(' ', array('tudu', 'filter', '', http_build_query(array('tsid' => $this->_tsId, 'tuduid' => $tuduId))));
        $httpsqs->put($data, 'tudu');
        // 发送外部邮件(如果有),处理联系人
        $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $this->_tsId, 'tuduid' => $tuduId, 'uniqueid' => $this->_user['uniqueid'], 'to' => ''))));
        $httpsqs->put($data, 'send');
        // IM提醒
        if (!empty($notifyTo)) {
            $content = str_replace('%', '%%', mb_substr(preg_replace('/<[^>]+>/', '', $params['content']), 0, 100, 'UTF-8'));
            $names = array('task' => '图度', 'discuss' => '讨论', 'notice' => '公告');
            $tpl = <<<HTML
<strong>您刚收到一个新的{$names[$type]}</strong><br />
<a href="http://{$this->_request->getServer('HTTP_HOST')}/frame#m=view&tid=%s&page=1" target="_blank">%s</a><br />
发起人:{$this->_user['truename']}<br />
更新日期:%s<br />
{$content}
HTML;
            $data = implode(' ', array('tudu', 'create', '', http_build_query(array('tuduid' => $this->_tudu->tuduId, 'from' => $this->_user['email'], 'to' => implode(',', $notifyTo), 'content' => sprintf($tpl, $this->_tudu->tuduId, $params['subject'], date('Y-m-d H:i:s', time()))))));
            $httpsqs->put($data);
        }
        $this->json(true, $this->lang['send_success'], $tuduId);
    }
コード例 #28
0
ファイル: FrameController.php プロジェクト: bjtenao/tudu-web
 /**
  * 天气预报
  */
 public function weatherAction()
 {
     $loc = $this->_request->getQuery('loc');
     $lang = $this->_request->getQuery('lang');
     if (!$lang) {
         $lang = empty($this->_user->option['language']) ? 'zh_CN' : $this->_user->option['language'];
     }
     /**
      * @see Tudu_Api
      */
     require_once 'Tudu/Api.php';
     $option = $this->bootstrap->getOption('api');
     $api = new Tudu_Api($option['tudu']);
     if (!$loc) {
         $loc = $api->getLocation(Oray_Function::getTrueIp());
     }
     $weather = $api->getWeather($lang, $loc);
     $this->json(true, null, $weather);
 }
コード例 #29
0
ファイル: Memcached.php プロジェクト: bjtenao/tudu-web
 /**
  * Get session id
  * 
  * @return string
  */
 private function _getSessionId()
 {
     if (null === $this->_sessionId) {
         $this->_sessionId = Oray_Function::randKeys(32);
         setcookie(Oray_Auth::COOKIE_SID, $this->_sessionId, null, '/', null);
     }
     return $this->_sessionId;
 }
コード例 #30
0
ファイル: Flow.php プロジェクト: lucn/tudu-web
 /**
  *
  * @param string $stepId
  * @param int    $sectionIndex
  * @param string $userName
  */
 public function addStepSectionUser($stepId, $sectionIndex, $user)
 {
     foreach ($this->_steps as $index => $item) {
         if ($item['stepid'] == $stepId) {
             if (isset($item['section'][$sectionIndex])) {
                 $users = array();
                 foreach ($item['section'][$sectionIndex] as $u) {
                     if ($u['username'] == $user['username']) {
                         return $this;
                     }
                 }
                 $orgId = $this->_attrs['orgid'];
                 $userName = isset($user['username']) ? $user['username'] : $user['email'];
                 $trueName = $user['truename'];
                 if (Oray_Function::isEmail($userName)) {
                     require_once 'Dao/Td/Contact/Contact.php';
                     $u = array('uniqueid' => Dao_Td_Contact_Contact::getContactId(), 'truename' => isset($item['truename']) ? $item['truename'] : substr($userName, 0, strpos($userName, '@')), 'email' => $userName, 'username' => $userName);
                 } else {
                     if (empty($item['uniqueid'])) {
                         $u = $this->_getAddressBook()->searchUser($orgId, $userName);
                     } else {
                         $u = array('uniqueid' => $item['uniqueid'], 'truename' => $item['truename'], 'email' => isset($item['email']) ? $item['email'] : $item['username'], 'username' => $item['username']);
                     }
                 }
                 if (!$u) {
                     require_once 'Model/Tudu/Exception.php';
                     throw new Model_Tudu_Exception('User in Tudu flow was not exists: ' . $item['username'], Model_Tudu_Exception::FLOW_USER_NOT_EXISTS);
                 }
                 $item = array('uniqueid' => $u['uniqueid'], 'truename' => $u['truename'], 'username' => $u['email'], 'deptid' => !empty($u['deptid']) ? $u['deptid'] : '^root');
                 if (isset($user['status'])) {
                     $item['status'] = $user['status'];
                 }
                 $this->_steps[$index]['section'][$sectionIndex][] = $item;
             }
         }
     }
     return $this;
 }