function rollback_field_from_relationship($Relation_ID) { //****************************************************************************** //*** START: ROLLBACK OF FIELD INFO UPON REMOVAL OF RELATIONSHIP *************** //****************************************************************************** //We have to undo changes in the child field $mysqli = connect_DB(); //Get the Child Field involved $mysqli->real_query("SELECT Child_Field_ID\n FROM `table_relations`\n WHERE Relation_ID='{$Relation_ID}'"); if ($result = $mysqli->use_result()) { while ($data = $result->fetch_assoc()) { $Child_Field_ID = $data['Child_Field_ID']; } } //Delete the SQL list settings (for 1-1 relationships) $mysqli->real_query("DELETE FROM table_fields_list_source_select WHERE Field_ID='{$Child_Field_ID}'"); $mysqli->real_query("DELETE FROM table_fields_list_source_where WHERE Field_ID='{$Child_Field_ID}'"); //See what the attribute value is. //- if "primary&foregin key", change back to "primary". //- if "foreign key", change back to "none". $mysqli->real_query("SELECT Attribute FROM table_fields WHERE Field_ID='{$Child_Field_ID}'"); if ($result = $mysqli->use_result()) { while ($data = $result->fetch_assoc()) { $Child_Field_Attribute = $data['Attribute']; } } if ($Child_Field_Attribute == 'primary&foreign key') { $new_attribute = 'primary key'; } else { $new_attribute = 'none'; } $stmt = $mysqli->stmt_init(); if ($stmt->prepare("UPDATE table_fields SET Attribute=? WHERE Field_ID=?")) { $stmt->bind_param("ss", $new_attribute, $Child_Field_ID); $stmt->execute(); $stmt->close(); } else { die($stmt->error); } //After undoing the attribute, we now have to undo the change to the control type (for 1-1 relationships). //We need to look at this field's metadata to determine how to roll it back to default $mysqli->real_query("SELECT Field_Name, Data_Type FROM table_fields WHERE Field_ID='{$Child_Field_ID}'"); if ($result = $mysqli->use_result()) { while ($data = $result->fetch_assoc()) { $Child_Field_Name = $data['Field_Name']; $Child_Data_Type = $data['Data_Type']; } } $arr_textarea_names = get_textarea_field_names(); if (in_array(strtoupper($Child_Field_Name), $arr_textarea_names)) { $control_type = 'textarea'; } else { switch ($Child_Data_Type) { case 'text': $control_type = 'textarea'; break; case 'date': $control_type = 'date controls'; break; default: $control_type = 'textbox'; } } if (strtoupper($Child_Field_Name) == 'ID') { $label = 'ID'; } else { $label = str_replace('_', ' ', $Child_Field_Name); $label = ucwords($label); //if field contains "Id" as a word somewhere in the middle, change to "ID" $label = str_replace(' Id ', ' ID ', $label); if (substr($label, 0, 3) == 'Id ') { //Field name starts with 'Id', change to 'ID ' (e.g., field name was originally "id_number") $label = 'ID ' . substr($label, 3); } if (substr($label, strlen($label) - 3) == ' Id') { //Field name ends with 'Id', change to ' ID' (e.g., field name was originally "employee_id") $label = substr($label, 0, strlen($label) - 3) . ' ID'; } } $stmt = $mysqli->stmt_init(); if ($stmt->prepare("UPDATE table_fields SET Control_Type=?, Label=? WHERE Field_ID=?")) { $stmt->bind_param("sss", $control_type, $label, $Child_Field_ID); $stmt->execute(); $stmt->close(); } else { die($stmt->error); } //****************************************************************************** //*** END: ROLLBACK OF FIELD INFO UPON REMOVAL OF RELATIONSHIP ***************** //****************************************************************************** }
$data_type = 'double or float'; break; case 'text': case 'tinytext': case 'mediumtext': case 'longtext': $data_type = 'text'; $control_type = 'textarea'; break; case 'date': $control_type = 'date controls'; break; default: } //Some field names are to be interpreted as needing a textarea $textareaFieldNames = get_textarea_field_names(); if (in_array(strtoupper($field_name), $textareaFieldNames)) { $control_type = 'textarea'; } $in_listview = 'yes'; //this is the default, might be changed by some conditions found below if (strtoupper($field_name) == 'ID') { $label = 'ID'; } else { $label = str_replace('_', ' ', $field_name); $label = ucwords($label); //if field contains "Id" as a word somewhere in the middle, change to "ID" $label = str_replace(' Id ', ' ID ', $label); if (substr($label, 0, 3) == 'Id ') { //Field name starts with 'Id', change to 'ID ' (e.g., field name was originally "id_number") $label = 'ID ' . substr($label, 3);