task 0000018: Gestion des modèles de documents
This commit is contained in:
parent
312c912719
commit
a5ee2dbd03
7 changed files with 315 additions and 5 deletions
|
|
@ -41,7 +41,7 @@ require_once('function_javascript.php');
|
|||
require_once('ac_common.php');
|
||||
require_once ('class_user.php');
|
||||
|
||||
$var=array('gDossier');
|
||||
$var=array('gDossier','op');
|
||||
$cont=0;
|
||||
/* check if mandatory parameters are given */
|
||||
foreach ($var as $v)
|
||||
|
|
@ -426,4 +426,7 @@ echo <<<EOF
|
|||
</data>
|
||||
EOF;
|
||||
break;
|
||||
case 'mod_doc':
|
||||
require_once('modify_mod_document.inc.php');
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
61
html/js/modele_document.js
Normal file
61
html/js/modele_document.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*!\brief
|
||||
* \param p_value jrn.jr_id
|
||||
*/
|
||||
function modifyModeleDocument(p_value,dossier)
|
||||
{
|
||||
layer++;
|
||||
id='det'+layer;
|
||||
var popup={'id':
|
||||
'mod_doc','cssclass':'op_detail'
|
||||
,'html':
|
||||
loading(),'drag':
|
||||
true};
|
||||
querystring='?gDossier='+dossier+'&op=mod_doc&id='+p_value+'&div=mod_doc';
|
||||
add_div(popup);
|
||||
var action=new Ajax.Request(
|
||||
"ajax_misc.php",
|
||||
{
|
||||
method:'get',
|
||||
parameters:querystring,
|
||||
onFailure:error_box,
|
||||
onSuccess:modify_document_success_box
|
||||
}
|
||||
);
|
||||
}
|
||||
/**
|
||||
*@brief receive answer from ajax and just display it into the IBox
|
||||
* XML must contains at least 2 fields : code is the ID of the IBOX and
|
||||
* html which is the contain
|
||||
*/
|
||||
function modify_document_success_box(req,json)
|
||||
{
|
||||
try
|
||||
{
|
||||
var answer=req.responseXML;
|
||||
var a=answer.getElementsByTagName('ctl');
|
||||
var html=answer.getElementsByTagName('code');
|
||||
if ( a.length == 0 )
|
||||
{
|
||||
var rec=req.responseText;
|
||||
alert ('erreur :'+rec);
|
||||
}
|
||||
var name_ctl=a[0].firstChild.nodeValue;
|
||||
var code_html=getNodeText(html[0]);
|
||||
|
||||
code_html=unescape_xml(code_html);
|
||||
g(name_ctl).innerHTML=code_html;
|
||||
g(name_ctl).style.height='auto';
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
alert("success_box"+e.message);
|
||||
}
|
||||
try
|
||||
{
|
||||
code_html.evalScripts();
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
alert("answer_box Impossible executer script de la reponse\n"+e.message);
|
||||
}
|
||||
}
|
||||
|
|
@ -86,6 +86,8 @@ class Document_modele
|
|||
$c->name="dm_remove_".$row['md_id'];
|
||||
$r.=$c->input();
|
||||
$r.="</td>";
|
||||
$r.=td(HtmlInput::detail_modele_document($row['md_id'],'Modifier'));
|
||||
|
||||
$r.="</tr>";
|
||||
}
|
||||
$r.="</table>";
|
||||
|
|
@ -100,7 +102,6 @@ class Document_modele
|
|||
return $r;
|
||||
}
|
||||
/*!
|
||||
**************************************************
|
||||
* \brief : Save a document_modele in the database,
|
||||
* if the document_modele doesn't exist yet it will be
|
||||
* first created (-> insert into document_modele)
|
||||
|
|
@ -285,5 +286,72 @@ class Document_modele
|
|||
$this->$idx=$array[0][$idx];
|
||||
}
|
||||
}
|
||||
/*!
|
||||
* \brief : update a document_modele in the database,
|
||||
*/
|
||||
function update($p_array)
|
||||
{
|
||||
$this->load();
|
||||
// if name is empty return immediately
|
||||
if ( trim(strlen($p_array['md_name']))==0)
|
||||
return;
|
||||
try
|
||||
{
|
||||
// Start transaction
|
||||
$this->cn->start();
|
||||
$sql="update document_modele set md_name=$1,md_type=$2,md_affect=$3 where md_id=$4";
|
||||
$this->cn->exec_sql($sql,array(
|
||||
$p_array['md_name'],
|
||||
$p_array['md_type'],
|
||||
$p_array['md_affect'],
|
||||
$this->md_id
|
||||
));
|
||||
if ( $p_array['seq'] != 0 )
|
||||
$this->cn->alter_seq('seq_doc_type_'.$p_array['md_type'],$p_array['seq']);
|
||||
|
||||
// Save the file
|
||||
$new_name=tempnam($_ENV['TMP'],'document_');
|
||||
if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
|
||||
{
|
||||
if (move_uploaded_file($_FILES['doc']['tmp_name'],
|
||||
$new_name))
|
||||
{
|
||||
// echo "Image saved";
|
||||
$oid= $this->cn->lo_import($new_name);
|
||||
if ( $oid == false )
|
||||
{
|
||||
echo_error('class_document_modele.php',__LINE__,"cannot upload document");
|
||||
$this->cn->rollback();
|
||||
return;
|
||||
}
|
||||
// Remove old document
|
||||
$ret=$this->cn->exec_sql("select md_lob from document_modele where md_id=".$this->md_id);
|
||||
if (Database::num_row($ret) != 0)
|
||||
{
|
||||
$r=Database::fetch_array($ret,0);
|
||||
$old_oid=$r['md_lob'];
|
||||
if (strlen($old_oid) != 0)
|
||||
$this->cn->lo_unlink($old_oid);
|
||||
}
|
||||
// Load new document
|
||||
$this->cn->exec_sql("update document_modele set md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' ,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id);
|
||||
$this->cn->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<H1>Error</H1>";
|
||||
$this->cn->rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
rollback($this->cn);
|
||||
return ;
|
||||
}
|
||||
$this->cn->commit();
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -249,6 +249,15 @@ class HtmlInput
|
|||
return sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:modifyOperation(%d,%d)">%s</A>',
|
||||
$p_jr_id,dossier::id(),$p_mesg);
|
||||
}
|
||||
/**
|
||||
* return a string containing the html code for calling the modifyModeleDocument
|
||||
*/
|
||||
static function detail_modele_document($p_id,$p_mesg)
|
||||
{
|
||||
return sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:modifyModeleDocument(%d,%d)">%s</A>',
|
||||
$p_id,dossier::id(),$p_mesg);
|
||||
}
|
||||
|
||||
/**
|
||||
* display a div with the history of the card
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
require_once("class_document_modele.php");
|
||||
$sub_action=(isset ($_REQUEST['sa']))?$_REQUEST['sa']:"";
|
||||
echo js_include('modele_document.js');
|
||||
|
||||
echo "<hr>";
|
||||
// show the form for adding a template
|
||||
|
|
@ -65,11 +66,17 @@ if ( $sub_action=='rm_template')
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Document modify a template
|
||||
//----------------------------------------------------------------------
|
||||
if ( $sub_action == 'mod_template')
|
||||
{
|
||||
require_once('class_document_modele.php');
|
||||
$doc=new Document_modele($cn,$_POST['id']);
|
||||
$doc->update($_POST);
|
||||
}
|
||||
//-----------------------------------------------------
|
||||
// Default action : Show the list
|
||||
//-----------------------------------------------------
|
||||
echo $doc->myList();
|
||||
?>
|
||||
?>
|
||||
?>
|
||||
52
include/modify_mod_document.inc.php
Normal file
52
include/modify_mod_document.inc.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of PhpCompta.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
/* $Revision$ */
|
||||
|
||||
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
|
||||
|
||||
/*!\file
|
||||
* \brief show the detail of a document and let you modify it
|
||||
*/
|
||||
require_once('class_database.php');
|
||||
require_once('class_dossier.php');
|
||||
require_once("class_document_modele.php");
|
||||
|
||||
/* 1. Check security */
|
||||
$cn=new Database(dossier::id());
|
||||
/* 2. find the document */
|
||||
$doc=new Document_Modele($cn,$id);
|
||||
|
||||
/* 3. display it */
|
||||
$doc->load();
|
||||
ob_start();
|
||||
require('template/modele_document.php');
|
||||
|
||||
$html=ob_get_contents();
|
||||
ob_clean();
|
||||
$html=escape_xml($html);
|
||||
header('Content-type: text/xml; charset=UTF-8');
|
||||
|
||||
echo <<<EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<data>
|
||||
<ctl>mod_doc</ctl>
|
||||
<code>$html</code>
|
||||
</data>
|
||||
EOF;
|
||||
exit();
|
||||
110
include/template/modele_document.php
Normal file
110
include/template/modele_document.php
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
<div style="float:right">
|
||||
<A style="background-color:blue;color:white;text-decoration:none" HREF="javascript:void(0)" onclick="removeDiv('mod_doc');">Fermer</A>
|
||||
</div>
|
||||
<h2 class="info">Modèle de document</h2>
|
||||
<form action="parametre.php" method="post" enctype="multipart/form-data">
|
||||
<table>
|
||||
|
||||
<tr>
|
||||
<td>Nom du document</td>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
$a=new IText('md_name');
|
||||
$a->value=$doc->md_name;
|
||||
echo $a->input();
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
Catégorie de document
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
// Load all the category
|
||||
$w=new ISelect();
|
||||
$w->name="md_type";
|
||||
|
||||
$w->value=$cn->make_array('select dt_id,dt_value from document_type');
|
||||
$w->selected=$doc->md_type;
|
||||
echo $w->input();
|
||||
?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Affectation
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
|
||||
$waffect=new ISelect();
|
||||
$waffect->name='md_affect';
|
||||
$waffect->value=array(
|
||||
array('value'=>'ACH','label'=>_('Uniquement journaux achat')),
|
||||
array('value'=>'VEN','label'=>_('Uniquement journaux vente')),
|
||||
array('value'=>'GES','label'=>_('Partie gestion'))
|
||||
);
|
||||
$waffect->selected=$doc->md_affect;
|
||||
echo $waffect->input();
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Fichier
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$file=new IFile('doc');
|
||||
echo $file->input();
|
||||
?>
|
||||
</td>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
Dernier numéro utilisé pour ce type de document
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$last=0;
|
||||
if ( $cn->exist_sequence("seq_doc_type_".$doc->md_type) )
|
||||
{
|
||||
$ret= $cn->get_array("select last_value,is_called from seq_doc_type_".$doc->md_type) ;
|
||||
|
||||
$last=$ret[0]['last_value'];
|
||||
/*!
|
||||
*\note With PSQL sequence , the last_value column is 1 when before AND after the first call, to make the difference between them
|
||||
* I have to check whether the sequence has been already called or not */
|
||||
if ($ret[0]['is_called']=='f' ) $last--;
|
||||
}
|
||||
echo $last;
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Redémarrer la séquence (laisser à 0 pour ne pas changer)
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$pj=new INum('seq');
|
||||
$pj->value=0;
|
||||
echo $pj->input();
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<?php
|
||||
echo HtmlInput::hidden('p_action','document');
|
||||
echo dossier::hidden();
|
||||
echo HtmlInput::hidden('sa','mod_template');
|
||||
echo HtmlInput::hidden('id',$doc->md_id);
|
||||
echo HtmlInput::submit("mod",'Sauver');
|
||||
|
||||
?>
|
||||
</form>
|
||||
Loading…
Add table
Add a link
Reference in a new issue