Changeset 693 for trunk/phpbms/report/general_sql.php
- Timestamp:
- 12/31/09 13:36:45 (2 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/report/general_sql.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/report/general_sql.php
r578 r693 37 37 +-------------------------------------------------------------------------+ 38 38 */ 39 if(!class_exists("phpbmsReport")) 40 include("report_class.php"); 39 41 40 if(!class_exists("phpbmsReport")) 41 include("report_class.php"); 42 /** 43 * Handles creation of SQL insert records 44 * 45 * This class handles the file creation of SQL Insert records that 46 * correspond to the table definition main table that intializes a print of this 47 * report 48 */ 49 class sqlExport extends phpbmsReport{ 42 50 43 class sqlExport extends phpbmsReport{ 51 /** 52 * $maintable 53 * @var string the SQL name of the main table to print. 54 */ 55 var $maintable = ""; 44 56 45 var $maintable = ""; 46 var $reportOutput = ""; 47 var $tabledefuuid; 57 /** 58 * function generalTablePrint 59 * 60 * Initialization function 61 * 62 * @param object $db database object 63 * @param string $reportUUID UUID of report record 64 * @param string $tabledefUUID UUID of table definition intializing print 65 */ 66 function sqlExport($db, $reportUUID, $tabledefUUID){ 48 67 49 function sqlExport($db, $tabledefuuid){ 68 parent::phpbmsReport($db, $reportUUID, $tabledefUUID); 50 69 51 $this->tabledefuuid = mysql_real_escape_string($tabledefuuid);70 $therecord = $this->getTableDefInfo(); 52 71 53 parent::phpbmsReport($db);72 $this->maintable = $therecord["maintable"]; 54 73 55 $querystatement = " 56 SELECT 57 maintable 58 FROM 59 tabledefs 60 WHERE 61 uuid = '".$this->tabledefuuid."'"; 62 63 $queryresult = $db->query($querystatement); 64 $therecord=$db->fetchArray($queryresult); 65 66 $this->maintable = $therecord["maintable"]; 67 68 }//end method 74 }//end function init 69 75 70 76 71 function generate(){ 77 /** 78 * function generate 79 * 80 * Generates the SQL Insert statements for each record 81 */ 82 function generate(){ 72 83 73 $querystatement = "74 SELECT75 *76 FROM77 ".$this->maintable;84 $querystatement = " 85 SELECT 86 * 87 FROM 88 ".$this->maintable; 78 89 79 $querystatement = $this->assembleSQL($querystatement);90 $querystatement = $this->assembleSQL($querystatement); 80 91 81 $queryresult = $this->db->query($querystatement);92 $queryresult = $this->db->query($querystatement); 82 93 83 $num_fields = $this->db->numFields($queryresult);94 $num_fields = $this->db->numFields($queryresult); 84 95 85 $statementstart = "INSERT INTO `".$this->maintable."` (";96 $statementstart = "INSERT INTO `".$this->maintable."` ("; 86 97 87 for($i=0; $i<$num_fields ;$i++)88 $statementstart .= "`".$this->db->fieldName($queryresult,$i)."`, ";98 for($i=0; $i<$num_fields ;$i++) 99 $statementstart .= "`".$this->db->fieldName($queryresult,$i)."`, "; 89 100 90 $statementstart = substr($statementstart,0,strlen($statementstart)-2).") VALUES (";101 $statementstart = substr($statementstart,0,strlen($statementstart)-2).") VALUES ("; 91 102 92 while($therecord = $this->db->fetchArray($queryresult)){103 while($therecord = $this->db->fetchArray($queryresult)){ 93 104 94 $insertstatement = $statementstart;105 $insertstatement = $statementstart; 95 106 96 foreach($therecord as $name => $field){107 foreach($therecord as $name => $field){ 97 108 98 if($field === NULL)99 $addfield = "NULL, ";100 else101 $addfield = "'".mysql_real_escape_string($field)."', ";109 if($field === NULL) 110 $addfield = "NULL, "; 111 else 112 $addfield = "'".mysql_real_escape_string($field)."', "; 102 113 103 //this is in temp for intallation exporting104 if(hasRights("Admin")){114 //this is in temp for intallation exporting 115 if(hasRights("Admin")){ 105 116 106 switch($name){117 switch($name){ 107 118 108 case "createdby":109 case "modifiedby":110 $addfield = "1, ";111 break;119 case "createdby": 120 case "modifiedby": 121 $addfield = "1, "; 122 break; 112 123 113 case "creationdate":114 case "modifieddate":115 $addfield = "NOW(), ";116 break;124 case "creationdate": 125 case "modifieddate": 126 $addfield = "NOW(), "; 127 break; 117 128 118 }//end switch129 }//end switch 119 130 120 }//endif131 }//endif 121 132 122 $insertstatement .= $addfield;133 $insertstatement .= $addfield; 123 134 124 }//endforeach135 }//endforeach 125 136 126 $insertstatement = substr($insertstatement,0,strlen($insertstatement)-2).");\n";137 $insertstatement = substr($insertstatement,0,strlen($insertstatement)-2).");\n"; 127 138 128 $this->reportOutput .= $insertstatement;139 $this->reportOutput .= $insertstatement; 129 140 130 }//endwhile141 }//endwhile 131 142 132 }//end method 143 }//end function generate 144 145 /** 146 * function show 147 * 148 * outputs the report to a .sql file 149 */ 150 function show(){ 151 152 if(!isset($this->settings["filename"])) 153 $this->settings["filename"] = $this->maintable."-export.sql"; 154 155 header("Content-type: text/plain"); 156 header('Content-Disposition: attachment; filename="'.$this->settings["filename"].'"'); 157 158 echo $this->reportOutput; 159 160 }//end function show 161 162 }//end class sqlExport 133 163 134 164 135 function show(){ 165 /** 166 * PROCESSING 167 * ============================================================================= 168 */ 169 if(!isset($noOutput)){ 136 170 137 header("Content-type: text/plain"); 138 header('Content-Disposition: attachment; filename="export.sql"'); 171 session_cache_limiter('private'); 139 172 140 echo $this->reportOutput;173 require_once("../include/session.php"); 141 174 142 }//end method 175 checkForReportArguments(); 143 176 177 $report = new sqlExport($db, $_GET["rid"],$_GET["tid"]); 178 $report->setupFromPrintScreen(); 179 $report->generate(); 180 $report->show(); 144 181 145 }//end class 182 }//end if 146 183 147 //PROCESSING 148 //======================================================================== 184 /** 185 * When adding a new report record, the add/edit needs to know what the class 186 * name is so that it can instantiate it, and grab it's default settings. 187 */ 188 if(isset($addingReportRecord)) 189 $reportClass ="pdfLabels"; 149 190 150 if(!isset($noOutput)){151 152 session_cache_limiter('private');153 154 require("../include/session.php");155 if(!isset($_GET["tid"]))156 $error = new appError(200,"URL variable missing: tid");157 158 $report = new sqlExport($db, $_GET["tid"]);159 $report->setupFromPrintScreen();160 $report->generate();161 $report->show();162 163 }//end if164 191 ?>