Fix: multicompany sharings compatibility

This commit is contained in:
Regis Houssin 2012-04-07 09:14:33 +02:00
parent 6d2a3edf69
commit 13624eeb86
12 changed files with 126 additions and 140 deletions

View File

@ -159,7 +159,7 @@ if ( ($action == 'update' && empty($_POST["cancel"]))
if ($action == 'addthumb')
{
if (file_exists($conf->societe->dir_output.'/logos/'.$_GET["file"]))
if (file_exists($conf->mycompany->dir_output.'/logos/'.$_GET["file"]))
{
$isimage=image_format_supported($_GET["file"]);

View File

@ -162,7 +162,7 @@ if ($type == 'directory')
// Right area
if ($module == 'company') // Auto area for suppliers invoices
{
$upload_dir = $conf->societe->dir_output;
$upload_dir = $conf->societe->dir_output; // TODO change for multicompany sharing
$filearray=dol_dir_list($upload_dir,"files",1,'',array('^SPECIMEN\.pdf$','^\.','\.meta$','^temp$','^payments$','^CVS$','^thumbs$'),$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$param.='&module='.$module;

View File

@ -3691,7 +3691,7 @@ class Form
if ($modulepart=='societe')
{
$dir=$conf->societe->dir_output;
$dir=$conf->societe->multidir_output[$object->entity];
$smallfile=$object->logo;
$smallfile=preg_replace('/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i','_small\\1',$smallfile);
if ($object->logo) $file=$object->id.'/logos/thumbs/'.$smallfile;
@ -3717,14 +3717,14 @@ class Form
if ($file && file_exists($dir."/".$file))
{
// TODO Link to large image
$ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='<img alt="Photo" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$object->entity.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='<img alt="Photo" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$object->entity.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='</a>';
}
else if ($altfile && file_exists($dir."/".$altfile))
{
$ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='<img alt="Photo alt" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($altfile).'&cache='.$cache.'">';
$ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$object->entity.'&file='.urlencode($file).'&cache='.$cache.'">';
$ret.='<img alt="Photo alt" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$object->entity.'&file='.urlencode($altfile).'&cache='.$cache.'">';
$ret.='</a>';
}
else

View File

@ -179,7 +179,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc
$outputlangs->load("companies");
$outputlangs->load("projects");
if ($conf->societe->dir_output)
if ($conf->societe->multidir_output[$object->entity])
{
// If $object is id instead of object
if (! is_object($object))
@ -194,7 +194,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc
}
}
$dir = $conf->societe->dir_output;
$dir = $conf->societe->multidir_output[$object->entity];
$objectref = dol_sanitizeFileName($object->id);
if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;

View File

@ -124,13 +124,13 @@ if ($modulepart)
// On fait une verification des droits et on definit le repertoire concerne
// Wrapping for third parties
if ($modulepart == 'company')
if ($modulepart == 'company' || $modulepart == 'societe')
{
if ($user->rights->societe->lire || preg_match('/^specimen/i',$original_file))
{
$accessallowed=1;
}
$original_file=$conf->societe->dir_output.'/'.$original_file;
$original_file=$conf->societe->multidir_output[GETPOST('entity','int')].'/'.$original_file;
$sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$refname."' AND entity=".$conf->entity;
}
@ -252,17 +252,6 @@ if ($modulepart)
$original_file=$conf->compta->dir_output.'/'.$original_file;
}
// Wrapping pour les societe
else if ($modulepart == 'societe')
{
if ($user->rights->societe->lire || preg_match('/^specimen/i',$original_file))
{
$accessallowed=1;
}
$original_file=$conf->societe->dir_output.'/'.$original_file;
$sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$refname."' AND entity=".$conf->entity;
}
// Wrapping pour les expedition
else if ($modulepart == 'expedition')
{

View File

@ -199,7 +199,7 @@ if (GETPOST('purge'))
{
$filearray=array();
$upload_dir = $conf->$modulepart->dir_output;
if ($modulepart == 'company') $upload_dir = $conf->societe->dir_output;
if ($modulepart == 'company') $upload_dir = $conf->societe->dir_output; // TODO change for multicompany sharing
if ($modulepart == 'invoice') $upload_dir = $conf->facture->dir_output;
if ($modulepart == 'invoice_supplier') $upload_dir = $conf->fournisseur->facture->dir_output;
if ($modulepart == 'order') $upload_dir = $conf->commande->dir_output;

View File

@ -259,7 +259,7 @@ for ($i=1; $i<=4; $i++) {
/*
* Documents generes
*/
$filedir=$conf->societe->dir_output.'/'.$socid;
$filedir=$conf->societe->multidir_output[$this->control->tpl['entity']].'/'.$socid;
$urlsource=$_SERVER["PHP_SELF"]."?socid=".$socid;
$genallowed=$user->rights->societe->creer;
$delallowed=$user->rights->societe->supprimer;

View File

@ -199,7 +199,7 @@ dol_fiche_head($head, 'card', $langs->trans("ThirdParty"),0,'company');
/*
* Documents generes
*/
$filedir=$conf->societe->dir_output.'/'.$socid;
$filedir=$conf->societe->multidir_output[$this->control->tpl['entity']].'/'.$socid;
$urlsource=$_SERVER["PHP_SELF"]."?socid=".$socid;
$genallowed=$user->rights->societe->creer;
$delallowed=$user->rights->societe->supprimer;

View File

@ -845,7 +845,7 @@ class Societe extends CommonObject
// Remove contacts
if (! $error)
{
$sql = "DELETE from ".MAIN_DB_PREFIX."socpeople";
$sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
$sql.= " WHERE fk_soc = " . $id;
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
if (! $this->db->query($sql))
@ -873,7 +873,7 @@ class Societe extends CommonObject
// Remove ban
if (! $error)
{
$sql = "DELETE from ".MAIN_DB_PREFIX."societe_rib";
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_rib";
$sql.= " WHERE fk_soc = " . $id;
dol_syslog(get_class($this)."::Delete sql=".$sql, LOG_DEBUG);
if (! $this->db->query($sql))
@ -906,7 +906,7 @@ class Societe extends CommonObject
// Remove third party
if (! $error)
{
$sql = "DELETE from ".MAIN_DB_PREFIX."societe";
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
$sql.= " WHERE rowid = " . $id;
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
if (! $this->db->query($sql))
@ -932,7 +932,7 @@ class Societe extends CommonObject
$this->db->commit();
// Delete directory
$docdir = $conf->societe->dir_output . "/" . $id;
$docdir = $conf->societe->multidir_output[$this->entity] . "/" . $id;
if (file_exists($docdir))
{
dol_delete_dir_recursive($docdir);

View File

@ -35,9 +35,10 @@ $langs->load('other');
$mesg='';
$action = GETPOST('action');
$confirm = GETPOST('confirm');
$socid = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
$action=GETPOST('action');
$confirm=GETPOST('confirm');
$id=(GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
$ref = GETPOST('ref', 'alpha');
// Security check
if ($user->societe_id > 0)
@ -46,7 +47,7 @@ if ($user->societe_id > 0)
$action='';
$socid = $user->societe_id;
}
$result = restrictedArea($user, 'societe', $socid, '&societe');
$result = restrictedArea($user, 'societe', $id, '&societe');
// Get parameters
$sortfield = GETPOST("sortfield",'alpha');
@ -59,19 +60,24 @@ $pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name";
$upload_dir = $conf->societe->dir_output . "/" . $socid ;
$courrier_dir = $conf->societe->dir_output . "/courrier/" . get_exdir($socid);
$object = new Societe($db);
if ($id > 0 || ! empty($ref))
{
$result = $object->fetch($id, $ref);
$upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ;
$courrier_dir = $conf->societe->multidir_output[$object->entity] . "/courrier/" . get_exdir($object->id);
}
/*
* Actions
*/
// Post file
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
if ($object->fetch($socid))
if ($object->id)
{
if (dol_mkdir($upload_dir) >= 0)
{
@ -113,7 +119,7 @@ if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
// Delete file
if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
if ($object->fetch($socid))
if ($object->id)
{
$file = $upload_dir . "/" . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
@ -131,107 +137,98 @@ $form = new Form($db);
$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('',$langs->trans("ThirdParty").' - '.$langs->trans("Files"),$help_url);
if ($socid > 0)
if ($object->id)
{
if ($object->fetch($socid))
{
/*
* Affichage onglets
*/
if ($conf->notification->enabled) $langs->load("mails");
$head = societe_prepare_head($object);
$form=new Form($db);
dol_fiche_head($head, 'document', $langs->trans("ThirdParty"),0,'company');
// Construit liste des fichiers
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$totalsize=0;
foreach($filearray as $key => $file)
{
$totalsize+=$file['size'];
}
print '<table class="border"width="100%">';
// Ref
print '<tr><td width="30%">'.$langs->trans("ThirdPartyName").'</td>';
print '<td colspan="3">';
print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom');
print '</td></tr>';
// Prefix
if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
{
print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
}
if ($object->client)
{
print '<tr><td>';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
print '</td></tr>';
}
if ($object->fournisseur)
{
print '<tr><td>';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
print '</td></tr>';
}
// Nbre fichiers
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
//Total taille
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
print '</table>';
print '</div>';
dol_htmloutput_mesg($mesg,$mesgs);
/*
* Confirmation suppression fichier
*/
if ($action == 'delete')
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?socid='.$socid.'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
if ($ret == 'html') print '<br>';
}
$formfile=new FormFile($db);
// Show upload form
$formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?socid='.$socid,'',0,0,$user->rights->societe->creer,50,$object);
// List of document
$param='&socid='.$object->id;
$formfile->list_of_documents($filearray,$object,'societe',$param);
print "<br><br>";
}
else
{
dol_print_error($db);
}
/*
* Affichage onglets
*/
if ($conf->notification->enabled) $langs->load("mails");
$head = societe_prepare_head($object);
$form=new Form($db);
dol_fiche_head($head, 'document', $langs->trans("ThirdParty"),0,'company');
// Construit liste des fichiers
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$totalsize=0;
foreach($filearray as $key => $file)
{
$totalsize+=$file['size'];
}
print '<table class="border"width="100%">';
// Ref
print '<tr><td width="30%">'.$langs->trans("ThirdPartyName").'</td>';
print '<td colspan="3">';
print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom');
print '</td></tr>';
// Prefix
if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
{
print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
}
if ($object->client)
{
print '<tr><td>';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
print '</td></tr>';
}
if ($object->fournisseur)
{
print '<tr><td>';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
print '</td></tr>';
}
// Nbre fichiers
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
//Total taille
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
print '</table>';
print '</div>';
dol_htmloutput_mesg($mesg,$mesgs);
/*
* Confirmation suppression fichier
*/
if ($action == 'delete')
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
if ($ret == 'html') print '<br>';
}
$formfile=new FormFile($db);
// Show upload form
$formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$object->id,'',0,0,$user->rights->societe->creer,50,$object);
// List of document
$param='&socid='.$object->id;
$formfile->list_of_documents($filearray,$object,'societe',$param);
print "<br><br>";
}
else
{
accessforbidden('',0,0);
}
$db->close();
llxFooter();
$db->close();
?>

View File

@ -252,7 +252,7 @@ if (empty($reshook))
}
// Gestion du logo de la société
$dir = $conf->societe->dir_output."/".$object->id."/logos/";
$dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK)
{
@ -328,14 +328,14 @@ if (empty($reshook))
}
// Gestion du logo de la société
$dir = $conf->societe->dir_output."/".$object->id."/logos";
$dir = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK)
{
if (GETPOST('deletephoto'))
{
$fileimg=$conf->societe->dir_output.'/'.$object->id.'/logos/'.$object->logo;
$dirthumbs=$conf->societe->dir_output.'/'.$object->id.'/logos/thumbs';
$fileimg=$dir.'/'.$object->logo;
$dirthumbs=$dir.'/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
}
@ -568,7 +568,7 @@ else
$object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
// Gestion du logo de la société
$dir = $conf->societe->dir_output."/".$object->id."/logos";
$dir = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK)
{
@ -1821,7 +1821,7 @@ else
/*
* Documents generes
*/
$filedir=$conf->societe->dir_output.'/'.$object->id;
$filedir=$conf->societe->multidir_output[$object->entity].'/'.$object->id;
$urlsource=$_SERVER["PHP_SELF"]."?socid=".$object->id;
$genallowed=$user->rights->societe->creer;
$delallowed=$user->rights->societe->supprimer;

View File

@ -121,7 +121,7 @@ if ($modulepart)
elseif ($modulepart == 'societe')
{
$accessallowed=1;
$original_file=$conf->societe->dir_output.'/'.$original_file;
$original_file=$conf->societe->multidir_output[GETPOST('entity','int')].'/'.$original_file;
}
// Wrapping pour les apercu factures
elseif ($modulepart == 'apercufacture')