Code

Udpated password method
[gosa.git] / DEVEL
1 * How to get plugged in
3 Lets explain how to create a simple GOsa plugin. The example shows a dummy plugin which is not
4 directly related with LDAP. Independently of beeing an LDAP style or LDAP unrelated plugin, you
5 may start a new plugin, by creating a new directory below the plugin directory structure. To be up to
6 date, get a fresh SVN checkout:
8 Change to the directory which will contain your GOsa checkout, then get the source:
10 # svn co https://oss.gonicus.de/repositories/gosa/branches/2.5 gosa
12 for the current 2.5 development line or
14 # svn co https://oss.gonicus.de/repositories/gosa/trunk gosa
16 for the bleeding edge development tree.
19 The gosa directory will contain your initial checkout now. In order to update from SVN
20 you simply can call "svn up".
22 Now you've an up to date GOsa. Note that there may be most obviously something brokein if
23 you use trunk. Continue by choosing a name and creating the directories:
25 # cd plugins/addons
26 # mkdir dummyplug && cd dummyplug
28 GOsa expects a file named "main.inc" inside of this plugin directory. It is needed because some
29 plugins may need no standard handling and GOsa itself may not know how to initialize the plugin
30 classes. Here's our example:
32 ---
33 <?php
34         /* All page output must be placed inside the display variable. Please do not output anything
35            from within your plugin directly. GOsa will take the display variable after things got processed
36            and assemble the final page after that. */
38         /* print_header generates the page header including the headline and the icon, get template
39             path looks for eventually overloaded files. You don't have to take care of this - it's only important
40             for theming artists. Copy the icon (as .png) to the html/images directory, if you don't care about
41             the image, just copy the personal.png to dummy.png. */
42         $display= print_header(get_template_path('images/dummy.png'), _("A nice dummy plugin"));
44         /* All plugin objects get stored inside the PHP session. Here we create the object if it doesn't
45             exist yet. It is recreated if "reset" is set. */
46         if (!isset($_SESSION['dummy']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
47                 $_SESSION['dummy']= new dummy ($config);
48         }
49         $dummy= $_SESSION['dummy'];
51         /* Execute plugin. This calls your plugin class and appends its output to the display variable. */
52         $display.= $dummy->execute ();
54         /* The ignore field controls if GOsa should ignore the users tries to leave the plugin without
55            saving. For the dummy plugin, you can leave all the time without loosing data. */
56         $display.= "<input type=\"hidden\" name=\"ignore\">\n";
58         /* After executing the plugin, some data may have changed, so we need to put the plugin back
59            to the session. */
60         $_SESSION['export']= $export;
61 ?>
62 ---
64 The basic starter for your plugin is ready now. We're missing the plugin itself currently. To create it,
65 you need to create a file starting with class_ and ending with .inc. These files get sourced automatically.
67 Here's the class_dummy.inc:
69 ---
70 <?php
72 /* Create a class (name must be unique inside GOsa) which extends plugin. The plugin base
73     class contains all methods that are used by GOsa and it provides the mechanism to load data
74     from LDAP to local variables and prepare the save to ldap routine for you. */
75 class dummy extends plugin
76 {
78   /* These contain attributes to be loaded. We're not doing an LDAP plugin currently, so we don't
79      care... */
80   var $attributes= array();
81   var $objectclasses= array();
83   /* The constructor just saves a copy of the config. You may add what ever you need. */
84   function dummy ($config, $dn= NULL)
85   {
86         /* Include config object */
87         $this->config= $config;
88   }
90   /* Execute is the function all plugins need. It fills the plugin with life and produces the output. */
91   function execute()
92   {
93         /* Use the smarty templating engine here... */
94         $smarty= get_smarty();
96         /* Normally you would react to user input here. */
98         /* Let smarty fetch and process the page. Always seperate PHP and HTML as much as
99            you can. */
100         return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
101   }
104 ?>
105 ---
107 There are two things missing now. The template file and an entry in your gosa.conf. Lets finish the
108 work in the plugin directory, first.
110 Here is the contents.tpl file:
112 ---
113 <p>
114   {t}This is a dummy plugin. It really does nothing. The tags around this text do automatic translations to the desired language. Please don't include linefeeds here, or it will not work at all!{/t}
115 </p>
117 <p class="plugbottom">
118   &nbsp;
119 </p>
120 ---
122 Now add the following entry to your Addons section in gosa.conf:
123 --
124                         <plugin acl="dummy" class="dummy" icon="dummy.png"
125                                 path="plugins/addons/dummy" />
126 --
128 After logging into GOsa, you'll see your plugin in the addons section.