Fix: mise en commun des fonctions

This commit is contained in:
Regis Houssin 2007-06-07 10:58:15 +00:00
parent 74b367c5f0
commit b4c399bd9f
5 changed files with 84 additions and 272 deletions

View File

@ -38,69 +38,7 @@ $langs->load("sendings");
$langs->load("companies");
$user->getrights('propale');
if (!$user->rights->propale->lire)
accessforbidden();
// les methodes locales
/**
* \brief Retourne la liste déroulante des sociétés
* \param selected Societe présélectionnée
* \param htmlname Nom champ formulaire
*/
function select_societes_for_newconcat($propal, $selected = '', $htmlname = 'newcompany'){
// On recherche les societes
$sql = "SELECT s.idp, s.nom FROM";
$sql .= " ".MAIN_DB_PREFIX."societe as s";
// if ($filter) $sql .= " WHERE $filter";
$sql .= " ORDER BY nom ASC";
$resql = $propal->db->query($sql);
if ($resql)
{
$javaScript = "window.location='./contact.php?propalid=".$propal->id."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">';
$num = $propal->db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $propal->db->fetch_object($resql);
if ($i == 0)
$firstCompany = $obj->idp;
if ($selected > 0 && $selected == $obj->idp)
{
print '<option value="'.$obj->idp.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
$firstCompany = $obj->idp;
} else
{
print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>';
}
$i ++;
}
}
print "</select>\n";
return $firstCompany;
} else
{
dolibarr_print_error($propal->db);
}
}
/**
*
*/
function select_type_contact($propal, $defValue, $htmlname = 'type', $source)
{
$lesTypes = $propal->liste_type_contact($source);
print '<select class="flat" name="'.$htmlname.'">';
foreach($lesTypes as $key=>$value)
{
print '<option value="'.$key.'">'.$value.'</option>';
}
print "</select>\n";
}
if (!$user->rights->propale->lire) accessforbidden();
// Sécurité accés client
if ($user->societe_id > 0)
@ -291,7 +229,7 @@ if ($id > 0)
$html->select_users($user->id,'contactid');
print '</td>';
print '<td>';
select_type_contact($propal, '', 'type','internal');
$propal->selectTypeContact($propal, '', 'type','internal');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
@ -313,14 +251,14 @@ if ($id > 0)
print '<td colspan="1">';
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$propal->client->id;
$selectedCompany = select_societes_for_newconcat($propal, $selectedCompany, $htmlname = 'newcompany');
$selectedCompany = $propal->selectCompaniesForNewContact($propal, 'propalid', $selectedCompany, $htmlname = 'newcompany');
print '</td>';
print '<td colspan="1">';
$html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid');
print '</td>';
print '<td>';
select_type_contact($propal, '', 'type','external');
$propal->selectTypeContact($propal, '', 'type','external');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';

View File

@ -38,69 +38,7 @@ $langs->load("sendings");
$langs->load("companies");
$user->getrights('commande');
if (!$user->rights->commande->lire)
accessforbidden();
// les methodes locales
/**
* \brief Retourne la liste déroulante des sociétés
* \param selected Societe présélectionnée
* \param htmlname Nom champ formulaire
*/
function select_societes_for_newconcat($commande, $selected = '', $htmlname = 'newcompany'){
// On recherche les societes
$sql = "SELECT s.idp, s.nom FROM";
$sql .= " ".MAIN_DB_PREFIX."societe as s";
// if ($filter) $sql .= " WHERE $filter";
$sql .= " ORDER BY nom ASC";
$resql = $commande->db->query($sql);
if ($resql)
{
$javaScript = "window.location='./contact.php?id=".$commande->id."&amp;".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">';
$num = $commande->db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $commande->db->fetch_object($resql);
if ($i == 0)
$firstCompany = $obj->idp;
if ($selected > 0 && $selected == $obj->idp)
{
print '<option value="'.$obj->idp.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
$firstCompany = $obj->idp;
} else
{
print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>';
}
$i ++;
}
}
print "</select>\n";
return $firstCompany;
} else
{
dolibarr_print_error($commande->db);
}
}
/**
*
*/
function select_type_contact($commande, $defValue, $htmlname = 'type', $source)
{
$lesTypes = $commande->liste_type_contact($source);
print '<select class="flat" name="'.$htmlname.'">';
foreach($lesTypes as $key=>$value)
{
print '<option value="'.$key.'">'.$value.'</option>';
}
print "</select>\n";
}
if (!$user->rights->commande->lire) accessforbidden();
// Sécurité accés client
if ($user->societe_id > 0)
@ -302,7 +240,7 @@ if ($id > 0)
$html->select_users($user->id,'contactid');
print '</td>';
print '<td>';
select_type_contact($commande, '', 'type','internal');
$commande->selectTypeContact($commande, '', 'type','internal');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
@ -324,14 +262,14 @@ if ($id > 0)
print '<td colspan="1">';
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$commande->client->id;
$selectedCompany = select_societes_for_newconcat($commande, $selectedCompany, $htmlname = 'newcompany');
$selectedCompany = $commande->selectCompaniesForNewContact($commande, 'id', $selectedCompany, $htmlname = 'newcompany');
print '</td>';
print '<td colspan="1">';
$html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid');
print '</td>';
print '<td>';
select_type_contact($commande, '', 'type','external');
$commande->selectTypeContact($commande, '', 'type','external');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';

View File

@ -369,11 +369,74 @@ class CommonObject
* \param userid Id du contact
*/
function fetch_adresse_livraison($deliveryaddressid)
{
$address = new Societe($this->db);
$address->fetch_adresse_livraison($deliveryaddressid);
$this->deliveryaddress = $address;
}
{
$address = new Societe($this->db);
$address->fetch_adresse_livraison($deliveryaddressid);
$this->deliveryaddress = $address;
}
/**
* \brief Retourne la liste déroulante des sociétés
* \param object Fetch du document
* \param var_id Nom de la variable de l'id du document
* \param selected Societe présélectionnée
* \param htmlname Nom champ formulaire
*/
function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany')
{
// On recherche les societes
$sql = "SELECT s.idp, s.nom FROM";
$sql .= " ".MAIN_DB_PREFIX."societe as s";
//if ($filter) $sql .= " WHERE $filter";
$sql .= " ORDER BY nom ASC";
$resql = $object->db->query($sql);
if ($resql)
{
$javaScript = "window.location='./contact.php?".$var_id."=".$object->id."&amp;".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">';
$num = $object->db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $object->db->fetch_object($resql);
if ($i == 0) $firstCompany = $obj->idp;
if ($selected > 0 && $selected == $obj->idp)
{
print '<option value="'.$obj->idp.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
$firstCompany = $obj->idp;
}
else
{
print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>';
}
$i ++;
}
}
print "</select>\n";
return $firstCompany;
}
else
{
dolibarr_print_error($object->db);
}
}
/**
*
*/
function selectTypeContact($object, $defValue, $htmlname = 'type', $source)
{
$lesTypes = $object->liste_type_contact($source);
print '<select class="flat" name="'.$htmlname.'">';
foreach($lesTypes as $key=>$value)
{
print '<option value="'.$key.'">'.$value.'</option>';
}
print "</select>\n";
}
}

View File

@ -38,70 +38,7 @@ $langs->load("companies");
$user->getrights('facture');
if (!$user->rights->facture->lire)
accessforbidden();
// les methodes locales
/**
* \brief Retourne la liste déroulante des sociétés
* \param selected Societe présélectionnée
* \param htmlname Nom champ formulaire
*/
function select_societes_for_newconcat($facture, $selected = '', $htmlname = 'newcompany')
{
// On recherche les societes
$sql = "SELECT s.idp, s.nom FROM";
$sql .= " ".MAIN_DB_PREFIX."societe as s";
// if ($filter) $sql .= " WHERE $filter";
$sql .= " ORDER BY nom ASC";
$resql = $facture->db->query($sql);
if ($resql)
{
$javaScript = "window.location='./contact.php?facid=".$facture->id."&amp;".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">';
$num = $facture->db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $facture->db->fetch_object($resql);
if ($i == 0)
$firstCompany = $obj->idp;
if ($selected > 0 && $selected == $obj->idp)
{
print '<option value="'.$obj->idp.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
$firstCompany = $obj->idp;
} else
{
print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>';
}
$i ++;
}
}
print "</select>\n";
return $firstCompany;
} else
{
dolibarr_print_error($facture->db);
}
}
/**
*
*/
function select_type_contact($facture, $defValue, $htmlname = 'type', $source)
{
$lesTypes = $facture->liste_type_contact($source);
print '<select class="flat" name="'.$htmlname.'">';
foreach($lesTypes as $key=>$value)
{
print '<option value="'.$key.'">'.$value.'</option>';
}
print "</select>\n";
}
if (!$user->rights->facture->lire) accessforbidden();
// Sécurité accés client
if ($user->societe_id > 0)
@ -285,7 +222,7 @@ if ($id > 0)
$html->select_users($user->id,'contactid');
print '</td>';
print '<td>';
select_type_contact($facture, '', 'type','internal');
$facture->selectTypeContact($facture, '', 'type','internal');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
@ -307,14 +244,14 @@ if ($id > 0)
print '<td colspan="1">';
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$facture->client->id;
$selectedCompany = select_societes_for_newconcat($facture, $selectedCompany, $htmlname = 'newcompany');
$selectedCompany = $facture->selectCompaniesForNewContact($facture, 'facid', $selectedCompany, $htmlname = 'newcompany');
print '</td>';
print '<td colspan="1">';
$html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid');
print '</td>';
print '<td>';
select_type_contact($facture, '', 'type','external');
$facture->selectTypeContact($facture, '', 'type','external');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';

View File

@ -39,8 +39,7 @@ $langs->load("companies");
$user->getrights('contrat');
if (!$user->rights->contrat->lire)
accessforbidden();
if (!$user->rights->contrat->lire) accessforbidden();
// Sécurité accés client et commerciaux
$contratid = isset($_GET["id"])?$_GET["id"]:'';
@ -69,69 +68,6 @@ if ($contratid && (!$user->rights->commercial->client->voir || $user->societe_id
}
}
// les methodes locales
/**
* \brief Retourne la liste déroulante des sociétés
* \param selected Societe présélectionnée
* \param htmlname Nom champ formulaire
*/
function select_societes_for_newconcat($contrat, $selected = '', $htmlname = 'newcompany')
{
// On recherche les societes
$sql = "SELECT s.idp, s.nom FROM";
$sql .= " ".MAIN_DB_PREFIX."societe as s";
if ($filter) $sql .= " WHERE $filter";
$sql .= " ORDER BY nom ASC";
$resql = $contrat->db->query($sql);
if ($resql)
{
$javaScript = "window.location='./contact.php?id=".$contrat->id."&amp;".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">';
$num = $contrat->db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $contrat->db->fetch_object($resql);
if ($i == 0)
$firstCompany = $obj->idp;
if ($selected > 0 && $selected == $obj->idp)
{
print '<option value="'.$obj->idp.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
$firstCompany = $obj->idp;
} else
{
print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>';
}
$i ++;
}
}
print "</select>\n";
return $firstCompany;
} else
{
dolibarr_print_error($contrat->db);
}
}
/**
*
*/
function select_type_contact($contrat, $defValue, $htmlname = 'type', $source)
{
$lesTypes = $contrat->liste_type_contact($source);
print '<select class="flat" name="'.$htmlname.'">';
foreach($lesTypes as $key=>$value)
{
print '<option value="'.$key.'">'.$value.'</option>';
}
print "</select>\n";
}
/*
* Ajout d'un nouveau contact
*/
@ -327,7 +263,7 @@ if ($id > 0)
$html->select_users($user->id,'contactid');
print '</td>';
print '<td>';
select_type_contact($contrat, '', 'type','internal');
$contrat->selectTypeContact($contrat, '', 'type','internal');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
@ -349,14 +285,14 @@ if ($id > 0)
print '<td colspan="1">';
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$contrat->societe->id;
$selectedCompany = select_societes_for_newconcat($contrat, $selectedCompany, $htmlname = 'newcompany');
$selectedCompany = $contrat->selectCompaniesForNewContact($contrat, 'id', $selectedCompany, $htmlname = 'newcompany');
print '</td>';
print '<td colspan="1">';
$html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid');
print '</td>';
print '<td>';
select_type_contact($contrat, '', 'type','external');
$contrat->selectTypeContact($contrat, '', 'type','external');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';