2
0
forked from Wavyzz/dolibarr

Start normalize project module : create html.formprojet.class.php with

selec_project
This commit is contained in:
Florian Henry
2013-06-14 22:33:01 +02:00
parent 19214714e1
commit 8fb2b8fa12
19 changed files with 294 additions and 195 deletions

View File

@@ -190,111 +190,6 @@ function project_admin_prepare_head()
}
/**
* Show a combo list with projects qualified for a third party
*
* @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
* @param int $selected Id project preselected
* @param string $htmlname Nom de la zone html
* @param int $maxlength Maximum length of label
* @return int Nbre of project if OK, <0 if KO
*/
function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16)
{
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);
}
// Search all projects
$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 !== false) $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 '<select class="flat" name="'.$htmlname.'">';
print '<option value="0">&nbsp;</option>';
$num = $db->num_rows($resql);
$i = 0;
if ($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.
if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
{
// Do nothing
}
else
{
$labeltoshow=dol_trunc($obj->ref,18);
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
//else $labeltoshow.=' ('.$langs->trans("Private").')';
if (!empty($selected) && $selected == $obj->rowid && $obj->fk_statut > 0)
{
print '<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.' - '.dol_trunc($obj->title,$maxlength).'</option>';
}
else
{
$disabled=0;
if (! $obj->fk_statut > 0)
{
$disabled=1;
$labeltoshow.=' - '.$langs->trans("Draft");
}
if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
{
$disabled=1;
$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
}
if ($hideunselectables && $disabled)
{
$resultat='';
}
else
{
$resultat='<option value="'.$obj->rowid.'"';
if ($disabled) $resultat.=' disabled="disabled"';
//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
//else $labeltoshow.=' ('.$langs->trans("Private").')';
$resultat.='>'.$labeltoshow;
if (! $disabled) $resultat.=' - '.dol_trunc($obj->title,$maxlength);
$resultat.='</option>';
}
print $resultat;
}
}
$i++;
}
}
print '</select>';
$db->free($resql);
return $num;
}
else
{
dol_print_error($db);
return -1;
}
}
/**
* Show task lines with a particular parent
*
@@ -653,64 +548,6 @@ function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
return $inc;
}
/**
* Clean task not linked to a parent
*
* @param DoliDB $db Database handler
* @return int Nb of records deleted
*/
function clean_orphelins($db)
{
$nb=0;
// There is orphelins. We clean that
$listofid=array();
// Get list of id in array listofid
$sql='SELECT rowid FROM '.MAIN_DB_PREFIX.'projet_task';
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num && $i < 100)
{
$obj = $db->fetch_object($resql);
$listofid[]=$obj->rowid;
$i++;
}
}
else
{
dol_print_error($db);
}
if (count($listofid))
{
// Removed orphelins records
print 'Some orphelins were found and restored to be parents so records are visible again: ';
print join(',',$listofid);
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
$sql.= " SET fk_task_parent = 0";
$sql.= " WHERE fk_task_parent NOT IN (".join(',',$listofid).")";
$resql = $db->query($sql);
if ($resql)
{
$nb=$db->affected_rows($sql);
return $nb;
}
else
{
return -1;
}
}
}
/**
* Return HTML table with list of projects and number of opened tasks
*