00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 class import_doc extends WebObject
00032 {
00034 function on_refresh($event_args)
00035 {
00036 sleep(1);
00037 }
00038
00040 function on_delete($event_args)
00041 {
00042 $fname = $event_args['fname'];
00043 $xml_file = CONTENT."initial_xml/uploaded/$fname";
00044 $media_file = ereg_replace('\.xml$', '.media.tgz', $xml_file);
00045 shell("rm $xml_file");
00046 shell("rm $media_file");
00047 }
00048
00049 function on_import($event_args)
00050 {
00051
00052 set_time_limit(0);
00053
00054
00055 $book_id = $event_args['book_id'];
00056 $lng = $event_args['lng'];
00057 if ($lng=='') $lng = 'en';
00058 $fname = $event_args['fname'];
00059
00060
00061 $xml_file = "initial_xml/uploaded/$fname";
00062 $media_files = ereg_replace('\.xml$', '.media.tgz', $xml_file);
00063 if (! file_exists(CONTENT.$media_files)) $media_files = '';
00064
00065
00066 $fpi = '-
00067 $xmllint = "xmllint --noout --dtdvalidfpi '$fpi' --nonet --nowarning";
00068 $sed = 'sed -e \$d -e /warning:/d';
00069 $xml_errors = shell("$xmllint $xml_file 2>&1 | $sed");
00070 if (trim($xml_errors)!='')
00071 {
00072
00073 $msg = T_("The XML file 'v_xml_file' cannot be imported because\n\
00074 there are some validation problems (see the output below).\n\
00075 Fix the problems first and try again.");
00076 $msg = str_replace('v_xml_file', $xml_file, $msg);
00077 WebApp::message($msg);
00078 WebApp::debug_msg("<xmp>$xml_errors</xmp>");
00079 return;
00080 }
00081
00082
00083 $output = shell(CONTENT."import.sh $xml_file $book_id $lng $media_files");
00084 WebApp::debug_msg("<xmp>$output</xmp>");
00085 }
00086
00087 function onRender()
00088 {
00089 $this->add_uploaded_files_rs();
00090 }
00091
00093 function add_uploaded_files_rs()
00094 {
00095 $rs = new EditableRS('uploaded_files');
00096
00097 $path = CONTENT.'initial_xml/uploaded';
00098 $output = shell("ls $path/*.xml");
00099 $arr_files = explode("\n", $output);
00100 for ($i=0; $i < sizeof($arr_files); $i++)
00101 {
00102 $file = $arr_files[$i];
00103 if ($file=='' or ereg('No such file or directory', $file)) continue;
00104 $xml_file = str_replace("$path/", '', $file);
00105 $files = ereg_replace('\.xml$', '', $xml_file);
00106 $media = ereg_replace('\.xml$', '.media.tgz', $file);
00107 $files .= (file_exists($media) ? '.{xml,media.tgz}' : '.xml');
00108 $rs->addRec(compact('xml_file', 'files'));
00109 }
00110
00111 global $webPage;
00112 $webPage->addRecordset($rs);
00113 }
00114 }
00115 ?>