Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_submission_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
32 {
33 
34 
40  {
41  $this->Asset_Edit_Fns();
42 
43  }//end constructor
44 
45 
56  function paintSubmissionIpAddress(&$asset, &$o, $prefix)
57  {
58  echo $asset->getIP();
59 
60  }//end paintSubmissionIpAddress()
61 
62 
73  function paintSubmissionTime(&$asset, &$o, $prefix)
74  {
75  if ($asset->attr('submitted') == '---------- --:--:--') {
76  echo translate('cms_not_submitted');
77  } else {
78  echo date('d M Y H:i:s', strtotime($asset->attr('submitted')));
79  }//end if
80 
81  }//end paintSubmissionTime()
82 
83 
94  function paintSubmissionAnswers(&$asset, &$o, $prefix)
95  {
96  $wa = $asset->writeAccess('attributes');
97  $is_editable_q = FALSE;
98 
99  $answers = $asset->attr('attributes');
100  if (empty($answers['answers'])) return ($wa && $is_editable_q);
101 
102  reset($answers['answers']);
103  $form_id = key($GLOBALS['SQ_SYSTEM']->am->getParents(key($answers['answers']), 'form', FALSE));
104  $form = $GLOBALS['SQ_SYSTEM']->am->getAsset($form_id);
105  $sections = $form->getSections();
106  for (reset($sections); $section = current($sections); next($sections)) {
107  $section_questions[$section->id] = Array();
108  }
109  $section_questions[$form_id] = Array();
110  foreach ($answers['answers'] as $q_id => $details) {
111  $section_id = strtok($q_id, ':');
112  $details['printed'] = FALSE;
113  $section_questions[$section_id][$q_id] = $details;
114  }
115  foreach ($form->attr('sort_order') as $q_id) {
116  $q = $GLOBALS['SQ_SYSTEM']->am->getAsset($q_id);
117  if ($q->isEditable() && !$is_editable_q) {
118  $is_editable_q = TRUE;
119  }
120  if (isset($section_questions[$form_id][$q_id])) {
121  if (is_string($section_questions[$form_id][$q_id]['answer'])) {
122  $q->setValue(html_entity_decode($section_questions[$form_id][$q_id]['answer']));
123  } else {
124  $q->setValue($section_questions[$form_id][$q_id]['answer']);
125  }
126  }
127  $note = $q->isEditable() ? $q->getVal('note') : '<i>'.translate('cms_form_submission_cannot_edit_question_type').'</i>';
128  $o->openField($q->getVal('title'), '', $note);
129 
130  if ($q instanceof Form_Question_Type_File_Upload) {
131  $q->setValue(array_get_index($section_questions[$form_id][$q_id], 'answer', ''));
132  $q->setExtraData(array_get_index($section_questions[$form_id][$q_id], 'extra_data', Array()));
133 
134  $q_summary = $q->getSummary();
135  $filepath = $q->getExtraData('filesystem_path');
136 
137  // Bug fix #4018 Download link On submission logs screen doesnt work. When we have create location specified
138  // on the upload question, we can directly get the assetid of file asset created from $filepath and create a working link
139  if ((SQ_IN_BACKEND || SQ_IN_LIMBO) && (!empty($filepath) && (!isset($filepath['existing_file_assetid']) && !isset($filepath['new_file_assetid'])) ) ) {
140  $q_summary .= ' [ <a href="./?a='.$asset->id.'&q='.$q->id.'">'.'Click to download'.'</a> ]';
141  } else if ((SQ_IN_BACKEND || SQ_IN_LIMBO) && (!empty($filepath) && (isset($filepath['existing_file_assetid']) || isset($filepath['new_file_assetid']) ) ) ) {
142  $uploade_file_id = array_key_exists('existing_file_assetid', $filepath) ? $filepath['existing_file_assetid'] : $filepath['new_file_assetid'];
143  $q_summary .= ' [ <a href="./?a='.$uploade_file_id.'" target="_blank" >'.'Click to download'.'</a> ]';
144  }
145  } else {
146  $q_summary = htmlentities($q->getSummary(), ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET).'&nbsp;';
147  }
148  echo ($q->isEditable() && $wa) ? $q->getHtmlField() : $q_summary;
149 
150  $section_questions[$form_id][$q_id]['printed'] = TRUE;
151  $o->closeField();
152  }
153  foreach ($section_questions[$form_id] as $q_id => $q_details) {
154  if (!$q_details['printed']) {
155  $note = '<i>'.translate('cms_form_submission_question_deleted_cannot_be_edited').'</i>';
156  $o->openField($answers['summary'][$q_id]['name'], '', $note);
157  echo $q_details['answer'];
158  $o->closeField();
159  }
160  }
161  $o->closeSection();
162  unset($section_questions[$form_id]);
163  foreach ($section_questions as $section_id => $section_qs) {
164  $section_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($section_id);
165  if (!empty($section_info)) {
166  $section = $GLOBALS['SQ_SYSTEM']->am->getAsset($section_id);
167  $o->openSection(translate('cms_form_submission_answers_for_section',$section->name));
168  foreach ($section->attr('sort_order') as $q_id) {
169  $q = $GLOBALS['SQ_SYSTEM']->am->getAsset($q_id);
170  if ($q->isEditable() && !$is_editable_q) {
171  $is_editable_q = TRUE;
172  }
173 
174  if (isset($section_questions[$section_id][$q_id])) {
175  $q->setValue(array_get_index($section_questions[$section_id][$q_id], 'answer', ''));
176  $q->setExtraData(array_get_index($section_questions[$section_id][$q_id], 'extra_data', Array()));
177  }
178 
179  $note = $q->isEditable() ? $q->getVal('note') : '<i>'.translate('cms_form_submission_cannot_edit_question_type').'</i>';
180 
181  $o->openField($q->getVal('title'), '', $note);
182  if ($q->isEditable() && $wa) {
183  echo $q->getHtmlField();
184  $is_editable_q = TRUE;
185  } else {
186  $summary = $q->getSummary();
187 
188  if ($q instanceof Form_Question_Type_File_Upload) {
189  $filepath = $q->getExtraData('filesystem_path');
190 
191  // Bug fix #4018 Download link On submission logs screen doesnt work. When we have create location specified
192  // on the upload question, we can directly get the assetid of file asset created from $filepath and create a working link
193  if ((SQ_IN_BACKEND || SQ_IN_LIMBO) && (!empty($filepath) && (!isset($filepath['existing_file_assetid']) && !isset($filepath['new_file_assetid'])) ) ) {
194  $summary .= ' [ <a href="./?a='.$asset->id.'&q='.$q->id.'">'.'Click to download'.'</a> ]';
195  } else if ((SQ_IN_BACKEND || SQ_IN_LIMBO) && (!empty($filepath) && (isset($filepath['existing_file_assetid']) || isset($filepath['new_file_assetid']) ) ) ) {
196  $uploade_file_id = array_key_exists('existing_file_assetid', $filepath) ? $filepath['existing_file_assetid'] : $filepath['new_file_assetid'];
197  $summary .= ' [ <a href="./?a='.$uploade_file_id.'" target="_blank" >'.'Click to download'.'</a> ]';
198  }
199  }
200 
201  $summary .= '&nbsp;';
202  echo $summary;
203  }
204  $section_questions[$section_id][$q_id]['printed'] = TRUE;
205  $o->closeField();
206  }
207  } else {
208  $o->openSection(translate('cms_form_submission_answers_for_deleted_section'));
209  $o->closeField();
210  }
211  foreach ($section_questions[$section_id] as $q_id => $q_details) {
212 
213  if (!$q_details['printed']) {
214  $note = '<i>'.translate('cms_form_submission_question_deleted_cannot_be_edited').'</i>';
215  $o->openField($answers['summary'][$q_id]['name'], '', $note);
216  echo $q_details['answer'];
217  $o->closeField();
218  }
219  }
220  $o->closeSection();
221 
222  }//end foreach
223  return $wa && $is_editable_q;
224 
225  }//end paintSubmissionAnswers()
226 
227 
238  function processSubmissionAnswers(&$asset, &$o, $prefix)
239  {
240  $attributes = $asset->attr('attributes');
241  $wa = $asset->writeAccess('attributes');
242 
243  if (empty($attributes['answers']) || !$wa) return FALSE;
244 
245  $form_id = key($GLOBALS['SQ_SYSTEM']->am->getParents(key($attributes['answers']), 'form', FALSE));
246  $form = $GLOBALS['SQ_SYSTEM']->am->getAsset($form_id);
247  $this->_tmp['question_errors'] = Array();
248  $unanswered_questions = $form->getAllQuestionAssets();
249 
250  foreach ($attributes['answers'] as $q_id => $details) {
251  $question_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($q_id);
252  if (!is_null($question_asset)) {
253  if (!$question_asset->isEditable()) continue;
254  $question_asset->populate();
255  if (($question_asset->getValue() != $details['answer']) && (!$question_asset->hasValidValue())) {
256  $this->_tmp['question_errors'] = array_merge($this->_tmp['question_errors'], $question_asset->failed_rules);
257  } else {
258  $value = $question_asset->getValue();
259  $attributes['answers'][$q_id]['answer'] = $value;
260  $attributes['summary'][$q_id]['answer'] = $question_asset->getSummary();
261  $attributes['summary'][$q_id]['name'] = $question_asset->getVal('title');
262  }
263  unset($unanswered_questions[$q_id]);
264  }
265  $section_id = strtok($q_id, ':');
266  $details['printed'] = FALSE;
267  $section_questions[$section_id][$q_id] = $details;
268  }
269 
270  foreach ($unanswered_questions as $unanswered_question) {
271  $question_asset =& $unanswered_question;
272  if (!$question_asset->isEditable()) continue;
273  $question_asset->setAttrValue('is_required', FALSE); // temporarily
274  $question_asset->populate();
275  if (!$question_asset->hasValidValue()) {
276  $this->_tmp['question_errors'] = array_merge($this->_tmp['question_errors'], $question_asset->failed_rules);
277  } else {
278  $value = $question_asset->getValue();
279  $attributes['answers'][$question_asset->id]['answer'] = $value;
280  $attributes['summary'][$question_asset->id]['answer'] = $question_asset->getSummary();
281  $attributes['summary'][$question_asset->id]['name'] = $question_asset->getVal('title');
282  }
283  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($question_asset); // make sure that attr change doesn't stick
284  }
285  if (empty($this->_tmp['question_errors'])) {
286  $asset->setAttrValue('attributes', $attributes);
287  return TRUE;
288  } else {
289  ?>
290  <div style="color: red">
291  <strong><?php echo translate('cms_form_submission_error_during_processing'); ?></strong>
292  <ul>
293  <?php
294  foreach ($this->_tmp['question_errors'] as $msg) {
295  ?>
296  <li><?php echo $msg; ?></li>
297  <?php
298  }
299  ?>
300  </ul>
301  </div>
302  <?php
303 
304  return FALSE;
305  }
306 
307  }//end processSubmissionAnswers()
308 
309 
310 }//end class
311 ?>