function drop_all_deck() { global $DECK_TABLE_NAME; $all_deck_ids = get_attribute_values($DECK_TABLE_NAME, "id"); foreach ($all_deck_ids as $id) { $deck_table_name = get_deck_table_name($id); drop_table($deck_table_name); print_msg("drop {$deck_table_name}"); } }
function print_form() { global $DECK_TABLE_NAME; echo "<form id=\"compare_form\">"; $ids = get_attribute_values($DECK_TABLE_NAME, "id"); print_deck_compare_select("deck1", $ids); print_deck_compare_select("deck2", $ids); echo "</form>"; echo "<div id=\"compare_table\"></div>"; }
function print_compare_form($default1, $default2) { global $DECK_TABLE_NAME; echo "<form id=\"compare_form\" action=\"compare_deck.php\">"; $ids = get_attribute_values($DECK_TABLE_NAME, "id"); print_deck_compare_select("deck1", $ids, $default1); print_deck_compare_select("deck2", $ids, $default2); echo "<input type=\"submit\" name=\"submit\" value=\"compare\">"; echo "</form>"; }
function print_all_form_select($table, $attributes) { foreach ($attributes as $attr) { $values = get_attribute_values($table, $attr); echo "{$attr}: "; print_form_select($attr, $values, get_current_get_value($attr)); echo " "; echo " "; echo " "; } }
function get_deck_new_id($class) { global $DECK_TABLE_NAME; $all_deck_ids = get_attribute_values($DECK_TABLE_NAME, "id"); for ($i = 0; $i < 10000; $i++) { $new_id = "add_{$class}" . "_{$i}"; if (!in_array($new_id, $all_deck_ids)) { return $new_id; } } return "error_id"; }
function print_add_form() { $error = false; $data = array(); $card = array(); $attributes = array("name", "class", "creator", "link", "comment"); foreach ($attributes as $attr) { $data[$attr] = get_current_post_value($attr); if ($data[$attr] == "") { $error = true; } } #var_dump($data); #var_dump($error); global $CARD_TABLE_NAME; echo "<form method=\"post\" action=\"add_deck.php\">"; echo "name: "; print_form_input("name", get_current_post_value("name")); echo "<br>"; echo "class: "; $class_values = get_attribute_values($CARD_TABLE_NAME, "playerClass"); print_form_select("class", $class_values, get_current_post_value("class")); echo "<br>"; echo "creator: "; print_form_input("creator", get_current_post_value("creator"), 40); echo "<br>"; echo "link: "; print_form_input("link", get_current_post_value("link")); echo "<br>"; echo "comment: "; $comment_value = get_current_post_value("comment"); echo "<textarea name=\"comment\" maxlength=\"255\">{$comment_value}</textarea>"; echo "<br>"; $all_card_names = get_attribute_values($CARD_TABLE_NAME, "name"); for ($i = 1; $i <= 10; ++$i) { $card_value = get_current_post_value("card_{$i}"); echo "card_{$i}: <input list=\"card_name\" name=\"card_{$i}\" value=\"{$card_value}\">"; $card_num_value = get_current_post_value("card_num_{$i}"); echo "<input type=\"number\" name=\"card_num_{$i}\" min=\"1\" max=\"5\" value=\"{$card_num_value}\">"; if ($card_value != "") { if (!in_array($card_value, $all_card_names)) { echo "*invalid card name"; $error = true; } else { if ($card_num_value == "") { echo "*at least 1"; $error = true; } else { $card[$card_value] = $card_num_value; } } } echo "<br>"; } echo "<datalist id=\"card_name\">"; foreach ($all_card_names as $value) { echo "<option value=\"{$value}\">"; } echo "</datalist>"; echo "<input type=\"submit\" name=\"submit\" value=\"add\">"; echo "</form>"; if (!$error) { $data["id"] = get_deck_new_id($data["class"]); $data["num"] = deck_count_card($card); if ($data["num"] != 0) { create_new_deck($data, $card); echo "Add deck \"" . $data["name"] . "\" successfully"; echo "<br>"; } } #var_dump($data); #echo "<br>"; #var_dump($card); #echo "<br>"; #var_dump($error); #echo "<br>"; }
function print_add_form() { global $CARD_TABLE_NAME, $CARD_VALID_ID_CONSTRAINT, $DECK_TABLE_NAME; $is_post = false; $is_load = false; $is_update = false; $error = false; $data = array(); $card = array(); $all_card = array(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $is_post = true; } $action = get_current_post_value("action"); if ($action == "load") { $is_load = true; } else { if ($action == "update") { $is_update = true; } } $deck = get_current_post_value("deck"); if ($deck == "" && $is_load) { $is_load = false; $error = true; } else { $all_card = get_deck_all_card($deck); } #var_dump($all_card); $attributes = array("name", "class", "creator", "link", "comment"); if ($is_load) { $all_attr = get_deck_all_attr($deck); foreach ($attributes as $attr) { $data[$attr] = $all_attr[$attr]; } } else { foreach ($attributes as $attr) { $data[$attr] = get_current_post_value($attr); if ($attr != "comment" && $data[$attr] == "") { $error = true; } } } echo "<form id=\"add_form\">"; echo "deck: "; $ids = get_attribute_values($DECK_TABLE_NAME, "id"); print_deck_compare_select("deck", $ids, $deck); echo " "; echo " "; echo " "; echo " "; echo "<input type=\"submit\" name=\"submit\" value=\"load\" id=\"load_button\">"; echo "<br>"; print_add_form_input_line("name", $data, $is_post); echo "class: "; $class_values = get_attribute_values($CARD_TABLE_NAME, "playerClass"); #print_form_select("class", $class_values, get_current_post_value("class"), false); print_form_select("class", $class_values, $data["class"], false); #echo "<br>"; echo " "; echo " "; echo " "; echo " "; print_add_form_input_line("creator", $data, $is_post, 40); print_add_form_input_line("link", $data, $is_post); echo "<br>"; echo "comment: "; $comment_value = get_current_post_value("comment"); echo "<textarea name=\"comment\" maxlength=\"255\">{$comment_value}</textarea>"; #if ($is_post) { # check_empty($comment_value); #} echo "<br>"; #echo "</form>"; #echo "<form id=\"add_form_card\">"; #$all_card_names = get_attribute_values($CARD_TABLE_NAME, "name", "id RLIKE '[0-9_][0-9]$'"); $all_card_names = get_attribute_values($CARD_TABLE_NAME, "name", $CARD_VALID_ID_CONSTRAINT); #var_dump($all_card_names); echo "<datalist id=\"card_name\">"; foreach ($all_card_names as $value) { echo "<option value=\"{$value}\">"; } echo "</datalist>"; $all_card_size = count($all_card); for ($i = 0; $i < 30; ++$i) { $card_value = get_current_post_value("card_{$i}"); if ($is_load) { if ($i < $all_card_size) { $card_value = get_card_name_by_id($all_card[$i][0]); } else { $card_value = ""; } } #echo "card $i: <input list=\"card_name\" name=\"card_$i\" value=\"$card_value\">"; echo "<input list=\"card_name\" name=\"card_{$i}\" value=\"{$card_value}\">"; $card_num_value = get_current_post_value("card_num_{$i}"); if ($is_load) { if ($i < $all_card_size) { $card_num_value = $all_card[$i][1]; } else { $card_num_value = ""; } } echo "<input type=\"number\" name=\"card_num_{$i}\" min=\"1\" max=\"5\" value=\"{$card_num_value}\">"; if ($card_value != "") { if (!in_array($card_value, $all_card_names)) { #echo "<span class>*invalid card name"; echo "<span class=\"error\">*incalid card name card</span>"; $error = true; } else { if ($card_num_value == "") { echo "<span class=\"error\">*at least 1</span>"; #echo "*at least 1"; $error = true; } else { $card[$card_value] = $card_num_value; } } } if (($i + 1) % 5 == 0) { echo "<br>"; } else { echo " "; } } $data["num"] = deck_count_card($card); if ($is_post) { if ($data["num"] == 0) { echo "<span class=\"error\">*at least 1 card</span>"; echo "<br>"; } } echo "<input type=\"submit\" name=\"submit\" value=\"add\" id=\"add_button\">"; echo "<input type=\"submit\" name=\"submit\" value=\"update\" id=\"update_button\">"; echo "</form>"; if ($is_post && !$error && !$is_load) { $data["id"] = get_deck_new_id($data["class"]); if ($data["num"] != 0) { foreach ($data as $key => $value) { $data[$key] = test_input($value); } create_new_deck($data, $card); if ($is_update) { echo "Update"; } else { echo "Add"; } echo " deck \"" . $data["name"] . "\" successfully"; echo "<br>"; } } #var_dump($data); #echo "<br>"; #var_dump($card); #echo "<br>"; #var_dump($error); #echo "<br>"; }
<?php include_once "../db/login.php"; include_once "global.php"; include_once "mysql_query.php"; include_once "html.php"; include_once "deck_util.php"; ?> <?php $link = @mysql_connect("{$servername}", "{$username}", "{$password}"); if (!$link) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($database) or die("Unable to select database"); #print_add_form(); $id = get_current_get_value("id"); $ids = get_attribute_values($DECK_TABLE_NAME, "id"); if (in_array($id, $ids)) { $deck_table_name = get_deck_table_name($id); drop_table($deck_table_name); $query = "DELETE FROM {$DECK_TABLE_NAME} WHERE id=\"{$id}\";"; exec_mysql_query($query); } # close mysql_close($link);
function get_attribute($attribute = array()) { $result = ''; if (!empty($attribute)) { $attribute_value_types = array('D' => 'Date', 'F' => 'Float', 'I' => 'Integer', 'PC' => 'Picklist (Contacts)', 'PT' => 'Picklist (Text Field)', 'T' => 'Text Field', 'U' => 'URL', 'N' => 'Not Used'); $smart_field_value_types = array('SF' => 'HTML String Search', 'N' => 'Not Used'); $attribute_id = $attribute['attribute_id']; $client_attribute_id = $attribute['client_attribute_id']; $attribute_filter_flag = $attribute['attribute_filter_flag']; $attribute_type = $attribute['attribute_type']; $attribute_group_type = $attribute['attribute_group_type']; $attribute_name = $attribute['attribute_name']; $attribute_value_type = $attribute['attribute_value_type']; $attribute_values = $attribute['attribute_values']; if (empty($attribute_value_type)) { $attribute_value_type = 'N'; } $readonly = ''; $disabled = ''; if ($attribute_group_type == 'P') { $readonly = ' readonly="readonly"'; $disabled = ' disabled="disabled"'; } $field_data = array('name' => 'data[attribute_name][]', 'size' => '30', 'maxlength' => '255', 'class' => 'attribute_name', 'id' => 'attribute_name_' . $attribute_id); $result .= ' <div id="tabs-' . $attribute_id . '"> <div class="form_field attributes"> <button class="btn theme small reset_to_default" type="button" attribute_id="' . $attribute_id . '">Reset Field To Default</button> <div class="form_title"><span class="mandatory">Name:</span></div> <div class="form_input"> ' . form_input($field_data, $attribute_name, $disabled) . ' <input type="hidden" name="data[attribute_id][]" value="' . $attribute_id . '"> <input type="hidden" name="data[client_attribute_id][]" value="' . $client_attribute_id . '"> <input type="hidden" name="data[reset_to_default][]" id="reset_' . $attribute_id . '" value=""> </div> </div> <div class="form_field attributes"> <div class="form_title"><span class="mandatory">Type:</span></div> <div class="form_input attribute_type_values">'; if ($attribute_group_type == 'M') { $value_types = $smart_field_value_types; } else { $value_types = $attribute_value_types; } foreach ($value_types as $option_value => $option_name) { $option_id = $attribute_id . '_' . $option_value; $checked = false; if ($option_value == $attribute_value_type) { $checked = true; } $result .= form_radio('data[attribute_value_' . $attribute_id . ']', $option_value, $checked, 'class="attribute_value_type" id="' . $option_id . '"' . $disabled); $result .= '<label for="' . $option_id . '">' . $option_name . '</label>'; } $result .= ' </div> </div> <div id="use_as_filter_' . $attribute_id . '" class="form_field attributes"> <div class="form_title">Use as Filter:</div> <div class="form_input">'; $checked = false; if ($attribute_filter_flag == '1') { $checked = true; } $result .= form_checkbox('data[filter_flag][]', $attribute_id, $checked, 'id="attribute_filter_flag_' . $attribute_id . '" class="attribute_filter_flag"'); $result .= ' </div> </div>'; if ($attribute_group_type == 'M') { $result .= ' <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_SF_values"> ' . get_attribute_values('SF', $attribute) . ' </div>'; } else { $result .= ' <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_D_values"></div> <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_F_values"></div> <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_I_values"></div> <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_PC_values"> ' . get_attribute_values('PC', $attribute) . ' </div> <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_PD_values"> ' . get_attribute_values('PD', $attribute) . ' </div> <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_PT_values"> ' . get_attribute_values('PT', $attribute) . ' </div> <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_T_values"></div> <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_U_values"> <div class="help_text"> Please specify the URL value in <a href="/users/sites/admin">Edit domain data</a>. </div> </div>'; } $result .= ' <div class="attribute_values ' . $attribute_id . '_values" id="' . $attribute_id . '_N_values"></div> </div>'; } return $result; }