Query("
SELECT *
FROM " . PREFIX . "_module_gmap
WHERE id = '" . $gmap_id . "'
");
$row_gs = $sql->FetchAssocArray();
$sql = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_gmap_markers
WHERE gmap_id = '" . $gmap_id . "'
");
$markers = array();
while ($row = $sql->FetchAssocArray())
{
array_push($markers, $row);
}
$AVE_Template->assign('gmap', $row_gs);
$AVE_Template->assign('markers', json_encode($markers));
$AVE_Template->assign('api_key', GOOGLE_MAP_API_KEY);
$AVE_Template->display($tpl_dir . 'map.tpl');
}
/**
* ФУНКЦИИ АДМИНИСТРАТИВНОЙ ЧАСТИ
*/
/**
* Просмотр маркеров карты и добавление новых в админке
*
* @param string $tpl_dir - путь к папке с шаблонами модуля
* @param int $gmap_id - идентификатор карты
*/
function gmapMarkersShow($tpl_dir, $gmap_id)
{
global $AVE_DB, $AVE_Template;
$pin_dir = BASE_DIR.'/modules/gmap/images';
$pin_base_dir = ABS_PATH.'modules/gmap/images';
$pins = array();
if ($handle = opendir($pin_dir . '/')) {
while (false !== ($file = readdir($handle)))
{
if ($file != '.' && $file != '..')
{
$image_title = substr($file, 0, -4);
$upload_file_ext = strtolower(substr($file, -4));
$upload_filename = prepare_fname($image_title) . $upload_file_ext;
if (!empty($upload_filename) && $upload_file_ext == '.png')
{
$pins[] = array('name' => $image_title, 'path' => $pin_base_dir . '/' . $upload_filename);
}
}
}
closedir($handle);
}
$sql = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_gmap
WHERE id = '" . $gmap_id . "'
");
$row_gs = $sql->FetchAssocArray();
$sql = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_gmap_markers
WHERE gmap_id = '" . $gmap_id . "'
");
$load_markers = array();
while ($row = $sql->FetchAssocArray())
{
array_push($load_markers, $row);
}
$limit = 5;
$start = get_current_page() * $limit - $limit;
$sql = $AVE_DB->Query("
SELECT SQL_CALC_FOUND_ROWS *
FROM " . PREFIX . "_module_gmap_markers
WHERE gmap_id = '" . $gmap_id . "'
ORDER BY id ASC
LIMIT " . $start . "," . $limit . "
");
$sql_num = $AVE_DB->Query("SELECT FOUND_ROWS()");
$num = $sql_num->GetCell();
$markers = array();
while ($row = $sql->FetchAssocArray())
{
array_push($markers, $row);
}
if ($num > $limit)
{
$page_nav = ' {t} ';
$page_nav = get_pagination(ceil($num / $limit), 'page', $page_nav);
}
else
{
$page_nav = '';
}
$AVE_Template->assign('api_key', GOOGLE_MAP_API_KEY);
$AVE_Template->assign('page_nav', $page_nav);
$AVE_Template->assign('gmap', $row_gs);
$AVE_Template->assign('gmap_id', $row_gs['id']);
$AVE_Template->assign('gmap_title', $row_gs['gmap_title']);
$AVE_Template->assign('markers', $markers);
$AVE_Template->assign('load_markers', json_encode($load_markers));
$AVE_Template->assign('pins', $pins);
$AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_gmap_markers.tpl'));
}
/**
* Вывод списка карт
*
* @param string $tpl_dir - путь к папке с шаблонами модуля
*/
function gmapListShow($tpl_dir)
{
global $AVE_DB, $AVE_Template;
$gmaps = array();
$limit = 20;
$start = get_current_page() * $limit - $limit;
$sql = $AVE_DB->Query("
SELECT SQL_CALC_FOUND_ROWS
g.*,
COUNT(m.id) AS marker_count
FROM
" . PREFIX . "_module_gmap AS g
LEFT JOIN
" . PREFIX . "_module_gmap_markers AS m
ON m.gmap_id = g.id
GROUP BY g.id
ORDER BY g.id ASC
LIMIT " . $start . "," . $limit . "
");
$sql_num = $AVE_DB->Query("SELECT FOUND_ROWS()");
$num = $sql_num->GetCell();
while($row = $sql->FetchAssocArray())
{
array_push($gmaps, $row);
}
if ($num > $limit)
{
$page_nav = "
{t}";
$page_nav = get_pagination(ceil($num / $limit), 'page', $page_nav);
}
else
{
$page_nav = '';
}
$AVE_Template->assign('page_nav', $page_nav);
if (!empty($_REQUEST['alert']))
{
$AVE_Template->assign('alert', htmlspecialchars(stripslashes($_REQUEST['alert'])));
}
$AVE_Template->assign('api_key', GOOGLE_MAP_API_KEY);
$AVE_Template->assign('gmaps', $gmaps);
$AVE_Template->assign('formaction', 'index.php?do=modules&action=modedit&mod=gmap&moduleaction=new&sub=save&cp=' . SESSION);
$AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_gmap_list.tpl'));
}
/**
* Сохранение маркеров
*
* @param int $gmap_id - идентификатор карты
*/
function gmapMarkersAdd($gmap_id){
if (isset($_POST['marker']))
{
global $AVE_DB;
$markerData = $_POST['marker'];
$sql = "
INSERT
INTO " . PREFIX . "_module_gmap_markers
SET
id = '',
gmap_id = '".(int)$gmap_id."',
latitude = '" . $markerData['latitude'] . "',
longitude = '" . $markerData['longitude'] . "',
title = '" . $markerData['title'] . "',
image = '" . $markerData['image']. "'
";
$AVE_DB->Query($sql);
$markerData['id'] = $AVE_DB->InsertId();
echo json_encode($markerData);
exit;
}
}
/**
* Сохранение редактирования описания маркера
*
* @param int $id - идентификатор маркера
*/
function gmapMarkerSave($id){
if (isset($_POST['marker_title']))
{
global $AVE_DB;
$markerData = $_POST['marker_title'];
$sql = "UPDATE " . PREFIX . "_module_gmap_markers
SET
title = '" . $markerData . "' WHERE id = '" . (int)$id. "'
";
$AVE_DB->Query($sql);
}
exit;
}
/**
* Удаление маркера
*
* @param int $id - идентификатор маркера
*/
function gmapMarkersDel($id){
global $AVE_DB;
$sql = "DELETE FROM " . PREFIX . "_module_gmap_markers WHERE id = '" . (int)$id. "'";
$AVE_DB->Query($sql);
exit;
}
/**
* Получение описания маркера
*
* @param int $id - идентификатор маркера
*/
function gmapMarkersGet($id){
global $AVE_DB;
$sql = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_gmap_markers
WHERE id = '" . $id . "'
");
$row_gs = $sql->FetchRow();
echo $row_gs->title;
exit;
}
/**
* Создание карты
*
*/
function gmapNew()
{
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'save')
{
global $AVE_DB;
$cont = true;
$alert = '';
if (empty($_POST['gmap_title']))
{
$alert = '&alert=empty_gmap_title';
$cont = false;
}
if ($cont)
{
$AVE_DB->Query("
INSERT
INTO " . PREFIX . "_module_gmap
SET
id = '',
gmap_title = '" . $_POST['gmap_title'] . "',
gmap_height = '" . $_POST['gmap_height'] . "',
gmap_width = '" . $_POST['gmap_width'] . "',
longitude = '" . $_POST['longitude'] . "',
latitude = '" . $_POST['latitude'] . "',
gmap_zoom = '" . (int)$_POST['gmap_zoom'] . "'
");
}
header('Location:index.php?do=modules&action=modedit&mod=gmap&moduleaction=1'. $alert);
exit;
}
}
/**
* Редактирование карты
*
* @param string $tpl_dir - путь к папке с шаблонами модуля
* @param int $gmap_id - идентификатор карты
*/
function gmapEdit($tpl_dir, $gmap_id)
{
global $AVE_DB, $AVE_Template;
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'save')
{
$AVE_DB->Query("
UPDATE " . PREFIX . "_module_gmap
SET
gmap_title = '" . $_POST['gmap_title'] . "',
gmap_height = '" . $_POST['gmap_height'] . "',
gmap_width = '" . $_POST['gmap_width'] . "',
longitude = '" . $_POST['longitude'] . "',
latitude = '" . $_POST['latitude'] . "',
gmap_zoom = '" . (int)$_POST['gmap_zoom'] . "'
WHERE
id = '" . (int)$gmap_id . "'
");
header('Location:index.php?do=modules&action=modedit&mod=gmap&moduleaction=1&cp=' . SESSION);
exit;
}
$sql = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_gmap
WHERE id = '" . (int)$gmap_id . "'
");
$row = $sql->FetchAssocArray();
$AVE_Template->assign('api_key', GOOGLE_MAP_API_KEY);
$AVE_Template->assign('gmap', $row);
$AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_gmap_edit.tpl'));
}
/**
* Удаление карты
*
* @param int $gmap_id - идентификатор карты
*/
function gmapDelete($gmap_id)
{
global $AVE_DB;
$AVE_DB->Query("DELETE FROM " . PREFIX . "_module_gmap WHERE id = '" . $gmap_id . "'");
$AVE_DB->Query("DELETE FROM " . PREFIX . "_module_gmap_markers WHERE gmap_id = '" . $gmap_id . "'");
header('Location:index.php?do=modules&action=modedit&mod=gmap&moduleaction=1&cp=' . SESSION);
exit;
}
}
?>