diff --git a/htdocs/core/tpl/contacts.tpl.php b/htdocs/core/tpl/contacts.tpl.php
index dc97d84e9b6..33b98d56f48 100644
--- a/htdocs/core/tpl/contacts.tpl.php
+++ b/htdocs/core/tpl/contacts.tpl.php
@@ -14,6 +14,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
+ *
+ * This template needs:
+ * $object
*/
if (! class_exists('Contact')) {
@@ -30,6 +33,7 @@ if ($module == 'propal') { $permission=$user->rights->propale->creer; }
elseif ($module == 'fichinter') { $permission=$user->rights->ficheinter->creer; }
elseif ($module == 'invoice_supplier') { $permission=$user->rights->fournisseur->facture->creer; }
elseif ($module == 'order_supplier') { $permission=$user->rights->fournisseur->commande->creer; }
+elseif ($module == 'project') { $permission=$user->rights->projet->creer; }
elseif (! isset($permission)) { $permission=$user->rights->$module->creer; } // If already defined by caller page
$formcompany= new FormCompany($db);
diff --git a/htdocs/projet/contact.php b/htdocs/projet/contact.php
index 2f253112cdf..0674bcaf24b 100644
--- a/htdocs/projet/contact.php
+++ b/htdocs/projet/contact.php
@@ -31,17 +31,20 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
$langs->load("projects");
$langs->load("companies");
-$id = GETPOST('id','int');
-$ref= GETPOST('ref','alpha');
+$id = GETPOST('id','int');
+$ref = GETPOST('ref','alpha');
+$lineid = GETPOST('lineid','int');
+$socid = GETPOST('socid','int');
+$action = GETPOST('action','alpha');
-$mine = $_REQUEST['mode']=='mine' ? 1 : 0;
+$mine = GETPOST('mode')=='mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
-$project = new Project($db);
+$object = new Project($db);
if ($ref)
{
- $project->fetch(0,$ref);
- $id=$project->id;
+ $object->fetch(0,$ref);
+ $id=$object->id;
}
// Security check
@@ -55,41 +58,42 @@ $result = restrictedArea($user, 'projet', $id);
*/
// Add new contact
-if ($_POST["action"] == 'addcontact' && $user->rights->projet->creer)
+if ($action == 'addcontact' && $user->rights->projet->creer)
{
$result = 0;
- $result = $project->fetch($id);
+ $result = $object->fetch($id);
if ($result > 0 && $id > 0)
{
- $result = $project->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
+ $contactid = (GETPOST('userid') ? GETPOST('userid','int') : GETPOST('contactid','int'));
+ $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
}
if ($result >= 0)
{
- header("Location: contact.php?id=".$project->id);
+ header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
else
{
- if ($project->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
+ if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$langs->load("errors");
$mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
';
}
else
{
- $mesg = ''.$project->error.'
';
+ $mesg = ''.$object->error.'
';
}
}
}
// bascule du statut d'un contact
-if ($_GET["action"] == 'swapstatut' && $user->rights->projet->creer)
+if ($action == 'swapstatut' && $user->rights->projet->creer)
{
- if ($project->fetch($id))
+ if ($object->fetch($id))
{
- $result=$project->swapContactStatus(GETPOST('ligne'));
+ $result=$object->swapContactStatus(GETPOST('ligne'));
}
else
{
@@ -98,14 +102,14 @@ if ($_GET["action"] == 'swapstatut' && $user->rights->projet->creer)
}
// Efface un contact
-if ($_GET["action"] == 'deleteline' && $user->rights->projet->creer)
+if (($action == 'deleteline' || $action == 'deletecontact') && $user->rights->projet->creer)
{
- $project->fetch($id);
- $result = $project->delete_contact($_GET["lineid"]);
+ $object->fetch($id);
+ $result = $object->delete_contact($_GET["lineid"]);
if ($result >= 0)
{
- header("Location: contact.php?id=".$project->id);
+ header("Location: contact.php?id=".$object->id);
exit;
}
else
@@ -137,18 +141,18 @@ dol_htmloutput_mesg($mesg);
if ($id > 0 || ! empty($ref))
{
- if ( $project->fetch($id,$ref) > 0)
+ if ( $object->fetch($id,$ref) > 0)
{
- if ($project->societe->id > 0) $result=$project->societe->fetch($project->societe->id);
+ if ($object->societe->id > 0) $result=$object->societe->fetch($object->societe->id);
// To verify role of users
- //$userAccess = $project->restrictedProjectArea($user,'read');
- $userWrite = $project->restrictedProjectArea($user,'write');
- //$userDelete = $project->restrictedProjectArea($user,'delete');
+ //$userAccess = $object->restrictedProjectArea($user,'read');
+ $userWrite = $object->restrictedProjectArea($user,'write');
+ //$userDelete = $object->restrictedProjectArea($user,'delete');
//print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
- $head = project_prepare_head($project);
- dol_fiche_head($head, 'contact', $langs->trans("Project"), 0, ($project->public?'projectpub':'project'));
+ $head = project_prepare_head($object);
+ dol_fiche_head($head, 'contact', $langs->trans("Project"), 0, ($object->public?'projectpub':'project'));
/*
@@ -163,231 +167,42 @@ 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').")";
+ $objectsListId = $object->getProjectsAuthorizedForUser($user,$mine,0);
+ $object->next_prev_filter=" rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")";
}
- print $form->showrefnav($project, 'ref', $linkback, 1, 'ref', 'ref', '');
+ print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
print '';
// Label
- print '| '.$langs->trans("Label").' | '.$project->title.' |
';
+ print '| '.$langs->trans("Label").' | '.$object->title.' |
';
// Customer
print "| ".$langs->trans("Company")." | ";
print '';
- if ($project->societe->id > 0) print $project->societe->getNomUrl(1);
+ if ($object->societe->id > 0) print $object->societe->getNomUrl(1);
else print ' ';
print ' |
';
// Visibility
print '| '.$langs->trans("Visibility").' | ';
- if ($project->public) print $langs->trans('SharedProject');
+ if ($object->public) print $langs->trans('SharedProject');
else print $langs->trans('PrivateProject');
print ' |
';
// Statut
- print '| '.$langs->trans("Status").' | '.$project->getLibStatut(4).' |
';
+ print '| '.$langs->trans("Status").' | '.$object->getLibStatut(4).' |
';
print "";
print '';
- /*
- * Lignes de contacts
- */
- print '
';
-
- /*
- * Ajouter une ligne de contact
- * Non affiche en mode modification de ligne
- */
- if ($_GET["action"] != 'editline')
+ // Contacts lines (modules that overwrite templates must declare this into descriptor)
+ $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
+ foreach($dirtpls as $reldir)
{
- print '';
- print '| '.$langs->trans("Source").' | ';
- print ''.$langs->trans("Company").' | ';
- print ''.$langs->trans("Contacts").' | ';
- print ''.$langs->trans("ContactType").' | ';
- print ' | ';
- print "
\n";
-
- $var = false;
-
- print '';
-
- // Line to add external contact. Only if project is linked to a third party.
- //if ($project->societe->id)
- //{
- print '";
- //}
-
- print '| |
';
- }
-
- // Liste des contacts lies
- print '';
- print '| '.$langs->trans("Source").' | ';
- print ''.$langs->trans("Company").' | ';
- print ''.$langs->trans("Contacts").' | ';
- print ''.$langs->trans("ContactType").' | ';
- print ''.$langs->trans("Status").' | ';
- print ' | ';
- print "
\n";
-
- $companystatic = new Societe($db);
- $var = true;
-
- foreach(array('internal','external') as $source)
- {
- $tab = $project->liste_contact(-1,$source);
- $num=count($tab);
-
- $i = 0;
- while ($i < $num)
- {
- $var = !$var;
-
- print '';
-
- // Source
- print '| ';
- if ($tab[$i]['source']=='internal') print $langs->trans("User");
- if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
- print ' | ';
-
- // Societe
- print '';
- if ($tab[$i]['socid'] > 0)
- {
- $companystatic->fetch($tab[$i]['socid']);
- print $companystatic->getNomUrl(1);
- }
- if ($tab[$i]['socid'] < 0)
- {
- print $conf->global->MAIN_INFO_SOCIETE_NOM;
- }
- if (! $tab[$i]['socid'])
- {
- print ' ';
- }
- print ' | ';
-
- // Contact
- print '';
- if ($tab[$i]['source']=='internal')
- {
- $userstatic->id=$tab[$i]['id'];
- $userstatic->lastname=$tab[$i]['nom'];
- $userstatic->firstname=$tab[$i]['firstname'];
- print $userstatic->getNomUrl(1);
- }
- if ($tab[$i]['source']=='external')
- {
- $contactstatic->id=$tab[$i]['id'];
- $contactstatic->lastname=$tab[$i]['nom'];
- $contactstatic->firstname=$tab[$i]['firstname'];
- print $contactstatic->getNomUrl(1);
- }
- print ' | ';
-
- // Type de contact
- print ''.$tab[$i]['libelle'].' | ';
-
- // Statut
- print '';
- // Activation desativation du contact
- if ($project->statut >= 0 && $userWrite > 0) print 'id.'&action=swapstatut&ligne='.$tab[$i]['rowid'].'">';
- print $contactstatic->LibStatut($tab[$i]['status'],3);
- if ($project->statut >= 0 && $userWrite > 0) print '';
- print ' | ';
-
- // Icon update et delete
- print '';
- if ($user->rights->projet->creer && $userWrite > 0)
- {
- print ' ';
- print 'id.'&action=deleteline&lineid='.$tab[$i]['rowid'].'">';
- print img_delete();
- print '';
- }
- print ' | ';
-
- print "
\n";
-
- $i ++;
- }
- }
- print "
";
+ $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
+ if ($res) break;
+ }
}
else
{