Merge branch '4.0' of git@github.com:Dolibarr/dolibarr.git into 4.0

This commit is contained in:
Laurent Destailleur 2016-11-27 17:10:25 +01:00
commit ad912bed04
3 changed files with 42 additions and 42 deletions

View File

@ -45,11 +45,14 @@ class GenericApi extends DolibarrApi
* @return array Response status and user token * @return array Response status and user token
* *
* @throws RestException * @throws RestException
*
* @url POST /login
* @url GET /login
*/ */
public function login($login, $password, $entity=0, $reset=0) { public function login($login, $password, $entity=0, $reset=0) {
global $conf, $dolibarr_main_authentication, $dolibarr_auto_user; global $conf, $dolibarr_main_authentication, $dolibarr_auto_user;
// Authentication mode // Authentication mode
if (empty($dolibarr_main_authentication)) if (empty($dolibarr_main_authentication))
$dolibarr_main_authentication = 'http,dolibarr'; $dolibarr_main_authentication = 'http,dolibarr';
@ -67,21 +70,21 @@ class GenericApi extends DolibarrApi
} }
$token = 'failedtogenerateorgettoken'; $token = 'failedtogenerateorgettoken';
$tmpuser=new User($this->db); $tmpuser=new User($this->db);
$tmpuser->fetch(0, $login); $tmpuser->fetch(0, $login);
// Renew the hash // Renew the hash
if (empty($tmpuser->api_key) || $reset) if (empty($tmpuser->api_key) || $reset)
{ {
// Generate token for user // Generate token for user
$token = dol_hash($login.uniqid().$conf->global->MAIN_API_KEY,1); $token = dol_hash($login.uniqid().$conf->global->MAIN_API_KEY,1);
// We store API token into database // We store API token into database
$sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql.= " SET api_key = '".$this->db->escape($token)."'"; $sql.= " SET api_key = '".$this->db->escape($token)."'";
$sql.= " WHERE login = '".$this->db->escape($login)."'"; $sql.= " WHERE login = '".$this->db->escape($login)."'";
dol_syslog(get_class($this)."::login", LOG_DEBUG); // No log dol_syslog(get_class($this)."::login", LOG_DEBUG); // No log
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (!$result) if (!$result)
@ -93,7 +96,7 @@ class GenericApi extends DolibarrApi
{ {
$token = $tmpuser->api_key; $token = $tmpuser->api_key;
} }
//return token //return token
return array( return array(
'success' => array( 'success' => array(

View File

@ -26,6 +26,7 @@
* *
*/ */
if (! defined("NOLOGIN")) define("NOLOGIN",'1'); if (! defined("NOLOGIN")) define("NOLOGIN",'1');
if (! defined("NOCSRFCHECK")) define("NOCSRFCHECK",'1');
$res=0; $res=0;
if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php'; if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php';
@ -121,9 +122,9 @@ foreach ($modulesdir as $dir)
$classname = str_replace('Api_','',ucwords($reg[1])).'Api'; $classname = str_replace('Api_','',ucwords($reg[1])).'Api';
$classname = ucfirst($classname); $classname = ucfirst($classname);
require_once $dir_part.$file_searched; require_once $dir_part.$file_searched;
if (class_exists($classname)) if (class_exists($classname))
{ {
dol_syslog("Found API classname=".$classname); dol_syslog("Found API classname=".$classname);
$api->r->addAPIClass($classname,''); $api->r->addAPIClass($classname,'');
$listofapis[]=array('classname'=>$classname, 'fullpath'=>$file_searched); $listofapis[]=array('classname'=>$classname, 'fullpath'=>$file_searched);
} }
@ -142,7 +143,3 @@ foreach ($modulesdir as $dir)
// Call API (we suppose we found it) // Call API (we suppose we found it)
$api->r->handle(); $api->r->handle();

View File

@ -64,7 +64,7 @@ $search_state=trim(GETPOST("search_state"));
$search_country=GETPOST("search_country",'int'); $search_country=GETPOST("search_country",'int');
$search_type_thirdparty=GETPOST("search_type_thirdparty",'int'); $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
$search_user=GETPOST('search_user','int'); $search_user=GETPOST('search_user','int');
$search_request_author=GETPOST('search_request_author','int'); $search_request_author=GETPOST('search_request_author','alpha');
$search_ht=GETPOST('search_ht'); $search_ht=GETPOST('search_ht');
$search_ttc=GETPOST('search_ttc'); $search_ttc=GETPOST('search_ttc');
$search_status=(GETPOST('search_status','alpha')!=''?GETPOST('search_status','alpha'):GETPOST('statut','alpha')); // alpha and not intbecause it can be '6,7' $search_status=(GETPOST('search_status','alpha')!=''?GETPOST('search_status','alpha'):GETPOST('statut','alpha')); // alpha and not intbecause it can be '6,7'
@ -192,7 +192,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP
$search_type=''; $search_type='';
$search_country=''; $search_country='';
$search_type_thirdparty=''; $search_type_thirdparty='';
$search_request_author=-1; $search_request_author='';
$search_total_ht=''; $search_total_ht='';
$search_total_vat=''; $search_total_vat='';
$search_total_ttc=''; $search_total_ttc='';
@ -205,7 +205,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP
$deliveryyear=''; $deliveryyear='';
$billed=''; $billed='';
$search_array_options=array(); $search_array_options=array();
} }
if (empty($reshook)) if (empty($reshook))
@ -248,7 +248,7 @@ if ($socid > 0)
$fourn->fetch($socid); $fourn->fetch($socid);
$title .= ' - '.$fourn->name; $title .= ' - '.$fourn->name;
} }
if ($status) if ($status)
{ {
if ($status == '1,2,3') $title.=' - '.$langs->trans("StatusOrderToProcessShort"); if ($status == '1,2,3') $title.=' - '.$langs->trans("StatusOrderToProcessShort");
if ($status == '6,7') $title.=' - '.$langs->trans("StatusOrderCanceled"); if ($status == '6,7') $title.=' - '.$langs->trans("StatusOrderCanceled");
@ -300,7 +300,7 @@ if ($search_ref) $sql .= natural_search('cf.ref', $search_ref);
if ($search_refsupp) $sql.= natural_search("cf.ref_supplier", $search_refsupp); if ($search_refsupp) $sql.= natural_search("cf.ref_supplier", $search_refsupp);
if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall); if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
if ($search_company) $sql .= natural_search('s.nom', $search_company); if ($search_company) $sql .= natural_search('s.nom', $search_company);
if ($search_request_author > 0) $sql.= " AND u.login LIKE '%".$db->escape($search_request_author)."%'"; if ($search_request_author) $sql.= " AND u.login LIKE '%".$db->escape($search_request_author)."%'";
if ($billed != '' && $billed >= 0) $sql .= " AND cf.billed = ".$billed; if ($billed != '' && $billed >= 0) $sql .= " AND cf.billed = ".$billed;
//Required triple check because statut=0 means draft filter //Required triple check because statut=0 means draft filter
@ -382,7 +382,7 @@ $sql.= $db->plimit($limit+1, $offset);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
if ($socid > 0) if ($socid > 0)
{ {
$soc = new Societe($db); $soc = new Societe($db);
@ -393,7 +393,7 @@ if ($resql)
{ {
$title = $langs->trans('ListOfSupplierOrders'); $title = $langs->trans('ListOfSupplierOrders');
} }
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$param=''; $param='';
@ -410,13 +410,13 @@ if ($resql)
if ($search_ref) $param.='&search_ref='.$search_ref; if ($search_ref) $param.='&search_ref='.$search_ref;
if ($search_company) $param.='&search_company='.$search_company; if ($search_company) $param.='&search_company='.$search_company;
if ($search_user > 0) $param.='&search_user='.$search_user; if ($search_user > 0) $param.='&search_user='.$search_user;
if ($search_request_author > 0) $param.='&search_request_author='.$search_request_author; if ($search_request_author) $param.='&search_request_author='.$search_request_author;
if ($search_sale > 0) $param.='&search_sale='.$search_sale; if ($search_sale > 0) $param.='&search_sale='.$search_sale;
if ($search_total_ht != '') $param.='&search_total_ht='.$search_total_ht; if ($search_total_ht != '') $param.='&search_total_ht='.$search_total_ht;
if ($search_total_ttc != '') $param.="&search_total_ttc=".$search_total_ttc; if ($search_total_ttc != '') $param.="&search_total_ttc=".$search_total_ttc;
if ($search_refsupp) $param.="&search_refsupp=".$search_refsupp; if ($search_refsupp) $param.="&search_refsupp=".$search_refsupp;
if ($search_status >= 0) $param.="&search_status=".$search_status; if ($search_status >= 0) $param.="&search_status=".$search_status;
if ($billed != '') $param.="&billed=".$billed; if ($billed != '') $param.="&billed=".$billed;
if ($optioncss != '') $param.='&optioncss='.$optioncss; if ($optioncss != '') $param.='&optioncss='.$optioncss;
// Add $param from extra fields // Add $param from extra fields
foreach ($search_array_options as $key => $val) foreach ($search_array_options as $key => $val)
@ -425,9 +425,9 @@ if ($resql)
$tmpkey=preg_replace('/search_options_/','',$key); $tmpkey=preg_replace('/search_options_/','',$key);
if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
} }
//$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
// Lignes des champs de filtre // Lignes des champs de filtre
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
@ -437,9 +437,9 @@ if ($resql)
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">'; print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit);
if ($sall) if ($sall)
{ {
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
@ -447,7 +447,7 @@ if ($resql)
} }
$moreforfilter=''; $moreforfilter='';
// If the user can view prospects other than his' // If the user can view prospects other than his'
if ($user->rights->societe->client->voir || $socid) if ($user->rights->societe->client->voir || $socid)
{ {
@ -485,7 +485,7 @@ if ($resql)
print $moreforfilter; print $moreforfilter;
print '</div>'; print '</div>';
} }
$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
@ -511,9 +511,9 @@ if ($resql)
// Extra fields // Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{ {
foreach($extrafields->attribute_label as $key => $val) foreach($extrafields->attribute_label as $key => $val)
{ {
if (! empty($arrayfields["ef.".$key]['checked'])) if (! empty($arrayfields["ef.".$key]['checked']))
{ {
$align=$extrafields->getAlignFlag($key); $align=$extrafields->getAlignFlag($key);
print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
@ -538,7 +538,7 @@ if ($resql)
print '<td class="liste_titre"><input size="8" type="text" class="flat" name="search_ref" value="'.$search_ref.'"></td>'; print '<td class="liste_titre"><input size="8" type="text" class="flat" name="search_ref" value="'.$search_ref.'"></td>';
} }
// Ref customer // Ref customer
if (! empty($arrayfields['cf.ref_supplier']['checked'])) if (! empty($arrayfields['cf.ref_supplier']['checked']))
{ {
print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_refsupp" value="'.$search_refsupp.'"></td>'; print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_refsupp" value="'.$search_refsupp.'"></td>';
} }
@ -551,11 +551,11 @@ if ($resql)
if (! empty($arrayfields['u.login']['checked'])) if (! empty($arrayfields['u.login']['checked']))
{ {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
//print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">'; print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">';
print '</td>'; print '</td>';
} }
// Thirpdarty // Thirpdarty
if (! empty($arrayfields['s.nom']['checked'])) if (! empty($arrayfields['s.nom']['checked']))
{ {
print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>'; print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>';
} }
@ -594,7 +594,7 @@ if ($resql)
print '</td>'; print '</td>';
} }
// Date delivery // Date delivery
if (! empty($arrayfields['cf.date_delivery']['checked'])) if (! empty($arrayfields['cf.date_delivery']['checked']))
{ {
print '<td class="liste_titre" align="center">'; print '<td class="liste_titre" align="center">';
if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="deliveryday" value="'.$deliveryday.'">'; if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="deliveryday" value="'.$deliveryday.'">';
@ -622,7 +622,7 @@ if ($resql)
print '<td class="liste_titre" align="right">'; print '<td class="liste_titre" align="right">';
print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">'; print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
print '</td>'; print '</td>';
} }
// Extra fields // Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{ {
@ -649,7 +649,7 @@ if ($resql)
// Fields from hook // Fields from hook
$parameters=array('arrayfields'=>$arrayfields); $parameters=array('arrayfields'=>$arrayfields);
$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Date creation // Date creation
if (! empty($arrayfields['cf.datec']['checked'])) if (! empty($arrayfields['cf.datec']['checked']))
{ {
@ -681,13 +681,13 @@ if ($resql)
$searchpitco=$form->showFilterAndCheckAddButtons(0); $searchpitco=$form->showFilterAndCheckAddButtons(0);
print $searchpitco; print $searchpitco;
print '</td>'; print '</td>';
print "</tr>\n"; print "</tr>\n";
$total=0; $total=0;
$subtotal=0; $subtotal=0;
$productstat_cache=array(); $productstat_cache=array();
$userstatic = new User($db); $userstatic = new User($db);
$objectstatic=new CommandeFournisseur($db); $objectstatic=new CommandeFournisseur($db);
$projectstatic=new Project($db); $projectstatic=new Project($db);
@ -699,7 +699,7 @@ if ($resql)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$var=!$var; $var=!$var;
$objectstatic->id=$obj->rowid; $objectstatic->id=$obj->rowid;
$objectstatic->ref=$obj->ref; $objectstatic->ref=$obj->ref;
$objectstatic->ref_supplier = $obj->ref_supplier; $objectstatic->ref_supplier = $obj->ref_supplier;
@ -708,7 +708,7 @@ if ($resql)
$objectstatic->total_ttc = $obj->total_ttc; $objectstatic->total_ttc = $obj->total_ttc;
$objectstatic->date_delivery = $db->jdate($obj->date_delivery); $objectstatic->date_delivery = $db->jdate($obj->date_delivery);
$objectstatic->statut = $obj->fk_statut; $objectstatic->statut = $obj->fk_statut;
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
// Ref // Ref
@ -802,7 +802,7 @@ if ($resql)
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
// Order date // Order date
if (! empty($arrayfields['cf.date_commande']['checked'])) if (! empty($arrayfields['cf.date_commande']['checked']))
{ {
@ -847,7 +847,7 @@ if ($resql)
if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield']; if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
$totalarray['totalttc'] += $obj->total_ttc; $totalarray['totalttc'] += $obj->total_ttc;
} }
// Extra fields // Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{ {
@ -898,7 +898,7 @@ if ($resql)
print '<td align="center">'.yn($obj->billed).'</td>'; print '<td align="center">'.yn($obj->billed).'</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
// Action column // Action column
print '<td></td>'; print '<td></td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;