* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ define("SYTELINE_DSN", "syteline"); define("SYTELINE_USER", "sa"); define("SYTELINE_PASS", ""); define("COLOR_HEADER", 12); define("COLOR_EVEN_ROW", 13); define("COLOR_ODD_ROW", 14); define("XLS_FORMAT_TEXT", 0); define("XLS_FORMAT_NUMBER", 1); define("XLS_FORMAT_MONETARY", 2); require_once 'Spreadsheet/Excel/Writer.php'; $mode_script = "html"; function debug($string) { global $mode_script; if ($mode_script == "html") echo '
' . $string . '
'; else echo $string . LF; } function debug_err($string) { global $mode_script; if ($mode_script == "html") echo '
' . $string . '
'; else fwrite(STDERR, $string . LF); } function debug_gen($string) { if (DISPLAY_DEBUG_GEN) { debug ($string); } } function debug_sql($string) { if (DISPLAY_DEBUG_SQL) { debug($string); } } /* Détection si le script PHP est appelé par le serveur web ou sur la ligne de commande */ function detection_mode_script() { global $mode_script; if (isset($_SERVER['REQUEST_METHOD'])) { $mode_script = "html"; } else { $mode_script = "cmdline"; } } function windows_to_unix_path( $path ) { // Remplacement de "\" par "/" return str_replace( "\\", "/", $path ); } function remove_spaces_from_filename( $file ) { $file = str_replace( " ", "\\ ", $file ); return $file; } function strip_ext($name) { $ext = strrchr($name, '.'); if($ext !== false) { $name = substr($name, 0, -strlen($ext)); } return $name; } function strip_trailing_slash($name) { if (substr($name, -1, 1) == '/') { $name = substr($name, 0, -1); } return $name; } function strip_last_dir($name) { $name = strip_trailing_slash($name); $last_dir = strrchr($name, '/'); if($last_dir !== false) { $name = substr($name, 0, -strlen($last_dir)); } return $name; } /* Création de couleurs personalisées dans la table des couleurs. */ function xls_set_colors($workbook) { /* Entête. */ $workbook->setCustomColor(COLOR_HEADER, 255, 153, 00); /* Rangée paire. */ $workbook->setCustomColor(COLOR_EVEN_ROW, 255, 255, 255); /* Rangée impaire. */ $workbook->setCustomColor(COLOR_ODD_ROW, 219, 225, 255); } /* * Écriture dans une cellule, avec la couleur alternée pour les lignes * paires et impaires. * * $format_texte: * true = texte * false = nombre */ function xls_write_cell_gen($row, $col, $value, $format_texte, $entete, $size, $border, $wrap) { global $workbook,$worksheet; $value = mb_convert_encoding($value, "ISO-8859-1", "UTF-8"); /* Création object format. */ $format =& $workbook->addFormat(); /* Grosseur du texte. */ $format->setSize($size); if ($wrap) { $format->setTextWrap(); } if ($format_texte == XLS_FORMAT_TEXT) { $format->setAlign('left'); $format->setAlign('top'); } else if ($format_texte == XLS_FORMAT_MONETARY) { $format->setNumFormat('$0.00'); } if ($entete == TRUE) { /* Texte en gras. */ $format->setBold(); $format->setFgColor(COLOR_HEADER); } else { if ($row % 2) { $format->setFgColor(COLOR_ODD_ROW); } else { $format->setFgColor(COLOR_EVEN_ROW); } } if ($border) { if ($entete == TRUE) { $format->setTop(1); /* Bordure du haut. */ } $format->setBottom(1); /* Bordure du haut. */ $format->setRight(1); /* Bordure de droite. */ $format->setLeft(1); /* Bordure de gauche. */ } if ($format_texte == XLS_FORMAT_TEXT) { $worksheet->writeString($row, $col, $value, $format); } else { $worksheet->write($row, $col, $value, $format); } } function xls_write_col_header($row, $col, $value) { xls_write_cell_gen($row, $col, $value, XLS_FORMAT_TEXT, true, 12, true, true); } function xls_write_cell($row, $col, $value, $format_texte) { xls_write_cell_gen($row, $col, $value, $format_texte, false, 11, true, true); } function xls_write_price($row, $col, $value) { xls_write_cell_gen($row, $col, $value, XLS_FORMAT_MONETARY, false, 11, true, true); } function get_price($item) { /* Connect to a DSN "syteline" */ $connect = odbc_connect(SYTELINE_DSN, SYTELINE_USER, SYTELINE_PASS); /* * unit_cost: * lst_u_cost: Last * avg_u_cost: * cur_u_cost: */ $query = "SELECT item, cur_u_cost FROM dbo.item WHERE item='" . $item . "'"; /* Perform the query. */ $result = odbc_exec($connect, $query); $price = ""; /* Fetch the data from the database. */ while(odbc_fetch_row($result)) { $item = odbc_result($result, 1); $price = odbc_result($result, 2); } /* Close the connection. */ odbc_close($connect); return $price; } function get_mpn($item) { /* Connect to a DSN "syteline" */ $connect = odbc_connect(SYTELINE_DSN, SYTELINE_USER, SYTELINE_PASS); /* * unit_cost: * lst_u_cost: Last * avg_u_cost: * cur_u_cost: */ $query = "SELECT item, MPN FROM dbo.DAP_MPN WHERE item='" . $item . "'"; /* Perform the query. */ $result = odbc_exec($connect, $query); $mpn = ""; /* Fetch the data from the database. */ while(odbc_fetch_row($result)) { $item = odbc_result($result, 1); $mpn = odbc_result($result, 2); } /* Close the connection. */ odbc_close($connect); return $mpn; } function get_manufacturer($item) { /* Connect to a DSN "syteline" */ $connect = odbc_connect(SYTELINE_DSN, SYTELINE_USER, SYTELINE_PASS); /* * unit_cost: * lst_u_cost: Last * avg_u_cost: * cur_u_cost: */ $query = "SELECT item, MANUFACTURER FROM dbo.DAP_MPN WHERE item='" . $item . "'"; /* Perform the query. */ $result = odbc_exec($connect, $query); $manufacturer = ""; /* Fetch the data from the database. */ while(odbc_fetch_row($result)) { $item = odbc_result($result, 1); $manufacturer = odbc_result($result, 2); } /* Close the connection. */ odbc_close($connect); return $manufacturer; } ?>