예제 #1
0
 /**
  * 创建邮箱绑定
  */
 public function createAction()
 {
     $post = $this->_request->getPost();
     $port = !empty($post['port']) ? $post['port'] : null;
     if (empty($post['address']) || !Oray_Function::isEmail($post['address'])) {
         return $this->json(false, $this->lang['invalid_email_address']);
     }
     if (!trim($post['password'])) {
         return $this->json(false, $this->lang['missing_email_password']);
     }
     if (empty($post['host'])) {
         return $this->json(false, $this->lang['missing_email_host'], array('advance' => true));
     }
     if (!Oray_Function::isDomainName($post['host']) && !Oray_Function::isIp($post['host'])) {
         return $this->json(false, sprintf($this->lang['invalid_imap_host'], strtoupper($post['protocol'])), array('advance' => true));
     }
     if ($port != null) {
         if ($port <= 0 || $port > 65535) {
             return $this->json(false, sprintf($this->lang['invalid_imap_port'], strtoupper($post['protocol'])));
         }
     }
     $address = $post['address'];
     if (null !== $this->_daoEmail->getEmailByAddress($this->_user->orgId, $this->_user->userId, $address)) {
         $this->json(false, sprintf($this->lang['already_binded'], $address));
     }
     $isSsl = isset($post['isssl']) && $post['isssl'] == 1 ? 1 : 0;
     $type = isset($post['type']) ? (int) $post['type'] : 0;
     /**
      * 验证邮箱密码
      */
     if (!$this->_validMailbox($address, $post['password'], $post['host'], $port, (bool) $isSsl, $post['protocol'])) {
         return $this->json(false);
     }
     $params = array('orgid' => $this->_user->orgId, 'userid' => $this->_user->userId, 'address' => $post['address'], 'password' => $post['password'], 'protocol' => $post['protocol'], 'host' => $post['host'], 'port' => (int) $post['port'] > 0 ? (int) $post['port'] : null, 'isssl' => $isSsl, 'type' => $type, 'ordernum' => $this->_daoEmail->getMaxOrderNum($this->_user->orgId, $this->_user->userId) + 1);
     $ret = $this->_daoEmail->createEmail($params);
     if (!$ret) {
         return $this->json(false, $this->lang['create_mailbox_failure']);
     }
     return $this->json(true, $this->lang['create_mailbox_success']);
 }
예제 #2
0
    /**
     * 转发图度
     *
     */
    public function sendAction()
    {
        $post = $this->_request->getPost();
        $post = array_merge(array('to' => '', 'cc' => ''), $post);
        $action = $post['action'];
        $type = $post['type'];
        // 判断操作,默认为发送
        if (!in_array($action, array('send', 'save'))) {
            $action = 'send';
        }
        // 判断类型,默认为任务
        if (!in_array($type, array('task', 'discuss', 'notice'))) {
            $type = 'task';
        }
        // 当前用户唯一ID
        $uniqueId = $this->_user['uniqueid'];
        // 是否现在发送
        $isSend = true;
        // 是否已经发送过,可判读来源的图度是否发送过,已发送过的不允许保存为草稿
        $isSent = false;
        // 是否转发
        $isForward = !empty($post['forward']);
        // 是否来源于草稿
        $isFromDraft = false;
        // 是否发起人
        $isSender = false;
        // 是否执行人
        $isAccpter = false;
        // 是否通知所有关联人员
        $notifyAll = !empty($post['notifyall']);
        // 需要发送提醒的人
        $notifyTo = array();
        // 抄送人加入自己
        $post['cc'] .= "\n" . $this->_user['email'] . ' ' . $this->_user['truename'];
        // 需要发送的地址,可能为空
        $address = array('to' => $this->_formatRecipients($post['to']), 'cc' => $this->_formatRecipients($post['cc'], true));
        // 需要发送的执行人,方便后面调用
        $accepters = $address['to'];
        // 需要投递的联系人数据,保存用户唯一ID
        // uniqueid => array(isaccepter => {boolean}, accepterinfo => {string})
        $recipients = array();
        // 需要移除接受人的用户唯一ID
        $removeAccepters = array();
        if (null === $this->_tudu) {
            return $this->json(false, $this->lang['tudu_not_exists']);
        }
        $fromTudu = $this->_tudu;
        // 日志记录内容
        $tuduLog = array('action' => 'create', 'detail' => array());
        $postLog = array('action' => 'create', 'detail' => array());
        ////////////////////////////
        // 操作及参数判断
        // 发送操作
        if ('send' == $action) {
            $isAccpter = array_key_exists($this->_user['email'], $accepters);
            // 如果是转发
            if ($isForward) {
                // 转发时,必须有图度存在
                if (!$fromTudu) {
                    $this->json(false, $this->lang['tudu_not_exists']);
                }
                // 图度组不能转发
                if ($fromTudu->isTuduGroup) {
                    $this->json(false, $this->lang['deny_forward_tudugroup']);
                }
                // 非图度执行人不能转发图度
                if (!in_array($this->_user['email'], $fromTudu->accepter)) {
                    $this->json(false, $this->lang['forbid_non_accepter_forward']);
                }
                // 执行人不能转发给自己
                if ($isAccpter) {
                    $this->json(false, $this->lang['forbid_forward_myself']);
                }
                foreach ($address['to'] as $a => $n) {
                    if (in_array($a, $fromTudu->accepter, true)) {
                        $this->json(false, sprintf($this->lang['user_is_accepter'], $n));
                    }
                }
                $tuduLog['action'] = Dao_Td_Log_Log::ACTION_TUDU_FORWARD;
            }
            // 保存图度
        } else {
            if ('save' == $action) {
                $this->json(false);
            }
        }
        // 发送时参数判断,1.检查必须的参数,2.检查联系人是否存在。保存草稿时不需要这些判断
        if ($isSend) {
            if ('task' == $type) {
                if (empty($address['to']) && (!$fromTudu || !$fromTudu->isTuduGroup)) {
                    $this->json(false, $this->lang['missing_to']);
                }
            } else {
                if (empty($address['cc'])) {
                    $this->json(false, $this->lang['missing_cc']);
                }
            }
            if (!$isForward && empty($post['subject'])) {
                $this->json(false, $this->lang['missing_subject']);
            }
            if (empty($post['content'])) {
                $this->json(false, $this->lang['missing_content']);
            }
            /* @var $daouser Dao_Td_Contact_Contact */
            $daoContact = $this->getDao('Dao_Td_Contact_Contact');
            /* @var $daoUser Dao_Md_User_User */
            $daoUser = Oray_Dao::factory('Dao_Md_User_User');
            $forwardInfo = array();
            //被转发用户继承转发用户进度
            if ($isForward) {
                $forwardInfo = array('forwardinfo' => $this->_user['truename'] . "\n" . time(), 'percent' => isset($post['percent']) ? (int) $post['percent'] : $fromTudu->selfPercent);
            }
            $users = $this->_deliver->getTuduUsers($this->_tudu->tuduId);
            $isAuth = $fromTudu->isAuth;
            // 外部联系人转发,仅从当前图度相关用户中检查
            foreach ($address['to'] as $a => $name) {
                foreach ($users as $u) {
                    if ($u['email'] == $a && $u['truename'] == $name) {
                        $unId = $u['uniqueid'];
                        $recipients[$unId] = array_merge(array('uniqueid' => $unId, 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'accepterinfo' => $a . ' ' . $name, 'percent' => 0, 'tudustatus' => 0, 'isforeign' => $u['isforeign'], 'authcode' => $u['isforeign'] && $isAuth ? Oray_Function::randKeys(4) : null), $forwardInfo);
                        continue 2;
                    }
                }
                $unId = Dao_Td_Contact_Contact::getContactId();
                $info = Oray_Function::isEmail($a) ? $a . ' ' . $name : $name;
                $recipients[$unId] = array_merge(array('uniqueid' => $unId, 'role' => Dao_Td_Tudu_Tudu::ROLE_ACCEPTER, 'accepterinfo' => $info, 'percent' => 0, 'tudustatus' => 0, 'isforeign' => 1, 'authcode' => $isAuth ? Oray_Function::randKeys(4) : null), $forwardInfo);
            }
            // 去除原有执行人
            if ($fromTudu) {
                $fromAccepter = $this->_deliver->getTuduAccepters($fromTudu->tuduId);
                $removeInfos = array();
                $to = array();
                foreach ($fromAccepter as $acpter) {
                    if ($isForward) {
                        if ($acpter['uniqueid'] == $uniqueId) {
                            $removeAccepters[] = $this->_user['uniqueid'];
                            $removeInfos[$this->_user['uniqueid']] = $acpter['accepterinfo'];
                            continue;
                        }
                    } elseif (!isset($recipients[$acpter['uniqueid']]) || !is_array($recipients[$acpter['uniqueid']])) {
                        $removeAccepters[] = $acpter['uniqueid'];
                        $removeInfos[$acpter['uniqueid']] = $acpter['accepterinfo'];
                        continue;
                    }
                    if (isset($recipients[$acpter['uniqueid']]['tudustatus'])) {
                        $recipients[$acpter['uniqueid']]['percent'] = (int) $acpter['percent'];
                        if (!$isForward && $acpter['tudustatus'] != 3) {
                            $recipients[$acpter['uniqueid']]['tudustatus'] = $acpter['tudustatus'];
                        }
                    }
                    $to[] = $acpter['accepterinfo'];
                    $acceptInfo = explode(' ', $acpter['accepterinfo']);
                    $notifyTo[] = $acceptInfo[0];
                }
                $post['to'] = array_unique(array_merge($to, explode("\n", $post['to'])));
                $post['to'] = implode("\n", $post['to']);
                if ($fromTudu->isTuduGroup && !empty($removeAccepters)) {
                    /** @var $daoGroup Dao_Td_Tudu_Group */
                    $daoGroup = $this->getDao('Dao_Td_Tudu_Group');
                    foreach ($removeAccepters as $unId) {
                        if ($daoGroup->getChildrenCount($fromTudu->tuduId, $unId) > 0) {
                            $this->json(false, sprintf($this->lang['user_has_divide'], $removeInfos[$unId]));
                        }
                    }
                }
            }
            // 处理抄送人
            $arrCC = array();
            // 外部联系人转发,仅从当前图度相关用户中检查
            foreach ($address['cc'] as $a => $name) {
                foreach ($users as $u) {
                    if ($u['email'] == $a && $u['truename'] == $name) {
                        $unId = $u['uniqueid'];
                        $recipients[$unId] = array('uniqueid' => $unId, 'role' => Dao_Td_Tudu_Tudu::ROLE_CC, 'accepterinfo' => $a . ' ' . $name, 'isforeign' => $u['isforeign'], 'authcode' => $u['isforeign'] && $isAuth ? Oray_Function::randKeys(4) : null);
                        continue 2;
                    }
                }
                $unId = Dao_Td_Contact_Contact::getContactId();
                $recipients[$unId] = array('uniqueid' => $unId, 'role' => Dao_Td_Tudu_Tudu::ROLE_CC, 'accepterinfo' => $a . ' ' . $name, 'isforeign' => 1, 'authcode' => $isAuth ? Oray_Function::randKeys(4) : null);
            }
            // 编辑/转发,合并原有转发人信息
            if (null !== $fromTudu) {
                $fromCC = array();
                foreach ($fromTudu->cc as $addr => $cc) {
                    if (!array_key_exists($addr, $address['cc'])) {
                        $fromCC[] = $addr . ' ' . $cc[0];
                    }
                }
                $post['cc'] = implode("\n", $fromCC) . "\n" . $post['cc'];
            }
            // 通知所有人
            if (in_array($type, array('notice', 'discuss')) || $notifyAll) {
                $notifyTo = array_merge($notifyTo, $arrCC);
            }
            if ($fromTudu) {
                $users = $this->_deliver->getTuduUsers($fromTudu->tuduId);
                foreach ($users as $item) {
                    $labels = explode(',', $item['labels']);
                    if (in_array('^t', $labels) && !in_array('^n', $labels)) {
                        $user = $daoUser->getUser(array('uniqueid' => $item['uniqueid']));
                        $notifyTo[] = $user->address;
                    }
                }
            }
            // 通知跳过当前操作用户(如果有)
            $notifyTo = array_unique(array_diff($notifyTo, array($this->_user['email'])));
            if ($type == 'notice' && !isset($post['remind'])) {
                $notifyTo = null;
            }
            //$recipients = array_unique($recipients);
            //var_dump($address);
            //var_dump($recipients);
        }
        ////////////////////////////////
        // 参数构造逻辑
        // 基本参数
        $params = array('orgid' => $this->_tudu->orgId, 'boardid' => $fromTudu ? $fromTudu->boardId : $post['bid'], 'email' => $this->_user['email'], 'type' => $type, 'subject' => isset($post['subject']) ? $post['subject'] : $fromTudu->subject, 'to' => $post['to'], 'cc' => $post['cc'], 'priority' => empty($post['priority']) ? 0 : (int) $post['priority'], 'privacy' => empty($post['privacy']) ? 0 : (int) $post['privacy'], 'status' => Dao_Td_Tudu_Tudu::STATUS_UNSTART, 'lastposttime' => $this->_timestamp, 'content' => $post['content'], 'attachment' => !empty($post['attach']) ? (array) $post['attach'] : array(), 'file' => !empty($post['file']) ? (array) $post['file'] : array());
        if (isset($post['starttime'])) {
            $params['starttime'] = !empty($post['starttime']) ? strtotime($post['starttime']) : null;
        }
        if (isset($post['endtime'])) {
            $params['endtime'] = !empty($post['endtime']) ? strtotime($post['endtime']) : null;
        }
        if (isset($post['totaltime']) && is_numeric($post['totaltime'])) {
            $params['totaltime'] = round((double) $post['totaltime'], 2) * 3600;
        }
        if (isset($post['percent'])) {
            $params['percent'] = min(100, (int) $post['percent']);
        }
        if (isset($post['classid'])) {
            $params['classid'] = $post['classid'];
        }
        if (!empty($post['notifyall'])) {
            $params['notifyall'] = $post['notifyall'];
        }
        // 公告置顶
        if ($type == 'notice' && !empty($params['endtime']) && $params['endtime'] >= strtotime('today')) {
            $params['istop'] = 1;
        } else {
            $params['istop'] = 0;
        }
        // 仅当草稿发送时更新创建时间
        if (!$fromTudu || $isFromDraft && $isSend) {
            $params['createtime'] = $this->_timestamp;
        }
        // 更新图度操作时,一些参数设置
        if (!isset($params['percent'])) {
            $params['percent'] = $fromTudu->percent;
        }
        if (isset($params['percent'])) {
            if (100 === $params['percent']) {
                $params['status'] = Dao_Td_Tudu_Tudu::STATUS_DONE;
                $params['cycle'] = null;
            } elseif ($params['percent'] > 0) {
                $params['status'] = Dao_Td_Tudu_Tudu::STATUS_DOING;
            }
        }
        // 处理日志记录内容
        $tuduLog['detail'] = $params;
        $postLog['detail'] = array('content' => $params['content']);
        unset($tuduLog['detail']['cycle'], $tuduLog['detail']['vote'], $tuduLog['detail']['email'], $tuduLog['detail']['content'], $tuduLog['detail']['attachment'], $tuduLog['detail']['file'], $tuduLog['detail']['poster'], $tuduLog['detail']['posterinfo']);
        $logPrivacy = !$isSend;
        ///////////////////////////////////
        // 保存图度数据
        $tuduId = $fromTudu->tuduId;
        $postId = $fromTudu->postId;
        // 内容的参数
        $postParams = array('content' => $params['content'], 'lastmodify' => implode(chr(9), array($uniqueId, $this->_timestamp, $this->_user['truename'])), 'createtime' => $this->_timestamp, 'attachment' => $params['attachment'], 'isforeign' => 1, 'file' => !empty($post['file']) ? (array) $post['file'] : array());
        // 从未发送时(草稿),相关的数据初始化(时效性的数据清除)
        if (!$isSent) {
            // 创建时间可相当于最先发送的时间
            $params['createtime'] = $this->_timestamp;
            // 未发送过,不存在最后编辑
            unset($postParams['lastmodify']);
        }
        // 不变更发起人
        unset($params['from']);
        if ($isForward) {
            // 转发,更新最后转发人信息,不更新图度元数据,新建回复内容
            unset($postParams['lastmodify']);
            $params['subject'] = $fromTudu->subject;
            $params['content'] = $fromTudu->content;
            $params['status'] = Dao_Td_Tudu_Tudu::STATUS_UNSTART;
            $params['accepttime'] = null;
            $params['lastforward'] = implode("\n", array($this->_user['truename'], time()));
            // 先发送新的回复
            $postParams = array_merge($postParams, array('orgid' => $this->_tudu->orgId, 'boardid' => $fromTudu->boardId, 'tuduid' => $tuduId, 'uniqueid' => $this->_user['uniqueid'], 'poster' => $this->_user['truename'], 'email' => $this->_user['email']));
            $postId = $this->_deliver->createPost($postParams);
            if (!$postId) {
                $this->json(false, $this->lang['save_failure']);
            }
            $this->getDao('Dao_Td_Tudu_Post')->sendPost($tuduId, $postId);
            $postLog['detail'] = $postParams;
            // 工作流程
            $steps = $this->_manager->getSteps($tuduId)->toArray('stepid');
            if (!empty($steps) && ($type = 'task')) {
                $currentStep = $this->_tudu->stepId && false === strpos($this->_tudu->stepId, '^') ? $steps[$this->_tudu->stepId] : array_pop($steps);
                // 当前为审批步骤
                $stepNum = count($steps);
                $newSteps = array();
                $currentTo = array_keys($this->_formatStepRecipients($params['to']));
                $fromTo = array_keys($this->_tudu->to);
                $fromCount = count($fromTo);
                $isChangeTo = count($currentTo) != $fromCount || count(array_uintersect($fromTo, $currentTo, "strcasecmp")) != $fromCount;
                if ($isChangeTo) {
                    $prevId = $currentStep['stepid'];
                    $orderNum = $currentStep['ordernum'];
                    $stepId = Dao_Td_Tudu_Step::getStepId();
                    $newSteps[$stepId] = array('orgid' => $this->_tudu->orgId, 'tuduid' => $tuduId, 'stepid' => $stepId, 'uniqueid' => $uniqueId, 'prevstepid' => $prevId, 'nextstepid' => '^end', 'type' => $this->_tudu->acceptMode ? Dao_Td_Tudu_Step::TYPE_CLAIM : Dao_Td_Tudu_Step::TYPE_EXECUTE, 'ordernum' => ++$orderNum, 'createtime' => time(), 'users' => $this->_formatStepRecipients($params['to']));
                    $params['stepid'] = $stepId;
                }
                // 移除后随未开始执行的步骤
                foreach ($steps as $step) {
                    if ($step['ordernum'] > $currentStep['ordernum']) {
                        $this->_manager->deleteStep($tuduId, $step['stepid']);
                        $stepNum--;
                    }
                }
                foreach ($newSteps as $step) {
                    if ($this->_manager->createStep($step)) {
                        var_dump($step['users']);
                        $recipients = $this->_prepareStepRecipients($this->_tudu->orgId, $uniqueId, $step['users']);
                        $processIndex = $step['type'] == Dao_Td_Tudu_Step::TYPE_EXAMINE ? 0 : null;
                        $this->_manager->addStepUsers($tuduId, $step['stepid'], $recipients, $processIndex);
                        $stepNum++;
                    }
                }
                $params['stepnum'] = $stepNum;
            }
            // 更新图度
            if (!$this->_deliver->updateTudu($tuduId, $params)) {
                $this->json(false, $this->lang['save_failure']);
            }
        }
        // 过滤日志变更内容参数
        if ($fromTudu) {
            $arrFromTudu = $fromTudu->toArray();
            foreach ($tuduLog['detail'] as $k => $val) {
                // 记录增加抄送人
                if ($k == 'cc') {
                    $arr = explode("\n", $val);
                    foreach ($arr as $idx => $v) {
                        $ccArr = explode(' ', $v);
                        if (array_key_exists($ccArr[0], $fromTudu->cc)) {
                            unset($arr[$idx]);
                        }
                    }
                    if (!$arr) {
                        unset($tuduLog['detail']['cc']);
                    } else {
                        $tuduLog['detail']['cc'] = implode("\n", $arr);
                    }
                    continue;
                }
                // 过滤未更新字段
                if (array_key_exists($k, $arrFromTudu) && $val == $arrFromTudu[$k]) {
                    unset($tuduLog['detail'][$k]);
                }
            }
            // 内容没有变更
            if (!$isForward) {
                if ($postLog['detail']['content'] == $fromTudu->content) {
                    unset($postLog['detail']);
                } else {
                    if (isset($postParams['lastmodify'])) {
                        $postLog['detail']['lastmodify'] = $postParams['lastmodify'];
                    }
                    $postLog['detail']['createtime'] = $postParams['createtime'];
                }
            }
            if (empty($tuduLog['detail']['cc'])) {
                unset($tuduLog['detail']['cc']);
            }
            unset($tuduLog['detail']['from']);
        }
        // 写入操作日志
        $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, $tuduLog['action'], $tuduLog['detail'], $logPrivacy);
        if (!empty($postLog['detail'])) {
            $this->_writeLog(Dao_Td_Log_Log::TYPE_POST, $postId, $postLog['action'], $postLog['detail'], $logPrivacy);
        }
        $sendParams = array();
        if ($type != 'task') {
            $sendParams['notice'] = $type == 'notice';
            $sendParams['discuss'] = $type == 'discuss';
        }
        // 删除需要移除的接受人
        if ($removeAccepters) {
            if (!$this->_deliver->removeTuduAccepter($tuduId, $removeAccepters)) {
                $this->json(false, $this->lang['send_failure']);
            }
        }
        // 发送图度
        if (!$this->_deliver->sendTudu($tuduId, $recipients, $sendParams)) {
            $this->json(false, $this->lang['send_failure']);
        }
        // 已发送的任务更新时,设置所有人为未读状态
        if ($isSent) {
            $this->_manager->markAllUnread($tuduId);
        }
        // 转发任务时,设置当前关联用户为转发状态
        if ($isForward) {
            $this->_manager->markForward($tuduId, $uniqueId);
            // 更新转发编辑后的任务进度
            $this->_deliver->updateProgress($tuduId, $uniqueId, null);
            // 更新转发后的任务接受状态
            $this->_deliver->updateLastAcceptTime($tuduId, $uniqueId, null);
            // 移除“我执行”标签
            $this->_manager->deleteLabel($tuduId, $uniqueId, '^a');
        }
        // 重新计算父级图度进度
        if ($fromTudu && $fromTudu->parentId) {
            $this->_deliver->calParentsProgress($fromTudu->parentId);
        }
        if ('task' == $type) {
            // 发起人为当前执行人
            if ($isAccpter) {
                // 自动接受任务
                $this->_deliver->acceptTudu($tuduId, $uniqueId, null);
                // 添加我执行
                $this->_deliver->addLabel($tuduId, $uniqueId, '^a');
                // 接受添加日志
                $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tuduId, Dao_Td_Log_Log::ACTION_TUDU_ACCEPT, array('status' => Dao_Td_Tudu_Tudu::STATUS_DOING, 'accepttime' => time()));
                // 非当前执行人
            } else {
                // 设为已读
                $this->_deliver->markRead($tuduId, $uniqueId);
            }
        }
        $config = $this->_bootstrap->getOption('httpsqs');
        // 插入消息队列
        $httpsqs = new Oray_Httpsqs($config['host'], $config['port'], $config['chartset'], $config['name']);
        // 收发规则过滤
        $data = implode(' ', array('tudu', 'filter', '', http_build_query(array('tsid' => $this->_tsId, 'tuduid' => $tuduId))));
        $httpsqs->put($data, 'tudu');
        // 发送外部邮件(如果有),处理联系人
        $data = implode(' ', array('send', 'tudu', '', http_build_query(array('tsid' => $this->_tsId, 'tuduid' => $tuduId, 'uniqueid' => $this->_user['uniqueid'], 'to' => ''))));
        $httpsqs->put($data, 'send');
        // IM提醒
        if (!empty($notifyTo)) {
            $content = str_replace('%', '%%', mb_substr(preg_replace('/<[^>]+>/', '', $params['content']), 0, 100, 'UTF-8'));
            $names = array('task' => '图度', 'discuss' => '讨论', 'notice' => '公告');
            $tpl = <<<HTML
<strong>您刚收到一个新的{$names[$type]}</strong><br />
<a href="http://{$this->_request->getServer('HTTP_HOST')}/frame#m=view&tid=%s&page=1" target="_blank">%s</a><br />
发起人:{$this->_user['truename']}<br />
更新日期:%s<br />
{$content}
HTML;
            $data = implode(' ', array('tudu', 'create', '', http_build_query(array('tuduid' => $this->_tudu->tuduId, 'from' => $this->_user['email'], 'to' => implode(',', $notifyTo), 'content' => sprintf($tpl, $this->_tudu->tuduId, $params['subject'], date('Y-m-d H:i:s', time()))))));
            $httpsqs->put($data);
        }
        $this->json(true, $this->lang['send_success'], $tuduId);
    }
예제 #3
0
파일: Send.php 프로젝트: bjtenao/tudu-web
 /**
  * 外发会议
  *
  * @param array $params
  */
 public function sendMeeting($params)
 {
     if (empty($params['tuduid']) || empty($params['tsid']) || empty($params['uniqueid']) || empty($params['from']) || empty($params['content']) || empty($params['location'])) {
         return;
     }
     $tuduId = $params['tuduid'];
     $uniqueId = $params['uniqueid'];
     $tsId = $params['tsid'];
     $to = !empty($params['to']) ? explode(',', $params['to']) : null;
     $sender = $params['from'];
     $content = $params['content'];
     $location = $params['location'];
     /* @var $manager Tudu_Tudu_Manager */
     $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     $tudu = $manager->getTuduById($tuduId, $uniqueId);
     if (null == $tudu) {
         $this->getLogger()->warn("Tudu id:{$tuduId} is not exists");
         return;
     }
     // 获取接收人
     $receivers = $manager->getTuduUsers($tudu->tuduId);
     $emails = array();
     /* @var $daoContact Dao_Td_Contact_Contact */
     $daoContact = Tudu_Dao_Manager::getDao('Dao_Td_Contact_Contact', Tudu_Dao_Manager::DB_TS);
     // 处理接收人数据
     foreach ($receivers as $receiver) {
         $info = explode(' ', $receiver['accepterinfo'], 3);
         $email = $info[0];
         $name = !empty($info[1]) ? $info[1] : null;
         $contactId = isset($info[2]) ? $info[2] : null;
         if ($name == null && $email) {
             $arr = explode('@', $email);
             $name = array_shift($arr);
         }
         if (!$email && !$name) {
             continue;
         }
         if (!empty($to) && !in_array($email, $to)) {
             continue;
         }
         if ($receiver['isforeign']) {
             $auth = $receiver['authcode'];
             if (Oray_Function::isEmail($email) && $uniqueId != $receiver['uniqueid']) {
                 $array = array('address' => $email, 'name' => $name, 'authinfo' => '', 'url' => 'http://' . $tudu->orgId . '.com/foreign/tudu?ts=' . $tsId . '&tid=' . $tudu->tuduId . '&fid=' . $receiver['uniqueid']);
                 if ($auth) {
                     $array['authinfo'] = '<p style="margin:10px 0">打开任务链接后需要输入以下验证码:<strong style="color:#f00">' . $auth . '</strong></p>';
                 }
                 $emails[] = $array;
             }
         }
     }
     // 执行外发
     $tpl = $this->_options['data']['path'] . '/templates/tudu/mail_meeting_notify.tpl';
     if (!file_exists($tpl) || !is_readable($tpl)) {
         $this->getLogger()->warn("Tpl file:\"mail_meeting_notify.tpl\" is not exists");
         return;
     }
     // 公用信息
     $common = array('subject' => $tudu->subject, 'sender' => $sender, 'lastupdate' => date('Y-m-d H:i:s', $tudu->lastPostTime), 'content' => mb_substr(strip_tags($content), 0, 20, 'utf-8'), 'type' => $this->_typeNames[$tudu->type]);
     $mailTransport = $this->getMailTransport($this->_balancer->select());
     $template = $this->_assignTpl(file_get_contents($tpl), $common);
     foreach ($emails as $email) {
         try {
             $mail = new Zend_Mail('utf-8');
             $mail->setFrom($this->_options['smtp']['from']['alert'], urldecode($this->_options['smtp']['fromname']));
             $mail->addTo($email['address'], $email['name']);
             $mail->addHeader('tid', $tudu->tuduId);
             $mail->setSubject("图度{$this->_typeNames[$tudu->type]}——" . $tudu->subject . '[会议提醒]');
             $mail->setBodyHtml($this->_assignTpl($template, $email));
             $mail->send($mailTransport);
         } catch (Zend_Mail_Exception $ex) {
             $this->getLogger()->warn("[Failed] Email send type:{$this->_typeNames[$tudu->type]} TuduId:{$tuduId} retry\n{$ex}");
             continue;
         }
     }
     $this->getLogger()->debug("Send Meeting id:{$tuduId} done");
 }
예제 #4
0
 /**
  * 编辑表单
  */
 public function modifyAction()
 {
     $tuduId = $this->_request->getQuery('tid');
     $type = $this->_request->getQuery('type', 'task');
     $to = $this->_request->getQuery('to', $this->_request->getQuery('email'));
     // email IM跳转
     $boardId = trim($this->_request->getQuery('bid'));
     $flowId = $this->_request->getQuery('flowid');
     $autosave = $this->_request->getPost('autosave');
     $newwin = (bool) $this->_request->getQuery('newwin');
     $attachments = null;
     $isSynchro = false;
     //是否逐级执行
     $tudu = array();
     $votes = array();
     $access = $this->_user->getAccess();
     // 权限
     $perm = array('task' => $access->assertEquals(Tudu_Access::PERM_CREATE_TUDU, true), 'discuss' => $access->assertEquals(Tudu_Access::PERM_CREATE_DISCUSS, true), 'notice' => $access->assertEquals(Tudu_Access::PERM_CREATE_NOTICE, true), 'meeting' => $access->assertEquals(Tudu_Access::PERM_CREATE_MEETING, true), 'board' => $access->assertEquals(Tudu_Access::PERM_CREATE_BOARD, true));
     $perm['group'] = $perm['task'];
     if (!in_array($type, array('task', 'notice', 'discuss', 'group', 'meeting'))) {
         foreach ($perm as $key => $value) {
             if ($value) {
                 $type = $key;
                 break;
             }
         }
     }
     if ($type == 'board') {
         return $this->_redirect('/board/modify');
     }
     if ($tuduId) {
         if (!$access->assertEquals(Tudu_Access::PERM_UPDATE_TUDU, true)) {
             Oray_Function::alert($this->lang['perm_deny_update_tudu'], '/tudu/?search=inbox');
         }
         $tudu = $this->getDao('Dao_Td_Tudu_Tudu')->getTuduById($this->_user->uniqueId, $tuduId);
         if (null === $tudu) {
             Oray_Function::alert($this->_lang['tudu_not_exists']);
         }
         $perm = array('discuss' => false, 'group' => false, 'notice' => false, 'task' => false, 'board' => false);
         $boards = $this->getBoards(false);
         $board = $boards[$tudu->boardId];
         $isSender = in_array($tudu->sender, array($this->_user->address, $this->_user->userName));
         $isModerators = array_key_exists($this->_user->userId, $board['moderators']);
         // 上级分区负责人
         $isSuperModerator = !empty($board['parentid']) && array_key_exists($this->_user->userId, $boards[$board['parentid']]['moderators']);
         $isOwner = $board['ownerid'] == $this->_user->userId;
         if (!$isSender && !$isModerators && !$isSuperModerator) {
             Oray_Function::alert($this->lang['perm_deny_update_tudu'], '/tudu/?search=inbox');
         }
         $daoClasses = $this->getDao('Dao_Td_Tudu_Class');
         $classes = $daoClasses->getClassesByBoardId($this->_user->orgId, $tudu->boardId, array('ordernum' => 'ASC'))->toArray();
         if ($isModerators || $isSuperModerator || $isOwner) {
             $classes[] = array('classname' => $this->lang['create_board_class'], 'classid' => '^add-class');
         }
         $this->view->classes = $classes;
         if ($tudu->attachNum > 0) {
             /**
              *
              * @var Dao_Td_Attachment_File
              */
             $daoFile = $this->getDao('Dao_Td_Attachment_File');
             $attachments = $daoFile->getFiles(array('tuduid' => $tudu->tuduId, 'postid' => $tudu->postId));
             $attachments = $attachments->toArray();
         }
         if ($tudu->special == Dao_Td_Tudu_Tudu::SPECIAL_VOTE) {
             /* @var $daoVote Dao_Td_Tudu_Vote */
             $daoVote = $this->getDao('Dao_Td_Tudu_Vote');
             $votes = $daoVote->getVotesByTuduId($tudu->tuduId);
             $votes = $votes->toArray();
             $votes = $daoVote->formatVotes($votes);
         }
         if ($tudu->cycleId) {
             $daoCycle = $this->getDao('Dao_Td_Tudu_Cycle');
             $cycle = $daoCycle->getCycle(array('cycleid' => $tudu->cycleId));
             $this->view->cycle = $cycle->toArray();
         }
         /* @var $daoFlow Dao_Td_Tudu_Flow */
         $daoFlow = $this->getDao('Dao_Td_Tudu_Flow');
         if ($tudu->flowId) {
             /* @var $daoFlowTpl Dao_Td_Flow_Flow */
             $daoFlowTpl = $this->getDao('Dao_Td_Flow_Flow');
             $flow = $daoFlowTpl->getFlow(array('flowid' => $tudu->flowId))->toArray();
             $flows[] = $flow;
             $this->view->flows = $flows;
             $isDisagreed = false;
             if ($tudu->type == 'task' && $tudu->stepNum > 0) {
                 $flow = $daoFlow->getFlow(array('tuduid' => $tudu->tuduId));
                 $steps = array();
                 $isExceed = false;
                 $counter = 0;
                 foreach ($flow->steps as $sid => $st) {
                     if (!$isExceed && $sid == $flow->currentStepId) {
                         $isExceed = true;
                     }
                     foreach ($st['section'] as $idx => $sec) {
                         foreach ($sec as $i => $u) {
                             $user = array('email' => $u['username'], 'truename' => $u['truename'], 'stepid' => $sid, 'type' => $st['type'], 'stepstatus' => isset($u['status']) ? (int) $u['status'] : 0, 'processindex' => $counter);
                             if ($isExceed && ($sid != $flow->currentStepId || $st['type'] == 1 && (!isset($user['status']) || $user['status'] < 1))) {
                                 $user['future'] = true;
                             }
                             $steps[$counter]['users'][] = $user;
                             $steps[$counter]['type'] = $st['type'];
                         }
                         $counter++;
                     }
                 }
                 ksort($steps);
                 if (!$isDisagreed && count($steps)) {
                     $lastStep = end($steps);
                     reset($steps);
                 }
                 if (count($steps) > 1) {
                     $this->view->steps = $steps;
                 }
             }
         }
         if ($tudu->type == 'meeting') {
             $daoMeeting = $this->getDao('Dao_Td_Tudu_Meeting');
             $meeting = $daoMeeting->getMeeting(array('tuduid' => $tudu->tuduId));
             if (null !== $meeting) {
                 $this->view->meeting = $meeting->toArray();
             }
         }
         if ($tudu->isTuduGroup && (!$tudu->to || in_array($this->_user->userName, $tudu->accepter))) {
             //$type = 'group';
             $type = 'task';
             $children = $this->getDao('Dao_Td_Tudu_Tudu')->getGroupTudus(array('parentid' => $tudu->tuduId, 'senderid' => $this->_user->uniqueId, 'uniqueid' => $this->_user->uniqueId), null, 'lastposttime DESC')->toArray();
             /* @var $daoFlow Dao_Td_Tudu_Flow */
             $daoFlow = $this->getDao('Dao_Td_Tudu_Flow');
             foreach ($children as $key => $child) {
                 $to = array();
                 $toText = array();
                 if (empty($child['flowid']) && $child['stepid']) {
                     $flow = $daoFlow->getFlow(array('tuduid' => $child['tuduid']));
                     if (!$flow) {
                         continue;
                     }
                     $isExceed = false;
                     $toIdx = null;
                     foreach ($flow->steps as $sid => $step) {
                         if (!$isExceed && ($sid == $flow->currentStepId || ($flow->currentStepId = '^head'))) {
                             $isExceed = true;
                         }
                         if ($isExceed && $step['type'] == 0) {
                             foreach ($step['section'] as $sec) {
                                 if (!empty($to)) {
                                     $to[] = '>';
                                 }
                                 foreach ($sec as $idx => $u) {
                                     if (!isset($u['status']) || (int) $u['status'] != 4) {
                                         if ($idx > 0) {
                                             $to[] = '+';
                                         }
                                         $to[] = $u['username'] . ' ' . $u['truename'];
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (!empty($to)) {
                     foreach ($to as $item) {
                         if ($item == '+' || $item == '>') {
                             $toText[] = $item;
                             continue;
                         }
                         $info = explode(' ', $item);
                         if (isset($info[1])) {
                             $toText[] = $info[1];
                         }
                     }
                 }
                 $children[$key]['totext'] = $toText;
                 $children[$key]['to'] = $to;
                 if ($child['status'] == 3) {
                     $claimAccepters = array();
                     foreach ($flow->steps as $step) {
                         if ($step['type'] == 2) {
                             foreach ($step['section'] as $sec) {
                                 foreach ($sec as $u) {
                                     $claimAccepters[] = array('email' => $u['username'], 'truename' => $u['truename'], 'userinfo' => $u['username'] . ' ' . $u['truename']);
                                 }
                             }
                         }
                     }
                     if (!empty($claimAccepters)) {
                         $this->view->claimAccepters = $claimAccepters;
                     }
                 }
             }
             $this->view->children = $children;
         }
         if ($tudu->status == 3 && !$tudu->isTuduGroup && $tudu->stepId) {
             $flow = $daoFlow->getFlow(array('tuduid' => $tuduId));
             if ($flow && isset($flow->steps[$tudu->stepId])) {
                 //$claimAccepters = $daoFlow->getUsers($tuduId, $claim->stepId);
                 $step = $flow->steps[$tudu->stepId];
                 if ($step['type'] == 2) {
                     $claimAccepters = $step['section'][0];
                     foreach ($claimAccepters as &$claimAccepter) {
                         $info = explode(' ', $claimAccepter['userinfo'], 2);
                         if (count($info) == 2) {
                             $claimAccepter['email'] = $info[0];
                             $claimAccepter['truename'] = $info[1];
                         }
                     }
                     $this->view->claimAccepters = $claimAccepters;
                 }
             }
         }
         $tudu = $tudu->toArray();
         $tudu['attachments'] = $attachments;
         $type = $tudu['type'];
         if ($type == 'task' && !empty($tudu['stepid']) && $tudu['stepid'] == '^end') {
             $to = array();
             foreach ($tudu['to'] as $item) {
                 if (!empty($to)) {
                     $to[]['userinfo'] = '+';
                 }
                 $to[] = array('email' => $item[3], 'truename' => $item[0], 'userinfo' => $item[3] . ' ' . $item[0]);
             }
             $tudu['to'] = $to;
             // 逐级执行,执行人填充  审批人填充
         } elseif ($tudu && empty($tudu['flowid']) && ($type == 'task' || $type == 'notice') && !empty($tudu['stepid'])) {
             /* @var $daoFlow Dao_Td_Tudu_Flow */
             $daoFlow = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Flow', Tudu_Dao_Manager::DB_TS);
             $flow = $daoFlow->getFlow(array('tuduid' => $tudu['tuduid']));
             $steps = $flow->steps;
             $step = isset($flow->steps[$flow->currentStepId]) ? $flow->steps[$flow->currentStepId] : null;
             foreach ($steps as $st) {
                 if ($st['type'] == 1 && $st['section']) {
                     foreach ($st['section'] as $sec) {
                         foreach ($sec as $u) {
                             if ($u['status'] > 2) {
                                 $step = $st;
                                 break 3;
                             }
                         }
                     }
                 }
             }
             if (!$step) {
                 $reviewer = array();
                 $to = array();
                 $step = isset($steps[$flow->currentStepId]) ? $steps[$flow->currentStepId] : null;
                 if (null === $step && $flow->currentStepId == '^head') {
                     $step = reset($steps);
                 }
             }
             if (null !== $step) {
                 if ($step['type'] == 1) {
                     foreach ($step['section'] as $idx => $section) {
                         if (isset($step['currentSection']) && $idx < $step['currentSection']) {
                             continue;
                         }
                         if (!empty($reviewer)) {
                             $reviewer[] = array('userinfo' => '>');
                         }
                         foreach ($section as $i => $user) {
                             if (isset($user['status']) && $user['status'] == 2) {
                                 continue;
                             }
                             if ($idx > 0 && $i > 0) {
                                 $reviewer[] = array('userinfo' => '+');
                             }
                             $reviewer[] = array('email' => $user['username'], 'truename' => $user['truename'], 'userinfo' => $user['username'] . ' ' . $user['truename']);
                         }
                     }
                     $executeStep = isset($steps[$step['next']]) ? $steps[$step['next']] : null;
                 } else {
                     $executeStep = isset($steps[$flow->currentStepId]) ? $steps[$flow->currentStepId] : null;
                 }
                 if ($executeStep && $executeStep['type'] != 1) {
                     foreach ($executeStep['section'] as $idx => $section) {
                         if (isset($executeStep['currentSection']) && $idx < $executeStep['currentSection']) {
                             continue;
                         }
                         if (!empty($to)) {
                             $to[] = array('userinfo' => '>');
                         }
                         foreach ($section as $i => $user) {
                             if ($i > 0) {
                                 $to[] = array('userinfo' => '+');
                             }
                             $to[] = array('email' => $user['username'], 'truename' => $user['truename'], 'userinfo' => $user['username'] . ' ' . $user['truename']);
                         }
                     }
                 }
             }
             if (!empty($reviewer)) {
                 $this->view->reviewer = $reviewer;
             }
             if (!empty($to)) {
                 $tudu['to'] = $to;
             }
         }
     } else {
         if (!$perm[$type]) {
             Oray_Function::alert($this->lang['perm_deny_create_' . $type], '/tudu/?search=inbox');
         }
         if ($this->_request->getPost()) {
             $params = $this->_getModifyParams();
             $tudu = $params['tudu'];
             if ($type == 'meeting') {
                 unset($tudu['starttime']);
                 unset($tudu['endtime']);
             }
             if (!empty($tudu['type']) && $tudu['type'] == 'meeting') {
                 unset($tudu['starttime']);
                 unset($tudu['endtime']);
             }
             unset($tudu['type']);
         }
         $boards = $this->getBoards(false);
         if (!empty($boardId) && isset($boards[$boardId])) {
             $board = $boards[$boardId];
             $isModerators = array_key_exists($this->_user->userId, $board['moderators']);
             $isOwner = $board['ownerid'] == $this->_user->userId;
             // 上级分区负责人
             $isSuperModerator = !empty($board['parentid']) && array_key_exists($this->_user->userId, $boards[$board['parentid']]['moderators']);
             if ($boardId && (!isset($tudu['tuduid']) || empty($tudu['boardid']))) {
                 $tudu['boardid'] = $boardId;
             }
             $daoClasses = $this->getDao('Dao_Td_Tudu_Class');
             $classes = $daoClasses->getClassesByBoardId($this->_user->orgId, $tudu['boardid'], array('ordernum' => 'ASC'))->toArray();
             // XXX
             if ($isModerators || $isSuperModerator || $isOwner) {
                 $classes[] = array('classname' => $this->lang['create_board_class'], 'classid' => '^add-class');
             }
             $this->view->classes = $classes;
         }
         if ($flowId) {
             $this->view->flowid = $flowId;
         }
         if (isset($tudu['to']) && is_array($tudu['to'])) {
             foreach ($tudu['to'] as $idx => $item) {
                 $tudu['to'][$idx]['userinfo'] = $item[3] . ' ' . $item[0];
             }
         }
     }
     if ($to && !$tudu) {
         if (Oray_Function::isEmail($to)) {
             $to = explode('@', $to);
             $userId = $to[0];
             echo $userId;
             $daoUser = Oray_Dao::factory('Dao_Md_User_User', $this->multidb->getDb());
             $to = $daoUser->getUsers(array('orgid' => $this->_user->orgId, 'userid' => $userId), null, null, 1)->toArray();
             if (!empty($to[0])) {
                 $email = $to[0]['userid'] . '@' . $to[0]['domainname'];
                 $tudu['to'] = array($email => array(0 => $to[0]['truename'], 1 => $to[0]['userid'], 2 => $to[0]['domainname']));
                 $tudu['accepter'] = array($email);
             }
         } else {
             // IM email特殊处理
             $to = explode("\n", $to);
             foreach ($to as $item) {
                 $tudu['to'][]['userinfo'] = $item;
             }
             /*if (strpos($to, ' ') === false) {
                   $to = ' ' . $to;
               }
               $tudu['to'] = Dao_Td_Tudu_Tudu::formatAddress($to);*/
         }
     }
     $perm['upload'] = $access->isAllowed(Tudu_Access::PERM_UPLOAD_ATTACH);
     $uploadOpt = $this->bootstrap->getOption('upload');
     $boards = $this->getBoards();
     $cookies = $this->_request->getCookie();
     $this->view->registModifier('tudu_format_content', array($this, 'formatContent'));
     $board = null;
     if (!$tudu) {
         foreach ($boards as $key => $zone) {
             if (!empty($zone['children'])) {
                 foreach ($zone['children'] as $k => $child) {
                     if ($child['status'] == 2) {
                         unset($boards[$key]['children'][$k]);
                         $boards[$key]['children'] = array_values($boards[$key]['children']);
                     }
                 }
             }
             if ($zone['type'] == 'zone' && empty($zone['children'])) {
                 unset($boards[$key]);
             }
         }
         //var_dump($boards['^zone']);exit();
     } else {
         foreach ($boards as $key => $zone) {
             if (!empty($zone['children']) && !empty($tudu['boardid'])) {
                 foreach ($zone['children'] as $k => $child) {
                     if ($tudu['boardid'] == $child['boardid']) {
                         $tudu['boardname'] = $child['boardname'];
                         $board = $child;
                         // 执行人拒绝任务,在不可修改板块也可修改图度
                         if ($board['protect'] && (isset($tudu['status']) && $tudu['status'] == Dao_Td_Tudu_Tudu::STATUS_REJECT && in_array($tudu['sender'], array($this->_user->address, $this->_user->userName))) || empty($tudu['tuduid']) || !empty($tudu['isdraft'])) {
                             $board['protect'] = 0;
                         }
                         break;
                     }
                 }
             }
         }
     }
     // 处理快捷板块
     //$attentions = array('children' => array());
     /* @var $daoBoard Dao_Td_Board_Board */
     /*$daoBoard = $this->getDao('Dao_Td_Board_Board');
             $attenBoards = $daoBoard->getAttentionBoards($this->_user->orgId, $this->_user->uniqueId);
             if ($attenBoards !== null) {
                 $attentions['children'] = $attenBoards;
             }
     
             if (!empty($attentions['children'])) {
                 $attentions['type'] = 'zone';
                 $attentions['boardname'] = $this->lang['my_attention_board'];
                 $boards = array_merge(array($attentions), $boards);
             }*/
     $upload = $this->options['upload'];
     $upload['cgi']['upload'] .= '?' . session_name() . '=' . $this->_sessionId . '&email=' . $this->_user->address;
     if (!empty($tudu['tuduid'])) {
         $tudu['users'] = $this->getDao('Dao_Td_Tudu_Tudu')->getUsers($tudu['tuduid']);
     }
     if ($autosave) {
         $tudu['autosave'] = $autosave;
     }
     $accepters = $this->getDao('Dao_Td_Tudu_Tudu')->getAccepters($tuduId);
     foreach ($accepters as &$accepter) {
         $info = explode(' ', $accepter['accepterinfo'], 2);
         if (count($info) == 2) {
             $accepter['email'] = str_replace(array('oray.com', 'tudu.com'), array('oray', ''), $info[0]);
             $accepter['truename'] = $info[1];
         }
         $accepter['percent'] = (int) $accepter['percent'];
     }
     if ($tudu && $type == 'task') {
         $canNotDelAccepter = array();
         foreach ($accepters as &$accepter) {
             $childrenCount = $this->getDao('Dao_Td_Tudu_Group')->getChildrenCount($tudu['tuduid'], $accepter['uniqueid']);
             if ($childrenCount > 0) {
                 $canNotDelAccepter[] = array('uniqueid' => $accepter['uniqueid'], 'truename' => $accepter['truename'], 'username' => $accepter['email'], 'accepterinfo' => $accepter['accepterinfo']);
             }
         }
         $this->view->cannotdelaccepter = $canNotDelAccepter;
     }
     if ($newwin) {
         $daoOrg = $this->getMdDao('Dao_Md_Org_Org');
         $org = $daoOrg->getOrg(array('orgid' => $this->_user->orgId));
         $this->view->org = $org->toArray();
     }
     $this->view->registModifier('format_board_list', array($this, 'formatBoardList'));
     $this->view->board = $board;
     $this->view->back = $this->_request->getQuery('back');
     $this->view->reopen = $this->_request->getQuery('reopen');
     $this->view->upload = $upload;
     $this->view->cookies = serialize($cookies);
     $this->view->boards = $boards;
     $this->view->tudu = $tudu;
     $this->view->accepters = $accepters;
     $this->view->access = $perm;
     $this->view->votes = $votes;
     $this->view->ndfile = !empty($tudu['nd-attach']) ? $tudu['nd-attach'] : null;
     $this->view->newwin = $newwin;
     $this->view->sessionid = $this->_sessionId;
     $this->view->issynchro = $isSynchro;
     $this->render('modify_' . $type);
 }
예제 #5
0
 /**
  * 保存邮箱
  */
 public function savemailboxAction()
 {
     $post = $this->_request->getPost();
     $bind = false;
     $daoUser = $this->getMdDao('Dao_Md_User_User');
     $mailBox = $daoUser->getMailbox($this->_user->orgId, $this->_user->userId);
     if (!empty($post['address']) || !empty($post['password']) || !empty($post['imaphost'])) {
         $bind = true;
         if (empty($post['address']) || !Oray_Function::isEmail($post['address'])) {
             return $this->json(false, $this->lang['invalid_email_address']);
         }
         if (empty($post['password']) && !$mailBox) {
             return $this->json(false, $this->lang['missing_email_password']);
         }
         if (!empty($post['imaphost']) && (!Oray_Function::isDomainName($post['imaphost']) && !Oray_Function::isIp($post['imaphost']))) {
             return $this->json(false, $this->lang['invalid_imap_host']);
         }
         if ($post['port'] != '') {
             if ((int) $post['port'] <= 0 || (int) $post['port'] > 65535) {
                 return $this->json(false, $this->lang['invalid_imap_port']);
             }
         }
     }
     if ($bind) {
         $isSsl = isset($post['isssl']) && $post['isssl'] == 1 ? 1 : 0;
         $type = isset($post['type']) ? (int) $post['type'] : 0;
         if (null !== $mailBox) {
             $params = array('address' => $post['address'], 'imaphost' => $post['imaphost'], 'port' => (int) $post['port'] > 0 ? (int) $post['port'] : null, 'isssl' => $isSsl, 'type' => $type);
             if (!empty($post['password'])) {
                 $params['password'] = $post['password'];
             }
             $ret = $daoUser->updateMailbox($this->_user->orgId, $this->_user->userId, $params);
         } else {
             $ret = $daoUser->addMailbox(array('orgid' => $this->_user->orgId, 'userid' => $this->_user->userId, 'address' => $post['address'], 'imaphost' => $post['imaphost'], 'password' => $post['password'], 'port' => (int) $post['port'] > 0 ? (int) $post['port'] : null, 'isssl' => $isSsl, 'type' => $type));
         }
     } else {
         $ret = $daoUser->removeMailbox($this->_user->orgId, $this->_user->userId);
     }
     if (!$ret) {
         return $this->json(false, $this->lang['update_mailbox_failure']);
     }
     return $this->json(true, $this->lang['update_mailbox_success']);
 }
예제 #6
0
파일: Flow.php 프로젝트: lucn/tudu-web
 /**
  *
  * @param string $stepId
  * @param int    $sectionIndex
  * @param string $userName
  */
 public function addStepSectionUser($stepId, $sectionIndex, $user)
 {
     foreach ($this->_steps as $index => $item) {
         if ($item['stepid'] == $stepId) {
             if (isset($item['section'][$sectionIndex])) {
                 $users = array();
                 foreach ($item['section'][$sectionIndex] as $u) {
                     if ($u['username'] == $user['username']) {
                         return $this;
                     }
                 }
                 $orgId = $this->_attrs['orgid'];
                 $userName = isset($user['username']) ? $user['username'] : $user['email'];
                 $trueName = $user['truename'];
                 if (Oray_Function::isEmail($userName)) {
                     require_once 'Dao/Td/Contact/Contact.php';
                     $u = array('uniqueid' => Dao_Td_Contact_Contact::getContactId(), 'truename' => isset($item['truename']) ? $item['truename'] : substr($userName, 0, strpos($userName, '@')), 'email' => $userName, 'username' => $userName);
                 } else {
                     if (empty($item['uniqueid'])) {
                         $u = $this->_getAddressBook()->searchUser($orgId, $userName);
                     } else {
                         $u = array('uniqueid' => $item['uniqueid'], 'truename' => $item['truename'], 'email' => isset($item['email']) ? $item['email'] : $item['username'], 'username' => $item['username']);
                     }
                 }
                 if (!$u) {
                     require_once 'Model/Tudu/Exception.php';
                     throw new Model_Tudu_Exception('User in Tudu flow was not exists: ' . $item['username'], Model_Tudu_Exception::FLOW_USER_NOT_EXISTS);
                 }
                 $item = array('uniqueid' => $u['uniqueid'], 'truename' => $u['truename'], 'username' => $u['email'], 'deptid' => !empty($u['deptid']) ? $u['deptid'] : '^root');
                 if (isset($user['status'])) {
                     $item['status'] = $user['status'];
                 }
                 $this->_steps[$index]['section'][$sectionIndex][] = $item;
             }
         }
     }
     return $this;
 }
예제 #7
0
파일: User.php 프로젝트: bjtenao/tudu-web
 /**
  * 更新用户
  */
 public function update(array $params)
 {
     // 组织ID必须有
     if (empty($params['orgid'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing or invalid value of parameter "orgid"', self::CODE_INVALID_ORGID);
     }
     $orgId = $params['orgid'];
     $edit = array('truename' => true, 'password' => true, 'dept' => true, 'status' => true, 'role' => true, 'group' => true, 'cast' => true, 'netdisk' => true, 'email' => true);
     if (!empty($params['edit'])) {
         $edit = $params['edit'];
     }
     /* @var $daoUser Dao_Md_User_User */
     $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD);
     // 用户名
     if (empty($params['userid'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing the value of parameter "userid"', self::CODE_MISSING_UID);
     }
     $userId = $params['userid'];
     $user = $daoUser->getUser(array('orgid' => $orgId, 'userid' => $userId));
     $userIf = $daoUser->getUserInfo(array('orgid' => $orgId, 'userid' => $userId));
     // 用户不存在
     if (null === $user) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing the value of parameter "userid"', self::CODE_USER_NOTEXISTS);
     }
     // 用户真实姓名
     if ($edit['truename'] && empty($params['truename'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing or invalid value of parameter "truename"', self::CODE_INVALID_USERNAME);
     }
     // 邮箱格式有误
     if ($edit['email'] && !empty($params['email']) && !Oray_Function::isEmail($params['email'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Invalid value of parameter "email"', self::CODE_INVALID_EMAIL);
     }
     $userParam = array();
     $userInfo = array();
     if ($edit['status']) {
         $userParam['status'] = isset($params['status']) ? (int) $params['status'] : 1;
     }
     if ($edit['dept']) {
         $userParam['deptid'] = isset($params['deptid']) ? $params['deptid'] : null;
     }
     if (isset($params['ordernum'])) {
         $userParam['ordernum'] = (int) $params['ordernum'];
     }
     $userParam['lastupdatetime'] = time();
     if (isset($params['isshow'])) {
         $userParam['isshow'] = $params['isshow'];
     }
     if (isset($params['truename'])) {
         $userInfo['truename'] = $params['truename'];
     }
     if (isset($params['position'])) {
         $userInfo['position'] = $params['position'];
     }
     if (isset($params['gender'])) {
         $userInfo['gender'] = (int) $params['gender'];
     }
     if (isset($params['tel'])) {
         $userInfo['tel'] = $params['tel'];
     }
     if (isset($params['mobile'])) {
         $userInfo['mobile'] = $params['mobile'];
     }
     if (isset($params['email'])) {
         $userInfo['email'] = $params['email'];
     }
     /* @var $daoOrg Dao_Md_Org_Org */
     $daoOrg = Tudu_Dao_Manager::getDao('Dao_Md_Org_Org', Tudu_Dao_Manager::DB_MD);
     // 读取组织信息
     $org = $daoOrg->getOrg(array('orgid' => $orgId));
     // 网盘空间
     if ($edit['netdisk'] && !empty($params['maxndquota'])) {
         $ndQuota = (double) $params['maxndquota'] * 1000000;
         if ($ndQuota != $user->maxNdQuota) {
             if ($params['maxndquota'] > 1000) {
                 require_once 'Model/User/Exception.php';
                 throw new Model_User_Exception('You can not set exceed 1000MB netdisk space', self::CODE_EXCEED_MAX_NDSPACE);
             }
             /* @var $daoFolder Dao_Td_Netdisk_Folder */
             $daoFolder = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_Folder', Tudu_Dao_Manager::DB_TS);
             $folderRoot = $daoFolder->getFolder(array('uniqueid' => $user->uniqueId, 'folderid' => '^root'));
             if (null !== $folderRoot && $ndQuota < $folderRoot->folderSize) {
                 require_once 'Model/User/Exception.php';
                 throw new Model_User_Exception('This netdisk space can not less than the used netdisk space', self::CODE_LESS_NDSPACE);
             }
             // 更新用户网盘跟文件夹空间
             if (null !== $folderRoot) {
                 $daoFolder->updateFolder($user->uniqueId, '^root', array('maxquota' => $ndQuota));
             }
             $userParam['maxndquota'] = $ndQuota;
         }
     }
     // 无效的出生日期
     if (!empty($params['birthday'])) {
         if (false === $params['birthday']) {
             require_once 'Model/User/Exception.php';
             throw new Model_User_Exception('Missing or invalid value of parameter "birthday"', self::CODE_INVALID_BIRTHDAY);
         }
         $userInfo['birthday'] = $params['birthday'];
     }
     if ($edit['truename'] && !Oray_Function::isByte($params['truename'])) {
         require_once 'Tudu/Pinyin.php';
         $userInfo['pinyin'] = Tudu_Pinyin::parse($params['truename'], true);
     }
     if (!empty($params['nick'])) {
         $userInfo['nick'] = $params['nick'];
     }
     if (!empty($params['idnumber'])) {
         $userInfo['idnumber'] = $params['idnumber'];
     }
     if ($edit['password'] && !empty($params['password'])) {
         if ($daoUser->isAdmin($orgId, $userId)) {
             require_once 'Model/User/Exception.php';
             throw new Model_User_Exception('Can not modify the administrator password', self::CODE_NOT_MODIFY_PWD);
         }
         $userParam['initpassword'] = 1;
         $userInfo['password'] = $params['password'];
     }
     // 用户头像
     if (!empty($params['avatars'])) {
         $userInfo['avatartype'] = $params['avatartype'];
         $userInfo['avatars'] = $params['avatars'];
         /* @var $daoImContact Dao_Im_Contact_Contact */
         //$daoImContact = Tudu_Dao_Manager::getDao('Dao_Im_Contact_Contact', Tudu_Dao_Manager::DB_IM);
         // 需要更新im自定义联系人表的updatetime
         // im通过更新时间判断是否需要获取用户头像
         //$daoImContact->updateUser($userId . '@' . $orgId, array('updatetime' => time()));
     }
     // 更新用户数据
     if (!empty($userParam)) {
         if (!$daoUser->updateUser($orgId, $user->userId, $userParam)) {
             require_once 'Model/User/Exception.php';
             throw new Model_User_Exception('Update user failed', self::CODE_SAVE_FAILED);
         }
     }
     if (!empty($userInfo)) {
         if (!$daoUser->updateUserInfo($orgId, $user->userId, $userInfo)) {
             require_once 'Model/User/Exception.php';
             throw new Model_User_Exception('Update user info failed', self::CODE_SAVE_FAILED);
         }
     }
     // 群组
     /* @var $daoGroup Dao_Md_User_Group */
     $daoGroup = Tudu_Dao_Manager::getDao('Dao_Md_User_Group', Tudu_Dao_Manager::DB_MD);
     if ($edit['group']) {
         $groups = !empty($params['groupid']) ? $params['groupid'] : array();
         $daoUser->removeGroups($user->orgId, $user->userId);
         foreach ($groups as $groupId) {
             $daoGroup->addUser($orgId, $groupId, $userId);
         }
     }
     // 权限组
     /* @var $daoRole Dao_Md_User_Role */
     $daoRole = Tudu_Dao_Manager::getDao('Dao_Md_User_Role', Tudu_Dao_Manager::DB_MD);
     if ($edit['role']) {
         $roles = !empty($params['roleid']) ? $params['roleid'] : array();
         $daoUser->removeRoles($user->orgId, $user->userId);
         foreach ($roles as $roleId) {
             $daoRole->addUsers($orgId, $roleId, $userId);
         }
     }
     // 组织架构
     /* @var $daoCast Dao_Md_User_Cast */
     $daoCast = Tudu_Dao_Manager::getDao('Dao_Md_User_Cast', Tudu_Dao_Manager::DB_MD);
     if ($edit['cast']) {
         $castDepts = !empty($params['castdept']) ? $params['castdept'] : array();
         $castUsers = !empty($params['castuser']) ? $params['castuser'] : array();
         // 清除组织架构
         $daoCast->clear($orgId, $userId);
         // 隐藏部门
         foreach ($castDepts as $dept) {
             if (!trim($dept) || $dept == '^root' || $dept == $userParam['deptid']) {
                 continue;
             }
             $daoCast->hideDepartment($orgId, $userId, $dept);
         }
         // 隐藏用户
         foreach ($castUsers as $uId) {
             if (!$uId || $uId == $userId) {
                 continue;
             }
             $daoCast->hideUser($orgId, $userId, $uId);
         }
         // 更换部门
         if ($user->deptId != $userParam['deptid']) {
             $daoCast->updateDepartment($orgId, $userId, $userParam['deptid']);
         }
     }
     // 修改企业默认密码
     if ($edit['password'] && !empty($params['password']) && $org->defaultPassword != $params['password']) {
         $daoOrg->updateOrg($orgId, array('defaultpassword' => $params['password']));
     }
     // 发送通知,插入消息队列
     if (Tudu_Model::hasResource(Tudu_Model::RESOURCE_CONFIG)) {
         $config = Tudu_Model::getResource(Tudu_Model::RESOURCE_CONFIG);
         if ($config['httpsqs']) {
             $options = $config['httpsqs'];
             $httpsqs = new Oray_Httpsqs($options['host'], $options['port'], $options['charset'], $options['name']);
             $data = implode(' ', array(Dao_Md_Log_Oplog::MODULE_DEPT, Dao_Md_Log_Oplog::OPERATION_UPDATE, null, implode(':', array($orgId, $user->userName, $user->uniqueId, ''))));
             $httpsqs->put($data);
         }
     }
     // 添加后台操作日志
     if (!empty($params['operator']) && !empty($params['clientip'])) {
         $params['local'] = empty($params['local']) ? null : $params['local'];
         $trueName = $edit['truename'] ? $params['truename'] : $userIf->trueName;
         $this->_createLog(Dao_Md_Log_Oplog::MODULE_USER, Dao_Md_Log_Oplog::OPERATION_UPDATE, null, array('orgid' => $orgId, 'operator' => $params['operator'], 'clientip' => $params['clientip'], 'local' => $params['local']), implode(':', array($orgId, $user->userName, $user->uniqueId)), array('truename' => $trueName, 'account' => $user->userName));
     }
 }
예제 #8
0
파일: Tudu.php 프로젝트: bjtenao/tudu-web
 /**
  * 执行图度规则过滤
  *
  * 遍历所有接收人所有可用规则,并执行过滤
  * @param $params
  */
 public function filterTudu($params)
 {
     if (empty($params['tuduid']) || empty($params['tsid'])) {
         return;
     }
     $tuduId = $params['tuduid'];
     $manager = Tudu_Tudu_Manager::getInstance(Tudu_Dao_Manager::getDb(Tudu_Dao_Manager::DB_TS));
     /** @var $daoRule Dao_Td_Rule_Rule */
     $daoRule = Tudu_Dao_Manager::getDao('Dao_Td_Rule_Rule', Tudu_Dao_Manager::DB_TS);
     $users = $manager->getTuduUsers($tuduId);
     if (!$users) {
         $this->getLogger()->warn("Tudu id:{$tuduId} Users are not exists");
         return;
     }
     $tudu = $manager->getTuduById($tuduId, $users[0]['uniqueid']);
     if (null === $tudu) {
         $this->getLogger()->warn("Tudu id: {$tuduId} is not exists");
         return;
     }
     $tudu = $tudu->toArray();
     $expire = 3600 * 24;
     //定义Memcache过期时间: 一天
     // 获取接收用户规则过滤
     foreach ($users as $user) {
         $unId = $user['uniqueid'];
         $rules = $this->_memcache->loadCache(array($daoRule, 'getRulesByUniqueId'), array($unId, array('isvalid' => true)), $expire);
         if ($rules->count() <= 0) {
             continue;
         }
         foreach ($rules as $rule) {
             $filters = $rule->getFilters();
             $filterCount = $filters->count();
             $matchCount = 0;
             if ($filterCount <= 0) {
                 continue;
             }
             foreach ($filters as $filter) {
                 $contain = false;
                 switch ($filter->what) {
                     // 发起人
                     case 'from':
                         if (is_array($filter->value)) {
                             foreach ($filter->value as $item) {
                                 $item = str_replace(array('oray.com', 'tudu.com'), array('oray', ''), $item);
                                 if ($item == $tudu['from'][3]) {
                                     $contain = true;
                                     break;
                                 }
                             }
                         }
                         break;
                         // 接收人,抄送人
                     // 接收人,抄送人
                     case 'to':
                     case 'cc':
                         if (is_array($filter->value)) {
                             $count = 0;
                             $match = 0;
                             foreach ($filter->value as $item) {
                                 $count++;
                                 $item = str_replace(array('oray.com', 'tudu.com'), array('oray', ''), $item);
                                 if (isset($tudu[$filter->what][$item])) {
                                     $match++;
                                 }
                             }
                             if ($count == $match) {
                                 $contain = true;
                             }
                         }
                         break;
                     case 'subject':
                         $contain = false !== strpos($tudu['subject'], $filter->value);
                         break;
                 }
                 if ($filter->type == 'contain' && $contain || $filter->type == 'exclusive' && !$contain) {
                     $matchCount++;
                 }
             }
             // 匹配过滤条件,执行规则操作
             if ($matchCount == $filterCount) {
                 // 标签
                 if ($rule->operation == 'label') {
                     $manager->addLabel($tuduId, $unId, $rule->value);
                     // 忽略
                 } elseif ($rule->operation == 'ignore') {
                     $manager->deleteLabel($tuduId, $unId, '^i');
                     $manager->addLabel($tuduId, $unId, '^g');
                     // 星标
                 } elseif ($rule->operation == 'starred') {
                     $manager->addLabel($tuduId, $unId, '^t');
                 }
                 // 是否需要邮件提醒
                 if (!empty($rule->mailRemind)) {
                     $mailRemind = $rule->mailRemind;
                     // 邮件提醒可用且图度在指定的板块的
                     if ($mailRemind['isvalid'] && !empty($mailRemind['boards']) && !empty($mailRemind['mailbox']) && is_array($mailRemind['boards']) && in_array($tudu['boardid'], $mailRemind['boards'])) {
                         $emails = array();
                         foreach ($mailRemind['mailbox'] as $email) {
                             // 必须是邮箱
                             if (Oray_Function::isEmail($email)) {
                                 $emails[] = $email;
                             }
                         }
                         if (!empty($emails)) {
                             $remind = array('tuduid' => $tudu['tuduid'], 'tsid' => $params['tsid'], 'emails' => $emails, 'subject' => $tudu['subject'], 'sender' => $tudu['from'][0], 'lastupdate' => date('Y-m-d H:i:s', $tudu['lastposttime']), 'content' => mb_substr(strip_tags($tudu['content']), 0, 20, 'utf-8'), 'type' => $this->_typeNames[$tudu['type']], 'url' => 'http://' . $tudu['orgid'] . '.tudu.com/tudu/view?tid=' . $tudu['tuduid']);
                             $this->getLogger()->warn("Send Email notify to:" . implode(',', $emails));
                             // 发送邮件提醒请求
                             $data = implode(' ', array('send', 'email', '', http_build_query($remind)));
                             $this->_httpsqs->put($data, $this->_options['httpsqs']['names']['send']);
                         }
                     }
                 }
             }
         }
     }
     $this->getLogger()->debug("Tudu id:{$tuduId} done");
 }
예제 #9
0
 /**
  * 执行讨论数据处理
  */
 public function run()
 {
     $today = date('Y-m-d');
     foreach ($this->_dbs as $key => $db) {
         $tsId = (int) str_replace('ts', '', $key);
         // 会议提醒
         $sql = 'SELECT T.tudu_id, T.org_id, T.subject, T.from, T.start_time, M.is_allday, M.location FROM td_tudu AS T ' . 'LEFT JOIN td_tudu_meeting M ON T.tudu_id = M.tudu_id ' . 'WHERE type = \'meeting\' ' . 'AND T.is_draft = 0 ' . 'AND T.is_done = 0 ' . 'AND M.notify_time >= UNIX_TIMESTAMP() - 120 ' . 'AND M.notify_time <= UNIX_TIMESTAMP() + 60 ' . 'AND is_notified = 0';
         Tudu_Dao_Manager::setDb(Tudu_Dao_Manager::DB_TS, $db, true);
         $manager = Tudu_Tudu_Manager::getInstance();
         $meetings = $db->fetchAll($sql);
         $daoLog = Tudu_Dao_Manager::getDao('Dao_Td_Log_Log', Tudu_Dao_Manager::DB_TS);
         foreach ($meetings as $item) {
             $tuduId = $item['tudu_id'];
             $users = $db->fetchAll("SELECT accepter_info, role, is_foreign FROM td_tudu_user WHERE tudu_id = '{$tuduId}' AND role = 'to' AND tudu_status < 3");
             $flag = true;
             // 记录提醒人员
             $notifyTo = array();
             $mailTo = array();
             foreach ($users as $row) {
                 list($email, ) = explode(' ', $row['accepter_info']);
                 if (!$row['is_foreign']) {
                     $notifyTo[] = $email;
                 } else {
                     if (Oray_Function::isEmail($email)) {
                         $mailTo[] = $email;
                     }
                 }
             }
             // 发送talk提醒
             if (count($notifyTo)) {
                 $this->sendNotify($item, $notifyTo);
             }
             // 发送外部提醒(Email)
             if (count($mailTo)) {
                 $this->sendMail($tsId, $item, $mailTo);
             }
             $db->query("UPDATE td_tudu_meeting SET is_notified = 1 WHERE tudu_id = '{$tuduId}'");
             $this->getLogger()->info("Meeting id:({$tuduId}) notify success");
         }
         // 过期会议自动结束
         $sql = 'SELECT T.tudu_id, T.org_id, T.cycle_id, M.is_allday, T.end_time FROM td_tudu AS T ' . 'LEFT JOIN td_tudu_meeting M ON T.tudu_id = M.tudu_id ' . 'WHERE type = \'meeting\' ' . 'AND is_draft = 0 ' . 'AND is_done  = 0 ' . 'AND (end_time < UNIX_TIMESTAMP() OR end_time IS NULL)';
         $records = $db->fetchAll($sql);
         foreach ($records as $record) {
             $orgId = $record['org_id'];
             $tuduId = $record['tudu_id'];
             $endTime = (int) $record['end_time'];
             if ($record['is_allday'] && date('Y-m-d', $endTime) == $today) {
                 continue;
             }
             if (!$manager->updateTudu($tuduId, array('isdone' => true))) {
                 $this->getLogger()->info("Meeting id:({$tuduId}) done failure");
                 continue;
             }
             // 成功记录操作日志
             $daoLog->createLog(array('orgid' => $orgId, 'targettype' => Dao_Td_Log_Log::TYPE_TUDU, 'targetid' => $tuduId, 'uniqueid' => '^system', 'action' => Dao_Td_Log_Log::ACTION_TUDU_DONE, 'detail' => serialize(array('isdone' => true)), 'logtime' => time()));
             $users = $manager->getTuduUsers($tuduId);
             foreach ($users as $user) {
                 // 移出图度箱
                 $ret = $manager->deleteLabel($tuduId, $user['uniqueid'], '^i');
                 $ret = $manager->deleteLabel($tuduId, $user['uniqueid'], '^a');
             }
             // 周期任务
             if (!empty($record['cycle_id'])) {
                 if (!$this->cycle($tsId, $tuduId, $record['cycle_id'])) {
                     $this->getLogger()->warn("Meeting id:({$tuduId}) cycle failure");
                 }
             }
             $this->getLogger()->info("Meeting id:({$tuduId}) done success");
         }
         $this->getLogger()->info("Ts db:({$key}) process complete");
     }
 }
예제 #10
0
 /**
  * 提交保存
  *
  */
 public function saveAction()
 {
     $email = $this->_request->getPost('email');
     $daoEmail = $this->getDao('Dao_Md_User_Email');
     if (!Oray_Function::isEmail($email)) {
         return $this->json(false, '无效的email格式');
     }
     // 密码邮箱是否已被注册/修改
     $daoEmailAuth = Tudu_Dao_Manager::getDao('Dao_Reg_Email', Tudu_Dao_Manager::DB_SITE);
     /* @var $daoEmail Dao_Md_User_Email */
     $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD);
     if ($daoEmailAuth->existsEmail($email, array('orgid' => $this->_user->orgId, 'userid' => $this->_user->userId)) || $daoUser->existsEmail($email)) {
         return $this->json(false, '该邮箱已被注册');
     }
     $time = time();
     $authId = Dao_Reg_Email::getEmailAuthId($this->_user->orgId, $this->_user->userId);
     $ret = $daoEmailAuth->createEmailAuth(array('emailauthid' => $authId, 'email' => $email, 'orgid' => $this->_user->orgId, 'userid' => $this->_user->userId, 'createtime' => $time, 'expiretime' => $time + 86400 * 2));
     if (!$ret) {
         return $this->json(false, '验证邮件发送失败,请重试');
     }
     $config = $this->_options['httpsqs'];
     $key = md5($this->_user->userId . '@' . $this->_user->orgId . $authId . self::EMAIL_AUTH_KEY);
     $bind = array('url' => $this->_options['sites']['www'] . "/email/?k={$key}&i={$authId}");
     // 通过队列发送邮件
     $httpsqs = new Oray_Httpsqs($this->_options['httpsqs']['host'], $this->_options['httpsqs']['port']);
     $httpsqs->put(implode(' ', array('email', $email, serialize($bind), 0)), 'reg');
     return $this->json(true, '验证邮件发送成功', array('authid' => $authId));
 }
예제 #11
0
 /**
  * 用户联系人列表
  */
 public function listAction()
 {
     $detail = $this->_request->getQuery('detail', true);
     $contactId = trim($this->_request->getQuery('contactid'));
     // 获取指定ID的联系人
     $userIds = array();
     $contactIds = array();
     if (!empty($contactId)) {
         $arr = explode(',', $contactId);
         foreach ($arr as $item) {
             if (false !== strpos($item, '@')) {
                 $userIds[] = $item;
             } else {
                 $contactIds[] = $item;
             }
         }
     }
     $list = array();
     /*=============组织用户列表================*/
     /* @var $daoCast Dao_Md_User_Cast */
     $daoCast = Tudu_Dao_Manager::getDao('Dao_Md_User_Cast', Tudu_Dao_Manager::DB_MD);
     $condition = array('orgid' => $this->_user->orgId, 'userid' => $this->_user->userId);
     $users = $daoCast->getCastUsers($condition)->toArray('username');
     $depts = $daoCast->getCastDepartments($this->_user->orgId, $this->_user->userId)->toArray('deptid');
     if (!empty($users)) {
         $count = 0;
         foreach ($users as &$user) {
             if (!empty($contactId) && !in_array($user['username'], $userIds) || $user['username'] == 'robot@oray') {
                 continue;
             }
             $item = array('contactid' => $user['username'], 'lastupdatetime' => isset($user['lastupdatetime']) ? $user['lastupdatetime'] : null, 'avatarupdatetime' => isset($user['updatetime']) ? $user['updatetime'] : null);
             if ($detail) {
                 $deptId = $this->_getDeptRoot($user['deptid'], $depts);
                 $item['truename'] = $user['truename'];
                 $item['position'] = !empty($user['position']) ? $user['position'] : null;
                 $item['gender'] = (int) $user['gender'];
                 $item['groups'] = $deptId ? array($deptId) : array('^none');
                 $item['mobile'] = $user['mobile'];
                 $item['tel'] = $user['tel'];
                 $item['email'] = $user['username'];
                 $item['isavatars'] = $user['isavatars'];
                 $item['status'] = $user['status'];
             }
             $list[] = $item;
             //unset($user);
             $user['num'] = $count;
             $count++;
         }
     }
     /*=============用户联系人列表================*/
     /* @var $daoContact Dao_Td_Contact_Contact */
     $daoContact = Tudu_Dao_Manager::getDao('Dao_Td_Contact_Contact', Tudu_Dao_Manager::DB_TS);
     $condition = array('uniqueid' => $this->_user->uniqueid);
     $contacts = $daoContact->getContacts($condition);
     if (!empty($contacts)) {
         $contacts = $contacts->toArray();
         foreach ($contacts as &$contact) {
             if (!empty($contactId) && !in_array($contact['contactid'], $contactIds) && !in_array($contact['email'], $userIds)) {
                 continue;
             }
             if ($contact['fromuser'] || !empty($contact['email']) && !Oray_Function::isEmail($contact['email'])) {
                 /*if ($detail) {
                       $list[$users[$contact['email']]['num']]['groups'] = array_merge($list[$users[$contact['email']]['num']]['groups'], $contact['groups']);
                   }*/
                 continue;
             }
             $item = array('contactid' => $contact['contactid'], 'lastupdatetime' => !empty($contact['lastupdatetime']) ? (int) $contact['lastupdatetime'] : time(), 'avatarupdatetime' => isset($contact['lastupdatetime']) ? $contact['lastupdatetime'] : time());
             if ($detail) {
                 $properties = $contact['properties'];
                 $item['truename'] = $contact['truename'];
                 $item['position'] = !empty($contact['position']) ? $contact['position'] : null;
                 $item['gender'] = isset($properties['gender']) ? (int) $properties['gender'] : null;
                 $item['groups'] = array('^none');
                 //$contact['groups'];
                 $item['mobile'] = $contact['mobile'];
                 $item['tel'] = isset($properties['tel']) ? $properties['tel'] : null;
                 $item['email'] = $contact['email'];
                 $item['isavatars'] = $contact['isavatars'];
             }
             $list[] = $item;
             unset($contact);
         }
         unset($contacts);
     }
     $this->view->code = TuduX_OpenApi_ResponseCode::SUCCESS;
     $this->view->contacts = $list;
 }
예제 #12
0
파일: Ansync.php 프로젝트: bjtenao/tudu-web
 /**
  * 发送图度操作
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function send(Model_Tudu_Tudu &$tudu)
 {
     $object = array('tuduid' => $tudu->tuduId, 'tsid' => $this->_user->tsId, 'uniqueid' => $this->_user->uniqueId, 'orgid' => $this->_user->orgId, 'from' => $this->_user->userName, 'type' => $tudu->type, 'host' => $_SERVER['HTTP_HOST'], 'action' => $tudu->operation, 'iscreate' => !$tudu->fromTudu || $tudu->fromTudu->isDraft, 'isflow' => !!$tudu->flowId, 'parentid' => $tudu->fromTudu ? $tudu->fromTudu->parentId : $tudu->parentId, 'operator' => array('uniqueid' => $this->_user->uniqueId, 'username' => $this->_user->userName, 'truename' => $this->_user->trueName));
     if ($tudu->operation == 'review') {
         $sqsAction = 'review';
         $object['stepid'] = $tudu->fromTudu->stepId;
         $object['agree'] = $tudu->agree;
         if ($tudu->flowId) {
             $flow = $tudu->getExtension('Model_Tudu_Extension_Flow');
             if ($flow) {
                 $object['flow']['nstepid'] = $flow->currentStepId;
                 $object['flow']['flowid'] = $tudu->flowId;
                 $object['flow']['stepstatus'] = $flow->currentStepId != $tudu->fromTudu->stepId ? 1 : 0;
             }
         }
         if ($tudu->type == 'notice' && $tudu->stepId == '^end') {
             $sqsAction = 'create';
         }
     }
     $receiver = array();
     if ($tudu->reviewer) {
         $reviewers = $tudu->reviewer;
         foreach ($reviewers as $reviewer) {
             $item = array('username' => $reviewer['username'], 'truename' => $reviewer['truename']);
             if (isset($reviewer['unqiueid'])) {
                 $item['uniqueid'] = $reviewer['uniqueid'];
             }
             $receiver['reviewer'][] = $item;
         }
     } elseif ($tudu->to) {
         $to = $tudu->to;
         foreach ($to as $u) {
             if (!Oray_Function::isEmail($u['username'])) {
                 $item = array('username' => $u['username'], 'truename' => $u['truename'], 'role' => 'to', 'percent' => isset($u['percent']) ? $u['percent'] : 0, 'status' => isset($u['status']) ? $u['status'] : (empty($u['percent']) || $u['percent'] < 0 ? 0 : ($u['percent'] >= 100 ? 2 : 1)));
             } else {
                 $item = array('email' => $u['username'], 'truename' => $u['truename'], 'role' => 'to', 'percent' => isset($u['percent']) ? $u['percent'] : 0, 'status' => isset($u['status']) ? $u['status'] : (empty($u['percent']) || $u['percent'] < 0 ? 0 : ($u['percent'] >= 100 ? 2 : 1)));
             }
             $receiver['to'][] = $item;
         }
     }
     if ($tudu->cc && ($tudu->type != 'notice' || !$tudu->reviewer)) {
         $cc = $tudu->cc;
         foreach ($cc as $u) {
             if (!empty($u['groupid'])) {
                 $receiver['cc'][] = array('groupid' => $u['groupid']);
             } else {
                 $receiver['cc'][] = array('username' => $u['username'], 'truename' => $u['truename']);
             }
         }
     }
     if ($tudu->bcc) {
         $bcc = $tudu->bcc;
         foreach ($bcc as $u) {
             if ($u['groupid']) {
                 $receiver['bcc'][] = array('groupid' => $u['groupid']);
             } else {
                 $receiver['bcc'][] = array('username' => $u['username'], 'truename' => $u['truename']);
             }
         }
     }
     $object['receiver'] = $receiver;
     $error = null;
     do {
         $connection = $this->_getConnection();
         $bytes = @fwrite($connection, json_encode(array('type' => 'queue', 'data' => $object)));
         if (!$bytes) {
             $error = 'Data transfer error, posting tudu data to deliver service failed.';
             break;
         }
         $response = @fgets($connection);
         if (!$response || !($resposne = @json_decode($response, true))) {
             $error = 'Invalid response data.';
             break;
         }
     } while (false);
     if ($error) {
         require_once 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('连接发送服务器失败,请稍候重试');
     }
     // 标记发送
     Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS)->sendTudu($tudu->tuduId);
     return $response['code'] == self::CODE_SUCCESS;
 }
예제 #13
0
 /**
  * 更新规则
  */
 public function updateAction()
 {
     $post = $this->_request->getPost();
     $ruleId = $this->_request->getPost('ruleid');
     /* @var $daoRule Dao_Td_Rule_Rule */
     $daoRule = $this->getDao('Dao_Td_Rule_Rule');
     $rule = $daoRule->getRuleById($ruleId);
     if (null === $rule) {
         return $this->json(false, $this->lang['rule_not_exists']);
     }
     $params = array('operation' => $post['operation'], 'isvalid' => $post['isvalid'] ? 1 : 0);
     if (!empty($post['value'])) {
         $params['value'] = $post['value'];
     }
     // 邮件提醒部分
     if (!empty($post['mailremind'])) {
         $remind = array('isvalid' => true);
         // 邮箱
         $vowels = array(',', ';', ',', '、');
         $mailbox = str_replace($vowels, ';', $post['mailbox']);
         $mailbox = explode(';', $mailbox);
         if (count($mailbox) <= 0) {
             return $this->json(false, $this->lang['mailbox_null_tips']);
         }
         foreach ($mailbox as $key => $item) {
             if (strlen($item) <= 0) {
                 unset($mailbox[$key]);
                 continue;
             }
             if (!Oray_Function::isEmail($item)) {
                 return $this->json(false, $this->lang['invalid_mailbox_address']);
             }
         }
         $remind['mailbox'] = $mailbox;
         // 应用板块
         $boards = array();
         foreach ($post['member'] as $key) {
             $boards[] = str_replace('_', '^', $post['boardid-' . $key]);
         }
         if (!empty($boards)) {
             $remind['boards'] = $boards;
         }
         $params['mailremind'] = json_encode($remind);
     } else {
         if (!empty($rule->mailRemind)) {
             $remind = $rule->mailRemind;
             $remind['isvalid'] = false;
             $params['mailremind'] = json_encode($remind);
         }
     }
     $filterIdx = $post['filters'];
     $filters = array();
     $subject = array();
     foreach ($filterIdx as $index) {
         $item = array('ruleid' => $ruleId);
         $item['action'] = isset($post['filterid-' . $index]) ? 'update' : 'create';
         $item['filterid'] = $item['action'] == 'update' ? $post['filterid-' . $index] : Dao_Td_Rule_Rule::getFilterId();
         $item['value'] = $post['value-' . $index];
         $item['type'] = $post['type-' . $index];
         $item['isvalid'] = isset($post['isvalid-' . $index]) ? $post['isvalid-' . $index] : false;
         $item['what'] = $post['what-' . $index];
         if ($item['action'] == 'create' && !$item['isvalid'] && empty($item['value'])) {
             continue;
         }
         // 生成规则描述内容
         $strValue = null;
         switch ($item['what']) {
             case 'from':
             case 'to':
             case 'cc':
                 $array = explode("\n", $item['value']);
                 $valueStr = array();
                 foreach ($array as $user) {
                     $arr = explode(' ', $user);
                     if (isset($arr[1])) {
                         $valueStr[] = $arr[1];
                     }
                 }
                 $strValue = implode(',', $valueStr);
                 break;
             case 'subject':
             default:
                 $strValue = str_replace("\t", '', $item['value']);
                 break;
         }
         if ($item['isvalid']) {
             $subject[] = implode("\t", array($item['what'], $item['type'], $strValue));
         }
         $filters[$index] = $item;
     }
     $params['description'] = implode("\n", $subject);
     $ret = $daoRule->updateRule($ruleId, $params);
     if (!$ret) {
         return $this->json(false, $this->lang['rule_update_failure']);
     }
     foreach ($filters as $filter) {
         if ($filter['action'] == 'create') {
             $daoRule->addFilter($filter);
         } else {
             $daoRule->updateFilter($filter['filterid'], $filter);
         }
     }
     //Memcache
     $rules = $this->cache->deleteCache(array($daoRule, 'getRulesByUniqueId'), array($rule->uniqueId, array('isvalid' => true)));
     return $this->json(true, $this->lang['rule_update_success'], array('ruleid' => $ruleId));
 }