daily pastebin goal
95%
SHARE
TWEET

PP: PF Podio Portal Demo 1

globiws Jun 25th, 2018 (edited) 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ppdemo_portal_1.php
  2. // simple portal with user/pass auth
  3.  
  4. //config
  5. $publicPage = "http://globi.ca/ppdemo_portal_1.php";
  6. $user_app_id = 12345;
  7. $user_app_email_field = "title";
  8. $user_app_pass_field = "md5-password";
  9. $project_app_id = 23456;
  10. // end config
  11.  
  12. // pre work
  13. $data = @json_decode($pf_payload, true);
  14. $pfsessid = false;
  15. $userEmail = false;
  16. $html = '';
  17.  
  18. // if we're returning from our login, pfsessid is in POST and not GET
  19. if ( isset($data['POST']['pfsessid']) ) $data['GET']['pfsessid'] = $data['POST']['pfsessid'];
  20.  
  21. // make sure we have a valid session ID
  22. if ( ! isset($data['GET']) || ! isset($data['GET']['pfsessid']) ) return "Bad Session ID";
  23. $pfsessid = $data['GET']['pfsessid'];
  24. pf_session_start($pfsessid);
  25. $session = pf_session_get();
  26. $localUrl = "https://procfu.com/widgets/html/".$data['widget_id']."&pfsessid=".$pfsessid;
  27.  
  28. // add styles
  29. $html .= <<<'EOF'
  30. <style>
  31. .pf-form { width: 100%; max-width: 900px; }
  32. .pf-form .pf-info { padding: 2px 5px; margin: 2px 5px; }
  33. .pf-form .pf-error { padding: 10px 15px; margin: 2px 5px; background: red; color: white; }
  34. .pf-form .pf-form-row { padding: 2px 5px; margin: 2px 5px; border: 1px solid #eee; }
  35. .pf-form .pf-label { display: inline-block; width: 30%; vertical-align: top; padding-top: 2px; }
  36. .pf-form .pf-value, .pf-form-row .pf-input { display: inline-block; width: 70%; color: #333; min-height: 32px; }
  37. .pf-form .pf-input[readonly] { color: #999; }
  38. .pf-form .pf-selector { border: 1px solid #999; cursor: pointer; padding: 2px 5px; white-space: normal; min-height: 32px; color: #333; }
  39. .pf-form .pf-button { cursor: pointer; }
  40. .pf-form .pf-button.pf-disabled { cursor: default; }
  41. .pf-comment { margin-bottom: 5px; padding-bottom: 5px; border-bottom: 1px solid #444; }
  42. .pf-comment .pf-whowhen { text-decoration: underline; }
  43. </style>
  44. <style>
  45. .maintab { width: 100%; max-width: 900px; }
  46. .maintab td { vertical-align: top; }
  47. .projlink { display: inline-block; width: 250px; background: #eee; border: 1px solid #ddd; padding: 5px 10px; margin: 2px 10px; }
  48. .commentblock  { padding: 2px 5px; margin: 2px 5px; border: 1px solid #444; }
  49. .profile { text-align:right; padding: 2px 5px; background: #f8f8f8; border: 1px solid #eee; width: 20%; }
  50. </style>
  51. EOF;
  52.  
  53. // add PF javascript
  54. $html .= pf_ui_include_js();
  55.  
  56. // are we logging out
  57. if ( isset($data['GET']['logout']) ) {
  58.     pf_session_set([]);
  59.     return '<script>document.location.href="'.$publicPage.'";</script>';
  60. }
  61.  
  62. // check if we're returning from login
  63. if ( isset($data['POST']) && isset($data['POST']['user']) ) {
  64.     $user = $data['POST']['user'];
  65.     $pass = @$data['POST']['pass'];
  66.     $session['tempuser'] = $user;
  67.     $session['temppass'] = $pass;
  68.     pf_session_set($session);
  69.     return '<script>document.location.href="'.$publicPage.'";</script>';
  70. }
  71.  
  72. // return from login pt 2
  73. if ( isset($session['tempuser']) ) {
  74.     $user = trim(strtolower($session['tempuser']));
  75.     $pass = trim(strtolower($session['temppass']));
  76.     unset($session['tempuser']);
  77.     unset($session['temppass']);
  78.     pf_session_set($session);
  79.     $foo = @json_decode(call_pf_script("podio_search_app.pf", ["app_id" => $user_app_id, "field_id" => $user_app_email_field, "search_val" => $user, "condition" => "E", "max_results" => 1]), true);
  80.     if ( ! is_array($foo) || sizeof($foo) == 0 ) return "<h3>Error</h3><p>Invalid Credentials (1)</p>";
  81.     $bar = pf_podio_item_as_field_array($foo[0]);
  82.     if ( $bar[$user_app_email_field] != $user) return "<h3>Error</h3><p>Invalid Credentials (2)</p>";
  83.     if ( $bar[$user_app_pass_field] != md5($pass) ) return "<h3>Error</h3><p>Invalid Credentials (3)</p>";
  84.     // login was successful
  85.     $userEmail = $user;
  86.     $userRecordId = $foo[0]['item_id'];
  87.     $session['userRecordId'] = $userRecordId;
  88.     $session['userEmail'] = $userEmail;
  89.     pf_session_set($session);
  90. }
  91.  
  92. // page: create account
  93. if ( isset($data['GET']['create']) ) {
  94.     $html .= '<h3>Reset Account</h3>';
  95.     $html .= '<p>Use this Podio Webform to create a new account or reset the password of your current account.</p>';
  96.     $html .= '<p>A new password will be emailed to you.</p>';
  97.     $html .= '<iframe src="https://podio.com/webforms/21113746/1459417" style="width:700px;height:500px;border:0">';
  98.     $html .= '</iframe>';
  99.     return $html;
  100. }
  101.  
  102. // check if we're logged in
  103. if ( ! isset($session['userEmail']) ) {
  104.     $html .= '<h3>Login Required</h3>';
  105.     $html .= '<form class="pf-form" method="POST" action="'.$localUrl.'">';
  106.     $html .= '<input type="hidden" name="pfsessid" value="'.$pfsessid.'">';
  107.     $html .= '<div class="pf-form-row">';
  108.     $html .= '<label class="pf-label" for="user">Email Address</label>';
  109.     $html .= '<input class="pf-input" type="text" name="user" id="user">';
  110.     $html .= '</div>';
  111.     $html .= '<div class="pf-form-row">';
  112.     $html .= '<label class="pf-label" for="user">Password</label>';
  113.     $html .= '<input class="pf-input" type="password" name="pass" id="pass">';
  114.     $html .= '</div>';
  115.     $html .= '<div class="form-row">';
  116.     $html .= '<label class="pf-label" for="submit"></label>';
  117.     $html .= '<input class="pf-input" type="submit" name="submit" id="submit" value="Log In">';
  118.     $html .= '</div>';
  119.     $html .= '</form>';
  120.     $html .= '<p style="margin-top: 25px; text-align: center"><a href="'.$publicPage.'?create">Create Account</a> or <a href="'.$publicPage.'?create">Reset Password</a></p>';
  121.     return $html;
  122. }
  123.  
  124. // OK - we're logged in
  125. $userEmail = $session['userEmail'];
  126. $userRecordId = $session['userRecordId'];
  127.  
  128. // do we have a project list?
  129. if ( ! isset($session['projects']) ) {
  130.     $ret = @json_decode(call_pf_script("item_get_referenced.pf", ["podio_item_id" => $userRecordId]), true);
  131.     if ( $ret === null ) return "<h3>Error</h3><p>An unexpected error has occured (4)</p>";
  132.     $session['projects'] = [];
  133.     foreach ( $ret as $ref ) {
  134.         if ( $ref['app']['app_id'] == $project_app_id ) {
  135.             foreach ( $ref['items'] as $item ) {
  136.                 $session['projects'][] = ["item_id"=>$item['item_id'], "title"=>$item['title']];
  137.             }
  138.         }
  139.     }
  140.     pf_session_set($session);
  141. }
  142.  
  143. // page: edit profile
  144. if ( isset($data['GET']['editprofile']) ) {
  145.     if ( ! isset($session['userapp']) ) {
  146.         $ret = @json_decode(call_pf_script("podio_app_get_raw.pf", ["app_id" => $user_app_id]),true);
  147.         if ( $ret === null ) return "<h3>Error</h3><p>An unexpected error has occured (4)</p>";
  148.         $session['userapp'] = $ret;
  149.         pf_session_set($session);
  150.     }
  151.     $userRecord = @json_decode(call_pf_script("podio_item_get_raw.pf", ["podio_item_id" => $session['userRecordId']]), true);
  152.     if ( $userRecord === null ) return "<h3>Error</h3><p>Could not retrieve user record.</p>";
  153.     $html .= '<h3>Edit Profile</h3>';
  154.     $ui = new pf_ui_item($session['userapp'], $userRecord);
  155.     $ui->setMode("edit");
  156.     $ui->setSuccessUrl($publicPage);
  157.     $ui->setFields(["title", "name", "about", "podio-user-type"]);
  158.     $ui->setReadOnly(["title"]);
  159.     $html .= $ui->render();
  160.     return $html;
  161. }
  162.  
  163. // page: view project
  164. if ( isset($data['GET']['project']) ) {
  165.     $projid = intval($data['GET']['project']);
  166.     // make sure we're allowed to view this
  167.     $projlist = array_column($session['projects'], "item_id");
  168.     if ( ! in_array($projid, $projlist) ) return "<h3>Error</h3><p>You are not authorized to view that project.</p>";
  169.     if ( ! isset($session['projapp']) ) {
  170.         $ret = @json_decode(call_pf_script("podio_app_get_raw.pf", ["app_id" => $project_app_id]),true);
  171.         if ( $ret === null ) return "<h3>Error</h3><p>An unexpected error has occured (5)</p>";
  172.         $session['projapp'] = $ret;
  173.         pf_session_set($session);
  174.     }
  175.     $project = @json_decode(call_pf_script("podio_item_get_raw.pf", ["podio_item_id" => $projid]), true);
  176.     if ( $project === null ) return "<h3>Error</h3><p>Could not retrieve project.</p>";
  177.     $html .= '<h3>Project: '.$project['title'].'</h3>';
  178.     $ui = new pf_ui_item($session['projapp'], $project);
  179.     $ui->setMode("view");
  180.     $ui->setSuccessUrl($publicPage);
  181.     $ui->setFields(["title", "status", "details"]);
  182.     $ui->setShowFiles(true);
  183.     $html .= $ui->render();
  184.     $html .= '<form class="pf-form"><div class="pf-form-row"><div class="pf-label"><b>Comments</b></div><div class="pf-value">';
  185.     $ui->setAppNameReplace("You (".$userEmail.")");
  186.     $html .= $ui->getComments();
  187.     $html .= '</div></div></form>';
  188.     $ui = new pf_ui_comment($session['projapp'], $project);
  189.     $ui->setAllowFiles(true);
  190.     $html .= $ui->render();
  191.     return $html;
  192. }
  193.  
  194. // page: NEW project
  195. if ( isset($data['GET']['newproject']) ) {
  196.     if ( ! isset($session['projapp']) ) {
  197.         $ret = @json_decode(call_pf_script("podio_app_get_raw.pf", ["app_id" => $project_app_id]),true);
  198.         if ( $ret === null ) return "<h3>Error</h3><p>An unexpected error has occured (5)</p>";
  199.         $session['projapp'] = $ret;
  200.         pf_session_set($session);
  201.     }
  202.     $html .= '<h3>Create New Project</h3>';
  203.     $ui = new pf_ui_item($session['projapp'], null);
  204.     $ui->setMode("create");
  205.     $ui->setSuccessUrl($publicPage);
  206.     $ui->setFields(["title", "status", "details", "customer"]);
  207.     $ui->setValue("customer", $userRecordId);
  208.     $ui->setValue("status", "New");
  209.     $ui->setHidden(["customer", "status"]);
  210.     $ui->setAllowFiles(true);
  211.     $html .= $ui->render();
  212.     unset($session['projects']);
  213.     pf_session_set($session);
  214.     return $html;
  215. }
  216.  
  217.  
  218. $html .= '<table class="maintab"><tr><td>';
  219. $html .= '<h5>My Projects</h5>';
  220. if ( sizeof($session['projects']) == 0 ) {
  221.     $html .= '<p>You do not have any current projects</p>';
  222. } else {
  223.     foreach ( $session['projects'] as $project ) {
  224.         $html .= '<p><a class="projlink" href="?project='.$project['item_id'].'">';
  225.         $html .= $project['title'].'</a></p>';
  226.     }
  227. }
  228. $html .= '<p><a href="?newproject">+ New Project</a></p>';
  229.  
  230. $html .= '</td><td class="profile">';
  231.  
  232. $html .= 'Logged in as:<br>'.$userEmail.'<br>';
  233. $html .= '<a href="?editprofile">Edit Profile</a><br>';
  234. $html .= '<a href="?logout">Log Out</a>';
  235.  
  236. $html .= '</td></tr></table>';
  237.  
  238. return $html;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top