public function Load() { parent::$PAGE_TITLE = __(MANAGE_TRANSLATIONS); $content = new Object(); // Search in all translation files the labels // Features : // - get the list of the labels for a page / language // - display for each label if there is a translation in all the language of the website // - enter a new label // - update a label // - delete a label $translate_table = new Table(); $translate_table->setDefaultValign(RowTable::VALIGN_TOP); if (!isset($_GET['language'])) { $_GET['language'] = $this->getLanguage(); } $this->form = new Form($this); $this->form->setAction($this->getCurrentURLWithoutParameters() . "?language=" . $_GET['language']); $this->hdn_old_file = new Hidden($this->form, "hdn_old_file"); $content->add($this->hdn_old_file); $tree = new TreeView("wsp_lang_files"); $array_path = explode("/", $this->getRootWspDirectory()); $root = new TreeViewFolder($array_path[sizeof($array_path) - 1]); $tree_page_items = new TreeViewItems(); $dir = $this->getRootWspDirectory() . "/lang/" . $_GET['language'] . "/"; $array_files = $this->loadFiles($dir, '', $_GET['language']); foreach ($array_files as $key => $value) { $tree_page_type = new TreeViewFolder($key); $tree_page_type->expand(); $tree_page_items->add($tree_page_type); $tree_items = new TreeViewItems(); $array_folder = array(); for ($i = 0; $i < sizeof($value); $i++) { $file = $value[$i]; $expand = false; if ($file == $_GET['file']) { $expand = true; } $array_path = explode('/', $file); $file_name = $array_path[sizeof($array_path) - 1]; $array_path[sizeof($array_path) - 1] = null; $folder = implode('/', $array_path); if ($folder == "") { $parent_tree_items = $tree_items; } else { if (isset($array_folder[$folder])) { $parent_tree_items = $array_folder[$folder]; $tree_folder = $parent_tree_items->getTreeViewItemParent(); if (!$tree_folder->isExpand()) { if ($expand) { $tree_folder->expand(); } else { $tree_folder->collapse(); } } } else { $tree_folder = new TreeViewFolder($folder); if ($expand) { $tree_folder->expand(); } else { $tree_folder->collapse(); } $tree_items->add($tree_folder); $parent_tree_items = new TreeViewItems(); $tree_folder->setTreeViewItems($parent_tree_items); $array_folder[$folder] = $parent_tree_items; } } $file_link = new Button($this->form); $file_name_label = new Label($file_name); $file_name_label->setId("file_label_" . str_replace("/", "_slashsep_", str_replace(".", "_", str_replace("-", "_", $file)))); $this->array_files_label[$file] = $file_name_label; $file_link->setValue($file_name_label)->setIsLink(); $file_link->onClick("loadTranslation", $file, $this->hdn_old_file, $_GET['language'], 1)->setAjaxEvent(); $tree_file = new TreeViewFile($file_link); $parent_tree_items->add($tree_file); } $tree_page_type->setTreeViewItems($tree_items); } $root->setTreeViewItems($tree_page_items); $root_items = new TreeViewItems(); $root_items->add($root); $tree->setTreeViewItems($root_items); $language_selector = new Object(); $array_lang_dir = scandir($this->getRootWspDirectory() . "/lang", 0); for ($i = 0; $i < sizeof($array_lang_dir); $i++) { if (is_dir($this->getRootWspDirectory() . "/lang/" . $array_lang_dir[$i]) && $array_lang_dir[$i] != "" && $array_lang_dir[$i] != "." && $array_lang_dir[$i] != ".." && $array_lang_dir[$i] != ".svn" && strlen($array_lang_dir[$i]) == 2) { $lang_link = $this->getCurrentURLWithoutParameters() . "?language=" . $array_lang_dir[$i]; $language_link = new Link($lang_link, Link::TARGET_NONE, new Picture("wsp/img/lang/" . $array_lang_dir[$i] . ".png", 24, 24, 0, Picture::ALIGN_ABSMIDDLE)); if ($array_lang_dir[$i] == $_GET['language']) { $language_link->setStyle("border:1px solid red;padding-bottom: 4px;"); } $language_link->setId("lang_link_" . $array_lang_dir[$i]); $this->array_lang_link[] = $language_link; $language_selector->add($language_link); } } $lang_tree_obj = new Object($language_selector, "<br/>"); $tree_obj = new Object($tree); $tree_obj->setAlign(Object::ALIGN_LEFT)->setWidth(200)->setHeight(608)->setMaxHeight(608); $lang_tree_obj->add($tree_obj); // create translate area with all translation labels and sortable $this->translate_area = new Object(); $this->translate_area->setWidth(600)->setHeight(620)->setStyle("border:1px solid gray;overflow:auto;padding:5px;"); $this->translate_area->emptyObject()->setId("translate_area"); $this->sort_label_event = new SortableEvent($this->form); $this->sort_label_event->onSort("onSort", ""); $this->sort_label_event->setAjaxEvent()->disableAjaxWaitMessage(); $this->translate_area->setSortable(true, $this->sort_label_event); $translate_table->addRowColumns($lang_tree_obj, $this->translate_area); $translate_table->addRow(); $this->btn_save = new Button($this->form); $this->btn_save->setValue(__(BTN_SAVE))->onClick("save", "")->setAjaxEvent(); $this->btn_save->forceSpanTag(); if (Page::getInstance("wsp-admin/manage/manage-pages")->userHaveRights()) { $this->btn_page = new Button($this); $this->btn_page->setValue(__(BTN_PHP_PAGE))->forceSpanTag()->disable(); } $this->btn_add_label = new Button($this); $this->btn_add_label->setValue(__(ADD_LABEL))->onClick("addLabel", "")->setAjaxEvent(); $this->btn_add_label->forceSpanTag(); $translate_table->addRow(new Object($this->btn_page, " ", $this->btn_add_label, " ", $this->btn_save))->setColspan(2); $translate_table->addRow(); $this->form->setContent($translate_table); // Create a link to the page // TODO $this->render = new AdminTemplateForm($this, $content->add($this->form)); if ($this->btn_save->isClicked() || $this->sort_label_event->isSorted() || $this->btn_add_label->isClicked()) { // do nothing, translation load is done by the callback function } else { if (isset($_GET['file'])) { $this->loadTranslation(null, $_GET['file'], "", $_GET['language']); if (isset($_GET['saved'])) { alert(__(FILE_SAVED, $_GET['file'])); } } else { if (!$this->isAjaxPage()) { $this->loadTranslation(null, "all.inc.php", "", $_GET['language']); } } } // Create addLabel form $this->form_add_label = new Form($this); $this->form_add_label->setAction($this->getCurrentURLWithoutParameters() . "?language=" . $_GET['language']); $table_add_label = new Table(); $this->add_label_label_name = new TextBox($this->form_add_label, "add_label_label_name"); $this->add_label_label_name->setWidth(200); $table_add_label->addRowColumns(__(LABEL_NAME) . ": ", $this->add_label_label_name); $this->add_label_label_value = new TextArea($this->form_add_label, "add_label_label_value"); $this->add_label_label_value->setAutoHeight()->setWidth(200); $table_add_label->addRowColumns(__(LABEL_VALUE) . ": ", $this->add_label_label_value); $this->btn_create_label = new Button($this->form_add_label, "btn_create_label"); $this->btn_create_label->setValue(__(ADD_LABEL))->setAjaxEvent(); $table_add_label->addRowColumns($this->btn_create_label)->setColspan(2)->setAlign(RowTable::ALIGN_CENTER); $this->form_add_label->setContent($table_add_label); }
public function Load() { parent::$PAGE_TITLE = __(MANAGE_PAGES); $content = new Object(); // Search all php files in the folder pages with the synstax "class * extends Page" $code_editor_table = new Table(); $code_editor_table->setDefaultValign(RowTable::VALIGN_TOP); $form = new Form($this); $this->hdn_old_file = new Hidden($this); $content->add($this->hdn_old_file); $tree = new TreeView("wsp_files"); $array_path = explode("/", $this->getRootWspDirectory()); $root = new TreeViewFolder($array_path[sizeof($array_path) - 1]); $tree_page_items = new TreeViewItems(); $dir = $this->getRootWspDirectory() . "/pages/"; $array_files = $this->loadFiles($dir); foreach ($array_files as $key => $value) { $tree_page_type = new TreeViewFolder($key); if ($key == "Page classes") { $tree_page_type->expand(); } else { $tree_page_type->collapse(); } $tree_page_items->add($tree_page_type); $tree_items = new TreeViewItems(); $array_folder = array(); for ($i = 0; $i < sizeof($value); $i++) { $file = $value[$i]; $array_path = explode('/', $file); $file_name = $array_path[sizeof($array_path) - 1]; $array_path[sizeof($array_path) - 1] = null; $folder = implode('/', $array_path); if ($folder == "") { $parent_tree_items = $tree_items; } else { if (isset($array_folder[$folder])) { $parent_tree_items = $array_folder[$folder]; } else { $tree_folder = new TreeViewFolder($folder); $tree_folder->collapse(); $tree_items->add($tree_folder); $parent_tree_items = new TreeViewItems(); $tree_folder->setTreeViewItems($parent_tree_items); $array_folder[$folder] = $parent_tree_items; } } $file_link = new Button($this); $file_name_label = new Label($file_name); $file_name_label->setId("file_label_" . str_replace("/", "_slashsep_", str_replace(".", "_", str_replace("-", "_", $file)))); $this->array_files_label[$file] = $file_name_label; $file_link->setValue($file_name_label)->setIsLink(); $file_link->onClick("loadFile", $file, $this->hdn_old_file)->setAjaxEvent(); $tree_file = new TreeViewFile($file_link); $parent_tree_items->add($tree_file); } $tree_page_type->setTreeViewItems($tree_items); } $root->setTreeViewItems($tree_page_items); $root_items = new TreeViewItems(); $root_items->add($root); $tree->setTreeViewItems($root_items); $tree_obj = new Object($tree); $tree_obj->setAlign(Object::ALIGN_LEFT)->setWidth(220)->setHeight(630)->setMaxHeight(630); $this->code_editor = new TextArea($form); $this->code_editor->setWidth(600)->setHeight(620)->allowTabulation()->activateSourceCodeEdit("php")->noWrap(); $code_editor_table->addRowColumns($tree_obj, $this->code_editor); $this->btn_save = new Button($form); $this->btn_save->setValue(__(BTN_SAVE))->setAjaxEvent()->hide(); $this->btn_save->forceSpanTag(); if (Page::getInstance("wsp-admin/manage/manage-translations")->userHaveRights()) { $this->tranlate_links_obj = new Object(__(MANAGE_TRANSLATIONS) . ": "); $this->tranlate_links_obj->setId("tranlate_links_obj"); } $code_editor_table->addRow(new Object($this->tranlate_links_obj, " ", $this->btn_save))->setColspan(2); $code_editor_table->addRow(); $form->setContent($code_editor_table); // Create a link to the labels of this page // TODO $this->render = new AdminTemplateForm($this, $content->add($form)); if (isset($_GET['file'])) { $this->loadFile(null, $_GET['file'], ""); } else { if (!$this->isAjaxPage()) { $this->loadFile(null, "home.php", ""); } } }