/**
  * Delete a generic field
  * @trigger : deleteGenericField.pre, deleteGenericField.post
  * @param FrontFormAdminFieldEntity $objField
  * @return \FrontFormAdmin\Entities\FrontFormAdminFieldEntity
  */
 public function deleteGenericField(FrontFormAdminFieldEntity $objField)
 {
     //trigger pre event
     $result = $this->getEventManager()->trigger(__FUNCTION__ . ".pre", $this, array("objField" => $objField));
     //create the request object
     $objApiRequest = $this->getApiRequestModel();
     //setup the object and specify the action
     $objApiRequest->setApiAction($objField->getHyperMedia("delete-generic-field")->url);
     $objApiRequest->setApiModule(NULL);
     //execute
     $objField = $objApiRequest->performDELETERequest(array())->getBody();
     //trigger post event
     $result = $this->getEventManager()->trigger(__FUNCTION__ . ".pre", $this, array("objField" => $objField));
     //recreate field entity
     $objField = $this->createGenericFieldEntity($objField->data);
     return $objField->data;
 }
 public function generateCustomFieldCriteriaHTML(FrontFormAdminFieldEntity $objField, $value = FALSE, $objParam = FALSE)
 {
     //determine field type to setup data returned for the field
     switch ($objField->get("fields_types_input_type")) {
         case "text":
             //check for particular field types
             switch (strtolower($objField->get("fields_types_field_type"))) {
                 case "text":
                     //normal texrt fields
                     $html = "<select name=\"custom_field_operator_" . $objField->get("field") . "\" id=\"custom_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
                     if (is_object($objParam) && $objParam->field_operator == "equals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"equals\" {$selected}>is equal to</option>";
                     if (is_object($objParam) && $objParam->field_operator == "notequals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"notequals\" {$selected}>is not equal to</option>";
                     if ($value != "" && $value == $objParam->field_value) {
                         $field_value = "value=\"{$objParam->field_value}\"";
                     } else {
                         $field_value = "";
                     }
                     //end if
                     $html .= "</select>&nbsp;\n\t\t\t\t\t\t\t\t<input type=\"text\" name=\"custom_field_" . $objField->get("field") . "\" id=\"custom_field_" . $objField->get("field") . "\" required=\"required\" {$field_value}>";
                     break;
                 case "money":
                     //monetary field
                 //monetary field
                 case "text (numeric)":
                     //numeric field
                     $html = "<select name=\"custom_field_operator_" . $objField->get("field") . "\" id=\"custom_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
                     if (is_object($objParam) && $objParam->field_operator == "equals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"equals\" {$selected}>is equal to</option>";
                     if (is_object($objParam) && $objParam->field_operator == "notequals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"notequals\" {$selected}>is not equal to</option>";
                     if (is_object($objParam) && $objParam->field_operator == "greaterthanequals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"greaterthanequals\" {$selected}>is greater than or equal to</option>";
                     if (is_object($objParam) && $objParam->field_operator == "lessthanequals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "option value=\"lessthanequals\" {$selected}>is less than or equal to</option>";
                     if (is_object($objParam) && $objParam->field_operator == "greaterthan") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"greaterthan\" {$selected}>is greater than</option>";
                     if (is_object($objParam) && $objParam->field_operator == "lessthan") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"lessthan\" {$selected}>is less than</option>";
                     if ($value != "" && $value == $objParam->field_value) {
                         $field_value = "value=\"{$objParam->field_value}\"";
                     } else {
                         $field_value = "";
                     }
                     //end if
                     $html .= "</select>&nbsp;\n\t\t\t\t\t\t\t\t<input type=\"text\" name=\"custom_field_" . $objField->get("field") . "\" id=\"custom_field_" . $objField->get("field") . "\" required=\"required\" {$field_value}>";
                     break;
                 case "date":
                     $html = "<select name=\"custom_field_operator_" . $objField->get("field") . "\" id=\"custom_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
                     if (is_object($objParam) && $objParam->field_operator == "equals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"equals\" {$selected}>is equal to</option>";
                     if (is_object($objParam) && $objParam->field_operator == "notequals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"notequals\" {$selected}>is not equal to</option>";
                     if (is_object($objParam) && $objParam->field_operator == "greaterthanequals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"greaterthanequals\" {$selected}>is greater than or equal to</option>";
                     if (is_object($objParam) && $objParam->field_operator == "lessthanequals") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"lessthanequals\" {$selected}>is less than or equal to</option>";
                     if (is_object($objParam) && $objParam->field_operator == "greaterthan") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"greaterthan\" {$selected}>is greater than</option>";
                     if (is_object($objParam) && $objParam->field_operator == "lessthan") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"lessthan\">is less than</option>";
                     if ($value != "" && $value == $objParam->field_value) {
                         $field_value = "value=\"{$objParam->field_value}\"";
                     } else {
                         $field_value = "";
                     }
                     //end if
                     $html .= "</select>&nbsp;\n\t\t\t\t\t\t\t\t<!--activate datepicker for field-->\n\t\t\t\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\t\t\tjQuery(document).ready(function () {\n\t\t\t\t\t\t\t\t\t\tjQuery(\".datepicker\").datepicker({ dateFormat: \"dd-mm-yy\" });\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t</script>\n\t\t\t\t\t\t\t\t<input type=\"text\" name=\"custom_field_" . $objField->get("field") . "\" id=\"custom_field_" . $objField->get("field") . "\" required=\"required\" readonly=\"readonly\" class=\"datepicker\" style=\"width: 100px;\" {$field_value}>";
                     break;
                 case "date range":
                     $html = "<select name=\"custom_field_operator_" . $objField->get("field") . "\" id=\"custom_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
                     if (is_object($objParam) && $objParam->field_operator == "between") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"between\" {$selected}>is between</option>";
                     if (is_object($objParam) && $objParam->field_operator == "notbetween") {
                         $selected = "selected=\"selected\"";
                     } else {
                         $selected = "";
                     }
                     //end if
                     $html .= "<option value=\"notbetween\" {$selected}>is not between</option>";
                     //extract date values
                     if ($value != "" && $value == $objParam->field_value) {
                         $arr_data = explode(" AND ", $objParam->field_value);
                         $date_start_value = str_replace("'", "", str_replace(" ", "", $arr_data[0]));
                         $date_end_value = str_replace("'", "", str_replace(" ", "", $arr_data[1]));
                     } else {
                         $date_start_value = "";
                         $date_end_value = "";
                     }
                     //end if
                     $html .= "</select>&nbsp;\n\t\t\t\t\t\t\t\t<!--activate datepicker for field-->\n\t\t\t\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\t\t\tjQuery(document).ready(function () {\n\t\t\t\t\t\t\t\t\t\tjQuery(\".datepicker\").datepicker({ dateFormat: \"dd-mm-yy\" });\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t</script>\n\t\t\t\t\t\t\t\t<input type=\"text\" name=\"custom_field_date_start_" . $objField->get("field") . "\" id=\"custom_field_date_start_" . $objField->get("field") . "\" required=\"required\" readonly=\"readonly\" class=\"datepicker\" style=\"width: 100px;\" {$date_start_value}>\n\t\t\t\t\t\t\t\t&nbsp;-&nbsp;\n\t\t\t\t\t\t\t\t<input type=\"text\" name=\"custom_field_date_end_" . $objField->get("field") . "\"   id=\"custom_field_date_end_" . $objField->get("field") . "\" required=\"required\" readonly=\"readonly\" class=\"datepicker\" style=\"width: 100px;\" {$date_end_value}>";
                     break;
             }
             //end switch
             break;
         case "textarea":
             return FALSE;
             break;
         case "select":
         case "radio":
             $html = "<select name=\"custom_field_operator_" . $objField->get("field") . "\" id=\"custom_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
             if (is_object($objParam) && $objParam->field_operator == "equals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"equals\" {$selected}>is equal to</option>";
             if (is_object($objParam) && $objParam->field_operator == "notequals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"notequals\" {$selected}>is not equal to</option>";
             $html .= "</select>&nbsp;\n\t\t\t\t\t\t\t\t <select name=\"custom_field_" . $objField->get("field") . "\" id=\"custom_field_" . $objField->get("field") . "\">\n\t\t\t\t\t\t\t\t\t<option value=\"\">--select--</option>\n\t\t\t\t\t\t\t\t\t#field_values\n\t\t\t\t\t\t\t\t </select>";
             foreach ($objField->get("field_values_data") as $id => $value) {
                 if (is_object($objParam) && $id == $objParam->field_value) {
                     $selected = "selected=\"selected\"";
                 } else {
                     $selected = "";
                 }
                 //end if
                 $html_values .= "<option value=\"{$id}\" {$selected}>{$value}</option>";
             }
             //end foreach
             $html = str_replace("#field_values", $html_values, $html);
             break;
         case "checkbox":
             $html = "<select name=\"custom_field_operator_" . $objField->get("field") . "\" id=\"custom_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
             if (is_object($objParam) && $objParam->field_operator == "equals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"equals\" {$selected}>is checked</option>";
             if (is_object($objParam) && $objParam->field_operator == "notequals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"notequals\" {$selected}>is not checked</option>";
             $html .= "</select>";
             break;
     }
     //end switch
     $element_id = str_replace(".", "", microtime(TRUE));
     $html_section = "<script type=\"text/javascript\">\n\t\t\t\t\t\t\tjQuery(document).ready(function () {\n\t\t\t\t\t\t\t\t//remove field section from criteria section\n\t\t\t\t\t\t\t\tjQuery(\".custom_field_section_{$element_id} .remove_section\").click(function () {\n\t\t\t\t\t\t\t\t\t//confirm removal\n\t\t\t\t\t\t\t\t\tif (confirm(\"Are you sure you want to remove this field?\"))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tjQuery(\".custom_field_section_{$element_id}\").remove();\n\t\t\t\t\t\t\t\t\t}//end if\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t</script>";
     $html_section .= "<div class=\"custom_field_section custom_field_section_{$element_id}\">";
     $html_section .= "<span class=\"custom_field_section field_criteria\">" . $objField->get("description") . " : </span>&nbsp;";
     $html_section .= $html;
     $html_section .= "<button class=\"remove_section\">-</button>";
     $html_section .= "</div>";
     return $html_section;
 }
 public function generateStandardFieldCriteriaHTML(FrontFormAdminFieldEntity $objField, $value = FALSE, $objParam = FALSE)
 {
     switch ($objField->get("field")) {
         case "city_id":
         case "province_id":
         case "country_id":
         case "user_id":
             $html = "<select name=\"std_field_operator_" . $objField->get("field") . "\" id=\"std_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
             if (is_object($objParam) && $objParam->field_operator == "equals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"equals\" {$selected}>is equal to</option>";
             if (is_object($objParam) && $objParam->field_operator == "notequals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"notequals\" {$selected}>is not equal to</option>";
             $html .= "</select>&nbsp;\n\t\t\t\t\t\t<select name=\"std_field_" . $objField->get("field") . "\" id=\"std_field_" . $objField->get("field") . "\">\n\t\t\t\t\t\t\t<option value=\"\">--select--</option>\n\t\t\t\t\t\t\t#field_values\n\t\t\t\t\t\t</select>";
             foreach ($objField->get("field_values_data") as $id => $field_value) {
                 if ($id == $value) {
                     $selected = "selected=\"selected\"";
                 } else {
                     $selected = "";
                 }
                 //end if
                 $html_values .= "<option value=\"{$id}\" {$selected}>{$field_value}</option>";
             }
             //end foreach
             $html = str_replace("#field_values", $html_values, $html);
             break;
         case "reference":
             $html = "<select name=\"std_field_operator_" . $objField->get("field") . "\" id=\"std_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
             if (is_object($objParam) && $objParam->field_operator == "equals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"equals\" {$selected}>is equal to</option>";
             if (is_object($objParam) && $objParam->field_operator == "notequals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"notequals\">is not equal to</option>";
             if (is_object($objParam) && $objParam->field_operator == "like") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"like\" {$selected}>is partly equal to</option>";
             if (is_object($objParam) && $objParam->field_operator == "notlike") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"notlike\" {$selected}>is not partly equal to</option>";
             $html .= "</select>&nbsp;\n\t\t\t\t\t\t<select name=\"std_field_" . $objField->get("field") . "\" id=\"std_field_" . $objField->get("field") . "\">\n\t\t\t\t\t\t\t<option value=\"\">--select--</option>\n\t\t\t\t\t\t\t#field_values\n\t\t\t\t\t\t</select>";
             foreach ($objField->get("field_values_data") as $id => $field_value) {
                 if ($id == $value) {
                     $selected = "selected=\"selected\"";
                 } else {
                     $selected = "";
                 }
                 //end if
                 $html_values .= "<option value=\"{$id}\" {$selected}>{$field_value}</option>";
             }
             //end foreach
             $html = str_replace("#field_values", $html_values, $html);
             break;
         case "suburb":
             $html = "<select name=\"std_field_operator_" . $objField->get("field") . "\" id=\"std_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
             if (is_object($objParam) && $objField->field_operator == "equals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"equals\" {$selected}>is equal to</option>";
             if (is_object($objParam) && $objField->field_operator == "notequals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"notequals\" {$selected}>is not equal to</option>";
             if (is_object($objParam) && $objField->field_operator == "like") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"like\" {$selected}>is partly equal to</option>";
             if (is_object($objParam) && $objField->field_operator == "notlike") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"notlike\">is not partly equal to</option>";
             $html .= "</select>&nbsp;\n\t\t\t\t\t\t<select name=\"std_field_" . $objField->get("field") . "\" id=\"std_field_" . $objField->get("field") . "\">\n\t\t\t\t\t\t\t<option value=\"\">--select--</option>\n\t\t\t\t\t\t\t#field_values\n\t\t\t\t\t\t</select>";
             foreach ($objField->get("field_values_data") as $id => $field_value) {
                 if ($field_value == $value) {
                     $selected = "selected=\"selected\"";
                 } else {
                     $selected = "";
                 }
                 //end if
                 $html_values .= "<option value=\"{$id}\" {$selected}>{$field_value}</option>";
             }
             //end foreach
             $html = str_replace("#field_values", $html_values, $html);
             break;
         case "source":
             $html = "<select name=\"std_field_operator_" . $objField->get("field") . "\" id=\"std_field_operator_" . $objField->get("field") . "\" required=\"required\">\n\t\t\t\t\t\t\t<option value=\"\">--select--</option>";
             if (is_object($objParam) && $objParam->field_operator == "equals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"equals\" {$selected}>is equal to</option>";
             if (is_object($objParam) && $objParam->field_operator == "notequals") {
                 $selected = "selected=\"selected\"";
             } else {
                 $selected = "";
             }
             //end if
             $html .= "<option value=\"notequals\" {$selected}>is not equal to</option>";
             $html .= "</select>&nbsp;\n\t\t\t\t\t\t<select name=\"std_field_" . $objField->get("field") . "\" id=\"std_field_" . $objField->get("field") . "\">\n\t\t\t\t\t\t\t<option value=\"\">--select--</option>\n\t\t\t\t\t\t\t#field_values\n\t\t\t\t\t\t</select>";
             foreach ($objField->get("field_values_data") as $id => $field_value) {
                 if ($field_value == $value) {
                     $selected = "selected=\"selected\"";
                 } else {
                     $selected = "";
                 }
                 //end if
                 $html_values .= "<option value=\"{$id}\" {$selected}>{$field_value}</option>";
             }
             //end foreach
             $html = str_replace("#field_values", $html_values, $html);
             break;
         default:
             return FALSE;
             break;
     }
     //end switch
     $element_id = str_replace(".", "", microtime(TRUE));
     $html_section = "<script type=\"text/javascript\">\n\t\t\t\t\t\t\tjQuery(document).ready(function () {\n\t\t\t\t\t\t\t\t//remove field section from criteria section\n\t\t\t\t\t\t\t\tjQuery(\".std_field_section_{$element_id} .remove_section\").click(function () {\n\t\t\t\t\t\t\t\t\t//confirm removal\n\t\t\t\t\t\t\t\t\tif (confirm(\"Are you sure you want to remove this field?\"))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tjQuery(\".std_field_section_{$element_id}\").remove();\n\t\t\t\t\t\t\t\t\t}//end if\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t</script>";
     $html_section .= "<div class=\"std_field_section std_field_section_{$element_id}\">";
     $html_section .= "<span class=\"std_field_section field_criteria\">" . $objField->get("description") . " : </span>&nbsp;";
     $html_section .= $html;
     $html_section .= "<button class=\"remove_section\">-</button>";
     $html_section .= "</div>";
     return $html_section;
 }
 /**
  * Update an existing custom field
  * @triggers updateCustomField.pre, updateCustomField.post
  * @param FrontFormAdminFieldEntity $objField
  * @return \FrontFormAdmin\Entities\FrontFormAdminFieldEntity
  */
 public function updateCustomField(FrontFormAdminFieldEntity $objField)
 {
     //create the request object
     $objApiRequest = $this->getApiRequestModel();
     //setup the object and specify the action
     $objApiRequest->setApiAction($objField->getHyperMedia("edit-field")->url);
     $objApiRequest->setApiModule(NULL);
     //trigger pre event
     $result = $this->getEventManager()->trigger(__FUNCTION__ . ".pre", $this, array("objField" => $objField, "objApiRequest" => $objApiRequest));
     //execute
     $objResult = $objApiRequest->performPUTRequest($objField->getArrayCopy())->getBody();
     //create link entity
     $entity_field = $this->createFieldEntity($objResult->data);
     //trigger post event
     $result = $this->getEventManager()->trigger(__FUNCTION__ . ".post", $this, array("objField" => $entity_field, "objResult" => $objResult));
     return $entity_field;
 }