Make code simpler

This commit is contained in:
Laurent Destailleur 2010-09-07 10:24:26 +00:00
parent e1bc58080c
commit 31de91ecca

View File

@ -49,13 +49,17 @@ $socid = isset($_GET["socid"])?$_GET["socid"]:'';
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'societe', $socid); $result = restrictedArea($user, 'societe', $socid);
$soc = new Societe($db);
// Get object canvas (By default, this is not defined, so standard usage of dolibarr) // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
$socstatic = new Societe($db); if (!empty($socid)) $soc->getCanvas($socid);
if (!empty($socid)) $socstatic->getCanvas($socid); $canvas = (!empty($soc->canvas)?$soc->canvas:GETPOST("canvas"));
$canvas = (!empty($socstatic->canvas)?$socstatic->canvas:GETPOST("canvas")); if (! empty($canvas))
{
require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php");
$soccanvas = new Canvas($db);
}
$soc = new Societe($db);
/* /*
@ -65,16 +69,22 @@ $soc = new Societe($db);
// If canvas is defined, because on url, or because company was created with canvas feature on, // If canvas is defined, because on url, or because company was created with canvas feature on,
// we use the canvas feature. // we use the canvas feature.
// If canvas is not defined, we use standard feature. // If canvas is not defined, we use standard feature.
if (empty($canvas)) if (! empty($canvas))
{
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
$soccanvas->getCanvas('thirdparty','card',$canvas);
// Load data control
$soccanvas->doActions($socid);
}
else
{ {
// ----------------------------------------- // -----------------------------------------
// When used in standard mode // When used in standard mode
// ----------------------------------------- // -----------------------------------------
/*
* Actions
*/
if ($_POST["getcustomercode"]) if ($_POST["getcustomercode"])
{ {
// We defined value code_client // We defined value code_client
@ -350,18 +360,6 @@ if (empty($canvas))
} }
} }
} }
else
{
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php");
$soccanvas = new Canvas($db);
$soccanvas->getCanvas('thirdparty','card',$canvas);
// Load data control
$soccanvas->doActions($socid);
}
@ -379,16 +377,166 @@ $formcompany = new FormCompany($db);
$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
if (empty($canvas))
if (! empty($canvas))
{ {
if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || // -----------------------------------------
$_GET["action"] == 'create' || $_POST["action"] == 'create') // When used with CANVAS
// -----------------------------------------
if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || GETPOST("action") == 'create')
{ {
/* /*
* Sheet mode creation * Mode creation
*/ */
// Set action type
$soccanvas->setAction(GETPOST("action"));
// Card header
$title = $soccanvas->getTitle();
print_fiche_titre($title);
// Assign _POST data
$soccanvas->assign_post();
// Assign template values
$soccanvas->assign_values();
dol_htmloutput_errors($soccanvas->error,$soccanvas->errors);
// Display canvas
$soccanvas->display_canvas();
}
elseif (GETPOST("action") == 'edit')
{
/*
* Mode edition
*/
// Set action type
$soccanvas->setAction(GETPOST("action"));
// Card header
$title = $soccanvas->getTitle();
print_fiche_titre($title);
if ($reload || ! $_POST["nom"])
{
//Reload object
$soccanvas->fetch($socid);
}
else
{
// Assign _POST data
$soccanvas->assign_post();
}
dol_htmloutput_errors($soccanvas->error,$soccanvas->errors);
// Assign values
$soccanvas->assign_values();
// Display canvas
$soccanvas->display_canvas();
}
else
{
/*
* Mode view
*/
// Set action type
$soccanvas->setAction('view');
// Fetch object
$result=$soccanvas->fetch($socid);
if ($result > 0)
{
// Card header
$head = societe_prepare_head($soccanvas->control->object);
$title = $soccanvas->getTitle();
dol_fiche_head($head, 'company', $title, 0, 'company');
// Assign values
$soccanvas->assign_values();
// Display canvas
$soccanvas->display_canvas();
/*
* Actions
*/
if ($_GET["action"] == '')
{
print '<div class="tabsAction">';
if ($user->rights->societe->creer) if ($user->rights->societe->creer)
{ {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'&amp;action=edit&amp;canvas='.$canvas.'">'.$langs->trans("Modify").'</a>';
}
if ($user->rights->societe->contact->creer)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$socid.'&amp;action=create&amp;canvas='.$canvas.'">'.$langs->trans("AddContact").'</a>';
}
if ($user->rights->societe->supprimer)
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'&amp;action=delete&amp;canvas='.$canvas.'">'.$langs->trans('Delete').'</a>';
}
print '</div>';
print '<br>';
}
print '<table width="100%"><tr><td valign="top" width="50%">';
print '<a name="builddoc"></a>'; // ancre
/*
* Documents generes
*/
$filedir=$conf->societe->dir_output.'/'.$socid;
$urlsource=$_SERVER["PHP_SELF"]."?socid=".$socid;
$genallowed=$user->rights->societe->creer;
$delallowed=$user->rights->societe->supprimer;
$var=true;
$somethingshown=$formfile->show_documents('company',$socid,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$soccanvas->control->object->default_lang);
print '</td>';
print '<td>';
print '</td>';
print '</tr>';
print '</table>';
print '<br>';
// Contacts list
$result=show_contacts($conf,$langs,$db,$soccanvas->control->object);
// Projects list
$result=show_projects($conf,$langs,$db,$soccanvas->control->object);
}
else
{
dol_htmloutput_errors($soccanvas->error,$soccanvas->errors);
}
}
}
else
{
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || GETPOST('action') == 'create')
{
/*
* Creation
*/
// Load object modCodeTiers // Load object modCodeTiers
$module=$conf->global->SOCIETE_CODECLIENT_ADDON; $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
if (! $module) dolibarr_error('',$langs->trans("ErrorModuleThirdPartyCodeInCompanyModuleNotDefined")); if (! $module) dolibarr_error('',$langs->trans("ErrorModuleThirdPartyCodeInCompanyModuleNotDefined"));
@ -800,13 +948,11 @@ if (empty($canvas))
print '</table>'."\n"; print '</table>'."\n";
print '</form>'."\n"; print '</form>'."\n";
} }
} elseif (GETPOST('action') == 'edit')
elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
{ {
/* /*
* Company Fact Mode edition * Edition
*/ */
print_fiche_titre($langs->trans("EditCompany")); print_fiche_titre($langs->trans("EditCompany"));
@ -1192,7 +1338,7 @@ if (empty($canvas))
else else
{ {
/* /*
* Company Fact Sheet mode visu * View
*/ */
$soc = new Societe($db); $soc = new Societe($db);
$soc->id = $socid; $soc->id = $socid;
@ -1596,163 +1742,6 @@ if (empty($canvas))
} }
} }
else
{
if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || GETPOST("action") == 'create')
{
/*
* Mode creation
*/
if ($user->rights->societe->creer)
{
// Set action type
$soccanvas->setAction(GETPOST("action"));
// Card header
$title = $soccanvas->getTitle();
print_fiche_titre($title);
// Assign _POST data
$soccanvas->assign_post();
// Assign template values
$soccanvas->assign_values();
dol_htmloutput_errors($soccanvas->error,$soccanvas->errors);
// Display canvas
$soccanvas->display_canvas();
}
}
elseif (GETPOST("action") == 'edit')
{
/*
* Mode edition
*/
// Set action type
$soccanvas->setAction(GETPOST("action"));
// Card header
$title = $soccanvas->getTitle();
print_fiche_titre($title);
if ($socid)
{
if ($reload || ! $_POST["nom"])
{
//Reload object
$soccanvas->fetch($socid);
}
else
{
// Assign _POST data
$soccanvas->assign_post();
}
dol_htmloutput_errors($soccanvas->error,$soccanvas->errors);
// Assign values
$soccanvas->assign_values();
// Display canvas
$soccanvas->display_canvas();
}
else
{
$langs->load("errors");
print $langs->trans("ErrorRecordNotFound");
}
}
else
{
/*
* Mode view
*/
// Set action type
$soccanvas->setAction('view');
// Fetch object
$result=$soccanvas->fetch($socid);
if ($result > 0)
{
// Card header
$head = societe_prepare_head($soccanvas->control->object);
$title = $soccanvas->getTitle();
dol_fiche_head($head, 'company', $title, 0, 'company');
// Assign values
$soccanvas->assign_values();
// Display canvas
$soccanvas->display_canvas();
/*
* Actions
*/
if ($_GET["action"] == '')
{
print '<div class="tabsAction">';
if ($user->rights->societe->creer)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'&amp;action=edit&amp;canvas='.$canvas.'">'.$langs->trans("Modify").'</a>';
}
if ($user->rights->societe->contact->creer)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$socid.'&amp;action=create&amp;canvas='.$canvas.'">'.$langs->trans("AddContact").'</a>';
}
if ($user->rights->societe->supprimer)
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'&amp;action=delete&amp;canvas='.$canvas.'">'.$langs->trans('Delete').'</a>';
}
print '</div>';
print '<br>';
}
print '<table width="100%"><tr><td valign="top" width="50%">';
print '<a name="builddoc"></a>'; // ancre
/*
* Documents generes
*/
$filedir=$conf->societe->dir_output.'/'.$socid;
$urlsource=$_SERVER["PHP_SELF"]."?socid=".$socid;
$genallowed=$user->rights->societe->creer;
$delallowed=$user->rights->societe->supprimer;
$var=true;
$somethingshown=$formfile->show_documents('company',$socid,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$soccanvas->control->object->default_lang);
print '</td>';
print '<td>';
print '</td>';
print '</tr>';
print '</table>';
print '<br>';
// Contacts list
$result=show_contacts($conf,$langs,$db,$soccanvas->control->object);
// Projects list
$result=show_projects($conf,$langs,$db,$soccanvas->control->object);
}
else
{
$langs->load("errors");
print $langs->trans("ErrorRecordNotFound");
}
}
}
$db->close(); $db->close();