diff --git a/include/action.inc.php b/include/action.inc.php index c60406e80..b7edc4277 100644 --- a/include/action.inc.php +++ b/include/action.inc.php @@ -245,11 +245,59 @@ if ( $sub_action=='detail' ) echo $upload->Submit("save","Sauve"); echo $upload->Submit("add_action_here","Ajoute une action à celle-ci"); echo ''; + echo '
'; + + echo $upload->Submit("delete","Efface cette action"); + echo ''; + echo ''; + echo ''; + echo '
'; echo $retour; echo ''; } +//------------------------------------------------------------------------------- +// Delete an action +if ( $sub_action == 'delete' ) +{ + // first the confirmation + if ( ! isset ($_POST['confirm_delete'])) + { + echo '
'; + echo ''; + $act=new action($cn); + $act->ag_id=$_REQUEST['ag_id']; + echo $act->get(); + $act->ag_comment=Decode($act->ag_comment); + + echo JS_SEARCH_CARD; + echo $act->display('READ',false); + // display the form + echo '
'; + echo ''; + echo ''; + echo ''; + $upload=new widget("text"); + echo $upload->Submit("confirm_delete","Confirmer l'effacement"); + + echo '
'; + + + + echo '
'; + + } + else + { + // confirmed + $act=new action($cn); + $act->ag_id=$_REQUEST['ag_id']; + $act->remove(); + $sub_action="list"; + } +} + //-------------------------------------------------------------------------------- // Show a list of the action if ( $sub_action == "list" ) @@ -372,3 +420,4 @@ if ( $sub_action == "save_action_st3" ) //--------------------------------------------------------------------- echo ""; +?> \ No newline at end of file diff --git a/include/class_action.php b/include/class_action.php index 5bd3f5055..a2511951d 100644 --- a/include/class_action.php +++ b/include/class_action.php @@ -59,6 +59,7 @@ class action * \enum $f_id_dest fiche id (From field ) * \enum $f_id_exp fiche id (to field) * \enum $ag_ref_ag_id concern previous action + * \enum $ag_id pk of the table action_gestion * \todo replace attribut from class document document by an object document */ @@ -174,9 +175,12 @@ class action $state->selected=$this->d_state; $str_state=$state->IOValue(); } else { - $str_state=getDbValue($this->db,"select s_value from document_state where s_id=".$this->d_state); - $g=new widget("hidden"); - $str_state.=$g->IOValue('d_state',$this->d_state); + $str_state=""; + if ( strlen($this->d_state) != 0 ) + { $str_state=getDbValue($this->db,"select s_value from document_state where s_id=".$this->d_state); + $g=new widget("hidden"); + $str_state.=$g->IOValue('d_state',$this->d_state); + } } // Retrieve the value if there is an attached doc $doc_ref=""; @@ -190,10 +194,14 @@ class action { $h2->readonly=($p_view=='NEW')?false:true; $doc=new Document($this->db,$this->d_id); - $d_id=new widget("hidden"); - $doc_ref="

Document ".$doc->a_ref().'

'; - $doc_ref.=$h2->IOValue().$d_id->IOValue('d_id',$this->d_id); - + $doc->get(); + if ( strlen(trim($doc->d_lob)) != 0 ) + { + $d_id=new widget("hidden"); + $doc_ref="

Document ".$doc->a_ref().'

'; + $doc_ref.=$h2->IOValue().$d_id->IOValue('d_id',$this->d_id); + } + } @@ -643,6 +651,7 @@ class action */ function myList($p_filter="",$p_search="") { + /*!\todo idea to add a sort */ // for the sort $sort=""; if ( isset($_GET['s'])){ @@ -794,8 +803,13 @@ class action $r.="".$row['dt_value'].""; $r.="".$row['ag_ref'].""; $r.="".$ref.""; - $doc=new Document($this->db,$row['d_id']); - $r.="".$doc->a_ref().""; + if ( $row['d_id'] != '') + { + $doc=new Document($this->db,$row['d_id']); + $doc->get(); + if ( strlen(trim($doc->d_lob)) != 0 ) + $r.="".$doc->a_ref().""; + } $r.=""; } @@ -909,5 +923,30 @@ class action } return true; } + /*!\brief remove the action + * + */ + function remove() + { + $this->get(); + // remove the key + $sql=sprintf("delete from action_gestion where ag_id=%d",$this->ag_id); + ExecSql($this->db,$sql); + // remove the ref + $sql=sprintf("update action_gestion set ag_ref_ag_id=0 where ag_ref_ag_id=%d", + $this->ag_id); + ExecSql($this->db,$sql); + + // if there is a document + if ( $this->dt_id != 0 ) + { + $doc=new Document($this->db,$this->dt_id); + $doc->get(); + $doc->remove(); + if ( strlen(trim($doc->d_lob))!=0 ) + pg_lo_unlink($this->db,$doc->dt_lob); + } + + } } diff --git a/include/class_document.php b/include/class_document.php index 1da360fde..7b1f01fa1 100644 --- a/include/class_document.php +++ b/include/class_document.php @@ -400,7 +400,7 @@ class Document function get() { $sql="select * from document where d_id=".$this->d_id; - $ret=Exec($this->db,$sql); + $ret=ExecSql($this->db,$sql); if ( pg_num_rows($ret) == 0 ) return; $row=pg_fetch_array($ret,0); @@ -408,7 +408,6 @@ class Document $this->d_mimetype=$row['d_mimetype']; $this->d_filename=$row['d_filename']; $this->d_lob=$row['d_lob']; - $this->d_number=$row['']; $this->d_state=$row['ag_id']; $this->d_number=$row['d_number'];