00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfields.class.php" );
00006 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00007 lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
00008 lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
00009 lt_include( PLOG_CLASS_PATH."class/view/admin/admincustomfieldslistview.class.php" );
00010
00017 class AdminAddCustomFieldAction extends AdminAction
00018 {
00019
00020 var $_fieldName;
00021 var $_fieldDescription;
00022 var $_fieldType;
00023 var $_fieldSearchable;
00024 var $_fieldHidden;
00025
00026 function AdminAddCustomFieldAction( $actionInfo, $request )
00027 {
00028 $this->AdminAction( $actionInfo, $request );
00029
00030
00031 $this->registerFieldValidator( "fieldName", new StringValidator());
00032 $this->registerFieldValidator( "fieldDescription", new StringValidator());
00033 $this->registerFieldValidator( "fieldType", new IntegerValidator());
00034 $this->registerFieldValidator( "fieldSearchable", new IntegerValidator(), true );
00035 $this->registerFieldValidator( "fieldHidden", new IntegerValidator(), true );
00036 if( $this->_request->getValue( "fieldType" ) == CUSTOM_FIELD_LIST )
00037 {
00038 $this->registerFieldValidator( "fieldValues", new ArrayValidator( new StringValidator() ));
00039 }
00040 $view = new AdminTemplatedView( $this->_blogInfo, "newcustomfield" );
00041 $view->setErrorMessage( $this->_locale->tr("error_adding_custom_field"));
00042 $this->setValidationErrorView( $view );
00043
00044 $this->requirePermission( "add_custom_field" );
00045 }
00046
00050 function perform()
00051 {
00052
00053 $this->_fieldName = Textfilter::filterAllHTML($this->_request->getValue( "fieldName" ));
00054 $this->_fieldDescription = Textfilter::filterAllHTML($this->_request->getValue( "fieldDescription" ));
00055 $this->_fieldType = $this->_request->getValue( "fieldType" );
00056 $this->_fieldSearchable = (int)($this->_request->getValue( "fieldSearchable" ) != "" );
00057 $this->_fieldHidden = (int)($this->_request->getValue( "fieldHidden" ) != "" );
00058
00059
00060 if( $this->_fieldType == CUSTOM_FIELD_LIST ) {
00061 $values = $this->_request->getValue( "fieldValues" );
00062 $this->_fieldValues = Array();
00063 foreach( $values as $value ) {
00064 $this->_fieldValues[] = Textfilter::filterAllHTML( $value );
00065 }
00066 }
00067
00068 $fields = new CustomFields();
00069
00070
00071 $customField = new CustomField( $this->_fieldName,
00072 $this->_fieldDescription,
00073 $this->_fieldType,
00074 $this->_blogInfo->getId(),
00075 $this->_fieldHidden,
00076 $this->_fieldSearchable );
00077
00078 if( $this->_fieldType == CUSTOM_FIELD_LIST )
00079 $customField->setFieldValues( $this->_fieldValues );
00080
00081
00082 $this->notifyEvent( EVENT_PRE_CUSTOM_FIELD_ADD, Array( "field" => &$customField ));
00083
00084 $result = $fields->addCustomField( $customField );
00085
00086 if( $this->userHasPermission( "view_custom_fields" ))
00087 $this->_view = new AdminCustomFieldsListView( $this->_blogInfo );
00088 else
00089 $this->_view = new AdminTemplatedView( $this->_blogInfo, "newcustomfield" );
00090
00091 if( !$result ) {
00092 $this->_view->setErrorMessage( $this->_locale->tr("error_adding_custom_field" ));
00093 }
00094 else {
00095 $this->_view->setSuccessMessage( $this->_locale->pr( "custom_field_added_ok", $customField->getName()));
00096
00097
00098 $this->notifyEvent( EVENT_POST_CUSTOM_FIELD_ADD, Array( "field" => &$customField ));
00099 }
00100
00101 $this->setCommonData();
00102
00103 return true;
00104 }
00105 }
00106 ?>