PageRenderTime 150ms CodeModel.GetById 60ms app.highlight 55ms RepoModel.GetById 26ms app.codeStats 0ms

/htdocs/core/lib/project.lib.php

https://github.com/asterix14/dolibarr
PHP | 711 lines | 467 code | 97 blank | 147 comment | 109 complexity | dd66f1ed41e157da5321e25b8b7f0010 MD5 | raw file
  1<?php
  2/* Copyright (C) 2006-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  3 * Copyright (C) 2010      Regis Houssin        <regis@dolibarr.fr>
  4* Copyright (C) 2011      Juanjo Menent        <jmenent@2byte.es>
  5*
  6* This program is free software; you can redistribute it and/or modify
  7* it under the terms of the GNU General Public License as published by
  8* the Free Software Foundation; either version 2 of the License, or
  9* (at your option) any later version.
 10*
 11* This program is distributed in the hope that it will be useful,
 12* but WITHOUT ANY WARRANTY; without even the implied warranty of
 13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14* GNU General Public License for more details.
 15*
 16* You should have received a copy of the GNU General Public License
 17* along with this program. If not, see <http://www.gnu.org/licenses/>.
 18* or see http://www.gnu.org/
 19*/
 20
 21/**
 22 *	    \file       htdocs/core/lib/project.lib.php
 23 *		\brief      Functions used by project module
 24 *      \ingroup    project
 25 */
 26require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
 27
 28
 29function project_prepare_head($object)
 30{
 31    global $langs, $conf, $user;
 32    $h = 0;
 33    $head = array();
 34
 35    $head[$h][0] = DOL_URL_ROOT.'/projet/fiche.php?id='.$object->id;
 36    $head[$h][1] = $langs->trans("Project");
 37    $head[$h][2] = 'project';
 38    $h++;
 39
 40    $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
 41    $head[$h][1] = $langs->trans("ProjectContact");
 42    $head[$h][2] = 'contact';
 43    $h++;
 44
 45    if ($conf->fournisseur->enabled || $conf->propal->enabled || $conf->commande->enabled || $conf->facture->enabled || $conf->contrat->enabled
 46    || $conf->ficheinter->enabled || $conf->agenda->enabled || $conf->deplacement->enabled)
 47    {
 48        $head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$object->id;
 49        $head[$h][1] = $langs->trans("Referers");
 50        $head[$h][2] = 'element';
 51        $h++;
 52    }
 53
 54    // Show more tabs from modules
 55    // Entries must be declared in modules descriptor with line
 56    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
 57    // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
 58    complete_head_from_modules($conf,$langs,$object,$head,$h,'project');
 59
 60    $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
 61    /*$filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
 62     include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
 63    $listoffiles=dol_dir_list($filesdir,'files',1);
 64    $head[$h][1] = (count($listoffiles)?$langs->trans('DocumentsNb',count($listoffiles)):$langs->trans('Documents'));*/
 65    $head[$h][1] = $langs->trans('Documents');
 66    $head[$h][2] = 'document';
 67    $h++;
 68
 69    $head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
 70    $head[$h][1] = $langs->trans('Notes');
 71    $head[$h][2] = 'note';
 72    $h++;
 73
 74    // Then tab for sub level of projet, i mean tasks
 75    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id;
 76    $head[$h][1] = $langs->trans("Tasks");
 77    $head[$h][2] = 'tasks';
 78    $h++;
 79
 80    /* Now this is a filter in the Task tab.
 81     $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id.'&mode=mine';
 82    $head[$h][1] = $langs->trans("MyTasks");
 83    $head[$h][2] = 'mytasks';
 84    $h++;
 85    */
 86
 87    $head[$h][0] = DOL_URL_ROOT.'/projet/ganttview.php?id='.$object->id;
 88    $head[$h][1] = $langs->trans("Gantt");
 89   	$head[$h][2] = 'gantt';
 90   	$h++;
 91
 92   	return $head;
 93}
 94
 95
 96/**
 97 *	    \file       htdocs/core/lib/project.lib.php
 98 *		\brief      Ensemble de fonctions de base pour le module projet
 99 *      \ingroup    societe
100 */
101function task_prepare_head($object)
102{
103    global $langs, $conf, $user;
104    $h = 0;
105    $head = array();
106
107    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id;
108    $head[$h][1] = $langs->trans("Card");
109    $head[$h][2] = 'task';
110    $h++;
111
112    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id;
113    $head[$h][1] = $langs->trans("TaskRessourceLinks");
114    $head[$h][2] = 'contact';
115    $h++;
116
117    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id;
118    $head[$h][1] = $langs->trans("TimeSpent");
119    $head[$h][2] = 'time';
120    $h++;
121
122    // Show more tabs from modules
123    // Entries must be declared in modules descriptor with line
124    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
125    // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
126    complete_head_from_modules($conf,$langs,$object,$head,$h,'task');
127
128    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id;
129    /*$filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
130     include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
131    $listoffiles=dol_dir_list($filesdir,'files',1);
132    $head[$h][1] = (count($listoffiles)?$langs->trans('DocumentsNb',count($listoffiles)):$langs->trans('Documents'));*/
133    $head[$h][1] = $langs->trans('Documents');
134    $head[$h][2] = 'document';
135    $h++;
136
137    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id;
138    $head[$h][1] = $langs->trans('Notes');
139    $head[$h][2] = 'note';
140    $h++;
141
142    return $head;
143}
144
145
146
147/**
148 *	Show a combo list with projects qualified for a third party
149 *
150 *	@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)
151 *	@param  int		$selected   Id project preselected
152 *	@param  string	$htmlname   Nom de la zone html
153 *	@return int         		Nbre of project if OK, <0 if KO
154 */
155function select_projects($socid=-1, $selected='', $htmlname='projectid')
156{
157    global $db,$user,$conf,$langs;
158
159    $hideunselectables = false;
160    if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
161
162    $projectstatic=new Project($db);
163    $projectsListId = '';
164    if (empty($user->rights->projet->all->lire))
165    {
166        $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
167    }
168
169    // On recherche les projets
170    $sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public';
171    $sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
172    $sql.= " WHERE p.entity = ".$conf->entity;
173    if ($projectsListId) $sql.= " AND p.rowid in (".$projectsListId.")";
174    if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
175    //if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc='0' OR p.fk_soc IS NULL)";	// We will filter later
176    $sql.= " ORDER BY p.title ASC";
177
178    //print $sql;
179    //var_dump($user->rights);
180    dol_syslog("project.lib::select_projects sql=".$sql);
181    $resql=$db->query($sql);
182    if ($resql)
183    {
184        print '<select class="flat" name="'.$htmlname.'">';
185        print '<option value="0">&nbsp;</option>';
186        $num = $db->num_rows($resql);
187        $i = 0;
188        if ($num)
189        {
190            while ($i < $num)
191            {
192                $obj = $db->fetch_object($resql);
193                // 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.
194                if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
195                {
196                    // Do nothing
197                }
198                else
199                {
200                    $labeltoshow=dol_trunc($obj->ref,16);
201                    //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
202                    //else $labeltoshow.=' ('.$langs->trans("Private").')';
203                    if (!empty($selected) && $selected == $obj->rowid && $obj->fk_statut > 0)
204                    {
205                        print '<option value="'.$obj->rowid.'" selected="selected">'.$labeltoshow.'</option>';
206                    }
207                    else
208                    {
209                        $disabled=0;
210                        if (! $obj->fk_statut > 0)
211                        {
212                            $disabled=1;
213                            $labeltoshow.=' - '.$langs->trans("Draft");
214                        }
215                        if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
216                        {
217                            $disabled=1;
218                            $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
219                        }
220
221                        if ($hideunselectables && $disabled)
222                        {
223                            $resultat='';
224                        }
225                        else
226                        {
227                            $resultat='<option value="'.$obj->rowid.'"';
228                            if ($disabled) $resultat.=' disabled="disabled"';
229                            //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
230                            //else $labeltoshow.=' ('.$langs->trans("Private").')';
231                            $resultat.='>'.$labeltoshow;
232                            if (! $disabled) $resultat.=' - '.dol_trunc($obj->title,12);
233                            $resultat.='</option>';
234                        }
235                        print $resultat;
236                    }
237                }
238                $i++;
239            }
240        }
241        print '</select>';
242        $db->free($resql);
243        return $num;
244    }
245    else
246    {
247        dol_print_error($db);
248        return -1;
249    }
250}
251
252
253/**
254 * Output a task line
255 * @param   $inc
256 * @param   $parent
257 * @param   $lines
258 * @param   $level
259 * @param   $projectsrole
260 * @param   $tasksrole
261 * @param   $mytask			0 or 1 to enable only if task is a task i am affected to
262 * @return  $inc
263 */
264function PLinesb(&$inc, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mytask=0)
265{
266    global $user, $bc, $langs;
267    global $form;
268
269    $lastprojectid=0;
270
271    $projectstatic = new Project($db);
272    $taskstatic = new Task($db);
273
274    $var=true;
275
276    $numlines=count($lines);
277    for ($i = 0 ; $i < $numlines ; $i++)
278    {
279        if ($parent == 0) $level = 0;
280
281        if ($lines[$i]->fk_parent == $parent)
282        {
283            // Break on a new project
284            if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
285            {
286                $var = !$var;
287                $lastprojectid=$lines[$i]->fk_project;
288            }
289
290            print "<tr $bc[$var]>\n";
291
292            // Project
293            print "<td>";
294            $projectstatic->id=$lines[$i]->fk_project;
295            $projectstatic->ref=$lines[$i]->projectref;
296            $projectstatic->public=$lines[$i]->public;
297            $projectstatic->label=$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project];
298            print $projectstatic->getNomUrl(1);
299            print "</td>";
300
301            // Ref
302            print '<td>';
303            $taskstatic->id=$lines[$i]->id;
304            $taskstatic->ref=$lines[$i]->id;
305            print $taskstatic->getNomUrl(1);
306            print '</td>';
307
308            // Label task
309            print "<td>";
310
311            for ($k = 0 ; $k < $level ; $k++)
312            {
313                print "&nbsp;&nbsp;&nbsp;";
314            }
315            print $lines[$i]->label;
316            print "</td>\n";
317
318            // Time spent
319            print '<td align="right">';
320            if ($lines[$i]->duration) print ConvertSecondToTime($lines[$i]->duration,'all');
321            else print '--:--';
322            print "</td>\n";
323
324            $disabledproject=1;$disabledtask=1;
325            //print "x".$lines[$i]->fk_project;
326            //var_dump($lines[$i]);
327            //var_dump($projectsrole[$lines[$i]->fk_project]);
328            // If at least one role for project
329            if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
330            {
331                $disabledproject=0;
332                $disabledtask=0;
333            }
334            // If mytask and no role on task
335            if ($mytask && empty($tasksrole[$lines[$i]->id]))
336            {
337                $disabledtask=1;
338            }
339
340            print '<td nowrap="nowrap">';
341            print $form->select_date('',$lines[$i]->id,'','','',"addtime",1,0,1,$disabledtask);
342            print '&nbsp;&nbsp;&nbsp;';
343            print $form->select_duration($lines[$i]->id,'',$disabledtask);
344            print '&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled="disabled"':'').' value="'.$langs->trans("Add").'">';
345            if ($disabledtask) print '('.$langs->trans("TaskIsNotAffectedToYou").')';
346            if ((! $lines[$i]->public) && $disabledproject) print '('.$langs->trans("YouAreNotContactOfProject").')';
347            print '</td>';
348            print "<td>&nbsp;";
349            print '</td>';
350
351            print "</tr>\n";
352            $inc++;
353            $level++;
354            if ($lines[$i]->id) PLinesb($inc, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mytask);
355            $level--;
356        }
357        else
358        {
359            //$level--;
360        }
361    }
362
363    return $inc;
364}
365
366
367/**
368 * Show task lines with a particular parent
369 * @param 	$inc				Counter that count number of lines legitimate to show (for return)
370 * @param 	$parent				Id of parent task to start
371 * @param 	$lines				Array of all tasks
372 * @param 	$level				Level of task
373 * @param 	$var				Color
374 * @param 	$showproject		Show project columns
375 * @param	$taskrole			Array of roles of user for each tasks
376 * @param	$projectsListId		List of id of project allowed to user (separated with comma)
377 */
378function PLines(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='')
379{
380    global $user, $bc, $langs;
381
382    $lastprojectid=0;
383
384    $projectstatic = new Project($db);
385    $taskstatic = new Task($db);
386
387    $projectsArrayId=explode(',',$projectsListId);
388
389    $numlines=count($lines);
390
391    $total=0;
392
393    for ($i = 0 ; $i < $numlines ; $i++)
394    {
395        if ($parent == 0) $level = 0;
396
397        // Process line
398        // print "i:".$i."-".$lines[$i]->fk_project.'<br>';
399
400        if ($lines[$i]->fk_parent == $parent)
401        {
402            // Show task line.
403            $showline=1;
404            $showlineingray=0;
405
406            // If there is filters to use
407            if (is_array($taskrole))
408            {
409                // If task not legitimate to show, search if a legitimate task exists later in tree
410                if (! isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent)
411                {
412                    // So search if task has a subtask legitimate to show
413                    $foundtaskforuserdeeper=0;
414                    SearchTaskInChild($foundtaskforuserdeeper,$lines[$i]->id,$lines,$taskrole);
415                    //print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
416                    if ($foundtaskforuserdeeper > 0)
417                    {
418                        $showlineingray=1;		// We will show line but in gray
419                    }
420                    else
421                    {
422                        $showline=0;			// No reason to show line
423                    }
424                }
425            }
426
427            if ($showline)
428            {
429                // Break on a new project
430                if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
431                {
432                    $var = !$var;
433                    $lastprojectid=$lines[$i]->fk_project;
434                }
435
436                print "<tr ".$bc[$var].">\n";
437
438                // Project
439                if ($showproject)
440                {
441                    print "<td>";
442                    //var_dump($taskrole);
443                    if ($showlineingray) print '<i>';
444                    $projectstatic->id=$lines[$i]->fk_project;
445                    $projectstatic->ref=$lines[$i]->projectref;
446                    $projectstatic->public=$lines[$i]->public;
447                    if ($lines[$i]->public || in_array($lines[$i]->fk_project,$projectsArrayId)) print $projectstatic->getNomUrl(1);
448                    else print $projectstatic->getNomUrl(1,'nolink');
449                    if ($showlineingray) print '</i>';
450                    print "</td>";
451                }
452
453                // Ref of task
454                print '<td>';
455                if ($showlineingray)
456                {
457                    print '<i>'.img_object('','projecttask').' '.$lines[$i]->id.'</i>';
458                }
459                else
460                {
461                    $taskstatic->id=$lines[$i]->id;
462                    $taskstatic->ref=$lines[$i]->id;
463                    $taskstatic->label=($taskrole[$lines[$i]->id]?$langs->trans("YourRole").': '.$taskrole[$lines[$i]->id]:'');
464                    print $taskstatic->getNomUrl(1);
465                }
466                print '</td>';
467
468                // Title of task
469                print "<td>";
470                if ($showlineingray) print '<i>';
471                else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'">';
472                for ($k = 0 ; $k < $level ; $k++)
473                {
474                    print "&nbsp; &nbsp; &nbsp;";
475                }
476                print $lines[$i]->label;
477                if ($showlineingray) print '</i>';
478                else print '</a>';
479                print "</td>\n";
480
481                // Progress
482                print '<td align="right">';
483                print $lines[$i]->progress.' %';
484                print '</td>';
485
486                // Time spent
487                print '<td align="right">';
488                if ($showlineingray) print '<i>';
489                else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
490                if ($lines[$i]->duration) print ConvertSecondToTime($lines[$i]->duration,'all');
491                else print '--:--';
492                if ($showlineingray) print '</i>';
493                else print '</a>';
494                print '</td>';
495
496                print "</tr>\n";
497
498                if (! $showlineingray) $inc++;
499
500                $level++;
501                if ($lines[$i]->id) PLines($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId);
502                $level--;
503                $total += $lines[$i]->duration;
504            }
505        }
506        else
507        {
508            //$level--;
509        }
510    }
511
512    if ($total>0)
513    {
514        print '<tr class="liste_total"><td class="liste_total">'.$langs->trans("Total").'</td>';
515        print '<td></td>';
516        print '<td></td>';
517        print '<td align="right" nowrap="nowrap" class="liste_total">'.ConvertSecondToTime($total).'</td></tr>';
518    }
519
520    return $inc;
521}
522
523
524/**
525 * Search in task lines with a particular parent if there is a task for a particular user (in taskrole)
526 * @param 	$inc				Counter that count number of lines legitimate to show (for return)
527 * @param 	$parent				Id of parent task to start
528 * @param 	$lines				Array of all tasks
529 * @param	$taskrole			Array of task filtered on a particular user
530 * @return	int					1 if there is
531 */
532function SearchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
533{
534    //print 'Search in line with parent id = '.$parent.'<br>';
535    $numlines=count($lines);
536    for ($i = 0 ; $i < $numlines ; $i++)
537    {
538        // Process line $lines[$i]
539        if ($lines[$i]->fk_parent == $parent && $lines[$i]->id != $lines[$i]->fk_parent)
540        {
541            // If task is legitimate to show, no more need to search deeper
542            if (isset($taskrole[$lines[$i]->id]))
543            {
544                //print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
545                $inc++;
546                return $inc;
547            }
548
549            SearchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
550            //print 'Found inc='.$inc.'<br>';
551
552            if ($inc > 0) return $inc;
553        }
554    }
555
556    return $inc;
557}
558
559
560/**
561 * Clean task not linked to a parent
562 * @param   $db     Database handler
563 * @return	int		Nb of records deleted
564 */
565function clean_orphelins($db)
566{
567    $nb=0;
568
569    // There is orphelins. We clean that
570    $listofid=array();
571
572    // Get list of id in array listofid
573    $sql='SELECT rowid FROM '.MAIN_DB_PREFIX.'projet_task';
574    $resql = $db->query($sql);
575    if ($resql)
576    {
577        $num = $db->num_rows($resql);
578        $i = 0;
579        while ($i < $num && $i < 100)
580        {
581            $obj = $db->fetch_object($resql);
582            $listofid[]=$obj->rowid;
583            $i++;
584        }
585    }
586    else
587    {
588        dol_print_error($db);
589    }
590
591    if (count($listofid))
592    {
593        // Removed orphelins records
594        print 'Some orphelins were found and restored to be parents so records are visible again: ';
595        print join(',',$listofid);
596
597        $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
598        $sql.= " SET fk_task_parent = 0";
599        $sql.= " WHERE fk_task_parent NOT IN (".join(',',$listofid).")";
600
601        $resql = $db->query($sql);
602        if ($resql)
603        {
604            $nb=$db->affected_rows($sql);
605
606            return $nb;
607        }
608        else
609        {
610            return -1;
611        }
612    }
613}
614
615
616/**
617 * Return HTML table with list of projects and number of opened tasks
618 *
619 * @param   $db
620 * @param   $socid
621 * @param   $projectsListId     Id of project i have permission on
622 * @param   $mytasks            Limited to task i am contact to
623 */
624function print_projecttasks_array($db, $socid, $projectsListId, $mytasks=0)
625{
626    global $langs,$conf,$user,$bc;
627
628    require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
629
630    $projectstatic=new Project($db);
631
632    $sortfield='';
633    $sortorder='';
634
635    print '<table class="noborder" width="100%">';
636    print '<tr class="liste_titre">';
637    print_liste_field_titre($langs->trans("Project"),"index.php","","","","",$sortfield,$sortorder);
638    print_liste_field_titre($langs->trans("NbOpenTasks"),"","","","",'align="right"',$sortfield,$sortorder);
639    print_liste_field_titre($langs->trans("Status"),"","","","",'align="right"',$sortfield,$sortorder);
640    print "</tr>\n";
641
642    $sql = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut, COUNT(t.rowid) as nb";
643    $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
644    if ($mytasks)
645    {
646        $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
647        $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
648        $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
649    }
650    else
651    {
652        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
653    }
654    $sql.= " WHERE p.entity = ".$conf->entity;
655    $sql.= " AND p.rowid IN (".$projectsListId.")";
656    if ($socid) $sql.= "  AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
657    if ($mytasks)
658    {
659        $sql.= " AND p.rowid = t.fk_projet";
660        $sql.= " AND ec.element_id = t.rowid";
661        $sql.= " AND ctc.rowid = ec.fk_c_type_contact";
662        $sql.= " AND ctc.element = 'project_task'";
663        $sql.= " AND ec.fk_socpeople = ".$user->id;
664    }
665    $sql.= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut";
666    $sql.= " ORDER BY p.title, p.ref";
667
668    $var=true;
669    $resql = $db->query($sql);
670    if ( $resql )
671    {
672        $num = $db->num_rows($resql);
673        $i = 0;
674
675        while ($i < $num)
676        {
677            $objp = $db->fetch_object($resql);
678
679            $projectstatic->id = $objp->projectid;
680            $projectstatic->user_author_id = $objp->fk_user_creat;
681            $projectstatic->public = $objp->public;
682
683            // Check is user has read permission on project
684            $userAccess = $projectstatic->restrictedProjectArea($user,1);
685            if ($userAccess >= 0)
686            {
687                $var=!$var;
688                print "<tr ".$bc[$var].">";
689                print '<td nowrap="nowrap">';
690                $projectstatic->ref=$objp->ref;
691                print $projectstatic->getNomUrl(1);
692                print ' - '.$objp->title.'</td>';
693                print '<td align="right">'.$objp->nb.'</td>';
694                $projectstatic->statut = $objp->fk_statut;
695                print '<td align="right">'.$projectstatic->getLibStatut(3).'</td>';
696                print "</tr>\n";
697            }
698
699            $i++;
700        }
701
702        $db->free($resql);
703    }
704    else
705    {
706        dol_print_error($db);
707    }
708    print "</table>";
709}
710
711?>