PHP.EE FOORUM   
Nimi:   Pass:   Mäleta mind! 
   Teemad | php.ee esilehele | registreeri | Märgi kõik teemad loetuks | #php.ee Skype vestlus | RSS
UUS TEEMA  OTSI  Lehekülgi: 1
Wordpressi postitusele registreerumine
Postitaja: Anti 2016-06-19 13:56:16
Tere

Probleem järgmine - kasutan WordPressi pluginat SEATT, mis on ilus ja väike plugin - laseb konkreetse postituse all sisseloginud kasutajal vajutada registreeru üritusele nuppu ja tema nimi ilmub nimekirja. Rohkemid varjante sel pluginal polegi.

Nüüd oleks aga tarvis lisada sinna custom-field, ehk siis koos registreerumisega peaks kasutaja valima dropdown listist mingi valiku ja see kuvatakse pärast nimekirjas koos tema nimega.

Või äkki on võimalik see lahendada kuidagi lihtsamalt ja kiiremalt?

Lähteandmed:
postitus või leht
sisseloginud kasutajad

dropdown valikutega ning registreeru nupp
Pärast klikkamist ilmub postituse alla nimekirja lisarida nime ja dropdown valikuga
RE: Wordpressi postitusele registreerumine
Postitaja: fddfgdfgfg 2016-06-19 19:18:53
Eks sinna tabelisse tuleb lisada veerg juurde selle dropdownist tuleva infi jaoks. Pluginal midagi vahele hookida ei anna vaatasin, ehk siis lihstalt pluginat ennast tuleks muuta (ja edapsidi mitte uuendada).

RE: Wordpressi postitusele registreerumine
Postitaja: Anti 2016-06-19 21:00:05
Jõudsin nüüd lõpuks niikaugele, et andmeid saab sisestada, andmebaasi need kohale jõuavad, ent probleemiks on see, et neid andmeid kodulehel ei kuvata.



PHP kood:
 
<?php
function seatt_form($event_id) {
    global 
$wpdb;
    global 
$current_user;
    
get_currentuserinfo();
    
$seatt_error "";
    
    
// Clean down event ID by checking if numeric, then casting to integer
    
if (isset($event_id)) {
        if (
is_numeric($event_id)) {
            
$event_id intval($event_id);
        } else {
            
$event_id '';
        }
    } else {
        
$event_id '';
    }
    
    
// Clean down form event ID by checking if numeric, then casting to integer
    
if (isset($_POST['seatt_event_id'])) {
        if (
is_numeric($_POST['seatt_event_id'])) {
            
$form_event_id intval($_POST['seatt_event_id']);
        } else {
            
$form_event_id '';
        }
    } else {
        
$form_event_id '';
    }

    
// Continue if field isn't NULL
    
if ($event_id != '') {
        
        
// Get current state of event. 1 = open, 0 = closed, NULL = expired or doesn't exist
        
$seatt_event_state $wpdb->get_var($wpdb->prepare("SELECT event_status FROM ".$wpdb->prefix."seatt_events WHERE id = %d AND event_expire >= %d"$event_idtime()));
        
        
// If submitted, remove registration
        
if ((isset($_POST['seatt_unregister'])) && ($form_event_id == $event_id)) {
            
            
// Check that the event isn't closed or expired, remove if not
            
if ($seatt_event_state == 1) {
                
$wpdb->query($wpdb->prepare("DELETE FROM ".$wpdb->prefix."seatt_attendees WHERE user_id = %d AND event_id = %d"$current_user->ID,  $event_id));
            } else {
                
// If event no longer active
                    
$seatt_error "Unable to remove registration as this event is closed.";
            }
        }
        
        
// If submitted, add registration
        
if ((isset($_POST['seatt_register'])) && ($form_event_id == $event_id)) {
            
            
// If event active
            
if ($seatt_event_state == 1) {
            
                
// Get current number of free slots
                
$seatt_this_limit $wpdb->get_var($wpdb->prepare("SELECT event_limit FROM ".$wpdb->prefix."seatt_events WHERE id = %d"$event_id));
                
$seatt_this_registered $wpdb->get_var($wpdb->prepare("SELECT count(user_id) FROM ".$wpdb->prefix."seatt_attendees WHERE event_id = %d"$event_id));
                
                
// If space, add registration
                
if ($seatt_this_limit $seatt_this_registered) {
                    
                    
// If not already registered
                    
if ($wpdb->get_var($wpdb->prepare("SELECT user_id FROM ".$wpdb->prefix."seatt_attendees WHERE event_id = %d AND user_id = %d"$event_id$current_user->ID)) == "") {
                        
$user_comment stripslashes_deep(sanitize_text_field($_POST['seatt_comment']));
                        
$user_commentz stripslashes_deep(sanitize_text_field($_POST['seatt_commentz']));                        
                        
$wpdb->insert($wpdb->prefix.'seatt_attendees', array( 'event_id' => $event_id'user_id' => $current_user->ID'user_comment' => $user_comment'user_commentz' => $user_commentz ), array('%d''%d''%s''%s'));
                    } else {
                        
// If registered already
                        
$seatt_error "Sa oled juba kirjas.";
                    }
                } else {
                    
// If no space
                    
$seatt_error "There are no free slots.";
                }
            } else {
                
// If event no longer active
                    
$seatt_error "Registreerimine on suletud.";
            }
        }
        
// End registration
        
        // Get event details
        
$event $wpdb->get_row($wpdb->prepare("SELECT id, event_name, event_desc, event_limit, event_start, event_expire, event_status FROM ".$wpdb->prefix."seatt_events WHERE id = %d LIMIT 1"$event_id));
        
        
// Make sure that results were returned
        
if (count($event) > 0) {
            
            if (
$event->id != "") {
                
$attendees $wpdb->get_var($wpdb->prepare("SELECT COUNT(user_id) FROM ".$wpdb->prefix."seatt_attendees WHERE event_id = %d"$event_id));
                
                if (
$attendees == '') {
                    
$attendees 0;
                }
                if (
intval($event->event_limit) == 0) { 
                    
$event->event_limit 100000
                }
                
                
$seatt_output '<div>';
                
                if (
$event->event_limit != 100000) {
                    
$seatt_output .= '';
            }
            
            
$seatt_output .= '<p><strong>Turniirile on ennast kirja pannud:</strong>
            <ol style="margin-left:1em;">'
;
            
            
$users $wpdb->get_results($wpdb->prepare("SELECT id, user_id, user_comment, user_commentz FROM ".$wpdb->prefix."seatt_attendees WHERE event_id = %d ORDER BY id ASC"$event_id));

            
$num 1;
            foreach (
$users as $user) {
                
$user_info get_userdata($user->user_id);
                
$seatt_output .= '<li>' esc_html($user_info->user_firstname ' ' $user_info->user_lastname ' - ' $user_info->user_comment ' ' $user_info->user_commentz) . '</li>';
                
$num++;
            }
            
            if (
$num == 1) {
                
$seatt_output .= 'None found.';
            }
            
            
$seatt_output .= '</ol></p>';
            
            
// Check if user has already registered
            
$attending $wpdb->get_row($wpdb->prepare("SELECT user_id, user_comment, user_commentz FROM ".$wpdb->prefix."seatt_attendees WHERE event_id = %d AND user_id = %d"$event_id$current_user->ID));
            
            
$current_time current_time('timestamp');
            if ((
$event->event_status != 1) OR ($current_time >= $event->event_expire) OR ($current_time $event->event_start)) {
                
$seatt_output .= '
                <p><strong>Registration is currently closed.</strong></p>'
;
            }
            
// Check if user logged in
            
elseif (!is_user_logged_in()) {
                
$seatt_output .= '
            <p><strong>Please <a href="' 
site_url('wp-login.php') . '">login</a> (or <a href="' site_url('wp-login.php?action=register') . '">create an account</a>) to sign up for this event. </strong></p>'
                } elseif (
$attending) {
                    
// if they have already signed up
                    
$seatt_output .= '
                    <p><strong>Sa oled turniirile registreerunud.</strong></p>
            <form name="seatt_unregister" method="post" action="">
                    <input name="seatt_event_id" type="hidden" id="seatt_event_id" value="' 
$event_id '" size="40">
             
                  <p>
                    <input type="submit" name="seatt_unregister" id="seatt_unregister" value="Eemalda ennast turniirilt">
                  </p>
                </form>'
;
            
                } elseif (
$attendees >= $event->event_limit) { 
                
$seatt_output .= '<p><strong>Unfortunately all places are already reserved. </strong></p>';
                } else {
                
$seatt_output .= '
                <strong>Pane ennast turniirile kirja:</strong>
                    </p>
            
                <form name="seatt_register" method="post" action="">
                    <input name="seatt_event_id" type="hidden" id="seatt_event_id" value="' 
$event_id '" size="40">
                  <p>Vali vanusegrupp: 
                    <select name="seatt_comment" id="seatt_comment">
                        <option value="ÜM 35+">ÜM 35+</option>
                        <option value="ÜM 45+">ÜM 45+</option>
                        <option value="ÜM 50+">ÜM 50+</option>
                        <option value="ÜM 55+">ÜM 55+</option>
                        <option value="ÜM 60+">ÜM 60+</option>
                        <option value="ÜM 65+">ÜM 65+</option>
                        <option value="-">---</option>
                        <option value="PM 35+">PM 35+</option>
                        <option value="PM 45+">PM 45+</option>
                        <option value="PM 55+">PM 55+</option>
                        <option value="PM 65+">PM 65+</option>
                    </select>
                  </p>
                    <p>Vali vanusegrupp 2: 
                    <select name="seatt_comment2" id="seatt_comment2">
                        <option value="ÜM 35+">ÜM 35+</option>
                        <option value="ÜM 45+">ÜM 45+</option>
                        <option value="ÜM 50+">ÜM 50+</option>
                        <option value="ÜM 55+">ÜM 55+</option>
                        <option value="ÜM 60+">ÜM 60+</option>
                        <option value="ÜM 65+">ÜM 65+</option>
                        <option value="-">---</option>
                        <option value="PM 35+">PM 35+</option>
                        <option value="PM 45+">PM 45+</option>
                        <option value="PM 55+">PM 55+</option>
                        <option value="PM 65+">PM 65+</option>
                    </select>
                  </p>
                  <p>
                    <input type="submit" name="seatt_register" id="seatt_register" value="Registreeru">
                  </p>
                </form>'
;
                
                }
            } 
//End if no results
            
            // Add on error message if needed
            
if ($seatt_error != "") {
                
$seatt_error "<br /><p style=\"color:#ff0000\"><strong>Error:</strong> " . $seatt_error . "</p><br />";
                
$seatt_output .= $seatt_error;
            }
            
            
$seatt_output .= '</div>';
            
            return 
$seatt_output;
        }
    }
}

?>

RE: Wordpressi postitusele registreerumine
Postitaja: Anti 2016-06-19 21:02:11
Täpsemalt siis just see osa peaks teksti väljastama, väljastab aga ainult eesnime ja perekonnanime:


PHP kood:
 $seatt_output .= '<p><strong>Turniirile on ennast kirja pannud:</strong>
            <ol style="margin-left:1em;">'
;
            
            
$users $wpdb->get_results($wpdb->prepare("SELECT id, user_id, user_comment, user_commentz FROM ".$wpdb->prefix."seatt_attendees WHERE event_id = %d ORDER BY id ASC"$event_id));

            
$num 1;
            foreach (
$users as $user) {
                
$user_info get_userdata($user->user_id);
                
$seatt_output .= '<li>' esc_html($user_info->user_firstname ' ' $user_info->user_lastname ' - ' $user_info->user_comment ' ' $user_info->user_commentz) . '</li>';
                
$num++;
            }
            
            if (
$num == 1) {
                
$seatt_output .= 'None found.';
            }
            
            
$seatt_output .= '</ol></p>';
RE: Wordpressi postitusele registreerumine
Postitaja: väga hea1 2016-06-19 23:42:43
$seatt_output .= '<li>' . esc_html($user_info->user_firstname . ' ' . $user_info->user_lastname . ' - ' . $user->user_comment . ' ' . $user->user_commentz) . '</li>';

Näpuviga sisse jäänud.

Leheküljed: 1

©2002-2013 Martin Rebane & PHP.ee kaasautorid
  0.089751958847