';
diff --git a/htdocs/api/admin/explorer.php b/htdocs/api/admin/explorer.php
index 66d06e91679..262b3f69476 100644
--- a/htdocs/api/admin/explorer.php
+++ b/htdocs/api/admin/explorer.php
@@ -1,5 +1,6 @@
+ * Copyright (C) 2016 Laurent Destailleur
*
* 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
@@ -19,11 +20,7 @@
* \defgroup api Module DolibarrApi
* \brief API loader
* Search files htdocs//class/api_.class.php
- * \file htdocs/api/indexphp
- *
- * @todo User authentication with api_key
- *
- *
+ * \file htdocs/api/admin/explorer.php
*/
require_once '../../main.inc.php';
@@ -51,7 +48,6 @@ use \Luracast\Restler\Defaults;
$api = new DolibarrApi($db);
$api->r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root
-$api->r->addAPIClass('DolibarrApiInit',''); // Just for url root page
$api->r->setSupportedFormats('JsonFormat', 'XmlFormat');
$api->r->addAuthenticationClass('DolibarrApiAccess','');
@@ -149,7 +145,6 @@ llxHeader();
$linkback=''.$langs->trans("BackToModuleList").'';
print load_fiche_titre($langs->trans("ApiSetup"),$linkback,'title_setup');
-
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
@@ -158,27 +153,46 @@ $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain
// Show message
print ' ';
$message='';
-$url=''.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword';
+$url=''.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword[&reset=1]';
$message.=$langs->trans("UrlToGetKeyToUseAPIs").': ';
$message.=img_picto('','object_globe.png').' '.$url;
print $message;
print ' ';
print ' ';
+$oldclass='';
+
print $langs->trans("ListOfAvailableAPIs").': ';
foreach($listofapis['v1'] as $key => $val)
{
if ($key == 'login') continue;
+
if ($key)
{
- //print $key.' - '.$val['classname'].' - '.$val['fullpath']." - ".DOL_MAIN_URL_ROOT.'/api/index.php/'.strtolower(preg_replace('/Api$/','',$val['classname']))."/xxx \n";
- $url=$urlwithroot.'/api/index.php/'.$key;
- $url.='?api_key=token';
- print img_picto('','object_globe.png').' '.$url." \n";
-
+ foreach($val as $method => $val2)
+ {
+ $newclass=$val2['className'];
+
+ if (preg_match('/restler/i', $newclass)) continue;
+
+ if ($oldclass != $newclass)
+ {
+ print "\n \n".$langs->trans("Class").': '.$newclass.' '."\n";
+ $oldclass = $newclass;
+ }
+ //print $key.' - '.$val['classname'].' - '.$val['fullpath']." - ".DOL_MAIN_URL_ROOT.'/api/index.php/'.strtolower(preg_replace('/Api$/','',$val['classname']))."/xxx \n";
+ $url=$urlwithroot.'/api/index.php/'.$key;
+ $url.='?api_key=token';
+ print img_picto('','object_globe.png').' '.$method.' '.$url." \n";
+ }
}
}
+print ' ';
+print ' ';
+print $langs->trans("OnlyActiveElementsAreExposed", DOL_URL_ROOT.'/admin/modules.php');
+
+
llxFooter();
$db->close();
diff --git a/htdocs/api/admin/index.php b/htdocs/api/admin/index.php
index 2c31432b63b..3a69dadaaba 100644
--- a/htdocs/api/admin/index.php
+++ b/htdocs/api/admin/index.php
@@ -100,19 +100,6 @@ print ''.$langs->trans("ApiExporerIs").': ';
$url=DOL_MAIN_URL_ROOT.'/api/admin/explorer.php';
print img_picto('','object_globe.png').' '.$url." \n";
-// API endpoint
-/*print ''.$langs->trans("ApiEndPointIs").': ';
-$url=DOL_MAIN_URL_ROOT.'/api/index.php/xxx/list';
-print img_picto('','object_globe.png').' '.$url." \n";
-$url=DOL_MAIN_URL_ROOT.'/api/xxx/list.json';
-print img_picto('','object_globe.png').' '.$url." \n";
-*/
-
-print ' ';
-print ' ';
-print $langs->trans("OnlyActiveElementsAreExposed", DOL_URL_ROOT.'/admin/modules.php');
-
-
llxFooter();
$db->close();
diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php
index bc5b4378c0c..b3a2cdaf9d0 100644
--- a/htdocs/api/class/api.class.php
+++ b/htdocs/api/class/api.class.php
@@ -140,89 +140,3 @@ class DolibarrApi
return checkUserAccessToObject(DolibarrApiAccess::$user, $featuresarray,$resource_id,$dbtablename,$feature2,$dbt_keyfield,$dbt_select);
}
}
-
-/**
- * API init
- *
- */
-class DolibarrApiInit extends DolibarrApi
-{
-
- function __construct() {
- global $db;
- $this->db = $db;
- }
-
- /**
- * Login
- *
- * Log user with username and password
- *
- * @param string $login Username
- * @param string $password User password
- * @param int $entity User entity
- * @return array Response status and user token
- *
- * @throws RestException
- */
- public function login($login, $password, $entity = 0) {
-
- global $conf, $dolibarr_main_authentication, $dolibarr_auto_user;
-
- // Authentication mode
- if (empty($dolibarr_main_authentication))
- $dolibarr_main_authentication = 'http,dolibarr';
- // Authentication mode: forceuser
- if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user))
- $dolibarr_auto_user = 'auto';
- // Set authmode
- $authmode = explode(',', $dolibarr_main_authentication);
-
- include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
- $login = checkLoginPassEntity($login, $password, $entity, $authmode);
- if (empty($login))
- {
- throw new RestException(403, 'Access denied');
- }
-
- // Generate token for user
- $token = dol_hash($login.uniqid().$conf->global->MAIN_API_KEY,1);
-
- // We store API token into database
- $sql = "UPDATE ".MAIN_DB_PREFIX."user";
- $sql.= " SET api_key = '".$this->db->escape($token)."'";
- $sql.= " WHERE login = '".$this->db->escape($login)."'";
-
- dol_syslog(get_class($this)."::login", LOG_DEBUG); // No log
- $result = $this->db->query($sql);
- if (!$result)
- {
- throw new RestException(500, 'Error when updating user :'.$this->db->error_msg);
- }
-
- //return token
- return array(
- 'success' => array(
- 'code' => 200,
- 'token' => $token,
- 'message' => 'Welcome ' . $login
- )
- );
- }
-
- /**
- * Get status (Dolibarr version)
- *
- * @access protected
- * @class DolibarrApiAccess {@requires admin}
- */
- function status() {
- require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
- return array(
- 'success' => array(
- 'code' => 200,
- 'dolibarr_version' => DOL_VERSION
- )
- );
- }
-}
diff --git a/htdocs/api/class/api_generic.class.php b/htdocs/api/class/api_generic.class.php
new file mode 100644
index 00000000000..038621b6235
--- /dev/null
+++ b/htdocs/api/class/api_generic.class.php
@@ -0,0 +1,124 @@
+
+ *
+ * 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 .
+ */
+
+use Luracast\Restler\Restler;
+use Luracast\Restler\RestException;
+use Luracast\Restler\Defaults;
+
+require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
+require_once DOL_DOCUMENT_ROOT.'/api/class/api.class.php';
+
+
+/**
+ * API generic (login, status, ...)
+ *
+ */
+class GenericApi extends DolibarrApi
+{
+
+ function __construct() {
+ global $db;
+ $this->db = $db;
+ }
+
+ /**
+ * Login
+ *
+ * Log user with username and password
+ *
+ * @param string $login Username
+ * @param string $password User password
+ * @param int $entity User entity
+ * @param int $reset Reset token
+ * @return array Response status and user token
+ *
+ * @throws RestException
+ */
+ public function login($login, $password, $entity=0, $reset=0) {
+
+ global $conf, $dolibarr_main_authentication, $dolibarr_auto_user;
+
+ // Authentication mode
+ if (empty($dolibarr_main_authentication))
+ $dolibarr_main_authentication = 'http,dolibarr';
+ // Authentication mode: forceuser
+ if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user))
+ $dolibarr_auto_user = 'auto';
+ // Set authmode
+ $authmode = explode(',', $dolibarr_main_authentication);
+
+ include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
+ $login = checkLoginPassEntity($login, $password, $entity, $authmode);
+ if (empty($login))
+ {
+ throw new RestException(403, 'Access denied');
+ }
+
+ $token = 'failedtogenerateorgettoken';
+
+ $tmpuser=new User($this->db);
+ $tmpuser->fetch(0, $login);
+
+ // Renew the hash
+ if (empty($tmpuser->api_key) || $reset)
+ {
+ // Generate token for user
+ $token = dol_hash($login.uniqid().$conf->global->MAIN_API_KEY,1);
+
+ // We store API token into database
+ $sql = "UPDATE ".MAIN_DB_PREFIX."user";
+ $sql.= " SET api_key = '".$this->db->escape($token)."'";
+ $sql.= " WHERE login = '".$this->db->escape($login)."'";
+
+ dol_syslog(get_class($this)."::login", LOG_DEBUG); // No log
+ $result = $this->db->query($sql);
+ if (!$result)
+ {
+ throw new RestException(500, 'Error when updating api_key for user :'.$this->db->lasterror());
+ }
+ }
+ else
+ {
+ $token = $tmpuser->api_key;
+ }
+
+ //return token
+ return array(
+ 'success' => array(
+ 'code' => 200,
+ 'token' => $token,
+ 'message' => 'Welcome ' . $login.($reset?' - Token is new':' - Token was generated by a previous call')
+ )
+ );
+ }
+
+ /**
+ * Get status (Dolibarr version)
+ *
+ * @access protected
+ * @class DolibarrApiAccess {@requires admin}
+ */
+ function status() {
+ require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
+ return array(
+ 'success' => array(
+ 'code' => 200,
+ 'dolibarr_version' => DOL_VERSION
+ )
+ );
+ }
+}
diff --git a/htdocs/api/index.php b/htdocs/api/index.php
index 55a45aea4b9..2fbad04ecbb 100644
--- a/htdocs/api/index.php
+++ b/htdocs/api/index.php
@@ -60,7 +60,6 @@ use \Luracast\Restler\Defaults;
$api = new DolibarrApi($db);
$api->r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root
-$api->r->addAPIClass('DolibarrApiInit',''); // Just for url root page
$api->r->setSupportedFormats('JsonFormat', 'XmlFormat');
$api->r->addAuthenticationClass('DolibarrApiAccess','');
diff --git a/htdocs/cashdesk/tpl/facturation1.tpl.php b/htdocs/cashdesk/tpl/facturation1.tpl.php
index ecb11c3e6ee..8ddd7e48a85 100644
--- a/htdocs/cashdesk/tpl/facturation1.tpl.php
+++ b/htdocs/cashdesk/tpl/facturation1.tpl.php
@@ -203,7 +203,7 @@ $langs->load("cashdesk");
?>
" onclick="javascript: verifClic('DIF');" />
trans("DateEcheance").' :';
+ print $langs->trans("DateDue").' :';
print $form->select_date(-1,'txtDatePaiement',0,0,0,'paymentmode',1,0,1);
print '';
?>
diff --git a/htdocs/cashdesk/tpl/validation1.tpl.php b/htdocs/cashdesk/tpl/validation1.tpl.php
index 047d597a6ef..bb6bd92c8bd 100644
--- a/htdocs/cashdesk/tpl/validation1.tpl.php
+++ b/htdocs/cashdesk/tpl/validation1.tpl.php
@@ -83,7 +83,7 @@ $langs->load("bills");
// Affichage des infos en fonction du mode de paiement
if ( $obj_facturation->getsetPaymentMode() == 'DIF' ) {
- echo ('
'.$langs->trans("DateEcheance").'
'.$obj_facturation->paiementLe().'
');
+ echo ('
'.$langs->trans("DateDue").'
'.$obj_facturation->paiementLe().'
');
} else {
diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index b602bc0076d..672ea7b6408 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -48,14 +48,13 @@ class Categorie extends CommonObject
const TYPE_CUSTOMER = 2;
const TYPE_MEMBER = 3;
const TYPE_CONTACT = 4;
- const TYPE_USER = 4; // categorie contact and user are same
- // bank account
- const TYPE_ACCOUNT = 5;
+ const TYPE_USER = 4; // categorie contact and user are same !
+ const TYPE_ACCOUNT = 5; // bank account
/**
* @var array ID mapping from type string
*
- * @note Move to const array when PHP 5.6 will be our minimum target
+ * @note This array should be remove in future, once previous constants are moved to the string value.
*/
private $MAP_ID = array(
'product' => 0,
@@ -1274,14 +1273,12 @@ class Categorie extends CommonObject
* Should be named getListOfCategForObject
*
* @param int $id Id of element
- * @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode
- * (0, 1, 2, ...) is deprecated.
+ * @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated.
* @param string $mode 'object'=Get array of fetched category instances, 'label'=Get array of category
* labels, 'id'= Get array of category IDs
- *
* @return mixed Array of category objects or < 0 if KO
*/
- function containing($id,$type,$mode='object')
+ function containing($id, $type, $mode='object')
{
$cats = array();
diff --git a/htdocs/categories/photos.php b/htdocs/categories/photos.php
index 72c184af113..d3b1f8854b9 100644
--- a/htdocs/categories/photos.php
+++ b/htdocs/categories/photos.php
@@ -29,6 +29,7 @@
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
$langs->load("categories");
@@ -90,6 +91,7 @@ if ($action == 'addthumb' && $_GET["file"])
llxHeader("","",$langs->trans("Categories"));
$form = new Form($db);
+$formother = new FormOther($db);
if ($object->id)
{
@@ -117,8 +119,8 @@ if ($object->id)
print '