模块开发: Difference between revisions

Tag: 2017 source edit
 
(24 intermediate revisions by the same user not shown)
Line 11: Line 11:


[[Category:Core]]
[[Category:Core]]
[[Category:开发]]
{{Template用户手册}}
{{Template用户手册}}
{{Template开发文档}}
{{Template开发文档}}
Line 171: Line 172:


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
// Array to add new pages in new tabs or remove existing one
// 用于在新tabs中添加新页面或删除现有页面的数组
$this->tabs = array('objecttype:+tabname1:Title1:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mypagetab1.php?id=__ID__'    // To add a new tab identified by code tabname1
$this->tabs = array('objecttype:+tabname1:Title1:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mypagetab1.php?id=__ID__'    // 增加一个由code tabname1标识的新tab
                             'objecttype:+tabname2:Title2:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mypagetab2.php?id=__ID__',  // To add a new tab identified by code tabname2
                             'objecttype:+tabname2:Title2:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mypagetab2.php?id=__ID__',  // 增加一个由code tabname2标识的新tab
                             'objecttype:-tabname');                                                    // To remove an existing tab identified by code tabname
                             'objecttype:-tabname');                                                    // 删除一个由code tabname标识的现有选项卡
</syntaxhighlight>
</syntaxhighlight>


Line 239: Line 240:


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$head        // Array of tabs
$head        // tabs的数组
$head[$h]    // Element to describe one tab.
$head[$h]    // Element to describe one tab.
$head[$h][0] // Url of page to show when you click on tab
$head[$h][0] // Url of page to show when you click on tab
Line 260: Line 261:
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
dol_fiche_head($links, $active='0', $title='', $notab=0, $picto='')
dol_fiche_head($links, $active='0', $title='', $notab=0, $picto='')
//$links  // Tableau des onglets, appelé $head plus haut.
//$links  // tabs的数组,上面称为$head
//$active // Onglet actif (mettre le nom de l'onglet défini dans votre fichier de module, ou un nom contenu dans $head[$h][2]). Cet onglet sera mis en surbrillance
//$active // 活动选项卡(输入模块文件中定义的选项卡名称,或$head[$h][2]中包含的名称)。此选项卡将突出显示
//$title  // Title to show (shown into a special tab that you can't click)
//$title  // 要显示的标题(显示在无法单击的特殊选项卡中)
//$notab
//$notab
//$picto  // Name of image to show into title. Possible values are:
//$picto  // 要显示到标题中的图片的名称。可能的值为:
//            product
//            product
//            service
//            service
Line 274: Line 275:
注:相关的更多细节,请参阅 [http://www.dolibarr.fr/doxygen/ Doxygen文档] 或直接参考 Dolibarr 代码。
注:相关的更多细节,请参阅 [http://www.dolibarr.fr/doxygen/ Doxygen文档] 或直接参考 Dolibarr 代码。


==创建或修改 PHP 屏显 (可选)==
==创建PHP屏幕页面(可选)==
'''何时''': 如果模块的目的是为了修改屏显。
'''何时''':如果新模块的目的是添加一个需要新屏幕页面的功能。


===创建新 PHP 屏显===
===创建原始PHP屏幕页面===
然后,您必须创建PHP页面,使用目录'''modulebuilder/myobject_page.php'''中提供的框架模板来显示/编辑表中的数据。 (从命令行开发脚本, 见 [[Script development]]).
随后,您可以使用 '''modulebuilder''' 目录中提供的示例模板('''myobject_page.php''')创建基于表数据的PHP页面(有关命令行脚本的开发,请参阅 [[脚本开发]] )。同样,如果您使用的是 ModuleBuilder,则在初始化对象时会自动创建页面实例(清单、创建页面、Notes选项卡等)。


要创建一个新的用户屏幕,创建一个模块名的子目录(若无)  (例如 '''htdocs/mymodule''') 来存储创建的屏幕。
要创建新的用户屏幕页面,请创建特定于模块的 '''htdocs''' 子目录(如果尚未创建)(如 '''htdocs/mymodule''' ),以便在其中放置要创建的页面。


复制 '''myobject_page.php''' 做为屏幕页。
从复制文件 '''myobject_page.php''' 作为开始。编辑该文件,以便能正确找到并加载 main.inc.php 文件:


编辑该文件,以包括正确的 '''main.inc.php'''文件。
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
// Load Dolibarr environment
// 加载Dolibarr环境
$res=0;
$res=0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
// 尝试include在CONTEXT_DOCUMENT_ROOT(不总是定义的)中定义的已知web根目录中的main.inc.php
if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include($_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php");
if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include($_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php");
// Try main.inc.php into web root detected using web root caluclated from SCRIPT_FILENAME
// 尝试include由SCRIPT_FILENAME计算的web根检测到web根的main.inc.php
$tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1;
$tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1;
while($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; }
while($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; }
if (! $res && $i > 0 && file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include(substr($tmp, 0, ($i+1))."/main.inc.php");
if (! $res && $i > 0 && file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include(substr($tmp, 0, ($i+1))."/main.inc.php");
if (! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php");
if (! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php");
// Try main.inc.php using relative path
// 尝试include使用相对路径的main.inc.php
if (! $res && file_exists("../main.inc.php")) $res=@include("../main.inc.php");
if (! $res && file_exists("../main.inc.php")) $res=@include("../main.inc.php");
if (! $res && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php");
if (! $res && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php");
Line 301: Line 301:
if (! $res) die("Include of main fails");
if (! $res) die("Include of main fails");
</syntaxhighlight>
</syntaxhighlight>
注: 你可能增加更多的 "../" 根据你的模块目录的深度。
在3.2之后,为所有版本的Dolibarr开发的模块应该能够在不同的文件夹中移动,而不是“htdocs”,比如“htdocs/custom”,而不必修改模块的源代码,这就是为什么我们要做几个包含,所以这个规则必须被所有模块应用。


在main.inc.php文件中,加载了技术环境变量和权限。以下变量是位于该文件中的对象:
如您所见,其多次尝试加载 main.inc.php(或 master.inc.php)文件。目标是在尽可能多的场景下取得成功。最少为2行:一行用于尝试将 master/main.inc.php 文件加载到 dolibarr 的根目录中,另一行用于尝试加载该文件,以支持模块部署在“custom”目录中的场景。但你可能不得不处理更多的场景。上面提供的示例应该能够在几乎所有场景/配置下加载 main/master.inc.php 文件。


*$user    包含用户+ 权限。
在3.2之后,为所有版本的Dolibarr开发的扩展模块可以放置在不同的文件夹中,而不仅仅是“htdocs”,如“htdocs/custom”,为了不必修改模块的源代码,我们要做几个包含,所以这个规则必须被所有模块使用。
*$conf    包含 Dolibarr 设置
*$db      它包含一个打开的数据库连接处理程序。
*$langs  包含用户语言


然后输入代码显示页面。
请注意,您可以根据文件相对于模块目录树的深度添加更多的“../”。


*包含模块专属的类或库,使用Dolibarr函数dol_include_once()(而不是直接使用 include_once):
main.inc.php文件加载了技术环境变量和权限。然后设置以下对象变量:
 
*$user    包含用户属性 + 权限的对象
*$conf    包含 Dolibarr 设置的对象
*$db      包含数据库连接句柄的对象
*$langs  包含用户语言的对象
 
然后输入代码以显示页面。
 
*在不知道从何处调用文件的情况下,使用Dolibarr函数dol_include_once()(而不是直接使用include_once)包含专用于模块的类或库
 
''例如:''


''例如 :''
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
dol_include_once('/mymodule/class/myclass.class.php', 'MyClass');
dol_include_once('/mymodule/class/myclass.class.php', 'MyClass');
</syntaxhighlight>
</syntaxhighlight>


*若要包含Dolibarr提供的类,请使用以下语法:
*另一方面,Dolibarr提供的标准类将使用 require-once 直接调用,语法如下:
 
''例如:''


''例如 :''
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
require_once DOL_DOCUMENT_ROOT.'/core/class/doli.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doli.class.php';
</syntaxhighlight>
</syntaxhighlight>


===为现存表单增加新字段===
原因是,尽管dol_include_once很方便,却因它会扫描每个备用路径目录以找到文件,所以它的性能也很差,因为它会在每次调用时生成访问和磁盘搜索(实际上,PHP集成了已读文件的缓存,但未集成“未找到”文件的缓存)。由于给定的文件只可能存在于一个树中,所以总会有一个无此文件的备用树,这会产生对硬盘的不必要访问,从而影响性能。与Dolibarr的内部文件一样,我们总是知道确切的路径,应该首选带有该直接路径的 require_once)。
您可能需要提供一个模块,该模块将更多字段添加到一些元素的表单(输入和查看)中。


一个较累的解决方案(但不是很糟糕)是替换所有用于创建元素的页面(这意味着禁用“新元素”菜单条目并添加您的,禁用“显示”元素,用一个选项卡替换该元素,该选项卡是您自己的完整页面(从原始复制/粘贴),以完成与原始页面相同的操作,修改以添加字段并将添加的数据存储到自己的表中)。
===在已存在的表单上增加新字段===
您可能希望提供一个模块,将更多字段添加到某些元素的表单(录入和展示)中。


转到菜单 [[#Define your entries in menu (optional)]]和[[#The tab management (optional)]],如果这个解决方案适合你(这个解决方案是更强大的,因为你可以改变你想要的一切进入页面)。
一个繁琐(但不太糟糕)的解决方案可能是替换用于创建元素的所有页面(这意味着禁用“新建元素”菜单项并添加您的菜单项,并禁用显示元素的选项卡,以替换选项卡,该选项卡是您自己的完整页面(从原始页面复制/粘贴),使其与原始页面相同,但被修改为添加字段并将添加的数据存储到您自己的表中)。如果此解决方案适合您,请前往菜单 [[#Define your entries in menu (optional)]] 和 [[#The tab management (optional)]](本解决方案更强大,因为您可以在页面中改变你想要改变的一切)。


我们将在这里描述另一种解决方案,它只在现有字段结束时“添加字段”,使用元素“category”作为示例,但您可以将此教程转换为发票、提案…
我们将在这里描述另一种解决方案,该解决方案仅适用于在现有字段的末尾“添加字段”,下面以元素“category”作为示例,但您可以将本教程转换为发票、报价单...


*首先,添加一个由您的模块所拥有的表,以存储新字段的值。此表有一个名为“rowid”的列(将包含与元素表的字段rowid相同的值+每一个要添加的新字段的列。然后为这个新表创建一个CRUD(创建/读取/更新/删除)方法类。对于这两个任务,请回到前一章[[#创建数据表和表的PHP类文件 (可选)]]。
*首先,添加一个由您的模块拥有的表,以存储新字段的值。此表将有一个名为“rowid”的列(将包含与元素表的字段rowid相同的值+每一个要添加的新字段。然后为这个新表创建一个具有CRUD(Create/Read/Update/Delete)方法的类。对于这两项任务,请返回前一章[[#创建数据表和表的PHP类文件 (可选)]]。
*下一步是在模块中添加一个钩子,以将新字段添加到窗体中。有关使用钩子的通用文档,请参见[[Hooks_system#Implement_the_Hook]]章节。
*其次,在模块中添加一个钩子,以将新字段添加到表单中。有关使用钩子的通用文档,请参阅[[Hooks_system#Implement_the_Hook]]章节。


如果您遵循本教程,以便能够将字段添加到类别窗体中,您必须这样做:
如果遵循本教程,则必须执行以下操作才能将字段添加到 category 表单中:
{{ToComplete}}
{{ToComplete}}


===增/换部分字段(需钩子支持)===
===用钩子添加/替换部分字段===
要知道如何使用Dolibarr现有的钩子来添加/替换Dolibarr 钩子代码,参考 [[钩子系统#实现钩子]] 。
请参阅  [[钩子系统#实现钩子]] 章节,了解如何使用Dolibarr现有的钩子在Dolibarr钩子位置添加/替换代码。


===数据通道===
===访问数据库===
如果需要在自己的表中编辑数据库中的一些数据,请使用的PHP类。
如果您需要对自己添加的表进行基本变更,请使用之前生成的类,其中包含用于此目的的方法。


如果您要访问没有专用PHP类的表(例如,如果您想获得具有特定连接或筛选器的记录列表)。在这种情况下,这是要遵循的代码示例:
但是,如果您希望在没有专用PHP对象的情况下访问表,这仍然是可能的(例如,检索记录列表)。在这种情况下,请考虑以下示例:


进行插入、更新或删除:
对于插入、更新或删除:


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
Line 359: Line 365:
</syntaxhighlight>
</syntaxhighlight>


读:
对于读取:


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
Line 384: Line 390:
</syntaxhighlight>
</syntaxhighlight>


===页面风格===
===定义页面样式===
为了让你自己的页面看起来与Dolibarr主题相匹配,必须使用Dolibarr CSS样式。
为了使页面的外观与 Dolibarr 主题保持一致,必须使用 Dolibarr CSS 样式。


例如,您可以使用:
例如:


*class="'''liste_titre'''" on tags ''tr'' and ''td'' for the head row of a table.
*在表格标题行的''tr''和''td''标签上使用 class="'''liste_titre'''"
*class="'''pair'''" or class="'''impair'''" on tags ''tr'' and ''td'' of other rows of a table.
*在表格数据行的''tr''和''td''标签上使用 class="'''pair'''" 或 class="'''impair'''"
*class="'''flat'''" on all input fields (''input, select, textarea''...).
*在所有输入域(''input, select, textarea''...)上使用 class="'''flat'''"
*class="'''button'''" on HTML fields with type ''input type="submit"''.
*在所有 ''type="submit"'' 的 ''input'' 对象上使用 class="'''button'''"
 
===使用 Dolibarr 日期选择器===
如果您愿意,您可以使用 Dolibarr 屏幕页面中的日期选择器(带日历弹出窗口)。为此,请使用以下行:


===使用Dolibarr日期选择器===
如果您的页面使用Dolibarr日期选择器(日历弹出),请使用以下行:
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
  $form=new Form($db);
  $form=new Form($db);
  $form->select_date('','mykey',0,0,0,"myform");
  $form->select_date('','mykey',0,0,0,"myform");
</syntaxhighlight>
</syntaxhighlight>
字符串mykey将标识表单中的日期选择器。如果在同一页中使用多个日期选择器,则必须使用不同的值。


字符串myform是包含选择器的表单的名称(在HTML页面中的form name="myform")中找到的值。
字符串<syntaxhighlight lang="PHP">
$form=new Form($db);
$form->select_date('','mykey',0,0,0,"myform");
</syntaxhighlight>标识表单中的日期选择器。如果在同一页面中使用多个日期选择器,则必须设置不同的值。
 
字符串myform是FORM区域的名称(在HTML页面的form name=“myform”中)。因此,日期选择器的显示必须集成到FORM Html区域中。


这意味着日期选择器必须包含在HTML表单中。
要在POST结束时检索值,命令为:


要获得表单POST的值,命令是:
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$mydate = dol_mktime(12, 0 , 0, $_POST['mykeymonth'], $_POST['mykeyday'], $_POST['mykeyyear']);
$mydate = dol_mktime(12, 0 , 0, $_POST['mykeymonth'], $_POST['mykeyday'], $_POST['mykeyyear']);
Line 412: Line 422:
</syntaxhighlight>
</syntaxhighlight>


==新增设置页 (可选)==
===覆盖模板文件 (tpl)===
'''何时''': 如果模块需要用户提供的参数,以正确设置模块。
如果您想覆盖模块上的tpl文件,则需要在 module_parts 上声明它:
 
<syntaxhighlight lang="PHP">
'tpl' => 1,
</syntaxhighlight>
 
然后您可以在 '''mymodule/core/tpl''' 上放置任何tpl文件。
 
一旦模块被激活,tpl就会被覆盖。


===创建页面以编辑参数===
==设置配置页面 (可选)==
如果模块需要设置几个参数,则必须创建一个页面来编辑选项。 (这些制作存储于 [[Table llx_const|表 '''llx_const''']]).
'''何时''':如果您的模块提供多个可配置选项。


新建 '''mymodule_setuppage.php''' 这显示了可能的选项的表单,将它们更新到上面提到的表中。
===创建配置编辑页面===
如果您的模块提供了多个可配置选项,则需要创建一个PHP页面来编辑这些选项(存储在 [[Table llx_const|表 '''llx_const''']] 中)。


有必要从目录''/admin ''的页面中获取一个示例,它将向您展示读取/保存参数的方法。
创建一个名为 '''mymodule_setuppage.php''' 的PHP页面,显示可能的选项并更新它们。


把这个PHP页面放到你的模块的''/admin ''(例如mymodule/admin/mymodule_setuppage.php)的目录中。
有必要以 '''/admin''' 中的一个页面为例,展示读取或保存选项的方法。将此配置页面也放在'''/admin'''目录中。


===修改模块主文件===
===修改模块的描述符文件===
然后,在模块主文件中,将变量“config_page_url”修改为PHP页面的设置名称。
然后,在模块描述符文件中,修改变量 '''config_page_url''' 以指定该PHP页面的名称。
 
如果页面在目录 '''admin/''' 中),则:


如果页面位于目录'''admin/'''中,则不需要路径,例如:
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$this->config_page_url = array("mymodule_setuppage.php");
$this->config_page_url = array("mymodule_setuppage.php");
</syntaxhighlight>
</syntaxhighlight>


如果页面在目录 '''mymodule/admin/'''中,则像这样:
如果页面在目录 '''mymodule/admin/''' 中,则:
 
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$this->config_page_url = array("mymodule_setuppage.php@mymodule");
$this->config_page_url = array("mymodule_setuppage.php@mymodule");
</syntaxhighlight>
</syntaxhighlight>


===测试页面===
===测试您的页面===
进入'''首页->安装>模块''',您应该在您的模块行的末尾看到一个图片,以转到您的设置页面。点击它,你就可以从页面中查看/编辑参数。
前往“主页->设置->模块/应用”页面,您应该会看到一个齿轮图标,允许您访问配置页面,并且您应该能够修改这些选项并将其保存到数据库中。
 
==设置菜单项 (可选)==
'''何时''' :如果您创建了PHP页面,则必须从Dolibarr菜单访问这些屏幕页面。
 
===设置菜单项===
为此,您需要在模块描述符文件中定义数组 this->menu,该数组用于声明菜单。
 
此数组包含模块激活后将显示在菜单中的所有条目。


==增加菜单条目 (可选)==
模块描述符文件的示例文件 '''modMyModule.class.php''' 中有一个声明顶部菜单及其相关的左侧菜单项的示例。
'''何时''': 如果您创建了PHP页面,则必须从Dolibarr菜单中的菜单条目中访问这些页面。


===增加菜单条目===
以下是描述符文件中菜单项声明的示例:
For this, you must define into the module descriptor, the array this->menu that declare all menus added by your module.
This array contains entries that will appear once your module is activated.
The example module descriptor file '''modMyModule.class.php''' contains an example to declare a top menu and also its left menu entries.


This is the example of code to declare your own menu entries in a module descriptor file:
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
// Main menu entries
// Main menu entries
Line 486: Line 510:
</syntaxhighlight>
</syntaxhighlight>


To show menu or not depending on a permission, modify property '''perms''' in array. See chapter on permissions later to see how to add permissions.
若要根据权限限制对菜单的访问,请更改数组的 '''perms''' 属性。有关如何添加权限的更多信息,请参阅后面有关权限的章节。


===测试菜单===
===测试您的菜单项===
Disable and reenable your module under Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok).
在Dolibarr中禁用并重新激活您的模块,然后应该会出现菜单项(如果 “enabled”为真)。


==新增权限 (可选)==
==设置您自己的权限 (可选)==
'''When''': If you want to add new permissions.
'''何时''': 如果要添加新权限。
 
模块将其管理的权限定义,放在第一步中创建的模块描述符文件中完成。更改行:


The way to define permissions that will manage your module is done inside the module descriptor created previously.
Modify line
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$this->rights_class = 'mymodule'
$this->rights_class = 'mymodule'
</syntaxhighlight>
</syntaxhighlight>
with correct value for mymodule.


Then you must fill the array $this->rights with as many entries than different permissions you need to manage.
录入正确的 myModule 值。
 
然后在 $this->rights 数组中填充与要管理的不同权限一样多的条目。


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
Line 512: Line 537:
</syntaxhighlight>
</syntaxhighlight>


Into $this->rights[$r][0], put a permission id not already used (See into menu '''System info''' on a working installation of Dolibarr to know list of id already used by standard modules.
在$this->rights[$r][0]中,输入尚未使用的权限ID(请参阅'''系统信息'''菜单,在运行Dolibarr的设备上查看已在使用的ID)。
Into $this->rights[$r][3], put 1 if this permission must be granted automatically by default to any new created user.
 
Into $this->rights[$r][1], put a label by default for permission (This label will be used if no translation can be found into the file '''admin.lang''').
在$this->rights[$r][1]中,输入默认标签(如果在 '''admin.lang''' 文件中找不到您权限标签的翻译字符串,则显示该标签。翻译键值为 “Permission10001=我的超级权限的描述”)。
Into $this->rights[$r][4] and $this->rights[$r][5], put an action and subaction string without spaces. You will be able to test if a user has the permission in your PHP source code with the sequence:
 
在$this>rights[$r][2]中,输入权限类型。有三种类型的权限,“r”表示读取、列出清单或导出权限,“w”表示写入或更新权限,“d”表示删除权限。
 
在$this->rights[$r][3]中,如果任何一个新创建的用户都会被默认自动分配此权限,则输入1。
 
在$this->rights[$r][4]和$this->rights[$r][5]中,输入不带空格的操作和子操作字符串。然后,您可以通过以下命令在PHP代码中测试用户是否具有正确的权限:


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
Line 521: Line 551:
</syntaxhighlight>
</syntaxhighlight>


==信息窗 (可选)==
==设置您自己的消息框/widget小组件 (可选)==
'''When''': If your module need to provide one or several new boxes to show on home page.
'''何时''':如果您的模块附带提供在主页上展示的一个或多个消息框。


===信息窗===
===设置您的消息框===
For this, modify the array $this->boxes into the module descriptor file.
为此,请修改模块描述符文件中的数组 $this->boxes。
All you have to do is to add 2 lines for each box file you will create into directory '''htdocs/mymodule/core/boxes'''
 
首先为即将在 '''htdocs/mymodule/core/boxes''' 目录中创建的每个box文件添加2行。
 
例如:


''Example:''
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$this->boxes[0]['file']='mybox0.php@mymodule'
$this->boxes[0]['file']='mybox0.php@mymodule'
Line 537: Line 569:
</syntaxhighlight>
</syntaxhighlight>


Then create files '''htdocs/mymodule/core/boxes/mybox0.php''', '''htdocs/mymodule/core/boxes/mybox1.php'''... by copying an example from an existing box file (found into directory '''htdocs/core/boxes''').
其次,创建文件'''htdocs/mymodule/core/boxes/mybox0.php'''、'''htdocs/mymodule/core/boxes/mybox1.php'''…,以现有的消息框(在 '''htdocs/core/boxes''' 目录中)为示例。
 
===测试您的消息框是否被 Dolibarr 检测到===
停用并重新激活模块。
 
前往菜单  '''主页 - 设置 - widget小组件''' 。


===Test if your box is detected by Dolibarr===
您的消息框必须显示在可激活消息框的清单中。激活它们,然后前往'''主页'''并检查它们是否正确显示。
Disable and enabled module.


Go into menu '''Home - Setup - Boxes'''.
==定义您自己的导出 (可选)==
'''何时''':如果您的模块附带提供预定义的数据导出(针对自己的表或来自另一个Dolibarr模块的现有表)。


Your boxes must appear in the list of boxes you can activated. Activate the box and go on home page to see if the box is showing correctly.
===定义导出===
为此,请取消注释并修改模块描述符文件中的 $this->export_xxx 数组。


==Define your own export (optional)==
===测试您的导出===
'''When''': If your module provide new predefined database export profiles (for its own tables or for already existing tables of another module).
前往菜单 '''工具->导出助手''' 。您的导出应显示在可用的预定义导出清单中(如果您的模块已激活)。选择它,您将看到在上一步时在表中定义的可能字段。选择几个字段并尝试生成导出文件。


===导出===
==设置CSS样式 (可选)==
For this uncomment and modify arrays $this->export_xxx in your module descriptor file.
'''何时''':在PHP屏幕页面中,您使用的样式类不是Dolibarr主题的样式类(不推荐)。


===Test your export===
===创建并声明您的样式表===
Go into menu Tools -> Export. Your export will appear in the list of available predefined exports (if your module is enabled).
创建一个名为 '''mymodule.css''' 或 '''mymodule.css.php''' 的CSS样式文件,并将其放在 '''htdocs/mymodule''' 目录中。每个模块只能有一个CSS文件。
Choose it, you must see list of all possible fields defined in the export arrays.
Choose on field and try to build an export file. If ok, try again with all fields.


==Define your CSS styles (optional)==
请记住,最好使用已有的Dolibarr样式(Dolibarr使用的CSS文件是'''themes/mytheme/''themename''.css.php''')。仅当您必须处理不存在的样式时,才创建特定于模块的CSS文件。
'''When''': If in your PHP pages, you use class styles that are not defined inside Dolibarr themes CSS (not recommanded).


===Create and declare your style sheet===
样式表准备就绪后,通过更改 '''$this->modules_parts''' 属性在模块描述符文件中声明样式表。
Create a style sheet CSS named '''mymodule.css''' or '''mymodule.css.php''' and put it into directory '''htdocs/mymodule'''. You can have only one CSS file per module.
 
Remember it's better to use existing styles already available by default into Dolibarr (The CSS file used by Dolibarr is file '''themes/mytheme/''themename''.css.php'''. Create your own CSS file only if you need absolutely to add not already existing styles.
此处要输入的值必须是 CSS 文件 URL 的相对路径。
 
例如:


Once your style sheet is ready, declare it into your module descriptor file by modifying the property '''$this->modules_parts'''.
Value to put here must be a relative URL to your CSS file.
For example
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$this->module_parts = array('css' => array('/mymodule/css/mymodule.css.php'));
$this->module_parts = array('css' => array('/mymodule/css/mymodule.css.php'));
</syntaxhighlight>
</syntaxhighlight>


===Test your style sheet===
===测试您的样式表===
Disable and enable your module.
停用并重新激活模块。
 
前往Dolibarr的主页。查看页面的HTML源代码。
 
您应该在HTML标头中看到有一行是声明您的样式表。


Go on home page (index.php). Show the HTML source of the page.
==定义Javascript函数 (可选)==
'''何时''':当您在PHP屏幕页面中使用的 javascript 函数不是Dolibarr的标准js函数(在lib_head.js中)。


You should see into the HTML header, a line that declare your style sheet.
如果在PHP屏幕页面上使用 javascript 函数,则必须将在 javascript 文件 '''htdocs/mymodule/js/mymodule.js''' 中声明的函数加载到HTML头中。


==增加JS函数功能 (可选)==
若要求Dolibarr(负责生成 header 部分)包含一个 javascript 文件,必须在页面开头调用的llxHeader()函数的参数中提供包含要包含的JS URL的参数。
'''When''': If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js)


If you need to use your own javascript functions inside your PHP pages, it is necessary to have your functions, defined into your  javascript file '''htdocs/mymodule/js/mymodule.js''', included into the HTML HEAD section.
页面 /htdocs/mymodule/mypage.php 的示例:
To ask Dolibarr that forge this header to include your own javascript file, you must just provide it to the llxHeader() function called by your page.


Example for page /htdocs/mymodule/mypage.php :
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$morejs=array("/mymodule/js/mymodule.js");
$morejs=array("/mymodule/js/mymodule.js");
Line 590: Line 626:
</syntaxhighlight>
</syntaxhighlight>


==执行Dolibarr事件代码 (可选)==
==在Dolibarr事件上触发代码 (可选)==
'''When''': If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a '''triggers'''.
'''何时''':希望在Dolibarr标准操作后触发执行特定操作时(例如:当在Dolibarr中创建发票时,我想更新模块中的表),您需要创建一个 '''triggers''' 文件。
 
See also [[Interfaces_Dolibarr_toward_foreign_systems]]
and [[Interfaces_from_foreign_systems_toward_Dolibarr]]


==钩子代码 (可选)==
另请参阅 [[Interfaces_Dolibarr_toward_foreign_systems|Dolibarr到外部系统的接口]] 和 [[Interfaces_from_foreign_systems_toward_Dolibarr|外部系统到Dolibarr的接口]]
'''When''': When you want to add code or replace Dolibarr code into another situation than a business event (See previous chapter for adding code during a business event).


See page [[Hooks_system]].
==在Dolibarr的hooks处插入代码 (可选)==
'''何时''':当您想更改或添加业务事件以外的代码时(请参阅上一章)。


请参阅页面 [[Hooks_system|Hooks系统]].
==添加编号模块(可选)==
'''何时''':当您想添加默认模块未涵盖的编号规则时。


==添加编码规则==
请参阅页面 [[Create numbering module|创建编号模块]] 。
'''When''': When you need a new rule for generated ref of elements that is not covered by existing rules.


See page [[Create numbering module]].
==添加新文档模板 (可选)==
'''何时''':需要添加新文档模板时。如想要个性化自己生成的 PDF 或 ODT 文档。


==创建文档模板 (optional)==
注意:要添加此功能,您无需创建模块描述符文件。
'''When''': When you want to personalized your own generated PDF or ODT documents.


Note: To add this feature you don't need to create a module descriptor.
有关如何从模板生成文档的详情,请参阅页面 [[Create_a_PDF_document_template|创建PDF文档模板]] 或 [[Create_an_ODT_document_template|创建ODT文档模板]] 。


Documentation to add your own template is available on page [[Create_a_PDF_document_template]] or [[Create_an_ODT_document_template]].
==添加主题 (可选)==
'''何时''':当您想要根据您的情况定制界面(颜色/字体/图形)时。


==创建主题 (optional)==
注意:要添加此功能,您无需创建模块描述符。
'''When''': When you want to personalized your colors/fonts/images.


Note: To add this feature you don't need to create a module descriptor.
请参阅页面 [[Skins|主题]] 。
 
To add your own skin, read page [[Skins]].


==修改开发模块作者名==
==修改开发模块作者名==
Line 626: Line 659:


修改以下变量的值以修改作者名称
修改以下变量的值以修改作者名称
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$this->editor_name = 'Roger@QQ:12464313';
$this->editor_name = 'Roger@QQ:12464313';
Line 631: Line 665:
</syntaxhighlight>
</syntaxhighlight>


=一些编码规则和预定义函数=
=面向开发人员的一些编码规则和函数=
The coding rules to be followed are defined in the [[Developer documentation]], under section "General Information - Language and standards development".
要遵循的编码规则请参阅 [[语言和开发规则|开发语言和编码规范(PHP, SQL, HTML)]] 。


A lot of predefined features for developers are also available and described into page [[Developer documentation]] under section "Technical components of Dolibarr".
要调用 Dolibarr 供开发人员使用的预定义函数,请参阅  [[开发文档]] 的“内部函数”一节。


=创建一个安装包来分发和安装您的模块=
=创建一个安装包来分发和安装您的模块=
This process must be used to generate a package to submit it on the http://www.dolistore.com market place.
必须使用此步骤来制作安装包,以便将其提交到市场 http://www.dolistore.com。
But you can use it to have a package easy to distribute on your on network.


*Go into the directory '''/build''' and copy the file '''makepack-dolibarrmodules.conf''' into '''makepack-mymodule.conf'''. Warning, this directory may not be provided in some packages of stable versions. If so, it can be retrieved from the snapshot available for download on the Dolibarr website in area "Development version" (taken in this case the whole build directory which is autonomous and independent directory).
但您也可以使用它通过自己的分发网络轻松分发模块。


Edit this file to add list of file names for all new files you created for your module (module descriptor, new sql tables files, php page, images, etc...)
*进入 '''/build''' 目录并将文件 '''makepack-dolibarrmodules.conf''' 复制到 '''makepack-mymodule.conf'''。请注意,稳定版本包中可能不提供此目录。如果是这种情况,可以在 Dolibarr 网站的“开发版本”部分供下载的快照中检索(在这种情况下,请获取整个 build 目录,这是一个独立于版本的目录)。


*Run the script via Perl (need the Perl version 5.0 or later):
在此文件中输入为模块创建的新文件的名称清单(模块描述符、新表的SQL文件、PHP页面、图像等)。
 
*通过 Perl 运行脚本(需要Perl 5.0或更高版本):


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
perl makepack-dolibarrmodule.pl
perl makepack-dolibarrmodule.pl
</syntaxhighlight>
</syntaxhighlight>
The script asks you the name of your module, its major and minor version. A file '''mymodule.zip ''' will then be manufactured containing your module ready to be deployed.


*The person who receives your module must then place the file in the root directory of a Dolibarr installation and perform the command:
该脚本将询问模块的名称、主要版本和次要版本。然后将生成一个 '''mymodule.zip '''文件,其中包含准备部署的模块。
 
*接收您的模块的人员必须将该文件放在其 Dolibarr 的安装根目录中,并执行以下命令:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 657: Line 693:
</syntaxhighlight>
</syntaxhighlight>


*If you want your module to be public, you can submit it (the zip file) on Dolibarr market place web site: {{LinkToPluginDownload}} (you must create an account first and be logged to use the link "Submit a module/product").
*如果您希望您的模块惠及所有人,您可以在插件市场 {{LinkToPluginDownload}} 上提交它(zip文件)(您必须先创建一个帐户并登录,以使用“提交模块/产品”链接)。
**If your module was build correctly, file will be validated later.
**如果您的模块制作正确,文件将很快通过验证。
**If quality is enough and license permits it, code might be added inside main Dolibarr sources (except if you disagree for that).
**如果质量足够好、许可证允许、并且模块的功能被证明是普遍感兴趣的,则可以将代码添加到 Dolibarr 的源代码中(除非您不希望这样做)。


=Dolistor上的外部模块的启用/激活条件=
=Dolistore上外部模块的归档和验证=


See [[Module_Dolistore_Validation_Rules|Validation Rules]]
请参阅 [[Module_Dolistore_Validation_Rules|验证规则]]
715

edits