Fix: sharing code
This commit is contained in:
parent
84057d46cc
commit
cde000e9ce
@ -37,8 +37,11 @@ $langs->load("errors");
|
|||||||
|
|
||||||
if (! $user->admin) accessforbidden();
|
if (! $user->admin) accessforbidden();
|
||||||
|
|
||||||
$action =GETPOST('action','alpha');
|
$action = GETPOST('action','alpha');
|
||||||
$value = GETPOST('value','alpha');
|
$value = GETPOST('value','alpha');
|
||||||
|
$label = GETPOST('label','alpha');
|
||||||
|
$scandir = GETPOST('scandir','alpha');
|
||||||
|
$type='propal';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Actions
|
* Actions
|
||||||
@ -183,26 +186,13 @@ if ($action == 'setclassifiedinvoiced')
|
|||||||
|
|
||||||
if ($action == 'set')
|
if ($action == 'set')
|
||||||
{
|
{
|
||||||
$label = GETPOST('label','alpha');
|
$ret = addDocumentModel($value, $type, $label, $scandir);
|
||||||
$scandir = GETPOST('scandir','alpha');
|
|
||||||
|
|
||||||
$type='propal';
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
|
|
||||||
$sql.= " VALUES ('".$db->escape($value)."','".$type."',".$conf->entity.", ";
|
|
||||||
$sql.= ($label?"'".$db->escape($label)."'":'null').", ";
|
|
||||||
$sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
|
|
||||||
$sql.= ")";
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ($action == 'del')
|
else if ($action == 'del')
|
||||||
{
|
{
|
||||||
$type='propal';
|
$ret = delDocumentModel($value, $type);
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
|
if ($ret > 0)
|
||||||
$sql.= " WHERE nom = '".$db->escape($value)."'";
|
|
||||||
$sql.= " AND type = '".$type."'";
|
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
|
||||||
if ($db->query($sql))
|
|
||||||
{
|
{
|
||||||
if ($conf->global->PROPALE_ADDON_PDF == "$value") dolibarr_del_const($db, 'PROPALE_ADDON_PDF',$conf->entity);
|
if ($conf->global->PROPALE_ADDON_PDF == "$value") dolibarr_del_const($db, 'PROPALE_ADDON_PDF',$conf->entity);
|
||||||
}
|
}
|
||||||
@ -210,37 +200,16 @@ else if ($action == 'del')
|
|||||||
|
|
||||||
else if ($action == 'setdoc')
|
else if ($action == 'setdoc')
|
||||||
{
|
{
|
||||||
$label = GETPOST('label','alpha');
|
|
||||||
$scandir = GETPOST('scandir','alpha');
|
|
||||||
|
|
||||||
$db->begin();
|
|
||||||
|
|
||||||
if (dolibarr_set_const($db, "PROPALE_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
|
if (dolibarr_set_const($db, "PROPALE_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
|
||||||
{
|
{
|
||||||
$conf->global->PROPALE_ADDON_PDF = $value;
|
$conf->global->PROPALE_ADDON_PDF = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On active le modele
|
// On active le modele
|
||||||
$type='propal';
|
$ret = delDocumentModel($value, $type);
|
||||||
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
|
if ($ret > 0)
|
||||||
$sql_del.= " WHERE nom = '".$db->escape($value)."'";
|
|
||||||
$sql_del.= " AND type = '".$type."'";
|
|
||||||
$sql_del.= " AND entity = ".$conf->entity;
|
|
||||||
$result1=$db->query($sql_del);
|
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
|
|
||||||
$sql.= " VALUES ('".$db->escape($value)."', '".$type."', ".$conf->entity.", ";
|
|
||||||
$sql.= ($value?"'".$db->escape($label)."'":'null').", ";
|
|
||||||
$sql.= (! empty($value)?"'".$db->escape($scandir)."'":"null");
|
|
||||||
$sql.= ")";
|
|
||||||
$result2=$db->query($sql);
|
|
||||||
if ($result1 && $result2)
|
|
||||||
{
|
{
|
||||||
$db->commit();
|
$ret = addDocumentModel($value, $type, $label, $scandir);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$db->rollback();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
/* Copyright (C) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -1121,4 +1121,73 @@ function form_constantes($tableau)
|
|||||||
print '</table>';
|
print '</table>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add document model used by doc generator
|
||||||
|
*
|
||||||
|
* @param string $name Model name
|
||||||
|
* @param string $type Model type
|
||||||
|
* @param string $label Model label
|
||||||
|
* @param string $description Model description
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
|
*/
|
||||||
|
function addDocumentModel($name, $type, $label='', $description='')
|
||||||
|
{
|
||||||
|
global $db, $conf;
|
||||||
|
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
|
||||||
|
$sql.= " VALUES ('".$db->escape($name)."','".$type."',".$conf->entity.", ";
|
||||||
|
$sql.= ($label?"'".$db->escape($label)."'":'null').", ";
|
||||||
|
$sql.= (! empty($description)?"'".$db->escape($description)."'":"null");
|
||||||
|
$sql.= ")";
|
||||||
|
|
||||||
|
dol_syslog("admin.lib::addDocumentModel sql=".$sql);
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_print_error($db);
|
||||||
|
$db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete document model used by doc generator
|
||||||
|
*
|
||||||
|
* @param string $name Model name
|
||||||
|
* @param string $type Model type
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
|
*/
|
||||||
|
function delDocumentModel($name, $type)
|
||||||
|
{
|
||||||
|
global $db, $conf;
|
||||||
|
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
|
||||||
|
$sql.= " WHERE nom = '".$db->escape($name)."'";
|
||||||
|
$sql.= " AND type = '".$type."'";
|
||||||
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
|
dol_syslog("admin.lib::delDocumentModel sql=".$sql);
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_print_error($db);
|
||||||
|
$db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Loading…
Reference in New Issue
Block a user