1: <?php
2: 3: 4: 5: 6:
7:
8: if (!defined('XOOPS_ROOT_PATH')) exit();
9:
10: require_once XOOPS_ROOT_PATH . "/core/XCube_ActionForm.class.php";
11: require_once XOOPS_MODULE_PATH . "/legacy/class/Legacy_Validator.class.php";
12:
13: class Profile_DataEditForm extends XCube_ActionForm
14: {
15:
16: var $mDef = array();
17:
18: 19: 20:
21: function getTokenName()
22: {
23: return "module.profile.DataEditForm.TOKEN";
24: }
25:
26: 27: 28:
29: function prepare()
30: {
31: $handler =& xoops_getmodulehandler('definitions');
32: $this->mDef = $handler->getFields4DataEdit();
33:
34:
35:
36:
37: $this->mFormProperties['uid'] =new XCube_IntProperty('uid');
38: foreach(array_keys($this->mDef) as $key){
39: $className = $this->mDef[$key]->mFieldType->getFormPropertyClass();
40: $this->mFormProperties[$this->mDef[$key]->get('field_name')] =new $className($this->mDef[$key]->get('field_name'));
41:
42:
43: $validationArr = array();
44: $this->mFieldProperties[$this->mDef[$key]->get('field_name')] =new XCube_FieldProperty($this);
45:
46: if($this->mDef[$key]->get('required')==1){
47: $validationArr[] = 'required';
48: $this->mFieldProperties[$this->mDef[$key]->get('field_name')]->addMessage('required', _MD_PROFILE_ERROR_REQUIRED, $this->mDef[$key]->get('label'));
49: }
50:
51: switch($this->mDef[$key]->get('validation')){
52: case 'email' :
53: $validationArr[] = 'email';
54: $this->mFieldProperties[$this->mDef[$key]->get('field_name')]->addMessage($this->mDef[$key]->get('field_name'), _MD_PROFILE_ERROR_EMAIL);
55: break;
56: }
57: $this->mFieldProperties[$this->mDef[$key]->get('field_name')]->setDependsByArray($validationArr);
58: }
59:
60:
61:
62:
63: $this->mFieldProperties['uid'] =new XCube_FieldProperty($this);
64: $this->mFieldProperties['uid']->setDependsByArray(array('required'));
65: $this->mFieldProperties['uid']->addMessage('required', _MD_PROFILE_ERROR_REQUIRED, _MD_PROFILE_LANG_UID);
66: }
67:
68: 69: 70:
71: function load(&$obj)
72: {
73: $this->set('uid', $obj->get('uid'));
74: foreach(array_keys($this->mDef) as $key){
75: $this->set($this->mDef[$key]->get('field_name'), $obj->showField($this->mDef[$key]->get('field_name'), Profile_ActionType::EDIT));
76: }
77: }
78:
79: 80: 81:
82: function update(&$obj)
83: {
84: $obj->set('uid', $this->get('uid'));
85: foreach(array_keys($this->mDef) as $key){
86: $val = ($this->mDef[$key]->get('type')!='date') ? $this->get($this->mDef[$key]->get('field_name')) : $this->_makeUnixtime($this->mDef[$key]->get('field_name'));
87: $obj->set($this->mDef[$key]->get('field_name'), $val);
88: }
89: }
90:
91: protected function _makeUnixtime($key)
92: {
93: $timeArray = explode('/', $this->get($key));
94: return mktime(0, 0, 0, $timeArray[1], $timeArray[2], $timeArray[0]);
95: }
96: }
97:
98: ?>
99: