function users_contact_tool($params) { $defaults = array('uri' => 'users/contact', 'omit' => array(), 'fields' => array(), 'title' => "Contact Info", 'collapsed' => false, 'toggle' => false, 'editing' => true, 'complete' => true, 'inProcess' => false, 'prompt' => "In order for things to work, we must be able to reach you.", 'button_content' => 'OK'); extract(array_merge($defaults, $params)); $default_fields = array('first_name' => array('type' => 'text', 'label' => 'First Name'), 'last_name' => array('type' => 'text', 'label' => 'Last Name'), 'email_address' => array('type' => 'text', 'label' => 'Email')); $fields = array_merge($default_fields, $fields); $user = Users::loggedInUser(); if (!$user) { throw new Users_Exception_NotLoggedIn(); } $email = null; $missing_fields = Users::accountStatus($email); if (isset($user->first_name)) { $fields['first_name']['value'] = $user->first_name; } if (isset($user->last_name)) { $fields['last_name']['value'] = $user->last_name; } if (isset($user->email_address)) { $fields['email_address']['value'] = $user->email_address; } else { if ($email) { $link = Pie_Html::a('#resend', array('class' => 'users_contact_tool_resend'), "You can re-send the activation email"); switch ($email->state) { case 'active': if ($email->user_id == $user->id) { $message = "Please confirm this email address.<br>{$link}"; } else { $message = "This email seems to belong to another user"; } break; case 'suspended': $message = "This address has been suspended."; break; case 'unsubscribed': $message = "The owner of this address has unsubscribed"; break; case 'unverified': default: $message = "Not verified yet.<br>{$link}"; break; } $fields['email_address']['value'] = $email->address; $fields['email_address']['message'] = $message; } } $on_success = isset($_REQUEST['_pie']['onSuccess']) ? $_REQUEST['_pie']['onSuccess'] : Pie_Request::url(); Pie_Response::addScript('plugins/users/js/Users.js'); $form = $static = compact('fields'); return Pie::tool('pie/panel', compact('uri', 'on_success', 'form', 'static', 'title', 'collapsed', 'toggle', 'complete', 'editing', 'inProcess', '_form_static')); }
function users_account_tool($params) { $defaults = array('uri' => 'users/account', 'omit' => array(), 'fields' => array(), 'title' => "Basic Info", 'editing' => true, 'complete' => true, 'inProcess' => false, 'collapsed' => false, 'toggle' => false); extract(array_merge($defaults, $params)); $default_fields = array('username' => array('type' => 'text', 'label' => 'Choose Username'), 'gender' => array('type' => 'select', 'label' => 'I am', 'options' => array('male' => 'a man', 'female' => 'a woman')), 'orientation' => array('type' => 'select', 'label' => 'Orientation', 'options' => array('straight' => 'straight', 'gay' => 'gay', 'bi' => 'bi')), 'relationship_status' => array('type' => 'select', 'label' => 'Status', 'options' => array('single' => "I'm single", 'open' => "I'm in an open relationship", 'relationship' => "I'm in a relationship", 'engaged' => "I'm engaged", 'married' => "I'm married", 'complicated' => "It's complicated", 'widowed' => "I'm widowed")), 'birthday' => array('type' => 'date', 'label' => 'My Birthday', 'options' => array('year_from' => '1920', 'year_to' => date('Y') - 16)), 'zipcode' => array('type' => 'text', 'label' => 'Zipcode', 'attributes' => array('maxlength' => 5))); $fields = array_merge($default_fields, $fields); $user = Users::loggedInUser(); if (!$user) { throw new Users_Exception_NotLoggedIn(); } if (isset($user->gender)) { $fields['gender']['value'] = $user->gender; } if (isset($user->desired_gender)) { if ($user->desired_gender == 'either') { $fields['orientation']['value'] = 'bi'; } else { if (isset($user->gender)) { $fields['orientation']['value'] = $user->gender != $user->desired_gender ? 'straight' : 'gay'; } } } if (isset($user->relationship_status)) { $fields['relationship_status']['value'] = $user->relationship_status; } if (isset($user->birthday)) { $fields['birthday']['value'] = date("Y-m-d", Users::db()->fromDate($user->birthday)); } if (isset($user->zipcode)) { $fields['zipcode']['value'] = $user->zipcode; } if (isset($user->username)) { $fields['username']['value'] = $user->username; } foreach ($omit as $v) { unset($fields[$v]); } $on_success = isset($_REQUEST['_pie']['onSuccess']) ? $_REQUEST['_pie']['onSuccess'] : Pie_Request::url(); Pie_Response::addScript('plugins/users/js/Users.js'); $form = $static = compact('fields'); return Pie::tool('pie/panel', compact('uri', 'title', 'form', 'static', 'on_success', 'complete', 'collapsed', 'toggle', 'editing', 'inProcess', '_form_static')); }
function users_account_response_content() { Pie_Session::start(); return Pie::tool('users/account'); }
function users_contact_response_form() { // Calling this will fill the slots Pie::tool('users/contact', array('_form_static' => true), array('inner' => true)); return true; }
function items_addPhoto_response_photo_list() { if (!isset($_REQUEST['aid'])) { throw new Pie_Exception_RequiredField(array('field' => 'aid')); } return Pie::tool('items/addPhoto', array('aid' => $_REQUEST['aid'], 'tool_part' => 'photo_list'), array('inner' => true)); }
function users_contact_response_content() { Pie_Session::start(); return Pie::tool('users/contact'); }
/** * This tool generates a panel with a <form> tag inside it * @param array $params * An associative array of parameters, containing: * "uri" => the uri or url the form should post to * "title" => the title of the panel * "complete" => boolean, indicating whether the data on the server is in a complete state * "editing" => boolean, indicating whether to show the form in the "editing" state * "form" => string containing the contents of the form portion of the panel * which is normally generated by a "pie/form" tool * "static" => string containing the contents of the "static" portion * "collapsed" => defaults to false. Whether the panel is shown as collapsed into just the header * "toggle" => defaults to false. The events that cause toggling of collapsed state. * If the string is 'click' then toggles the panel on clicks. * If the string is 'move' then toggles the panel on mouseenter/mouseleave. * "edit_button" => optional, to override the edit button * "save_button" => optional, to override the save button * "cancel_button" => optional, to override the cancel button * "panel_classes" => optional, additional classes for the panel * "snf" => optional. The name of the nonce field in the session * "on_success" => optional. The URI to redirect to on success * "on_errors" => optional. The URI to display if errors occur * "inProcess" => optional. Causes the panel to appear as if it's a step in a process. */ function pie_panel_tool($params) { foreach (array('title', 'complete', 'editing', 'static', 'form') as $f) { if (!array_key_exists($f, $params)) { throw new Pie_Exception_RequiredField(array('field' => '$' . $f)); } } $defaults = array('edit_button' => "<button type='submit' class='basic16 basic16_edit pie_panel_tool_edit'>edit</button>", 'save_button' => "<button type='submit' class='basic16 basic16_check pie_panel_tool_save'>save</button>", 'cancel_button' => "<button type='reset' class='basic16 basic16_cancel pie_panel_tool_cancel'>cancel</button>", 'panel_classes' => '', 'uri' => null, 'collapsed' => false, 'toggle' => false, 'inProcess' => false, 'on_success' => null, 'on_errors' => null, 'snf' => null); extract(array_merge($defaults, $params)); $more_class = $params['complete'] ? 'pie_panel_tool_complete' : 'pie_panel_tool_incomplete'; $panel_classes = "{$more_class} {$panel_classes}"; $title_div = "<div class='pie_panel_tool_title'>{$title}</div>"; if ($uri) { $header = "<div class='pie_panel_tool_buttons'>{$save_button}{$cancel_button}{$edit_button}</div>{$title_div}"; } else { $header = $title_div; } // Whether to display the panel one way or the other if ($inProcess) { $header = $title_div; if (is_array($form)) { $form['fields']['_pie_buttons'] = array('type' => 'buttons', 'label' => '', 'options' => array('continue' => 'Continue'), 'attributes' => array('class' => 'basic32 basic32_right', 'type' => 'submit')); } else { $form .= "<div class='pie_panel_tool_formbuttons'><button type='submit' class='pie_panel_tool_continue basic32 basic32_right' value='continue'>Continue</button></div>"; } } // Turn the static into a string, if it's an array // This currently doesn't work well, because it causes // a bug where the outer form is submitted twice. if (is_array($static)) { foreach ($static['fields'] as $k => $f) { if (Pie::ifset($static['fields'][$k]['type'])) { switch ($static['fields'][$k]['type']) { case 'textarea': $static['fields'][$k]['value'] = str_replace("\n", "<br>", $static['fields'][$k]['value']); break; case 'date': if (!isset($static['fields'][$k]['options']['date'])) { $static['fields'][$k]['options']['date'] = "M j, Y"; } break; case 'buttons': unset($static['fields'][$k]); } } $static['fields'][$k]['type'] = 'static'; } $static = Pie::tool('pie/form', $static, array('id' => 'static')); } // Turn the form into a form if (is_array($form)) { $form = Pie::tool('pie/form', $form); } // Build the panel $panel = "<div class='pie_panel_tool_header'>{$header}</div>" . "<div class='pie_panel_tool_form'>{$form}</div>"; if (isset($snf) or isset($on_success) or isset($on_errors)) { $panel .= "<div>" . Pie_Html::formInfo($on_success, $on_errors, $snf) . "</div>"; } if ($uri) { $panel = Pie_Html::form($uri, 'post', array('class' => "pie_panel_tool_panel"), $panel); } $panel .= "<div class='pie_panel_tool_static'>{$static}</div>"; if ($editing) { $panel_classes .= ' pie_editing'; } if ($complete) { $panel_classes .= ' pie_complete'; } if ($collapsed) { $panel_classes .= ' pie_collapsed'; } if ($toggle === 'click') { $panel_classes .= ' pie_panel_tool_toggle_onclick'; } if ($toggle === 'move') { $panel_classes .= ' pie_panel_tool_toggle_move'; } Pie_Response::addScript('plugins/pie/js/PieTools.js'); Pie_Response::addStylesheet('plugins/pie/css/Ui.css'); if (isset($_form_static)) { Pie_Response::setSlot('form', $form); Pie_Response::setSlot('static', $static); } return "<div class='pie_panel_tool_container {$panel_classes}'>{$panel}</div>"; }