Ka¿da wskazówka bardzo mile widziana.
Oto kod w pliku (plik najpierw zapisuje e-news jako plik html, potem wysy³a pocztê ze skrótem informacji oraz z dodatkow± informacj± z bazy danych):
<script type="text/javascript"> var counter=0; function insRow() { counter++; var x=document.getElementById('tblEntry').insertRow(document.getElementById('tblEntry').rows.length) var y=x.insertCell(0) var row = "<td><p>Title: <input name="title[" + counter + "]" type="text" size="42" />"; row += "</p><p>Article Bookmark (max12 characters, NO SPACES): "; row += "<input name="anchor[" + counter + "]" type="text" size="18" "; row += "maxlength="12" /></p><p>Short Introduction (max 225 characters): "; row += "<input name="intro[" + counter + "]" type="text" size="38" "; row += "maxlength="255" /></p><p>Article:<br /><textarea name="article[" + counter + "]" "; row += "cols="75" rows="10" ></textarea></p><hr></td>"; y.innerHTML=row; //z.innerHTML="<input type='text' name='title[" + counter + "]'/>"; //alert(counter); //alert(z.innerHTML); //var arr = document.getElementById('myTable').rows //alert(document.getElementById('myTable').rows.length - 1); } function delRow() { if (counter>0) { var x = document.getElementById('tblEntry').deleteRow(document.getElementById('tblEntry').rows.length-1); counter--; } } </script> <h2>Create And Mail Newsletter</h2> <?php $emailsent=false; $query = "SELECT DISTINCT coursetypeid FROM courses c WHERE startdate>CURDATE() AND startdate <= DATE_ADD(CURDATE(),INTERVAL 90 DAY) ORDER BY c.coursetypeid"; $result = getRecords($query); for ($i=0;$i<count($result);$i++) $arrCourseTypes[$i]=$result[$i][0]; $courselist = ""; for ($i=0;$i<count($arrCourseTypes);$i++) { //get courses for the coursetype $ctid = $arrCourseTypes[$i]; //add coursetype name to the courselist $courselist .= "<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <strong>" .getCoursetypeName($ctid) . "</strong>:<br>"; $query = "SELECT courseid,c.coursetypeid, DATE_FORMAT(c.startdate,'%e %b %Y') as sdate, city, coursetypename FROM courses c, coursetypes ct,hostagency h WHERE c.coursetypeid=ct.coursetypeid AND c.hostagencyid=h.hostagencyid AND startdate>CURDATE() AND ct.active='yes' AND startdate <= DATE_ADD(CURDATE(),INTERVAL 90 DAY) AND c.coursetypeid = $ctid ORDER BY startdate"; //get the records $result = getRecords($query); //loop through the records foreach ($result as $course) { $courselist .= $course['sdate'] . " - " .$course['city'] . "<br>"; } // add link $courselist .= "<a href="http://www.ccaa-outreach.com/list_coursedates.php?coursetypeid=$ctid"> See course calendar >></a></font></p>"; } //build the newsletter linklist $linklist=''; $today = getdate(); $month = (strlen($today['mon'])<2)?"0".$today['mon']:$today['mon']; $day = (strlen($today['mday'])<2)?"0".$today['mday']:$today['mday']; $datestamp = $today['year'] . $month .$day; $newsletterurl="http://www.ccaa-outreach.com/newsletter_display.php?nldate=$datestamp"; //a variable to hold the newsletter text for($i=0;$i<count($_POST['title']);$i++) { $linklist .="<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>" . $_POST['title'][$i] . "</strong> <br><strong>" . $_POST['intro'][$i] ."</strong><br>" . "<a href="$newsletterurl#" . $_POST['anchor'][$i] . "">more information >></a></font></p>"; //add text to the newsletter file $newsletter .= "<a name='" . $_POST['anchor'][$i] . "'></a><h2>" . stripslashes($_POST['title'][$i]) . "</h2><p>" . stripslashes($_POST['intro'][$i]) . "</p><p>" . stripslashes($_POST['article'][$i]) . "</p>"; } //save the newsletter to file $filename = "/var/www/html/newsletters/newsletter_" . $datestamp .".htm"; //open the file for writing $fp = fopen($filename,"w"); if ($fp) { if (!fwrite($fp,$newsletter)) { Please contact the web master."; } } else { echo "Couldn't open the file. Please contact the web master."; } //get the template $htmlfile = file_get_contents("newsletter.htm"); $htmlfile = str_replace("%courselist%",$courselist,$htmlfile); $htmlfile = str_replace("%linklist%",$linklist, $htmlfile); $html = true; $subject = "CCAA Newsletter"; //build the emails array $query = "select email from newsletter"; $result = getRecords($query); $arrEmails = array(); for ($i=0;$i<count($result);$i++) $arrEmails[$i]=$result[$i][0]; if (!sendNewsletter($arrEmails, $subject, stripslashes($htmlfile), $html)) { echo "There were some problems with sending this newsletter. Please contact the w
eb administrator"; } else { echo "Mail sent."; $emailsent=true; } //print_r($_POST); //echo $newsletter; } if (isset($emailsent) && $emailsent==false) { ?> <P><input type="button" onclick="insRow()" value="+"> <input type="button" onclick="delRow()" value="-"></P> <form method="post" id="form" name="form"> <table border="0" cellspacing="0" cellpadding="4" id="tblEntry"> <tr> <td><p>Title: <input name="title[0]" type="text" size="42" /></p> <p>Article Bookmark (max12 characters, NO SPACES): <input name="anchor[0]" type="text" size="18" maxlength="12" /> </p> <p>Short Introduction (max 225 characters): <input name="intro[0]" type="text" size="38" maxlength="255" /> </p> <p>Article:<br /> <textarea name="article[0]" cols="75" rows="10" ></textarea> </p><HR> </td> </tr> </table> <p> <input id="submit" type="submit" value=" Send Newsletter " name="submit" /> </p> </form> <?php } else { }
Dziêkujê
Andrzej