~ubuntu-branches/ubuntu/vivid/gosa/vivid

« back to all changes in this revision

Viewing changes to plugins/admin/fai/class_askClassName.inc

Tags: 2.7.1-1
* New upstream release
* Updated packaging to not include smarty (Closes: #620489)
* Fixed case of POSIX (Closes: #620486)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
class askClassName extends plugin
4
 
{
5
 
  /* attribute list for save action */
6
 
  var $ignore_account     = TRUE;
7
 
  var $attributes         = array();
8
 
  var $objectclasses      = array("whatever");
9
 
 
10
 
  var $objectClass        = false;
11
 
  var $forbidden          = array();
12
 
  var $ClassName          = "";  
13
 
  var $ClassAlreadyExists = false;
14
 
 
15
 
  function askClassName ($config, $dn= NULL,$ui = false, $objectClass)
16
 
  {
17
 
    $this->ui = $ui;
18
 
    $this->objectClass = $objectClass;
19
 
    plugin::plugin ($config, $dn);
20
 
    if(!isset($_SESSION['CurrentMainBase'])){
21
 
      $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
22
 
    }
23
 
  }
24
 
 
25
 
  function execute()
26
 
  {
27
 
    /* Call parent execute */
28
 
    plugin::execute();
29
 
 
30
 
    /* Fill templating stuff */
31
 
    $smarty = get_smarty();
32
 
    $display= "";
33
 
 
34
 
    /* The faifilter contais 
35
 
     * The base for all fai objects 
36
 
     */
37
 
    $faifilter = $_SESSION['faifilter'];
38
 
 
39
 
    /* First search for every ou, in given fai base
40
 
     * With a second search detect all object that belong to the different ous. 
41
 
     */
42
 
 
43
 
    $base = "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
44
 
    if($faifilter['branch'] != "main"){
45
 
      $base = $faifilter['branch'];
46
 
    }
47
 
    $ldap = $this->config->get_ldap_link();
48
 
    $res= get_list("(objectClass=organizationalUnit)", $this->ui->subtreeACL, $base,
49
 
                   array("cn","description","objectClass"), GL_SIZELIMIT);
50
 
    $used = array();
51
 
 
52
 
    $delete = array();
53
 
    foreach($res as $objecttypes){
54
 
      $res2= get_list("(objectClass=*)", $this->ui->subtreeACL, $objecttypes['dn'],
55
 
                      array("cn","description","objectClass","FAIclass"), GL_SIZELIMIT | GL_CONVERT);
56
 
 
57
 
      foreach($res2 as $object){
58
 
        /* skip class names with this name */ 
59
 
        if(in_array($this->objectClass,$object['objectClass']) || in_array("FAIprofile",$object['objectClass'])){
60
 
          $delete[] = $object['cn'][0];
61
 
        }
62
 
    
63
 
        /* Skip profiles */
64
 
        if(!in_array("FAIprofile",$object['objectClass'])){
65
 
          if(isset($object['cn'])){
66
 
            $used[$object['cn'][0]]= $object['cn'][0];
67
 
          }
68
 
        }
69
 
      }
70
 
    }
71
 
    
72
 
    /* Create headline
73
 
     * Depending on the object type we want to create, a different headline will be shown
74
 
     */ 
75
 
    switch($this->objectClass) {
76
 
      case "FAIpartitionTable":  $str =_("Create new FAI object - partition table.");break;
77
 
      case "FAIpackageList"   :  $str =_("Create new FAI object - package bundle.");break;
78
 
      case "FAIscript"        :  $str =_("Create new FAI object - script bundle.");break;
79
 
      case "FAIvariable"      :  $str =_("Create new FAI object - variable bundle.");break;
80
 
      case "FAIhook"          :  $str =_("Create new FAI object - hook bundle.");break;
81
 
      case "FAIprofile"       :  $str =_("Create new FAI object - profile.");break;
82
 
      case "FAItemplate"      :  $str =_("Create new FAI object - template.");break;
83
 
      default                 :  $str =_("Create new FAI object");break;
84
 
    }
85
 
    $smarty->assign("headline",$str);
86
 
    
87
 
    /* Save forbidden class names
88
 
     */
89
 
    $this->forbidden = $delete;
90
 
 
91
 
    /* Delete all class names which already have this type of object 
92
 
     */
93
 
    foreach($delete as $del){
94
 
      unset($used[$del]);
95
 
    }
96
 
   
97
 
    /* if there is no class name which is missing for this type 
98
 
     *  of objectClass, we only can create a new one, disable selectBox 
99
 
     */
100
 
    if(count ($used)==0){
101
 
      $smarty->assign("ClassNamesAvailable", " disabled ");
102
 
      $smarty->assign("grey", 'style="color:#C0C0C0"');
103
 
    }else{
104
 
      $smarty->assign("ClassNamesAvailable", "");
105
 
      $smarty->assign("grey", "");
106
 
    }
107
 
    ksort($used);
108
 
    $smarty->assign("ClassNames", $used);
109
 
    $smarty->assign("ClassName",  $this->ClassName);
110
 
    $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE));
111
 
    return($display);
112
 
  }
113
 
 
114
 
  /* Get posts and set class name 
115
 
   */ 
116
 
  function save_object()
117
 
  {
118
 
    if(isset($_POST['classSelector']) && $_POST['classSelector'] == 1 
119
 
       && isset($_POST['edit_continue'])){
120
 
      $this->ClassName          = $_POST['UseTextInputName'];
121
 
      $this->ClassAlreadyExists = true;
122
 
    }
123
 
  
124
 
    if(isset($_POST['classSelector']) && $_POST['classSelector'] == 2 
125
 
       && isset($_POST['edit_continue'])){
126
 
      $this->ClassAlreadyExists = false;
127
 
      $this->ClassName          = $_POST['SelectedClass'];
128
 
    }
129
 
  }
130
 
 
131
 
  /* Check given class name 
132
 
   */
133
 
  function check()
134
 
  {
135
 
    /* Call common method to give check the hook */
136
 
    $message= plugin::check();
137
 
 
138
 
    if($this->ClassName != preg_replace("/ /","",trim($this->ClassName))){
139
 
      $message[] = _("Spaces are not allowed within class names.");
140
 
    }
141
 
 
142
 
    if(empty($this->ClassName)){
143
 
      $message[]=_("The given class name is empty.");
144
 
    }
145
 
 
146
 
    if(in_array($this->ClassName,$this->forbidden)){
147
 
      $message[]=_("The specified class name is already in use for this object type.");
148
 
    }
149
 
 
150
 
    return ($message);
151
 
  }
152
 
 
153
 
 
154
 
  /* Return the class name */
155
 
  function save()
156
 
  {
157
 
    return($this->ClassName);
158
 
  }
159
 
 
160
 
}
161
 
 
162
 
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
163
 
?>