-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.php
executable file
·233 lines (171 loc) · 11.4 KB
/
interface.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
$task = $_GET['task'];
###################### Functions that DO NOT require MySQL ########################
# For things like using GD to export to /dev/null we need to load these first #
# because if not, there might be whitespace before the content string. #
#_________________________________________________________________________________#
if ($task == "loadPreview") { echo loadPreview($pub_id, $page_num, $user_id, $order_id); }
###################################################################################
##################### Includes required for MySQL functions #######################
# #
# #
# #
include 'scripts/config.php';
require 'scripts/dbconnect.php';
###################################################################################
################### Functions that DO require MySQL ###############################
# #
# #
# #
if ($task == "todo") { $pub_id = getpub($user_id, $order_id); echo todo($pub_id, $user_id, $order_id); }
if ($task == "getMap") { echo getMap($pub_id, $page_num, $user_id, $order_id); }
if ($task == "completion") { echo completion($pub_id, $user_id, $order_id); }
###################################################################################
############## OTB Function Library of Functions that have a Function #############
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
function getpub($user_id, $order_id) {
$query = "SELECT pub_id FROM users WHERE user_id = '".$user_id."' AND order_id = '".$order_id."'";
$result = mysql_query($query) or die(mysql_error());
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
return $row['pub_id'];
}
}
function todo($pub_id, $user_id, $order_id) {
$query = "SELECT * FROM assets WHERE pub_id = '".$pub_id."' ORDER BY page_num, CASE WHEN asset_typ = 'Page' THEN 1 ELSE 2 END , asset_typ";
$result = mysql_query($query) or die(mysql_error());
$num = 0;
$listclass = "";
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
//First check to see if the asset id exists
$sql = mysql_query("SELECT * FROM completed WHERE user_id = '".$user_id."' AND asset_id = '".$row['id']."' AND order_id = '".$order_id."'") or die ("query 1: " . mysql_error());
$mysql_num = mysql_num_rows($sql);
if ($mysql_num >= 1) { $listclass = "have"; }
else { $listclass = "need";}
//pipe the data of the completed item back to the list.
$data = "";
while($comp = mysql_fetch_array($sql)){
if ($comp['data']) { $data = $comp['data']; } else { $data = ""; }
}
//Now check for empty pages (REDO THIS IMMEDIATELY. TOO MANY SQL CALLS. YOU SHOULD BE ABLE TO DO THIS IN ONE QUERY IF YOU WERE REALLY AS SMART AS YOU SAY YOU ARE.)
if ($row['asset_typ'] == "Page") {
$sql = mysql_query("SELECT * FROM assets WHERE page_num = '".$row['page_num']."' AND pub_id = '".$pub_id."'") or die ("query 1: " . mysql_error());
$mysql_num = mysql_num_rows($sql);
if ($mysql_num >= 2) { $emptypage = "not-empty"; }
else { $emptypage = "is-empty";}
}
//Now echo out the tree
if ($num==0 && $row['asset_typ'] == "Page") { echo "<h3 class=\"todo-page-title ".$emptypage."\"><a class=\"hand\" onClick=\"loadPreview(".$row['pub_id'].",".$row['page_num'].",'".$user_id."','".$order_id."')\">Cover ".$row['asset_typ']."</a></h3>\n<div><ul id=\"todo\" class=\"todo\">"; }
if ($num>=1 && $row['asset_typ'] == "Page") { echo "</ul></div>\n<h3 class=\"todo-page-title ".$emptypage."\"><a class=\"hand\" onClick=\"loadPreview(".$row['pub_id'].",".$row['page_num'].",'".$user_id."','".$order_id."')\">".$row['asset_typ']." ".$row['page_num']."</a></h3>\n<div><ul id=\"todo\" class=\"todo\">"; }
if ($num>=1 && $row['asset_typ'] != "Page") { if ($row['asset_num'] <= 1) { $asset_num = ""; } else { $asset_num = $row['asset_num']; }
echo "<li class=\"".$listclass."\"><a href=\"#\" title=\"Page ".$row['page_num']." - ".$row['asset_typ']." ".$row['asset_num']."\" onClick=\"panel('".$row['id']."','".$user_id."','".$order_id."','".$pub_id."','".$row['page_num']."','".$row['asset_des']."','".$row['asset_typ']."','".$row['asset_num']."','".$row['asset_img']."','".$row['asset_typ']."','".$data."')\" id=\"".$row['asset_typ'].$row['asset_num']."\">".$row['asset_typ']." ".$asset_num."</a></li>"; }
$num++;
}
}
function loadPreview($pub_id, $page_num, $user_id, $order_id) {
// add more up to four leading zeros because Brad uses an apple computer
$pub_id = sprintf("%05d",$pub_id);
$lz = "0"; if ($page_num >= 10) { $lz = ""; }
$filename = "templates/".$pub_id."/images/".$pub_id."_Page_".$lz.$page_num.".jpg";
// Not sure if we need to set the content type... if so:
/* header('Content-type: image/jpeg'); */
// Ratio calc: W/H*444 = New height
list($width, $height) = getimagesize($filename);
$new_height = 444 * $height / $width;
$new_width = 444;
// GD Really needs to resample the image to make it look good.
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Write the image to /dev/null > We could set nice -1 in GD libs later if needed.
imagejpeg($image_p, null, 100);
}
function getMap($pub_id, $page_num, $user_id, $order_id) {
// Get the height of the original image and then determine the ratio to size the image maps down.
// This is just copied from the image resizing function.
$pub_id = sprintf("%05d",$pub_id);
$query = "SELECT * FROM assets WHERE pub_id = '".$pub_id."' AND page_num = '1' AND asset_num = '0'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$document_width = $row['asset_x2'] - $row['asset_x1'];
}
/*
$pub_id = sprintf("%05d",$pub_id);
$lz = "0"; if ($page_num >= 10) { $lz = ""; }
$filename = "templates/".$pub_id."/images/".$pub_id."_Page_".$lz.$page_num.".jpg";
// Ratio calc: W/H*444 = New height
list($width, $height) = getimagesize($filename);
$ratioy = (444 * $height / $width) / $height; */
$ratio = 444 / $document_width;
$zindex = "0";
$pub_id = sprintf("%05d",$pub_id);
$query = "SELECT * FROM assets WHERE pub_id = '".$pub_id."' AND page_num = '".$page_num."' ORDER BY CASE WHEN asset_typ = 'Page' THEN 1 WHEN asset_typ = 'Body copy' THEN 5 WHEN asset_img = '1' THEN 4 ELSE 3 END , asset_typ";
$result = mysql_query($query) or die(mysql_error());
$num = 0;
$page_spread = 0;
// Start the image map
//echo "<MAP NAME=\"map\">";
while($row = mysql_fetch_array($result)){
//First check to see if the asset id exists
$sql = mysql_query("SELECT * FROM completed WHERE user_id = '".$user_id."' AND asset_id = '".$row['id']."' AND order_id = '".$order_id."'") or die ("query 1: " . mysql_error());
$mysql_num = mysql_num_rows($sql);
if ($mysql_num >= 1) { $listclass = "have"; }
else { $listclass = "need";}
//pipe the data of the completed item back to the list.
$data = "";
while($comp = mysql_fetch_array($sql)){
$data = $comp['data'];
}
//order the css z-index value so overlapping elements do not cover each other.
if ($row['asset_typ'] == "Body copy") {$zindex = 5;} else {
if ($row['asset_img'] == 1) {$zindex = 10;} else {
$zindex = 15;
}
}
//resize the coordinates in relation to the scaled image
if ($row['asset_x1'] == 0 && $row['asset_typ'] == "Page" && $num == 0) { $document_width = 0; }
$x1 = ($row['asset_x1'] - $document_width) * $ratio; $x1=(int)$x1;
$x2 = ($row['asset_x2'] - $document_width) * $ratio; $x2=(int)$x2;
$y1 = $row['asset_y1'] * $ratio; $y1=(int)$y1;
$y2 = $row['asset_y2'] * $ratio; $y2=(int)$y2;
//calculate the div dimensions and margins
$divwidth = abs($x2-$x1);
$divheight = abs($y2-$y1);
$divtop = abs($y1);
$divleft = abs($x1);
//adjust margins for div borders
$divtop = $divtop - 2;
$divleft = $divleft - 1;
//strip the number off of the first elements so they correlate with nav
$asset_num = "";
if ($row['asset_num'] == 1) { $asset_num = "";} else { $asset_num = $row['asset_num']; }
if ($row['asset_typ'] != "Page") {
echo "<a href=\"#\" class=\"tips\" title=\"".$row['asset_typ']." ".$asset_num."\" onClick=\"panel('".$row['id']."','".$user_id."','".$order_id."','".$pub_id."','".$row['page_num']."','".$row['asset_des']."','".$row['asset_typ']."','".$row['asset_num']."','".$row['asset_img']."','".$row['asset_typ']."','".$data."')\" id=\"".$row['asset_typ'].$row['asset_num']."\"><div class=\"maps\" style=\"z-index: ".$zindex."; position: absolute; border: 2px dashed #723882; width: ".$divwidth."px; height: ".$divheight."px; top: ".$divtop."px; left: ".$divleft."px;\"></div></a>\n";
// echo "<AREA class=\"thickmap tip\" title=\"".$row['asset_typ']." ".$row['asset_num']."\" SHAPE=\"rect\" COORDS=\"".$x1.",".$y1.",".$x2.",".$y2."\" title=\"Page ".$row['page_num']." - ".$row['asset_typ']." ".$row['asset_num']."\" href=\"upload.php?id=".$row['id']."&user_id=".$user_id."&order_id=".$order_id."&pub_id=".$pub_id."&page_num=".$row['page_num']."&asset_type=".$row['asset_typ']."&asset_num=".$row['asset_num']."&img=".$row['asset_img']."&type=".$row['asset_typ']."&KeepThis=true&TB_iframe=true&height=140&width=340\" id=\"".$row['asset_typ'].$row['asset_num']."\">";
}
$num++;
}
//echo "</MAP>";
}
function completion($pub_id, $user_id, $order_id) {
$sql1 = mysql_query("SELECT * FROM assets WHERE pub_id = '".$pub_id."' AND asset_typ != 'Page'") or die ("query 1: " . mysql_error());
$total = mysql_num_rows($sql1);
$sql2 = mysql_query("SELECT * FROM completed WHERE user_id = '".$user_id."' AND order_id = '".$order_id."'") or die ("query 1: " . mysql_error());
$completed = mysql_num_rows($sql2);
$percent = ($completed / $total) * 100;
$percent = (int)$percent;
return $percent;
}
?>