0) { //POSTED FORM, PROCESS IT
$message = "";
$page = array(); // Holds the data required to save the submission as a page within the CMS.
$name = "";
$form_fields = array(); // Holds the field names of all fields provided in the submitted data.
$form_submitted = true; // Indicates if the form can be submitted or if it had data entry errors.
$form_values = array(); // Holds the values of all fields provided in the submitted data.
$required_fields = array(); // Holds the field names of fields that are required.
$unsatisfied_fields_message = ""; // Message indicating any unsatisfied required fields.
// Helper array containing POST elements to skip during processing.
$postKeysToSkip = array(
"send-email", "save-to-cms", "save-to-excel", "form-config", "emails"
);
function getParentFolderOutOfPath($path){
return substr($path, 0, strripos($path,'/'));
}
//Convert date to unix timestamp
function convert_datetime($str)
{
list($date, $time, $meridian) = explode(' ', $str);
list($month, $day, $year) = explode('/', $date);
list($hour, $minute) = explode(':', $time);
if(strcmp($meridian, "PM") == 0 && strcmp($hour, "12")){
$hour = intval($hour) + 12;
}
// this was causing an issue so removed
//$hour = intval($hour)-3;
$timestamp = mktime($hour, $minute, 0, $month, $day, $year);
//Return Cascade timestamp
return $timestamp*1000;
}
// Helper function used for escaping CSV content.
function arrayToCSV($fields, $delimiter = ',', $enclosure = '"') {
$str = '';
foreach ($fields as $cell) {
$cell = str_replace($enclosure, $enclosure . $enclosure, $cell);
if (strchr($cell, $delimiter) !== false ||
strchr($cell, $enclosure) !== false ||
strchr($cell, "\n") !== false) {
$str .= $enclosure . $cell . $enclosure . $delimiter;
} else {
$str .= $cell . $delimiter;
}
}
return substr($str, 0, -1) . "\n";
}
function get_category_values_for_ws($categories)
{
$r = array();
foreach($categories as $value) {
array_push($r,array("value" => $value));
}
return $r;
}
function get_contact_values_for_ws($name, $phone, $email)
{
return array(
array(
"type" => "text",
"identifier" => "name",
"text" => $name
),
array(
"type" => "text",
"identifier" => "phone",
"text" => $phone
),
array(
"type" => "text",
"identifier" => "email",
"text" => $email
)
);
}
function get_recurring_values_for_ws($recurrence, $interval, $recurrence_ends, $monthly_type, $weekly_days)
{
$r = array();
array_push($r, array("type" => "text", "identifier" => "frequency", "text" => $recurrence));
if($recurrence !== "Once") {
array_push($r, array("type" => "text", "identifier" => "interval", "text" => $interval));
}
if($recurrence === "Weekly") {
$glue = "::CONTENT-XML-CHECKBOX::";
$weekly_days = $glue.implode($glue, $weekly_days);
array_push($r, array("type" => "text", "identifier" => "day", "text" => $weekly_days));
}
if($recurrence === "Monthly") {
array_push($r, array("type" => "text", "identifier" => "monthly-day", "text" => $monthly_type));
}
if(!empty($recurrence_ends)) {
array_push($r, array("type" => "text", "identifier" => "ends", "text" => $recurrence_ends));
}
return $r;
}
/* Pull the required fields array out of POST.
$required_fields = $_POST['REQUIRED'];
unset($_POST['REQUIRED']);
*/
$date_fields = ["startDateYear", "endDateYear", "recEndYear"];
$fields_to_process = [
"name",
"phone",
"email",
"startDateYear",
"endDateYear",
"location",
"eventURL",
"admissionInfo",
"details",
"subtitle"
];
// Go through each POST element and add the information to the message and to the content of the xml file
foreach ($_POST as $key => $value) {
// If this is a field that actually provides the script with submitted content
// If the field is an array, combine the values.
if (is_array($value)){
$value = implode(", ", $value);
}
// Perform some value sanitization.
$value = strip_tags(stripslashes($value));
// Record the field and add to the message string.
$form_fields[$key] = $value;
$message .= $key . ": " . $value . "\r\n";
// use this for custom data definition output
//get title
if(strcmp($key, "title") == 0){
$page['metadata']['title'] = $value;
//convert title into name
$name = htmlspecialchars(str_replace(" ", "-", strtolower($value)));
}
/* MM/dd/yyyy HH:mm PP */
if(in_array($key, $date_fields)) {
switch($key) {
case "startDateYear":
if(!empty($_POST["startDateMonth"]) && !empty($_POST["startDateDay"])) {
$startTimeType = $_POST["startTimeType"];
// time will default to '12:00 AM' unless specified
$time = "12:00 AM";
switch($startTimeType) {
case "allDay":
$page['structuredData']['structuredDataNodes']['structuredDataNode'][] = array(
'identifier' => 'all-day',
'type' => 'text',
'text' => '::CONTENT-XML-CHECKBOX::Yes');
break;
case "TBA":
$page['structuredData']['structuredDataNodes']['structuredDataNode'][] = array(
'identifier' => 'time-tba',
'type' => 'text',
'text' => '::CONTENT-XML-CHECKBOX::Yes');
break;
default:
$time = $_POST["startTimeHour"].":".$_POST["startTimeMin"]." ".$_POST["startTimeAMPM"];
break;
}
$startDate = $_POST["startDateMonth"] . "/" . $_POST["startDateDay"] . "/" . $value . " " .$time;
$value = convert_datetime($startDate);
} else {
// break or add to bad array
}
break;
case "endDateYear":
if(!empty($_POST["endDateMonth"]) && !empty($_POST["endDateDay"])) {
// the default time value is OK to use
$time = $_POST["endTimeHour"].":".$_POST["endTimeMin"]." ".$_POST["endTimeAMPM"];
$date = $_POST["endDateMonth"] . "/" . $_POST["endDateDay"] . "/" . $value . " " .$time;
$value = convert_datetime($date);
}
break;
case "recEndYear":
break;
}
}
if(strcmp($key, "location") == 0){
$out = "";
if($value === "on") {
$out .= "On Campus";
if(!empty($_POST["building"])) {
$out .= " - " . $_POST["building"];
} else {
//echo "building empty!";
}
if(!empty($_POST["roomnumber"])) {
$out .= " - Room ". $_POST["roomnumber"];
}
} else {
$out .= "Off Campus";
}
if(!empty($_POST["offCampus"])) {
$out .= " - " .$_POST["offCampus"];
}
$value = $out;
}
if(in_array($key, $fields_to_process)) {
switch($key) {
case "startDateYear":
$key = "starts";
break;
case "endDateYear":
$key = "ends";
break;
}
$page['structuredData']['structuredDataNodes']['structuredDataNode'][] = array(
'identifier' => $key,
'type' => 'text',
'text' => $value);
}
}
$webName = $_POST["name"];
$webPhone = $_POST["phone"];
$webEmail = $_POST["email"];
if($_POST["sameAsAbove"] === "true") {
$eventName = $webName;
$eventPhone = $webPhone;
$eventEmail = $webEmail;
} else {
$eventName = $_POST["ContactName"];
$eventPhone = $_POST["ContactPhone"];
$eventEmail = $_POST["ContactEmail"];
}
// add web contact info
$page["structuredData"]["structuredDataNodes"]["structuredDataNode"][] = array(
"identifier" => "web-submission-contact",
"type" => "group",
"structuredDataNodes" => array(
"structuredDataNode" => get_contact_values_for_ws($webName, $webPhone, $webEmail)
)
);
// add web contact info
$page["structuredData"]["structuredDataNodes"]["structuredDataNode"][] = array(
"identifier" => "contact",
"type" => "group",
"structuredDataNodes" => array(
"structuredDataNode" => get_contact_values_for_ws($eventName, $eventPhone, $eventEmail)
)
);
$open_to_fields = [
["name" => "openToPublic", "label" => "Public"],
["name" => "openToAlumni", "label" => "Alumni"],
["name" => "openToStudents", "label" => "Students"],
["name" => "openToFaculty", "label" => "Faculty"],
["name" => "openToStaff", "label" => "Staff"],
["name" => "invitationOnly", "label" => "Invitation Only"],
];
$add_comma = false;
$open_to_values = "";
foreach($open_to_fields as $field) {
if($_POST[$field["name"]] === "true") {
if($add_comma) {
$open_to_values .= ", ";
}
$open_to_values .= $field["label"];
if(!$add_comma) {
$add_comma = true;
}
}
}
$page['structuredData']['structuredDataNodes']['structuredDataNode'][] = array(
'identifier' => 'open-to',
'type' => 'text',
'text' => $open_to_values
);
// ************ start RECURRENCE INFO ************ //
$recurrence = $_POST["eventrecurrs"];
switch($recurrence) {
case "Daily":
$interval = $_POST["recDailyInt"];
break;
case "Weekly":
$interval = $_POST["recWeeklyInt"];
$weekly_days = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
foreach($weekly_days as $key=>$day) {
$day = 'recWeekly'.$day;
if(empty($_POST[$day])) {
unset($weekly_days[$key]);
}
}
break;
case "Monthly":
$interval = $_POST["recMonthlyInt"];
$monthly_type = $_POST["recMonthlyType"];
break;
case "Yearly":
$interval = $_POST["recYearlyInt"];
break;
}
// get recurrence end date
if(!empty($_POST["recEndYear"]) && !empty($_POST["recEndMonth"]) && !empty($_POST["recEndDay"])) {
$recurrence_ends = $_POST["recEndMonth"] . "/" . $_POST["recEndDay"] . "/" . $_POST["recEndYear"] . " 01:00 AM";
$recurrence_ends = convert_datetime($recurrence_ends);
}
// add web contact info
$page["structuredData"]["structuredDataNodes"]["structuredDataNode"][] = array(
"identifier" => "recurrence",
"type" => "group",
"structuredDataNodes" => array(
"structuredDataNode" => get_recurring_values_for_ws($recurrence, $interval, $recurrence_ends, $monthly_type, $weekly_days)
)
);
// ************ end RECURRENCE INFO ************ //
$required_fields = [
"name",
"phone",
"email",
"startDateYear", "startDateMonth", "startDateDay",
"endDateYear", "endDateMonth", "endDateDay",
"eventrecurrs",
"startTimeType",
"title",
"category",
"location"
];
// Check required fields to make sure they are valid.
foreach ($required_fields as $field) {
// If the field is not present or its value is empty, mark it as unsatisfied.
if (!array_key_exists($field, $form_fields) || empty($form_fields[$field])) {
$unsatisfied_fields_message .= "
".$field."";
}
}
// Do we have any fields that were not valid?
// If so, display an error message containing these fields
if (!empty($unsatisfied_fields_message)) {
$pageURL = (@$_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
echo "
";
echo "
Error: The following required fields were not provided:
";
echo "
".$unsatisfied_fields_message."
";
echo "
The form's data was not sent. Please hit the 'Back' button and fill in the required fields mentioned above.
";
// Update the form submission flag due to the failed validation.
$form_submitted = false;
}
if ($form_submitted) {
$cascade_address = "webdev1.lagrange.edu:8080";
$username = "eventSubmit";
$password = "lagrange";
$siteName = "Calendar";
$soapURL = $cascade_address . "/ws/services/AssetOperationService?wsdl";
$client = new SoapClient($soapURL, array('trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'location' => str_replace('?wsdl', '', $soapURL)));
// default the event frequency to 'Once'
$page["structuredData"]["structuredDataNodes"]["structuredDataNode"][] = array(
"identifier" => "recurrence",
"type" => "group",
"structuredDataNodes" => array(
"structuredDataNode" => array(
"type" => "text",
"identifier" => "frequency",
"text" => "Once"
)
)
);
$category_values = get_category_values_for_ws($_POST["category"]);
$page['metadata']['dynamicFields']['dynamicField'] = ["name" => "categories", "fieldValues" => ["fieldValue" => $category_values]];
try {
$page['name'] = $name;
//find parent folder for this event
//$startDate = explode("/", $form_fields['starts']);
$startDate = explode("/", $startDate);
$month = $startDate[0];
$yearTime = explode(" ", $startDate[2]);
$year = $yearTime[0];
// verify month has two digits for folder placement
if($month < 10 && !isset($month[1])) {
$month = "0".$month;
}
$parentPath = array('siteName' => $siteName, 'path' => $year . "/" . $month);
$parentIdentifier = array('type' => 'folder', 'path' => $path);
//$page['parentFolderPath'] = $folder;
$page['parentFolderPath'] = $year . "/" . $month;
$page['contentTypePath'] = "Calendar:Event Submission/Submission Form";
$page['siteName'] = $siteName;
$create_params = array(
'authentication' => array( 'password' => $password, 'username' => $username ),
'asset' => array(
'page' => $page
// Uncomment this section if a workflow should be started on creation of a page in Cascade using the form.
// WorkflowName can be whatever the user wants.
// WorkflowDefinitionPath should be the Workflow to be started.
// WorkflowComments may be modified as well.
,
'workflowConfiguration' => array(
'workflowName' => 'New Event',
'workflowDefinitionPath' => 'Event Approval',
'workflowComments' => 'Asset created by outside user.'
)
)
);
try {
$client->create($create_params);
} catch (Exception $e) {
print_r($client->__getLastResponse());
print ($e->getMessage());
print("Error: File creation request failed to conform to the WSDL.
");
}
} catch (Exception $e) {
print_r($client->__getLastResponse());
print("Error: File creation request failed to conform to the WSDL.
");
}
?>Your event has been submitted. Thank you!
Submit another event.
'); //htmlentities(
} else { ?>
submit
Add Event
Please enter the following information to add an event. Required fields are marked with an asterisk (*).