Subversion Repositories SmartDukaan

Rev

Rev 15226 | Rev 17976 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15226 Rev 15404
Line 111... Line 111...
111
			$this->Session->setFlash(__('The callhistory could not be deleted. Please, try again.'));
111
			$this->Session->setFlash(__('The callhistory could not be deleted. Please, try again.'));
112
		}
112
		}
113
		return $this->redirect(array('action' => 'index'));
113
		return $this->redirect(array('action' => 'index'));
114
	}
114
	}
115
	public function admin_search(){
115
	public function admin_search(){
-
 
116
		$type=$this->request->query('type');
116
		$date_from = $this->request->query('date_from');
117
		$date_from = $this->request->query('date_from');
117
		$date_to = $this->request->query('date_to');
118
		$date_to = $this->request->query('date_to');
-
 
119
		$searchTerm = $this->request->query('search');
-
 
120
		if(empty($searchTerm)){
-
 
121
			if(!empty($date_from) && !empty($date_to)){
-
 
122
				if(strtotime($date_from) > strtotime($date_to)){
-
 
123
					$userActions = array();
-
 
124
					$resul=$userActions;
-
 
125
					echo "Wrong date selected";
-
 
126
				}else{
-
 
127
					$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where date(call_time) between '$date_from' and '$date_to' order by id desc";
-
 
128
					$resul=$this->Callhistory->query($sqlQuery);	
-
 
129
				}
-
 
130
			}else{
-
 
131
				$userActions = array();
-
 
132
				$resul=$userActions;
-
 
133
			}
-
 
134
 
-
 
135
		}else if($type=='agent_name'){
-
 
136
			if(!empty($date_from) && !empty($date_to)){
-
 
137
				if(strtotime($date_from) > strtotime($date_to)){
-
 
138
					$userActions = array();
-
 
139
					$resul=$userActions;
-
 
140
					echo "Wrong date selected";
-
 
141
				}else{
-
 
142
					$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where date(call_time) between '$date_from' and '$date_to' and a.name like lower('%$searchTerm%')order by id desc";
-
 
143
					$resul=$this->Callhistory->query($sqlQuery);	
-
 
144
				}
-
 
145
			}else{
-
 
146
				$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where a.name like lower('%$searchTerm%')order by id desc";
-
 
147
				$resul=$this->Callhistory->query($sqlQuery);	
-
 
148
			}			
-
 
149
		}else if($type=='agent_id'){
-
 
150
			if(!empty($date_from) && !empty($date_to)){
-
 
151
				if(strtotime($date_from) > strtotime($date_to)){
-
 
152
					$userActions = array();
-
 
153
					$resul=$userActions;
-
 
154
					echo "Wrong date selected";
-
 
155
				}else{
-
 
156
					$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where date(call_time) between '$date_from' and '$date_to' and c.agent_id = '$searchTerm' order by id desc";
-
 
157
					$resul=$this->Callhistory->query($sqlQuery);	
-
 
158
				}
-
 
159
			}else{
-
 
160
				$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where c.agent_id ='$searchTerm' order by id desc";
-
 
161
				$resul=$this->Callhistory->query($sqlQuery);	
-
 
162
			}			
-
 
163
		}else if($type=='agent_role'){
-
 
164
			if(!empty($date_from) && !empty($date_to)){
-
 
165
				if(strtotime($date_from) > strtotime($date_to)){
-
 
166
					$userActions = array();
-
 
167
					$resul=$userActions;
-
 
168
					echo "Wrong date selected";
-
 
169
				}else{
-
 
170
					$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where date(call_time) between '$date_from' and '$date_to' and c.call_type = '$searchTerm' order by id desc";
-
 
171
					$resul=$this->Callhistory->query($sqlQuery);	
-
 
172
				}
-
 
173
			}else{
-
 
174
				$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where c.call_type = '$searchTerm' order by id desc";
-
 
175
				$resul=$this->Callhistory->query($sqlQuery);	
-
 
176
			}		
-
 
177
		}	
118
		$this->Callhistory->recursive = 0;
178
		$this->Callhistory->recursive = 0;
119
		if(!empty($date_from) && !empty($date_to)){
-
 
120
			$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where date(call_time) between '$date_from' and '$date_to' order by id desc";
179
		
121
			$resul=$this->Callhistory->query($sqlQuery);	
-
 
122
		}
-
 
123
		$this->set('result', $resul);
180
		$this->set('result', $resul);
124
	}
181
	}
125
}
182
}