Jump to content

Timing Issue??


tuxbuddy

Recommended Posts

Can Anyone Help me understanding the code:

<?
$reportwhat_array = array(    'incidents_small_stat'                 => text('incidents_small_stat'),
                     'incidents_extended'                => text('incidents_extended'),
                     'incidents_sla'                        => text('incidents_sla'),
                     'incidents_time'                    => text('incidents_time'),
                     'incidents_extended_incl_solution'        => text('incidents_extended_incl_solution'),
                     'incidents_per_org_per_building'       => text('incidents_per_org_per_building'),
                     'incidents_per_org_bld_solution'       => text('report_incidents_per_org_per_building_incl_solution' ),
                     'incidents_report_short'               => text('incidents_report_short' )
                      );
/**
*Organisatie naam, Incident nummer, Samenvatting, Laatste twee lijnen in, interne notes, status, streefdatum
*/
function report_incidents_report_short()
{
   global $main_time_where, $where, $uls_incident_limiter, $custom_table, $custom_id_fields;

   $incident_limiter = $uls_incident_limiter;
   if( $incident_limiter != '' ) $incident_limiter =  ' AND '.$incident_limiter;

   $table = new class_table;
   $table->table_columns = 4;
   $table->add_header_row( array( text('loginname'), '#', text('description'), text('notes'), text('status'), text('date_solv

   $GLOBALS['db']->query( 'SELECT '.$custom_id_fields.', i.desc_small AS description, status.name AS status, status.id AS sta
                           users.firstname AS firstname, users.surname AS surname, users.id AS userid, users.loginname as log
                           i.sla_date_solve_before AS solve_before, organisation.name as organisation_name, organisation.id a
                       FROM '.$custom_table.' AS i, status, users
                  LEFT JOIN organisation ON organisation.id = i.organisation_id
                      '.$main_time_where.' '.$where.
                     '  AND i.contact_id=users.id  AND i.status_id = status.id '.$incident_limiter .
                  ' ORDER BY organisation.name, loginname, status, i.id' );


   while( $row=$GLOBALS['db']->fetch_array() ) {

      // Get last 2 lines
      $boom = explode( "\n", $row['notes'] );
      if( count($boom) > 2 ) {
         $notes = $boom[count($boom)-2] . "\n" . $boom[count($boom)-1];
      }
      else {
         $notes = $row['notes'];
      }
                                           
      $table->add_row( array( '<img src="'.BASE_URL.'images/user_tiny.gif"><a href="users.php?usersaction=show&usersshowid='.
                        '( <a href="users.php?usersaction=show&usersshowid='.$row['userid'].'">'.$row['loginname'].'</a> ) <b
                        '<img src="'.BASE_URL.'images/organisation_tiny.gif"><a href="organisation.php?organisationaction=sho
                        '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$row['dbid'].'
                        nl2br($row['description']),
                        nl2br(trim($notes)),
                        '<a href="status.php?statusaction=show&statusshowid='.$row['statusid'].'">'.$row['status'].'</a>',
                        db_to_human_date( $row['solve_before'] )

                         ) );
   }

   $GLOBALS['box']->add( text('incidents_report_short'), $table->finish() );

}


/**
* Show a report with incidents per organisation per building
*/
function report_incidents_per_org_per_building()
{
   global $main_time_where, $where, $uls_incident_limiter, $custom_table, $custom_id_fields;

   $incident_limiter = $uls_incident_limiter;
   if( $incident_limiter != '' ) $incident_limiter =  ' AND '.$incident_limiter;

   // Store
   $orgName = '';
   $bldName = '';

   // All incidents
   $table = new class_table;
   $table->table_columns = 3;
   $table->add_header_row( array( text('status'), '#', text('description') ) );


   $GLOBALS['db']->query( 'SELECT '.$custom_id_fields.', i.desc_small AS description, status.name AS status, status.id AS sta
                           organisation.name AS organisation_name, buildings.name AS building_name
                       FROM '.$custom_table.' AS i, status, organisation, buildings '.$main_time_where.' '.$where.
                     '  AND i.organisation_id=organisation.id AND i.building_id=buildings.id AND i.status_id = status.id '.$i
                  ' ORDER BY organisation_name, building_name, status, i.id' );
                                                                                    while( $row=$GLOBALS['db']->fetch_array() ) {

      // show if new org
      if( $orgName != $row['organisation_name'] ) {
         $orgName = $row['organisation_name'];
         $table->add_header_line( $orgName );
      }

      // Show if new building
      if( $bldName != $row['building_name'] ) {
         $bldName = $row['building_name'];
         $table->add_line( $bldName );
      }


      $table->add_row( array( '<a href="status.php?statusaction=show&statusshowid='.$row['statusid'].'">'.$row['status'].'</a
                        '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$row['dbid'].'
                        nl2br($row['description']) ) );
   }

   $GLOBALS['box']->add( text('incidents_per_org_per_building'), $table->finish() );
}


/**
* Show a report with incidents per organisation per building
*
* Show incidents with solution grouped by organisation and building
*/
function report_incidents_per_org_bld_solution()
{
   global $main_time_where, $where, $uls_incident_limiter, $custom_table, $custom_id_fields;

   $incident_limiter = $uls_incident_limiter;
   if( $incident_limiter != '' ) $incident_limiter =  ' AND '.$incident_limiter;

   // Store
   $orgName = '';
   $bldName = '';

   // All incidents
   $table = new class_table;
$table->add_header_row( array( text('status'), '#', text('description'), text('solution') ) );


   $GLOBALS['db']->query( 'SELECT '.$custom_id_fields.', i.desc_small AS description, i.solution AS solution, status.name AS
                           organisation.name AS organisation_name, buildings.name AS building_name
                       FROM '.$custom_table.' AS i, status, organisation, buildings '.$main_time_where.' '.$where.
                     '  AND i.organisation_id=organisation.id AND i.building_id=buildings.id AND i.status_id = status.id '.$i
                  ' ORDER BY organisation_name, building_name, status, i.id' );

   while( $row=$GLOBALS['db']->fetch_array() ) {

      // show if new org
      if( $orgName != $row['organisation_name'] ) {
         $orgName = $row['organisation_name'];
         $table->add_header_line( $orgName );
      }

      // Show if new building
      if( $bldName != $row['building_name'] ) {
         $bldName = $row['building_name'];
         $table->add_line( $bldName );
      }

      $table->add_row( array( '<a href="status.php?statusaction=show&statusshowid='.$row['statusid'].'">'.$row['status'].'</a
                        '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$row['dbid'].'
                        nl2br($row['description']),
                        nl2br($row['solution'] ) ) );
   }

   $GLOBALS['box']->add( text('incidents_per_org_per_building'), $table->finish() );
}

/**
* Show a report with timeing information for incidents
*/
function report_incidents_time()
{
   global $main_time_where, $where, $db2, $uls_incident_limiter, $custom_table, $custom_id_fields;

   $incident_limiter = $uls_incident_limiter;
   if( $incident_limiter != '' ) $incident_limiter =  ' AND '.$incident_limiter;

   $epoch_now = dmy_to_days_from_epoch( date( 'd' ), date( 'm' ), date( 'Y' ) );
$secs_now = ( date( 'H' ) * 3600 ) + ( date( 'i' ) * 60 ) + date( 's' );

   // All incidents
   $table = new class_table;
   $table->table_columns = 3;
   $table->add_header_row( array( '#', text('description'), text( 'date_reported' ), text('date_started'), text( 'date_status
   $GLOBALS['db']->query( 'SELECT '.$custom_id_fields.',
                           desc_small,
                           date_started,
                           date_reported,
                           date_laststatuschange
                       FROM '.$custom_table.' AS i'.
                           $main_time_where.' '.
                           $where. ' '.
                           $incident_limiter );
   while( $row=$GLOBALS['db']->fetch_array() ) {

      $date_reported          = $row['date_reported'];
      $date_started           = $row['date_started'];
      $date_laststatuschange  = $row['date_laststatuschange'];

      $ta = db_time_to_array( $row['date_reported'] );
      $epoch_reported = dmy_to_days_from_epoch( $ta[0], $ta[1], $ta[2] );
      $secs_reported = ( $ta[3] * 3600 ) + ( $ta[4] * 60 ) + $ta[5];

      // report -> now
      $offset = (( $epoch_now - $epoch_reported ) * 86400 ) + ( $secs_now - $secs_reported );
      $hour = ( int )( $offset / 3600 );
      $min = ( int )( ( $offset - ( $hour * 3600 ) ) / 60 );
      if ( $min < 10 ) $min = '0' . $min;
      $date_reported .= '<br /><em>'.text( 'difference' ) . ' '. text('now') . ': ' . $hour . ':' . $min . ' ' . text( 'hour'


      $ta = db_time_to_array( $row['date_started'] );
      if( ($ta[0]==0) &&($ta[1]==0) &&($ta[2]==0) &&($ta[3]==0) &&($ta[4]==0) &&($ta[5]==0) ) {

         $table->add_row( array( '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$row[
                  nl2br($row['desc_small']),
                  $date_reported,
                  '-',
                  '-' ) );

         continue;
}
      $epoch_started = dmy_to_days_from_epoch( $ta[0], $ta[1], $ta[2] );
      $secs_started = ( $ta[3] * 3600 ) + ( $ta[4] * 60 ) + $ta[5];


      $ta = db_time_to_array( $row['date_laststatuschange'] );
      if( ($ta[0]==0) &&($ta[1]==0) &&($ta[2]==0) &&($ta[3]==0) &&($ta[4]==0) &&($ta[5]==0) ) {

         $table->add_row( array( '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$row[
                  nl2br($row['desc_small']),
                  $date_reported,
                  '-',
                  '-' ) );

         continue;
      }
      $epoch_sc = dmy_to_days_from_epoch( $ta[0], $ta[1], $ta[2] );
      $secs_sc = ( $ta[3] * 3600 ) + ( $ta[4] * 60 ) + $ta[5];


      // Report -> start
      $offset = (( $epoch_started - $epoch_reported ) * 86400 ) + ( $secs_started - $secs_reported );
      $hour = ( int )( $offset / 3600 );
      $min = ( int )( ( $offset - ( $hour * 3600 ) ) / 60 );
      if ( $min < 10 ) $min = '0' . $min;
      $date_started .= '<br /><em>'.text( 'difference' ) . ' '. text('date_reported') . ': ' . $hour . ':' . $min . ' ' . tex

      // started -> now
      $offset = (( $epoch_now - $epoch_started ) * 86400 ) + ( $secs_now- $secs_started );
      $hour = ( int )( $offset / 3600 );
      $min = ( int )( ( $offset - ( $hour * 3600 ) ) / 60 );
      if ( $min < 10 ) $min = '0' . $min;
      $date_started .= '<br /><em>'.text( 'difference' ) . ' '. text('now') . ': ' . $hour . ':' . $min . ' ' . text( 'hour'



      // laststatuschange -> now
      $offset = (( $epoch_now - $epoch_sc ) * 86400 ) + ( $secs_now - $secs_sc );
      $hour = ( int )( $offset / 3600 );
      $min = ( int )( ( $offset - ( $hour * 3600 ) ) / 60 );
      if ( $min < 10 ) $min = '0' . $min;
      $date_laststatuschange .= '<br /><em>'.text( 'difference' ) . ' '. text('now') . ': ' . $hour . ':' . $min . ' ' . text

                                                                                                           297,0-1       47%
// laststatuschange -> started
      $offset = (( $epoch_sc - $epoch_started ) * 86400 ) + ( $secs_sc - $secs_started);
      $hour = ( int )( $offset / 3600 );
      $min = ( int )( ( $offset - ( $hour * 3600 ) ) / 60 );
      if ( $min < 10 ) $min = '0' . $min;
      $date_laststatuschange .= '<br /><em>'.text( 'difference' ) . ' '. text('date_started') . ': ' . $hour . ':' . $min . '

      $table->add_row( array( '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$row['db
                        nl2br($row['desc_small']),
                        $date_reported,
                        $date_started,
                        $date_laststatuschange ) );
   }

   $GLOBALS['box']->add( text('incidents_time'), $table->finish() );
}



/**
* Shows SLA information per incident
*/
function report_incidents_sla()
{
   global $main_time_where, $where, $db2, $uls_incident_limiter, $custom_table, $custom_id_fields;

   $amount_missed = 0;
   $amount_ok = 0;
   $amount_none = 0;
   $bar_chart = '';
   $value_row = '';
   $name_row = '';
   $bar_chart = '<table cellspacing="20" height="200" align="center"><tr>';

   $incident_limiter = $uls_incident_limiter;
   if( $incident_limiter != '' ) $incident_limiter = ' AND '.$incident_limiter;

   $ta = db_time_to_array( now() );
   $days_now = dmy_to_days_from_epoch( $ta[0], $ta[1], $ta[2] );
   $secs_now = ( $ta[3] * 3600 ) + ( $ta[4] * 60 ) + $ta[5];
   $epoch_now = ( $days_now * ( 3600 * 24 ) ) + $secs_now;

   $table_missed = new class_table;
$table_missed->add_header_row( array( '#', text('status'), text('priority'), text('hour'),  text('desc_small') ) );

   $table_ok = new class_table;
   $table_ok->table_columns = 5;
   $table_ok->add_header_row( array( '#', text('status'), text('priority'), text('hour'),  text('desc_small') ) );

   $table_none = new class_table;
   $table_none->table_columns = 4;
   $table_none->add_header_row( array( '#', text('status'), text('priority'), text('desc_small') ) );


   // Loop incidents
   $GLOBALS['db']->query( 'SELECT '.$custom_id_fields.',
                           desc_small,
                           i.date_reported AS date_reported,
                           i.date_escalated AS date_escalated,
                           status.name AS status,
                           status.id AS statusid,
                           priorities.id AS priorityid,
                           priorities.name AS priority
                       FROM '.$custom_table.' AS i
                   LEFT JOIN status ON ( i.status_id = status.id )
                   LEFT JOIN priorities ON ( i.priorities_id = priorities.id )
                            '.$main_time_where.' '.$where. ' ' . $incident_limiter .
                    'ORDER BY status.id' );
   while( $row=$GLOBALS['db']->fetch_array() ) {

      // Get the last new sla_time from the logs
      $db2->query( 'SELECT sla_time, changed FROM '.$custom_table.'_log WHERE incident_id='.$row['id'].' AND sla_time IS NOT

      // Sla time found !
      if( $db2->num_rows() > 0 ) {
         $log_row = $db2->fetch_array();

         // Calc it back to seconds and check if we are still within the limits
         // date escalted has higher precidence and if set use that as a the base time
         // replace the date_reported with the escalation time
         if ( is_valid_date( $row['date_escalated'] ) && O_INC_USEESCALATION )
         {
            $row['date_reported'] = $row['date_escalated'];
         }

         // Calc how many days from epoch this task is
// Calc how many days from epoch this task is
         // Calc how many seconds from the start of the day the task is
         $ta = db_time_to_array( $row['date_reported'] );
         $days_incident = dmy_to_days_from_epoch( $ta[0], $ta[1], $ta[2] );
         $secs_incident = ( $ta[3] * 3600 ) + ( $ta[4] * 60 ) + $ta[5];
         $epoch_incident = ( $days_incident * ( 3600 * 24 ) ) + $secs_incident;

         $ta = db_time_to_array( $log_row['changed'] );
         $days_sla = dmy_to_days_from_epoch( $ta[0], $ta[1], $ta[2] );
         $secs_sla = ( $ta[3] * 3600 ) + ( $ta[4] * 60 ) + $ta[5];
         $epoch_sla = ( $days_sla * ( 3600 * 24 ) ) + $secs_sla;

         // Check if we are now past this date
         if( ( $epoch_sla + ( $log_row['changed'] * 3600 ) ) < $epoch_now ) {
            $table_missed->add_row( array(   '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'sh
                                    '<a href="status.php?statusaction=show&statusshowid='.$row['statusid'].'">'.$row['status'
                                    '<a href="priorities.php?prioritiesaction=show&prioritiesshowid='.$row['priorityid'].'">'
                                    $log_row['sla_time'],
                                    $row['desc_small'] ) );
            $amount_missed++;
            continue;
         }

         $table_ok->add_row( array(    '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='
                              '<a href="status.php?statusaction=show&statusshowid='.$row['statusid'].'">'.$row['status'].'</a
                              '<a href="priorities.php?prioritiesaction=show&prioritiesshowid='.$row['priorityid'].'">'.$row[
                              $log_row['sla_time'],
                              $row['desc_small'] ) );
         $amount_ok++;
         continue;


      }

      // No sla
      $table_none->add_row( array(  '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$r
                              '<a href="status.php?statusaction=show&statusshowid='.$row['statusid'].'">'.$row['status'].'</a
                              '<a href="priorities.php?prioritiesaction=show&prioritiesshowid='.$row['priorityid'].'">'.$row[
                              $row['desc_small'] ) );
      $amount_none++;
   }

// Create nice array
   $sla_array = array();
   $sla_array[ text('sla_missed') ] = $amount_missed;
   $sla_array[ text('sla_ok') ] = $amount_ok;
   $sla_array[ text('sla_none') ] = $amount_none;

   $totals = $amount_ok + $amount_missed + $amount_none;

   if( $totals == 0 ) return;

   reset( $sla_array );
   while( list($key,$value) = each($sla_array ) )
   {
      $pct = ( $value / ($totals/100) );
      $bar_chart .= '<td class="customReportReportIncidentsSlaColumnHolder"><table class="customReportReportIncidentsSlaColum
      $name_row .= '<td> '.$key.' <br /><em>'.number_format( $pct, 2).' %</em></td>';
      $value_row .= '<td><small> ( '.$value.' '.text('of'). ' '. $totals . ' ) </small></td>';
   }
   $bar_chart .= '</tr><tr>'.$name_row.'</tr><tr>'.$value_row.'</tr></table>';
   $bar_chart = $GLOBALS['box']->data( text('status'), $bar_chart );

   // Show it all in a template
   $GLOBALS['template']->show( 'report_incidents_sla.tpl',
                        array(   'SLA_MISSED'   => $GLOBALS['box']->data( text('sla_missed').' ('.$amount_missed.')', $table_
                              'SLA_NONE'     => $GLOBALS['box']->data( text('sla_none').' ('.$amount_none.')', $table_none->f
                              'SLA_OK'    => $GLOBALS['box']->data( text('sla_ok').' ('.$amount_ok.')', $table_ok->finish() )
                              'BAR_CHART'    => $bar_chart ) );
}


/**
* Show all incidents categorized by their status
*/
function report_incidents_small_stat()
{
   global $main_time_where, $where, $uls_incident_limiter, $custom_table, $custom_id_fields;


   $incident_limiter = $uls_incident_limiter;
   if( $incident_limiter != '' ) $incident_limiter =  ' AND '.$incident_limiter;

   $status_array = array();
   $totals = 0;
// Query
   $table = new class_table;
   $table->table_columns = 3;
   $table->add_header_row( array( text('status'), '#', text('desc_small') ) );
   $GLOBALS['db']->query( 'SELECT '.$custom_id_fields.', desc_small, status.name AS status, status.id AS statusid
                       FROM '.$custom_table.' AS i
                   LEFT JOIN status ON ( i.status_id = status.id )
                            '.$main_time_where.' '.$where. ' '.$incident_limiter.
                    'ORDER BY status.id' );
   while( $row=$GLOBALS['db']->fetch_array() ) {

      if( ! isset( $status_array[$row['status']]) ) $status_array[$row['status']] = 0;
      $status_array[$row['status']]++;
      $totals++;

      $table->add_row( array( '<a href="status.php?statusaction=show&statusshowid='.$row['statusid'].'">'.$row['status'].'</a
                        '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$row['dbid'].'
                        $row['desc_small']
                         ) );
   }
   $amount_incidents = $GLOBALS['db']->num_rows();
   $incidents_box = $GLOBALS['box']->data( text('incidents').' ('.$amount_incidents.')', $table->finish() );

   $bar_chart = '';
   $name_row = '';
   $value_row = '';
   $bar_chart .= '<table cellspacing="20" height="200" align="center"><tr>';
   reset( $status_array );
   while( list($key,$value) = each($status_array ) )
   {
      $pct = ( $value / ($totals/100) );
      $bar_chart .= '<td class="customReportReportIncidentsSlaColumnHolder"><table class="customReportReportIncidentsSlaColum
      $name_row .= '<td> '.$key.' <br /><em>'.number_format( $pct, 2).' %</em></td>';
      $value_row .= '<td><small> ( '.$value.' '.text('of'). ' '. $totals . ' ) </small></td>';
   }
   $bar_chart .= '</tr><tr>'.$name_row.'</tr><tr>'.$value_row.'</tr></table>';
   $bar_chart = $GLOBALS['box']->data( text('status'), $bar_chart );

   $GLOBALS['template']->show( 'report_incidents_totals.tpl',
                                          array(   'INCIDENTS_BOX'      => $incidents_box,
                                                'BAR_CHART'          => $bar_chart ) );
}
}


/**
* Show a report with all incidents but without their solution
*/
function report_incidents_extended()
{
   global $main_time_where, $where, $uls_incident_limiter, $custom_table, $custom_id_fields;

   $incident_limiter = $uls_incident_limiter;
   if( $incident_limiter != '' ) $incident_limiter =  ' AND '.$incident_limiter;

   // All incidents
   $table = new class_table;
   $table->table_columns = 3;
   $table->add_header_row( array( text('status'), '#', text('description') ) );


   $GLOBALS['db']->query( 'SELECT '.$custom_id_fields.', i.description AS description, status.name AS status, status.id AS st
                                    FROM '.$custom_table.' AS i, status '.$main_time_where.' '.$where.
                                    ' AND i.status_id = status.id '.$incident_limiter . ' ORDER BY statusid, i.id' );

   while( $row=$GLOBALS['db']->fetch_array() ) {

      $table->add_row( array( '<a href="status.php?statusaction=show&statusshowid='.$row['statusid'].'">'.$row['status'].'</a
                        '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$row['dbid'].'
                        nl2br($row['description']) ) );
   }

   $GLOBALS['box']->add( text('incidents_extended'), $table->finish() );
}

/**
* Show a report with all incidents and their solutions
*/
function report_incidents_extended_incl_solution()
{
   global $main_time_where, $where, $uls_incident_limiter, $custom_table, $custom_id_fields;

   $incident_limiter = $uls_incident_limiter;
   if( $incident_limiter != '' ) $incident_limiter =  ' AND '.$incident_limiter;
// All incidents
   $table = new class_table;
   $table->table_columns = 4;
   $table->add_header_row( array( text('status'), '#', text('description'), text('solution') ) );


   $GLOBALS['db']->query( 'SELECT '.$custom_id_fields.', i.description AS description, i.solution AS solution, status.name AS
                                    FROM '.$custom_table.' AS i, status '.$main_time_where.' '.$where.
                                    ' AND i.status_id = status.id '.$incident_limiter . ' ORDER BY statusid, i.id' );

   while( $row=$GLOBALS['db']->fetch_array() ) {

      $table->add_row( array( '<a href="status.php?statusaction=show&statusshowid='.$row['statusid'].'">'.$row['status'].'</a
                        '<a href="'.$custom_table.'.php?'.$custom_table.'action=show&'.$custom_table.'showid='.$row['dbid'].'
                        nl2br($row['description']),
                        nl2br($row['solution']) ) );
   }

   $GLOBALS['box']->add( text('incidents_extended'), $table->finish() );
}

?>
                     

Link to comment
https://forums.phpfreaks.com/topic/106901-timing-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.