From f235caf4ece0feaa71c8a609eeb15cd13003e598 Mon Sep 17 00:00:00 2001 From: FHenry Date: Wed, 18 Apr 2012 11:16:15 +0200 Subject: [PATCH] Fix: Bug #362 and clean code --- htdocs/projet/tasks/contact.php | 148 ++++++++------- htdocs/projet/tasks/document.php | 307 ++++++++++++++++--------------- htdocs/projet/tasks/note.php | 84 ++++++--- htdocs/projet/tasks/task.php | 172 +++++++++-------- htdocs/projet/tasks/time.php | 166 +++++++++-------- 5 files changed, 479 insertions(+), 398 deletions(-) diff --git a/htdocs/projet/tasks/contact.php b/htdocs/projet/tasks/contact.php index 69543c2a163..4c19d85888b 100644 --- a/htdocs/projet/tasks/contact.php +++ b/htdocs/projet/tasks/contact.php @@ -1,7 +1,7 @@ - * Copyright (C) 2006-2010 Laurent Destailleur - * Copyright (C) 2010 Regis Houssin +/* Copyright (C) 2005 Rodolphe Quiedeville + * Copyright (C) 2006-2010 Laurent Destailleur + * Copyright (C) 2010-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,17 +33,21 @@ require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'); $langs->load("projects"); $langs->load("companies"); -$taskid = isset($_GET["id"])?$_GET["id"]:''; -$id = GETPOST('id','int'); -$ref= GETPOST('ref'); -$action=GETPOST('action'); -$withproject=GETPOST('withproject'); +$id=GETPOST('id','int'); +$ref=GETPOST('ref','alpha'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); +$withproject=GETPOST('withproject','int'); +$project_ref=GETPOST('project_ref','alpha'); // Security check $socid=0; if ($user->societe_id > 0) $socid = $user->societe_id; -//$result = restrictedArea($user, 'projet', $taskid, 'projet_task'); -if (!$user->rights->projet->lire) accessforbidden(); +//$result = restrictedArea($user, 'projet', $id, 'projet_task'); +if (! $user->rights->projet->lire) accessforbidden(); + +$object = new Task($db); +$projectstatic = new Project($db); /* @@ -53,31 +57,28 @@ if (!$user->rights->projet->lire) accessforbidden(); // Add new contact if ($action == 'addcontact' && $user->rights->projet->creer) { + $result = $object->fetch($id); - $result = 0; - $task = new Task($db); - $result = $task->fetch($taskid); - - if ($result > 0 && $taskid > 0) + if ($result > 0 && $id > 0) { - $result = $task->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]); + $result = $object->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]); } if ($result >= 0) { - Header("Location: contact.php?id=".$task->id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } else { - if ($task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; } else { - $mesg = '
'.$task->error.'
'; + $mesg = '
'.$object->error.'
'; } } } @@ -85,10 +86,9 @@ if ($action == 'addcontact' && $user->rights->projet->creer) // bascule du statut d'un contact if ($action == 'swapstatut' && $user->rights->projet->creer) { - $task = new Task($db); - if ($task->fetch($taskid)) + if ($object->fetch($id)) { - $result=$task->swapContactStatus(GETPOST('ligne')); + $result=$object->swapContactStatus(GETPOST('ligne')); } else { @@ -99,13 +99,12 @@ if ($action == 'swapstatut' && $user->rights->projet->creer) // Efface un contact if ($action == 'deleteline' && $user->rights->projet->creer) { - $task = new Task($db); - $task->fetch($taskid); - $result = $task->delete_contact($_GET["lineid"]); + $object->fetch($id); + $result = $object->delete_contact($_GET["lineid"]); if ($result >= 0) { - Header("Location: contact.php?id=".$task->id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } else @@ -114,6 +113,22 @@ if ($action == 'deleteline' && $user->rights->projet->creer) } } +// Retreive First Task ID of Project if withprojet is on to allow project prev next to work +if (! empty($project_ref) && ! empty($withproject)) +{ + if ($projectstatic->fetch(0,$project_ref) > 0) + { + $tasksarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0); + if (count($tasksarray) > 0) + { + $id=$tasksarray[0]->id; + } + else + { + Header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode)?'':'&mode='.$mode)); + } + } +} /* * View @@ -125,8 +140,6 @@ $form = new Form($db); $formcompany = new FormCompany($db); $contactstatic = new Contact($db); $userstatic = new User($db); -$project = new Project($db); -$task = new Task($db); /* *************************************************************************** */ @@ -137,19 +150,19 @@ $task = new Task($db); if ($id > 0 || ! empty($ref)) { - if ($task->fetch($id,$ref) > 0) + if ($object->fetch($id) > 0) { - $result=$project->fetch($task->fk_project); - if (! empty($project->socid)) $project->societe->fetch($project->socid); + $result=$projectstatic->fetch($object->fk_project); + if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); - $userWrite = $project->restrictedProjectArea($user,'write'); + $userWrite = $projectstatic->restrictedProjectArea($user,'write'); if ($withproject) { // Tabs for project $tab='tasks'; - $head=project_prepare_head($project); - dol_fiche_head($head, $tab, $langs->trans("Project"),0,($project->public?'projectpub':'project')); + $head=project_prepare_head($projectstatic); + dol_fiche_head($head, $tab, $langs->trans("Project"),0,($projectstatic->public?'projectpub':'project')); $param=($mode=='mine'?'&mode=mine':''); @@ -162,28 +175,28 @@ if ($id > 0 || ! empty($ref)) // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,0); - $project->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0); + $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; } - print $form->showrefnav($project,'ref','',1,'ref','ref','',$param); + print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1'); print ''; - print ''.$langs->trans("Label").''.$project->title.''; + print ''.$langs->trans("Label").''.$projectstatic->title.''; print ''.$langs->trans("Company").''; - if (! empty($project->societe->id)) print $project->societe->getNomUrl(1); + if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); else print ' '; print ''; print ''; // Visibility print ''.$langs->trans("Visibility").''; - if ($project->public) print $langs->trans('SharedProject'); + if ($projectstatic->public) print $langs->trans('SharedProject'); else print $langs->trans('PrivateProject'); print ''; // Statut - print ''.$langs->trans("Status").''.$project->getLibStatut(4).''; + print ''.$langs->trans("Status").''.$projectstatic->getLibStatut(4).''; print ''; @@ -193,12 +206,12 @@ if ($id > 0 || ! empty($ref)) } // To verify role of users - //$userAccess = $project->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project - //$arrayofuseridoftask=$task->getListContactId('internal'); + //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project + //$arrayofuseridoftask=$object->getListContactId('internal'); dol_htmloutput_mesg($mesg); - $head = task_prepare_head($task); + $head = task_prepare_head($object); dol_fiche_head($head, 'task_contact', $langs->trans("Task"), 0, 'projecttask'); @@ -208,33 +221,33 @@ if ($id > 0 || ! empty($ref)) print ''; $param=(GETPOST('withproject')?'&withproject=1':''); - $linkback=GETPOST('withproject')?''.$langs->trans("BackToList").'':''; + $linkback=GETPOST('withproject')?''.$langs->trans("BackToList").'':''; // Ref print ''; // Label - print ''; + print ''; // Project if (empty($withproject)) { print ''; // Customer print ""; print ''; } @@ -283,11 +296,11 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; print ''; @@ -295,13 +308,13 @@ if ($id > 0 || ! empty($ref)) print ''; // Line to add an external contact. Only if project linked to a third party. - if ($project->socid) + if ($projectstatic->socid) { - print ''; + print ''; print ''; print ''; print ''; - print ''; + print ''; $var=!$var; print ""; @@ -311,18 +324,18 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; print ''; print ''; // Icon update et delete @@ -415,7 +428,7 @@ if ($id > 0 || ! empty($ref)) if ($user->rights->projet->creer) { print ' '; - print ''; + print ''; print img_delete(); print ''; } @@ -436,6 +449,5 @@ if ($id > 0 || ! empty($ref)) llxFooter(); - $db->close(); ?> diff --git a/htdocs/projet/tasks/document.php b/htdocs/projet/tasks/document.php index 12840e9dd34..37856acec08 100644 --- a/htdocs/projet/tasks/document.php +++ b/htdocs/projet/tasks/document.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,12 +32,14 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); $langs->load('projects'); $langs->load('other'); -$action=GETPOST('action'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); $mine = $_REQUEST['mode']=='mine' ? 1 : 0; //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects $id = GETPOST('id','int'); -$ref= GETPOST('ref'); -$withproject=GETPOST('withproject'); +$ref= GETPOST('ref','alpha'); +$withproject=GETPOST('withproject','int'); +$project_ref = GETPOST('project_ref','alpha'); // Security check $socid=0; @@ -57,21 +59,23 @@ if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="name"; +$object = new Task($db); +$projectstatic = new Project($db); -$task = new Task($db); - -if ($task->fetch($id,$ref) > 0) +if ($id > 0 || ! empty($ref)) { - $projectstatic = new Project($db); - $projectstatic->fetch($task->fk_project); - - if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); - - $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($task->ref); -} -else -{ - dol_print_error($db); + if ($object->fetch($id,$ref) > 0) + { + $projectstatic->fetch($object->fk_project); + + if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); + + $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref); + } + else + { + dol_print_error($db); + } } @@ -118,143 +122,155 @@ if ($action=='delete') $mesg = '
'.$langs->trans("FileWasRemoved").'
'; } +// Retreive First Task ID of Project if withprojet is on to allow project prev next to work +if (! empty($project_ref) && ! empty($withproject)) +{ + if ($projectstatic->fetch(0,$project_ref) > 0) + { + $tasksarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0); + if (count($tasksarray) > 0) + { + $id=$tasksarray[0]->id; + $object->fetch($id); + } + else + { + Header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode)?'':'&mode='.$mode)); + } + } +} + /* * View */ $form = new Form($db); -$project = new Project($db); -$task = new Task($db); llxHeader('',$langs->trans('Project')); -if ($id > 0 || ! empty($ref)) -{ - if ($task->fetch($id,$ref) >= 0) - { - $result=$project->fetch($task->fk_project); - if (! empty($project->socid)) $project->societe->fetch($project->socid); - - $userWrite = $project->restrictedProjectArea($user,'write'); - - if ($withproject) - { - // Tabs for project - $tab='tasks'; - $head=project_prepare_head($project); - dol_fiche_head($head, $tab, $langs->trans("Project"),0,($project->public?'projectpub':'project')); - - $param=($mode=='mine'?'&mode=mine':''); - - print '
'.$langs->trans('Ref').''; - if (! GETPOST('withproject') || empty($project->id)) + if (! GETPOST('withproject') || empty($projectstatic->id)) { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1); - $task->next_prev_filter=" fk_projet in (".$projectsListId.")"; + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); + $object->next_prev_filter=" fk_projet in (".$projectsListId.")"; } - else $task->next_prev_filter=" fk_projet = ".$project->id; - print $form->showrefnav($task,'id',$linkback,1,'rowid','ref','',$param); + else $object->next_prev_filter=" fk_projet = ".$projectstatic->id; + print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param); print '
'.$langs->trans("Label").''.$task->label.'
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("Project").''; - print $project->getNomUrl(1); + print $projectstatic->getNomUrl(1); print '
".$langs->trans("Company")."'; - if ($project->societe->id > 0) print $project->societe->getNomUrl(1); + if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1); else print ' '; print '
'; // On recupere les id des users deja selectionnes - $contactsofproject=$project->getListContactId('internal'); + $contactsofproject=$projectstatic->getListContactId('internal'); $form->select_users($user->id,'contactid',0,'',0,'',$contactsofproject); print ''; - $formcompany->selectTypeContact($task, '', 'type','internal','rowid'); + $formcompany->selectTypeContact($object, '', 'type','internal','rowid'); print '
'; - $thirdpartyofproject=$project->getListContactId('thirdparty'); - $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$project->societe->id; - $selectedCompany = $formcompany->selectCompaniesForNewContact($task, 'id', $selectedCompany, 'newcompany',$thirdpartyofproject); + $thirdpartyofproject=$projectstatic->getListContactId('thirdparty'); + $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id; + $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany',$thirdpartyofproject); print ''; - $contactofproject=$project->getListContactId('external'); + $contactofproject=$projectstatic->getListContactId('external'); $nbofcontacts=$form->select_contacts($selectedCompany,'','contactid',0,'',$contactofproject); if ($nbofcontacts == 0) print $langs->trans("NoContactDefined"); print ''; - $formcompany->selectTypeContact($task, '', 'type','external','rowid'); + $formcompany->selectTypeContact($object, '', 'type','external','rowid'); print ' 0 || ! empty($ref)) foreach(array('internal','external') as $source) { - $tab = $task->liste_contact(-1,$source); + $tab = $object->liste_contact(-1,$source); $num=count($tab); $i = 0; @@ -405,9 +418,9 @@ if ($id > 0 || ! empty($ref)) // Statut print ''; // Activation desativation du contact - if ($task->statut >= 0) print ''; + if ($object->statut >= 0) print ''; print $contactstatic->LibStatut($tab[$i]['status'],3); - if ($task->statut >= 0) print ''; + if ($object->statut >= 0) print ''; print '
'; - - // Ref - print ''; - - print ''; - - print ''; - print ''; - - // Visibility - print ''; - - // Statut - print ''; - - print '
'; - print $langs->trans("Ref"); - print ''; - // Define a complementary filter for search of next/prev ref. - if (! $user->rights->projet->all->lire) - { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,0); - $project->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; - } - print $form->showrefnav($project,'ref','',1,'ref','ref','',$param); - print '
'.$langs->trans("Label").''.$project->title.'
'.$langs->trans("Company").''; - if (! empty($project->societe->id)) print $project->societe->getNomUrl(1); - else print ' '; - print '
'.$langs->trans("Visibility").''; - if ($project->public) print $langs->trans('SharedProject'); - else print $langs->trans('PrivateProject'); - print '
'.$langs->trans("Status").''.$project->getLibStatut(4).'
'; - - dol_fiche_end(); - - print '
'; - } - - $head = task_prepare_head($task); - dol_fiche_head($head, 'task_document', $langs->trans("Task"), 0, 'projecttask'); - - $param=(GETPOST('withproject')?'&withproject=1':''); - $linkback=GETPOST('withproject')?''.$langs->trans("BackToList").'':''; - - // Files list constructor - $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); - $totalsize=0; - foreach($filearray as $key => $file) - { - $totalsize+=$file['size']; - } - - print ''; - - // Ref - print ''; - print ''; - - // Label - print ''; - - // Project - if (empty($withproject)) - { - print ''; - - // Third party - print ''; - } - - // Files infos - print ''; - print ''; - - print "
'; - print $langs->trans("Ref"); - print ''; - if (! GETPOST('withproject') || empty($project->id)) - { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1); - $task->next_prev_filter=" fk_projet in (".$projectsListId.")"; - } - else $task->next_prev_filter=" fk_projet = ".$project->id; - print $form->showrefnav($task,'id',$linkback,1,'rowid','ref','',$param); - print '
'.$langs->trans("Label").''.$task->label.'
'.$langs->trans("Project").''; - print $projectstatic->getNomUrl(1); - print '
'.$langs->trans("Company").''; - if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1); - else print ' '; - print '
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
\n"; - - dol_fiche_end(); - - print '
'; - - dol_htmloutput_mesg($mesg); - - - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/projet/tasks/document.php?id='.$task->id,'',0,0,$user->rights->projet->creer); - - - // List of document - $param='&id='.$task->id; - $formfile->list_of_documents($filearray,$task,'projet',$param,0,dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($task->ref).'/'); - } +if ($object->id > 0) +{ + if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); + + $userWrite = $projectstatic->restrictedProjectArea($user,'write'); + + if (! empty($withproject)) + { + // Tabs for project + $tab='tasks'; + $head=project_prepare_head($projectstatic); + dol_fiche_head($head, $tab, $langs->trans("Project"),0,($projectstatic->public?'projectpub':'project')); + + $param=($mode=='mine'?'&mode=mine':''); + + print ''; + + // Ref + print ''; + + print ''; + + print ''; + print ''; + + // Visibility + print ''; + + // Statut + print ''; + + print '
'; + print $langs->trans("Ref"); + print ''; + // Define a complementary filter for search of next/prev ref. + if (! $user->rights->projet->all->lire) + { + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0); + $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; + } + print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1'); + print '
'.$langs->trans("Label").''.$projectstatic->title.'
'.$langs->trans("Company").''; + if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); + else print ' '; + print '
'.$langs->trans("Visibility").''; + if ($projectstatic->public) print $langs->trans('SharedProject'); + else print $langs->trans('PrivateProject'); + print '
'.$langs->trans("Status").''.$projectstatic->getLibStatut(4).'
'; + + dol_fiche_end(); + + print '
'; + } + + $head = task_prepare_head($object); + dol_fiche_head($head, 'task_document', $langs->trans("Task"), 0, 'projecttask'); + + $param=(GETPOST('withproject')?'&withproject=1':''); + $linkback=GETPOST('withproject')?''.$langs->trans("BackToList").'':''; + + // Files list constructor + $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + + print ''; + + // Ref + print ''; + print ''; + + // Label + print ''; + + // Project + if (empty($withproject)) + { + print ''; + + // Third party + print ''; + } + + // Files infos + print ''; + print ''; + + print "
'; + print $langs->trans("Ref"); + print ''; + if (empty($withproject) || empty($projectstatic->id)) + { + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); + $object->next_prev_filter=" fk_projet in (".$projectsListId.")"; + } + else $object->next_prev_filter=" fk_projet = ".$projectstatic->id; + print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param); + print '
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("Project").''; + print $projectstatic->getNomUrl(1); + print '
'.$langs->trans("Company").''; + if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1); + else print ' '; + print '
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
\n"; + + dol_fiche_end(); + + print '
'; + + dol_htmloutput_mesg($mesg); + + + // Affiche formulaire upload + $formfile=new FormFile($db); + $formfile->form_attach_new_file(DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id,'',0,0,$user->rights->projet->creer); + + + // List of document + $param='&id='.$object->id; + $formfile->list_of_documents($filearray,$object,'projet',$param,0,dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref).'/'); } else { @@ -264,6 +280,5 @@ else llxFooter(); - $db->close(); ?> diff --git a/htdocs/projet/tasks/note.php b/htdocs/projet/tasks/note.php index 5946dd5d23c..11cf96ca9c7 100644 --- a/htdocs/projet/tasks/note.php +++ b/htdocs/projet/tasks/note.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,12 +28,14 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php"); $langs->load('projects'); -$action=GETPOST('action'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); $mine = $_REQUEST['mode']=='mine' ? 1 : 0; //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects $id = GETPOST('id','int'); $ref= GETPOST('ref', 'alpha'); -$withproject=GETPOST('withproject'); +$withproject=GETPOST('withproject','int'); +$project_ref = GETPOST('project_ref','alpha'); // Security check $socid=0; @@ -42,7 +44,39 @@ if (!$user->rights->projet->lire) accessforbidden(); //$result = restrictedArea($user, 'projet', $id, '', 'task'); // TODO ameliorer la verification $object = new Task($db); -$object->fetch($id, $ref); +$projectstatic = new Project($db); + +if ($id > 0 || ! empty($ref)) +{ + if ($object->fetch($id,$ref) > 0) + { + $projectstatic->fetch($object->fk_project); + if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); + } + else + { + dol_print_error($db); + } +} + + +// Retreive First Task ID of Project if withprojet is on to allow project prev next to work +if (! empty($project_ref) && ! empty($withproject)) +{ + if ($projectstatic->fetch(0,$project_ref) > 0) + { + $tasksarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0); + if (count($tasksarray) > 0) + { + $id=$tasksarray[0]->id; + $object->fetch($id); + } + else + { + Header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode)?'':'&mode='.$mode)); + } + } +} /* @@ -70,24 +104,20 @@ else if ($action == 'setnote_private' && $user->rights->ficheinter->creer) llxHeader(); $form = new Form($db); -$project = new Project($db); $userstatic = new User($db); $now=dol_now(); -if ($id > 0 || ! empty($ref)) +if ($object->id > 0) { - $result=$project->fetch($object->fk_project); - if (! empty($project->socid)) $project->societe->fetch($project->socid); + $userWrite = $projectstatic->restrictedProjectArea($user,'write'); - $userWrite = $project->restrictedProjectArea($user,'write'); - - if ($withproject) + if (! empty($withproject)) { // Tabs for project $tab='tasks'; - $head=project_prepare_head($project); - dol_fiche_head($head, $tab, $langs->trans("Project"),0,($project->public?'projectpub':'project')); + $head=project_prepare_head($projectstatic); + dol_fiche_head($head, $tab, $langs->trans("Project"),0,($projectstatic->public?'projectpub':'project')); $param=($mode=='mine'?'&mode=mine':''); @@ -100,30 +130,30 @@ if ($id > 0 || ! empty($ref)) // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,0); - $project->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0); + $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; } - print $form->showrefnav($project,'ref','',1,'ref','ref','',$param); + print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1'); print ''; // Project - print ''.$langs->trans("Label").''.$project->title.''; + print ''.$langs->trans("Label").''.$projectstatic->title.''; // Company print ''.$langs->trans("Company").''; - if (! empty($project->societe->id)) print $project->societe->getNomUrl(1); + if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); else print ' '; print ''; print ''; // Visibility print ''.$langs->trans("Visibility").''; - if ($project->public) print $langs->trans('SharedProject'); + if ($projectstatic->public) print $langs->trans('SharedProject'); else print $langs->trans('PrivateProject'); print ''; // Statut - print ''.$langs->trans("Status").''.$project->getLibStatut(4).''; + print ''.$langs->trans("Status").''.$projectstatic->getLibStatut(4).''; print ''; @@ -138,16 +168,16 @@ if ($id > 0 || ! empty($ref)) print ''; $param=(GETPOST('withproject')?'&withproject=1':''); - $linkback=GETPOST('withproject')?''.$langs->trans("BackToList").'':''; + $linkback=GETPOST('withproject')?''.$langs->trans("BackToList").'':''; // Ref print ''; @@ -158,12 +188,12 @@ if ($id > 0 || ! empty($ref)) if (empty($withproject)) { print ''; // Third party print ''; } @@ -180,7 +210,7 @@ if ($id > 0 || ! empty($ref)) dol_fiche_end(); } -llxFooter(); +llxFooter(); $db->close(); ?> diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 261dbd2d985..b31b2ccb328 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -1,7 +1,7 @@ - * Copyright (C) 2006-2011 Laurent Destailleur - * Copyright (C) 2010 Regis Houssin +/* Copyright (C) 2005 Rodolphe Quiedeville + * Copyright (C) 2006-2012 Laurent Destailleur + * Copyright (C) 2010-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ /** * \file htdocs/projet/tasks/task.php - * \ingroup projet + * \ingroup project * \brief Page of a project task */ @@ -29,17 +29,20 @@ require_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php"); -$taskid = GETPOST('id','int'); -$taskref = GETPOST("ref"); -$id = GETPOST('id','int'); -$ref= GETPOST('ref'); -$action=GETPOST('action'); -$withproject=GETPOST('withproject'); +$id=GETPOST('id','int'); +$ref=GETPOST('ref','alpha'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); +$withproject=GETPOST('withproject','int'); +$project_ref=GETPOST('project_ref','alpha'); // Security check $socid=0; if ($user->societe_id > 0) $socid = $user->societe_id; -if (!$user->rights->projet->lire) accessforbidden(); +if (! $user->rights->projet->lire) accessforbidden(); + +$object = new Task($db); +$projectstatic = new Project($db); /* @@ -57,44 +60,38 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer) } if (! $error) { - $task = new Task($db); - $task->fetch($id); + $object->fetch($id); $tmparray=explode('_',$_POST['task_parent']); $task_parent=$tmparray[1]; if (empty($task_parent)) $task_parent = 0; // If task_parent is '' - $task->label = $_POST["label"]; - $task->description = $_POST['description']; - $task->fk_task_parent = $task_parent; - $task->date_start = dol_mktime(12,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']); - $task->date_end = dol_mktime(12,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']); - $task->progress = $_POST['progress']; + $object->label = $_POST["label"]; + $object->description = $_POST['description']; + $object->fk_task_parent = $task_parent; + $object->date_start = dol_mktime(12,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']); + $object->date_end = dol_mktime(12,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']); + $object->progress = $_POST['progress']; - $result=$task->update($user); - - $taskid=$task->id; // On retourne sur la fiche tache + $result=$object->update($user); } else { - $taskid=$_POST["id"]; $action='edit'; } } -if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->projet->supprimer) +if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->projet->supprimer) { - $task = new Task($db); - if ($task->fetch($id) >= 0 ) + if ($object->fetch($id) >= 0 ) { - $projet = new Project($db); - $result=$projet->fetch($task->fk_projet); - if (! empty($projet->socid)) + $result=$projecstatict->fetch($object->fk_projet); + if (! empty($projecstatic->socid)) { - $projet->societe->fetch($projet->socid); + $projecstatic->societe->fetch($projecstatic->socid); } - if ($task->delete($user) > 0) + if ($object->delete($user) > 0) { Header("Location: index.php"); exit; @@ -102,12 +99,28 @@ if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights-> else { $langs->load("errors"); - $mesg='
'.$langs->trans($task->error).'
'; - $_POST["action"]=''; + $mesg='
'.$langs->trans($object->error).'
'; + $action=''; } } } +// Retreive First Task ID of Project if withprojet is on to allow project prev next to work +if (! empty($project_ref) && ! empty($withproject)) +{ + if ($projectstatic->fetch('',$project_ref) > 0) + { + $tasksarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0); + if (count($tasksarray) > 0) + { + $id=$tasksarray[0]->id; + } + else + { + Header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode)?'':'&mode='.$mode)); + } + } +} /* * View @@ -117,24 +130,22 @@ llxHeader("",$langs->trans("Task")); $form = new Form($db); $formother = new FormOther($db); -$project = new Project($db); -$task = new Task($db); -if ($taskid) +if ($id > 0 || ! empty($ref)) { - if ($task->fetch($taskid) > 0) + if ($object->fetch($id) > 0) { - $result=$project->fetch($task->fk_project); - if (! empty($project->socid)) $project->societe->fetch($project->socid); + $result=$projectstatic->fetch($object->fk_project); + if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); - $userWrite = $project->restrictedProjectArea($user,'write'); + $userWrite = $projectstatic->restrictedProjectArea($user,'write'); - if ($withproject) + if (! empty($withproject)) { // Tabs for project $tab='tasks'; - $head=project_prepare_head($project); - dol_fiche_head($head, $tab, $langs->trans("Project"),0,($project->public?'projectpub':'project')); + $head=project_prepare_head($projectstatic); + dol_fiche_head($head, $tab, $langs->trans("Project"),0,($projectstatic->public?'projectpub':'project')); $param=($mode=='mine'?'&mode=mine':''); @@ -147,28 +158,28 @@ if ($taskid) // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,0); - $project->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0); + $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; } - print $form->showrefnav($project,'ref','',1,'ref','ref','',$param); + print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1'); print ''; - print '
'; + print ''; print ''; print ''; // Visibility print ''; // Statut - print ''; + print ''; print '
'.$langs->trans("Ref").''; - if (! GETPOST('withproject') || empty($project->id)) + if (empty($withproject) || empty($projectstatic->id)) { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1); + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); $object->next_prev_filter=" fk_projet in (".$projectsListId.")"; } - else $object->next_prev_filter=" fk_projet = ".$project->id; + else $object->next_prev_filter=" fk_projet = ".$projectstatic->id; print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param); print '
'.$langs->trans("Project").''; - print $project->getNomUrl(1); + print $projectstatic->getNomUrl(1); print '
'.$langs->trans("Company").''; - if ($project->societe->id > 0) print $project->societe->getNomUrl(1); + if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1); else print' '; print '
'.$langs->trans("Label").''.$project->title.'
'.$langs->trans("Label").''.$projectstatic->title.'
'.$langs->trans("Company").''; - if (! empty($project->societe->id)) print $project->societe->getNomUrl(1); + if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); else print ' '; print '
'.$langs->trans("Visibility").''; - if ($project->public) print $langs->trans('SharedProject'); + if ($projectstatic->public) print $langs->trans('SharedProject'); else print $langs->trans('PrivateProject'); print '
'.$langs->trans("Status").''.$project->getLibStatut(4).'
'.$langs->trans("Status").''.$projectstatic->getLibStatut(4).'
'; @@ -184,7 +195,7 @@ if ($taskid) if ($user->rights->projet->all->creer || $user->rights->projet->creer) { - if ($project->public || $userWrite > 0) + if ($projectstatic->public || $userWrite > 0) { print ''.$langs->trans('AddTask').''; } @@ -202,12 +213,12 @@ if ($taskid) */ // To verify role of users - //$userAccess = $project->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project - //$arrayofuseridoftask=$task->getListContactId('internal'); + //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project + //$arrayofuseridoftask=$object->getListContactId('internal'); dol_htmloutput_mesg($mesg); - $head=task_prepare_head($task); + $head=task_prepare_head($object); dol_fiche_head($head, 'task_task', $langs->trans("Task"),0,'projecttask'); if ($action == 'edit' && $user->rights->projet->creer) @@ -216,56 +227,56 @@ if ($taskid) print ''; print ''; print ''; - print ''; + print ''; print ''; // Ref print ''; - print ''; + print ''; // Label print ''; - print ''; + print ''; // Project if (empty($withproject)) { print ''; // Third party print ''; } // Task parent print ''; // Date start print ''; // Date end print ''; // Progress print ''; // Description print ''; print ''; print '
'.$langs->trans("Ref").''.$task->ref.'
'.$object->ref.'
'.$langs->trans("Label").'
'.$langs->trans("Project").''; - print $project->getNomUrl(1); + print $projectstatic->getNomUrl(1); print '
'.$langs->trans("Company").''; - if ($project->societe->id) print $project->societe->getNomUrl(1); + if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1); else print ' '; print '
'.$langs->trans("ChildOfTask").''; - print $formother->selectProjectTasks($task->fk_task_parent,$project->id, 'task_parent', $user->admin?0:1, 0); + print $formother->selectProjectTasks($object->fk_task_parent,$projectstatic->id, 'task_parent', $user->admin?0:1, 0); print '
'.$langs->trans("DateStart").''; - print $form->select_date($task->date_start,'dateo'); + print $form->select_date($object->date_start,'dateo'); print '
'.$langs->trans("DateEnd").''; - print $form->select_date($task->date_end?$task->date_end:-1,'datee'); + print $form->select_date($object->date_end?$object->date_end:-1,'datee'); print '
'.$langs->trans("Progress").''; - print $formother->select_percent($task->progress,'progress'); + print $formother->select_percent($object->progress,'progress'); print '
'.$langs->trans("Description").''; - print ''; + print ''; print '
'; @@ -283,7 +294,7 @@ if ($taskid) * Fiche tache en mode visu */ $param=($withproject?'&withproject=1':''); - $linkback=$withproject?''.$langs->trans("BackToList").'':''; + $linkback=$withproject?''.$langs->trans("BackToList").'':''; if ($action == 'delete') { @@ -297,51 +308,51 @@ if ($taskid) print ''; print $langs->trans("Ref"); print ''; - if (! GETPOST('withproject') || empty($project->id)) + if (! GETPOST('withproject') || empty($projectstatic->id)) { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1); - $task->next_prev_filter=" fk_projet in (".$projectsListId.")"; + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); + $object->next_prev_filter=" fk_projet in (".$projectsListId.")"; } - else $task->next_prev_filter=" fk_projet = ".$project->id; - print $form->showrefnav($task,'id',$linkback,1,'rowid','ref','',$param); + else $object->next_prev_filter=" fk_projet = ".$projectstatic->id; + print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param); print ''; print ''; // Label - print ''.$langs->trans("Label").''.$task->label.''; + print ''.$langs->trans("Label").''.$object->label.''; // Project if (empty($withproject)) { print ''.$langs->trans("Project").''; - print $project->getNomUrl(1); + print $projectstatic->getNomUrl(1); print ''; // Third party print ''.$langs->trans("Company").''; - if ($project->societe->id) print $project->societe->getNomUrl(1); + if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1); else print ' '; print ''; } // Date start print ''.$langs->trans("DateStart").''; - print dol_print_date($task->date_start,'day'); + print dol_print_date($object->date_start,'day'); print ''; // Date end print ''.$langs->trans("DateEnd").''; - print dol_print_date($task->date_end,'day'); + print dol_print_date($object->date_end,'day'); print ''; // Progress print ''.$langs->trans("Progress").''; - print $task->progress.' %'; + print $object->progress.' %'; print ''; // Description print ''.$langs->trans("Description").''; - print nl2br($task->description); + print nl2br($object->description); print ''; print ''; @@ -361,7 +372,7 @@ if ($taskid) // Modify if ($user->rights->projet->creer) { - print ''.$langs->trans('Modify').''; + print ''.$langs->trans('Modify').''; } else { @@ -369,9 +380,9 @@ if ($taskid) } // Delete - if ($user->rights->projet->supprimer && ! $task->hasChildren()) + if ($user->rights->projet->supprimer && ! $object->hasChildren()) { - print ''.$langs->trans('Delete').''; + print ''.$langs->trans('Delete').''; } else { @@ -385,6 +396,5 @@ if ($taskid) llxFooter(); - $db->close(); ?> diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 8f93368d6e4..d6d592d21f8 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -1,8 +1,8 @@ - * Copyright (C) 2006-2012 Laurent Destailleur - * Copyright (C) 2010 Regis Houssin - * Copyright (C) 2011 Juanjo Menent +/* Copyright (C) 2005 Rodolphe Quiedeville + * Copyright (C) 2006-2012 Laurent Destailleur + * Copyright (C) 2010-2012 Regis Houssin + * Copyright (C) 2011 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,7 @@ /** * \file htdocs/projet/tasks/time.php - * \ingroup projet + * \ingroup project * \brief Page to add new time spent on a task */ @@ -32,17 +32,21 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); $langs->load('projects'); -$taskid = isset($_GET["id"])?$_GET["id"]:''; -$id = GETPOST('id','int'); -$ref= GETPOST('ref'); -$action=GETPOST('action'); -$withproject=GETPOST('withproject'); +$id=GETPOST('id','int'); +$ref=GETPOST('ref','alpha'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); +$withproject=GETPOST('withproject','int'); +$project_ref=GETPOST('project_ref','alpha'); // Security check $socid=0; if ($user->societe_id > 0) $socid = $user->societe_id; if (!$user->rights->projet->lire) accessforbidden(); +$object = new Task($db); +$projectstatic = new Project($db); + /* * Actions @@ -64,28 +68,27 @@ if ($action == 'addtimespent' && $user->rights->projet->creer) if (! $error) { - $task = new Task($db); - $task->fetch($_POST["id"]); + $object->fetch($id); - $task->timespent_note = $_POST["timespent_note"]; - $task->timespent_duration = $_POST["timespent_durationhour"]*60*60; // We store duration in seconds - $task->timespent_duration+= $_POST["timespent_durationmin"]*60; // We store duration in seconds - $task->timespent_date = dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]); - $task->timespent_fk_user = $_POST["userid"]; + $object->timespent_note = $_POST["timespent_note"]; + $object->timespent_duration = $_POST["timespent_durationhour"]*60*60; // We store duration in seconds + $object->timespent_duration+= $_POST["timespent_durationmin"]*60; // We store duration in seconds + $object->timespent_date = dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]); + $object->timespent_fk_user = $_POST["userid"]; - $result=$task->addTimeSpent($user); + $result=$object->addTimeSpent($user); if ($result >= 0) { } else { - $mesg='
'.$langs->trans($task->error).'
'; + $mesg='
'.$langs->trans($object->error).'
'; } } else { - $_POST["action"]=''; + $action=''; } } @@ -101,44 +104,59 @@ if ($action == 'updateline' && ! $_POST["cancel"] && $user->rights->projet->cree if (! $error) { - $task = new Task($db); - $task->fetch($_POST["id"]); + $object->fetch($id); - $task->timespent_id = $_POST["lineid"]; - $task->timespent_note = $_POST["timespent_note_line"]; - $task->timespent_old_duration = $_POST["old_duration"]; - $task->timespent_duration = $_POST["new_durationhour"]*60*60; // We store duration in seconds - $task->timespent_duration+= $_POST["new_durationmin"]*60; // We store duration in seconds - $task->timespent_date = dol_mktime(12,0,0,$_POST["timelinemonth"],$_POST["timelineday"],$_POST["timelineyear"]); - $task->timespent_fk_user = $_POST["userid_line"]; + $object->timespent_id = $_POST["lineid"]; + $object->timespent_note = $_POST["timespent_note_line"]; + $object->timespent_old_duration = $_POST["old_duration"]; + $object->timespent_duration = $_POST["new_durationhour"]*60*60; // We store duration in seconds + $object->timespent_duration+= $_POST["new_durationmin"]*60; // We store duration in seconds + $object->timespent_date = dol_mktime(12,0,0,$_POST["timelinemonth"],$_POST["timelineday"],$_POST["timelineyear"]); + $object->timespent_fk_user = $_POST["userid_line"]; - $result=$task->updateTimeSpent($user); + $result=$object->updateTimeSpent($user); if ($result >= 0) { } else { - $mesg='
'.$langs->trans($task->error).'
'; + $mesg='
'.$langs->trans($object->error).'
'; } } else { - $_POST["action"]=''; + $action=''; } } -if ($action == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->rights->projet->creer) +if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->projet->creer) { - $task = new Task($db); - $task->fetchTimeSpent($_GET['lineid']); - $result = $task->delTimeSpent($user); + $object->fetchTimeSpent($_GET['lineid']); + $result = $object->delTimeSpent($user); if (!$result) { $langs->load("errors"); - $mesg='
'.$langs->trans($task->error).'
'; - $_POST["action"]=''; + $mesg='
'.$langs->trans($object->error).'
'; + $action=''; + } +} + +// Retreive First Task ID of Project if withprojet is on to allow project prev next to work +if (! empty($project_ref) && ! empty($withproject)) +{ + if ($projectstatic->fetch(0,$project_ref) > 0) + { + $tasksarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0); + if (count($tasksarray) > 0) + { + $id=$tasksarray[0]->id; + } + else + { + Header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode)?'':'&mode='.$mode)); + } } } @@ -147,10 +165,6 @@ if ($action == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->right * View */ -$form = new Form($db); -$project = new Project($db); -$task = new Task($db); - llxHeader("",$langs->trans("Task")); $form = new Form($db); @@ -160,19 +174,19 @@ if ($id > 0 || ! empty($ref)) /* * Fiche projet en mode visu */ - if ($task->fetch($id,$ref) >= 0) + if ($object->fetch($id) >= 0) { - $result=$project->fetch($task->fk_project); - if (! empty($project->socid)) $project->societe->fetch($project->socid); + $result=$projectstatic->fetch($object->fk_project); + if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); - $userWrite = $project->restrictedProjectArea($user,'write'); + $userWrite = $projectstatic->restrictedProjectArea($user,'write'); if ($withproject) { // Tabs for project $tab='tasks'; - $head=project_prepare_head($project); - dol_fiche_head($head, $tab, $langs->trans("Project"),0,($project->public?'projectpub':'project')); + $head=project_prepare_head($projectstatic); + dol_fiche_head($head, $tab, $langs->trans("Project"),0,($projectstatic->public?'projectpub':'project')); $param=($mode=='mine'?'&mode=mine':''); @@ -185,28 +199,28 @@ if ($id > 0 || ! empty($ref)) // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,0); - $project->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0); + $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; } - print $form->showrefnav($project,'ref','',1,'ref','ref','',$param); + print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1'); print ''; - print ''.$langs->trans("Label").''.$project->title.''; + print ''.$langs->trans("Label").''.$projectstatic->title.''; print ''.$langs->trans("Company").''; - if (! empty($project->societe->id)) print $project->societe->getNomUrl(1); + if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1); else print ' '; print ''; print ''; // Visibility print ''.$langs->trans("Visibility").''; - if ($project->public) print $langs->trans('SharedProject'); + if ($projectstatic->public) print $langs->trans('SharedProject'); else print $langs->trans('PrivateProject'); print ''; // Statut - print ''.$langs->trans("Status").''.$project->getLibStatut(4).''; + print ''.$langs->trans("Status").''.$projectstatic->getLibStatut(4).''; print ''; @@ -215,48 +229,48 @@ if ($id > 0 || ! empty($ref)) print '
'; } - $head=task_prepare_head($task); + $head=task_prepare_head($object); dol_fiche_head($head, 'task_time', $langs->trans("Task"),0,'projecttask'); dol_htmloutput_mesg($mesg); if ($action == 'deleteline') { - $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"].'&lineid='.$_GET["lineid"],$langs->trans("DeleteATimeSpent"),$langs->trans("ConfirmDeleteATimeSpent"),"confirm_delete",'','',1); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id.'&lineid='.$_GET["lineid"],$langs->trans("DeleteATimeSpent"),$langs->trans("ConfirmDeleteATimeSpent"),"confirm_delete",'','',1); if ($ret == 'html') print '
'; } print ''; $param=($withproject?'&withproject=1':''); - $linkback=$withproject?''.$langs->trans("BackToList").'':''; + $linkback=$withproject?''.$langs->trans("BackToList").'':''; // Ref print ''; // Label - print ''; + print ''; // Project if (empty($withproject)) { print ''; // Third party print ''; } @@ -273,10 +287,10 @@ if ($id > 0 || ! empty($ref)) { print '
'; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print '
'; print $langs->trans("Ref"); print ''; - if (! GETPOST('withproject') || empty($project->id)) + if (! GETPOST('withproject') || empty($projectstatic->id)) { - $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1); - $task->next_prev_filter=" fk_projet in (".$projectsListId.")"; + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1); + $object->next_prev_filter=" fk_projet in (".$projectsListId.")"; } - else $task->next_prev_filter=" fk_projet = ".$project->id; - print $form->showrefnav($task,'id',$linkback,1,'rowid','ref','',$param); + else $object->next_prev_filter=" fk_projet = ".$projectstatic->id; + print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param); print '
'.$langs->trans("Label").''.$task->label.'
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("Project").''; - print $project->getNomUrl(1); + print $projectstatic->getNomUrl(1); print '
'.$langs->trans("Company").''; - if ($project->societe->id) print $project->societe->getNomUrl(1); + if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1); else print ' '; print '
'; @@ -298,7 +312,7 @@ if ($id > 0 || ! empty($ref)) // Contributor print ''; @@ -329,7 +343,7 @@ if ($id > 0 || ! empty($ref)) $sql.= ", u.name, u.firstname"; $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; $sql .= " , ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE t.fk_task =".$task->id; + $sql .= " WHERE t.fk_task =".$object->id; $sql .= " AND t.fk_user = u.rowid"; $sql .= " ORDER BY t.task_date DESC"; @@ -353,10 +367,10 @@ if ($id > 0 || ! empty($ref)) dol_print_error($db); } - print ''; + print ''; print ''; print ''; - print ''; + print ''; print '
'; - $contactoftask=$task->getListContactId('internal'); + $contactoftask=$object->getListContactId('internal'); print img_object('','user'); print $form->select_users($_POST["userid"]?$_POST["userid"]:$user->id,'userid',0,'',0,'',$contactoftask); print '
'; print ''; @@ -427,7 +441,7 @@ if ($id > 0 || ! empty($ref)) // Edit and delete icon print '
'; - if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) + if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) { print ''; print ''; @@ -437,12 +451,12 @@ if ($id > 0 || ! empty($ref)) else if ($user->rights->projet->creer) { print ' '; - print 'rowid.'">'; + print 'rowid.'">'; print img_edit(); print ''; print ' '; - print 'rowid.'">'; + print 'rowid.'">'; print img_delete(); print ''; } @@ -460,7 +474,7 @@ if ($id > 0 || ! empty($ref)) } } -$db->close(); llxFooter(); +$db->close(); ?>