Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
submit_translation.php
Go to the documentation of this file.
1 <?php
2 import('Dataface/TranslationTool.php');
4 
5  function handle(&$params){
7  $tt = new Dataface_TranslationTool();
8  if ( !Dataface_Table::tableExists('dataface__translation_submissions',false) ){
9  $tt->createTranslationSubmissionsTable();
10  $app->redirect($app->url(''));
11 
12  }
13 
14  if ( !@$_POST['--submit']){
15 
16  df_display(array('query'=>$app->getQuery(), 'success'=>@$_REQUEST['--success']), 'Dataface_submit_translation.html');
17  return;
18  } else {
19 
20  if ( @$_POST['subject'] ){
21  // This is a dummy field - possible hacking attempt
22  $app->redirect($app->url('-action=list'));
23 
24  }
25  if ( @$_POST['--recordid'] ){
26  $record = df_get_record_by_id($_POST['--recordid']);
27  $values = array(
28  'record_id'=>@$_POST['--recordid'],
29  'language'=>@$_POST['--language'],
30  'url'=>@$_POST['--url'],
31  'original_text'=>@$_POST['--original_text'],
32  'translated_text'=>@$_POST['--translated_text'],
33  'translated_by'=>@$_POST['--translated_by']);
34  $trec = new Dataface_Record('dataface__translation_submissions', array());
35  $trec->setValues($values);
36  $trec->save();
37 
38  $email = <<<END
39  The following translation was submitted to the web site {$app->url('')}:
40 
41  Translation for record {$record->getTitle()} which can be viewed at {$record->getURL('-action=view')}.
42  This translation was submitted by {$_POST['--translated_by']} after viewing the content at {$_POST['--url']}.
43 
44  The original text that was being translated is as follows:
45 
46  {$_POST['--original_text']}
47 
48  The translation proposed by this person is as follows:
49 
50  {$_POST['--translated_text']}
51 
52  For more details about this translation, please visit {$trec->getURL('-action=view')}.
53 END;
54 
55 
56  if ( @$app->_conf['admin_email'] ){
57  mail($app->_conf['admin_email'],
58  'New translation submitted',
59  $email
60  );
61 
62  }
63 
64  if ( @$_POST['--redirect'] || @$_POST['--url']){
65  $url = @$_POST['--redirect'] ? $_POST['--redirect'] : $_POST['--url'];
66  $app->redirect($url.'&--msg='.urlencode('Thank you for your submission.'));
67 
68  } else {
69  $app->redirect($app->url('').'&--success=1&--msg='.urlencode('Thank you for your submission.'));
70 
71  }
72  } else {
73  throw new Exception("No record id was provided", E_USER_ERROR);
74 
75  }
76  }
77 
78 
79  }
80 }
81 
82 ?>