home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / daogen / sqlGenerateCode.php < prev   
PHP Script  |  2004-03-08  |  3KB  |  111 lines

  1. <?php
  2. /*
  3. Copyright T & M Web Enterprises 2003
  4. Author: Mike Hostetler <mike@tm-web.com>
  5. Version: 1.0 Release date: 01 November 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. /**
  14.  *
  15.  *@NAME:        generateCode
  16.  *@PURPOSE:        To call each of the actions and display the output
  17.  *@REMARKS:        This serves as the default action for the entire module
  18.  *
  19.  */
  20. $post = $_POST;
  21.  
  22. //Classname and tablename should come through $_POST
  23. $db = new db();
  24. $result = $db->metadata($post['tablename'],true);
  25. //debug($result);
  26. //exit;
  27. for($i=0;$i<$result['num_fields'];$i++) {
  28.     $post['colname'][$i] = $result[$i]['name'];
  29.     $post['varname'][$i] = $result[$i]['name'];
  30.     $post['type_colname'][$i] = $result[$i]['type'];
  31. }
  32. $post['col_num'] = $result['num_fields'];
  33. $db->query("SHOW KEYS FROM ".$post['tablename']);
  34. $post['pk_num'] = $db->nf();
  35. $post['ordering'] = 0;
  36.  
  37. import('action','generateVo');
  38. import('action','generateDao');
  39.  
  40. //Remove empty column names
  41. foreach($post['colname'] as $k => $v) {
  42.     if($v == "") {
  43.         //We have an empty entry, remove it
  44.         unset($post['colname'][$k]);
  45.         unset($post['type_db_colname'][$k]);
  46.         unset($post['varname'][$k]);
  47.         $post['col_num']--;
  48.     }
  49. }
  50. foreach( $post['varname'] as $k => $v )
  51. {
  52.     if( $v == "" )
  53.     {
  54.         $post['varname'][$k] = $post['colname'][$k];
  55.     }
  56.  
  57. }
  58. echo "<br>";
  59. $tabtable = new tabtable('gen_type', 'DAO Generator', '600', '400');
  60. $tabtable->add_tab('new', 'New DAO');
  61. $tabtable->add_tab('sql', 'SQL Based');
  62. $tabtable->add_tab('base', 'Base Classes');
  63. $tabtable->print_head();
  64. ?>
  65. <div align="center"><a href="index.php">[Start Over]</a></div>
  66. <table border="0" cellpadding="5" cellspacing="0">
  67. <tr>
  68.     <td><h1>Value Object Code</h1>
  69.     <br>Copy this code into a file named the same as the classname
  70.     <br>(Data Access object is below)
  71.     </td>
  72. </tr>
  73. <tr>
  74.     <td>
  75.     <?php
  76. print "<pre>";
  77. print "<textarea name=\"valueObj\" cols=\"80\" rows=\"15\">";
  78. print htmlspecialchars("<?php\n");
  79. $vo = generateVo($post['classname'],$post['varname']);
  80. print ($vo);
  81. print htmlspecialchars("\n?>");
  82. echo '</textarea>';
  83. print "</pre>";
  84. ?>
  85.     </td>
  86. </tr>
  87. <tr>
  88.     <td><h1>Data Access Object Code</h1>
  89.     <br>Copy this code into a file named the same as the classname
  90.     </td>
  91. </tr>
  92. <tr>
  93.     <td>
  94. <?php
  95. print "<pre>";
  96. print "<textarea name=\"valueObj\" cols=\"80\" rows=\"15\">";
  97. print htmlspecialchars("<?php\n");
  98. $dao = generateDao($post['classname'],$post['tablename'],$post['pk_num'],$post['col_num'],$post['colname'],$post['varname'],$post['type_colname'],$post['ordering']);
  99. print ($dao);
  100. print htmlspecialchars("\n?>");
  101. echo '</textarea>';
  102. print "</pre>";
  103. ?>
  104.     </td>
  105. </tr>
  106. </table>
  107. <?php
  108. $tabtable->print_foot();
  109. ?>
  110. <br>
  111.