![]() |
Xataface Translation Memory Module 0.1
Translation Memory for Xataface Applications
|
00001 <?php 00002 /* 00003 * Xataface Translation Memory Module 00004 * Copyright (C) 2011 Steve Hannah <steve@weblite.ca> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public 00017 * License along with this library; if not, write to the 00018 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00022 00056 class actions_tm_save_field { 00057 00058 function handle($params){ 00059 00060 00061 $app = Dataface_Application::getInstance(); 00062 $query = $app->getQuery(); 00063 00064 try { 00065 00066 if ( !@$_POST['--lang'] ){ 00067 throw new Exception("No language specified."); 00068 00069 } 00070 00071 if ( !preg_match('/^[0-9-a-z]{2}$/', $_POST['--lang']) ){ 00072 throw new Exception("Invalid language code."); 00073 } 00074 00075 00076 if ( !@$_POST['--record_id'] ){ 00077 throw new Exception("No record specified"); 00078 } 00079 00080 $record = df_get_record_by_id($_POST['--record_id']); 00081 00082 if ( !$record ){ 00083 throw new Exception("Record could not be found."); 00084 } 00085 00086 $tlangs = $record->table()->getTranslations(); 00087 foreach (array_keys($tlangs) as $trans){ 00088 $record->table()->getTranslation($trans); 00089 } 00090 $tlangs = $record->table()->getTranslations(); 00091 if ( !isset($tlangs[$_POST['--lang']]) ){ 00092 throw new Exception("Failed to save translation because the specified record does not support this language."); 00093 00094 } 00095 00096 00097 if ( !@$_POST['--field'] ){ 00098 throw new Exception("No field was specified for the update."); 00099 00100 } 00101 00102 00103 00104 if ( !$record->checkPermission('edit', array('field'=>$_POST['--field']) ) ){ 00105 throw new Exception("Failed to update field because permission was denied."); 00106 } 00107 00108 $record->setValue($_POST['--field'], @$_POST['--newval']); 00109 $res = $record->save(); 00110 if ( PEAR::isError($res) ){ 00111 error_log($res->getMessage()); 00112 throw new Exception('Failed to update field. See server error log for details.'); 00113 } 00114 00115 $this->out(array( 00116 'code'=>200, 00117 'message'=>'Successfully saved field value.', 00118 'fieldContent'=>$record->strval($_POST['--field']) 00119 )); 00120 00121 } catch (Exception $ex){ 00122 00123 $this->out(array( 00124 'code'=>$ex->getCode(), 00125 'message'=>$ex->getMessage(), 00126 'error'=>1 00127 )); 00128 00129 00130 } 00131 } 00132 00133 function out($params){ 00134 00135 header('Content-type: text/json; charset="'.Dataface_Application::getInstance()->_conf['oe'].'"'); 00136 echo json_encode($params); 00137 } 00138 }