function docs_spsr_excel($comp, $offer, &$order, $core = null) { // Load the Excel require_once PATH_LIB . 'PHPExcel/IOFactory.php'; $objPHPExcel = PHPExcel_IOFactory::load(PATH_DOCS . "spsr.xls"); $objPHPExcel->setActiveSheetIndex(0); $aSheet = $objPHPExcel->getActiveSheet(); // Company info $aSheet->setCellValue('C4', date('d.m.Y')); $aSheet->setCellValue('C5', $comp['comp_spsr']); $aSheet->setCellValue('H7', $comp['comp_fio']); $aSheet->setCellValue('H8', $comp['comp_addr']); $aSheet->setCellValue('H9', $comp['comp_phone']); $i = $addrok = 0; foreach ($order as $o) { // Show the line $i++; $r = 10 + $i; $aSheet->getRowDimension($r)->setVisible(true); // Basic order info $aSheet->setCellValue('A' . $r, $i); $aSheet->setCellValue('J' . $r, $o['order_name']); $aSheet->setCellValue('K' . $r, $o['order_phone']); $aSheet->setCellValue('L' . $r, $o['order_id']); $aSheet->setCellValue('M' . $r, $o['order_price']); // the Offer if ($o['items']) { $aSheet->setCellValue('C' . $r, sprintf("%s (%s)", $offer[$o['offer_id']], $o['items'])); $aSheet->setCellValue('B' . $r, $o['order_count']); } else { $aSheet->setCellValue('C' . $r, $offer[$o['offer_id']]); $aSheet->setCellValue('B' . $r, '1'); } // Order address if ($o['order_addr'] && $o['order_area'] && $o['order_street'] && $o['order_city']) { $house = $o['order_addr']; $region = $o['order_area']; $street = $o['order_street']; $city = $o['order_city']; } else { $addr = $o['order_addr']; if ($o['order_street']) { $addr = $o['order_street'] . ', ' . $addr; } if ($o['order_city']) { $addr = $o['order_city'] . ', ' . $addr; } if ($o['order_area']) { $addr = $o['order_area'] . ', ' . $addr; } $region = $city = $street = $house = ''; $addr = $addr ? parseaddress($addr) : false; if ($addr) { foreach ($addr as $a) { if ($a['id'] == 'zip') { continue; } if ($a['id'] == 'street') { $street = trim($a['type'], '. ') . '. ' . $a['value']; } elseif ($a['id'] == 'city' || $a['id'] == 'place') { $city .= $a['value'] . ', '; } elseif ($a['id'] == 'district') { $city .= $a['value'] . ' ' . trim($a['type'], '. ') . ', '; } elseif ($a['id'] == 'region') { if ($a['type'] != 'г') { if ($a['type'] == 'Респ') { $region = trim($a['type'], '. ') . '. ' . $a['value']; } else { $region = $a['value'] . ' ' . $a['type']; } } else { $city = $a['value'] . ', '; } } else { if ($a['type'] == 'ДОМ' || $a['type'] == 'дом') { $a['type'] = 'д'; } $house .= trim($a['type'], '. ') . '. ' . $a['value'] . ', '; } } $house = trim($house, ', '); $city = trim($city, ', '); $addrok += 1; if ($city == 'Москва' && !$region) { $region = 'Московская обл.'; } if ($city == 'Санкт-Петербург' && !$region) { $region = 'Ленинградская обл.'; } } } // Setting address info $aSheet->setCellValue('E' . $r, $region); $aSheet->setCellValue('F' . $r, $city); $aSheet->setCellValue('G' . $r, $street); $aSheet->setCellValue('H' . $r, $house); } // Output the document header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="spsr.xls"'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save("php://output"); $objPHPExcel->disconnectWorksheets(); unset($aSheet, $objWriter, $objPHPExcel); return $addrok; }
GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. *******************************************************************************/ // Loading Site Core error_reporting(0); define('PATH', dirname(__FILE__) . '/'); header('Content-Type: text/html; charset=utf-8'); require_once PATH . 'core/settings.php'; require_once PATH . 'lib/addr.php'; $addr = normalizeaddr(stripslashes($_POST['addr'])); $cached = PATH . 'data/cache/addr-' . md5($addr) . '.txt'; if (!file_exists($cached)) { $data = parseaddress($addr); if (count($data)) { $ind = 0; $ad = ''; $region = $city = $street = $house = ''; foreach ($data as $d) { if ($d['id'] == 'zip') { $ind = $d['value']; continue; } else { if ($d['id'] == 'region' || $d['id'] == 'district') { if ($d['type'] == 'Респ' || $d['type'] == 'г') { $ad .= trim($d['type'], '. ') . '. ' . $d['value'] . ', '; } else { $ad .= $d['value'] . ' ' . $d['type'] . ', '; }