Пример #1
0
 $form = new FormValidator('glossary', 'post', api_get_self() . '?action=import');
 $form->addElement('header', '', get_lang('ImportGlossary'));
 $form->addElement('file', 'file', get_lang('ImportCSVFileLocation'));
 $form->addElement('checkbox', 'replace', null, get_lang('DeleteAllGlossaryTerms'));
 $form->addElement('style_submit_button', 'SubmitImport', get_lang('Import'), 'class="save"');
 $form->display();
 echo get_lang('CSVMustLookLike') . ' (' . get_lang('MandatoryFields') . ')';
 echo '<pre>
         <strong>term</strong>;<strong>definition</strong>;
         "Hello";"Hola";
         "Good";"Bueno";</pre>';
 if ($form->validate()) {
     //this is a bad idea //jm
     if (isset($_POST['replace']) && $_POST['replace']) {
         foreach (GlossaryManager::get_glossary_terms() as $term) {
             if (!GlossaryManager::delete_glossary($term['id'], false)) {
                 Display::display_error_message(get_lang("CannotDeleteGlossary") . ':' . $term['id']);
             }
         }
     }
     //$data = Import::csv_to_array($_FILES['file']['tmp_name']);
     $data = Import::csv_reader($_FILES['file']['tmp_name']);
     $good = 0;
     $bad = 0;
     foreach ($data as $item) {
         if (GlossaryManager::save_glossary(array('glossary_title' => $item['term'], 'glossary_comment' => $item['definition']), false)) {
             $good++;
         } else {
             $bad++;
         }
     }