Ejemplo n.º 1
0
 function save()
 {
     $map_id = $_POST['map_id'];
     $data['polylines'][0] = $_POST['shapes_values'];
     $infowindow['map_polyline_setting']['shapes'] = serialize($data);
     $in_loc_data = array('map_polyline_setting' => $infowindow['map_polyline_setting']['shapes']);
     $where['map_id'] = $map_id;
     WPGMP_Database::insert_or_update(TBL_MAP, $in_loc_data, $where);
     unset($_POST['operation']);
 }
Ejemplo n.º 2
0
$map_records = $mapobj->fetch();
if (isset($_REQUEST['_wpnonce'])) {
    $nonce = sanitize_text_field(wp_unslash($_REQUEST['_wpnonce']));
    if (!wp_verify_nonce($nonce, 'wpgmp-nonce')) {
        die('Cheating...');
    } else {
        $data = $_POST;
    }
}
if (!empty($_POST['save_shapes']) && $_POST['save_shapes'] == 'save_shapes') {
    $map_id = $_POST['map_id'];
    $data['polylines'] = $_POST['shapes_values'];
    $infowindow['map_polyline_setting']['shapes'] = serialize($data);
    $in_loc_data = array('map_polyline_setting' => $infowindow['map_polyline_setting']['shapes']);
    $where['map_id'] = $map_id;
    $insertId = WPGMP_Database::insert_or_update(TBL_MAP, $in_loc_data, $where);
}
if (!empty($_GET['map_id'])) {
    $map_id = $_GET['map_id'];
    $selected_map = $mapobj->fetch(array(array('map_id', '=', $map_id)));
}
$all_map[] = __('Select Map', WPGMP_TEXT_DOMAIN);
foreach ($map_records as $key => $map_record) {
    $all_map[$map_record->map_id] = $map_record->map_title;
}
$form = new Responsive_Markup();
$form->set_form_method('get');
$form->add_element('hidden', 'page', array('value' => $_GET['page']));
$form->set_header(__('Choose Map for Drawing', WPGMP_TEXT_DOMAIN), $response, __('Choose Map for Drawing', WPGMP_TEXT_DOMAIN), 'wpgmp_manage_location');
$form->add_element('select', 'map_id', array('lable' => __('Select map', WPGMP_TEXT_DOMAIN), 'current' => $map_id, 'value' => $data['map_id'], 'desc' => __('Enter here the location title.', WPGMP_TEXT_DOMAIN), 'required' => true, 'options' => $all_map));
$form->render();
 /**
  * Import Location via CSV,JSON,XML and Excel.
  * @return array Success or Failure error message.
  */
 public function import_location()
 {
     $result = false;
     if (isset($_REQUEST['_wpnonce'])) {
         $nonce = sanitize_text_field(wp_unslash($_REQUEST['_wpnonce']));
     }
     if (!wp_verify_nonce($nonce, 'wpgmp-nonce')) {
         die('Cheating...');
     }
     if (isset($_POST['import_loc'])) {
         if (isset($_FILES['import_file']['tmp_name']) and '' == sanitize_file_name(wp_unslash($_FILES['import_file']['tmp_name']))) {
             $response['error'] = __('Please select file to be imported.', WPGMP_TEXT_DOMAIN);
         } elseif (isset($_FILES['import_file']['name']) and !$this->wpgmp_validate_extension(sanitize_file_name(wp_unslash($_FILES['import_file']['name'])))) {
             $response['error'] = __('Please upload a valid file', WPGMP_TEXT_DOMAIN);
         } else {
             if (isset($_POST['wpgmp_import_mode']) and 'wpgmp_delete' == sanitize_text_field(wp_unslash($_POST['wpgmp_import_mode']))) {
                 global $wpdb;
                 $wpdb->query('TRUNCATE TABLE ' . TBL_LOCATION . '');
                 // DB call ok; no-cache ok.
             }
             $file_extension = explode('.', sanitize_file_name(wp_unslash($_FILES['import_file']['name'])));
             $importer = new WP_Export_Import();
             $file_data = $importer->import($file_extension[1], 'import_file');
             $datas = array();
             if (!empty($file_data)) {
                 $modelFactory = new FactoryModelWPGMP();
                 $category = $modelFactory->create_object('group_map');
                 $categories = $category->fetch();
                 if (!empty($categories)) {
                     $categories_data = array();
                     foreach ($categories as $cat) {
                         $categories_data[$cat->group_map_id] = strtolower(sanitize_text_field($cat->group_map_title));
                     }
                 }
                 foreach ($file_data as $data) {
                     $category_ids = array();
                     if (isset($data['title'])) {
                         $datas['location_title'] = $data['title'];
                     } else {
                         if (isset($data['location_title'])) {
                             $datas['location_title'] = $data['location_title'];
                         }
                     }
                     if (isset($data['address'])) {
                         $datas['location_address'] = $data['address'];
                     } else {
                         if (isset($data['location_title'])) {
                             $datas['location_address'] = $data['location_address'];
                         }
                     }
                     if (isset($data['latitude'])) {
                         $datas['location_latitude'] = $data['latitude'];
                     } else {
                         if (isset($data['location_latitude'])) {
                             $datas['location_latitude'] = $data['location_latitude'];
                         }
                     }
                     if (isset($data['longitude'])) {
                         $datas['location_longitude'] = $data['longitude'];
                     } else {
                         if (isset($data['location_longitude'])) {
                             $datas['location_longitude'] = $data['location_longitude'];
                         }
                     }
                     if (isset($data['city'])) {
                         $datas['location_city'] = $data['city'];
                     } else {
                         if (isset($data['location_city'])) {
                             $datas['location_city'] = $data['location_city'];
                         }
                     }
                     if (isset($data['country'])) {
                         $datas['location_country'] = $data['country'];
                     } else {
                         if (isset($data['location_city'])) {
                             $datas['location_country'] = $data['location_country'];
                         }
                     }
                     if (isset($data['postal-code'])) {
                         $datas['location_postal_code'] = $data['postal-code'];
                     } else {
                         if (isset($data['location_city'])) {
                             $datas['location_postal_code'] = $data['location_postal_code'];
                         }
                     }
                     if (isset($data['message'])) {
                         $datas['location_messages'] = $data['message'];
                     } else {
                         if (isset($data['location_messages'])) {
                             $datas['location_messages'] = $data['location_messages'];
                         }
                     }
                     if (isset($data['location_group_map'])) {
                         $data['categories'] = $data['location_group_map'];
                     }
                     $datas['location_messages'] = $data['message'];
                     // Find out categories id or insert new category.
                     if (isset($data['categories']) and !empty($data['categories'])) {
                         $all_cat = explode(',', strtolower($data['categories']));
                         if (is_array($all_cat)) {
                             foreach ($all_cat as $cat) {
                                 $cat_id = array_search(sanitize_text_field($cat), (array) $categories_data);
                                 if (false == $cat_id) {
                                     // Create a new category.
                                     $new_cat_id = WPGMP_Database::insert_or_update(TBL_GROUPMAP, array('group_map_title' => sanitize_text_field($cat), 'group_marker' => WPGMP_IMAGES . 'default_marker.png'));
                                     $category_ids[] = $new_cat_id;
                                     $categories_data[$new_cat_id] = sanitize_text_field($cat);
                                 } else {
                                     $category_ids[] = $cat_id;
                                 }
                             }
                         }
                     }
                     $datas['location_group_map'] = serialize((array) $category_ids);
                     $result = WPGMP_Database::insert_or_update($this->table, $datas);
                 }
             }
             if (false === $result) {
                 $response['error'] = __('Something went wrong. Please try again.', WPGMP_TEXT_DOMAIN);
             } elseif ($entityID > 0) {
                 $response['success'] = __('Location updated successfully', WPGMP_TEXT_DOMAIN);
             } else {
                 $response['success'] = __('Location added successfully.', WPGMP_TEXT_DOMAIN);
             }
             return $response;
         }
         return $response;
     }
 }
Ejemplo n.º 4
0
 /**
  * Clone map object by id.
  */
 function copy($map_id)
 {
     if (isset($map_id)) {
         $id = intval(wp_unslash($map_id));
         $map = $this->get($this->table, array(array('map_id', '=', $id)));
         $data = array();
         foreach ($map[0] as $column => $value) {
             if ($column == 'map_id') {
                 continue;
             } else {
                 if ($column == 'map_title') {
                     $data[$column] = $value . ' ' . __('Copy', WPGMP_TEXT_DOMAIN);
                 } else {
                     $data[$column] = $value;
                 }
             }
         }
         $result = WPGMP_Database::insert_or_update($this->table, $data);
     }
 }
 /**
  * Delete location object by id.
  */
 function delete()
 {
     if (isset($_GET['group_map_id'])) {
         $id = intval(wp_unslash($_GET['group_map_id']));
         $connection = WPGMP_Database::connect();
         $this->query = $connection->prepare("DELETE FROM {$this->table} WHERE {$this->unique}='%d'", $id);
         return WPGMP_Database::non_query($this->query, $connection);
     }
 }
Ejemplo n.º 6
0
 /**
  * Query to be executed.
  * @param  string $query SQL Query.
  * @return array        Records.
  */
 function query($query)
 {
     $this->query = $query;
     $connection = WPGMP_Database::connect();
     $thisObjectName = get_class($this);
     $cursors = WPGMP_Database::reader($this->query, $connection);
     if (!empty($cursors)) {
         foreach ($cursors as $row) {
             $obj = new $thisObjectName();
             $obj->fill($row);
             $objects[] = $obj;
         }
         return $objects;
     }
 }