diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index cdc6217228ed501bc51f01f9520db45110753ded..e620669c9339a1dcfe1f5f31e56b530f14c0909a 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -101,8 +101,8 @@ class DynamicForm extends VerySimpleModel { } - function getTitle() { return $this->get('title'); } - function getInstructions() { return $this->get('instructions'); } + function getTitle() { return $this->getLocal('title'); } + function getInstructions() { return $this->getLocal('instructions'); } function getForm($source=false) { if (!$this->_form || $source) { @@ -151,7 +151,9 @@ class DynamicForm extends VerySimpleModel { $this->set('updated', new SqlFunction('NOW')); if (isset($this->dirty['notes'])) $this->notes = Format::sanitize($this->notes); - return parent::save($refetch); + if ($rv = parent::save($refetch | $this->dirty)) + return $this->saveTranslations(); + return $rv; } function delete() { @@ -195,6 +197,53 @@ class DynamicForm extends VerySimpleModel { return $inst; } + function saveTranslations($vars=false) { + global $thisstaff; + + $vars = $vars ?: $_POST; + $tags = array( + 'title' => $this->getTranslateTag('title'), + 'instructions' => $this->getTranslateTag('instructions'), + ); + $rtags = array_flip($tags); + $translations = CustomDataTranslation::allTranslations($tags, 'phrase'); + foreach ($translations as $t) { + $T = $rtags[$t->object_hash]; + $content = @$vars['trans'][$t->lang][$T]; + if (!isset($content)) + continue; + + // Content is not new and shouldn't be added below + unset($vars['trans'][$t->lang][$T]); + + $t->text = $content; + $t->agent_id = $thisstaff->getId(); + $t->updated = SqlFunction::NOW(); + if (!$t->save()) + return false; + } + // New translations (?) + foreach ($vars['trans'] as $lang=>$parts) { + if (!Internationalization::isLanguageInstalled($lang)) + continue; + foreach ($parts as $T => $content) { + $content = trim($content); + if (!$content) + continue; + $t = CustomDataTranslation::create(array( + 'type' => 'phrase', + 'object_hash' => $tags[$T], + 'lang' => $lang, + 'text' => $content, + 'agent_id' => $thisstaff->getId(), + 'updated' => SqlFunction::NOW(), + )); + if (!$t->save()) + return false; + } + } + return true; + } static function getCrossTabQuery($object_type, $object_id='object_id', $exclude=array()) { @@ -709,10 +758,10 @@ class DynamicFormField extends VerySimpleModel { $this->save(); } - function save() { + function save($refetch=false) { if (count($this->dirty)) $this->set('updated', new SqlFunction('NOW')); - return parent::save(); + return parent::save($this->dirty || $refetch); } static function create($ht=false) { diff --git a/include/staff/dynamic-form.inc.php b/include/staff/dynamic-form.inc.php index 2d6e64f496f86f99f3743d34869ed8b328c95723..1939cda0e211de50eaddf249e51243853750ad7a 100644 --- a/include/staff/dynamic-form.inc.php +++ b/include/staff/dynamic-form.inc.php @@ -7,9 +7,20 @@ if($form && $_REQUEST['a']!='add') { $url = "?id=".urlencode($_REQUEST['id']); $submit_text=__('Save Changes'); $info = $form->ht; - $trans['title'] = $form->getTranslateTag('title'); - $trans['instructions'] = $form->getTranslateTag('instructions'); + $trans = array( + 'title' => $form->getTranslateTag('title'), + 'instructions' => $form->getTranslateTag('instructions'), + ); $newcount=2; + $translations = CustomDataTranslation::allTranslations($trans, 'phrase'); + $_keys = array_flip($trans); + foreach ($translations as $t) { + if (!Internationalization::isLanguageInstalled($t->lang)) + continue; + // Create keys of [trans][de_DE][title] for instance + $info['trans'][$t->lang][$_keys[$t->object_hash]] + = Format::viewableImages($t->text); + } } else { $title = __('Add new custom form section'); $action = 'add'; @@ -39,23 +50,65 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </thead> <tbody style="vertical-align:top"> <tr> - <td width="180" class="required"><?php echo __('Title'); ?>:</td> - <td><input type="text" name="title" size="40" - data-translate-tag="<?php echo $trans['title']; ?>" + <td colspan="2"> + <table class="full-width"><tbody><tr><td style="vertical-align:top"> +<?php +$langs = Internationalization::getConfiguredSystemLanguages(); +if ($form && count($langs) > 1) { ?> + <ul class="vertical tabs" id="translations"> + <li class="empty"><i class="icon-globe" title="This content is translatable"></i></li> +<?php foreach ($langs as $tag=>$nfo) { ?> + <li class="<?php if ($tag == $cfg->getPrimaryLanguage()) echo "active"; + ?>"><a href="#translation-<?php echo $tag; ?>" title="<?php + echo Internationalization::getLanguageDescription($tag); + ?>"><span class="flag flag-<?php echo strtolower($nfo['flag']); ?>"></span> + </a></li> +<?php } ?> + </ul> +<?php +} ?> + </td> + <td id="translations_container"> + <div id="translation-<?php echo $cfg->getPrimaryLanguage(); ?>" class="tab_content" + lang="<?php echo $cfg->getPrimaryLanguage(); ?>"> + <div class="required"><?php echo __('Title'); ?>:</div> + <div> + <input type="text" name="title" size="60" value="<?php echo $info['title']; ?>"/> <i class="help-tip icon-question-sign" href="#form_title"></i> - <font class="error"><?php - if ($errors['title']) echo '<br/>'; echo $errors['title']; ?></font> - </td> - </tr> - <tr> - <td width="180"><?php echo __('Instructions'); ?>:</td> - <td><textarea name="instructions" rows="3" cols="40" - data-translate-tag="<?php echo $trans['instructions']; ?>"><?php - echo $info['instructions']; ?></textarea> + <div class="error"><?php + if ($errors['title']) echo '<br/>'; echo $errors['title']; ?></div> + </div> + <div style="margin-top: 8px"><?php echo __('Instructions'); ?>: <i class="help-tip icon-question-sign" href="#form_instructions"></i> - </td> - </tr> + </div> + <textarea name="instructions" rows="3" cols="40" class="richtext"><?php + echo $info['instructions']; ?></textarea> + </div> + +<?php if ($langs && $form) { + foreach ($langs as $tag=>$nfo) { + if ($tag == $cfg->getPrimaryLanguage()) + continue; ?> + <div id="translation-<?php echo $tag; ?>" class="tab_content" + style="display:none;" lang="<?php echo $tag; ?>"> + <div> + <div class="required"><?php echo __('Title'); ?>:</div> + <input type="text" name="trans[<?php echo $tag; ?>][title]" size="60" + value="<?php echo $info['trans'][$tag]['title']; ?>"/> + <i class="help-tip icon-question-sign" href="#form_title"></i> + </div> + <div style="margin-top: 8px"><?php echo __('Instructions'); ?>: + <i class="help-tip icon-question-sign" href="#form_instructions"></i> + </div> + <textarea name="trans[<?php echo $tag; ?>][instructions]" cols="21" rows="12" + style="width:100%" class="richtext"><?php + echo $info['trans'][$tag]['instructions']; ?></textarea> + </div> +<?php } +} ?> + </td></tr></tbody></table> + </td></tr> </tbody> </table> <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> diff --git a/include/staff/page.inc.php b/include/staff/page.inc.php index cbc2d2526f1ed37e65952a3efb4e309208825c63..6326500aba5bd1b6d545eb1f8eae59bb7645cbda 100644 --- a/include/staff/page.inc.php +++ b/include/staff/page.inc.php @@ -116,10 +116,11 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <li><a href="#notes"><?php echo __('Internal Notes'); ?></a></li> </ul> <div class="tab_content active" id="content"> +<table class="full-width"><tbody><tr><td style="vertical-align:top"> <?php $langs = Internationalization::getConfiguredSystemLanguages(); if ($page && count($langs) > 1) { ?> - <ul class="vertical left tabs"> + <ul class="vertical tabs" id="translations"> <li class="empty"><i class="icon-globe" title="This content is translatable"></i></li> <?php foreach ($langs as $tag=>$nfo) { ?> <li class="<?php if ($tag == $cfg->getPrimaryLanguage()) echo "active"; @@ -131,15 +132,18 @@ if ($page && count($langs) > 1) { ?> </ul> <?php } ?> - <div id="msg_info" style="margin:0 55px"> +</td> +<td id="translations_container" style="padding-left: 10px"> + <div id="msg_info"> <em><i class="icon-info-sign"></i> <?php echo __( 'Ticket variables are only supported in thank-you pages.' - ); ?></em></div> + ); ?></em> + </div> - <div id="translation-<?php echo $cfg->getPrimaryLanguage(); ?>" class="tab_content" style="margin:0 45px" + <div id="translation-<?php echo $cfg->getPrimaryLanguage(); ?>" class="tab_content" lang="<?php echo $cfg->getPrimaryLanguage(); ?>"> - <textarea name="body" cols="21" rows="12" style="width:98%;" class="richtext draft" + <textarea name="body" cols="21" rows="12" style="width:100%" class="richtext draft" <?php list($draft, $attrs) = Draft::getDraftAndDataAttrs('page', $info['id'], $info['body']); echo $attrs; ?>><?php echo $draft ?: $info['body']; ?></textarea> @@ -150,17 +154,18 @@ if ($page && count($langs) > 1) { ?> if ($tag == $cfg->getPrimaryLanguage()) continue; ?> <div id="translation-<?php echo $tag; ?>" class="tab_content" - style="display:none;margin:0 45px" lang="<?php echo $tag; ?>"> + style="display:none;" lang="<?php echo $tag; ?>"> <textarea name="trans[<?php echo $tag; ?>][body]" cols="21" rows="12" - style="width:98%;" class="richtext draft" + style="width:100%" class="richtext draft" <?php list($draft, $attrs) = Draft::getDraftAndDataAttrs('page', $info['id'].'.'.$tag, $info['trans'][$tag]); echo $attrs; ?>><?php echo $draft ?: $info['trans'][$tag]; ?></textarea> </div> <?php } } ?> +</td></tr></tbody></table> - <div class="error" style="margin: 5px 55px"><?php echo $errors['body']; ?></div> + <div class="error" style="margin: 5px 0"><?php echo $errors['body']; ?></div> <div class="clear"></div> </div> <div class="tab_content" style="display:none" id="notes"> diff --git a/scp/css/scp.css b/scp/css/scp.css index 4773680839f8c5f349e6c2fc6090ef7a8b803464..d958edda6e4b31ffbe376d141fc68788e7c8d60e 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -632,10 +632,16 @@ table.fixed { border-collapse: collapse; width: 100%; } -table.fixed td { +table.fixed > thead > tr > th, +table.fixed > thead > tr > td, +table.fixed > tbody > tr > td, +table.fixed > tr > td { width: 180px; } -table.fixed td + td { +table.fixed > thead > tr > th + th, +table.fixed > thead > tr > td + td, +table.fixed > tbody > tr > td + td, +table.fixed > tr > td + td { width: auto; } diff --git a/scp/css/translatable.css b/scp/css/translatable.css index d949d2d4fafac616e4fd4764847044e7116b90cf..3bece152ac700f39a6e7ff6404e3e7ae14814044 100644 --- a/scp/css/translatable.css +++ b/scp/css/translatable.css @@ -100,13 +100,14 @@ div.translatable { box-shadow: inset 0 1px 1px rgba(0,0,0,0.05); display: inline-block; white-space: nowrap; - border-top-left-radius: 4px; - border-bottom-left-radius: 4px; + border-top-left-radius: 3px; + border-bottom-left-radius: 3px; border-right: none; - padding: 0 5px 2px; + padding: 1px 5px 1px; margin-left: 2px; width: auto; background-color: white; + line-height: 16px; } div.translatable.textarea { border: 1px solid #bbb;