Saving a DomDocument to a Folder on the Server and calling a
Posted: Mon Jun 25, 2012 10:14 pm
Hello,
I am in need of some guidance in solving a couple of issues and want to apologize beforehand for the lengthy summary. Issue one; I am trying to save a filtered mySQL select to a DOMDocument in a folder on the server and it does not seem to be saving the file. The folder attributes is set to 777 so there is not a permissions issue and I have confirmed that a file can be saved to it. Issue two; I need to call a javascript function using a Post Method (i.e., submit button) and I am unsure on how to do that.
URL to a demo page: http://demo.welllocators.com/search2.php
This is what I have to populate dataTable and create checkbox in the first column
Once the desired checkbox(s) has been selected and the "Refresh Map" button clicked
the following code is triggered to create a new DOMDocument and save it as a XML file:
and the javascript load() function should be triggered by the on submit event
Finally the javascript function populates the map with the map markers of the selected wells. Below is the load() function:
Can someone assist with solving the DOMDocument not saving problem and guide me on the proper way to call a javascript function via a onsubmit event. I am open to any ideas or suggestions. Thanks in advance for your help and guidance.
Cheers
Rene'
I am in need of some guidance in solving a couple of issues and want to apologize beforehand for the lengthy summary. Issue one; I am trying to save a filtered mySQL select to a DOMDocument in a folder on the server and it does not seem to be saving the file. The folder attributes is set to 777 so there is not a permissions issue and I have confirmed that a file can be saved to it. Issue two; I need to call a javascript function using a Post Method (i.e., submit button) and I am unsure on how to do that.
URL to a demo page: http://demo.welllocators.com/search2.php
This is what I have to populate dataTable and create checkbox in the first column
Code: Select all
<form name="formWellLocators" onsubmit="javascript:load();" method="post">
<table align="center" cellpadding="0" cellspacing="0" border="1" id="dataTable" width="100%">
<thead>
<tr>
<th><input name="checkAll" type="checkbox" value="1" onclick="javascript:checkThemAll(this);" /></th>
<th><input type="text" name="<?=$row['api']?>" value="Filter API" class="search_init" /></th>
<th><input type="text" name="<?=$row['state']?>" value="Filter State" class="search_init" /></th>
<th><input type="text" name="<?=$row['county']?>" value="Filter County" class="search_init" /></th>
<th><input type="text" name="<?=$row['operator']?>" value="Filter Operator" class="search_init" /></th>
<th><input type="text" name="<?=$row['spud_date']?>" value="Filter SPUD Date" class="search_init" /></th>
<th><input type="text" name="<?=$row['lease_well_no']?>" value="Filter Lease/Well No" class="search_init" /></th>
</tr>
<tr>
<th><img src="picts/Check_UnCheck.png" /></th> <!--Check All / Uncheck All Checkbox-->
<th>API</th>
<th>State</th>
<th>County</th>
<th>Operator</th>
<th>SPUD Date</th>
<th>Lease / Well No</th>
</tr>
</thead>
<tbody>
<!--Start Loop-->
<?php
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td align="center"><input type="checkbox" name="CheckedWell[]" value="<?=$row['id']?>"></td> <!--Individual Check Boxes for the Check All / Uncheck All Button-->
<td width="120"><?=$row['api']?></td>
<td align="center"><?=$row['state']?></td>
<td><?=$row['county']?></td>
<td><?=$row['operator']?></td>
<td align="center" width="100"><?=$row['spud_date']?></td>
<td><?=$row['lease_well_no']?></td>
</tr>
<!--End Loop-->
</form>
Code: Select all
<input type="submit" name="CheckedWells" value="Refresh Map" align="left" />
Code: Select all
<?php
if(isset($_POST['CheckedWell'])) {
foreach($_POST['CheckedWell'] as $item) {
$query = ("SELECT * FROM rig_locator WHERE id=$item");
$CheckedResult = mysql_query($query);
mysql_query($query) or trigger_error("SQL: $sql, ERROR: " . mysql_error(), E_USER_ERROR);
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$dom->formatOutput = true;
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = mysql_fetch_assoc($CheckedResult)){
// Add to XML Document Node
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("ID", $row['id']);
$newnode->setAttribute("API", $row['api']);
$newnode->setAttribute("State", $row['state']);
$newnode->setAttribute("County", $row['county']);
$newnode->setAttribute("Operator",$row['operator']);
$newnode->setAttribute("Phone",$row['phone']);
$newnode->setAttribute("LeaseWellNo", $row['lease_well_no']);
$newnode->setAttribute("FieldZone", $row['field_zone']);
$newnode->setAttribute("WellBoreType", $row['well_bore_type']);
$newnode->setAttribute("Depth", $row['depth']);
$newnode->setAttribute("RigNameNo", $row['rig_name_no']);
$newnode->setAttribute("SPUD", $row['spud_date']);
$newnode->setAttribute("CurrentActivity", $row['current_activity']);
$newnode->setAttribute("LAT", $row['lat']);
$newnode->setAttribute("LON", $row['lon']);
}
// Save DomDocument as CheckedWells.xml
$dom->Save("xml/CheckedWells.xml");
//echo $dom->saveXML() . "\n";
}
}
}
?>
Code: Select all
<form name="formWellLocators" onsubmit="javascript:load();" method="post">
Code: Select all
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(36.77046585083,-98.30557250977), 4);
GDownloadUrl("xml/CheckedWells.xml", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var state = markers[i].getAttribute("State");
var county = markers[i].getAttribute("County");
var operator = markers[i].getAttribute("Operator");
var field_zone = markers[i].getAttribute("FieldZone");
var lease_well_no = markers[i].getAttribute("LeaseWellNo");
var api = markers[i].getAttribute("API");
var well_bore_type = markers[i].getAttribute("WellBoreType");
var spud_date = markers[i].getAttribute("SPUD");
var point = new GLatLng(parseFloat(markers[i].getAttribute("LAT")),
parseFloat(markers[i].getAttribute("LON")));
var directions = "http://maps.google.com/maps?q=" + encodeURIComponent(point);
var marker = createMarker(point, state, county, operator, field_zone, lease_well_no, api, well_bore_type, spud_date, directions);
map.addOverlay(marker);
}
});
}
}
Cheers
Rene'