Changeset 693 for trunk/phpbms/modules/base/report/tabledefs_sqlexport.php
- Timestamp:
- 12/31/09 13:36:45 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/modules/base/report/tabledefs_sqlexport.php
r612 r693 38 38 */ 39 39 40 if(!isset($_SESSION["userinfo"])){ 40 if(!class_exists("phpbmsReport")) 41 include("../../../report/report_class.php"); 41 42 42 session_cache_limiter('private'); 43 class tabledefSQLExport extends phpbmsReport{ 43 44 44 require("../../../include/session.php"); 45 function tabledefSQLExport($db, $reportUUID, $tabledefUUID){ 45 46 46 }//end if 47 parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 48 49 }//end method 47 50 48 51 49 if(!class_exists("phpbmsReport")) 50 include("report/report_class.php"); 52 function generate(){ 51 53 52 class tabledefSQLExport extends phpbmsReport{ 54 $this->reportOutput .= $this->_addTableInfo("tablecolumns"); 55 $this->reportOutput .= $this->_addTableInfo("tablefindoptions"); 56 $this->reportOutput .= $this->_addTableInfo("tablegroupings"); 57 $this->reportOutput .= $this->_addTableInfo("tableoptions"); 58 $this->reportOutput .= $this->_addTableInfo("tablesearchablefields"); 53 59 54 var $reportOutput = ""; 55 56 function sqlExport($db){ 57 58 parent::phpbmsReport($db); 59 60 }//end method 60 }//end method 61 61 62 62 63 function generate(){63 function _addTableInfo($tablename){ 64 64 65 $this->reportOutput .= $this->_addTableInfo("tablecolumns"); 66 $this->reportOutput .= $this->_addTableInfo("tablefindoptions"); 67 $this->reportOutput .= $this->_addTableInfo("tablegroupings"); 68 $this->reportOutput .= $this->_addTableInfo("tableoptions"); 69 $this->reportOutput .= $this->_addTableInfo("tablesearchablefields"); 65 $querystatement = " 66 SELECT 67 `uuid` 68 FROM 69 `tabledefs` 70 WHERE 71 ".$this->whereClause; 70 72 71 }//end method 73 $queryresult = $this->db->query($querystatement); 74 75 $whereclause = ""; 76 77 while($therecord = $this->db->fetchArray($queryresult)) 78 $whereclause .= " OR `tabledefid` = '".mysql_real_escape_string($therecord["uuid"])."'"; 79 80 $whereclause = substr($whereclause, 4); 81 82 $output = "/* Begin ".$tablename." */\n". 83 "/* ====================================================================== */\n"; 84 85 $querystatement = " 86 SELECT 87 * 88 FROM 89 `".$tablename."` 90 WHERE 91 ".$whereclause." 92 ORDER BY 93 ".$tablename.".tabledefid"; 94 95 $queryresult = $this->db->query($querystatement); 96 97 $num_fields = $this->db->numFields($queryresult); 98 99 $statementstart = "INSERT INTO `".$tablename."` ("; 100 101 for($i=0; $i<$num_fields ;$i++){ 102 103 $fieldname = $this->db->fieldName($queryresult,$i); 104 105 if($fieldname != "id") 106 $statementstart .= "`".$fieldname."`, "; 107 108 }//endfor 109 110 $statementstart = substr($statementstart,0,strlen($statementstart)-2).") VALUES ("; 111 112 while($therecord = $this->db->fetchArray($queryresult)){ 113 114 $insertstatement = $statementstart; 115 116 foreach($therecord as $name => $field){ 117 118 if($field === NULL) 119 $addfield = "NULL, "; 120 else 121 $addfield = "'".mysql_real_escape_string($field)."', "; 122 123 if($name != "id") 124 $insertstatement .= $addfield; 125 126 }//endforeach 127 128 $insertstatement = substr($insertstatement,0,strlen($insertstatement)-2).");\n"; 129 130 $output .= $insertstatement; 131 132 }//endwhile 72 133 73 134 74 function _addTableInfo($tablename){ 135 $output .= "/* ====================================================================== */\n". 136 "/* END ".$tablename." - record count: ".$this->db->numRows($queryresult)."*/\n\n"; 75 137 76 $querystatement = " 77 SELECT 78 `uuid` 79 FROM 80 `tabledefs` 81 WHERE 82 ".$this->whereclause." 83 "; 138 return $output; 84 139 85 $queryresult = $this->db->query($querystatement); 86 87 $whereclause = ""; 88 while($therecord = $this->db->fetchArray($queryresult)){ 89 90 $whereclause .= " OR `tabledefid` = '".mysql_real_escape_string($therecord["uuid"])."'"; 91 92 }//end while 93 94 $whereclause = substr($whereclause, 4); 95 96 $output = "/* Begin ".$tablename." */\n". 97 "/* ====================================================================== */\n"; 98 99 $querystatement = " 100 SELECT 101 * 102 FROM 103 `".$tablename."` 104 WHERE 105 ".$whereclause." 106 ORDER BY 107 ".$tablename.".tabledefid"; 108 109 $queryresult = $this->db->query($querystatement); 110 111 $num_fields = $this->db->numFields($queryresult); 112 113 $statementstart = "INSERT INTO `".$tablename."` ("; 114 115 for($i=0; $i<$num_fields ;$i++){ 116 117 $fieldname = $this->db->fieldName($queryresult,$i); 118 119 if($fieldname != "id") 120 $statementstart .= "`".$fieldname."`, "; 121 122 }//endfor 123 124 $statementstart = substr($statementstart,0,strlen($statementstart)-2).") VALUES ("; 125 126 while($therecord = $this->db->fetchArray($queryresult)){ 127 128 $insertstatement = $statementstart; 129 130 foreach($therecord as $name => $field){ 131 132 if($field === NULL) 133 $addfield = "NULL, "; 134 else 135 $addfield = "'".mysql_real_escape_string($field)."', "; 136 137 if($name != "id") 138 $insertstatement .= $addfield; 139 140 }//endforeach 141 142 $insertstatement = substr($insertstatement,0,strlen($insertstatement)-2).");\n"; 143 144 $output .= $insertstatement; 145 146 }//endwhile 140 }//end method 147 141 148 142 149 $output .= "/* ====================================================================== */\n". 150 "/* END ".$tablename." - record count: ".$this->db->numRows($queryresult)."*/\n\n"; 143 function show(){ 151 144 152 return $output; 145 header("Content-type: text/plain"); 146 header('Content-Disposition: attachment; filename="tableInfoSQL.sql"'); 153 147 154 }//end method 148 echo $this->reportOutput; 149 150 }//end method 155 151 156 152 157 function show(){ 153 }//end class 158 154 159 header("Content-type: text/plain"); 160 header('Content-Disposition: attachment; filename="tableInfoSQL.sql"'); 155 /** 156 * PROCESSING 157 * ============================================================================= 158 */ 159 if(!isset($noOutput)){ 161 160 162 echo $this->reportOutput;161 session_cache_limiter('private'); 163 162 164 }//end method 163 require_once("../../../include/session.php"); 165 164 165 checkForReportArguments(); 166 166 167 }//end class 167 $report = new tabledefSQLExport($db, $_GET["rid"],$_GET["tid"]); 168 $report->setupFromPrintScreen(); 169 $report->generate(); 170 $report->show(); 168 171 169 //PROCESSING 170 //======================================================================== 172 }//end if 171 173 172 if(!isset($noOutput)){ 173 174 $report = new tabledefSQLExport($db); 175 $report->setupFromPrintScreen(); 176 $report->generate(); 177 $report->show(); 178 179 }//end if 174 /** 175 * When adding a new report record, the add/edit needs to know what the class 176 * name is so that it can instantiate it, and grab it's default settings. 177 */ 178 if(isset($addingReportRecord)) 179 $reportClass ="tabledefSQLExport"; 180 180 ?>