Skip to content

Commit

Permalink
New: sharing code of contact and note tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Mar 17, 2012
1 parent ffa3e2a commit 281c6b7
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 928 deletions.
6 changes: 2 additions & 4 deletions htdocs/comm/propal/contact.php
Expand Up @@ -199,12 +199,10 @@
print "</table>";

print '</div>';

/*
* Lignes de contacts
*/

print '<br>';

// Contacts lines
include(DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php');

}
Expand Down
11 changes: 0 additions & 11 deletions htdocs/comm/propal/note.php
Expand Up @@ -148,17 +148,6 @@
print "</table>";

print '</div>';

/*
* Actions
*/

print '<div class="tabsAction">';
if ($user->rights->propale->creer && $action <> 'edit')
{
print '<a class="butAction" href="note.php?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
}
print '</div>';
}
}
}
Expand Down
186 changes: 5 additions & 181 deletions htdocs/commande/contact.php
Expand Up @@ -90,7 +90,7 @@
}

// Efface un contact
else if ($action == 'deleteline' && $user->rights->commande->creer)
else if ($action == 'deletecontact' && $user->rights->commande->creer)
{
$object->fetch($id);
$result = $object->delete_contact($_GET["lineid"]);
Expand Down Expand Up @@ -199,187 +199,11 @@

print '</div>';

/*
* Lignes de contacts
*/
echo '<br><table class="noborder" width="100%">';

/*
* Ajouter une ligne de contact
* Non affiche en mode modification de ligne
*/
if ($action != 'editline' && $user->rights->commande->creer)
{
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Source").'</td>';
print '<td>'.$langs->trans("Company").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>';
print '<td>'.$langs->trans("ContactType").'</td>';
print '<td>&nbsp;</td>';
print '<td colspan="2">&nbsp;</td>';
print "</tr>\n";

$var = false;

print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="internal">';
print '<input type="hidden" name="id" value="'.$id.'">';

// Ligne ajout pour contact interne
print '<tr '.$bc[$var].'>';

print '<td nowrap="nowrap">';
print img_object('','user').' '.$langs->trans("Users");
print '</td>';

print '<td colspan="1">';
print $conf->global->MAIN_INFO_SOCIETE_NOM;
print '</td>';

print '<td colspan="1">';
//$userAlreadySelected = $object->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionne car on doit pouvoir le selectionner une deuxieme fois pour un autre type
$form->select_users($user->id,'contactid',0,$userAlreadySelected);
print '</td>';
print '<td>';
$formcompany->selectTypeContact($object, '', 'type','internal');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';

print '</form>';

print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="external">';
print '<input type="hidden" name="id" value="'.$id.'">';

// Ligne ajout pour contact externe
$var=!$var;
print '<tr '.$bc[$var].'>';

print '<td nowrap="nowrap">';
print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
print '</td>';

print '<td colspan="1">';
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$object->client->id;
$selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany');
print '</td>';

print '<td colspan="1">';
$nbofcontacts=$form->select_contacts($selectedCompany, '', 'contactid');
if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
print '</td>';
print '<td>';
$formcompany->selectTypeContact($object, '', 'type','external');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
if (! $nbofcontacts) print ' disabled="disabled"';
print '></td>';
print '</tr>';

print "</form>";

print '<tr><td colspan="7">&nbsp;</td></tr>';
}

// List of linked contacts
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Source").'</td>';
print '<td>'.$langs->trans("Company").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>';
print '<td>'.$langs->trans("ContactType").'</td>';
print '<td align="center">'.$langs->trans("Status").'</td>';
print '<td colspan="2">&nbsp;</td>';
print "</tr>\n";

$companystatic=new Societe($db);
$var = true;
print '<br>';

// Contacts lines
include(DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php');

foreach(array('internal','external') as $source)
{
$tab = $object->liste_contact(-1,$source);
$num=count($tab);

$i = 0;
while ($i < $num)
{
$var = !$var;

print '<tr '.$bc[$var].' valign="top">';

// Source
print '<td align="left">';
if ($tab[$i]['source']=='internal') print $langs->trans("User");
if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
print '</td>';

// Societe
print '<td align="left">';
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 '&nbsp;';
}
print '</td>';

// Contact
print '<td>';
if ($tab[$i]['source']=='internal')
{
$userstatic->id=$tab[$i]['id'];
$userstatic->lastname=$tab[$i]['lastname'];
$userstatic->firstname=$tab[$i]['firstname'];
print $userstatic->getNomUrl(1);
}
if ($tab[$i]['source']=='external')
{
$contactstatic->id=$tab[$i]['id'];
$contactstatic->lastname=$tab[$i]['lastname'];
$contactstatic->firstname=$tab[$i]['firstname'];
print $contactstatic->getNomUrl(1);
}
print '</td>';

// Type de contact
print '<td>'.$tab[$i]['libelle'].'</td>';

// Statut
print '<td align="center">';
// Activation desativation du contact
if ($object->statut >= 0) print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
print $contactstatic->LibStatut($tab[$i]['status'],3);
if ($object->statut >= 0) print '</a>';
print '</td>';

// Icon update et delete
print '<td align="center" nowrap="nowrap" colspan="2">';
if ($object->statut < 5 && $user->rights->commande->creer)
{
print '&nbsp;';
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=deleteline&amp;lineid='.$tab[$i]['rowid'].'">';
print img_delete();
print '</a>';
}
print '</td>';

print "</tr>\n";

$i ++;
}
}
print "</table>";
}
else
{
Expand Down
78 changes: 75 additions & 3 deletions htdocs/commande/fiche.php
Expand Up @@ -1191,6 +1191,66 @@
}
}

if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
{
if ($action == 'addcontact' && $user->rights->commande->creer)
{
$result = $object->fetch($id);

if ($result > 0 && $id > 0)
{
$result = $object->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
}

if ($result >= 0)
{
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
else
{
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
}
else
{
$mesg = '<div class="error">'.$object->error.'</div>';
}
}
}

// bascule du statut d'un contact
else if ($action == 'swapstatut' && $user->rights->commande->creer)
{
if ($object->fetch($id))
{
$result=$object->swapContactStatus(GETPOST('ligne'));
}
else
{
dol_print_error($db);
}
}

// Efface un contact
else if ($action == 'deletecontact' && $user->rights->commande->creer)
{
$object->fetch($id);
$result = $object->delete_contact($lineid);

if ($result >= 0)
{
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
else {
dol_print_error($db);
}
}
}


/*
* View
Expand Down Expand Up @@ -1951,9 +2011,21 @@
print '</table><br>';
print "\n";

if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
{
include(DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php');
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
{
require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
$formcompany= new FormCompany($db);

$blocname = 'contacts';
$title = $langs->trans('ContactsAddresses');
include(DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php');
}

if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
{
$blocname = 'notes';
$title = $langs->trans('Notes');
include(DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php');
}

/*
Expand Down

0 comments on commit 281c6b7

Please sign in to comment.