-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnew_conversation.php
203 lines (183 loc) · 10.2 KB
/
new_conversation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
session_start();
if(!isset($_SESSION['is_login']) || !$_SESSION['is_login'])
header("location:index.php");
include('inc/db.php');
include('inc/cls/Rs_Users.php');
include('inc/chat/load.php');
$user = new Rs_Users($_SESSION['user']['id']);
$db = new DB();
$errorMessage = "";
if(isset($_POST['members']) && isset($_POST['start_con'])){
$userFrom = $_SESSION['user']['id'];
$userTo = $_POST['members'];
$message = $_POST['message'];
if(!$userTo || empty($userTo)){
$errorMessage = "Please select a contact";
}
if(!$message || empty($message) ){
$errorMessage = "Please type a message";
}
if(empty($errorMessage)){
$conversation = new Conversation();
$cnId = $conversation->StartNew($userFrom,$userTo,$message);
if($cnId){
header("location:".'inbox.php?con='.$cnId);
}
}
}
$offset = 0;
$page = 1;
$postPerPage = 10;
$contactFound = false;
$sql = "";
$skey = "";
$search_by = "";
if(isset($_GET['page'])){
$offset = ($postPerPage * ($_GET['page'] - 1));
$page = $_GET['page'];
}
if($user->user_role == "admin"){
$sql = "SELECT * from tbl_users";
if(isset($_GET['s'])){
$skey = $_GET['s'];
$search_by = $_GET['search_by'];
$sql .= " WHERE ( f_name like '%$skey%' || l_name like '%$skey%' ) AND user_role ='$search_by'";
}
}elseif ($user->user_role == "parent"){
$sql = "SELECT * from tbl_users where ( user_role = 'tutor' || id in( SELECT std_id from tbl_parent_std where parent_id = $user->id ) ) ";
if(isset($_GET['s'])){
$skey = $_GET['s'];
$sql .= " AND ( f_name like '%$skey%' || l_name like '%$skey%' )";
}
}elseif ($user->user_role == "student"){
$sql = "SELECT * from tbl_users where ( user_role = 'tutor' || id in( SELECT parent_id from tbl_parent_std where std_id = $user->id ) ) ";
if(isset($_GET['s'])){
$skey = $_GET['s'];
$sql .= " AND ( f_name like '%$skey%' || l_name like '%$skey%' )";
}
}elseif ($user->user_role == "tutor"){
}
$sql .= ' '."LIMIT $postPerPage OFFSET $offset";
$contactsResult = $db->con->query($sql);
?>
<!DOCTYPE html>
<html lang="en" data-textdirection="LTR" class="loading">
<head>
<?php
include_once 'master_page/head.php';
?>
<link rel="stylesheet" type="text/css" href="style/chat.css">
</head> <body data-open="click" data-menu="vertical-menu" data-col="2-columns" class="vertical-layout vertical-menu 2-columns ">
<?php
include_once 'master_page/header.php';
include_once 'master_page/admin_menu.php';
$tempChatInformation = [
'id' => '10',
'conversionId' => '20',
];
?>
<div class="robust-content content container-fluid">
<div class="content-wrapper">
<?php
if(!empty($errorMessage)){
?>
<div class="alert alert-danger">
<strong>Error: </strong> <?php echo $errorMessage; ?>
</div>
<?php
}
?>
<div class="rs_chat_box nw_conversion_chat" data-message_option = '<?php echo json_encode( $tempChatInformation ); ?>'>
<div class="row">
<div class="col-xs-12 col-md-12">
<div class="rs_chat_users">
<div class="row search_box">
<form action="" method="get">
<?php if($user->user_role == "admin"): ?>
<div class="col-xs-3 form-group ">
<select class="form-control" name="search_by">
<?php
$serchByOptoins = array(
'tutor' => "Tutors",
'student' => "Students",
'parent' => "Parent",
'admin' => "Admin"
);
foreach ($serchByOptoins as $key => $value) {
?>
<option <?php echo ($key == $search_by ? "selected": ''); ?> value="<?php echo $key; ?>"><?php echo $value; ?></option>
<?php
}
?>
</select>
</div>
<?php endif; ?>
<div class="col-xs-3">
<input type="text" name="s" value="<?php echo $skey; ?>" class="form-control">
</div>
<div class="col-xs-6">
<button class="btn rs_btn">Search</button>
<a class="btn btn-default rs_btn btn-lg" href="new_conversation.php">Reset</a>
<a class="btn btn-default rs_btn btn-lg pull-right" href="inbox.php">Inbox</a>
</div>
</form>
</div>
<form action="" method="post">
<div class="row">
<div class="col-xs-12 col-sm-5">
<ul id="rs_startConversionList">
<?php
if($contactsResult->num_rows > 0):
$contactFound = true;
while ($contact = $contactsResult->fetch_assoc()) {
?>
<li>
<label style="display: block;">
<input style="display: none;" type="radio" name="members" value="<?php echo $contact['id']; ?>">
<div class="single_user">
<img src="<?php echo (!empty($contact['picture'])? $contact['picture']:'images/blank_user.png'); ?>" style="width:40px;" alt="">
<div>
<h3 class="name"><?php echo $contact['f_name'].' '.$contact['l_name']; ?></h3>
<span class="last_message" style="text-transform: capitalize;"><?php echo $contact['user_role']; ?></span>
</div>
</div>
</label>
</li>
<?php
}
endif;
?>
</ul>
<div class="new_conv_pagination">
<div class="btn-group">
<?php if($page>=2): ?>
<a href="?page=<?php echo $page-1; ?>" class="btn btn-info">< Previus</a>
<?php endif; ?>
<?php if($contactFound): ?>
<a href="?page=<?php echo $page+1; ?>" class="btn btn-info" style="margin-left:5px;">Next ></a>
<?php endif; ?>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-7">
<div class="rs_message_editor">
<textarea type="text" name="message" class="form-control rs_editor_fw"></textarea>
<button class="btn btn-default" name="start_con">Send</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include_once 'master_page/footer.php';
include_once 'master_page/script.php';
?>
<script type="text/javascript" src="js/chat.js"></script>
</body>
</html>