public function doAction()
 {
     //get Job Infos
     $job_data = getJobData($this->jid);
     $pCheck = new AjaxPasswordCheck();
     //check for Password correctness
     if (!$pCheck->grantJobAccessByJobData($job_data, $this->password)) {
         $this->result['errors'][] = array("code" => -10, "message" => "wrong password");
         return;
     }
     $lang_handler = Langs_Languages::getInstance();
     if ($this->ref_segment == '') {
         $this->ref_segment = 0;
     }
     $data = getMoreSegments($this->jid, $this->password, $this->step, $this->ref_segment, $this->where);
     $this->prepareNotes($data);
     foreach ($data as $i => $seg) {
         if ($this->where == 'before') {
             if ((double) $seg['sid'] >= (double) $this->ref_segment) {
                 break;
             }
         }
         if (empty($this->pname)) {
             $this->pname = $seg['pname'];
         }
         if (empty($this->last_opened_segment)) {
             $this->last_opened_segment = $seg['last_opened_segment'];
         }
         if (empty($this->cid)) {
             $this->cid = $seg['cid'];
         }
         if (empty($this->pid)) {
             $this->pid = $seg['pid'];
         }
         if (empty($this->tid)) {
             $this->tid = $seg['tid'];
         }
         if (empty($this->create_date)) {
             $this->create_date = $seg['create_date'];
         }
         if (empty($this->source_code)) {
             $this->source_code = $seg['source'];
         }
         if (empty($this->target_code)) {
             $this->target_code = $seg['target'];
         }
         if (empty($this->source)) {
             $s = explode("-", $seg['source']);
             $source = strtoupper($s[0]);
             $this->source = $source;
         }
         if (empty($this->target)) {
             $t = explode("-", $seg['target']);
             $target = strtoupper($t[0]);
             $this->target = $target;
         }
         if (empty($this->err)) {
             $this->err = $seg['serialized_errors_list'];
         }
         $id_file = $seg['id_file'];
         if (!isset($this->data["{$id_file}"])) {
             $this->data["{$id_file}"]['jid'] = $seg['jid'];
             $this->data["{$id_file}"]["filename"] = ZipArchiveExtended::getFileName($seg['filename']);
             $this->data["{$id_file}"]["mime_type"] = $seg['mime_type'];
             $this->data["{$id_file}"]['source'] = $lang_handler->getLocalizedName($seg['source']);
             $this->data["{$id_file}"]['target'] = $lang_handler->getLocalizedName($seg['target']);
             $this->data["{$id_file}"]['source_code'] = $seg['source'];
             $this->data["{$id_file}"]['target_code'] = $seg['target'];
             $this->data["{$id_file}"]['segments'] = array();
         }
         unset($seg['id_file']);
         unset($seg['source']);
         unset($seg['target']);
         unset($seg['source_code']);
         unset($seg['target_code']);
         unset($seg['mime_type']);
         unset($seg['filename']);
         unset($seg['jid']);
         unset($seg['pid']);
         unset($seg['cid']);
         unset($seg['tid']);
         unset($seg['pname']);
         unset($seg['create_date']);
         unset($seg['id_segment_end']);
         unset($seg['id_segment_start']);
         unset($seg['serialized_errors_list']);
         $seg['parsed_time_to_edit'] = CatUtils::parse_time_to_edit($seg['time_to_edit']);
         $seg['source_chunk_lengths'] === null ? $seg['source_chunk_lengths'] = '[]' : null;
         $seg['target_chunk_lengths'] === null ? $seg['target_chunk_lengths'] = '{"len":[0],"statuses":["DRAFT"]}' : null;
         $seg['source_chunk_lengths'] = json_decode($seg['source_chunk_lengths'], true);
         $seg['target_chunk_lengths'] = json_decode($seg['target_chunk_lengths'], true);
         $seg['segment'] = CatUtils::rawxliff2view(CatUtils::reApplySegmentSplit($seg['segment'], $seg['source_chunk_lengths']));
         $seg['translation'] = CatUtils::rawxliff2view(CatUtils::reApplySegmentSplit($seg['translation'], $seg['target_chunk_lengths']['len']));
         $this->attachNotes($seg);
         $this->data["{$id_file}"]['segments'][] = $seg;
     }
     $this->result['data']['files'] = $this->data;
     $this->result['data']['where'] = $this->where;
 }
 public function doAction()
 {
     $lang_handler = languages::getInstance("en");
     //		log::doLog('REF SEGMENT: '.$this->ref_segment);
     if ($this->ref_segment == '') {
         $this->ref_segment = 0;
     }
     // CASMACAT extension start
     if ($this->casIsReplaying) {
         $data = getMoreSegmentsWithoutTranslation($this->jid, $this->password, $this->step, $this->ref_segment, $this->where);
     } else {
         $data = getMoreSegments($this->jid, $this->password, $this->step, $this->ref_segment, $this->where);
     }
     // CASMACAT extension end
     $first_not_translated_found = false;
     //log::doLog('REF SEGMENT: '.$this->ref_segment);
     //		print_r($data); exit;
     foreach ($data as $i => $seg) {
         if ($this->where == 'before') {
             if ((double) $seg['sid'] >= (double) $this->ref_segment) {
                 break;
             }
         }
         // remove this when tag management enabled
         //        	$seg['segment'] = $this->stripTagsFromSource($seg['segment']);
         if (empty($this->pname)) {
             $this->pname = $seg['pname'];
         }
         if (empty($this->last_opened_segment)) {
             $this->last_opened_segment = $seg['last_opened_segment'];
         }
         if (empty($this->cid)) {
             $this->cid = $seg['cid'];
         }
         if (empty($this->pid)) {
             $this->pid = $seg['pid'];
         }
         if (empty($this->tid)) {
             $this->tid = $seg['tid'];
         }
         if (empty($this->create_date)) {
             $this->create_date = $seg['create_date'];
         }
         if (empty($this->source_code)) {
             $this->source_code = $seg['source'];
         }
         if (empty($this->target_code)) {
             $this->target_code = $seg['target'];
         }
         if (empty($this->source)) {
             $s = explode("-", $seg['source']);
             $source = strtoupper($s[0]);
             $this->source = $source;
         }
         if (empty($this->target)) {
             $t = explode("-", $seg['target']);
             $target = strtoupper($t[0]);
             $this->target = $target;
         }
         $id_file = $seg['id_file'];
         $file_stats = CatUtils::getStatsForFile($id_file);
         if (!isset($this->data["{$id_file}"])) {
             $this->data["{$id_file}"]['jid'] = $seg['jid'];
             $this->data["{$id_file}"]["filename"] = $seg['filename'];
             $this->data["{$id_file}"]["mime_type"] = $seg['mime_type'];
             $this->data["{$id_file}"]['id_segment_start'] = $seg['id_segment_start'];
             $this->data["{$id_file}"]['id_segment_end'] = $seg['id_segment_end'];
             $this->data["{$id_file}"]['source'] = $lang_handler->iso2Language($seg['source']);
             $this->data["{$id_file}"]['target'] = $lang_handler->iso2Language($seg['target']);
             $this->data["{$id_file}"]['source_code'] = $seg['source'];
             $this->data["{$id_file}"]['target_code'] = $seg['target'];
             $this->data["{$id_file}"]['file_stats'] = $file_stats;
             $this->data["{$id_file}"]['segments'] = array();
         }
         //if (count($this->data["$id_file"]['segments'])>100){continue;}
         $this->filetype_handler = new filetype($seg['mime_type']);
         unset($seg['id_file']);
         unset($seg['source']);
         unset($seg['target']);
         unset($seg['source_code']);
         unset($seg['target_code']);
         unset($seg['mime_type']);
         unset($seg['filename']);
         unset($seg['jid']);
         unset($seg['pid']);
         unset($seg['cid']);
         unset($seg['tid']);
         unset($seg['pname']);
         unset($seg['create_date']);
         unset($seg['id_segment_end']);
         unset($seg['id_segment_start']);
         //		log::doLog('A');
         $seg['segment'] = $this->filetype_handler->parse($seg['segment']);
         // ASKED. MARCO CONFIRMED: in the web interface do not show xliff_ext_prec_tags and xliff_ext_succ_tags
         // $seg['segment'] = $seg['xliff_ext_prec_tags'] . $seg['segment'].$seg['xliff_ext_succ_tags'] ;
         $seg['segment'] = CatUtils::rawxliff2view($seg['segment']);
         $seg['translation'] = CatUtils::rawxliff2view($seg['translation']);
         $seg['parsed_time_to_edit'] = $this->parse_time_to_edit($seg['time_to_edit']);
         $this->data["{$id_file}"]['segments'][] = $seg;
     }
     //log::doLog ($this->data);
     $this->result['data']['files'] = $this->data;
     $this->result['data']['where'] = $this->where;
 }