PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/functions.php

https://bitbucket.org/websightdesigns/project-manager
PHP | 1022 lines | 917 code | 67 blank | 38 comment | 105 complexity | 0f76f9b7a79170992462494eb6829239 MD5 | raw file
  1. <?php
  2. include_once($web_root . "/config.php");
  3. include_once($web_root . "/mysql.php");
  4. function pagination($colspan) {
  5. ?>
  6. <tfoot>
  7. <tr>
  8. <td colspan="<?php echo $colspan; ?>">
  9. <div class="pager">
  10. <a href="" class="pagePrev"><img src="/img/icons/pagePrev.png" alt="&laquo; Previous" border="0" /></a>
  11. <span class="pageText">Page <span class="pageNum"></span> of <span class="pageCount"></span></span>
  12. <a href="" class="pageNext"><img src="/img/icons/pageNext.png" alt="Next &raquo;" border="0" /></a>
  13. </div>
  14. </td>
  15. </tr>
  16. </tfoot>
  17. <?php
  18. }
  19. function menuItems($menu) {
  20. $items = array();
  21. $sql = "SELECT id,
  22. menuid,
  23. `name`,
  24. appicon,
  25. level_gte
  26. FROM menus
  27. WHERE menu='$menu'
  28. AND `order`!='0'
  29. ORDER BY `order` ASC";
  30. $query = mysql_query($sql) or die("menuItems function: " . mysql_error());
  31. $num_rows = mysql_num_rows($query);
  32. if($num_rows):
  33. while(list($id, $menuid, $name, $appicon, $level_gte) = mysql_fetch_row($query)):
  34. $items[$menuid] = array(
  35. 'name' => $name,
  36. 'appicon' => $appicon,
  37. 'level_gte' => $level_gte
  38. );
  39. endwhile;
  40. endif;
  41. $z_sql = "SELECT id,
  42. menuid,
  43. `name`,
  44. appicon,
  45. level_gte
  46. FROM menus
  47. WHERE menu='$menu'
  48. AND `order`='0'
  49. ORDER BY `name` ASC";
  50. $z_query = mysql_query($z_sql) or die("menuItems function: " . mysql_error());
  51. $z_num_rows = mysql_num_rows($z_query);
  52. if($z_num_rows):
  53. while(list($id, $menuid, $name, $appicon, $level_gte) = mysql_fetch_row($z_query)):
  54. $items[$menuid] = array(
  55. 'name' => $name,
  56. 'appicon' => $appicon,
  57. 'level_gte' => $level_gte
  58. );
  59. endwhile;
  60. endif;
  61. return $items;
  62. }
  63. // convert a date into a string that tells how long
  64. // ago that date was.... eg: 2 days ago, 3 minutes ago.
  65. function ago($d) {
  66. $c = getdate();
  67. $p = array('year', 'mon', 'mday', 'hours', 'minutes', 'seconds');
  68. $display = array('year', 'month', 'day', 'hour', 'minute', 'second');
  69. $factor = array(0, 12, 30, 24, 60, 60);
  70. $d = datetoarr($d);
  71. for ($w = 0; $w < 6; $w++) {
  72. if ($w > 0) {
  73. $c[$p[$w]] += $c[$p[$w-1]] * $factor[$w];
  74. $d[$p[$w]] += $d[$p[$w-1]] * $factor[$w];
  75. }
  76. if ($c[$p[$w]] - $d[$p[$w]] > 1) {
  77. return ($c[$p[$w]] - $d[$p[$w]]).' '.$display[$w].'s ago';
  78. }
  79. }
  80. return '';
  81. }
  82. // you can replace this if need be. This converts the dates
  83. // returned from a mysql date string into an array object similar
  84. // to that returned by getdate().
  85. function datetoarr($d) {
  86. preg_match("/([0-9]{4})(\\-)([0-9]{2})(\\-)([0-9]{2}) ([0-9]{2})(\\:)([0-9]{2})(\\:)([0-9]{2})/", $d, $matches);
  87. return array(
  88. 'seconds' => $matches[10],
  89. 'minutes' => $matches[8],
  90. 'hours' => $matches[6],
  91. 'mday' => $matches[5],
  92. 'mon' => $matches[3],
  93. 'year' => $matches[1],
  94. );
  95. }
  96. function timetoarr($t) {
  97. preg_match("/([0-9]{2})(\\:)([0-9]{2})(\\:)([0-9]{2})/", $t, $matches);
  98. return array(
  99. 'seconds' => $matches[6],
  100. 'minutes' => $matches[4],
  101. 'hours' => $matches[2],
  102. );
  103. }
  104. function checkIfClockedIn() {
  105. $check_sql = "SELECT id,
  106. taskid,
  107. clock_in,
  108. clock_out
  109. FROM hours
  110. WHERE clock_out='0000-00-00 00:00:00'
  111. AND userid='" . $_SESSION['userid_auth'] . "'
  112. ORDER BY clock_in DESC
  113. LIMIT 1";
  114. $check_query = mysql_query($check_sql) or die("checkIfClockedIn function: " . mysql_error());
  115. $num_rows = mysql_num_rows($check_query);
  116. if($num_rows):
  117. while(list($hour_id, $task_id, $clock_in, $clock_out) = mysql_fetch_row($check_query)):
  118. return $task_id;
  119. endwhile;
  120. else:
  121. return false;
  122. endif;
  123. }
  124. function getDuration() {
  125. $check_sql = "SELECT id,
  126. taskid,
  127. clock_in,
  128. clock_out
  129. FROM hours
  130. WHERE clock_out='0000-00-00 00:00:00'
  131. AND userid='" . $_SESSION['userid_auth'] . "'
  132. ORDER BY clock_in DESC
  133. LIMIT 1";
  134. $check_query = mysql_query($check_sql) or die("getDuration function: " . mysql_error());
  135. $num_rows = mysql_num_rows($check_query);
  136. if($num_rows):
  137. while(list($hour_id, $task_id, $clock_in, $clock_out) = mysql_fetch_row($check_query)):
  138. // determine duration since clock-in time
  139. $interval = date_diff(date_create($clock_in), date_create(date('H:i:s')));
  140. return $interval->format('%H:%M:%S');
  141. endwhile;
  142. else:
  143. return FALSE;
  144. endif;
  145. }
  146. function getClientName($id) {
  147. $sql = "SELECT id, fullname FROM clients WHERE id='" . $id . "'";
  148. $query = mysql_query($sql) or die(mysql_error());
  149. $numrows = mysql_num_rows($query);
  150. if($numrows):
  151. while(list($id, $name) = mysql_fetch_row($query)) {
  152. return $name;
  153. }
  154. endif;
  155. }
  156. function getClientID($id) {
  157. $sql = "SELECT id, clientid FROM projects WHERE id='" . $id . "'";
  158. $query = mysql_query($sql) or die(mysql_error());
  159. $numrows = mysql_num_rows($query);
  160. if($numrows):
  161. while(list($id, $clientid) = mysql_fetch_row($query)) {
  162. return $clientid;
  163. }
  164. endif;
  165. }
  166. function addClientName($objectid, $newvalue) {
  167. // insert new jobcode
  168. $groupid = getCurrentUserGroupID();
  169. $insert_sql = "INSERT INTO clients (`name`, `groupid`, `linkdate`) VALUES ('" . $newvalue . "', '" . $groupid . "', NOW())";
  170. $insert_query = mysql_query($insert_sql) or die(mysql_error());
  171. // update object with new client id
  172. $id_sql = "SELECT id FROM clients WHERE name = '" . $newvalue . "'";
  173. $id_query = mysql_query($id_sql) or die("addClientName function: " . mysql_error());
  174. $numrows = mysql_num_rows($id_query);
  175. if($numrows):
  176. while(list($id) = mysql_fetch_row($id_query)) {
  177. $object_sql = "UPDATE objects
  178. SET clientid='" . $id . "'
  179. WHERE id='" . $objectid . "'";
  180. $object_query = mysql_query($object_sql) or die(mysql_error());
  181. }
  182. endif;
  183. // return new value
  184. return $newvalue;
  185. }
  186. function getTaskTitle($id) {
  187. $sql = "SELECT id, task_title FROM tasks WHERE id='" . $id . "'";
  188. $query = mysql_query($sql) or die("getTaskTitle function: " . mysql_error());
  189. $numrows = mysql_num_rows($query);
  190. if($numrows):
  191. while(list($id, $name) = mysql_fetch_row($query)) {
  192. return $name;
  193. }
  194. endif;
  195. }
  196. function getProjectName($id) {
  197. $sql = "SELECT id, project_name FROM projects WHERE id='" . $id . "'";
  198. $query = mysql_query($sql) or die("getProjectName function: " . mysql_error());
  199. $numrows = mysql_num_rows($query);
  200. if($numrows):
  201. while(list($id, $name) = mysql_fetch_row($query)) {
  202. return $name;
  203. }
  204. endif;
  205. }
  206. function getProjectHourlyRate($id) {
  207. $sql = "SELECT id, project_hourly_rate FROM projects WHERE id='" . $id . "'";
  208. $query = mysql_query($sql) or die("getProjectHourlyRate function: " . mysql_error());
  209. $numrows = mysql_num_rows($query);
  210. if($numrows):
  211. while(list($id, $rate) = mysql_fetch_row($query)) {
  212. return $rate;
  213. }
  214. endif;
  215. }
  216. function getProjectID($id) {
  217. $sql = "SELECT id, projectid FROM tasks WHERE id='" . $id . "'";
  218. $query = mysql_query($sql) or die("getProjectID function: " . mysql_error());
  219. $numrows = mysql_num_rows($query);
  220. if($numrows):
  221. while(list($id, $projectid) = mysql_fetch_row($query)) {
  222. return $projectid;
  223. }
  224. endif;
  225. }
  226. function getProjectIDfromHourID($id) {
  227. $sql = "SELECT projects.id
  228. FROM projects, tasks, hours
  229. WHERE hours.id='" . $id . "'
  230. AND hours.taskid=tasks.id
  231. AND tasks.projectid=projects.id";
  232. $query = mysql_query($sql) or die("getProjectIDfromHourID function: " . mysql_error());
  233. $numrows = mysql_num_rows($query);
  234. if($numrows):
  235. while(list($projectid) = mysql_fetch_row($query)) {
  236. return $projectid;
  237. }
  238. endif;
  239. }
  240. function setProjectName($taskid, $newvalue) {
  241. $sql = "SELECT tasks.`id`,
  242. tasks.`projectid`
  243. FROM tasks
  244. WHERE tasks.`id`='" . $taskid . "'";
  245. $query = mysql_query($sql) or die("setProjectName function: " . mysql_error());
  246. $numrows = mysql_num_rows($query);
  247. if($numrows):
  248. while(list($id, $projectid) = mysql_fetch_row($query)) {
  249. $update_project_sql = "UPDATE tasks
  250. SET projectid='" . $newvalue . "'
  251. WHERE id='" . $taskid . "'";
  252. $update_project_query = mysql_query($update_project_sql) or die(mysql_error());
  253. $project_sql = "SELECT project_name FROM projects WHERE id='" . $newvalue . "'";
  254. $project_query = mysql_query($project_sql) or die("setProjectName function 2: " . mysql_error());
  255. while(list($project_name) = mysql_fetch_row($project_query)) {
  256. return $project_name;
  257. }
  258. }
  259. endif;
  260. }
  261. function getUserID() {
  262. $sql = "SELECT id FROM users WHERE username='" . $_SESSION['username_auth'] . "'";
  263. $query = mysql_query($sql) or die("getUserID function: " . mysql_error());
  264. $numrows = mysql_num_rows($query);
  265. if($numrows):
  266. while(list($user_id) = mysql_fetch_row($query)) {
  267. return $user_id;
  268. }
  269. endif;
  270. }
  271. function getCurrentUserAccessLevel() {
  272. if(isset($_SESSION['username_auth'])) {
  273. $sql = "SELECT level FROM users WHERE username='" . $_SESSION['username_auth'] . "'";
  274. $query = mysql_query($sql) or die("getCurrentUserAccessLevel function: " . mysql_error());
  275. $numrows = mysql_num_rows($query);
  276. if($numrows):
  277. while(list($level) = mysql_fetch_row($query)) {
  278. return $level;
  279. }
  280. endif;
  281. }
  282. }
  283. function getCurrentUserGroupID() {
  284. if(isset($_SESSION['username_auth'])) {
  285. $sql = "SELECT groupid FROM users WHERE username='" . $_SESSION['username_auth'] . "'";
  286. $query = mysql_query($sql) or die("getCurrentUserGroupID function: " . mysql_error());
  287. $numrows = mysql_num_rows($query);
  288. if($numrows):
  289. while(list($level) = mysql_fetch_row($query)) {
  290. return $level;
  291. }
  292. endif;
  293. }
  294. }
  295. function getAclName($level) {
  296. $sql = "SELECT name FROM acl WHERE level='" . $level . "'";
  297. $query = mysql_query($sql) or die("getAclName function: " . mysql_error());
  298. $numrows = mysql_num_rows($query);
  299. if($numrows):
  300. while(list($name) = mysql_fetch_row($query)) {
  301. return $name;
  302. }
  303. endif;
  304. }
  305. function getGroupName($groupid) {
  306. $sql = "SELECT name FROM groups WHERE id='" . $groupid . "'";
  307. $query = mysql_query($sql) or die("getGroupName function: " . mysql_error());
  308. $numrows = mysql_num_rows($query);
  309. if($numrows):
  310. while(list($name) = mysql_fetch_row($query)) {
  311. return $name;
  312. }
  313. endif;
  314. }
  315. function getAccessLevelName($level) {
  316. $sql = "SELECT name FROM acl WHERE level='" . $level . "'";
  317. $query = mysql_query($sql) or die("getAccessLevelName function: " . mysql_error());
  318. $numrows = mysql_num_rows($query);
  319. if($numrows):
  320. while(list($name) = mysql_fetch_row($query)) {
  321. return $name;
  322. }
  323. endif;
  324. }
  325. function createSalt() {
  326. $string = md5(uniqid(rand(), true));
  327. return substr($string, 0, 3);
  328. }
  329. function getUsernameByID($user_id) {
  330. $sql = "SELECT username
  331. FROM users
  332. WHERE id = '" . $user_id . "'";
  333. $query = mysql_query($sql) or die("getUsernameByID function: " . mysql_error());
  334. $numrows = mysql_num_rows($query);
  335. if($numrows):
  336. while(list($username) = mysql_fetch_row($query)) {
  337. return $username;
  338. }
  339. endif;
  340. }
  341. function getGroupsDropdown($level_auth) {
  342. if($level_auth == "11"):
  343. $sql = "SELECT id, name
  344. FROM groups
  345. ORDER BY name";
  346. $query = mysql_query($sql) or die("getGroupsDropdown function: " . mysql_error());
  347. $numrows = mysql_num_rows($query);
  348. if($numrows):
  349. while(list($id, $name) = mysql_fetch_row($query)) {
  350. $options[] = '<option value="'.$id.'">'.$name.'</option>'."\n";
  351. }
  352. return $options;
  353. endif;
  354. endif;
  355. }
  356. function getClientsDropdown($level_auth) {
  357. $sql = "SELECT id, fullname
  358. FROM clients
  359. ORDER BY fullname";
  360. $query = mysql_query($sql) or die("getClientsDropdown function: " . mysql_error());
  361. $numrows = mysql_num_rows($query);
  362. if($numrows):
  363. while(list($id, $name) = mysql_fetch_row($query)) {
  364. $options[] = '<option value="'.$id.'">'.$name.'</option>'."\n";
  365. }
  366. return $options;
  367. endif;
  368. }
  369. function getProjectsDropdown($seldb) {
  370. $projects_sql = "SELECT id, project_name
  371. FROM projects
  372. ORDER BY project_name ASC";
  373. $projects_query = mysql_query($projects_sql) or die("getProjectsDropdown function: " . mysql_error());
  374. $numrows = mysql_num_rows($projects_query);
  375. if($numrows):
  376. while(list($id, $name) = mysql_fetch_row($query)) {
  377. $options[] = '<option value="'.$id.'">'.$name.'</option>'."\n";
  378. }
  379. return $options;
  380. else:
  381. return array('TEST');
  382. endif;
  383. }
  384. function getUsersDropdown($level_auth, $group_auth) {
  385. $sql = "SELECT id, username
  386. FROM users
  387. ORDER BY username ASC";
  388. $query = mysql_query($sql) or die("getUsersDropdown function: " . mysql_error());
  389. $numrows = mysql_num_rows($query);
  390. if($numrows):
  391. while(list($id, $name) = mysql_fetch_row($query)) {
  392. $options[] = '<option value="'.$id.'">'.$name.'</option>'."\n";
  393. }
  394. return $options;
  395. endif;
  396. }
  397. function getClientGroupID($clientid) {
  398. $sql = "SELECT users.groupid
  399. FROM users, clients
  400. WHERE clients.userid=users.id
  401. AND clients.id='" . $clientid . "'";
  402. $query = mysql_query($sql) or die("getClientGroupID function: " . mysql_error());
  403. $numrows = mysql_num_rows($query);
  404. if($numrows):
  405. while(list($groupid) = mysql_fetch_row($query)) {
  406. return $groupid;
  407. }
  408. endif;
  409. }
  410. function getSetting($name, $userid) {
  411. $sql = "SELECT name, value
  412. FROM settings
  413. WHERE name='" . $name . "'
  414. AND userid='" . $userid . "'";
  415. $query = mysql_query($sql) or die("getSetting function: " . mysql_error());
  416. $numrows = mysql_num_rows($query);
  417. if($numrows):
  418. while(list($name, $value) = mysql_fetch_row($query)) {
  419. return $value;
  420. }
  421. else:
  422. return "0";
  423. endif;
  424. }
  425. function checkSetting($name, $userid) {
  426. $sql = "SELECT `name`, `value` FROM `settings`
  427. WHERE userid='" . $userid . "'
  428. AND name='" . $name . "'";
  429. $query = mysql_query($sql) or die("checkSetting function: " . mysql_error());
  430. $numrows = mysql_num_rows($query);
  431. if($numrows):
  432. while(list($name, $value) = mysql_fetch_row($query)) {
  433. return "1";
  434. }
  435. else:
  436. return "0";
  437. endif;
  438. }
  439. function insertSetting($name, $value, $userid) {
  440. $sql = "INSERT INTO `settings` (
  441. `name`,
  442. `value`,
  443. `userid`
  444. ) VALUES (
  445. '" . $name . "',
  446. '" . $value . "',
  447. '" . $userid . "'
  448. )";
  449. $query = mysql_query($sql) or die("insertSetting function: " . mysql_error());
  450. }
  451. function updateSetting($name, $value, $userid) {
  452. $sql = "UPDATE `settings`
  453. SET `name`='" . $name . "',
  454. `value`='" . $value . "',
  455. `userid`='" . $userid . "'
  456. WHERE userid='" . $userid . "'
  457. AND name='" . $name . "'";
  458. $query = mysql_query($sql) or die("updateSetting function: " . mysql_error());
  459. }
  460. function getStatesDropdown($level_auth) {
  461. ?>
  462. <option value="AL">Alabama</option>
  463. <option value="AK">Alaska</option>
  464. <option value="AZ">Arizona</option>
  465. <option value="AR">Arkansas</option>
  466. <option value="CA">California</option>
  467. <option value="CO">Colorado</option>
  468. <option value="CT">Connecticut</option>
  469. <option value="DE">Delaware</option>
  470. <option value="DC">District of Columbia</option>
  471. <option value="FL">Florida</option>
  472. <option value="GA">Georgia</option>
  473. <option value="HI">Hawaii</option>
  474. <option value="ID">Idaho</option>
  475. <option value="IL">Illinois</option>
  476. <option value="IN">Indiana</option>
  477. <option value="IA">Iowa</option>
  478. <option value="KS">Kansas</option>
  479. <option value="KY">Kentucky</option>
  480. <option value="LA">Louisiana</option>
  481. <option value="ME">Maine</option>
  482. <option value="MD">Maryland</option>
  483. <option value="MA">Massachusetts</option>
  484. <option value="MI">Michigan</option>
  485. <option value="MN">Minnesota</option>
  486. <option value="MS">Mississippi</option>
  487. <option value="MO">Missouri</option>
  488. <option value="MT">Montana</option>
  489. <option value="NE">Nebraska</option>
  490. <option value="NV">Nevada</option>
  491. <option value="NH">New Hampshire</option>
  492. <option value="NJ">New Jersey</option>
  493. <option value="NM">New Mexico</option>
  494. <option value="NY">New York</option>
  495. <option value="NC">North Carolina</option>
  496. <option value="ND">North Dakota</option>
  497. <option value="OH">Ohio</option>
  498. <option value="OK">Oklahoma</option>
  499. <option value="OR">Oregon</option>
  500. <option value="PA">Pennsylvania</option>
  501. <option value="RI">Rhode Island</option>
  502. <option value="SC">South Carolina</option>
  503. <option value="SD">South Dakota</option>
  504. <option value="TN">Tennessee</option>
  505. <option value="TX">Texas</option>
  506. <option value="UT">Utah</option>
  507. <option value="VT">Vermont</option>
  508. <option value="VA">Virginia</option>
  509. <option value="WA">Washington</option>
  510. <option value="WV">West Virginia</option>
  511. <option value="WI">Wisconsin</option>
  512. <option value="WY">Wyoming</option>
  513. <?php
  514. }
  515. function getAccessLevelsDropdown() {
  516. $sql = "SELECT level, name
  517. FROM acl
  518. WHERE level != '11'";
  519. $query = mysql_query($sql) or die("getAccessLevelsDropdown function: " . mysql_error());
  520. $numrows = mysql_num_rows($query);
  521. if($numrows):
  522. while(list($level, $name) = mysql_fetch_row($query)) {
  523. $options[] = '<option value="'.$level.'">'.$name.'</option>'."\n";
  524. }
  525. return $options;
  526. endif;
  527. }
  528. function checkAlias($alias, $withssl) {
  529. $sql = "SELECT directives.id AS alias_id,
  530. directives.value AS alias,
  531. directives.withssl AS withssl
  532. FROM directives
  533. WHERE value = '" . $alias . "'
  534. AND name='ServerAlias'
  535. AND withssl = '" . $withssl . "'";
  536. $query = mysql_query($sql) or die("checkAlias function: " . mysql_error());
  537. $numrows = mysql_num_rows($query);
  538. if($numrows) return true;
  539. }
  540. function convertDate($date) {
  541. $parts = explode("/", $date);
  542. $month = $parts[0];
  543. $day = $parts[1];
  544. $year = $parts[2];
  545. return $year."-".$month."-".$day;
  546. }
  547. function formatWebsite($website) {
  548. if(substr($website, 0, 7) != "http://"):
  549. $return = "http://" . $website;
  550. else:
  551. $return = $website;
  552. endif;
  553. return $return;
  554. }
  555. // trim inputted phone numbers
  556. function trimPhone($phone) {
  557. $return = onlyNumbers($phone);
  558. if(substr($return, 0, 1) == "1"):
  559. $return = substr($return, 1, strlen($return));
  560. endif;
  561. if(strlen($return) > "10"):
  562. $return = substr($return, 0, 10);
  563. endif;
  564. return $return;
  565. }
  566. function trimExt($ext) {
  567. return onlyNumbers($ext);
  568. }
  569. function onlyNumbers($number) {
  570. $return = preg_replace('/[^0-9]/', '', $number);
  571. return $return;
  572. }
  573. // display/print phone numbers to the user
  574. function printPhone($phone) {
  575. $areacode = substr($phone, 0, 3);
  576. $prefix = substr($phone, 3, 3);
  577. $suffix = substr($phone, 6, 4);
  578. $return = "(" . $areacode . ") " . $prefix . "-" . $suffix;
  579. return $return;
  580. }
  581. function createThumbs( $pathToImages, $thumbWidth ) {
  582. $pathToThumbs = $pathToImages . "thumbs/";
  583. // open the directory
  584. $dir = opendir( $pathToImages );
  585. // loop through it, looking for any/all JPG files:
  586. while (false !== ($fname = readdir( $dir ))) {
  587. // parse path for the extension
  588. $info = pathinfo($pathToImages . $fname);
  589. // continue only if this is a JPEG image
  590. if ( strtolower($info['extension']) == 'jpg' ) {
  591. // load image and get image size
  592. $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
  593. $width = imagesx( $img );
  594. $height = imagesy( $img );
  595. // calculate thumbnail size
  596. $new_width = $thumbWidth;
  597. $new_height = floor( $height * ( $thumbWidth / $width ) );
  598. // create a new temporary image
  599. $tmp_img = imagecreatetruecolor( $new_width, $new_height );
  600. // copy and resize old image into new image
  601. imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
  602. // create variable for new file name
  603. // save thumbnail into a file
  604. imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
  605. }
  606. }
  607. // close the directory
  608. closedir( $dir );
  609. }
  610. function recursiveDelete($str){
  611. if(is_file($str)){
  612. return @unlink($str);
  613. } elseif(is_dir($str)){
  614. $scan = glob(rtrim($str,'/').'/*');
  615. foreach($scan as $index=>$path){
  616. recursiveDelete($path);
  617. }
  618. return @rmdir($str);
  619. }
  620. }
  621. function validate_email($Email) {
  622. global $HTTP_HOST;
  623. $result = array();
  624. if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) {
  625. $result[0]=false;
  626. $result[1]="$Email is not properly formatted";
  627. return $result;
  628. }
  629. list ( $Username, $Domain ) = split ("@",$Email);
  630. if (getmxrr($Domain, $MXHost)) {
  631. $ConnectAddress = $MXHost[0];
  632. } else {
  633. $ConnectAddress = $Domain;
  634. }
  635. $Connect = fsockopen ( $ConnectAddress, 25 );
  636. if ($Connect) {
  637. if (ereg("^220", $Out = fgets($Connect, 1024))) {
  638. fputs ($Connect, "HELO $HTTP_HOST\r\n");
  639. $Out = fgets ( $Connect, 1024 );
  640. fputs ($Connect, "MAIL FROM: <{$Email}>\r\n");
  641. $From = fgets ( $Connect, 1024 );
  642. fputs ($Connect, "RCPT TO: <{$Email}>\r\n");
  643. $To = fgets ($Connect, 1024);
  644. fputs ($Connect, "QUIT\r\n");
  645. fclose($Connect);
  646. if (!ereg ("^250", $From) || !ereg ( "^250", $To )) {
  647. $result[0]=false;
  648. $result[1]="Server rejected address";
  649. return $result;
  650. }
  651. } else {
  652. $result[0] = false;
  653. $result[1] = "No response from server";
  654. return $result;
  655. }
  656. } else {
  657. $result[0]=false;
  658. $result[1]="Can not connect E-Mail server.";
  659. return $result;
  660. }
  661. $result[0]=true;
  662. $result[1]="$Email appears to be valid.";
  663. return $result;
  664. } // end of validate_email() function
  665. function blacklist_check() {
  666. return '<p>This search feature is still under development.</p>';
  667. } // end of blacklist_check() function
  668. /* EMAIL FUNCTIONS */
  669. function customEmailHeader() {
  670. $return_header = '
  671. <html>
  672. <head>
  673. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  674. <title>WebSight Designs Invoice</title>
  675. <link rel="stylesheet" type="text/css" href="http://manage.websightdesigns.com/css/email.css">
  676. </head>
  677. <body bgcolor="#eeeeee">
  678. <table border="0" width="100%" border="0" cellspacing="0" cellpadding="0" class="bg1">
  679. <tr>
  680. <td align="center">
  681. <table width="600" border="0" cellspacing="0" cellpadding="0" class="bg2">
  682. <tr>
  683. <td class="header" align="left">
  684. <img src="http://websightdesigns.com/scripts/header.gif" alt="WebSight Designs Invoice" width="600" height="107" />
  685. </td>
  686. </tr>
  687. <tr>
  688. <td valign="top" class="body">
  689. ';
  690. return $return_header;
  691. }
  692. function customEmailFooter($invoice_id, $comments) {
  693. $return_footer = '';
  694. if($comments) $return_footer .= '<p style="font-size: 12px;">' . $comments . '</p>';
  695. $return_footer .= '
  696. <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>
  697. </td>
  698. </tr>
  699. <tr>
  700. <td valign="middle" align="left" class="footer" height="72">
  701. <p>361 S. Camino Del Rio, Durango, CO 81303. 970-239-1247<br /><br />
  702. <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>
  703. </td>
  704. </tr>
  705. </table>
  706. </td>
  707. </tr>
  708. </table>
  709. </body>
  710. </html>
  711. ';
  712. return $return_footer;
  713. }
  714. function invoicesEmailTextBody() {
  715. return 'Please call if you have any questions at 970-239-1247
  716. Technical Support: support@websightdesigns.com
  717. ';
  718. }
  719. function sendInvoice($invoice_id, $comments) {
  720. // send an invoice
  721. $invoice_sql = "SELECT clientid FROM invoices WHERE id='".$invoice_id."'";
  722. $invoice_query = mysql_query($invoice_sql) or die(mysql_error());
  723. while(list($clientid) = mysql_fetch_row($invoice_query)):
  724. $customer = $clientid;
  725. endwhile;
  726. $customers_sql = "SELECT `id`,
  727. `fullname`,
  728. `company`,
  729. `email`,
  730. `phone`,
  731. `phone_ext`,
  732. `address`,
  733. `city`,
  734. `state`,
  735. `zipcode`,
  736. `cc_fullname`,
  737. `cc_company`,
  738. `cc_email`,
  739. `cc_phone`,
  740. `cc_phone_ext`,
  741. `cc_address`,
  742. `cc_city`,
  743. `cc_state`,
  744. `cc_zipcode`,
  745. `cc_type`,
  746. `cc_number`,
  747. `cc_expire`,
  748. `ownerid`,
  749. `userid`,
  750. `created`,
  751. `sort`
  752. FROM clients
  753. WHERE id='" . $customer . "'";
  754. #echo $customers_sql . "<br />";
  755. $customers_query = mysql_query($customers_sql) or die(mysql_error());
  756. 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)):
  757. // for each customer (there is only one though) now check to see if there are any
  758. // outstanding invoices
  759. $invoices_sql = "SELECT id,
  760. hours,
  761. title,
  762. amount_due,
  763. amount_paid,
  764. DATE_FORMAT(`created`, '%b %e, %Y') AS `created`,
  765. sent,
  766. duedate,
  767. clientid,
  768. projectid
  769. FROM invoices
  770. WHERE clientid='" . $customer . "'
  771. AND amount_paid < amount_due";
  772. //echo $invoices_sql . "<br />";
  773. $invoices_query = mysql_query($invoices_sql) or die(mysql_error());
  774. $invoices_count = mysql_num_rows($invoices_query);
  775. if($invoices_count):
  776. // SET UP THE TEXT VERSION
  777. $text_message = 'Invoice from WebSight Designs
  778. This is an invoice for services rendered by WebSight Designs, Inc.
  779. Please enable HTML emails so you may see the contents of this invoice.
  780. If you cannot enable HTML in your email client, please contact us at 970-239-1247 to discuss payment options.
  781. ';
  782. // SET UP THE HTML VERSION
  783. $html_message = customEmailHeader();
  784. $html_message .= '
  785. <table bgcolor="#FFFFFF" width="100%" border="0" cellspacing="0" cellpadding="3">
  786. <tr>
  787. <td id="content" valign="top" class="mainbar" align="left">
  788. <div id="billinginfo">
  789. <h1 style="color: #333333; font-size: 13px;">Billing Information</h1>
  790. <p>' . $cc_fullname . '<br />
  791. '; if($cc_company) $html_message .= $cc_company . '<br />'; $html_message .= '
  792. '; if($cc_address) $html_message .= $cc_address . '<br />';
  793. if($cc_city) $html_message .= $cc_city . ', ';
  794. if($cc_state) $html_message .= $cc_state . ' ';
  795. if($cc_zipcode) $html_message .= sprintf("%05d",$cc_zipcode);
  796. if($cc_zipcode_ext) $html_message .= '-'.sprintf("%04d",$cc_zipcode_ext);
  797. if($cc_city || $cc_state || $cc_zipcode) $html_message .= '<br />';
  798. $html_message .= '<br />
  799. '; if($cc_phone) { $html_message .= printPhone($cc_phone); if($cc_phone_ext) $html_message .= 'ext. ' . $cc_phone_ext; }
  800. $html_message .= '</p>
  801. </div>
  802. <div id="companyinfo">
  803. <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>
  804. <p>WebSight Designs<br />
  805. 5100 Leetsdale Dr., #423<br />
  806. Denver, CO 80246<br /><br />
  807. (970) 239-1247</p>
  808. </div>
  809. <div id="invoiceinfo">
  810. <table id="inner" border="0" cellspacing="0" cellpadding="3" summary="">
  811. <tr style="background-color: #333333; font-size: 13px;">
  812. <th width="10%">Invoice</th>
  813. <th width="24%">Date</th>
  814. <th width="42%">Description</th>
  815. <th width="12%" style="text-align: center;">Fee</th>
  816. <th width="12%" style="text-align: center;" class="last">Amount Due</th>
  817. </tr>
  818. ';
  819. $total_amount_due = 0;
  820. $altrows = 0;
  821. while(list($invoice_id, $hours, $title, $amount_due, $amount_paid, $created, $sent, $duedate, $clientid, $projectid) = mysql_fetch_row($invoices_query)):
  822. $hourly_rate = getProjectHourlyRate($projectid);
  823. $total_amount_due += sprintf("%01.2f", $amount_due - $amount_paid);
  824. $total_hours_worked = $amount_due / $hourly_rate;
  825. $project_name = getProjectName($projectid);
  826. if($hours) {
  827. $hoursids = explode(",", $hours);
  828. foreach($hoursids AS $hourid) {
  829. if($hourid) {
  830. $sql = "SELECT tasks.`task_title`,
  831. hours.`duration`,
  832. DATE_FORMAT(hours.`clock_out`, '%b %e, %Y') AS `clock_out`
  833. FROM hours, tasks
  834. WHERE hours.userid='" . $_SESSION['userid_auth'] . "'
  835. AND hours.id='".$hourid."'
  836. AND hours.`taskid`=tasks.`id`";
  837. $q = mysql_query($sql);
  838. while($i = mysql_fetch_object($q)) {
  839. $task_title = $i->task_title;
  840. $duration = $i->duration;
  841. $time = explode(":", $duration);
  842. $hours = ltrim($time[0], "0");
  843. $mins = ltrim($time[1], "0");
  844. if($mins > "15") $hours += "1";
  845. $cur_amount_due = $hours * $hourly_rate;
  846. // add invoice list to html email message
  847. if($hours) {
  848. $text_message .= '- ' . $task_title . "\n";
  849. $html_message .= '<tr style="font-size: 13px;">
  850. <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">' . sprintf("%05d",$invoice_id) . '</td>
  851. <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">' . $created . '</td>
  852. <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>
  853. <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>
  854. <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>
  855. </tr>';
  856. $altrows++;
  857. }
  858. }
  859. }
  860. }
  861. } else { // hours field is blank, so use title field instead
  862. $text_message .= '- '; if($title) $text_message .= $title; else $text_message .= "Website Design Work"; $html_message .= "\n";
  863. $html_message .= '<tr style="font-size: 13px;">
  864. <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">' . sprintf("%05d",$invoice_id) . '</td>
  865. <td style="text-align: left; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '">' . $created . '</td>
  866. <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>
  867. <td style="text-align: center; vertical-align: top;'; if($altrows % 2 == 0) $html_message .= ' background-color: #eeeeee;'; $html_message .= '" align="right">$' . $amount_due . '</td>
  868. <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>
  869. </tr>';
  870. $altrows++;
  871. } // end if($hours)
  872. // mark invoice as sent
  873. $update_sent_sql = "UPDATE invoices SET sendcount=sendcount+1, sent=NOW() WHERE id='" . $invoice_id . "'";
  874. $update_sent_query = mysql_query($update_sent_sql) or die(mysql_error());
  875. endwhile;
  876. $html_message .= '
  877. <tr>
  878. <td style="font-size: 14px; background-color: #e6e6e6;" colspan="4">Total Amount Due</td>
  879. <td style="font-size: 14px; background-color: #e6e6e6; text-align: right;" class="last" align="right">$' . $total_amount_due . '</td>
  880. </tr>
  881. </table>
  882. </div>
  883. </td>
  884. </tr>
  885. </table>
  886. ';
  887. $html_message .= customEmailFooter(sprintf("%05d",$invoice_id), $comments);
  888. $text_message .= 'Amount Due: ' . $total_amount_due . "\n";
  889. $text_message .= 'Please mail a check made out to Gregory Burga to the following address:
  890. WebSight Designs
  891. 5100 Leetsdale Dr., #423
  892. Denver, CO 80246
  893. Or you may pay online at http://www.websightdesigns.com/payments/
  894. Please call if you have any questions at 970-239-1247
  895. Technical Support: http://www.websightdesigns.com/contact/ or support@websightdesigns.com
  896. ';
  897. // send the email
  898. include('Mail.php');
  899. include('Mail/mime.php');
  900. $message = new Mail_mime("\n");
  901. $message->setTXTBody($text_message);
  902. $message->setHTMLBody($html_message);
  903. $body = $message->get();
  904. $extraheaders = array("From"=>"invoices@websightdesigns.com", "Subject"=>"WebSight Designs Invoice");
  905. $headers = $message->headers($extraheaders);
  906. $mail = Mail::factory("mail");
  907. // send email to customer
  908. $mail->send($cc_email, $headers, $body);
  909. // send a copy to invoices email
  910. $mail->send("invoices@websightdesigns.com", $headers, $body);
  911. // print result into browser window for debugging
  912. echo 'E-mailed an invoice to ' . $cc_email . "\n";
  913. // END HTML EMAIL
  914. else:
  915. ?>There are currently no invoices scheduled to be sent to this customer.<?php
  916. endif; // end if($invoices_count)
  917. endwhile;
  918. }
  919. function dbug($var, $name, $debugmode) {
  920. if($debugmode) {
  921. ob_start();
  922. echo '<p>' . $name . ':</p>';
  923. echo '<pre>';
  924. var_dump($var);
  925. echo '</pre>';
  926. $dump = ob_get_clean();
  927. print $dump;
  928. }
  929. }
  930. /* COMMAND RESULTS */
  931. function display_command_results($action) {
  932. $obj = json_decode($_SESSION["command_results"][$action]);
  933. $total = $obj->{'total'};
  934. $return = '';
  935. for($i = 0; $i < $total; $i++):
  936. $code = $obj->{$i}->{'code'};
  937. if($code == "0") $image = "info";
  938. elseif($code == -1) $image = "alert";
  939. else $image = "subtract";
  940. $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" />';
  941. endfor;
  942. $_SESSION["command_results"][$action] = "";
  943. print $return;
  944. }
  945. ?>