Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

php problem with calendar

General discussions related to php

Moderators: macek, egami, gesf

php problem with calendar

Postby glontzjr » Fri Apr 26, 2013 12:07 am

Hi!

I have a script for calendar not working properly:

Calendar should work like this:

The customer can choose the calendar data from Monday to Saturday (the selection is made from the admin), and the timing should work as follows:

closing time is 13.00 edition

Monday after 13.00, the customer can not select the Tuesday edition

Tuesday after 13.00, the customer can not select the Wednesday edition

Wednesday after 13.00, the customer can not select the Thursday edition

Friday after 13.00, the customer can not select the Saturday and Monday editions

Sunday can select Edit from Monday

I can say after days of occurrence and time can not take listings for the day are selected from admin.

You have the following code that allows selection Friday after 13.00 Monday.

$(document).ready(function() {

// AVAILABLE DAYS
var day_index = $("#day-index").val();
var available_days = $("#available-days").val();
var days = available_days.split("$");

// CURRENT DATE
var dt = new Date();
var dt_h = dt.getHours();
var dt_d = dt.getDay();
var deadline_limit =parseInt($('#deadline-offset').val());

// AVAILABLE OFFSET OFFSET
var flag = false;
var iterations = 0;
var d = dt_d;
var initial_date = d;

while (!(flag) && (iterations<7)) {
(d<6) ? (d++) : (d=0);

if(deadline_limit!=0){
if ($.inArray("" + d, days) != -1 && iterations==deadline_limit) {
flag = true;
}
}
else{
if ($.inArray("" + d, days) != -1 ) {
flag = true;
}
}
if(iterations==deadline_limit && deadline_limit!=0){
flag= true;
}
iterations++;
}

// DEADLINE HOUR OFFSET
var deadline_hour = $("#deadline-hour").val();
var deadline_hour_offset = (deadline_hour > dt_h) ? 0 : 1;
if(initial_date == 6 || initial_date == 7 || initial_date == 0)
deadline_hour_offset = 1;


min_date_offset = deadline_hour_offset + iterations;
console.log('deadline_hour_offset='+deadline_hour_offset);
console.log('iterations='+iterations);
console.log('date='+dt_d);
console.log('min_date_offset='+min_date_offset);
console.log('dt_d+min_date_offset='+(dt_d+iterations));
if($.inArray("" + 6, days) && (dt_d+iterations)==6 && deadline_hour_offset==1)
min_date_offset = min_date_offset+2;
if($.inArray("" + 6, days) && (dt_d+iterations)==6 && deadline_hour_offset==0)
min_date_offset = min_date_offset+1;
console.log(min_date_offset);


$("#datepicker").datepicker({

dateFormat: 'dd-mm-yy',

minDate: +min_date_offset, maxDate:'+12M',

beforeShowDay: function(date) {
var day = date.getDay();
var flag = false;
if (days[0] != "") {
for(var i=0; i<days.length; i++) {
if (day == days[i]) {
flag = true;
break;
}
}
}
return [flag];
},

onSelect: function(dateStr) {
if ($('input[value="' + dateStr + '"]').length<1) {
day_index++;
var date_item = '<div class="date-item" id="date-item-' + day_index + '"><a href="#" id="action-remove-date-' + day_index + '" class="action-remove-date"><img src="public/images/ic-del-c.jpg" class="calendar-im" alt="Sterge"></a><input value="' + dateStr + '" id="calendar-date-' + day_index + '" name="ad-date[]" type="text" class="inp-calendar-date" readonly="readonly"/><span class="calendar-date-detail">' + "" + '</span></div>';
$("#date-holder").prepend(date_item);
}
}

});

$(".days-type").change(function (){
if ($("#days-type-1").is(":checked")) {
$("#datepicker").datepicker("disable");
$("#date-holder").empty();
$("#ad-days-count").show();
}
else {
$("#datepicker").datepicker("enable");
$("#ad-days-count").hide();
}
});

if ($("#days-type-1").is(":checked")) {
$("#datepicker").datepicker("disable");
$("#ad-days-count").show();
} else {
$("#datepicker").datepicker("enable");
$("#ad-days-count").hide();
}

$('.action-remove-date').live("click", function(){
var cur_date_id = $(this).attr("id").split("-")[3];
$("#date-holder").find("#date-item-" + cur_date_id).remove();
return false;
});


});
glontzjr
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Apr 25, 2013 11:59 pm

Return to PHP General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron