Created
February 5, 2015 19:44
-
-
Save rafaelfoster/a69559c2063cd74cc2bb to your computer and use it in GitHub Desktop.
Script PHP to UPDATE GLPI Computers with DELL warranty (get from webservice)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require("config_db.php"); | |
$url = "http://xserv.dell.com/services/assetservice.asmx?WSDL"; | |
$soap = new SoapClient($url,array('soap_version' => SOAP_1_2)); | |
if (! empty($_GET['TAG']) || ! empty($_GET['tag']) ) { | |
if ( isset($_GET['TAG']) ) | |
$tag = $_GET['TAG']; | |
else | |
$tag = $_GET['tag']; | |
$response = $soap->GetAssetInformation( | |
array( | |
"guid" => "11111111-1111-1111-1111-111111111111", | |
"applicationName" => "DellGetWarranty", | |
"serviceTags" => $tag | |
) | |
); | |
print "<pre>"; | |
print_r($response); | |
print "</pre>"; | |
exit(); | |
} | |
$sql_warrantyInformation = "SELECT warranty_date FROM glpi_infocoms WHERE items_id = %d"; | |
$updated_info = "Informacoes de garantia atualizadas em: " . date('Y-m-d H:i:s'); | |
$query_sql = "SELECT c.id, c.serial, i.comment, i.id as warranty_id, i.warranty_date, i.warranty_duration FROM glpi_computers c LEFT JOIN glpi_infocoms i ON c.id = i.items_id"; | |
//$query_condition = "c.serial = '22T9WL1'"; | |
$query_condition = "c.serial REGEXP '^.{7}$'"; | |
//print $query_sql . " WHERE " . $query_condition; | |
$result = mysql_query($query_sql . " WHERE " . $query_condition); | |
$count = 0; | |
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
// var_dump($row); | |
$computer_id = $row['id']; | |
$comment = $row['comment']; | |
$warranty_date = $row['warranty_date']; | |
$warranty_duration = $row['warranty_duration']; | |
$warranty_id = $row['warranty_id']; | |
$tag = $row['serial']; | |
$response = $soap->GetAssetInformation( | |
array( | |
"guid" => "11111111-1111-1111-1111-111111111111", | |
"applicationName" => "DellGetWarranty", | |
"serviceTags" => $tag | |
) | |
); | |
$response_entitlements = $response->GetAssetInformationResult->Asset->Entitlements; | |
if (is_array($response_entitlements->EntitlementData)) { | |
$warranty_start = $response_entitlements->EntitlementData[0]->StartDate; | |
$warranty_end = $response_entitlements->EntitlementData[0]->EndDate; | |
} else { | |
$warranty_start = $response_entitlements->EntitlementData->StartDate; | |
$warranty_end = $response_entitlements->EntitlementData->EndDate; | |
} | |
$warranty_start = split("T", $warranty_start); | |
$warranty_start = $warranty_start[0]; | |
$warranty_end = split("T", $warranty_end); | |
$warranty_end = $warranty_end[0]; | |
$diff = abs(strtotime($warranty_end) - strtotime($warranty_start)); | |
$years = floor($diff / (365*60*60*24) ); | |
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); | |
$total = $years * 12 + $months; | |
if ( ! isset($_GET['debug']) ) { | |
if ( is_null($warranty_id) ){ | |
$query = "INSERT INTO glpi_infocoms (items_id,itemtype,entities_id,warranty_date,warranty_duration,comment) values($computer_id,'Computer','14',\"$warranty_start\",\"$total\",\"$updated_info\")"; | |
$sql = mysql_query($query) or die("Insert error: $query <br>". mysql_error()); | |
} else { | |
if ( $warranty_date == $warranty_start ) continue; | |
$query = "UPDATE glpi_infocoms SET warranty_date = \"".$warranty_start."\", warranty_duration = \"$total\", comment = \"$updated_info \r\n\r\n $comment\" WHERE id = $warranty_id"; | |
$sql = mysql_query($query) or die(print "UPDATE Error: ". mysql_error()); | |
} | |
} | |
print "--------------------------------- <br>"; | |
print "TAG: $tag <br>"; | |
print "Inicio da Garantia: $warranty_start <br>"; | |
print "Fim da Garantia: $warranty_end <br>"; | |
print "Total : $total meses <br>"; | |
print "--------------------------------- <br><br>"; | |
$count++; | |
} | |
print "<br><br>Total de Items: $count"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment