Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_question_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
32 {
33 
34 
40  {
41  $this->Asset_Edit_Fns();
42  // override static screens - only display details because the others don't apply
43  $this->static_screens = Array(
44  'details' => Array(
45  'name' => 'Details',
46  'force_unlock' => FALSE,
47  'lock_type' => 'none',
48  ),
49  );
50 
51  }//end constructor
52 
53 
64  function paintRules(&$asset, &$o, $prefix)
65  {
66  if ($asset->getRuleCount() == 0) {
67  $o->openRaw();
68  echo translate('core_form_no_rules_set');
69  $o->closeRaw();
70  return FALSE;
71  }
72 
73  $rule_codes = $asset->getAllowedRules();
74  $type_codes = Array();
75  $write_access = $asset->writeAccess('attributes');
76 
77  foreach ($rule_codes as $rule_code) {
78  $type_codes[] = 'form_question_rule_type_'.$rule_code;
79  }
80 
81  $desc = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_codes, 'description');
82 
83  $rules = $asset->getRules();
84 
85  for (reset($rules); NULL !== ($k = key($rules)); next($rules)) {
86  $rule = $rules[$k];
87  // let the rule paint itself here!!
88  $type_code = 'form_question_rule_type_'.$rule['rule_code'];
89  $GLOBALS['SQ_SYSTEM']->am->includeAsset($type_code);
90  $rule_asset = new $type_code();
91  $edit_fns = $rule_asset->getEditFns();
92 
93  $o->openSection($desc[$type_code]);
94  $edit_fns->paintRule($rule_asset, $o, $prefix.'_rule_'.$k, $rule, $write_access, $this);
95 
96  if ($write_access) {
97  $o->openField(translate('core_form_custom_error_text'));
98  text_box($prefix.'_rule_'.$k.'[custom_text]', array_get_index($rule, 'custom_text', ''), 30);
99  $o->closeField();
100 
101  $o->openField(translate('delete_question'));
102  check_box($prefix.'_rule_'.$k.'[delete]');
103  $o->closeField();
104  } else {
105  $o->openField(translate('core_form_custom_error_text'));
106  $custom_text = array_get_index($rule, 'custom_text', '');
107  if (empty($custom_text)) {
108  ?><i><?php echo translate('core_form_no_custom_error_text_set') ?></i><?php
109  } else {
110  echo $rule['custom_text'];
111  }
112  $o->closeField();
113  }
114 
115  $o->closeSection();
116  }//end for
117 
118  return $write_access;
119 
120  }//end paintRules()
121 
122 
133  function processRules(&$asset, &$o, $prefix)
134  {
135  if ($asset->getRuleCount() == 0) return FALSE;
136 
137  if (!$asset->writeAccess('attributes')) return FALSE;
138 
139  $rule_codes = $asset->getAllowedRules();
140  $type_codes = Array();
141 
142  foreach ($rule_codes as $rule_code) {
143  $type_codes[] = 'form_question_rule_type_'.$rule_code;
144  }
145 
146  $desc = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_codes, 'description');
147 
148  $rules = $asset->getRules();
149 
150  // delete rules first
151  foreach (array_keys($rules) as $k) {
152  $rule_prefix = $prefix.'_rule_'.$k;
153  if (!isset($_POST[$rule_prefix])) continue;
154  if (array_get_index($_POST[$rule_prefix], 'delete', 0)) {
155  unset($rules[$k]);
156  }
157  }
158 
159  // modify what's left
160  for (reset($rules); NULL !== ($k = key($rules)); next($rules)) {
161  $rule =& $rules[$k];
162  $rule_prefix = $prefix.'_rule_'.$k;
163  // let the rule paint itself here!!
164  $type_code = 'form_question_rule_type_'.$rule['rule_code'];
165  $GLOBALS['SQ_SYSTEM']->am->includeAsset($type_code);
166  $rule_asset = new $type_code();
167  $edit_fns = $rule_asset->getEditFns();
168 
169  $edit_fns->processRule($rule_asset, $o, $prefix.'_rule_'.$k, $rule);
170 
171  // set custom text
172  if (isset($_POST[$rule_prefix]['custom_text'])) {
173  $rule['custom_text'] = $_POST[$rule_prefix]['custom_text'];
174  }
175  }
176 
177  $asset->setAttrValue('rules', $rules);
178  return $asset->saveAttributes();
179 
180  }//end processRules()
181 
182 
195  function paintAddRule(&$asset, &$o, $prefix)
196  {
197  if (!$asset->writeAccess('attributes')) return FALSE;
198 
199  $rule_codes = $asset->getAllowedRules();
200  $type_codes = Array();
201 
202  foreach ($rule_codes as $rule_code) {
203  $type_code = 'form_question_rule_type_'.$rule_code;
204  $GLOBALS['SQ_SYSTEM']->am->includeAsset($type_code);
205  $val_rule = eval('return '.$type_code.'::isValidationRule();');
206  if ($val_rule) $type_codes[] = $type_code;
207  }
208 
209  $desc = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_codes, 'description');
210  combo_box('rule', array_merge(Array(' ' => '------ '.translate('please_select').' ------'), $desc), FALSE, '');
211 
212  return TRUE;
213 
214  }//end paintAddRule()
215 
216 
227  function processAddRule(&$asset, &$o, $prefix)
228  {
229  $type_code = $_POST['rule'];
230  $rule_code = substr($type_code,strlen('form_question_rule_type_'));
231  if (!trim($rule_code)) return FALSE;
232 
233  $rules = $asset->getRules();
234  $rules[] = Array('rule_code' => $rule_code);
235 
236  $asset->setAttrValue('rules', $rules);
237  return $asset->saveAttributes();
238 
239  }//end processAddRule()
240 
241 
254  function paintLockMessage(&$asset, &$o, $prefix)
255  {
256  $section_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($asset->_formid);
257 
258  $locks = $GLOBALS['SQ_SYSTEM']->am->getLockInfo($section_asset->id, 'attributes', TRUE);
259  $lock = $locks['attributes'];
260 
261  $full_write_access = $section_asset->writeAccess('');
262  $acquire_lock_access = $section_asset->canLiveEdit('attributes');
263 
264  if (empty($lock)) {
265  if ($full_write_access && $acquire_lock_access) {
266  echo '<p class="sq-backend-unlocked">The "Attributes" lock to the '.(($section_asset instanceof Form_Section) ? 'Form Section' : 'Form').' is not currently held.</p>';
267  } else {
268  echo 'You do not have access to edit "'.$section_asset->name.'".';
269  }
270 
271  } else {
272  // this asset is currently locked so display message to the user
273  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($lock['userid']);
274  $editing = $GLOBALS['SQ_SYSTEM']->am->getAsset($lock['source_assetid']);
275 
276  if (SQ_ROLLBACK_VIEW) {
277  $now = strtotime($_SESSION['sq_rollback_view']['rollback_time']);
278  } else {
279  $now = time();
280  }
281 
282  if (is_null($lock['expires'])) {
283  $expires_in = 'The lock is being held indefinitely and will not expire. The lock must be released manually or be forceably acquired by a System Administrator.';
284  } else {
285  require_once SQ_FUDGE_PATH.'/general/datetime.inc';
286  $expires_in = easy_time_total(($lock['expires'] - $now), TRUE);
287  if (!$expires_in) $expires_in = '1 second';
288  $expires_in = 'The lock is due to expire in '.$expires_in;
289  }
290 
291  ?>
292  <p class="sq-backend-locked-by-<?php echo ($GLOBALS['SQ_SYSTEM']->currentUser($user)) ? 'user' : 'someone-else'; ?>">
293  The "Attributes" lock to the <?php echo ($section_asset instanceof Form_Section) ? 'Form Section' : 'Form' ?> is held by user "<?php echo htmlspecialchars($user->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET); ?>" at "<?php echo htmlspecialchars($editing->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET); ?>".<br/>
294  <?php echo $expires_in; ?>
295  </p>
296  <?php
297 
298  }//end if
299  ?>
300 
301  <p>Locking for this asset is controlled by its parent form<?php
302  if ($section_asset instanceof Form_Section) {
303  echo ' section';
304  }
305  ?>. Click to access this asset: <?php $href = $section_asset->getBackendHref(!($section_asset instanceof Form) ? 'details' : 'contents'); ?><a href="<?php echo $href ?>"><?php echo $section_asset->_getName() ?></a></p><?php
306  return TRUE;
307 
308  }//end paintLockMessage()
309 
310 
321  function processLockMessage(&$asset, &$o, $prefix)
322  {
323  return TRUE;
324 
325  }//end processLockMessage()
326 
327 
328 }//end class
329 ?>