<?php
/*
****************************************
*
* Snippet Name: MakeNewsletter
* Short Desc: Makes a newsletter from articles stored in the database
* Created By: Sarah Vardy
*
* Version: 1.0 beta
* Modified: November 9th, 2007
*
* Changelog:
*
*
****************************************
*
* Description:
* Display a list of articles that have been posted to the site
* Shows a drop-down list next to each article so the user can select and article and a relevant weight for inclusion in the IT newsletter
*
****************************************
*
* Example: [[MakeNewsletter?]]
*/
$output = '';
//connect to table that stores site content
$table_content = $modx->getFullTableName("site_content");
//connect to the table that stores web user data
$table_users= $modx->getFullTableName("web_users");
//fields to get from query
$fields = 'id,pagetitle,createdby,createdon';
//$sql= "SELECT {$fields} FROM {$table_content} table_content JOIN {$table_users} table_users ON table_users.id = table_content.createdby WHERE table_content.parent= '48' AND table_content.published = '1' ORDER BY table_content.createdon DESC LIMIT 3";
$sql= "SELECT {$fields} FROM {$table_content} table_content WHERE table_content.parent= '48' AND table_content.published = '1' ORDER BY table_content.createdon DESC LIMIT 3";
$results= $modx->db->query($sql);
$output .='<form>';
$output .='<table>';
while ($row=$modx->db->getRow($results)) {
$output .='<tr><td><label><input type="checkbox" name="checkbox" value="' . $row[id] . '" /> Include this</label></td>';
$output .='<td width="100px"><label>Weight <select name="select"><option>-10</option><option>-9</option><option>-8</option><option>-7</option><option>-6</option><option>-5</option>
<option>-4</option><option>-3</option><option>-2</option><option>-1</option><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option>
<option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select>';
$output .= '<td><a href="index.php?id=' . $row[id] . '">' . $row[pagetitle] . '</a>' . "<br>" . '</td></tr>';
}
$output .='</table>';
$output .='<label><input type="submit" name="Submit" value="Make newsletter" /></label>';
$output .='</form>';
return $output;
?><?php
/*
****************************************
*
* Snippet Name: MakeNewsletter
* Short Desc: Makes a newsletter from articles stored in the database
* Created By: Sarah Vardy
*
* Version: 1.0 beta
* Modified: November 9th, 2007
*
* Changelog:
*
*
****************************************
*
* Description:
* Display a list of articles that have been posted to the site
* Shows a drop-down list next to each article so the user can select and article and a relevant weight for inclusion in the IT newsletter
*
****************************************
*
* Example: [[MakeNewsletter?]]
*/
$months = array(January,February,March,April,May,June,July,August,September,October,November,December);
// getting current timestamp
if(!isset($format)) {
$format="%m";
}
if(!isset($timestamp)) {
$timestamp=time();
}
// getting current timestamp
if(!isset($format_two)) {
$format_two="%Y";
}
$currentMonth = strftime($format, $timestamp+$modx->config['server_offset_time']);
$currentYear = strftime($format_two, $timestamp+$modx->config['server_offset_time']);
$output = '';
//connect to table that stores site content
$table_content = $modx->getFullTableName("site_content");
//connect to the table that stores web user data
$table_users= $modx->getFullTableName("web_users");
//fields to get from query
$fields = 'id,pagetitle,createdby,createdon';
//$sql= "SELECT {$fields} FROM {$table_content} table_content JOIN {$table_users} table_users ON table_users.id = table_content.createdby WHERE table_content.parent= '48' AND table_content.published = '1' ORDER BY table_content.createdon DESC LIMIT 3";
$sql= "SELECT {$fields} FROM {$table_content} table_content WHERE table_content.parent= '48' AND table_content.published = '1' ORDER BY table_content.createdon DESC LIMIT 3";
$results= $modx->db->query($sql);
$output .='<form>';
$output .='<table>';
while ($row=$modx->db->getRow($results)) {
$tempMonth = strftime($format, $row[createdon]);
$tempYear = strftime($format_two, $row[createdon]);
//if the current entry is the current month display it
if ($tempMonth == $currentMonth && $tempYear == $currentYear)
{
$output .='<tr><td><label><input type="checkbox" name="checkbox" value="' . $row[id] . '" /> Include this</label></td>';
$output .='<td width="100px"><label>Weight <select name="select"><option>-10</option><option>-9</option><option>-8</option><option>-7</option><option>-6</option><option>-5</option>
<option>-4</option><option>-3</option><option>-2</option><option>-1</option><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option>
<option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select>';
$output .= '<td><a href="index.php?id=' . $row[id] . '">' . $row[pagetitle] . '</a>' . "<br>" . '</td></tr>';
$tempMonth ='';
//else do not display it
}else
{
$tempMonth ='';
}
}
$output .='</table>';
$output .='<label><input type="submit" name="make" value="Make newsletter for ' . $months[$currentMonth -1] . ',' . $currentYear . '" /></label>';
$output .='</form>';
/*
if(isset($_POST['make']))
{
$checkbox = $_POST['checkbox'];
$select = $_POST['select'];
$sql = "INSERT INTO ".$modx->getFullTableName('rcs_it_newsletters')." (doc_id, doc_weight) VALUES ('".$checkbox."' , '"$select"')";
$rs = $modx->db->query($sql);
$id = $modx->db->getInsertId();
//include 'library/closedb.php';
echo "Article '$checkbox' added with weight of '$select'";
}
*/
return $output;
?><?php
/*
****************************************
*
* Snippet Name: MakeNewsletter
* Short Desc: Makes a newsletter from articles stored in the database
* Created By: Sarah Vardy
*
* Version: 0.1 beta
* Modified: November 13th, 2007
*
* Changelog:
*
*
****************************************
*
* Description:
* Display a list of articles that have been posted to the site
* Shows a drop-down list next to each article so the user can select and article and a relevant weight for inclusion in the IT newsletter
*
****************************************
*
* Example: [[MakeNewsletter?]]
*/
$months = array(January,February,March,April,May,June,July,August,September,October,November,December);
// getting current timestamp
if(!isset($format)) {
$format="%m";
}
if(!isset($timestamp)) {
$timestamp=time();
}
// getting current timestamp
if(!isset($format_two)) {
$format_two="%Y";
}
$currentMonth = strftime($format, $timestamp+$modx->config['server_offset_time']);
$currentYear = strftime($format_two, $timestamp+$modx->config['server_offset_time']);
$output = '';
//connect to table that stores site content
$table_content = $modx->getFullTableName("site_content");
//connect to the table that stores web user data
$table_users= $modx->getFullTableName("web_users");
//fields to get from query
$fields = 'id,pagetitle,createdby,createdon';
//query mySQL database
$sql= "SELECT {$fields} FROM {$table_content} table_content WHERE table_content.parent= '48' AND table_content.published = '1' ORDER BY table_content.createdon DESC LIMIT 3";
$results= $modx->db->query($sql);
while ($row=$modx->db->getRow($results)) {
$tempMonth = strftime($format, $row[createdon]);
$tempYear = strftime($format_two, $row[createdon]);
$output .='<form action="index.php?id=99" method="post">';
$output .='<table>';
//if the current entry is the current month display it
if ($tempMonth == $currentMonth && $tempYear == $currentYear)
{
$output .='<tr><td><label><input type="checkbox" name="doc_id" value="' . $row[id] . '" /> Include this</label></td>';
$output .='<td width="100px"><label>Weight <select name="doc_weight"><option>-10</option><option>-9</option><option>-8</option><option>-7</option><option>-6</option><option>-5</option>
<option>-4</option><option>-3</option><option>-2</option><option>-1</option><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option>
<option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select>';
$output .= '<td><a href="index.php?id=' . $row[id] . '">' . $row[pagetitle] . '</a>' . "<br>" . '</td>';
$tempMonth ='';
//else do not display it
}
else
{
$tempMonth ='';
}
}
$output .='</table>';
$output .='<input type="hidden" name="doc_month" value="' . $currentMonth . '">';
$output .='<input type="hidden" name="doc_year" value="' . $currentYear . '">';
$output .='<label><input type="submit" name="make" value="Make newsletter for ' . $months[$currentMonth -1] . ',' . $currentYear . '" /></label>';
$output .='</form>';
return $output;
?><?php
#
# Snippet MakeNewsletter v 0.1 beta
# By sarah Vardy
# This release: 13-Nov-2007.
#
# Processes form entry fields from MakeNewsletter snippet
#
# Warning! This add-on might not be ready for public use
#
//global variables
//global $modx, $table_prefix;
$table = $modx->getFullTableName("rcs_it_newsletters");
//get values from post and insert them into table in database
$doc_id=$_POST['doc_id'];
$doc_weight=$_POST['doc_weight'];
$doc_month=$_POST['doc_month'];
$doc_year=$_POST['doc_year'];
mysql_query("INSERT INTO $table VALUES ('$doc_id', '$doc_weight', '$doc_month', '$doc_year')");
print "Your information has been successfully added to the database.";
print $doc_id;
print $doc_weight;
print $doc_month;
print $doc_year;
?><?php
/*
****************************************
*
* Snippet Name: MakeNewsletter
* Short Desc: Makes a newsletter from articles stored in the database
* Created By: Sarah Vardy
*
* Version: 0.1 beta
* Modified: November 13th, 2007
*
* Changelog:
*
*
****************************************
*
* Description:
* Display a list of articles that have been posted to the site
* Shows a drop-down list next to each article so the user can select and article and a relevant weight for inclusion in the IT newsletter
*
****************************************
*TO-DO
* Check the custom newsletter table to see if an article is already being used in an existing newsletter before displaying it to be included in a newsletter
****************************************
*
* Example: [[MakeNewsletter?]]
*/
global $currentCounter;
$counter =1;
$months = array(January,February,March,April,May,June,July,August,September,October,November,December);
// getting current timestamp
if(!isset($format)) {
$format="%m";
}
if(!isset($timestamp)) {
$timestamp=time();
}
// getting current timestamp
if(!isset($format_two)) {
$format_two="%Y";
}
$currentMonth = strftime($format, $timestamp+$modx->config['server_offset_time']);
$currentYear = strftime($format_two, $timestamp+$modx->config['server_offset_time']);
$output = '';
//connect to table that stores site content
$table_content = $modx->getFullTableName("site_content");
//connect to the table that stores web user data
$table_users= $modx->getFullTableName("web_users");
//connect to custom table that stores newsletter documents
$table_newsletters = $modx->getFullTableName("rcs_it_newsletters");
//fields to get from query
$fields = 'id,pagetitle,createdby,createdon';
//query mySQL database
$sql= "SELECT {$fields} FROM {$table_content} table_content WHERE table_content.parent= '48' AND table_content.published = '1' ORDER BY table_content.createdon DESC LIMIT 3";
$results= $modx->db->query($sql);
while ($row=$modx->db->getRow($results)) {
$tempMonth = strftime($format, $row[createdon]);
$tempYear = strftime($format_two, $row[createdon]);
$output .='<form action="index.php?id=99" method="post">';
$output .='<table>';
//if the current entry is the current month display it
if ($tempMonth == $currentMonth && $tempYear == $currentYear)
{
//------------------------------------------DO I DO THIS HERE?????
//if the existing entry does not already belong in the rcs_it_newsletters table display it
$docIdTag = 'doc_id_';
$docWeightTag = 'doc_weight_';
$output .='<tr><td><label><input type="checkbox" name="' . $docIdTag . $counter . '" value="' . $row[id] . '" /> Include this</label></td>';
$output .='<td width="100px"><label>Weight <select name="' . $docWeightTag . $counter . '"><option>-10</option><option>-9</option><option>-8</option><option>-7</option><option>-6</option><option>-5</option>
<option>-4</option><option>-3</option><option>-2</option><option>-1</option><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option>
<option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select>';
$output .= '<td><a href="index.php?id=' . $row[id] . '">' . $row[pagetitle] . '</a>' . "<br>" . '</td>';
$counter++;
$tempMonth ='';
//else do not display it
}
else
{
$tempMonth ='';
}
//return $counter;
}
$output .='</table>';
//$output .='<input type="hidden" name="doc_counter" value="' . $currentCounter . '">';
$output .='<input type="hidden" name="doc_month" value="' . $currentMonth . '">';
$output .='<input type="hidden" name="doc_year" value="' . $currentYear . '">';
$output .='<label><input type="submit" name="make" value="Make newsletter for ' . $months[$currentMonth -1] . ',' . $currentYear . '" /></label>';
$output .='</form>';
if ($counter >= '20')
{
return $output;
}
else if ($counter < '20')
{
print '<strong><font size="3">THERE ARE NOT ENOUGH ARTICLES TO MAKE A FULL NEWSLETTER YET!</font></strong>' . "<br>" . 'You have a total of <strong><font size="3">' . $counter . ' articles</font></strong>';
}
?><?php
#
# Snippet MakeNewsletter v 0.1 beta
# By Sarah Vardy
# This release: 13-Nov-2007.
#
# Processes form entry fields from MakeNewsletter snippet
#
# Warning! This add-on might not be ready for public use
#
//global variables
global $modx, $table_prefix;
$table = $modx->getFullTableName("rcs_it_newsletters");
//while (false)
for ($counter =0; $counter < 20; $counter ++)
{
if (isset($_POST['doc_id_'.$counter]))
{
print 'Got here!';
print $val_count;
$val_id = $_POST['doc_id_'.$counter];
$val_weight = $_POST['doc_weight_'.$counter];
$val_month=$_POST['doc_month'];
$val_year=$_POST['doc_year'];
// do something with val
print $val_id;
print $val_weight;
mysql_query("INSERT INTO $table VALUES ('$val_id', '$val_weight', '$val_month', '$val_year')");
}
//$counter++;
}
print "Your information has been successfully added to the database.";
?><?php
/*
****************************************
*
* Snippet Name: MakeNewsletter
* Short Desc: Makes a newsletter from articles stored in the database
* Created By: Sarah Vardy
*
* Version: 0.1 beta
* Modified: November 13th, 2007
*
* Changelog:
*
*
****************************************
*
* Description:
* Display a list of articles that have been posted to the site
* Shows a drop-down list next to each article so the user can select and article and a relevant weight for inclusion in the IT newsletter
*
****************************************
*TO-DO
* Check the custom newsletter table to see if an article is already being used in an existing newsletter before displaying it to be included in a newsletter
****************************************
*
* Example: [[MakeNewsletter?]]
*/
global $currentCounter;
$counter =1;
$docIdArray = array();
$counter_two =0;
$months = array(January,February,March,April,May,June,July,August,September,October,November,December);
// getting current timestamp
if(!isset($format)) {
$format="%m";
}
if(!isset($timestamp)) {
$timestamp=time();
}
// getting current timestamp
if(!isset($format_two)) {
$format_two="%Y";
}
$currentMonth = strftime($format, $timestamp+$modx->config['server_offset_time']);
$currentYear = strftime($format_two, $timestamp+$modx->config['server_offset_time']);
$output = '';
//connect to table that stores site content
$table_content = $modx->getFullTableName("site_content");
//connect to the table that stores web user data
$table_users= $modx->getFullTableName("web_users");
//connect to custom table that stores newsletter documents
$table_newsletters = $modx->getFullTableName("rcs_it_newsletters");
//fields to get from query
$fields = 'id,pagetitle,createdby,createdon';
$fields_two = 'doc_id';
//query mySQL database
$sql= "SELECT {$fields} FROM {$table_content} table_content WHERE table_content.parent= '48' AND table_content.published = '1' ORDER BY table_content.createdon DESC LIMIT 3";
$results= $modx->db->query($sql);
$sql_two= "SELECT {$fields_two} FROM {$table_newsletters} table_newsletters";
$results_two= $modx->db->query($sql_two);
//store the results of the doc_id in an array
while ($row_two=$modx->db->getRow($results_two))
{
//store the value in the array
$docIdArray[$counter_two] = $row_two[doc_id];
//print $docIdArray[$counter_two];
$counter_two++;
}
while ($row=$modx->db->getRow($results)) {
$tempMonth = strftime($format, $row[createdon]);
$tempYear = strftime($format_two, $row[createdon]);
$tempId = $row[id];
$output .='<form action="index.php?id=99" method="post">';
$output .='<table>';
//if the current entry is the current month display it
if ($tempMonth == $currentMonth && $tempYear == $currentYear)
{
//iterate through the $docIdArray
for($i = 0; $i < count($docIdArray); $i++)
{
//If the id of the current document is found
$tempArrayIDStore = $docIdArray[$i];
if($tempArrayIDStore == $tempId)
{
//Do not display the document and go back to the statement that called this one
$output .= 'Resource with id '. $tempId . ' has already been used!';
$output .= "<br>";
$tempId = '';
break;
}
else if($tempId != $tempArrayIDStore)
{
//else display the document
$docIdTag = 'doc_id_';
$docWeightTag = 'doc_weight_';
$output .='<tr><td><label><input type="checkbox" name="' . $docIdTag . $counter . '" value="' . $row[id] . '" /> Include this</label></td>';
$output .='<td width="100px"><label>Weight <select name="' . $docWeightTag . $counter . '"><option>-10</option><option>-9</option><option>-8</option><option>-7</option><option>-6</option><option>-5</option>
<option>-4</option><option>-3</option><option>-2</option><option>-1</option><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option>
<option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select>';
$output .= '<td><a href="index.php?id=' . $row[id] . '">' . $row[pagetitle] . '</a>' . "<br>" . '</td>';
$counter++;
$tempMonth ='';
break;
}
}
}//end if statement
//else do not display it
else
{
}//end else statement
}//end while statement
$output .='</table>';
$output .='<input type="hidden" name="doc_month" value="' . $currentMonth . '">';
$output .='<input type="hidden" name="doc_year" value="' . $currentYear . '">';
$output .='<label><input type="submit" name="make" value="Make newsletter for ' . $months[$currentMonth -1] . ',' . $currentYear . '" /></label>';
$output .='</form>';
//if ($counter >= '20')
//{
return $output;
//}
//else if ($counter < '20')
//{
//print '<strong><font size="3">THERE ARE NOT ENOUGH ARTICLES TO MAKE A FULL NEWSLETTER YET!</font></strong>' . "<br>" . 'You have a total of <strong><font size="3">' . $counter . ' articles</font></strong>';
//}
?><?php
/*
****************************************
*
* Snippet Name: MakeNewsletter
* Short Desc: Makes a newsletter from articles stored in the database
* Created By: Sarah Vardy
*
* Version: 0.1 beta
* Modified: November 14th, 2007
*
* Changelog:
*
*
****************************************
*
* Description:
* Display a list of articles that have been posted to the site
* Shows a drop-down list next to each article so the user can select and article and a relevant weight for inclusion in the IT newsletter
*
****************************************
*TO-DO
* Check the custom newsletter table to see if an article is already being used in an existing newsletter before displaying it to be included in a newsletter
****************************************
*
* Example: [[MakeNewsletter?]]
*/
global $currentCounter;
$counter =1;
$docIdArray = array();
$counter_two =0;
$months = array(January,February,March,April,May,June,July,August,September,October,November,December);
// getting current timestamp
if(!isset($format)) {
$format="%m";
}
if(!isset($timestamp)) {
$timestamp=time();
}
// getting current timestamp
if(!isset($format_two)) {
$format_two="%Y";
}
$currentMonth = strftime($format, $timestamp+$modx->config['server_offset_time']);
$currentYear = strftime($format_two, $timestamp+$modx->config['server_offset_time']);
$output = '';
//connect to table that stores site content
$table_content = $modx->getFullTableName("site_content");
//fields to get from query
$fields = 'id,pagetitle,createdby,createdon';
//query mySQL database
$sql= "SELECT {$fields} FROM {$table_content} table_content WHERE table_content.parent= '48' AND table_content.published = '1' ORDER BY table_content.createdon DESC LIMIT 3";
$results= $modx->db->query($sql);
while ($row=$modx->db->getRow($results)) {
$tempMonth = strftime($format, $row[createdon]);
$tempYear = strftime($format_two, $row[createdon]);
$tempId = $row[id];
$output .='<form action="index.php?id=99" method="post">';
$output .='<table>';
//if the current entry is the current month display it
while ($tempMonth == $currentMonth && $tempYear == $currentYear)
{
//display the document
$docIdTag = 'doc_id_';
$docWeightTag = 'doc_weight_';
$output .='<tr><td><label><input type="checkbox" name="' . $docIdTag . $counter . '" value="' . $row[id] . '" /> Include this</label></td>';
$output .='<td width="100px"><label>Weight <select name="' . $docWeightTag . $counter . '"><option>-10</option><option>-9</option><option>-8</option><option>-7</option><option>-6</option><option>-5</option>
<option>-4</option><option>-3</option><option>-2</option><option>-1</option><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option>
<option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select>';
$output .= '<td><a href="index.php?id=' . $row[id] . '">' . $row[pagetitle] . '</a>' . "<br>" . '</td>';
$counter++;
$tempMonth ='';
}
}//end while statement
$output .='</table>';
$output .='<label><input type="submit" name="make" value="Make newsletter for ' . $months[$currentMonth -1] . ',' . $currentYear . '" /></label>';
$output .='</form>';
return $output;
?><?php
#
# Snippet MakeNewsletter v 0.1 beta
# By Sarah Vardy
# This release: 13-Nov-2007.
#
# Processes form entry fields from MakeNewsletter snippet
#
# Warning! This add-on might not be ready for public use
#
//global variables
global $modx, $table_prefix;
$table = $modx->getFullTableName("rcs_it_newsletters");
//while (false)
/*for ($counter =0; $counter < 20; $counter ++)
{
*/
if (isset($_POST['doc_id']))
{
//$val_weight = $_POST['doc_weight_'.$counter];
$val_id=serialize($_POST['doc_id']);
$val_weight=serialize($_POST['doc_weight']);
//$val_month=$_POST['doc_month'];
//$val_year=$_POST['doc_year'];
//$val_id = $_POST['doc_id_'.$counter];
// do something with val
print $val_id;
print $val_weight;
mysql_query("INSERT INTO $table VALUES ('$val_id', '$val_weight')");
}
//$counter++;
//}
print "Your information has been successfully added to the database.";
?>