Code

Updated template
[gosa.git] / gosa-plugins / goto / admin / mimetypes / class_mimetypeGeneric.inc
index f5cb4d0aad5278ecfc7f5b429c34332211d3dd6a..7ca7c32309f39c019234fc9e783e8755bac63ece 100644 (file)
@@ -37,6 +37,8 @@ class mimetype extends plugin
   var $DivApps                                                             = NULL;
   var $DivEApps                                                                    = NULL;
 
+  var $FAIstate ="";
+
   /* These vars will be copied too, if you use copy&paste mode */
   var $CopyPasteVars        = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData",
                                     "gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q","use_gotoMimeIcon");
@@ -51,6 +53,8 @@ class mimetype extends plugin
   var $orig_dn                 = "";
   var $orig_base         = "";
 
+  var $baseSelector;
+
   function mimetype(&$config,$dn= NULL)
   {
     plugin::plugin ($config, $dn);
@@ -104,7 +108,7 @@ class mimetype extends plugin
         $tmp = array();
         for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
           $str = $this->attrs[$attr][$i];
-          $tmp2= split("\|",$str);
+          $tmp2= explode("|",$str);
 
           if(count($tmp2) == 2){
             $name = $tmp2[0];
@@ -127,7 +131,7 @@ class mimetype extends plugin
         $this->base= dn2base($ui->dn);
       }
     } else {
-      $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
+      $this->base= preg_replace ("/^.*,".preg_quote(get_ou("mimetypeRDN"), '/')."/i", "", $this->dn);
     }
 
     /* Get icon data */
@@ -141,14 +145,60 @@ class mimetype extends plugin
     }
     session::set('binary',$this->iconData);
     session::set('binarytype',"image/jpeg");
+
+    /* Instanciate base selector */
+    $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
+    $this->baseSelector->setSubmitButton(false);
+    $this->baseSelector->setHeight(300);
+    $this->baseSelector->update(true);
+
     $this->orig_base = $this->base;
+
+
+    // Prepare lists
+    $this->patternList = new sortableListing(array(),array(),TRUE);
+    $this->patternList->setDeleteable(true);
+    $this->patternList->setInstantDelete(true);
+    $this->patternList->setEditable(false);
+    $this->patternList->setWidth("100%");
+    $this->patternList->setHeight("100px");
+    $this->patternList->setColspecs(array('200px','*'));
+    $this->patternList->setHeader(array(_("Section"),_("Description")));
+    $this->patternList->setDefaultSortColumn(1);
+    $this->patternList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
+
+    $this->applicationList = new sortableListing(array(),array(),TRUE);
+    $this->applicationList->setDeleteable(true);
+    $this->applicationList->setEditable(false);
+    $this->applicationList->setWidth("100%");
+    $this->applicationList->setHeight("100px");
+    $this->applicationList->setColspecs(array('200px','*'));
+    $this->applicationList->setHeader(array(_("Section"),_("Description")));
+    $this->applicationList->setInstantDelete(true);
+    $this->applicationList->setDefaultSortColumn(1);
+    $this->applicationList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
+
+    $this->embeddedList = new sortableListing(array(),array(),TRUE);
+    $this->embeddedList->setDeleteable(true);
+    $this->embeddedList->setEditable(false);
+    $this->embeddedList->setWidth("100%");
+    $this->embeddedList->setInstantDelete(true);
+    $this->embeddedList->setHeight("100px");
+    $this->embeddedList->setColspecs(array('200px','*'));
+    $this->embeddedList->setHeader(array(_("Section"),_("Description")));
+    $this->embeddedList->setDefaultSortColumn(1);
+    $this->embeddedList->setAcl('rwcdm'); // All ACLs, we filter on our own here.
   }
 
 
   function execute()
   {
+    plugin::execute();
     $smarty = get_smarty();
 
+    /* Assign base ACL */
+    $smarty->assign("base", $this->baseSelector->render());
+
     if(!$this->view_logged){
       $this->view_logged =TRUE;
       new log("view","mimetypes/".get_class($this),$this->dn);
@@ -156,197 +206,106 @@ class mimetype extends plugin
 
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translation){
-      $smarty->assign($name."ACL",$this->getacl($name));
-    }
-
-    /* Base select dialog */
-    $once = true;
-    foreach($_POST as $name => $value){
-      if(preg_match("/^chooseBase/",$name) && $once){
-        $once = false;
-        $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
-        $this->dialog->setCurrentBase($this->base);
-      }
+      $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/i",$this->FAIstate)));
     }
-
-    /* Dialog handling */
-    if(is_object($this->dialog)){
-
-      /* Must be called before save_object */
-      $this->dialog->save_object();
-
-      if($this->dialog->isClosed()){
-        $this->dialog = false;
-      }elseif($this->dialog->isSelected()){
-
-        /* A new base was selected, check if it is a valid one */
-        $tmp = $this->get_allowed_bases();
-        if(isset($tmp[$this->dialog->isSelected()])){
-          $this->base = $this->dialog->isSelected();
-        }
-
-        $this->dialog= false;
-      }else{
-        return($this->dialog->execute());
-      }
-    }
-
-    /* Check Posts */
-    $posts = array(    
-        "/^Pattern_SortUp_/"   => array("Action" => "Pattern_SortUp",  "Func" => "ArrayUp",    "Attr" => "use_gotoMimeFilePattern"),
-        "/^Pattern_SortDown_/"         => array("Action" => "Pattern_SortDown","Func" => "ArrayDown",  "Attr" => "use_gotoMimeFilePattern"),
-        "/^Pattern_Remove_/"   => array("Action" => "Pattern_Remove",  "Func" => "ArrayRemove","Attr" => "use_gotoMimeFilePattern"),
-        "/^Apps_SortUp_/"              => array("Action" => "Apps_SortUp",             "Func" => "ArrayUp",    "Attr" => "use_gotoMimeApplication"),
-        "/^Apps_SortDown_/"    => array("Action" => "Apps_SortDown",   "Func" => "ArrayDown",  "Attr" => "use_gotoMimeApplication"),
-        "/^Apps_Remove_/"              => array("Action" => "Apps_Remove",             "Func" => "ArrayRemove","Attr" => "use_gotoMimeApplication"),
-        "/^EApps_SortUp_/"             => array("Action" => "EApps_SortUp",    "Func" => "ArrayUp",    "Attr" => "use_gotoMimeEmbeddedApplication"),
-        "/^EApps_SortDown_/"   => array("Action" => "EApps_SortDown",  "Func" => "ArrayDown",  "Attr" => "use_gotoMimeEmbeddedApplication"),
-        "/^EApps_Remove_/"             => array("Action" => "EApps_Remove",    "Func" => "ArrayRemove","Attr" => "use_gotoMimeEmbeddedApplication"));          
-    $once = true;
+    $smarty->assign("IconReadable", preg_match("/r/",$this->getacl("gotoMimeIcon",preg_match("/freeze/i",$this->FAIstate))));
 
     /* Walk through posts and try to find some commands for us. */
-    foreach($_POST as $name => $value){
-
-      /* Walk through possible commands */
-      foreach($posts as $regex => $action){
-
-        /* Check if there is a command posted */
-        if(preg_match($regex,$name) && $once){
-          $once = false;
-
-          /* Get action vars */
-          $func                = $action['Func'];              // Get function name 
-          $attr                = $action['Attr'];              // Get attribute name
-
-          /* Get entry id */
-          $s_entry     = preg_replace($regex,"",$name);
-          $s_entry     = preg_replace("/_[xy]$/","",$s_entry); 
-
-          /* Execute a command with the given attribute and entry 
-             e.g. $this->gotoMimeFilePattern = $this->ArrayUp(3,$this->gotoMimeFilePattern) */
-          if($this->acl_is_writeable($attr)){
-            $this->$attr= $this->$func($s_entry,$this->$attr,true);                                     
-          }
-        }
-      }
-    }
-
-    /* Set a new icon was requested */
-    if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
-      $this->set_new_picture($_FILES['picture_file']['tmp_name']);             
-    }
-
-    /* Add gotoMimeFilePattern */
-    if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
-      if($this->acl_is_writeable("gotoMimeFilePattern")){
-        $str = $_POST['NewFilePattern'];
-        if(!empty($str)){
-          $this->use_gotoMimeFilePattern[] = $str;
-        }
-      }
-    }  
+    if(!preg_match("/freeze/i",$this->FAIstate)){
 
-    /* Add gotoMimeFilePattern */
-    if(isset($_POST['AddNewApplication']) && 
-            (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
-      if($this->acl_is_writeable("gotoMimeApplication")){
-        $str = "";
-        if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
-          $str = get_post("NewApplicationSelect");
-        }
-        if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
-          $str = get_post("NewApplication");
-        }
-        if(!empty($str) && !in_array($str,$this->use_gotoMimeApplication)){
-          $this->use_gotoMimeApplication[] = $str;
-        }
+      /* Set a new icon was requested */
+      if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
+        $this->set_new_picture($_FILES['picture_file']['tmp_name']);           
       }
-    }  
 
-    /* Add embedded application 
-     *  - From input or from select box 
-     */
-    if(isset($_POST['AddNewEmbeddedApplication']) && 
-            (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
-      if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
-        $str = "";
-        if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
-          $str = get_post('NewEmbeddedApplicationSelect');
+      /* Add gotoMimeFilePattern */
+      if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
+        if($this->acl_is_writeable("gotoMimeFilePattern")){
+          $str = trim($_POST['NewFilePattern']);
+          if($str != ""){
+            $this->use_gotoMimeFilePattern[] = $str;
+          }
         }
-        if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
-          $str = get_post('NewEmbeddedApplication');
+      }        
+
+      /* Add gotoMimeFilePattern */
+      if(isset($_POST['AddNewApplication']) && 
+          (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
+        if($this->acl_is_writeable("gotoMimeApplication")){
+          $str = "";
+          if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
+            $str = trim(get_post("NewApplicationSelect"));
+          }
+          if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
+            $str = trim(get_post("NewApplication"));
+          }
+          if($str != "" && !in_array($str,$this->use_gotoMimeApplication)){
+            $this->use_gotoMimeApplication[] = $str;
+          }
         }
-        if(!empty($str) && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
-          $this->use_gotoMimeEmbeddedApplication[] = $str;
+      }        
+
+      /* Add embedded application 
+       *  - From input or from select box 
+       */
+      if(isset($_POST['AddNewEmbeddedApplication']) && 
+          (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
+        if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
+          $str = "";
+          if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
+            $str = trim(get_post('NewEmbeddedApplicationSelect'));
+          }
+          if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
+            $str = trim(get_post('NewEmbeddedApplication'));
+          }
+          if($str != "" && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
+            $this->use_gotoMimeEmbeddedApplication[] = $str;
+          }
         }
-      }
+      }        
     }  
 
-    /* Create divlists */
-    $DivPatterns       = new divSelectBox("gotoMimePatterns");
-    $DivApps           = new divSelectBox("gotoMimeApplications");
-    $DivEApps          = new divSelectBox("gotoMimeEmbeddedApplications");
-    $DivPatterns       -> SetHeight(100);
-    $DivApps           -> SetHeight(100);
-    $DivEApps          -> SetHeight(100);
+    // Set list acls 
+    $this->patternList->setAcl($this->getacl("gotoMimeFilePattern", 
+                preg_match("/freeze/i",$this->FAIstate)));
+    $this->applicationList->setAcl($this->getacl("gotoMimeApplication",
+                preg_match("/freeze/i",$this->FAIstate)));
+    $this->embeddedList->setAcl($this->getacl("gotoMimeEmbeddedApplication",
+                preg_match("/freeze/i",$this->FAIstate)));
 
 
-    if($this->acl_is_writeable("gotoMimeFilePattern")){
-      $Pattern_Actions= " <input type='image' src='images/lists/sort-up.png'   class='center'  name='Pattern_SortUp_%s' >&nbsp;
-      <input type='image' src='images/lists/sort-down.png'     class='center'  name='Pattern_SortDown_%s'>&nbsp;
-      <input type='image' src='images/lists/trash.png' class='center'  name='Pattern_Remove_%s'>";
-    }else{
-      $Pattern_Actions= "";    
-    }
+    /* Before adding some entries check acls */
+    $data = $lData = array();
+    foreach($this->use_gotoMimeFilePattern as $key => $pattern){
+        $data[$key] = $pattern;
+        $lData[$key] = array('data'=>array($pattern));
+    }                  
+    $this->patternList->setListData($data, $lData);
+    $this->patternList->update();
 
-    if($this->acl_is_writeable("gotoMimeApplication")){
-      $Apps_Actions    = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='Apps_SortUp_%s' >&nbsp;
-      <input type='image' src='images/lists/sort-down.png'     class='center'  name='Apps_SortDown_%s'>&nbsp;
-      <input type='image' src='images/lists/trash.png' class='center'  name='Apps_Remove_%s'>";
-    }else{
-      $Apps_Actions= "";       
-    }
+    $data = $lData = array();
+    foreach($this->use_gotoMimeApplication as $key => $pattern){
+        $data[$key] = $pattern;
+        $lData[$key] = array('data'=>array($pattern));
+    }                  
+    $this->applicationList->setListData($data, $lData);
+    $this->applicationList->update();
 
-    if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
-      $EApps_Actions   = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='EApps_SortUp_%s' >&nbsp;
-      <input type='image' src='images/lists/sort-down.png'     class='center'  name='EApps_SortDown_%s'>&nbsp;
-      <input type='image' src='images/lists/trash.png' class='center'  name='EApps_Remove_%s'>";
-    }else{
-      $EApps_Actions= "";      
+    $data = $lData = array();
+    foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
+        $data[$key] = $pattern;
+        $lData[$key] = array('data'=>array($pattern));
     }
+    $this->embeddedList->setListData($data, $lData);
+    $this->embeddedList->update();
 
-    /* Before adding some entries check acls */
-    if($this->acl_is_readable("gotoMimeFilePattern")){
-      foreach($this->use_gotoMimeFilePattern as $key => $pattern){
-        $field1 = array("string" => $pattern);
-        $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'");
-        $fields = array($field1,$field2);
-        $DivPatterns -> AddEntry($fields);
-      }                        
-    }
-
-    if($this->acl_is_readable("gotoMimeApplication")){
-      foreach($this->use_gotoMimeApplication as $key => $pattern){
-        $field1 = array("string" => $pattern);
-        $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
-        $fields = array($field1,$field2);
-        $DivApps -> AddEntry($fields);
-      }                        
-    }                  
-    if($this->acl_is_readable("gotoMimeEmbeddedApplication")){
-      foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){
-        $field1 = array("string" => $pattern);
-        $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'");
-        $fields = array($field1,$field2);
-        $DivEApps -> AddEntry($fields);
-      }
-    }                  
+    $smarty->assign("usePrototype", "true");
     $smarty->assign("bases",                                           $this->get_allowed_bases());            
     $smarty->assign("base_select",                                     $this->base);           
     $smarty->assign("isReleaseMimeType",                       $this->is_release());
-    $smarty->assign("gotoMimeFilePatterns",                    $DivPatterns->DrawList());
-    $smarty->assign("gotoMimeApplications",                    $DivApps->DrawList());
-    $smarty->assign("gotoMimeEmbeddedApplications",    $DivEApps->DrawList());
+    $smarty->assign("gotoMimeFilePatterns",                    $this->patternList->render());
+    $smarty->assign("gotoMimeApplications",                    $this->applicationList->render());
+    $smarty->assign("gotoMimeEmbeddedApplications",    $this->embeddedList->render());
 
     $smarty->assign("ApplicationList",$this->ApplicationList);
   
@@ -369,7 +328,25 @@ class mimetype extends plugin
 
   function save_object()
   {
-    if(isset($_POST['MimeGeneric'])){
+      if(isset($_POST['MimeGeneric']) && !preg_match("/freeze/i",$this->FAIstate)){
+        
+          // Act on list actions here
+          $this->patternList->save_object();
+          $this->applicationList->save_object();
+          $this->embeddedList->save_object();
+
+          $action=$this->patternList->getAction();
+          if(in_array($action['action'],array('delete', 'reorder'))){
+              $this->use_gotoMimeFilePattern = array_values($this->patternList->getMaintainedData());
+          }
+          $action=$this->applicationList->getAction();
+          if(in_array($action['action'],array('delete', 'reorder'))){
+              $this->use_gotoMimeApplication = array_values($this->applicationList->getMaintainedData());
+          }
+          $action=$this->embeddedList->getAction();
+          if(in_array($action['action'],array('delete', 'reorder'))){
+              $this->use_gotoMimeEmbeddedApplication = array_values($this->embeddedList->getMaintainedData());
+          }
 
       /* Create a base backup and reset the
          base directly after calling plugin::save_object();
@@ -391,6 +368,17 @@ class mimetype extends plugin
 
       }
 
+      /* Refresh base */
+      if ($this->acl_is_moveable($this->base)){
+        if (!$this->baseSelector->update()) {
+          msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
+        }
+        if ($this->base != $this->baseSelector->getBase()) {
+          $this->base= $this->baseSelector->getBase();
+          $this->is_modified= TRUE;
+        }
+      }
+
       /* Save radio buttons */
       if($this->acl_is_writeable("gotoMimeLeftClickAction")){
         if(isset($_POST['gotoMimeLeftClickAction_IE'])){
@@ -522,13 +510,18 @@ class mimetype extends plugin
   function check()
   {
     $message = plugin::check();
-    if(empty($this->cn)){
+    if($this->cn == "" ){
       $message[] = msgPool::required(_("Name"));
     }
     if(!count($this->use_gotoMimeFilePattern)){
       $message[] = msgPool::required(_("File pattern"));
     }
 
+    // Check if a wrong base was supplied
+    if(!$this->baseSelector->checkLastBaseUpdate()){
+      $message[]= msgPool::check_base();;
+    }
+
     /* Check if there is already a mime type with this cn */
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->config->current["BASE"]);
@@ -536,7 +529,7 @@ class mimetype extends plugin
     if($this->is_release()){
       $base = $this->parent->parent->mime_release;
     }else{
-      $base = get_ou("mimetypeou").$this->base;
+      $base = get_ou("mimetypeRDN").$this->base;
     }
 
     $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$base,array("cn"));
@@ -565,7 +558,7 @@ class mimetype extends plugin
   function set_new_picture($filename)
   {
     if (empty($filename)){
-      $filename= "./images/default_icon.png";
+      $filename= "./plugins/goto/images/default_icon.png";
       $this->use_gotoMimeIcon= "*removed*";
     }else{
       $this->use_gotoMimeIcon= $filename;