Oliver,
I want make a query and pass query results to different php files which depend 
on a previous user choice.
I think your suggestions will be very useful, i'm trying to implement a part of 
them.

thank you again

Valerio


/*
Valerio Noti
[EMAIL PROTECTED]
*/


----- Original Message ----- From: "Oliver Christen" <[EMAIL PROTECTED]>
To: "Valerio Noti" <[EMAIL PROTECTED]>; <[email protected]>
Sent: Monday, February 05, 2007 10:55 AM
Subject: Re: [Cartoweb-users] query tools with different icons


Im no sure I understand exactly what you want to do.

You want, after a query, that it doesnt make any query, but instead open some php file of your own?

Thats certainly possible.
You need to handle a new parameter received from the formular (radio, checkbox or select input element, which will be used to select what action you want) in the query plugin.

You will still need to extend the query plugin, but the modification are certainly less complicated than before, as you dont have to handle any new tool.

Dont worry, this may sound complicated, but it is in fact fairly easy.
I will attache some kind of exemple of extended query plugin so you can understand better the explanation below.

First, in handleStandardParameters, recover the new parameter value with $this->querySpecial = $this->getHttpValue($request, 'my_new_parameter_name');
(dont forget to declare $querySpecial at the beginning of the class)

since you wont use the normal query result, there is no point of triggering the server part of the query plugin, so you can bypass the whole buildRequest() content if your triggered your special query:

   public function buildRequest() {
     if (!$this->querySpecial) { // <- new!
// in other words, if you didnt pass any special parameter, you need to process the query normally
       if (!is_null($this->shape) || (!is_null($this->queryState)
           ...
     }
   }
This way you wont have a query done and not used.

Then, in the initializeResult function, you need to change:

if (empty($queryResult))
           return;

nothing will happens if you triggered the query with your special parameter. Then we will trick the query to react even if nothing was returned from the server side.

if (empty($queryResult) && !$this->querySpecial)
  return;

if (!$this->querySpecial) {
// here process the rest of the original function content
}

then, the last part, modify the drawQuery:

simply add somthing like:

if ($this->querySpecial) {
$smarty->assign('specialQueryWhatever', true); // this is to activate a template part
}

and finally, in the query.tpl (NOT the table.tpl ! as we dont have any normal result to handle) add the part of the code that will open a new window, pointing on your external php file.
{if $specialQueryWhatever}
  <script ....
      ....
  </script>
{/if}

You could avoid the popup part, if you call your php file direcly from within the extended query part.
For exemple, from the drawQuery,

if ($this->querySpecial) {
$smarty->assign('specialQueryWhatever', true); // this is to activate a template part
   $smarty->assign('specialQueryResult', $this->getSpecialQueryResult());
}

and a new function

private function getSpecialQueryResult() {
 require_once(path/to/your/special/query/phpfile.php');
 $specialQuery = new specialQuery(); // defined in your external php file
$result = $specialQuery->callSomeFunctionInSpecialQuery($this->querySpecial) // call a function, passing the spacial query parameter
 return $result;
}

this way, the result would be displayed in Cartoweb template, below the map, as usual and this would be transparent to the user.

Oh, dont forget to activate this new plugin in your client.ini

regards
Oliver

Oliver,
thank you for your reply.
I think this solution is too much complicated for me.
I can modify tables.tpl in order to open a certain php file instead of display query results in the same map window. My goal is to open a different php file (or the same with different parameters) from tables.tpl depending on a previous choice. I thought about a gif map and an hidden input form to retry in tables.tpl but I haven't tried yet and maybe it's not possible.
What do you think about this? and is tables.tpl the right file to modify?
thanks

Valerio


----- Original Message ----- From: "Oliver Christen" <[EMAIL PROTECTED]> To: "Valerio Noti" <[EMAIL PROTECTED]>; <[email protected]>
Sent: Friday, February 02, 2007 3:33 PM
Subject: Re: [Cartoweb-users] query tools with different icons


Hi valerio
this is certainly possible but also delicate.

you will need to touch php client side and server side and also some javascript.

concerning the tool itself:

for the php, you will probably need to extend the query plugin and add new tools definition to the getTools() function.

to help you a bit, new ToolDescription(self::TOOL_QUERY_BY_BBOX, true, 41) this will define a new tool, whose name will be defined by self::TOOL_QUERY_BY_BBOX (you can use a string like 'mynewquerytool' , the notation used here allow us to change the name without changing the code, but you dont need to use it). The name is important as it is the identifiant for that tool which will be used in the web interface and also in the javascript. The second parameter say if the tool has an icon or not. This is usually true. third is the weight, in other words, the place of the tool in the toolbar. There are other parameters (see client/ClientPlugin.php) but you probably dont need them.

Now the javascript part. All tools action are handled by the dhtmlAPI.js, dhtmlFeatures.js and dhtmlInit.js.
This is probably the less userfriendly part of cartoweb.

What you need to do is, in a new javascript file, copy the existing properties and methodes of the existing query tool that meet the beahaviour you need (for exemple query_by_bbox).

Since the behaviour is the same, you wont have to duplicate this, fortunately.
You will have something like :
Map.prototype.mynewquerytool = function(aDisplay) {
 this.selectionBox(aDisplay, 'Query.Perform');
 this.getDisplay(aDisplay).docObj.style.cursor = "help";
};

then include that javascript in your main template header, like the other javascript files.

Thats only for "duplicating" a query tool.

Now, for the database switch.... I will do some wild guess as I never had such problem before.

If the database connection is set in the layers connection parameter, it means : either you have two layers and activate one or the other depending of the query tool selected, or you need to change the connection on-the-fly depending of the query tool selected.

I must say i dont really see how to change the layer on which the query is done. Maybe with a filterPostRequest but I think the query plugin use the list of activated layers before the query, obtained from the layer plugin. And I wouldnt mess with that personally. Maybe someone else has a better idea...

To change a layer parameter on-the-fly, you can do that on the server side, in the function handlepreDrawing with some use of mapOverlay plugin. This is done on the server side part of the query plugin, so you will need to extend this too. For that, first, enable the mapOverlay plugin in the server side yourproject.ini file (where the other plugins for server side are listed for activation)

below is an exemple on how to change some layer properties:

public function handlePreDrawing($request) {
       if (isset($this->selectid) && !empty($this->selectid)) {
        $layer = new LayerOverlay();
        $layer->name = "vue_recenter";
$layer->data = "position FROM (SELECT * FROM vue_recenter WHERE filtre_id = ".$this->selectid.") as foo USING UNIQUE bien_id USING SRID=-1";

$mapOverlay = $this->serverContext->getPluginManager()->mapOverlay;
        if ($mapOverlay == NULL) {
throw new CartoserverException('Plugin MapOverlay must be activated!');
        }
        // update layer
        $mapOverlay->updateMap($layer);

       }
}

in this case we changed the DATA value from the layer vue_recenter, but you can probably do the same with the CONNECTION value. the important part is you need to pass some parameter from client side to server side to activate the change (in the "if" condition). So you need to modify a bit the buildRequest() function (client side) to pass that parameter (for exemple the name of the tool used) on the server side. on the server side, the paramter will be in $request, which directly is available in handlePreDrawing.

This is certainly not easy but it is possible ;)

Good luck
Oliver

----- Original Message ----- From: "Valerio Noti" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, February 02, 2007 10:37 AM
Subject: [Cartoweb-users] query tools with different icons


Hello,
I'd like to duplicate a query tool in cartoweb interface in order to have two buttons (different icons) with query functionality but with separate tasks. These separate tasks are not cartoweb-dependant (i.e. a different database to connect). So perhaps my problem it how to assign two different icons to the same tool.

Any help appreciated

thanks in advance

Valerio

/*
Valerio Noti
[EMAIL PROTECTED]
*/
_______________________________________________
Cartoweb-users mailing list
[email protected]
http://lists.maptools.org/mailman/listinfo/cartoweb-users




--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.19/663 - Release Date: 01/02/07 14.28







--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.27/671 - Release Date: 05/02/07 16.48

_______________________________________________
Cartoweb-users mailing list
[email protected]
http://lists.maptools.org/mailman/listinfo/cartoweb-users

Reply via email to