管理員可以手動建立選單,從LDAP服務器中選擇個別部門名單,並且可以選取多筆收件人和副本、密件副本,並且使用預設郵件客戶端寄出。 共有三個檔案: ldap.Html 純粹的框架檔。 ldap.PHP 使用選單,經由php 來取得郵件地址,並建立javascript選單。 select.html 從ldap.php 獲取選擇項目,並建立一個連結,讓郵件客戶端取用。 剪剪貼貼來的。由於部份程序代碼來自 Squirrel Mail,本程序為 GPL。功力不佳,請高手好好修改一番吧。 icon_redface.gif ldap.html(不需修改) 代碼: <html> <head><title>Java Script LDAP Addressbook</title></head> <frameset rows="*,130"> <frame src="ldap.php" name="fr1"> <frame src="select.html" name="fr2"> </frameset> </html> ldap.php(請修改ldap服務器連結、部門清單和搜尋基礎的部份,以符合您的需求。) ※特別說明,我們公司的搜尋是以lastname 為基礎。並不是以部門區分。請自行修改以符合需求。 代碼: <h3>自由原始碼公司通訊簿查詢</h3> <Script language="javascript"> function to_addr($addr) { var prefix = ""; var pwintype = typeof parent.fr2.document.selectaddr; $addr = $addr.replace(/ {1,35}$/, ""); if (pwintype != "undefined") { if (parent.fr2.document.selectaddr.toaddr.value) { prefix = ", "; parent.fr2.document.selectaddr.toaddr.value = parent.fr2.document.selectaddr.toaddr.value + ", " + $addr; } else { parent.fr2.document.selectaddr.toaddr.value = $addr; } } } function cc_addr($addr) { var prefix = ""; var pwintype = typeof parent.fr2.document.selectaddr; $addr = $addr.replace(/ {1,35}$/, ""); if (pwintype != "undefined") { if (parent.fr2.document.selectaddr.ccaddr.value) { prefix = ", "; parent.fr2.document.selectaddr.ccaddr.value = parent.fr2.document.selectaddr.ccaddr.value + ", " + $addr; } else { parent.fr2.document.selectaddr.ccaddr.value = $addr; } } } function bcc_addr($addr) { var prefix = ""; var pwintype = typeof parent.fr2.document.selectaddr; $addr = $addr.replace(/ {1,35}$/, ""); if (pwintype != "undefined") { if (parent.fr2.document.selectaddr.bccaddr.value) { prefix = ", "; parent.fr2.document.selectaddr.bccaddr.value = parent.fr2.document.selectaddr.bccaddr.value + ", " + $addr; } else { parent.fr2.document.selectaddr.bccaddr.value = $addr; } } } </Script> <form method="post" action=ldap.php?$query> <SELECT NAME="query" SIZE="1" onChange="submit();"> <OPTION VLAUE="" SELECTED> <OPTION VALUE=01*>01研發部 <OPTION VALUE=02*>02行政部 <OPTION VALUE=03*>03品保部 <OPTION VALUE=*>全部列出 </SELECT> </form> <?php // basic sequence with LDAP is connect, bind, search, interpret search // result, close connection $ds=ldap_connect("localhost"); // must be a valid LDAP server! //echo "connect result is ".$ds."<p>"; if (empty($query)) { echo "請從下拉式選單中選擇欲查詢部門"; } else { if ($ds) { // echo "Binding ..."; $r=ldap_bind($ds); // this is an "anonymous" bind, typically // read-only Access // echo "Bind result is ".$r."<p>"; echo "搜尋 $query .... "; // Search surname entry $sr=ldap_search($ds,"o=oss, c=tw", "cn=$query"); // echo "搜尋結果 ".$sr."<p>"; echo "總共 ".ldap_count_entries($ds,$sr)."筆<p>"; echo "取得資料 ...<p>"; $info = ldap_get_entries($ds, $sr); // echo "Data for ".$info["count"]." items returned:<p>"; echo "<table border=black>"; echo "<th>姓名<th>E-mail<th>收件者<th>副本<th>密件副本"; for ($i=0; $i<$info["count"]; $i++) { echo "<tr><td width=180>" . $info[$i]["cn"][0] . "<td>" . '<a href=mailto:' . $info[$i]["mail"][0].'>'. $info[$i]["mail"][0]."</a>"; echo "<td>" . '<a href=javascript:to_addr(\'' . $info[$i]["mail"][0].'\');>'.'收件者'."</a><br>"; echo "<td>" . '<a href=javascript:cc_addr(\'' . $info[$i]["mail"][0].'\');>'.'副本'."</a><br>"; echo "<td>" . '<a href=javascript:bcc_addr(\'' . $info[$i]["mail"][0].'\');>'.'密件副本'."</a><br>"; } echo "</table>"; echo "<br>"; echo "查詢結束"; ldap_close($ds); } else { echo "<h4>無法連結 LDAP 服務器,請洽MIS</h4>"; } } ?> select.html(不需修改) 代碼: <html> <head> <Script language="javascript"> function generate() { var to_total=document.selectaddr.toaddr.value; var cc_total=document.selectaddr.ccaddr.value; var bcc_total=document.selectaddr.bccaddr.value; document.write("<p align=center><a href=\"mailto:" + document.selectaddr.toaddr.value + "?cc=" + document.selectaddr.ccaddr.value + "&bcc=" + document.selectaddr.bccaddr.value +"\">寄出郵件</a><br><br><a href=\"javascript:history.go(-1)\">回上一頁</a>"); } function cleartoaddr() { document.selectaddr.toaddr.value = ""; } </script> </head> <body> <form name="selectaddr"> <table> <tr><td>收件者:<td><input type="text" name=toaddr size="100"><td></td></tr> <tr><td>副本:<td><input type="text" name=ccaddr size="100"></td></tr> <tr><td>密件副本:<td><input type="text" name=bccaddr size="100"></td></tr> </table> <input type="reset" value="重新選擇"> <input type="button" name="sum" value="產生連結" onClick=generate()> </form> </body> </html>