function ToDateTime($vValue)
 {
     $oDate = new DCLTimestamp();
     // Set to 0 to invalidate by default.  If parsing doesn't succeed, it will remain 0
     $oDate->time = 0;
     $oDate->SetFromDisplay($vValue);
     return $oDate->ToDisplay();
 }
 function showgraph()
 {
     commonHeader();
     // GD is required, so short-circuit if not installed
     if (!extension_loaded('gd')) {
         trigger_error(STR_BO_GRAPHNEEDSGD);
         return;
     }
     if (($iDays = @DCL_Sanitize::ToInt($_REQUEST['days'])) === null || ($dateFrom = @DCL_Sanitize::ToDate($_REQUEST['dateFrom'])) === null) {
         trigger_error('Data sanitize failed.');
         return;
     }
     $iProduct = 0;
     if (($iProduct = @DCL_Sanitize::ToInt($_REQUEST['product'])) === null) {
         $iProduct = 0;
     }
     $objG =& CreateObject('dcl.boGraph');
     $obj =& CreateObject('dcl.dbWorkorders');
     $beginDate = new DCLTimestamp();
     $endDate = new DCLTimestamp();
     $testDate = new DCLDate();
     $testTS = new DCLTimestamp();
     $endDate->SetFromDisplay($dateFrom . ' 23:59:59');
     $beginDate->SetFromDisplay($dateFrom . ' 00:00:00');
     $beginDate->time -= ($iDays - 1) * 86400;
     $query = 'SELECT ' . $obj->ConvertTimestamp('createdon', 'createdon') . ', ' . $obj->ConvertTimestamp('closedon', 'closedon') . ' FROM workorders WHERE ';
     if ($iProduct > 0) {
         $query .= 'product = ' . $iProduct . ' AND ';
     }
     $query .= '(createdon between ' . $obj->DisplayToSQL($beginDate->ToDisplay());
     $query .= ' AND ' . $obj->DisplayToSQL($endDate->ToDisplay());
     $query .= ') OR (closedon between ' . $obj->DisplayToSQL($beginDate->ToDisplay());
     $query .= ' AND ' . $obj->DisplayToSQL($endDate->ToDisplay()) . ')';
     $obj->Query($query);
     $objG->data[0] = array();
     // Open
     $objG->data[1] = array();
     // Closed
     $daysBack = array();
     $testDate->time = $beginDate->time;
     for ($i = 0; $i < $iDays; $i++) {
         $daysBack[$i] = $testDate->time;
         // Set the relevant object properties while we're at it
         $objG->line_captions_x[$i] = date('m/d', $testDate->time);
         $objG->data[0][$i] = 0;
         $objG->data[1][$i] = 0;
         $testDate->time += 86400;
     }
     while ($obj->next_record()) {
         $iTime = 0;
         for ($y = 0; $y < 2; $y++) {
             if ($y == 0) {
                 $testTS->SetFromDB($obj->f($y));
                 $iTime = $testTS->time;
             } else {
                 $testDate->SetFromDB($obj->f($y));
                 $iTime = $testDate->time;
             }
             $j = $iDays - 1;
             while ($j >= 0) {
                 if ($iTime >= $daysBack[$j]) {
                     if (!isset($objG->data[$y][$j])) {
                         $objG->data[$y][$j] = 0;
                     }
                     $objG->data[$y][$j]++;
                     break;
                 }
                 $j--;
             }
         }
     }
     $objG->title = STR_BO_WOGRAPHTITLE;
     if ($iProduct > 0) {
         $oDB =& CreateObject('dcl.dbProducts');
         if ($oDB->Load($iProduct) != -1) {
             $objG->title .= ' ' . $oDB->name;
         }
     }
     $objG->caption_y = STR_BO_WOGRAPHCAPTIONY;
     $objG->caption_x = STR_BO_GRAPHCAPTIONX;
     $objG->num_lines_y = 15;
     $objG->num_lines_x = $iDays;
     $objG->colors = array('red', 'blue');
     print '<center>';
     echo '<img border="0" src="', menuLink('', 'menuAction=boGraph.Show&' . $objG->ToURL()), '">';
     print '</center>';
 }
 function showgraph()
 {
     commonHeader();
     // GD is required, so short-circuit if not installed
     if (!extension_loaded('gd')) {
         trigger_error(STR_BO_GRAPHNEEDSGD);
         return;
     }
     $objG =& CreateObject('dcl.boGraph');
     $obj =& CreateObject('dcl.dbTickets');
     $beginDate = new DCLTimestamp();
     $endDate = new DCLTimestamp();
     $testDate = new DCLTimestamp();
     if (($iDays = @DCL_Sanitize::ToInt($_REQUEST['days'])) === null || ($dateFrom = @DCL_Sanitize::ToDate($_REQUEST['dateFrom'])) === null) {
         trigger_error('Data sanitize failed.');
         return;
     }
     $endDate->SetFromDisplay($dateFrom . ' 23:59:59');
     $beginDate->SetFromDisplay($dateFrom . ' 00:00:00');
     $beginDate->time -= ($iDays - 1) * 86400;
     $product_id = 0;
     if (($product_id = @DCL_Sanitize::ToInt($_REQUEST['product'])) === null) {
         $product_id = 0;
     }
     if ($obj->LoadDatesByRange($beginDate->ToDisplay(), $endDate->ToDisplay(), $product_id) == -1) {
         return;
     }
     $objG->data[0] = array();
     // Open
     $objG->data[1] = array();
     // Closed
     $daysBack = array();
     $testDate->time = $beginDate->time;
     for ($i = 0; $i < $iDays; $i++) {
         $daysBack[$i] = $testDate->time;
         // Set the relevant object properties while we're at it
         $objG->line_captions_x[$i] = date('m/d', $testDate->time);
         $objG->data[0][$i] = 0;
         $objG->data[1][$i] = 0;
         $testDate->time += 86400;
     }
     while ($obj->next_record()) {
         for ($y = 0; $y < 2; $y++) {
             $testDate->SetFromDB($obj->f($y));
             $j = $iDays - 1;
             while ($j >= 0) {
                 if ($testDate->time >= $daysBack[$j]) {
                     if (!isset($objG->data[$y][$j])) {
                         $objG->data[$y][$j] = 0;
                     }
                     $objG->data[$y][$j]++;
                     break;
                 }
                 $j--;
             }
         }
     }
     $objG->title = STR_BO_GRAPHTITLE;
     if ($product_id > 0) {
         $oDB =& CreateObject('dcl.dbProducts');
         if ($oDB->Load($product_id) != -1) {
             $objG->title .= ' ' . $oDB->name;
         }
     }
     $objG->caption_y = STR_BO_GRAPHCAPTIONY;
     $objG->caption_x = STR_BO_GRAPHCAPTIONX;
     $objG->num_lines_y = 15;
     $objG->num_lines_x = $iDays;
     $objG->colors = array('red', 'blue');
     print '<center>';
     echo '<img border="0" src="', menuLink('', 'menuAction=boGraph.Show&' . $objG->ToURL()), '">';
     print '</center>';
 }