-
Notifications
You must be signed in to change notification settings - Fork 2
/
add_contact_group.php
147 lines (146 loc) · 4.86 KB
/
add_contact_group.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
<?php
/**
* File add_contact_group.php
*
* PHP version 5.3+
* A view of add contact group page.
*
* @author Dzung Nguyen <[email protected]>
* @copyright 2014-2015 evolpas
* @license http://www.evolpas.com license
* @version XXX
* @link http://www.evolpas.com
* @category root
*/
require_once 'autoloader.php';
// new contact controller
$contactCtrl = new Controllers\ContactController();
$classError = ''; // this is get class of span display message error or not
if (!empty($_POST)) {
$contactCtrl->data = $_POST;
$edit = $contactCtrl->updateGroupContactAction($contactCtrl->data['id']);
if ($edit !== false) {
header('Location: add_contact_group.php?id_contact=' . $contactCtrl->data['id'].'&status=1');
//$error_log = 'Update group of contact successful!';
} else {
$message_log = 'Error: Cannot update data!';
}
} else {
@$id = $_GET['id_contact'];
if(isset($_GET['status'])){
$message_log = 'The contact was added to group successfully';
}
// get contact info based on id contact passed via url
$contact = $contactCtrl->findById($id);
if ($contact === false) {
header('Location: groups.php');
}
// new group controller
$groupCtrl = new Controllers\GroupController();
// get all groups
$groups = $groupCtrl->getAllGroups();
// get connections of group
$groupInherits = $groupCtrl->getGroupInherits();
// get groups list of contact
$groupsInherited = $groupCtrl->listGroupsOfContact($contact['id']);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Address book::List groups</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>
<!-- container -->
<div id="container">
<!-- main -->
<div id="main">
<div class="center">
<h2 class="title">Add contact <?php echo $contact['name'] ?> to groups</h2>
<div class="nav-menu">
<a href="index.php">Contacts list</a> | <a href="groups.php">Groups list</a> | <a href="create_group.php">Create group</a>
</div>
<div id="content_data">
<div id="form">
<?php if (isset($message_log)) { ?>
<span class='<?php echo $classError ?>'><?php echo $message_log; ?></span>
<?php } ?>
<form id='fmAddContactToGroups' method='POST' action='add_contact_group.php' >
<input type='hidden' name='id' value='<?php echo isset($id) ? $id : '' ?>' />
<table id="table">
<thead>
<tr>
<th class="first">#</th>
<th class="first"></th>
<th>Group name</th>
<th>Inherit contacts from</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($groups)):
$i = 0;
foreach ($groups as $group):
$classRow = ($i % 2 == 0 ? 'even' : 'odd');
$i++;
foreach ($groupsInherited as $gh):
$checked = '';
if ($gh['id'] == $group['id']) {
$checked = 'checked';
break;
}
endforeach;
?>
<tr class="<?php echo $classRow ?>">
<td><?php echo $i ?></td>
<td><input type="checkbox" <?php echo isset($checked) ? $checked : '' ?> class="check-group" id="group_<?php echo $group['id'] ?>" value="<?php echo $group['id'] ?>" name="id_group[]"></td>
<td><?php echo $group['group_name'] ?></td>
<td>
<?php
$j = 0;
foreach ($groupInherits as $groupInherit):
if ($groupInherit['id'] == $group['id']) {
if ($j != 0) {
echo '<br/>';
}
echo $parentName = '- ' . $groupInherit['parent_name'];
$j++;
continue;
}
endforeach;
if ($j == 0) {
echo 'none';
}
?>
</td>
</tr>
<?php
endforeach;
else:
?>
<tr class="even">
<td colspan="6"><?php echo 'The list is empty!' ?></td>
</tr>
<?php
endif;
?>
</tbody>
</table>
<div style='text-align: center; padding: 5px'>
<input type='submit' style='width: auto' class='submit' name='btSubmit' value ='Add to Groups' />
<input type='button' style='width: auto' class='submit' name='btBack' value ='Back' onclick='document.location.href="index.php";' />
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- script -->
<script src="assets/js/main.js"></script>
</body>
</html>