@@ -88,27 +88,31 @@ function finalize($quiz, $points) {
8888
8989 $ _result = new ChainedQuizResult ();
9090 // calculate result
91- $ result = $ _result ->calculate ($ quiz , $ points );
91+ $ result = $ _result ->calculate ($ output , $ points );
9292
9393 // get final screen and replace vars
9494 $ snapshot = '' ; // The SOAP note data to be saved in the submission record snapshot.
9595 $ output = stripslashes ($ quiz ->output );
9696 $ email_output = $ quiz ->set_email_output ? stripslashes ($ quiz ->email_output ) : $ output ;
9797
98+ /** THIS MAY BE REMOVED BECAUSE THE EMAIL OUTPUT IS USED FOR SNAPSHOT INSTEAD */
9899 $ output = str_replace ('{{result-title}} ' , @$ result ->title , $ output );
99100 $ output = str_replace ('{{result-text}} ' , stripslashes (@$ result ->description ), $ output );
100101 $ output = str_replace ('{{points}} ' , $ points , $ output );
101102 $ output = str_replace ('{{questions}} ' , $ _POST ['total_questions ' ], $ output );
102103
104+ // Find the first occurrence of the shortcode and replace with the HTML answers table.
103105 if (strstr ($ output , '{{answers-table}} ' )) {
104106 $ snapshot = $ this ->answers_table ($ completion_id );
105107 $ output = str_replace ('{{answers-table}} ' , $ snapshot , $ output );
106108 }
107109
110+ // If there is now HTML answers table, then substitute it for the soap note instead.
108111 if ($ snapshot == '' ) {
109112 $ snapshot = $ this ->soap_note ($ completion_id );
110113 }
111114
115+ // Find the first occurrence of the shortcode and replace with the HTML SOAP note.
112116 if (strstr ($ output , '{{soap-note}} ' )) {
113117 $ output = str_replace ('{{soap-note}} ' , $ snapshot , $ output );
114118 }
@@ -118,10 +122,17 @@ function finalize($quiz, $points) {
118122 $ email_output = str_replace ('{{points}} ' , $ points , $ email_output );
119123 $ email_output = str_replace ('{{questions}} ' , $ _POST ['total_questions ' ], $ email_output );
120124
125+ // Find the first occurrence of the shortcode and replace with the HTML answers table.
121126 if (strstr ($ email_output , '{{answers-table}} ' )) {
122127 $ email_output = str_replace ('{{answers-table}} ' , $ this ->answers_table ($ completion_id ), $ email_output );
123128 }
124129
130+ // If there is now HTML answers table, then substitute it for the soap note instead.
131+ if ($ snapshot == '' ) {
132+ $ snapshot = $ this ->soap_note ($ completion_id );
133+ }
134+
135+ // Find the first occurrence of the shortcode and replace with the HTML SOAP note.
125136 if (strstr ($ email_output , '{{soap-note}} ' )) {
126137 $ email_output = str_replace ('{{soap-note}} ' , $ this ->soap_note ($ completion_id ), $ email_output );
127138 }
@@ -169,7 +180,7 @@ function finalize($quiz, $points) {
169180 $ wpdb ->query ( $ wpdb ->prepare ("UPDATE " .CHAINED_COMPLETED ." SET
170181 quiz_id = %d, points = %f, result_id = %d, datetime = NOW(), ip = %s, user_id = %d,
171182 snapshot = %s, source_url=%s, email=%s WHERE id=%d " ,
172- $ quiz ->id , $ points , @$ result ->id , $ _SERVER ['REMOTE_ADDR ' ], $ user_id , $ snapshot ,
183+ $ quiz ->id , $ points , @$ result ->id , $ _SERVER ['REMOTE_ADDR ' ], $ user_id , $ email_output ,
173184 $ source_url , $ user_email , intval ($ _SESSION ['chained_completion_id ' ])));
174185 $ taking_id = $ _SESSION ['chained_completion_id ' ];
175186 unset($ _SESSION ['chained_completion_id ' ]);
@@ -179,7 +190,7 @@ function finalize($quiz, $points) {
179190 $ wpdb ->query ( $ wpdb ->prepare ("INSERT INTO " .CHAINED_COMPLETED ." SET
180191 quiz_id = %d, points = %f, result_id = %d, datetime = NOW(), ip = %s, user_id = %d, snapshot = %s,
181192 source_url=%s, email=%s " ,
182- $ quiz ->id , $ points , @$ result ->id , $ _SERVER ['REMOTE_ADDR ' ], $ user_id , $ snapshot , $ source_url , $ user_email ));
193+ $ quiz ->id , $ points , @$ result ->id , $ _SERVER ['REMOTE_ADDR ' ], $ user_id , $ email_output , $ source_url , $ user_email ));
183194 $ taking_id = $ wpdb ->insert_id ;
184195 }
185196
0 commit comments