function execute()
 {
     log_debug("services_form_details", "Executing execute()");
     /*
     	Define form structure
     */
     $this->obj_form = new form_input();
     $this->obj_form->formname = "service_" . $this->mode;
     $this->obj_form->language = $_SESSION["user"]["lang"];
     $this->obj_form->action = "services/edit-process.php";
     $this->obj_form->method = "post";
     // general
     $structure = NULL;
     $structure["fieldname"] = "name_service";
     $structure["type"] = "input";
     $structure["options"]["req"] = "yes";
     $this->obj_form->add_input($structure);
     $structure = charts_form_prepare_acccountdropdown("chartid", "ar_income");
     $structure["options"]["search_filter"] = "yes";
     $structure["options"]["width"] = "400";
     $structure["options"]["req"] = "yes";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "description";
     $structure["type"] = "textarea";
     $structure["options"]["width"] = "600";
     $structure["options"]["height"] = "100";
     $this->obj_form->add_input($structure);
     // the service type can only be set at creation time.
     if ($this->mode == "add") {
         $structure = form_helper_prepare_radiofromdb("typeid", "SELECT id, name as label, description as label1 FROM service_types WHERE active='1' ORDER BY name");
         $structure["options"]["req"] = "yes";
         // replace all the -- joiners with <br> for clarity
         for ($i = 0; $i < count($structure["values"]); $i++) {
             $structure["translations"][$structure["values"][$i]] = str_replace("--", "<br><i>", $structure["translations"][$structure["values"][$i]]);
             $structure["translations"][$structure["values"][$i]] .= "</i><br>";
         }
         // handle misconfiguration gracefully
         if (empty($this->obj_form->structure["typeid"]["values"])) {
             $this->obj_form->structure["typeid"]["type"] = "text";
             $this->obj_form->structure["typeid"]["defaultvalue"] = "error_no_types_available";
         }
         $this->obj_form->add_input($structure);
     } else {
         $structure = NULL;
         $structure["fieldname"] = "typeid";
         $structure["type"] = "text";
         $this->obj_form->add_input($structure);
     }
     // service grouping
     $structure = form_helper_prepare_dropdownfromgroup("id_service_group", "SELECT id as value_id, group_name as value_key, id_parent as value_parent FROM service_groups");
     $structure["options"]["req"] = "yes";
     $structure["options"]["search_filter"] = "yes";
     $structure["options"]["width"] = "400";
     $this->obj_form->add_input($structure);
     $structure = form_helper_prepare_dropdownfromgroup("id_service_group_usage", "SELECT id as value_id, group_name as value_key, id_parent as value_parent FROM service_groups");
     $structure["options"]["req"] = "yes";
     $structure["options"]["search_filter"] = "yes";
     $structure["options"]["width"] = "400";
     $this->obj_form->add_input($structure);
     // write service usage grouping javascript UI logic - we need to get all the options
     // and write actions for each ID
     $this->obj_form->add_action("typeid", "default", "id_service_group_usage", "hide");
     $sql_obj = new sql_query();
     $sql_obj->string = "SELECT id, name as label FROM service_types";
     $sql_obj->execute();
     $sql_obj->fetch_array();
     foreach ($sql_obj->data as $data_row) {
         switch ($data_row["label"]) {
             case "data_traffic":
             case "generic_with_usage":
             case "phone_single":
             case "phone_trunk":
             case "phone_tollfree":
             case "time":
                 $this->obj_form->add_action("typeid", $data_row["id"], "id_service_group_usage", "show");
                 // for add mode
                 $this->obj_form->add_action("typeid", $data_row["label"], "id_service_group_usage", "show");
                 // for view mode
                 break;
             case "bundle":
             case "generic_no_usage":
             case "licenses":
                 $this->obj_form->add_action("typeid", $data_row["id"], "id_service_group_usage", "hide");
                 // for add mode
                 $this->obj_form->add_action("typeid", $data_row["label"], "id_service_group_usage", "hide");
                 // for view mode
                 break;
         }
     }
     // define service_details subform
     $this->obj_form->subforms["service_details"] = array("name_service", "chartid", "typeid", "id_service_group", "id_service_group_usage", "description");
     /*
     	List all the taxes, so that the user can select the tax(es) that apply to the service
     */
     $sql_tax_obj = new sql_query();
     $sql_tax_obj->string = "SELECT id, name_tax, description, default_services FROM account_taxes ORDER BY name_tax";
     $sql_tax_obj->execute();
     if ($sql_tax_obj->num_rows()) {
         // user note
         $structure = NULL;
         $structure["fieldname"] = "tax_message";
         $structure["type"] = "message";
         $structure["defaultvalue"] = "<p>Check all taxes that apply to this service below.</p>";
         $this->obj_form->add_input($structure);
         $this->obj_form->subforms["service_tax"][] = "tax_message";
         // run through all the taxes
         $sql_tax_obj->fetch_array();
         foreach ($sql_tax_obj->data as $data_tax) {
             // define tax checkbox
             $structure = NULL;
             $structure["fieldname"] = "tax_" . $data_tax["id"];
             $structure["type"] = "checkbox";
             $structure["options"]["label"] = $data_tax["name_tax"] . " -- " . $data_tax["description"];
             $structure["options"]["no_fieldname"] = "enable";
             if ($this->serviceid) {
                 // see if this tax is currently enabled for this service
                 $sql_obj = new sql_query();
                 $sql_obj->string = "SELECT id FROM services_taxes WHERE serviceid='" . $this->serviceid . "' AND taxid='" . $data_tax["id"] . "' LIMIT 1";
                 $sql_obj->execute();
                 if ($sql_obj->num_rows()) {
                     $structure["defaultvalue"] = "on";
                 }
             } else {
                 if ($data_tax["default_services"]) {
                     $structure["defaultvalue"] = "on";
                 }
             }
             // add to form
             $this->obj_form->add_input($structure);
             $this->obj_form->subforms["service_tax"][] = "tax_" . $data_tax["id"];
         }
     }
     /*
     	Upstream Vendor Information
     
     	These fields are purely for users notes/record keeping purposes.
     */
     $structure = NULL;
     $structure["fieldname"] = "upstream_help_message";
     $structure["type"] = "message";
     $structure["defaultvalue"] = "<p>" . lang_trans("upstream_help_message") . "</p>";
     $this->obj_form->add_input($structure);
     $sql_struct_obj = new sql_query();
     $sql_struct_obj->prepare_sql_settable("vendors");
     $sql_struct_obj->prepare_sql_addfield("id", "vendors.id");
     $sql_struct_obj->prepare_sql_addfield("label", "vendors.code_vendor");
     $sql_struct_obj->prepare_sql_addfield("label1", "vendors.name_vendor");
     $sql_struct_obj->prepare_sql_addorderby("code_vendor");
     $sql_struct_obj->prepare_sql_addwhere("id = 'CURRENTID' OR date_end = '0000-00-00'");
     $structure = form_helper_prepare_dropdownfromobj("upstream_id", $sql_struct_obj);
     $structure["options"]["search_filter"] = "yes";
     $structure["options"]["width"] = "400";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "upstream_notes";
     $structure["type"] = "textarea";
     $structure["options"]["width"] = "600";
     $structure["options"]["height"] = "100";
     $this->obj_form->add_input($structure);
     $this->obj_form->subforms["service_upstream"] = array("upstream_help_message", "upstream_id", "upstream_notes");
     // define subforms
     if (user_permissions_get("services_write")) {
         $this->obj_form->subforms["submit"] = array("submit");
     } else {
         $this->obj_form->subforms["submit"] = array("");
     }
     /*
     	Mode dependent options
     */
     if ($this->mode == "add") {
         // submit button
         $structure = NULL;
         $structure["fieldname"] = "submit";
         $structure["type"] = "submit";
         $structure["defaultvalue"] = "Create Service";
         $this->obj_form->add_input($structure);
     } else {
         // submit button
         $structure = NULL;
         $structure["fieldname"] = "submit";
         $structure["type"] = "submit";
         $structure["defaultvalue"] = "Save Changes";
         $this->obj_form->add_input($structure);
         // hidden data
         $structure = NULL;
         $structure["fieldname"] = "id_service";
         $structure["type"] = "hidden";
         $structure["defaultvalue"] = $this->serviceid;
         $this->obj_form->add_input($structure);
         $this->obj_form->subforms["hidden"] = array("id_service");
     }
     /*
     	Load Data
     */
     if ($this->mode == "add") {
         $this->obj_form->load_data_error();
     } else {
         // load details data
         $this->obj_form->sql_query = "SELECT \n\t\t\t\t\t\t\t\tservices.name_service, \n\t\t\t\t\t\t\t\tservices.chartid, \n\t\t\t\t\t\t\t\tservices.id_service_group,\n\t\t\t\t\t\t\t\tservices.id_service_group_usage,\n\t\t\t\t\t\t\t\tservices.description, \n\t\t\t\t\t\t\t\tservice_types.name as typeid,\n\t\t\t\t\t\t\t\tservices.upstream_id as upstream_id,\n\t\t\t\t\t\t\t\tservices.upstream_notes as upstream_notes\n\t\t\t\t\t\t\tFROM `services`\n\t\t\t\t\t\t\tLEFT JOIN service_types ON service_types.id = services.typeid\n\t\t\t\t\t\t\tWHERE services.id='" . $this->serviceid . "' LIMIT 1";
         $this->obj_form->load_data();
     }
 }
 function execute()
 {
     log_debug("products_form_details", "Executing execute()");
     /*
     	Define form structure
     */
     $this->obj_form = new form_input();
     $this->obj_form->formname = "product_" . $this->mode;
     $this->obj_form->language = $_SESSION["user"]["lang"];
     $this->obj_form->action = "products/edit-process.php";
     $this->obj_form->method = "post";
     // general
     $structure = NULL;
     $structure["fieldname"] = "code_product";
     $structure["type"] = "input";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "name_product";
     $structure["type"] = "input";
     $structure["options"]["req"] = "yes";
     $this->obj_form->add_input($structure);
     $structure = form_helper_prepare_dropdownfromgroup("id_product_group", "SELECT id as value_id, group_name as value_key, id_parent as value_parent FROM product_groups");
     $structure["options"]["req"] = "yes";
     $structure["options"]["search_filter"] = "yes";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "units";
     $structure["type"] = "input";
     $structure["options"]["width"] = 50;
     $structure["options"]["max_length"] = 10;
     $structure["options"]["req"] = "yes";
     $this->obj_form->add_input($structure);
     $structure = charts_form_prepare_acccountdropdown("account_sales", "ar_income");
     $structure["options"]["req"] = "yes";
     $structure["options"]["search_filter"] = "yes";
     $this->obj_form->add_input($structure);
     $structure = charts_form_prepare_acccountdropdown("account_purchase", "ap_expense");
     $structure["options"]["req"] = "yes";
     $structure["options"]["search_filter"] = "yes";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "details";
     $structure["type"] = "textarea";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "date_start";
     $structure["type"] = "date";
     $structure["options"]["req"] = "yes";
     $structure["defaultvalue"] = date("Y-m-d");
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "date_end";
     $structure["type"] = "date";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "date_current";
     $structure["type"] = "date";
     $this->obj_form->add_input($structure);
     $this->obj_form->subforms["product_view"] = array("code_product", "name_product", "id_product_group", "units", "account_sales", "account_purchase", "date_start", "date_end", "date_current", "details");
     // pricing
     $structure = NULL;
     $structure["fieldname"] = "price_cost";
     $structure["type"] = "money";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "price_sale";
     $structure["type"] = "money";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "discount";
     $structure["type"] = "input";
     $structure["options"]["width"] = 50;
     $structure["options"]["label"] = " %";
     $structure["options"]["max_length"] = "6";
     $this->obj_form->add_input($structure);
     $this->obj_form->subforms["product_pricing"] = array("price_cost", "price_sale", "discount");
     /*
     	List all the taxes, so that the user can select the tax(es) that apply to the product
     */
     $sql_tax_obj = new sql_query();
     $sql_tax_obj->string = "SELECT id, name_tax, description, default_products FROM account_taxes ORDER BY name_tax";
     $sql_tax_obj->execute();
     if ($sql_tax_obj->num_rows()) {
         // user note
         $structure = NULL;
         $structure["fieldname"] = "tax_message";
         $structure["type"] = "message";
         $structure["defaultvalue"] = "<p>Check all taxes that apply to this product below.</p>";
         $this->obj_form->add_input($structure);
         $this->obj_form->subforms["product_tax"][] = "tax_message";
         // run through all the taxes
         $sql_tax_obj->fetch_array();
         foreach ($sql_tax_obj->data as $data_tax) {
             // define tax checkbox
             $structure = NULL;
             $structure["fieldname"] = "tax_" . $data_tax["id"];
             $structure["type"] = "checkbox";
             $structure["options"]["label"] = $data_tax["name_tax"] . " -- " . $data_tax["description"];
             $structure["options"]["no_fieldname"] = "enable";
             // see if this tax is currently enabled for this product
             if ($this->productid) {
                 $sql_obj = new sql_query();
                 $sql_obj->string = "SELECT id FROM products_taxes WHERE productid='" . $this->productid . "' AND taxid='" . $data_tax["id"] . "' LIMIT 1";
                 $sql_obj->execute();
                 if ($sql_obj->num_rows()) {
                     $structure["defaultvalue"] = "on";
                 }
             } else {
                 if ($data_tax["default_products"]) {
                     $structure["defaultvalue"] = "on";
                 }
             }
             // add to form
             $this->obj_form->add_input($structure);
             $this->obj_form->subforms["product_tax"][] = "tax_" . $data_tax["id"];
         }
     }
     // quantity
     $structure = NULL;
     $structure["fieldname"] = "quantity_instock";
     $structure["type"] = "input";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "quantity_vendor";
     $structure["type"] = "input";
     $this->obj_form->add_input($structure);
     $this->obj_form->subforms["product_quantity"] = array("quantity_instock", "quantity_vendor");
     // supplier details
     $sql_struct_obj = new sql_query();
     $sql_struct_obj->prepare_sql_settable("vendors");
     $sql_struct_obj->prepare_sql_addfield("id", "vendors.id");
     $sql_struct_obj->prepare_sql_addfield("label", "vendors.name_vendor");
     $sql_struct_obj->prepare_sql_addwhere("id = 'CURRENTID' OR date_end = '0000-00-00'");
     $structure = form_helper_prepare_dropdownfromobj("vendorid", $sql_struct_obj);
     $structure["options"]["search_filter"] = "yes";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "code_product_vendor";
     $structure["type"] = "input";
     $this->obj_form->add_input($structure);
     $this->obj_form->subforms["product_supplier"] = array("vendorid", "code_product_vendor");
     // define remaining subforms
     if (user_permissions_get("products_write")) {
         $this->obj_form->subforms["submit"] = array("submit");
     } else {
         $this->obj_form->subforms["submit"] = array();
     }
     /*
     	Mode dependent options
     */
     if ($this->mode == "add") {
         // submit button
         $structure = NULL;
         $structure["fieldname"] = "submit";
         $structure["type"] = "submit";
         $structure["defaultvalue"] = "Create Product";
         $this->obj_form->add_input($structure);
     } else {
         // submit button
         $structure = NULL;
         $structure["fieldname"] = "submit";
         $structure["type"] = "submit";
         $structure["defaultvalue"] = "Save Changes";
         $this->obj_form->add_input($structure);
         // hidden data
         $structure = NULL;
         $structure["fieldname"] = "id_product";
         $structure["type"] = "hidden";
         $structure["defaultvalue"] = $this->productid;
         $this->obj_form->add_input($structure);
         $this->obj_form->subforms["hidden"] = array("id_product");
     }
     /*
     	Load Data
     */
     if ($this->mode == "add") {
         $this->obj_form->load_data_error();
     } else {
         $this->obj_form->sql_query = "SELECT * FROM `products` WHERE id='" . $this->productid . "' LIMIT 1";
         $this->obj_form->load_data();
     }
 }