function editView($id, $language) { global $Controller, $DB; $obj = new NewsItem($id, $language); if (!$obj) { return false; } if (!$obj->mayI(EDIT)) { errorPage(401); } $this->setContent('header', __('Editing') . ' <i>"' . $obj . '"</i>'); if ($_REQUEST['view'] == 'content') { $form = new Form('editN'); $translate = array(); if (!@$obj->content['Preamble'] && !$_POST['apre']) { $translate[] = 'Preamble'; } if (!@$obj->content['Text'] && !$_POST['atxt']) { $translate[] = 'Text'; } $trFrom = $trSect = $trText = array(); if (!empty($translate)) { $newest = $DB->asArray("SELECT t1.section, t1.* FROM content AS t1\n LEFT JOIN content t2 ON t1.section = t2.section\n AND t1.language = t2.language\n AND t1.revision < t2.revision\n WHERE t2.section IS NULL\n AND t1.id='" . Database::escape($id) . "'\n AND (t1.section='" . implode("' OR t1.section='", Database::escape($translate, true)) . "')\n ORDER BY t1.revision DESC", true); foreach ($newest as $s => $translation) { $trFrom[] = $translation['language']; $trText[] = $translation['content']; $trSect[] = $s; } } if (!$obj->Name && !$_POST['atitle']) { if ($info = $DB->metadata->getRow(array('id' => $obj->ID, 'field' => 'Name'), 'value, metameta')) { $trFrom[] = $info['metameta']; $trText[] = $info['value']; $trSect[] = 'Name'; } } $translation = array(); if (!empty($trText)) { $translation = @array_combine($trSect, google::translate($trText, $trFrom, $language)); } $this->setContent('main', '<div class="nav"><a href="' . url(null, array('id', 'edit')) . '">' . icon('small/arrow_left') . __('Back') . '</a></div>' . $form->collection(new Hidden('asave', 1), new Hidden('edit', $id), new Set(new Hidden('lang', $language), new FormText(__('Language'), google::languages($language)), empty($translation) ? null : '<span class="warning">' . __('Warning - Some of the text has been automatically translated') . '</span>', new Input(__('Title'), 'atitle', $_POST['atitle'] ? $_POST['atitle'] : ($obj->Name ? $obj->Name : @$translation['Name'])), new Li(new Datepicker(__('Publish'), 'apubd', $_POST['apubd'] ? $_POST['apubd'] : ($obj->Publish ? date('Y-m-d', $obj->Publish) : '')), new Timepickr(false, 'apubt', $_POST['apubt'] ? $_POST['pubt'] : ($obj->Publish ? date('H:i', $obj->Publish) : ''))), new htmlfield(__('Text'), 'atxt', $_POST['atxt'] ? $_POST['atxt'] : (@$obj->content['Text'] ? @$obj->content['Text'] : @$translation['Text'])), new htmlfield(__('Preamble'), 'apre', $_POST['apre'] ? $_POST['apre'] : (@$obj->content['Preamble'] ? @$obj->content['Preamble'] : @$translation['Preamble']))))); } else { PageEditor::saveChanges($obj); $this->setContent('main', PageEditor::editor($id)); } }