From 66b46ecef72b3073d36176f570789380d4544020 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sat, 21 Dec 2013 12:48:19 +0000 Subject: [PATCH] Configure default menu --- html/admin/sql/patch/upgrade111.sql | 16 ++++ include/ajax_view_action.php | 8 +- include/class_acc_ledger.php | 5 +- include/class_default_menu.php | 141 ++++++++++++++++++++++++++++ include/class_default_menu_sql.php | 45 +++++++++ include/class_follow_up.php | 3 +- include/class_phpcompta_sql.php | 2 +- include/default_menu.inc.php | 28 ++++++ include/template/detail-action.php | 5 +- 9 files changed, 244 insertions(+), 9 deletions(-) create mode 100644 include/class_default_menu.php create mode 100644 include/class_default_menu_sql.php create mode 100644 include/default_menu.inc.php diff --git a/html/admin/sql/patch/upgrade111.sql b/html/admin/sql/patch/upgrade111.sql index 908876bed..be7d5bc1e 100644 --- a/html/admin/sql/patch/upgrade111.sql +++ b/html/admin/sql/patch/upgrade111.sql @@ -8,6 +8,22 @@ insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_de values ('MANAGER','GESTION',1,25,'E',0), ('MANAGER','GESTION',2,25,'E',0); +insert into menu_ref(me_code,me_menu,me_file, me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue) +values +('CFGDEFMENU','Menu par défaut','default_menu.inc.php',null,'Configuration des menus par défaut',null,null,'ME','Configuration des menus par défaut, ces menus sont appelés par des actions dans d''autres menus'); + +insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_default) +values +('CFGDEFMENU','MOD',1,30,'E',0); + + +create table menu_default +( + md_id serial primary key, + md_code text not null unique , + me_code text not null +); +insert into menu_default (md_code,me_code) values ('code_invoice','COMPTA/VENMENU/VEN'),('code_follow','GESTION/FOLLOW'); update menu_ref set me_file='customer.inc.php' where me_code ='CUST'; update version set val=112; diff --git a/include/ajax_view_action.php b/include/ajax_view_action.php index 14c8c5d93..a76f31731 100644 --- a/include/ajax_view_action.php +++ b/include/ajax_view_action.php @@ -29,14 +29,18 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); ob_start(); require_once 'class_follow_up.php'; +require_once 'class_default_menu.php'; + echo HtmlInput::title_box(_("Détail action"), $div); $act = new Follow_Up($cn); $act->ag_id = $ag_id; $act->get(); if ($g_user->can_write_action($ag_id) == true || $g_user->can_read_action($ag_id) == true || $act->ag_dest == -1) -{ +{ + $menu=new Default_Menu(); echo $act->Display('READ', false, "ajax", ""); - $action=HtmlInput::array_to_string(array("gDossier","ag_id"), $_GET)."&ac=FOLLOW&sa=detail"; + //$action=HtmlInput::array_to_string(array("gDossier","ag_id"), $_GET)."&ac=FOLLOW&sa=detail"; + $action= "do.php?".http_build_query(array("gDossier"=>Dossier::id(),"ag_id"=>$ag_id,"ac"=>$menu->get('code_follow'),"sa"=>"detail")); if ( $_GET['mod']== 1) : ?> Modifier diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index e4963c165..19b83953c 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -3702,8 +3702,9 @@ class Acc_Ledger extends jrn_def_sql left join vw_poste_qcode using(f_id) where ag_id=$1',array($p_ag_id)); - $array['nb_item']=$this->db->size(); - for ($i=0;$i<$array['nb_item'];$i++) + + $array['nb_item']=($this->nb > count($a_item))?$this->nb:count($a_item); + for ($i=0;$iseek(); + for ($i = 0; $i < Database::num_row($ret); $i++) + { + $tmenu = $menu->next($ret, $i); + $idx = $tmenu->getp('md_code'); + $this->a_menu_def[$idx] = $tmenu->getp('me_code'); + } + $this->code = explode(',', 'code_follow,code_invoice'); + } + + function input_value() + { + $code_invoice = new IText('code_invoice', $this->a_menu_def['code_invoice']); + $code_follow = new IText('code_follow', $this->a_menu_def['code_follow']); + echo '

' . _('Code pour création facture depuis gestion') . $code_invoice->input() . '

'; + echo '

' . _('Code pour appel gestion') . $code_follow->input() . '

'; + } + + private function check_code($p_string) + { + global $cn; + $count = $cn->get_value('select count(*) from v_menu_description_favori where ' + . 'code = $1', array($p_string)); + if ($count == 0) + { + throw new Exception('code_inexistant'); + } + } + + function verify() + { + foreach ($this->code as $code) + { + $this->check_code($this->a_menu_def[$code]); + } + } + + function set($p_string, $p_value) + { + if (in_array($p_string, $this->code) == false) + { + throw new Exception("code_invalid"); + } + $this->a_menu_def[$p_string] = $p_value; + } + function get ($p_string) + { + return $this->a_menu_def[$p_string]; + } + + function save() + { + global $cn; + try + { + $this->verify(); + foreach ($this->code as $key => $value) + { + $cn->exec_sql('update menu_default set me_code=$1 where + md_code =$2', array($value,$this->a_menu_def[$value])); + } + } catch (Exception $e) + { + $e->getTraceAsString(); + throw $e; + } + } + + static function test_me() + { + global $cn, $g_user, $g_succeed, $g_failed; + + echo h2('Constructor', ''); + $a = new Default_Menu(); + echo $g_succeed . 'constructor'; + if (count($a->a_menu_def) != 2) + echo $g_failed; + else + echo $g_succeed; + echo h2("input_value", ""); + $a->input_value(); + echo h2('verify'); + $a->verify(); + try { + echo h2('Verify must failed'); + $a->set('code_follow', 'MEMNU/MEMEM/'); + $a->verify(); + } catch (Exception $e) { + echo $g_succeed. " OK "; + } + echo h2('Verify must succeed'); + try { + $a->set('code_follow', 'GESTION/FOLLOW'); + $a->verify(); + echo $g_succeed. " OK "; + } catch (Exception $e) + { + echo $g_failed."NOK"; + } + echo h2('Save'); + $a->save(); + echo h2('GET'); + echo ( assert($a->get('code_follow')=='GESTION/FOLLOW') )?$g_succeed.$a->get('code_follow'):$g_failed.$a->get('code_follow'); + echo ( assert($a->get('code_invoice')=='COMPTA/VENMENU/VEN') )?$g_succeed.$a->get('code_invoice'):$g_failed.$a->get('code_invoice'); + echo $a->get('code_invoice'); + } + +} diff --git a/include/class_default_menu_sql.php b/include/class_default_menu_sql.php new file mode 100644 index 000000000..217e51966 --- /dev/null +++ b/include/class_default_menu_sql.php @@ -0,0 +1,45 @@ +table = "public.menu_default"; + $this->primary_key = "md_id"; + + $this->name = array( + "md_id"=>"md_id", + "md_code" => "md_code", + "me_code" => "me_code" + ); + $this->type = array( + "md_id"=>"md_id" + ,"md_code" => "text" + , "me_code" => "text" + ); + $this->default = array( + "md_id" + ); + global $cn; + + parent::__construct($cn, $p_id); + } + +} diff --git a/include/class_follow_up.php b/include/class_follow_up.php index 941acbf31..47d738119 100644 --- a/include/class_follow_up.php +++ b/include/class_follow_up.php @@ -38,7 +38,7 @@ require_once('class_inum.php'); require_once 'class_sort_table.php'; require_once 'class_irelated_action.php'; require_once 'class_tag.php'; - +require_once 'class_default_menu.php'; /** * \file * \brief class_action for manipulating actions @@ -521,6 +521,7 @@ class Follow_Up $r.=$Hid->input("nb_item", $article_count); $r.=HtmlInput::request_to_hidden(array("closed_action","remind_date_end","remind_date","sag_ref","only_internal","state","qcode", "ag_dest_query", "action_query", "tdoc", "date_start", "date_end", "hsstate","searchtag")); $a_tag=$this->tag_get(); + $menu=new Default_Menu(); /* get template */ ob_start(); require 'template/detail-action.php'; diff --git a/include/class_phpcompta_sql.php b/include/class_phpcompta_sql.php index fbe4e222f..c0b586c7d 100644 --- a/include/class_phpcompta_sql.php +++ b/include/class_phpcompta_sql.php @@ -71,7 +71,7 @@ class table_name_sql extends phpcompta_sql * @endcode * */ -class phpcompta_sql +class Phpcompta_SQL { function __construct(&$p_cn, $p_id = -1) diff --git a/include/default_menu.inc.php b/include/default_menu.inc.php new file mode 100644 index 000000000..728350cb6 --- /dev/null +++ b/include/default_menu.inc.php @@ -0,0 +1,28 @@ +set('code_follow',$_POST['code_follow']); + $a_default->set('code_invoice',$_POST['code_invoice']); + try + { + $a_default->save(); + echo h2("Sauvé",'class="notice"',$g_succeed); + } catch (Exception $ex) + { + echo h2("Code menu invalide",'class="notice"',$g_failed); + } +} + +echo '
'; +echo HtmlInput::hidden('ac',$_REQUEST['ac']); +echo Dossier::hidden(); +$a_default->input_value(); +echo HtmlInput::submit('save_menu_default', "Sauver"); +echo '
'; +?> \ No newline at end of file diff --git a/include/template/detail-action.php b/include/template/detail-action.php index b11b5680a..93e584702 100644 --- a/include/template/detail-action.php +++ b/include/template/detail-action.php @@ -1,4 +1,3 @@ -
@@ -364,8 +363,8 @@ function toggleShowDetail() {

Dossier::id(),'ag_id'=>$this->ag_id,'create_invoice'=>1,'ac'=>'VEN')); - echo HtmlInput::button_anchor("Transformer en facture","do.php?".$query,"create_invoice", "","button"); + $query= http_build_query(array('gDossier'=>Dossier::id(),'ag_id'=>$this->ag_id,'create_invoice'=>1,'ac'=>$menu->get('code_invoice'))); + echo HtmlInput::button_anchor("Transformer en facture","do.php?".$query,"create_invoice", ' target="_blank" ',"button"); ?>