article_pictures.php
Go to the documentation of this file.00001 <?php
00002
00009 class Article_Pictures extends oxAdminDetails
00010 {
00017 public function render()
00018 {
00019 parent::render();
00020
00021 $this->_aViewData["edit"] = $oArticle = oxNew( "oxarticle");
00022
00023 $soxId = oxConfig::getParameter( 'oxid' );
00024 if ( $soxId != "-1" && isset( $soxId ) ) {
00025
00026 $oArticle->load( $soxId);
00027
00028
00029
00030 if ( $oArticle->oxarticles__oxparentid->value) {
00031 $oParentArticle = oxNew( "oxarticle");
00032 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00033 $this->_aViewData["parentarticle"] = $oParentArticle;
00034 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00035 }
00036 }
00037
00038 $this->_aViewData["iPicCount"] = $this->getConfig()->getConfigParam( 'iPicCount' );
00039
00040 return "article_pictures.tpl";
00041 }
00042
00048 public function save()
00049 {
00050 $myConfig = $this->getConfig();
00051
00052 if ( $myConfig->isDemoShop() ) {
00053
00054 $oEx = new oxExceptionToDisplay();
00055 $oEx->setMessage( 'ARTICLE_PICTURES_UPLOADISDISABLED' );
00056 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false );
00057
00058 return;
00059 }
00060
00061
00062 $soxId = oxConfig::getParameter( "oxid");
00063 $aParams = oxConfig::getParameter( "editval");
00064 $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
00065
00066 $oArticle = oxNew( "oxarticle");
00067 $oArticle->load( $soxId);
00068
00069
00070 $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop");
00071 $myUtilsPic = oxUtilsPic::getInstance();
00072
00073
00074 $this->_deleteMasterPicture( $oArticle, $iIndex );
00075
00076 $oArticle->assign( $aParams );
00077 $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00078
00079
00080 $this->_updateGeneratedPicsAmount( $oArticle );
00081
00082
00083 $this->_cleanupZoomFields( $oArticle );
00084
00085
00086
00087 $iFrom = $this->_getMinUploadedMasterPicIndex();
00088 for ( $i=$iFrom; $i<= $iPicCount; $i++ ) {
00089 $this->_resetMasterPicture( $oArticle, $i );
00090 }
00091
00092 $oArticle->save();
00093 }
00094
00102 public function deletePicture()
00103 {
00104 $myConfig = $this->getConfig();
00105
00106 if ( $myConfig->isDemoShop() ) {
00107
00108 $oEx = new oxExceptionToDisplay();
00109 $oEx->setMessage( 'ARTICLE_PICTURES_UPLOADISDISABLED' );
00110 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false );
00111
00112 return;
00113 }
00114
00115 $sOxId = oxConfig::getParameter( "oxid");
00116 $iIndex = oxConfig::getParameter( "masterPicIndex" );
00117 $iPicCount = $this->getConfig()->getConfigParam( 'iPicCount' );
00118
00119 $oArticle = oxNew( "oxarticle" );
00120 $oArticle->load( $sOxId );
00121
00122
00123 if ( $iIndex == "ICO" ) {
00124 $this->_deleteMainIcon( $oArticle );
00125 }
00126
00127
00128 if ( $iIndex == "TH" ) {
00129 $this->_deleteThumbnail( $oArticle );
00130 }
00131
00132
00133 if ( (int)$iIndex > 0 ) {
00134 $this->_deleteMasterPicture( $oArticle, $iIndex );
00135
00136
00137
00138 for ( $i=$iIndex+1; $i<= $iPicCount; $i++ ) {
00139 $this->_resetMasterPicture( $oArticle, $i );
00140 }
00141
00142
00143 if ( $iIndex > 0 ) {
00144 $oArticle->updateAmountOfGeneratedPictures( $iIndex-1 );
00145 }
00146 }
00147
00148 $oArticle->save();
00149 }
00150
00160 protected function _deleteMasterPicture( $oArticle, $iIndex )
00161 {
00162 if ( $oArticle->{"oxarticles__oxpic".$iIndex}->value ) {
00163
00164 $oPicHandler = oxPictureHandler::getInstance();
00165 $oPicHandler->deleteArticleMasterPicture( $oArticle, $iIndex );
00166
00167
00168 $oArticle->{"oxarticles__oxpic".$iIndex} = new oxField();
00169
00170
00171 if ( isset( $oArticle->{"oxarticles__oxzoom".$iIndex} ) ) {
00172 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00173 }
00174
00175 if ( $iIndex == 1 ) {
00176 $this->_cleanupCustomFields( $oArticle );
00177 }
00178 }
00179 }
00180
00188 protected function _deleteMainIcon( $oArticle )
00189 {
00190 if ( $oArticle->oxarticles__oxicon->value ) {
00191
00192 $oPicHandler = oxPictureHandler::getInstance();
00193 $oPicHandler->deleteMainIcon( $oArticle );
00194
00195
00196 $oArticle->oxarticles__oxicon = new oxField();
00197 }
00198 }
00199
00207 protected function _deleteThumbnail( $oArticle )
00208 {
00209 if ( $oArticle->oxarticles__oxthumb->value ) {
00210
00211 $oPicHandler = oxPictureHandler::getInstance();
00212 $oPicHandler->deleteThumbnail( $oArticle );
00213
00214
00215 $oArticle->oxarticles__oxthumb = new oxField();
00216 }
00217 }
00218
00228 protected function _resetMasterPicture( $oArticle, $iIndex )
00229 {
00230 if ( $oArticle->{"oxarticles__oxpic".$iIndex}->value ) {
00231
00232 $oPicHandler = oxPictureHandler::getInstance();
00233 $oPicHandler->deleteArticleMasterPicture( $oArticle, $iIndex, false );
00234
00235
00236 if ( isset( $oArticle->{"oxarticles__oxzoom".$iIndex} ) ) {
00237 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00238 }
00239
00240 if ( $iIndex == 1 ) {
00241 $this->_cleanupCustomFields( $oArticle );
00242 }
00243 }
00244 }
00245
00246
00254 protected function _updateGeneratedPicsAmount( $oArticle )
00255 {
00256 $iMinUploadedIndex = $this->_getMinUploadedMasterPicIndex();
00257
00258 if ( $iMinUploadedIndex > 0 && $iMinUploadedIndex <= $oArticle->oxarticles__oxpicsgenerated->value ) {
00259 $oArticle->updateAmountOfGeneratedPictures( $iMinUploadedIndex-1 );
00260 }
00261 }
00262
00268 protected function _getMinUploadedMasterPicIndex()
00269 {
00270 if ( isset( $_FILES['myfile']['name'] ) ) {
00271 $iIndex = $this->getConfig()->getConfigParam( 'iPicCount' );
00272 $oStr = getStr();
00273
00274 while ( list( $sKey, $sValue ) = each( $_FILES['myfile']['name'] ) ) {
00275 if ( !empty($sValue) ) {
00276 $oStr->preg_match( "/^M(\d+)/", $sKey, $aMatches );
00277 $iPicIndex = $aMatches[1];
00278 $iIndex = ( $iIndex > $iPicIndex ) ? $iPicIndex : $iIndex;
00279 }
00280 }
00281 }
00282
00283 return (int)$iIndex;
00284 }
00285
00293 protected function _cleanupZoomFields( $oArticle )
00294 {
00295 $myConfig = $this->getConfig();
00296 if ( isset( $_FILES['myfile']['name'] ) ) {
00297 $iIndex = 0;
00298
00299 while ( list( $sKey, $sValue ) = each( $_FILES['myfile']['name'] ) ) {
00300 if ( !empty($sValue) ) {
00301 $iIndex = $this->_getUploadedMasterPicIndex( $sKey );
00302 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00303 }
00304 }
00305 }
00306 }
00307
00316 protected function _cleanupCustomFields( $oArticle )
00317 {
00318 $myConfig = $this->getConfig();
00319
00320 $sIcon = $oArticle->oxarticles__oxicon->value;
00321 $sThumb = $oArticle->oxarticles__oxthumb->value;
00322
00323 if ( $sIcon == "nopic_ico.jpg" ) {
00324 $oArticle->oxarticles__oxicon = new oxField();
00325 }
00326
00327 if ( $sThumb == "nopic.jpg" ) {
00328 $oArticle->oxarticles__oxthumb = new oxField();
00329 }
00330 }
00331
00339 protected function _getUploadedMasterPicIndex( $sFileType )
00340 {
00341 $iPicIndex = 0;
00342
00343 if ( getStr()->preg_match( "/^M(\d+)/", $sFileType, $aMatches ) ) {
00344 $iPicIndex = $aMatches[1];
00345 }
00346
00347 return (int) $iPicIndex;
00348 }
00349 }