diff options
Diffstat (limited to 'includes/admin')
-rw-r--r-- | includes/admin/register_db_tables.php | 18 | ||||
-rw-r--r-- | includes/admin/views/giglog_admin_page.php | 243 | ||||
-rw-r--r-- | includes/admin/views/giglog_import_gigs.php | 2 |
3 files changed, 126 insertions, 137 deletions
diff --git a/includes/admin/register_db_tables.php b/includes/admin/register_db_tables.php index 11223b3..64123d9 100644 --- a/includes/admin/register_db_tables.php +++ b/includes/admin/register_db_tables.php @@ -260,7 +260,7 @@ if ( !function_exists( "giglog_register_db_tables") ) function giglog_register_db_tables() { $db_version = get_option('giglogadmin_db_version'); - if ($db_version == 5) { + if ($db_version == 6) { return; } @@ -445,7 +445,21 @@ if ( !function_exists( "giglog_register_db_tables") ) "ALTER TABLE `wpg_concerts` DROP FOREIGN KEY `wpgconcert_band`;"); } - update_option("giglogadmin_db_version", 5); + if ($db_version == NULL || $db_version < 6) + { + /* + * Move status and roles from concertlogs to main concerts table + * Don't really see the value in a separate table for these items + * Also make the roles fiels a JSON field instead of separate + * fields for each role. + */ + $wpdb->query( + "ALTER TABLE `wpg_concerts` ADD COLUMN IF NOT EXISTS ( + wpgconcert_status INT DEFAULT 1, + wpgconcert_roles JSON CHECK (JSON_VALID(wpgconcert_roles)))"); + } + + update_option("giglogadmin_db_version", 6); } giglog_register_db_tables(); diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 9d9d759..6c1f059 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -9,7 +9,21 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { require_once __DIR__ . '/../../venue.php'; class GiglogAdmin_AdminPage { - static function render_html(): void { + private string $username; + + public function __construct() + { + $this->username = wp_get_current_user()->user_login; + } + + public static function render_html() : void + { + $page = new self(); + $page->render_page(); + } + + public function render_page() : void + { ?> <div class="wrap"> <h1>Giglog Admin</h1> @@ -28,96 +42,60 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { what the accreditation status is. You will get personal message if this is really close to the concert date.</p> - <p><?php echo GiglogAdmin_AdminPage::get_filters() ?></p> - <p><?php echo GiglogAdmin_AdminPage::get_concerts() ?></p> + <p><?php echo $this->get_filters() ?></p> + <p><?php echo $this->get_concerts() ?></p> </div> <?php if (current_user_can('administrator')) echo(GiglogAdmin_AdminPage::editforms()); //not sure why it doesn't show without the echo? } - static function get_venue_selector( ?GiglogAdmin_Venue $invenue ): string + private function get_venue_selector( ?GiglogAdmin_Venue $invenue ): string { - $select = '<select name="selectvenueadmin">'; - $select .= '<option value="">Please Select..</option>'; - foreach ( GiglogAdmin_Venue::all_venues() AS $venue ) { - if($invenue && $invenue->id() == $venue->id() ) { - $select .= '<option value="' . $venue->id(). '" selected="selected">'.$venue->name(); - } - else { - $select .= '<option value="' . $venue->id() . '">'. $venue->name(); - } - $select .='</option>'; - } - $select .= '</select>'; - return($select); + return \EternalTerror\ViewHelpers\select_field( + "selectvenueadmin", + array_map(fn($venue) => [$venue->id(), $venue->name()], GiglogAdmin_Venue::all_venues()), + $invenue ? $invenue->id() : null); } - static function get_user( ?int $cid, string $ctype): string + private function get_user( ?int $cid, string $ctype): string { - $hf_user = wp_get_current_user(); - $hf_username = $hf_user->user_login; - $select = '<select name="'.$ctype.'">'; - $select .= '<option value="">Please Select..</option>'; - $users = get_users( array( 'fields' => array( 'user_login' ) ) ); - foreach ( $users as $user ) { - $usr = $user->user_login; - $taken = strpos(GiglogAdmin_AdminPage::returnuser($ctype, $cid),$usr); - if($taken) $select .= '<option value="' .$usr. '" selected="selected">'.$usr; - else - { - $takenbyself = strpos(GiglogAdmin_AdminPage::returnuser($ctype, $cid),'name="unassignitem"'); - if($takenbyself && $usr==$hf_username) $select .= '<option value="' .$usr. '" selected="selected">'.$usr; - else - $select .= '<option value="'.$usr. '">'. $usr; - $select .='</option>'; - } - } - $select .= '</select>'; - return($select); - } + $users = array_map( + fn($usr) => $usr->user_login, + get_users( array( 'fields' => array( 'user_login' ) ) ) ); + $current_user = $cid ? GiglogAdmin_Concertlogs::get_assigned_user( $cid, $ctype ) : null; - static function get_filters(): string - { - $cities = array_merge(["ALL"], GiglogAdmin_Venue::all_cities()); - $cty = filter_input( INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS ); - $selected_city = - filter_input(INPUT_POST, "selectcity", FILTER_SANITIZE_SPECIAL_CHARS) - || $cities[0]; + return \EternalTerror\ViewHelpers\select_field( + $ctype, + array_map( fn($user) => [ $user, $user ], $users ), + $current_user); + } - $select = '<form method="POST" action="">FILTER DATA: <select name="selectcity">'; - foreach ( $cities AS $city ) { - $select .= '<option value="' . $city . '"' . selected($city,$cty ) . '>'; - $select .= $city . '</option>'; - } + private function get_filters() : string + { + $cty = filter_input(INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS); - $select .= '</select>'; + $select = '<form method="POST" action="">FILTER DATA:'; + $select .= \EternalTerror\ViewHelpers\select_field( + "selectcity", + array_map(fn($city) => [$city, $city], GiglogAdmin_Venue::all_cities()), + $cty, + "Select city..."); - if ( $cty && $cty!= "ALL" ) { + if ( !empty($cty) ) { //second drop down for venue - $venues = GiglogAdmin_Venue::venues_in_city($cty); - - $venue_list = array_merge( - [0, "ALL"], + $select .= \EternalTerror\ViewHelpers\select_field( + "selectvenue", array_map( - function($v) { return [$v->id(), $v->name()]; }, - $venues)); - - $selected_venue = filter_input(INPUT_POST, "selectvenue", FILTER_SANITIZE_SPECIAL_CHARS) - || $venue_list[0]; - - $select .= '<select name="selectvenue">'; - - foreach ( $venue_list as $venue ) { - $select .= '<option value="' . $venue[0] . '"' . selected($venue, $selected_venue) . '>'; - $select .= $venue[1] . '</option>'; - } - $select .= '</select>'; - + fn($venue) => [$venue->id(), $venue->name()], + GiglogAdmin_Venue::venues_in_city($cty) + ), + filter_input(INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS), + "Select venue..."); } //option to select own concerts only $select .= '<input class="ownconc" type="checkbox" value="1"'; @@ -129,7 +107,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { return $select; } - static function editforms(): string + private function editforms(): string { $cid = filter_input(INPUT_POST, "cid"); $editing = filter_input(INPUT_POST, "edit") == "EDIT"; @@ -144,7 +122,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { .'<div class="concertitems"><strong>CONCERT DETAILS</strong><br><br><fieldset>' .'<input type="hidden" name="pid" value="' .$c->id(). '" />' .'<label for="cname">Concert Name:</label><textarea id="cname" name="cname" value="'.$c->cname().'">'.$c->cname().'</textarea><br>' - .'<label for="venue">Venue:</label>' . GiglogAdmin_AdminPage::get_venue_selector($c->venue()) . '<br>' + .'<label for="venue">Venue:</label>' . $this->get_venue_selector($c->venue()) . '<br>' .'<label for="cdate">Date:</label><input type="date" id="cdate" name="cdate" value="'.$c->cdate().'"><br>' .'<label for="ticket">Tickets:</label><input type="text" id="ticket" name="ticket" value="'.$c->tickets().'"><br>' .'<label for="eventurl">Event link:</label><input type="text" id="eventurl" name="eventurl" value="'.$c->eventlink().'"><br>' @@ -157,10 +135,10 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $content.='</div>'; $content.='<div class="useritems"><strong>ASSIGNMENT DETAILS</strong><br><br><fieldset>' - .'<label for="photo1">Photo1:</label>'.GiglogAdmin_AdminPage::get_user($c->id(),'photo1').'<br>' - .'<label for="photo2">Photo2:</label>'.GiglogAdmin_AdminPage::get_user($c->id(),'photo2').'<br>' - .'<label for="rev1">Text1:</label>'.GiglogAdmin_AdminPage::get_user($c->id(),'rev1').'<br>' - .'<label for="rev2">Text2:</label>'.GiglogAdmin_AdminPage::get_user($c->id(),'rev2').'<br>'; + .'<label for="photo1">Photo1:</label>'.$this->get_user($c->id(),'photo1').'<br>' + .'<label for="photo2">Photo2:</label>'.$this->get_user($c->id(),'photo2').'<br>' + .'<label for="rev1">Text1:</label>'.$this->get_user($c->id(),'rev1').'<br>' + .'<label for="rev2">Text2:</label>'.$this->get_user($c->id(),'rev2').'<br>'; $content.='<fieldset></div></form></div>'; $content.='<div class="venueform"><form method="POST" action="" class="venue" ><strong>VENUE DETAILS</strong><br><br>' @@ -172,35 +150,29 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { return $content; } - static function adminactions( int $concert_id ) : string + private function adminactions( int $concert_id ) : string { global $wpdb; $query = "SELECT id,wpgs_name from wpg_pressstatus" ; $statuses = $wpdb->get_results($query); - $select = + return '<form method="POST" action="">' . '<input type="hidden" name="cid" value="' . $concert_id . '" />' - . '<select name="selectstatus">'; - - foreach ( $statuses AS $sts ) { - $select .= '<option value="' . $sts->id . '">' . $sts->wpgs_name . '</option>'; - } - - $select .= - '</select>' + . \EternalTerror\ViewHelpers\select_field( + 'selectstatus', + array_map(fn($status) => [ $status->id, $status->wpgs_name ], $statuses), + GiglogAdmin_Concertlogs::get_status($concert_id)) . '<input type="submit" value="SetStatus">' . '<input type="submit" name ="edit" value="EDIT">' . '</form>'; - - return $select; } //function to calculate if the concert has been added in the past 10 days or before that and show a green NEW for the newest rows /** * @return null|string */ - static function getpublishstatus(int $concert_id) + private function getpublishstatus(int $concert_id) { global $wpdb; $date1 = new DateTime("now"); @@ -217,11 +189,8 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { } - static function get_concerts(): string + private function get_concerts(): string { - $hf_user = wp_get_current_user(); - $hf_username = $hf_user->user_login; - $roles = $hf_user->roles; global $wpdb; $content = '<table class="assignit">'; @@ -231,7 +200,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { <th>CITY</th><th>NAME</th><th>VENUE</th><th>DATE</th><th> </th> <th>PHOTO1</th><th>PHOTO2</th><th>TEXT1</th><th>TEXT2</th> <th>STATUS</th>'; - if (current_user_can('administrator')) //($hf_username == 'etadmin') + if (current_user_can('administrator')) $content .= '<th>AdminOptions</th>'; $content .= '</tr>'; @@ -252,7 +221,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $query .= ($cty == "ALL") ? "" : " and wpgv.wpgvenue_city='" .$cty ."'"; $query .= ($venue == "0") ? "" : " and wpgv.id='" .$venue ."'"; - $query.= (empty($_POST['my_checkbox'])) ? "": " and (wpgcl_photo1 ='".$hf_username."' or wpgcl_photo2 ='".$hf_username."' or wpgcl_rev1 ='".$hf_username."' or wpgcl_rev2 ='".$hf_username."')"; + $query.= (empty($_POST['my_checkbox'])) ? "": " and (wpgcl_photo1 ='".$this->username."' or wpgcl_photo2 ='".$this->username."' or wpgcl_rev1 ='".$this->username."' or wpgcl_rev2 ='".$this->username."')"; $query .=" order by wpgv.wpgvenue_city, wpgconcert_date, wpgc.id" ; $results = $wpdb->get_results($query); $lastType = ''; @@ -277,17 +246,17 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); $content .= '<td>' .$newformat. '</td>'; - $content .= '<td>'.GiglogAdmin_AdminPage::getpublishstatus($row->id ).'</td>'; - $content .= '<td>'.GiglogAdmin_AdminPage::returnuser('photo1', $row->id ).'</td>'; - $content .= '<td>'.GiglogAdmin_AdminPage::returnuser('photo2', $row->id ).'</td>'; - $content .= '<td>'.GiglogAdmin_AdminPage::returnuser('rev1', $row->id ).'</td>'; - $content .= '<td>'.GiglogAdmin_AdminPage::returnuser('rev2', $row->id ).'</td>'; + $content .= '<td>'.$this->getpublishstatus($row->id ).'</td>'; + $content .= '<td>'.$this->returnuser('photo1', $row->id ).'</td>'; + $content .= '<td>'.$this->returnuser('photo2', $row->id ).'</td>'; + $content .= '<td>'.$this->returnuser('rev1', $row->id ).'</td>'; + $content .= '<td>'.$this->returnuser('rev2', $row->id ).'</td>'; $content .= '<td>'.$row -> wpgs_name.'</td>'; if (current_user_can('administrator')) { $content .= '<td class="adminbuttons">' - . GiglogAdmin_AdminPage::adminactions($row->id) + . $this->adminactions($row->id) . '</td>'; } $content .= '</tr>'; @@ -334,7 +303,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { } //handling the admin drop down menu - if(isset($_POST['selectstatus']) && $_POST['edit']!="EDIT" && !empty($_POST['cid'])) + if(isset($_POST['selectstatus']) && (isset($_POST['edit']) && $_POST['edit']!="EDIT") && !empty($_POST['cid'])) { $usql = "UPDATE wpg_concertlogs SET wpgcl_status=".$_POST['selectstatus']." WHERE wpgcl_concertid=".$_POST['cid']; $uresults = $wpdb->get_results($usql); @@ -363,7 +332,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { else { GiglogAdmin_Concert::update_concert($_POST['pid'],$_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl']); - GiglogAdmin_Concert::update_concertlog($_POST['pid'],$_POST['photo1'], $_POST['photo2'], $_POST['rev1'], $_POST['rev2']); + GiglogAdmin_Concertlogs::update($_POST['pid'],$_POST['photo1'], $_POST['photo2'], $_POST['rev1'], $_POST['rev2']); echo '<script language="javascript">alert("Yay, concert updated"); </script>'; } @@ -386,17 +355,15 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { { global $wpdb; - $hf_user = wp_get_current_user(); - $hf_username = $hf_user->user_login; $to = 'live@eternal-terror.com'; - $subject = $hf_username.' has taken '.$p1. 'for a concert with id '.$c; + $subject = $this->username.' has taken '.$p1. 'for a concert with id '.$c; $body = 'The email body content'; $headers = array('Content-Type: text/html; charset=UTF-8'); - $usql = "UPDATE wpg_concertlogs SET wpgcl_".$p1."='".$hf_username."' WHERE wpgcl_concertid=".$c; + $usql = "UPDATE wpg_concertlogs SET wpgcl_".$p1."='".$this->username."' WHERE wpgcl_concertid=".$c; $uresults = $wpdb->get_results($usql); $wpdb->insert( 'wpg_logchanges', array ( 'id' => '', - 'userid' => $hf_username, + 'userid' => $this->username, 'action' => 'assigned '.$p1, 'concertid' => $c)); echo ($wpdb->last_error ); @@ -407,48 +374,56 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { { global $wpdb; - $hf_user = wp_get_current_user(); - $hf_username = $hf_user->user_login; $to = 'live@eternal-terror.com'; - $subject = $hf_username.' has UNASSINED '.$p1. 'for a concert with id '.$c; + $subject = $this->username.' has UNASSINED '.$p1. 'for a concert with id '.$c; $body = 'The email body content'; $headers = array('Content-Type: text/html; charset=UTF-8'); $usql = "UPDATE wpg_concertlogs SET wpgcl_".$p1."='' WHERE wpgcl_concertid=".$c; $uresults = $wpdb->get_results($usql); $wpdb->insert( 'wpg_logchanges', array ( 'id' => '', - 'userid' => $hf_username, + 'userid' => $this->username, 'action' => 'unassigned '.$p1, 'concertid' => $c)); echo ($wpdb->last_error ); wp_mail( $to, $subject, $body, $headers ); } - static function returnuser(string $p1, ?int $c): string + private function returnuser(string $p1, ?int $c) : ?string { - global $wpdb; - $hf_user = wp_get_current_user(); - $hf_username = $hf_user->user_login; - + if (!$c) { + return null; + } - if (!empty($c)) - { - $sql = "select * from wpg_concertlogs where wpgcl_concertid=".$c; - $crow = $wpdb->get_results($sql); - $array = array('photo1' => $crow[0]->wpgcl_photo1, 'photo2'=> $crow[0]->wpgcl_photo2, 'rev1' => $crow[0]->wpgcl_rev1, 'rev2'=> $crow[0]->wpgcl_rev2); - - //first check if current slot is taken by current user - if ($array[$p1] == $hf_username) return ('<form class="unassignit" method="POST" action=""> <input type="hidden" name="cid" value="' . $c. '" /><input type="hidden" name="pid" value="' . $p1. '" /><input type="submit" name="unassignitem" value="Your"/></form>'); - else //check if slot is taken by another user - if (!empty($array[$p1])) return ('<span class="takenby">Taken</span><div class="takenby">Taken by '.$array[$p1].'</div>'); - else //check if other slots for this concert are taken by user - if (in_array($hf_username,$array)) return ('<span class="taken_by_self">-</span>'); - else //not taken by anyone - return ('<form method="POST" action=""> <input type="hidden" name="cid" value="' . $c. '" /><input type="hidden" name="pid" value="' . $p1. '" /><input type="submit" name="assignitem" value=""/> - </form>'); + $cl = GiglogAdmin_Concertlogs::get($c); + $role = $cl->get_assigned_role( $this->username ); + $assigned_user = $cl->assigned_user( $p1 ); + + //first check if current slot is taken by current user + if ( $role == $p1 ) { + $f = '<form class="unassignit" method="POST" action="">' + . ' <input type="hidden" name="cid" value="' . $c. '" />' + . ' <input type="hidden" name="pid" value="' . $p1. '" />' + . ' <input type="submit" name="unassignitem" value="Your"/>' + . '</form>'; + } + elseif ( $assigned_user ) { //check if slot is taken by another user + $f = '<span class="takenby">Taken</span>' + . '<div class="takenby">Taken by ' . $assigned_user . '</div>'; + } + elseif ( $role ) { + // other slots for this concert are taken by user + $f = '<span class="taken_by_self">-</span>'; + } + else { //not taken by anyone + $f = '<form method="POST" action="">' + . ' <input type="hidden" name="cid" value="' . $c. '" />' + . ' <input type="hidden" name="pid" value="' . $p1. '" />' + . ' <input type="submit" name="assignitem" value=""/>' + . '</form>'; } - else return ('no concert selected'); + return $f; } } } diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php index a8daa3f..aeaf974 100644 --- a/includes/admin/views/giglog_import_gigs.php +++ b/includes/admin/views/giglog_import_gigs.php @@ -51,7 +51,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { * * @return void * - * @param ArrayAccess|array $file + * @param array<int, mixed> */ static function process_upload(array $file): void { $newconcert= []; |