pwCustomerField = ($pwCustomerField && is_a($pwCustomerField , 'PW_CustomerField')) ? $pwCustomerField : L::loadClass('CustomerField','user');
$this->initHtmlTemplate();
}
function buildHtml($fieldInfo,$defaultValue=''){
if (!S::isArray($fieldInfo)) return false;
$this->fieldHtml = '';
$this->defaultValueHtml = '';
$this->fieldInfo = $this->pwCustomerField->formatFieldInfo($fieldInfo);
$this->defaultValue = '';
$defaultValue && $this->defaultValue = $defaultValue;
$this->formatRequriedHtml();
$this->formatDescripHtml();
if (!isset($this->pwCustomerField->flipTypeMap[$this->fieldInfo['type']])) return false;
$methodName = 'build'. ucfirst($this->pwCustomerField->flipTypeMap[$this->fieldInfo['type']]);
$htmlTemplate = 'template'. ucfirst($this->pwCustomerField->flipTypeMap[$this->fieldInfo['type']]);
method_exists($this,$methodName) && eval("\$this->$methodName();");
if(!isset($this->htmlTemplate[$htmlTemplate])) return false;
$this->fieldHtml = str_replace(
array(
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
),
array(
$this->fieldInfo['title'],
$this->fieldInfo['maxlen'],
$this->fieldInfo['fieldname'],
$this->fieldInfo['descrip'],
$this->requriedHtml,
$this->descripHtml,
$this->fieldInfo['html_select'],
$this->fieldInfo['html_radio'],
$this->fieldInfo['html_checkbox'],
$this->fieldInfo['html_year'],
$this->fieldInfo['html_areascripts'],
$this->fieldInfo['html_areaprovince'],
$this->fieldInfo['html_areacity'],
$this->fieldInfo['html_areaarea'],
$this->fieldInfo['html_eduscripts'],
$this->fieldInfo['html_eduname'],
$this->fieldInfo['html_edulevel'],
$this->fieldInfo['html_eduyear'],
$this->fieldInfo['html_careerscripts'],
$this->fieldInfo['html_careername'],
$this->fieldInfo['html_careerdate'],
$this->defaultValueHtml,
),
$this->htmlTemplate[$htmlTemplate]
);
if(preg_match_all('/<\!--\[IF\sFIELD_([A-Z_]+)\]-->.*<\!--\[ENDIF\sFIELD_[A-Z_]+\]-->/',$this->fieldHtml,$m)) {
$deleteFragment = array();
foreach($m[1] as $k=>$v){
$key = strtolower($v);
if(!isset($fieldInfo[$key]) || !$fieldInfo[$key]) {
$deleteFragment[] = $m[0][$k];
}
}
$deleteFragment && $this->fieldHtml = str_replace($deleteFragment,'',$this->fieldHtml);
//$this->fieldHtml = preg_replace('/<\!?--\[(IF|ENDIF)\sFIELD_[A-Z_]+\]-->/i','',$this->fieldHtml);
}
return true;
}
function formatRequriedHtml(){
$this->requriedHtml = $this->fieldInfo['required'] ? '*' : '';
}
function formatDescripHtml(){
$this->descripHtml = $this->fieldInfo['descrip'] ? '':' style="display:none"';
}
function buildInput(){
$this->defaultValue && $this->defaultValueHtml = $this->defaultValue;
}
function buildTextarea(){
$this->defaultValue && $this->defaultValueHtml = $this->defaultValue;
}
function buildSelect(){
$this->fieldInfo['html_select'] = <<
EOT;
$selectedHtml = '';
foreach ($this->fieldInfo['options'] as $k=>$v){
$selectedHtml = '';
if ($this->defaultValue && $k == $this->defaultValue) $selectedHtml = ' selected=1';
$this->fieldInfo['html_select'] .= <<$v
EOT;
}
$this->fieldInfo['html_select'] .= <<
EOT;
}
function buildRadio(){
$this->fieldInfo['html_radio'] = '';
$checked = false;
foreach ($this->fieldInfo['options'] as $k=>$v){
$checkedHtml = '';
if ($this->defaultValue && $k == $this->defaultValue && $checked == false) {
$checkedHtml = 'checked';
$checked = true;
}
$this->fieldInfo['html_radio'] .= <<$v
EOT;
}
}
function buildCheckbox(){
$this->fieldInfo['html_checkbox'] = '';
$defaultValue = array();
$this->defaultValue && $defaultValue = explode("\t",$this->defaultValue);
foreach ($this->fieldInfo['options'] as $k=>$v){
$checkedHtml = S::inArray($k,$defaultValue) ? ' checked' : '';
$this->fieldInfo['html_checkbox'] .= <<$v
EOT;
}
}
function buildYear(){
$this->fieldInfo['html_year'] = '';
$defaultValue = array('year'=>0,'month'=>0,'day'=>0);
if ($this->defaultValue) {
$tmpDate = getdate(strtotime($this->defaultValue));
$defaultValue['year'] = $tmpDate['year'];
$defaultValue['month'] = $tmpDate['mon'];
$defaultValue['day'] = $tmpDate['mday'];
}
$this->fieldInfo['html_year'] .= <<
EOT;
for ($i = $this->fieldInfo['options']['enddate']; $i>= $this->fieldInfo['options']['startdate']; $i--) {
//year
$selectedHtml = $i == $defaultValue['year'] ? ' selected=1' : '';
$this->fieldInfo['html_year'] .= <<$i
EOT;
}
$this->fieldInfo['html_year'] .= <<
EOT;
}
function buildArea(){
static $areaService;
!$areaService && $areaService = L::LoadClass('AreasService','utility');
$id = md5(microtime());
if(!S::isArray($this->defaultValue)){
$basicValue = array(array('parentid'=>0,'selectid'=>'province_'.$id,'defaultid'=>'','hasfirst'=>1));
} else {
//var_dump($this->defaultValue);exit;
$basicValue = array(
array('parentid'=>0,'selectid'=>'province_'.$id,'defaultid'=>intval($this->defaultValue['province']),'hasfirst'=>1),
array('parentid'=>$this->defaultValue['province'],'selectid'=>'city_'.$id,'defaultid'=>intval($this->defaultValue['city']),'hasfirst'=>1),
array('parentid'=>$this->defaultValue['city'],'selectid'=>'area_'.$id,'defaultid'=>intval($this->defaultValue['area']),'hasfirst'=>1)
);
}
$this->fieldInfo['html_areascripts'] = $areaService->buildAllAreasLists($basicValue);
if(!$this->loadedScripts['area']){
$this->fieldInfo['html_areascripts'] .= <<
EOT;
$this->loadedScripts['area'] = true;
}
$this->fieldInfo['html_areaprovince'] = <<
EOT;
$this->fieldInfo['html_areacity'] = <<
EOT;
$this->fieldInfo['html_areaarea'] = <<
EOT;
}
function buildEducation(){
$id = 'ids_' . md5(microtime());
$this->fieldInfo['html_eduscripts'] = <<
var eduHtml = '';
function getSchoolWindow(id,inputObj){
var type=1;
inputObj = getObj('schoolname_' + id);
level = getObj('level_' + id).value;
var schoolNameObj = getObj('schoolname_'+id);
if(level > 3){
type = 3;//大學
}else if(level > 1){
type = 2;//中學
}
url = 'pw_ajax.php?action=pwschools&type=' + type + '&sid=' + id;
sendmsg(url,'',getObj('schoolname_' + id));return false;
}
function addEducation(s,t){
var l = getObj(t).lastChild;
var n = getObj(s).cloneNode(true);
n.style.display = '';
n.id = '';
n.innerHTML = n.innerHTML.replace(/((w+_)?ids_)[a-z0-9]+/ig, '$1'+Math.random().toString().substring(2));
getObj(t).insertBefore(n,l);
}
EOT;
$this->fieldInfo['html_edulevel'] = <<
EOT;
$this->fieldInfo['html_eduname'] = <<
EOT;
$this->fieldInfo['html_eduyear'] = <<
EOT;
$date = getdate($GLOBALS['timestamp']);
$startYear = $date['year'] - 10;
$endYear = $startYear - 60;
for($i = $startYear; $i>= $endYear ; $i--){
$this->fieldInfo['html_eduyear'] .= <<$i
EOT;
}
$this->fieldInfo['html_eduyear'] .= <<
EOT;
/*有默認值格式化默認值*/
if (S::isArray($this->defaultValue) && preg_match('/<\!--DEFAULT_VALUE_TEMPLATE-->(.*)<\!--END_DEFAULT_VALUE_TEMPLATE-->/is',$this->htmlTemplate['templateEducation'],$m) ) {
if(!$m[1]) return ;
foreach ($this->defaultValue as $k=>$v) {
if (!S::isArray($v)) continue;
$tmpEducation = array();
//教育程度
$tmpEducation['html_edulevel'] = <<
EOT;
$tmpEducation['html_eduname'] = <<
EOT;
//入學年份
$tempDate = getdate($v['starttime']);
$year = $tempDate['year'];
$tmpEducation['html_eduyear'] = <<
EOT;
$date = getdate($GLOBALS['timestamp']);
$startYear = $date['year'] - 10;
$endYear = $startYear - 60;
for($i = $startYear; $i>= $endYear ; $i--){
$selectedHtml = $i == $year ? ' selected=1' : '';
$tmpEducation['html_eduyear'] .= <<$i
EOT;
}
$tmpEducation['html_eduyear'] .= <<
EOT;
//todo
$this->defaultValueHtml .= str_replace(
array('','',''),
array($tmpEducation['html_edulevel'],$tmpEducation['html_eduname'],$tmpEducation['html_eduyear']),
//$this->htmlTemplate['templateEducation']
$m[1]
);
}
}
}
function buildCareer(){
$id = 'ids_' . md5(microtime());
$this->fieldInfo['html_careerscripts'] = <<
function addCareer(s,t){
var l = getObj(t).lastChild;
var n = getObj(s).cloneNode(true);
n.style.display = '';
n.id = '';
n.innerHTML = n.innerHTML.replace(/((w+_)?ids_)[a-z0-9]+/ig, '$1'+Math.random().toString().substring(2));
getObj(t).insertBefore(n,l);
}
EOT;
$this->fieldInfo['html_careername'] = <<
EOT;
$this->fieldInfo['html_careerdate'] = <<
EOT;
$date = getdate($GLOBALS['timestamp']);
$startYear = $date['year'];
$endYear = $startYear - 60;
for($i = $startYear; $i>= $endYear ; $i--){
$this->fieldInfo['html_careerdate'] .= <<$i
EOT;
}
$this->fieldInfo['html_careerdate'] .= <<
EOT;
/*有默認值格式化默認值*/
if (S::isArray($this->defaultValue) && preg_match('/<\!--DEFAULT_VALUE_TEMPLATE-->(.*)<\!--END_DEFAULT_VALUE_TEMPLATE-->/is',$this->htmlTemplate['templateCareer'],$m)) {
if(!$m[1]) return ;
foreach ($this->defaultValue as $k=>$v) {
if (!S::isArray($v)) continue;
$tmpCareer = array();
//公司名
$tmpCareer['html_careername'] = <<
EOT;
//入職日期
$careerdate = getdate($v['starttime']);
$tmpCareer['html_careerdate'] = <<
EOT;
$date = getdate($GLOBALS['timestamp']);
$startYear = $date['year'];
$endYear = $startYear - 60;
for($i = $startYear; $i>= $endYear ; $i--){
$selectedHtml = $careerdate['year'] == $i ?' selected=1':'';
$tmpCareer['html_careerdate'] .= <<$i
EOT;
}
$tmpCareer['html_careerdate'] .= <<
EOT;
//default value html
$this->defaultValueHtml .= str_replace(
array('',''),
array($tmpCareer['html_careername'],$tmpCareer['html_careerdate']),
$m[1]
//$this->htmlTemplate['templateCareer']
);
}
}
}
function initHtmlTemplate(){
$this->htmlTemplate['templateInput'] = <<
>
EOT;
$this->htmlTemplate['templateTextarea'] = <<
>
EOT;
$this->htmlTemplate['templateSelect'] = <<
>
EOT;
$this->htmlTemplate['templateRadio'] = <<
>
EOT;
$this->htmlTemplate['templateCheckbox'] = <<
>
EOT;
$this->htmlTemplate['templateYear'] = <<
>
EOT;
$this->htmlTemplate['templateArea'] = <<
-
EOT;
$this->htmlTemplate['templateEducation'] = <<
增加一個新經歷
EOT;
$this->htmlTemplate['templateCareer'] = <<
增加一個新經歷
EOT;
}
}
?>