diff --git a/htdocs/dolistore/ajax/image.php b/htdocs/admin/dolistore/ajax/image.php similarity index 94% rename from htdocs/dolistore/ajax/image.php rename to htdocs/admin/dolistore/ajax/image.php index 5bc6c9f2f0f..10ce4656c40 100644 --- a/htdocs/dolistore/ajax/image.php +++ b/htdocs/admin/dolistore/ajax/image.php @@ -1,65 +1,67 @@ -. - * - * This program is free software; you can redistribute it and/or modifyion 2.0 (the "License"); - * it under the terms of the GNU General Public License as published bypliance with the License. - * the Free Software Foundation; either version 3 of the License, or - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * 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 . - * or see http://www.gnu.org/ - */ - -if (!defined('REQUIRE_JQUERY_BLOCKUI')) define('REQUIRE_JQUERY_BLOCKUI', 1); -/** - * \file htdocs/commande/info.php - * \ingroup commande - * \brief Page des informations d'une commande - */ -$res = 0; -if (!$res && file_exists("../main.inc.php")) $res = @include("../main.inc.php"); -if (!$res && file_exists("../../main.inc.php")) $res = @include("../../main.inc.php"); -if (!$res && file_exists("../../../main.inc.php")) $res = @include("../../../main.inc.php"); -if (!$res && file_exists("../../../../main.inc.php")) $res = @include("../../../../main.inc.php"); -if (!$res && file_exists("../../../dolibarr/htdocs/main.inc.php")) - $res = @include("../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only -if (!$res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) - $res = @include("../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only -if (!$res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) - $res = @include("../../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only -if (!$res) die("Include of main fails"); - -// CORE - -global $lang, $user, $conf; - - -dol_include_once('/dolistore/class/dolistore.class.php'); -$dolistore = new Dolistore(); - -$id_product = GETPOST('id_product', 'int'); -$id_image = GETPOST('id_image', 'int'); -// quality : image resize with this in the URL : "cart_default", "home_default", "large_default", "medium_default", "small_default", "thickbox_default" -$quality = GETPOST('quality', 'alpha'); - -try { - $url = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/images/products/'.$id_product.'/'.$id_image.'/'.$quality; - $api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, - $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $dolistore->debug_api); - //echo $url; - $request = $api->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET')); - header('Content-type:image'); - print $request['response']; -} catch (PrestaShopWebserviceException $e) { - // Here we are dealing with errors - $trace = $e->getTrace(); - if ($trace[0]['args'][0] == 404) die('Bad ID'); - else if ($trace[0]['args'][0] == 401) die('Bad auth key'); - else die('Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV); -} \ No newline at end of file +. + * Copyright (C) 2008-2011 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modifyion 2.0 (the "License"); + * it under the terms of the GNU General Public License as published bypliance with the License. + * the Free Software Foundation; either version 3 of the License, or + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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 . + * or see http://www.gnu.org/ + */ + +if (!defined('REQUIRE_JQUERY_BLOCKUI')) define('REQUIRE_JQUERY_BLOCKUI', 1); + + +/** + * \file htdocs/commande/info.php + * \ingroup commande + * \brief Page des informations d'une commande + */ +$res = 0; +if (!$res && file_exists("../main.inc.php")) $res = @include("../main.inc.php"); +if (!$res && file_exists("../../main.inc.php")) $res = @include("../../main.inc.php"); +if (!$res && file_exists("../../../main.inc.php")) $res = @include("../../../main.inc.php"); +if (!$res && file_exists("../../../../main.inc.php")) $res = @include("../../../../main.inc.php"); +if (!$res && file_exists("../../../dolibarr/htdocs/main.inc.php")) + $res = @include("../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only +if (!$res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) + $res = @include("../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only +if (!$res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) + $res = @include("../../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only +if (!$res) die("Include of main fails"); + +// CORE + +global $lang, $user, $conf; + + +dol_include_once('/dolistore/class/dolistore.class.php'); +$dolistore = new Dolistore(); + +$id_product = GETPOST('id_product', 'int'); +$id_image = GETPOST('id_image', 'int'); +// quality : image resize with this in the URL : "cart_default", "home_default", "large_default", "medium_default", "small_default", "thickbox_default" +$quality = GETPOST('quality', 'alpha'); + +try { + $url = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/images/products/'.$id_product.'/'.$id_image.'/'.$quality; + $api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, + $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $dolistore->debug_api); + //echo $url; + $request = $api->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET')); + header('Content-type:image'); + print $request['response']; +} catch (PrestaShopWebserviceException $e) { + // Here we are dealing with errors + $trace = $e->getTrace(); + if ($trace[0]['args'][0] == 404) die('Bad ID'); + else if ($trace[0]['args'][0] == 401) die('Bad auth key'); + else die('Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV); +} \ No newline at end of file diff --git a/htdocs/dolistore/class/PSWebServiceLibrary.class.php b/htdocs/admin/dolistore/class/PSWebServiceLibrary.class.php similarity index 96% rename from htdocs/dolistore/class/PSWebServiceLibrary.class.php rename to htdocs/admin/dolistore/class/PSWebServiceLibrary.class.php index 8f55f6fd323..bb59fa93929 100644 --- a/htdocs/dolistore/class/PSWebServiceLibrary.class.php +++ b/htdocs/admin/dolistore/class/PSWebServiceLibrary.class.php @@ -45,8 +45,8 @@ class PrestaShopWebservice protected $version; /** @var array compatible versions of PrestaShop Webservice */ - const psCompatibleVersionsMin = '1.4.0.0'; - const psCompatibleVersionsMax = '1.6.99.99'; + const PSCOMPATIBLEVERSIONMIN = '1.4.0.0'; + const PSCOMPATIBLEVERSIONMAX = '1.6.99.99'; /** * PrestaShopWebservice constructor. Throw an exception when CURL is not installed/activated @@ -152,8 +152,8 @@ class PrestaShopWebservice { $this->version = $headerArray['PSWS-Version']; if ( - version_compare(PrestaShopWebservice::psCompatibleVersionsMin, $headerArray['PSWS-Version']) == 1 || - version_compare(PrestaShopWebservice::psCompatibleVersionsMax, $headerArray['PSWS-Version']) == -1 + version_compare(PrestaShopWebservice::PSCOMPATIBLEVERSIONMIN, $headerArray['PSWS-Version']) == 1 || + version_compare(PrestaShopWebservice::PSCOMPATIBLEVERSIONMAX, $headerArray['PSWS-Version']) == -1 ) throw new PrestaShopWebserviceException('This library is not compatible with this version of PrestaShop. Please upgrade/downgrade this library'); } @@ -218,8 +218,9 @@ class PrestaShopWebservice * 'resource' => Resource name
* 'postXml' => Full XML string to add resource

* Examples are given in the tutorial

- * @param array $options - * @return SimpleXMLElement status_code, response + * + * @param array $options Options + * @return SimpleXMLElement status_code, response */ public function add($options) { @@ -406,4 +407,7 @@ class PrestaShopWebservice /** * @package PrestaShopWebservice */ -class PrestaShopWebserviceException extends Exception { } \ No newline at end of file +class PrestaShopWebserviceException extends Exception +{ + +} diff --git a/htdocs/dolistore/class/dolistore.class.php b/htdocs/admin/dolistore/class/dolistore.class.php similarity index 95% rename from htdocs/dolistore/class/dolistore.class.php rename to htdocs/admin/dolistore/class/dolistore.class.php index 35900d66f7d..3b3abadd3e4 100644 --- a/htdocs/dolistore/class/dolistore.class.php +++ b/htdocs/admin/dolistore/class/dolistore.class.php @@ -1,308 +1,316 @@ -. - * - * This program is free software; you can redistribute it and/or modifyion 2.0 (the "License"); - * it under the terms of the GNU General Public License as published bypliance with the License. - * the Free Software Foundation; either version 3 of the License, or - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * 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 . - * or see http://www.gnu.org/ - */ -dol_include_once('/core/lib/admin.lib.php'); -dol_include_once('/dolistore/class/PSWebServiceLibrary.class.php'); - -class Dolistore extends DolistoreModel -{ - // params - public $start // beginning of pagination - , $end // end of pagination - , $per_page // pagination: display per page - , $categorie // the current categorie - , $search // the search keywords - // setups - , $url // the url of this page - , $shop_url // the url of the shop - , $vat_rate // the vat rate used in the shop (prices are provided without vat) - , $lang // the integer representing the lang in the store - , $debug_api; // usefull if no dialog - - function __construct($options = array('start' => 0, 'end' => 10, 'per_page' => 50, 'categorie' => 0)) - { - global $conf, $langs; - - $this->start = $options['start']; - $this->end = $options['end']; - $this->per_page = $options['per_page']; - $this->categorie = $options['categorie']; - $this->search = $options['search']; - - $this->url = dol_buildpath('/dolistore/index.php', 2); - $this->shop_url = 'https://www.dolistore.com/index.php?controller=product&id_product='; - $this->vat_rate = 1.2; // 20% de TVA - $this->debug_api = false; - - if ($this->end == 0) { - $this->end = $this->per_page; - } - - $lang = explode('_', $langs->defaultlang); - $lang = $lang[0]; - $lang_array = ['fr', 'en', 'es', 'it', 'de']; - if (!in_array($lang, $lang_array)) { - $lang = 'en'; - } - $this->lang = array_search($lang, $lang_array) + 1; // 1=fr 2=en ... - - try { - $this->api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, - $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api); - - // Here we set the option array for the Webservice : we want products resources - $opt = array(); - $opt['resource'] = 'products'; - // make a search to limit the id returned. - if ($this->search != '') { - $opt2 = array(); - $opt2['url'] = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/search?query='.$this->search.'&language='.$this->lang; - // Call - $xml = $this->api->get($opt2); - $products = array(); - foreach ($xml->products->children() as $product) { - $products[] = (int) $product['id']; - } - $opt['filter[id]'] = '['.implode('|', $products).']'; - } elseif ($this->categorie != 0) { - $opt2 = array(); - $opt2['resource'] = 'categories'; - $opt2['id'] = $this->categorie; - // Call - $xml = $this->api->get($opt2); - $products = array(); - foreach ($xml->category->associations->products->children() as $product) { - $products[] = (int) $product->id; - } - $opt['filter[id]'] = '['.implode('|', $products).']'; - } - $opt['display'] = '[id,name,id_default_image,id_category_default,reference,price,condition,show_price,date_add,date_upd,description_short,description,module_version,dolibarr_min,dolibarr_max]'; - $opt['sort'] = 'id_desc'; - $opt['filter[active]'] = '[1]'; - $opt['limit'] = "$this->start,$this->end"; - // Call - $xml = $this->api->get($opt); - $this->products = $xml->products->children(); - - - // Here we set the option array for the Webservice : we want categories resources - $opt = array(); - $opt['resource'] = 'categories'; - $opt['display'] = '[id,id_parent,nb_products_recursive,active,is_root_category,name,description]'; - $opt['sort'] = 'id_asc'; - // Call - $xml = $this->api->get($opt); - $this->categories = $xml->categories->children(); - } catch (PrestaShopWebserviceException $e) { - // Here we are dealing with errors - $trace = $e->getTrace(); - if ($trace[0]['args'][0] == 404) die('Bad ID'); - else if ($trace[0]['args'][0] == 401) die('Bad auth key'); - else die('Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV); - } - } - - function get_previous_url() - { - $param_array = array(); - if ($this->start < $this->per_page) { - $sub = 0; - } else { - $sub = $this->per_page; - } - $param_array['start'] = $this->start - $sub; - $param_array['end'] = $this->end - $sub; - if ($this->categorie != 0) { - $param_array['categorie'] = $this->categorie; - } - $param = http_build_query($param_array); - return $this->url."?$param"; - } - - function get_next_url() - { - $param_array = array(); - if (count($this->products) < $this->per_page) { - $add = 0; - } else { - $add = $this->per_page; - } - $param_array['start'] = $this->start + $add; - $param_array['end'] = $this->end + $add; - if ($this->categorie != 0) { - $param_array['categorie'] = $this->categorie; - } - $param = http_build_query($param_array); - return $this->url."?$param"; - } - - function version_compare($v1, $v2) - { - $v1 = explode('.', $v1); - $v2 = explode('.', $v2); - $ret = 0; - $level = 0; - $count1 = count($v1); - $count2 = count($v2); - $maxcount = max($count1, $count2); - while ($level < $maxcount) { - $operande1 = isset($v1[$level]) ? $v1[$level] : 'x'; - $operande2 = isset($v2[$level]) ? $v2[$level] : 'x'; - $level++; - if (strtoupper($operande1) == 'X' || strtoupper($operande2) == 'X' || $operande1 == '*' || $operande2 == '*') { - break; - } - if ($operande1 < $operande2) { - $ret = -$level; - break; - } - if ($operande1 > $operande2) { - $ret = $level; - break; - } - } - //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'
'."\n"; - return $ret; - } -} - -class DolistoreModel -{ - - function get_categories($parent = 0) - { - if (!isset($this->categories)) die('not possible'); - if ($parent != 0) { - $html = '
    '; - } else { - $html = ''; - } - - for ($i = 0; $i < count($this->categories); $i++) { - $cat = $this->categories[$i]; - if ($cat->is_root_category == 1 && $parent == 0) { - $html .= '
  • '.$cat->name->language[$this->lang].' '.$cat->nb_products_recursive.'

    '; - $html .= self::get_categories($cat->id); - $html .= "
  • \n"; - } elseif (trim($cat->id_parent) == $parent && $cat->active == 1 && trim($cat->id_parent) != 0) { // si cat est de ce niveau - $select = ($cat->id == $this->categorie) ? ' selected' : ''; - $html .= '
  • '.$cat->name->language[$this->lang].' '.$cat->nb_products_recursive.''; - $html .= self::get_categories($cat->id); - $html .= "
  • \n"; - } else { - - } - } - - if ($html == '
      ') { - return ''; - } - if ($parent != 0) { - return $html.'
    '; - } else { - return $html; - } - } - - function get_products() - { - global $langs, $conf; - $html = ""; - $parity = "pair"; - $last_month = time() - (30 * 24 * 60 * 60); - foreach ($this->products as $product) { - $parity = ($parity == "impair") ? 'pair' : 'impair'; - - // check new product ? - $newapp = ''; - if ($last_month < strtotime($product->date_add)) { - $newapp .= ''.$langs->trans('New').' '; - } - - // check updated ? - if ($last_month < strtotime($product->date_upd) && $newapp == '') { - $newapp .= ''.$langs->trans('Updated').' '; - } - - // add image or default ? - if ($product->id_default_image != '') { - $image_url = dol_buildPath('/dolistore/ajax/image.php?id_product=', 2).$product->id.'&id_image='.$product->id_default_image; - $images = ''. - ''; - } else { - $images = ''; - } - - // free or pay ? - if ($product->price > 0) { - $price = '

    '.price(round((float) $product->price * $this->vat_rate, 2)).' €

    '; - $download_link = ''; - } else { - $price = $langs->trans('Free'); - $download_link = ''; - } - - //checking versions - if ($this->version_compare($product->dolibarr_min, DOL_VERSION) <= 0) { - if ($this->version_compare($product->dolibarr_max, DOL_VERSION) >= 0) { - //compatible - $version = ''.$langs->trans('CompatibleUpTo', $product->dolibarr_max, - $product->dolibarr_min, $product->dolibarr_max).''; - $compatible = ''; - } else { - //never compatible, module expired - $version = ''.$langs->trans('NotCompatible', DOL_VERSION, - $product->dolibarr_min, $product->dolibarr_max).''; - $compatible = 'NotCompatible'; - } - } else { - //need update - $version = ''.$langs->trans('CompatibleAfterUpdate', DOL_VERSION, - $product->dolibarr_min, $product->dolibarr_max).''; - $compatible = 'NotCompatible'; - } - - //output template - $html .= ' -
    '.$newapp.$images.'
    -

    '.$product->name->language[$this->lang].'Details' - .'
    '.$version.'

    - '.dol_print_date(strtotime($product->date_upd)).' - '.$langs->trans('Référence').': '.$product->reference.' - '.$langs->trans('Id').': '.$product->id.'

    '.$product->description_short->language[$this->lang].' - '.$product->description->language[$this->lang].' - '.$price.' - '.$download_link.' - '; - } - return $html; - } - - function get_previous_link($text = '<<') - { - return "$text"; - } - - function get_next_link($text = '>>') - { - return "$text"; - } -} \ No newline at end of file +. + * + * This program is free software; you can redistribute it and/or modifyion 2.0 (the "License"); + * it under the terms of the GNU General Public License as published bypliance with the License. + * the Free Software Foundation; either version 3 of the License, or + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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 . + * or see http://www.gnu.org/ + */ + +include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +include_once DOL_DOCUMENT_ROOT.'/admin/dolistore/class/PSWebServiceLibrary.class.php'; + +/** + * Class DolistoreModel + */ +class Dolistore extends DolistoreModel +{ + // params + public $start // beginning of pagination + , $end // end of pagination + , $per_page // pagination: display per page + , $categorie // the current categorie + , $search // the search keywords + // setups + , $url // the url of this page + , $shop_url // the url of the shop + , $vat_rate // the vat rate used in the shop (prices are provided without vat) + , $lang // the integer representing the lang in the store + , $debug_api; // usefull if no dialog + + function __construct($options = array('start' => 0, 'end' => 10, 'per_page' => 50, 'categorie' => 0)) + { + global $conf, $langs; + + $this->start = $options['start']; + $this->end = $options['end']; + $this->per_page = $options['per_page']; + $this->categorie = $options['categorie']; + $this->search = $options['search']; + + $this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace'; + $this->shop_url = 'https://www.dolistore.com/index.php?controller=product&id_product='; + $this->vat_rate = 1.2; // 20% de TVA + $this->debug_api = false; + + if ($this->end == 0) { + $this->end = $this->per_page; + } + + $lang = explode('_', $langs->defaultlang); + $lang = $lang[0]; + $lang_array = ['fr', 'en', 'es', 'it', 'de']; + if (!in_array($lang, $lang_array)) { + $lang = 'en'; + } + $this->lang = array_search($lang, $lang_array) + 1; // 1=fr 2=en ... + + try { + $this->api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, + $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api); + + // Here we set the option array for the Webservice : we want products resources + $opt = array(); + $opt['resource'] = 'products'; + // make a search to limit the id returned. + if ($this->search != '') { + $opt2 = array(); + $opt2['url'] = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/search?query='.$this->search.'&language='.$this->lang; + // Call + $xml = $this->api->get($opt2); + $products = array(); + foreach ($xml->products->children() as $product) { + $products[] = (int) $product['id']; + } + $opt['filter[id]'] = '['.implode('|', $products).']'; + } elseif ($this->categorie != 0) { + $opt2 = array(); + $opt2['resource'] = 'categories'; + $opt2['id'] = $this->categorie; + // Call + $xml = $this->api->get($opt2); + $products = array(); + foreach ($xml->category->associations->products->children() as $product) { + $products[] = (int) $product->id; + } + $opt['filter[id]'] = '['.implode('|', $products).']'; + } + $opt['display'] = '[id,name,id_default_image,id_category_default,reference,price,condition,show_price,date_add,date_upd,description_short,description,module_version,dolibarr_min,dolibarr_max]'; + $opt['sort'] = 'id_desc'; + $opt['filter[active]'] = '[1]'; + $opt['limit'] = "$this->start,$this->end"; + // Call + $xml = $this->api->get($opt); + $this->products = $xml->products->children(); + + + // Here we set the option array for the Webservice : we want categories resources + $opt = array(); + $opt['resource'] = 'categories'; + $opt['display'] = '[id,id_parent,nb_products_recursive,active,is_root_category,name,description]'; + $opt['sort'] = 'id_asc'; + // Call + $xml = $this->api->get($opt); + $this->categories = $xml->categories->children(); + } catch (PrestaShopWebserviceException $e) { + // Here we are dealing with errors + $trace = $e->getTrace(); + if ($trace[0]['args'][0] == 404) die('Bad ID'); + else if ($trace[0]['args'][0] == 401) die('Bad auth key'); + else die('Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV); + } + } + + function get_previous_url() + { + $param_array = array(); + if ($this->start < $this->per_page) { + $sub = 0; + } else { + $sub = $this->per_page; + } + $param_array['start'] = $this->start - $sub; + $param_array['end'] = $this->end - $sub; + if ($this->categorie != 0) { + $param_array['categorie'] = $this->categorie; + } + $param = http_build_query($param_array); + return $this->url."&".$param; + } + + function get_next_url() + { + $param_array = array(); + if (count($this->products) < $this->per_page) { + $add = 0; + } else { + $add = $this->per_page; + } + $param_array['start'] = $this->start + $add; + $param_array['end'] = $this->end + $add; + if ($this->categorie != 0) { + $param_array['categorie'] = $this->categorie; + } + $param = http_build_query($param_array); + return $this->url."&".$param; + } + + function version_compare($v1, $v2) + { + $v1 = explode('.', $v1); + $v2 = explode('.', $v2); + $ret = 0; + $level = 0; + $count1 = count($v1); + $count2 = count($v2); + $maxcount = max($count1, $count2); + while ($level < $maxcount) { + $operande1 = isset($v1[$level]) ? $v1[$level] : 'x'; + $operande2 = isset($v2[$level]) ? $v2[$level] : 'x'; + $level++; + if (strtoupper($operande1) == 'X' || strtoupper($operande2) == 'X' || $operande1 == '*' || $operande2 == '*') { + break; + } + if ($operande1 < $operande2) { + $ret = -$level; + break; + } + if ($operande1 > $operande2) { + $ret = $level; + break; + } + } + //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'
    '."\n"; + return $ret; + } +} + + +/** + * Class DolistoreModel + */ +class DolistoreModel +{ + + function get_categories($parent = 0) + { + if (!isset($this->categories)) die('not possible'); + if ($parent != 0) { + $html = '
      '; + } else { + $html = ''; + } + + for ($i = 0; $i < count($this->categories); $i++) { + $cat = $this->categories[$i]; + if ($cat->is_root_category == 1 && $parent == 0) { + $html .= '
    • '.$cat->name->language[$this->lang].' '.$cat->nb_products_recursive.'

      '; + $html .= self::get_categories($cat->id); + $html .= "
    • \n"; + } elseif (trim($cat->id_parent) == $parent && $cat->active == 1 && trim($cat->id_parent) != 0) { // si cat est de ce niveau + $select = ($cat->id == $this->categorie) ? ' selected' : ''; + $html .= '
    • '.$cat->name->language[$this->lang].' '.$cat->nb_products_recursive.''; + $html .= self::get_categories($cat->id); + $html .= "
    • \n"; + } else { + + } + } + + if ($html == '
        ') { + return ''; + } + if ($parent != 0) { + return $html.'
      '; + } else { + return $html; + } + } + + function get_products() + { + global $langs, $conf; + $html = ""; + $parity = "pair"; + $last_month = time() - (30 * 24 * 60 * 60); + foreach ($this->products as $product) { + $parity = ($parity == "impair") ? 'pair' : 'impair'; + + // check new product ? + $newapp = ''; + if ($last_month < strtotime($product->date_add)) { + $newapp .= ''.$langs->trans('New').' '; + } + + // check updated ? + if ($last_month < strtotime($product->date_upd) && $newapp == '') { + $newapp .= ''.$langs->trans('Updated').' '; + } + + // add image or default ? + if ($product->id_default_image != '') { + $image_url = dol_buildPath('/dolistore/ajax/image.php?id_product=', 2).$product->id.'&id_image='.$product->id_default_image; + $images = ''. + ''; + } else { + $images = ''; + } + + // free or pay ? + if ($product->price > 0) { + $price = '

      '.price(round((float) $product->price * $this->vat_rate, 2)).' €

      '; + $download_link = ''; + } else { + $price = $langs->trans('Free'); + $download_link = ''; + } + + //checking versions + if ($this->version_compare($product->dolibarr_min, DOL_VERSION) <= 0) { + if ($this->version_compare($product->dolibarr_max, DOL_VERSION) >= 0) { + //compatible + $version = ''.$langs->trans('CompatibleUpTo', $product->dolibarr_max, + $product->dolibarr_min, $product->dolibarr_max).''; + $compatible = ''; + } else { + //never compatible, module expired + $version = ''.$langs->trans('NotCompatible', DOL_VERSION, + $product->dolibarr_min, $product->dolibarr_max).''; + $compatible = 'NotCompatible'; + } + } else { + //need update + $version = ''.$langs->trans('CompatibleAfterUpdate', DOL_VERSION, + $product->dolibarr_min, $product->dolibarr_max).''; + $compatible = 'NotCompatible'; + } + + //output template + $html .= ' +
      '.$newapp.$images.'
      +

      '.$product->name->language[$this->lang].'Details' + .'
      '.$version.'

      + '.dol_print_date(strtotime($product->date_upd)).' - '.$langs->trans('Référence').': '.$product->reference.' - '.$langs->trans('Id').': '.$product->id.'

      '.$product->description_short->language[$this->lang].' + '.$product->description->language[$this->lang].' + '.$price.' + '.$download_link.' + '; + } + return $html; + } + + function get_previous_link($text = '<<') + { + return "$text"; + } + + function get_next_link($text = '>>') + { + return "$text"; + } +} diff --git a/htdocs/dolistore/class/init.php b/htdocs/admin/dolistore/class/init.php similarity index 100% rename from htdocs/dolistore/class/init.php rename to htdocs/admin/dolistore/class/init.php diff --git a/htdocs/dolistore/css/dolistore.css b/htdocs/admin/dolistore/css/dolistore.css similarity index 100% rename from htdocs/dolistore/css/dolistore.css rename to htdocs/admin/dolistore/css/dolistore.css diff --git a/htdocs/dolistore/img/Download-128.png b/htdocs/admin/dolistore/img/Download-128.png similarity index 100% rename from htdocs/dolistore/img/Download-128.png rename to htdocs/admin/dolistore/img/Download-128.png diff --git a/htdocs/dolistore/img/NoImageAvailable.png b/htdocs/admin/dolistore/img/NoImageAvailable.png similarity index 100% rename from htdocs/dolistore/img/NoImageAvailable.png rename to htdocs/admin/dolistore/img/NoImageAvailable.png diff --git a/htdocs/dolistore/img/compatible.png b/htdocs/admin/dolistore/img/compatible.png similarity index 100% rename from htdocs/dolistore/img/compatible.png rename to htdocs/admin/dolistore/img/compatible.png diff --git a/htdocs/dolistore/img/dolistore.png b/htdocs/admin/dolistore/img/dolistore.png similarity index 100% rename from htdocs/dolistore/img/dolistore.png rename to htdocs/admin/dolistore/img/dolistore.png diff --git a/htdocs/dolistore/img/follow.png b/htdocs/admin/dolistore/img/follow.png similarity index 100% rename from htdocs/dolistore/img/follow.png rename to htdocs/admin/dolistore/img/follow.png diff --git a/htdocs/dolistore/img/object_dolistore.png b/htdocs/admin/dolistore/img/object_dolistore.png similarity index 100% rename from htdocs/dolistore/img/object_dolistore.png rename to htdocs/admin/dolistore/img/object_dolistore.png diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index a59d6fca3bb..40beaeadec2 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/admin/dolistore/class/dolistore.class.php'; $langs->load("errors"); $langs->load("admin"); @@ -46,6 +47,17 @@ $search_status=GETPOST('search_status','alpha'); $search_nature=GETPOST('search_nature','alpha'); $search_version=GETPOST('search_version','alpha'); + +// For dolistore search +$options = array(); +$options['per_page'] = 20; +$options['categorie'] = GETPOST('categorie', 'int') + 0; +$options['start'] = GETPOST('start', 'int') + 0; +$options['end'] = GETPOST('end', 'int') + 0; +$options['search'] = GETPOST('search_keyword', 'alpha'); +$dolistore = new Dolistore($options); + + if (! $user->admin) accessforbidden(); @@ -240,6 +252,11 @@ if ($action == 'reset' && $user->admin) * View */ +$form = new Form($db); + +$morejs = array("/admin/dolistore/js/dolistore.js.php"); +$morecss = array("/admin/dolistore/css/dolistore.css"); + // Set dir where external modules are installed if (! dol_is_dir($dirins)) { @@ -247,10 +264,8 @@ if (! dol_is_dir($dirins)) } $dirins_ok=(dol_is_dir($dirins)); -$form = new Form($db); - $help_url='EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones'; -llxHeader('',$langs->trans("Setup"),$help_url); +llxHeader('',$langs->trans("Setup"),$help_url, '', '', '', $morejs, $morecss, 0, 0); $arrayofnatures=array('core'=>$langs->transnoentitiesnoconv("Core"), 'external'=>$langs->transnoentitiesnoconv("External").' - '.$langs->trans("AllPublishers")); $arrayofwarnings=array(); // Array of warning each module want to show when activated @@ -423,24 +438,9 @@ print load_fiche_titre($langs->trans("ModulesSetup"),$moreinfo,'title_setup'); if ($mode=='common') print ''.$langs->trans("ModulesDesc")."
      \n"; if ($mode=='marketplace') print ''.$langs->trans("ModulesMarketPlaceDesc")."
      \n"; if ($mode=='deploy') print ''.$langs->trans("ModulesDeployDesc", $langs->transnoentitiesnoconv("AvailableModules"))."
      \n"; +if ($mode=='develop') print ''.$langs->trans("ModulesDevelopDesc")."
      \n"; - -$h = 0; - -$head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=common"; -$head[$h][1] = $langs->trans("AvailableModules"); -$head[$h][2] = 'common'; -$h++; - -$head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=marketplace"; -$head[$h][1] = $langs->trans("ModulesMarketPlaces"); -$head[$h][2] = 'marketplace'; -$h++; - -$head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=deploy"; -$head[$h][1] = $langs->trans("AddExtensionThemeModuleOrOther"); -$head[$h][2] = 'deploy'; -$h++; +$head = modules_prepare_head(); print "
      \n"; @@ -817,7 +817,6 @@ if ($mode == 'marketplace') print ''.$langs->trans("URL").''; print ''; - print "\n"; $url='https://www.dolistore.com'; print ''; @@ -825,17 +824,57 @@ if ($mode == 'marketplace') print ''.$url.''; print ''; - - print "\n"; - $url='https://partners.dolibarr.org'; - print ''; - print ''.$langs->trans("DoliPartnersDesc").''; - print ''.$url.''; - print ''; - print "\n"; dol_fiche_end(); + + print '
      '; + + if ($conf->global->MAIN_FEATURES_LEVEL >= 1) + { + print ''.$langs->trans('DOLISTOREdescriptionLong').''; + + + ?> +

      + +
      +
      + +
      trans('Mot-cle') ?>: +
      +
      +


      +
      +
      +
      +
        + get_categories(); ?> +
      +
      +
      + + + + + + + + get_products($categorie); ?> + + + + + + +
      get_previous_link() ?> get_next_link() ?> trans('AchatTelechargement') ?>
      get_previous_link() ?> get_next_link() ?> trans('AchatTelechargement') ?>
      +
      + + \n"; + print "\n"; + //print ''.$langs->trans("Logo").''; + print ''.$langs->trans("DevelopYourModuleDesc").''; + print ''.$langs->trans("URL").''; + print ''; + + print "\n"; + $url='https://partners.dolibarr.org'; + print ''; + print ''.$langs->trans("DoliPartnersDesc").''; + print ''.$url.''; + print ''; + + print "\n"; + + dol_fiche_end(); +} + + + llxFooter(); $db->close(); diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 77c24ff4109..15a17feaea8 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -579,6 +579,9 @@ class Conf $conf->global->AGENDA_DEFAULT_FILTER_TYPE='0'; // 'AC_NON_AUTO' does not exists when AGENDA_DEFAULT_FILTER_TYPE is not on. } + $conf->global->MAIN_MODULE_DOLISTORE_API_SRV='https://www.dolistore.com'; + $conf->global->MAIN_MODULE_DOLISTORE_API_KEY='dolistorecatalogpublickey1234567'; + // For backward compatibility if (isset($this->product)) $this->produit=$this->product; if (isset($this->facture)) $this->invoice=$this->facture; diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 2f604a5c702..d2c466287ff 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -532,6 +532,43 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not } + + +/** + * Prepare array with list of tabs + * + * @return array Array of tabs to show + */ +function modules_prepare_head() +{ + global $langs, $conf, $user; + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=common"; + $head[$h][1] = $langs->trans("AvailableModules"); + $head[$h][2] = 'common'; + $h++; + + $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=marketplace"; + $head[$h][1] = $langs->trans("ModulesMarketPlaces"); + $head[$h][2] = 'marketplace'; + $h++; + + $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=deploy"; + $head[$h][1] = $langs->trans("AddExtensionThemeModuleOrOther"); + $head[$h][2] = 'deploy'; + $h++; + + $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=develop"; + $head[$h][1] = $langs->trans("ModulesDevelopYourModule"); + $head[$h][2] = 'develop'; + $h++; + + return $head; +} + + /** * Prepare array with list of tabs * @@ -564,7 +601,7 @@ function security_prepare_head() $head[$h][2] = 'filedownload'; $h++; */ - + $head[$h][0] = DOL_URL_ROOT."/admin/proxy.php"; $head[$h][1] = $langs->trans("ExternalAccess"); $head[$h][2] = 'proxy'; diff --git a/htdocs/dolistore/core/modules/modDolistore.class.php b/htdocs/dolistore/core/modules/modDolistore.class.php deleted file mode 100644 index a582b93a038..00000000000 --- a/htdocs/dolistore/core/modules/modDolistore.class.php +++ /dev/null @@ -1,159 +0,0 @@ -. - * - * 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 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * 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 . - * - * - * Classe de description et activation du module DOLISTORE - */ - - -include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; - -class modDolistore extends DolibarrModules -{ - - /** - * Constructor. Define names, constants, directories, boxes, permissions - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - global $conf, $langs; - - $this->db = $db; - $this->numero = 66666; - - - // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) - $this->name = /* $langs->trans( */preg_replace('/^mod/i', '', get_class($this))/* ) */; - - $this->boxes = array(); - - - $this->description = $langs->trans("DOLISTOREdescription"); - - $this->descriptionlong = $langs->trans("DOLISTOREdescriptionLong"); - - $this->family = "interface"; - - $this->module_position = 1; - $this->version = 'dolibarr'; - $this->picto = 'dolistore@dolistore'; - $this->special=1; - $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); - - // Data directories to create when module is enabled - $this->dirs = array(); - - // Dependances - $this->depends = array(); - $this->requiredby = array(); - $this->langfiles = array('dolistore@dolistore'); - - // Config pages - //$this->config_page_url = array("index.php?page=config@dolistore"); - - - - $this->module_parts = array( - 'triggers' => 0, - // Set this to 1 if module overwrite template dir (core/tpl) - 'tpl' => 0, - ); - - - - - - // Main menu entries - $r = 0; - - $this->menu[$r] = array( - //'fk_menu' => -1, // Put 0 if this is a top menu - 'fk_menu' => 'fk_mainmenu=home,fk_leftmenu=setup', - 'type' => 'left', // This is a left menu entry - 'titre' => 'DOLISTOREMENU', - 'mainmenu' => 'home', - 'leftmenu' => 'setup', - 'url' => '/dolistore/index.php?mainmenu=home&leftmenu=setup', - 'langs' => 'dolistore@dolistore', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - 'position' => 1, - 'enabled' => '$leftmenu=="setup" && $conf->dolistore->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. - //'perms' => '$user->rights->edi->message->view', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - 'perms' => '', - 'target' => '', - 'user' => 0); // 0=Menu for internal users, 1=external users, 2=both - - $r++; - - // Constantes - $this->const = array(); - - - $r = 0; - $this->const[$r][0] = 'MAIN_MODULE_'.strtoupper($this->name).'_API_SRV'; - $this->const[$r][1] = "chaine"; - $this->const[$r][2] = "https://www.dolistore.com"; - $this->const[$r][3] = "Server URL"; - $this->const[$r][4] = 0; - $this->const[$r][5] = 1; // supprime la constante à la désactivation du module - $r++; - - $this->const[$r][0] = 'MAIN_MODULE_'.strtoupper($this->name).'_API_KEY'; - $this->const[$r][1] = "chaine"; - $this->const[$r][2] = "dolistorecatalogpublickey1234567"; - $this->const[$r][3] = "API key to authenticate"; - $this->const[$r][4] = 0; - $this->const[$r][5] = 1; // supprime la constante à la désactivation du module - $r++; - - } - - /** - * Function called when module is enabled. - * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. - * It also creates data directories - * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO - */ - function init($options = '') - { - global $conf; - - $this->remove($options); - - $sql = array(); - - return $this->_init($sql, $options); - } - - /** - * Function called when module is disabled. - * Remove from database constants, boxes and permissions from Dolibarr database. - * Data directories are not deleted - * - * @param string $options Options when enabling module ('', 'noboxes') - * @return int 1 if OK, 0 if KO - */ - function remove($options = '') - { - $sql = array(); - - return $this->_remove($sql, $options); - } -} \ No newline at end of file diff --git a/htdocs/dolistore/index.php b/htdocs/dolistore/index.php deleted file mode 100644 index 1295801b436..00000000000 --- a/htdocs/dolistore/index.php +++ /dev/null @@ -1,115 +0,0 @@ -. - * - * This program is free software; you can redistribute it and/or modifyion 2.0 (the "License"); - * it under the terms of the GNU General Public License as published bypliance with the License. - * the Free Software Foundation; either version 3 of the License, or - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * 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 . - * or see http://www.gnu.org/ - */ - -if (!defined('REQUIRE_JQUERY_BLOCKUI')) define('REQUIRE_JQUERY_BLOCKUI', 1); -/** - * \file htdocs/commande/info.php - * \ingroup commande - * \brief Page des informations d'une commande - */ -$res = 0; -if (!$res && file_exists("../main.inc.php")) $res = @include("../main.inc.php"); -if (!$res && file_exists("../../main.inc.php")) $res = @include("../../main.inc.php"); -if (!$res && file_exists("../../../main.inc.php")) $res = @include("../../../main.inc.php"); -if (!$res && file_exists("../../../../main.inc.php")) $res = @include("../../../../main.inc.php"); -if (!$res && file_exists("../../../dolibarr/htdocs/main.inc.php")) - $res = @include("../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only -if (!$res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) - $res = @include("../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only -if (!$res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) - $res = @include("../../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only -if (!$res) die("Include of main fails"); - -// CORE - -global $lang, $user, $conf; - - -dol_include_once('/dolistore/class/dolistore.class.php'); -$options = array(); -$options['per_page'] = 20; -$options['categorie'] = GETPOST('categorie', 'int') + 0; -$options['start'] = GETPOST('start', 'int') + 0; -$options['end'] = GETPOST('end', 'int') + 0; -$options['search'] = GETPOST('search_keyword', 'alpha'); -$dolistore = new Dolistore($options); -/* - * View - */ - -/* * ************************************************* - * VIEW - * - * Put here all code to build page - * ************************************************** */ - -// llxHeader('', iconv(iconv_get_encoding($langs->trans($lbl_folder)), $character_set_client . "//TRANSLIT", $langs->trans($lbl_folder)) . ' (' . $info->Nmsgs . ') ', ''); - -$morejs = array("/dolistore/js/dolistore.js.php", - "/dolistore/js/fancybox/jquery.fancybox.pack.js", - "/dolistore/js/fancybox/helpers/jquery.fancybox-thumbs.js"); -$morecss = array("/dolistore/css/dolistore.css", - "/dolistore/js/fancybox/jquery.fancybox.css", - "/dolistore/js/fancybox/helpers/jquery.fancybox-thumbs.css"); -llxHeader('', $langs->trans('DOLISTOREMENU'), '', '', '', '', $morejs, $morecss, 0, 0); -?>
      - - -
      - - -
      trans('Extensions disponibles sur le Dolistore') ?>
      -
      - trans('DOLISTOREdescriptionLong') ?>

      - -
      -
      -
      trans('Mot-cle') ?>: -
      -
      -


      -
      -
      -
      -
        - get_categories(); ?> -
      -
      -
      - - - - - - - - get_products($categorie); ?> - - - - - - -
      get_previous_link() ?> get_next_link() ?> trans('AchatTelechargement') ?>
      get_previous_link() ?> get_next_link() ?> trans('AchatTelechargement') ?>
      -
      -
      -. - * - * This program is free software; you can redistribute it and/or modifyion 2.0 (the "License"); - * it under the terms of the GNU General Public License as published bypliance with the License. - * the Free Software Foundation; either version 3 of the License, or - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * 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 . - * or see http://www.gnu.org/ - */ -$res = 0; -if (!$res && file_exists("../main.inc.php")) $res = @include("../main.inc.php"); -if (!$res && file_exists("../../main.inc.php")) $res = @include("../../main.inc.php"); -if (!$res && file_exists("../../../main.inc.php")) $res = @include("../../../main.inc.php"); -if (!$res && file_exists("../../../../main.inc.php")) $res = @include("../../../../main.inc.php"); -if (!$res && file_exists("../../../dolibarr/htdocs/main.inc.php")) - $res = @include("../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only -if (!$res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) - $res = @include("../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only -if (!$res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) - $res = @include("../../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only -if (!$res) die("Include of main fails"); - -global $langs; - -ob_start(); -?>