Как изменить первый день недели с воскресенья на понедельник
У меня есть сайт, где у меня есть календарь с часами работы в нижней части страницы, он выглядит так: фото
Проблема в том, что я хочу, чтобы "Мандаг" (понедельник) был первым днем недели, а не "Сендаг" (воскресенье), как сейчас. Я пытался выяснить в коде, где это делается, но не могу понять.
Если я нажму "<< Forrige Uge" (<< Last Week), то неделя будет показана с понедельником в качестве первого дня недели! Его только на самом деле неделю и все недели вперед он показывает воскресенье как первые дни недели.
Есть 2 PHP-файла, как я вижу, где эта информация может быть. Первый называется Panel.php:
<pre>$db = JFactory::getDBO(); $query = 'SELECT * FROM #__dpcalendar_events where state = 1'; $db->setQuery($query); $results = $db->loadObjectList(); date_default_timezone_set("Europe/Copenhagen"); $today = date('Y-m-d H:i:s'); $ts = strtotime($today); $year = date('o', $ts); $week = date('W', $ts); $days = array(); for($i = 1; $i <= 8; $i++) { $ts = strtotime($year.'W'.$week.$i); $days[] = date("l d/m", $ts); } (int)$currentpage = (!empty($_POST["currentpage"]))?$_POST["currentpage"]:0; (int)$nextpage = $currentpage + 1; (int)$prevpage = $currentpage - 1; //<!-------------Count Week here-----------------> $ts1 = date(strtotime('first monday')); $ts1 += $currentpage * 86400 * 7; $dow1 = date('w' , $ts1); $offset1 = $dow1; $ts1 = $ts1 - $offset1 * 86400; $week_number = date('W', $ts1); // $query2 = 'SELECT id FROM #__dpcalendar_events WHERE yearweek(DATE(`start_date`)) = yearweek(curdate()) ORDER BY `id` ASC LIMIT 0,1'; $aliass= "uge-".$week_number; $query2 = 'SELECT id FROM #__dpcalendar_events WHERE `alias` LIKE "'.$aliass.'" and `state` = 1 ORDER BY `alias` ASC'; $db->setQuery($query2); $results2 = $db->loadObjectList(); foreach($results2 as $result){ $event_id = $result->id; } $ts = date(strtotime('last sunday')); $ts += $currentpage * 86400 * 7; //$dow = date('N' , $ts); //$dow1 = date('w' , $ts1); ORGINAL $dow1 = date('w' , $ts1); $offset = $dow; $ts = $ts - $offset * 86400; for ($x=0 ; $x<8 ; $x++,$ts += 86400) { $d1 = date("d/m", $ts); $s_date = array(); $time = array(); $s = ''; $e = ''; $event_vari = ''; foreach($results as $result){ $Todays = date('Y-m-d H:i:s'); $id = $result->id; $s_date[] = date("d/m",strtotime($result->start_date)); $end_date = date("d/m",strtotime($result->end_date)); $start_time = date("G",strtotime($result->start_date)); $end_time = date("G",strtotime($result->end_date)); $close_date =$result->booking_closing_date; $s .= $start_time.' til '.$end_time.'_'.date("d/m",strtotime($result->start_date)).','; } //print_r($s); //print_r($d1); $startdatetime = explode(',', $s) ; if(in_array($d1, $s_date)){ foreach($startdatetime as $st){ $aa = explode('_', $st) ; //print_r(@$aa[1]); if($d1 == $aa[1]){ $day = date("l", $ts); //echo $day; $date = date("d/m", $ts); if($day == "Monday"){ $day = "Mandag"; }elseif($day == "Tuesday"){ $day = "Tirsdag"; }elseif($day == "Wednesday"){ $day = "Onsdag"; } elseif($day == "Thursday"){ $day = "Torsdag"; }elseif($day == "Friday"){ $day = "Fredag"; }elseif($day == "Saturday"){ $day = "Lørdag"; } elseif($day == "Sunday"){ $day = "Søndag";} echo '<tr>'; echo '<td class="eventscla pb-1"><span class="weekday vvv">' .$day. ' - ' . $date.'</span></td>' ; echo '<td class="eventscla pb-1" style="text-align:left;"><span class="label eventdate">'; //echo $timestart[$d1] .'-'. $timeend[$d1]; $daydesc = array(); $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 3 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[1] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 4 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[2] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 5 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[3] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 6 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[4] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 7 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[5] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 8 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[6] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 9 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[7] = $closetitle->value; } if($day == "Mandag"){ if($daydesc[1] !=''){ echo $daydesc[1];}else{echo 'Lukket';} }elseif($day == "Tirsdag"){ if($daydesc[2] !=''){echo $daydesc[2];}else{ echo 'Lukket';} // }elseif($day =='Onsdag'){ }elseif($day =="Onsdag"){ if($daydesc[3] !=''){echo $daydesc[3];}else{ echo 'Lukket';} }elseif($day=="Torsdag"){ if($daydesc[4] !=''){echo $daydesc[4];}else{ echo 'Lukket';} }elseif($day == "Fredag"){ if($daydesc[5] !=''){echo $daydesc[5];}else{ echo 'Lukket';} }elseif($day == "Lørdag"){ if($daydesc[6] !=''){echo $daydesc[6];}else{ echo 'Lukket';} }elseif($day == "Søndag"){ if($daydesc[7] !=''){ echo $daydesc[7];}else{echo 'Lukket';} } //echo $aa[0]; echo '</span></td>'; echo '</tr>'; } } }else{ $daydesc = array(); $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 3 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[0] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 4 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[1] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 5 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[2] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 6 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[3] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 7 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[4] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 8 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[5] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 9 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[6] = $closetitle->value; } $day = date("l", $ts); //print_r($day); $date = date("d/m", $ts); //print_r($day); if($day == "Monday"){ $day = "Mandag"; }elseif($day == "Tuesday"){ $day = "Tirsdag"; }elseif($day == "Wednesday"){ $day = "Onsdag"; } elseif($day == "Thursday"){ $day = "Torsdag"; }elseif($day == "Friday"){ $day = "Fredag"; }elseif($day == "Saturday"){ $day = "Lørdag"; } elseif($day == "Sunday"){ $day = "Søndag";} echo '<tr>'; echo '<td class="eventscla pb-1"><span class="weekday ttt">' .$day. ' - ' . $date. '</span></td>' ; /*echo '<td class="eventscla pb-1" style="text-align:right;"><span class="label eventdate">'. $close .'</span></td>'; echo '</tr>';*/ echo '<td class="eventscla pb-1" style="text-align:left;"><span class="label eventdate">'; if($day == "Mandag"){ if(@$daydesc[0] !=''){ echo $daydesc[0];}else{echo 'Lukket';} }elseif($day == "Tirsdag"){ if(@$daydesc[1] !=''){echo $daydesc[1];}else{ echo 'Lukket';} }elseif($day =='Onsdag'){ if(@$daydesc[2] !=''){echo $daydesc[2];}else{ echo 'Lukket';} }elseif($day=="Torsdag"){ if(@$daydesc[3] !=''){echo $daydesc[3];}else{ echo 'Lukket';} }elseif($day == "Fredag"){ if(@$daydesc[4] !=''){echo $daydesc[4];}else{ echo 'Lukket';} }elseif($day == "Lørdag"){ if(@$daydesc[5] !=''){echo $daydesc[5];}else{ echo 'Lukket';} }elseif($day == "Søndag"){ if(@$daydesc[6] !=''){ echo $daydesc[6];}else{echo 'Lukket';} } echo '</span></td>'; echo '</tr>'; } }
Второй файл-это calendar.php:
<pre>// Set flag that this is a parent file // Get Joomla! framework define( '_JEXEC', 1 ); define( '_VALID_MOS', 1 ); define( 'JPATH_BASE', realpath(dirname(__FILE__))); define( 'DS', DIRECTORY_SEPARATOR ); date_default_timezone_set("Europe/Copenhagen"); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); $mainframe =& JFactory::getApplication('site'); $mainframe->initialise(); $db = JFactory::getDBO(); $query = 'SELECT * FROM #__dpcalendar_events where state = 1'; $db->setQuery($query); $results = $db->loadObjectList(); date_default_timezone_set("Europe/Copenhagen"); $today = date('Y-m-d H:i:s'); $ts = strtotime($today); $year = date('o', $ts); $week = date('W', $ts); $days = array(); for($i = 1; $i <= 8; $i++) { $ts = strtotime($year.'W'.$week.$i); $days[] = date("l d/m", $ts); } (int)$currentpage = (!empty($_POST["currentpage"]))?$_POST["currentpage"]:0; (int)$nextpage = $currentpage + 1; (int)$prevpage = $currentpage - 1; //<!-------------Count Week here-----------------> $ts1 = date(strtotime('first monday')); $ts1 += $currentpage * 86400 * 7; $dow1 = date('w' , $ts1); $offset1 = $dow1; $ts1 = $ts1 - $offset1 * 86400; $week_number = date('W', $ts1); // $query2 = 'SELECT id FROM #__dpcalendar_events WHERE yearweek(DATE(`start_date`)) = yearweek(curdate()) ORDER BY `id` ASC LIMIT 0,1'; $aliass= "uge-".$week_number; $query2 = 'SELECT id FROM #__dpcalendar_events WHERE `alias` LIKE "'.$aliass.'" and `state` = 1 ORDER BY `alias` ASC'; $db->setQuery($query2); $results2 = $db->loadObjectList(); foreach($results2 as $result){ $event_id = $result->id; } $ts = date(strtotime('last sunday')); $ts += $currentpage * 86400 * 7; //$dow = date('N' , $ts); //$dow = date('w' , $ts); $dow1 = date('w' , $ts1); $offset = $dow; $ts = $ts - $offset * 86400; for ($x=0 ; $x<8 ; $x++,$ts += 86400) { $d1 = date("d/m", $ts); $s_date = array(); $time = array(); $s = ''; $e = ''; $event_vari = ''; foreach($results as $result){ $Todays = date('Y-m-d H:i:s'); $id = $result->id; $s_date[] = date("d/m",strtotime($result->start_date)); $end_date = date("d/m",strtotime($result->end_date)); $start_time = date("G",strtotime($result->start_date)); $end_time = date("G",strtotime($result->end_date)); $close_date =$result->booking_closing_date; $s .= $start_time.' til '.$end_time.'_'.date("d/m",strtotime($result->start_date)).','; } //print_r($s); //print_r($d1); $startdatetime = explode(',', $s) ; if(in_array($d1, $s_date)){ foreach($startdatetime as $st){ $aa = explode('_', $st) ; //print_r(@$aa[1]); if($d1 == $aa[1]){ $day = date("l", $ts); $date = date("d/m", $ts); if($day == "Monday"){ $day = "Mandag"; }elseif($day == "Tuesday"){ $day = "Tirsdag"; }elseif($day == "Wednesday"){ $day = "Onsdag"; } elseif($day == "Thursday"){ $day = "Torsdag"; }elseif($day == "Friday"){ $day = "Fredag"; }elseif($day == "Saturday"){ $day = "Lørdag"; } elseif($day == "Sunday"){ $day = "Søndag";} echo '<tr>'; echo '<td class="eventscla pb-1"><span class="weekday vvv">' .$day. ' - ' . $date.'</span></td>' ; echo '<td class="eventscla pb-1" style="text-align:left;"><span class="label eventdate">'; //echo $timestart[$d1] .'-'. $timeend[$d1]; $daydesc = array(); $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 3 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[1] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 4 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[2] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 5 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[3] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 6 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[4] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 7 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[5] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 8 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[6] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 9 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[7] = $closetitle->value; } if($day == "Mandag"){ if($daydesc[1] !=''){ echo $daydesc[1];}else{echo 'Lukket';} }elseif($day == "Tirsdag"){ if($daydesc[2] !=''){echo $daydesc[2];}else{ echo 'Lukket';} }elseif($day =='Onsdag'){ if($daydesc[3] !=''){echo $daydesc[3];}else{ echo 'Lukket';} }elseif($day=="Torsdag"){ if($daydesc[4] !=''){echo $daydesc[4];}else{ echo 'Lukket';} }elseif($day == "Fredag"){ if($daydesc[5] !=''){echo $daydesc[5];}else{ echo 'Lukket';} }elseif($day == "Lørdag"){ if($daydesc[6] !=''){echo $daydesc[6];}else{ echo 'Lukket';} }elseif($day == "Søndag"){ if($daydesc[7] !=''){ echo $daydesc[7];}else{echo 'Lukket';} } //echo $aa[0]; echo '</span></td>'; echo '</tr>'; } } }else{ $daydesc = array(); $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 3 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[0] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 4 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[1] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 5 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[2] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 6 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[3] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 7 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[4] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 8 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[5] = $closetitle->value; } $query1 = "SELECT value FROM `#__fields_values` WHERE `item_id`= '" . $event_id . "' and `field_id` = 9 order by field_id asc"; // print $query1; $db->setQuery($query1); $closetext = $db->loadObjectList(); foreach($closetext as $closetitle){ $daydesc[6] = $closetitle->value; } $day = date("l", $ts); //print_r($day); $date = date("d/m", $ts); //print_r($day); if($day == "Monday"){ $day = "Mandag"; }elseif($day == "Tuesday"){ $day = "Tirsdag"; }elseif($day == "Wednesday"){ $day = "Onsdag"; } elseif($day == "Thursday"){ $day = "Torsdag"; }elseif($day == "Friday"){ $day = "Fredag"; }elseif($day == "Saturday"){ $day = "Lørdag"; } elseif($day == "Sunday"){ $day = "Søndag";} echo '<tr>'; echo '<td class="eventscla pb-1"><span class="weekday ttt">' .$day. ' - ' . $date. '</span></td>' ; /*echo '<td class="eventscla pb-1" style="text-align:right;"><span class="label eventdate">'. $close .'</span></td>'; echo '</tr>';*/ echo '<td class="eventscla pb-1" style="text-align:left;"><span class="label `enter code here`eventdate">'; if($day == "Mandag"){ if($daydesc[0] !=''){ echo $daydesc[0];}else{echo 'Lukket';} }elseif($day == "Tirsdag"){ if($daydesc[1] !=''){echo $daydesc[1];}else{ echo 'Lukket';} }elseif($day =='Onsdag'){ if($daydesc[2] !=''){echo $daydesc[2];}else{ echo 'Lukket';} }elseif($day=="Torsdag"){ if($daydesc[3] !=''){echo $daydesc[3];}else{ echo 'Lukket';} }elseif($day == "Fredag"){ if($daydesc[4] !=''){echo $daydesc[4];}else{ echo 'Lukket';} }elseif($day == "Lørdag"){ if($daydesc[5] !=''){echo $daydesc[5];}else{ echo 'Lukket';} }elseif($day == "Søndag"){ if($daydesc[6] !=''){ echo $daydesc[6];}else{echo 'Lukket';} } echo '</span></td>'; echo '</tr>'; } }
Где и что я могу изменить, чтобы это сработало?
Что я уже пробовал:
//$dow = дата('N' , $ts);
//$dow = дата('w' , $ts);
$dow1 = дата('w' , $ts1);
Gerry Schmitz
.. в противном случае, если воскресенье, пропустите его.
Richard MacCutchan
Где во всем этом коде вы создаете календарь?