Refactoring class
This commit is contained in:
parent
cb576e6c99
commit
2fc74b4962
@ -207,45 +207,44 @@ class Listview
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function search($sql,&$TParam) {
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $sql
|
||||||
|
* @param $TParam
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function search($sql, &$TParam)
|
||||||
|
{
|
||||||
$ListPOST = GETPOST('Listview');
|
$ListPOST = GETPOST('Listview');
|
||||||
|
|
||||||
if(!empty($ListPOST[$this->id]['search'])) {
|
if(!empty($ListPOST[$this->id]['search']))
|
||||||
|
{
|
||||||
$sqlGROUPBY='';
|
$sqlGROUPBY='';
|
||||||
if(strpos($sql,'GROUP BY')!==false) { //TODO regex
|
if(strpos($sql,'GROUP BY')!==false)
|
||||||
|
{
|
||||||
list($sql, $sqlGROUPBY) = explode('GROUP BY', $sql);
|
list($sql, $sqlGROUPBY) = explode('GROUP BY', $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strpos($sql,'WHERE ')===false)$sql.=' WHERE 1 '; //TODO regex
|
if(strpos($sql,'WHERE ')===false) $sql.=' WHERE 1 ';
|
||||||
//TODO $value = GETPOST('Listview_'.$this->id.'_search_'.$key) ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'month'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'day'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'year') ) : '';
|
|
||||||
|
|
||||||
foreach($ListPOST[$this->id]['search'] as $key=>$value)
|
foreach($ListPOST[$this->id]['search'] as $key => $value)
|
||||||
{
|
{
|
||||||
$TsKey = $this->getSearchKey($key, $TParam);
|
$TsKey = $this->getSearchKey($key, $TParam);
|
||||||
|
|
||||||
//if (!empty($value)) var_dump($TsKey, $TsBindKey, '==================================');
|
|
||||||
$TSQLMore = array();
|
$TSQLMore = array();
|
||||||
|
|
||||||
$allow_is_null = $this->getSearchNull($key,$TParam);
|
$allow_is_null = $this->getSearchNull($key,$TParam);
|
||||||
$search_on_null = false; //TODO useless
|
|
||||||
|
|
||||||
foreach ($TsKey as $i => &$sKey)
|
foreach ($TsKey as $i => &$sKey)
|
||||||
{
|
{
|
||||||
if($allow_is_null && !empty($ListPOST[$this->id]['search_on_null'][$key]))
|
if($allow_is_null && !empty($ListPOST[$this->id]['search_on_null'][$key]))
|
||||||
{
|
{
|
||||||
$TSQLMore[] = $sKey.' IS NULL ';
|
$TSQLMore[] = $sKey.' IS NULL ';
|
||||||
$search_on_null = true;
|
|
||||||
|
|
||||||
$value = '';
|
$value = '';
|
||||||
}
|
}
|
||||||
elseif($allow_is_null)
|
|
||||||
|
// Do not use empty() function, statut 0 exist
|
||||||
|
if($value != '')
|
||||||
{
|
{
|
||||||
null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($value!='') { // pas empty car biensûr le statut = 0 existe dans de nombreux cas
|
|
||||||
|
|
||||||
if(isset($TParam['type'][$key]) && ($TParam['type'][$key]==='date' || $TParam['type'][$key]==='datetime'))
|
if(isset($TParam['type'][$key]) && ($TParam['type'][$key]==='date' || $TParam['type'][$key]==='datetime'))
|
||||||
{
|
{
|
||||||
$this->addSqlFromTypeDate($TSQLMore, $value, $sKey);
|
$this->addSqlFromTypeDate($TSQLMore, $value, $sKey);
|
||||||
@ -265,15 +264,18 @@ class Listview
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($sqlGROUPBY!='') $sql.=' GROUP BY '.$sqlGROUPBY;
|
if($sqlGROUPBY!='') $sql.=' GROUP BY '.$sqlGROUPBY;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render($sql,$TParam=array()) {
|
/**
|
||||||
|
* @param $sql
|
||||||
|
* @param array $TParam
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function render($sql, $TParam=array())
|
||||||
|
{
|
||||||
$THeader=array();
|
$THeader=array();
|
||||||
$TField=array();
|
$TField=array();
|
||||||
|
|
||||||
@ -287,10 +289,15 @@ class Listview
|
|||||||
list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam);
|
list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam);
|
||||||
|
|
||||||
return $this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam);
|
return $this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setSearch(&$THeader, &$TParam) {
|
/**
|
||||||
|
* @param $THeader
|
||||||
|
* @param $TParam
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function setSearch(&$THeader, &$TParam)
|
||||||
|
{
|
||||||
global $langs, $form;
|
global $langs, $form;
|
||||||
|
|
||||||
if(empty($TParam['search'])) return array();
|
if(empty($TParam['search'])) return array();
|
||||||
@ -299,32 +306,33 @@ class Listview
|
|||||||
|
|
||||||
$nb_search_in_bar = 0;
|
$nb_search_in_bar = 0;
|
||||||
|
|
||||||
if(!empty($TParam['search'])) {
|
if(!empty($TParam['search']))
|
||||||
foreach($THeader as $key=>$libelle) { // init
|
{
|
||||||
|
foreach($THeader as $key => $libelle)
|
||||||
|
{
|
||||||
if(empty($TSearch[$key]))$TSearch[$key]='';
|
if(empty($TSearch[$key]))$TSearch[$key]='';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ListPOST = GETPOST('Listview');
|
$ListPOST = GETPOST('Listview');
|
||||||
|
foreach($TParam['search'] as $key => $param_search)
|
||||||
foreach($TParam['search'] as $key=>$param_search) {
|
{
|
||||||
|
|
||||||
$value = isset($ListPOST[$this->id]['search'][$key]) ? $ListPOST[$this->id]['search'][$key] : '';
|
$value = isset($ListPOST[$this->id]['search'][$key]) ? $ListPOST[$this->id]['search'][$key] : '';
|
||||||
|
|
||||||
$typeRecherche = (is_array($param_search) && isset($param_search['recherche'])) ? $param_search['recherche'] : $param_search;
|
$typeRecherche = (is_array($param_search) && isset($param_search['recherche'])) ? $param_search['recherche'] : $param_search;
|
||||||
|
|
||||||
if(is_array($typeRecherche)) {
|
if(is_array($typeRecherche))
|
||||||
|
{
|
||||||
$fsearch=$form->selectarray('Listview['.$this->id.'][search]['.$key.']', $typeRecherche,$value,1);
|
$fsearch=$form->selectarray('Listview['.$this->id.'][search]['.$key.']', $typeRecherche,$value,1);
|
||||||
}
|
}
|
||||||
else if($typeRecherche==='calendar') {
|
else if($typeRecherche==='calendar')
|
||||||
|
{
|
||||||
$value = GETPOST('Listview_'.$this->id.'_search_'.$key) ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'month'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'day'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'year') ) : '';
|
$value = GETPOST('Listview_'.$this->id.'_search_'.$key) ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'month'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'day'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'year') ) : '';
|
||||||
|
|
||||||
$fsearch = $form->select_date($value, 'Listview_'.$this->id.'_search_'.$key,0, 0, 1, "", 1, 0, 1);
|
$fsearch = $form->select_date($value, 'Listview_'.$this->id.'_search_'.$key,0, 0, 1, "", 1, 0, 1);
|
||||||
//$fsearch=$form->calendrier('','Listview['.$this->id.'][search]['.$key.']',$value,10,10,' listviewtbs="calendar" ');
|
|
||||||
}
|
}
|
||||||
else if($typeRecherche==='calendars') {
|
else if($typeRecherche==='calendars')
|
||||||
|
{
|
||||||
$value_start = GETPOST('Listview_'.$this->id.'_search_'.$key.'_start') ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_startmonth'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_startday'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_startyear') ) : '';
|
$value_start = GETPOST('Listview_'.$this->id.'_search_'.$key.'_start') ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_startmonth'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_startday'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_startyear') ) : '';
|
||||||
$value_end = GETPOST('Listview_'.$this->id.'_search_'.$key.'_end') ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_endmonth'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_endday'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_endyear') ) : '';
|
$value_end = GETPOST('Listview_'.$this->id.'_search_'.$key.'_end') ? mktime(0,0,0, (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_endmonth'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_endday'), (int)GETPOST('Listview_'.$this->id.'_search_'.$key.'_endyear') ) : '';
|
||||||
|
|
||||||
@ -332,96 +340,113 @@ class Listview
|
|||||||
. $form->select_date($value_end, 'Listview_'.$this->id.'_search_'.$key.'_end',0, 0, 1, "", 1, 0, 1);
|
. $form->select_date($value_end, 'Listview_'.$this->id.'_search_'.$key.'_end',0, 0, 1, "", 1, 0, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(is_string($typeRecherche)) {
|
else if(is_string($typeRecherche))
|
||||||
|
{
|
||||||
$fsearch=$TParam['search'][$key];
|
$fsearch=$TParam['search'][$key];
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
$fsearch='<input type="text" name="Listview['.$this->id.'][search]['.$key.']" id="Listview['.$this->id.'][search]['.$key.']" value="'.$value.'" size="15" />';
|
$fsearch='<input type="text" name="Listview['.$this->id.'][search]['.$key.']" id="Listview['.$this->id.'][search]['.$key.']" value="'.$value.'" size="15" />';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($param_search['allow_is_null'])) {
|
if(!empty($param_search['allow_is_null']))
|
||||||
|
{
|
||||||
$valueNull = isset($ListPOST[$this->id]['search_on_null'][$key]) ? 1 : 0;
|
$valueNull = isset($ListPOST[$this->id]['search_on_null'][$key]) ? 1 : 0;
|
||||||
$fsearch.=' '.$form->checkbox1('', 'Listview['.$this->id.'][search_on_null]['.$key.']',1, $valueNull,' onclick=" if($(this).is(\':checked\')){ $(this).prev().val(\'\'); }" ').img_help(1, $langs->trans('SearchOnNUllValue'));
|
$fsearch.=' '.$form->checkbox1('', 'Listview['.$this->id.'][search_on_null]['.$key.']',1, $valueNull,' onclick=" if($(this).is(\':checked\')){ $(this).prev().val(\'\'); }" ').img_help(1, $langs->trans('SearchOnNUllValue'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!empty($THeader[$key]))
|
||||||
if(!empty($THeader[$key])) {
|
{
|
||||||
$TSearch[$key] = $fsearch;
|
$TSearch[$key] = $fsearch;
|
||||||
$nb_search_in_bar++;
|
$nb_search_in_bar++;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
|
|
||||||
$label = !empty($TParam['title'][$key]) ? $TParam['title'][$key] : $key ;
|
$label = !empty($TParam['title'][$key]) ? $TParam['title'][$key] : $key ;
|
||||||
$TParam['list']['head_search'].='<div><span style="min-width:200px;display:inline-block;">'.$libelle.'</span> '.$fsearch.'</div>';
|
$TParam['list']['head_search'].='<div><span style="min-width:200px;display:inline-block;">'.$libelle.'</span> '.$fsearch.'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$search_button = ' <a href="#" onclick="Listview_submitSearch(this);" class="list-search-link">'.img_search().'</a>';
|
$search_button = ' <a href="#" onclick="Listview_submitSearch(this);" class="list-search-link">'.img_search().'</a>';
|
||||||
|
|
||||||
if(!empty($TParam['list']['head_search'])) {
|
if(!empty($TParam['list']['head_search']))
|
||||||
|
{
|
||||||
$TParam['list']['head_search']='<div style="float:right;">'.$search_button.'</div>'.$TParam['list']['head_search'];
|
$TParam['list']['head_search']='<div style="float:right;">'.$search_button.'</div>'.$TParam['list']['head_search'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if($nb_search_in_bar>0) {
|
if($nb_search_in_bar>0)
|
||||||
|
{
|
||||||
end($TSearch);
|
end($TSearch);
|
||||||
list($key,$v) = each($TSearch);
|
list($key,$v) = each($TSearch);
|
||||||
$TSearch[$key].=$search_button;
|
$TSearch[$key].=$search_button;
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
$TSearch=array();
|
$TSearch=array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $TSearch;
|
return $TSearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Function analysant et totalisant une colonne
|
* Function to analyse and calculate the total from a column
|
||||||
* Supporté : sum, average
|
*
|
||||||
|
* @param $TField
|
||||||
|
* @param $TParam
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function get_total(&$TField, &$TParam) {
|
private function get_total(&$TField, &$TParam)
|
||||||
|
{
|
||||||
$TTotal=$TTotalGroup=array();
|
$TTotal=$TTotalGroup=array();
|
||||||
|
|
||||||
if(!empty($TParam['math']) && !empty($TField[0])) {
|
if(!empty($TParam['math']) && !empty($TField[0]))
|
||||||
|
{
|
||||||
foreach($TField[0] as $field=>$value) {
|
foreach($TField[0] as $field=>$value)
|
||||||
|
{
|
||||||
$TTotal[$field]='';
|
$TTotal[$field]='';
|
||||||
$TTotalGroup[$field] = '';
|
$TTotalGroup[$field] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($TParam['math'] as $field=>$typeMath){
|
foreach($TParam['math'] as $field=>$typeMath)
|
||||||
|
{
|
||||||
if(is_array($typeMath)) {
|
if(is_array($typeMath))
|
||||||
|
{
|
||||||
$targetField = $typeMath[1];
|
$targetField = $typeMath[1];
|
||||||
$typeMath = $typeMath[0];
|
$typeMath = $typeMath[0];
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
$targetField = $field;
|
$targetField = $field;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($typeMath == 'groupsum') {
|
if($typeMath == 'groupsum')
|
||||||
|
{
|
||||||
$TTotalGroup[$field] = array('target'=>$targetField, 'values'=> $this->TTotalTmp['@groupsum'][$targetField]);
|
$TTotalGroup[$field] = array('target'=>$targetField, 'values'=> $this->TTotalTmp['@groupsum'][$targetField]);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if($typeMath=='average') {
|
else if($typeMath=='average')
|
||||||
|
{
|
||||||
$TTotal[$field]=array_sum($this->TTotalTmp[$targetField]) / count($this->TTotalTmp[$targetField]);
|
$TTotal[$field]=array_sum($this->TTotalTmp[$targetField]) / count($this->TTotalTmp[$targetField]);
|
||||||
}
|
}
|
||||||
elseif($typeMath=='count') {
|
elseif($typeMath=='count')
|
||||||
|
{
|
||||||
$TTotal[$field]=count($this->TTotalTmp[$targetField]);
|
$TTotal[$field]=count($this->TTotalTmp[$targetField]);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
$TTotal[$field]=array_sum($this->TTotalTmp[$targetField]);
|
$TTotal[$field]=array_sum($this->TTotalTmp[$targetField]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($TTotal,$TTotalGroup);
|
return array($TTotal,$TTotalGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getJS() {
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getJS()
|
||||||
|
{
|
||||||
$javaScript = '<script language="javascript">
|
$javaScript = '<script language="javascript">
|
||||||
if(typeof(Listview_include)=="undefined") {
|
if(typeof(Listview_include)=="undefined") {
|
||||||
document.write("<script type=\"text/javascript\" src=\"'.DOL_URL_ROOT.'/core/js/listview.js?version='.DOL_VERSION.'\"></scr");
|
document.write("<script type=\"text/javascript\" src=\"'.DOL_URL_ROOT.'/core/js/listview.js?version='.DOL_VERSION.'\"></scr");
|
||||||
@ -432,55 +457,66 @@ class Listview
|
|||||||
return $javaScript;
|
return $javaScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setExport(&$TParam,$TField,$THeader) {
|
/**
|
||||||
|
* @param $TParam
|
||||||
|
* @param $TField
|
||||||
|
* @param $THeader
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function setExport(&$TParam, $TField, $THeader)
|
||||||
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
$Tab=array();
|
$Tab=array();
|
||||||
if(!empty($TParam['export'])) {
|
if(!empty($TParam['export']))
|
||||||
|
{
|
||||||
$token = GETPOST('token');
|
$token = GETPOST('token');
|
||||||
if(empty($token)) $token = md5($this->id.time().rand(1,9999));
|
if(empty($token)) $token = md5($this->id.time().rand(1,9999));
|
||||||
|
|
||||||
$_SESSION['token_list_'.$token] = gzdeflate( serialize( array(
|
$_SESSION['token_list_'.$token] = gzdeflate( serialize( array(
|
||||||
'title'=>$this->title
|
'title'=>$this->title,
|
||||||
,'sql'=>$this->sql
|
'sql'=>$this->sql,
|
||||||
,'TBind'=>$this->TBind
|
'TBind'=>$this->TBind,
|
||||||
,'TChamps'=>$TField
|
'TChamps'=>$TField,
|
||||||
,'TEntete'=>$THeader
|
'TEntete'=>$THeader
|
||||||
) ) );
|
)));
|
||||||
|
|
||||||
foreach($TParam['export'] as $mode_export) {
|
|
||||||
|
|
||||||
|
foreach($TParam['export'] as $mode_export)
|
||||||
|
{
|
||||||
$Tab[] = array(
|
$Tab[] = array(
|
||||||
'label'=>$langs->trans('Export'.$mode_export)
|
'label'=>$langs->trans('Export'.$mode_export),
|
||||||
,'url'=>dol_buildpath('/abricot/downlist.php',1)
|
'url'=>dol_buildpath('/abricot/downlist.php',1),
|
||||||
,'mode'=>$mode_export
|
'mode'=>$mode_export,
|
||||||
,'token'=>$token
|
'token'=>$token,
|
||||||
,'session_name'=>session_name()
|
'session_name'=>session_name()
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $Tab;
|
return $Tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addTotalGroup($TField,$TTotalGroup) {
|
/**
|
||||||
|
* @param $TField
|
||||||
|
* @param $TTotalGroup
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function addTotalGroup($TField, $TTotalGroup)
|
||||||
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
$Tab=array();
|
$Tab=array();
|
||||||
|
|
||||||
$proto_total_line = array();
|
$proto_total_line = array();
|
||||||
|
|
||||||
$tagbase = $old_tagbase = null;
|
$tagbase = $old_tagbase = null;
|
||||||
|
|
||||||
$addGroupLine = false;
|
$addGroupLine = false;
|
||||||
|
|
||||||
foreach($TField as $k=>&$line) {
|
foreach($TField as $k=>&$line)
|
||||||
|
{
|
||||||
if(empty($proto_total_line)) {
|
if(empty($proto_total_line))
|
||||||
foreach($line as $field=>$value) {
|
{
|
||||||
|
foreach($line as $field=>$value)
|
||||||
|
{
|
||||||
$proto_total_line[$field] = '';
|
$proto_total_line[$field] = '';
|
||||||
}
|
}
|
||||||
$group_line = $proto_total_line;
|
$group_line = $proto_total_line;
|
||||||
@ -489,19 +525,19 @@ class Listview
|
|||||||
$addGroupLine = false;
|
$addGroupLine = false;
|
||||||
|
|
||||||
$tagbase = '';
|
$tagbase = '';
|
||||||
foreach($line as $field=>$value) {
|
foreach($line as $field=>$value)
|
||||||
|
{
|
||||||
if(!empty($TTotalGroup[$field])) {
|
if(!empty($TTotalGroup[$field]))
|
||||||
|
{
|
||||||
$tagbase.=$value.'|';
|
$tagbase.=$value.'|';
|
||||||
$group_line[$field] = '<div style="text-align:right; font-weight:bold; color:#552266;">'.(empty($value) ? $langs->trans('Empty') : $value ).' : </div>';
|
$group_line[$field] = '<div style="text-align:right; font-weight:bold; color:#552266;">'.(empty($value) ? $langs->trans('Empty') : $value ).' : </div>';
|
||||||
$group_line[$TTotalGroup[$field]['target']] = '<div style="text-align:right; font-weight:bold; color:#552266;">'.price($TTotalGroup[$field]['values'][$value]).'</div>';
|
$group_line[$TTotalGroup[$field]['target']] = '<div style="text-align:right; font-weight:bold; color:#552266;">'.price($TTotalGroup[$field]['values'][$value]).'</div>';
|
||||||
$addGroupLine = true;
|
$addGroupLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_null($old_tagbase) && $old_tagbase!=$tagbase && $addGroupLine) {
|
if(!is_null($old_tagbase) && $old_tagbase!=$tagbase && $addGroupLine)
|
||||||
// var_dump(array($k,$tagbase,$old_tagbase,$empty_line));
|
{
|
||||||
$Tab[] = $previous_group_line;
|
$Tab[] = $previous_group_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,30 +546,36 @@ class Listview
|
|||||||
$group_line = $proto_total_line;
|
$group_line = $proto_total_line;
|
||||||
|
|
||||||
$Tab[] = $line;
|
$Tab[] = $line;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if($addGroupLine) {
|
|
||||||
|
if($addGroupLine)
|
||||||
|
{
|
||||||
$Tab[] = $previous_group_line;
|
$Tab[] = $previous_group_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $Tab;
|
return $Tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderList(&$THeader, &$TField, &$TTotal,&$TTotalGroup, &$TParam) {
|
/**
|
||||||
|
* @param $THeader
|
||||||
|
* @param $TField
|
||||||
|
* @param $TTotal
|
||||||
|
* @param $TTotalGroup
|
||||||
|
* @param $TParam
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function renderList(&$THeader, &$TField, &$TTotal, &$TTotalGroup, &$TParam)
|
||||||
|
{
|
||||||
$TSearch = $this->setSearch($THeader, $TParam);
|
$TSearch = $this->setSearch($THeader, $TParam);
|
||||||
$TExport=$this->setExport($TParam, $TField, $THeader);
|
$TExport=$this->setExport($TParam, $TField, $THeader);
|
||||||
$TField = $this->addTotalGroup($TField,$TTotalGroup);
|
$TField = $this->addTotalGroup($TField,$TTotalGroup);
|
||||||
|
|
||||||
$out = $this->getJS();
|
$out = $this->getJS();
|
||||||
$out.=load_fiche_titre($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $TParam['limit']['page'], count($TField), 'title_products.png', 0, '', '', $limit);
|
$out.=load_fiche_titre($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $TParam['limit']['page'], count($TField), 'title_products.png', 0, '', '', $limit);
|
||||||
$out.='<table id="'.$this->id.'" class="liste" width="100%">
|
$out.='<table id="'.$this->id.'" class="liste" width="100%"><thead>';
|
||||||
<thead>';
|
|
||||||
|
|
||||||
if(!empty($TParam['list']['head_search'])) {
|
if(!empty($TParam['list']['head_search']))
|
||||||
|
{
|
||||||
$out.='<tr class="liste_titre barre-recherche-head">
|
$out.='<tr class="liste_titre barre-recherche-head">
|
||||||
<td colspan="'.count($THeader).'">'.$TParam['list']['head_search'].'</td>
|
<td colspan="'.count($THeader).'">'.$TParam['list']['head_search'].'</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
@ -541,7 +583,8 @@ class Listview
|
|||||||
|
|
||||||
$out.='<tr class="liste_titre">';
|
$out.='<tr class="liste_titre">';
|
||||||
|
|
||||||
foreach($THeader as $field=>$head) {
|
foreach($THeader as $field=>$head)
|
||||||
|
{
|
||||||
if(empty($head['width']))$head['width']='auto';
|
if(empty($head['width']))$head['width']='auto';
|
||||||
|
|
||||||
$out.='<th style="width:'.$head['width'].';text-align:'.$head['text-align'].'" class="liste_titre">'.$head['libelle'];
|
$out.='<th style="width:'.$head['width'].';text-align:'.$head['text-align'].'" class="liste_titre">'.$head['libelle'];
|
||||||
@ -557,12 +600,14 @@ class Listview
|
|||||||
|
|
||||||
$out.='</tr>';
|
$out.='</tr>';
|
||||||
|
|
||||||
if(count($TSearch)>0) {
|
if(count($TSearch)>0)
|
||||||
|
{
|
||||||
$out.='<tr class="liste_titre barre-recherche">';
|
$out.='<tr class="liste_titre barre-recherche">';
|
||||||
foreach($TSearch as $field=>$search) {
|
foreach($TSearch as $field=>$search)
|
||||||
|
{
|
||||||
$out.='<td class="liste_titre">'.$search.'</td>';
|
$out.='<td class="liste_titre">'.$search.'</td>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$out.='</tr>';
|
$out.='</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,50 +615,54 @@ class Listview
|
|||||||
|
|
||||||
$class='pair';
|
$class='pair';
|
||||||
|
|
||||||
if(empty($TField)) {
|
if(empty($TField))
|
||||||
$out.='<tr class="'.$class.'">
|
{
|
||||||
<td colspan="'.$TParam['list']['nb_columns'].'">'.$TParam['list']['messageNothing'].'</td></tr>';
|
$out.='<tr class="'.$class.'"><td colspan="'.$TParam['list']['nb_columns'].'">'.$TParam['list']['messageNothing'].'</td></tr>';
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
foreach($TField as $fields) { //TODO pagination limit
|
foreach($TField as $fields)
|
||||||
|
{
|
||||||
$class = ($class=='pair') ? 'impair' : 'pair';
|
$class = ($class=='pair') ? 'impair' : 'pair';
|
||||||
$out.='<tr class="'.$class.'"> <!-- '.$field.' -->';
|
$out.='<tr class="'.$class.'"> <!-- '.$field.' -->';
|
||||||
|
|
||||||
foreach($fields as $field=>$value) {
|
foreach($fields as $field=>$value)
|
||||||
|
{
|
||||||
$out.='<td field="'.$field.'">'.$value.'</td>';
|
$out.='<td field="'.$field.'">'.$value.'</td>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$out.='</tr>';
|
$out.='</tr>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$out.='</tbody>';
|
$out.='</tbody>';
|
||||||
|
|
||||||
if(!empty($TParam['list']['haveTotal'])) {
|
if(!empty($TParam['list']['haveTotal']))
|
||||||
$out.='<tfoot>
|
{
|
||||||
<tr class="liste_total">';
|
$out.='<tfoot><tr class="liste_total">';
|
||||||
|
|
||||||
foreach($TTotal as $field=>$total) {
|
foreach($TTotal as $field=>$total)
|
||||||
|
{
|
||||||
$out.='<td align="right" field="'.$field.'">'.price($total).'</td>';
|
$out.='<td align="right" field="'.$field.'">'.price($total).'</td>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$out.='</tr></tfoot>';
|
$out.='</tr></tfoot>';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$out.='</table>';
|
$out.='</table>';
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderArray(&$db,$TField, $TParam=array()) {
|
/**
|
||||||
|
* @param $db
|
||||||
|
* @param $TField
|
||||||
|
* @param array $TParam
|
||||||
|
*/
|
||||||
|
public function renderArray(&$db, $TField, $TParam=array())
|
||||||
|
{
|
||||||
$this->typeRender = 'array';
|
$this->typeRender = 'array';
|
||||||
// on conserve db pour le traitement ultérieur des subQuery
|
|
||||||
$THeader=array();
|
$THeader=array();
|
||||||
$TField=array();
|
$TField=array();
|
||||||
|
|
||||||
@ -623,20 +672,27 @@ class Listview
|
|||||||
list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam);
|
list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam);
|
||||||
|
|
||||||
$this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam);
|
$this->renderList($THeader, $TField,$TTotal,$TTotalGroup, $TParam);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function order_by($sql, &$TParam) {
|
|
||||||
$first = true;
|
|
||||||
// print_r($TParam['orderBy']);
|
|
||||||
if(!empty($TParam['orderBy'])) {
|
|
||||||
|
|
||||||
if(strpos($sql,'LIMIT ')!==false) { //TODO regex
|
/**
|
||||||
|
* @param $sql
|
||||||
|
* @param $TParam
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function order_by($sql, &$TParam)
|
||||||
|
{
|
||||||
|
$first = true;
|
||||||
|
if(!empty($TParam['orderBy']))
|
||||||
|
{
|
||||||
|
if(strpos($sql,'LIMIT ')!==false)
|
||||||
|
{
|
||||||
list($sql, $sqlLIMIT) = explode('LIMIT ', $sql);
|
list($sql, $sqlLIMIT) = explode('LIMIT ', $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql.=' ORDER BY ';
|
$sql.=' ORDER BY ';
|
||||||
foreach($TParam['orderBy'] as $field=>$order) {
|
foreach($TParam['orderBy'] as $field=>$order)
|
||||||
|
{
|
||||||
if(!$first) $sql.=',';
|
if(!$first) $sql.=',';
|
||||||
|
|
||||||
if($order=='DESC')$TParam['list']['orderDown'] = $field;
|
if($order=='DESC')$TParam['list']['orderDown'] = $field;
|
||||||
@ -649,12 +705,17 @@ class Listview
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($sqlLIMIT))$sql.=' LIMIT '.$sqlLIMIT;
|
if(!empty($sqlLIMIT))$sql.=' LIMIT '.$sqlLIMIT;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $THeader
|
||||||
|
* @param $TField
|
||||||
|
* @param $TParam
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
private function parse_array(&$THeader, &$TField, &$TParam)
|
private function parse_array(&$THeader, &$TField, &$TParam)
|
||||||
{
|
{
|
||||||
$first = true;
|
$first = true;
|
||||||
@ -664,38 +725,42 @@ class Listview
|
|||||||
|
|
||||||
if (empty($TField)) return false;
|
if (empty($TField)) return false;
|
||||||
|
|
||||||
foreach($TField as $row) {
|
foreach($TField as $row)
|
||||||
if($first) {
|
{
|
||||||
|
if($first)
|
||||||
|
{
|
||||||
$this->initHeader($THeader, $TParam, $row);
|
$this->initHeader($THeader, $TParam, $row);
|
||||||
$first=false;
|
$first=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set_line($TField, $TParam, $row);
|
$this->set_line($TField, $TParam, $row);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function initHeader(&$THeader, &$TParam, $currentLine) {
|
/**
|
||||||
|
* @param $THeader
|
||||||
|
* @param $TParam
|
||||||
|
* @param $currentLine
|
||||||
|
*/
|
||||||
|
private function initHeader(&$THeader, &$TParam, $currentLine)
|
||||||
|
{
|
||||||
|
global $db,$conf,$user;
|
||||||
|
|
||||||
$TField=$TFieldVisibility=array();
|
$TField=$TFieldVisibility=array();
|
||||||
|
foreach ($currentLine as $field => $value)
|
||||||
foreach ($currentLine as $field => $value) {
|
{
|
||||||
$TField[$field]=true;
|
$TField[$field]=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
global $user;
|
|
||||||
|
|
||||||
$contextpage=md5($_SERVER['PHP_SELF']);
|
$contextpage=md5($_SERVER['PHP_SELF']);
|
||||||
if(!empty($TParam['allow-field-select'])) {
|
if(!empty($TParam['allow-field-select']))
|
||||||
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||||
|
|
||||||
global $db,$conf,$user;
|
|
||||||
$form=new Form($db);
|
$form=new Form($db);
|
||||||
|
|
||||||
$selectedfields = GETPOST('Listview'.$this->id.'_selectedfields');
|
$selectedfields = GETPOST('Listview'.$this->id.'_selectedfields');
|
||||||
|
|
||||||
if(!empty($selectedfields)) {
|
if(!empty($selectedfields))
|
||||||
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||||
$tabparam['MAIN_SELECTEDFIELDS_'.$contextpage]=$selectedfields;
|
$tabparam['MAIN_SELECTEDFIELDS_'.$contextpage]=$selectedfields;
|
||||||
$result=dol_set_user_param($db, $conf, $user, $tabparam);
|
$result=dol_set_user_param($db, $conf, $user, $tabparam);
|
||||||
@ -721,54 +786,58 @@ class Listview
|
|||||||
'label'=>$libelle
|
'label'=>$libelle
|
||||||
,'checked'=>$visible
|
,'checked'=>$visible
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
foreach($TField as $field=>$dummy)
|
foreach($TField as $field=>$dummy)
|
||||||
{
|
{
|
||||||
$libelle = isset($TParam['title'][$field]) ? $TParam['title'][$field] : $field;
|
$libelle = isset($TParam['title'][$field]) ? $TParam['title'][$field] : $field;
|
||||||
$visible = (!in_array($field,$TParam['hide'])) ? 1 : 0;
|
$visible = (!in_array($field, $TParam['hide'])) ? 1 : 0;
|
||||||
$TFieldVisibility[$field]=array(
|
$TFieldVisibility[$field]=array(
|
||||||
'label'=>$libelle
|
'label'=>$libelle,
|
||||||
,'checked'=>$visible
|
'checked'=>$visible
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$selectedfields=$form->multiSelectArrayWithCheckbox('Listview'.$this->id.'_selectedfields', $TFieldVisibility, $contextpage); // This also change content of $arrayfields_0
|
$selectedfields=$form->multiSelectArrayWithCheckbox('Listview'.$this->id.'_selectedfields', $TFieldVisibility, $contextpage); // This also change content of $arrayfields_0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($currentLine as $field => $value) {
|
foreach ($currentLine as $field => $value)
|
||||||
|
{
|
||||||
$libelle = isset($TParam['title'][$field]) ? $TParam['title'][$field] : $field;
|
$libelle = isset($TParam['title'][$field]) ? $TParam['title'][$field] : $field;
|
||||||
$visible = (!in_array($field,$TParam['hide'])) ? 1 : 0;
|
$visible = (!in_array($field,$TParam['hide'])) ? 1 : 0;
|
||||||
|
|
||||||
if($visible) {
|
if($visible)
|
||||||
|
{
|
||||||
$lastfield = $field;
|
$lastfield = $field;
|
||||||
$THeader[$field] = array(
|
$THeader[$field] = array(
|
||||||
'libelle'=>$libelle
|
'libelle'=>$libelle,
|
||||||
,'order'=>(in_array($field, $TParam['orderby']['noOrder']) ? 0 : 1)
|
'order'=>(in_array($field, $TParam['orderby']['noOrder']) ? 0 : 1),
|
||||||
,'width'=>(!empty($TParam['size']['width'][$field]) ? $TParam['size']['width'][$field] : 'auto')
|
'width'=>(!empty($TParam['size']['width'][$field]) ? $TParam['size']['width'][$field] : 'auto'),
|
||||||
,'text-align'=>(!empty($TParam['position']['text-align'][$field]) ? $TParam['position']['text-align'][$field] : 'auto')
|
'text-align'=>(!empty($TParam['position']['text-align'][$field]) ? $TParam['position']['text-align'][$field] : 'auto'),
|
||||||
,'more'=>''
|
'more'=>''
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($selectedfields) && !empty($lastfield)) {
|
if(!empty($selectedfields) && !empty($lastfield))
|
||||||
|
{
|
||||||
$THeader[$lastfield]['more']='<div style="float:right">'.$selectedfields.'</div>';
|
$THeader[$lastfield]['more']='<div style="float:right">'.$selectedfields.'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function in_view(&$TParam, $line_number) {
|
/**
|
||||||
|
* @param $TParam
|
||||||
|
* @param $line_number
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function in_view(&$TParam, $line_number)
|
||||||
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
if(!empty($_REQUEST['get-all-for-export'])) return true; // doit être dans la vue
|
if(!empty($_REQUEST['get-all-for-export'])) return true;
|
||||||
|
|
||||||
$page_number = !empty($TParam['limit']['page']) ? $TParam['limit']['page'] : 1;
|
$page_number = !empty($TParam['limit']['page']) ? $TParam['limit']['page'] : 1;
|
||||||
$line_per_page = !empty($TParam['limit']['nbLine']) ? $TParam['limit']['nbLine'] : $conf->liste_limit;
|
$line_per_page = !empty($TParam['limit']['nbLine']) ? $TParam['limit']['nbLine'] : $conf->liste_limit;
|
||||||
@ -780,76 +849,94 @@ class Listview
|
|||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_line(&$TField, &$TParam, $currentLine) {
|
/**
|
||||||
|
* @param $TField
|
||||||
|
* @param $TParam
|
||||||
|
* @param $currentLine
|
||||||
|
*/
|
||||||
|
private function set_line(&$TField, &$TParam, $currentLine)
|
||||||
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$line_number = count($TField);
|
$line_number = count($TField);
|
||||||
|
|
||||||
if($this->in_view($TParam,$line_number)) {
|
if($this->in_view($TParam,$line_number))
|
||||||
|
{
|
||||||
|
|
||||||
$row=array(); $trans = array();
|
$row=array(); $trans = array();
|
||||||
foreach($currentLine as $field=>$value) {
|
foreach($currentLine as $field=>$value)
|
||||||
|
{
|
||||||
if(is_object($value)) {
|
if(is_object($value))
|
||||||
|
{
|
||||||
if(get_class($value)=='stdClass') {$value=print_r($value, true);}
|
if(get_class($value)=='stdClass') {$value=print_r($value, true);}
|
||||||
else $value=(string)$value;
|
else $value=(string)$value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$trans['@'.$field.'@'] = $value;
|
$trans['@'.$field.'@'] = $value;
|
||||||
|
|
||||||
if(!empty($TParam['math'][$field])) {
|
if(!empty($TParam['math'][$field]))
|
||||||
|
{
|
||||||
$float_value = (double)strip_tags($value);
|
$float_value = (double)strip_tags($value);
|
||||||
$this->TTotalTmp[$field][] = $float_value;
|
$this->TTotalTmp[$field][] = $float_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!in_array($field,$TParam['hide'])) {
|
if(!in_array($field,$TParam['hide']))
|
||||||
|
{
|
||||||
$row[$field]=$value;
|
$row[$field]=$value;
|
||||||
|
|
||||||
if(isset($TParam['eval'][$field]) && in_array($field,array_keys($row))) {
|
if(isset($TParam['eval'][$field]) && in_array($field,array_keys($row)))
|
||||||
|
{
|
||||||
$strToEval = 'return '.strtr( $TParam['eval'][$field] , array_merge( $trans, array('@val@'=>$row[$field]) )).';';
|
$strToEval = 'return '.strtr( $TParam['eval'][$field] , array_merge( $trans, array('@val@'=>$row[$field]) )).';';
|
||||||
$row[$field] = eval($strToEval);
|
$row[$field] = eval($strToEval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($TParam['type'][$field]) && !isset($TParam['eval'][$field])) {
|
if(isset($TParam['type'][$field]) && !isset($TParam['eval'][$field]))
|
||||||
if($TParam['type'][$field]=='date'
|
{
|
||||||
|| $TParam['type'][$field]=='datetime' ) {
|
if($TParam['type'][$field]=='date' || $TParam['type'][$field]=='datetime' )
|
||||||
|
{
|
||||||
|
|
||||||
if($row[$field] != '0000-00-00 00:00:00' && $row[$field] != '1000-01-01 00:00:00' && $row[$field] != '0000-00-00' && !empty($row[$field])) {
|
if($row[$field] != '0000-00-00 00:00:00' && $row[$field] != '1000-01-01 00:00:00' && $row[$field] != '0000-00-00' && !empty($row[$field]))
|
||||||
|
{
|
||||||
if($TParam['type'][$field]=='datetime')$row[$field] = dol_print_date(strtotime($row[$field]),'dayhoursec');
|
if($TParam['type'][$field]=='datetime')$row[$field] = dol_print_date(strtotime($row[$field]),'dayhoursec');
|
||||||
else $row[$field] = dol_print_date(strtotime($row[$field]),'day');
|
else $row[$field] = dol_print_date(strtotime($row[$field]),'day');
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$row[$field] = '';
|
$row[$field] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($TParam['type'][$field]=='hour') { $row[$field] = date('H:i', strtotime($row[$field])); }
|
if($TParam['type'][$field]=='hour') { $row[$field] = date('H:i', strtotime($row[$field])); }
|
||||||
if($TParam['type'][$field]=='money') { $row[$field] = '<div align="right">'.price($row[$field],0,'',1,-1,2).'</div>'; }
|
if($TParam['type'][$field]=='money') { $row[$field] = '<div align="right">'.price($row[$field],0,'',1,-1,2).'</div>'; }
|
||||||
if($TParam['type'][$field]=='number') { $row[$field] = '<div align="right">'.price($row[$field]).'</div>'; }
|
if($TParam['type'][$field]=='number') { $row[$field] = '<div align="right">'.price($row[$field]).'</div>'; }
|
||||||
if($TParam['type'][$field]=='integer') { $row[$field] = '<div align="right">'.(int)$row[$field].'</div>'; }
|
if($TParam['type'][$field]=='integer') { $row[$field] = '<div align="right">'.(int)$row[$field].'</div>'; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($TParam['link'][$field])) {
|
if(isset($TParam['link'][$field]))
|
||||||
|
{
|
||||||
if(empty($row[$field]) && $row[$field]!==0 && $row[$field]!=='0')$row[$field]='(vide)';
|
if(empty($row[$field]) && $row[$field]!==0 && $row[$field]!=='0')$row[$field]='(vide)';
|
||||||
$row[$field]= strtr( $TParam['link'][$field], array_merge( $trans, array('@val@'=>$row[$field]) )) ;
|
$row[$field]= strtr( $TParam['link'][$field], array_merge( $trans, array('@val@'=>$row[$field]))) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($TParam['translate'][$field])) {
|
if(isset($TParam['translate'][$field]))
|
||||||
|
{
|
||||||
if(isset($TParam['translate'][$field][''])) unset($TParam['translate'][$field]['']);
|
if(isset($TParam['translate'][$field][''])) unset($TParam['translate'][$field]['']);
|
||||||
|
|
||||||
$row[$field] = strtr( $row[$field] , $TParam['translate'][$field]);
|
$row[$field] = strtr( $row[$field] , $TParam['translate'][$field]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
}
|
||||||
$row=array();
|
else
|
||||||
|
{
|
||||||
|
$row = array();
|
||||||
|
|
||||||
foreach($currentLine as $field=>&$value) {
|
foreach($currentLine as $field=>&$value)
|
||||||
if(!isset($this->THideFlip[$field])) {
|
{
|
||||||
if(isset($TParam['math'][$field]) && !empty($TParam['math'][$field])) {
|
if(!isset($this->THideFlip[$field]))
|
||||||
|
{
|
||||||
|
if(isset($TParam['math'][$field]) && !empty($TParam['math'][$field]))
|
||||||
|
{
|
||||||
$float_value = (double)strip_tags($value);
|
$float_value = (double)strip_tags($value);
|
||||||
$this->TTotalTmp[$field][] = $float_value;
|
$this->TTotalTmp[$field][] = $float_value;
|
||||||
}
|
}
|
||||||
@ -859,32 +946,45 @@ class Listview
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($TParam['math'][$field])) {
|
if(!empty($TParam['math'][$field]))
|
||||||
foreach($row as $field=>$value) {
|
{
|
||||||
if(!empty($TParam['math'][$field]) && is_array($TParam['math'][$field])) {
|
foreach($row as $field=>$value)
|
||||||
|
{
|
||||||
|
if(!empty($TParam['math'][$field]) && is_array($TParam['math'][$field]))
|
||||||
|
{
|
||||||
$toField = $TParam['math'][$field][1];
|
$toField = $TParam['math'][$field][1];
|
||||||
$float_value = (double)strip_tags($row[$toField]);
|
$float_value = (double)strip_tags($row[$toField]);
|
||||||
$this->TTotalTmp['@groupsum'][$toField][ $row[$field] ] +=$float_value;
|
$this->TTotalTmp['@groupsum'][$toField][ $row[$field] ] +=$float_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$TField[] = $row;
|
$TField[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function limitSQL($sql,&$TParam) {
|
/**
|
||||||
|
* @param $sql
|
||||||
if(!empty($TParam['limit']['global']) && strpos($sql,'LIMIT ')===false ) {
|
* @param $TParam
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function limitSQL($sql, &$TParam)
|
||||||
|
{
|
||||||
|
if(!empty($TParam['limit']['global']) && strpos($sql,'LIMIT ')===false )
|
||||||
|
{
|
||||||
$sql.=' LIMIT '.(int)$TParam['limit']['global'];
|
$sql.=' LIMIT '.(int)$TParam['limit']['global'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parse_sql( &$THeader, &$TField,&$TParam, $sql) {
|
/**
|
||||||
|
* @param $THeader
|
||||||
|
* @param $TField
|
||||||
|
* @param $TParam
|
||||||
|
* @param $sql
|
||||||
|
*/
|
||||||
|
private function parse_sql(&$THeader, &$TField, &$TParam, $sql)
|
||||||
|
{
|
||||||
$this->sql = $this->limitSQL($sql, $TParam);
|
$this->sql = $this->limitSQL($sql, $TParam);
|
||||||
|
|
||||||
$this->TTotalTmp=array();
|
$this->TTotalTmp=array();
|
||||||
@ -892,25 +992,26 @@ class Listview
|
|||||||
$this->THideFlip = array_flip($TParam['hide']);
|
$this->THideFlip = array_flip($TParam['hide']);
|
||||||
|
|
||||||
$res = $this->db->query($this->sql);
|
$res = $this->db->query($this->sql);
|
||||||
if($res!==false) {
|
if($res!==false)
|
||||||
|
{
|
||||||
dol_syslog(get_class($this)."::parse_sql id=".$this->id." sql=".$this->sql, LOG_DEBUG);
|
dol_syslog(get_class($this)."::parse_sql id=".$this->id." sql=".$this->sql, LOG_DEBUG);
|
||||||
|
|
||||||
$first=true;
|
$first=true;
|
||||||
while($currentLine = $this->db->fetch_object($res)) {
|
while($currentLine = $this->db->fetch_object($res))
|
||||||
if($first) {
|
{
|
||||||
|
if($first)
|
||||||
|
{
|
||||||
$this->initHeader($THeader, $TParam, $currentLine);
|
$this->initHeader($THeader, $TParam, $currentLine);
|
||||||
$first = false;
|
$first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set_line($TField, $TParam, $currentLine);
|
$this->set_line($TField, $TParam, $currentLine);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
dol_syslog(get_class($this)."::parse_sql id=".$this->id." sql=".$this->sql, LOG_ERR);
|
dol_syslog(get_class($this)."::parse_sql id=".$this->id." sql=".$this->sql, LOG_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,33 +50,33 @@ $THide = array('label','title');
|
|||||||
echo $list->render(Inventory::getSQL('All'), array(
|
echo $list->render(Inventory::getSQL('All'), array(
|
||||||
'link'=>array(
|
'link'=>array(
|
||||||
'fk_warehouse'=>'<a href="'.DOL_URL_ROOT.'/product/stock/card.php?id=@val@">'.img_picto('','object_stock.png','',0).' @label@</a>'
|
'fk_warehouse'=>'<a href="'.DOL_URL_ROOT.'/product/stock/card.php?id=@val@">'.img_picto('','object_stock.png','',0).' @label@</a>'
|
||||||
)
|
),
|
||||||
,'translate'=>array()
|
'translate'=>array(),
|
||||||
,'hide'=>$THide
|
'hide'=>$THide,
|
||||||
,'type'=>array(
|
'type'=>array(
|
||||||
'datec'=>'date'
|
'datec'=>'date',
|
||||||
,'tms'=>'datetime'
|
'tms'=>'datetime',
|
||||||
,'date_inventory'=>'date'
|
'date_inventory'=>'date'
|
||||||
)
|
),
|
||||||
,'list'=>array(
|
'list'=>array(
|
||||||
'title'=>$langs->trans('inventoryListTitle')
|
'title'=>$langs->trans('inventoryListTitle'),
|
||||||
,'messageNothing'=>$langs->trans('inventoryListEmpty')
|
'messageNothing'=>$langs->trans('inventoryListEmpty')
|
||||||
)
|
),
|
||||||
,'title'=>array(
|
'title'=>array(
|
||||||
'rowid'=>$langs->trans('Title')
|
'rowid'=>$langs->trans('Title'),
|
||||||
,'fk_warehouse'=>$langs->trans('Warehouse')
|
'fk_warehouse'=>$langs->trans('Warehouse'),
|
||||||
,'date_inventory'=>$langs->trans('InventoryDate')
|
'date_inventory'=>$langs->trans('InventoryDate'),
|
||||||
,'datec'=>$langs->trans('DateCreation')
|
'datec'=>$langs->trans('DateCreation'),
|
||||||
,'tms'=>$langs->trans('DateUpdate')
|
'tms'=>$langs->trans('DateUpdate'),
|
||||||
,'status'=>$langs->trans('Status')
|
'status'=>$langs->trans('Status')
|
||||||
)
|
),
|
||||||
,'eval'=>array(
|
'eval'=>array(
|
||||||
'status' => '(@val@ ? img_picto("'.$langs->trans("inventoryValidate").'", "statut4") : img_picto("'.$langs->trans("inventoryDraft").'", "statut3"))'
|
'status' => '(@val@ ? img_picto("'.$langs->trans("inventoryValidate").'", "statut4") : img_picto("'.$langs->trans("inventoryDraft").'", "statut3"))',
|
||||||
,'rowid'=>'Inventory::getLink(@val@)'
|
'rowid'=>'Inventory::getLink(@val@)'
|
||||||
)
|
),
|
||||||
,'search'=>array(
|
'search'=>array(
|
||||||
'date_inventory'=>'calendars'
|
'date_inventory'=>'calendars',
|
||||||
,'status'=>array(1=>$langs->trans("inventoryValidate"), 0=>$langs->trans("inventoryDraft"))
|
'status'=>array(1=>$langs->trans("inventoryValidate"), 0=>$langs->trans("inventoryDraft"))
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user