Code

Added samba logon hours
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 23 Jan 2007 10:14:43 +0000 (10:14 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 23 Jan 2007 10:14:43 +0000 (10:14 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5591 594d385d-05f5-0310-b6e9-bd551577e9d8

html/include/focus.js
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 4a112e0fb7c8d3d908bfa9318a6de4fde4630940..3b86afac8bc4ad3cc8dbb8046340429787b84429 100644 (file)
@@ -15,6 +15,18 @@ for (iln = 0; iln < len; iln++){
 netscape= (ver.charAt(iln+1).toUpperCase() != "C");
 
 
+/* Toggle checkbox that matches regex */
+function chk_set_all(regex,value)
+{
+        for (var i = 0; i < document.mainform.elements.length; i++) {
+                var _id=document.mainform.elements[i].id;
+                if(_id.match(regex)) {
+                        document.getElementById(_id).checked= value;
+                }
+        }
+}
+
+
 function scrollDown() {
   document.body.scrollTop = document.body.scrollHeight - document.body.clientHeight;
   timeout= setTimeout("scrollDown()", 500);
index d48d8821e9fee3acd6dfd6b30086c3b7fa2ea5b6..87712a9636cd32f97252514918395b9ff2b38a3d 100644 (file)
@@ -88,7 +88,7 @@ class sambaAccount extends plugin
   var $objectclasses= array();
   
   var $uid= "";
-
+  var $dialog = NULL;
   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
 
   function sambaAccount ($config, $dn= NULL)
@@ -234,6 +234,32 @@ class sambaAccount extends plugin
 
     $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
 
+    /* Open Samaba Logong hours dialog */
+    if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
+      $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();
+      if($this->acl_is_writeable("sambaLogonHours")){
+        $this->sambaLogonHours = $this->dialog->save();
+      }
+      $this->dialog = NULL;
+    }
+
+    /* Display dialog */
+    if((isset($this->dialog)) && (is_object($this->dialog))){
+      $this->dialog->save_object();
+      return($this->dialog->execute());
+    }
+
+
     /* Prepare templating */
     $smarty= get_smarty();
 
@@ -1062,6 +1088,7 @@ class sambaAccount extends plugin
 
             "sambaLogonTime"        => _("Limit Logon Time") ,
             "sambaLogoffTime"       => _("Limit Logoff Time") ,
+            "sambaLogonHours"       => _("Logon hours") ,
 
             "sambaHomePath"         => _("Generic home directory") ,
             "sambaHomeDrive"        => _("Generic samba home drive") ,
diff --git a/plugins/personal/samba/class_sambaLogonHours.inc b/plugins/personal/samba/class_sambaLogonHours.inc
new file mode 100644 (file)
index 0000000..df8bf51
--- /dev/null
@@ -0,0 +1,148 @@
+<?php
+
+class sambaLogonHours extends plugin
+{
+
+  var $sambaLogonHours = "";
+  var $Matrix          = array();
+  var $timezone        = 0; 
+  var $config;
+
+  function sambaLogonHours ($config, $dn, $slh)
+  {
+    plugin::plugin($config,$dn);
+    $this->sambaLogonHours = $slh;
+
+    /* Get Timezone to be able to shift to the correct beginning */
+    if(isset($this->config->current['TIMEZONE'])){
+      $this->timezone = $this->config->current['TIMEZONE'];
+    }
+
+    /* 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;
+
+    /* Set to default if value is empty or seams to be broken */
+    if(strlen($slh) != 168){
+      $slh = str_pad('',168 , "1");
+    }
+
+    /* Rework string, because it was stored in little endian */
+    $new = '';
+    for($i = 0 ; $i < 21 ; $i ++ ){
+      $part         = strrev(substr($slh, $i * 8, 8));
+      $byte['hi']   = substr($part,0,4);
+      $byte['low']  = substr($part,4,4);
+      $new .= $byte['hi'].$byte['low'];
+    }
+
+    /* Shift string to match given timezone settings */
+    $shift_by = (168 + $this->timezone) % 168;
+    for($i = 0 ; $i < $shift_by; $i ++){
+      $new = $new[167].$new;
+      $new = substr($new,0,168);
+    }
+
+    /* 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] = $new[$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 ;
+    }
+    $ui =get_userinfo();
+
+    $smarty = get_smarty();
+    $smarty->assign("sambaLogonHoursACL",$ui->get_permissions($this->acl_base,"user/generic","sambaLogonHours"));
+    $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()
+  {
+    /* Get userinfo */
+    $ui = get_userinfo();
+  
+    /* Check if dialog was opened and if there were any changes */
+    if(isset($_POST['sambaLogonHoursPosted']) && preg_match("/w/i",$ui->get_permissions($this->acl_base,"user/generic","sambaLogonHours"))){
+      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 */
+    $slh = "";
+    foreach($this->Matrix as $day_key => $days){
+      foreach($days as $hour_key => $hour){
+        $slh .= $hour;
+      }
+    }
+
+    /* Shift string to match given timezone settings */
+    $shift_by = (168 + ($this->timezone*(-1))) % 168;
+    for($i = 0 ; $i < $shift_by; $i ++){
+      $slh = $slh[167].$slh;
+      $slh = substr($slh,0,168);
+    }
+    /* Rework string, because it was stored in little endian */
+    $new = '';
+    for($i = 0 ; $i < 21 ; $i ++ ){
+      $part         = strrev(substr($slh, $i * 8, 8));
+      $byte['hi']   = substr($part,0,4);
+      $byte['low']  = substr($part,4,4);
+      $new .= $byte['hi'].$byte['low'];
+    }
+
+    /* Convert to bin */
+    $tmp = '';
+    for($i = 0 ; $i < 21 ; $i ++){
+      $tmp .= str_pad(base_convert(substr($new,$i*8,8),2,16),2,'0',STR_PAD_LEFT);
+    }
+
+    /* Create uppercase HEX chars */
+    $ret = strtoupper( $tmp);
+    
+    /* All hours and days selected */
+    if(substr_count($ret,'F') == 42){
+      $ret = "";
+    }
+
+    return($ret);
+  }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index 3e305f01aeed5a651910a172c8c831968a67c7e9..251cf53545f92393928c92f6c2b172b17f287c9e 100644 (file)
    <input type="hidden" name="sambaLogonTime" value="{$sambaLogonTime}">
    <input type="hidden" name="sambaLogoffTime" value="{$sambaLogoffTime}">
    <input type="hidden" name="sambaKickoffTime" value="{$sambaKickoffTime}">
+<br>
+{render acl=$sambaLogonHoursACL mode=read_active}
+   {t}Samba logon times{/t}&nbsp;<input type='submit' name='SetSambaLogonHours' value='{t}Edit settings...{/t}'>
+{/render}
+
   </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..1eb7306
--- /dev/null
@@ -0,0 +1,111 @@
+
+<!-- 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>
+
+<h1>{t}Specify the hours this user is allowed to log in{/t}</h1>
+<br>
+
+<table cellspacing=0 cellpadding=0 style='border: solid 1px #B0B0B0; background-color: #EEEEEE; width :100%;' >
+  <tr>
+    <td>&nbsp;</td>
+    <td colspan=24 style='text-align:center;height:24px;border-bottom: solid 1px #B0B0B0;'><b>{t}Hour{/t}</b></td>
+  </tr>
+  <tr>
+    <td style='text-align: left;' class='list0'>&nbsp;</td>
+    {foreach from=$Hours item=hours key=key_hours}
+      {if (($hours)%2) == 0 }
+        <td style="text-align:center;height: 22px; background-color: rgb(226, 226, 226); ">
+      {else}
+        <td style="text-align:center;height: 22px; background-color: rgb(245, 245, 245); border-right: solid 1px #B0B0B0;">
+      {/if}
+      {$hours}
+    </td>
+    {/foreach}
+  </tr>
+
+  <!-- Add toggle buttons for hours -->
+  <tr>
+    <td style='text-align: left;' class='list0'>
+      &nbsp;
+    </td>
+    {foreach from=$Hours item=hours key=key_hours}
+      {if (($hours)%2) == 0 }
+        <td style="text-align:center; height: 22px; background-color: rgb(226, 226, 226); text-align: right;">
+      {else}
+        <td style="text-align:center; height: 22px; background-color: rgb(245, 245, 245); border-right: solid 1px #B0B0B0; text-align: right;">
+      {/if}
+
+{render acl=$sambaLogonHoursACL}
+      <input type='button' onClick="toggle_chk('^day_[0-9]*_{$hours}$');" value='+/-' style='width:100%;'>
+{/render}
+    </td>
+    {/foreach}
+    <td>
+
+{render acl=$sambaLogonHoursACL}
+      <input type='button' onClick="toggle_chk('^day_[0-9]*_[0-9]*$');" value='+/-' style='width:100%;'>
+{/render}
+    </td>
+  </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="text-align:center;height: 22px; background-color: rgb(226, 226, 226); ">
+      {else}
+        <td style="text-align:center;height: 22px; background-color: rgb(245, 245, 245); border-right: solid 1px;">
+      {/if}
+        {if $Matrix[$key_day].$key_hour}
+{render acl=$sambaLogonHoursACL}
+          <input id='day_{$key_day}_{$key_hour}' type='checkbox' name='day_{$key_day}_{$key_hour}' checked >
+{/render}
+        {else}
+{render acl=$sambaLogonHoursACL}
+          <input id='day_{$key_day}_{$key_hour}' type='checkbox' name='day_{$key_day}_{$key_hour}' >
+{/render}
+        {/if}
+      </td>
+    {/foreach}
+
+    <!-- Add toggle button for days -->
+    <td>  
+{render acl=$sambaLogonHoursACL}
+      <input type='button' onClick="toggle_chk('^day_{$key_day}_[0-9]*$')" value='+/-'  style='padding:0px;margin:0px;'>
+{/render}
+    </td>
+  </tr>
+{/foreach}
+</table>
+<br>
+<input type='hidden' name='sambaLogonHoursPosted' value='1'> 
+<br>
+<p class="plugbottom">
+  <input type=submit name="save_logonHours" value="{t}Apply{/t}">
+  &nbsp;
+  <input type=submit name="cancel_logonHours" value="{t}Cancel{/t}">
+</p>
+
+<!--  
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: 
+-->