/admin/app/controllers/abusive_words_controller.php
PHP | 124 lines | 114 code | 7 blank | 3 comment | 21 complexity | d06838d6d4dacf2d2ce47c1e786975ad MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
- <?php
- class AbusiveWordsController extends AppController
- {
- var $name='AbusiveWords';
- var $components = array('Pagination');
- var $helpers = array('Pagination', 'error');
-
- function manage_abuse()
- {
- $this->checkSession();
- $this->layout = 'default_user';
- $this->set('menu', $_REQUEST['menu']);
-
- $this->set('rows', mysql_num_rows(mysql_query("select * from abusive_words")));
-
- if (empty($this->data))
- {
- if(isset($_REQUEST['id']))
- {
- $id = $_REQUEST['id'];
- $this->AbusiveWord->id = $_REQUEST['id'];
- $this->data = $this->AbusiveWord->read(null, $id);
- }
- }
- else if(!empty($this->data) && isset($_REQUEST['act']) && $_REQUEST['act'] == "edit")
- {
- $id = $_REQUEST['id'];
- if($this->data['AbusiveWord']['words'] == "")
- $this->set('msg', $msg = "Please give any word");
- else
- {
- $word_find = "select * from abusive_words where words='".addslashes($this->data['AbusiveWord']['words'])."'";
- $num_rows = mysql_num_rows(mysql_query($word_find));
- if($num_rows==0)
- {
- $up_word_qry = "update abusive_words set words ='".addslashes($this->data['AbusiveWord']['words'])."' where id ='".$id."'";
- $up_word = mysql_query($up_word_qry);
- }
- else $this->set('msg', $msg = "This word has already been inserted");
- if(isset($res))
- {
- $this->flash('Your post has been saved.','/users');
- $this->redirect('/abusive_words/manage_abuse?menu='.$_REQUEST['menu']."&page=".$_REQUEST['page']);
- }
- }
- }
- else
- {
- $word = "select * from abusive_words where words = '".addslashes($this->data['AbusiveWord']['words'])."'";
- $chk_word = mysql_query($word);
- if(mysql_num_rows($chk_word) == 0)
- {
- if($this->data['AbusiveWord']['words'] == "")
- $this->set('msg', $msg = "Please give any word");
- else
- {
- $qry = "insert into abusive_words(`id`,`words`) values('','".addslashes($this->data['AbusiveWord']['words'])."')";
- $res_word = mysql_query($qry);
- if(isset($res_word))
- {
- $this->flash('Your post has been saved.','/users');
- $this->redirect('/abusive_words/manage_abuse?menu='.$_REQUEST['menu']);
- }
- }
- }
- else
- {
- $this->set('msg', $msg = "This word has already been inserted");
- //$this->redirect('/abusive_words/manage_abuse?menu='.$_REQUEST['menu']);
- }
- }
- $order = "";
- if(!empty($_GET['search']))
- {
- $criteria="1";
- $order.= " ORDER BY `AbusiveWord`.`words` DESC";
- $this->data['AbusiveWord']['search'] = $_GET['search'];
- $search=trim($this->data['AbusiveWord']['search']);
- $criteria .= " and AbusiveWord.words LIKE '".$search."%'";
- list($order,$limit,$page) = $this->Pagination->init($criteria);
- $this->set('users', $this->AbusiveWord->findAll($criteria, NULL, $order, $limit, $page));
- }
- else
- {
- $criteria= "1";
- $order.= " ORDER BY `AbusiveWord`.`words` DESC";
- list($order,$limit,$page) = $this->Pagination->init($criteria);
- $this->set('users', $this->AbusiveWord->findAll($criteria, NULL, $order, $limit, $page));
- }
- }
- function delete($id=null)
- {
- $this->checkSession();
- $id=$_REQUEST['id'];
- if(isset($_REQUEST['box']))
- {
- /////IF SEARCH IS COLLECTIVE OR CHOSEN BY ADMIN SELECTION//////
-
- $arr = $_REQUEST['box'];
- foreach($arr as $key => $value)
- {
- $sql = "delete from `abusive_words` where `id` = '".$value."'";
- $res = mysql_query($sql);
- }
- }
- ////IF DELETE IS FOR A SPECIFIC USER////
- else
- {
- $this->data['AbusiveWord']['menu'] = $_REQUEST['menu'];
- $this->AbusiveWord->del($id);
- if(isset($_REQUEST['page']))
- {
- $page = $_REQUEST['page'];
- }
- else $page = 1;
- }
- $this->flash('The post with id: '.$id.' has been deleted.', '/posts');
- $this->redirect('/abusive_words/manage_abuse?menu='.$_REQUEST['menu'].'&page='.$page);
- }
-
- }
- ?>