Untitled a guest Feb 15th, 2014 784 Never a guest784Never

Not a member of Pastebin yet? Sign Up , it unlocks many cool features!

rawdownloadcloneembedreportprint PHP 37.15 KB <?php // this is the variable that controls the overall flow of the script $pgflow = $_GET [ pgflow ] ; $hostname_dataConn = $_POST [ hostname_dataConn ] ; $database_dataConn = $_POST [ database_dataConn ] ; $username_dataConn = $_POST [ username_dataConn ] ; $password_dataConn = $_POST [ password_dataConn ] ; // globals $current_table_name = '' ; $pk = '' ; #used to determine if feild is autoincrementing or not $ispk = '' ; #used to determine if the feild is a primary key $curpk = '' ; #used to store current primary key $autoincr = '' ; #used to determine if feild is autoincrementing or not for icon purpose $inset_keys = '' ; #used to build key portion of insert sql $insert_values = '' ; #used to build key portion of insert sql $insert_counter = '' ; #used to manage commas in insert sql $edit_counter = '' ; #used to manage commas in edit sql $insert_sql = '' ; #used for insert sql. duh $update_sql = '' ; #used for update sql $feildsarray = array ( ) ; #used for keyarray $keyarray = array ( ) ; #used for keyarray $numofpks = '' ; $where = '' ; #used for keyarray $where_orig = '' ; #used for show_changes function to track the original keys keyarray $passkeys = '' ; #used to hold string representation of primary keys that need to be passed along. $secure_string = '' ; #building this to lock down index.php to validate $pg feild # Conditional statements to determine program flow switch ( $pgflow ) { case 'build_scripts' : build_scripts ( ) ; break ; default : get_datbase_info ( ) ; } # switch ($pgflow) #------------------------------------------------------------------------------------------------------------------------------- function build_scripts ( ) { // globals global $current_table_name ; global $pk ; global $curpk ; print ( "Building Scripts, Please Wait!<br>" ) ; create_dataConn ( ) ; create_main_php ( ) ; print ( "dataConn.php built succesfully....<br>" ) ; print ( "Checking for Database Tables<br>" ) ; get_tables ( ) ; create_index_php ( ) ; } # end function build_scripts() #------------------------------------------------------------------------------------------------------------------------------- function get_tables ( ) { global $current_table_name ; global $pk ; global $curpk ; global $feildsarray ; global $keyarray ; global $numofpks ; global $where ; global $where_orig ; global $passkeys ; global $secure_string ; $sql_tables = "show tables" ; $result = connect ( $sql_tables ) ; $tablecount = 0 ; while ( $rows = mysql_fetch_array ( $result ) ) { ############# $numofpks = 0 ; $feildsarray = array ( ) ; $keyarray = array ( ) ; if ( $tablecount > 0 ) { # echo "<font color='orange'> AND </font>"; $secure_string = $secure_string . " && " ; } #$secure_string = $secure_string." \&\& "; $secure_string = $secure_string . " \$ pg != \" $rows[0] \" " ; ############### echo "<br><b>" . $rows [ 0 ] . "</b><br>" ; $current_table_name = $rows [ 0 ] ; $filename = "workshop/" . $rows [ 0 ] . ".php" ; $sql_feilds = "describe $rows[0] " ; $result_feilds = connect ( $sql_feilds ) ; $num_rows = mysql_num_rows ( $result_feilds ) ; $what = makefile ( $filename ) ; if ( $what == "success" ) { print ( "<a href=' $filename ' target='new_window'><font color='blue'>Created file $filename .</font></a><br>" ) ; } else { print ( "<font color='red'> Could not create Table $filename .</font><br>" ) ; } # end if ($what == "success") while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { echo "<font color='red'> " . $rows_feilds [ 0 ] . " | " . $rows_feilds [ 1 ] . " | " . $rows_feilds [ 2 ] . " | " . $rows_feilds [ 3 ] . " | " . $rows_feilds [ 4 ] . " | " . $rows_feilds [ 5 ] . "</font><br>" ; if ( $rows_feilds [ 3 ] == 'PRI' ) { $curpk = $rows_feilds [ 0 ] ; } //added code ---------------------------------- $feildsarray [ $rows_feilds [ 0 ] ] = $rows_feilds [ 1 ] ; if ( $rows_feilds [ 3 ] == 'PRI' | $num_rows == 0 ) { $keyarray [ $curpk ] = $rows_feilds [ 1 ] ; $numofpks ++; } $where = "WHERE " ; $where_orig = "WHERE " ; $passkeys = '' ; if ( $numofpks == 0 ) { $keyarray = $feildsarray ; } $add = 0 ; foreach ( $keyarray as $k => $v ) { #echo "<font color='orange'>\$makeallkeys[$k] => $v.<br /></font>

"; if ( $add > 0 ) { # echo "<font color='orange'> AND </font>"; $where = $where . " AND " ; $where_orig = $where_orig . " AND " ; } #echo "<font color='orange'>`$k` =`$$k`</font>"; $where = $where . "` $k ` ='$ $k '" ; $where_orig = $where_orig . "` $k ` =' \$ orig_ $k '" ; $passkeys = $passkeys . "& $k = \$ row[ $k ]" ; #$pg != "main" # `application_id` =2 AND `language_id` =4 AND `application_name` = 'hgsd' AND `application_comment` = 'hgd' LIMIT 1 ; $add ++; } $where = $where . " LIMIT 1 ;" ; $where_orig = $where_orig . " LIMIT 1 ;" ; // end added code ---------------------------------- } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) print ( "<br>WHERE CLAUSE: $where " ) ; print ( "<br>ORIG WHERE CLAUSE: $where_orig " ) ; print ( "<br>PASSKEYS: $passkeys " ) ; # print("<br>SECURE STRING: $secure_string"); //here we start writing to the files write_header ( ) ; write_delete_record_function ( ) ; write_new_record_functon ( ) ; write_insert_record_functon ( ) ; write_edit_record_functon ( ) ; write_show_changes_functon ( ) ; write_update_database_functon ( ) ; //keep this function last since it has the code that closes out the program. write_default_function ( ) ; // increment table counter $tablecount ++; } # end while ($rows = mysql_fetch_array($result)) } # end function get_tables #------------------------------------------------------------------------------------------------------------------------------- function get_datbase_info ( ) { //This presents the user with a form to fill out to type in the information of their database ?> <form action="phpapp.php?pgflow=build_scripts" method="POST"> <h2>Welcome to My PHP Project. This program will generate an application based on tables in your MYSQL database. </h2> <table width="600" cellspacing="5" cellpadding="5"> <tr> <td>Host Name</td> <td><input name="hostname_dataConn" type="text" id="hostname_dataConn"></td> </tr> <tr> <td>Database Name</td> <td><input name="database_dataConn" type="text" id="database_dataConn"></td> </tr> <tr> <td>User Name</td> <td><input name="username_dataConn" type="text" id="username_dataConn"></td> </tr> <tr> <td>Password</td> <td><input name="password_dataConn" type="text" id="password_dataConn"></td> </tr> <tr> <td><input type="submit" name="submit" value="submit"></td> <td><input type="reset" name="reset" value="reset"></td> </tr> </table> </form> <? } #end function get_database_info() #------------------------------------------------------------------------------------------------------------------------------- function connect ( $sql ) { include ( "workshop/dataConn.php" ) ; //echo "commnecing connection to local db<br>"; if ( ! ( $conn = mysql_connect ( $hostname_dataConn , $username_dataConn , $password_dataConn ) ) ) { printf ( "error connecting to DB" ) ; exit ( ) ; } # end if (!($conn=mysql_connect($hostname_dataConn, $username_dataConn, $password_dataConn))) $db2 = mysql_select_db ( $database_dataConn , $conn ) ; $result = mysql_query ( $sql ) ; if ( $result ) { return $result ; } else { $error = mysql_error ( ) ; echo "Can't complete query because $error " ; die ( ) ; } #end if ($result) } # end function connect($sql) #------------------------------------------------------------------------------------------------------------------------------- function create_dataConn ( ) { global $hostname_dataConn ; global $database_dataConn ; global $username_dataConn ; global $password_dataConn ; #print ("Host Name: $hostname_dataConn<br>"); #print ("Database Name: $database_dataConn<br>"); #print ("User Name: $username_dataConn<br>"); #print ("Password: $password_dataConn<br>"); $filename = "workshop/dataConn.php" ; $what = makefile ( $filename ) ; if ( $what == "success" ) { # print("Write to dataConn.php"); $f = @ fopen ( $filename , 'w' ) ; // Write the data to the file fwrite ( $f , "<?

" ) ; fwrite ( $f , " \$ hostname_dataConn = \" $hostname_dataConn \" ;

" ) ; fwrite ( $f , " \$ database_dataConn = \" $database_dataConn \" ;

" ) ; fwrite ( $f , " \$ username_dataConn = \" $username_dataConn \" ;

" ) ; fwrite ( $f , " \$ password_dataConn = \" $password_dataConn \" ;

" ) ; fwrite ( $f , " \$ dataConn = mysql_pconnect( \$ hostname_dataConn, \$ username_dataConn, \$ password_dataConn) or trigger_error(mysql_error(),E_USER_ERROR);

" ) ; fwrite ( $f , "?>" ) ; fclose ( $f ) ; } else { print ( " $what <br>" ) ; print ( "Can not proceed any further<br>" ) ; print ( "<a href='deletefiles.php'>Delete that Shit!</a>" ) ; exit ; } # end if ($what == "success") } #end function create_dataConn(){ #------------------------------------------------------------------------------------------------------------------------------- function makefile ( $file ) { global $hostname_dataConn ; global $database_dataConn ; global $username_dataConn ; global $password_dataConn ; if ( file_exists ( $file ) ) { $fileresult = $file . ' already exists!' ; return $fileresult ; } else { $f = @ fopen ( $file , 'w' ) ; if ( ! $f ) { $fileresult = 'could not create file: ' . $file ; return $fileresult ; } else { $fileresult = 'success' ; return $fileresult ; } #end if (file_exists($file)) fclose ( $f ) ; } # end if (!$f) } # end function makefile($file) #------------------------------------------------------------------------------------------------------------------------------- function write_header ( ) { global $table_names ; global $current_table_name ; # print(" Write the header of the file. This is the Flow control portion of the file<br>"); # echo "<br>$current_table_name <font color='red'>".$rows_feilds[0]." | ".$rows_feilds[1]." | ".$rows_feilds[2]." | ".$rows_feilds[3]." | ".$rows_feilds[4]." | ".$rows_feilds[5]."</font><br>"; $f = @ fopen ( "workshop/" . $current_table_name . ".php" , 'w' ) ; // Write the data to the file fwrite ( $f , " <? # include ( \" secure.php \" ); \$ pgflow = \$ _GET[pgflow]; #global \$ application; if ( \$ application != \" yes \" ) { print( \" <html> <head> <title>IOBE - PHP - MySQL </title> <link rel='stylesheet' href='styles/style.css' type='text/css' media='all' /> <script language= \\ \" javascript \\ \" type= \\ \" text/javascript \\ \" src= \\ \" js/datetimepicker.js \\ \" ></script> <script language= \\ \" javascript \\ \" type= \\ \" text/javascript \\ \" > <!-- function confirmLink() { return confirm( \\ \" Are you sure you want to Delete this Record? \\ \" ) } //--> </script> </head> <body> \" ); } # Conditional statements to determine program flow switch ( \$ pgflow) { case 'addrecord': new_record(); break; case 'insertrecord': insert_record(); break; case 'deleterecord': delete_record(); break; case 'editrecord': edit_record(); break; case 'showchanges': show_changes(); break; case 'verified': update_database(); break; default: show_data(); } " ) ; fclose ( $f ) ; } #end function write_header() #------------------------------------------------------------------------------------------------------------------------------- function write_default_function ( ) { global $current_table_name ; global $pk ; global $passkeys ; # print(" Write the Default function"); $f = @ fopen ( "workshop/" . $current_table_name . ".php" , 'a' ) ; // Write the data to the file fwrite ( $f , " function show_data(){ // Title of page print \" <center><h3> $current_table_name </h3></center> \" ; // this pulls in connection specific information to connect to the database include ( \" dataConn.php \" ); //connect to database mysql_select_db( \$ database_dataConn, \$ dataConn); //create sql \$ sql_user_data= \" SELECT * FROM $current_table_name \" ; // this statement actually executes the sql \$ result = mysql_query( \$ sql_user_data); //Create table print( \" <table border='1' align='center'><tr> \" ); //add edit column header print( \" <th>Edit \" ); //create column headers based on feilds from table " ) ; $sql_feilds = "describe $current_table_name " ; $result_feilds = connect ( $sql_feilds ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { fwrite ( $f , " print( \" <th> $rows_feilds[0] \" );

" ) ; if ( $rows_feilds [ 3 ] == 'PRI' ) { $pk = '$row[' . $rows_feilds [ 0 ] . ']' ; } } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite ( $f , " // add the delete column header print( \" <th>Delete</tr> \" ); //now we iterate through the results of the SQL Query while( \$ row = mysql_fetch_array( \$ result)) { //create a new row in the table print( \" <tr> \" ); // add an edit icon for the row print( \" <td align='center'><a href=' \" . \$ _SERVER['PHP_SELF']. \" ?pg= $current_table_name &pgflow=editrecord $passkeys '><img src='images/edit_icon.png' width='16' height='16' border='0' alt='edit'></a></td> \" ); " ) ; $result_feilds = connect ( $sql_feilds ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { fwrite ( $f , "print( \" <td> \$ row[ $rows_feilds[0] ] </td> \" );

" ) ; } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite ( $f , " // add a delete icon for the row print( \" <td align='center'><a href=' \" . \$ _SERVER['PHP_SELF']. \" ?pg= $current_table_name &pgflow=deleterecord $passkeys ' ONCLICK= \\ \" return confirmLink() \\ \" ><img src='images/delete_icon.png' width='16' height='16' border='0' alt='edit'></a></td> \" ); print( \" </tr> \" ); } #end while( $row = mysql_fetch_array( $result )) // add a final row to the end of the table that has a link to add a record print( \" <tr><td align='right'><a href=' \" . \$ _SERVER['PHP_SELF']. \" ?pg= $current_table_name &pgflow=addrecord'>New Record</a><td></tr> \" ); // finally we close the table print( \" </table> \" ); " ) ; //Close out functions and end program since this is the last functions fwrite ( $f , " } ?>" ) ; fclose ( $f ) ; } #end function write_default_function() #------------------------------------------------------------------------------------------------------------------------------- function write_delete_record_function ( ) { global $current_table_name ; global $pk ; global $where ; $sql_feilds = "describe $current_table_name " ; $result_feilds = connect ( $sql_feilds ) ; $insert_counter = 1 ; # while ($rows_feilds = mysql_fetch_array($result_feilds)) # { # if ($rows_feilds[3] == 'PRI') {$pk=$rows_feilds[0];} # } # end while ($rows_feilds = mysql_fetch_array($result_feilds #print(" Write the Default function. Primary Key:$pk:"); $f = @ fopen ( "workshop/" . $current_table_name . ".php" , 'a' ) ; // Write the data to the file fwrite ( $f , " #------------------------------------------------------------------------------------------------------------------------------- function delete_record(){ //get the variable datakey //database info include( \" dataConn.php \" ); " ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { if ( $insert_counter == 1 ) { $inset_keys = $inset_keys . $rows_feilds [ 0 ] ; $insert_values = $insert_values . $rows_feilds [ 0 ] ; } else { $inset_keys = $inset_keys . ', ' . $rows_feilds [ 0 ] ; $insert_values = $insert_values . '\', \'$' . $rows_feilds [ 0 ] ; } fwrite ( $f , " \$ $rows_feilds[0] = \$ _GET[ $rows_feilds[0] ]; //print out variables so we can see if they made it #print ( \" \$ $rows_feilds[0] <br> \" ); " ) ; $insert_counter ++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds //Create complete sql statement # $insert_sql=$inset_keys.$insert_values.'\')";'; #print("<hr>sql: $insert_sql<hr>"); fwrite ( $f , " //connect to database mysql_select_db( \$ database_dataConn, \$ dataConn); // create sql \$ sql_delete_record = \" DELETE FROM ` $current_table_name ` $where \" ; #print ( \" \$ sql_delete_record \" ); // delete the old record if it exists \$ result = mysql_query( \$ sql_delete_record); // close database mysql_close(); //show records in table show_data(); } " ) ; fclose ( $f ) ; } #end function write_delete_function() #------------------------------------------------------------------------------------------------------------------------------- function write_new_record_functon ( ) { global $current_table_name ; global $pk ; global $ispk ; global $autoincr ; $f = @ fopen ( "workshop/" . $current_table_name . ".php" , 'a' ) ; // Write the data to the file fwrite ( $f , " #------------------------------------------------------------------------------------------------------------------------------- function new_record(){ //title of page and open table print ( \" <br><br><center><h3> Add New Record in Table: $current_table_name </h3></center> <form action=' \" . \$ _SERVER['PHP_SELF']. \" ?pg= $current_table_name &pgflow=insertrecord' method='POST' name='log_entry'> <TABLE align='center' border='1'> \" ); " ) ; $sql_feilds = "describe $current_table_name " ; $result_feilds = connect ( $sql_feilds ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { if ( $rows_feilds [ 3 ] == 'PRI' ) { $pk = '$row[' . $rows_feilds [ 0 ] . ']' ; $ispk = "<img src='images/primarykey_icon.png' width='16' height='16' border='0' alt='Primary Key Feild'>" ; } else { $ispk = '' ; } if ( $rows_feilds [ 5 ] == 'auto_increment' ) { $autoincr = "<img src='images/autoincrement_icon.png' width='16' height='16' border='0' alt='Auto Incrementing'>" ; } else { $autoincr = '' ; } if ( $rows_feilds [ 1 ] == 'datetime' ) { $datepicker = "<a href= \\ \" javascript:NewCal('" . $rows_feilds [ 0 ] . "','ddmmmyyyy',true,24) \\ \" ><img src= \\ \" images/calendar_icon.png \\ \" width= \\ \" 16 \\ \" height= \\ \" 16 \\ \" border= \\ \" 0 \\ \" alt= \\ \" Pick a date \\ \" ></a>

" ; } elseif ( $rows_feilds [ 1 ] == 'date' ) { $datepicker = "<a href= \\ \" javascript:NewCal('" . $rows_feilds [ 0 ] . "','ddmmmyyyy') \\ \" ><img src= \\ \" images/calendar_icon.png \\ \" width= \\ \" 16 \\ \" height= \\ \" 16 \\ \" border= \\ \" 0 \\ \" alt= \\ \" Pick a date \\ \" ></a>

" ; } else { $datepicker = '' ; } fwrite ( $f , "print( \" <tr><td> $rows_feilds[0] </td><td><input name=' $rows_feilds[0] ' type='text' id=' $rows_feilds[0] '> $ispk $autoincr $datepicker </td></tr>

\" ); " ) ; } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite ( $f , " //add submit and reset buttons print( \" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> \" ); } " ) ; fclose ( $f ) ; } #end function write_new_record_functon(); #------------------------------------------------------------------------------------------------------------------------------- function write_insert_record_functon ( ) { global $current_table_name ; global $pk ; global $ispk ; global $autoincr ; global $inset_keys ; global $insert_values ; global $insert_counter ; global $insert_sql ; //Initialize our variables $inset_keys = '$sql_insert = "INSERT INTO ' . $current_table_name . ' (' ; $insert_values = ') VALUES (\'$' ; $insert_counter = 1 ; $sql_feilds = "describe $current_table_name " ; $result_feilds = connect ( $sql_feilds ) ; $f = @ fopen ( "workshop/" . $current_table_name . ".php" , 'a' ) ; // Write the data to the file fwrite ( $f , " #------------------------------------------------------------------------------------------------------------------------------- function insert_record(){ include( \" dataConn.php \" ); // Variables can be declared here " ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { if ( $insert_counter == 1 ) { $inset_keys = $inset_keys . $rows_feilds [ 0 ] ; $insert_values = $insert_values . $rows_feilds [ 0 ] ; } else { $inset_keys = $inset_keys . ', ' . $rows_feilds [ 0 ] ; $insert_values = $insert_values . '\', \'$' . $rows_feilds [ 0 ] ; } fwrite ( $f , " \$ $rows_feilds[0] = \$ _POST[ $rows_feilds[0] ]; //print out variables so we can see if they made it #print ( \" \$ $rows_feilds[0] <br> \" ); " ) ; $insert_counter ++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds //Create complete sql statement $insert_sql = $inset_keys . $insert_values . '\')";' ; print ( "<hr>sql: $insert_sql <hr>" ) ; fwrite ( $f , " //connect to database mysql_select_db( \$ database_dataConn, \$ dataConn); //create sql $insert_sql #print( \" \$ sql_insert \" ); // this statement actually executes the sql \$ result = mysql_query( \$ sql_insert); # make this vaiable match the last one // close database mysql_close(); //show records in table show_data(); } " ) ; fclose ( $f ) ; } #function write_insert_record_functon() #------------------------------------------------------------------------------------------------------------------------------- function write_edit_record_functon ( ) { global $current_table_name ; global $pk ; global $ispk ; global $autoincr ; global $curpk ; global $where ; $sql_feilds = "describe $current_table_name " ; $result_feilds = connect ( $sql_feilds ) ; $insert_counter = 1 ; # print("<hr>Primary key is $curpk<hr>"); $f = @ fopen ( "workshop/" . $current_table_name . ".php" , 'a' ) ; // Write the data to the file fwrite ( $f , " #------------------------------------------------------------------------------------------------------------------------------- function edit_record(){ // this pulls in connection specific information to connect to the database include ( \" dataConn.php \" ); //get vars " ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { if ( $insert_counter == 1 ) { $inset_keys = $inset_keys . $rows_feilds [ 0 ] ; $insert_values = $insert_values . $rows_feilds [ 0 ] ; } else { $inset_keys = $inset_keys . ', ' . $rows_feilds [ 0 ] ; $insert_values = $insert_values . '\', \'$' . $rows_feilds [ 0 ] ; } fwrite ( $f , " \$ $rows_feilds[0] = \$ _GET[ $rows_feilds[0] ]; //print out variables so we can see if they made it #print ( \" \$ $rows_feilds[0] <br> \" ); " ) ; $insert_counter ++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds fwrite ( $f , " //connect to database mysql_select_db( \$ database_dataConn, \$ dataConn); //create sql \$ sql_table_data= \" SELECT * FROM $current_table_name $where \" ; #print( \" \$ sql_table_data \" ); // this statement actually executes the sql \$ result = mysql_query( \$ sql_table_data); //access record info and build form while( \$ row = mysql_fetch_array( \$ result)) { //title of page and open table print ( \" <br><br><center><h3> Edit Log entry </h3></center> <form action=' \" . \$ _SERVER['PHP_SELF']. \" ?pg= $current_table_name &pgflow=showchanges' method='POST' name='log_entry'> <TABLE border='1'> \" ); " ) ; $sql_feilds = "describe $current_table_name " ; $result_feilds = connect ( $sql_feilds ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { if ( $rows_feilds [ 3 ] == 'PRI' ) { $pk = '$row[' . $rows_feilds [ 0 ] . ']' ; $ispk = "<img src='images/primarykey_icon.png' width='16' height='16' border='0' alt='Primary Key Feild'>

" ; } else { $ispk = '' ; } if ( $rows_feilds [ 5 ] == 'auto_increment' ) { $autoincr = "<img src='images/autoincrement_icon.png' width='16' height='16' border='0' alt='Auto Incrementing'>

" ; } else { $autoincr = '' ; } if ( $rows_feilds [ 1 ] == 'datetime' ) { $datepicker = "<a href= \\ \" javascript:NewCal('" . $rows_feilds [ 0 ] . "','ddmmmyyyy',true,24) \\ \" ><img src= \\ \" images/calendar_icon.png \\ \" width= \\ \" 16 \\ \" height= \\ \" 16 \\ \" border= \\ \" 0 \\ \" alt= \\ \" Pick a date \\ \" ></a>

" ; } elseif ( $rows_feilds [ 1 ] == 'date' ) { $datepicker = "<a href= \\ \" javascript:NewCal('" . $rows_feilds [ 0 ] . "','ddmmmyyyy') \\ \" ><img src= \\ \" images/calendar_icon.png \\ \" width= \\ \" 16 \\ \" height= \\ \" 16 \\ \" border= \\ \" 0 \\ \" alt= \\ \" Pick a date \\ \" ></a>

" ; } else { $datepicker = '' ; } fwrite ( $f , " print( \" <tr><td> $rows_feilds[0] </td><td><input name=' $rows_feilds[0] ' type='text' id=' $rows_feilds[0] ' value=' \$ row[ $rows_feilds[0] ]'> $ispk $autoincr $datepicker </td></tr>

\" );

print( \" <input name='orig_ $rows_feilds[0] ' type='hidden' id='orig_ $rows_feilds[0] ' value=' \$ row[ $rows_feilds[0] ]'>

\" );

" ) ; } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite ( $f , " //add submit and reset buttons print( \" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> \" ); } } " ) ; fclose ( $f ) ; } #end function write_edit_record_functon() #------------------------------------------------------------------------------------------------------------------------------- function write_show_changes_functon ( ) { global $current_table_name ; global $pk ; global $ispk ; global $autoincr ; global $inset_keys ; global $insert_values ; global $insert_counter ; global $insert_sql ; global $update_sql ; global $curpk ; global $where ; global $where_orig ; //Initialize our variables $sql_feilds = "describe $current_table_name " ; $result_feilds = connect ( $sql_feilds ) ; $f = @ fopen ( "workshop/" . $current_table_name . ".php" , 'a' ) ; // Write the data to the file fwrite ( $f , " #------------------------------------------------------------------------------------------------------------------------------- function show_changes(){ // Variables can be declared here " ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { if ( $insert_counter == 1 ) { $inset_keys = $inset_keys . $rows_feilds [ 0 ] ; $insert_values = $insert_values . $rows_feilds [ 0 ] ; } else { $inset_keys = $inset_keys . ', ' . $rows_feilds [ 0 ] ; $insert_values = $insert_values . '\', \'$' . $rows_feilds [ 0 ] ; } fwrite ( $f , " \$ $rows_feilds[0] = \$ _POST[ $rows_feilds[0] ]; \$ orig_ $rows_feilds[0] = \$ _POST[orig_ $rows_feilds[0] ]; //print out variables so we can see if they made it #print ( \" \$ $rows_feilds[0] <br> \" ); #print ( \" \$ orig_ $rows_feilds[0] <br> \" ); " ) ; $insert_counter ++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds fwrite ( $f , " // this pulls in connection specific information to connect to the database include ( \" dataConn.php \" ); //connect to database mysql_select_db( \$ database_dataConn, \$ dataConn); //create sql \$ sql_user_data= \" SELECT * FROM $current_table_name $where_orig \" ; #print( \" \$ sql_user_data \" ); // this statement actually executes the sql \$ result = mysql_query( \$ sql_user_data); //access record info and build form while( \$ row = mysql_fetch_array( \$ result)) { //title of page and open table print ( \" <br><br><center><h3> Please Verify Changed below and Submit to database if correct. </h3></center> <form action=' \" . \$ _SERVER['PHP_SELF']. \" ?pg= $current_table_name &pgflow=verified' method='POST' name='log_entry'> <TABLE> \" ); " ) ; $sql_feilds = "describe $current_table_name " ; $result_feilds = connect ( $sql_feilds ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { fwrite ( $f , " if ( \$ row[ $rows_feilds[0] ]== \$ $rows_feilds[0] ) { \$ fontcolor = 'black';} else { \$ fontcolor = 'red';} print( \" <tr><td><font color= \$ fontcolor> $rows_feilds[0] </font></td><td><input name='x $rows_feilds[0] ' type='text' id='x $rows_feilds[0] ' value=' \$ $rows_feilds[0] ' disabled></td></tr> \" ); print( \" <input name=' $rows_feilds[0] ' type='hidden' id=' $rows_feilds[0] ' value=' \$ $rows_feilds[0] '> \" ); print( \" <input name='orig_ $rows_feilds[0] ' type='hidden' id='orig_ $rows_feilds[0] ' value=' \$ orig_ $rows_feilds[0] '> \" ); " ) ; } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite ( $f , " //add submit and reset buttons print( \" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> \" ); } #end while( \$ row = mysql_fetch_array( \$ result)) exit; } #end function show_changes(){ " ) ; } #end function write_show_changes_functon() #------------------------------------------------------------------------------------------------------------------------------- function write_update_database_functon ( ) { global $current_table_name ; global $pk ; global $ispk ; global $autoincr ; global $edit_counter ; global $curpk ; global $where ; global $where_orig ; //Initialize our variables $edit_counter = 1 ; $update_sql = "" ; $sql_feilds = "describe $current_table_name " ; $result_feilds = connect ( $sql_feilds ) ; $f = @ fopen ( "workshop/" . $current_table_name . ".php" , 'a' ) ; // Write the data to the file fwrite ( $f , " #------------------------------------------------------------------------------------------------------------------------------- function update_database(){ include( \" dataConn.php \" ); // Variables can be declared here " ) ; while ( $rows_feilds = mysql_fetch_array ( $result_feilds ) ) { if ( $edit_counter == 1 ) { $update_sql = $update_sql . "`" . $rows_feilds [ 0 ] . "` = '$" . $rows_feilds [ 0 ] . "'" ; } else { $update_sql = $update_sql . ",`" . $rows_feilds [ 0 ] . "` = '$" . $rows_feilds [ 0 ] . "'" ; } fwrite ( $f , " \$ $rows_feilds[0] = \$ _POST[ $rows_feilds[0] ]; \$ orig_ $rows_feilds[0] = \$ _POST[orig_ $rows_feilds[0] ]; //print out variables so we can see if they made it #print ( \" \$ $rows_feilds[0] <br> \" ); #print ( \" \$ orig_ $rows_feilds[0] <br> \" ); " ) ; $edit_counter ++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds print ( "<hr> $update_sql <hr>" ) ; //Create complete sql statement fwrite ( $f , " //connect to database mysql_select_db( \$ database_dataConn, \$ dataConn); //create sql \$ sql_update= \" UPDATE `" . $current_table_name . "` SET " . $update_sql . " " . $where_orig . " \" ; #print( \" \$ sql_update \" ); // this statement actually executes the sql \$ result = mysql_query( \$ sql_update); # make this vaiable match the last one // close database mysql_close(); //show records in table show_data(); exit; } " ) ; fclose ( $f ) ; } #end function write_update_database_functon() #------------------------------------------------------------------------------------------------------------------------------- function create_main_php ( ) { global $hostname_dataConn ; global $database_dataConn ; global $username_dataConn ; global $password_dataConn ; #print ("Host Name: $hostname_dataConn<br>"); #print ("Database Name: $database_dataConn<br>"); #print ("User Name: $username_dataConn<br>"); #print ("Password: $password_dataConn<br>"); $filename = "workshop/main.php" ; $what = makefile ( $filename ) ; if ( $what == "success" ) { # print("Write to dataConn.php"); $f = @ fopen ( $filename , 'w' ) ; // Write the data to the file fwrite ( $f , "<? print( \" <br><br><br><br><br><hr><h3>If you are seeing this, your application build was probably successful</h3><hr> \" ); ?>" ) ; fclose ( $f ) ; } else { print ( " $what <br>" ) ; print ( "Can not proceed any further<br>" ) ; print ( "<a href='deletefiles.php'>Delete that Shit!</a>" ) ; exit ; } # end if ($what == "success") } #end function create_main_php()() #------------------------------------------------------------------------------------------------------------------------------- function create_index_php ( ) { global $hostname_dataConn ; global $database_dataConn ; global $username_dataConn ; global $password_dataConn ; global $secure_string ; #print ("Host Name: $hostname_dataConn<br>"); #print ("Database Name: $database_dataConn<br>"); #print ("User Name: $username_dataConn<br>"); #print ("Password: $password_dataConn<br>"); print ( "<hr>SECURITY STRING: $secure_string <hr>" ) ; print ( "<hr><hr><a href='workshop/index.php' target='newwin'>Click Here to Check out your new application</a><hr><hr>" ) ; $filename = "workshop/index.php" ; $what = makefile ( $filename ) ; if ( $what == "success" ) { # print("Write to dataConn.php"); $f = @ fopen ( $filename , 'w' ) ; // Write the data to the file fwrite ( $f , " <html> <head> <title>IOBE - PHP - MySQL </title> <? \$ application = \" yes \" ; ?> <link rel='stylesheet' href='styles/style.css' type='text/css' media='all' /> <script language= \" javascript \" type= \" text/javascript \" src= \" js/datetimepicker.js \" > </script> <script language= \" javascript \" type= \" text/javascript \" > <!-- function confirmLink() { return confirm( \" Are you sure you want to Delete this Record? \" ) } //--> </script> </head> <table style='width:100%; background-color:#E4E0E0' cellspacing='3' class='topborder'><tr><td style='text-align:left; vertical-align:bottom'> </td> <td style='text-align:right'> </td> </tr></table><table style='width:100%;' cellspacing='3' id='header'><tr><td colspan='2' style='text-align:left; vertical-align: middle;'> <h2><img src='images/logo.png' alt='' /> IOBE</h2></td><td style='text-align:right'><h2>Application Builder 1.0 </h2> </td> </tr></table> <table style='width:100 %' c ellspacing='3'><td style='width:20%;'></td> <td style='width:60%;'><img src='images/blank.gif' width='1' height='1' alt='' /></td> <td style='width:20%;'></td></tr><tr><td style='width:20%; vertical-align: top;'> <div class='spacer'> <table cellpadding='0' cellspacing='0'> <tr> <td class='captiontopleft'><img src='images/blank.gif' width='24' height='3' alt='' style='display: block;' /></td> <td class='captiontopmiddle'><img src='images/blank.gif' width='1' height='3' alt='' style='display: block;' /></td> <td class='captiontopright'><img src='images/blank.gif' width='11' height='3' alt='' style='display: block;' /></td> </tr> </table> <table cellpadding='0' cellspacing='0'> <tr> <td class='captionleft'><img src='images/blank.gif' width='24' height='18' alt='' style='display: block;' /></td> <td class='captionbar' style='white-space:nowrap'>Table Menu</td> <td class='captionend'><img src='images/blank.gif' width='12' height='18' alt='' style='display: block;' /></td> <td class='captionmain'><img src='images/blank.gif' width='1' height='18' alt='' style='display: block;' /></td> <td class='captionright'><img src='images/blank.gif' width='11' height='18' alt='' style='display: block;' /></td> </tr> </table> <table cellpadding='0' cellspacing='0'> <tr> <td class='bodyleft'><img src='images/blank.gif' width='3' height='1' alt='' style='display: block;' /></td> <td class='bodymain'> " ) ; $sql_tables = "show tables" ; $result = connect ( $sql_tables ) ; while ( $rows = mysql_fetch_array ( $result ) ) { #echo "<br><b>".$rows[0]."</b><br>"; $current_table_name = $rows [ 0 ] ; fwrite ( $f , " <span><img src='images/bullet2.gif' alt='bullet' /><a href='index.php?pg= $current_table_name '> $current_table_name </a></span><br /> " ) ; } # end while ($rows = mysql_fetch_array($result)) fwrite ( $f , " </td> <td class='bodyright'><img src='images/blank.gif' width='3' height='1' alt='' style='display: block;' /></td> </tr> </table> <table cellpadding='0' cellspacing='0'> <tr> <td class='bottomleft'><img src='images/blank.gif' width='10' height='9' alt='' style='display: block;' /></td> <td class='bottommain'><img src='images/blank.gif' width='1' height='9' alt='' style='display: block;' /></td> <td class='bottomright'><img src='images/blank.gif' width='10' height='9' alt='' style='display: block;' /></td> </tr> </table> </div> <div class='spacer'></div> </td> <td style='width:20%; vertical-align:top'> <? if ( $secure_string ){ \$ pg = \" main \" ;} if ( \$ pg == \" \" ){ \$ pg = \" main \" ; } \$ page= \$ pg. \" .php \" ; include( \$ page) ; ?></td></tr><tr> <td colspan='3' style='text-align:center' class='smalltext'>This site was created with IOBE.<br /></td></tr></table> <div style='text-align:center'><table style='width:100%'><tr><td style='width:30%; vertical-align:top'> </td><td style='width:40%; vertical-align:top'></td><td style='width:30%; vertical-align:top'> </td></tr></table></div> </body></html> " ) ; fclose ( $f ) ; print ( "<hr><hr>file should be written<hr><hr>" ) ; } else { print ( " $what <br>" ) ; print ( "Can not proceed any further<br>" ) ; print ( "<a href='deletefiles.php'>Delete that Shit!</a>" ) ; exit ; } # end if ($what == "success") } #end function create_index_php() #------------------------------------------------------------------------------------------------------------------------------- function blank ( ) { } #end function blank() ?>

RAW Paste Data

<?php // this is the variable that controls the overall flow of the script $pgflow = $_GET[pgflow]; $hostname_dataConn = $_POST[hostname_dataConn]; $database_dataConn = $_POST[database_dataConn]; $username_dataConn = $_POST[username_dataConn]; $password_dataConn = $_POST[password_dataConn]; // globals $current_table_name = ''; $pk =''; #used to determine if feild is autoincrementing or not $ispk=''; #used to determine if the feild is a primary key $curpk =''; #used to store current primary key $autoincr=''; #used to determine if feild is autoincrementing or not for icon purpose $inset_keys=''; #used to build key portion of insert sql $insert_values=''; #used to build key portion of insert sql $insert_counter = ''; #used to manage commas in insert sql $edit_counter = ''; #used to manage commas in edit sql $insert_sql = ''; #used for insert sql. duh $update_sql = ''; #used for update sql $feildsarray = array(); #used for keyarray $keyarray = array(); #used for keyarray $numofpks = ''; $where = ''; #used for keyarray $where_orig = ''; #used for show_changes function to track the original keys keyarray $passkeys = ''; #used to hold string representation of primary keys that need to be passed along. $secure_string =''; #building this to lock down index.php to validate $pg feild # Conditional statements to determine program flow switch ($pgflow) { case 'build_scripts': build_scripts(); break; default: get_datbase_info(); }# switch ($pgflow) #------------------------------------------------------------------------------------------------------------------------------- function build_scripts(){ // globals global $current_table_name; global $pk; global $curpk; print ("Building Scripts, Please Wait!<br>"); create_dataConn(); create_main_php(); print ("dataConn.php built succesfully....<br>"); print ("Checking for Database Tables<br>"); get_tables (); create_index_php(); } # end function build_scripts() #------------------------------------------------------------------------------------------------------------------------------- function get_tables (){ global $current_table_name; global $pk; global $curpk; global $feildsarray; global $keyarray; global $numofpks; global $where; global $where_orig; global $passkeys; global $secure_string; $sql_tables = "show tables"; $result = connect($sql_tables); $tablecount = 0; while ($rows = mysql_fetch_array($result)) { ############# $numofpks = 0; $feildsarray = array(); $keyarray = array(); if ($tablecount > 0){ # echo "<font color='orange'> AND </font>"; $secure_string = $secure_string." && "; } #$secure_string = $secure_string." \&\& "; $secure_string = $secure_string."\$pg != \"$rows[0]\""; ############### echo "<br><b>".$rows[0]."</b><br>"; $current_table_name = $rows[0]; $filename ="workshop/".$rows[0].".php"; $sql_feilds = "describe $rows[0]"; $result_feilds = connect($sql_feilds); $num_rows = mysql_num_rows($result_feilds); $what = makefile($filename); if ($what == "success"){ print("<a href='$filename' target='new_window'><font color='blue'>Created file $filename.</font></a><br>"); } else { print("<font color='red'> Could not create Table $filename.</font><br>"); }# end if ($what == "success") while ($rows_feilds = mysql_fetch_array($result_feilds)) { echo "<font color='red'> ".$rows_feilds[0]." | ".$rows_feilds[1]." | ".$rows_feilds[2]." | ".$rows_feilds[3]." | ".$rows_feilds[4]." | ".$rows_feilds[5]."</font><br>"; if ($rows_feilds[3] == 'PRI') {$curpk=$rows_feilds[0];} //added code ---------------------------------- $feildsarray[$rows_feilds[0]] = $rows_feilds[1]; if ($rows_feilds[3] == 'PRI' | $num_rows == 0) { $keyarray[$curpk] = $rows_feilds[1]; $numofpks++; } $where = "WHERE "; $where_orig = "WHERE "; $passkeys = ''; if ($numofpks == 0) {$keyarray = $feildsarray;} $add = 0; foreach ($keyarray as $k => $v) { #echo "<font color='orange'>\$makeallkeys[$k] => $v.<br /></font>

"; if ($add > 0){ # echo "<font color='orange'> AND </font>"; $where = $where." AND "; $where_orig = $where_orig." AND "; } #echo "<font color='orange'>`$k` =`$$k`</font>"; $where = $where."`$k` ='$$k'"; $where_orig = $where_orig."`$k` ='\$orig_$k'"; $passkeys = $passkeys."&$k=\$row[$k]"; #$pg != "main" # `application_id` =2 AND `language_id` =4 AND `application_name` = 'hgsd' AND `application_comment` = 'hgd' LIMIT 1 ; $add++; } $where = $where." LIMIT 1 ;"; $where_orig = $where_orig." LIMIT 1 ;"; // end added code ---------------------------------- } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) print("<br>WHERE CLAUSE: $where"); print("<br>ORIG WHERE CLAUSE: $where_orig"); print("<br>PASSKEYS: $passkeys"); # print("<br>SECURE STRING: $secure_string"); //here we start writing to the files write_header(); write_delete_record_function(); write_new_record_functon(); write_insert_record_functon(); write_edit_record_functon(); write_show_changes_functon(); write_update_database_functon(); //keep this function last since it has the code that closes out the program. write_default_function(); // increment table counter $tablecount++; } # end while ($rows = mysql_fetch_array($result)) } # end function get_tables #------------------------------------------------------------------------------------------------------------------------------- function get_datbase_info(){ //This presents the user with a form to fill out to type in the information of their database ?> <form action="phpapp.php?pgflow=build_scripts" method="POST"> <h2>Welcome to My PHP Project. This program will generate an application based on tables in your MYSQL database. </h2> <table width="600" cellspacing="5" cellpadding="5"> <tr> <td>Host Name</td> <td><input name="hostname_dataConn" type="text" id="hostname_dataConn"></td> </tr> <tr> <td>Database Name</td> <td><input name="database_dataConn" type="text" id="database_dataConn"></td> </tr> <tr> <td>User Name</td> <td><input name="username_dataConn" type="text" id="username_dataConn"></td> </tr> <tr> <td>Password</td> <td><input name="password_dataConn" type="text" id="password_dataConn"></td> </tr> <tr> <td><input type="submit" name="submit" value="submit"></td> <td><input type="reset" name="reset" value="reset"></td> </tr> </table> </form> <? } #end function get_database_info() #------------------------------------------------------------------------------------------------------------------------------- function connect($sql) { include ("workshop/dataConn.php"); //echo "commnecing connection to local db<br>"; if (!($conn=mysql_connect($hostname_dataConn, $username_dataConn, $password_dataConn))) { printf("error connecting to DB"); exit(); } # end if (!($conn=mysql_connect($hostname_dataConn, $username_dataConn, $password_dataConn))) $db2=mysql_select_db($database_dataConn,$conn); $result = mysql_query($sql); if ($result){ return $result; }else{ $error = mysql_error(); echo "Can't complete query because $error"; die(); } #end if ($result) } # end function connect($sql) #------------------------------------------------------------------------------------------------------------------------------- function create_dataConn(){ global $hostname_dataConn; global $database_dataConn; global $username_dataConn; global $password_dataConn; #print ("Host Name: $hostname_dataConn<br>"); #print ("Database Name: $database_dataConn<br>"); #print ("User Name: $username_dataConn<br>"); #print ("Password: $password_dataConn<br>"); $filename ="workshop/dataConn.php"; $what = makefile($filename); if ($what == "success"){ # print("Write to dataConn.php"); $f = @fopen($filename, 'w'); // Write the data to the file fwrite($f, "<?

"); fwrite($f, "\$hostname_dataConn = \"$hostname_dataConn\";

"); fwrite($f, "\$database_dataConn = \"$database_dataConn\";

"); fwrite($f, "\$username_dataConn = \"$username_dataConn\";

"); fwrite($f, "\$password_dataConn = \"$password_dataConn\";

"); fwrite($f, "\$dataConn = mysql_pconnect(\$hostname_dataConn, \$username_dataConn, \$password_dataConn) or trigger_error(mysql_error(),E_USER_ERROR);

"); fwrite($f, "?>"); fclose($f); } else { print("$what<br>"); print("Can not proceed any further<br>"); print("<a href='deletefiles.php'>Delete that Shit!</a>"); exit; } # end if ($what == "success") } #end function create_dataConn(){ #------------------------------------------------------------------------------------------------------------------------------- function makefile($file){ global $hostname_dataConn; global $database_dataConn; global $username_dataConn; global $password_dataConn; if (file_exists($file)) { $fileresult = $file.' already exists!'; return $fileresult; } else { $f = @fopen($file, 'w'); if (!$f) { $fileresult = 'could not create file: '.$file; return $fileresult; } else { $fileresult = 'success'; return $fileresult; } #end if (file_exists($file)) fclose($f); } # end if (!$f) }# end function makefile($file) #------------------------------------------------------------------------------------------------------------------------------- function write_header(){ global $table_names; global $current_table_name; # print(" Write the header of the file. This is the Flow control portion of the file<br>"); # echo "<br>$current_table_name <font color='red'>".$rows_feilds[0]." | ".$rows_feilds[1]." | ".$rows_feilds[2]." | ".$rows_feilds[3]." | ".$rows_feilds[4]." | ".$rows_feilds[5]."</font><br>"; $f = @fopen("workshop/".$current_table_name.".php", 'w'); // Write the data to the file fwrite($f, " <? # include (\"secure.php\"); \$pgflow = \$_GET[pgflow]; #global \$application; if ( \$application != \"yes\" ) { print(\" <html> <head> <title>IOBE - PHP - MySQL </title> <link rel='stylesheet' href='styles/style.css' type='text/css' media='all' /> <script language=\\\"javascript\\\" type=\\\"text/javascript\\\" src=\\\"js/datetimepicker.js\\\"></script> <script language=\\\"javascript\\\" type=\\\"text/javascript\\\"> <!-- function confirmLink() { return confirm(\\\"Are you sure you want to Delete this Record?\\\") } //--> </script> </head> <body> \"); } # Conditional statements to determine program flow switch (\$pgflow) { case 'addrecord': new_record(); break; case 'insertrecord': insert_record(); break; case 'deleterecord': delete_record(); break; case 'editrecord': edit_record(); break; case 'showchanges': show_changes(); break; case 'verified': update_database(); break; default: show_data(); } "); fclose($f); }#end function write_header() #------------------------------------------------------------------------------------------------------------------------------- function write_default_function(){ global $current_table_name; global $pk; global $passkeys; # print(" Write the Default function"); $f = @fopen("workshop/".$current_table_name.".php", 'a'); // Write the data to the file fwrite($f, " function show_data(){ // Title of page print \"<center><h3>$current_table_name</h3></center>\"; // this pulls in connection specific information to connect to the database include (\"dataConn.php\"); //connect to database mysql_select_db(\$database_dataConn, \$dataConn); //create sql \$sql_user_data=\"SELECT * FROM $current_table_name\"; // this statement actually executes the sql \$result = mysql_query(\$sql_user_data); //Create table print(\"<table border='1' align='center'><tr>\"); //add edit column header print(\"<th>Edit\"); //create column headers based on feilds from table "); $sql_feilds = "describe $current_table_name"; $result_feilds = connect($sql_feilds); while ($rows_feilds = mysql_fetch_array($result_feilds)) { fwrite($f, " print(\"<th>$rows_feilds[0]\");

"); if ($rows_feilds[3] == 'PRI') {$pk='$row['.$rows_feilds[0].']';} } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite($f, " // add the delete column header print(\"<th>Delete</tr>\"); //now we iterate through the results of the SQL Query while(\$row = mysql_fetch_array(\$result)) { //create a new row in the table print(\"<tr>\"); // add an edit icon for the row print(\"<td align='center'><a href='\".\$_SERVER['PHP_SELF'].\"?pg=$current_table_name&pgflow=editrecord$passkeys'><img src='images/edit_icon.png' width='16' height='16' border='0' alt='edit'></a></td>\"); "); $result_feilds = connect($sql_feilds); while ($rows_feilds = mysql_fetch_array($result_feilds)) { fwrite($f, "print(\"<td>\$row[$rows_feilds[0]] </td>\");

"); } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite($f, " // add a delete icon for the row print(\"<td align='center'><a href='\".\$_SERVER['PHP_SELF'].\"?pg=$current_table_name&pgflow=deleterecord$passkeys' ONCLICK=\\\"return confirmLink()\\\"><img src='images/delete_icon.png' width='16' height='16' border='0' alt='edit'></a></td>\"); print(\"</tr>\"); } #end while($row = mysql_fetch_array($result)) // add a final row to the end of the table that has a link to add a record print(\"<tr><td align='right'><a href='\".\$_SERVER['PHP_SELF'].\"?pg=$current_table_name&pgflow=addrecord'>New Record</a><td></tr>\"); // finally we close the table print(\"</table>\"); "); //Close out functions and end program since this is the last functions fwrite($f, " } ?>"); fclose($f); }#end function write_default_function() #------------------------------------------------------------------------------------------------------------------------------- function write_delete_record_function(){ global $current_table_name; global $pk; global $where; $sql_feilds = "describe $current_table_name"; $result_feilds = connect($sql_feilds); $insert_counter=1; # while ($rows_feilds = mysql_fetch_array($result_feilds)) # { # if ($rows_feilds[3] == 'PRI') {$pk=$rows_feilds[0];} # } # end while ($rows_feilds = mysql_fetch_array($result_feilds #print(" Write the Default function. Primary Key:$pk:"); $f = @fopen("workshop/".$current_table_name.".php", 'a'); // Write the data to the file fwrite($f, " #------------------------------------------------------------------------------------------------------------------------------- function delete_record(){ //get the variable datakey //database info include(\"dataConn.php\"); "); while ($rows_feilds = mysql_fetch_array($result_feilds)) { if ($insert_counter == 1) {$inset_keys=$inset_keys.$rows_feilds[0];$insert_values=$insert_values.$rows_feilds[0]; } else {$inset_keys=$inset_keys.', '.$rows_feilds[0]; $insert_values=$insert_values.'\', \'$'.$rows_feilds[0];} fwrite($f, " \$$rows_feilds[0] = \$_GET[$rows_feilds[0]]; //print out variables so we can see if they made it #print (\"\$$rows_feilds[0] <br>\"); "); $insert_counter++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds //Create complete sql statement # $insert_sql=$inset_keys.$insert_values.'\')";'; #print("<hr>sql: $insert_sql<hr>"); fwrite($f, " //connect to database mysql_select_db(\$database_dataConn, \$dataConn); // create sql \$sql_delete_record =\"DELETE FROM `$current_table_name` $where \"; #print (\"\$sql_delete_record\"); // delete the old record if it exists \$result = mysql_query(\$sql_delete_record); // close database mysql_close(); //show records in table show_data(); } "); fclose($f); }#end function write_delete_function() #------------------------------------------------------------------------------------------------------------------------------- function write_new_record_functon(){ global $current_table_name; global $pk; global $ispk; global $autoincr; $f = @fopen("workshop/".$current_table_name.".php", 'a'); // Write the data to the file fwrite($f, " #------------------------------------------------------------------------------------------------------------------------------- function new_record(){ //title of page and open table print (\"<br><br><center><h3> Add New Record in Table: $current_table_name</h3></center> <form action='\".\$_SERVER['PHP_SELF'].\"?pg=$current_table_name&pgflow=insertrecord' method='POST' name='log_entry'> <TABLE align='center' border='1'>\"); "); $sql_feilds = "describe $current_table_name"; $result_feilds = connect($sql_feilds); while ($rows_feilds = mysql_fetch_array($result_feilds)) { if ($rows_feilds[3] == 'PRI') {$pk='$row['.$rows_feilds[0].']'; $ispk="<img src='images/primarykey_icon.png' width='16' height='16' border='0' alt='Primary Key Feild'>";} else {$ispk='';} if ($rows_feilds[5] == 'auto_increment') {$autoincr="<img src='images/autoincrement_icon.png' width='16' height='16' border='0' alt='Auto Incrementing'>";} else {$autoincr='';} if ($rows_feilds[1] == 'datetime') {$datepicker="<a href=\\\"javascript:NewCal('".$rows_feilds[0]."','ddmmmyyyy',true,24)\\\"><img src=\\\"images/calendar_icon.png\\\" width=\\\"16\\\" height=\\\"16\\\" border=\\\"0\\\" alt=\\\"Pick a date\\\"></a>

";} elseif ($rows_feilds[1] == 'date') {$datepicker="<a href=\\\"javascript:NewCal('".$rows_feilds[0]."','ddmmmyyyy')\\\"><img src=\\\"images/calendar_icon.png\\\" width=\\\"16\\\" height=\\\"16\\\" border=\\\"0\\\" alt=\\\"Pick a date\\\"></a>

";} else {$datepicker='';} fwrite($f, "print(\"<tr><td>$rows_feilds[0]</td><td><input name='$rows_feilds[0]' type='text' id='$rows_feilds[0]'>$ispk$autoincr$datepicker</td></tr>

\"); "); } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite($f, " //add submit and reset buttons print(\" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> \"); } "); fclose($f); }#end function write_new_record_functon(); #------------------------------------------------------------------------------------------------------------------------------- function write_insert_record_functon(){ global $current_table_name; global $pk; global $ispk; global $autoincr; global $inset_keys; global $insert_values; global $insert_counter; global $insert_sql; //Initialize our variables $inset_keys='$sql_insert = "INSERT INTO '.$current_table_name.' ('; $insert_values=') VALUES (\'$'; $insert_counter=1; $sql_feilds = "describe $current_table_name"; $result_feilds = connect($sql_feilds); $f = @fopen("workshop/".$current_table_name.".php", 'a'); // Write the data to the file fwrite($f, " #------------------------------------------------------------------------------------------------------------------------------- function insert_record(){ include(\"dataConn.php\"); // Variables can be declared here "); while ($rows_feilds = mysql_fetch_array($result_feilds)) { if ($insert_counter == 1) {$inset_keys=$inset_keys.$rows_feilds[0];$insert_values=$insert_values.$rows_feilds[0]; } else {$inset_keys=$inset_keys.', '.$rows_feilds[0]; $insert_values=$insert_values.'\', \'$'.$rows_feilds[0];} fwrite($f, " \$$rows_feilds[0] = \$_POST[$rows_feilds[0]]; //print out variables so we can see if they made it #print (\"\$$rows_feilds[0] <br>\"); "); $insert_counter++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds //Create complete sql statement $insert_sql=$inset_keys.$insert_values.'\')";'; print("<hr>sql: $insert_sql<hr>"); fwrite($f, " //connect to database mysql_select_db(\$database_dataConn, \$dataConn); //create sql $insert_sql #print(\"\$sql_insert\"); // this statement actually executes the sql \$result = mysql_query(\$sql_insert); # make this vaiable match the last one // close database mysql_close(); //show records in table show_data(); } "); fclose($f); }#function write_insert_record_functon() #------------------------------------------------------------------------------------------------------------------------------- function write_edit_record_functon(){ global $current_table_name; global $pk; global $ispk; global $autoincr; global $curpk; global $where; $sql_feilds = "describe $current_table_name"; $result_feilds = connect($sql_feilds); $insert_counter=1; # print("<hr>Primary key is $curpk<hr>"); $f = @fopen("workshop/".$current_table_name.".php", 'a'); // Write the data to the file fwrite($f, " #------------------------------------------------------------------------------------------------------------------------------- function edit_record(){ // this pulls in connection specific information to connect to the database include (\"dataConn.php\"); //get vars "); while ($rows_feilds = mysql_fetch_array($result_feilds)) { if ($insert_counter == 1) {$inset_keys=$inset_keys.$rows_feilds[0];$insert_values=$insert_values.$rows_feilds[0]; } else {$inset_keys=$inset_keys.', '.$rows_feilds[0]; $insert_values=$insert_values.'\', \'$'.$rows_feilds[0];} fwrite($f, " \$$rows_feilds[0] = \$_GET[$rows_feilds[0]]; //print out variables so we can see if they made it #print (\"\$$rows_feilds[0] <br>\"); "); $insert_counter++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds fwrite($f, " //connect to database mysql_select_db(\$database_dataConn, \$dataConn); //create sql \$sql_table_data=\"SELECT * FROM $current_table_name $where\"; #print(\"\$sql_table_data\"); // this statement actually executes the sql \$result = mysql_query(\$sql_table_data); //access record info and build form while(\$row = mysql_fetch_array(\$result)) { //title of page and open table print (\"<br><br><center><h3> Edit Log entry </h3></center> <form action='\".\$_SERVER['PHP_SELF'].\"?pg=$current_table_name&pgflow=showchanges' method='POST' name='log_entry'> <TABLE border='1'>\"); "); $sql_feilds = "describe $current_table_name"; $result_feilds = connect($sql_feilds); while ($rows_feilds = mysql_fetch_array($result_feilds)) { if ($rows_feilds[3] == 'PRI') {$pk='$row['.$rows_feilds[0].']'; $ispk="<img src='images/primarykey_icon.png' width='16' height='16' border='0' alt='Primary Key Feild'>

";} else {$ispk='';} if ($rows_feilds[5] == 'auto_increment') {$autoincr="<img src='images/autoincrement_icon.png' width='16' height='16' border='0' alt='Auto Incrementing'>

";} else {$autoincr='';} if ($rows_feilds[1] == 'datetime') {$datepicker="<a href=\\\"javascript:NewCal('".$rows_feilds[0]."','ddmmmyyyy',true,24)\\\"><img src=\\\"images/calendar_icon.png\\\" width=\\\"16\\\" height=\\\"16\\\" border=\\\"0\\\" alt=\\\"Pick a date\\\"></a>

";} elseif ($rows_feilds[1] == 'date') {$datepicker="<a href=\\\"javascript:NewCal('".$rows_feilds[0]."','ddmmmyyyy')\\\"><img src=\\\"images/calendar_icon.png\\\" width=\\\"16\\\" height=\\\"16\\\" border=\\\"0\\\" alt=\\\"Pick a date\\\"></a>

";} else {$datepicker='';} fwrite($f, " print(\"<tr><td>$rows_feilds[0]</td><td><input name='$rows_feilds[0]' type='text' id='$rows_feilds[0]' value='\$row[$rows_feilds[0]]'>$ispk$autoincr$datepicker</td></tr>

\");

print(\"<input name='orig_$rows_feilds[0]' type='hidden' id='orig_$rows_feilds[0]' value='\$row[$rows_feilds[0]]'>

\");

"); } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite($f, " //add submit and reset buttons print(\" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> \"); } } "); fclose($f); }#end function write_edit_record_functon() #------------------------------------------------------------------------------------------------------------------------------- function write_show_changes_functon(){ global $current_table_name; global $pk; global $ispk; global $autoincr; global $inset_keys; global $insert_values; global $insert_counter; global $insert_sql; global $update_sql; global $curpk; global $where; global $where_orig; //Initialize our variables $sql_feilds = "describe $current_table_name"; $result_feilds = connect($sql_feilds); $f = @fopen("workshop/".$current_table_name.".php", 'a'); // Write the data to the file fwrite($f, " #------------------------------------------------------------------------------------------------------------------------------- function show_changes(){ // Variables can be declared here "); while ($rows_feilds = mysql_fetch_array($result_feilds)) { if ($insert_counter == 1) {$inset_keys=$inset_keys.$rows_feilds[0];$insert_values=$insert_values.$rows_feilds[0]; } else {$inset_keys=$inset_keys.', '.$rows_feilds[0]; $insert_values=$insert_values.'\', \'$'.$rows_feilds[0];} fwrite($f, " \$$rows_feilds[0] = \$_POST[$rows_feilds[0]]; \$orig_$rows_feilds[0] = \$_POST[orig_$rows_feilds[0]]; //print out variables so we can see if they made it #print (\"\$$rows_feilds[0] <br>\"); #print (\"\$orig_$rows_feilds[0] <br>\"); "); $insert_counter++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds fwrite($f, " // this pulls in connection specific information to connect to the database include (\"dataConn.php\"); //connect to database mysql_select_db(\$database_dataConn, \$dataConn); //create sql \$sql_user_data=\"SELECT * FROM $current_table_name $where_orig\"; #print(\"\$sql_user_data\"); // this statement actually executes the sql \$result = mysql_query(\$sql_user_data); //access record info and build form while(\$row = mysql_fetch_array(\$result)) { //title of page and open table print (\"<br><br><center><h3> Please Verify Changed below and Submit to database if correct. </h3></center> <form action='\".\$_SERVER['PHP_SELF'].\"?pg=$current_table_name&pgflow=verified' method='POST' name='log_entry'> <TABLE>\"); "); $sql_feilds = "describe $current_table_name"; $result_feilds = connect($sql_feilds); while ($rows_feilds = mysql_fetch_array($result_feilds)) { fwrite($f, " if (\$row[$rows_feilds[0]]== \$$rows_feilds[0]) {\$fontcolor = 'black';} else {\$fontcolor = 'red';} print(\"<tr><td><font color=\$fontcolor>$rows_feilds[0]</font></td><td><input name='x$rows_feilds[0]' type='text' id='x$rows_feilds[0]' value='\$$rows_feilds[0]' disabled></td></tr>\"); print(\"<input name='$rows_feilds[0]' type='hidden' id='$rows_feilds[0]' value='\$$rows_feilds[0]'>\"); print(\"<input name='orig_$rows_feilds[0]' type='hidden' id='orig_$rows_feilds[0]' value='\$orig_$rows_feilds[0]'>\"); "); } # end while ($rows_feilds = mysql_fetch_array($result_feilds)) fwrite($f, " //add submit and reset buttons print(\" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> \"); } #end while(\$row = mysql_fetch_array(\$result)) exit; } #end function show_changes(){ "); }#end function write_show_changes_functon() #------------------------------------------------------------------------------------------------------------------------------- function write_update_database_functon(){ global $current_table_name; global $pk; global $ispk; global $autoincr; global $edit_counter; global $curpk; global $where; global $where_orig; //Initialize our variables $edit_counter=1; $update_sql =""; $sql_feilds = "describe $current_table_name"; $result_feilds = connect($sql_feilds); $f = @fopen("workshop/".$current_table_name.".php", 'a'); // Write the data to the file fwrite($f, " #------------------------------------------------------------------------------------------------------------------------------- function update_database(){ include(\"dataConn.php\"); // Variables can be declared here "); while ($rows_feilds = mysql_fetch_array($result_feilds)) { if ($edit_counter == 1) {$update_sql=$update_sql."`".$rows_feilds[0]."` = '$".$rows_feilds[0]."'"; } else {$update_sql=$update_sql.",`".$rows_feilds[0]."` = '$".$rows_feilds[0]."'"; } fwrite($f, " \$$rows_feilds[0] = \$_POST[$rows_feilds[0]]; \$orig_$rows_feilds[0] = \$_POST[orig_$rows_feilds[0]]; //print out variables so we can see if they made it #print (\"\$$rows_feilds[0] <br>\"); #print (\"\$orig_$rows_feilds[0] <br>\"); "); $edit_counter++; } # end while ($rows_feilds = mysql_fetch_array($result_feilds print("<hr>$update_sql<hr>"); //Create complete sql statement fwrite($f, " //connect to database mysql_select_db(\$database_dataConn, \$dataConn); //create sql \$sql_update=\"UPDATE `".$current_table_name."` SET ".$update_sql." ".$where_orig."\"; #print(\"\$sql_update\"); // this statement actually executes the sql \$result = mysql_query(\$sql_update); # make this vaiable match the last one // close database mysql_close(); //show records in table show_data(); exit; } "); fclose($f); }#end function write_update_database_functon() #------------------------------------------------------------------------------------------------------------------------------- function create_main_php(){ global $hostname_dataConn; global $database_dataConn; global $username_dataConn; global $password_dataConn; #print ("Host Name: $hostname_dataConn<br>"); #print ("Database Name: $database_dataConn<br>"); #print ("User Name: $username_dataConn<br>"); #print ("Password: $password_dataConn<br>"); $filename ="workshop/main.php"; $what = makefile($filename); if ($what == "success"){ # print("Write to dataConn.php"); $f = @fopen($filename, 'w'); // Write the data to the file fwrite($f, "<? print(\"<br><br><br><br><br><hr><h3>If you are seeing this, your application build was probably successful</h3><hr>\"); ?>"); fclose($f); } else { print("$what<br>"); print("Can not proceed any further<br>"); print("<a href='deletefiles.php'>Delete that Shit!</a>"); exit; } # end if ($what == "success") }#end function create_main_php()() #------------------------------------------------------------------------------------------------------------------------------- function create_index_php(){ global $hostname_dataConn; global $database_dataConn; global $username_dataConn; global $password_dataConn; global $secure_string; #print ("Host Name: $hostname_dataConn<br>"); #print ("Database Name: $database_dataConn<br>"); #print ("User Name: $username_dataConn<br>"); #print ("Password: $password_dataConn<br>"); print ("<hr>SECURITY STRING:$secure_string<hr>"); print("<hr><hr><a href='workshop/index.php' target='newwin'>Click Here to Check out your new application</a><hr><hr>"); $filename ="workshop/index.php"; $what = makefile($filename); if ($what == "success"){ # print("Write to dataConn.php"); $f = @fopen($filename, 'w'); // Write the data to the file fwrite($f, " <html> <head> <title>IOBE - PHP - MySQL </title> <? \$application = \"yes\"; ?> <link rel='stylesheet' href='styles/style.css' type='text/css' media='all' /> <script language=\"javascript\" type=\"text/javascript\" src=\"js/datetimepicker.js\"> </script> <script language=\"javascript\" type=\"text/javascript\"> <!-- function confirmLink() { return confirm(\"Are you sure you want to Delete this Record?\") } //--> </script> </head> <table style='width:100%; background-color:#E4E0E0' cellspacing='3' class='topborder'><tr><td style='text-align:left; vertical-align:bottom'> </td> <td style='text-align:right'> </td> </tr></table><table style='width:100%;' cellspacing='3' id='header'><tr><td colspan='2' style='text-align:left; vertical-align: middle;'> <h2><img src='images/logo.png' alt='' /> IOBE</h2></td><td style='text-align:right'><h2>Application Builder 1.0 </h2> </td> </tr></table> <table style='width:100%' cellspacing='3'><td style='width:20%;'></td> <td style='width:60%;'><img src='images/blank.gif' width='1' height='1' alt='' /></td> <td style='width:20%;'></td></tr><tr><td style='width:20%; vertical-align: top;'> <div class='spacer'> <table cellpadding='0' cellspacing='0'> <tr> <td class='captiontopleft'><img src='images/blank.gif' width='24' height='3' alt='' style='display: block;' /></td> <td class='captiontopmiddle'><img src='images/blank.gif' width='1' height='3' alt='' style='display: block;' /></td> <td class='captiontopright'><img src='images/blank.gif' width='11' height='3' alt='' style='display: block;' /></td> </tr> </table> <table cellpadding='0' cellspacing='0'> <tr> <td class='captionleft'><img src='images/blank.gif' width='24' height='18' alt='' style='display: block;' /></td> <td class='captionbar' style='white-space:nowrap'>Table Menu</td> <td class='captionend'><img src='images/blank.gif' width='12' height='18' alt='' style='display: block;' /></td> <td class='captionmain'><img src='images/blank.gif' width='1' height='18' alt='' style='display: block;' /></td> <td class='captionright'><img src='images/blank.gif' width='11' height='18' alt='' style='display: block;' /></td> </tr> </table> <table cellpadding='0' cellspacing='0'> <tr> <td class='bodyleft'><img src='images/blank.gif' width='3' height='1' alt='' style='display: block;' /></td> <td class='bodymain'> "); $sql_tables = "show tables"; $result = connect($sql_tables); while ($rows = mysql_fetch_array($result)) { #echo "<br><b>".$rows[0]."</b><br>"; $current_table_name = $rows[0]; fwrite($f, " <span><img src='images/bullet2.gif' alt='bullet' /><a href='index.php?pg=$current_table_name'>$current_table_name </a></span><br /> "); } # end while ($rows = mysql_fetch_array($result)) fwrite($f, " </td> <td class='bodyright'><img src='images/blank.gif' width='3' height='1' alt='' style='display: block;' /></td> </tr> </table> <table cellpadding='0' cellspacing='0'> <tr> <td class='bottomleft'><img src='images/blank.gif' width='10' height='9' alt='' style='display: block;' /></td> <td class='bottommain'><img src='images/blank.gif' width='1' height='9' alt='' style='display: block;' /></td> <td class='bottomright'><img src='images/blank.gif' width='10' height='9' alt='' style='display: block;' /></td> </tr> </table> </div> <div class='spacer'></div> </td> <td style='width:20%; vertical-align:top'> <? if ($secure_string){\$pg = \"main\";} if (\$pg == \"\"){ \$pg = \"main\"; } \$page=\$pg.\".php\"; include(\$page) ; ?></td></tr><tr> <td colspan='3' style='text-align:center' class='smalltext'>This site was created with IOBE.<br /></td></tr></table> <div style='text-align:center'><table style='width:100%'><tr><td style='width:30%; vertical-align:top'> </td><td style='width:40%; vertical-align:top'></td><td style='width:30%; vertical-align:top'> </td></tr></table></div> </body></html> "); fclose($f); print("<hr><hr>file should be written<hr><hr>"); } else { print("$what<br>"); print("Can not proceed any further<br>"); print("<a href='deletefiles.php'>Delete that Shit!</a>"); exit; } # end if ($what == "success") }#end function create_index_php() #------------------------------------------------------------------------------------------------------------------------------- function blank(){ }#end function blank() ?>