PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/app/controllers/abusive_words_controller.php

https://bitbucket.org/fxrialab/spsp_editor
PHP | 124 lines | 114 code | 7 blank | 3 comment | 21 complexity | d06838d6d4dacf2d2ce47c1e786975ad MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
  1. <?php
  2. class AbusiveWordsController extends AppController
  3. {
  4. var $name='AbusiveWords';
  5. var $components = array('Pagination');
  6. var $helpers = array('Pagination', 'error');
  7. function manage_abuse()
  8. {
  9. $this->checkSession();
  10. $this->layout = 'default_user';
  11. $this->set('menu', $_REQUEST['menu']);
  12. $this->set('rows', mysql_num_rows(mysql_query("select * from abusive_words")));
  13. if (empty($this->data))
  14. {
  15. if(isset($_REQUEST['id']))
  16. {
  17. $id = $_REQUEST['id'];
  18. $this->AbusiveWord->id = $_REQUEST['id'];
  19. $this->data = $this->AbusiveWord->read(null, $id);
  20. }
  21. }
  22. else if(!empty($this->data) && isset($_REQUEST['act']) && $_REQUEST['act'] == "edit")
  23. {
  24. $id = $_REQUEST['id'];
  25. if($this->data['AbusiveWord']['words'] == "")
  26. $this->set('msg', $msg = "Please give any word");
  27. else
  28. {
  29. $word_find = "select * from abusive_words where words='".addslashes($this->data['AbusiveWord']['words'])."'";
  30. $num_rows = mysql_num_rows(mysql_query($word_find));
  31. if($num_rows==0)
  32. {
  33. $up_word_qry = "update abusive_words set words ='".addslashes($this->data['AbusiveWord']['words'])."' where id ='".$id."'";
  34. $up_word = mysql_query($up_word_qry);
  35. }
  36. else $this->set('msg', $msg = "This word has already been inserted");
  37. if(isset($res))
  38. {
  39. $this->flash('Your post has been saved.','/users');
  40. $this->redirect('/abusive_words/manage_abuse?menu='.$_REQUEST['menu']."&page=".$_REQUEST['page']);
  41. }
  42. }
  43. }
  44. else
  45. {
  46. $word = "select * from abusive_words where words = '".addslashes($this->data['AbusiveWord']['words'])."'";
  47. $chk_word = mysql_query($word);
  48. if(mysql_num_rows($chk_word) == 0)
  49. {
  50. if($this->data['AbusiveWord']['words'] == "")
  51. $this->set('msg', $msg = "Please give any word");
  52. else
  53. {
  54. $qry = "insert into abusive_words(`id`,`words`) values('','".addslashes($this->data['AbusiveWord']['words'])."')";
  55. $res_word = mysql_query($qry);
  56. if(isset($res_word))
  57. {
  58. $this->flash('Your post has been saved.','/users');
  59. $this->redirect('/abusive_words/manage_abuse?menu='.$_REQUEST['menu']);
  60. }
  61. }
  62. }
  63. else
  64. {
  65. $this->set('msg', $msg = "This word has already been inserted");
  66. //$this->redirect('/abusive_words/manage_abuse?menu='.$_REQUEST['menu']);
  67. }
  68. }
  69. $order = "";
  70. if(!empty($_GET['search']))
  71. {
  72. $criteria="1";
  73. $order.= " ORDER BY `AbusiveWord`.`words` DESC";
  74. $this->data['AbusiveWord']['search'] = $_GET['search'];
  75. $search=trim($this->data['AbusiveWord']['search']);
  76. $criteria .= " and AbusiveWord.words LIKE '".$search."%'";
  77. list($order,$limit,$page) = $this->Pagination->init($criteria);
  78. $this->set('users', $this->AbusiveWord->findAll($criteria, NULL, $order, $limit, $page));
  79. }
  80. else
  81. {
  82. $criteria= "1";
  83. $order.= " ORDER BY `AbusiveWord`.`words` DESC";
  84. list($order,$limit,$page) = $this->Pagination->init($criteria);
  85. $this->set('users', $this->AbusiveWord->findAll($criteria, NULL, $order, $limit, $page));
  86. }
  87. }
  88. function delete($id=null)
  89. {
  90. $this->checkSession();
  91. $id=$_REQUEST['id'];
  92. if(isset($_REQUEST['box']))
  93. {
  94. /////IF SEARCH IS COLLECTIVE OR CHOSEN BY ADMIN SELECTION//////
  95. $arr = $_REQUEST['box'];
  96. foreach($arr as $key => $value)
  97. {
  98. $sql = "delete from `abusive_words` where `id` = '".$value."'";
  99. $res = mysql_query($sql);
  100. }
  101. }
  102. ////IF DELETE IS FOR A SPECIFIC USER////
  103. else
  104. {
  105. $this->data['AbusiveWord']['menu'] = $_REQUEST['menu'];
  106. $this->AbusiveWord->del($id);
  107. if(isset($_REQUEST['page']))
  108. {
  109. $page = $_REQUEST['page'];
  110. }
  111. else $page = 1;
  112. }
  113. $this->flash('The post with id: '.$id.' has been deleted.', '/posts');
  114. $this->redirect('/abusive_words/manage_abuse?menu='.$_REQUEST['menu'].'&page='.$page);
  115. }
  116. }
  117. ?>