| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | // TODO: remake according to new design and principles, site setup part leave in admin and remake other functionality move to user part |
|---|
| 4 | |
|---|
| 5 | /*************************************************************************** |
|---|
| 6 | * Dolphin Smart Community Builder |
|---|
| 7 | * ----------------- |
|---|
| 8 | * begin : Mon Mar 23 2006 |
|---|
| 9 | * copyright : (C) 2006 BoonEx Group |
|---|
| 10 | * website : http://www.boonex.com/ |
|---|
| 11 | * This file is part of Dolphin - Smart Community Builder |
|---|
| 12 | * |
|---|
| 13 | * Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License. |
|---|
| 14 | * http://creativecommons.org/licenses/by/3.0/ |
|---|
| 15 | * |
|---|
| 16 | * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 17 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 18 | * See the Creative Commons Attribution 3.0 License for more details. |
|---|
| 19 | * You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin, |
|---|
| 20 | * see license.txt file; if not, write to marketing@boonex.com |
|---|
| 21 | ***************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | define('BX_SECURITY_EXCEPTIONS', true); |
|---|
| 24 | $aBxSecurityExceptions = array( |
|---|
| 25 | 'POST.content_text', |
|---|
| 26 | 'REQUEST.content_text', |
|---|
| 27 | ); |
|---|
| 28 | |
|---|
| 29 | require_once( '../inc/header.inc.php' ); |
|---|
| 30 | |
|---|
| 31 | $GLOBALS['iAdminPage'] = 1; |
|---|
| 32 | |
|---|
| 33 | require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' ); |
|---|
| 34 | require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' ); |
|---|
| 35 | require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' ); |
|---|
| 36 | require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' ); |
|---|
| 37 | bx_import('BxDolAdminSettings'); |
|---|
| 38 | |
|---|
| 39 | $logged['admin'] = member_auth( 1, true, true ); |
|---|
| 40 | |
|---|
| 41 | //--- Process submit ---// |
|---|
| 42 | $mixedResultLogo = ''; |
|---|
| 43 | $mixedResultPromo = ''; |
|---|
| 44 | |
|---|
| 45 | $oSettings = new BxDolAdminSettings(7); |
|---|
| 46 | |
|---|
| 47 | //--- Logo uploading ---// |
|---|
| 48 | if(isset($_POST['upload']) && isset($_FILES['new_file'])) |
|---|
| 49 | $mixedResultLogo = setLogo($_POST, $_FILES); |
|---|
| 50 | |
|---|
| 51 | //--- Promo image uploading ---// |
|---|
| 52 | if(isset($_POST['save_image']) && isset($_FILES['browse_image'])) { |
|---|
| 53 | setParam('enable_flash_promo', ($_POST['type'] == 'image' ? 'on' : '')); |
|---|
| 54 | |
|---|
| 55 | $mixedResultPromo = setPromoImage($_FILES); |
|---|
| 56 | } |
|---|
| 57 | //--- Promo image deleting ---// |
|---|
| 58 | if (!empty($_GET['delete'])) { |
|---|
| 59 | $sFile = process_pass_data( $_GET['delete'] ); |
|---|
| 60 | |
|---|
| 61 | $sFile = str_replace('\\', '', $sFile); |
|---|
| 62 | $sFile = str_replace('/', '', $sFile); |
|---|
| 63 | |
|---|
| 64 | $bResult = @unlink($dir['imagesPromo'] . $sFile) && @unlink($dir['imagesPromo'] . 'original/' . $sFile); |
|---|
| 65 | |
|---|
| 66 | if(!$bResult) |
|---|
| 67 | $mixedResultPromo = '_adm_txt_settings_file_cannot_delete'; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | //--- Site's settings saving ---// |
|---|
| 71 | if(isset($_POST['save']) && isset($_POST['cat'])) { |
|---|
| 72 | $sResult = $oSettings->saveChanges($_POST); |
|---|
| 73 | } |
|---|
| 74 | //--- Promo text saving ---// |
|---|
| 75 | if(isset($_POST['save_text']) && isset($_POST['content_text'])) { |
|---|
| 76 | setParam('enable_flash_promo', ($_POST['type'] == 'text' ? '' : 'on')); |
|---|
| 77 | setParam('custom_promo_code', process_db_input($_POST['content_text'], BX_TAGS_VALIDATE)); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | $iNameIndex = 4; |
|---|
| 81 | $_page = array( |
|---|
| 82 | 'name_index' => $iNameIndex, |
|---|
| 83 | 'css_name' => array('forms_adv.css', 'settings.css'), |
|---|
| 84 | 'header' => _t('_adm_page_cpt_settings') |
|---|
| 85 | ); |
|---|
| 86 | $_page_cont[$iNameIndex] = array( |
|---|
| 87 | 'page_code_settings' => DesignBoxAdmin(_t('_adm_box_cpt_settings_main'), $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oSettings->getForm()))), |
|---|
| 88 | 'page_code_logo' => PageCodeLogo($mixedResultLogo), |
|---|
| 89 | 'page_code_promo' => PageCodePromo($mixedResultPromo) |
|---|
| 90 | ); |
|---|
| 91 | |
|---|
| 92 | PageCodeAdmin(); |
|---|
| 93 | |
|---|
| 94 | function PageCodePromo($mixedResultPromo) { |
|---|
| 95 | $aFormImage = array( |
|---|
| 96 | 'form_attrs' => array( |
|---|
| 97 | 'id' => 'adm-settings-form-promo-image', |
|---|
| 98 | 'name' => 'adm-settings-form-promo-image', |
|---|
| 99 | 'action' => $GLOBALS['site']['url_admin'] . 'basic_settings.php', |
|---|
| 100 | 'method' => 'post', |
|---|
| 101 | 'enctype' => 'multipart/form-data' |
|---|
| 102 | ), |
|---|
| 103 | 'params' => array(), |
|---|
| 104 | 'inputs' => array( |
|---|
| 105 | 'type' => array( |
|---|
| 106 | 'type' => 'hidden', |
|---|
| 107 | 'name' => 'type', |
|---|
| 108 | 'value' => 'image', |
|---|
| 109 | ), |
|---|
| 110 | 'content_text' => array( |
|---|
| 111 | 'type' => 'custom', |
|---|
| 112 | 'caption' => _t('_adm_txt_settings_promo_uploaded'), |
|---|
| 113 | 'content' => getPromoImages(), |
|---|
| 114 | ), |
|---|
| 115 | 'browse_image' => array( |
|---|
| 116 | 'type' => 'file', |
|---|
| 117 | 'name' => 'browse_image', |
|---|
| 118 | 'caption' => _t('_adm_txt_settings_promo_browse'), |
|---|
| 119 | 'value' => '', |
|---|
| 120 | ), |
|---|
| 121 | 'save_image' => array( |
|---|
| 122 | 'type' => 'submit', |
|---|
| 123 | 'name' => 'save_image', |
|---|
| 124 | 'value' => _t("_adm_btn_settings_save"), |
|---|
| 125 | ) |
|---|
| 126 | ) |
|---|
| 127 | ); |
|---|
| 128 | $oFormImage = new BxTemplFormView($aFormImage); |
|---|
| 129 | |
|---|
| 130 | $aFormText = array( |
|---|
| 131 | 'form_attrs' => array( |
|---|
| 132 | 'id' => 'adm-settings-form-promo-text', |
|---|
| 133 | 'name' => 'adm-settings-form-promo-text', |
|---|
| 134 | 'action' => $GLOBALS['site']['url_admin'] . 'basic_settings.php', |
|---|
| 135 | 'method' => 'post', |
|---|
| 136 | 'enctype' => 'multipart/form-data' |
|---|
| 137 | ), |
|---|
| 138 | 'params' => array(), |
|---|
| 139 | 'inputs' => array( |
|---|
| 140 | 'type' => array( |
|---|
| 141 | 'type' => 'hidden', |
|---|
| 142 | 'name' => 'type', |
|---|
| 143 | 'value' => 'text', |
|---|
| 144 | ), |
|---|
| 145 | 'content_text' => array( |
|---|
| 146 | 'type' => 'textarea', |
|---|
| 147 | 'name' => 'content_text', |
|---|
| 148 | 'caption' => '', |
|---|
| 149 | 'value' => stripslashes(getParam('custom_promo_code')), |
|---|
| 150 | 'colspan' => true, |
|---|
| 151 | 'html' => 2, |
|---|
| 152 | 'db' => array ( |
|---|
| 153 | 'pass' => 'XssHtml', |
|---|
| 154 | ), |
|---|
| 155 | ), |
|---|
| 156 | 'save_text' => array( |
|---|
| 157 | 'type' => 'submit', |
|---|
| 158 | 'name' => 'save_text', |
|---|
| 159 | 'value' => _t("_adm_btn_settings_save"), |
|---|
| 160 | ) |
|---|
| 161 | ) |
|---|
| 162 | ); |
|---|
| 163 | $oFormText = new BxTemplFormView($aFormText); |
|---|
| 164 | |
|---|
| 165 | $bPromoImage = getParam('enable_flash_promo') == 'on'; |
|---|
| 166 | $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('promo.html', array( |
|---|
| 167 | 'checked_image' => $bPromoImage ? 'checked="checked"' : '', |
|---|
| 168 | 'checked_text' => !$bPromoImage ? 'checked="checked"' : '', |
|---|
| 169 | 'style_image' => $bPromoImage ? '' : 'display:none;', |
|---|
| 170 | 'style_text' => !$bPromoImage ? '' : 'display:none;', |
|---|
| 171 | 'content_image' => $oFormImage->getCode(), |
|---|
| 172 | 'content_text' => $oFormText->getCode() |
|---|
| 173 | )); |
|---|
| 174 | |
|---|
| 175 | return DesignBoxAdmin(_t('_adm_box_cpt_promo'), $sResult); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | function PageCodeLogo($mixedResultLogo) { |
|---|
| 179 | $aForm = array( |
|---|
| 180 | 'form_attrs' => array( |
|---|
| 181 | 'id' => 'adm-settings-form-logo', |
|---|
| 182 | 'name' => 'adm-settings-form-logo', |
|---|
| 183 | 'action' => $GLOBALS['site']['url_admin'] . 'basic_settings.php', |
|---|
| 184 | 'method' => 'post', |
|---|
| 185 | 'enctype' => 'multipart/form-data' |
|---|
| 186 | ), |
|---|
| 187 | 'params' => array(), |
|---|
| 188 | 'inputs' => array( |
|---|
| 189 | 'upload_header_beg' => array( |
|---|
| 190 | 'type' => 'block_header', |
|---|
| 191 | 'caption' => _t('_adm_txt_settings_logo_header'), |
|---|
| 192 | 'collapsable' => false, |
|---|
| 193 | 'collapsed' => false |
|---|
| 194 | ), |
|---|
| 195 | 'old_file' => array( |
|---|
| 196 | 'type' => 'custom', |
|---|
| 197 | 'content' => getMainLogo(), |
|---|
| 198 | 'colspan' => true |
|---|
| 199 | ), |
|---|
| 200 | 'new_file' => array( |
|---|
| 201 | 'type' => 'file', |
|---|
| 202 | 'name' => 'new_file', |
|---|
| 203 | 'caption' => _t('_adm_txt_settings_logo_upload'), |
|---|
| 204 | 'value' => '', |
|---|
| 205 | ), |
|---|
| 206 | 'resize_header_beg' => array( |
|---|
| 207 | 'type' => 'block_header', |
|---|
| 208 | 'caption' => _t('_adm_txt_settings_resize_header'), |
|---|
| 209 | 'collapsable' => false, |
|---|
| 210 | 'collapsed' => false |
|---|
| 211 | ), |
|---|
| 212 | 'resize' => array( |
|---|
| 213 | 'type' => 'checkbox', |
|---|
| 214 | 'name' => 'resize', |
|---|
| 215 | 'caption' => _t('_adm_txt_settings_resize_enable'), |
|---|
| 216 | 'value' => 'yes', |
|---|
| 217 | 'checked' => true |
|---|
| 218 | ), |
|---|
| 219 | 'new_width' => array( |
|---|
| 220 | 'type' => 'text', |
|---|
| 221 | 'name' => 'new_width', |
|---|
| 222 | 'caption' => _t('_adm_txt_settings_resize_width'), |
|---|
| 223 | 'value' => '64' |
|---|
| 224 | ), |
|---|
| 225 | 'new_height' => array( |
|---|
| 226 | 'type' => 'text', |
|---|
| 227 | 'name' => 'new_height', |
|---|
| 228 | 'caption' => _t('_adm_txt_settings_resize_height'), |
|---|
| 229 | 'value' => '64' |
|---|
| 230 | ), |
|---|
| 231 | 'resize_header_end' => array( |
|---|
| 232 | 'type' => 'block_end' |
|---|
| 233 | ), |
|---|
| 234 | 'upload' => array( |
|---|
| 235 | 'type' => 'submit', |
|---|
| 236 | 'name' => 'upload', |
|---|
| 237 | 'value' => _t("_adm_btn_settings_upload"), |
|---|
| 238 | ) |
|---|
| 239 | ) |
|---|
| 240 | ); |
|---|
| 241 | |
|---|
| 242 | $oForm = new BxTemplFormView($aForm); |
|---|
| 243 | $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode())); |
|---|
| 244 | |
|---|
| 245 | if($mixedResultLogo !== true && !empty($mixedResultLogo)) |
|---|
| 246 | $sResult = MsgBox(_t($mixedResultLogo), 3) . $sResult; |
|---|
| 247 | |
|---|
| 248 | return DesignBoxAdmin(_t('_adm_box_cpt_logo'), $sResult); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | function setLogo(&$aData, &$aFile) { |
|---|
| 252 | global $dir; |
|---|
| 253 | |
|---|
| 254 | $aFileInfo = getimagesize($aFile['new_file']['tmp_name']); |
|---|
| 255 | if(empty($aFileInfo)) |
|---|
| 256 | return '_adm_txt_settings_file_not_image'; |
|---|
| 257 | |
|---|
| 258 | $sExt = ''; |
|---|
| 259 | switch( $aFileInfo['mime'] ) { |
|---|
| 260 | case 'image/jpeg': $sExt = 'jpg'; break; |
|---|
| 261 | case 'image/gif': $sExt = 'gif'; break; |
|---|
| 262 | case 'image/png': $sExt = 'png'; break; |
|---|
| 263 | } |
|---|
| 264 | if(empty($sExt)) |
|---|
| 265 | return '_adm_txt_settings_file_wrong_format'; |
|---|
| 266 | |
|---|
| 267 | $sFileName = mktime() . '.' . $sExt; |
|---|
| 268 | $sFilePath = $dir['mediaImages'] . $sFileName; |
|---|
| 269 | if(!move_uploaded_file($aFile['new_file']['tmp_name'], $sFilePath)) |
|---|
| 270 | return '_adm_txt_settings_file_cannot_move'; |
|---|
| 271 | |
|---|
| 272 | if(!empty($aData['resize'])) { |
|---|
| 273 | $iWidth = (int)$aData['new_width']; |
|---|
| 274 | $iHeight = (int)$aData['new_height']; |
|---|
| 275 | if($iWidth <= 0 || $iHeight <= 0) |
|---|
| 276 | return '_adm_txt_settings_logo_wrong_size'; |
|---|
| 277 | |
|---|
| 278 | if(imageResize($sFilePath, $sFilePath, $iWidth, $iHeight) != IMAGE_ERROR_SUCCESS) |
|---|
| 279 | return '_adm_txt_settings_image_cannot_resize'; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | @unlink($dir['mediaImages'] . getParam('sys_main_logo')); |
|---|
| 283 | setParam('sys_main_logo', $sFileName); |
|---|
| 284 | |
|---|
| 285 | return true; |
|---|
| 286 | } |
|---|
| 287 | function getPromoImages() { |
|---|
| 288 | global $site; |
|---|
| 289 | |
|---|
| 290 | $aFiles = getPromoImagesArray(); |
|---|
| 291 | if(empty($aFiles)) |
|---|
| 292 | return MsgBox(_t('_Empty')); |
|---|
| 293 | |
|---|
| 294 | $aResult = array(); |
|---|
| 295 | foreach($aFiles as $sFile) { |
|---|
| 296 | $aResult[] = array( |
|---|
| 297 | 'delete_url' => $GLOBALS['site']['url_admin'] . 'basic_settings.php?delete=' . urlencode($sFile), |
|---|
| 298 | 'title' => $sFile |
|---|
| 299 | ); |
|---|
| 300 | } |
|---|
| 301 | return $GLOBALS['oAdmTemplate']->parseHtmlByName('promo_images.html', array( |
|---|
| 302 | 'bx_repeat:images' => $aResult, |
|---|
| 303 | 'images_url' => $site['imagesPromo'] |
|---|
| 304 | )); |
|---|
| 305 | } |
|---|
| 306 | function setPromoImage(&$aFile) { |
|---|
| 307 | global $dir; |
|---|
| 308 | |
|---|
| 309 | $aFileInfo = getimagesize($aFile['browse_image']['tmp_name']); |
|---|
| 310 | if(empty($aFileInfo)) |
|---|
| 311 | return '_adm_txt_settings_file_not_image'; |
|---|
| 312 | |
|---|
| 313 | $sExt = ''; |
|---|
| 314 | switch( $aFileInfo['mime'] ) { |
|---|
| 315 | case 'image/jpeg': $sExt = 'jpg'; break; |
|---|
| 316 | case 'image/gif': $sExt = 'gif'; break; |
|---|
| 317 | case 'image/png': $sExt = 'png'; break; |
|---|
| 318 | } |
|---|
| 319 | if(empty($sExt)) |
|---|
| 320 | return '_adm_txt_settings_file_wrong_format'; |
|---|
| 321 | |
|---|
| 322 | $sFileName = $aFile['browse_image']['name']; |
|---|
| 323 | $sFilePath = $dir['imagesPromo'] . 'original/' . $sFileName; |
|---|
| 324 | if(!move_uploaded_file($aFile['browse_image']['tmp_name'], $sFilePath)) |
|---|
| 325 | return '_adm_txt_settings_file_cannot_move'; |
|---|
| 326 | |
|---|
| 327 | ResizeAllPromos(); |
|---|
| 328 | return true; |
|---|
| 329 | } |
|---|
| 330 | ?> |
|---|