Subversion Repositories cheapmusic

Rev

Rev 103 | Details | Compare with Previous | 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";
155 - 30
    var $installAlertSubject = "Seo Panel New Version is Available Now!";
103 - 31
 
32
    function __construct() {
33
        parent::__construct();
34
        $this->alertCategory = array(
35
            'general' => $_SESSION['text']['common']["General"],
155 - 36
            'reports' => $_SESSION['text']['common']["Reports"],
103 - 37
        );
38
 
39
        $this->alertType = array(
40
            'success',
41
            'info',
42
            'warning',
43
            'danger',
44
            'primary',
45
            'secondary',
46
            'light',
47
            'dark',
48
        );
49
    }
50
 
51
	// func to get all Alerts
52
	function __getAllAlerts($cond = '') {
53
		$sql = "select * from $this->tableName where 1=1 $cond";
54
		$langList = $this->db->select($sql);
55
		return $langList;
56
	}
57
 
58
	// func to get alert info
59
	function __getAlertInfo($value, $col='id') {
60
		$sql = "select * from $this->tableName where $col = '". addslashes($value) ."'";
61
		$langInfo = $this->db->select($sql, true);
62
		return $langInfo;
63
	}
64
 
65
	/**
66
	 * Function to display alert details
67
	 * @param Array $info	Contains all search details
68
	 */
69
	function listAlerts($info = '') {
70
	    $userId = isLoggedIn();
71
	    $fromTime = !empty($info['from_time']) ? $info['from_time'] : date('Y-m-d', strtotime('-30 days'));
72
	    $toTime = !empty($info['to_time']) ? $info['to_time'] : date('Y-m-d');
73
	    $this->set('fromTime', $fromTime);
74
	    $this->set('toTime', $toTime);
75
 
76
	    $sql = "select * from $this->tableName t where t.user_id=$userId and t.alert_time>='".addslashes("$fromTime 00:00:00")."'
77
		        and t.alert_time<='" . addslashes("$toTime 23:59:59") . "'";
78
	    $sql .= !empty($info['keyword']) ? " and (alert_subject like '%".addslashes($info['keyword'])."%' or alert_message like '%".addslashes($info['keyword'])."%')" : "";
79
	    $sql .= " order by alert_time DESC";
80
 
81
	    // pagination setup
82
	    $this->db->query($sql, true);
83
	    $this->paging->setDivClass('pagingdiv');
84
	    $this->paging->loadPaging($this->db->noRows, SP_PAGINGNO);
85
	    $pagingDiv = $this->paging->printPages($this->pgScriptPath, 'listform', 'scriptDoLoadPost', 'content', '' );
86
	    $this->set('pagingDiv', $pagingDiv);
87
	    $sql .= " limit ".$this->paging->start .",". $this->paging->per_page;
88
 
89
	    $alertList = $this->db->select($sql);
90
	    $this->set('pageNo', $info['pageno']);
91
	    $this->set('pgScriptPath', $this->pgScriptPath);
92
	    $this->set('post', $info);
93
	    $this->set('list', $alertList);
94
	    $this->set('alertCategory', $this->alertCategory);
95
	    $this->render('alerts/alert_list');
96
	}
97
 
98
	/**
99
	 * function to delete alert
100
	 */
101
	function deleteAlert($alertId) {
102
	    $sql = "delete from $this->tableName where id=".intval($alertId);
103
	    $this->db->query($sql);
104
	}
105
 
106
	function showAlertInfo($alertId) {
107
	    $alertInfo = $this->__getAlertInfo($alertId);
108
	    $this->set('listInfo', $alertInfo);
109
	    $this->set('alertCategory', $this->alertCategory);
110
	    $this->render('alerts/alert_info');
111
	}
112
 
113
	function fetchAlerts($info) {
114
	    $userId = isLoggedIn();
115
	    if(isset($info['view'])) {
116
 
117
	        if(!empty($info["view"])) {
118
	            $sql = "UPDATE $this->tableName SET visited=1 WHERE visited=0 and user_id=$userId";
119
	            $this->db->query($sql);
120
	        }
121
 
122
	        $alertList = $this->__getAllAlerts("and user_id=$userId order by visited ASC, alert_time DESC limit " . SP_PAGINGNO);
123
	        $this->set('alertList', $alertList);
124
	        $output = $this->getViewContent('alerts/alert_box');
125
 
126
	        $sql = "SELECT count(*) count FROM $this->tableName WHERE visited=0 and user_id=$userId";
127
	        $countInfo = $this->db->select($sql, true);
128
	        $data = array(
129
	            'notification' => $output,
130
	            'unseen_notification'  => $countInfo['count'],
131
	        );
132
 
133
	        echo json_encode($data);
134
	    }
135
 
136
	}
137
 
155 - 138
	/*
139
	 * alert_type => [success|danger]
140
	 * alert_category => [general|reports]
141
	 */
103 - 142
	function createAlert($alertInfo, $userId = false, $adminAlert = false) {
143
 
144
		if (!$userId && $adminAlert) {
145
			$userCtler = new UserController();
146
			$adminInfo = $userCtler->__getAdminInfo();
147
			$userId = $adminInfo['id'];
148
		}
149
 
150
		$dataList = array(
151
			'user_id|int' => $userId,
152
			'alert_subject' => $alertInfo['alert_subject'],
153
			'alert_message' => $alertInfo['alert_message'],
154
			'alert_url' => !empty($alertInfo['alert_url']) ? $alertInfo['alert_url'] : "",
155 - 155
			'alert_time' => date("Y-m-d H:i:s"),
103 - 156
		);
157
 
158
		if (!empty($alertInfo['alert_category'])) {
159
			$dataList['alert_category'] = $alertInfo['alert_category'];
160
		}
161
 
162
		if (!empty($alertInfo['alert_type'])) {
163
			$dataList['alert_type'] = $alertInfo['alert_type'];
164
		}
165
 
166
		// check whether alert already exists
167
		$cond = "user_id=" . intval($userId) . " and alert_subject='".addslashes($dataList['alert_subject'])."'";
168
		$cond .= " and alert_message='".addslashes($dataList['alert_message'])."'";
169
		$cond .= " and date(alert_time)='".date('Y-m-d')."'";
170
		$existInfo = $this->dbHelper->getRow($this->tableName, $cond, "id");
171
 
172
		// if alert not exists
173
		if (empty($existInfo['id'])) {
174
			$this->dbHelper->insertRow($this->tableName, $dataList);
175
		}
155 - 176
	}
177
 
178
	/**
179
	 * function to update system alerts, eg: installation uptodate etc
180
	 */
181
	function updateSystemAlerts() {
182
 
183
	    // installation version check
184
	    if (in_array(date('d'), [1, 7, 14])) {
185
 
186
	        $informationCtrler = new InformationController();
187
	        $check_info = $informationCtrler->__getTodayInformation('install_check');
188
	        if (empty($check_info)) {
189
    	        $cond = "and alert_subject='" .addslashes($this->installAlertSubject). "' and date(alert_time)='". date("Y-m-d"). "'";
190
    	        $alertList = $this->__getAllAlerts($cond);
191
 
192
    	        // check the installation version
193
    	        if (empty($alertList)) {
194
    	            $settingCtrler = new SettingsController();
195
    	            $settingCtrler->spTextSettings = $this->getLanguageTexts('settings', $_SESSION['lang_code']);
196
    	            list($oldVersion, $message) = $settingCtrler->checkVersion(true);
197
 
198
    	            // if current version is old
199
    	            if ($oldVersion) {
200
    	                $alertInfo = array(
201
    	                    'alert_subject' => $this->installAlertSubject,
202
    	                    'alert_message' => $message,
203
    	                    'alert_type' => "danger",
204
    	                );
205
    	                $this->createAlert($alertInfo, false, true);
206
    	                $informationCtrler->updateTodayInformation($message, "install_check");
207
    	                return ['status' => true, 'result' => "Installation version is old."];
208
    	            } else {
209
    	                $informationCtrler->updateTodayInformation($message, "install_check");
210
    	            	return ['status' => false, 'result' => "Installation version is uptodate."];
211
    	            }
212
    	        }
213
	        }
214
 
215
	        return ['status' => false, 'result' => "Installation version check is already done."];
216
	    } else {
217
	    	return ['status' => false, 'result' => "Skip installation version check due to date."];
218
	    }
103 - 219
	}
220
}
155 - 221
?>