* @version $Revision: 1253 $ * * This is some of the ugliest code I've ever written. Please do not * judge me by it. :) */ GalleryCoreApi::requireOnce('modules/map/classes/mapHelper.class'); GalleryCoreApi::requireOnce('modules/map/classes/GoogleMapUtilities.class'); /** * @package map * @subpackage UserInterface */ class MapSiteAdminController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest($form) { include(dirname(__FILE__) . '/includes/MapAdminControllerInit.inc'); /* Cancel hit, return to the default Admin Page */ if (isset($form['action']['cancel'])) { $results['status'] = $status; $results['error'] = array(); $results['redirect']['view'] = 'core.SiteAdmin'; $results['redirect']['subView'] = 'map.MapSiteAdmin'; } /* Save general settings */ if (isset($form['action']['save'])) { /* Check for errors */ if (!is_numeric($form['mapWidth']) || intval($form['mapWidth']) != $form['mapWidth']) { $error[] = 'form[error][mapWidth]'; } else if (!is_numeric($form['mapHeight']) || intval($form['mapHeight']) != $form['mapHeight']) { $error[] = 'form[error][mapHeight]'; } else if (!isset($form['AutoCenterZoom']) && (empty($form['centerLongLat']) || !preg_match('/^([-+]?(([0-9]{1,3}(\.[0-9]{0,16})?)|(\.[0-9]{1,16}))(\040)*,' . '(\040)*[-+]?(([0-9]{1,3}(\.[0-9]{0,16})?)|(\.[0-9]{1,16})))?$/', $form['centerLongLat']))) { $error[] = 'form[error][centerLongLat]'; } else if (!isset($form['AutoCenterZoom']) && (!is_numeric($form['zoomLevel']) || (intval($form['zoomLevel']) != $form['zoomLevel']) || ($form['zoomLevel'] < 0) || ($form['zoomLevel'] > 19))) { $error[] = 'form[error][zoomLevel]'; } else if (!empty($form['GVMCenter']) && !preg_match('/^([-+]?(([0-9]{1,3}(\.[0-9]{0,16})?)|(\.[0-9]{1,16}))(\040)*,' . '(\040)*[-+]?(([0-9]{1,3}(\.[0-9]{0,16})?)|(\.[0-9]{1,16})))?$/', $form['GVMCenter'])) { $error[] = 'form[error][GVMCenter]'; } else if (!empty($form['GVMZoom']) && (!is_numeric($form['GVMZoom']) || (intval($form['GVMZoom']) != $form['GVMZoom']) || ($form['GVMZoom'] < 0) || ($form['GVMZoom'] > 19))) { $error[] = 'form[error][GVMZoom]'; } else { if (!array_key_exists('showScale', $form)) { $form['showScale'] = false; } if (!array_key_exists('centerLongLat', $form)) { $form['centerLongLat'] = '0,0'; } if (!array_key_exists('zoomLevel', $form)) { $form['zoomLevel'] = '0'; } /* Cleanup coordinates of any spaces */ if ($form['centerLongLat'] != '') { $form['centerLongLat'] = str_replace(' ', '', trim($form['centerLongLat'])); } /* Save parameters if there have been no errors */ foreach (array('GVMZoom', 'GVMCenter', 'mapWidth', 'linktype', 'mapHeight', 'centerLongLat', 'zoomLevel', 'mapType', 'MapWidthFormat', 'MapHeightFormat') as $setting) { GalleryCoreApi::setPluginParameter('module', 'map', $setting, $form[$setting]); } foreach (array('showScale', 'AutoCenterZoom', 'ShowExportGELink', 'GoogleOverviewFeature', 'ThemeFeature', 'MarkerFeature', 'LegendFeature', 'AdminHelp', 'UserHelp', 'FilterFeature', 'GroupFeature', 'RouteFeature', 'GZoomFeature') as $setting) { GalleryCoreApi::setPluginParameter('module', 'map', $setting, (isset($form[$setting]) && $form[$setting]) ? 1 : 0); } $status['saved'] = 1; } /* Figure out the method we will use */ $method = empty($error) ? 'redirect' : 'delegate'; $results['status'] = $status; $results['error'] = $error; $results[$method]['view'] = 'core.SiteAdmin'; $results[$method]['subView'] = 'map.MapSiteAdmin'; } if (isset($form['action']['editkey'])) { $id = $form['MapKeys']; $tmp = GalleryCoreApi::getPluginParameter('module', 'map', 'MapKeys'); $AllMapKeys = explode('|', $tmp[1]); $newkeys = ''; foreach ($AllMapKeys as $key) { $temp = explode('`', $key); if ($temp[0] <> $id) { if ($newkeys == '') { $newkeys = $key; } else { $newkeys = $newkeys . '|' . $key; } } else { $editkey = $key; } } GalleryCoreApi::setPluginParameter('module', 'map', 'MapKeys', $newkeys); GalleryCoreApi::setPluginParameter('module', 'map', 'EditKey', $editkey); $results['status'] = ''; $results['error'] = ''; $results['redirect']['view'] = 'core.SiteAdmin'; $results['redirect']['subView'] = 'map.MapSiteAdmin'; $results['redirect']['mode'] = 'mapkey'; } if (isset($form['action']['addkey'])) { GalleryCoreApi::setPluginParameter('module', 'map', 'EditKey', ''); $results['status'] = ''; $results['error'] = ''; $results['redirect']['view'] = 'core.SiteAdmin'; $results['redirect']['subView'] = 'map.MapSiteAdmin'; $results['redirect']['mode'] = 'mapkey'; } if (isset($form['action']['delkey'])) { $id = $form['MapKeys']; $tmp = GalleryCoreApi::getPluginParameter('module', 'map', 'MapKeys'); $currentprofiles = explode('|', $tmp[1]); $newprofiles = ''; foreach ($currentprofiles as $profile) { $temp = explode('`', $profile); if ($temp[0] <> $id) { if ($newprofiles == '') { $newprofiles = $profile; } else { $newprofiles = $newprofiles . '|' . $profile; } } } GalleryCoreApi::setPluginParameter('module', 'map', 'MapKeys', $newprofiles); if ($id != 0) { $status['profiledeleted'] = 1; } $results['status'] = $status; $results['error'] = ''; $results['redirect']['view'] = 'core.SiteAdmin'; $results['redirect']['subView'] = 'map.MapSiteAdmin'; $results['redirect']['mode'] = 'General'; } if (isset($form['action']['savekey'])) { /* error checking */ if ($form['KeyProfileName'] == '') { $form['error']['profilename'] = 1; } else if ($form['KeySvrName'] == '') { $form['error']['profilesvr'] = 1; } else if ($form['keyMapKey'] == '') { $form['error']['profilekey'] = 1; } else { if ($form['KeyPortName'] == '') { $form['KeyPortName'] = '80'; } $oldprofiles = GalleryCoreApi::getPluginParameter('module', 'map', 'MapKeys'); if ($oldprofiles[1] <> '') { $temp = explode('|', $oldprofiles[1]); $maxprofile = explode('`', max($temp)); $num = $maxprofile[0] + 1; $mapkey = $oldprofiles[1] . '|' . $num . '`' . $form['KeyProfileName'] . '`' . $form['KeySvrName'] . '`' . $form['KeyPortName'] . '`' . $form['keyMapKey']; } else { $mapkey = '1`' . $form['KeyProfileName'] . '`' . $form['KeySvrName'] . '`' . $form['KeyPortName'] . '`' . $form['keyMapKey']; } GalleryCoreApi::setPluginParameter('module', 'map', 'MapKeys', $mapkey); GalleryCoreApi::setPluginParameter('module', 'map', 'EditKey', ''); } if (empty($error)) { $status['profilesaved'] = 1; list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'map'); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } list ($ret, $isActive) = $module->isActive(); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } $results['redirect']['view'] = 'core.SiteAdmin'; if ($isActive) { $results['status'] = $status; $results['error'] = $error; $results['redirect']['subView'] = 'map.MapSiteAdmin'; $results['redirect']['mode'] = 'General'; } else { $status['configured'] = 'map'; $results['status'] = $status; $results['error'] = $error; $results['redirect']['subView'] = 'core.AdminModules'; } } else { $results['status'] = $status; $results['error'] = $error; $results['delegate']['view'] = 'core.SiteAdmin'; $results['delegate']['subView'] = 'map.MapSiteAdmin'; $results['delegate']['mode'] = 'addkey'; } } if (isset($form['action']['getviamap'])) { $results['status'] = ''; $results['error'] = array(); $results['redirect']['view'] = 'map.ShowMap'; $results['redirect']['Mode'] = 'Pick'; $results['redirect']['plugin'] = 'AdminCenter'; } if (isset($form['action']['getviamap2'])) { $results['status'] = ''; $results['error'] = array(); $results['redirect']['view'] = 'map.ShowMap'; $results['redirect']['Mode'] = 'Pick'; $results['redirect']['plugin'] = 'GVMDefault'; } return array (null, $results); } } /** * @package map * @subpackage UserInterface */ class mapSiteAdminView extends GalleryView { /** * @see GalleryView::loadTemplate */ function loadTemplate(&$template, &$form) { list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'map'); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } include(dirname(__FILE__) . '/includes/MapAdminViewInit.inc'); $form['formName'] = 'mapSiteAdmin'; $template->head('modules/map/includes/GoogleMap.css'); $template->javascript('modules/map/GoogleMap.js'); /* Set default values for undefined plugin parameters */ if (!array_key_exists('mapWidth', $form)) { $form['mapWidth'] = 600; } if (!array_key_exists('mapHeight', $form)) { $form['mapHeight'] = 400; } if (!array_key_exists('centerLongLat', $form)) { $form['centerLongLat'] = '0,0'; } if (!array_key_exists('zoomLevel', $form)) { $form['zoomLevel'] = 17; } if (!array_key_exists('mapType', $form)) { $form['mapType'] = 'G_SATELLITE_TYPE'; } if (!array_key_exists('showScale', $form)) { $form['showScale'] = false; } if (!array_key_exists('AutoCenterZoom', $form)) { $form['AutoCenterZoom'] = false; } if (!array_key_exists('ShowExportGELink', $form)) { $form['ShowExportGELink'] = true; } if (!array_key_exists('GVMCenter', $form)) { $form['GVMCenter'] = '0,0'; } if (!array_key_exists('GVMZoom', $form)) { $form['GVMZoom'] = 17; } if (!array_key_exists('MapWidthFormat', $form)) { $form['MapWidthFormat'] = 1; /* pixels by default */ } if (!array_key_exists('MapHeightFormat', $form)) { $form['MapHeightFormat'] = 1; /* pixels by default */ } if (!array_key_exists('GoogleOverviewFeature', $form)) { $form['GoogleOverviewFeature'] = 0; /* Disabled by default */ } if (!array_key_exists('GZoomFeature', $form)) { $form['GZoomFeature'] = 0; /* Disabled by default */ } if (!array_key_exists('ThemeFeature', $form)) { $form['ThemeFeature'] = 0; /* Disabled by default */ } if (!array_key_exists('MarkerFeature', $form)) { $form['MarkerFeature'] = 0; /* Disabled by default */ } if (!array_key_exists('LegendFeature', $form)) { $form['LegendFeature'] = 0; /* Disabled by default */ } if (!array_key_exists('FilterFeature', $form)) { $form['FilterFeature'] = 0; /* Disabled by default */ } if (!array_key_exists('GroupFeature', $form)) { $form['GroupFeature'] = 0; /* Disabled by default */ } if (!array_key_exists('RouteFeature', $form)) { $form['RouteFeature'] = 0; /* Disabled by default */ } if (!array_key_exists('linktype', $form)) { $form['linktype'] = 0; /* Default link */ } include(dirname(__FILE__) . '/includes/MapAdminEdits.inc'); /* Gather server data to ease fill up */ $form['SRVName'] = preg_replace('/:[0-9]+/', '', GalleryUtilities::getServerVar('HTTP_HOST')); $form['SRVPort'] = GalleryUtilities::getServerVar('SERVER_PORT'); /* Create the Google Map key profile array */ if (array_key_exists('MapKeys', $param) and $param['MapKeys'] != '') { $temp = explode('|', $param['MapKeys']); sort($temp); foreach ($temp as $tmp) { $key = explode('`', $tmp); $form['ArrayMapKeys'][] = $key; } } else { $form['ArrayMapKeys'][] = array(0, '« ' . $module->translate('No Profiles') . ' »'); } if ($template->hasVariable('SiteAdmin')) { $SiteAdmin =& $template->getVariableByReference('SiteAdmin'); $SiteAdmin['enctype'] = 'multipart/form-data'; } else { $SiteAdmin['enctype'] = 'multipart/form-data'; $template->setVariable('SiteAdmin', $SiteAdmin); } $template->setVariable('controller', 'map.MapSiteAdmin'); return array(null, array('body' => 'modules/map/templates/MapSiteAdmin.tpl')); } } ?>