Merge branch 'develop' of git+ssh://git@github.com/Dolibarr/dolibarr.git into develop

This commit is contained in:
Regis Houssin
2013-01-24 17:32:52 +01:00
9 changed files with 267 additions and 51 deletions

View File

@@ -47,6 +47,7 @@ class Categorie
var $import_key;
var $cats=array(); // Tableau en memoire des categories
var $motherof=array();
/**
@@ -542,6 +543,40 @@ class Categorie
return ($n[0] > 0);
}
/**
* Load this->motherof that is array(id_son=>id_parent, ...)
*
* @return int <0 if KO, >0 if OK
*/
private function load_motherof()
{
global $conf;
$this->motherof=array();
// Load array[child]=parent
$sql = "SELECT fk_parent as id_parent, rowid as id_son";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE fk_parent != 0";
$sql.= " AND entity = ".$conf->entity;
dol_syslog(get_class($this)."::load_motherof sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
while ($obj= $this->db->fetch_object($resql))
{
$this->motherof[$obj->id_son]=$obj->id_parent;
}
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Reconstruit l'arborescence des categories sous la forme d'un tableau
@@ -554,13 +589,16 @@ class Categorie
* fullpath = chemin complet compose des id
*
* @param string $type Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
* @param int $markafterid Mark all categories after this leaf in category tree.
* @return array Array of categories
* @param int $markafterid Removed all categories including the leaf $markafterid in category tree.
* @return array Array of categories. this->cats and this->motherof are set.
*/
function get_full_arbo($type,$markafterid=0)
{
$this->cats = array();
// Init this->motherof that is array(id_son=>id_parent, ...)
$this->load_motherof();
// Init $this->cats array
$sql = "SELECT DISTINCT c.rowid, c.label, c.description, c.fk_parent"; // Distinct reduce pb with old tables with duplicates
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c";
@@ -592,10 +630,11 @@ class Categorie
dol_syslog(get_class($this)."::get_full_arbo call to build_path_from_id_categ", LOG_DEBUG);
foreach($this->cats as $key => $val)
{
//print 'key='.$key.'<br>'."\n";
$this->build_path_from_id_categ($key,0); // Process a branch from the root category key (this category has no parent)
}
// Exclude tree for $markafterid
// Exclude leaf including $markafterid from tree
if ($markafterid)
{
//print "Look to discard category ".$markafterid."\n";
@@ -608,8 +647,6 @@ class Categorie
if (preg_match('/'.$keyfilter1.'/',$val['fullpath']) || preg_match('/'.$keyfilter2.'/',$val['fullpath'])
|| preg_match('/'.$keyfilter3.'/',$val['fullpath']) || preg_match('/'.$keyfilter4.'/',$val['fullpath']))
{
//print "Categ discarded ".$this->cats[$key]['fullpath']."\n";
//$this->cats[$key]['marked']=1;
unset($this->cats[$key]);
}
}
@@ -630,51 +667,38 @@ class Categorie
* @param int $protection Deep counter to avoid infinite loop
* @return void
*/
function build_path_from_id_categ($id_categ,$protection=0)
function build_path_from_id_categ($id_categ,$protection=1000)
{
dol_syslog(get_class($this)."::build_path_from_id_categ id_categ=".$id_categ." protection=".$protection, LOG_DEBUG);
//if (! empty($this->cats[$id_categ]['fullpath']))
//{
// Already defined
// dol_syslog(get_class($this)."::build_path_from_id_categ fullpath and fulllabel already defined", LOG_WARNING);
// return;
//}
if (! empty($this->cats[$id_categ]['fullpath']))
{
// Already defined
dol_syslog(get_class($this)."::build_path_from_id_categ fullpath and fulllabel already defined", LOG_WARNING);
return;
}
// First build full array $motherof
//$this->load_motherof(); // Disabled because already done by caller of build_path_from_id_categ
// Define fullpath and fulllabel
if (! empty($this->cats[$id_categ]['fk_parent']))
$this->cats[$id_categ]['fullpath'] = '_'.$id_categ;
$this->cats[$id_categ]['fulllabel'] = $this->cats[$id_categ]['label'];
$i=0; $cursor_categ=$id_categ;
//print 'Work for id_categ='.$id_categ.'<br>'."\n";
while ((empty($protection) || $i < $protection) && ! empty($this->motherof[$cursor_categ]))
{
$this->cats[$id_categ]['fullpath'] = $this->cats[$this->cats[$id_categ]['fk_parent']]['fullpath'];
$this->cats[$id_categ]['fullpath'].= '_'.$id_categ;
$this->cats[$id_categ]['fulllabel'] = $this->cats[$this->cats[$id_categ]['fk_parent']]['fulllabel'];
$this->cats[$id_categ]['fulllabel'].= ' >> '.$this->cats[$id_categ]['label'];
}
else
{
$this->cats[$id_categ]['fullpath'] = '_'.$id_categ;
$this->cats[$id_categ]['fulllabel'] = $this->cats[$id_categ]['label'];
//print '&nbsp; cursor_categ='.$cursor_categ.' i='.$i.' '.$this->motherof[$cursor_categ].'<br>'."\n";
$this->cats[$id_categ]['fullpath'] = '_'.$this->motherof[$cursor_categ].$this->cats[$id_categ]['fullpath'];
$this->cats[$id_categ]['fulllabel'] = $this->cats[$this->motherof[$cursor_categ]]['label'].' >> '.$this->cats[$id_categ]['fulllabel'];
//print '&nbsp; Result for id_categ='.$id_categ.' : '.$this->cats[$id_categ]['fullpath'].' '.$this->cats[$id_categ]['fulllabel'].'<br>'."\n";
$i++; $cursor_categ=$this->motherof[$cursor_categ];
}
//print 'Result for id_categ='.$id_categ.' : '.$this->cats[$id_categ]['fullpath'].'<br>'."\n";
// We count number of _ to have level
$this->cats[$id_categ]['level']=dol_strlen(preg_replace('/[^_]/i','',$this->cats[$id_categ]['fullpath']));
/*
// Process all childs on several levels of this category
$protection++;
if ($protection > 10) return; // On ne traite pas plus de 10 niveaux de profondeurs
if (empty($this->cats[$id_categ]['id_children'])) return;
foreach($this->cats[$id_categ]['id_children'] as $key => $idchild)
{
// Protection when a category has itself as a child (should not happen)
if ($idchild == $id_categ)
{
dol_syslog(get_class($this)."::build_path_from_id_categ bad couple (".$idchild.",".$id_categ.") in association table: An entry should not have itself has child", LOG_WARNING);
continue;
}
$this->build_path_from_id_categ($idchild,$protection);
}
*/
return;
}

View File

@@ -209,12 +209,15 @@ foreach($fulltree as $key => $val)
// Define showline
$showline=0;
//var_dump($expandedsectionarray);
// If directory is son of expanded directory, we show line
if (isset($val['fk_parent']) && in_array($val['fk_parent'],$expandedsectionarray)) $showline=4;
// If directory is parent of selected directory or is selected directory, we show line
elseif (preg_match('/'.$val['fullpath'].'_/i',$fullpathselected.'_')) $showline=2;
// If we are level one we show line
elseif ($val['level'] < 2) $showline=1;
//print 'xxx '.$val['level'].' - '.$fullpathselected.' - '.$val['fullpath'].' - '.$val['fk_parent'].' showline='.$showline.'<br>'."\n";
if ($showline)
{

View File

@@ -0,0 +1,171 @@
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/compta/deplacement/document.php
* \ingroup deplacement
* \brief Page of linked files onto trip and expenses
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/trip.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$langs->load("other");
$langs->load("trips");
$langs->load("companies");
$langs->load("interventions");
$id = GETPOST('id','int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action','alpha');
$confirm = GETPOST('confirm','alpha');
// Security check
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'deplacement', $id, '');
// Get parameters
$sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha');
$page = GETPOST('page','int');
if ($page == -1) { $page = 0; }
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name";
$object = new Deplacement($db);
$object->fetch($id, $ref);
$upload_dir = $conf->deplacement->dir_output.'/'.dol_sanitizeFileName($object->ref);
$modulepart='trip';
/*
* Actions
*/
if (GETPOST('sendit','alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_add_file_process($upload_dir,0,1,'userfile');
}
// Delete
else if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
if ($object->id > 0)
{
$langs->load("other");
$object->fetch_thirdparty();
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$ret=dol_delete_file($file,0,0,0,$object);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
}
/*
* View
*/
$form = new Form($db);
llxHeader("","",$langs->trans("TripCard"));
if ($object->id)
{
$object->fetch_thirdparty();
$head=trip_prepare_head($object, $user);
dol_fiche_head($head, 'documents', $langs->trans("TripCard"), 0, 'trip');
// 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%">';
$linkback = '<a href="'.DOL_URL_ROOT.'/compta/deplacement/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
// Ref
print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
print '</td></tr>';
// Societe
//print "<tr><td>".$langs->trans("Company")."</td><td>".$object->client->getNomUrl(1)."</td></tr>";
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
print '</table>';
print '</div>';
/*
* Confirmation suppression fichier
*/
if ($action == 'delete')
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
if ($ret == 'html') print '<br>';
}
// Affiche formulaire upload
$formfile=new FormFile($db);
$formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/deplacement/document.php?id='.$object->id,'',0,0,$user->rights->deplacement->creer,50,$object);
// List of document
$param='&id='.$object->id;
$formfile->list_of_documents($filearray,$object,'deplacement',$param);
}
else
{
print $langs->trans("UnkownError");
}
llxFooter();
$db->close();
?>

View File

@@ -522,7 +522,7 @@ else if ($id)
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
// Other attributes
$parameters=array('colspan' => ' colspan="3"');
$parameters=array('colspan' => ' colspan="3"', 'showblocbydefault' => 1);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print "</table><br>";
@@ -578,7 +578,8 @@ else if ($id)
}
}
$db->close();
llxFooter();
$db->close();
?>

View File

@@ -45,11 +45,16 @@ function trip_prepare_head($object)
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'trip');
$head[$h][0] = DOL_URL_ROOT . '/compta/deplacement/info.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info';
$head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/document.php?id='.$object->id;
$head[$h][1] = $langs->trans("Documents");
$head[$h][2] = 'documents';
$h++;
$head[$h][0] = DOL_URL_ROOT . '/compta/deplacement/info.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info';
$h++;
complete_head_from_modules($conf,$langs,$object,$head,$h,'trip','remove');
return $head;

View File

@@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
@@ -13,11 +14,11 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Hide by default
$hide = (empty($object->extraparams[$blocname]['showhide']) ? true : false);
$hide = true; // Hide by default
if (isset($parameters['showblocbydefault'])) $hide=(empty($parameters['showblocbydefault']) ? true : false);
if (isset($object->extraparams[$blocname]['showhide'])) $hide = (empty($object->extraparams[$blocname]['showhide']) ? true : false);
?>

View File

@@ -137,6 +137,17 @@ if ($modulepart)
$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$refname."' AND entity=".$conf->entity;
}
// Wrapping pour les deplacements et notes de frais
else if ($modulepart == 'deplacement')
{
if ($user->rights->deplacement->lire || preg_match('/^specimen/i',$original_file))
{
$accessallowed=1;
}
$original_file=$conf->deplacement->dir_output.'/'.$original_file;
//$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$refname."' AND entity=".$conf->entity;
}
// Wrapping pour les prelevements
else if ($modulepart == 'prelevement')
{

View File

@@ -479,13 +479,13 @@ class EcmDirectory // extends CommonObject
$this->motherof=array();
// Charge tableau des meres
// Load array[child]=parent
$sql = "SELECT fk_parent as id_parent, rowid as id_son";
$sql.= " FROM ".MAIN_DB_PREFIX."ecm_directories";
$sql.= " WHERE fk_parent != 0";
$sql.= " AND entity = ".$conf->entity;
dol_syslog(get_class($this)."::get_full_arbo sql=".$sql);
dol_syslog(get_class($this)."::load_motherof sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{

View File

@@ -78,7 +78,7 @@ $alwayshiddencheckedmodules=array('accounting','barcode','bookmark','clicktodial
'memcached','numberwords','zipautofillfr');
$alwayshiddenuncheckedmodules=array('boutique','ftp',
// Extended modules
'awstats','bittorrent','cabinetmed','cmcic','concatpdf','dolicloud','filemanager','lightbox','mantis','monitoring','moretemplates','nltechno','numberingpack','openstreetmap',
'awstats','bittorrent','bootstrap','cabinetmed','cmcic','concatpdf','customfield','dolicloud','filemanager','lightbox','mantis','monitoring','moretemplates','multicompany','nltechno','numberingpack','openstreetmap',
'ovh','phenix','phpsysinfo','pibarcode','postnuke','skincoloreditor','submiteverywhere','survey','thomsonphonebook','topten','tvacerfa','voyage','webcalendar','webmail');
// Search modules