Export not working

Talk about Printing & Exporting Settings

Moderators: ne_moj, zewa

Drat
Newbie
Newbie
Posts: 3
Joined: Dec 28th, '10, 22:35

Export not working

Postby Drat » Jan 2nd, '11, 04:58

I am having a real problem with the export of xml. When I try to export it pulls up the page, looks like it tries to load the grid but the column info is empty.


This is a sample of the code I have for the grid itself.

Code: Select all

<?php
   session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <titleE-Dir</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    </head>
<body>

<?php
    $mode = isset($_REQUEST['prd_mode']) ? $_REQUEST['prd_mode'] : "";

    ################################################################################
    ## +---------------------------------------------------------------------------+
    ## | 1. Creating & Calling:                                                    |
    ## +---------------------------------------------------------------------------+
    ##  *** define a relative (virtual) path to datagrid.class.php file
    ##  *** (relatively to the current file)
    ##  *** RELATIVE PATH ONLY ***     
      define ("DATAGRID_DIR", "../");                     /* Ex.: "datagrid/" */
      define ("PEAR_DIR", "../pear/");                    /* Ex.: "datagrid/pear/" */
   
      require_once(DATAGRID_DIR.'datagrid.class.php');
      require_once(PEAR_DIR.'PEAR.php');
      require_once(PEAR_DIR.'DB.php');
   
    ##
    ##  *** creating variables that we need for database connection

      // includes database connection parameters
      include_once('install/config.inc.php');
     
      //$DB_USER='username';           
      //$DB_PASS='password';           
      //$DB_HOST='localhost';       
      //$DB_NAME='database_name';   
   
      ob_start();
    ##  *** (example of ODBC connection string)
    ##  *** $result_conn = $db_conn->connect(DB::parseDSN('odbc://root:12345@test_db'));
    ##  *** (example of Oracle connection string)
    ##  *** $result_conn = $db_conn->connect(DB::parseDSN('oci8://root:12345@localhost:1521/mydatabase));
    ##  *** (example of PostgreSQL connection string)
    ##  *** $result_conn = $db_conn->connect(DB::parseDSN('pgsql://root:12345@localhost/mydatabase));
    ##  === (Examples of connections to other db types see in "docs/pear/" folder)
      $db_conn = DB::factory('mysql');  /* don't forget to change on appropriate db type */
      $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
      if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); } 
    ##  *** put a primary key on the first place
      $sql = "SELECT
                TenantInfo.tenant_id,
            TenantInfo.orderby_Id,
                TenantInfo.suitenumber,
                TenantInfo.listingName,
                TenantInfo.companyName,
                TenantInfo.email,
                TenantInfo.contactInfo1,
                TenantInfo.contactInfo2,
                TenantInfo.contactInfo3,
            TenantInfo.details_ad,
                TenantInfo.logo,
                TenantInfo.map,
            TenantInfo.active,
            TenantInfo.create_date,
            TenantInfo.last_update
            FROM TenantInfo";
    ##  *** set needed options and create a new class instance
      $debug_mode = false;        /* display SQL statements while processing */   
      $messaging = true;          /* display system messages on a screen */
      $unique_prefix = "prd_";    /* prevent overlays - must be started with a letter */
      $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
    ##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
      $dg_encoding = "utf8";
      $dg_collation = "utf8_unicode_ci";
      $dgrid->SetEncoding($dg_encoding, $dg_collation);
    ##  *** set data source with needed options
      $default_order_field = "TenantInfo.orderby_Id";
      $default_order_type = "ASC";
      $dgrid->DataSource($db_conn, $sql, $default_order_field, $default_order_type);
     

     $postback_method = "post";
     $dgrid->SetPostBackMethod($postback_method);       
    ## +---------------------------------------------------------------------------+
    ## | 2. General Settings:                                                      |
    ## +---------------------------------------------------------------------------+
    ##  *** allow multirow operations
        $multirow_option = true;
        $dgrid->AllowMultirowOperations($multirow_option);
        $multirow_operations = array(
            "edit"  => array("view"=>false),
            "delete"  => array("view"=>true),
            "details" => array("view"=>true),
        );
        $dgrid->SetMultirowOperations($multirow_operations);
       
    ##  *** set CSS class for datagrid
    ##  *** "default|blue|gray|green|pink|empty|x-blue|x-gray|x-green" or your own css style
     $css_class = "default";
     $dgrid->SetCssClass($css_class);
   
    ##  *** "default" or "blue" or "gray" or "green" or "pink" or your own css file
    ##  *** set DataGrid caption
//      $dg_caption = "List of Mobile Phones - <a href=index.php>Back to Index</a>";
//      $dgrid->SetCaption($dg_caption);


    ## +---------------------------------------------------------------------------+
    ## | 3. Printing & Exporting Settings:                                         |
    ## +---------------------------------------------------------------------------+
    ##  *** set printing option: true(default) or false
      $printing_option = false;
      $dgrid->AllowPrinting($printing_option);
      $exporting_option = true;
      $exporting_directory = "";               
      $export_all = true;
      $dgrid->AllowExporting($exporting_option, $exporting_directory, $export_all);
      $exporting_types = array("excel"=>"true", "pdf"=>"true", "xml"=>"true");
      $dgrid->AllowExportingTypes($exporting_types);   
   
    ## +---------------------------------------------------------------------------+
    ## | 4. Sorting & Paging Settings:                                             |
    ## +---------------------------------------------------------------------------+
    ##  *** set paging option: true(default) or false
      $paging_option = true;
      $rows_numeration = false;
      $numeration_sign = "N #";       
      $dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign);
    ##  *** set paging settings
      $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
      $top_paging = array();
      $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
      $default_page_size = 50;
      $dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
   
    ## +---------------------------------------------------------------------------+
    ## | 5. Filter Settings:                                                       |
    ## +---------------------------------------------------------------------------+
    ##  *** set filtering option: true or false(default)
//      $filtering_option = true;
//      $show_search_type = true;
//      $dgrid->AllowFiltering($filtering_option, $show_search_type);
    ##  *** set additional filtering settings
    ##  *** tips: use "," (comma) if you want to make search by some words, for ex.: hello, bye, hi
      $filtering_fields = array(
        "Supplier"  => array("type"=>"dropdownlist", "order"=>"ASC", "table"=>"demo_suppliers", "field"=>"name", "source"=>"self", "show"=>"", "condition"=>"", "show_operator"=>"false", "default_operator"=>"=", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"", "multiple"=>"false", "multiple_size"=>"4", "on_js_event"=>""),
        "From"      =>array("type"=>"textbox", "calendar_type"=>"floating", "table"=>"demo_products", "field"=>"suitenumber", "field_type"=>"from", "show_operator"=>"false", "default_operator"=>">=", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"", "on_js_event"=>""),
        "To"        =>array("type"=>"textbox", "calendar_type"=>"floating", "table"=>"demo_products", "field"=>"suitenumber", "field_type"=>"to", "show_operator"=>"false", "default_operator"=>"<=", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"", "on_js_event"=>""),
      );
//      $dgrid->SetFieldsFiltering($filtering_fields);
   
    ## +---------------------------------------------------------------------------+
    ## | 6. View Mode Settings:                                                    |
    ## +---------------------------------------------------------------------------+
    ##  *** set view mode table properties
      $vm_table_properties = array("width"=>"95%");
      $dgrid->SetViewModeTableProperties($vm_table_properties); 
    ##  *** set columns in view mode
    ##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
    ##  ***      "barchart" : number format in SELECT SQL must be equal with number format in max_value
      $vm_colimns = array(
        "suitenumber"              => array("header"=>"Suite", "type"=>"linktoedit",      "align"=>"left", "width"=>"58px", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
        "details_ad"       => array("header"=>"Details Ad", "type"=>"image",  "align"=>"center", "width"=>"58px", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "default"=>"default_image.ext", "image_width"=>"50px", "image_height"=>"30px", "magnify"=>"true", "magnify_type"=>"magnifier", "magnify_power"=>"3"),
        "logo"       => array("header"=>"Logo", "type"=>"image",  "align"=>"center", "width"=>"58px", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "default"=>"default_image.ext", "image_width"=>"50px", "image_height"=>"30px", "magnify"=>"true", "magnify_type"=>"magnifier", "magnify_power"=>"3"),
        "map"       => array("header"=>"Map", "type"=>"image",  "align"=>"center", "width"=>"58px", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "default"=>"default_image.ext", "image_width"=>"50px", "image_height"=>"30px", "magnify"=>"true", "magnify_type"=>"magnifier", "magnify_power"=>"3"),
      
      
        "listingName"     => array("header"=>"Tenant", "type"=>"linktoview",      "align"=>"center", "width"=>"175px", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
        "contactInfo1" => array("header"=>"Contact Info 1", "type"=>"label",      "align"=>"left", "width"=>"175px", "wrap"=>"nowrap", "text_length"=>"17", "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
        "contactInfo2" => array("header"=>"Contact Info 2", "type"=>"label",      "align"=>"left", "width"=>"175px", "wrap"=>"nowrap", "text_length"=>"17", "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
        "contactInfo3" => array("header"=>"Contact Info 3", "type"=>"label",      "align"=>"left", "width"=>"175px", "wrap"=>"nowrap", "text_length"=>"17", "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),            
        "email" => array("header"=>"EMail", "type"=>"label",      "align"=>"left", "width"=>"175px", "wrap"=>"nowrap", "text_length"=>"17", "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),            
      
    "active"  =>array("header"=>"Active",      "type"=>"checkbox",  "align"=>"center", "width"=>"", "wrap"=>"nowrap", "sort_type"=>"numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "true_value"=>1, "false_value"=>0),
    "orderby_Id"     =>array("header"=>"Order",      "type"=>"label", "align"=>"center",  "wrap"=>"nowrap", "text_length"=>"30", "case"=>"normal", "movable"=>"true"),            
   
//        "statistics"        => array("header"=>"Sales %", "type"=>"barchart",   "align"=>"left", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal|upper|lower|camel", "summarize"=>"false", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "field"=>"statistics", "maximum_value"=>"100"),
      );
      $dgrid->SetColumnsInViewMode($vm_colimns);
   
   
    ## +---------------------------------------------------------------------------+
    ## | 7. Add/Edit/Details Mode Settings:                                        |
    ## +---------------------------------------------------------------------------+
    ##  *** set add/edit mode table properties
      $em_table_properties = array("width"=>"70%");
      $dgrid->SetEditModeTableProperties($em_table_properties);
    ##  *** set details mode table properties
      $dm_table_properties = array("width"=>"70%");
      $dgrid->SetDetailsModeTableProperties($dm_table_properties);
    ##  ***  set settings for add/edit/details modes
      $table_name  = "TenantInfo";
      $primary_key = "tenant_id";
      $condition   = "";
      $dgrid->SetTableEdit($table_name, $primary_key, $condition);

//     $layouts = array("view"=>"0", "edit"=>"0", "details"=>"1", "filter"=>"1");
//    $dgrid->SetLayouts($layouts);
        
      $fill_from_array_sales = array();
      for($i=1; $i<100; $i++){
        $fill_from_array_sales[$i] = $i;
      }
       
      $em_columns = array(
//            "delimiter_0"   =>array("inner_html"=>"<div style='padding:5px;'></div>"),
            "listingName"          =>array("header"=>"Listing Name", "type"=>"textbox",    "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
            "companyName"          =>array("header"=>"Details Name", "type"=>"textbox",    "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
            "suitenumber"   =>array("header"=>"Suite Number", "type"=>"textbox","req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
           
//            "delimiter_1"   =>array("inner_html"=>"<div style='padding:5px;'>Image fields: These are image fields. You can click on each picture to enlarge. </div>"),
            "details_ad"   =>array("header"=>"Details Section Ad", "type"=>"image",      "req_type"=>"st", "width"=>"350px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"400K", "image_width"=>"300px", "image_height"=>"100px", "magnify"=>"true", "magnify_type"=>"lightbox", "file_name"=>"img_".(($mode == "add") ? $dgrid->GetRandomString("10") : $dgrid->GetCurrentId()), "host"=>"local", "pre_addition"=>"Click on image to enlarge...<br>"),
            "logo"   =>array("header"=>"Company Logo", "type"=>"image",      "req_type"=>"st", "width"=>"350px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"400K", "image_width"=>"300px", "image_height"=>"100px", "magnify"=>"true", "magnify_type"=>"lightbox", "file_name"=>"img_".(($mode == "add") ? $dgrid->GetRandomString("10") : $dgrid->GetCurrentId()), "host"=>"local", "pre_addition"=>"Click on image to enlarge...<br>"),
            "map"     =>array("header"=>"Floor Map", "type"=>"image",      "req_type"=>"st", "width"=>"220px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"500K", "image_width"=>"875px", "image_height"=>"350px", "magnify"=>"true", "magnify_type"=>"lightbox", "file_name"=>"img_".(($mode == "add") ? $dgrid->GetRandomString("10") : $dgrid->GetCurrentId()), "host"=>"local", "pre_addition"=>"Click on image to enlarge...<br>"),
           
//            "delimiter_2"   =>array("inner_html"=>"<div style='padding:5px;'>Detailed Contact Information</div>"),
            "contactInfo1"          =>array("header"=>"Contact Info 1", "type"=>"textbox",    "req_type"=>"", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"30", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
            "contactInfo2"          =>array("header"=>"Contact Info 2", "type"=>"textbox",    "req_type"=>"", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
            "contactInfo3"          =>array("header"=>"Contact Info 3", "type"=>"textbox",    "req_type"=>"", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
            "email"          =>array("header"=>"Email", "type"=>"textbox",    "req_type"=>"", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
                  
//            "short_description"  =>array("header"=>"Short Description", "type"=>"textarea",   "req_type"=>"rt", "width"=>"500px", "title"=>"", "readonly"=>"false", "maxlength"=>"255", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "edit_type"=>"simple", "resizable"=>"true", "rows"=>"5", "cols"=>"50"),
//           "long_description"   =>array("header"=>"Long Description", "type"=>"textarea",   "req_type"=>"rt", "width"=>"500px", "title"=>"", "readonly"=>"false", "maxlength"=>"1024", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "edit_type"=>"wysiwyg", "resizable"=>"false", "rows"=>"7", "cols"=>"50"),
   
//            "delimiter_3"   =>array("inner_html"=>"<div style='padding:5px;'>Date/Time fields:</div>"),
//            "available_from"  =>array("header"=>"Available From", "type"=>"datetime",   "req_type"=>"st", "width"=>"187px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"dropdownlist"),         
            "create_date"    =>array("header"=>"Date Added", "type"=>"label",      "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
            "last_update"  =>array("header"=>"Last Updated", "type"=>"label",   "req_type"=>"st", "width"=>"187px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
           
//            "delimiter_4"   =>array("inner_html"=>"<div style='padding:5px;'>Other fields: </div>"),
//            "price"         =>array("header"=>"Price", "type"=>"textbox",    "req_type"=>"rf", "width"=>"90px", "title"=>"", "readonly"=>"false", "maxlength"=>"12", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "pre_addition"=>"$"),
//            "statistics"    =>array("header"=>"Sales in %", "type"=>"enum",       "req_type"=>"rf", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>$fill_from_array_sales, "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "multiple"=>"false", "multiple_size"=>"4"),
       "orderby_Id"      =>array("header"=>"Order",     "type"=>"textbox",  "width"=>"100px", "req_type"=>"ri", "maxlength"=>"3", "title"=>"Order"),         
            "active"     =>array("header"=>"Active", "type"=>"checkbox",   "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"1", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "true_value"=>1, "false_value"=>0),
//            "is_featured"   =>array("header"=>"Is Featured", "type"=>"enum",       "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>"self", "view_type"=>"radiobutton", "radiobuttons_alignment"=>"horizontal", "multiple"=>"false", "multiple_size"=>"4"),
      );
      $dgrid->SetColumnsInEditMode($em_columns);
    ##  *** set auto-generated columns in edit mode
      $auto_column_in_edit_mode = false;
      $dgrid->SetAutoColumnsInEditMode($auto_column_in_edit_mode);
    ##  *** set foreign keys for add/edit/details modes (if there are linked tables)
    ##  *** Ex.: "field_name"=>"CONCAT(field1,','field2) as field3"
    ##  *** Ex.: "condition"=>"TableName_1.FieldName > 'a' AND TableName_1.FieldName < 'c'"
    ##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
      $foreign_keys = array(
        "supplier_id"=>array("table"=>"demo_suppliers", "field_key"=>"id", "field_name"=>"name", "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "condition"=>"", "order_by_field"=>"name", "order_type"=>"ASC", "on_js_event"=>""),
      );
      $dgrid->SetForeignKeysEdit($foreign_keys);
     
    ## +---------------------------------------------------------------------------+
    ## | 8. Bind the DataGrid:                                                     |
    ## +---------------------------------------------------------------------------+
    ##  *** bind the DataGrid and draw it on the screen
      $dgrid->Bind();       
      ob_end_flush();
   
    ################################################################################   
 
function my_format_date($last_login_time){
    $last_login = @mktime(substr($last_login_time, 11, 2), substr($last_login_time, 14, 2),
                        substr($last_login_time, 17, 2), substr($last_login_time, 5, 2),
                        substr($last_login_time, 8, 2), substr($last_login_time, 0, 4));
    if($last_login_time != ""){
        return @date("M d, Y g:i A", $last_login);
    }else return "";
}
?>

</body>
</html><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>E-Dir</title>
</head>

<body>
</body>
</html>



here is the download code

Code: Select all

<?php
    // Last changed: 23.09.2010


    session_start();   

    $dir  = (isset($_SESSION['datagrid_export_dir']) && $_SESSION['datagrid_export_dir'] != null) ? $_SESSION['datagrid_export_dir'] : "";
    $file = (isset($_SESSION['datagrid_export_file']) && $_SESSION['datagrid_export_file'] != null) ? $_SESSION['datagrid_export_file'] : "";
    $debug = (isset($_SESSION['datagrid_debug']) && $_SESSION['datagrid_debug'] != null) ? $_SESSION['datagrid_debug'] : "";
   
    // define the appropriate path, relatively to download.php
    // 1. For example: $file_path = "../../".$dir.$file; for following structure
    //          export/
    //          datagrid/
    //              - datagrid.class.php
    //              - scripts/
    //                -- download.php
    //
    // 2. For example: $file_path = "../../admin/".$dir.$file; for following structure
    //          admin/
    //              - export/
    //          datagrid/
    //              - datagrid.class.php
    //              - scripts/
    //                -- download.php
    //
    // 3. For example: $file_path = "../".$dir.$file; for following structure
    //          datagrid/
    //              - export/
    //              - datagrid.class.php
    //              - scripts/
    //                -- download.php
    //
    // 4. For example: $file_path = "../examples/".$dir.$file; for following structure
    //          datagrid/
    //              - examples/
    //                  - export/
    //              - datagrid.class.php
    //              - scripts/
    //                -- download.php

    $file_path = "../".$dir.$file;

    unset($_SESSION['datagrid_export_dir']);
    unset($_SESSION['datagrid_export_file']);
    unset($_SESSION['datagrid_debug']);
   
    // check for hacking attacks
    if(preg_match("/0/", $file) || preg_match("/0/", $dir)){
        echo "Can not find export file! Turn on debug mode to see more info.";
    }
    if ((($file == "export.xml") || ($file == "export.csv") || ($file == "export.pdf")) && @file_exists($file_path))
    {
        // strlen() added for security reasons
        header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
        header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
        header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
        header ("Pragma: no-cache"); // HTTP/1.0
       
        header("Content-type: application/force-download");
        header('Content-Disposition: inline; filename="'.$file.'"');
        header("Content-Transfer-Encoding: Binary");
        header("Content-length: ".filesize($file_path));
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.$file.'"');
        readfile($file_path);
    }
    else
    {
        if($debug){
            echo "Can not find such path: $file_path! Also, check please you have added session_start(); command in your code";
        }else{
            echo "Can not find export file! Turn on debug mode to get more info.";                                         
        }       
    }
    exit(0);

?>




If you would like to see the test area I have been working off of go to
http://www.efscust.com/Boards/PHPDG/examples/edir.php

Please, any help on this would be great. I would really like to get this up and going asap.

administrator
Site Admin
Site Admin
Posts: 5939
Joined: Jan 7th, '09, 23:18
Contact:

Re: Export not working

Postby administrator » Jan 8th, '11, 15:26

What browser you works with?
Do you use ob_start(); ?


Return to “Settings: Printing & Exporting”