mychannel_edit.php
31.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
<?php
/**
* 自定义模型管理
*
* @version $Id: mychannel_edit.php 1 14:49 2010年7月20日Z tianya $
* @package DedeCMS.Administrator
* @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
* @license http://help.dedecms.com/usersguide/license.html
* @link http://www.dedecms.com
*/
require_once(dirname(__FILE__)."/config.php");
CheckPurview('c_Edit');
require_once(DEDEINC."/dedetag.class.php");
require_once(DEDEINC."/oxwindow.class.php");
if(empty($dopost)) $dopost="";
$id = isset($id) && is_numeric($id) ? $id : 0;
/*----------------
function __ShowHide()
-----------------*/
if($dopost=="show")
{
$dsql->ExecuteNoneQuery("UPDATE `#@__channeltype` SET isshow=1 WHERE id='$id' ");
ShowMsg("操作成功!", "mychannel_main.php");
exit();
}
else if($dopost=="hide")
{
$dsql->ExecuteNoneQuery("UPDATE `#@__channeltype` SET isshow=0 WHERE id='$id'");
ShowMsg("操作成功!", "mychannel_main.php");
exit();
}
/*----------------
function __CopyStart()
-----------------*/
else if($dopost=="copystart")
{
if($id==-1)
{
ShowMsg("专题模型不支持复制!","-1");
exit();
}
$row = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$id'");
if($row['id'] > -1)
{
$nrow = $dsql->GetOne("SELECT MAX(id) AS id FROM `#@__channeltype` LIMIT 0,1 ");
$newid = $nrow['id'] + 1;
if($newid < 10)
{
$newid = $newid + 10;
}
$idname = $newid;
} else {
$nrow = $dsql->GetOne("SELECT MIN(id) AS id FROM `#@__channeltype` LIMIT 0,1 ");
$newid = $nrow['id'] - 1;
if($newid < -10)
{
$newid = $newid - 10;
}
$idname = 'w'.($newid * -1);
}
$row = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$id'");
$wintitle = "频道管理-模型复制";
$wecome_info = " <a href='mychannel_main.php'>频道管理</a> - 模型复制";
$win = new OxWindow();
$win->Init("mychannel_edit.php", "js/blank.js", "post");
$win->AddTitle(" 被复制频道: [<font color='red'>".$row['typename']."</font>]");
$win->AddHidden("cid", $id);
$win->AddHidden("id", $id);
$win->AddHidden("dopost", 'copysave');
$msg = "
<table width='460' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='170' height='24' align='center'>新频道id:</td>
<td width='230'><input name='newid' type='text' id='newid' size='6' value='{$newid}' /></td>
</tr>
<tr>
<td height='24' align='center'>新频道名称:</td>
<td><input name='newtypename' type='text' id='newtypename' value='{$row['typename']}{$idname}' style='width:250px' /></td>
</tr>
<tr>
<td height='24' align='center'>新频道标识:</td>
<td><input name='newnid' type='text' id='newnid' value='{$row['nid']}{$idname}' style='width:250px' /></td>
</tr>
<tr>
<td height='24' align='center'>新附加表:</td>
<td><input name='newaddtable' type='text' id='newaddtable' value='{$row['addtable']}{$idname}' style='width:250px' /></td>
</tr>
<tr>
<td height='24' align='center'>复制模板:</td>
<td>
<input name='copytemplet' type='radio' id='copytemplet' value='1' class='np' checked='checked' /> 复制
<input name='copytemplet' type='radio' id='copytemplet' class='np' value='0' /> 不复制
</td>
</tr>
</table>
";
$win->AddMsgItem("<div style='padding:20px;line-height:300%'>$msg</div>");
$winform = $win->GetWindow("ok", "");
$win->Display();
exit();
}
/*----------------
function __Export()
-----------------*/
else if($dopost=="export")
{
if($id==-1)
{
ShowMsg("专题模型不支持导出!","-1");
exit();
}
$row = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$id' ");
$channelconfig = '';
$row['maintable'] = preg_replace('#dede_#', '#@__', $row['maintable']);
$row['addtable'] = preg_replace('#dede_#', '#@__', $row['addtable']);
foreach($row as $k=>$v)
{
if($k=='fieldset') $v = "\r\n$v\r\n";
$channelconfig .= "<channel:{$k}>$v</channel:{$k}>\r\n";
}
$wintitle = "导出内容模型规则";
$wecome_info = "<a href='mychannel_main.php'><u>内容模型管理</u></a>::导出内容模型规则";
$win = new OxWindow();
$win->Init();
$win->AddTitle("以下为规则 [{$row['typename']}] 的模型规则,你可以共享给你的朋友:");
$winform = $win->GetWindow("hand","<textarea name='config' style='width:99%;height:450px;word-wrap: break-word;word-break:break-all;'>".$channelconfig."</textarea>");
$win->Display();
exit();
}
/*----------------
function __ExportIn()
-----------------*/
else if($dopost=="exportin")
{
$wintitle = "导入内容模型规则";
$wecome_info = "<a href='mychannel_main.php'>内容模型管理</a>::导入内容模型规则";
$win = new OxWindow();
$win->Init("mychannel_edit.php", "js/blank.js", "post");
$win->AddHidden("dopost", "exportinok");
$win->AddTitle("输入规则内容:(导入模型会和原有模型冲突,不过可以在导入后修改)");
$win->AddMsgItem("<textarea name='exconfig' style='width:99%;height:450px;word-wrap: break-word;word-break:break-all;'></textarea>");
$winform = $win->GetWindow("ok");
$win->Display();
exit();
}
/*----------------
function __ExportInOk()
-----------------*/
else if($dopost=="exportinok")
{
require_once(DEDEADMIN."/inc/inc_admin_channel.php");
function GotoStaMsg($msg)
{
global $wintitle,$wecome_info,$winform;
$wintitle = "导入内容模型规则";
$wecome_info = "<a href='mychannel_main.php'>内容模型管理</a>::导入内容模型规则";
$win = new OxWindow();
$win->Init();
$win->AddTitle("操作状态提示:");
$win->AddMsgItem($msg);
$winform = $win->GetWindow("hand");
$win->Display();
exit();
}
$msg = "无信息";
$exconfig = stripslashes($exconfig);
$dtp = new DedeTagParse();
$dtp->SetNameSpace('channel', '<', '>');
$dtp->LoadSource($exconfig);
if(!is_array($dtp->CTags)) GotoStaMsg("模型规则不是合法的Dede模型规则!");
$fields = array();
foreach($dtp->CTags as $ctag)
{
$fname = $ctag->GetName('name');
$fields[$fname] = trim($ctag->GetInnerText());
}
if(!isset($fields['nid']) || !isset($fields['fieldset']))
{
GotoStaMsg("模型规则不是合法的Dede模型规则!");
}
//正常的导入过程
$mysql_version = $dsql->GetVersion(true);
$row = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE nid='{$fields['nid']}' ");
if(is_array($row))
{
GotoStaMsg("系统中已经存在相同标识 {$fields['nid']} 的规则!");
}
//创建表
if($fields['issystem'] != -1)
{
$tabsql = "CREATE TABLE IF NOT EXISTS `{$fields['addtable']}`(
`aid` int(11) NOT NULL default '0',
`typeid` int(11) NOT NULL default '0',
`redirecturl` varchar(255) NOT NULL default '',
`templet` varchar(30) NOT NULL default '',
`userip` char(15) NOT NULL default '',";
}
else
{
$tabsql = "CREATE TABLE IF NOT EXISTS `{$fields['addtable']}`(
`aid` int(11) NOT NULL default '0',
`typeid` int(11) NOT NULL default '0',
`channel` SMALLINT NOT NULL DEFAULT '0',
`arcrank` SMALLINT NOT NULL DEFAULT '0',
`mid` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT '0',
`click` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0',
`title` varchar(60) NOT NULL default '',
`senddate` int(11) NOT NULL default '0',
`flag` set('c','h','p','f','s','j','a','b') default NULL,";
}
if($mysql_version < 4.1)
{
$tabsql .= " PRIMARY KEY (`aid`), KEY `typeid` (`typeid`)\r\n) TYPE=MyISAM; ";
}
else
{
$tabsql .= " PRIMARY KEY (`aid`), KEY `typeid` (`typeid`)\r\n) ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language."; ";
}
$rs = $dsql->ExecuteNoneQuery($tabsql);
if(!$rs)
{
GotoStaMsg("创建表失败!".$dsql->GetError());
exit();
}
if($fields['issystem']==1) $fields['issystem'] = 0;
if($fields['issystem'] == 0)
{
$row = $dsql->GetOne("SELECT id FROM `#@__channeltype` ORDER BY id DESC ");
$fields['newid'] = $row['id'] + 1;
}
else
{
$row = $dsql->GetOne("SELECT id FROM `#@__channeltype` ORDER BY id ASC ");
$fields['newid'] = $row['id'] - 1;
}
$fieldset = $fields['fieldset'];
$fields['fieldset'] = addslashes($fields['fieldset']);
$inquery = " INSERT INTO `#@__channeltype`(`id` , `nid` , `typename` , `addtable` , `addcon` ,
`mancon` , `editcon` , `useraddcon` , `usermancon` , `usereditcon` ,
`fieldset` , `listfields` , `issystem` , `isshow` , `issend` ,
`arcsta`,`usertype` , `sendrank` )
VALUES('{$fields['newid']}' , '{$fields['nid']}' , '{$fields['typename']}' , '{$fields['addtable']}' , '{$fields['addcon']}' ,
'{$fields['mancon']}' , '{$fields['editcon']}' , '{$fields['useraddcon']}' , '{$fields['usermancon']}' , '{$fields['usereditcon']}' ,
'{$fields['fieldset']}' , '{$fields['listfields']}' , '{$fields['issystem']}' , '{$fields['isshow']}' , '{$fields['issend']}' ,
'{$fields['arcsta']}' , '{$fields['usertype']}' , '{$fields['sendrank']}' ); ";
$rs = $dsql->ExecuteNoneQuery($inquery);
if(!$rs) GotoStaMsg("导入模型时发生错误!".$dsql->GetError());
$dtp = new DedeTagParse();
$dtp->SetNameSpace("field","<",">");
$dtp->LoadSource($fieldset);
$allfields = '';
if(is_array($dtp->CTags))
{
foreach($dtp->CTags as $ctag)
{
//检测被修改的字段类型
$dtype = $ctag->GetAtt('type');
$fieldname = $ctag->GetName();
$dfvalue = $ctag->GetAtt('default');
$islist = $ctag->GetAtt('islist');
$mxlen = $ctag->GetAtt('maxlength');
$fieldinfos = GetFieldMake($dtype,$fieldname,$dfvalue,$mxlen);
$ntabsql = $fieldinfos[0];
$buideType = $fieldinfos[1];
if($islist!='')
{
$allfields .= ($allfields=='' ? $fieldname : ','.$fieldname);
}
$dsql->ExecuteNoneQuery(" ALTER TABLE `{$fields['addtable']}` ADD $ntabsql ");
}
}
if($allfields!='')
{
$dsql->ExecuteNoneQuery("UPDATE `#@__channeltype` SET listfields='$allfields' WHERE id='{$fields['newid']}' ");
}
GotoStaMsg("成功导入一个模型!");
}
/*----------------
function __SaveCopy()
-----------------*/
else if($dopost=="copysave")
{
$cid = intval($cid);
$row = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$cid' ", MYSQL_ASSOC);
foreach($row as $k=>$v)
{
${strtolower($k)} = addslashes($v);
}
$inquery = " INSERT INTO `#@__channeltype`(`id` , `nid` , `typename` , `addtable` , `addcon` ,
`mancon` , `editcon` , `useraddcon` , `usermancon` , `usereditcon` , `fieldset` , `listfields` ,
`issystem` , `isshow` , `issend` , `arcsta`,`usertype` , `sendrank` )
VALUES('$newid' , '$newnid' , '$newtypename' , '$newaddtable' , '$addcon' ,
'$mancon' , '$editcon' , '$useraddcon' , '$usermancon' , '$usereditcon' , '$fieldset' , '$listfields' ,
'$issystem' , '$isshow' , '$issend' , '$arcsta','$usertype' , '$sendrank' );
";
$mysql_version = $dsql->GetVersion(TRUE);
if(!$dsql->IsTable($newaddtable))
{
$dsql->Execute('me', "SHOW CREATE TABLE {$dsql->dbName}.{$addtable}");
$row = $dsql->GetArray('me', MYSQL_BOTH);
$tableStruct = $row[1];
$tb = str_replace('#@__', $cfg_dbprefix, $addtable);
$tableStruct = preg_replace("/CREATE TABLE `$addtable`/iU","CREATE TABLE `$newaddtable`",$tableStruct);
$dsql->ExecuteNoneQuery($tableStruct);
}
if($copytemplet==1)
{
$tmpletdir = $cfg_basedir.$cfg_templets_dir.'/'.$cfg_df_style;
copy("{$tmpletdir}/article_{$nid}.htm","{$tmpletdir}/{$newnid}_article.htm");
copy("{$tmpletdir}/list_{$nid}.htm","{$tmpletdir}/{$newnid}_list.htm");
copy("{$tmpletdir}/index_{$nid}.htm","{$tmpletdir}/{$newnid}_index.htm");
}
$rs = $dsql->ExecuteNoneQuery($inquery);
if($rs)
{
ShowMsg("成功复制模型,现转到详细参数页... ","mychannel_edit.php?id={$newid}&dopost=edit");
exit();
}
else
{
$errv = $dsql->GetError();
ShowMsg("系统出错,请把错误代码发送到官方论坛,以检查原因!<br /> 错误代码:mychannel_edit.php?dopost=savecopy $errv","javascript:;");
exit();
}
}
/*------------
function __SaveEdit()
------------*/
else if($dopost=="save")
{
$fieldset = preg_replace("#[\r\n]{1,}#", "\r\n", $fieldset);
$usertype = empty($usertype)? '' : $usertype;
$query = "Update `#@__channeltype` set
typename = '$typename',
addtable = '$addtable',
addcon = '$addcon',
mancon = '$mancon',
editcon = '$editcon',
useraddcon = '$useraddcon',
usermancon = '$usermancon',
usereditcon = '$usereditcon',
fieldset = '$fieldset',
listfields = '$listfields',
issend = '$issend',
arcsta = '$arcsta',
usertype = '$usertype',
sendrank = '$sendrank',
needdes = '$needdes',
needpic = '$needpic',
titlename = '$titlename',
onlyone = '$onlyone',
dfcid = '$dfcid'
where id='$id' ";
if(trim($fieldset)!='')
{
$dtp = new DedeTagParse();
$dtp->SetNameSpace("field", "<", ">");
$dtp->LoadSource(stripslashes($fieldset));
if(!is_array($dtp->CTags))
{
ShowMsg("文本配置参数无效,无法进行解析!","-1");
exit();
}
}
$trueTable = str_replace("#@__", $cfg_dbprefix, $addtable);
if(!$dsql->IsTable($trueTable))
{
ShowMsg("系统找不到你所指定的表 $trueTable ,请手工创建这个表!","-1");
exit();
}
$dsql->ExecuteNoneQuery($query);
ShowMsg("成功更改一个模型!","mychannel_main.php");
exit();
}
/*--------------------
function __GetTemplate()
--------------------*/
else if($dopost=="gettemplets")
{
require_once(DEDEINC."/oxwindow.class.php");
$row = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$id'");
$wintitle = " 频道管理-查看模板";
$wecome_info = "<a href='mychannel_main.php'>频道管理</a>::查看模板";
$win = new OxWindow();
$win->Init("", "js/blank.js", "");
$win->AddTitle(" 频道:(".$row['typename'].")默认模板文件说明:");
$defaulttemplate = $cfg_templets_dir.'/'.$cfg_df_style;
$msg = "
文档模板:{$defaulttemplate}/article_{$row['nid']}.htm
<a href='tpl.php?acdir={$cfg_df_style}&action=edit&filename=article_{$row['nid']}.htm'>[修改]</a><br/>
列表模板:{$defaulttemplate}/list_{$row['nid']}.htm
<a href='tpl.php?acdir={$cfg_df_style}&action=edit&filename=list_{$row['nid']}.htm'>[修改]</a>
<br/>
频道封面模板:{$defaulttemplate}/index_{$row['nid']}.htm
<a href='tpl.php?acdir={$cfg_df_style}&action=edit&filename=index_{$row['nid']}.htm'>[修改]</a>
";
$win->AddMsgItem("<div style='padding:20px;line-height:300%'>$msg</div>");
$winform = $win->GetWindow("hand","");
$win->Display();
exit();
}
/*--------------------
function __Delete()
--------------------*/
else if($dopost=="delete")
{
CheckPurview('c_Del');
$row = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$id'");
if($row['issystem'] == 1)
{
ShowMsg("系统模型不允许删除!","mychannel_main.php");
exit();
}
if(empty($job)) $job="";
if($job == "") //确认提示
{
require_once(DEDEINC."/oxwindow.class.php");
$wintitle = "频道管理-删除模型";
$wecome_info = "<a href='mychannel_main.php'>频道管理</a>::删除模型";
$win = new OxWindow();
$win->Init("mychannel_edit.php","js/blank.js","POST");
$win->AddHidden("job","yes");
$win->AddHidden("dopost",$dopost);
$win->AddHidden("id",$id);
$win->AddTitle("你确实要删除 (".$row['typename'].") 这个频道?");
$winform = $win->GetWindow("ok");
$win->Display();
exit();
} else if($job=="yes") //操作
{
require_once(DEDEINC."/typeunit.class.admin.php");
$myrow = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$id'",MYSQL_ASSOC);
if(!is_array($myrow))
{
ShowMsg('你所指定的频道信息不存在!','-1');
exit();
}
//检查频道的表是否独占数据表
$addtable = str_replace($cfg_dbprefix,'',str_replace('#@__',$cfg_dbprefix,$myrow['addtable']));
$row = $dsql->GetOne("SELECT COUNT(id) AS dd FROM `#@__channeltype` WHERE addtable like '{$cfg_dbprefix}{$addtable}' OR addtable LIKE CONCAT('#','@','__','$addtable') ; ");
$isExclusive2 = ($row['dd']>1 ? 0 : 1 );
//获取与频道关连的所有栏目id
$tids = '';
$dsql->Execute('qm',"SELECT id FROM `#@__arctype` WHERE channeltype='$id'");
while($row = $dsql->GetArray('qm'))
{
$tids .= ($tids=='' ? $row['id'] : ','.$row['id']);
}
//删除相关信息
if($tids!='')
{
$dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE typeid IN($tids); ");
$dsql->ExecuteNoneQuery("DELETE FROM `{$myrow['maintable']}` WHERE typeid IN($tids); ");
$dsql->ExecuteNoneQuery("DELETE FROM `#@__spec` WHERE typeid IN ($tids); ");
$dsql->ExecuteNoneQuery("DELETE FROM `#@__feedback` WHERE typeid IN ($tids); ");
$dsql->ExecuteNoneQuery("DELETE FROM `#@__arctype` WHERE id IN ($tids); ");
}
//删除附加表或附加表内的信息
if($isExclusive2==1)
{
$dsql->ExecuteNoneQuery("DROP TABLE IF EXISTS `{$cfg_dbprefix}{$addtable}`;");
}
else
{
if($tids!='' && $myrow['addtable']!='')
{
$dsql->ExecuteNoneQuery("DELETE FROM `{$myrow['addtable']}` WHERE typeid IN ($tids); ");
}
}
//删除频道配置信息
$dsql->ExecuteNoneQuery("DELETE FROM `#@__channeltype` WHERE id='$id' ");
//更新栏目缓存
UpDateCatCache($dsql);
ShowMsg("成功删除一个模型!","mychannel_main.php");
exit();
}
}//del
/*----------------
function __modifysearch()
-----------------*/
else if($dopost == 'modifysearch')
{
if(!isset($step)) $step=0;
if(empty($step))
{
$step = 1;
$mid = intval($mid);
$query = "SELECT mainfields, addonfields, template FROM #@__advancedsearch WHERE mid='$mid'";
$searchinfo = $dsql->GetOne($query);
if(!is_array($searchinfo))
{
$searchinfo['mainfields'] = $searchinfo['addonfields'] = $searchinfo['template'] = '';
}
$searchinfo['mainfields'] = explode(',', $searchinfo['mainfields']);
$searchinfo['addonfields'] = explode(',', $searchinfo['addonfields']);
$addonfieldsarr = array();
foreach($searchinfo['addonfields'] as $k)
{
$karr = explode(':', $k);
$addonfieldsarr[] = $karr[0];
}
$template = $searchinfo['template'] == '' ? 'advancedsearch.htm' : $searchinfo['template'];
$c1 = in_array('iscommend', $searchinfo['mainfields']) ? 'checked' : '';
$c2 = in_array('typeid', $searchinfo['mainfields']) ? 'checked' : '';
$c3 = in_array('writer', $searchinfo['mainfields']) ? 'checked' : '';
$c4 = in_array('source', $searchinfo['mainfields']) ? 'checked' : '';
$c5 = in_array('senddate', $searchinfo['mainfields']) ? 'checked' : '';
$mainfields = '<label><input type="checkbox" name="mainfields[]" '.$c1.' value="iscommend" class="np" />是否推荐</label>';
$mainfields .= '<label><input type="checkbox" name="mainfields[]" '.$c2.' value="typeid" class="np" />栏目</label>';
$mainfields .= '<label><input type="checkbox" name="mainfields[]" '.$c3.' value="writer" class="np" />作者</label>';
$mainfields .= '<label><input type="checkbox" name="mainfields[]" '.$c4.' value="source" class="np" />来源</label>';
$mainfields .= '<label><input type="checkbox" name="mainfields[]" '.$c5.' value="senddate" class="np" />发布时间</label>';
/*
$mainfields .= '<label><input type="checkbox" name="mainfields[]" value="description" />摘要</label>';
$mainfields .= '<label><input type="checkbox" name="mainfields[]" value="keywords" />关键词</label>';
$mainfields .= '<label><input type="checkbox" name="mainfields[]" value="smalltypeid" />小分类</label>';
$mainfields .= '<label><input type="checkbox" name="mainfields[]" value="area" />地区</label>';
$mainfields .= '<label><input type="checkbox" name="mainfields[]" value="sector" />行业</label>';
*/
$query = "SELECT * FROM `#@__channeltype` WHERE id='$mid'";
$channel = $dsql->GetOne($query);
$searchtype = array('int', 'datetime', 'float', 'textdata', 'textchar', 'text', 'htmltext', 'multitext', 'select', 'radio', 'checkbox');
$addonfields = '';
$dtp = new DedeTagParse();
$dtp->SetNameSpace("field", "<", ">");
$dtp->LoadSource($channel['fieldset']);
if($channel['issystem'] < 0)
{
$checked = in_array('typeid', $addonfieldsarr) ? 'checked' : '';
$addonfields .= '<label><input type="checkbox" name="addonfields[]" '.$checked.' value="typeid" class="np" />栏目</label>';
$checked = in_array('senddate', $addonfieldsarr) ? 'checked' : '';
$addonfields .= '<label><input type="checkbox" name="addonfields[]" '.$checked.' value="senddate" class="np" />发布时间</label>';
}
if(is_array($dtp->CTags) && !empty($dtp->CTags))
{
foreach($dtp->CTags as $ctag)
{
$datatype = $ctag->GetAtt('type');
$value = $ctag->GetName();
if($channel['issystem'] < 0)
{
$_oo = array('channel','arcrank', 'title', 'senddate', 'mid', 'click', 'flag', 'litpic', 'userip', 'lastpost', 'scores', 'goodpost', 'badpost', 'endtime');
if(in_array($value, $_oo)) continue;
}
$label = $ctag->GetAtt('itemname');
if(in_array($datatype, $searchtype)){
$checked = in_array($value, $addonfieldsarr) ? 'checked' : '';
$addonfields .= "<label><input type=\"checkbox\" name=\"addonfields[]\" $checked value=\"$value\" class='np' />$label</label>";
}
}
}
require_once(dirname(__FILE__)."/templets/mychannel_modifysearch.htm");
} else if ($step == 1)
{
$query = "SELECT * FROM `#@__channeltype` WHERE id='$mid'";
$channel = $dsql->GetOne($query);
if(empty($addonfields))
{
$addonfields = '';
}
$template = trim($template);
$forms = '<form action="'.$cfg_cmspath.'/plus/advancedsearch.php" method="post">';
$forms .= "<input type=\"hidden\" name=\"mid\" value=\"$mid\" />";
$forms .= "<input type=\"hidden\" name=\"dopost\" value=\"search\" />";
$forms .= "关键词:<input type=\"text\" name=\"q\" /><br />";
$mainstring = '';
if(!empty($mainfields) && is_array($mainfields))
{
$mainstring = implode(',', $mainfields);
foreach($mainfields as $mainfield)
{
if($mainfield == 'typeid')
{
require_once(dirname(__FILE__)."/../include/typelink.class.php");
$tl = new TypeLink(0);
$typeOptions = $tl->GetOptionArray(0,0,$mid);
$forms .= "<br />栏目:<select name='typeid' style='width:200'>\r\n";
$forms .= "<option value='0' selected>--不限栏目--</option>\r\n";
$forms .= $typeOptions;
$forms .= "</select>";
$forms .= "<label><input type=\"checkbox\" name=\"includesons\" value=\"1\" />包含子栏目</label><br />";
}else if ($mainfield == 'iscommend')
{
$forms .= "<label><input type=\"checkbox\" name=\"iscommend\" value=\"1\" />推荐</label><br />";
}else if ($mainfield == 'writer')
{
$forms .= "作者: <input type=\"text\" name=\"writer\" value=\"\" /><br />";
}else if ($mainfield == 'source')
{
$forms .= "来源: <input type=\"text\" name=\"source\" value=\"\" /><br />";
}else if ($mainfield == 'senddate')
{
$forms .= "开始时间:<input type=\"text\" name=\"startdate\" value=\"\" /><br />";
$forms .= "结束时间:<input type=\"text\" name=\"enddate\" value=\"\" /><br />";
}
}
}
$addonstring = '';
$intarr = array('int','float');
$textarr = array('textdata','textchar','text','htmltext','multitext');
if($channel['issystem'] < 0)
{
foreach($addonfields as $addonfield)
{
if($addonfield == 'typeid'){
require_once(dirname(__FILE__)."/../include/typelink.class.php");
$tl = new TypeLink(0);
$typeOptions = $tl->GetOptionArray(0,0,$mid);
$forms .= "<br />栏目:<select name='typeid' style='width:200'>\r\n";
$forms .= "<option value='0' selected>--不限栏目--</option>\r\n";
$forms .= $typeOptions;
$forms .= "</select>";
$forms .= "<label><input type=\"checkbox\" name=\"includesons\" value=\"1\" />包含子栏目</label><br />";
$addonstring .= 'typeid:int,';
} elseif($addonfield == 'senddate') {
$forms .= "开始时间:<input type=\"text\" name=\"startdate\" value=\"\" /><br />";
$forms .= "结束时间:<input type=\"text\" name=\"enddate\" value=\"\" /><br />";
$addonstring .= 'senddate:datetime,';
}
}
}
if(is_array($addonfields) && !empty($addonfields))
{
$query = "SELECT * FROM #@__channeltype WHERE id='$mid'";
$channel = $dsql->GetOne($query);
$dtp = new DedeTagParse();
$dtp->SetNameSpace("field", "<", ">");
$dtp->LoadSource($channel['fieldset']);
$fieldarr = $itemarr = $typearr = array();
foreach($dtp->CTags as $ctag)
{
foreach($addonfields as $addonfield)
{
if($ctag->GetName() == $addonfield)
{
if($addonfield == 'typeid' || $addonfield == 'senddate') continue;
$fieldarr[] = $addonfield;
$itemarr[] = $ctag->GetAtt('itemname');
$typearr[] = $ctag->GetAtt('type');
$valuearr[] = $ctag->GetAtt('default');
}
}
}
foreach($fieldarr as $k=>$field)
{
$itemname = $itemarr[$k];
$name = $field;
$type = $typearr[$k];
$tmp = $name.':'.$type;
if(in_array($type, $intarr))
{
$forms .= "<br />$itemname : <input type=\"text\" name=\"start".$name."\" value=\"\" /> 到 <input type=\"text\" name=\"end".$name."\" value=\"\" /><br />";
} else if (in_array($type, $textarr))
{
$forms .= "$itemname : <input type=\"text\" name=\"$name\" value=\"\" /><br />";
} else if ($type == 'select')
{
$values = explode(',', $valuearr[$k]);
if(is_array($values) && !empty($values))
{
$forms .= "<br />$itemname : <select name=\"$name\" ><option value=\"\">不限</option>";
foreach($values as $value)
{
$forms .= "<option value=\"$value\">$value</option>";
}
$forms .= "</select>";
}
} else if ($type == 'radio')
{
$values = explode(',', $valuearr[$k]);
if(is_array($values) && !empty($values)){
$forms .= "<br />$itemname : <label><input type=\"radio\" name=\"".$name."\" value=\"\" checked />不限</label>";
foreach($values as $value){
$forms .= "<label><input type=\"radio\" name=\"".$name."\" value=\"$value\" />$value</label>";
}
}
} else if ($type == 'checkbox')
{
$values = explode(',', $valuearr[$k]);
if(is_array($values) && !empty($values))
{
$forms .= "<br />$itemname : ";
foreach($values as $value)
{
$forms .= "<label><input type=\"checkbox\" name=\"".$name."[]\" value=\"$value\" />$value</label>";
}
}
}elseif($type == 'datetime'){
$forms .= "<br />开始时间:<input type=\"text\" name=\"startdate\" value=\"\" /><br />";
$forms .= "结束时间:<input type=\"text\" name=\"enddate\" value=\"\" /><br />";
}else{
$tmp = '';
}
$addonstring .= $tmp.',';
}
}
$forms .= '<input type="submit" name="submit" value="开始搜索" /></form>';
$formssql = addslashes($forms);
$query = "REPLACE INTO #@__advancedsearch(mid, maintable, mainfields, addontable, addonfields, forms, template) VALUES('$mid','$maintable','$mainstring','$addontable','$addonstring','$formssql', '$template')";
$dsql->ExecuteNoneQuery($query);
$formshtml = htmlspecialchars($forms);
echo '<meta http-equiv="Content-Type" content="text/html; charset='.$cfg_soft_lang.'">';
echo "下面为生成的html表单,请自行复制,根据自己需求修改样式后粘贴到对应的模板中<br><br><textarea cols=\"100\" rows=\"10\">".$forms."</textarea>";
echo '<br />预览:<br /><hr>';
echo $forms;
}
exit;
}
//删除自定义搜索;
else if($dopost == 'del')
{
$mid = intval($mid);
$dsql->ExecuteNoneQuery("DELETE FROM `#@__advancedsearch` WHERE mid = '$mid'; ");
ShowMsg("成功删除一个自定义搜索!","mychannel_main.php");
exit();
}
$row = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$id' ");
require_once(DEDEADMIN."/templets/mychannel_edit.htm");