Exemplo n.º 1
0
 function getFieldValueHTML($type, $fieldvalue, $rules)
 {
     if ($type == 'radio') {
         $newradio = array();
         foreach ($rules as $rk => $rv) {
             $rv_value = substr($rv, 0, strpos($rv, '='));
             $rv_name = substr($rv, strpos($rv, '=') + 1);
             $newradio[$rv_value] = $rv_name;
         }
         $topicvalue .= "{$newradio[$fieldvalue]}";
     } elseif ($type == 'checkbox') {
         $newcheckbox = array();
         foreach ($rules as $ck => $cv) {
             $cv_value = substr($cv, 0, strpos($cv, '='));
             $cv_name = substr($cv, strpos($cv, '=') + 1);
             $newcheckbox[$cv_value] = $cv_name;
         }
         $topicvalues = '';
         foreach (explode(",", $fieldvalue) as $value) {
             if (S::isNatualValue($value)) {
                 $topicvalues .= $topicvalues ? "," . $newcheckbox[$value] : $newcheckbox[$value];
             }
         }
         $topicvalue .= $topicvalues;
     } elseif ($type == 'select') {
         $newselect = array();
         foreach ($rules as $sk => $sv) {
             $sv_value = substr($sv, 0, strpos($sv, '='));
             $sv_name = substr($sv, strpos($sv, '=') + 1);
             $newselect[$sv_value] = $sv_name;
         }
         $topicvalue .= "{$newselect[$fieldvalue]}";
     } elseif ($type == 'url') {
         $topicvalue .= "<a href=\"{$fieldvalue}\" target=\"_blank\">{$fieldvalue}</a>";
     } elseif ($type == 'calendar') {
         $topicvalue .= get_date($fieldvalue, 'Y-n-j');
     } else {
         $topicvalue .= "{$fieldvalue}";
     }
     return $topicvalue;
 }
Exemplo n.º 2
0
 function initData()
 {
     /*初始化上传信息*/
     global $timestamp, $db_topicname, $tid, $limitnums;
     $postcate = S::getGP('postcate', 'P');
     $query = $this->db->query("SELECT fieldname,name,type,rules,ifmust,ifable FROM pw_pcfield WHERE pcid=" . S::sqlEscape($this->pcid));
     while ($rt = $this->db->fetch_array($query)) {
         if ($rt['type'] != 'upload' && $rt['ifable'] && $rt['ifmust'] && !S::isNatualValue($postcate[$rt['fieldname']])) {
             $db_topicname = $rt['name'];
             Showmsg('topic_field_must');
         }
         if (in_array($rt['fieldname'], array('tel', 'phone', 'limitnum'))) {
             $postcate[$rt['fieldname']] && !is_numeric($postcate[$rt['fieldname']]) && Showmsg('telphone_error');
         } elseif (in_array($rt['fieldname'], array('price', 'deposit', 'mprice'))) {
             $postcate[$rt['fieldname']] && !is_numeric($postcate[$rt['fieldname']]) && Showmsg('numeric_error');
             $postcate[$rt['fieldname']] = number_format(floatval($postcate[$rt['fieldname']]), 2, '.', '');
         }
         if ($postcate[$rt['fieldname']]) {
             if ($rt['type'] == 'number') {
                 !is_numeric($postcate[$rt['fieldname']]) && Showmsg('number_error');
                 $limitnum = unserialize($rt['rules']);
                 if ($limitnum['minnum'] && $limitnum['maxnum'] && ($postcate[$rt['fieldname']] < $limitnum['minnum'] || $postcate[$rt['fieldname']] > $limitnum['maxnum'])) {
                     $db_topicname = $rt['name'];
                     Showmsg('topic_number_limit');
                 }
             } elseif ($rt['type'] == 'range') {
                 !is_numeric($postcate[$rt['fieldname']]) && Showmsg('number_error');
             } elseif ($rt['type'] == 'email') {
                 if (!preg_match("/^[-a-zA-Z0-9_\\.]+@([0-9A-Za-z][0-9A-Za-z-]+\\.)+[A-Za-z]{2,5}\$/", $postcate[$rt['fieldname']])) {
                     Showmsg('illegal_email');
                 }
             } elseif ($rt['type'] == 'checkbox') {
                 $checkboxs = ',';
                 foreach ($postcate[$rt['fieldname']] as $value) {
                     $checkboxs .= $value . ',';
                 }
                 $postcate[$rt['fieldname']] = $checkboxs;
             } elseif ($rt['type'] == 'calendar') {
                 //日期值检查
                 $checkTime = strtotime($postcate[$rt['fieldname']]);
                 if (!$checkTime || -1 == $checkTime) {
                     $GLOBALS['db_actname'] = $rt['name'];
                     Showmsg('calendar_wrong_format');
                 }
                 //end
                 $postcate[$rt['fieldname']] = PwStrtoTime($postcate[$rt['fieldname']]);
             }
         }
     }
     $limitnums = $this->db->get_value("SELECT SUM(nums) as num FROM pw_pcmember WHERE tid=" . S::sqlEscape($tid));
     if ($postcate['limitnum'] && $limitnums > $postcate['limitnum']) {
         Showmsg('pclimitnum_error');
     }
     $postcate['begintime'] > $postcate['endtime'] && Showmsg('begin_endtime');
     $postcate['endtime'] < $timestamp && Showmsg('截止时间必须大于当前时间');
     $this->data['postcate'] = serialize($postcate);
 }