noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 65/119: Rewriting of card attributes


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 65/119: Rewriting of card attributes
Date: Mon, 26 Oct 2020 18:27:23 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 5f61996d4af7627cab12f919c3d205fe631352da
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Sat Oct 10 13:31:19 2020 +0200

    Rewriting of card attributes
---
 include/ajax/ajax_card.php                   |  28 +--
 include/ajax/ajax_card_attribute.php         | 102 +++++++++
 include/card_attr.inc.php                    | 150 +------------
 include/class/card_attribut_mtable.class.php | 201 +++++++++++++++++
 include/class/fiche_attr.class.php           | 317 +++++++++------------------
 include/lib/manage_table_sql.class.php       |  17 +-
 include/lib/message_javascript.php           |   1 +
 sql/upgrade.sql                              |   5 +
 8 files changed, 431 insertions(+), 390 deletions(-)

diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php
index aa73b65..fe8834f 100644
--- a/include/ajax/ajax_card.php
+++ b/include/ajax/ajax_card.php
@@ -99,31 +99,9 @@ $extra="";
 $http=new \HttpInput();
 switch($op2)
 {
-    /* ------------------------------------------------------------ */
-    /* Remove a attribut */
-    /* ------------------------------------------------------------ */
-case 'rmfa':
-    if ($g_user->check_action(FICCAT)==0)exit();
-
-    ob_start();
-    try
-    {
-        $ad_id= $http->get("ad_id","number");
-        $cn->start();
-        $fa=new Fiche_Attr($cn,$ad_id);
-        $fa->delete();
-        $cn->commit();
-    }
-    catch (Exception $e)
-    {
-        $cn->rollback();
-        record_log($e->getMessage());
-          record_log($e);
-        echo $e->getMessage();
-    }
-    $html=ob_get_contents();
-    ob_end_clean();
-    break;
+    case 'attribute':
+        require_once "ajax/ajax_card_attribute.php";
+        return ;
     /* ------------------------------------------------------------ */
     /* Display card detail */
     /* ------------------------------------------------------------ */
diff --git a/include/ajax/ajax_card_attribute.php 
b/include/ajax/ajax_card_attribute.php
new file mode 100644
index 0000000..feedef0
--- /dev/null
+++ b/include/ajax/ajax_card_attribute.php
@@ -0,0 +1,102 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta 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 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta 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 PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2002-2020) Author Dany De Bontridder <danydb@noalyss.eu>
+
+/**
+ * @file
+ * @brief answer to card_attr_inc.php
+ */
+global $g_user;
+// security
+$g_user->can_request("CFGATCARD");
+require_once NOALYSS_INCLUDE."/lib/inplace_switch.class.php";
+require_once NOALYSS_INCLUDE.'/class/card_attribut_mtable.class.php';
+
+$http=new HttpInput();
+
+try
+{
+    $action=$http->request("action", "string");
+}
+catch (Exception $ex)
+{
+    record_log("ACA01".$ex->getMessage().$ex->getTraceAsString());
+}
+
+if ($action=="enable_search")
+{
+    $value=$http->request("value");
+    $ad_id=$http->request("ad_id");
+    $name=$http->request("name");
+    if ($value==1)
+    {
+        $cn->exec_sql("update attr_def set ad_search_followup=0 where 
ad_id=$1", [$ad_id]);
+        $value=0;
+    }
+    else
+    {
+        $cn->exec_sql("update attr_def set ad_search_followup=1 where 
ad_id=$1", [$ad_id]);
+        $value=1;
+    }
+    $ic=new Inplace_Switch($name, $value);
+    $ic->set_callback("ajax_misc.php");
+    $ic->add_json_param("op", "card");
+    $ic->add_json_param("gDossier", Dossier::id());
+    $ic->add_json_param("op2", "attribute");
+    $ic->add_json_param("action", "enable_search");
+    $ic->add_json_param("ad_id", $ad_id);
+    $ic->add_json_param("ctl", $ad_id);
+    echo $ic->input();
+}
+else
+{
+    $obj=new Fiche_Attr($cn);
+    $mtable=new Card_Attribut_MTable($obj);
+    $mtable->add_json_param("op", "card");
+    $mtable->add_json_param("op2", "attribute");
+    $mtable->set_callback("ajax_misc.php");
+    $mtable->set_object_name($http->request("ctl"));
+    $ad_id=$http->request("p_id");
+    $mtable->get_table()->set_parameter("id", $ad_id);
+    switch ($action)
+    {
+        case "input":
+            $mtable->set_pk($ad_id);
+            $mtable->send_header();
+            echo $mtable->ajax_input()->saveXML();
+
+            break;
+        case "save":
+            $mtable->set_pk($http->request("p_id"));
+            $mtable->send_header();
+            echo $mtable->ajax_save()->saveXML();
+
+
+            break;
+        case "delete":
+            $mtable->set_pk($http->request("p_id"));
+            $mtable->send_header();
+            echo $mtable->ajax_delete()->saveXML();
+            break;
+        default:
+            break;
+    }
+}
+?>
diff --git a/include/card_attr.inc.php b/include/card_attr.inc.php
index fa8bcae..c098f7b 100644
--- a/include/card_attr.inc.php
+++ b/include/card_attr.inc.php
@@ -20,146 +20,18 @@
 // Copyright Author Dany De Bontridder danydb@aevalys.eu
 
 /*!\file
- * \brief Manage the attributs
+ * \brief Manage the attributs ,CFGATCARD
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class/fiche_attr.class.php';
-global $http;
-
-
-$fa=new Fiche_Attr($cn);
-
-/////////////////////////////////////////////////////////////////////////////
-// If data are post we save them first
-/////////////////////////////////////////////////////////////////////////////
-if ( isset($_POST['save']))
-{
-    try
-    {
-        $ad_id=$http->post('ad_id');
-        $ad_text=$http->post('desc');
-        $ad_type=$http->post('type');
-        $ad_size=$http->post('size');
-        $ad_extra=$http->post('extra');
-        $cn->start();
-        for ($e=0;$e<count($ad_id);$e++)
-        {
-            $fa->set_parameter('id',$ad_id[$e]);
-            $fa->set_parameter('desc',$ad_text[$e]);
-            $fa->set_parameter('type',$ad_type[$e]);
-            $fa->set_parameter('size',$ad_size[$e]);
-            $fa->set_parameter('extra',$ad_extra[$e]);
-            if ( trim($ad_text[$e])!='' && trim($ad_type[$e])!='')
-                $fa->save();
-        }
-        $cn->commit();
-    }
-    catch (Exception $e)
-    {
-          record_log($e);
-      alert($e->getMessage());
-        $cn->rollback();
-    }
-
-}
-/* show list of existing */
-$gDossier=dossier::id();
-$array=$fa->seek();
-
-$select_type=new ISelect('type[]');
-$select_type->table=0;
-$desc=new IText('desc[]');
-$desc->size=50;
-$size=new INum('size[]');
-$size->size=5;
-$extra=new IText('extra[]');
-
-$select_type->value=array(
-                        array('value'=>'text','label'=>_('Texte')),
-                        array('value'=>'numeric','label'=>_('Nombre')),
-                        array('value'=>'date','label'=>_('Date')),
-                        array('value'=>'zone','label'=>_('Zone de texte')),
-                        array('value'=>'poste','label'=>_('Poste Comptable')),
-                        array('value'=>'card','label'=>_('Fiche')),
-                        array('value'=>'select','label'=>_('Selection'))
-                    );
-
+require_once NOALYSS_INCLUDE.'/class/card_attribut_mtable.class.php';
+
+$obj=new Fiche_Attr($cn);
+$mtable=new Card_Attribut_MTable($obj);
+$mtable->add_json_param("op", "card");
+$mtable->add_json_param("op2", "attribute");
+$mtable->set_callback("ajax_misc.php");
+$mtable->create_js_script();
 echo '<div class="content">';
-echo '<form method="post">';
-
-echo HtmlInput::hidden('sa','fat');
-echo HtmlInput::hidden('p_action','divers');
-echo '<table id="tb_rmfa">';
-echo '<tr>';
-echo th(_("id"));
-echo th(_("Description"));
-echo th(_("Type"));
-echo th(_("Taille"));
-echo th(_("Paramètre"));
-echo '</tr>';
-for ($e=0;$e<count($array);$e++)
-{
-    $row=$array[$e];
-    $r='';
-    
$r.=td(HtmlInput::hidden('ad_id[]',$row->get_parameter('id')).$row->get_parameter('id'));
-    $select_type->selected=$row->get_parameter('type');
-    $desc->value=$row->get_parameter('desc');
-    $size->value=$row->get_parameter('size');
-    $extra->value=$row->get_parameter('extra');
-    $remove=new IButton('rmfa'.$e);
-    $remove->label=_('Effacer');
-    if ( $row->get_parameter('id')>= 9000)
-    {
-        $select_type->readOnly=false;
-        $desc->readOnly=false;
-        $size->readOnly=false;
-        $extra->readOnly=false;
-
-        $desc->style=' class="input_text" ';
-        $r.=td($desc->input());
-        $r.=td($select_type->input());
-        $r.=td($size->input());
-        $r.=td($extra->input());
-
-        $remove->javascript=sprintf('confirm_box(\'tb_rmfa\',\'Vous  confirmez 
?\',function() { removeCardAttribut(%d,%d,\'tb_rmfa\',$(\'rmfa%d\') );})',
-                                    $row->get_parameter('id'),$gDossier,$e);
-        $msg='<span class="notice">'._("Attention : effacera les données qui y 
sont liées").' </span>';
-        $r.=td($remove->input().$msg);
-    }
-    else
-    {
-        $select_type->readOnly=true;
-        $desc->readOnly=true;
-        $size->readOnly=true;
-        $extra->readOnly=true;
-
-        $r.=td($desc->input().HtmlInput::hidden('type[]',''));
-        $r.=td($select_type->input());
-        $r.=td($size->input());
-        $r.=td($extra->input());
-        $r.=td("");
-    }
-
-
-
-
-    echo tr($r);
-
-}
-$desc->readOnly=false;
-$select_type->readOnly=false;
-$size->readOnly=false;
-$extra->readOnly=false;
-$desc->value='';
-$select_type->selected=-1;
-$r=td(_("Nouvel 
attribut").HtmlInput::hidden('ad_id[]','0'),'class="highlight"');
-$r.=td($desc->input());
-$r.=td($select_type->input());
-$r.=td($size->input());
-$r.=td($extra->input());
-echo tr($r);
-
-echo '</table>';
-echo HtmlInput::submit('save',_('Sauver'));
-echo '</form>';
+echo $mtable->display_table("order by ad_text");
 echo '</div>';
+
diff --git a/include/class/card_attribut_mtable.class.php 
b/include/class/card_attribut_mtable.class.php
new file mode 100644
index 0000000..5638384
--- /dev/null
+++ b/include/class/card_attribut_mtable.class.php
@@ -0,0 +1,201 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta 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 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta 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 PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2002-2020) Author Dany De Bontridder <danydb@noalyss.eu>
+
+/**
+ * @file
+ * @brief manage the table attr_def 
+ * @see card_attr.inc.php
+ */
+require_once NOALYSS_INCLUDE."/class/fiche_attr.class.php";
+require_once NOALYSS_INCLUDE."/lib/manage_table_sql.class.php";
+require_once NOALYSS_INCLUDE."/lib/inplace_switch.class.php";
+
+class Card_Attribut_MTable extends Manage_Table_SQL
+{
+
+    function __construct(\Data_SQL $p_table)
+    {
+        parent::__construct($p_table);
+        $this->set_property_visible("ad_id", FALSE);
+        $this->set_property_updatable("ad_id", FALSE);
+        $this->set_col_label("ad_text", _("Nom"));
+        $this->set_col_label("ad_type", _("Type"));
+        $this->set_col_label('ad_size', _("Taille"));
+        $this->set_col_label("ad_extra", _("Option sup."));
+        $this->set_col_label("ad_search_followup", _("Recherche suivi"));
+
+        $this->set_col_type("ad_search_followup", "custom");
+        $this->set_col_type("ad_text", "custom");
+        $this->set_col_type("ad_size", "numeric");
+        $this->set_col_type("ad_extra", "text");
+        $this->set_col_type("ad_type", "select",
+                array(
+                    ["value"=>"text", "label"=>_("Texte")],
+                    ["value"=>"date", "label"=>_("Date")],
+                    ["value"=>"numeric", "label"=>_("Nombre")],
+                    ["value"=>"select", "label"=>_("Choix")],
+                    ["value"=>"card", "label"=>_("Fiche")],
+                    ["value"=>"zone", "label"=>_("Zone de texte")],
+                    ["value"=>"poste", "label"=>_("Poste comptable")]
+        ));
+        $this->set_col_tips("ad_search_followup", 77);
+        // to prevent a call to this function for each row
+        $this->dossier_id=Dossier::id();
+    }
+
+    /**
+     * Display row of table attr_def
+     * @param array $row 
+     */
+    function display_row($row)
+    {
+        tracedebug("card_attribute.log", $row);
+        if ($row['ad_id']>=9000)
+        {
+            $this->set_delete_row(TRUE);
+            $this->set_update_row(TRUE);
+        }
+        else
+        {
+            $this->set_delete_row(FALSE);
+            $this->set_update_row(FALSE);
+        }
+
+        parent::display_row($row);
+    }
+
+    /**
+     * For the type custom , we can call a function to display properly the 
value
+     * @param $p_key string key name
+     * @param $p_value string value
+     * @see input_custom
+     * @see set_type
+     * @note must return a string which will be in surrounded by td in the 
function display_row
+     * @return string
+     */
+    function display_row_custom($p_key, $p_value, $p_id=0)
+    {
+        if ($p_key=="ad_search_followup")
+        {
+            $ic=new Inplace_Switch(uniqid("search_follow_up"), $p_value);
+            $ic->set_callback("ajax_misc.php");
+            $ic->add_json_param("op", "card");
+            $ic->add_json_param("gDossier", $this->dossier_id);
+            $ic->add_json_param("op2", "attribute");
+            $ic->add_json_param("action", "enable_search");
+            $ic->add_json_param("ad_id", $p_id);
+            $ic->add_json_param("ctl", $p_id);
+            $ret=$ic->input();
+
+            return $ret;
+        }
+        if ($p_key == "ad_text"){
+            return $p_value;
+        }
+        return;
+    }
+
+    /**
+     * For the type custom , we can call a function to display properly the 
value
+     * @param $p_key string key name
+     * @param $p_value string value
+     * @see input_custom
+     * @see set_type
+     * @note must return a string which will be in surrounded by td in the 
function display_row
+     * @return string
+     */
+    function input_custom($p_key, $p_value)
+    {
+        if ($p_key=="ad_search_followup")
+        {
+            $p_id=$this->get_table()->get("ad_id");
+            $ic=new ISelect("ad_search_followup", $p_value);
+            $ic->value=array(["value"=>0, "label"=>_("Non")],
+                ["value"=>0, "label"=>_("Oui")]
+            );
+            $ic->set_value($p_value);
+            echo $ic->input();
+        }
+        /**
+         * Bug in firefox if id=ad_text , the widget is not displaid 
+         */
+        if ( $p_key == "ad_text") 
+        {
+            $text=new IText("ad_text",$p_value);
+            $text->id=uniqid();
+            echo $text->input();
+        }
+        echo "";
+        return;
+    }
+    
+    function check()
+    {
+        $nb_error=0;
+        $object_sql=$this->get_table();
+
+        if ($object_sql->get("ad_id")<9000 && $object_sql->get("ad_id")!=-1)
+        {
+            $this->set_error("ad_id",_("Bloqué"));
+            return false;
+        }
+        
+        // Duplicate
+        $count="select count(*) 
+                from attr_def as ad1 
+                where 
+                upper(trim(ad1.ad_text)) = upper(trim($1))
+                and ad1.ad_id != $2
+                ";
+        $count_duplicate=$object_sql->cn->get_value($count, 
[$object_sql->ad_text, $object_sql->ad_id]);
+        if ($count_duplicate>0)
+        {
+            $this->set_error("ad_text", _("Doublon"));
+            $nb_error++;
+        }
+
+        // Name empty
+        if (trim($object_sql->ad_text)=="")
+        {
+            $this->set_error("ad_text", _("Description ne peut pas être 
vide"));
+            $nb_error++;
+        }
+        // select protect 
+
+
+        if ($nb_error>0)
+            return false;
+        return true;
+    }
+
+    function delete() {
+         $object_sql=$this->get_table();
+         $db=$object_sql->cn;
+         try {
+             $db->start();
+              $object_sql=$this->get_table()->delete();
+             $db->commit();
+         } catch (Exception $ex) {
+             $db->rollback();
+            throw new Exception (_("Effacement bloqué : attribut utilisé"));
+         }
+    }
+}
diff --git a/include/class/fiche_attr.class.php 
b/include/class/fiche_attr.class.php
index c764731..7133a0a 100644
--- a/include/class/fiche_attr.class.php
+++ b/include/class/fiche_attr.class.php
@@ -1,286 +1,165 @@
 <?php
+
 //This file is part of NOALYSS and is under GPL 
 //see licence.txt
 /**
- *@brief Manage the table attr_def
+ * @brief Manage the table attr_def
  *
  *
  */
 require_once NOALYSS_INCLUDE.'/class/database.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE."/database/attr_def_sql.class.php";
 
-class Fiche_Attr
+class Fiche_Attr extends Attr_def_SQL
 {
     /* example private 
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
 */
 
-    protected 
$variable=array("id"=>"ad_id","desc"=>"ad_text","type"=>"ad_type","size"=>"ad_size","extra"=>"ad_extra");
-    function __construct ($p_cn,$p_id=0)
+    function __construct($p_cn, $p_id=0)
     {
-        $this->cn=$p_cn;
-        if ( $p_id == 0 )
-        {
-            /* Initialize an empty object */
-            foreach ($this->variable as $key=>$value) $this->$value='';
-        }
-        else
-        {
-            /* load it */
-            $this->ad_id=$p_id;
-            $this->load();
-        }
+        parent::__construct($p_cn, $p_id);
     }
+
     public function get_parameter($p_string)
     {
-        if ( array_key_exists($p_string,$this->variable) )
-        {
-            $idx=$this->variable[$p_string];
-            return $this->$idx;
-        }
-        else
-            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
-    }
-    public function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,$this->variable) )
-        {
-            $idx=$this->variable[$p_string];
-            $this->$idx=$p_value;
-        }
-        else
-            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
+        return $this->getp($p_string);
     }
-    public function get_info()
+
+    public function set_parameter($p_string, $p_value)
     {
-        return var_export($this,true);
+        $this->setp($p_string, $p_value);
     }
+
     public function verify()
     {
         // Verify that the elt we want to add is correct
         /* verify only the datatype */
-        if ( strlen(trim($this->ad_text))==0)
-            throw new Exception('La description ne peut pas être vide',1);
-        if ( strlen(trim($this->ad_type))==0)
-            throw new Exception('Le type ne peut pas être vide',1);
+        if (strlen(trim($this->ad_text))==0)
+            throw new Exception('La description ne peut pas être vide', 1);
+        if (strlen(trim($this->ad_type))==0)
+            throw new Exception('Le type ne peut pas être vide', 1);
         $this->ad_type=strtolower($this->ad_type);
-        if ( 
in_array($this->ad_type,array('date','text','numeric','zone','poste','card','select'))==false)
-            throw new Exception('Le type doit être text, numeric,poste, card, 
select ou date',1);
-        if ( trim($this->ad_size)=='' || 
isNumber($this->ad_size)==0||$this->ad_size>22)
+        if (in_array($this->ad_type, array('date', 'text', 'numeric', 'zone', 
'poste', 'card', 'select'))==false)
+            throw new Exception('Le type doit être text, numeric,poste, card, 
select ou date', 1);
+        if 
(trim($this->ad_size)==''||isNumber($this->ad_size)==0||$this->ad_size>22)
         {
             switch ($this->ad_type)
             {
-            case 'text':
+                case 'text':
+                    $this->ad_size=22;
+                    break;
+                case 'numeric':
+                    $this->ad_size=9;
+                    break;
+                case 'date':
+                    $this->ad_size=8;
+                    break;
+                case 'zone':
                     $this->ad_size=22;
-                break;
-            case 'numeric':
-                $this->ad_size=9;
-                break;
-            case 'date':
-                $this->ad_size=8;
-                break;
-            case 'zone':
-                $this->ad_size=22;
-                break;
+                    break;
 
-            default:
-                $this->ad_size=22;
+                default:
+                    $this->ad_size=22;
             }
         }
-               if ( $this->ad_type == 'numeric' ) {
-                       
$this->ad_extra=(trim($this->ad_extra)=='')?'2':$this->ad_extra;
-                       if (isNumber($this->ad_extra) == 0) throw new Exception 
("La précision doit être un chiffre");
-
-               }
-               if ( $this->ad_type == 'select')
+        if ($this->ad_type=='numeric')
         {
-                if (trim($this->ad_extra)=="") throw new Exception ("La 
requête SQL est vide ");
-               if ( preg_match('/^\h*select/i',$this->ad_extra)  == 0) throw 
new Exception ("La requête SQL doit commencer par SELECT ");
-                try{
-
-                        $this->cn->exec_sql($this->ad_extra);
-                }catch (Exception $e)
-                {
-                      record_log($e);
-                    throw new Exception ("La requête SQL 
".h($this->ad_extra)." est invalide ");
-                }
+            $this->ad_extra=(trim($this->ad_extra)=='')?'2':$this->ad_extra;
+            if (isNumber($this->ad_extra)==0)
+                throw new Exception("La précision doit être un chiffre");
         }
-    }
-    public function save()
-    {
-
-        /* please adapt */
-        if (  $this->ad_id == 0 )
-            $this->insert();
-        else
-            $this->update();
-    }
-    /**
-     *@brief retrieve array of object thanks a condition
-     *@param $cond condition (where clause)
-     *@param $p_array array for the SQL stmt
-     *@see Database::get_array
-     *@return an empty array if nothing is found
-     */
-    public function seek($cond='',$p_array=null)
-    {
-        if ( $cond != '')
-            $sql="select * from attr_def where $cond order by ad_text";
-        else
-            $sql="select * from attr_def order by ad_text";
-
-        $aobj=array();
-        $array= $this->cn->get_array($sql,$p_array);
-        // map each row in a object
-        $size=$this->cn->count();
-        if ( $size == 0 ) return $aobj;
-        for ($i=0;$i<$size;$i++)
+        if ($this->ad_type=='select')
         {
-            $oobj=new Fiche_Attr ($this->cn);
-            foreach ($array[$i] as $idx=>$value)
+            if (trim($this->ad_extra)=="")
+                throw new Exception("La requête SQL est vide ");
+            if (preg_match('/^\h*select/i', $this->ad_extra)==0)
+                throw new Exception("La requête SQL doit commencer par SELECT 
");
+            try
+            {
+
+                $this->cn->exec_sql($this->ad_extra);
+            }
+            catch (Exception $e)
             {
-                $oobj->$idx=$value;
+                record_log($e);
+                throw new Exception("La requête SQL ".h($this->ad_extra)." est 
invalide ");
             }
-            $aobj[]=clone $oobj;
         }
-        return $aobj;
     }
-    public function insert()
-    {
-        try{
-        $this->verify();
-        /*  please adapt */
-        $sql="insert into attr_def(ad_text
-             ,ad_type,ad_size,ad_extra
-             ) values ($1
-             ,$2,$3,$4
-             ) returning ad_id";
-
-        $this->ad_id=$this->cn->get_value(
-                         $sql,
-                         array( 
$this->ad_text,$this->ad_type,$this->ad_size,$this->ad_extra
-                              )
-                     );
-        } catch (Exception $e)
-        {
-              record_log($e);
-            throw $e;
-        }
 
-    }
 
     public function update()
     {
         try
         {
-         $this->verify();
-        if ( $this->ad_id < 9000) return;
-        /*   please adapt */
-        $sql=" update attr_def set ad_text = $1
-             ,ad_type = $2,ad_size=$4,ad_extra=$5
-             where ad_id= $3";
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->ad_text
-                       ,$this->ad_type
-                       ,$this->ad_id,$this->ad_size,$this->ad_extra)
-             );
-        }catch (Exception $e)
-        {
-              record_log($e);
-            throw $e;
-        }
-
-
-    }
-    /**
-     *@brief load a object
-     *@return 0 on success -1 the object is not found
-     */
-    public function load()
-    {
-
-        $sql="select ad_text
-             ,ad_type,ad_size,ad_extra
-             from attr_def where ad_id=$1";
-        /* please adapt */
-        $res=$this->cn->get_array(
-                 $sql,
-                 array($this->ad_id)
-             );
-
-        if ( count($res) == 0 )
-        {
-            /* Initialize an empty object */
-            foreach ($this->variable as $key=>$value) $this->$key='';
-
-            return -1;
+            $this->verify();
+            if ($this->ad_id<9000)
+                return;
+            /*   please adapt */
+            parent::update();
         }
-        foreach ($res[0] as $idx=>$value)
+        catch (Exception $e)
         {
-            $this->$idx=$value;
+            record_log($e);
+            throw $e;
         }
-        return 0;
     }
 
     public function delete()
     {
-        if ($this->ad_id < 9000)  return;
-        $sql=$this->cn->exec_sql("delete from fiche_detail  where ad_id=$1 ",
-                                 array($this->ad_id));
+        if ($this->ad_id<9000)
+            return;
+        $sql=$this->cn->exec_sql("delete from fiche_detail  where ad_id=$1 ", 
array($this->ad_id));
 
-       $sql="delete from jnt_fic_attr where ad_id=$1";
-        $res=$this->cn->exec_sql($sql,array($this->ad_id));
+        $sql="delete from jnt_fic_attr where ad_id=$1";
+        $res=$this->cn->exec_sql($sql, array($this->ad_id));
 
         $sql="delete from attr_def where ad_id=$1";
-        $res=$this->cn->exec_sql($sql,array($this->ad_id));
-
+        $res=$this->cn->exec_sql($sql, array($this->ad_id));
     }
-    /**
-     * Unit test for the class
-     */
-    static function test_me()
-    {
-        $cn=new Database(25);
-        $cn->start();
-        echo h2info('Test object vide');
-        $obj=new Fiche_Attr($cn);
-        var_dump($obj);
 
-        echo h2info('Test object NON vide');
-        $obj->set_parameter('j_id',3);
-        $obj->load();
-        var_dump($obj);
-
-        echo h2info('Update');
-        $obj->set_parameter('j_qcode','NOUVEAU CODE');
-        $obj->save();
-        $obj->load();
-        var_dump($obj);
-
-        echo h2info('Insert');
-        $obj->set_parameter('j_id',0);
-        $obj->save();
-        $obj->load();
-        var_dump($obj);
-
-        echo h2info('Delete');
-        $obj->delete();
-        echo (($obj->load()==0)?'Trouve':'non trouve');
-        var_dump($obj);
-        $cn->rollback();
-
-    }
-    /*!
-     *@brief used with a usort function, to sort an array of Attribut on the 
attribut_id (ad_id)
+    /* !
+     * @brief used with a usort function, to sort an array of Attribut on the 
attribut_id (ad_id)
      */
-    static function sort_by_id($o1,$o2)
+
+    static function sort_by_id($o1, $o2)
     {
-        if ( $o1->ad_id > $o2->ad_id ) return 1;
-        if ( $o1->ad_id == $o2->ad_id ) return 0;
+        if ($o1->ad_id>$o2->ad_id)
+            return 1;
+        if ($o1->ad_id==$o2->ad_id)
+            return 0;
         return -1;
     }
 
+    public function save()
+    {
 
+        /* please adapt */
+        if ($this->ad_id < 1)
+        {
+            $this->ad_id=-1;
+            $this->insert();
+        }
+        else
+            $this->update();
+    }
+    public function to_array($prefix="")
+    {
+        
+        $array=array();
+        foreach ($this->name as $key=> $value)
+        {
+            $nkey=$prefix.$value;
+            $array[$nkey]=$this->$value;
+//            $nkey=$prefix.$key;
+//            $array[$nkey]=$this->$value;
+//            
+        }
+        tracedebug("card_attribute.log",$array);
+        return $array;
+    }
 }
+
 //Fiche_Attr::test_me();
 
 
diff --git a/include/lib/manage_table_sql.class.php 
b/include/lib/manage_table_sql.class.php
index 116d61f..b0e8cfa 100644
--- a/include/lib/manage_table_sql.class.php
+++ b/include/lib/manage_table_sql.class.php
@@ -103,7 +103,7 @@ class Manage_Table_SQL
         foreach ($this->table->name as $key=> $value)
         {
 
-            $this->a_label_displaid[$value]=$value;
+            $this->a_label_displaid[$value]=$key;
             $this->a_order[$order]=$value;
             $this->a_prop[$value]=self::UPDATABLE|self::VISIBLE;
             $this->a_type[$value]=$this->table->type[$value];
@@ -833,9 +833,10 @@ function check()
      */
     function display_row($p_row)
     {
-
+        
+        $pk_id=$p_row[$this->table->primary_key];
         printf('<tr id="%s_%s">', $this->object_name,
-                $p_row[$this->table->primary_key])
+                $pk_id)
         ;
         
         if ($this->icon_mod=="left")
@@ -847,10 +848,11 @@ function check()
         for ($i=0; $i<$nb_order; $i++)
         {
             $v=$this->a_order[$i];
+            
             if ($i==0&&$this->icon_mod=="first"&&$this->can_update_row())
             {
                 $js=sprintf("onclick=\"%s.input('%s','%s');\"", 
$this->object_name,
-                        $p_row[$this->table->primary_key], $this->object_name);
+                        $pk_id, $this->object_name);
                 $td=($i == $this->col_sort ) ? sprintf('<td sort_value="X%s" 
>',$p_row[$v]):"<td>";
                 echo $td.HtmlInput::anchor($p_row[$v], "", $js).'</td>';
             }
@@ -878,7 +880,7 @@ function check()
                     
$nb_search=(is_array($array_to_search))?count($array_to_search):0;
                     $found=FALSE;
                     for ( $e=0;$e< $nb_search;$e++) {
-                        if (isset ($array_to_search[$e]['value']) && 
$array_to_search[$e]['value']==$value ) {
+                        if (isset ($array_to_search[$e]['value']) && 
$array_to_search[$e]['value']==$value )                          {
                             $found=TRUE;
                             echo td($array_to_search[$e]['label']);
                         }
@@ -891,7 +893,7 @@ function check()
                     
                 } elseif ($this->get_col_type($v)=="custom") {
                     // For custom col
-                    echo td($this->display_row_custom($v,$p_row[$v]));
+                    echo td($this->display_row_custom($v,$p_row[$v],$pk_id));
                 }
                 else {
                     echo td($p_row[$v]);
@@ -911,12 +913,13 @@ function check()
      * For the type custom , we can call a function to display properly the 
value
      * @param $p_key string key name
      * @param $p_value string value
+     * @param int $p_id id of the row (optional default 0)
      * @see input_custom
      * @see set_type
      * @note must return a string which will be in surrounded by td in the 
function display_row
      * @return string
      */
-    function display_row_custom($p_key,$p_value) {
+    function display_row_custom($p_key,$p_value,$p_id=0) {
         return $p_value;
     }
     /**
diff --git a/include/lib/message_javascript.php 
b/include/lib/message_javascript.php
index e9b9d1e..cebdf22 100644
--- a/include/lib/message_javascript.php
+++ b/include/lib/message_javascript.php
@@ -107,4 +107,5 @@ content[73]="<?php echo _("Mettre à oui pour un journal 
dédié uniquement aux
 content[74]="<?php echo _('TVA due ou récupérable quand l\'opération est payée 
ou exécutée')?>";
 content[75]="<?php echo _('Journaux Achat ou vente en mode simple, TVA ou 
détaillé')?>";
 content[76]="<?php echo _('Il est conseillé d\'avoir un quickcode de moins de 
9 car.')?>";
+content[77]="<?php echo _("Permet de chercher dans le suivi pour les contacts 
multiques")?>";
 </script>
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 54c62c6..6ee0d7e 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -1,2 +1,7 @@
 ALTER TABLE public.document_option ADD do_option varchar NULL;
 COMMENT ON COLUMN public.document_option.do_option IS 'Option for the detail';
+
+alter table attr_def add column ad_search_followup int;
+alter table attr_def alter column ad_search_followup set default 1;
+update attr_def set ad_search_followup=1;
+comment on column attr_def.ad_search_followup is '1 : search  available  from 
followup , 0  : search not available in followup'



reply via email to

[Prev in Thread] Current Thread [Next in Thread]