Skip to content

Commit

Permalink
Add Map module
Browse files Browse the repository at this point in the history
  • Loading branch information
Herve Prot committed Jul 12, 2011
1 parent a9e7f89 commit 1f34e0e
Show file tree
Hide file tree
Showing 6 changed files with 514 additions and 0 deletions.
145 changes: 145 additions & 0 deletions htdocs/includes/modules/modMap.class.php
@@ -0,0 +1,145 @@
<?php
/* Copyright (C) 20011 Herve Prot <herve.prot@symeos.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

/**
* \defgroup member Module Map
* \brief Module to create map
*/

/**
* \file htdocs/includes/modules/modMap.class.php
* \ingroup member
* \brief File descriptor or module Map
* \version $Id: modMap.class.php,v 1.76 2010/10/01 23:37:37 eldy Exp $
*/

include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php");

/**
* \class modAdherent
* \brief Classe de description et activation du module Adherent
*/
class modMap extends DolibarrModules
{

/**
* \brief Constructeur. Definit les noms, constantes et boites
* \param DB Database handler
*/
function modMap($DB)
{
$this->db = $DB;
$this->numero = 450 ;

$this->family = "technic";
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
$this->name = preg_replace('/^mod/i','',get_class($this));
$this->description = "Carthographie";
$this->version = 'development'; // 'experimental' or 'dolibarr' or version
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
$this->special = 0;
$this->picto='globe';

// Data directories to create when module is enabled
$this->dirs = array("/map/temp");

// Config pages
//-------------
$this->config_page_url = array("map.php@map");

// Dependances
//------------
$this->depends = array();
$this->requiredby = array();
$this->langfiles = array("map","companies");

// Constantes
//-----------
$this->const = array();


// Boites
//-------
$this->boxes = array();


// Menu
//------------
// None

// Permissions
//------------
$this->rights = array();
$this->rights_class = 'map';
$r=0;

// $this->rights[$r][0] Id permission (unique tous modules confondus)
// $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
// $this->rights[$r][2] Non utilise
// $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
// $this->rights[$r][4] Niveau 1 pour nommer permission dans code
// $this->rights[$r][5] Niveau 2 pour nommer permission dans code

$this->rights[$r][0] = 451;
$this->rights[$r][1] = 'See map';
$this->rights[$r][2] = 'r';
$this->rights[$r][3] = 1;
$this->rights[$r][4] = 'read';

}


/**
* \brief Fonction appelee lors de l'activation du module. Insere en base les constantes, boites, permissions du module.
* Definit egalement les repertoires de donnees a creer pour ce module.
*/
function init()
{

$sql = array();

$result=$this->load_tables();
return $this->_init($sql);
}

/**
* \brief Fonction appelee lors de la desactivation d'un module.
* Supprime de la base les constantes, boites et permissions du module.
*/
function remove()
{
$sql = array();

return $this->_remove($sql);
}

/**
* \brief Create tables and keys required by module
* Files mymodule.sql and mymodule.key.sql with create table and create keys
* commands must be stored in directory /mymodule/sql/
* This function is called by this->init.
* \return int <=0 if KO, >0 if OK
*/
function load_tables()
{
return $this->_load_tables('/map/sql/');
}

}
?>
139 changes: 139 additions & 0 deletions htdocs/map/admin/map.php
@@ -0,0 +1,139 @@
<?php
/* Copyright (C) 2010-2011 Herve Prot <herve.prot@symeos.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

/**
* \file htdocs/map/admin/map.php
* \ingroup technic
* \brief Page to setup the module Foundation
* \version $Id: map.php,v 1.10.2.1 2011/05/30 13:43:59 herve Exp $
*/

require("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");

$langs->load("admin");
$langs->load("map");

if (!$user->admin)
accessforbidden();


$typeconst=array('yesno','texte','chaine');


// Action mise a jour ou ajout d'une constante
if ($_POST["action"] == 'update' || $_POST["action"] == 'add')
{
$const=$_POST["constname"];
$value=$_POST["constvalue"];
$type=$_POST["consttype"];
$constnote=isset($_POST["constnote"])?$_POST["constnote"]:'';
$result=dolibarr_set_const($db,$const,$value,$typeconst[$type],0,$constnote,$conf->entity);
if ($result < 0)
{
print $db->error();
}
}

// Action activation d'un sous module du module adherent
if ($_GET["action"] == 'set')
{
$result=dolibarr_set_const($db, $_GET["name"],$_GET["value"],'',0,'',$conf->entity);
if ($result < 0)
{
print $db->error();
}
}

// Action desactivation d'un sous module du module adherent
if ($_GET["action"] == 'unset')
{
$result=dolibarr_del_const($db,$_GET["name"],$conf->entity);
if ($result < 0)
{
print $db->error();
}
}



/*
* View
*/

llxHeader();


$var=True;

$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("MapSetup"),$linkback,'setup');
print "<br>";


print_fiche_titre($langs->trans("MapMainOptions"),'','');
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Description").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '<td align="center">'.$langs->trans("Action").'</td>';
print "</tr>\n";
$var=true;
$form = new Form($db);

$graphtheme=array(
'openlayers',
'google',
'microsoft'
);

$var=!$var;
print '<form action="map.php" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="rowid" value="'.$rowid.'">';
print '<input type="hidden" name="constname" value="MAP_SYSTEM">';
print "<tr $bc[$var] class=value><td>".$langs->trans("MapSolution").'</td><td>';
print $form->selectarray('constvalue',$graphtheme,$conf->global->MAP_SYSTEM,0,0,1);
print '</td><td align="center" width="80">';
print '<input type="submit" class="button" value="'.$langs->trans("Update").'" name="Button">';
print "</td></tr>\n";
print '</form>';

// Export
$var=!$var;
print '<form action="map.php" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="rowid" value="'.$rowid.'">';
print '<input type="hidden" name="constname" value="GOOGLE_KEY">';
print "<tr $bc[$var] class=value><td>".$langs->trans("GoogleKey").'</td><td>';
print '<input type="text" size="100" name="constvalue" value="'.$conf->global->GOOGLE_KEY.'">';
print '</td><td align="center" width="80">';
print '<input type="submit" class="button" value="'.$langs->trans("Update").'" name="Button">';
print "</td></tr>\n";
print '</form>';

print "</tr>\n";
print '</form>';
print '</table>';
print '<br>';


?>
101 changes: 101 additions & 0 deletions htdocs/map/geoservice.php
@@ -0,0 +1,101 @@
<?php
require("../main.inc.php");

$socid=$_GET['socid'];

?>
{
features: [
<?php
$resql = $db->query("SELECT rowid, address, ville ,nom , latitude, longitude FROM ".MAIN_DB_PREFIX."societe WHERE longitude is NOT NULL AND latitude IS NOT NULL AND fk_stcomm > 0 AND rowid !=".$socid );
if ($resql)
{
$nump = $db->num_rows($resql);
if ($nump)
{
$i = 0;
while ($i < $nump)
{
$obj = $db->fetch_object($resql);
?>

{
"type": "Feature",
"toponym": null,
"title": "<?php print '<a href=\"'.DOL_URL_ROOT."/societe/soc.php?socid=".$obj->rowid.'\">'.$obj->nom.'</a>'; ?>",
"author": "",
"id": <?php echo $obj->rowid; ?>,
"description": "<?php /*print $obj->address.'<br/>*/'<b>'.$obj->ville.'</b>'; ?>",
"categories": "",
"geometry": {
"type": "Point",
"coordinates": [<?php echo $obj->longitude; ?>,<?php echo $obj->latitude; ?>]
},
"icon_shadow": "",
"icon_shadow_size": [0,0],

"icon_size": [32,32],

"icon": "<?php if( $obj->rowid == $socid ) print DOL_URL_ROOT."/theme/".$conf->theme."/img/red-dot.png"; else print DOL_URL_ROOT."/theme/".$conf->theme."/img/green-dot.png"; ?>",
"line_opacity": 1.0,
"line_width": 1.0,
"poly_color": "",
"source_id": <?php echo $obj->rowid; ?>
}
<?php
print ",";
$i++;

}
$resql = $db->query("SELECT rowid, address, ville ,nom , latitude, longitude FROM ".MAIN_DB_PREFIX."societe WHERE longitude is NOT NULL AND latitude IS NOT NULL AND rowid=".$socid );
if ($resql)
{
$nump = $db->num_rows($resql);
if ($nump)
{
$i = 0;
while ($i < $nump)
{
$obj = $db->fetch_object($resql);
?>

{
"type": "Feature",
"toponym": null,
"title": "<?php print '<a href=\"'.DOL_URL_ROOT."/societe/soc.php?socid=".$obj->rowid.'\">'.$obj->nom.'</a>'; ?>",
"author": "",
"id": <?php echo $obj->rowid; ?>,
"description": "<?php /*print $obj->address.'<br/>*/'<b>'.$obj->ville.'</b>'; ?>",
"categories": "",
"geometry": {
"type": "Point",
"coordinates": [<?php echo $obj->longitude; ?>,<?php echo $obj->latitude; ?>]
},
"icon_shadow": "",
"icon_shadow_size": [0,0],

"icon_size": [32,32],

"icon": "<?php if( $obj->rowid == $socid ) print DOL_URL_ROOT."/theme/".$conf->theme."/img/red-dot.png"; else print DOL_URL_ROOT."/theme/".$conf->theme."/img/green-dot.png"; ?>",
"line_opacity": 1.0,
"line_width": 1.0,
"poly_color": "",
"source_id": <?php echo $obj->rowid; ?>
}
<?php
print ",";
$i++;

}
}
}
}
else
{
print '"error"';
}
}

?>
]
}

0 comments on commit 1f34e0e

Please sign in to comment.