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 = $this->getEditObjectId();
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 parent::save();
00062
00063 $oArticle = oxNew( "oxarticle");
00064 if ( $oArticle->load( $this->getEditObjectId() ) ) {
00065 $oArticle->assign( oxConfig::getParameter( "editval") );
00066 oxUtilsFile::getInstance()->processFiles( $oArticle );
00067 $oArticle->save();
00068 }
00069 }
00070
00078 public function deletePicture()
00079 {
00080 $myConfig = $this->getConfig();
00081
00082 if ( $myConfig->isDemoShop() ) {
00083
00084 $oEx = new oxExceptionToDisplay();
00085 $oEx->setMessage( 'ARTICLE_PICTURES_UPLOADISDISABLED' );
00086 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false );
00087
00088 return;
00089 }
00090
00091 $sOxId = $this->getEditObjectId();
00092 $iIndex = oxConfig::getParameter( "masterPicIndex" );
00093
00094 $oArticle = oxNew( "oxarticle" );
00095 $oArticle->load( $sOxId );
00096
00097 if ( $iIndex == "ICO" ) {
00098
00099 $this->_deleteMainIcon( $oArticle );
00100 } elseif ( $iIndex == "TH" ) {
00101
00102 $this->_deleteThumbnail( $oArticle );
00103 } else {
00104 $iIndex = (int) $iIndex;
00105 if ( $iIndex > 0 ) {
00106
00107 $this->_resetMasterPicture( $oArticle, $iIndex, true );
00108 $oArticle->oxarticles__oxpicsgenerated = new oxField( 0 );
00109 }
00110 }
00111
00112 $oArticle->save();
00113 }
00114
00125 protected function _resetMasterPicture( $oArticle, $iIndex, $blDeleteMaster = false )
00126 {
00127 if ( $oArticle->{"oxarticles__oxpic".$iIndex}->value ) {
00128
00129 if ( !$oArticle->isDerived() ) {
00130 $oPicHandler = oxPictureHandler::getInstance();
00131 $oPicHandler->deleteArticleMasterPicture( $oArticle, $iIndex, $blDeleteMaster );
00132 }
00133
00134 if ( $blDeleteMaster ) {
00135
00136 $oArticle->{"oxarticles__oxpic".$iIndex} = new oxField();
00137 }
00138
00139
00140 if ( isset( $oArticle->{"oxarticles__oxzoom".$iIndex} ) ) {
00141 $oArticle->{"oxarticles__oxzoom".$iIndex} = new oxField();
00142 }
00143
00144 if ( $iIndex == 1 ) {
00145 $this->_cleanupCustomFields( $oArticle );
00146 }
00147 }
00148 }
00149
00157 protected function _deleteMainIcon( $oArticle )
00158 {
00159 if ( $oArticle->oxarticles__oxicon->value ) {
00160
00161 if ( !$oArticle->isDerived() ) {
00162 $oPicHandler = oxPictureHandler::getInstance();
00163 $oPicHandler->deleteMainIcon( $oArticle );
00164 }
00165
00166
00167 $oArticle->oxarticles__oxicon = new oxField();
00168 }
00169 }
00170
00178 protected function _deleteThumbnail( $oArticle )
00179 {
00180 if ( $oArticle->oxarticles__oxthumb->value ) {
00181
00182 if ( !$oArticle->isDerived() ) {
00183 $oPicHandler = oxPictureHandler::getInstance();
00184 $oPicHandler->deleteThumbnail( $oArticle );
00185 }
00186
00187
00188 $oArticle->oxarticles__oxthumb = new oxField();
00189 }
00190 }
00191
00199 protected function _getUploadedMasterPicIndexes()
00200 {
00201 $aIndexes = array();
00202 if ( isset( $_FILES['myfile']['name'] ) ) {
00203 $oStr = getStr();
00204
00205 while ( list( $sKey, $sValue ) = each( $_FILES['myfile']['name'] ) ) {
00206 if ( $sValue ) {
00207 $oStr->preg_match( "/^M(\d+)/", $sKey, $aMatches );
00208 if ( isset( $aMatches[1] ) && !in_array( $aMatches[1], $aIndexes ) ) {
00209 $aIndexes[] = $aMatches[1];
00210 }
00211 }
00212 }
00213 }
00214
00215 return $aIndexes;
00216 }
00217
00226 protected function _cleanupCustomFields( $oArticle )
00227 {
00228 $myConfig = $this->getConfig();
00229
00230 $sIcon = $oArticle->oxarticles__oxicon->value;
00231 $sThumb = $oArticle->oxarticles__oxthumb->value;
00232
00233 if ( $sIcon == "nopic.jpg" ) {
00234 $oArticle->oxarticles__oxicon = new oxField();
00235 }
00236
00237 if ( $sThumb == "nopic.jpg" ) {
00238 $oArticle->oxarticles__oxthumb = new oxField();
00239 }
00240 }
00241 }