From 0c437c746a8f964bf59ae9808a2b990d144bc39e Mon Sep 17 00:00:00 2001 From: AndreaChirulescu Date: Tue, 13 Apr 2021 19:23:59 +0200 Subject: Fixes of LF and extra spaces done by ATOM --- includes/admin/helpfiles/instr_photog.php | 2 +- includes/admin/helpfiles/instr_reviewers.php | 2 +- includes/admin/helpfiles/instrunctions.php | 2 +- includes/admin/views/giglog_admin_page.php | 64 ++--- includes/admin/views/giglog_import_gigs.php | 10 +- includes/concert.php | 314 ++++++++++----------- includes/public/shortcodes/giglog_bands.php | 228 +++++++-------- .../shortcodes/giglog_display_unprocessed.php | 306 ++++++++++---------- .../public/shortcodes/giglog_process_files.php | 134 ++++----- 9 files changed, 531 insertions(+), 531 deletions(-) diff --git a/includes/admin/helpfiles/instr_photog.php b/includes/admin/helpfiles/instr_photog.php index 34af4dd..510b95d 100644 --- a/includes/admin/helpfiles/instr_photog.php +++ b/includes/admin/helpfiles/instr_photog.php @@ -294,4 +294,4 @@ if ( !class_exists( 'Instructions_Photogs' ) ) { -?> \ No newline at end of file +?> diff --git a/includes/admin/helpfiles/instr_reviewers.php b/includes/admin/helpfiles/instr_reviewers.php index 51c2c48..b8d43d5 100644 --- a/includes/admin/helpfiles/instr_reviewers.php +++ b/includes/admin/helpfiles/instr_reviewers.php @@ -113,4 +113,4 @@ if ( !class_exists( 'Instructions_Reviewers' ) ) { } -?> \ No newline at end of file +?> diff --git a/includes/admin/helpfiles/instrunctions.php b/includes/admin/helpfiles/instrunctions.php index 3f5c49b..52019b5 100644 --- a/includes/admin/helpfiles/instrunctions.php +++ b/includes/admin/helpfiles/instrunctions.php @@ -55,4 +55,4 @@ Pick a help file to go through } -?> \ No newline at end of file +?> diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 8deba81..3f43873 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -41,8 +41,8 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) {

- - + '; return($select); } - + static function get_filters() { $cities = array_merge(["ALL"], GiglogAdmin_Venue::all_cities()); @@ -133,12 +133,12 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { return $select; } - + static function editforms() { global $wpdb; - $cid = filter_input(INPUT_POST, "cid"); - $c = GiglogAdmin_Concert::find_or_create($cid,'','','','',''); - + $cid = filter_input(INPUT_POST, "cid"); + $c = GiglogAdmin_Concert::find_or_create($cid,'','','','',''); + $content='
Form to create/edit concerts, bands, venues
' .'' .''.GiglogAdmin_AdminPage::get_allbands($c->band()).'
' @@ -148,21 +148,21 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { .'
'; if ($c->band()=='') //actions differ if we update or create a concert, hence two buttons needed $content.='

'; - else + else $content.='

'; $content.='
'; - + $content.='

' .'
' .''.GiglogAdmin_AdminPage::get_countries().'
' .'

' .'
'; - + $content.='

' .'
' .'
' .'

' - .'
'; + .''; return $content; } @@ -290,7 +290,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { // return the table return $content; } - + static function update() { @@ -330,49 +330,49 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { //$url2=$_SERVER['REQUEST_URI']; //doesn't seem to be needed actually, leaving here just in case //header("Refresh: 1; URL=$url2"); //reload page } - + if(isset($_POST['newconcert'])) { IF (empty($_POST['selectband']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) echo ''; - else - { + else + { GiglogAdmin_Concert::create($_POST['selectband'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl']); echo ''; - } + } } if(isset($_POST['editconcert'])) { IF (empty($_POST['selectband']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) echo ''; - else - { + else + { GiglogAdmin_Concert::updatec($_POST['pid'],$_POST['selectband'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl']); echo ''; - } - } - + } + } + if(isset($_POST['newband'])) { - IF (empty($_POST['bandname'])) //country is not checked as it is set to Norway by default + IF (empty($_POST['bandname'])) //country is not checked as it is set to Norway by default echo ''; - else - { - GiglogAdmin_Band::create($_POST['bandname'],$_POST['selectcountry']); + else + { + GiglogAdmin_Band::create($_POST['bandname'],$_POST['selectcountry']); echo ''; - } + } } - + if(isset($_POST['newvenue'])) { IF (empty($_POST['venuename']) || empty($_POST['venuecity'])) echo ''; - else - { - GiglogAdmin_Venue::create($_POST['venuename'],$_POST['venuecity']); + else + { + GiglogAdmin_Venue::create($_POST['venuename'],$_POST['venuecity']); echo ''; - } - } + } + } } static function assignconcert($p1, $c) diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php index d0520e7..ae34c2d 100644 --- a/includes/admin/views/giglog_import_gigs.php +++ b/includes/admin/views/giglog_import_gigs.php @@ -104,8 +104,8 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { $newconcert[1], $condate, $ticketlink, - $eventlink); - + $eventlink); + error_log( 'NEW CONCERT ADDED: ' . ' ID: ' . $id->id() . ' BAND ' . $band . ' with band ID ' . $newconcert[0] @@ -115,14 +115,14 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { . ', Event LINK ' . $eventlink); GiglogAdmin_Concertlogs::add($id->id()); - - /*the last line can be replaced by a trigger + + /*the last line can be replaced by a trigger CREATE TRIGGER `insertIntoPhotoLogs` AFTER INSERT ON `wpg_concerts` FOR EACH ROW INSERT INTO wpg_concertlogs ( wpg_concertlogs.id, wpg_concertlogs.wpgcl_concertid, wpg_concertlogs.wpgcl_status) - + VALUES (null, new.id, 1) */ diff --git a/includes/concert.php b/includes/concert.php index 5c50d43..e7165cc 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -1,157 +1,157 @@ -. - */ - -if ( !class_exists('GiglogAdmin_Concert') ) { - class GiglogAdmin_Concert - { - private $id; - private $band; - private $venue; - private $cdate; - private $tickets; - private $eventlink; - - /* - * Constructs a new venue object from an array of attributes. - * The attributes are expected to be named as in the database, - * so this constructor can be used to construct the object - * directly from the database row. - */ - private function __construct($attrs) - { - $this->id = isset($attrs->id) ? $attrs->id : NULL; - $this->band = isset($attrs->band) ? $attrs->band : NULL; - $this->venue = isset($attrs->venue) ? $attrs->venue : NULL; - $this->cdate = isset($attrs->wpgconcert_date) ? $attrs->wpgconcert_date : NULL; - $this->tickets = isset($attrs->wpgconcert_tickets) ? $attrs->wpgconcert_tickets : NULL; - $this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL; - } - - static function find_or_create($id,$band, $venue, $cdate, $ticketlink, $eventlink) - { - global $wpdb; - if($id) - { - $csql = 'SELECT * FROM wpg_concerts WHERE id="' . $id . '"'; - $results = $wpdb->get_results($csql); - - if ($results) - return new GiglogAdmin_Concert($results[0]); - } - else { - - return GiglogAdmin_Concert::create($band, $venue, $cdate, $ticketlink, $eventlink); - } - } - - public static function create($band, $venue, $cdate, $ticketlink, $eventlink) - { - $attrs = new stdClass(); - $attrs->id = ''; - $attrs->band = $band; - $attrs->venue = $venue; - $attrs->wpgconcert_date = $cdate; - $attrs->wpgconcert_tickets = $ticketlink; - $attrs->wpgconcert_event = $eventlink; - $cid = new GiglogAdmin_Concert($attrs); - $cid->save(); - - return $cid; - } - - - public static function updatec($id, $band, $venue, $cdate, $ticketlink, $eventlink) - { - global $wpdb; - - $res = $wpdb->update('wpg_concerts', array( - 'band' => $band, - 'venue' => $venue, - 'wpgconcert_date' => $cdate, - 'wpgconcert_tickets' => $ticketlink, - 'wpgconcert_event' => $eventlink - ), - array('id' => $id) - ); - - if ( !$res ) { - // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed - error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}"); - die; - } - - return ($wpdb->last_error); //not sure what to return here? - } - - public static function get($band, $venue, $date) - { - global $wpdb; - - $sql = 'SELECT id from wpg_concerts' - . ' where band = ' . $band - . ' and venue = ' . $venue - . ' and wpgconcert_date ="' . $date . '"'; - - error_log(__CLASS__ . '::' . __FUNCTION__ . ": {$sql}"); - return $wpdb->get_results($sql); - } - - public function save() - { - global $wpdb; - - $wpdb->insert('wpg_concerts', array( - 'id' => '', - 'band' => $this->band, - 'venue' => $this->venue, - 'wpgconcert_date' => $this->cdate, - 'wpgconcert_tickets' => $this->tickets, - 'wpgconcert_event' => $this->eventlink - )); - - $this->id = $wpdb->insert_id; - } - - public function id() - { - return $this->id; - } - - public function band() - { - return $this->band; - } - public function venue() - { - return $this->venue; - } - public function cdate() - { - return $this->cdate; - } - public function tickets() - { - return $this->tickets; - } - public function eventlink() - { - return $this->eventlink; - } - } -} -?> \ No newline at end of file +. + */ + +if ( !class_exists('GiglogAdmin_Concert') ) { + class GiglogAdmin_Concert + { + private $id; + private $band; + private $venue; + private $cdate; + private $tickets; + private $eventlink; + + /* + * Constructs a new venue object from an array of attributes. + * The attributes are expected to be named as in the database, + * so this constructor can be used to construct the object + * directly from the database row. + */ + private function __construct($attrs) + { + $this->id = isset($attrs->id) ? $attrs->id : NULL; + $this->band = isset($attrs->band) ? $attrs->band : NULL; + $this->venue = isset($attrs->venue) ? $attrs->venue : NULL; + $this->cdate = isset($attrs->wpgconcert_date) ? $attrs->wpgconcert_date : NULL; + $this->tickets = isset($attrs->wpgconcert_tickets) ? $attrs->wpgconcert_tickets : NULL; + $this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL; + } + + static function find_or_create($id,$band, $venue, $cdate, $ticketlink, $eventlink) + { + global $wpdb; + if($id) + { + $csql = 'SELECT * FROM wpg_concerts WHERE id="' . $id . '"'; + $results = $wpdb->get_results($csql); + + if ($results) + return new GiglogAdmin_Concert($results[0]); + } + else { + + return GiglogAdmin_Concert::create($band, $venue, $cdate, $ticketlink, $eventlink); + } + } + + public static function create($band, $venue, $cdate, $ticketlink, $eventlink) + { + $attrs = new stdClass(); + $attrs->id = ''; + $attrs->band = $band; + $attrs->venue = $venue; + $attrs->wpgconcert_date = $cdate; + $attrs->wpgconcert_tickets = $ticketlink; + $attrs->wpgconcert_event = $eventlink; + $cid = new GiglogAdmin_Concert($attrs); + $cid->save(); + + return $cid; + } + + + public static function updatec($id, $band, $venue, $cdate, $ticketlink, $eventlink) + { + global $wpdb; + + $res = $wpdb->update('wpg_concerts', array( + 'band' => $band, + 'venue' => $venue, + 'wpgconcert_date' => $cdate, + 'wpgconcert_tickets' => $ticketlink, + 'wpgconcert_event' => $eventlink + ), + array('id' => $id) + ); + + if ( !$res ) { + // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed + error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}"); + die; + } + + return ($wpdb->last_error); //not sure what to return here? + } + + public static function get($band, $venue, $date) + { + global $wpdb; + + $sql = 'SELECT id from wpg_concerts' + . ' where band = ' . $band + . ' and venue = ' . $venue + . ' and wpgconcert_date ="' . $date . '"'; + + error_log(__CLASS__ . '::' . __FUNCTION__ . ": {$sql}"); + return $wpdb->get_results($sql); + } + + public function save() + { + global $wpdb; + + $wpdb->insert('wpg_concerts', array( + 'id' => '', + 'band' => $this->band, + 'venue' => $this->venue, + 'wpgconcert_date' => $this->cdate, + 'wpgconcert_tickets' => $this->tickets, + 'wpgconcert_event' => $this->eventlink + )); + + $this->id = $wpdb->insert_id; + } + + public function id() + { + return $this->id; + } + + public function band() + { + return $this->band; + } + public function venue() + { + return $this->venue; + } + public function cdate() + { + return $this->cdate; + } + public function tickets() + { + return $this->tickets; + } + public function eventlink() + { + return $this->eventlink; + } + } +} +?> 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 @@ -get_results('select distinct wpgvenue_city from wpg_venues'); - $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 .= '
'; - return $select; -} - - -function giglogadmin_getconcerts() -{ - global $wpdb; - // Shortcodes RETURN content, so store in a variable to return - $content = ''; - // $content .= ''; - $content .= ''; - // 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 .= ''; - - if ($lastType != '' && $lastType != $row->wpgvenue_city) { - $content .= ''; - } - - if ($lastType == '') { - $content .= ''; - } - // Modify these to match the database structure - // $content .= ''; - $content .= ''; - $content .= ''; - $content .= ''; - $fdate = strtotime($row->wpgconcert_date); - $newformat = date('d.M.Y', $fdate); - - //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); - $content .= ''; - $content .= ''; - $content .= ''; - $content .= ''; - $lastType = $row->wpgvenue_city; - } - $content .= '
CITYIDBANDVENUEDATETICKETSEVENT
CITYBANDVENUEDATETICKETSEVENT
' . $row->wpgvenue_city . '
' . $row->wpgvenue_city . '
' . $row->id. '' . $row->band . '' . $row->venue . '' . $newformat . 'TicketsEvent link
'; - // return the table - return $content; -} +get_results('select distinct wpgvenue_city from wpg_venues'); + $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 .= '
'; + return $select; +} + + +function giglogadmin_getconcerts() +{ + global $wpdb; + // Shortcodes RETURN content, so store in a variable to return + $content = ''; + // $content .= ''; + $content .= ''; + // 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 .= ''; + + if ($lastType != '' && $lastType != $row->wpgvenue_city) { + $content .= ''; + } + + if ($lastType == '') { + $content .= ''; + } + // Modify these to match the database structure + // $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; + $fdate = strtotime($row->wpgconcert_date); + $newformat = date('d.M.Y', $fdate); + + //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); + $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; + $lastType = $row->wpgvenue_city; + } + $content .= '
CITYIDBANDVENUEDATETICKETSEVENT
CITYBANDVENUEDATETICKETSEVENT
' . $row->wpgvenue_city . '
' . $row->wpgvenue_city . '
' . $row->id. '' . $row->band . '' . $row->venue . '' . $newformat . 'TicketsEvent link
'; + // 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 @@ -

UNPROCESSED ROWS

'; - $content .= ''; - $query = 'SELECT rowid,filename,filedate,rowcontent from wpg_files where processed="N"'; - $results = $wpdb->get_results($query); - foreach ($results AS $row) { - $content .= ''; - $content .= ''; - $content .= ''; - $content .= ''; - $content .= ''; - $content .= ''; - } - $content .= '
FilerowFILENAMEDATEUploadedContent
' . $row->rowid . '' . $row->filename . '' . $row->filedate . '' . $row->rowcontent . '
'; - 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 = '

Inserted the following:

'; - $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 .= '
'; - } 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 .= '
'; - - } - - //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 .= '
'; - - - 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; -} +

UNPROCESSED ROWS

'; + $content .= ''; + $query = 'SELECT rowid,filename,filedate,rowcontent from wpg_files where processed="N"'; + $results = $wpdb->get_results($query); + foreach ($results AS $row) { + $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; + $content .= ''; + } + $content .= '
FilerowFILENAMEDATEUploadedContent
' . $row->rowid . '' . $row->filename . '' . $row->filedate . '' . $row->rowcontent . '
'; + 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 = '

Inserted the following:

'; + $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 .= '
'; + } 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 .= '
'; + + } + + //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 .= '
'; + + + 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 @@ - 3 and (is_dir($dir . '/' . $value) == false)) { - $output .= 'Filename: ' . $value . '
'; - $filecontent = file_get_contents($dir . '/' . $value); - $listcontent = str_replace(array( - "\r", - "\n" - ), '
', $filecontent); //tring to replace end of lines with brs for html - - $output .= 'FILE CONTENT
'; - $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 .= '
  • ' . $newconcert . '
  • '; - $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 .= '
    ---------------
    Inserted rowID ' . $my_id . '
    '; - } //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 .= '
    File ' . $value . ' 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 .= '
    '; - return $output; -} + 3 and (is_dir($dir . '/' . $value) == false)) { + $output .= 'Filename: ' . $value . '
    '; + $filecontent = file_get_contents($dir . '/' . $value); + $listcontent = str_replace(array( + "\r", + "\n" + ), '
    ', $filecontent); //tring to replace end of lines with brs for html + + $output .= 'FILE CONTENT
    '; + $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 .= '
  • ' . $newconcert . '
  • '; + $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 .= '
    ---------------
    Inserted rowID ' . $my_id . '
    '; + } //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 .= '
    File ' . $value . ' 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 .= '
    '; + return $output; +} -- cgit v1.2.3