Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_action_set_session_var.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/cms/form/form_action/form_action.inc';
19 
20 require_once SQ_FUDGE_PATH.'/general/general.inc';
21 
36 {
37 
38 
43  function __construct()
44  {
45  parent::__construct();
46 
47  }//end constructor
48 
49 
55  public static function paintInlineInterface(Form $form, $settings, Backend_Outputter $o, $prefix)
56  {
57  if (!isset($settings['set_session_var'])) {
58  $var_settings = Array();
59  } else {
60  $var_settings = $settings['set_session_var'];
61  }
62  $name = array_get_index($var_settings, 'var_name', '');
63  $value = array_get_index($var_settings, 'var_value', '');
64 
65  // Paint something here!
66  ?>
67  <table class="no-borders" style="width:auto">
68  <tr>
69  <td><?php echo translate('variable_name');?></td>
70  <td>
71  <?php
72  text_box($prefix.'_var_name', $name, 30);
73  ?>
74  </td>
75  </tr>
76  <tr>
77  <td><?php echo translate('set_value');?></td>
78  <td>
79  <?php
80  text_box($prefix.'_var_value', $value, 30);
81  ?>
82  </td>
83  </tr>
84  </table>
85  <?php
86 
87  }//end paintInlineInterface()
88 
89 
95  public static function processInlineInterface(Form $form, &$settings, Backend_Outputter $o, $prefix)
96  {
97  if (!isset($settings['set_session_var'])) {
98  $var_settings = Array();
99  } else {
100  $var_settings = $settings['set_session_var'];
101  }
102 
103  $var_settings['var_name'] = array_get_index($_POST, $prefix.'_var_name', '');
104  $var_settings['var_value'] = array_get_index($_POST, $prefix.'_var_value', '');
105 
106  $settings['set_session_var'] = $var_settings;
107 
108  return TRUE;
109 
110  }//end processInlineInterface()
111 
112 
118  public static function paintSummary(Form $form, $settings, Backend_Outputter $o, $prefix)
119  {
120  if (!isset($settings['set_session_var'])) {
121  $var_settings = Array();
122  } else {
123  $var_settings = $settings['set_session_var'];
124  }
125  $name = array_get_index($var_settings, 'var_name', '');
126  $value = array_get_index($var_settings, 'var_value', '');
127 
128  ?><table class="no-borders">
129  <colgroup>
130  <col width="80" />
131  <col/>
132  </colgroup>
133  <tbody>
134  <tr>
135  <td class="sq-backend-table-cell" style="vertical-align: top"><p><strong><?php echo translate('variable_name');?></strong></p></td>
136  <td class="sq-backend-table-cell" style="vertical-align: top"><p><?php echo $name; ?></p></td>
137  </tr>
138  <tr>
139  <td class="sq-backend-table-cell" style="vertical-align: top"><p><strong><?php echo translate('set_value');?></strong></p></td>
140  <td class="sq-backend-table-cell" style="vertical-align: top"><p><?php echo $value; ?></p></td>
141  </tr>
142  </tbody>
143  </table>
144  <?php
145 
146  }//end paintSummary()
147 
148 
153  public static function execute(Form $form, $settings)
154  {
155  $var_settings = $settings['set_session_var'];
156  $found = 0;
157 
158  // We will replace all responses, including raw values.
159  // We will also replace keywords relating to the form submission asset
160  // (eg. submission assetid, time, IP address)
161  $matches = Array();
162  $found = preg_match_all('/%(response_(\\d+_)?q\\d+(_raw)?)%/U', $var_settings['var_value'], $set_matches, PREG_SET_ORDER);
163  $matches += $set_matches;
164  $found = preg_match_all('/%(form_submission_.*)%/U', $var_settings['var_value'], $set_matches, PREG_SET_ORDER);
165  $matches = array_merge($matches, $set_matches);
166 
167  foreach ($matches as $match) {
168  if (empty($match)) continue;
169  $var_settings['var_value'] = preg_replace('/%'.$match[1].'%/U', html_entity_decode($form->_getThankYouKeywordReplacement($match[1])), $var_settings['var_value']);
170  }
171 
172  $_SESSION[SQ_SESSION_SANDBOX_INDEX][$var_settings['var_name']] = $var_settings['var_value'];
173 
174  return TRUE;
175 
176  }//end execute()
177 
178 
183  public static function isValid(Form $form, $settings)
184  {
185  if (!isset($settings['set_session_var'])) {
186  $var_settings = Array();
187  } else {
188  $var_settings = $settings['set_session_var'];
189  }
190  self::_fillDefaultValues($var_settings);
191 
192  // Check if valid and return FALSE
193  if (!isset($var_settings['var_name']) || empty($var_settings['var_name'])) {
194  return FALSE;
195  }//end if
196 
197  if (!isset($var_settings['var_value'])) return FALSE;
198 
199  return TRUE;
200 
201  }//end isValid()
202 
203 
211  private static function _fillDefaultValues(&$session_format)
212  {
213  if (!isset($session_format['var_value'])) {
214  $session_format['var_value'] = '';
215  }
216  if (!isset($session_format['var_name'])) {
217  $session_format['var_name'] = '';
218  }
219 
220  }//end _fillDefaultValues()
221 
222 
223 }//end class
224 
225 ?>