Skip to content
Snippets Groups Projects
Commit cb3f178d authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Add samples for code example

parent 372ecf4e
No related branches found
No related tags found
No related merge requests found
File moved
README (English)
--------------------------------
Scripts in this directory can be used to reinit a demo database.
WARNING: This will erase current database with data into initdemo.sql.
Do a chmod 700 initdemo.sh
then run ./initdemo.sh to launch Graphic User Interface.
L'installation du package "dialog" est indispensable.
......@@ -3,9 +3,10 @@ README (French)
Ce script permet de reinitialiser une base de donnée Dolibarr avec des
données de demo.
ATTENTION: Ceci efface les données en cours de la base.
ATTENTION: Ceci efface les données en cours de la base avec les données
du fichier initdemo.sql.
Faite un chmod 700 initdemo.sh
puis ./initdemo.sh pour executer l'interface.
puis ./initdemo.sh pour lancer l'interface graphique.
L'installation du package "dialog" est indispensable.
......@@ -7,6 +7,7 @@
# Laurent Destailleur - eldy@users.sourceforge.net
#------------------------------------------------------
# WARNING: This script erase all data of database
# with data into initdemo.sql
#------------------------------------------------------
export mydir=`echo "$_" | sed -e 's/initdemo.sh//'`;
......
......@@ -189,7 +189,7 @@ for ($s = 0 ; $s < GEN_NUMBER_COMMANDE ; $s++)
}
else
{
dol_print_error($db,$facture->error);
dol_print_error($db,$com->error);
}
print "\n";
......
README (English)
--------------------------------
This directory contains samples of code to use Dolibarr classes to build
external interfaces that need to read/update data from/into Dolibarr.
\ No newline at end of file
<?PHP
/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file dev/samples/manage_order.php
* \brief This file is an example for a command line script
* \version $Id$
* \author Put author name here
* \remarks Put here some comments
*/
// Test if batch mode
$sapi_type = php_sapi_name();
$script_file=__FILE__;
if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1];
$path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Error: You are using PHP for CGI/Web. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
exit;
}
// Global variables
$version='$Revision$';
$error=0;
// -------------------- START OF YOUR CODE HERE --------------------
// Include Dolibarr environment
require_once($path."../../htdocs/master.inc.php");
require_once($path."../../htdocs/commande/commande.class.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) { dol_print_error('',$user->error); exit; }
$user->getrights();
print "***** ".$script_file." (".$version.") *****\n";
// Check parameters
if (! isset($argv[1])) {
print "Usage: ".$script_file." param1 param2 ...\n";
exit;
}
// Show parameters
print 'Argument 1='.$argv[1]."\n";
print 'Argument 2='.$argv[2]."\n";
print '--- start'."\n";
// Start of transaction
$db->begin();
// Create order object
$com = new Commande($db);
$com->ref = 'ABCDE';
$com->socid = 4; // Put id of third party (rowid in llx_societe table)
$com->date_commande = mktime();
$com->note = 'A comment';
$com->source = 1;
$com->remise_percent = 0;
$orderline1=new CommandeLigne($db);
$orderline1->tva_tx=10.0;
$orderline1->remise_percent=0;
$orderline1->qty=1;
$com->lines[]=$orderline1;
// Create order
$result=$com->create($user);
if ($result >= 0)
{
// Change status to validated
$result=$com->valid($user);
if ($result) print " OK";
else
{
$error++;
dol_print_error($db,$com->error);
}
}
else
{
$error++;
dol_print_error($db,$com->error);
}
print "\n";
// -------------------- 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;
?>
......@@ -26,31 +26,36 @@
* \remarks Put here some comments
*/
// Test if batch mode
// Test if batch mode and define path of script
$sapi_type = php_sapi_name();
$script_file=__FILE__;
if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1];
$path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Error: You are using PH for CGI/Web. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
echo "Error: You are using PHP for CGI/Web. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
exit;
}
// Include Dolibarr environment
require_once($path."../../htdocs/master.inc.php");
// After this $db, $mysoc, $langs and $conf->entity are defined. Opened handler to database will be closed at end of file.
require_once(DOL_DOCUMENT_ROOT."/cron/functions_cron.lib.php");
// Global variables
$version='$Revision$';
$error=0;
// -------------------- START OF YOUR CODE HERE --------------------
// Include Dolibarr environment
require_once($path."../../htdocs/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);
@set_time_limit(0); // No timeout for this script
// Load user and its permissions
$result=$user->fetch('admin'); // Load user for login 'admin'. Comment line to run as anonymous user.
if (! $result > 0) { dol_print_error('',$user->error); exit; }
$user->getrights();
print "***** ".$script_file." (".$version.") *****\n";
// Check parameters
......@@ -80,7 +85,7 @@ dol_syslog($script_file." CREATE", LOG_DEBUG);
$myobject->prop1='value_prop1';
$myobject->prop2='value_prop2';
$id=$myobject->create($user);
if ($id < 0) dol_print_error($db,$myobject->error);
if ($id < 0) { $error++; dol_print_error($db,$myobject->error); }
else print "Object created with id=".$id."\n";
*/
......@@ -88,7 +93,7 @@ else print "Object created with id=".$id."\n";
/*
dol_syslog($script_file." FETCH", LOG_DEBUG);
$result=$myobject->fetch($id);
if ($result < 0) dol_print_error($db,$myobject->error);
if ($result < 0) { $error; dol_print_error($db,$myobject->error); }
else print "Object with id=".$id." loaded\n";
*/
......@@ -98,7 +103,7 @@ dol_syslog($script_file." UPDATE", LOG_DEBUG);
$myobject->prop1='newvalue_prop1';
$myobject->prop2='newvalue_prop2';
$result=$myobject->update($user);
if ($result < 0) dol_print_error($db,$myobject->error);
if ($result < 0) { $error++; dol_print_error($db,$myobject->error); }
else print "Object with id ".$myobject->id." updated\n";
*/
......@@ -106,7 +111,7 @@ else print "Object with id ".$myobject->id." updated\n";
/*
dol_syslog($script_file." DELETE", LOG_DEBUG);
$result=$myobject->delete($user);
if ($result < 0) dol_print_error($db,$myobject->error);
if ($result < 0) { $error++; dol_print_error($db,$myobject->error); }
else print "Object with id ".$myobject->id." deleted\n";
*/
......@@ -141,8 +146,8 @@ if ($resql)
}
else
{
$error++;
dol_print_error($db);
exit;
}
*/
......@@ -160,7 +165,7 @@ else
$db->rollback();
}
$db->close();
$db->close(); // Close database opened handler
return $error;
?>
README (English)
--------------------------------
This directory contains tools to generate translation files for a new languages
or to update translation files for existing languages.
See http://wiki.dolibarr.org/ in pages about "How to translate Dolibarr" for
more informations on how to use them.
README (English)
--------------------------------
This directory contains information to know how to setup XDebug in Eclipse for
running PHP scripts with XDebug.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment