/** * Get the parent permalink */ function get_parent_url() { global $post; $parent = get_parent_id(); if ($parent > 0) { return get_permalink($parent); } elseif (is_single() && get_post_type() == 'opportunity') { $opps_page = get_field('opportunities_listing_page', 'option'); return get_permalink($opps_page->post_parent); } elseif (is_single() && get_post_type() == 'event') { $opps_page = get_field('programs_listing_page', 'option'); return get_permalink($opps_page->ID); } elseif (is_archive()) { return get_permalink(get_option('page_for_posts')); } else { return false; } }
function reparent_branch($new_parent_id, $tree_item_id) { if (empty($tree_item_id)) { return 0; } /* get the current tree_id */ $graph_tree_id = db_fetch_cell("select graph_tree_id from graph_tree_items where id={$tree_item_id}"); /* make sure the parent id actually changed */ if (get_parent_id($tree_item_id, "graph_tree_items", "graph_tree_id={$graph_tree_id}") == $new_parent_id) { return 0; } /* get current key so we can do a sql select on it */ $old_order_key = db_fetch_cell("select order_key from graph_tree_items where id={$tree_item_id}"); $new_order_key = get_next_tree_id(db_fetch_cell("select order_key from graph_tree_items where id={$new_parent_id}"), "graph_tree_items", "order_key", "graph_tree_id={$graph_tree_id}"); /* yeah, this would be really bad */ if (empty($old_order_key)) { return 0; } $old_starting_tier = tree_tier($old_order_key); $new_starting_tier = tree_tier($new_order_key); $new_base_tier = substr($new_order_key, 0, $new_starting_tier * CHARS_PER_TIER); $old_base_tier = substr($old_order_key, 0, $old_starting_tier * CHARS_PER_TIER); /* prevent possible collisions */ db_execute("update graph_tree_items set order_key = CONCAT('x',order_key) where order_key like '{$old_base_tier}%%' and graph_tree_id={$graph_tree_id}"); /* truncate */ if ($new_starting_tier >= $old_starting_tier) { db_execute("update graph_tree_items set order_key = SUBSTRING(REPLACE(order_key, 'x{$old_base_tier}', '{$new_base_tier}'), 1, " . MAX_TREE_DEPTH * CHARS_PER_TIER . ") where order_key like 'x{$old_base_tier}%%' and graph_tree_id={$graph_tree_id}"); /* append */ } else { db_execute("update graph_tree_items set order_key = CONCAT(REPLACE(order_key, 'x{$old_base_tier}', '{$new_base_tier}'), '" . str_repeat('0', strlen($old_base_tier) - strlen($new_base_tier)) . "') where order_key like 'x{$old_base_tier}%%' and graph_tree_id={$graph_tree_id}"); } }
function explore_tree($path, $tree_id, $parent_tree_item_id) { /* seek graph_tree_items of the tree_id which are NOT graphs but headers */ $links = db_fetch_assoc("SELECT\n\t\tid,\n\t\ttitle,\n\t\thost_id\n\t\tFROM graph_tree_items\n\t\tWHERE rra_id = 0\n\t\tAND graph_tree_id = " . $tree_id); $total_graphs_created = 0; foreach ($links as $link) { /* this test gives us the parent of the curent graph_tree_item */ if (get_parent_id($link["id"], "graph_tree_items", "graph_tree_id = " . $tree_id) == $parent_tree_item_id) { if (get_tree_item_type($link["id"]) == "host") { if (read_config_option("export_tree_isolation") == "off") { $total_graphs_created += export_build_tree_single(clean_up_export_name($path), clean_up_export_name(get_host_description($link["host_id"]) . "_" . $link["id"] . ".html"), $tree_id, $link["id"]); } else { $total_graphs_created += export_build_tree_isolated(clean_up_export_name($path), clean_up_export_name(get_host_description($link["host_id"]) . "_" . $link["id"] . ".html"), $tree_id, $link["id"]); } } else { /*now, this graph_tree_item is the parent of others graph_tree_items*/ if (read_config_option("export_tree_isolation") == "off") { $total_graphs_created += export_build_tree_single(clean_up_export_name($path), clean_up_export_name($link["title"] . "_" . $link["id"] . ".html"), $tree_id, $link["id"]); } else { $total_graphs_created += export_build_tree_isolated(clean_up_export_name($path), clean_up_export_name($link["title"] . "_" . $link["id"] . ".html"), $tree_id, $link["id"]); } } } } return $total_graphs_created; }
public static function makeList() { global $lng, $coach, $settings; HTMLOUT::frame_begin(); # Make page frame, banner and menu. title($lng->getTrn('name', __CLASS__)); echo $lng->getTrn('desc', __CLASS__) . "<br><br>\n"; list($sel_node, $sel_node_id) = HTMLOUT::nodeSelector(array()); $ALLOW_EDIT = is_object($coach) && $coach->isNodeCommish($sel_node, $sel_node_id); /* A new entry was sent. Add it to system */ if ($ALLOW_EDIT && isset($_POST['tid']) && isset($_POST['trid'])) { if (get_magic_quotes_gpc()) { $_POST['title'] = stripslashes($_POST['title']); $_POST['txt'] = stripslashes($_POST['txt']); } switch ($_GET['action']) { case 'new': status(self::create($_POST['ptype'], $_POST['tid'], $_POST['trid'], $_POST['title'], $_POST['txt'])); break; } } /* Was a request for a new entry made? */ if (isset($_GET['action']) && $ALLOW_EDIT) { switch ($_GET['action']) { case 'delete': if (isset($_GET['prid']) && is_numeric($_GET['prid'])) { $pr = new Prize($_GET['prid']); status($pr->delete()); unset($pr); } else { fatal('Sorry. You did not specify which prize ID you wish to delete.'); } break; case 'new': echo "<a href='handler.php?type=prize'><-- " . $lng->getTrn('common/back') . "</a><br><br>"; $_DISABLED = !isset($_POST['trid']) ? 'DISABLED' : ''; ?> <form name="STS" method="POST" enctype="multipart/form-data"> <b><?php echo $lng->getTrn('common/tournament'); ?> </b><br> <?php echo HTMLOUT::nodeList(T_NODE_TOURNAMENT, 'trid'); ?> <input type='submit' value='<?php echo $lng->getTrn('common/select'); ?> '> </form> <br> <form method="POST" enctype="multipart/form-data"> <b><?php echo $lng->getTrn('team', __CLASS__); ?> </b><br> <select name="tid" <?php echo $_DISABLED; ?> > <?php $teams = isset($_POST['trid']) ? Team::getTeams(false, array(get_parent_id(T_NODE_TOURNAMENT, (int) $_POST['trid'], T_NODE_LEAGUE)), true) : array(); foreach ($teams as $tid => $name) { echo "<option value='{$tid}'>{$name}</option>\n"; } ?> </select> <br><br> <b><?php echo $lng->getTrn('kind', __CLASS__); ?> </b><br> <select name="ptype" <?php echo $_DISABLED; ?> > <?php foreach (self::getTypes() as $ptype => $desc) { echo "<option value='{$ptype}'>{$desc}</option>\n"; } ?> </select> <br><br> <?php echo '<b>' . $lng->getTrn('g_title', __CLASS__) . '</b> — ' . $lng->getTrn('title', __CLASS__); ?> <br> <input type="text" name="title" size="60" maxlength="100" value="" <?php echo $_DISABLED; ?> > <br><br> <?php echo '<b>' . $lng->getTrn('g_about', __CLASS__) . '</b> — ' . $lng->getTrn('about', __CLASS__); ?> <br> <textarea name="txt" rows="15" cols="100" <?php echo $_DISABLED; ?> ></textarea> <br><br><br> <input type='hidden' name='trid' value='<?php echo $_DISABLED ? 0 : $_POST['trid']; ?> '> <input type="submit" value="<?php echo $lng->getTrn('submit', __CLASS__); ?> " name="Submit" <?php echo $_DISABLED; ?> > </form> <br> <?php return; break; } } if ($ALLOW_EDIT) { echo "<br><a href='handler.php?type=prize&action=new'>" . $lng->getTrn('new', __CLASS__) . "</a><br>\n"; } /* Print the prizes */ self::printList($sel_node, $sel_node_id, $ALLOW_EDIT); HTMLOUT::frame_end(); }
break; /* Name autocompletion - AJAX */ /* Name autocompletion - AJAX */ case 'autocomplete': $objs = array(); switch ($_GET['obj']) { case T_OBJ_COACH: $query = "SELECT coach_id AS 'id', name FROM coaches WHERE name LIKE '{$_GET['query']}%' ORDER BY name ASC"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $objs[$row['id']] = $row['name']; } break; case T_OBJ_TEAM: $lid = isset($_GET['trid']) ? get_parent_id(T_NODE_TOURNAMENT, (int) $_GET['trid'], T_NODE_LEAGUE) : false; $did = $lid && get_alt_col('leagues', 'lid', $lid, 'tie_teams') == 1 ? get_parent_id(T_NODE_TOURNAMENT, (int) $_GET['trid'], T_NODE_DIVISION) : false; $FROM_lid = $lid ? "f_lid = {$lid} AND" : ''; $FROM_did = $did ? "f_did = {$did} AND" : ''; $query = "SELECT team_id AS 'id', name, rdy FROM teams WHERE {$FROM_lid} {$FROM_did} name LIKE '%{$_GET['query']}%' ORDER BY name ASC"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $objs[$row['id']] = $row['name']; } break; } echo json_encode(array('query' => $_GET['query'], 'suggestions' => array_values($objs), 'data' => array_keys($objs))); break; /* League Tables */ /* League Tables */ case 'scheduler': $subtype = '';
public static function getSelectedNodeLid() { global $leagues; $lids = array_keys($leagues); $_lid = false; if (isset($_SESSION[self::T_NSStr__node_id]) && (int) $_SESSION[self::T_NSStr__node_id] > 0) { $_lid = (int) $_SESSION[self::T_NSStr__node] != T_NODE_LEAGUE ? get_parent_id((int) $_SESSION[self::T_NSStr__node], (int) $_SESSION[self::T_NSStr__node_id], T_NODE_LEAGUE) : (int) $_SESSION[self::T_NSStr__node_id]; if (!in_array($_lid, $lids)) { $_lid = false; } } return $_lid; }
function get_all_cat($fid) { global $db, $pre; $query = $db->query("SELECT * FROM {$pre}sort WHERE fup=0"); while ($rs = $db->fetch_array($query)) { $listdb[] = $rs; } foreach ($listdb as $key => $row) { $curpid = get_parent_id($fid); $pid = get_parent_id($row['fid']); $ishighlight = $curpid == $pid ? 1 : 0; $arr[$key] = array('pid' => $pid, 'fid' => $row['fid'], 'name' => $row['name'], 'sid' => get_sub_cat($row['fid']), 'ishighlight' => $ishighlight); } return $arr; }
function get_parent_name($type, $id, $parent_type) { global $relations_node, $relations_obj; $relations = in_array($type, array_keys($relations_node)) ? $relations_node : $relations_obj; return get_alt_col($relations[$parent_type]['tbl'], $relations[$parent_type]['id'], get_parent_id($type, $id, $parent_type), 'name'); }
public static function create(array $input) { /** * Creates a new match. * * Input: team1_id, team2_id, round, f_tour_id **/ global $settings; # Used multiple times in error conditions below. $tour__f_lid = (int) get_parent_id(T_NODE_TOURNAMENT, (int) $input['f_tour_id'], T_NODE_LEAGUE); $tour__f_did = (int) get_parent_id(T_NODE_TOURNAMENT, (int) $input['f_tour_id'], T_NODE_DIVISION); $t1__f_lid = (int) get_alt_col('teams', 'team_id', $input['team1_id'], 'f_lid'); $t2__f_lid = (int) get_alt_col('teams', 'team_id', $input['team2_id'], 'f_lid'); $t1__f_did = (int) get_alt_col('teams', 'team_id', $input['team1_id'], 'f_did'); $t2__f_did = (int) get_alt_col('teams', 'team_id', $input['team2_id'], 'f_did'); $errors = array(self::T_CREATE_ERROR__IDENTICAL_TEAM_IDS => (int) $input['team1_id'] == (int) $input['team2_id'], self::T_CREATE_ERROR__IDENTICAL_PARENT_COACH => (int) get_alt_col('teams', 'team_id', $input['team1_id'], 'owned_by_coach_id') == (int) get_alt_col('teams', 'team_id', $input['team2_id'], 'owned_by_coach_id'), self::T_CREATE_ERROR__PARENT_TOUR_LOCKED => (bool) get_alt_col('tours', 'tour_id', $input['f_tour_id'], 'locked'), self::T_CREATE_ERROR__TEAM_LEAGUE_IDS_DIFFER => $t1__f_lid != $t2__f_lid, self::T_CREATE_ERROR__TEAM_DIVISION_IDS_DIFFER => (bool) get_alt_col('leagues', 'lid', $tour__f_lid, 'tie_teams') && $t1__f_did != $t2__f_did, self::T_CREATE_ERROR__ILLEGAL_PARENT_LID_OF_TOUR => $t1__f_lid != $tour__f_lid || $t2__f_lid != $tour__f_lid, self::T_CREATE_ERROR__ILLEGAL_PARENT_DID_OF_TOUR => (bool) get_alt_col('leagues', 'lid', $tour__f_lid, 'tie_teams') && ($t1__f_did != $tour__f_did || $t2__f_did != $tour__f_did)); foreach ($errors as $exitStatus => $halt) { if ($halt) { return array($exitStatus, null); } } $query = "INSERT INTO matches (team1_id, team2_id, round, f_tour_id, date_created)\n VALUES ({$input['team1_id']}, {$input['team2_id']}, {$input['round']}, '{$input['f_tour_id']}', NOW())"; if (mysql_query($query)) { $mid = mysql_insert_id(); } else { self::$T_CREATE_SQL_ERROR['query'] = $query; self::$T_CREATE_SQL_ERROR['error'] = mysql_error(); return array(self::T_CREATE_ERROR__SQL_QUERY_FAIL, null); } Module::runTriggers(T_TRIGGER_MATCH_CREATE, array($mid)); return array(self::T_CREATE_SUCCESS, $mid); }
function item_edit() { global $colors; require(CACTI_BASE_PATH . "/include/data_query/data_query_arrays.php"); require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("tree_id")); /* ==================================================== */ if (!empty($_GET["id"])) { $tree_item = db_fetch_row("select * from graph_tree_items where id=" . $_GET["id"]); if ($tree_item["local_graph_id"] > 0) { $db_type = TREE_ITEM_TYPE_GRAPH; } if ($tree_item["title"] != "") { $db_type = TREE_ITEM_TYPE_HEADER; } if ($tree_item["device_id"] > 0) { $db_type = TREE_ITEM_TYPE_DEVICE; } } if (isset($_GET["type_select"])) { $current_type = $_GET["type_select"]; }elseif (isset($db_type)) { $current_type = $db_type; }else{ $current_type = TREE_ITEM_TYPE_HEADER; } $tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='" . $_GET["tree_id"] . "'"); print "<form action='tree.php' name='form_tree' method='post'>\n"; html_start_box("<strong>" . __("Tree Items") . "</strong>", "100", $colors["header"], "3", "center", ""); form_alternate_row_color("parent_item"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Parent Item");?></font><br> <?php print __("Choose the parent for this header/graph.");?> </td> <td> <?php grow_dropdown_tree($_GET["tree_id"], "parent_item_id", (isset($_GET["parent_id"]) ? $_GET["parent_id"] : get_parent_id($tree_item["id"], "graph_tree_items", "graph_tree_id=" . $_GET["tree_id"])));?> </td> <?php form_end_row(); form_alternate_row_color("tree_item"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Tree Item Type");?></font><br> <?php print __("Choose what type of tree item this is.");?> </td> <td> <select name="type_select" onChange="window.location=document.form_tree.type_select.options[document.form_tree.type_select.selectedIndex].value"> <?php while (list($var, $val) = each($tree_item_types)) { print "<option value='" . htmlspecialchars("tree.php?action=item_edit" . (isset($_GET["id"]) ? "&id=" . $_GET["id"] : "") . (isset($_GET["parent_id"]) ? "&parent_id=" . $_GET["parent_id"] : "") . "&tree_id=" . $_GET["tree_id"] . "&type_select=" . $var) . "'"; if ($var == $current_type) { print " selected"; } print ">$val</option>\n"; } ?> </select> </td> <?php form_end_row(); ?> <tr class='rowSubHeader'> <td colspan="2" class='textSubHeaderDark'><?php print __("Tree Item Value");?></td> </tr> <?php switch ($current_type) { case TREE_ITEM_TYPE_HEADER: $i = 0; /* it's nice to default to the parent sorting style for new items */ if (empty($_GET["id"])) { $default_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=" . $_GET["parent_id"]); }else{ $default_sorting_type = DATA_QUERY_INDEX_SORT_TYPE_NONE; } form_alternate_row_color("item_title"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Title");?></font><br> <?php print __("If this item is a header, enter a title here.");?> </td> <td> <?php form_text_box("title", (isset($tree_item["title"]) ? $tree_item["title"] : ""), "", "255", 30, "text", (isset($_GET["id"]) ? $_GET["id"] : "0"));?> </td> <?php form_end_row(); /* don't allow the user to change the tree item ordering if a tree order has been specified */ if ($tree_sort_type == DATA_QUERY_INDEX_SORT_TYPE_NONE) { form_alternate_row_color("sorting_type"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Sorting Type");?></font><br> <?php print __("Choose how children of this branch will be sorted.");?> </td> <td> <?php form_dropdown("sort_children_type", $tree_sort_types, "", "", (isset($tree_item["sort_children_type"]) ? $tree_item["sort_children_type"] : $default_sorting_type), "", "");?> </td> <?php form_end_row(); } if ((!empty($_GET["id"])) && ($tree_sort_type == DATA_QUERY_INDEX_SORT_TYPE_NONE)) { form_alternate_row_color("propagate"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Propagate Changes");?></font><br> <?php print __("Propagate all options on this form (except for 'Title') to all child 'Header' items.");?> </td> <td> <?php form_checkbox("propagate_changes", "", __("Propagate Changes"), "", "", "", 0);?> </td> <?php form_end_row(); } break; case TREE_ITEM_TYPE_GRAPH: form_alternate_row_color("graph"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Graph");?></font><br> <?php print __("Choose a graph from this list to add it to the tree.");?> </td> <td> <?php form_dropdown("local_graph_id", db_fetch_assoc("select graph_templates_graph.local_graph_id as id,graph_templates_graph.title_cache as name from (graph_templates_graph,graph_local) where graph_local.id=graph_templates_graph.local_graph_id and local_graph_id != 0 order by title_cache"), "name", "id", (isset($tree_item["local_graph_id"]) ? $tree_item["local_graph_id"] : ""), "", "");?> </td> <?php form_end_row(); form_alternate_row_color("rra"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Round Robin Archive");?></font><br> <?php print __("Choose a round robin archive to control how this graph is displayed.");?> </td> <td> <?php form_dropdown("rra_id", db_fetch_assoc("select id,name from rra order by timespan"), "name", "id", (isset($tree_item["rra_id"]) ? $tree_item["rra_id"] : ""), "", "");?> </td> <?php form_end_row(); break; case TREE_ITEM_TYPE_DEVICE: form_alternate_row_color("device"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Host");?></font><br> <?php print __("Choose a device here to add it to the tree.");?> </td> <td> <?php form_dropdown("device_id", db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from device order by description,hostname"), "name", "id", (isset($tree_item["device_id"]) ? $tree_item["device_id"] : ""), "", "");?> </td> <?php form_end_row(); form_alternate_row_color("graph_grouping"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Graph Grouping Style");?></font><br> <?php print __("Choose how graphs are grouped when drawn for this particular device on the tree.");?> </td> <td> <?php form_dropdown("device_grouping_type", $tree_device_group_types, "", "", (isset($tree_item["device_grouping_type"]) ? $tree_item["device_grouping_type"] : "1"), "", "");?> </td> <?php form_end_row(); break; } html_end_box(); form_hidden_box("id", (isset($_GET["id"]) ? $_GET["id"] : "0"), ""); form_hidden_box("graph_tree_id", get_request_var("tree_id"), ""); form_hidden_box("type", $current_type, ""); form_hidden_box("save_component_tree_item", "1", ""); form_save_button_alt("path!tree.php|action!edit|id!" . get_request_var("tree_id")); }
// Teams $team_ids = explode(',', $_POST['teams']); $teamsCount = count($team_ids); // Shortcut booleans: $mkNewFFA = $_POST['type'] == 'FFA_TOUR'; $addMatchToFFA = $_POST['type'] == 'FFA_SINGLE'; $nameSet = isset($_POST['name']) && !empty($_POST['name']) && !ctype_space($_POST['name']); /* Error condition definitions. */ /* Here we test for illegal pair-ups due to league and division relations. Normally Match::create() does this too, but we don't want to end up creating a long list of matches first, but then have to abort because (for example) the last pair of teams are an illegal paring. */ $teams_OK['l'] = $teams_OK['d'] = true; $lid = ($GOT_DID = $_POST['type'] == 'RR_TOUR' || $mkNewFFA) ? get_parent_id(T_NODE_DIVISION, $_POST['did'], T_NODE_LEAGUE) : get_parent_id(T_NODE_TOURNAMENT, $_POST['existTour'], T_NODE_LEAGUE); $did = $GOT_DID ? $_POST['did'] : get_parent_id(T_NODE_TOURNAMENT, $_POST['existTour'], T_NODE_DIVISION); $TIE_TEAMS = get_alt_col('leagues', 'lid', $lid, 'tie_teams'); foreach ($team_ids as $tid) { $query = "SELECT (t.f_did = {$did}) AS 'in_did', (t.f_lid = {$lid}) AS 'in_lid' FROM teams AS t WHERE t.team_id = {$tid}"; $result = mysql_query($query); if ($result) { $state = mysql_fetch_assoc($result); if (!$state['in_lid']) { $teams_OK['l'] = false; break; } if ($TIE_TEAMS && !$state['in_did']) { $teams_OK['d'] = false; break; } }
display_help($me); exit(1); } if (!strlen($sql_vars)) { # no sql updates required $sql = ""; } else { $sql .= $sql_vars . " WHERE id=" . $tree_item["id"]; } if (!$debug) { if (strlen($sql)) { # if only reparent action required, sql may be empty db_execute($sql); } /* re-parent the branch if the parent item has changed */ if (isset($tree_item["parent_node"])) { $current_parent = get_parent_id($tree_item["id"], "graph_tree_items"); if ($tree_item["parent_node"] != $current_parent) { reparent_branch($tree_item["parent_node"], $tree_item["id"]); } } echo __("Success - Tree item updated (%s)", $tree_item["id"]) . "\n"; } else { print $sql . "\n"; } break; default: echo __("ERROR: Unknown type: (%s)", $type) . "\n"; display_help($me); exit(1);
function reparent_branch($new_parent_id, $tree_item_id) { if (empty($tree_item_id)) { return 0; } /* get the current tree_id */ $graph_tree_id = db_fetch_cell("select graph_tree_id from graph_tree_items where id=$tree_item_id"); /* make sure the parent id actually changed */ if (get_parent_id($tree_item_id, "graph_tree_items", "graph_tree_id=$graph_tree_id") == $new_parent_id) { return 0; } /* get current key so we can do a sql select on it */ $old_order_key = db_fetch_cell("select order_key from graph_tree_items where id=$tree_item_id"); $new_order_key = get_next_tree_id(db_fetch_cell("select order_key from graph_tree_items where id=$new_parent_id"), "graph_tree_items", "order_key", "graph_tree_id=$graph_tree_id"); /* yeah, this would be really bad */ if (empty($old_order_key)) { return 0; } $old_starting_tier = tree_tier($old_order_key); $new_starting_tier = tree_tier($new_order_key); $new_base_tier = substr($new_order_key, 0, ($new_starting_tier * CHARS_PER_TIER)); $old_base_tier = substr($old_order_key, 0, ($old_starting_tier * CHARS_PER_TIER)); /* prevent possible collisions */ db_execute("update graph_tree_items set order_key = ".sql_function_concat("'x'","order_key")." where order_key like '$old_base_tier%%' and graph_tree_id=$graph_tree_id"); /* truncate */ if ($new_starting_tier >= $old_starting_tier) { db_execute("update graph_tree_items set order_key = ".sql_function_substr()."(".sql_function_replace()."(order_key, 'x$old_base_tier', '$new_base_tier'), 1, " . (MAX_TREE_DEPTH * CHARS_PER_TIER) . ") where order_key like 'x$old_base_tier%%' and graph_tree_id=$graph_tree_id"); /* append */ }else{ db_execute("update graph_tree_items set order_key = ".sql_function_concat(sql_function_replace()."(order_key, 'x$old_base_tier', '$new_base_tier')"," '" . str_repeat('0', (strlen($old_base_tier) - strlen($new_base_tier))) . "'")." where order_key like 'x$old_base_tier%%' and graph_tree_id=$graph_tree_id"); } }
function item_edit() { global $colors, $tree_sort_types; global $tree_item_types, $host_group_types; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("tree_id")); /* ==================================================== */ /* modify for multi user start */ $public_tree = FALSE; if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) { if ($_GET["tree_id"] == $_SESSION["public_tree_id"]) { $public_tree = TRUE; } else { if (!empty($_GET["id"])) { if (!check_tree_item($_GET["id"])) { access_denied(); } } } } /* modify for multi user end */ if (!empty($_GET["id"])) { $tree_item = db_fetch_row("select * from graph_tree_items where id=" . get_request_var("id")); if ($tree_item["local_graph_id"] > 0) { $db_type = TREE_ITEM_TYPE_GRAPH; } if ($tree_item["title"] != "") { $db_type = TREE_ITEM_TYPE_HEADER; } if ($tree_item["host_id"] > 0) { $db_type = TREE_ITEM_TYPE_HOST; } } if (isset($_GET["type_select"])) { $current_type = $_GET["type_select"]; } elseif (isset($db_type)) { $current_type = $db_type; } else { $current_type = TREE_ITEM_TYPE_HEADER; } $tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='" . get_request_var("tree_id") . "'"); print "<form method='post' action='tree.php' name='form_tree'>\n"; html_start_box("<strong>Tree Items</strong>", "100%", $colors["header"], "3", "center", ""); form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0); ?> <td width="50%"> <font class="textEditTitle">Parent Item</font><br> Choose the parent for this header/graph. </td> <td> <?php grow_dropdown_tree($_GET["tree_id"], "parent_item_id", isset($_GET["parent_id"]) ? $_GET["parent_id"] : get_parent_id($tree_item["id"], "graph_tree_items", "graph_tree_id=" . $_GET["tree_id"])); ?> </td> </tr> <?php form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1); ?> <td width="50%"> <font class="textEditTitle">Tree Item Type</font><br> Choose what type of tree item this is. </td> <td> <select name="type_select" onChange="window.location=document.form_tree.type_select.options[document.form_tree.type_select.selectedIndex].value"> <?php /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { if (!db_fetch_cell("\r\n SELECT COUNT(graph_local.id) FROM graph_local\r\n INNER JOIN host ON graph_local.host_id = host.id\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'")) { unset($tree_item_types[2]); // graph } if (!db_fetch_cell("\r\n SELECT COUNT(host.id) FROM host\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'")) { unset($tree_item_types[3]); // host } if ($public_tree == TRUE) { unset($tree_item_types[1]); // header unset($tree_item_types[3]); // host $current_type = 2; } } /* modify for multi user end */ while (list($var, $val) = each($tree_item_types)) { print "<option value='tree.php?action=item_edit" . (isset($_GET["id"]) ? "&id=" . $_GET["id"] : "") . (isset($_GET["parent_id"]) ? "&parent_id=" . $_GET["parent_id"] : "") . "&tree_id=" . $_GET["tree_id"] . "&type_select={$var}'"; if ($var == $current_type) { print " selected"; } print ">{$val}</option>\n"; } ?> </select> </td> </tr> <tr bgcolor='#<?php print $colors["header_panel"]; ?> '> <td colspan="2" class='textSubHeaderDark'>Tree Item Value</td> </tr> <?php switch ($current_type) { case TREE_ITEM_TYPE_HEADER: $i = 0; /* it's nice to default to the parent sorting style for new items */ if (empty($_GET["id"])) { $default_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=" . $_GET["parent_id"]); } else { $default_sorting_type = TREE_ORDERING_NONE; } form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i); $i++; ?> <td width="50%"> <font class="textEditTitle">Title</font><br> If this item is a header, enter a title here. </td> <td> <?php form_text_box("title", isset($tree_item["title"]) ? $tree_item["title"] : "", "", "255", 30, "text", isset($_GET["id"]) ? $_GET["id"] : "0"); ?> </td> </tr> <?php /* don't allow the user to change the tree item ordering if a tree order has been specified */ if ($tree_sort_type == TREE_ORDERING_NONE) { form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i); $i++; ?> <td width="50%"> <font class="textEditTitle">Sorting Type</font><br> Choose how children of this branch will be sorted. </td> <td> <?php form_dropdown("sort_children_type", $tree_sort_types, "", "", isset($tree_item["sort_children_type"]) ? $tree_item["sort_children_type"] : $default_sorting_type, "", ""); ?> </td> </tr> <?php } if (!empty($_GET["id"]) && $tree_sort_type == TREE_ORDERING_NONE) { form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i); $i++; ?> <td width="50%"> <font class="textEditTitle">Propagate Changes</font><br> Propagate all options on this form (except for 'Title') to all child 'Header' items. </td> <td> <?php form_checkbox("propagate_changes", "", "Propagate Changes", "", "", "", 0); ?> </td> </tr> <?php } break; case TREE_ITEM_TYPE_GRAPH: form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0); ?> <td width="50%"> <font class="textEditTitle">Graph</font><br> Choose a graph from this list to add it to the tree. </td> <td> <?php /* modify for multi user start */ if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) { form_dropdown("local_graph_id", db_fetch_assoc("\r\n \tSELECT graph_templates_graph.local_graph_id as id,graph_templates_graph.title_cache as name FROM graph_templates_graph \r\n INNER JOIN graph_local ON graph_templates_graph.local_graph_id = graph_local.id\r\n INNER JOIN host ON graph_local.host_id = host.id\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n WHERE graph_templates_graph.local_graph_id != 0 \r\n ORDER BY graph_templates_graph.title_cache"), "name", "id", isset($tree_item["local_graph_id"]) ? $tree_item["local_graph_id"] : "", "", ""); } else { form_dropdown("local_graph_id", db_fetch_assoc("select graph_templates_graph.local_graph_id as id,graph_templates_graph.title_cache as name from (graph_templates_graph,graph_local) where graph_local.id=graph_templates_graph.local_graph_id and local_graph_id != 0 order by title_cache"), "name", "id", isset($tree_item["local_graph_id"]) ? $tree_item["local_graph_id"] : "", "", ""); } /* modify for multi user end */ ?> </td> </tr> <?php form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1); ?> <td width="50%"> <font class="textEditTitle">Round Robin Archive</font><br> Choose a round robin archive to control how the Graph Thumbnail is displayed when using Tree Export. </td> <td> <?php form_dropdown("rra_id", db_fetch_assoc("select id,name from rra order by timespan"), "name", "id", isset($tree_item["rra_id"]) ? $tree_item["rra_id"] : "", "", ""); ?> </td> </tr> <?php break; case TREE_ITEM_TYPE_HOST: form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0); ?> <td width="50%"> <font class="textEditTitle">Host</font><br> Choose a host here to add it to the tree. </td> <td> <?php /* modify for multi user start */ if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) { form_dropdown("host_id", db_fetch_assoc("\r\n\t\t\t\t\t\tSELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') as name FROM host\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n ORDER BY host.description,host.hostname"), "name", "id", isset($tree_item["host_id"]) ? $tree_item["host_id"] : "", "", ""); } else { form_dropdown("host_id", db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "name", "id", isset($tree_item["host_id"]) ? $tree_item["host_id"] : "", "", ""); } /* modify for multi user end */ ?> </td> </tr> <?php form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1); ?> <td width="50%"> <font class="textEditTitle">Graph Grouping Style</font><br> Choose how graphs are grouped when drawn for this particular host on the tree. </td> <td> <?php form_dropdown("host_grouping_type", $host_group_types, "", "", isset($tree_item["host_grouping_type"]) ? $tree_item["host_grouping_type"] : "1", "", ""); ?> </td> </tr> <?php form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1); ?> <td width="50%"> <font class="textEditTitle">Round Robin Archive</font><br> Choose a round robin archive to control how Graph Thumbnails are displayed when using Tree Export. </td> <td> <?php form_dropdown("rra_id", db_fetch_assoc("select id,name from rra order by timespan"), "name", "id", isset($tree_item["rra_id"]) ? $tree_item["rra_id"] : "", "", ""); ?> </td> </tr> <?php break; } ?> </tr> <?php form_hidden_box("id", isset($_GET["id"]) ? $_GET["id"] : "0", ""); form_hidden_box("graph_tree_id", $_GET["tree_id"], ""); form_hidden_box("type", $current_type, ""); form_hidden_box("save_component_tree_item", "1", ""); html_end_box(); form_save_button("tree.php?action=edit&id=" . $_GET["tree_id"]); }
function item_edit() { global $colors, $tree_sort_types; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("tree_id")); /* ==================================================== */ $tree_item_types = array( TREE_ITEM_TYPE_HEADER => "Header", TREE_ITEM_TYPE_GRAPH => "Graph", TREE_ITEM_TYPE_HOST => "Host" ); $host_group_types = array( HOST_GROUPING_GRAPH_TEMPLATE => "Graph Template", HOST_GROUPING_DATA_QUERY_INDEX => "Data Query Index" ); if (!empty($_GET["id"])) { $tree_item = db_fetch_row("select * from graph_tree_items where id=" . $_GET["id"]); if ($tree_item["local_graph_id"] > 0) { $db_type = TREE_ITEM_TYPE_GRAPH; } if ($tree_item["title"] != "") { $db_type = TREE_ITEM_TYPE_HEADER; } if ($tree_item["host_id"] > 0) { $db_type = TREE_ITEM_TYPE_HOST; } } if (isset($_GET["type_select"])) { $current_type = $_GET["type_select"]; }elseif (isset($db_type)) { $current_type = $db_type; }else{ $current_type = TREE_ITEM_TYPE_HEADER; } $tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='" . $_GET["tree_id"] . "'"); html_start_box("<strong>Tree Items</strong>", "100%", $colors["header"], "3", "center", ""); print "<form method='post' action='tree.php' name='form_tree'>\n"; form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?> <td width="50%"> <font class="textEditTitle">Parent Item</font><br> Choose the parent for this header/graph. </td> <td> <?php grow_dropdown_tree($_GET["tree_id"], "parent_item_id", (isset($_GET["parent_id"]) ? $_GET["parent_id"] : get_parent_id($tree_item["id"], "graph_tree_items", "graph_tree_id=" . $_GET["tree_id"])));?> </td> </tr> <?php form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1); ?> <td width="50%"> <font class="textEditTitle">Tree Item Type</font><br> Choose what type of tree item this is. </td> <td> <select name="type_select" onChange="window.location=document.form_tree.type_select.options[document.form_tree.type_select.selectedIndex].value"> <?php while (list($var, $val) = each($tree_item_types)) { print "<option value='tree.php?action=item_edit" . (isset($_GET["id"]) ? "&id=" . $_GET["id"] : "") . (isset($_GET["parent_id"]) ? "&parent_id=" . $_GET["parent_id"] : "") . "&tree_id=" . $_GET["tree_id"] . "&type_select=$var'"; if ($var == $current_type) { print " selected"; } print ">$val</option>\n"; } ?> </select> </td> </tr> <tr bgcolor='#<?php print $colors["header_panel"];?>'> <td colspan="2" class='textSubHeaderDark'>Tree Item Value</td> </tr> <?php switch ($current_type) { case TREE_ITEM_TYPE_HEADER: $i = 0; /* it's nice to default to the parent sorting style for new items */ if (empty($_GET["id"])) { $default_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=" . $_GET["parent_id"]); }else{ $default_sorting_type = TREE_ORDERING_NONE; } form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++; ?> <td width="50%"> <font class="textEditTitle">Title</font><br> If this item is a header, enter a title here. </td> <td> <?php form_text_box("title", (isset($tree_item["title"]) ? $tree_item["title"] : ""), "", "255", 30, "text", (isset($_GET["id"]) ? $_GET["id"] : "0"));?> </td> </tr> <?php /* don't allow the user to change the tree item ordering if a tree order has been specified */ if ($tree_sort_type == TREE_ORDERING_NONE) { form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++; ?> <td width="50%"> <font class="textEditTitle">Sorting Type</font><br> Choose how children of this branch will be sorted. </td> <td> <?php form_dropdown("sort_children_type", $tree_sort_types, "", "", (isset($tree_item["sort_children_type"]) ? $tree_item["sort_children_type"] : $default_sorting_type), "", "");?> </td> </tr> <?php } if ((!empty($_GET["id"])) && ($tree_sort_type == TREE_ORDERING_NONE)) { form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++; ?> <td width="50%"> <font class="textEditTitle">Propagate Changes</font><br> Propagate all options on this form (except for 'Title') to all child 'Header' items. </td> <td> <?php form_checkbox("propagate_changes", "", "Propagate Changes", "", "", "", 0);?> </td> </tr> <?php } break; case TREE_ITEM_TYPE_GRAPH: form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?> <td width="50%"> <font class="textEditTitle">Graph</font><br> Choose a graph from this list to add it to the tree. </td> <td> <?php form_dropdown("local_graph_id", db_fetch_assoc("select graph_templates_graph.local_graph_id as id,graph_templates_graph.title_cache as name from (graph_templates_graph CROSS JOIN graph_local) where graph_local.id=graph_templates_graph.local_graph_id and local_graph_id != 0 order by title_cache"), "name", "id", (isset($tree_item["local_graph_id"]) ? $tree_item["local_graph_id"] : ""), "", "");?> </td> </tr> <?php form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1); ?> <td width="50%"> <font class="textEditTitle">Round Robin Archive</font><br> Choose a round robin archive to control how this graph is displayed. </td> <td> <?php form_dropdown("rra_id", db_fetch_assoc("select id,name from rra order by timespan"), "name", "id", (isset($tree_item["rra_id"]) ? $tree_item["rra_id"] : ""), "", "");?> </td> </tr> <?php break; case TREE_ITEM_TYPE_HOST: form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?> <td width="50%"> <font class="textEditTitle">Host</font><br> Choose a host here to add it to the tree. </td> <td> <?php form_dropdown("host_id", db_fetch_assoc("select id,".sql_function_concat("description","' ('","hostname","')'")." as name from host order by description,hostname"), "name", "id", (isset($tree_item["host_id"]) ? $tree_item["host_id"] : ""), "", "");?> </td> </tr> <?php form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1); ?> <td width="50%"> <font class="textEditTitle">Graph Grouping Style</font><br> Choose how graphs are grouped when drawn for this particular host on the tree. </td> <td> <?php form_dropdown("host_grouping_type", $host_group_types, "", "", (isset($tree_item["host_grouping_type"]) ? $tree_item["host_grouping_type"] : "1"), "", "");?> </td> </tr> <?php break; } ?> </tr> <?php form_hidden_box("id", (isset($_GET["id"]) ? $_GET["id"] : "0"), ""); form_hidden_box("graph_tree_id", $_GET["tree_id"], ""); form_hidden_box("type", $current_type, ""); form_hidden_box("save_component_tree_item", "1", ""); html_end_box(); form_save_button("tree.php?action=edit&id=" . $_GET["tree_id"]); }
public static function userSched() { global $lng, $coach, $settings, $leagues, $divisions, $tours; if (!is_object($coach)) { status(false, "You must be logged in to schedule games"); return; } if (isset($_POST['creategame'])) { // Test input $trid = (int) $_POST['trid']; $round = (int) $_POST['round']; $own_team = (int) $_POST['own_team']; $errmsg = ''; // Logged in coach has access to the tour? if (!in_array($trid, array_keys($tours))) { $errmsg = 'You do not have access to the tournament ' . $tours[$trid]['tname']; } // Is the team is really owned by the logged in coach? if ($coach->coach_id != get_alt_col('teams', 'team_id', $own_team, 'owned_by_coach_id')) { $errmsg = 'The team ' . get_alt_col('teams', 'team_id', $own_team, 'name') . ' is not owned by you'; } // Create match if (!$errmsg) { list($exitStatus, $mid) = Match::create(array('team1_id' => $own_team, 'team2_id' => get_alt_col('teams', 'name', $_POST['opposing_team_autocomplete'], 'team_id'), 'round' => $round, 'f_tour_id' => $trid)); $backFromMatchLink = Mobile::isMobile() ? "index.php?mobile=1" : "index.php?section=matches&type=report&mid={$mid}"; status(!$exitStatus, $exitStatus ? Match::$T_CREATE_ERROR_MSGS[$exitStatus] : "<a href='{$backFromMatchLink}'>Click here</a> to open the match report"); if (!$exitStatus) { echo "<br>"; } } else { status(false, $errmsg); } } $trid = isset($_GET['trid']) && is_numeric($_GET['trid']) ? (int) $_GET['trid'] : 0; $lid = $trid ? get_parent_id(T_NODE_TOURNAMENT, $trid, T_NODE_LEAGUE) : false; $lname = $lid ? get_parent_name(T_NODE_TOURNAMENT, $trid, T_NODE_LEAGUE) : '- N/A -'; $did = $trid && get_alt_col('leagues', 'lid', $lid, 'tie_teams') == 1 ? get_parent_id(T_NODE_TOURNAMENT, $trid, T_NODE_DIVISION) : false; $dname = $did ? get_parent_name(T_NODE_TOURNAMENT, $trid, T_NODE_DIVISION) : false; $_DISABLED = !$trid ? 'DISABLED' : ''; #print_r(array($trid, $lid, $lname, $did)); title($lng->getTrn('menu/matches_menu/usersched')); $LOCK_FORMS = false; ?> <div class='boxCommon'> <h3 class='boxTitle<?php echo T_HTMLBOX_MATCH; ?> '><?php echo $lng->getTrn('menu/matches_menu/usersched'); ?> </h3> <div class='boxBody'> <form method="POST" id="usersched"> <?php echo "In tournament "; echo HTMLOUT::nodeList(T_NODE_TOURNAMENT, 'trid', array(T_NODE_TOURNAMENT => array('locked' => 0, 'type' => TT_FFA, 'allow_sched' => 1)), array(), array('sel_id' => $trid, 'extra_tags' => array('onChange="document.location.href = \'' . getFormAction('?section=matches&type=usersched') . '&trid=\' + $(this).val();"'), 'init_option' => '<option value="0">- ' . $lng->getTrn('matches/usersched/selecttour') . " -</option>\n")); echo ' as '; echo '<select name="round" id="round" ' . $_DISABLED . '>'; $T_ROUNDS = Match::getRounds(); foreach ($T_ROUNDS as $r => $d) { echo "<option value='{$r}' " . ($r == 1 ? 'SELECTED' : '') . ">" . $d . "</option>\n"; } ?> </select> <br><br> Your team <?php $teams = array(); foreach ($coach->getTeams($lid, $did, array('sortby' => 'team_id DESC')) as $t) { if (!$t->rdy || $t->is_retired) { continue; } $teams[] = $t; } ?> <select name='own_team' id='own_team' <?php echo $_DISABLED; ?> > <?php echo "<optgroup class='leagues' label='{$lname}'>\n"; if ($dname) { echo "<optgroup class='divisions' label=' {$dname}'>\n"; } foreach ($teams as $t) { echo "<option style='background-color: white; margin-left: -1em;' value='{$t->team_id}'> {$t->name}</option>\n"; } ?> </select> VS. <input type="text" id='opposing_team_autoselect' name="opposing_team_autocomplete" size="30" maxlength="50" <?php echo $_DISABLED; ?> > <script> $(document).ready(function(){ var options, b; options = { minChars:2, serviceUrl:'handler.php?type=autocomplete&obj=<?php echo T_OBJ_TEAM; ?> &trid=<?php echo $trid; ?> ', }; b = $('#opposing_team_autoselect').autocomplete(options); }); </script> <br><br><br> <input type="submit" name="creategame" value="<?php echo $lng->getTrn('menu/matches_menu/usersched'); ?> " <?php if (empty($teams) || $_DISABLED) { echo 'DISABLED'; } ?> > <?php if (Mobile::isMobile()) { echo '<a href="' . getFormAction('') . '">' . $lng->getTrn('common/back') . '</a>'; } ?> </form> </div> </div> <?php }
function export_build_graphs($fp, $path, $tree_id, $parent_tree_item_id) { /* start the count of graphs */ $total_graphs_created = 0; $cacti_export_path = read_config_option("path_html_export"); $req=""; if (get_tree_item_type($parent_tree_item_id)=="host") { $req="select distinct graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id from graph_templates_graph left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id) left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id) where graph_local.host_id=".get_host_id($parent_tree_item_id)." and graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on' order by graph_templates_graph.title_cache"; }else { /* searching for the graph_tree_items of the tree_id which are graphs */ $req="select distinct graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id, graph_tree_items.id as gtid from graph_templates_graph left join graph_tree_items on (graph_templates_graph.local_graph_id=graph_tree_items.local_graph_id) left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id) left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id) where graph_tree_items.graph_tree_id =".$tree_id." and graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on' order by graph_templates_graph.title_cache"; } $graphs=db_fetch_assoc($req); $rras = db_fetch_assoc("select rra.id, rra.name from rra order by timespan"); /* open a pipe to rrdtool for writing */ $rrdtool_pipe = rrd_init(); /* for each graph... */ $i = 0; foreach($graphs as $graph) { /* this test gives us the graph_tree_items which are just under the parent_graph_tree_item */ if (((get_tree_item_type($parent_tree_item_id)=="header") || ($parent_tree_item_id == 0)) && (get_parent_id($graph["gtid"], "graph_tree_items","graph_tree_id = ".$tree_id) != $parent_tree_item_id)) { /* do nothing */ }else { /* settings for preview graphs */ $graph_data_array["graph_height"] = "100"; $graph_data_array["graph_width"] = "300"; $graph_data_array["graph_nolegend"] = true; $graph_data_array["export"] = true; $graph_data_array["export_filename"] = "'".$path."'/thumb_".$graph["local_graph_id"].".png"; rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe); $total_graphs_created++; /* generate html files for each graph */ $fp_graph_index = fopen($cacti_export_path."/".$path."/graph_".$graph["local_graph_id"].".html", "w"); fwrite($fp_graph_index, HTML_HEADER_TREE); draw_html_left_tree($fp_graph_index,$tree_id); fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE_TREE); fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong>"); fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO); fwrite($fp_graph_index, "<td>"); /* reset vars for actual graph image creation */ reset($rras); unset($graph_data_array); /* generate graphs for each rra */ foreach ($rras as $rra) { $graph_data_array["export"] = true; $graph_data_array["export_filename"] = "'".$path."'/graph_".$graph["local_graph_id"]."_".$rra["id"].".png"; rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe); $total_graphs_created++; /* write image related html */ fwrite($fp_graph_index, "<div align=center><img src='graph_".$graph["local_graph_id"]."_".$rra["id"].".png' border=0></div>\n <div align=center><strong>".$rra["name"]."</strong></div><br>"); } fwrite($fp_graph_index, "</tr></table>"); fwrite($fp_graph_index, HTML_FOOTER_TREE); fclose($fp_graph_index); /* main graph page html */ fwrite($fp, "<td align='center' width='\" . (98 / 2) . \"%'><a href='graph_" . $graph["local_graph_id"] . ".html'><img src='thumb_" . $graph["local_graph_id"] . ".png' border='0' alt='" . $graph["title_cache"] . "'></a></td>\n"); $i++; if (($i == 2)) { $i = 0; fwrite($fp, "</tr><tr>"); } } } /* close the rrdtool pipe */ rrd_close($rrdtool_pipe); return $total_graphs_created; }
function createJoomlaUser($data) { $user =& JFactory::getUser(); $uid = $user->get('id'); $custumgroupparentids = ""; // Initialize variable $normalgroupids = ""; // Initialize variable $normalgroupidsstring = ""; // Initialize variable $custumgroupparentidsstring = ""; // Initialize variable $usergroups = $user->getAuthorisedGroups(); // get all usergroups for this user foreach ($usergroups as $usergroup) { // For each usergroup do something if ($usergroup > "8") { // If the usergroup ID is higher then 8 and therefore is a custum usergroup $result = get_parent_id($usergroup); // If the resulting parent_id is also a custom usergroup while ($result > 8) { // Loop to get parent_id untill we find a parent id of the standard joomla usergroups $result = get_parent_id($result); } $custumgroupparentidsstring .= $result . ","; // Make comma seperated string out of results } else { // Else of: if($usergroup > "8") { - (usergroup is not higher then 8 and therefore is a 'normal' usergroup) $normalgroupidsstring .= $usergroup . ","; // Make comma seperated string out of results } } // END - (foreach ($usergroups as $usergroup) { - For each usergroup do something) $custumgroupparentidsstring = substr($custumgroupparentidsstring, 0, -1); // Delete not needed comma's $custumgroupparentids = explode(",", $custumgroupparentidsstring); // Explode comma seperated string to array $normalgroupidsstring = substr($normalgroupidsstring, 0, -1); // Delete not needed comma's $normalgroupids = explode(",", $normalgroupidsstring); // Explode comma seperated string to array $allgroupids = array_merge($custumgroupparentids, $normalgroupids); // Merge the 2 arrays $allgroupids = array_unique($allgroupids); // Remove duplicate value's from array sort($allgroupids, SORT_NUMERIC); // Sort all groups numeric $highestgroup = max($allgroupids); // Get highest groupid or parent groupid $groupid = $highestgroup; $showpass = $data['password']; $password = getCryptedPassword($showpass, $salt = '', $encryption = 'md5-hex', $show_encrypt = false); $name = $data['name']; # | 3 | 2 | 3 | 8 | Reseller | # | 4 | 3 | 4 | 7 | Company | # | 16 | 4 | 5 | 6 | Group | # (1, 'Reseller'), # (2, 'Group'), # (3, 'Company'), switch ($data['entity_type']) { case 1: # Reseller $usertype = 3; $usertypename = 'Reseller'; break; case 2: # Company $usertype = 4; $usertypename = 'Company'; break; case 3: # Group $usertype = 16; $usertypename = 'Group'; break; } $group = $usertype; if ($group > 8) { $parentgrouporgroup = get_parent_id($group); while ($parentgrouporgroup > 8) { // Loop to get parent_id untill we find a parent_id of the standard joomla usergroups $parentgrouporgroup = get_parent_id($parentgrouporgroup); } } else { $parentgrouporgroup = $group; } $username = clean_now($data['username']); $db =& JFactory::getDBO(); $query = "SELECT " . $db->nameQuote('title') . " FROM " . $db->nameQuote('#__usergroups') . " WHERE id = " . $db->quote($usertype) . ""; $db->setQuery($query); $usertypename = $db->loadResult(); if ($usertypename == "") { die("user group id not found in db"); } $sql = "SELECT COUNT(*) " . $db->nameQuote('username') . " FROM " . $db->nameQuote('#__users') . " WHERE " . $db->nameQuote('username') . " = " . $db->quote($username) . ""; $db->setQuery($sql); $num_rows = $db->loadResult(); if ($num_rows != 0) { die("user name taken"); } $email = trim($data['email']); $sql = "SELECT COUNT(*) " . $db->nameQuote('email') . " FROM " . $db->nameQuote('#__users') . " WHERE " . $db->nameQuote('email') . " = " . $db->quote($email) . ""; $db->setQuery($sql); $num_rows = $db->loadResult(); if ($num_rows == 0) { //die("email already in use"); } $block = '0'; $sendmail = '0'; $sql1 = "INSERT INTO " . $db->nameQuote('#__users') . " SET\n " . $db->nameQuote('name') . " = " . $db->quote($name) . ",\n " . $db->nameQuote('username') . " = " . $db->quote($username) . ",\n " . $db->nameQuote('email') . " = " . $db->quote($email) . ",\n " . $db->nameQuote('password') . " = " . $db->quote($password) . ",\n " . $db->nameQuote('usertype') . " = " . $db->quote($usertypename) . ",\n " . $db->nameQuote('block') . " = " . $db->quote($block) . ",\n " . $db->nameQuote('sendEmail') . " = " . $db->quote($sendmail) . ",\n " . $db->nameQuote('registerDate') . " = NOW(),\n " . $db->nameQuote('lastvisitDate') . " = " . $db->quote('0000-00-00 00:00:00') . ",\n " . $db->nameQuote('activation') . " = '',\n " . $db->nameQuote('params') . " = ''\n "; $db->setQuery($sql1); $db->query(); $user_id = $db->insertid(); $sql2 = "INSERT INTO " . $db->nameQuote('#__user_usergroup_map') . " SET\n " . $db->nameQuote('group_id') . " = " . $db->quote($usertype) . ",\n " . $db->nameQuote('user_id') . " = " . $db->quote($user_id) . "\n "; $db->setQuery($sql2); $db->query(); $config =& JFactory::getConfig(); $fromname = $config->getValue('config.fromname'); $from = $config->getValue('config.mailfrom'); $recipient = $email; $subject = "Your user details for " . $_SERVER['HTTP_HOST']; $body = <<<BODY You have been added as a User to __HTTP_HOST__. <br><br> This e-mail contains your username and password to log in to __HTTP_HOST__. <br><br> Username: __USERNAME__ <br> Password: __PASSWORD__ <br><br> Please do not respond to this message as it is automatically generated and is for information purposes only. BODY; $body = str_replace('__HTTP_HOST__', $_SERVER['HTTP_HOST'], $body); $body = str_replace('__USERNAME__', $username, $body); $body = str_replace('__PASSWORD__', $showpass, $body); JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode = 1, $cc = null, $bcc = null, $attachment = null, $replyto = null, $replytoname = null); $recipient = $from; $subject = "A new user has been added to " . $_SERVER['HTTP_HOST'] . ""; $body = "A new user has been added to " . $_SERVER['HTTP_HOST'] . ". This is a copy off the email notification that this user received:<br>" . $body; JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode = 1, $cc = null, $bcc = null, $attachment, $replyto = null, $replytoname = null); return $user_id; }