function handle(&$params) { session_write_close(); header('Connection: close'); $app = Dataface_Application::getInstance(); try { $query =& $app->getQuery(); if (!@$query['-record-id']) { throw new Exception("No record id was specified"); } $record = df_get_record_by_id($query['-record-id']); $username = $query['-username']; if (!$username) { throw new Exception("No username was specified"); } if ($record->val('compiled') == 0) { throw new Exception("The job has must be compiled before it can be approved"); } if ($record->val('job_status') == SweteJob::JOB_STATUS_CLOSED) { throw new Exception("The job has already been approved"); } $job = new SweteJob($record); $job->approve($username); $out = array('code' => 200, 'message' => 'Successfully approved your job '); } catch (Exception $ex) { $out = array('code' => $ex->getCode(), 'message' => $ex->getMessage()); } header('Content-type: text/json; charset="' . $app->_conf['oe'] . '"'); echo json_encode($out); return; }
function handle(&$params) { try { // add a new message to the current job record //-content is the new message content $app = Dataface_Application::getInstance(); $query = $app->getQuery(); $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); $content = trim(htmlspecialchars($query['-content'])); if (!$content) { throw new Exception("No message contents entered.", E_USER_ERROR); } $job_id = $query['-job_id']; $job_rec =& df_get_record("jobs", array('job_id' => $job_id)); if (!$job_rec->checkPermission('add new related record')) { throw new Exception("You do not have permission to add a note to this job.", E_USER_ERROR); } require_once 'inc/SweteDb.class.php'; require_once 'inc/SweteJob.class.php'; require_once 'inc/SweteJobInbox.class.php'; $job = new SweteJob($job_rec); $inbox = $job->getInbox($user->val('username')); $noteRec = $inbox->addMessage($content); } catch (Exception $e) { if ($e->getCode() == E_USER_ERROR) { echo $e->getMessage(); } else { throw $e; } } }
function handle(&$params) { try { $app = Dataface_Application::getInstance(); $query = $app->getQuery(); $selectedRecords = df_get_selected_records($query); $isNewJob = false; if ($query['-job'] && is_numeric($query['-job'])) { $selectedJob = df_get_record('jobs', array('job_id' => '=' . $query['-job'])); } else { //no job was selected by user $site_id = $selectedRecords[0]->val('website_id'); $jobs = df_get_records_array('jobs', array('website_id' => $site_id, 'compiled' => 'false')); $createNewJob = false; if ($query['-job'] == "new") { $createNewJob = true; } if (count($jobs) == 0 || $createNewJob) { //create a new job $selectedJob = SweteJob::createJob(SweteSite::loadSiteById($site_id))->getRecord(); $isNewJob = true; } else { if (count($jobs) == 1) { //only one available job $selectedJob = $jobs[0]; } else { throw new Exception("No Job id was specified, but there are " . $count($jobs) . " available jobs to add to"); } } } if (!$selectedJob) { throw new Exception("Job could not be found", E_USER_ERROR); } if (!$selectedJob->checkPermission('edit')) { throw new Exception("You don't have permission to edit this job"); } $job = new SweteJob($selectedJob); $stringsAdded = array(); foreach ($selectedRecords as $record) { if (intval($record->val('website_id')) !== intval($selectedJob->val("website_id"))) { throw new Exception("The string " . $record->val('string') . " is not in the same site as the job."); } //If string was already added to ANOTHER job, it doesn't matter //It will also be added to this one //if string was already added to this job, do nothing if (!$job->containsString($record->val('string'))) { $job->addTranslationMiss($record->val('translation_miss_log_id')); array_push($stringsAdded, $record->val('string')); } } $results = array('stringsAdded' => $stringsAdded, 'jobId' => $selectedJob->val('job_id'), 'isNewJob' => $isNewJob); echo json_encode($results); } catch (Exception $e) { if ($e->getCode() == E_USER_ERROR) { echo $e->getMessage(); } else { throw $e; } } }
function handle(&$params) { try { $app = Dataface_Application::getInstance(); $query =& $app->getQuery(); $jt = Dataface_JavascriptTool::getInstance(); $jt->import('swete/ui/filter_translations.js'); $app->addHeadContent('<link rel="stylesheet" type="text/css" href="css/swete/actions/review_translations.css"/>'); if (!@$query['-recordid']) { throw new Exception("No record id was specified"); } $record = df_get_record_by_id($query['-recordid']); $job = new SweteJob($record); $tm = XFTranslationMemory::loadTranslationMemoryFor($record, $record->val('source_language'), $record->val('destination_language')); $translations = $job->getTranslations(); $template = 'swete/actions/review_translations.html'; if (@$query['-isDialog']) { $template = 'swete/actions/review_translations_dlg.html'; } df_display(array('job' => $job, 'translations' => $translations), $template); } catch (Exception $e) { if ($e->getCode() == E_USER_ERROR) { echo $e->getMessage(); } else { throw $e; } } }
public static function decorateNewJob(SweteSite $site, Dataface_Record $rec) { require_once 'modules/tm/lib/XFTranslationMemory.php'; try { SweteDb::q('start transaction'); // First we need to create a translation memory for this job. $tm = XFTranslationMemory::createTranslationMemory('Job translation memory for site ' . $site->getRecord()->val('website_id') . ' ' . $site->getSourceLanguage() . '->' . $site->getDestinationLanguage(), $site->getSourceLanguage(), $site->getDestinationLanguage()); $status = SweteJob::JOB_STATUS_NEW; if ($rec->val('assigned_to')) { $status = SweteJob::JOB_STATUS_ASSIGNED; } $rec->setValues(array('website_id' => $site->getRecord()->val('website_id'), 'date_created' => date('Y-m-d H:i:s'), 'job_status' => $status, 'translation_memory_id' => $tm->getRecord()->val('translation_memory_id'), 'source_language' => $site->getSourceLanguage(), 'destination_language' => $site->getDestinationLanguage())); //print_r($rec->vals()); $res = $rec->save(); if (PEAR::isError($res)) { //print_r($res); throw new Exception($res->getMessage(), $res->getCode()); } if ($rec->val('posted_by')) { $res = df_q("insert ignore into job_roles (job_id, username, access_level) values ('" . addslashes($rec->val('job_id')) . "','" . addslashes($rec->val('posted_by')) . "','" . self::JOB_ROLE_OWNER . "')"); } if ($rec->val('assigned_to')) { $res = df_q("insert ignore into job_roles (job_id, username, access_level) values ('" . addslashes($rec->val('job_id')) . "','" . addslashes($rec->val('assigned_to')) . "','" . self::JOB_ROLE_TRANSLATOR . "')"); } SweteDb::q('commit'); $out = new SweteJob($rec); $out->setTranslationMemory($tm); return $out; } catch (Exception $ex) { SweteDb::q('rollback'); throw $ex; } }
function handle(&$params) { try { $app = Dataface_Application::getInstance(); $query = $app->getQuery(); $jobRecord = df_get_record('jobs', array('job_id' => '=' . $query['-job_id'])); if (!$jobRecord->checkPermission('edit')) { throw new Exception("You do not have permission make changes to this translation job.", E_USER_ERROR); } $job = new SweteJob($jobRecord); if (array_key_exists('-webpage_id', $query)) { $webpageRecord = df_get_record('webpages', array('webpage_id' => '=' . $query['-webpage_id'])); $webpage = new SweteWebpage($webpageRecord); $job->removeWebpage($webpage); } else { if (array_key_exists('-data-http-request-log-id', $query)) { $job->removeRequestStrings($query['-data-http-request-log-id']); } } } catch (Exception $e) { if ($e->getCode() == E_USER_ERROR) { echo $e->getMessage(); } else { throw $e; } } }
function handle($params) { session_write_close(); header('Connection: close'); $app = Dataface_Application::getInstance(); $query = $app->getQuery(); if (!@$query['-job_translatable_id']) { throw new Exception("No translatable id specified"); } $translatable = df_get_record('job_translatable', array('job_translatable_id' => '=' . $query['-job_translatable_id'])); if (!$translatable) { throw new Exception("Translatable could not be found."); } $job = df_get_record('jobs', array('job_id' => '=' . $translatable->val('job_id'))); if (!$job) { throw new Exception("Job could not be loaded."); } if (!$job->checkPermission('preview job')) { header('HTTP/1.0 401 Forbidden'); exit; } require_once 'inc/SweteJob.class.php'; require_once 'inc/SweteJobPageSucker.php'; $jobO = new SweteJob($job); $pageSucker = new SweteJobPageSucker($jobO); $translation = "source"; if (@$query['-translation']) { $translation = $query['-translation']; } if ($translation == "source") { $output = $translatable->val('full_contents'); $output = $pageSucker->renderHtml($output, DATAFACE_SITE_HREF . '?-action=swete_job_serve_content&job_id=' . $job->val('job_id') . '&url_hash='); //$output = $jobO->translateHtml($output, unserialize($job->val('previous_translations'))); } else { if ($translation == "previous") { $output = $translatable->val('full_contents'); $output = $pageSucker->renderHtml($output, DATAFACE_SITE_HREF . '?-action=swete_job_serve_content&job_id=' . $job->val('job_id') . '&url_hash='); $output = $jobO->translatePreviousHtml($output, unserialize($job->val('previous_translations'))); } else { if ($translation == "new") { $output = $translatable->val('full_contents'); $output = $pageSucker->renderHtml($output, DATAFACE_SITE_HREF . '?-action=swete_job_serve_content&job_id=' . $job->val('job_id') . '&url_hash='); $output = $jobO->translateHtml($output, unserialize($job->val('previous_translations'))); } else { throw new Exception("Invalid translation parameter " . $translation); } } } header('Content-Length: ' . strlen($output)); header('Content-type: text/html; charset="UTF-8"'); echo $output; }
function handle(&$params) { // returns html for a table with all the messages for -job_id $app = Dataface_Application::getInstance(); $query = $app->getQuery(); $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); $job_id = $query['-job_id']; $job =& df_get_record("jobs", array('job_id' => $job_id)); require_once 'inc/SweteDb.class.php'; require_once 'inc/SweteJob.class.php'; require_once 'inc/SweteJobInbox.class.php'; require_once 'inc/SweteJobInboxPresentation.php'; $sweteJob = new SweteJob($job); $messageList = $sweteJob->getInbox($user->val('username'))->getMessageList(); echo SweteJobInboxPresentation::tableContent($messageList); }
function handle($params) { $app = Dataface_Application::getInstance(); $query = $app->getQuery(); if (!@$query['-record-id']) { throw new Exception("No record id was specified"); } $record = df_get_record_by_id($query['-record-id']); if (!isset($record) || !$record instanceof Dataface_Record) { throw new Exception("Record could not be found for the record id [" . $query['-record-id'] . "] that was specified"); } require_once 'inc/SweteJob.class.php'; $job = new SweteJob($record); $stats = $job->getStats(); $out = array('code' => 200, 'message' => 'Successfully retrieved job translation stats.', 'stats' => $stats); header('Content-type: text/json; charset="' . $app->_conf['oe'] . '"'); echo json_encode($out); return; }
function afterInsert($record) { $site = SweteSite::loadSiteById($record->val('website_id')); SweteJob::decorateNewJob($site, $record); }
function testExtractDictionaryFromHtml() { //create a job so that we can use its translation memory $job = SweteJob::createJob($this->staticSite); $username = '******'; //add strings to the job $strings = array("Blah blah blah string", "Doop doop doop doop string", "Whee whee whee whee whee string", "Hey hey hey hey hey strings"); $this->addWebpageForStaticSite($url, $strings); $misses = df_get_records_array('translation_miss_log', array('website_id' => '=' . $this->staticSite->getRecord()->val('website_id'))); foreach ($misses as $miss) { $job->addTranslationMiss($miss->val('translation_miss_log_id')); } $job->compile(); $tm = $job->getTranslationMemory(); $trec = $tm->setTranslationStatus('cheese', 'fromage', XFTranslationMemory::TRANSLATION_SUBMITTED, $username); $trec = $tm->setTranslationStatus('ham', 'jambon', XFTranslationMemory::TRANSLATION_SUBMITTED, $username); $html = "<div>apple</div>\n\t\t\t<div>cheese</div>\n\t\t\t<div>Ham</div>\n\t\t\t<div>ham and cheese</div>"; $dict = $job->extractDictionaryFromHtml($job->getTranslationMemory(), $html); $this->assertTrue(isset($dict)); $this->assertEquals(4, sizeof($dict)); foreach ($dict as $k => $v) { error_log("extractDictionaryFromHtml result: {$k} => {$v}"); } $this->assertTrue(empty($dict[0])); $this->assertEquals("fromage", $dict[1]); $this->assertTrue(empty($dict[2])); $this->assertTrue(empty($dict[3])); }
function handle(&$params) { try { // First get the selected records $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); $isNewJob = false; if (!@$query['-record-id']) { throw new Exception("No record id was specified"); } $record = df_get_record_by_id($query['-record-id']); //get the selected job if ($query['-job'] && is_numeric($query['-job'])) { $selectedJob = df_get_record('jobs', array('job_id' => '=' . $query['-job'])); } else { //no job was selected by user $site_id = $record->val('website_id'); $jobs = df_get_records_array('jobs', array('website_id' => $site_id, 'compiled' => 'false')); $createNewJob = false; if ($query['-job'] == "new") { $createNewJob = true; } if (count($jobs) == 0 || $createNewJob) { //create a new job $selectedJob = SweteJob::createJob(SweteSite::loadSiteById($site_id))->getRecord(); $isNewJob = true; } else { if (count($jobs) == 1) { //only one available job $selectedJob = $jobs[0]; } else { throw new Exception("No Job id was specified, but there are " . $count($jobs) . " available jobs to add to"); } } } if (!$selectedJob) { throw new Exception("Job could not be found", E_USER_ERROR); } if (!$selectedJob->checkPermission('edit')) { throw new Exception("You don't have permission to edit this job"); } $job = new SweteJob($selectedJob); if (intval($record->val('website_id')) !== intval($selectedJob->val("website_id"))) { throw new Exception("The webpage " . $record->val('webpage_id') . " is not in the same site as the job."); } $webpage = new SweteWebpage($record); //if webpage was already added to this job, do nothing if (!$job->containsWebpage($webpage)) { $job->addWebpage($webpage, null, true); $results = array('pageAdded' => $record->val('webpage_id'), 'jobId' => $selectedJob->val('job_id'), 'isNewJob' => $isNewJob); } else { $results = array('pageAdded' => "false", 'jobId' => $selectedJob->val('job_id'), 'isNewJob' => $isNewJob); } echo json_encode($results); } catch (Exception $e) { if ($e->getCode() == E_USER_ERROR) { echo $e->getMessage(); } else { throw $e; } } }