Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/VariableManager/VariableSetter.php - 88 lines - 3790 bytes - Summary - Text - Print

   1  <?php
   2  
   3  class VariableSetter extends App {
   4      function dispatch() {
   5          $variables = explode("\r\n", $this->settingsVars['availablevals']);
   6          if(isset($this->httpVars['variname'])) {
   7              if(T_USER != '')
   8                  $_SESSION['caravel_variables'][$this->settingsVars['varname']] = $variables[$this->httpVars['variname']];
   9              else {
  10                  setcookie('variname' . $this->settingsVars['varname'], $this->httpVars['variname']);                    
  11                  $_SESSION['caravel_variables'][$this->settingsVars['varname']] = $variables[$this->httpVars['variname']];    
  12              }    
  13          } else if(isset($_COOKIE['variname' . $this->settingsVars['varname']])) {
  14              $_SESSION['caravel_variables'][$this->settingsVars['varname']] = $variables[$_COOKIE['variname' . $this->settingsVars['varname']]];
  15          }         
  16  
  17          // return configuration/editing screen if we're in that mode
  18          if ( isset($this->httpVars['cv_submit'])) {
  19              // close window if necessary
  20              $submit = str_replace('&amp;', '&', $this->httpVars['cv_submit']);
  21              if (T_SINGLE_BLOCK and ($submit == 'Save & Preview' or $submit == 'Save & Close'))
  22                  return Utility::getCloseRefreshJavascript();
  23              else if(T_SINGLE_BLOCK and ($submit == 'Save & Return'))
  24                  return Utility::getCloseRefreshJavascript('' , true, false);
  25          }
  26  
  27          if ($this->edit && $this->can('config')) {
  28              if (method_exists($this, 'getConfig'))
  29                  return $this->getConfig();
  30              else
  31                  return $this->getContent();
  32          }
  33  
  34          return $this->getContent();
  35      }
  36    
  37      function onSave() {
  38          $this->settingsVars['varname'] = $this->httpVars['varname'];
  39          $this->settingsVars['availablevals'] = $this->httpVars['availablevals'];
  40          $this->saveSettings($this->settingsVars);
  41      }
  42      
  43      function getHeader() {
  44      
  45      }
  46      
  47      function getContent() {
  48          if(isset($this->settingsVars['varname']) && $this->settingsVars['availablevals'] != "") {
  49              $variables = explode("\r\n", $this->settingsVars['availablevals']);
  50              $f = FormWidget::init('', 'form.nonsettings.tpl.html');
  51              $f->name('vareditform');
  52              $f->action = $this->linktoself();
  53              $loc = array_search($_SESSION['caravel_variables'][$this->settingsVars['varname']], $variables);
  54              $f->dropdown('variname', $variables, $loc, '', array('class' => 'variablesetter', 'id' => $this->paramName('vset'), 'onchange' => 'document.vareditform.submit();'));
  55              return $f->get();
  56          }
  57      }
  58      
  59  	function getConfig() {
  60          $variables = array();
  61          foreach($this->section->siteCVGlobalVars as $varname => $vararr) {
  62              $variables[$varname] = $varname; 
  63          }
  64      
  65          $f = FormWidget::init('', 'form.nonsettings.tpl.html');
  66          $f->name('vareditform');
  67          $f->action = $this->linktoself();
  68          
  69          $f->html(Widget::getWizardHelp("Choose a global variable and list the options that will be available to the user, separated by a line break."));
  70          $f->html('<div class="cv_form">');
  71          $f->html('<div style="float: left;padding-top: 1px;">');
  72          $f->dropdown('varname', $variables, $this->settingsVars['varname'], '');
  73          $f->html('</div>');
  74          $f->html('<div style="float: left; padding-left: 4px;">');
  75          $f->textarea('availablevals', $this->settingsVars['availablevals'], 3, 30, array('style' => 'width: 50%;'));
  76          $f->html('</div>');
  77          
  78          $f->html('<div style="clear: both; float: right;padding-top: 10px;">');
  79          $f->defaultButtons();
  80          $f->html('</div>');
  81          $f->html('</div>');
  82          
  83          return $f->get();
  84          
  85      }
  86  }
  87      
  88  ?>

title

Description

title

Description

title

Description

title

title

Body