public static function getPage_CreateProject($contents, $containers) { $repositoryID = self::validateID(self::getDataGET('project'), true); $repositoryData = Database::getRepositoryData($repositoryID); $currentPageURL = empty($repositoryData) ? URL::toPage('create_project') : URL::toEditProject($repositoryID); $form = new UI_Form($currentPageURL, false); if (!empty($repositoryData)) { self::addBreadcrumbItem(URL::toProject($repositoryID), htmlspecialchars($repositoryData['name'])); $isAllowed = Repository::hasUserPermissions(Authentication::getUserID(), $repositoryID, $repositoryData, Repository::ROLE_ADMINISTRATOR); if (!$isAllowed) { $repositoryData = NULL; } } self::addBreadcrumbItem($currentPageURL, 'Create project'); if (!empty($repositoryData)) { $form->addContent(new UI_Form_StaticText('Public URL', Repository::getRepositoryShareURL($repositoryID), 'Share this URL with other people to let them contribute to your project.')); } $radioVisibility = new UI_Form_Radio('Visibility', 'create_project[visibility]'); $radioVisibility->addOption(Repository::getRepositoryVisibilityTag(Repository::VISIBILITY_PUBLIC), Repository::VISIBILITY_PUBLIC); $radioVisibility->addOption(Repository::getRepositoryVisibilityTag(Repository::VISIBILITY_PRIVATE), Repository::VISIBILITY_PRIVATE); if (!empty($repositoryData)) { $radioVisibility->setDefaultOption($repositoryData['visibility']); } $form->addContent($radioVisibility); $textProjectName = new UI_Form_Text('Project name', 'create_project[name]', 'Enter your project\'s name', false, 'The public name of your project, shown in your dashboard and also shown to contributors'); if (!empty($repositoryData)) { $textProjectName->setDefaultValue($repositoryData['name']); } $form->addContent($textProjectName); $defaultLanguageHelpText = 'The base language that you and your collaborators will translate from. This cannot be changed later and should be "English" in most cases.'; if (empty($repositoryData)) { // default language can only be set when creating the project $selectDefaultLanguage = new UI_Form_Select('Default language', 'create_project[defaultLanguage]', $defaultLanguageHelpText); $languages = Language::getList(); foreach ($languages as $language) { $languageLabel = Language_Android::getLanguageNameFull($language); $selectDefaultLanguage->addOption($languageLabel, $language); } if (!empty($repositoryData)) { $selectDefaultLanguage->addDefaultOption($repositoryData['defaultLanguage']); } $form->addContent($selectDefaultLanguage); } else { // when editing the project just show the current setting $form->addContent(new UI_Form_StaticText('Default language', Language::getLanguageNameFull($repositoryData['defaultLanguage']), $defaultLanguageHelpText)); $form->addContent(new UI_Form_Hidden('create_project[defaultLanguage]', $repositoryData['defaultLanguage'])); } $buttonSubmit = new UI_Form_Button(empty($repositoryData) ? 'Create project' : 'Edit project', UI_Link::TYPE_SUCCESS); $buttonCancel = new UI_Link('Cancel', empty($repositoryData) ? URL::toDashboard() : URL::toProject($repositoryID), UI_Link::TYPE_UNIMPORTANT); $form->addContent(new UI_Form_ButtonGroup(array($buttonSubmit, $buttonCancel))); self::setTitle(empty($repositoryData) ? 'Create project' : 'Edit project'); $contents[] = new UI_Heading(empty($repositoryData) ? 'Create project' : 'Edit project', true); $contents[] = new UI_Heading('Project settings', false, 3); $contents[] = $form; if (!empty($repositoryData)) { $contents[] = new UI_Heading('Manage phrase groups', false, 3, '', 'manage_groups'); $formList = new UI_Form(htmlspecialchars($currentPageURL), false); $table = new UI_Table(array('Phrase group', 'Phrases', 'Actions')); $table->setColumnPriorities(5, 5, 2); $phraseGroups = Database::getPhraseGroups($repositoryID, $repositoryData['defaultLanguage']); $phrasesInDefaultGroup = Database::getPhraseCountInGroup($repositoryID, 0, $repositoryData['defaultLanguage']); $table->addRow(array('(Default group)', $phrasesInDefaultGroup . ' phrases', '')); foreach ($phraseGroups as $phraseGroup) { $linkDelete = new UI_Form_Button('Delete', UI_Link::TYPE_DANGER, UI_Form_Button::ACTION_SUBMIT, 'deleteGroup[id]', $phraseGroup['id'], 'return confirm(\'Are you sure you want to delete this group? All phrases will be moved to the default group.\');'); $table->addRow(array(htmlspecialchars($phraseGroup['name']), $phraseGroup['phraseCount'] . ' phrases', $linkDelete->getHTML())); } $formList->addContent($table); $contents[] = $formList; $contents[] = new UI_Heading('Add a new phrase group', false, 3); $formAdd = new UI_Form(htmlspecialchars($currentPageURL), false); $formAdd->addContent(new UI_Form_Text('Add new group', 'addGroup[name]', 'Enter group name ...', false, 'If you want to create a new phrase group, please enter its name here.')); $formAdd->addContent(new UI_Form_ButtonGroup(array(new UI_Form_Button('Create group')))); $contents[] = $formAdd; $contents[] = new UI_Heading('Clean languages', false, 3); $contents[] = new UI_Paragraph('Use the following option to remove all translations that don\'t differ from the default language.'); $contents[] = new UI_Paragraph('These translations have no effect and thus only distort the progress indication.'); $formAdd = new UI_Form(htmlspecialchars($currentPageURL), false); $formAdd->addContent(new UI_Form_Button('Run now', UI_Link::TYPE_SUCCESS, UI_Form_Button::ACTION_SUBMIT, 'cleanLanguages[run]', 1)); $contents[] = $formAdd; } $cell = new UI_Cell($contents); $row = new UI_Row(array($cell)); $containers[] = new UI_Container(array($row)); return new UI_Group($containers); }