A Qcodo based CMS/ecommerce framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.5 KiB

12 years ago
  1. <?php
  2. //TODO: Autoload me ..
  3. require(__QUASI_CONTRIB_CLASSES__ . '/QFileInput.class.php');
  4. /**
  5. * This class provides a dialog pop-up for uploading files.
  6. *
  7. *
  8. *@author Erik Winn <erikwinnmail@yahoo.com>
  9. *
  10. *
  11. * $Id: QFileInputDialog.class.php 1 2008-07-29 06:33:41Z erikwinn $
  12. *@version 0.1
  13. *
  14. *@copyright (C) 2008 by Erik Winn
  15. *@license GPL v.2
  16. This program is free software; you can redistribute it and/or modify
  17. it under the terms of the GNU General Public License as published by
  18. the Free Software Foundation; either version 2 of the License, or
  19. (at your option) any later version.
  20. This program is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. GNU General Public License for more details.
  24. You should have received a copy of the GNU General Public License
  25. along with this program; if not, write to the Free Software
  26. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  27. *
  28. * @package QuasiContrib
  29. * @subpackage Classes
  30. */
  31. class QFileInputDialog extends QDialogBox
  32. {
  33. public $ctlFileInput;
  34. public $lblErrorMessage;
  35. public $btnUpload;
  36. public $btnCancel;
  37. public $objSpinner;
  38. protected $objParentObject;
  39. protected $strFileUploadCallback;
  40. public function __construct($objParentObject, $strFileUploadCallback, $strControlId = null)
  41. {
  42. $this->objParentObject = $objParentObject;
  43. try {
  44. parent::__construct($this->objParentObject, $strControlId);
  45. } catch (QCallerException $objExc) {
  46. $objExc->IncrementOffset();
  47. throw $objExc;
  48. }
  49. $this->strFileUploadCallback = $strFileUploadCallback;
  50. $this->strTemplate = __QUASI_CONTRIB_TEMPLATES__ . '/QFileInputDialog.tpl.php';
  51. $this->blnDisplay = false;
  52. $this->blnMatteClickable = false;
  53. $this->lblErrorMessage = new QLabel($this);
  54. $this->lblErrorMessage->HtmlEntities = false;
  55. $this->ctlFileInput = new QFileInput($this);
  56. $this->btnUpload = new QButton($this);
  57. $this->btnUpload->Text = QApplication::Translate('Upload');
  58. $this->btnUpload->CausesValidation = QCausesValidation::SiblingsOnly;
  59. $this->btnCancel = new QButton($this);
  60. $this->btnCancel->Text = QApplication::Translate('Cancel');
  61. $this->objSpinner = new QWaitIcon($this);
  62. // Events on the Dialog Box Controls
  63. $this->ctlFileInput->AddAction(new QEnterKeyEvent(), new QTerminateAction());
  64. $this->btnUpload->AddAction(new QClickEvent(), new QToggleEnableAction($this->btnUpload));
  65. $this->btnUpload->AddAction(new QClickEvent(), new QToggleEnableAction($this->btnCancel));
  66. $this->btnUpload->AddAction(new QClickEvent(), new QToggleDisplayAction($this->objSpinner));
  67. $this->btnUpload->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnUpload_Click'));
  68. $this->btnCancel->AddAction(new QClickEvent(), new QHideDialogBox($this));
  69. }
  70. /* fixme - figure out how to call this ..
  71. public function Validate()
  72. {
  73. $this->strValidationError = "";
  74. if ($this->ErrorCode != 0)
  75. {
  76. $this->strValidationError = $this->ErrorMessage;
  77. return false;
  78. }
  79. if (! $this->blnRequired )
  80. return true;
  81. if (strlen($this->strFileName) > 0)
  82. return true;
  83. if(strlen( $this->Name ))
  84. $this->strValidationError = _t($this->strName) . ' ' . _t('is required');
  85. else
  86. $this->strValidationError = "Filename is required";
  87. return false;
  88. }*/
  89. public function btnUpload_Click($strFormId, $strControlId, $strParameter)
  90. {
  91. $this->btnUpload->Enabled = true;
  92. $this->btnCancel->Enabled = true;
  93. $this->objSpinner->Display = false;
  94. $strFileControlCallback = $this->strFileUploadCallback;
  95. $this->objParentControl->$strFileControlCallback($strFormId, $strControlId, $strParameter);
  96. }
  97. public function ShowErrorMessage($strErrorMessage=null)
  98. {
  99. if( null !== $strErrorMessage)
  100. $this->lblErrorMessage->Text = $strErrorMessage;
  101. else
  102. $this->lblErrorMessage->Text = $this->ErrorMessage;
  103. $this->ctlFileInput->Focus();
  104. $this->Blink();
  105. }
  106. public function __get($strName)
  107. {
  108. switch ($strName)
  109. {
  110. case 'TempUri':
  111. return $this->ctlFileInput->TempUri;
  112. case 'FileName':
  113. return $this->ctlFileInput->FileName;
  114. case 'Extension':
  115. return $this->ctlFileInput->Extension;
  116. case 'Size':
  117. return $this->ctlFileInput->Size;
  118. case 'MimeType':
  119. return $this->ctlFileInput->MimeType;
  120. case 'ErrorCode':
  121. return $this->ctlFileInput->ErrorCode;
  122. case 'ErrorMessage':
  123. return $this->ctlFileInput->ErrorMessage;
  124. default:
  125. try {
  126. return parent::__get($strName);
  127. } catch (QCallerException $objExc) {
  128. $objExc->IncrementOffset();
  129. throw $objExc;
  130. }
  131. }
  132. }
  133. }
  134. ?>