Forums

What to do with coding

?
Guest 04 May, 2011
Hey, I've seen the coding which you use for putting a "backup CSV" button on the front-end but I have no clue what to do with it. Can someone please tell me where I have to put the code for it to work?
GreyHead 04 May, 2011
Hi Poepol!,

Which code are you looking at? Normally it would go in the OnSubmit After Email box.

Bob
?
Guest 13 May, 2011
Hey sorry, got quite busy here, didn't have time to check back.

    global $mosConfig_absolute_path, $database, $mosConfig_dbprefix;

       
       
       $formname = $_GET['chronoformname'];
       $database->setQuery( "SELECT id FROM #__chrono_contact WHERE name='".$formname."'" );
       $formid = $database->loadResult();
       $tablename = $mosConfig_dbprefix."chronoforms_".$formid;
       $tables = array( $tablename );
       $result = $database->getTableFields( $tables );
       $table_fields = array_keys($result[$tablename]);
       
       $database->setQuery( "SELECT * FROM ".$tablename."" );
       $datarows = $database->loadObjectList();
       
       $titcol = 0;
       foreach($table_fields as $table_field){
          if($titcol){$csvline .=",";}
          $csvline .= $table_field;
          $titcol++;
       }
       $csvline .="\n";
             
       $datacol = 0;
       $rowcount = 1;
       foreach($datarows as $datarow){
          foreach($table_fields as $table_field){
             if($datacol){$csvline .=",";}
             $csvline .= '"'.addslashes($datarow->$table_field).'"';
             $datacol++;
          }
          $csvline .="\n";
          $datacol = 0;
          $rowcount++;
       }
       
       if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
          $UserBrowser = "Opera";
       }
       elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
          $UserBrowser = "IE";
       } else {
          $UserBrowser = '';
       }
       $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
       @ob_end_clean();
       ob_start();

       header('Content-Type: ' . $mime_type);
       header('Expires: ' . gmdate('D, d M Y H:i:«»s') . ' GMT');

       if ($UserBrowser == 'IE') {
          header('Content-Disposition: inline; filename="' . "ChronoForms - ".$formname." - ".date("j_n_Y"«»).'.csv"');
          header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
          header('Pragma: public');
       }
       else {
          header('Content-Disposition: attachment; filename="' . "ChronoForms - ".$formname." - ".date("j_n_Y"«»).'.csv"');
          header('Pragma: no-cache');
       }
       print $csvline;
       exit();


That coding🙂. When I put it directly into the place you mentioned it doesn't do anything really.

What I did is use the form wizard to create a form which has a button on it with the name submit. When I hit the button nothing happens, it takes me from the article it was posted in to a page with this url http://(website adress)/index.php?option=com_chronocontact&task=send&chronoformname=download&Itemid=15. Nothing happens and I'm left with a blank article on my website with nothing in it.

After the code there failed, I tried the "Backup" code and the "Backup CSV" code from the admin.chronocontact.php. The same results, I then thought it might be because in the SQL statements it calls tables that don't exist so I changed some around, (not really knowing what I'm doing). Still same thing, I just get a page with a blank article.

Am I doing something wrong or what's going on? I take it I am missing something, as I have no experience with PHP. I only managed to change the SQL statements slightly by having a little coding experience in Delphi and Access DB linking.

So please any help would be much appreciated.
GreyHead 13 May, 2011
Hi Poepol!,

That looks like Joomla! 1.0 code. Which versions of Joomla! & ChronoForms are you using.

Bob
?
Guest 15 May, 2011
1.5.14, not sure about the chronoforms.

Though I have found another way to get a link for downloading the table from front-end. I used SQL 2 Excel plugin and just wrote the SQL query, it was very straight forward. hehe.

Thanks for the quick reply's I appreciate it, but I have found a solution so don't worry. One day I'll know php enough to do it the the way you suggested, which is probably the beter way, for now I will use the SQL 2 Excel plugin.🙂

Thx for support.
This topic is locked and no more replies can be posted.