12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452 |
- <?php
- # 此类很大,以后优化,放到Database目录中,拆分为工厂模式
- # 必须要优化了...当时为了快速实现直接扔这一个里面了,近期优化
- namespace Manage\Src;
- use Dever;
- use Manage\Src\Lib\Input as Html;
- use Manage\Src\Lib\Log;
- class Database
- {
- /**
- * project
- *
- * @var string
- */
- private $project;
- /**
- * table
- *
- * @var string
- */
- private $table;
- /**
- * menu
- *
- * @var string
- */
- private $menu;
- /**
- * menu_id
- *
- * @var string
- */
- private $menu_id;
- /**
- * id
- *
- * @var string
- */
- private $id;
- /**
- * config
- *
- * @var array
- */
- private $config;
- /**
- * search
- *
- * @var bool
- */
- private $search = false;
- /**
- * __construct
- *
- * @return mixed
- */
- public function __construct()
- {
- $this->project = Dever::input('project');
- $this->table = Dever::input('table');
- $this->menu = Dever::input('menu');
- $this->menu_id = Dever::input('menu_id');
- $this->id = Dever::input('update_where_id', Dever::input('where_id'));
- $this->name = $this->project . '/' . $this->table;
- $this->top = Dever::input('top');
- if ($this->top) {
- Dever::load('manage/top.update_action', $this->top);
- }
- }
- /**
- * 提供给异步获取数据的接口
- *
- * @return array
- */
- public function getAjax($data)
- {
- $key = Dever::input('key');
- $value = Dever::input('value');
- $source = Dever::input('source');
-
- $config = Dever::db($source)->config['struct'][$key];
- $config['value'] = $value;
- $config['option'] = $data;
- return $this->create_update_html($key, $config);
- }
- /**
- * url
- *
- * @return array
- */
- public function url($key = false, $id = 0, $table = false, $suffix = '')
- {
- $table = $table ? $table : $this->table;
- if (strpos($table, 'http://') !== false || strpos($table, 'javascript') !== false) {
- return $table;
- }
- $config = array
- (
- 'project' => 'project/database?project=' . $this->project,
- 'list' => 'project/database/list?{param}',
- 'search' => 'project/database/list?{param}',
- 'add' => 'project/database/update?{param}',
- 'update' => 'project/database/update?{param}&where_id=' . $id,
- # 增加快捷更新
- 'edit' => 'project/database/update?{param}&where_id=' . $id,
- 'updateAction' => 'database.update_action',
- 'url' => '',
- 'delete' => 'database.delete_action?{param}&where_id=' . $id,
- 'recovery' => 'database.recovery_action?{param}&where_id=' . $id,
- 'stat' => 'project/database/stat?{param}',
- 'excel' => 'database.list_excel?{param}',
- 'stat_excel' => 'database.stat_excel?{param}',
- 'diy' => 'list?{param}',
- );
- $state = $this->getState();
- if ($key == 'delete' && $state == 2) {
- $key = 'recovery';
- }
- if (strpos($key, 'list') !== false) {
- $config[$key] = $config['list'];
- } elseif (strpos($key, 'add') !== false) {
- $config[$key] = $config['add'];
- } elseif (strpos($key, 'edit') !== false) {
- $config[$key] = $config['edit'];
- }
- if (isset($config[$key])) {
- if (strpos($config[$key], '{param}')) {
- $param = $this->getUrlParam($key, $table, $suffix, $state);
- $config[$key] = str_replace('{param}', $param, $config[$key]);
- }
- return Dever::url($config[$key]);
- }
- return $config;
- }
- /**
- * 获取url需要的参数
- *
- * @return string
- */
- private function getUrlParam($key, $table, $suffix, $state)
- {
- $param = '';
- $array = array('project', 'search', 'add', 'list', 'update', 'edit');
- if (in_array($key, $array) && !strstr($table, 'oper_')) {
- $where = Dever::preInput('search_');
- if ($where) {
- if (isset($where['where_id'])) {
- //unset($where['where_id']);
- }
- unset($where['search_option_state']);
- $param .= '&' . http_build_query($where);
- }
- $oper = Dever::preInput('oper_');
- if ($oper) {
- $param .= '&' . http_build_query($oper);
- }
- }
- if ($key == 'search' && $search_limit = Dever::input('search_limit')) {
- $param .= '&search_limit=' . $search_limit;
- }
-
- if (strpos($suffix, 'search_option_state') !== false) {
- $state = '';
- } else {
- $state = '&search_option_state=' . $state;
- }
- $page_type = Dever::input('page_type');
- if ($page_type) {
- $param .= '&page_type=' . $page_type . '';
- }
- $param = 'project=' . $this->project . $param . '&table=' . $table . '&menu=' . $this->menu . '&menu_id=' . $this->menu_id . $state . $suffix;
- return $param;
- }
- /**
- * 获得refer
- *
- * @return string
- */
- private function refer($type = 'project')
- {
- return '';
- switch ($type) {
- case 'project':
- $name = '数据库操作';
- break;
- case 'list':
- $name = '数据列表';
- break;
- case 'url':
- $name = '项目列表';
- break;
- }
- $name = '返回上一级';
- $url = $this->url($type);
- $refer = '-[<a href="' . $url . '">' . $name . '</a>]';
- return $refer;
- }
- /**
- * getAdminInfo
- *
- * @return array
- */
- private function getAdminInfo($data)
- {
- $admin = Dever::load('manage/auth.info');
- $data['my_admin_id'] = $admin['id'];
- $data['my_role_id'] = $admin['role'];
- return $data;
- }
- /**
- * cookie 处理cookie
- *
- * @return array
- */
- public function cookie()
- {
- $cookie = $_COOKIE;
- $array = array();
- # 判断手机版
- $mobile = Dever::mobile();
- if ((isset($cookie['left_menu']) && $cookie['left_menu'] == 'close') || $mobile) {
- $array['wrapper'] = 'enlarged forced';
- } else {
- $array['wrapper'] = 'forced';
- }
- return $array;
- }
- /**
- * listStyle
- *
- * @return array
- */
- public function listStyle()
- {
- $mobile = Dever::mobile();
- if ($mobile) {
- $style = '.container_list .panel-heading .form-control,#mul .form-control,#page .form-control
- {
- width:70%;
- }
- .row
- {
- margin-right: -15px;
- margin-left: -15px;
- }
- #dever_modal_body img
- {
- max-width:300px;
- }
- ';
- } else {
- $style = '#dever_modal_body img
- {
- max-width:300px;
- }';
- }
- return $style;
- }
- /**
- * info 处理一些基本的信息,供模板使用
- *
- * @return array
- */
- public function info()
- {
- $config = $this->config();
- $menu = isset($config['lang']) ? $config['lang'] : $this->project . '-' . $this->table;
- if (isset($config['state']) && $config['state'] == 2) {
- $menu .= '[回收站]';
- }
- $top = Dever::load('manage/top.get');
- //print_r($top);die;
- $display = '';
- # 新增权限
- $insert_state = Dever::load('manage/auth.oper', 4);
- if ((isset($config['manage']['insert']) && $config['manage']['insert'] == false) || !isset($config['manage']['insert']) || $insert_state == false) {
- $display = 'display:none';
- }
- $info = array
- (
- 'action' => $this->url('updateAction'),
- 'list' => $this->url('list'),
- 'search' => $this->url('search'),
- 'mul' => $this->url('list'),
- //'add' => 'location.href=\'' . $this->url('add') . '\'',
- 'add' => $this->url('add'),
- 'add_state' => $display,
- 'state' => $this->getState(),
- 'l' => 'project/database/list',
- 'project' => $this->project,
- 'table' => $this->table,
- 'menu' => $this->menu,
- 'menu_id' => $this->menu_id,
- 'id' => $this->id,
- 'main' => '数据管理' . $this->refer('url'),
- 'list_header' => $menu,
- 'list_desc' => '数据列表',
- 'project_name' => Dever::load('manage/project.name', $this->project),
- 'update_header' => $menu,
- 'update_desc' => '更新数据',
- 'updateMul' => (!$this->id && isset($config['manage']['updateMul']) && $config['manage']['updateMul']) ? '增加一条' : false,
- 'updateDesc' => isset($config['manage']['desc']) ? $config['manage']['desc'] : '',
- 'listDesc' => isset($config['desc']) ? $config['desc'] : '',
- 'struct' => isset($config['manage']['struct']) ? $config['manage']['struct'] : '',
- 'stat_desc' => '主动统计',
- 'search_param' => '',
- );
- $info['parent'] = Dever::input('oper_parent');
- if ($info['parent']) {
- $oper = Dever::preInput('oper_');
- if ($oper) {
- $info['parent'] .= '&' . str_replace('oper_', '', http_build_query($oper));
- //$info['parent'] .= '&' . http_build_query($oper);
- }
- //$info['parent'] = 'location.href=\'' . $this->url(Dever::input('oper_index', 11), 0, $info['parent']) . '\'';
- $info['parent'] = $this->url(Dever::input('oper_index', 'listData'), 0, $info['parent']);
- $info['parent_state'] = '';
- } else {
- $info['parent_state'] = 'display:none';
- }
- $info['save'] = Dever::input('oper_save_jump');
- if ($info['save']) {
- $info['list'] = $this->url(Dever::input('oper_index', 'listData'), 0, $info['save']);
- }
- $search = Dever::preInput('search_');
- if ($search) {
- $info['mul'] .= '&' . http_build_query($search);
- if (layadmin()) {
- foreach ($search as $k => $v) {
- if (!strstr($k, 'search_option_')) {
- if (is_array($v)) {
- $v = implode(',', $v);
- }
- $info['search_param'] .= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
- }
- }
- }
- }
- if ($this->id) {
- $info['update_header'] = $menu . '-更新数据' . $this->refer('list');
- }
- return $info;
- }
- /**
- * 获取表名
- *
- * @return array
- */
- public function getTableName($project, $table)
- {
- if ($project == 'other') {
- return '无数据表';
- }
- $path = Dever::load('manage/project.path', $project);
- $config = $this->config($project, $path, $table);
- $data = isset($config['lang']) ? $config['lang'] : $project;
- return $data;
- }
- private function getState()
- {
- return Dever::input('search_option_state', 1);
- }
- /**
- * config
- *
- * @return array
- */
- public function config($project = false, $path = false, $table = false)
- {
- if (!$project) {
- $project = $this->project;
- $table = $this->table;
- }
- if (!$project) {
- return array();
- }
- Dever::$global['manage']['project'] = $project;
- $config = Dever::load('manage/project.config', $project);
- if (!is_array($config)) {
- Dever::alert($project . ' error');
- }
- $project = $config['name'];
- if (!$path) {
- if (isset($config['base']) && isset($config['rel'])) {
- $path = DEVER_INCLUDE_PATH . $config['rel'];
- } else {
- $path = $config['path'];
- }
- }
- if ($project && $path && empty($this->config[$path])) {
- $this->config[$path] = array();
- $dir = $path . 'database/';
- if (is_dir($dir)) {
- $database = scandir($dir);
- foreach ($database as $k => $v) {
- if (strpos($v, '.php') !== false) {
- $k = str_replace('.php', '', $v);
- $this->config[$path][$k] = $this->struct($dir . $v, $project);
- }
- }
- }
- }
- return ($table && isset($this->config[$path][$table])) ? $this->config[$path][$table] : $this->config[$path];
- }
- /**
- * 对database配置文件进行解析
- *
- * @return array
- */
- private function struct($file, $project = false)
- {
- $config = include $file;
- if (isset($config['struct']) && is_array($config['struct']['id'])) {
- $config['update'] = false;
- $config['manage']['struct'] = '<table border=1 width=100% height=100%>';
- $config['level'] = 1;
- foreach ($config['struct'] as $k => $v) {
- if (isset($v['level'])) {
- $config['level'] = 3;
- }
- if (isset($v['search_parent'])) {
- $config['manage']['search_parent'][$v['search_parent']] = $k;
- $config['manage']['search_child'][$k] = $v['search_parent'];
- }
- if (isset($v['search']) && is_string($v['search'])) {
- if (strpos($v['search'], 'time') !== false) {
- $config['manage']['search']['time'][$k] = $v['name'];
- }
- if (strpos($v['search'], 'date') !== false) {
- $config['manage']['search']['date'][$k] = $v['name'];
- }
- if (strpos($v['search'], 'exp') !== false) {
- $config['manage']['search']['exp'][$k] = $v['name'];
- }
- if (strpos($v['search'], 'fulltext') !== false) {
- $config['manage']['search']['fulltext'][$k] = $v['name'];
- isset($v['match']) && $config['request']['list']['option'][$k] = array('option', 'like');
- } elseif (strpos($v['search'], 'text') !== false) {
- $config['manage']['search']['text'][$k] = $v['name'];
- }
- if (isset($v['exist']) && strpos($v['search'], 'exist') !== false) {
- $config['manage']['search']['exist'][$k]['option'] = $v['exist'];
- $config['manage']['search']['exist'][$k]['lang'] = $v['name'];
- }
- if (isset($v['option']) && strpos($v['search'], 'select') !== false) {
- $config['manage']['search']['select'][$k]['option'] = $v['option'];
- $config['manage']['search']['select'][$k]['lang'] = $v['name'];
- if (isset($v['default'])) {
- $config['manage']['search']['select'][$k]['default'] = $v['default'];
- }
- }
- if (isset($v['option']) && strpos($v['search'], 'group') !== false) {
- $config['manage']['search']['group'][$k]['option'] = $v['option'];
- $config['manage']['search']['group'][$k]['lang'] = $v['name'];
- if (isset($v['default'])) {
- $config['manage']['search']['group'][$k]['default'] = $v['default'];
- }
- }
- if (isset($v['option']) && strpos($v['search'], 'linkage') !== false) {
- $config['manage']['search']['linkage'][$k]['option'] = $v['option'];
- $config['manage']['search']['linkage'][$k]['lang'] = $v['name'];
- if (isset($v['default'])) {
- $config['manage']['search']['linkage'][$k]['default'] = $v['default'];
- }
- }
- } elseif (isset($v['search']) && is_array($v['search'])) {
- if (isset($v['search']['api'])) {
- $config['manage']['search']['api'][$k] = $v['search'];
- $config['manage']['search']['api'][$k]['lang'] = $v['name'];
- }
- }
- /*
- if (isset($v['table']) && !isset($config['end'])) {
- $config['end']['insert'] = $v['value'];
- }
- */
- if (isset($v['update'])) {
- if (!isset($config['manage']['insert'])) {
- $config['manage']['insert'] = true;
- }
- $config['update'] = true;
- }
- if (isset($v['type'])) {
- $config['manage']['struct'] .= Dever::tbody(array($k, $v['type'], $v['name']));
- }
- }
- $config['manage']['struct'] .= '</table>';
- $config['manage']['_list'] = array
- (
- 'col' => 'manage',
- 'name' => '管理',
- 'value' => array(),
- );
- if (!isset($config['manage']['edit']) || (!isset($config['manage']['edit']) && $config['manage']['edit'] == true)) {
- if (!isset($config['manage']['list_button']['update'])) {
- $config['manage']['_list']['value']['update'] = '编辑';
- }
- }
-
- if (isset($config['manage']['list'][0]) && is_array($config['manage']['list'][0])) {
- $config['manage']['_list']['value'] += $config['manage']['list'][0];
- unset($config['manage']['list'][0]);
- } elseif (isset($config['manage']['list_button'])) {
- $config['manage']['_list']['value'] += $config['manage']['list_button'];
- }
- if (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] == true)) {
- if (!isset($config['manage']['list_button']['delete'])) {
- $config['manage']['_list']['value']['delete'] = '删除';
- }
- }
- if (!$config['manage']['_list']['value']) {
- unset($config['manage']['_list']);
- }
- }
- $config['state'] = $this->getState();
- $config['project'] = $project;
- return $config;
- }
- /**
- * 自定义列表页面
- *
- * @return array
- */
- public function page($key = 'list')
- {
- $key = Dever::input('page_value', $key);
- $type = Dever::input('page_type', 1);
- $config = $this->config();
- $result = array();
- $result['s1'] = 'display:none';
- $result['s2'] = 'display:';
- $result['content'] = '';
- $key = 'page_' . $key;
- if (isset($config['manage'][$key])) {
- if ($config['manage'][$key] == 'photo' && isset($config['manage']['photo'])) {
- $result['content'] = Dever::view('list/photo', false, 'manage');
- } else {
- $result['content'] = Dever::view($config['manage'][$key], 'manage', $this->project);
- }
-
- //echo $result['content'];die;
- if ($result['content']) {
- Dever::setInput('page_content', 1);
- $result['s1'] = 'display:';
- $result['s2'] = 'display:none';
- # 添加底部
- if ($key != 'page_list_table') {
- $result['content'] .= Dever::view('inc/foot', false, 'manage');
- }
- }
- } elseif (strstr($key, 'list_table')) {
- Dever::setInput('page_type', 2);
- }
- return $result;
- }
- /**
- * 自定义列表页面
- *
- * @return array
- */
- public function page_list()
- {
- return $this->page('list');
- }
- /**
- * 自定义列表页面 只接管table部分,同时必须传值page_type=1
- *
- * @return array
- */
- public function page_list_table()
- {
- $type = Dever::input('page_type', 2);
- if ($type == 1) {
- return $this->page('list_table');
- } else {
- return $this->page('list_table_default');
- }
- }
- /**
- * 自定义列表页面
- *
- * @return array
- */
- public function page_update()
- {
- return $this->page('update');
- }
- /**
- * 载入自定义资源
- *
- * @return array
- */
- public function res()
- {
- $result = array
- (
- 'js' => '',
- 'css' => '',
- );
- if (!$this->project) {
- return $result;
- }
- $config = $this->config();
- if (isset($config['manage']['res'])) {
- foreach ($config['manage']['res'] as $k => $v) {
- $result[$k] = $this->getRes($k, $v);
- }
- }
- return $result;
- }
- /**
- * getRes
- *
- * @return string
- */
- protected function getRes($path, $value)
- {
- if (is_array($value)) {
- $res = '';
- foreach ($value as $k => $v) {
- $res .= $this->getRes($path, $v);
- }
- return $res;
- } else {
- if ($this->project != 'manage') {
- $base = str_replace('assets/', 'assets/manage/', Dever::config('host', $this->project)->$path);
- } else {
- $base = Dever::config('host', $this->project)->$path;
- }
-
- $file = $base . $value . '.' . $path;
- $res = '<script type="text/javascript" src="'.$file.'"></script>';
- return $res;
- }
- }
- /**
- * 头部banner
- *
- * @return array
- */
- public function banner()
- {
- if (!$this->project) {
- return '';
- }
- $config = $this->config();
- $result = '';
- if (isset($config['manage']['banner'])) {
- foreach ($config['manage']['banner'] as $k => $v) {
- $config['manage']['banner'][$k] = $this->value($v, 'yes');
- }
- if (empty($config['manage']['banner']['link'])) {
- $config['manage']['banner']['link'] = '#';
- $config['manage']['banner']['target'] = '_self';
- }
- if (empty($config['manage']['banner']['target'])) {
- $config['manage']['banner']['target'] = '_blank';
- }
- $result = '<a target="' . $config['manage']['banner']['target'] . '" href="' . $config['manage']['banner']['link'] . '"><img src="' . $config['manage']['banner']['img'] . '"></a>
- <span>' . $config['manage']['banner']['name'] . '</span>';
- }
- return $result;
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search_select(&$result, $search, $name, $lang, $option, $default = false, $bind = array(), $parent = '')
- {
- $value = array();
- if (strpos($lang, '-')) {
- $temp = explode('-', $lang);
- $lang = $temp[0];
- }
- $value['name'] = $name;
- $value['lang'] = $lang;
- $value['option'] = $option;
- if (isset($search[$name])) {
- $value['value'] = $search[$name];
- }
- if ($default) {
- //$value['default'] = $default;
- }
- if ($bind) {
- $value['bind'] = $bind;
- }
- $value['parent'] = $parent;
- $result .= Html::select($value, false);
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search_group(&$result, $search, $name, $lang, $option, $default = false)
- {
- $value = array();
- $value['name'] = $name;
- $value['lang'] = $lang;
- $value['option'] = $option;
- if (isset($search[$name])) {
- $value['value'] = $search[$name];
- }
- if ($default) {
- //$value['default'] = $default;
- }
- $result .= Html::group($value, false);
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search_linkage(&$result, $search, $name, $lang, $option, $default = false)
- {
- $value = array();
- $value['name'] = $name;
- $value['lang'] = $lang;
- $value['option'] = $option;
- $value['search_state'] = true;
- if (isset($search[$name])) {
- $value['value'] = $search[$name];
- }
- if ($default) {
- //$value['default'] = $default;
- }
- $result .= Html::linkage($value, 'span');
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search_time(&$result, $search, $prefix, $key, $lang, $type = 'time')
- {
- $value['name'] = $prefix . 'option_start_' . $key;
- $value['lang'] = '>=' . $lang;
- if (isset($search[$value['name']])) {
- $value['value'] = Dever::maketime($search[$value['name']]);
- Dever::setInput($value['name'], $value['value'], 'search_');
- }
- $result .= Html::$type($value, false);
- $value['name'] = $prefix . 'option_end_' . $key;
- $value['lang'] = '<=' . $lang;
- if (isset($search[$value['name']])) {
- $value['value'] = Dever::maketime($search[$value['name']]);
- Dever::setInput($value['name'], $value['value'], 'search_');
- }
- $result .= Html::$type($value, false);
- }
- /**
- * 列表页头部按钮
- *
- * @return array
- */
- public function list_button()
- {
- if (Dever::load('manage/auth.oper', 2) == false) {
- return '';
- }
- $config = $this->config();
- $result = '';
- # 增加主动统计按钮
- if (isset($config['manage']['stat'])) {
- $name = '数据统计';
- if (is_string($config['manage']['stat'])) {
- $name = $config['manage']['stat'];
- }
- $config['manage']['button'][$name] = $this->url('stat');
- }
- # 增加下载报表按钮
- if (isset($config['manage']['excel'])) {
- $name = '导出数据';
- if (is_string($config['manage']['excel'])) {
- $name = $config['manage']['excel'];
- }
- $config['manage']['button'][$name] = 'onclick="jump(\''.$this->url('excel').'\', \'#form1\')"';
- }
- # 增加回收站
- if (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] && isset($config['manage']['_list']['value']['delete'])))) {
- if ($config['state'] == 2) {
- $config['manage']['button']['返回数据列表'] = $this->url('list', 0, false, '&search_option_state=1');
- } else {
- $config['manage']['button']['回收站'] = $this->url('list', 0, false, '&search_option_state=2');
- }
- }
- # 列表页按钮
- if (isset($config['manage']['button'])) {
- $result .= $this->button_list($config['manage']['button']);
- }
- return $result;
- }
- /**
- * 更新页按钮
- *
- * @return array
- */
- public function update_button()
- {
- # 新增权限
- if (Dever::load('manage/auth.oper', 2) == false) {
- Dever::alert('你没有权限');
- }
- $info = $this->info();
- $result = '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> 提交保存</button>
- <a href="' . $info['list'] . '" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclicks="msg({status:1,msg:\'yes\'})">放弃保存</a>';
- $config = $this->config();
- if (isset($config['manage']['update_button']) && $config['manage']['update_button']) {
- $result = '';
- foreach ($config['manage']['update_button'] as $k => $v) {
- if ($v == 'save-data') {
- $result .= '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> ' . $k . '</button>';
- } elseif ($v == 'copy-data') {
- $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="set_update(\'#copy_num\', 1);set_update(\'#update_where_id\', 0);submit_action();">' . $k . '</a>';
- } elseif ($v == 'copy-datas') {
- $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="copy_data($(this))">' . $k . '</a>';
- } else {
- $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="' . $v . '">' . $k . '</a>';
- }
- }
- }
- return $result;
- }
- private function button_list($button)
- {
- $result = '';
- foreach ($button as $k => $v) {
- if (is_array($v)) {
- if ($v[0] == 'location') {
- if ($v[1] == 'add') {
- $url = $this->url('add');
- } elseif ($v[1] == 'list') {
- $url = $this->url('list');
- } else {
- $url = Dever::url($v[1]);
- }
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" onclick="location.href=\''.$url.'\'">' . $k . '</a>';
- } elseif ($v[0] == 'fast') {
- if (isset($v[2]) && $v[2]) {
- $url = $this->url('add', $v[1], $v[2]);
- } elseif (isset($v[1]) && $v[1]) {
- $url = Dever::url($v[1]);
- } else {
- $url = $this->url('add');
- }
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$url.'\',\''.$k.'\', \'\')">' . $k . '</a>';
- } elseif ($v[0] == 'fasts') {
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$this->url('add').'\',\''.$k.'\', \'\', 1)">' . $k . '</a>';
- } else {
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . $this->url($v[0], false, $v[1]) . '">' . $k . '</a>';
- }
-
- } elseif (strpos($v, 'modal|') !== false) {
- $t = explode('modal|', $v);
- $result .= ' <a href="javascript:;" class="btn btn-default layui-btn layuiadmin-btn-list" onclick="showAlert(\'' . $t[1] . '\')">' . $k . '</a>';
- } elseif (strpos($v, '|') !== false) {
- $t = explode('|', $v);
- $result .= $t[0] . ' <a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $t[1] . '>' . $k . '</a>';
- } elseif (strpos($v, 'onclick') !== false) {
- $result .= ' <a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $v . '>' . $k . '</a>';
- } elseif (strpos($v, 'http://') !== false) {
- //$result .= ' <a href="javascript:;" class="btn btn-default" onclick="jump(\''.Dever::url($v).'\')">'.$k.'</a>';
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . Dever::url($v) . '">' . $k . '</a>';
- } else {
- $result .= ' <a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="load(\'' . Dever::url($v) . '\')">' . $k . '</a>';
- }
- }
- return $result;
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search()
- {
- # 新增权限
- if (Dever::load('manage/auth.oper', 2) == false) {
- return '';
- }
- $config = $this->config();
- $result = '';
- # 搜索
- if (isset($config['struct']) && isset($config['manage']['search'])) {
- $search = Dever::preInput('search_');
- $node = Html::node(array(' style="margin-top:0px;"', ''));
- $btn = '<div class="layui-inline"><input type="hidden" value="2" name="excel" id="excel"><button class="btn btn-primary layui-btn layuiadmin-btn-list" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('search') . '\');list_search($(this))" type="button" style="height: 38px;margin-left:0px;margin-top:-2px;">搜索</button></div>';
- //$result .= '<form id="f1" action="'.$this->url('list').'" method="post">';
- $prefix = 'search_';
- $result .= $node[0];
- if (isset($config['manage']['search']['linkage'])) {
- foreach ($config['manage']['search']['linkage'] as $k => $v) {
- $this->list_search_linkage($result, $search, $prefix . 'linkage_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
- if (!layadmin()) {
- $result .= '<br />';
- }
- }
- }
- if (isset($config['manage']['search']['time'])) {
- foreach ($config['manage']['search']['time'] as $k => $v) {
- $this->list_search_time($result, $search, $prefix, $k, $v);
- }
- }
- if (isset($config['manage']['search']['date'])) {
- foreach ($config['manage']['search']['date'] as $k => $v) {
- $this->list_search_time($result, $search, $prefix, $k, $v, 'date');
- }
- }
- if (isset($config['manage']['search']['select'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['select'] as $k => $v) {
- $bind = array();
- $parent = '';
- $option = $this->option($v['option']);
- if (isset($config['manage']['search_parent'][$k])) {
- $bind = array
- (
- 'onchange',
- 'setOption',
- 'search_option_' . $config['manage']['search_parent'][$k]
- );
- }
- elseif (isset($config['manage']['search_child'][$k])) {
- $parent = $config['manage']['search_child'][$k];
- }
- $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent);
- }
- }
- if (isset($config['manage']['search']['exist'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['exist'] as $k => $v) {
- $this->list_search_select($result, $search, $prefix . 'exist_' . $k, $v['lang'], $this->option($v['option']), '');
- }
- }
- if (isset($config['manage']['search']['group'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['group'] as $k => $v) {
- $this->list_search_group($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
- }
- }
- if (isset($config['manage']['search']['api'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['api'] as $k => $v) {
- $value = array();
- $value['name'] = $prefix . 'api_' . $k;
- $value['class'] = 'form-control';
- if (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- if (strpos($v['lang'], '-') !== false) {
- $t = explode('-', $v['lang']);
- $v['lang'] = $t[0];
- }
- $value['placeholder'] = $v['lang'];
- $result .= Html::text($value, false);
- }
- }
- if (isset($config['manage']['search']['text'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['text'] as $k => $v) {
- $value = array();
- $value['name'] = $prefix . 'option_' . $k;
- $value['class'] = 'form-control';
- if (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- if (strpos($v, '-') !== false) {
- $t = explode('-', $v);
- $v = $t[0];
- }
- $value['placeholder'] = $v;
- $result .= Html::text($value, false);
- }
- }
- if (isset($config['manage']['search']['fulltext'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['fulltext'] as $k => $v) {
- $value = array();
- $value['name'] = $prefix . 'fulltext_' . $k;
- $value['class'] = 'form-control';
- if (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- if (strpos($v, '-') !== false) {
- $t = explode('-', $v);
- $v = $t[0];
- }
- $value['placeholder'] = $v;
- $result .= Html::text($value, false);
- }
- }
- if (isset($config['manage']['search']['exp'])) {
- $result .= '<br />';
- $this->list_search_select($result, $search, $prefix . 'exp_col', '选择检索项', $config['manage']['search']['exp']);
- $this->list_search_select($result, $search, $prefix . 'exp_type', '', array
- (
- 3 => '大于',
- 4 => '大于等于',
- 5 => '小于',
- 6 => '小于等于',
- ), 1);
- $value = array();
- $value['name'] = $prefix . 'exp_value';
- $value['class'] = 'form-control';
- if (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- $value['placeholder'] = '填写值';
- $result .= Html::text($value, false);
- }
- # 列表页按钮
- if (isset($config['manage']['search_button'])) {
- $btn .= $this->button_list($config['manage']['search_button']);
- }
- $result .= $btn . $node[1];
- //$result .= '</form>';
- # 增加每页显示条数
- $config['manage']['num'] = $this->getNumConfig($config);
-
- if ($config['manage']['num']) {
- $result = $this->num($result, $config['manage']['num']);
- }
- }
- //print_r($result);die;
- return $result;
- }
- private function list_search_br(&$result)
- {
- if (strpos($result, ' ') && !strpos($result, '<br />')) {
- $result .= '<br />';
- }
- }
- /**
- * 获取条数配置
- *
- * @return array
- */
- private function getNumConfig($config)
- {
- if (isset($config['manage']['list_type'])) {
- return false;
- }
- if (isset($config['manage']['num']) && $config['manage']['num'] == false) {
- return false;
- }
- if (!isset($config['manage']['num'])) {
- $config['manage']['num'] = array(20,50,100);
- }
- return $config['manage']['num'];
- }
- /**
- * 生成条数的html
- *
- * @return string
- */
- private function num($result, $config)
- {
- $limit = '';
- $cur = Dever::input('search_limit', 0);
- foreach($config as $k => $v) {
- if ($cur == $k) {
- $btn = 'success';
- } else {
- $btn = 'default';
- }
- $url = $this->url('list', 0, false, '&search_limit=' . $k);
- $limit .= '<a href="'.$url.'" style="width:60px;font-weight:bold;" class="btn btn-'.$btn.'">'.$v.'</a> ';
- }
-
- $num = '<div class="form-group layui-inline"><div style="padding-top:20px;margin-bottom: -30px;"><label style="color:#bababa;margin-left:8px;margin-right:10px;font-size:14px;font-weight:bold;">每页显示条数:</label>'.$limit.'</div></div>';
- if (layadmin()) {
- $num = '';
- }
- $result .= $num;
- return $result;
- }
- /**
- * 列表页表格头
- *
- * @return array
- */
- public function list_thead($type = false)
- {
- # 新增权限
- if (Dever::load('manage/auth.oper', 1) == false) {
- Dever::alert('你没有权限');
- }
- $config = $this->config();
- $result = array();
- if (isset($config['struct'])) {
- if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
- # 验证头部权限 这里如果是多个选择权限的话,暂时无法实现。。。
- if (isset($config['top']) && is_string($config['top'])) {
- $top = Dever::load('manage/auth.getTop', array($config['top']));
- if ($top) {
- $url = $this->url('update', $top['value']);
- }
- } else {
- $url = $this->url('update', 1);
- }
- return Dever::location($url);
- } else {
- if (isset($config['manage']['mul'])) {
- if ($type == 'layui') {
- $layui = array
- (
- 'field' => 'checkbox',
- 'title' => '<input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list" lay-ignore/>',
- 'fixed' => 'left',
- );
- $result[] = $layui;
- } else {
- $result[] = '<th><input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list"/></th>';
- }
- }
- $data = array();
- $data = $this->getAdminInfo($data);
- foreach ($config['struct'] as $k => $v) {
- if (isset($v['list']) && $v['list']) {
- # 处理权限
- if (isset($v['auth'])) {
- $auth = $this->value($v['auth'], $data);
- if (!$auth) {
- continue;
- }
- }
- if (isset($v['list_name'])) {
- $v['name'] = $v['list_name'];
- } else {
- $temp = Html::cue(array('name' => $v['name']));
- $v['name'] = $temp['name'];
- }
- if (!isset($v['level'])) {
- $v['level'] = $config['level'];
- }
- if (isset($v['search']) && is_string($v['search']) && strpos($v['search'], 'order') !== false) {
- $link = Dever::url();
- $order = 'search_order_' . $k . '';
- if (strpos($link, $order) !== false) {
- $link = preg_replace('/[?|&]' . $order . '=(desc|asc)/i', '{order}', $link);
- } else {
- $link .= '{order}';
- }
- $search = Dever::input($order);
- $cancel = '';
- if ($search) {
- $asc = $search;
- $cancel = ' <a class="glyphicon glyphicon-remove-sign" style="color:black;" href="' . str_replace('{order}', '', $link) . '" title="取消排序"></a>';
- } else {
- $asc = 'desc';
- if (!isset($v['order']) && $k != 'id') {
- $cancel = ' <a class="glyphicon glyphicon-circle-arrow-down" style="color:black;" href="' . str_replace('{order}', '&' . $order . '=desc', $link) . '" title="降序"></a>';
- }
- }
- if ($asc == 'asc') {
- $asc = 'desc';
- $icon = 'down';
- $text = '降序';
- } else {
- $asc = 'asc';
- $icon = 'up';
- $text = '升序';
- }
- $link = str_replace('{order}', '&' . $order . '=' . $asc, $link);
- if ($type == 'layui') {
- $layui = array
- (
- 'field' => $k,
- 'title' => '<a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . ' <span class="layui-icon layui-icon-' . $icon . '"></span></a>',
- );
- $result[] = $layui;
-
- } else {
- $result[] = '<th data-priority="'.$v['level'].'"><a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . ' <span class="glyphicon glyphicon-circle-arrow-' . $icon . '"></span></a>' . $cancel . '</th>';
- }
-
- } else {
-
- if ($type == 'layui') {
- if ($k == 'id' || isset($v['fixed'])) {
- $layui = array
- (
- 'field' => $k,
- 'title' => $v['name'],
- //'fixed' => 'left',
- );
- } else {
- $layui = array
- (
- 'field' => $k,
- 'title' => $v['name'],
- );
- }
- $result[] = $layui;
- } else {
- $result[] = '<th data-priority="'.$v['level'].'">' . $v['name'] . '</th>';
- }
- }
- }
- }
- if ((Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false) && isset($config['manage']['_list']['value'])) {
- if ($type == 'layui') {
- $layui = array
- (
- 'field' => $config['manage']['_list']['col'],
- 'title' => $config['manage']['_list']['name'],
- //'fixed' => 'right',
- );
- $result[] = $layui;
- } else {
- $result[] = '<th data-priority="1">' . $config['manage']['_list']['name'] . '</th>';
- }
- }
- }
- }
- return $result;
- }
- # layui表头
- public function list_thead_layui()
- {
- $html = 'config.table = {};config.table.cols = [];';
- $data = array($this->list_thead('layui'));
- $data = Dever::json_encode($data);
- $html .= 'config.table.cols = ' . $data;
- return $html;
- }
- # layui表的数据 没有使用其异步方式
- public function list_tbody_layui()
- {
- $html = 'config.table.data = [];';
- $data = $this->list_tbody(false, 'layui');
- $data = Dever::json_encode($data);
- $html .= 'config.table.data = ' . $data;
- return $html;
- }
- /**
- * 导出列表
- *
- * @return array
- */
- public function list_excel_api()
- {
- Dever::$global['base']['excel'] = 1;
- $data = $this->list_tbody(true);
- if ($data) {
- $config = $this->config();
- if (isset($config['manage']['excel']) && $config['manage']['excel']) {
- $method = 'excel';
- $info = $this->info();
- $data = $this->getAdminInfo($data);
- $this->excel($info, $data, $config);
- }
- }
- //print_r($data);die;
- }
- private function excel($info, $data, $config)
- {
- $file = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
- $header = $body = array();
- $i = 0;
- foreach ($config['struct'] as $k => $v) {
- if (isset($v['list']) && $v['list']) {
- # 处理权限
- if (isset($v['auth'])) {
- $auth = $this->value($v['auth'], $data);
- if (!$auth) {
- continue;
- }
- }
- //$v['name'] = mb_convert_encoding($v['name'],'gb2312','utf-8');
- $header[$i] = $v['name'];
- $i++;
- $j = 0;
- foreach ($data as $ki => $vi) {
- $body[$j][$i] = '';
- if (isset($vi[$k])) {
- $value = $vi[$k];
- if (is_string($v['list'])) {
- $value = $this->value($v['list'], $data[$ki], $config['struct']);
- }
- if (isset($v['option'])) {
- $value = $this->getOptionValue($value, $v);
- }
- //$value = mb_convert_encoding($value,'gb2312','utf-8');
- $body[$j][$i] = $value;
- $j++;
- }
- }
- }
- }
- Dever::excelExport($body, $header, $file);
- }
- private function getOptionValue($value, $v)
- {
- # 验证option是否是匿名函数
- $v['option'] = $this->option($v['option']);
- # 位运算
- if (isset($v['bit'])) {
- $ts = array();
- foreach ($v['option'] as $tm => $tv) {
- if (isset($v['bit'][$tm]) && ($value & $tm) > 0) {
- $ts[] = $tv;
- }
- }
- $value = implode(',', $ts);
- }
- if ((isset($v['child_name']) || (isset($v['show']) && is_string($v['show'])))) {
- if (isset($v['option'][$value]) && is_array($v['option'][$value])) {
- $value = $v['option'][$value]['name'];
- } else {
- $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
- }
- } else {
- if (strstr($value, ',')) {
- $temp = explode(',', $value);
- $t = array();
- foreach ($temp as $vv) {
- if (isset($v['option'][$vv]) && is_array($v['option'][$vv])) {
- $t[] = $v['option'][$vv]['name'];
- } elseif(isset($v['option'][$vv])) {
- $t[] = $v['option'][$vv];
- } else {
- $t[] = $vv;
- }
- }
- $value = implode("\r\n", $t);
- } elseif (isset($v['option'][$value]) && is_array($v['option'][$value])) {
- $value = $v['option'][$value]['name'];
- } else {
- $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
- }
- }
- return $value;
- }
- private function _getChr($start, $num)
- {
- $num = $start + $num;
- $max = floor($num / 91);
- if ($max > 0) {
- $num = $num - (91 * $max) + $start;
- $num = chr($start) . chr($num);
- } else {
- $num = chr($num);
- }
- return $num;
- }
- /**
- * 列表页数据列表 检索
- *
- * @return array
- */
- private function list_tbody_search($config, $param, $high, $search)
- {
- # 根据api的数据检索到id
- $api = Dever::preInput('search_api_');
- if ($api) {
- foreach ($api as $k => $v) {
- if ($v) {
- unset($search[$k]);
- $k = str_replace('search_api_', '', $k);
- # 设定检索高亮
- $high[$k] = $v;
- if (isset($config['manage']['search']['api'][$k]['api'])) {
- $col = $config['manage']['search']['api'][$k]['col'];
- $option = array($col => $v);
- $v = Dever::load($config['manage']['search']['api'][$k]['api'], $option);
- $result = $config['manage']['search']['api'][$k]['result'];
- if ($v && is_array($v)) {
- if (isset($v[$result])) {
- $v = $v[$result];
- } else {
- if ($result == 'id') {
- $v = array_keys($v);
- } else {
- $t = array();
- foreach ($v as $k1 => $v1) {
- $t[] = $v1[$result];
- }
- $v = $t;
- }
- if (isset($config['manage']['search']['api'][$k]['search'])) {
- $param['option'][$config['manage']['search']['api'][$k]['search']] = array('yes', 'in');
- } else {
- $param['option'][$k] = array('yes', 'in');
- }
- }
- } else {
- $v = '-100';
- }
- }
- if (isset($config['manage']['search']['api'][$k]['search'])) {
- $param['option_' . $config['manage']['search']['api'][$k]['search']] = $v;
- } else {
- $param['option_' . $k] = $v;
- }
-
- }
- }
- }
- # 检索有无值
- $exist = Dever::preInput('search_exist_');
- if ($exist) {
- foreach ($exist as $k => $v) {
- if ($v) {
- unset($search[$k]);
- $k = str_replace('search_exist_', '', $k);
- if ($v == 'yes') {
- # 有值
- $param['option'][$k] = array('yes', '!=');
- $param['option_' . $k] = 'null';
- } elseif ($v == 'no') {
- # 无值
- $param['option'][$k] = array('yes', '=');
- $param['option_' . $k] = 'null';
- } elseif (strpos($v, '|')) {
- # 有无值或者自定义的值
- $temp = explode('|', $v);
- $param['option_' . $k] = $temp[1];
- if ($temp[0] == 'yes') {
- $param['option'][$k] = array('yes', '!=');
- $param['option'][$k . '_t1'] = array('yes-' . $k, '!=');
- } else {
- $param['option'][$k] = array('yes', '=', 'and(');
- $param['option'][$k . '_t1'] = array('yes-' . $k, '=', 'or)');
- }
- $param['option_' . $k . '_t1'] = 'null';
- } else {
- # 自定义的值
- $param['option_' . $k] = $v;
- }
- }
- }
- }
- $fulltext = Dever::preInput('search_fulltext_');
- if ($fulltext) {
- $fulltext_state = false;
- foreach ($fulltext as $k => $v) {
- if ($v) {
- unset($search[$k]);
- $k = str_replace('search_fulltext_', '', $k);
- $param['option_' . $k] = $v;
- # 设定检索高亮
- $high[$k] = $v;
- $fulltext_state = true;
- }
- }
- $this->search = true;
- }
- $linkage = Dever::preInput('search_linkage_');
- if ($linkage) {
- foreach ($linkage as $k => $v) {
- if ($v && $v != -1) {
- unset($search[$k]);
- $k = str_replace('search_linkage_', '', $k);
- if (isset($config['struct'][$k]['search_col'])) {
- $temp = explode(',', $config['struct'][$k]['search_col']);
- if (!is_array($v)) {
- $v = explode(',', $v);
- }
- foreach ($temp as $k1 => $v1) {
- if (isset($v[$k1]) && $v[$k1] != -1) {
- $param['option_' . $v1] = $v[$k1];
- }
- }
- } else {
- if (is_array($v)) {
- $v = implode(',', $v);
- }
-
- if ($v != -1) {
- $v = Dever::defaultValue($v);
- $param['option_' . $k] = $v;
- # 设定检索高亮
- $high[$k] = $v;
- }
- }
- }
- }
- $this->search = true;
- }
- $exp = Dever::preInput('search_exp_');
- if ($exp) {
- $k = $search['search_exp_col'];
- $v = $search['search_exp_value'];
- $param['option_' . $k] = $v;
- $param['search_type'] = $search['search_exp_type'];
- $this->search = true;
- }
- $order = Dever::preInput('search_order_');
- if ($order) {
- foreach ($order as $k => $v) {
- $k = str_replace('search_order_', '', $k);
- $param['order'][0][$k] = $v;
- unset($search[$k]);
- }
- }
- foreach ($search as $k => $v) {
- if ($v) {
- if (strpos($k, 'option_') !== false) {
- //Dever::setInput(str_replace('search_', '', $k), $v);
- if (is_array($v)) {
- if ($v[0] == 0) {
- continue;
- }
- $v = str_replace(',0', '', implode(',', $v));
- $t = explode(',', $v);
- $parent = end($t);
- $v .= '%';
- }
- $param[str_replace('search_', '', $k)] = $v;
- $this->search = true;
- } elseif ($k == 'search_limit') {
- $num = $this->getNumConfig($config);
- if ($num) {
- $param['page'][0] = $num[$v];
- }
- }
- }
- }
- return array($param, $high);
- }
- private function list_tbody_mul($param)
- {
- $mul = Dever::load('manage/auth.oper', 3) ? Dever::preInput('mul_') : false;
- if (Dever::input('method') == 'mul' && $mul && $mul['mul_type'] > 0) {
- if ($mul['mul_type'] == 1 && empty($mul['mul_where_id'])) {
- Dever::alert('您还未选择任何数据条目');
- }
- Dever::$global['base']['mul_type'] = $mul['mul_type'];
- unset($mul['mul_type']);
- foreach ($mul as $k => $v) {
- if ($v) {
- if (is_array($v)) {
- $v = implode(',', $v);
- }
- $param[str_replace('mul_', '', $k)] = $v;
- }
- }
- if (isset($param)) {
- $method = $this->project . '/' . $this->table . '-updatemul';
- $state = Dever::load($method, $param);
- }
- Dever::alert('reload');
- }
- }
- /**
- * 列表页数据列表:图片形式
- *
- * @return array
- */
- public function list_photo()
- {
- $config = $this->config();
- $result = array();
- if (isset($config['manage']['photo'])) {
- $high = array();
-
- $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
- $param = array();
- $parent = 0;
- if ($search) {
- list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
- }
- if (empty($param['page'])) {
- $num = $this->getNumConfig($config);
- if ($num) {
- $param['page'][0] = $num[0];
- }
- }
- $method = $this->project . '/' . $this->table . '-list';
- $result = Dever::load($method, $param);
- if ($result) {
- foreach ($result as $k => $v) {
- $result[$k] = Dever::load($config['manage']['photo'], $v);
- $result[$k]['button'] = $this->list_tbody_button($config, $v, 'div');
- }
- }
- }
- return $result;
- }
- /**
- * 列表页数据列表:表格形式
- *
- * @return array
- */
- public function list_tbody($excel = false, $type = false)
- {
- # 新增权限
- if (Dever::load('manage/auth.oper', 1) == false) {
- Dever::alert('你没有权限');
- }
- if (Dever::input('page_content') == 1) {
- return;
- }
- $config = $this->config();
- $high = array();
-
- $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
- $param = array();
- $parent = 0;
- if ($search) {
- list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
- }
- if (empty($param['page'])) {
- $num = $this->getNumConfig($config);
- if ($num) {
- $param['page'][0] = $num[0];
- }
- }
- # 批量更新
- $this->list_tbody_mul($param);
- $result = $return = array();
- if (isset($config['top_option']) && $config['top_option']) {
- $param['option'][$config['top_option']['col']] = array($config['top_option']['value'], 'in');
- }
- if ($excel == true) {
- $method = $this->project . '/' . $this->table . '-all';
- } else {
- $method = $this->project . '/' . $this->table . '-list';
- }
- //print_r($param);die;
- $data = Dever::load($method, $param);
- if (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'parent') {
- $parent = array();
- $child = array();
- foreach ($data as $k => $v) {
- if ($v[$config['name'] . '_id'] <= 0) {
- $parent[$k] = $v;
- } else {
- $v['name'] = '|-----' . $v['name'];
- $child[$v[$config['name'] . '_id']][$k] = $v;
- }
- }
- if ($parent) {
- $data = array();
- foreach ($parent as $k => $v) {
- $data[$v['id']] = $v;
- if (isset($child[$v['id']])) {
- foreach ($child[$v['id']] as $i => $j) {
- $data[$j['id']] = $j;
- }
- }
- }
- }
- } elseif (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'tree') {
- $data = $this->tree($data, $config, -1);
- }
- if ($excel == true) {
- return $data;
- }
- if (Dever::input('page_type') == 1) {
- Dever::$global['manage']['list_data'] = $data;
- return;
- }
- //print_r($data);die;
- //print_r(Helper::page("current"));die;
- if ($data && isset($config['struct'])) {
- $i = 0;
- $pg = Dever::input('pg', 1);
- $cur = Dever::input('search_limit', 0);
- $num = $this->getNumConfig($config);
- foreach ($data as $k => $v) {
- $data[$k] = $this->getAdminInfo($data[$k]);
- $data[$k]['i'] = $i;
- $ii = intval($num[$cur])*($pg-1);
- $data[$k]['r'] = $i+1+$ii;
- $result[$k] = '<tr>';
- $return[$i] = array();
- if (isset($config['manage']['mul'])) {
- $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="' . $v['id'] . '"/>';
- $result[$k] .= '<td>'.$checkbox.'</td>';
- $return[$i]['checkbox'] = $checkbox;
- }
- foreach ($config['struct'] as $ki => $vi) {
- # 处理同步
- if (isset($vi['sync']) && strpos($ki, '-')) {
- $temp = explode('-', $ki);
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
- $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
- }
- if (isset($vi['list']) && $vi['list']) {
- if (empty($v[$ki])) {
- $v[$ki] = $vi['default'];
- }
- # 处理权限
- if (isset($vi['auth'])) {
- $auth = $this->value($vi['auth'], $data[$k]);
- if (!$auth) {
- continue;
- }
- }
- $show = $v[$ki];
- if (is_string($vi['list'])) {
- $show = $this->value($vi['list'], $data[$k], $config['struct']);
- }
- if (isset($vi['key']) && $vi['update'] != 'editor') {
- $show = Dever::upload($show);
- }
- if (isset($vi['modal'])) {
- $show = Html::modal($this->value($vi['modal'], $data[$k], $config['struct']), $show);
- } elseif (isset($vi['option'])) {
- # 验证option是否是匿名函数
- $vi['option'] = $this->option($vi['option']);
- # 位运算
- if (isset($vi['bit'])) {
- $ts = array();
- foreach ($vi['option'] as $tm => $tv) {
- if (isset($vi['bit'][$tm]) && ($show & $tm) > 0) {
- $ts[] = $tv;
- }
- }
- $show = implode(',', $ts);
- }
- if ((isset($vi['child_name']) || (isset($vi['show']) && is_string($vi['show'])))) {
- if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
- $show = $vi['option'][$show]['name'];
- } else {
- $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
- }
- }
- //elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']) || $ki == 'status')
- elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']))
- {
- $vi['name'] = 'up_col_' . $ki;
- $vi['value'] = $v[$ki];
- $m = 'select';
- if (isset($vi['update']) && $vi['update'] == 'group') {
- $m = 'group';
- }
- $show = Html::$m($vi, 'form-list', '', 'style="min-width: 100px;" data-old="'.$show.'" onchange="update($(this), \'' . $v['id'] . '\', \'' . $this->project . '\', \'' . $this->table . '\')"');
- } else {
- if (strstr($show, ',')) {
- $temp = explode(',', $show);
- $t = array();
- foreach ($temp as $vv) {
- if (isset($vi['option'][$vv]) && is_array($vi['option'][$vv])) {
- $t[] = $vi['option'][$vv]['name'];
- } elseif(isset($vi['option'][$vv])) {
- $t[] = $vi['option'][$vv];
- } else {
- $t[] = $vv;
- }
- }
- $show = implode('<br />', $t);
- } elseif (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
- $show = $vi['option'][$show]['name'];
- } else {
- $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
- }
- }
- }
- $text = $show;
- if ($high && isset($high[$ki])) {
- if (isset($v['s_' . $ki])) {
- $text = $v['s_' . $ki];
- $text = str_replace('<em class="dever_highlight">', '<font color="red" class="dever_highlight">', $text);
- $text = str_replace('</em>', '</font>', $text);
- } else {
- $text = preg_replace('/('.$high[$ki].')/i', '<font color="red" class="dever_highlight">${1}</font>', $text);
- }
- }
- if (!isset($vi['option']) && isset($vi['edit']) && $vi['edit']) {
- //$url = Dever::url($vi['edit'] . '?where_id=' . $v['id'] . '&col=' . $vi['col']. '&key=' . $this->project . '&table=' . $this->table);
- $url = $this->url('updateAction');
- $vi['edit'] = $vi['edit'] == 'textarea' ? $vi['edit'] : 'text';
- $text = '<span class="edit" data-col="' . $ki . '" data-url="' . $url . '" data-id="' . $v['id'] . '" data-project="' . $this->project . '" data-table="' . $this->table . '" data-content="' . $show . '" data-type="' . $vi['edit'] . '">'.$text.'</span>';
- $result[$k] .= '<td >' . $text . '</td>';
- if (isset($return[$i][$ki])) {
- $text = $return[$i][$ki] . $text;
- }
- $return[$i][$ki] = $text;
- } else {
- $result[$k] .= '<td>' . $text . '</td>';
- if (isset($return[$i][$ki])) {
- $text = $return[$i][$ki] . $text;
- }
- $return[$i][$ki] = $text;
- }
- }
- }
- $button = $this->list_tbody_button($config, $data[$k]);
- $result[$k] .= $button;
- $return[$i]['manage'] = str_replace(array('<td>', '</td>'), '', $button);
- $result[$k] .= '</tr>';
- $i++;
- }
- }
- /*
- if ($result) {
- $thead = $this->list_thead();
- if ($thead) {
- $k = $k + 1;
- $result[$k] = '<tr>';
- foreach ($thead as $k => $v) {
- $result[$k] .= $v;
- }
- $result[$k] .= '</tr>';
- }
- }
- */
- if ($type) {
- return $return;
- }
- return $result;
- }
- private function list_tbody_button($config, $data, $type = 'td')
- {
- $result = '';
- if (isset($config['manage']['_list']['value'])) {
- $result = '<'.$type.'>';
- if ($config['state'] == 2) {
- if (isset($config['manage']['_list']['value']['update'])) {
- unset($config['manage']['_list']['value']['update']);
- }
- if (isset($config['manage']['_list']['value']['delete'])) {
- $config['manage']['_list']['value']['delete'] = '恢复';
- }
- }
- foreach ($config['manage']['_list']['value'] as $kj => $vj) {
- $pj = false;
- $h = '<span class="am-icon-pencil-square-o"></span>';
- $oper = true;
- if ($kj == 'update') {
- $oper = Dever::load('manage/auth.oper', 3);
- } elseif ($kj == 'delete') {
- $oper = Dever::load('manage/auth.oper', 5);
- $h = '<span class="am-icon-trash-o"></span>';
- }
- if (is_array($vj) && isset($vj[1])) {
- if (isset($vj[2])) {
- $oper = $this->value($vj[2], $data);
- }
- if ($oper && strpos($vj[1], 'modal|') === false) {
- $pj = $this->value($vj[1], $data);
- $vjn = $vj[0];
- }
- } else {
- $vjn = $vj;
- }
- if ($oper == true) {
- if ($kj == 'delete') {
- $class = 'layui-btn layui-btn-danger';
- } else {
- $class = 'layui-btn';
- }
- if (layadmin()) {
- $class .= ' layui-btn-xs';
- }
- if (strpos($kj, 'edits') !== false) {
- if (!isset($vj[1])) {
- $vj[1] = '';
- }
- $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url($kj, $data['id']) . '\', \''.$vj[0].'\', \''.$vj[1].'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'edit') !== false) {
- if (!isset($vj[1])) {
- $vj[1] = '';
- }
- if (strstr($vj[1], 'http')) {
- $url = $vj[1] . '&id=' . $data['id'];
- } else {
- $url = $this->url($kj, $data['id']);
- }
- $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $url . '\', \''.$vj[0].'\', \''.$vj[1].'\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'oper') !== false) {
- $result .= '<a href="javascript:;" onclick="load(\'' . Dever::url($pj) . '\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (isset($vj[1]) && strpos($vj[1], 'modal|') !== false) {
- $t = explode('|', $vj[1]);
- $result .= '<a href="#dever_modal" data-toggle="modal" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'" onclick=' . $t[1] . ' msg-send="' . $this->value($t[2], $data) . '">' . $vj[0] . '</a> ';
- } elseif (isset($vj[1])) {
- $result .= '<a href="' . $this->url($kj, $data['id'], $pj) . '" class="oper_' . $kj . '"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $h . $vjn . '</button></a> ';
- } else {
- $result .= '<span style="margin-left:5px;margin-right:10px;">' . $vj[0] . '</span>';
- }
- }
- }
- $result .= '</'.$type.'>';
- }
- return $result;
- }
- /**
- * 多级分类
- *
- * @return array
- */
- private function tree($data, $config, $parent = 0)
- {
- $key = $config['name'] . '_id';
- $result = array();
- $this->treeData($data, $result, $key, $parent);
- return $result;
- }
- private function treeData($array, &$result, $key, $parent_id = 0, $level = 0)
- {
- if (empty($array)) {
- return;
- }
- $level++;
- foreach ($array as $k => $v) {
- if (isset($v[$key]) && $v[$key] == $parent_id) {
- $v['level'] = $level;
- $v['name'] = $this->treeName($v['name'], $level);
- $result[] = $v;
- unset($array[$k]);
- $this->treeData($array, $result, $key, $v['id'], $level);
- }
- }
- }
- private function treeName($name, $level = 1)
- {
- $string = '';
- if ($level > 1) {
- /*
- $num = 4;
- $string = '-';
- //STR_PAD_LEFT
- $string = str_pad('|', $level * $num, $string);
- */
- $string = str_repeat(' ',$level-1);
- $string .= '|—';
- }
- return $string . $name;
- }
- /**
- * 列表页批量管理
- *
- * @return array
- */
- public function list_mul()
- {
- # 新增权限:更新权限
- if (Dever::load('manage/auth.oper', 3) == false) {
- return '';
- }
- $config = $this->config();
- $result = '';
- if (isset($config['struct']) && isset($config['manage']['mul'])) {
- $mul = Dever::preInput('mul_');
- $node = Html::node(array('class="am-u-sm-12" style="margin-top:10px;"', 'class="am-form-group am-input-group-sm"'));
- $btn = '<button class="btn btn-danger layui-btn layui-btn-danger" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('list') . '\');list_mul($(this))" type="button" style="height: 38px;margin-left:10px;">更新</button>';
- $prefix = 'mul_';
- $result .= $node[0];
- $default = 0;
- $option = array
- (
- 1 => '本页选中的数据',
- );
- # 只有当有搜索条件时才会出现
- if (Dever::load('manage/auth.oper', 2) && $this->search == true) {
- $option[2] = '所有页面的数据';
- $default = 2;
- }
- $this->list_search_select($result, $mul, $prefix . 'type' . '" id="' . $prefix . 'type', '请选择要更新的数据', $option, $default);
- foreach ($config['struct'] as $k => $v) {
- if ($k == 'state' && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
- $v['option'] = Dever::config('base')->state;
- if ($this->getState() == 2) {
- unset($v['option'][2]);
- } else {
- unset($v['option'][1]);
- }
-
- $v['edit'] = true;
- }
- if (isset($v['edit']) && isset($v['option']) && (is_array($v['option']) || is_object($v['option']))) {
- $result .= ' ';
- $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['option']), $v['default']);
- }
- }
- $result .= $btn . $node[1];
- }
- //print_r($result);die;
- return $result;
- }
- private function value($value, $data, $struct = array())
- {
- if (!$data) {
- return $value;
- }
- if (is_string($data)) {
- $eval = '$value = ' . $value . ';';
- eval($eval);
- return $value;
- }
- if ($value == 'table' && $struct) {
- $result = $this->struct_data($struct, $data);
- $value = Dever::table($result);
- } elseif (strpos($value, '{') !== false) {
- # 这里用到了/e,注意这里无论如何不能传入$_GET之类的用户参数 2015/7/21更新为callback方式
- //$eval = '$value = ' . preg_replace('/{(.*?)}/e', "\$data['$1']", $value) . ';';
- $func = function ($r) use ($data) {
- if (isset($data[$r[1]])) {
- return $data[$r[1]];
- }
- return false;
- };
- $eval = '$value = ' . preg_replace_callback('/{(.*?)}/', $func, $value) . ';';
- eval($eval);
- }
- return $value;
- }
- /**
- * update
- *
- * @return array
- */
- public function update()
- {
- $config = $this->config();
- $result = array();
- $prefix = 'update';
- $data = array();
- if ($this->id) {
- # 新增权限
- if (Dever::load('manage/auth.oper', 3) == false) {
- Dever::alert('你没有权限');
- }
- $data = $this->load('one', $this->id);
- if ($data) {
- //$prefix = 'set';
- }
- } else {
- # 新增权限
- if (Dever::load('manage/auth.oper', 4) == false) {
- Dever::alert('你没有权限');
- }
- }
- //print_r($config['manage']['update']);die;
- $data = $this->getAdminInfo($data);
- $col = Dever::input('col');
- foreach ($config['struct'] as $k => $v) {
- if (isset($v['update'])) {
- if ($col && !strstr(',' . $col . ',', ',' . $k . ',')) {
- continue;
- }
- //处理权限
- if (isset($v['auth'])) {
- $auth = $this->value($v['auth'], $data);
- if (!$auth) {
- continue;
- }
- }
- # 处理show模式下的class
- $class = $this->update_class($k, $v, '', $data);
- $result[$k] = '<div class="form-group ' . $class . '"><div class="margin-top">';
- if (layadmin()) {
- $result[$k] = '<div class="layui-form-item ' . $class . '"><div classs="layui-col-lg6">';
- if (isset($v['update']) && is_array($v['update'])) {
- $result[$k] = '<div class="layui-form-item ' . $class . '"><div class="layui-tab-card">';
- }
- }
- $result[$k] .= $this->create_update_html($k, $v, $data);
- $result[$k] .= '</div></div>';
- } elseif (!$col && isset($v['class'])) {
- # 分割线
- $v['name'] = $this->value($v['name'], array('test' => 1));
- if (isset($v['right'])) {
- $this->card_right = true;
- }
- $this->card = true;
- $result[$k] = Html::hr($v);
- }
- }
- if (Dever::input('ajax') == 1) {
- return implode('', $result);
- }
- //print_r($result);die;
- return $result;
- }
- public function card()
- {
- if (isset($this->card_right)) {
- return 'layui-col-md6';
- }
- return 'layui-col-md12';
- }
- public function layui_card()
- {
- if (isset($this->card)) {
- return false;
- }
- return true;
- }
- /**
- * update_class
- *
- * @return string
- */
- public function update_class($name, $param, $prefix = '', $data = array())
- {
- $class = '';
- $key = 'show';
- if (isset($param[$key]) && $param[$key]) {
- $parent = array();
- $child = array();
- if (is_string($param[$key])) {
- parse_str($param[$key], $param[$key]);
- }
- if (is_array($param[$key])) {
- foreach ($param[$key] as $k => $v) {
- if ($k == 'no') {
- $child[$k . '_' . $v] = $key . '_no';
- } elseif (strpos($v, '/')) {
- $parent[$k] = $key . '_' . $k;
- $k = $k . '_ajax';
- $value = '';
- if (isset($data[$name])) {
- $value = $data[$name];
- }
- $v = str_replace('?', '?key='.$name.'&value='.$value.'&source='.$this->name.'&', $v);
- $child[$k] = $key . '_' . $k .'" dever-ajax="'.Dever::url($v).'"';
- } else {
- if (strpos($v, ',')) {
- $temp = explode(',', $v);
- foreach ($temp as $v1) {
- $show = $k . '_' . $v1;
- if ($prefix) {
- $k = str_replace($name, $k, $prefix);
- $show = str_replace($name, $show, $prefix);
- }
- $parent[$k] = $key . '_' . $k;
- $child[$show] = $key . '_' . $show;
- }
- } else {
- $show = $k . '_' . $v;
- if ($prefix) {
- $k = str_replace($name, $k, $prefix);
- $show = str_replace($name, $show, $prefix);
- }
- $parent[$k] = $key . '_' . $k;
- $child[$show] = $key . '_' . $show;
- }
- }
- }
- }
- $class = implode(' ', $parent) . ' ' . implode(' ', $child);
- }
- if (isset($param['control'])) {
- $class .= ' ' . $key . '_input';
- }
- return $class;
- }
- /**
- * update_html
- *
- * @return string
- */
- public function create_update_html($key, $value, $data = array())
- {
- $result = '';
- $value['ext'] = $value['col'] = $key;
- $value['update'] = $value['update'] ? $value['update'] : 'text';
- if (isset($value['match']) && $value['match'] != 'option') {
- if (is_string($value['match']) && strpos($value['match'], '/') !== false) {
- if (strstr($value['match'], 'option||')) {
- $value['valid'] = 'validate[custom[' . $key . ']]';
- } else {
- $value['valid'] = 'validate[required,custom[' . $key . ']]';
- }
- } else {
- $value['valid'] = 'validate[required]';
- }
- }
- if (is_string($value['update']) && strpos($value['update'], 'copy.') !== false) {
- $value['value'] = $value['update'];
- $value['update'] = 'hidden';
- }
- $this->update_html($value, $key, $key, $data, $result);
- return $result;
- }
- /**
- * update_html
- *
- * @return string
- */
- public function update_html($param, $key, $index, $data, &$result)
- {
- if (isset($param['name']) && $param['update'] != 'hidden' && isset($param['update'])) {
- $result .= Html::pageLeft($param);
- }
- if ($param['update']) {
- # 名称带前缀
- $param['name'] = 'update_' . $param['ext'];
- $param['index'] = $index;
- //$param['value'] = '';
- # 得到当前的值
- if (isset($data[$index]) && !isset($param['value'])) {
- $param['value'] = $data[$index];
- }
- # 得到下级的值
- if (isset($param['child_value']) && isset($data['id'])) {
- $param['child_value'] = $this->value($param['child_value'], $data);
- }
- # 验证option是否是匿名函数
- if (isset($param['option'])) {
- $param['option'] = $this->option($param['option']);
- }
- if (isset($data[$index]) && isset($param['key']) && $param['update'] != 'editor') {
- $param['value'] = Dever::upload($data[$index]);
- }
- # 处理下级字段
- if (isset($param['child'])) {
- $param['child'] = $this->option($param['child']);
- if (isset($data[$key . '_parent'])) {
- $param['parent_value'] = $data[$key . '_parent'];
- }
- }
- # 设置默认值
- if (isset($param['default'])) {
- $param['default'] = $this->option($param['default']);
- }
- # 处理同步
- if (isset($param['sync']) && isset($data[$param['sync'][0]]) && strpos($key, '-')) {
- $temp = explode('-', $key);
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $param['sync'][1] => $data[$param['sync'][0]]));
- $param['value'] = isset($load[$temp[2]]) ? $load[$temp[2]] : $param['default'];
- }
- $method = $param['update'];
- if (is_array($method)) {
- $c = '';
- if (layadmin()) {
- $c = 'layui-tab-title';
- }
- $delete = true;
- if (isset($param['option'])) {
- $delete = false;
- $result .= '<ul class="nav nav-tabs '.$c.'">{tab}</ul>';
- $order = array
- (
- 'col' => $key,
- 'name' => $param['desc'],
- 'default' => '1',
- 'desc' => $param['desc'],
- 'match' => 'is_string',
- 'update' => 'hidden',
- 'option' => $param['option']
- );
- array_unshift($method, $order);
- if (isset($param['value']) && $param['value']) {
- $value = json_decode(base64_decode($param['value']), true);
- $param['value'] = array();
- foreach ($param['option'] as $k => $v) {
- foreach ($value[$k-1] as $k1 => $v1) {
- $param['value'][$v][$k1] = $v1;
- }
- }
- } else {
- $param['value'] = array();
- foreach ($param['option'] as $k => $v) {
- $param['value'][$v][$key] = $k;
- }
- }
- } else {
- $result .= '<ul class="nav nav-tabs '.$c.'">{tab}<li><a href="javascript:;" class="dever_form_add" toggle_key="' . $key . '">增加一条</a></li></ul>';
- $order = array
- (
- 'col' => 'order',
- 'name' => '排序-按照数字正序排列',
- 'default' => '1',
- 'desc' => '排序',
- 'match' => 'is_string',
- 'update' => 'text',
- );
- array_unshift($method, $order);
- }
- $tab = '';
- $this->update_child(array(), $method, $key, $result, -1, $delete);
- if (isset($param['value']) && $param['value']) {
- if (!is_array($param['value'])) {
- $param['value'] = json_decode(base64_decode($param['value']), true);
- }
- if (is_array($param['value'])) {
- $i = 0;
- foreach ($param['value'] as $k => $v) {
- $n = $k;
- if (is_string($k)) {
- $k = $i;
- }
- $this->update_child($v, $method, $key, $result, $k, $delete);
- $active = '';
- if ($k == 0) {
- $active = 'active';
- }
- if (layadmin() && $active) {
- $active .= ' layui-this';
- }
- $k = $k + 1;
- if (!is_string($n)) {
- $n = '第' . $k . '条';
- }
- $tab .= '<li class="' . $active . '"><a href="javascript:;" id="tab-' . $key . '-child-' . $k . '" toggle_key="' . $key . '" toggle_id="' . $k . '" toggle_child=".dever_' . $key . '_child" toggle="#' . $key . '-child-' . $k . '" onclick="showToggle($(this))">'.$n.'</a></li>';
- $i++;
- }
- }
-
- } else {
- $this->update_child(array(), $method, $key, $result, 0, $delete);
- $tab = '<li class="active layui-this"><a href="javascript:;" id="tab-' . $key . '-child-1" toggle_key="' . $key . '" toggle_id="1" toggle_child=".dever_' . $param['col'] . '_child" toggle="#' . $key . '-child-1" onclick="showToggle($(this))">第1条</a></li>';
- }
- $result = str_replace('{tab}', $tab, $result);
- } else {
- if (isset($param['update_input']) && isset($data[$index . '_input'])) {
- $param['update_input_data'] = explode(',', $data[$index . '_input']);
- }
- $result .= Html::$method($param);
- }
- if (isset($param['desc']) && ($param['update'] == 'text' || $param['update'] == 'password')) {
- $result .= Html::desc($param['desc']);
- }
- }
- }
- /**
- * update_action
- *
- * @return array
- */
- private function update_child($data, $param, $key, &$result, $index, $delete = true)
- {
- $style = '';
- if ($index != 0) {
- $style = 'style="display:none;"';
- }
- $result .= '<div id="' . $key . '-child-' . ($index + 1) . '" class="dever_' . $key . '_child dever_form_add_child" ' . $style . '>';
- if ($delete) {
- $result .= '<div class="dever_form_delete">[删除]</div>';
- }
- foreach ($param as $k => $v) {
- $v['type'] = $v['update'];
- $prefix = '';
- if ($index < 0) {
- $v['ext'] = $key . '_c_' . $v['col'];
- $prefix = $v['ext'];
- } else {
- $v['ext'] = $key . '_c_' . $index . '_i_' . $v['col'];
- $prefix = $v['ext'];
- }
- if ($v['col'] == 'order') {
- $v['default'] = $index+1;
- }
-
- $class = $this->update_class($v['col'], $v, $prefix);
- $result .= '<div class="form-group ' . $class . '">';
- $this->update_html($v, $key, $v['col'], $data, $result);
- $result .= '</div>';
- }
- $result .= '</div>';
- }
- /**
- * update_action
- *
- * @return array
- */
- public function update_action_api()
- {
- $method = false;
- $config = $this->config();
- $input = Dever::preInput('update_');
- if ($this->id) {
- # 新增权限
- if (Dever::load('manage/auth.oper', 3) == false) {
- Dever::alert('你没有权限');
- }
- Dever::setInput('where_id', $this->id);
- //Dever::setInput('update_where_id', $this->id);
- $info = $this->load('one', $this->id);
- if ($info) {
- $method = 'update';
- $col = Dever::input('col');
- $value = Dever::input('value');
- if ($col && $value) {
- $method = 'update_' . $col;
- //Dever::setInput('set_' . $col, $value);
- //Dever::setInput('update_' . $col, $value);
- $param['where_id'] = $this->id;
- $param['set_' . $col] = $value;
- $this->load($method, $param);
- $struct = $this->struct_data($config['struct'], array($col => $value));
- Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct, 'struct' => $config['struct']), $this->id);
- Dever::out('yes');
- return;
- }
- $prefix = 'set';
- } else {
- $method = 'insert';
- $prefix = 'add';
- }
- }
- if (!$method) {
- # 新增权限
- if (Dever::load('manage/auth.oper', 4) == false) {
- Dever::alert('你没有权限');
- }
- $method = 'insert';
- $prefix = 'add';
- }
- if ($method && $input) {
- $update = $order = array();
- $i = 0;
- $c = array();
- foreach ($input as $k => $v) {
- if ($v === '') {
- $v = 'null';
- }
- if ($v && is_string($v) && strpos($v, 'copy.') !== false) {
- $temp = str_replace('copy.', '', $v);
- if (isset($input['update_' . $temp])) {
- $v = $input['update_' . $temp];
- }
- }
- if (strpos($k, '_c_') !== false) {
- if ($v == 'null') {
- $v = '';
- }
- $temp = explode('_c_', $k);
- $k = str_replace('update_', $prefix . '_', $temp[0]);
- if (!isset($c[$k])) {
- $c[$k] = array();
- }
- if (strpos($temp[1], '_i_') !== false) {
- $temp = explode('_i_', $temp[1]);
- if (!isset($c[$k][$temp[1]])) {
- $c[$k][$temp[1]] = 0;
- } else {
- $c[$k][$temp[1]]++;
- }
- $num = $c[$k][$temp[1]];
- $update[$i][$k][$num][$temp[1]] = $v;
- if ($temp[1] == 'order') {
- $order[$i][$k][$num] = $v;
- }
- } else {
- //$update[$i][$k][$c][$temp[1]] = $v;
- }
- } elseif (strpos($k, '__') !== false) {
- $temp1 = explode('__', $k);
- $temp2 = explode('_', $temp1[0]);
- $i = $temp2[1] - 1;
- if (strpos($k, 'where_id') !== false) {
- //$update[$i]['where_id'] = $v;
- } else {
- $update[$i]['add_' . $temp1[1]] = $v;
- }
- } else {
- $ki = str_replace('update_', $prefix . '_', $k);
- if (strpos($ki, 'where_id') !== false) {
- if ($method != 'insert') {
- $update[$i]['where_id'] = $v;
- }
- } else {
- if (strpos($k, '-')) {
- $k = str_replace('update_', '', $k);
- if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
- $s_col = $config['struct'][$k]['sync'][0];
- $m_col = $config['struct'][$k]['sync'][1];
- if ($s_col == 'id') {
- $s_value = $this->id;
- } else {
- $s_one = $this->load('one', $this->id);
- $s_value = $s_one[$s_col];
- }
- $temp = explode('-', $k);
- $index = $temp[0] . '/' . $temp[1];
- $update_other_set[$index]['set_' . $temp[2]] = $v;
- //$update_other_set[$index]['set_' . $m_col] = $s_value;
- $update_other_add[$index]['add_' . $temp[2]] = $v;
- $update_other_add[$index]['add_' . $m_col] = $s_value;
- $update_other_id[$index]['option_' . $m_col] = $s_value;
- }
- } else {
- if (is_array($v)) {
- $k = str_replace('update_', '', $k);
- $kd = $k . '_id';
- if (isset($config['struct'][$kd])) {
- foreach ($v as $vk => $vt) {
- if ($vt == -1) {
- unset($v[$vk]);
- }
- }
- if ($v) {
- $vd = end($v);
- $kdi = $prefix . '_' . $kd;
- $update[$i][$kdi] = $vd;
- }
- }
- if (isset($config['struct'][$k]) && strpos($config['struct'][$k]['type'], 'int') !== false) {
- $v = end($v);
- }
- }
- $update[$i][$ki] = $v;
- }
- }
- }
- }
- //print_r($update_other_set);die;
- //print_r($input);
- //print_r($update_other);die;
- //print_r($config['struct']);die;
- # 增加复制的数量
- $copy_num = Dever::input('copy_num');
- if ($copy_num > 0) {
- $update[0]['where_id'] = 0;
- for ($i = 1; $i < $copy_num; $i++) {
- $update[$i] = $update[0];
- # 缓存处理
- $update[$i]['rank'] = $i;
- }
- }
- if ($this->id && !$info) {
- $update[0]['add_id'] = $this->id;
- }
- //print_r($update);die;
- foreach ($update as $k => $v) {
- $method = 'insert';
- $old = array();
- if (isset($v['where_id']) && $v['where_id']) {
- $method = 'update';
- $old = $this->load('one', $v['where_id']);
- }
- if (isset($order[$k])) {
- foreach ($order[$k] as $i => $j) {
- array_multisort($j, SORT_ASC, $v[$i]);
- }
- }
- if (isset($v['set_password']) && (!$v['set_password'] || $v['set_password'] == 'null')) {
- unset($v['set_password']);
- }
- $id = $this->load($method, $v);
- if ($id) {
- $struct = $this->struct_data($config['struct'], $v, $old);
- Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct), $this->id ? $this->id : $id);
- }
- if (isset($update_other_id) && $update_other_id) {
- foreach ($update_other_set as $k => $v) {
- $check = Dever::load($k . '-one', $update_other_id[$k]);
- //print_r($check);die;
- if ($check) {
- $v['where_id'] = $check['id'];
- Dever::load($k . '-update', $v);
- } else {
- Dever::load($k . '-insert', $update_other_add[$k]);
- }
- }
- }
- }
- }
- Dever::out('yes');
- }
- private function struct_data($struct, $data, $old = array())
- {
- $log = $tlog = array();
- foreach ($struct as $i => $j) {
- if (isset($j['list_name'])) {
- $j['name'] = $j['list_name'];
- } elseif (strpos($j['name'], '-')) {
- $temp = explode('-', $j['name']);
- $j['name'] = $temp[0];
- }
- if (isset($j['list_table'])) {
- $j['list'] = $j['list_table'];
- if ($j['list'] == false) {
- $data[$i] = false;
- }
- }
- $list = (isset($j['list']) && is_string($j['list']) && $j['list'] != 'table');
- if (isset($data['where_' . $i]) && $data['where_' . $i]) {
- $log[$j['name']] = $data['where_' . $i];
- } elseif (isset($data['set_' . $i]) && $data['set_' . $i]) {
- $log[$j['name']] = $data['set_' . $i];
- } elseif (isset($data['add_' . $i]) && $data['add_' . $i]) {
- $log[$j['name']] = $data['add_' . $i];
- } elseif (isset($data[$i]) && $data[$i]) {
- $log[$j['name']] = $list ? $this->value($j['list'], $data) : $data[$i];
- }
- if (isset($log[$j['name']])) {
- $tlog[$j['name']] = $log[$j['name']];
- if (is_array($tlog[$j['name']])) {
- if (isset($tlog[$j['name']][0]) && is_array($tlog[$j['name']][0])) {
- $tlog[$j['name']] = json_encode($tlog[$j['name']]);
- if (isset($old[$i]) && is_array($old[$i])) {
- $old[$i] = json_encode($old[$i]);
- }
- } elseif (isset($tlog[$j['name']][0])) {
- $tlog[$j['name']] = implode(',', $tlog[$j['name']]);
- if (isset($old[$i]) && is_array($old[$i])) {
- $old[$i] = implode(',', $old[$i]);
- }
- }
- } elseif (strpos($log[$j['name']], 'http://wx.qlogo.cn/') !== false || strpos($log[$j['name']], '.jpg') !== false || strpos($log[$j['name']], '.gif') !== false || strpos($log[$j['name']], '.png') !== false) {
- $log[$j['name']] = '<img layer-src="' . $log[$j['name']] . '" src="' . $log[$j['name']] . '" width="150">';
- if (isset($old[$i]) && $old[$i]) {
- $old[$i] = '<img layer-src="' . $old[$i] . '" src="' . $old[$i] . '" width="150">';
- }
- } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'time') !== false || strpos($i, 'date') !== false)) {
- $log[$j['name']] = date("Y-m-d H:i:s", $log[$j['name']]);
- if (isset($old[$i]) && $old[$i]) {
- $old[$i] = date("Y-m-d H:i:s", $old[$i]);
- }
- } elseif (isset($j['decode'])) {
- $log[$j['name']] = json_decode(base64_decode($log[$j['name']]), true);
- if (isset($old[$i]) && $old[$i]) {
- $old[$i] = json_decode(base64_decode($old[$i]), true);
- }
- }
- if (isset($j['option']) && !$list) {
- $name = array();
- $option = $this->option($j['option']);
- if (is_array($option)) {
- foreach ($option as $a => $b) {
- if (!is_array($log[$j['name']])) {
- if ($a == $log[$j['name']]) {
- $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
- }
- } elseif (in_array($a, $log[$j['name']])) {
- $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
- }
- }
- }
-
- $log[$j['name']] = implode(',', $name);
- }
- if (isset($old[$i]) && $old[$i] != $tlog[$j['name']]) {
- $log[$j['name']] = array('old' => $old[$i], 'new' => $log[$j['name']]);
- }
- }
- }
- return $log;
- }
- /**
- * delete_action
- *
- * @return array
- */
- public function delete_action_api()
- {
- if (Dever::load('manage/auth.oper', 5) == false) {
- Dever::alert('您没有权限');
- }
- $config = $this->config();
- if (isset($config['manage']['delete']) && $config['manage']['delete'] === 2) {
- $this->load('delete', array('where_id' => $this->id));
- } elseif (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
- $this->load('update', array('where_id' => $this->id, 'state' => 2));
- }
- return 'reloaderror';
- }
- /**
- * recovery_action
- *
- * @return array
- */
- public function recovery_action_api()
- {
- if (Dever::load('manage/auth.oper', 5) == false) {
- Dever::alert('您没有权限');
- }
- $this->load('update', array('where_id' => $this->id, 'state' => 1));
- return 'reload';
- }
- /**
- * stat 为主动统计提供相关数据
- *
- * @return array
- */
- public function stat()
- {
- //bundle 包依赖工具
- $config = $this->config();
- if (empty($config['manage']['stat'])) {
- Dever::alert('该项目主动统计功能未开放');
- }
- $data = $config['manage'];
- $data['table'] = '';
- $method = $this->project . '/' . $this->table . '-all';
- $gp = Dever::input('gp', 'month,day');
- $col = is_string($gp) ? explode(',', $gp) : $gp;
- $data['search'] = $this->stat_search($config['struct'], $gp, $config['manage']['stat'], $config['manage']['search']);
- foreach ($col as $k => $v) {
- $this->stat_data($data, $config['struct'], $v, $method);
- }
- return $data;
- }
- /**
- * stat 为主动统计提供导出数据 后续优化
- *
- * @return array
- */
- public function stat_excel()
- {
- Dever::$global['base']['excel'] = 1;
- //print_r($data['thead']);die;
- $data = $this->stat();
- if ($data && isset($data['list'])) {
- $xls = new \PHPExcel();
- $xls->getProperties()->setCreator("Maze Stat Excel")
- ->setLastModifiedBy("Maze Stat Excel")
- ->setTitle("Office 2007 XLSX Maze Document")
- ->setSubject("Office 2007 XLSX Maze Document")
- ->setDescription("Mazephp Stat Excel")
- ->setKeywords("Mazephp Stat Excel")
- ->setCategory("Mazephp Stat Excel");
- $info = $this->info();
- $name = $info['list_header'] . '的' . $info['stat_desc'] . '-' . $info['project_name'];
- $start = 65;
- $s = 0;
- foreach ($data['thead'] as $k => $v) {
- if ($s > 0) {
- $xls->createSheet();
- }
- $act = $xls->setActiveSheetIndex($s);
- $act->setTitle($v[0]);
- $s++;
- $i = 0;
- foreach ($v as $kj => $vj) {
- $num = 1;
- $cell = $this->_getChr($start, $i);
- $act->setCellValue($cell . '' . $num, $vj);
- $act->getColumnDimension($cell)->setWidth(20);
- $i++;
- if (isset($data['list'][$k])) {
- foreach ($data['list'][$k] as $ki => $vi) {
- if (isset($vi[$kj])) {
- $num += 1;
- $act->setCellValue($cell . $num, $vi[$kj]);
- }
- }
- }
- }
- }
- //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
- //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
- $xls->setActiveSheetIndex(0);
- $filename = $name . '.xlsx';
- header('Pragma: public');
- header('Expires: 0');
- header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
- header('Content-Type:application/force-download');
- header('Content-Type:application/vnd.ms-execl');
- header('Content-Type:application/octet-stream');
- header('Content-Type:application/download');
- header("Content-Disposition:attachment;filename='" . $filename . "'");
- header('Content-Transfer-Encoding:binary');
- $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
- $write->save('php://output');
- }
- }
- /**
- * stat_search
- *
- * @return mixed
- */
- private function stat_search($struct, $col, $stat, $search)
- {
- unset($struct['id']);
- unset($struct['cdate']);
- if ($stat) {
- $stat = explode(',', $stat);
- foreach ($stat as $k => $v) {
- if (isset($struct[$v])) {
- unset($struct[$v]);
- }
- }
- }
- $struct['day']['name'] = '天';
- $struct['month']['name'] = '月';
- $struct['year']['name'] = '年';
- $param['update'] = 'checkbox';
- $param['name'] = 'gp';
- $param['value'] = $col;
- $param['option'] = $struct;
- $html = '<form action="' . $this->url('stat') . '" method="post" id="f1">';
- $html .= '<div class="form-group">';
- $html .= Html::pageLeft(array('name' => '统计项', 'col' => 'col'));
- $html .= Html::radio($param);
- $html .= '</div>';
- $input = Dever::preInput('search_');
- if (isset($search['date'])) {
- foreach ($search['date'] as $k => $v) {
- $html .= '<div class="form-group">';
- $this->list_search_time($html, $input, 'search_', $k, $v, 'date');
- $html .= '</div>';
- }
- $input = Dever::preInput('search_');
- if ($input) {
- foreach ($input as $k => $v) {
- if ($v && strpos($k, 'option_') !== false) {
- Dever::setInput(str_replace('search_', '', $k), $v);
- }
- }
- }
- }
- if (isset($search['fulltext'])) {
- $html .= '<div class="form-group">';
- $this->list_search_select($html, $input, 'search_fulltext', '选择检索项', $search['fulltext']);
- $this->list_search_select($html, $input, 'search_fulltext_type', '', array
- (
- 1 => '精确匹配',
- 2 => '模糊匹配',
- 3 => '大于',
- 4 => '大于等于',
- 5 => '小于',
- 6 => '小于等于',
- ), 1);
- $value = array();
- $value['name'] = 'search_fulltext_value';
- $value['class'] = 'form-control';
- if (isset($input[$value['name']])) {
- $value['value'] = $input[$value['name']];
- $fix = '';
- if ($input['search_fulltext_type'] == 2) {
- $fix = '%';
- }
- Dever::setInput('option_' . $input['search_fulltext'], $fix . $value['value'] . $fix);
- //print_r(Dever::input('option_name'));die;
- }
- $html .= Html::text($value, false);
- $html .= '</div>';
- }
- $html .= '<input type="hidden" name="excel" id="excel" value="2"><a href="javascript:;" class="btn btn-primary" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat') . '\').submit();">确定</a>';
- $html .= ' <a href="javascript:;" class="btn btn-warning" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat_excel') . '\').submit();">下载报表</a>';
- $html .= '</form>';
- return $html;
- }
- /**
- * stat_data
- *
- * @return mixed
- */
- private function stat_data(&$data, $struct, $col, $method)
- {
- Dever::setInput('group', $col);
- switch ($col) {
- case 'year':
- $name = '按年统计';
- break;
- case 'month':
- $name = '按月统计';
- break;
- case 'day':
- $name = '按天统计';
- break;
- default:
- $name = $struct[$col]['name'];
- break;
- }
- $list = Dever::load($method, array('group' => $col, 'col' => 'count(1) as total,id'));
- $data['table'] .= '<div style="overflow-y:auto;width:100%;max-height:600px;"><table class="table table-bordered table-striped">';
- $data['table'] .= '<thead><tr><th>' . $name . '</th><th>统计数字</th></tr></thead>';
- $data['thead'][$col] = array($name, '统计数字');
- if ($list) {
- $data['table'] .= '<tbody>';
- $total = 0;
- foreach ($list as $k => $v) {
- if (isset($v[$col])) {
- if (isset($struct[$col]['option'])) {
- $option = $this->option($struct[$col]['option']);
- if (isset($option[$v[$col]])) {
- $v[$col] = $option[$v[$col]];
- if (is_array($v[$col])) {
- $v[$col] = $v[$col]['name'];
- }
- }
- }
- $data['table'] .= '<tr><td width="60%" style="word-break:break-all;word-wrap:break-word;">' . $v[$col] . '</td><td>' . $v['total'] . '</td></tr>';
- $total += $v['total'];
- $data['list'][$col][] = array($v[$col], $v['total']);
- }
- }
- $data['table'] .= '</tbody>';
- if ($total > 0 && $k > 0) {
- $data['table'] .= '<tr><td style="font-weight:bold">汇总</td><td style="font-weight:bold">' . $total . '</td></tr>';
- $data['list'][$col][] = array('汇总', $total);
- }
- }
- $data['table'] .= '</table></div>';
- }
- /**
- * load
- *
- * @return mixed
- */
- private function load($method = 'one', $param = array())
- {
- return Dever::load($this->project . '/' . $this->table . '-' . $method, $param);
- }
- /**
- * __call
- *
- * @return object
- */
- public function __call($method, $param)
- {
- if (strpos($method, 'html_') !== false) {
- return Html::text($param);
- }
- return $this;
- }
- /**
- * option
- *
- * @return string
- */
- private function option($option)
- {
- if (is_object($option)) {
- $function = $option;
- $option = $function();
- }
- return $option;
- }
- /**
- * option
- *
- * @return string
- */
- public function manage()
- {
- $config = $this->config();
- return $config;
- }
- /**
- * valid
- *
- * @return string
- */
- public function valid()
- {
- //http://placehold.it/350x150
- $config = $this->config();
- if (isset($config['struct'])) {
- $rule = array();
- $rule['required']['regex'] = 'none';
- $rule['required']['alertText'] = '此项不能为空';
- $rule['required']['alertTextCheckboxMultiple'] = '请选择一个选项';
- $rule['required']['alertTextCheckboxe'] = '请选择一个选项';
- $rule['required']['alertTextDateRange'] = '日期范围不可空白';
- foreach ($config['struct'] as $k => $v) {
- if (isset($v['match']) && $v['match'] != 'option' && is_string($v['match']) && strpos($v['match'], '/') !== false) {
- if (strstr($v['match'], 'option||')) {
- $v['match'] = str_replace('option||', '', $v['match']);
- }
- $rule[$k]['regex'] = $v['match'];
- $rule[$k]['alertText'] = $v['desc'];
- }
- }
- }
- $script = '<script>';
- //参考https://blog.csdn.net/wangzl1163/article/details/51071826
- //http://code.ciaoca.com/jquery/validation-engine/demo/demoOnForm
- $script .= '(function($){
- $.fn.validationEngineLanguage = function(){
- };
- $.validationEngineLanguage = {
- newLang: function(){
- $.validationEngineLanguage.allRules = ';
- //此处进行了转义过滤,其实也可以使用json_encode的第二个参数,不过只支持5.4以上版本,考虑到虚拟主机就放弃了
- $script .= str_replace(array('\\\\', '\\/', '"/', '/"', '/u"', '/g"', '/i"', '\x{4e00}-\x{9fa5}', '\x'), array('\\', '/', '/', '/', '/u', '/g', '/i', '\u4e00-\u9fa5', '\u'), json_encode($rule)) . ';';
- $script .= '}
- };
- $.validationEngineLanguage.newLang();
- })(jQuery);';
- $script .= '$(document).ready(function(){
- $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
- });';
- $script .= '</script>';
- //print_r($script);die;
- return $script;
- }
- /**
- * save
- *
- * @return string
- */
- public function save()
- {
- $config = $this->config();
- if (isset($config['manage']['save'])) {
- return 'yes';
- }
- return 'no';
- }
- }
|