| 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 | |
|---|
| 25 | require_once( '../inc/header.inc.php' ); |
|---|
| 26 | require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' ); |
|---|
| 27 | require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' ); |
|---|
| 28 | require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' ); |
|---|
| 29 | require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' ); |
|---|
| 30 | bx_import('BxDolDb'); |
|---|
| 31 | bx_import('BxTemplSearchResult'); |
|---|
| 32 | bx_import('BxDolCategories'); |
|---|
| 33 | bx_import('BxDolAdminSettings'); |
|---|
| 34 | |
|---|
| 35 | $aBxSecurityExceptions = array (); |
|---|
| 36 | if (bx_get('pathes') !== false) { |
|---|
| 37 | $aPathes = bx_get('pathes'); |
|---|
| 38 | |
|---|
| 39 | if(is_array($aPathes)) |
|---|
| 40 | for ($i=0; $i<count($aPathes); ++$i) { |
|---|
| 41 | $aBxSecurityExceptions[] = 'POST.pathes.'.$i; |
|---|
| 42 | $aBxSecurityExceptions[] = 'REQUEST.pathes.'.$i; |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | $logged['admin'] = member_auth( 1, true, true ); |
|---|
| 47 | |
|---|
| 48 | function actionAllCategories() { |
|---|
| 49 | $oDb = new BxDolDb(); |
|---|
| 50 | |
|---|
| 51 | // check actions |
|---|
| 52 | if(bx_get('pathes') !== false) { |
|---|
| 53 | $aPathes = bx_get('pathes'); |
|---|
| 54 | |
|---|
| 55 | if(is_array($aPathes) && !empty($aPathes)) |
|---|
| 56 | foreach($_POST['pathes'] as $sValue) { |
|---|
| 57 | list($sCategory, $sId, $sType) = split('%%', $sValue); |
|---|
| 58 | |
|---|
| 59 | if (bx_get('action_disable') !== false) |
|---|
| 60 | $oDb->query("UPDATE `sys_categories` SET `Status` = 'passive' WHERE |
|---|
| 61 | `Category` = '$sCategory' AND `ID` = $sId AND `Type` = '$sType'"); |
|---|
| 62 | else if(bx_get('action_delete') !== false) |
|---|
| 63 | $oDb->query("DELETE FROM `sys_categories` WHERE |
|---|
| 64 | `Category` = '$sCategory' AND `ID` = $sId AND `Type` = '$sType'"); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | $sContent = MsgBox(_t('_Empty')); |
|---|
| 69 | $aModules = array(); |
|---|
| 70 | $oCategories = new BxDolCategories(); |
|---|
| 71 | $oCategories->getTagObjectConfig(); |
|---|
| 72 | |
|---|
| 73 | if (!empty($oCategories->aTagObjects)) |
|---|
| 74 | { |
|---|
| 75 | $sModule = bx_get('module') !== false ? bx_get('module') : ''; |
|---|
| 76 | foreach ($oCategories->aTagObjects as $sKey => $aValue) |
|---|
| 77 | { |
|---|
| 78 | if (!$sModule) |
|---|
| 79 | $sModule = $sKey; |
|---|
| 80 | |
|---|
| 81 | $aModules[] = array( |
|---|
| 82 | 'value' => $sKey, |
|---|
| 83 | 'caption' => _t($aValue['LangKey']), |
|---|
| 84 | 'selected' => $sKey == $sModule ? 'selected="selected"' : '' |
|---|
| 85 | ); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | $sContent = $GLOBALS['oAdmTemplate']->parseHtmlByName('top_block_select.html', array( |
|---|
| 89 | 'name' => _t('_categ_modules'), |
|---|
| 90 | 'bx_repeat:items' => $aModules, |
|---|
| 91 | 'location_href' => BX_DOL_URL_ADMIN . 'categories.php?action=all&module=' |
|---|
| 92 | )); |
|---|
| 93 | |
|---|
| 94 | $aCategories = $oDb->getAll("SELECT * FROM `sys_categories` WHERE `Status` = 'active' AND `Owner` = 0 AND `Type` = '$sModule'"); |
|---|
| 95 | |
|---|
| 96 | if (!empty($aCategories)) |
|---|
| 97 | { |
|---|
| 98 | $aItems = array(); |
|---|
| 99 | $sFormName = 'categories_form'; |
|---|
| 100 | |
|---|
| 101 | foreach($aCategories as $aCategory) |
|---|
| 102 | { |
|---|
| 103 | $aItems[] = array( |
|---|
| 104 | 'name' => $aCategory['Category'], |
|---|
| 105 | 'value' => $aCategory['Category'] . '%%' . $aCategory['ID'] . '%%' . $aCategory['Type'], |
|---|
| 106 | 'title'=> $aCategory['Category'], |
|---|
| 107 | ); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | $sControls = $sControls = BxTemplSearchResult::showAdminActionsPanel($sFormName, array( |
|---|
| 111 | 'action_disable' => _t('_categ_btn_disable'), |
|---|
| 112 | 'action_delete' => _t('_categ_btn_delete') |
|---|
| 113 | ), 'pathes'); |
|---|
| 114 | |
|---|
| 115 | $sContent .= $GLOBALS['oAdmTemplate']->parseHtmlByName('categories_list.html', array( |
|---|
| 116 | 'form_name' => $sFormName, |
|---|
| 117 | 'bx_repeat:items' => $aItems, |
|---|
| 118 | 'controls' => $sControls |
|---|
| 119 | )); |
|---|
| 120 | } |
|---|
| 121 | else |
|---|
| 122 | $sContent .= MsgBox(_t('_Empty')); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | return $sContent; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | function actionPending() |
|---|
| 129 | { |
|---|
| 130 | $oDb = new BxDolDb(); |
|---|
| 131 | $sFormName = 'categories_aprove_form'; |
|---|
| 132 | $aItems = array(); |
|---|
| 133 | |
|---|
| 134 | if(is_array($_POST['pathes']) && !empty($_POST['pathes'])) |
|---|
| 135 | { |
|---|
| 136 | foreach($_POST['pathes'] as $sValue) |
|---|
| 137 | { |
|---|
| 138 | list($sCategory, $sId, $sType) = split('%%', $sValue); |
|---|
| 139 | $oDb->query("UPDATE `sys_categories` SET `Status` = 'active' WHERE |
|---|
| 140 | `Category` = '$sCategory' AND `ID` = $sId AND `Type` = '$sType'"); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | $aCategories = $oDb->getAll("SELECT * FROM `sys_categories` WHERE `Status` = 'passive'"); |
|---|
| 145 | |
|---|
| 146 | if (!empty($aCategories)) |
|---|
| 147 | { |
|---|
| 148 | foreach($aCategories as $aCategory) |
|---|
| 149 | { |
|---|
| 150 | $aItems[] = array( |
|---|
| 151 | 'name' => $aCategory['Category'], |
|---|
| 152 | 'value' => $aCategory['Category'] . '%%' . $aCategory['ID'] . '%%' . $aCategory['Type'], |
|---|
| 153 | 'title'=> $aCategory['Category'] . '(' . $aCategory['Type'] . ')', |
|---|
| 154 | ); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | $aButtons = array( |
|---|
| 158 | 'action_activate' => _t('_categ_btn_activate'), |
|---|
| 159 | ); |
|---|
| 160 | $sControls = BxTemplSearchResult::showAdminActionsPanel($sFormName, $aButtons, 'pathes'); |
|---|
| 161 | |
|---|
| 162 | return $GLOBALS['oAdmTemplate']->parseHtmlByName('categories_list.html', array( |
|---|
| 163 | 'form_name' => $sFormName, |
|---|
| 164 | 'bx_repeat:items' => $aItems, |
|---|
| 165 | 'controls' => $sControls |
|---|
| 166 | )); |
|---|
| 167 | } |
|---|
| 168 | else |
|---|
| 169 | return MsgBox(_t('_Empty')); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | function actionSettings() |
|---|
| 173 | { |
|---|
| 174 | $oDb = new BxDolDb(); |
|---|
| 175 | $iId = $oDb->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name` = 'Categories' LIMIT 1"); |
|---|
| 176 | |
|---|
| 177 | if(!empty($iId)) |
|---|
| 178 | { |
|---|
| 179 | $oSettings = new BxDolAdminSettings($iId); |
|---|
| 180 | |
|---|
| 181 | $mixedResult = ''; |
|---|
| 182 | if(isset($_POST['save']) && isset($_POST['cat'])) |
|---|
| 183 | $mixedResult = $oSettings->saveChanges($_POST); |
|---|
| 184 | |
|---|
| 185 | $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oSettings->getForm())); |
|---|
| 186 | |
|---|
| 187 | if($mixedResult !== true && !empty($mixedResult)) |
|---|
| 188 | $sResult = $mixedResult . $sResult; |
|---|
| 189 | |
|---|
| 190 | return $sResult; |
|---|
| 191 | } |
|---|
| 192 | else |
|---|
| 193 | return MsgBox(_t('_Empty')); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | function getCategoryForm() |
|---|
| 197 | { |
|---|
| 198 | $oCateg = new BxDolCategories(); |
|---|
| 199 | $aTypes = array(); |
|---|
| 200 | $oCateg->getTagObjectConfig(); |
|---|
| 201 | |
|---|
| 202 | foreach ($oCateg->aTagObjects as $sKey => $aValue) |
|---|
| 203 | $aTypes[$sKey] = _t($aValue[$oCateg->aObjFields['lang_key']]); |
|---|
| 204 | |
|---|
| 205 | $aForm = array( |
|---|
| 206 | |
|---|
| 207 | 'form_attrs' => array( |
|---|
| 208 | 'name' => 'category_form', |
|---|
| 209 | 'action' => $_SERVER['REQUEST_URI'], |
|---|
| 210 | 'method' => 'post', |
|---|
| 211 | 'enctype' => 'multipart/form-data', |
|---|
| 212 | ), |
|---|
| 213 | |
|---|
| 214 | 'params' => array ( |
|---|
| 215 | 'db' => array( |
|---|
| 216 | 'table' => 'sys_categories', |
|---|
| 217 | 'submit_name' => 'submit_form' |
|---|
| 218 | ), |
|---|
| 219 | ), |
|---|
| 220 | |
|---|
| 221 | 'inputs' => array( |
|---|
| 222 | |
|---|
| 223 | 'name' => array( |
|---|
| 224 | 'type' => 'text', |
|---|
| 225 | 'name' => 'Category', |
|---|
| 226 | 'value' => isset($aUnit['name']) ? $aUnit['name'] : '', |
|---|
| 227 | 'caption' => _t('_categ_form_name'), |
|---|
| 228 | 'required' => true, |
|---|
| 229 | 'checker' => array ( |
|---|
| 230 | 'func' => 'length', |
|---|
| 231 | 'params' => array(3, 100), |
|---|
| 232 | 'error' => _t('_categ_form_field_name_err'), |
|---|
| 233 | ), |
|---|
| 234 | 'db' => array( |
|---|
| 235 | 'pass' => 'Xss' |
|---|
| 236 | ), |
|---|
| 237 | 'display' => true, |
|---|
| 238 | ), |
|---|
| 239 | 'type' => array( |
|---|
| 240 | 'type' => 'select', |
|---|
| 241 | 'name' => 'Type', |
|---|
| 242 | 'required' => true, |
|---|
| 243 | 'values' => $aTypes, |
|---|
| 244 | 'value' => bx_get('module') !== false ? bx_get('module') : '', |
|---|
| 245 | 'caption' => _t('_categ_form_type'), |
|---|
| 246 | 'attrs' => array( |
|---|
| 247 | 'multiplyable' => false |
|---|
| 248 | ), |
|---|
| 249 | 'display' => true, |
|---|
| 250 | 'db' => array( |
|---|
| 251 | 'pass' => 'Xss' |
|---|
| 252 | ), |
|---|
| 253 | ), |
|---|
| 254 | 'submit' => array ( |
|---|
| 255 | 'type' => 'submit', |
|---|
| 256 | 'name' => 'submit_form', |
|---|
| 257 | 'value' => _t('_Submit'), |
|---|
| 258 | 'colspan' => false, |
|---|
| 259 | ), |
|---|
| 260 | ) |
|---|
| 261 | ); |
|---|
| 262 | |
|---|
| 263 | return new BxTemplFormView($aForm); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | function getAddCategoryForm() |
|---|
| 267 | { |
|---|
| 268 | $oForm = getCategoryForm(); |
|---|
| 269 | $oForm->initChecker(); |
|---|
| 270 | $sResult = ''; |
|---|
| 271 | |
|---|
| 272 | if ($oForm->isSubmittedAndValid()) |
|---|
| 273 | { |
|---|
| 274 | $oDb = new BxDolDb(); |
|---|
| 275 | if ($oDb->getOne("SELECT COUNT(*) FROM `sys_categories` WHERE `Category` = '" . |
|---|
| 276 | $oForm->getCleanValue('Category') . "' AND `ID` = 0 AND `Type` = '" . |
|---|
| 277 | $oForm->getCleanValue('Type') . "'") == 0) |
|---|
| 278 | { |
|---|
| 279 | $aValsAdd = array ( |
|---|
| 280 | 'ID' => 0, |
|---|
| 281 | 'Owner' => 0, |
|---|
| 282 | 'Status' => 'active', |
|---|
| 283 | ); |
|---|
| 284 | |
|---|
| 285 | $oForm->insert($aValsAdd); |
|---|
| 286 | header('Location:' . BX_DOL_URL_ADMIN . 'categories.php?action=all&module=' . $oForm->getCleanValue('Type')); |
|---|
| 287 | } |
|---|
| 288 | else |
|---|
| 289 | $sResult = sprintf(_t('_categ_exist_err'), $oForm->getCleanValue('Category')); |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | return (strlen($sResult) > 0 ? MsgBox($sResult) : '') . |
|---|
| 293 | $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode())); |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | $iNameIndex = 9; |
|---|
| 297 | $aMenu = array( |
|---|
| 298 | 'all' => array( |
|---|
| 299 | 'title' => _t('_categ_all'), |
|---|
| 300 | 'href' => $GLOBALS['site']['url_admin'] . 'categories.php?action=all', |
|---|
| 301 | '_func' => array ('name' => 'actionAllCategories', 'params' => array()), |
|---|
| 302 | ), |
|---|
| 303 | 'pending' => array( |
|---|
| 304 | 'title' => _t('_categ_admin_pending'), |
|---|
| 305 | 'href' => $GLOBALS['site']['url_admin'] . 'categories.php?action=pending', |
|---|
| 306 | '_func' => array ('name' => 'actionPending', 'params' => array()), |
|---|
| 307 | ), |
|---|
| 308 | 'settings' => array( |
|---|
| 309 | 'title' => _t('_categ_admin_settings'), |
|---|
| 310 | 'href' => $GLOBALS['site']['url_admin'] . 'categories.php?action=settings', |
|---|
| 311 | '_func' => array ('name' => 'actionSettings', 'params' => array()), |
|---|
| 312 | ), |
|---|
| 313 | ); |
|---|
| 314 | $sAction = bx_get('action') !== false ? bx_get('action') : 'all'; |
|---|
| 315 | $aMenu[$sAction]['active'] = 1; |
|---|
| 316 | $sContent = call_user_func_array($aMenu[$sAction]['_func']['name'], $aMenu[$sAction]['_func']['params']); |
|---|
| 317 | |
|---|
| 318 | $_page = array( |
|---|
| 319 | 'name_index' => $iNameIndex, |
|---|
| 320 | 'css_name' => array('forms_adv.css', 'settings.css', 'modules.css'), |
|---|
| 321 | 'header' => _t('_Categories'), |
|---|
| 322 | 'header_text' => 'Test title' |
|---|
| 323 | ); |
|---|
| 324 | |
|---|
| 325 | $_page_cont[$iNameIndex]['page_main_code'] = DesignBoxAdmin(_t('_categ_form_add'), getAddCategoryForm()) . |
|---|
| 326 | DesignBoxAdmin($aMenu[$sAction]['title'], $sContent, $aMenu); |
|---|
| 327 | |
|---|
| 328 | PageCodeAdmin(); |
|---|
| 329 | ?> |
|---|