[code]
$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
// Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
exit;
}
// Global variables
$version='1.7';
$error=0;
// -------------------- START OF YOUR CODE HERE --------------------
// Include Dolibarr environment
require_once($path."../dolibarr/master.inc.php");
// After this $db, $mysoc, $langs and $conf->entity are defined. Opened handler to database will be closed at end of file.
//$langs->setDefaultLang('en_US'); // To change default language of $langs
$langs->load("main"); // To load language file for default language
@set_time_limit(0);
// Load user and its permissions
$result=$user->fetch('','admin'); // Load user for login 'admin'. Comment line to run as anonymous user.
if (! $result > 0)
$user->getrights();
print "***** ".$script_file." (".$version.") *****\n";
// Start of transaction
$db->begin();
require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
// Create invoice object
$company = new Societe($db);
$company->name="test";
$company->firstname="testa";
$company->lastname="testb";
$company->civility_id="1";
$company->address="fgjlkkjgfjkgome";
$company->zip="06000";
$company->country_id="1";
$company->phone="00";
$company->email="test@test.com";
$company->client=1;
$idobject=$company->create($user);
var_dump($idobject);
if ($idobject > 0)
{
// Change status to validated
$result=$company->setStatut(1);
if ($result > 0) print "OK Object created with id ".$idobject."\n";
else
{
$error++;
dol_print_error($db,$company->error);
}
}
else
{
$error++;
dol_print_error($db,$companys->error);
}
// -------------------- END OF YOUR CODE --------------------
if (! $error)
{
//$db->commit();
print '--- end ok'."\n";
}
else
{
print '--- end error code='.$error."\n";
$db->rollback();
}
$db->close();
return $error;
[/code]
↧