18 require_once SQ_CORE_PACKAGE_PATH.
'/page/page_edit_fns.inc';
41 parent::__construct();
42 $this->static_screens[
'details'][
'force_unlock'] = FALSE;
61 $write_access = $asset->writeAccess(
'links');
62 $first_question = $GLOBALS[
'SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE,
'decision_tree_question', FALSE,
'first_question');
65 $assetid = (!empty($first_question[
'minorid'])) ? $first_question[
'minorid'] : 0;
66 asset_finder($prefix.
'_first_question', $assetid, $type_codes = Array (
'decision_tree_question' =>
'D'));
67 if (!empty($assetid)) echo
'<p>'.get_asset_tag_line($first_question[
'minorid'],
'details').
'</p>';
69 if (!empty($first_question[
'minorid'])) {
70 echo get_asset_tag_line($first_question[
'minorid'],
'details');
72 echo
"<i>".translate(
'first_question_not_selected').
"</i>";
93 if (!$asset->writeAccess(
'links'))
return FALSE;
95 $asset_finder = array_get_index($_POST, $prefix.
'_first_question');
96 $new_first_id = array_get_index($asset_finder,
'assetid');
97 $existing_first = $GLOBALS[
'SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE,
'decision_tree_question', FALSE,
'first_question');
100 if (!empty($new_first_id)){
101 $child_questions = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($asset->id,
'decision_tree_question', FALSE);
102 if (!in_array($new_first_id, array_keys($child_questions))){
103 trigger_error(
'The first question must be a child of this page', E_USER_NOTICE);
108 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
109 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
113 if (!empty($existing_first) && (empty($new_first_id) || ($new_first_id != $existing_first[
'minorid']))){
114 if (!$GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($existing_first[
'linkid'])) {
120 if (!empty($new_first_id) && (empty($existing_first) || ($new_first_id != $existing_first[
'minorid']))){
121 $first_question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($new_first_id);
122 if (!$GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($asset, $first_question, SQ_LINK_NOTICE,
'first_question')){
128 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
129 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
131 trigger_error(
'Failed to Process First Question Selection', E_USER_WARNING);
132 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
133 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
155 if (!$asset->writeAccess(
'links'))
return FALSE;
157 $am = $GLOBALS[
'SQ_SYSTEM']->am;
158 $question_types = $am->getTypeDescendants(
'decision_tree_question');
159 $questions = Array(
'' =>
'-- Choose Type --');
161 foreach ($question_types as $question) {
162 $q = str_replace(
'decision_tree_question_type',
'', $question);
163 $q = str_replace(
'_',
' ', $q);
164 $q = trim(ucwords($q));
165 $questions[$question] = $q;
168 combo_box($prefix.
'question_type', $questions, FALSE,
'');
171 text_box($prefix.
'question_name',
'',
'25');
190 if (!$asset->writeAccess(
'links'))
return FALSE;
192 $type = (isset($_POST[$prefix.
'question_type'])) ? $_POST[$prefix.
'question_type'] :
'';
193 $name = (isset($_POST[$prefix.
'question_name'])) ? $_POST[$prefix.
'question_name'] :
'';
195 if ($type && $name) {
196 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
197 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
199 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type);
200 $type = ucwords($type);
201 $new_asset =
new $type;
202 $new_asset->setAttrValue(
'name', $name);
206 'link_type' => SQ_LINK_TYPE_2,
208 'sort_order' => NULL,
209 'is_dependant' => TRUE,
210 'is_exclusive' => FALSE,
213 if(!$new_asset->create($link)) {
214 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
215 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
219 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
220 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
242 $admin_access = $asset->writeAccess(
'attributes');
243 $bodycopy_points = $asset->attr(
'bodycopy_points');
244 $bodycopies = $asset->getResultBodycopies();
247 <table
class=
"sq-backend-table">
249 <td
class=
"sq-backend-table-header">
250 <?php echo translate(
'result_bodycopy'); ?>
252 <td
class=
"sq-backend-table-header">
253 <?php echo translate(
'points_range_min_max_incl'); ?>
258 foreach ($bodycopies as $b_link) {
259 if ($b_link[
'value'] ==
'default_result_bodycopy')
continue;
260 $assetid = $b_link[
'minorid'];
263 <td
class=
"sq-backend-table-cell">
264 <?php echo get_asset_tag_line($assetid,
'details'); ?>
266 <td
class=
"sq-backend-table-cell">
268 $min = (!empty($bodycopy_points[$assetid][
'min'])) ? $bodycopy_points[$assetid][
'min'] : 0;
269 $max = (!empty($bodycopy_points[$assetid][
'max'])) ? $bodycopy_points[$assetid][
'max'] : 0;
271 text_box($prefix.
'_bodycopy_points_min_'.$assetid, $min);
273 text_box($prefix.
'_bodycopy_points_max_'.$assetid, $max);
275 echo $min.
' to '.$max;
303 if (!$asset->writeAccess(
'attributes'))
return FALSE;
305 $bodycopy_points = Array();
306 $bodycopies = $asset->getResultBodycopies();
308 foreach ($bodycopies as $b_link) {
309 if ($b_link[
'value'] ==
'default_result_bodycopy')
continue;
310 $assetid = $b_link[
'minorid'];
312 $max = (isset($_POST[$prefix.
'_bodycopy_points_max_'.$assetid])) ? $_POST[$prefix.
'_bodycopy_points_max_'.$assetid] : 0;
313 $min = (isset($_POST[$prefix.
'_bodycopy_points_min_'.$assetid])) ? $_POST[$prefix.
'_bodycopy_points_min_'.$assetid] : 0;
315 if (!is_numeric($max) || !is_numeric($min)) {
316 trigger_localised_error(
'CMS0115', E_USER_WARNING);
321 trigger_localised_error(
'CMS0116', E_USER_WARNING);
325 $bodycopy_points[$assetid][
'max'] = $max;
326 $bodycopy_points[$assetid][
'min'] = $min;
329 $asset->setAttrValue(
'bodycopy_points', $bodycopy_points);
330 $asset->saveAttributes();
349 if (!$asset->writeAccess(
'links'))
return FALSE;
352 for ($i = 0; $i <= 10; $i++) {
356 combo_box($prefix.
'num_bodycopies', $num, FALSE,
'');
375 if (!$asset->writeAccess(
'links'))
return FALSE;
377 $to_create = (isset($_POST[$prefix.
'num_bodycopies'])) ? $_POST[$prefix.
'num_bodycopies'] : 0;
378 $bodycopies = $asset->getResultBodycopies();
379 $no_bodycopies = count($bodycopies) - 1;
380 for ($i = 0; $i < $to_create; $i++){
382 if (!$asset->createResultBodycopy(
'Result Bodycopy '.$no_bodycopies,
'')){
383 trigger_localised_error(
'CMS0117', E_USER_WARNING);