/**
     * 转发图度
     *
     */
    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
 /**
  * 外发图度任务
  *
  * @param array $params
  */
 public function sendTudu($params)
 {
     if (empty($params['tuduid']) || empty($params['tsid']) || empty($params['uniqueid'])) {
         return;
     }
     $tuduId = $params['tuduid'];
     $uniqueId = $params['uniqueid'];
     $tsId = $params['tsid'];
     $to = !empty($params['to']) ? explode(',', $params['to']) : null;
     /* @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;
     }
     // 当前发送人信息
     $sender = $manager->getUser($tuduId, $uniqueId);
     // 获取接收人
     $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'], 2);
         $email = $info[0];
         $name = !empty($info[1]) ? $info[1] : null;
         $unId = $receiver['uniqueid'];
         if ($name == null && $email) {
             $arr = explode('@', $email);
             $name = array_shift($arr);
         }
         if (!$email && !$name) {
             continue;
         }
         if (!empty($to) && !in_array($email, $to)) {
             continue;
         }
         // 发送人联系人处理
         if (!$sender['isforeign']) {
             $condition = array('uniqueid' => $uniqueId, 'contactid' => $unId);
             $contact = $daoContact->getContact($condition);
             // 加入最近联系人
             if (!$email || (array_key_exists($email, $tudu->to) || array_key_exists($email, $tudu->cc) || $tudu->bcc && array_key_exists($email, $tudu->bcc))) {
                 if (null == $contact) {
                     $contactId = $receiver['isforeign'] ? $receiver['uniqueid'] : Dao_Td_Contact_Contact::getContactId();
                     $params = array('contactid' => $unId, 'uniqueid' => $uniqueId, 'fromuser' => $receiver['isforeign'] ? 0 : 1, 'truename' => $name, 'pinyin' => Tudu_Pinyin::parse($name), 'email' => $email, 'lastcontacttime' => time());
                     $contactId = $daoContact->createContact($params);
                     if (!$contactId) {
                         $data = serialize($params);
                         $this->getLogger()->warn("Create Contact failed:{$data}");
                     }
                 } else {
                     $ret = $daoContact->updateContact($contact->contactId, $uniqueId, array('lastcontacttime' => time()));
                     if (!$ret) {
                         $data = serialize(array('contactid' => $contact->contactId, 'uniqueid' => $uniqueId, 'lastcontacttime' => time()));
                         $this->getLogger()->warn("Update Contact failed:{$data}");
                     }
                     $contactId = $contact->contactId;
                 }
             }
         }
         if ($receiver['isforeign']) {
             $auth = $receiver['authcode'];
             if (Oray_Function::isEmail($info[0])) {
                 $array = array('address' => $info[0], 'name' => empty($info[1]) ? $info[1] : $info[0], 'authinfo' => '', 'url' => 'http://' . $tudu->orgId . '.tudu.com/foreign/tudu?ts=' . $tsId . '&tid=' . $tudu->tuduId . '&fid=' . $unId);
                 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_tudu_notify.tpl';
     if (!file_exists($tpl) || !is_readable($tpl)) {
         $this->getLogger()->warn("Tpl file:\"mail_tudu_notify.tpl\" is not exists");
         return;
     }
     // 公用信息
     $common = array('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]);
     $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 Tudu id:{$tuduId} done");
 }
Exemple #3
0
 /**
  * 创建联系人
  *
  * @param $params
  */
 public function createContact($uniqueId, $email, $name)
 {
     /* @var $daoContact Dao_Td_Contact_Contact */
     $daoContact = $this->getDao('Dao_Td_Contact_Contact');
     $contactId = $daoContact->createContact(array('contactid' => Dao_Td_Contact_Contact::getContactId(), 'uniqueid' => $uniqueId, 'truename' => $name, 'email' => $email));
     return $contactId;
 }
Exemple #4
0
 /**
  *
  * @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;
 }
 /**
  * 联系人 - 从公共通讯录复制过去个人通讯录和添加到组的操作
  *
  * @param $email
  * @param $groupId
  */
 private function _addSystemMember($email, $groupId)
 {
     $daoContact = $this->getDao('Dao_Td_Contact_Contact');
     $daoGroup = $this->getDao('Dao_Td_Contact_Group');
     $daoCast = $this->getMdDao('Dao_Md_User_Cast');
     $daoUser = $this->getMdDao('Dao_Md_User_User');
     $userId = array_shift(explode('@', $email));
     $domain = array_pop(explode('@', $email));
     if (!$daoCast->existsUser($this->_user->orgId, $this->_user->userId, $userId)) {
         return;
     }
     $profile = $daoUser->getUser(array('domainname' => $domain, 'userid' => $userId));
     $userinfo = $daoUser->getUserInfo(array('orgid' => $this->_user->orgId, 'userid' => $userId));
     $ctid = Dao_Td_Contact_Contact::getContactId();
     $params = array('contactid' => $ctid, 'uniqueid' => $this->_user->uniqueId, 'truename' => $userinfo->trueName, 'pinyin' => Tudu_Pinyin::parse($userinfo->trueName, true), 'email' => $email, 'mobile' => $userinfo->mobile, 'fromuser' => 1);
     $daoContact->createContact($params);
     $daoGroup->addMember($groupId, $this->_user->uniqueId, $ctid);
 }
Exemple #6
0
 /**
  *
  * @param string $uniqueId
  * @param string $email
  * @param string $trueName
  * @return array
  */
 public function prepareContact($email, $trueName)
 {
     return array('uniqueid' => Dao_Td_Contact_Contact::getContactId(), 'email' => $email, 'truename' => $trueName, 'isforeign' => true);
 }