17 require_once SQ_INCLUDE_PATH.
'/asset.inc';
18 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
19 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
20 require_once SQ_FUDGE_PATH.
'/general/general.inc';
21 require_once SQ_FUDGE_PATH.
'/general/www.inc';
22 require_once SQ_CORE_PACKAGE_PATH.
'/interfaces/bridge/bridge.inc';
23 require_once SQ_FUDGE_PATH.
'/mollom/mollom.inc';
45 var $current_answers = Array();
56 var $extra_data = Array();
63 var $active_section = NULL;
70 var $submission_errors = NULL;
77 var $submission_asset = NULL;
91 $this->_ser_attrs = TRUE;
92 $this->
Asset($assetid);
111 $this->
setAttrValue(
'submission_errors_msg', translate(
'cms_form_error_msg_default'));
113 return parent::create($link);
144 return parent::_createAdditional($link);
159 protected function _getName($short_name=FALSE, $contextid=NULL)
162 if ($contextid === NULL) {
163 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
167 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
168 if (empty($values) === TRUE) {
169 return parent::_getName($short_name, $contextid);
171 return $values[$this->id];
187 SQ_LINK_TYPE_2 => Array(
188 'form_section' => Array(
190 'exclusive' => FALSE,
247 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
248 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
250 if (!parent::cloneComponents($clone, $components, $override)) {
251 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
252 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
256 if (in_array(
'attributes', $components) || in_array(
'all', $components)) {
257 $sort_order = $this->
attr(
'sort_order');
258 $sort_order = str_replace($this->
id.
':q', $clone->id.
':q', $sort_order);
261 $clone->setAttrValue(
'sort_order', $sort_order);
262 $clone->saveAttributes();
268 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
269 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
301 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
302 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
304 if (in_array(
'attributes', $components) || in_array(
'all', $components)) {
305 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($GLOBALS[
'SQ_SYSTEM']->getRunLevel() & SQ_RUN_LEVEL_FORCED);
309 $clone_section_links = $clone->getSectionLinks();
311 $originals_clones = Array();
312 foreach ($section_links as $link) {
313 foreach ($clone_section_links as $cloned_link) {
314 if ($cloned_link[
'sort_order'] == $link[
'sort_order']) {
316 $originals_clones[] = Array (
317 'original' => $link[
'minorid'],
318 'clone' => $cloned_link[
'minorid'],
325 $originals_clones[] = Array (
326 'original' => $this->
id,
327 'clone' => $clone->id,
331 $bodycopies = Array (
332 'use_bodycopy_main' =>
'Page Contents',
333 'use_bodycopy_thank_you' =>
'Thank You',
335 if ((isset($clone->_bodycopies) && !empty($clone->_bodycopies)) ) {
336 $bodycopies = array_merge($bodycopies, Array (
'use_bodycopy_receipt' =>
'Receipt'));
339 $replace_keywords = Array (
'question_name',
'response',
'question_field',
'question_id',
'question_note',
'question_label',
'section_title');
340 foreach ($bodycopies as $attribute => $bodycopy_name) {
342 if ((isset($clone->_bodycopies) && !empty($clone->_bodycopies)) ) {
343 $bodycopy = $clone->getBodycopy($bodycopy_name);
345 $attr_value = $clone->attr($attribute);
346 if (!empty($attr_value)) $bodycopy = $clone->getBodycopy($bodycopy_name);
349 if (!empty($bodycopy)) {
350 $containers = $bodycopy->getContainers();
351 foreach ($containers as $container) {
352 $content_type = $container->getContentType();
353 if ($container->type() ==
'bodycopy_table') {
354 if (is_array($content_type)) {
355 foreach ($content_type as $cell_type) {
356 if (!$this->
_cloneDIVContents($cell_type, $originals_clones, $replace_keywords)) {
357 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
358 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
363 if (!$this->
_cloneDIVContents($content_type, $originals_clones, $replace_keywords)) {
364 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
365 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
370 if (!$this->
_cloneDIVContents($content_type, $originals_clones, $replace_keywords)) {
371 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
372 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
380 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
384 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
385 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
403 $old_html = $content_type->attr(
'html');
404 if (!empty($old_html) && !empty($original_clones)) {
405 $new_html = $content_type->attr(
'html');
406 foreach ($original_clones as $original_clone) {
408 foreach ($replace_keywords as $keyword) {
409 if ($keyword ==
'section_title') {
410 $new_html = str_replace($keyword.
'_'.$original_clone[
'original'], $keyword.
'_'.$original_clone[
'clone'], $new_html);
412 $new_html = str_replace($keyword.
'_'.$original_clone[
'original'].
'_q', $keyword.
'_'.$original_clone[
'clone'].
'_q', $new_html);
418 if (!$content_type->setAttrValue(
'html', $new_html)) {
422 if (!$content_type->saveAttributes())
return FALSE;
448 public function getAsset($assetid, $type_code=
'', $mute_errors=FALSE)
451 $id_parts = explode(
':', $assetid);
453 if (isset($id_parts[1])) {
454 $shadowid = $id_parts[1];
460 if ($shadowid{0} ==
'q') {
463 $questions = $this->
attr(
'questions');
464 $questionid = substr($shadowid, 1, strlen($shadowid));
465 if (empty($questions[$questionid]))
return $asset;
467 $q_type_code = $questions[$questionid][
'question_type_code'];
470 if (empty($type_code)) $type_code = $q_type_code;
473 if (in_array($q_type_code, $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants($type_code, TRUE))) {
474 $questions[$questionid][
'questionid'] = $questionid;
475 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($q_type_code);
478 $asset =
new $q_type_code($this->
id, $questions[$questionid]);
507 function getLinks($assetid, $link_types, $type_code=
'', $strict_type_code=TRUE, $side_of_link=
'major', $sort_by=NULL)
509 $id_parts = explode(
':', $assetid);
510 if (isset($id_parts[1])) $assetid = $id_parts[1];
516 if (!is_numeric($assetid)) {
517 if ($side_of_link ==
'minor') {
518 $return_link = FALSE;
520 if ($type_code ==
'') {
523 }
else if ($strict_type_code) {
525 $return_link = ($type_code == $this->
type());
527 $return_link = (in_array($this->
type(), $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants($type_code, TRUE)));
533 'majorid' => $this->
id,
534 'minorid' => $this->
id.
':'.$assetid,
535 'major_type_code' => $this->
type(),
537 'link_type' => SQ_LINK_TYPE_2,
538 'is_dependant' => TRUE,
539 'is_exclusive' => FALSE,
550 $real_type_codes = Array(
551 'folder' => SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
552 'form_section' => SQ_LINK_TYPE_2,
557 foreach ($real_type_codes as $real_type_code => $allowed_link_types) {
558 if ($type_code ==
'') {
561 }
else if ($strict_type_code) {
562 $get_type = ($type_code == $real_type_code);
565 $get_type = (in_array($real_type_code, $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants($type_code, TRUE)));
570 $query = $GLOBALS[
'SQ_SYSTEM']->am->generateGetLinksQuery($assetid, $link_types & $allowed_link_types, $real_type_code, FALSE);
571 if (empty($query))
return Array();
576 foreach ($query[
'bind_vars'] as $bind_var => $bind_value) {
580 }
catch (Exception $e) {
581 throw new Exception(
'Unable to get links for asset: '.$assetid.
' due to database error: '.$e->getMessage());
584 foreach (array_keys($type_links) as $key) {
591 if ($link_types & SQ_LINK_TYPE_2) {
592 $questions = $this->
attr(
'questions');
597 $get_question_types = Array();
599 foreach ($questions as $questionid => $data) {
600 if ($type_code ==
'') {
602 $get_question = TRUE;
603 }
else if ($strict_type_code) {
605 $get_question = ($type_code == $data[
'question_type_code']);
609 if (isset($get_question_types[$data[
'question_type_code']])) {
610 $get_question = $get_question_types[$data[
'question_type_code']];
611 $get_question_types[$data[
'question_type_code']] = $get_question;
613 $get_question = (in_array($data[
'question_type_code'], $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants($type_code, TRUE)));
620 'majorid' => $this->
id,
621 'minorid' => $this->
id.
':q'.$questionid,
622 'minor_type_code' => $data[
'question_type_code'],
624 'link_type' => SQ_LINK_TYPE_2,
625 'is_dependant' => TRUE,
626 'is_exclusive' => FALSE,
627 'sort_order' => $new_sort_order,
635 if (is_null($sort_by)) $sort_by =
'sort_order';
637 uasort($links, create_function(
'$a,$b',
'return $a["'.$sort_by.
'"] > $b["'.$sort_by.
'"];'));
653 $old_links = $this->
getLinks($this->
id, SQ_SC_LINK_BACKEND_NAV);
655 while (!empty($old_links)) {
656 array_push($links, array_shift($old_links));
659 $questions = $this->
attr(
'questions');
661 foreach (array_keys($links) as $i) {
666 if ($link[
'minor_type_code'] ==
'folder') {
671 if ($link[
'minor_type_code'] ==
'form_section') {
679 $link[
'num_kids'] = 0;
680 $link[
'accessible'] = 1;
682 $link[
'assetid'] = $link[
'minorid'];
683 $link[
'type_code'] = $link[
'minor_type_code'];
684 $link[
'linkid'] = $link[
'majorid'].
':'.$link[
'minorid'];
686 $questionid = str_replace($this->
id.
':q',
'', $link[
'assetid']);
689 $link[
'name'] = $questions[$questionid][
'attributes'][
'name'];
690 $link[
'short_name'] = $link[
'name'];
693 $link[
'status'] = $this->status;
695 unset($link[
'minor_type_code']);
696 unset($link[
'majorid']);
697 unset($link[
'minorid']);
698 unset($link[
'value']);
699 unset($link[
'is_exclusive']);
722 function getParents($shadowid, $type_code=
'', $strict_type_code=TRUE)
724 $id_parts = explode(
':', $shadowid);
725 if (isset($id_parts[1])) $shadowid = $id_parts[1];
728 $ret_val = $GLOBALS[
'SQ_SYSTEM']->am->generateGetParentsQuery($this->
id, $type_code, $strict_type_code);
730 if (empty($ret_val))
return Array();
734 foreach ($ret_val[
'bind_vars'] as $bind_var => $bind_value) {
739 }
catch (Exception $e) {
740 throw new Exception(
'Unable to get the parents of shadow id: '.$shadowid.
' due to database error: '.$e->getMessage());
744 foreach ($queried_parents as $queried_parent) {
745 $parents[$queried_parent[
'majorid']] = $queried_parent[
'type_code'];
748 $parents[$this->id] = $this->
type();
777 function getChildren($assetid, $type_code=
'', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL)
780 if (!is_numeric($assetid))
return Array();
782 if (!is_array($type_code)) {
783 if (empty($type_code)) {
784 $type_code = Array();
786 $type_code = Array($type_code);
794 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
795 if (($asset instanceof
Bridge) && ($assetid != $this->
id)) {
796 $children = $asset->getChildren($assetid, $type_code, $dependant, $strict_type_code, $sort_by);
797 $this->forgetAsset($asset);
799 $ret_val = $GLOBALS[
'SQ_SYSTEM']->am->generateGetChildrenQuery($asset, $type_code, $strict_type_code, $dependant, $sort_by);
802 if (!empty($ret_val)) {
804 $sql_array = $ret_val[
'sql_array'];
805 $bind_vars = $ret_val[
'bind_vars'];
808 foreach ($bind_vars as $bind_var => $bind_value) {
812 }
catch (Exception $e) {
813 throw new Exception(
'Unable to get children for asset: '.$assetid.
' due to database error: '.$e->getMessage());
816 $children =& $result;
821 $entries = $this->
attr(
'questions');
822 if (empty($type_code)) {
823 foreach ($entries as $questionid => $data) {
824 $children[$this->
id.
':q'.$questionid] = Array(Array(
'type_code' => $data[
'question_type_code']));
827 foreach ($type_code as $this_type_code) {
828 foreach ($entries as $questionid => $data) {
829 if ($strict_type_code) {
830 if ($data[
'question_type_code'] == $this_type_code) {
831 $children[$this->
id.
':q'.$questionid] = Array(Array(
'type_code' => $data[
'question_type_code']));
834 $type_desc = $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants($this_type_code) + Array($this_type_code);
835 if (in_array($data[
'question_type_code'], $type_desc)) {
836 $children[$this->
id.
':q'.$questionid] = Array(Array(
'type_code' => $data[
'question_type_code']));
843 foreach ($children as $child_id => $details) {
844 foreach ($type_code as $index => $code) {
845 if ($details[0][
'type_code'] != $code) {
846 unset($children[$child_id]);
851 if (!is_null($sort_by)) {
852 uasort($children, create_function(
'$a,$b',
'return $a["'.$sort_by.
'"] > $b["'.$sort_by.
'"]'));
876 if (!parent::_updated($update_parents))
return FALSE;
899 return parent::canCreateLink($minor, $link_type, $exclusive);
924 function prepareLink(&$asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
926 if ($side_of_link ==
'major' && $asset->type() ==
'form_section') {
927 $link_type = SQ_LINK_TYPE_2;
955 function countLinks($assetid, $side_of_link=
'major', $link_types=0, $type_code=
'', $strict_type_code=TRUE, $ignore_linkid=0)
1000 function getPermission($assetid, $permission, $granted=NULL, $and_greater=TRUE, $expand_groups=FALSE, $all_info=FALSE)
1056 function getAssetInfo($assetids, $type_code=Array(), $strict_type_code=TRUE, $field=
'')
1102 function getLink($assetid, $link_type=NULL, $type_code=
'', $strict_type_code=TRUE, $value=NULL, $side_of_link=
'major', $exclusive=NULL)
1147 function getLinkByAsset($assetid, $other_assetid, $link_types=NULL, $value=NULL, $side_of_link=
'major', $force_array=FALSE, $dependant=NULL, $exclusive=NULL)
1184 function updateLink($linkid, $link_type=NULL, $value=NULL, $sort_order=NULL)
1238 function createAssetLink(&$major, &$minor, $link_type, $value=
'', $sort_order=NULL, $dependant=
'0', $exclusive=
'0', $moving=FALSE)
1258 $questions = $this->
attr(
'questions');
1279 $all_questions = Array();
1281 foreach ($questions as $q_id => $question_detail) {
1282 $all_questions[$this->
id.
':q'.$q_id] = $question_detail;
1286 foreach ($sections as $section) {
1287 $questions = $section->getQuestions();
1288 foreach ($questions as $q_id => $question_detail) {
1289 $all_questions[$section->id.
':q'.$q_id] = $question_detail;
1293 return $all_questions;
1308 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1311 $questions = $this->
attr(
'questions');
1312 if (!empty($questions)) {
1313 foreach ($questions as $q_id => $question) {
1314 if (empty($type_code) || ($question[
'question_type_code'] === $type_code)) {
1315 $id = $this->
id.
':q'.$q_id;
1316 $result[$id] = $am->getAsset($id);
1341 foreach ($sections as $section) {
1342 $questions = $section->getQuestionAssets($type_code);
1343 $all_questions = array_merge($all_questions, $questions);
1346 return $all_questions;
1363 if (($page_number == $this->
getTotalPages()) && $this->
attr(
'use_confirmation_page')) {
1367 if ($this->
attr(
'multi_page')) {
1376 if (!empty($unattached_questions)) {
1380 if ($page_number == 0) {
1386 $section_link = reset(array_slice($section_links, $page_number - 1, 1));
1387 $section = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_link[
'minorid']);
1388 $questions = $section->getAllQuestionAssets();
1416 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1419 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1422 if ($this->
attr(
'next_questionid') > 0) {
1423 $new_key = $this->
attr(
'next_questionid');
1424 }
else if (empty($questions)) {
1427 $new_key = max(array_keys($questions)) + 1;
1430 $questions[$new_key] = Array(
1431 'question_type_code' => $type_code,
1432 'attributes' => Array(
'name' =>
'Question '.(count($questions)+1)),
1438 $sort_order = $this->
attr(
'sort_order');
1440 if (empty($sort_order)) {
1443 $new_index = max(array_keys($sort_order))+1;
1445 $sort_order[$new_index] = $this->
id.
':q'.$new_key;
1449 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1450 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1455 $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->
id.
':q'.$new_key,
'all', $this->
id, TRUE);
1456 $GLOBALS[
'SQ_SYSTEM']->am->updateLock($this->
id,
'all');
1458 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1459 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1479 if ($question->_questionid == 0)
return FALSE;
1481 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1482 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1485 unset($questions[$question->_questionid]);
1489 $sort_order = $this->
attr(
'sort_order');
1492 $old_index = array_search($question->id, $sort_order);
1493 unset($sort_order[$old_index]);
1501 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1502 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1505 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1506 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1522 return count($questions);
1538 return (isset($questions[$questionid])) ? $questions[$questionid] : Array();
1553 $sort_order = $this->
attr(
'sort_order');
1554 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($sort_order[$orderid]);
1573 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1575 $sections = Array();
1577 foreach ($section_links as $link) {
1578 $sections[$link[
'sort_order']] = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
1595 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1597 $sections = Array();
1599 while (!empty($section_links)) {
1600 $link = array_shift($section_links);
1601 $sections[] = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
1604 $sub_section_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($link[
'minorid'], SQ_SC_LINK_ALL,
'form_section', FALSE);
1605 $section_links = array_merge($sub_section_links, $section_links);
1620 return $GLOBALS[
'SQ_SYSTEM']->am->countLinks($this->
id,
'major', SQ_LINK_TYPE_2,
'form_section', TRUE);
1638 'link_value' => Array(
''),
1641 $links_query = $GLOBALS[
'SQ_SYSTEM']->am->generateGetLinksQuery($this->
id, SQ_LINK_TYPE_2,
'form_section', TRUE,
'major', $value,
'1',
'0');
1642 if (empty($links_query))
return Array();
1643 $links_query[
'sql_array'][
'select'] .=
', l.majorid';
1646 $sql = implode(
' ', $links_query[
'sql_array']);
1649 foreach ($links_query[
'bind_vars'] as $bind_var => $bind_value) {
1654 }
catch (Exception $e) {
1655 throw new Exception(
'Unable to get section links attached to form: '.$this->
id.
' due to database error: '.$e->getMessage());
1674 if ($GLOBALS[
'SQ_SYSTEM']->userPublic()) {
1676 $submission_var =& $_SESSION[
'SQ_FORM_'.$this->id.
'_SUBMISSION'];
1681 if (isset($submission)) {
1682 $current_page = array_get_index($_POST,
'SQ_FORM_'.$this->
id.
'_PAGE', $submission->attr(
'current_page'));
1683 $latest_page = $submission->attr(
'latest_page');
1684 }
else if (isset($submission_var)) {
1685 $current_page = array_get_index($_POST,
'SQ_FORM_'.$this->
id.
'_PAGE', array_get_index($submission_var,
'current_page', NULL));
1686 $latest_page = array_get_index($submission_var,
'latest_page', NULL);
1688 $current_page = $latest_page = NULL;
1695 $possible_actions = Array(
1703 foreach ($possible_actions as $possible_action) {
1704 if (isset($_POST[$prefix.
'_'.$possible_action])) {
1705 $action = $possible_action;
1710 $submission_limit = $this->
attr(
'submission_limit');
1713 if (is_null($action) && $submission_limit != 0 && $submission_limit <= $this->
getSubmissionCount()) {
1718 $jump_to_page = array_get_index($_GET,
'SQ_FORM_'.$this->
id.
'_PAGE', NULL);
1724 if (!is_null($current_page) || !is_null($jump_to_page) || (!is_null($action) && ($action !==
'reset'))) {
1727 if (!is_null($jump_to_page)) {
1728 $current_page = $jump_to_page;
1734 $validate_page = ($action ===
'submit') ? TRUE : FALSE;
1736 $mute_errors = (empty($action)) ? TRUE : FALSE;
1738 if (is_null($current_page)) $current_page = 1;
1739 $success = $this->
processPage($current_page, $validate_page, $mute_errors);
1742 $success = $success && (!$validate_page || $this->
performFormSectionActions($current_page)) && empty($this->submission_errors);
1750 if (!isset($submission_var) && !$submission) {
1751 $create_in_completed = ($total_pages == 1) ? TRUE : FALSE;
1757 $this->submission_asset = $submission;
1762 if (isset($submission)) {
1764 }
else if (isset($submission_var)) {
1770 if (($current_page == $total_pages) && ($action ===
'submit')) {
1773 if ($action ===
'previous_page') {
1775 }
else if ($action ===
'submit') {
1779 $current_page = max($current_page, 1);
1785 $latest_page = $current_page = 1;
1791 if ($action ===
'save_and_exit') {
1797 if (isset($submission)) {
1798 $submission->setAttrValue(
'current_page', $current_page);
1799 if ($current_page > $latest_page) {
1800 $submission->setAttrValue(
'latest_page', $current_page);
1802 $submission->saveAttributes(FALSE, $this->
attr(
'log_submissions'));
1803 }
else if (isset($submission_var)) {
1804 $_SESSION[
'SQ_FORM_'.$this->id.
'_SUBMISSION'][
'current_page'] = $current_page;
1805 if ($current_page > $latest_page) {
1806 $_SESSION[
'SQ_FORM_'.$this->id.
'_SUBMISSION'][
'latest_page'] = $current_page;
1819 if (($current_page == $total_pages) && $this->
attr(
'use_confirmation_page')) {
1858 if ($this->
attr(
'use_client_side')) {
1859 $on_submit =
'onsubmit="return beforeSubmit_'.$form_prefix.
'(this);"';
1860 $header =
'<form id="'.$form_prefix.
'" enctype="multipart/form-data" action="'.$form_action.
'" method="post" '.$on_submit.
'>';
1863 $header =
'<form id="'.$form_prefix.
'" enctype="multipart/form-data" action="'.$form_action.
'" method="post">';
1868 $submission_var = array_get_index($_SESSION,
'SQ_FORM_'.$this->
id.
'_SUBMISSION', NULL);
1870 if ($current_submission) {
1872 hidden_field(
'SQ_FORM_'.$this->
id.
'_SUBMISSION', $current_submission->id);
1873 hidden_field(
'SQ_FORM_'.$this->
id.
'_PAGE', $current_submission->attr(
'current_page'));
1874 $header .= ob_get_clean();
1875 }
else if ($submission_var) {
1877 hidden_field(
'SQ_FORM_'.$this->
id.
'_PAGE', array_get_index($submission_var,
'current_page', 1));
1878 $header .= ob_get_clean();
1881 hidden_field(
'SQ_FORM_'.$this->
id.
'_PAGE', 1);
1882 $header .= ob_get_clean();
1897 $form_action = $_SERVER[
'PHP_SELF'];
1903 if (!empty($_SERVER[
'QUERY_STRING'])) {
1904 preg_match_all(
'/([^=&]*)\=([^&]*)/', $_SERVER[
'QUERY_STRING'], $matches);
1905 $matches = array_combine($matches[1], $matches[2]);
1907 foreach ($matches as $key => $value) {
1908 if (($key ===
'SQ_FORM_'.$this->
id.
'_PAGE') || ($key ===
'SQ_FORM_'.$this->
id.
'_SUBMISSION')) {
1909 unset($matches[$key]);
1912 $matches[$key] = urldecode($matches[$key]);
1916 $form_action .=
'?'.htmlspecialchars(make_raw_post_data($matches), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
1919 return $form_action;
1937 $page_number = max($page_number, 1);
1945 if (($page_number == $total_pages) && $this->
attr(
'use_confirmation_page')) {
1949 if ($this->
attr(
'multi_page')) {
1958 if (!empty($questions)) {
1962 if ($page_number == 0) {
1964 $bodycopy = $this->
getBodycopy(
'Unattached Questions Format');
1967 if ($this->
attr(
'use_bodycopy_unattached') && $bodycopy && !$bodycopy->isEmpty()) {
1968 $keyword_list = $bodycopy->getKeywords();
1970 if (!empty($keyword_list)) {
1971 foreach ($keyword_list as $keyword) {
1975 if (is_null($replacement)) {
1982 if (!is_null($replacement)) {
1984 $replacements[$keyword] = $replacement;
1989 $bodycopy->setKeywordReplacements($replacements);
1990 $bodycopy->printBody();
1994 require_once $this->data_path.
'/content_file_questions.php';
1999 $section_link = reset(array_slice($sections, $page_number - 1, 1));
2000 $section = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_link[
'minorid']);
2001 $section->printBody($this, FALSE);
2008 $contents = ob_get_clean();
2050 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2052 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2076 if ($this->
attr(
'use_bodycopy_main') && $bodycopy && !$bodycopy->isEmpty()) {
2077 $keyword_list = $bodycopy->getKeywords();
2079 if (!empty($keyword_list)) {
2080 foreach ($keyword_list as $keyword) {
2084 if (is_null($replacement)) {
2091 if (!is_null($replacement)) {
2093 $replacements[$keyword] = $replacement;
2098 $bodycopy->setKeywordReplacements($replacements);
2099 $bodycopy->printBody();
2102 $multi_page = $this->
attr(
'multi_page');
2123 $error = !empty($this->submission_errors);
2125 $form_width = $this->
attr(
'form_width');
2127 if (!empty($form_width)) {
2128 $form_width =
' width="'.$form_width.
'"';
2131 $question_width = $this->
attr(
'question_col_width');
2132 if (!empty($question_width)) {
2133 $question_width =
' width="'.$question_width.
'"';
2136 $answer_width = $this->
attr(
'answer_col_width');
2137 if (!empty($answer_width)) {
2138 $answer_width =
' width="'.$answer_width.
'"';
2146 %<?php echo $also_print_sections ?
'form' :
'current_page' ?>_contents%<table <?php echo $form_width; ?>>
2148 <td <?php echo $question_width; ?>> </td>
2149 <td <?php echo $answer_width; ?>>
2151 if ($this->
attr(
'require_captcha') && ($current_page == $this->
getTotalPages())) {
2164 <tr><td colspan=
"2">%form_errors%</td></tr>
2170 $content = ob_get_clean();
2172 require_once SQ_FUDGE_PATH.
'/general/text.inc';
2174 $keyword_list = extract_keywords($content);
2175 if (!empty($keyword_list)) {
2176 foreach ($keyword_list as $keyword) {
2177 if (isset($replacements[$keyword]))
continue;
2181 replace_keywords($content, $replacements);
2210 $form_processed = FALSE;
2213 if (isset($_POST[$prefix.
'_submit'])) {
2214 $form_processed = $this->processForm();
2217 if ($form_processed) {
2240 if ($this->
attr(
'use_bodycopy_exit')) {
2241 $bodycopy = $this->
getBodycopy(
'Exit Page Contents');
2246 $keyword_list = $bodycopy->getKeywords();
2247 $replacements = Array();
2249 foreach ($keyword_list as $keyword) {
2252 if (strpos($keyword,
'question_field_') !== 0) {
2254 if (!empty($keyword_value)) {
2255 $replacements[$keyword] = $keyword_value;
2260 $bodycopy->setKeywordReplacements($replacements);
2261 $bodycopy->printBody();
2263 $contents = ob_get_clean();
2290 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2293 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2296 $folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'bodycopies_folder');
2297 if (empty($folder_link)) {
2300 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
2302 $folder->setAttrValue(
'name',
'Bodycopies');
2304 $folder_link = Array(
'asset' => &$this,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'bodycopies_folder',
'is_dependant' => 1,
'is_exclusive' => 1);
2306 if (!$folder->create($folder_link)) {
2307 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2308 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2313 $folder = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($folder_link[
'minorid'], $folder_link[
'minor_type_code']);
2315 if (is_null($folder)) {
2316 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2317 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2322 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $name);
2323 if (!empty($bodycopy_link)) {
2324 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2325 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2331 $copy_link = Array(
'asset' => &$folder,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1,
'value' => $name);
2334 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
2336 $bodycopy->setAttrValue(
'name', $name);
2340 $name = strtolower(str_replace(
' ',
'_', $name));
2342 if (!$bodycopy->create($copy_link, $content)) {
2343 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2344 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2348 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2349 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2368 if (!$name)
return $null;
2369 $am = $GLOBALS[
'SQ_SYSTEM']->am;
2371 $folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'bodycopies_folder');
2372 if (empty($folder_link))
return $null;
2374 $folder = $am->getAsset($folder_link[
'minorid'], $folder_link[
'minor_type_code']);
2375 if (is_null($folder))
return $null;
2377 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($folder->id, $link_type,
'bodycopy', TRUE, $name);
2378 if (empty($bodycopy_link))
return $null;
2380 $bodycopy = $am->getAsset($bodycopy_link[
'minorid'], $bodycopy_link[
'minor_type_code']);
2405 if (!file_exists($this->data_path.
'/content_file.php')) {
2406 if (!$edit_fns->generateStandardContentFile($this)) {
2410 include($this->data_path.
'/content_file.php');
2414 if (!file_exists($this->data_path.
'/content_file_questions.php')) {
2415 if (!$edit_fns->generateQuestionsContentFile($this)) {
2419 include($this->data_path.
'/content_file_questions.php');
2442 if ($this->
attr(
'multi_page')) {
2449 if ($this->
attr(
'use_confirmation_page')) {
2468 if ($this->
attr(
'use_bodycopy_confirmation')) {
2469 $bodycopy = $this->
getBodycopy(
'Confirmation Page Contents');
2470 $keyword_list = $bodycopy->getKeywords();
2473 $keyword_list = extract_keywords($contents);
2477 $replacements = Array();
2478 if (!empty($keyword_list)) {
2479 foreach ($keyword_list as $keyword) {
2480 $lookup_keyword = $keyword;
2483 if (($keyword ===
'form_info') || ($keyword ==
'form_summary')) {
2484 $lookup_keyword = $keyword.
'_html';
2490 if ($this->
attr(
'use_bodycopy_confirmation')) {
2492 $bodycopy->setKeywordReplacements($replacements);
2493 $bodycopy->printBody();
2494 $contents = ob_get_clean();
2496 replace_keywords($contents, $replacements);
2516 if ($this->
attr(
'require_captcha')) {
2518 <p>%form_captcha%</p>
2522 %submit_button% %previous_page_button%
2524 $contents = ob_get_clean();
2543 return $edit->generateStandardContentFile($this);
2561 public function processPage($page_number, $validate_page=TRUE, $mute_errors=FALSE)
2566 $one_page_captcha_status = FALSE;
2568 if (is_null($this->submission_errors)) $this->submission_errors = Array();
2575 if ($validate_page && isset($_POST[
'SQ_SYSTEM_SECURITY_KEY_VALUE'])) {
2576 if (validate_security_key()) {
2579 if (!empty($submission)) {
2580 $submission->setAttrValue(
'captcha_status', TRUE);
2581 $submission->saveAttributes(FALSE, $this->
attr(
'log_submissions'));
2582 }
else if (isset($_SESSION[
'SQ_FORM_'.$this->
id.
'_SUBMISSION'])) {
2583 $submission_var =& $_SESSION[
'SQ_FORM_'.$this->id.
'_SUBMISSION'];
2584 $submission_var[
'captcha_status'] = TRUE;
2586 $one_page_captcha_status = TRUE;
2590 $this->submission_errors = array_merge($this->submission_errors, Array($this->
attr(
'captcha_invalid_error_message')));
2597 if (!empty($submission)) {
2598 $captcha_status = $submission->attr(
'captcha_status');
2599 }
else if (isset($_SESSION[
'SQ_FORM_'.$this->
id.
'_SUBMISSION'])) {
2600 $submission_var =& $_SESSION[
'SQ_FORM_'.$this->id.
'_SUBMISSION'];
2601 $captcha_status = array_get_index($submission_var,
'captcha_status', FALSE);
2602 }
else if ($one_page_captcha_status === TRUE) {
2603 $captcha_status = TRUE;
2605 $captcha_status = FALSE;
2611 $submission_limit = $this->
attr(
'submission_limit');
2613 $error_text = $this->
attr(
'submission_limit_reached_text');
2614 $this->submission_errors = array_merge($this->submission_errors, Array($error_text));
2619 if (($page_number == $this->
getTotalPages()) && !in_array($this->
attr(
'captcha_invalid_error_message'),$this->submission_errors) && $validate_page && !$captcha_status && $this->
attr(
'require_captcha')) {
2620 $this->submission_errors = array_merge($this->submission_errors, Array($this->
attr(
'captcha_form_invalid_error_message')));
2625 $questions_to_verify = $this->
attr(
'mollom_questions_to_check');
2626 $mollom_parameters = Array();
2629 for (reset($questions); $question =& $questions[key($questions)]; next($questions)) {
2632 if (isset($_POST[
'SQ_FORM_'.$this->
id.
'_PAGE'])) {
2633 $question->populate($this);
2634 $content_type = isset($questions_to_verify[$question->id]) ? $questions_to_verify[$question->id] : -1;
2635 if ($content_type > -1) {
2636 $mollom_parameters[$content_type] = $question->getValue();
2642 $question_type = strtolower($question->type());
2643 $valid_value = $question->hasValidValue(NULL, FALSE);
2645 if (!$valid_value && (($question_type ==
'form_question_type_file_upload') || $validate_page)) {
2647 if (!$mute_errors) {
2648 $this->submission_errors = array_merge($this->submission_errors, $question->failed_rules);
2653 $this->current_answers[$question->id] = $question->getValue();
2654 $this->extra_data[$question->id] = $question->getExtraData();
2658 if ($ok && $this->
attr(
'use_mollom') && !empty($mollom_parameters)) {
2661 switch ($mollom_result) {
2662 case SQ_MOLLOM_SPAM:
2664 $error_text = $this->
attr(
'mollom_spam_submission_text');
2666 $mollom_error = $error_text;
2668 $mollom_error = translate(
'cms_form_mollom_spam_submission_message');
2672 case SQ_MOLLOM_UNSURE:
2674 $error_text = $this->
attr(
'mollom_unsure_submission_text');
2676 $mollom_error = $error_text;
2678 $mollom_error = translate(
'cms_form_mollom_unsure_spam_submission_message');
2686 case SQ_MOLLOM_UNKNOWN:
2690 case SQ_MOLLOM_INCORRECT_CAPTCHA:
2691 $error_text = $this->
attr(
'mollom_captcha_incorrect_text');
2693 $mollom_error = $error_text;
2695 $mollom_error = translate(
'cms_form_mollom_invalid_captcha_message');
2700 if (!empty($mollom_error)) {
2701 $this->submission_errors = array_merge($this->submission_errors, Array($mollom_error));
2720 if (empty($this->current_answers) && empty($this->extra_data))
return;
2723 foreach (array_keys($questions) as $key) {
2724 if (array_key_exists($key, $this->current_answers)) {
2725 $question = $questions[$key];
2726 $question->setValue($this->current_answers[$question->id]);
2729 if (array_key_exists($key, $this->extra_data)) {
2730 $question = $questions[$key];
2731 $extra_data = $this->extra_data[$question->id];
2732 if (!empty($extra_data)) {
2733 $question->setExtraData($this->extra_data[$question->id]);
2749 if (!empty($this->submission_errors)) {
2751 foreach ($this->submission_errors as $error) {
2774 $submission_id = $submission->id;
2775 $submission_ip = $submission->getIP();
2778 echo
'<submission time="'.str_replace(
' ',
'T', ts_iso8601((is_null($time) ? time() : $time))).
'"';
2779 echo
' ip="'.$submission_ip.
'"';
2780 echo
' assetid="'.$submission_id.
'"';
2781 if (!is_null($cur_user = $GLOBALS[
'SQ_SYSTEM']->user)) {
2782 echo
' user="'.$cur_user->id.
'"';
2787 $sort_order = $this->
attr(
'sort_order');
2789 foreach ($sort_order as $sort_order_index => $assetid) {
2792 if ($this->
id == strtok($assetid,
':')) {
2793 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2794 echo $question->getXML($question->getValue());
2801 for (reset($sections); NULL !== ($k = key($sections)); next($sections)) {
2802 $section =& $sections[$k];
2803 echo
'<section id="'.$section->id.
'" name="'.$section->attr(
'name').
'">';
2805 $sort_order = $section->attr(
'sort_order');
2807 foreach ($sort_order as $sort_order_index => $assetid) {
2810 if ($section->id == strtok($assetid,
':')) {
2811 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2812 echo $question->getXML($question->getValue($assetid));
2821 echo
'</submission>';
2823 $contents = ob_get_contents();
2841 echo ($html) ?
'<table>' :
'';
2844 $sort_order = $this->
attr(
'sort_order');
2846 foreach ($sort_order as $sort_order_index => $assetid) {
2849 if ($this->
id == strtok($assetid,
':')) {
2850 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2851 echo ($html) ?
'<tr><td><ul><li>' :
'';
2852 echo $question->attr(
'name');
2853 echo ($html) ?
': </li></ul></td><td>' :
' : ';
2855 echo htmlspecialchars($question->getSummary(), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
2857 echo $question->getSummary();
2859 echo ($html) ?
'</td></tr>' :
"\n";
2866 for (reset($sections); NULL !== ($k = key($sections)); next($sections)) {
2867 $section =& $sections[$k];
2868 $section->current_answers =& $this->current_answers;
2869 $section->extra_data =& $this->extra_data;
2870 echo ($html) ?
'<tr><td colspan="2">' :
"\n";
2871 echo ($html) ?
'<strong>'.$section->attr(
'name').
'</strong>' :
'** '.$section->attr(
'name').
' **';
2872 echo ($html) ?
'</td></tr>' :
"\n\n";
2874 $sort_order = $section->attr(
'sort_order');
2876 foreach ($sort_order as $sort_order_index => $assetid) {
2879 if ($section->id == strtok($assetid,
':')) {
2880 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2881 echo ($html) ?
'<tr><td><ul><li>' :
'';
2882 echo $question->attr(
'name');
2883 echo ($html) ?
': </li></ul></td><td>' :
' : ';
2885 echo htmlspecialchars($question->getSummary(), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
2887 echo $question->getSummary();
2889 echo ($html) ?
'</td></tr>' :
"\n";
2893 echo ($html) ?
'' :
"\n";
2896 echo ($html) ?
'</table>' :
'';
2904 public function printSemanticSummary()
2906 echo
'<ul id="sq-form-summary-semantic-'.$this->id.
'" class="sq-form-summary-semantic">'.
"\n";
2910 echo
'<strong>'.htmlspecialchars($this->
attr(
'unattached_page_name'), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET).
'</strong>'.
"\n";
2912 foreach ($this->
attr(
'sort_order') as $sort_order => $question_assetid) {
2915 if ($this->
id == strtok($question_assetid,
':')) {
2916 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($question_assetid);
2917 echo
'<dt>'.$question->attr(
'name').
'</dt>'.
"\n";
2918 echo
'<dd>'.htmlspecialchars($question->getSummary(), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET).
'</dd>'.
"\n";
2928 foreach ($section_links as $section_link) {
2930 $section = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_link[
'minorid']);
2931 echo
'<strong>'.htmlspecialchars($section->attr(
'name'), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET).
'</strong>'.
"\n";
2932 $section->printSemanticSummary();
2950 $am = $GLOBALS[
'SQ_SYSTEM']->am;
2952 $lineage = $am->getLineageFromURL();
2953 foreach ($lineage as $asset) {
2954 $info[$asset[
'type_code'].
'_name'] = $asset[
'name'];
2955 $info[$asset[
'type_code'].
'_id'] = $asset[
'assetid'];
2957 $info[
'url'] = current_url(TRUE, TRUE);
2959 if (!is_null($this->submission_asset)) {
2960 $info[
'submission_id'] = $this->submission_asset->id;
2982 if (!$this->
attr(
'use_client_side'))
return '';
2984 $keywords = Array();
2985 $use_bc = ($this->
attr(
'use_bodycopy_main') == 1) ? TRUE : FALSE;
2990 $keywords = $bc->getKeywords();
2994 if (in_array(
'form_contents', $keywords) || in_array(
'current_page_contents', $keywords)) {
2998 $section_keywords = Array();
2999 foreach($keywords as $keyword) {
3000 if (strpos($keyword,
'section_contents_') !== FALSE) {
3001 $section_id = substr($keyword, strlen(
'section_contents_'));
3002 if ($GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($section_id, Array(
'form_section'))) {
3003 $section = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_id);
3004 $s_questions = array_keys($section->getQuestions());
3005 foreach($s_questions as $q_id) {
3006 $q_keyword =
'question_field_'.$section_id.
'_q'.$q_id;
3007 if (!in_array($q_keyword, $keywords)) {
3008 $section_keywords[] = $q_keyword;
3011 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($section);
3017 $keywords = array_merge($keywords, $section_keywords);
3023 submission_errors =
new Array();
3025 $code = ob_get_contents();
3028 if (!in_array(
'form_contents', $keywords) && !$use_bc && $this->
attr(
'multi_page')) {
3035 foreach (array_keys($questions) as $key) {
3036 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($key);
3039 $keyword_search =
'question_field_'.str_replace(
':',
'_', $question->id);
3040 if (in_array($keyword_search, $keywords)) {
3042 $q_code = $question->generateJSCode();
3045 $q_code = $question->generateJSCode();
3047 $code .= $q_code.(empty($q_code) ?
'' :
"\n");
3064 if (empty($code))
return '';
3068 <script
type=
"text/javascript">
3069 function beforeSubmit_<?php echo $this->
getPrefix() ?>(form)
3071 var submission_errors =
new Array();
3074 <?php echo $code; ?>
3076 if (submission_errors.length > 0) {
3077 var errors_list =
"<?php echo translate('cms_form_submission_errors'); ?>\n";
3078 for(x in submission_errors) {
3079 errors_list += submission_errors[x] +
"\n";
3089 $code = ob_get_contents();
3123 if($this->
attr(
'multi_page')) {
3124 foreach ($all_questions as $assetid => $question_info) {
3125 $question_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
3126 if(!$question_asset->hasValidValue()) {
3127 $this->submission_errors = array_merge($this->submission_errors, $question_asset->failed_rules);
3133 if(!$ok)
return FALSE;
3135 foreach ($all_questions as $assetid => $question_info) {
3136 $type_code = $question_info[
'question_type_code'];
3137 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
3138 if (method_exists($type_code,
'onSubmitForm')) {
3139 $question_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
3140 $question_asset->onSubmitForm($this);
3142 if (!empty($question_asset->failed_rules)) {
3143 if (!is_array($this->submission_errors)) $this->submission_errors = Array();
3144 $this->submission_errors = array_merge($this->submission_errors, $question_asset->failed_rules);
3152 if ($this->
attr(
'log_submissions')) {
3153 if ($GLOBALS[
'SQ_SYSTEM']->userPublic()) {
3156 $this->submission_asset = $submission_asset;
3161 $incomplete_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'incomplete_submissions');
3162 if ($incomplete_link) {
3163 $complete_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'submissions_folder');
3165 $submission_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($incomplete_link[
'minorid'], $submission_asset->id);
3166 if ($submission_link) {
3171 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
3172 $GLOBALS[
'SQ_SYSTEM']->am->moveLink($submission_link[
'linkid'], $complete_link[
'minorid'], SQ_LINK_TYPE_3, 0);
3173 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
3183 $submission_asset->setIP($_SERVER[
'REMOTE_ADDR']);
3184 $submission_asset->setAttrValue(
'complete', TRUE);
3185 $submission_asset->setAttrValue(
'submitted', ts_iso8601(time()));
3186 $submission_asset->setAttrValue(
'xml', $this->
getXML());
3187 $submission_asset->saveAttributes();
3194 if ($submission_asset) {
3195 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_SECURITY_LINK_INTEGRITY);
3196 $GLOBALS[
'SQ_SYSTEM']->am->trashAsset($submission_asset->id);
3197 $submission_asset->delete();
3198 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
3223 foreach (array_keys($file_uploads) as $assetid) {
3224 $file_upload = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
3226 $create_location = $file_upload->attr(
'create_location');
3227 if (empty($create_location)) {
3228 $extra_data = $file_upload->getExtraData();
3229 if (!empty($extra_data[
'temp_filesystem_path'])) {
3230 $filename = $file_upload->getValue();
3231 $perm_path = $submission_asset->data_path.
'/attachments/'.str_replace(
':',
'_', $file_upload->id);
3234 create_directory($perm_path);
3235 $moved = move_file($extra_data[
'temp_filesystem_path'], $perm_path.
'/'.$filename);
3236 if ($moved) delete_directory(dirname($extra_data[
'temp_filesystem_path']));
3238 $extra_data = Array(
3239 'filesystem_path' => $perm_path.
'/'.$filename,
3242 $file_upload->setExtraData($extra_data);
3243 $submission_asset->setExtraData($assetid, $extra_data);
3246 $extra_data = $file_upload->getExtraData();
3247 $uploaded_assetid = array_get_index($extra_data,
'existing_file_assetid', array_get_index($extra_data,
'new_file_assetid', NULL));
3249 if (!empty($uploaded_assetid)) {
3250 $uploaded_file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($uploaded_assetid);
3252 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
3253 $this->submission_asset->createLink($uploaded_file, SQ_LINK_NOTICE,
'file_submission');
3254 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
3274 $summary_info = ob_get_contents();
3278 if ($this->
attr(
'use_bodycopy_thank_you') && $tyb && !$tyb->isEmpty()) {
3280 if ($this->
attr(
'show_results')) {
3281 $keyword_list = $tyb->getKeywords();
3282 $replacements = Array();
3284 foreach ($keyword_list as $keyword) {
3285 $lookup_keyword = $keyword;
3289 if (($keyword ===
'form_info') || ($keyword ==
'form_summary')) {
3290 $lookup_keyword = $keyword.
'_html';
3294 $replacements[$keyword] = $replacement;
3297 $tyb->setKeywordReplacements($replacements);
3306 if ($this->
attr(
'show_results')) echo $summary_info;
3313 foreach ($all_questions as $assetid => $question_info) {
3314 $type_code = $question_info[
'question_type_code'];
3315 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
3316 if (method_exists($type_code,
'onSubmitForm')) {
3317 $question_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
3318 $question_asset->cleanUp($this);
3322 if (!is_null($this->submission_asset)) {
3323 $submission_path = $this->data_path.
'/incomplete_attachments/s'.$this->submission_asset->id;
3324 if (is_dir($submission_path)){
3325 $dirs = list_dirs($submission_path);
3326 if (empty($dirs)) delete_directory($submission_path);
3330 $public_submission_path = $this->data_path.
'/incomplete_attachments/'.session_id();
3331 if (is_dir($public_submission_path)){
3332 $dirs = list_dirs($public_submission_path);
3333 if (empty($dirs)) delete_directory($public_submission_path);
3337 unset($_SESSION[
'SQ_FORM_'.$this->
id.
'_SUBMISSION']);
3360 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE, $link_value);
3361 if (!empty($link)) {
3362 $res = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'],
'folder');
3380 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3385 if ($existing_folder) {
3386 return $existing_folder;
3389 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
3390 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
3392 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
3394 $create_info = Array(
3396 'link_type' => SQ_LINK_TYPE_2,
3397 'value' => $link_value,
3398 'is_dependant' => 1,
3399 'is_exclusive' => 1,
3402 $folder->setAttrValue(
'name', $folder_name);
3403 if (!$folder->create($create_info)) {
3411 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
3413 $public_userid = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
3415 if (!$am->setPermission($folder->id, $public_userid, SQ_PERMISSION_WRITE, 0, TRUE, TRUE)) {
3420 if (!$am->setPermission($folder->id, $public_userid, SQ_PERMISSION_READ, 0, TRUE, TRUE)) {
3424 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
3430 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
3432 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
3436 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
3455 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3457 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
3458 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
3459 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'form_submission');
3461 if ($create_in_completed) {
3462 $link_value =
'submissions_folder';
3464 $link_value =
'incomplete_submissions';
3470 if (is_null($submissions_folder)) {
3474 if (!$create_in_completed) {
3475 $submissions_folder = $this->
createSubmissionsFolder(translate(
'cms_form_incomplete_submissions'),
'incomplete_submissions');
3478 if (is_null($submissions_folder)) {
3479 trigger_localised_error(
'CMS0069', E_USER_WARNING);
3485 'asset' => $submissions_folder,
3486 'link_type' => SQ_LINK_TYPE_3,
3487 'is_dependant' => 0,
3488 'is_exclusive' => 0,
3491 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
3493 if (!$submission_asset->create($copy_link)) {
3494 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
3495 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
3496 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
3500 $submission_asset->setAttrValue(
'complete', FALSE);
3502 $submission_asset->setAttrValue(
'current_page', 1);
3503 $submission_asset->saveAttributes(FALSE, $this->
attr(
'log_submissions'));
3507 $public_userid = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
3508 $current_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserid();
3509 if ((
string)$current_userid !== (
string)$public_userid) {
3510 if (!$am->setPermission($submission_asset->id, $current_userid, SQ_PERMISSION_WRITE, 1, TRUE, TRUE)) {
3511 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
3512 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
3513 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
3518 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
3519 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
3520 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
3522 return $submission_asset;
3535 if (!$this->submission_asset) {
3537 $submission_assetid = array_get_index($_POST,
'SQ_FORM_'.$this->
id.
'_SUBMISSION', NULL);
3538 if (is_null($submission_assetid)) {
3539 $submission_assetid = array_get_index($_GET,
'SQ_FORM_'.$this->
id.
'_SUBMISSION', NULL);
3543 if (!is_null($submission_assetid)) {
3544 $this->submission_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($submission_assetid,
'form_submission');
3546 if (!$this->submission_asset || !$this->submission_asset->writeAccess()) {
3547 $this->submission_asset = NULL;
3551 if (!$this->submission_asset) {
3552 $this->submission_asset = NULL;
3556 if ($this->submission_asset) {
3557 $answers = $this->submission_asset->getAnswers();
3558 foreach ($answers as $assetid => $response) {
3559 if (is_string($response[
'answer'])) {
3560 $response[
'answer'] = html_entity_decode($response[
'answer']);
3562 $this->current_answers[$assetid] = $response[
'answer'];
3563 $this->extra_data[$assetid] = array_get_index($response,
'extra_data',
'');
3569 return $this->submission_asset;
3583 foreach ($this->current_answers as $assetid => $response) {
3584 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
3588 $question->saveValue($this);
3591 if ($question->attr(
'sticky')) {
3592 $question->stickValue($question->getValue());
3596 $value = $question->getValue();
3597 if (is_string($value)) {
3598 $value = htmlspecialchars($value, ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
3600 if ($value !== $submission_asset->
getAnswer($assetid)) {
3601 $submission_asset->
setAnswer($assetid, $value);
3605 if ($question->getExtraData() !== $submission_asset->
getExtraData($assetid)) {
3606 $submission_asset->
setExtraData($assetid, $question->getExtraData());
3609 $submission_asset->
setSummary($assetid, $question->attr(
'name'), htmlspecialchars($question->getSummary(), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET));
3616 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3617 $applied_schemas = $mm->getSchemas($submission_asset->id);
3618 if (!empty($applied_schemas)) {
3619 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
3620 $em->broadCastEvent($submission_asset,
'MetadataUpdate', Array(
'all'));
3635 if ($GLOBALS[
'SQ_SYSTEM']->userPublic()) {
3640 if (!$incomplete_folder) {
3644 $sql_parts = $GLOBALS[
'SQ_SYSTEM']->am->generateGetChildrenQuery($incomplete_folder,
'form_submission', FALSE);
3645 $sql_parts[
'sql_array'][
'where'] .=
' AND (a.assetid IN (SELECT assetid FROM sq_vw_ast_perm WHERE userid = :is_userid AND permission >= :is_min_perm AND granted = :is_granted))';
3646 $sql_parts[
'bind_vars'][
'is_userid'] = $GLOBALS[
'SQ_SYSTEM']->currentUserid();
3647 $sql_parts[
'bind_vars'][
'is_min_perm'] = SQ_PERMISSION_WRITE;
3648 $sql_parts[
'bind_vars'][
'is_granted'] =
'1';
3650 $sql = implode(
' ', $sql_parts[
'sql_array']);
3654 foreach ($sql_parts[
'bind_vars'] as $bind_var => $bind_value) {
3659 throw new Exception($e->getMessage());
3674 if ($GLOBALS[
'SQ_SYSTEM']->userPublic()) {
3675 $submission_var =& $_SESSION[
'SQ_FORM_'.$this->id.
'_SUBMISSION'];
3676 $current_page = array_get_index($submission_var,
'current_page', 1);
3679 if ($submission_asset) {
3680 $current_page = $submission_asset->attr(
'current_page');
3686 return $current_page;
3698 if ($GLOBALS[
'SQ_SYSTEM']->userPublic()) {
3699 $submission_var =& $_SESSION[
'SQ_FORM_'.$this->id.
'_SUBMISSION'];
3700 $latest_page = array_get_index($submission_var,
'latest_page',
'1');
3703 if ($submission_asset) {
3704 $latest_page = $submission_asset->attr(
'latest_page');
3710 return $latest_page;
3731 if ($submission_asset) {
3732 $path = $this->data_path.
'/incomplete_attachments/s'.$submission_asset->id;
3734 $path = $this->data_path.
'/incomplete_attachments/'.session_id();
3752 $session_var_name =
'SQ_FORM_'.$this->id.
'_SUBMISSION';
3754 if (!isset($_SESSION[$session_var_name])) {
3755 $_SESSION[$session_var_name] = Array();
3758 $session_var =& $_SESSION[$session_var_name];
3761 if (isset($session_var[$question->id])) {
3765 $this->current_answers[$question->id] = $session_var[$question->id][
'answer'];
3766 $this->extra_data[$question->id] = array_get_index($session_var[$question->id],
'extra_data', Array());
3768 $question->setValue($this->current_answers[$question->id]);
3769 $question->setExtraData($this->extra_data[$question->id]);
3784 $session_var_name =
'SQ_FORM_'.$this->id.
'_SUBMISSION';
3786 if (!isset($_SESSION[$session_var_name])) {
3787 $_SESSION[$session_var_name] = Array();
3790 foreach ($this->current_answers as $assetid => $response) {
3791 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
3794 $question->saveValue($this);
3797 if ($question->attr(
'sticky')) {
3798 $question->stickValue($question->getValue());
3801 if (isset($_SESSION[$session_var_name][$assetid])) {
3802 $current_answer = $_SESSION[$session_var_name][$assetid][
'answer'];
3804 $current_answer = NULL;
3808 if ($question->getValue() !== $current_answer) {
3809 $_SESSION[$session_var_name][$assetid][
'answer'] = $question->getValue();
3812 $_SESSION[$session_var_name][$assetid][
'name'] = $question->attr(
'name');
3813 $_SESSION[$session_var_name][$assetid][
'summary'] = $question->getSummary();
3814 $_SESSION[$session_var_name][$assetid][
'extra_data'] = $question->getExtraData();
3847 if (!isset($vars[
'keywords']))
return;
3851 $bc_parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id);
3852 if (!in_array(
'form_section', $bc_parents)) {
3854 $keywords = Array();
3856 $folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'bodycopies_folder');
3858 $folder = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($folder_link[
'minorid'], $folder_link[
'minor_type_code']);
3860 if (is_null($folder))
return FALSE;
3864 $bodycopy_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($folder->id, SQ_LINK_TYPE_2,
'bodycopy');
3865 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'bodycopy', TRUE);
3867 $bodycopy_code = NULL;
3868 foreach ($bodycopy_links as $link_info) {
3869 if (isset($parents[$link_info[
'minorid']])) {
3870 $bodycopy_code = $link_info[
'value'];
3875 if (is_null($bodycopy_code))
return;
3877 $keywords = @$this->_tmp[
'keywords'][$bodycopy_code];
3878 if (is_null($keywords) || !is_array($keywords)) {
3879 $keywords = Array();
3881 $keyword_provider_method =
'_get'.str_replace(
' ',
'',ucfirst($bodycopy_code)).
'BodycopyKeywords';
3883 if (method_exists($this, $keyword_provider_method)) {
3884 $keywords = $this->$keyword_provider_method();
3885 $this->_tmp[
'keywords'][$bodycopy_code] = $keywords;
3889 $vars[
'keywords'] = array_merge($vars[
'keywords'], $keywords);
3907 $keywords[
'form_contents'] = translate(
'cms_form_contents');
3908 $keywords[
'current_page_contents'] = translate(
'cms_current_page_contents');
3909 $keywords[
'form_errors'] = translate(
'cms_form_errors');
3910 $keywords[
'form_errors_message'] = translate(
'cms_form_errors_message');
3912 foreach ($questions as $question) {
3913 $keywords[
'question_name_' .$question->id] = translate(
'cms_form_question_name', ellipsisize($question->attr(
'name'), 30)).
' ('.$question->id.
')';
3917 foreach ($sections as $section) {
3918 $keywords[
'section_title_'.$section->id] =
'Section Name: '.$section->attr(
'name').
' ('.$section->id.
')';
3919 $keywords[
'section_contents_'.$section->id] =
'Section Contents: '.$section->attr(
'name').
' ('.$section->id.
')';
3920 $keywords += $section->getDisplayKeywords(FALSE);
3924 $keywords[
'reset_button'] = translate(
'cms_form_reset_button');
3925 $keywords[
'submit_button'] = translate(
'cms_form_submit_button');
3928 $keywords[
'previous_page_button'] = translate(
'cms_form_previous_page_button');
3933 if ($this->
attr(
'use_mollom')) {
3950 $keywords[
'form_submissions_limit'] = translate(
'cms_form_submissions_limit');
3951 $keywords[
'form_submissions_count'] = translate(
'cms_form_submissions_count');
3952 $keywords[
'form_submissions_left'] = translate(
'cms_form_submissions_left');
3970 $keywords[
'form_summary'] = translate(
'cms_form_submission_summary');
3971 $keywords[
'form_summary_html'] = translate(
'cms_form_submission_summary').
' (html)';
3972 $keywords[
'form_info'] = translate(
'cms_form_submission_info');
3973 $keywords[
'form_info_html'] = translate(
'cms_form_submission_info').
' (html)';
3974 $keywords[
'form_submission_id'] = translate(
'cms_form_submission_id');
3975 $keywords[
'form_submission_ip_address'] = translate(
'cms_form_submission_ip_address');
3976 $keywords[
'form_submission_time'] = translate(
'cms_form_submission_time_format', translate(
'date_format_default'));
3978 foreach (get_date_format_names() as $date_name => $date_format) {
3979 $keywords[
'form_submission_time_'.$date_name] = translate(
'cms_form_submission_time_format', translate(
'date_format_'.$date_name));
3982 foreach ($questions as $q_id => $question) {
3983 $q_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id.
':q'.$q_id);
3984 $q_name = $q_asset->attr(
'name');
3985 $keywords[
'response_'.$this->id.
'_q'.$q_id] = translate(
'cms_form_question_response', ellipsisize($q_name,30));
3986 $keywords[
'question_name_'.$this->id.
'_q'.$q_id] = translate(
'cms_form_question_name', ellipsisize($q_name,30));
3987 $keywords[
'question_note_'.$this->id.
'_q'.$q_id] = translate(
'cms_form_question_note', ellipsisize($q_name,30));
3990 foreach ($sections as $section) {
3991 $keywords[
'section_title_'.$section->id] = translate(
'cms_form_section_title', $section->attr(
'name'));
3992 $keywords += $section->getResponseKeywords();
4011 $keywords = Array();
4013 $keywords[
'form_summary'] = translate(
'cms_form_submission_summary');
4014 $keywords[
'form_info'] = translate(
'cms_form_submission_info');
4016 foreach ($questions as $question) {
4020 foreach ($sections as $section) {
4021 $keywords[
'section_title_'.$section->id] =
'Section Name: '.$section->attr(
'name').
' ('.$section->id.
')';
4022 $keywords += $section->getResponseKeywords();
4026 $keywords[
'reset_button'] = translate(
'cms_form_reset_button');
4027 $keywords[
'submit_button'] = translate(
'cms_form_submit_button');
4028 $keywords[
'previous_page_button'] = translate(
'cms_form_previous_page_button');
4050 assert_true(($parent instanceof
Form) || ($parent instanceof
Form_Section),
'Argument 2 must be a Form or Form Section asset');
4052 $keywords = Array();
4055 $keyword_assetid = str_replace(
':',
'_', $question->id);
4057 if ($parent instanceof Form_Section) {
4058 $keywords[
'question_field_' .$keyword_assetid] = translate(
'cms_form_section_q_field', $parent->
attr(
'name'), ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4059 $keywords[
'question_name_' .$keyword_assetid] = translate(
'cms_form_section_q_name', $parent->
attr(
'name'), ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4060 $keywords[
'question_id_' .$keyword_assetid] = translate(
'cms_form_section_q_id', $parent->
attr(
'name'), ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4061 $keywords[
'question_note_' .$keyword_assetid] = translate(
'cms_form_section_q_note', $parent->
attr(
'name'), ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4062 $keywords[
'question_label_'.$keyword_assetid] = translate(
'cms_form_section_q_label', $parent->
attr(
'name'), ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4064 $keywords[
'question_field_' .$keyword_assetid] = translate(
'cms_form_question_field', ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4065 $keywords[
'question_name_' .$keyword_assetid] = translate(
'cms_form_question_name', ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4066 $keywords[
'question_id_' .$keyword_assetid] = translate(
'cms_form_question_id', ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4067 $keywords[
'question_note_' .$keyword_assetid] = translate(
'cms_form_question_note', ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4068 $keywords[
'question_label_'.$keyword_assetid] = translate(
'cms_form_question_label', ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4085 $keywords = Array();
4087 $keywords[
'section_title_'.$section->id] = translate(
'cms_form_section_title', $section->
attr(
'name')).
' ('.$section->id.
')';
4110 assert_true(($parent instanceof
Form) || ($parent instanceof
Form_Section),
'Argument 2 must be a Form or Form Section asset');
4112 $keywords = Array();
4115 $keyword_assetid = str_replace(
':',
'_', $question->id);
4117 if ($parent instanceof Form_Section) {
4118 $keywords[
'response_' .$keyword_assetid] = translate(
'cms_form_section_response', $parent->
attr(
'name'), ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4120 $keywords[
'response_' .$keyword_assetid] = translate(
'cms_form_question_response', ellipsisize($question->
attr(
'name'), 30)).
' ('.$question->id.
')';
4135 $keywords = Array();
4137 $keywords[
'form_captcha'] = translate(
'cms_form_captcha');
4138 $keywords[
'form_captcha_image'] = translate(
'cms_form_captcha_image');
4139 $keywords[
'form_captcha_field'] = translate(
'cms_form_captcha_field');
4140 $keywords[
'form_captcha_link'] = translate(
'cms_form_captcha_link');
4155 $keywords = Array();
4157 $keywords[
'form_mollom_captcha'] = translate(
'cms_form_mollom_captcha');
4158 $keywords[
'form_mollom_captcha_image'] = translate(
'cms_form_mollom_captcha_image');
4159 $keywords[
'form_mollom_captcha_audio'] = translate(
'cms_form_mollom_captcha_audio');
4160 $keywords[
'form_mollom_captcha_field'] = translate(
'cms_form_mollom_captcha_field');
4161 $keywords[
'form_mollom_captcha_regen_link'] = translate(
'cms_form_mollom_captcha_link');
4183 $replacement = NULL;
4184 $keyword = parse_keyword($keyword, $modifiers);
4185 $is_question_keyword = preg_match(
'/^question\_(.*)\_(\d+[\_\:]q\d+)$/', $keyword, $question_matches);
4186 $is_response_keyword = preg_match(
'/^response\_(\d+[\_\:]q\d+)(\_raw)?$/', $keyword, $response_matches);
4187 $is_section_keyword = preg_match(
'/^section\_(.*)\_(\d+)$/', $keyword, $section_matches);
4188 $is_form_keyword = preg_match(
'/^form\_(.*)$/', $keyword, $form_matches);
4190 if ($is_question_keyword) {
4194 list(, $sub_keyword, $assetid) = $question_matches;
4195 $assetid = str_replace(
'_',
':', $assetid);
4197 $question_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
4199 if (!empty($question_asset)) {
4201 switch ($sub_keyword) {
4203 $replacement = $question_asset->getHtmlField();
4207 $replacement = $question_asset->attr(
'name');
4211 $replacement =
'q'.str_replace(
':',
'_', $assetid);
4215 $replacement = $question_asset->attr(
'note');
4219 $replacement = $question_asset->getHtmlLabel();
4225 }
else if ($is_section_keyword) {
4228 list(, $sub_keyword, $assetid) = $section_matches;
4230 $section_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
4232 switch ($sub_keyword) {
4234 $replacement = $section_asset->attr(
'name');
4239 include_once($section_asset->data_path.
'/content_file.php');
4240 $replacement = ob_get_clean();
4245 }
else if ($is_response_keyword) {
4246 $raw_response = (count($response_matches) == 3);
4247 list(, $assetid) = $response_matches;
4248 $assetid = str_replace(
'_',
':', $assetid);
4250 $question_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
4251 if (!empty($question_asset)) {
4252 if ($raw_response) {
4253 $replacement = htmlspecialchars($question_asset->getValue(), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
4255 $replacement = htmlspecialchars($question_asset->getSummary(), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
4259 }
else if ($is_form_keyword) {
4260 list(, $sub_keyword) = $form_matches;
4261 switch ($sub_keyword) {
4262 case 'mollom_captcha':
4265 case 'mollom_captcha_field':
4269 case 'mollom_captcha_image':
4273 case 'mollom_captcha_audio':
4277 case 'mollom_captcha_regen_link':
4278 $regen_link_text = $this->
attr(
'mollom_captcha_regen_link_text');
4279 if (empty($regen_link_text)) {
4280 $regen_link_text = translate(
'cms_form_mollom_regen_link_text');
4285 case 'submission_id':
4288 $replacement = $submission->id;
4292 case 'submissions_limit':
4293 $replacement = $this->
attr(
'submission_limit');
4296 case 'submissions_count':
4297 if ($this->
attr(
'log_submissions')) {
4304 case 'submissions_left':
4305 if ($this->
attr(
'log_submissions')) {
4306 $sub_limit = $this->
attr(
'submission_limit');
4308 $replacement = $sub_limit - $sub_done;
4316 if (!is_null($replacement)) {
4317 $replace_keywords = Array(
4318 'assetid' => $this->
id,
4319 'call_fns' => Array (
'getDisplayKeywordReplacement',
'getKeywordReplacement'),
4321 apply_keyword_modifiers($replacement, $modifiers, $replace_keywords);
4324 return $replacement;
4337 if ($this->
attr(
'multi_page')) {
4358 if (is_null($current_page)) {
4361 $replacement = NULL;
4363 if (($current_page == $this->
getTotalPages()) && $this->
attr(
'use_confirmation_page')) {
4364 $replacement = $this->
attr(
'confirmation_page_name');
4367 if ($question_count > 0) $current_page--;
4369 if ($current_page == 0) {
4370 $replacement = $this->
attr(
'unattached_page_name');
4373 $current_section_link = reset(array_slice($sections, $current_page - 1, 1));
4374 $current_section_id = $current_section_link[
'minorid'];
4375 $current_section_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($current_section_id);
4377 $replacement = $current_section_info[$current_section_id][
'name'];
4381 return $replacement;
4426 return ob_get_clean();
4441 return ob_get_clean();
4453 if (!$this->
attr(
'captcha_ttf') ==
'') {
4454 $font = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
attr(
'captcha_ttf'));
4455 $file_path = $font->data_path.
'/'.$font->attr(
'name');
4462 $this->
attr(
'captcha_length'),
4463 $this->
attr(
'captcha_length'),
4464 $this->
attr(
'captcha_zoom'),
4466 trim($this->
attr(
'captcha_bgcolour'),
'#'),
4467 trim($this->
attr(
'captcha_textcolour'),
'#'),
4468 trim($this->
attr(
'captcha_bordercolour'),
'#'),
4469 $this->
attr(
'captcha_use_colours'),
4470 $this->
attr(
'captcha_usefont'),
4472 $this->
attr(
'captcha_font_size'),
4473 $this->
attr(
'captcha_min_angle'),
4474 $this->
attr(
'captcha_max_angle'),
4475 $this->
attr(
'captcha_x_start'),
4476 $this->
attr(
'captcha_min_distance'),
4477 $this->
attr(
'captcha_max_distance'),
4478 $this->
attr(
'captcha_width'),
4479 $this->
attr(
'captcha_height'),
4480 $this->
attr(
'captcha_arc'),
4481 trim($this->
attr(
'captcha_arc_colour'),
'#'),
4482 $this->
attr(
'captcha_include_uppercase'),
4483 $this->
attr(
'captcha_include_numbers'),
4484 $this->
attr(
'provide_accessible_captcha')
4486 return ob_get_clean();
4499 if (!$this->
attr(
'captcha_ttf') ==
'') {
4500 $font = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
attr(
'captcha_ttf'));
4501 $file_path = $font->data_path.
'/'.$font->attr(
'name');
4507 security_key_image_box(
4508 $this->
attr(
'captcha_length'),
4509 $this->
attr(
'captcha_zoom'),
4510 trim($this->
attr(
'captcha_bgcolour'),
'#'),
4511 trim($this->
attr(
'captcha_textcolour'),
'#'),
4512 trim($this->
attr(
'captcha_bordercolour'),
'#'),
4513 $this->
attr(
'captcha_use_colours'),
4514 $this->
attr(
'captcha_usefont'),
4516 $this->
attr(
'captcha_font_size'),
4517 $this->
attr(
'captcha_min_angle'),
4518 $this->
attr(
'captcha_max_angle'),
4519 $this->
attr(
'captcha_x_start'),
4520 $this->
attr(
'captcha_min_distance'),
4521 $this->
attr(
'captcha_max_distance'),
4522 $this->
attr(
'captcha_width'),
4523 $this->
attr(
'captcha_height'),
4524 $this->
attr(
'captcha_arc'),
4525 trim($this->
attr(
'captcha_arc_colour'),
'#'),
4526 $this->
attr(
'captcha_include_uppercase'),
4527 $this->
attr(
'captcha_include_numbers'),
4528 $this->
attr(
'provide_accessible_captcha')
4530 return ob_get_clean();
4544 security_key_field($this->
attr(
'captcha_length'));
4545 return ob_get_clean();
4559 security_key_image_link($this->
attr(
'captcha_link_text'));
4560 return ob_get_clean();
4573 if (empty($this->submission_errors))
return '';
4577 return ob_get_clean();
4590 if (empty($this->submission_errors))
return '';
4592 return $this->
attr(
'submission_errors_msg');
4608 if ($current_page >= $total_pages) {
4609 $button_name = ($this->
attr(
'submit_button')) ? $this->
attr(
'submit_button') : translate(
'submit');
4611 $button_name = ($this->
attr(
'next_button')) ? $this->
attr(
'next_button') : translate(
'next');
4615 submit_button($this->
getPrefix().
'_submit', $button_name,
'', $this->
attr(
'submit_button_extras'));
4616 return ob_get_clean();
4629 $button_name = ($this->
attr(
'save_button')) ? $this->
attr(
'save_button') : translate(
'save');
4632 submit_button($this->
getPrefix().
'_save', $button_name);
4633 return ob_get_clean();
4647 if (isset($_POST[$prefix.
'_save'])) {
4648 $message = ($this->
attr(
'save_confirmation_message')) ? $this->
attr(
'save_confirmation_message') : translate(
'cms_form_save_confirmation');
4667 $bodycopy = $this->
getBodycopy(
'Exit Page Contents');
4670 $button_name = ($this->
attr(
'save_and_exit_button')) ? $this->
attr(
'save_and_exit_button') : translate(
'save_and_exit');
4673 submit_button($this->
getPrefix().
'_save_and_exit', $button_name);
4674 $replacement = ob_get_clean();
4676 $replacement = NULL;
4679 return $replacement;
4692 $button_name = ($this->
attr(
'reset_button')) ? $this->
attr(
'reset_button') : translate(
'reset');
4695 reset_button($this->
getPrefix().
'_reset', $button_name,
'', $this->
attr(
'reset_button_extras'));
4696 return ob_get_clean();
4712 if ($current_page > 1) {
4713 $button_name = ($this->
attr(
'previous_button')) ? $this->
attr(
'previous_button') : translate(
'previous_page');
4715 submit_button($this->
getPrefix().
'_previous_page', $button_name);
4716 $replacement = ob_get_clean();
4721 return $replacement;
4741 $page_list_format = $this->
attr(
'page_list_format');
4742 $keywords = extract_keywords($page_list_format);
4745 <ul
class=
"sq-form-page-list">
4747 for ($page_number = 1; $page_number <= $total_pages; $page_number++) {
4749 $page_entry = $page_list_format;
4750 $replacements = Array();
4752 $replacements[
'page_number'] = htmlspecialchars($page_number, ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
4753 $replacements[
'total_pages'] = htmlspecialchars($total_pages, ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
4756 replace_keywords($page_entry, $replacements);
4758 $page_has_link = ($page_number <= $latest_page) && ($page_number != $current_page);
4760 $style_classes = Array();
4761 if ($page_number == $current_page) {
4762 $style_classes[] =
'sq-form-current-page-number';
4763 }
else if ($page_number > $latest_page) {
4764 $style_classes[] =
'sq-form-unseen-page-number';
4765 }
else if ($page_number > $current_page) {
4766 $style_classes[] =
'sq-form-later-page-number';
4768 $style_classes[] =
'sq-form-prior-page-number';
4771 if ($page_number == $latest_page) {
4772 $style_classes[] =
'sq-form-last-seen-page-number';
4775 <li<?php echo !empty($style_classes) ?
' class="'.implode(
' ', $style_classes).
'"' :
'' ?>><?php
4776 if ($page_has_link) {
4777 ?><a href=
"<?php echo $this->getURL() ?>?SQ_FORM_<?php echo $this->id ?>_PAGE=<?php echo $page_number ?><?php
4778 if ($submission_asset) {
4779 echo '&SQ_FORM_'.$this->id.'_SUBMISSION='.$submission_asset->id;
4786 if ($page_has_link) {
4793 return ob_get_clean();
4810 $replacement =
'%'.$keyword.
'%';
4812 $keyword = parse_keyword($keyword, $modifiers);
4817 if ($keyword ===
'form_info_html') {
4823 }
else if ($keyword ===
'form_info_text') {
4829 }
else if ($keyword ===
'form_summary_html') {
4835 $replacement = ob_get_contents();
4838 }
else if ($keyword ===
'form_summary_semantic') {
4842 $this->printSemanticSummary();
4843 $replacement = ob_get_contents();
4846 }
else if ($keyword ===
'form_summary_text') {
4852 $replacement = ob_get_contents();
4855 }
else if ($keyword ===
'form_submission_id') {
4859 if (!is_null($this->submission_asset)) {
4860 $replacement = $this->submission_asset->id;
4863 }
else if (preg_match(
'|^form_submission_time(_?.*)|', $keyword, $matches)) {
4869 if (empty($matches[1])) {
4870 $date_format =
'Y-m-d H:i:s';
4872 $date_format = substr($matches[1], 1);
4875 if (!is_null($this->submission_asset)) {
4876 $date_formats_list = get_date_formats();
4877 if (array_key_exists($date_format, $date_formats_list)) {
4878 $replacement = format_date($this->submission_asset->created, $date_format);
4880 $replacement = date($date_format, $this->submission_asset->created);
4884 }
else if ($keyword ===
'form_submission_ip_address') {
4890 $ip_address = $_SERVER[
'REMOTE_ADDR'];
4891 $replacement = $ip_address;
4893 }
else if (preg_match(
'|^form_asset_(.*)|', $keyword, $matches)) {
4897 $parent_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'page_custom_form', FALSE, NULL,
'minor');
4898 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parent_link[
'majorid']);
4900 $form_keyword =
'asset_'.$matches[1];
4901 $asset_replacement = $parent_asset->getKeywordReplacement($form_keyword);
4902 if ($asset_replacement !==
"%$form_keyword%") {
4903 $replacement = $asset_replacement;
4910 if (empty($this->_tmp[
'keyword_cache'])) {
4911 $this->_tmp[
'keyword_cache'][
'questions'] = $this->
getQuestions();
4912 $this->_tmp[
'keyword_cache'][
'sections' ] = $this->
getSections();
4915 $questions =& $this->_tmp[
'keyword_cache'][
'questions'];
4916 $sections =& $this->_tmp[
'keyword_cache'][
'sections'];
4918 if (preg_match(
'|^section_title_(.*)|', $keyword, $matches)) {
4922 $section_assetid = $matches[1];
4923 $section_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_assetid,
'form_section');
4924 if (!empty($section_asset)) {
4925 $replacement = $section_asset->attr(
'name');
4928 }
else if (preg_match(
'|^question_([^_]*)_([^_]*_)?q(.*)|', $keyword, $matches)) {
4934 $question_keyword = $matches[1];
4935 if (empty($matches[2])) {
4937 $section_assetid = $this->id;
4938 $question_assetid = $matches[3];
4940 $section_assetid = str_replace(
'_',
'', $matches[2]);
4941 $question_assetid = $matches[3];
4944 $question_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_assetid.
':q'.$question_assetid);
4945 if (!empty($question_asset)) {
4946 switch ($question_keyword) {
4948 $replacement = $question_asset->attr(
'name');
4952 $replacement = $question_asset->attr(
'note');
4957 }
else if (preg_match(
'|^response_([0-9]*_)?q([0-9]*)?(_raw)?|', $keyword, $matches)) {
4962 if (empty($matches[1])) {
4964 $section_assetid = $this->id;
4965 $question_assetid = $matches[2];
4967 $section_assetid = str_replace(
'_',
'', $matches[1]);
4968 $question_assetid = $matches[2];
4971 $raw = (array_get_index($matches, 3,
'') ==
'_raw');
4973 $question_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_assetid.
':q'.$question_assetid);
4974 if (!empty($question_asset)) {
4976 $value = $question_asset->getValue();
4977 if (is_string($question_asset->getValue())) {
4978 $replacement = htmlspecialchars($question_asset->getValue(), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
4983 $replacement = htmlspecialchars($question_asset->getSummary(), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
4992 if ($replacement ==
'%'.$keyword.
'%') {
4996 $replace_keywords = Array(
4997 'assetid' => $this->
id,
4998 'call_fns' => Array (
'_getThankYouKeywordReplacement',
'getKeywordReplacement'),
5000 apply_keyword_modifiers($replacement, $modifiers, $replace_keywords);
5002 return $replacement;
5019 if ($this->
attr(
'multi_page')) {
5024 $section_link = reset(array_slice($section_links, $page_number - 1, 1));
5025 if (isset($section_link[
'minorid'])) {
5026 $section = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_link[
'minorid']);
5028 $actions = $section->attr(
'actions');
5029 foreach ($actions as $action) {
5030 $action_type = $action[
'type_code'];
5031 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($action_type);
5033 if ($action[
'active'] && call_user_func(Array($action_type,
'isValid'), $section, $action[
'settings'])) {
5034 $success = call_user_func(Array($action_type,
'execute'), $section, $this, $action[
'settings']);
5041 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($section);
5060 if ($this->
attr(
'multi_page')) {
5063 foreach($section_links as $section_link) {
5064 if (!isset($section_link[
'minorid']))
continue;
5065 $section = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_link[
'minorid']);
5066 $actions = $section->attr(
'actions');
5068 foreach ($actions as $action) {
5069 $action_type = $action[
'type_code'];
5070 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($action_type);
5071 call_user_func(Array($action_type,
'finalise'), $this);
5074 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($section);
5089 if (!$this->
attr(
'log_submissions'))
return FALSE;
5092 if (is_null($submission_folder))
return FALSE;
5094 $submissions = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($submission_folder->id,
'form_submission', TRUE, NULL, NULL, NULL, TRUE, 1, 1);
5096 return count($submissions);
5113 $bodycopy = $this->
getBodycopy(
'Submission Limit Reached');
5116 if ($bodycopy && !$bodycopy->isEmpty()) {
5117 $keyword_list = $bodycopy->getKeywords();
5119 if (!empty($keyword_list)) {
5120 foreach ($keyword_list as $keyword) {
5124 if (is_null($replacement)) {
5131 if (!is_null($replacement)) {
5133 $replacements[$keyword] = $replacement;
5138 $bodycopy->setKeywordReplacements($replacements);
5139 $bodycopy->printBody();