<commit_before><?php

/* We use this interface for booking venue. We may also come here from manage 
 * talks page. If a user creates a talk and we come here for a booking; we use 
 * the external_id _GET variable.
 */

include_once 'database.php';
include_once 'methods.php';
include_once 'tohtml.php';
include_once './check_access_permissions.php';

mustHaveAnyOfTheseRoles( array( "USER" ) );

echo userHTML( );


$roundedTimeNow = round( time( ) / (15 * 60) ) * (15 * 60 );

$defaults = array( 
    "date" => dbDate( strtotime( 'today' ) )
    , "start_time" => date( 'H:i', $roundedTimeNow )
    , "end_time" => date( 'H:i', $roundedTimeNow + 3600 )
    , "strength" => 10
    , "has_skype" => "NO"
    , "has_projector" => "NO"
    , "openair" => "NO"
    , "title" => ''
    );

$external_id = null;


/*
 * We can come here from a $_GET or $_POST request 
 */
if( array_key_exists( 'external_id', $_GET ) )
{
    $external_id = $_GET[ 'external_id' ];
    $expr = explode( ".", $external_id );
    $tableName = $expr[ 0 ];
    $id = $expr[ 1 ];
    $entry = getTableEntry( $tableName, 'id', array( "id" => $id ) );
    echo "<h1>Scheduling for the following talk </h1>";
    echo arrayToTableHTML( $entry, 'events', '', 'id,status,date,time,venue' );
    $defaults = array_merge( $defaults, $entry );

    // Update the title of booking request.
    $defaults[ 'title' ] = __ucwords__( $defaults[ 'class' ] ) . ' by ' 
            . $defaults[ 'speaker' ] . " on '" . $defaults[ 'title' ] . "'";
}
else
{
    // Display these messages if $_GET is not used.
    echo '<div style="font-size:x-small">';
    echo printInfo( 'A powerful booking interface is also available 
        if you need to explore other events/dates/venues  before booking. 
        <a href="bookmyvenue_browse.php">TAKE ME THERE</a> ' );
    echo '</div>';

    echo alertUser( 
        'NOTICE: This interface is not for booking talks/seminar. 
        Please use <a href="user_register_talk.php">this interface</a>
            '
        );
}

// Since we come back to this page again and again, we reuse the previous values 
// provided by user.
foreach( $defaults as $key => $val )
    if( array_key_exists( $key, $_POST ) )
        $defaults[ $key ] = $_POST[ $key ];

$skypeYes = ''; $skypeNo = '';
if( $defaults[ 'has_skype' ] == 'YES' )
    $skypeYes = 'checked'; 
else 
    $skypeNo = 'checked';

$projectorYes = ''; $projectorNo = '';
if( $defaults[ 'has_projector' ] == 'YES' )
    $projectorYes = 'checked'; 
else 
    $projectorNo = 'checked';

$openAirNo = ''; $openAirYes = ' ';
if( $defaults[ 'openair' ] == 'YES' )
    $openAirYes = 'checked'; 
else 
    $openAirNo = 'checked';



echo '<br />';
echo '<table style="min-width:300px;max-width:500px",border="0">';
echo '<form action="" method="post" accept-charset="utf-8">';
echo '
    <tr>
        <td>Pick a date</td>
        <td><input  class="datepicker" name="date" 
            value="' . $defaults[ 'date' ] . '" /> </td>
    </tr>
    <tr>
        <td>Start time </td>
        <td><input  class="timepicker" name="start_time" 
            value="' . $defaults[ 'start_time'] . '" /> </td>
    </tr>
    <tr>
        <td>End time </td>
        <td><input  class="timepicker" name="end_time" 
            value="' . $defaults[ 'end_time'] . '" /> </td>
    </tr>
    <tr>
        <td>Mininum seatings required? </td>
        <td><input type="text" name="strength" 
            value="' . $defaults[ 'strength' ] . '" /> </td>
    </tr>
    <tr>
        <td>Do you need video-conference facility?</td>
        <td>
            <input type="radio" name="has_skype" value="NO" ' . $skypeNo . ' /> No
            <input type="radio" name="has_skype" value="YES" ' .$skypeYes . ' /> Yes
        </td>
    </tr>
    <tr>
        <td>Do you need a projector?</td>
        <td>
        <input type="radio" name="has_projector" 
            value="NO" ' . $projectorNo . ' /> No
        <input type="radio" name="has_projector" 
                value="YES" ' .$projectorYes . ' /> Yes
        </td>
    </tr>
    <tr>
        <td>Prefer open-air location?</td>
        <td>
            <input type="radio" name="openair" value="NO"' . $openAirNo . ' $/> No
            <input type="radio" name="openair" value="YES"' . $openAirYes . ' /> Yes
        </td>
    </tr>
    <tr>
        <td></td>
        <td style="text-align:right">
        <button title="Scan for venues" 
            style="font-size:large" name="Response" value="scan">
                Show me <br> available venues</button>
        </td>
    </tr>
    ';

echo '</form>';
echo '</table>';

$date = __get__( $_POST, 'date', dbDate(strtotime( 'today' )) );

// Force this only if user is not admin.
if( ! anyOfTheseRoles( array( 'BOOKMYVENUE_ADMIN', 'AWS_ADMIN' ) ) )
{
    if( strtotime( $date ) >= strtotime( 'today' ) + 60 * 24 * 3600 )
    {
        echo alertUser( "You can not book more than 60 days in advance" );
        exit;
    }
}

// Get list of public events on user request day and show them to him. So he can 
// decides if some other timeslot should be used.
$publicEvents = getPublicEventsOnThisDay( $date );
if( count( $publicEvents ) > 0 )
{
    echo "<div style=\"font-size:small\">";
    echo alertUser( "Following public events are scheduled on the campus on 
        selected date" 
    );
    foreach( $publicEvents as $event )
        echo arrayToTableHTML( $event, 'events', ''
            , array( 'gid', 'eid', 'description', 'status', 'is_public_event'
            , 'external_id'
            , 'calendar_id', 'calendar_event_id', 'last_modified_on' 
            )
        );

    echo "</div>";
}

if( array_key_exists( 'Response', $_POST ) && $_POST['Response'] == "scan" )
{
    $date = humanReadableDate( $_POST[ 'date' ] );

    echo printInfo( "I found following available venues for $date" );
    echo "<br/>";

    $venues = getVenues( $sortby = 'name' );

    echo '<table border="0">';
    foreach ($venues as $venue) 
    {
        if( $venue[ 'strength' ] < $_POST[ 'strength' ] )
            continue;
<commit_msg>Updated quickbook with minor tweaks.<commit_after><?php

/* We use this interface for booking venue. We may also come here from manage 
 * talks page. If a user creates a talk and we come here for a booking; we use 
 * the external_id _GET variable.
 */

include_once 'database.php';
include_once 'methods.php';
include_once 'tohtml.php';
include_once './check_access_permissions.php';

mustHaveAnyOfTheseRoles( array( "USER" ) );

echo userHTML( );


$roundedTimeNow = round( time( ) / (15 * 60) ) * (15 * 60 );

$defaults = array( 
    "date" => dbDate( strtotime( 'today' ) )
    , "start_time" => date( 'H:i', $roundedTimeNow )
    , "end_time" => date( 'H:i', $roundedTimeNow + 3600 )
    , "strength" => 10
    , "has_skype" => "NO"
    , "has_projector" => "NO"
    , "openair" => "NO"
    , "title" => ''
    );

$external_id = null;


/*
 * We can come here from a $_GET or $_POST request 
 */
if( array_key_exists( 'external_id', $_GET ) )
{
    $external_id = $_GET[ 'external_id' ];
    $expr = explode( ".", $external_id );
    $tableName = $expr[ 0 ];
    $id = $expr[ 1 ];
    $entry = getTableEntry( $tableName, 'id', array( "id" => $id ) );
    echo "<h1>Scheduling for the following talk </h1>";
    echo arrayToTableHTML( $entry, 'events', '', 'id,status,date,time,venue' );
    $defaults = array_merge( $defaults, $entry );

    // Update the title of booking request.
    $defaults[ 'title' ] = __ucwords__( $defaults[ 'class' ] ) . ' by ' 
            . $defaults[ 'speaker' ] . " on '" . $defaults[ 'title' ] . "'";
}
else
{
    // Display these messages if $_GET is not used.
    echo '<div style="font-size:x-small">';
    echo printInfo( 'A powerful booking interface is also available 
        if you need to explore other events/dates/venues  before booking. 
        <a href="bookmyvenue_browse.php">TAKE ME THERE</a> ' );
    echo '</div>';

    echo alertUser( 
        'NOTICE: This interface is not for booking talks/seminar. 
        Please use <a href="user_register_talk.php">this interface</a>
            '
        );
}

// Since we come back to this page again and again, we reuse the previous values 
// provided by user.
foreach( $defaults as $key => $val )
    if( array_key_exists( $key, $_POST ) )
        $defaults[ $key ] = $_POST[ $key ];

$skypeYes = ''; $skypeNo = '';
if( $defaults[ 'has_skype' ] == 'YES' )
    $skypeYes = 'checked'; 
else 
    $skypeNo = 'checked';

$projectorYes = ''; $projectorNo = '';
if( $defaults[ 'has_projector' ] == 'YES' )
    $projectorYes = 'checked'; 
else 
    $projectorNo = 'checked';

$openAirNo = ''; $openAirYes = ' ';
if( $defaults[ 'openair' ] == 'YES' )
    $openAirYes = 'checked'; 
else 
    $openAirNo = 'checked';



echo '<br />';
echo '<table style="min-width:300px;max-width:500px",border="0">';
echo '<form action="" method="post" accept-charset="utf-8">';
echo '
    <tr>
        <td>Pick a date</td>
        <td><input  class="datepicker" name="date" 
            value="' . $defaults[ 'date' ] . '" /> </td>
    </tr>
    <tr>
        <td>Start time </td>
        <td><input  class="timepicker" name="start_time" 
            value="' . $defaults[ 'start_time'] . '" /> </td>
    </tr>
    <tr>
        <td>End time </td>
        <td><input  class="timepicker" name="end_time" 
            value="' . $defaults[ 'end_time'] . '" /> </td>
    </tr>
    <tr>
        <td>Mininum seatings required? </td>
        <td><input type="text" name="strength" 
            value="' . $defaults[ 'strength' ] . '" /> </td>
    </tr>
    <tr>
        <td>Do you need video-conference facility?</td>
        <td>
            <input type="radio" name="has_skype" value="NO" ' . $skypeNo . ' /> No
            <input type="radio" name="has_skype" value="YES" ' .$skypeYes . ' /> Yes
        </td>
    </tr>
    <tr>
        <td>Do you need a projector?</td>
        <td>
        <input type="radio" name="has_projector" 
            value="NO" ' . $projectorNo . ' /> No
        <input type="radio" name="has_projector" 
                value="YES" ' .$projectorYes . ' /> Yes
        </td>
    </tr>
    <tr>
        <td>Prefer open-air location?</td>
        <td>
            <input type="radio" name="openair" value="NO"' . $openAirNo . ' $/> No
            <input type="radio" name="openair" value="YES"' . $openAirYes . ' /> Yes
        </td>
    </tr>
    <tr>
        <td></td>
        <td style="text-align:right">
        <button title="Scan for venues" 
            style="font-size:large" name="Response" value="scan">
                Show me <br> available venues</button>
        </td>
    </tr>
    ';

echo '</form>';
echo '</table>';

$date = __get__( $_POST, 'date', dbDate(strtotime( 'today' )) );

// Force this only if user is not admin.
if( ! anyOfTheseRoles( array( 'BOOKMYVENUE_ADMIN', 'AWS_ADMIN' ) ) )
{
    if( strtotime( $date ) >= strtotime( 'today' ) + 60 * 24 * 3600 )
    {
        echo alertUser( "You can not book more than 60 days in advance" );
        exit;
    }
}

// Get list of public events on user request day and show them to him. So he can 
// decides if some other timeslot should be used.
$publicEvents = getPublicEventsOnThisDay( $date );
if( count( $publicEvents ) > 0 )
{
    echo "<div style=\"font-size:small\">";
    echo alertUser( "Following public events are scheduled on the campus on 
        selected date" 
    );
    foreach( $publicEvents as $event )
        echo arrayToTableHTML( $event, 'events', ''
            , array( 'gid', 'eid', 'description', 'status', 'is_public_event'
            , 'external_id'
            , 'calendar_id', 'calendar_event_id', 'last_modified_on' 
            )
        );

    echo "</div>";
}

if( array_key_exists( 'Response', $_POST ) && $_POST['Response'] == "scan" )
{
    $date = humanReadableDate( $_POST[ 'date' ] );

    echo "<br/>";
    echo alertUser( "I found following venues available on $date" );

    $venues = getVenues( $sortby = 'name' );

    echo '<table border="0">';
    foreach ($venues as $venue) 
    {
        if( $venue[ 'strength' ] < $_POST[ 'strength' ] )
            continue;

{'fraction_non_alphanumeric': 0.17497532082922013, 'fraction_numerical': 0.006252056597564989, 'mean_word_length': 2.4994242947610825, 'pattern_counts': {'":': 0, '<': 163, '<?xml version=': 0, '>': 183, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2826740', 'n_tokens_mistral': 4247, 'n_tokens_neox': 4046, 'n_words': 1108}