Skip to content

Instantly share code, notes, and snippets.

@gnh1201
Last active February 25, 2020 10:48
Show Gist options
  • Select an option

  • Save gnh1201/ca7530938c8ebb84ec7d2f5be0e9e330 to your computer and use it in GitHub Desktop.

Select an option

Save gnh1201/ca7530938c8ebb84ec7d2f5be0e9e330 to your computer and use it in GitHub Desktop.
itsm.api.php
<?php
/**
* @file itsm.api.php
* @author Go Namhyeon <[email protected]>
* @brief ITSM service interface module
* @framework https://github.com/gnh1201/reasonableframework
*/
if(!check_function_exists("itsm_get_data")) {
function itsm_get_data($resource, $bind=array()) {
$result = false;
$config = get_config();
$itsm_key = get_value_in_array("itsm_key", $config, "");
$itsm_base_url = get_value_in_array("itsm_base_url", $config, "");
$itsm_url = sprintf("%s/api/", $itsm_base_url);
if(!empty($itsm_key)) {
if(loadHelper("webpagetool")) {
// get category of client
if($resource == "clientcategories") {
$response = get_web_page($itsm_url, "post", array(
"key" => $itsm_key,
"method" => "get",
"resource" => $resource
));
}
// get assets
$response = get_web_json($itsm_url, "post", array(
"key" => $itsm_key,
"method" => "get",
"resource" => $resource,
"filters" => $bind
));
$result = get_property_value("result", $response, false);
}
}
return $result;
}
}
if(!check_function_exists("itsm_add_data")) {
function itsm_add_data($resource, $bind) {
$status = false;
$config = get_config();
$itsm_key = get_value_in_array("itsm_key", $config, "");
$itsm_base_url = get_value_in_array("itsm_base_url", $config, "");
$itsm_url = sprintf("%s/api/", $itsm_base_url);
if(!empty($itsm_key)) {
if(loadHelper("webpagetool")) {
$response = get_web_page($itsm_url, "post", array(
"key" => $itsm_key,
"method" => "add",
"resource" => $resource,
"data" => $bind
));
$status = get_property_value("status", $response, false);
}
}
return $status;
}
}
if(!check_function_exists("itsm_edit_data")) {
function itsm_edit_data($resource, $bind) {
$status = false;
$config = get_config();
$itsm_key = get_value_in_array("itsm_key", $config, "");
$itsm_base_url = get_value_in_array("itsm_base_url", $config, "");
$itsm_url = sprintf("%s/api/", $itsm_base_url);
$assets = itsm_get_data("assets", array("id" => $bind['id']));
$asset = current($assets);
$_bind = array(
"categoryid" => $asset->categoryid,
"adminid" => $asset->adminid,
"clientid" => $asset->clientid,
"userid" => $asset->userid,
"manufacturerid" => $asset->manufacturerid,
"modelid" => $asset->modelid,
"supplierid" => $asset->supplierid,
"statusid" => $asset->statusid,
"purchase_date" => $asset->purchase_date,
"warranty_months" => $asset->warranty_months,
"tag" => $asset->tag,
"name" => $asset->name,
"serial" => $asset->serial,
"notes" => $asset->notes,
"locationid" => $asset->locationid,
"qrvalue" => $asset->qrvalue,
);
$_bind = array_merge($_bind, (array)$asset->customfields);
foreach($bind as $k=>$v) {
$_bind[$k] = $v;
}
$bind = $_bind;
if(!empty($itsm_key)) {
if(loadHelper("webpagetool")) {
$response = get_web_json($itsm_url, "post", array(
"key" => $itsm_key,
"method" => "edit",
"resource" => $resource,
"data" => $bind
));
$status = get_property_value("status", $response, false);
}
}
return $status;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment