Пример #1
0
 /**
  * ...
  *
  * @return	void
  */
 protected function manage()
 {
     \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__membermap_membermap_settings');
     \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('jquery/jquery-ui.js', 'membermap', 'interface'));
     \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('admin_membermap.js', 'membermap', 'admin'));
     \IPS\Output::i()->cssFiles = array_merge(\IPS\Output::i()->cssFiles, \IPS\Theme::i()->css('jquery-ui.css', 'membermap', 'global'));
     \IPS\Output::i()->jsVars['membermap_mapquestAPI'] = \IPS\membermap\Application::getApiKeys('mapquest');
     $form = new \IPS\Helpers\Form();
     $form->addHeader('api_settings');
     $form->add(new \IPS\Helpers\Form\Text('membermap_mapQuestAPI', \IPS\Settings::i()->membermap_mapQuestAPI, TRUE, array(), NULL, NULL, NULL, 'membermap_mapQuestAPI'));
     if (!empty(\IPS\Settings::i()->membermap_mapQuestAPI)) {
         $form->attributes['data-controller'] = 'membermap.admin.membermap.settings';
         $form->attributes['id'] = 'membermap_form_settings';
         $form->addHeader('map_settings');
         $form->add(new \IPS\Helpers\Form\YesNo('membermap_groupByMemberGroup', \IPS\Settings::i()->membermap_groupByMemberGroup));
         $form->add(new \IPS\Helpers\Form\YesNo('membermap_enable_clustering', \IPS\Settings::i()->membermap_enable_clustering));
         $form->add(new \IPS\Helpers\Form\Text('membermap_bbox_location', \IPS\Settings::i()->membermap_bbox_location, FALSE, array(), NULL, NULL, NULL, 'membermap_bbox_location'));
         $form->add(new \IPS\Helpers\Form\Number('membermap_bbox_zoom', intval(\IPS\Settings::i()->membermap_bbox_zoom), FALSE, array('min' => 1, 'max' => 18)));
         $form->hiddenValues['membermap_bbox'] = \IPS\Settings::i()->membermap_bbox;
         $form->addHeader('membermap_autoUpdate');
         $profileFields = array('' => ' -- ' . \IPS\Member::loggedIn()->language()->addToStack('membermap_profileLocationField') . ' -- ');
         foreach (\IPS\core\ProfileFields\Field::fields(array(), \IPS\core\ProfileFields\Field::PROFILE) as $group => $fields) {
             foreach ($fields as $id => $field) {
                 $profileFields['core_pfieldgroups_' . $group][$id] = $field->name;
             }
         }
         $form->add(new \IPS\Helpers\Form\YesNo('membermap_monitorLocationField', \IPS\Settings::i()->membermap_monitorLocationField, FALSE, array('togglesOn' => array('membermap_profileLocationField', 'membermap_monitorLocationField_groupPerm', 'membermap_syncLocationField'))));
         $form->add(new \IPS\Helpers\Form\Select('membermap_profileLocationField', \IPS\Settings::i()->membermap_profileLocationField ? intval(\IPS\Settings::i()->membermap_profileLocationField) : NULL, FALSE, array('options' => $profileFields), NULL, NULL, NULL, 'membermap_profileLocationField'));
         $form->add(new \IPS\Helpers\Form\Select('membermap_monitorLocationField_groupPerm', \IPS\Settings::i()->membermap_monitorLocationField_groupPerm != '' ? \IPS\Settings::i()->membermap_monitorLocationField_groupPerm === '*' ? '*' : explode(",", \IPS\Settings::i()->membermap_monitorLocationField_groupPerm) : '*', FALSE, array('options' => \IPS\Member\Group::groups(), 'multiple' => TRUE, 'parse' => 'normal', 'unlimited' => '*', 'unlimitedLang' => 'all'), NULL, NULL, NULL, 'membermap_monitorLocationField_groupPerm'));
         $form->add(new \IPS\Helpers\Form\YesNo('membermap_syncLocationField', \IPS\Settings::i()->membermap_syncLocationField, FALSE, array(), NULL, NULL, NULL, 'membermap_syncLocationField'));
     }
     if ($values = $form->values(TRUE)) {
         $values['membermap_bbox'] = \IPS\Request::i()->membermap_bbox;
         if (empty($values['membermap_bbox_location'])) {
             $values['membermap_bbox'] = "";
         }
         \IPS\DB::i()->update('core_tasks', array('enabled' => isset($values['membermap_syncLocationField']) and $values['membermap_syncLocationField'] ? 1 : 0), array('`key`=?', 'locationSync'));
         $form->saveAsSettings($values);
         \IPS\Session::i()->log('acplogs__membermap_settings');
         \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=membermap&module=membermap&controller=settings"), 'saved');
     }
     \IPS\Output::i()->output = $form;
 }
 /**
  * Database Schema: Execute Query
  *
  * @return  void
  */
 protected function executeQuery()
 {
     /* Get form */
     $message = NULL;
     $form = new \IPS\Helpers\Form("database_table_execute");
     $form->add(new \IPS\Helpers\Form\Codemirror('versions_sql_query', NULL, TRUE, array('mode' => 'sql')));
     /* Has the form been submitted? */
     if ($values = $form->values()) {
         $excTime = microtime(TRUE);
         $queryResult = \IPS\Db::i()->query($values['versions_sql_query']);
         $excTime = microtime(TRUE) - $excTime;
         $excTime = number_format(round($excTime, 2), 2);
         if ($queryResult === TRUE) {
             \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=core&module=applications&controller=developer&appKey={$this->application->directory}&tab=schema"), 'versions_sql_query_execution_success');
         }
         $data = array();
         foreach ($queryResult as $result) {
             $data[] = $result;
         }
         /**
          * I can't seem to find any reliable method of storing arbitrary data in a members database session, so for
          * right now we store results in a compressed base64 encoded cookie. This data is stored so that we can
          * offer sorting and (possibly pagination in the future) for database results.
          */
         \IPS\Request::i()->setCookie('versions_sql_query_result', base64_encode(gzencode(json_encode(array('numRows' => $queryResult->num_rows, 'excTime' => $excTime, 'data' => $data)))), \IPS\DateTime::create()->add(new \DateInterval('PT1H')));
         /**
          * If we get a result from MySQL (instead of just a success status), we send the output back
          * in a formatted table here.
          */
         $table = new \IPS\Helpers\Table\Custom($data, \IPS\Http\Url::internal("app=core&module=applications&controller=developer&appKey={$this->application->directory}&do=executeQueryResult"));
         \IPS\Output::i()->breadcrumb[] = array(\IPS\Http\Url::internal("app=core&module=applications&controller=developer&appKey={$this->application->directory}&tab=schema"), 'dev_schema');
         \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('versions_sql_query_result_count', TRUE, array('pluralize' => array($queryResult->num_rows), 'sprintf' => array($excTime)));
         \IPS\Output::i()->output = (string) $table;
         return;
     }
     /* If not, show it */
     \IPS\Output::i()->output = (string) $form;
 }
Пример #3
0
 /**
  * Loads add/update location form
  *
  * @return	void
  */
 protected function add()
 {
     if (!\IPS\Member::loggedIn()->member_id) {
         \IPS\Output::i()->error('no_permission', '2MM3/1', 403, '');
     }
     /* Get the members location, if it exists */
     $existing = \IPS\membermap\Map::i()->getMarkerByMember(\IPS\Member::loggedIn()->member_id, FALSE);
     $groupId = \IPS\membermap\Map::i()->getMemberGroupId();
     /* Check permissions */
     if ($existing) {
         if (!$existing->canEdit()) {
             \IPS\Output::i()->error('membermap_error_cantEdit', '2MM3/2', 403, '');
         }
     } else {
         if (!\IPS\membermap\Markers\Groups::load($groupId)->can('add')) {
             \IPS\Output::i()->error('membermap_error_cantAdd', '2MM3/3', 403, '');
         }
     }
     /* HTML5 GeoLocation form */
     $geoLocForm = new \IPS\Helpers\Form('membermap_form_geoLocation', NULL, NULL, array('id' => 'membermap_form_geoLocation'));
     $geoLocForm->class = 'ipsForm_vertical ipsType_center';
     $geoLocForm->addHeader('membermap_current_location');
     $geoLocForm->addHtml('<li class="ipsType_center"><i class="fa fa-fw fa-4x fa-location-arrow"></i></li>');
     $geoLocForm->addHtml('<li class="ipsType_center">' . \IPS\Member::loggedIn()->language()->addToStack('membermap_geolocation_desc') . '</li>');
     $geoLocForm->addButton('membermap_current_location', 'button', NULL, 'ipsButton ipsButton_primary', array('id' => 'membermap_currentLocation'));
     $form = new \IPS\Helpers\Form('membermap_form_location', NULL, NULL, array('id' => 'membermap_form_location'));
     $form->class = 'ipsForm_vertical ipsType_center';
     $form->addHeader('membermap_form_location');
     $form->add(new \IPS\Helpers\Form\Text('membermap_location', '', FALSE, array('placeholder' => \IPS\Member::loggedIn()->language()->addToStack('membermap_form_placeholder')), NULL, NULL, NULL, 'membermap_location'));
     $form->addButton('save', 'submit', NULL, 'ipsPos_center ipsButton ipsButton_primary', array('id' => 'membermap_locationSubmit'));
     $form->hiddenValues['lat'] = \IPS\Request::i()->lat;
     $form->hiddenValues['lng'] = \IPS\Request::i()->lng;
     if ($values = $form->values()) {
         try {
             /* Create marker */
             if ($existing instanceof \IPS\membermap\Markers\Markers) {
                 $marker = $existing;
                 $marker->updated = time();
             } else {
                 $marker = \IPS\membermap\Markers\Markers::createItem(\IPS\Member::loggedIn(), \IPS\Request::i()->ipAddress(), new \IPS\DateTime(), \IPS\membermap\Markers\Groups::load($groupId));
                 $marker->member_id = \IPS\Member::loggedIn()->member_id;
             }
             if (isset($values['membermap_location']) and !empty($values['membermap_location'])) {
                 $marker->location = $values['membermap_location'];
             }
             $marker->name = \IPS\Member::loggedIn()->name;
             $marker->lat = $values['lat'];
             $marker->lon = $values['lng'];
             $marker->save();
             /* Add to search index */
             \IPS\Content\Search\Index::i()->index($marker);
             /* Content approval is requred, redirect the member to the marker page, where this is made clear */
             if ($marker->hidden()) {
                 \IPS\Output::i()->redirect($marker->url());
             } else {
                 \IPS\Output::i()->redirect(\IPS\Http\Url::internal('app=membermap&module=membermap&controller=showmap&dropBrowserCache=1&goHome=1', 'front', 'membermap'));
             }
             return;
         } catch (\Exception $e) {
             $form->error = \IPS\Member::loggedIn()->language()->addToStack('membermap_' . $e->getMessage());
             \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('map')->addLocation($geoLocForm, $form);
             return;
         }
     }
     \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack(!$existing ? 'membermap_button_addLocation' : 'membermap_button_editLocation');
     \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('map')->addLocation($geoLocForm, $form);
 }
Пример #4
0
 public function import()
 {
     $id = isset(\IPS\Request::i()->id) ? intval(\IPS\Request::i()->id) : 0;
     /* Build form */
     $form = new \IPS\Helpers\Form(NULL, 'import');
     if (isset(\IPS\Request::i()->id)) {
         $group = \IPS\membermap\Markers\Groups::load(intval(\IPS\Request::i()->id));
         if ($group->type == 'member') {
             \IPS\Output::i()->error('generic_error', '1MM4/1', 403, '');
         }
     }
     $form->add(new \IPS\Helpers\Form\Upload('import_upload', NULL, TRUE, array('allowedFileTypes' => array('kml'), 'temporary' => TRUE)));
     $form->add(new \IPS\Helpers\Form\YesNo('import_creategroups', FALSE, FALSE, array('togglesOff' => array('import_group'))));
     $form->add(new \IPS\Helpers\Form\Node('import_group', $id ?: 0, FALSE, array('class' => '\\IPS\\membermap\\Markers\\Groups', 'permissionCheck' => 'add', 'subnodes' => false, 'where' => array('group_type != ?', 'member')), NULL, NULL, NULL, 'import_group'));
     if ($values = $form->values()) {
         try {
             $xml = \IPS\Xml\SimpleXML::loadFile($values['import_upload']);
         } catch (\InvalidArgumentException $e) {
             $form->error = \IPS\Member::loggedIn()->language()->addToStack('xml_upload_invalid');
             \IPS\Output::i()->output = $form;
             return;
         }
         /* No group selected, and don't create groups?! */
         if ($values['import_creategroups'] == FALSE and !$values['import_group']) {
             $form->error = \IPS\Member::loggedIn()->language()->addToStack('membermap_error_no_id_no_create');
             \IPS\Output::i()->output = $form;
             return;
         }
         $markers = array();
         $groupOrder = NULL;
         $imported = 0;
         foreach ($xml->Document->Folder as $folder) {
             if (!isset($folder->Placemark)) {
                 continue;
             }
             $folderName = (string) $folder->name;
             foreach ($folder->Placemark as $placemark) {
                 if (!isset($placemark->Point->coordinates)) {
                     continue;
                 }
                 list($lon, $lat, $elev) = explode(',', $placemark->Point->coordinates);
                 $markers[] = array('marker_name' => (string) $placemark->name, 'marker_name_seo' => \IPS\Http\Url::seoTitle((string) $placemark->name), 'marker_description' => (string) $placemark->description, 'marker_lat' => $lat, 'marker_lon' => $lon, 'marker_member_id' => \IPS\Member::loggedIn()->member_id, 'marker_added' => time(), 'marker_open' => 1, 'marker_parent_id' => isset($values['import_group']) ? $values['import_group']->id : NULL);
             }
             /* Create a new group per "folder" */
             if ($values['import_creategroups'] == TRUE and count($markers) > 0) {
                 if ($groupOrder === NULL) {
                     $groupOrder = \IPS\Db::i()->select(array("MAX( `group_position` ) as position"), 'membermap_markers_groups')->first();
                 }
                 $groupOrder = $groupOrder + 1;
                 $group = new \IPS\membermap\Markers\Groups();
                 $group->name = $folderName;
                 $group->name_seo = \IPS\Http\Url::seoTitle($folderName);
                 $group->type = 'custom';
                 $group->pin_colour = '#FFFFFF';
                 $group->pin_bg_colour = 'red';
                 $group->pin_icon = 'fa-globe';
                 $group->position = $groupOrder;
                 $group->save();
                 \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$group->id}", trim($folderName));
                 \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$group->id}_JS", trim($folderName), 1);
                 // Add group id to all elements of the array
                 array_walk($markers, function (&$v, $k) use($group) {
                     $v['marker_parent_id'] = $group->id;
                 });
                 // Insert
                 \IPS\Db::i()->insert('membermap_markers', $markers);
                 $group->setLastComment();
                 $group->save();
                 // Set default permissions
                 $perms = $group->permissions();
                 \IPS\Db::i()->update('core_permission_index', array('perm_view' => '*', 'perm_2' => '*', 'perm_3' => \IPS\Settings::i()->admin_group, 'perm_4' => \IPS\Settings::i()->admin_group), array('perm_id=?', $perms['perm_id']));
                 // Reset
                 $imported += count($markers);
                 $markers = array();
             }
         }
         /* If we still got markers here, it's all pushed to one group, probably */
         if (is_array($markers) and count($markers) > 0) {
             \IPS\Db::i()->insert('membermap_markers', $markers);
             $group = $values['import_group'];
             $group->setLastComment();
             $group->save();
             $imported += count($markers);
         }
         \IPS\membermap\Map::i()->invalidateJsonCache();
         $message = \IPS\Member::loggedIn()->language()->addToStack('membermap_import_thumbup', FALSE, array('sprintf' => array($imported)));
         \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=membermap&module=membermap&controller=markers"), $message);
     }
     /* Display */
     \IPS\Output::i()->output = $form;
 }