Advertisement
Guest User

OpenTBS

a guest
Aug 15th, 2012
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. // load the TinyButStrong libraries
  2. if (version_compare(PHP_VERSION,'5')<0) {
  3.     include_once('tbs_class_php4.php'); // TinyButStrong template engine for PHP 4
  4. } else {
  5.     include_once('tbs_class_php5.php'); // TinyButStrong template engine
  6. }
  7. // load the OpenTBS plugin
  8. if (file_exists('tbs_plugin_opentbs.php')) {
  9.     include_once('tbs_plugin_opentbs.php');
  10. } else {
  11.     include_once('../tbs_plugin_opentbs.php');
  12. }
  13. $TBS = new clsTinyButStrong; // new instance of TBS
  14. $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load OpenTBS plugin
  15.  
  16. //work with oracle
  17. $conn = oci_connect('hr', 'welcome', 'localhost/XE');
  18. if (!$conn) {
  19.     $e = oci_error();
  20.     trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
  21. }
  22. $stid = oci_parse($conn, 'SELECT department_name FROM departments');
  23. oci_execute($stid);
  24. while (($data = oci_fetch_array($stid, OCI_BOTH))) {
  25.     // Use the uppercase column names for the associative array indices
  26.     // echo $row[0] . " and " . $row['DEPARTMENT_ID']   . " are the same<br>\n";
  27.     // echo $row[1] . " and " . $row['DEPARTMENT_NAME'] . " are the same<br>\n";
  28.     var_dump($data);
  29. }
  30. oci_free_statement($stid);
  31. oci_close($conn);
  32. // Load the template
  33. $TBS->LoadTemplate('example.docx', OPENTBS_ALREADY_UTF8);
  34.  
  35. // Merge data
  36. $TBS->MergeBlock('a,b', $data);
  37.  
  38. // Define the name of the output file
  39. $file_name = str_replace('.','_'.date('Y-m-d').'.',$template);
  40. // Output as a download file (some automatic fields are merged here)
  41. if ($debug==3) { // debug mode 3
  42.     $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW);
  43. } elseif ($suffix==='') {
  44.     // download
  45.     $TBS->Show(OPENTBS_DOWNLOAD, $file_name);
  46. } else {
  47.     // save as file
  48.     $file_name = "example.docx";
  49.     $TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement