From 4345d2563b32c8aa59d277286218d1c2c5a46145 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 26 Jan 2010 13:28:25 +0000 Subject: [PATCH] Works on enhancement of project tasks Fix: data migration of llx_projet_task_actors in llx_element_contact --- htdocs/commonobject.class.php | 16 +++--- htdocs/install/upgrade2.php | 91 ++++++++++++++++++++++++++++++++- htdocs/langs/en_US/install.lang | 5 +- htdocs/langs/fr_FR/install.lang | 3 ++ htdocs/projet/element.php | 71 +++++++++++++++---------- htdocs/projet/fiche.php | 26 ++++++++-- htdocs/projet/tasks/fiche.php | 26 ++++++++-- 7 files changed, 195 insertions(+), 43 deletions(-) diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index 5d89ae47c31..16023eae844 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -173,13 +173,13 @@ class CommonObject $tab=array(); - $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,"; - if ($source == 'internal') $sql.=" '-1' as socid,"; - if ($source == 'external') $sql.=" t.fk_soc as socid,"; - $sql.=" t.name as nom,"; - $sql.= "tc.source, tc.element, tc.code, tc.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc,"; - $sql.= " ".MAIN_DB_PREFIX."element_contact ec"; + $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id"; + if ($source == 'internal') $sql.=", '-1' as socid"; + if ($source == 'external') $sql.=", t.fk_soc as socid"; + $sql.= ", t.name as nom, t.firstname"; + $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; + $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; if ($source == 'external') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; $sql.= " WHERE ec.element_id =".$this->id; @@ -203,7 +203,7 @@ class CommonObject $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom, + $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom, 'firstname'=>$obj->firstname, 'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut); $i++; } diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 98ed86c0845..5d1ea45fa13 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -1,7 +1,7 @@ * Copyright (C) 2005-2009 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2010 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 @@ -256,6 +256,8 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"])) migrate_relationship_tables($db,$langs,$conf,'fa_pr','fk_propal','propal','fk_facture','facture'); migrate_relationship_tables($db,$langs,$conf,'co_fa','fk_commande','commande','fk_facture','facture'); + + migrate_project_task_actors($db,$langs,$conf); } // On commit dans tous les cas. @@ -2456,6 +2458,93 @@ function migrate_restore_missing_links($db,$langs,$conf) print ''; } +/* + * Migration de la table llx_projet_task_actors vers llx_element_contact + */ +function migrate_project_task_actors($db,$langs,$conf) +{ + dolibarr_install_syslog("upgrade2::migrate_project_task_actors"); + + print ''; + + print '
'; + print ''.$langs->trans('MigrationProjectTaskActors')."
\n"; + + if ($db->DDLInfoTable(MAIN_DB_PREFIX."projet_task_actors")) + { + $error = 0; + + $db->begin(); + + $sql = "SELECT fk_projet_task, fk_user FROM ".MAIN_DB_PREFIX."projet_task_actors"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact ("; + $sql2.= "datecreate"; + $sql2.= ", statut"; + $sql2.= ", element_id"; + $sql2.= ", fk_c_type_contact"; + $sql2.= ", fk_socpeople"; + $sql2.= ") VALUES ("; + $sql2.= $db->idate(dol_now()); + $sql2.= ", '4'"; + $sql2.= ", ".$obj->fk_projet_task; + $sql2.= ", '180'"; + $sql2.= ", ".$obj->fk_user; + $sql2.= ")"; + + $resql2=$db->query($sql2); + + if (!$resql2) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } + + if ($error == 0) + { + $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."projet_task_actors"; + if ($db->query($sqlDrop)) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + print ''; +} + /* * Migration des tables de relation */ diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 950c616020b..9efbca2c3b1 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -206,4 +206,7 @@ MigrationStockDetail=Update stock value of products MigrationMenusDetail=Update dynamic menus tables # Migration delivery address -MigrationDeliveryAddress=Update delivery address in shipments \ No newline at end of file +MigrationDeliveryAddress=Update delivery address in shipments + +# Migration project task actors +MigrationProjectTaskActors=Data migration for llx_projet_task_actors table \ No newline at end of file diff --git a/htdocs/langs/fr_FR/install.lang b/htdocs/langs/fr_FR/install.lang index 5cfb4afb79e..18a9e502f30 100644 --- a/htdocs/langs/fr_FR/install.lang +++ b/htdocs/langs/fr_FR/install.lang @@ -209,3 +209,6 @@ MigrationMenusDetail=Mise a jour table des menus dynamiques # Migration delivery address MigrationDeliveryAddress=Mise a jour des adresses de livraison dans les bons d'expedition + +# Migration project task actors +MigrationProjectTaskActors=Migration de la table llx_projet_task_actors diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index aae0eb5e4fb..f171077d6f3 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2009 Laurent Destailleur - * Copyright (C) 2005-2008 Regis Houssin + * Copyright (C) 2005-2010 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 @@ -44,15 +44,15 @@ if ($conf->commande->enabled) $langs->load("orders"); if ($conf->propal->enabled) $langs->load("propal"); // Security check -$projetid=''; +$projectid=''; $ref=''; -if (isset($_GET["id"])) { $projetid=$_GET["id"]; } +if (isset($_GET["id"])) { $projectid=$_GET["id"]; } if (isset($_GET["ref"])) { $ref=$_GET["ref"]; } -if ($projetid == '' && $ref == '') accessforbidden(); +if ($projectid == '' && $ref == '') accessforbidden(); // Security check if ($user->societe_id) $socid=$user->societe_id; -$result = restrictedArea($user, 'projet', $projetid); +$result = restrictedArea($user, 'projet', $projectid); /* @@ -63,39 +63,56 @@ llxHeader("",$langs->trans("Referers"),"EN:Module_Projects|FR:Module_Projets|ES: $form = new Form($db); -$projet = new Project($db); -$projet->fetch($_GET["id"],$_GET["ref"]); -$projet->societe->fetch($projet->societe->id); -if ($projet->user_resp_id > 0) -{ - $result=$projet->fetch_user($projet->user_resp_id); -} +$userstatic=new User($db); -$head=project_prepare_head($projet); +$project = new Project($db); +$project->fetch($_GET["id"],$_GET["ref"]); +$project->societe->fetch($project->societe->id); + +$head=project_prepare_head($project); dol_fiche_head($head, 'element', $langs->trans("Project"),0,'project'); print ''; print ''; -print ''; +print ''; print ''; // Project leader print ''; // Statut -print ''; +print ''; print '
'.$langs->trans("Ref").''; -print $form->showrefnav($projet,'ref','',1,'ref','ref'); +print $form->showrefnav($project,'ref','',1,'ref','ref'); print '
'.$langs->trans("Label").''.$projet->title.'
'.$langs->trans("Label").''.$project->title.'
'.$langs->trans("Company").''; -if (! empty($projet->societe->id)) print $projet->societe->getNomUrl(1); +if (! empty($project->societe->id)) print $project->societe->getNomUrl(1); else print ' '; print '
'.$langs->trans("OfficerProject").''; -if ($projet->user->id) print $projet->user->getNomUrl(1); -else print $langs->trans('SharedProject'); +$contact = $project->liste_contact(4,'internal'); +$num=sizeof($contact); +if ($num) +{ + $i = 0; + while ($i < $num) + { + if ($contact[$i]['code'] == 'PROJECTLEADER') + { + $userstatic->id = $contact[$i]['id']; + $userstatic->fetch(); + print $userstatic->getNomUrl(1); + print '
'; + } + $i++; + } +} +else +{ + print $langs->trans('SharedProject'); +} print '
'.$langs->trans("Status").''.$projet->getLibStatut(4).'
'.$langs->trans("Status").''.$project->getLibStatut(4).'
'; @@ -160,7 +177,7 @@ foreach ($listofreferent as $key => $value) if (empty($value['disableamount'])) print ''.$langs->trans("Amount").''; print ''.$langs->trans("Status").''; print ''; - $elementarray = $projet->get_element_list($key); + $elementarray = $project->get_element_list($key); if (sizeof($elementarray)>0 && is_array($elementarray)) { $var=true; @@ -208,30 +225,30 @@ foreach ($listofreferent as $key => $value) */ print '
'; - if ($projet->societe->prospect || $projet->societe->client) + if ($project->societe->prospect || $project->societe->client) { if ($key == 'propal' && $conf->propal->enabled && $user->rights->propale->creer) { - print ''.$langs->trans("AddProp").''; + print ''.$langs->trans("AddProp").''; } if ($key == 'order' && $conf->commande->enabled && $user->rights->commande->creer) { - print ''.$langs->trans("AddCustomerOrder").''; + print ''.$langs->trans("AddCustomerOrder").''; } if ($key == 'invoice' && $conf->facture->enabled && $user->rights->facture->creer) { - print ''.$langs->trans("AddCustomerInvoice").''; + print ''.$langs->trans("AddCustomerInvoice").''; } } - if ($projet->societe->fournisseur) + if ($project->societe->fournisseur) { if ($key == 'order_supplier' && $conf->fournisseur->enabled && $user->rights->fournisseur->commande->creer) { - print ''.$langs->trans("AddSupplierInvoice").''; + print ''.$langs->trans("AddSupplierInvoice").''; } if ($key == 'invoice_supplier' && $conf->fournisseur->enabled && $user->rights->fournisseur->facture->creer) { - print ''.$langs->trans("AddSupplierOrder").''; + print ''.$langs->trans("AddSupplierOrder").''; } } print '
'; diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index c7d7ac361e3..6a8188b0b63 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -309,7 +309,6 @@ else $project->fetch($projectid,$projectref); if ($project->societe->id > 0) $result=$project->societe->fetch($project->societe->id); - if ($project->user_resp_id > 0) $result=$project->fetch_user($project->user_resp_id); $head=project_prepare_head($project); dol_fiche_head($head, 'project', $langs->trans("Project"),0,'project'); @@ -386,6 +385,8 @@ else } else { + $userstatic=new User($db); + print ''; // Ref @@ -404,8 +405,27 @@ else // Project leader print ''; // Statut diff --git a/htdocs/projet/tasks/fiche.php b/htdocs/projet/tasks/fiche.php index 0cb95a15806..fb6c948d436 100644 --- a/htdocs/projet/tasks/fiche.php +++ b/htdocs/projet/tasks/fiche.php @@ -146,7 +146,6 @@ if ($id > 0 || ! empty($ref)) $project = new Project($db); $project->fetch($_REQUEST["id"],$_GET["ref"]); if ($project->societe->id > 0) $result=$project->societe->fetch($project->societe->id); - if ($project->user_resp_id > 0) $result=$project->fetch_user($project->user_resp_id); } if ($_GET["action"] == 'create' && $user->rights->projet->creer) @@ -212,6 +211,8 @@ else * Fiche projet en mode visu * */ + $userstatic=new User($db); + $tab='tasks'; if ($_REQUEST["mode"]=='mine') $tab='mytasks'; @@ -242,8 +243,27 @@ else // Project leader print ''; // Statut
'.$langs->trans("OfficerProject").''; - if ($project->user->id) print $project->user->getNomUrl(1); - else print $langs->trans('SharedProject'); + $contact = $project->liste_contact(4,'internal'); + $num=sizeof($contact); + if ($num) + { + $i = 0; + while ($i < $num) + { + if ($contact[$i]['code'] == 'PROJECTLEADER') + { + $userstatic->id = $contact[$i]['id']; + $userstatic->fetch(); + print $userstatic->getNomUrl(1); + print '
'; + } + $i++; + } + } + else + { + print $langs->trans('SharedProject'); + } print '
'.$langs->trans("OfficerProject").''; - if ($project->user->id) print $project->user->getNomUrl(1); - else print $langs->trans('SharedProject'); + $contact = $project->liste_contact(4,'internal'); + $num=sizeof($contact); + if ($num) + { + $i = 0; + while ($i < $num) + { + if ($contact[$i]['code'] == 'PROJECTLEADER') + { + $userstatic->id = $contact[$i]['id']; + $userstatic->fetch(); + print $userstatic->getNomUrl(1); + print '
'; + } + $i++; + } + } + else + { + print $langs->trans('SharedProject'); + } print '