PageRenderTime 63ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/server/admin/adminapi.php

http://openqwaq.googlecode.com/
PHP | 1550 lines | 1347 code | 130 blank | 73 comment | 177 complexity | ecb18a197010be5ae0ae45f7dfebb420 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. include("config.php");
  3. include("SFUpdateDB.php");
  4. $lastError = "";
  5. // Sends the XML request to the specified url
  6. function sendServerRequest($url, $xml, $timeout = 10) {
  7. $tokens = @explode("/", $url, 4);
  8. $page = '/'.$tokens[3];
  9. $tokens = @explode(":", $tokens[2], 2);
  10. $host = $tokens[0];
  11. $port = $tokens[1];
  12. $ip = gethostbyname($host);
  13. $data = "POST $page HTTP/1.0\r\n";
  14. $data .= "Host: $host:$port\r\n";
  15. $data .= "Connection: Close\r\n";
  16. $data .= "Content-Type: text/xml\r\n";
  17. $data .= "Content-Length: ".strlen($xml)."\r\n\r\n";
  18. $data .= $xml;
  19. $handle = @fsockopen($ip,$port, $errno, $errstr, $timeout);
  20. if(!$handle) {
  21. return "<failed>Unable to connect to $url</failed>";
  22. }
  23. fputs($handle, $data);
  24. $response = stream_get_contents($handle);
  25. fclose($handle);
  26. // Check the response code. If its a 200 return the contents,
  27. // otherwise construct an error response from the reason string.
  28. $response = @explode("\r\n\r\n",$response,2);
  29. $line = @explode("\r\n", $response[0], 2);
  30. // syslog(LOG_INFO, "HTTP response: {$line[0]}");
  31. $tokens = @explode(" ", $line[0], 3);
  32. if($tokens[1] == "200") {
  33. return $response[1];
  34. } else {
  35. return '<failed>'.$line[0].'</failed>';
  36. }
  37. }
  38. function parseServerResponse($response) {
  39. $doc = new DOMDocument("1.0", "UTF-8");
  40. #$old = libxml_use_internal_errors(true);
  41. $doc->loadXML($response);
  42. #libxml_use_internal_errors($old);
  43. return $doc;
  44. }
  45. /**************************************************************************/
  46. // Encapsulates connection settings etc.
  47. function odbcConnect() {
  48. global $odbcData, $odbcUser, $odbcPass;
  49. return odbc_connect($odbcData, $odbcUser, $odbcPass);
  50. }
  51. function odbcLogConnect() {
  52. global $odbcLogData, $odbcLogUser, $odbcLogPass;
  53. return odbc_connect($odbcLogData, $odbcLogUser, $odbcLogPass);
  54. }
  55. // Creates the actual stuff on disk
  56. function setupOrgDir($serverName, $orgName) {
  57. global $lastError, $allServers;
  58. // Setup the files on disk for the organization
  59. foreach($allServers as $server) {
  60. if($serverName == $server[0]) $urlBase=$server[2];
  61. }
  62. $setupOrgUrl = $urlBase . "/coal/createOrg";
  63. // We don't have enough info at the php level to do the actual
  64. // org creation to punt and task the SP with it.
  65. $doc = new DOMDocument("1.0", "UTF-8");
  66. $top = $doc->createElement("createOrg", "");
  67. $doc->appendChild($top);
  68. $node = $doc->createElement("orgName");
  69. $node->appendChild($doc->createTextNode($orgName));
  70. $top->appendChild($node);
  71. $xml = $doc->saveXML();
  72. $response = sendServerRequest($setupOrgUrl, $xml);
  73. $xml = new SimpleXMLElement($response);
  74. $success = $xml->getName();
  75. $reason = $response;
  76. $loc = $xml->location;
  77. if($success <> "ok") {
  78. $lastError = $reason;
  79. } else {
  80. return $loc;
  81. }
  82. }
  83. // Creates the actual stuff on disk
  84. function setupUserDir($serverName, $userName) {
  85. global $lastError, $allServers;
  86. // Setup the files on disk for the organization
  87. foreach($allServers as $server) {
  88. if($serverName == $server[0]) $urlBase=$server[2];
  89. }
  90. $setupOrgUrl = $urlBase . "/coal/createUser";
  91. // We don't have enough info at the php level to do the actual
  92. // creation to punt and task the SP with it.
  93. $doc = new DOMDocument("1.0", "UTF-8");
  94. $top = $doc->createElement("createUser", "");
  95. $doc->appendChild($top);
  96. $node = $doc->createElement("userName");
  97. $node->appendChild($doc->createTextNode($userName));
  98. $top->appendChild($node);
  99. $xml = $doc->saveXML();
  100. $response = sendServerRequest($setupOrgUrl, $xml);
  101. $xml = new SimpleXMLElement($response);
  102. $success = $xml->getName();
  103. $reason = $response;
  104. $loc = $xml->location;
  105. if($success <> "ok") {
  106. $lastError = $reason;
  107. } else {
  108. return $loc;
  109. }
  110. }
  111. // Creates an activation request this sends the welcome email
  112. function sendActivationRequest($serverName, $form) {
  113. global $lastError, $allServers;
  114. foreach($allServers as $server) {
  115. if($serverName == $server[0]) $urlBase=$server[2];
  116. }
  117. $activateUrl = $urlBase . "/coal/activate";
  118. $xml = createCommonRequest($form, "activate");
  119. $response = sendServerRequest($activateUrl, $xml);
  120. $xml = new SimpleXMLElement($response);
  121. $success = $xml->getName();
  122. $reason = $response;
  123. if($success <> "ok") {
  124. $lastError = $reason;
  125. return False;
  126. }
  127. return True;
  128. }
  129. // Creates a password reminder request
  130. function sendPasswordReminderRequest($serverName, $email) {
  131. global $lastError, $allServers;
  132. foreach($allServers as $server) {
  133. if($serverName == $server[0]) $urlBase=$server[2];
  134. }
  135. $reminderURL = $urlBase . "/coal/emailpassword";
  136. $doc = new DOMDocument("1.0", "UTF-8");
  137. $top = $doc->createElement("emailPassword", "");
  138. $doc->appendChild($top);
  139. $node = $doc->createElement("email");
  140. $node->appendChild($doc->createTextNode($email));
  141. $top->appendChild($node);
  142. $xml = $doc->saveXML();
  143. $response = sendServerRequest($reminderURL, $xml);
  144. $xml = new SimpleXMLElement($response);
  145. $success = $xml->getName();
  146. $reason = $response;
  147. if($success <> "ok") {
  148. $lastError = $reason;
  149. return False;
  150. } else {
  151. return True;
  152. }
  153. }
  154. // Creates a common activation / signup request
  155. function createCommonRequest($form, $tag) {
  156. $doc = new DOMDocument("1.0", "UTF-8");
  157. $top = $doc->createElement($tag, "");
  158. $doc->appendChild($top);
  159. $node = $doc->createElement("firstName");
  160. $node->appendChild($doc->createTextNode($form["firstName"]));
  161. $top->appendChild($node);
  162. $node = $doc->createElement("lastName");
  163. $node->appendChild($doc->createTextNode($form["lastName"]));
  164. $top->appendChild($node);
  165. $node = $doc->createElement("company");
  166. $node->appendChild($doc->createTextNode($form["company"]));
  167. $top->appendChild($node);
  168. $node = $doc->createElement("email");
  169. $node->appendChild($doc->createTextNode($form["email"]));
  170. $top->appendChild($node);
  171. if(isset($form["password"])) {
  172. $node = $doc->createElement("password");
  173. $node->appendChild($doc->createTextNode($form["password"]));
  174. $top->appendChild($node);
  175. }
  176. return $doc->saveXML();
  177. }
  178. // Renames an org
  179. function renameOrg($server, $orgid, $newName) {
  180. global $lastError, $allServers;
  181. // Setup the files on disk for the organization
  182. foreach($allServers as $server) {
  183. if($serverName == $server[0]) $urlBase=$server[2];
  184. }
  185. $renameOrgUrl = $urlBase . "/coal/renameOrg";
  186. // We don't have enough info at the php level to do the actual
  187. // org rename to punt and task the SP with it.
  188. echo "orgName is: ".$newName;
  189. $doc = new DOMDocument("1.0", "UTF-8");
  190. $top = $doc->createElement("renameOrg", "");
  191. $doc->appendChild($top);
  192. $node = $doc->createElement("orgid", $orgid);
  193. $top->appendChild($node);
  194. $node = $doc->createElement("orgName");
  195. $node->appendChild($doc->createTextNode($newName));
  196. $top->appendChild($node);
  197. $xml = $doc->saveXML();
  198. echo $xml;
  199. $response = sendServerRequest($renameOrgUrl, $xml);
  200. echo $response;
  201. if(true) {
  202. $xml = new SimpleXMLElement($response);
  203. $success = $xml->getName();
  204. $reason = $response;
  205. } else {
  206. $doc = parseServerResponse($response);
  207. $success = $doc->firstChild->nodeName;
  208. $reason = $doc->firstChild->nodeValue;
  209. }
  210. $lastError = $reason;
  211. return $success == "ok";
  212. }
  213. function uuid() {
  214. $odbc = odbcConnect();
  215. $rs = odbc_exec($odbc, 'select UUID()');
  216. if (odbc_fetch_row($rs)) {
  217. return odbc_result($rs,'UUID()');
  218. } else {
  219. return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  220. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
  221. mt_rand( 0, 0x0fff ) | 0x4000,
  222. mt_rand( 0, 0x3fff ) | 0x8000,
  223. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) );
  224. }
  225. }
  226. /* Operations:
  227. * createUser(values): Create new user; return id.
  228. * updateUser(id, values): Update user information.
  229. * deleteUser(id): Delete a user.
  230. * findUserById(id): return user info.
  231. * findUsersByMatch(query, limit): Find users by match.
  232. */
  233. function createUser($values) {
  234. global $lastError;
  235. if($values["name"] == '') {
  236. $lastError = "No user name provided";
  237. return;
  238. }
  239. $odbc = odbcConnect();
  240. // Check if this user already exists and fail if so
  241. $stmt = odbc_prepare($odbc, "SELECT * FROM users WHERE name = ?");
  242. $rs = odbc_execute($stmt, array($values["name"]));
  243. if(!$rs) {
  244. odbc_close($odbc);
  245. return;
  246. }
  247. if(odbc_fetch_row($stmt)) {
  248. odbc_close($odbc);
  249. $lastError = "<b>Error:</b> User {$values['name']} already exists";
  250. return;
  251. }
  252. // Setup the files on disk
  253. if(!isset($values["server"])) $values["server"] = "";
  254. $userDir = setupUserDir($values["server"], $values["name"]);
  255. if($userDir == "") {
  256. odbc_close($odbc);
  257. return;
  258. }
  259. $id = uuid();
  260. /* create digest entry first */
  261. $stmt = odbc_prepare($odbc, "INSERT into user_digests(name, digest, updated) VALUES(?, ?, CURRENT_TIMESTAMP())");
  262. $rs = odbc_execute($stmt, array($values["name"], ""));
  263. $stmt = odbc_prepare($odbc, "INSERT into users(id, name, email, status, first_name, last_name, company, comment, created, files) VALUES(?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), ?)");
  264. $rs = odbc_execute($stmt, array($id, $values["name"], $values["email"], $values["status"], $values["firstName"], $values["lastName"], $values["company"], $values["comment"], $userDir));
  265. odbc_close($odbc);
  266. if($rs) return $id;
  267. }
  268. function updateUser($id, $values) {
  269. if ($values['sfdc'] != "") {
  270. updateSF('users', $id, $values['sfdc']);
  271. }
  272. $odbc = odbcConnect();
  273. /* update password / digest first */
  274. if($values["password"] <> "") {
  275. $md5 = md5($values["name"] . ":" . $values["password"]);
  276. $stmt = odbc_prepare($odbc, "UPDATE user_passwords SET password=?, updated=CURRENT_TIMESTAMP() WHERE name=?");
  277. $rs = odbc_execute($stmt, array($values["password"], $values["name"]));
  278. $stmt = odbc_prepare($odbc, "UPDATE user_digests SET digest=?, updated=CURRENT_TIMESTAMP() where name=?");
  279. $rs = odbc_execute($stmt, array($md5, $values["name"]));
  280. }
  281. // update the data base accordingly
  282. $stmt = odbc_prepare($odbc, "UPDATE users SET email=?, first_name=?, last_name=?, company=?, comment=?, status=? WHERE id=?");
  283. $rs = odbc_execute($stmt, array(
  284. $values["email"],
  285. $values["firstName"],
  286. $values["lastName"],
  287. $values["company"],
  288. $values["comment"],
  289. $values["status"],
  290. $id));
  291. odbc_close($odbc);
  292. return $rs;
  293. }
  294. function deleteUser($id) {
  295. $form = findUserById($id);
  296. if(!isset($form)) return;
  297. if ($form['sfdc'] != "") {
  298. updateSF('users', $id, $form['sfdc']);
  299. $accounts = findAccountsByUser($id);
  300. foreach ($accounts as $account) {
  301. if ($account['sfdc'] != "") {
  302. updateSF('org_members', $account['id'], $account['sfdc']);
  303. }
  304. }
  305. }
  306. $odbc = odbcConnect();
  307. $stmt = odbc_prepare($odbc, "DELETE FROM org_members WHERE member_id = ? AND member_type = ?");
  308. $rs = odbc_execute($stmt, array($id, "user"));
  309. $stmt = odbc_prepare($odbc, "DELETE FROM group_members WHERE member_id = ? AND member_type = ?");
  310. $rs = odbc_execute($stmt, array($id, "user"));
  311. $stmt = odbc_prepare($odbc, "DELETE FROM users WHERE id = ?");
  312. $rs = odbc_execute($stmt, array($id));
  313. $stmt = odbc_prepare($odbc, "DELETE FROM user_passwords WHERE name = ?");
  314. $rs = odbc_execute($stmt, array($form["name"]));
  315. $stmt = odbc_prepare($odbc, "DELETE FROM user_digests WHERE name = ?");
  316. $rs = odbc_execute($stmt, array($form["name"]));
  317. odbc_close($odbc);
  318. return $rs;
  319. }
  320. function findUserById($id) {
  321. $odbc = odbcConnect();
  322. $sql = "SELECT * from users where id='$id'";
  323. $rs = odbc_exec($odbc, $sql);
  324. if(odbc_fetch_row($rs)) {
  325. $result = array(
  326. "id" => odbc_result($rs, "id"),
  327. "name" => odbc_result($rs, "name"),
  328. "password" => "",
  329. "email" => odbc_result($rs, "email"),
  330. "status" => odbc_result($rs, "status"),
  331. "firstName" => odbc_result($rs, "first_name"),
  332. "lastName" => odbc_result($rs, "last_name"),
  333. "company" => odbc_result($rs, "company"),
  334. "comment" => odbc_result($rs, "comment"),
  335. "sfdc" => odbc_result($rs, "sfdc_id")
  336. );
  337. }
  338. odbc_close($odbc);
  339. if(isset($result)) return $result;
  340. }
  341. // Returns true if the user has been previously activated
  342. function isUserActivated($name) {
  343. $odbc = odbcConnect();
  344. $rs=odbc_exec($odbc, "SELECT count(*) from user_digests where name='$name'");
  345. $result = odbc_result($rs,1);
  346. odbc_close($odbc);
  347. return $result > 0;
  348. }
  349. function findUserByName($name) {
  350. $odbc = odbcConnect();
  351. $sql = "SELECT * from users where name='$name'";
  352. $rs = odbc_exec($odbc, $sql);
  353. if(odbc_fetch_row($rs)) {
  354. $result = array(
  355. "id" => odbc_result($rs, "id"),
  356. "name" => odbc_result($rs, "name"),
  357. "password" => "",
  358. "email" => odbc_result($rs, "email"),
  359. "status" => odbc_result($rs, "status"),
  360. "firstName" => odbc_result($rs, "first_name"),
  361. "lastName" => odbc_result($rs, "last_name"),
  362. "company" => odbc_result($rs, "company"),
  363. "comment" => odbc_result($rs, "comment")
  364. );
  365. }
  366. odbc_close($odbc);
  367. if(isset($result)) return $result;
  368. }
  369. function findAllUserNames() {
  370. $odbc = odbcConnect();
  371. $rs = odbc_exec($odbc, "SELECT name from users");
  372. $result = array();
  373. while(odbc_fetch_row($rs)) {
  374. $result[] = odbc_result($rs, "name");
  375. }
  376. odbc_close($odbc);
  377. natcasesort($result);
  378. return $result;
  379. }
  380. function totalUserCount() {
  381. $odbc = odbcConnect();
  382. $rs = odbc_exec($odbc, "SELECT count(*) from users");
  383. $total = odbc_result($rs,1);
  384. odbc_close($odbc);
  385. return $total;
  386. }
  387. function findUsersByMatch($query, $limit, $page=1) {
  388. $odbc = odbcConnect();
  389. $rs = odbc_exec($odbc, "SELECT count(*) from users where name like '%$query%' or first_name like '%$query%' or last_name like '%$query%' or company like '$query%'");
  390. $total = odbc_result($rs,1);
  391. $rs = odbc_exec($odbc, "SELECT * from users where name like '%$query%' or email like '%$query%' or first_name like '%$query%' or last_name like '%$query%' or company like '%$query%' order by created desc");
  392. $result = array();
  393. $result["total"] = $total;
  394. $count = ($limit*($page-1))+1;
  395. $rows = 0;
  396. while(odbc_fetch_row($rs, $count) && ($rows < $limit) ) {
  397. $id = odbc_result($rs, "id");
  398. $count += 1;
  399. $rows += 1;
  400. $result[] = array(
  401. "id" => $id,
  402. "created" => odbc_result($rs, "created"),
  403. "name" => odbc_result($rs, "name"),
  404. "email" => odbc_result($rs, "email"),
  405. "firstName" => odbc_result($rs, "first_name"),
  406. "lastName" => odbc_result($rs, "last_name"),
  407. "company" => odbc_result($rs, "company"),
  408. "sfdc" => odbc_result($rs, "sfdc_id")
  409. );
  410. }
  411. $count = $count - 1; //we didn't use the last count
  412. $count = $count - ($limit*($page-1));
  413. $result["count"] = $count;
  414. odbc_close($odbc);
  415. return $result;
  416. }
  417. /*
  418. * createGroup(values): Create new group; return id.
  419. * updateGroup(id,values): Update group information.
  420. * deleteGroup(id): Delete a group.
  421. * findGroupById(id): return group info.
  422. * findGroupsByMatch(query, limit): Find group by match.
  423. */
  424. function createGroup($values) {
  425. global $lastError;
  426. if($values["name"] == '') {
  427. $lastError = "No group name provided";
  428. return;
  429. }
  430. $odbc = odbcConnect();
  431. $groupName = $values["name"];
  432. // Check if this group already exists and fail if so
  433. $stmt = odbc_prepare($odbc, "SELECT * FROM groups WHERE name = ?");
  434. $rs = odbc_execute($stmt, array($groupName));
  435. if(!$rs) {
  436. odbc_close($odbc);
  437. return;
  438. }
  439. if(odbc_fetch_row($stmt)) {
  440. odbc_close($odbc);
  441. $lastError= "<b>Error:</b> Group '$groupName' already exists";
  442. return;
  443. }
  444. // Create the group
  445. $id = uuid();
  446. $stmt = odbc_prepare($odbc, "INSERT into groups(id, name, status, comment, created) VALUES(?, ?, ?, ?, CURRENT_TIMESTAMP())");
  447. $rs = odbc_execute($stmt, array($id, $values["name"], $values["status"], $values["comment"]));
  448. odbc_close($odbc);
  449. if($rs) return $id;
  450. }
  451. function updateGroup($id, $values) {
  452. $odbc = odbcConnect();
  453. $stmt = odbc_prepare($odbc, "UPDATE groups SET name=?, status=?, comment=? WHERE id=?");
  454. $rs = odbc_execute($stmt, array($values["name"], $values["status"], $values["comment"], $id));
  455. odbc_close($odbc);
  456. return $rs;
  457. }
  458. function deleteGroup($id) {
  459. $group = findGroupById($id);
  460. if (!isset($group)) return;
  461. $odbc = odbcConnect();
  462. $stmt = odbc_prepare($odbc, "DELETE FROM group_members WHERE group_id = ?");
  463. $rs = odbc_execute($stmt, array($id));
  464. if(!$rs) {
  465. odbc_close($odbc);
  466. return false;
  467. }
  468. $stmt = odbc_prepare($odbc, "DELETE FROM org_members WHERE member_type = 'group' and member_id = ?");
  469. $rs = odbc_execute($stmt, array($id));
  470. if(!$rs) {
  471. odbc_close($odbc);
  472. return false;
  473. }
  474. $stmt = odbc_prepare($odbc, "DELETE FROM groups WHERE id = ?");
  475. $rs = odbc_execute($stmt, array($id));
  476. odbc_close($odbc);
  477. return $rs;
  478. }
  479. function findGroupById($id) {
  480. $odbc = odbcConnect();
  481. $sql = "SELECT * from groups where id='$id'";
  482. $rs = odbc_exec($odbc, $sql);
  483. if(odbc_fetch_row($rs)) {
  484. $result = array(
  485. "id" => odbc_result($rs, "id"),
  486. "name" => odbc_result($rs, "name"),
  487. "status" => odbc_result($rs, "status"),
  488. "comment" => odbc_result($rs, "comment"),
  489. "created" => odbc_result($rs, "created"),
  490. );
  491. }
  492. odbc_close($odbc);
  493. if(isset($result)) return $result;
  494. }
  495. function findGroupByName($name) {
  496. $odbc = odbcConnect();
  497. $sql = "SELECT * from groups where name='$name'";
  498. $rs = odbc_exec($odbc, $sql);
  499. if(odbc_fetch_row($rs)) {
  500. $result = array(
  501. "id" => odbc_result($rs, "id"),
  502. "name" => odbc_result($rs, "name"),
  503. "status" => odbc_result($rs, "status"),
  504. "comment" => odbc_result($rs, "comment"),
  505. "created" => odbc_result($rs, "created")
  506. );
  507. }
  508. odbc_close($odbc);
  509. if(isset($result)) return $result;
  510. }
  511. function findAllGroupNames() {
  512. $odbc = odbcConnect();
  513. $rs = odbc_exec($odbc, "SELECT name from groups");
  514. $result = array();
  515. while(odbc_fetch_row($rs)) {
  516. $result[] = odbc_result($rs, "name");
  517. }
  518. odbc_close($odbc);
  519. natcasesort($result);
  520. return $result;
  521. }
  522. function totalGroupCount() {
  523. $odbc = odbcConnect();
  524. $rs = odbc_exec($odbc, "SELECT count(*) from groups");
  525. $total = odbc_result($rs,1);
  526. odbc_close($odbc);
  527. return $total;
  528. }
  529. function findGroupsByMatch($query, $limit, $page=1) {
  530. $result = array();
  531. $odbc = odbcConnect();
  532. $rs = odbc_exec($odbc, "SELECT count(*) from groups where name like '%$query%'");
  533. $result["total"] = odbc_result($rs,1);
  534. $sql = "SELECT * from groups where name like '%$query%' order by created desc";
  535. $rs = odbc_exec($odbc, $sql);
  536. $count = ($limit*($page-1))+1;
  537. $rows = 0;
  538. while(odbc_fetch_row($rs, $count) && ($rows < $limit) ) {
  539. $id = odbc_result($rs, "id");
  540. $count += 1;
  541. $rows += 1;
  542. $result[] = array(
  543. "id" => $id,
  544. "created" => odbc_result($rs, "created"),
  545. "name" => odbc_result($rs, "name"),
  546. "status" => odbc_result($rs, "status"),
  547. );
  548. }
  549. $count = $count - 1; //we didn't use the last count
  550. $count = $count - ($limit*($page-1));
  551. $result["count"] = $count;
  552. odbc_close($odbc);
  553. return $result;
  554. }
  555. function createGroupAccount($values) {
  556. global $lastError;
  557. $odbc = odbcConnect();
  558. // Check if this acct already exists and fail if so
  559. $stmt = odbc_prepare($odbc, "SELECT * FROM group_members WHERE member_id=? and group_id=? AND member_type=?");
  560. $rs = odbc_execute($stmt, array($values["userid"],$values["groupid"],$values["type"]));
  561. if(!$rs) {
  562. odbc_close($odbc);
  563. return;
  564. }
  565. if(odbc_fetch_row($stmt)) {
  566. odbc_close($odbc);
  567. $lastError= "<b>Error:</b> Membership for {$values['userName']} in {$values['groupName']} already exists";
  568. return;
  569. }
  570. $id = uuid();
  571. $stmt = odbc_prepare($odbc, "INSERT into group_members(id, member_type, member_id, member_name, group_id, group_name, created) VALUES(?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP())");
  572. $rs = odbc_execute($stmt, array($id, $values["type"], $values["userid"], $values["userName"], $values["groupid"], $values["groupName"]));
  573. odbc_close($odbc);
  574. if($rs) return $id;
  575. }
  576. /*
  577. * createOrg(values): Create new org; return id.
  578. * updateOrg(id,values): Update org information.
  579. * deleteOrg(id): Delete an organization.
  580. * findOrgById(id): return org info.
  581. * findOrgsByMatch(query, limit): Find orgs by match.
  582. */
  583. function createOrg($values) {
  584. global $lastError;
  585. if($values["name"] == '') {
  586. $lastError = "No group name provided";
  587. return;
  588. }
  589. $odbc = odbcConnect();
  590. $orgName = $values["name"];
  591. // Check if this org already exists and fail if so
  592. $stmt = odbc_prepare($odbc, "SELECT * FROM organizations WHERE name = ?");
  593. $rs = odbc_execute($stmt, array($orgName));
  594. if(!$rs) {
  595. odbc_close($odbc);
  596. return;
  597. }
  598. if(odbc_fetch_row($stmt)) {
  599. odbc_close($odbc);
  600. $lastError= "<b>Error:</b> Organization '$orgName' already exists";
  601. return;
  602. }
  603. // Setup the files on disk for the organization
  604. if(!isset($values["server"])) $values["server"] = "";
  605. //$orgDir = setupOrgDir($values["server"], $orgName);
  606. //if($orgDir == "") {
  607. //odbc_close($odbc);
  608. //return;
  609. //}
  610. $orgDir = '';
  611. // Create the org in the DB
  612. $id = uuid();
  613. $stmt = odbc_prepare($odbc, "INSERT into organizations(id, name, seats, status, tier, comment, files, server, created) VALUES(?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP())");
  614. $rs = odbc_execute($stmt, array($id, $values["name"], $values["seats"], $values["status"], $values["tier"], $values["comment"], $orgDir, $values["server"]));
  615. odbc_close($odbc);
  616. if($rs) return $id;
  617. }
  618. function updateOrg($id, $values) {
  619. if ($values['sfdc'] != "") {
  620. updateSF('organizations', $id, $values['sfdc']);
  621. }
  622. $odbc = odbcConnect();
  623. $stmt = odbc_prepare($odbc, "UPDATE organizations SET name=?, seats=?, status=?, tier=?, server=?, comment=? WHERE id=?");
  624. $rs = odbc_execute($stmt, array($values["name"], $values["seats"], $values["status"], $values["tier"], $values["server"], $values["comment"], $id));
  625. odbc_close($odbc);
  626. return $rs;
  627. }
  628. function deleteOrg($id) {
  629. $org = findOrgById($id);
  630. if (!isset($org)) return;
  631. if ($org['sfdc'] != "") {
  632. updateSF('organizations', $id, $org['sfdc']);
  633. $accounts = findAccountsByOrg($id);
  634. foreach ($accounts as $account){
  635. if ($account['sfdc'] != ""){
  636. updateSF('org_members', $account['id'], $account['sfdc']);
  637. }
  638. }
  639. }
  640. $odbc = odbcConnect();
  641. $stmt = odbc_prepare($odbc, "DELETE FROM org_members WHERE org_id = ?");
  642. $rs = odbc_execute($stmt, array($id));
  643. if(!$rs) {
  644. odbc_close($odbc);
  645. return false;
  646. }
  647. $stmt = odbc_prepare($odbc, "DELETE FROM organizations WHERE id = ?");
  648. $rs = odbc_execute($stmt, array($id));
  649. odbc_close($odbc);
  650. return $rs;
  651. }
  652. function findOrgById($id) {
  653. $odbc = odbcConnect();
  654. $sql = "SELECT * from organizations where id='$id'";
  655. $rs = odbc_exec($odbc, $sql);
  656. if(odbc_fetch_row($rs)) {
  657. $result = array(
  658. "id" => odbc_result($rs, "id"),
  659. "name" => odbc_result($rs, "name"),
  660. "status" => odbc_result($rs, "status"),
  661. "seats" => odbc_result($rs, "seats"),
  662. "tier" => odbc_result($rs, "tier"),
  663. "server" => odbc_result($rs, "server"),
  664. "comment" => odbc_result($rs, "comment"),
  665. "sfdc" => odbc_result($rs, "sfdc_id")
  666. );
  667. }
  668. odbc_close($odbc);
  669. if(isset($result)) return $result;
  670. }
  671. function findOrgByName($name) {
  672. $odbc = odbcConnect();
  673. $sql = "SELECT * from organizations where name='$name'";
  674. $rs = odbc_exec($odbc, $sql);
  675. if(odbc_fetch_row($rs)) {
  676. $result = array(
  677. "id" => odbc_result($rs, "id"),
  678. "name" => odbc_result($rs, "name"),
  679. "status" => odbc_result($rs, "status"),
  680. "seats" => odbc_result($rs, "seats"),
  681. "tier" => odbc_result($rs, "tier"),
  682. "server" => odbc_result($rs, "server"),
  683. "comment" => odbc_result($rs, "comment"),
  684. "sfdc" => odbc_result($rs, "sfdc_id")
  685. );
  686. }
  687. odbc_close($odbc);
  688. if(isset($result)) return $result;
  689. }
  690. function findAllOrgNames() {
  691. $odbc = odbcConnect();
  692. $rs = odbc_exec($odbc, "SELECT name from organizations");
  693. $result = array();
  694. while(odbc_fetch_row($rs)) {
  695. $result[] = odbc_result($rs, "name");
  696. }
  697. odbc_close($odbc);
  698. natcasesort($result);
  699. return $result;
  700. }
  701. function totalOrgCount() {
  702. $odbc = odbcConnect();
  703. $rs = odbc_exec($odbc, "SELECT count(*) from organizations");
  704. $total = odbc_result($rs,1);
  705. odbc_close($odbc);
  706. return $total;
  707. }
  708. function findOrgsByMatch($query, $limit, $page=1) {
  709. $result = array();
  710. $odbc = odbcConnect();
  711. $rs = odbc_exec($odbc, "SELECT count(*) from organizations where name like '%$query%'");
  712. $result["total"] = odbc_result($rs,1);
  713. $sql = "SELECT * from organizations where name like '%$query%' order by created desc";
  714. $rs = odbc_exec($odbc, $sql);
  715. $count = ($limit*($page-1))+1;
  716. $rows = 0;
  717. while(odbc_fetch_row($rs, $count) && ($rows < $limit) ) {
  718. $id = odbc_result($rs, "id");
  719. $count += 1;
  720. $rows += 1;
  721. $result[] = array(
  722. "id" => $id,
  723. "created" => odbc_result($rs, "created"),
  724. "name" => odbc_result($rs, "name"),
  725. "status" => odbc_result($rs, "status"),
  726. "seats" => odbc_result($rs, "seats"),
  727. "tier" => odbc_result($rs, "tier"),
  728. "server" => odbc_result($rs, "server"),
  729. "sfdc" => odbc_result($rs, "sfdc_id")
  730. );
  731. }
  732. $count = $count - 1; //we didn't use the last count
  733. $count = $count - ($limit*($page-1));
  734. $result["count"] = $count;
  735. odbc_close($odbc);
  736. return $result;
  737. }
  738. /*
  739. * createAccount(values): Create user account; return id.
  740. * updateAccount(id, values): Update account info.
  741. * deleteAccount(id): Delete an account.
  742. * findAccountsByUser(id): Find accounts belonging to user.
  743. * findAccountsByOrg(id): Find accounts belonging to org.
  744. */
  745. function createAccount($values) {
  746. global $lastError;
  747. $odbc = odbcConnect();
  748. // Check if this acct already exists and fail if so
  749. $stmt = odbc_prepare($odbc, "SELECT * FROM org_members WHERE member_id=? and org_id=? AND member_type=?");
  750. $rs = odbc_execute($stmt, array($values["userid"],$values["orgid"],$values["type"]));
  751. if(!$rs) {
  752. odbc_close($odbc);
  753. return;
  754. }
  755. if(odbc_fetch_row($stmt)) {
  756. odbc_close($odbc);
  757. $lastError= "<b>Error:</b> Membership for {$values['userName']} in {$values['orgName']} already exists";
  758. return;
  759. }
  760. $id = uuid();
  761. $stmt = odbc_prepare($odbc, "INSERT into org_members(id, member_type, member_id, member_name, org_id, org_name, status, role_name, created) VALUES(?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP())");
  762. $rs = odbc_execute($stmt, array($id, $values["type"], $values["userid"], $values["userName"], $values["orgid"], $values["orgName"], $values["status"], $values["role"]));
  763. odbc_close($odbc);
  764. if($rs) return $id;
  765. }
  766. function updateOrgAccount($id, $values) {
  767. if ($values['sfdc'] != "") {
  768. updateSF('org_members', $id, $values['sfdc']);
  769. }
  770. $odbc = odbcConnect();
  771. $stmt = odbc_prepare($odbc, "UPDATE org_members SET status=?, role_name=? WHERE id=?");
  772. $rs = odbc_execute($stmt, array($values["status"], $values["role"], $id));
  773. odbc_close($odbc);
  774. return $rs;
  775. }
  776. function updateGroupAccount($id, $values) {
  777. $odbc = odbcConnect();
  778. $stmt = odbc_prepare($odbc, "UPDATE group_members SET status=? WHERE id=?");
  779. $rs = odbc_execute($stmt, array($values["status"], $id));
  780. odbc_close($odbc);
  781. return $rs;
  782. }
  783. function deleteGroupAccount($id) {
  784. $odbc = odbcConnect();
  785. $stmt = odbc_prepare($odbc, "DELETE FROM group_members WHERE id = ?");
  786. $rs = odbc_execute($stmt, array($id));
  787. odbc_close($odbc);
  788. return $rs;
  789. }
  790. function deleteOrgAccount($id) {
  791. $account = findOrgAccountById($id);
  792. if ($account['sfdc'] != "") {
  793. updateSF('org_members', $account['id'], $account['sfdc']);
  794. }
  795. $odbc = odbcConnect();
  796. $stmt = odbc_prepare($odbc, "DELETE FROM org_members WHERE id = ?");
  797. $rs = odbc_execute($stmt, array($id));
  798. odbc_close($odbc);
  799. return $rs;
  800. }
  801. function deleteAccount($id) {
  802. $acct = findOrgAccountById($id);
  803. if(isset($acct)) deleteOrgAccount($id);
  804. $acct = findGroupAccountById($id);
  805. if(isset($acct)) deleteGroupAccount($id);
  806. }
  807. function findAccountById($id) {
  808. $odbc = odbcConnect();
  809. $sql="SELECT * from org_members where id='$id'";
  810. $rs = odbc_exec($odbc, $sql);
  811. if(odbc_fetch_row($rs)) {
  812. $result = array(
  813. "id" => odbc_result($rs, "id"),
  814. "created" => odbc_result($rs, "created"),
  815. "type" => odbc_result($rs, "member_type"),
  816. "userid" => odbc_result($rs, "member_id"),
  817. "userName" => odbc_result($rs, "member_name"),
  818. "orgid" => odbc_result($rs,"org_id"),
  819. "orgName" => odbc_result($rs, "org_name"),
  820. "status" => odbc_result($rs, "status"),
  821. "role" => odbc_result($rs, "role_name"),
  822. "sfdc" => odbc_result($rs, "sfdc_id")
  823. );
  824. }
  825. odbc_close($odbc);
  826. if(isset($result)) return $result;
  827. }
  828. function findOrgAccountById($id) {
  829. $odbc = odbcConnect();
  830. $sql="SELECT * from org_members where id='$id'";
  831. $rs = odbc_exec($odbc, $sql);
  832. if(odbc_fetch_row($rs)) {
  833. $result = array(
  834. "id" => odbc_result($rs, "id"),
  835. "created" => odbc_result($rs, "created"),
  836. "type" => odbc_result($rs, "member_type"),
  837. "memberid" => odbc_result($rs, "member_id"),
  838. "memberName" => odbc_result($rs, "member_name"),
  839. "orgid" => odbc_result($rs,"org_id"),
  840. "orgName" => odbc_result($rs, "org_name"),
  841. "status" => odbc_result($rs, "status"),
  842. "role" => odbc_result($rs, "role_name"),
  843. "sfdc" => odbc_result($rs, "sfdc_id")
  844. );
  845. }
  846. odbc_close($odbc);
  847. if(isset($result)) return $result;
  848. }
  849. function findGroupAccountById($id) {
  850. $odbc = odbcConnect();
  851. $sql="SELECT * from group_members where id='$id'";
  852. $rs = odbc_exec($odbc, $sql);
  853. if(odbc_fetch_row($rs)) {
  854. $result = array(
  855. "id" => odbc_result($rs, "id"),
  856. "created" => odbc_result($rs, "created"),
  857. "type" => odbc_result($rs, "member_type"),
  858. "memberid" => odbc_result($rs, "member_id"),
  859. "memberName" => odbc_result($rs, "member_name"),
  860. "groupid" => odbc_result($rs,"group_id"),
  861. "groupName" => odbc_result($rs, "group_name"),
  862. );
  863. }
  864. odbc_close($odbc);
  865. if(isset($result)) return $result;
  866. }
  867. function findAccountByUserAndOrg($uid, $oid) {
  868. $odbc = odbcConnect();
  869. $sql="SELECT * from org_members where member_id='$uid' and org_id='$oid' and member_type='user'";
  870. $rs = odbc_exec($odbc, $sql);
  871. if(odbc_fetch_row($rs)) {
  872. $result = array(
  873. "id" => odbc_result($rs, "id"),
  874. "created" => odbc_result($rs, "created"),
  875. "type" => odbc_result($rs, "member_type"),
  876. "userid" => odbc_result($rs, "member_id"),
  877. "userName" => odbc_result($rs, "member_name"),
  878. "orgid" => odbc_result($rs,"org_id"),
  879. "orgName" => odbc_result($rs, "org_name"),
  880. "status" => odbc_result($rs, "status"),
  881. "role" => odbc_result($rs, "role_name"),
  882. "sfdc" => odbc_result($rs, "sfdc_id")
  883. );
  884. }
  885. odbc_close($odbc);
  886. if(isset($result)) return $result;
  887. }
  888. function findAccountsByUser($id) {
  889. $odbc = odbcConnect();
  890. $sql="SELECT * from org_members where member_id='$id' and member_type = 'user' order by created desc";
  891. $rs = odbc_exec($odbc, $sql);
  892. $result = array();
  893. while(odbc_fetch_row($rs)) {
  894. $result[] = array(
  895. "id" => odbc_result($rs, "id"),
  896. "created" => odbc_result($rs, "created"),
  897. "type" => odbc_result($rs, "member_type"),
  898. "userid" => odbc_result($rs, "member_id"),
  899. "userName" => odbc_result($rs, "member_name"),
  900. "orgid" => odbc_result($rs,"org_id"),
  901. "orgName" => odbc_result($rs, "org_name"),
  902. "status" => odbc_result($rs, "status"),
  903. "role" => odbc_result($rs, "role_name"),
  904. "sfdc" => odbc_result($rs, "sfdc_id")
  905. );
  906. }
  907. odbc_close($odbc);
  908. return $result;
  909. }
  910. function findGroupAccountsByUser($id) {
  911. $odbc = odbcConnect();
  912. $sql="SELECT * from group_members where member_id='$id' and member_type = 'user' order by created desc";
  913. $rs = odbc_exec($odbc, $sql);
  914. $result = array();
  915. while(odbc_fetch_row($rs)) {
  916. $result[] = array(
  917. "id" => odbc_result($rs, "id"),
  918. "created" => odbc_result($rs, "created"),
  919. "type" => odbc_result($rs, "member_type"),
  920. "userid" => odbc_result($rs, "member_id"),
  921. "userName" => odbc_result($rs, "member_name"),
  922. "orgid" => odbc_result($rs,"group_id"),
  923. "orgName" => odbc_result($rs, "group_name"),
  924. "status" => odbc_result($rs, "status"),
  925. );
  926. }
  927. odbc_close($odbc);
  928. return $result;
  929. }
  930. function findGroupAccountsByGroupId($id) {
  931. $odbc = odbcConnect();
  932. $sql="SELECT * from group_members where group_id='$id'";
  933. $rs = odbc_exec($odbc, $sql);
  934. $result = array();
  935. while(odbc_fetch_row($rs)) {
  936. $result[] = array(
  937. "id" => odbc_result($rs, "id"),
  938. "created" => odbc_result($rs, "created"),
  939. "type" => odbc_result($rs, "member_type"),
  940. "userid" => odbc_result($rs, "member_id"),
  941. "userName" => odbc_result($rs, "member_name"),
  942. "groupid" => odbc_result($rs,"group_id"),
  943. "groupName" => odbc_result($rs, "group_name"),
  944. "status" => odbc_result($rs, "status"),
  945. );
  946. }
  947. odbc_close($odbc);
  948. return $result;
  949. }
  950. function findOrgAccountsByGroupId($groupid) {
  951. $odbc = odbcConnect();
  952. $sql="SELECT * from org_members where member_id='$groupid' and member_type='group'";
  953. $rs = odbc_exec($odbc, $sql);
  954. $result = array();
  955. while(odbc_fetch_row($rs)) {
  956. $result[] = array(
  957. "id" => odbc_result($rs, "id"),
  958. "created" => odbc_result($rs, "created"),
  959. "type" => odbc_result($rs, "member_type"),
  960. "userid" => odbc_result($rs, "member_id"),
  961. "userName" => odbc_result($rs, "member_name"),
  962. "orgid" => odbc_result($rs,"org_id"),
  963. "orgName" => odbc_result($rs, "org_name"),
  964. "status" => odbc_result($rs, "status"),
  965. "role" => odbc_result($rs, "role_name"),
  966. "sfdc" => odbc_result($rs, "sfdc_id")
  967. );
  968. }
  969. odbc_close($odbc);
  970. return $result;
  971. }
  972. function findAccountsByOrg($id) {
  973. $odbc = odbcConnect();
  974. $sql="SELECT * from org_members where org_id='$id' order by created desc";
  975. $rs = odbc_exec($odbc, $sql);
  976. $result = array();
  977. while(odbc_fetch_row($rs)) {
  978. $result[] = array(
  979. "id" => odbc_result($rs, "id"),
  980. "created" => odbc_result($rs, "created"),
  981. "type" => odbc_result($rs, "member_type"),
  982. "userid" => odbc_result($rs, "member_id"),
  983. "userName" => odbc_result($rs, "member_name"),
  984. "orgid" => odbc_result($rs,"org_id"),
  985. "orgName" => odbc_result($rs, "org_name"),
  986. "status" => odbc_result($rs, "status"),
  987. "role" => odbc_result($rs, "role_name"),
  988. "sfdc" => odbc_result($rs, "sfdc_id")
  989. );
  990. }
  991. odbc_close($odbc);
  992. return $result;
  993. }
  994. function findTotalAccountsInOrg($id) {
  995. $odbc = odbcConnect();
  996. $sql="SELECT count(*) from org_members where org_id='$id'";
  997. $rs = odbc_exec($odbc, $sql);
  998. if(odbc_fetch_row($rs)) {
  999. $result = odbc_result($rs, "count(*)");
  1000. } else {
  1001. $result = 0;
  1002. }
  1003. odbc_close($odbc);
  1004. return $result;
  1005. }
  1006. /****************************************************************************/
  1007. function makeOrgsTable($query, $limit, $showLimit, $page=1) {
  1008. global $allTiers;
  1009. $includeTier = (count($allTiers) > 1);
  1010. $matches = findOrgsByMatch($query, $limit, $page);
  1011. $total = $matches["total"];
  1012. $count = $matches["count"];
  1013. if($showLimit) {
  1014. echo "<b>Total number of results:</b> $total";
  1015. if($total > $limit) {
  1016. echo " (first $limit matches shown below; show ";
  1017. echo "<a href=\"findorg.php?limit=10\">10</a>, ";
  1018. echo "<a href=\"findorg.php?limit=20\">20</a>, ";
  1019. echo "<a href=\"findorg.php?limit=50\">50</a>, ";
  1020. echo "<a href=\"findorg.php?limit=100\">100</a>";
  1021. echo ")";
  1022. }
  1023. }
  1024. echo '<table cellpadding="0" cellspacing="0" class="alternate">';
  1025. echo "<tr>
  1026. <th>Date</th>
  1027. <th>Organization</th>
  1028. <th>Members</th>
  1029. <th>Seats</th>
  1030. <th>Status</th>";
  1031. if ($includeTier) {
  1032. echo "<th>Tier</th>";
  1033. };
  1034. for($index=0; $index < $count; $index+=1) {
  1035. $form = $matches[$index];
  1036. $used = findTotalAccountsInOrg($form['id']);
  1037. $created = explode(" ", $form["created"]);
  1038. $created = $created[0];
  1039. echo "<tr>
  1040. <td>$created</td>
  1041. <td><a href=\"editorg.php?id={$form['id']}\">{$form['name']}</a></td>
  1042. <td>$used</td>
  1043. <td>{$form['seats']}</td>
  1044. <td>{$form['status']}</td>";
  1045. if ($includeTier) {
  1046. echo "<td>{$form['tier']}</td>";
  1047. }
  1048. }
  1049. echo "</table>";
  1050. return $total;
  1051. }
  1052. function makeUsersTable($query, $limit, $showLimit, $page=1) {
  1053. $matches = findUsersByMatch($query, $limit, $page);
  1054. $count = $matches["count"];
  1055. $total = $matches["total"];
  1056. if($showLimit) {
  1057. echo "<b>Total number of results:</b> $total";
  1058. if($total > $limit) {
  1059. echo " (first $limit matches shown below; show ";
  1060. echo "<a href=\"finduser.php?limit=10\">10</a>, ";
  1061. echo "<a href=\"finduser.php?limit=20\">20</a>, ";
  1062. echo "<a href=\"finduser.php?limit=50\">50</a>, ";
  1063. echo "<a href=\"finduser.php?limit=100\">100</a>";
  1064. echo ")";
  1065. }
  1066. }
  1067. echo '<table cellpadding="0" cellspacing="0" class="alternate">';
  1068. echo "<tr> <th>Date</th> <th>User ID</th> <th>First</th> <th>Last</th> <th>Company</th> </tr>";
  1069. for($index = 0; $index < $count; $index += 1) {
  1070. $form = $matches[$index];
  1071. $created = explode(" ", $form["created"]);
  1072. $created = $created[0];
  1073. $sfdc = $form["sfdc"];
  1074. echo "<tr>
  1075. <td>$created</td>
  1076. <td><a href=\"edituser.php?id=${form['id']}\">{$form['name']}</a></td>
  1077. <td>{$form['firstName']}</td>
  1078. <td>{$form['lastName']}</td>
  1079. <td>{$form['company']}</td>";
  1080. }
  1081. echo "</table>";
  1082. return $total;
  1083. }
  1084. function makeGroupsTable($query, $limit, $showLimit, $page=1) {
  1085. $matches = findGroupsByMatch($query, $limit, $page);
  1086. $count = $matches["count"];
  1087. $total = $matches["total"];
  1088. if($showLimit) {
  1089. echo "<b>Total number of results:</b> $total";
  1090. if($total > $limit) {
  1091. echo " (first $limit matches shown below; show ";
  1092. echo "<a href=\"findgroup.php?limit=10\">10</a>, ";
  1093. echo "<a href=\"findgroup.php?limit=20\">20</a>, ";
  1094. echo "<a href=\"findgroup.php?limit=50\">50</a>, ";
  1095. echo "<a href=\"findgroup.php?limit=100\">100</a>";
  1096. echo ")";
  1097. }
  1098. }
  1099. echo '<table cellpadding="0" cellspacing="0" class="alternate">';
  1100. echo "<tr> <th>Date</th> <th>Group Name</th> <th>Status</th> </tr>";
  1101. for($index = 0; $index < $count; $index += 1) {
  1102. $form = $matches[$index];
  1103. $created = explode(" ", $form["created"]);
  1104. $created = $created[0];
  1105. echo "<tr>
  1106. <td>$created</td>
  1107. <td><a href=\"editgroup.php?id=${form['id']}\">{$form['name']}</a></td>
  1108. <td>{$form['status']}</td>";
  1109. }
  1110. echo "</table>";
  1111. return $total;
  1112. }
  1113. /****************************************************************************/
  1114. function makeOrgAccountTable($orgid, $url) {
  1115. $accounts = findAccountsByOrg($orgid);
  1116. echo '<table cellpadding="0" cellspacing="0" class="alternate">';
  1117. echo "<thead>";
  1118. echo "<tr>
  1119. <th>Created</th>
  1120. <th>User ID</th>
  1121. <th>Role</th>
  1122. <th>Status</th>
  1123. <th>Action</th>
  1124. </tr>";
  1125. echo '</thead><tbody>';
  1126. echo "<form method=\"POST\" action=\"$url?orgid=$orgid\">";
  1127. echo '<tr><td>';
  1128. echo date("Y-m-d");
  1129. echo '</td>';
  1130. echo '<td><table style="border: 0px none ; border-spacing: 5px;"><tr><td style="background: white;">';
  1131. if(totalUserCount() < 9999 and totalGroupCount() < 9999) {
  1132. echo '<select id="userName" name="userName" style="width: 250px">';
  1133. echo "<option value=\"\">-- Select User / Group --</option>";
  1134. foreach(findAllGroupNames() as $name)
  1135. echo "<option value=\"$name\">$name (group)</option>\n";
  1136. echo "<option value=\"\">-- Registered Users --</option>";
  1137. foreach(findAllUserNames() as $name)
  1138. echo "<option>$name</option>\n";
  1139. echo "</select>";
  1140. } else {
  1141. echo '<input type="text" name="userName" class="text">';
  1142. }
  1143. echo '</td><td style="background: white; "></td></tr></table>';
  1144. echo '<td><select name="role" title="User Role">
  1145. <option value="admin">Administrator</option>
  1146. <option value="user">Member</option>
  1147. <option value="guest">Visitor</option>
  1148. </select></td>';
  1149. echo '<td>Invited</td>';
  1150. echo '<td>
  1151. <div class="button">
  1152. <input type="submit" value="Add Member">
  1153. </div>
  1154. </td>';
  1155. echo '</tr></form>';
  1156. foreach($accounts as $form) {
  1157. $created = explode(" ", $form["created"]);
  1158. $created = $created[0];
  1159. echo "<tr>\n<td>$created</td>\n";
  1160. if($form['type'] == 'user') {
  1161. echo "<td><a href=\"edituser.php?id={$form['userid']}\">{$form['userName']}</a></td>";
  1162. } else {
  1163. echo "<td><a href=\"editgroup.php?id={$form['userid']}\">{$form['userName']} (Group)</a></td>";
  1164. }
  1165. $isUser = $isGuest = $isAdmin = "";
  1166. if($form['role'] == "user") $isUser = "selected";
  1167. if($form['role'] == "guest") $isGuest = "selected";
  1168. if($form['role'] == "admin") $isAdmin = "selected";
  1169. echo "<td><select id=\"updateRole\" name=\"updateRole\" title=\"User Role\">
  1170. <option value=\"{$form['id']}|admin\" $isAdmin>Administrator</option>
  1171. <option value=\"{$form['id']}|user\" $isUser>User</option>
  1172. <option value=\"{$form['id']}|guest\" $isGuest>Visitor</option>
  1173. </select></td>";
  1174. $isInvited = $isActive = $isDeleted = "";
  1175. if($form['status'] == "Invited") $isInvited = "selected";
  1176. if($form['status'] == "Active") $isActive = "selected";
  1177. if($form['status'] == "Deleted") $isDeleted = "selected";
  1178. echo "<td><select id=\"updateStatus\" name=\"updateStatus\" title=\"User Status\">
  1179. <option value=\"{$form['id']}|Invited\" $isInvited>Invited</option>
  1180. <option value=\"{$form['id']}|Active\" $isActive>Active</option>
  1181. <option value=\"{$form['id']}|Deleted\" $isDeleted>Deactivated</option>
  1182. </select></td>";
  1183. echo "<td>
  1184. <form method=\"POST\" class=\"slimform\" action=\"deleteacct.php?id=${form['id']}&from=org\">
  1185. <div class=\"button\">
  1186. <input type=\"submit\" value=\"Remove Member\">
  1187. </div></form>
  1188. </td>";
  1189. echo "</tr>";
  1190. }
  1191. echo "</tbody>";
  1192. echo "</table>";
  1193. }
  1194. function makeGroupMemberTable($gid, $url) {
  1195. $accounts = findGroupAccountsByGroupId($gid);
  1196. echo '<table cellpadding="0" cellspacing="0" class="alternate">';
  1197. echo "<thead>";
  1198. echo "<tr>
  1199. <th>Created</th>
  1200. <th>Member</th>
  1201. <th>Status</th>
  1202. <th>Action</th>
  1203. </tr>";
  1204. echo '</thead><tbody>';
  1205. echo "<form method=\"POST\" action=\"$url?groupid=$gid\">";
  1206. echo '<tr><td>';
  1207. echo date("Y-m-d");
  1208. echo '</td>';
  1209. echo '<td><table style="border: 0px none ; border-spacing: 5px;"><tr><td style="background: white;">';
  1210. if(totalUserCount() < 9999) {
  1211. echo '<select id="userName" name="userName" style="width: 250px">';
  1212. echo "<option value=\"\">-- Select User --</option>";
  1213. foreach(findAllUserNames() as $name)
  1214. echo "<option>$name</option>\n";
  1215. echo "</select>";
  1216. echo "</select>";
  1217. } else {
  1218. echo '<input type="text" name="userName" class="text">';
  1219. }
  1220. echo '</td><td style="background: white; "></td></tr></table>';
  1221. echo '<td>Invited</td>';
  1222. echo '<td>
  1223. <div class="button">
  1224. <input type="submit" value="Add Member">
  1225. </div>
  1226. </td>';
  1227. echo '</tr></form>';
  1228. foreach($accounts as $form) {
  1229. $created = explode(" ", $form["created"]);
  1230. $created = $created[0];
  1231. echo "<tr>\n<td>$created</td>\n";
  1232. if($form['type'] == 'user') {
  1233. echo "<td><a href=\"edituser.php?id={$form['userid']}\">{$form['userName']}</a></td>";
  1234. } else {
  1235. echo "<td><a href=\"editgroup.php?id={$form['userid']}\">{$form['userName']} (Group)</a></td>";
  1236. }
  1237. $isInvited = $isActive = $isDeleted = "";
  1238. if($form['status'] == "Invited") $isInvited = "selected";
  1239. if($form['status'] == "Active") $isActive = "selected";
  1240. if($form['status'] == "Deleted") $isDeleted = "selected";
  1241. echo "<td><select id=\"updateStatus\" name=\"updateStatus\" title=\"User Status\">
  1242. <option value=\"{$form['id']}|Invited\" $isInvited>Invited</option>
  1243. <option value=\"{$form['id']}|Active\" $isActive>Active</option>
  1244. <option value=\"{$form['id']}|Deleted\" $isDeleted>Deactivated</option>
  1245. </select></td>";
  1246. echo "<td>
  1247. <form method=\"POST\" class=\"slimform\" action=\"deleteacct.php?id=${form['id']}&from=group\">
  1248. <div class=\"button\">
  1249. <input type=\"submit\" value=\"Remove Member\">
  1250. </div></form>
  1251. </td>";
  1252. echo "</tr>";
  1253. }
  1254. echo "</tbody>";
  1255. echo "</table>";
  1256. }
  1257. function makeGroupOwnerTable($groupid, $url) {
  1258. $groups = findOrgAccountsByGroupId($groupid);
  1259. echo '<table cellpadding="0" cellspacing="0" class="alternate">';
  1260. echo "<tr>
  1261. <th>Created</th>
  1262. <th>Organization</th>
  1263. <th>Role</th>
  1264. <th>Status</th>
  1265. <th>Action</th>
  1266. </tr>";
  1267. echo "<form method=\"POST\" action=\"$url?groupid=$groupid\">";
  1268. echo '<tr><td>';
  1269. echo date("Y-m-d");
  1270. echo '</td>';
  1271. echo '<td><table style="border: 0px none ; border-spacing: 5px;"><tr><td style="background: white;">';
  1272. if(totalOrgCount() < 9999) {
  1273. echo '<select id="orgName" name="orgName" style="width: 250px">';
  1274. echo "<option value=\"\">-- Select Organization --</option>";
  1275. foreach(findAllOrgNames() as $name)
  1276. echo "<option>$name</option>\n";
  1277. echo "</select>";
  1278. } else {
  1279. echo '<input type="text" name="userName" class="text">';
  1280. }
  1281. echo '</td><td style="background: white; "></td></tr></table>';
  1282. echo '<td><select name="role" title="User Role">
  1283. <option value="admin">Administrator</option>
  1284. <option value="user">Member</option>
  1285. <option value="guest">Visitor</option>
  1286. </select></td>';
  1287. echo '<td>Invited</td><td><div class="button"><input type="submit" value="Add Member"></div></td>';
  1288. echo '</tr></form>';
  1289. foreach($groups as $form) {
  1290. $created = explode(" ", $form["created"]);
  1291. $created = $created[0];
  1292. echo "<tr>
  1293. <td>$created</td>
  1294. <td><a href=\"editorg.php?id={$form['orgid']}\">{$form['orgName']}</a></td>";
  1295. $isUser = $isGuest = $isAdmin = "";
  1296. if($form['role'] == "user") $isUser = "selected";
  1297. if($form['role'] == "guest") $isGuest = "selected";
  1298. if($form['role'] == "admin") $isAdmin = "selected";
  1299. echo "<td><select id=\"updateRole\" name=\"updateRole\" title=\"User Role\">
  1300. <option value=\"{$form['id']}|admin\" $isAdmin>Administrator</option>
  1301. <option value=\"{$form['id']}|user\" $isUser>User</option>
  1302. <option value=\"{$form['id']}|guest\" $isGuest>Visitor</option>
  1303. </select></td>";
  1304. $isInvited = $isActive = $isDeleted = "";
  1305. if($form['status'] == "Invited") $isInvited = "selected";
  1306. if($form['status'] == "Active") $isActive = "selected";
  1307. if($form['status'] == "Deleted") $isDeleted = "selected";
  1308. //$statusClass = strtolower($form['status']);
  1309. echo "<td><select id=\"updateStatus\" name=\"updateStatus\" title=\"User Status\">
  1310. <option value=\"{$form['id']}|Invited\" $isInvited>Invited</option>
  1311. <option value=\"{$form['id']}|Active\" $isActive>Active</option>
  1312. <option value=\"{$form['id']}|Deleted\" $isDeleted>Deactivated</option>
  1313. </select></td>";
  1314. echo "<td>
  1315. <form method=\"POST\" class=\"slimform\" action=\"deleteacct.php?id=${form['id']}&from=group\">
  1316. <div class=\"button\">
  1317. <input type=\"submit\" value=\"Remove Member\">
  1318. </div></form>
  1319. </td>";
  1320. echo "</tr>";
  1321. }
  1322. echo "</table>";
  1323. }
  1324. function makeUserAccountTable($userid, $url) {
  1325. $accounts = findAccountsByUser($userid);
  1326. $groups = findGroupAccountsByUser($userid);
  1327. echo '<table cellpadding="0" cellspacing="0" class="alternate">';
  1328. echo "<thead><tr>
  1329. <th>Created</th>
  1330. <th>Organization</th>
  1331. <th>Role</th>
  1332. <th>Status</th>
  1333. <th>Action</th>
  1334. </tr></thead><tbody>";
  1335. echo "<form method=\"POST\" action=\"$url?userid=$userid\">";
  1336. echo '<tr><td>';
  1337. echo date("Y-m-d");
  1338. echo '</td>';
  1339. echo '<td><table style="border: 0px none ; border-spacing: 5px;"><tr><td style="background: white;">';
  1340. if(totalOrgCount() < 9999 and totalGroupCount() < 9999) {
  1341. echo '<select id="orgName" name="orgName" style="width: 250px">';
  1342. echo "<option value=\"\">-- Select Group / Organization --</option>";
  1343. foreach(findAllGroupNames() as $name)
  1344. echo "<option value=\"$name\">$name (group)</option>\n";
  1345. echo "<option value=\"\">-- Organizations --</option>";
  1346. foreach(findAllOrgNames() as $name)
  1347. echo "<option>$name</option>\n";
  1348. echo "</select>";
  1349. } else {
  1350. echo '<input type="text" name="userName" class="text">';
  1351. }
  1352. echo '</td><td style="background: white; "></td></tr></table>';
  1353. echo '<td><select name="role" title="User Role">
  1354. <option value="admin">Administrator</option>
  1355. <option value="user">Membe

Large files files are truncated, but you can click here to view the full file