Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
importDocuments.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * importation of documents
9  *
10  * @author Anakeen 2002
11  * @version $Id: freedom_import.php,v 1.9 2008/11/13 16:49:16 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage WSH
15  */
16 /**
17  */
18 
19 global $appl, $action;
20 
21 include_once ("FDL/import_file.php");
22 include_once ("FREEDOM/freedom_import.php");
23 
24 $usage = new ApiUsage();
25 $usage->setText("Import documents from description file");
26 $filename = $usage->addNeeded("file", "the description file path");
27 $analyze = $usage->addOption("analyze", "analyze only", array(
28  "yes",
29  "no"
30 ) , "no");
31 $archive = $usage->addOption("archive", "description file is an standard archive (not xml)", array(
32  "yes",
33  "no"
34 ) , "no");
35 $logfile = $usage->addOption("log", "log file output");
36 $htmlmode = $usage->addOption("htmlmode", "analyze report mode in html", array(
37  "yes",
38  "no"
39 ) , "yes");
40 $reinit = $usage->addOption("reinitattr", "reset attribute before import family update", array(
41  "yes",
42  "no"
43 ));
44 $to = $usage->addOption("to", "email address to send report");
45 $usage->verify();
46 
47 if (!file_exists($filename)) {
48  $action->ExitError(sprintf(_("import file %s not found") , $filename));
49 }
50 if ($logfile) {
51  if (file_exists($logfile) && (!is_writable($logfile))) {
52  $action->ExitError(sprintf(_("log file %s not writable") , $logfile));
53  }
54  if (!file_exists($logfile)) {
55  $f = @fopen($logfile, 'a');
56  if ($f === false) {
57  $action->ExitError(sprintf(_("log file %s not writable") , $logfile));
58  }
59  fclose($f);
60  }
61 }
62 setHttpVar('analyze', ($analyze == "yes") ? 'Y' : 'N');
63 setHttpVar('htmlmode', ($htmlmode == "yes") ? 'Y' : 'N');
64 $archive = ($archive == "yes");
65 
67 
68 $filetmp = false;
69 if ((!$logfile) && $to) {
70  $logfile = tempnam(getTmpDir() , 'logimport');
71  $filetmp = true;
72 }
73 if ($logfile) {
74  if ($htmlmode == "yes") {
76  } else {
78  }
79 }
80 // mode HTML
81 if ($to) {
82  include_once ("FDL/sendmail.php");
83 
84  $themail = new Fdl_Mail_mime();
85 
86  $themail->setHTMLBody(file_get_contents($logfile) , false);
87 
88  $from = getMailAddr($action->user->id);
89  if ($from == "") $from = getParam('SMTP_FROM');
90  if ($from == "") $from = $action->user->login . '@' . php_uname('n');
91 
92  $subject = sprintf(_("result of import %s") , basename(GetHttpVars("file")));
94  if ($err) error_log("import sending mail: Error:$err");
95  if ($filetmp) unlink($logfile);
96 } else {
97  if (GetHttpVars("htmlmode") == "Y") print $out;
98 }
99 ?>
← centre documentaire © anakeen - published under CC License - Dynacase