function open_csa_wp_show_new_product_form($product_id, $display, $page_url)
{
    wp_enqueue_script('open-csa-wp-general-scripts');
    wp_enqueue_script('open-csa-wp-products-scripts');
    global $days_of_week, $wpdb;
    $product_info;
    if ($product_id != null) {
        $product_info = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . OPEN_CSA_WP_TABLE_PRODUCTS . " WHERE id=%d", $product_id));
    }
    ?>

	<br/>
	<div id="open-csa-wp-addProduct_formHeader">
		<span 
			id="open-csa-wp-addProduct_formHeader_text" 
			<?php 
    if ($product_id == null) {
        echo 'style="cursor:pointer"';
        echo 'onclick="open_csa_wp_toggle_form(\'addProduct\',\'' . __('Add New Product', OPEN_CSA_WP_DOMAIN) . '\', \' ' . __('form', OPEN_CSA_WP_DOMAIN) . '\')"';
    }
    ?>
>
			<font size='4'>
			<?php 
    if ($product_id == null) {
        if ($display == false) {
            echo __('Add New Product', OPEN_CSA_WP_DOMAIN) . ' (' . __('show form', OPEN_CSA_WP_DOMAIN) . ')';
        } else {
            echo __('Add New Product', OPEN_CSA_WP_DOMAIN) . ' (' . __('hide form', OPEN_CSA_WP_DOMAIN) . ')';
        }
    } else {
        echo __('Edit Product', OPEN_CSA_WP_DOMAIN) . ' #' . $product_id;
    }
    ?>

			</font>
		</span>
	</div>
	<div id="open-csa-wp-addProduct_div" 
		<?php 
    if ($display == false) {
        echo 'style="display:none"';
    }
    ?>
	
	>
		<form method="POST" id='open-csa-wp-showNewProduct_form'>
			<table class="form-table">
				<tr valign="top">
					<td>
					<input 
						type='text' 
						<?php 
    if ($product_id != null && $product_info[0]->name != "" && $product_info[0]->name != null) {
        echo "value='" . $product_info[0]->name . "'";
    }
    ?>
						placeholder='<?php 
    _e('Product Name', OPEN_CSA_WP_DOMAIN);
    ?>
 *' 
						name="open-csa-wp-product_name_input" 
						required></td></tr>
				<tr valign="top"><td>
					<select 
						name="open-csa-wp-product_category_input" 
						id="open-csa-wp-newProductForm_category_input_id"
						<?php 
    if ($product_id == null) {
        echo "style='color:#999'";
    }
    ?>
						onfocus = '
							getElementById("open-csa-wp-newProductForm_category_input_span_id").style.display = "none";
						'
						onchange = '
							this.style.color="black"
							if (this.options[this.selectedIndex].text.split(" ")[0] != "<?php 
    _e('Category is', OPEN_CSA_WP_DOMAIN);
    ?>
".split(" ")[0]) {
								this.options[this.selectedIndex].text = "<?php 
    _e('Category is', OPEN_CSA_WP_DOMAIN);
    ?>
 " + this.options[this.selectedIndex].text;
							}
						'
					>
					<option 
						value="" 
						selected='selected' 
						disabled='disabled'
						id = "open-csa-wp-newProductForm_category_input_disabled_id"
					>Category *</option>
 					<?php 
    echo open_csa_wp_select_options_from_db(array("name"), "id", OPEN_CSA_WP_TABLE_PRODUCT_CATEGORIES, $product_id != null ? $product_info[0]->category : null, __("Category is ", OPEN_CSA_WP_DOMAIN));
    ?>
                  	</select>
					<span id="open-csa-wp-newProductForm_category_input_span_id"></span>
				</td></tr>
					
				<tr valign="top"><td>
					<select 
						name="open-csa-wp-product_producer_input"
						id="open-csa-wp-newProductForm_producer_input_id"
						onfocus = '
							getElementById("open-csa-wp-newProductForm_producer_input_span_id").style.display = "none";
						'					
						onchange = '
							this.style.color="black"
							if (this.options[this.selectedIndex].text.split(" ")[0] != "<?php 
    _e('Producer is', OPEN_CSA_WP_DOMAIN);
    ?>
".split(" ")[0]) {
								this.options[this.selectedIndex].text = "<?php 
    _e('Producer is', OPEN_CSA_WP_DOMAIN);
    ?>
 " + this.options[this.selectedIndex].text;
							}
						'
						<?php 
    if ($product_id == null) {
        echo "style='color:#999'";
    }
    ?>
					>
						<option 
							value="" 
							<?php 
    if ($product_id == null) {
        echo "selected='selected'";
    }
    ?>
							disabled='disabled'
							id = "open-csa-wp-newProductForm_producer_input_disabled_id"
						>Producer *</option>
						<?php 
    echo open_csa_wp_select_users_of_type("producer", $product_id != null ? $product_info[0]->producer : null, __("Producer is ", OPEN_CSA_WP_DOMAIN));
    ?>
					</select>
					<span id="open-csa-wp-newProductForm_producer_input_span_id"></span>
				</td></tr>

				<tr valign="top">
					<td>
					<input 
						type='text' 
						onfocus = ' 
							getElementById ("open-csa-wp-showNewProduct_button_id").disabled=true;
							if (this.value != "") {
								this.value = (this.value.split(" ").slice(2)).join(" ");
							}
						'
						onblur = '
							getElementById ("open-csa-wp-showNewProduct_button_id").disabled=false;
							if (this.value != "") {
								this.value = "<?php 
    _e('Variety is', OPEN_CSA_WP_DOMAIN);
    ?>
 "+ this.value;
							}
						'
						<?php 
    if ($product_id != null && $product_info[0]->variety != "" && $product_info[0]->variety != null) {
        echo "value='" . __('Variety is', OPEN_CSA_WP_DOMAIN) . " " . $product_info[0]->variety . "'";
    }
    ?>
						placeholder='<?php 
    _e('Variety', OPEN_CSA_WP_DOMAIN);
    ?>
 *' 
						required 
						name="open-csa-wp-product_variety_input">
					</td>
				</tr>
				<tr valign="top">
					<td>
					<input 
						min='0' step='0.1'
						<?php 
    if ($product_id != null && $product_info[0]->current_price_in_euro != "" && $product_info[0]->current_price_in_euro != null) {
        echo "type='text'";
        echo "style='width:8em; text-align:right'";
        echo 'value = "' . __('It costs', OPEN_CSA_WP_DOMAIN) . ' ' . $product_info[0]->current_price_in_euro . '"';
    } else {
        echo "type='number'";
        echo "style='width:8em'";
    }
    ?>
						placeholder='<?php 
    _e('Price', OPEN_CSA_WP_DOMAIN);
    ?>
 *' 
						onfocus = '
							getElementById ("open-csa-wp-showNewProduct_button_id").disabled=true;
							this.value = this.value.split(" ")[2];
							this.type = "number";
						'
						onblur = '
							getElementById ("open-csa-wp-showNewProduct_button_id").disabled=false;
							this.type = "text";
							if (this.value == "") {
								this.style.textAlign="left";
							} else {
								this.value = "<?php 
    _e('It costs', OPEN_CSA_WP_DOMAIN);
    ?>
 " + this.value;
								this.style.textAlign="right";
							}
						'
						name="open-csa-wp-product_price_input" required> € &nbsp;
					<select 
						name="open-csa-wp-product_unit_input" 
						id="open-csa-wp-newProductForm_unit_input_id"
						<?php 
    if ($product_id == null) {
        echo "style='color:#999'";
    }
    ?>
						onfocus = '
							getElementById("open-csa-wp-newProductForm_unit_input_span_id").style.display = "none";
						'
						onchange = '
							this.style.color="black";
							if (this.options[this.selectedIndex].text.split(" ")[0] != "<?php 
    _e('per', OPEN_CSA_WP_DOMAIN);
    ?>
") {
								this.options[this.selectedIndex].text = "<?php 
    _e('per', OPEN_CSA_WP_DOMAIN);
    ?>
 " + this.options[this.selectedIndex].text;
							}
					'>
						<option 
							value="" 
							<?php 
    if ($product_id == null) {
        echo "selected='selected'";
    }
    ?>
							disabled='disabled'
							id = "open-csa-wp-newProductForm_unit_input_disabled_id"
						>per... *</option>
						<?php 
    echo open_csa_wp_select_measurement_unit($product_id, $product_info);
    ?>
					</select> 
					<span id="open-csa-wp-newProductForm_unit_input_span_id"></span>
				</td></tr>
				<tr valign="top">
					<td>
						<textarea placeholder='<?php 
    _e('Description', OPEN_CSA_WP_DOMAIN);
    ?>
' rows="3" cols="30" name="open-csa-wp-product_descritpion_input"
						><?php 
    if ($product_id != null && $product_info[0]->description != "" && $product_info[0]->description != null) {
        echo $product_info[0]->description;
    }
    ?>
</textarea></td></tr>


				<tr valign="top"><td>
					<select 
					name="open-csa-wp-product_availability_input" 
					id="open-csa-wp-newProductForm_availability_input_id"
					<?php 
    if ($product_id == null) {
        echo "style='color:#999'";
    } else {
        if ($product_info[0]->is_available == 1) {
            echo "style='color:green'";
        } else {
            echo "style='color:brown'";
        }
    }
    ?>
					onfocus = '
							getElementById("open-csa-wp-newProductForm_availability_input_span_id").style.display = "none";
						'
					onchange='
						if (this.options[this.selectedIndex].value == "yes") {
							this.style.color = "green";
							this.options[this.selectedIndex].text = "<?php 
    _e('Currently, it is available', OPEN_CSA_WP_DOMAIN);
    ?>
"
						} else {
							this.style.color = "brown";
							this.options[this.selectedIndex].text = "<?php 
    _e('Currently, it is not available', OPEN_CSA_WP_DOMAIN);
    ?>
"
						}
						'
				>
					<option 
						value="" 
						<?php 
    if ($product_id == null) {
        echo "selected='selected'";
    }
    ?>
						disabled='disabled'
						id = "open-csa-wp-newProductForm_availability_input_disabled_id"
					>Available? *</option>
					<?php 
    if ($product_id != null) {
        echo '
								<option value="yes" style="color:green". ' . ($product_info[0]->is_available == 1 ? "selected='selected'> " . __('Currently, it is available', OPEN_CSA_WP_DOMAIN) : ">" . __('yes', OPEN_CSA_WP_DOMAIN)) . ' </option>
								<option value="no" style="color:brown"' . ($product_info[0]->is_available == 0 ? "selected='selected'> " . __('Currently, it is not available', OPEN_CSA_WP_DOMAIN) : ">" . __('no', OPEN_CSA_WP_DOMAIN)) . ' </option>
							';
    } else {
        ?>
							<option value="yes" style="color:green"><?php 
        _e('yes', OPEN_CSA_WP_DOMAIN);
        ?>
</option>
							<option value="no" style="color:brown"><?php 
        _e('no', OPEN_CSA_WP_DOMAIN);
        ?>
</option>
						<?php 
    }
    ?>
					
					</select>
					<span id="open-csa-wp-newProductForm_availability_input_span_id"></span>
				</td></tr>
			</table> 
		<input 
			type="submit" 
			name="Add Product"  
			class="button button-primary"
			id="open-csa-wp-showNewProduct_button_id"
			<?php 
    if ($product_id == null) {
        echo "value='" . __('Add Product', OPEN_CSA_WP_DOMAIN) . "'";
        echo "onclick='open_csa_wp_new_product_fields_validation(this, null, \"{$page_url}\")'";
    } else {
        echo "value='" . __('Update Product', OPEN_CSA_WP_DOMAIN) . "'";
        echo "onclick='open_csa_wp_new_product_fields_validation(this, {$product_id}, \"{$page_url}\")'";
    }
    ?>
		/>
		<input 
			type="button"
			class="button button-secondary"
			<?php 
    if ($product_id == null) {
        echo "\n\t\t\t\tvalue='" . __('Reset Info', OPEN_CSA_WP_DOMAIN) . "'\n\t\t\t\tonclick='open_csa_wp_reset_product_form();'";
    } else {
        echo "\n\t\t\t\tvalue='" . __('Cancel', OPEN_CSA_WP_DOMAIN) . "'\n\t\t\t\tonclick='window.location.replace(\"{$page_url}\")'\n\t\t\t\t'";
    }
    ?>
		/>
		
		</form>
		<br/><br/>
	</div>
	
<?php 
}
Ejemplo n.º 2
0
function open_csa_wp_new_delivery_form($spot_id, $order_deadline_date, $custom_values, $delivery_id, $display)
{
    wp_enqueue_script('open-csa-wp-general-scripts');
    wp_enqueue_script('open-csa-wp-deliveries-scripts');
    wp_enqueue_script('jquery.cluetip');
    wp_enqueue_style('jquery.cluetip.style');
    global $days_of_week, $wpdb;
    $in_charge = null;
    $custom_bool = false;
    if ($spot_id != null) {
        $spot_info = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . OPEN_CSA_WP_TABLE_SPOTS . " WHERE id=%d", $spot_id))[0];
        if ($delivery_id != null) {
            $delivery_info = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . OPEN_CSA_WP_TABLE_DELIVERIES . " WHERE id=%d", $delivery_id))[0];
            $in_charge = $delivery_info->user_in_charge;
            $order_deadline_day = (date("w", strtotime($order_deadline_date)) - 1) % 7;
            if ($order_deadline_day == -1) {
                $order_deadline_day = 6;
                // So that the 'if' below (for custom_bool) is executed correctly
            }
            $order_deadline_time = open_csa_wp_remove_seconds($delivery_info->order_deadline_time);
            $delivery_day = (date("w", strtotime($delivery_info->delivery_date)) - 1) % 7;
            if ($delivery_day == -1) {
                $delivery_day = 6;
                // So that the 'if' below (for custom_bool) is executed correctly
            }
            $delivery_start_time = open_csa_wp_remove_seconds($delivery_info->delivery_start_time);
            $delivery_end_time = open_csa_wp_remove_seconds($delivery_info->delivery_end_time);
            if ($order_deadline_day != $spot_info->default_order_deadline_day || $order_deadline_time != open_csa_wp_remove_seconds($spot_info->default_order_deadline_time) || $delivery_day != $spot_info->default_delivery_day || $delivery_start_time != open_csa_wp_remove_seconds($spot_info->default_delivery_start_time) || $delivery_end_time != open_csa_wp_remove_seconds($spot_info->default_delivery_end_time)) {
                $custom_bool = true;
            }
        } else {
            $order_deadline_day = $spot_info->default_order_deadline_day;
            $order_deadline_time = open_csa_wp_remove_seconds($spot_info->default_order_deadline_time);
            $delivery_day = $spot_info->default_delivery_day;
            $delivery_start_time = open_csa_wp_remove_seconds($spot_info->default_delivery_start_time);
            $delivery_end_time = open_csa_wp_remove_seconds($spot_info->default_delivery_end_time);
        }
        if (count($custom_values) > 0) {
            $custom_bool = true;
            if (isset($custom_values["order_deadline_day"])) {
                $order_deadline_day = $custom_values["order_deadline_day"];
            }
            if (isset($custom_values["order_deadline_time"])) {
                $order_deadline_time = $custom_values["order_deadline_time"];
            }
            if (isset($custom_values["delivery_day"])) {
                $delivery_day = $custom_values["delivery_day"];
            }
            if (isset($custom_values["delivery_start_time"])) {
                $delivery_start_time = $custom_values["delivery_start_time"];
            }
            if (isset($custom_values["delivery_end_time"])) {
                $delivery_end_time = $custom_values["delivery_end_time"];
            }
        } else {
            if ($delivery_id != null && $order_deadline_date == null) {
                $order_deadline_date = $delivery_info->order_deadline_date;
            }
        }
    }
    if ($order_deadline_date != null) {
        $order_deadline_date = explode(";", $order_deadline_date)[0];
        if ($spot_id != null && $delivery_id == null) {
            $delivery_date = date(OPEN_CSA_WP_DATE_FORMAT, strtotime("Next " . $days_of_week[$delivery_day], strtotime($order_deadline_date)));
            $deliveries_info = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\tSELECT * FROM " . OPEN_CSA_WP_TABLE_DELIVERIES . " \n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\torder_deadline_date = %s AND\n\t\t\t\t\t\t\t\t\t\t\tdelivery_date=%s\n\t\t\t\t\t\t\t\t\t", $order_deadline_date, $delivery_date));
            if ($deliveries_info != null) {
                $delivery_info = $deliveries_info[0];
                $delivery_id = $delivery_info->id;
                $in_charge = $delivery_info->user_in_charge;
            }
        }
    }
    ?>

	<br/>

	<div id="open-csa-wp-newDelivery_formHeader">
		<span 
			id="open-csa-wp-newDelivery_formHeader_text" 
			<?php 
    if ($spot_id == null) {
        echo 'style="cursor:pointer"';
        echo 'onclick="open_csa_wp_toggle_form(\'newDelivery\',\'' . __('Initiate New Delivery', OPEN_CSA_WP_DOMAIN) . '\', \'' . __(' 	form', OPEN_CSA_WP_DOMAIN) . '\')"';
    }
    ?>
		><font size='4'>
		<?php 
    if ($spot_id == null) {
        if ($display == false) {
            echo __('Initiate New Delivery', OPEN_CSA_WP_DOMAIN) . ' (' . __('show form', OPEN_CSA_WP_DOMAIN) . ')';
        } else {
            echo __('Initiate New Delivery', OPEN_CSA_WP_DOMAIN) . ' (' . __('hide form', OPEN_CSA_WP_DOMAIN) . ')';
        }
    } else {
        if ($delivery_id != null) {
            echo __('Edit Delivery', OPEN_CSA_WP_DOMAIN) . ' #' . $delivery_id;
        } else {
            echo __('Initiating new delivery for ', OPEN_CSA_WP_DOMAIN);
        }
    }
    ?>
		</font>
		</span>
	</div>
	<div id="open-csa-wp-newDelivery_div" 
		<?php 
    if ($display == false) {
        echo 'style="display:none"';
    }
    ?>
	
	>
		<form method="POST" id='open-csa-wp-initiateNewDelivery_form_id'>
			<table class="form-table">
				<tr valign="top">
					<td>
					<select 
						name="open-csa-wp-newDelivery_spotDetails_spotID_input" 
						id="open-csa-wp-newDelivery_spotDetails_spotID_input_id"
						<?php 
    if ($spot_id == null) {
        echo "style='color:#999'";
    }
    echo "onchange='window.location.replace(\"" . admin_url('/admin.php?page=csa_deliveries_management') . "&id=\" + this.value)'";
    ?>
					>
					<option 
						value="" 
						<?php 
    if ($spot_id == null) {
        echo "selected='selected' ";
    }
    ?>
						disabled='disabled'
						id = "open-csa-wp-newDelivery_spotDetails_spotID_input_disabled_id"
					><?php 
    _e('Select Spot', OPEN_CSA_WP_DOMAIN);
    ?>
 *</option>
 					<?php 
    echo open_csa_wp_select_delivery_spots($spot_id != null ? $spot_id : null, "Spot ");
    ?>
                  	</select>
					<span id="open-csa-wp-newDelivery_spotDetails_spotID_input_span_id">
					<?php 
    if ($spot_id != null) {
        if ($order_deadline_date != null) {
            echo "&nbsp;&nbsp;where";
        } else {
            if ($custom_bool === false) {
                echo "\n\t\t\t\t\t\t\t\t\t<i style='color:gray' class='open-csa-wp-tip_deliveries' title='\n\t\t\t\t\t\t\t\t\t\t" . __('Below, you can customize the deadline and delivery dates (and times) for this delivery.', OPEN_CSA_WP_DOMAIN) . "\n\t\t\t\t\t\t\t\t\t'> \n\t\t\t\t\t\t\t\t\t\t&nbsp; &nbsp; " . __('with default values... (point here)', OPEN_CSA_WP_DOMAIN) . " \n\t\t\t\t\t\t\t\t\t</i>";
            } else {
                echo "<i style='color:gray'> &nbsp; &nbsp; " . __('with custom values...', OPEN_CSA_WP_DOMAIN) . " </i>";
            }
        }
    }
    ?>
					</span>
				</tr>
				<tr
					<?php 
    if ($spot_id == null) {
        echo 'style="display:none"';
    }
    ?>
				>
					<td>
					<select 
						<?php 
    if ($order_deadline_date == null) {
        echo 'style="color:#999"';
    }
    ?>
						id="open-csa-wp-newDelivery_delivery_deadline_date_input_id"
						name="open-csa-wp-newDelivery_delivery_deadline_date_input"
						onchange = '														
							document.getElementById("open-csa-wp-newDelivery_orderDeadlineDate_choice_id").value = this.options[this.selectedIndex].value;
							open_csa_wp_new_delivery_format_custom_values(
								document.getElementById("open-csa-wp-newDeliveryCustomValues_button_id")
							)
						'

					>
					<option disabled="disabled" 
						value=""
						id = "open-csa-wp-newDelivery_delivery_deadline_date_disabled_id";
					<?php 
    if ($order_deadline_date == null) {
        echo 'selected="selected"';
    }
    ?>
					> <?php 
    _e('Choose a deadline date', OPEN_CSA_WP_DOMAIN);
    ?>
 * </option>
					<?php 
    $deadline_day = $days_of_week[$order_deadline_day];
    for ($i = 0; $i < 5; $i++) {
        $next_deadline_date = date(OPEN_CSA_WP_DATE_FORMAT, strtotime("Next " . $deadline_day . "+{$i} week"));
        $next_deadline_date_readable = $deadline_day . ", " . date(OPEN_CSA_WP_DATE_FORMAT_READABLE, strtotime($next_deadline_date)) . ", " . __('up to', OPEN_CSA_WP_DOMAIN) . " " . $order_deadline_time;
        if ($order_deadline_date == null || $order_deadline_date != $next_deadline_date) {
            echo "<option \n\t\t\t\t\t\t\t\t\t\tstyle='color:black' \n\t\t\t\t\t\t\t\t\t\tvalue='{$next_deadline_date};{$order_deadline_time}'\n\t\t\t\t\t\t\t\t\t>{$next_deadline_date_readable}</option>";
        } else {
            if ($order_deadline_date == $next_deadline_date) {
                echo "<option \n\t\t\t\t\t\t\t\t\t\tstyle='color:black' \n\t\t\t\t\t\t\t\t\t\tselected = 'selected' \n\t\t\t\t\t\t\t\t\t\tvalue='{$next_deadline_date};{$order_deadline_time}'\n\t\t\t\t\t\t\t\t\t>" . __('Order deadline is on', OPEN_CSA_WP_DOMAIN) . " {$next_deadline_date_readable}</option>";
            }
        }
    }
    ?>
					</select>
					<span id="open-csa-wp-newDelivery_delivery_deadline_date_input_span_id" 
						<?php 
    if ($order_deadline_date == null) {
        echo 'style="display:none"';
    }
    ?>
					> &nbsp;&nbsp; <?php 
    _e('and', OPEN_CSA_WP_DOMAIN);
    ?>
					</span></td>
				</tr>
				<tr valign="top" 
				<?php 
    if ($order_deadline_date == null) {
        echo 'style="display:none"';
    }
    ?>
><td><span> 
				<?php 
    $delivery_date = date(OPEN_CSA_WP_DATE_FORMAT_READABLE, strtotime("Next " . $days_of_week[$delivery_day], strtotime($order_deadline_date)));
    $value_of_read_only_input = "Delivery is on " . $days_of_week[$delivery_day] . ", " . $delivery_date . ", from {$delivery_start_time} to {$delivery_end_time}";
    $value_of_read_only_input_len = strlen($value_of_read_only_input);
    $size_of_read_only_input = $value_of_read_only_input_len + 1 . '"px\\"';
    echo " \t<input \n\t\t\t\t\t\t\t\tname = 'open-csa-wp-newDelivery_DeliveryDaTeDetails_input'\n\t\t\t\t\t\t\t\ttype = 'text'\n\t\t\t\t\t\t\t\treadonly = 'readonly'\n\t\t\t\t\t\t\t\tvalue='{$value_of_read_only_input}'\n\t\t\t\t\t\t\t\tstyle='border:none; background-color:white;'\n\t\t\t\t\t\t\t\tsize='{$size_of_read_only_input}'\n\t\t\t\t\t\t\t/>";
    ?>
				</span></td></tr>
				
				<tr valign="top" 
				<?php 
    if ($order_deadline_date == null) {
        echo 'style="display:none"';
    }
    ?>
><td>
					<select 
						name="open-csa-wp-newDelivery_inCharge_input"
						id="open-csa-wp-newDelivery_inCharge_input_id"		
						onchange = '
							this.style.color="black"
							if (this.options[this.selectedIndex].text.split(" ")[0] != "<?php 
    _e('Responsible for this delivery is', OPEN_CSA_WP_DOMAIN);
    ?>
".split(" ")[0]) {
								this.options[this.selectedIndex].text = <?php 
    _e('Responsible for this delivery is', OPEN_CSA_WP_DOMAIN);
    ?>
 + " " + this.options[this.selectedIndex].text;
							}
						'
						<?php 
    if ($delivery_id == null) {
        echo "style='color:#999'";
    }
    ?>
					>
						<option 
							value="" 
							<?php 
    if ($delivery_id == null) {
        echo "selected='selected'";
    }
    ?>
							id = "open-csa-wp-newDelivery_inCharge_input_disabled_id"
							disabled='disabled'
						><?php 
    _e('Do you know who is going to be in charge?', OPEN_CSA_WP_DOMAIN);
    ?>
 </option>
						<?php 
    echo open_csa_wp_select_users_of_type("consumer", $in_charge, __('Responsible for this delivery is', OPEN_CSA_WP_DOMAIN) . " ");
    ?>
					</select>
				</td></tr>
				
				<tr valign="top"
					<?php 
    if ($delivery_id == null) {
        echo "style='display:none'";
    }
    ?>
				><td>
					<select 
						name="open-csa-wp-delivery_abilityToSubmitOrder_input" 
						id="open-csa-wp-delivery_abilityToSubmitOrder_input_id"
						<?php 
    if ($delivery_id != null && $delivery_info->are_orders_open == 1) {
        echo "style='color:green'";
    } else {
        echo "style='color:brown'";
    }
    ?>
						onchange='
							if (this.options[this.selectedIndex].value == "yes") {
								this.style.color = "green";
								this.options[this.selectedIndex].text = "<?php 
    _e('Currently, new orders can be submitted', OPEN_CSA_WP_DOMAIN);
    ?>
"
							}
							else {
								this.style.color = "brown";
								this.options[this.selectedIndex].text = "<?php 
    _e('Currently, new orders can not be submitted', OPEN_CSA_WP_DOMAIN);
    ?>
"
							}
							'
					>
					<?php 
    if ($delivery_id != null) {
        echo '
								<option value="yes" style="color:green". ' . ($delivery_info->are_orders_open == 1 ? "selected='selected'" : "") . '> ' . __('Currently, new orders can be submitted', OPEN_CSA_WP_DOMAIN) . ' </option>
								<option value="no" style="color:brown"' . ($delivery_info->are_orders_open == 0 ? "selected='selected'" : "") . '> ' . __('Currently, new orders can not be submitted', OPEN_CSA_WP_DOMAIN) . ' </option>
							';
    }
    ?>
					
					</select>
					</td>
				</tr>

				
				
				<tr <?php 
    if ($spot_id == null) {
        echo 'style="display:none"';
    }
    ?>
>
					<td>
					<input 
						type="submit" 
						class="button button-primary"
						id="open-csa-wp-initiateNewDelivery_button_id"
						
						<?php 
    if ($delivery_id == null) {
        echo "\n\t\t\t\t\t\t\t\t\tvalue='" . __('Initiate Delivery', OPEN_CSA_WP_DOMAIN) . "'\n\t\t\t\t\t\t\t\t\tonclick='open_csa_wp_request_initiate_new_or_update_delivery(this, null, \"" . admin_url("/admin.php?page=csa_deliveries_management") . "\");'\n\t\t\t\t\t\t\t\t";
    } else {
        echo "\n\t\t\t\t\t\t\t\t\tvalue='" . __('Update Delivery', OPEN_CSA_WP_DOMAIN) . "'\n\t\t\t\t\t\t\t\t\tonclick='open_csa_wp_request_initiate_new_or_update_delivery(this, {$delivery_id}, \"" . admin_url("/admin.php?page=csa_deliveries_management") . "\");'\n\t\t\t\t\t\t\t\t";
    }
    ?>
					/>
					
					<input 
						type="button"
						class="button button-secondary"
						value="<?php 
    _e('Cancel', OPEN_CSA_WP_DOMAIN);
    ?>
"
						<?php 
    echo "onclick='window.location.replace(\"" . admin_url('/admin.php?page=csa_deliveries_management') . "\")'";
    ?>
					/>
					</td>
				</tr>
			</table>
		</form>
		
		
		<form 
			id="open-csa-wp-initiateNewDelivery_spotDetails_form"
			method="post"
			<?php 
    if ($spot_id == null) {
        echo 'style="display:none"';
    }
    ?>
			action="<?php 
    echo admin_url('/admin.php?page=csa_deliveries_management');
    ?>
"
		>
			<br/>
			<div id="open-csa-wp-newDelivery_spotDetailsDetails_formHeader">
				<span 
					id="open-csa-wp-newDelivery_spotDetailsDetails_formHeader_text" 
					style="cursor:pointer"
					<?php 
    if ($custom_bool === true) {
        echo "onclick=\"open_csa_wp_toggle_form('newDelivery_spotDetailsDetails','" . __('Custom values', OPEN_CSA_WP_DOMAIN) . " ', ' " . __('form', OPEN_CSA_WP_DOMAIN) . "', 3, '&nbsp;&nbsp;&nbsp;')\"";
    } else {
        echo "onclick=\"open_csa_wp_toggle_form('newDelivery_spotDetailsDetails','" . __('Customize default values', OPEN_CSA_WP_DOMAIN) . " ', ' " . __('form', OPEN_CSA_WP_DOMAIN) . "', 3, '&nbsp;&nbsp;&nbsp;')\"";
    }
    ?>
				><font size='3'>
				<?php 
    $text_hide_show = "hide";
    if ($order_deadline_date != null || $delivery_id != null) {
        $text_hide_show = "show";
    }
    if ($custom_bool === true) {
        echo "&nbsp;&nbsp;&nbsp;" . __('Custom values', OPEN_CSA_WP_DOMAIN) . " ({$text_hide_show} " . __('form', OPEN_CSA_WP_DOMAIN) . ")";
    } else {
        echo "&nbsp;&nbsp;&nbsp;" . __('Customize default values', OPEN_CSA_WP_DOMAIN) . " ({$text_hide_show} " . __('form', OPEN_CSA_WP_DOMAIN) . ")";
    }
    ?>
					
				</font>
				</span>
			</div>
			<div id = "open-csa-wp-newDelivery_spotDetailsDetails_div"
				<?php 
    if ($order_deadline_date != null || $delivery_id != null) {
        echo "style='display:none'";
    }
    ?>
			>
				<table class="form-table">		
				<tr hidden="hidden">
					<td>
					<input 	name='open-csa-wp-newDelivery_spotID_choice' 
							id='open-csa-wp-newDelivery_spotID_choice_id'
							value="<?php 
    if ($spot_id != null) {
        echo $spot_id;
    }
    ?>
">
					</td>
				<tr/>
				<tr hidden="hidden">
					<td>
					<input 	name='open-csa-wp-newDelivery_deliveryID_choice' 
							value="<?php 
    if ($delivery_id != null) {
        echo $delivery_id;
    }
    ?>
">
					</td>
				<tr/>
				<tr hidden="hidden">
					<td>
					<input 	name='open-csa-wp-newDelivery_orderDeadlineDate_choice' 
							id='open-csa-wp-newDelivery_orderDeadlineDate_choice_id'
							value="">
					</td>
				<tr/>
				
				<?php 
    if ($delivery_id != null) {
        echo "\n\t\t\t\t\t\t\t<tr hidden = 'hidden'> \n\t\t\t\t\t\t\t\t<td> <input name='open-csa-wp-newDelivery_deliveryID' value=\"{$delivery_id}\"/> </td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t";
    }
    ?>
				<tr valign="top"><td>
					<select 
						name="open-csa-wp-newDelivery_order_deadline_day_input"
						id='open-csa-wp-newDelivery_order_deadline_day_input_id'
						onfocus=' getElementById("open-csa-wp-newDelivery_spotDetails_orderDeadline_span").style.display = "none";'
						onchange='
							if (this.options[this.selectedIndex].text.split(" ")[0] != "order") {
								this.options[this.selectedIndex].text = "order deadline is on " + this.options[this.selectedIndex].text;
							}
							getElementById("open-csa-wp-newDelivery_order_deadline_time_input_id").style.display = "inline"
							'
					>
					<option value="" selected='selected' disabled="disabled" id="open-csa-wp-newDelivery_order_deadline_day_disabled_id">order deadline day ... *</option>
					<?php 
    for ($i = 0; $i < 7; $i++) {
        if ($order_deadline_day == $i) {
            echo "<option value='{$i}' selected='selected'> " . __('order deadline is on', OPEN_CSA_WP_DOMAIN) . " {$days_of_week[$i]} </option>";
        } else {
            echo "<option value='{$i}'>" . $days_of_week[$i] . "</option>";
        }
    }
    ?>
					</select> 
					<input 
						<?php 
    if ($spot_id != null) {
        echo "value='" . __('up to', OPEN_CSA_WP_DOMAIN) . " {$order_deadline_time}'";
    }
    ?>
						placeholder="up to... *"
						id="open-csa-wp-newDelivery_order_deadline_time_input_id"
						class="textbox-n" type="text" size="10" name="open-csa-wp-newDelivery_order_deadline_time_input"
						onfocus='
							getElementById("open-csa-wp-newDeliveryCustomValues_button_id").disabled = true;
							<?php 
    if ($custom_bool === true && $delivery_id == null) {
        echo 'getElementById("open-csa-wp-newDeliveryCustomValues_reset_button_id").disabled = true;';
    }
    ?>
							if (this.value != "") this.value=this.value.split(" ")[2];
							else getElementById("open-csa-wp-newDelivery_spotDetails_orderDeadline_span").style.display = "none";
							this.type="time";'
						onblur='
							getElementById("open-csa-wp-newDeliveryCustomValues_button_id").disabled = false;
							<?php 
    if ($custom_bool === true && $delivery_id == null) {
        echo 'getElementById("open-csa-wp-newDeliveryCustomValues_reset_button_id").disabled = false;';
    }
    ?>
							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-newDelivery_spotDetails_orderDeadline_span" style="display:none"></span>
				</td></tr>
								
				<tr valign="top"><td>
					<select 
						name="open-csa-wp-newDelivery_delivery_day_input" 
						id="open-csa-wp-newDelivery_delivery_day_input_id"
						onfocus='getElementById("open-csa-wp-newDelivery_spotDetails_invalidDeliveryTime_span").innerHTML = "";'
						onchange='
							if (this.options[this.selectedIndex].text.split(" ")[0] != "Delivery") {
								this.options[this.selectedIndex].text = "Delivery day is " + this.options[this.selectedIndex].text;
							}
							getElementById("open-csa-wp-newDelivery_spotDetails_delivery_start_time_input_id").style.display = "inline"'
					>
					<option value="" disabled="disabled" 
						id="open-csa-wp-newDelivery_delivery_day_disabled_id"><?php 
    _e('Delivery Day', OPEN_CSA_WP_DOMAIN);
    ?>
 ... *</option>
					<?php 
    for ($i = 0; $i < 7; $i++) {
        if ($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-newDelivery_spotDetails_delivery_start_time_input_id"
						<?php 
    if ($spot_id != null) {
        echo "value='from {$delivery_start_time}'";
    }
    ?>
						placeholder="<?php 
    _e('from', OPEN_CSA_WP_DOMAIN);
    ?>
... *"
						class="textbox-n" type="text" size="10" 
						name="open-csa-wp-newDelivery_delivery_start_time_input"

						onfocus='
							getElementById("open-csa-wp-newDeliveryCustomValues_button_id").disabled = true;
							<?php 
    if ($custom_bool === true && $delivery_id == null) {
        echo 'getElementById("open-csa-wp-newDeliveryCustomValues_reset_button_id").disabled = true;';
    }
    ?>
							if (this.value != "") {
								this.value=this.value.split(" ")[1];
							} else {
								getElementById("open-csa-wp-newDelivery_spotDetails_invalidDeliveryTime_span").style.display = "none";
							}
							this.type="time";'
						onblur='
							getElementById("open-csa-wp-newDeliveryCustomValues_button_id").disabled = false;
							<?php 
    if ($custom_bool === true && $delivery_id == null) {
        echo 'getElementById("open-csa-wp-newDeliveryCustomValues_reset_button_id").disabled = false;';
    }
    ?>
							this.type="text";
							if (this.value == "") {
								getElementById("open-csa-wp-newDelivery_spotDetails_delivery_end_time_input_id").style.display = "none";
								getElementById("open-csa-wp-newDelivery_spotDetails_delivery_end_time_input_id").value = "";
							}
							else {
								this.style.color="black";
								this.value = "from " + this.value;
								getElementById("open-csa-wp-newDelivery_spotDetails_delivery_end_time_input_id").style.display = "inline";
								open_csa_wp_validate_delivery_time_period("newDelivery_spotDetails");
							}'
						>
					<input id="open-csa-wp-newDelivery_spotDetails_delivery_end_time_input_id"
						<?php 
    if ($spot_id != null) {
        echo "value='" . __('to', OPEN_CSA_WP_DOMAIN) . " {$delivery_end_time}'";
    }
    ?>
						placeholder="<?php 
    _e('to', OPEN_CSA_WP_DOMAIN);
    ?>
... *"					
						class="textbox-n" type="text" size="10" 
						name="open-csa-wp-newDelivery_delivery_end_time_input"
						
						onfocus='
							getElementById("open-csa-wp-newDeliveryCustomValues_button_id").disabled = true;
							<?php 
    if ($custom_bool === true && $delivery_id == null) {
        echo 'getElementById("open-csa-wp-newDeliveryCustomValues_reset_button_id").disabled = true;';
    }
    ?>
							if (this.value != "") {
								this.value=this.value.split(" ")[1]
							}
							getElementById("open-csa-wp-newDelivery_spotDetails_invalidDeliveryTime_span").style.display = "none";
							this.type="time";'
						onblur='
							getElementById("open-csa-wp-newDeliveryCustomValues_button_id").disabled = false;
							<?php 
    if ($custom_bool === true && $delivery_id == null) {
        echo 'getElementById("open-csa-wp-newDeliveryCustomValues_reset_button_id").disabled = false;';
    }
    ?>
							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("newDelivery_spotDetails");
							}
						'
						>
					<span id="open-csa-wp-newDelivery_spotDetails_invalidDeliveryTime_span"> </span>
					</td> 
				</tr>					
				<tr valign="top"><td>
					<input 
						type="submit" 
						class="button button-secondary"
						id="open-csa-wp-newDeliveryCustomValues_button_id"
						value="<?php 
    _e('Use Custom Values', OPEN_CSA_WP_DOMAIN);
    ?>
"
						onclick="open_csa_wp_new_delivery_format_custom_values(this);"
					/>
					<?php 
    if ($custom_bool === true && $delivery_id == null) {
        echo "\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\ttype='submit'\n\t\t\t\t\t\t\t\t\tclass='button button-secondary'\n\t\t\t\t\t\t\t\t\tid='open-csa-wp-newDeliveryCustomValues_reset_button_id'\n\t\t\t\t\t\t\t\t\tvalue='" . __('Reset to default values', OPEN_CSA_WP_DOMAIN) . "'\n\t\t\t\t\t\t\t\t\tonclick='\n\t\t\t\t\t\t\t\t\t\twindow.location.replace(\"" . admin_url('/admin.php?page=csa_deliveries_management') . "&id=" . $spot_id . "\");\n\t\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t\t'\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t";
    }
    ?>
				</td>
				
				</tr>
				</table>
			</div>
		</form>
	</div>
	
<?php 
}