diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php
index 1cc68f38cb7..7d784073412 100644
--- a/htdocs/core/class/coreobject.class.php
+++ b/htdocs/core/class/coreobject.class.php
@@ -25,7 +25,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
class CoreObject extends CommonObject {
-
+ protected $__fields=array();
/**
* Constructor
*
@@ -38,7 +38,7 @@ class CoreObject extends CommonObject {
$this->date_0 = '1001-01-01 00:00:00'; //TODO there is a solution for this ?
}
- private function init() {
+ protected function init() {
$this->id = 0;
$this->datec = time();
@@ -110,20 +110,20 @@ class CoreObject extends CommonObject {
}
else return false;
}
- private function _is_float($info){
+ private function is_float($info){
if(is_array($info)) {
if(isset($info['type']) && $info['type']=='float') return true;
else return false;
} else return false;
}
- private function _is_text($info){
+ private function is_text($info){
if(is_array($info)) {
if(isset($info['type']) && $info['type']=='text') return true;
else return false;
} else return false;
}
- private function _is_index($info){
+ private function is_index($info){
if(is_array($info)) {
if(isset($info['index']) && $info['index']==true) return true;
else return false;
@@ -172,14 +172,23 @@ class CoreObject extends CommonObject {
return $query;
}
+ private function get_field_list(){
+
+ $keys = array_keys($this->__fields);
+
+ return implode(',', $keys);
+ }
public function fetch($id, $loadChild = true) {
if(empty($id)) return false;
- $res = $db->query( 'SELECT '.$this->get_field_list().'datec,tms
+ $sql = 'SELECT '.$this->get_field_list().',datec,tms
FROM '.$this->table_element.'
- WHERE rowid='.$id );
+ WHERE rowid='.$id;
+
+ $res = $this->db->query( $sql );
+ var_dump($sql);
if($obj = $db->fetch_object($res)) {
$this->rowid=$id;
diff --git a/htdocs/core/class/class.listview.php b/htdocs/core/class/listview.class.php
similarity index 61%
rename from htdocs/core/class/class.listview.php
rename to htdocs/core/class/listview.class.php
index f37fc9a1628..0cedad18855 100644
--- a/htdocs/core/class/class.listview.php
+++ b/htdocs/core/class/listview.class.php
@@ -20,7 +20,9 @@
class Listview {
- function __construct( $id ) {
+ function __construct(&$db, $id ) {
+
+ $this->db = &$db;
$this->id = $id;
@@ -263,79 +265,25 @@ class Listview {
return $sql;
}
- private function getViewType(&$TParam) {
- if(!empty($TParam['view_type'])) return $TParam['view_type'];
- else if (is_string($TParam['type']))return $TParam['type'] ;
- else return 'list';
+ public function render($sql,$TParam=array()) {
+
+ $THeader=array();
+ $TField=array();
+
+ $this->init($TParam);
+
+ $sql = $this->search($sql,$TParam);
+ $sql = $this->order_by($sql, $TParam);
+
+ $this->parse_sql($THeader, $TField, $TParam, $sql);
+
+ list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam);
+
+ return $this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam);
+
}
- public function render(&$db,$sql,$TParam=array(),$TBind=array()) {
- $this->typeRender = 'sql';
- // print_r($TParam);
- $TEntete=array();
- $TChamps=array();
-
- $this->init($TParam);
-
- if(!empty($TBind)) $this->TBind = $TBind;
-
- $sql = $this->search($sql,$TParam);
- $sql = $this->order_by($sql, $TParam);
-
- $this->parse_sql($db, $TEntete, $TChamps, $TParam, $sql);
-
- list($TTotal, $TTotalGroup)=$this->get_total($TChamps, $TParam);
-
- $view_type = $this->getViewType($TParam);
-
- if($view_type == 'raw') {
- return $this->renderRAW($TEntete, $TChamps,$TTotal,$TTotalGroup, $TParam);
- }
- else if($view_type == 'chart') {
- return $this->renderChart($TEntete, $TChamps,$TTotal, $TParam);
- }
- else {
- return $this->renderList($TEntete, $TChamps,$TTotal,$TTotalGroup, $TParam);
- }
-
-
- }
- public function renderDataTableAjax(&$db,$sql,$TParam=array()) {
- $this->renderDataTableSQL($db, $sql, $TParam);
- }
- public function renderDataTableSQL(&$db,$sql,$TParam=array()) {
- $this->typeRender = 'dataTableAjax';
- // print_r($TParam);
- $TEntete=array();
- $TChamps=array();
-
- $this->init($TParam);
-
- $sql = $this->search($sql,$TParam);
- $sql = $this->order_by($sql, $TParam);
-
- $this->parse_sql($db, $TEntete, $TChamps, $TParam, $sql);
- list($TTotal, $TTotalGroup)=$this->get_total($TChamps, $TParam);
-
- return $this->renderList($TEntete, $TChamps,$TTotal,$TTotalGroup, $TParam);
-
- }
- public function renderXML(&$db,$xmlString, $TParam=array()) {
- $this->typeRender = 'xml';
-
- $TEntete=array();
- $TChamps=array();
-
- $this->init($TParam);
-
- $this->parse_xml($db, $TEntete, $TChamps, $TParam,$xmlString);
-
- list($TTotal, $TTotalGroup)=$this->get_total($TChamps, $TParam);
-
- return $this->renderList($TEntete, $TChamps,$TTotal,$TTotalGroup, $TParam);
-
- }
- private function setSearch(&$TEntete, &$TParam) {
+ private function setSearch(&$THeader, &$TParam) {
global $langs;
if(empty($TParam['search'])) return array();
@@ -347,7 +295,7 @@ class Listview {
$nb_search_in_bar = 0;
if(!empty($TParam['search'])) {
- foreach($TEntete as $key=>$libelle) { // init
+ foreach($THeader as $key=>$libelle) { // init
if(empty($TSearch[$key]))$TSearch[$key]='';
}
}
@@ -382,7 +330,7 @@ class Listview {
}
- if(!empty($TEntete[$key]) || $this->getViewType($TParam) == 'chart') {
+ if(!empty($THeader[$key]) || $this->getViewType($TParam) == 'chart') {
$TSearch[$key] = $fsearch;
$nb_search_in_bar++;
}
@@ -416,12 +364,12 @@ class Listview {
* Function analysant et totalisant une colonne
* Supporté : sum, average
*/
- private function get_total(&$TChamps, &$TParam) {
+ private function get_total(&$TField, &$TParam) {
$TTotal=$TTotalGroup=array();
- if(!empty($TParam['math']) && !empty($TChamps[0])) {
+ if(!empty($TParam['math']) && !empty($TField[0])) {
- foreach($TChamps[0] as $field=>$value) {
+ foreach($TField[0] as $field=>$value) {
$TTotal[$field]='';
$TTotalGroup[$field] = '';
}
@@ -460,80 +408,16 @@ class Listview {
private function getJS(&$TParam) {
$javaScript = '';
-
- if($this->typeRender=='dataTable') {
-
- $javaScript.='
- ';
-
- $TPagination=array();
- }
- elseif($this->typeRender=='dataTableAjax') {
- $javaScript.='
- ';
- }
-
return $javaScript;
}
- private function setExport(&$TParam,$TChamps,$TEntete) {
+ private function setExport(&$TParam,$TField,$THeader) {
global $langs;
$Tab=array();
@@ -545,8 +429,8 @@ class Listview {
'title'=>$this->title
,'sql'=>$this->sql
,'TBind'=>$this->TBind
- ,'TChamps'=>$TChamps
- ,'TEntete'=>$TEntete
+ ,'TChamps'=>$TField
+ ,'TEntete'=>$THeader
) ) );
foreach($TParam['export'] as $mode_export) {
@@ -567,133 +451,7 @@ class Listview {
return $Tab;
}
- private function renderChart(&$TEntete, &$TChamps,&$TTotal, &$TParam) {
-
- $TData = array();
- $header = '';
- $first = true;
-
- $TSearch = $this->setSearch($TEntete, $TParam);
- $TExport= $this->setExport($TParam, $TChamps, $TEntete);
-
- if(empty($TParam['xaxis']) && !empty($TEntete)) {
- $fieldXaxis = key($TEntete);
- }
- else {
- $fieldXaxis = $TParam['xaxis'];
- }
-
- $TValue=array(); $key = null;
- foreach($TEntete as $field=>&$entete) {
- if($field!=$fieldXaxis)$TValue[] = addslashes($entete['libelle']);
- }
-
- $header='["'.addslashes( $TEntete[$fieldXaxis]['libelle'] ).'","'.implode('","', $TValue).'"]';
- //var_dump($fieldXaxis, $TChamps);
- foreach($TChamps as &$row) {
- $TValue=array();
- $key = null;
-
- foreach($row as $k=>$v) {
-
- if($k == $fieldXaxis) {
- $key = $v;
- }
- else {
- $TValue[] = (float)$v;
- }
-
- }
-
- if(!is_null($key)) {
- if(!isset($TData[$key])) $TData[$key] = $TValue;
- else {
- foreach($TData[$key] as $k=>$v) {
- $TData[$key][$k]+=(float)$TValue[$k];
- }
-
- }
- }
-
-
- }
-
- $data = $header;
- foreach($TData as $key=>$TValue) {
-
- $data .= ',[ "'.$key.'", ';
- foreach($TValue as $v) {
- $data.=(float)$v.',';
- }
-
- $data.=' ]';
- }
-
- $height = empty($TParam['height']) ? 500 : $TParam['height'];
- $curveType= empty($TParam['curveType']) ? 'none': $TParam['curveType']; // none or function
- $pieHole = empty($TParam['pieHole']) ? 0: $TParam['pieHole']; // none or function
- $hAxis = empty($TParam['hAxis']) ? array() : $TParam['hAxis']; // Array of params
- $vAxis = empty($TParam['vAxis']) ? array() : $TParam['vAxis']; // Array of params
-
- // This feature is experimental and may change in future releases
- $explorer = empty($TParam['explorer']) ? array() : $TParam['explorer']; // Note: The explorer only works with continuous axes (such as numbers or dates)
-
- $type = empty($TParam['chartType']) ? 'LineChart' : $TParam['chartType'];
-
- $html = '';
-
- if(!empty($TSearch)) {
-
- $html.='
';
- foreach($TSearch as $field=>$input) {
- if(!empty($input)) {
- $label = !empty($TParam['title'][$field]) ? $TParam['title'][$field] : $field;
- $html.='| '.$label.' | '.$input.' |
';
- }
- }
-
- $html.='
';
-
- }
- $javaScript = $this->getJS($TParam);
-
- $html.='
-
-
- '.$javaScript;
-
- return $html;
- }
-
- private function addTotalGroup($TChamps,$TTotalGroup) {
+ private function addTotalGroup($TField,$TTotalGroup) {
global $langs;
$Tab=array();
@@ -704,7 +462,7 @@ class Listview {
$addGroupLine = false;
- foreach($TChamps as $k=>&$line) {
+ foreach($TField as $k=>&$line) {
if(empty($proto_total_line)) {
foreach($line as $field=>$value) {
@@ -748,99 +506,50 @@ class Listview {
return $Tab;
}
-
- private function renderRAW(&$TEntete, &$TChamps, &$TTotal,&$TTotalGroup, &$TParam) {
- $TSearch = $this->setSearch($TEntete, $TParam);
- $TExport=$this->setExport($TParam, $TChamps, $TEntete);
- $TChamps = $this->addTotalGroup($TChamps,$TTotalGroup);
-
- return array(
- 'entete'=>$TEntete
- ,'champs'=>$TChamps
- ,'recherche'=>$TSearch
- ,'total'=>$TTotal
- ,'export'=>$TExport
- ,'haveExport'=>count($TExport)
- , 'id'=>$this->id
- , 'nb_columns'=>count($TEntete)
- ,'totalNB'=>count($TChamps)
- , 'nbSearch'=>count($TSearch)
- , 'haveTotal'=>(int)!empty($TTotal)
- , 'havePage'=>(int)!empty($TPagination)
- );
- }
- private function renderList(&$TEntete, &$TChamps, &$TTotal,&$TTotalGroup, &$TParam) {
- $TBS = new TTemplateTBS;
-
+ private function renderList(&$THeader, &$TField, &$TTotal,&$TTotalGroup, &$TParam) {
+
$javaScript = $this->getJS($TParam);
- if($this->typeRender!='dataTableAjax') {
- $TPagination=array(
- 'pagination'=>array('pageSize'=>$TParam['limit']['nbLine'], 'pageNum'=>$TParam['limit']['page'], 'blockName'=>'champs', 'totalNB'=>count($TChamps))
- );
- }
- else {
- $TPagination=array();
- }
+ $TPagination=array(
+ 'pagination'=>array('pageSize'=>$TParam['limit']['nbLine'], 'pageNum'=>$TParam['limit']['page'], 'blockName'=>'champs', 'totalNB'=>count($TField))
+ );
- $TSearch = $this->setSearch($TEntete, $TParam);
- $TExport=$this->setExport($TParam, $TChamps, $TEntete);
- $TChamps = $this->addTotalGroup($TChamps,$TTotalGroup);
+ $TSearch = $this->setSearch($THeader, $TParam);
+ $TExport=$this->setExport($TParam, $TField, $THeader);
+ $TField = $this->addTotalGroup($TField,$TTotalGroup);
- return $TBS->render($this->template
- , array(
- 'entete'=>$TEntete
- ,'champs'=>$TChamps
+ var_dump(
+ array(
+ 'entete'=>$THeader
+ ,'champs'=>$TField
,'recherche'=>$TSearch
,'total'=>$TTotal
,'export'=>$TExport
)
, array(
- 'liste'=>array_merge(array('haveExport'=>count($TExport), 'id'=>$this->id, 'nb_columns'=>count($TEntete) ,'totalNB'=>count($TChamps), 'nbSearch'=>count($TSearch), 'haveTotal'=>(int)!empty($TTotal), 'havePage'=>(int)!empty($TPagination) ), $TParam['liste'])
+ 'liste'=>array_merge(array('haveExport'=>count($TExport), 'id'=>$this->id, 'nb_columns'=>count($THeader) ,'totalNB'=>count($TField), 'nbSearch'=>count($TSearch), 'haveTotal'=>(int)!empty($TTotal), 'havePage'=>(int)!empty($TPagination) ), $TParam['liste'])
)
, $TPagination
- , array()
- )
- .$javaScript;
- }
- public function renderDatatable(&$db, $TField, $TParam) {
- $this->typeRender = 'dataTable';
- // on conserve db pour le traitement ultérieur des subQuery
- $TEntete=array();
- $TChamps=array();
-
- //$TParam['limit']['nbLine'] = 99999;
-
- $this->init($TParam);
-
- $this->parse_array($TEntete, $TChamps, $TParam,$TField);
- list($TTotal, $TTotalGroup)=$this->get_total($TChamps, $TParam);
- return $this->renderList($TEntete, $TChamps, $TTotal,$TTotalGroup,$TParam);
-
+
+ );
+
+ $javaScript;
}
+
public function renderArray(&$db,$TField, $TParam=array()) {
$this->typeRender = 'array';
// on conserve db pour le traitement ultérieur des subQuery
- $TEntete=array();
- $TChamps=array();
+ $THeader=array();
+ $TField=array();
$this->init($TParam);
- $this->parse_array($TEntete, $TChamps, $TParam,$TField);
- list($TTotal, $TTotalGroup)=$this->get_total($TChamps, $TParam);
+ $this->parse_array($THeader, $TField, $TParam,$TField);
+ list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam);
- $view_type = $this->getViewType($TParam);
+ $this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam);
- if($view_type == 'raw') {
- return $this->renderRAW($TEntete, $TChamps,$TTotal, $TParam);
- }
- if($view_type == 'chart') {
- return $this->renderChart($TEntete, $TChamps,$TTotal, $TParam);
- }
- else {
- return $this->renderList($TEntete, $TChamps,$TTotal,$TTotalGroup, $TParam);
- }
}
private function order_by($sql, &$TParam) {
@@ -848,7 +557,7 @@ class Listview {
// print_r($TParam['orderBy']);
if(!empty($TParam['orderBy'])) {
- if(strpos($sql,'LIMIT ')!==false) {
+ if(strpos($sql,'LIMIT ')!==false) { //TODO regex
list($sql, $sqlLIMIT) = explode('LIMIT ', $sql);
}
@@ -871,22 +580,8 @@ class Listview {
return $sql;
}
- private function parse_xml(&$db, &$TEntete, &$TChamps, &$TParam, $xmlString) {
- $xml = simplexml_load_string($xmlString);
- $this->THideFlip = array_flip($TParam['hide']);
-
- $first=true;
- foreach($xml->{$TParam['node']['main']}->{$TParam['node']['object']} as $node) {
- if($first) {
- $this->init_entete($TEntete, $TParam, $node);
- $first=false;
- }
-
- $this->set_line($TChamps, $TParam, $node);
- }
-
- }
- private function parse_array(&$TEntete, &$TChamps, &$TParam, $TField) {
+
+ private function parse_array(&$THeader, &$TField, &$TParam, $TField) {
$first=true;
$this->THideFlip = array_flip($TParam['hide']);
@@ -896,16 +591,16 @@ class Listview {
foreach($TField as $row) {
if($first) {
- $this->init_entete($TEntete, $TParam, $row);
+ $this->init_entete($THeader, $TParam, $row);
$first=false;
}
- $this->set_line($TChamps, $TParam, $row);
+ $this->set_line($TField, $TParam, $row);
}
}
- private function init_entete(&$TEntete, &$TParam, $currentLine) {
+ private function init_entete(&$THeader, &$TParam, $currentLine) {
$TField=$TFieldVisibility=array();
@@ -977,7 +672,7 @@ class Listview {
if($visible) {
$lastfield = $field;
- $TEntete[$field] = array(
+ $THeader[$field] = array(
'libelle'=>$libelle
,'order'=>((in_array($field, $TParam['orderby']['noOrder']) || $this->typeRender != 'sql') ? 0 : 1)
,'width'=>(!empty($TParam['size']['width'][$field]) ? $TParam['size']['width'][$field] : 'auto')
@@ -989,19 +684,15 @@ class Listview {
}
if(!empty($selectedfields) && !empty($lastfield)) {
- $TEntete[$lastfield]['more']=''.$selectedfields.'
';
+ $THeader[$lastfield]['more']=''.$selectedfields.'
';
}
- /*if(!empty($TParam['search']) && !empty($TEntete)) {
- $TEntete['actions']=array('libelle'=>'', 'order'=>0);
- }*/
-
}
private function in_view(&$TParam, $line_number) {
global $conf;
-// var_dump($_REQUEST['get-all-for-export']);
+
if(!empty($_REQUEST['get-all-for-export'])) return true; // doit être dans la vue
$page_number = !empty($TParam['limit']['page']) ? $TParam['limit']['page'] : 1;
@@ -1014,11 +705,11 @@ class Listview {
else return false;
}
- private function set_line(&$TChamps, &$TParam, $currentLine) {
+ private function set_line(&$TField, &$TParam, $currentLine) {
global $conf;
- $line_number = count($TChamps);
+ $line_number = count($TField);
if($this->in_view($TParam,$line_number)) {
@@ -1114,67 +805,7 @@ class Listview {
}
}
}
- $TChamps[] = $row;
- }
-
- private function getBind(&$TParam) {
-
- $TBind = array();
- foreach($this->TBind as $k=>$v) {
- if(!empty($TParam['operator'][$k]) && $TParam['operator'][$k] == 'IN') {
-
- if($v==='')$TBind[$k] =array("'0'");
- else $TBind[$k] =explode(',', $v);
-
- }
- else{
- $TBind[$k] = $v;
- }
-
- }
-
- return $TBind;
- }
-
- private function getSQL(&$PDOdb,$sql,&$TParam) {
- global $user,$conf;
-
- $sql=strtr($sql,array(
- '@current_user@'=>$user->id
- ));
-
- //AA oui c'est moche mais le bindParam ne prends pas en compte les tableaux pour le IN ce qui est super pénalisant. En attendant de refaire mieux ou d'un coup de main
- $TBind = $this->getBind($TParam);
-
- $sql = preg_replace_callback('/(:[a-z])\w+/i',function($matches) use($TBind,$PDOdb) {
- $field = substr($matches[0],1);
- if(isset($TBind[$field]) || is_null($TBind[$field]) ) {
-
- if(is_array($TBind[$field])) {
- $r = '';
- foreach($TBind[$field] as $v ){
- if(!empty($r))$r.=',';
- $r.=$PDOdb->quote($v);
- }
-
- return $r;
-
- }
- else if(strpos($TBind[$field],' IS NULL') === false) {
- return $PDOdb->quote($TBind[$field]);
- }
- else {
- return $TBind[$field];
- }
- }
- else {
- return 'errorBindingField '.$field;
- }
-
- }, $sql);
-
-
- return $sql;
+ $TField[] = $row;
}
private function limitSQL($sql,&$TParam) {
@@ -1188,29 +819,26 @@ class Listview {
return $sql;
}
- private function parse_sql(&$PDOdb, &$TEntete, &$TChamps,&$TParam, $sql, $TBind=array()) {
+ private function parse_sql( &$THeader, &$TField,&$TParam, $sql) {
+ global $db;
- //$sql.=' LIMIT '.($TParam['limit']['page']*$TParam['limit']['nbLine']).','.$TParam['limit']['nbLine'];
- $sql = $this->limitSQL($sql, $TParam);
+ $this->sql = $this->limitSQL($sql, $TParam);
$this->TTotalTmp=array();
- $this->sql = $this->getSQL($PDOdb,$sql,$TParam);
$this->THideFlip = array_flip($TParam['hide']);
- $res = $PDOdb->Execute($this->sql);
+ $res = $db->query($this->sql);
$first=true;
- while($currentLine = $PDOdb->Get_line()) {
+ while($currentLine = $db->fetch_object($res)) {
if($first) {
- $this->init_entete($TEntete, $TParam, $currentLine);
+ $this->init_entete($THeader, $TParam, $currentLine);
$first = false;
}
- $this->set_line($TChamps, $TParam, $currentLine);
+ $this->set_line($TField, $TParam, $currentLine);
}
-//pre($TChamps);exit;
-
}
}
diff --git a/htdocs/core/js/listview.js b/htdocs/core/js/listview.js
new file mode 100644
index 00000000000..1157c2ef4b8
--- /dev/null
+++ b/htdocs/core/js/listview.js
@@ -0,0 +1,143 @@
+var TListTBS_include = true;
+
+function TListTBS_OrderDown(idListe, column) {
+ var base_url = document.location.href;
+
+ base_url = TListTBS_recup_form_param(idListe,base_url);
+ base_url = TListTBS_removeParam(base_url,'TListTBS['+encodeURIComponent(idListe)+'][orderBy]');
+
+ base_url = TListTBS_removeParam(base_url,'get-all-for-export');
+
+ document.location.href=TListTBS_modifyUrl(base_url,"TListTBS["+encodeURIComponent(idListe)+"][orderBy]["+encodeURIComponent(column)+"]","DESC");
+}
+function TListTBS_OrderUp(idListe, column) {
+
+ var base_url = document.location.href;
+
+ base_url = TListTBS_recup_form_param(idListe,base_url);
+ base_url = TListTBS_removeParam(base_url,'TListTBS['+encodeURIComponent(idListe)+'][orderBy]');
+
+ base_url = TListTBS_removeParam(base_url,'get-all-for-export');
+
+ document.location.href=TListTBS_modifyUrl(base_url,"TListTBS["+encodeURIComponent(idListe)+"][orderBy]["+encodeURIComponent(column)+"]","ASC");
+}
+function TListTBS_modifyUrl(strURL,paramName,paramNewValue){
+ if (strURL.indexOf(paramName+'=')!=-1){
+
+ var strFirstPart=strURL.substring(0,strURL.indexOf(paramName+'=',0))+paramName+'=';
+ var strLastPart="";
+ if (strURL.indexOf('&',strFirstPart.length-1)>0)
+ strLastPart=strURL.substring(strURL.indexOf('&',strFirstPart.length-1),strURL.length);
+ strURL=strFirstPart+paramNewValue+strLastPart;
+ }
+ else{
+ if (strURL.search('=')!=-1) // permet de verifier s'il y a dej� des param�tres dans l'URL
+ strURL+='&'+paramName+'='+paramNewValue;
+ else
+ strURL+='?'+paramName+'='+paramNewValue;
+ }
+
+ return strURL;
+}
+function TListTBS_removeParam(strURL, paramMask) {
+ var cpt=0;
+ var url = '';
+
+ while(strURL.indexOf(paramMask)!=-1 && cpt++ <50){
+ var strFirstPart= strURL.substring(0,strURL.indexOf(paramMask)-1);
+
+ var strLastPart='';
+ if (strURL.indexOf('&',strFirstPart.length+1)>0) {
+ strLastPart = strURL.substring(strURL.indexOf('&',strFirstPart.length+1),strURL.length);
+ }
+
+ url = strFirstPart+strLastPart;
+
+ }
+
+ if(url=='')url = strURL;
+
+ return url;
+}
+
+function TListTBS_recup_form_param(idListe,base_url) {
+
+ $('#'+idListe+' tr.barre-recherche [listviewtbs],#'+idListe+' tr.barre-recherche-head input,#'+idListe+' tr.barre-recherche-head select,#'+idListe+' div.tabsAction input[listviewtbs]').each(function(i,item) {
+ if($(item).attr("name")) {
+ base_url = TListTBS_modifyUrl(base_url, $(item).attr("name") , $(item).val());
+ }
+
+ });
+
+ return base_url;
+}
+
+function TListTBS_GoToPage(idListe,pageNumber){
+
+ var base_url = document.location.href;
+
+ base_url = TListTBS_recup_form_param(idListe,base_url);
+ base_url =TListTBS_modifyUrl(base_url,"TListTBS["+encodeURIComponent(idListe)+"][page]",pageNumber);
+
+ base_url = TListTBS_removeParam(base_url,'get-all-for-export');
+
+ document.location.href=base_url;
+}
+function TListTBS_submitSearch(obj) {
+
+ $(obj).closest('form').submit();
+ //console.log($(obj).closest('form'));
+}
+function TListTBS_launch_downloadAs(mode,url,token,session_name) {
+ $('#listTBSdAS_export_form').remove();
+
+ $form = $('');
+ $form.append('');
+ $form.append('');
+ $form.append('');
+
+ $('body').append($form);
+
+ $('#listTBSdAS_export_form').submit();
+
+}
+
+function TListTBS_downloadAs(obj, mode,url,token,session_name) {
+
+ $form = $(obj).closest('form');
+ $div = $form.find('div.tabsAction');
+ $div.append('');
+ $div.append('');
+ $div.append('');
+ $div.append('');
+ $div.append('');
+
+ TListTBS_submitSearch(obj);
+}
+
+$(document).ready(function() {
+ $('tr.barre-recherche input').keypress(function(e) {
+ if(e.which == 13) {
+
+ var id_list = $(this).closest('table').attr('id');
+
+ $('#'+id_list+' .list-search-link').click();
+
+ }
+ });
+
+ var $_GET = {};
+
+ document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
+ function decode(s) {
+ return decodeURIComponent(s.split("+").join(" "));
+ }
+
+ $_GET[decode(arguments[1])] = decode(arguments[2]);
+ });
+
+ if(typeof $_GET["get-all-for-export"] != "undefined") {
+ TListTBS_launch_downloadAs($_GET["mode"],$_GET["url"],$_GET["token"],$_GET["session_name"]);
+ }
+
+});
diff --git a/htdocs/inventory/class/inventory.class.php b/htdocs/inventory/class/inventory.class.php
index 60a8dde8652..f158ab260cf 100644
--- a/htdocs/inventory/class/inventory.class.php
+++ b/htdocs/inventory/class/inventory.class.php
@@ -61,7 +61,7 @@ class Inventory extends CoreObject
*/
public $title;
- private $__fields=array(
+ protected $__fields=array(
'fk_warehouse'=>array('type'=>'integer','index'=>true)
,'entity'=>array('type'=>'integer','index'=>true)
,'status'=>array('type'=>'integer','index'=>true)
@@ -69,20 +69,14 @@ class Inventory extends CoreObject
,'title'=>array('type'=>'string')
);
- function __construct(&$db)
+ function __construct(DoliDB &$db)
{
$this->db = &$db;
parent::init();
- $this->_init_vars();
-
- $this->start();
-
- $this->setChild('Inventorydet','fk_inventory');
-
- $this->status = 0;
+ $this->status = 0;
$this->entity = $conf->entity;
$this->errors = array();
$this->amount = 0;
@@ -94,12 +88,12 @@ class Inventory extends CoreObject
usort($this->Inventorydet, array('Inventory', 'customSort'));
}
- function load(&$PDOdb, $id,$annexe = true)
+ function fetch($id,$annexe = true)
{
if(!$annexe) $this->withChild = false;
- $res = parent::load($PDOdb, $id);
+ $res = parent::fetch($id);
$this->sort_det();
$this->amount = 0;
@@ -124,7 +118,7 @@ class Inventory extends CoreObject
return $r;
}
- function changePMP(&$PDOdb) {
+ function changePMP() {
foreach ($this->Inventorydet as $k => &$Inventorydet)
{
@@ -133,16 +127,9 @@ class Inventory extends CoreObject
$Inventorydet->pmp = $Inventorydet->new_pmp;
$Inventorydet->new_pmp = 0;
- $PDOdb->Execute("UPDATE ".MAIN_DB_PREFIX."product as p SET pmp = ".$Inventorydet->pmp."
+ $db->query("UPDATE ".MAIN_DB_PREFIX."product as p SET pmp = ".$Inventorydet->pmp."
WHERE rowid = ".$Inventorydet->fk_product );
- if((float)DOL_VERSION<4.0) {
-
- $PDOdb->Execute("UPDATE ".MAIN_DB_PREFIX."product_stock SET pmp=".$Inventorydet->pmp."
- WHERE fk_entrepot = ".$this->fk_warehouse." AND fk_product = ".$Inventorydet->fk_product) ;
-
- }
-
}
}
@@ -150,15 +137,15 @@ class Inventory extends CoreObject
}
- function save(&$PDOdb)
+ function update()
{
//si on valide l'inventaire on sauvegarde le stock à cette instant
if ($this->status)
{
- $this->regulate($PDOdb);
+ $this->regulate();
}
- parent::save($PDOdb);
+ parent::update();
}
function set_values($Tab)
@@ -188,24 +175,24 @@ class Inventory extends CoreObject
return parent::set_values($Tab);
}
- function deleteAllLine(&$PDOdb) {
+ function deleteAllLine() {
foreach($this->Inventorydet as &$det) {
$det->to_delete = true;
}
- $this->save($PDOdb);
+ $this->update();
$this->Inventorydet=array();
}
- function add_product(&$PDOdb, $fk_product, $fk_entrepot='') {
+ function add_product($fk_product, $fk_entrepot='') {
- $k = $this->addChild($PDOdb, 'Inventorydet');
+ $k = $this->addChild('Inventorydet');
$det = &$this->Inventorydet[$k];
- $det->fk_inventory = $this->getId();
+ $det->fk_inventory = $this->id;
$det->fk_product = $fk_product;
$det->fk_warehouse = empty($fk_entrepot) ? $this->fk_warehouse : $fk_entrepot;
@@ -213,16 +200,16 @@ class Inventory extends CoreObject
$date = $this->get_date('date_inventory', 'Y-m-d');
if(empty($date))$date = $this->get_date('date_cre', 'Y-m-d');
- $det->setStockDate($PDOdb, $date , $fk_entrepot);
+ $det->setStockDate( $date , $fk_entrepot);
}
- function correct_stock($fk_product, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $inventorycode='')
+ function correct_stock($fk_product, $fk_warehouse, $nbpiece, $movement, $label='', $price=0, $inventorycode='')
{
global $conf, $db, $langs, $user;
/* duplication method product to add datem */
- if ($id_entrepot)
+ if ($fk_warehouse)
{
$db->begin();
@@ -234,7 +221,7 @@ class Inventory extends CoreObject
$datem = empty($conf->global->INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT) ? dol_now() : $this->date_inventory;
$movementstock=new MouvementStock($db);
- $result=$movementstock->_create($user,$fk_product,$id_entrepot,$op[$movement],$movement,$price,$label,$inventorycode, $datem);
+ $result=$movementstock->_create($user,$fk_product,$fk_warehouse,$op[$movement],$movement,$price,$label,$inventorycode, $datem);
if ($result >= 0)
{
@@ -252,7 +239,7 @@ class Inventory extends CoreObject
}
}
- function regulate(&$PDOdb)
+ function regulate()
{
global $db,$user,$langs,$conf;
@@ -288,10 +275,10 @@ class Inventory extends CoreObject
$nbpiece = abs($Inventorydet->qty_regulated);
$movement = (int) ($Inventorydet->qty_view < $Inventorydet->qty_stock); // 0 = add ; 1 = remove
- $href = dol_buildpath('/inventory/inventory.php?id='.$this->getId().'&action=view', 1);
+ $href = dol_buildpath('/inventory/inventory.php?id='.$this->id.'&action=view', 1);
if(empty($this->title))
- $this->correct_stock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStock', $href, $this->getId()));
+ $this->correct_stock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStock', $href, $this->id));
else
$this->correct_stock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStockWithNomInventaire', $href, $this->title));
}
@@ -306,16 +293,14 @@ class Inventory extends CoreObject
}
static function getLink($id) {
- global $langs;
+ global $langs,$db;
- $PDOdb=new TPDOdb;
+ $i = new Inventory($db);
+ $i->fetch($id, false);
- $i = new Inventory;
- $i->load($PDOdb, $id, false);
+ $title = !empty($i->title) ? $i->title : $langs->trans('inventoryTitle').' '.$i->id;
- $title = !empty($i->title) ? $i->title : $langs->trans('inventoryTitle').' '.$i->getId();
-
- return ''.img_picto('','object_list.png','',0).' '.$title.'';
+ return ''.img_picto('','object_list.png','',0).' '.$title.'';
}
@@ -354,7 +339,7 @@ class Inventorydet extends CoreObject
public $pa;
public $new_pmp;
- private $__fields=array(
+ protected $__fields=array(
'fk_inventory'=>array('type'=>'int')
,'fk_warehouse'=>array('type'=>'int')
,'fk_product'=>array('type'=>'int')
@@ -385,11 +370,11 @@ class Inventorydet extends CoreObject
}
- function load(&$PDOdb, $id)
+ function fetch($id)
{
global $conf;
- $res = parent::load($PDOdb, $id);
+ $res = parent::fetch($id);
$this->load_product();
$this->fetch_current_pa();
@@ -431,9 +416,9 @@ class Inventorydet extends CoreObject
AND datem<='".$date." 23:59:59'
ORDER BY datem DESC LIMIT 1";
- $PDOdb->Execute($sql);
+ $res = $db->query($sql);
- if($obj = $PDOdb->Get_line()) {
+ if($obj = $db->fetch_object($res)) {
$last_pa = $obj->price;
}
@@ -467,7 +452,7 @@ class Inventorydet extends CoreObject
ORDER BY datem DESC";
//echo $sql.'
';
- $PDOdb->Execute($sql);
+ $db->query($sql);
$TMouvementStock = $PDOdb->Get_All();
$laststock = $stock;
$lastpmp = $pmp;