We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19349
    • 9 Posts
    Hi,
    Im using Xdbedit and now i need to export a CSV. So hopefully somebody can help.

    In my registuser.grid.js it call the button:
    {
    	xtype: 'buttongroup',
    	title: 'Excel (CSV)',
    	columns: 1,
    	defaults: {
    		scale: 'large'
    	},
    	items: [{
                    text: _(Xdbedit.customconfigs.task + '.export_selected') || _('xdbedit.export_selected')
                    ,handler: this.csvExport
                    ,enableToggle: false
                    ,scope: this
    		}]		
    },
    
    .
    .
    .
    csvExport: function(btn,e) {
            var cs = this.getSelectedAsList();
            if (cs === false) return false;
            MODx.Ajax.request({
                url: this.config.url
                ,params: {
                    action: 'mgr/'+Xdbedit.customconfigs.task+'/export'
    				,task: 'export'
    				,configs: this.config.configs
                }
            });
            return true;
    },
    
    



    And my export.php:
    <?php
    header('Content-type: text/comma-separated-values');
    header('Content-Disposition: attachment; filename="Anmeldung_event.csv"');
    
    $config=$modx->xdbedit->customconfigs;
    $prefix = $config['prefix'];
    $packageName = $config['packageName'];
    $tablename = $config['tablename'];
    
    $packagepath = $modx->getOption('core_path') . 'components/'.$packageName.'/';
    $modelpath = $packagepath.'model/';
    
    $modx->addPackage($packageName,$modelpath,$prefix);
    $classname = $modx->xdbedit->getClassName($tablename);
    
    $region = $modx->getOption('region',$scriptProperties,'all');
    if ($region != 'all'){
        $c->where(array($classname.'.region' => $region));
    }
    
    
    if($modx->isBackend()){
        
        $query = 'SELECT modx_registevent_'.$tablename.'.id, DATE_FORMAT( sent, \'%d.%m.%Y um %H:%i\' ) as eventdate, region, gender, title, firstname, name, email, phone, adress, zipcode, city WHERE '.$region.' FROM `modx_registevent_'.$tablename.'`;';
        $event = $modx->query($query);
        
        $output .= '"ID";"Veranstaltung";"Veranstaltungsdatum";"Geschlecht";"Titel";"Vorname";"Nachname";"Straße";"PLZ";"Ort";"Telefon";"Email"'."\r\n";
        
        while( $row = $modx->db->getRow( $event ) ) {
            $output .= '"'.$row['id'].'";"'.$row['eventdate'].'";"'.htmlspecialchars($row['region'], ENT_QUOTES).'";"'.htmlspecialchars($row['eventdate'], ENT_QUOTES).'";"'.htmlspecialchars($row['gender'], ENT_QUOTES).'";"'.htmlspecialchars($row['title'], ENT_QUOTES).'";"'.htmlspecialchars($row['firstname'], ENT_QUOTES).'";"'.htmlspecialchars($row['name'], ENT_QUOTES).'";"'.htmlspecialchars($row['adress'], ENT_QUOTES).'";"'.htmlspecialchars($row['zipcode'], ENT_QUOTES).'";"'.htmlspecialchars($row['city'], ENT_QUOTES).'";"'.htmlspecialchars($row['phone'], ENT_QUOTES).'";"'.htmlspecialchars($row['email'], ENT_QUOTES).'"'."\r\n";
        }
    }
    return $output;
    
    ?>
    


    Nothing happen. I dont know whats missing. So please can somebody help?
      • 4172
      • 5,888 Posts
      perhaps you can try the way, its done with export element-properties.

      /manager/assets/modext/widgets/element/modx.grid.element.properties.js:
          ,exportProperties: function (btn,e) {
              var id = Ext.getCmp('modx-combo-property-set').getValue();
              MODx.Ajax.request({
                  url: MODx.config.connectors_url+'element/index.php'
                  ,params: {
                      action: 'exportProperties'
                      ,data: this.encode()
                      ,id: id
                  }
                  ,listeners: {
                      'success': {fn:function(r) {
                          location.href = MODx.config.connectors_url+'element/index.php?action=exportProperties&download='+r.message+'&id='+id+'&HTTP_MODAUTH='+MODx.siteId;
                      },scope:this}
                  }
              });
          }



      and core/model/modx/processors/element/exportproperties.php

      <?php
      /**
       * Export properties and output url to download to browser
       *
       * @package modx
       * @subpackage processors.element
       */
      if (!$modx->hasPermission('view_propertyset')) return $modx->error->failure($modx->lexicon('permission_denied'));
      $modx->lexicon->load('propertyset','element');
      
      $o = '';
      if (empty($scriptProperties['download'])) {
          $o = $scriptProperties['data'];
      
          $f = 'export.js';
          $fileName = $modx->getOption('core_path').'export/properties/'.$f;
      
          $cacheManager = $modx->getCacheManager();
          $s = $cacheManager->writeFile($fileName,$o);
      
          return $modx->error->success($f);
      } else {
          $file = $scriptProperties['download'];
          $f = $modx->getOption('core_path').'export/properties/'.$file;
      
          if (empty($scriptProperties['id'])) {
              $name = 'default';
          } else {
              $propertySet = $modx->getObject('modPropertySet',$scriptProperties['id']);
              if (empty($propertySet)) {
                  $name = 'unknown';
              } else {
                  $name = $propertySet->get('name');
                  $name = strtolower(str_replace(' ','-',$name));
              }
          }
      
          if (!is_file($f)) return $o;
      
          $o = file_get_contents($f);
      
          header('Content-Type: application/force-download');
          header('Content-Disposition: attachment; filename="'.$name.'.properties.js"');
      
          return $o;
      }
      return '';



        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 19349
        • 9 Posts
        Thanks for the fast answer. I will try it later grin
          • 19349
          • 9 Posts
          Now i tried it and i have some quetions.
          What makes data:this.encode()? Its not defined.
            • 4172
            • 5,888 Posts
            see function encode in /modx/manager/assets/modext/widgets/core/modx.grid.js

            and here: http://dev.sencha.com/deploy/dev/docs/output/Ext.html
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 19349
              • 9 Posts
              I have not this modext in my assets. So i cant work with this. Your solution works not for me. Im really new in modx cmp programming and im not so fit in php. So maybe you can explain a little more?