Пример #1
0
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 . '>&nbsp;';
            } 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;
    }
}
Пример #2
0
     break;
 }
 $sql = "SELECT\n\t            mk.*, m.free_marker\n            FROM {$_TABLES['maps_markers']} AS mk\n\t\t\tLEFT JOIN {$_TABLES['maps_maps']} AS m\n\t\t\t\t  ON mk.mid = m.mid\n\t\t\tWHERE mkid = {$_REQUEST['mkid']} LIMIT 1";
 $res = DB_query($sql, 0);
 $A = DB_fetchArray($res);
 if ($A['owner_id'] != $_USER['uid'] or $_MAPS_CONF['marker_edition'] == 0 or $A['free_marker'] != 1) {
     echo COM_refresh($_CONF['site_url']);
     exit;
 }
 $_REQUEST['mid'] = $A['mid'];
 // prepare strings for insertion
 $_REQUEST['modified'] = date("YmdHis");
 // lat, lng can only contain numbers and a decimal
 if (empty($_REQUEST['lat']) || empty($_REQUEST['lng'])) {
     $address = $_REQUEST['address'];
     $coords = MAPS_getCoords($address, $lat, $lng);
     if ($lat == 0 && $lng == 0) {
         $display .= getMarkerForm($_REQUEST);
         $display .= COM_siteFooter();
         COM_output($display);
         exit;
     }
 } else {
     $lat = strval($_REQUEST['lat']);
     $lng = strval($_REQUEST['lng']);
 }
 // addslashes
 $_REQUEST['name'] = addslashes($_REQUEST['name']);
 $_REQUEST['description'] = addslashes($_REQUEST['description']);
 $_REQUEST['address'] = addslashes($_REQUEST['address']);
 $_REQUEST['street'] = addslashes($_REQUEST['street']);
Пример #3
0
switch ($_REQUEST['mode']) {
    case 'delete':
        DB_delete($_TABLES['maps_maps'], 'mid', $_REQUEST['mid']);
        if (DB_affectedRows('') == 1) {
            $msg = $LANG_MAPS_1['deletion_succes'];
        } else {
            $msg = $LANG_MAPS_1['deletion_fail'];
        }
        // delete complete, return to map list
        echo COM_refresh($_CONF['site_url'] . "/admin/plugins/maps/index.php?msg={$msg}");
        exit;
        break;
    case 'save':
        $coords = true;
        // lat, lng, zoom and height can only contain numbers and a decimal
        $coords = MAPS_getCoords(stripslashes($_REQUEST['geo']), $lat, $lng);
        if (empty($_REQUEST['name']) || empty($_REQUEST['geo']) || $coords != true) {
            $display .= COM_startBlock($LANG_MAPS_1['error'], '', 'blockheader-message.thtml');
            $display .= $LANG_MAPS_1['missing_field'];
            if ($coords != true) {
                $display .= $LANG_MAPS_1['geo_fail'];
            }
            $display .= COM_endBlock('blockfooter-message.thtml');
            $display .= getMapForm($_REQUEST);
            break;
        }
        // prepare strings for insertion
        $_REQUEST['created'] = date("YmdHis");
        $_REQUEST['modified'] = date("YmdHis");
        if (!empty($_REQUEST['zoom'])) {
            $_REQUEST['zoom'] = preg_replace('/[^\\d.]/', '', $_REQUEST['zoom']);