/modules/images/includes/images.inc.php
PHP | 352 lines | 328 code | 8 blank | 16 comment | 59 complexity | 962e7a7a6e9db7d57b2cd8f280864af8 MD5 | raw file
- <div class="navbar">
- <div class="navbar-inner">
- <div class="container">
- <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-images-collapse">
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </a>
- <a class="brand" href="<?php echo $basehref; ?>images/">Images</a>
- <div class="nav-collapse nav-images-collapse collapse">
- <ul class="nav nav-pills">
- <li class="active"><a href="#current" data-toggle="tab">Current</a></li>
- <li><a href="#archived" data-toggle="tab">Archived</a></li>
- </ul>
- <div class="pull-right">
- <form class="navbar-search">
- <input type="text" id="searchbox" class="search-query" placeholder="Search Images" data-provide="typeahead">
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="span6 pull-left">
- </div>
- <div class="span6 pull-right">
- <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>
- </div>
- </div>
- <br clear="all" /><br clear="all" />
- <?php
- if($_POST['doAddImage'] && $link) {
- // file upload
- $allowedExts = array("jpg", "jpeg", "gif", "png");
- $extension = end(explode(".", $_FILES["upload_file"]["name"]));
- if (
- (
- ($_FILES["upload_file"]["type"] == "image/gif")
- || ($_FILES["upload_file"]["type"] == "image/jpeg")
- || ($_FILES["upload_file"]["type"] == "image/png")
- || ($_FILES["upload_file"]["type"] == "image/pjpeg")
- )
- && ($_FILES["upload_file"]["size"] < 500000)
- && in_array($extension, $allowedExts)
- ) {
- if ($_FILES["upload_file"]["error"] > 0) {
- echo "Return Code: " . $_FILES["upload_file"]["error"] . "<br />";
- } else {
- if($debugmode) {
- echo "Upload: " . $_FILES["upload_file"]["name"] . "<br />";
- echo "Type: " . $_FILES["upload_file"]["type"] . "<br />";
- echo "Size: " . ($_FILES["upload_file"]["size"] / 1024) . " Kb<br />";
- echo "Temp file: " . $_FILES["upload_file"]["tmp_name"] . "<br />";
- }
- $uploadpath = $web_root . "/modules/screenshots/uploads/";
- $file_sig = md5_file($_FILES["upload_file"]["tmp_name"]);
- $newfile = $file_sig . "." . $extension;
- $newfilepath = $uploadpath . $newfile;
- $i = 1;
- while(file_exists($newfilepath)){
- $i++;
- $newfile = $file_sig . "_" . $i . "." . $extension;
- $newfilepath = $uploadpath . $newfile;
- }
- move_uploaded_file($_FILES["upload_file"]["tmp_name"], $newfilepath);
- $screenshot_orig = $_FILES['upload_file']['name'];
- $screenshot_file = $newfile;
- }
- } else {
- if($debugmode) {
- ob_start();
- echo "<pre>";
- var_dump($_FILES);
- echo "</pre>";
- $dump = ob_get_clean();
- echo $dump;
- echo "File Name: " . $_FILES["file"]["name"];
- }
- echo "Invalid file";
- }
- // resize image if needed
- function resizeImage( $image, $thumbWidth ) {
- // parse path for the extension
- $info = pathinfo($image);
- // continue only if this is a JPEG image
- if ( strtolower($info['extension']) == 'jpg' ) {
- // load image and get image size
- $img = imagecreatefromjpeg( "{$image}" );
- $width = imagesx( $img );
- $height = imagesy( $img );
- // calculate thumbnail size
- $new_width = $thumbWidth;
- $new_height = floor( $height * ( $thumbWidth / $width ) );
- // create a new temporary image
- $tmp_img = imagecreatetruecolor( $new_width, $new_height );
- // copy and resize old image into new image
- imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
- // create variable for file path
- $imagepath = end(explode("/", $image));
- // save resized image into a file
- imagejpeg( $tmp_img, "{$imagepath}" );
- }
- // close the directory
- closedir( $dir );
- }
- list($width, $height, $type, $attr) = getimagesize($newfilepath);
- if($width && $width > 1300) {
- resizeImage($newfilepath, "1300");
- }
- // add the screenshot
- if($_POST['clientid'] != "X") $clientid = $_POST['clientid'];
- if($_POST['projectid'] != "0") $projectid = $_POST['projectid'];
- $sql = "INSERT INTO screenshots (
- `screenshot_name`,
- `screenshot_describe`,
- `screenshot_file`,
- `screenshot_orig`,
- `screenshot_filesize`,
- `created`,
- `modified`,
- `clientid`,
- `projectid`,
- `userid`
- ) VALUES (
- '" . $_POST['screenshot_name'] . "',
- '" . $_POST['screenshot_describe'] . "',
- '" . $screenshot_file . "',
- '" . $screenshot_orig . "',
- '" . $_FILES['upload_file']['size'] . "',
- NOW(),
- NOW(),
- '" . $clientid . "',
- '" . $projectid . "',
- '" . $_SESSION['userid_auth'] . "'
- )";
- $q = mysql_query($sql);
- $notice = "Your new image was created.";
- }
- if(getSetting("dateFormat", $_SESSION['userid_auth']) && getSetting("dateFormat", $_SESSION['userid_auth']) != "0") {
- $date_format_setting = getSetting("dateFormat", $_SESSION['userid_auth']);
- }
- if (isset($_POST['search'])) { // a search was performed
- $level_auth = getCurrentUserAccessLevel();
- $group_auth = getCurrentUserGroupID();
- $search_client = "Client: ";
- // CLIENT SECTION
- if(substr($_POST['search'], 0, strlen($search_client)) == $search_client) {
- $screenshot_sql = "SELECT id
- FROM clients
- WHERE fullname LIKE '%" . str_replace($search_client, "", $_POST['search']) . "%'";
- $screenshot_q = mysql_query($screenshot_sql);
- while($i = mysql_fetch_object($screenshot_q)) {
- $screenshot_id = $i->id;
- }
- $sql = "SELECT screenshots.`id` AS `id`,
- screenshots.`screenshot_name` AS `screenshot_name`,
- screenshots.`screenshot_hourly` AS `screenshot_hourly`,
- screenshots.`screenshot_rate` AS `screenshot_rate`,
- DATE_FORMAT(screenshots.`created`, '" . $date_format_setting . ", %l:%i %p') AS `fcreated`,
- DATE_FORMAT(screenshots.`modified`, '" . $date_format_setting . ", %l:%i %p') AS `fmodified`,
- screenshots.`created` AS `created`,
- screenshots.`modified` AS `modified`,
- screenshots.`clientid` AS `clientid`
- FROM screenshots, users
- WHERE users.userid='" . $_SESSION['userid_auth'] . "'
- AND screenshots.screenshot_name LIKE '%" . $_POST['search'] . "%'";
- if($level_auth < "11" || getSetting('onlyShowImagesInMyGroup', $_SESSION['userid_auth']) == "0")
- $sql .= " AND users.id=screenshots.ownerid AND users.groupid = '" . $group_auth . "'";
- $sql .= " ORDER BY screenshots.`sort` ASC, screenshots.`modified` DESC, screenshots.`created` DESC";
- $search_text = "Images for the client <u>".str_replace($search_client, "", $_POST['search'])."</u>";
- // PROJECT SECTION
- } elseif(substr($_POST['search'], 0, strlen($search_client)) == $search_client) {
- $screenshot_sql = "SELECT id
- FROM clients
- WHERE fullname LIKE '%" . str_replace($search_client, "", $_POST['search']) . "%'";
- $screenshot_q = mysql_query($screenshot_sql);
- while($i = mysql_fetch_object($screenshot_q)) {
- $screenshot_id = $i->id;
- }
- $sql = "SELECT screenshots.`id` AS `id`,
- screenshots.`screenshot_name` AS `screenshot_name`,
- screenshots.`screenshot_file` AS `screenshot_file`,
- DATE_FORMAT(screenshots.`created`, '" . $date_format_setting . ", %l:%i %p') AS `fcreated`,
- DATE_FORMAT(screenshots.`modified`, '" . $date_format_setting . ", %l:%i %p') AS `fmodified`,
- screenshots.`created` AS `created`,
- screenshots.`modified` AS `modified`,
- screenshots.`clientid` AS `clientid`
- FROM screenshots, users
- WHERE users.userid='" . $_SESSION['userid_auth'] . "'
- AND screenshots.screenshot_name LIKE '%" . $_POST['search'] . "%'";
- if($level_auth < "11" || getSetting('onlyShowImagesInMyGroup', $_SESSION['userid_auth']) == "0")
- $sql .= " AND users.id=screenshots.ownerid AND users.groupid = '" . $group_auth . "'";
- $sql .= " ORDER BY screenshots.`sort` ASC, screenshots.`modified` DESC, screenshots.`created` DESC";
- $search_text = "Images for the client <u>".str_replace($search_client, "", $_POST['search'])."</u>";
- // SEARCH SECTION
- } else {
- $sql = "SELECT screenshots.`id` AS `id`,
- screenshots.`screenshot_name` AS `screenshot_name`,
- screenshots.`screenshot_hourly` AS `screenshot_hourly`,
- screenshots.`screenshot_rate` AS `screenshot_rate`,
- DATE_FORMAT(screenshots.`created`, '" . $date_format_setting . ", %l:%i %p') AS `fcreated`,
- DATE_FORMAT(screenshots.`modified`, '" . $date_format_setting . ", %l:%i %p') AS `fmodified`,
- screenshots.`created` AS `created`,
- screenshots.`modified` AS `modified`,
- screenshots.`clientid` AS `clientid`
- FROM screenshots
- WHERE userid='" . $_SESSION['userid_auth'] . "'
- AND milestoneid='0'
- AND completed='" . $completed . "'
- AND screenshotid='" . $screenshot_id . "'";
- $sql .= " ORDER BY screenshots.`sort` ASC, screenshots.`modified` DESC, screenshots.`created` DESC";
- $search_text = "Search results for the search term <u>".$_POST['search']."</u>";
- }
- } else { // a search was not performed
- $sql = "SELECT screenshots.`id` AS `id`,
- screenshots.`screenshot_name` AS `screenshot_name`,
- screenshots.`screenshot_file` AS `screenshot_file`,
- DATE_FORMAT(screenshots.`created`, '" . $date_format_setting . ", %l:%i %p') AS `fcreated`,
- DATE_FORMAT(screenshots.`modified`, '" . $date_format_setting . ", %l:%i %p') AS `fmodified`,
- screenshots.`created` AS `created`,
- screenshots.`modified` AS `modified`,
- screenshots.`clientid` AS `clientid`,
- screenshots.`projectid` AS `projectid`
- FROM screenshots
- ORDER BY screenshots.`modified` DESC, screenshots.`created` DESC";
- }
- //if($debugmode) echo "<pre>".$sql."</pre>";
- $q = mysql_query($sql);
- $total_numrows = mysql_num_rows($q);
- if($_POST['search']) echo "<p><strong>" . $search_text . "</strong></p>";
- if($notice) {
- ?>
- <div class="icon-container fadeout">
- <img src="<?php echo $basehref; ?>img/icons/button-info.png" class="icon-image" alt="" />
- </div>
- <div class="icon-text fadeout"><?php echo $notice; ?></div>
- <br clear="all" /><br clear="all" />
- <?php
- }
- if($_POST['search'] || $total_numrows) {
- ?>
- <div class="tab-content">
- <div class="tab-pane active" id="current">
- <table id="images" class="table table-striped table-bordered table-condensed table-hover table-pager" border="0" cellspacing="0" cellpadding="4" summary="">
- <thead>
- <tr>
- <th class="icon"></th>
- <th class="item">Image</th>
- <th>Client</th>
- <th>Project</th>
- <th>Updated</th>
- <th></th>
- </tr>
- </thead>
- <tbody><?php
- $j = 0;
- while($i = mysql_fetch_object($q)) {
- $id = $i->id;
- $screenshot_name = $i->screenshot_name;
- $screenshot_file = $i->screenshot_file;
- $screenshot_file = $i->screenshot_file;
- $completed = $i->completed;
- $created = $i->created;
- $modified = $i->modified;
- $fcreated = $i->fcreated;
- $fmodified = $i->fmodified;
- $clientid = $i->clientid;
- if($j % 2 == 0) $rowcolor = "row"; else $rowcolor = "altrow";
- ?>
- <tr id="item_<?php echo $id; ?>">
- <td class="icon"><button class="btn pull-left" type="button" id="<?php echo $id; ?>"><i class="icon-camera"></i></button></td>
- <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>
- <td><?php if($clientid) echo getClientName($clientid); else echo 'Internal'; ?></td>
- <td><?php if($projectid) echo getProjectName($projectid); ?></td>
- <td><?php if($modified != "0000-00-00 00:00:00" && $modified != "") echo $fmodified; else echo '-'; ?></td>
- <td><button class="btn btn-danger pull-right delete" type="button" id="<?php echo $id; ?>"><i class="icon-trash icon-white"></i></button></td>
- </tr>
- <?php
- $j++;
- }
- ?></tbody><?php
- if($total_numrows > "10") pagination();
- ?></table>
- </div>
- <div class="tab-pane" id="archived">
- <h3>Archived</h3>
- </div>
- </div>
- <?php
- }
- mysql_close($link);
- ?>
- <!-- Modal -->
- <?php require_once('includes/functions.php'); ?>
- <div id="addImage" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addImageLabel" aria-hidden="true">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">?—</button>
- <h3 id="addImageLabel">Add A New Image</h3>
- </div>
- <div class="modal-body">
- <form method="post" action="<? echo $basehref; ?>tasks/" class="form-horizontal">
- <div class="control-group">
- <label class="control-label" for="task_title">Image Title</label>
- <div class="controls">
- <input type="text" id="task_title" placeholder="Image Title">
- </div>
- </div>
- <div class="control-group">
- <label class="control-label" for="task_describe">Description</label>
- <div class="controls">
- <textarea id="task_describe" name="task_describe" class="blurred" cols="52" rows="4" placeholder="Description"></textarea>
- </div>
- </div>
- <div class="control-group">
- <label class="control-label" for="startdate">Start</label>
- <div class="controls">
- <input type="text" name="fstartdate" id="startdate" placeholder="Start">
- </div>
- </div>
- <div class="control-group">
- <label class="control-label" for="duedate">Due</label>
- <div class="controls">
- <input type="text" name="fduedate" id="duedate" placeholder="Due">
- </div>
- </div>
- <div class="control-group">
- <label class="control-label" for="duedate">Priority</label>
- <div class="controls">
- <select id="prioritydropdown" name="priority">
- <option value="1">High</option>
- <option value="2" selected="selected">Normal</option>
- <option value="3">Low</option>
- </select>
- </div>
- </div>
- </form>
- </div>
- <div class="modal-footer">
- <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
- <button class="btn btn-primary">Add Image</button>
- <input type="hidden" name="doAddImage" value="1" />
- </div>
- </div>