KeyListAction.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class KeyListAction extends CommonAction{
  10. //KEYlist
  11. public function index(){
  12. $model = M('KeyList');
  13. $count = $model->count();
  14. $p = new Page($count);
  15. $page = $p->show();
  16. $vo = $model->where(array('is_delete'=>0))->limit($p->firstRow.','.$p->listRows)->select();
  17. $this->assign("page", $page);
  18. $this->assign("list", $vo);
  19. $this->display ();
  20. }
  21. //添加页面显示
  22. public function add()
  23. {
  24. $this->display();
  25. }
  26. //添加方法
  27. public function insert()
  28. {
  29. B('FilterString');
  30. filter_request($_REQUEST);
  31. $data =array();
  32. //$data['type'] = trim($_REQUEST['type']);
  33. $data['aes_key'] = trim($_REQUEST['aes_key']);
  34. $data['version'] = trim($_REQUEST['version']);
  35. $data['is_init'] = trim($_REQUEST['is_init']);
  36. $data['is_effect'] = trim($_REQUEST['is_effect']);
  37. //开始验证有效性
  38. $this->assign("jumpUrl", u(MODULE_NAME . "/add"));
  39. /*if (!in_array($data['type'],array('ios','android'))) {
  40. $this->error("手机端类型请输入ios或android");
  41. }
  42. if ($data['version']=='') {
  43. $this->error("请输入yyyymmddnn版本格式");
  44. }*/
  45. // 更新数据
  46. $log_info = 'aes_key';
  47. $list = $GLOBALS['db']->autoExecute(DB_PREFIX."key_list", $data,"INSERT");
  48. if ($list!==false) {
  49. //更新动态秘钥
  50. $this->edit_full_group_info();
  51. //成功提示
  52. save_log($log_info . L("INSERT_SUCCESS"), 1);
  53. $this->success(L("INSERT_SUCCESS"));
  54. } else {
  55. //错误提示
  56. save_log($log_info . L("INSERT_FAILED"), 0);
  57. $this->error(L("INSERT_FAILED"));
  58. }
  59. }
  60. //编辑
  61. public function edit(){
  62. $id = intval($_REQUEST['id']);
  63. $list = M(MODULE_NAME)->where('id='.$id)->find();//根据ID相关数据
  64. $this->assign('vo',$list);
  65. $this->display();
  66. }
  67. //删除
  68. public function delete() {
  69. //彻底删除指定记录
  70. $ajax = intval($_REQUEST['ajax']);
  71. $id = intval($_REQUEST ['id']);
  72. if (isset ( $id )) {
  73. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  74. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  75. foreach($rel_data as $data)
  76. {
  77. if($data['is_init']){
  78. if(is_array($id)){
  79. $key = array_search($data['id'],$id);
  80. if($key){
  81. unset($id[$key]);
  82. save_log($data['aes_key'].'是打包填写KEY不能删除!',1);
  83. }
  84. }else{
  85. $this->error($data['aes_key'].'是打包填写KEY不能删除!!',1);
  86. }
  87. }
  88. $info[] = $data['aes_key'];
  89. }
  90. if($info) $info = implode(",",$info);
  91. $ids = explode ( ',', $id );
  92. foreach($ids as $uid)
  93. {
  94. $sql = "update ".DB_PREFIX."key_list set is_delete = 1 where is_delete = 0 and id =".$uid;
  95. $GLOBALS['db']->query($sql); //删除
  96. }
  97. //更新动态秘钥
  98. $this->edit_full_group_info();
  99. save_log($info.l("DELETE_SUCCESS"),1);
  100. $this->success (l("DELETE_SUCCESS"),$ajax);
  101. } else {
  102. $this->error (l("INVALID_OPERATION"),$ajax);
  103. }
  104. }
  105. //更新
  106. public function update(){
  107. B('FilterString');
  108. filter_request($_REQUEST);
  109. $data =array();
  110. $id = trim($_REQUEST['id']);
  111. $data['aes_key'] = trim($_REQUEST['aes_key']);
  112. $data['is_init'] = trim($_REQUEST['is_init']);
  113. $data['is_effect'] = trim($_REQUEST['is_effect']);
  114. //开始验证有效性
  115. $this->assign("jumpUrl", u(MODULE_NAME . "/edit"));
  116. /*if (!in_array($data['type'],array('ios','android'))) {
  117. $this->error("手机端类型请输入ios或android");
  118. }
  119. if ($data['version']=='') {
  120. $this->error("请输入yyyymmddnn版本格式");
  121. }*/
  122. // 更新数据
  123. $log_info = 'aes_key';
  124. foreach($data as $k=>$v){
  125. if($v==''){
  126. unset($data[$k]);
  127. }
  128. }
  129. $list = $GLOBALS['db']->autoExecute(DB_PREFIX . "key_list", $data, $mode = 'UPDATE', 'id=' . $id);
  130. if ($list!==false) {
  131. //更新动态秘钥
  132. $this->edit_full_group_info();
  133. //成功提示
  134. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  135. $this->success(L("UPDATE_SUCCESS"));
  136. } else {
  137. //错误提示
  138. save_log($log_info . L("UPDATE_FAILED"), 0);
  139. $this->error(L("UPDATE_FAILED"));
  140. }
  141. }
  142. //彻底删除指定记录
  143. public function foreverdelete() {
  144. //彻底删除指定记录
  145. $ajax = intval($_REQUEST['ajax']);
  146. $id = intval($_REQUEST ['id']);
  147. if (isset ( $id )) {
  148. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  149. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  150. foreach($rel_data as $data)
  151. {
  152. $info[] = $data['aes_key'];
  153. }
  154. if($info) $info = implode(",",$info);
  155. $list = M(MODULE_NAME)->where ( $condition )->delete();
  156. if ($list!==false) {
  157. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  158. clear_auto_cache("get_help_cache");
  159. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  160. } else {
  161. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  162. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  163. }
  164. } else {
  165. $this->error (l("INVALID_OPERATION"),$ajax);
  166. }
  167. }
  168. //更新动态秘钥
  169. public function edit_full_group_info(){
  170. $m_config = load_auto_cache("m_config");//初始化手机端配置
  171. $group_id = strim($m_config['full_group_id']);
  172. if($group_id){
  173. require_once(APP_ROOT_PATH . 'system/tim/TimApi.php');
  174. $api = createTimAPI();
  175. $aes_key_info = get_privatekey();
  176. if(is_array($aes_key_info[0]['aes_key'])){
  177. $aes_key = $aes_key_info[0]['aes_key'][0];
  178. }else{
  179. $aes_key = $aes_key_info[0]['aes_key'];
  180. }
  181. $base_info_filter = array("Introduction");
  182. $ret = $api->group_get_group_info2(array('0'=>$group_id),$base_info_filter);
  183. if($ret['GroupInfo'][0]['ErrorCode']){
  184. $ret = $api->full_group_create($group_id,$aes_key);
  185. }else{
  186. if($ret['GroupInfo'][0]['Introduction'] != $aes_key){
  187. $info_set['introduction'] = $aes_key;
  188. $rets = $api->group_modify_group_base_info2($ret['GroupInfo'][0]['GroupId'], 'FullGroup', $info_set);
  189. }
  190. }
  191. }
  192. }
  193. }
  194. ?>