content_form.class.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. class content_form {
  3. var $modelid;
  4. var $fields;
  5. var $id;
  6. var $formValidator;
  7. function __construct($modelid,$catid = 0,$categorys = array()) {
  8. $this->modelid = $modelid;
  9. $this->catid = $catid;
  10. $this->categorys = $categorys;
  11. $this->fields = getcache('model_field_'.$modelid,'model');
  12. $this->siteid = get_siteid();
  13. }
  14. function get($data = array()) {
  15. $_groupid = param::get_cookie('_groupid');
  16. $this->data = $data;
  17. if(isset($data['id'])) $this->id = $data['id'];
  18. $info = array();
  19. $this->content_url = $data['url'];
  20. foreach($this->fields as $field=>$v) {
  21. if(defined('IN_ADMIN')) {
  22. if($v['iscore'] || check_in($_SESSION['roleid'], $v['unsetroleids'])) continue;
  23. } else {
  24. if($v['iscore'] || !$v['isadd'] || check_in($_groupid, $v['unsetgroupids'])) continue;
  25. }
  26. $func = $v['formtype'];
  27. $value = isset($data[$field]) ? new_html_special_chars($data[$field]) : '';
  28. if($func=='pages' && isset($data['maxcharperpage'])) {
  29. $value = $data['paginationtype'].'|'.$data['maxcharperpage'];
  30. }
  31. if(!method_exists($this, $func)) continue;
  32. $form = $this->$func($field, $value, $v);
  33. if($form !== false) {
  34. if(defined('IN_ADMIN')) {
  35. if($v['isbase']) {
  36. $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
  37. $info['base'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
  38. } else {
  39. $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
  40. $info['senior'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
  41. }
  42. } else {
  43. $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
  44. $info[$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
  45. }
  46. }
  47. }
  48. return $info;
  49. }
  50. }?>