/**
     * 转发图度
     *
     */
    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);
    }
Exemple #2
0
 /**
  * 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;
 }
 /**
  * 接收参数,通过接口方 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/');
 }
 /**
  * /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);
 }
Exemple #5
0
 /**
  * 生成周期图度
  *
  * @param $params
  */
 public function cycle($params)
 {
     if (empty($params['tuduid']) || empty($params['cycleid']) || empty($params['tsid'])) {
         return;
     }
     $tuduId = $params['tuduid'];
     $cycleId = $params['cycleid'];
     $tsId = $params['tsid'];
     $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD);
     $daoCycle = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Cycle', Tudu_Dao_Manager::DB_TS);
     $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     $tudu = $manager->getTuduById($tuduId, $this->_unId);
     $fromTuduId = $tudu->tuduId;
     $acceptMode = $tudu->acceptMode;
     $isAuth = $tudu->isAuth;
     if (null === $tudu) {
         $this->getLogger()->warn("Tudu id: {$tuduId} is not exists");
         return;
     }
     $cycle = $daoCycle->getCycle(array('cycleid' => $cycleId));
     if (null === $cycle) {
         $this->getLogger()->warn("Tudu Cycle id: {$cycleId} is not exists");
         return;
     }
     // 已经失效的周期设置
     if ($cycle->isValid == 0) {
         return;
     }
     if (Dao_Td_Tudu_Cycle::END_TYPE_COUNT == $cycle->endType && $cycle->count >= $cycle->endCount) {
         $daoCycle->deleteCycle($cycle->cycleId);
         return;
     }
     if (Dao_Td_Tudu_Cycle::END_TYPE_DATE == $cycle->endType && time() >= $cycle->endDate) {
         $daoCycle->deleteCycle($cycle->cycleId);
         return;
     }
     $time = $daoCycle->getCycleTime($cycle, $tudu->startTime, $tudu->endTime);
     $recipients = array();
     $to = array();
     $fromUnId = null;
     $u = $daoUser->getUserByAddress($tudu->sender);
     if ($u) {
         $recipients[$u->uniqueId] = array('uniqueid' => $u->uniqueId, 'role' => 'from');
         $fromUnId = $u->uniqueId;
     }
     if (!$acceptMode) {
         $accepters = $manager->getTuduAccepters($tudu->tuduId);
         foreach ($accepters as $a) {
             $recipients[$a['uniqueid']] = array('accepterinfo' => $a['accepterinfo'], 'uniqueid' => $a['uniqueid'], 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'isforeign' => (int) $a['isforeign'], 'percent' => 0, 'authcode' => (int) $a['isforeign'] && $tudu->isAuth ? Oray_Function::randKeys(4) : null);
             if ($tudu->isAuth) {
                 $recipients[$a['uniqueid']]['authcode'] = $a['authcode'];
             }
             $to[] = $a['accepterinfo'];
         }
     }
     // 公共周期任务图度数据
     $params = $this->getCycleTuduParams($tudu, $cycle, $to, $fromUnId, $time);
     // 抄送
     if (!empty($tudu->cc)) {
         $cc = array();
         $sendCc = array();
         foreach ($tudu->cc as $userName => $item) {
             $cc[] = $userName . ' ' . $item[0];
         }
         $params['cc'] = implode("\n", $cc);
         $sendCc = $this->formatRecipients($params['cc']);
         $addressBook = Tudu_AddressBook::getInstance();
         foreach ($sendCc as $key => $item) {
             if (isset($item['groupid'])) {
                 if (0 === strpos($item['groupid'], 'XG')) {
                     $users = $addressBook->getGroupContacts($tudu->orgId, $fromUnId, $item['groupid']);
                 } else {
                     $users = $addressBook->getGroupUsers($tudu->orgId, $item['groupid']);
                 }
                 $recipients = array_merge($users, $recipients);
             } else {
                 $user = $addressBook->searchUser($tudu->orgId, $item['email']);
                 if (null === $user) {
                     $user = $addressBook->searchContact($fromUnId, $item['email'], $item['truename']);
                     if (null === $user) {
                         $user = $addressBook->prepareContact($item['email'], $item['truename']);
                     }
                 }
                 if (!isset($recipients[$user['uniqueid']])) {
                     $recipients[$user['uniqueid']] = $user;
                 }
             }
         }
     }
     // 密送
     if (!empty($tudu->bcc)) {
         $bcc = array();
         $sendBcc = array();
         foreach ($tudu->bcc as $userName => $item) {
             $bcc[] = $userName . ' ' . $item[0];
         }
         $params['bcc'] = implode("\n", $bcc);
         $sendBcc = $this->formatRecipients($params['bcc']);
         $addressBook = Tudu_AddressBook::getInstance();
         foreach ($sendBcc as $key => $item) {
             if (isset($item['groupid'])) {
                 if (0 === strpos($item['groupid'], 'XG')) {
                     $users = $addressBook->getGroupContacts($tudu->orgId, $fromUnId, $item['groupid']);
                 } else {
                     $users = $addressBook->getGroupUsers($tudu->orgId, $item['groupid']);
                 }
                 $recipients = array_merge($users, $recipients);
             } else {
                 $user = $addressBook->searchUser($tudu->orgId, $item['email']);
                 if (null === $user) {
                     $user = $addressBook->searchContact($fromUnId, $item['email'], $item['truename']);
                     if (null === $user) {
                         $user = $addressBook->prepareContact($item['email'], $item['truename']);
                     }
                 }
                 if (!isset($recipients[$user['uniqueid']])) {
                     $recipients[$user['uniqueid']] = $user;
                 }
             }
         }
     }
     // 会议数据
     if ($tudu->type == 'meeting') {
         $daoMeeting = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Meeting', Tudu_Dao_Manager::DB_TS);
         $meeting = $daoMeeting->getMeeting(array('tuduid' => $tudu->tuduId));
         if ($meeting) {
             $params['meeting'] = array('notifytype' => $meeting->notifyType, 'location' => $meeting->location, 'isallday' => $meeting->isAllday);
             $params['meeting']['notifytime'] = Dao_Td_Tudu_Meeting::calNotifyTime($params['starttime'], $meeting->notifyType);
         }
     }
     // 保留周期任务的附件
     if ($cycle->isKeepAttach) {
         $daoAttach = Tudu_Dao_Manager::getDao('Dao_Td_Attachment_File', Tudu_Dao_Manager::DB_TS);
         $attaches = $daoAttach->getFiles(array('tuduid' => $tudu->tuduId, 'postid' => $tudu->postId))->toArray();
         $attachNum = 0;
         foreach ($attaches as $attach) {
             if ($attach['isattach']) {
                 $params['attachment'][] = $attach['fileid'];
             } else {
                 $params['file'][] = $attach['fielid'];
             }
         }
     }
     $stepId = $params['stepid'];
     $tudu = new Tudu_Tudu_Storage_Tudu($params);
     $storage = Tudu_Tudu_Storage::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     $deliver = Tudu_Tudu_Deliver::getInstance();
     $tuduId = $storage->createTudu($tudu);
     if (!$tuduId) {
         $this->getLogger()->warn("Create Cycle Tudu failed id:{$tuduId}");
         return;
     }
     if ($params['type'] == 'task' && $tuduId) {
         $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS);
         $flow = $daoFlow->getFlow(array('tuduid' => $fromTuduId));
         $steps = $flow->steps;
         $step = reset($steps);
         $modelFlow = new Model_Tudu_Extension_Flow(array('orgid' => $tudu->orgId, 'tuduid' => $tuduId));
         /*$step = $daoStep->getStep(array('tuduid' => $fromTuduId, 'prevstepid' => '^head'));
           $orderNum   = 1;*/
         $prevStepId = '^head';
         $addressBook = Tudu_AddressBook::getInstance();
         // 认领
         if ($step && $step['type'] == Dao_Td_Tudu_Step::TYPE_CLAIM) {
             $modelFlow->addStep(array('stepid' => $step['stepid'], 'prev' => $step['prev'], 'next' => '^end', 'type' => $step['type']));
             $acceptMode = true;
             $to = array();
             foreach ($step['section'] as $idx => $sec) {
                 $section = array();
                 foreach ($sec as $user) {
                     $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']);
                     if ($idx == 0) {
                         $to[] = $user['username'] . ' ' . $user['truename'];
                         $recipient = array('uniqueid' => $user['uniqueid'], 'userinfo' => $user['username'] . ' ' . $user['truename'], 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'percent' => 0);
                         $u = $addressBook->searchUser($fromUnId, $user['username']);
                         if (!$u) {
                             $recipient['isforeign'] = 1;
                             if ($isAuth) {
                                 $recipient['auth'] = Oray_Function::randKeys(4);
                             }
                         }
                         $recipients[$recipient['uniqueid']] = $recipient;
                     }
                 }
                 $modelFlow->addStepSection($step['stepid'], $sec);
             }
             $modelFlow->stepNum = 1;
             $modelFlow->flowTo($step['stepid']);
             $daoFlow->createFlow($modelFlow->toArray());
             // 更新to字段
             $manager->updateTudu($tuduId, array('to' => implode("\n", $to), 'acceptmode' => 1, 'accepttime' => null));
         } else {
             // 审批
             $nextId = $step['next'];
             $modelFlow->addStep(array('stepid' => $step['stepid'], 'prev' => $step['prev'], 'next' => $step['next'], 'type' => $step['type']));
             foreach ($step['section'] as $idx => $sec) {
                 $section = array();
                 foreach ($sec as $user) {
                     $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']);
                     if ($idx == 0) {
                         $to[] = $user['username'] . ' ' . $user['truename'];
                         $recipient = array('uniqueid' => $user['uniqueid'], 'userinfo' => $user['username'] . ' ' . $user['truename'], 'role' => isset($recipients[$user['uniqueid']]) ? $recipients[$user['uniqueid']]['role'] : null, 'isreview' => true, 'tudustatus' => Dao_Td_Tudu_Tudu::STATUS_UNSTART);
                         $recipients[$recipient['uniqueid']] = $recipient;
                     }
                 }
                 $modelFlow->addStepSection($step['stepid'], $sec);
             }
             if (isset($flow->steps[$nextId])) {
                 $next = $flow->steps[$nextId];
                 $modelFlow->addStep(array('stepid' => $next['stepid'], 'prev' => $next['prev'], 'next' => '^end', 'type' => $next['type']));
                 foreach ($next['section'] as $idx => $sec) {
                     $section = array();
                     foreach ($sec as $user) {
                         $section[] = array('uniqueid' => $user['uniqueid'], 'username' => $user['username'], 'truename' => $user['truename']);
                     }
                     $modelFlow->addStepSection($next['stepid'], $sec);
                 }
             }
             $modelFlow->stepNum = count($modelFlow->steps);
             $modelFlow->flowTo($step['stepid']);
             $daoFlow->createFlow($modelFlow->toArray());
         }
     }
     $sendParams = array();
     if ($tudu->type == 'meeting') {
         $sendParams['meeting'] = true;
     }
     if (empty($reviewer)) {
         $ret = $deliver->sendTudu($tudu, $recipients, $sendParams);
         if (!$ret) {
             $this->getLogger()->warn("Send Tudu failed id:{$tuduId}");
             return;
         }
         if (!$acceptMode) {
             foreach ($recipients as $unId => $recipient) {
                 if (isset($recipient['role']) && $recipient['role'] == Dao_Td_Tudu_Tudu::ROLE_ACCEPTER) {
                     $manager->acceptTudu($tuduId, $unId, null);
                 }
             }
         }
     } else {
         $rev = array_shift($reviewer);
         $ret = $deliver->sendTudu($tudu, array($rev['uniqueid'] => array('tuduid' => $tuduId, 'uniqueid' => $rev['uniqueid']), $fromUnId => array('tuduid' => $tuduId, 'uniqueid' => $fromUnId)), null);
         if (!$ret) {
             $this->getLogger()->warn("Send Tudu failed id:{$tuduId}");
             return;
         }
         $manager->addLabel($tuduId, $rev['uniqueid'], '^e');
     }
     // 发起人的
     if (null !== $fromUnId) {
         $manager->addLabel($tuduId, $fromUnId, '^f');
         $manager->addLabel($tuduId, $fromUnId, '^i');
     }
     $daoCycle->increment($cycle->cycleId);
     // 收发规则过滤
     $data = implode(' ', array('tudu', 'filter', '', http_build_query(array('tsid' => $tsId, 'tuduid' => $tuduId))));
     $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['tudu']);
     // 外发请求
     $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $tsId, 'tuduid' => $tuduId, 'uniqueid' => $fromUnId, 'to' => ''))));
     $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['send']);
     $this->getLogger()->debug("Tudu id:{$tuduId} done");
 }
Exemple #6
0
 /**
  * 发送图度
  */
 protected function _sendTudu(Model_Tudu_Tudu &$tudu, array $recipients)
 {
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $isAccepted = false;
     $to = $tudu->to;
     $timestemp = time();
     if ($tudu->operation == 'send' && ($tudu->type == 'task' || $tudu->type == 'notice')) {
         $reviewers = $daoTudu->getUsers($tudu->tuduId, array('labelid' => '^e'));
         foreach ($reviewers as $reviewer) {
             $daoTudu->deleteLabel($tudu->tuduId, $reviewer['uniqueid'], '^e');
         }
     }
     foreach ($recipients as $unId => $recipient) {
         if (!is_array($recipient)) {
             continue;
         }
         // 跳过已发送的外发执行人
         if (!empty($recipient['isforeign']) && !empty($to) && array_key_exists($recipient['email'], $to)) {
             continue;
         }
         // 需要验证的外部访问人员
         if (!empty($recipient['isforeign'])) {
             $recipient['authcode'] = $tudu->isAuth ? Oray_Function::randKeys(4) : null;
         }
         if (!isset($recipient['accepterinfo']) && isset($recipient['email']) && isset($recipient['truename'])) {
             $recipient['accepterinfo'] = $recipient['email'] . ' ' . $recipient['truename'];
         }
         /*if ($tudu->flowId && isset($recipient['role']) && $recipient['role'] == 'to') {
               $recipients[$unId]['tudustatus'] = 1;
               $recipients[$unId]['percent']    = 0;
           }*/
         $params = $recipient;
         if (array_key_exists('percent', $params)) {
             $params['percent'] = isset($params['percent']) ? (int) $params['percent'] : 0;
         }
         $labels = $daoTudu->addUser($tudu->tuduId, $unId, $params);
         if (false !== $labels) {
             if (is_string($labels) && !empty($recipient)) {
                 if ($tudu->operation == 'forward') {
                     unset($params['percent'], $params['tudustatus']);
                 }
                 $daoTudu->updateTuduUser($tudu->tuduId, $unId, $params);
             }
             if (!empty($recipient['role']) && $recipient['role'] === 'to') {
                 $to[] = $unId;
             }
             if (is_string($labels)) {
                 $labels = explode(',', $labels);
             } else {
                 $labels = array();
             }
             // 所有图度标签
             if (!in_array('^all', $labels)) {
                 $daoTudu->addLabel($tudu->tuduId, $unId, '^all');
             }
             // 图度箱
             if (!in_array('^i', $labels) && !in_array('^g', $labels)) {
                 if (!isset($recipient['role']) || $recipient['role'] != 'from' || !$tudu->parentId) {
                     $daoTudu->addLabel($tudu->tuduId, $unId, '^i');
                 }
             }
             // 类型标签
             if ($tudu->type == 'notice' && !in_array('^n', $labels)) {
                 $daoTudu->addLabel($tudu->tuduId, $unId, '^n');
             }
             if ($tudu->type == 'discuss' && !in_array('^d', $labels)) {
                 $daoTudu->addLabel($tudu->tuduId, $unId, '^d');
             }
             if ($tudu->type == 'meeting' && !in_array('^m', $labels)) {
                 $daoTudu->addLabel($tudu->tuduId, $unId, '^m');
             }
             // 我执行
             if (!empty($recipient['role']) && $recipient['role'] == 'to' && $tudu->type == 'task') {
                 if (!in_array('^a', $labels)) {
                     $daoTudu->addLabel($tudu->tuduId, $unId, '^a');
                 }
                 if (($tudu->flowId || $tudu->uniqueId == $unId) && !$tudu->acceptMode) {
                     $isAccepted = true;
                     // 更新最后接受时间
                     $daoTudu->updateTuduUser($tudu->tuduId, $unId, array('tudustatus' => 1, 'accepttime' => $timestemp));
                 }
             }
             // 审批
             if (!empty($recipient['isreview']) && !in_array('^e', $labels)) {
                 if ($tudu->operation != 'review' || $recipient['uniqueid'] != $tudu->uniqueId) {
                     $daoTudu->addLabel($tudu->tuduId, $unId, '^e');
                 }
             }
             if (isset($this->_typeLabels[$tudu->type])) {
                 $labelId = $this->_typeLabels[$tudu->type];
                 if (!in_array($labelId, $labels)) {
                     $daoTudu->addLabel($tudu->tuduId, $unId, $labelId);
                 }
             }
         }
     }
     if ($tudu->type == 'task') {
         if ($isAccepted) {
             $daoTudu->updateLastAcceptTime($tudu->tuduId);
         } else {
             foreach ($recipients as $unId => $u) {
                 if (!empty($u['role'])) {
                     $daoTudu->addLabel($tudu->tuduId, $unId, '^td');
                 }
             }
         }
     }
     if (!$daoTudu->sendTudu($tudu->tuduId)) {
         require_once 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('Tudu send failed', Model_Tudu_Exception::SAVE_FAILED);
     }
 }
Exemple #7
0
 /**
  * 获取验证码
  *
  * @param int $length
  * @return string
  */
 public static function getCode($length = self::DEFAULT_LENGTH)
 {
     return Oray_Function::randKeys($length, '0123456789');
 }