Question regarding CSV files and information gathering.

cb1 29 Feb, 2012
I'm on a Joomla 1.5.23 site using Chronoforms 4.0 RC3.11.

My client wants to gather the csv output daily.

We have form output going to a CSV file. That part works.

However - we want to know if the CSV can hold ALL the entries for one day. Or if they have to gather each CSV generated. One csv output with each line representing one applicant.

Any help is appreciated.

thanks!
GreyHead 29 Feb, 2012
Hi cb1,

There's a WHERE box in the CSV Export action that you can use to specify which records to export. Save the data to a table and export what you need.

A fixed one day will not work for weekends and holidays so I'd add code to the exporter to set an 'exported' marker in the saved record and then let the export put all the unmarked records into the CSV file.

Bob
cb1 29 Feb, 2012
They don't want to have to manually pull the CSV's.

They want to write a hook that goes to the directory and grabs a single days report - say, at 12:05am the following morning.

And they want it all in one report as opposed to separate.

Sorry if I'm redundant - just want to make sure we re talking apples to apples here.

Let me know.
GreyHead 29 Feb, 2012
Hi cb1,

Then I think that you need to have the CSV save you've written add to the exisitng file and let their 'hook' delete it when it's hooked.

Personally I'd go the other way and use a cron job to do the save and send it to them. But they are the client . . .

Bob
cb1 29 Feb, 2012
How do I get an individual file to "add to the existing file?" Is that a setting? Or code? (I have no idea how to do it)
GreyHead 29 Feb, 2012
Hi cb1,

What code are you using to create the CSV file now?

Bob
cb1 01 Mar, 2012
I'm using the Wizard Edit for the form.

And this code on a separate form - though I am not sure how it applies exactly.

    <?php
    global $mainframe;
       $database =& JFactory::getDBO();

       include_once JPATH_BASE.'/components/com_chronocontact/excelwriter/'."Writer.php";
       //echo $_POST['formid'];
       /*$formid = JRequest::getVar( 'formid', array(), 'post', 'array');
       $database->setQuery( "SELECT name FROM #__chrono_contact WHERE id='".$formid[0]."'" );
       $formname = $database->loadResult();*/
       
       $tablename = '#__chronoforms_data_NEW_HR_Application_1';
       $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 - ".$tablename." - ".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 - ".$tablename." - ".date("j_n_Y").'.csv"');
          header('Pragma: no-cache');
       }
       print $csvline;
       exit();
    ?>
cb1 06 Mar, 2012
Hey greyhead,

Am I providing the wrong information you are looking for?

Bottom line is my client should be able to pull the CSV each night woith a script, but needs to have a new CSV to start the next day with.

He can't have this one CSV there all the time with a months full of previous entries still on it.

In his own words: "The biggest issue I would think would be making certain that you’re only populating the file with data from that day and not from the “beginning of time” as it were..."

Not understanding how this all works - I need some help in if what he is asking is possible.
GreyHead 06 Mar, 2012
Hi cb1,

Well, the code you've posted doesn't save the file it just creates it for immediate download. I'm not sure how that helps you.

Sure, what he's asking is possible, I've given you a couple of ways to do it. From what you;ve said so far I'd schedule a couple of cron jobs, one half an dhour before the pickup to place the file in a colder and a second half and hour after that to clean up and delete it. It would be a bit easier if you could send the client the file at a fixed time.

Bob
cb1 06 Mar, 2012
1 - I am not sure what a cron job is - but is that something I would initiate through Chronoforms?

2 - I am understanding that deleting the csv would force it to not start over from square 1 again with all previous applicants.
This topic is locked and no more replies can be posted.