function open_csa_wp_spot_form($spot_id, $display)
{
    wp_enqueue_script('open-csa-wp-general-scripts');
    wp_enqueue_script('open-csa-wp-spots-scripts');
    wp_enqueue_script('jquery.cluetip');
    wp_enqueue_style('jquery.cluetip.style');
    global $days_of_week, $wpdb;
    $spot_info;
    if ($spot_id != null) {
        $spot_info = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . OPEN_CSA_WP_TABLE_SPOTS . " WHERE id=%d", $spot_id));
    }
    ?>
	
	<br />
	<div id="open-csa-wp-showNewSpot_formHeader">
		<span 	
			id="open-csa-wp-showNewSpot_formHeader_text" 
			<?php 
    if ($spot_id == null) {
        echo 'style="cursor:pointer"';
        echo 'onclick="open_csa_wp_toggle_form(\'showNewSpot\',\'' . __('Add New Spot', OPEN_CSA_WP_DOMAIN) . '\', \' ' . __('form', OPEN_CSA_WP_DOMAIN) . '\')"';
    }
    ?>
>
			<font size='4'>
			<?php 
    if ($spot_id == null) {
        if ($display == false) {
            _e('Add New Spot (show form)', OPEN_CSA_WP_DOMAIN);
        } else {
            _e('Add New Spot (hide form)', OPEN_CSA_WP_DOMAIN);
        }
    } else {
        echo __('Edit Spot #', OPEN_CSA_WP_DOMAIN) . $spot_id;
    }
    ?>
		</font></span></div>
	<div id="open-csa-wp-showNewSpot_div" 
		<?php 
    if ($display == false) {
        echo "style='display:none'";
    }
    ?>
>
		<form method="POST" id="open-csa-wp-showNewSpot_form">
			<table class="form-table">
				<tr valign="top"><td>
					<input type="text" 
						<?php 
    if ($spot_id != null && $spot_info[0]->spot_name != "" && $spot_info[0]->spot_name != null) {
        echo "value='" . $spot_info[0]->spot_name . "'";
    }
    echo "placeholder=\"" . __('Spot Name *', OPEN_CSA_WP_DOMAIN) . "\"";
    ?>
						required 
						name="open-csa-wp-spots_spot_name_input" 
						onchange="open_csa_wp_request_spot_name_validity(this.value, <?php 
    echo $spot_id != null ? $spot_id : "null";
    ?>
 , 0, null)">
					<span id="open-csa-wp-showNewSpot_name_span_id" style="display:none"></span></td></tr>
				<tr valign="top"><td>
					<input 
						type="text" 
						<?php 
    if ($spot_id != null && $spot_info[0]->street_name != "" && $spot_info[0]->street_name != null) {
        echo "value='" . $spot_info[0]->street_name . "'";
    }
    echo "placeholder=\"" . __('Street Name *', OPEN_CSA_WP_DOMAIN) . "\"";
    ?>
						required 
						name="open-csa-wp-spots_street_name_input">
					<input 
						type="text" 
						<?php 
    if ($spot_id != null && $spot_info[0]->street_number != "" && $spot_info[0]->street_number != null) {
        echo "value='" . $spot_info[0]->street_number . "'";
    }
    echo "placeholder=\"" . __('Street Number *', OPEN_CSA_WP_DOMAIN) . "\"";
    ?>
						required 
						name="open-csa-wp-spots_street_number_input"></td></tr>
				<tr valign="top"><td>
					<input 
						type="text" 
						<?php 
    if ($spot_id != null && $spot_info[0]->city != "" && $spot_info[0]->city != null) {
        echo "value='" . $spot_info[0]->city . "'";
    }
    echo "placeholder=\"" . __('City *', OPEN_CSA_WP_DOMAIN) . "\"";
    ?>
						required 
						name="open-csa-wp-spots_city_input">
					<input 
						type="text" 
						<?php 
    if ($spot_id != null && $spot_info[0]->region != "" && $spot_info[0]->region != null) {
        echo "value='" . $spot_info[0]->region . "'";
    }
    echo "placeholder=\"" . __('Region *', OPEN_CSA_WP_DOMAIN) . "\"";
    ?>
						required 
						name="open-csa-wp-spots_region_input"></td></tr>
				<tr valign="top"><td>
					<textarea name="open-csa-wp-spots_description_input" rows="3" cols="30" 
						<?php 
    _e('placeholder="Description"', OPEN_CSA_WP_DOMAIN);
    ?>
						><?php 
    if ($spot_id != null) {
        echo $spot_info[0]->description;
    }
    ?>
</textarea></td></tr>
				
				<tr valign="top"><td>
					<select name="open-csa-wp-spots_is_delivery_spot_input" id="open-csa-wp-spots_is_delivery_spot_input_id"  onchange='open_csa_wp_show_new_spot_is_delivery_selection(this,<?php 
    echo $spot_id ? $spot_id : "null";
    ?>
)'
					<?php 
    if ($spot_id == null) {
        echo "style='color:#999'";
    }
    ?>
>
						<?php 
    if ($spot_id != null) {
        echo '
								<option value="" style="color:#999" disabled="disabled">Is this a delivery spot? *</option>
								<option value="yes" style="color:black". ' . ($spot_info[0]->is_delivery_spot == 1 ? "selected='selected'> it is a delivery spot" : ">yes") . ' </option>
								<option value="no" style="color:black"' . ($spot_info[0]->is_delivery_spot == 0 ? "selected='selected'> it is not a delivery spot" : ">no") . ' </option>
								';
    } else {
        ?>
							<option value="" selected="selected" disabled="disabled">Is this a delivery spot? *</option>
							<option value="yes" style="color:black"><?php 
        _e('yes', OPEN_CSA_WP_DOMAIN);
        ?>
</option>
							<option value="no" style="color:black"><?php 
        _e('no', OPEN_CSA_WP_DOMAIN);
        ?>
</option>
						<?php 
    }
    ?>
					</select> 
					<span id="open-csa-wp-showNewSpotForm_deliverySpot_span"></span>
				
				</td></tr>				
				
			</table> 
			<div id = "open-csa-wp-spots_deliverySpot_div" 
				<?php 
    $is_delivery_spot = $spot_id != null && $spot_info[0]->is_delivery_spot == 1 ? 1 : 0;
    if ($is_delivery_spot) {
        "style='display:block'";
    } else {
        echo "style='display:none'";
    }
    ?>
>
				<table class="form-table">		
				
				<tr valign="top"><td>
					<select 
						name="open-csa-wp-delivery_spot_owner_input" 
						id="open-csa-wp-delivery_spot_owner_input_id"
						<?php 
    if (!$is_delivery_spot) {
        echo "style='color:#999'";
    }
    ?>
						
						onfocus='getElementById("open-csa-wp-delivery_spot_owner_span_id").style.display = "none";'
						onchange='
							if (this.options[this.selectedIndex].text.split(" ")[0] != "<?php 
    _e('The owner of this delivery spot is', OPEN_CSA_WP_DOMAIN);
    ?>
".split(" ")[0]) 
								this.options[this.selectedIndex].text = "<?php 
    _e('The owner of this delivery spot is', OPEN_CSA_WP_DOMAIN);
    ?>
: "+ this.options[this.selectedIndex].text;
							(this.style.color=this.options[this.selectedIndex].style.color);'
					>
						<option value="" 
							<?php 
    if (!$is_delivery_spot) {
        echo "selected='selected'";
    }
    ?>
 
							disabled="disabled" id="open-csa-wp-delivery_spot_owner_disabled_id"><?php 
    _e('Owner of this delivery spot... *', OPEN_CSA_WP_DOMAIN);
    ?>
						</option>
						<?php 
    $spot_owner_id = null;
    if ($is_delivery_spot) {
        $spot_owner_id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM " . OPEN_CSA_WP_TABLE_SPOTS_TO_USERS . " WHERE spot_id=%d AND type='delivery' ", $spot_id), 0, 0);
    }
    open_csa_wp_select_users($spot_owner_id, __("The owner of this delivery spot is: ", OPEN_CSA_WP_DOMAIN));
    ?>
					</select> 
					<span style="display:none;color:blue" id="open-csa-wp-delivery_spot_owner_span_id"></span>
				</td></tr>
			
				<tr valign="top"><td>
					<select 
						name="open-csa-wp-spots_order_deadline_day_input"
						id='open-csa-wp-spots_order_deadline_day_input_id'
						onfocus='document.getElementById("open-csa-wp-showNewSpotForm_orderDeadline_span").style.display = "none";'
						onchange='
							this.style.color="black";
							if (this.options[this.selectedIndex].text.split(" ")[0] != "<?php 
    _e('Order deadline is on', OPEN_CSA_WP_DOMAIN);
    ?>
".split(" ")[0])
								this.options[this.selectedIndex].text = "<?php 
    _e('Order deadline is on', OPEN_CSA_WP_DOMAIN);
    ?>
: " + this.options[this.selectedIndex].text;
							getElementById("open-csa-wp-spots_order_deadline_time_input_id").style.display = "inline"
							'
						<?php 
    if (!$is_delivery_spot) {
        echo "style='color:#999'";
    }
    ?>
					>
					<option value="" 
						<?php 
    if (!$is_delivery_spot) {
        echo "selected='selected'";
    }
    ?>
						disabled="disabled" id="open-csa-wp-spots_order_deadline_day_disabled_id"><?php 
    _e('Order deadline day... *', OPEN_CSA_WP_DOMAIN);
    ?>
 </option>
					<?php 
    for ($i = 0; $i < 7; $i++) {
        if ($is_delivery_spot && $spot_info[0]->default_order_deadline_day == $i) {
            echo "<option value='{$i}' selected='selected' style='color:black'>" . __('Order deadline is on ', OPEN_CSA_WP_DOMAIN) . " {$days_of_week[$i]} </option>";
        } else {
            echo "<option value='{$i}' style='color:black'>" . $days_of_week[$i] . "</option>";
        }
    }
    ?>
					</select> 	
					<input 
						<?php 
    if ($is_delivery_spot && $spot_info[0]->default_order_deadline_time != "" && $spot_info[0]->default_order_deadline_time != null) {
        echo "value='" . __('up to', OPEN_CSA_WP_DOMAIN) . " " . open_csa_wp_remove_seconds($spot_info[0]->default_order_deadline_time) . "'";
    }
    if (!$is_delivery_spot) {
        echo "style='display:none'";
    }
    echo "placeholder=\"" . __('up to', OPEN_CSA_WP_DOMAIN) . "... *\"";
    ?>
						id="open-csa-wp-spots_order_deadline_time_input_id"
						class="textbox-n" type="text" size="10" name="open-csa-wp-spots_order_deadline_time_input"
						onfocus='
							if (this.value != "") {
								this.value=this.value.split(" ")[2];
							} else {
								getElementById("open-csa-wp-showNewSpotForm_orderDeadline_span").style.display = "none";
							}
							this.type="time";'
						onblur='
							this.type="text";
							if (this.value != "") {
								this.style.color="black";
								this.value = "<?php 
    _e('up to', OPEN_CSA_WP_DOMAIN);
    ?>
 " + this.value;
							}'>
					<span id="open-csa-wp-showNewSpotForm_orderDeadline_span" style="display:none"></span>
				</td></tr>
								
				<tr valign="top"><td>
					<select 
						name="open-csa-wp-spots_delivery_day_input" 
						id="open-csa-wp-spots_delivery_day_input_id"
						onfocus='getElementById("open-csa-wp-showNewSpotForm_invalidDeliveryTime_span").innerHTML = "";'
						onchange='
							this.style.color="black";
							if (this.options[this.selectedIndex].text.split(" ")[0] != "<?php 
    _e('Delivery day is', OPEN_CSA_WP_DOMAIN);
    ?>
".split(" ")[0]) {
								this.options[this.selectedIndex].text = "<?php 
    _e('Delivery day is', OPEN_CSA_WP_DOMAIN);
    ?>
 " + this.options[this.selectedIndex].text;
							}
							
							getElementById("open-csa-wp-showNewSpotForm_delivery_start_time_input_id").style.display = "inline"
							getElementById("open-csa-wp-showNewSpotForm_delivery_end_time_input_id").style.display = "inline";
						'
						<?php 
    if (!$is_delivery_spot) {
        echo "style='color:#999'";
    }
    ?>
>
					<option value="" disabled="disabled" 
						<?php 
    if (!$is_delivery_spot) {
        echo "selected='selected'";
    }
    ?>
						id="open-csa-wp-spots_delivery_day_disabled_id"><?php 
    _e('Delivery day', OPEN_CSA_WP_DOMAIN);
    ?>
... *</option>
					<?php 
    for ($i = 0; $i < 7; $i++) {
        if ($is_delivery_spot && $spot_info[0]->default_delivery_day == $i) {
            echo "<option value='{$i}' selected='selected'>" . __('Delivery day is', OPEN_CSA_WP_DOMAIN) . " {$days_of_week[$i]} </option>";
        } else {
            echo "<option value='{$i}'>" . $days_of_week[$i] . "</option>";
        }
    }
    ?>
					</select> 
					<input id="open-csa-wp-showNewSpotForm_delivery_start_time_input_id"
						<?php 
    if ($is_delivery_spot && $spot_info[0]->default_delivery_start_time != "" && $spot_info[0]->default_delivery_start_time != null) {
        echo "value='" . __('from', OPEN_CSA_WP_DOMAIN) . " " . open_csa_wp_remove_seconds($spot_info[0]->default_delivery_start_time) . "'";
    }
    if (!$is_delivery_spot) {
        echo "style='display:none'";
    }
    echo "placeholder=\"" . __('from', OPEN_CSA_WP_DOMAIN) . "... *\"";
    ?>
						class="textbox-n" type="text" size="10" name="open-csa-wp-spots_delivery_start_time_input"

						onfocus='
							if (this.value != "") {
								this.value=this.value.split(" ")[1];
							} else {
								getElementById("open-csa-wp-showNewSpotForm_invalidDeliveryTime_span").style.display = "none";
							}
							this.type="time";'
						onblur='
							this.type="text";
							if (this.value == "") {
								getElementById("open-csa-wp-showNewSpotForm_delivery_end_time_input_id").value = "";
							}
							else {
								this.style.color="black";
								this.value = "<?php 
    _e('from', OPEN_CSA_WP_DOMAIN);
    ?>
 " + this.value;
								open_csa_wp_validate_delivery_time_period("showNewSpotForm");
							}'>
					<input id="open-csa-wp-showNewSpotForm_delivery_end_time_input_id"
						<?php 
    if ($is_delivery_spot && $spot_info[0]->default_delivery_end_time != "" && $spot_info[0]->default_delivery_end_time != null) {
        echo "value='" . __('to', OPEN_CSA_WP_DOMAIN) . " " . open_csa_wp_remove_seconds($spot_info[0]->default_delivery_end_time) . "'";
    }
    if (!$is_delivery_spot) {
        echo "style='display:none'";
    }
    echo "placeholder=\"" . __('to', OPEN_CSA_WP_DOMAIN) . "... *\"";
    ?>
						class="textbox-n" type="text" size="10" name="open-csa-wp-spots_delivery_end_time_input"
						
						onfocus='
							if (this.value != "") { 
								this.value=this.value.split(" ")[1];
							}
							getElementById("open-csa-wp-showNewSpotForm_invalidDeliveryTime_span").style.display = "none";
							this.type="time";'
						onblur='
							this.type="text";
							if (this.value != "") {
								this.style.color="black";
								this.value = "<?php 
    _e('to', OPEN_CSA_WP_DOMAIN);
    ?>
 " + this.value;
								open_csa_wp_validate_delivery_time_period("showNewSpotForm");
							}
						'>
					<span id="open-csa-wp-showNewSpotForm_invalidDeliveryTime_span"> </span>
				</td></tr>
			
				<tr valign="top"><td>
				<select 
					name="open-csa-wp-spots_close_input" 
					id="open-csa-wp-spots_close_input_id"
					<?php 
    if (!$is_delivery_spot) {
        echo "style='color:#999'";
    }
    ?>
					onfocus='getElementById("open-csa-wp-showNewSpotForm_ordersClose_span_id").innerHTML = "";'
					onchange='
						this.style.color="black";
						if (this.options[this.selectedIndex].text.split(" ")[0] != "<?php 
    _e('Order close', OPEN_CSA_WP_DOMAIN);
    ?>
".split(" ")[0]) {
							this.options[this.selectedIndex].text = "<?php 
    _e('Order close', OPEN_CSA_WP_DOMAIN);
    ?>
 "+this.options[this.selectedIndex].text;
						}
						getElementById("open-csa-wp-spots_close_"+ this.options[this.selectedIndex].value).style.display= "inline";
						getElementById("open-csa-wp-spots_close_"+ this.options[((this.selectedIndex-1)+1)%2+1].value).style.display="none"'>
					<option value="" 
						<?php 
    if (!$is_delivery_spot) {
        echo "selected='selected'";
    }
    ?>
 
						disabled="disabled" id="open-csa-wp-spots_close_disabled_id"><?php 
    _e('Order close', OPEN_CSA_WP_DOMAIN);
    ?>
... *</option>
					<option value="automatic" 
						<?php 
    if ($is_delivery_spot && $spot_info[0]->close_order == "automatic") {
        echo "selected='selected'";
    }
    ?>
 
						title="<?php 
    _e("Orders' submission will be closed automatically when order submission deadline is reached", OPEN_CSA_WP_DOMAIN);
    ?>
">
						<?php 
    if ($is_delivery_spot && $spot_info[0]->close_order == "automatic") {
        echo __('Order close', OPEN_CSA_WP_DOMAIN) . " ";
    }
    ?>
						automatically</option>
					<option value="manual" 
						<?php 
    if ($is_delivery_spot && $spot_info[0]->close_order == "manual") {
        echo "selected='selected'";
    }
    ?>
 
						title="<?php 
    _e("Orders' submission will be closed manually by the user that is responsible for the delivery", OPEN_CSA_WP_DOMAIN);
    ?>
">
						<?php 
    if ($is_delivery_spot && $spot_info[0]->close_order == "manual") {
        echo __('Order close', OPEN_CSA_WP_DOMAIN) . " ";
    }
    ?>
						manually</option>
				</select>
				<span 
					<?php 
    if (!$is_delivery_spot || $spot_info[0]->close_order != "automatic") {
        echo "style='display:none;color:gray'";
    } else {
        echo "style='color:gray'";
    }
    ?>
 
					id="open-csa-wp-spots_close_automatic" 
					class="open-csa-wp-tip_spots"
					title="<?php 
    _e("Orders' submission will be closed automatically when order submission deadline is reached", OPEN_CSA_WP_DOMAIN);
    ?>
"
				>&nbsp;i.e. ... (point here)</span>
				<span 
					<?php 
    if (!$is_delivery_spot || $spot_info[0]->close_order != "manual") {
        echo "style='display:none;color:gray'";
    } else {
        echo "style='color:gray'";
    }
    ?>
 
					id="open-csa-wp-spots_close_manual"
					class="open-csa-wp-tip_spots"
					title="<?php 
    _e("Orders' submission will be closed manually by the user that is responsible for the delivery", OPEN_CSA_WP_DOMAIN);
    ?>
"
				>&nbsp;i.e. ... (point here)</span>
				<span id="open-csa-wp-showNewSpotForm_ordersClose_span_id"></span>
				</td></tr>

				<tr valign="top"><td>
					<select 
						name="open-csa-wp-spots_parking_input" 
						id="open-csa-wp-spots_parking_input_id"
						<?php 
    $styleAttributes = "style='color:";
    if (!$is_delivery_spot || $spot_info[0]->parking == "") {
        $styleAttributes = $styleAttributes . "#999'";
    } else {
        if ($spot_info[0]->parking == "easy") {
            $styleAttributes = $styleAttributes . "blue'";
        } else {
            if ($spot_info[0]->parking == "possible") {
                $styleAttributes = $styleAttributes . "green'";
            } else {
                if ($spot_info[0]->parking == "hard") {
                    $styleAttributes = $styleAttributes . "orange'";
                } else {
                    if ($spot_info[0]->parking == "impossible") {
                        $styleAttributes = $styleAttributes . "brown'";
                    }
                }
            }
        }
    }
    echo $styleAttributes;
    ?>
						
						onfocus='getElementById("open-csa-wp-showNewSpotForm_parkingSpace_span_id").style.display = "none";'
						onchange='
							this.style.color=this.options[this.selectedIndex].style.color;
							if (this.options[this.selectedIndex].text.split(" ")[0] != "Finding") {
								this.options[this.selectedIndex].text = "Finding parking space is " + this.options[this.selectedIndex].text;
							}'
					>
						<option value="" 
						<?php 
    if (!$is_delivery_spot || $spot_info[0]->parking == "") {
        echo "selected='selected'";
    }
    ?>
 
							disabled="disabled" id="open-csa-wp-spots_parking_disabled_id"><?php 
    _e("Finding parking space is", OPEN_CSA_WP_DOMAIN);
    ?>
...</option>
						<option value="easy" 
							<?php 
    if ($is_delivery_spot && $spot_info[0]->parking != "" && $spot_info[0]->parking == "easy") {
        echo "selected='selected'";
    }
    ?>
 
							style="color:blue">
							<?php 
    if ($is_delivery_spot && $spot_info[0]->parking != "" && $spot_info[0]->parking == "easy") {
        echo __('Finding parking space is', OPEN_CSA_WP_DOMAIN) . " ";
    }
    ?>
							easy :)</option>
						<option value="possible" 
							<?php 
    if ($is_delivery_spot && $spot_info[0]->parking != "" && $spot_info[0]->parking == "possible") {
        echo "selected='selected'";
    }
    ?>
 
							style="color:green">
							<?php 
    if ($is_delivery_spot && $spot_info[0]->parking != "" && $spot_info[0]->parking == "possible") {
        echo __('Finding parking space is', OPEN_CSA_WP_DOMAIN) . " ";
    }
    ?>
							possible :)</option>
						<option value="hard" 
							<?php 
    if ($is_delivery_spot && $spot_info[0]->parking != "" && $spot_info[0]->parking == "hard") {
        echo "selected='selected'";
    }
    ?>
 
							style="color:orange">
							<?php 
    if ($is_delivery_spot && $spot_info[0]->parking != "" && $spot_info[0]->parking == "hard") {
        echo __('Finding parking space is', OPEN_CSA_WP_DOMAIN) . " ";
    }
    ?>
							hard :(</option>
						<option value="impossible" 
							<?php 
    if ($is_delivery_spot && $spot_info[0]->parking != "" && $spot_info[0]->parking == "impossible") {
        echo "selected='selected'";
    }
    ?>
 
							style="color:brown">
							<?php 
    if ($is_delivery_spot && $spot_info[0]->parking != "" && $spot_info[0]->parking == "impossible") {
        echo __('Finding parking space is', OPEN_CSA_WP_DOMAIN) . " ";
    }
    ?>
							impossible :(</option>
					</select>
					<span style="display:none;color:blue" id="open-csa-wp-showNewSpotForm_parkingSpace_span_id"></span>
				</td></tr>
				<tr valign="top"><td>
					<select 
						name="open-csa-wp-spots_refrigerator_input" 
						id="open-csa-wp-spots_refrigerator_input_id"
						<?php 
    $styleAttributes = "style='color:";
    if (!$is_delivery_spot || $spot_info[0]->has_refrigerator == "") {
        $styleAttributes = $styleAttributes . "#999'";
    } else {
        if ($spot_info[0]->has_refrigerator == "1") {
            $styleAttributes = $styleAttributes . "green'";
        } else {
            if ($spot_info[0]->has_refrigerator == "0") {
                $styleAttributes = $styleAttributes . "brown'";
            }
        }
    }
    echo $styleAttributes;
    ?>
						
						onfocus='getElementById("open-csa-wp-showNewSpotForm_hasRefrigerator_span_id").style.display = "none";'
						onchange='
							(this.style.color=this.options[this.selectedIndex].style.color);
							if (this.options[this.selectedIndex].value == "yes") {
								this.options[this.selectedIndex].text = "<?php 
    _e('It has refrigerator to store products', OPEN_CSA_WP_DOMAIN);
    ?>
! :)";
							}
							else {
								this.options[this.selectedIndex].text = "<?php 
    _e('It does not have refrigerator to store products', OPEN_CSA_WP_DOMAIN);
    ?>
! :("
							}'
					>
						<option value="" 
							<?php 
    if (!$is_delivery_spot || $spot_info[0]->has_refrigerator == "") {
        echo "selected='selected'";
    }
    ?>
 
							disabled="disabled" id="open-csa-wp-spots_refrigerator_disabled_id"><?php 
    _e('Does it have refrigerator to store products', OPEN_CSA_WP_DOMAIN);
    ?>
...?</option>
						<option value="yes" style="color:green"
							<?php 
    if ($is_delivery_spot && $spot_info[0]->has_refrigerator != "" && $spot_info[0]->has_refrigerator == "1") {
        echo "selected='selected'";
    }
    ?>
 
							>
							<?php 
    if ($is_delivery_spot && $spot_info[0]->has_refrigerator != "" && $spot_info[0]->has_refrigerator == "1") {
        echo __('It has refrigerator to store products', OPEN_CSA_WP_DOMAIN) . "! :) ";
    } else {
        echo __("yes", OPEN_CSA_WP_DOMAIN);
    }
    ?>
 </option>
						<option value="no" style="color:brown"
							<?php 
    if ($is_delivery_spot && $spot_info[0]->has_refrigerator != "" && $spot_info[0]->has_refrigerator == "0") {
        echo "selected='selected'";
    }
    ?>
 
							>
							<?php 
    if ($is_delivery_spot && $spot_info[0]->has_refrigerator != "" && $spot_info[0]->has_refrigerator == "0") {
        echo _e('It does not have refrigerator to store products', OPEN_CSA_WP_DOMAIN) . "! :( ";
    } else {
        echo __("no", OPEN_CSA_WP_DOMAIN);
    }
    ?>
</option>
					</select> 
					<span style="display:none;color:blue" id="open-csa-wp-showNewSpotForm_hasRefrigerator_span_id"></span>
				</td></tr>
				
			</table> 
			</div>
			<input 
				type="submit" 
				name="open-csa-wp-showNewSpot_button" 
				id="open-csa-wp-showNewSpot_button_id"
				<?php 
    if ($spot_id == null) {
        echo "\n\t\t\t\t\t\t\tvalue='" . __('Add Spot', OPEN_CSA_WP_DOMAIN) . "'\n\t\t\t\t\t\t\tonclick='open_csa_wp_new_spot_fields_validation(this, null, \"" . admin_url("/admin.php?page=csa_spots_management") . "\")'\n\t\t\t\t\t\t";
    } else {
        echo "\n\t\t\t\t\t\t\tvalue='" . __('Update Spot', OPEN_CSA_WP_DOMAIN) . "'\n\t\t\t\t\t\t\tonclick='open_csa_wp_new_spot_fields_validation(this, {$spot_id}, \"" . admin_url("/admin.php?page=csa_spots_management") . "\")'\n\t\t\t\t\t\t";
    }
    ?>
				class="button button-primary"
				title="<?php 
    __('Please fill in required fields, i.e. those marked with (*)', OPEN_CSA_WP_DOMAIN);
    ?>
"
			/>
			<input 
				type="button"
				class="button button-secondary"
				<?php 
    if ($spot_id == null) {
        echo "\n\t\t\t\t\tvalue='" . __('Reset Info', OPEN_CSA_WP_DOMAIN) . "'\n\t\t\t\t\tonclick='open_csa_wp_reset_spot_form();'";
    } else {
        echo "\n\t\t\t\t\tvalue='" . __('Cancel', OPEN_CSA_WP_DOMAIN) . "'\n\t\t\t\t\tonclick='window.location.replace(\"" . admin_url('/admin.php?page=csa_spots_management') . "\")'\n\t\t\t\t\t'";
    }
    ?>
			/>
		</form>
		<br/><br/>
	</div>
	
<?php 
}
function open_csa_wp_show_delivery_orders_list($personal_user_id, $is_producer, $display)
{
    wp_enqueue_script('open-csa-wp-general-scripts');
    wp_enqueue_script('open-csa-wp-deliveries-scripts');
    wp_enqueue_script('jquery.datatables');
    wp_enqueue_script('jquery.jeditable');
    wp_enqueue_script('jquery.blockui');
    wp_enqueue_script('jquery.cluetip');
    wp_enqueue_style('jquery.cluetip.style');
    global $wpdb;
    if ($personal_user_id != null && $is_producer == false) {
        $deivery_orders_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM " . OPEN_CSA_WP_TABLE_DELIVERIES . " WHERE user_in_charge = %d ", $personal_user_id));
    } else {
        $deivery_orders_count = $wpdb->get_var("SELECT COUNT(id) FROM " . OPEN_CSA_WP_TABLE_DELIVERIES);
    }
    if ($deivery_orders_count == 0) {
        if ($personal_user_id == null) {
            "<br/><div style='color:brown'>" . __('No delivery has yet been initiated.', OPEN_CSA_WP_DOMAIN) . "</div>";
        } else {
            if ($is_producer == false) {
                echo "<br/><div style='color:brown'>" . __('You have not yet become responsible for any delivery.', OPEN_CSA_WP_DOMAIN) . "</div>";
            }
        }
    } else {
        if ($personal_user_id) {
            $text_to_show = __("List", OPEN_CSA_WP_DOMAIN);
        } else {
            $text_to_show = __("Delivery Total Orders List", OPEN_CSA_WP_DOMAIN);
        }
        if ($is_producer === true) {
            $text_for_label = "showDeliveryOrdersListProducer";
        } else {
            $text_for_label = "showDeliveryOrdersList";
        }
        ?>
		
		<br />
		<div
			id='open-csa-wp-<?php 
        echo $text_for_label;
        ?>
_header'
		>
			<span 
				style="cursor:pointer" 
				id="open-csa-wp-<?php 
        echo $text_for_label;
        ?>
_formHeader_text" 
				onclick="open_csa_wp_toggle_form('<?php 
        echo $text_for_label;
        ?>
','<?php 
        echo $text_to_show;
        ?>
', '')">
				<font size='4'>
				<?php 
        if ($display == false) {
            echo "{$text_to_show} (" . __("show", OPEN_CSA_WP_DOMAIN) . ")";
        } else {
            echo "{$text_to_show} (" . __("hide", OPEN_CSA_WP_DOMAIN) . ")";
        }
        ?>
				</font>
			</span>
		</div>
		<div id="open-csa-wp-<?php 
        echo $text_for_label;
        ?>
_div" 
			<?php 
        if ($display == false) {
            echo 'style="display:none"';
        }
        ?>
	
		>
			<span class='open-csa-wp-tip_order' title='
					<?php 
        _e('Deliveries in "green" are pending and still accept new orders.', OPEN_CSA_WP_DOMAIN);
        ?>
					| <?php 
        _e('Deliveries in "brown" are pending and do not accept new orders.', OPEN_CSA_WP_DOMAIN);
        ?>
					| <?php 
        _e('Deliveries in "grey" are accomplished.', OPEN_CSA_WP_DOMAIN);
        ?>
					| <?php 
        _e('To view the total user orders for some delivery, click the "magnifier" icon.', OPEN_CSA_WP_DOMAIN);
        ?>
				'>
			<p style="color:green;font-style:italic; font-size:13px">
				<?php 
        _e('by pointing here you can read additional information...', OPEN_CSA_WP_DOMAIN);
        ?>
</p></span>


			<table 
				class='table-bordered' 
				id="open-csa-wp-<?php 
        echo $text_for_label;
        ?>
_table" 
				style='border-spacing:1em' 
			> 
			<thead class='tableHeader'>
				<tr>
					<th><?php 
        _e('Spot', OPEN_CSA_WP_DOMAIN);
        ?>
</th>
					<th><?php 
        _e('Order Deadline Date', OPEN_CSA_WP_DOMAIN);
        ?>
</th>
					<th><?php 
        _e('Order Deadline Time', OPEN_CSA_WP_DOMAIN);
        ?>
</th>
					<th><?php 
        _e('Delivery Date', OPEN_CSA_WP_DOMAIN);
        ?>
</th>
					<th><?php 
        _e('Delivery Start Time', OPEN_CSA_WP_DOMAIN);
        ?>
</th>
					<th><?php 
        _e('Delivery End Time', OPEN_CSA_WP_DOMAIN);
        ?>
</th>
					<?php 
        if ($personal_user_id == null || $is_producer === true) {
            echo "<th>" . __('User In Charge', OPEN_CSA_WP_DOMAIN) . "</th>";
        }
        ?>
					<th><?php 
        _e('New Orders Can be Submitted?', OPEN_CSA_WP_DOMAIN);
        ?>
</th>
					<th/>
				</tr>
			</thead> 
			<tbody> <?php 
        global $wpdb;
        $plugins_dir = plugins_url();
        if ($personal_user_id == null || $is_producer === true) {
            $deliveries = $wpdb->get_results("SELECT * FROM " . OPEN_CSA_WP_TABLE_DELIVERIES);
        } else {
            $deliveries = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . OPEN_CSA_WP_TABLE_DELIVERIES . " WHERE user_in_charge = %d ", $personal_user_id));
        }
        foreach ($deliveries as $delivery) {
            $delivery_id = $delivery->id;
            $spot_name = $wpdb->get_var($wpdb->prepare("SELECT spot_name FROM " . OPEN_CSA_WP_TABLE_SPOTS . " WHERE id=%d", $delivery->spot_id));
            $user_in_charge_login = "";
            if ($delivery->user_in_charge != null) {
                $user_in_charge_login = get_user_by('id', $delivery->user_in_charge)->user_login;
            }
            $past_delivery = false;
            $current_date_time = current_time('mysql');
            if (strtotime($delivery->order_deadline_date . " " . $delivery->order_deadline_time) < strtotime($current_date_time)) {
                $past_delivery = true;
            }
            echo "\n\t\t\t\t\t\t<tr \n\t\t\t\t\t\t\tvalign='top' \n\t\t\t\t\t\t\tid='open-csa-wp-showDeliveriesDeliveryID_{$delivery_id}'  \n\t\t\t\t\t\t\tclass='open-csa-wp-showDeliveries-delivery'\n\t\t\t\t\t\t\tstyle='color:" . ($past_delivery === true ? "gray" : ($delivery->are_orders_open == 1 ? "green" : "brown")) . "'\n\t\t\t\t\t\t>\n\t\t\t\t\t\t<td style='text-align:center'>{$spot_name} </td>\n\t\t\t\t\t\t<td style='text-align:center'>" . date(OPEN_CSA_WP_DATE_FORMAT_READABLE, strtotime($delivery->order_deadline_date)) . "</td>\n\t\t\t\t\t\t<td style='text-align:center'>" . open_csa_wp_remove_seconds($delivery->order_deadline_time) . "</td>\n\t\t\t\t\t\t<td style='text-align:center'>" . date(OPEN_CSA_WP_DATE_FORMAT_READABLE, strtotime($delivery->delivery_date)) . "</td>\n\t\t\t\t\t\t<td style='text-align:center'>" . open_csa_wp_remove_seconds($delivery->delivery_start_time) . "</td>\n\t\t\t\t\t\t<td style='text-align:center'>" . open_csa_wp_remove_seconds($delivery->delivery_end_time) . "</td>\n\t\t\t\t\t\t" . ($personal_user_id == null || $is_producer === true ? "<td style='text-align:center'>" . $user_in_charge_login . "</td>" : "") . "\n\t\t\t\t\t\t<td style='text-align:center'\n\t\t\t\t\t\t\tclass='editable_boolean'\n\t\t\t\t\t\t\tid = 'open-csa-wp-showDeliveriesOpenOrdersID_{$delivery_id}'\n\t\t\t\t\t\t>" . ($delivery->are_orders_open == 1 ? "yes" : "no") . "</td>\n\t\t\t\t\t\t<td style='text-align:center'> \n\t\t\t\t\t\t\t<img \n\t\t\t\t\t\t\t\twidth='24' height='24'  \n\t\t\t\t\t\t\t\tclass='delete no-underline' \n\t\t\t\t\t\t\t\tsrc='{$plugins_dir}/open-csa-wp/icons/magnifier.png' \n\t\t\t\t\t\t\t\tstyle='cursor:pointer;padding-left:10px;' \n\t\t\t\t\t\t\t\tonclick='open_csa_wp_request_total_orders_of_delivery(" . $delivery_id . ", " . ($is_producer === true ? "{$personal_user_id}" : "null") . ");' \n\t\t\t\t\t\t\t\ttitle='" . __('click to view the total user orders for this delivery', OPEN_CSA_WP_DOMAIN) . "'/></td>\n\t\t\t\t\t\t</tr>\n\n\t\t\t\t\t";
        }
        ?>
			</tbody> </table>
		</div>	
<?php 
    }
}
function CsaWpPluginGetReadableDeliveryInfo($delivery_id)
{
    global $days_of_week, $wpdb;
    $delivery_info = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . OPEN_CSA_WP_TABLE_DELIVERIES . " WHERE id=%d", $delivery_id))[0];
    $spotName = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\t\t\t\tSELECT DISTINCT " . OPEN_CSA_WP_TABLE_SPOTS . ".spot_name \n\t\t\t\t\t\t\t\t\tFROM " . OPEN_CSA_WP_TABLE_DELIVERIES . " LEFT JOIN " . OPEN_CSA_WP_TABLE_SPOTS . " ON " . OPEN_CSA_WP_TABLE_DELIVERIES . ".spot_id = " . OPEN_CSA_WP_TABLE_SPOTS . ".id\n\t\t\t\t\t\t\t\t\tWHERE " . OPEN_CSA_WP_TABLE_DELIVERIES . ".id = %d\n\t\t\t\t\t\t\t\t", $delivery_id));
    $deadlineDate = $delivery_info->order_deadline_date;
    $order_deadline_day = (date("w", strtotime($deadlineDate)) - 1) % 7;
    $deadline_day = $days_of_week[$order_deadline_day];
    $delivery_date = $delivery_info->delivery_date;
    $delivery_day = (date("w", strtotime($delivery_date)) - 1) % 7;
    $delivery_day = $days_of_week[$delivery_day];
    $delivery_info_readable = __('Delivery for spot', OPEN_CSA_WP_DOMAIN) . " {$spotName} " . __('with', OPEN_CSA_WP_DOMAIN) . "\n\t\t" . __('deadline on', OPEN_CSA_WP_DOMAIN) . " {$deadline_day} ," . date(OPEN_CSA_WP_DATE_FORMAT_READABLE, strtotime($deadlineDate)) . ", \n\t\t\tup to " . open_csa_wp_remove_seconds($delivery_info->order_deadline_time) . ",\n\t\t" . __('and delivery on', OPEN_CSA_WP_DOMAIN) . " {$delivery_day}," . date(OPEN_CSA_WP_DATE_FORMAT_READABLE, strtotime($delivery_date)) . ", \n\t\t\t" . __('from', OPEN_CSA_WP_DOMAIN) . " " . open_csa_wp_remove_seconds($delivery_info->delivery_start_time) . "\n\t\t\t" . __('up to', OPEN_CSA_WP_DOMAIN) . " " . open_csa_wp_remove_seconds($delivery_info->delivery_end_time);
    return $delivery_info_readable;
}