From: Anthony Talarico Date: Wed, 20 Apr 2016 20:37:44 +0000 (-0400) Subject: added front end form functionality, added jquery, css X-Git-Tag: v1.0.0^2~95 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=009915b971eba8f46a65c56740a468e6181e0d7b;p=WP-Plugins%2Fglm-member-db-events.git added front end form functionality, added jquery, css --- diff --git a/css/front.css b/css/front.css index 8b5c564..4e92e69 100644 --- a/css/front.css +++ b/css/front.css @@ -115,4 +115,13 @@ .timeDropDown{ width: 30%; } +.frontRecurrences{ + display: none; +} +input[name="event_name"]{ + margin-bottom: 0px; +} +input[name='contact_fname'], input[name='contact_lname']{ + width: 50%; +} diff --git a/js/front.js b/js/front.js index bf46cf1..2aafe48 100644 --- a/js/front.js +++ b/js/front.js @@ -20,7 +20,43 @@ var EventFront = { return false; }); jQuery("#sdate, #edate").datepicker({ - dateFormat: 'dd-mm-yy' + dateFormat: 'mm/dd/yy' + }); + + $("#freeEvent").change( function () { + if(this.checked){ + $("#cost").fadeOut('medium'); + } else { + $("#cost").fadeIn('medium'); + } + }); + $("#repeatingEvent").change( function () { + if(this.checked){ + $(".frontRecurrences").fadeIn('medium'); + } else { + $(".frontRecurrences").fadeOut('medium'); + } + }); + $("#allDay").change( function () { + if(this.checked){ + $(".timeRow").fadeOut('medium'); + } else { + $(".timeRow").fadeIn('medium'); + } + }); + $("#dayOfMonth").change( function () { + if($(this).val() !== ""){ + $("#daysOfWeek, #weeklyRepeatRow").fadeOut(); + } else { + $("#daysOfWeek, #weeklyRepeatRow").fadeIn(); + } + }); + $("#weeklyRepeat").change( function () { + if($(this).val() !== ""){ + $("#dayOfMonthRow").fadeOut(); + } else { + $("#dayOfMonthRow").fadeIn(); + } }); } }; diff --git a/models/front/events/frontAdd.php b/models/front/events/frontAdd.php index 3ec2191..df94f30 100644 --- a/models/front/events/frontAdd.php +++ b/models/front/events/frontAdd.php @@ -7,7 +7,10 @@ */ require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataEvents.php'; +require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataCategories.php'; require_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/baseAction.php'; +require_once(GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php'); + require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php'; /** * GLmMembersFront_event_fontAdd @@ -21,6 +24,37 @@ require_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/baseAction.p */ class GLmMembersFront_events_frontAdd extends GlmDataEvents { + + + /* getCityId + * + * Given a city name find and return the id of the city. + * If a city cannot be found then create city with that name. + * + * @param mixed $cityName Name of the city + * + * @access public + * @return id of city + */ + public function getCityId($cityName) + { + $sql = " + SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities + WHERE name like '" . esc_sql( trim( $cityName ) ) . "'"; + $cityId = $this->wpdb->get_row($sql, ARRAY_A); + if ( !$cityId ) { + // then add the city to the city table + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities', + array( 'name' => trim( $cityName ) ), + array( '%s' ) + ); + return $this->wpdb->insert_id; + } else { + return $cityId['id']; + } + } /** * modelAction * @@ -31,23 +65,61 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents */ public function modelAction($actionData = false) { + // populate category dropdown + $categories = new GlmDataEventsCategories($this->wpdb, $this->config); + $cats = $categories->getList(); + foreach($cats as $cat){ + $eventCategories[] = $cat; + } + + // Load recurrences class + $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config); + + //Load Events class $events = new GlmDataEvents($this->wpdb, $this->config ); $newEvent = $events->newEntry(); + // if form is submitted if($_REQUEST['newEvent'] == "Add Event"){ // parse dates and times date_default_timezone_set('America/New_York'); - $date = date('y/m/d h:i:s a', time()); + $date = date('y/m/d H:i:s a', time()); $starting = trim(filter_var($_REQUEST['starting'], FILTER_SANITIZE_STRING)); - $startTime = trim(filter_var($_REQUEST['shour'],FILTER_SANITIZE_STRING)) . ':' . trim(filter_var($_REQUEST['smin'],FILTER_SANITIZE_STRING)) . " " . trim(filter_var($_REQUEST['sampam'],FILTER_SANITIZE_STRING)) ; - $smilitaryTime = date("H:i:s", strtotime($startTime)); + $ending = trim(filter_var($_REQUEST['ending'], FILTER_SANITIZE_STRING)); + + + + // if there are no times selected, default the start time to midnight and the endtime to 12:00pm as it is in the admin + if(empty($_REQUEST['ehour']) || empty($_REQUEST['emin'])){ + $startTimeOnly = true; + $emilitaryTime = "12:00:00"; + } else { + $endTime = trim(filter_var($_REQUEST['ehour'],FILTER_SANITIZE_STRING)) . ':' . trim(filter_var($_REQUEST['emin'],FILTER_SANITIZE_STRING)) . " " . trim(filter_var($_REQUEST['eampm'],FILTER_SANITIZE_STRING)); + + $emilitaryTime = date("H:i:s", strtotime($endTime)); + } + + + if(empty($_REQUEST['shour']) || empty($_REQUEST['smin'])){ + $smilitaryTime = "12:00:00"; + } else { + $startTime = trim(filter_var($_REQUEST['shour'],FILTER_SANITIZE_STRING)) . ':' . trim(filter_var($_REQUEST['smin'],FILTER_SANITIZE_STRING)) . " " . trim(filter_var($_REQUEST['sampm'],FILTER_SANITIZE_STRING)); + + $smilitaryTime = date("H:i:s", strtotime($startTime)); + } + + + if(empty($_REQUEST['shour']) || empty($_REQUEST['smin']) && empty($_REQUEST['ehour']) || empty($_REQUEST['emin'])){ + $allDay = true; + } + + + + $starting_date = strtotime($starting . " " . $smilitaryTime); $mysqlStart = date("Y-m-d H:i:s",$starting_date); - $ending = trim(filter_var($_REQUEST['ending'], FILTER_SANITIZE_STRING)); - $endTime = trim(filter_var($_REQUEST['ehour'],FILTER_SANITIZE_STRING)) . ':' . trim(filter_var($_REQUEST['emin'],FILTER_SANITIZE_STRING)) . " " . trim(filter_var($_REQUEST['eampam'],FILTER_SANITIZE_STRING)) ; - $emilitaryTime = date("H:i:s", strtotime($endTime)); $ending_date = strtotime($ending . " " . $emilitaryTime); $mysqlEnd = date("Y-m-d H:i:s",$ending_date); @@ -55,12 +127,17 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents $name = trim(filter_var($_REQUEST['event_name'],FILTER_SANITIZE_STRING)); $intro = trim(filter_var($_REQUEST['intro'],FILTER_SANITIZE_STRING)); $descr = trim(filter_var($_REQUEST['descr'],FILTER_SANITIZE_STRING)); - $cost = trim(filter_var($_REQUEST['event_cost'],FILTER_SANITIZE_STRING)); + $cost = trim(filter_var($_REQUEST['cost'],FILTER_SANITIZE_STRING)); $url = trim(filter_var($_REQUEST['url'],FILTER_SANITIZE_STRING)); $admin_name = trim(filter_var($_REQUEST['admin_name'],FILTER_SANITIZE_STRING)); $admin_org = trim(filter_var($_REQUEST['admin_org'],FILTER_SANITIZE_STRING)); + $adminPhone = trim(filter_var($_REQUEST['admin_phone'],FILTER_SANITIZE_STRING)); + $adminEmail = trim(filter_var($_REQUEST['admin_email'],FILTER_SANITIZE_STRING)); + $facebook = trim(filter_var($_REQUEST['facebook'],FILTER_SANITIZE_STRING)); + $twitter = trim(filter_var($_REQUEST['twitter'],FILTER_SANITIZE_STRING)); - // locations table data + $contactFirst = trim(filter_var($_REQUEST['contact_fname'],FILTER_SANITIZE_STRING)); + $contactLast = trim(filter_var($_REQUEST['contact_lname'],FILTER_SANITIZE_STRING)); $place = trim(filter_var($_REQUEST['place'],FILTER_SANITIZE_STRING)); $address = trim(filter_var($_REQUEST['address'],FILTER_SANITIZE_STRING)); $city = trim(filter_var($_REQUEST['city'],FILTER_SANITIZE_STRING)); @@ -68,21 +145,128 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents $zip = trim(filter_var($_REQUEST['zip'],FILTER_SANITIZE_STRING)); $contactEmail = trim(filter_var($_REQUEST['contact_email'],FILTER_SANITIZE_STRING)); $contactPhone = trim(filter_var($_REQUEST['contact_phone'],FILTER_SANITIZE_STRING)); + $fileDescr = trim(filter_var($_REQUEST['fileDescription'],FILTER_SANITIZE_STRING)); + $weekOfMonth = $_REQUEST['weekom']; + $weekofMonth = pow(2, $weekOfMonth); + + $category = $_REQUEST['categories']; + // set boolean values based on selected recurrence options + if(!empty($dayOfMonth = $_REQUEST['dayom'])){ + $dayOfMonth = pow(2, $dayOfMonth); + $byDayOfMonth = true; + echo $dayOfMonth; + } else { + $byDayOfMonth = false; + } + + if(empty($_REQUEST['free'])){ + $free = false; + } else { + $free = true; + } + if(empty($_REQUEST['repeating'])){ + $repeating = false; + } else { + $repeating = $_REQUEST['repeating']; + } + if(empty($_REQUEST['allday'])){ + $allDay = false; +// $startTimeOnly = false; + } else { + $allDay = $_REQUEST['allday']; +// $startTimeOnly = true; + } + //get days of the week values for recurrences + foreach($_REQUEST['daysow'] as $check){ + $daysOfWeek[] = $check; + } + foreach($daysOfWeek as $key=>$value){ + if(!empty($value)){ + $days += $value; + } + } + + $city = $this->getCityId($city); + // image upload settings + $image = $_FILES['image_new']; + $imageName = $image['name']; + $imageTmp = $image['tmp_name']; + $imageSize = $image['size']; + $imageError = $image['error']; + + $temp = explode('.', $imageName); + $imageExt = array_pop($temp); + $imageExt = strtolower($imageExt); + $tmpName = implode('.', $temp); + + $allowed = array('jpeg', 'png', 'jpg', 'bmp', 'gif','svg'); + if(in_array($imageExt, $allowed)){ + if($imageError === 0){ + if($imageSize <= 1000000){ + $imageName = $tmpName . "-" . uniqid() . "." . $imageExt; + $imgUrl = GLM_MEMBERS_PLUGIN_MEDIA_PATH . "/images/small/" . $imageName; + if(!file_exists($imgUrl)){ + if(move_uploaded_file($imageTmp, $imgUrl)){ + + } + } else { + echo "Image Already Exists"; + } + } + } + } + //file upload settings + $file = $_FILES['file_rmv']; + $fileName = $file['name']; + $fileTmp = $file['tmp_name']; + $fileSize = $file['size']; + $fileError = $file['error']; + + $temp = explode('.', $fileName); + $fileExt = array_pop($temp); + $fileExt = strtolower($fileExt); + $tmpName = implode('.', $temp); + $allowed = array('txt', 'pdf', 'docx', 'odt', 'xls', 'doc'); + if(in_array($fileExt, $allowed)){ + if($fileError === 0){ + if($fileSize <= 2000000){ + $fileName = $tmpName . "-" . uniqid() . "." . $fileExt; + $fileUrl = GLM_MEMBERS_PLUGIN_MEDIA_PATH . "/files/" .$fileName; + if(!file_exists($fileUrl)){ + if(move_uploaded_file($fileTmp, $fileUrl)){ + + } + } else { + echo "File Already Exists"; + } + } + } + } + // mySql transactions $eventData = array( - 'status' => '20', - 'created' => $date, - 'updated' => $date, - 'name' => $name, - 'intro' => $intro, - 'descr' => $descr, - 'image' => $event['img'], - 'cost' => $cost, - 'url' => $url, - 'admin_name' => $admin_name, - 'admin_org' => $admin_org + 'status' => '20', + 'created' => $date, + 'updated' => $date, + 'name' => $name, + 'intro' => $intro, + 'descr' => $descr, + 'image' => $imageName, + 'file1' => $fileName, + 'file1_descr' => $fileDescr, + 'cost' => $cost, + 'free' => $free, + 'url' => $url, + 'contact_phone' => $contactPhone, + 'admin_name' => $admin_name, + 'admin_phone' => $adminPhone, + 'admin_email' => $adminEmail, + 'contact_name' => $contactFirst . " " . $contactLast, + 'contact_email' => $contactEmail, + 'contact_email' => $contactPhone, + 'admin_org' => $admin_org ); $this->wpdb->insert( GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events', @@ -95,36 +279,34 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents '%s', '%s', '%s', - '%d', '%s', '%s', '%s', - ) - ); - $lastID = $this->wpdb->insert_id; - $timeData = array( - 'event' => $lastID, - 'start_time' => $mysqlStart, - 'end_time' => $mysqlEnd, - ); - $this->wpdb->insert( - GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'times', - $timeData, - array( - '%d', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', '%s', '%s' ) - ); + ); + $eventID = $this->wpdb->insert_id; + $locationData = array( - 'event' => $lastID, - 'name' => $place, - 'address' => $address, - 'city' => $city, - 'state' => $state, - 'zip' => $zip, - 'phone' => $contactPhone, - 'email' => $contactEmail + 'event' => $eventID, + 'name' => $place, + 'address' => $address, + 'city' => $city, + 'state' => $state, + 'zip' => $zip, + 'phone' => $contactPhone, + 'contact_fname' => $contactFirst, + 'contact_lname' => $contactLast, + 'email' => $contactEmail ); $this->wpdb->insert( @@ -138,16 +320,98 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents '%s', '%s', '%s', + '%s', + '%s', '%s' ) ); - } - + $ending = date("Y-m-d", strtotime($ending)); + $starting = date("Y-m-d", strtotime($starting)); + $recurData =array( + 'event' => $eventID, + 'start_time' => $smilitaryTime, + 'end_time' => $emilitaryTime, + 'from_date' => $starting, + 'to_date' => $ending, + 'all_day' => $allDay, + 'recurring' => $repeating, + 'day_of_month' => $dayOfMonth, + 'week_of_month' => $weekOfMonth, + 'start_time_only' => $startTimeOnly, + 'day_of_week' => $days, + 'by_day_of_month' => $byDayOfMonth, + 'last_day_of_month' => $lastDayOfMonth + ); + $this->wpdb->insert( + GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences', + $recurData, + array( + '%d', + '%s', + '%s', + '%s', + '%s', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d', + '%d' + ) + ); + $recurID = $this->wpdb->insert_id; + $timeData = array( + 'event' => $eventID, + 'start_time' => $mysqlStart, + 'end_time' => $mysqlEnd, + 'recur_id' => $recurID, + 'all_day' => $allDay + ); + $this->wpdb->insert( + GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'times', + $timeData, + array( + '%d', + '%s', + '%s', + '%d', + '%d' + ) + ); + $categoryData = array( + 'event' => $eventID, + 'category' => $category + ); + $this->wpdb->insert( + GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories', + $categoryData, + array( + '%d', + '%d' + ) + ); + + + // Send confirmation email + $to = 'anthony@localhost'; + $subject = 'Event Form Submission'; + $message = "Thank you for submitting your event! \r\n". "Event Name: " . $name . "\r\n" . + "Scheduled for: " . $starting ; + $headers = 'From: webmaster@example.com' . "\r\n" . + 'Reply-To: webmaster@example.com' . "\r\n" . + 'X-Mailer: PHP/' . phpversion(); + + mail($to, $subject, $message, $headers); + } + +// echo '
', print_r($cats), '
'; // Compile template data $templateData = array( 'siteBaseUrl' => GLM_MEMBERS_EVENTS_SITE_BASE_URL, 'currentUrl' => $_SERVER['HTTP_REFERER'], - 'categories' => $categories, + 'categories' => $eventCategories, 'fromDate' => $fromDate, 'event' => $newEvent, 'permalink' => $permalink, diff --git a/views/front/events/frontAdd.html b/views/front/events/frontAdd.html index 3ce053e..d5d2907 100644 --- a/views/front/events/frontAdd.html +++ b/views/front/events/frontAdd.html @@ -1,29 +1,39 @@

Add Your Event

-
+ + - + - - - + + - - + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + +
Event Name:Event Name: - - {if $event.fieldFail.name}

{$event.fieldFail.name}

{/if}
+ + {if $event.fieldFail.event_name}

{$event.fieldFail.event_name}

{/if}
Start Date Start Date
End Date End Date
All Day Event + + +
Start Time - + @@ -36,20 +46,20 @@ -  :  :   
End Time
Repeating Event + +
+ +
+ +
+ + + + + + + + + + + + + + + +
Categories + + +
Web Address (URL): @@ -110,6 +191,12 @@
Free Event + +
Cost: @@ -150,8 +237,6 @@ {/if}
New image:
-
- {if $event.fieldFail.image}

{$event.fieldFail.image}

{/if} @@ -159,7 +244,7 @@ - + @@ -167,7 +252,7 @@ - + @@ -175,17 +260,214 @@ - + - - - - - - - + State: + + + + @@ -198,8 +480,10 @@ - - + + + + @@ -215,61 +499,58 @@ - + - + - + - + - + - + - + - + + - + - + - + - - + - + - - -