page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); // input var okay. } else { wp_die( __( 'ERROR: Wrong arguments', 'wp-data-access' ) ); } if ( isset( $_REQUEST['action'] ) ) { $this->action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); } if ( isset( $_REQUEST['action2'] ) ) { $this->action2 = sanitize_text_field( wp_unslash( $_REQUEST['action2'] ) ); } if ( isset( $_REQUEST['wpda_table_name'] ) && ! is_array( $_REQUEST['wpda_table_name'] ) ) { $wpda_project_design_table_model = new WPDP_Project_Design_Table_Model(); if ( 'reconcile' === $this->action ) { $wpda_table_name_re = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) ); // input var okay. $wpda_reverse_engineering = new \WPDataAccess\Utilities\WPDA_Reverse_Engineering( $wpda_table_name_re ); $table_structure = $wpda_reverse_engineering->get_designer_format( 'advanced' ); if ( isset( $_REQUEST['keep_options'] ) ) { $param_keep_options = sanitize_text_field( wp_unslash( $_REQUEST['keep_options'] ) ); } else { $param_keep_options = 'off'; } $result_update = $wpda_project_design_table_model->reconcile( $table_structure, $param_keep_options ); if ( false === $result_update ) { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Update failed', 'wp-data-access' ), 'message_type' => 'error', 'message_is_dismissible' => false, ] ); $msg->box(); } if ( 0 === $result_update ) { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Nothing to save', 'wp-data-access' ), ] ); $msg->box(); } else { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Succesfully saved changes to database', 'wp-data-access' ), ] ); $msg->box(); } } elseif ( 'reverse_engineering' === $this->action ) { if ( isset( $_REQUEST['wpda_table_name'] ) ) { $wpda_table_name_re = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) ); // input var okay. $wpda_reverse_engineering = new \WPDataAccess\Utilities\WPDA_Reverse_Engineering( $wpda_table_name_re ); $table_structure = $wpda_reverse_engineering->get_designer_format( 'advanced' ); if ( count( $table_structure ) > 0 ) { $this->wpda_table_name = $wpda_table_name_re; $this->wpda_table_design = $table_structure; } else { wp_die( __( 'ERROR: Reverse engineering table failed', 'wp-data-access' ) ); } if ( ! WPDP_Project_Design_Table_Model::insert_reverse_engineered( $this->wpda_table_name, $this->wpda_table_design ) ) { wp_die( __( 'ERROR: Reverse engineering table failed', 'wp-data-access' ) ); } else { // Convert named array to object (needed to display structure). $this->wpda_table_design = json_decode( json_encode( $table_structure ) ); } $this->action2 = 'edit'; $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Table added to respository', 'wp-data-access' ), ] ); $msg->box(); } else { wp_die( __( 'ERROR: Wrong arguments', 'wp-data-access' ) ); } } elseif ( null !== $this->action2 ) { $result_update = $wpda_project_design_table_model->update(); if ( false === $result_update ) { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Update failed', 'wp-data-access' ), 'message_type' => 'error', 'message_is_dismissible' => false, ] ); $msg->box(); } if ( 0 === $result_update ) { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Nothing to save', 'wp-data-access' ), ] ); $msg->box(); } else { $msg = new WPDA_Message_Box( [ 'message_text' => __( 'Succesfully saved changes to database', 'wp-data-access' ), ] ); $msg->box(); } } $wpda_project_design_table_model->query(); $structure_messages = $wpda_project_design_table_model->validate(); foreach ( $structure_messages as $messages ) { if ( 'ERR' === $messages[0] ) { $msg = new WPDA_Message_Box( [ 'message_text' => $messages[1], 'message_type' => 'error', 'message_is_dismissible' => false, ] ); $msg->box(); } else { $msg = new WPDA_Message_Box( [ 'message_text' => $messages[1], ] ); $msg->box(); } } $this->table_structure = $wpda_project_design_table_model->get_table_design(); $this->wpda_table_name = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) ); $this->wpda_data_dictionary = new WPDA_Dictionary_Exist( '', $this->wpda_table_name ); if ( $this->wpda_data_dictionary->table_exists() ) { $this->wpda_list_columns = WPDP_List_Columns_Cache::get_list_columns( '', $this->wpda_table_name, 'tableform' ); if ( 0 === count( $this->wpda_list_columns->get_table_primary_key() ) ) { $this->has_primary_key = false; } else { $this->has_primary_key = true; } } else { wp_die( __( 'ERROR: Invalid table name or not authorized', 'wp-data-access' ) ); } } else { wp_die( __( 'ERROR: Argument wpda_table_name not found', 'wp-data-access' ) ); } } /** * */ public function show() { ?>

 

 
show_table_info(); if ( true === $this->has_primary_key ) { echo '
'; $this->show_relations(); } echo '
'; $this->show_list_table(); if ( true === $this->has_primary_key ) { echo '
'; $this->show_table_form(); } ?> table_structure->tableinfo ) && isset( $this->table_structure->tableinfo->tab_label ) ) { $tab_label = $this->table_structure->tableinfo->tab_label; } else { $tab_label = ''; } ?>
wpda_list_columns->get_table_columns(); $target_table_names = WPDA_Dictionary_Lists::get_tables( true ); $i = 0; ?>
table_structure->relationships ) ) { $relationships = $this->table_structure->relationships; if ( 0 < count( $relationships ) ) { foreach ( $relationships as $relationship ) { ?> table_structure ) { return __( 'Invalid structure', 'wp-data-access' ); } ?>
table_structure->listtable_column_options ) ) { $structure = $this->table_structure->listtable_column_options; foreach ( $this->table_structure->table as $column ) { $table_structure[ $column->column_name ] = $column; } } else { $structure = $this->table_structure->table; } $i = 0; foreach ( $structure as $column ) { $column_name = $column->column_name; if ( isset( $this->table_structure->listtable_column_options ) && isset ( $table_structure[ $column_name ] ) ) { $data_type = $table_structure[ $column_name ]->data_type; $type_attribute = $table_structure[ $column_name ]->type_attribute; $key = $table_structure[ $column_name ]->key; $mandatory = $table_structure[ $column_name ]->mandatory; $max_length = $table_structure[ $column_name ]->max_length; } else { $msg = new WPDA_Message_Box( [ 'message_text' => __( "Column $column_name not found for list table", 'wp-data-access' ), 'message_type' => 'error', 'message_is_dismissible' => false, ] ); $msg->box(); break; } if ( '' === $max_length ) { $data_type = $data_type . ' ' . $type_attribute; } else { $data_type = $data_type . ' (' . $max_length . ') ' . $type_attribute; } if ( isset( $this->table_structure->listtable_column_options ) ) { $show_in_list = 'on' === $column->show ? 'checked' : ''; $label_in_list = $column->label; $lookup_in_list = isset( $column->lookup ) ? $column->lookup : ''; } else { $show_in_list = 'checked'; $label_in_list = ucfirst( str_replace( '_', ' ', $column_name ) ); $lookup_in_list = ''; } $i++; ?>
     
style="vertical-align:middle;width:16px;height:16px;" /> table_structure->relationships ) ) { foreach ( $this->table_structure->relationships as $relationship ) { if ( $column_name === $relationship->source_column_name[0] && 'lookup' === $relationship->relation_type ) { $lookup_column_list = WPDA_Dictionary_Lists::get_table_columns( $relationship->target_table_name ); ?>
table_structure ) { return __( 'Invalid structure', 'wp-data-access' ); } ?>
table_structure->tableform_column_options ) ) { $structure = $this->table_structure->tableform_column_options; foreach ( $this->table_structure->table as $column ) { $table_structure[ $column->column_name ] = $column; } } else { $structure = $this->table_structure->table; } $i = 0; foreach ( $structure as $column ) { $column_name = $column->column_name; if ( isset( $this->table_structure->tableform_column_options ) && isset ( $table_structure[ $column_name ] ) ) { $data_type = $table_structure[ $column_name ]->data_type; $type_attribute = $table_structure[ $column_name ]->type_attribute; $key = $table_structure[ $column_name ]->key; $mandatory = $table_structure[ $column_name ]->mandatory; $max_length = $table_structure[ $column_name ]->max_length; } else { $msg = new WPDA_Message_Box( [ 'message_text' => __( "Column $column_name not found for data entry form", 'wp-data-access' ), 'message_type' => 'error', 'message_is_dismissible' => false, ] ); $msg->box(); break; } if ( '' === $max_length ) { $data_type = $data_type . ' ' . $type_attribute; } else { $data_type = $data_type . ' (' . $max_length . ') ' . $type_attribute; } if ( isset( $this->table_structure->tableform_column_options ) ) { $show_on_form = 'on' === $column->show ? 'checked' : ''; $label_on_form = $column->label; $lookup_in_list = isset( $column->lookup ) ? $column->lookup : ''; } else { $show_on_form = 'checked'; $label_on_form = ucfirst( str_replace( '_', ' ', $column_name ) ); $lookup_in_list = ''; } if ( $this->wpda_list_columns->get_auto_increment_column_name() === $column_name ) { // Allow to hide auto_increment column. $key = 'No'; $mandatory = 'No'; } $i++; ?>
     
style="vertical-align:middle;width:16px;height:16px;" /> table_structure->relationships ) ) { foreach ( $this->table_structure->relationships as $relationship ) { if ( $column_name === $relationship->source_column_name[0] && 'lookup' === $relationship->relation_type ) { $lookup_column_list = WPDA_Dictionary_Lists::get_table_columns( $relationship->target_table_name ); ?>