diff --git a/ChangeLog b/ChangeLog index ec9b5d50ba0..06310ddce07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,7 @@ Following changes may create regression for some external modules, but were nece Dolibarr better: - Function log() of class CommandeFournisseur has been removed. Using it is no more required. - Method select_type_comptes_financiers() has been renamed into selectTypeOfBankAccount() +- Property ->client that was deprecated 6 years ago, is replaced in all core code with ->thirdparty. - File '/core/tpl/document_actions_pre_headers.tpl.php' were renamed into '/core/actions_linkedfiles.inc.php'. So if you included it into your module, change your code like this to be compatible with all version: $res=@include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php'; diff --git a/dev/skeletons/skeleton_class.class.php b/dev/skeletons/skeleton_class.class.php index 2e737b8e87f..2858e791ce8 100644 --- a/dev/skeletons/skeleton_class.class.php +++ b/dev/skeletons/skeleton_class.class.php @@ -71,7 +71,6 @@ class Skeleton_Class extends CommonObject public function __construct(DoliDB $db) { $this->db = $db; - return 1; } /** @@ -249,7 +248,7 @@ class Skeleton_Class extends CommonObject $line->prop1 = $obj->field1; $line->prop2 = $obj->field2; - $this->lines[] = $line; + $this->lines[$line->id] = $line; //... } $this->db->free($resql); diff --git a/htdocs/accountancy/admin/export.php b/htdocs/accountancy/admin/export.php index 1a32c22e12f..7b4ca7f91ce 100644 --- a/htdocs/accountancy/admin/export.php +++ b/htdocs/accountancy/admin/export.php @@ -21,9 +21,9 @@ */ /** - * \file htdocs/accountancy/admin/export.php - * \ingroup Accounting Expert - * \brief Setup page to configure accounting expert module + * \file htdocs/accountancy/admin/export.php + * \ingroup Advanced accountancy + * \brief Setup page to configure accounting expert module */ require '../../main.inc.php'; diff --git a/htdocs/accountancy/admin/importaccounts.php b/htdocs/accountancy/admin/importaccounts.php index 15bd063bf9c..0dc560aa62e 100644 --- a/htdocs/accountancy/admin/importaccounts.php +++ b/htdocs/accountancy/admin/importaccounts.php @@ -19,9 +19,9 @@ */ /** - * \file htdocs/accountancy/admin/importaccounts.php - * \ingroup Accounting Expert - * \brief Page import accounting account + * \file htdocs/accountancy/admin/importaccounts.php + * \ingroup Advanced accountancy + * \brief Page import accounting account */ require '../../main.inc.php'; diff --git a/htdocs/accountancy/admin/index.php b/htdocs/accountancy/admin/index.php index 6a63ad433cb..c9041e2a848 100644 --- a/htdocs/accountancy/admin/index.php +++ b/htdocs/accountancy/admin/index.php @@ -1,7 +1,7 @@ * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2013-2015 Alexandre Spangaro + * Copyright (C) 2013-2016 Alexandre Spangaro * Copyright (C) 2014-2015 Ari Elbaz (elarifr) * Copyright (C) 2014 Marcos García * Copyright (C) 2014 Juanjo Menent @@ -23,9 +23,9 @@ */ /** - * \file htdocs/accountancy/admin/index.php - * \ingroup Accounting Expert - * \brief Setup page to configure accounting expert module + * \file htdocs/accountancy/admin/index.php + * \ingroup Advanced accountancy + * \brief Setup page to configure accounting expert module */ require '../../main.inc.php'; @@ -38,6 +38,7 @@ $langs->load("compta"); $langs->load("bills"); $langs->load("admin"); $langs->load("accountancy"); +$langs->load("salaries"); // Security check if (! $user->admin) @@ -45,7 +46,7 @@ if (! $user->admin) $action = GETPOST('action', 'alpha'); -// Other parameters ACCOUNTING_* +// Parameters ACCOUNTING_* and others $list = array ( 'ACCOUNTING_LIMIT_LIST_VENTILATION', 'ACCOUNTING_LENGTH_DESCRIPTION', // adjust size displayed for lines description for dol_trunc @@ -63,8 +64,11 @@ $list_account = array ( 'ACCOUNTING_SERVICE_SOLD_ACCOUNT', 'ACCOUNTING_VAT_BUY_ACCOUNT', 'ACCOUNTING_VAT_SOLD_ACCOUNT', + 'ACCOUNTING_VAT_PAY_ACCOUNT', 'ACCOUNTING_ACCOUNT_SUSPENSE', - 'ACCOUNTING_ACCOUNT_TRANSFER_CASH' + 'ACCOUNTING_ACCOUNT_TRANSFER_CASH', + 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', + 'DONATION_ACCOUNTINGACCOUNT' ); /* diff --git a/htdocs/accountancy/admin/journal.php b/htdocs/accountancy/admin/journal.php index e1b76273193..ca4ab67aee8 100644 --- a/htdocs/accountancy/admin/journal.php +++ b/htdocs/accountancy/admin/journal.php @@ -22,9 +22,9 @@ */ /** - * \file htdocs/accountancy/admin/journal.php - * \ingroup Accounting Expert - * \brief Setup page to configure accounting expert module + * \file htdocs/accountancy/admin/journal.php + * \ingroup Advanced accountancy + * \brief Setup page to configure accounting expert module */ require '../../main.inc.php'; diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php index b7d563c9621..d6f21960a49 100644 --- a/htdocs/accountancy/admin/productaccount.php +++ b/htdocs/accountancy/admin/productaccount.php @@ -20,9 +20,9 @@ */ /** - * \file htdocs/accountancy/admin/productaccount.php - * \ingroup Accounting Expert - * \brief To define accounting account on product / service + * \file htdocs/accountancy/admin/productaccount.php + * \ingroup Advanced accountancy + * \brief To define accounting account on product / service */ require '../../main.inc.php'; @@ -184,7 +184,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both * View */ -llxHeader('', $langs->trans("Accounts")); +llxHeader('', $langs->trans("InitAccountancy")); print ''."\n"; @@ -1131,8 +1126,8 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs else print ''."\n"; print ''."\n"; print ''."\n"; - // jQuery Layout - if (empty($conf->dol_use_jmobile) && ! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) || defined('REQUIRE_JQUERY_LAYOUT')) + // jQuery Layout (still used by ECM module) + if (defined('REQUIRE_JQUERY_LAYOUT')) { print ''."\n"; } @@ -1374,60 +1369,6 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a if ($conf->use_javascript_ajax) { - if (empty($conf->dol_use_jmobile) && ! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) - { - print '' . "\n"; - } - // Raven.js for client-side Sentry logging support if (array_key_exists('mod_syslog_sentry', $conf->loghandlers) && ! empty($conf->global->SYSLOG_SENTRY_DSN)) { @@ -1448,8 +1389,6 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a */ print "\n".''."\n"; - if (empty($conf->dol_use_jmobile) && ! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) print '
'."\n"; - if (empty($conf->dol_hide_topmenu)) { print '
'; @@ -1579,11 +1518,10 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a //unset($form); } - if (empty($conf->dol_use_jmobile) && ! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) print "
\n"; print '
'; print "\n\n"; - if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile) && empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) print '
'; + if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) print '
'; } @@ -1616,8 +1554,7 @@ function left_menu($menu_array_before, $helppagename='', $notused='', $menu_arra // Instantiate hooks of thirdparty module $hookmanager->initHooks(array('searchform','leftblock')); - if (empty($conf->dol_use_jmobile) && ! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) print "\n".''."\n".'
'."\n"; - else print "\n".''."\n".'
'."\n"; + print "\n".''."\n".'
'."\n"; print "\n"; @@ -1779,8 +1716,7 @@ function left_menu($menu_array_before, $helppagename='', $notused='', $menu_arra $reshook=$hookmanager->executeHooks('printLeftBlock',$parameters); // Note that $action and $object may have been modified by some hooks print $hookmanager->resPrint; - if (empty($conf->dol_use_jmobile) && ! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) print '
'."\n"; - else print '
'; // End div id="id-left" + print '
'; // End div id="id-left" } print "\n"; @@ -1800,7 +1736,6 @@ function main_area($title='') { global $conf, $langs; - if (empty($conf->dol_use_jmobile) && ! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) print '
'."\n"; if (empty($conf->dol_hide_leftmenu)) print '
'; print "\n"; @@ -1944,7 +1879,6 @@ if (! function_exists("llxFooter")) print '
'."\n"; if (! empty($conf->dol_use_jmobile)) print '
'; // end data-role="page" - if (empty($conf->dol_use_jmobile) && ! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) print '
'."\n"; if (empty($conf->dol_hide_leftmenu)) print '
'; // End div id-right print "\n"; @@ -1953,7 +1887,7 @@ if (! function_exists("llxFooter")) printCommonFooter($zone); //var_dump($langs); // Uncommment to see the property _tab_loaded to see which language file were loaded - if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile) && empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) print '
'."\n"; // End div container + if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) print '
'."\n"; // End div container if (! empty($delayedhtmlcontent)) print $delayedhtmlcontent; diff --git a/htdocs/margin/admin/margin.php b/htdocs/margin/admin/margin.php index 6e84b13e286..3a61ee0e72e 100644 --- a/htdocs/margin/admin/margin.php +++ b/htdocs/margin/admin/margin.php @@ -236,6 +236,12 @@ print ''.$langs->trans('ForceBuyingPriceIfNullDetails').''; print ''; // GLOBAL DISCOUNT MANAGEMENT +$methods = array( + 1 => $langs->trans('UseDiscountAsProduct'), + 2 => $langs->trans('UseDiscountAsService'), + 3 => $langs->trans('UseDiscountOnTotal') +); + $var=!$var; print '
'; print ''; @@ -243,20 +249,7 @@ print ""; print ''; print ''.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").''; print ''; -print ''; +print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, $conf->global->MARGIN_METHODE_FOR_DISCOUNT); print ''; print ''; print ''; diff --git a/htdocs/margin/lib/margins.lib.php b/htdocs/margin/lib/margins.lib.php index 6687b9fcf59..84d7945ec0d 100644 --- a/htdocs/margin/lib/margins.lib.php +++ b/htdocs/margin/lib/margins.lib.php @@ -118,7 +118,7 @@ function getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localta $marge_tx_ret=''; $marque_tx_ret=''; - if ($fk_pa > 0) { + if ($fk_pa > 0 && empty($paht)) { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; $product = new ProductFournisseur($db); if ($product->fetch_product_fournisseur_price($fk_pa)) diff --git a/htdocs/multicurrency/class/multicurrency.class.php b/htdocs/multicurrency/class/multicurrency.class.php index 36c392b5930..b4baa550ce7 100644 --- a/htdocs/multicurrency/class/multicurrency.class.php +++ b/htdocs/multicurrency/class/multicurrency.class.php @@ -505,7 +505,9 @@ class MultiCurrency extends CommonObject { $sql = 'SELECT m.rowid, mc.rate FROM '.MAIN_DB_PREFIX.'multicurrency m'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'multicurrency_rate mc ON (m.rowid = mc.fk_multicurrency)'; + // FIXME Is this comptible with SQL ? $sql.= ' WHERE m.code = "'.$db->escape($code).'" AND mc.date_sync >= ALL (SELECT date_sync FROM '.MAIN_DB_PREFIX.'multicurrency_rate)'; + $sql.= " AND m.entity IN '".getEntity('multicurrency', 1)."'"; $resql = $db->query($sql); if ($resql && $obj = $db->fetch_object($resql)) return array($obj->rowid, $obj->rate); else return array(0, 1); diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php index c17fdb65aea..05efcc24a0e 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -183,7 +183,7 @@ if (! empty($action) && $action == 'fetch' && ! empty($id)) if (empty($mode) || $mode == 1) { $arrayresult = $form->select_produits_list("", $htmlname, $type, "", $price_level, $searchkey, $status, $finished, $outjson, $socid); } elseif ($mode == 2) { - $arrayresult = $form->select_produits_fournisseurs_list($socid, "", $htmlname, $type, "", $searchkey, $status, $outjson, $socid); + $arrayresult = $form->select_produits_fournisseurs_list($socid, "", $htmlname, $type, "", $searchkey, $status, $outjson); } $db->close(); diff --git a/htdocs/product/card.php b/htdocs/product/card.php index ef126a85b52..0307c4aed5e 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -44,7 +44,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.php'; @@ -152,7 +151,7 @@ if (empty($reshook)) $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 499fd8c3694..819a5438eda 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -97,6 +97,8 @@ class Product extends CommonObject var $prices_by_qty=array(); var $prices_by_qty_id=array(); var $prices_by_qty_list=array(); + //! Default VAT code for product (link to code into llx_c_tva but without foreign keys) + var $default_vat_code; //! Default VAT rate of product var $tva_tx; //! French VAT NPR (0 or 1) @@ -702,6 +704,7 @@ class Product extends CommonObject $sql.= " SET label = '" . $this->db->escape($this->label) ."'"; $sql.= ", ref = '" . $this->db->escape($this->ref) ."'"; $sql.= ", ref_ext = ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null"); + $sql.= ", default_vat_code = ".($this->default_vat_code ? "'".$this->db->escape($this->default_vat_code)."'" : "null"); $sql.= ", tva_tx = " . $this->tva_tx; $sql.= ", recuperableonly = " . $this->tva_npr; $sql.= ", localtax1_tx = " . $this->localtax1_tx; @@ -824,12 +827,14 @@ class Product extends CommonObject { if (empty($conf->barcode->enabled)) $this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref); else $this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductBarCodeAlreadyExists",$this->barcode); + $this->errors[]=$this->error; $this->db->rollback(); return -1; } else { $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; + $this->errors[]=$this->error; $this->db->rollback(); return -2; } @@ -1390,27 +1395,28 @@ class Product extends CommonObject /** - * Modify price of a product/Service + * Modify customer price of a product/Service * - * @param double $newprice New price - * @param string $newpricebase HT or TTC - * @param User $user Object user that make change - * @param double $newvat New VAT Rate (For example 8.5. Should not be a string) - * @param double $newminprice New price min - * @param int $level 0=standard, >0 = level if multilevel prices - * @param int $newnpr 0=Standard vat rate, 1=Special vat rate for French NPR VAT - * @param int $newpsq 1 if it has price by quantity - * @param int $ignore_autogen Used to avoid infinite loops + * @param double $newprice New price + * @param string $newpricebase HT or TTC + * @param User $user Object user that make change + * @param double $newvat New VAT Rate (For example 8.5. Should not be a string) + * @param double $newminprice New price min + * @param int $level 0=standard, >0 = level if multilevel prices + * @param int $newnpr 0=Standard vat rate, 1=Special vat rate for French NPR VAT + * @param int $newpsq 1 if it has price by quantity + * @param int $ignore_autogen Used to avoid infinite loops * @param array $localtaxes_array Array with localtaxes info array('0'=>type1,'1'=>rate1,'2'=>type2,'3'=>rate2) (loaded by getLocalTaxesFromRate(vatrate, 0, ...) function). + * @param string $newdefaultvatcode Default vat code * @return int <0 if KO, >0 if OK */ - function updatePrice($newprice, $newpricebase, $user, $newvat='',$newminprice='', $level=0, $newnpr=0, $newpsq=0, $ignore_autogen=0, $localtaxes_array=array()) + function updatePrice($newprice, $newpricebase, $user, $newvat='',$newminprice='', $level=0, $newnpr=0, $newpsq=0, $ignore_autogen=0, $localtaxes_array=array(), $newdefaultvatcode='') { global $conf,$langs; $id=$this->id; - dol_syslog(get_class($this)."::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr); + dol_syslog(get_class($this)."::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr," newdefaultvatcode=".$newdefaultvatcode); // Clean parameters if (empty($this->tva_tx)) $this->tva_tx=0; @@ -1504,6 +1510,7 @@ class Product extends CommonObject $sql.= " localtax2_tx=".($localtax2>=0?$localtax2:'NULL').","; $sql.= " localtax1_type=".($localtaxtype1!=''?"'".$localtaxtype1."'":"'0'").","; $sql.= " localtax2_type=".($localtaxtype2!=''?"'".$localtaxtype2."'":"'0'").","; + $sql.= " default_vat_code=".($newdefaultvatcode?"'".$this->db->escape($newdefaultvatcode)."'":"null").","; $sql.= " tva_tx='".price2num($newvat)."',"; $sql.= " recuperableonly='".$newnpr."'"; $sql.= " WHERE rowid = ".$id; @@ -1517,6 +1524,7 @@ class Product extends CommonObject $this->multiprices_min[$level]= $price_min; $this->multiprices_min_ttc[$level]= $price_min_ttc; $this->multiprices_base_type[$level]= $newpricebase; + $this->multiprices_default_vat_code[$level]= $newdefaultvatcode; $this->multiprices_tva_tx[$level]= $newvat; $this->multiprices_recuperableonly[$level]= $newnpr; @@ -1525,6 +1533,7 @@ class Product extends CommonObject $this->price_min = $price_min; $this->price_min_ttc = $price_min_ttc; $this->price_base_type = $newpricebase; + $this->default_vat_code = $newdefaultvatcode; $this->tva_tx = $newvat; $this->tva_npr = $newnpr; //Local taxes @@ -1603,7 +1612,7 @@ class Product extends CommonObject } $sql = "SELECT rowid, ref, ref_ext, label, description, url, note, customcode, fk_country, price, price_ttc,"; - $sql.= " price_min, price_min_ttc, price_base_type, cost_price, tva_tx, recuperableonly as tva_npr, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, tosell,"; + $sql.= " price_min, price_min_ttc, price_base_type, cost_price, default_vat_code, tva_tx, recuperableonly as tva_npr, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, tosell,"; $sql.= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas,"; $sql.= " weight, weight_units, length, length_units, surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,"; $sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,"; @@ -1647,6 +1656,7 @@ class Product extends CommonObject $this->price_min_ttc = $obj->price_min_ttc; $this->price_base_type = $obj->price_base_type; $this->cost_price = $obj->cost_price; + $this->default_vat_code = $obj->default_vat_code; $this->tva_tx = $obj->tva_tx; //! French VAT NPR $this->tva_npr = $obj->tva_npr; diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php index 9686c4683ae..f4b3f575eba 100644 --- a/htdocs/product/composition/card.php +++ b/htdocs/product/composition/card.php @@ -361,7 +361,7 @@ if ($id > 0 || ! empty($ref)) } print ''; - $totalline=price2num($value['nb'] * $product_fourn->fourn_unitprice, 'MT'); + $totalline=price2num($value['nb'] * ($product_fourn->fourn_unitprice * (1 - $product_fourn->fourn_remise_percent/100) + $product_fourn->fourn_unitcharges - $product_fourn->fourn_remise), 'MT'); $total+=$totalline; print ''; print ($notdefined?'':($value['nb']> 1 ? $value['nb'].'x' : '').price($product_fourn->fourn_unitprice,'','',0,0,-1,$conf->currency)); diff --git a/htdocs/product/document.php b/htdocs/product/document.php index facff9f9a52..ca207f8429f 100644 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -262,43 +262,11 @@ if ($object->id) print ''; - $delauft_lang = (empty($lang_id)) ? $langs->getDefaultLang() : $lang_id; + $delauft_lang = empty($lang_id) ? $langs->getDefaultLang() : $lang_id; $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12); - print ''; + print Form::selectarray('lang_id', $langs_available, $delauft_lang, 0, 0, 0, '', 0, 0, 0, 'ASC'); if ($conf->global->MAIN_MULTILANGS) { print ''; diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 857a6634bf6..5b024391b20 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -94,11 +94,10 @@ if (empty($reshook)) if (($action == 'update_vat') && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) { - $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 - - $tva_tx_txt; - + $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)' + // We must define tva_tx, npr and local taxes + $vatratecode = ''; $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; @@ -116,33 +115,37 @@ if (empty($reshook)) $resql=$db->query($sql); if ($resql) { - $obj = $db->fetch_object($resql); - $npr = $obj->recuperableonly; - $localtax1 = $obj->localtax1; - $localtax2 = $obj->localtax2; - $localtax1_type = $obj->localtax1_type; - $localtax2_type = $obj->localtax2_type; + $obj = $db->fetch_object($resql); + $npr = $obj->recuperableonly; + $localtax1 = $obj->localtax1; + $localtax2 = $obj->localtax2; + $localtax1_type = $obj->localtax1_type; + $localtax2_type = $obj->localtax2_type; } } - + + $object->default_vat_code = $vatratecode; $object->tva_tx = $tva_tx; $object->tva_npr = $npr; $object->localtax1_tx = $localtax1; $object->localtax2_tx = $localtax2; $object->localtax1_type = $localtax1_type; $object->localtax2_type = $localtax2_type; - + $db->begin(); - + $resql = $object->update($object->id, $user); if (! $resql) { $error++; + setEventMessages($object->error, $object->errors, 'errors'); } if ($error) { - $object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq); // FIXME Bug $newvat and $newnpr not defined + //$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2); + $localtaxarray=array(); // We do not store localtaxes into product, we will use instead the "vat code" to retreive them. + $object->updatePrice(0, $object->price_base_type, $user, $tva_tx, '', 0, $npr, 0, 0, $localtaxarray, $vatratecode); } if (! $error) @@ -203,19 +206,44 @@ if (empty($reshook)) } $tva_tx_txt = $newvattx[$i]; - $npr = $newvatnpr[$i]; + + $vatratecode = ''; + $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot + $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = $newlocaltax1_tx[$i]; $localtax1_type = $newlocaltax1_type[$i]; $localtax2 = $newlocaltax2_tx[$i]; $localtax2_type = $newlocaltax2_type[$i]; - + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) + { + // We look into database using code + $vatratecode=$reg[1]; + // Get record from code + $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; + $sql.= " WHERE t.fk_pays = c.rowid AND c.code = '".$mysoc->country_code."'"; + $sql.= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; + $sql.= " AND t.code ='".$vatratecode."'"; + $resql=$db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + $npr = $obj->recuperableonly; + $localtax1 = $obj->localtax1; + $localtax2 = $obj->localtax2; + $localtax1_type = $obj->localtax1_type; + $localtax2_type = $obj->localtax2_type; + } + } + $pricestoupdate[$i] = array( 'price' => $newprice[$i], 'price_min' => $newprice_min[$i], 'price_base_type' => $newpricebase[$i], - 'vat_tx' => $tva_tx, - 'npr' => $npr, - 'localtaxes_array' => array('0'=>$localtax1_type, '1'=>$localtax1, '2'=>$localtax2_type, '3'=>$localtax2) + 'default_vat_code' => $vatratecode, + 'vat_tx' => $tva_tx, // default_vat_code should be used in priority in a future + 'npr' => $npr, // default_vat_code should be used in priority in a future + 'localtaxes_array' => array('0'=>$localtax1_type, '1'=>$localtax1, '2'=>$localtax2_type, '3'=>$localtax2) // default_vat_code should be used in priority in a future ); //If autogeneration is enabled, then we only set the first level @@ -223,9 +251,12 @@ if (empty($reshook)) break; } } - } else { - $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' , '8.5*', '8.5 (8.5NPR) *' for example. + } + elseif (! $error) + { + $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)' + $vatratecode = ''; // We must define tva_tx, npr and local taxes $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; @@ -256,9 +287,10 @@ if (empty($reshook)) 'price' => $_POST["price"], 'price_min' => $_POST["price_min"], 'price_base_type' => $_POST["price_base_type"], - 'vat_tx' => $tva_tx, - 'npr' => $npr, - 'localtaxes_array' => array('0'=>$localtax1_type, '1'=>$localtax1, '2'=>$localtax2_type, '3'=>$localtax2) + 'default_vat_code' => $vatratecode, + 'vat_tx' => $tva_tx, // default_vat_code should be used in priority in a future + 'npr' => $npr, // default_vat_code should be used in priority in a future + 'localtaxes_array' => array('0'=>$localtax1_type, '1'=>$localtax1, '2'=>$localtax2_type, '3'=>$localtax2) // default_vat_code should be used in priority in a future ); } @@ -282,7 +314,7 @@ if (empty($reshook)) break; } - $res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq, 0, $val['localtaxes_array']); + $res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq, 0, $val['localtaxes_array'], $val['default_vat_code']); if ($res < 0) { $error ++; @@ -422,6 +454,7 @@ if (empty($reshook)) $tva_tx_txt = GETPOST("tva_tx"); + $vatratecode = ''; // We must define tva_tx, npr and local taxes $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; @@ -449,6 +482,7 @@ if (empty($reshook)) } } + $prodcustprice->default_vat_code = $vatratecode; $prodcustprice->tva_tx = $tva_tx; $prodcustprice->recuperableonly = $npr; $prodcustprice->localtax1_tx = $localtax1; @@ -463,7 +497,7 @@ if (empty($reshook)) $error++; $action='add_customer_price'; } - if (! empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $prodcustprice->price_min<$maxpricesupplier) + if (! empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $prodcustprice->price_min < $maxpricesupplier) { $langs->load("errors"); setEventMessages($langs->trans("MinimumPriceLimit",price($maxpricesupplier,0,'',1,-1,-1,'auto')), null, 'errors'); @@ -511,9 +545,10 @@ if (empty($reshook)) $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); - + $tva_tx_txt = GETPOST("tva_tx"); - + + $vatratecode=''; // We must define tva_tx, npr and local taxes $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; @@ -541,6 +576,7 @@ if (empty($reshook)) } } + $prodcustprice->default_vat_code = $vatratecode; $prodcustprice->tva_tx = $tva_tx; $prodcustprice->recuperableonly = $npr; $prodcustprice->localtax1_tx = $localtax1; @@ -548,7 +584,7 @@ if (empty($reshook)) $prodcustprice->localtax1_type = $localtax1_type; $prodcustprice->localtax2_type = $localtax2_type; - if ($prodcustprice->price_min<$maxpricesupplier && !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) + if ($prodcustprice->price_min < $maxpricesupplier && !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) { setEventMessages($langs->trans("MinimumPriceLimit",price($maxpricesupplier,0,'',1,-1,-1,'auto')), null, 'errors'); $error++; @@ -640,7 +676,13 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) else { // TVA - print '' . $langs->trans("VATRate") . '' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . ''; + print '' . $langs->trans("VATRate") . ''; + if ($object->default_vat_code) + { + print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; + } + else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true); + print ''; } } @@ -649,17 +691,23 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility { // We show only vat for level 1 - print '' . $langs->trans("VATRate") . '' . vatrate($object->multiprices_tva_tx [1], true) . ''; + print '' . $langs->trans("VATRate") . '' . vatrate($object->multiprices_tva_tx[1], true) . ''; } else { // TVA - print '' . $langs->trans("VATRate") . '' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . ''; + print '' . $langs->trans("VATRate") . ''; + if ($object->default_vat_code) + { + print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; + } + else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true); + print ''; } print ''.$langs->trans("PriceLevel").''.$langs->trans("SellingPrice").''.$langs->trans("MinPrice").''; - for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) + for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { print ''; @@ -771,7 +819,13 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) else { // TVA - print '' . $langs->trans("VATRate") . '' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . ''; + print '' . $langs->trans("VATRate") . ''; + if ($object->default_vat_code) + { + print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; + } + else print vatrate($object->tva_tx, true, $object->tva_npr, true); + print ''; // Price print '' . $langs->trans("SellingPrice") . ''; @@ -933,10 +987,10 @@ if ($action == 'edit_vat' && ($user->rights->produit->creer || $user->rights->se dol_fiche_head(''); print ''; - + // VAT print ''; print '
' . $langs->trans("VATRate") . ''; - print $form->load_tva("tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1); + print $form->load_tva("tva_tx", $object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1); print '
'; @@ -969,7 +1023,7 @@ if ($action == 'edit_price' && $object->getRights()->creer) // VAT print '' . $langs->trans("VATRate") . ''; - print $form->load_tva("tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1); + print $form->load_tva("tva_tx", $object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1); print ''; // Price base @@ -1102,13 +1156,17 @@ if ($action == 'edit_price' && $object->getRights()->creer) } print ''; - print ' - '; - if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { - print ''; - } - print ' - '; + print ''; + + print ''; + + if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) print ''; + else print ''; + + print ''; + + print ''; + if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) { print ''; } @@ -1126,12 +1184,14 @@ if ($action == 'edit_price' && $object->getRights()->creer) // VAT if (empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { - print ''; + print ''; } else { // This option is kept for backward compatibility but has no sense print ''; } diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 5f9fc3eacd6..f5675db86f3 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -221,16 +221,16 @@ class SupplierProposal extends CommonObject $productdesc = $prod->description; - $tva_tx = get_default_tva($mysoc,$this->client,$prod->id); - $tva_npr = get_default_npr($mysoc,$this->client,$prod->id); + $tva_tx = get_default_tva($mysoc,$this->thirdparty,$prod->id); + $tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id); if (empty($tva_tx)) $tva_npr=0; - $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->client,$tva_npr); - $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->client,$tva_npr); + $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->thirdparty,$tva_npr); + $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->thirdparty,$tva_npr); // multiprix - if($conf->global->PRODUIT_MULTIPRICES && $this->client->price_level) + if($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) { - $price = $prod->multiprices[$this->client->price_level]; + $price = $prod->multiprices[$this->thirdparty->price_level]; } else { @@ -1662,7 +1662,7 @@ class SupplierProposal extends CommonObject if (! empty($conf->global->MAIN_MULTILANGS)) { $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $this->client->default_lang); + $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $this->thirdparty->default_lang); $outputlangs->setDefaultLang($newlang); } //$ret=$object->fetch($id); // Reload to get new records @@ -1764,7 +1764,7 @@ class SupplierProposal extends CommonObject $values = array( "'".$this->db->idate($now)."'", $product->fk_product, - $this->client->id, + $this->thirdparty->id, "'".$product->ref_fourn."'", $price, $qty, diff --git a/htdocs/supplier_proposal/note.php b/htdocs/supplier_proposal/note.php index 4e9f3affa50..a3799c0eb29 100644 --- a/htdocs/supplier_proposal/note.php +++ b/htdocs/supplier_proposal/note.php @@ -87,10 +87,10 @@ if ($id > 0 || ! empty($ref)) print ''; // Customer - if ( is_null($object->client) ) + if ( is_null($object->thirdparty) ) $object->fetch_thirdparty(); print ""; - print ''; + print ''; print ''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } - } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } + foreach ($account->getFieldsToShow() as $val) { + if ($val == 'BankCode') { + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $content = $account->cle_rib; } - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''; - print ''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''; - print ''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } - } + print ''; + print ''; + print ''; } print ''; @@ -290,65 +246,28 @@ if ($id && $action == 'edit' && $user->rights->user->user->creer) print ''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } + foreach ($account->getFieldsToShow() as $val) { + if ($val == 'BankCode') { + $name = 'code_banque'; + $size = 8; + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $name = 'code_guichet'; + $size = 8; + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $name = 'number'; + $size = 18; + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $name = 'cle_rib'; + $size = 3; + $content = $account->cle_rib; } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } - } - - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''; - print ''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''; - print ''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } - } + print ''; + print ''; + print ''; } // IBAN diff --git a/htdocs/user/class/api_user.class.php b/htdocs/user/class/api_user.class.php new file mode 100644 index 00000000000..d09785d3ccb --- /dev/null +++ b/htdocs/user/class/api_user.class.php @@ -0,0 +1,208 @@ + + * + * 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 . + */ + +use Luracast\Restler\RestException; + +//require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; + +/** + * API class for user object + * + * @smart-auto-routing false + * @access protected + * @class DolibarrApiAccess {@requires user,external} + * + */ +class UserApi extends DolibarrApi +{ + /** + * + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'login' + ); + + /** + * @var User $user {@type User} + */ + public $useraccount; + + /** + * Constructor + * + * @url user/ + * + */ + function __construct() { + global $db, $conf; + $this->db = $db; + $this->useraccount = new User($this->db); + } + + /** + * Get properties of an user object + * + * Return an array with user informations + * + * @param int $id ID of user + * @return array|mixed data without useless information + * + * @url GET user/{id} + * @throws RestException + */ + function get($id) { + //if (!DolibarrApiAccess::$user->rights->user->user->lire) { + //throw new RestException(401); + //} + + $result = $this->useraccount->fetch($id); + if (!$result) + { + throw new RestException(404, 'User not found'); + } + + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($this->useraccount); + } + + /** + * Create useraccount object from contact + * + * @param int $contactid Id of contact + * @param array $request_data Request datas + * @return int ID of user + * + * @url POST /contact/{contactid}/createUser + */ + function createFromContact($contactid, $request_data = NULL) { + //if (!DolibarrApiAccess::$user->rights->user->user->creer) { + //throw new RestException(401); + //} + + if (!isset($request_data["login"])) + throw new RestException(400, "login field missing"); + if (!isset($request_data["password"])) + throw new RestException(400, "password field missing"); + if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { + throw new RestException(401); + } + $contact = new Contact($this->db); + $contact->fetch($contactid); + if ($contact->id <= 0) { + throw new RestException(404, 'Contact not found'); + } + + if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + // Check mandatory fields + $login = $request_data["login"]; + $password = $request_data["password"]; + $result = $this->useraccount->create_from_contact($contact,$login,$password); + if ($result <= 0) { + throw new RestException(500, "User not created"); + } + // password parameter not used in create_from_contact + $this->useraccount->setPassword($this->useraccount,$password); + return $result; + } + + /** + * Update account + * + * @param int $id Id of account to update + * @param array $request_data Datas + * @return int + * + * @url PUT user/{id} + */ + function put($id, $request_data = NULL) { + //if (!DolibarrApiAccess::$user->rights->user->user->creer) { + //throw new RestException(401); + //} + + $result = $this->useraccount->fetch($id); + if (!$result) + { + throw new RestException(404, 'Account not found'); + } + + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + + foreach ($request_data as $field => $value) + { + $this->useraccount->$field = $value; + } + + if ($this->useraccount->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) + return $this->get($id); + + return false; + } + + /** + * Delete account + * + * @param int $id Account ID + * @return array + * + * @url DELETE user/{id} + */ + function delete($id) { + //if (!DolibarrApiAccess::$user->rights->user->user->supprimer) { + //throw new RestException(401); + //} + $result = $this->useraccount->fetch($id); + if (!$result) + { + throw new RestException(404, 'User not found'); + } + + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + + return $this->useraccount->delete($id); + } + + /** + * Validate fields before create or update object + * + * @param array $data Data to validate + * @return array + * @throws RestException + */ + function _validate($data) { + $account = array(); + foreach (UserApi::$FIELDS as $field) + { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $account[$field] = $data[$field]; + } + return $account; + } +} diff --git a/htdocs/user/class/userbankaccount.class.php b/htdocs/user/class/userbankaccount.class.php index a91d064c7f8..4e88233fe35 100644 --- a/htdocs/user/class/userbankaccount.class.php +++ b/htdocs/user/class/userbankaccount.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2012 Regis Houssin * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2016 Marcos García * * 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 @@ -57,7 +58,7 @@ class UserBankAccount extends Account /** * Create bank information record * - * @param Object $user User + * @param User $user User * @return int <0 if KO, >= 0 if OK */ function create($user='') @@ -177,78 +178,26 @@ class UserBankAccount extends Account } } - /** - * Return RIB - * - * @param boolean $displayriblabel Prepend or Hide Label - * @return string RIB - */ - function getRibLabel($displayriblabel = true) - { - global $langs,$conf; + /** + * Return RIB + * + * @param boolean $displayriblabel Prepend or Hide Label + * @return string RIB + */ + public function getRibLabel($displayriblabel = true) + { + $rib = ''; - if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) - { - if ($this->label && $displayriblabel) $rib = $this->label." : "; + if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) { - // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; + if ($this->label && $displayriblabel) { + $rib = $this->label." : "; } - $fieldlistsarray=explode(' ',$fieldlists); - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->code_banque.' '; - } - } + $rib .= (string) $this; + } - if ($val == 'DeskCode') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->code_guichet.' '; - } - } - - if ($val == 'BankCode') - { - if ($this->useDetailedBBAN() == 2) - { - $rib.=$this->code_banque.' '; - } - } - - if ($val == 'AccountNumber') - { - $rib.=$this->number.' '; - } - - if ($val == 'BankAccountNumberKey') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->cle_rib.' '; - } - } - } - } - else - { - $rib=''; - } - - return $rib; - } + return $rib; + } } diff --git a/htdocs/user/index.php b/htdocs/user/index.php index f4c77644f1f..f7927cee665 100644 --- a/htdocs/user/index.php +++ b/htdocs/user/index.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2016 Marcos García * * 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 @@ -201,7 +202,9 @@ if ($search_login != '') $sql.= natural_search("u.login", $search_login); if ($search_lastname != '') $sql.= natural_search("u.lastname", $search_lastname); if ($search_firstname != '') $sql.= natural_search("u.firstname", $search_firstname); if ($search_gender != '' && $search_gender != '-1') $sql.= " AND u.gender = '".$search_gender."'"; -if ($search_employee >= 0) $sql.= natural_search("u.employee", $search_employee); +if (is_numeric($search_employee) && $search_employee >= 0) { + $sql .= ' AND u.employee = '.(int) $search_employee; +} if ($search_accountancy_code != '') $sql.= natural_search("u.accountancy_code", $search_accountancy_code); if ($search_email != '') $sql.= natural_search("u.email", $search_email); if ($search_statut != '' && $search_statut >= 0) $sql.= " AND (u.statut=".$search_statut.")"; diff --git a/htdocs/webservices/server_actioncomm.php b/htdocs/webservices/server_actioncomm.php index dc07bc156ec..a5df31c2a7e 100644 --- a/htdocs/webservices/server_actioncomm.php +++ b/htdocs/webservices/server_actioncomm.php @@ -459,7 +459,7 @@ function createActionComm($authentication,$actioncomm) $db->begin(); - $result=$newobject->add($fuser); + $result=$newobject->create($fuser); if ($result <= 0) { $error++; diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index 2e3314fff12..43facbb24fa 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -374,7 +374,7 @@ function getProductOrService($authentication,$id='',$ref='',$ref_ext='',$lang='' $product->load_stock(); $dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output); - $pdir = get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos/"; + $pdir = get_exdir($product->id,2,0,0,$product,'product') . $product->ref . "/"; $dir = $dir . '/'. $pdir; if (! empty($product->multilangs[$langs->defaultlang]["label"])) $product->label = $product->multilangs[$langs->defaultlang]["label"]; diff --git a/htdocs/websites/class/website.class.php b/htdocs/websites/class/website.class.php new file mode 100644 index 00000000000..464223a8ed3 --- /dev/null +++ b/htdocs/websites/class/website.class.php @@ -0,0 +1,639 @@ + + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2015 Florian Henry + * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) ---Put here your own copyright and developer email--- + * + * 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 . + */ + +/** + * \file websites/website.class.php + * \ingroup websites + * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) + * Put some comments here + */ + +// Put here all includes required by your class file +require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; + +/** + * Class Website + * + * Put here description of your class + * @see CommonObject + */ +class Website extends CommonObject +{ + /** + * @var string Id to identify managed objects + */ + public $element = 'website'; + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'website'; + + /** + * @var WebsitePage[] Lines of all pages + */ + public $lines = array(); + + /** + */ + + public $entity; + public $ref; + public $description; + public $status; + public $date_creation = ''; + public $date_modification = ''; + public $tms = ''; + + public $records; + + /** + */ + + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct(DoliDB $db) + { + $this->db = $db; + return 1; + } + + /** + * Create object into database + * + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, Id of created object if OK + */ + public function create(User $user, $notrigger = false) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $error = 0; + + // Clean parameters + + if (isset($this->entity)) { + $this->entity = trim($this->entity); + } + if (isset($this->ref)) { + $this->ref = trim($this->ref); + } + if (isset($this->description)) { + $this->description = trim($this->description); + } + if (isset($this->status)) { + $this->status = trim($this->status); + } + + + + // Check parameters + // Put here code to add control on parameters values + + // Insert request + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; + + $sql.= 'entity,'; + $sql.= 'ref,'; + $sql.= 'description,'; + $sql.= 'status,'; + $sql.= 'date_creation,'; + $sql.= 'date_modification'; + + + $sql .= ') VALUES ('; + + $sql .= ' '.(! isset($this->entity)?'NULL':$this->entity).','; + $sql .= ' '.(! isset($this->ref)?'NULL':"'".$this->db->escape($this->ref)."'").','; + $sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").','; + $sql .= ' '.(! isset($this->status)?'NULL':$this->status).','; + $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").','; + $sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_modification)."'"); + + + $sql .= ')'; + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + + if (!$error) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); + + if (!$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action to call a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_CREATE',$user); + //if ($result < 0) $error++; + //// End call triggers + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return $this->id; + } + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @param string $ref Ref + * + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetch($id, $ref = null) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.entity,"; + $sql .= " t.ref,"; + $sql .= " t.description,"; + $sql .= " t.status,"; + $sql .= " t.date_creation,"; + $sql .= " t.date_modification,"; + $sql .= " t.tms"; + + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + if (null !== $ref) { + $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; + } else { + $sql .= ' WHERE t.rowid = ' . $id; + } + + $resql = $this->db->query($sql); + if ($resql) { + $numrows = $this->db->num_rows($resql); + if ($numrows) { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->entity = $obj->entity; + $this->ref = $obj->ref; + $this->description = $obj->description; + $this->status = $obj->status; + $this->date_creation = $this->db->jdate($obj->date_creation); + $this->date_modification = $this->db->jdate($obj->date_modification); + $this->tms = $this->db->jdate($obj->tms); + + + } + $this->db->free($resql); + + if ($numrows) { + return 1; + } else { + return 0; + } + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * + * @return int <0 if KO, >0 if OK + */ + public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.entity,"; + $sql .= " t.ref,"; + $sql .= " t.description,"; + $sql .= " t.status,"; + $sql .= " t.date_creation,"; + $sql .= " t.date_modification,"; + $sql .= " t.tms"; + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; + + // Manage filter + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { + $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } + } + if (count($sqlwhere) > 0) { + $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); + } + + if (!empty($sortfield)) { + $sql .= $this->db->order($sortfield,$sortorder); + } + if (!empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); + } + $this->records = array(); + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + while ($obj = $this->db->fetch_object($resql)) { + $line = new WebsiteLine(); + + $line->id = $obj->rowid; + + $line->entity = $obj->entity; + $line->ref = $obj->ref; + $line->description = $obj->description; + $line->status = $obj->status; + $line->date_creation = $this->db->jdate($obj->date_creation); + $line->date_modification = $this->db->jdate($obj->date_modification); + $line->tms = $this->db->jdate($obj->tms); + + $this->records[$line->id] = $line; + } + $this->db->free($resql); + + return $num; + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + /** + * Update object into database + * + * @param User $user User that modifies + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = false) + { + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + // Clean parameters + + if (isset($this->entity)) { + $this->entity = trim($this->entity); + } + if (isset($this->ref)) { + $this->ref = trim($this->ref); + } + if (isset($this->description)) { + $this->description = trim($this->description); + } + if (isset($this->status)) { + $this->status = trim($this->status); + } + + + + // Check parameters + // Put here code to add a control on parameters values + + // Update request + $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; + + $sql .= ' entity = '.(isset($this->entity)?$this->entity:"null").','; + $sql .= ' ref = '.(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").','; + $sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").','; + $sql .= ' status = '.(isset($this->status)?$this->status:"null").','; + $sql .= ' date_creation = '.(! isset($this->date_creation) || dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').','; + $sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').','; + $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'"); + + + $sql .= ' WHERE rowid=' . $this->id; + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + + if (!$error && !$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return 1; + } + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, >0 if OK + */ + public function delete(User $user, $notrigger = false) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $error = 0; + + $this->db->begin(); + + if (!$error) { + if (!$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_DELETE',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + } + } + + if (!$error) { + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; + $sql .= ' WHERE rowid=' . $this->id; + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return 1; + } + } + + /** + * Load an object from its id and create a new one in database + * + * @param int $fromid Id of object to clone + * + * @return int New id of clone + */ + public function createFromClone($fromid) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + global $user; + $error = 0; + $object = new Website($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + // Reset object + $object->id = 0; + + // Clear fields + // ... + + // Create clone + $result = $object->create($user); + + // Other options + if ($result < 0) { + $error ++; + $this->errors = $object->errors; + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + + // End + if (!$error) { + $this->db->commit(); + + return $object->id; + } else { + $this->db->rollback(); + + return - 1; + } + } + + /** + * Return a link to the user card (with optionaly the picto) + * Use this->id,this->lastname, this->firstname + * + * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) + * @param string $option On what the link point to + * @param integer $notooltip 1=Disable tooltip + * @param int $maxlen Max length of visible user name + * @param string $morecss Add more css on link + * @return string String with URL + */ + function getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='') + { + global $langs, $conf, $db; + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; + + + $result = ''; + $companylink = ''; + + $label = '' . $langs->trans("MyModule") . ''; + $label.= '
'; + $label.= '' . $langs->trans('Ref') . ': ' . $this->ref; + + $link = 'ref . $linkend; + return $result; + } + + /** + * Retourne le libelle du status d'un user (actif, inactif) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of status + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->status,$mode); + } + + /** + * Renvoi le libelle d'un status donne + * + * @param int $status Id status + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of status + */ + function LibStatut($status,$mode=0) + { + global $langs; + + if ($mode == 0) + { + $prefix=''; + if ($status == 1) return $langs->trans('Enabled'); + if ($status == 0) return $langs->trans('Disabled'); + } + if ($mode == 1) + { + if ($status == 1) return $langs->trans('Enabled'); + if ($status == 0) return $langs->trans('Disabled'); + } + if ($mode == 2) + { + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); + if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); + } + if ($mode == 3) + { + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4'); + if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5'); + } + if ($mode == 4) + { + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); + if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); + } + if ($mode == 5) + { + if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); + if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); + } + } + + + /** + * Initialise object with example values + * Id must be 0 if object instance is a specimen + * + * @return void + */ + public function initAsSpecimen() + { + $this->id = 0; + + $this->entity = ''; + $this->ref = ''; + $this->description = ''; + $this->status = ''; + $this->date_creation = ''; + $this->date_modification = ''; + $this->tms = ''; + + + } + +} + +/** + * Class WebsiteLine + */ +class WebsiteLine +{ + /** + * @var int ID + */ + public $id; + /** + * @var mixed Sample line property 1 + */ + + public $entity; + public $ref; + public $description; + public $status; + public $date_creation = ''; + public $date_modification = ''; + public $tms = ''; + + /** + * @var mixed Sample line property 2 + */ + +} diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php new file mode 100644 index 00000000000..88b6cee2401 --- /dev/null +++ b/htdocs/websites/class/websitepage.class.php @@ -0,0 +1,649 @@ + + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2015 Florian Henry + * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) ---Put here your own copyright and developer email--- + * + * 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 . + */ + +/** + * \file websites/websitepage.class.php + * \ingroup websites + * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) + * Put some comments here + */ + +// Put here all includes required by your class file +require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; + +/** + * Class Websitepage + */ +class WebsitePage extends CommonObject +{ + /** + * @var string Id to identify managed objects + */ + public $element = 'websitepage'; + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'website_page'; + + /** + */ + + public $fk_website; + public $pageurl; + public $title; + public $description; + public $keywords; + public $content; + public $status; + public $date_creation; + public $date_modification; + public $tms; + + /** + */ + + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct(DoliDB $db) + { + $this->db = $db; + } + + /** + * Create object into database + * + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, Id of created object if OK + */ + public function create(User $user, $notrigger = false) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $error = 0; + + // Clean parameters + + if (isset($this->fk_website)) { + $this->fk_website = trim($this->fk_website); + } + if (isset($this->pageurl)) { + $this->pageurl = trim($this->pageurl); + } + if (isset($this->title)) { + $this->title = trim($this->title); + } + if (isset($this->description)) { + $this->description = trim($this->description); + } + if (isset($this->keywords)) { + $this->keywords = trim($this->keywords); + } + if (isset($this->content)) { + $this->content = trim($this->content); + } + if (isset($this->status)) { + $this->status = trim($this->status); + } + + + + // Check parameters + // Put here code to add control on parameters values + + // Insert request + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; + + $sql.= 'fk_website,'; + $sql.= 'pageurl,'; + $sql.= 'title,'; + $sql.= 'description,'; + $sql.= 'keywords,'; + $sql.= 'content,'; + $sql.= 'status,'; + $sql.= 'date_creation,'; + $sql.= 'date_modification'; + + + $sql .= ') VALUES ('; + + $sql .= ' '.(! isset($this->fk_website)?'NULL':$this->fk_website).','; + $sql .= ' '.(! isset($this->pageurl)?'NULL':"'".$this->db->escape($this->pageurl)."'").','; + $sql .= ' '.(! isset($this->title)?'NULL':"'".$this->db->escape($this->title)."'").','; + $sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").','; + $sql .= ' '.(! isset($this->keywords)?'NULL':"'".$this->db->escape($this->keywords)."'").','; + $sql .= ' '.(! isset($this->content)?'NULL':"'".$this->db->escape($this->content)."'").','; + $sql .= ' '.(! isset($this->status)?'NULL':$this->status).','; + $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").','; + $sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_modification)."'"); + + + $sql .= ')'; + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + + if (!$error) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); + + if (!$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action to call a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_CREATE',$user); + //if ($result < 0) $error++; + //// End call triggers + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return $this->id; + } + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @param string $website_id Web site page + * @param string $page Page name + * + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetch($id, $website_id = null, $page = null) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.fk_website,"; + $sql .= " t.pageurl,"; + $sql .= " t.title,"; + $sql .= " t.description,"; + $sql .= " t.keywords,"; + $sql .= " t.content,"; + $sql .= " t.status,"; + $sql .= " t.date_creation,"; + $sql .= " t.date_modification,"; + $sql .= " t.tms"; + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + if (null !== $website_id) { + $sql .= ' WHERE t.fk_website = ' . '\'' . $website_id . '\''; + $sql .= ' AND t.pageurl = ' . '\'' . $page . '\''; + } else { + $sql .= ' WHERE t.rowid = ' . $id; + } + + $resql = $this->db->query($sql); + if ($resql) { + $numrows = $this->db->num_rows($resql); + if ($numrows) { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->fk_website = $obj->fk_website; + $this->pageurl = $obj->pageurl; + $this->title = $obj->title; + $this->description = $obj->description; + $this->keywords = $obj->keywords; + $this->content = $obj->content; + $this->status = $obj->status; + $this->date_creation = $this->db->jdate($obj->date_creation); + $this->date_modification = $this->db->jdate($obj->date_modification); + $this->tms = $this->db->jdate($obj->tms); + + + } + $this->db->free($resql); + + if ($numrows) { + return 1; + } else { + return 0; + } + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * + * @return int <0 if KO, >0 if OK + */ + public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.fk_website,"; + $sql .= " t.pageurl,"; + $sql .= " t.title,"; + $sql .= " t.description,"; + $sql .= " t.keywords,"; + $sql .= " t.content,"; + $sql .= " t.status,"; + $sql .= " t.date_creation,"; + $sql .= " t.date_modification,"; + $sql .= " t.tms"; + + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; + + // Manage filter + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { + $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } + } + if (count($sqlwhere) > 0) { + $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); + } + + if (!empty($sortfield)) { + $sql .= $this->db->order($sortfield,$sortorder); + } + if (!empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); + } + $this->lines = array(); + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + while ($obj = $this->db->fetch_object($resql)) { + $line = new WebsitepageLine(); + + $line->id = $obj->rowid; + + $line->fk_website = $obj->fk_website; + $line->pageurl = $obj->pageurl; + $line->title = $obj->title; + $line->description = $obj->description; + $line->keywords = $obj->keywords; + $line->content = $obj->content; + $line->status = $obj->status; + $line->date_creation = $this->db->jdate($obj->date_creation); + $line->date_modification = $this->db->jdate($obj->date_modification); + $line->tms = $this->db->jdate($obj->tms); + + + + $this->lines[$line->id] = $line; + } + $this->db->free($resql); + + return $num; + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + /** + * Update object into database + * + * @param User $user User that modifies + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = false) + { + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + // Clean parameters + + if (isset($this->fk_website)) { + $this->fk_website = trim($this->fk_website); + } + if (isset($this->pageurl)) { + $this->pageurl = trim($this->pageurl); + } + if (isset($this->title)) { + $this->title = trim($this->title); + } + if (isset($this->description)) { + $this->description = trim($this->description); + } + if (isset($this->keywords)) { + $this->keywords = trim($this->keywords); + } + if (isset($this->content)) { + $this->content = trim($this->content); + } + if (isset($this->status)) { + $this->status = trim($this->status); + } + + + + // Check parameters + // Put here code to add a control on parameters values + + // Update request + $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; + + $sql .= ' fk_website = '.(isset($this->fk_website)?$this->fk_website:"null").','; + $sql .= ' pageurl = '.(isset($this->pageurl)?"'".$this->db->escape($this->pageurl)."'":"null").','; + $sql .= ' title = '.(isset($this->title)?"'".$this->db->escape($this->title)."'":"null").','; + $sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").','; + $sql .= ' keywords = '.(isset($this->keywords)?"'".$this->db->escape($this->keywords)."'":"null").','; + $sql .= ' content = '.(isset($this->content)?"'".$this->db->escape($this->content)."'":"null").','; + $sql .= ' status = '.(isset($this->status)?$this->status:"null").','; + $sql .= ' date_creation = '.(! isset($this->date_creation) || dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').','; + $sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').','; + $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'"); + + + $sql .= ' WHERE rowid=' . $this->id; + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + + if (!$error && !$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return 1; + } + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, >0 if OK + */ + public function delete(User $user, $notrigger = false) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $error = 0; + + $this->db->begin(); + + if (!$error) { + if (!$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_DELETE',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + } + } + + if (!$error) { + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; + $sql .= ' WHERE rowid=' . $this->id; + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return 1; + } + } + + /** + * Load an object from its id and create a new one in database + * + * @param int $fromid Id of object to clone + * + * @return int New id of clone + */ + public function createFromClone($fromid) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + global $user; + $error = 0; + $object = new Websitepage($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + // Reset object + $object->id = 0; + + // Clear fields + // ... + + // Create clone + $result = $object->create($user); + + // Other options + if ($result < 0) { + $error ++; + $this->errors = $object->errors; + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + + // End + if (!$error) { + $this->db->commit(); + + return $object->id; + } else { + $this->db->rollback(); + + return - 1; + } + } + + /** + * Return a link to the user card (with optionaly the picto) + * Use this->id,this->lastname, this->firstname + * + * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) + * @param string $option On what the link point to + * @param integer $notooltip 1=Disable tooltip + * @param int $maxlen Max length of visible user name + * @param string $morecss Add more css on link + * @return string String with URL + */ + function getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='') + { + global $langs, $conf, $db; + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; + + $result = ''; + $companylink = ''; + + $label = '' . $langs->trans("Page") . ''; + $label.= '
'; + $label.= '' . $langs->trans('Ref') . ': ' . $this->ref; + + $link = 'ref . $linkend; + return $result; + } + + /** + * Retourne le libelle du status d'un user (actif, inactif) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of status + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->status,$mode); + } + + /** + * Renvoi le libelle d'un status donne + * + * @param int $status Id status + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of status + */ + function LibStatut($status,$mode=0) + { + global $langs; + + if ($mode == 0) + { + $prefix=''; + if ($status == 1) return $langs->trans('Enabled'); + if ($status == 0) return $langs->trans('Disabled'); + } + if ($mode == 1) + { + if ($status == 1) return $langs->trans('Enabled'); + if ($status == 0) return $langs->trans('Disabled'); + } + if ($mode == 2) + { + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); + if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); + } + if ($mode == 3) + { + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4'); + if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5'); + } + if ($mode == 4) + { + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); + if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); + } + if ($mode == 5) + { + if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); + if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); + } + } + + + /** + * Initialise object with example values + * Id must be 0 if object instance is a specimen + * + * @return void + */ + public function initAsSpecimen() + { + $this->id = 0; + + $this->fk_website = ''; + $this->pageurl = ''; + $this->title = ''; + $this->description = ''; + $this->keywords = ''; + $this->content = ''; + $this->status = ''; + $this->date_creation = ''; + $this->date_modification = ''; + $this->tms = ''; + + + } + +} diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 7c52b440f44..bfcdb9e0c85 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -21,8 +21,50 @@ * \brief Page to setup the module Website */ + +/** + * Show HTML header HTML + BODY + Top menu + left menu + DIV + * + * @param string $head Optionnal head lines + * @param string $title HTML title + * @param string $help_url Url links to help page + * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage + * For other external page: http://server/url + * @param string $target Target to use on links + * @param int $disablejs More content into html header + * @param int $disablehead More content into html header + * @param array $arrayofjs Array of complementary js files + * @param array $arrayofcss Array of complementary css files + * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails) + * @return void + */ +function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='') +{ + global $conf; + + // html header + top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); + + // top menu and left menu area + if (empty($conf->dol_hide_topmenu)) + { + top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url); + } + if (empty($conf->dol_hide_leftmenu)) + { + left_menu('', $help_url, '', '', 1, $title, 1); + } + + // main area + //main_area($title); +} + + + require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php'; +require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php'; $langs->load("admin"); $langs->load("other"); @@ -30,13 +72,23 @@ $langs->load("website"); if (! $user->admin) accessforbidden(); -$action = GETPOST('action','alpha'); - $conf->dol_hide_leftmenu = 1; +$error=0; +$website=GETPOST('website', 'alpha'); +$page=GETPOST('page', 'alpha'); +$action = GETPOST('action','alpha'); -$website='website1'; +if (GETPOST('preview')) $action='preview'; +if (GETPOST('editmeta')) { $action='editmeta'; } +if (GETPOST('editmenu')) { $action='editmenu'; } +if (GETPOST('editcontent')) { $action='editcontent'; } +if (empty($action)) $action='preview'; + + +$object=new Website($db); +$objectpage=new WebsitePage($db); /* @@ -46,19 +98,43 @@ $website='website1'; // Action mise a jour ou ajout d'une constante if ($action == 'update') { - + $db->begin(); + $object->fetch(0, $website); - if (! $res > 0) $error++; - - if (! $error) - { - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - else - { - setEventMessages($langs->trans("Error"), null, 'errors'); - } + $objectpage->fk_website = $object->id; + $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); + + $res = $objectpage->fetch(0, $object->fk_website, $objectpage->pageurl); + + if ($res > 0) + { + $objectpage->title = GETPOST('WEBSITE_TITLE'); + $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); + $objectpage->keyword = GETPOST('WEBSITE_KEYWORD'); + + $res = $objectpage->update($user); + if (! $res > 0) + { + $error++; + setEventMessages($objectpage->error, $objectpage->errors, 'errors'); + } + + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + $action=''; + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db); + } } @@ -68,19 +144,110 @@ if ($action == 'update') * View */ -$_SESSION['website_mode'] = 'edit'; - - $form = new Form($db); $help_url=''; -llxHeader('',$langs->trans("WebsiteSetup"),$help_url); +llxHeader('', $langs->trans("WebsiteSetup"), $help_url); + + print "\n".''; + print ''; + print ''; + print ''; + print ''; -$linkback=''.$langs->trans("BackToModuleList").''; -print load_fiche_titre($langs->trans("WebsiteSetup"),$linkback,'title_setup'); +$style=''; +if ($action != 'preview') $style=' margin-bottom: 5px;'; +print '
'; + +$tmp = $object->fetchAll(); +if (count($object->records) > 0) +{ + print '
'; + print $langs->trans("Website").': '; + print '
'; + + print '
'; + // Loop on each sites + $i=0; + foreach($object->records as $key => $websitearray) + { + if (empty($website)) $website=$websitearray->ref; + + if ($i) print ' - '; + print ''; + if ($websitearray->ref == $website) print ''; + print $websitearray->ref; + if ($websitearray->ref == $website) print ''; + print ''; + + $i++; + } + + print '
'; + + print '
'; + + if ($action == 'preview') + { + $disabled=''; + if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"'; + + print ''; + } + //else print ''; + if (preg_match('/^edit/',$action)) print ''; + + print '
'; + + if ($website) + { + print '
'; + print '
'; + print '
'; + print $langs->trans("Page").': '; + print '
'; + print '
'; + $array=$objectpage->fetchAll(); + print $form->selectarray('page', $array); + print '
'; + print ''; + + print '
'; + + if ($action == 'preview') + { + $disabled=''; + if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"'; + + if ($page) + { + print ''; + print ''; + } + } + else print ''; + if (preg_match('/^addpage/',$action)) print ''; + + print '
'; + + } +} +else +{ + print '
'; + $langs->load("errors"); + print $langs->trans("ErrorModuleSetupNotComplete"); + print '
'; + $action=''; +} + + +print '
'; $head = array(); @@ -89,16 +256,8 @@ $head = array(); * Edit mode */ -if ($_SESSION['website_mode'] == 'edit') +if ($action == 'editmeta' || $action == 'addpage') { - print "\n".''; - print ''; - print ''; - - dol_fiche_head($head, 'general', $langs->trans("Page").': '.$langs->trans("Home"), 0, 'globe'); - - print load_fiche_titre($langs->trans("SEO"),'',''); - print '
'.$langs->trans("PriceLevel").''.$langs->trans("VATRate").''.$langs->trans("SellingPrice").''.$langs->trans("MinPrice").'
'.$langs->trans("PriceLevel").''.$langs->trans("VATRate").''.$langs->trans("SellingPrice").''.$langs->trans("MinPrice").''; + print ''; print ''; print ''; print ''; print ''; print ''; + print ''; diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 84c72afc7a0..0a12d87fc2d 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -407,8 +407,7 @@ $langs->load("orders"); $langs->load("proposals"); $langs->load("margins"); -//print load_fiche_titre($langs->trans("Profit"),'','title_accountancy'); -print '
'.img_picto("", "title_accountancy").' '.$langs->trans("Profit").'

'; +print load_fiche_titre($langs->trans("Profit"), '', 'title_accountancy'); print ''; print ''; diff --git a/htdocs/societe/canvas/actions_card_common.class.php b/htdocs/societe/canvas/actions_card_common.class.php index 782a7f070c4..74a05cba39d 100644 --- a/htdocs/societe/canvas/actions_card_common.class.php +++ b/htdocs/societe/canvas/actions_card_common.class.php @@ -439,12 +439,12 @@ abstract class ActionsCardCommon if ($modCodeClient->code_auto) $this->tpl['prefix_customercode'] = $modCodeClient->verif_prefixIsUsed(); // TODO create a function - $this->tpl['select_customertype'] = ''; + $this->tpl['select_customertype'] = Form::selectarray('client', array( + 0 => $langs->trans('NorProspectNorCustomer'), + 1 => $langs->trans('Customer'), + 2 => $langs->trans('Prospect'), + 3 => $langs->trans('ProspectCustomer') + ), $this->object->client); // Customer $this->tpl['customercode'] = $this->object->code_client; diff --git a/htdocs/societe/class/api_contact.class.php b/htdocs/societe/class/api_contact.class.php index f2c19f2e484..ba7c0d4a211 100644 --- a/htdocs/societe/class/api_contact.class.php +++ b/htdocs/societe/class/api_contact.class.php @@ -17,7 +17,7 @@ use Luracast\Restler\RestException; -require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; /** * API class for contact object @@ -100,6 +100,7 @@ class ContactApi extends DolibarrApi * @url GET /contact/list * @url GET /contact/list/{socid} * @url GET /thirdparty/{socid}/contacts + * @url GET /customer/{socid}/contacts * * @throws RestException */ diff --git a/htdocs/societe/class/api_thirdparty.class.php b/htdocs/societe/class/api_thirdparty.class.php index d56c269e08e..9c65d08ac43 100644 --- a/htdocs/societe/class/api_thirdparty.class.php +++ b/htdocs/societe/class/api_thirdparty.class.php @@ -40,6 +40,10 @@ class ThirdpartyApi extends DolibarrApi * @var Societe $company {@type Societe} */ public $company; + /** + * @var Customer $customer {@type Client} + */ + public $customer; /** * Constructor @@ -52,39 +56,87 @@ class ThirdpartyApi extends DolibarrApi global $db, $conf; $this->db = $db; $this->company = new Societe($this->db); + $this->customer = new Client($this->db); if (! empty($conf->global->SOCIETE_MAIL_REQUIRED)) { static::$FIELDS[] = 'email'; } } - /** - * Get properties of a thirdparty object - * - * Return an array with thirdparty informations - * - * @param int $id ID of thirdparty - * @return array|mixed data without useless information + /** + * Get properties of a customer object + * + * Return an array with customer informations + * + * @param int $id ID of customer + * @return array|mixed data without useless information * - * @url GET thirdparty/{id} - * @throws RestException + * @url GET customer/{id} + * @throws RestException + */ + function getCustomer($id) + { + if(! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } + + $result = $this->customer->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Customer not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$this->customer->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($this->customer); + } + + /** + * Search customer by email + * + * @param string $email email id + * + * @return object client with given email + * + * @url GET customer/byemail/{email} */ + function getByEmail($email) { + $res = $this->getList(1,$email); + if (count($res) == 1) { + $customer = $res[0]; + return $customer; + } + return $res; + } + + /** + * Get properties of a thirdparty object + * + * Return an array with thirdparty informations + * + * @param int $id ID of thirdparty + * @return array|mixed data without useless information + * + * @url GET thirdparty/{id} + * @throws RestException + */ function get($id) { - if(! DolibarrApiAccess::$user->rights->societe->lire) { - throw new RestException(401); - } + if(! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - return $this->_cleanObjectDatas($this->company); + return $this->_cleanObjectDatas($this->company); } /** @@ -95,6 +147,7 @@ class ThirdpartyApi extends DolibarrApi * @param int $mode Set to 1 to show only customers * Set to 2 to show only prospects * Set to 3 to show only those are not customer neither prospect + * @param Text $email Search by email filter * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list @@ -104,7 +157,7 @@ class ThirdpartyApi extends DolibarrApi * @url GET /thirdparty/list * */ - function getList($mode=0, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { + function getList($mode=0, $email=NULL, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { global $db, $conf; $obj_ret = array(); @@ -126,6 +179,7 @@ class ThirdpartyApi extends DolibarrApi if ($mode == 3) $sql.= " AND s.client IN (0)"; $sql.= ' AND s.entity IN ('.getEntity('societe', 1).')'; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; + if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; if ($socid) $sql.= " AND s.rowid = ".$socid; if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale @@ -183,6 +237,7 @@ class ThirdpartyApi extends DolibarrApi * @return array List of customers * * @url GET /thirdparty/list/customers + * @url GET /customer/list */ function getListCustomers() { return $this->getList(1); @@ -196,7 +251,7 @@ class ThirdpartyApi extends DolibarrApi * @url GET /thirdparty/list/prospects */ function getListProspects() { - return $this->getList('',1); + return $this->getList(2); } /** @@ -207,7 +262,7 @@ class ThirdpartyApi extends DolibarrApi * @url GET /thirdparty/list/others */ function getListOthers() { - return $this->getList('','',1); + return $this->getList(3); } /** @@ -220,16 +275,31 @@ class ThirdpartyApi extends DolibarrApi */ function post($request_data = NULL) { - if(! DolibarrApiAccess::$user->rights->societe->creer) { - throw new RestException(401); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - foreach($request_data as $field => $value) { - $this->company->$field = $value; - } - return $this->company->create(DolibarrApiAccess::$user); + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + foreach($request_data as $field => $value) { + $this->company->$field = $value; + } + return $this->company->create(DolibarrApiAccess::$user); + } + + + /** + * Create customer object + * + * @param array $request_data Request datas + * @return int ID of thirdparty + * + * @url POST customer/ + */ + function postCustomer($request_data) { + $this->post($request_data); + $this->company->set_as_client(); + return $this->company->id; } /** @@ -265,30 +335,59 @@ class ThirdpartyApi extends DolibarrApi return false; } + /** + * Update customer + * + * @param int $id Id of thirdparty to update + * @param array $request_data Datas + * @return int + * + * @url PUT customer/{id} + */ + function putClient($id, $request_data = NULL) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $result = $this->customer->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Customer not found'); + } + if( ! DolibarrApi::_checkAccessToResource('societe',$this->customer->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + foreach($request_data as $field => $value) { + $this->customer->$field = $value; + } + + if($this->customer->update($id, DolibarrApiAccess::$user,1,'','','update')) + return $this->get ($id); + + return false; + } /** * Delete thirdparty * * @param int $id Thirparty ID - * @return integer + * @return type * * @url DELETE thirdparty/{id} + * @url DELETE customer/{id} */ function delete($id) { - if(! DolibarrApiAccess::$user->rights->societe->supprimer) { - throw new RestException(401); - } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } - - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - return $this->company->delete($id); + if(! DolibarrApiAccess::$user->rights->societe->supprimer) { + throw new RestException(401); + } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + return $this->company->delete($id); } /** diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index f71b04b7730..fe34f57fd6d 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2010-2013 Laurent Destailleur * Copyright (C) 2012 Regis Houssin * Copyright (C) 2013 Peter Fontaine + * Copyright (C) 2016 Marcos García * * 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 @@ -60,7 +61,7 @@ class CompanyBankAccount extends Account /** * Create bank information record * - * @param Object $user User + * @param User $user User * @return int <0 if KO, >= 0 if OK */ function create($user='') @@ -222,79 +223,27 @@ class CompanyBankAccount extends Account } } - /** - * Return RIB - * - * @param boolean $displayriblabel Prepend or Hide Label - * @return string RIB - */ - function getRibLabel($displayriblabel = true) - { - global $langs,$conf; + /** + * Return RIB + * + * @param boolean $displayriblabel Prepend or Hide Label + * @return string RIB + */ + public function getRibLabel($displayriblabel = true) + { + $rib = ''; - if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) - { - if ($this->label && $displayriblabel) $rib = $this->label." : "; + if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) { - // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; + if ($this->label && $displayriblabel) { + $rib = $this->label." : "; } - $fieldlistsarray=explode(' ',$fieldlists); - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->code_banque.' '; - } - } + $rib .= (string) $this; + } - if ($val == 'DeskCode') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->code_guichet.' '; - } - } - - if ($val == 'BankCode') - { - if ($this->useDetailedBBAN() == 2) - { - $rib.=$this->code_banque.' '; - } - } - - if ($val == 'AccountNumber') - { - $rib.=$this->number.' '; - } - - if ($val == 'BankAccountNumberKey') - { - if ($this->useDetailedBBAN() == 1) - { - $rib.=$this->cle_rib.' '; - } - } - } - } - else - { - $rib=''; - } - - return $rib; - } + return $rib; + } /** * Set RIB as Default diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 1005b8c3c8d..17f96a93c3c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -678,6 +678,7 @@ class Societe extends CommonObject $this->idprof5 = (! empty($this->idprof5)?trim($this->idprof5):''); $this->idprof6 = (! empty($this->idprof6)?trim($this->idprof6):''); $this->prefix_comm = trim($this->prefix_comm); + $this->outstanding_limit = price2num($this->outstanding_limit); $this->tva_assuj = trim($this->tva_assuj); $this->tva_intra = dol_sanitizeFileName($this->tva_intra,''); @@ -831,7 +832,7 @@ class Societe extends CommonObject $sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null"); $sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null"); - + $sql .= ",fk_stcomm='".$this->stcomm_id."'"; $sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0"); $sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null"); @@ -840,13 +841,15 @@ class Societe extends CommonObject $sql .= ",cond_reglement = ".(! empty($this->cond_reglement_id)?"'".$this->db->escape($this->cond_reglement_id)."'":"null"); $sql .= ",mode_reglement_supplier = ".(! empty($this->mode_reglement_supplier_id)?"'".$this->db->escape($this->mode_reglement_supplier_id)."'":"null"); $sql .= ",cond_reglement_supplier = ".(! empty($this->cond_reglement_supplier_id)?"'".$this->db->escape($this->cond_reglement_supplier_id)."'":"null"); - $sql .= ", fk_shipping_method_id = ".(! empty($this->shipping_method_id)?"'".$this->db->escape($this->shipping_method_id)."'":"null"); + $sql .= ",fk_shipping_method = ".(! empty($this->shipping_method_id)?"'".$this->db->escape($this->shipping_method_id)."'":"null"); $sql .= ",client = " . (! empty($this->client)?$this->client:0); $sql .= ",fournisseur = " . (! empty($this->fournisseur)?$this->fournisseur:0); $sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null"); $sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null"); $sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null"); + $sql .= ",outstanding_limit= '".($this->outstanding_limit!=''?$this->outstanding_limit:'null')."'"; + $sql .= ",fk_prospectlevel='".$this->fk_prospectlevel."'"; $sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null"); $sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null"); @@ -3178,30 +3181,11 @@ class Societe extends CommonObject * * @param User $user Utilisateur qui definie la remise * @return int <0 if KO, >0 if OK + * @deprecated Use update function instead */ function set_prospect_level(User $user) { - if ($this->id) - { - $this->db->begin(); - - // Positionne remise courante - $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET "; - $sql.= " fk_prospectlevel='".$this->fk_prospectlevel."'"; - $sql.= ",fk_user_modif='".$user->id."'"; - $sql.= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::set_prospect_level", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) - { - $this->db->rollback(); - $this->error=$this->db->error(); - return -1; - } - - $this->db->commit(); - return 1; - } + return $this->update($this->id, $user); } /** @@ -3274,31 +3258,11 @@ class Societe extends CommonObject * * @param User $user User making change * @return int <0 if KO, >0 if OK + * @deprecated Use update function instead */ function set_commnucation_level($user) { - if ($this->id) - { - $this->db->begin(); - - // Positionne remise courante - $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET "; - $sql.= " fk_stcomm='".$this->stcomm_id."'"; - $sql.= ",fk_user_modif='".$user->id."'"; - $sql.= " WHERE rowid = ".$this->id; - - dol_syslog(get_class($this)."::set_commnucation_level", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - return -1; - } - - $this->db->commit(); - return 1; - } + return $this->update($this->id, $user); } /** @@ -3306,35 +3270,11 @@ class Societe extends CommonObject * * @param User $user User making change * @return int <0 if KO, >0 if OK + * @deprecated Use update function instead */ function set_OutstandingBill(User $user) { - if ($this->id) - { - $this->db->begin(); - - // Clean parameters - $outstanding = price2num($this->outstanding_limit); - - // Set outstanding amount - $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET "; - $sql.= " outstanding_limit= '".($outstanding!=''?$outstanding:'null')."'"; - $sql.= " WHERE rowid = ".$this->id; - - dol_syslog(get_class($this)."::set_outstanding", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - return -1; - } - } + return $this->update($this->id, $user); } /** diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index e01331617ea..4e9d0b1ed18 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -191,7 +191,7 @@ if (empty($reshook)) $object = new Client($db); $result=$object->fetch(GETPOST('stcommsocid')); $object->stcomm_id=dol_getIdFromCode($db, GETPOST('stcomm','alpha'), 'c_stcomm'); - $result=$object->set_commnucation_level($user); + $result=$object->update($object->id, $user); if ($result < 0) setEventMessages($object->error,$object->errors,'errors'); $action=''; diff --git a/htdocs/societe/rib.php b/htdocs/societe/rib.php index c7f087daf72..0d8cdcc1264 100644 --- a/htdocs/societe/rib.php +++ b/htdocs/societe/rib.php @@ -4,7 +4,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Peter Fontaine - * Copyright (C) 2015 Marcos García + * Copyright (C) 2015-2016 Marcos García * * 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 @@ -254,64 +254,22 @@ if ($socid && $action != 'edit' && $action != "create") print ''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) + + foreach($account->getFieldsToShow() as $val) { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } - } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } + if ($val == 'BankCode') { + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $content = $account->cle_rib; } - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''; - print ''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''; - print ''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } - } + print ''; + print ''; + print ''; } print ''; @@ -473,65 +431,28 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print ''; // Show fields of bank account - $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; - if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) - { - if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; - } - else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; - } - $fieldlistsarray=explode(' ',$fieldlists); - - foreach($fieldlistsarray as $val) - { - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } + foreach ($account->getFieldsToShow() as $val) { + if ($val == 'BankCode') { + $name = 'code_banque'; + $size = 8; + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $name = 'code_guichet'; + $size = 8; + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $name = 'number'; + $size = 18; + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $name = 'cle_rib'; + $size = 3; + $content = $account->cle_rib; } - if ($val == 'DeskCode') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } - } - - if ($val == 'BankCode') - { - if ($account->useDetailedBBAN() == 2) - { - print ''; - print ''; - print ''; - } - } - - if ($val == 'AccountNumber') - { - print ''; - print ''; - print ''; - } - - if ($val == 'BankAccountNumberKey') - { - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } - } + print ''; + print ''; + print ''; } // IBAN diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 866e53bcd6b..eedcd449c0d 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -1903,7 +1903,7 @@ else 'name' => 'soc_origin', 'label' => $langs->trans('MergeOriginThirdparty'), 'type' => 'other', - 'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 1, 0, 0, array(), 0, 'minwidth200') + 'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200') ) ); diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index be07d022fdb..9101b6efda2 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -717,6 +717,7 @@ if (empty($reshook)) unset($_POST['type']); unset($_POST['remise_percent']); unset($_POST['price_ht']); + unset($_POST['multicurrency_price_ht']); unset($_POST['price_ttc']); unset($_POST['tva_tx']); unset($_POST['product_ref']); @@ -841,6 +842,7 @@ if (empty($reshook)) unset($_POST['productid']); unset($_POST['remise_percent']); unset($_POST['price_ht']); + unset($_POST['multicurrency_price_ht']); unset($_POST['price_ttc']); unset($_POST['tva_tx']); unset($_POST['product_ref']); @@ -1549,9 +1551,9 @@ if ($action == 'create') print '
'.$account->bank.'
'.$langs->trans("BankCode").''.$account->code_banque.'
'.$langs->trans("DeskCode").''.$account->code_guichet.'
'.$langs->trans("BankCode").''.$account->code_banque.'
'.$langs->trans("BankAccountNumber").''.$account->number.'
'.$langs->trans("BankAccountNumberKey").''.$account->cle_rib.'
'.$langs->trans($val).''.$content.'
'.$langs->trans("IBAN").'
'.$langs->trans("BankCode").'
'.$langs->trans("DeskCode").'
'.$langs->trans("BankCode").'
'.$langs->trans("BankAccountNumber").'
'.$langs->trans("BankAccountNumberKey").'
'.$langs->trans($val).'
'; print '
'; if ($action == 'editmulticurrencyrate') { - $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'multicurrency_tx'); + $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code); } else { - $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none'); + $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); } print '
".$langs->trans("Supplier")."'.$object->client->getNomUrl(1).'
'.$object->thirdparty->getNomUrl(1).'
'.$langs->trans('SupplierProposalDate').''; print dol_print_date($object->date_livraison,'daytext'); diff --git a/htdocs/theme/eldy/img/menus/menu.png b/htdocs/theme/eldy/img/menus/menu.png new file mode 100644 index 00000000000..e8ef108b127 Binary files /dev/null and b/htdocs/theme/eldy/img/menus/menu.png differ diff --git a/htdocs/theme/eldy/img/menus_black/menu.png b/htdocs/theme/eldy/img/menus_black/menu.png new file mode 100644 index 00000000000..0b080a18715 Binary files /dev/null and b/htdocs/theme/eldy/img/menus_black/menu.png differ diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index b772f741219..e7fe3a14952 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -646,7 +646,7 @@ td.showDragHandle { div.fiche { - margin-: global->MAIN_MENU_USE_JQUERY_LAYOUT))?($dol_hide_leftmenu?'6':'20'):'24')); ?>px; + margin-: px; margin-: dol_optimize_smallscreen)?'12':'6')); ?>px; dol_hide_leftmenu) && ! empty($conf->dol_hide_topmenu)) print 'margin-top: 4px;'; ?> } @@ -683,7 +683,7 @@ div.ficheaddleft { @media only screen and (max-width: 900px) { div.fiche { - margin-: global->MAIN_MENU_USE_JQUERY_LAYOUT))?($dol_hide_leftmenu?'6':'20'):'24')); ?>px; + margin-: px; margin-: px; dol_hide_leftmenu) && ! empty($conf->dol_hide_topmenu)) print 'margin-top: 4px;'; ?> } @@ -1021,6 +1021,10 @@ div.mainmenu.tools { background-image: url(); } +div.mainmenu.websites { + background-image: url(); +} + 'name of class for div') @@ -1040,7 +1044,8 @@ foreach($conf->modules as $val) $mainmenuusedarray=array_unique(explode(',',$mainmenuused)); $generic=1; -$divalreadydefined=array('home','companies','products','commercial','externalsite','accountancy','project','tools','members','agenda','holiday','bookmark','cashdesk','ecm','geoipmaxmind','gravatar','clicktodial','paypal','webservices'); +// Put here list of menu entries when the div.mainmenu.menuentry was previously defined +$divalreadydefined=array('home','companies','products','commercial','externalsite','accountancy','project','tools','members','agenda','holiday','bookmark','cashdesk','ecm','geoipmaxmind','gravatar','clicktodial','paypal','webservices','websites'); foreach($mainmenuusedarray as $val) { if (empty($val) || in_array($val,$divalreadydefined)) continue; @@ -3099,6 +3104,27 @@ td.hidden { } +/* ============================================================================== */ +/* Module website */ +/* ============================================================================== */ + +.websitebar { + border-bottom: 1px solid #888; + height: 30px; +} +.websiteselection { + display: inline-block; + padding-left: 10px; + vertical-align: middle; + margin-bottom: 5px; + line-height: 29px; +} +.websitetools { + float: right; + padding-top: 2px; +} + + /* ============================================================================== */ /* Module agenda */ /* ============================================================================== */ diff --git a/htdocs/theme/md/img/menu.png b/htdocs/theme/md/img/menu.png new file mode 100644 index 00000000000..e8ef108b127 Binary files /dev/null and b/htdocs/theme/md/img/menu.png differ diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 9644232d2c6..9b5bbc5966e 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -120,7 +120,7 @@ if (empty($conf->global->THEME_ELDY_ENABLE_PERSONALIZED)) $conf->global->THEME_ELDY_LINEPAIR1='250,250,250'; $conf->global->THEME_ELDY_LINEPAIR2='248,248,248'; $conf->global->THEME_ELDY_LINEPAIRHOVER='238,246,252'; - $conf->global->THEME_ELDY_USE_HOVER=='238,246,252'; + $conf->global->THEME_ELDY_USE_HOVER='238,246,252'; $conf->global->THEME_ELDY_TEXT='0,0,0'; $conf->global->THEME_ELDY_FONT_SIZE1='13'; $conf->global->THEME_ELDY_FONT_SIZE2='11'; @@ -699,7 +699,7 @@ td.showDragHandle { div.fiche { - margin-: global->MAIN_MENU_USE_JQUERY_LAYOUT))?($dol_hide_leftmenu?'4':'20'):'24')); ?>px; + margin-: px; margin-: dol_optimize_smallscreen)?'16':'4')); ?>px; dol_hide_leftmenu) && ! empty($conf->dol_hide_topmenu)) print 'margin-top: 4px;'; ?> margin-bottom: 15px; @@ -737,7 +737,7 @@ div.ficheaddleft { @media only screen and (max-width: 900px) { div.fiche { - margin-: global->MAIN_MENU_USE_JQUERY_LAYOUT))?($dol_hide_leftmenu?'4':'20'):'24')); ?>px; + margin-: px; margin-: px; dol_hide_leftmenu) && ! empty($conf->dol_hide_topmenu)) print 'margin-top: 4px;'; ?> margin-bottom: 15px; @@ -1072,6 +1072,10 @@ div.mainmenu.tools { background-image: url(); } +div.mainmenu.websites { + background-image: url(); +} + 'name of class for div') @@ -1091,7 +1095,8 @@ foreach($conf->modules as $val) $mainmenuusedarray=array_unique(explode(',',$mainmenuused)); $generic=1; -$divalreadydefined=array('home','companies','products','commercial','externalsite','accountancy','project','tools','members','agenda','holiday','bookmark','cashdesk','ecm','geoipmaxmind','gravatar','clicktodial','paypal','webservices'); +// Put here list of menu entries when the div.mainmenu.menuentry was previously defined +$divalreadydefined=array('home','companies','products','commercial','externalsite','accountancy','project','tools','members','agenda','holiday','bookmark','cashdesk','ecm','geoipmaxmind','gravatar','clicktodial','paypal','webservices','websites'); foreach($mainmenuusedarray as $val) { if (empty($val) || in_array($val,$divalreadydefined)) continue; @@ -2944,6 +2949,27 @@ td.hidden { } +/* ============================================================================== */ +/* Module website */ +/* ============================================================================== */ + +.websitebar { + border-bottom: 1px solid #888; + height: 30px; +} +.websiteselection { + display: inline-block; + padding-left: 10px; + vertical-align: middle; + margin-bottom: 5px; + line-height: 29px; +} +.websitetools { + float: right; + padding-top: 2px; +} + + /* ============================================================================== */ /* Module agenda */ /* ============================================================================== */ diff --git a/htdocs/user/bank.php b/htdocs/user/bank.php index b4f070a2187..951c3a6ef7e 100644 --- a/htdocs/user/bank.php +++ b/htdocs/user/bank.php @@ -4,7 +4,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Peter Fontaine - * Copyright (C) 2015 Marcos García + * Copyright (C) 2015-2016 Marcos García * Copyright (C) 2015 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify @@ -149,64 +149,20 @@ if ($id && $action != 'edit') print ''.$account->bank.'
'.$langs->trans("BankCode").''.$account->code_banque.'
'.$langs->trans("DeskCode").''.$account->code_guichet.'
'.$langs->trans("BankCode").''.$account->code_banque.'
'.$langs->trans("BankAccountNumber").''.$account->number.'
'.$langs->trans("BankAccountNumberKey").''.$account->cle_rib.'
'.$langs->trans($val).''.$content.'
'.$langs->trans("IBAN").'
'.$langs->trans("BankCode").'
'.$langs->trans("DeskCode").'
'.$langs->trans("BankCode").'
'.$langs->trans("BankAccountNumber").'
'.$langs->trans("BankAccountNumberKey").'
'.$langs->trans($val).'
'; print ''; print ''; @@ -106,11 +265,20 @@ if ($_SESSION['website_mode'] == 'edit') print "\n"; print ''; + if ($action != 'addpage') + { + print ''; + } + print '
'.$langs->trans("Description").'
'; - print $langs->trans('WEBSITE_PAGEURL'); + print $langs->trans('WEBSITE_PAGENAME'); print ''; - print '/public/websites/'.$website.'/index.php?page=home'; + print ''; print '
'; + print $langs->trans('WEBSITE_URL'); + print ''; + print '/public/websites/'.$website.'/index.php?page='.urlencode($page); + print '
'; print $langs->trans('WEBSITE_TITLE'); print ''; @@ -132,9 +300,16 @@ if ($_SESSION['website_mode'] == 'edit') print '
'; print '
'; - - - /* +} + +if ($action == 'editmenu') +{ + print '
'.$langs->trans("FeatureNotYetAvailable").''; +} + +if ($action == 'editcontent') +{ +/* * Editing global variables not related to a specific theme */ @@ -151,16 +326,19 @@ if ($_SESSION['website_mode'] == 'edit') require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('WEBSITE_FOOTER',$obj->value,'',160,'dolibarr_notes','',false,false,$conf->fckeditor->enabled,5,60); $doleditor->Create(); - - dol_fiche_end(); - - print '
'; - - print ''; } +print ''; + +if ($action == 'preview') +{ + print '
Preview TO DO'; +} + + + llxFooter(); $db->close(); diff --git a/htdocs/websites/indexold.php b/htdocs/websites/indexold.php deleted file mode 100644 index db7b69e1bdd..00000000000 --- a/htdocs/websites/indexold.php +++ /dev/null @@ -1,65 +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 . - * - */ - -/** - * \file htdocs/externalsite/frames.php - * \ingroup externalsite - * \brief Page that build two frames: One for menu, the other for the target page to show - * \author Laurent Destailleur - */ - -require '../main.inc.php'; - -$langs->load("website"); - - -$mainmenu=GETPOST('mainmenu', 'alpha'); -$leftmenu=GETPOST('leftmenu', 'alpha'); -$idmenu=GETPOST('idmenu', 'int'); -$theme=GETPOST('theme', 'alpha'); -$codelang=GETPOST('lang', 'alpha'); - -print " - - -Dolibarr frame for web site menu - - -global->MAIN_MENU_INVERT)?"rows":"cols")."=\"".($heightforframes+50).",*\" border=0 framespacing=0 frameborder=0> - - - - <body> - - </body> - - - - -<body> - <br><div class=\"center\"> - Sorry, your browser is too old or not correctly configured to view this area.<br> - Your browser must support frames.<br> - </div> -</body> - - - -"; - -