Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_condition_interface_mode.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 
31 {
32 
33 
51  public static function evaluate($settings, &$state)
52  {
53  // grab the data we need to check the condition, if it's not already cached
54  // note that new state is modified and new data is available to other conditions
55  if (empty($state['asset'])) {
56  // grab the asset if assetid is given, but not the asset
57  if (empty($state['assetid'])) {
58  return FALSE;
59  } else {
60  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
61  }
62  }
63 
64  $satisfied = FALSE;
65  $modes = $settings['modes'];
66  // check the current interface against the list
67  foreach ($modes as $mode) {
68  switch ($mode) {
69  case 'frontend':
70  if (!SQ_IN_BACKEND && !SQ_IN_LIMBO && !SQ_IN_LOGIN && !SQ_IN_CRON) {
71  $satisfied = TRUE;
72  }
73  break;
74 
75  case 'backend':
76  if (SQ_IN_BACKEND) $satisfied = TRUE;
77  break;
78 
79  case 'limbo':
80  if (SQ_IN_LIMBO) $satisfied = TRUE;
81  break;
82 
83  case 'login':
84  if (SQ_IN_LOGIN) $satisfied = TRUE;
85  break;
86 
87  case 'cron':
88  if (SQ_IN_CRON) $satisfied = TRUE;
89  break;
90  }
91  }
92 
93  return $satisfied;
94 
95  }//end evaluate()
96 
97 
108  public static function getInterface($settings, $prefix, $write_access=FALSE)
109  {
110  $selected = array_get_index($settings, 'modes', Array());
111 
112  ob_start();
113  echo translate('condition_interface_mode_user_in');
114  if ($write_access) {
115  $options = Array(
116  'frontend',
117  'backend',
118  'limbo',
119  'login',
120  'cron',
121  );
122  ?>
123  <table>
124  <tbody>
125  <tr>
126  <?php
127  foreach ($options as $idx => $option) {
128  echo '<td>'.check_box($prefix.'['.$idx.']', $option, in_array($option, $selected)).'</td>';
129  echo '<td>'.label(translate('condition_interface_mode_'.$option), $prefix.'['.$idx.']').'</td>';
130  }
131  ?>
132  </tr>
133  </tbody>
134  </table>
135  <?php
136  } else {
137  echo '<ul>';
138  foreach ($selected as $mode) {
139  echo '<li>'.translate('condition_interface_mode_'.$mode).'</li>';
140  }
141  echo '</ul>';
142  }
143  $contents = ob_get_clean();
144  return $contents;
145 
146  }//end getInterface()
147 
148 
158  public static function processInterface(&$settings, $request_data)
159  {
160  $settings['modes'] = $request_data;
161 
162  return FALSE;
163 
164  }//end processInterface()
165 
166 
167 }//end class
168 
169 ?>