Code

Added new filterEditor
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 9 Mar 2010 12:02:07 +0000 (12:02 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 9 Mar 2010 12:02:07 +0000 (12:02 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@16360 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/ihtml/themes/modern/filterEditor.tpl [new file with mode: 0644]
gosa-core/ihtml/themes/modern/filterEditorEntry.tpl [new file with mode: 0644]
gosa-core/include/class_filterEditor.inc [new file with mode: 0644]
gosa-core/include/class_filterEditorEntry.inc [new file with mode: 0644]
gosa-core/plugins/personal/myaccount/main.inc

diff --git a/gosa-core/ihtml/themes/modern/filterEditor.tpl b/gosa-core/ihtml/themes/modern/filterEditor.tpl
new file mode 100644 (file)
index 0000000..66c6442
--- /dev/null
@@ -0,0 +1,14 @@
+<h3>{t}Filter editor{/t}</h3>
+
+<hr>
+
+{t}List of configured filters{/t}
+{$list}
+<button type='submit' name='addFilter'>{msgPool type='addButton'}</button>
+
+<hr>
+
+<div class="plugin-actions">
+  <button type='submit' name='saveFilter'>{msgPool type='saveButton'}</button>
+  <button type='submit' name='cancelFilter'>{msgPool type='cancelButton'}</button>
+</div>
diff --git a/gosa-core/ihtml/themes/modern/filterEditorEntry.tpl b/gosa-core/ihtml/themes/modern/filterEditorEntry.tpl
new file mode 100644 (file)
index 0000000..54855f0
--- /dev/null
@@ -0,0 +1,61 @@
+<h3>{t}Filter editor{/t}</h3>
+
+<hr>
+
+<table summary="{t}Filter editor{/t}" width="100%">
+  <tr>
+    <td style='vertical-align: top; width:40%;'>
+      <table summary='{t}Filter properties{/t}'>
+        <tr>
+          <td>
+            <label for='name'>{t}Name{/t}</label>
+          </td>
+          <td>
+            <input type='text' name='name' id='name' value='{$name}'>
+          </td>   
+        </tr>
+        <tr>
+          <td>
+            <label for='description'>{t}Description{/t}</label>
+          </td>
+          <td>
+            <input type='text' name='description' id='description' value='{$description}'>
+          </td>   
+        </tr>
+      </table>  
+    
+      <br>
+      
+      <input type='checkbox' name='shareFilter' value='1' {if $share} checked {/if}>
+       {t}Share this filter with others{/t}              
+    </td>
+    <td style='vertical-align: top;'>
+      <label for='usedCategory'>{t}The categories this filter is displayed for{/t}</label><br>
+      <select id='usedCategory' name='usedCategory[]' size='4' multiple style='width:100%;'>
+        {html_options options=$selectedCategories}
+      </select>
+      <br>
+      <select id='availableCategory' name='availableCategory'
+        onChange="$('manualCategory').value=$('availableCategory').options[$('availableCategory').selectedIndex].value"> 
+        <option value=''>&nbsp;</option>
+        {html_options values=$availableCategories output=$availableCategories}
+      </select>
+      <input type='text' id='manualCategory' name='manualCategory' value=''>
+      <button type='submit' name='addCategory'>{msgPool type='addButton'}</button>
+      <button type='submit' name='delCategory'>{msgPool type='delButton'}</button>
+    </td>
+  </tr>
+</table>
+
+<hr>
+
+<textarea name='filter' id='filter' cols="0" style='width:100%; height: 100px;'>{$filter}</textarea>
+
+<hr>
+
+<input type='hidden' value='1' name='filterEditorEntry'>
+
+<div class="plugin-actions">
+  <button type='submit' name='saveFilterSettings'>{msgPool type='saveButton'}</button>
+  <button type='submit' name='cancelFilterSettings'>{msgPool type='cancelButton'}</button>
+</div>
diff --git a/gosa-core/include/class_filterEditor.inc b/gosa-core/include/class_filterEditor.inc
new file mode 100644 (file)
index 0000000..0cafbb4
--- /dev/null
@@ -0,0 +1,168 @@
+<?php
+
+class filterEditor extends plugin 
+{
+  protected $fitlers = array();
+  protected $availableCategories = array();
+  
+  public $objectClass = array('gosaProperties');
+  public $attributes = array('gosaUserDefinedFilter');
+  public $gosaUserDefinedFilter = array();
+  
+  
+  function __construct($config, $categories)
+  {
+
+    // Initialize this plugin with the users dn to gather user defined filters.
+    $ui = get_userinfo();
+    plugin::plugin($config, $ui->dn);
+
+    // Keep list of currently managed categories.
+    $this->availableCategories = array_unique($categories);
+    $this->availableCategories[] = 'systems';
+    $this->availableCategories[] = 'phones';
+    $this->availableCategories[] = 'printer';
+    $this->availableCategories[] = 'component';
+
+    // Load list of filters
+    if(isset($this->attrs['gosaUserDefinedFilter'])){
+      for($i=0; $i< $this->attrs['gosaUserDefinedFilter']['count']; $i++){
+        list($categories, $name, $description, $filter, $flags) = split(";", $this->attrs['gosaUserDefinedFilter'][$i]);
+        $tmp = array(
+            'name' => $name, 
+            'categories' => split(',', $categories),
+            'description' => base64_decode($description),
+            'filter' => base64_decode($filter),
+            'flags' => split(',',$flags));
+        $this->filters[$name] = $tmp; 
+      }
+    }
+
+    $this->filterWidget= new sortableListing();
+    $this->filterWidget->setDeleteable(true);
+    $this->filterWidget->setEditable(true);
+    $this->filterWidget->setWidth("100%");
+    $this->filterWidget->setHeight("70px");
+    $this->filterWidget->setColspecs(array('100px', '200px', '100px', '70px','150px'));
+    $this->filterWidget->setAcl($ui->get_permissions($ui->dn,'users/user','gosaUserDefinedFilter'));
+    $this->filterWidget->setListData($this->filters, $this->convertFilterList());
+  }
+
+  function convertFilterList()
+  { 
+    $data = array();
+    foreach($this->filters as $name => $filter){
+      $data[$name] = array('data' =>
+          array(
+            $filter['name'],
+            $filter['description'],
+            implode(", ",$filter['categories']),
+            implode(", ",$filter['flags'])));
+    }
+    return($data); 
+  }
+
+  function execute()
+  {
+    plugin::execute();
+
+    // Close edit dialog
+    if(isset($_POST['cancelFilterSettings'])){
+      $this->dialog = NULL;
+    }
+
+    // Close edit dialog
+    if(isset($_POST['saveFilterSettings']) && $this->dialog instanceOf filterEditEntry){
+      $this->dialog->save_object();
+      $msgs = $this->dialog->check();
+      if(count($msgs)){
+        msg_dialog::display_checks($msgs);
+      }else{
+        $orig_name = $this->dialog->getOriginalName();
+        $new_name = $this->dialog->getCurrentName();
+
+        // Remove old entry
+        if($orig_name != "") unset($this->filters[$orig_name]);
+
+        $this->filters[$new_name] = $this->dialog->save();
+        $this->dialog = NULL;
+        $this->filterWidget->setListData($this->filters, $this->convertFilterList());
+        $this->filterWidget->update();
+      }
+    }
+
+    // Act on edit requests 
+    $this->filterWidget->save_object();
+    $action = $this->filterWidget->getAction();
+    if($action['action'] == 'edit' && count($action['targets']) == 1){
+      $key= $this->filterWidget->getKey($action['targets'][0]);
+      if(isset($this->filters[$key])){
+        $this->dialog=new filterEditEntry($this->filters[$key], $this->availableCategories);
+      }
+    }
+
+    // Act add requests
+    if(isset($_POST['addFilter'])){
+      $this->dialog=new filterEditEntry(array(), $this->availableCategories);
+    }
+
+    // Act on remove requests 
+    $action = $this->filterWidget->getAction();
+    if($action['action'] == 'delete' && count($action['targets']) == 1){
+      $key= $this->filterWidget->getKey($action['targets'][0]);
+      if(isset($this->filters[$key])){
+        unset($this->filters[$key]);
+        $this->filterWidget->update();
+      }
+    }
+
+    // Display edit dialog
+    if($this->dialog instanceOf filterEditEntry){
+      $this->dialog->save_object();
+      return($this->dialog->execute());
+    }
+
+
+    $smarty = get_smarty();
+    $smarty->assign("list", $this->filterWidget->render());
+    return($smarty->fetch(get_template_path('filterEditor.tpl', FALSE)));
+  }
+
+  function enabled()
+  {
+    return(count($this->_parent->categories) != 0);
+  }
+
+  function save_object()
+  {
+  
+  }
+
+  function save()
+  {
+    $attrs = array();
+    foreach($this->filters as $filter){
+      $tmp = implode(',', $filter['categories']).";";
+      $tmp.= $filter['name'].";";
+      $tmp.= base64_encode($filter['description']).";";
+      $tmp.= base64_encode($filter['filter']).";";
+      $tmp.= implode(',', $filter['flags']);
+      $attrs[] = $tmp;
+    }
+    $this->gosaUserDefinedFilter = $attrs;
+    plugin::save();
+
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->dn);
+    $ldap->modify($this->attrs);
+    
+    new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MODIFY, get_class()));
+    }
+  }  
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-core/include/class_filterEditorEntry.inc b/gosa-core/include/class_filterEditorEntry.inc
new file mode 100644 (file)
index 0000000..dce7cde
--- /dev/null
@@ -0,0 +1,101 @@
+<?php
+
+class filterEditEntry extends plugin 
+{
+  public $entry = array();
+  public $name = "";
+  public $description = "";
+  public $selectedCategories = array();
+  public $share = FALSE;
+  public $filter = "(objectClass=*)";
+
+  public $availableCategories = array();
+  public $orig_name = "";
+
+  function __construct($entry, $categories)
+  {
+    $this->availableCategories = $categories;
+    if($entry){
+      $this->entry = $entry;
+      $this->name = $entry['name'];
+      $this->description = $entry['description'];
+      $this->selectedCategories = $entry['categories'];
+      $this->filter = $entry['filter'];
+      $this->share = in_array("share",$entry['flags']);
+    }
+
+    $this->orig_name = $this->name;
+  }
+
+  function getOriginalName()
+  {
+    return($this->orig_name);
+  }
+
+  function getCurrentName()
+  {
+    return($this->name);
+  }
+
+  function execute()
+  {
+    plugin::execute();
+    $smarty = get_smarty();
+    $smarty->assign('name', $this->name);
+    $smarty->assign('filter', $this->filter);
+    $smarty->assign('share', $this->share);
+    $smarty->assign('description', $this->description);
+    $smarty->assign('selectedCategories', $this->selectedCategories);
+    $smarty->assign('availableCategories', $this->availableCategories);
+    return($smarty->fetch(get_template_path('filterEditorEntry.tpl', FALSE)));
+  }
+
+  function save_object()
+  {
+    if(isset($_POST['filterEditorEntry'])){
+
+      // Get posted strings
+      foreach(array('name','description','filter') as $attr){
+        if(isset($_POST[$attr])){
+          $this->$attr = get_post($attr);
+        }
+      }
+
+      // Get posted flags 
+      $this->share = isset($_POST['shareFilter']);
+
+      // Get additional category  
+      if(isset($_POST['addCategory'])){
+        if(isset($_POST['manualCategory']) && !empty($_POST['manualCategory'])){
+          $this->selectedCategories[] = get_post('manualCategory');
+        }elseif(isset($_POST['availableCategory']) && !empty($_POST['availableCategory'])){
+          $this->selectedCategories[] = get_post('availableCategory');
+        }
+      }
+
+      // Remove categories
+      if(isset($_POST['delCategory']) && isset($_POST['usedCategory'])){
+        foreach($_POST['usedCategory'] as $cat){
+          if(isset($this->selectedCategories[$cat])) unset($this->selectedCategories[$cat]);
+        }
+      }
+    }
+  }
+
+  function save()
+  {
+    $ret= array();
+    $ret['name'] = $this->name;
+    $ret['description'] = $this->description;
+    $ret['categories'] = $this->selectedCategories;
+    $ret['filter'] = $this->filter;
+    $ret['flags'] = array();
+    if($this->share){
+      $ret['flags'][] = "share";
+    }
+    return($ret);
+  }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index 142defd53f632090a99d613a38875060b3d17559..4854e5a8001cfb19779181f832a3a70eb00f360f 100644 (file)
@@ -111,7 +111,7 @@ if (! $cleanup ){
       $display.= "<button class='button' type='submit' name='edit_finish'>".msgPool::okButton()."</button>\n";
       $display.= "<button class='button' type='submit' name='edit_cancel'>".msgPool::cancelButton()."</button>\n";
     } else {
-      if(preg_match("/r/",$ui->get_permissions($ui->dn,"users/MyAccountTabs"))){
+      if(preg_match("/r/",$ui->get_category_permissions($ui->dn,"users"))){
         $display.= "<button class='button' type='submit' name='edit'>".msgPool::editButton()."</button>\n";
       }
       $display.= "<input type='hidden' name='ignore'>\n";