PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/programs/includefiles/init.php

https://github.com/damanlovett/SEAHO
PHP | 567 lines | 338 code | 164 blank | 65 comment | 50 complexity | ea68a37477ab095fe803bd310f651bcc MD5 | raw file
  1. <?php
  2. ob_start();
  3. session_start();
  4. $systemDate = date ("Y-m-d G:i:s");
  5. $currentDate = date('Y-m-d');
  6. # FileName="Connection_php_mysql.htm"
  7. # Type="MYSQL"
  8. # HTTP="true"
  9. $hostname_Programming = "db101.perfora.net";
  10. $database_Programming = "db251380847";
  11. $username_Programming = "dbo251380847";
  12. $password_Programming = "fwu8mPPV";
  13. $Programming = mysql_pconnect($hostname_Programming, $username_Programming, $password_Programming) or trigger_error(mysql_error(),E_USER_ERROR);
  14. ////// TESTING SESSIONS /////////
  15. //$_SESSION['userID'] = "c2fa9886-f81d-5d31-9ace-461d39b39d4e";
  16. //$_SESSION['first_name'] = "Eddie";
  17. //$_SESSION['last_name'] = "Lovett";
  18. //$_SESSION['access'] = 1;
  19. //$_SESSION['group'] = "Academic Initiatives and Partnerships";
  20. // Magic Quotes - This is the normal magic quotes that Dreamweaver adds to pages with recordsets
  21. if (!function_exists("GetSQLValueString")) {
  22. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  23. {
  24. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  25. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  26. switch ($theType) {
  27. case "text":
  28. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  29. break;
  30. case "long":
  31. case "int":
  32. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  33. break;
  34. case "double":
  35. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  36. break;
  37. case "date":
  38. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  39. break;
  40. case "defined":
  41. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  42. break;
  43. }
  44. return $theValue;
  45. }
  46. }
  47. // Check for Access Point
  48. if($_SESSION['accesspoint']!="Seaho Programming") {
  49. session_destroy();
  50. header ("Location: /programs/admin/login.php");
  51. exit;
  52. }
  53. if(!isset($_SESSION['sitename'])){
  54. if (isset($_SESSION['accesspoint'])) {
  55. $colname_rsSystemConfiguration = (get_magic_quotes_gpc()) ? $_SESSION['accesspoint'] : addslashes($_SESSION['accesspoint']);
  56. }
  57. mysql_select_db($database_Programming, $Programming);
  58. $query_rsSystemConfiguration = sprintf("SELECT * FROM sys_configuration WHERE sitename = %s", GetSQLValueString($colname_rsSystemConfiguration, "text"));
  59. $rsSystemConfiguration = mysql_query($query_rsSystemConfiguration, $Programming) or die(mysql_error());
  60. $row_rsSystemConfiguration = mysql_fetch_assoc($rsSystemConfiguration);
  61. $totalRows_rsSystemConfiguration = mysql_num_rows($rsSystemConfiguration);
  62. $_SESSION['systemStatus'] = $row_rsSystemConfiguration['status'];
  63. $_SESSION['systemSitename'] = $row_rsSystemConfiguration['sitename'];
  64. $_SESSION['systemSupportEmail'] = $row_rsSystemConfiguration['supportemail'];
  65. $_SESSION['systemVersion'] = $row_rsSystemConfiguration['sysVersion'];
  66. $_SESSION['systemCreation'] = $row_rsSystemConfiguration['sysCreation'];
  67. $_SESSION['systemContract'] = $row_rsSystemConfiguration['sysContract'];
  68. $_SESSION['systemOperator'] = $row_rsSystemConfiguration['sysOperator'];
  69. $_SESSION['systemLiaison'] = $row_rsSystemConfiguration['sysLiaison'];
  70. $_SESSION['systemRoot'] = $row_rsSystemConfiguration['sysRoot'];
  71. $_SESSION['systemFileRoot'] = $row_rsSystemConfiguration['sysFileRoot'];
  72. $_SESSION['systemDescription'] = $row_rsSystemConfiguration['sysDescription'];
  73. }
  74. // Assign User Information
  75. if ((isset($_POST['user'])) && (isset($_POST['password']))) {
  76. $colname_rsUserInfo = "-1";
  77. if (isset($_POST['user'])) {
  78. $colname_rsUserInfo = $_POST['user'];
  79. }
  80. $colname2_rsUserInfo = "-1";
  81. if (isset($_POST['password'])) {
  82. $colname2_rsUserInfo = $_POST['password'];
  83. }
  84. mysql_select_db($database_Programming, $Programming);
  85. $query_rsUserInfo = sprintf("SELECT * FROM users WHERE email = %s AND users.password = %s AND 'delete' = 0", GetSQLValueString($colname_rsUserInfo, "text"),GetSQLValueString($colname2_rsUserInfo, "text"));
  86. $rsUserInfo = mysql_query($query_rsUserInfo, $Programming) or die(mysql_error());
  87. $row_rsUserInfo = mysql_fetch_assoc($rsUserInfo);
  88. $totalRows_rsUserInfo = mysql_num_rows($rsUserInfo);
  89. //User is not in the system
  90. if($totalRows_rsUserInfo == '0') {
  91. header ("Location: /programs/admin/login.php?error=4");
  92. exit;
  93. }
  94. //User is not active
  95. if($row_rsUserInfo['active'] != '1') {
  96. header ("Location: /programs/admin/login.php?error=3");
  97. exit;
  98. }
  99. //User is in the system
  100. if($totalRows_rsUserInfo == '1') {
  101. $_SESSION['userID'] = $row_rsUserInfo['userID'];
  102. $_SESSION['first_name'] = $row_rsUserInfo['first_name'];
  103. $_SESSION['last_name'] = $row_rsUserInfo['last_name'];
  104. $_SESSION['display_name'] = $row_rsUserInfo['first_name']." ".$row_rsUserInfo['last_name'];
  105. $_SESSION['email'] = $row_rsUserInfo['email'];
  106. $_SESSION['access'] = $row_rsUserInfo['access'];
  107. $_SESSION['group'] = $row_rsUserInfo['group'];
  108. // recordset for voting
  109. //$colname_rsVotes = "-1";
  110. //if (isset($_SESSION['userID'])) {
  111. // $colname_rsVotes = $_SESSION['userID'];
  112. //}
  113. //mysql_select_db($database_Directory, $Directory);
  114. //$query_rsVotes = sprintf("SELECT id, position_id, user_id, votes FROM team_positions WHERE user_id = %s AND votes = 1", GetSQLValueString($colname_rsVotes, "text"));
  115. //$rsVotes = mysql_query($query_rsVotes, $Directory) or die(mysql_error());
  116. //$row_rsVotes = mysql_fetch_assoc($rsVotes);
  117. //$totalRows_rsVotes = mysql_num_rows($rsVotes);
  118. //
  119. //$_SESSION['votes'] = $row_rsVotes['votes'];
  120. // Check for session still live
  121. if(!isset($_SESSION['access'])) {
  122. header ("Location: /programs/admin/login.php");
  123. exit;
  124. }
  125. // Members - login record
  126. $insertOnline = sprintf("INSERT INTO loginrecord (id, username, ip_address) VALUES (%s, %s, %s)",
  127. GetSQLValueString($_POST['id'], "int"),
  128. GetSQLValueString($_SESSION['userID'], "text"),
  129. GetSQLValueString($_SERVER['REMOTE_ADDR'], "text"));
  130. mysql_select_db($database_Programming, $Programming);
  131. $ResultOnline = mysql_query($insertOnline, $Programming) or die(mysql_error());
  132. }
  133. }
  134. // ** Logout the current user. **
  135. $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
  136. if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  137. $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
  138. }
  139. if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  140. //Delete them from online database
  141. //$deleteSQL = sprintf("DELETE FROM online_report WHERE user_id=%s",
  142. // GetSQLValueString($_SESSION['userID'], "text"));
  143. // mysql_select_db($database_Directory, $Directory);
  144. // $Resultdelete = mysql_query($deleteSQL, $Directory) or die(mysql_error());
  145. //to fully log out a visitor we need to clear the session varialbles
  146. $_SESSION['MM_Username'] = NULL;
  147. $_SESSION['MM_UserGroup'] = NULL;
  148. $_SESSION['PrevUrl'] = NULL;
  149. unset($_SESSION['MM_Username']);
  150. unset($_SESSION['MM_UserGroup']);
  151. unset($_SESSION['PrevUrl']);
  152. session_destroy();
  153. $logoutGoTo = "/programs/admin/login.php?error=1";
  154. if ($logoutGoTo) {
  155. header("Location: $logoutGoTo");
  156. exit;
  157. }
  158. }
  159. // Delete record - sets the delete field to 1
  160. function DeleteRecord($table,$tableID){
  161. global $database_Programming;
  162. global $Programming;
  163. if ((isset($_GET['delete'])) && ($_GET['delete'] != "")) {
  164. $deleteSQL = sprintf("UPDATE $table SET `delete`= 1 WHERE $tableID=%s",
  165. GetSQLValueString($_GET['delete'], "text"));
  166. mysql_select_db($database_Programming, $Programming);
  167. $Result1 = mysql_query($deleteSQL, $Programming) or die(mysql_error());
  168. }
  169. }
  170. // unDelete record - sets the delete field to 0
  171. function unDeleteRecord($table,$tableID){
  172. global $database_Programming;
  173. global $Programming;
  174. if ((isset($_GET['undelete'])) && ($_GET['undelete'] != "")) {
  175. $deleteSQL = sprintf("UPDATE $table SET `delete`= 0 WHERE $tableID=%s",
  176. GetSQLValueString($_GET['undelete'], "text"));
  177. mysql_select_db($database_Programming, $Programming);
  178. $Result1 = mysql_query($deleteSQL, $Programming) or die(mysql_error());
  179. }
  180. }
  181. ///// On off Switch //////////
  182. function OnOffSwitch($record,$item1,$item2,$item3){
  183. switch ($record) {
  184. case 0:
  185. echo $item1;
  186. break;
  187. case 1:
  188. echo $item2;
  189. break;
  190. case 2:
  191. echo $item3;
  192. break;
  193. default:
  194. echo "N/A";
  195. break;
  196. }
  197. }
  198. ///// Image On off Switch //////////
  199. function ImageOnOffSwitch($record,$item1,$item2,$item3){
  200. switch ($record) {
  201. case 0:
  202. echo "<img src='../../images/$item1' width='16' height='16' />";
  203. break;
  204. case 1:
  205. echo "<img src='../../images/$item2' width='16' height='16' />";
  206. break;
  207. case 2:
  208. echo "<img src='../../images/$item3' width='16' height='16' />";
  209. break;
  210. default:
  211. echo "N/A";
  212. break;
  213. }
  214. }
  215. // Format Date
  216. function formatDate($datestring,$format){
  217. $convertDate = date("".$format."",strtotime($datestring));
  218. echo $convertDate;
  219. }
  220. ///////////////////////////////////////////
  221. //// Administrator replacement /////
  222. function login($access) {
  223. if ($access == "2") { echo "Level 2 - Administrator"; }
  224. elseif ($access == "1") { echo "Level 1 - Super Administrator"; }
  225. elseif ($access == "3") { echo "Level 3 - Staff"; }
  226. else { echo "Inactive - None"; }
  227. }
  228. /////////////////////////////////////////////
  229. //// Create Password ////
  230. function createPassword() {
  231. $chars = "abcdefghijkmnopqrstuvwxyz023456789";
  232. srand((double)microtime()*1000000);
  233. $i = 0;
  234. $pass = '' ;
  235. while ($i <= 7) {
  236. $num = rand() % 33;
  237. $tmp = substr($chars, $num, 1);
  238. $pass = $pass . $tmp;
  239. $i++;
  240. }
  241. return $pass;
  242. }
  243. function stopSign($record,$Yes,$No) {
  244. if($record == $Yes) {
  245. echo "<img src='/admin/images/Approved.gif' width='12' height='12' />";
  246. } elseif ($record == $No) {
  247. echo "<img src='/admin/images/Denied.gif' width='12' height='12' />";
  248. } else { echo "<img src='/admin/images/Pending.gif' width='12' height='12' />";}
  249. }
  250. /////////////////////////////////////////////////
  251. /////////// Password Update /////////////
  252. function passwordRequest2($firstName,$mailto,$password)
  253. {
  254. // Variables
  255. $subject = "Password Request";
  256. // Header for return address
  257. $headers = 'From: webmaster@seaho.org' . "\r\n" .
  258. 'Reply-To: webmaster@seaho.org' . "\r\n" .
  259. 'X-Mailer: PHP/' . phpversion();
  260. // Header for html email
  261. $headers .= "MIME-Version: 1.0" . "\r\n";
  262. $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
  263. // Message Area
  264. $message = "
  265. <html>
  266. <style type='text/css'>
  267. <!--
  268. .boldcolor {
  269. color: #000099;
  270. font-weight: bold;
  271. }
  272. .style1 {color: #000099}
  273. -->
  274. </style>
  275. <body>
  276. <h3>Password Update</h3>
  277. <hr />
  278. <p>Dear ".$firstName."</p>
  279. <p>This email is being sent to you because your password has requested. If you did not request for your password to be sent to you please contact the webmaster at webmaster@seaho.org ASAP. Below is the information, that was requested. </p>
  280. <p>
  281. <strong>user/email: ".$mailto."<br />
  282. password: ".$password."</strong>
  283. </p>
  284. </body>
  285. </html>
  286. ";
  287. mail($mailto, $subject, $message,$headers);
  288. }
  289. /////////////////////////////////////////////
  290. //// Email New Member Information ////
  291. function NewMemberEmail($firstName,$mailto,$password)
  292. {
  293. // Variables
  294. $subject = "Welcome to SEAHO Program LCCM";
  295. // Header for return address
  296. $headers = 'From: webmaster@seaho.org' . "\r\n" .
  297. 'Reply-To: webmaster@seaho.org' . "\r\n" .
  298. 'X-Mailer: PHP/' . phpversion();
  299. // Header for html email
  300. $headers .= "MIME-Version: 1.0" . "\r\n";
  301. $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
  302. // Message Area
  303. $message = "
  304. <html>
  305. <style type='text/css'>
  306. <!--
  307. .boldcolor {
  308. color: #000099;
  309. font-weight: bold;
  310. }
  311. .style1 {color: #000099}
  312. -->
  313. </style>
  314. <body>
  315. <h3>Welcome to LCCM</h3>
  316. <hr />
  317. <p>Dear ".$firstName."</p>
  318. <p>Welcome to the SEAHO Program LCCM. The Lovett Creations Content Manager is your member portal that will allow you access to vital information pertaining to the SEAHO programming.</p>
  319. <p>Your new account has been created, and is ready for you to access. Below you will find your login information, your next step is to login at <a href='http://seaho.org/programs/admin'>SEAHO Programs LCCM</a>. If you have any question please let us know. Thanks and enjoy.
  320. <hr />
  321. <strong>user/email: </strong>".$mailto."<br />
  322. <strong>password: </strong>".$password."</p>
  323. <hr />
  324. </body>
  325. </html>
  326. ";
  327. mail($mailto, $subject, $message,$headers);
  328. }
  329. /////////////////////////////////////////////
  330. //// Simple Email Notification Form ////
  331. function emailNotification($name,$title,$mailto)
  332. {
  333. // Variables
  334. $subject = $title;
  335. // Header for return address
  336. $headers = 'From: webmaster@seaho.org' . "\r\n" .
  337. 'Reply-To: webmaster@seaho.org' . "\r\n" .
  338. 'X-Mailer: PHP/' . phpversion();
  339. // Header for html email
  340. $headers .= "MIME-Version: 1.0" . "\r\n";
  341. $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
  342. // Message Area
  343. $message = "
  344. <html>
  345. <body>
  346. <p>".$name.",<br />
  347. <strong>".$title."</strong> has been submitted to the Database. The information has been entered into the database. You can login to review the information</p>
  348. </body>
  349. </html>
  350. ";
  351. mail($mailto, $subject, $message,$headers);
  352. }
  353. //////////////////////////////////////////
  354. /// Create guid function //////
  355. function create_guid()
  356. {
  357. $microTime = microtime();
  358. list($a_dec, $a_sec) = explode(" ", $microTime);
  359. $dec_hex = sprintf("%x", $a_dec* 1000000);
  360. $sec_hex = sprintf("%x", $a_sec);
  361. ensure_length($dec_hex, 5);
  362. ensure_length($sec_hex, 6);
  363. $guid = "";
  364. $guid .= $dec_hex;
  365. $guid .= create_guid_section(3);
  366. $guid .= '-';
  367. $guid .= create_guid_section(4);
  368. $guid .= '-';
  369. $guid .= create_guid_section(4);
  370. $guid .= '-';
  371. $guid .= create_guid_section(4);
  372. $guid .= '-';
  373. $guid .= $sec_hex;
  374. $guid .= create_guid_section(6);
  375. return $guid;
  376. }
  377. function create_guid_section($characters)
  378. {
  379. $return = "";
  380. for($i=0; $i<$characters; $i++)
  381. {
  382. $return .= sprintf("%x", mt_rand(0,15));
  383. }
  384. return $return;
  385. }
  386. function ensure_length(&$string, $length)
  387. {
  388. $strlen = strlen($string);
  389. if($strlen < $length)
  390. {
  391. $string = str_pad($string,$length,"0");
  392. }
  393. else if($strlen > $length)
  394. {
  395. $string = substr($string, 0, $length);
  396. }
  397. }
  398. function microtime_diff($a, $b) {
  399. list($a_dec, $a_sec) = explode(" ", $a);
  400. list($b_dec, $b_sec) = explode(" ", $b);
  401. return $b_sec - $a_sec + $b_dec - $a_dec;
  402. }
  403. ?>