* @package Maps */ require_once '../../../lib-common.php'; require_once '../../auth.inc.php'; $display = ''; // Ensure user even has the rights to access this page if (!SEC_hasRights('maps.admin')) { $display .= COM_siteHeader('menu', $MESSAGE[30]) . COM_showMessageText($MESSAGE[29], $MESSAGE[30]) . COM_siteFooter(); // Log attempt to access.log COM_accessLog("User {$_USER['username']} tried to illegally access the Maps plugin administration screen."); echo $display; exit; } // Incoming variable filter $vars = array('mode' => 'alpha', 'cid' => 'number', 'id' => 'number', 'msg' => 'text'); MAPS_filterVars($vars, $_REQUEST); /** * List all maps that the user has access to * * @retun string HTML for the list * */ function MAPS_listmaps() { global $_CONF, $_TABLES, $_IMAGE_TYPE, $LANG_ADMIN, $LANG_MAPS_1; require_once $_CONF['path_system'] . 'lib-admin.php'; $retval = ''; if (DB_count($_TABLES['maps_maps']) == 0) { return $retval = ''; } $header_arr = array(array('text' => $LANG_ADMIN['edit'], 'field' => 'edit', 'sort' => false), array('text' => $LANG_MAPS_1['id'], 'field' => 'mid', 'sort' => true), array('text' => $LANG_MAPS_1['name'], 'field' => 'name', 'sort' => true), array('text' => $LANG_MAPS_1['active_field'], 'field' => 'active', 'sort' => true), array('text' => $LANG_MAPS_1['hidden_field'], 'field' => 'hidden', 'sort' => true));
function MAPS_importCSV($FILES = '', $map_id, $separator = ';', $fields, $valid = false, $filename = '') { global $_CONF, $_TABLES, $LANG24, $LANG_MAPS_1, $_USER; if ($map_id == '') { return MAPS_message('Map ID is missing'); } if (!in_array($separator, array(',', 'tab', ';'))) { echo COM_refresh($_CONF['site_admin_url'] . '/plugins/maps/import_export.php'); exit; } if ($valid == false) { // OK, let's upload csv file require_once $_CONF['path_system'] . 'classes/upload.class.php'; $upload = new upload(); //Debug with story debug function if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) { $upload->setLogFile($_CONF['path'] . 'logs/error.log'); $upload->setDebug(true); } $upload->setMaxFileUploads(1); $upload->setAllowedMimeTypes(array('text/csv' => '.csv', 'text/comma-separated-values' => '.csv', 'application/vnd.ms-excel' => '.csv')); if (!$upload->setPath($_CONF['path_data'])) { $output = COM_siteHeader('menu', $LANG24[30]); $output .= COM_startBlock($LANG24[30], '', COM_getBlockTemplate('_msg_block', 'header')); $output .= $upload->printErrors(false); $output .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer')); $output .= COM_siteFooter(); echo $output; exit; } // Set file permissions on file after it gets uploaded (number is in octal) $upload->setPerms('0644'); $curfile = current($FILES); if (!empty($curfile['name'])) { $pos = strrpos($curfile['name'], '.') + 1; $fextension = substr($curfile['name'], $pos); $filename = 'import_markers_' . COM_makesid() . '.' . $fextension; } if ($filename == '') { return MAPS_message('Houston, we have a problem.'); } $upload->setFileNames($filename); reset($FILES); $upload->uploadFiles(); if ($upload->areErrors()) { $msg = $upload->printErrors(false); return MAPS_message($msg, $LANG24[30]); } $retval = '<p>' . $LANG_MAPS_1['markers_to_add'] . ' ' . DB_getItem($_TABLES['maps_maps'], 'name', "mid={$map_id}") . '</p><ul>'; } else { $retval = '<p>' . $LANG_MAPS_1['markers_added'] . ' ' . DB_getItem($_TABLES['maps_maps'], 'name', "mid={$map_id}") . '</p><ul>'; } //open file and record markers $row = 1; $marker = array(); $valid_fields = MAPS_getFieldsImportExport(); if (($handle = fopen($_CONF['path_data'] . $filename, "r")) !== FALSE) { if ($separator == 'tab') { $separator = "\t"; } $iteration = 0; while (($field_read = fgetcsv($handle, 0, $separator)) !== FALSE) { $iteration++; for ($i = 27; $i > -1; $i = $i - 1) { if ($fields[$i] == $valid_fields[$i]) { $marker[$i] = $field_read[$i]; } else { if (!isset($marker[$i])) { $marker[$i] = ''; } while ($position = current($valid_fields)) { if ($position == $fields[$i]) { $key = key($valid_fields); $marker[$key] = $field_read[$i]; } next($valid_fields); } reset($valid_fields); } } if ($marker[3] == '') { ksort($marker); $retval = '<table style="margin:20px;" border="1">'; foreach ($marker as $key => $val) { $retval .= "<tr><td><font size=2>" . $key . "</td><td><font size=2>" . $val . "</td></tr>"; } $retval .= "</table>"; return MAPS_message($LANG_MAPS_1['name_missing'] . ' | Line: ' . $iteration . $retval); } if ($marker[0] == '' && $marker[1] == '') { return MAPS_message($LANG_MAPS_1['need_address']); } if ($valid == false) { $retval .= '<li>#' . $iteration . ' Name: ' . $marker[3] . '<br' . XHTML . '>Address: ' . $marker[0] . '<br' . XHTML . '>Lat: ' . $marker[1] . ' | Lng: ' . $marker[2] . '<br' . XHTML . '>Description: ' . $marker[4] . '<br' . XHTML . '>mk_default: ' . $marker[5] . ' | mk_pcolor: ' . $marker[6] . ' | mk_scolor: ' . $marker[7] . ' | mk_label: ' . $marker[8] . ' | mk_label_color: ' . $marker[9] . '<br' . XHTML . '>street: ' . $marker[10] . '<br' . XHTML . '>code: ' . $marker[11] . ' | city: ' . $marker[12] . '<br' . XHTML . '>state: ' . $marker[13] . ' | country: ' . $marker[14] . '<br' . XHTML . '>tel: ' . $marker[15] . ' | fax: ' . $marker[16] . '<br' . XHTML . '>web: ' . $marker[17] . '<br' . XHTML . '>item_1: ' . $marker[18] . ' | item_2: ' . $marker[19] . ' | item_3: ' . $marker[20] . ' | item_4: ' . $marker[21] . ' | item_5: ' . $marker[22] . ' | item_6: ' . $marker[23] . ' | item_7: ' . $marker[24] . ' | item_8: ' . $marker[25] . ' | item_9: ' . $marker[26] . ' | item_10: |' . $marker[27] . '<br' . XHTML . '>Map id: ' . $map_id . ' | ' . 'Owner id: ' . $_USER['uid'] . '<br' . XHTML . '> '; } else { ksort($marker); $markers = ''; foreach ($marker as $key => $value) { if ($key != 0) { $markers .= ","; } // prepare strings for insertion switch ($key) { case '0': //address $val[0] = $value; $type = array(0 => 'text'); MAPS_filterVars($type, $val); //MAPS_convert_to ( $val[0], $_CONF['default_charset'] ); $address = $val[0]; break; case '1': //lat if ($value == '') { $lat = $lng = ''; $coords = MAPS_getCoords($address, $lat, $lng); $value = $lat; } break; case '2': //lng if ($value == '') { $value = $lng; } break; default: $val[0] = $value; $type = array(0 => 'text'); MAPS_filterVars($type, $val); //MAPS_convert_to ( $val[0], $_CONF['default_charset'] ); $value = $val[0]; break; } $markers .= " '" . $value . "'"; } //pause 1/10 second to avoid $nano = time_nanosleep(0, 100000); if ($nano === true) { $mkid = date('YmdHis') . $iteration; } $created = $modified = date("Ymd"); $sql = "INSERT INTO {$_TABLES['maps_markers']} (\n\t\t\t\t mkid,\n\t\t\t\t mid,\n\t\t\t\t owner_id,\n\t\t\t\t created, modified,\n\t\t\t\t address, lat, lng, name, description, mk_default, mk_pcolor, mk_scolor, mk_label, mk_label_color,\n\t\t\t\t street, code, city, state, country, tel, fax, web, item_1, item_2, item_3, item_4, item_5, item_6,\n\t\t\t\t item_7, item_8, item_9, item_10) VALUES (\n\t\t\t\t {$mkid},\n\t\t\t\t {$map_id},\n\t\t\t\t {$_USER['uid']},\n\t\t\t\t {$created}, {$modified},\n\t\t\t\t {$markers})"; $mkid_exists = DB_getItem($_TABLES['maps_markers'], 'mkid', "mkid={$mkid}"); DB_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'"); if ($mkid_exists == '' and $mkid != '') { DB_query($sql, 0); } else { COM_errorLog('MAPS - Duplicate mkid during import from ' . $filename); } $mkid = ''; $retval .= '<li>' . stripslashes($marker[3]) . ' | ' . stripslashes($marker[0]); } } fclose($handle); } $retval .= '</ul>'; if ($valid == false) { $validation = '<p><form name="import" action="' . $_CONF['site_url'] . '/admin/plugins/maps/import_export.php?mode=valid" method="POST">'; $validation .= '<input type="hidden" name="filename" value="' . $filename . '">'; $validation .= '<input type="hidden" name="mid" value="' . $map_id . '">'; $validation .= '<input type="hidden" name="separator_in" value="' . $separator . '">'; $validation .= '<input type="submit" name="submit" value="' . $LANG_MAPS_1['yes'] . '"> '; foreach ($fields as $value) { $validation .= '<input type="hidden" name="import_export[]" value="' . $value . '">'; } $validation .= '<input type="submit" name="submit" value="' . $LANG_MAPS_1['no'] . '">'; $validation .= '</form></p>'; return MAPS_message($retval) . $validation; } else { return $retval; } }