Code

Updated schema check
[gosa.git] / gosa-core / include / class_configRegistry.inc
1 <?php
3 class configRegistry{
5     public $config = NULL;
6     public $properties = array();
7     public $ldapStoredProperties = array(); 
8     public $fileStoredProperties = array(); 
9     public $classToName = array(); 
11     public $status = 'none';
13     // Excludes property values defined in ldap 
14     public $ignoreLdapProperties = FALSE;
16     // Contains all classes with plInfo
17     public $classesWithInfo = array();
18     public $pluginRequirements  = array();
19     public $categoryToClass  = array();
21     public $objectClasses = array();
23     public $detectedSchemaIssues = array();
24     public $schemaCheckFailed = FALSE;
25     public $schemaCheckFinished = FALSE;
26     public $pluginsDeactivated = array();
28     function __construct($config)
29     {
30         $this->config = &$config;
32         // Detect classes that have a plInfo method 
33         global $class_mapping;
34         foreach ($class_mapping as $cname => $path){
35             $cmethods = get_class_methods($cname);
36             if (is_array($cmethods) && in_array_ics('plInfo',$cmethods)){
38                 // Get plugin definitions
39                 $def = call_user_func(array($cname, 'plInfo'));;
41                 // Register Post Events (postmodfiy,postcreate,postremove,checkhook)
42                 if(count($def)){
43                     $this->classesWithInfo[$cname] = $def;
44                 }
45             }
46         }
48         // (Re)Load properties
49         $this->reload();
50     }
52     
53     function schemaCheckFinished()
54     {
55         return($this->schemaCheckFinished);
56     }
59     
60     function validateSchemata($force = FALSE, $disableIncompatiblePlugins = FALSE)
61     {
62         // Read objectClasses from ldap
63         if(!count($this->objectClasses)){
64             $ldap = $this->config->get_ldap_link();
65             $ldap->cd($this->config->current['BASE']);
66             $this->setObjectClasses($ldap->get_objectclasses());
67         }
69         return($this->_validateSchemata($force, $disableIncompatiblePlugins));
70     }
72     function setObjectClasses($ocs)
73     {
74         $this->objectClasses = $ocs;
75     }
77     function getSchemaResults()
78     {
79         return($this->detectedSchemaIssues);
80     }
82     function _validateSchemata($force = FALSE, $disableIncompatiblePlugins = FALSE)
83     {
84         // We cannot check without readable schema info
85         if(!count($this->objectClasses)){
86             return(TRUE); 
87         }
89         // Don't do things twice unless forced
90         if($this->schemaCheckFinished && !$force) return($this->schemaCheckFailed); 
92         // Prepare result array
93         $this->detectedSchemaIssues = array();
94         $this->detectedSchemaIssues['missing'] = array();
95         $this->detectedSchemaIssues['versionMismatch'] = array();
97         // Clear last results 
98         $this->pluginsDeactivated = array();
100         // Collect required schema infos
101         $this->pluginRequirements = array('ldapSchema' => array());
102         $this->categoryToClass = array();
103         foreach($this->classesWithInfo as $cname => $defs){
104             if(isset($defs['plRequirements'])){
105                 $this->pluginRequirements[$cname] = $defs['plRequirements'];
106             }
107         }
109         // Check schema requirements now        $missing = $invalid = array();
110         foreach($this->pluginRequirements as $cname => $requirements){
112             // Check LDAP schema requirements for this plugins
113             $failure = FALSE;
114             if(isset($requirements['ldapSchema'])){
115                 foreach($requirements['ldapSchema'] as $oc => $version){
116                     if(!$this->ocAvailable($oc)){
117                         $this->detectedSchemaIssues['missing'][] = $oc;
118                         $this->schemaCheckFailed = TRUE;
119                         $failure = TRUE;
120                     }elseif(!empty($version)){
121                         $currentVersion = $this->getObjectClassVersion($oc);
122                         if(!empty($currentVersion) && !$this->ocVersionMatch($version, $currentVersion)){
123                             if($currentVersion == -1){
124                                 $currentVersion = _("unknown");
125                             }
126                             $this->detectedSchemaIssues['versionMismatch'][] = 
127                                 sprintf(_("%s has version %s but %s is required!"), bold($oc),bold($currentVersion),bold($version));
128                             $this->schemaCheckFailed = TRUE;
129                             $failure = TRUE;
130                         }
131                     }
132                 }
133             }
135             // Display corresponding plugins now 
136             if($disableIncompatiblePlugins && $failure && isset($requirements['onFailureDisablePlugin'])){
137                 foreach($requirements['onFailureDisablePlugin'] as $name){
138                     $this->pluginsDeactivated[$name] = $name;
139                 } 
140             }
141         }
142         $this->schemaCheckFinished =TRUE;
143         session::un_set('plist');
144         return(!$this->schemaCheckFailed);
145     }
147     
148     function getDisabledPlugins()
149     {
150         return($this->pluginsDeactivated);
151     }
153         
154     function displayErrors()
155     {
157         $message = "";
158         if(count($this->detectedSchemaIssues['missing'])){
159             $message.= "<br>".
160                 _("The following object classes are missing:").
161                 "<div class='scrollContainer' style='height:100px'>".
162                 msgPool::buildList($this->detectedSchemaIssues['missing']).
163                 "</div>";
164         }    
165         if(count($this->detectedSchemaIssues['versionMismatch'])){
166             $message.= "<br>".
167                 _("The following object classes are outdated:").
168                 "<div class='scrollContainer' style='height:100px'>".
169                 msgPool::buildList($this->detectedSchemaIssues['versionMismatch']).
170                 "</div>";
171         }    
172         if($message != ""){
173             $message.= "<br>"._("Plugins that require one or more of the object classes above will be disabled until the object classes get updated.");
174  
175             msg_dialog::display(_("Schema validation error"),$message, ERROR_DIALOG);
176         }
177     }
180     function ocVersionMatch($required, $installed)
181     {
182         $operator = preg_replace('/^([=<>]*).*$/',"\\1",$required);
183         $required = preg_replace('/^[=<>]*(.*)$/',"\\1",$required);
184         return(version_compare($installed,$required, $operator)); 
185     }
187     
188     function getObjectClassVersion($oc)
189     {
190         if(!isset($this->objectClasses[$oc])){
191             return(NULL);
192         }else{
193             $version = -1; // unknown
194             if(preg_match("/(v[^)]*)/", $this->objectClasses[$oc]['DESC'])){
195                 $version = preg_replace('/^.*\(v([^)]*)\).*$/',"\\1", $this->objectClasses[$oc]['DESC']);
196             }
197         }
198         return($version);
199     }
200     
202     // check wheter an objectClass is installed or not.
203     function ocAvailable($name)
204     {
205         return(isset($this->objectClasses[$name]));
206     }
209     function reload($force = FALSE)
210     {
211         // Do not reload the properties everytime, once we have  
212         //  everything loaded and registrered skip the reload.
213         // Status is 'finished' once we had a ldap connection (logged in)
214         if(!$force && $this->status == 'finished') return;
216         // Reset everything
217         $this->ldapStoredProperties = array();
218         $this->fileStoredProperties = array();
219         $this->properties = array();
220         $this->mapByName = array();
222         if(!$this->config) return;
224         // Search for config flags defined in the config file (TAB section)
225         foreach($this->config->data['TABS'] as $tabname => $tabdefs){
226             foreach($tabdefs as $info){
228                 // Check if the info is valid
229                 if(isset($info['NAME']) && isset($info['CLASS'])){
231                     // Check if there is nore than just the plugin definition
232                     if(count($info) > 2){
233                         foreach($info as $name => $value){
234                             
235                             if(!in_array($name, array('CLASS','NAME'))){
236                                 $class= $info['CLASS'];    
237                                 $this->fileStoredProperties[$class][strtolower($name)] = $value;
238                             }
239                         }
240                     }
241                 }
242             }
243         }
245         // Search for config flags defined in the config file (MENU section)
246         foreach($this->config->data['MENU'] as $section => $entries){
247             foreach($entries as $entry){
248                 if(count($entry) > 2 && isset($entry['CLASS'])){
249                     $class = $entry['CLASS'];
250                     foreach($entry as $name => $value){
251                         if(!in_array($name, array('CLASS','ACL'))){
252                             $this->fileStoredProperties[strtolower($class)][strtolower($name)] = $value;
253                         }
254                     }
255                 }
256             }
257         }
259         // Search for config flags defined in the config file (MAIN section)
260         foreach($this->config->data['MAIN'] as $name => $value){
261             $this->fileStoredProperties['core'][strtolower($name)] = $value;
262         }
264         // Search for config flags defined in the config file (Current LOCATION section)
265         if(isset($this->config->current)){
266             foreach($this->config->current as $name => $value){
267                 $this->fileStoredProperties['core'][strtolower($name)] = $value;
268             }
269         }
271         // Skip searching for LDAP defined properties if 'ignoreLdapProperties' is set to 'true'
272         //  in the config. 
273         $this->ignoreLdapProperties = FALSE;
274         if(isset($this->fileStoredProperties['core'][strtolower('ignoreLdapProperties')]) && 
275             preg_match("/(true|on)/i", $this->fileStoredProperties['core'][strtolower('ignoreLdapProperties')])){
276             $this->ignoreLdapProperties = TRUE;
277         }
279         // Search for all config flags defined in the LDAP - BUT only if we ARE logged in. 
280         if(!empty($this->config->current['CONFIG'])){
281             $ldap = $this->config->get_ldap_link();
282             $ldap->cd($this->config->current['CONFIG']);
283             $ldap->search('(&(objectClass=gosaConfig)(gosaSetting=*))', array('cn','gosaSetting'));
284             while($attrs = $ldap->fetch()){
285                 $class = $attrs['cn'][0];
286                 for($i=0; $i<$attrs['gosaSetting']['count']; $i++){
287                     list($name,$value) = preg_split("/:/",$attrs['gosaSetting'][$i],2);
288                     $this->ldapStoredProperties[$class][$name] = $value;
289                 }
290             }
291             $this->status = 'finished';
292         }
294         // Register plugin properties.
295         foreach ($this->classesWithInfo as $cname => $def){
297             // Detect class name
298             $name = $cname;
299             $name = (isset($def['plShortName'])) ? $def['plShortName'] : $cname;
300             $name = (isset($def['plDescription'])) ? $def['plDescription'] : $cname;
302             // Register post events
303             $this->classToName[$cname] = $name;
304             $data = array('name' => 'postcreate','type' => 'command');
305             $this->register($cname, $data);    
306             $data = array('name' => 'postremove','type' => 'command');
307             $this->register($cname, $data);    
308             $data = array('name' => 'postmodify','type' => 'command');
309             $this->register($cname, $data);    
310             $data = array('name' => 'check', 'type' => 'command');
311             $this->register($cname, $data);    
313             // Register properties 
314             if(isset($def['plProperties'])){
315                 foreach($def['plProperties'] as $property){
316                     $this->register($cname, $property);
317                 }
318             }
319         }
320     }
322     function register($class,$data)
323     {
324         $id = count($this->properties);
325         $this->properties[$id] = new gosaProperty($this,$class,$data);
326         $p = strtolower("{$class}::{$data['name']}");
327         $this->mapByName[$p] = $id;
328     }
330     public function getAllProperties()
331     {
332         return($this->properties);
333     }
335     function propertyExists($class,$name)
336     {       
337         $p = strtolower("{$class}::{$name}");
338         return(isset($this->mapByName[$p]));
339     }
341     private function getId($class,$name)
342     {
343         $p = strtolower("{$class}::{$name}");
344         if(!isset($this->mapByName[$p])){
345             return(-1);
346         }       
347         return($this->mapByName[$p]);    
348     }
350     function getProperty($class,$name)
351     {
352         if($this->propertyExists($class,$name)){
353             return($this->properties[$this->getId($class,$name)]);
354         }
355         return(NULL); 
356     }
358     function getPropertyValue($class,$name)
359     {   
360         if($this->propertyExists($class,$name)){
361             $tmp = $this->getProperty($class,$name);
362             return($tmp->getValue());
363         }
364         return("");
365     }
367     function setPropertyValue($class,$name, $value)
368     {   
369         if($this->propertyExists($class,$name)){
370             $tmp = $this->getProperty($class,$name);
371             return($tmp->setValue($value));
372         }
373         return("");
374     }
376     function saveChanges()
377     {
378         $migrate = array();
379         foreach($this->properties as $prop){
381             // Is this property modified
382             if(in_array($prop->getStatus(),array('modified','removed'))){
384                 // Check if we've to migrate something before we can make the changes effective. 
385                 if($prop->migrationRequired()){
386                     $migrate[] = $prop;
387                 }else{
388                     $prop->save();
389                 }
390             }
391         }
392         return($migrate);
393     }
397 class gosaProperty
399     protected $name = "";
400     protected $class = "";
401     protected $value = "";
402     protected $tmp_value = "";  // Used when modified but not saved 
403     protected $type = "string";
404     protected $default = "";
405     protected $defaults = "";
406     protected $description = "";
407     protected $check = "";
408     protected $migrate = "";
409     protected $mandatory = FALSE;
410     protected $group = "default";
411     protected $parent = NULL;
412     protected $data = array();
414     protected $migrationClass = NULL;
416     /*!  The current property status
417      *     'ldap'       Property is stored in ldap 
418      *     'file'       Property is stored in the config file
419      *     'undefined'  Property is currently not stored anywhere
420      *     'modified'   Property has been modified (should be saved)
421      */
422     protected $status = 'undefined';
424     protected $attributes = array('name','type','default','description','check',
425             'migrate','mandatory','group','defaults');
430     function __construct($parent,$classname,$data)
431     {
432         // Set some basic infos 
433         $this->parent = &$parent;
434         $this->class = $classname;
435         $this->data  = $data;
437         // Get all relevant information from the data array (comes from plInfo)    
438         foreach($this->attributes as $aName){
439             if(isset($data[$aName])){
440                 $this->$aName = $data[$aName];
441             }
442         }      
444         // Initialize with the current value
445         $this->_restoreCurrentValue(); 
447     }
449     function migrationRequired()
450     {
451         // Instantiate migration class 
452         if(!empty($this->migrate) && $this->migrationClass == NULL){
453             if(!class_available($this->migrate)){
454                 trigger_error("Cannot start migration for gosaProperty::'{$this->getName()}' class not found ({$this->migrate})!");
455             }else{
456                 $class = $this->migrate;
457                 $tmp = new $class($this->parent->config,$this);
458                 if(! $tmp instanceof propertyMigration){ 
459                     trigger_error("Cannot start migration for gosaProperty::'{$this->getName()}' doesn't implement propertyMigration!");
460                 }else{
461                     $this->migrationClass = $tmp;
462                 }
463             }
464         }
465         if(empty($this->migrate) || $this->migrationClass == NULL){
466             return(FALSE);
467         }
468         return($this->migrationClass->checkForIssues());
469     }
471     function getMigrationClass()
472     {
473         return($this->migrationClass);
474     }
476     function check()
477     {
478         $val = $this->getValue(TRUE);
479         $return = TRUE;
480         if($this->mandatory && empty($val)){
481             $return = FALSE;
482         }
484         $check = $this->getCheck();
485         if(!empty($val) && !empty($check)){
486             $res = call_user_func(preg_split("/::/", $this->check),$messages=TRUE, $this->class,$this->name,$val, $this->type);
487             if(!$res){
488                 $return = FALSE;
489             }
490         }
491         return($return);
492     }
494     static function isBool($message,$class,$name,$value, $type)
495     {
496         $match = in_array($value,array('true','false',''));
498         // Display the reason for failing this check.         
499         if($message && ! $match){
500             msg_dialog::display(_("Warning"), 
501                     sprintf(_("The value '%s' specified for '%s:%s' is invalid. A bool value is required here!"), 
502                         bold($value),bold($class),bold($name)), 
503                     WARNING_DIALOG);
504         }
505     
506         return($match);
507     }
509     static function isString($message,$class,$name,$value, $type)
510     {
511         $match = TRUE;
512     
513         // Display the reason for failing this check.         
514         if($message && ! $match){
515             msg_dialog::display(_("Warning"), 
516                     sprintf(_("The value '%s' specified for '%s:%s' is invalid. A string value is required here!"), 
517                         bold($value),bold($class),bold($name)), 
518                     WARNING_DIALOG);
519         }
521         return($match);
522     }
524     static function isInteger($message,$class,$name,$value, $type)
525     {
526         $match = is_numeric($value) && !preg_match("/[^0-9]/", $value);
528         // Display the reason for failing this check.         
529         if($message && ! $match){
530             msg_dialog::display(_("Warning"), 
531                     sprintf(_("The value '%s' specified for '%s:%s' is invalid. A numeric value is required here!"), 
532                         bold($value),bold($class),bold($name)), 
533                     WARNING_DIALOG);
534         }
536         return($match);
537     }
539     static function isPath($message,$class,$name,$value, $type)
540     {
541         $match = preg_match("#^(/[^/]*/){1}#", $value);
542     
543         // Display the reason for failing this check.         
544         if($message && ! $match){
545             msg_dialog::display(_("Warning"), 
546                     sprintf(_("The path '%s' specified for '%s:%s' is invalid!"), 
547                         bold($value),bold($class),bold($name)), 
548                     WARNING_DIALOG);
549         }
551         return($match);
552     }
554     static function isReadablePath($message,$class,$name,$value, $type)
555     {
556         $match = !empty($value)&&is_dir($value)&&is_writeable($value);
557    
558         // Display the reason for failing this check.         
559         if($message && ! $match){
560             if(!is_dir($value)){
561                 msg_dialog::display(_("Warning"), 
562                         sprintf(_("The folder '%s' specified for '%s:%s' does not exists!"), 
563                             bold($value),bold($class),bold($name)), 
564                         WARNING_DIALOG);
565             }elseif(!is_readable($value)){
566                 msg_dialog::display(_("Warning"), 
567                         sprintf(_("The folder '%s' specified for '%s:%s' cannot be used for reading!"), 
568                             bold($value),bold($class),bold($name)), 
569                         WARNING_DIALOG);
570             }
571         }
573         return($match);
574     }
576     static function isWriteablePath($message,$class,$name,$value, $type)
577     {
578         $match = !empty($value)&&is_dir($value)&&is_writeable($value);
579    
580         // Display the reason for failing this check.         
581         if($message && ! $match){
582             if(!is_dir($value)){
583                 msg_dialog::display(_("Warning"), 
584                         sprintf(_("The folder '%s' specified for '%s:%s' does not exists!"), 
585                             bold($value),bold($class),bold($name)), 
586                         WARNING_DIALOG);
587             }elseif(!is_writeable($value)){
588                 msg_dialog::display(_("Warning"), 
589                         sprintf(_("The folder '%s' specified for '%s:%s' cannot be used for writing!"), 
590                             bold($value),bold($class),bold($name)), 
591                         WARNING_DIALOG);
592             }
593         }
595         return($match);
596     }
598     static function isReadableFile($message,$class,$name,$value, $type)
599     {
600         $match = !empty($value) && is_readable($value) && is_file($value);
602         // Display the reason for failing this check.         
603         if($message && ! $match){
604                 
605             if(!is_file($value)){
606                 msg_dialog::display(_("Warning"), 
607                         sprintf(_("The file '%s' specified for '%s:%s' does not exists!"), 
608                             bold($value),bold($class),bold($name)), 
609                         WARNING_DIALOG);
610             }elseif(!is_readable($value)){
611                 msg_dialog::display(_("Warning"), 
612                         sprintf(_("The file '%s' specified for '%s:%s' cannot be read!"), 
613                             bold($value),bold($class),bold($name)), 
614                         WARNING_DIALOG);
615             }
616         }
618         return($match);
619     }
621     static function isCommand($message,$class,$name,$value, $type)
622     {
623         $match = TRUE;
625         // Display the reason for failing this check.         
626         if($message && ! $match){
627             msg_dialog::display(_("Warning"), 
628                     sprintf(_("The command '%s' specified for '%s:%s' is invalid!"), 
629                         bold($value),bold($class),bold($name)), 
630                     WARNING_DIALOG);
631         }
632         
633         return($match);
634     }
636     static function isDn($message,$class,$name,$value, $type)
637     {
638         $match = preg_match("/^([a-z]*=[^=,]*,)*[^=]*=[^=]*$/i", $value);
640         // Display the reason for failing this check.         
641         if($message && ! $match){
642             msg_dialog::display(_("Warning"), 
643                     sprintf(_("The dn '%s' specified for '%s:%s' is invalid!"), 
644                         bold($value),bold($class),bold($name)), 
645                     WARNING_DIALOG);
646         }
647         
648         return($match);
649     }
651     static function isRdn($message,$class,$name,$value, $type)
652     {
653         $match = preg_match("/^([a-z]*=[^=,]*,)*[^=]*=[^=,]*,?$/i", $value);
655         // Display the reason for failing this check.         
656         if($message && ! $match){
657             msg_dialog::display(_("Warning"), 
658                     sprintf(_("The rdn '%s' specified for '%s:%s' is invalid!"), 
659                         bold($value),bold($class),bold($name)), 
660                     WARNING_DIALOG);
661         }
662         
663         return($match);
664     }
666     private function _restoreCurrentValue()
667     {
668         // First check for values in the LDAP Database.
669         if(isset($this->parent->ldapStoredProperties[$this->class][$this->name])){
670             $this->setStatus('ldap');
671             $this->value = $this->parent->ldapStoredProperties[$this->class][$this->name];
672             return;
673         }
675         // Second check for values in the config file.
676         if(isset($this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)])){
677             $this->setStatus('file');
678             $this->value = $this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)];
679             return;
680         }
682         // If there still wasn't found anything then fallback to the default.
683         if($this->getStatus() == 'undefined'){
684             $this->value = $this->getDefault();
685         }
686     }
688     function getMigrate() { return($this->migrate); }
689     function getCheck() { return($this->check); }
690     function getName() { return($this->name); }
691     function getClass() { return($this->class); }
692     function getGroup() { return($this->group); }
693     function getType() { return($this->type); }
694     function getDescription() { return($this->description); }
695     function getDefault() { return($this->default); }
696     function getDefaults() { return($this->defaults); }
697     function getStatus() { return($this->status); }
698     function isMandatory() { return($this->mandatory); }
700     function setValue($str) 
701     {
702         if(in_array($this->getStatus(), array('modified'))){
703             $this->tmp_value = $str; 
704         }elseif($this->value != $str){
705             $this->setStatus('modified'); 
706             $this->tmp_value = $str; 
707         }
708     }
710     function getValue($temporary = FALSE) 
711     { 
712         if($temporary){
713             if(in_array($this->getStatus(), array('modified','removed'))){
714                 return($this->tmp_value); 
715             }else{
716                 return($this->value); 
717             }
718         }else{ 
720             // Do not return ldap values if we've to ignore them.
721             if($this->parent->ignoreLdapProperties){
722                 if(isset($this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)])){
723                     return($this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)]);
724                 }else{
725                     return($this->getDefault());
726                 }
727             }else{
728                 return($this->value); 
729             }
730         }
731     }
733     function restoreDefault() 
734     {
735         if(in_array($this->getStatus(),array('ldap'))){
736             $this->setStatus('removed'); 
738             // Second check for values in the config file.
739             if(isset($this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)])){
740                 $this->tmp_value = $this->parent->fileStoredProperties[strtolower($this->class)][strtolower($this->name)];
741             }else{
742                 $this->tmp_value = $this->getDefault();
743             }
744         }
745     }
747     function save()
748     {
749         if($this->getStatus() == 'modified'){
750             $ldap = $this->parent->config->get_ldap_link();
751             $ldap->cd($this->parent->config->current['BASE']);
752             $dn = "cn={$this->class},".$this->parent->config->current['CONFIG'];
753             $ldap->cat($dn);
754             if(!$ldap->count()){
755                 $ldap->cd($dn);
756                 $data = array(
757                         'cn' => $this->class, 
758                         'objectClass' => array('top','gosaConfig'),
759                         'gosaSetting' => $this->name.":".$this->tmp_value);
761                 $ldap->add($data);
762                 if(!$ldap->success()){
763                     echo $ldap->get_error();
764                 }
766             }else{
767                 $attrs = $ldap->fetch();
768                 $data = array();
769                 $found = false;
770                 if(isset($attrs['gosaSetting']['count'])){
771                     for($i = 0;$i<$attrs['gosaSetting']['count']; $i ++){
772                         $set = $attrs['gosaSetting'][$i];
773                         if(preg_match("/^{$this->name}:/", $set)){
774                             $set = "{$this->name}:{$this->tmp_value}";
775                             $found = true;
776                         }
777                         $data['gosaSetting'][] = $set;
778                     }
779                 }
780                 if(!$found) $data['gosaSetting'][] = "{$this->name}:{$this->tmp_value}";
781                 $ldap->cd($dn);
782                 $ldap->modify($data);
783                 if(!$ldap->success()){
784                     echo $ldap->get_error();
785                 }
786             }
787             $this->value = $this->tmp_value;
788             $this->setStatus('ldap'); 
789         }elseif($this->getStatus() == 'removed'){
790             $ldap = $this->parent->config->get_ldap_link();
791             $ldap->cd($this->parent->config->current['BASE']);
792             $dn = "cn={$this->class},".$this->parent->config->current['CONFIG'];
793             $ldap->cat($dn);
794             $attrs = $ldap->fetch();
795             $data = array('gosaSetting' => array());
796             for($i = 0;$i<$attrs['gosaSetting']['count']; $i ++){
797                 $set = $attrs['gosaSetting'][$i];
798                 if(preg_match("/^{$this->name}:/", $set)){
799                     continue;
800                 }
801                 $data['gosaSetting'][] = $set;
802             }
803             $ldap->cd($dn);
804             $ldap->modify($data);
805             if(!$ldap->success()){
806                 echo $ldap->get_error();
807             }
808             $this->_restoreCurrentValue();
809         }
810     }
812     private function setStatus($state) 
813     {
814         if(!in_array($state, array('ldap','file','undefined','modified','removed'))) {
815             trigger_error("Unknown property status given '{$state}' for {$this->class}:{$this->name}!");
816         }else{
817             $this->status = $state; 
818         }
819     }
821     function isValid() 
822     { 
823         return(TRUE);    
824     }
829 interface propertyMigration
831     function __construct($config,$property);
835 ?>