<?php
 class listField extends baseField { var $Conf = array( 'xtype' => 'list', 'icon' => 'folder_edit.png', ); function edit($addConf,$R) { $R['height']= 200; $R['setAutoSize'] = true; $R['noSave'] = true; $SearchFields = array(); $orderBy = array(); if($addConf['lng']) { foreach($addConf['lng'] as $y => $z) { if($z['attr'] AND $z['attr']['header']) { if(!$z['attr']['name']) $z['attr']['name'] = $y; $r = array(); $r['cnt'] = false; $r['name'] = $this->Mizu->getElementName($z['attr']);; $r['field'] = $y; $r['attr'] = $z['attr']; if($z['attr']['orderBy']) { $orderBy[$y] = $z['attr']['orderBy']; } $Header['lng-'.$y] = ($r); } if($z['attr']['searchable']) { $SearchFields[] = $y; } } } if($addConf['cnt']) { foreach($addConf['cnt'] as $y => $z) { if($z['attr'] AND $z['attr']['header']) { if(!$z['attr']['name']) $z['attr']['name'] = $y; $r = array(); $r['cnt'] = true; $r['name'] = $this->Mizu->getElementName($z['attr']);; $r['field'] = $y; $r['attr'] = $z['attr']; if($z['attr']['orderBy']) { $orderBy[$y] = $z['attr']['orderBy']; } $Header['cnt-'.$y] = ($r); } if($z['attr']['searchable']) { $SearchFields[] = $y; } } } $R['attr'] = $addConf['attr']; $R['Head'] = $Header; if($SearchFields) { $R['searchable'] = true; } return parent::edit($addConf,$R); } function setAction() { $this->GP = $this->Mizu->GP; switch($this->Mizu->GP['action']) { case 'getList' : $orderBy = array(); $this->Mizu->setPage($this->Mizu->GP['id']); $Page = $this->Mizu->getCurrentPage(); if(!is_numeric($this->Mizu->GP['limit'])) $this->Mizu->GP['limit'] = 20; $Header = array(); $Fields = array(); $SearchFields = array(); $addConf = $this->Mizu->getEditTpl($this->Mizu->GP['id'],$this->Mizu->GP['t'].'/'.$this->Mizu->GP['field']); if($addConf['attr']['draggable']) { } else { $offset = array($this->Mizu->GP['start'],$this->Mizu->GP['limit']); } if($addConf['lng']) { foreach($addConf['lng'] as $y => $z) { $Fields[] = $y; if($z['attr'] AND $z['attr']['header']) { $r = array(); $r['cnt'] = false; $r['name'] = $this->Mizu->getElementName($z['attr']); $r['field'] = $y; $r['attr'] = $z['attr']; $Header['lng-'.$y] = $r; } if($z['attr']['orderBy']) { $orderBy[$y] = $z['attr']['orderBy']; } if($z['attr']['searchable']) { $SearchFields[] = $y; } } } if($addConf['cnt']) { foreach($addConf['cnt'] as $y => $z) { $Fields[] = $y; if($z['attr'] AND $z['attr']['header']) { $r = array(); $r['cnt'] = true; $r['name'] = $this->Mizu->getElementName($z['attr']); $r['field'] = $y; $r['attr'] = $z['attr']; $Header['cnt-'.$y] = $r; } if($z['attr']['orderBy']) { $orderBy[$y] = $z['attr']['orderBy']; } if($z['attr']['searchable']) { $SearchFields[] = $y; } } } $StructData = array(); $join = array(); if(!count($SearchFields)) { $SearchFields = $Fields; } if($this->Mizu->GP['sword'] AND count($SearchFields)) { $as=''; foreach($SearchFields as $f) { $as.= 'y'; $join[] = 'JOIN %content% '.$as.' ON '.$as.'.cid = c1.id AND '.$as.'.k="'.$f.'" AND '.$as.'.v LIKE "%'.$this->Mizu->GP['sword'].'%"'; } } $Data = $this->Mizu->_DB->getList($this->Mizu->GP['id'],$this->Mizu->GP['t'],$this->Mizu->GP['field'],$this->Mizu->GP['lng'],false,$orderBy,$offset,false,$join); if(is_array($Data)) { foreach($Data as $y => $z) { $sd = array(); foreach($Header as $f => $d) { if($d['cnt']) { $sd[$f] = $z['cnt'][$d['field']]; } else { $sd[$f] = $z['lng'][$this->Mizu->lng][$d['field']]; } if($d['attr'] AND $d['attr']['type']) { $F = $this->Mizu->_Field->getFieldClass($d['attr']['type']); $sd[$f] = $F->getGetValue($sd[$f]); } if($d['attr'] AND $d['attr']['type']=='file') { $tmp = explode('?',$sd[$f]); if(preg_match('/\.('.$this->Mizu->_File->Types['img'].')$/iU',$tmp[0])) { $sd[$f]= $this->Mizu->getImg($sd[$f],100,50); } } } $sd['id'] = $z['cid']; $StructData[] = $sd; } } $R['total'] = count($this->Mizu->_DB->getList($this->Mizu->GP['id'],$this->Mizu->GP['t'],$this->Mizu->GP['field'],$this->Mizu->GP['lng'],false,$orderBy,false,array('returnRows'=>true),$join)); $R['items'] = $StructData; $this->Mizu->sendJson($R); break; case 'setListSort' : $ok = true; $ids = explode(',',$this->GP['cids']); $i = 10; $I = array(); foreach($ids as $id) { if(is_numeric($id)) { $this->Mizu->_DB->editContent($this->GP['id'],'cnt',$this->GP['sortField'],false,$i,$id); } $i+=10; } $this->Mizu->sendJson(array()); break; case 'delListItem' : $ok = true; $ids = explode(',',$this->GP['cids']); foreach($ids as $id) { if(!is_numeric($id)) { $ok = false; break; } } if($this->GP['cids'] AND $ok) { $sql = 'DELETE FROM %content% WHERE 
							id IN ('.$this->GP['cids'].')
							OR
							cid IN ('.$this->GP['cids'].')
						'; $this->Mizu->_DB->query($sql); $R['ids'] = $ids; } $this->Mizu->sendJson($R); break; } } } 