Code

Added acls to mimetype
[gosa.git] / plugins / admin / applications / class_applicationGeneric.inc
index da52cb304ad45e052debdf21e503bc5bcdbb950e..c483bb97d3e71f8fb6338caed3e79767b3e5e848 100644 (file)
@@ -110,6 +110,17 @@ class application extends plugin
 
     $smarty= get_smarty();
 
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translation){
+      $smarty->assign($name."ACL",$this->getacl($name));
+    }
+    $baseACL = $this->getacl("base");
+    if(!$this->acl_is_moveable()) {
+      $baseACL = preg_replace("/w/","",$baseACL);
+    }
+    $smarty->assign("baseACL",          $baseACL);
+
     /* Do we represent a valid group? */
     if (!$this->is_account && $this->parent == NULL){
       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
@@ -117,6 +128,22 @@ class application extends plugin
       return ($display);
     }
 
+    /* Download requested */
+    foreach($_POST as $name => $value){
+      if(preg_match("/^downloadScript/",$name)){
+        $_SESSION['binary']       = $this->gotoLogonScript;
+        $_SESSION['binarytype']   = "octet-stream";
+        $_SESSION['binaryfile']   = $this->cn.".gosaApplication";
+        header("location: getbin.php ");
+        exit();
+      }
+    }
+
+    /* Reassign picture data, sometimes its corrupt cause we started a download of application scripts */
+    $_SESSION['binary']     = $this->iconData;
+    $_SESSION['binarytype'] = "image/jpeg";
+    
+    $smarty->assign("rand", rand(0, 10000));
     $head = $this->generateTemplate();
     $this->gotoLogonScript= $this->generateTemplate().preg_replace('/.*### END HEADER ###/s', '', $this->gotoLogonScript);
 
@@ -135,6 +162,31 @@ class application extends plugin
       $smarty->assign("namemode", "readonly");
       $smarty->assign("selectmode", "disabled");
     }
+    
+    /* 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->dialog->setCurrentBase($this->base);
+      }
+    }
+
+    /* 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()){
+        $this->base = $this->dialog->isSelected();
+        $this->dialog= false;
+      }else{
+        return($this->dialog->execute());
+      }
+    }
 
     /* Get random number for pictures */
     srand((double)microtime()*1000000);
@@ -143,7 +195,6 @@ class application extends plugin
     /* Variables */
     foreach(array("description", "gosaApplicationExecute", "gosaApplicationName","cn") as $val){
       $smarty->assign($val, $this->$val);
-      $smarty->assign($val."ACL", chkacl($this->acl, $val));
     }
 
     /* Checkboxes */
@@ -160,7 +211,6 @@ class application extends plugin
     $smarty->assign("isReleaseApplikation" , $this->isReleaseApplikation);
     $smarty->assign("gotoLogonScript",htmlentities($this->gotoLogonScript, ENT_COMPAT, 'UTF-8'));
     $smarty->assign("base_select", $this->base);
-    $smarty->assign("gosaApplicationFlagsACL", chkacl($this->acl, "gosaApplicationFlags"));
     /* Show main page */
     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
   }
@@ -170,6 +220,7 @@ class application extends plugin
   {
     $ldap= $this->config->get_ldap_link();
     $ldap->rmDir($this->dn);
+    show_ldap_error($ldap->get_error(), sprintf(_("Removing of application with dn '%s' failed."),$this->dn));
 
     /* Optionally execute a command after we're done */
     $this->handle_post_events("remove");
@@ -181,12 +232,14 @@ class application extends plugin
       $og= new ogroup($this->config, $ldap->getDN());
       unset($og->member[$this->dn]);
       $og->save ();
+      show_ldap_error($ldap->get_error(), sprintf(_("Removing application from objectgroup '%s' failed"), $og->dn));
     }
     $ldap->search ("(&(objectClass=posixGroup)(gosaMemberApplication=".$this->cn."))", array("cn"));
     while ($attrs= $ldap->fetch()){
       $ag= new appgroup($this->config, $ldap->getDN());
       $ag->removeApp($this->cn);
       $ag->save ();
+      show_ldap_error($ldap->get_error(), sprintf(_("Removing application from group '%s' failed"), $ag->dn));
     }
 
   }
@@ -221,7 +274,7 @@ class application extends plugin
       if (isset($_POST['overwrite_config']) && $_POST['overwrite_config'] == 1){
         $flag.= "O";
       }
-      if (chkacl ($this->acl, "gosaApplicationFlags") ==""){
+      if ($this->acl_is_writeable("gosaApplicationFlags")){
         $this->gosaApplicationFlags= "[$flag]";
       }
 
@@ -284,11 +337,7 @@ class application extends plugin
         $this->set_picture($_FILES['picture_file']['tmp_name']);
       }        
 
-
-      /* Save base, since this is no LDAP attribute */
-      if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
-        $this->base= $_POST['base'];
-      }
+      $this->base= $_POST['base'];
     }
 
     if($this->isReleaseApplikation){
@@ -315,9 +364,7 @@ class application extends plugin
     }
 
     $ui= get_userinfo();
-    $acl= get_permissions ($new_dn, $ui->subtreeACL);
-    $acl= get_module_permission($acl, "application", $new_dn);
-    if (chkacl($acl, "create") != ""){
+    if (!$this->acl_is_createable() && $this->dn == "new"){
       $message[]= _("You have no permissions to create a application on this 'Base'.");
     }
 
@@ -365,27 +412,42 @@ class application extends plugin
   /* Save to LDAP */
   function save()
   {
+    /* Get application script without header part, to check if we must save the script itself */
+    $script = preg_replace('/.*### END HEADER ###/s', '', $this->gotoLogonScript);
+
     plugin::save();
     $this->attrs["gosaApplicationIcon"]= $this->gosaApplicationIcon;
 
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
-    $ldap->cat($this->dn);
+    $ldap->cat($this->dn, array('dn'));
 
     $a= $ldap->fetch();
     if (count($a)){
+
+      /* Remove gotoLogonScript if it is empty */
+      if(empty($script))    {
+        $this->attrs['gotoLogonScript'] = array();
+      }
+
       $ldap->cd($this->dn);
       $this->cleanup();
       $ldap->modify ($this->attrs); 
       $this->handle_post_events("modify");
     } else {
+      
+      /* Remove gotoLogonScript if it is empty */
+      if(empty($script))    {
+        unset($this->attrs['gotoLogonScript']);
+      }
+
       $ldap->cd($this->config->current['BASE']);
       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
       $ldap->cd($this->dn);
       $ldap->add($this->attrs);
       $this->handle_post_events("add");
     }
-    show_ldap_error($ldap->get_error());
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of application with dn '%s' failed."),$this->dn));
   }
 
   function set_picture($filename)
@@ -435,6 +497,38 @@ class application extends plugin
       $this->cn = $_POST['cn'];
     }
   }
+
+
+  /* Return plugin informations for acl handling
+      #FIXME FAIscript seams to ununsed within this class... */
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Generic"),
+          "plDescription" => _("Application generic"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 0,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("application" => array("description"  => _("Application"),
+                                                          "objectClass"  => "gosaApplication")),
+          "plProvidedAcls"=> array(
+            "cn"                => _("Name"),
+            "base"              => _("Base"),
+            "description"       => _("Description"),
+            "gosaApplicationExecute"  => _("Execute"),
+            "gosaApplicationName"     => _("Name"),
+            "gosaApplicationIcon"     => _("Icon"),
+            "gosaApplicationFlags"    => _("Flag"),
+            "gotoLogonScript"         => _("Script content"),
+
+            "exec_for_groupmembers" => _("Only executable for members"),              // G
+            "place_on_desktop"      => _("Place icon on members desktop"),            // D
+            "place_on_kicker"       => _("Place entry in members launch bar"),        // L
+            "place_in_startmenu"    => _("Place entry in members startmenu"),         // M
+            "overwrite_config"      => _("Replace user configuration on startup"))  // O
+            ));
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>