/[ludap]/ludap/www/xml.php
ViewVC logotype

Diff of /ludap/www/xml.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by mose, Thu Oct 23 09:32:35 2003 UTC revision 1.9 by mose, Sun Oct 26 12:58:01 2003 UTC
# Line 30  copyright (C) 2001, 2002 mose, makina co Line 30  copyright (C) 2001, 2002 mose, makina co
30   */   */
31    
32  require_once('../setup.php');  require_once('../setup.php');
33    $xmlpath = LUDAP_DIR."/xmldata/";
34    
35    if      ($xmlaction == 'uploader') {
36            if (is_file($xmlimport["tmp_name"])) {
37                    $filename = date("Y-m-d-H-i",time());
38                    if (strtolower(substr($xmlimport["name"],-4,4)) == ".xml") {
39                            $xmltype = "ludapxml";
40                    } else {
41                            $xmltype = "ludapcsv";
42                    }
43                    // rename($xmlimport["tmp_name"],$xmlpath.$filename);
44            }
45    } elseif ($xmlaction == 'effacer') {
46            if (is_file($xmlpath.$xdfile)) {
47                    unlink($xmlpath.$xdfile);
48            }
49    } elseif ($xmlaction == 'sauvegarder') {
50            $filename = date("Y-m-d-H-i",time());
51            if ($xmltype == 'ludapxml') {
52                    $filename.= ".xml";
53            } else {
54                    $filename.= ".csv";
55            }
56            $fp = fopen($xmlpath.$filename,"w");
57            fputs($fp,$_POST["data"]);
58            fclose($fp);
59    } elseif ($xmlaction == 'télécharger') {
60            $filename = date("Y-m-d-H-i",time());
61            header("Content-type: text/plain");
62            if ($xmltype == 'ludapxml') {
63                    header("Content-Disposition: attachment; filename=$filename.xml");
64            } else {
65                    header("Content-Disposition: attachment; filename=$filename.csv");
66            }
67            echo $_POST["data"];
68            die();
69    }
70    
71  $S->display('header.tpl');  $S->display('header.tpl');
72  if (!$useframe) {  if (!$useframe) {
73          $S->display('topbar.tpl');          $S->display('topbar.tpl');
74  }  }
75  if ($handle = opendir(LUDAP_DIR.'xmldata')) {  if ($handle = opendir($xmlpath)) {
76          while (false !== ($file = readdir($handle))) {          while (false !== ($file = readdir($handle))) {
77                  if ($file != "." && $file != "..") {                  if ($file != "." && $file != "..") {
78                          $xmldatafile[] = $file;                          $xmldatafile[] = $file;
# Line 45  if ($handle = opendir(LUDAP_DIR.'xmldata Line 82  if ($handle = opendir(LUDAP_DIR.'xmldata
82          @sort($xmldatafile);          @sort($xmldatafile);
83  }  }
84  $S->assign("xdf",$xmldatafile);  $S->assign("xdf",$xmldatafile);
85    if (isset($_POST['xdfile'])) {
86            $S->assign("xdfile",$_POST['xdfile']);
87    } else {
88            $S->assign("xdfile",'');
89    }
90  $S->display("xml_topnav.tpl");  $S->display("xml_topnav.tpl");
91  if ($xmlaction == 'importer xml') {  if (($xmlaction == 'importer') and ($xmltype == 'ludapxml')) {
92                    $xfile = str_replace('&','&',$_POST["data"]);
93          if ($xmlimport) {          $obj = domxml_xmltree($xfile);
94                  $xfile = implode('',file($xmlimport["tmp_name"]));          $xmltree = $L->xml2array($obj);
95                  $xfile = str_replace('&','&',$xfile);          array_shift($xmltree);
96                  $obj = domxml_xmltree($xfile);          foreach ($xmltree as $insert) {
97                  $xmltree = $L->xml2array($obj);                  #$mes = $L->write_id($insert);
98                  array_shift($xmltree);                  if (is_array($mes)) {
99                  foreach ($xmltree as $insert) {                          echo implode("<br>",$mes)."<hr>";
100                          #$mes = $L->write_id($insert);                  } else {
101                          if (is_array($mes)) {                          echo $mes;
                                 echo implode("<br>",$mes)."<hr>";  
                         } else {  
                                 echo $mes;  
                         }  
102                  }                  }
103          }          }
104  //echo'<pre>';print_r(get_defined_vars());echo'</pre>';  //echo'<pre>';print_r(get_defined_vars());echo'</pre>';
105  } elseif        ($xmlaction == 'importer csv') {  } elseif        ($xmlaction == 'importer') {
106          if ($xmlimport) {          $content = split("(\r|\n)",$_POST['data']);
107                  if (is_file($xmlimport["tmp_name"])) {          $headed = array_shift($content);
108                          $fp = fopen($xmlimport["tmp_name"],'r');          $head = split('","',$headed);
109                  } elseif (is_file('xmldata/'.$xdfile)) {          $nbhead = count($head) - 1;
110                          $fp = fopen('xmldata/'.$xdfile,'r');          foreach ($content as $lined) {
111                  }                  $insert = array();
112                  $headed = substr(fgets($fp,4096),1);                  if (trim($lined)) {
113                  $head = split('","',$headed);                          $line = split('","',$lined);
114                  $nbhead = count($head) - 1;                          for ($i=0;$i<$nbhead;$i++) {
115                  while (!feof($fp)) {                                  $it = str_replace('"',"",$head[$i]);
116                          $insert = array();                                  if ($line[$i]) {
117                          $lined = substr(fgets($fp,4096),1);                                          $insert[$it] = str_replace('"',"",$line[$i]);
                         if (trim($lined)) {  
                                 $line = split('","',$lined);  
                                 for ($i=0;$i<$nbhead;$i++) {  
                                         $it = $head[$i];  
                                         if ($line[$i]) {  
                                                 $insert[$it] = $line[$i];  
                                         }  
118                                  }                                  }
119                                  if ($insert['cn'] == "Abonné lettre") {                          }
120                                          // $insert['cn'] = $insert['mail'];                          if ($insert['cn'] == "Abonné lettre") {
121                                  } elseif ($insert['cn'] == "Nouveau") {                                  // $insert['cn'] = $insert['mail'];
122                                          $insert = false;                          } elseif ($insert['cn'] == "Nouveau") {
123                                  }                                  $insert = false;
124                                  if ($insert) {                          }
125                                          echo "<pre>";print_r($insert);echo "</pre>";                              if ($insert) {
126                                          #$mes = $L->write_id($insert);                                  echo "<pre>";print_r($insert);echo "</pre>";    
127                                          if (is_array($mes)) {                                  $mes = $L->write_id($insert);
128                                                  echo implode("<br>",$mes)."<hr>";                                  if (is_array($mes)) {
129                                          } else {                                          echo implode("<br>",$mes)."<hr>";
130                                                  echo $mes."<hr>";                                  } elseif (isset($mes)) {
131                                          }                                          echo $mes."<hr>";
132                                  }                                  }
133                          }                          }
134                  }                  }
135          }          }
136    } elseif        ($xmlaction == 'visualiser') {
137            if (isset($_POST["xdfile"]) and is_file($xmlpath.$_POST["xdfile"])) {
138                    $data = implode("",file($xmlpath.$_POST["xdfile"]));
139                    $S->assign("data",$data);
140                    $S->assign("xmltype",$xmltype);
141                    $S->display('xml_input.tpl');
142            }
143  } elseif ($xmltype) {  } elseif ($xmltype) {
144          $info = $L->get_users_list(array_keys($L->schema_user),$searchx,'',20,0,20);          $info = $L->get_users_list(array_keys($L->schema_user),$searchx,'',20,0,20);
145          $S->assign('info', $info);          $S->assign('info', $info);
# Line 111  if ($xmlaction == 'importer xml') { Line 149  if ($xmlaction == 'importer xml') {
149          } else {          } else {
150                  $tpl = 'csv_ludap.tpl';                  $tpl = 'csv_ludap.tpl';
151          }          }
152          $buffer = $S->fetch($tpl);          $data = $S->fetch($tpl);
153                    $S->assign("data",$data);
154          echo "<div class=area><textarea cols=92 rows=40 nowrap class=acto>".htmlentities($buffer)."</textarea></div></form>";          $S->assign("xmltype",$xmltype);
155                    $S->display('xml_input.tpl');
156  }  }
157  if (!$useframe) {  if (!$useframe) {
158          $S->display('botbar.tpl');          $S->display('botbar.tpl');

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26