function getExpirationsText() { $row_format = "%3s|%-30s|%-15s|%-15s|%s\r\n"; $ret = ''; $breakdown = array(); $breakdown[21] = array(array('from' => -365, 'to' => 0, 'title' => 'has expired within last year'), array('from' => 0, 'to' => 30, 'title' => 'expires within 30 days')); $breakdown[22] = $breakdown[21]; $breakdown[24] = $breakdown[21]; $attrmap = getAttrMap(); foreach ($breakdown as $attr_id => $sections) { $ret .= $attrmap[$attr_id]['name'] . "\r\n"; $ret .= "===========================================\r\n"; foreach ($sections as $section) { $count = 1; $result = scanAttrRelativeDays($attr_id, $section['from'], $section['to']); if (!count($result)) { continue; } $ret .= $section['title'] . "\r\n"; $ret .= "-----------------------------------------------------------------------------------\r\n"; $ret .= sprintf($row_format, '#', 'Name', 'Asset Tag', 'OEM S/N 1', 'Date Warranty Expires'); $ret .= "-----------------------------------------------------------------------------------\r\n"; foreach ($result as $row) { $object = spotEntity('object', $row['object_id']); $attributes = getAttrValues($object['id']); $ret .= sprintf($row_format, $count, $object['dname'], $object['asset_no'], array_key_exists(1, $attributes) ? $attributes[1]['a_value'] : '', datetimestrFromTimestamp($row['uint_value'])); $count++; } $ret .= "-----------------------------------------------------------------------------------\r\n"; } $ret .= "\r\n"; } return $ret; }
function supplementAttrMap() { assertUIntArg('attr_id'); assertUIntArg('objtype_id'); $attrMap = getAttrMap(); if ($attrMap[$_REQUEST['attr_id']]['type'] != 'dict') { $chapter_id = NULL; } else { try { assertUIntArg('chapter_no'); } catch (InvalidRequestArgException $e) { showFuncMessage(__FUNCTION__, 'ERR1', array('chapter not selected')); return; } $chapter_id = $_REQUEST['chapter_no']; } commitSupplementAttrMap($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $chapter_id); showFuncMessage(__FUNCTION__, 'OK'); }
function scanAttrRelativeDays($attr_id, $not_before_days, $not_after_days) { $attrmap = getAttrMap(); if ($attrmap[$attr_id]['type'] != 'date') { throw new InvalidArgException('attr_id', $attr_id, 'attribute cannot store dates'); } $result = usePreparedSelectBlade('SELECT uint_value, object_id FROM AttributeValue ' . 'WHERE attr_id=? and FROM_UNIXTIME(uint_value) BETWEEN ' . 'DATE_ADD(curdate(), INTERVAL ? DAY) and DATE_ADD(curdate(), INTERVAL ? DAY)', array($attr_id, $not_before_days, $not_after_days)); return $result->fetchAll(PDO::FETCH_ASSOC); }
function renderExpirations() { global $nextorder; $breakdown = array(); $breakdown[21] = array(array('from' => -365, 'to' => 0, 'class' => 'has_problems_', 'title' => 'has expired within last year'), array('from' => 0, 'to' => 30, 'class' => 'row_', 'title' => 'expires within 30 days'), array('from' => 30, 'to' => 60, 'class' => 'row_', 'title' => 'expires within 60 days'), array('from' => 60, 'to' => 90, 'class' => 'row_', 'title' => 'expires within 90 days')); $breakdown[22] = $breakdown[21]; $breakdown[24] = $breakdown[21]; $attrmap = getAttrMap(); foreach ($breakdown as $attr_id => $sections) { startPortlet($attrmap[$attr_id]['name']); foreach ($sections as $section) { $count = 1; $order = 'odd'; $result = scanAttrRelativeDays($attr_id, $section['from'], $section['to']); echo '<table align=center width=60% border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>'; echo "<caption>{$section['title']}</caption>\n"; if (!count($result)) { echo "<tr><td colspan=4>(none)</td></tr></table><br>\n"; continue; } echo '<tr valign=top><th align=center>Count</th><th align=center>Name</th>'; echo "<th align=center>Asset Tag</th><th align=center>OEM S/N 1</th><th align=center>Date Warranty <br> Expires</th></tr>\n"; foreach ($result as $row) { $date_value = datetimestrFromTimestamp($row['uint_value']); $object = spotEntity('object', $row['object_id']); $attributes = getAttrValues($object['id']); $oem_sn_1 = array_key_exists(1, $attributes) ? $attributes[1]['a_value'] : ' '; echo '<tr class=' . $section['class'] . $order . ' valign=top>'; echo "<td>{$count}</td>"; echo '<td>' . mkA($object['dname'], 'object', $object['id']) . '</td>'; echo "<td>{$object['asset_no']}</td>"; echo "<td>{$oem_sn_1}</td>"; echo "<td>{$date_value}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; $count++; } echo "</table><br>\n"; } finishPortlet(); } }
} $objects[$object_id] = $object; $objects[$object_id]['attrs'] = $attrs; } } sendAPIResponse($objects); break; // get all available object attributes // UI equivalent: /index.php?page=attrs // UI handler: renderAttributes() // get all available object attributes // UI equivalent: /index.php?page=attrs // UI handler: renderAttributes() case 'get_attributes': require_once 'inc/init.php'; sendAPIResponse(getAttrMap()); break; // get all chapters in the dictionary // UI equivalent: /index.php?page=dict // UI handler: renderDictionary() // get all chapters in the dictionary // UI equivalent: /index.php?page=dict // UI handler: renderDictionary() case 'get_dictionary': require_once 'inc/init.php'; sendAPIResponse(getChapterList()); break; // get dictionary chapter // UI equivalent: /index.php?page=chapter&chapter_no=1 // UI handler: renderChapter() // get dictionary chapter
function renderCustomReport() { # Get object list $phys_typelist = readChapter(CHAP_OBJTYPE, 'o'); $attibutes = getAttrMap(); $aTagList = getTagList(); if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['csv'])) { header('Content-type: text/csv'); header('Content-Disposition: attachment; filename=export_' . date("Ymdhis") . '.csv'); header('Pragma: no-cache'); header('Expires: 0'); $outstream = fopen("php://output", "w"); $aResult = getResult($_POST); // Get Result $_POST['name'] = validateColums($_POST); // Fix empty colums $csvDelimiter = isset($_POST['csvDelimiter']) ? $_POST['csvDelimiter'] : ','; /* Create Header */ $aCSVRow = array(); if (isset($_POST['sName']) && $_POST['sName']) { array_push($aCSVRow, "Name"); } if (isset($_POST['label'])) { array_push($aCSVRow, "Label"); } if (isset($_POST['type'])) { array_push($aCSVRow, "Type"); } if (isset($_POST['asset_no'])) { array_push($aCSVRow, "Asset Tag"); } if (isset($_POST['has_problems'])) { array_push($aCSVRow, "Has Problems"); } if (isset($_POST['comment'])) { array_push($aCSVRow, "Comment"); } if (isset($_POST['runs8021Q'])) { array_push($aCSVRow, "Runs 8021Q"); } if (isset($_POST['location'])) { array_push($aCSVRow, "Location"); } if (isset($_POST['MACs'])) { array_push($aCSVRow, "MACs"); } if (isset($_POST['IPs'])) { array_push($aCSVRow, "IPs"); } if (isset($_POST['attributeIDs'])) { foreach ($_POST['attributeIDs'] as $attributeID) { array_push($aCSVRow, $attibutes[$attributeID]['name']); } } if (isset($_POST['Tags'])) { array_push($aCSVRow, "Tags"); } if (isset($_POST['Ports'])) { array_push($aCSVRow, "Ports"); } if (isset($_POST['Containers'])) { array_push($aCSVRow, "Containers"); } if (isset($_POST['Childs'])) { array_push($aCSVRow, "Child objects"); } fputcsv($outstream, $aCSVRow, $csvDelimiter); /* Create data rows */ foreach ($aResult as $Result) { $aCSVRow = array(); if (isset($_POST['sName'])) { array_push($aCSVRow, $Result['name']); } if (isset($_POST['label'])) { array_push($aCSVRow, $Result['label']); } if (isset($_POST['type'])) { array_push($aCSVRow, $phys_typelist[$Result['objtype_id']]); } if (isset($_POST['asset_no'])) { array_push($aCSVRow, $Result['asset_no']); } if (isset($_POST['has_problems'])) { array_push($aCSVRow, $Result['has_problems']); } if (isset($_POST['comment'])) { array_push($aCSVRow, str_replace('"', "'", $Result['comment'])); } if (isset($_POST['runs8021Q'])) { array_push($aCSVRow, $Result['runs8021Q']); } if (isset($_POST['location'])) { array_push($aCSVRow, preg_replace('/<a[^>]*>(.*)<\\/a>/iU', '$1', getLocation($Result))); } if (isset($_POST['MACs'])) { $sTemp = ''; foreach (getObjectPortsAndLinks($Result['id']) as $portNumber => $aPortDetails) { if (trim($aPortDetails['l2address']) != '') { $sTemp .= $aPortDetails['l2address'] . ' '; } } array_push($aCSVRow, $sTemp); } if (isset($_POST['IPs'])) { $sTemp = ''; foreach (getObjectIPv4AllocationList($Result['id']) as $key => $aDetails) { if (function_exists('ip4_format')) { $key = ip4_format($key); } if (trim($key) != '') { $sTemp .= $key . ' '; } } foreach (getObjectIPv6AllocationList($Result['id']) as $key => $aDetails) { if (function_exists('ip6_format')) { $key = ip6_format($key); } else { $key = new IPv6Address($key); } if (trim($key) != '') { $sTemp .= $key . ' '; } } array_push($aCSVRow, $sTemp); } if (isset($_POST['attributeIDs'])) { $attributes = getAttrValues($Result['id']); foreach ($_POST['attributeIDs'] as $attributeID) { if (isset($attributes[$attributeID]['a_value'])) { array_push($aCSVRow, $attributes[$attributeID]['a_value']); } elseif ($attributes[$attributeID]['value'] != '' && $attributes[$attributeID]['type'] == 'date') { array_push($aCSVRow, date("Y-m-d", $attributes[$attributeID]['value'])); } else { array_push($aCSVRow, ''); } } } if (isset($_POST['Tags'])) { $sTemp = ''; foreach ($Result['tags'] as $aTag) { $sTemp .= $aTag['tag'] . ' '; } if (count($Result['itags']) > 0) { $sTemp .= '('; foreach ($Result['itags'] as $aTag) { $sTemp .= $aTag['tag'] . ' '; } $sTemp .= ')'; } array_push($aCSVRow, $sTemp); } if (isset($_POST['Ports'])) { $sTemp = ''; foreach ($Result['portsLinks'] as $port) { $sTemp .= $port['name'] . ': ' . $port['remote_object_name']; if (trim($port['cableid']) != '') { $sTemp .= ' Cable ID: ' . $port['cableid']; } $sTemp .= ' '; } $sTemp = trim($sTemp); array_push($aCSVRow, $sTemp); } if (isset($_POST['Containers'])) { $sTemp = ''; foreach (getObjectContainerList($Result['id']) as $key => $aDetails) { $sTemp .= trim($aDetails['container_name']) . ' '; } $sTemp = trim($sTemp); array_push($aCSVRow, $sTemp); } if (isset($_POST['Childs'])) { $sTemp = ''; foreach (getObjectChildObjectList($Result['id']) as $key => $aDetails) { $sTemp .= trim($aDetails['object_name']) . ' '; } $sTemp = trim($sTemp); array_push($aCSVRow, $sTemp); } fputcsv($outstream, $aCSVRow, $csvDelimiter); } fclose($outstream); exit(0); # Exit normally after send CSV to browser } echo '<h2>Custom report</h2><ul>'; // Load stylesheet and jquery scripts addCSS('css/extensions/style.css'); addJS('js/extensions/saveFormValues.js'); addJS('js/extensions/jquery-latest.js'); addJS('js/extensions/jquery.tablesorter.js'); addJS('js/extensions/picnet.table.filter.min.js'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { echo '<a href="#" class="show_hide">Show/hide search form</a><br/><br/>'; } echo '<div class="searchForm">'; echo '<form method="post" name="searchForm">'; echo '<table class="searchTable"> <tr> <th>Object Type</th> <th>Common Values</th> <th>Attributes</th> <th>Tags</th> <th>Misc</th> </tr> <tr>'; echo '<td valign="top"> <table class="searchTable">'; $i = 0; foreach ($phys_typelist as $objectTypeID => $sName) { if ($i % 2) { echo '<tr class="odd">'; } else { echo '<tr>'; } echo ' <td> <input type="checkbox" name="objectIDs[]" value="' . $objectTypeID . '"'; if (isset($_POST['objectIDs']) && in_array($objectTypeID, $_POST['objectIDs'])) { echo ' checked="checked"'; } echo ' > ' . $sName . ' </td> </tr>'; $i++; } echo ' </table> </td>'; echo '<td valign="top"> <table class="searchTable"> <tr><td><input type="checkbox" name="sName" value="1" '; if (isset($_POST['sName'])) { echo ' checked="checked"'; } echo '> Name</td></tr> <tr class="odd"><td><input type="checkbox" name="label" value="1" '; if (isset($_POST['label'])) { echo ' checked="checked"'; } echo '> Label</td></tr> <tr><td><input type="checkbox" name="type" value="1" '; if (isset($_POST['type'])) { echo ' checked="checked"'; } echo '> Type</td></tr> <tr class="odd"><td><input type="checkbox" name="asset_no" value="1" '; if (isset($_POST['asset_no'])) { echo ' checked="checked"'; } echo '> Asset Tag</td></tr> <tr><td><input type="checkbox" name="location" value="1" '; if (isset($_POST['location'])) { echo ' checked="checked"'; } echo '> Location</td></tr> <tr class="odd"><td><input type="checkbox" name="has_problems" value="1" '; if (isset($_POST['has_problems'])) { echo ' checked="checked"'; } echo '> Has Problems</td></tr> <tr><td><input type="checkbox" name="comment" value="1" '; if (isset($_POST['comment'])) { echo ' checked="checked"'; } echo '> Comment</td></tr> <tr class="odd"><td><input type="checkbox" name="runs8021Q" value="1" '; if (isset($_POST['runs8021Q'])) { echo ' checked="checked"'; } echo '> Runs 8021Q</td></tr> <tr><td><input type="checkbox" name="MACs" value="1" '; if (isset($_POST['MACs'])) { echo ' checked="checked"'; } echo '> MACs</td></tr> <tr class="odd"><td><input type="checkbox" name="IPs" value="1" '; if (isset($_POST['IPs'])) { echo ' checked="checked"'; } echo '> IPs</td></tr> <tr><td><input type="checkbox" name="Tags" value="1" '; if (isset($_POST['Tags'])) { echo ' checked="checked"'; } echo '> Tags</td></tr> <tr class="odd"><td><input type="checkbox" name="Ports" value="1" '; if (isset($_POST['Ports'])) { echo ' checked="checked"'; } echo '> Ports</td></tr> <tr><td><input type="checkbox" name="Containers" value="1" '; if (isset($_POST['Containers'])) { echo ' checked="checked"'; } echo '> Containers</td></tr> <tr class="odd"><td><input type="checkbox" name="Childs" value="1" '; if (isset($_POST['Childs'])) { echo ' checked="checked"'; } echo '> Child objects</td></tr> </table> </td>'; echo '<td valign="top"> <table class="searchTable">'; $i = 0; foreach ($attibutes as $attributeID => $aRow) { if ($i % 2) { echo '<tr class="odd">'; } else { echo '<tr>'; } echo ' <td> <input type="checkbox" name="attributeIDs[]" value="' . $attributeID . '"'; if (isset($_POST['attributeIDs']) && in_array($attributeID, $_POST['attributeIDs'])) { echo ' checked="checked"'; } echo '> ' . $aRow['name'] . ' </td> </tr>'; $i++; } echo ' </table> </td>'; echo '<td valign="top"> <table class="searchTable">'; $i = 0; foreach ($aTagList as $aTag) { echo '<tr ' . ($i % 2 ? 'class="odd"' : '') . '> <td> <input type="checkbox" name="tag[' . $aTag['id'] . ']" value="1" ' . (isset($_POST['tag'][$aTag['id']]) ? 'checked="checked" ' : '') . '> ' . $aTag['tag'] . ' </td> </tr>'; $i++; } if (count($aTagList) < 1) { echo '<tr><td><i>No Tags available</i></td></tr>'; } echo ' </table> </td>'; echo '<td valign="top"> <table class="searchTable"> <tr><td><input type="checkbox" name="csv" value="1"> CSV Export</td></tr> <tr><td><input type="text" name="csvDelimiter" value="," size="1"> CSV Delimiter</td></tr> <tr class="odd"><td>Name Filter: <i>(Regular Expression)</i></td></tr> <tr><td><input type="text" name="name_preg" value="'; if (isset($_POST['name_preg'])) { echo $_POST['name_preg']; } echo '" style="height: 11pt;"></td></tr> <tr class="odd"><td>Asset Tag Filter: <i>(Regular Expression)</i></td></tr> <tr><td><input type="text" name="tag_preg" value="'; if (isset($_POST['tag_preg'])) { echo $_POST['tag_preg']; } echo '" style="height: 11pt;"></td></tr> <tr class="odd"><td>Comment Filter: <i>(Regular Expression)</i></td></tr> <tr><td><input type="text" name="comment_preg" value="'; if (isset($_POST['comment_preg'])) { echo $_POST['comment_preg']; } echo '" style="height: 11pt;"></td></tr> <tr class="odd"><td> </td></tr> <tr> <td> Save: <input id="nameQuery" type="text" name="nameQuery" value="" style="height: 11pt; width:155px"/> <input type="button" value=" Ok " onclick="saveQuery();"> <br/> Load:<br/> <span id="loadButtons"></span> <script type="text/javascript"> loadButtons(); </script> </td> </tr> <tr class="odd"><td> </td></tr> <tr><td align="right"><input type="submit" value=" Search "></td></tr> </table> </td> </tr> </table>'; echo '</form>'; echo '</div>'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $aResult = getResult($_POST); // Get Result $_POST['sName'] = validateColums($_POST); // Fix empty colums if (count($aResult) > 0) { echo '<table id="customTable" class="tablesorter"> <thead> <tr>'; if (isset($_POST['sName']) && $_POST['sName']) { echo '<th>Name</th>'; } if (isset($_POST['label'])) { echo '<th>Label</th>'; } if (isset($_POST['type'])) { echo '<th>Type</th>'; } if (isset($_POST['asset_no'])) { echo '<th>Asset Tag</th>'; } if (isset($_POST['has_problems'])) { echo '<th>Has Problems</th>'; } if (isset($_POST['comment'])) { echo '<th>Comment</th>'; } if (isset($_POST['runs8021Q'])) { echo '<th>Runs 8021Q</th>'; } if (isset($_POST['location'])) { echo '<th>Location</th>'; } if (isset($_POST['MACs'])) { echo '<th>MACs</th>'; } if (isset($_POST['IPs'])) { echo '<th>IPs</th>'; } if (isset($_POST['attributeIDs'])) { foreach ($_POST['attributeIDs'] as $attributeID) { echo '<th>' . $attibutes[$attributeID]['name'] . '</th>'; } } if (isset($_POST['Tags'])) { echo '<th>Tags</th>'; } if (isset($_POST['Ports'])) { echo '<th>Ports</th>'; } if (isset($_POST['Containers'])) { echo '<th>Containers</th>'; } if (isset($_POST['Childs'])) { echo '<th>Child objects</th>'; } echo ' </tr> </thead> <tbody>'; foreach ($aResult as $Result) { echo '<tr>'; if (isset($_POST['sName'])) { echo '<td> <span class="object_' . str_replace('$', '', $Result['atags'][1]['tag']) . '">'; if (isset($Result['name'])) { echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $Result['id'])) . '">' . $Result['name'] . '</a>'; } else { echo ' '; } echo ' </span> </td>'; } if (isset($_POST['label'])) { echo '<td>'; if (isset($Result['label'])) { echo $Result['label']; } else { echo ' '; } echo '</td>'; } if (isset($_POST['type'])) { echo '<td>'; if (isset($Result['objtype_id'])) { echo $phys_typelist[$Result['objtype_id']]; } else { echo ' '; } echo '</td>'; } if (isset($_POST['asset_no'])) { echo '<td>'; if (isset($Result['asset_no'])) { echo $Result['asset_no']; } else { echo ' '; } echo '</td>'; } if (isset($_POST['has_problems'])) { echo '<td>'; if (isset($Result['has_problems'])) { echo $Result['has_problems']; } else { echo ' '; } echo '</td>'; } if (isset($_POST['comment'])) { echo '<td>'; if (isset($Result['comment'])) { echo makeLinksInText($Result['comment']); } else { echo ' '; } echo '</td>'; } if (isset($_POST['runs8021Q'])) { echo '<td>'; if (isset($Result['runs8021Q'])) { echo $Result['runs8021Q']; } else { echo ' '; } echo '</td>'; } if (isset($_POST['location'])) { echo '<td>'; echo getLocation($Result); echo '</td>'; } if (isset($_POST['MACs'])) { echo '<td>'; foreach (getObjectPortsAndLinks($Result['id']) as $portNumber => $aPortDetails) { if (trim($aPortDetails['l2address']) != '') { echo $aPortDetails['l2address'] . '<br/>'; } } echo '</td>'; } if (isset($_POST['IPs'])) { echo '<td>'; foreach (getObjectIPv4AllocationList($Result['id']) as $key => $aDetails) { if (function_exists('ip4_format')) { $key = ip4_format($key); } if (trim($key) != '') { echo $key . '<br/>'; } } foreach (getObjectIPv6AllocationList($Result['id']) as $key => $aDetails) { if (function_exists('ip6_format')) { $key = ip6_format($key); } else { $key = new IPv6Address($key); } if (trim($key) != '') { echo $key . '<br/>'; } } echo '</td>'; } if (isset($_POST['attributeIDs'])) { $attributes = getAttrValues($Result['id']); foreach ($_POST['attributeIDs'] as $attributeID) { echo '<td>'; if (isset($attributes[$attributeID]['a_value']) && $attributes[$attributeID]['a_value'] != '') { echo $attributes[$attributeID]['a_value']; } elseif ($attributes[$attributeID]['value'] != '' && $attributes[$attributeID]['type'] == 'date') { echo date("Y-m-d", $attributes[$attributeID]['value']); } else { echo ' '; } } } if (isset($_POST['Tags'])) { echo '<td>'; foreach ($Result['tags'] as $aTag) { echo '<a href="' . makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cft[]' => $aTag['id'])) . '">' . $aTag['tag'] . '</a> '; } if (count($Result['itags']) > 0) { echo '('; foreach ($Result['itags'] as $aTag) { echo '<a href="' . makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cft[]' => $aTag['id'])) . '">' . $aTag['tag'] . '</a> '; } echo ')'; } echo '</td>'; } if (isset($_POST['Ports'])) { echo '<td>'; foreach ($Result['portsLinks'] as $port) { echo $port['name'] . ': '; if ($port['remote_object_name'] != 'unknown') { echo formatPortLink($port['remote_object_id'], $port['remote_object_name'], $port['remote_id'], NULL); } else { echo $port['remote_object_name']; } if (trim($port['cableid']) != '') { echo ' Cable ID: ' . $port['cableid']; } echo '<br/>'; } echo '</td>'; } if (isset($_POST['Containers'])) { echo '<td>'; foreach (getObjectContainerList($Result['id']) as $key => $aDetails) { echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $key)) . '">' . $aDetails['container_name'] . '</a><br/>'; } echo '</td>'; } if (isset($_POST['Childs'])) { echo '<td>'; foreach (getObjectChildObjectList($Result['id']) as $key => $aDetails) { echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $key)) . '">' . $aDetails['object_name'] . '</a><br/>'; } echo '</td>'; } echo '</tr>'; } echo ' </tbody> </table> <script type="text/javascript">$(".searchForm").hide();</script>'; } else { echo '<br/><br/><div align="center" style="font-size:10pt;"><i>No items found !!!</i></div><br/>'; } echo '<script type="text/javascript"> $(document).ready(function() { $.tablesorter.defaults.widgets = ["zebra"]; $("#customTable").tablesorter( { headers: { }, sortList: [[0,0]] } ); $("#customTable").tableFilter(); $(".show_hide").show(); $(".show_hide").click(function(){ $(".searchForm").slideToggle(\'slow\'); }); } ); </script>'; } }
function fetchNetworkRowsByAttr($attribute_id, $attribute_value, $use_key = FALSE, $dont_filter = FALSE) { global $netobject_type_id, $SQLSchema; // get attribute type static $map; if (!isset($map)) { $map = getAttrMap(); } if (!array_key_exists($attribute_id, $map)) { throw new InvalidArgException('attribute_id', $attribute_id, "No such attribute"); } $attribute = $map[$attribute_id]; // get realms $realms = array(); foreach ($attribute['application'] as $application) { foreach ($netobject_type_id as $realm => $type) { if ($application['objtype_id'] == $type) { $realms[] = $realm; } } } $join_side = $dont_filter && $attribute_value !== NULL ? 'INNER' : 'LEFT'; $join = ''; $field = ''; switch ($attribute['type']) { case 'string': $field = 'AV.string_value'; break; case 'uint': $field = 'AV.uint_value'; break; case 'float': $field = 'AV.float_value'; break; case 'date': $field = 'AV.uint_value'; break; case 'dict': if ($use_key) { $field = 'AV.uint_value'; } else { $join = 'LEFT JOIN Dictionary D ON D.dict_key = AV.uint_value'; $field = 'D.dict_value'; } break; default: throw new RackTablesError(); } $subqueries = array(); $params = array(); foreach (array('ipv4net' => 'AttributeValue_IPv4', 'ipv6net' => 'AttributeValue_IPv6') as $realm => $table) { if (in_array($realm, $realms)) { $main_table = $SQLSchema[$realm]['table']; $subquery = "\nSELECT\n MT.id as net_id,\n MT.ip,\n MT.mask,\n ? as realm,\n {$field} as attr_value\nFROM\n `{$main_table}` MT\n {$join_side} JOIN `{$table}` AV ON MT.id = AV.net_id AND AV.attr_id = ?\n {$join}\n"; $params[] = $realm; $params[] = $attribute_id; if (!$dont_filter) { if (isset($attribute_value)) { $subquery .= " WHERE {$field} = ?"; $params[] = $attribute_value; } else { $subquery .= " WHERE {$field} IS NULL"; } } $subqueries[] = $subquery; } } $query = implode(' UNION ', $subqueries); $result = usePreparedSelectBlade($query, $params); return $result->fetchAll(PDO::FETCH_ASSOC); }
function getObjectTypeChangeOptions($object_id) { $map = getAttrMap(); $used = array(); $ret = array(); foreach (getAttrValues($object_id) as $attr) { if (!array_key_exists($attr['id'], $map)) { return array(); } // inconsistent current data if ($attr['value'] != '') { $used[] = $attr; } } foreach (readChapter(CHAP_OBJTYPE, 'o') as $test_id => $text) { foreach ($used as $attr) { $app = $map[$attr['id']]['application']; if (NULL === ($appidx = scanArrayForItem($app, 'objtype_id', $test_id)) or $attr['type'] == 'dict' and $attr['chapter_id'] != $app[$appidx]['chapter_no']) { continue 2; } // next type ID } $ret[$test_id] = $text; } return $ret; }
function renderChaptersEditor() { function printNewItemTR() { printOpFormIntro('add'); echo '<tr><td>'; printImageHREF('create', 'Add new', TRUE); echo "</td><td><input type=text name=chapter_name></td><td> </td><td>"; printImageHREF('create', 'Add new', TRUE); echo '</td></tr></form>'; } $dict = getChapterList(); foreach (array_keys($dict) as $chapter_no) { $dict[$chapter_no]['mapped'] = FALSE; } foreach (getAttrMap() as $attrinfo) { if ($attrinfo['type'] == 'dict') { foreach ($attrinfo['application'] as $app) { $dict[$app['chapter_no']]['mapped'] = TRUE; } } } echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n"; echo '<tr><th> </th><th>Chapter name</th><th>Words</th><th> </th></tr>'; if (getConfigVar('ADDNEW_AT_TOP') == 'yes') { printNewItemTR(); } foreach ($dict as $chapter_id => $chapter) { $wordcount = $chapter['wordc']; $sticky = $chapter['sticky'] == 'yes'; printOpFormIntro('upd', array('chapter_no' => $chapter_id)); echo '<tr>'; echo '<td>'; if ($sticky) { printImageHREF('nodestroy', 'system chapter'); } elseif ($wordcount > 0) { printImageHREF('nodestroy', 'contains ' . $wordcount . ' word(s)'); } elseif ($chapter['mapped']) { printImageHREF('nodestroy', 'used in attribute map'); } else { echo getOpLink(array('op' => 'del', 'chapter_no' => $chapter_id), '', 'destroy', 'Remove chapter'); } echo '</td>'; echo "<td><input type=text name=chapter_name value='{$chapter['name']}'" . ($sticky ? ' disabled' : '') . "></td>"; echo "<td class=tdleft>{$wordcount}</td><td>"; if ($sticky) { echo ' '; } else { printImageHREF('save', 'Save changes', TRUE); } echo '</td></tr>'; echo '</form>'; } if (getConfigVar('ADDNEW_AT_TOP') != 'yes') { printNewItemTR(); } echo "</table>\n"; }