Changeset 7132


Ignore:
Timestamp:
Oct 9, 2010, 12:28:05 AM (14 years ago)
Author:
grum
Message:

KML files manager implemented + fixe some small bugs + forgotten file for the search page

Location:
extensions/GMaps
Files:
5 added
10 edited

Legend:

Unmodified
Added
Removed
  • extensions/GMaps/admin/gmaps_admin.tpl

    r7054 r7132  
    11<h2 style="float:right;top:-24px;position:relative;height:auto;font-size:12px;font-weight:normal;">{$plugin.GMAPS_VERSION}</h2>
    22
     3{if isset($errcode) and $errcode!=''}
     4<div class='errors' id='iErrorMsg'>
     5<p>{'gmaps_action_was_stopped'|@translate}</p>
     6<p style='font-style:italic;margin:0 30px;'>{$errcode}</p>
     7</div>
     8{/if}
     9
    310{$GMAPS_BODY_PAGE}
  • extensions/GMaps/admin/gmaps_category_maps.tpl

    r7125 r7132  
    4949
    5050      $('#iBDAssocMapId').bind('change', changeMapDisplayType);
     51      $('[name=fBDAssocKmlFile]').bind('change', changeKmlFileSource);
    5152
    5253      loadList();
    53 
     54    }
     55
     56    /**
     57     * called when the source of kml file changed
     58     */
     59    var changeKmlFileSource = function ()
     60    {
     61      switch($('[name=fBDAssocKmlFile]:checked').val())
     62      {
     63        case 'N':
     64          $('#iBDAssocKmlFileId').css('display', 'none');
     65          $('#iBDAssocKmlFileUrl').css('display', 'none');
     66          $('#iBDKmlWarning').css('display', 'none');
     67          break;
     68        case 'S':
     69          $('#iBDAssocKmlFileId').css('display', 'block');
     70          $('#iBDAssocKmlFileUrl').css('display', 'none');
     71          $('#iBDKmlWarning').css('display', 'block');
     72          break;
     73        case 'U':
     74          $('#iBDAssocKmlFileId').css('display', 'none');
     75          $('#iBDAssocKmlFileUrl').css('display', 'block');
     76          $('#iBDKmlWarning').css('display', 'block');
     77          break;
     78      }
    5479    }
    5580
     
    196221        $('#iBDAssocMapId').val($('#iBDAssocMapId option:first').val());
    197222        $('#iBDAssocApplySubCat').val('y');
     223        $('#iBDAssocKmlNone').attr('checked', true);
     224        $('#iBDAssocKmlFileId').val($('#iBDAssocKmlFileId option:first').val());
    198225        $('#iBDAssocKmlFileUrl').val('');
    199         $('#iBDAssocIcon').val($('#iBDAssocIcon option:visible:first').val());
     226        $('#iBDAssocIcon').val($('#iBDAssocIcon option:first').val());
    200227        $('#iBDAssocTitle').val('');
    201228      }
     
    207234        $('#iBDAssocMapId').val(tmp.mapId);
    208235        $('#iBDAssocApplySubCat').val(tmp.applySubCat);
     236        if(tmp.kmlFileId>0)
     237        {
     238          $('#iBDAssocKmlSelect').attr('checked', true);
     239        }
     240        else if(tmp.kmlFileUrl!='')
     241        {
     242          $('#iBDAssocKmlUrl').attr('checked', true);
     243        }
     244        else
     245        {
     246          $('#iBDAssocKmlNone').attr('checked', true);
     247        }
     248        $('#iBDAssocKmlFileId').val(tmp.kmlFileId);
    209249        $('#iBDAssocKmlFileUrl').val(tmp.kmlFileUrl);
    210250        $('#iBDAssocIcon').val(tmp.icon);
     
    213253
    214254      changeMapDisplayType();
     255      changeKmlFileSource();
    215256    }
    216257
     
    269310        mapId:$('#iBDAssocMapId').val(),
    270311        applySubCat:$('#iBDAssocApplySubCat').val(),
    271         kmlFileUrl:$('#iBDAssocKmlFileUrl').val(),
     312        kmlFileId:($('#iBDAssocKmlSelect').attr('checked'))?$('#iBDAssocKmlFileId').val():0,
     313        kmlFileUrl:($('#iBDAssocKmlSelect').attr('checked'))?'':$('#iBDAssocKmlFileUrl').val(),
    272314        icon:$('#iBDAssocIcon').val(),
    273315        title:$('#iBDAssocTitle').val(),
     
    339381    <th>{'gmaps_category'|@translate}</th>
    340382    <th style="width:90px;">{'gmaps_apply_subcat'|@translate}</th>
    341     <th style="width:90px;">{'gmaps_mapType'|@translate}</th>
    342     <th style="width:356px;">{'gmaps_map'|@translate}</th>
    343     <th style="width:90px;">{'gmaps_map_kmlfile'|@translate}</th>
     383    <th style="width:150px;">{'gmaps_mapType'|@translate}</th>
     384    <th style="width:350px;">{'gmaps_map'|@translate}</th>
     385    <th style="width:220px;">{'gmaps_map_associate_kmlfile'|@translate}</th>
    344386    <th width="40px">&nbsp;</th>
    345387  </tr>
     
    432474            <td>{'gmaps_map_associate_kmlfile'|@translate}</td>
    433475            <td>
    434               <input type="text" id="iBDAssocKmlFileUrl" maxlength='255' size='55' value="">
     476              <label><input type="radio" id='iBDAssocKmlNone' name="fBDAssocKmlFile" value="N">&nbsp;{'gmaps_kml_file_none'|@translate}</label><br>
     477              <label><input type="radio" id='iBDAssocKmlSelect' name="fBDAssocKmlFile" value="S">&nbsp;{'gmaps_kml_file_selected'|@translate}</label><br>
     478              <select style="margin-left:20px;margin-bottom:10px;"  id="iBDAssocKmlFileId">
     479                {foreach from=$datas.kmlFiles item=file}
     480                  <option value='{$file.id}'>{$file.name}</option>
     481                {/foreach}
     482              </select>
     483
     484              <label><input type="radio" id='iBDAssocKmlUrl' name="fBDAssocKmlFile" value="U">&nbsp;{'gmaps_kml_file_url'|@translate}</label><br>
     485              <input style="margin-left:20px;" type="text" id="iBDAssocKmlFileUrl" maxlength='255' size='55' value=""><br>
     486              <p id='iBDKmlWarning' class='helps' style="width:520px;padding-right:20px;">{'gmaps_kml_file_access'|@translate}</p>
     487
    435488            </td>
    436489          </tr>
  • extensions/GMaps/admin/gmaps_category_maps_iListMaps.tpl

    r7125 r7132  
    44    <td>{$data.catName}</td>
    55    <td style="width:90px;">{$data.applySubCat}</td>
    6     <th style="width:150px;">{$data.displayType}</th>
    7     <td style="width:300px;">{$data.mapName}</td>
    8     <td style="width:90px;">{$data.mapKmlFile}</td>
     6    <td style="width:150px;">{$data.displayType}</td>
     7    <td style="width:350px;">{$data.mapName}</td>
     8    <td style="width:220px;">
     9      {if $data.mapKmlFile==''}
     10        {'gmaps_n'|@translate}
     11      {else}
     12        {'gmaps_y'|@translate}&nbsp;<span style='font-style:italic;'>({$data.mapKmlFile})</span>
     13      {/if}
     14    </td>
    915
    1016    <td width="40px">
  • extensions/GMaps/gmaps.css

    r7128 r7132  
    11#iHeaderListMaps { width:100%; border:1px solid; border-collapse: collapse; margin-top:3px; }
    2 #iListMaps, #iListAssoc { width:100%; border:1px solid; height:280px; border-top:0px; overflow:auto; position:relative; left:-1px;}
    3 #iListMapsNb, #iListAssocNb { width:99%; text-align:right; margin-bottom:8px; padding:2px; font-size:80%; }
    4 #iListMaps table, table.listMaps, #iListAssoc table { width:100%; text-align:left; border-collapse: collapse; }
    5 #iListMaps.roma table tr:hover, #iListAssoc.roma table tr:hover  { cursor:pointer; background:#303030; }
    6 #iListMaps.clear table tr:hover, #iListAssoc.clear table tr:hover { cursor:pointer; color: #D54E21; background:#dbe8f3; }
     2#iListMaps, #iListAssoc, #iListKml { width:100%; border:1px solid; height:280px; border-top:0px; overflow:auto; position:relative; left:-1px;}
     3#iListMapsNb, #iListAssocNb, #iListKmlNb { width:99%; text-align:right; margin-bottom:8px; padding:2px; font-size:80%; }
     4
     5#iListMaps table, table.listMaps,
     6#iListAssoc table,
     7#iListKml table  { width:100%; text-align:left; border-collapse: collapse; }
     8
     9#iListMaps.roma table tr:hover,
     10#iListAssoc.roma table tr:hover,
     11#iListKml.roma table tr:hover  { cursor:pointer; background:#303030; }
     12
     13#iListMaps.clear table tr:hover,
     14#iListAssoc.clear table tr:hover,
     15#iListKml.clear table tr:hover { cursor:pointer; color: #D54E21; background:#dbe8f3; }
     16
    717div.addMap { text-align:left; }
    818
  • extensions/GMaps/gmaps2.css

    r7128 r7132  
    140140  position:absolute;
    141141  z-index:1500;
    142   background:#000000;
     142  background:#ffffff;
    143143  opacity:0.55;
    144144  filter:alpha(opacity:55);
  • extensions/GMaps/gmaps_aip.class.inc.php

    r7128 r7132  
    5050                          l10n('gmaps_associate_category_maps'),
    5151                          $this->getAdminLink()."&amp;fGMaps_tabsheet=category_maps");
    52 /*
    5352    $this->tabsheet->add('kml_files',
    5453                          l10n('gmaps_kml_files_management'),
    55                           $this->getAdminLink()."&amp;fGMaps_tabsheet=kml_files"); */
     54                          $this->getAdminLink()."&amp;fGMaps_tabsheet=kml_files");
    5655    $this->tabsheet->add('search',
    5756                          l10n('gmaps_search'),
     
    128127
    129128    $template->assign('plugin', $template_plugin);
     129
     130    if($_REQUEST['errcode']!='')
     131    {
     132      $template->assign('errcode', l10n('gmaps_error_code_'.$_REQUEST['errcode']));
     133    }
     134
    130135    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
    131136
     
    144149  {
    145150    //initialise $REQUEST values if not defined
     151
     152    if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']='';
    146153
    147154    if(!isset($_REQUEST['fGMaps_tabsheet']))
     
    227234      'maps' => $this->makeMapsList(),
    228235      'icons' => $this->makeIconsList(),
     236      'kmlFiles'  => $this->makeKmlFilesList()
    229237    );
    230238    $template->assign('datas', $datas);
     
    242250    global $template;
    243251
    244     /*$template->set_filename('body_page',
    245                 dirname($this->getFileLocation()).'/admin/plugin_admin_maps.tpl');
    246 
    247 
    248     $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');*/
     252    $template->set_filename('body_page',
     253                dirname($this->getFileLocation()).'/admin/gmaps_kmlfiles.tpl');
     254
     255    $datas=Array(
     256      'urlRequest' => $this->getAdminLink('ajax'),
     257    );
     258    $template->assign('datas', $datas);
     259
     260    $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');
    249261  }
    250262
     
    370382
    371383    return($returned);
    372   } //makeCategoriesTree
     384  } //makeMapsList
    373385
    374386
     
    395407
    396408    return($returned);
     409  } //makeIconsList
     410
     411
     412  /**
     413   * build the kml files list
     414   * @return Array : an array, ready to use in the template
     415   */
     416  private function makeKmlFilesList()
     417  {
     418    $returned=array();
     419
     420    $sql="SELECT id, name
     421          FROM ".$this->tables['kmlfiles']."
     422          ORDER BY name, id";
     423    $result = pwg_query($sql);
     424    if($result)
     425    {
     426      while($row = pwg_db_fetch_assoc($result))
     427      {
     428        $returned[]=$row;
     429      }
     430    }
     431
     432    return($returned);
    397433  } //makeCategoriesTree
    398434
    399 
    400435} //class
    401436
  • extensions/GMaps/gmaps_ajax.php

    r7128 r7132  
    6060
    6161      if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']='';
     62      if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']='';
    6263
    6364      // check if asked function is valid
     
    7071           $_REQUEST['ajaxfct']=='admin.assoc.getAssoc' or
    7172           $_REQUEST['ajaxfct']=='admin.assoc.deleteAssoc' or
     73           $_REQUEST['ajaxfct']=='admin.kmlFiles.getList' or
     74           $_REQUEST['ajaxfct']=='admin.kmlFiles.setFile' or
     75           $_REQUEST['ajaxfct']=='admin.kmlFiles.getFile' or
     76           $_REQUEST['ajaxfct']=='admin.kmlFiles.deleteFile' or
    7277
    7378           $_REQUEST['ajaxfct']=='public.maps.init' or
     
    8792
    8893        /*
    89          * check admin.maps.getMap & admin.assoc.getAssoc values
     94         * check values for
     95         *  admin.maps.getMap
     96         *  admin.assoc.getAssoc
     97         *  admin.kmlFiles.getFile
    9098         */
    9199        if($_REQUEST['ajaxfct']=="admin.maps.getMap" or
    92            $_REQUEST['ajaxfct']=="admin.assoc.getAssoc")
     100           $_REQUEST['ajaxfct']=="admin.assoc.getAssoc" or
     101           $_REQUEST['ajaxfct']=="admin.kmlFiles.getFile")
    93102        {
    94103          if(!isset($_REQUEST['id']) or
     
    98107
    99108        /*
    100          * check admin.maps.deleteMap values
     109         * check values for
     110         *  admin.maps.deleteMap
     111         *  admin.assoc.deleteAssoc
     112         *  admin.kmlFiles.deleteFile
    101113         */
    102114        if($_REQUEST['ajaxfct']=="admin.maps.deleteMap" or
    103            $_REQUEST['ajaxfct']=="admin.maps.deleteAssoc")
     115           $_REQUEST['ajaxfct']=="admin.assoc.deleteAssoc" or
     116           $_REQUEST['ajaxfct']=="admin.kmlFiles.deleteFile")
    104117        {
    105118          if(!isset($_REQUEST['id']) or
     
    190203                 isset($_REQUEST['datas']['mapId']) &&
    191204                 isset($_REQUEST['datas']['applySubCat']) &&
     205                 isset($_REQUEST['datas']['kmlFileId']) &&
    192206                 isset($_REQUEST['datas']['kmlFileUrl']) &&
    193207                 isset($_REQUEST['datas']['icon']) &&
     
    208222          }
    209223        }
     224
     225
     226        /*
     227         * check admin.kmlFiles.setFile values
     228         */
     229        if($_REQUEST['ajaxfct']=="admin.kmlFiles.setFile")
     230        {
     231          if(!isset($_REQUEST['id']) )
     232          {
     233            $_REQUEST['ajaxfct']='';
     234          }
     235          else
     236          {
     237            if($_REQUEST['id']=='')
     238            {
     239              if(!(isset($_FILES['file']['name']) and
     240                   isset($_FILES['file']['tmp_name']))) $_REQUEST['ajaxfct']='';
     241            }
     242          }
     243        }
     244
    210245
    211246
     
    293328          $result=$this->ajax_gmaps_admin_assocDeleteAssoc($_REQUEST['id']);
    294329          break;
     330        case 'admin.kmlFiles.getList':
     331          $result=$this->ajax_gmaps_admin_kmlFilesGetList();
     332          break;
     333        case 'admin.kmlFiles.getFile':
     334          $result=$this->ajax_gmaps_admin_kmlFilesGetFile($_REQUEST['id']);
     335          break;
     336        case 'admin.kmlFiles.setFile':
     337          $result=$this->ajax_gmaps_admin_kmlFilesSetFile($_REQUEST['id'], $_REQUEST['name']);
     338          break;
     339        case 'admin.kmlFiles.deleteFile':
     340          $result=$this->ajax_gmaps_admin_kmlFilesDeleteFile($_REQUEST['id']);
     341          break;
     342
    295343
    296344        case 'public.maps.init':
     
    496544      $sql="SELECT pgcm.id, pgcm.categoryId, pct.name AS catName,
    497545                   pgmm.name AS mapName, pgmm.displayType,
    498                    pgcm.kmlFileUrl, pgcm.imgSort, pgcm.applySubCat, pgcm.icon,
    499                    pgcm.title
    500             FROM (".$this->tables['category_maps']." pgcm
     546                   pgcm.kmlFileId, pgcm.kmlFileUrl, pgcm.imgSort, pgcm.applySubCat, pgcm.icon,
     547                   pgcm.title, pgkf.name AS kmlName
     548            FROM ((".$this->tables['category_maps']." pgcm
    501549                  LEFT JOIN ".CATEGORIES_TABLE." pct ON pct.id=pgcm.categoryId)
    502                   LEFT JOIN ".$this->tables['maps']." pgmm ON pgcm.mapId = pgmm.id
     550                  LEFT JOIN ".$this->tables['maps']." pgmm ON pgcm.mapId = pgmm.id)
     551                  LEFT JOIN ".$this->tables['kmlfiles']." pgkf ON pgkf.id = pgcm.kmlFileId
    503552            ORDER BY pct.name, pgmm.displayType, pgcm.imgSort";
    504553      $result=pwg_query($sql);
     
    513562          $keys['prev']=$keys['curr'];
    514563
     564          if($row['kmlFileId']>0)
     565          {
     566            $mapKmlFile=$row['kmlName'];
     567          }
     568          elseif($row['kmlFileUrl']!='')
     569          {
     570            $mapKmlFile='URL';
     571          }
     572          else
     573          {
     574            $mapKmlFile='';
     575          }
     576
     577
    515578          $tmp=array(
    516579            'id' => $row['id'],
     
    518581            'applySubCat' => l10n('gmaps_'.$row['applySubCat']),
    519582            'mapName' => $row['mapName'],
    520             'mapKmlFile' => l10n('gmaps_'.(($row['kmlFileUrl']=='')?'n':'y')),
     583            'mapKmlFile' => $mapKmlFile,
    521584            'icon' => $row['icon'],
    522585            'displayType' => l10n('gmaps_displayTypeShort'.$row['displayType']),
     
    598661                ($db['maxImgSort']+1)."', '".
    599662                $properties['applySubCat']."', '".
     663                $properties['kmlFileId']."', '".
    600664                $properties['kmlFileUrl']."', '".
    601665                $properties['icon']."', '".
     
    611675                $properties['mapId']."', applySubCat='".
    612676                $properties['applySubCat']."', kmlFileUrl='".
    613                 $properties['kmlFileUrl']."', icon='".
     677                $properties['kmlFileUrl']."', kmlFileId='".
     678                $properties['kmlFileId']."', icon='".
    614679                $properties['icon']."', title='".
    615680                mysql_escape_string($properties['title'])."'
     
    637702        'mapId' => '',
    638703        'applySubCat'=> 'y',
     704        'kmlFileId' => 0,
    639705        'kmlFileUrl' => '',
    640706        'icon' => '',
     
    642708      );
    643709
    644       $sql="SELECT id, categoryId, mapId, applySubCat, kmlFileUrl,
     710      $sql="SELECT id, categoryId, mapId, applySubCat, kmlFileId, kmlFileUrl,
    645711                   icon, title
    646712            FROM ".$this->tables['category_maps']."
     
    676742      return('ko!unknown error');
    677743    } //ajax_gmaps_admin_assocDeleteAssoc
     744
     745
     746
     747    /**
     748     * return a HTML list of referenced kml files
     749     *
     750     * @return String
     751     */
     752    private function ajax_gmaps_admin_kmlFilesGetList()
     753    {
     754      global $template;
     755
     756      $template->set_filename('list_page',
     757                    dirname($this->getFileLocation()).'/admin/gmaps_kmlfiles_iListFiles.tpl');
     758
     759      $datas=Array();
     760
     761      $sql="SELECT pgkf.id, pgkf.file, pgkf.name, pgkf.fileDate, pgkf.fileSize, COUNT(pgcm.id) AS nbAssoc
     762            FROM ".$this->tables['kmlfiles']." pgkf
     763                  LEFT JOIN ".$this->tables['category_maps']." pgcm ON pgcm.kmlFileId = pgkf.id
     764            GROUP BY pgkf.id
     765            ORDER BY pgkf.name";
     766
     767      $result=pwg_query($sql);
     768      if($result)
     769      {
     770        while($row=pwg_db_fetch_assoc($result))
     771        {
     772          $row['fileSize']=$this->formatOctet($row['fileSize']);
     773          $datas[]=$row;
     774        }
     775      }
     776
     777      $template->assign('datas', $datas);
     778      return($template->parse('list_page', true));
     779    } //ajax_gmaps_admin_kmlFilesGetList
     780
     781
     782
     783
     784    /**
     785     * set properties for a given file id ; if no file id is given create a new
     786     * file
     787     *
     788     * @param String $id : the file Id
     789     * @param String $name : the name
     790     * @param String $file : the file name
     791     * @return String : the num id, or an error message
     792     */
     793    private function ajax_gmaps_admin_kmlFilesSetFile($id, $name)
     794    {
     795      global $template;
     796
     797      if(isset($_FILES['file']['name']))
     798      {
     799        $file=$_FILES['file']['name'];
     800      }
     801      else
     802      {
     803        $file='';
     804      }
     805
     806      if($file=='' and $id!='')
     807      {
     808        // update name for an existing file
     809        $sql="UPDATE ".$this->tables['kmlfiles']."
     810              SET name='".mysql_escape_string($name)."'
     811              WHERE id='$id';";
     812        $result=pwg_query($sql);
     813      }
     814      elseif($file!='')
     815      {
     816        // check if this file is not already used by an another file id
     817        $sql="SELECT file
     818              FROM ".$this->tables['kmlfiles']."
     819              WHERE file='".mysql_escape_string($_FILES['file']['name'])."'";
     820        if($id!='') $sql.=" AND id!='$id'";
     821        $result=pwg_query($sql);
     822        if($result)
     823        {
     824          $ok='';
     825          while($row=pwg_db_fetch_assoc($result))
     826          {
     827            $ok=$row['file'];
     828          }
     829          if($ok!='')
     830          {
     831            //file already used by another file id
     832            header("Location: ".$_SERVER['HTTP_REFERER']."&errcode=aksf10");
     833            exit();
     834          }
     835        }
     836        else
     837        {
     838          //unknown error
     839          header("Location: ".$_SERVER['HTTP_REFERER']."&errcode=aksf01");
     840          exit();
     841        }
     842
     843        $file=dirname(__FILE__).'/kml/'.$file;
     844
     845        if(file_exists($file)) unlink($file);
     846        if($id!='')
     847        {
     848          $currentInfo=$this->ajax_gmaps_admin_kmlFilesGetFile($id, false);
     849          if(file_exists(dirname(__FILE__).'/kml/'.$currentInfo['file'])) unlink(dirname(__FILE__).'/kml/'.$currentInfo['file']);
     850        }
     851
     852
     853        if(!move_uploaded_file($_FILES['file']['tmp_name'], $file))
     854        {
     855          /*
     856           * something was wrong, previous file was deleted, so delete the file
     857           * from the database
     858           */
     859          if($id!='') $this->ajax_gmaps_admin_kmlFilesDeleteFile($id);
     860          // error when trying to copy the uploaded file
     861          header("Location: ".$_SERVER['HTTP_REFERER']."&errcode=aksf02");
     862          exit();
     863        }
     864
     865        if($id!='')
     866        {
     867          // update file & name for an existing file
     868          $sql="UPDATE ".$this->tables['kmlfiles']."
     869                SET name='".mysql_escape_string($name)."',
     870                    file='".mysql_escape_string($_FILES['file']['name'])."',
     871                    fileSize=".filesize($file).",
     872                    fileDate='".date('Y-m-d H:i:s', filemtime($file))."'
     873                WHERE id='$id';";
     874          $result=pwg_query($sql);
     875        }
     876        else
     877        {
     878          $sql="INSERT INTO ".$this->tables['kmlfiles']."
     879                VALUES ('', '".mysql_escape_string($_FILES['file']['name'])."',
     880                '".mysql_escape_string($name)."',
     881                '".date('Y-m-d H:i:s', filemtime($file))."',
     882                '".filesize($file)."')";
     883          $result=pwg_query($sql);
     884          $id=pwg_db_insert_id();
     885        }
     886
     887        header("Location: ".$_SERVER['HTTP_REFERER']);
     888        exit();
     889      }
     890
     891
     892
     893      return($id);
     894    } //ajax_gmaps_admin_kmlFilesSetFile
     895
     896
     897
     898    /**
     899     * get properties for a given file id
     900     *
     901     * @param String id : the file Id
     902     * @param Bool $json : if true, return a json string, otherwise an array
     903     * @return String : data formatted in a JSON string
     904     */
     905    private function ajax_gmaps_admin_kmlFilesGetFile($id, $json=true)
     906    {
     907      $returned=array(
     908        'id' => '',
     909        'file' => '',
     910        'name' => '',
     911        'fileDate'=> '',
     912        'fileSize' => 0,
     913        'fileSizeUnits' => 0,
     914      );
     915
     916      $sql="SELECT id, file, name, fileDate, fileSize
     917            FROM ".$this->tables['kmlfiles']."
     918            WHERE id='$id';";
     919      $result=pwg_query($sql);
     920      if($result)
     921      {
     922        while($row=pwg_db_fetch_assoc($result))
     923        {
     924          $row['fileSizeUnits']=$this->formatOctet($row['fileSize']);
     925          $returned=$row;
     926        }
     927      }
     928
     929      if($json)
     930      {
     931        return(json_encode($returned));
     932      }
     933      else
     934      {
     935        return($returned);
     936      }
     937    } //ajax_gmaps_admin_kmlFilesGetFile
     938
     939
     940
     941
     942    /**
     943     * delete a file
     944     *
     945     * @param String id : if of the file to delete
     946     * @return String : ok or ko
     947     */
     948    private function ajax_gmaps_admin_kmlFilesDeleteFile($id)
     949    {
     950      $file='';
     951
     952      /*
     953       * before deleting record in the table, get the associated file name stored
     954       * on the server
     955       */
     956      $sql="SELECT file
     957            FROM ".$this->tables['kmlfiles']."
     958            WHERE id='$id';";
     959      $result=pwg_query($sql);
     960      if($result)
     961      {
     962        while($row=pwg_db_fetch_assoc($result))
     963        {
     964          $file=$row['file'];
     965        }
     966      }
     967
     968      // reset kmlFileId for assocation
     969      $sql="UPDATE ".$this->tables['category_maps']."
     970            SET kmlFileId='0'
     971            WHERE kmlFileId='$id'";
     972      pwg_query($sql);
     973
     974      // delete the file
     975      $sql="DELETE FROM ".$this->tables['kmlfiles']."
     976            WHERE id='$id';";
     977      $result=pwg_query($sql);
     978      if($result)
     979      {
     980        if($file!='' and file_exists(dirname(__FILE__).'/kml/'.$file))
     981        {
     982          unlink(dirname(__FILE__).'/kml/'.$file);
     983        }
     984        return('ok');
     985      }
     986      return('ko!unknown error');
     987    } //ajax_gmaps_admin_kmlFilesDeleteFile
     988
     989
    678990
    679991
     
    9821294          }
    9831295
    984 
    985 
    9861296          $returned['markers'][]=$coords;
    9871297          $returned['datas']['nbPhotos']+=$coords['nbImages'];
     
    9931303        $returned['datas']['nbPhotos']=sprintf(l10n('gmaps_nb_pictures'), $returned['datas']['nbPhotos']);
    9941304      }
     1305      elseif($returned['datas']['nbPhotos']==1)
     1306      {
     1307        $returned['datas']['nbPhotos']=l10n('gmaps_1_picture');
     1308      }
    9951309      else
    9961310      {
    997         $returned['datas']['nbPhotos']=l10n('gmaps_1_picture');
     1311        $returned['datas']['nbPhotos']=l10n('gmaps_0_picture');
    9981312      }
    9991313
     
    10021316
    10031317
     1318
     1319
     1320     /**
     1321      * formats a file size into a human readable size
     1322      *
     1323      * @param String $format : "A"  : auto
     1324      *                         "Ai" : auto (io)
     1325      *                         "O"  : o
     1326      *                         "K"  : Ko
     1327      *                         "M"  : Mo
     1328      *                         "G"  : Go
     1329      *                         "Ki" : Kio
     1330      *                         "Mi" : Mio
     1331      *                         "Gi" : Gio
     1332      * @param String $thsep : thousand separator
     1333      * @param Integer $prec : number of decimals
     1334      * @param Bool $visible : display or not the unit
     1335      * @return String : a formatted file size
     1336      */
     1337     private function formatOctet($octets, $format="Ai", $thsep="", $prec=2, $visible=true)
     1338     {
     1339      if($format=="Ai")
     1340      {
     1341       if($octets<1024)
     1342       { $format="O"; }
     1343       elseif($octets<1024000)
     1344       { $format="Ki"; }
     1345       elseif($octets<1024000000)
     1346       { $format="Mi"; }
     1347       else
     1348       { $format="Gi"; }
     1349      }
     1350      elseif($format=="A")
     1351      {
     1352       if($octets<1000)
     1353       { $format="O"; }
     1354       elseif($octets<1000000)
     1355       { $format="Ki"; }
     1356       elseif($octets<1000000000)
     1357       { $format="Mi"; }
     1358       else
     1359       { $format="Gi"; }
     1360      }
     1361
     1362      switch($format)
     1363      {
     1364       case "O":
     1365        $unit="o"; $div=1;
     1366        break;
     1367       case "K":
     1368        $unit="Ko"; $div=1000;
     1369        break;
     1370       case "M":
     1371        $unit="Mo"; $div=1000000;
     1372        break;
     1373       case "G":
     1374        $unit="Go"; $div=1000000000;
     1375        break;
     1376       case "Ki":
     1377        $unit="Kio"; $div=1024;
     1378        break;
     1379       case "Mi":
     1380        $unit="Mio"; $div=1024000;
     1381        break;
     1382       case "Gi":
     1383        $unit="Gio"; $div=1024000000;
     1384        break;
     1385      }
     1386
     1387      $returned=number_format($octets/$div, $prec, '.', $thsep);
     1388      if($visible) $returned.=' '.$unit;
     1389      return($returned);
     1390     } //function formatOctet
     1391
     1392
     1393
    10041394  } //class
    10051395
  • extensions/GMaps/gmaps_install.class.inc.php

    r7128 r7132  
    6969  `imgSort` smallint(5) unsigned NOT NULL default '0',
    7070  `applySubCat` char(1) NOT NULL default 'y',
     71  `kmlFileId` int(10) unsigned NOT NULL default '0',
    7172  `kmlFileUrl` varchar(255) NOT NULL,
    7273  `icon` varchar(255) NOT NULL,
     
    8788  `imageCatsPLink` varchar(255) NOT NULL,
    8889  PRIMARY KEY  USING BTREE (`userId`,`requestId`,`imageId`)
     90)",
     91"CREATE TABLE `".$this->tables['kmlfiles']."` (
     92  `id` int(10) unsigned NOT NULL auto_increment,
     93  `file` varchar(255) NOT NULL,
     94  `name` varchar(255) NOT NULL,
     95  `fileDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
     96  `fileSize` mediumint(8) unsigned NOT NULL,
     97  PRIMARY KEY  (`id`)
    8998)"
    9099      );
  • extensions/GMaps/gmaps_root.class.inc.php

    r7128 r7132  
    7676      $this->section_name=$this->getPluginNameFiles();
    7777
    78       $this->setTablesList(array('maps', 'category_maps', 'cache'));
     78      $this->setTablesList(array('maps', 'category_maps', 'cache', 'kmlfiles'));
    7979      $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css");
    8080    }
     
    203203       */
    204204      $sql="SELECT DISTINCT pgcm.id, pgcm.categoryId,
    205               pgcm.imgSort, pgcm.applySubCat, pgcm.kmlFileUrl,
     205              pgcm.imgSort, pgcm.applySubCat, pgcm.kmlFileUrl, pgcm.kmlFileId, pgkf.file AS kmlFileUrlId,
    206206              pgcm.icon, pgcm.title,
    207207              pgmm.displayType, pgmm.sizeMode,
     
    210210              pgmm.navigationControl, pgmm.style,
    211211              IF(pgcm.categoryId=0, 0, pct.global_rank) AS priorityRank
    212             FROM (".$this->tables['category_maps']." pgcm
    213               LEFT JOIN ".$this->tables['maps']." pgmm ON pgcm.mapId = pgmm.id)
    214               LEFT JOIN ".CATEGORIES_TABLE." pct ON (FIND_IN_SET(pgcm.categoryId, pct.uppercats)!=0 OR pgcm.categoryId=0)
     212            FROM ((".$this->tables['category_maps']." pgcm
     213                  LEFT JOIN ".$this->tables['maps']." pgmm ON pgcm.mapId = pgmm.id)
     214                  LEFT JOIN ".CATEGORIES_TABLE." pct ON (FIND_IN_SET(pgcm.categoryId, pct.uppercats)!=0 OR pgcm.categoryId=0))
     215                  LEFT JOIN ".$this->tables['kmlfiles']." pgkf ON  pgkf.id = pgcm.kmlFileId
    215216            WHERE $where ";
    216217      if($category!=0)
     
    237238        while($row=pwg_db_fetch_assoc($result))
    238239        {
     240          // if an kml file id is given, apply the url of the file (needs to give the complete URI for google)
     241          if($row['kmlFileId']>0 and $row['kmlFileUrlId']!='') $row['kmlFileUrl']=dirname($_SERVER['SCRIPT_URI']).'/plugins/GMaps/kml/'.$row['kmlFileUrlId'];
     242
    239243          if($row['displayType']!='MP')
    240244          {
  • extensions/GMaps/language/fr_FR/plugin.lang.php

    r7128 r7132  
    1414$lang['gmaps_associate_category_maps'] = 'Association des cartes';
    1515$lang['gmaps_search'] = 'Rechercher';
    16 $lang['gmaps_kml_files_management'] = 'Gestion des fichiers KML';
     16$lang['gmaps_kml_files_management'] = 'Gestion des fichiers KML/KMZ';
    1717$lang['gmaps_help'] = 'Aide';
    1818
     
    3030$lang['gmaps_pleaseConfirmMetadataDelete_1']="La carte ainsi que toutes les associations qui en dépendent seront supprimées.";
    3131$lang['gmaps_pleaseConfirmMetadataDelete_2']="Merci de confirmer la suppression.";
    32 $lang['gmaps_pleaseConfirmAssoc']="Merci de confirmer la suppression.";
     32$lang['gmaps_pleaseConfirmKml_1']="Le fichier KML/KMZ sera supprimé et toutes les références à celui seront réinitialisées.";
     33$lang['gmaps_pleaseConfirmKml_2']="Merci de confirmer la suppression.";
     34$lang['gmaps_pleaseConfirmKml']="Merci de confirmer la suppression.";
    3335$lang['gmaps_deleteMap']="Suppression de la carte";
    3436$lang['gmaps_add_a_new_map']="Ajouter une carte";
     37$lang['gmaps_deleteKml']="Suppression du fichier KML/KMZ";
     38$lang['gmaps_add_a_new_kmlFile']="Ajouter un fichier KML/KMZ";
    3539
    3640$lang['gmaps_name']="Nom";
     
    9599$lang['gmaps_nb_pictures']="%s photos";
    96100$lang['gmaps_1_picture']="1 photo";
     101$lang['gmaps_0_picture']="Il n'y a aucune photo sur cette zone géographique";
    97102$lang['gmaps_apply_subcat']="Appliquer aux sous-catégories";
    98103$lang['gmaps_map_id']="Carte";
    99 $lang['gmaps_map_kmlfile']="Présence fichier KML";
     104$lang['gmaps_map_kmlfile']="Présence fichier KML/KMZ";
    100105$lang['gmaps_map_icon']="Icone";
    101 $lang['gmaps_map_kmlfile']="Associer un fichier KML";
    102 $lang['gmaps_map_associate_kmlfile']="Associer un fichier KML (saisir l'URL)";
     106$lang['gmaps_map_associate_kmlfile']="Associer un fichier KML/KMZ";
    103107
    104108$lang['gmaps_map_integration']="Intégration dans la galerie";
     
    134138
    135139
     140$lang['gmaps_kml_file_management']="Gestion d\\'un fichier KML/KMZ";
     141$lang['gmaps_kml_files_management']="Gestion des fichiers KML/KMZ";
     142$lang['gmaps_file']="Fichier";
     143$lang['gmaps_date']="Date";
     144$lang['gmaps_file_size']="Taille du fichier";
     145$lang['gmaps_nb_assoc']="Affectations";
     146$lang['gmaps_file_required']="La sélection d\\'un fichier est requise !";
     147$lang['gmaps_file_is_not_kml_kmz']="L\\'extension du fichier est invalide ! Seuls les fichiers KML et KMZ sont acceptés.";
     148
     149$lang['gmaps_error_code_aksf01']="Une erreur d'origine inconnue est survenue... :-/";
     150$lang['gmaps_error_code_aksf02']="Une erreur est survenu lors de l'enregistrement du fichier";
     151$lang['gmaps_error_code_aksf10']="Un fichier portant le même nom est déjà utilisé";
     152$lang['gmaps_action_was_stopped']="L'action a été interrompue pour le motif suivant :";
     153
     154$lang['gmaps_kml_file_selected']="Sélection parmi les fichiers gérés";
     155$lang['gmaps_kml_file_url']="Saisie d'une URL";
     156$lang['gmaps_kml_file_none']="Aucun";
     157
     158$lang['gmaps_kml_file_access']="Les fichiers KML/KMZ doivent, pour pouvoir être affichés sur une carte, être accessibles par les serveurs de Google";
     159
     160
    136161?>
Note: See TracChangeset for help on using the changeset viewer.