1 Star 0 Fork 6

夜雨纷飞 / p2_plan_team

forked from 焦虑的羽毛 / p2_plan_team 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
managemessage.php 17.67 KB
一键复制 编辑 原始数据 按行查看 历史
programcj 提交于 2019-12-28 20:44 . 原始文件
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
<?php
require("./init.php");
// check if user is logged in
if (!isset($_SESSION["userid"]))
{
$template->assign("loginerror", 0);
$template->display("login.tpl");
die();
}
// create message object
$msg = new message();
$objmilestone = (object) new milestone();
// get data from POST and GET
// getArrayVal will return the value from the array if present, or false if not. This way the variable is never undeclared.
$action = getArrayVal($_GET, "action");
$id = getArrayVal($_GET, "id");
$mid = getArrayVal($_GET, "mid");
$mode = getArrayVal($_GET, "mode");
$thefiles = getArrayVal($_POST, "mode");
$numfiles = getArrayVal($_POST, "numfiles");
$userfile = getArrayVal($_POST, "userfiles");
$tags = getArrayVal($_POST, "tags");
$redir = getArrayVal($_GET, "redir");
$message = getArrayVal($_POST, "text");
$title = getArrayVal($_POST, "title");
$mid_post = getArrayVal($_POST, "mid");
$text = getArrayVal($_POST, "text");
$milestone = getArrayVal($_POST, "milestone");
$project = array('ID' => $id);
$template->assign("project", $project);
$template->assign("mode", $mode);
// define the active tab in the project navigation
$classes = array("overview" => "overview", "msgs" => "msgs_active", "tasks" => "tasks", "miles" => "miles", "files" => "files", "users" => "users", "tracker" => "tracking");
$template->assign("classes", $classes);
$cloud = new tags();
$cloud->cloudlimit = 1;
$thecloud = $cloud->getTagcloud($id);
if (strlen($thecloud) > 0)
$template->assign("cloud", $thecloud);
if ($action != "mymsgs" and $action != "mymsgs-pdf")
{
// check if the user belongs to the current project. die if he/she doesn't
if (!chkproject($userid, $id))
{
$errtxt = $langfile["notyourproject"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "$errtxt<br>$noperm");
$template->display("error.tpl");
die();
}
}
if ($action == "addform")
{
// display addform
$template->display("addmessageform.tpl");
} elseif ($action == "add")
{
// check if the user is allowed to add messages
if (!$userpermissions["messages"]["add"])
{
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// format tags properly
if ($tags)
{
$tagobj = new tags();
$tags = $tagobj->formatInputTags($tags);
}
// add message
$themsg = $msg->add($id, $title, $message, $tags, $userid, $username, 0, $milestone);
if ($themsg)
{
if ($thefiles > 0)
{
// if upload files are set, upload and attach
$msg->attachFile($thefiles, $themsg);
} elseif ($thefiles == 0 and $numfiles > 0)
{
// else just attach existing file
$msg->attachFile(0, $themsg, $id);
}
if ($settings["mailnotify"])
{
$sendto = getArrayVal($_POST, "sendto");
$usr = (object) new project();
$users = $usr->getProjectMembers($id, 10000);
if ($sendto[0] == "all")
{
$sendto = $users;
$sendto = reduceArray($sendto);
} elseif ($sendto[0] == "none")
{
$sendto = array();
}
foreach($users as $user)
{
if (!empty($user["email"]))
{
if (is_array($sendto))
{
if (in_array($user["ID"], $sendto))
{
// send email
$themail = new emailer($settings);
$themail->send_mail($user["email"], $langfile["messagewasaddedsubject"], $langfile["hello"] . ",<br /><br/>" . $langfile["messagewasaddedtext"] . "<br /><br />". $message . "<br /><br /><a href = \"" . $url . "managemessage.php?action=showmessage&id=$id&mid=$themsg\">$title</a>");
}
}
else
{
// send email
$themail = new emailer($settings);
$themail->send_mail($user["email"], $langfile["messagewasaddedsubject"], $langfile["hello"] . ",<br /><br/>" . $langfile["messagewasaddedtext"] . "<br /><br />". $message . "<br /><br /><a href = \"" . $url . "managemessage.php?action=showmessage&id=$id&mid=$themsg\">$title</a>");
}
}
}
}
$loc = $url . "managemessage.php?action=showproject&id=$id&mode=added";
header("Location: $loc");
}
} elseif ($action == "editform")
{
// check if the user is allowed to edit messages
if (!$userpermissions["messages"]["edit"])
{
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// get page title from language file
$title = $langfile["editmessage"];
$template->assign("title", $title);
// get the message to edit
$message = $msg->getMessage($mid);
$template->assign("message", $message);
$template->display("editmessageform.tpl");
} elseif ($action == "edit")
{
// check if the user is allowed to edit messages
if (!$userpermissions["messages"]["edit"])
{
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
$tagobj = new tags();
$tags = $tagobj->formatInputTags($tags);
// edit the msg
if ($msg->edit($mid_post, $title, $text, $tags))
{
if ($redir)
{
$redir = $url . $redir;
header("Location: $redir");
}
else
{
$loc = $url . "managemessage.php?action=showproject&id=$id&mode=edited";
header("Location: $loc");
}
}
} elseif ($action == "del")
{
// check if the user is allowed to delete messages
if (!$userpermissions["messages"]["del"])
{
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// delete the message
if ($msg->del($mid))
{
// if a redir target is given, redirect to it. else redirect to standard target.
if ($redir)
{
echo "ok";
$redir = $url . $redir;
header("Location: $redir");
}
else
{
echo "ok";
}
}
} elseif ($action == "replyform")
{
// check if the user is allowed to add messages
if (!$userpermissions["messages"]["add"])
{
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// get page title from language file
$title = $langfile["reply"];
$template->assign("title", $title);
$myfile = new datei();
$ordner = $myfile->getProjectFiles($id, 1000);
$message = $msg->getMessage($mid);
$template->assign("message", $message);
$template->assign("files", $ordner);
$template->display("replyform.tpl");
} elseif ($action == "reply")
{
// check if the user is allowed to edit messages
if (!$userpermissions["messages"]["add"])
{
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
$tagobj = new tags();
$tags = $tagobj->formatInputTags($tags);
$themsg = $msg->add($id, $title, $message, $tags, $userid, $username, $mid_post);
if ($themsg)
{
if ($thefiles > 0)
{
$msg->attachFile($thefiles, $themsg);
} elseif ($thefiles == 0 and $numfiles > 0)
{
$msg->attachFile(0, $themsg, $id);
}
$loc = $url . "managemessage.php?action=showmessage&mid=$mid_post&id=$id&mode=replied";
header("Location: $loc");
}
} elseif ($action == "mymsgs")
{
// create new project and file objects
$project = new project();
$myfile = new datei();
// get all uof the users projects
$myprojects = $project->getMyProjects($userid);
$cou = 0;
$messages = array();
// loop through the projects and get messages and files for each project
if (!empty($myprojects))
{
foreach($myprojects as $proj)
{
$message = $msg->getProjectMessages($proj["ID"]);
$ordner = $myfile->getProjectFiles($proj["ID"], 1000);
$milestones = $objmilestone->getProjectMilestones($proj["ID"], 10000);
$myprojects[$cou]["milestones"] = $milestones;
$myprojects[$cou]["messages"] = $message;
$myprojects[$cou]["files"] = $ordner;
$cou = $cou + 1;
}
}
// print_r($myprojects);
$title = $langfile['mymessages'];
$template->assign("title", $title);
$template->assign("myprojects", $myprojects);
$template->display("mymessages.tpl");
} elseif ($action == "showproject")
{
// get all messages of this project
$messages = $msg->getProjectMessages($id);
// get project's name
$myproject = new project();
$pro = $myproject->getProject($id);
$members = $myproject->getProjectMembers($id, 10000);
$projectname = $pro['name'];
$template->assign("projectname", $projectname);
// get the page title
$title = $langfile['messages'];
$template->assign("title", $title);
if (!empty($messages))
{
$mcount = count($messages);
}
else
{
$mcount = 0;
}
// get files of the project
$datei = new datei();
$thefiles = $datei->getProjectFiles($id);
$milestones = $objmilestone->getAllProjectMilestones($id, 10000);
$template->assign("milestones", $milestones);
$template->assign("projectname", $projectname);
$template->assign("files", $thefiles);
$template->assign("messages", $messages);
$template->assign("members", $members);
$template->assign("messagenum", $mcount);
$template->display("projectmessages.tpl");
} elseif ($action == "showmessage")
{
// get the message and it's replies
$message = $msg->getMessage($mid);
$replies = $msg->getReplies($mid);
$myproject = new project();
$pro = $myproject->getProject($id);
$myfile = new datei();
$ordner = $myfile->getProjectFiles($id);
$projectname = $pro['name'];
$title = $langfile['message'];
$template->assign("projectname", $projectname);
$template->assign("title", $title);
$template->assign("mode", $mode);
$template->assign("message", $message);
$template->assign("ordner", $ordner);
$template->assign("replies", $replies);
$template->display("message.tpl");
} elseif ($action == "export-project")
{
$l = Array();
$l['a_meta_charset'] = 'UTF-8';
$l['a_meta_dir'] = 'ltr';
$l['a_meta_language'] = 'en';
// TRANSLATIONS --------------------------------------
$l['w_page'] = 'page';
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_DATA, '', 20));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', 8));
$pdf->SetHeaderMargin(0);
$pdf->SetFont(PDF_FONT_NAME_DATA, "", 11);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$pdf->setLanguageArray($l);
$pdf->AliasNbPages();
$pdf->AddPage();
// check if the user is allowed to edit messages
if (!$userpermissions["messages"]["add"])
{
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// get all messages of this project
$messages = $msg->getProjectMessages($id);
// get project's name
$myproject = new project();
$pro = $myproject->getProject($id);
$projectname = $pro['name'];
$template->assign("projectname", $projectname);
// get the page title
$title = $langfile['messages'];
if (!empty($messages))
{
$mcount = count($messages);
}
else
{
$mcount = 0;
}
$htmltable = "<h1>$projectname / $langfile[messages]</h1><table border=\"1\" bordercolor = \"#d9dee8\" >";
if (!empty($messages))
{
foreach($messages as $message)
{
$htmltable .= "
<tr bgcolor=\"#d9dee8\" style=\"font-weight:bold;\">
<th align=\"left\">$langfile[message]: $message[title] $langfile[by]: $message[username] ($message[postdate])</th>
</tr>
<tr><td >$message[text]</td></tr>
";
}
} else {
$htmltable .= "
<tr><td >$langfile[none] $langfile[messages]</td></tr>
";
}
$pdf->writeHTML($htmltable, true, 0, true, 0);
$pdf->Output("project-$id-messages.pdf", "D");
} elseif ($action == "export-single")
{
$l = Array();
$l['a_meta_charset'] = 'UTF-8';
$l['a_meta_dir'] = 'ltr';
$l['a_meta_language'] = 'en';
// TRANSLATIONS --------------------------------------
$l['w_page'] = 'page';
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_DATA, '', 20));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', 8));
$pdf->SetHeaderMargin(0);
$pdf->SetFont(PDF_FONT_NAME_DATA, "", 11);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$pdf->setLanguageArray($l);
$pdf->AliasNbPages();
$pdf->AddPage();
// check if the user is allowed to edit messages
if (!$userpermissions["messages"]["add"])
{
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// get all messages of this project
$message = $msg->getMessage($mid);
// get project's name
$myproject = new project();
$pro = $myproject->getProject($id);
$projectname = $pro['name'];
$template->assign("projectname", $projectname);
// get the page title
$title = $langfile['messages'];
$htmltable = "<h1>$message[title]</h1><table border=\"1\" bordercolor = \"#d9dee8\" >
<tr bgcolor=\"#d9dee8\" style=\"font-weight:bold;\">
<th align=\"left\">$langfile[project]: $projectname - $langfile[by]: $message[username] ($message[endstring])</th>
</tr>
<tr><td >$message[text]</td></tr></table>";
$pdf->writeHTML($htmltable, true, 0, true, 0);
$pdf->Output("message$mid.pdf", "D");
} elseif ($action == "mymsgs-pdf")
{
$l = Array();
$l['a_meta_charset'] = 'UTF-8';
$l['a_meta_dir'] = 'ltr';
$l['a_meta_language'] = 'en';
$l['w_page'] = 'page';
// set some PDF options
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
$title = $langfile['mymessages'];
$pdf->SetHeaderData("", 0, "" , $title);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_DATA, '', 20));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', 8));
$pdf->SetHeaderMargin(0);
$pdf->SetFont(PDF_FONT_NAME_DATA, "", 11);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$pdf->setLanguageArray($l);
$pdf->AliasNbPages();
$pdf->AddPage();
// check if the user is allowed to edit messages
if (!$userpermissions["messages"]["add"])
{
$errtxt = $langfile["nopermission"];
$noperm = $langfile["accessdenied"];
$template->assign("errortext", "<h2>$errtxt</h2><br>$noperm");
$template->display("error.tpl");
die();
}
// get all messages of this project
$messages = $msg->getProjectMessages($id);
// get project's name
$myproject = new project();
$pro = $myproject->getProject($id);
$projectname = $pro['name'];
$template->assign("projectname", $projectname);
// get the page title
// create new project and file objects
$project = new project();
$myfile = new datei();
// get all uof the users projects
$myprojects = $project->getMyProjects($userid);
$cou = 0;
$messages = array();
// loop through the projects and get messages and files for each project
if (!empty($myprojects))
{
foreach($myprojects as $proj)
{
$message = $msg->getProjectMessages($proj["ID"]);
array_push($messages, $message);
}
}
// flatten array
$messages = reduceArray($messages);
if (!empty($messages))
{
$mcount = count($messages);
}
else
{
$mcount = 0;
}
// construct html table for pdf export
$htmltable = "<table border=\"1\" bordercolor = \"#d9dee8\" >";
if (!empty($messages))
{
foreach($messages as $message)
{
$htmltable .= "
<tr bgcolor=\"#d9dee8\" style=\"font-weight:bold;\">
<th align=\"left\">$langfile[message]: $message[title] $langfile[by]: $message[username] ($message[postdate])</th>
</tr>
<tr><td >$message[text]</td></tr>
";
}
} else {
$htmltable .= "
<tr><td >$langfile[none] $langfile[messages]</td></tr>
";
}
$htmltable .= "</table>";
// write it to PDF
$pdf->writeHTML($htmltable, true, 0, true, 0);
$pdf->Output("mymessages-$id.pdf", "D");
}
?>
PHP
1
https://gitee.com/xuganlin/p2_plan_team.git
git@gitee.com:xuganlin/p2_plan_team.git
xuganlin
p2_plan_team
p2_plan_team
1.4

搜索帮助