3e78f44e12f77244d2a439b8828305f8b4794052
1 <?php
3 class faiPackage extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage server basic objects";
7 var $cli_description = "Some longer text\nfor help";
8 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* attribute list for save action */
11 var $ignore_account = TRUE;
13 /* Attributes for this Object */
14 var $attributes = array("cn","description","FAIpackage");
16 /* ObjectClasses for this Object*/
17 var $objectclasses = array("top","FAIclass","FAIpackageList");
19 /* Class name of the Ldap ObjectClass for the Sub Object */
20 var $subClass = "";
21 var $subClasses = array("top","FAIclass","FAIscriptEntry");
23 /* Class name of the php class which allows us to edit a Sub Object */
24 var $subClassName = "";
26 /* Attributes to initialise for each subObject */
27 var $subAttributes = array("cn","description");
28 var $sub64coded = array();
30 /* Specific attributes */
31 var $cn = ""; // The class name for this object
32 var $description = ""; // The description for this set of partitions
33 var $is_dialog = false; // specifies which buttons will be shown to save or abort
34 var $dialog = NULL; // a dialog, e.g. new disk dialog
35 var $SubObjects = array(); // All leafobjects of this object
37 function faiPackage ($config, $dn= NULL)
38 {
39 /* Load Attributes */
40 plugin::plugin ($config, $dn);
42 /* If "dn==new" we try to create a new entry
43 * Else we must read all objects from ldap which belong to this entry.
44 * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
45 */
46 if($dn != "new"){
47 $this->dn =$dn;
48 }
50 $this->FAIpackage = "test";
51 }
53 function execute()
54 {
55 /* Fill templating stuff */
56 $smarty= get_smarty();
57 $display= "";
59 /* Assign variables */
60 foreach($this->attributes as $attrs){
61 $smarty->assign($attrs,$this->$attrs);
62 }
64 $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
65 return($display);
66 }
68 /* Generate listbox friendly SubObject list
69 */
70 function getList(){
71 $a_return=array();
72 foreach($this->SubObjects as $obj){
73 if($obj['status'] != "delete"){
74 $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]";
75 }
76 }
77 return($a_return);
78 }
80 /* Delete me, and all my subtrees
81 */
82 function remove_from_parent()
83 {
84 $ldap = $this->config->get_ldap_link();
85 $ldap->cd ($this->dn);
86 $ldap->rmdir_recursive($this->dn);
87 $this->handle_post_events("remove");
88 }
91 /* Save data to object
92 */
93 function save_object()
94 {
95 plugin::save_object();
96 foreach($this->attributes as $attrs){
97 if(isset($_POST[$attrs])){
98 $this->$attrs = $_POST[$attrs];
99 }
100 }
101 }
104 /* Check supplied data */
105 function check()
106 {
107 $message= array();
108 $str = utf8_encode("üöä");
109 if((empty($this->description))){
110 $message[]=_("Please enter a valid description.");
111 }
112 if((preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->description))){
113 $message[]=_("Please enter a valid description.");
114 }
115 return ($message);
116 }
119 /* Save to LDAP */
120 function save()
121 {
122 plugin::save();
124 $ldap = $this->config->get_ldap_link();
126 $ldap->cat($this->dn);
127 if($ldap->count()!=0){
128 /* Write FAIscript to ldap*/
129 $ldap->cd($this->dn);
130 $ldap->modify($this->attrs);
131 }else{
132 /* Write FAIscript to ldap*/
133 $ldap->cd(preg_replace('/^[^,]+,[^,]+,/', '', $this->dn));
134 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
135 $ldap->cd($this->dn);
136 $ldap->add($this->attrs);
137 }
138 show_ldap_error($ldap->get_error());
139 }
140 }
142 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
143 ?>