public function updateAction(Request $request) { $user = $this->get('security.context')->getToken()->getUser(); $circleid = $request->get("id"); $da = $this->get("we_data_access"); $da_im = $this->get('we_data_access_im'); $session = $this->get('session'); $filename120 = $session->get("circle_filename120"); $filename48 = $session->get("circle_filename48"); $filename24 = $session->get("circle_filename24"); $im_sender = $this->container->getParameter('im_sender'); /* $dm = $this->get('doctrine.odm.mongodb.document_manager'); if (!empty($filename120)) $filename120= $this->saveFile($filename120,$dm); if (!empty($filename48)) $filename48= $this->saveFile($filename48,$dm); if (!empty($filename24)) $filename24=$this->saveFile($filename24,$dm); $session->remove("avatar_big"); $session->remove("avatar_middle"); $session->remove("avatar_small"); */ $fileid = ""; $fafa_groupid = ""; //判断是添加还是修改 $table = $da->GetData("circle", "select circle_id,logo_path,logo_path_small,logo_path_big,fafa_groupid from we_circle where manager=? and circle_id=?", array((string) $user->getUserName(), (string) $circleid)); if ($table && $table["circle"]["recordcount"] == 0) { $circleid = 0; } else { $fafa_groupid = $table["circle"]["rows"][0]["fafa_groupid"]; } //判断是否能创建圈子 $ec = new \Justsy\BaseBundle\Management\EnoParamManager($da, $this->get('logger')); if ($ec->IsBeyondCreateCircle($user->getUserName())) { return $this->render('JustsyBaseBundle:login:index.html.twig', array('name' => 'err')); } if (!empty($filename120)) { if ($table && $table["circle"]["recordcount"] > 0) { $this->removeFile($table["circle"]["rows"][0]["logo_path"], $dm); $this->removeFile($table["circle"]["rows"][0]["logo_path_small"], $dm); $this->removeFile($table["circle"]["rows"][0]["logo_path_big"], $dm); } } $classify = $session->get("classify"); //$classify_childer = $session->get("classify-childer"); $classify_childer = $request->get("classify-childer"); //对数据的操作 $sqls = ""; $paras = ""; if ($circleid == 0) { $circle_id = (string) SysSeq::GetSeqNextValue($da, "we_circle", "circle_id"); $fafa_groupid = SysSeq::GetSeqNextValue($da_im, "im_group", "groupid"); $network = $circle_id; $sqls = array("insert into we_circle(circle_id,circle_name,circle_desc,logo_path,logo_path_big,logo_path_small,create_staff,create_date,manager,join_method,network_domain,allow_copy,circle_class_id,fafa_groupid)value(?,?,?,?,?,?,?,now(),?,?,?,?,?,?)", "insert into we_circle_staff(circle_id,login_account,nick_name)values(?,?,?)"); $paras = array(array((string) $circle_id, (string) $request->get("txtcircle"), (string) $request->get("txtdesc"), (string) $filename48, (string) $filename120, (string) $filename24, (string) $user->getUsername(), (string) $user->getUsername(), (string) $request->get("radjoin"), $network, (string) $request->get("radcopy"), (string) $classify_childer, (string) $fafa_groupid), array((string) $circle_id, (string) $user->getUsername(), (string) $user->nick_name)); } else { if (!empty($filename120)) { $sqls = "update we_circle set circle_name=?,circle_desc=?,logo_path=?,logo_path_big=?,logo_path_small=?,join_method=?,allow_copy=?,circle_class_id=? where circle_id=?"; $paras = array((string) $request->get("txtcircle"), (string) $request->get("txtdesc"), (string) $filename48, (string) $filename120, (string) $filename24, (string) $request->get("radjoin"), (string) $request->get("radcopy"), (string) $circleid, (string) $classify_childer); } else { $sqls = "update we_circle set circle_name=?,circle_desc=?,join_method=?,allow_copy=?,circle_class_id=? where circle_id=?"; $paras = array((string) $request->get("txtcircle"), (string) $request->get("txtdesc"), (string) $request->get("radjoin"), (string) $request->get("radcopy"), (string) $circleid, (string) $classify_childer); } $circle_id = $circleid; } try { if ($circleid == 0) { $da->ExecSQLs($sqls, $paras); //创建文档根目录 $docCtl = new \Justsy\BaseBundle\Controller\DocumentMgrController(); $docCtl->setContainer($this->container); if ($docCtl->createDir("c" . $circle_id, "", $request->get("txtcircle"), $circle_id) > 0) { $docCtl->saveShare("c" . $circle_id, "0", $circle_id, "c", "w"); //将圈子目录共享给该圈子成员 } } else { $da->ExecSQL($sqls, $paras); } //给创建者发送创建群组成功出席 Utils::sendImPresence($im_sender, $user->fafa_jid, "creategroup", json_encode(array("groupid" => $fafa_groupid, "groupname" => $request->get("txtcircle"))), $this->container, "", "", false, Utils::$systemmessage_code); //发送邀请邮件 $circleId = $circle_id; $circleName = $request->get("txtcircle"); $invitedmemebers = $request->get('invitedmemebers'); if (!empty($invitedmemebers)) { $user = $this->get('security.context')->getToken()->getUser(); $invInfo = array('inv_send_acc' => $user->getUsername(), 'inv_recv_acc' => '', 'eno' => '', 'inv_rela' => '', 'inv_title' => '', 'inv_content' => '', 'active_addr' => ''); $invitedmemebersLst = explode(";", $invitedmemebers); foreach ($invitedmemebersLst as $key => $value) { $invacc = trim($value); if (empty($invacc)) { continue; } $invInfo['inv_recv_acc'] = $invacc; $sql = "select eno,fafa_jid from we_staff where login_account=?"; $ds = $da->GetData("we_staff", $sql, array((string) $invacc)); //帐号存在 if ($ds && $ds['we_staff']['recordcount'] > 0) { //1.帐号存在,直接加入圈子 //受邀人员帐号,圈子id,邀请人帐号 $encode = DES::encrypt("{$invacc},{$circleId}," . $user->getUsername()); $activeurl = $this->generateUrl("JustsyBaseBundle_invite_agreejoincircle", array('para' => $encode), true); $rejectactiveurl = $this->generateUrl("JustsyBaseBundle_invite_refuse", array('para' => $encode), true); $txt = $this->renderView('JustsyBaseBundle:Invite:circle_invitation_msg.html.twig', array("ename" => $user->ename, "nick_name" => $user->nick_name, "activeurl" => $activeurl, 'circle_name' => $circleName, 'invMsg' => '', 'staff' => array())); $invInfo['eno'] = "c{$circleId}"; $invInfo['inv_title'] = "邀请加入圈子【" . Utils::makeCircleTipHTMLTag($circleid == 0 ? $circle_id : $circleid, $circleName) . "】"; $invInfo['inv_content'] = ''; $invInfo['active_addr'] = $activeurl; //保存邀请信息 InviteController::saveWeInvInfo($da, $invInfo); //发送即时消息 $fafa_jid = $ds['we_staff']['rows'][0]['fafa_jid']; $message = Utils::makeHTMLElementTag('employee', $user->fafa_jid, $user->nick_name) . "邀请您加入圈子【" . Utils::makeHTMLElementTag('circle', $fafa_groupid, $circleName) . "】"; $buttons = array(); $buttons[] = array("text" => "拒绝", "code" => "agree", "value" => "0", "link" => $rejectactiveurl); $buttons[] = array("text" => "立即加入", "code" => "agree", "value" => "1", "link" => $activeurl); Utils::sendImMessage($im_sender, $fafa_jid, "邀请加入圈子", $message, $this->container, "", Utils::makeBusButton($buttons), false, Utils::$systemmessage_code); } else { //2.帐号不存在 $tmp = explode("@", $invacc); $tmp = count($tmp) > 1 ? $tmp[1] : 'fafatime.com'; $sql = "select count(1) as cnt from we_public_domain where domain_name=?"; $ds = $da->GetData("we_public_domain", $sql, array((string) $tmp)); if ($ds && $ds['we_public_domain']['rows'][0]['cnt'] == 0) { //2.1企业邮箱 $sql = "select eno from we_enterprise where edomain=?"; $ds = $da->GetData("we_enterprise", $sql, array((string) $tmp)); if ($ds && $ds['we_enterprise']['recordcount'] > 0) { //2.1.1企业已创建 帐号,圈子id,企业edomain des encode $eno = $ds['we_enterprise']['rows'][0]['eno']; $encode = DES::encrypt($user->getUsername() . ",{$circleId},{$eno}"); $activeurl = $this->generateUrl("JustsyBaseBundle_active_inv_s1", array('account' => DES::encrypt($invacc), 'invacc' => $encode), true); } else { //2.1.2企业未创建 $sql = "insert into we_register (login_account,ename,credential_path,active_code,ip,email_type,first_reg_date,last_reg_date,register_date,state_id)" . " values (?,?,?,?,?,?,now(),now(),now(),'0')"; $para = array($invacc, '', '', strtoupper(substr(uniqid(), 3, 10)), $_SERVER['REMOTE_ADDR'], '1'); $da->ExecSQL($sql, $para); //发送邮件 帐号,圈子id,邀请发送者帐号,邀请人企业名 des encode $encode = DES::encrypt("{$invacc},{$circleId}," . $user->getUserName() . "," . $user->ename); $activeurl = $this->generateUrl("JustsyBaseBundle_active_reg_s1", array('account' => $encode), true); } //保存邀请信息 circleid保存到eno字段,以字母'c'开头 $invInfo['eno'] = "c{$circleId}"; $title = $user->nick_name . " 邀请您加入 " . Utils::makeCircleTipHTMLTag($circleid == 0 ? $circle_id : $circleid, $circleName) . " 协作网络"; $txt = $this->renderView('JustsyBaseBundle:Invite:circle_invitation.html.twig', array("ename" => $user->ename, "nick_name" => $user->nick_name, "activeurl" => $activeurl, 'circle_name' => $circleName, 'invMsg' => '', 'staff' => array())); $invInfo['inv_title'] = $title; $invInfo['inv_content'] = $txt; $invInfo['active_addr'] = $activeurl; InviteController::saveWeInvInfo($da, $invInfo); Utils::saveMail($da, $user->getUsername(), $invacc, $title, $txt, $invInfo['eno']); //Utils::sendMail($this->get('mailer'),$title,$this->container->getParameter('mailer_user'),null,$invacc,$txt); } else { //公共邮箱 $sql = "insert into we_register (login_account,ename,credential_path,active_code,ip,email_type,first_reg_date,last_reg_date,register_date,state_id) " . "select ?,'','','" . strtoupper(substr(uniqid(), 3, 10)) . "','" . $_SERVER['REMOTE_ADDR'] . "','0',now(),now(),now(),'2' from dual " . "where not exists (select 1 from we_register where login_account=?)"; $para = array($invacc, $invacc); $da->ExecSQL($sql, $para); //发送邮件 帐号,圈子id,邀请发送者帐号,邀请人企业名 des encode $encode = DES::encrypt("{$invacc},{$circleId}," . $user->getUserName() . "," . $user->ename); $activeurl = $this->generateUrl("JustsyBaseBundle_active_reg_s1", array('account' => $encode), true); $invInfo['eno'] = "c{$circleId}"; $title = $user->nick_name . " 邀请您加入 " . Utils::makeCircleTipHTMLTag($circleid == 0 ? $circle_id : $circleid, $circleName) . " 协作网络"; $txt = $this->renderView('JustsyBaseBundle:Invite:circle_invitation.html.twig', array("ename" => $user->ename, "nick_name" => $user->nick_name, "activeurl" => $activeurl, 'circle_name' => $circleName, 'invMsg' => '', 'staff' => array())); //保存邀请信息 $invInfo['inv_title'] = $title; $invInfo['inv_content'] = $txt; $invInfo['active_addr'] = $activeurl; InviteController::saveWeInvInfo($da, $invInfo); Utils::saveMail($da, $user->getUsername(), $invacc, $title, $txt, $invInfo['eno']); //Utils::sendMail($this->get('mailer'),$title,$this->container->getParameter('mailer_user'),null,$invacc,$txt); } } } } return $this->redirect($this->generateUrl("JustsyBaseBundle_enterprise", array('network_domain' => $circle_id), true)); } catch (Exception $e) { return $this->render('JustsyBaseBundle:login:index.html.twig', array('name' => 'err')); } }
public function createcircleAction() { $re = array("returncode" => ReturnCode::$SUCCESS); $user = $this->get('security.context')->getToken()->getUser(); $request = $this->getRequest(); $circlename = $request->get("circle_name"); $circledesc = $request->get("circle_desc"); $joinmethod = $request->get("join_method", "0"); $allowcopy = $request->get("allow_copy", "0"); $circleclassid = $request->get("circle_class_id"); $invitedmemebers = $request->get("invitedmemebers"); $logo_path = $request->get("logo_path"); $logo_path_small = $request->get("logo_path_small"); $logo_path_big = $request->get("logo_path_big"); $da = $this->get('we_data_access'); $da_im = $this->get('we_data_access_im'); try { if (empty($circlename) || empty($circleclassid)) { $re["returncode"] = ReturnCode::$SYSERROR; $re["error"] = "参数传递错误!"; $response = new Response($request->get('jsoncallback') ? $request->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re)); $response->headers->set('Content-Type', 'text/json'); return $response; } if (!$this->hasCircle($da, $circlename)) { $ec = new \Justsy\BaseBundle\Management\EnoParamManager($da, $this->get('logger')); if ($ec->IsBeyondCreateCircle($user->getUserName())) { $re["returncode"] = ReturnCode::$SYSERROR; $re["error"] = "创建圈子数量已超过限制!"; } else { $circle_id = (string) SysSeq::GetSeqNextValue($da, "we_circle", "circle_id"); //创建圈子不再同步创建群组 //liling 2015-1-18 $fafa_groupid = ""; // SysSeq::GetSeqNextValue($da_im,"im_group","groupid"); $network = $circle_id; $sqls = array("insert into we_circle(circle_id,circle_name,circle_desc,logo_path,logo_path_big,logo_path_small,create_staff,create_date,manager,join_method,network_domain,allow_copy,circle_class_id,fafa_groupid)value(?,?,?,?,?,?,?,now(),?,?,?,?,?,?)", "insert into we_circle_staff(circle_id,login_account,nick_name)values(?,?,?)"); $paras = array(array((string) $circle_id, (string) $circlename, (string) $circledesc, (string) $logo_path, (string) $logo_path_big, (string) $logo_path_small, (string) $user->getUsername(), (string) $user->getUsername(), (string) $joinmethod, $network, (string) $allowcopy, (string) $circleclassid, (string) $fafa_groupid), array((string) $circle_id, (string) $user->getUsername(), (string) $user->nick_name)); $da->ExecSQLs($sqls, $paras); //创建文档根目录 $docCtl = new \Justsy\BaseBundle\Controller\DocumentMgrController(); $docCtl->setContainer($this->container); if ($docCtl->createDir("c" . $circle_id, "", $circlename, $circle_id) > 0) { $docCtl->saveShare("c" . $circle_id, "0", $circle_id, "c", "w"); //将圈子目录共享给该圈子成员 } //给创建者发送创建群组成功出席 //Utils::sendImPresence($user->fafa_jid,$user->fafa_jid,"creategroup",json_encode(array("groupid"=> $fafa_groupid,"groupname"=> $circlename)),$this->container,"","",false,Utils::$systemmessage_code); //发送邀请邮件 if (!empty($invitedmemebers)) { $user = $this->get('security.context')->getToken()->getUser(); $invInfo = array('inv_send_acc' => $user->getUsername(), 'inv_recv_acc' => '', 'eno' => '', 'inv_rela' => '', 'inv_title' => '', 'inv_content' => '', 'active_addr' => ''); $invitedmemebers = str_replace(";", ";", $invitedmemebers); $invitedmemebersLst = explode(";", $invitedmemebers); foreach ($invitedmemebersLst as $key => $value) { $invacc = trim($value); if (empty($invacc)) { continue; } $invInfo['inv_recv_acc'] = $invacc; $sql = "select eno,fafa_jid from we_staff where login_account=?"; $ds = $da->GetData("we_staff", $sql, array((string) $invacc)); //帐号存在 if ($ds && $ds['we_staff']['recordcount'] > 0) { //1.帐号存在,直接加入圈子 //受邀人员帐号,圈子id,邀请人帐号 $encode = DES::encrypt("{$invacc},{$circle_id}," . $user->getUsername()); $activeurl = $this->generateUrl("JustsyBaseBundle_invite_agreejoincircle", array('para' => $encode), true); $rejectactiveurl = $this->generateUrl("JustsyBaseBundle_invite_refuse", array('para' => $encode), true); $txt = $this->renderView('JustsyBaseBundle:Invite:circle_invitation_msg.html.twig', array("ename" => $user->ename, "nick_name" => $user->nick_name, "activeurl" => $activeurl, 'circle_name' => $circlename, 'invMsg' => '', 'staff' => array())); $invInfo['eno'] = "c{$circle_id}"; $invInfo['inv_title'] = "邀请加入圈子【" . Utils::makeCircleTipHTMLTag($circle_id, $circlename) . "】"; $invInfo['inv_content'] = ''; $invInfo['active_addr'] = $activeurl; //保存邀请信息 InviteController::saveWeInvInfo($da, $invInfo); //发送即时消息 $fafa_jid = $ds['we_staff']['rows'][0]['fafa_jid']; $message = Utils::makeHTMLElementTag('employee', $user->fafa_jid, $user->nick_name) . "邀请您加入圈子【" . Utils::makeHTMLElementTag('circle', $fafa_groupid, $circlename) . "】"; $buttons = array(); $buttons[] = array("text" => "拒绝", "code" => "agree", "value" => "0", "link" => $rejectactiveurl); $buttons[] = array("text" => "立即加入", "code" => "agree", "value" => "1", "link" => $activeurl); Utils::sendImMessage($im_sender, $fafa_jid, "邀请加入圈子", $message, $this->container, "", Utils::makeBusButton($buttons), false, Utils::$systemmessage_code); } else { //2.帐号不存在 $tmp = explode("@", $invacc); $tmp = count($tmp) > 1 ? $tmp[1] : 'fafatime.com'; $sql = "select count(1) as cnt from we_public_domain where domain_name=?"; $ds = $da->GetData("we_public_domain", $sql, array((string) $tmp)); if ($ds && $ds['we_public_domain']['rows'][0]['cnt'] == 0) { //2.1企业邮箱 $sql = "select eno from we_enterprise where edomain=?"; $ds = $da->GetData("we_enterprise", $sql, array((string) $tmp)); if ($ds && $ds['we_enterprise']['recordcount'] > 0) { //2.1.1企业已创建 帐号,圈子id,企业edomain des encode $eno = $ds['we_enterprise']['rows'][0]['eno']; $encode = DES::encrypt($user->getUsername() . ",{$circle_id},{$eno}"); $activeurl = $this->generateUrl("JustsyBaseBundle_active_inv_s1", array('account' => DES::encrypt($invacc), 'invacc' => $encode), true); } else { //2.1.2企业未创建 $sql = "insert into we_register (login_account,ename,credential_path,active_code,ip,email_type,first_reg_date,last_reg_date,register_date,state_id)" . " values (?,?,?,?,?,?,now(),now(),now(),'0')"; $para = array($invacc, '', '', strtoupper(substr(uniqid(), 3, 10)), $_SERVER['REMOTE_ADDR'], '1'); $da->ExecSQL($sql, $para); //发送邮件 帐号,圈子id,邀请发送者帐号,邀请人企业名 des encode $encode = DES::encrypt("{$invacc},{$circle_id}," . $user->getUserName() . "," . $user->ename); $activeurl = $this->generateUrl("JustsyBaseBundle_active_reg_s1", array('account' => $encode), true); } //保存邀请信息 circleid保存到eno字段,以字母'c'开头 $invInfo['eno'] = "c{$circle_id}"; $title = $user->nick_name . " 邀请您加入 " . Utils::makeCircleTipHTMLTag($circle_id, $circlename) . " 协作网络"; $txt = $this->renderView('JustsyBaseBundle:Invite:circle_invitation.html.twig', array("ename" => $user->ename, "nick_name" => $user->nick_name, "activeurl" => $activeurl, 'circle_name' => $circlename, 'invMsg' => '', 'staff' => array())); $invInfo['inv_title'] = $title; $invInfo['inv_content'] = $txt; $invInfo['active_addr'] = $activeurl; InviteController::saveWeInvInfo($da, $invInfo); Utils::saveMail($da, $user->getUsername(), $invacc, $title, $txt, $invInfo['eno']); } else { //公共邮箱 $sql = "insert into we_register (login_account,ename,credential_path,active_code,ip,email_type,first_reg_date,last_reg_date,register_date,state_id) " . "select ?,'','','" . strtoupper(substr(uniqid(), 3, 10)) . "','" . $_SERVER['REMOTE_ADDR'] . "','0',now(),now(),now(),'2' from dual " . "where not exists (select 1 from we_register where login_account=?)"; $para = array($invacc, $invacc); $da->ExecSQL($sql, $para); //发送邮件 帐号,圈子id,邀请发送者帐号,邀请人企业名 des encode $encode = DES::encrypt("{$invacc},{$circle_id}," . $user->getUserName() . "," . $user->ename); $activeurl = $this->generateUrl("JustsyBaseBundle_active_reg_s1", array('account' => $encode), true); $invInfo['eno'] = "c{$circle_id}"; $title = $user->nick_name . " 邀请您加入 " . Utils::makeCircleTipHTMLTag($circle_id, $circlename) . " 协作网络"; $txt = $this->renderView('JustsyBaseBundle:Invite:circle_invitation.html.twig', array("ename" => $user->ename, "nick_name" => $user->nick_name, "activeurl" => $activeurl, 'circle_name' => $circlename, 'invMsg' => '', 'staff' => array())); //保存邀请信息 $invInfo['inv_title'] = $title; $invInfo['inv_content'] = $txt; $invInfo['active_addr'] = $activeurl; InviteController::saveWeInvInfo($da, $invInfo); Utils::saveMail($da, $user->getUsername(), $invacc, $title, $txt, $invInfo['eno']); } } } } $re["circle"] = $this->getCricle($da, $circle_id); } } else { $re["returncode"] = ReturnCode::$SYSERROR; $re["error"] = "圈子名称已存在!"; } } catch (\Exception $e) { $re["returncode"] = ReturnCode::$SYSERROR; $re["error"] = "系统错误,创建圈子失败!"; $this->get('logger')->err($e); } $response = new Response($request->get('jsoncallback') ? $request->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re)); $response->headers->set('Content-Type', 'text/json'); return $response; }