Code

Added initialy repository setup
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 8 Dec 2005 13:43:51 +0000 (13:43 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 8 Dec 2005 13:43:51 +0000 (13:43 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2259 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_servRepository.inc [new file with mode: 0644]
plugins/admin/systems/class_servRepositorySetup.inc [new file with mode: 0644]
plugins/admin/systems/servRepository.tpl [new file with mode: 0644]
plugins/admin/systems/servRepositorySetup.tpl [new file with mode: 0644]

diff --git a/plugins/admin/systems/class_servRepository.inc b/plugins/admin/systems/class_servRepository.inc
new file mode 100644 (file)
index 0000000..a205138
--- /dev/null
@@ -0,0 +1,221 @@
+<?php
+
+class servrepository extends plugin
+{
+  /* CLI vars */
+  var $cli_summary          = "Manage server basic objects";
+  var $cli_description      = "Some longer text\nfor help";
+  var $cli_parameters       = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+
+  /* attribute list for save action */
+//  var $ignore_account         = TRUE;
+  var $attributes             = array("FAIrepository");
+  var $objectclasses          = array("FAIrepositoryServer");
+  
+  /* Search filter */
+  var $regex                  = "*";
+
+  /* Configurationdialog for repositories */
+  var $dialog                 = NULL;
+
+  /* Repositories */
+  var $repositories           = array();
+  var $FAIrepository           = array();
+
+  function servrepository ($config, $dn= NULL)
+  {
+    plugin::plugin ($config, $dn);
+    $this->repositories = array();
+    for($i = 0; $i < $this->attrs['FAIrepository']['count']; $i++){
+      $tmp = split("\|",$this->attrs['FAIrepository'][$i]);
+      $tmp2 = array();  
+      $tmp3 = array();   
+      $tmp2['ParentServer'] = $tmp[1];
+      $tmp2['Url']          = $tmp[0];
+      $tmp2['Release']      = $tmp[2];
+      
+      $tmp3 = split(",",$tmp[3]);
+    
+      foreach($tmp3 as $sec){
+        $tmp2['Sections'][$sec]=$sec;
+      }    
+      $this->repositories[$tmp[2]]=$tmp2;      
+      
+    }
+  }
+
+  function execute()
+  {
+    /* Call parent execute */
+    plugin::execute();
+
+    /* Fill templating stuff */
+    $smarty= get_smarty();
+    $display= "";
+
+    /* Smarty vars*/
+    $smarty->assign("search_image", get_template_path('images/search.png'));
+    $smarty->assign("launchimage",  get_template_path('images/small_filter.png'));
+    $smarty->assign("tree_image",   get_template_path('images/tree.png'));
+    $smarty->assign("alphabet",     generate_alphabet());
+    $smarty->assign("apply",        apply_filter());
+    $smarty->assign("regex",        $this->regex);
+
+
+    /* Do we need to flip is_account state? */
+    if (isset($_POST['modify_state'])){
+      $this->is_account= !$this->is_account;
+    }
+
+    /* Show tab dialog headers */
+    if ($this->is_account){
+      $display= $this->show_header(_("Remove FAI repository extension."),
+          _("This server has FAI repository features enabled. You can disable them by clicking below."));
+    } else {
+      $display= $this->show_header(_("Add FAI repository extension."),
+          _("This server has FAI repository features disabled. You can enable them by clicking below."));
+      return ($display);
+    }
+    /*
+      ADD / EDIT Repository
+      Dialog Handling
+    */
+    
+    $once = false;
+    foreach($_POST as $name => $value){
+      if((preg_match("/^edit_/",$name))&&(!$once)){
+        if(isset($this->repositories[$value])){
+          $once = true;
+          $obj = $this->repositories[$value];
+      
+          /* to be able to detect if this was renamed */
+          $obj['initialy_was'] = $obj['Release'];
+          $this->dialog = new servRepositorySetup($this->config,$this->dn,$obj);
+          $this->dialog->acl = $this->acl;
+        }
+      }
+    }
+    if(isset($_POST['AddRepository'])){
+      $this->dialog = new servRepositorySetup($this->config,$this->dn);
+      $this->dialog->acl = $this->acl;
+    }
+
+    if(isset($_POST['repository_setup_save'])){
+      $this->dialog->save_object();
+      if(($this->dialog->is_new_name())&&(isset($this->repositories[$this->dialog->GetName()]))){
+        print_red(_("This name is already in use."));
+      }else
+
+      if(count($this->dialog->check())!=0){
+        foreach($this->dialog->check() as $msg){
+          print_red($msg);
+        }
+      }else{
+        $obj = $this->dialog->save();
+        $this->dialog = NULL;
+        $this->is_dialog= false;
+        $this->repositories[$obj['Release']]=$obj;        
+      }
+    }
+
+    if(isset($_POST['repository_setup_cancel'])){
+      $this->dialog=NULL;
+      $this->is_dialog = false;
+    }
+   
+    if($this->dialog != NULL){
+      $this->dialog->save_object();
+      $this->is_dialog = true;
+      return($this->dialog->execute());
+    }
+
+    /*
+      Repository setup dialog handling /END
+    */
+
+    $divlist = new divSelectBox("repositories");
+    $divlist->setHeight(400);
+
+    $edit = "<input type='image' value='%s' name='edit_%s' src='images/edit.png'>";
+   
+    foreach($this->repositories as $name => $reps){
+      $str = " ";
+      foreach($reps['Sections'] as $sec){
+        $str.=$sec." ";  
+      }    
+  
+      $divlist->AddEntry(array(
+                              array("string"=>$name),
+                              array("string"=>_("Sections")." :".$str),
+                              array("string"=>preg_replace("/%s/",$name,$edit),"attach"=>"style='border-right:0px;'")
+                              ));
+    }
+    $smarty -> assign("Repositories",$divlist->DrawList());
+
+    $display.= $smarty->fetch(get_template_path('servRepository.tpl', TRUE));
+    return($display);
+  }
+
+  function remove_from_parent()
+  {
+    /* This cannot be removed... */
+  }
+
+
+  /* Save data to object */
+  function save_object()
+  {
+    plugin::save_object();
+  }
+
+
+  /* Check supplied data */
+  function check()
+  {
+    $message= array();
+    return ($message);
+  }
+
+
+  /* Save to LDAP */
+  function save()
+  {
+    plugin::save();
+
+    $arr = array();
+    foreach($this->repositories as $servername => $conf){
+      $str = "";
+      foreach($conf['Sections'] as $sec){
+        $str.=$sec.",";
+      }
+      $str=preg_replace("/,$/","",$str);
+      $arr[]=$conf['Url']."|".$conf['ParentServer']."|".$conf['Release']."|".$str;
+    }
+    $this->attrs['FAIrepository'] = $arr;
+
+    $ldap= $this->config->get_ldap_link();
+    $ldap->cd ($this->config->current['BASE']);
+    
+    $ldap->cat($this->dn);
+    
+    if($ldap->count()){
+      $ldap->cd($this->dn);
+      $ldap->modify($this->attrs);      
+      $this->handle_post_events("modify");
+    }else{
+      $ldap->cd ($this->config->current['BASE']);
+      $ldap->create_missing_trees($this->dn);
+      $ldap->cd($this->dn);
+      $ldap->add($this->attrs);
+      $this->handle_post_events("add");
+    }
+  }
+
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/systems/class_servRepositorySetup.inc b/plugins/admin/systems/class_servRepositorySetup.inc
new file mode 100644 (file)
index 0000000..2fa8a7c
--- /dev/null
@@ -0,0 +1,153 @@
+<?php
+
+class servRepositorySetup  extends plugin
+{
+  /* CLI vars */
+  var $cli_summary        = "Manage FAI repositories";
+  var $cli_description    = "Some longer text\nfor help";
+  var $cli_parameters     = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+
+  /* attribute list for save action */
+  var $ignore_account   = TRUE;
+  var $attributes       = array("Release","ParentServer","Url");
+  var $objectclasses    = array("whatever");
+
+  /* Attributes */
+  var $Release;
+  var $ParentServer;
+  var $Url;
+  var $Sections=array();
+  var $ParentServers;
+
+  var $initialy_was=false;
+
+  function servRepositorySetup ($config, $dn= NULL,$data = false)
+  {
+    plugin::plugin ($config, $dn);
+    if($data != false){
+      $this->Sections= $data['Sections'];
+      $this->Url= $data['Url'];
+      $this->Release= $data['Release'];
+      $this->ParentServer= $data['ParentServer'];
+      if(isset($data['initialy_was'])){
+        $this->initialy_was= $data['initialy_was'];
+      }
+    }
+  }
+
+  function GetName()
+  {
+    return($this->Release);
+  }
+  
+  function is_new_name()
+  {
+    if(!$this->initialy_was){
+      return(true);
+    }else{
+      if($this->Release != $this->initialy_was){
+        return(true);
+      }
+    }
+    return(false);
+  }
+
+  
+
+  function execute()
+  {
+    /* Call parent execute */
+    plugin::execute();
+
+    /* Fill templating stuff */
+    $smarty= get_smarty();
+
+    if((isset($_POST['AddSection']))&&(isset($_POST['SectionName']))&&(!empty($_POST['SectionName']))){
+      $this->Sections[$_POST['SectionName']]=$_POST['SectionName'];
+    }
+    
+    foreach($_POST as $name => $value){
+      if(preg_match("/^delete_/",$name)){
+        if(isset($this->Sections[$value])){
+          unset($this->Sections[$value]);
+        }
+      }
+    }
+
+    $divlist = new divSelectBox("servRepositorySetup");
+    $divlist->setHeight("120");
+
+    $dellink = "<input type='image' src='images/edittrash.png' title='delete' alt='delete' name='delete_%s' value='%s'>";
+
+    foreach($this->Sections as $sec){
+      $divlist->AddEntry(array(
+                              array("string"=>$sec),
+                              array("string"=>sprintf($dellink,$sec,$sec),"attach"=>"style='border-right:0px;width:20px;'")
+                              ));
+    }
+  
+    $smarty->assign("Sections",$divlist->DrawList());
+
+    foreach($this->attributes as $attr){
+      $smarty->assign($attr       ,$this->$attr);
+      $smarty->assign($attr."ACL" ,chkacl($this->acl,$attr));
+    }
+
+    $smarty->assign("ParentServers"   ,$this->getParentServers());
+    $smarty->assign("ParentServerKeys",array_flip($this->getParentServers()));
+
+    return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
+  }
+
+  /* Save data to object */
+  function save_object()
+  {
+    plugin::save_object();
+  }
+
+
+  /* Check supplied data */
+  function check()
+  {
+    $message= array();
+
+    if(!isset($this->Release)){
+      $message[]=_("Please enter a value for 'release'.");
+    }
+
+    return ($message);
+  }
+
+
+  /* Save to LDAP */
+  function save()
+  {
+    $tmp = array();
+    $tmp['ParentServer']  = $this->ParentServer;
+    $tmp['Url']           = $this->Url;
+    $tmp['Release']       = $this->Release;
+    $tmp['Sections']      = $this->Sections;
+    return($tmp);
+  }
+
+  function getParentServers()
+  {
+
+    $ret = array();
+    
+    $ldap = $this->config->get_ldap_link();
+        
+    $ldap->cd($this->config->current['BASE']);
+    
+    $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
+    while($attr = $ldap->fetch()){
+      $ret[$attr['cn'][0]]= $attr['cn'][0];   
+    }
+    $ret['none']=_("Master");
+    return($ret);
+  }
+
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/admin/systems/servRepository.tpl b/plugins/admin/systems/servRepository.tpl
new file mode 100644 (file)
index 0000000..4453b44
--- /dev/null
@@ -0,0 +1,48 @@
+<table summary="" style="width:100%; vertical-align:top; text-align:left;" cellpadding=4>
+       <tr>
+               <td style="vertical-align:top;" width="50%">
+   
+                       <div class="contentboxh" style="width:610px; height:20px;">
+                       <p class="contentboxh" style="font-size:12px">
+                               <b>{t}Repositories{/t}</b>
+                       </p>
+                       </div>
+
+                       <div class="contentboxb">
+                               <p class="contentboxb" style="border-top:1px solid #B0B0B0;background-color:#F8F8F8">
+                                       {$Repositories}
+                                       <input type="submit" value="{t}Add{/t}" name="AddRepository">
+                               </p>
+                       </div>
+
+               </td>
+
+               <td style="vertical-align:top;">
+                       <div class="contentboxh" style="height:20px;">
+                       <p class="contentboxh" style="font-size:12px">
+                                       <img src="{$launchimage}" align="right" alt="[F]">
+                                       <b>{t}Filters{/t}</b>
+                               </p>
+                       </div>
+
+                       <div class="contentboxb" style="border-top:1px solid #B0B0B0;background-color:#F8F8F8">
+                               <table summary="" style="width:100%;">
+                                       {$alphabet}
+                               </table>
+               
+                               <table summary="" width="100%" style="border-top:1px solid #B0B0B0;background-color:#F8F8F8">
+                                       <tr>
+                                               <td width="50%">
+                                                       <img alt="" src="{$search_image}" align=middle>&nbsp;{t}Display groups of user{/t}
+                                               </td>
+                                               <td>
+                                                       <input type='text' name='regex' maxlength='20' value='{$regex}' 
+                                                               title='{t}Search filter{/t}' onChange="mainform.submit()">
+                                               </td>
+                                       </tr>
+                               </table>
+                               {$apply}
+                       </div>
+               </td>
+       </tr>
+</table>
diff --git a/plugins/admin/systems/servRepositorySetup.tpl b/plugins/admin/systems/servRepositorySetup.tpl
new file mode 100644 (file)
index 0000000..fb39b0e
--- /dev/null
@@ -0,0 +1,46 @@
+<h2><img src="images/fai_small.png" >&nbsp;{t}Repository{/t}</h2>
+
+<table width="100%">
+       <tr>
+               <td width="50%" valign="top">
+                       <table>
+                               <tr>
+                                       <td>{t}Release{/t} :
+                                       </td>
+                                       <td>
+                                               <input type="text" value="{$Release}" name="Release" {$ReleaseACL}>
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}Parent server{/t} :
+                                       </td>
+                                       <td>
+                                               <select name="ParentServer" {$ParentServerACL}>
+                                                       {html_options options=$ParentServers values=$ParentServerKeys selected=$ParentServer} 
+                                               </select>
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}Url{/t} :
+                                       </td>
+                                       <td>
+                                               <input type="text" value="{$Url}" name="Url" {$UrlACL}>
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+               <td>
+                       {t}Sections{/t} :<br>
+                       {$Sections}
+                       <input type="text"              name="SectionName" value="">
+                       <input type="submit"    name="AddSection"  value="{t}Add{/t}">
+               </td>
+       </tr>
+</table>
+<p class="plugbottom">
+  <input type=submit name="repository_setup_save" value="{t}Save{/t}">
+  &nbsp;
+  <input type=submit name="repository_setup_cancel" value="{t}Cancel{/t}">
+</p>
+
+