00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 class t3lib_modSettings {
00126
00127
00128
00129
00130
00131 var $type = 'perm';
00132
00133
00134
00135
00136 var $prefix = '';
00137
00138
00139
00140
00141 var $storeList = array();
00142
00143
00144
00145
00146 var $storedSettings = array();
00147
00148
00149
00150
00151 var $msg = '';
00152
00153
00154
00155
00156
00157 var $formName = 'storeControl';
00158
00159
00160
00161 var $writeDevLog = 0;
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 function init($prefix='', $storeList='') {
00182 $this->prefix = $prefix;
00183 $this->setStoreList($storeList);
00184 $this->type = 'perm';
00185
00186
00187 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_modSettings.php']['writeDevLog']) $this->writeDevLog = TRUE;
00188 if (TYPO3_DLOG) $this->writeDevLog = TRUE;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 function setSessionType($type='ses') {
00198 $this->type = $type;
00199 }
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 function setStoreList($storeList) {
00219 $this->storeList = is_array($storeList) ? $storeList : t3lib_div::trimExplode(',',$storeList,1);
00220
00221 if ($this->writeDevLog) t3lib_div::devLog('Store list:'.implode(',',$this->storeList), 't3lib_modSettings', 0);
00222 }
00223
00224
00225
00226
00227
00228
00229
00230
00231 function addToStoreList($storeList) {
00232 $storeList = is_array($storeList) ? $storeList : t3lib_div::trimExplode(',',$storeList,1);
00233 $this->storeList = array_merge($this->storeList, $storeList);
00234
00235 if ($this->writeDevLog) t3lib_div::devLog('Store list:'.implode(',',$this->storeList), 't3lib_modSettings', 0);
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245 function addToStoreListFromPrefix($prefix='') {
00246 global $SOBE;
00247
00248 $prefix = $prefix ? $prefix : $this->prefix;
00249
00250 foreach ($SOBE->MOD_SETTINGS as $key => $value) {
00251 if (preg_match('/^'.$prefix.'/',$key)) {
00252 $this->storeList[$key]=$key;
00253 }
00254 }
00255
00256 unset($this->storeList[$this->prefix.'_storedSettings']);
00257
00258 if ($this->writeDevLog) t3lib_div::devLog('Store list:'.implode(',',$this->storeList), 't3lib_modSettings', 0);
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 function initStorage() {
00279 global $SOBE;
00280
00281 $storedSettings = unserialize($SOBE->MOD_SETTINGS[$this->prefix.'_storedSettings']);
00282 $this->storedSettings = $this->cleanupStorageArray($storedSettings);
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 function cleanupStorageArray($storedSettings) {
00294
00295 $storedSettings = is_array($storedSettings) ? $storedSettings : array();
00296
00297
00298 foreach($storedSettings as $id => $sdArr) {
00299 if (!is_array($sdArr)) unset($storedSettings[$id]);
00300 if (!is_array($sdArr['data'])) unset($storedSettings[$id]);
00301 if (!trim($sdArr['title'])) $storedSettings[$id]['title'] = '[no title]';
00302 }
00303
00304 return $storedSettings;
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 function compileEntry($data) {
00316 global $SOBE;
00317
00318 $storageData = array();
00319 foreach($this->storeList as $MS_key) {
00320 $storageData[$MS_key] = $SOBE->MOD_SETTINGS[$MS_key];
00321 }
00322 $storageArr = array (
00323 'title' => $data['title'],
00324 'desc' => (string)$data['desc'],
00325 'data' => $storageData,
00326 'user' => NULL,
00327 'tstamp' => $GLOBALS['EXEC_TIME'],
00328 );
00329 $storageArr = $this->processEntry($storageArr);
00330
00331 return $storageArr;
00332 }
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 function getStoredData($storeIndex, $writeArray=array()) {
00343 if ($this->storedSettings[$storeIndex]) {
00344 foreach($this->storeList as $k) {
00345 $writeArray[$k] = $this->storedSettings[$storeIndex]['data'][$k];
00346 }
00347 }
00348 return $writeArray;
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 function processStoreControl($mconfName='') {
00360
00361 $this->initStorage();
00362
00363 $storeControl = t3lib_div::_GP('storeControl');
00364 $storeIndex = $storeControl['STORE'];
00365
00366 $msg = '';
00367 $saveSettings = FALSE;
00368 $writeArray = array();
00369
00370 if (is_array($storeControl)) {
00371 if ($this->writeDevLog) {
00372 t3lib_div::devLog('Store command: '.t3lib_div::arrayToLogString($storeControl), 't3lib_modSettings', 0);
00373 }
00374
00375
00376
00377
00378
00379 if ($storeControl['LOAD'] AND $storeIndex) {
00380 $writeArray = $this->getStoredData($storeIndex, $writeArray);
00381 $saveSettings = TRUE;
00382 $msg = "'".$this->storedSettings[$storeIndex]['title']."' preset loaded!";
00383
00384
00385
00386
00387
00388 } elseif ($storeControl['SAVE']) {
00389 if (trim($storeControl['title'])) {
00390
00391
00392 $newEntry = $this->compileEntry($storeControl);
00393
00394
00395 if (!$storeIndex) {
00396 $storeIndex = t3lib_div::shortMD5($newEntry['title']);
00397 }
00398
00399
00400 $this->storedSettings[$storeIndex] = $newEntry;
00401
00402 $saveSettings = TRUE;
00403 $msg = "'".$newEntry['title']."' preset saved!";
00404
00405 } else {
00406 $msg = 'Please enter a name for the preset!';
00407 }
00408
00409
00410
00411
00412
00413 } elseif ($storeControl['REMOVE'] AND $storeIndex) {
00414
00415 $msg = "'".$this->storedSettings[$storeIndex]['title']."' preset entry removed!";
00416 unset($this->storedSettings[$storeIndex]);
00417
00418 $saveSettings = TRUE;
00419 }
00420
00421
00422 $this->msg = $msg;
00423
00424 if ($saveSettings) {
00425 $this->writeStoredSetting($writeArray, $mconfName);
00426 }
00427
00428 }
00429 return $this->msg;
00430 }
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 function writeStoredSetting($writeArray=array(), $mconfName='') {
00441 global $SOBE;
00442
00443
00444 # $GLOBALS['BE_USER']->pushModuleData($SOBE->MCONF['name'],array());
00445
00446 unset($this->storedSettings[0]);
00447 $this->storedSettings = $this->cleanupStorageArray($this->storedSettings);
00448 $writeArray[$this->prefix.'_storedSettings'] = serialize($this->storedSettings);
00449
00450 $SOBE->MOD_SETTINGS = t3lib_BEfunc::getModuleData($SOBE->MOD_MENU, $writeArray, ($mconfName?$mconfName:$SOBE->MCONF['name']), $this->type);
00451
00452 if ($this->writeDevLog) t3lib_div::devLog('Settings stored:'.$this->msg, 't3lib_modSettings', 0);
00453 }
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472 function getStoreControl($showElements='load,remove,save', $useOwnForm=TRUE) {
00473 global $TYPO3_CONF_VARS;
00474
00475 $showElements = t3lib_div::trimExplode(',', $showElements, 1);
00476
00477 $this->initStorage();
00478
00479
00480 $opt=array();
00481 $opt[] = '<option value="0"> </option>';
00482 foreach($this->storedSettings as $id => $v) {
00483 $opt[] = '<option value="'.$id.'">'.htmlspecialchars($v['title']).'</option>';
00484 }
00485 $storedEntries = count($opt)>1;
00486
00487
00488
00489 $codeTD = array();
00490
00491
00492
00493 if($storedEntries AND (count($showElements))) {
00494
00495
00496 $onChange = 'document.forms[\''.$this->formName.'\'][\'storeControl[title]\'].value= this.options[this.selectedIndex].value!=0 ? this.options[this.selectedIndex].text : \'\';';
00497 $code = '
00498 <select name="storeControl[STORE]" onChange="'.htmlspecialchars($onChange).'">
00499 '.implode('
00500 ', $opt).'
00501 </select>';
00502
00503
00504 if(in_array('load', $showElements)) {
00505 $code.= '
00506 <input type="submit" name="storeControl[LOAD]" value="Load" /> ';
00507 }
00508
00509
00510 if(in_array('remove', $showElements)) {
00511 $code.= '
00512 <input type="submit" name="storeControl[REMOVE]" value="Remove" /> ';
00513 }
00514 $codeTD[] = '<td width="1%">Preset:</td>';
00515 $codeTD[] = '<td nowrap="nowrap">'.$code.' </td>';
00516 }
00517
00518
00519
00520 if(in_array('save', $showElements)) {
00521 $onClick = (!$storedEntries) ? '' : 'if (document.forms[\''.$this->formName.'\'][\'storeControl[STORE]\'].options[document.forms[\''.$this->formName.'\'][\'storeControl[STORE]\'].selectedIndex].value<0) return confirm(\'Are you sure you want to overwrite the existing entry?\');';
00522 $code = '<input name="storeControl[title]" value="" type="text" max="80" width="25"> ';
00523 $code.= '<input type="submit" name="storeControl[SAVE]" value="Save" onClick="'.htmlspecialchars($onClick).'" />';
00524 $codeTD[] = '<td nowrap="nowrap">'.$code.'</td>';
00525 }
00526
00527
00528 $codeTD = implode ('
00529 ', $codeTD);
00530
00531 if (trim($code)) {
00532 $code = '
00533 <!--
00534 Store control
00535 -->
00536 <table border="0" cellpadding="3" cellspacing="0" width="100%">
00537 <tr class="bgColor4">
00538 '.$codeTD.'
00539 </tr>
00540 </table>
00541 ';
00542 }
00543
00544 if ($this->msg) {
00545 $code.= '
00546 <div><strong>'.htmlspecialchars($this->msg).'</strong></div>';
00547 }
00548 #TODO need to add parameters
00549 if ($useOwnForm AND trim($code)) {
00550 $code = '
00551 <form action="' . t3lib_div::getIndpEnv('SCRIPT_NAME') . '" method="post" name="' . $this->formName . '" enctype="' . $TYPO3_CONF_VARS['SYS']['form_enctype'] . '">' . $code . '</form>';
00552 }
00553
00554 return $code;
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574 function processEntry($storageArr) {
00575 return $storageArr;
00576 }
00577 }
00578
00579 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_modSettings.php']) {
00580 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_modSettings.php']);
00581 }
00582
00583 ?>