/includes/functions.php
PHP | 1022 lines | 917 code | 67 blank | 38 comment | 105 complexity | 0f76f9b7a79170992462494eb6829239 MD5 | raw file
- <?php
- include_once($web_root . "/config.php");
- include_once($web_root . "/mysql.php");
- function pagination($colspan) {
- ?>
- <tfoot>
- <tr>
- <td colspan="<?php echo $colspan; ?>">
- <div class="pager">
- <a href="" class="pagePrev"><img src="/img/icons/pagePrev.png" alt="« Previous" border="0" /></a>
- <span class="pageText">Page <span class="pageNum"></span> of <span class="pageCount"></span></span>
- <a href="" class="pageNext"><img src="/img/icons/pageNext.png" alt="Next »" border="0" /></a>
- </div>
- </td>
- </tr>
- </tfoot>
- <?php
- }
- function menuItems($menu) {
- $items = array();
- $sql = "SELECT id,
- menuid,
- `name`,
- appicon,
- level_gte
- FROM menus
- WHERE menu='$menu'
- AND `order`!='0'
- ORDER BY `order` ASC";
- $query = mysql_query($sql) or die("menuItems function: " . mysql_error());
- $num_rows = mysql_num_rows($query);
- if($num_rows):
- while(list($id, $menuid, $name, $appicon, $level_gte) = mysql_fetch_row($query)):
- $items[$menuid] = array(
- 'name' => $name,
- 'appicon' => $appicon,
- 'level_gte' => $level_gte
- );
- endwhile;
- endif;
- $z_sql = "SELECT id,
- menuid,
- `name`,
- appicon,
- level_gte
- FROM menus
- WHERE menu='$menu'
- AND `order`='0'
- ORDER BY `name` ASC";
- $z_query = mysql_query($z_sql) or die("menuItems function: " . mysql_error());
- $z_num_rows = mysql_num_rows($z_query);
- if($z_num_rows):
- while(list($id, $menuid, $name, $appicon, $level_gte) = mysql_fetch_row($z_query)):
- $items[$menuid] = array(
- 'name' => $name,
- 'appicon' => $appicon,
- 'level_gte' => $level_gte
- );
- endwhile;
- endif;
- return $items;
- }
- // convert a date into a string that tells how long
- // ago that date was.... eg: 2 days ago, 3 minutes ago.
- function ago($d) {
- $c = getdate();
- $p = array('year', 'mon', 'mday', 'hours', 'minutes', 'seconds');
- $display = array('year', 'month', 'day', 'hour', 'minute', 'second');
- $factor = array(0, 12, 30, 24, 60, 60);
- $d = datetoarr($d);
- for ($w = 0; $w < 6; $w++) {
- if ($w > 0) {
- $c[$p[$w]] += $c[$p[$w-1]] * $factor[$w];
- $d[$p[$w]] += $d[$p[$w-1]] * $factor[$w];
- }
- if ($c[$p[$w]] - $d[$p[$w]] > 1) {
- return ($c[$p[$w]] - $d[$p[$w]]).' '.$display[$w].'s ago';
- }
- }
- return '';
- }
- // you can replace this if need be. This converts the dates
- // returned from a mysql date string into an array object similar
- // to that returned by getdate().
- function datetoarr($d) {
- preg_match("/([0-9]{4})(\\-)([0-9]{2})(\\-)([0-9]{2}) ([0-9]{2})(\\:)([0-9]{2})(\\:)([0-9]{2})/", $d, $matches);
- return array(
- 'seconds' => $matches[10],
- 'minutes' => $matches[8],
- 'hours' => $matches[6],
- 'mday' => $matches[5],
- 'mon' => $matches[3],
- 'year' => $matches[1],
- );
- }
- function timetoarr($t) {
- preg_match("/([0-9]{2})(\\:)([0-9]{2})(\\:)([0-9]{2})/", $t, $matches);
- return array(
- 'seconds' => $matches[6],
- 'minutes' => $matches[4],
- 'hours' => $matches[2],
- );
- }
- function checkIfClockedIn() {
- $check_sql = "SELECT id,
- taskid,
- clock_in,
- clock_out
- FROM hours
- WHERE clock_out='0000-00-00 00:00:00'
- AND userid='" . $_SESSION['userid_auth'] . "'
- ORDER BY clock_in DESC
- LIMIT 1";
- $check_query = mysql_query($check_sql) or die("checkIfClockedIn function: " . mysql_error());
- $num_rows = mysql_num_rows($check_query);
- if($num_rows):
- while(list($hour_id, $task_id, $clock_in, $clock_out) = mysql_fetch_row($check_query)):
- return $task_id;
- endwhile;
- else:
- return false;
- endif;
- }
- function getDuration() {
- $check_sql = "SELECT id,
- taskid,
- clock_in,
- clock_out
- FROM hours
- WHERE clock_out='0000-00-00 00:00:00'
- AND userid='" . $_SESSION['userid_auth'] . "'
- ORDER BY clock_in DESC
- LIMIT 1";
- $check_query = mysql_query($check_sql) or die("getDuration function: " . mysql_error());
- $num_rows = mysql_num_rows($check_query);
- if($num_rows):
- while(list($hour_id, $task_id, $clock_in, $clock_out) = mysql_fetch_row($check_query)):
- // determine duration since clock-in time
- $interval = date_diff(date_create($clock_in), date_create(date('H:i:s')));
- return $interval->format('%H:%M:%S');
- endwhile;
- else:
- return FALSE;
- endif;
- }
- function getClientName($id) {
- $sql = "SELECT id, fullname FROM clients WHERE id='" . $id . "'";
- $query = mysql_query($sql) or die(mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $name) = mysql_fetch_row($query)) {
- return $name;
- }
- endif;
- }
- function getClientID($id) {
- $sql = "SELECT id, clientid FROM projects WHERE id='" . $id . "'";
- $query = mysql_query($sql) or die(mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $clientid) = mysql_fetch_row($query)) {
- return $clientid;
- }
- endif;
- }
- function addClientName($objectid, $newvalue) {
- // insert new jobcode
- $groupid = getCurrentUserGroupID();
- $insert_sql = "INSERT INTO clients (`name`, `groupid`, `linkdate`) VALUES ('" . $newvalue . "', '" . $groupid . "', NOW())";
- $insert_query = mysql_query($insert_sql) or die(mysql_error());
- // update object with new client id
- $id_sql = "SELECT id FROM clients WHERE name = '" . $newvalue . "'";
- $id_query = mysql_query($id_sql) or die("addClientName function: " . mysql_error());
- $numrows = mysql_num_rows($id_query);
- if($numrows):
- while(list($id) = mysql_fetch_row($id_query)) {
- $object_sql = "UPDATE objects
- SET clientid='" . $id . "'
- WHERE id='" . $objectid . "'";
- $object_query = mysql_query($object_sql) or die(mysql_error());
- }
- endif;
- // return new value
- return $newvalue;
- }
- function getTaskTitle($id) {
- $sql = "SELECT id, task_title FROM tasks WHERE id='" . $id . "'";
- $query = mysql_query($sql) or die("getTaskTitle function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $name) = mysql_fetch_row($query)) {
- return $name;
- }
- endif;
- }
- function getProjectName($id) {
- $sql = "SELECT id, project_name FROM projects WHERE id='" . $id . "'";
- $query = mysql_query($sql) or die("getProjectName function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $name) = mysql_fetch_row($query)) {
- return $name;
- }
- endif;
- }
- function getProjectHourlyRate($id) {
- $sql = "SELECT id, project_hourly_rate FROM projects WHERE id='" . $id . "'";
- $query = mysql_query($sql) or die("getProjectHourlyRate function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $rate) = mysql_fetch_row($query)) {
- return $rate;
- }
- endif;
- }
- function getProjectID($id) {
- $sql = "SELECT id, projectid FROM tasks WHERE id='" . $id . "'";
- $query = mysql_query($sql) or die("getProjectID function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $projectid) = mysql_fetch_row($query)) {
- return $projectid;
- }
- endif;
- }
- function getProjectIDfromHourID($id) {
- $sql = "SELECT projects.id
- FROM projects, tasks, hours
- WHERE hours.id='" . $id . "'
- AND hours.taskid=tasks.id
- AND tasks.projectid=projects.id";
- $query = mysql_query($sql) or die("getProjectIDfromHourID function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($projectid) = mysql_fetch_row($query)) {
- return $projectid;
- }
- endif;
- }
- function setProjectName($taskid, $newvalue) {
- $sql = "SELECT tasks.`id`,
- tasks.`projectid`
- FROM tasks
- WHERE tasks.`id`='" . $taskid . "'";
- $query = mysql_query($sql) or die("setProjectName function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $projectid) = mysql_fetch_row($query)) {
- $update_project_sql = "UPDATE tasks
- SET projectid='" . $newvalue . "'
- WHERE id='" . $taskid . "'";
- $update_project_query = mysql_query($update_project_sql) or die(mysql_error());
- $project_sql = "SELECT project_name FROM projects WHERE id='" . $newvalue . "'";
- $project_query = mysql_query($project_sql) or die("setProjectName function 2: " . mysql_error());
- while(list($project_name) = mysql_fetch_row($project_query)) {
- return $project_name;
- }
- }
- endif;
- }
- function getUserID() {
- $sql = "SELECT id FROM users WHERE username='" . $_SESSION['username_auth'] . "'";
- $query = mysql_query($sql) or die("getUserID function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($user_id) = mysql_fetch_row($query)) {
- return $user_id;
- }
- endif;
- }
- function getCurrentUserAccessLevel() {
- if(isset($_SESSION['username_auth'])) {
- $sql = "SELECT level FROM users WHERE username='" . $_SESSION['username_auth'] . "'";
- $query = mysql_query($sql) or die("getCurrentUserAccessLevel function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($level) = mysql_fetch_row($query)) {
- return $level;
- }
- endif;
- }
- }
- function getCurrentUserGroupID() {
- if(isset($_SESSION['username_auth'])) {
- $sql = "SELECT groupid FROM users WHERE username='" . $_SESSION['username_auth'] . "'";
- $query = mysql_query($sql) or die("getCurrentUserGroupID function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($level) = mysql_fetch_row($query)) {
- return $level;
- }
- endif;
- }
- }
- function getAclName($level) {
- $sql = "SELECT name FROM acl WHERE level='" . $level . "'";
- $query = mysql_query($sql) or die("getAclName function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($name) = mysql_fetch_row($query)) {
- return $name;
- }
- endif;
- }
- function getGroupName($groupid) {
- $sql = "SELECT name FROM groups WHERE id='" . $groupid . "'";
- $query = mysql_query($sql) or die("getGroupName function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($name) = mysql_fetch_row($query)) {
- return $name;
- }
- endif;
- }
- function getAccessLevelName($level) {
- $sql = "SELECT name FROM acl WHERE level='" . $level . "'";
- $query = mysql_query($sql) or die("getAccessLevelName function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($name) = mysql_fetch_row($query)) {
- return $name;
- }
- endif;
- }
- function createSalt() {
- $string = md5(uniqid(rand(), true));
- return substr($string, 0, 3);
- }
- function getUsernameByID($user_id) {
- $sql = "SELECT username
- FROM users
- WHERE id = '" . $user_id . "'";
- $query = mysql_query($sql) or die("getUsernameByID function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($username) = mysql_fetch_row($query)) {
- return $username;
- }
- endif;
- }
- function getGroupsDropdown($level_auth) {
- if($level_auth == "11"):
- $sql = "SELECT id, name
- FROM groups
- ORDER BY name";
- $query = mysql_query($sql) or die("getGroupsDropdown function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $name) = mysql_fetch_row($query)) {
- $options[] = '<option value="'.$id.'">'.$name.'</option>'."\n";
- }
- return $options;
- endif;
- endif;
- }
- function getClientsDropdown($level_auth) {
- $sql = "SELECT id, fullname
- FROM clients
- ORDER BY fullname";
- $query = mysql_query($sql) or die("getClientsDropdown function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $name) = mysql_fetch_row($query)) {
- $options[] = '<option value="'.$id.'">'.$name.'</option>'."\n";
- }
- return $options;
- endif;
- }
- function getProjectsDropdown($seldb) {
- $projects_sql = "SELECT id, project_name
- FROM projects
- ORDER BY project_name ASC";
- $projects_query = mysql_query($projects_sql) or die("getProjectsDropdown function: " . mysql_error());
- $numrows = mysql_num_rows($projects_query);
- if($numrows):
- while(list($id, $name) = mysql_fetch_row($query)) {
- $options[] = '<option value="'.$id.'">'.$name.'</option>'."\n";
- }
- return $options;
- else:
- return array('TEST');
- endif;
- }
- function getUsersDropdown($level_auth, $group_auth) {
- $sql = "SELECT id, username
- FROM users
- ORDER BY username ASC";
- $query = mysql_query($sql) or die("getUsersDropdown function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($id, $name) = mysql_fetch_row($query)) {
- $options[] = '<option value="'.$id.'">'.$name.'</option>'."\n";
- }
- return $options;
- endif;
- }
- function getClientGroupID($clientid) {
- $sql = "SELECT users.groupid
- FROM users, clients
- WHERE clients.userid=users.id
- AND clients.id='" . $clientid . "'";
- $query = mysql_query($sql) or die("getClientGroupID function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($groupid) = mysql_fetch_row($query)) {
- return $groupid;
- }
- endif;
- }
- function getSetting($name, $userid) {
- $sql = "SELECT name, value
- FROM settings
- WHERE name='" . $name . "'
- AND userid='" . $userid . "'";
- $query = mysql_query($sql) or die("getSetting function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($name, $value) = mysql_fetch_row($query)) {
- return $value;
- }
- else:
- return "0";
- endif;
- }
- function checkSetting($name, $userid) {
- $sql = "SELECT `name`, `value` FROM `settings`
- WHERE userid='" . $userid . "'
- AND name='" . $name . "'";
- $query = mysql_query($sql) or die("checkSetting function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($name, $value) = mysql_fetch_row($query)) {
- return "1";
- }
- else:
- return "0";
- endif;
- }
- function insertSetting($name, $value, $userid) {
- $sql = "INSERT INTO `settings` (
- `name`,
- `value`,
- `userid`
- ) VALUES (
- '" . $name . "',
- '" . $value . "',
- '" . $userid . "'
- )";
- $query = mysql_query($sql) or die("insertSetting function: " . mysql_error());
- }
- function updateSetting($name, $value, $userid) {
- $sql = "UPDATE `settings`
- SET `name`='" . $name . "',
- `value`='" . $value . "',
- `userid`='" . $userid . "'
- WHERE userid='" . $userid . "'
- AND name='" . $name . "'";
- $query = mysql_query($sql) or die("updateSetting function: " . mysql_error());
- }
- function getStatesDropdown($level_auth) {
- ?>
- <option value="AL">Alabama</option>
- <option value="AK">Alaska</option>
- <option value="AZ">Arizona</option>
- <option value="AR">Arkansas</option>
- <option value="CA">California</option>
- <option value="CO">Colorado</option>
- <option value="CT">Connecticut</option>
- <option value="DE">Delaware</option>
- <option value="DC">District of Columbia</option>
- <option value="FL">Florida</option>
- <option value="GA">Georgia</option>
- <option value="HI">Hawaii</option>
- <option value="ID">Idaho</option>
- <option value="IL">Illinois</option>
- <option value="IN">Indiana</option>
- <option value="IA">Iowa</option>
- <option value="KS">Kansas</option>
- <option value="KY">Kentucky</option>
- <option value="LA">Louisiana</option>
- <option value="ME">Maine</option>
- <option value="MD">Maryland</option>
- <option value="MA">Massachusetts</option>
- <option value="MI">Michigan</option>
- <option value="MN">Minnesota</option>
- <option value="MS">Mississippi</option>
- <option value="MO">Missouri</option>
- <option value="MT">Montana</option>
- <option value="NE">Nebraska</option>
- <option value="NV">Nevada</option>
- <option value="NH">New Hampshire</option>
- <option value="NJ">New Jersey</option>
- <option value="NM">New Mexico</option>
- <option value="NY">New York</option>
- <option value="NC">North Carolina</option>
- <option value="ND">North Dakota</option>
- <option value="OH">Ohio</option>
- <option value="OK">Oklahoma</option>
- <option value="OR">Oregon</option>
- <option value="PA">Pennsylvania</option>
- <option value="RI">Rhode Island</option>
- <option value="SC">South Carolina</option>
- <option value="SD">South Dakota</option>
- <option value="TN">Tennessee</option>
- <option value="TX">Texas</option>
- <option value="UT">Utah</option>
- <option value="VT">Vermont</option>
- <option value="VA">Virginia</option>
- <option value="WA">Washington</option>
- <option value="WV">West Virginia</option>
- <option value="WI">Wisconsin</option>
- <option value="WY">Wyoming</option>
- <?php
- }
- function getAccessLevelsDropdown() {
- $sql = "SELECT level, name
- FROM acl
- WHERE level != '11'";
- $query = mysql_query($sql) or die("getAccessLevelsDropdown function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows):
- while(list($level, $name) = mysql_fetch_row($query)) {
- $options[] = '<option value="'.$level.'">'.$name.'</option>'."\n";
- }
- return $options;
- endif;
- }
- function checkAlias($alias, $withssl) {
- $sql = "SELECT directives.id AS alias_id,
- directives.value AS alias,
- directives.withssl AS withssl
- FROM directives
- WHERE value = '" . $alias . "'
- AND name='ServerAlias'
- AND withssl = '" . $withssl . "'";
- $query = mysql_query($sql) or die("checkAlias function: " . mysql_error());
- $numrows = mysql_num_rows($query);
- if($numrows) return true;
- }
- function convertDate($date) {
- $parts = explode("/", $date);
- $month = $parts[0];
- $day = $parts[1];
- $year = $parts[2];
- return $year."-".$month."-".$day;
- }
- function formatWebsite($website) {
- if(substr($website, 0, 7) != "http://"):
- $return = "http://" . $website;
- else:
- $return = $website;
- endif;
- return $return;
- }
- // trim inputted phone numbers
- function trimPhone($phone) {
- $return = onlyNumbers($phone);
- if(substr($return, 0, 1) == "1"):
- $return = substr($return, 1, strlen($return));
- endif;
- if(strlen($return) > "10"):
- $return = substr($return, 0, 10);
- endif;
- return $return;
- }
- function trimExt($ext) {
- return onlyNumbers($ext);
- }
- function onlyNumbers($number) {
- $return = preg_replace('/[^0-9]/', '', $number);
- return $return;
- }
- // display/print phone numbers to the user
- function printPhone($phone) {
- $areacode = substr($phone, 0, 3);
- $prefix = substr($phone, 3, 3);
- $suffix = substr($phone, 6, 4);
- $return = "(" . $areacode . ") " . $prefix . "-" . $suffix;
- return $return;
- }
- function createThumbs( $pathToImages, $thumbWidth ) {
- $pathToThumbs = $pathToImages . "thumbs/";
- // open the directory
- $dir = opendir( $pathToImages );
- // loop through it, looking for any/all JPG files:
- while (false !== ($fname = readdir( $dir ))) {
- // parse path for the extension
- $info = pathinfo($pathToImages . $fname);
- // continue only if this is a JPEG image
- if ( strtolower($info['extension']) == 'jpg' ) {
- // load image and get image size
- $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
- $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 new file name
- // save thumbnail into a file
- imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
- }
- }
- // close the directory
- closedir( $dir );
- }
- function recursiveDelete($str){
- if(is_file($str)){
- return @unlink($str);
- } elseif(is_dir($str)){
- $scan = glob(rtrim($str,'/').'/*');
- foreach($scan as $index=>$path){
- recursiveDelete($path);
- }
- return @rmdir($str);
- }
- }
- function validate_email($Email) {
- global $HTTP_HOST;
- $result = array();
- if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) {
- $result[0]=false;
- $result[1]="$Email is not properly formatted";
- return $result;
- }
- list ( $Username, $Domain ) = split ("@",$Email);
- if (getmxrr($Domain, $MXHost)) {
- $ConnectAddress = $MXHost[0];
- } else {
- $ConnectAddress = $Domain;
- }
- $Connect = fsockopen ( $ConnectAddress, 25 );
- if ($Connect) {
- if (ereg("^220", $Out = fgets($Connect, 1024))) {
- fputs ($Connect, "HELO $HTTP_HOST\r\n");
- $Out = fgets ( $Connect, 1024 );
- fputs ($Connect, "MAIL FROM: <{$Email}>\r\n");
- $From = fgets ( $Connect, 1024 );
- fputs ($Connect, "RCPT TO: <{$Email}>\r\n");
- $To = fgets ($Connect, 1024);
- fputs ($Connect, "QUIT\r\n");
- fclose($Connect);
- if (!ereg ("^250", $From) || !ereg ( "^250", $To )) {
- $result[0]=false;
- $result[1]="Server rejected address";
- return $result;
- }
- } else {
- $result[0] = false;
- $result[1] = "No response from server";
- return $result;
- }
- } else {
- $result[0]=false;
- $result[1]="Can not connect E-Mail server.";
- return $result;
- }
- $result[0]=true;
- $result[1]="$Email appears to be valid.";
- return $result;
- } // end of validate_email() function
- function blacklist_check() {
- return '<p>This search feature is still under development.</p>';
- } // end of blacklist_check() function
- /* EMAIL FUNCTIONS */
- function customEmailHeader() {
- $return_header = '
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>WebSight Designs Invoice</title>
- <link rel="stylesheet" type="text/css" href="http://manage.websightdesigns.com/css/email.css">
- </head>
- <body bgcolor="#eeeeee">
- <table border="0" width="100%" border="0" cellspacing="0" cellpadding="0" class="bg1">
- <tr>
- <td align="center">
- <table width="600" border="0" cellspacing="0" cellpadding="0" class="bg2">
- <tr>
- <td class="header" align="left">
- <img src="http://websightdesigns.com/scripts/header.gif" alt="WebSight Designs Invoice" width="600" height="107" />
- </td>
- </tr>
- <tr>
- <td valign="top" class="body">
- ';
- return $return_header;
- }
- function customEmailFooter($invoice_id, $comments) {
- $return_footer = '';
- if($comments) $return_footer .= '<p style="font-size: 12px;">' . $comments . '</p>';
- $return_footer .= '
- <p style="font-size: 12px;"><strong>Important:</strong> Please add <em>invoices@websightdesigns.com</em> to your e-mail\'s whitelist or address book to ensure you receive your invoices to your inbox. Otherwise, you may need to check your Junk Mail folder for your invoices.</p>
- </td>
- </tr>
- <tr>
- <td valign="middle" align="left" class="footer" height="72">
- <p>361 S. Camino Del Rio, Durango, CO 81303. 970-239-1247<br /><br />
- <font color="#333333"><a href="http://www.websightdesigns.com/payments/" style="color: #333333;">Pay Your Invoice Online</a></font> | <font color="#333333"><a href="http://www.websightdesigns.com/quote/" style="color: #333333;">Contact Us Online</a></font> | <font color="#333333"><a href="mailto:info@websightdesigns.com?subject=Invoice%20#'.$invoice_id.'" style="color: #333333;">Contact Us by E-mail</a></font></p>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </body>
- </html>
- ';
- return $return_footer;
- }
- function invoicesEmailTextBody() {
- return 'Please call if you have any questions at 970-239-1247
- Technical Support: support@websightdesigns.com
- ';
- }
- function sendInvoice($invoice_id, $comments) {
- // send an invoice
- $invoice_sql = "SELECT clientid FROM invoices WHERE id='".$invoice_id."'";
- $invoice_query = mysql_query($invoice_sql) or die(mysql_error());
- while(list($clientid) = mysql_fetch_row($invoice_query)):
- $customer = $clientid;
- endwhile;
- $customers_sql = "SELECT `id`,
- `fullname`,
- `company`,
- `email`,
- `phone`,
- `phone_ext`,
- `address`,
- `city`,
- `state`,
- `zipcode`,
- `cc_fullname`,
- `cc_company`,
- `cc_email`,
- `cc_phone`,
- `cc_phone_ext`,
- `cc_address`,
- `cc_city`,
- `cc_state`,
- `cc_zipcode`,
- `cc_type`,
- `cc_number`,
- `cc_expire`,
- `ownerid`,
- `userid`,
- `created`,
- `sort`
- FROM clients
- WHERE id='" . $customer . "'";
- #echo $customers_sql . "<br />";
- $customers_query = mysql_query($customers_sql) or die(mysql_error());
- while(list($id, $fullname, $company, $email, $phone, $phone_ext, $address, $city, $state, $zipcode, $cc_fullname, $cc_company, $cc_email, $cc_phone, $cc_phone_ext, $cc_address, $cc_city, $cc_state, $cc_zipcode, $cc_type, $cc_number, $cc_expire, $ownerid, $userid, $created, $sort) = mysql_fetch_row($customers_query)):
- // for each customer (there is only one though) now check to see if there are any
- // outstanding invoices
- $invoices_sql = "SELECT id,
- hours,
- title,
- amount_due,
- amount_paid,
- DATE_FORMAT(`created`, '%b %e, %Y') AS `created`,
- sent,
- duedate,
- clientid,
- projectid
- FROM invoices
- WHERE clientid='" . $customer . "'
- AND amount_paid < amount_due";
- //echo $invoices_sql . "<br />";
- $invoices_query = mysql_query($invoices_sql) or die(mysql_error());
- $invoices_count = mysql_num_rows($invoices_query);
- if($invoices_count):
- // SET UP THE TEXT VERSION
- $text_message = 'Invoice from WebSight Designs
- This is an invoice for services rendered by WebSight Designs, Inc.
- Please enable HTML emails so you may see the contents of this invoice.
- If you cannot enable HTML in your email client, please contact us at 970-239-1247 to discuss payment options.
- ';
- // SET UP THE HTML VERSION
- $html_message = customEmailHeader();
- $html_message .= '
- <table bgcolor="#FFFFFF" width="100%" border="0" cellspacing="0" cellpadding="3">
- <tr>
- <td id="content" valign="top" class="mainbar" align="left">
- <div id="billinginfo">
- <h1 style="color: #333333; font-size: 13px;">Billing Information</h1>
- <p>' . $cc_fullname . '<br />
- '; if($cc_company) $html_message .= $cc_company . '<br />'; $html_message .= '
- '; if($cc_address) $html_message .= $cc_address . '<br />';
- if($cc_city) $html_message .= $cc_city . ', ';
- if($cc_state) $html_message .= $cc_state . ' ';
- if($cc_zipcode) $html_message .= sprintf("%05d",$cc_zipcode);
- if($cc_zipcode_ext) $html_message .= '-'.sprintf("%04d",$cc_zipcode_ext);
- if($cc_city || $cc_state || $cc_zipcode) $html_message .= '<br />';
- $html_message .= '<br />
- '; if($cc_phone) { $html_message .= printPhone($cc_phone); if($cc_phone_ext) $html_message .= 'ext. ' . $cc_phone_ext; }
- $html_message .= '</p>
- </div>
- <div id="companyinfo">
- <h1 style="color: #333333; font-size: 13px;"><a href="http://www.websightdesigns.com/payments/">Make Payments Online</a> or Mail Check Payable To Gregory Burga</h1>
- <p>WebSight Designs<br />
- 5100 Leetsdale Dr., #423<br />
- Denver, CO 80246<br /><br />
- (970) 239-1247</p>
- </div>
- <div id="invoiceinfo">
- <table id="inner" border="0" cellspacing="0" cellpadding="3" summary="">
- <tr style="background-color: #333333; font-size: 13px;">
- <th width="10%">Invoice</th>
- <th width="24%">Date</th>
- <th width="42%">Description</th>
- <th width="12%" style="text-align: center;">Fee</th>
- <th width="12%" style="text-align: center;" class="last">Amount Due</th>
- </tr>
- ';
- $total_amount_due = 0;
- $altrows = 0;
- while(list($invoice_id, $hours, $title, $amount_due, $amount_paid, $created, $sent, $duedate, $clientid, $projectid) = mysql_fetch_row($invoices_query)):
- $hourly_rate = getProjectHourlyRate($projectid);
- $total_amount_due += sprintf("%01.2f", $amount_due - $amount_paid);
- $total_hours_worked = $amount_due / $hourly_rate;
- $project_name = getProjectName($projectid);
- if($hours) {
- $hoursids = explode(",", $hours);
- foreach($hoursids AS $hourid) {
- if($hourid) {
- $sql = "SELECT tasks.`task_title`,
- hours.`duration`,
- DATE_FORMAT(hours.`clock_out`, '%b %e, %Y') AS `clock_out`
- FROM hours, tasks
- WHERE hours.userid='" . $_SESSION['userid_auth'] . "'
- AND hours.id='".$hourid."'
- AND hours.`taskid`=tasks.`id`";
- $q = mysql_query($sql);
- while($i = mysql_fetch_object($q)) {
- $task_title = $i->task_title;
- $duration = $i->duration;
- $time = explode(":", $duration);
- $hours = ltrim($time[0], "0");
- $mins = ltrim($time[1], "0");
- if($mins > "15") $hours += "1";
- $cur_amount_due = $hours * $hourly_rate;
- // add invoice list to html email message
- if($hours) {
- $text_message .= '- ' . $task_title . "\n";
- $html_message .= '<tr style="font-size: 13px;">
- <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">' . sprintf("%05d",$invoice_id) . '</td>
- <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">' . $created . '</td>
- <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">'; if($project_name) $html_message .= '<strong>' . $project_name . ':</strong> '; $html_message .= $task_title . '</td>
- <td style="text-align: center; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '" align="right">$' . $hourly_rate . ' x ' . $hours . '</td>
- <td style="text-align: right; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '" align="right" class="last">$' . $cur_amount_due; $html_message .= '</td>
- </tr>';
- $altrows++;
- }
- }
- }
- }
- } else { // hours field is blank, so use title field instead
- $text_message .= '- '; if($title) $text_message .= $title; else $text_message .= "Website Design Work"; $html_message .= "\n";
- $html_message .= '<tr style="font-size: 13px;">
- <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">' . sprintf("%05d",$invoice_id) . '</td>
- <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">' . $created . '</td>
- <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">'; if($project_name) $html_message .= '<strong>' . $project_name . ':</strong> '; if($title) $html_message .= $title; else $html_message .= 'Website Design Work'; $html_message .= '</td>
- <td style="text-align: center; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '" align="right">$' . $amount_due . '</td>
- <td style="text-align: right; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '" align="right" class="last">$' . $amount_due; $html_message .= '</td>
- </tr>';
- $altrows++;
- } // end if($hours)
- // mark invoice as sent
- $update_sent_sql = "UPDATE invoices SET sendcount=sendcount+1, sent=NOW() WHERE id='" . $invoice_id . "'";
- $update_sent_query = mysql_query($update_sent_sql) or die(mysql_error());
- endwhile;
- $html_message .= '
- <tr>
- <td style="font-size: 14px; background-color: #e6e6e6;" colspan="4">Total Amount Due</td>
- <td style="font-size: 14px; background-color: #e6e6e6; text-align: right;" class="last" align="right">$' . $total_amount_due . '</td>
- </tr>
- </table>
- </div>
- </td>
- </tr>
- </table>
- ';
- $html_message .= customEmailFooter(sprintf("%05d",$invoice_id), $comments);
- $text_message .= 'Amount Due: ' . $total_amount_due . "\n";
- $text_message .= 'Please mail a check made out to Gregory Burga to the following address:
- WebSight Designs
- 5100 Leetsdale Dr., #423
- Denver, CO 80246
- Or you may pay online at http://www.websightdesigns.com/payments/
- Please call if you have any questions at 970-239-1247
- Technical Support: http://www.websightdesigns.com/contact/ or support@websightdesigns.com
- ';
- // send the email
- include('Mail.php');
- include('Mail/mime.php');
- $message = new Mail_mime("\n");
- $message->setTXTBody($text_message);
- $message->setHTMLBody($html_message);
- $body = $message->get();
- $extraheaders = array("From"=>"invoices@websightdesigns.com", "Subject"=>"WebSight Designs Invoice");
- $headers = $message->headers($extraheaders);
- $mail = Mail::factory("mail");
- // send email to customer
- $mail->send($cc_email, $headers, $body);
- // send a copy to invoices email
- $mail->send("invoices@websightdesigns.com", $headers, $body);
- // print result into browser window for debugging
- echo 'E-mailed an invoice to ' . $cc_email . "\n";
- // END HTML EMAIL
- else:
- ?>There are currently no invoices scheduled to be sent to this customer.<?php
- endif; // end if($invoices_count)
- endwhile;
- }
- function dbug($var, $name, $debugmode) {
- if($debugmode) {
- ob_start();
- echo '<p>' . $name . ':</p>';
- echo '<pre>';
- var_dump($var);
- echo '</pre>';
- $dump = ob_get_clean();
- print $dump;
- }
- }
- /* COMMAND RESULTS */
- function display_command_results($action) {
- $obj = json_decode($_SESSION["command_results"][$action]);
- $total = $obj->{'total'};
- $return = '';
- for($i = 0; $i < $total; $i++):
- $code = $obj->{$i}->{'code'};
- if($code == "0") $image = "info";
- elseif($code == -1) $image = "alert";
- else $image = "subtract";
- $return .= '<div class="icon-container fadeout"><img src="/img/icons/button-' . $image . '.png" class="icon-image" alt="" /></div><div class="icon-text fadeout">' . $obj->{$i}->{'description'} . '</div><br clear="all" />';
- endfor;
- $_SESSION["command_results"][$action] = "";
- print $return;
- }
- ?>