tiki-edit_translation.php 8.4 KB
Newer Older
sylvieg's avatar
sylvieg committed
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3
// 
sylvieg's avatar
sylvieg committed
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
6
// $Id$
sylvieg's avatar
sylvieg committed
7 8 9 10

require_once('tiki-setup.php');

include_once('lib/multilingual/multilinguallib.php');
11 12 13
include_once('modules/mod-func-translation.php');

execute_module_translation();
sylvieg's avatar
sylvieg committed
14

15
$access->check_feature('feature_multilingual');
16
	
sylvieg's avatar
sylvieg committed
17 18
if (!(isset($_REQUEST['page']) && $_REQUEST['page']) && !(isset($_REQUEST['id']) && $_REQUEST['id'])) {
	$smarty->assign('msg',tra("No object indicated"));
sylvieg's avatar
sylvieg committed
19 20 21 22
	$smarty->display("error.tpl");
	die;
}

23 24
include_once("lang/langmapping.php");

25
if ((!isset($_REQUEST['type']) || $_REQUEST['type'] == 'wiki page' || $_REQUEST['type'] == 'wiki') && isset($_REQUEST['page']) && $_REQUEST['page']) {
sylvieg's avatar
sylvieg committed
26 27 28 29 30 31 32 33 34
	$info = $tikilib->get_page_info($_REQUEST['page']);
	if (empty($info)) {
		$smarty->assign('msg',tra("Page cannot be found"));
		$smarty->display("error.tpl");
		die;
	}
	$name = $_REQUEST['page'];
	$type = "wiki page";
	$objId = $info['page_id'];
35
	$langpage = $info['lang'];
36 37
	$fullLangName = $langmapping[$langpage][0];
	$smarty->assign( 'languageName', $fullLangName );
38 39
	$cat_type = 'wiki page';
	$cat_objid = $name;
40 41 42

	$edit_data = $info['data'];
	$smarty->assign('pagedata', TikiLib::htmldecode($edit_data));
43
	
44
	if ($prefs['feature_translation_incomplete_notice'] == 'y') {
45
		$smarty->assign('translate_message', "^".tra("Translation of this page is incomplete.")."^\n\n");
46
	}
sylvieg's avatar
sylvieg committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
}
else if ($_REQUEST['id']) {
	if (!isset($_REQUEST['type'])) {
		$smarty->assign('msg',tra("No type indicated"));
		$smarty->display("error.tpl");
		die;
	}
	if ($_REQUEST['type'] == "wiki page") {
		$info = $tikilib->get_page_info_from_id($_REQUEST['id']);
		if (empty($info)) {
			$smarty->assign('msg',tra("Page cannot be found"));
			$smarty->display("error.tpl");
			die;
		}
		$name = $info['pageName'];
		$type = "wiki page";
		$objId = $info['page_id'];
64
		$langpage = $info['lang'];
65 66
		$fullLangName = $langmapping[$langpage][0];
		$smarty->assign( 'languageName', $fullLangName );
67 68
		$cat_type = 'wiki page';
		$cat_objid = $name;
69 70 71 72 73 74 75 76
		
		$edit_data = $info['data'];
		$smarty->assign('pagedata', TikiLib::htmldecode($edit_data));
		
		if ($prefs['feature_translation_incomplete_notice'] == 'y') {
			$smarty->assign('translate_message', "^".tra("Translation of this page is incomplete.")."^\n\n");
		}
		
sylvieg's avatar
sylvieg committed
77 78
	}
	else if ($_REQUEST['type'] == "article") {
79 80
		global $artlib; require_once 'lib/articles/artlib.php';
		$info = $artlib->get_article($_REQUEST["id"]);
sylvieg's avatar
sylvieg committed
81 82 83 84 85 86 87 88
		if (empty($info)) {
			$smarty->assign('msg', tra("Article not found"));
			$smarty->display("error.tpl");
			die;
		}
		$name = $info['title'];
		$type = "article";
		$objId = $_REQUEST['id'];
89
		$langpage = $info['lang'];
90 91
		$cat_type = 'article';
		$cat_objid = $objId;
92 93
		$fullLangName = $langmapping[$langpage][0];
		$smarty->assign( 'languageName', $fullLangName );
sylvieg's avatar
sylvieg committed
94
	}
sylvieg's avatar
sylvieg committed
95 96
}

sylvieg's avatar
sylvieg committed
97 98 99
$smarty->assign('name', $name);
$smarty->assign('type', $type);
$smarty->assign('id', $objId);
sylvieg's avatar
sylvieg committed
100

101 102
include_once 'categorize_list.php';

103 104
if (isset($_REQUEST['langpage']) && !empty($_REQUEST['langpage']) && $_REQUEST['langpage'] != "NULL"
				&& $langpage != $_REQUEST['langpage']) { // update the language
sylvieg's avatar
sylvieg committed
105

106
	$error = $multilinguallib->updateObjectLang($type, $objId, $_REQUEST['langpage']);
sylvieg's avatar
sylvieg committed
107 108 109
	if ($error)
		$smarty->assign('error', $error);
	else {
110 111
		$info['lang'] = $_REQUEST['langpage'];	
		$langpage = $_REQUEST['langpage'];
sylvieg's avatar
sylvieg committed
112
	}
113 114 115

	$fullLangName = $langmapping[$langpage][0];
	$smarty->assign( 'languageName', $fullLangName );
sylvieg's avatar
sylvieg committed
116
}
117
$smarty->assign('langpage', $langpage);
sylvieg's avatar
sylvieg committed
118

119 120
if ($type == "wiki page") {
  $tikilib->get_perm_object($name, 'wiki page', $info, true);	
lphuberdeau's avatar
lphuberdeau committed
121
  if ( !($tiki_p_edit == 'y' || ($prefs['wiki_creator_admin'] == 'y' && $user && $info['creator'] == $user) )) {
122
	  $smarty->assign('errortype', 401);
123
		$smarty->assign('msg', tra("You do not have permission to edit this page."));
124 125 126 127 128 129
		$smarty->display("error.tpl");
		die;
	}
}

if (isset($_REQUEST['detach']) && isset($_REQUEST['srcId']) && $tiki_p_detach_translation == 'y') { // detach from a translation set
130
	check_ticket('edit-translation');
sylvieg's avatar
sylvieg committed
131 132
	$multilinguallib->detachTranslation($type, $_REQUEST['srcId']);
}
133
 else if (isset($_REQUEST['set']) && !empty($_REQUEST['srcName'])) { // attach to a translation set
134
	check_ticket('edit-translation');
135
	if (empty($langpage) || $langpage == "NULL") {
sylvieg's avatar
sylvieg committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149
		$error = "traLang";
		$smarty->assign('error', $error);
	}
	else {
		$srcInfo = $tikilib->get_page_info($_REQUEST['srcName']);
		if (empty($srcInfo)) {
			$error = "srcExists";
			$smarty->assign('error', $error);
		}
		else 
			if (!(isset($srcInfo['lang']) && $srcInfo['lang'])) {
				$error = "srcLang";
				$smarty->assign('error', $error);
			}
150
			elseif ($srcInfo['page_id'] != $objId) {
151
				$error = $multilinguallib->insertTranslation($type, $srcInfo['page_id'], $srcInfo['lang'], $objId, $langpage);
sylvieg's avatar
sylvieg committed
152 153 154 155 156 157 158 159
				if ($error)
					$smarty->assign('error', $error);
				else
					$_REQUEST['srcName'] = "";
			}
	}
	$smarty->assign('srcName', $_REQUEST['srcName']);
}
160
else if  (isset($_REQUEST['set']) && !empty($_REQUEST['srcId'])) {
161
	check_ticket('edit-translation');
162
	if (empty($langpage) || $langpage == "NULL") {
sylvieg's avatar
sylvieg committed
163 164 165 166
		$error = "traLang";
		$smarty->assign('error', $error);
	}
	else {
167 168
		global $artlib; require_once 'lib/articles/artlib.php';
		$srcInfo = $artlib->get_article($_REQUEST["srcId"]);
sylvieg's avatar
sylvieg committed
169 170 171 172 173 174 175 176 177 178
	if (empty($srcInfo)) {
			$error = "srcExists";
			$smarty->assign('error', $error);
		}
		else 
			if (!(isset($srcInfo['lang']) && $srcInfo['lang'])) {
				$error = "srcLang";
				$smarty->assign('error', $error);
			}
			else {
179
				$error = $multilinguallib->insertTranslation($type, $srcInfo['articleId'], $srcInfo['lang'], $objId, $langpage);
sylvieg's avatar
sylvieg committed
180 181 182 183 184 185 186
				if ($error)
					$smarty->assign('error', $error);
				else
					$_REQUEST['srcName'] = "";
			}
	}
	$smarty->assign('srcId', $_REQUEST['srcId']);
sylvieg's avatar
sylvieg committed
187
}
sylvieg's avatar
sylvieg committed
188

189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
if ($type == "wiki page") {
	// Fetches the list of pages with a langage assigned
	// that is different than those already included in the
	// current set.
	$result = $tikilib->query("
		SELECT lang, pageName 
		FROM tiki_pages 
		WHERE
			lang IS NOT NULL
			AND lang <> ?
			AND page_id NOT IN(
				SELECT
					a.page_id
				FROM
					tiki_pages a
					INNER JOIN tiki_translated_objects b ON a.lang = b.lang
					INNER JOIN tiki_translated_objects c ON b.traId = c.traId
				WHERE
					c.type = 'wiki page'
					AND c.objId = ?
			)
			AND page_id NOT IN(
				SELECT
					a.objId
				FROM
					tiki_translated_objects a
					INNER JOIN tiki_translated_objects b ON a.traId = b.traId
				WHERE
					b.lang = ?
218 219
					AND a.type = 'wiki page'
					AND b.type = 'wiki page'
220 221 222 223 224 225 226 227 228
			)
		ORDER BY pageName ASC", array($langpage, $info['page_id'], $langpage) );
  $pages = array( 'data' => array() );
  while( $row = $result->fetchRow() )
    $pages['data'][] = $row;

	$smarty->assign_by_ref('pages', $pages["data"]);
}
else if ($type == "article") {
229
	if ($tiki_p_admin_cms != 'y' && !$tikilib->user_has_perm_on_object($user, $id, 'article', 'tiki_p_edit_article') and ($info['author'] != $user or $info['creator_edit'] != 'y')) {
230
		$smarty->assign('errortype', 401);
231
		$smarty->assign('msg', tra("You do not have permission to edit this article"));
232 233 234 235 236
		$smarty->display("error.tpl");
		die;
	}
}

237
$trads = $multilinguallib->getTranslations($type, $objId, $name, $langpage, true);
sylvieg's avatar
sylvieg committed
238 239
$smarty->assign('trads', $trads);

240 241 242 243 244 245 246 247 248
$usedLang = array();
foreach( $trads as $trad )
	$usedLang[] = $trad['lang'];

$rawLangs = $tikilib->list_languages();
$languages = array();
foreach( $rawLangs as $langInfo )
	if( ! in_array( $langInfo['value'], $usedLang ) )
		$languages[] = $langInfo;
sylvieg's avatar
sylvieg committed
249
$smarty->assign_by_ref('languages', $languages);
250 251 252
if (count($languages) == 1) {
   $smarty->assign('only_one_language_left', 'y');
}
253

254
ask_ticket('edit-translation');
255 256 257 258

// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');

259 260 261 262 263
if ($type == 'article') {
	$articles = $artlib->list_articles(0, -1, 'title_asc', '', '', '', $user);
	$smarty->assign('articles', $articles["data"]);
}

sylvieg's avatar
sylvieg committed
264 265 266
// Display the template
$smarty->assign('mid', 'tiki-edit_translation.tpl');
$smarty->display("tiki.tpl");
267 268

function execute_module_translation() { 
269
	global $smarty;
270 271
	$module_reference = array(
		'name' => 'translation',
sylvieg's avatar
sylvieg committed
272 273 274 275
		'params' => '',
		'position' => 'r',
		'ord' => 1,
		'moduleId' => 0
276 277 278
	);

	global $modlib; require_once 'lib/modules/modlib.php';	
279

280
	$out = $modlib->execute_module( $module_reference );
281
	$smarty->assign('content_of_update_translation_section', $out);
282
}