2
0
forked from Wavyzz/dolibarr

Work on modulebuilder tool

This commit is contained in:
Laurent Destailleur
2017-05-27 13:46:34 +02:00
parent 7a1480d362
commit c651f1da45
27 changed files with 2327 additions and 1658 deletions

View File

@@ -33,7 +33,7 @@ top_httphead('text/html'); // TODO Use a json mime type
global $user, $db, $langs, $conf;
$time = (int) GETPOST('time'); // Use the time parameter that is always increased by time_update, even if call is late
$time = (int) GETPOST('time','int'); // Use the time parameter that is always increased by time_update, even if call is late
//$time=dol_now();

View File

@@ -54,7 +54,7 @@ function dol_basename($pathfile)
* @return array Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file',...)
* @see dol_dir_list_indatabase
*/
function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=false)
function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0)
{
global $db, $hookmanager;
global $object;
@@ -483,6 +483,8 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0)
dol_delete_file($tmpdestfile);
// Create $newpathoftmpdestfile from $newpathofsrcfile

View File

@@ -18,6 +18,7 @@ ErrorFailToCreateFile=Failed to create file '<b>%s</b>'.
ErrorFailToRenameDir=Failed to rename directory '<b>%s</b>' into '<b>%s</b>'.
ErrorFailToCreateDir=Failed to create directory '<b>%s</b>'.
ErrorFailToDeleteDir=Failed to delete directory '<b>%s</b>'.
ErrorFailToMakeReplacementInto=Failed to make replacement into file '<b>%s</b>'.
ErrorThisContactIsAlreadyDefinedAsThisType=This contact is already defined as contact for this type.
ErrorCashAccountAcceptsOnlyCashMoney=This bank account is a cash account, so it accepts payments of type cash only.
ErrorFromToAccountsMustDiffers=Source and targets bank accounts must be different.

View File

@@ -1,5 +1,6 @@
# Dolibarr language file - Source file is en_US - loan
ModuleBuilderDesc=This tools give you utilites to build or edit your own module.
EnterNameOfModuleDesc=Enter name of the module to create with no spaces. Use uppercase to separate words (For example: MyModule, EcommerceForShop, SyncWithMySystem...)
ModuleBuilderDesc2=Path were modules are generated/edited (first alternative directory defined into %s): <strong>%s</strong>
ModuleBuilderDesc3=Generated/editable modules found: <strong>%s</strong> (they are detected as editable when the file <strong>%s</strong> exists in root of module directory).
NewModule=New module

View File

@@ -0,0 +1,221 @@
Dolibarr Module Template (aka My Module)
========================================
This is a full featured module template for Dolibarr.
It's a tool for module developers to kickstart their project and give an hands-on sample of which features Dolibarr has to offer for module development.
If you're not a module developer you have no use for this.
Documentation
-------------
[Module tutorial](http://wiki.dolibarr.org/index.php/Module_development)
[Dolibarr development](http://wiki.dolibarr.org/index.php/Developer_documentation)
### Translations
Dolibarr uses [Transifex](http://transifex.com) to manage it's translations.
This template also contains a sample configuration for Transifex managed translations under the hidden [.tx](.tx) directory.
For more informations, see the [translator's documentation](http://wiki.dolibarr.org/index.php/Translator_documentation).
There is a [Transifex project](http://transifex.com/projects/p/dolibarr-module-template) for this module.
Install
-------
### Manually
- Make sure Dolibarr (>= 3.3.x) is already installed and configured on your workstation or development server.
- In your Dolibarr installation directory, edit the ```htdocs/conf/conf.php``` file
- Find the following lines:
```php
//$dolibarr_main_url_root_alt ...
//$dolibarr_main_document_root_alt ...
```
- Uncomment these lines (delete the leading ```//```) and assign a sensible value according to your Dolibarr installation
For example :
- UNIX:
```php
$dolibarr_main_url_root = 'http://localhost/Dolibarr/htdocs';
$dolibarr_main_document_root = '/var/www/Dolibarr/htdocs';
$dolibarr_main_url_root_alt = '/custom';
$dolibarr_main_document_root_alt = '/var/www/Dolibarr/htdocs/custom';
```
- Windows:
```php
$dolibarr_main_url_root = 'http://localhost/Dolibarr/htdocs';
$dolibarr_main_document_root = 'C:/My Web Sites/Dolibarr/htdocs';
$dolibarr_main_url_root_alt = '/custom';
$dolibarr_main_document_root_alt = 'C:/My Web Sites/Dolibarr/htdocs/custom';
```
For more information about the ```conf.php``` file take a look at the conf.php.example file.
*Note that for Dolibarr versions before 3.5, the ```$dolibarr_main_url_root_alt``` has to be an absolute path*
- Clone the repository in ```$dolibarr_main_document_root_alt/mymodule```
*(You may have to create the ```htdocs/custom``` directory first if it doesn't exist yet.)*
```sh
git clone git@github.com:Dolibarr/dolibarr-module-template.git mymodule
```
- Install [Composer](https://getcomposer.org) dependencies:
```sh
composer install
```
Follow the [final steps](#final_steps).
### Using [Composer](https://getcomposer.org)
Require this repository from Dolibarr's composer:
```json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/dolibarr/dolibarr-module-template"
}
],
"require": {
"dolibarr/mymodule": "dev-master"
}
}
```
Run
```sh
composer update
```
Follow the [final steps](#final_steps).
### <a name="final_steps"></a>Final steps
From your browser:
- Log into Dolibarr as a super-administrator
- Under "Setup" -> "Other setup", set ```MAIN_FEATURES_LEVEL``` to ```2```
- Go to "Setup" -> "Modules"
- The module is under one of the tabs
- You should now be able to enable the new module and start coding ;)
Provided tools
--------------
### Starting a new module
A [script](dev/newmodule.sh) allows you to rename most of the code to your own module name.
It requires ```find```, ```sed``` and ```rename``` commands on your system.
Just make sure you provide a CamelCase name.
```sh
./dev/newmodule.sh [NewName]
```
Some work still has to be done manually:
- Rename the directory holding the code
- Maybe rename some other bits (Search for 'my' in filenames and code)
- Update your module ID in the module descriptor
- Update your language files
- Keywords based on the module ID
- String referencing the template
- Remove the features you don't plan to use
- Fill the copyright notices at the top of each file
- Add your logo: see [images README](dev/img/README.md) for specifications
- Start a new GIT history
```
git checkout --orphan [new_branch_name]
```
- Build an awesome module ;)
### Composer scripts
Only the main commands are listed here.
See the [composer comments](composer-comments.md) or the [composer.json](composer.json) itself for more informations.
#### Check
Run a linter, a PHP compatibility version checker and checks coding style.
```sh
composer check
```
#### Test
Run unit and functional tests.
```sh
composer test
```
#### Doc
Build code and user documentation.
#### Release
Run the checks and tests then build a distribution ZIP.
```sh
composer release
```
#### Git hooks
Optional [GIT hooks](https://git-scm.com/book/it/v2/Customizing-Git-Git-Hooks) are provided.
These are just wrappers calling composer scripts.
They ensure best practices are followed during module development.
Install:
```sh
composer git_hooks_install
```
Remove:
```sh
composer git_hooks_remove
```
## Publishing the module
The de-facto standard for publishing and marketing modules for Dolibarr is the [Dolistore](https://www.dolistore.com).
Templates for required images and texts are [provided](dev/dolistore).
Check the dedicated [README](dev/dolistore/README.md) for more informations.
Contributions
-------------
Feel free to contribute and report defects on our [issue tracker](http://github.com/Dolibarr/dolibarr-module-template/issues).
Licenses
--------
### Main code
![GPLv3 logo](img/gplv3.png)
GPLv3 or (at your option) any later version.
See [COPYING](COPYING) for more information.
### Other Licenses
#### [Parsedown](http://parsedown.org/)
Used to display this README in the module's about page.
Licensed under MIT.
#### [GNU Licenses logos](https://www.gnu.org/graphics/license-logos.html)
Public domain
#### Documentation
All texts and readmes.
![GFDL logo](img/gfdl.png)

View File

@@ -32,15 +32,15 @@ $langs->load("other");
$action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha');
$module=GETPOST('module');
$tab=GETPOST('tab');
if (empty($module)) $module='initmodule';
if (empty($tab)) $tab='description';
$modulename=dol_sanitizeFileName(GETPOST('modulename','alpha'));
// Security check
if (! $user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) accessforbidden('ModuleBuilderNotAllowed');
$modulename=dol_sanitizeFileName(GETPOST('modulename','alpha'));
// Dir for custom dirs
$tmp=explode(',', $dolibarr_main_document_root_alt);
@@ -55,35 +55,59 @@ $FILEFLAG='modulebuilder.txt';
if ($dircustom && $action == 'initmodule' && $modulename)
{
$srcfile = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$destfile = $dircustom.'/'.$modulename;
$result = dolCopyDir($srcfile, $destfile, 0, 0);
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$destdir = $dircustom.'/'.$modulename;
$arrayreplacement=array(
'mymodule'=>strtolower($modulename),
'MyModule'=>$modulename
);
$result = dolCopyDir($srcdir, $destdir, 0, 0);
//dol_mkdir($destfile);
if ($result <= 0)
{
$error++;
setEventMessages($langs->trans("ErrorFailedToCopyDir"), null, 'errors');
$langs->load("errors");
setEventMessages($langs->trans("ErrorFailToCopyDir", $srcdir, $destdir), null, 'errors');
}
// Edit PHP files
$listofphpfilestoedit = dol_dir_list($destfile, 'files', 1, '\.php$', 'fullname', SORT_ASC, 0, true);
foreach($listofphpfilestoedit as $phpfileval)
if (! $error)
{
$arrayreplacement=array(
'mymodule'=>$modulename
);
$result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
var_dump($phpfileval);
var_dump($result);
}
$listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.php$', '', 'fullname', SORT_ASC, 0, 1);
foreach($listofphpfilestoedit as $phpfileval)
{
var_dump($phpfileval['fullname']);
$arrayreplacement=array(
'mymodule'=>strtolower($modulename),
'MyModule'=>$modulename,
'MYMODULE'=>strtoupper($modulename),
'My module'=>$modulename,
'htdocs/modulebuilder/template/'=>'',
);
$result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
//var_dump($result);
if ($result < 0)
{
setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
}
}
}
if (! $error)
{
setEventMessages('ModuleInitialized', null);
$module=$modulename;
$modulename = '';
}
}
/*
* View
*/
@@ -96,6 +120,7 @@ $text=$langs->trans("ModuleBuilder");
print load_fiche_titre($text, '', 'title_setup');
$listofmodules=array();
/*
if (!empty($conf->modulebuilder->enabled) && $mainmenu == 'modulebuilder') // Entry for Module builder
{
@@ -124,7 +149,7 @@ if (!empty($conf->modulebuilder->enabled) && $mainmenu == 'modulebuilder') // En
$newmenu->add('', 'NoGeneratedModuleFound', 0, 0);
}*/
// Show description of content
print $langs->trans("ModuleBuilderDesc").'<br>';
print $langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $dircustom).'<br>';
@@ -161,7 +186,10 @@ if ($module == 'initmodule')
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="initmodule">';
print '<input type="hidden" name="module" value="initmodule">';
print '<input type="text" name="modulename" value="" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'">';
print $langs->trans("EnterNameOfModuleDesc").'<br><br>';
print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'">';
print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
print '</form>';
}

View File

@@ -1,221 +1,6 @@
Dolibarr Module Template (aka My Module)
========================================
# MYMODULE FOR DOLIBARR ERP CRM
This is a full featured module template for Dolibarr.
It's a tool for module developers to kickstart their project and give an hands-on sample of which features Dolibarr has to offer for module development.
## Features
MyModuleDescription
If you're not a module developer you have no use for this.
Documentation
-------------
[Module tutorial](http://wiki.dolibarr.org/index.php/Module_development)
[Dolibarr development](http://wiki.dolibarr.org/index.php/Developer_documentation)
### Translations
Dolibarr uses [Transifex](http://transifex.com) to manage it's translations.
This template also contains a sample configuration for Transifex managed translations under the hidden [.tx](.tx) directory.
For more informations, see the [translator's documentation](http://wiki.dolibarr.org/index.php/Translator_documentation).
There is a [Transifex project](http://transifex.com/projects/p/dolibarr-module-template) for this module.
Install
-------
### Manually
- Make sure Dolibarr (>= 3.3.x) is already installed and configured on your workstation or development server.
- In your Dolibarr installation directory, edit the ```htdocs/conf/conf.php``` file
- Find the following lines:
```php
//$dolibarr_main_url_root_alt ...
//$dolibarr_main_document_root_alt ...
```
- Uncomment these lines (delete the leading ```//```) and assign a sensible value according to your Dolibarr installation
For example :
- UNIX:
```php
$dolibarr_main_url_root = 'http://localhost/Dolibarr/htdocs';
$dolibarr_main_document_root = '/var/www/Dolibarr/htdocs';
$dolibarr_main_url_root_alt = '/custom';
$dolibarr_main_document_root_alt = '/var/www/Dolibarr/htdocs/custom';
```
- Windows:
```php
$dolibarr_main_url_root = 'http://localhost/Dolibarr/htdocs';
$dolibarr_main_document_root = 'C:/My Web Sites/Dolibarr/htdocs';
$dolibarr_main_url_root_alt = '/custom';
$dolibarr_main_document_root_alt = 'C:/My Web Sites/Dolibarr/htdocs/custom';
```
For more information about the ```conf.php``` file take a look at the conf.php.example file.
*Note that for Dolibarr versions before 3.5, the ```$dolibarr_main_url_root_alt``` has to be an absolute path*
- Clone the repository in ```$dolibarr_main_document_root_alt/mymodule```
*(You may have to create the ```htdocs/custom``` directory first if it doesn't exist yet.)*
```sh
git clone git@github.com:Dolibarr/dolibarr-module-template.git mymodule
```
- Install [Composer](https://getcomposer.org) dependencies:
```sh
composer install
```
Follow the [final steps](#final_steps).
### Using [Composer](https://getcomposer.org)
Require this repository from Dolibarr's composer:
```json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/dolibarr/dolibarr-module-template"
}
],
"require": {
"dolibarr/mymodule": "dev-master"
}
}
```
Run
```sh
composer update
```
Follow the [final steps](#final_steps).
### <a name="final_steps"></a>Final steps
From your browser:
- Log into Dolibarr as a super-administrator
- Under "Setup" -> "Other setup", set ```MAIN_FEATURES_LEVEL``` to ```2```
- Go to "Setup" -> "Modules"
- The module is under one of the tabs
- You should now be able to enable the new module and start coding ;)
Provided tools
--------------
### Starting a new module
A [script](dev/newmodule.sh) allows you to rename most of the code to your own module name.
It requires ```find```, ```sed``` and ```rename``` commands on your system.
Just make sure you provide a CamelCase name.
```sh
./dev/newmodule.sh [NewName]
```
Some work still has to be done manually:
- Rename the directory holding the code
- Maybe rename some other bits (Search for 'my' in filenames and code)
- Update your module ID in the module descriptor
- Update your language files
- Keywords based on the module ID
- String referencing the template
- Remove the features you don't plan to use
- Fill the copyright notices at the top of each file
- Add your logo: see [images README](dev/img/README.md) for specifications
- Start a new GIT history
```
git checkout --orphan [new_branch_name]
```
- Build an awesome module ;)
### Composer scripts
Only the main commands are listed here.
See the [composer comments](composer-comments.md) or the [composer.json](composer.json) itself for more informations.
#### Check
Run a linter, a PHP compatibility version checker and checks coding style.
```sh
composer check
```
#### Test
Run unit and functional tests.
```sh
composer test
```
#### Doc
Build code and user documentation.
#### Release
Run the checks and tests then build a distribution ZIP.
```sh
composer release
```
#### Git hooks
Optional [GIT hooks](https://git-scm.com/book/it/v2/Customizing-Git-Git-Hooks) are provided.
These are just wrappers calling composer scripts.
They ensure best practices are followed during module development.
Install:
```sh
composer git_hooks_install
```
Remove:
```sh
composer git_hooks_remove
```
## Publishing the module
The de-facto standard for publishing and marketing modules for Dolibarr is the [Dolistore](https://www.dolistore.com).
Templates for required images and texts are [provided](dev/dolistore).
Check the dedicated [README](dev/dolistore/README.md) for more informations.
Contributions
-------------
Feel free to contribute and report defects on our [issue tracker](http://github.com/Dolibarr/dolibarr-module-template/issues).
Licenses
--------
### Main code
![GPLv3 logo](img/gplv3.png)
GPLv3 or (at your option) any later version.
See [COPYING](COPYING) for more information.
### Other Licenses
#### [Parsedown](http://parsedown.org/)
Used to display this README in the module's about page.
Licensed under MIT.
#### [GNU Licenses logos](https://www.gnu.org/graphics/license-logos.html)
Public domain
#### Documentation
All texts and readmes.
![GFDL logo](img/gfdl.png)
Other modules are available on <a href="https://www.dolistore.com target="_new">Dolistore.com</a>.

View File

@@ -17,7 +17,7 @@
*/
/**
* \file admin/about.php
* \file htdocs/modulebuilder/template/admin/about.php
* \ingroup mymodule
* \brief About page of module MyModule.
*

View File

@@ -17,7 +17,7 @@
*/
/**
* \file admin/setup.php
* \file htdocs/modulebuilder/template/admin/setup.php
* \ingroup mymodule
* \brief Example module setup page.
*
@@ -57,8 +57,8 @@ $page_name = "MyModuleSetup";
llxHeader('', $langs->trans($page_name));
// Subheader
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">'
. $langs->trans("BackToModuleList") . '</a>';
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
print load_fiche_titre($langs->trans($page_name), $linkback);
// Configuration header

View File

@@ -1,51 +0,0 @@
<?php
/* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) <year> <name of author>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/**
* \file class/MyTrigger.php
* \ingroup mymodule
* \brief Compatibility class for triggers in Dolibarr < 3.7.
*
* Hack for compatibility with Dolibarr versions < 3.7.
* Remove this and extend DolibarrTriggers directly from interface_99_modMyModule_MyTrigger.class.php
* if you don't intend to support these versions.
*/
// We ignore the PSR1.Classes.ClassDeclaration.MultipleClasses rule.
// @codingStandardsIgnoreStart
$dolibarr_version = versiondolibarrarray();
if ($dolibarr_version[0] < 3 || ($dolibarr_version[0] == 3 && $dolibarr_version[1] < 7)) { // DOL_VERSION < 3.7
/**
* Class MyTrigger
*
* For Dolibarr < 3.7.
*/
abstract class MyTrigger
{
}
} else {
/**
* Class MyTrigger
*
* For Dolibarr >= 3.7
*/
abstract class MyTrigger extends DolibarrTriggers
{
}
}
// @codingStandardsIgnoreEnd

View File

@@ -17,7 +17,7 @@
*/
/**
* \file class/actions_mymodule.class.php
* \file htdocs/modulebuilder/template/class/actions_mymodule.class.php
* \ingroup mymodule
* \brief Example hook overload.
*

View File

@@ -1,361 +0,0 @@
<?php
/* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) <year> <name of author>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/**
* \file class/myclass.class.php
* \ingroup mymodule
* \brief Example CRUD (Create/Read/Update/Delete) class.
*
* Put detailed description here.
*/
/** Includes */
//require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
//require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
//require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
/**
* Put your class' description here
*/
class MyClass // extends CommonObject
{
/** @var DoliDb Database handler */
private $db;
/** @var string Error code or message */
public $error;
/** @var array Several error codes or messages */
public $errors = array();
/** @var string Id to identify managed object */
//public $element='myelement';
/** @var string Name of table without prefix where object is stored */
//public $table_element='mytable';
/** @var int An example ID */
public $id;
/** @var mixed An example property */
public $prop1;
/** @var mixed An example property */
public $prop2;
/**
* Constructor
*
* @param DoliDb $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
return 1;
}
/**
* Create object into database
*
* @param User $user User that create
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, Id of created object if OK
*/
public function create($user, $notrigger = 0)
{
global $conf, $langs;
$error = 0;
// Clean parameters
if (isset($this->prop1)) {
$this->prop1 = trim($this->prop1);
}
if (isset($this->prop2)) {
$this->prop2 = trim($this->prop2);
}
// Check parameters
// Put here code to add control on parameters values
// Insert request
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "mytable(";
$sql.= " field1,";
$sql.= " field2";
$sql.= ") VALUES (";
$sql.= " '" . $this->prop1 . "',";
$sql.= " '" . $this->prop2 . "'";
$sql.= ")";
$this->db->begin();
dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) {
$error ++;
$this->errors[] = "Error " . $this->db->lasterror();
}
if (! $error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "mytable");
if (! $notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action call a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR);
$this->error.=($this->error ? ', ' . $errmsg : $errmsg);
}
$this->db->rollback();
return -1 * $error;
} else {
$this->db->commit();
return $this->id;
}
}
/**
* Load object in memory from database
*
* @param int $id Id object
* @return int <0 if KO, >0 if OK
*/
public function fetch($id)
{
global $langs;
$sql = "SELECT";
$sql.= " t.rowid,";
$sql.= " t.field1,";
$sql.= " t.field2";
//...
$sql.= " FROM " . MAIN_DB_PREFIX . "mytable as t";
$sql.= " WHERE t.rowid = " . $id;
dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->prop1 = $obj->field1;
$this->prop2 = $obj->field2;
//...
}
$this->db->free($resql);
return 1;
} else {
$this->error = "Error " . $this->db->lasterror();
dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
return -1;
}
}
/**
* Update object into database
*
* @param User $user User that modify
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
public function update($user = 0, $notrigger = 0)
{
global $conf, $langs;
$error = 0;
// Clean parameters
if (isset($this->prop1)) {
$this->prop1 = trim($this->prop1);
}
if (isset($this->prop2)) {
$this->prop2 = trim($this->prop2);
}
// Check parameters
// Put here code to add control on parameters values
// Update request
$sql = "UPDATE " . MAIN_DB_PREFIX . "mytable SET";
$sql.= " field1=" . (isset($this->field1) ? "'" . $this->db->escape($this->field1) . "'" : "null") . ",";
$sql.= " field2=" . (isset($this->field2) ? "'" . $this->db->escape($this->field2) . "'" : "null") . "";
$sql.= " WHERE rowid=" . $this->id;
$this->db->begin();
dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) {
$error ++;
$this->errors[] = "Error " . $this->db->lasterror();
}
if (! $error) {
if (! $notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action call a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR);
$this->error.=($this->error ? ', ' . $errmsg : $errmsg);
}
$this->db->rollback();
return -1 * $error;
} else {
$this->db->commit();
return 1;
}
}
/**
* Delete object in database
*
* @param User $user User that delete
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
public function delete($user, $notrigger = 0)
{
global $conf, $langs;
$error = 0;
$this->db->begin();
if (! $error) {
if (! $notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action call a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
if (! $error) {
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "mytable";
$sql.= " WHERE rowid=" . $this->id;
dol_syslog(__METHOD__ . " sql=" . $sql);
$resql = $this->db->query($sql);
if (! $resql) {
$error ++;
$this->errors[] = "Error " . $this->db->lasterror();
}
}
// Commit or rollback
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR);
$this->error.=($this->error ? ', ' . $errmsg : $errmsg);
}
$this->db->rollback();
return -1 * $error;
} else {
$this->db->commit();
return 1;
}
}
/**
* Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
{
global $user, $langs;
$error = 0;
$object = new SkeletonClass($this->db);
$this->db->begin();
// Load source object
$object->fetch($fromid);
$object->id = 0;
$object->statut = 0;
// Clear fields
// ...
// Create clone
$result = $object->create($user);
// Other options
if ($result < 0) {
$this->error = $object->error;
$error ++;
}
if (! $error) {
// Do something
}
// End
if (! $error) {
$this->db->commit();
return $object->id;
} else {
$this->db->rollback();
return -1;
}
}
/**
* Initialise object with example values
* Id must be 0 if object instance is a specimen
*
* @return void
*/
public function initAsSpecimen()
{
$this->id = 0;
$this->prop1 = 'prop1';
$this->prop2 = 'prop2';
}
}

View File

@@ -0,0 +1,607 @@
<?php
/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) ---Put here your own copyright and developer email---
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/modulebuilder/template/class/myobject.class.php
* \ingroup mymodule othermodule1 othermodule2
* \brief This file is an example for a CRUD class file (Create/Read/Update/Delete)
*/
// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
/**
* Class MyModuleObject
*
* Put here description of your class.
*/
class MyModuleObject extends CommonObject
{
/**
* @var string Id to identify managed object
*/
public $element = 'mymoduleobject';
/**
* @var string Name of table without prefix where object is stored
*/
public $table_element = 'mymoduleobject';
/**
* @var array Array with all fields and their property
*/
public $picto = 'generic';
/**
* @var array Array with all fields and their property
*/
public $fields;
/**
* @var mixed Sample property 1
*/
public $prop1;
/**
* @var mixed Sample property 2
*/
public $prop2;
//...
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $table_element_line = 'mymoduleobjectdet';
public $class_element_line = 'MyModuleObjectline';
public $fk_element = 'fk_mymoduleobject';
/**
* @var MyModuleObjectLine[] Lines
*/
public $lines = array();
/**
* Constructor
*
* @param DoliDb $db Database handler
*/
public function __construct(DoliDB $db)
{
$this->db = $db;
}
/**
* Create object into database
*
* @param User $user User that creates
* @param bool $notrigger false=launch triggers after, true=disable triggers
*
* @return int <0 if KO, Id of created object if OK
*/
public function create(User $user, $notrigger = false)
{
dol_syslog(__METHOD__, LOG_DEBUG);
$error = 0;
// Clean parameters
if (isset($this->prop1)) {
$this->prop1 = trim($this->prop1);
}
if (isset($this->prop2)) {
$this->prop2 = trim($this->prop2);
}
//...
// Check parameters
// Put here code to add control on parameters values
// Insert request
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
$sql .= ' field1,';
$sql .= ' field2';
//...
$sql .= ') VALUES (';
$sql .= ' \'' . $this->prop1 . '\',';
$sql .= ' \'' . $this->prop2 . '\'';
//...
$sql .= ')';
$this->db->begin();
$resql = $this->db->query($sql);
if (!$resql) {
$error ++;
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
}
if (!$error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
if (!$notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action to call a trigger.
//// Call triggers
//$result=$this->call_trigger('MYOBJECT_CREATE',$user);
//if ($result < 0) $error++;
//// End call triggers
}
}
// Commit or rollback
if ($error) {
$this->db->rollback();
return - 1 * $error;
} else {
$this->db->commit();
return $this->id;
}
}
/**
* Load object in memory from the database
*
* @param int $id Id object
* @param string $ref Ref
*
* @return int <0 if KO, 0 if not found, >0 if OK
*/
public function fetch($id, $ref = null)
{
dol_syslog(__METHOD__, LOG_DEBUG);
$sql = 'SELECT';
$sql .= ' t.rowid,';
$sql .= ' t.field1,';
$sql .= ' t.field2';
//...
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
$sql.= ' WHERE 1 = 1';
if (! empty($conf->multicompany->enabled)) {
$sql .= " AND entity IN (" . getEntity("mymoduleobject", 1) . ")";
}
if (null !== $ref) {
$sql .= ' AND t.ref = ' . '\'' . $ref . '\'';
} else {
$sql .= ' AND t.rowid = ' . $id;
}
$resql = $this->db->query($sql);
if ($resql) {
$numrows = $this->db->num_rows($resql);
if ($numrows) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->prop1 = $obj->field1;
$this->prop2 = $obj->field2;
//...
}
// Retrieve all extrafields for invoice
// fetch optionals attributes and labels
/*
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
*/
// $this->fetch_lines();
$this->db->free($resql);
if ($numrows) {
return 1;
} else {
return 0;
}
} else {
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
return - 1;
}
}
/**
* Load object in memory from the database
*
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param int $limit offset limit
* @param int $offset offset limit
* @param array $filter filter array
* @param string $filtermode filter mode (AND or OR)
*
* @return int <0 if KO, >0 if OK
*/
public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
{
dol_syslog(__METHOD__, LOG_DEBUG);
$sql = 'SELECT';
$sql .= ' t.rowid,';
$sql .= ' t.field1,';
$sql .= ' t.field2';
//...
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
}
}
$sql.= ' WHERE 1 = 1';
if (! empty($conf->multicompany->enabled)) {
$sql .= " AND entity IN (" . getEntity("mymoduleobject", 1) . ")";
}
if (count($sqlwhere) > 0) {
$sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere);
}
if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield,$sortorder);
}
if (!empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit, $offset);
}
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
while ($obj = $this->db->fetch_object($resql)) {
$line = new self($this->db);
$line->id = $obj->rowid;
$line->prop1 = $obj->field1;
$line->prop2 = $obj->field2;
//...
}
$this->db->free($resql);
return $num;
} else {
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
return - 1;
}
}
/**
* Update object into database
*
* @param User $user User that modifies
* @param bool $notrigger false=launch triggers after, true=disable triggers
*
* @return int <0 if KO, >0 if OK
*/
public function update(User $user, $notrigger = false)
{
dol_syslog(__METHOD__, LOG_DEBUG);
$error = 0;
// Clean parameters
if (isset($this->prop1)) {
$this->prop1 = trim($this->prop1);
}
if (isset($this->prop2)) {
$this->prop2 = trim($this->prop2);
}
//...
// Check parameters
// Put here code to add a control on parameters values
// Update request
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
$sql .= " field1=".(isset($this->field1)?"'".$this->db->escape($this->field1)."'":"null").",";
$sql .= " field2=".(isset($this->field2)?"'".$this->db->escape($this->field2)."'":"null")."";
//...
$sql .= ' WHERE rowid=' . $this->id;
$this->db->begin();
$resql = $this->db->query($sql);
if (!$resql) {
$error ++;
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
}
if (!$error && !$notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
//// Call triggers
//$result=$this->call_trigger('MYOBJECT_MODIFY',$user);
//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
//// End call triggers
}
// Commit or rollback
if ($error) {
$this->db->rollback();
return - 1 * $error;
} else {
$this->db->commit();
return 1;
}
}
/**
* Delete object in database
*
* @param User $user User that deletes
* @param bool $notrigger false=launch triggers after, true=disable triggers
*
* @return int <0 if KO, >0 if OK
*/
public function delete(User $user, $notrigger = false)
{
dol_syslog(__METHOD__, LOG_DEBUG);
$error = 0;
$this->db->begin();
if (!$error) {
if (!$notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
//// Call triggers
//$result=$this->call_trigger('MYOBJECT_DELETE',$user);
//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
//// End call triggers
}
}
// If you need to delete child tables to, you can insert them here
if (!$error) {
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
$sql .= ' WHERE rowid=' . $this->id;
$resql = $this->db->query($sql);
if (!$resql) {
$error ++;
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
}
}
// Commit or rollback
if ($error) {
$this->db->rollback();
return - 1 * $error;
} else {
$this->db->commit();
return 1;
}
}
/**
* Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
*
* @return int New id of clone
*/
public function createFromClone($fromid)
{
dol_syslog(__METHOD__, LOG_DEBUG);
global $user;
$error = 0;
$object = new MyModuleObject($this->db);
$this->db->begin();
// Load source object
$object->fetch($fromid);
// Reset object
$object->id = 0;
// Clear fields
// ...
// Create clone
$result = $object->create($user);
// Other options
if ($result < 0) {
$error ++;
$this->errors = $object->errors;
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
}
// End
if (!$error) {
$this->db->commit();
return $object->id;
} else {
$this->db->rollback();
return - 1;
}
}
/**
* Return a link to the object card (with optionaly the picto)
*
* @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
* @param string $option On what the link point to
* @param int $notooltip 1=Disable tooltip
* @param int $maxlen Max length of visible user name
* @param string $morecss Add more css on link
* @return string String with URL
*/
function getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
{
global $db, $conf, $langs;
global $dolibarr_main_authentication, $dolibarr_main_demo;
global $menumanager;
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
$result = '';
$companylink = '';
$label = '<u>' . $langs->trans("MyModule") . '</u>';
$label.= '<br>';
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
$url = DOL_URL_ROOT.'/mymodule/'.$this->table_name.'_card.php?id='.$this->id;
$linkclose='';
if (empty($notooltip))
{
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
$label=$langs->trans("ShowProject");
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
}
else $linkclose = ($morecss?' class="'.$morecss.'"':'');
$linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>';
$linkend='</a>';
if ($withpicto)
{
$result.=($linkstart.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend);
if ($withpicto != 2) $result.=' ';
}
$result.= $linkstart . $this->ref . $linkend;
return $result;
}
/**
* Retourne le libelle du status d'un user (actif, inactif)
*
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* @return string Label of status
*/
function getLibStatut($mode=0)
{
return $this->LibStatut($this->status,$mode);
}
/**
* Return the status
*
* @param int $status Id status
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto
* @return string Label of status
*/
static function LibStatut($status,$mode=0)
{
global $langs;
if ($mode == 0)
{
$prefix='';
if ($status == 1) return $langs->trans('Enabled');
if ($status == 0) return $langs->trans('Disabled');
}
if ($mode == 1)
{
if ($status == 1) return $langs->trans('Enabled');
if ($status == 0) return $langs->trans('Disabled');
}
if ($mode == 2)
{
if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
}
if ($mode == 3)
{
if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
}
if ($mode == 4)
{
if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
}
if ($mode == 5)
{
if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
}
if ($mode == 6)
{
if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
}
}
/**
* Initialise object with example values
* Id must be 0 if object instance is a specimen
*
* @return void
*/
public function initAsSpecimen()
{
$this->id = 0;
$this->prop1 = 'prop1';
$this->prop2 = 'prop2';
}
}
/**
* Class MyModuleObjectLine
*/
class MyModuleObjectLine
{
/**
* @var int ID
*/
public $id;
/**
* @var mixed Sample line property 1
*/
public $prop1;
/**
* @var mixed Sample line property 2
*/
public $prop2;
}

View File

@@ -0,0 +1,292 @@
<?php
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
use Luracast\Restler\RestException;
/**
* \file htdocs/modulebuilder/template/class/myobject_api_class.class.php
* \ingroup mymodule
* \brief File for API management of myobject.
*/
/**
* API class for mymodule myobject
*
* @smart-auto-routing false
* @access protected
* @class DolibarrApiAccess {@requires user,external}
*/
class MyObjectApi extends DolibarrApi
{
/**
* @var array $FIELDS Mandatory fields, checked when create and update object
*/
static $FIELDS = array(
'name'
);
/**
* @var MyObject $myobject {@type MyObject}
*/
public $myobject;
/**
* Constructor
*
* @url GET myobject/
*
*/
function __construct()
{
global $db, $conf;
$this->db = $db;
$this->myobject = new MyObject($this->db);
}
/**
* Get properties of a myobject object
*
* Return an array with myobject informations
*
* @param int $id ID of myobject
* @return array|mixed data without useless information
*
* @url GET myobject/{id}
* @throws RestException
*/
function get($id)
{
if(! DolibarrApiAccess::$user->rights->myobject->read) {
throw new RestException(401);
}
$result = $this->myobject->fetch($id);
if( ! $result ) {
throw new RestException(404, 'MyObject not found');
}
if( ! DolibarrApi::_checkAccessToResource('myobject',$this->myobject->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
return $this->_cleanObjectDatas($this->myobject);
}
/**
* List myobjects
*
* Get a list of myobjects
*
* @param int $mode Use this param to filter list
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101') or (t.import_key:=:'20160101')"
* @return array Array of myobject objects
*
* @url GET /myobjects/
*/
function index($mode, $sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
global $db, $conf;
$obj_ret = array();
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
// If the internal user must only see his customers, force searching by him
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
$sql = "SELECT s.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
$sql.= " FROM ".MAIN_DB_PREFIX."myobject as s";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
$sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
$sql.= " WHERE s.fk_stcomm = st.id";
// Example of use $mode
//if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
//if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
$sql.= ' AND s.entity IN ('.getEntity('myobject', 1).')';
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
if ($socid) $sql.= " AND s.fk_soc = ".$socid;
if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
// Insert sale filter
if ($search_sale > 0)
{
$sql .= " AND sc.fk_user = ".$search_sale;
}
if ($sqlfilters)
{
if (! DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
$sql.= $db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0)
{
$page = 0;
}
$offset = $limit * $page;
$sql.= $db->plimit($limit + 1, $offset);
}
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
{
$obj = $db->fetch_object($result);
$myobject_static = new MyObject($db);
if($myobject_static->fetch($obj->rowid)) {
$obj_ret[] = parent::_cleanObjectDatas($myobject_static);
}
$i++;
}
}
else {
throw new RestException(503, 'Error when retrieve myobject list');
}
if( ! count($obj_ret)) {
throw new RestException(404, 'No myobject found');
}
return $obj_ret;
}
/**
* Create myobject object
*
* @param array $request_data Request datas
* @return int ID of myobject
*
* @url POST myobject/
*/
function post($request_data = NULL)
{
if(! DolibarrApiAccess::$user->rights->myobject->create) {
throw new RestException(401);
}
// Check mandatory fields
$result = $this->_validate($request_data);
foreach($request_data as $field => $value) {
$this->myobject->$field = $value;
}
if( ! $this->myobject->create(DolibarrApiAccess::$user)) {
throw new RestException(500);
}
return $this->myobject->id;
}
/**
* Update myobject
*
* @param int $id Id of myobject to update
* @param array $request_data Datas
* @return int
*
* @url PUT myobject/{id}
*/
function put($id, $request_data = NULL)
{
if(! DolibarrApiAccess::$user->rights->myobject->create) {
throw new RestException(401);
}
$result = $this->myobject->fetch($id);
if( ! $result ) {
throw new RestException(404, 'MyObject not found');
}
if( ! DolibarrApi::_checkAccessToResource('myobject',$this->myobject->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
foreach($request_data as $field => $value) {
$this->myobject->$field = $value;
}
if($this->myobject->update($id, DolibarrApiAccess::$user))
return $this->get ($id);
return false;
}
/**
* Delete myobject
*
* @param int $id MyObject ID
* @return array
*
* @url DELETE myobject/{id}
*/
function delete($id)
{
if(! DolibarrApiAccess::$user->rights->myobject->supprimer) {
throw new RestException(401);
}
$result = $this->myobject->fetch($id);
if( ! $result ) {
throw new RestException(404, 'MyObject not found');
}
if( ! DolibarrApi::_checkAccessToResource('myobject',$this->myobject->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( !$this->myobject->delete($id))
{
throw new RestException(500);
}
return array(
'success' => array(
'code' => 200,
'message' => 'MyObject deleted'
)
);
}
/**
* Validate fields before create or update object
*
* @param array $data Data to validate
* @return array
*
* @throws RestException
*/
function _validate($data)
{
$myobject = array();
foreach (MyObjectApi::$FIELDS as $field) {
if (!isset($data[$field]))
throw new RestException(400, "$field field missing");
$myobject[$field] = $data[$field];
}
return $myobject;
}
}

View File

@@ -1,10 +1,11 @@
<?php
/* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) <year> <name of author>
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@capnetworks.com>
*
* This program is free software: you can redistribute it and/or modify
* 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 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@@ -13,309 +14,28 @@
* 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, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \defgroup mymodule MyModule module
* \brief MyModule module descriptor.
* \defgroup mymodule Module MyModule
* \brief MyModule module descriptor.
*
* Put detailed description here.
* \file htdocs/mymodule/core/modules/modMyModule.class.php
* \ingroup mymodule
* \brief Description and activation file for module MyModule
*/
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
/**
* \file core/modules/modMyModule.class.php
* \ingroup mymodule
* \brief Example module description and activation file.
*
* Put detailed description here.
*/
include_once DOL_DOCUMENT_ROOT . "/core/modules/DolibarrModules.class.php";
// The class name should start with a lower case mod for Dolibarr to pick it up
// so we ignore the Squiz.Classes.ValidClassName.NotCamelCaps rule.
// @codingStandardsIgnoreStart
/**
* Description and activation class for module MyModule
* Description and activation class for module MyModule
*/
class modMyModule extends DolibarrModules
{
/** @var DoliDB Database handler */
public $db;
/**
* @var int numero Module unique ID
* @see http://wiki.dolibarr.org/index.php/List_of_modules_id Available ranges
*/
public $numero = 500000;
/** @var string Text key to reference module (for permissions, menus, etc.) */
public $rights_class = 'mymodule';
/**
* @var string Module family.
* Used to group modules in module setup page.
* Can be one of 'crm', 'financial', 'hr', 'projects', 'products', 'ecm', 'technic', 'other'
*/
public $family = 'other';
/** @var int Module position in the family */
public $module_position = 500;
/** @var array Provide a custom family and options */
public $familyinfo = array(
// 'myownfamily' => array(
// 'position' => '001',
// 'label' => 'MyOwnFamily'
// )
);
/** @var string Module name */
public $name = "My Module";
/** @var string Module short description */
public $description = "Description of module MyModule";
/** @var string Module long description */
public $descriptionlong = "A very long description. Can be a full HTML content";
/**
* @var string Module editor name
* @since 4.0
*/
public $editor_name = "My Company";
/**
* @var string Module editor website
* @since 4.0
*/
public $editor_url = "http://www.example.com";
/**
* @var string Module version string
* Special values to hide the module behind MAIN_FEATURES_LEVEL: development, experimental
* @see https://semver.org
*/
public $version = 'development';
/** @var string Key used in llx_const table to save module status enabled/disabled */
public $const_name = 'MAIN_MODULE_MYMODULE';
/**
* @var string Module logo
* Should be named object_mymodule.png and store under mymodule/img
*/
public $picto = 'mymodule@mymodule';
/** @var array Define module parts */
public $module_parts = array(
/** @var bool Module ships triggers in mymodule/core/triggers */
'triggers' => true,
/**
* @var bool Module ships login in mymodule/core/login
* @todo: example
*/
'login' => false,
/**
* @var bool Module ships substitution functions
* @todo example
*/
'substitutions' => false,
/**
* @var bool Module ships menu handlers
* @todo example
*/
'menus' => false,
/**
* @var bool Module ships theme in mymodule/theme
* @todo example
*/
'theme' => false,
/**
* @var bool Module shipped templates in mymodule/core/tpl overload core ones
* @todo example
*/
'tpl' => false,
/**
* @var bool Module ships barcode functions
* @todo example
*/
'barcode' => false,
/**
* @var bool Module ships models
* @todo example
*/
'models' => false,
/** @var string[] List of module shipped custom CSS relative file paths */
'css' => array(
'mymodule/css/mycss.css.php'
),
/** @var string[] List of module shipped custom JavaScript relative file paths */
'js' => array(
'mymodule/js/myjs.js.php'
),
/**
* @var string[] List of hook contexts managed by the module
* @ todo example
*/
'hooks' => array(),
/**
* @var array List of default directory names to force
* @todo example
*/
'dir' => array(),
/**
* @var array List of workflow contexts managed by the module
*/
'workflow' => array(),
);
/** @var string Data directories to create when module is enabled */
public $dirs = array(
'/mymodule/temp'
);
/** @var array Configuration page declaration */
public $config_page_url = 'setup.php@mymodule';
/** @var bool Control module visibility */
public $hidden = false;
/** @var string[] List of class names of modules to enable when this one is enabled */
public $depends = array();
/** @var string[] List of class names of modules to disable when this one is disabled */
public $requiredby = array();
/** @var string List of class names of modules this module conflicts with */
public $conflictwith = array();
/** @var int[] Minimum PHP version required by this module */
public $phpmin = array(5, 3);
/** @var int[] Minimum Dolibarr version required by this module */
public $need_dolibarr_version = array(3, 2);
/** @var string[] List of language files */
public $langfiles = array('mymodule@mymodule');
/** @var array Indexed list of constants options */
public $const = array(
0 => array(
/** @var string Constant name */
'MYMODULE_MYNEWCONST1',
/**
* @var string Constant type
* @todo Are there other types than 'chaine'?
*/
'chaine',
/** @var string Constant initial value */
'myvalue',
/** @var string Constant description */
'This is a configuration constant',
/** @var bool Constant visibility */
true,
/**
* @var string Multi-company entities
* 'current' or 'allentities'
*/
'current',
/** @var bool Delete constant when module is disabled */
true
)
);
/**
* @var string List of pages to add as tab in a specific view
* @todo example
*/
public $tabs = array();
/**
* @var array Dictionaries declared by the module
*@todo example
*/
public $dictionaries = array();
/** @var array Indexed list of boxes options */
public $boxes = array(
0 => array(
'file' => 'mybox@mymodule',
'note' => '',
'enabledbydefaulton' => 'Home'
)
);
/**
* @var array Indexed list of cronjobs options
* @todo: example
*/
public $cronjobs = array();
/**
* @var array Indexed list of permissions options
* @todo example
*/
public $rights = array();
/**
* @var array Indexed list of menu options
* @todo example
*/
public $menu = array();
/**
* @var array Indexed list of export IDs
* @todo example
*/
public $export_code = array();
/**
* @var array Indexed list of export names
* @todo example
*/
public $export_label = array();
/**
* @var array Indexed list of export enabling conditions
* @todo example
*/
public $export_enabled = array();
/**
* @var array Indexed list of export required permissions
* @todo example
*/
public $export_permission = array();
/**
* @var array Indexed list of export fields
* @todo example
*/
public $export_fields_array = array();
/**
* @var array Indexed list of export entities
* @todo example
*/
public $export_entities_array = array();
/**
* @var array Indexed list of export SQL queries start
* @todo example
*/
public $export_sql_start = array();
/**
* @var array Indexed list of export SQL queries end
* @todo example
*/
public $export_sql_end = array();
/** @var bool Module only enabled / disabled in main company when multi-company is in use */
public $core_enabled = false;
// @codingStandardsIgnoreEnd
/**
* Constructor. Define names, constants, directories, boxes, permissions
@@ -324,61 +44,90 @@ class modMyModule extends DolibarrModules
*/
public function __construct($db)
{
global $langs, $conf;
global $langs,$conf;
// DolibarrModules is abstract in Dolibarr < 3.8
if (is_callable('parent::__construct')) {
parent::__construct($db);
} else {
global $db;
$this->db = $db;
}
$this->db = $db;
// Declare custom family with translated label
//$this->familyinfo = array(
// 'myownfamily' => array(
// 'position' => '001',
// 'label' => $langs->trans("MyOwnFamily")
// )
//);
// Id for module (must be unique).
// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
$this->numero = 500000; // TODO Go on page http://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module
// Key text used to identify module (for permissions, menus, etc...)
$this->rights_class = 'mymodule';
// Lazy automatic module naming from class names
//$this->name = preg_replace('/^mod/i', '', get_class($this));
// Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
// It is used to group modules by family in module setup page
$this->family = "other";
// Module position in the family
$this->module_position = 500;
// Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
//$this->familyinfo = array('myownfamily' => array('position' => '001', 'label' => $langs->trans("MyOwnFamily")));
// Lazy automatic constant naming from module name
//$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
$this->name = preg_replace('/^mod/i','',get_class($this));
// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
$this->description = "MyModuleDescription";
$this->descriptionlong = "MyModuleDescription (Long)";
$this->editor_name = 'Editor name';
$this->editor_url = 'https://www.example.com';
// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
$this->version = '1.0';
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
// Name of image file used for this module.
// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
$this->picto='generic';
// Examples for complex types
// Defined all module parts (triggers, login, substitutions, menus, css, etc...)
// for default path (eg: /mymodule/core/xxxxx) (0=disable, 1=enable)
// for specific path of parts (eg: /mymodule/core/modules/barcode)
// for specific css file (eg: /mymodule/css/mymodule.css.php)
//$this->module_parts = array(
// Set here all hooks context managed by module
// 'hooks' => array('hookcontext1','hookcontext2'),
// To force the default directories names
// 'dir' => array('output' => 'othermodulename'),
// Set here all workflow context managed by module
// Don't forget to depend on modWorkflow!
// The description translation key will be descWORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2
// You will be able to check if it is enabled with the $conf->global->WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2 constant
// Implementation is up to you and is usually done in a trigger.
// 'workflow' => array(
// 'WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2' => array(
// 'enabled' => '! empty($conf->module1->enabled) && ! empty($conf->module2->enabled)',
// 'picto' => 'yourpicto@mymodule',
// 'warning' => 'WarningTextTranslationKey',
// ),
// ),
//);
// 'triggers' => 0, // Set this to 1 if module has its own trigger directory (core/triggers)
// 'login' => 0, // Set this to 1 if module has its own login method directory (core/login)
// 'substitutions' => 0, // Set this to 1 if module has its own substitution function file (core/substitutions)
// 'menus' => 0, // Set this to 1 if module has its own menus handler directory (core/menus)
// 'theme' => 0, // Set this to 1 if module has its own theme directory (theme)
// 'tpl' => 0, // Set this to 1 if module overwrite template dir (core/tpl)
// 'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode)
// 'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx)
// 'css' => array('/mymodule/css/mymodule.css.php'), // Set this to relative path of css file if module has its own css file
// 'js' => array('/mymodule/js/mymodule.js'), // Set this to relative path of js file if module must load a js on all pages
// 'hooks' => array('hookcontext1','hookcontext2',...) // Set here all hooks context managed by module. You can also set hook context 'all'
// 'dir' => array('output' => 'othermodulename'), // To force the default directories names
// 'workflow' => array('WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2'=>array('enabled'=>'! empty($conf->module1->enabled) && ! empty($conf->module2->enabled)', 'picto'=>'yourpicto@mymodule')) // Set here all workflow context managed by module
// );
$this->module_parts = array();
// Data directories to create when module is enabled.
// Example: this->dirs = array("/mymodule/temp");
$this->dirs = array();
// Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module.
$this->config_page_url = array("setup.php@mymodule");
// Dependencies
$this->hidden = false; // A condition to hide module
$this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
$this->requiredby = array(); // List of module ids to disable if this one is disabled
$this->conflictwith = array(); // List of module class names as string this module is in conflict with
$this->phpmin = array(5,0); // Minimum version of PHP required by module
$this->need_dolibarr_version = array(3,0); // Minimum version of Dolibarr required by module
$this->langfiles = array("mymodule@mymodule");
// Constants
// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
// 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
// );
$this->const = array();
// Array to add new pages in new tabs
// Example:
//$this->tabs = array(
// // To add a new tab identified by code tabname1
// 'objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__',
// // To add another new tab identified by code tabname2
// 'objecttype:+tabname2:Title2:langfile@mymodule:$user->rights->othermodule->read:/mymodule/mynewtab2.php?id=__ID__',
// // To remove an existing tab identified by code tabname
// 'objecttype:-tabname'
//);
// Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__', // To add a new tab identified by code tabname1
// 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@mymodule:$user->rights->othermodule->read:/mymodule/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
// 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
// where objecttype can be
// 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
// 'contact' to add a tab in contact view
// 'contract' to add a tab in contract view
@@ -398,317 +147,142 @@ class modMyModule extends DolibarrModules
// 'stock' to add a tab in stock view
// 'thirdparty' to add a tab in third party view
// 'user' to add a tab in user view
$this->tabs = array();
// Dictionaries
if (! isset($conf->mymodule->enabled)) {
$conf->mymodule=new stdClass();
$conf->mymodule->enabled = 0;
}
//$this->dictionaries = array();
/* Example:
$this->dictionaries=array(
'langs'=>'mymodule@mymodule',
// List of tables we want to see into dictonary editor
'tabname'=>array(
MAIN_DB_PREFIX."table1",
MAIN_DB_PREFIX."table2",
MAIN_DB_PREFIX."table3"
),
// Label of tables
'tablib'=>array("Table1","Table2","Table3"),
// Query to select fields
'tabsql'=>array(
'SELECT f.rowid as rowid, f.code, f.label, f.active'
. ' FROM ' . MAIN_DB_PREFIX . 'table1 as f',
'SELECT f.rowid as rowid, f.code, f.label, f.active'
. ' FROM ' . MAIN_DB_PREFIX . 'table2 as f',
'SELECT f.rowid as rowid, f.code, f.label, f.active'
. ' FROM ' . MAIN_DB_PREFIX . 'table3 as f'
),
// Sort order
'tabsqlsort'=>array("label ASC","label ASC","label ASC"),
// List of fields (result of select to show dictionary)
'tabfield'=>array("code,label","code,label","code,label"),
// List of fields (list of fields to edit a record)
'tabfieldvalue'=>array("code,label","code,label","code,label"),
// List of fields (list of fields for insert)
'tabfieldinsert'=>array("code,label","code,label","code,label"),
// Name of columns with primary key (try to always name it 'rowid')
'tabrowid'=>array("rowid","rowid","rowid"),
// Condition to show each dictionary
'tabcond'=>array(
$conf->mymodule->enabled,
$conf->mymodule->enabled,
$conf->mymodule->enabled
)
);
*/
if (! isset($conf->mymodule) || ! isset($conf->mymodule->enabled))
{
$conf->mymodule=new stdClass();
$conf->mymodule->enabled=0;
}
// Dictionaries
$this->dictionaries=array();
/* Example:
$this->dictionaries=array(
'langs'=>'mylangfile@mymodule',
'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor
'tablib'=>array("Table1","Table2","Table3"), // Label of tables
'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), // Request to select fields
'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order
'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary)
'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record)
'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert)
'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid')
'tabcond'=>array($conf->mymodule->enabled,$conf->mymodule->enabled,$conf->mymodule->enabled) // Condition to show each dictionary
);
*/
// Boxes
// Add here list of php file(s) stored in core/boxes that contains class to show a box.
$this->boxes = array(); // List of boxes
// Example:
//$this->boxes=array(
// 0=>array('file'=>'myboxa.php@mymodule','note'=>'','enabledbydefaulton'=>'Home'),
// 1=>array('file'=>'myboxb.php@mymodule','note'=>''),
// 2=>array('file'=>'myboxc.php@mymodule','note'=>'')
//);
// Cronjobs
// List of cron jobs entries to add
//$this->cronjobs = array();
// Example:
// $this->cronjobs = array(
// 0 => array(
// 'label' => 'My label',
// 'jobtype' => 'method',
// 'class' => '/dir/class/file.class.php',
// 'objectname' => 'MyClass',
// 'method' => 'myMethod',
// 'parameters' => '',
// 'comment' => 'Comment',
// 'frequency' => 2,
// 'unitfrequency' => 3600,
// 'test' => true
// ),
// 1 => array(
// 'label' => 'My label',
// 'jobtype' => 'command',
// 'command' => '',
// 'parameters' => '',
// 'comment' => 'Comment',
// 'frequency' => 1,
// 'unitfrequency' => 3600 * 24,
// 'test' => true
// )
// );
$this->cronjobs = array(); // List of cron jobs entries to add
// Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'test'=>true),
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'test'=>true)
// );
// Permissions
//$r = 0;
// Add here list of permission defined by
// an id, a label, a boolean and two constant strings.
// Example:
//// Permission id (must not be already used)
//$this->rights[$r][0] = 2000;
//// Permission label
//$this->rights[$r][1] = 'Permision label';
//// Permission by default for new user (0/1)
//$this->rights[$r][3] = 1;
//// In php code, permission will be checked by test
//// if ($user->rights->permkey->level1->level2)
//$this->rights[$r][4] = 'level1';
//// In php code, permission will be checked by test
//// if ($user->rights->permkey->level1->level2)
//$this->rights[$r][5] = 'level2';
//$r++;
// Main menu entries
$this->rights = array(); // Permission array used by this module
$r=0;
// Menu entries
// Add here list of permission defined by an id, a label, a boolean and two constant strings.
// Example:
// $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
// $this->rights[$r][1] = 'Permision label'; // Permission label
// $this->rights[$r][3] = 1; // Permission by default for new user (0/1)
// $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
// $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
// $r++;
// Main menu entries
$this->menu = array(); // List of menus to add
$r=0;
// Add here entries to declare new menus
//
// Example to declare a new Top Menu entry and its Left menu entry:
//$this->menu[]=array(
// // Put 0 if this is a top menu
// 'fk_menu'=>0,
// // This is a Top menu entry
// 'type'=>'top',
// Menu's title. FIXME: use a translation key
// 'titre'=>'MyModule top menu',
// This menu's mainmenu ID
// 'mainmenu'=>'mymodule',
// This menu's leftmenu ID
// 'leftmenu'=>'mymodule',
// 'url'=>'/mymodule/pagetop.php',
// // Lang file to use (without .lang) by module.
// // File must be in langs/code_CODE/ directory.
// 'langs'=>'mylangfile',
// 'position'=>100,
// // Define condition to show or hide menu entry.
// // Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
// 'enabled'=>'$conf->mymodule->enabled',
// // Use 'perms'=>'$user->rights->mymodule->level1->level2'
// // if you want your menu with a permission rules
// 'perms'=>'1',
// 'target'=>'',
// // 0=Menu for internal users, 1=external users, 2=both
// 'user'=>2
//);
//$this->menu[]=array(
// // Use r=value where r is index key used for the parent menu entry
// // (higher parent must be a top menu entry)
// 'fk_menu'=>'r=0',
// // This is a Left menu entry
// 'type'=>'left',
// Menu's title. FIXME: use a translation key
// 'titre'=>'MyModule left menu',
// This menu's mainmenu ID
// 'mainmenu'=>'mymodule',
// This menu's leftmenu ID
// 'leftmenu'=>'mymodule',
// 'url'=>'/mymodule/pagelevel1.php',
// // Lang file to use (without .lang) by module.
// // File must be in langs/code_CODE/ directory.
// 'langs'=>'mylangfile',
// 'position'=>100,
// // Define condition to show or hide menu entry.
// // Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
// 'enabled'=>'$conf->mymodule->enabled',
// // Use 'perms'=>'$user->rights->mymodule->level1->level2'
// // if you want your menu with a permission rules
// 'perms'=>'1',
// 'target'=>'',
// // 0=Menu for internal users, 1=external users, 2=both
// 'user'=>2
//);
// $this->menu[$r]=array( 'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
// 'type'=>'top', // This is a Top menu entry
// 'titre'=>'MyModule top menu',
// 'mainmenu'=>'mymodule',
// 'leftmenu'=>'mymodule',
// 'url'=>'/mymodule/pagetop.php',
// 'langs'=>'mylangfile@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
// 'position'=>100,
// 'enabled'=>'$conf->mymodule->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
// 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
// 'target'=>'',
// 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
// $r++;
//
// Example to declare a Left Menu entry into an existing Top menu entry:
//$this->menu[]=array(
// // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy'
// 'fk_menu'=>'fk_mainmenu=mainmenucode',
// // This is a Left menu entry
// 'type'=>'left',
// Menu's title. FIXME: use a translation key
// 'titre'=>'MyModule left menu',
// This menu's mainmenu ID
// 'mainmenu'=>'mainmenucode',
// This menu's leftmenu ID
// 'leftmenu'=>'mymodule',
// 'url'=>'/mymodule/pagelevel2.php',
// // Lang file to use (without .lang) by module.
// // File must be in langs/code_CODE/ directory.
// 'langs'=>'mylangfile',
// 'position'=>100,
// // Define condition to show or hide menu entry.
// // Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
// // Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
// 'enabled'=>'$conf->mymodule->enabled',
// // Use 'perms'=>'$user->rights->mymodule->level1->level2'
// // if you want your menu with a permission rules
// 'perms'=>'1',
// 'target'=>'',
// // 0=Menu for internal users, 1=external users, 2=both
// 'user'=>2
//);
// $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=xxx', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
// 'type'=>'left', // This is a Left menu entry
// 'titre'=>'MyModule left menu',
// 'mainmenu'=>'xxx',
// 'leftmenu'=>'mymodule',
// 'url'=>'/mymodule/pagelevel2.php',
// 'langs'=>'mylangfile@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
// 'position'=>100,
// 'enabled'=>'$conf->mymodule->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
// 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
// 'target'=>'',
// 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
// $r++;
// Exports
//$r = 0;
$r=1;
// Example:
//$this->export_code[$r]=$this->rights_class.'_'.$r;
//// Translation key (used only if key ExportDataset_xxx_z not found)
//$this->export_label[$r]='CustomersInvoicesAndInvoiceLines';
//// Condition to show export in list (ie: '$user->id==3').
//// Set to 1 to always show when module is enabled.
//$this->export_enabled[$r]='1';
//$this->export_permission[$r]=array(array("facture","facture","export"));
//$this->export_fields_array[$r]=array(
// 's.rowid'=>"IdCompany",
// 's.nom'=>'CompanyName',
// 's.address'=>'Address',
// 's.cp'=>'Zip',
// 's.ville'=>'Town',
// 's.fk_pays'=>'Country',
// 's.tel'=>'Phone',
// 's.siren'=>'ProfId1',
// 's.siret'=>'ProfId2',
// 's.ape'=>'ProfId3',
// 's.idprof4'=>'ProfId4',
// 's.code_compta'=>'CustomerAccountancyCode',
// 's.code_compta_fournisseur'=>'SupplierAccountancyCode',
// 'f.rowid'=>"InvoiceId",
// 'f.facnumber'=>"InvoiceRef",
// 'f.datec'=>"InvoiceDateCreation",
// 'f.datef'=>"DateInvoice",
// 'f.total'=>"TotalHT",
// 'f.total_ttc'=>"TotalTTC",
// 'f.tva'=>"TotalVAT",
// 'f.paye'=>"InvoicePaid",
// 'f.fk_statut'=>'InvoiceStatus',
// 'f.note'=>"InvoiceNote",
// 'fd.rowid'=>'LineId',
// 'fd.description'=>"LineDescription",
// 'fd.price'=>"LineUnitPrice",
// 'fd.tva_tx'=>"LineVATRate",
// 'fd.qty'=>"LineQty",
// 'fd.total_ht'=>"LineTotalHT",
// 'fd.total_tva'=>"LineTotalTVA",
// 'fd.total_ttc'=>"LineTotalTTC",
// 'fd.date_start'=>"DateStart",
// 'fd.date_end'=>"DateEnd",
// 'fd.fk_product'=>'ProductId',
// 'p.ref'=>'ProductRef'
//);
//$this->export_entities_array[$r]=array('s.rowid'=>"company",
// 's.nom'=>'company',
// 's.address'=>'company',
// 's.cp'=>'company',
// 's.ville'=>'company',
// 's.fk_pays'=>'company',
// 's.tel'=>'company',
// 's.siren'=>'company',
// 's.siret'=>'company',
// 's.ape'=>'company',
// 's.idprof4'=>'company',
// 's.code_compta'=>'company',
// 's.code_compta_fournisseur'=>'company',
// 'f.rowid'=>"invoice",
// 'f.facnumber'=>"invoice",
// 'f.datec'=>"invoice",
// 'f.datef'=>"invoice",
// 'f.total'=>"invoice",
// 'f.total_ttc'=>"invoice",
// 'f.tva'=>"invoice",
// 'f.paye'=>"invoice",
// 'f.fk_statut'=>'invoice',
// 'f.note'=>"invoice",
// 'fd.rowid'=>'invoice_line',
// 'fd.description'=>"invoice_line",
// 'fd.price'=>"invoice_line",
// 'fd.total_ht'=>"invoice_line",
// 'fd.total_tva'=>"invoice_line",
// 'fd.total_ttc'=>"invoice_line",
// 'fd.tva_tx'=>"invoice_line",
// 'fd.qty'=>"invoice_line",
// 'fd.date_start'=>"invoice_line",
// 'fd.date_end'=>"invoice_line",
// 'fd.fk_product'=>'product',
// 'p.ref'=>'product'
//);
//$this->export_sql_start[$r] = 'SELECT DISTINCT ';
//$this->export_sql_end[$r] = ' FROM (' . MAIN_DB_PREFIX . 'facture as f, '
// . MAIN_DB_PREFIX . 'facturedet as fd, ' . MAIN_DB_PREFIX . 'societe as s)';
//$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX
// . 'product as p on (fd.fk_product = p.rowid)';
//$this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid '
// . 'AND f.rowid = fd.fk_facture';
//$r++;
// $this->export_code[$r]=$this->rights_class.'_'.$r;
// $this->export_label[$r]='MyModule'; // Translation key (used only if key ExportDataset_xxx_z not found)
// $this->export_enabled[$r]='1'; // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled.
// $this->export_icon[$r]='generic:MyModule'; // Put here code of icon then string for translation key of module name
// $this->export_permission[$r]=array(array("mymodule","level1","level2"));
// $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef');
// $this->export_TypeFields_array[$r]=array('t.date'=>'Date', 't.qte'=>'Numeric', 't.poids'=>'Numeric', 't.fad'=>'Numeric', 't.paq'=>'Numeric', 't.stockage'=>'Numeric', 't.fadparliv'=>'Numeric', 't.livau100'=>'Numeric', 't.forfait'=>'Numeric', 's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text','f.facnumber'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>"Date",'f.total'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_private'=>"Text",'f.note_public'=>"Text",'fd.description'=>"Text",'fd.subprice'=>"Numeric",'fd.tva_tx'=>"Numeric",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_tva'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.date_start'=>"Date",'fd.date_end'=>"Date",'fd.special_code'=>'Numeric','fd.product_type'=>"Numeric",'fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text','p.accountancy_code_sell'=>'Text');
// $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product');
// $this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
// $this->export_sql_start[$r]='SELECT DISTINCT ';
// $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
// $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
// $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
// $this->export_sql_order[$r] .=' ORDER BY s.nom';
// $r++;
}
/**
* Function called when module is enabled.
* The init function add constants, boxes, permissions and menus
* (defined in constructor) into Dolibarr database.
* It also creates data directories
* Function called when module is enabled.
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
* It also creates data directories
*
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
public function init($options = '')
public function init($options='')
{
$sql = array();
$result = $this->loadTables();
$this->_load_tables('/mymodule/sql/');
return $this->_init($sql, $options);
}
/**
* Create tables, keys and data required by module
* Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys
* and create data commands must be stored in directory /mymodule/sql/
* This function is called by this->init
*
* @return int <=0 if KO, >0 if OK
*/
private function loadTables()
{
return $this->_load_tables('/mymodule/sql/');
}
/**
* Function called when module is disabled.
* Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted
*
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
public function remove($options = '')
{
@@ -716,4 +290,5 @@ class modMyModule extends DolibarrModules
return $this->_remove($sql, $options);
}
}

View File

@@ -17,7 +17,7 @@
*/
/**
* \file core/triggers/interface_99_modMyModule_MyTrigger.class.php
* \file core/triggers/interface_99_modMyModule_Triggers.class.php
* \ingroup mymodule
* \brief Example trigger.
*
@@ -30,17 +30,16 @@
* - The file must stay in core/triggers
* - The class name must be InterfaceMytrigger
* - The constructor method must be named InterfaceMytrigger
* - The name property name must be Mytrigger
* - The name property name must be MyTrigger
*/
/** Includes */
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT . dol_buildpath('/mymodule/class/MyTrigger.php', 1);
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
/**
* Class InterfaceMytrigger
* Class of triggers for MyModule module
*/
class InterfaceMytrigger extends MyTrigger
class InterfaceMyModuleTrigger extends DolibarrTriggers
{
/**
* @var DoliDB Database handler
@@ -58,9 +57,7 @@ class InterfaceMytrigger extends MyTrigger
$this->name = preg_replace('/^Interface/i', '', get_class($this));
$this->family = "demo";
$this->description = "Triggers of this module are empty functions."
. "They have no effect."
. "They are provided for tutorial purpose only.";
$this->description = "MyModule triggers.";
// 'development', 'experimental', 'dolibarr' or version
$this->version = 'development';
$this->picto = 'mymodule@mymodule';
@@ -86,58 +83,18 @@ class InterfaceMytrigger extends MyTrigger
return $this->description;
}
/**
* Trigger version
*
* @return string Version of trigger file
*/
public function getVersion()
{
global $langs;
$langs->load("admin");
if ($this->version == 'development') {
return $langs->trans("Development");
} elseif ($this->version == 'experimental') {
return $langs->trans("Experimental");
} elseif ($this->version == 'dolibarr') {
return DOL_VERSION;
} elseif ($this->version) {
return $this->version;
} else {
return $langs->trans("Unknown");
}
}
// @codingStandardsIgnoreStart
/**
* Compatibility trigger function for Dolibarr < 3.7
*
* @param int $action Trigger action
* @param CommonObject $object Object trigged from
* @param User $user User that trigged
* @param Translate $langs Translations handler
* @param Conf $conf Configuration
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
* @deprecated Replaced by DolibarrTriggers::runTrigger()
*/
public function run_trigger($action, $object, $user, $langs, $conf)
{
return $this->runTrigger($action, $object, $user, $langs, $conf);
}
// @codingStandardsIgnoreEnd
/**
* Function called when a Dolibarrr business event is done.
* All functions "runTrigger" are triggered if file
* is inside directory core/triggers
*
* @param string $action Event action code
* @param CommonObject $object Object
* @param User $user Object user
* @param Translate $langs Object langs
* @param Conf $conf Object conf
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
* @param string $action Event action code
* @param CommonObject $object Object
* @param User $user Object user
* @param Translate $langs Object langs
* @param Conf $conf Object conf
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
*/
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
{

View File

Before

Width:  |  Height:  |  Size: 360 B

After

Width:  |  Height:  |  Size: 360 B

View File

@@ -17,7 +17,7 @@
*/
/**
* \file js/mymodule.js.php
* \file htdocs/modulebuilder/template/js/mymodule.js.php
* \ingroup mymodule
* \brief Example JavaScript.
*

View File

@@ -1,10 +1,10 @@
<?php
/* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) <year> <name of author>
/* Copyright (C) 2007-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) ---Put here your own copyright and developer email---
*
* This program is free software: you can redistribute it and/or modify
* 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 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@@ -13,21 +13,20 @@
* 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, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file myobject_list.php
* \ingroup mymodule
* \brief Page with list of myobject.
*
* List of myobject
* \file htdocs/modulebuilder/template/myobject_card.php
* \ingroup mymodule othermodule1 othermodule2
* \brief This file is an example of a php page
* Put here some comments
*/
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check anti CSRF attack test
//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not check anti POST attack test
@@ -36,28 +35,31 @@
//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
// Change the following lines to use the correct relative path (../, ../../, etc)
// Change this following line to use the correct relative path (../, ../../, etc)
$res=0;
if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php'; // to work if your module directory is into dolibarr root htdocs directory
if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory
if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
if (! $res) die("Include of main fails");
// Change this following line to use the correct relative path from htdocs
include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
dol_include_once('/mymodule/class/myobject_class.class.php');
// Load Dolibarr environment
if (false === (@include '../../main.inc.php')) { // From htdocs directory
require '../../../main.inc.php'; // From "custom" directory
}
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
dol_include_once('/mymodule/class/myclass.class.php');
// Load translation files required by the page
$langs->load("mymodule@mymodule");
// Load traductions files requiredby by page
$langs->load("mymodule");
$langs->load("other");
// Get parameters
$action = GETPOST('action','alpha');
$confirm = GETPOST('confirm','alpha');
$id = GETPOST('id','int');
$action = GETPOST('action','alpha');
$cancel = GETPOST('cancel');
$backtopage = GETPOST('backtopage');
// TODO Add here list of search params
$myparam = GETPOST('myparam','alpha');
$search_field1=GETPOST("search_field1");
$search_field2=GETPOST("search_field2");
if (empty($action) && empty($id) && empty($ref)) $action='view';
// Protection if external user
@@ -67,7 +69,8 @@ if ($user->societe_id > 0)
}
//$result = restrictedArea($user, 'mymodule', $id);
$object = new Skeleton_Class($db);
$object = new MyObject_Class($db);
$extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
@@ -77,7 +80,8 @@ $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
// Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('skeleton'));
$hookmanager->initHooks(array('mymodule'));
/*
@@ -86,7 +90,6 @@ $hookmanager->initHooks(array('skeleton'));
* Put here all code to do according to value of "action" parameter
*/
$parameters=array();
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
@@ -206,15 +209,16 @@ if (empty($reshook))
/*
* VIEW
*
* Put here all code to build page
*/
$form = new Form($db);
$form=new Form($db);
llxHeader('', $langs->trans('MyPageName'), '');
llxHeader('','MyPageName','');
// Put here content of your page
@@ -293,54 +297,308 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
{
$res = $object->fetch_optionals($object->id, $extralabels);
$head = commande_prepare_head($object);
dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), 0, 'order');
$head = mymodule_prepare_head($object);
dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), -1, 'order');
print load_fiche_titre($langs->trans("MyModule"));
dol_fiche_head();
$formconfirm = '';
// Confirmation to delete
if ($action == 'delete') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteMyOjbect'), $langs->trans('ConfirmDeleteMyObject'), 'confirm_delete', '', 0, 1);
print $formconfirm;
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
}
// Confirmation of action xxxx
if ($action == 'xxx')
{
$formquestion=array();
/*
$formquestion = array(
// 'text' => $langs->trans("ConfirmClone"),
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
// array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1)));
}*/
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
}
if (! $formconfirm) {
$parameters = array('lineid' => $lineid);
$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
}
// Print form confirm
print $formconfirm;
// Object card
// ------------------------------------------------------------
$linkback = '<a href="' . DOL_URL_ROOT . '/mymodule/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
$morehtmlref='<div class="refidno">';
/*
// Ref bis
$morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', 0, 1);
$morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mymodule->creer, 'string', '', null, null, '', 1);
// Thirdparty
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
// Project
if (! empty($conf->projet->enabled))
{
$langs->load("projects");
$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
if ($user->rights->mymodule->creer)
{
if ($action != 'classify')
{
$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
if ($action == 'classify') {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref.='<input type="hidden" name="action" value="classin">';
$morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref.='</form>';
} else {
$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
}
}
} else {
if (! empty($object->fk_project)) {
$proj = new Project($db);
$proj->fetch($object->fk_project);
$morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
$morehtmlref.=$proj->ref;
$morehtmlref.='</a>';
} else {
$morehtmlref.='';
}
}
}
*/
$morehtmlref.='</div>';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">'."\n";
// print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
// LIST_OF_TD_LABEL_FIELDS_VIEW
// Other attributes
$cols = 2;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '</table>';
print '</div>';
print '<div class="fichehalfright">';
print '<div class="ficheaddleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">';
print '</table>';
print '</div>';
print '</div>';
print '</div>';
print '<div class="clearboth"></div><br>';
dol_fiche_end();
// Buttons
print '<div class="tabsAction">'."\n";
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook))
{
if ($user->rights->mymodule->write)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
}
if ($user->rights->mymodule->delete)
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
}
// Buttons for actions
if ($action != 'presend' && $action != 'editline') {
print '<div class="tabsAction">'."\n";
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook))
{
if ($user->rights->mymodule->write)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>'."\n";
}
if ($user->rights->mymodule->delete)
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>'."\n";
}
}
print '</div>'."\n";
}
print '</div>'."\n";
// Select mail models is same action as presend
if (GETPOST('modelselected')) {
$action = 'presend';
}
if ($action != 'presend')
{
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre
// Documents
$comref = dol_sanitizeFileName($object->ref);
$relativepath = $comref . '/' . $comref . '.pdf';
$filedir = $conf->mymodule->dir_output . '/' . $comref;
$urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
$genallowed = $user->rights->mymodule->creer;
$delallowed = $user->rights->mymodule->supprimer;
print $formfile->showdocuments('mymodule', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
// Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
print '</div><div class="fichehalfright"><div class="ficheaddleft">';
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
$formactions = new FormActions($db);
$somethingshown = $formactions->showactions($object, 'order', $socid);
print '</div></div></div>';
}
// Example 2 : Adding links to objects
// Show links to link elements
//$linktoelem = $form->showLinkToObjectBlock($object, null, array('skeleton'));
//$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
/*
* Action presend
*/
/*
if ($action == 'presend')
{
$object->fetch_projet();
$ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (!empty($newlang))
{
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($newlang);
$outputlangs->load('commercial');
}
// Build document if it not exists
if (! $file || ! is_readable($file)) {
$result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) {
dol_print_error($db, $object->error, $object->errors);
exit();
}
$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
$file = $fileparams['fullname'];
}
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
print '<div class="clearboth"></div>';
print '<br>';
print load_fiche_titre($langs->trans('SendOrderByMail'));
dol_fiche_head('');
// Cree l'objet formulaire mail
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
$formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
if($formmail->fromtype === 'user'){
$formmail->fromid = $user->id;
}
$formmail->trackid='ord'.$object->id;
if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
{
include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id);
}
$formmail->withfrom = 1;
$liste = array();
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value)
$liste [$key] = $value;
$formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
$formmail->withtocc = $liste;
$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
if (empty($object->ref_client)) {
$formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__');
} else if (! empty($object->ref_client)) {
$formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__ (__REFCLIENT__)');
}
$formmail->withfile = 2;
$formmail->withbody = 1;
$formmail->withdeliveryreceipt = 1;
$formmail->withcancel = 1;
// Tableau des substitutions
$formmail->setSubstitFromObject($object);
$formmail->substit ['__ORDERREF__'] = $object->ref;
$custcontact = '';
$contactarr = array();
$contactarr = $object->liste_contact(- 1, 'external');
if (is_array($contactarr) && count($contactarr) > 0)
{
foreach ($contactarr as $contact)
{
if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) { // TODO Use code and not label
$contactstatic = new Contact($db);
$contactstatic->fetch($contact ['id']);
$custcontact = $contactstatic->getFullName($langs, 1);
}
}
if (! empty($custcontact)) {
$formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
}
}
// Tableau des parametres complementaires
$formmail->param['action'] = 'send';
$formmail->param['models'] = 'order_send';
$formmail->param['models_id']=GETPOST('modelmailselected','int');
$formmail->param['orderid'] = $object->id;
$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
// Init list of files
if (GETPOST("mode") == 'init') {
$formmail->clear_attached_files();
$formmail->add_attached_files($file, basename($file), dol_mimetype($file));
}
// Show form
print $formmail->get_form();
dol_fiche_end();
}*/
}
// End of page
llxFooter();
$db->close();

View File

@@ -1,10 +1,10 @@
<?php
/* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) <year> <name of author>
/* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) ---Put here your own copyright and developer email---
*
* This program is free software: you can redistribute it and/or modify
* 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 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@@ -13,21 +13,20 @@
* 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, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file myobject_list.php
* \ingroup mymodule
* \brief Page with list of myobject.
*
* List of myobject
* \file htdocs/modulebuilder/template/myobject_list.php
* \ingroup mymodule othermodule1 othermodule2
* \brief This file is an example of a php page
* Put here some comments
*/
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check anti CSRF attack test
//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not check anti POST attack test
@@ -36,31 +35,39 @@
//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
// Change the following lines to use the correct relative path (../, ../../, etc)
// Load Dolibarr environment
if (false === (@include '../../main.inc.php')) { // From htdocs directory
require '../../../main.inc.php'; // From "custom" directory
}
// Change this following line to use the correct relative path (../, ../../, etc)
$res=0;
if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php'; // to work if your module directory is into dolibarr root htdocs directory
if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory
if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
if (! $res) die("Include of main fails");
// Change this following line to use the correct relative path from htdocs
require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
dol_include_once('/mymodule/class/myclass.class.php');
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
dol_include_once('/mymodule/class/skeleton_class.class.php');
// Load translation files required by the page
$langs->load("mymodule@mymodule");
// Load traductions files requiredby by page
$langs->load("mymodule");
$langs->load("other");
// Get parameters
$action = GETPOST('action','alpha');
$massaction = GETPOST('massaction','alpha');
$show_files = GETPOST('show_files','int');
$confirm = GETPOST('confirm','alpha');
$toselect = GETPOST('toselect', 'array');
$action=GETPOST('action','alpha');
$massaction=GETPOST('massaction','alpha');
$show_files=GETPOST('show_files','int');
$confirm=GETPOST('confirm','alpha');
$toselect = GETPOST('toselect', 'array');
$id = GETPOST('id','int');
$backtopage = GETPOST('backtopage');
// TODO Add here list of search params
$myparam = GETPOST('myparam','alpha');
$search_all=trim(GETPOST("sall"));
$search_field1=GETPOST("search_field1");
$search_field2=GETPOST("search_field2");
$search_myfield=GETPOST('search_myfield');
$optioncss = GETPOST('optioncss','alpha');
// Load variable for pagination
$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
$sortfield = GETPOST('sortfield','alpha');
@@ -74,11 +81,12 @@ if (! $sortfield) $sortfield="t.rowid"; // Set here default search field
if (! $sortorder) $sortorder="ASC";
// Protection if external user
$socid=0;
if ($user->societe_id > 0)
{
$socid = $user->societe_id;
//accessforbidden();
}
//$result = restrictedArea($user, 'mymodule', $id);
// Initialize technical object to manage context to save list fields
$contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'mymodulelist';
@@ -87,14 +95,41 @@ $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'mymoduleli
$hookmanager->initHooks(array('mymodulelist'));
$extrafields = new ExtraFields($db);
// Load object if id or ref is provided as parameter
$object = new MyClass($db);
if (($id > 0 || ! empty($ref)) && $action != 'add') {
$result = $object->fetch($id, $ref);
if ($result < 0) dol_print_error($db);
// fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label('mymodule');
$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array(
't.ref'=>'Ref',
't.note_public'=>'NotePublic',
);
if (empty($user->socid)) $fieldstosearchall["t.note_private"]="NotePrivate";
// Definition of fields for list
$arrayfields=array(
't.field1'=>array('label'=>"Field1", 'checked'=>1),
't.field2'=>array('label'=>"Field2", 'checked'=>1),
//'t.entity'=>array('label'=>"Entity", 'checked'=>1, 'enabled'=>(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode))),
't.datec'=>array('label'=>"DateCreationShort", 'checked'=>0, 'position'=>500),
't.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
//'t.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
);
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{
foreach($extrafields->attribute_label as $key => $val)
{
$arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
}
}
$object=new Skeleton_Class($db);
/*
* ACTIONS
*
@@ -116,10 +151,10 @@ if (empty($reshook))
// Purge search criteria
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") ||GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
{
$search_field1='';
$search_field2='';
$search_date_creation='';
$search_date_update='';
$search_field1='';
$search_field2='';
$search_date_creation='';
$search_date_update='';
$toselect='';
$search_array_options=array();
}
@@ -134,18 +169,24 @@ if (empty($reshook))
}
/*
* VIEW
*
* Put here all code to build page
*/
llxHeader('', $langs->trans('MyPageName'), '');
$now=dol_now();
$form = new Form($db);
$form=new Form($db);
//$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
$help_url='';
$title = $langs->trans('MyModuleListTitle');
// Put here content of your page
// Example 1: Adding jquery code
// Example : Adding jquery code
print '<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
function init_myfunc()
@@ -161,15 +202,368 @@ jQuery(document).ready(function() {
</script>';
$sql = "SELECT";
$sql.= " t.rowid,";
$sql.= " t.field1,";
$sql.= " t.field2";
// Add fields from extrafields
foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
// Add fields from hooks
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
$sql.= " FROM ".MAIN_DB_PREFIX."mytable as t";
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."mytable_extrafields as ef on (t.rowid = ef.fk_object)";
$sql.= " WHERE 1 = 1";
//$sql.= " WHERE u.entity IN (".getEntity('mytable',1).")";
if ($search_field1) $sql.= natural_search("field1",$search_field1);
if ($search_field2) $sql.= natural_search("field2",$search_field2);
if ($sall) $sql.= natural_search(array_keys($fieldstosearchall), $sall);
// Add where from extra fields
foreach ($search_array_options as $key => $val)
{
$crit=$val;
$tmpkey=preg_replace('/search_options_/','',$key);
$typ=$extrafields->attribute_type[$tmpkey];
$mode=0;
if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
{
$sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
}
}
// Add where from hooks
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
$sql.=$db->order($sortfield,$sortorder);
// TODO
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
}
$sql.= $db->plimit($limit+1, $offset);
dol_syslog($script_file, LOG_DEBUG);
$resql=$db->query($sql);
if (! $resql)
{
dol_print_error($db);
exit;
}
$num = $db->num_rows($resql);
// Direct jump if only one record found
if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
{
$obj = $db->fetch_object($resql);
$id = $obj->rowid;
header("Location: ".DOL_URL_ROOT.'/skeleton/card.php?id='.$id);
exit;
}
llxHeader('', $title, $help_url);
$arrayofselected=is_array($toselect)?$toselect:array();
$param='';
if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
if ($search_field1 != '') $param.= '&amp;search_field1='.urlencode($search_field1);
if ($search_field2 != '') $param.= '&amp;search_field2='.urlencode($search_field2);
if ($optioncss != '') $param.='&optioncss='.$optioncss;
// Add $param from extra fields
foreach ($search_array_options as $key => $val)
{
$crit=$val;
$tmpkey=preg_replace('/search_options_/','',$key);
if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
}
$arrayofmassactions = array(
'presend'=>$langs->trans("SendByMail"),
'builddoc'=>$langs->trans("PDFMerge"),
);
if ($user->rights->mymodule->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
if ($massaction == 'presend') $arrayofmassactions=array();
$massactionbutton=$form->selectMassAction('', $arrayofmassactions);
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
if ($sall)
{
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
}
$moreforfilter = '';
$moreforfilter.='<div class="divsearchfield">';
$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
$moreforfilter.= '</div>';
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
else $moreforfilter = $hookmanager->resPrint;
if (! empty($moreforfilter))
{
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print $moreforfilter;
print '</div>';
}
$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
// Fields title
print '<tr class="liste_titre">';
// LIST_OF_TD_TITLE_FIELDS
//if (! empty($arrayfields['t.field1']['checked'])) print_liste_field_titre($arrayfields['t.field1']['label'],$_SERVER['PHP_SELF'],'t.field1','',$param,'',$sortfield,$sortorder);
//if (! empty($arrayfields['t.field2']['checked'])) print_liste_field_titre($arrayfields['t.field2']['label'],$_SERVER['PHP_SELF'],'t.field2','',$param,'',$sortfield,$sortorder);
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{
foreach($extrafields->attribute_label as $key => $val)
{
if (! empty($arrayfields["ef.".$key]['checked']))
{
$align=$extrafields->getAlignFlag($key);
$sortonfield = "ef.".$key;
if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
}
}
}
// Hook fields
$parameters=array('arrayfields'=>$arrayfields);
$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (! empty($arrayfields['t.datec']['checked'])) print_liste_field_titre($arrayfields['t.datec']['label'],$_SERVER["PHP_SELF"],"t.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
if (! empty($arrayfields['t.tms']['checked'])) print_liste_field_titre($arrayfields['t.tms']['label'],$_SERVER["PHP_SELF"],"t.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
//if (! empty($arrayfields['t.status']['checked'])) print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"t.status","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
print '</tr>'."\n";
// Fields title search
print '<tr class="liste_titre">';
// LIST_OF_TD_TITLE_SEARCH
//if (! empty($arrayfields['t.field1']['checked'])) print '<td class="liste_titre"><input type="text" class="flat" name="search_field1" value="'.$search_field1.'" size="10"></td>';
//if (! empty($arrayfields['t.field2']['checked'])) print '<td class="liste_titre"><input type="text" class="flat" name="search_field2" value="'.$search_field2.'" size="10"></td>';
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{
foreach($extrafields->attribute_label as $key => $val)
{
if (! empty($arrayfields["ef.".$key]['checked']))
{
$align=$extrafields->getAlignFlag($key);
$typeofextrafield=$extrafields->attribute_type[$key];
print '<td class="liste_titre'.($align?' '.$align:'').'">';
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key]))
{
$crit=$val;
$tmpkey=preg_replace('/search_options_/','',$key);
$searchclass='';
if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
}
print '</td>';
}
}
}
// Fields from hook
$parameters=array('arrayfields'=>$arrayfields);
$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (! empty($arrayfields['t.datec']['checked']))
{
// Date creation
print '<td class="liste_titre">';
print '</td>';
}
if (! empty($arrayfields['t.tms']['checked']))
{
// Date modification
print '<td class="liste_titre">';
print '</td>';
}
/*if (! empty($arrayfields['u.statut']['checked']))
{
// Status
print '<td class="liste_titre" align="center">';
print $form->selectarray('search_statut', array('-1'=>'','0'=>$langs->trans('Disabled'),'1'=>$langs->trans('Enabled')),$search_statut);
print '</td>';
}*/
// Action column
print '<td class="liste_titre" align="right">';
$searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
print $searchpicto;
print '</td>';
print '</tr>'."\n";
// Detect if we need a fetch on each output line
$needToFetchEachLine=0;
foreach ($extrafields->attribute_computed as $key => $val)
{
if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object
}
$i=0;
$totalarray=array();
while ($i < min($num, $limit))
{
$obj = $db->fetch_object($resql);
if ($obj)
{
// Show here line of result
print '<tr class="oddeven">';
// LIST_OF_TD_FIELDS_LIST
/*
if (! empty($arrayfields['t.field1']['checked']))
{
print '<td>'.$obj->field1.'</td>';
if (! $i) $totalarray['nbfield']++;
}
if (! empty($arrayfields['t.field2']['checked']))
{
print '<td>'.$obj->field2.'</td>';
if (! $i) $totalarray['nbfield']++;
}*/
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{
foreach($extrafields->attribute_label as $key => $val)
{
if (! empty($arrayfields["ef.".$key]['checked']))
{
print '<td';
$align=$extrafields->getAlignFlag($key);
if ($align) print ' align="'.$align.'"';
print '>';
$tmpkey='options_'.$key;
print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
}
}
// Fields from hook
$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Date creation
if (! empty($arrayfields['t.datec']['checked']))
{
print '<td align="center">';
print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
// Date modification
if (! empty($arrayfields['t.tms']['checked']))
{
print '<td align="center">';
print dol_print_date($db->jdate($obj->date_update), 'dayhour');
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
// Status
/*
if (! empty($arrayfields['u.statut']['checked']))
{
$userstatic->statut=$obj->statut;
print '<td align="center">'.$userstatic->getLibStatut(3).'</td>';
}*/
// Action column
print '<td class="nowrap" align="center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
$selected=0;
if (in_array($obj->rowid, $arrayofselected)) $selected=1;
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
}
print '</td>';
if (! $i) $totalarray['nbfield']++;
print '</tr>';
}
$i++;
}
// Show total line
if (isset($totalarray['totalhtfield']))
{
print '<tr class="liste_total">';
$i=0;
while ($i < $totalarray['nbfield'])
{
$i++;
if ($i == 1)
{
if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
}
elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
else print '<td></td>';
}
print '</tr>';
}
$db->free($resql);
$parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
$reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print '</table>'."\n";
print '</div>'."\n";
print '</form>'."\n";
// Example 2: Adding links to objects
// The class must extend CommonObject for this method to be available
$somethingshown = $form->showLinkedObjectBlock($myobject);
if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
{
// Show list of available documents
$urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
$urlsource.=str_replace('&amp;','&',$param);
$filedir=$diroutputmassaction;
$genallowed=$user->rights->facture->lire;
$delallowed=$user->rights->facture->lire;
print $formfile->showdocuments('massfilesarea_mymodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
}
else
{
print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
}
// End of page
llxFooter();
$db->close();

View File

@@ -0,0 +1,165 @@
#!/usr/bin/env php
<?php
/* Copyright (C) 2007-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) ---Put here your own copyright and developer email---
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/modulebuilder/template/scripts/myobject.php
* \ingroup mymodule
* \brief This file is an example for a command line script to work on MyObject
*/
$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(-1);
}
// Global variables
$version='1.0';
$error=0;
// -------------------- START OF YOUR CODE HERE --------------------
@set_time_limit(0); // No timeout for this script
define('EVEN_IF_ONLY_LOGIN_ALLOWED',1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only".
// Include and load Dolibarr environment variables
require_once($path."../../htdocs/master.inc.php");
// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
// $user is created but empty.
//$langs->setDefaultLang('en_US'); // To change default language of $langs
$langs->load("main"); // To load language file for default language
// 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.") pid=".dol_getmypid()." *****\n";
if (! isset($argv[1])) { // Check parameters
print "Usage: ".$script_file." param1 param2 ...\n";
exit(-1);
}
print '--- start'."\n";
print 'Argument 1='.$argv[1]."\n";
print 'Argument 2='.$argv[2]."\n";
// Start of transaction
$db->begin();
// Examples for manipulating class MyObject
dol_include_once("/mymodule/class/myobject.class.php");
$myobject=new MyObject($db);
// Example for inserting creating object in database
/*
dol_syslog($script_file." CREATE", LOG_DEBUG);
$myobject->prop1='value_prop1';
$myobject->prop2='value_prop2';
$id=$myobject->create($user);
if ($id < 0) { $error++; dol_print_error($db,$myobject->error); }
else print "Object created with id=".$id."\n";
*/
// Example for reading object from database
/*
dol_syslog($script_file." FETCH", LOG_DEBUG);
$result=$myobject->fetch($id);
if ($result < 0) { $error; dol_print_error($db,$myobject->error); }
else print "Object with id=".$id." loaded\n";
*/
// Example for updating object in database ($myobject must have been loaded by a fetch before)
/*
dol_syslog($script_file." UPDATE", LOG_DEBUG);
$myobject->prop1='newvalue_prop1';
$myobject->prop2='newvalue_prop2';
$result=$myobject->update($user);
if ($result < 0) { $error++; dol_print_error($db,$myobject->error); }
else print "Object with id ".$myobject->id." updated\n";
*/
// Example for deleting object in database ($myobject must have been loaded by a fetch before)
/*
dol_syslog($script_file." DELETE", LOG_DEBUG);
$result=$myobject->delete($user);
if ($result < 0) { $error++; dol_print_error($db,$myobject->error); }
else print "Object with id ".$myobject->id." deleted\n";
*/
// An example of a direct SQL read without using the fetch method
/*
$sql = "SELECT field1, field2";
$sql.= " FROM ".MAIN_DB_PREFIX."myobject";
$sql.= " WHERE field3 = 'xxx'";
$sql.= " ORDER BY field1 ASC";
dol_syslog($script_file, LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $db->fetch_object($resql);
if ($obj)
{
// You can use here results
print $obj->field1;
print $obj->field2;
}
$i++;
}
}
}
else
{
$error++;
dol_print_error($db);
}
*/
// -------------------- END OF YOUR CODE --------------------
if (! $error)
{
$db->commit();
print '--- end ok'."\n";
}
else
{
print '--- end error code='.$error."\n";
$db->rollback();
}
$db->close(); // Close $db database opened handler
exit($error);

View File

@@ -1,203 +0,0 @@
#!/usr/bin/env php
<?php
/* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) <year> <name of author>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/**
* \file scripts/myscript.php
* \ingroup mymodule
* \brief Example command line script.
*
* Put detailed description here.
*/
$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 ";
echo $script_file;
echo " from command line, you must use PHP for CLI mode.\n";
exit;
}
// Global variables
$version = '1.0.0';
$error = 0;
/*
* -------------------- YOUR CODE STARTS HERE --------------------
*/
/* Set this define to 0 if you want to allow execution of your script
* even if dolibarr setup is "locked to admin user only". */
define('EVEN_IF_ONLY_LOGIN_ALLOWED', 0);
/* Include Dolibarr environment
* Customize to your needs
*/
require_once $path . '../../../master.inc.php';
/* After this $db, $conf, $langs, $mysoc, $user and other Dolibarr utility variables should be defined.
* Warning: this still requires a valid htdocs/conf.php file
*/
global $conf, $db, $langs, $mysoc, $user;
// No timeout for this script
@set_time_limit(0);
// Set the default language
//$langs->setDefaultLang('en_US');
// Load translations for the default language
$langs->load("main");
/* User and permissions loading
* Loads user for login 'admin'.
* Comment out to run as anonymous user. */
$result = $user->fetch('', 'admin');
if (! $result > 0) {
dol_print_error('', $user->error);
exit;
}
$user->getrights();
// Display banner and help
echo "***** " . $script_file . " (" . $version . ") pid=" . getmypid() . " *****\n";
dol_syslog($script_file . " launched with arg " . join(',', $argv));
if (! isset($argv[1])) {
// Check parameters
echo "Usage: " . $script_file . " param1 param2 ...\n";
exit;
}
echo '--- start' . "\n";
echo 'Argument 1=' . $argv[1] . "\n";
echo 'Argument 2=' . $argv[2] . "\n";
// Start database transaction
$db->begin();
// Examples for manipulating a class
require_once '../class/myclass.class.php';
$myobject = new MyClass($db);
// Example for inserting creating object in database
/*
dol_syslog($script_file . " CREATE", LOG_DEBUG);
$myobject->prop1 = 'value_prop1';
$myobject->prop2 = 'value_prop2';
$id = $myobject->create($user);
if ($id < 0) {
$error++;
dol_print_error($db, $myobject->error);
} else {
echo "Object created with id=" . $id . "\n";
}
*/
// Example for reading object from database
/*
dol_syslog($script_file . " FETCH", LOG_DEBUG);
$result = $myobject->fetch($id);
if ($result < 0) {
$error;
dol_print_error($db, $myobject->error);
} else {
echo "Object with id=" . $id . " loaded\n";
}
*/
// Example for updating object in database
// ($myobject must have been loaded by a fetch before)
/*
dol_syslog($script_file . " UPDATE", LOG_DEBUG);
$myobject->prop1 = 'newvalue_prop1';
$myobject->prop2 = 'newvalue_prop2';
$result = $myobject->update($user);
if ($result < 0) {
$error++;
dol_print_error($db, $myobject->error);
} else {
echo "Object with id " . $myobject->id . " updated\n";
}
*/
// Example for deleting object in database
// ($myobject must have been loaded by a fetch before)
/*
dol_syslog($script_file . " DELETE", LOG_DEBUG);
$result = $myobject->delete($user);
if ($result < 0) {
$error++;
dol_print_error($db, $myobject->error);
} else {
echo "Object with id " . $myobject->id . " deleted\n";
}
*/
// An example of a direct SQL read without using the fetch method
/*
$sql = "SELECT field1, field2";
$sql.= " FROM " . MAIN_DB_PREFIX . "c_pays";
$sql.= " WHERE field3 = 'xxx'";
$sql.= " ORDER BY field1 ASC";
dol_syslog($script_file . " sql=" . $sql, LOG_DEBUG);
$resql=$db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
if ($num) {
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($obj) {
// You can use here results
echo $obj->field1;
echo $obj->field2;
}
$i++;
}
}
} else {
$error++;
dol_print_error($db);
}
*/
/*
* --------------------- YOUR CODE ENDS HERE ----------------------
*/
// Error management
if (! $error) {
$db->commit();
echo '--- end ok' . "\n";
$exit_status = 0; // UNIX no errors exit status
} else {
echo '--- end error code=' . $error . "\n";
$db->rollback();
$exit_status = 1; // UNIX general error exit status
}
// Close database handler
$db->close();
// Return exit status code
return $exit_status;

View File

@@ -14,6 +14,6 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
INSERT INTO llx_mytable VALUES (
INSERT INTO llx_myobject VALUES (
1, 1, 'mydata'
);

View File

@@ -14,4 +14,4 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
ALTER TABLE llx_mytable ADD UNIQUE INDEX uk_fk_othertable (fk_othertable);
ALTER TABLE llx_myobject ADD UNIQUE INDEX uk_fk_othertable (fk_othertable);

View File

@@ -14,7 +14,7 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
CREATE TABLE llx_mytable(
CREATE TABLE llx_myobject(
rowid INTEGER AUTO_INCREMENT PRIMARY KEY,
entity INTEGER DEFAULT 1 NOT NULL,
fk_othertable INTEGER NOT NULL,

View File

@@ -17,20 +17,18 @@
*/
/**
* \file test/unit/MyClassTest.php
* \file test/unit/MyObjectTest.php
* \ingroup mymodule
* \brief Example PHPUnit test.
*
* Put detailed description here.
* \brief PHPUnit test for MyObject class.
*/
namespace test\unit;
/**
* Class MyClassTest
* Class MyObjectTest
* @package Testmymodule
*/
class MyClassTest extends \PHPUnit_Framework_TestCase
class MyObjectTest extends \PHPUnit_Framework_TestCase
{
/**
* Global test setup