Code

Fixed attachment for printer
[gosa.git] / plugins / admin / applications / class_applicationGeneric.inc
index 351d6e458cb1234aa8183e055ddd26173d6a8903..0918b0f031cf82a4d098f4af11b6e6eea0b153f1 100644 (file)
@@ -14,6 +14,7 @@ class application extends plugin
   var $gosaApplicationName= "";
   var $gosaApplicationFlags= "";
   var $gosaApplicationIcon= "";
+  var $gotoLogonScript ="";
   var $iconData;
 
   /* Headpage attributes */
@@ -22,7 +23,7 @@ class application extends plugin
 
   /* attribute list for save action */
   var $attributes= array("cn", "description", "gosaApplicationExecute", "gosaApplicationName",
-                       "gosaApplicationFlags");
+                       "gosaApplicationFlags","gotoLogonScript");
   var $objectclasses= array("top", "gosaApplication");
 
   function application ($config, $dn= NULL)
@@ -37,7 +38,8 @@ class application extends plugin
        if ($this->iconData == ""){
                $this->set_picture("");
        }
-       $_SESSION['picture']= $this->iconData;
+       $_SESSION['binary']= $this->iconData;
+       $_SESSION['binarytype']= "image/jpeg";
        $this->gosaApplicationIcon= $this->iconData;
 
        /* This is always an account */
@@ -55,17 +57,65 @@ class application extends plugin
        }
   }
 
+
+  function generateTemplate(){
+       $str= "# This code is part of GOsa (https://gosa.gonicus.de)\n#\n";
+
+       $values = array();
+       $names  = array();
+       if($this->parent->by_object['applicationParameters']->is_account){
+               $names = $this->parent->by_object['applicationParameters']->option_name;
+               $values = $this->parent->by_object['applicationParameters']->option_value;
+       }
+
+       if (count($names)){
+               $str .="# This plugin handles these environment variables:\n";
+       } else {
+               $str .="# This plugin handles no environment variables.\n";
+       }
+
+       foreach($names as $index => $name){
+
+               // Fix length
+               for($i = strlen($name) ; $i < 30 ; $i++){
+                       $name= $name." ";
+               }
+               if((isset($values[$index]))&&(!empty($values[$index]))){
+                       $str.= "# ".$name."\t(e.g. '".$values[$index]."')\n";
+               }else{
+                       $str.= "# ".$name."\t("._("no example").")\n";
+               }
+       }
+       $str .= "#\n".
+                       "# Don't remove the following tag, it is used for header update.\n".
+                       "### END HEADER ###";
+       return($str);
+  }
+
   function execute()
   {
+       /* Call parent execute */
+       plugin::execute();
+
+       $smarty= get_smarty();
+
        /* Do we represent a valid group? */
        if (!$this->is_account && $this->parent == NULL){
                 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
                         _("This 'dn' is no application.")."</b>";
                 return ($display);
        }
-  
+
+       $head = $this->generateTemplate();
+       $this->gotoLogonScript= $this->generateTemplate().preg_replace('/.*### END HEADER ###/s', '', $this->gotoLogonScript);
+       
+       if((isset($_POST['upLoad']))&&(isset($_FILES['ScriptFile']))){
+               $str = file_get_contents($_FILES['ScriptFile']['tmp_name']);
+               $this->gotoLogonScript = $str;
+       }
        /* Fill templating stuff */
-       $smarty= get_smarty();
        $smarty->assign("cn", $this->cn);
        $smarty->assign("bases", $this->config->idepartments);
        if ($this->dn == "new"){
@@ -81,13 +131,14 @@ class application extends plugin
        $smarty->assign("rand", rand(0, 10000));
 
        /* Variables */
-       foreach(array("description", "gosaApplicationExecute", "gosaApplicationName") as $val){
+       foreach(array("description", "gosaApplicationExecute", "gosaApplicationName","cn") as $val){
                $smarty->assign($val, $this->$val);
                $smarty->assign($val."ACL", chkacl($this->acl, $val));
        }
 
        /* Checkboxes */
        foreach (array("G" => "exec_for_groupmembers", "O" => "overwrite_config",
+                       "L" => "place_on_kicker",
                        "D" => "place_on_desktop", "M" => "place_in_startmenu") as $key => $val){
                if (preg_match("/$key/", $this->gosaApplicationFlags)){
                        $smarty->assign("$val", "checked");
@@ -95,6 +146,7 @@ class application extends plugin
                        $smarty->assign("$val", "");
                }
        }
+       $smarty->assign("gotoLogonScript",$this->gotoLogonScript);
        $smarty->assign("base_select", $this->base);
        $smarty->assign("gosaApplicationFlagsACL", chkacl($this->acl, "gosaApplicationFlags"));
 
@@ -133,6 +185,7 @@ class application extends plugin
   function save_object()
   {
        if (isset($_POST['cn'])){
+       
                plugin::save_object();
 
                /* Save application flags */
@@ -143,6 +196,9 @@ class application extends plugin
                if (isset($_POST['place_on_desktop']) && $_POST['place_on_desktop'] == 1){
                        $flag.= "D";
                }
+               if (isset($_POST['place_on_kicker']) && $_POST['place_on_kicker'] == 1){
+                       $flag.= "L";
+               }
                if (isset($_POST['place_in_startmenu']) && $_POST['place_in_startmenu'] == 1){
                        $flag.= "M";
                }
@@ -244,6 +300,11 @@ class application extends plugin
        if ($this->cn == ""){
                $message[]= _("Required field 'Name' is not filled.");
        }
+
+       if(preg_match("/[^a-z0-9]/",$this->cn)) {
+               $message[]=_("Invalid character in application name. Only a-z 0-9 are allowed.");
+       }
+
        if ($this->gosaApplicationExecute == ""){
                $message[]= _("Required field 'Execute' is not filled.");
        }
@@ -251,7 +312,7 @@ class application extends plugin
        /* Check for existing application */
        $ldap= $this->config->get_ldap_link();
        $ldap->cd($this->config->current["BASE"]);
-       $ldap->search("(&(objectClass=gosaApplication)(cn=$this->cn))");
+       $ldap->search("(&(objectClass=gosaApplication)(cn=$this->cn))",array("cn"));
        $ldap->fetch();
        if ($ldap->count() != 0 && $this->dn == "new"){
                $message[]= _("There's already an application with this 'Name'.");
@@ -295,7 +356,8 @@ class application extends plugin
        if (file_exists($filename)){
                $fd = fopen ($filename, "rb");
                $this->iconData= fread ($fd, filesize ($filename));
-               $_SESSION['picture']= $this->iconData;
+               $_SESSION['binary']= $this->iconData;
+               $_SESSION['binarytype']= "image/jpeg";
                $this->gosaApplicationIcon= $this->iconData;
 
                fclose ($fd);