Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nconf/development
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyclodex committed Apr 2, 2012
2 parents cf7aac2 + ec2c712 commit 7df549e
Showing 1 changed file with 94 additions and 37 deletions.
131 changes: 94 additions & 37 deletions include/ajax/json/history.php
Expand Up @@ -7,14 +7,12 @@
# Get History of a Item
$basic_query = ' fk_id_item='.$_GET["id"].'
AND action <> "edited"';
// ORDER BY timestamp DESC, id_hist DESC';

$show_item_links = FALSE;

}else{
$show_item_links = TRUE;
# Show all entries but still with sql filters (basic history entries, no details about services)
//'SELECT SQL_CALC_FOUND_ROWS * FROM History WHERE'
$basic_query =
' (action="created"'
. ' OR action="removed"'
Expand Down Expand Up @@ -103,46 +101,105 @@
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];

$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
while ( $aRow = mysql_fetch_array( $rResult ) )
{
# do some stuff bevore generating output

# if object name contains password, and PASSWD_DISPLAY is 0 (made in called function), do not show password
if ( stristr($aRow["attr_name"], "password") ){
$aRow["attr_value"] = show_password($aRow["attr_value"]);
if (function_exists("json_encoded")){
// If json_ecode we use the php function to encode the array
// as example code from DataTables

$aColumns = array( 'timestamp', 'user_str', 'action', 'attr_name', 'attr_value', 'id_hist' );

$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);

while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( $aColumns[$i] == "version" )
{
$row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
}
else if ( $aColumns[$i] != ' ' )
{
$row[] = $aRow[ $aColumns[$i] ];
}
}
# do some stuff bevore generating output

# if object name contains password, and PASSWD_DISPLAY is 0 (made in called function), do not show password
if ( stristr($aRow["attr_name"], "password") ){
$aRow["attr_value"] = show_password($aRow["attr_value"]);
}
# item linking
if ( !empty($aRow["fk_id_item"]) AND $show_item_links ){
if ($aRow["action"] == "removed" AND $aRow["attr_name"] == "service"){
# removed services will link to hosts service list view
$aRow['attr_value'] = '<a href="modify_item_service.php?id='.$aRow["fk_id_item"].'">'.$aRow["attr_value"].'</a>';
}else{
# all other entries will link to its detail view
$aRow['attr_value'] = '<a href="detail.php?id='.$aRow["fk_id_item"].'">'.$aRow["attr_value"].'</a>';
}
}else{
# entries which are removed, do not have any link
}
$output['aaData'][] = $row;
}
# item linking
if ( !empty($aRow["fk_id_item"]) AND $show_item_links ){
if ($aRow["action"] == "removed" AND $aRow["attr_name"] == "service"){
# removed services will link to hosts service list view
$aRow['attr_value'] = '<a href="modify_item_service.php?id='.$aRow["fk_id_item"].'">'.$aRow["attr_value"].'</a>';

echo json_encode( $output );

}else{
// else we have a manual process to create JSON data
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';


while ( $aRow = mysql_fetch_array( $rResult ) )
{
# do some stuff bevore generating output

# if object name contains password, and PASSWD_DISPLAY is 0 (made in called function), do not show password
if ( stristr($aRow["attr_name"], "password") ){
$aRow["attr_value"] = show_password($aRow["attr_value"]);
}
# item linking
if ( !empty($aRow["fk_id_item"]) AND $show_item_links ){
if ($aRow["action"] == "removed" AND $aRow["attr_name"] == "service"){
# removed services will link to hosts service list view
$aRow['attr_value'] = '<a href="modify_item_service.php?id='.$aRow["fk_id_item"].'">'.$aRow["attr_value"].'</a>';
}else{
# all other entries will link to its detail view
$aRow['attr_value'] = '<a href="detail.php?id='.$aRow["fk_id_item"].'">'.$aRow["attr_value"].'</a>';
}
}else{
# all other entries will link to its detail view
$aRow['attr_value'] = '<a href="detail.php?id='.$aRow["fk_id_item"].'">'.$aRow["attr_value"].'</a>';
# entries which are removed, do not have any link
}
}else{
# entries which are removed, do not have any link

# create output (JSON)
$sOutput .= "[";
$sOutput .= '"'.addslashes($aRow['timestamp']).'",';
$sOutput .= '"'.addslashes($aRow['user_str']).'",';
$sOutput .= '"'.addslashes($aRow['action']).'",';
$sOutput .= '"'.addslashes($aRow['attr_name']).'",';
$sOutput .= '"'.addslashes($aRow['attr_value']).'",';
$sOutput .= '"'.addslashes($aRow['id_hist']).'"';
$sOutput .= "],";
}

# create output (JSON)
$sOutput .= "[";
$sOutput .= '"'.addslashes($aRow['timestamp']).'",';
$sOutput .= '"'.addslashes($aRow['user_str']).'",';
$sOutput .= '"'.addslashes($aRow['action']).'",';
$sOutput .= '"'.addslashes($aRow['attr_name']).'",';
$sOutput .= '"'.addslashes($aRow['attr_value']).'",';
$sOutput .= '"'.addslashes($aRow['id_hist']).'"';
$sOutput .= "],";

$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';
// This should fix a json problem
$sOutput = str_replace("\'", "'", $sOutput);

echo $sOutput;
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';

echo $sOutput;


function fnColumnToField( $i )
Expand All @@ -162,4 +219,4 @@ function fnColumnToField( $i )
}


?>
?>

0 comments on commit 7df549e

Please sign in to comment.