Categories > OpenTBS general >

Generate multiple documents with only one click

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Amok
Date: 2015-03-06
Time: 10:11

Generate multiple documents with only one click

OpenTBS now it's working for me, but I have a problem: I have an html form and a list of checkboxes so the user can choose one or more documents to generate (all of them are merged with the data retrieved from an unique form). But, if the user choose two or more documents to generate and click the button, once the openTBS-Show() method is called for the first time, it won't execute the code below. It just generates the first document, and ends the execution. And I'm sure i don't have any exit(); on my code.

So... any trick to solve this?
By: Skrol29
Date: 2015-03-06
Time: 16:47

Re: Generate multiple documents with only one click

Hi Amok,

TBS alone (i.e. without OpenTBS) actually exit the script by default when you are using Show(). Some options can change that behavior.

But with TBS + OpenTBS then options OPENTBS_DOWNLOAD and OPENTBS_FILE should not exit the script.

See :
http://www.tinybutstrong.com/manual.php#php_setoption_render
http://www.tinybutstrong.com/opentbs.php?doc#show
By: Amok
Date: 2015-04-09
Time: 10:37

Re: Generate multiple documents with only one click

Thank you for the quick response Skrol, but it isn't working. I've tried using SetOption('render',TBS_OUTPUT) instead of the default value which is TBS_OUTPUT + TBS_EXIT. But it doesn't prevent the script from exiting. Each time the Show() method is executed, the scripts ends. This is not a problem when I want to render only one document, but sometimes I need to render  several of them. I have some checboxes, and I need to render as many documents as selected checboxes.

For example:

function Docs2Generate () {

  IF (CHECKBOX1 IS SELECTED){
   GenDoc("Doc1.odt","Template1.odt","nodebug");
  }

  IF (CHECKBOX2 IS SELECTED){
   GenDoc("Doc2.odt","Template2.odt","nodebug");
  }

  IF (CHECKBOXN IS SELECTED){
   GenDoc("DocN.odt","TemplateN.odt","nodebug");
  }

}

My GenDoc function looks like this:

function GenDoc($filename,$template,$debug) {

   include_once('../librerias/tbs_us/tbs_class.php');
   include_once('../librerias/open_tbs/tbs_plugin_opentbs.php');

   //OpenTBS developer recommendation: prevent from a PHP configuration problem when using mktime() and date()
   if (version_compare(PHP_VERSION,'5.1.0')>=0) {
      if (ini_get('date.timezone')=='') {
         date_default_timezone_set('UTC');
      }
   }

   // create a TBS instance
   $TBS = new clsTinyButStrong;

   //load OpenTBS Plugin
   $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

   //Prevent the script from exiting when method show() is called
   $TBS->SetOption('render',TBS_OUTPUT);

   //Load template
   $TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8);
        
   // Display the intented XML of the current sub-file, and exit.
   if (isset($debug) && ($debug=='current')) $TBS->Plugin(OPENTBS_DEBUG_XML_CURRENT, true);
   // Display information about the document, and exit.
   if (isset($debug) && ($debug=='info'))    $TBS->Plugin(OPENTBS_DEBUG_INFO, true);
   // Tells TBS to display information when the document is merged. No exit.
   if (isset($debug) && ($debug=='show'))    $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW);

   //Render the document
   $TBS->Show(OPENTBS_DOWNLOAD,$filename);
}

It seems that it doesn't matter the value of the render property you set. I tried with SetOption('render',TBS_NOTHING) and it is just the same. It calls Show() method one time, generates the document, and exits the script. Even if I invented values for the render property, such as SetOption('render',NONSENSE) it keeps doing the same...
By: Skrol29
Date: 2015-04-09
Time: 23:35

Re: Generate multiple documents with only one click

You cannot download several files with HTML, only one.
Your script is not ending but only the fist document is given for download by the HTTP reply.
By: Amok
Date: 2015-04-10
Time: 09:02

Re: Generate multiple documents with only one click

Thank you Skrol. You are right, it's not a TBS/Open TBS issue, but an html handicap. Some possible solutions found here: http://stackoverflow.com/questions/2339440/download-multiple-files-with-a-single-action