本文整理汇总了PHP中sort_tree函数的典型用法代码示例。如果您正苦于以下问题:PHP sort_tree函数的具体用法?PHP sort_tree怎么用?PHP sort_tree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sort_tree函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: form_save
function form_save()
{
if (isset($_POST["save_component_tree"])) {
$save["id"] = $_POST["id"];
$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
$save["sort_type"] = form_input_validate($_POST["sort_type"], "sort_type", "", true, 3);
if (!is_error_message()) {
$tree_id = sql_save($save, "graph_tree");
if ($tree_id) {
raise_message(1);
/* sort the tree using the algorithm chosen by the user */
sort_tree(SORT_TYPE_TREE, $tree_id, $_POST["sort_type"]);
} else {
raise_message(2);
}
}
if (is_error_message() || empty($_POST["id"])) {
header("Location: tree.php?action=edit&id=" . (empty($tree_id) ? $_POST["id"] : $tree_id));
} else {
header("Location: tree.php");
}
} elseif (isset($_POST["save_component_tree_item"])) {
$tree_item_id = api_tree_item_save($_POST["id"], $_POST["graph_tree_id"], $_POST["type"], $_POST["parent_item_id"], isset($_POST["title"]) ? $_POST["title"] : "", isset($_POST["local_graph_id"]) ? $_POST["local_graph_id"] : "0", isset($_POST["rra_id"]) ? $_POST["rra_id"] : "0", isset($_POST["host_id"]) ? $_POST["host_id"] : "0", isset($_POST["host_grouping_type"]) ? $_POST["host_grouping_type"] : "1", isset($_POST["sort_children_type"]) ? $_POST["sort_children_type"] : "1", isset($_POST["propagate_changes"]) ? true : false);
if (is_error_message()) {
header("Location: tree.php?action=item_edit&tree_item_id=" . (empty($tree_item_id) ? $_POST["id"] : $tree_item_id) . "&tree_id=" . $_POST["graph_tree_id"] . "&parent_id=" . $_POST["parent_item_id"]);
} else {
header("Location: tree.php?action=edit&id=" . $_POST["graph_tree_id"]);
}
}
}
开发者ID:BackupTheBerlios,项目名称:odp-svn,代码行数:30,代码来源:tree.php
示例2: categories_meta_box
function categories_meta_box ($Product) {
$db =& DB::get();
$category_table = DatabaseObject::tablename(Category::$table);
$categories = $db->query("SELECT id,name,parent FROM $category_table ORDER BY parent,name",AS_ARRAY);
$categories = sort_tree($categories);
if (empty($categories)) $categories = array();
$categories_menu = '<option value="0">'.__('Parent Category','Ecart').'…</option>';
foreach ($categories as $category) {
$padding = str_repeat(" ",$category->depth*3);
$categories_menu .= '<option value="'.$category->id.'">'.$padding.esc_html($category->name).'</option>';
}
$selectedCategories = array();
foreach ($Product->categories as $category) $selectedCategories[] = $category->id;
?>
<div id="category-menu" class="multiple-select short">
<ul>
<?php $depth = 0; foreach ($categories as $category):
if ($category->depth > $depth) echo "<li><ul>"; ?>
<?php if ($category->depth < $depth): ?>
<?php for ($i = $category->depth; $i < $depth; $i++): ?>
</ul></li>
<?php endfor; ?>
<?php endif; ?>
<li id="category-element-<?php echo $category->id; ?>"><input type="checkbox" name="categories[]" value="<?php echo $category->id; ?>" id="category-<?php echo $category->id; ?>" tabindex="3"<?php if (in_array($category->id,$selectedCategories)) echo ' checked="checked"'; ?> class="category-toggle" /><label for="category-<?php echo $category->id; ?>"><?php echo esc_html($category->name); ?></label></li>
<?php $depth = $category->depth; endforeach; ?>
<?php for ($i = 0; $i < $depth; $i++): ?>
</ul></li>
<?php endfor; ?>
</ul>
</div>
<div>
<div id="new-category" class="hidden">
<input type="text" name="new-category" value="" size="15" id="new-category-name" /><br />
<select name="new-category-parent"><?php echo $categories_menu; ?></select>
<button id="add-new-category" type="button" class="button-secondary" tabindex="2"><small><?php _e('Add','Ecart'); ?></small></button>
</div>
<button id="new-category-button" type="button" class="button-secondary" style="margin-top:10px;" tabindex="2"><?php _e('Add New Category','Ecart'); ?></button>
</div>
<?php
}
开发者ID:robbiespire,项目名称:paQui,代码行数:43,代码来源:ui.php
示例3: db_fetch_cell
$groups[$group][$host]["snmp_ver"] = $version;
$groups[$group][$host]["community"] = $community;
}
/* ----------------------------------------------------------------------------------------------------- */
/* Make sure we have a netdot tree */
$treeId = db_fetch_cell("SELECT id FROM graph_tree WHERE name = 'Netdot'");
if ($treeId) {
debug("Netdot tree already exists - id: ({$treeId})");
} else {
$treeOpts = array();
$treeOpts["id"] = 0;
# Zero means create a new one rather than save over an existing one
$treeOpts["name"] = "Netdot";
$treeOpts["sort_type"] = $sortMethods["alpha"];
$treeId = sql_save($treeOpts, "graph_tree");
sort_tree(SORT_TYPE_TREE, $treeId, $treeOpts["sort_type"]);
echo "Created Netdot Tree - id: {$treeId}\n";
}
/* Store all header and host nodes for faster lookups */
$hostNodes = array();
$headerNodes = array();
$treeNodes = db_fetch_assoc("SELECT id, title, host_id FROM graph_tree_items WHERE graph_tree_id={$treeId}");
foreach ($treeNodes as $row) {
if ($row["host_id"] != 0) {
$hostNodes[$row["host_id"]] = $row["id"];
} elseif ($row["title"] != "") {
$headerNodes[$row["title"]] = $row["id"];
}
}
/* ----------------------------------------------------------------------------------------------------- */
foreach ($groups as $group => $hosts) {
开发者ID:richwellman,项目名称:Netdot,代码行数:31,代码来源:netdot_to_cacti.php
示例4: load_children
/**
* Load sub-categories
*
* @since 1.0
* @version 1.1
*
* @param array $loading Query configuration array
* @return boolean successfully loaded or not
**/
function load_children($loading=array()) {
if (isset($this->smart)
|| empty($this->id)
|| empty($this->uri)) return false;
$db = DB::get();
$catalog_table = DatabaseObject::tablename(Catalog::$table);
$defaults = array(
'columns' => 'cat.*,count(sc.product) as total',
'joins' => array("LEFT JOIN $catalog_table AS sc ON sc.parent=cat.id AND sc.type='category'"),
'where' => array("cat.uri like '%$this->uri%' AND cat.id <> $this->id"),
'orderby' => 'name',
'order' => 'ASC'
);
$loading = array_merge($defaults,$loading);
extract($loading);
switch(strtolower($orderby)) {
case "id": $orderby = "cat.id"; break;
case "slug": $orderby = "cat.slug"; break;
case "count": $orderby = "total"; break;
default: $orderby = "cat.name";
}
switch(strtoupper($order)) {
case "DESC": $order = "DESC"; break;
default: $order = "ASC";
}
$joins = join(' ',$joins);
$where = join(' AND ',$where);
$name_order = ($orderby !== "name")?",name ASC":"";
$query = "SELECT $columns FROM $this->_table AS cat
$joins
WHERE $where
GROUP BY cat.id
ORDER BY cat.parent DESC,$orderby $order$name_order";
$children = $db->query($query,AS_ARRAY);
$children = sort_tree($children,$this->id);
foreach ($children as &$child) {
$this->children[$child->id] = new Category();
$this->children[$child->id]->populate($child);
$this->children[$child->id]->depth = $child->depth;
$this->children[$child->id]->total = $child->total;
}
return (!empty($this->children));
}
开发者ID:robbiespire,项目名称:paQui,代码行数:60,代码来源:Category.php
示例5: sort_tree
function sort_tree(&$result, $key)
{
$master_sort = sorter($result, $key);
foreach ($master_sort as $data) {
$id = $data[$key];
// remove child
$newdata = $data;
unset($data['children']);
$current_array[$id] = $data;
// fielded parents
if (array_key_exists("children", $newdata)) {
$result = $newdata['children'];
$current_array[$id]['children'] = sort_tree($result, $key);
}
}
return $current_array;
}
开发者ID:WuChEn,项目名称:PHP-Fusion,代码行数:17,代码来源:sqlhandler.inc.php
示例6: products
/**
* Interface processor for the product list manager
*
* @return void
**/
function products ($workflow=false) {
global $Ecart,$Products;
$db = DB::get();
$Settings = &EcartSettings();
if ( !(is_ecart_userlevel() || current_user_can('ecart_products')) )
wp_die(__('You do not have sufficient permissions to access this page.'));
$defaults = array(
'cat' => false,
'pagenum' => 1,
'per_page' => 20,
's' => '',
'sl' => '',
'matchcol' => '',
'f' => ''
);
$args = array_merge($defaults,$_GET);
extract($args,EXTR_SKIP);
if (!$workflow) {
if (empty($categories)) $categories = array('');
$category_table = DatabaseObject::tablename(Category::$table);
$query = "SELECT id,name,parent FROM $category_table ORDER BY parent,name";
$categories = $db->query($query,AS_ARRAY);
$categories = sort_tree($categories);
if (empty($categories)) $categories = array();
$categories_menu = '<option value="">'.__('View all categories','Ecart').'</option>';
$categories_menu .= '<option value="-"'.($cat=='-'?' selected="selected"':'').'>'.__('Uncategorized','Ecart').'</option>';
foreach ($categories as $category) {
$padding = str_repeat(" ",$category->depth*3);
if ($cat == $category->id) $categories_menu .= '<option value="'.$category->id.'" selected="selected">'.$padding.esc_html($category->name).'</option>';
else $categories_menu .= '<option value="'.$category->id.'">'.$padding.esc_html($category->name).'</option>';
}
$inventory_filters = array(
'all' => __('View all products','Ecart'),
'is' => __('In stock','Ecart'),
'ls' => __('Low stock','Ecart'),
'oos' => __('Out-of-stock','Ecart'),
'ns' => __('Not stocked','Ecart')
);
$inventory_menu = menuoptions($inventory_filters,$sl,true);
}
$subfilters = array('f' => 'featured','p' => 'published','s' => 'onsale','i' => 'inventory');
$subs = array(
'all' => array('label' => __('All','Ecart'),'columns' => "count(distinct pd.id) AS total",'where'=>'true'),
'published' => array('label' => __('Published','Ecart'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pd.status='publish'",'request' => 'p'),
'onsale' => array('label' => __('On Sale','Ecart'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pt.sale='on'",'request' => 's'),
'featured' => array('label' => __('Featured','Ecart'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pd.featured='on'",'request' => 'f'),
'inventory' => array('label' => __('Inventory','Ecart'),'total' => 0,'columns' => "count(distinct pt.id) AS total",'where'=>"pt.inventory='on' AND pt.type!='N/A'",'grouping'=>'pt.id','request' => 'i')
);
if ('i' == $f) $per_page = 50;
$pagenum = absint( $pagenum );
if ( empty($pagenum) )
$pagenum = 1;
if( !$per_page || $per_page < 0 )
$per_page = 20;
$start = ($per_page * ($pagenum-1));
$pd = DatabaseObject::tablename(Product::$table);
$pt = DatabaseObject::tablename(Price::$table);
$catt = DatabaseObject::tablename(Category::$table);
$clog = DatabaseObject::tablename(Catalog::$table);
$orderby = "pd.created DESC";
$where = "true";
$having = "";
if (!empty($s)) {
$products = new SearchResults(array("search"=>$s));
$products->load_products(array("load"=>array()));
$ids = array_keys($products->products);
$where .= " AND pd.id IN (".join(',',$ids).")";
}
// if (!empty($cat)) $where .= " AND cat.id='$cat' AND (clog.category != 0 OR clog.id IS NULL)";
if (!empty($cat)) {
if ($cat == "-") {
$having = "HAVING COUNT(cat.id) = 0";
} else {
$matchcol .= ", GROUP_CONCAT(DISTINCT cat.id ORDER BY cat.id SEPARATOR ',') AS catids";
$where .= " AND cat.id IN (SELECT parent FROM $clog WHERE parent=$cat AND type='category')";
}
}
if (!empty($sl)) {
switch($sl) {
case "ns": $where .= " AND pt.inventory='off'"; break;
case "oos":
$where .= " AND (pt.inventory='on')";
$having .= (empty($having)?"HAVING ":" AND ")."SUM(pt.stock) = 0";
//.........这里部分代码省略.........
开发者ID:robbiespire,项目名称:paQui,代码行数:101,代码来源:Warehouse.php
示例7: form_save
function form_save()
{
/* clear graph tree cache on save - affects current user only, other users should see changes in <5 minutes */
if (isset($_SESSION['dhtml_tree'])) {
unset($_SESSION['dhtml_tree']);
}
if (isset($_POST["save_component_tree"])) {
/* modify for multi user start */
if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
if ($_POST["id"] != $_SESSION["private_tree_id"]) {
access_denied();
}
}
/* modify for multi user end */
$save["id"] = $_POST["id"];
$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
$save["sort_type"] = form_input_validate($_POST["sort_type"], "sort_type", "", true, 3);
if (!is_error_message()) {
$tree_id = sql_save($save, "graph_tree");
if ($tree_id) {
raise_message(1);
/* sort the tree using the algorithm chosen by the user */
sort_tree(SORT_TYPE_TREE, $tree_id, $_POST["sort_type"]);
} else {
raise_message(2);
}
}
header("Location: tree.php?action=edit&id=" . (empty($tree_id) ? $_POST["id"] : $tree_id));
} elseif (isset($_POST["save_component_tree_item"])) {
/* modify for multi user start */
if (!empty($_GET["id"])) {
if (!check_tree_item($_POST["id"])) {
access_denied();
}
}
/* modify for multi user end */
$tree_item_id = api_tree_item_save($_POST["id"], $_POST["graph_tree_id"], $_POST["type"], $_POST["parent_item_id"], isset($_POST["title"]) ? $_POST["title"] : "", isset($_POST["local_graph_id"]) ? $_POST["local_graph_id"] : "0", isset($_POST["rra_id"]) ? $_POST["rra_id"] : "0", isset($_POST["host_id"]) ? $_POST["host_id"] : "0", isset($_POST["host_grouping_type"]) ? $_POST["host_grouping_type"] : "1", isset($_POST["sort_children_type"]) ? $_POST["sort_children_type"] : "1", isset($_POST["propagate_changes"]) ? true : false);
if (is_error_message()) {
header("Location: tree.php?action=item_edit&tree_item_id=" . (empty($tree_item_id) ? $_POST["id"] : $tree_item_id) . "&tree_id=" . $_POST["graph_tree_id"] . "&parent_id=" . $_POST["parent_item_id"]);
} else {
/* modify for multi user start */
if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
if (isset($_POST["local_graph_id"]) && $_POST["graph_tree_id"] == $_SESSION["public_tree_id"]) {
exec("php ./cli/add_perms.php --user-id=" . $_SESSION["sess_user_id"] . " --item-type=graph --item-id=" . $_POST["local_graph_id"]);
}
}
/* modify for multi user end */
header("Location: tree.php?action=edit&id=" . $_POST["graph_tree_id"]);
}
}
}
开发者ID:resmon,项目名称:resmon-cacti,代码行数:51,代码来源:tree.php
示例8: api_tree_item_save
function api_tree_item_save($id, $tree_id, $type, $parent_tree_item_id, $title, $local_graph_id, $rra_id,
$host_id, $host_grouping_type, $sort_children_type, $propagate_changes) {
global $config;
input_validate_input_number($tree_id);
input_validate_input_number($parent_tree_item_id);
include_once($config["library_path"] . "/tree.php");
$parent_order_key = db_fetch_cell("select order_key from graph_tree_items where id=$parent_tree_item_id");
/* fetch some cache variables */
if (empty($id)) {
/* new/save - generate new order key */
$order_key = get_next_tree_id($parent_order_key, "graph_tree_items", "order_key", "graph_tree_id=$tree_id");
}else{
/* edit/save - use old order_key */
$order_key = db_fetch_cell("select order_key from graph_tree_items where id=$id");
}
/* duplicate graph check */
$search_key = substr($parent_order_key, 0, (tree_tier($parent_order_key) * CHARS_PER_TIER));
if (($type == TREE_ITEM_TYPE_GRAPH) && (sizeof(db_fetch_assoc("select id from graph_tree_items where local_graph_id='$local_graph_id' and rra_id='$rra_id' and graph_tree_id='$tree_id' and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) {
return 0;
}
$save["id"] = $id;
$save["graph_tree_id"] = $tree_id;
$save["title"] = form_input_validate($title, "title", "", ($type == TREE_ITEM_TYPE_HEADER ? false : true), 3);
$save["order_key"] = $order_key;
$save["local_graph_id"] = form_input_validate($local_graph_id, "local_graph_id", "", true, 3);
$save["rra_id"] = form_input_validate($rra_id, "rra_id", "", true, 3);
$save["host_id"] = form_input_validate($host_id, "host_id", "", true, 3);
$save["host_grouping_type"] = form_input_validate($host_grouping_type, "host_grouping_type", "", true, 3);
$save["sort_children_type"] = form_input_validate($sort_children_type, "sort_children_type", "", true, 3);
$tree_item_id = 0;
if (!is_error_message()) {
$tree_item_id = sql_save($save, "graph_tree_items");
if ($tree_item_id) {
raise_message(1);
/* re-parent the branch if the parent item has changed */
if ($parent_tree_item_id != $tree_item_id) {
reparent_branch($parent_tree_item_id, $tree_item_id);
}
$tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='$tree_id'");
/* tree item ordering */
if ($tree_sort_type == TREE_ORDERING_NONE) {
/* resort our parent */
$parent_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=$parent_tree_item_id");
if ((!empty($parent_tree_item_id)) && ($parent_sorting_type != TREE_ORDERING_NONE)) {
sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $parent_sorting_type);
}
/* if this is a header, sort direct children */
if (($type == TREE_ITEM_TYPE_HEADER) && ($sort_children_type != TREE_ORDERING_NONE)) {
sort_tree(SORT_TYPE_TREE_ITEM, $tree_item_id, $sort_children_type);
}
/* tree ordering */
}else{
/* potential speed savings for large trees */
if (tree_tier($save["order_key"]) == 1) {
sort_tree(SORT_TYPE_TREE, $tree_id, $tree_sort_type);
}else{
sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $tree_sort_type);
}
}
/* if the user checked the 'Propagate Changes' box */
if (($type == TREE_ITEM_TYPE_HEADER) && ($propagate_changes == true)) {
$search_key = preg_replace("/0+$/", "", $order_key);
$tree_items = db_fetch_assoc("select
graph_tree_items.id
from graph_tree_items
where graph_tree_items.host_id = 0
and graph_tree_items.local_graph_id = 0
and graph_tree_items.title != ''
and graph_tree_items.order_key like '$search_key%%'
and graph_tree_items.graph_tree_id='$tree_id'");
if (sizeof($tree_items) > 0) {
foreach ($tree_items as $item) {
db_execute("update graph_tree_items set sort_children_type = '$sort_children_type' where id = '" . $item["id"] . "'");
if ($sort_children_type != TREE_ORDERING_NONE) {
sort_tree(SORT_TYPE_TREE_ITEM, $item["id"], $sort_children_type);
}
}
}
}
}else{
raise_message(2);
}
}
//.........这里部分代码省略.........
开发者ID:songchin,项目名称:Cacti,代码行数:101,代码来源:api_tree.php
示例9: load_children
function load_children($loading = array())
{
if (isset($this->smart) || empty($this->id) || empty($this->uri)) {
return false;
}
$db = DB::get();
if (empty($loading['orderby'])) {
$loading['orderby'] = "name";
}
switch (strtolower($loading['orderby'])) {
case "id":
$orderby = "cat.id";
break;
case "slug":
$orderby = "cat.slug";
break;
case "count":
$orderby = "total";
break;
default:
$orderby = "cat.name";
}
if (empty($loading['order'])) {
$loading['order'] = "ASC";
}
switch (strtoupper($loading['order'])) {
case "DESC":
$order = "DESC";
break;
default:
$order = "ASC";
}
$catalog_table = DatabaseObject::tablename(Catalog::$table);
$children = $db->query("SELECT cat.*,count(sc.product) AS total FROM {$this->_table} AS cat LEFT JOIN {$catalog_table} AS sc ON sc.category=cat.id WHERE cat.uri like '%{$this->uri}%' AND cat.id <> {$this->id} GROUP BY cat.id ORDER BY cat.parent DESC,{$orderby} {$order},name ASC", AS_ARRAY);
$children = sort_tree($children, $this->id);
foreach ($children as &$child) {
$this->children[$child->id] = new Category();
$this->children[$child->id]->populate($child);
$this->children[$child->id]->depth = $child->depth;
$this->children[$child->id]->total = $child->total;
}
if (!empty($this->children)) {
return true;
}
return false;
}
开发者ID:kennethreitz-archive,项目名称:wordpress-skeleton,代码行数:46,代码来源:Category.php
示例10: categories_meta_box
function categories_meta_box($Product)
{
$db =& DB::get();
$category_table = DatabaseObject::tablename(Category::$table);
$categories = $db->query("SELECT id,name,parent FROM {$category_table} ORDER BY parent,name", AS_ARRAY);
$categories = sort_tree($categories);
if (empty($categories)) {
$categories = array();
}
$categories_menu = '<option value="0" rel="-1,-1">' . __('Parent Category', 'Shopp') . '…</option>';
foreach ($categories as $category) {
$padding = str_repeat(" ", $category->depth * 3);
$categories_menu .= '<option value="' . $category->id . '" rel="' . $category->parent . ',' . $category->depth . '">' . $padding . $category->name . '</option>';
}
$selectedCategories = array();
foreach ($Product->categories as $category) {
$selectedCategories[] = $category->id;
}
?>
<div id="category-menu" class="multiple-select short">
<ul>
<?php
$depth = 0;
foreach ($categories as $category) {
if ($category->depth > $depth) {
echo "<li><ul>";
}
?>
<?php
if ($category->depth < $depth) {
?>
<?php
for ($i = $category->depth; $i < $depth; $i++) {
?>
</ul></li>
<?php
}
?>
<?php
}
?>
<li id="category-element-<?php
echo $category->id;
?>
"><input type="checkbox" name="categories[]" value="<?php
echo $category->id;
?>
" id="category-<?php
echo $category->id;
?>
" tabindex="3"<?php
if (in_array($category->id, $selectedCategories)) {
echo ' checked="checked"';
}
?>
class="category-toggle" /><label for="category-<?php
echo $category->id;
?>
"><?php
echo $category->name;
?>
</label></li>
<?php
$depth = $category->depth;
}
?>
<?php
for ($i = 0; $i < $depth; $i++) {
?>
</ul></li>
<?php
}
?>
</ul>
</div>
<div id="new-category">
<input type="text" name="new-category" value="" size="15" id="new-category" /><br />
<select name="new-category-parent"><?php
echo $categories_menu;
?>
</select>
<button id="add-new-category" type="button" class="button-secondary" tabindex="2"><small><?php
_e('Add', 'Shopp');
?>
</small></button>
</div>
<?php
}
开发者ID:kennethreitz-archive,项目名称:wordpress-skeleton,代码行数:89,代码来源:ui.php
示例11: api_tree_item_save
function api_tree_item_save($id, $tree_id, $type, $parent_tree_item_id, $title, $local_graph_id, $rra_id, $host_id, $host_grouping_type, $sort_children_type, $propagate_changes)
{
global $config;
input_validate_input_number($tree_id);
input_validate_input_number($parent_tree_item_id);
include_once $config["library_path"] . "/tree.php";
db_execute("LOCK TABLES graph_tree_items WRITE, graph_tree READ, graph_templates_graph READ, host READ");
$parent_order_key = db_fetch_cell("select order_key from graph_tree_items where id={$parent_tree_item_id}");
/* fetch some cache variables */
if (empty($id)) {
/* new/save - generate new order key */
$order_key = get_next_tree_id($parent_order_key, "graph_tree_items", "order_key", "graph_tree_id={$tree_id}");
} else {
/* edit/save - use old order_key */
$order_key = db_fetch_cell("select order_key from graph_tree_items where id={$id}");
}
/* duplicate graph check */
$search_key = substr($parent_order_key, 0, tree_tier($parent_order_key) * CHARS_PER_TIER);
if ($id == 0 && $type == TREE_ITEM_TYPE_GRAPH && sizeof(db_fetch_assoc("select id from graph_tree_items where local_graph_id='{$local_graph_id}' and graph_tree_id='{$tree_id}' and order_key like '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0) {
$value = db_fetch_cell("select id from graph_tree_items where local_graph_id='{$local_graph_id}' and graph_tree_id='{$tree_id}' and order_key like '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "'");
db_execute("UNLOCK TABLES");
return $value;
}
/* Duplicate header check */
if ($id == 0 && $type == TREE_ITEM_TYPE_HEADER) {
if (sizeof(db_fetch_assoc("SELECT id FROM graph_tree_items WHERE title='{$title}' AND graph_tree_id='{$tree_id}' AND order_key LIKE '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "' AND order_key NOT LIKE '{$search_key}" . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - strlen($search_key)) . "%'")) > 0) {
$value = db_fetch_cell("select id from graph_tree_items where title='{$title}' and graph_tree_id='{$tree_id}' and order_key like '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "'");
db_execute("UNLOCK TABLES");
return $value;
}
}
/* Duplicate host check */
if ($id == 0 && $type == TREE_ITEM_TYPE_HOST && sizeof(db_fetch_assoc("select id from graph_tree_items where host_id='{$host_id}' and local_graph_id='{$local_graph_id}' and graph_tree_id='{$tree_id}' and order_key like '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0) {
$value = db_fetch_cell("select id from graph_tree_items where host_id='{$host_id}' and local_graph_id='{$local_graph_id}' and graph_tree_id='{$tree_id}' and order_key like '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "'");
db_execute("UNLOCK TABLES");
return $value;
}
$save["id"] = $id;
$save["graph_tree_id"] = $tree_id;
$save["title"] = form_input_validate($title, "title", "", $type == TREE_ITEM_TYPE_HEADER ? false : true, 3);
$save["order_key"] = $order_key;
$save["local_graph_id"] = form_input_validate($local_graph_id, "local_graph_id", "", true, 3);
$save["rra_id"] = form_input_validate($rra_id, "rra_id", "", true, 3);
$save["host_id"] = form_input_validate($host_id, "host_id", "", true, 3);
$save["host_grouping_type"] = form_input_validate($host_grouping_type, "host_grouping_type", "", true, 3);
$save["sort_children_type"] = form_input_validate($sort_children_type, "sort_children_type", "", true, 3);
$tree_item_id = 0;
if (!is_error_message()) {
$tree_item_id = sql_save($save, "graph_tree_items");
if ($tree_item_id) {
raise_message(1);
/* re-parent the branch if the parent item has changed */
if ($parent_tree_item_id != $tree_item_id) {
reparent_branch($parent_tree_item_id, $tree_item_id);
}
$tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='{$tree_id}'");
/* tree item ordering */
if ($tree_sort_type == TREE_ORDERING_NONE) {
/* resort our parent */
$parent_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id={$parent_tree_item_id}");
if (!empty($parent_tree_item_id) && $parent_sorting_type != TREE_ORDERING_NONE) {
sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $parent_sorting_type);
}
/* if this is a header, sort direct children */
if ($type == TREE_ITEM_TYPE_HEADER && $sort_children_type != TREE_ORDERING_NONE) {
sort_tree(SORT_TYPE_TREE_ITEM, $tree_item_id, $sort_children_type);
}
/* tree ordering */
} else {
/* potential speed savings for large trees */
if (tree_tier($save["order_key"]) == 1) {
sort_tree(SORT_TYPE_TREE, $tree_id, $tree_sort_type);
} else {
sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $tree_sort_type);
}
}
/* if the user checked the 'Propagate Changes' box */
if ($type == TREE_ITEM_TYPE_HEADER && $propagate_changes == true) {
$search_key = preg_replace("/0+\$/", "", $order_key);
$tree_items = db_fetch_assoc("select\n\t\t\t\t\tgraph_tree_items.id\n\t\t\t\t\tfrom graph_tree_items\n\t\t\t\t\twhere graph_tree_items.host_id = 0\n\t\t\t\t\tand graph_tree_items.local_graph_id = 0\n\t\t\t\t\tand graph_tree_items.title != ''\n\t\t\t\t\tand graph_tree_items.order_key like '{$search_key}%%'\n\t\t\t\t\tand graph_tree_items.graph_tree_id='{$tree_id}'");
if (sizeof($tree_items) > 0) {
foreach ($tree_items as $item) {
db_execute("update graph_tree_items set sort_children_type = '{$sort_children_type}' where id = '" . $item["id"] . "'");
if ($sort_children_type != TREE_ORDERING_NONE) {
sort_tree(SORT_TYPE_TREE_ITEM, $item["id"], $sort_children_type);
}
}
}
}
} else {
raise_message(2);
}
}
db_execute("UNLOCK TABLES");
return $tree_item_id;
}
开发者ID:teddywen,项目名称:cacti,代码行数:96,代码来源:api_tree.php
示例12: form_save
function form_save() {
require_once(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_constants.php");
if (isset($_POST["save_component_tree"])) {
$save["id"] = $_POST["id"];
$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
$save["sort_type"] = form_input_validate($_POST["sort_type"], "sort_type", "", true, 3);
if (!is_error_message()) {
$tree_id = sql_save($save, "graph_tree");
if ($tree_id) {
raise_message(1);
/* sort the tree using the algorithm chosen by the user */
sort_tree(SORT_TYPE_TREE, $tree_id, get_request_var_post("sort_type"));
}else{
raise_message(2);
}
}
if ((is_error_message()) || (empty($_POST["id"]))) {
header("Location: tree.php?action=edit&id=" . (empty($tree_id) ? $_POST["id"] : $tree_id));
}else{
header("Location: tree.php");
}
exit;
}elseif (isset($_POST["save_component_tree_item"])) {
$tree_item_id = api_tree_item_save($_POST["id"], $_POST["graph_tree_id"], $_POST["type"], $_POST["parent_item_id"],
(isset($_POST["title"]) ? $_POST["title"] : ""),
(isset($_POST["local_graph_id"]) ? $_POST["local_graph_id"] : "0"),
(isset($_POST["rra_id"]) ? $_POST["rra_id"] : "0"),
(isset($_POST["device_id"]) ? $_POST["device_id"] : "0"),
(isset($_POST["device_grouping_type"]) ? $_POST["device_grouping_type"] : "1"),
(isset($_POST["sort_children_type"]) ? $_POST["sort_children_type"] : "1"),
(isset($_POST["propagate_changes"]) ? true : false));
if (is_error_message()) {
header("Location: tree.php?action=item_edit&tree_item_id=" . (empty($tree_item_id) ? $_POST["id"] : $tree_item_id) . "&tree_id=" . $_POST["graph_tree_id"] . "&parent_id=" . $_POST["parent_item_id"]);
}else{
header("Location: tree.php?action=edit&id=" . $_POST["graph_tree_id"]);
}
exit;
}
}
开发者ID:songchin,项目名称:Cacti,代码行数:45,代码来源:tree.php
示例13: __
display_help($me);
exit(1);
}
$tree["id"] = 0; # create a new tree item
unset($tree["sort_type_cli"]); # remove for save
reset($tree);
if ($debug) {
print __("Save Tree Array:") . "\n";
print_r($tree);
} else {
$tree["id"] = sql_save($tree, "graph_tree");
if ($tree["id"] === 0) {
echo __("Failed to create Tree") . "\n";
} else {
sort_tree(SORT_TYPE_TREE, $tree["id"], $tree["sort_type"]);
echo __("Tree Created - tree-id: (%d)", $tree["id"]) . "\n";
}
}
break;
case (strtolower($tree_types[TREE_TYPE_NODE])):
# name is used both for tree and tree_items
if (isset($tree["name"])) $tree_item["title"] = $tree["name"];
if (isset($tree["sort_type_cli"])) $tree_item["sort_type_cli"] = $tree["sort_type_cli"];
if (isset($tree["id"])) $tree_item["graph_tree_id"] = $tree["id"];
# at least one matching criteria for tree item has to be defined
if (!sizeof($tree_item)) {
开发者ID:songchin,项目名称:Cacti,代码行数:31,代码来源:tree_create.php
示例14: form_save
function form_save()
{
/* clear graph tree cache on save - affects current user only, other users should see changes in <5 minutes */
if (isset($_SESSION['dhtml_tree'])) {
unset($_SESSION['dhtml_tree']);
}
if (isset($_POST["save_component_tree"])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post("id"));
/* ==================================================== */
$save["id"] = $_POST["id"];
$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
$save["sort_type"] = form_input_validate($_POST["sort_type"], "sort_type", "", true, 3);
if (!is_error_message()) {
$tree_id = sql_save($save, "graph_tree");
if ($tree_id) {
raise_message(1);
/* sort the tree using the algorithm chosen by the user */
sort_tree(SORT_TYPE_TREE, $tree_id, $_POST["sort_type"]);
} else {
raise_message(2);
}
}
header("Location: tree.php?action=edit&id=" . (empty($tree_id) ? $_POST["id"] : $tree_id));
} elseif (isset($_POST["save_component_tree_item"])) {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post("id"));
input_validate_input_number(get_request_var_post("graph_tree_id"));
input_validate_input_number(get_request_var_post("type"));
input_validate_input_number(get_request_var_post("parent_item_id"));
input_validate_input_number(get_request_var_post("local_graph_id"));
input_validate_input_number(get_request_var_post("host_id"));
input_validate_input_number(get_request_var_post("rra_id"));
input_validate_input_number(get_request_var_post("host_group_type"));
/* ==================================================== */
$tree_item_id = api_tree_item_save($_POST["id"], $_POST["graph_tree_id"], $_POST["type"], $_POST["parent_item_id"], isset($_POST["title"]) ? $_POST["title"] : "", isset($_POST["local_graph_id"]) ? $_POST["local_graph_id"] : "0", isset($_POST["rra_id"]) ? $_POST["rra_id"] : "0", isset($_POST["host_id"]) ? $_POST["host_id"] : "0", isset($_POST["host_grouping_type"]) ? $_POST["host_grouping_type"] : "1", isset($_POST["sort_children_type"]) ? $_POST["sort_children_type"] : "1", isset($_POST["propagate_changes"]) ? true : false);
if (is_error_message()) {
header("Location: tree.php?action=item_edit&tree_item_id=" . (empty($tree_item_id) ? $_POST["id"] : $tree_item_id) . "&tree_id=" . $_POST["graph_tree_id"] . "&parent_id=" . $_POST["parent_item_id"]);
} else {
header("Location: tree.php?action=edit&id=" . $_POST["graph_tree_id"]);
}
}
}
开发者ID:teddywen,项目名称:cacti,代码行数:43,代码来源:tree.php
示例15: load_categories
function load_categories($filtering = false, $showsmart = false, $results = false)
{
$db = DB::get();
if (empty($filtering['columns'])) {
$filtering['columns'] = "cat.id,cat.parent,cat.name,cat.description,cat.uri,cat.slug,count(DISTINCT pd.id) AS total,IF(SUM(IF(pt.inventory='off',1,0) OR pt.inventory IS NULL)>0,'off','on') AS inventory, SUM(pt.stock) AS stock";
}
if (!empty($filtering['limit'])) {
$filtering['limit'] = "LIMIT " . $filtering['limit'];
} else {
$filtering['limit'] = "";
}
// if (!$this->outofstock) $filtering['where'] .= (empty($filtering['where'])?"":" AND ")."(pt.inventory='off' OR (pt.inventory='on' AND pt.stock > 0))";
if (empty($filtering['where'])) {
$filtering['where'] = "true";
}
if (empty($filtering['orderby'])) {
$filtering['orderby'] = "name";
}
switch (strtolower($filtering['orderby'])) {
case "id":
$orderby = "cat.id";
break;
case "slug":
$orderby = "cat.slug";
break;
case "count":
$orderby = "total";
break;
default:
$orderby = "cat.name";
}
if (empty($filtering['order'])) {
$filtering['order'] = "ASC";
}
switch (strtoupper($filtering['order'])) {
case "DESC":
$order = "DESC";
break;
default:
$order = "ASC";
}
$category_table = DatabaseObject::tablename(Category::$table);
$product_table = DatabaseObject::tablename(Product::$table);
$price_table = Databa
|
请发表评论