Go to the documentation of this file.00001 <?php
00002
00008 class Article_Files extends oxAdminDetails
00009 {
00015 protected $_sThisTemplate = 'article_files.tpl';
00016
00022 protected $_oArticle = null;
00023
00030 public function render()
00031 {
00032 parent::render();
00033
00034 if ( !$this->getConfig()->getConfigParam( 'blEnableDownloads' ) ) {
00035 oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_DISABLED_DOWNLOADABLE_PRODUCTS' );
00036 }
00037 $oArticle = $this->getArticle();
00038
00039 if ( $oArticle->oxarticles__oxparentid->value) {
00040 $oParentArticle = oxNew( 'oxarticle' );
00041 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00042 $oArticle->oxarticles__oxisdownloadable = new oxField( $oParentArticle->oxarticles__oxisdownloadable->value );
00043 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00044 }
00045
00046 return $this->_sThisTemplate;
00047 }
00048
00055 public function save()
00056 {
00057
00058 $aArticleChanges = oxConfig::getParameter('editval');
00059 $oArticle = $this->getArticle();
00060 $oArticle->assign($aArticleChanges);
00061 $oArticle->save();
00062
00063
00064 $aArticleFiles = oxConfig::getParameter('article_files');
00065 if (count($aArticleFiles) > 0) {
00066 foreach ($aArticleFiles as $sArticleFileId => $aArticleFileUpdate) {
00067 $oArticleFile = oxNew('oxFile');
00068 $oArticleFile->load($sArticleFileId);
00069 $aArticleFileUpdate = $this->_processOptions($aArticleFileUpdate);
00070 $oArticleFile->assign($aArticleFileUpdate);
00071 $oArticleFile->save();
00072 }
00073 }
00074 }
00075
00083 public function getArticle($blReset = false)
00084 {
00085 if ($this->_oArticle !== null && !$blReset) {
00086 return $this->_oArticle;
00087 }
00088 $sOxid = $this->getEditObjectId();
00089 $this->_oArticle = oxNewArticle($sOxid);
00090
00091 return $this->_oArticle;
00092 }
00093
00099 public function upload()
00100 {
00101 $myConfig = $this->getConfig();
00102
00103 if ( $myConfig->isDemoShop() ) {
00104 $oEx = oxNew( "oxExceptionToDisplay" );
00105 $oEx->setMessage( 'ARTICLE_EXTEND_UPLOADISDISABLED' );
00106 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
00107
00108 return;
00109 }
00110
00111 $soxId = $this->getEditObjectId();
00112
00113 $aParams = oxConfig::getParameter( "newfile");
00114 $aParams = $this->_processOptions($aParams);
00115 $aNewFile = $this->getConfig()->getUploadedFile( "newArticleFile");
00116
00117 $sExistingFilename = trim(oxConfig::getParameter( "existingFilename"));
00118
00119
00120 $oArticleFile = oxNew( "oxFile" );
00121 $oArticleFile->assign($aParams);
00122
00123 if (!$aNewFile['name'] && !$oArticleFile->oxfiles__oxfilename->value) {
00124 return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_NOFILE' );
00125 }
00126
00127 if ($aNewFile['name']) {
00128 $oArticleFile->oxfiles__oxfilename = new oxField($aNewFile['name'], oxField::T_RAW);
00129 try {
00130 $oArticleFile->processFile( 'newArticleFile' );
00131 } catch (Exception $e) {
00132 return oxRegistry::get("oxUtilsView")->addErrorToDisplay( $e->getMessage() );
00133 }
00134 }
00135
00136
00137 $oArticleFile->oxfiles__oxartid = new oxField($soxId, oxField::T_RAW);
00138 $oArticleFile->save();
00139 }
00140
00146 public function deletefile()
00147 {
00148 $myConfig = $this->getConfig();
00149
00150 if ( $myConfig->isDemoShop() ) {
00151 $oEx = oxNew( "oxExceptionToDisplay" );
00152 $oEx->setMessage( 'ARTICLE_EXTEND_UPLOADISDISABLED' );
00153 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
00154
00155 return;
00156 }
00157
00158 $sArticleId = $this->getEditObjectId();
00159 $sArticleFileId = oxConfig::getParameter('fileid');
00160 $oArticleFile = oxNew('oxFile');
00161 $oArticleFile->load($sArticleFileId);
00162 if ($oArticleFile->hasValidDownloads()) {
00163 return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_DELETING_VALID_FILE' );
00164 }
00165 if ($oArticleFile->oxfiles__oxartid->value == $sArticleId) {
00166 $oArticleFile->delete();
00167 }
00168 }
00169
00177 public function getConfigOptionValue( $iOption )
00178 {
00179 $iOption = ( $iOption < 0 ) ? "" : $iOption;
00180 return $iOption;
00181 }
00182
00190 protected function _processOptions($aParams)
00191 {
00192 if (!is_array($aParams)) {
00193 $aParams = array();
00194 }
00195
00196 if (!isset($aParams["oxfiles__oxdownloadexptime"]) || $aParams["oxfiles__oxdownloadexptime"] == "") {
00197 $aParams["oxfiles__oxdownloadexptime"] = -1;
00198 }
00199 if (!isset($aParams["oxfiles__oxlinkexptime"]) || $aParams["oxfiles__oxlinkexptime"] == "") {
00200 $aParams["oxfiles__oxlinkexptime"] = -1;
00201 }
00202 if (!isset($aParams["oxfiles__oxmaxunregdownloads"]) || $aParams["oxfiles__oxmaxunregdownloads"] == "") {
00203 $aParams["oxfiles__oxmaxunregdownloads"] = -1;
00204 }
00205 if (!isset($aParams["oxfiles__oxmaxdownloads"]) || $aParams["oxfiles__oxmaxdownloads"] == "") {
00206 $aParams["oxfiles__oxmaxdownloads"] = -1;
00207 }
00208 return $aParams;
00209 }
00210 }