Skip to content

Commit fe90bb2

Browse files
author
Patrice Lynde
committed
change the table layout fot the admin part and add the editing
1 parent 058062f commit fe90bb2

13 files changed

+2831
-142
lines changed

src/admin.php

+77-61
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,89 @@
11
<?php
22
include 'db.php';
3-
include 'utils.php';
4-
hasAccess('');
3+
include "utils.php";
54
require_once "header.php";
5+
include "popup_infos.php";
6+
autoload();
7+
hasAccess();
68
?>
7-
<body>
8-
9+
<html>
10+
<body>
911
<?php require_once "top_bar.php" ?>
1012

1113
<div class="content">
12-
<div class="banner">
13-
<div class="logoSlovenia"><img src="images/slovenia.png" style="padding-top : 5px" /></div>
14-
<div class="logoFlag"><img src="images/banner.jpg" /></div>
15-
</div>
16-
<?php require_once "menu.php";?>
17-
<form>
18-
<table id='myTable' class="table table-striped">
19-
<thead>
20-
<tr>
21-
<td>Company Name</td>
22-
<td>Info</td>
23-
<td>Location</td>
24-
<td>Staff</td>
25-
<td>Website</td>
26-
<td>Phone</td>
27-
<td></td>
28-
</tr>
29-
</thead>
30-
<tbody>
31-
<?php
32-
$sql = 'SELECT * FROM `company`';
33-
$res = $db->query($sql);
34-
while($row = $res->fetch())
35-
{
36-
echo '<tr id="row'.$row['id'].'">';
37-
echo "<td>";
38-
echo '<input class="input-small" type="text" value="'.$row['name'].'">';
39-
echo "</td>";
40-
echo "<td>";
41-
echo '<textarea type="text">'.$row['info'].'</textarea>';
42-
echo "</td>";
43-
echo "<td>";
44-
echo '<input type="text" value="'.$row['location'].'">';
45-
echo "</td>";
46-
echo "<td>";
47-
echo '<input type="text" value="'.$row['staff'].'">';
48-
echo "</td>";
49-
echo "<td>";
50-
echo '<input type="text" value="'.$row['website'].'">';
51-
echo "</td>";
52-
echo "<td>";
53-
echo '<input type="text" value="'.$row['phone'].'">';
54-
echo "</td>";
55-
echo "<td><a class='btn' onclick='deleteUser(".$row['id'].", \"./ajax/adminGestion.php\", \"delete\");'><i class='icon-remove'></i></a></td>";
56-
echo "</tr>";
57-
}
58-
$res->closeCursor();
59-
?>
60-
</tbody>
61-
</table>
62-
<a class='btn' onclick='addRow();'><i class='icon-plus-sign'></i></a>
63-
<div class="form-actions">
64-
<button type="submit" class="btn btn-primary">Save changes</button>
65-
<a href="index.php"><button type="button" class="btn">Cancel</button></a>
14+
<div class="banner">
15+
<div class="logoSlovenia"><img src="images/slovenia.png" style="padding-top : 5px" /></div>
16+
<div class="logoFlag"><img src="images/banner.jpg" /></div>
17+
</div>
18+
<script type="text/javascript">
19+
20+
$(document).ready(function() {
21+
22+
$('#example').dataTable( {
23+
"bPaginate": false,
24+
"bStateSave": true
25+
} );
26+
27+
/* Init DataTables */
28+
var oTable = $('#example').dataTable();
29+
30+
/* Apply the jEditable handlers to the table */
31+
oTable.$('td').editable( './admin_js.php', {
32+
"callback": function( sValue, y ) {
33+
var aPos = oTable.fnGetPosition( this );
34+
oTable.fnUpdate( sValue, aPos[0], aPos[1] );
35+
window.location.reload();
36+
},
37+
"submitdata": function ( value, settings ) {
38+
return {
39+
"row_id": this.parentNode.getAttribute('id\'),
40+
"column": oTable.fnGetPosition( this )[2]
41+
};
42+
},
43+
"height": "14px",
44+
"width": "100%"
45+
} );
46+
} );
47+
48+
</script>
49+
<?php require_once "menu.php"; ?>
50+
<div>
51+
<table cellpadding="0" cellspacing="0" border="0" class="display" id='example' class="table table-striped">
52+
<thead>
53+
<tr>
54+
<td>Company Name</td>
55+
<td>Info</td>
56+
<td>Location</td>
57+
<td>Contact</td>
58+
<td>Website</td>
59+
<td>Phone</td>
60+
<td></td>
61+
</tr>
62+
</thead>
63+
<tbody>
64+
<?php
65+
$sql = 'SELECT country.country, company.* FROM `company` LEFT JOIN country ON company.location=country.id_country ORDER BY name';
66+
$res = $db->query($sql);
67+
while($row = $res->fetch())
68+
{
69+
echo '<tr id="row'.$row['id'].'">';
70+
echo "<td>".$row['name']."</td>";
71+
echo "<td>".$row['info']."</td>";
72+
echo "<td>".$row['country']."</td>";
73+
echo "<td>".$row['contact']."</td>";
74+
echo "<td>".$row['website']."</td>";
75+
echo "<td>".$row['phone']."</td>";
76+
echo "<td><a class='btn' onclick='deleteUser(".$row['id'].", \"./ajax/adminGestion.php\", \"delete\");'><i class='icon-remove'></i></a></td>";
77+
echo '</tr>';
78+
}
79+
$res->closeCursor();
80+
?>
81+
</tbody>
82+
</table>
6683
</div>
67-
</form>
68-
<?php require_once "footer.php"; /* footer */ ?>
84+
<?php require_once "footer.php"; /* footer */ ?>
6985
</div>
7086
<script src="./js/ajaxRequest.js"></script>
71-
<?php require_once "inc_script.php"; ?> <!-- load all script -->
87+
<?php require_once "inc_script.php"; ?> <!-- load all script -->
7288
</body>
7389
</html>

src/admin_js.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
include 'db.php';
3+
4+
$rawdata = $_POST;
5+
$table = 'company'
6+
$query = "show columns from $table";
7+
$result = $db->query($query);
8+
9+
$fields = array();
10+
while ($row = $result->fetch())
11+
{
12+
$feldname = $row['Field'];
13+
array_push($fields, $feldname);
14+
}
15+
16+
$id = $rawdata['row_id'];
17+
$value = $rawdata['value'];
18+
$column = $rawdata['column'];
19+
20+
$column = $column + 1;
21+
22+
$fieldname = $fields[$column];
23+
24+
$value = utf8_decode($value);
25+
26+
$query = "update $table set $fieldname = '$value' where id = '$id'";
27+
$result = $db->query($query);
28+
29+
if (!$result) { echo "Update failed"; }
30+
else { echo "UPD: $value"; }
31+
32+
$res->closeCursor();
33+
?>

src/css/style.css

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ body {
44
background-color : #FAFAFA;
55
}
66

7+
.adminBloc{
8+
width: 1000px;
9+
10+
margin : 5px auto;
11+
background-image : linear-gradient(to bottom, #FFFFFF, #F2F2F2);
12+
}
713

814
.logoTopBar{
915
margin-top : 4px;

src/footer.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
</div>
55

66
<div class="myFooter">
7-
<ul class="menuFooter">
7+
<ul class="menuFooter">
88
<li><a href="index.php">Home</a></li>
99
<li><a href="<?php echo getLinkPage("about")?>">About Us</a></li>
1010
<li><a href="<?php echo getLinkPage("login")?>">Log In</a></li>
1111
<li><a href="<?php echo getLinkPage("contact")?>">Contact Us</a></li>
1212
<li><a href="<?php echo getLinkPage("sitemap")?>">SiteMap</a></li>
1313
</ul>
14-
<div class="privacy">
15-
<br/><br/>
16-
<img src="images/flag.png" style="float: left; margin-right : 15px;margin-top :5px;"/>
17-
<p>This site is managed by the U.S. Department of State. <br/>External links to other Internet sites should not be construed as an endorsement of the views or privacy policies contained therein.<br/><br/></p>
18-
19-
</div>
14+
<div class="privacy">
15+
<br/><br/>
16+
<img src="images/flag.png" style="float: left; margin-right : 15px;margin-top :5px;"/>
17+
<p>This site is managed by the U.S. Department of State. <br/>External links to other Internet sites should not be construed as an endorsement of the views or privacy policies contained therein.<br/><br/></p>
18+
</div>
2019
</div>

src/inc_script.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
1+
<script type="text/javascript" language="javascript" src="js/jquery-1.9.1.min.js"></script>
2+
<script type="text/javascript" language="javascript" src="js/jquery-ui.js"></script>
3+
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
4+
<script type="text/javascript" language="javascript" src="js/jquery.jeditable.js"></script>
5+
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.editable.js"></script>
6+
<script type="text/javascript" language="javascript" src="js/jquery.validate.js"></script>
7+
<script src="./bootstrap-2.3.0/js/bootstrap-carousel.js"></script>
28
<script type='text/javascript' src='js/jquery.hoverIntent.minified.js'></script>
39
<script type='text/javascript' src='js/jquery.dcmegamenu.1.2.js'></script>
4-
<script src="js/jquery-ui.js"></script>
5-
<script src="./bootstrap-2.3.0/js/bootstrap-carousel.js"></script>
610
<script src="js/ui/jquery.ui.dialog.js"></script>
7-
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
811

912

1013
<script type="text/javascript">

src/js/ajaxRequest.js

-15
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,3 @@ if (answer){
1515
});
1616
}
1717
}
18-
19-
var glb = 0
20-
var glb2 = 0
21-
22-
function addRow()
23-
{
24-
$('#myTable > tbody').append("<tr><td><input name=name"+glb+" class=input-small type=text></td><td><input name=info"+glb+" type=text></td><td><input name=location"+glb+" type=text></td><td><input name=staff"+glb+" type=text></td><td><input name=website"+glb+" type=text></td><td><input name=phone"+glb+" type=text></td><td><a class='btn' onclick='$(this).parent().fadeOut(300, function(){ $(this).parent().remove(); });'><i class='icon-remove'></i></a></td></tr>");
25-
glb += 1;
26-
}
27-
28-
function adduserRow()
29-
{
30-
$('#myTable > tbody').append("<tr><td><input name=username"+glb2+" class=input-small type=text></td><td><input name=password"+glb+" type=password></td><td><input name=mail"+glb2+" type=text></td><td><a class='btn' onclick='$(this).parent().fadeOut(300, function(){ $(this).parent().remove(); });'><i class='icon-remove'></i></a></td></tr>");
31-
glb2 += 1;
32-
}

0 commit comments

Comments
 (0)