ModuleAction.class.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. *
  4. * Module(模型管理)
  5. *
  6. */
  7. if(!defined("Ainaphp")) exit("Access Denied");
  8. class ModuleAction extends AdminbaseAction {
  9. protected $dao;
  10. function _initialize()
  11. {
  12. parent::_initialize();
  13. $this->dao=D('Admin/module');
  14. $this->Role = F('Role');
  15. $this->assign('Role',$this->Role);
  16. }
  17. function _before_index(){
  18. if($_REQUEST ['type']){
  19. $_REQUEST['where'] = 'type='.intval($_REQUEST ['type']);
  20. }else{
  21. $_REQUEST['where'] = 'type=1';
  22. }
  23. }
  24. function _before_add(){
  25. if(empty($_GET['type'])) $_GET['type']=1;
  26. }
  27. function _before_update(){
  28. $_POST['postgroup'] = implode(',',$_POST['postgroup']);
  29. }
  30. function insert(){
  31. if($_GET['isajax']){
  32. $name=$_GET['name'];
  33. $tablename = C('DB_PREFIX').$name;
  34. $db=D('');
  35. $db = DB::getInstance();
  36. $tables = $db->getTables();
  37. if(in_array($tablename,$tables)){
  38. echo 'false';
  39. }else{
  40. echo 'true';
  41. }
  42. exit;
  43. }
  44. $db=D('');
  45. $db = DB::getInstance();
  46. $tablename = C('DB_PREFIX').$_POST['name'];
  47. $_POST['name'] = ucfirst($_POST['name']);
  48. $model = $this->dao;
  49. if (false === $model->create ()) {
  50. $this->error ( $model->getError () );
  51. }
  52. $moduleid = $model->add();
  53. if(empty($moduleid)) $this->error (L('add_error').': '.$model->getDbError());
  54. if(empty($_POST['emptytable'])){
  55. $db->execute("CREATE TABLE `".$tablename."` (
  56. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  57. `catid` smallint(5) unsigned NOT NULL DEFAULT '0',
  58. `userid` int(8) unsigned NOT NULL DEFAULT '0',
  59. `username` varchar(40) NOT NULL DEFAULT '',
  60. `title` varchar(120) NOT NULL DEFAULT '',
  61. `title_style` varchar(40) NOT NULL DEFAULT '',
  62. `thumb` varchar(100) NOT NULL DEFAULT '',
  63. `keywords` varchar(120) NOT NULL DEFAULT '',
  64. `description` mediumtext NOT NULL,
  65. `content` mediumtext NOT NULL,
  66. `url` varchar(60) NOT NULL DEFAULT '',
  67. `template` varchar(40) NOT NULL DEFAULT '',
  68. `posid` tinyint(2) unsigned NOT NULL DEFAULT '0',
  69. `status` tinyint(1) unsigned NOT NULL DEFAULT '0',
  70. `listorder` int(10) unsigned NOT NULL DEFAULT '0',
  71. `hits` int(11) unsigned NOT NULL DEFAULT '0',
  72. `createtime` int(11) unsigned NOT NULL DEFAULT '0',
  73. `updatetime` int(11) unsigned NOT NULL DEFAULT '0',
  74. `lang` tinyint(1) unsigned NOT NULL DEFAULT '0',
  75. PRIMARY KEY (`id`),
  76. KEY `status` (`id`,`status`,`listorder`),
  77. KEY `catid` (`id`,`catid`,`status`),
  78. KEY `listorder` (`id`,`catid`,`status`,`listorder`)
  79. ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8");
  80. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'catid', '".L('catid')."', '', '1', '1', '6', '', '".L('catid_error')."', '', 'catid', '','1','', '0', '1', '1')");
  81. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'title', '".L('title')."', '', '1', '1', '80', '', '".L('title_error')."', '', 'title', 'array (\n \'thumb\' => \'1\',\n \'style\' => \'1\',\n \'size\' => \'55\',\n)','1','', '0', '1', '1')");
  82. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'keywords', '".L('keywords')."', '', '0', '0', '80', '', '', '', 'text', 'array (\n \'size\' => \'55\',\n \'default\' => \'\',\n \'ispassword\' => \'0\',\n \'fieldtype\' => \'varchar\',\n)','1','', '2', '1', '1')");
  83. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'description', '".L('description')."', '', '0', '0', '0', '', '', '', 'textarea', 'array (\n \'fieldtype\' => \'mediumtext\',\n \'rows\' => \'4\',\n \'cols\' => \'55\',\n \'default\' => \'\',\n)','1','', '3', '1', '1')");
  84. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'content', '".L('content')."', '', '0', '0', '0', '', '', '', 'editor', 'array (\n \'toolbar\' => \'full\',\n \'default\' => \'\',\n \'height\' => \'\',\n \'showpage\' => \'1\',\n \'enablekeylink\' => \'0\',\n \'replacenum\' => \'\',\n \'enablesaveimage\' => \'0\',\n \'flashupload\' => \'1\',\n \'alowuploadexts\' => \'\',\n)','1','', '10', '1', '1')");
  85. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'createtime', '".L('createtime')."', '', '0', '0', '0', '', '', '', 'datetime', '','1','3,4', '93', '1', '1')");
  86. //$db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'recommend', '".L('recommend')."', '', '0', '0', '1', '', '', '', 'radio', 'array (\n \'options\' => \'".L('recommend')."|1\r\n".L('norecommend')."|0\',\n \'fieldtype\' => \'tinyint\',\n \'numbertype\' => \'1\',\n \'labelwidth\' => \'\',\n \'default\' => \'\',\n)','1','3,4', '93', '0', '0')");
  87. //$db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'readpoint', '".L('readpoint')."', '', '0', '0', '5', '', '', '', 'number', 'array (\n \'size\' => \'5\',\n \'numbertype\' => \'1\',\n \'decimaldigits\' => \'0\',\n \'default\' => \'0\',\n)','1','3,4', '93', '0', '0')");
  88. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'hits', '".L('hits')."', '', '0', '0', '8', '', '', '', 'number', 'array (\n \'size\' => \'10\',\n \'numbertype\' => \'1\',\n \'decimaldigits\' => \'0\',\n \'default\' => \'0\',\n)','1','3,4', '93', '0', '0')");
  89. //$db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'readgroup', '".L('readgroup')."', '', '0', '0', '0', '', '', '', 'groupid', 'array (\n \'inputtype\' => \'checkbox\',\n \'fieldtype\' => \'tinyint\',\n \'labelwidth\' => \'85\',\n \'default\' => \'\',\n)','1','3,4', '96', '0', '1')");
  90. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'posid', '".L('posid')."', '', '0', '0', '0', '', '', '', 'posid', '','1','', '97', '1', '1')");
  91. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'template', '".L('template')."', '', '0', '0', '0', '', '', '', 'template', '','1','3,4', '98', '1', '1')");
  92. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'status', '".L('status')."', '', '0', '0', '0', '', '', '', 'radio', 'array (\n \'options\' => \'".L('fabu')."|1\r\n".L('dingshi')."|0\',\n \'fieldtype\' => \'tinyint\',\n \'numbertype\' => \'1\',\n \'labelwidth\' => \'75\',\n \'default\' => \'1\',\n)','1','3,4','99', '1', '1')");
  93. }else{
  94. $db->execute("CREATE TABLE `".$tablename."` (
  95. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  96. `status` tinyint(1) unsigned NOT NULL DEFAULT '0',
  97. `userid` int(8) unsigned NOT NULL DEFAULT '0',
  98. `username` varchar(40) NOT NULL DEFAULT '',
  99. `url` varchar(60) NOT NULL DEFAULT '',
  100. `listorder` int(10) unsigned NOT NULL DEFAULT '0',
  101. `createtime` int(11) unsigned NOT NULL DEFAULT '0',
  102. `updatetime` int(11) unsigned NOT NULL DEFAULT '0',
  103. `lang` tinyint(1) unsigned NOT NULL DEFAULT '0',
  104. PRIMARY KEY (`id`)
  105. ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8");
  106. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'createtime', '".L('createtime')."', '', '1', '0', '0', '', '', '', 'datetime', '','0','3,4', '93', '1', '1')");
  107. $db->execute("INSERT INTO `".C('DB_PREFIX')."field` VALUES ('', '".$moduleid."', 'status', '".L('status')."', '', '0', '0', '0', '', '', '', 'radio', 'array (\n \'options\' => \'".L('isshenhe')."|1\r\n".L('noshenhe')."|0\',\n \'fieldtype\' => \'tinyint\',\n \'numbertype\' => \'1\',\n \'labelwidth\' => \'75\',\n \'default\' => \'1\',\n)','0','3,4', '99', '1', '1')");
  108. }
  109. if ($moduleid !==false) {
  110. $menu=M('Menu');
  111. $data=array();
  112. $data['parentid'] = $_POST['type']==2 ? 4 : 3;
  113. $data['model'] = $_POST['name'];
  114. $data['action'] = 'index';
  115. $data['type'] = 1;
  116. $data['status'] = 1;
  117. $data['name'] = $_POST['title'];
  118. $data['listorder']=9;
  119. $pmenuid = $menu->data($data)->add();
  120. $data['parentid'] = $pmenuid;
  121. $data['action'] ='add';
  122. $data['name'] = L('module_addmenu');
  123. $menu->data($data)->add();
  124. savecache('Module');
  125. savecache('Menu');
  126. savecache('Field',$moduleid);
  127. $this->assign ( 'jumpUrl', U(MODULE_NAME.'/index') );
  128. $this->success (L('add_ok'));
  129. } else {
  130. $this->error (L('add_error').': '.$model->getDbError());
  131. }
  132. }
  133. function delete() {
  134. $id =intval($_GET['id']);
  135. $r = $this->dao->find($id);
  136. if(empty($r)) $this->error (L('do_empty'));
  137. $tablename = C('DB_PREFIX').$this->module[$id]['name'];
  138. $m = $this->dao->delete($id);
  139. if($m){
  140. $t =$this->dao->execute("DROP TABLE IF EXISTS `".$tablename."`");
  141. $module = ucfirst($this->module[$id]['name']);
  142. $menu = M('Menu');
  143. $menu->where("model='".$module."'")->delete();
  144. $module = M('Field');
  145. $f = $module->where('moduleid='.$id)->delete();
  146. savecache('Module');
  147. savecache('Menu');
  148. @unlink(RUNTIME_PATH.'Data/'.$id.'_Field.php');
  149. $this->success (L('do_ok'));
  150. }
  151. }
  152. }
  153. ?>