From 9da5661d429fe4acb35a4bba4d075e0ebdbbfa0c Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sat, 17 Oct 2015 16:37:31 +0200 Subject: [PATCH] Restructure files , move show_document.php to export_document.php --- html/js/gestion.js | 48 ++++++++++++---- include/class/class_document.php | 7 ++- include/class/class_follow_up.php | 2 +- .../export/export_document.php | 57 ++++++++++--------- sql/upgrade.sql | 8 ++- 5 files changed, 81 insertions(+), 41 deletions(-) rename html/show_document.php => include/export/export_document.php (71%) diff --git a/html/js/gestion.js b/html/js/gestion.js index d7c0e5dce..69a7d1f33 100644 --- a/html/js/gestion.js +++ b/html/js/gestion.js @@ -33,9 +33,14 @@ */ function remove_document(p_dossier,p_id) { - var queryString="gDossier="+p_dossier+"&a=rm&d_id="+p_id; + var queryString={ + "gDossier":p_dossier, + "a":"rm", + "d_id":p_id, + 'act':'RAW:document' + }; var action=new Ajax.Request ( - "show_document.php", + "export.php", { method:'get', parameters:queryString, @@ -53,10 +58,15 @@ function remove_document(p_dossier,p_id) */ function update_document(p_dossier,p_id) { - var queryString="gDossier="+p_dossier+"&a=upd_doc&d_id="+p_id; - queryString+="&value="+$('input_desc_txt'+p_id).value; + var queryString={ + "gDossier":p_dossier, + "a":"upd_doc", + "d_id":p_id, + 'act':'RAW:document', + 'value':$('input_desc_txt'+p_id).value + }; var action=new Ajax.Request ( - "show_document.php", + "export.php", { method:'get', parameters:queryString, @@ -79,9 +89,14 @@ function update_document(p_dossier,p_id) */ function remove_operation(p_dossier,p_id) { - var queryString="gDossier="+p_dossier+"&a=rmop&id="+p_id; + var queryString={ + "gDossier":p_dossier, + "a":"rmop", + "id":p_id, + 'act':'RAW:document' + }; var action=new Ajax.Request ( - "show_document.php", + "export.php", { method:'get', parameters:queryString, @@ -115,9 +130,15 @@ function successRemoveOp(request,json) */ function remove_action(p_dossier,p_id,ag_id) { - queryString="gDossier="+p_dossier+"&a=rmaction&id="+p_id+"&ag_id="+ag_id; + var queryString={ + "gDossier":p_dossier, + "a":"rmaction", + "id":p_id, + "ag_id":ag_id, + 'act':'RAW:document' + }; var action=new Ajax.Request ( - "show_document.php", + "export.php", { method:'get', parameters:queryString, @@ -146,9 +167,14 @@ function remove_action(p_dossier,p_id,ag_id) */ function remove_comment(p_dossier,p_id) { - queryString="gDossier="+p_dossier+"&a=rmcomment&id="+p_id; + var queryString={ + "gDossier":p_dossier, + "a":"rmcomment", + "id":p_id, + 'act':'RAW:document' + }; var action=new Ajax.Request ( - "show_document.php", + "export.php", { method:'get', parameters:queryString, diff --git a/include/class/class_document.php b/include/class/class_document.php index f0153d4e5..aef02285f 100644 --- a/include/class/class_document.php +++ b/include/class/class_document.php @@ -162,7 +162,8 @@ class Document } $this->SaveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse); // Invoice - $ret='Document généré'; + $href=http_build_query(array('gDossier'=>Dossier::id(),"d_id"=>$this->d_id,'act'=>'RAW:document')); + $ret='Document généré'; @rmdir($dirname); return $ret; } @@ -409,7 +410,9 @@ class Document return ''; $image=''; $r=""; - $r=''.$image.''; + $href=http_build_query(array('gDossier'=>Dossier::id(),"d_id"=>$this->d_id,'act'=>'RAW:document')); + + $r=''.$image.''; return $r; } /** Get diff --git a/include/class/class_follow_up.php b/include/class/class_follow_up.php index 4b007e847..4babe2371 100644 --- a/include/class/class_follow_up.php +++ b/include/class/class_follow_up.php @@ -404,7 +404,7 @@ class Follow_Up $upload->readOnly=$readonly; $upload->value=""; $aAttachedFile=$this->db->get_array('select d_id,d_filename,d_description,d_mimetype,'. - '\'show_document.php?'. + '\'export.php?act=RAW:document&'. Dossier::get().'&d_id=\'||d_id as link'. ' from document where ag_id=$1', array($this->ag_id)); /* create the select for document */ diff --git a/html/show_document.php b/include/export/export_document.php similarity index 71% rename from html/show_document.php rename to include/export/export_document.php index a30cdfd58..1a6ab074f 100644 --- a/html/show_document.php +++ b/include/export/export_document.php @@ -19,31 +19,36 @@ */ // Copyright Author Dany De Bontridder danydb@aevalys.eu // Verify parameters -/** \file +/** + * \file * \brief retrieve a document */ -require_once '../include/constant.php'; -require_once NOALYSS_INCLUDE.'/lib/class_database.php'; +if ( ! defined ('ALLOWED')) die (_('Non autorisé')); + require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; require_once NOALYSS_INCLUDE.'/class/class_document.php'; require_once NOALYSS_INCLUDE.'/class/class_dossier.php'; -$gDossier = dossier::id(); -$cn = Dossier::connect(); $action = (isset($_REQUEST['a'])) ? $_REQUEST['a'] : 'sh'; -require_once NOALYSS_INCLUDE.'/class/class_user.php'; -global $g_user; -$g_user = new User($cn); -$g_user->Check(); -$g_user->check_dossier($gDossier); -set_language(); +$d_id=HtmlInput::default_value_request('d_id',0); +$id=HtmlInput::default_value_request('id',0); +$ag_id=HtmlInput::default_value_request('ag_id',0); +$value=HtmlInput::default_value_request('value', null); + +if ( isNumber($id) == 0 || + isNumber($ag_id) == 0 || + isNumber($d_id) == 0 + ) +{ + die (_('Données invalides')); +} /* Show the document */ if ($action == 'sh') { if ($g_user->check_action(VIEWDOC) == 1) { // retrieve the document - $doc = new Document($cn, $_REQUEST['d_id']); + $doc = new Document($cn, $d_id); $doc->Send(); } } @@ -53,9 +58,9 @@ if ($action == 'rm') $json='{"d_id":"-1"}'; if ($g_user->check_action(RMDOC) == 1) { - $doc = new Document($cn, $_REQUEST['d_id']); + $doc = new Document($cn, $d_id); $doc->remove(); - $json = sprintf('{"d_id":"%s"}', $_REQUEST['d_id']); + $json = sprintf('{"d_id":"%s"}', $d_id); } header("Content-type: text/html; charset: utf8", true); print $json; @@ -65,11 +70,11 @@ if ( $action == "upd_doc") { if ($g_user->check_action(VIEWDOC) == 1) { - $doc = new Document($cn, $_REQUEST['d_id']); + $doc = new Document($cn, $d_id); $doc->get(); if ( $g_user->can_write_action($doc->ag_id)) // retrieve the document - $doc->update_description(strip_tags ($_REQUEST['value'])); + $doc->update_description(strip_tags ($value)); } } @@ -77,11 +82,11 @@ if ( $action == "upd_doc") if ($action == 'rmop') { $json = '{"ago_id":"-1"}'; - $dt_id = $cn->get_value("select ag_id from action_gestion_operation where ago_id=$1",array( $_REQUEST['id'])); + $dt_id = $cn->get_value("select ag_id from action_gestion_operation where ago_id=$1",array( $id)); if ($g_user->check_action(RMDOC) == 1 && $g_user->can_write_action($dt_id) == true) { - $cn->exec_sql("delete from action_gestion_operation where ago_id=$1", array($_REQUEST['id'])); - $json = sprintf('{"ago_id":"%s"}', $_REQUEST['id']); + $cn->exec_sql("delete from action_gestion_operation where ago_id=$1", array($id)); + $json = sprintf('{"ago_id":"%s"}', $id); } header("Content-type: text/html; charset: utf8", true); print $json; @@ -90,11 +95,11 @@ if ($action == 'rmop') if ($action == 'rmcomment') { $json = '{"agc_id":"-1"}'; - $dt_id = $cn->get_value("select ag_id from action_gestion_comment where agc_id=$1", array($_REQUEST['id'])); + $dt_id = $cn->get_value("select ag_id from action_gestion_comment where agc_id=$1", array($id)); if ($g_user->check_action(RMDOC) == 1 && $g_user->can_write_action($dt_id) == true) { - $cn->exec_sql("delete from action_gestion_comment where agc_id=$1", array($_REQUEST['id'])); - $json = sprintf('{"agc_id":"%s"}', $_REQUEST['id']); + $cn->exec_sql("delete from action_gestion_comment where agc_id=$1", array($id)); + $json = sprintf('{"agc_id":"%s"}', $id); } header("Content-type: text/html; charset: utf8", true); print $json; @@ -103,11 +108,11 @@ if ($action == 'rmcomment') if ($action == 'rmaction') { $json = '{"act_id":"-1"}'; - if ($g_user->check_action(RMDOC) == 1 && $g_user->can_write_action($_REQUEST['id']) == true && $g_user->can_write_action($_REQUEST['ag_id']) == true) + if ($g_user->check_action(RMDOC) == 1 && $g_user->can_write_action($id) == true && $g_user->can_write_action($ag_id) == true) { - $cn->exec_sql("delete from action_gestion_related where aga_least=$1 and aga_greatest=$2", array($_REQUEST['id'], $_REQUEST['ag_id'])); - $cn->exec_sql("delete from action_gestion_related where aga_least=$2 and aga_greatest=$1", array($_REQUEST['id'], $_REQUEST['ag_id'])); - $json = sprintf('{"act_id":"%s"}', $_REQUEST['id']); + $cn->exec_sql("delete from action_gestion_related where aga_least=$1 and aga_greatest=$2", array($id, $ag_id)); + $cn->exec_sql("delete from action_gestion_related where aga_least=$2 and aga_greatest=$1", array($id, $ag_id)); + $json = sprintf('{"act_id":"%s"}', $id); } header("Content-type: text/html; charset: utf8", true); print $json; diff --git a/sql/upgrade.sql b/sql/upgrade.sql index e35879d92..84a2c73a3 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -9,4 +9,10 @@ CREATE TRIGGER fiche_detail_upd_trg insert into menu_ref(me_code,me_file,me_menu,me_description,me_type) values ('RAW:receipt','export_receipt.php','Export la pièce','export la pièce justificative d''une opération','PR'); -insert into profile_menu (me_code,p_id,p_type_display) select 'RAW:receipt',p_id,'P' from profile where p_id > 0; \ No newline at end of file +insert into profile_menu (me_code,p_id,p_type_display) select 'RAW:receipt',p_id,'P' from profile where p_id > 0; + + +insert into menu_ref(me_code,me_file,me_menu,me_description,me_type) +values ('RAW:document','export_document.php','Export le document','export le document d''une événement','PR'); + +insert into profile_menu (me_code,p_id,p_type_display) select 'RAW:document',p_id,'P' from profile where p_id > 0; \ No newline at end of file