Question:
Is there something weird about date-time that would affect the assignment of a variable?
The situation:
From Controller I'm passing a variable $startDate and on the view assigning it to different variables $day1, $day2, etc etc. I go through a loop on $day1 and I modify the day to increment $day1 by 1 using $day1->modify("+1 day")
$day2 the loop (in the else portion) doesn't trigger because the value of $startDate is too high. however, it's value should be the same as $day1 before modification.
the Code:
The controller
public function appointmentSearch()
{
$counselor = $this->session->userdata('idUser');
if($this->input->post('SearchAppointments'))
{
$fromDate = $_POST['fromDate'];
$fromTimeSlot = $this->Admin_model->TimeConversion($_POST['fromTime']);
$toDate = $_POST['toDate'];
$toTimeSlot = $this->Admin_model->TimeConversion($_POST['toTime']);
$theStart = new DateTime($fromDate);
$theEnd = new DateTime($toDate);
$difference = $theEnd->diff($theStart);
$dayCount = $difference->d;
$timeCount = (int)$toTimeSlot-(int)$fromTimeSlot;
$data['schedule'] = true;
$data['days'] = $dayCount;
$data['slots'] = $timeCount;
$data['dayStart'] = $theStart;
$data['dayEnd'] = $theEnd;
$data['slotStart'] = $fromTimeSlot;
$data['slotEnd'] = $toTimeSlot;
$data['r1Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,1);
$data['r2Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,2);
$data['r3Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,3);
$data['r4Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,4);
$data['r5Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,5);
$data['r6Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,6);
$data['r7Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,7);
$data['r8Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,8);
$data['r9Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,9);
$data['r10Data'] = $this->Admin_model->GetOpenApptTimes($fromDate,$fromTimeSlot,$toDate,$toTimeSlot,10);
$this->load->view('admin/scheduler',$data);
}
}
The View:
<?php
if($schedule == true)
{ //if false we have search results
//classes for the form
$attributes = array('class' => 'row');
//normal attributtes for the time slots if they are blacked out
$subAttUnav = array('class' => 'btn btn-secondary btn-sm');
// if the used time slot is someone they can ask to move
$subAttMove = array('class' => 'btn btn-secondary btn-sm', 'style' => 'background:darkgrey;');
// it's wide open
$subAttOpen = array('class' => 'btn btn-secondary btn-sm');
if(count($r1Data) >= 1)
{ //room 1 has appoints scheduled during the time frame queried
echo '<div class="row" style="width:70%;margin:0 auto;"><h3 class="highlight">Room 1</h3>';
$day1 = $dayStart;
while($day1 <= $dayEnd)
{
$day1format = $day1->format('Y-m-d-H-i-s');
$dayArray = explode('-',$day1format);
for($i = 0;$i <= $slots; $i++)
{
$timeslot = $slotStart + $i;
$label = 'Book: ' . $timeslot . ':00 on ' . $dayArray[1] . '/' . $dayArray[2] . ' ';
foreach($r1Data as $index)
{
$row = explode('-',$index);
//var_dump($row);
$thisDay = $dayArray[0] . '/' . $dayArray[1] . '/' . $dayArray[2];
//echo '$thisDay =' . $thisDay . '</br>';
$apptDay = $row[6] . '/' . $row[7] . '/' . $row[8];
//echo '$apptDay =' . $apptDay . '</br>';
//echo '$timeslot =' . $timeslot . '</br>';
//echo '$row[9] =' . $row[9] . '</br>';
if($thisDay == $apptDay && $timeslot == (int)$row[9])
{ // the appointment date and timeslot matches current slide
echo '<div class="btn btn-secondary btn-sm m-1" style="background:black;" title="Time unavailable">' . $label . '</div>';
}
else
{
echo form_open('AdminForms/booking/' . $dayArray[0] . '/' . $dayArray[1] . '/' . $dayArray[2] . '/' . $timeslot . '/1', $attributes);
echo form_submit("Book",$label,$subAttOpen);
echo form_close();
}
}
}
$placeholder = $day1->modify('+1 day');
$day1 = $placeholder;
}
echo '</div><!-- End of Room 1 data -->';
}
else
{ // no results on query the time frame is wide open
echo '<div class="row" style="width:70%;margin:0 auto;"><h3 class="highlight">Room 1</h3>';
$day1 = $dayStart;
while($day1 <= $dayEnd)
{
$day1format = $day1->format('Y-m-d-H-i-s');
$dayArray = explode('-',$day1format);
for($i = 0;$i <= $slots; $i++)
{
$timeslot = $slotStart + $i;
$label = 'Book: ' . $timeslot . ':00 on ' . $dayArray[1] . '/' . $dayArray[2] . ' ';
echo form_open('AdminForms/booking/' . $dayArray[0] . '/' . $dayArray[1] . '/' . $dayArray[2] . '/' . $timeslot . '/1', $attributes);
echo form_submit("Book",$label,$subAttOpen);
echo form_close();
}
$placeholder = $day1->modify('+1 day');
$day1 = $placeholder;
}
echo '</div><!-- End of Room 1 data -->';
var_dump($dayStart);
}
if(count($r2Data) >= 1)
{ //room 1 has appoints scheduled during the time frame queried
echo '<div class="row" style="width:70%;margin:0 auto;"><h3 class="highlight">Room 2</h3>';
$day2 = $dayStart;
while($day2 <= $dayEnd)
{
$day2format = $day2->format('Y-m-d-H-i-s');
$day2Array = explode('-',$day2format);
for($i = 0;$i <= $slots; $i++)
{
$timeslot = $slotStart + $i;
$label = 'Book: ' . $timeslot . ':00 on ' . $day2Array[1] . '/' . $day2Array[2] . ' ';
foreach($r2Data as $index)
{
$row = explode('-',$index);
//var_dump($row);
$thisDay = $day2Array[0] . '/' . $day2Array[1] . '/' . $day2Array[2];
//echo '$thisDay =' . $thisDay . '</br>';
$apptDay = $row[6] . '/' . $row[7] . '/' . $row[8];
//echo '$apptDay =' . $apptDay . '</br>';
//echo '$timeslot =' . $timeslot . '</br>';
//echo '$row[9] =' . $row[9] . '</br>';
if($thisDay == $apptDay && $timeslot == (int)$row[9])
{ // the appointment date and timeslot matches current slide
echo '<div class="btn btn-secondary btn-sm m-1" style="background:black;" title="Time unavailable">' . $label . '</div>';
}
else
{
echo form_open('AdminForms/booking/' . $day2Array[0] . '/' . $day2Array[1] . '/' . $day2Array[2] . '/' . $timeslot . '/1', $attributes);
echo form_submit("Book",$label,$subAttOpen);
echo form_close();
}
}
}
$placeholder2 = $day2->modify('+1 day');
$day2 = $placeholder2;
}
echo '</div<!-- End of Room 2 data -->';
}
else
{ // no results on query the time frame is wide open
echo '<div class="row" style="width:70%;margin:0 auto;"><h3 class="highlight">Room 2</h3>';
$day2 = $startDate;
while($day2 <= $dayEnd)
{
$day2format = $day2->format('Y-m-d-H-i-s');
$day2Array = explode('-',$day2format);
for($i = 0;$i <= $slots; $i++)
{
$timeslot = $slotStart + $i;
$label = 'Book: ' . $timeslot . ':00 on ' . $day2Array[1] . '/' . $day2Array[2] . ' ';
echo form_open('AdminForms/booking/' . $day2Array[0] . '/' . $day2Array[1] . '/' . $day2Array[2] . '/' . $timeslot . '/1', $attributes);
echo form_submit("Book",$label,$subAttOpen);
echo form_close();
}
$placeholder2 = $day2->modify('+1 day');
$day2 = $placeholder2;
}
echo '</div><!-- End of Room 2 data -->';
}
Related
In a contract management tool I'm trying to populate a table from a PHP query.
The function is working properly until I use it in the while to calculate several dates during the same while loop.
FUNCTION CODE:
function calculo_data($data_calculo){
if($data_calculo == 0 ){
$result_datas = "NÂO aplicavel ";
echo $result_datas;
} else {
$hoje = date_create();
$data_calculo_date = date_create($data_calculo);
$diff = date_diff( $hoje, $data_calculo_date );
$meses = (($diff->format('%y')*12)+$diff->format('%m'));
$dias = $diff->days;
if($data_calculo_date < $hoje){
$result_datas = "não aplicavel ";
echo $result_datas;
} elseif($meses >=1 ) {
$result_datas = $meses . " meses ";
echo $result_datas;
} else {
$result_datas = $dias . " dias ";
echo $result_datas;
};
;
};
};
TABLE CODE:
while ($row_detalhes = mysqli_fetch_assoc($result_listagem_contratos)){
$listagem_cliente_ref = $row_detalhes['PkContrato'];
$listagem_cliente_cliente = $row_detalhes['ClienteNome'];
$listagem_cliente_inicio = $row_detalhes['ContratoDataInicio'];
$listagem_cliente_fim = $row_detalhes['ContratoDataFim'];
$listagem_cliente_senhorio = $row_detalhes['ContratoPreAvisoSenhorio'];
$listagem_cliente_inquilino = $row_detalhes['ContratoPreAvisoInquilino'];
$listagem_cliente_break = $row_detalhes['ContratoDataBreak'];
echo '<tr>';
echo '<td>' . $listagem_cliente_ref .'</td>';
echo '<td>' . $listagem_cliente_cliente .'</td>';
echo '<td>' . $listagem_cliente_inicio .'</td>';
echo '<td>' . $listagem_cliente_fim .' ( ' . calculo_data($listagem_cliente_fim) . ' )</td>';
echo '<td>' . $listagem_cliente_senhorio .' ( ' .calculo_data($listagem_cliente_senhorio) . ' )</td>';
echo '<td>' . $listagem_cliente_inquilino .' ( ' . calculo_data($listagem_cliente_inquilino) . ' )</td>';
echo '<td>' . $listagem_cliente_break .' ( ' . calculo_data($listagem_cliente_break) . ' )</td>';
echo '<td><a href="detalhe_contrato.php?id='. $listagem_cliente_ref . '">
<span class="glyphicon glyphicon-file" style="color:black"></span>
</a></td<>';
The result is the table showing at least part of the results but in the wrong position as in the picture!
It's because you echo directly in the function. It should return the values, not echo them:
function calculo_data($data_calculo){
if($data_calculo == 0 ){
$result_datas = "NÂO aplicavel ";
return $result_datas;
} else {
$hoje = date_create();
$data_calculo_date = date_create($data_calculo);
$diff = date_diff( $hoje, $data_calculo_date );
$meses = (($diff->format('%y')*12)+$diff->format('%m'));
$dias = $diff->days;
if($data_calculo_date < $hoje){
$result_datas = "não aplicavel ";
return $result_datas;
} elseif($meses >=1 ) {
$result_datas = $meses . " meses ";
return $result_datas;
} else {
$result_datas = $dias . " dias ";
return $result_datas;
}
}
}
There were also some ; too much that I removed.
I'm trying to open modal window with full picture inside for every thumbnail on list after clicking on it. There is my code with my tries of doing that. Does anyone know how should I do that?
<?php
$directory = 'uploads/delivery-pictures/';
// Zamieniamy znaki, bo w nazwach plikow nie ma znaku /
$npsNumber = str_replace('/', '_', $model->getNps());
$images = glob($directory . $npsNumber . '_' . $model->delivery_no . '*' .'*_m.jpg', GLOB_BRACE);
$i = 0;
if (empty($images)) {
echo 'Brak zdjęć';
}
foreach($images as $image) {
$i = $i + 1;
$id = $npsNumber . '_' . $model->delivery_no . '_' . $i;
echo '<img id=' . $id . ' src=https://produkcja.onix.lh/' . $image . ' />';
}
Modal::begin([
'header'=>'<h4>Zdjęcie dla dostawy'. $model->delivery_no .'</h4>',
'id' => 'modal',
'size'=>'modal-lg',
]);
echo "<div id='modalContent'>Zawartosc</div>";
Modal::end();
$this->registerJs(
"
$('".$id."').click(function (){
$('#modal').modal('show')
.find('#modalContent');
//.load($(this).attr('value'));
});
"
);
?>
I have found the solution, if someone is interested in it, I have pasted my code below.
<?php
$directory = 'uploads/delivery-pictures/';
// Zamieniamy znaki, bo w nazwach plikow nie ma znaku /
$npsNumber = str_replace('/', '_', $model->getNps());
$images = glob($directory . $npsNumber . '_' . $model->delivery_no . '*' .'*_m.jpg', GLOB_BRACE);
$i = 0;
if (empty($images)) {
echo 'Brak zdjęć';
}
echo "<script>
function showImg(srcImg){
console.log('debug2');
$('#modalImg').attr('src', srcImg);
$('#modal').modal('show');
};
</script>";
foreach($images as $image) {
$i = $i + 1;
$id = $npsNumber . '_' . $model->delivery_no . '_' . $i;
$fullImage = str_replace('_m', '_d', $image);
echo '<img id="' . $id . '" src="https://produkcja.onix.lh/' . $image . '" />';
echo "<script>
var currentId = \"".$id."\";
console.log(currentId);
$('#".$id."').click(function(){showImg(\"https://produkcja.onix.lh/" . $fullImage . "\")});
</script>";
}
Modal::begin([
'header'=>'<center><h4>Zdjęcie dla dostawy '. $model->delivery_no .'</h4></center>',
'id' => 'modal',
'size'=>'modal-lg',
]);
echo '<center><img id="modalImg" src="https://produkcja.onix.lh/' . $fullImage . '" /></center>';
Modal::end();
?>
I don't know what are the errors of this code because it's suddenly not accurate the showing value to the user like this:
$holidays = array();
$query_holiday = "SELECT * FROM holiday_tbl";
$result = mysqli_query($dbcon, $query_holiday);
while($row_holiday = mysqli_fetch_assoc($result))
{
array_push($row_holiday, $holidays);
}
if(strtotime(date("Y-m-d")) > strtotime($row['due_date']))
{
$currentDate = date("Y-m-d");
$days = (strtotime($currentDate) - strtotime($row['due_date'])) / 86400;
$daysTemp = $days;
for($i=1;$i<$days;$i++)
{
$currentDay = date("D", strtotime("+ ".$i." days"));
$date_loop = date("Y-m-d", strtotime("+ ".$i." days"));
if($currentDay == "Sun" || $currentDay == "Sat")
{
$daysTemp--;
}
else if(in_array($date_loop, $holidays))
{
$daysTemp--;
}
}
echo $daysTemp;
}
The current implementation is rather convoluted. In these cases I find it's always better to start over and try to simplify the logic as much as possible. Here is my take on your problem:
function calculate_days_late($due_date = '', $holidays = array(), $current_date = 'today') {
$days_late = 0;
// Get the timestamps for due date and current date
$current_date_ts = strtotime($current_date);
$due_date_ts = strtotime($due_date);
// If current date is not after due date then not late
if ($current_date_ts <= $due_date_ts) {
return $days_late;
}
$loop_date_ts = $current_date_ts;
while ($loop_date_ts > $due_date_ts) {
// If the looping date is not a weekend or holiday then count it
if ( ! in_array(date('D', $loop_date_ts), array('Sat','Sun'))
&& ! in_array(date('Y-m-d', $loop_date_ts), $holidays)) {
$days_late++;
}
$loop_date_ts = strtotime('-1 day', $loop_date_ts);
}
return $days_late;
}
// Test
echo '2017-09-05 = ' . calculate_days_late('2017-09-05', array(), '2017-09-05') . "\n";
echo '2017-09-06 = ' . calculate_days_late('2017-09-05', array(), '2017-09-06') . "\n";
echo '2017-09-07 = ' . calculate_days_late('2017-09-05', array(), '2017-09-07') . "\n";
echo '2017-09-08 = ' . calculate_days_late('2017-09-05', array(), '2017-09-08') . "\n";
echo '2017-09-09 = ' . calculate_days_late('2017-09-05', array(), '2017-09-09') . "\n";
echo '2017-09-10 = ' . calculate_days_late('2017-09-05', array(), '2017-09-10') . "\n";
echo '2017-09-11 = ' . calculate_days_late('2017-09-05', array(), '2017-09-11') . "\n";
echo '2017-09-12 = ' . calculate_days_late('2017-09-05', array(), '2017-09-12') . "\n";
echo '2017-09-13 = ' . calculate_days_late('2017-09-05', array(), '2017-09-13') . "\n";
Working example: https://eval.in/856018
Few days ago server crashed and was down for few hours, after server become available, my calendar started to display wrong data. It had to show me current month and 5 next(half a year in total). Server data is correct. Any ideas whats wrong with calendar? Does mysql server time can make my calendar show wrong data?
if (!isset($_MONTH))
$_MONTH = 6;
if (isset($_POST['subscribe_month']))
$_MONTH = $class->_dig($_POST['subscribe_month']);
$sql = mysql_query("SELECT d.header, d.id FROM " . $class->_cfg['pfx'] . "workshops as w
LEFT JOIN " . $class->_cfg['pfx'] . "workshops_date as wd ON wd.cid=w.id
LEFT JOIN " . $class->_cfg['pfx'] . "dictionary as d ON d.id=wd.city
WHERE w.public='1' and wd.public='1' and wd.date_end>='" . date("Y-m-d") . "' a
nd wd.predprosomtr='0' " . $where . " ORDER BY d.rang");
$CityList = array();
while ($_sql = mysql_fetch_assoc($sql)) {
$CityList[$_sql['id']] = $_sql['header'];
}
if ($Fcity && $Fcity != 0)
$where.=" and d.id=" . $Fcity . "";
elseif ($_POST['city'] && $class->_dig($_POST['city']) > 0)
$where.=" and d.id=" . $class->_dig($_POST['city']) . "";
if ($CitySearch != 0)
$where.=" and wd.city=" . $CitySearch . " ";
$sql = mysql_query("SELECT w.header, w.direction, w.subheader, wd.colsmonth, wd.is_new, wd.public_date_finish, wd.p_date_finish, w.aliaslink, wd.aliaslink as wd_aliaslink, w.direction, wd.city, wd.date_start, d.header as city_name, wd.date_end, wd.cid, wd.id as wd_id, w.id as w_id FROM " . $class->_cfg['pfx'] . "workshops as w
LEFT JOIN " . $class->_cfg['pfx'] . "workshops_date as wd ON wd.cid=w.id
LEFT JOIN " . $class->_cfg['pfx'] . "dictionary as d ON d.id=wd.city
WHERE w.public='1' and wd.public='1' and wd.date_end>='" . date("Y-m-d") . "' and w.direction<>'' and wd.predprosomtr='0' " . $where . " ORDER BY wd.date_start, wd.city");
//$output.=$where;
$month = 12;
$year = date("Y");
while ($_sql = mysql_fetch_assoc($sql)) {
$view = true;
if ($_sql['public_date_finish'] == '1' && $_sql['p_date_finish'] < date("Y-m-d"))
$view = false;
if ($view) {
$arWorkshops[$_sql['w_id']] = $_sql;
if (!isset($arWorkshopsCity[$_sql['cid']][$_sql['city']]) && $_sql['city'] > 0)
$arWorkshopsCity[$_sql['cid']][$_sql['city']] = $_sql['city'];
if (isset($arWorkshopsDate[$_sql['cid']]['count']))
$arWorkshopsDate[$_sql['cid']]['count'] = $arWorkshopsDate[$_sql['cid']]['count'] + 1;
else
$arWorkshopsDate[$_sql['cid']]['count'] = 1;
$direct = explode('#', $_sql['direction']);
for ($i = 0; $i < count($direct); $i++) {
if (trim($direct[$i]) != '') {
$arDirectionList[$direct[$i]] = $direct[$i];
}
}
//$arDirectionList[$_sql['direction']]=$_sql['direction'];
if (!isset($arWorkshopsDate[$_sql['cid']][ceil($class->convert_date($_sql['date_start'], '.', "month"))]))
$arWorkshopsDate[$_sql['cid']][ceil($class->convert_date($_sql['date_start'], '.', "month"))] = $_sql;
if ($class->convert_date($_sql['date_start'], '.', "month") < $month && $class->convert_date($_sql['date_start'], '.', "year") == $year) {
$month = $class->convert_date($_sql['date_start'], '.', "month");
$year = $class->convert_date($_sql['date_start'], '.', "year");
}
//if($class->convert_date($_sql['date_start'], '.', "year")==(date("Y")+1))$year=$class->convert_date($_sql['date_start'], '.', "year");
//$output.=$_sql['header']."-".$_sql['date_start']."-".$_sql['wd_id']."<br>";
}
}
//var_dump($arWorkshopsDate[185]);
$output.='<table class="table"><tr><th width="60"> </th><th class="first" style="width:auto">Название</th>';
if ($_MONTH == 12)
$w = "5%"; else
$w = "9%";
for ($i = $month; $i < ($month + $_MONTH); $i++) {
if ($year == date("Y"))
$m = $i;else
$m++;
if ($m <= 12 && $year == date("Y")) {
$output.='<th class="month" style="width:' . $w . '">' . $class->convert_date($m, '.', "myear") . ' <span>' . $year . '</span></th>';
} else {
if ($m > 12) {
$m = 1;
$year = $year + 1;
}
$output.='<th class="month" style="width:' . $w . '">' . $class->convert_date($m, '.', "myear") . ' <span>' . $year . '</span></th>';
}
}
$output.=' <th style="width:10%">';
if ($typeblock == 'webinars')
$output.='Формат';
else
$output.='Город';
$output.='</th></tr>';
if (isset($arWorkshops)) {
//foreach($arWorkshops as $LO=>$listOrd){
foreach ($arWorkshops as $k => $value) {
if (!$direction || $direction == 0)
$direction2 = $class->_direction($value['direction']);
else
$direction2 = $direction;
foreach ($arWorkshopsCity[$k] as $LO => $listOrd) {
$output2 = "";
$link_date = "";
$pt = 0;
$m_nth = ceil($month);
$is_new_class = '';
for ($i = ceil($month); $i < ($month + $_MONTH); $i++) {
if ($m_nth > 12)
$m_nth = 1;
if (isset($arWorkshopsDate[$k][$m_nth]) && $arWorkshopsDate[$k][$m_nth]['city'] == $LO) {
$pt++;
if ($pt == 1)
$city_name = $arWorkshopsDate[$k][$m_nth]['city_name'];
//if(isset($_TYPE) && $_TYPE!=0)$output.='<td class="date"><a href="/'.$typeblock.'/'.$value['aliaslink'].'/'.$arWorkshopsDate[$k][$i]['wd_aliaslink'].'/">';
//else
if (($arWorkshopsDate[$k][$m_nth]['is_new'] == '1') || ($arWorkshopsDate[$k][$m_nth + 1]['is_new'] == '1')) {
$is_new_class = " it_is_new";
} else {
$is_new_class = '';
}
$output2.='<td class="date"><a href="/' . $typeblock . '/' . $arDictionaryID[$direction2]['aliaslink'] . '/' . $value['aliaslink'] . '/' . $arWorkshopsDate[$k][$m_nth]['wd_aliaslink'] . '/">';
$link_date = '/' . $typeblock . '/' . $arDictionaryID[$direction2]['aliaslink'] . '/' . $value['aliaslink'] . '/' . $arWorkshopsDate[$k][$m_nth]['wd_aliaslink'] . '/';
if ($arWorkshopsDate[$k][$m_nth]['colsmonth'] > 0)
$output2.=$class->convert_date($arWorkshopsDate[$k][$m_nth]['date_start'], '.', "day_month") . "</a><br />" . $arWorkshopsDate[$k][$m_nth]['colsmonth'] . " мес.";
elseif ($arWorkshopsDate[$k][$m_nth]['date_start'] == $arWorkshopsDate[$k][$m_nth]['date_end'])
$output2.=$class->convert_date($arWorkshopsDate[$k][$m_nth]['date_start'], '.', "day_month") . "</a>";
else
$output2.=$class->convert_date($arWorkshopsDate[$k][$m_nth]['date_start'], '.', "day_month") . "<br />-" . $class->convert_date($arWorkshopsDate[$k][$m_nth]['date_end'], '.', "day_month") . "</a>";
$output2.='</td>';
}else {
$output2.='<td></td>';
}
$m_nth++;
}
if (($arWorkshopsDate[$k][$m_nth]['is_new'] == '1')) {
$is_new_class = " it_is_new";
}
$output.='<tr><td class="' . $is_new_class . '"> </td><td>';
//if(isset($_TYPE) && $_TYPE!=0)$output.='<strong>'.$value['header'].'</strong>';
//else
if ($pt == 1 && $arWorkshopsDate[$k]['count'] == 1)
$link = $link_date;
else
$link = '/' . $typeblock . '/' . $arDictionaryID[$direction2]['aliaslink'] . '/' . $value['aliaslink'] . '/';
$output.='<a href="' . $link . '"><strong>' . $value['header'] . '</strong>';
if (trim($value['subheader']) != '')
$output.=': ' . $value['subheader'] . '';
$output.='</a>';
$output.='</td>';
$output.=$output2;
$output.=' <td class="city">' . $city_name . '</td></tr>';
}
}
//}
}
$output.='</table>';
?>
Issue solved. By default some "good" coder made it show only from 12th month in $month = 12;
I just changed it to $month = date("m"); And this solved my issue
I'm looking to edit the Gigpress code so that when events are not 'grouped by artist', they are still ordered by event date rather than artist name.
The Gigpress sidebar does this no problem so I figure that the main plugin should be able to be configured to do this somehow. Just can't get my head around this.
The plugin code is
<?php
// These two functions are for backwards-compatibility the shortcodes used in GigPress < 2.0
function gigpress_upcoming($filter = null, $content = null) {
if(!is_array($filter)) $filter = array();
$filter['scope'] = 'upcoming';
return gigpress_shows($filter, $content);
}
function gigpress_archive($filter = null, $content = null) {
if(!is_array($filter)) $filter = array();
$filter['scope'] = 'past';
return gigpress_shows($filter, $content);
}
function gigpress_shows($filter = null, $content = null) {
global $wpdb, $gpo;
$further_where = $limit = '';
extract(shortcode_atts(array(
'tour' => FALSE,
'artist' => FALSE,
'venue' => FALSE,
'limit' => FALSE,
'scope' => 'upcoming',
'sort' => FALSE,
'group_artists' => 'yes',
'artist_order' => 'custom',
'show_menu' => FALSE,
'show_menu_count' => FALSE,
'menu_sort' => FALSE,
'menu_title' => FALSE,
'year' => FALSE,
'month' => FALSE
), $filter)
);
$total_artists = $wpdb->get_var("SELECT count(*) from " . GIGPRESS_ARTISTS);
// Date conditionals and sorting based on scope
switch($scope) {
case 'upcoming':
$date_condition = "show_expire >= '" . GIGPRESS_NOW . "'";
if(empty($sort)) $sort = 'asc';
break;
case 'past':
$date_condition = "show_expire < '" . GIGPRESS_NOW . "'";
if(empty($sort)) $sort = 'desc';
break;
case 'today':
$date_condition = "show_expire >= '".GIGPRESS_NOW."' AND show_date <= '".GIGPRESS_NOW."'";
if(empty($sort)) $sort = 'asc';
break;
case 'all':
$date_condition = "show_expire != ''";
if(empty($sort)) $sort = 'desc';
break;
}
// Artist, tour and venue filtering
if($artist) $further_where .= ' AND show_artist_id = ' . $wpdb->prepare('%d', $artist);
if($tour) $further_where .= ' AND show_tour_id = ' . $wpdb->prepare('%d', $tour);
if($venue) $further_where .= ' AND show_venue_id = ' . $wpdb->prepare('%d', $venue);
// Date filtering
// Query vars take precedence over function vars
if(isset($_REQUEST['gpy'])) {
$year = $_REQUEST['gpy'];
if(isset($_REQUEST['gpm'])) {
$month = $_REQUEST['gpm'];
} else {
unset($month);
}
$no_limit = TRUE;
}
// Validate year and date parameters
if($year || $month) {
if($year) {
if(is_numeric($year) && strlen($year) == 4) {
$year = round($year);
} else {
$year = date('Y', current_time('timestamp'));
}
} else {
// We've only specified a month, so we'll assume the year is current
$year = date('Y', current_time('timestamp'));
}
if($month) {
if($month == 'current') {
$month = date('m', current_time('timestamp'));
} elseif(round($month) == 0) {
// Probably using a month name
$month = date('m', strtotime($month));
} elseif(round($month) < 10) {
// Make sure the month is padded through 09
$month = str_pad($month, 2, 0, STR_PAD_LEFT);
} elseif(round($month) < 13) {
// Between 10 and 12 we're OK
$month = $month;
} else {
// Bogus month value (not a string and > 12)
// Sorry, bailing out. Your "month" will be ignored. Dink.
$month = FALSE;
}
$start_month = $end_month = $month;
}
if(!$month) {
$start_month = '01';
$end_month = '12';
}
$start = $year.'-'.$start_month.'-01';
$end = $year.'-'.$end_month.'-31';
$further_where .= ' AND show_date BETWEEN '.$wpdb->prepare('%s', $start).' AND '.$wpdb->prepare('%s', $end);
}
$limit = ($limit && !$no_limit) ? ' LIMIT ' . $wpdb->prepare('%d', $limit) : '';
$artist_order = ($artist_order == 'custom') ? "artist_order ASC," : '';
// With the new 'all' scope, we should probably have a third message option, but I'm too lazy
// Really, there should just be one generic 'no shows' message. Oh well.
$no_results_message = ($scope == 'upcoming') ? wptexturize($gpo['noupcoming']) : wptexturize($gpo['nopast']);
ob_start();
// Are we showing our menu?
if($show_menu) {
$menu_options = array();
$menu_options['scope'] = $scope;
$menu_options['type'] = $show_menu;
if($menu_title) $menu_options['title'] = $menu_title;
if($show_menu_count) $menu_options['show_count'] = $show_menu_count;
if($menu_sort) $menu_options['sort'] = $menu_sort;
if($artist) $menu_options['artist'] = $artist;
if($tour) $menu_options['tour'] = $tour;
if($venue) $menu_options['venue'] = $venue;
include gigpress_template('before-menu');
echo gigpress_menu($menu_options);
include gigpress_template('after-menu');
}
// If we're grouping by artist, we'll unfortunately have to first get all artists
// Then make a query for each one. Looking for a better way to do this.
if($group_artists == 'yes' && !$artist && $total_artists > 1) {
$artists = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " ORDER BY " . $artist_order . "artist_name ASC");
foreach($artists as $artist_group) {
$shows = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS ." AS s LEFT JOIN " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE " . $date_condition . " AND show_status != 'deleted' AND s.show_artist_id = " . $artist_group->artist_id . " AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id " . $further_where . " ORDER BY s.show_date " . $sort . ",s.show_expire " . $sort . ",s.show_time ". $sort . $limit);
if($shows) {
// For each artist group
$some_results = TRUE;
$current_tour = '';
$i = 0;
$showdata = array(
'artist' => wptexturize($artist_group->artist_name),
'artist_id' => $artist_group->artist_id
);
include gigpress_template('shows-artist-heading');
include gigpress_template('shows-list-start');
foreach($shows as $show) {
// For each individual show
$showdata = gigpress_prepare($show, 'public');
if($showdata['tour'] && $showdata['tour'] != $current_tour && !$tour) {
$current_tour = $showdata['tour'];
include gigpress_template('shows-tour-heading');
}
$class = $showdata['status'];
++ $i; $class .= ($i % 2) ? '' : ' gigpress-alt';
if(!$showdata['tour'] && $current_tour) {
$current_tour = '';
$class .= ' divider';
}
$class .= ($showdata['tour'] && !$tour) ? ' gigpress-tour' : '';
include gigpress_template('shows-list');
}
include gigpress_template('shows-list-end');
}
}
if($some_results) {
// After all artist groups
include gigpress_template('shows-list-footer');
} else {
// No shows from any artist
include gigpress_template('shows-list-empty');
}
} else {
// Not grouping by artists
$shows = $wpdb->get_results("
SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS ." AS s LEFT JOIN " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE " . $date_condition . " AND show_status != 'deleted' AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id " . $further_where . " ORDER BY s.show_date " . $sort . ",s.show_expire " . $sort . ",s.show_time " . $sort . $limit);
if($shows) {
$current_tour = '';
$i = 0;
include gigpress_template('shows-list-start');
foreach($shows as $show) {
// For each individual show
$showdata = gigpress_prepare($show, 'public');
if($showdata['tour'] && $showdata['tour'] != $current_tour && !$tour) {
$current_tour = $showdata['tour'];
include gigpress_template('shows-tour-heading');
}
$class = $showdata['status'];
++ $i; $class .= ($i % 2) ? '' : ' gigpress-alt';
if(!$showdata['tour'] && $current_tour) {
$current_tour = '';
$class .= ' divider';
}
$class .= ($showdata['tour'] && !$tour) ? ' gigpress-tour' : '';
include gigpress_template('shows-list');
}
include gigpress_template('shows-list-end');
include gigpress_template('shows-list-footer');
} else {
// No shows to display
include gigpress_template('shows-list-empty');
}
}
echo('<!-- Generated by GigPress ' . GIGPRESS_VERSION . ' -->
');
return ob_get_clean();
}
function gigpress_menu($options = null) {
global $wpdb, $wp_locale, $gpo;
extract(shortcode_atts(array(
'type' => 'monthly',
'base' => get_permalink(),
'scope' => 'upcoming',
'title' => FALSE,
'id' => 'gigpress_menu',
'show_count' => FALSE,
'artist' => FALSE,
'tour' => FALSE,
'venue' => FALSE,
'sort' => 'desc'
), $options));
$base .= (strpos($base, '?') === FALSE) ? '?' : '&';
// Date conditionals based on scope
switch($scope) {
case 'upcoming':
$date_condition = ">= '" . GIGPRESS_NOW . "'";
break;
case 'past':
$date_condition = "< '" . GIGPRESS_NOW . "'";
break;
case 'all':
$date_condition = "!= ''";
}
$further_where = '';
// Artist, tour and venue filtering
if($artist) $further_where .= ' AND show_artist_id = ' . $wpdb->prepare('%d', $artist);
if($tour) $further_where .= ' AND show_tour_id = ' . $wpdb->prepare('%d', $tour);
if($venue) $further_where .= ' AND show_venue_id = ' . $wpdb->prepare('%d', $venue);
// Variable operajigamarations based on monthly vs. yearly
switch($type) {
case 'monthly':
$sql_select_extra = 'MONTH(show_date) AS month, ';
$sql_group_extra = ', MONTH(show_date)';
$title = ($title) ? wptexturize(strip_tags($title)) : __('Select Month');
$current = (isset($_REQUEST['gpy']) && isset($_REQUEST['gpm'])) ? $_REQUEST['gpy'].$_REQUEST['gpm'] : '';
break;
case 'yearly':
$sql_select_extra = $sql_group_extra = '';
$title = ($title) ? wptexturize(strip_tags($title)) : __('Select Year');
$current = (isset($_REQUEST['gpy'])) ? $_REQUEST['gpy'] : '';
}
// Build query
$dates = $wpdb->get_results("
SELECT YEAR(show_date) AS year, " . $sql_select_extra . " count(show_id) as shows
FROM ".GIGPRESS_SHOWS."
WHERE show_status != 'deleted'
AND show_date " . $date_condition . $further_where . "
GROUP BY YEAR(show_date)" . $sql_group_extra . "
ORDER BY show_date " . $sort);
ob_start();
if($dates) : ?>
<select name="gigpress_menu" class="gigpress_menu" id="<?php echo $id; ?>">
<option value="<?php echo $base; ?>"><?php echo $title; ?></option>
<?php foreach($dates as $date) : ?>
<?php $this_date = ($type == 'monthly') ? $date->year.$date->month : $date->year; ?>
<option value="<?php echo $base.'gpy='.$date->year; if($type == 'monthly') echo '&gpm='.$date->month; ?>"<?php if($this_date == $current) : ?> selected="selected"<?php endif; ?>>
<?php if($type == 'monthly') echo $wp_locale->get_month($date->month).' '; echo $date->year; ?>
<?php if($show_count && $show_count == 'yes') : ?>(<?php echo $date->shows; ?>)<?php endif; ?>
</option>
<?php endforeach; ?>
</select>
<?php endif;
return ob_get_clean();
}
The line under // Not grouping by artists
Change from:
$shows = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS ." AS s LEFT JOIN " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE " . $date_condition . " AND show_status != 'deleted' AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id " . $further_where . " ORDER BY s.show_date " . $sort . ",s.show_expire " . $sort . ",s.show_time " . $sort . $limit);
To:
$shows = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS ." AS s LEFT JOIN " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE " . $date_condition . " AND show_status != 'deleted' AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id " . $further_where . " ORDER BY a.artist_name ASC,s.show_date " . $sort . ",s.show_expire " . $sort . ",s.show_time " . $sort . $limit);