Subversion Repositories cheapmusic

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 - 1
<?php
2
 
3
/***************************************************************************
4
 *   Copyright (C) 2009-2011 by Geo Varghese(www.seopanel.in)  	           *
5
 *   sendtogeo@gmail.com   												   *
6
 *                                                                         *
7
 *   This program is free software; you can redistribute it and/or modify  *
8
 *   it under the terms of the GNU General Public License as published by  *
9
 *   the Free Software Foundation; either version 2 of the License, or     *
10
 *   (at your option) any later version.                                   *
11
 *                                                                         *
12
 *   This program is distributed in the hope that it will be useful,       *
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
 *   GNU General Public License for more details.                          *
16
 *                                                                         *
17
 *   You should have received a copy of the GNU General Public License     *
18
 *   along with this program; if not, write to the                         *
19
 *   Free Software Foundation, Inc.,                                       *
20
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
21
 ***************************************************************************/
22
 
23
// class defines all alert controller functions
24
class AlertController extends Controller {
25
 
26
    var $alertCategory;
27
    var $alertType;
28
    var $tableName = "alerts";
29
    var $pgScriptPath = "alerts.php";
30
 
31
    function __construct() {
32
        parent::__construct();
33
        $this->alertCategory = array(
34
            'general' => $_SESSION['text']['common']["General"],
35
            'reports' => $_SESSION['text']['common']["Reports"],
36
        );
37
 
38
        $this->alertType = array(
39
            'success',
40
            'info',
41
            'warning',
42
            'danger',
43
            'primary',
44
            'secondary',
45
            'light',
46
            'dark',
47
        );
48
    }
49
 
50
	// func to get all Alerts
51
	function __getAllAlerts($cond = '') {
52
		$sql = "select * from $this->tableName where 1=1 $cond";
53
		$langList = $this->db->select($sql);
54
		return $langList;
55
	}
56
 
57
	// func to get alert info
58
	function __getAlertInfo($value, $col='id') {
59
		$sql = "select * from $this->tableName where $col = '". addslashes($value) ."'";
60
		$langInfo = $this->db->select($sql, true);
61
		return $langInfo;
62
	}
63
 
64
	/**
65
	 * Function to display alert details
66
	 * @param Array $info	Contains all search details
67
	 */
68
	function listAlerts($info = '') {
69
	    $userId = isLoggedIn();
70
	    $fromTime = !empty($info['from_time']) ? $info['from_time'] : date('Y-m-d', strtotime('-30 days'));
71
	    $toTime = !empty($info['to_time']) ? $info['to_time'] : date('Y-m-d');
72
	    $this->set('fromTime', $fromTime);
73
	    $this->set('toTime', $toTime);
74
 
75
	    $sql = "select * from $this->tableName t where t.user_id=$userId and t.alert_time>='".addslashes("$fromTime 00:00:00")."'
76
		        and t.alert_time<='" . addslashes("$toTime 23:59:59") . "'";
77
	    $sql .= !empty($info['keyword']) ? " and (alert_subject like '%".addslashes($info['keyword'])."%' or alert_message like '%".addslashes($info['keyword'])."%')" : "";
78
	    $sql .= " order by alert_time DESC";
79
 
80
	    // pagination setup
81
	    $this->db->query($sql, true);
82
	    $this->paging->setDivClass('pagingdiv');
83
	    $this->paging->loadPaging($this->db->noRows, SP_PAGINGNO);
84
	    $pagingDiv = $this->paging->printPages($this->pgScriptPath, 'listform', 'scriptDoLoadPost', 'content', '' );
85
	    $this->set('pagingDiv', $pagingDiv);
86
	    $sql .= " limit ".$this->paging->start .",". $this->paging->per_page;
87
 
88
	    $alertList = $this->db->select($sql);
89
	    $this->set('pageNo', $info['pageno']);
90
	    $this->set('pgScriptPath', $this->pgScriptPath);
91
	    $this->set('post', $info);
92
	    $this->set('list', $alertList);
93
	    $this->set('alertCategory', $this->alertCategory);
94
	    $this->render('alerts/alert_list');
95
	}
96
 
97
	/**
98
	 * function to delete alert
99
	 */
100
	function deleteAlert($alertId) {
101
	    $sql = "delete from $this->tableName where id=".intval($alertId);
102
	    $this->db->query($sql);
103
	}
104
 
105
	function showAlertInfo($alertId) {
106
	    $alertInfo = $this->__getAlertInfo($alertId);
107
	    $this->set('listInfo', $alertInfo);
108
	    $this->set('alertCategory', $this->alertCategory);
109
	    $this->render('alerts/alert_info');
110
	}
111
 
112
	function fetchAlerts($info) {
113
	    $userId = isLoggedIn();
114
	    if(isset($info['view'])) {
115
 
116
	        if(!empty($info["view"])) {
117
	            $sql = "UPDATE $this->tableName SET visited=1 WHERE visited=0 and user_id=$userId";
118
	            $this->db->query($sql);
119
	        }
120
 
121
	        $alertList = $this->__getAllAlerts("and user_id=$userId order by visited ASC, alert_time DESC limit " . SP_PAGINGNO);
122
	        $this->set('alertList', $alertList);
123
	        $output = $this->getViewContent('alerts/alert_box');
124
 
125
	        $sql = "SELECT count(*) count FROM $this->tableName WHERE visited=0 and user_id=$userId";
126
	        $countInfo = $this->db->select($sql, true);
127
	        $data = array(
128
	            'notification' => $output,
129
	            'unseen_notification'  => $countInfo['count'],
130
	        );
131
 
132
	        echo json_encode($data);
133
	    }
134
 
135
	}
136
 
137
	function createAlert($alertInfo, $userId = false, $adminAlert = false) {
138
 
139
		if (!$userId && $adminAlert) {
140
			$userCtler = new UserController();
141
			$adminInfo = $userCtler->__getAdminInfo();
142
			$userId = $adminInfo['id'];
143
		}
144
 
145
		$dataList = array(
146
			'user_id|int' => $userId,
147
			'alert_subject' => $alertInfo['alert_subject'],
148
			'alert_message' => $alertInfo['alert_message'],
149
			'alert_url' => !empty($alertInfo['alert_url']) ? $alertInfo['alert_url'] : "",
150
			'alert_time' => date("Y-m-d H:i:s"),
151
		);
152
 
153
		if (!empty($alertInfo['alert_category'])) {
154
			$dataList['alert_category'] = $alertInfo['alert_category'];
155
		}
156
 
157
		if (!empty($alertInfo['alert_type'])) {
158
			$dataList['alert_type'] = $alertInfo['alert_type'];
159
		}
160
 
161
		// check whether alert already exists
162
		$cond = "user_id=" . intval($userId) . " and alert_subject='".addslashes($dataList['alert_subject'])."'";
163
		$cond .= " and alert_message='".addslashes($dataList['alert_message'])."'";
164
		$cond .= " and date(alert_time)='".date('Y-m-d')."'";
165
		$existInfo = $this->dbHelper->getRow($this->tableName, $cond, "id");
166
 
167
		// if alert not exists
168
		if (empty($existInfo['id'])) {
169
			$this->dbHelper->insertRow($this->tableName, $dataList);
170
		}
171
	}
172
 
173
}
174
?>