Fix: instantiate class if needed

Fix: reindent and clean code
This commit is contained in:
Regis Houssin 2011-12-13 10:39:59 +01:00
parent 1e76d296ae
commit 70bccc91ba

View File

@ -154,99 +154,96 @@ function task_prepare_head($object)
*/ */
function select_projects($socid=-1, $selected='', $htmlname='projectid') function select_projects($socid=-1, $selected='', $htmlname='projectid')
{ {
global $db,$user,$conf,$langs; global $db,$user,$conf,$langs;
$hideunselectables = false; $hideunselectables = false;
if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true; if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
$projectstatic=new Project($db); $projectsListId = false;
$projectsListId = ''; if (empty($user->rights->projet->all->lire))
if (empty($user->rights->projet->all->lire)) {
{ $projectstatic=new Project($db);
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1); $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
} }
// On recherche les projets // On recherche les projets
$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public'; $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.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
$sql.= " WHERE p.entity = ".$conf->entity; $sql.= " WHERE p.entity = ".$conf->entity;
if ($projectsListId) $sql.= " AND p.rowid in (".$projectsListId.")"; 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=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";
$sql.= " ORDER BY p.title ASC";
//print $sql; dol_syslog("project.lib::select_projects sql=".$sql);
//var_dump($user->rights); $resql=$db->query($sql);
dol_syslog("project.lib::select_projects sql=".$sql); if ($resql)
$resql=$db->query($sql); {
if ($resql) print '<select class="flat" name="'.$htmlname.'">';
{ print '<option value="0">&nbsp;</option>';
print '<select class="flat" name="'.$htmlname.'">'; $num = $db->num_rows($resql);
print '<option value="0">&nbsp;</option>'; $i = 0;
$num = $db->num_rows($resql); if ($num)
$i = 0; {
if ($num) while ($i < $num)
{ {
while ($i < $num) $obj = $db->fetch_object($resql);
{ // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
$obj = $db->fetch_object($resql); if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. {
if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) // Do nothing
{ }
// Do nothing else
} {
else $labeltoshow=dol_trunc($obj->ref,16);
{ //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
$labeltoshow=dol_trunc($obj->ref,16); //else $labeltoshow.=' ('.$langs->trans("Private").')';
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; if (!empty($selected) && $selected == $obj->rowid && $obj->fk_statut > 0)
//else $labeltoshow.=' ('.$langs->trans("Private").')'; {
if (!empty($selected) && $selected == $obj->rowid && $obj->fk_statut > 0) print '<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.'</option>';
{ }
print '<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.'</option>'; else
} {
else $disabled=0;
{ if (! $obj->fk_statut > 0)
$disabled=0; {
if (! $obj->fk_statut > 0) $disabled=1;
{ $labeltoshow.=' - '.$langs->trans("Draft");
$disabled=1; }
$labeltoshow.=' - '.$langs->trans("Draft"); if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
} {
if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) $disabled=1;
{ $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
$disabled=1; }
$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
}
if ($hideunselectables && $disabled) if ($hideunselectables && $disabled)
{ {
$resultat=''; $resultat='';
} }
else else
{ {
$resultat='<option value="'.$obj->rowid.'"'; $resultat='<option value="'.$obj->rowid.'"';
if ($disabled) $resultat.=' disabled="disabled"'; if ($disabled) $resultat.=' disabled="disabled"';
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')'; //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
//else $labeltoshow.=' ('.$langs->trans("Private").')'; //else $labeltoshow.=' ('.$langs->trans("Private").')';
$resultat.='>'.$labeltoshow; $resultat.='>'.$labeltoshow;
if (! $disabled) $resultat.=' - '.dol_trunc($obj->title,12); if (! $disabled) $resultat.=' - '.dol_trunc($obj->title,12);
$resultat.='</option>'; $resultat.='</option>';
} }
print $resultat; print $resultat;
} }
} }
$i++; $i++;
} }
} }
print '</select>'; print '</select>';
$db->free($resql); $db->free($resql);
return $num; return $num;
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
return -1; return -1;
} }
} }