Ejemplo n.º 1
0
 /**
  * Constructor ContactForm
  * @param Page $page_object 
  * @param string $send_method 
  * @param string $table_style 
  */
 function __construct($page_object, $send_method, $table_style = '')
 {
     parent::__construct();
     if (!isset($page_object) || !isset($send_method)) {
         throw new NewException("2 arguments for " . get_class($this) . "::__construct() are mandatory", 0, getDebugBacktrace(1));
     }
     if (gettype($page_object) != "object" || !is_subclass_of($page_object, "Page")) {
         throw new NewException("Argument page_object for " . get_class($this) . "::__construct() error", 0, getDebugBacktrace(1));
     }
     $this->page_object = $page_object;
     $this->mail_to = SMTP_MAIL;
     $this->mail_to_name = SMTP_NAME;
     $table_main = new Table();
     $table_main->setClass($table_style);
     $form = new Form($this->page_object);
     $name = new TextBox($form, "contact_name");
     $name_validation = new LiveValidation();
     $name->setLiveValidation($name_validation->addValidatePresence()->setFieldName(__(CONTACTFORM_NAME)));
     $table_main->addRowColumns(__(CONTACTFORM_NAME) . ": ", $name->setFocus())->setColumnWidth(2, "100%");
     $email = new TextBox($form, "contact_email");
     $email_validation = new LiveValidation();
     $email->setLiveValidation($email_validation->addValidateEmail()->addValidatePresence()->setFieldName(__(CONTACTFORM_EMAIL)));
     $table_main->addRowColumns(__(CONTACTFORM_EMAIL) . ": ", $email);
     $subject = new TextBox($form, "contact_subject");
     $subject_validation = new LiveValidation();
     $subject->setLiveValidation($subject_validation->addValidatePresence()->setFieldName(__(CONTACTFORM_SUBJECT)));
     $table_main->addRowColumns(__(CONTACTFORM_SUBJECT) . ": ", $subject);
     $table_main->addRow();
     $editor = new Editor($form, "contact_message");
     $editor_validation = new LiveValidation();
     $editor->setLiveValidation($editor_validation->addValidatePresence()->setFieldName(__(CONTACTFORM_MESSAGE)));
     $editor->setToolbar(Editor::TOOLBAR_SIMPLE);
     $table_main->addRow(new Object(__(CONTACTFORM_MESSAGE) . ": ", "<br/>", $editor))->setColspan(3)->setAlign(RowTable::ALIGN_LEFT);
     $table_main->addRow();
     $this->captcha = new Captcha($form, "contact_captcha");
     $table_main->addRow($this->captcha)->setColspan(3);
     $table_main->addRow();
     $this->send_button = new Button($form, "contact_send", "", __(CONTACTFORM_SEND));
     $this->send_button->assignEnterKey()->onClick($send_method)->setAjaxEvent();
     $table_main->addRow($this->send_button)->setColspan(3);
     $table_main->addRow();
     $form->setContent($table_main);
     $this->render = $form;
 }
Ejemplo n.º 2
0
 /**
  * FormHandler::editor()
  *
  * Create a editor on the form
  *
  * @param string $title: The title of the field
  * @param string $name: The name of the field
  * @param string $validator: The validator which should be used to validate the value of the field
  * @param string $path: Path on the server where we have to upload the files
  * @param string $toolbar: The toolbar we have to use
  * @param string $skin: The skin to use
  * @param int $width: The width of the field
  * @param int $height: The height of the field
  * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
  * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  * @return void
  * @access public
  * @author Teye Heimans
  */
 function editor($title, $name, $validator = null, $path = null, $toolbar = null, $skin = null, $width = null, $height = null, $config = null)
 {
     require_once FH_INCLUDE_DIR . 'fields/class.TextArea.php';
     require_once FH_INCLUDE_DIR . 'fields/class.Editor.php';
     // create a new editor
     $fld = new Editor($this, $name);
     if (!empty($validator)) {
         $fld->setValidator($validator);
     }
     if (!is_null($path)) {
         $fld->setServerPath($path);
     }
     if (!empty($toolbar)) {
         $fld->setToolbar($toolbar);
     }
     if (!empty($skin)) {
         $fld->setSkin($skin);
     }
     if (!empty($width)) {
         $fld->setWidth($width);
     }
     if (!empty($height)) {
         $fld->setHeight($height);
     }
     if (is_array($config)) {
         $fld->setConfig($config);
     }
     // register the field
     $this->_registerField($name, $fld, $title);
 }
Ejemplo n.º 3
0
 /**
  * Method prepareFieldsArray
  * @access public
  * @param mixed $properties [default value: array(]
  * @return mixed
  * @since 1.2.1
  */
 public function prepareFieldsArray($properties = array())
 {
     $this->fields_array = array();
     $list_attribute = $this->database_object->getDbTableAttributes();
     $list_attribute_type = $this->database_object->getDbTableAttributesType();
     $auto_increment_id = $this->database_object->getDbTableAutoIncrement();
     // Add properties to apply on all fields
     if (isset($properties[ModelViewMapper::PROPERTIES_ALL]) && is_array($properties[ModelViewMapper::PROPERTIES_ALL])) {
         $apply_all_array = $properties[ModelViewMapper::PROPERTIES_ALL];
         foreach ($apply_all_array as $property_name => $property_value) {
             for ($i = 0; $i < sizeof($list_attribute); $i++) {
                 $property[$property_name] = $property_value;
                 if (isset($properties[$list_attribute[$i]])) {
                     // Handle child override of global property
                     if (!isset($properties[$list_attribute[$i]][$property_name])) {
                         $properties[$list_attribute[$i]] = array_merge($properties[$list_attribute[$i]], $property);
                     }
                 } else {
                     $properties[$list_attribute[$i]] = $property;
                 }
             }
         }
     }
     // check foreign keys
     $db_table_foreign_keys = $this->database_object->getDbTableForeignKeys();
     foreach ($db_table_foreign_keys as $fk_attribute => $value) {
         if (isset($properties[$fk_attribute])) {
             $fk_property = $properties[$fk_attribute];
             if (isset($fk_property["fk_attribute"])) {
                 // create combobox
                 $cmb = new ComboBox($this->form_or_page);
                 // get foreign key data
                 $query = "select distinct " . $value["column"] . " as id, " . $fk_property["fk_attribute"] . " as value from " . $value["table"];
                 if (isset($fk_property["fk_where"])) {
                     $query .= " where " . $fk_property["fk_where"];
                 }
                 if (isset($fk_property["fk_orderby"])) {
                     $query .= " order by " . $fk_property["fk_orderby"];
                 }
                 $stmt = DataBase::getInstance()->prepareStatement($query);
                 $row = DataBase::getInstance()->stmtBindAssoc($stmt, $row);
                 while ($stmt->fetch()) {
                     $cmb->addItem(utf8encode($row['id']), utf8encode($row['value']));
                 }
                 // add combo box in properties
                 $value['cmb_obj'] = $cmb;
                 $properties[$fk_attribute] = array_merge($properties[$fk_attribute], $value);
             }
         }
     }
     foreach ($list_attribute as $i => $attribute) {
         $wspobject = "TextBox";
         $attribute_properties = array();
         if (is_array($properties[$attribute])) {
             $attribute_properties = $properties[$attribute];
         }
         if (isset($attribute_properties["display"]) && $attribute_properties["display"] == false) {
             continue;
         }
         $is_update_ok = true;
         if (isset($attribute_properties["update"]) && $attribute_properties["update"] == false) {
             $is_update_ok = false;
         }
         $method = "get" . $this->getFormatValue($attribute);
         $value = call_user_func_array(array($this->database_model_object, $method), array());
         if ($attribute != $auto_increment_id && $is_update_ok) {
             // get property cmb_obj
             if (isset($attribute_properties['cmb_obj'])) {
                 $field = $attribute_properties['cmb_obj'];
             } else {
                 if (isset($attribute_properties["wspobject"]) && $attribute_properties["wspobject"] != "") {
                     $wspobject = $attribute_properties["wspobject"];
                 } else {
                     if ($list_attribute_type[$i] == "datetime") {
                         $wspobject = "Calendar";
                     } else {
                         if ($list_attribute_type[$i] == "boolean") {
                             $wspobject = "CheckBox";
                         }
                     }
                 }
                 if ($wspobject == "Calendar") {
                     $field = new Calendar($this->form_or_page);
                 } else {
                     if ($wspobject == "CheckBox") {
                         $field = new CheckBox($this->form_or_page);
                     } else {
                         if ($wspobject == "TextArea") {
                             $field = new TextArea($this->form_or_page);
                         } else {
                             if ($wspobject == "Editor") {
                                 $field = new Editor($this->form_or_page);
                                 if (isset($attribute_properties["editor_param"]) && $attribute_properties["editor_param"] != "") {
                                     $field->setToolbar($attribute_properties["editor_param"]);
                                 }
                             } else {
                                 if ($wspobject == "ComboBox") {
                                     $field = new ComboBox($this->form_or_page);
                                     if (isset($attribute_properties["combobox_values"])) {
                                         if (is_array($attribute_properties["combobox_values"])) {
                                             for ($j = 0; $j < sizeof($attribute_properties["combobox_values"]); $j++) {
                                                 $field->addItem($attribute_properties["combobox_values"][$j]['value'], $attribute_properties["combobox_values"][$j]['text']);
                                             }
                                         } else {
                                             throw new NewException(get_class($this) . "->prepareFieldsArray() error: the property combobox_values need to be an array.", 0, getDebugBacktrace(1));
                                         }
                                     }
                                 } else {
                                     $field = new TextBox($this->form_or_page);
                                     if ($list_attribute_type[$i] == "integer" || $list_attribute_type[$i] == "double") {
                                         $field->setWidth(70);
                                     }
                                     if (in_array($attribute, $key_attributes)) {
                                         $lv = new LiveValidation();
                                         $field->setLiveValidation($lv->addValidatePresence());
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             // Handle Checkbox case that only support value as "on" or "off"
             if (get_class($field) == "CheckBox") {
                 if ($value == "1") {
                     $field->setValue("on");
                 } else {
                     $field->setValue("off");
                 }
             } else {
                 if (get_class($field) == "Calendar") {
                     $field->setValue($value);
                 } else {
                     $field->setValue(utf8encode($value));
                 }
             }
             if (isset($attribute_properties["width"]) && method_exists($field, "setWidth")) {
                 $field->setWidth($attribute_properties["width"]);
             }
             if (isset($attribute_properties["height"]) && method_exists($field, "setHeight")) {
                 $field->setHeight($attribute_properties["height"]);
             }
             if (isset($attribute_properties["class"]) && method_exists($field, "setClass")) {
                 $field->setClass($attribute_properties["class"]);
             }
             if (isset($attribute_properties["style"]) && method_exists($field, "setStyle")) {
                 $field->setStyle($attribute_properties["style"]);
             }
             if (isset($attribute_properties["disable"])) {
                 if ($attribute_properties["disable"] == true && method_exists($field, "disable")) {
                     $field->disable();
                 } else {
                     if ($attribute_properties["disable"] == false && method_exists($field, "enable")) {
                         $field->enable();
                     }
                 }
             }
             if (get_class($field) != "Calendar") {
                 if (isset($attribute_properties["strip_tags"]) && $attribute_properties["strip_tags"] == true && method_exists($field, "setStripTags")) {
                     if (isset($attribute_properties["allowable_tags"])) {
                         $field->setStripTags($attribute_properties["allowable_tags"]);
                     } else {
                         $field->setStripTags("");
                         // no tag allowed
                     }
                 }
             }
         } else {
             if (isset($attribute_properties['cmb_obj'])) {
                 $field_tmp = $attribute_properties['cmb_obj'];
                 $field_tmp->setValue($value);
                 $value = $field_tmp->getText();
             }
             if (get_class($value) == "DateTime") {
                 $value = $value->format("Y-m-d");
             }
             $field = new Object(utf8encode($value));
         }
         $this->fields_array[$attribute] = $field;
     }
     return $this->fields_array;
 }
Ejemplo n.º 4
0
 /**
  * Method createDbAttributeObject
  * @access private
  * @param mixed $row 
  * @param mixed $list_attribute 
  * @param mixed $list_attribute_type 
  * @param mixed $i 
  * @param mixed $ind 
  * @param mixed $key_attributes 
  * @return mixed
  * @since 1.1.6
  */
 private function createDbAttributeObject($row, $list_attribute, $list_attribute_type, $i, $ind, $key_attributes)
 {
     // get property cmb_obj (created by method loadFromSqlDataView)
     if (isset($this->from_sql_data_view_properties[$list_attribute[$i]]['cmb_obj'])) {
         $input_obj_tmp = $this->from_sql_data_view_properties[$list_attribute[$i]]['cmb_obj'];
         $input_obj = clone $input_obj_tmp;
         $input_obj->setName($this->id . "_input_" . $list_attribute[$i] . "_ind_" . $ind);
         $register_objects = WebSitePhpObject::getRegisterObjects();
         $register_objects[] = $input_obj;
         $_SESSION['websitephp_register_object'] = $register_objects;
     } else {
         $wspobject = "TextBox";
         $attribute_properties = array();
         if (is_array($this->from_sql_data_view_properties[$list_attribute[$i]])) {
             $attribute_properties = $this->from_sql_data_view_properties[$list_attribute[$i]];
         }
         if (isset($attribute_properties["wspobject"]) && $attribute_properties["wspobject"] != "") {
             $wspobject = $attribute_properties["wspobject"];
         } else {
             if ($list_attribute_type[$i] == "datetime") {
                 $wspobject = "Calendar";
             } else {
                 if ($list_attribute_type[$i] == "boolean") {
                     $wspobject = "CheckBox";
                 }
             }
         }
         if ($wspobject == "Calendar") {
             $input_obj = new Calendar($this->table_form_object, $this->id . "_input_" . $list_attribute[$i] . "_ind_" . $ind);
         } else {
             if ($wspobject == "CheckBox") {
                 $input_obj = new CheckBox($this->table_form_object, $this->id . "_input_" . $list_attribute[$i] . "_ind_" . $ind);
             } else {
                 if ($wspobject == "TextArea") {
                     $input_obj = new TextArea($this->table_form_object, $object_id);
                 } else {
                     if ($wspobject == "Editor") {
                         $input_obj = new Editor($this->table_form_object, $object_id);
                         if (isset($attribute_properties["editor_param"]) && $attribute_properties["editor_param"] != "") {
                             $input_obj->setToolbar($attribute_properties["editor_param"]);
                         }
                     } else {
                         if ($wspobject == "ComboBox") {
                             $input_obj = new ComboBox($this->table_form_object, $object_id);
                             if (isset($attribute_properties["combobox_values"])) {
                                 if (is_array($attribute_properties["combobox_values"])) {
                                     for ($j = 0; $j < sizeof($attribute_properties["combobox_values"]); $j++) {
                                         $input_obj->addItem($attribute_properties["combobox_values"][$j]['value'], $attribute_properties["combobox_values"][$j]['text']);
                                     }
                                 } else {
                                     throw new NewException(get_class($this) . "->loadFromSqlDataView() error: the property combobox_values need to be an array.", 0, getDebugBacktrace(1));
                                 }
                             }
                         } else {
                             $input_obj = new TextBox($this->table_form_object, $this->id . "_input_" . $list_attribute[$i] . "_ind_" . $ind);
                             if ($list_attribute_type[$i] == "integer" || $list_attribute_type[$i] == "double") {
                                 $input_obj->setWidth(70);
                             }
                             if (in_array($list_attribute[$i], $key_attributes)) {
                                 $lv = new LiveValidation();
                                 $input_obj->setLiveValidation($lv->addValidatePresence());
                             }
                         }
                     }
                 }
             }
         }
     }
     // get properties width and strip_tags
     if (is_array($this->from_sql_data_view_properties[$list_attribute[$i]])) {
         $attribute_properties = $this->from_sql_data_view_properties[$list_attribute[$i]];
         if (isset($attribute_properties["width"]) && method_exists($input_obj, "setWidth")) {
             $input_obj->setWidth($attribute_properties["width"]);
         }
         if (isset($attribute_properties["height"]) && method_exists($input_obj, "setHeight")) {
             $input_obj->setHeight($attribute_properties["height"]);
         }
         if (isset($attribute_properties["class"]) && method_exists($input_obj, "setClass")) {
             $input_obj->setClass($attribute_properties["class"]);
         }
         if (isset($attribute_properties["style"]) && method_exists($input_obj, "setStyle")) {
             $input_obj->setStyle($attribute_properties["style"]);
         }
         if (isset($attribute_properties["disable"])) {
             if ($attribute_properties["disable"] == true && method_exists($input_obj, "disable")) {
                 $input_obj->disable();
             } else {
                 if ($attribute_properties["disable"] == false && method_exists($input_obj, "enable")) {
                     $input_obj->enable();
                 }
             }
         }
         if (get_class($input_obj) != "Calendar") {
             if (isset($attribute_properties["strip_tags"]) && $attribute_properties["strip_tags"] == true && method_exists($input_obj, "setStripTags")) {
                 if (isset($attribute_properties["allowable_tags"])) {
                     $input_obj->setStripTags($attribute_properties["allowable_tags"]);
                 } else {
                     $input_obj->setStripTags("");
                     // no tag allowed
                 }
             }
         }
     }
     if ($row != null) {
         // get property db_attribute
         $field_value = $row->getValue($list_attribute[$i]);
         if (isset($this->from_sql_data_view_properties[$list_attribute[$i]]["db_attribute"])) {
             $db_attribute = $this->from_sql_data_view_properties[$list_attribute[$i]]["db_attribute"];
             $field_value = $row->getValue($db_attribute);
         }
         $input_obj->onChange("onChangeTableFromSqlDataView")->setAjaxEvent()->disableAjaxWaitMessage();
         if (get_class($input_obj) == "TextBox") {
             $input_obj->onKeyUpJs("if (\$(this)[0].defaultValue != \$(this).val()) { \$('#" . $this->id . "_img_" . $ind . "_cancel_" . $list_attribute[$i] . "').hide(); } else { \$('#" . $this->id . "_img_" . $ind . "_cancel_" . $list_attribute[$i] . "').show(); }");
         }
         if ($list_attribute_type[$i] == "boolean") {
             if (!$input_obj->isChanged()) {
                 $input_obj->setValue($field_value == true ? "on" : "off");
             }
         } else {
             if (gettype($field_value) == "object") {
                 $input_obj->setValue($field_value);
             } else {
                 $input_obj->setValue(utf8encode($field_value));
             }
         }
     }
     return $input_obj;
 }