Skip to content

Commit

Permalink
For cities without a master address system, we now allow users to ent…
Browse files Browse the repository at this point in the history
…er locations as plain text

Fixes #57
  • Loading branch information
inghamn committed Feb 13, 2013
1 parent c0bc4b1 commit bfef69c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
12 changes: 9 additions & 3 deletions crm/blocks/html/locations/findLocationForm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
<div class="findLocationForm">
<h1><?php echo $this->title ? View::escape($this->title) : 'Find a Location'; ?></h1>
<?php
include APPLICATION_HOME.'/blocks/html/locations/findAddressForm.inc';
include APPLICATION_HOME.'/blocks/html/locations/findStreetForm.inc';
if (defined('ADDRESS_SERVICE')) {
include APPLICATION_HOME.'/blocks/html/locations/findAddressForm.inc';
include APPLICATION_HOME.'/blocks/html/locations/findStreetForm.inc';
}

// Don't allow searching for descriptive locations if they're in
// the process of adding a ticket
// We don't want them to be able to add new stuff with locations
// that are just random text
if (!isset($_REQUEST['return_url'])) {
//
// (2013-02-13) However, if they do not have a master address system
// this is the only way for employees to enter locations, so we need
// to make sure it's there if they need it.
if (!defined('ADDRESS_SERVICE') || isset($_REQUEST['return_url'])) {
include APPLICATION_HOME.'/blocks/html/locations/findDescriptiveLocationForm.inc';
}
if (isset($_REQUEST['callback'])) {
Expand Down
31 changes: 29 additions & 2 deletions crm/blocks/html/locations/findLocationResults.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* @author Cliff Ingham <[email protected]>
* @param Array $this->results
*/
$callback = isset($_REQUEST['callback'])
? preg_replace('/[^a-zA-Z_\.]/', '', $_REQUEST['callback'])
: '';

if (count($this->results)) {
echo "
<table>
Expand All @@ -22,8 +26,7 @@ if (count($this->results)) {
: new URL(BASE_URL.'/locations/view');

foreach ($this->results as $location=>$data) {
if (isset($_REQUEST['callback'])) {
$callback = preg_replace('/[^a-zA-Z_\.]/', '', $_REQUEST['callback']);
if ($callback) {
$url = "javascript:self.opener.$callback('$location');";
}
else {
Expand Down Expand Up @@ -55,6 +58,30 @@ if (count($this->results)) {
}
else {
echo '<p>No locations found. Please try your search again or contact an administrator if you believe a location is missing from our database.</p>';

// If they don't have a master address service they still need a way to add
// new locations. However, once they have a master address system, users
// should not be able to add new addresses. Instead, they should only
// choose addresses returned from the search results
if (!defined('ADDRESS_SERVICE')
&& (isset($_REQUEST['return_url']) || $callback)) {
$return_url = isset($_REQUEST['return_url']) ? $_REQUEST['return_url'] : '';
$onsubmit = $callback
? "self.opener.$callback(document.getElementById('location').value); return false;"
: '';
echo "
<form method=\"get\" action=\"$return_url\" onsubmit=\"$onsubmit\">
<fieldset><legend>Add a location</legend>
<table>
<tr><th><label for=\"location\">Location</th>
<td><input id=\"location\" name=\"location\" /></td>
</tr>
</table>
<button type=\"submit\" class=\"submit\">Submit</button>
</fieldset>
</form>
";
}
}
?>
</div>

0 comments on commit bfef69c

Please sign in to comment.