diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php index 4205c9c24ac..1a4b4e34ddf 100644 --- a/htdocs/core/ajax/ajaxdirpreview.php +++ b/htdocs/core/ajax/ajaxdirpreview.php @@ -2,7 +2,7 @@ /* Copyright (C) 2004-2007 Rodolphe Quiedeville * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005 Simon Tosser - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010 Pierre Morin * * This program is free software; you can redistribute it and/or modify @@ -54,7 +54,7 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call $pagenext = $page + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="name"; - + $upload_dir = dirname(str_replace("../","/", $conf->ecm->dir_output.'/'.$file)); $ecmdir = new EcmDirectory($db); @@ -121,7 +121,7 @@ if (! isset($mode) || $mode != 'noajax') // Ajout directives pour resoudre bug IE header('Cache-Control: Public, must-revalidate'); header('Pragma: public'); - + top_httphead(); } @@ -137,7 +137,7 @@ if (! dol_is_dir($upload_dir)) } print ''."\n"; -print ''."\n"; +print ''."\n"; $param=''; $param.=($sortfield?'&sortfield='.$sortfield:'').($sortorder?'&sortorder='.$sortorder:''); @@ -252,7 +252,7 @@ if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE if ($section) { $param.=($param?'?':'').(preg_replace('/^&/','',$param)); - + require_once(DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'); $useglobalvars=1; $form = new Form($db); diff --git a/htdocs/core/boxes/box_produits.php b/htdocs/core/boxes/box_produits.php index a75cbf15991..fe12c196138 100644 --- a/htdocs/core/boxes/box_produits.php +++ b/htdocs/core/boxes/box_produits.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * 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 @@ -23,8 +23,8 @@ * \brief Module to generate box of last products/services */ -include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); -include_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); +include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php'; +include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; /** @@ -105,7 +105,8 @@ class box_produits extends ModeleBoxes if ($resultd) { $objtp = $db->fetch_object($resultd); - if ($objtp->label != '') $objp->label = $objtp->label; + if (isset($objtp->label) && $objtp->label != '') + $objp->label = $objtp->label; } } diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 8cc95621df6..f33ac4460f9 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -581,7 +581,8 @@ class FormFile && ! preg_match('/\.meta$/i',$file['name'])) { // Define relative path used to store the file - if (! $relativepath) $relativepath=dol_sanitizeFileName($object->ref).'/'; + if (empty($relativepath)) + $relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/'; $var=!$var; print ''; @@ -725,14 +726,14 @@ class FormFile $id=0; $ref=''; $label=''; // To show ref or specific information according to view to show (defined by $module) - if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1]; } - if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; } - if ($modulepart == 'invoice_supplier') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1]; } - if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; } - if ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; } - if ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; } - if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; } - if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1]; } + if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); } + if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } + if ($modulepart == 'invoice_supplier') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); } + if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } + if ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } + if ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } + if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } + if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); } if (! $id && ! $ref) continue; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index f4e19d333d2..b306b18a70b 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -287,7 +287,7 @@ function dol_mimetype($file,$default='application/octet-stream',$mode=0) if ($mode == 1) { $tmp=explode('/',$mime); - return $tmp[1]; + return (! empty($tmp[1])?$tmp[1]:$tmp[0]); } if ($mode == 2) { diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php index d13ff95f03d..bb665e09cb1 100644 --- a/htdocs/ecm/class/ecmdirectory.class.php +++ b/htdocs/ecm/class/ecmdirectory.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2008-2009 Regis Houssin +/* Copyright (C) 2007-2012 Laurent Destailleur + * Copyright (C) 2008-2012 Regis Houssin * * 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 @@ -529,7 +529,7 @@ class EcmDirectory // extends CommonObject { global $conf; - if (empty($force) && $this->full_arbo_loaded) + if (empty($force) && ! empty($this->full_arbo_loaded)) { return $this->cats; } @@ -561,7 +561,7 @@ class EcmDirectory // extends CommonObject while ($obj = $this->db->fetch_object($resql)) { $this->cats[$obj->rowid]['id'] = $obj->rowid; - $this->cats[$obj->rowid]['id_mere'] = $this->motherof[$obj->rowid]; + $this->cats[$obj->rowid]['id_mere'] = (isset($this->motherof[$obj->rowid])?$this->motherof[$obj->rowid]:''); $this->cats[$obj->rowid]['label'] = $obj->label; $this->cats[$obj->rowid]['description'] = $obj->description; $this->cats[$obj->rowid]['cachenbofdoc'] = $obj->cachenbofdoc; @@ -617,7 +617,7 @@ class EcmDirectory // extends CommonObject function build_path_from_id_categ($id_categ,$protection=0) { // Define fullpath - if (isset($this->cats[$id_categ]['id_mere'])) + if (! empty($this->cats[$id_categ]['id_mere'])) { $this->cats[$id_categ]['fullpath'] =$this->cats[$this->cats[$id_categ]['id_mere']]['fullpath']; $this->cats[$id_categ]['fullpath'].='_'.$id_categ; @@ -638,7 +638,7 @@ class EcmDirectory // extends CommonObject // Traite ces enfants $protection++; if ($protection > 20) return; // On ne traite pas plus de 20 niveaux - if (is_array($this->cats[$id_categ]['id_children'])) + if (isset($this->cats[$id_categ]['id_children']) && is_array($this->cats[$id_categ]['id_children'])) { foreach($this->cats[$id_categ]['id_children'] as $key => $val) { diff --git a/htdocs/ecm/docdir.php b/htdocs/ecm/docdir.php index c6f0d654ca5..9165deae7e3 100644 --- a/htdocs/ecm/docdir.php +++ b/htdocs/ecm/docdir.php @@ -1,6 +1,6 @@ - * Copyright (C) 2008 Regis Houssin +/* Copyright (C) 2008-2012 Laurent Destailleur + * Copyright (C) 2008-2012 Regis Houssin * * 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 @@ -39,10 +39,12 @@ $langs->load("bills"); $langs->load("contracts"); $langs->load("categories"); -if (!$user->rights->ecm->setup) accessforbidden(); +if (! $user->rights->ecm->setup) accessforbidden(); // Get parameters -$socid = GETPOST("socid","int"); +$socid = GETPOST('socid','int'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); // Security check if ($user->societe_id > 0) @@ -51,9 +53,9 @@ if ($user->societe_id > 0) $socid = $user->societe_id; } -$section=$_GET["section"]; -if (! $section) $section='misc'; -$upload_dir = $conf->ecm->dir_output.'/'.$section; +$section=$urlsection=GETPOST('section'); +if (empty($urlsection)) $urlsection='misc'; +$upload_dir = $conf->ecm->dir_output.'/'.$urlsection; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); @@ -66,9 +68,9 @@ if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="label"; $ecmdir = new EcmDirectory($db); -if (! empty($_GET["section"])) +if (! empty($section)) { - $result=$ecmdir->fetch($_GET["section"]); + $result=$ecmdir->fetch($section); if (! $result > 0) { dol_print_error($db,$ecmdir->error); @@ -77,14 +79,12 @@ if (! empty($_GET["section"])) } -/******************************************************************* - * ACTIONS - * - * Put here all code to do according to value of "action" parameter - ********************************************************************/ +/* + * Actions + */ // Action ajout d'un produit ou service -if ($_POST["action"] == 'add' && $user->rights->ecm->setup) +if ($action == 'add' && $user->rights->ecm->setup) { if (! empty($_POST["cancel"])) { @@ -100,8 +100,8 @@ if ($_POST["action"] == 'add' && $user->rights->ecm->setup) if (! $ecmdir->label) { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
'; - $_GET["action"] = "create"; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")), 'errors'); + $action = 'create'; $ok=false; } @@ -117,34 +117,32 @@ if ($_POST["action"] == 'add' && $user->rights->ecm->setup) else { $langs->load("errors"); - $mesg='
'.$langs->trans($ecmdir->error).'
'; - $_GET["action"] = "create"; + setEventMessage($langs->trans($ecmdir->error), 'errors'); + $action = 'create'; } } } // Suppression fichier -if ($_POST['action'] == 'confirm_deletesection' && $_POST['confirm'] == 'yes') +if ($action == 'confirm_deletesection' && $confirm == 'yes') { $result=$ecmdir->delete($user); - $mesg = '
'.$langs->trans("ECMSectionWasRemoved", $ecmdir->label).'
'; + setEventMessage($langs->trans("ECMSectionWasRemoved", $ecmdir->label)); } -/******************************************************************* - * PAGE - * - * Put here all code to do according to value of "action" parameter - ********************************************************************/ +/* + * View + */ llxHeader(); $form=new Form($db); $formecm=new FormEcm($db); -if ($_GET["action"] == 'create') +if ($action == 'create') { //*********************** // Create @@ -155,7 +153,6 @@ if ($_GET["action"] == 'create') $title=$langs->trans("ECMNewSection"); print_fiche_titre($title); - if ($mesg) { print $mesg."
"; } print ''; @@ -186,7 +183,7 @@ if ($_GET["action"] == 'create') } -if (! $_GET["action"] || $_GET["action"] == 'delete_section') +if (empty($action) || $action == 'delete_section') { //*********************** // List @@ -204,15 +201,12 @@ if (! $_GET["action"] || $_GET["action"] == 'delete_section') */ // Confirmation de la suppression d'une ligne categorie - if ($_GET['action'] == 'delete_section') + if ($action == 'delete_section') { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_GET["section"], $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection'); + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection'); if ($ret == 'html') print '
'; } - if ($mesg) { print $mesg."
"; } - - // Construit fiche rubrique @@ -231,7 +225,6 @@ if (! $_GET["action"] || $_GET["action"] == 'delete_section') // End of page -$db->close(); - llxFooter(); +$db->close(); ?> diff --git a/htdocs/ecm/docmine.php b/htdocs/ecm/docmine.php index b31e5bcbd26..cbbbfc6da43 100644 --- a/htdocs/ecm/docmine.php +++ b/htdocs/ecm/docmine.php @@ -34,6 +34,9 @@ $langs->load("ecm"); $langs->load("companies"); $langs->load("other"); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); + // Get parameters $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); @@ -101,12 +104,12 @@ if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC)) { // Echec transfert (fichier depassant la limite ?) $langs->load("errors"); - $mesg = '
'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'
'; + setEventMessage($langs->trans("ErrorFailToCreateDir",$upload_dir), 'errors'); } } // Remove file -if (GETPOST('action') == 'confirm_deletefile' && GETPOST('confirm') == 'yes') +if ($action == 'confirm_deletefile' && $confirm == 'yes') { $langs->load("other"); $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). @@ -118,7 +121,7 @@ if (GETPOST('action') == 'confirm_deletefile' && GETPOST('confirm') == 'yes') } // Remove dir -if (GETPOST('action') == 'confirm_deletedir' && GETPOST('confirm') == 'yes') +if ($action == 'confirm_deletedir' && $confirm == 'yes') { // Fetch was already done $result=$ecmdir->delete($user); @@ -129,12 +132,12 @@ if (GETPOST('action') == 'confirm_deletedir' && GETPOST('confirm') == 'yes') } else { - $mesg = '
'.$langs->trans($ecmdir->error,$ecmdir->label).'
'; + setEventMessage($langs->trans($ecmdir->error,$ecmdir->label), 'errors'); } } // Update description -if (GETPOST('action') == 'update' && ! GETPOST('cancel')) +if ($action == 'update' && ! GETPOST('cancel')) { $error=0; @@ -151,8 +154,7 @@ if (GETPOST('action') == 'update' && ! GETPOST('cancel')) if ($result > 0) { // Try to rename file if changed - if ($oldlabel != $ecmdir->label - && file_exists($olddir)) + if ($oldlabel != $ecmdir->label && file_exists($olddir)) { $newdir=$ecmdir->getRelativePath(1); // return "xxx/zzz/" from ecm directory $newdir=$conf->ecm->dir_output.'/'.$newdir; @@ -161,7 +163,7 @@ if (GETPOST('action') == 'update' && ! GETPOST('cancel')) if (! $result) { $langs->load('errors'); - $mesg='
'.$langs->trans('ErrorFailToRenameDir',$olddir,$newdir).'
'; + setEventMessage($langs->trans('ErrorFailToRenameDir',$olddir,$newdir), 'errors'); $error++; } } @@ -181,7 +183,7 @@ if (GETPOST('action') == 'update' && ! GETPOST('cancel')) else { $db->rollback(); - $mesg='
'.$ecmdir->error.'
'; + setEventMessage($ecmdir->error, 'errors'); } } @@ -210,7 +212,7 @@ foreach($filearray as $key => $file) $head = ecm_prepare_head($ecmdir); dol_fiche_head($head, 'card', $langs->trans("ECMSectionManual"), '', 'dir'); -if ($_GET["action"] == 'edit') +if ($action == 'edit') { print ''; print ''; @@ -228,7 +230,7 @@ $i=0; while ($tmpecmdir && $result > 0) { $tmpecmdir->ref=$tmpecmdir->label; - if ($i == 0 && $_GET["action"] == 'edit') + if ($i == 0 && $action == 'edit') { $s=''; } @@ -249,7 +251,7 @@ print img_picto('','object_dir').' '.$l print $s; print ''; print '
'.$langs->trans("Description").''; -if ($_GET["action"] == 'edit') +if ($action == 'edit') { print '