Fix: add function to sort project authorized for a user
This commit is contained in:
parent
0ded40ad3e
commit
e6b06fd6b4
@ -109,7 +109,8 @@ print "</table>";
|
||||
print '</td><td width="70%" valign="top" class="notopnoleft">';
|
||||
|
||||
$projectsIdArray=array();
|
||||
$projectsListArray = $projectstatic->getProjectsAuthorizedForUser($user);
|
||||
$mine = $_GET['mode']=='mine'?1:0;
|
||||
$projectsListArray = $projectstatic->getProjectsAuthorizedForUser($user,$mine);
|
||||
foreach ($projectsListArray as $key => $value)
|
||||
{
|
||||
$projectsIdArray[] = $key;
|
||||
@ -126,7 +127,7 @@ $sql.= ", s.nom, s.rowid as socid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
|
||||
$sql.= " WHERE p.entity = ".$conf->entity;
|
||||
$sql.= " AND p.rowid IN (".implode(',',$projectsIdArray).")";
|
||||
$sql.= " AND p.rowid IN (".(!empty($projectsIdArray) ? implode(',',$projectsIdArray) : 0).")";
|
||||
if ($socid) $sql.= " AND s.rowid = ".$socid;
|
||||
$sql.= " GROUP BY s.nom, s.rowid";
|
||||
|
||||
|
||||
@ -657,10 +657,10 @@ class Project extends CommonObject
|
||||
* @param unknown_type $user
|
||||
* @return unknown
|
||||
*/
|
||||
function getProjectsAuthorizedForUser($user)
|
||||
function getProjectsAuthorizedForUser($user,$mine=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
||||
$projects = array();
|
||||
|
||||
$sql = "SELECT DISTINCT p.rowid, p.ref";
|
||||
@ -668,12 +668,23 @@ class Project extends CommonObject
|
||||
$sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
|
||||
$sql.= " WHERE p.entity = ".$conf->entity;
|
||||
$sql.= " AND ( p.public = 1";
|
||||
$sql.= " OR p.fk_user_creat = ".$user->id;
|
||||
$sql.= " OR ( ec.element_id = p.rowid";
|
||||
$sql.= " AND ctc.rowid = ec.fk_c_type_contact";
|
||||
$sql.= " AND ctc.element = '".$this->element."'";
|
||||
$sql.= " AND ec.fk_socpeople = ".$user->id." ) )";
|
||||
|
||||
if ($mine)
|
||||
{
|
||||
$sql.= " AND ec.element_id = p.rowid";
|
||||
$sql.= " AND ctc.rowid = ec.fk_c_type_contact";
|
||||
$sql.= " AND ctc.element = '".$this->element."'";
|
||||
$sql.= " AND ec.fk_socpeople = ".$user->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql.= " AND ( p.public = 1";
|
||||
$sql.= " OR p.fk_user_creat = ".$user->id;
|
||||
$sql.= " OR ( ec.element_id = p.rowid";
|
||||
$sql.= " AND ctc.rowid = ec.fk_c_type_contact";
|
||||
$sql.= " AND ctc.element = '".$this->element."'";
|
||||
$sql.= " AND ec.fk_socpeople = ".$user->id." ) )";
|
||||
}
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user