function add_attribute($id, $id_attr, $attr_value) { # temporary map vars: $attr = array(); $attr["key"] = $id_attr; $attr["value"] = $attr_value; # get class_id of item --> for function $class_id = db_templates("get_classid_of_item", $id); # only handle integer (attribute ids) on "key" element if (is_int($attr["key"])) { # different logic for text / linked items if (!is_array($attr["value"])) { # Add text or select attribute # Lookup datatype # Password field is a encrypted, do not save $datatype = db_templates("attr_datatype", $attr["key"]); if ($datatype == "password") { $insert_attr_value = encrypt_password($attr["value"]); } else { # normal text/select $insert_attr_value = escape_string($attr["value"]); } # insert query $query = 'INSERT INTO ConfigValues (fk_id_item, attr_value, fk_id_attr) VALUES ("' . $id . '", "' . $insert_attr_value . '", "' . $attr["key"] . '") '; if (DB_NO_WRITES != 1) { $result_insert = db_handler($query, "insert", "Insert"); if ($result_insert) { NConf_DEBUG::set("Added attr " . $insert_attr_value, 'DEBUG', "Add attribute"); # add value ADDED to history history_add("added", $attr["key"], $insert_attr_value, $id, "get_attr_name"); } else { message('ERROR', 'Error when adding ' . $attr["value"], "failed"); } } } elseif (is_array($attr["value"])) { # add assign attrbibutes # counter for assign_cust_order $cust_order = 0; $attr_datatype = db_templates("attr_datatype", $attr["key"]); # save assign_one/assign_many/assign_cust_order in ItemLinks while ($many_attr = each($attr["value"])) { # if value is empty go to next one if (!$many_attr["value"]) { continue; } else { # create insert query $check = check_link_as_child_or_bidirectional($attr["key"], $class_id); if ($check === TRUE) { $query = 'INSERT INTO ItemLinks (fk_id_item, fk_item_linked2, fk_id_attr, cust_order) VALUES (' . $many_attr["value"] . ', ' . $id . ', ' . $attr["key"] . ', ' . $cust_order . ') '; } else { $query = 'INSERT INTO ItemLinks (fk_id_item, fk_item_linked2, fk_id_attr, cust_order) VALUES (' . $id . ', ' . $many_attr["value"] . ', ' . $attr["key"] . ', ' . $cust_order . ') '; } if (DB_NO_WRITES != 1) { $result_insert = db_handler($query, "insert", "Insert"); if ($result_insert) { history_add("assigned", $attr["key"], $many_attr["value"], $id, "resolve_assignment"); message('DEBUG', '', "ok"); //message ('DEBUG', 'Successfully linked "'.$many_attr["value"].'" with '.$attr["key"]); } else { message('ERROR', 'Error when linking ' . $many_attr["value"] . ' with ' . $attr["key"] . ':' . $query); } } # increase assign_cust_order if needed if ($attr_datatype == "assign_cust_order") { $cust_order++; } } } } } }
message($debug, 'no changes in this attribute'); NConf_DEBUG::close_group(); ########## CONTINUE IF ATTRIBUTE WAS NOT CHANGED ############ continue; } ########################### ### Delete old links ########################### message($debug, '<b>Delete old links</b>'); # special handling for advanced services (coming from modify_item_service page) if (isset($advanced_services) and $_GET["ajax_file"] == "advanced_service.php") { # force swaping the data $lac_OR_bidirectional = TRUE; } else { # check link_as_child & link_bidirectional $lac_OR_bidirectional = check_link_as_child_or_bidirectional($attr["key"], $class_id); } if ($handle_action == "multimodify" and $replace_mode == "add") { # do no deletions } else { if ($lac_OR_bidirectional) { # interchange data $delete_query_lac = 'DELETE FROM ItemLinks WHERE fk_id_attr="' . $attr["key"] . '" AND fk_item_linked2="' . $id . '"'; db_handler($delete_query_lac, "delete", "Delete link as child"); } else { $delete_query = 'DELETE FROM ItemLinks WHERE fk_id_attr="' . $attr["key"] . '" AND fk_id_item="' . $id . '"'; db_handler($delete_query, "delete", "Delete (not link as child)");