4 * This file is a library of computational functions for RackTables.
9 $loclist[1] = 'interior';
11 $loclist['front'] = 0;
12 $loclist['interior'] = 1;
14 $template[0] = array (TRUE, TRUE, TRUE);
15 $template[1] = array (TRUE, TRUE, FALSE);
16 $template[2] = array (FALSE, TRUE, TRUE);
17 $template[3] = array (TRUE, FALSE, FALSE);
18 $template[4] = array (FALSE, TRUE, FALSE);
19 $template[5] = array (FALSE, FALSE, TRUE);
20 $templateWidth[0] = 3;
21 $templateWidth[1] = 2;
22 $templateWidth[2] = 2;
23 $templateWidth[3] = 1;
24 $templateWidth[4] = 1;
25 $templateWidth[5] = 1;
27 // Objects of some types should be explicitly shown as
28 // anonymous (labelless). This function is a single place where the
29 // decision about displayed name is made.
30 function displayedName ($objectData)
32 if ($objectData['name'] != '')
33 return $objectData['name'];
34 elseif (in_array ($objectData['objtype_id'], explode (',', getConfigVar ('NAMEFUL_OBJTYPES'))))
35 return "ANONYMOUS " . $objectData['objtype_name'];
37 return "[${objectData['objtype_name']}]";
40 // This function finds height of solid rectangle of atoms, which are all
41 // assigned to the same object. Rectangle base is defined by specified
43 function rectHeight ($rackData, $startRow, $template_idx)
46 // The first met object_id is used to match all the folowing IDs.
51 for ($locidx = 0; $locidx < 3; $locidx++
)
53 // At least one value in template is TRUE, but the following block
54 // can meet 'skipped' atoms. Let's ensure we have something after processing
56 if ($template[$template_idx][$locidx])
58 if (isset ($rackData[$startRow - $height][$locidx]['skipped']))
60 if (isset ($rackData[$startRow - $height][$locidx]['rowspan']))
62 if (isset ($rackData[$startRow - $height][$locidx]['colspan']))
64 if ($rackData[$startRow - $height][$locidx]['state'] != 'T')
67 $object_id = $rackData[$startRow - $height][$locidx]['object_id'];
68 if ($object_id != $rackData[$startRow - $height][$locidx]['object_id'])
72 // If the first row can't offer anything, bail out.
73 if ($height == 0 and $object_id == 0)
77 while ($startRow - $height > 0);
78 # echo "for startRow==${startRow} and template==(" . ($template[$template_idx][0] ? 'T' : 'F');
79 # echo ', ' . ($template[$template_idx][1] ? 'T' : 'F') . ', ' . ($template[$template_idx][2] ? 'T' : 'F');
80 # echo ") height==${height}<br>\n";
84 // This function marks atoms to be avoided by rectHeight() and assigns rowspan/colspan
86 function markSpan (&$rackData, $startRow, $maxheight, $template_idx)
88 global $template, $templateWidth;
90 for ($height = 0; $height < $maxheight; $height++
)
92 for ($locidx = 0; $locidx < 3; $locidx++
)
94 if ($template[$template_idx][$locidx])
96 // Add colspan/rowspan to the first row met and mark the following ones to skip.
97 // Explicitly show even single-cell spanned atoms, because rectHeight()
98 // is expeciting this data for correct calculation.
100 $rackData[$startRow - $height][$locidx]['skipped'] = TRUE;
103 $colspan = $templateWidth[$template_idx];
105 $rackData[$startRow - $height][$locidx]['colspan'] = $colspan;
107 $rackData[$startRow - $height][$locidx]['rowspan'] = $maxheight;
115 // This function sets rowspan/solspan/skipped atom attributes for renderRack()
116 // What we actually have to do is to find _all_ possible rectangles for each unit
117 // and then select the widest of those with the maximal square.
118 function markAllSpans (&$rackData = NULL)
120 if ($rackData == NULL)
122 showError ('Invalid rackData', __FUNCTION__
);
125 for ($i = $rackData['height']; $i > 0; $i--)
126 while (markBestSpan ($rackData, $i));
129 // Calculate height of 6 possible span templates (array is presorted by width
130 // descending) and mark the best (if any).
131 function markBestSpan (&$rackData, $i)
133 global $template, $templateWidth;
134 for ($j = 0; $j < 6; $j++
)
136 $height[$j] = rectHeight ($rackData, $i, $j);
137 $square[$j] = $height[$j] * $templateWidth[$j];
139 // find the widest rectangle of those with maximal height
140 $maxsquare = max ($square);
143 $best_template_index = 0;
144 for ($j = 0; $j < 6; $j++
)
145 if ($square[$j] == $maxsquare)
147 $best_template_index = $j;
148 $bestheight = $height[$j];
151 // distribute span marks
152 markSpan ($rackData, $i, $bestheight, $best_template_index);
156 function delRow ($row_id = 0)
160 showError ('Not all required args are present.', __FUNCTION__
);
163 if (!isset ($_REQUEST['confirmed']) ||
$_REQUEST['confirmed'] != 'true')
165 echo "Press <a href='?op=del_row&row_id=${row_id}&confirmed=true'>here</a> to confirm rack row deletion.";
169 echo 'Deleting rack row information: ';
170 $result = $dbxlink->query ("update RackRow set deleted = 'yes' where id=${row_id} limit 1");
171 if ($result->rowCount() != 1)
173 showError ('Marked ' . $result.rowCount() . ' rows as deleted, but expected 1', __FUNCTION__
);
177 recordHistory ('RackRow', "id = ${row_id}");
178 echo "Information was deleted. You may return to <a href='?op=list_rows&editmode=on'>rack row list</a>.";
181 function delRack ($rack_id = 0)
185 showError ('Not all required args are present.', __FUNCTION__
);
188 if (!isset ($_REQUEST['confirmed']) ||
$_REQUEST['confirmed'] != 'true')
190 echo "Press <a href='?op=del_rack&rack_id=${rack_id}&confirmed=true'>here</a> to confirm rack deletion.";
194 echo 'Deleting rack information: ';
195 $result = $dbxlink->query ("update Rack set deleted = 'yes' where id=${rack_id} limit 1");
196 if ($result->rowCount() != 1)
198 showError ('Marked ' . $result.rowCount() . ' rows as deleted, but expected 1', __FUNCTION__
);
202 recordHistory ('Rack', "id = ${rack_id}");
203 echo "Information was deleted. You may return to <a href='?op=list_racks&editmode=on'>rack list</a>.";
206 function delObject ($object_id = 0)
210 showError ('Not all required args are present.', __FUNCTION__
);
213 if (!isset ($_REQUEST['confirmed']) ||
$_REQUEST['confirmed'] != 'true')
215 echo "Press <a href='?op=del_object&object_id=${object_id}&confirmed=true'>here</a> to confirm object deletion.";
219 echo 'Deleting object information: ';
220 $result = $dbxlink->query ("update RackObject set deleted = 'yes' where id=${object_id} limit 1");
221 if ($result->rowCount() != 1)
223 showError ('Marked ' . $result.rowCount() . ' rows as deleted, but expected 1', __FUNCTION__
);
227 recordHistory ('RackObject', "id = ${object_id}");
228 echo "Information was deleted. You may return to <a href='?op=list_objects&editmode=on'>object list</a>.";
231 // We can mount 'F' atoms and unmount our own 'T' atoms.
232 function applyObjectMountMask (&$rackData, $object_id)
234 for ($unit_no = $rackData['height']; $unit_no > 0; $unit_no--)
235 for ($locidx = 0; $locidx < 3; $locidx++
)
236 switch ($rackData[$unit_no][$locidx]['state'])
239 $rackData[$unit_no][$locidx]['enabled'] = TRUE;
242 $rackData[$unit_no][$locidx]['enabled'] = ($rackData[$unit_no][$locidx]['object_id'] == $object_id);
245 $rackData[$unit_no][$locidx]['enabled'] = FALSE;
249 // Design change means transition between 'F' and 'A' and back.
250 function applyRackDesignMask (&$rackData)
252 for ($unit_no = $rackData['height']; $unit_no > 0; $unit_no--)
253 for ($locidx = 0; $locidx < 3; $locidx++
)
254 switch ($rackData[$unit_no][$locidx]['state'])
258 $rackData[$unit_no][$locidx]['enabled'] = TRUE;
261 $rackData[$unit_no][$locidx]['enabled'] = FALSE;
265 // The same for 'F' and 'U'.
266 function applyRackProblemMask (&$rackData)
268 for ($unit_no = $rackData['height']; $unit_no > 0; $unit_no--)
269 for ($locidx = 0; $locidx < 3; $locidx++
)
270 switch ($rackData[$unit_no][$locidx]['state'])
274 $rackData[$unit_no][$locidx]['enabled'] = TRUE;
277 $rackData[$unit_no][$locidx]['enabled'] = FALSE;
281 // This mask should allow toggling 'T' and 'W' on object's rackspace.
282 function applyObjectProblemMask (&$rackData)
284 for ($unit_no = $rackData['height']; $unit_no > 0; $unit_no--)
285 for ($locidx = 0; $locidx < 3; $locidx++
)
286 switch ($rackData[$unit_no][$locidx]['state'])
290 $rackData[$unit_no][$locidx]['enabled'] = ($rackData[$unit_no][$locidx]['object_id'] == $object_id);
293 $rackData[$unit_no][$locidx]['enabled'] = FALSE;
297 // This function highlights specified object (and removes previous highlight).
298 function highlightObject (&$rackData, $object_id)
300 for ($unit_no = $rackData['height']; $unit_no > 0; $unit_no--)
301 for ($locidx = 0; $locidx < 3; $locidx++
)
304 $rackData[$unit_no][$locidx]['state'] == 'T' and
305 $rackData[$unit_no][$locidx]['object_id'] == $object_id
307 $rackData[$unit_no][$locidx]['hl'] = 'h';
309 unset ($rackData[$unit_no][$locidx]['hl']);
312 // This function marks atoms to selected or not depending on their current state.
313 function markupAtomGrid (&$data, $checked_state)
315 for ($unit_no = $data['height']; $unit_no > 0; $unit_no--)
316 for ($locidx = 0; $locidx < 3; $locidx++
)
318 if (!($data[$unit_no][$locidx]['enabled'] === TRUE))
320 if ($data[$unit_no][$locidx]['state'] == $checked_state)
321 $data[$unit_no][$locidx]['checked'] = ' checked';
323 $data[$unit_no][$locidx]['checked'] = '';
327 // This function is almost a clone of processGridForm(), but doesn't save anything to database
328 // Return value is the changed rack data.
329 // Here we assume that correct filter has already been applied, so we just
330 // set or unset checkbox inputs w/o changing atom state.
331 function mergeGridFormToRack (&$rackData)
333 $rack_id = $rackData['id'];
334 for ($unit_no = $rackData['height']; $unit_no > 0; $unit_no--)
335 for ($locidx = 0; $locidx < 3; $locidx++
)
337 if ($rackData[$unit_no][$locidx]['enabled'] != TRUE)
339 $inputname = "atom_${rack_id}_${unit_no}_${locidx}";
340 if (isset ($_REQUEST[$inputname]) and $_REQUEST[$inputname] == 'on')
341 $rackData[$unit_no][$locidx]['checked'] = ' checked';
343 $rackData[$unit_no][$locidx]['checked'] = '';
347 function binMaskFromDec ($maskL)
350 for ($i=0; $i<$maskL; $i++
)
355 for ($i=$maskL; $i<32; $i++
)
362 function binInvMaskFromDec ($maskL)
365 for ($i=0; $i<$maskL; $i++
)
369 for ($i=$maskL; $i<32; $i++
)
377 function addRange ($range='', $name='', $is_bcast = FALSE, $taglist = array())
379 // $range is in x.x.x.x/x format, split into ip/mask vars
380 $rangeArray = explode('/', $range);
381 if (count ($rangeArray) != 2)
382 return "Invalid IP subnet '${range}'";
383 $ip = $rangeArray[0];
384 $mask = $rangeArray[1];
386 if (empty ($ip) or empty ($mask))
387 return "Invalid IP subnet '${range}'";
389 $maskL = ip2long($mask);
390 if ($ipL == -1 ||
$ipL === FALSE)
391 return 'Bad ip address';
392 if ($mask < 32 && $mask > 0)
396 $maskB = decbin($maskL);
397 if (strlen($maskB)!=32)
401 foreach( str_split ($maskB) as $digit)
414 $binmask = binMaskFromDec($maskL);
415 $ipL = $ipL & $binmask;
419 "id, ip, mask, name ".
423 $result = useSelectBlade ($query);
425 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
427 $otherip = $row['ip'];
428 $othermask = binMaskFromDec($row['mask']);
429 // echo "checking $otherip & $othermask ".($otherip & $othermask)." == $ipL & $othermask ".($ipL & $othermask)." ".decbin($otherip)." ".decbin($othermask)." ".decbin($otherip & $othermask)." ".decbin($ipL)." ".decbin($othermask)." ".decbin($ipL & $othermask)."\n";
430 // echo "checking $otherip & $binmask ".($otherip & $binmask)." == $ipL & $binmask ".($ipL & $binmask)." ".decbin($otherip)." ".decbin($binmask)." ".decbin($otherip & $binmask)." ".decbin($ipL)." ".decbin($binmask)." ".decbin($ipL & $binmask)."\n";
433 if (($otherip & $othermask) == ($ipL & $othermask))
434 return "This subnet intersects with ".long2ip($row['ip'])."/${row['mask']}";
435 if (($otherip & $binmask) == ($ipL & $binmask))
436 return "This subnet intersects with ".long2ip($row['ip'])."/${row['mask']}";
438 $result->closeCursor();
440 $result = useInsertBlade
445 'ip' => sprintf ('%u', $ipL),
446 'mask' => "'${maskL}'",
447 'name' => "'${name}'"
451 if ($is_bcast and $maskL < 31)
453 $network_addr = long2ip ($ipL);
454 $broadcast_addr = long2ip ($ipL |
binInvMaskFromDec ($maskL));
455 updateAddress ($network_addr, 'network', 'yes');
456 updateAddress ($broadcast_addr, 'broadcast', 'yes');
458 if (!count ($taglist))
460 if (($result = useSelectBlade ('select last_insert_id()')) == NULL)
461 return 'Query #3 failed in ' . __FUNCTION__
;
462 $row = $result->fetch (PDO
::FETCH_NUM
);
464 $result->closeCursor();
467 foreach ($taglist as $tag_id)
473 'target_realm' => "'ipv4net'",
474 'target_id' => $netid,
482 return "Experienced ${errcount} errors adding tags for the network";
485 function getIPRange ($id = 0)
490 "id as IPRanges_id, ".
491 "INET_NTOA(ip) as IPRanges_ip, ".
492 "mask as IPRanges_mask, ".
493 "name as IPRanges_name ".
496 $result = useSelectBlade ($query);
498 $row = $result->fetch (PDO
::FETCH_ASSOC
);
501 $ret['id'] = $row['IPRanges_id'];
502 $ret['ip'] = $row['IPRanges_ip'];
503 $ret['ip_bin'] = ip2long ($row['IPRanges_ip']);
504 $ret['mask_bin'] = binMaskFromDec($row['IPRanges_mask']);
505 $ret['mask_bin_inv'] = binInvMaskFromDec($row['IPRanges_mask']);
506 $ret['name'] = $row['IPRanges_name'];
507 $ret['mask'] = $row['IPRanges_mask'];
508 $ret['addrlist'] = array();
509 $result->closeCursor();
511 // We risk losing some significant bits in an unsigned 32bit integer,
512 // unless it is converted to a string.
513 $db_first = "'" . sprintf ('%u', 0x00000000 +
$ret['ip_bin'] & $ret['mask_bin']) . "'";
514 $db_last = "'" . sprintf ('%u', 0x00000000 +
$ret['ip_bin'] |
($ret['mask_bin_inv'])) . "'";
516 // Don't try to build up the whole structure in a single pass. Request
517 // the list of user comments and reservations and merge allocations in
518 // at a latter point.
520 "select INET_NTOA(ip) as ip, name, reserved from IPAddress " .
521 "where ip between ${db_first} and ${db_last} " .
522 "and (reserved = 'yes' or name != '')";
523 $result = $dbxlink->query ($query);
524 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
526 $ip_bin = ip2long ($row['ip']);
527 $ret['addrlist'][$ip_bin] = $row;
529 foreach (array ('ip', 'name', 'reserved') as $cname)
530 $tmp[$cname] = $row[$cname];
531 $tmp['references'] = array();
532 $tmp['lbrefs'] = array();
533 $tmp['rsrefs'] = array();
534 $ret['addrlist'][$ip_bin] = $tmp;
536 $result->closeCursor();
540 "select INET_NTOA(ipb.ip) as ip, ro.id as object_id, " .
541 "ro.name as object_name, ipb.name, ipb.type, objtype_id, " .
542 "dict_value as objtype_name from " .
543 "IPBonds as ipb inner join RackObject as ro on ipb.object_id = ro.id " .
544 "left join Dictionary on objtype_id=dict_key natural join Chapter " .
545 "where ip between ${db_first} and ${db_last} " .
546 "and chapter_name = 'RackObjectType'" .
547 "order by ipb.type, object_name";
548 $result = useSelectBlade ($query);
549 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
551 $ip_bin = ip2long ($row['ip']);
552 if (!isset ($ret['addrlist'][$ip_bin]))
554 $ret['addrlist'][$ip_bin] = array();
555 $ret['addrlist'][$ip_bin]['ip'] = $row['ip'];
556 $ret['addrlist'][$ip_bin]['name'] = '';
557 $ret['addrlist'][$ip_bin]['reserved'] = 'no';
558 $ret['addrlist'][$ip_bin]['references'] = array();
559 $ret['addrlist'][$ip_bin]['lbrefs'] = array();
560 $ret['addrlist'][$ip_bin]['rsrefs'] = array();
563 foreach (array ('object_id', 'type', 'name') as $cname)
564 $tmp[$cname] = $row[$cname];
565 $quasiobject['name'] = $row['object_name'];
566 $quasiobject['objtype_id'] = $row['objtype_id'];
567 $quasiobject['objtype_name'] = $row['objtype_name'];
568 $tmp['object_name'] = displayedName ($quasiobject);
569 $ret['addrlist'][$ip_bin]['references'][] = $tmp;
571 $result->closeCursor();
574 $query = "select vs_id, inet_ntoa(vip) as ip, vport, proto, " .
575 "object_id, objtype_id, ro.name, dict_value as objtype_name from " .
576 "IPVirtualService as vs inner join IPLoadBalancer as lb on vs.id = lb.vs_id " .
577 "inner join RackObject as ro on lb.object_id = ro.id " .
578 "left join Dictionary on objtype_id=dict_key " .
579 "natural join Chapter " .
580 "where vip between ${db_first} and ${db_last} " .
581 "and chapter_name = 'RackObjectType'" .
582 "order by vport, proto, ro.name, object_id";
583 $result = useSelectBlade ($query);
584 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
586 $ip_bin = ip2long ($row['ip']);
587 if (!isset ($ret['addrlist'][$ip_bin]))
589 $ret['addrlist'][$ip_bin] = array();
590 $ret['addrlist'][$ip_bin]['ip'] = $row['ip'];
591 $ret['addrlist'][$ip_bin]['name'] = '';
592 $ret['addrlist'][$ip_bin]['reserved'] = 'no';
593 $ret['addrlist'][$ip_bin]['references'] = array();
594 $ret['addrlist'][$ip_bin]['lbrefs'] = array();
595 $ret['addrlist'][$ip_bin]['rsrefs'] = array();
597 $tmp = $qbject = array();
598 foreach (array ('object_id', 'vport', 'proto', 'vs_id') as $cname)
599 $tmp[$cname] = $row[$cname];
600 foreach (array ('name', 'objtype_id', 'objtype_name') as $cname)
601 $qobject[$cname] = $row[$cname];
602 $tmp['object_name'] = displayedName ($qobject);
603 $ret['addrlist'][$ip_bin]['lbrefs'][] = $tmp;
605 $result->closeCursor();
608 $query = "select inet_ntoa(rsip) as ip, rsport, rspool_id, rsp.name as rspool_name from " .
609 "IPRealServer as rs inner join IPRSPool as rsp on rs.rspool_id = rsp.id " .
610 "where rsip between ${db_first} and ${db_last} " .
611 "order by ip, rsport, rspool_id";
612 $result = useSelectBlade ($query);
613 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
615 $ip_bin = ip2long ($row['ip']);
616 if (!isset ($ret['addrlist'][$ip_bin]))
618 $ret['addrlist'][$ip_bin] = array();
619 $ret['addrlist'][$ip_bin]['ip'] = $row['ip'];
620 $ret['addrlist'][$ip_bin]['name'] = '';
621 $ret['addrlist'][$ip_bin]['reserved'] = 'no';
622 $ret['addrlist'][$ip_bin]['references'] = array();
623 $ret['addrlist'][$ip_bin]['lbrefs'] = array();
624 $ret['addrlist'][$ip_bin]['rsrefs'] = array();
627 foreach (array ('rspool_id', 'rsport', 'rspool_name') as $cname)
628 $tmp[$cname] = $row[$cname];
629 $ret['addrlist'][$ip_bin]['rsrefs'][] = $tmp;
635 // Don't require any records in IPAddress, but if there is one,
636 // merge the data between getting allocation list. Collect enough data
637 // to call displayedName() ourselves.
638 function getIPAddress ($ip=0)
641 $ret['bonds'] = array();
642 // FIXME: below two aren't neither filled in with data nor rendered (ticket:23)
643 $ret['outpf'] = array();
644 $ret['inpf'] = array();
645 $ret['vslist'] = array();
646 $ret['rslist'] = array();
649 $ret['reserved'] = 'no';
655 "where ip = INET_ATON('$ip') and (reserved = 'yes' or name != '')";
656 $result = $dbxlink->query ($query);
659 showError ('Query #1 failed', __FUNCTION__
);
662 if ($row = $result->fetch (PDO
::FETCH_ASSOC
))
665 $ret['name'] = $row['name'];
666 $ret['reserved'] = $row['reserved'];
668 $result->closeCursor();
673 "IPBonds.object_id as object_id, ".
674 "IPBonds.name as name, ".
675 "IPBonds.type as type, ".
676 "objtype_id, dict_value as objtype_name, " .
677 "RackObject.name as object_name ".
678 "from IPBonds join RackObject on IPBonds.object_id=RackObject.id ".
679 "left join Dictionary on objtype_id=dict_key natural join Chapter " .
680 "where IPBonds.ip=INET_ATON('$ip') ".
681 "and chapter_name = 'RackObjectType' " .
682 "order by RackObject.id, IPBonds.name";
683 $result = $dbxlink->query ($query);
685 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
687 $ret['bonds'][$count]['object_id'] = $row['object_id'];
688 $ret['bonds'][$count]['name'] = $row['name'];
689 $ret['bonds'][$count]['type'] = $row['type'];
691 $qo['name'] = $row['object_name'];
692 $qo['objtype_id'] = $row['objtype_id'];
693 $qo['objtype_name'] = $row['objtype_name'];
694 $ret['bonds'][$count]['object_name'] = displayedName ($qo);
698 $result->closeCursor();
701 $query = "select id, vport, proto, name from IPVirtualService where vip = inet_aton('${ip}')";
702 $result = $dbxlink->query ($query);
703 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
707 $ret['vslist'][] = $new;
709 $result->closeCursor();
712 $query = "select inservice, rsport, IPRSPool.id as pool_id, IPRSPool.name as poolname from " .
713 "IPRealServer inner join IPRSPool on rspool_id = IPRSPool.id " .
714 "where rsip = inet_aton('${ip}')";
715 $result = $dbxlink->query ($query);
716 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
720 $ret['rslist'][] = $new;
722 $result->closeCursor();
728 function bindIpToObject ($ip='', $object_id=0, $name='', $type='')
732 $range = getRangeByIp($ip);
734 return 'Non-existant ip address. Try adding IP range first';
736 $result = useInsertBlade
741 'ip' => "INET_ATON('$ip')",
742 'object_id' => "'${object_id}'",
743 'name' => "'${name}'",
744 'type' => "'${type}'"
747 return $result ?
'' : 'useInsertBlade() failed in bindIpToObject()';
750 // This function looks up 'has_problems' flag for 'T' atoms
751 // and modifies 'hl' key. May be, this should be better done
752 // in getRackData(). We don't honour 'skipped' key, because
753 // the function is also used for thumb creation.
754 function markupObjectProblems (&$rackData)
756 for ($i = $rackData['height']; $i > 0; $i--)
757 for ($locidx = 0; $locidx < 3; $locidx++
)
758 if ($rackData[$i][$locidx]['state'] == 'T')
760 $object = getObjectInfo ($rackData[$i][$locidx]['object_id']);
761 if ($object['has_problems'] == 'yes')
763 // Object can be already highlighted.
764 if (isset ($rackData[$i][$locidx]['hl']))
765 $rackData[$i][$locidx]['hl'] = $rackData[$i][$locidx]['hl'] . 'w';
767 $rackData[$i][$locidx]['hl'] = 'w';
772 function search_cmpObj ($a, $b)
774 return ($a['score'] > $b['score'] ?
-1 : 1);
777 // This function performs search and then calculates score for each result.
778 // Given previous search results in $objects argument, it adds new results
779 // to the array and updates score for existing results, if it is greater than
781 function mergeSearchResults (&$objects, $terms, $fieldname)
785 "select name, label, asset_no, barcode, ro.id, dict_key as objtype_id, " .
786 "dict_value as objtype_name, asset_no from RackObject as ro inner join Dictionary " .
787 "on objtype_id = dict_key natural join Chapter where chapter_name = 'RackObjectType' and ";
789 foreach (explode (' ', $terms) as $term)
791 if ($count) $query .= ' or ';
792 $query .= "${fieldname} like '%$term%'";
795 $result = useSelectBlade ($query);
796 // FIXME: this dead call was executed 4 times per 1 object search!
797 // $typeList = getObjectTypeList();
798 $clist = array ('id', 'name', 'label', 'asset_no', 'barcode', 'objtype_id', 'objtype_name');
799 while ($row = $result->fetch(PDO
::FETCH_ASSOC
))
801 foreach ($clist as $cname)
802 $object[$cname] = $row[$cname];
803 $object['score'] = 0;
804 $object['dname'] = displayedName ($object);
805 unset ($object['objtype_id']);
806 foreach (explode (' ', $terms) as $term)
807 if (strstr ($object['name'], $term))
808 $object['score'] +
= 1;
809 unset ($object['name']);
810 if (!isset ($objects[$row['id']]))
811 $objects[$row['id']] = $object;
812 elseif ($objects[$row['id']]['score'] < $object['score'])
813 $objects[$row['id']]['score'] = $object['score'];
818 function getObjectSearchResults ($terms)
821 mergeSearchResults ($objects, $terms, 'name');
822 mergeSearchResults ($objects, $terms, 'label');
823 mergeSearchResults ($objects, $terms, 'asset_no');
824 mergeSearchResults ($objects, $terms, 'barcode');
825 if (count ($objects) == 1)
826 usort ($objects, 'search_cmpObj');
830 // This function removes all colons and dots from a string.
831 function l2addressForDatabase ($string)
835 $pieces = explode (':', $string);
836 // This workaround is for SunOS ifconfig.
837 foreach ($pieces as &$byte)
838 if (strlen ($byte) == 1)
840 // And this workaround is for PHP.
842 $string = implode ('', $pieces);
843 $pieces = explode ('.', $string);
844 $string = implode ('', $pieces);
845 $string = strtoupper ($string);
849 function l2addressFromDatabase ($string)
851 switch (strlen ($string))
855 $ret = implode (':', str_split ($string, 2));
864 // The following 2 functions return previous and next rack IDs for
865 // a given rack ID. The order of racks is the same as in renderRackspace()
867 function getPrevIDforRack ($row_id = 0, $rack_id = 0)
869 if ($row_id <= 0 or $rack_id <= 0)
871 showError ('Invalid arguments passed', __FUNCTION__
);
874 $rackList = getRacksForRow ($row_id);
875 doubleLink ($rackList);
876 if (isset ($rackList[$rack_id]['prev_key']))
877 return $rackList[$rack_id]['prev_key'];
881 function getNextIDforRack ($row_id = 0, $rack_id = 0)
883 if ($row_id <= 0 or $rack_id <= 0)
885 showError ('Invalid arguments passed', __FUNCTION__
);
888 $rackList = getRacksForRow ($row_id);
889 doubleLink ($rackList);
890 if (isset ($rackList[$rack_id]['next_key']))
891 return $rackList[$rack_id]['next_key'];
895 // This function finds previous and next array keys for each array key and
896 // modifies its argument accordingly.
897 function doubleLink (&$array)
900 foreach (array_keys ($array) as $key)
904 $array[$key]['prev_key'] = $prev_key;
905 $array[$prev_key]['next_key'] = $key;
911 // After applying usort() to a rack list we will lose original array keys.
912 // This function restores the keys so they are equal to rack IDs.
913 function restoreRackIDs ($racks)
916 foreach ($racks as $rack)
917 $ret[$rack['id']] = $rack;
921 function sortTokenize ($a, $b)
927 $a = ereg_replace('[^a-zA-Z0-9]',' ',$a);
928 $a = ereg_replace('([0-9])([a-zA-Z])','\\1 \\2',$a);
929 $a = ereg_replace('([a-zA-Z])([0-9])','\\1 \\2',$a);
936 $b = ereg_replace('[^a-zA-Z0-9]',' ',$b);
937 $b = ereg_replace('([0-9])([a-zA-Z])','\\1 \\2',$b);
938 $b = ereg_replace('([a-zA-Z])([0-9])','\\1 \\2',$b);
943 $ar = explode(' ', $a);
944 $br = explode(' ', $b);
945 for ($i=0; $i<count($ar) && $i<count($br); $i++
)
948 if (is_numeric($ar[$i]) and is_numeric($br[$i]))
949 $ret = ($ar[$i]==$br[$i])?
0:($ar[$i]<$br[$i]?
-1:1);
951 $ret = strcasecmp($ar[$i], $br[$i]);
962 function sortByName ($a, $b)
964 return sortTokenize($a['name'], $b['name']);
967 function sortRacks ($a, $b)
969 return sortTokenize($a['row_name'] . ': ' . $a['name'], $b['row_name'] . ': ' . $b['name']);
977 function neq ($a, $b)
982 function countRefsOfType ($refs, $type, $eq)
985 foreach ($refs as $ref)
987 if ($eq($ref['type'], $type))
993 function sortEmptyPorts ($a, $b)
995 $objname_cmp = sortTokenize($a['Object_name'], $b['Object_name']);
996 if ($objname_cmp == 0)
998 return sortTokenize($a['Port_name'], $b['Port_name']);
1000 return $objname_cmp;
1003 function sortObjectAddressesAndNames ($a, $b)
1005 $objname_cmp = sortTokenize($a['object_name'], $b['object_name']);
1006 if ($objname_cmp == 0)
1008 $name_a = (isset ($a['port_name'])) ?
$a['port_name'] : '';
1009 $name_b = (isset ($b['port_name'])) ?
$b['port_name'] : '';
1010 $objname_cmp = sortTokenize($name_a, $name_b);
1011 if ($objname_cmp == 0)
1012 sortTokenize($a['ip'], $b['ip']);
1013 return $objname_cmp;
1015 return $objname_cmp;
1020 function sortAddresses ($a, $b)
1022 $name_cmp = sortTokenize($a['name'], $b['name']);
1025 return sortTokenize($a['ip'], $b['ip']);
1030 // This function expands port compat list into a matrix.
1031 function buildPortCompatMatrixFromList ($portTypeList, $portCompatList)
1034 // Create type matrix and markup compatible types.
1035 foreach (array_keys ($portTypeList) as $type1)
1036 foreach (array_keys ($portTypeList) as $type2)
1037 $matrix[$type1][$type2] = FALSE;
1038 foreach ($portCompatList as $pair)
1039 $matrix[$pair['type1']][$pair['type2']] = TRUE;
1043 function newPortForwarding($object_id, $localip, $localport, $remoteip, $remoteport, $proto, $description)
1047 $range = getRangeByIp($localip);
1049 return "$localip: Non existant ip";
1051 $range = getRangeByIp($remoteip);
1053 return "$remoteip: Non existant ip";
1055 if ( ($localport <= 0) or ($localport >= 65536) )
1056 return "$localport: invaild port";
1058 if ( ($remoteport <= 0) or ($remoteport >= 65536) )
1059 return "$remoteport: invaild port";
1062 "insert into PortForwarding set object_id='$object_id', localip=INET_ATON('$localip'), remoteip=INET_ATON('$remoteip'), localport='$localport', remoteport='$remoteport', proto='$proto', description='$description'";
1063 $result = $dbxlink->exec ($query);
1068 function deletePortForwarding($object_id, $localip, $localport, $remoteip, $remoteport, $proto)
1073 "delete from PortForwarding where object_id='$object_id' and localip=INET_ATON('$localip') and remoteip=INET_ATON('$remoteip') and localport='$localport' and remoteport='$remoteport' and proto='$proto'";
1074 $result = $dbxlink->exec ($query);
1078 function updatePortForwarding($object_id, $localip, $localport, $remoteip, $remoteport, $proto, $description)
1083 "update PortForwarding set description='$description' where object_id='$object_id' and localip=INET_ATON('$localip') and remoteip=INET_ATON('$remoteip') and localport='$localport' and remoteport='$remoteport' and proto='$proto'";
1084 $result = $dbxlink->exec ($query);
1088 function getNATv4ForObject ($object_id)
1091 $ret['out'] = array();
1092 $ret['in'] = array();
1096 "INET_NTOA(localip) as localip, ".
1098 "INET_NTOA(remoteip) as remoteip, ".
1100 "ipa1.name as local_addr_name, " .
1101 "ipa2.name as remote_addr_name, " .
1103 "from PortForwarding ".
1104 "left join IPAddress as ipa1 on PortForwarding.localip = ipa1.ip " .
1105 "left join IPAddress as ipa2 on PortForwarding.remoteip = ipa2.ip " .
1106 "where object_id='$object_id' ".
1107 "order by localip, localport, proto, remoteip, remoteport";
1108 $result = useSelectBlade ($query);
1110 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
1112 foreach (array ('proto', 'localport', 'localip', 'remoteport', 'remoteip', 'description', 'local_addr_name', 'remote_addr_name') as $cname)
1113 $ret['out'][$count][$cname] = $row[$cname];
1116 $result->closeCursor();
1122 "INET_NTOA(localip) as localip, ".
1124 "INET_NTOA(remoteip) as remoteip, ".
1126 "PortForwarding.object_id as object_id, ".
1127 "RackObject.name as object_name, ".
1129 "from ((PortForwarding join IPBonds on remoteip=IPBonds.ip) join RackObject on PortForwarding.object_id=RackObject.id) ".
1130 "where IPBonds.object_id='$object_id' ".
1131 "order by remoteip, remoteport, proto, localip, localport";
1132 $result = useSelectBlade ($query);
1134 while ($row = $result->fetch (PDO
::FETCH_ASSOC
))
1136 foreach (array ('proto', 'localport', 'localip', 'remoteport', 'remoteip', 'object_id', 'object_name', 'description') as $cname)
1137 $ret['in'][$count][$cname] = $row[$cname];
1140 $result->closeCursor();
1145 // This function returns an array of single element of object's FQDN attribute,
1146 // if FQDN is set. The next choice is object's common name, if it looks like a
1147 // hostname. Otherwise an array of all 'regular' IP addresses of the
1148 // object is returned (which may appear 0 and more elements long).
1149 function findAllEndpoints ($object_id, $fallback = '')
1151 $values = getAttrValues ($object_id);
1152 foreach ($values as $record)
1153 if ($record['name'] == 'FQDN' && !empty ($record['value']))
1154 return array ($record['value']);
1155 $addresses = getObjectAddresses ($object_id);
1157 foreach ($addresses as $idx => $address)
1158 if ($address['type'] == 'regular')
1159 $regular[] = $address['ip'];
1160 if (!count ($regular) && !empty ($fallback))
1161 return array ($fallback);
1165 // Some records in the dictionary may be written as plain text or as Wiki
1166 // link in the following syntax:
1168 // 2. [[word URL]] // FIXME: this isn't working
1169 // 3. [[word word word | URL]]
1170 // This function parses the line and returns text suitable for either A
1171 // (rendering <A HREF>) or O (for <OPTION>).
1172 function parseWikiLink ($line, $which, $strip_optgroup = FALSE)
1174 if (preg_match ('/^\[\[.+\]\]$/', $line) == 0)
1176 if ($strip_optgroup)
1177 return ereg_replace ('^.+\^', '', ereg_replace ('^(.+)&', '\\1 ', $line));
1181 $line = preg_replace ('/^\[\[(.+)\]\]$/', '$1', $line);
1182 $s = explode ('|', $line);
1183 $o_value = trim ($s[0]);
1184 if ($strip_optgroup)
1185 $o_value = ereg_replace ('^.+\^', '', ereg_replace ('^(.+)&', '\\1 ', $o_value));
1186 $a_value = trim ($s[1]);
1188 return "<a href='${a_value}'>${o_value}</a>";
1193 function buildVServiceName ($vsinfo = NULL)
1195 if ($vsinfo == NULL)
1197 showError ('NULL argument', __FUNCTION__
);
1200 return $vsinfo['vip'] . ':' . $vsinfo['vport'] . '/' . $vsinfo['proto'];
1203 function buildRSPoolName ($rspool = NULL)
1205 if ($rspool == NULL)
1207 showError ('NULL argument', __FUNCTION__
);
1210 return strlen ($rspool['name']) ?
$rspool['name'] : 'ANONYMOUS pool';
1213 // rackspace usage for a single rack
1214 // (T + W + U) / (height * 3 - A)
1215 function getRSUforRack ($data = NULL)
1219 showError ('Invalid argument', __FUNCTION__
);
1222 $counter = array ('A' => 0, 'U' => 0, 'T' => 0, 'W' => 0, 'F' => 0);
1223 for ($unit_no = $data['height']; $unit_no > 0; $unit_no--)
1224 for ($locidx = 0; $locidx < 3; $locidx++
)
1225 $counter[$data[$unit_no][$locidx]['state']]++
;
1226 return ($counter['T'] +
$counter['W'] +
$counter['U']) / ($counter['T'] +
$counter['W'] +
$counter['U'] +
$counter['F']);
1230 function getRSUforRackRow ($rowData = NULL)
1232 if ($rowData === NULL)
1234 showError ('Invalid argument', __FUNCTION__
);
1237 if (!count ($rowData))
1239 $counter = array ('A' => 0, 'U' => 0, 'T' => 0, 'W' => 0, 'F' => 0);
1241 foreach (array_keys ($rowData) as $rack_id)
1243 $data = getRackData ($rack_id);
1244 $total_height +
= $data['height'];
1245 for ($unit_no = $data['height']; $unit_no > 0; $unit_no--)
1246 for ($locidx = 0; $locidx < 3; $locidx++
)
1247 $counter[$data[$unit_no][$locidx]['state']]++
;
1249 return ($counter['T'] +
$counter['W'] +
$counter['U']) / ($counter['T'] +
$counter['W'] +
$counter['U'] +
$counter['F']);
1252 function getObjectCount ($rackData)
1255 for ($i = $rackData['height']; $i > 0; $i--)
1256 for ($locidx = 0; $locidx < 3; $locidx++
)
1259 $rackData[$i][$locidx]['state'] == 'T' and
1260 !in_array ($rackData[$i][$locidx]['object_id'], $objects)
1262 $objects[] = $rackData[$i][$locidx]['object_id'];
1263 return count ($objects);
1266 // Perform substitutions and return resulting string
1267 function apply_macros ($macros, $subject)
1270 foreach ($macros as $search => $replace)
1271 $ret = str_replace ($search, $replace, $ret);
1275 // Make sure the string is always wrapped with LF characters
1276 function lf_wrap ($str)
1278 $ret = trim ($str, "\r\n");
1284 // Adopted from Mantis BTS code.
1285 function string_insert_hrefs ($s)
1287 if (getConfigVar ('DETECT_URLS') != 'yes')
1289 # Find any URL in a string and replace it by a clickable link
1290 $s = preg_replace( '/(([[:alpha:]][-+.[:alnum:]]*):\/\/(%[[:digit:]A-Fa-f]{2}|[-_.!~*\';\/?%^\\\\:@&={\|}+$#\(\),\[\][:alnum:]])+)/se',
1291 "'<a href=\"'.rtrim('\\1','.').'\">\\1</a> [<a href=\"'.rtrim('\\1','.').'\" target=\"_blank\">^</a>]'",
1293 $s = preg_replace( '/\b' . email_regex_simple() . '\b/i',
1294 '<a href="mailto:\0">\0</a>',
1300 function email_regex_simple ()
1302 return "(([a-z0-9!#*+\/=?^_{|}~-]+(?:\.[a-z0-9!#*+\/=?^_{|}~-]+)*)" . # recipient
1303 "\@((?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?))"; # @domain
1306 // Parse AUTOPORTS_CONFIG and return a list of generated pairs (port_type, port_name)
1307 // for the requested object_type_id.
1308 function getAutoPorts ($type_id)
1311 $typemap = explode (';', str_replace (' ', '', getConfigVar ('AUTOPORTS_CONFIG')));
1312 foreach ($typemap as $equation)
1314 $tmp = explode ('=', $equation);
1315 if (count ($tmp) != 2)
1317 $objtype_id = $tmp[0];
1318 if ($objtype_id != $type_id)
1320 $portlist = $tmp[1];
1321 foreach (explode ('+', $portlist) as $product)
1323 $tmp = explode ('*', $product);
1324 if (count ($tmp) != 3)
1327 $port_type = $tmp[1];
1329 for ($i = 0; $i < $nports; $i++
)
1330 $ret[] = array ('type' => $port_type, 'name' => @sprintf
($format, $i));
1336 // Find if a particular tag id exists on the tree, then attach the
1337 // given child tag to it. If the parent tag doesn't exist, return FALSE.
1338 function attachChildTag (&$tree, $parent_id, $child_id, $child_info)
1340 foreach ($tree as $tagid => $taginfo)
1342 if ($tagid == $parent_id)
1344 $tree[$tagid]['kids'][$child_id] = $child_info;
1347 elseif (attachChildTag ($tree[$tagid]['kids'], $parent_id, $child_id, $child_info))
1353 // Build a tree from the tag list and return it.
1354 function getTagTree ()
1357 $mytaglist = $taglist;
1359 while (count ($mytaglist) > 0)
1362 foreach ($mytaglist as $tagid => $taginfo)
1364 $taginfo['kids'] = array();
1365 if ($taginfo['parent_id'] == NULL)
1367 $ret[$tagid] = $taginfo;
1369 unset ($mytaglist[$tagid]);
1371 elseif (attachChildTag ($ret, $taginfo['parent_id'], $tagid, $taginfo))
1374 unset ($mytaglist[$tagid]);
1377 if (!$picked) // Only orphaned items on the list.
1383 function serializeTags ($trail)
1387 foreach ($trail as $taginfo)
1389 $ret .= $comma . $taginfo['tag'];
1395 // a helper for getTrailExpansion()
1396 function traceTrail ($tree, $trail)
1398 // For each tag find its path from the root, then combine items
1399 // of all paths and add them to the trail, if they aren't there yet.
1401 foreach ($tree as $taginfo1)
1404 foreach ($trail as $taginfo2)
1405 if ($taginfo1['id'] == $taginfo2['id'])
1410 if (count ($taginfo1['kids']) > 0)
1412 $subsearch = traceTrail ($taginfo1['kids'], $trail);
1413 if (count ($subsearch))
1416 $ret = array_merge ($ret, $subsearch);
1425 // For each tag add all its parent tags onto the list. Don't expect anything
1426 // except user's tags on the trail.
1427 function getTrailExpansion ($trail)
1430 return traceTrail ($tagtree, $trail);
1433 // Return the list of missing implicit tags.
1434 function getImplicitTags ($oldtags)
1437 $newtags = getTrailExpansion ($oldtags);
1438 foreach ($newtags as $newtag)
1440 $already_exists = FALSE;
1441 foreach ($oldtags as $oldtag)
1442 if ($newtag['id'] == $oldtag['id'])
1444 $already_exists = TRUE;
1447 if ($already_exists)
1449 $ret[] = array ('id' => $newtag['id'], 'tag' => $newtag['tag'], 'parent_id' => $newtag['parent_id']);
1454 // Minimize the trail: exclude all implicit tags and return the resulting trail.
1455 function getExplicitTagsOnly ($trail, $tree = NULL)
1461 foreach ($tree as $taginfo)
1463 if (isset ($taginfo['kids']))
1465 $harvest = getExplicitTagsOnly ($trail, $taginfo['kids']);
1466 if (count ($harvest) > 0)
1468 $ret = array_merge ($ret, $harvest);
1472 // This tag isn't implicit, test is for being explicit.
1473 foreach ($trail as $testtag)
1474 if ($taginfo['id'] == $testtag['id'])
1483 // Maximize the trail: for each tag add all tags, for which it is direct or indirect parent.
1484 // Unlike other functions, this one accepts and returns a list of integer tag IDs, not
1485 // a list of tag structures.
1486 function complementByKids ($idlist, $tree = NULL, $getall = FALSE)
1491 $getallkids = $getall;
1493 foreach ($tree as $taginfo)
1495 foreach ($idlist as $test_id)
1496 if ($getall or $taginfo['id'] == $test_id)
1498 $ret[] = $taginfo['id'];
1499 // Once matched node makes all sub-nodes match, but don't make
1500 // a mistake of matching every other node at the current level.
1504 if (isset ($taginfo['kids']))
1505 $ret = array_merge ($ret, complementByKids ($idlist, $taginfo['kids'], $getallkids));
1506 $getallkids = FALSE;
1511 function loadRackObjectAutoTags()
1513 assertUIntArg ('object_id', __FUNCTION__
);
1514 $object_id = $_REQUEST['object_id'];
1515 $oinfo = getObjectInfo ($object_id);
1517 $ret[] = array ('tag' => '$id_' . $_REQUEST['object_id']);
1518 $ret[] = array ('tag' => '$any_object');
1522 function loadIPv4PrefixAutoTags()
1524 assertUIntArg ('id', __FUNCTION__
);
1525 $subnet = getIPRange ($_REQUEST['id']);
1527 $ret[] = array ('tag' => '$id_' . $_REQUEST['id']);
1528 $ret[] = array ('tag' => '$ipv4net-' . str_replace ('.', '-', $subnet['ip']) . '-' . $subnet['mask']);
1529 // FIXME: find and list tags for all parent networks
1530 $ret[] = array ('tag' => '$any_ipv4net');
1531 $ret[] = array ('tag' => '$any_net');
1535 function loadRackAutoTags()
1537 assertUIntArg ('rack_id', __FUNCTION__
);
1539 $ret[] = array ('tag' => '$id_' . $_REQUEST['rack_id']);
1540 $ret[] = array ('tag' => '$any_rack');
1544 function loadIPv4AddressAutoTags()
1546 assertIPv4Arg ('ip', __FUNCTION__
);
1548 $ret[] = array ('tag' => '$ipv4net-' . str_replace ('.', '-', $subnet['ip']) . '-32');
1549 // FIXME: find and list tags for all parent networks
1550 $ret[] = array ('tag' => '$any_ipv4net');
1551 $ret[] = array ('tag' => '$any_net');
1555 function loadIPv4VSAutoTags()
1557 assertUIntArg ('id', __FUNCTION__
);
1559 $ret[] = array ('tag' => '$id_' . $_REQUEST['id']);
1560 $ret[] = array ('tag' => '$any_ipv4vs');
1561 $ret[] = array ('tag' => '$any_vs');
1565 function loadIPv4RSPoolAutoTags()
1567 assertUIntArg ('pool_id', __FUNCTION__
);
1569 $ret[] = array ('tag' => '$id_' . $_REQUEST['pool_id']);
1570 $ret[] = array ('tag' => '$any_ipv4rspool');
1571 $ret[] = array ('tag' => '$any_rspool');
1575 function getGlobalAutoTags()
1577 global $remote_username, $accounts;
1580 foreach ($accounts as $a)
1581 if ($a['user_name'] == $remote_username)
1583 $user_id = $a['user_id'];
1586 $ret[] = array ('tag' => '$username_' . $remote_username);
1587 $ret[] = array ('tag' => '$userid_' . $user_id);
1591 // Build a tag trail from supplied tag id list and return it.
1592 function buildTrailFromIds ($tagidlist)
1596 foreach ($tagidlist as $tag_id)
1597 if (isset ($taglist[$tag_id]))
1598 $ret[] = $taglist[$tag_id];
1602 // Process a given tag tree and return only meaningful branches. The resulting
1603 // (sub)tree will have refcnt leaves on every last branch.
1604 function getObjectiveTagTree ($tree, $realm)
1607 foreach ($tree as $taginfo)
1609 $subsearch = array();
1611 if (count ($taginfo['kids']))
1613 $subsearch = getObjectiveTagTree ($taginfo['kids'], $realm);
1614 $pick = count ($subsearch) > 0;
1616 if (isset ($taginfo['refcnt'][$realm]))
1622 'id' => $taginfo['id'],
1623 'tag' => $taginfo['tag'],
1624 'parent_id' => $taginfo['parent_id'],
1625 'refcnt' => $taginfo['refcnt'],
1626 'kids' => $subsearch
1632 function getStringFromTrail ($trail)
1636 foreach ($trail as $tag)
1638 $str .= $comma . $tag['id'];
1644 function getTagFilter ()
1646 return isset ($_REQUEST['tagfilter']) ?
complementByKids ($_REQUEST['tagfilter']) : array();