예제 #1
0
 function result_recommend($recommend)
 {
     if (!$recommend || !is_array($recommend)) {
         return null;
     }
     $result = array();
     foreach ($recommend as $r) {
         $item = array();
         $item['ID'] = $r['ID'];
         $item['Title'] = $r['Title'];
         $item['SectionID'] = $r['SectionID'];
         $item['Feature'] = $r['Feature'];
         $item['Price'] = format_price2($r['Price']);
         $item['MarketPrice'] = format_price2($r['MarketPrice']);
         $item['Url'] = $r['Url'];
         $no_image = false;
         if ($r['MobilePic']) {
             $pic = $this->static_domain . $r['MobilePic'];
             $width = $r['MobileWidth'];
             $height = $r['MobileHeight'];
         } else {
             if ($r['Pic']) {
                 $pic = $this->image_url($r['Pic']);
                 $width = $r['Width'];
                 $height = $r['Height'];
             } else {
                 $no_image = true;
                 $width = $height = 0;
             }
         }
         $item['Img'] = $no_image ? null : array('Url' => $pic, 'Width' => $width ? $width : 0, 'Height' => $height ? $height : 0);
         $pids = array();
         if (preg_match('/\\/(visa|tour|ticket|insurance|info)\\/(list|search|detail)\\/?\\?(p|n)?id=(\\d+)\\w*/i', $r['Url'], $pids)) {
             $module = $pids[1];
             $page = $pids[2];
             $id = $pids[4];
             if ($module == 'info') {
                 $module = 'article';
             }
             $item['Module'] = array('Name' => $module, 'Action' => $page == 'search' ? 'list' : $page, 'ID' => $id);
         } else {
             $item['Module'] = array('Name' => '', 'Action' => '', 'ID' => 0);
         }
         array_push($result, $item);
     }
     return $result;
 }
function draw_calendar($month, $year, $data)
{
    /* draw table */
    $calendar = '<table data-year="' . $year . '" data-month="' . $month . '">';
    /* table headings */
    $headings = array('一', '二', '三', '四', '五');
    $calendar .= '<tr class="header"><th class="sunday">日</th><th>' . implode('</th><th>', $headings) . '</th><th class="saturday">六</th></tr>';
    /* days and weeks vars now ... */
    $running_day = date('w', mktime(0, 0, 0, $month, 1, $year));
    $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year));
    $days_in_this_week = 1;
    $day_counter = 0;
    $dates_array = array();
    /* row for week one */
    $calendar .= '<tr class="calendar-row">';
    /* print "blank" days until the first of the current week */
    for ($x = 0; $x < $running_day; $x++) {
        $calendar .= '<td class="calendar-day-np invalid-day"> </td>';
        $days_in_this_week++;
    }
    /* keep going with days.... */
    for ($list_day = 1; $list_day <= $days_in_month; $list_day++) {
        $key_day = $year . '-' . $month . '-' . $list_day;
        $td_class = '';
        $td_available = '';
        $td_price = '';
        $td_attr_price = '';
        if ($data && array_key_exists($key_day, $data)) {
            $val = $data[$key_day];
            if ($val['Available'] <= 0) {
                $td_class .= ' invalid-day ';
            } else {
                if ($val['Available'] <= 5) {
                    $td_class .= ' over ';
                    $td_available = '余位' . $val['Available'];
                } else {
                    if ($val['Available'] > 5) {
                        $td_class .= ' enough ';
                        $td_available = '充足';
                    }
                }
            }
            $td_price = '¥' . format_price2($val['AdultPrice']);
            $td_attr_price = ' adault-price="' . format_price2($val['AdultPrice']) . '"  child-price="' . format_price2($val['ChildPrice']) . '"  room-price="' . format_price2($val['RoomPrice']) . '" ';
        } else {
            $td_class = ' invalid-day ';
        }
        $calendar .= '<td class="calendar-day' . $td_class . '" data-date="' . $list_day . '" ' . $td_attr_price . '>';
        /* add in the day number */
        $calendar .= '<div><span class="date" data-date="' . $list_day . '">' . $list_day . '</span><a class="dayjh" href="javascript:void(0);"></a></div>';
        $calendar .= '<div><span class="dataprace">' . $td_available . '</span></div>';
        $calendar .= '<div><span class="dataprice">' . $td_price . '</span></div>';
        /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !!  IF MATCHES FOUND, PRINT THEM !! **/
        $calendar .= str_repeat('<p> </p>', 2);
        $calendar .= '</td>';
        if ($running_day == 6) {
            $calendar .= '</tr>';
            if ($day_counter + 1 != $days_in_month) {
                $calendar .= '<tr class="calendar-row">';
            }
            $running_day = -1;
            $days_in_this_week = 0;
        }
        $days_in_this_week++;
        $running_day++;
        $day_counter++;
    }
    /* finish the rest of the days in the week */
    if ($days_in_this_week < 8) {
        for ($x = 1; $x <= 8 - $days_in_this_week; $x++) {
            $calendar .= '<td class="calendar-day-np invalid-day"> </td>';
        }
    }
    /* final row */
    $calendar .= '</tr>';
    /* end the table */
    $calendar .= '</table>';
    /* all done, return result */
    return $calendar;
}