Code

ef9446584fc1b296ad56e926a8f473a6f2ef14c4
[gosa.git] / sudo-ldap / src / class_sudoldapEditRole.inc
1 <?php
3 class sudoldapEditRole extends plugin
4 {
5   /* Plugin specific values */
6   var $attributes       = array("cn",
7                                 "description",
8                                 "sudoUser", 
9                                 "sudoHost", 
10                                 "sudoCommand", 
11                                 "sudoRunAs", 
12                                 "sudoOption");
13   
14   var $objectclasses    = array("sudoRole");
16   var $cn               = "";
17   var $description      = "";
18   var $sudoUser         = "";
19   var $sudoHost         = "";
20   var $sudoCommand      = "";
21   var $sudoRunAs        = "";
22   var $sudoOption       = "";
24   var $isNew            = true; 
26   function sudoldapEditRole ($config, $dn= NULL, $attrs = array())
27   {
28     plugin::plugin ($config, $dn);
30     echo '<pre>';
31     print_r($attrs);
32     echo '</pre>';
34     if(!count($attrs)){
35         $this->isNew = true;
36     }else{
37         $this->isNew = false;
38         foreach($this->attributes as $value){
39                 if(isset($attrs[$value])){
40                         $this->$value = $attrs[$value];
41                 }
42         }
43     }
44   }
46   function execute()
47   {
48     /* Call parent execute */
49     plugin::execute();
52     /* Fill templating stuff */
53     $smarty= get_smarty();
54     $display= "";
56     $smarty->assign("cn",               $this->cn);
57     $smarty->assign("description",      $this->description);
58     $smarty->assign("sudoUser",         $this->sudoUser);
59     $smarty->assign("sudoHost",         $this->sudoHost);
60     $smarty->assign("sudoCommand",      $this->sudoCommand);
61     $smarty->assign("sudoRunAs",        $this->sudoRunAs);
62     $smarty->assign("sudoOption",       $this->sudoOption);
64     /* Display template */
65     $display.= $smarty->fetch(
66         get_template_path('sudoldapeditrole.tpl', TRUE));
67     return($display);
68   }
70   /* Save data to object */
71   function save_object()
72   {
73      //plugin::save_object();
74      foreach($this->attributes as $attr){
75         if(isset($_POST[$attr])){
76                 $this->$attr = $_POST[$attr];
77         }
78      }
79   }
82   /* Check supplied data */
83   function check()
84   {
85   }
88   /* Save to LDAP */
89   function save()
90   {
91     plugin::save();
92     $ldap= $this->config->get_ldap_link();
94     $this->dn = "cn=".$this->cn.",ou=SUDOers,".$this->config->current['BASE'];
95     $this->attrs['objectClass'] = array("sudoRole");
97     $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
98     $ldap->cd($this->dn);
99     $ldap->add($this->attrs); 
101     /* Display errors 
102      */
103     if($ldap->get_error() != "Success"){
104         show_ldap_error("Record:".$ldap->get_error(), _("Saving failed!")); 
105     }
107   }
109   
112 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
113 ?>