golden hour
/home/phakp/public_html/formtools/global/code
⬆️ Go Up
Upload
File/Folder
Size
Actions
Accounts.class.php
14.56 KB
Del
OK
Administrator.class.php
32.41 KB
Del
OK
Clients.class.php
19.25 KB
Del
OK
Constants.class.php
51 B
Del
OK
Core.class.php
23.23 KB
Del
OK
CoreFieldTypes.class.php
11.16 KB
Del
OK
Database.class.php
6.34 KB
Del
OK
DatabaseSessions.class.php
3.09 KB
Del
OK
Emails.class.php
60.66 KB
Del
OK
Errors.class.php
4.78 KB
Del
OK
FieldOptions.class.php
1.1 KB
Del
OK
FieldSettings.class.php
1.25 KB
Del
OK
FieldSizes.class.php
2.9 KB
Del
OK
FieldTypes.class.php
61.04 KB
Del
OK
FieldValidation.class.php
11.7 KB
Del
OK
Fields.class.php
57.75 KB
Del
OK
Files.class.php
18.61 KB
Del
OK
Forms.class.php
63.07 KB
Del
OK
General.class.php
47.2 KB
Del
OK
Hooks.class.php
21.66 KB
Del
OK
Installation.class.php
57.45 KB
Del
OK
ListGroups.class.php
2.35 KB
Del
OK
Menus.class.php
36.83 KB
Del
OK
Module.abstract.class.php
8.29 KB
Del
OK
ModuleMenu.class.php
3.84 KB
Del
OK
Modules.class.php
30.52 KB
Del
OK
OmitLists.class.php
2.4 KB
Del
OK
OptionLists.class.php
28.04 KB
Del
OK
Pages.class.php
8.61 KB
Del
OK
Schemas.class.php
814 B
Del
OK
SecureSmarty.class.php
403 B
Del
OK
Sessions.class.php
4.01 KB
Del
OK
Settings.class.php
23.12 KB
Del
OK
Submissions.class.php
70.8 KB
Del
OK
Templates.class.php
6.64 KB
Del
OK
Themes.class.php
14.04 KB
Del
OK
Translations.class.php
3.54 KB
Del
OK
Upgrade.class.php
6.81 KB
Del
OK
User.class.php
14.47 KB
Del
OK
ViewColumns.class.php
3.06 KB
Del
OK
ViewFields.class.php
19.39 KB
Del
OK
ViewFilters.class.php
15.07 KB
Del
OK
ViewTabs.class.php
3.46 KB
Del
OK
Views.class.php
47.25 KB
Del
OK
actions.php
17.92 KB
Del
OK
field_types
-
Del
OK
index.php
35 B
Del
OK
polyfills.php
5.07 KB
Del
OK
validation.php
15.79 KB
Del
OK
Edit: CoreFieldTypes.class.php
<?php /** * Form Tools - generic form processing, storage and access script * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License included in this zipfile for more details. * * @copyright Benjamin Keen 2018 * @author Benjamin Keen <ben.keen@gmail.com> * @version 3.0.x * @package 3-0-x */ // ------------------------------------------------------------------------------------------------- namespace FormTools; use Exception; // down the road these should all extend an abstract class, with all the content standardized use FormTools\FieldTypes\Checkbox; use FormTools\FieldTypes\Code; use FormTools\FieldTypes\Date; use FormTools\FieldTypes\Dropdown; use FormTools\FieldTypes\MultiSelect; use FormTools\FieldTypes\Password; use FormTools\FieldTypes\Phone; use FormTools\FieldTypes\Radio; use FormTools\FieldTypes\Textarea; use FormTools\FieldTypes\Textbox; use FormTools\FieldTypes\Time; class CoreFieldTypes { /** * This installs a single field type and all related data: settings, setting options and validation. If * a field type with that identifier already exists, it returns false, with an appropriate error message. * * @param integer $field_type_identifier "textbox", "textarea", etc... TODO these should be constants. */ public static function installFieldType($field_type_identifier, $group_id) { $db = Core::$db; $field_type_info = FieldTypes::getFieldTypeByIdentifier($field_type_identifier); if (!empty($field_type_info)) { return array(false, "The database has already been populated with the $field_type_identifier field type."); } $cft_field_types = CoreFieldTypes::getFieldTypes(); $data = $cft_field_types[$field_type_identifier]; // Step 1: install the main field_types record $db->query("SELECT count(*) as c FROM {PREFIX}field_types WHERE group_id = :group_id"); $db->bind("group_id", $group_id); $db->execute(); $result = $db->fetch(); $next_list_order = $result["c"] + 1; $db->query(" INSERT INTO {PREFIX}field_types (is_editable, non_editable_info, managed_by_module_id, field_type_name, field_type_identifier, group_id, is_file_field, is_date_field, raw_field_type_map, raw_field_type_map_multi_select_id, list_order, compatible_field_sizes, view_field_rendering_type, view_field_php_function_source, view_field_php_function, view_field_smarty_markup, edit_field_smarty_markup, php_processing, resources_css, resources_js) VALUES ( :is_editable, :non_editable_info, :managed_by_module_id, :field_type_name, :field_type_identifier, :group_id, :is_file_field, :is_date_field, :raw_field_type_map, :raw_field_type_map_multi_select_id, :list_order, :compatible_field_sizes, :view_field_rendering_type, :view_field_php_function_source, :view_field_php_function, :view_field_smarty_markup, :edit_field_smarty_markup, :php_processing, :resources_css, :resources_js ) "); $db->bindAll(array( "is_editable" => $data["field_type"]["is_editable"], "non_editable_info" => $data["field_type"]["non_editable_info"], "managed_by_module_id" => $data["field_type"]["managed_by_module_id"], "field_type_name" => $data["field_type"]["field_type_name"], "field_type_identifier" => $data["field_type"]["field_type_identifier"], "group_id" => $group_id, "is_file_field" => $data["field_type"]["is_file_field"], "is_date_field" => $data["field_type"]["is_date_field"], "raw_field_type_map" => $data["field_type"]["raw_field_type_map"], "raw_field_type_map_multi_select_id" => null, "list_order" => $next_list_order, "compatible_field_sizes" => $data["field_type"]["compatible_field_sizes"], "view_field_rendering_type" => $data["field_type"]["view_field_rendering_type"], "view_field_php_function_source" => $data["field_type"]["view_field_php_function_source"], "view_field_php_function" => $data["field_type"]["view_field_php_function"], "view_field_smarty_markup" => $data["field_type"]["view_field_smarty_markup"], "edit_field_smarty_markup" => $data["field_type"]["edit_field_smarty_markup"], "php_processing" => $data["field_type"]["php_processing"], "resources_css" => $data["field_type"]["resources_css"], "resources_js" => $data["field_type"]["resources_js"] )); try { $db->execute(); } catch (Exception $e) { CoreFieldTypes::rollbackNewInstallation(); return array(false, "Failed to insert field type $field_type_identifier: " . $e->getMessage()); } $field_type_id = $db->getInsertId(); // Step 2: field type settings for ($i=1; $i<=count($data["settings"]); $i++) { $setting_info = $data["settings"][$i-1]; $use_for_option_list_map = isset($setting_info["use_for_option_list_map"]) ? $setting_info["use_for_option_list_map"] : false; $db->query(" INSERT INTO {PREFIX}field_type_settings (field_type_id, field_label, field_setting_identifier, field_type, field_orientation, default_value_type, default_value, list_order) VALUES (:field_type_id, :field_label, :field_setting_identifier, :field_type, :field_orientation, :default_value_type, :default_value, :list_order) "); $db->bindAll(array( "field_type_id" => $field_type_id, "field_label" => $setting_info["field_label"], "field_setting_identifier" => $setting_info["field_setting_identifier"], "field_type" => $setting_info["field_type"], "field_orientation" => $setting_info["field_orientation"], "default_value_type" => $setting_info["default_value_type"], "default_value" => $setting_info["default_value"], "list_order" => $i )); try { $db->execute(); } catch (Exception $e) { CoreFieldTypes::rollbackNewInstallation(); return array(false, "Failed to insert setting {$setting_info["field_setting_identifier"]}: " . $e->getMessage()); } $setting_id = $db->getInsertId(); // if this setting is being used for the raw field type option list, update the field type record if ($use_for_option_list_map) { $db->query(" UPDATE {PREFIX}field_types SET raw_field_type_map_multi_select_id = :raw_field_type_map_multi_select_id WHERE field_type_id = :field_type_id "); $db->bind("raw_field_type_map_multi_select_id", $setting_id); $db->bind("field_type_id", $field_type_id); $db->execute(); } for ($j=1; $j<=count($setting_info["options"]); $j++) { $option_info = $setting_info["options"][$j-1]; $db->query(" INSERT INTO {PREFIX}field_type_setting_options (setting_id, option_text, option_value, option_order, is_new_sort_group) VALUES (:setting_id, :option_text, :option_value, :option_order, :is_new_sort_group) "); $db->bindAll(array( "setting_id" => $setting_id, "option_text" => $option_info["option_text"], "option_value" => $option_info["option_value"], "option_order" => $j, "is_new_sort_group" => $option_info["is_new_sort_group"] )); try { $db->execute(); } catch (Exception $e) { CoreFieldTypes::rollbackNewInstallation(); return array(false, "Failed to insert setting option {$setting_info["field_setting_identifier"]}, {$option_info["option_text"]}: " . $e->getMessage()); } } } // Step 4: Validation for ($i=1; $i<=count($data["validation"]); $i++) { $rule_info = $data["validation"][$i-1]; $db->query(" INSERT INTO {PREFIX}field_type_validation_rules (field_type_id, rsv_rule, rule_label, rsv_field_name, custom_function, custom_function_required, default_error_message, list_order) VALUES (:field_type_id, :rsv_rule, :rule_label, :rsv_field_name, :custom_function, :custom_function_required, :default_error_message, :list_order) "); $db->bindAll(array( "field_type_id" => $field_type_id, "rsv_rule" => $rule_info["rsv_rule"], "rule_label" => $rule_info["rule_label"], "rsv_field_name" => $rule_info["rsv_field_name"], "custom_function" => $rule_info["custom_function"], "custom_function_required" => $rule_info["custom_function_required"], "default_error_message" => $rule_info["default_error_message"], "list_order" => $i )); try { $db->execute(); } catch (Exception $e) { CoreFieldTypes::rollbackNewInstallation(); return array(false, "Failed to insert validation rule {$rule_info["rule_label"]}: " . $e->getMessage()); } } return array(true, ""); } /** * Used during the installation. If there are ever ANY errors adding the core fields types, it empties the * database for a fresh try. * * This shouldn't ever occur, of course. However, the calling script will always return the explicit error * that occurs, so we should be able to plug any problems that occur. */ public static function rollbackNewInstallation() { $db = Core::$db; ListGroups::deleteByGroupType("field_types"); $db->query("TRUNCATE TABLE {PREFIX}field_types"); $db->execute(); $db->query("TRUNCATE TABLE {PREFIX}field_type_settings"); $db->execute(); $db->query("TRUNCATE TABLE {PREFIX}field_type_setting_options"); $db->execute(); $db->query("TRUNCATE TABLE {PREFIX}field_type_validation_rules"); $db->execute(); } public static function getFieldTypes() { return array( "checkboxes" => Checkbox::get(), "code_markup" => Code::get(), "date" => Date::get(), "dropdown" => Dropdown::get(), "multi_select_dropdown" => MultiSelect::get(), "password" => Password::get(), "phone" => Phone::get(), "radio_buttons" => Radio::get(), "textarea" => Textarea::get(), "textbox" => Textbox::get(), "time" => Time::get() ); } }
Save