ATK /handlers/class.atkdocumenthandler.inc

Language PHP Lines 117
MD5 Hash 2bf94aa181ac5e01fa81715ed2037fce
Repository https://github.com/ibuildingsnl/ATK.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
  /**
   * atkDocumentHandler class file
   *
   * @package atk
   * @subpackage handlers
   *
   * @author guido <guido@ibuildings.nl>
   *
   * @copyright (c) 2005 Ibuildings.nl BV
   * @license http://www.achievo.org/atk/licensing/ ATK open source license
   *
   * @version $Revision: 4296 $
   * $Id$
   */

  /**
   * Handler class for the document action
   *
   * @author guido <guido@ibuildings.nl>
   * @package atk
   * @subpackage handlers
   */
  class atkDocumentHandler extends atkActionHandler
  {

    /**
     * The action handler.
     */
    function action_document()
    {
      // Add "Action document" to debug log to indicate this function is entered
      atkdebug("Action document");

      // Load and instantiate the documentwriter
      atkimport("atk.document.atkdocumentwriter");
      $openDocumentWriter = &atkDocumentWriter::getInstance("opendocument");

      // ATKSelector must be available to perform this action
      if ($this->m_postvars["atkselector"] == "")
      {
        atkerror("Selector parameter not available.");
        return false;
      }

      // ATKDocTpl must be available to perform this action
      if (!isset($this->m_postvars["atkdoctpl"]))
      {
        atkerror("atkdoctpl parameter not available.");
        return false;
      }

      $tpl_file = $this->getFilenameForTemplate($this->m_postvars["atkdoctpl"]);

      // Check for invalid characters in filename, modulename and nodename in order to prevent hacking
      if (ereg("[<>\\/|;]", $module . $node . $this->m_postvars["atkdoctpl"]) !== false)
      {
        atkerror("Invalid filename given.");
        return false;
      }

      // Check if the file exists
      if (!is_file($tpl_file))
      {
        atkerror("Given file does not exist.");
        return false;
      }

      // Assign the record variables to the OpenOffice.org DocumentWriter
      if (method_exists($this->m_node, "assignDocumentVars"))
        $this->m_node->assignDocumentVars($openDocumentWriter, $this->m_postvars["atkselector"]);
      else
        $this->assignDocumentVars($openDocumentWriter, $this->m_postvars["atkselector"]);

      // Send the document to the browser
      if (!$openDocumentWriter->display($tpl_file, $this->m_postvars["atkdoctpl"]))
        return false;

      // Halt further execution to prevent atk rendering it's interface causing to corrupt the opendocument file
      exit;
    }

    /**
     * Default document assignment function (assigns the given record and
     * the generic vars)
     *
     * @param atkDocumentWriter $documentWriter DocumentWriter to which the variables should be assigned
     * @param String $selector String containing the selector used to get the document from the database
     */
    function assignDocumentVars(&$documentWriter, $selector)
    {
      // Load the selected record from the database
      $record = $this->m_node->selectDb($selector, "", "", $this->m_viewExcludes, "", "document");

      // Assign the record to the documentWriter
      $documentWriter->assignDocumentSingleRecord($this->m_node, $record[0]);

      // Also assign the generic (date) vars tot the documentWriter
      $documentWriter->assignDocumentGenericVars();
    }

    /**
     * Compose the filename to be used (doctemplatedir/module/node/<docmentfilename)
     *
     * @param String $template
     * @return String
     */
    function getFilenameForTemplate($template)
    {
      $basepath = atkconfig("doctemplatedir", "doctemplates/");
      $module = $this->m_node->m_module;
      $node = $this->m_node->m_type;

      return $basepath  . $module . "/" . $node . "/" . $template;
    }
  }
?>
Back to Top