00001 <?php 00002 00003 function getIncludePath( $file ) { 00004 return $_SERVER['DOCUMENT_ROOT'] . "/tm_version2/" . $file; 00005 } 00006 00007 define( "ROOT_DIR", "/"); 00008 00009 class JuelichFtp { 00010 00011 var $ftp; 00012 var $rDirs = array(); 00013 00014 function JuelichFtp() { 00015 $host = "mikroskop.homepage.t-online.de"; 00016 $user = "kontakt@mikroskop.homepage.t-online.de"; 00017 $pass = "sa8turm"; 00018 00019 $ftp = @ftp_connect( $host ); 00020 if( !$ftp ) { 00021 echo "Konnte keine Verbindung zu $host herstellen.<br>\n"; 00022 flush(); 00023 ftp_quit($ftp); 00024 exit(); 00025 } 00026 $succ = @ftp_login( $ftp, $user, $pass ); 00027 if( !$succ ) { 00028 echo "Anmeldung an $host fehlgeschlagen.<br>\n"; 00029 flush(); 00030 ftp_quit($ftp); 00031 exit(); 00032 } 00033 00034 $tmp = @ftp_rawlist( $ftp, ROOT_DIR ); 00035 foreach( $tmp as $d ) { 00036 if( substr( $d, 0, 1 ) == "d" ) { 00037 $pattern = "/.*?\d\d:\d\d (.*)/"; 00038 preg_match($pattern, $d, $match); 00039 array_push( $this->rDirs, ROOT_DIR . $match[1] ); 00040 } 00041 } 00042 00043 $this->ftp = $ftp; 00044 } 00045 00046 function closeConnection() { 00047 ftp_quit( $this->ftp ); 00048 } 00049 00050 function needDir( $dir ) { 00051 if( in_array( ROOT_DIR . $dir, $this->rDirs ) ) { 00052 return; 00053 } 00054 else { 00055 ftp_mkdir( $this->ftp, ROOT_DIR . $dir ); 00056 array_push( $this->rDirs, ROOT_DIR . $dir ); 00057 } 00058 return; 00059 } 00060 00061 function putFile( $rPath, $lPath) { 00062 ftp_put( $this->ftp, $rPath, $lPath, FTP_BINARY ); 00063 return; 00064 } 00065 00066 function checkDirs( &$needed ) { 00067 $del = array_diff( $this->rDirs, $needed ); 00068 foreach( $del as $d ) { 00069 if( $d == "/sub" ) { 00070 continue; 00071 } 00072 echo "Lösche Verzeichnis: $d<br>\n"; 00073 flush(); 00074 $this->ftp_rmAll( $d . "/" ); 00075 } 00076 return; 00077 } 00078 00079 function ftp_rmAll($dst_dir) { 00080 $conn_id = $this->ftp; 00081 $ar_files = ftp_rawlist($conn_id, $dst_dir); 00082 if (is_array($ar_files)) { 00083 foreach ($ar_files as $st_file) { 00084 if (ereg("([-d][rwxst-]+).* ([0-9]) ([a-zA-Z0-9]+).* ([a-zA-Z0-9]+).* ([0-9]*) ([a-zA-Z]+[0-9: ]*[0-9]) ([0-9]{2}:[0-9]{2}) (.+)",$st_file,$regs)) { 00085 if (($regs[8] == ".") || ($regs[8] == "..")) { 00086 continue; 00087 } 00088 if (substr($regs[1],0,1)=="d") { 00089 $this->ftp_rmAll($dst_dir."/".$regs[8]); 00090 } else { 00091 ftp_delete($conn_id, $dst_dir."/".$regs[8]); 00092 } 00093 } 00094 } 00095 } 00096 ftp_rmdir($conn_id, $dst_dir); 00097 } 00098 00099 } 00100 00101 00102 require_once( getIncludePath("constants.php") ); 00103 require_once( getIncludePath("db/db_basic.php") ); 00104 require_once( getIncludePath("db/DbMysql.php") ); 00105 require_once( getIncludePath("juelich/JuelichDbFunctions.php") ); 00106 require_once( getIncludePath("juelich/JuelichTemplate.php") ); 00107 00108 set_time_limit(0); 00109 00110 $connId = db_connect(); 00111 $db = new DbMysql; 00112 00113 $bereiche = array( "Mikroskop / Lupe ", 00114 "Fernoptik", 00115 "Teleskop", 00116 "Optik-Marken", 00117 "Service / Reparatur", 00118 "EDV" 00119 ); 00120 00121 # Template öffnen 00122 $template = new JuelichTemplate; 00123 $tpl = $template->getTemplate( "business-master", DEUTSCH_ID ); 00124 00125 $s = count( $bereiche ); 00126 00127 # Menü 00128 $menu = ""; 00129 $sqlL = "SELECT b_name FROM business WHERE bereich_id=%s AND b_sort='0001'"; 00130 for( $i = 0; $i < $s; ++$i ) { 00131 $row = ""; 00132 $sql = sprintf( $sqlL, $i ); 00133 $db->getRow( $row, $sql ); 00134 $l = makeFileName($row[0]); 00135 if( $l == "" ) { 00136 continue; 00137 } 00138 $menu .= "<tr><td></td><td>" 00139 . "<a href=\"/" 00140 . $l 00141 . "/" . $l . "_index.html\" class=\"menu\">$bereiche[$i]</a>" 00142 . "</td><td></td></tr>\n"; 00143 } 00144 00145 # Themen 00146 $sqlB = "SELECT b_name FROM business " 00147 . "WHERE bereich_id=%s AND b_online='1' ORDER BY b_sort"; 00148 $themes = array(); 00149 for( $i = 0; $i < $s; ++$i ) { 00150 $tmp = array(); 00151 $result = ""; 00152 $sql = sprintf( $sqlB, $i ); 00153 $db->queryDb( $result, $sql ); 00154 while( $row = mysql_fetch_row( $result ) ) { 00155 array_push( $tmp, $row[0] ); 00156 } 00157 $themes[$i] = makeThemes( $tmp ); 00158 } 00159 00160 echo "<html> 00161 <head> 00162 <title>Protokoll</title> 00163 </head> 00164 <body> 00165 <h3>Protokoll</h3> 00166 <p> 00167 Beginne die Übertragung ...<br> 00168 "; 00169 flush(); 00170 00171 $ftp = new JuelichFtp; 00172 00173 $neededDirs = array( ROOT_DIR . "pictures" ); 00174 $succ = 0; 00175 $sql = "SELECT * FROM business " 00176 . "WHERE b_online='1' ORDER BY bereich_id, b_sort "; 00177 $result = ""; 00178 $db->queryDb( $result, $sql ); 00179 while( $row = mysql_fetch_row( $result ) ) { 00180 echo "Erzeuge und übertrage: $row[5] ...<br>\n"; 00181 flush(); 00182 $page = $tpl; 00183 00184 $linkPattern = "/<a href=\"(http:\/\/www.juelich-bonn.com\/.*?)\"/"; 00185 preg_match( $linkPattern, $row[8], $links ); 00186 $linkJuelichStart = ""; 00187 $linkJuelichEnd = ""; 00188 if( count($links) > 1 && $links[1] != "" ) { 00189 $linkJuelichStart = "<a href=\"" . $links[1] . "\">"; 00190 $linkJuelichEnd = "</a>"; 00191 } 00192 00193 $page = str_replace( "TM__MENU", $menu, $page ); 00194 00195 $b_id = $row[4]; 00196 $page = str_replace( "TM__THEMES", $themes[$b_id], $page ); 00197 00198 $heading = $linkJuelichStart . $row[5] . $linkJuelichEnd; 00199 $page = str_replace( "TM__HEADING", $heading, $page ); 00200 $page = str_replace( "TM__TITLE", $row[5], $page ); 00201 00202 $page = str_replace( "TM__DESC", $row[7], $page ); 00203 00204 $page = str_replace( "TM__TEXT", $row[8], $page ); 00205 00206 $imgName = basename( $row[6] ); 00207 $image = $linkJuelichStart 00208 . "<img border=\"0\" src=\"/pictures/" 00209 . $imgName 00210 . "\">" 00211 . $linkJuelichEnd; 00212 $page = str_replace( "TM__IMG", $image, $page ); 00213 00214 $succ = @copy( $row[6], 'tmp/image' ); 00215 success( $succ, "Bild holen: $row[6].<br>\n" ); 00216 00217 #$ftp->needDir( "pictures" ); 00218 $rPath = "pictures/" . $imgName; 00219 #$ftp->putFile( $rPath, 'tmp/image' ); 00220 00221 $file = fopen( "tmp/page", 'w+'); 00222 fwrite( $file, $page ); 00223 fclose( $file ); 00224 $fsName = makeFileName( $row[5] ); 00225 $dirName = $fsName; 00226 array_push( $neededDirs, ROOT_DIR . $dirName ); 00227 #$ftp->needDir( $dirName ); 00228 $rPath = $dirName . "/" . $fsName . "_index.html"; 00229 #$ftp->putFile( $rPath, "tmp/page" ); 00230 } 00231 00232 echo "Überprüfe ob Seiten weggefallen sind ...<br>\n"; 00233 flush(); 00234 $ftp->checkDirs( $neededDirs ); 00235 echo "Fertig.<br>\n"; 00236 echo "</p></body></html>\n"; 00237 flush(); 00238 $ftp->closeConnection(); 00239 exit(); 00240 00241 00242 function makeFileName( $raw ) { 00243 $raw = str_replace( " ", "_", $raw ); 00244 $raw = str_replace( "ä", "ae", $raw ); 00245 $raw = str_replace( "ö", "oe", $raw ); 00246 $raw = str_replace( "ü", "ue", $raw ); 00247 $raw = str_replace( "ß", "ss", $raw ); 00248 $raw = str_replace( "Ä", "Ae", $raw ); 00249 $raw = str_replace( "Ö", "Oe", $raw ); 00250 $raw = str_replace( "Ü", "Ue", $raw ); 00251 $raw = strtolower( $raw ); 00252 return $raw; 00253 } 00254 00255 function makeThemes( &$wArray ) { 00256 $themes = ""; 00257 $s = count( $wArray ); 00258 $ts = array(); 00259 for( $i = 0; $i < $s; ++$i ) { 00260 $l = makeFileName( $wArray[$i] ); 00261 $link = "<a href=\"/" 00262 . $l 00263 . "/" 00264 . $l 00265 . "_index.html" 00266 . "\">$wArray[$i]</a>"; 00267 array_push( $ts, $link ); 00268 } 00269 $themes = implode( "• ", $ts ); 00270 return $themes; 00271 } 00272 00273 function success( $s, $t, $term = false ) { 00274 if( !$s ) { 00275 echo "Fehler: ", $t, "<br>\n"; 00276 if( $term ) { 00277 "Das Skript wird abgebrochen<br>\n"; 00278 exit(); 00279 } 00280 } 00281 return; 00282 } 00283 00284 ?>