]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 14 Jan 2013 16:19:22 +0000 (16:19 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 14 Jan 2013 16:19:22 +0000 (16:19 +0000)
inc/commons/class.common.tools.php

index 73aad54993c4285af326a46aeffbab32d3d4b96a..f7082beb956d7b172e4f052eb223c9c9af9162d8 100644 (file)
@@ -190,7 +190,6 @@ class commonTools {
                $res.='<table class="liste">';
                $res.='<tr><th colspan="3"><strong>' . __('Exporter la base clients') . '</strong></th></tr>';
                $res.='<tr><td>' . __('Type de client') . '</td><td>' . form::combo('type', $types) . '</td></td>';
-               $res.='<tr><td>' . __('Type d\'export') . '</td><td>' . form::combo('typeexp', $typeexp) . '</td></tr>';
                $res.='<tr class="odd"><td class="right" colspan="2"><a href="#" class="submit">' . $core->typo->BoutonOK(__('Exporter')) . '</a></td></td>';
                $res.='</table>';
                $res.='</form>';
@@ -222,7 +221,89 @@ class commonTools {
                foreach ($rows as $r) {
                        $entreprises[$r['entreprise']]['utilisateurs'][$r['utilisateur_id']] = $r;
                }
-               fb($entreprises);
+
+               $xls = new PHPExcel();
+               $s1 = $xls->getActiveSheet();
+               $s1->setTitle('Entreprises');
+               self::exportClientsXLSEntreprises($s1, $entreprises);
+
+               $s2 = $xls->createSheet();
+               $s2->setTitle('Utilisateurs');
+               self::exportClientsXLSUsers($s2, $entreprises);
+
+               ob_end_clean();
+               files::$mimeType['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
+               cubeHTTP::forceDownload('clients.xlsx', false);
+
+               $xls->setActiveSheetIndex(0);
+               $writer = new PHPExcel_Writer_Excel2007($xls);
+               $writer->save('php://output');
+               exit;
+       }
+
+       /**
+        * 
+        * @param PHPExcel_Worksheet $s
+        * @param type $e
+        */
+       public static function exportClientsXLSEntreprises(&$s, $e) {
+               $j = 2;
+               $w = 3;
+               foreach ($e as $id => $datas) {
+                       $mainAddress = self::_address($datas['nom'], $datas['adresse'], $datas['code_postal'], $datas['ville'], $datas['pays']);
+                       $otherAddress = array();
+                       foreach ($datas['utilisateurs'] as $u) {
+                               $a = self::_address($datas['nom'], $u['adresse'], $u['code_postal'], $u['ville'], $u['pays']);
+                               if ($a != $mainAddress && !in_array($a, $otherAddress)) {
+                                       $otherAddress[] = $a;
+                               }
+                       }
+
+                       $s->getCellByColumnAndRow(0, $j)->setValue($id);
+                       $s->getCellByColumnAndRow(1, $j)->setValue($datas['nom']);
+                       $s->getCellByColumnAndRow(2, $j)->setValue($mainAddress);
+                       $i = 3;
+                       foreach ($otherAddress as $o) {
+                               $s->getCellByColumnAndRow($i, $j)->setValue($o);
+                               $i++;
+                       }
+                       $j++;
+                       $w = max($w, $i);
+               }
+
+               $h = $j;
+
+               $s->getCellByColumnAndRow(0, 1)->setValue('#');
+               $s->getCellByColumnAndRow(1, 1)->setValue('Raison sociale');
+               $s->getCellByColumnAndRow(2, 1)->setValue('Adresse principale');
+               $s->getCellByColumnAndRow(3, 1)->setValue('Autres adresses');
+
+               for ($i = 0; $i <= $w; $i++) {
+                       for ($j = 0; $j <= $h; $j++) {
+                               $style = $s->getStyleByColumnAndRow($i, $j);
+                               $style->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER)->setWrapText(true);
+                       }
+                       if ($i == 0) {
+                               $s->getColumnDimensionByColumn($i)->setAutoSize();
+                       } elseif ($i == 1) {
+                               $s->getColumnDimensionByColumn($i)->setWidth(20);
+                       } else {
+                               $s->getColumnDimensionByColumn($i)->setWidth(30);
+                       }
+               }
+       }
+
+       protected static function _address($nom, $adresse, $code_postal, $ville, $pays) {
+               return trim(trim($nom) . "\r\n" . trim($adresse) . "\r\n" . trim($code_postal . " " . $ville) . "\r\n" . cubeCountry::getCountryName($pays, 'fr_FR'));
+       }
+
+       /**
+        * 
+        * @param PHPExcel_Worksheet $s
+        * @param type $e
+        */
+       public static function exportClientsXLSUsers(&$s, $e) {
+               
        }
 
        public static function favicon($args) {