PageRenderTime 320ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/images/includes/images.inc.php

https://bitbucket.org/websightdesigns/project-manager
PHP | 352 lines | 328 code | 8 blank | 16 comment | 59 complexity | 962e7a7a6e9db7d57b2cd8f280864af8 MD5 | raw file
  1. <div class="navbar">
  2. <div class="navbar-inner">
  3. <div class="container">
  4. <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-images-collapse">
  5. <span class="icon-bar"></span>
  6. <span class="icon-bar"></span>
  7. <span class="icon-bar"></span>
  8. </a>
  9. <a class="brand" href="<?php echo $basehref; ?>images/">Images</a>
  10. <div class="nav-collapse nav-images-collapse collapse">
  11. <ul class="nav nav-pills">
  12. <li class="active"><a href="#current" data-toggle="tab">Current</a></li>
  13. <li><a href="#archived" data-toggle="tab">Archived</a></li>
  14. </ul>
  15. <div class="pull-right">
  16. <form class="navbar-search">
  17. <input type="text" id="searchbox" class="search-query" placeholder="Search Images" data-provide="typeahead">
  18. </form>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="row">
  25. <div class="span6 pull-left">
  26. </div>
  27. <div class="span6 pull-right">
  28. <button href="#addImage" role="button" class="btn btn-success pull-right" type="button" data-toggle="modal"><i class="icon-plus icon-white"></i> Add A New Image</button>
  29. </div>
  30. </div>
  31. <br clear="all" /><br clear="all" />
  32. <?php
  33. if($_POST['doAddImage'] && $link) {
  34. // file upload
  35. $allowedExts = array("jpg", "jpeg", "gif", "png");
  36. $extension = end(explode(".", $_FILES["upload_file"]["name"]));
  37. if (
  38. (
  39. ($_FILES["upload_file"]["type"] == "image/gif")
  40. || ($_FILES["upload_file"]["type"] == "image/jpeg")
  41. || ($_FILES["upload_file"]["type"] == "image/png")
  42. || ($_FILES["upload_file"]["type"] == "image/pjpeg")
  43. )
  44. && ($_FILES["upload_file"]["size"] < 500000)
  45. && in_array($extension, $allowedExts)
  46. ) {
  47. if ($_FILES["upload_file"]["error"] > 0) {
  48. echo "Return Code: " . $_FILES["upload_file"]["error"] . "<br />";
  49. } else {
  50. if($debugmode) {
  51. echo "Upload: " . $_FILES["upload_file"]["name"] . "<br />";
  52. echo "Type: " . $_FILES["upload_file"]["type"] . "<br />";
  53. echo "Size: " . ($_FILES["upload_file"]["size"] / 1024) . " Kb<br />";
  54. echo "Temp file: " . $_FILES["upload_file"]["tmp_name"] . "<br />";
  55. }
  56. $uploadpath = $web_root . "/modules/screenshots/uploads/";
  57. $file_sig = md5_file($_FILES["upload_file"]["tmp_name"]);
  58. $newfile = $file_sig . "." . $extension;
  59. $newfilepath = $uploadpath . $newfile;
  60. $i = 1;
  61. while(file_exists($newfilepath)){
  62. $i++;
  63. $newfile = $file_sig . "_" . $i . "." . $extension;
  64. $newfilepath = $uploadpath . $newfile;
  65. }
  66. move_uploaded_file($_FILES["upload_file"]["tmp_name"], $newfilepath);
  67. $screenshot_orig = $_FILES['upload_file']['name'];
  68. $screenshot_file = $newfile;
  69. }
  70. } else {
  71. if($debugmode) {
  72. ob_start();
  73. echo "<pre>";
  74. var_dump($_FILES);
  75. echo "</pre>";
  76. $dump = ob_get_clean();
  77. echo $dump;
  78. echo "File Name: " . $_FILES["file"]["name"];
  79. }
  80. echo "Invalid file";
  81. }
  82. // resize image if needed
  83. function resizeImage( $image, $thumbWidth ) {
  84. // parse path for the extension
  85. $info = pathinfo($image);
  86. // continue only if this is a JPEG image
  87. if ( strtolower($info['extension']) == 'jpg' ) {
  88. // load image and get image size
  89. $img = imagecreatefromjpeg( "{$image}" );
  90. $width = imagesx( $img );
  91. $height = imagesy( $img );
  92. // calculate thumbnail size
  93. $new_width = $thumbWidth;
  94. $new_height = floor( $height * ( $thumbWidth / $width ) );
  95. // create a new temporary image
  96. $tmp_img = imagecreatetruecolor( $new_width, $new_height );
  97. // copy and resize old image into new image
  98. imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
  99. // create variable for file path
  100. $imagepath = end(explode("/", $image));
  101. // save resized image into a file
  102. imagejpeg( $tmp_img, "{$imagepath}" );
  103. }
  104. // close the directory
  105. closedir( $dir );
  106. }
  107. list($width, $height, $type, $attr) = getimagesize($newfilepath);
  108. if($width && $width > 1300) {
  109. resizeImage($newfilepath, "1300");
  110. }
  111. // add the screenshot
  112. if($_POST['clientid'] != "X") $clientid = $_POST['clientid'];
  113. if($_POST['projectid'] != "0") $projectid = $_POST['projectid'];
  114. $sql = "INSERT INTO screenshots (
  115. `screenshot_name`,
  116. `screenshot_describe`,
  117. `screenshot_file`,
  118. `screenshot_orig`,
  119. `screenshot_filesize`,
  120. `created`,
  121. `modified`,
  122. `clientid`,
  123. `projectid`,
  124. `userid`
  125. ) VALUES (
  126. '" . $_POST['screenshot_name'] . "',
  127. '" . $_POST['screenshot_describe'] . "',
  128. '" . $screenshot_file . "',
  129. '" . $screenshot_orig . "',
  130. '" . $_FILES['upload_file']['size'] . "',
  131. NOW(),
  132. NOW(),
  133. '" . $clientid . "',
  134. '" . $projectid . "',
  135. '" . $_SESSION['userid_auth'] . "'
  136. )";
  137. $q = mysql_query($sql);
  138. $notice = "Your new image was created.";
  139. }
  140. if(getSetting("dateFormat", $_SESSION['userid_auth']) && getSetting("dateFormat", $_SESSION['userid_auth']) != "0") {
  141. $date_format_setting = getSetting("dateFormat", $_SESSION['userid_auth']);
  142. }
  143. if (isset($_POST['search'])) { // a search was performed
  144. $level_auth = getCurrentUserAccessLevel();
  145. $group_auth = getCurrentUserGroupID();
  146. $search_client = "Client: ";
  147. // CLIENT SECTION
  148. if(substr($_POST['search'], 0, strlen($search_client)) == $search_client) {
  149. $screenshot_sql = "SELECT id
  150. FROM clients
  151. WHERE fullname LIKE '%" . str_replace($search_client, "", $_POST['search']) . "%'";
  152. $screenshot_q = mysql_query($screenshot_sql);
  153. while($i = mysql_fetch_object($screenshot_q)) {
  154. $screenshot_id = $i->id;
  155. }
  156. $sql = "SELECT screenshots.`id` AS `id`,
  157. screenshots.`screenshot_name` AS `screenshot_name`,
  158. screenshots.`screenshot_hourly` AS `screenshot_hourly`,
  159. screenshots.`screenshot_rate` AS `screenshot_rate`,
  160. DATE_FORMAT(screenshots.`created`, '" . $date_format_setting . ", %l:%i %p') AS `fcreated`,
  161. DATE_FORMAT(screenshots.`modified`, '" . $date_format_setting . ", %l:%i %p') AS `fmodified`,
  162. screenshots.`created` AS `created`,
  163. screenshots.`modified` AS `modified`,
  164. screenshots.`clientid` AS `clientid`
  165. FROM screenshots, users
  166. WHERE users.userid='" . $_SESSION['userid_auth'] . "'
  167. AND screenshots.screenshot_name LIKE '%" . $_POST['search'] . "%'";
  168. if($level_auth < "11" || getSetting('onlyShowImagesInMyGroup', $_SESSION['userid_auth']) == "0")
  169. $sql .= " AND users.id=screenshots.ownerid AND users.groupid = '" . $group_auth . "'";
  170. $sql .= " ORDER BY screenshots.`sort` ASC, screenshots.`modified` DESC, screenshots.`created` DESC";
  171. $search_text = "Images for the client <u>".str_replace($search_client, "", $_POST['search'])."</u>";
  172. // PROJECT SECTION
  173. } elseif(substr($_POST['search'], 0, strlen($search_client)) == $search_client) {
  174. $screenshot_sql = "SELECT id
  175. FROM clients
  176. WHERE fullname LIKE '%" . str_replace($search_client, "", $_POST['search']) . "%'";
  177. $screenshot_q = mysql_query($screenshot_sql);
  178. while($i = mysql_fetch_object($screenshot_q)) {
  179. $screenshot_id = $i->id;
  180. }
  181. $sql = "SELECT screenshots.`id` AS `id`,
  182. screenshots.`screenshot_name` AS `screenshot_name`,
  183. screenshots.`screenshot_file` AS `screenshot_file`,
  184. DATE_FORMAT(screenshots.`created`, '" . $date_format_setting . ", %l:%i %p') AS `fcreated`,
  185. DATE_FORMAT(screenshots.`modified`, '" . $date_format_setting . ", %l:%i %p') AS `fmodified`,
  186. screenshots.`created` AS `created`,
  187. screenshots.`modified` AS `modified`,
  188. screenshots.`clientid` AS `clientid`
  189. FROM screenshots, users
  190. WHERE users.userid='" . $_SESSION['userid_auth'] . "'
  191. AND screenshots.screenshot_name LIKE '%" . $_POST['search'] . "%'";
  192. if($level_auth < "11" || getSetting('onlyShowImagesInMyGroup', $_SESSION['userid_auth']) == "0")
  193. $sql .= " AND users.id=screenshots.ownerid AND users.groupid = '" . $group_auth . "'";
  194. $sql .= " ORDER BY screenshots.`sort` ASC, screenshots.`modified` DESC, screenshots.`created` DESC";
  195. $search_text = "Images for the client <u>".str_replace($search_client, "", $_POST['search'])."</u>";
  196. // SEARCH SECTION
  197. } else {
  198. $sql = "SELECT screenshots.`id` AS `id`,
  199. screenshots.`screenshot_name` AS `screenshot_name`,
  200. screenshots.`screenshot_hourly` AS `screenshot_hourly`,
  201. screenshots.`screenshot_rate` AS `screenshot_rate`,
  202. DATE_FORMAT(screenshots.`created`, '" . $date_format_setting . ", %l:%i %p') AS `fcreated`,
  203. DATE_FORMAT(screenshots.`modified`, '" . $date_format_setting . ", %l:%i %p') AS `fmodified`,
  204. screenshots.`created` AS `created`,
  205. screenshots.`modified` AS `modified`,
  206. screenshots.`clientid` AS `clientid`
  207. FROM screenshots
  208. WHERE userid='" . $_SESSION['userid_auth'] . "'
  209. AND milestoneid='0'
  210. AND completed='" . $completed . "'
  211. AND screenshotid='" . $screenshot_id . "'";
  212. $sql .= " ORDER BY screenshots.`sort` ASC, screenshots.`modified` DESC, screenshots.`created` DESC";
  213. $search_text = "Search results for the search term <u>".$_POST['search']."</u>";
  214. }
  215. } else { // a search was not performed
  216. $sql = "SELECT screenshots.`id` AS `id`,
  217. screenshots.`screenshot_name` AS `screenshot_name`,
  218. screenshots.`screenshot_file` AS `screenshot_file`,
  219. DATE_FORMAT(screenshots.`created`, '" . $date_format_setting . ", %l:%i %p') AS `fcreated`,
  220. DATE_FORMAT(screenshots.`modified`, '" . $date_format_setting . ", %l:%i %p') AS `fmodified`,
  221. screenshots.`created` AS `created`,
  222. screenshots.`modified` AS `modified`,
  223. screenshots.`clientid` AS `clientid`,
  224. screenshots.`projectid` AS `projectid`
  225. FROM screenshots
  226. ORDER BY screenshots.`modified` DESC, screenshots.`created` DESC";
  227. }
  228. //if($debugmode) echo "<pre>".$sql."</pre>";
  229. $q = mysql_query($sql);
  230. $total_numrows = mysql_num_rows($q);
  231. if($_POST['search']) echo "<p><strong>" . $search_text . "</strong></p>";
  232. if($notice) {
  233. ?>
  234. <div class="icon-container fadeout">
  235. <img src="<?php echo $basehref; ?>img/icons/button-info.png" class="icon-image" alt="" />
  236. </div>
  237. <div class="icon-text fadeout"><?php echo $notice; ?></div>
  238. <br clear="all" /><br clear="all" />
  239. <?php
  240. }
  241. if($_POST['search'] || $total_numrows) {
  242. ?>
  243. <div class="tab-content">
  244. <div class="tab-pane active" id="current">
  245. <table id="images" class="table table-striped table-bordered table-condensed table-hover table-pager" border="0" cellspacing="0" cellpadding="4" summary="">
  246. <thead>
  247. <tr>
  248. <th class="icon"></th>
  249. <th class="item">Image</th>
  250. <th>Client</th>
  251. <th>Project</th>
  252. <th>Updated</th>
  253. <th></th>
  254. </tr>
  255. </thead>
  256. <tbody><?php
  257. $j = 0;
  258. while($i = mysql_fetch_object($q)) {
  259. $id = $i->id;
  260. $screenshot_name = $i->screenshot_name;
  261. $screenshot_file = $i->screenshot_file;
  262. $screenshot_file = $i->screenshot_file;
  263. $completed = $i->completed;
  264. $created = $i->created;
  265. $modified = $i->modified;
  266. $fcreated = $i->fcreated;
  267. $fmodified = $i->fmodified;
  268. $clientid = $i->clientid;
  269. if($j % 2 == 0) $rowcolor = "row"; else $rowcolor = "altrow";
  270. ?>
  271. <tr id="item_<?php echo $id; ?>">
  272. <td class="icon"><button class="btn pull-left" type="button" id="<?php echo $id; ?>"><i class="icon-camera"></i></button></td>
  273. <td class="item"><a href="<?php echo $basehref; ?>modules/images/ajax/get_screenshot.php?id=<? echo $id; ?>" class="screenshot" rel="screenshot"><? echo $screenshot_name; ?></a></td>
  274. <td><?php if($clientid) echo getClientName($clientid); else echo 'Internal'; ?></td>
  275. <td><?php if($projectid) echo getProjectName($projectid); ?></td>
  276. <td><?php if($modified != "0000-00-00 00:00:00" && $modified != "") echo $fmodified; else echo '-'; ?></td>
  277. <td><button class="btn btn-danger pull-right delete" type="button" id="<?php echo $id; ?>"><i class="icon-trash icon-white"></i></button></td>
  278. </tr>
  279. <?php
  280. $j++;
  281. }
  282. ?></tbody><?php
  283. if($total_numrows > "10") pagination();
  284. ?></table>
  285. </div>
  286. <div class="tab-pane" id="archived">
  287. <h3>Archived</h3>
  288. </div>
  289. </div>
  290. <?php
  291. }
  292. mysql_close($link);
  293. ?>
  294. <!-- Modal -->
  295. <?php require_once('includes/functions.php'); ?>
  296. <div id="addImage" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addImageLabel" aria-hidden="true">
  297. <div class="modal-header">
  298. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">?&#x2014;</button>
  299. <h3 id="addImageLabel">Add A New Image</h3>
  300. </div>
  301. <div class="modal-body">
  302. <form method="post" action="<? echo $basehref; ?>tasks/" class="form-horizontal">
  303. <div class="control-group">
  304. <label class="control-label" for="task_title">Image Title</label>
  305. <div class="controls">
  306. <input type="text" id="task_title" placeholder="Image Title">
  307. </div>
  308. </div>
  309. <div class="control-group">
  310. <label class="control-label" for="task_describe">Description</label>
  311. <div class="controls">
  312. <textarea id="task_describe" name="task_describe" class="blurred" cols="52" rows="4" placeholder="Description"></textarea>
  313. </div>
  314. </div>
  315. <div class="control-group">
  316. <label class="control-label" for="startdate">Start</label>
  317. <div class="controls">
  318. <input type="text" name="fstartdate" id="startdate" placeholder="Start">
  319. </div>
  320. </div>
  321. <div class="control-group">
  322. <label class="control-label" for="duedate">Due</label>
  323. <div class="controls">
  324. <input type="text" name="fduedate" id="duedate" placeholder="Due">
  325. </div>
  326. </div>
  327. <div class="control-group">
  328. <label class="control-label" for="duedate">Priority</label>
  329. <div class="controls">
  330. <select id="prioritydropdown" name="priority">
  331. <option value="1">High</option>
  332. <option value="2" selected="selected">Normal</option>
  333. <option value="3">Low</option>
  334. </select>
  335. </div>
  336. </div>
  337. </form>
  338. </div>
  339. <div class="modal-footer">
  340. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  341. <button class="btn btn-primary">Add Image</button>
  342. <input type="hidden" name="doAddImage" value="1" />
  343. </div>
  344. </div>