From 389fff2824ca8b6992a495decf659aec884a683f Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 18 Dec 2018 17:46:36 +0000 Subject: [PATCH] wip #2438 @1.5 --- inc/commons/class.common.ajax.php | 44 ++++++++++++++++++++++++++++++ inc/commons/class.common.core.php | 6 ++++ inc/commons/class.common.tools.php | 22 +++++++++++++++ inc/ws/Util/class.ws.links.php | 2 -- 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/inc/commons/class.common.ajax.php b/inc/commons/class.common.ajax.php index 2aacaae29..af147addc 100644 --- a/inc/commons/class.common.ajax.php +++ b/inc/commons/class.common.ajax.php @@ -472,5 +472,49 @@ Mot de passe : $password"; $mail->send($transport); } + public static function importWSReferences($args, &$x) + { + global $core; + + $e = explode('.', $_FILES['file']['name']); + $ext = array_pop($e); + new PHPExcel(); + $reader = new PHPExcel_Reader_Excel2007(); + $phpexcel = $reader->load($_FILES['file']['tmp_name']); + $sheet = $phpexcel->getSheet(0); + $maxRow = $sheet->getHighestRow(0); + for ($i = 0; $i < $maxRow; $i++) { + + $ref = trim($sheet->getCellByColumnAndRow(0, $i)); + $url = trim($sheet->getCellByColumnAndRow(1, $i)->getOldCalculatedValue()); + if ($url == '' || $ref == '') { + continue; + } + + $c = $core->con->openCursor('wsref'); + $c->type = $_POST['type']; + $c->ref = self::_formatWsReferenceRef($ref, $_POST['type']); + $c->url = self::_formatWsReferenceUrl($url, $_POST['type']); + try { + $c->insert(); + } catch (Exception $e) { + $c->update("WHERE ref='" . $core->con->escape($ref) . "' AND type='" . $core->con->escape($_POST['type']) . "'"); + } + } + } + + public static function _formatWsReferenceRef($ref, $type) + { + if ($type == '10doigts') { + if (stripos($ref, 'ic') === 0) { + return 'C' . substr($ref, 2); + } + } + return $ref; + } + public static function _formatWsReferenceUrl($url, $type) + { + return $url; + } } diff --git a/inc/commons/class.common.core.php b/inc/commons/class.common.core.php index 7b2ba635b..5ccaf0cab 100644 --- a/inc/commons/class.common.core.php +++ b/inc/commons/class.common.core.php @@ -525,6 +525,12 @@ class commonCore extends cubeCore $db->bulle->nom('varchar', 128, false); $db->bulle->catalogue('varchar', 128, false); + // WS Ref + + $db->wsref->type('varchar', 32, false); + $db->wsref->ref('varchar', 32, false); + $db->wsref->url('varchar', 512, false); + $db->wsref->primary('pk_wsref', 'type', 'ref'); // Table google search api $db->google_search_api->request('varchar', 256, false); diff --git a/inc/commons/class.common.tools.php b/inc/commons/class.common.tools.php index eae96d484..914a1667e 100644 --- a/inc/commons/class.common.tools.php +++ b/inc/commons/class.common.tools.php @@ -1141,6 +1141,28 @@ class commonTools return $res; } + public static function importWSReferences() + { + commonDroits::min(5); + global $core; + $res = commonPage::barre(); + $res .= commonPage::tMain(); + $res .= commonPage::bh(); + $res .= '
'; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= '
' . __('Importer un fichier de références') . '
' . __("Fichier XLSX") . '
(colonne A : référence, colonne B : URL)
' . __("Type") . '
' . $core->typo->BoutonOK(__('Importer les références')) . '
'; + $res .= '
'; + $res .= commonPage::bf(); + + $res .= commonPage::bMain(); + return $res; + } + + public static function makeSNCFCodes() { $list = explode("\n", file_get_contents($_FILES['file']['tmp_name'])); diff --git a/inc/ws/Util/class.ws.links.php b/inc/ws/Util/class.ws.links.php index 6e58b2fd5..c16e6a65f 100644 --- a/inc/ws/Util/class.ws.links.php +++ b/inc/ws/Util/class.ws.links.php @@ -35,8 +35,6 @@ class wsLinks 'group' => __('Groupe'), ); - new PHPExcel(); - /* $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_memcache; $cacheSettings = array('memcacheServer' => 'localhost', 'memcachePort' => 11211, -- 2.39.5