diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 00000000..8f20e7c9
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,280 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+.
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+.
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+.
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+.
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/admin/account/index.php b/admin/account/index.php
new file mode 100644
index 00000000..fbc3564b
--- /dev/null
+++ b/admin/account/index.php
@@ -0,0 +1,89 @@
+checkAuth("admin");
+
+$LANG = Core::$L;
+
+// update the administrator's account
+$success = true;
+$message = "";
+if (isset($_POST) && !empty($_POST)) {
+ list($success, $message) = Administrator::updateAdminAccount($_POST, Core::$user->getAccountId());
+
+ // if the user just changed their language file, reset the value in sessions and refresh the page
+ if ($success && ($_POST["old_ui_language"] != $_POST["ui_language"])) {
+ Sessions::set("ui_language", $_POST["ui_language"]);
+ General::redirect("index.php?updated");
+ }
+}
+
+// here, the user has just changed their ui language
+if (isset($_GET["updated"])) {
+ $success = true;
+ $message = $LANG["notify_account_updated"];
+}
+
+$admin_info = Administrator::getAdminInfo();
+
+$replacement_info = array("datefunctionlink" => 'date()');
+$LANG = Core::$L;
+
+// compile the theme variables
+$page_vars = array(
+ "page" => "your_account",
+ "g_success" => $success,
+ "g_message" => $message,
+ "page_url" => Pages::getPageUrl("your_account"),
+ "head_title" => $LANG["phrase_your_account"],
+ "admin_info" => $admin_info,
+ "text_date_formatting_link" => General::evalSmartyString($LANG["text_date_formatting_link"], $replacement_info)
+);
+
+$page_vars["head_js"] =<< 0 && $(swatch_id).val() == "") {
+ return [[$(swatch_id)[0], "{$LANG["validation_no_theme_swatch"]}"]];
+ }
+ return true;
+ }
+
+ function validate_username() {
+ var username = $("input[name=username]").val();
+ if (username.match(/[^\.@a-zA-Z0-9_]/)) {
+ return [[$("input[name=username]")[0], "{$LANG['validation_invalid_admin_username']}"]];
+ }
+ return true;
+ }
+
+ $(function() { document.login_info.first_name.focus(); });
+END;
+
+Themes::displayPage("admin/account/index.tpl", $page_vars);
diff --git a/admin/clients/add.php b/admin/clients/add.php
new file mode 100644
index 00000000..84a7243d
--- /dev/null
+++ b/admin/clients/add.php
@@ -0,0 +1,94 @@
+checkAuth("admin");
+
+$post_values = array();
+
+$success = true;
+$message = "";
+if (isset($_POST) && !empty($_POST['add_client'])) {
+ list($success, $message, $new_account_id) = Administrator::addClient($request);
+
+ // if added, redirect to the manage client page
+ if ($success) {
+ General::redirect("edit.php?page=main&client_id=$new_account_id");
+ exit;
+ } else {
+ $post_values = $_POST;
+ }
+}
+
+$LANG = Core::$L;
+$settings = Settings::get();
+$conditional_validation = array();
+if (!empty($settings["min_password_length"])) {
+ $rule = General::evalSmartyString($LANG["validation_client_password_too_short"], array("number" => $settings["min_password_length"]));
+ $conditional_validation[] = "rules.push(\"if:password!=,length>={$settings["min_password_length"]},password,$rule\");";
+}
+
+$required_password_chars = explode(",", $settings["required_password_chars"]);
+if (in_array("uppercase", $required_password_chars)) {
+ $conditional_validation[] = "rules.push(\"if:password!=,reg_exp,password,[A-Z],{$LANG["validation_client_password_missing_uppercase"]}\")";
+}
+if (in_array("number", $required_password_chars)) {
+ $conditional_validation[] = "rules.push(\"if:password!=,reg_exp,password,[0-9],{$LANG["validation_client_password_missing_number"]}\")";
+}
+if (in_array("special_char", $required_password_chars)) {
+ $error = General::evalSmartyString($LANG["validation_client_password_missing_special_char"], array("chars" => $g_password_special_chars));
+ $password_special_chars = preg_quote($g_password_special_chars);
+ $conditional_validation[] = "rules.push(\"if:password!=,reg_exp,password,[$password_special_chars],$error\")";
+}
+$conditional_rules = implode("\n", $conditional_validation);
+$core_password_special_chars = Core::getRequiredPasswordSpecialChars();
+
+
+$head_js =<< "add_client",
+ "g_success" => $success,
+ "g_message" => $message,
+ "page_url" => Pages::getPageUrl("add_client"),
+ "head_title" => $LANG["phrase_add_client"],
+ "required_password_chars" => $required_password_chars,
+ "password_special_chars" => $core_password_special_chars,
+ "has_extra_password_requirements" => (!empty($settings["required_password_chars"]) || !empty($settings["min_password_length"])),
+ "has_min_password_length" => !empty($settings["min_password_length"]),
+ "password_special_char" => General::evalSmartyString($LANG["phrase_password_special_char"], array("chars" => $core_password_special_chars)),
+ "phrase_password_min" => General::evalSmartyString($LANG["phrase_password_min"], array("length" => $settings["min_password_length"])),
+ "vals" => $post_values,
+ "head_js" => $head_js
+);
+
+Themes::displayPage("admin/clients/add.tpl", $page_vars);
diff --git a/admin/clients/edit.php b/admin/clients/edit.php
new file mode 100644
index 00000000..06096246
--- /dev/null
+++ b/admin/clients/edit.php
@@ -0,0 +1,63 @@
+checkAuth("admin");
+
+$LANG = Core::$L;
+
+$client_id = General::loadField("client_id", "curr_client_id", "");
+if (empty($client_id)) {
+ General::redirect("index.php");
+}
+
+// figure out the "<< prev" and "next >>" links
+$order = General::loadField("order", "client_sort_order", "last_name-ASC");
+$keyword = General::loadField("keyword", "client_search_keyword", "");
+$status = General::loadField("status", "client_search_status", "");
+
+// store the current selected tab in memory
+$page = General::loadField("page", "client_{$client_id}_page", "main");
+
+$search_criteria = array(
+ "order" => $order,
+ "keyword" => $keyword,
+ "status" => $status
+);
+
+$links = Clients::getClientPrevNextLinks($client_id, $search_criteria);
+
+$prev_tabset_link = (!empty($links["prev_account_id"])) ? "edit.php?page=$page&client_id={$links["prev_account_id"]}" : "";
+$next_tabset_link = (!empty($links["next_account_id"])) ? "edit.php?page=$page&client_id={$links["next_account_id"]}" : "";
+
+$same_page = General::getCleanPhpSelf();
+$tabs = array(
+ "main" => array("tab_label" => $LANG["word_main"], "tab_link" => "{$same_page}?page=main&client_id={$client_id}"),
+ "settings" => array("tab_label" => $LANG["word_settings"], "tab_link" => "{$same_page}?page=settings&client_id={$client_id}"),
+ "forms" => array("tab_label" => $LANG["word_forms"], "tab_link" => "{$same_page}?page=forms&client_id={$client_id}")
+);
+
+// start compiling the page vars here (save duplicate code!)
+$page_vars = array();
+$page_vars["tabs"] = $tabs;
+$page_vars["show_tabset_nav_links"] = true;
+$page_vars["prev_tabset_link"] = $prev_tabset_link;
+$page_vars["next_tabset_link"] = $next_tabset_link;
+$page_vars["prev_tabset_link_label"] = $LANG["phrase_prev_client"];
+$page_vars["next_tabset_link_label"] = $LANG["phrase_next_client"];
+
+$map = array(
+ "main" => "page_main.php",
+ "settings" => "page_settings.php",
+ "forms" => "page_forms.php"
+);
+if (isset($map[$page])) {
+ require_once($map[$page]);
+} else {
+ require_once($map["main"]);
+}
diff --git a/admin/clients/index.php b/admin/clients/index.php
new file mode 100644
index 00000000..dd086ebc
--- /dev/null
+++ b/admin/clients/index.php
@@ -0,0 +1,89 @@
+checkAuth("admin");
+
+$success = true;
+$message = "";
+if (isset($_GET['delete']) && !empty($_GET['client_id'])) {
+ list($success, $message) = Clients::deleteClient($_GET['client_id']);
+}
+if (isset($_GET['login'])) {
+ Administrator::loginAsClient($_GET['login']);
+}
+
+if (isset($_GET["reset"])) {
+ Sessions::set("client_sort_order", "");
+ Sessions::set("client_search_keyword", "");
+ Sessions::set("client_search_status", "");
+}
+$order = General::loadField("order", "client_sort_order", "last_name-ASC");
+$keyword = General::loadField("keyword", "client_search_keyword", "");
+$status = General::loadField("status", "client_search_status", "");
+
+$search_criteria = array(
+ "order" => $order,
+ "keyword" => $keyword,
+ "status" => $status
+);
+$num_clients = Clients::getNumClients();
+
+// retrieve all client information
+$clients = Clients::searchClients($search_criteria);
+$LANG = Core::$L;
+
+
+$head_js =<<< END
+ var page_ns = {};
+ page_ns.dialog = $("");
+ page_ns.delete_client = function(account_id) {
+ ft.create_dialog({
+ dialog: page_ns.dialog,
+ title: "{$LANG["phrase_please_confirm"]}",
+ content: "{$LANG["validation_check_delete_client"]}",
+ popup_type: "warning",
+ buttons: [
+ {
+ text: "{$LANG["word_yes"]}",
+ click: function() {
+ window.location = "index.php?delete=1&client_id=" + account_id;
+ }
+ },
+ {
+ text: "{$LANG["word_no"]}",
+ click: function() {
+ $(this).dialog("close");
+ }
+ }
+ ]
+ });
+ return false;
+ }
+END;
+
+$page = array(
+ "page" => "clients",
+ "g_success" => $success,
+ "g_message" => $message,
+ "page_url" => Pages::getPageUrl("clients"),
+ "head_title" => $LANG["word_clients"],
+ "num_clients" => $num_clients,
+ "clients" => $clients,
+ "order" => $order,
+ "search_criteria" => $search_criteria,
+ "pagination" => General::getJsPageNav(count($clients), Sessions::get("settings.num_clients_per_page"), 1),
+ "js_messages" => array("phrase_delete_row"),
+ "head_js" => $head_js
+);
+
+Themes::displayPage("admin/clients/index.tpl", $page);
diff --git a/admin/clients/page_forms.php b/admin/clients/page_forms.php
new file mode 100644
index 00000000..2f84d369
--- /dev/null
+++ b/admin/clients/page_forms.php
@@ -0,0 +1,102 @@
+ true,
+ "status" => ""
+));
+
+$forms_js_rows = array();
+$forms_js_rows[] = "var page_ns = {}";
+$forms_js_rows[] = "page_ns.forms = []";
+$form_views_js_info = array("page_ns.form_views = []");
+
+// convert ALL form and View info into Javascript, for use in the page
+foreach ($forms as $form_info) {
+ // ignore those forms that aren't set up
+ if ($form_info["is_complete"] == "no") {
+ continue;
+ }
+
+ $form_id = $form_info["form_id"];
+ $form_name = htmlspecialchars($form_info["form_name"]);
+ $forms_js_rows[] = "page_ns.forms.push([$form_id, \"$form_name\"])";
+
+ $form_views = Views::getViews($form_id);
+
+ $v = array();
+ foreach ($form_views["results"] as $form_view) {
+ $view_id = $form_view["view_id"];
+ $view_name = htmlspecialchars($form_view["view_name"]);
+ $v[] = "[$view_id, \"$view_name\"]";
+ }
+ $views = implode(",", $v);
+
+ $form_views_js_info[] = "page_ns.form_views.push([$form_id,[$views]])";
+}
+
+$forms_js = implode(";\n", $forms_js_rows);
+$form_views_js = implode(";\n", $form_views_js_info);
+
+// loop through each form and add all the Views
+$all_form_views = array();
+foreach ($forms as $form_info) {
+ $form_id = $form_info["form_id"];
+ $all_form_views[$form_id] = Views::getFormViews($form_id);
+}
+
+$client_forms = Forms::searchForms(array(
+ "account_id" => $client_id,
+ "is_admin" => true,
+ "status" => ""
+));
+
+
+$updated_client_forms = array();
+foreach ($client_forms as $form_info) {
+ $form_id = $form_info["form_id"];
+ $form_info["views"] = Views::getFormViews($form_id, $client_id);
+ $updated_client_forms[] = $form_info;
+}
+
+$LANG = Core::$L;
+$root_url = Core::getRootUrl();
+
+// compile header information
+$page_vars["page"] = "forms";
+$page_vars["g_success"] = $success;
+$page_vars["g_message"] = $message;
+$page_vars["page_url"] = Pages::getPageUrl("edit_client_forms", array("client_id" => $client_id));
+$page_vars["head_title"] = "{$LANG["phrase_edit_client"]} - {$LANG["word_forms"]}";
+$page_vars["client_info"] = $client_info;
+$page_vars["forms"] = $forms;
+$page_vars["client_forms"] = $updated_client_forms;
+$page_vars["all_form_views"] = $all_form_views;
+$page_vars["client_id"] = $client_id;
+$page_vars["js_messages"] = array(
+ "word_delete", "phrase_please_select", "phrase_please_select_form", "word_add_uc_rightarrow",
+ "word_remove_uc_leftarrow", "phrase_form_already_selected"
+);
+$page_vars["head_string"] = "";
+$page_vars["head_js"] = <<< END
+$forms_js
+$form_views_js
+END;
+
+Themes::displayPage("admin/clients/edit.tpl", $page_vars);
diff --git a/admin/clients/page_main.php b/admin/clients/page_main.php
new file mode 100644
index 00000000..d53a61f5
--- /dev/null
+++ b/admin/clients/page_main.php
@@ -0,0 +1,80 @@
+ $client_info["settings"]["min_password_length"]));
+ $conditional_validation[] = "rules.push(\"if:password!=,length>={$client_info["settings"]["min_password_length"]},password,$rule\");";
+}
+
+$required_password_chars = explode(",", $client_info["settings"]["required_password_chars"]);
+if (in_array("uppercase", $required_password_chars)) {
+ $conditional_validation[] = "rules.push(\"if:password!=,reg_exp,password,[A-Z],{$LANG["validation_client_password_missing_uppercase"]}\")";
+}
+if (in_array("number", $required_password_chars)) {
+ $conditional_validation[] = "rules.push(\"if:password!=,reg_exp,password,[0-9],{$LANG["validation_client_password_missing_number"]}\")";
+}
+if (in_array("special_char", $required_password_chars)) {
+ $error = General::evalSmartyString($LANG["validation_client_password_missing_special_char"], array("chars" => $req_password_special_chars));
+ $password_special_chars = preg_quote($req_password_special_chars);
+ $conditional_validation[] = "rules.push(\"if:password!=,reg_exp,password,[$password_special_chars],$error\")";
+}
+$conditional_rules = implode("\n", $conditional_validation);
+
+
+// define info for template
+$page_vars["page"] = "main";
+$page_vars["g_success"] = $success;
+$page_vars["g_message"] = $message;
+$page_vars["page_url"] = Pages::getPageUrl("edit_client_main", array("client_id" => $client_id));
+$page_vars["head_title"] = "{$LANG["phrase_edit_client"]} - {$LANG["word_main"]}";
+$page_vars["client_info"] = $client_info;
+$page_vars["client_id"] = $client_id;
+$page_vars["required_password_chars"] = $required_password_chars;
+$page_vars["password_special_chars"] = $req_password_special_chars;
+$page_vars["has_extra_password_requirements"] = (!empty($client_info["settings"]["required_password_chars"]) || !empty($client_info["settings"]["min_password_length"]));
+$page_vars["has_min_password_length"] = !empty($client_info["settings"]["min_password_length"]);
+$page_vars["password_special_char"] = General::evalSmartyString($LANG["phrase_password_special_char"], array("chars" => $req_password_special_chars));
+$page_vars["phrase_password_min"] = General::evalSmartyString($LANG["phrase_password_min"], array("length" => $client_info["settings"]["min_password_length"]));
+
+$page_vars["head_js"] =<<refreshLanguageList();
+}
+
+$client_info = Accounts::getAccountInfo($client_id);
+$forms = Forms::searchForms(array(
+ "account_id" => $client_id,
+ "status" => ""
+));
+
+$replacement_info = array(
+ "datefunctionlink" => 'date()'
+);
+
+// -------------------------------------------------------------------------------------------
+
+// compile header information
+$page_vars["page"] = "settings";
+$page_vars["g_success"] = $success;
+$page_vars["g_message"] = $message;
+$page_vars["page_url"] = Pages::getPageUrl("edit_client_settings", array("client_id" => $client_id));
+$page_vars["head_title"] = "{$LANG["phrase_edit_client"]} - {$LANG["word_settings"]}";
+$page_vars["phrase_one_special_char"] = General::evalSmartyString($LANG["phrase_one_special_char"], array("chars" => $req_password_special_chars));
+$page_vars["client_info"] = $client_info;
+$page_vars["forms"] = $forms;
+$page_vars["client_id"] = $client_id;
+$page_vars["text_date_formatting_link"] = General::evalSmartyString($LANG["text_date_formatting_link"], $replacement_info);
+
+$page_vars["head_js"] = <<< END
+var rules = [];
+rules.push("required,page_titles,{$LANG["validation_no_titles"]}");
+rules.push("required,menu_id,{$LANG["validation_no_menu"]}");
+rules.push("required,theme,{$LANG["validation_no_theme"]}");
+rules.push("function,validate_swatch");
+rules.push("required,login_page,{$LANG["validation_no_client_login_page"]}");
+rules.push("required,logout_url,{$LANG["validation_no_logout_url"]}");
+rules.push("required,ui_language,{$LANG["validation_no_ui_language"]}");
+rules.push("required,sessions_timeout,{$LANG["validation_no_sessions_timeout"]}");
+rules.push("digits_only,sessions_timeout,{$LANG["validation_invalid_sessions_timeout"]}");
+rules.push("required,date_format,{$LANG["validation_no_date_format"]}");
+
+function validate_swatch() {
+ var theme = $("#theme").val();
+ var swatch_id = "#" + theme + "_theme_swatches";
+ if ($(swatch_id).length > 0 && $(swatch_id).val() == "") {
+ return [[$(swatch_id)[0], "{$LANG["validation_no_theme_swatch"]}"]];
+ }
+ return true;
+}
+
+$(function() { $("#settings_form :input:visible:enabled:first").focus(); });
+END;
+
+Themes::displayPage("admin/clients/edit.tpl", $page_vars);
diff --git a/admin/forms/add/index.php b/admin/forms/add/index.php
new file mode 100644
index 00000000..7e1a06f1
--- /dev/null
+++ b/admin/forms/add/index.php
@@ -0,0 +1,65 @@
+checkAuth("client");
+
+if (isset($request["external"])) {
+ General::redirect("step1.php");
+} else if (isset($request["internal"])) {
+ General::redirect("internal.php");
+}
+
+if (isset($request["new_form"])) {
+ Sessions::clear("add_form_form_id");
+}
+
+$LANG = Core::$L;
+$num_forms = Forms::getFormCount();
+$max_forms = Core::getMaxForms();
+
+$head_js =<<< END
+$(function() {
+ $("#select_external").bind("click", function() {
+ var continue_decoded = $("").html("{$LANG["word_continue_rightarrow"]}").text();
+ ft.create_dialog({
+ dialog: $("#add_external_form_dialog"),
+ title: "{$LANG["word_checklist"]}",
+ popup_type: "info",
+ min_width: 600,
+ buttons: [{
+ text: continue_decoded,
+ click: function() {
+ window.location = "step1.php";
+ }
+ },
+ {
+ text: "{$LANG["word_cancel"]}",
+ click: function() {
+ $(this).dialog("close");
+ }
+ }]
+ });
+ });
+});
+END;
+
+$page = array(
+ "page" => "add_form_choose_type",
+ "page_url" => Pages::getPageUrl("add_form_choose_type"),
+ "head_title" => "{$LANG['phrase_add_form']}",
+ "max_forms_reached" => !empty($max_forms) && $num_forms >= $max_forms,
+ "max_forms" => $max_forms,
+ "notify_max_forms_reached" => General::evalSmartyString($LANG["notify_max_forms_reached"], array("max_forms" => $max_forms)),
+ "head_js" => $head_js
+);
+
+Themes::displayPage("admin/forms/add/index.tpl", $page);
diff --git a/admin/forms/add/internal.php b/admin/forms/add/internal.php
new file mode 100644
index 00000000..379c5d58
--- /dev/null
+++ b/admin/forms/add/internal.php
@@ -0,0 +1,59 @@
+checkAuth("admin");
+
+$success = true;
+$message = "";
+if (isset($request["add_form"])) {
+ list($success, $message, $new_form_id) = Forms::createInternalForm($request);
+ if ($message) {
+ General::redirect("../edit/?form_id={$new_form_id}&message=notify_internal_form_created");
+ }
+}
+
+$LANG = Core::$L;
+
+$head_js =<<< END
+ft.click([
+ { el: "at1", targets: [{ el: "custom_clients", action: "hide" }] },
+ { el: "at2", targets: [{ el: "custom_clients", action: "hide" }] },
+ { el: "at3", targets: [{ el: "custom_clients", action: "show" }] }
+]);
+
+$(function() {
+ $("#form_name").focus();
+ $("#create_internal_form").bind("submit",function(e) {
+ var rules = [];
+ rules.push("required,form_name,{$LANG["validation_no_form_name"]}");
+ rules.push("required,num_fields,{$LANG["validation_no_num_form_fields"]}");
+ rules.push("digits_only,num_fields,{$LANG["validation_invalid_num_form_fields"]}");
+ rules.push("range<=1000,num_fields,{$LANG["validation_internal_form_too_many_fields"]}");
+ rules.push("required,access_type,{$LANG["validation_no_access_type"]}");
+ if (!rsv.validate(this, rules)) {
+ e.preventDefault();
+ }
+ ft.select_all("selected_client_ids[]");
+ });
+});
+END;
+
+// compile the header information
+$page = array(
+ "page" => "add_form_internal",
+ "g_success" => $success,
+ "g_message" => $message,
+ "page_url" => Pages::getPageUrl("add_form_internal"),
+ "head_title" => $LANG["phrase_add_form"],
+ "head_js" => $head_js
+);
+
+Themes::displayPage("admin/forms/add/internal.tpl", $page);
diff --git a/admin/forms/add/step1.php b/admin/forms/add/step1.php
new file mode 100644
index 00000000..bf24957b
--- /dev/null
+++ b/admin/forms/add/step1.php
@@ -0,0 +1,58 @@
+checkAuth("admin");
+
+$num_forms = Forms::getFormCount();
+$max_forms = Core::getMaxForms();
+if (!empty($max_forms) && $num_forms > $max_forms) { // note it's not >=
+ General::redirect("../");
+}
+
+if (isset($request["code"]) || isset($request["direct"])) {
+ $type = isset($request["code"]) ? "code" : "direct";
+ General::redirect("step2.php?submission_type=$type");
+}
+
+$form_id = General::loadField("form_id", "add_form_form_id", "");
+
+$form_info = array();
+if (!empty($form_id)) {
+ $form_info = Forms::getForm($form_id);
+}
+$LANG = Core::$L;
+
+$head_js =<<< END
+var rules = [];
+var page_ns = {};
+page_ns.current_section = null;
+page_ns.show_section = function(section) {
+ if (page_ns.current_section != null) {
+ $("#" + page_ns.current_section).fadeOut({ duration: 400 });
+ setTimeout(function() { $("#" + section).fadeIn({ duration: 400, }); }, 410);
+ } else {
+ $("#" + section).fadeIn({ duration: 400 });
+ }
+ page_ns.current_section = section;
+ return false;
+}
+END;
+
+$page = array(
+ "page" => "add_form1",
+ "page_url" => Pages::getPageUrl("add_form1"),
+ "has_api" => Core::isAPIAvailable(),
+ "head_title" => "{$LANG['phrase_add_form']} - {$LANG["phrase_step_1"]}",
+ "form_info" => $form_info,
+ "head_js" => $head_js
+);
+
+Themes::displayPage("admin/forms/add/step1.tpl", $page);
diff --git a/admin/forms/add/step2.php b/admin/forms/add/step2.php
new file mode 100644
index 00000000..a027dd57
--- /dev/null
+++ b/admin/forms/add/step2.php
@@ -0,0 +1,141 @@
+checkAuth("admin");
+
+$LANG = Core::$L;
+$root_url = Core::getRootUrl();
+$form_id = General::loadField("form_id", "add_form_form_id", "");
+
+$submission_type = General::loadField("submission_type", "submission_type");
+
+// the form may or may not be created in the DB at this point. If a user's coming back to this page to complete
+// setting up their form, update the submission_type - otherwise we have the info in sessions
+if (!empty($form_id)) {
+ Forms::setSubmissionType($form_id, $submission_type);
+}
+
+$page = array();
+
+// start setting up the form
+$success = true;
+$message = "";
+if (isset($request["add_form"])) {
+ $request["form_type"] = "external";
+ $request["submission_type"] = $submission_type;
+ list($success, $message, $form_id) = Forms::setupForm($request);
+
+ // store the uploading_files value for the duration of this session
+ Sessions::set("uploading_files", isset($request['uploading_files']) ? $request['uploading_files'] : "no");
+
+ // form successfully added. Continue to step 2.
+ if ($success) {
+ General::redirect("step3.php?form_id=$form_id");
+
+ // error. Reload the page with the already entered form values, and display the appropriate error message.
+ } else {
+ $page = Forms::addFormGetExternalFormValues("post", "", $request);
+ }
+}
+
+// update this form
+else if (isset($request['update_form'])) {
+
+ // store the uploading_files value for the duration of this session
+ Sessions::set("uploading_files", isset($request["uploading_files"]) ? $request["uploading_files"] : "no");
+ $request["submission_type"] = $submission_type;
+
+ list($success, $message) = Forms::setFormMainSettings($request);
+ if ($success) {
+ General::redirect("step3.php?form_id=$form_id");
+ } else {
+ $page = Forms::addFormGetExternalFormValues("post", $form_id, $request);
+ }
+}
+
+// edit existing form (used for cases where user fails to complete form building process, then returns
+// later to finish the job)
+else if (!empty($form_id)) {
+ $page = Forms::addFormGetExternalFormValues("database", $form_id);
+}
+// otherwise, the user is coming to this page for the first time. init the default values
+else {
+ $page = Forms::addFormGetExternalFormValues("new_form");
+}
+
+if (!Sessions::exists("uploading_files")) {
+ Sessions::set("uploading_files", "no");
+}
+
+$selected_client_ids = array();
+for ($i=0; $i
+
+EOF;
+
+$page_vars["head_js"] =<<< END
+ft.click([
+ { el: "at1", targets: [{ el: "custom_clients", action: "hide" }] },
+ { el: "at2", targets: [{ el: "custom_clients", action: "hide" }] },
+ { el: "at3", targets: [{ el: "custom_clients", action: "show" }] }
+]);
+
+var rules = [];
+rules.push("required,form_name,{$LANG['validation_no_form_name']}");
+rules.push("function,mf_ns.check_first_form_url");
+rules.push("required,access_type,{$LANG["validation_no_access_type"]}");
+
+rsv.onCompleteHandler = function() {
+ ft.select_all("selected_client_ids[]");
+ return true;
+}
+
+$(function() {
+ $("#form_name").focus();
+ $(".is_multi_page_form").bind("click", function() {
+ if ($(this).val() == "yes") {
+ $("#form_url_single, #form_label_single").hide();
+ $("#form_url_multiple, #form_label_multiple").show();
+ } else {
+ $("#form_url_single, #form_label_single").show();
+ $("#form_url_multiple, #form_label_multiple").hide();
+ }
+ });
+ ft.init_check_url_buttons();
+});
+
+END;
+
+Themes::displayPage("admin/forms/add/step2.tpl", $page_vars);
diff --git a/admin/forms/add/step3.php b/admin/forms/add/step3.php
new file mode 100644
index 00000000..b365414d
--- /dev/null
+++ b/admin/forms/add/step3.php
@@ -0,0 +1,127 @@
+checkAuth("admin");
+
+$root_url = Core::getRootUrl();
+$LANG = Core::$L;
+
+$form_id = General::loadField("form_id", "add_form_form_id", "");
+
+if (isset($_POST["submission_type"])) {
+ Forms::setSubmissionType($form_id, $_POST["submission_type"]);
+}
+
+// if returning from a later stage and the user wants to resubmit the test submission, update the form
+if (isset($_GET['uninitialize']) && $_GET['uninitialize'] == 1) {
+ Forms::uninitializeForm($form_id);
+}
+
+// retrieve the form info
+$form_info = Forms::getForm($form_id);
+
+// determine the input field values for cutting & pasting
+$hidden_fields = '' . "\n"
+ . '';
+$form_tag = '