Exemple #1
0
 function OutputCategories()
 {
     global $ReportLanguage;
     foreach ($this->Categories as $cats) {
         $el = $this->XmlDoc->createElement("categories");
         if (!isset($cats->CategoriesAttrs['bgColor'])) {
             $cats->CategoriesAttrs['bgColor'] = $this->CategoryColor;
         }
         if (!isset($cats->CategoriesAttrs['fontColor'])) {
             $cats->CategoriesAttrs['fontColor'] = $this->CategoryFontColor;
         }
         foreach ($cats->CategoriesAttrs as $attr => $value) {
             $this->SetAttribute($el, $attr, $value);
         }
         $this->Chart_DataRendered($el);
         $this->XmlDoc->documentElement->appendChild($el);
         if ($cats->Title != "") {
             // Title
             $cat = $this->XmlDoc->createElement("category");
             $this->SetAttribute($cat, 'start', $this->DateToStr($this->StartDate));
             $this->SetAttribute($cat, 'end', $this->DateToStr($this->EndDate));
             $this->SetAttribute($cat, 'name', $cats->Title);
             foreach ($cats->CategoryAttrs as $attr => $value) {
                 $this->SetAttribute($cat, $attr, $value);
             }
             $this->Chart_DataRendered($cat);
             $el->appendChild($cat);
         } else {
             // Intervals
             $arStart = $this->GetDateTime($this->StartDate);
             $arEnd = $this->GetDateTime($this->EndDate);
             if ($cats->Interval == EWR_GANTT_INTERVAL_YEAR) {
                 $yrs = intval($arStart["year"]);
                 $yre = intval($arEnd["year"]);
                 for ($y = $yrs; $y <= $yre; $y++) {
                     $cat = $this->XmlDoc->createElement("category");
                     $start = $y == $yrs ? $this->DateTimeToStr($arStart) : $this->YMDToStr($y, 1, 1);
                     $end = $y == $yre ? $this->DateTimeToStr($arEnd) : $this->YMDToStr($y, 12, 31);
                     $this->SetAttribute($cat, 'start', $start);
                     $this->SetAttribute($cat, 'end', $end);
                     //if ($start == $this->YMDToStr($y, 1, 1) && $end == $this->YMDToStr($y, 12, 31)) // Complete year
                     $this->SetAttribute($cat, 'name', $y);
                     foreach ($cats->CategoryAttrs as $attr => $value) {
                         $this->SetAttribute($cat, $attr, $value);
                     }
                     $this->Chart_DataRendered($el);
                     $el->appendChild($cat);
                 }
             } elseif ($cats->Interval == EWR_GANTT_INTERVAL_QUARTER) {
                 $yrs = intval($arStart["year"]);
                 $mons = intval($arStart["mon"]);
                 $qtrs = floor(($mons - 1) / 3) + 1;
                 $qs = $yrs * 4 + $qtrs;
                 $yre = intval($arEnd["year"]);
                 $mone = intval($arEnd["mon"]);
                 $qtre = floor(($mone - 1) / 3) + 1;
                 $qe = $yre * 4 + $qtre;
                 for ($q = $qs; $q <= $qe; $q++) {
                     $cat = $this->XmlDoc->createElement("category");
                     $yr = floor($q / 4);
                     $qtr = $q % 4;
                     $yr = $qtr == 0 ? $yr - 1 : $yr;
                     $qtr = $qtr == 0 ? 4 : $qtr;
                     $mos = ($qtr - 1) * 3 + 1;
                     $moe = $qtr * 3;
                     $dys = $this->CreateDateTime(0, 0, 0, $mos, 1, $yr);
                     if ($this->StartDate > $dys) {
                         $dys = $this->StartDate;
                     }
                     $dy = ewr_DaysInMonth($yr, $moe);
                     $dye = $this->CreateDateTime(0, 0, 0, $moe, $dy, $yr);
                     if ($this->EndDate < $dye) {
                         $dye = $this->EndDate;
                     }
                     $start = $q == $qs ? $this->DateToStr($dys) : $this->YMDToStr($yr, $mos, 1);
                     $end = $q == $qe ? $this->DateToStr($dye) : $this->YMDToStr($yr, $moe, $dy);
                     $this->SetAttribute($cat, 'start', $start);
                     $this->SetAttribute($cat, 'end', $end);
                     //if ($start == $this->YMDToStr($yr, $mos, 1) && $end == $this->YMDToStr($yr, $moe, $dy)) // Complete quarter
                     $this->SetAttribute($cat, 'name', 'Q' . $qtr);
                     foreach ($cats->CategoryAttrs as $attr => $value) {
                         $this->SetAttribute($cat, $attr, $value);
                     }
                     $this->Chart_DataRendered($cat);
                     $el->appendChild($cat);
                 }
             } elseif ($cats->Interval == EWR_GANTT_INTERVAL_MONTH) {
                 $yrs = intval($arStart["year"]);
                 $mons = intval($arStart["mon"]);
                 $ms = $yrs * 12 + $mons;
                 $yre = intval($arEnd["year"]);
                 $mone = intval($arEnd["mon"]);
                 $me = $yre * 12 + $mone;
                 for ($m = $ms; $m <= $me; $m++) {
                     $cat = $this->XmlDoc->createElement("category");
                     $yr = floor($m / 12);
                     $mo = $m % 12;
                     $yr = $mo == 0 ? $yr - 1 : $yr;
                     $mo = $mo == 0 ? 12 : $mo;
                     $dy = ewr_DaysInMonth($yr, $mo);
                     $start = $m == $ms ? $this->DateTimeToStr($arStart) : $this->YMDToStr($yr, $mo, 1);
                     $end = $m == $me ? $this->DateTimeToStr($arEnd) : $this->YMDToStr($yr, $mo, $dy);
                     $this->SetAttribute($cat, 'start', $start);
                     $this->SetAttribute($cat, 'end', $end);
                     if ($start == $this->YMDToStr($yr, $mo, 1) && $end == $this->YMDToStr($yr, $mo, $dy)) {
                         // Complete month
                         $this->SetAttribute($cat, 'name', ewr_MonthName($mo));
                     }
                     // Or ewr_FormatMonth
                     foreach ($cats->CategoryAttrs as $attr => $value) {
                         $this->SetAttribute($cat, $attr, $value);
                     }
                     $this->Chart_DataRendered($cat);
                     $el->appendChild($cat);
                 }
             } elseif ($cats->Interval == EWR_GANTT_INTERVAL_WEEK) {
                 $ds = $this->StartDate;
                 $de = $this->EndDate;
                 for ($d = $ds; $d < $de; $d += 86400) {
                     $dts = $this->GetDateTime($d);
                     //$dte = $this->GetDateTime($d + 6*86400);
                     $wday = $dts["wday"];
                     $diff = $wday >= EWR_GANTT_WEEK_START ? $wday - EWR_GANTT_WEEK_START : $wday + 7 - EWR_GANTT_WEEK_START;
                     $ws = $d == $ds ? $ds : $d - $diff * 86400;
                     $we = $d == $de ? $de : $d + (6 - $diff) * 86400;
                     $d = $we;
                     $cat = $this->XmlDoc->createElement("category");
                     $this->SetAttribute($cat, 'start', $this->DateToStr($ws));
                     $this->SetAttribute($cat, 'end', $this->DateToStr($we));
                     if ($this->ShowWeekNumber && EWR_GANTT_WEEK_START == 1) {
                         // Week start on Monday
                         $this->SetAttribute($cat, 'name', $ReportLanguage->Phrase("Week") . " " . $this->FormatDate("W", $d));
                     } else {
                         $this->SetAttribute($cat, 'name', $ReportLanguage->Phrase("Week"));
                     }
                     foreach ($cats->CategoryAttrs as $attr => $value) {
                         $this->SetAttribute($cat, $attr, $value);
                     }
                     $this->Chart_DataRendered($cat);
                     $el->appendChild($cat);
                 }
             } elseif ($cats->Interval == EWR_GANTT_INTERVAL_DAY) {
                 $ds = $this->StartDate;
                 $de = $this->EndDate;
                 for ($d = $ds; $d <= $de; $d += 86400) {
                     $dt = $this->GetDateTime($d);
                     $md = $dt["mday"];
                     $cat = $this->XmlDoc->createElement("category");
                     $sdt = $this->DateTimeToStr($dt);
                     $this->SetAttribute($cat, 'start', $sdt);
                     $this->SetAttribute($cat, 'end', $sdt);
                     $this->SetAttribute($cat, 'name', $md);
                     foreach ($cats->CategoryAttrs as $attr => $value) {
                         $this->SetAttribute($cat, $attr, $value);
                     }
                     $this->Chart_DataRendered($cat);
                     $el->appendChild($cat);
                 }
             }
         }
     }
 }
Exemple #2
0
function ewr_DateVal($FldOpr, $FldVal, $ValType)
{
    // Compose date string
    switch (strtolower($FldOpr)) {
        case "year":
            if ($ValType == 1) {
                $wrkVal = "{$FldVal}-01-01";
            } elseif ($ValType == 2) {
                $wrkVal = "{$FldVal}-12-31";
            }
            break;
        case "quarter":
            list($y, $q) = explode("|", $FldVal);
            if (intval($y) == 0 || intval($q) == 0) {
                $wrkVal = "0000-00-00";
            } else {
                if ($ValType == 1) {
                    $m = ($q - 1) * 3 + 1;
                    $m = str_pad($m, 2, "0", STR_PAD_LEFT);
                    $wrkVal = "{$y}-{$m}-01";
                } elseif ($ValType == 2) {
                    $m = ($q - 1) * 3 + 3;
                    $m = str_pad($m, 2, "0", STR_PAD_LEFT);
                    $wrkVal = "{$y}-{$m}-" . ewr_DaysInMonth($y, $m);
                }
            }
            break;
        case "month":
            list($y, $m) = explode("|", $FldVal);
            if (intval($y) == 0 || intval($m) == 0) {
                $wrkVal = "0000-00-00";
            } else {
                if ($ValType == 1) {
                    $m = str_pad($m, 2, "0", STR_PAD_LEFT);
                    $wrkVal = "{$y}-{$m}-01";
                } elseif ($ValType == 2) {
                    $m = str_pad($m, 2, "0", STR_PAD_LEFT);
                    $wrkVal = "{$y}-{$m}-" . ewr_DaysInMonth($y, $m);
                }
            }
            break;
        case "day":
            $wrkVal = str_replace("|", "-", $FldVal);
    }
    // Add time if necessary
    if (preg_match('/(\\d{4}|\\d{2})-(\\d{1,2})-(\\d{1,2})/', $wrkVal)) {
        // Date without time
        if ($ValType == 1) {
            $wrkVal .= " 00:00:00";
        } elseif ($ValType == 2) {
            $wrkVal .= " 23:59:59";
        }
    }
    // Check if datetime
    if (preg_match('/(\\d{4}|\\d{2})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})/', $wrkVal)) {
        // DateTime
        $DateVal = $wrkVal;
    } else {
        $DateVal = "";
    }
    return $DateVal;
}