当前位置:首页 > CMS教程 > phpcms > 正文

自己动手构建一个企业服务模块

模块功能分析:企业服务,企业填写招聘申请表,管理审核之后,展示作为招聘通知的功能。

1.文件分布:

?

modules文件夹和model文件夹,这是我们的文件范围。在modules下建立qiye这个文件夹;地址:F:\www\phpcms\modules\qiye

?

2.实例图:

\

3.前台控制器?index.php(class名必须与文件名一致),路径:F:\www\phpcms\modules\qiye\index.php

?

  1. defined('IN_PHPCMS')?or?exit('No?permission?resources.');??
  2. class?index?{??
  3. private?$db,$ip;??
  4. function?__construct()?{??
  5. pc_base::load_app_func('global');??
  6. $this->db?=?pc_base::load_model('qiye_model');??
  7. $this->ip?=?ip();??
  8. $siteid?=?isset($_GET['siteid'])???intval($_GET['siteid'])?:?get_siteid();??
  9. ??define("SITEID",$siteid);??
  10. ??}??
  11. public?function?init()?{??
  12. $siteid?=?SITEID;??
  13. $page?=?intval($_GET['page'])<=0???1?:??intval($_GET['page']);??
  14. ??????include?template('qiye',?'index');??
  15. }??
  16. public?function?lists()?{??
  17. ??$siteid?=?SITEID;??
  18. ??$page?=?intval($_GET['page']);??
  19. $page?=?max($page,1);??
  20. $r?=?$this->db->select(array('siteid'=>$siteid));??
  21. if($r)?extract($r);??
  22. ??????include?template('qiye',?'list');??
  23. }??
  24. public?function?show(){??
  25. $siteid?=?SITEID;??
  26. $comid?=?intval($_GET['comid']);??
  27. ??
  28. if(!$comid)?showmessage(L('information_does_not_exist'),'blank');??
  29. $r?=?$this->db->get_one(array('comid'=>$comid));??
  30. if(!$r)?showmessage(L('info_does_not_exists'),'blank');??
  31. extract($r);??
  32. include?template('qiye',?'show');??
  33. ??}??
  34. public?function?reg(){??
  35. if(isset($_POST['comname'])){??
  36. //如果用户提交申请??
  37. ??if($_POST['comname']==''){??
  38. ??showmessage(L('qiye_noname'),"?m=qiye&c=index&a=reg&siteid=$siteid");??
  39. ??}??
  40. ??$db?=?pc_base::load_model('qiye_model');//加载模型??
  41. ??
  42. //接收数据并存储??
  43. $s?=?array();??
  44. $num?=?array();??
  45. $num?=?$_POST['zp_num'];??
  46. $s['siteid']?????????=?SITEID;??
  47. $s['comname']???????=?safe_replace($_POST['comname']);??
  48. $s['dw_name']???????=?safe_replace($_POST['dw_name']);??
  49. $s['dw_department']?=?safe_replace($_POST['dw_department']);??
  50. $s['dw_area']?=?safe_replace($_POST['dw_area']);??
  51. $s['dw_property']?=?safe_replace($_POST['dw_property']);??
  52. $s['dw_economic']?=?safe_replace($_POST['dw_economic']);??
  53. $s['dw_contact']?=?safe_replace($_POST['dw_contact']);??
  54. $s['dw_zipcode']?=?safe_replace($_POST['dw_zipcode']);??
  55. $s['dw_address']?=?safe_replace($_POST['dw_address']);??
  56. $s['dw_telphone']?=?safe_replace($_POST['dw_telphone']);??
  57. $s['dw_fax']?????=?safe_replace($_POST['dw_fax']);??
  58. $s['dw_email']?=?safe_replace($_POST['dw_email']);??
  59. $s['zp_hr']???=?safe_replace($_POST['zp_hr']);??
  60. $s['zp_tel']???=?safe_replace($_POST['zp_tel']);??
  61. $s['zp_email']?=?safe_replace($_POST['zp_email']);??
  62. $s['zp_property']?=?safe_replace($_POST['zp_property']);??
  63. $s['zp_industry']?=?safe_replace($_POST['zp_industry']);??
  64. $s['zp_post']?????=?safe_replace($_POST['zp_post']);??
  65. $s['zp_area']?????=?safe_replace($_POST['zp_area']);??
  66. $s['zp_major']???=?safe_replace($_POST['zp_major']);??
  67. $s['zp_salary']???=?safe_replace($_POST['zp_salary']);??
  68. $s['zp_num']???=?array2string($num);??
  69. $s['attr_commercial']?=?safe_replace($_POST['attr_commercial']);??
  70. $s['attr_information']?=?safe_replace($_POST['attr_information']);??
  71. $s['url']?=?'index.php?m=qiye&c=index&a=show&id=`id`';??
  72. $s['ip']?=?$this->ip;??
  73. $s['inputtime']?=?SYS_TIME;??
  74. $s['updatetime']?=?SYS_TIME;??
  75. ??
  76. ??$comid?=?$db->insert($s,true);??
  77. if($comid){??
  78. showmessage(L('qiye_success'),?"?m=qiye&c=index&a=init&siteid=$siteid");??
  79. }??
  80. ??}?else?{??
  81. //默认显示申请页面??
  82. ??pc_base::load_sys_class('form',?'',?0);??
  83. ??$SEO?=?seo(SITEID,?'',?L('qiye_apply'),?'',?'');??
  84. ????include?template('qiye',?'register');??
  85. ??}??
  86. }??
  87. ??
  88. }??
  89. ?>??

4.后台控制器?qiye.php(class名必须与文件名一致),路径:F:\www\phpcms\modules\qiye\qiye.php

?

?

  1. defined('IN_PHPCMS')?or?exit('No?permission?resources.');??
  2. pc_base::load_app_class('admin','admin',0);??
  3. class?qiye?extends?admin?{??
  4. private?$db;??
  5. function?__construct()?{??
  6. parent::__construct();??
  7. $this->db?=?pc_base::load_model('qiye_model');??
  8. $siteid?=?isset($_GET['siteid'])???intval($_GET['siteid'])?:?get_siteid();??
  9. ??define("SITEID",$siteid);??
  10. }??
  11. ??
  12. //默认动作??
  13. public?function?init()?{??
  14. $where?=?array('siteid'=>$this->get_siteid(),'status'=>0);??
  15. ??$page?=?isset($_GET['page'])?&&?intval($_GET['page'])???intval($_GET['page'])?:?1;??
  16. $infos?=?$this->db->listinfo($where,$order?=?'listorder?DESC',$page,?$pages?=?'9');??
  17. $pages?=?$this->db->pages;??
  18. extract($infos);??
  19. include?$this->admin_tpl('list');??
  20. }??
  21. public?function?show()?{??
  22. $comid?=?intval($_GET['comid']);??
  23. if(!$comid)?showmessage(L('information_does_not_exist'),'blank');??
  24. $infos?=?$this->db->get_one(array('comid'=>$comid));??
  25. if(!$infos)?showmessage(L('info_does_not_exists'),'blank');??
  26. extract($infos);??
  27. include?$this->admin_tpl('show');??
  28. }??
  29. public?function?list_pass()?{??
  30. $where?=?array('siteid'=>$this->get_siteid(),'status'=>1);??
  31. ??$page?=?isset($_GET['page'])?&&?intval($_GET['page'])???intval($_GET['page'])?:?1;??
  32. $infos?=?$this->db->listinfo($where,$order?=?'listorder?DESC',$page,?$pages?=?'9');??
  33. $pages?=?$this->db->pages;??
  34. extract($infos);??
  35. include?$this->admin_tpl('list_pass');??
  36. }??
  37. public?function?pass()?{??
  38. if((!isset($_GET['comid'])?||?empty($_GET['comid']))?&&?(!isset($_POST['comid'])?||?empty($_POST['comid'])))?{??
  39. showmessage(L('illegal_parameters'),?HTTP_REFERER);??
  40. }?else?{???
  41. $comid?=?intval($_GET['comid']);??
  42. if($comid?return?false;??
  43. $result?=?$this->db->update(array('status'=>'1'),array('comid'=>$comid));??
  44. $infos?=?$this->db->get_one(array('comid'=>$comid));??
  45. if($result){??
  46. if(is_email($infos['zp_email'])){??
  47. pc_base::load_sys_func('mail');??
  48. $siteinfo?=?siteinfo(SITEID);??
  49. $sitename?=?$siteinfo['site_title'];??
  50. $toemail?=?$infos['zp_email'];?//发送通知邮件??
  51. $subject?=?'信息审核通知';??
  52. $message?.=?'尊敬的'.$infos['zp_hr'].':?????您好!';??
  53. $message?.=?'很高兴的通知您,您在'.date('Y年m月d日',$infos['inputtime']).'在我们网站['.$sitename.']发布的信息已经通过审核。';??
  54. $message?.=?'祝好!-----------------------------------------';??
  55. $message?.=?'这是一封由系统发送的邮件,请勿回复此邮件!';??
  56. sendmail($toemail,$subject,$message);??
  57. }??
  58. exit('1');??
  59. }?else?{??
  60. exit('0');??
  61. }??
  62. }??
  63. }??
  64. ??public?function?listorder()?{??
  65. if(isset($_POST['dosubmit']))?{??
  66. foreach($_POST['listorders']?as?$comid?=>?$listorder)?{??
  67. $this->db->update(array('listorder'=>$listorder),array('comid'=>$comid));??
  68. }??
  69. showmessage(L('operation_success'),HTTP_REFERER);??
  70. }??
  71. }??
  72. ??
  73. ??
  74. public?function?delete()?{??
  75. ??if((!isset($_GET['comid'])?||?empty($_GET['comid']))?&&?(!isset($_POST['comid'])?||?empty($_POST['comid'])))?{??
  76. showmessage(L('illegal_parameters'),?HTTP_REFERER);??
  77. }?else?{??
  78. if(is_array($_POST['comid'])){?//1.批量删除??
  79. foreach($_POST['comid']?as?$comid)?{??
  80. $this->db->delete(array('comid'=>$comid));??
  81. //删除附件??
  82. if(pc_base::load_config('system','attachment_stat'))?{??
  83. $this->attachment_db?=?pc_base::load_model('attachment_model');??
  84. $this->attachment_db->api_delete($comid);??
  85. }??
  86. }??
  87. showmessage(L('operation_success'),'?m=qiye&c=qiye');??
  88. }else{?//2.单条删除??
  89. $comid?=?intval($_GET['comid']);??
  90. if($comid?return?false;??
  91. $result?=?$this->db->delete(array('comid'=>$comid));??
  92. //删除附件??
  93. if(pc_base::load_config('system','attachment_stat'))?{??
  94. $this->attachment_db?=?pc_base::load_model('attachment_model');??
  95. $this->attachment_db->api_delete($comid);??
  96. }??
  97. if($result){??
  98. exit('1');??
  99. showmessage(L('operation_success'),'?m=qiye&c=qiye');??
  100. }else?{??
  101. exit('0');??
  102. showmessage(L("operation_failure"),'?m=qiye&c=qiye');??
  103. }??
  104. }??
  105. showmessage(L('operation_success'),?HTTP_REFERER);??
  106. }??
  107. }??
  108. ??
  109. public?function?setting()?{??
  110. ??include?$this->admin_tpl('setting');??
  111. }??
  112. ??
  113. ??
  114. }??
  115. ?>??

5.PC标签方法?:qiye_tag.class.php(为模板数据调用而设置),路径:F:\www\phpcms\modules\qiye\classes\qiye_tag.class.php

?

?

  1. defined('IN_PHPCMS')?or?exit('No?permission?resources.');??
  2. class?qiye_tag?{??
  3. ??private?$db;??
  4. public?function?__construct()?{??
  5. $this->db?=?pc_base::load_model('qiye_model');??
  6. ??}??
  7. public?function?lists($data)?{??
  8. $siteid?=?$data['siteid']???intval($data['siteid'])?:?get_siteid();??
  9. ??
  10. $sql?=?array('siteid'=>$siteid);??
  11. ??$data?=?$this->db->select($sql,?'*',?$data['limit'],?$data['order']);??
  12. return?$data;??
  13. }??
  14. public?function?pc_tag()?{??
  15. $sites?=?pc_base::load_app_class('sites','admin');??
  16. $sitelist?=?$sites->pc_tag_list();??
  17. return?array(??
  18. 'action'=>array('lists'=>L('lists',?'',?'qiye')),??
  19. 'lists'=>array(??
  20. 'catid'=>array('name'=>L('catid',?'',?'qiye'),'htmltype'=>'input_select_category','data'=>array('type'=>0),'validator'=>array('min'=>1)),??
  21. 'order'=>array(??
  22. 'name'=>L('sort',?'',?'qiye'),??
  23. 'htmltype'=>'select',??
  24. 'data'=>array(??
  25. 'id?DESC'=>L('id_desc',?'',?'qiye'),??
  26. 'inputtime?DESC'=>L('inputtime_desc',?'',?'qiye'),??
  27. 'updatetime?DESC'=>L('updatetime_desc',?'',?'qiye'),??
  28. 'listorder?ASC'=>L('listorder_asc',?'',?'qiye')??
  29. )??
  30. )??
  31. ),??
  32. );??
  33. }??
  34. }??

?

这里设置了一个方法,lists内容列表。在模版的时候调用如下:
{pc:qiye action="lists" catid="$catid"order="listorder desc" num="8"}

?

?

6.函数方法库

functions(因为我这里都用到的是系统的方法,所以里面是空的)
?
7.模块安装文件夹地址?F:\www\phpcms\modules\qiye\install
\

?

?

7.1?语言文件?qiye.lang.php(我这里只做了中文的语言),路径:F:\www\phpcms\modules\qiye\install\languages\zh-cn\qiye.lang.php
  1. $LANG['qiye_apply']?=?'企业服务申请';??
  2. $LANG['qiye_noname']?=?'企业名称不能为空!';??
  3. $LANG['qiye_success']?=?'申请填写成功!';??
  4. ??
  5. $LANG['comname']?=?'单位名称';??
  6. $LANG['attr_commercial']?=?'营业执照';??
  7. $LANG['dw_name']?=?'签约名称';??
  8. $LANG['dw_department']?=?'隶属部门';??
  9. $LANG['dw_area']?=?'单位地区';??
  10. $LANG['dw_property']?=?'单位性质';??
  11. $LANG['dw_contact']?=?'信息负责人';??
  12. $LANG['dw_telphone']?=?'负责人手机号';??
  13. $LANG['zp_email']?=?'负责人邮箱';??
  14. $LANG['attr_information']?=?'招聘信息';??
  15. $LANG['qiye_download']?=?'点击下载';??
  16. $LANG['qiye_control']?=?'操作';??
  17. $LANG['qiye_look']?=?'查看';??
  18. $LANG['click_open']?=?'点击下载';??
  19. $LANG['remove_all_selected']?=?'删除选择';??
  20. $LANG['confirm_del']?=?'确定删除吗?';??
  21. $LANG['del_confirm']?=?'确定删除吗?';??
  22. $LANG['delete']?=?'删除';??
  23. $LANG['pass']?=?'通过';??
  24. $LANG['pass_true']?=?'确定通过吗?';??
  25. ?>??

7.2?前台模版文件夹,路径: F:\www\phpcms\modules\qiye\install\templates
\

?

name.inc.php 模版安装文件,安装模块时把模版文件复制到默认的default目录下的控制文件。

?

  1. defined('IN_PHPCMS')?or?exit('Access?Denied');??
  2. defined('INSTALL')?or?exit('Access?Denied');??
  3. return?array?(??
  4. 'index.html'?=>?'企业信息首页',??
  5. 'list.html'?=>?'企业信息列表页',??
  6. 'show.html'?=>?'企业信息内容页',??
  7. 'register.html'?=>?'企业信息申请页',??
  8. ????);??
  9. ?>??

?

7.3?模块配置文件?config.inc.php地址?F:\www\phpcms\modules\qiye\install\config.inc.php
?
  1. defined('IN_PHPCMS')?or?exit('Access?Denied');??
  2. defined('INSTALL')?or?exit('Access?Denied');??
  3. $module?=?'qiye';??
  4. $modulename?=?'企业服务';??
  5. $introduce?=?'企业服务模块';??
  6. $author?=?'novalue';??
  7. $authorsite?=?'http://www.liaochuanyou.name/';??
  8. $authoremail?=?'novalue@qq.com';??
  9. ?>??

7.4模块菜单扩展文件?extention.inc.php(添加后台菜单栏功能),路径:F:\www\phpcms\modules\qiye\install\extention.inc.php

?

?

  1. defined('IN_PHPCMS')?or?exit('Access?Denied');??
  2. defined('INSTALL')?or?exit('Access?Denied');??
  3. ??
  4. $parentid?=?$menu_db->insert(array('name'=>'qiye',?'parentid'=>29,?'m'=>'qiye',?'c'=>'qiye',?'a'=>'init',?'data'=>'',?'listorder'=>0,?'display'=>'1'),?true);??
  5. $menu_db->insert(array('name'=>'qiye_list',?'parentid'=>$parentid,?'m'=>'qiye',?'c'=>'qiye',?'a'=>'list_pass',?'data'=>'',?'listorder'=>1,?'display'=>'1'));??
  6. $menu_db->insert(array('name'=>'qiye_setting',?'parentid'=>$parentid,?'m'=>'qiye',?'c'=>'qiye',?'a'=>'setting',?'data'=>'',?'listorder'=>2,?'display'=>'1'));??
  7. $language?=?array('qiye'=>'企业服务','qiye_list'=>'审核通过','qiye_setting'=>'模块配置');??
  8. ?>??

7.5?安装文件夹下的 model.php (安装模块时返回所使用的模型名),路径:F:\www\phpcms\modules\qiye\install\model.php

?

?

  1. defined('IN_PHPCMS')?or?exit('Access?Denied');??
  2. defined('INSTALL')?or?exit('Access?Denied');??
  3. return?array('qiye');??
  4. ?>??

?

7.6?安装文件夹下的?module.sql?(里面只有一句sql语句),路径:F:\www\phpcms\modules\qiye\install\module.sql
  1. INSERT?INTO?`phpcms_module`?VALUES?('qiye',?'企业服务',?'',?'0',?'1.0',?'企业服务',?'',?'0',?'0',?'2012-06-18',?'2012-06-18');??

7.7 企业服务模块安装数据库文件?qiye.sql?,路径:F:\www\phpcms\modules\qiye\install\qiye.sql
  1. DROP?TABLE?IF?EXISTS?`phpcms_qiye`;??
  2. CREATE?TABLE?`phpcms_qiye`?(??
  3. `comid`??int(11)?NOT?NULL?AUTO_INCREMENT?,??
  4. `siteid`??int(11)?NULL?DEFAULT?NULL?,??
  5. `comname`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'单位名称'?,??
  6. `dw_name`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'签约名称'?,??
  7. `dw_department`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'隶属部门'?,??
  8. `dw_area`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'单位地区'?,??
  9. `dw_property`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'单位性质'?,??
  10. `dw_economic`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'经济类型'?,??
  11. `dw_contact`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'单位联系人'?,??
  12. `dw_zipcode`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'单位邮编'?,??
  13. `dw_address`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'单位地址'?,??
  14. `dw_telphone`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'单位电话'?,??
  15. `dw_fax`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'单位传真'?,??
  16. `dw_email`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'单位邮箱'?,??
  17. `zp_hr`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'负责人'?,??
  18. `zp_tel`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?,??
  19. `zp_email`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?,??
  20. `zp_property`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?,??
  21. `zp_industry`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?,??
  22. `zp_post`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?,??
  23. `zp_area`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?,??
  24. `zp_major`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?,??
  25. `zp_salary`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'招聘薪水'?,??
  26. `zp_num`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'招聘人数'?,??
  27. `attr_commercial`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'营业执照'?,??
  28. `attr_information`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?COMMENT?'招聘信息'?,??
  29. `url`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?,??
  30. `ip`??varchar(255)?CHARACTER?SET?utf8?COLLATE?utf8_general_ci?NULL?DEFAULT?NULL?,??
  31. `status`??int(11)?NULL?DEFAULT?0?,??
  32. `listorder`??int(11)?NULL?DEFAULT?0?,??
  33. `inputtime`??int(11)?NULL?DEFAULT?NULL?,??
  34. `updatetime`??int(11)?NULL?DEFAULT?NULL?,??
  35. PRIMARY?KEY?(`comid`)??
  36. )??
  37. ENGINE=InnoDB?DEFAULT?CHARACTER?SET=utf8?COLLATE=utf8_general_ci?AUTO_INCREMENT=32?ROW_FORMAT=COMPACT;??

8.后台管理模版文件,路径:F:\www\phpcms\modules\qiye\templates\
\

9.模块卸载文件,路径:F:\www\phpcms\modules\qiye\uninstall
三个文件extention.inc.php、qiye.sql、model.php里面的语句比较简单,大家可以看其他模块的写法,修改里面对应的模块名即可。

10.模型的model(这里和上面要注意了,不在同一个目录下面了,在系统的model目录了($ _ $)),路径:F:\www\phpcms\model\qiye_model.class.php
  1. defined('IN_PHPCMS')?or?exit('No?permission?resources.');??
  2. pc_base::load_sys_class('model',?'',?0);??
  3. class?qiye_model?extends?model?{??
  4. function?__construct()?{??
  5. $this->db_config?=?pc_base::load_config('database');??
  6. $this->db_setting?=?'default';??
  7. $this->table_name?=?'qiye';??
  8. parent::__construct();??
  9. }??
  10. }??
  11. ?>??
  12. ?

上一篇:phpcms数据库操作 下一篇:最后一页