18 require_once dirname(__FILE__).
'/../form/form.inc';
19 require_once SQ_FUDGE_PATH.
'/general/www.inc';
20 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
21 require_once SQ_FUDGE_PATH.
'/general/text.inc';
46 $this->
Form($assetid);
61 function _getName($short_name=FALSE, $contextid=NULL)
64 if ($contextid === NULL) {
65 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
69 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
70 if (empty($values) === TRUE) {
71 return parent::_getName($short_name, $contextid);
73 return $values[$this->id];
91 $header = parent::getFormHeader();
100 if (array_key_exists($prefix.
'_referral_url', $_POST)) {
101 $referer = $_POST[$prefix.
'_referral_url'];
103 $referer = (isset($_SERVER[
'HTTP_REFERER'])) ? $_SERVER[
'HTTP_REFERER'] :
'';
107 ?><input
type=
"hidden" name=
"<?php echo $prefix; ?>_referral_url" value=
"<?php echo htmlentities($referer); ?>" /><?php
108 $header .= ob_get_clean();
125 $info = parent::getFormInfo();
126 $title =
'Form Information';
127 $information = ($html) ?
'<b>'.$title.
'</b><br />' : $title.
"\n\n";
128 $information .= ($html) ?
'<table>' :
'';
130 foreach ($info as $name => $value) {
131 $information .= ($html) ?
'<tr><td valign="top">'.ucwords(str_replace(
'_',
' ', $name)).
'</td>' : ucwords(str_replace(
'_',
' ', $name)).
' : ';
132 $information .= ($html) ?
'<td valign="top">'.$value.
'</td></tr>' : $value.
"\n";
135 $now = date(
'd M Y g:i a', time());
136 $information .= ($html) ?
'<tr><td valign="top">'.translate(
'cms_form_submission_time').
'</td>' : translate(
'cms_form_submission_time').
' : ';
137 $information .= ($html) ?
'<td valign="top">'.$now.
'</td></tr>' : $now.
"\n";
139 $ip_address = $_SERVER[
'REMOTE_ADDR'];
140 $information .= ($html) ?
'<tr><td valign="top">'.translate(
'cms_form_submission_ip_address').
'</td>' : translate(
'cms_form_submission_ip_address').
' : ';
141 $information .= ($html) ?
'<td valign="top">'.$ip_address.
'</td></tr>' : $ip_address.
"\n";
143 $information .= ($html) ?
'</table>' :
'';
176 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
177 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
180 $metadata_schemas_key = array_search(
'metadata_schemas', $components);
181 if ($metadata_schemas_key !== FALSE) {
182 unset($components[$metadata_schemas_key]);
185 if (!parent::cloneComponents($clone, $components, $override)) {
186 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
187 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
191 if (in_array(
'attributes', $components) || in_array(
'all', $components)) {
193 $recip = unserialize($this->
attr(
'recipient_emails_format'));
195 if(array_key_exists(
'to',$recip)) {
196 $recip = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $recip);
197 $recip[
'to'] = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $recip[
'to']);
199 $recip = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $recip);
202 $rec = unserialize($this->
attr(
'receipt_emails_format'));
204 if (array_key_exists(
'to',$rec)) {
205 $rec = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $rec);
206 $rec[
'to'] = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $rec[
'to']);
208 $rec = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $rec);
211 $staf = unserialize($this->
attr(
'staf_format'));
213 if (array_key_exists(
'to',$staf)) {
214 $staf = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $staf);
215 $staf[
'to'] = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $staf[
'to']);
217 $staf = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $staf);
220 $sel = $this->
attr(
'selective_emails');
221 foreach ($sel as $key => $null) {
222 $sel[$key][
'address'] = str_replace(
'%response_'.$this->
id.
'_',
'%response_'.$clone->id.
'_', $sel[$key][
'address']);
223 $sel[$key][
'assetid'] = str_replace($this->
id.
':q', $clone->id.
':q', $sel[$key][
'assetid']);
227 $staf_field = str_replace($this->
id.
':q', $clone->id.
':q', $this->attr(
'staf_field'));
228 $receipt_field = str_replace($this->
id.
':q', $clone->id.
':q', $this->attr(
'receipt_field'));
231 $clone->setAttrValue(
'recipient_emails_format', serialize($recip));
232 $clone->setAttrValue(
'receipt_emails_format', serialize($rec));
233 $clone->setAttrValue(
'staf_format', serialize($staf));
234 $clone->setAttrValue(
'selective_emails', $sel);
236 $clone->setAttrValue(
'staf_field', $staf_field);
237 $clone->setAttrValue(
'receipt_field', $receipt_field);
239 $clone->saveAttributes();
243 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
244 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
260 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
261 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
263 if (!parent::deleteQuestion($question)) {
264 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
265 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
269 if ($this->
attr(
'staf_field') == $question->id) {
273 if ($this->
attr(
'receipt_field') == $question->id) {
278 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
279 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
283 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
284 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
309 if (($current_page == $total_pages) && $this->
attr(
'use_confirmation_page')) {
318 parent::finishForm();
342 $email_field_assetid = $this->
attr(
'receipt_field');
343 if (empty($email_field_assetid))
return FALSE;
345 $email_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($email_field_assetid);
346 if (empty($email_field))
return FALSE;
347 $address = $email_field->getValue();
349 $additional_reps = Array(
350 'receipt_address' => $address,
353 $email_format_attr = $this->
getAttribute(
'receipt_emails_format');
356 $current_value = @unserialize($email_format_attr->value);
357 $current_value[
'to'][] = $address;
358 $email_format_attr->value = serialize($current_value);
360 $this->
sendEmail($email_format_attr, $additional_reps);
375 $email_format_attr = $this->
getAttribute(
'recipient_emails_format');
393 $file_assets = Array();
394 $filenames = Array();
396 foreach ($questions as $q_assetid => $question) {
397 if ($question[
'question_type_code'] ==
'form_question_type_file_upload') {
398 $q_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($q_assetid);
399 if (!is_null($q_asset) && $q_asset->attr(
'attach_to_mail')) {
400 $file_asset_id = $q_asset->getUploadedFileId();
401 if (!empty($file_asset_id)) {
402 $file_assets[] = $file_asset_id;
405 if (isset($q_asset->extra_data[
'filesystem_path']) && is_file($q_asset->extra_data[
'filesystem_path'])) {
406 $filenames[] = $q_asset->extra_data[
'filesystem_path'];
414 'assets' => $file_assets,
415 'filenames' => $filenames,
429 $email_field_assetid = $this->
attr(
'staf_field');
430 if (empty($email_field_assetid))
return FALSE;
432 $email_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($email_field_assetid);
433 if (empty($email_field))
return FALSE;
434 $addresses = preg_split(
'/[\s;,]+/',$email_field->getValue());
436 $email_format_attr = $this->
getAttribute(
'staf_format');
439 $current_value = @unserialize($email_format_attr->value);
440 $current_value[
'to'] = array_merge($current_value[
'to'], $addresses);
441 $email_format_attr->value = serialize($current_value);
459 $selective_emails = $this->
attr(
'selective_emails');
463 $recipients = Array();
467 for (reset($selective_emails); NULL !== ($k = key($selective_emails)); next($selective_emails)) {
468 $sel_email =& $selective_emails[$k];
473 if (empty($sel_email[
'rules'])) $valid = FALSE;
474 if (empty($sel_email[
'send'])) $valid = FALSE;
475 if (empty($sel_email[
'address'])) $valid = FALSE;
482 $require_all = ($sel_email[
'require'] ==
'all');
483 $passed = $require_all;
486 $rule_parts =& $sel_email[
'rules'];
488 for (reset($rule_parts); NULL !== ($rule_key = key($rule_parts)); next($rule_parts)) {
489 $rule =& $rule_parts[$rule_key];
490 $q_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($rule[
'assetid']);
499 $answer = $q_asset->getValue();
501 $type_code =
'form_question_rule_type_'.$rule[
'name'];
502 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
503 $rule_asset =
new $type_code();
504 $rule_passed = $rule_asset->evaluate($answer, $rule, $q_asset);
507 if ($require_all && !$rule_passed) {
511 }
else if (!$require_all && $rule_passed) {
521 $addresses = preg_split(
'/[\s;,]+/',$sel_email[
'address']);
523 switch ($sel_email[
'send']) {
525 $recipients = array_merge($recipients, $addresses);
528 $receipts = array_merge($receipts, $addresses);
531 $stafs = array_merge($stafs, $addresses);
542 if (!empty($recipients)) {
544 $recipients = array_unique($recipients);
546 $email_format = $this->
getAttribute(
'recipient_emails_format');
549 $current_value = @unserialize($email_format->value);
551 if (!empty($current_value)) {
552 $current_value[
'to'] = $recipients;
553 $email_format->value = serialize($current_value);
560 if (!empty($receipts)) {
562 $receipts = array_unique($receipts);
564 $email_format = $this->
getAttribute(
'receipt_emails_format');
567 $current_value = @unserialize($email_format->value);
569 if (!empty($current_value)) {
570 $current_value[
'to'] = $receipts;
571 $email_format->value = serialize($current_value);
573 $additional_reps = Array(
'receipt_address' =>
'');
574 $this->
sendEmail($email_format, $additional_reps);
580 if (!empty($stafs)) {
582 $stafs = array_unique($stafs);
587 $current_value = @unserialize($email_format->value);
589 if (!empty($current_value)) {
590 $current_value[
'to'] = $stafs;
591 $email_format->value = serialize($current_value);
617 function sendEmail(&$email_format_attr, $replacements=Array())
619 $current_value = @unserialize($email_format_attr->value);
620 $filenames = Array();
623 if (empty($current_value[
'to']) && empty($current_value[
'to_assetids'])) {
628 $current_value[
'html_format'] = str_replace(
629 Array(
'%form_info%',
'%form_summary%'),
630 Array(
'%form_info_html%',
'%form_summary_html%'), $current_value[
'html_format']);
631 $current_value[
'text_format'] = str_replace(
632 Array(
'%form_info%',
'%form_summary%'),
633 Array(
'%form_info_text%',
'%form_summary_text%'), $current_value[
'text_format']);
636 $current_value[
'attachments'] = Array();
637 $filenames = Array();
638 if (array_get_index($current_value,
'inc_attachments', FALSE)) {
640 $current_value[
'attachments'] = $attachments[
'assets'];
641 $filenames = $attachments[
'filenames'];
644 $all_text = $current_value[
'html_format']
645 .
' '.$current_value[
'text_format']
646 .
' '.implode(
', ', $current_value[
'to'])
647 .
' '.$current_value[
'from']
648 .
' '.$current_value[
'reply_to']
649 .
' '.$current_value[
'subject'];
651 $all_keywords = extract_keywords($all_text);
653 if (!is_array($replacements)) $replacements = Array();
655 foreach ($all_keywords as $keyword) {
656 if (isset($replacements[$keyword]))
continue;
660 $email_format_attr->value = serialize($current_value);
661 $email_format_attr->sendMail($replacements, $filenames);
675 $actions = $this->
attr(
'actions');
676 foreach ($actions as $action) {
677 $action_type = $action[
'type_code'];
678 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($action_type);
681 if ($before_submit && !isset($action[
'settings'][
'before_submit']))
continue;
683 if (!$before_submit && isset($action[
'settings'][
'before_submit']))
continue;
686 if ($action[
'active'] && call_user_func(Array($action_type,
'isValid'), $this, $action[
'settings'])) {
687 $success &= call_user_func(Array($action_type,
'execute'), $this, $action[
'settings']);
708 $keyword = parse_keyword($keyword, $modifiers);
713 $referrer = (isset($_POST[$prefix.
'_referral_url'])) ? $_POST[$prefix.
'_referral_url'] :
'';
715 if ($keyword ==
'referral_url') {
716 $replacement = $referrer;
717 }
else if (preg_match(
'|^referring_asset_(.*)|', $keyword, $matches)) {
720 if (!empty($referrer)) {
722 $referrer = clean_url($referrer);
724 $url_parts = parse_url($referrer);
725 $protocol = array_get_index($url_parts,
'scheme');
726 $path = array_get_index($url_parts,
'host').array_get_index($url_parts,
'path');
728 $referrer_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL($protocol, $path, TRUE, TRUE);
729 if (!is_null($referrer_asset)) {
730 $referrer_keyword =
'asset_'.$matches[1];
732 $referrer_replacement = $referrer_asset->getKeywordReplacement($referrer_keyword);
733 if ($referrer_replacement !==
"%$referrer_keyword%") {
734 $replacement = $referrer_replacement;
741 }
else if ($keyword ==
'youtube_video_link'){
742 $replacement = (isset($this->form_action_keywords[
'youtube_video_link'])) ? $this->form_action_keywords[
'youtube_video_link'] :
'';
743 }
else if ($keyword ==
'youtube_video_id'){
744 $replacement = (isset($this->form_action_keywords[
'youtube_video_id'])) ? $this->form_action_keywords[
'youtube_video_id'] :
'';
745 }
else if ($keyword ==
'youtube_video_published_date'){
746 $replacement = (isset($this->form_action_keywords[
'youtube_video_published_date'])) ? $this->form_action_keywords[
'youtube_video_published_date'] :
'';
748 $replacement = parent::_getThankYouKeywordReplacement($keyword);
751 $replace_keywords = Array(
752 'assetid' => $this->
id,
753 'call_fns' => Array (
'_getThankYouKeywordReplacement',
'getKeywordReplacement'),
755 apply_keyword_modifiers($replacement, $modifiers, $replace_keywords);