Code

Updated gotoLpdEnable Dialog.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 8 Oct 2008 10:48:02 +0000 (10:48 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 8 Oct 2008 10:48:02 +0000 (10:48 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12626 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/class_gotoLpdEnabled.inc
gosa-plugins/goto/admin/systems/goto/class_workstationService.inc
gosa-plugins/goto/admin/systems/goto/gotoLpdEnable.tpl
gosa-plugins/goto/admin/systems/goto/workstationService.tpl

index 6f83bda3a76cda643bb9219af6b0f6462707794e..7c25d92c3a8e2c3fce9a0fc1d46677b9660620c5 100644 (file)
@@ -4,42 +4,210 @@ class gotoLpdEnable extends plugin
 {
        public $parent;
 
-  protected $device   = "";
-  protected $port     = "";
-  protected $options  = "";
-  protected $writeonly= FALSE;
+  protected $DevID = 0;
+  private $data = array();
+  private $default_entry = array();
 
-  public    $attributes = array("device","port","options","writeonly");
+  protected $s_Type = "USB";
+  protected $s_Device = "/dev/usb/lp";
+  protected $i_Port = 9100;   
+  protected $s_Options = "";
+  protected $s_WriteOnly = "Y";
+
+  protected $s_Speed = 9600;
+  protected $s_FlowControl = "S";
+  protected $s_Parity = "E";
+  protected $i_Bit = 5;
+
+  /* Option predefinition */
+  private $a_Types = array();
+  private $a_Boolean = array();
+  private $a_FlowControls = array(); //  
+  private $a_Parities = array();    //  
+  private $a_Speeds = array();      // 
+  private $a_Bits = array();        //
+  private $a_Devices = array();
+
+  public    $attributes = array("s_Type","s_Device","i_Port","s_Options","s_WriteOnly",
+      "s_Speed","s_FlowControl","s_Parity","i_Bit");
 
        public function __construct($config,$data,&$parent)
        {
                plugin::plugin($config,NULL);
-    
                $this->parent = $parent;
-       }
+    $this->DevID = 0;
+
+    /****
+      Predefine values 
+     ****/ 
+    $this->a_Types = array(
+        "USB" => _("USB"),
+        "Parallel" => _("Parallel port"),
+        "Serial" => _("Serial"));
+    $this->a_Boolean = array(
+        "Y" => _("Yes"),
+        "N" => _("No"));
+    $this->a_FlowControl = array(
+        "S" => _("Software"),
+        "H" => _("Hardware"));
+    $this->a_Parities = array(
+        "E"  => _("Even"),
+        "O"  => _("Odd"),
+        "N"  => _("None"));
+    $this->a_Speeds = array(
+        "4800"  => "4.800&nbsp;"._("bit/s"),
+        "9600"  => "9.600&nbsp;"._("bit/s"),
+        "19200" => "19.200&nbsp;"._("bit/s"),
+        "38400" => "38.400&nbsp;"._("bit/s"),
+        "57600" => "57.600&nbsp;"._("bit/s"),
+        "115200"=> "115.200&nbsp;"._("bit/s"),
+        "230400"=> "230.400&nbsp;"._("bit/s"),
+        "460800"=> "460.800&nbsp;"._("bit/s"));
+    $this->a_Bits = array(
+        5,6,7,8);
+    $this->a_Devices = array(
+        "USB" => "/dev/usb/lp",
+        "Parallel" => "/dev/lp",
+        "Serial" => "/dev/ttyS");
+
+    /* Create default entry 
+     */
+    foreach($this->attributes as $attr){
+      $this->default_entry[$attr] = $this->$attr;
+    }
+
+    /* Load current settings 
+     */
+    if(count($data) == 0){
+      $this->is_account = FALSE;
+    }else{
+      $this->is_account = TRUE;
+      foreach($data as $dat){
+        list($s_Type,$s_Device,$i_Port,$s_Speed,$s_FlowControl,$s_Parity,$i_Bit,$s_WriteOnly,$s_Options) = split("\:",$dat);
+        $entry = array();
+        foreach($this->attributes as $attr){
+          $entry[$attr] = $$attr;
+        }
+        $this->data[] = $entry;
+      }
+
+      /* Set first entry values 
+       */
+      foreach($this->attributes as $attr){
+        $this->$attr = $this->data[$this->DevID][$attr];
+      }
+    }
+    $this->initially_was_account = $this->is_account;
+  }
 
        public function execute()
        {
-               $smarty = get_smarty();
-
-    $smarty->assign("devices",array(
-          "USB"       => _("USB"),
-          "PARALLEL"  => _("Parallel"),
-          "SERIAL"    => _("Serial")));
+    $display = "";
+    if(isset($_POST['modify_state'])){
+      $this->is_account = !$this->is_account;
+      if(!$this->is_account){
+        $this->data = array();
+      }else{
+        $entry = $this->default_entry;
+        $entry['i_Port'] = $entry['i_Port'] + count($this->data);
+        $entry['s_Device'] = $entry['s_Device'].count($this->data);
+        $this->data = array(0 => $entry);
+        $this->DevID = 0; 
+        foreach($this->attributes as $attr){
+          $this->$attr = $this->data[$this->DevID][$attr];
+        }
+      }
+    }
 
+    if($this->is_account){
+        $display .= $this->show_disable_header(msgPool::removeFeaturesButton(_("Printer")),"",FALSE);
+    }else{
+        $display .= $this->show_enable_header(msgPool::addFeaturesButton(_("Printer")),"",FALSE);
+    }
+               $smarty = get_smarty();
     foreach($this->attributes as $attr){
       $smarty->assign($attr,$this->$attr);
     }
-    foreach(array("devices","ports") as $attr){
-      $smarty->assign($attr,array());
+    foreach(array("DevID","a_Types","a_Boolean","a_FlowControl","a_Parities","a_Speeds","a_Bits") as $attr){
+      $smarty->assign($attr,$this->$attr);
     }
-
-               return($smarty->fetch(get_template_path("gotoLpdEnable.tpl",TRUE,dirname(__FILE__))));
+    ksort($this->data);
+    $smarty->assign("data_cnt",count($this->data));
+    $smarty->assign("data",$this->data);
+    $smarty->assign("a_DevIDs",array_keys($this->data));
+    $smarty->assign("s_WriteOnly", $this->s_WriteOnly == "Y");
+    $smarty->assign("is_account",$this->is_account);
+               return($display.$smarty->fetch(get_template_path("gotoLpdEnable.tpl",TRUE,dirname(__FILE__))));
        }
 
+
   public function save_object()
   {
+    if(!$this->is_account) return;
+    $propose_device = "";
+    if(isset($_POST['s_Device']) && empty($_POST['s_Device']) && 
+        isset($_POST['s_Type']) && $_POST['s_Type'] != $this->s_Type){
+      $propose_device = $this->a_Devices[$_POST['s_Type']].$this->DevID;
+    }
+
     plugin::save_object();
+
+    if(isset($_POST['gotoLpdEnable_entry_posted']) && isset($_POST['s_WriteOnly'])){
+      $this->s_WriteOnly = "Y";
+    }else{
+      $this->s_WriteOnly = "N";
+    }
+
+    if(!empty($propose_device)){
+      $this->s_Device = $propose_device;
+    }
+
+    foreach($this->attributes as $attr){
+      $this->data[$this->DevID][$attr] = $this->$attr;
+    } 
+
+    /* Device ID has changed */
+    if(isset($_POST['DevID']) && $_POST['DevID'] != $this->DevID){
+      $this->DevID = $_POST['DevID'];
+      foreach($this->attributes as $attr){
+        $this->$attr = $this->data[$this->DevID][$attr];
+      }
+    }
+
+    if(isset($_POST['del_printer'])){
+      unset($this->data[$this->DevID]);
+      $this->data = array_values($this->data);
+      if(count($this->data) == 0){
+        $this->is_account = FALSE;
+      }
+      $this->DevID = key($this->data);
+    }
+    if(isset($_POST['add_printer'])){
+      if(count($this->data) < 3){
+        $entry = $this->default_entry;
+        $entry['i_Port'] = $entry['i_Port'] + count($this->data);
+        $entry['s_Device'] = $entry['s_Device'].count($this->data);
+        $this->DevID = count($this->data);
+        $this->data[] = $entry; 
+        foreach($this->attributes as $attr){
+          $this->$attr = $this->data[$this->DevID][$attr];
+        }
+      }
+    }
+  }
+
+  public function save()
+  {
+    $ret = array();
+    $attrs = array("s_Type","s_Device","i_Port","s_Speed","s_FlowControl","s_Parity","i_Bit","s_WriteOnly","s_Options"); 
+    foreach($this->data as $entry){
+      $str = "";
+      foreach($attrs as $attr){
+        $str .= $entry[$attr].":";
+      }
+      $ret[] = preg_replace("/:$/","",$str);
+    }
+    return($ret);
   }
 
 
@@ -49,9 +217,15 @@ class gotoLpdEnable extends plugin
   { 
     return(TRUE);
   }
+  public function acl_is_removeable($skip_write = FALSE)
+  { 
+    return(TRUE);
+  }
+  public function acl_is_createable($skip_write = FALSE)
+  { 
+    return(TRUE);
+  }
 }
 
-
-
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index bae371a8bec95247b4576fe09283895ca0dccebf..4cb2df0c223a22b81cb0711e0db1672ed5baa178 100644 (file)
@@ -3,7 +3,7 @@
 class workservice extends plugin
 {
   var $gotoScannerEnable;
-  var $gotoLpdEnable;
+  var $gotoLpdEnable = array();
 
   /* Generic terminal attributes */
   var $gotoXMonitor= "";
@@ -40,7 +40,7 @@ class workservice extends plugin
   var $attributes= array("gotoXMonitor",
       "gotoXDriver", "gotoXResolution", "gotoXColordepth",
       "gotoXHsync", "gotoXVsync",
-      "gotoScannerEnable","gotoLpdEnable", "gotoScannerClients",
+      "gotoScannerEnable", "gotoScannerClients",
       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
   var $objectclasses= array("GOhard");
@@ -253,15 +253,20 @@ class workservice extends plugin
       }
     }
 
+
     /**********
       gotoLpdEnable 
      **********/
-
     if(isset($_POST['gotoLpdEnable_Close'])){
       $this->dialog = NULL;
     }
+    if(isset($_POST['gotoLpdEnable_Ok'])){
+      $this->dialog->save_object();
+      $this->gotoLpdEnable = $this->dialog->save();
+      $this->dialog = NULL;
+    }
 
-    if(isset($_POST['gotoLpdEnable'])){
+    if(isset($_POST['gotoLpdEnable_Edit'])){
       $this->dialog = new gotoLpdEnable($this->config,$this->gotoLpdEnable,$this);
     }
 
index c6972b0ede85150aac687132944ae479dafd8d3a..48910843cd5ff3871fac9c429fdeb9d6b5620d44 100644 (file)
+{if !$is_account}
 
+{else}
 <table style='width:100%;'>
        <tr>
                <td style='width:50%;'>
                        <table>
                                <tr>
-                                       <td>{t}Device{/t}</td>
+                                       <td>{t}Device{/t}&nbsp;#</td>
+                                       <td>
+                                               <select name='DevID' onChange="document.mainform.submit();">
+                                                       {foreach from=$data key=key item=item}
+       <option {if $key == $DevID} selected {/if} value='{$key}'>{$key+1}: {$item.s_Type} {$item.s_Device}</option>
+                                                       {/foreach}
+                                               </select>
+                                               {if $data_cnt >= 3}
+                                               <input type="button" disabled name="dummy1" value="{msgPool type=addButton}">
+                                               {else}
+                                               <input type="submit" name="add_printer" value="{msgPool type=addButton}">
+                                               {/if}
+                                               <input type="submit" name="del_printer" value="{msgPool type=delButton}">
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}Type{/t}</td>
                                        <td>    
-                                               <select name='device'>
-                                                       {html_options options=$devices selected=$device}
+                                               <select name='s_Type'  onChange="document.mainform.submit();">
+                                                       {html_options options=$a_Types selected=$s_Type}
                                                </select>
                                        </td>
                                </tr>
+                               <tr>
+                                       <td>{t}Device{/t}</td>
+                                       <td>    
+                                               <input type='text' name='s_Device' value='{$s_Device}'>
+                                       </td>
+                               </tr>
                                <tr>
                                        <td>{t}Port{/t}</td>
                                        <td>
-                                               <input type='text' name='port' value='{$port}'>
+                                               <input type='text' name='i_Port' value='{$i_Port}'>
                                        </td>
                                </tr>
                                <tr>
                                        <td>{t}Options{/t}</td>
                                        <td>
-                                               <input type='text' value='{$options}' name='options'>
+                                               <input type='text' name='s_Options' value='{$s_Options}'>
                                        </td>
                                </tr>
                                <tr>
                                        <td>{t}Write only{/t}</td>
                                        <td>
-                                               <input type='checkbox' name='writeonly' value='1' >
+                                               <input {if $s_WriteOnly} checked {/if} type='checkbox' name='s_WriteOnly' value='Y' >
                                        </td>
                                </tr>
                        </table>
                </td>
                <td>
+{if $s_Type == "Serial"}
                        <table>
                                <tr>
                                        <td>{t}Speed{/t}</td>
-                                       <td></td>
+                                       <td>
+                                               <select name='s_Speed'>
+                                                       {html_options options=$a_Speeds selected=$s_Speed}
+                                               </select>
+                                       </td>
                                </tr>
                                <tr>
                                        <td>{t}Flow control{/t}</td>
-                                       <td></td>
+                                       <td>
+                                               <select name='s_FlowControl'>
+                                                       {html_options options=$a_FlowControl selected=$s_FlowControl}
+                                               </select>
+                                       </td>
                                </tr>
                                <tr>
                                        <td>{t}Parity{/t}</td>
-                                       <td></td>
+                                       <td>
+                                               <select name='s_Parity'>
+                                                       {html_options options=$a_Parities selected=$s_Parity}
+                                               </select>
+                                       </td>
                                </tr>
                                <tr>
                                        <td>{t}Bits{/t}</td>
-                                       <td></td>
+                                       <td>
+                                               <select name='i_Bit'>
+                                                       {html_options options=$a_Bits selected=$i_Bit}
+                                               </select>
+                                       </td>
                                </tr>
                        </table>
+{/if}
                </td>
        </tr>
 </table>
-
+<input type='hidden' name="gotoLpdEnable_entry_posted" value="1">
 <p class='seperator'>
 </p>
+{/if}
 <div style='width:100%; text-align: right; padding:5px;'>
        <input type='submit' name='gotoLpdEnable_Ok' value='{msgPool type=okButton}'>&nbsp;
        <input type='submit' name='gotoLpdEnable_Close' value='{msgPool type=cancelButton}'>
index 4314be0682042ee4daeb03150f413c85738168fb..82539c3af3b3d057a48e4b1270db472a026ba1f9 100644 (file)
    <h2><img class="center" alt="" src="plugins/systems/images/select_printer.png"> {t}Printer{/t}</h2>
 
 {render acl=$gotoLpdEnableACL}
-       <input type='submit' name='gotoLpdEnable' value='{msgPool type=editButton}'>
+       <input type='submit' name='gotoLpdEnable_Edit' value='{msgPool type=editButton}'>
 {/render}
        </td>
  </tr>