function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array())
{
    $first_of_month = gmmktime(0, 0, 0, $month, 1, $year);
    #remember that mktime will automatically correct if invalid dates are entered
    # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
    # this provides a built in "rounding" feature to generate_calendar()
    $day_names = array();
    #generate all the day names according to the current locale
    for ($n = 0, $t = (3 + $first_day) * 86400; $n < 7; $n++, $t += 86400) {
        #January 4, 1970 was a Sunday
        $day_names[$n] = ucfirst(gmstrftime('%A', $t));
    }
    #%A means full textual day name
    list($month, $year, $month_name, $weekday) = explode(',', gmstrftime('%m,%Y,%B,%w', $first_of_month));
    $weekday = ($weekday + 7 - $first_day) % 7;
    #adjust for $first_day
    $title = strtoupper(htmlentities(ucfirst($month_name))) . '&nbsp;' . $year;
    #note that some locales don't capitalize month and day names
    #Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
    @(list($p, $pl) = each($pn));
    @(list($n, $nl) = each($pn));
    #previous and next links, if applicable
    if ($p) {
        $p = '<span class="calendar-prev">' . ($pl ? '<a href="' . htmlspecialchars($pl) . '">' . $p . '</a>' : $p) . '</span>&nbsp;';
    }
    if ($n) {
        $n = '&nbsp;<span class="calendar-next">' . ($nl ? '<a href="' . htmlspecialchars($nl) . '">' . $n . '</a>' : $n) . '</span>';
    }
    $calendar = '<table style="padding: 0px; margin: 0px auto;" class="calendar"><tr>';
    if ($day_name_length) {
        #if the day names should be shown ($day_name_length > 0)
        #if day_name_length is >3, the full name of the day will be printed
        foreach ($day_names as $d) {
            $calendar .= '<th abbr="' . htmlentities($d) . '">' . htmlentities($day_name_length < 4 ? substr($d, 0, $day_name_length) : $d) . '</th>';
        }
        $calendar .= "</tr>\n<tr>";
    }
    if ($weekday > 0) {
        $calendar .= '<td style="font-size: 8px" colspan="' . $weekday . '">&nbsp;</td>';
    }
    #initial 'empty' days
    for ($day = 1, $days_in_month = gmdate('t', $first_of_month); $day <= $days_in_month; $day++, $weekday++) {
        if ($weekday == 7) {
            $weekday = 0;
            #start a new week
            $calendar .= "</tr>\n<tr>";
        }
        $content = $day;
        $my_classes = "";
        $mysql_date = "{$year}-{$month}-{$day}";
        if (!is_working_day("{$year}-{$month}-{$day}")) {
            $days[$day][1] = "day_holiday";
            $days[$day][2] = "{$day}";
        }
        $agenda_eventt = get_event_date($mysql_date);
        foreach ($agenda_eventt as $agenda_event) {
            list($timestamp, $event) = explode("|", $agenda_event);
            $days[$day][1] = "agenda";
            $days[$day][2] = "{$day}";
            $days[$day][0] = "index.php?sec=agenda&sec2=operation/agenda/agenda&month={$month}&year={$year}";
            $days[$day][3] = $event;
        }
        $agenda_wo = get_wo_end_date($mysql_date);
        foreach ($agenda_wo as $agenda_woitem) {
            list($idwo, $woname) = explode("|", $agenda_woitem);
            $days[$day][1] = "workorder";
            $days[$day][2] = "{$day}";
            $days[$day][0] = "index.php?sec=projects&sec2=operation/workorders/wo&operation=view&id={$idwo}";
            $days[$day][3] = $woname;
        }
        $agenda_task = get_task_end_date($mysql_date);
        foreach ($agenda_task as $agenda_titem) {
            list($tname, $idt, $tend, $pname) = explode("|", $agenda_titem);
            $days[$day][1] = "task";
            $days[$day][2] = "{$day}";
            $days[$day][0] = "index.php?sec=projects&sec2=operation/projects/task_detail&id_task={$idt}&operation=view";
            $days[$day][3] = $pname . " / " . $tname;
        }
        $agenda_project = get_project_end_date($mysql_date);
        foreach ($agenda_project as $agenda_pitem) {
            list($pname, $idp, $pend) = explode("|", $agenda_pitem);
            $days[$day][1] = "project";
            $days[$day][2] = "{$day}";
            $days[$day][0] = "index.php?sec=projects&sec2=operation/projects/task&id_project={$idp}";
            $days[$day][3] = $pname;
        }
        $time = time();
        $today = date('j', $time);
        $today_m = date('n', $time);
        $today_style = "";
        if ($today == $day && $today_m == $month) {
            $today_style .= " style='border: 1px solid #FF9933; color: #FF9933;'";
        }
        if (isset($days[$day]) and is_array($days[$day])) {
            @(list($link, $classes, $content, $tooltip) = $days[$day]);
            $calendar .= '<td ' . $today_style . ' class="' . htmlspecialchars($classes) . '">';
            if ($link) {
                $calendar .= '<a title="' . $tooltip . '" href="' . htmlspecialchars($link) . '">' . $content . '</a></td>';
            } else {
                $calendar .= $content . '</td>';
            }
        } else {
            $calendar .= "<td {$today_style}>{$content}</td>";
        }
    }
    if ($weekday != 7) {
        $calendar .= '<td colspan="' . (7 - $weekday) . '">&nbsp;</td>';
    }
    #remaining "empty" days
    $calendar_outer = '<table style="padding: 0px; margin: 0px auto;" class="calendar_outer_orange"><tr>';
    $calendar_outer .= '<th colspan=7 class="calendar-month"><center><b>' . $title . '</b></center></th></tr><tr>';
    $calendar_outer .= '<td>' . $calendar . '</td></tr></table>';
    return $calendar_outer . "</tr>\n</table>\n";
}
Exemple #2
0
/**
 * Checks and notify user by mail if in current day there are ending projects
 *
 */
function run_project_check()
{
    global $config;
    $now = date("Y-m-d");
    $projects = get_project_end_date($now, 0, "_ANY_");
    foreach ($projects as $project) {
        list($pname, $idp, $pend, $owner) = split("\\|", $project);
        $user = get_db_row("tusuario", "id_usuario", $owner);
        $nombre = $user['nombre_real'];
        $email = $user['direccion'];
        $mail_description = "There is an Integria project ending today ({$pend}): {$pname}. \n\nUse this link to review the project information:\n";
        $mail_description .= $config["base_url"] . "index.php?sec=projects&sec2=operation/projects/project_detail&id_project={$idp}\n";
        integria_sendmail($email, "[" . $config["sitename"] . "] Project ends today ({$pname})", $mail_description);
    }
}