From 70bccc91bad2e39c8b2d16c233a47c034326c9d5 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 13 Dec 2011 10:39:59 +0100 Subject: [PATCH] Fix: instantiate class if needed Fix: reindent and clean code --- htdocs/core/lib/project.lib.php | 183 ++++++++++++++++---------------- 1 file changed, 90 insertions(+), 93 deletions(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 8a56766f46c..837123ee9c2 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -154,99 +154,96 @@ function task_prepare_head($object) */ function select_projects($socid=-1, $selected='', $htmlname='projectid') { - global $db,$user,$conf,$langs; - - $hideunselectables = false; - if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true; - - $projectstatic=new Project($db); - $projectsListId = ''; - if (empty($user->rights->projet->all->lire)) - { - $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1); - } - - // On recherche les projets - $sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public'; - $sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p'; - $sql.= " WHERE p.entity = ".$conf->entity; - if ($projectsListId) $sql.= " AND p.rowid in (".$projectsListId.")"; - if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; - //if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc='0' OR p.fk_soc IS NULL)"; // We will filter later - $sql.= " ORDER BY p.title ASC"; - - //print $sql; - //var_dump($user->rights); - dol_syslog("project.lib::select_projects sql=".$sql); - $resql=$db->query($sql); - if ($resql) - { - print ''; - $db->free($resql); - return $num; - } - else - { - dol_print_error($db); - return -1; - } + global $db,$user,$conf,$langs; + + $hideunselectables = false; + if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true; + + $projectsListId = false; + if (empty($user->rights->projet->all->lire)) + { + $projectstatic=new Project($db); + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1); + } + + // On recherche les projets + $sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public'; + $sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p'; + $sql.= " WHERE p.entity = ".$conf->entity; + if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")"; + if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; + $sql.= " ORDER BY p.title ASC"; + + dol_syslog("project.lib::select_projects sql=".$sql); + $resql=$db->query($sql); + if ($resql) + { + print ''; + $db->free($resql); + return $num; + } + else + { + dol_print_error($db); + return -1; + } }