/**
 * NBA Member Directory Search Form
 *
 * @param array $search_vals     Either default or last searched form values
 * @param array $divisions       Array of Divisions with their chairs, states, and state chairs
 * @param array $teaching_levels Array of Teaching Level strings and slugs that match the values in the MP custom field
 * @param bool  $is_chair        Whether or not the current user is a State or Division chair
 * @author Jordan Pakrosnis
 */
function nba_member_directory_search_form($search_vals, $divisions, $teaching_levels, $is_chair)
{
    global $post;
    // Page Slug (For Reset Button)
    $slug = $post->post_name;
    $reset_url = get_site_url() . '/' . $slug;
    function nba_new_search()
    {
        echo '<h1>SUBMISSION!</h1>';
    }
    //---------------//
    //  SEARCH FORM  //
    //---------------//
    ?>
	<form id="member-directory-search" class="clearfix" role="form" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
">

		<?php 
    if ($search_vals['first_name'] != 'disabled' || $search_vals['last_name'] != 'disabled') {
        ?>

			<!--// FIRST NAME //-->
			<?php 
        if ($search_vals != 'disabled ') {
            ?>
				<div class="field">
					<input type="text" name="first_name" id="first_name" value="<?php 
            echo $search_vals['first_name'];
            ?>
" placeholder="First Name">
				</div>
			<?php 
        }
        ?>

			<!--// LAST NAME //-->
			<?php 
        if ($search_vals['last_name'] != 'disabled') {
            ?>
				<div class="field">
					<input type="text" name="last_name" id="last_name" value="<?php 
            echo $search_vals['last_name'];
            ?>
" placeholder="Last Name">
				</div>
			<?php 
        }
        ?>

		<?php 
    }
    ?>


		<!--// EMAIL //-->
		<?php 
    if ($search_vals['email'] != 'disabled') {
        ?>
			<div class="field">
				<input type="email" name="email" id="email" value="<?php 
        echo $search_vals['email'];
        ?>
" placeholder="Email">
			</div>
		<?php 
    }
    ?>


		<?php 
    if ($search_vals['state'] != 'disabled' || $search_vals['division_name'] != 'disabled') {
        ?>

			<!--// STATE //-->
			<?php 
        if ($search_vals['state'] != 'disabled') {
            ?>
				<div class="field">
					<select name="state" id="state">

						<!-- DEFAULT / ALL -->
						<?php 
            $selected = $search_vals['state'] ? '' : 'selected';
            ?>

						<option value="all" <?php 
            echo $selected;
            ?>
>All States</option>

						<!-- SPECIFIC STATE -->
						<?php 
            foreach ($divisions["all_states"] as $state) {
                $state_abbr = nba_format_state($state, 'abbr');
                if ($search_vals['state'] == $state_abbr) {
                    $selected = 'selected ';
                } else {
                    $selected = '';
                }
                $value = 'value="' . $state_abbr . '"';
                ?>

							<option <?php 
                echo $selected;
                echo $value;
                ?>
><?php 
                echo $state;
                ?>
</option>

						<?php 
            }
            ?>


						<!-- INTERNATIONAL -->
						<?php 
            $selected = $search_vals['state'] == 'International' ? ' selected' : '';
            ?>
						<option value="International" <?php 
            echo $selected;
            ?>
>International</option>

					</select><!-- #state -->
				</div><!-- .field -->
			<?php 
        }
        // state != disabled
        ?>


			<!--// DIVISION //-->
			<?php 
        if ($search_vals['division_name'] != 'disabled') {
            ?>
				<div class="field">
					<select name="division_name" id="division_name">

						<!-- DEFAULT / ALL -->
						<?php 
            if ($search_vals['division_name']) {
                $selected = '';
            } else {
                $selected = 'selected';
            }
            ?>
						<option value="all" <?php 
            echo $selected;
            ?>
>All Divisions</option>


						<!-- SPECIFIC DIVISIONS -->
						<?php 
            foreach ($divisions as $key => $value) {
                if ($search_vals['division_name'] == $key) {
                    $selected = 'selected';
                } else {
                    $selected = '';
                }
                ?>

							<?php 
                if (nba_is_division($key)) {
                    ?>
								<option <?php 
                    echo $selected;
                    ?>
><?php 
                    echo $key;
                    ?>
</option>
							<?php 
                }
                ?>
						<?php 
            }
            ?>

					</select><!-- #division-name -->
				</div><!-- .field -->
			<?php 
        }
        // division != disabled
        ?>

		<?php 
    }
    // state or division_name != disabled
    ?>


		<!--// SCHOOL //-->
		<?php 
    if ($search_vals['school'] != 'disabled') {
        ?>
			<div class="field">
				<input type="school" name="school" id="school" value="<?php 
        echo $search_vals['school'];
        ?>
" placeholder="School">
			</div>
		<?php 
    }
    ?>


		<!--// TEACHING LEVEL //-->
		<?php 
    if ($search_vals['teaching_level'] != 'disabled') {
        ?>
			<div class="field">
				<select name="teaching_level" id="teaching_level">

					<!-- DEFAULT / ALL -->
					<?php 
        if ($search_vals['teaching_level']) {
            $selected = '';
        } else {
            $selected = 'selected';
        }
        ?>
					<option value="all" <?php 
        echo $selected;
        ?>
>All Teaching Levels</option>


					<!-- SPECIFIC -->
					<?php 
        foreach ($teaching_levels as $value => $label) {
            // "None" pretty much for admin use only
            if ($value != 'none') {
                if ($search_vals['teaching_level'] == $value) {
                    $selected = 'selected';
                } else {
                    $selected = '';
                }
                ?>

							<option value="<?php 
                echo $value;
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo $label;
                ?>
</option>

						<?php 
            }
            ?>

					<?php 
        }
        ?>
				</select><!-- #teaching-level -->
			</div><!-- .field -->
		<?php 
    }
    // teaching_level != disabled
    ?>


		<!--// SHOW INACTIVE //-->
		<?php 
    if ($search_vals['show_inactive'] != 'disabled' && $is_chair) {
        ?>
			<div class="field field-radio">

				<?php 
        // Checck Show Inactive?
        if ($search_vals['show_inactive'] == 'show_inactive') {
            $show_inactive = ' checked="checked"';
        } else {
            $show_inactive = '';
        }
        // Check Inactive Only?
        if ($search_vals['show_inactive'] == 'inactive_only') {
            $inactive_only = ' checked="checked"';
        } else {
            $inactive_only = '';
        }
        ?>

				<!-- SHOW INACTIVE MEMBERS -->
				<div class="radio-wrap">
					<input type="radio" name="show_inactive" id="show_inactive" value="show_inactive"<?php 
        echo $show_inactive;
        ?>
>
					<label for="show_inactive">Show Inactive</label>
				</div>

				<!-- INACTIVE MEMBERS ONLY -->
				<div class="radio-wrap">
					<input type="radio" name="show_inactive" id="inactive_only" value="inactive_only"<?php 
        echo $inactive_only;
        ?>
>
					<label for="inactive_only">Inactive Only</label>
				</div>

			</div><!-- .field -->
		<?php 
    }
    ?>


		<!-- RESET & SUBMIT -->
		<div class="buttons">

			<div class="field field-search-reset">
				<a class="button button-light" href="<?php 
    echo $reset_url;
    ?>
" id="member-directory-reset">Reset</a>
			</div>

			<div class="field field-submit">
				<button class="button" type="submit">Search</button>
			</div>

		</div><!-- .buttons -->


		<!-- HIDDEN SEARCH KEY -->
		<?php 
    // Create new search key so we know if the form is submitted
    $search_key = rand(0, 99999999);
    ?>
		<input type="hidden" name="search_key" value="<?php 
    echo $search_key;
    ?>
">


	</form><!-- #member-directory-search -->
	<?php 
}
Ejemplo n.º 2
0
/**
 * NBA Member Directory
 *
 * @author Jordan Pakrosnis
 */
function nba_do_member_directory()
{
    //=============================//
    //  CONFIG SEARCH VALS & META  //
    //=============================//
    $search_vals = nba_get_search_vals();
    //======================================================//
    //  DIVISIONS, DIVISION STATES, TEACHING LEVELS CONFIG  //
    //======================================================//
    //-- GET DIVISIONS --//
    //   Needed for checking chair
    $divisions = nba_get_divisions();
    //-- STATE OR DIVISION CHAIR? --//
    if ($divisions['current_user']['state_chair'] || $divisions['current_user']['division_chair']) {
        $is_chair = true;
    } else {
        $is_chair = false;
    }
    //-- SELECTED DIVISION STATES --//
    //   Get if searching by division is enabled & searched & form is submitted
    if ($search_vals['do_search'] && $search_vals['division_name'] != 'all' && $search_vals['division_name'] != 'disabled') {
        $division_states = array();
        // foreach           in the  searched division's     states    as State      Chair ID
        foreach ($divisions[$search_vals['division_name']]['states'] as $state => $chair) {
            $division_states[] = nba_format_state($state, 'abbr');
        }
    } else {
        $division_states = '';
    }
    // if division_name isn't default
    //-- TEACHING LEVELS --//
    $teaching_levels = array('none' => 'None', 'elementary' => 'Elementary', 'middle-school' => 'Middle School', 'junior-high-school' => 'Junior High School', 'high-school' => 'High School', 'college-university' => 'College / University', 'community' => 'Community', 'military' => 'Military', 'other' => 'Other');
    //=======================================//
    //  COUNT TOTAL USERS (SESSION CONTROL)  //
    //=======================================//
    nba_total_results($search_vals, $division_states);
    //-- WRAPPER --//
    echo '<section class="nba-member-directory clearfix">';
    //-- INIT PAGINATION --//
    if ($search_vals['do_search']) {
        $pagination = nba_get_pagination($search_vals, $division_states);
    }
    //===============//
    //  SEARCH FORM  //
    //===============//
    nba_member_directory_search_form($search_vals, $divisions, $teaching_levels, $is_chair);
    if ($search_vals['do_search']) {
        //======================================//
        //  GET & DISPLAY RESULTS & PAGINATION  //
        //======================================//
        $results = nba_do_member_directory_search($search_vals, $division_states, $pagination['users_per_page'], $pagination['offset']);
        //-- RESULTS FOUND --//
        if ($results) {
            nba_display_member_directory_results($results, $divisions, $teaching_levels);
            nba_do_pagination($pagination);
        } else {
            echo '<div class="directory-none-found">';
            echo '<h3>There are no members that match your search.</h3>';
            echo '<div>';
            // .directory-none-found
        }
        // None Found
    }
    // if do_search
    // Close Wrapper
    echo '</section>';
}
Ejemplo n.º 3
0
/**
 * NBA Get Division
 *
 * @param string $state
 * @param array $divisions array of divisions and their states
 * @return string Division of the supplied state (maybe user ID soon?)
 *
 * @author Jordan Pakrosnis
 */
function nba_get_division($state, $divisions)
{
    // Expand State
    $state = nba_format_state($state[0]);
    foreach ($divisions as $division_name => $division_data) {
        // Don't do for "current_user" or "all_states"
        if (nba_is_division($division_name)) {
            if (array_key_exists($state, $division_data['states'])) {
                return $division_name;
            }
        }
        // if is division
    }
    // foreach $divisions
}