From aace9db326fab7958fb691cb526f95915ffc4067 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Tue, 19 Aug 2025 13:31:11 +0200 Subject: [PATCH] Manage code rewriting --- html/js/card.js | 28 +++- html/js/noalyss_script.js | 2 +- include/ajax/ajax_card.php | 18 +- include/bank.inc.php | 139 ++++++--------- include/class/bank.class.php | 8 +- include/class/customer.class.php | 2 +- include/class/fiche_def.class.php | 8 +- include/class/manager.class.php | 2 +- include/class/supplier.class.php | 5 +- include/class/trait_card.php | 46 +++++ include/constant.php | 5 + include/customer.inc.php | 37 +--- include/lib/ac_common.php | 1 - include/lib/html_input.class.php | 2 +- include/manager.inc.php | 35 +--- include/supplier.inc.php | 177 ++++++++------------ include/template/trait_card-form_search.php | 76 +++++++++ 17 files changed, 304 insertions(+), 287 deletions(-) create mode 100644 include/class/trait_card.php create mode 100644 include/template/trait_card-form_search.php diff --git a/html/js/card.js b/html/js/card.js index 57f09f5f0..7fd6a5499 100644 --- a/html/js/card.js +++ b/html/js/card.js @@ -994,7 +994,7 @@ function add_category(obj) */ function save_card_category(obj) { - if ( ! document.getElementById(obj).ipopup) + if ( ! $(obj).ipopup) { alert_box('Erreur pas d\' attribut ipopup '+obj.id); return; @@ -1009,15 +1009,29 @@ try { queryString+='&op=card'; // sc for save card var action=new Ajax.Request ( 'ajax_misc.php', - { - method:'get', - parameters:queryString, - onFailure:errorFid, - onSuccess:fill_box - } + { + method:'POST', + parameters:queryString, + onFailure:errorFid, + onSuccess:function (req) + { + fill_box(req); + // populate + var answer = req.responseXML; + var a = answer.getElementsByTagName('id'); + var b = answer.getElementsByTagName('name'); + if ( a.length == 1 && b.length == 1) { + let option=new Element('option'); + option.value=getNodeText(a[0]); + option.text=getNodeText(b[0]); + id$('cat').add(option); + } + } + } ); } catch(e) { + alert_box(e.message); return false; } diff --git a/html/js/noalyss_script.js b/html/js/noalyss_script.js index d63596459..84c1c67fe 100644 --- a/html/js/noalyss_script.js +++ b/html/js/noalyss_script.js @@ -2223,7 +2223,7 @@ function filter_table(phrase, _id, colnr, start_row) { if (tot_found == 0) { if (document.getElementById('info_' + _id)) { id$('info_' + _id).innerHTML = content[69]; - id$('info_' + _id).style.display = 'block'; + id$('info_' + _id).style.display = 'inline-block'; } } else { if (document.getElementById('info_' + _id)) { diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php index 466ab6aae..7c25de60f 100644 --- a/include/ajax/ajax_card.php +++ b/include/ajax/ajax_card.php @@ -634,9 +634,9 @@ case 'scc': { $html=""; - $nom_mod=$http->get("nom_mod"); - $class_base=$http->get("class_base"); - $fd_description=$http->get("nom_mod"); + $nom_mod=$http->post("nom_mod"); + $class_base=$http->post("class_base"); + $fd_description=$http->post("fd_description","string",""); if ( noalyss_strlentrim($nom_mod) != 0 ) { $array=array("FICHE_REF"=>$cat, @@ -644,7 +644,7 @@ case 'scc': "class_base"=>$class_base, "fd_description"=>$fd_description); - if ( isset ($_POST['create'])) $array['create']=1; + if ( isset ($_POST['create'])) $array['create']="on"; $catcard=new Fiche_Def($cn); @@ -661,7 +661,15 @@ case 'scc': } else{ $script="alert_box('"._('Catégorie sauvée')."');removeDiv('$ctl')"; - } + // add code to update the SELECT in include/template/category_of_card.php + $catcard->get(); + + $extra = ''. + ''.$catcard->id.''. + ''. escape_xml($catcard->label).''. + ''; + + } $html.=create_script($script); } diff --git a/include/bank.inc.php b/include/bank.inc.php index a0db678e7..9ad1b6081 100644 --- a/include/bank.inc.php +++ b/include/bank.inc.php @@ -15,135 +15,96 @@ * You should have received a copy of the GNU General Public License * along with NOALYSS; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + */ // Copyright Author Dany De Bontridder danydb@aevalys.eu -/*!\brief include from supplier.inc.php and concerned only the supplier card and +/* !\brief include from supplier.inc.php and concerned only the supplier card and * the supplier category */ -if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); -global $g_user , $http; +if (!defined('ALLOWED')) + die('Appel direct ne sont pas permis'); +global $g_user, $http; -$low_action=$http->request('sb',"string",'list'); -/*! \file +$low_action = $http->request('sb', "string", 'list'); +/* ! \file * \brief Called from the module 'Gestion' to manage the supplier */ -$href=basename($_SERVER['PHP_SELF']); +$href=NOALYSS_URL."/do.php"; // by default open liste -if ( $low_action == '' ) - $low_action='list'; +if ($low_action == '') + $low_action = 'list'; -//----------------------------------------------------- +//----------------------------------------new------------- // Remove a card //----------------------------------------------------- -if ( isset($_POST['delete_card'] ) ) -{ - if ( $g_user->check_action(FICADD) == 0 ) - { +if (isset($_POST['delete_card'])) { + if ($g_user->check_action(FICADD) == 0) { alert(_('Vous ne pouvez pas enlever de fiche')); return; } - $f_id = $http->request('f_id','number'); + $f_id = $http->request('f_id', 'number'); - $fiche=new Bank($cn,$f_id); + $fiche = new Bank($cn, $f_id); $fiche->remove(); - $low_action="list"; - + $low_action = "list"; } //----------------------------------------------------- // list of supplier //----------------------------------------------------- -if ( $low_action == "list" ) -{ - +if ($low_action == "list") { ?>
-
-
- ' ._( "Exercice")." " . $g_user->get_exercice() . ''; - $a=$http->get("query","string",""); - echo _("Cherche ").HtmlInput::filter_table_form("tiers_tb", '0,1,2', 1,"query",$a); - - $choice_cat=$http->request("choice_cat", "string",1); - - if ( $choice_cat == 1 ) - { - $sel_card=new ISelect('cat'); - $sel_card->value=$cn->make_array('select fd_id, fd_label from fiche_def '. - ' where frd_id=$1'. - ' order by fd_label ',1,array(FICHE_TYPE_FIN)); - $sel_card->selected=$http->get("cat","number",-1); - $sel_card->javascript=' onchange="waiting_box();submit(this);"'; - echo _('Catégorie :').$sel_card->input(); +
+ +
+ get("query", "string", ""); + $sql = ""; + if (isset($_GET['cat'])) { + $cat = $http->get("cat", "number"); + if ($cat != -1) + $sql = sprintf(" and fd_id = %s", $cat); } - else - { - $cat=$http->request('cat',"string", ''); - echo HtmlInput::hidden("cat", $cat); - echo HtmlInput::hidden('choice_cat', 0); - } - $nooperation=new ICheckBox('noop'); - $nooperation->selected=(isset($_GET['noop']))?true:false; - echo _('Inclure les banques sans opération :').$nooperation->input(); - - ?> - - -
-
- get("query","string",""); - $sql=""; - if ( isset($_GET['cat'])) - { - $cat=$http->get("cat","number"); - if ($cat!= -1 ) $sql = sprintf(" and fd_id = %s", $cat); - } - $noop=(isset($_GET['noop']))?false:true; + $noop = (isset($_GET['noop'])) ? false : true; echo '
'; - echo $supplier->Summary($search,'bank',$sql,$noop); - + echo $supplier->Summary($search, 'bank', $sql, $noop); echo '
'; echo '
'; echo '
'; - if ($g_user->check_action(FICADD)==1) - { - /* Add button */ - $f_add_button=new IButton('add_card'); - $f_add_button->label=_('Créer une nouvelle fiche'); - $f_add_button->set_attribute('win_refresh','yes'); + if ($g_user->check_action(FICADD) == 1) { + /* Add button */ + $f_add_button = new IButton('add_card'); + $f_add_button->label = _('Créer une nouvelle fiche'); + $f_add_button->set_attribute('win_refresh', 'yes'); - $f_add_button->set_attribute('type_cat',FICHE_TYPE_FIN); - $f_add_button->javascript=" select_card_type(this);"; - echo $f_add_button->input(); + $f_add_button->set_attribute('type_cat', FICHE_TYPE_FIN); + $f_add_button->javascript = " select_card_type(this);"; + echo $f_add_button->input(); - $f_cat_button=new IButton('add_cat'); - $f_cat_button->set_attribute('type_cat',FICHE_TYPE_FIN); - $f_cat_button->set_attribute('ipopup','ipop_cat'); - $f_cat_button->label=_('Ajout d\'une catégorie'); - $f_cat_button->javascript='add_category(this)'; - echo $f_cat_button->input(); - } + $f_cat_button = new IButton('add_cat'); + $f_cat_button->set_attribute('type_cat', FICHE_TYPE_FIN); + $f_cat_button->set_attribute('ipopup', 'ipop_cat'); + $f_cat_button->label = _("Ajout d'une catégorie"); + $f_cat_button->javascript = 'add_category(this)'; + echo $f_cat_button->input(); + } echo '
'; echo '
'; - - } -/*---------------------------------------------------------------------- +/* ---------------------------------------------------------------------- * Detail for a card, Suivi, Contact, Operation,... * * cc stands for supplier card - *----------------------------------------------------------------------*/ -if ( $low_action == 'detail') -{ + * ---------------------------------------------------------------------- */ +if ($low_action == 'detail') { /* Menu */ require_once('category_card.inc.php'); return; diff --git a/include/class/bank.class.php b/include/class/bank.class.php index 0ab215cb7..c8acacc43 100644 --- a/include/class/bank.class.php +++ b/include/class/bank.class.php @@ -33,12 +33,10 @@ require_once NOALYSS_INCLUDE.'/lib/user_common.php'; class Bank extends Fiche { - var $name; /*!< $name name of the company */ - var $street; /*!< $street Street */ - var $country; /*!< $country Country */ - var $cp; /*!< $cp Zip code */ - var $vat_number; /*!< $vat_number vat number */ + + use Trait_Card; + /*! \brief Constructor only a db connection is needed */ function __construct($p_cn,$p_id=0) { diff --git a/include/class/customer.class.php b/include/class/customer.class.php index 4217e04b1..108687888 100644 --- a/include/class/customer.class.php +++ b/include/class/customer.class.php @@ -37,7 +37,7 @@ class Customer extends Fiche var $country; /*!< $country Country */ var $cp; /*!< $cp Zip code */ var $vat_number; /*!< $vat_number vat number */ - + use Trait_Card; /*! \brief Constructor * only a db connection is needed */ diff --git a/include/class/fiche_def.class.php b/include/class/fiche_def.class.php index cc5378254..af2b9376e 100644 --- a/include/class/fiche_def.class.php +++ b/include/class/fiche_def.class.php @@ -39,10 +39,10 @@ class Fiche_Def var $attribut; //!< get from attr_xxx tables var $fd_description; //!< Description of the Card Category - function __construct($p_cn,$p_id = 0) + function __construct($cn,$id = 0) { - $this->cn=$p_cn; - $this->id=$p_id; + $this->cn=$cn; + $this->id=$id; } @@ -61,7 +61,7 @@ class Fiche_Def } /** * @brief replace by load_attribute - * @deprecated since version 9.3.0.12 + * @deprecated since version 9.3.12 * @return type */ function getAttribut() { diff --git a/include/class/manager.class.php b/include/class/manager.class.php index 2dc9275e0..e6b96a272 100644 --- a/include/class/manager.class.php +++ b/include/class/manager.class.php @@ -39,7 +39,7 @@ class Manager extends Fiche var $country; /*!< $country Country */ var $cp; /*!< $cp Zip code */ var $vat_number; /*!< $vat_number vat number */ - + use Trait_Card; /*! \brief Constructor * only a db connection is needed */ function __construct($p_cn,$p_id=0) diff --git a/include/class/supplier.class.php b/include/class/supplier.class.php index da64ccf43..68b5144a1 100644 --- a/include/class/supplier.class.php +++ b/include/class/supplier.class.php @@ -26,7 +26,7 @@ require_once NOALYSS_INCLUDE.'/lib/user_common.php'; * \brief class Supplier are a specific kind of card */ -// Use the view vw_supplier +///@brief Use the view vw_supplier and the trait Trait_Card // class Supplier extends Fiche { @@ -38,6 +38,9 @@ class Supplier extends Fiche var $cp; /*!< $cp Zip code */ var $vat_number; /*!< $vat_number vat number */ + use Trait_Card; + + /*! \brief Constructor * only a db connection is needed */ function __construct($p_cn,$p_id=0) diff --git a/include/class/trait_card.php b/include/class/trait_card.php new file mode 100644 index 000000000..e7381b76e --- /dev/null +++ b/include/class/trait_card.php @@ -0,0 +1,46 @@ +"class/trait_card.php", "database" => "class/database.class.php", "acc_detail" => "class/acc_operation.class.php", "acc_sold" => "class/acc_operation.class.php", diff --git a/include/customer.inc.php b/include/customer.inc.php index a80fea4ac..1da57c91f 100644 --- a/include/customer.inc.php +++ b/include/customer.inc.php @@ -66,38 +66,11 @@ if ($low_action == "list") ?>
-
- ' . "Exercice " . $g_user->get_exercice() . ''; - $a=$http->get("query","string",""); - echo _("Cherche ").HtmlInput::filter_table_form("tiers_tb", '0,1,2', 1,"query",$a); - - $choice_cat=$http->request("choice_cat", "string",1); - - if ( $choice_cat == 1 ) - { - $sel_card=new ISelect('cat'); - $sel_card->value=$cn->make_array('select fd_id, fd_label from fiche_def '. - ' where frd_id='.FICHE_TYPE_CLIENT. - ' order by fd_label ',1); - $sel_card->selected=$http->get("cat","number",-1); - $sel_card->javascript=' onchange="waiting_box();submit(this);"'; - echo _('Catégorie :').$sel_card->input(); - } else - { - $cat=$http->request('cat',"string", ''); - echo HtmlInput::hidden("cat",$cat); - echo HtmlInput::hidden('choice_cat', 0); - } - $nooperation = new ICheckBox('noop'); - $nooperation->selected = (isset($_GET['noop'])) ? true : false; - echo Dossier::hidden(); - - echo _('Inclure les clients sans opération :') . $nooperation->input(); - ?> - - -
+
"; - $r.=' '; + $r.=' '; return $r; } /** diff --git a/include/manager.inc.php b/include/manager.inc.php index 8143f2c15..4888e5076 100644 --- a/include/manager.inc.php +++ b/include/manager.inc.php @@ -65,38 +65,9 @@ if ($low_action == "list") ?>
-
- ' . "Exercice " . $g_user->get_exercice() . ''; - echo dossier::hidden(); - $a=$http->get("query","string",""); - echo _("Cherche ").HtmlInput::filter_table_form("tiers_tb", '0,1,2', 1,"query",$a); - - echo HtmlInput::request_to_hidden(array('ac')); - $choice_cat=$http->request("choice_cat", "number",1); - if ( $choice_cat == 1 ) - { - $sel_card = new ISelect('cat'); - $sel_card->value = $cn->make_array('select fd_id, fd_label from fiche_def ' . - ' where frd_id=' . FICHE_TYPE_EMPL . - ' order by fd_label ', 1); - $sel_card->selected=$http->get("cat","number",-1); - $sel_card->javascript = ' onchange="waiting_box();submit(this);"'; - echo _('Catégorie :') . $sel_card->input(); - } - else - { - $cat=$http->request('cat',"string", ''); - echo HtmlInput::hidden("cat",$cat); - echo HtmlInput::hidden('choice_cat', 0); - } - $nooperation = new ICheckBox('noop'); - $nooperation->selected = (isset($_GET['noop'])) ? true : false; - echo _('Inclure les employés sans opération :') . $nooperation->input(); - ?> - - -
+
check_action(FICADD) == 0 ) - { +if (isset($_POST['action_fiche'])) { + if ($_POST['action_fiche'] == 'delete_card') { + if ($g_user->check_action(FICADD) == 0) { alert(_('Vous ne pouvez pas enlever de fiche')); return; } - $f_id = $http->request('f_id','number'); + $f_id = $http->request('f_id', 'number'); - $fiche=new Supplier($cn,$f_id); + $fiche = new Supplier($cn, $f_id); $fiche->remove(); - $low_action="list"; + $low_action = "list"; } } //----------------------------------------------------- // list of supplier //----------------------------------------------------- -if ( $low_action == "list" ) -{ - $search=$http->get("query","string",""); - +if ($low_action == "list") { + $search = $http->get("query", "string", ""); ?>
-
-
- ' . "Exercice " . $g_user->get_exercice() . ''; - echo dossier::hidden(); - echo _("Cherche ").HtmlInput::filter_table_form("tiers_tb", '0,1,2', 1,"query",$search); +
+ +
+ get("cat", "number"); + if ($cat != -1) + $sql = sprintf(" and fd_id = %s", $cat); + } + $noop = (isset($_GET['noop'])) ? false : true; - $choice_cat=$http->request("choice_cat", "string",1); - if ( $choice_cat == 1 ) - { - $sel_card=new ISelect('cat'); - $sel_card->value=$cn->make_array('select fd_id, fd_label from fiche_def '. - ' where frd_id='.FICHE_TYPE_FOURNISSEUR. - ' order by fd_label ',1); - $sel_card->selected=$http->get("cat","number",-1); - $sel_card->javascript=' onchange="waiting_box();submit(this);"'; - echo _('Catégorie :').$sel_card->input(); - } else - { - $cat=$http->request('cat','string', ''); - echo HtmlInput::hidden("cat",$cat); - echo HtmlInput::hidden('choice_cat', 0); + echo '
'; + echo $supplier->Summary($search, 'supplier', $sql, $noop); + + echo '
'; + echo '
'; + echo '
'; + if ($g_user->check_action(FICADD) == 1) { + /* Add button */ + $f_add_button = new IButton('add_card'); + $f_add_button->label = _('Créer une nouvelle fiche'); + $f_add_button->set_attribute('win_refresh', 'yes'); + + $f_add_button->set_attribute('type_cat', FICHE_TYPE_FOURNISSEUR); + $f_add_button->javascript = " select_card_type(this);"; + echo $f_add_button->input(); + + $f_cat_button = new IButton('add_cat'); + $f_cat_button->set_attribute('type_cat', FICHE_TYPE_FOURNISSEUR); + $f_cat_button->set_attribute('ipopup', 'ipop_cat'); + $f_cat_button->label = _('Ajout d\'une catégorie'); + $f_cat_button->javascript = 'add_category(this)'; + echo $f_cat_button->input(); + } + + echo '
'; + echo '
'; + } + /* ---------------------------------------------------------------------- + * Detail for a card, Suivi, Contact, Operation,... * + * cc stands for supplier card + * ---------------------------------------------------------------------- */ + if ($low_action == 'detail') { + /* Menu */ + require_once NOALYSS_INCLUDE . '/category_card.inc.php'; + return; } - $nooperation=new ICheckBox('noop'); - $nooperation->selected=(isset($_GET['noop']))?true:false; - echo _('Inclure les fournisseurs sans opération :').$nooperation->input(); + + + html_page_stop(); ?> - - - -
- get("cat","number"); - if ($cat!= -1) - $sql = sprintf(" and fd_id = %s", $cat); - } - $noop=(isset($_GET['noop']))?false:true; - - echo '
'; - echo $supplier->Summary($search,'supplier',$sql,$noop); - - - echo '
'; - echo '
'; - echo '
'; - if ($g_user->check_action(FICADD)==1) - { - /* Add button */ - $f_add_button=new IButton('add_card'); - $f_add_button->label=_('Créer une nouvelle fiche'); - $f_add_button->set_attribute('win_refresh','yes'); - - $f_add_button->set_attribute('type_cat',FICHE_TYPE_FOURNISSEUR); - $f_add_button->javascript=" select_card_type(this);"; - echo $f_add_button->input(); - - $f_cat_button=new IButton('add_cat'); - $f_cat_button->set_attribute('type_cat',FICHE_TYPE_FOURNISSEUR); - $f_cat_button->set_attribute('ipopup','ipop_cat'); - $f_cat_button->label=_('Ajout d\'une catégorie'); - $f_cat_button->javascript='add_category(this)'; - echo $f_cat_button->input(); - } - - echo '
'; - echo '
'; - - -} -/*---------------------------------------------------------------------- - * Detail for a card, Suivi, Contact, Operation,... * - * cc stands for supplier card - *----------------------------------------------------------------------*/ -if ( $low_action == 'detail') -{ - /* Menu */ - require_once NOALYSS_INCLUDE.'/category_card.inc.php'; - return; -} - - - -html_page_stop(); -?> diff --git a/include/template/trait_card-form_search.php b/include/template/trait_card-form_search.php new file mode 100644 index 000000000..82c5bfa40 --- /dev/null +++ b/include/template/trait_card-form_search.php @@ -0,0 +1,76 @@ + +
+ +

get_exercice()) ?>

+ +
+
+get("query", "string", ""); +echo _("Cherche ") . HtmlInput::filter_table_form("tiers_tb", '0,1,2', 1, "query", $a); + +$choice_cat = $http->request("choice_cat", "string", 1); +?> +
+ value = $cn->make_array('select fd_id, fd_label from fiche_def + where frd_id= $1 + order by fd_label ', 1, [$type_card]); + $sel_card->selected = $http->get("cat", "number", -1); + $sel_card->javascript = ' onchange="waiting_box();submit(this);"'; + echo '
'; + echo _('Catégorie :') . $sel_card->input(); + echo '
'; + } else { + $cat = $http->request('cat', "string", ''); + echo HtmlInput::hidden("cat", $cat); + echo HtmlInput::hidden('choice_cat', 0); + } + $nooperation = new ICheckBox('noop'); + $nooperation->selected = (isset($_GET['noop'])) ? true : false; + echo Dossier::hidden(); + ?> +
+ input() ?> +
+
+ + +
+
+
+