diff options
Diffstat (limited to 'includes/public')
-rw-r--r-- | includes/public/shortcodes/giglog_bands.php | 228 | ||||
-rw-r--r-- | includes/public/shortcodes/giglog_display_unprocessed.php | 306 | ||||
-rw-r--r-- | includes/public/shortcodes/giglog_process_files.php | 134 |
3 files changed, 334 insertions, 334 deletions
diff --git a/includes/public/shortcodes/giglog_bands.php b/includes/public/shortcodes/giglog_bands.php index 76187ab..b299644 100644 --- a/includes/public/shortcodes/giglog_bands.php +++ b/includes/public/shortcodes/giglog_bands.php @@ -1,114 +1,114 @@ -<?php
-/*
- * code used for giglogadmin for the open page where everyone sees the list of
- * concerts. First function displays filters by city, venue and the second one
- * builds the table with concerts
- */
-
-function giglogadmin_getfilters()
-{
- global $wpdb;
-
- //echo (var_dump($_POST["selectvenue"]));
-
- $results = $wpdb->get_results('select distinct wpgvenue_city from wpg_venues');
- $select = '<form method="POST" action=""><select name="selectcity">';
- $select .= '<option value="ALL" ';
- if (isset($_POST["selectcity"]) && $_POST["selectcity"] == "ALL") {
- $select .= ' selected = "selected"';
- }
- $select .= '> All cities</option>';
- foreach ($results AS $row) {
- $select .= '<option value="' . $row->wpgvenue_city . '"';
- if (isset($_POST["selectcity"]) && $_POST["selectcity"] == $row->wpgvenue_city) {
- $select .= ' selected = "selected"';
- }
- $select .= ' >' . $row->wpgvenue_city . '</option>';
- }
-
- if (isset($_POST["selectcity"]) && $_POST["selectcity"] != "ALL") {
- $select .= '</select>';
- //second drop down for venue
-
- $vquery = "select id, wpgvenue_name from wpg_venues";
- $vquery .= " where wpgvenue_city='" . $_POST["selectcity"] . "'";
- $resultsv = $wpdb->get_results($vquery);
- $select .= '<select name="selectvenue">';
- $select .= '<option value="0" ';
- if (isset($_POST["selectvenue"]) && $_POST["selectvenue"] == "0") {
- $select .= ' selected = "selected"';
- }
- $select .= '> All venues</option>';
-
- foreach ($resultsv AS $rowv) {
- $select .= '<option value="' . $rowv->id . '"';
- if (isset($_POST["selectvenue"]) && $_POST["selectvenue"] == $rowv->id) {
- $select .= ' selected = "selected"';
- }
- $select .= ' >' . $rowv->wpgvenue_name . '</option>';
- }
- //end IF that checks if city was selected
- }
- $select .= '</select><input type="submit" value="Filter"></form>';
- return $select;
-}
-
-
-function giglogadmin_getconcerts()
-{
- global $wpdb;
- // Shortcodes RETURN content, so store in a variable to return
- $content = '<table class="concertstb">';
- // $content .= '</tr><th>CITY</th><th>ID</th><th>BAND</th><th>VENUE</th><th>DATE</th><th>TICKETS</th><th>EVENT</th></tr>';
- $content .= '<tr class="concertshrow"><th>CITY</th><th>BAND</th><th>VENUE</th><th>DATE</th><th>TICKETS</th><th>EVENT</th></tr>';
- // Use the submitted "city" if any. Otherwise, use the default/static value.
- $cty = filter_input(INPUT_POST, 'selectcity');
- $cty = $cty ? $cty : 'ALL';
-
- $venue = filter_input(INPUT_POST, 'selectvenue');
- //echo($_POST['selectvenue']);
- $venue = $venue ? $venue : '0';
-
-
- $query = "SELECT wpgc.id, wpgb.wpgband_name as band ,wpgv.wpgvenue_name as venue ,wpgc.wpgconcert_date, wpgc.wpgconcert_tickets, wpgc.wpgconcert_event, wpgv.wpgvenue_city, wpgv.wpgvenue_webpage
- FROM wpg_concerts wpgc, wpg_bands wpgb, wpg_venues wpgv
-where wpgc.band=wpgb.id
-and wpgc.venue = wpgv.id
-and wpgconcert_date >= CURDATE()";
- $query .= ($cty == "ALL") ? "" : " and wpgv.wpgvenue_city='" . $cty . "'";
- $query .= ($venue == "0") ? "" : " and wpgv.id='" . $venue . "'";
- $query .= " order by wpgv.wpgvenue_city, wpgconcert_date, wpgc.id";
- //echo($query);
- $results = $wpdb->get_results($query);
-
-
- $lastType = '';
- foreach ($results AS $row) {
- $content .= '<tr class="concertsrow">';
-
- if ($lastType != '' && $lastType != $row->wpgvenue_city) {
- $content .= '<td class="concertstd">' . $row->wpgvenue_city . '</td></tr><tr>';
- }
-
- if ($lastType == '') {
- $content .= '<td>' . $row->wpgvenue_city . '</td></tr><tr>';
- }
- // Modify these to match the database structure
- // $content .= '<td>' . $row->id. '</td>';
- $content .= '<td></td>';
- $content .= '<td>' . $row->band . '</td>';
- $content .= '<td>' . $row->venue . '</td>';
- $fdate = strtotime($row->wpgconcert_date);
- $newformat = date('d.M.Y', $fdate);
-
- //$content .= DATE_FORMAT($fdate,'%d.%b.%Y');
- $content .= '<td>' . $newformat . '</td>';
- $content .= '<td><a href="' . $row->wpgconcert_tickets . '" target="_blank">Tickets</a></td>';
- $content .= '<td><a href="' . $row->wpgconcert_event . '" target="_blank">Event link</a></td>';
- $content .= '</tr>';
- $lastType = $row->wpgvenue_city;
- }
- $content .= '</table>';
- // return the table
- return $content;
-}
+<?php +/* + * code used for giglogadmin for the open page where everyone sees the list of + * concerts. First function displays filters by city, venue and the second one + * builds the table with concerts + */ + +function giglogadmin_getfilters() +{ + global $wpdb; + + //echo (var_dump($_POST["selectvenue"])); + + $results = $wpdb->get_results('select distinct wpgvenue_city from wpg_venues'); + $select = '<form method="POST" action=""><select name="selectcity">'; + $select .= '<option value="ALL" '; + if (isset($_POST["selectcity"]) && $_POST["selectcity"] == "ALL") { + $select .= ' selected = "selected"'; + } + $select .= '> All cities</option>'; + foreach ($results AS $row) { + $select .= '<option value="' . $row->wpgvenue_city . '"'; + if (isset($_POST["selectcity"]) && $_POST["selectcity"] == $row->wpgvenue_city) { + $select .= ' selected = "selected"'; + } + $select .= ' >' . $row->wpgvenue_city . '</option>'; + } + + if (isset($_POST["selectcity"]) && $_POST["selectcity"] != "ALL") { + $select .= '</select>'; + //second drop down for venue + + $vquery = "select id, wpgvenue_name from wpg_venues"; + $vquery .= " where wpgvenue_city='" . $_POST["selectcity"] . "'"; + $resultsv = $wpdb->get_results($vquery); + $select .= '<select name="selectvenue">'; + $select .= '<option value="0" '; + if (isset($_POST["selectvenue"]) && $_POST["selectvenue"] == "0") { + $select .= ' selected = "selected"'; + } + $select .= '> All venues</option>'; + + foreach ($resultsv AS $rowv) { + $select .= '<option value="' . $rowv->id . '"'; + if (isset($_POST["selectvenue"]) && $_POST["selectvenue"] == $rowv->id) { + $select .= ' selected = "selected"'; + } + $select .= ' >' . $rowv->wpgvenue_name . '</option>'; + } + //end IF that checks if city was selected + } + $select .= '</select><input type="submit" value="Filter"></form>'; + return $select; +} + + +function giglogadmin_getconcerts() +{ + global $wpdb; + // Shortcodes RETURN content, so store in a variable to return + $content = '<table class="concertstb">'; + // $content .= '</tr><th>CITY</th><th>ID</th><th>BAND</th><th>VENUE</th><th>DATE</th><th>TICKETS</th><th>EVENT</th></tr>'; + $content .= '<tr class="concertshrow"><th>CITY</th><th>BAND</th><th>VENUE</th><th>DATE</th><th>TICKETS</th><th>EVENT</th></tr>'; + // Use the submitted "city" if any. Otherwise, use the default/static value. + $cty = filter_input(INPUT_POST, 'selectcity'); + $cty = $cty ? $cty : 'ALL'; + + $venue = filter_input(INPUT_POST, 'selectvenue'); + //echo($_POST['selectvenue']); + $venue = $venue ? $venue : '0'; + + + $query = "SELECT wpgc.id, wpgb.wpgband_name as band ,wpgv.wpgvenue_name as venue ,wpgc.wpgconcert_date, wpgc.wpgconcert_tickets, wpgc.wpgconcert_event, wpgv.wpgvenue_city, wpgv.wpgvenue_webpage + FROM wpg_concerts wpgc, wpg_bands wpgb, wpg_venues wpgv +where wpgc.band=wpgb.id +and wpgc.venue = wpgv.id +and wpgconcert_date >= CURDATE()"; + $query .= ($cty == "ALL") ? "" : " and wpgv.wpgvenue_city='" . $cty . "'"; + $query .= ($venue == "0") ? "" : " and wpgv.id='" . $venue . "'"; + $query .= " order by wpgv.wpgvenue_city, wpgconcert_date, wpgc.id"; + //echo($query); + $results = $wpdb->get_results($query); + + + $lastType = ''; + foreach ($results AS $row) { + $content .= '<tr class="concertsrow">'; + + if ($lastType != '' && $lastType != $row->wpgvenue_city) { + $content .= '<td class="concertstd">' . $row->wpgvenue_city . '</td></tr><tr>'; + } + + if ($lastType == '') { + $content .= '<td>' . $row->wpgvenue_city . '</td></tr><tr>'; + } + // Modify these to match the database structure + // $content .= '<td>' . $row->id. '</td>'; + $content .= '<td></td>'; + $content .= '<td>' . $row->band . '</td>'; + $content .= '<td>' . $row->venue . '</td>'; + $fdate = strtotime($row->wpgconcert_date); + $newformat = date('d.M.Y', $fdate); + + //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); + $content .= '<td>' . $newformat . '</td>'; + $content .= '<td><a href="' . $row->wpgconcert_tickets . '" target="_blank">Tickets</a></td>'; + $content .= '<td><a href="' . $row->wpgconcert_event . '" target="_blank">Event link</a></td>'; + $content .= '</tr>'; + $lastType = $row->wpgvenue_city; + } + $content .= '</table>'; + // return the table + return $content; +} diff --git a/includes/public/shortcodes/giglog_display_unprocessed.php b/includes/public/shortcodes/giglog_display_unprocessed.php index 05fbb97..dad05f2 100644 --- a/includes/public/shortcodes/giglog_display_unprocessed.php +++ b/includes/public/shortcodes/giglog_display_unprocessed.php @@ -1,153 +1,153 @@ -<?php
-/*
- * I kinda overloaded this snippet. Added comments for each function. But this
- * is used in the giglog admin page, which should only be available to admin
- * users. After the file is being uploaded into the concertlists folder, its
- * content is written into wpg_files. Then the content is split into lines and
- * each line is transformed intoa concert
- */
-
-/* this checks th wpg_files table to see if any file is uploaded but hasn't
- * gone through the processing process - aka fetching each line and
- * transforming it into a concert line
- */
-function giglogadmin_getunprocessed()
-{
- global $wpdb;
-
- $content = '<br /><h3> UNPROCESSED ROWS</h3><table class="concertstable">';
- $content .= '<tr class="concertsheaderrow"><th>Filerow</th><th>FILENAME</th><th>DATE</TH><th>UploadedContent</th>';
- $query = 'SELECT rowid,filename,filedate,rowcontent from wpg_files where processed="N"';
- $results = $wpdb->get_results($query);
- foreach ($results AS $row) {
- $content .= '<tr>';
- $content .= '<td>' . $row->rowid . '</td>';
- $content .= '<td>' . $row->filename . '</td>';
- $content .= '<td>' . $row->filedate . '</td>';
- $content .= '<td>' . $row->rowcontent . '</td>';
- $content .= '</tr>';
- }
- $content .= '</table>';
- return $content;
-}
-
-/* function that goes through each line of the unprocessed file. Each line is
- * checked against the concerts table. if it exists - concert and date and
- * venue - it does nothing with it. If it doesn't exist, it checks if band or
- * venue exists. If they don't, they get created, if they do, their ID from
- * their table is fetchd and used in concerts table
- */
-function giglogadmin_insertconcerts()
-{
- global $wpdb;
- $concertlist = '<p>Inserted the following:</p>';
- $newconcert= [];
- $query1 = 'SELECT id,rowid,filename,filedate,rowcontent from wpg_files where processed="N"';
- $cresults = $wpdb->get_results($query1);
- foreach ($cresults AS $row) {
- $rowfileid = $row->id;
- $resultArray = explode("\t", $row->rowcontent);
- $band = $resultArray[0];
- $venue = $resultArray[1];
- $condate = date('Y-m-d', strtotime($resultArray[2]));
- $ticketlink = $resultArray[3];
- $eventlink = $resultArray[4];
- //first item in the row should be band $resultArray[0]; second should be venue $resultArray[1]; third should be concert date $resultArray[2];
- //fourth item is ticketlink $resultArray[3]; fifth item is eventlink $resultArray[4];
-
- //processing band
- $bandsql = 'SELECT id FROM wpg_bands WHERE upper(wpgband_name)="' . $band . '"';
- $results = $wpdb->get_results($bandsql);
- if ($results)
- $newconcert[0] = $results[0]->id;
- else {
- $wpdb->insert('wpg_bands', array(
- 'id' => '',
- 'wpgband_name' => $band
- ));
- echo ($wpdb->last_error);
- $newconcert[0] = $wpdb->insert_id;
- }
- //done processing band
-
- //processing venue
- if (is_numeric($venue))
- $newconcert[1] = $venue;
- else {
- $venuesql = 'SELECT id FROM wpg_venues WHERE upper(wpgvenue_name)="' . $venue . '"';
- $results = $wpdb->get_results($venuesql);
- if ($results)
- $newconcert[1] = $results[0]->id;
- else {
- $wpdb->insert('wpg_venues', array(
- 'id' => '',
- 'wpgvenue_name' => $venue
- ));
- echo ($wpdb->last_error);
- $newconcert[1] = $wpdb->insert_id;
- }
- }
- //done processing venue
-
- //not sure how to check dates, hopefully manual verification of files will take care of it
-
- //check if concert already exists and return ID if it does. Not checking by date, to be considered
- $csql = 'SELECT id from wpg_concerts where band = ' . $newconcert[0] . ' and venue = ' . $newconcert[1] . ' and wpgconcert_date ="' . $condate . '"';
-
- $cresults = $wpdb->get_results($csql);
- if ($cresults) {
- $usql = 'UPDATE wpg_files SET processed="D", wpgc_id = ' . $cresults[0]->id . ' WHERE id = ' . $rowfileid;
-
- $uresults = $wpdb->get_results($usql);
- $concertlist .= 'DUPLICATE ROW detected BAND ' . $band . ' with band ID ' . $newconcert[0];
- $concertlist .= ', VENUE ' . $venue . ' with venue ID ' . $newconcert[1];
- $concertlist .= ', CONCERTDATE ' . $condate;
- $concertlist .= ' <br />';
- } else {
- $wpdb->insert('wpg_concerts', array(
- 'id' => '',
- 'band' => $newconcert[0],
- 'venue' => $newconcert[1],
- 'wpgconcert_date' => $condate,
- 'wpgconcert_tickets' => $ticketlink,
- 'wpgconcert_event' => $eventlink
- ));
- echo ($wpdb->last_error);
- $newconcertid = $wpdb->insert_id;
-
- $usql = 'UPDATE wpg_files SET processed="Y", wpgc_id = ' . $newconcertid . ' WHERE id = ' . $rowfileid;
-
- $uresults = $wpdb->get_results($usql);
- $concertlist .= 'BAND ' . $band . ' with band ID ' . $newconcert[0];
- $concertlist .= ', VENUE ' . $venue . ' with venue ID ' . $newconcert[1];
- $concertlist .= ', CONCERTDATE ' . $condate . ', Ticket LINK ' . $ticketlink . ', event LINK' . $eventlink;
- $concertlist .= ' <br />';
-
- }
-
- //end check if concert exists
-
-
- //remember to add the concert ID when displaying
-
-
- } //end looping through unprocessed rows
-
- return $concertlist;
-}
-
-function giglogadmin_display_unprocessed() {
- $output = giglogadmin_getunprocessed();
-
- $output .= '<form method="POST" action=""><input type="submit" name="ProcessConcerts" value="ProcessConcerts"/></form>';
-
-
- if (isset($_POST['ProcessConcerts'])) {
- $output .= giglogadmin_insertconcerts();
-
- //$url2 = $_SERVER['REQUEST_URI'];
- //header("Refresh: 5; URL=$url2"); //reload page
- } //end if button for process concerts is pressed
-
- return $output;
-}
+<?php +/* + * I kinda overloaded this snippet. Added comments for each function. But this + * is used in the giglog admin page, which should only be available to admin + * users. After the file is being uploaded into the concertlists folder, its + * content is written into wpg_files. Then the content is split into lines and + * each line is transformed intoa concert + */ + +/* this checks th wpg_files table to see if any file is uploaded but hasn't + * gone through the processing process - aka fetching each line and + * transforming it into a concert line + */ +function giglogadmin_getunprocessed() +{ + global $wpdb; + + $content = '<br /><h3> UNPROCESSED ROWS</h3><table class="concertstable">'; + $content .= '<tr class="concertsheaderrow"><th>Filerow</th><th>FILENAME</th><th>DATE</TH><th>UploadedContent</th>'; + $query = 'SELECT rowid,filename,filedate,rowcontent from wpg_files where processed="N"'; + $results = $wpdb->get_results($query); + foreach ($results AS $row) { + $content .= '<tr>'; + $content .= '<td>' . $row->rowid . '</td>'; + $content .= '<td>' . $row->filename . '</td>'; + $content .= '<td>' . $row->filedate . '</td>'; + $content .= '<td>' . $row->rowcontent . '</td>'; + $content .= '</tr>'; + } + $content .= '</table>'; + return $content; +} + +/* function that goes through each line of the unprocessed file. Each line is + * checked against the concerts table. if it exists - concert and date and + * venue - it does nothing with it. If it doesn't exist, it checks if band or + * venue exists. If they don't, they get created, if they do, their ID from + * their table is fetchd and used in concerts table + */ +function giglogadmin_insertconcerts() +{ + global $wpdb; + $concertlist = '<p>Inserted the following:</p>'; + $newconcert= []; + $query1 = 'SELECT id,rowid,filename,filedate,rowcontent from wpg_files where processed="N"'; + $cresults = $wpdb->get_results($query1); + foreach ($cresults AS $row) { + $rowfileid = $row->id; + $resultArray = explode("\t", $row->rowcontent); + $band = $resultArray[0]; + $venue = $resultArray[1]; + $condate = date('Y-m-d', strtotime($resultArray[2])); + $ticketlink = $resultArray[3]; + $eventlink = $resultArray[4]; + //first item in the row should be band $resultArray[0]; second should be venue $resultArray[1]; third should be concert date $resultArray[2]; + //fourth item is ticketlink $resultArray[3]; fifth item is eventlink $resultArray[4]; + + //processing band + $bandsql = 'SELECT id FROM wpg_bands WHERE upper(wpgband_name)="' . $band . '"'; + $results = $wpdb->get_results($bandsql); + if ($results) + $newconcert[0] = $results[0]->id; + else { + $wpdb->insert('wpg_bands', array( + 'id' => '', + 'wpgband_name' => $band + )); + echo ($wpdb->last_error); + $newconcert[0] = $wpdb->insert_id; + } + //done processing band + + //processing venue + if (is_numeric($venue)) + $newconcert[1] = $venue; + else { + $venuesql = 'SELECT id FROM wpg_venues WHERE upper(wpgvenue_name)="' . $venue . '"'; + $results = $wpdb->get_results($venuesql); + if ($results) + $newconcert[1] = $results[0]->id; + else { + $wpdb->insert('wpg_venues', array( + 'id' => '', + 'wpgvenue_name' => $venue + )); + echo ($wpdb->last_error); + $newconcert[1] = $wpdb->insert_id; + } + } + //done processing venue + + //not sure how to check dates, hopefully manual verification of files will take care of it + + //check if concert already exists and return ID if it does. Not checking by date, to be considered + $csql = 'SELECT id from wpg_concerts where band = ' . $newconcert[0] . ' and venue = ' . $newconcert[1] . ' and wpgconcert_date ="' . $condate . '"'; + + $cresults = $wpdb->get_results($csql); + if ($cresults) { + $usql = 'UPDATE wpg_files SET processed="D", wpgc_id = ' . $cresults[0]->id . ' WHERE id = ' . $rowfileid; + + $uresults = $wpdb->get_results($usql); + $concertlist .= 'DUPLICATE ROW detected BAND ' . $band . ' with band ID ' . $newconcert[0]; + $concertlist .= ', VENUE ' . $venue . ' with venue ID ' . $newconcert[1]; + $concertlist .= ', CONCERTDATE ' . $condate; + $concertlist .= ' <br />'; + } else { + $wpdb->insert('wpg_concerts', array( + 'id' => '', + 'band' => $newconcert[0], + 'venue' => $newconcert[1], + 'wpgconcert_date' => $condate, + 'wpgconcert_tickets' => $ticketlink, + 'wpgconcert_event' => $eventlink + )); + echo ($wpdb->last_error); + $newconcertid = $wpdb->insert_id; + + $usql = 'UPDATE wpg_files SET processed="Y", wpgc_id = ' . $newconcertid . ' WHERE id = ' . $rowfileid; + + $uresults = $wpdb->get_results($usql); + $concertlist .= 'BAND ' . $band . ' with band ID ' . $newconcert[0]; + $concertlist .= ', VENUE ' . $venue . ' with venue ID ' . $newconcert[1]; + $concertlist .= ', CONCERTDATE ' . $condate . ', Ticket LINK ' . $ticketlink . ', event LINK' . $eventlink; + $concertlist .= ' <br />'; + + } + + //end check if concert exists + + + //remember to add the concert ID when displaying + + + } //end looping through unprocessed rows + + return $concertlist; +} + +function giglogadmin_display_unprocessed() { + $output = giglogadmin_getunprocessed(); + + $output .= '<form method="POST" action=""><input type="submit" name="ProcessConcerts" value="ProcessConcerts"/></form>'; + + + if (isset($_POST['ProcessConcerts'])) { + $output .= giglogadmin_insertconcerts(); + + //$url2 = $_SERVER['REQUEST_URI']; + //header("Refresh: 5; URL=$url2"); //reload page + } //end if button for process concerts is pressed + + return $output; +} diff --git a/includes/public/shortcodes/giglog_process_files.php b/includes/public/shortcodes/giglog_process_files.php index c3e3427..69a9a26 100644 --- a/includes/public/shortcodes/giglog_process_files.php +++ b/includes/public/shortcodes/giglog_process_files.php @@ -1,67 +1,67 @@ -<?php
-/*
- * snippet used to upload files with concerts. File is tab delimited file.
- * Band Venue Date TicketLink Eventlink. The form is at the end of this snippet
- */
-
-function giglogadmin_upload_files() {
- global $wpdb;
- $output = "";
- $dir = wp_upload_dir()['basedir'].'/concertlists/'; //the basedir is from file uploader plugin, namely the uploads folder in which I created a concertlist folder
- if ( !file_exists($dir) ) {
- mkdir( $dir );
- }
-
- $cfiles = scandir($dir);
- foreach ($cfiles as $value) { //list all files in directory
- $my_id = 0; //reset my_id which is used to check if anything was inserted
- if (strlen($value) > 3 and (is_dir($dir . '/' . $value) == false)) {
- $output .= 'Filename: ' . $value . '<br />';
- $filecontent = file_get_contents($dir . '/' . $value);
- $listcontent = str_replace(array(
- "\r",
- "\n"
- ), '<br />', $filecontent); //tring to replace end of lines with brs for html
-
- $output .= '<b>FILE CONTENT</b><br />';
- $r = 1;
- //processing each line of the file into a new row in wpg_files table
- if (isset($_POST['InsertFileContent'])) {
- $lines = new SplFileObject($dir . '/' . $value);
- //and then execute a sql query here
- $table = 'wpg_files';
- foreach ($lines as $newconcert) {
- $output .= '<li> ' . $newconcert . '</li>';
- $wpdb->insert($table, array(
- 'id' => '',
- 'filename' => $value,
- 'rowid' => $r,
- 'rowcontent' => $newconcert
- ));
- $r++;
- //$wpdb->print_error();
- $output .= $wpdb->last_error;
- $my_id = $wpdb->insert_id;
- $output .= '<br />---------------<br />Inserted rowID ' . $my_id . '<br />';
- } //end processing each line
- } //end file processing
-
-
- } //end if that checks whether filename is longer than 3 and is actually a file
-
- if ($my_id > 0) //if anything was inserted, move file to handled
- {
- $output .= '<br />File <b><i> ' . $value . ' </i></b> will be movedto handled folder';
- rename($dir . '/' . $value, $dir . '/handled/' . $value);
- }
-
- } //end looping through all folder content
-
- if ($my_id > 0) {
- $url1 = $_SERVER['REQUEST_URI'];
- header("Refresh: 5; URL=$url1");
- } //reload page
-
- $output .= '<form method="POST" action=""><input type="submit" name="InsertFileContent" value="InsertFileContent"/></form>';
- return $output;
-}
+<?php +/* + * snippet used to upload files with concerts. File is tab delimited file. + * Band Venue Date TicketLink Eventlink. The form is at the end of this snippet + */ + +function giglogadmin_upload_files() { + global $wpdb; + $output = ""; + $dir = wp_upload_dir()['basedir'].'/concertlists/'; //the basedir is from file uploader plugin, namely the uploads folder in which I created a concertlist folder + if ( !file_exists($dir) ) { + mkdir( $dir ); + } + + $cfiles = scandir($dir); + foreach ($cfiles as $value) { //list all files in directory + $my_id = 0; //reset my_id which is used to check if anything was inserted + if (strlen($value) > 3 and (is_dir($dir . '/' . $value) == false)) { + $output .= 'Filename: ' . $value . '<br />'; + $filecontent = file_get_contents($dir . '/' . $value); + $listcontent = str_replace(array( + "\r", + "\n" + ), '<br />', $filecontent); //tring to replace end of lines with brs for html + + $output .= '<b>FILE CONTENT</b><br />'; + $r = 1; + //processing each line of the file into a new row in wpg_files table + if (isset($_POST['InsertFileContent'])) { + $lines = new SplFileObject($dir . '/' . $value); + //and then execute a sql query here + $table = 'wpg_files'; + foreach ($lines as $newconcert) { + $output .= '<li> ' . $newconcert . '</li>'; + $wpdb->insert($table, array( + 'id' => '', + 'filename' => $value, + 'rowid' => $r, + 'rowcontent' => $newconcert + )); + $r++; + //$wpdb->print_error(); + $output .= $wpdb->last_error; + $my_id = $wpdb->insert_id; + $output .= '<br />---------------<br />Inserted rowID ' . $my_id . '<br />'; + } //end processing each line + } //end file processing + + + } //end if that checks whether filename is longer than 3 and is actually a file + + if ($my_id > 0) //if anything was inserted, move file to handled + { + $output .= '<br />File <b><i> ' . $value . ' </i></b> will be movedto handled folder'; + rename($dir . '/' . $value, $dir . '/handled/' . $value); + } + + } //end looping through all folder content + + if ($my_id > 0) { + $url1 = $_SERVER['REQUEST_URI']; + header("Refresh: 5; URL=$url1"); + } //reload page + + $output .= '<form method="POST" action=""><input type="submit" name="InsertFileContent" value="InsertFileContent"/></form>'; + return $output; +} |