Code

Added sambaWorkingHours.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 19 Dec 2006 07:16:32 +0000 (07:16 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 19 Dec 2006 07:16:32 +0000 (07:16 +0000)
Not finished yet

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@5421 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/personal/samba/class_sambaAccount.inc
plugins/personal/samba/class_sambaLogonHours.inc [new file with mode: 0644]
plugins/personal/samba/samba3.tpl
plugins/personal/samba/sambaLogonHours.tpl [new file with mode: 0644]

index a03d61c23e85844a6aa97acc6036f9ac7be0c8cb..2a84bd2988ee2c45b8114a8e2a90267025ec22f6 100644 (file)
@@ -77,6 +77,7 @@ class sambaAccount extends plugin
   var $mungedObject;
 
   /* Helper */
+  var $dialog;
   var $show_ws_dialog= FALSE;
   var $logon_time_set= 0;
   var $logoff_time_set= 0;
@@ -232,6 +233,31 @@ class sambaAccount extends plugin
       }
     }
 
+
+    /* Open Samaba Logong hours dialog */
+    if(isset($_POST['SetSambaLogonHours']) && $this->samba3){
+      $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
+    }
+
+    /* Cancel dialog */
+    if(isset($_POST['cancel_logonHours'])){
+      $this->dialog = NULL; 
+    }
+
+    /* Save selected logon hours */
+    if(isset($_POST['save_logonHours'])){
+      $this->dialog->save_object();  
+      $this->sambaLogonHours = $this->dialog->save();
+      $this->dialog = NULL; 
+    }
+
+    /* Display dialog */
+    if(isset($this->dialog)){
+      $this->dialog->save_object();
+      return($this->dialog->execute());
+    }
+
+
     /* Prepare templating */
     $smarty= get_smarty();
 
diff --git a/plugins/personal/samba/class_sambaLogonHours.inc b/plugins/personal/samba/class_sambaLogonHours.inc
new file mode 100644 (file)
index 0000000..7123527
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+
+class sambaLogonHours extends plugin
+{
+
+  var $sambaLogonHours = "";
+  var $Matrix          = array();
+  
+  var $config;
+
+  function sambaLogonHours ($config, $dn, $slh)
+  {
+    plugin::plugin($config,$dn);
+
+    /* Convert to bin */
+    $tmp = '';
+    for($i = 0 ; $i < strlen($slh) ; $i ++){
+      $tmp .= str_pad(base_convert($slh[$i],16,2),4,'0',STR_PAD_LEFT);
+    }
+    $slh = $tmp;
+    $this->sambaLogonHours = $slh;
+
+    /* Set to default if value is empty or seams to be broken */
+    if(strlen($slh) != 168){
+      $slh = str_pad('',168 , "1");
+    }
+
+    /* Create matrix */ 
+    $this->Matrix = array();
+    for($day = 0 ; $day < 7 ; $day ++ ){
+      for($hour  = 0 ; $hour < 24 ; $hour ++){
+        $bitpos  = ($day * 24 + $hour) % 168;
+        $this->Matrix[$day][$hour] = $slh[$bitpos]; 
+      }
+    }
+  }
+
+  function execute()
+  {
+    $week_days = array();
+    $week_days[0]= _("Sunday");
+    $week_days[1]= _("Monday");
+    $week_days[2]= _("Tuesday");
+    $week_days[3]= _("Wednesday");
+    $week_days[4]= _("Thursday");
+    $week_days[5]= _("Friday");
+    $week_days[6]= _("Saturday");
+
+    $hours = array();
+    for($i = 0 ; $i <24 ; $i++ ){
+      $hours[$i] = $i ;
+    }
+
+    $smarty = get_smarty();
+    $smarty->assign("Matrix",$this->Matrix);
+    $smarty->assign("Days"  ,$week_days);
+    $smarty->assign("Hours" ,$hours);
+    return($smarty->fetch(get_template_path("sambaLogonHours.tpl",TRUE,dirname(__FILE__))));
+  }
+
+  function save_object()
+  {
+    /* Check if dialog was opened and if there were any changes */
+    if(isset($_POST['sambaLogonHoursPosted'])){
+      foreach($this->Matrix as $day_key => $days){
+        foreach($days as $hour_key => $hour){
+          if(isset($_POST['day_'.$day_key.'_'.$hour_key])){
+            $this->Matrix[$day_key][$hour_key] = 1;
+          }else{
+            $this->Matrix[$day_key][$hour_key] = 0;
+          }
+        }
+      }
+    }
+  }
+  
+  function save()
+  {
+    /* Convert Matrix to Hex */
+    $ret = "";
+    foreach($this->Matrix as $day_key => $days){
+      $four_bit = '';
+      foreach($days as $hour_key => $hour){
+        $four_bit .= $hour;
+        if(strlen($four_bit) == 4){
+          $ret .= base_convert($four_bit,2,16);
+          $four_bit ='';
+        }
+      }
+    }
+    return($ret);
+  }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index ce9442dd8c3be813bb07e691ce462c9dd86dc7d6..6c41bf168ed0910fc30c8a91b4742e9765357df3 100644 (file)
    <input type="hidden" name="sambaLogonTime" value="{$sambaLogonTime}">
    <input type="hidden" name="sambaLogoffTime" value="{$sambaLogoffTime}">
    <input type="hidden" name="sambaKickoffTime" value="{$sambaKickoffTime}">
+
+   <input type='submit' name='SetSambaLogonHours' value='{t}Setup{/t}'>&nbsp;{t}Samba logon restrictions{/t}
   </td>        
   <td style="border-left:1px solid #A0A0A0">
    &nbsp;
diff --git a/plugins/personal/samba/sambaLogonHours.tpl b/plugins/personal/samba/sambaLogonHours.tpl
new file mode 100644 (file)
index 0000000..e259ec8
--- /dev/null
@@ -0,0 +1,89 @@
+
+<!-- Javacript function used to switch a complete row or col of selected hours -->
+<script language="javascript" type="text/javascript">
+  {literal}
+  var $regex = new Array();
+  function toggle_chk($reg)
+  {
+    if(!$regex[$reg]){
+      $regex[$reg] =1;
+    }
+    $regex[$reg] *= -1;
+    if($regex[$reg] == 1){
+      chk_set_all($reg,true);
+    }else{
+      chk_set_all($reg,false);
+    }
+  }
+  {/literal}
+</script>
+
+<table cellspacing=0 cellpadding=0>
+  <tr>
+    <td style='text-align: right;' class='list0'>
+      {t}Hours{/t}&nbsp;
+    </td>
+    {foreach from=$Hours item=hours key=key_hours}
+      {if (($hours)%2) == 0 }
+        <td style="height: 22px; background-color: rgb(226, 226, 226); ">
+      {else}
+        <td style="height: 22px; background-color: rgb(245, 245, 245); border-right: solid 1px;">
+      {/if}
+      {$hours}
+    </td>
+    {/foreach}
+  </tr>
+
+  <!-- Add toggle buttons for hours -->
+  <tr>
+    <td style='text-align: left;' class='list0'>
+      &nbsp;{t}Days{/t}
+    </td>
+    {foreach from=$Hours item=hours key=key_hours}
+      {if (($hours)%2) == 0 }
+        <td style="height: 22px; background-color: rgb(226, 226, 226); text-align: right;">
+      {else}
+        <td style="height: 22px; background-color: rgb(245, 245, 245); border-right: solid 1px; text-align: right;">
+      {/if}
+      <input type='button' onClick="toggle_chk('_{$hours}$');" value='+/-' style='width:31px;'>
+    </td>
+    {/foreach}
+  </tr>
+
+  <!-- Add Entries -->
+{foreach from=$Matrix item=days key=key_day}
+  <tr>
+    <td class='list0'>
+      <b>{$Days[$key_day]}</b>
+    </td>
+    {foreach from=$days item=hours key=key_hour}
+      {if (($key_hour)%2) == 0 }
+        <td style="height: 22px; background-color: rgb(226, 226, 226); ">
+      {else}
+        <td style="height: 22px; background-color: rgb(245, 245, 245); border-right: solid 1px;">
+      {/if}
+        {if $Matrix[$key_day].$key_hour}
+          <input id='day_{$key_day}_{$key_hour}' type='checkbox' name='day_{$key_day}_{$key_hour}' checked >
+        {else}
+          <input id='day_{$key_day}_{$key_hour}' type='checkbox' name='day_{$key_day}_{$key_hour}' >
+        {/if}
+      </td>
+    {/foreach}
+
+    <!-- Add toggle button for days -->
+    <td>  
+      <input type='button' onClick="toggle_chk('^day_{$key_day}')" value='+/-'>
+    </td>
+  </tr>
+{/foreach}
+</table>
+<input type='hidden' name='sambaLogonHoursPosted' value='1'> 
+<p class="plugbottom">
+  <input type=submit name="save_logonHours" value="{t}Use{/t}">
+  &nbsp;
+  <input type=submit name="cancel_logonHours" value="{t}Cancel{/t}">
+</p>
+
+<!--  
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: 
+-->