Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
decision_tree_question_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
30 {
31 
32 
38  {
39  $this->Asset_Edit_Fns();
40  // override static screens - only display details because the others don't apply
41  $this->static_screens = Array(
42  'details' => Array(
43  'name' => 'Details',
44  'force_unlock' => FALSE,
45  'lock_type' => 'none',
46  ),
47  );
48 
49  }//end constructor
50 
51 
62  function paintQuestionLinks(&$asset, &$o, $prefix)
63  {
64  $am = $GLOBALS['SQ_SYSTEM']->am;
65  $admin_access = $asset->writeAccess('attributes');
66  $prefix = $asset->getPrefix();
67  $questions = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2, 'decision_tree_question', FALSE);
68 
69  ?>
70  <table class="sq-backend-table">
71  <tr>
72  <td class="sq-backend-table-header">
73  <?php echo translate('question'); ?>
74  </td>
75  <td class="sq-backend-table-header">
76  <?php echo translate('type'); ?>
77  </td>
78  </tr>
79  <?php
80 
81  foreach ($questions as $q_link) {
82  $assetid = $q_link['minorid'];
83  $q = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
84  if (is_null($q)) continue;
85  ?>
86  <tr>
87  <td class="sq-backend-table-cell">
88  <?php echo get_asset_tag_line($assetid, 'details'); ?>
89  </td>
90  <td class="sq-backend-table-cell">
91  <?php
92  $q_type = str_replace('Decision_Tree_Question_Type', '', get_class($q));
93  $q_type = str_replace('_', ' ', $q_type);
94  $q_type = trim(ucwords($q_type));
95  echo $q_type;
96  ?>
97  </td>
98  </tr>
99  <?php
100  }//end foreach data
101  ?>
102  </table>
103  <?php
104  return TRUE;
105 
106  }//end paintQuestionLinks()
107 
108 
119  function processQuestionLinks(&$asset, &$o, $prefix)
120  {
121 
122  return TRUE;
123 
124  }//end processQuestionLinks()
125 
126 
139  function paintAddQuestions(&$asset, &$o, $prefix)
140  {
141  if (!$asset->writeAccess('links')) return FALSE;
142 
143  $am = $GLOBALS['SQ_SYSTEM']->am;
144  $question_types = $am->getTypeDescendants('decision_tree_question');
145  $questions = Array('' => '-- Choose Type --');
146 
147  foreach ($question_types as $question) {
148  $q = str_replace('decision_tree_question_type', '', $question);
149  $q = str_replace('_', ' ', $q);
150  $q = trim(ucwords($q));
151  $questions[$question] = $q;
152  }
153 
154  combo_box($prefix.'question_type', $questions, FALSE, '');
155  echo '&nbsp;';
156 
157  text_box($prefix.'question_name', '', '25');
158  return TRUE;
159 
160  }//end paintAddQuestions()
161 
162 
173  function processAddQuestions(&$asset, &$o, $prefix)
174  {
175  if (!$asset->writeAccess('links')) return FALSE;
176 
177  $type = (isset($_POST[$prefix.'question_type'])) ? $_POST[$prefix.'question_type'] : '';
178  $name = (isset($_POST[$prefix.'question_name'])) ? $_POST[$prefix.'question_name'] : '';
179 
180  if ($type && $name) {
181  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
182  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
183 
184  $GLOBALS['SQ_SYSTEM']->am->includeAsset($type);
185  $type = ucwords($type);
186  $new_asset = new $type;
187  $new_asset->setAttrValue('name', $name);
188  // Link the asset to the parent asset
189  $link = Array(
190  'asset' => $asset,
191  'link_type' => SQ_LINK_TYPE_2,
192  'value' => '',
193  'sort_order' => NULL,
194  'is_dependant' => TRUE,
195  'is_exclusive' => FALSE,
196  );
197 
198  if(!$new_asset->create($link)) {
199  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
200  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
201  //trigger error
202  return FALSE;
203  }
204 
205  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
206  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
207 
208  }//end if
209 
210  return TRUE;
211 
212  }//end processAddQuestions()
213 
214 
225  function paintLockMessage(&$asset, &$o, $prefix)
226  {
227  $dependant_parent = $GLOBALS['SQ_SYSTEM']->am->getDependantParents($asset->id, '', FALSE, FALSE);
228  if (empty($dependant_parent[0])) {
229  echo "<p>Locking for this asset is controlled by its parent Decision Tree Page.</p>";
230  return TRUE;
231  }
232 
233  $parent_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($dependant_parent[0]);
234 
235  $locks = $GLOBALS['SQ_SYSTEM']->am->getLockInfo($parent_asset->id, 'attributes', TRUE);
236  $lock = $locks['attributes'];
237 
238  $full_write_access = $parent_asset->writeAccess('');
239  $acquire_lock_access = $parent_asset->canLiveEdit('attributes');
240 
241  if (empty($lock)) {
242  if ($full_write_access && $acquire_lock_access) {
243  echo '<p class="sq-backend-unlocked">The "Attributes" lock to the Decision Tree Page is not currently held.</p>';
244  } else {
245  echo 'You do not have access to edit "'.$parent_asset->name.'".';
246  }
247 
248  } else {
249  // this asset is currently locked so display message to the user
250  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($lock['userid']);
251  $editing = $GLOBALS['SQ_SYSTEM']->am->getAsset($lock['source_assetid']);
252 
253  if (SQ_ROLLBACK_VIEW) {
254  $now = strtotime($_SESSION['sq_rollback_view']['rollback_time']);
255  } else {
256  $now = time();
257  }
258 
259  if (is_null($lock['expires'])) {
260  $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.';
261  } else {
262  require_once SQ_FUDGE_PATH.'/general/datetime.inc';
263  $expires_in = easy_time_total(($lock['expires'] - $now), TRUE);
264  if (!$expires_in) $expires_in = '1 second';
265  $expires_in = 'The lock is due to expire in '.$expires_in;
266  }
267 
268  ?>
269  <p class="sq-backend-locked-by-<?php echo ($GLOBALS['SQ_SYSTEM']->currentUser($user)) ? 'user' : 'someone-else'; ?>">
270  The "Attributes" lock to the Decision Tree Question 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/>
271  <?php echo $expires_in; ?>
272  </p>
273  <?php
274 
275  }//end if
276  ?>
277 
278  <p>Locking for this asset is controlled by its parent Decision Tree Page<?php
279  ?>. Click to access this asset: <?php $href = $parent_asset->getBackendHref('details'); ?><a href="<?php echo $href ?>"><?php echo $parent_asset->name ?></a></p><?php
280  return TRUE;
281 
282  }//end paintLockMessage()
283 
284 
295  function processLockMessage(&$asset, &$o, $prefix)
296  {
297  return TRUE;
298 
299  }//end processLockMessage()
300 
301 
302 }//end class
303 
304 ?>