示例#1
0
            // Load the appropriate CRUD form
            $tableData = $class::readForm($lookupID);
            // If this is the delete page, show an option to delete it
            $tableData['footer'] = ['' => '', 'Option Next' => '<a href="/model/' . $class . '/view/' . $lookupID . '&' . Link::prepare("DeletedRecord") . '" onclick="return confirm(\'Are you sure you want to delete this record?\')">Delete this Record</a>'];
            echo UI_Table::draw($tableData);
        }
        echo '<div><a href="/model/' . $class . '">Search Records</a></div>';
        break;
        // Generation of this model
    // Generation of this model
    case "generate":
        Classes_Generator::generate($class);
        break;
        // Search Table
    // Search Table
    case "search":
    default:
        // Display the Alerts
        echo Alert::display();
        // Make sure the class exists before calling it
        if (method_exists($class, 'searchForm')) {
            echo '<a href="/model/' . $class . '/create">Create New ' . ucfirst($class) . ' Record</a>';
            echo ' <a href="/model/' . $class . '/generate" onclick="return confirm(\'This will overwrite files in the /controller/' . $class . '/ directory. Are you sure you want to generate default pages?\')">Generate Default Pages For ' . ucfirst($class) . '</a>';
            // Display the Model Name
            echo '<h2>Search the `' . ucfirst($class) . '` Table</h2>';
            // Load the Search Form
            $tableData = $class::searchForm();
            echo UI_Table::draw($tableData);
            echo '<a href="/model/' . $class . '/create">Create New ' . ucfirst($class) . ' Record</a>';
        }
}
    public static function generateCreateForm($class)
    {
        // Prepare Values
        $schema = $class::$schema;
        $currentRow = 0;
        $controller = '
// Handle a Submission
if(Form::submitted("' . $class . '-protect-form"))
{
	// Make sure the the submission is valid
	if($result = ' . $class . '::verifyForm($_POST))
	{
		// If the submission is valid, process the form
		if(' . $class . '::create($_POST))
		{
			Alert::saveSuccess("Form Created", "The form data was properly submitted!");
			
			// Clear the existing POST data
			unset($_POST);
		}
	}
}

// Display the Alerts
echo Alert::display();';
        // Loop through each column in the schema
        foreach ($schema['columns'] as $columnName => $columnRules) {
            // Identify and process tags that were listed for this column
            if (isset($schema['tags'][$columnName])) {
                $tags = is_array($schema['tags'][$columnName]) ? $schema['tags'][$columnName] : [$schema['tags'][$columnName]];
                // Check if there are any tags that the user needs to test
                foreach ($tags as $tag) {
                    switch ($tag) {
                        // If the tag cannot be modified, don't show it on the form
                        case Model::CANNOT_SET:
                            continue 3;
                    }
                }
            }
            // If data was submitted by the user, set the column's value to their input
            if (isset($_POST[$columnName])) {
                $value = $_POST[$columnName];
            } else {
                $value = isset($schema['default'][$columnName]) ? $schema['default'][$columnName] : '';
            }
            $currentRow++;
            $columnTitle = ucwords(str_replace("_", " ", $columnName));
            $table[$currentRow][0] = $columnTitle;
            // Determine how to display the column
            switch ($columnRules[0]) {
                ### Strings and Text ###
                case "string":
                case "text":
                    // Identify all string-related form variables
                    $minLength = isset($columnRules[1]) ? (int) $columnRules[1] : 0;
                    $maxLength = isset($columnRules[2]) ? (int) $columnRules[2] : ($columnRules[0] == "text" ? 0 : 250);
                    // Display a textarea for strings of 101 characters or more
                    if (!$maxLength or $maxLength > 100) {
                        $table[$currentRow][1] = '
				<textarea id="' . $columnName . '" name="' . $columnName . '"' . ($maxLength ? 'maxlength="' . $maxLength . '"' : '') . '><?php htmlspecialchars($value); ?></textarea>';
                    } else {
                        $table[$currentRow][1] = '
				<input id="' . $columnName . '" type="text"
					name="' . $columnName . '"
					value="<?php htmlspecialchars($value); ?>"
					' . ($maxLength ? 'maxlength="' . $maxLength . '"' : '') . '
					/>';
                    }
                    break;
                    ### Integers ###
                ### Integers ###
                case "tinyint":
                    // 256
                // 256
                case "smallint":
                    // 65k
                // 65k
                case "mediumint":
                case "int":
                case "bigint":
                    // Identify all string-related form variables
                    $minRange = isset($columnRules[1]) ? (int) $columnRules[1] : null;
                    $maxRange = isset($columnRules[2]) ? (int) $columnRules[2] : null;
                    $maxLength = self::getLengthOfNumberType($columnRules[0], $minRange, $maxRange);
                    // Display the form field for an integer
                    $table[$currentRow][1] = '
			<input id="' . $columnName . '" type="number"
				name="' . $columnName . '"
				value="<?php echo ((int) $value); ?>"' . ($maxLength ? 'maxlength="' . $maxLength . '"' : '') . ($minRange ? 'min="' . $minRange . '"' : '') . ($maxRange ? 'max="' . $maxRange . '"' : '') . '
				/>';
                    break;
                    ### Floats ###
                ### Floats ###
                case "float":
                case "double":
                    // Identify all string-related form variables
                    $minRange = isset($columnRules[1]) ? (int) $columnRules[1] : null;
                    $maxRange = isset($columnRules[2]) ? (int) $columnRules[2] : null;
                    $maxLength = self::getLengthOfNumberType($columnRules[0], $minRange, $maxRange);
                    // Display the form field for an integer
                    $formHTML .= '
			<input id="' . $columnName . '" type="text"
				name="' . $columnName . '"
				value="<?php echo ((int) $value); ?>"' . ($maxLength ? 'maxlength="' . ($maxLength + ceil($maxLength / 3)) . '"' : '') . '
				/>';
                    break;
                    ### Booleans ###
                ### Booleans ###
                case "bool":
                case "boolean":
                    // If the boolean types are not declared, set defaults
                    $trueName = isset($columnRules[1]) ? $columnRules[1] : 'True';
                    $falseName = isset($columnRules[2]) ? $columnRules[2] : 'False';
                    // Display the form field for a boolean
                    $table[$currentRow][1] = '
			<select id="' . $columnName . '" name="' . $columnName . '"><?php echo str_replace(\'value="' . $value . '"\', \'value="' . $value . '" selected\', \'
				<option value="1">' . htmlspecialchars($trueName) . '</option>
				<option value="0">' . htmlspecialchars($falseName) . '</option>\'); ?>
			</select>';
                    break;
                    ### Enumerators ###
                ### Enumerators ###
                case "enum-number":
                case "enum-string":
                    // Get the available list of enumerators
                    $enums = array_slice($columnRules, 1);
                    // Display the form field for a boolean
                    $table[$currentRow][1] = '
			<select id="' . $columnName . '" name="' . $columnName . '"><?php echo str_replace(\'value="' . $value . '"\', \'value="' . $value . '" selected\', \'';
                    // Handle numeric enumerators differently than string enumerators
                    // These will have a numeric counter associated with each value
                    if ($columnRules[0] == "enum-number") {
                        $enumCount = count($enums);
                        for ($i = 0; $i < $enumCount; $i++) {
                            $table[$currentRow][1] .= '
					<option value="' . $i . '">' . htmlspecialchars($enums[$i]) . '</option>';
                        }
                    } else {
                        foreach ($enums as $enum) {
                            $table[$currentRow][1] .= '
					<option value="' . htmlspecialchars($enum) . '">' . htmlspecialchars($enum) . '</option>';
                        }
                    }
                    $table[$currentRow][1] .= '\'); ?>
			</select>';
                    break;
            }
        }
        // Convert the data into an HTML table
        $table[$currentRow + 1] = ['Submit', '<input type="submit" name="submit" value="Submit" />'];
        $view = '?>

<form action="/' . $class . '/create" method="post"><?php echo Form::prepare("' . $class . '-protect-form"); ?>
' . UI_Table::draw($table) . '
</form>

<?php';
        // Save the page / form to the appropriate file
        $pageHTML = self::generatePage($controller, $view);
        File::write(APP_PATH . "/controller/" . $class . "/create.php", $pageHTML);
    }
示例#3
0
文件: UI.php 项目: jeckel420/Localize
 public static function getPage_Project($contents, $containers)
 {
     $page = self::getDataGET('p');
     $repositoryID = self::validateID(self::getDataGET('project'), true);
     $languageID = self::validateID(self::getDataGET('language'), true);
     $isAddingMode = isset($page) && $page == 'add_phrase';
     $isExportMode = isset($page) && $page == 'export';
     $isImportMode = isset($page) && $page == 'import';
     $repositoryData = Database::getRepositoryData($repositoryID);
     $languageData = Database::getLanguageData($languageID);
     if (empty($repositoryData)) {
         self::addBreadcrumbItem(URL::toProject($repositoryID), 'Project not found');
         self::setTitle('Project not found');
         $contents[] = new UI_Heading('Project not found', true);
         $contents[] = new UI_Paragraph('We\'re sorry, but we could not find the project that you requested.');
         $contents[] = new UI_Paragraph('Please check if you have made any typing errors.');
     } else {
         self::addBreadcrumbItem(URL::toProject($repositoryID), htmlspecialchars($repositoryData['name']));
         Authentication::saveCachedRepository($repositoryID, $repositoryData['name']);
         $repository = new Repository($repositoryID, $repositoryData['name'], $repositoryData['visibility'], $repositoryData['defaultLanguage']);
         $role = Database::getRepositoryRole(Authentication::getUserID(), $repositoryID);
         $permissions = $repository->getPermissions(Authentication::getUserID(), $role);
         if (Authentication::getUserID() <= 0) {
             self::setTitle($repositoryData['name']);
             $contents[] = new UI_Heading(htmlspecialchars($repositoryData['name']), true);
             $contents[] = self::getLoginForm();
         } elseif ($permissions->isInvitationMissing()) {
             self::setTitle($repositoryData['name']);
             $contents[] = new UI_Heading(htmlspecialchars($repositoryData['name']), true);
             $contents[] = self::getInvitationForm($repositoryID);
         } else {
             $defaultLanguage = new Language_Android($repository->getDefaultLanguage());
             if ($isAddingMode) {
                 $formTargetURL = URL::toAddPhrase($repositoryID, $languageID);
                 self::addBreadcrumbItem($formTargetURL, 'Add phrase');
                 $form = new UI_Form($formTargetURL, false);
                 $radioType = new UI_Form_Radio('Phrase type', 'add_phrase[type]');
                 $radioType->addOption('<abbr title="Resource type for single phrases">string</abbr>', 1, 'addPhraseTypeSelect(\'addPhraseGroup_String\');');
                 $radioType->addOption('<abbr title="Resource type for arrays of phrases">string-array</abbr>', 2, 'addPhraseTypeSelect(\'addPhraseGroup_StringArray\');');
                 $radioType->addOption('<abbr title="Resource type for quantity strings">plurals</abbr>', 3, 'addPhraseTypeSelect(\'addPhraseGroup_Plurals\');');
                 $form->addContent($radioType);
                 $textPhraseKey = new UI_Form_Text('Key', 'add_phrase[key]', 'Unique identifier', false, 'This is the short string that you\'ll identify the phrase(s) with later.');
                 $form->addContent($textPhraseKey);
                 $textPhraseStringValue = new UI_Form_Textarea('String', 'add_phrase[string]', 'String for ' . $defaultLanguage->getNameFull(), 'You can later translate this string to other languages.', false, '', 2, $defaultLanguage->isRTL(), '', 'addPhraseGroup_String');
                 $form->addContent($textPhraseStringValue);
                 $textPhraseStringArrayValue = new UI_Form_Textarea('Item', 'add_phrase[string_array][]', 'Item for ' . $defaultLanguage->getNameFull(), 'You can later translate this item to other languages.', false, '', 2, $defaultLanguage->isRTL(), '', 'addPhraseGroup_StringArray', 'display:none;', false);
                 $form->addContent($textPhraseStringArrayValue);
                 $quantities = Phrase_Android_Plurals::getList();
                 foreach ($quantities as $quantity) {
                     $textPhrasePluralsValue = new UI_Form_Textarea($quantity, 'add_phrase[plurals][' . $quantity . ']', 'Quantity for ' . $defaultLanguage->getNameFull(), 'You can later translate this quantity to other languages.', false, '', 2, $defaultLanguage->isRTL(), '', 'addPhraseGroup_Plurals', 'display:none;');
                     $form->addContent($textPhrasePluralsValue);
                 }
                 $buttonSubmit = new UI_Form_Button('Save phrase(s)', UI_Link::TYPE_SUCCESS);
                 $buttonAddItem = new UI_Link('Add item', '#', UI_Link::TYPE_INFO, 'addPhraseGroup_StringArray', 'display:none;', 'addPhraseAddItem(\'add_phrase[string_array][]\'); return false;');
                 $buttonCancel = new UI_Link('Cancel', URL::toLanguage($repositoryID, $languageID), UI_Link::TYPE_UNIMPORTANT);
                 $form->addContent(new UI_Form_ButtonGroup(array($buttonSubmit, $buttonAddItem, $buttonCancel)));
                 self::setTitle('Add phrase to default language');
                 $contents[] = new UI_Heading('Add phrase to default language', true);
                 $contents[] = $form;
             } elseif ($isExportMode) {
                 $formTargetURL = URL::toExport($repositoryID);
                 self::addBreadcrumbItem($formTargetURL, 'Export');
                 $form = new UI_Form($formTargetURL, false);
                 $textFilename = new UI_Form_Text('Filename', 'export[filename]', 'strings', false, 'Please choose a filename (without extension) for the output files that will be exported inside each language folder.');
                 $textFilename->setDefaultValue('strings');
                 $form->addContent($textFilename);
                 $selectGroupID = new UI_Form_Select('Phrase groups', 'export[groupID]', 'Do you want to export all phrases or only a single group?');
                 $selectGroupID->addOption('(All groups)', Phrase::GROUP_ALL);
                 $selectGroupID->addOption('(Default group)', Phrase::GROUP_NONE);
                 $phraseGroups = Database::getPhraseGroups($repositoryID, $repositoryData['defaultLanguage'], false);
                 foreach ($phraseGroups as $phraseGroup) {
                     $selectGroupID->addOption($phraseGroup['name'], $phraseGroup['id']);
                 }
                 $form->addContent($selectGroupID);
                 $selectMinCompletion = new UI_Form_Select('Minimum completion', 'export[minCompletion]', 'You can either export all languages or only those with a given minimum completion.');
                 $selectMinCompletion->addOption('Export all languages', 0);
                 $selectMinCompletion->addOption('5% completion or more', 5);
                 $selectMinCompletion->addOption('10% completion or more', 10);
                 $selectMinCompletion->addOption('25% completion or more', 25);
                 $selectMinCompletion->addOption('50% completion or more', 50);
                 $selectMinCompletion->addOption('75% completion or more', 75);
                 $selectMinCompletion->addOption('100% completion or more', 100);
                 $form->addContent($selectMinCompletion);
                 $selectFormat = new UI_Form_Select('Output format', 'export[format]', 'Which output format do you want to export in? When developing for Android, you should usually keep the default choice.');
                 $selectFormat->addOption('Android XML', File_IO::FORMAT_ANDROID_XML);
                 $selectFormat->addOption('Android XML with escaped HTML', File_IO::FORMAT_ANDROID_XML_ESCAPED_HTML);
                 $selectFormat->addOption('JSON', File_IO::FORMAT_JSON);
                 $selectFormat->addOption('Plaintext', File_IO::FORMAT_PLAINTEXT);
                 $form->addContent($selectFormat);
                 $ignoreIfSameAsDefault = new UI_Form_Select('Exclude defaults', 'export[ignoreIfSameAsDefault]', 'Do you want to exclude phrases which are the same as the respective phrase in the default language?');
                 $ignoreIfSameAsDefault->addOption('No, export a complete file for each language', 0);
                 $ignoreIfSameAsDefault->addOption('Yes, export only what\'s necessary', 1);
                 $form->addContent($ignoreIfSameAsDefault);
                 $isAdmin = Repository::hasUserPermissions(Authentication::getUserID(), $repositoryID, $repositoryData, Repository::ROLE_ADMINISTRATOR);
                 $buttonSubmit = new UI_Form_Button('Export', UI_Link::TYPE_SUCCESS);
                 $buttonManageGroups = new UI_Link('Manage groups', URL::toEditProject($repositoryID, true), UI_Link::TYPE_UNIMPORTANT);
                 $buttonCancel = new UI_Link('Cancel', URL::toProject($repositoryID), UI_Link::TYPE_UNIMPORTANT);
                 if ($isAdmin) {
                     $form->addContent(new UI_Form_ButtonGroup(array($buttonSubmit, $buttonManageGroups, $buttonCancel)));
                 } else {
                     $form->addContent(new UI_Form_ButtonGroup(array($buttonSubmit, $buttonCancel)));
                 }
                 self::setTitle('Export');
                 $contents[] = new UI_Heading('Export', true);
                 $contents[] = $form;
             } elseif ($isImportMode) {
                 $formTargetURL = URL::toImport($repositoryID);
                 self::addBreadcrumbItem($formTargetURL, 'Import XML');
                 $form = new UI_Form($formTargetURL, false, true);
                 $radioOverwrite = new UI_Form_Radio('Overwrite', 'import[overwrite]');
                 $radioOverwrite->addOption('<strong>Import only new phrases</strong> and do not overwrite any existing phrases', 0);
                 $radioOverwrite->addOption('<strong>Import all phrases</strong> and overwrite any phrases that do already exist', 1);
                 $form->addContent($radioOverwrite);
                 $selectLanguage = new UI_Form_Select('Language', 'import[languageID]', 'Which language do you want to import the phrases for?', false, '', '', 'if (this.value === \'' . $repositoryData['defaultLanguage'] . '\') { $(\'.import-group-id\').show(400); } else { $(\'.import-group-id\').hide(400); }');
                 $selectLanguage->addOption('— Please choose —', 0);
                 $languageIDs = Language::getList($repositoryData['defaultLanguage']);
                 foreach ($languageIDs as $languageID) {
                     $selectLanguage->addOption(Language_Android::getLanguageNameFull($languageID), $languageID);
                 }
                 $form->addContent($selectLanguage);
                 $selectGroupID = new UI_Form_Select('Phrase group', 'import[groupID]', 'Which group do you want to import the phrases to?', false, 'import-group-id', 'display:none;');
                 $selectGroupID->addOption('(Default group)', Phrase::GROUP_NONE);
                 $phraseGroups = Database::getPhraseGroups($repositoryID, $repositoryData['defaultLanguage'], false);
                 foreach ($phraseGroups as $phraseGroup) {
                     $selectGroupID->addOption($phraseGroup['name'], $phraseGroup['id']);
                 }
                 $form->addContent($selectGroupID);
                 $fileSizeHidden = new UI_Form_Hidden('MAX_FILE_SIZE', File_IO::getMaxFileSize());
                 $form->addContent($fileSizeHidden);
                 $fileXML = new UI_Form_File('XML file', 'importFileXML', 'The XML resources file that you want to extract the phrases from.');
                 $form->addContent($fileXML);
                 $isAdmin = Repository::hasUserPermissions(Authentication::getUserID(), $repositoryID, $repositoryData, Repository::ROLE_ADMINISTRATOR);
                 $buttonSubmit = new UI_Form_Button('Import XML', UI_Link::TYPE_SUCCESS);
                 $buttonManageGroups = new UI_Link('Manage groups', URL::toEditProject($repositoryID, true), UI_Link::TYPE_UNIMPORTANT);
                 $buttonCancel = new UI_Link('Cancel', URL::toProject($repositoryID), UI_Link::TYPE_UNIMPORTANT);
                 if ($isAdmin) {
                     $form->addContent(new UI_Form_ButtonGroup(array($buttonSubmit, $buttonManageGroups, $buttonCancel)));
                 } else {
                     $form->addContent(new UI_Form_ButtonGroup(array($buttonSubmit, $buttonCancel)));
                 }
                 self::setTitle('Import XML');
                 $contents[] = new UI_Heading('Import XML', true);
                 $contents[] = $form;
             } elseif (empty($languageData)) {
                 self::setTitle($repositoryData['name']);
                 $heading = new UI_Heading(htmlspecialchars($repositoryData['name']), true, 1, $repository->getShareURL());
                 $languageTable = new UI_Table(array('Language', 'Completion'));
                 $languageTable->setColumnPriorities(8, 4);
                 $languages = Language::getList($defaultLanguage->getID());
                 $cachedLanguageProgress = Authentication::getCachedLanguageProgress($repositoryID);
                 $newCachedLanguageProgress = array();
                 if (empty($cachedLanguageProgress)) {
                     $repository->loadLanguages(false, Repository::SORT_NO_LANGUAGE, Repository::LOAD_ALL_LANGUAGES);
                 }
                 foreach ($languages as $languageID) {
                     $linkURL = URL::toLanguage($repositoryID, $languageID);
                     $nameLink = new UI_Link(Language::getLanguageNameFull($languageID), $linkURL, UI_Link::TYPE_UNIMPORTANT);
                     if (empty($cachedLanguageProgress)) {
                         $languageObject = $repository->getLanguage($languageID);
                         $completeness = intval($languageObject->getCompleteness() * 100);
                     } else {
                         $completeness = intval($cachedLanguageProgress[$languageID]);
                     }
                     $progressBar = new UI_Progress($completeness);
                     $rowClass = $languageID == $defaultLanguage->getID() ? 'active' : '';
                     $languageTable->addRow(array($nameLink->getHTML(), $progressBar->getHTML()), '', $rowClass);
                     $newCachedLanguageProgress[$languageID] = $completeness;
                 }
                 Authentication::setCachedLanguageProgress($repositoryID, $newCachedLanguageProgress);
                 $actionsForm = new UI_Form(URL::toProject($repositoryID), false);
                 $actionsForm->addContent(new UI_Form_Hidden('exportXML', 1));
                 $actionButtons = array();
                 if (Repository::hasUserPermissions(Authentication::getUserID(), $repositoryID, $repositoryData, Repository::ROLE_DEVELOPER)) {
                     $actionButtons[] = new UI_Link('Export', URL::toExport($repositoryID), UI_Link::TYPE_SUCCESS);
                     $actionButtons[] = new UI_Link('Import XML', URL::toImport($repositoryID), UI_Link::TYPE_UNIMPORTANT);
                     if (Repository::hasUserPermissions(Authentication::getUserID(), $repositoryID, $repositoryData, Repository::ROLE_ADMINISTRATOR)) {
                         $actionButtons[] = new UI_Link('Edit project', URL::toEditProject($repositoryID), UI_Link::TYPE_UNIMPORTANT);
                     }
                     $actionButtons[] = new UI_Link('Add phrase', URL::toAddPhrase($repositoryID, $defaultLanguage->getID()), UI_Link::TYPE_UNIMPORTANT);
                     $actionButtons[] = new UI_Link('Watch', URL::toWatchProject($repositoryID), UI_Link::TYPE_INFO);
                 }
                 if (!empty($actionButtons)) {
                     $actionsForm->addContent(new UI_Form_ButtonGroup($actionButtons, true));
                 }
                 $contents[] = $heading;
                 $contents[] = $actionsForm;
                 $contents[] = $languageTable;
                 $contents[] = $actionsForm;
             } else {
                 try {
                     $mayMovePhrases = Repository::isRoleAllowedToMovePhrases($role);
                     $language = new Language_Android($languageID);
                     self::addBreadcrumbItem(URL::toLanguage($repositoryID, $languageID), $language->getNameFull());
                     self::setTitle($languageData->getNameFull());
                     $heading = new UI_Heading($languageData->getNameFull(), true);
                     $repository->loadLanguages(false, $languageID, $languageID);
                     $languageLeft = $repository->getLanguage($repository->getDefaultLanguage());
                     $languageRight = $repository->getLanguage($language->getID());
                     $languageLeftPhrases = $languageLeft->getPhrases();
                     $languageRightPhrases = $languageRight->getPhrases();
                     if (count($languageLeftPhrases) != count($languageRightPhrases)) {
                         throw new Exception('Count of left language\'s phrases does not match right language\'s count of phrases');
                     }
                     $phrasesTableColumnNames = array('left' => '', 'right' => '');
                     if ($language->getID() == $defaultLanguage->getID()) {
                         // viewing the default language itself
                         $phrasesTableColumnNames['left'] = 'Unique key';
                         $phrasesTableColumnNames['right'] = $language->getNameFull();
                     } else {
                         // viewing another language that will be compared to default language
                         $phrasesTableColumnNames['left'] = $defaultLanguage->getNameFull();
                         $phrasesTableColumnNames['right'] = $language->getNameFull();
                     }
                     if ($mayMovePhrases) {
                         $phrasesTable = new UI_Table(array('&nbsp;', $phrasesTableColumnNames['left'], $phrasesTableColumnNames['right']));
                         $phrasesTable->setColumnPriorities(1, 5, 6);
                     } else {
                         $phrasesTable = new UI_Table(array($phrasesTableColumnNames['left'], $phrasesTableColumnNames['right']));
                         $phrasesTable->setColumnPriorities(6, 6);
                     }
                     $translationSecret = Authentication::createSecret();
                     if (count($languageLeftPhrases) <= 0) {
                         if ($mayMovePhrases) {
                             $phrasesTable->addRow(array('', 'No phrases yet', 'No phrases yet'));
                         } else {
                             $phrasesTable->addRow(array('No phrases yet', 'No phrases yet'));
                         }
                     } else {
                         Database::initTranslationSession($repositoryID, $languageID, Authentication::getUserID(), $translationSecret, time());
                         if ($language->getID() == $defaultLanguage->getID()) {
                             // viewing the default language itself
                             /** @var Phrase $defaultPhrase */
                             foreach ($languageLeftPhrases as $defaultPhrase) {
                                 $values = $defaultPhrase->getPhraseValues();
                                 foreach ($values as $subKey => $value) {
                                     $phraseFormKey = 'updatePhrases[edits][' . URL::encodeID($defaultPhrase->getID()) . '][' . $subKey . ']';
                                     $value = Authentication::getCachedEdit($repositoryID, $languageID, URL::encodeID($defaultPhrase->getID()), $subKey, $value);
                                     $valuePrevious = new UI_Form_Hidden(str_replace('[edits]', '[previous]', $phraseFormKey), $value);
                                     $valueEdit = new UI_Form_Textarea('', $phraseFormKey, $value, '', true, htmlspecialchars($value), UI_Form_Textarea::getOptimalRowCount($value, 2), $defaultLanguage->isRTL(), 'setUnsavedChanges(true);');
                                     if ($mayMovePhrases) {
                                         $editPhraseLink = new UI_Link('Edit', URL::toPhraseDetails($repositoryID, $languageID, $defaultPhrase->getID()), UI_Link::TYPE_UNIMPORTANT);
                                         $editPhraseLink->setSize(UI_Link::SIZE_SMALL);
                                         $editPhraseLink->setTabIndex('-1');
                                         $phrasesTable->addRow(array($editPhraseLink->getHTML(), Phrase_Android::getFullyQualifiedName($defaultPhrase, $subKey), $valuePrevious->getHTML() . $valueEdit->getHTML()));
                                     } else {
                                         $phrasesTable->addRow(array(Phrase_Android::getFullyQualifiedName($defaultPhrase, $subKey), $valuePrevious->getHTML() . $valueEdit->getHTML()));
                                     }
                                 }
                             }
                         } else {
                             // viewing another language that will be compared to default language
                             foreach ($languageRightPhrases as $rightPhrase) {
                                 /** @var Phrase $rightPhrase */
                                 $defaultPhrase = $languageLeft->getPhraseByKey($rightPhrase->getPhraseKey());
                                 $valuesLeft = $defaultPhrase->getPhraseValues();
                                 $valuesRight = $rightPhrase->getPhraseValues();
                                 foreach ($valuesLeft as $subKey => $valueLeft) {
                                     $valueLeftHTML = '<span dir="' . ($defaultLanguage->isRTL() ? 'rtl' : 'ltr') . '">' . nl2br(htmlspecialchars($valueLeft)) . '</span><span dir="ltr" class="small" style="display:block; color:#999; margin-top:4px;">' . Phrase_Android::getFullyQualifiedName($defaultPhrase, $subKey) . '</span>';
                                     $phraseKey = 'updatePhrases[edits][' . URL::encodeID($defaultPhrase->getID()) . '][' . $subKey . ']';
                                     $valuesRight[$subKey] = Authentication::getCachedEdit($repositoryID, $languageID, URL::encodeID($defaultPhrase->getID()), $subKey, $valuesRight[$subKey]);
                                     $valuePrevious = new UI_Form_Hidden(str_replace('[edits]', '[previous]', $phraseKey), $valuesRight[$subKey]);
                                     $valueEdit = new UI_Form_Textarea('', $phraseKey, $valuesRight[$subKey], '', true, htmlspecialchars($valuesRight[$subKey]), UI_Form_Textarea::getOptimalRowCount($valueLeft), $language->isRTL(), 'setUnsavedChanges(true);');
                                     if ($mayMovePhrases) {
                                         $editPhraseLink = new UI_Link('Edit', URL::toPhraseDetails($repositoryID, $languageID, $defaultPhrase->getID()), UI_Link::TYPE_UNIMPORTANT);
                                         $editPhraseLink->setSize(UI_Link::SIZE_SMALL);
                                         $editPhraseLink->setTabIndex('-1');
                                         $phrasesTable->addRow(array($editPhraseLink->getHTML(), $valueLeftHTML, $valuePrevious->getHTML() . $valueEdit->getHTML()));
                                     } else {
                                         $phrasesTable->addRow(array($valueLeftHTML, $valuePrevious->getHTML() . $valueEdit->getHTML()));
                                     }
                                 }
                             }
                         }
                     }
                     $formTargetURL = URL::toLanguage($repositoryID, $languageID);
                     $addPhraseURL = URL::toAddPhrase($repositoryID, $languageID);
                     $saveButton = new UI_Form_Button('Save changes', UI_Link::TYPE_SUCCESS, UI_Form_Button::ACTION_SUBMIT, '', '', 'setUnsavedChanges(false);');
                     if ($mayMovePhrases) {
                         $formButtonList = array($saveButton, new UI_Link('Add phrase', $addPhraseURL, UI_Link::TYPE_UNIMPORTANT));
                     } else {
                         $formButtonList = array($saveButton);
                     }
                     $formButtons = new UI_Form_ButtonGroup($formButtonList, true);
                     $phrasesTable->setShowSearchFilter(Authentication::isUserDeveloper());
                     $form = new UI_Form($formTargetURL, false);
                     $form->addContent($formButtons);
                     $form->addContent($phrasesTable);
                     $form->addContent(new UI_Form_Hidden('updatePhrases[secret]', $translationSecret));
                     $form->addContent(new UI_Form_Hidden('updatePhrases[translatorID]', Authentication::getUserID()));
                     $form->addContent($formButtons);
                     $contents[] = $heading;
                     $contents[] = $form;
                 } catch (Exception $e) {
                     self::addBreadcrumbItem(URL::toLanguage($repositoryID, $languageID), 'Language not found');
                     self::setTitle('Language not found');
                     $contents[] = new UI_Heading('Language not found', true);
                     $contents[] = new UI_Paragraph('We\'re sorry, but we could not find the language that you requested.');
                 }
             }
         }
     }
     $cell = new UI_Cell($contents);
     $row = new UI_Row(array($cell));
     $containers[] = new UI_Container(array($row));
     return new UI_Group($containers);
 }