From: cajus Date: Thu, 17 Jan 2008 14:42:37 +0000 (+0000) Subject: group clean up X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8226dbf41a86e75c24c7eab1f88f073fbe6706d0;p=gosa.git group clean up git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8466 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/plugins/admin/groups/application.tpl b/gosa-core/plugins/admin/groups/application.tpl deleted file mode 100644 index bc6297ab0..000000000 --- a/gosa-core/plugins/admin/groups/application.tpl +++ /dev/null @@ -1,69 +0,0 @@ - -{if $multiple_support} - -

Multiple edit

- - {if $use_apps} - - {t}Modify application settings.{/t} -
-
- {else} - - {t}Modify application settings for groups.{/t} -
- - -{/if} - diff --git a/gosa-core/plugins/admin/groups/application_options.tpl b/gosa-core/plugins/admin/groups/application_options.tpl deleted file mode 100644 index aa5522180..000000000 --- a/gosa-core/plugins/admin/groups/application_options.tpl +++ /dev/null @@ -1,15 +0,0 @@ -
-{t}Application options{/t} -
-
- -{$table} - -
- -

- -   - -

- diff --git a/gosa-core/plugins/admin/groups/apps/application.tpl b/gosa-core/plugins/admin/groups/apps/application.tpl new file mode 100644 index 000000000..bc6297ab0 --- /dev/null +++ b/gosa-core/plugins/admin/groups/apps/application.tpl @@ -0,0 +1,69 @@ + +{if $multiple_support} + +

Multiple edit

+ + {if $use_apps} + + {t}Modify application settings.{/t} +
+
+ {else} + + {t}Modify application settings for groups.{/t} +
+ + +{/if} + diff --git a/gosa-core/plugins/admin/groups/apps/application_options.tpl b/gosa-core/plugins/admin/groups/apps/application_options.tpl new file mode 100644 index 000000000..aa5522180 --- /dev/null +++ b/gosa-core/plugins/admin/groups/apps/application_options.tpl @@ -0,0 +1,15 @@ +
+{t}Application options{/t} +
+
+ +{$table} + +
+ +

+ +   + +

+ diff --git a/gosa-core/plugins/admin/groups/apps/class_groupApplication.inc b/gosa-core/plugins/admin/groups/apps/class_groupApplication.inc new file mode 100644 index 000000000..e10e4a69d --- /dev/null +++ b/gosa-core/plugins/admin/groups/apps/class_groupApplication.inc @@ -0,0 +1,1288 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* Appgroup attributes */ + var $gosaMemberApplication= array(); + + /* Helpers */ + var $departments = ""; // All departments within $this->curbase; + var $apps = array(); // All available applications + var $used_apps = array(); // Specifies which applications are currently assigned + + var $option_name = array(); + var $option_value = array(); + var $appoption = array(); + + var $table = ""; + var $curbase = ""; + var $curCatDir ; + var $curCatDepth =0; // + var $Categories; + + /* attribute list for save action */ + var $attributes = array("gosaMemberApplication","gosaApplicationParameter"); + var $objectclasses = array("gosaApplicationGroup"); + + var $FAIrelease = "/"; + var $InitialFAIrelease = "/"; + var $Releases = array(); + var $enableReleaseManagement = false; + + var $AllAppsForRelease = array(); + var $AllAppsForReleaseParameter = array(); + var $view_logged = FALSE; + var $CopyPasteVars = array("Categories"); + var $gosaApplicationParameter ; + var $ui = NULL; + var $no_release_acls = false; + + var $multiple_support = TRUE; + + function appgroup (&$config, $dn= NULL, $parent= NULL) + { + + /* Check if we have relase mangement enabled and prepare group application for release management */ + $tmp = $config->search("faiManagement", "CLASS",array('menu','tabs')); + if(!empty($tmp)){ + $this->enableReleaseManagement = true; + $this->objectclasses [] = "FAIreleaseTag"; + $this->attributes [] = "FAIrelease"; + } + + plugin::plugin ($config, $dn, $parent); + + /* set userinfo object */ + $this->ui = get_userinfo(); + + /* Compatibility check + In some case of old applikations with old release tag saving, + we must reassign is_account state. + (Or if release management wasn't activated before creating this app) */ + if($this->enableReleaseManagement){ + + /* Release management is activated && this is a valid group app account, + but no release class was found, so activate is_account flag */ + if(isset($this->attrs['objectClass'])){ + if($dn != "new" && ( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) && + (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){ + $this->is_account =true; + } + } + } + + /* Load member applications */ + if (isset ($this->attrs["gosaMemberApplication"][0])){ + $this->gosaMemberApplication = array(); + for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){ + $this->gosaMemberApplication[]= + $this->attrs["gosaMemberApplication"][$i]; + } + } + + /* Load application options */ + if (isset($this->attrs['gosaApplicationParameter'])){ + for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){ + $option= preg_replace('/^[^:]+:/', '', + $this->attrs['gosaApplicationParameter'][$i]); + $name= preg_replace('/:.*$/', '', + $this->attrs['gosaApplicationParameter'][$i]); + $this->appoption[$name]= $option; + } + } + + /* Parse MemberApplication*/ + $tmp = array(); + $tmp2 = array(); + $prios = array(); + $cats = array(); + + foreach($this->gosaMemberApplication as $memberApp){ + if(preg_match("/\|/i",$memberApp)){ + + $tmp = split("\|",$memberApp); + + if(!empty($tmp[0])){ + $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]); + } + if(!empty($tmp[1])){ + $n = split("/",$tmp[1]); + $c = count($n); + $cats [$tmp[1]] = $n[$c-1]; + } + $prios[$tmp[1]][$tmp[2]] = $tmp[2]; + }else{ + $tmp2[]['App'] = $memberApp; + } + } + + /* Assign collected category and application settings */ + $this->Categories = $cats; + $this->gosaMemberApplication = $tmp2; + + /* Sort application by category */ + $cats[""]=""; + foreach($cats as $cat ){ + if((isset($prios[$cat]))&&(count($prios[$cat]))){ + $max = max($prios[$cat]); + $min = 1;//min($prios[$cat]); + $last = false; + for($i = $min ; $i < $max ; $i++){ + if(!isset($prios[$cat][$i])){ + if($last == false){ + $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i; + + $last = true; + } + }else{ + $last = false; + } + } + } + } + + /* Sort application by priority */ + $tmp = array(); + foreach($this->gosaMemberApplication as $key => $entries){ + ksort ($entries); + foreach($entries as $entry){ + $tmp[$key][]= $entry; + } + } + $this->gosaMemberApplication = $tmp; + $this->curbase = $this->config->current['BASE']; + + /* Get required release informations */ + if($this->enableReleaseManagement){ + $this->InitialFAIrelease = $this->FAIrelease; + $this->Releases = $this->getReleases(); + } + + } + + + /* Combine new array */ + function combineArrays($ar0,$ar1,$ar2) + { + $ret = array(); + if(is_array($ar0)) + foreach($ar0 as $ar => $a){ + $ret[$ar]=$a; + } + if(is_array($ar1)) + foreach($ar1 as $ar => $a){ + $ret[$ar]=$a; + } + if(is_array($ar2)) + foreach($ar2 as $ar => $a){ + $ret[$ar]=$a; + } + return($ret); + } + + /* Returns element position within given array */ + function getpos($atr,$attrs) + { + $i = 0; + foreach($attrs as $attr => $name) { + $i++; + if($attr == $atr){ + return($i); + } + } + return(-1); + } + + + /* Check current combination of application && release + Are all application available?, application parameter changed? ... */ + function diffAppsInReleases() + { + /* Only diff if it is required */ + $ret =array(); + + /* If current release has changed */ + if($this->FAIrelease != $this->InitialFAIrelease){ + + /* Walk through all apps which are currently displayed */ + if(isset($this->gosaMemberApplication[$this->curCatDir])){ + + foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){ + + /* If application is also available in new release, check if parameter differs */ + if(in_array($entry['App'],$this->AllAppsForRelease)){ + + $old = array(); // Old application parameter + $new = array(); // New parameters + + /* There are possibly no parameters specified */ + if(isset($this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']])){ + $old = $this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']]; + } + + if(isset($this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']])){ + $new = $this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']]; + } + + /* Both (old & new) have no gosaApplicationParameter + */ + if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){ + $ret[$entry['App']] = false; + + /* Both got gosaApplicationParameter */ + }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){ + if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){ + $ret[$entry['App']] = true; + }else{ + $ret[$entry['App']] = false; + } + } + /* Initially had gosaApplicationParameter bot in new release not */ + }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){ + $ret[$entry['App']] = true; + + /* Old release had no gosaApplicationParameter but new got some */ + }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){ + $ret[$entry['App']] = true; + } + } + } + } + return($ret); + } + + /* TRansports the geiven Arraykey one position up*/ + function ArrayUp($atr,$attrs) + { + $ret = $attrs; + $pos = $this->getpos($atr,$attrs) ; + $cn = count($attrs); + if(!(($pos == -1)||($pos == 1))){ + $before = array_slice($attrs,0,($pos-2)); + $mitte = array_reverse(array_slice($attrs,($pos-2),2)); + $unten = array_slice($attrs,$pos); + $ret = array(); + $ret = $this->combineArrays($before,$mitte,$unten); + } + return($ret); + } + + + /* TRansports the geiven Arraykey one position up*/ + function ArrayDown($atr,$attrs) + { + $ret = $attrs; + $pos = $this->getpos($atr,$attrs) ; + $cn = count($attrs); + if(!(($pos == -1)||($pos == $cn))){ + $before = array_slice($attrs,0,($pos-1)); + $mitte = array_reverse(array_slice($attrs,($pos-1),2)); + $unten = array_slice($attrs,($pos+1)); + $ret = array(); + $ret = $this->combineArrays($before,$mitte,$unten); + } + return($ret); + } + + + /* Sort category on position up */ + function catUp($id) + { + /* Get all cats depinding on current dir */ + $cats = $this->GetSubdirs($this->curCatDir); + $newcats =$this->ArrayUp($id,$cats); + foreach($newcats as $cat => $name){ + unset($this->Categories[$cat]); + } + foreach($newcats as $cat => $name){ + $this->Categories[$cat]=$name; + } + } + + + /* Sort category on position down */ + function catDown($id) + { + /* Get all cats depinding on current dir */ + $cats = $this->GetSubdirs($this->curCatDir); + $newcats =$this->ArrayDown($id,$cats); + foreach($newcats as $cat => $name){ + unset($this->Categories[$cat]); + } + foreach($newcats as $cat => $name){ + $this->Categories[$cat]=$name; + } + } + + + /* Increase application priority */ + function getOneUp($appl) + { + $cat = $this->curCatDir; + $apps = $this->gosaMemberApplication[$cat]; + $appsA = array(); + foreach ($apps as $appkey => $name){ + $appsA[$name['App']] =$name['App']; + } + $result = $this->ArrayUp($appl,$appsA); + $ret = array(); + foreach($result as $app){ + $ret[]=array("App"=>$app); + } + $this->gosaMemberApplication[$cat] = $ret; + } + + + /* Decrease application priority */ + function getOneDown($appl) + { + $cat = $this->curCatDir; + $apps = $this->gosaMemberApplication[$cat]; + $appsA = array(); + foreach ($apps as $appkey => $name){ + $appsA[$name['App']] =$name['App']; + } + $result = $this->ArrayDown($appl,$appsA); + $ret = array(); + foreach($result as $app){ + $ret[]=array("App"=>$app); + } + $this->gosaMemberApplication[$cat] = $ret; + } + + + /* Add seperator to application list */ + function AddSeperator($id) + { + $found = false; + $cat = ""; + $tmp = array(); + foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){ + $tmp[] = $app; + if(($app['App'] == $id)&&(!$found)){ + $cnt = count($this->gosaMemberApplication[$this->curCatDir]); + $tmp[] = array("App" => "__SEPARATOR__".($cnt+1)); + $found = true; + } + } + if($found){ + $this->gosaMemberApplication[$this->curCatDir]=$tmp; + } + } + + + /* Check if application acls are readable */ + function check_acls() + { + return(count($this->ui->get_module_departments("application"))); + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + $display = ""; + + /* Log view */ + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","groups/".get_class($this),$this->dn); + } + + /* Account state settings - Skip if we are editing multiple entries */ + if(!$this->multiple_support_active){ + + /* Do we need to flip is_account state? */ + if(isset($_POST['modify_state'])){ + if($this->is_account && $this->acl_is_removeable()){ + $this->is_account= FALSE; + }elseif(!$this->is_account && $this->acl_is_createable()){ + $this->is_account= TRUE; + } + } + + /* Do we represent a valid group? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + _("This 'dn' is no appgroup.").""; + return ($display); + } + + /* Show tab dialog headers */ + $display= ""; + if ($this->parent !== NULL){ + if ($this->is_account){ + $display= $this->show_disable_header(_("Remove applications"), + _("This group has application features enabled. You can disable them by clicking below.")); + } else { + $display.= $this->show_enable_header(_("Create applications"), + _("This group has application features disabled. You can enable them by clicking below.")); + return ($display); + } + } + } + + /* Check acl, applications must be readable */ + if(!$this->check_acls()){ + $display .= ""._("ACL")." + "._("Insufficient permissions")." +

". + _("You do not have permission to query application entries. All your changes will not be saved."). + "

 

"; + $this->no_release_acls = true; + } + /* Check if department was selected */ + if((isset($_GET['act']))&&($_GET['act']=="depopen")){ + $dep = base64_decode($_GET['depid']); + $this->curbase =$dep; + } + + /* Check if category was selected */ + if((isset($_GET['act']))&&($_GET['act']=="open") && (empty($_GET['id']) || isset($this->Categories[base64_decode($_GET['id'])]))){ + $this->curCatDir = base64_decode($_GET['id']); + } + + + + + /* Add Categorie */ + if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){ + + /* Only allow adding a category, if it is allowed */ + if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ + + if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){ + print_red(_("Invalid character in category name.")); + }elseif(!in_array($_POST['CatName'],$this->Categories)){ + if(empty($this->curCatDir)){ + $this->Categories[$_POST['CatName']]=$_POST['CatName']; + }else{ + $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName']; + } + }else{ + print_red(_("The specified category already exists.")); + } + } + } + + + $this->reload(); + $this->diffAppsInReleases(); + + /* Check POST variables for commands + to add/remove some applications */ + $only_once = false; + if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ + + /* Walk through posts */ + foreach($_POST as $name => $value){ + + /* Add a seperator to current category */ + if((preg_match("/AddSep_/",$name))&&(!$only_once)){ + $only_once = true; + $n = preg_replace("/AddSep_/","",$name); + $val= preg_replace("/_.*$/","",$n); + $this->AddSeperator($val); + } + + /* Delete application | seperator entry */ + if((preg_match("/DelApp_/",$name))&&(!$only_once)){ + $only_once = true; + + if(preg_match("/DelApp___SEPARATOR__/",$name)) { + $n= preg_replace("/DelApp___SEPARATOR__/","",$name); + $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n); + }else{ + $n = preg_replace("/DelApp_/","",$name); + $val= preg_replace("/_.*$/","",$n); + } + + foreach($this->gosaMemberApplication as $key => $cat){ + foreach($cat as $key2 => $app){ + if($app['App'] == $val){ + unset($this->gosaMemberApplication[$key][$key2]); + if(isset($this->used_apps[$val])){ + foreach($this->getParameters($val) as $para){ + if(isset($this->appoption[$para])){ + unset($this->appoption[$para]); + } + } + unset($this->used_apps[$val]); + } + } + } + } + } + + if(preg_match("/DelCat_/",$name) && !$only_once){ + $only_once =TRUE; + $cat = preg_replace("/DelCat_/","",$name); + $cat = trim(base64_decode( preg_replace("/_.*$/","",$cat))); + + $free_apps = array(); + + if(isset($this->gosaMemberApplication[$cat]) && is_array($this->gosaMemberApplication[$cat])){ + foreach($this->gosaMemberApplication[$cat] as $app){ + $free_apps[] = $app['App']; + } + unset($this->gosaMemberApplication[$cat]); + unset($this->Categories[$cat]); + } + foreach($this->Categories as $key => $name){ + if(preg_match("/^".normalizePreg($cat)."\/.*/",$key)){ + foreach($this->gosaMemberApplication[$key] as $app){ + $free_apps[] = $app['App']; + } + unset($this->gosaMemberApplication[$key]); + unset($this->Categories[$key]); + } + } + foreach($free_apps as $app){ + if(isset($this->used_apps[$app])){ + unset($this->used_apps[$app]); + } + } + } + + /* Edit application parameter */ + if((preg_match("/EdiApp_/",$name))&&(!$only_once)){ + + $only_once = true; + $appname = $value; + $appname = preg_replace("/EdiApp_/","",$name); + $appname = preg_replace("/_.*$/","",$appname); + + /* We've got the appname, get parameters from ldap */ + $ldap= $this->config->get_ldap_link(); + + /* Check if we have release management enabled */ + $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs')); + if(!empty($tmp)){ + + /* Get application parameter from ldap */ + $tmp = array_flip($this->Releases); + $base = $tmp[$this->FAIrelease]; + $ldap->cd($base); + $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter")); + $found = ""; + while($attrs = $ldap->fetch()) { + if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){ + $found = $attrs['dn']; + } + } + $ldap->cat($found, array("gosaApplicationParameter")); + }else{ + + /* Get application parameter from ldap */ + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter")); + } + + /* Check if this application is unique */ + if ($ldap->count() != 1){ + print_red (_("The selected application name is not uniq. Please check your LDAP.")); + } else { + + /* Get parameter */ + $attrs= $ldap->fetch(); + if(isset($attrs['gosaApplicationParameter'])){ + $this->dialog= TRUE; + + /* Fill name and value arrays */ + for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){ + $option= preg_replace('/^[^:]+:/', '', + $attrs['gosaApplicationParameter'][$i]); + $name= preg_replace('/:.*$/', '', + $attrs['gosaApplicationParameter'][$i]); + $this->option_name[$i]= $name; + + /* Fill with values from application, default should be + loaded by the external scripts */ + if (isset($this->appoption[$name])){ + $this->option_value[$i]= $this->appoption[$name]; + } + } + + /* Create edit field */ + $table= ""; + for ($i= 0; $i < count($this->option_name); $i++){ + if (isset($this->option_value[$i])){ + $value= $this->option_value[$i]; + } else { + $value= ""; + } + $table.=""; + } + $table.= "
".$this->option_name[$i]."". + "
"; + $this->table= $table; + } else { + print_red (_("The selected application has no options.")); + } + } + } + } + } + + /* Add multiple */ + if(isset($_POST['AddApps'])){ + foreach($_POST as $name => $value){ + if(preg_match("/AddApp_/",$name)){ + $app = preg_replace("/AddApp_/","",$name); + $this->addApp($app); + } + } + } + + /* Add application with post */ + if((isset($_GET['act']))&&($_GET['act']=="add")){ + $this->used_apps[$_GET['id']]= $_GET['id']; + asort($this->used_apps); + $this->addApp($_GET['id']); + } + + /* Cancel edit options? */ + if (isset($_POST['edit_options_cancel'])){ + $this->dialog= FALSE; + } + + /* Finish edit options? */ + if (isset($_POST['edit_options_finish'])){ + $this->dialog= FALSE; + + /* Save informations passed by the user */ + $this->option_value= array(); + for ($i= 0; $ioption_name); $i++){ + $this->appoption[$this->option_name[$i]]= $_POST["value$i"]; + $this->is_modified= TRUE; + } + } + + /* Prepare templating stuff */ + $smarty= get_smarty(); + $smarty->assign("used_apps", $this->used_apps); + $apps= array(); + foreach ($this->apps as $key => $value){ + if (!array_key_exists($key, $this->used_apps)){ + $apps["$key"]= "$value"; + } + } + + + /* Create application list */ + $div = new divSelectBox("appgroup"); + $div->SetHeight(300); + $departments = array(); + $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT); + foreach($res as $value){ + $fdn = $value['dn']; + $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn); + $fdn= @LDAP::fix($fdn); + if($value["description"][0]!=".."){ + $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]"; + }else{ + $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]"; + } + } + + /* Create 'open' and 'add' links */ + if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ + $linkadd = "%s"; + }else{ + $linkadd = "%s"; + } + $linkopen = "%s"; + + /* Create base back entry */ + $base_back = preg_replace("/^[^,]+,/","",$this->curbase); + if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){ + $div->AddEntry(array( + array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"), + "attach"=>"style='border:0px;'") + )); + } + + /* Append departments for current base */ + foreach($departments as $key => $app){ + $div->AddEntry(array( + array("string"=>""._("department")." ".sprintf($linkopen,base64_encode($key),$app), + "attach"=>"style='border:0px;'") + )); + } + + /* Add applications found on this base */ + foreach($apps as $key => $app){ + $div->AddEntry(array( + array("string"=>sprintf("",$key). + ""._("application")." ".sprintf($linkadd,$key,$app), + "attach"=>"style='border:0px;'") + )); + } + + /* Create list of used/assigned applications */ + $div2 = new divSelectBox("appgroup"); + $div2->SetHeight(300); + + /* Check acls to create "edit/remove" category links */ + if(!$this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ + $linkopen = "\"\" %s"; + $catremove = "  "; + $catupdown = ""; + }else{ + $linkopen = "\"\" %s"; + $catremove = " "; + $catupdown = "". + "\"\"". + " ". + "". + "\"\"". + ""; + } + + /* Add back category for current category */ + if(empty($this->curCatDir)){ + $cnt =0; + }else{ + $cnt = count(split("/",$this->curCatDir)); + $tmp = split("/",$this->curCatDir); + $bbk = ""; + for($i = 0 ; $i < ($cnt -1 ) ; $i++){ + $bbk .= $tmp[$i]."/"; + } + $bbk = preg_replace("/\/$/","",$bbk); + $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),".. ["._("Back")."]")),array("string"=>" ","attach"=>"style='border-right:0px;'"))); + } + + /* Add sub categories */ + $this->GetSubdirs($this->curCatDir); + foreach($this->GetSubdirs($this->curCatDir) as $path => $name){ + $div2 ->AddEntry(array( + array("string"=>sprintf($linkopen,base64_encode($path),$name)), + array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove), + "attach"=>"align='right' style='width:80px;border-right:0px;'"))); + } + + /* Create priority & seperator links */ + $separator ="
"; + if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ + $sep = ""; + $upudown = "". + " {t}sort{/t}". + " ". + "". + " {t}sort{/t}". + " ". + ""; + }else{ + $sep = ""; + $upudown = ""; + } + + /* Create edit link */ + if($this->acl_is_writeable("gosaApplicationParameter",$this->no_release_acls)){ + $edit= " "; + }else{ + $edit= ""; + } + + /* Get differences to mark those entries that have changed from last edit. */ + $Differences = $this->diffAppsInReleases(); + + /* Walk through entries an append them to list */ + if(isset($this->gosaMemberApplication[$this->curCatDir])){ + foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){ + + /* Add seperator */ + if(preg_match("/__SEPARATOR__/",$entry['App'])){ + $div2 ->AddEntry(array(array("string"=>$separator), + array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'"))); + }else{ + + /* Add application */ + + $image = ""; + /* Check if application was available within selected release + * or application list if release management is not active + */ + if(!in_array($entry['App'],$this->AllAppsForRelease)){ + + /* release managent is active + */ + if(!$this->enableReleaseManagement){ + $image = "R "; + }else{ + $image = "FFAIrelease)."\"> "; + } + + }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) { + $entry['App'].=" ["._("Check parameter")."]"; + $image = " "; + }else{ + $image = "\"\" "; + } + + $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])), + array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown), + "attach"=>"align='right' style='width:100px;border-right:0px;'"))); + } + } + } + + /* Assign created div lists to template */ + $smarty->assign("UsedApps", $div2->DrawList()); + $smarty->assign("List", $div->DrawList()); + $smarty->assign("apps", $apps); + + $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement); + + $smarty->assign("ReleaseSelectAble", false); + $smarty->assign("Release", $this->FAIrelease); + + if($this->enableReleaseManagement){ + $smarty->assign("FAIrelease", $this->FAIrelease); + $smarty->assign("Releases", $this->Releases); + + if(!$this->no_release_acls && count($this->Releases)){ + $smarty->assign("ReleaseSelectAble", true); + } + } + + /* Set acls to template */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $acl => $translation){ + $smarty->assign($acl."ACL",$this->getacl($acl,$this->no_release_acls)); + } + + /* Assign multiple edit values */ + foreach(array("apps") as $attr){ + if(in_array($attr,$this->multi_boxes)){ + $smarty->assign("use_".$attr,TRUE); + }else{ + $smarty->assign("use_".$attr,FALSE); + } + } + $smarty->assign("multiple_support",$this->multiple_support_active); + + /* Show main page */ + if (($this->dialog)){ + $smarty->assign("table", $this->table); + $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE,dirname(__FILE__))); + } else { + $display.= $smarty->fetch (get_template_path('application.tpl', TRUE,dirname(__FILE__))); + } + return ($display); + } + + + function getReleases() + { + /* Only display those releases that we are able to read */ + $dn = $this->config->current['BASE']; + $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))"; + $res = get_list($filter,"application", $dn, array("ou"), GL_SUBSEARCH); + + $ret =array(); + foreach($res as $attrs){ + if(preg_match("/".get_ou('applicationou')."/",$attrs['dn'])){ + $bb = preg_replace("/".get_ou('applicationou').".*/","",$attrs['dn']); + $parts = array_reverse(split("ou=",$bb)); + + $str =""; + foreach($parts as $part){ + if(empty($part)) { + continue; + } + $str .= str_replace(",","",$part)."/"; + } + $name = preg_replace("/\/$/","",$str); + if(empty($name)) { + $name ="/"; + } + $ret[$attrs['dn']] = $name; + } + } + natcasesort($ret); + return($ret); + } + + function save_object() + { + + /* Move category one position up or down */ + if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){ + if($_GET['act']=="cat_up"){ + $this->catUp(base64_decode($_GET['id'])); + } + if($_GET['act']=="cat_down"){ + $this->catDown(base64_decode($_GET['id'])); + } + } + + /* Move application one position up or down */ + if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){ + if(isset($_GET['id'])){ + $id = $_GET['id']; + $act = $_GET['act']; + + if($act == "one_up"){ + $this->getOneUp($id); + }elseif($act == "one_down") { + $this->getOneDown($id); + } + } + } + + + plugin::save_object(); + } + + + function remove_from_parent() + { + if(!$this->initially_was_account){ + return; + } + + plugin::remove_from_parent(); + + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $this->cleanup(); + + $ldap->modify ($this->attrs); + new log("remove","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn)); + + /* Optionally execute a command after we're done */ + $this->handle_post_events("remove"); + } + + + /* Save to LDAP */ + function save() + { + /* Skip saving application settings, if we do not have release acls */ + if($this->no_release_acls && $this->enableReleaseManagement){ + new log("security","groups/".get_class($this),$this->dn,array(),"Skip saving group application extension. Caused by insufficient acls"); + + return; + } + + plugin::save(); + + /* Copy members */ + $tmp = array("" => ""); + $tmp = array_merge($tmp,$this->Categories); + + $this->attrs["gosaMemberApplication"]= array(); + $this->attrs["gosaApplicationParameter"]= array(); + $cat_id= 0 ; + foreach($tmp as $name => $cats){ + $i =0; + if(isset($this->gosaMemberApplication[$name])){ + foreach($this->gosaMemberApplication[$name] as $entry){ + if(!preg_match("/__SEPARATOR__/",$entry['App'])){ + $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i; + $i ++; + } + } + } + if(($i==0)&&(!empty($name))){ + $this->attrs["gosaMemberApplication"][]= "|".$name."|".$cat_id; + } + $cat_id++; + } + + + + /* Are there application parameters to be saved */ + $this->attrs['gosaApplicationParameter']= array(); + foreach($this->appoption as $name => $value){ + if ($value != ""){ + $this->attrs['gosaApplicationParameter'][]= "$name:$value"; + } + } + + /* Write back to LDAP */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + + if($this->initially_was_account){ + new log("modify","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + }else{ + new log("create","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + } + + show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn)); + + /* Optionally execute a command after we're done */ + if ($this->initially_was_account == $this->is_account){ + if ($this->is_modified){ + $this->handle_post_events("modify"); + } + } else { + $this->handle_post_events("add"); + } + + } + + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + return ($message); + } + + + function reload() + { + /* Generate applist */ + $this->apps= array(); + + /* Special handling for release managed apps */ + $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs')); + if(!empty($tmp) && count($this->Releases)){ + $this->enableReleaseManagement = true; + + /* Check if release is available */ + $tmp = array_flip($this->Releases); + if(isset($tmp[$this->FAIrelease])){ + $base = $tmp[$this->FAIrelease]; + }else{ + + /* Release is not available, check if there is an alternative */ + $old_r = $this->FAIrelease; + $k = key($tmp); + + if(isset($tmp[$k])){ + + /* We have found an alternative release name */ + $r = $tmp[$k]; + $this->FAIrelease = $k; + $base = $r; + + /* Display msg */ + if(!(!$this->initially_was_account && $old_r =="/")){ + print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k)); + } + }else{ + + /* There are no releases available ... */ + print_red(_("There are no releases available. You will not be able to select another release.")); + return; + } + } + + /* Get applications for this release */ + $base = preg_replace("/".get_ou('applicationou').".*$/",get_ou('applicationou').$this->curbase,$base); + $res = get_list("(objectClass=gosaApplication)","application",$base,array("*")); + }else{ + + /* Get applications for this base */ + $res = get_list("(objectClass=gosaApplication)","application",get_ou('applicationou').$this->curbase,array("*")); + } + + /* Append applications */ + foreach($res as $attrs){ + if (isset($attrs["description"][0])){ + $this->apps[$attrs["cn"][0]]= + $attrs["cn"][0]." (". + $attrs["description"][0].")"; + } else { + $this->apps[$attrs["cn"][0]]= + $attrs["cn"][0]; + } + } + + /* Get all apps ... */ + $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn"),GL_SUBSEARCH); + $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs')); + $this->AllAppsForRelease = array(); + if(!empty($tmp)){ + $tmp = array_flip($this->Releases); + foreach($res as $attrs){ + + $testdn = preg_replace("/".get_ou('applicationou').".*$/",get_ou('applicationou'),$attrs['dn']); + $testdn = preg_replace("/^[^,]+/","",$testdn); + $testdn = preg_replace("/^,/","",$testdn); + + if($testdn == preg_replace("/".get_ou('applicationou').".*$/",get_ou('applicationou'),$tmp[$this->FAIrelease])){ + $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0]; + $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs; + } + } + }else{ + foreach($res as $attrs){ + $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0]; + } + } + + natcasesort ($this->apps); + reset ($this->apps); + + if(is_array($this->gosaMemberApplication)) + foreach ($this->gosaMemberApplication as $cat){ + if(is_array($cat)) + foreach($cat as $entry){ + $this->used_apps[$entry['App']]= $entry['App']; + } + } + } + + + function addApp($cn) + { + if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){ + foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){ + if($entry['App'] == $cn) return; + } + } + $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn); + $this->used_apps[$cn]=$cn; + $this->is_modified= TRUE; + } + + + function removeApp($cn) + { + $temp= array(); + foreach ($this->gosaMemberApplication as $value){ + if ($value != $cn){ + $temp[]= $value; + } + } + $this->gosaMemberApplication= $temp; + $this->is_modified= TRUE; + } + + function getParameters($app) + { + $tmp = $this->getReleases(); + $ret = array(); + if(in_array($this->FAIrelease,$tmp)){ + $tmp2 = array_flip($tmp); + $base = $tmp2[$this->FAIrelease]; + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter")); + if($ldap->count()){ + $attrs = $ldap->fetch(); + for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){ + $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]); + $ret[$name] = $name; + } + } + } + return($ret); + } + + function GetSubdirs($dir) + { + $ret = array(); + $tmp1 = split("/",$this->curCatDir); + + foreach($this->Categories as $path=>$cat){ + $tmp2 = split("/",$path); + + if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){ + $abort = false; + }elseif(((count($tmp1))+1) == (count($tmp2))){ + $abort = false; + for($i = 0 ; $i < count($tmp1) ; $i++){ + if($tmp1[$i] != $tmp2[$i]){ + $abort = true; + } + } + }else{ + $abort= true; + } + if(!$abort){ + $ret[$path]=$cat; + } + } + return($ret); + } + + + function PrepareForCopyPaste($source) + { + $s = new appgroup($this->config,$source['dn']); + $this->FAIrelease = $this->InitialFAIrelease = $s->FAIrelease; + $this->gosaMemberApplication = $s->gosaMemberApplication; + $this->appoption = $s->appoption; + $this->Categories = $s->Categories; + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Applications"), + "plDescription" => _("Group applications"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 0, + "plSection" => array("admin"), + "plCategory" => array("groups"), + "plProvidedAcls"=> array( + "gosaMemberApplication" => _("Application"), + "FAIrelease" => _("Release"), + "gosaApplicationParameter" => _("Application parameter")) + )); + } + + + function multiple_save_object() + { + if(isset($_POST['group_apps_multi'])){ + $this->save_object(); + plugin::multiple_save_object(); + + /* Get posts */ + foreach(array("apps") as $attr){ + if(isset($_POST['use_'.$attr])) { + $this->multi_boxes[] = $attr; + } + } + } + } + + function multiple_execute() + { + return($this->execute()); + } + + function init_multiple_support($attrs,$all) + { + // Do nothing here + } + + function get_multi_edit_values() + { + $ret = plugin::get_multi_edit_values(); + + if(in_array("apps",$this->multi_boxes)){ + $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter; + $ret['Categories'] = $this->Categories; + $ret['gosaMemberApplication'] = $this->gosaMemberApplication; + $ret['FAIrelease'] = $this->FAIrelease; + $ret['appoption'] = $this->appoption; + } + return($ret); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-core/plugins/admin/groups/class_groupApplication.inc b/gosa-core/plugins/admin/groups/class_groupApplication.inc deleted file mode 100644 index e10e4a69d..000000000 --- a/gosa-core/plugins/admin/groups/class_groupApplication.inc +++ /dev/null @@ -1,1288 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* Appgroup attributes */ - var $gosaMemberApplication= array(); - - /* Helpers */ - var $departments = ""; // All departments within $this->curbase; - var $apps = array(); // All available applications - var $used_apps = array(); // Specifies which applications are currently assigned - - var $option_name = array(); - var $option_value = array(); - var $appoption = array(); - - var $table = ""; - var $curbase = ""; - var $curCatDir ; - var $curCatDepth =0; // - var $Categories; - - /* attribute list for save action */ - var $attributes = array("gosaMemberApplication","gosaApplicationParameter"); - var $objectclasses = array("gosaApplicationGroup"); - - var $FAIrelease = "/"; - var $InitialFAIrelease = "/"; - var $Releases = array(); - var $enableReleaseManagement = false; - - var $AllAppsForRelease = array(); - var $AllAppsForReleaseParameter = array(); - var $view_logged = FALSE; - var $CopyPasteVars = array("Categories"); - var $gosaApplicationParameter ; - var $ui = NULL; - var $no_release_acls = false; - - var $multiple_support = TRUE; - - function appgroup (&$config, $dn= NULL, $parent= NULL) - { - - /* Check if we have relase mangement enabled and prepare group application for release management */ - $tmp = $config->search("faiManagement", "CLASS",array('menu','tabs')); - if(!empty($tmp)){ - $this->enableReleaseManagement = true; - $this->objectclasses [] = "FAIreleaseTag"; - $this->attributes [] = "FAIrelease"; - } - - plugin::plugin ($config, $dn, $parent); - - /* set userinfo object */ - $this->ui = get_userinfo(); - - /* Compatibility check - In some case of old applikations with old release tag saving, - we must reassign is_account state. - (Or if release management wasn't activated before creating this app) */ - if($this->enableReleaseManagement){ - - /* Release management is activated && this is a valid group app account, - but no release class was found, so activate is_account flag */ - if(isset($this->attrs['objectClass'])){ - if($dn != "new" && ( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) && - (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){ - $this->is_account =true; - } - } - } - - /* Load member applications */ - if (isset ($this->attrs["gosaMemberApplication"][0])){ - $this->gosaMemberApplication = array(); - for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){ - $this->gosaMemberApplication[]= - $this->attrs["gosaMemberApplication"][$i]; - } - } - - /* Load application options */ - if (isset($this->attrs['gosaApplicationParameter'])){ - for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){ - $option= preg_replace('/^[^:]+:/', '', - $this->attrs['gosaApplicationParameter'][$i]); - $name= preg_replace('/:.*$/', '', - $this->attrs['gosaApplicationParameter'][$i]); - $this->appoption[$name]= $option; - } - } - - /* Parse MemberApplication*/ - $tmp = array(); - $tmp2 = array(); - $prios = array(); - $cats = array(); - - foreach($this->gosaMemberApplication as $memberApp){ - if(preg_match("/\|/i",$memberApp)){ - - $tmp = split("\|",$memberApp); - - if(!empty($tmp[0])){ - $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]); - } - if(!empty($tmp[1])){ - $n = split("/",$tmp[1]); - $c = count($n); - $cats [$tmp[1]] = $n[$c-1]; - } - $prios[$tmp[1]][$tmp[2]] = $tmp[2]; - }else{ - $tmp2[]['App'] = $memberApp; - } - } - - /* Assign collected category and application settings */ - $this->Categories = $cats; - $this->gosaMemberApplication = $tmp2; - - /* Sort application by category */ - $cats[""]=""; - foreach($cats as $cat ){ - if((isset($prios[$cat]))&&(count($prios[$cat]))){ - $max = max($prios[$cat]); - $min = 1;//min($prios[$cat]); - $last = false; - for($i = $min ; $i < $max ; $i++){ - if(!isset($prios[$cat][$i])){ - if($last == false){ - $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i; - - $last = true; - } - }else{ - $last = false; - } - } - } - } - - /* Sort application by priority */ - $tmp = array(); - foreach($this->gosaMemberApplication as $key => $entries){ - ksort ($entries); - foreach($entries as $entry){ - $tmp[$key][]= $entry; - } - } - $this->gosaMemberApplication = $tmp; - $this->curbase = $this->config->current['BASE']; - - /* Get required release informations */ - if($this->enableReleaseManagement){ - $this->InitialFAIrelease = $this->FAIrelease; - $this->Releases = $this->getReleases(); - } - - } - - - /* Combine new array */ - function combineArrays($ar0,$ar1,$ar2) - { - $ret = array(); - if(is_array($ar0)) - foreach($ar0 as $ar => $a){ - $ret[$ar]=$a; - } - if(is_array($ar1)) - foreach($ar1 as $ar => $a){ - $ret[$ar]=$a; - } - if(is_array($ar2)) - foreach($ar2 as $ar => $a){ - $ret[$ar]=$a; - } - return($ret); - } - - /* Returns element position within given array */ - function getpos($atr,$attrs) - { - $i = 0; - foreach($attrs as $attr => $name) { - $i++; - if($attr == $atr){ - return($i); - } - } - return(-1); - } - - - /* Check current combination of application && release - Are all application available?, application parameter changed? ... */ - function diffAppsInReleases() - { - /* Only diff if it is required */ - $ret =array(); - - /* If current release has changed */ - if($this->FAIrelease != $this->InitialFAIrelease){ - - /* Walk through all apps which are currently displayed */ - if(isset($this->gosaMemberApplication[$this->curCatDir])){ - - foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){ - - /* If application is also available in new release, check if parameter differs */ - if(in_array($entry['App'],$this->AllAppsForRelease)){ - - $old = array(); // Old application parameter - $new = array(); // New parameters - - /* There are possibly no parameters specified */ - if(isset($this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']])){ - $old = $this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']]; - } - - if(isset($this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']])){ - $new = $this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']]; - } - - /* Both (old & new) have no gosaApplicationParameter - */ - if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){ - $ret[$entry['App']] = false; - - /* Both got gosaApplicationParameter */ - }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){ - if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){ - $ret[$entry['App']] = true; - }else{ - $ret[$entry['App']] = false; - } - } - /* Initially had gosaApplicationParameter bot in new release not */ - }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){ - $ret[$entry['App']] = true; - - /* Old release had no gosaApplicationParameter but new got some */ - }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){ - $ret[$entry['App']] = true; - } - } - } - } - return($ret); - } - - /* TRansports the geiven Arraykey one position up*/ - function ArrayUp($atr,$attrs) - { - $ret = $attrs; - $pos = $this->getpos($atr,$attrs) ; - $cn = count($attrs); - if(!(($pos == -1)||($pos == 1))){ - $before = array_slice($attrs,0,($pos-2)); - $mitte = array_reverse(array_slice($attrs,($pos-2),2)); - $unten = array_slice($attrs,$pos); - $ret = array(); - $ret = $this->combineArrays($before,$mitte,$unten); - } - return($ret); - } - - - /* TRansports the geiven Arraykey one position up*/ - function ArrayDown($atr,$attrs) - { - $ret = $attrs; - $pos = $this->getpos($atr,$attrs) ; - $cn = count($attrs); - if(!(($pos == -1)||($pos == $cn))){ - $before = array_slice($attrs,0,($pos-1)); - $mitte = array_reverse(array_slice($attrs,($pos-1),2)); - $unten = array_slice($attrs,($pos+1)); - $ret = array(); - $ret = $this->combineArrays($before,$mitte,$unten); - } - return($ret); - } - - - /* Sort category on position up */ - function catUp($id) - { - /* Get all cats depinding on current dir */ - $cats = $this->GetSubdirs($this->curCatDir); - $newcats =$this->ArrayUp($id,$cats); - foreach($newcats as $cat => $name){ - unset($this->Categories[$cat]); - } - foreach($newcats as $cat => $name){ - $this->Categories[$cat]=$name; - } - } - - - /* Sort category on position down */ - function catDown($id) - { - /* Get all cats depinding on current dir */ - $cats = $this->GetSubdirs($this->curCatDir); - $newcats =$this->ArrayDown($id,$cats); - foreach($newcats as $cat => $name){ - unset($this->Categories[$cat]); - } - foreach($newcats as $cat => $name){ - $this->Categories[$cat]=$name; - } - } - - - /* Increase application priority */ - function getOneUp($appl) - { - $cat = $this->curCatDir; - $apps = $this->gosaMemberApplication[$cat]; - $appsA = array(); - foreach ($apps as $appkey => $name){ - $appsA[$name['App']] =$name['App']; - } - $result = $this->ArrayUp($appl,$appsA); - $ret = array(); - foreach($result as $app){ - $ret[]=array("App"=>$app); - } - $this->gosaMemberApplication[$cat] = $ret; - } - - - /* Decrease application priority */ - function getOneDown($appl) - { - $cat = $this->curCatDir; - $apps = $this->gosaMemberApplication[$cat]; - $appsA = array(); - foreach ($apps as $appkey => $name){ - $appsA[$name['App']] =$name['App']; - } - $result = $this->ArrayDown($appl,$appsA); - $ret = array(); - foreach($result as $app){ - $ret[]=array("App"=>$app); - } - $this->gosaMemberApplication[$cat] = $ret; - } - - - /* Add seperator to application list */ - function AddSeperator($id) - { - $found = false; - $cat = ""; - $tmp = array(); - foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){ - $tmp[] = $app; - if(($app['App'] == $id)&&(!$found)){ - $cnt = count($this->gosaMemberApplication[$this->curCatDir]); - $tmp[] = array("App" => "__SEPARATOR__".($cnt+1)); - $found = true; - } - } - if($found){ - $this->gosaMemberApplication[$this->curCatDir]=$tmp; - } - } - - - /* Check if application acls are readable */ - function check_acls() - { - return(count($this->ui->get_module_departments("application"))); - } - - - function execute() - { - /* Call parent execute */ - plugin::execute(); - $display = ""; - - /* Log view */ - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","groups/".get_class($this),$this->dn); - } - - /* Account state settings - Skip if we are editing multiple entries */ - if(!$this->multiple_support_active){ - - /* Do we need to flip is_account state? */ - if(isset($_POST['modify_state'])){ - if($this->is_account && $this->acl_is_removeable()){ - $this->is_account= FALSE; - }elseif(!$this->is_account && $this->acl_is_createable()){ - $this->is_account= TRUE; - } - } - - /* Do we represent a valid group? */ - if (!$this->is_account && $this->parent === NULL){ - $display= "\"\" ". - _("This 'dn' is no appgroup.").""; - return ($display); - } - - /* Show tab dialog headers */ - $display= ""; - if ($this->parent !== NULL){ - if ($this->is_account){ - $display= $this->show_disable_header(_("Remove applications"), - _("This group has application features enabled. You can disable them by clicking below.")); - } else { - $display.= $this->show_enable_header(_("Create applications"), - _("This group has application features disabled. You can enable them by clicking below.")); - return ($display); - } - } - } - - /* Check acl, applications must be readable */ - if(!$this->check_acls()){ - $display .= ""._("ACL")." - "._("Insufficient permissions")." -

". - _("You do not have permission to query application entries. All your changes will not be saved."). - "

 

"; - $this->no_release_acls = true; - } - /* Check if department was selected */ - if((isset($_GET['act']))&&($_GET['act']=="depopen")){ - $dep = base64_decode($_GET['depid']); - $this->curbase =$dep; - } - - /* Check if category was selected */ - if((isset($_GET['act']))&&($_GET['act']=="open") && (empty($_GET['id']) || isset($this->Categories[base64_decode($_GET['id'])]))){ - $this->curCatDir = base64_decode($_GET['id']); - } - - - - - /* Add Categorie */ - if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){ - - /* Only allow adding a category, if it is allowed */ - if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ - - if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){ - print_red(_("Invalid character in category name.")); - }elseif(!in_array($_POST['CatName'],$this->Categories)){ - if(empty($this->curCatDir)){ - $this->Categories[$_POST['CatName']]=$_POST['CatName']; - }else{ - $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName']; - } - }else{ - print_red(_("The specified category already exists.")); - } - } - } - - - $this->reload(); - $this->diffAppsInReleases(); - - /* Check POST variables for commands - to add/remove some applications */ - $only_once = false; - if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ - - /* Walk through posts */ - foreach($_POST as $name => $value){ - - /* Add a seperator to current category */ - if((preg_match("/AddSep_/",$name))&&(!$only_once)){ - $only_once = true; - $n = preg_replace("/AddSep_/","",$name); - $val= preg_replace("/_.*$/","",$n); - $this->AddSeperator($val); - } - - /* Delete application | seperator entry */ - if((preg_match("/DelApp_/",$name))&&(!$only_once)){ - $only_once = true; - - if(preg_match("/DelApp___SEPARATOR__/",$name)) { - $n= preg_replace("/DelApp___SEPARATOR__/","",$name); - $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n); - }else{ - $n = preg_replace("/DelApp_/","",$name); - $val= preg_replace("/_.*$/","",$n); - } - - foreach($this->gosaMemberApplication as $key => $cat){ - foreach($cat as $key2 => $app){ - if($app['App'] == $val){ - unset($this->gosaMemberApplication[$key][$key2]); - if(isset($this->used_apps[$val])){ - foreach($this->getParameters($val) as $para){ - if(isset($this->appoption[$para])){ - unset($this->appoption[$para]); - } - } - unset($this->used_apps[$val]); - } - } - } - } - } - - if(preg_match("/DelCat_/",$name) && !$only_once){ - $only_once =TRUE; - $cat = preg_replace("/DelCat_/","",$name); - $cat = trim(base64_decode( preg_replace("/_.*$/","",$cat))); - - $free_apps = array(); - - if(isset($this->gosaMemberApplication[$cat]) && is_array($this->gosaMemberApplication[$cat])){ - foreach($this->gosaMemberApplication[$cat] as $app){ - $free_apps[] = $app['App']; - } - unset($this->gosaMemberApplication[$cat]); - unset($this->Categories[$cat]); - } - foreach($this->Categories as $key => $name){ - if(preg_match("/^".normalizePreg($cat)."\/.*/",$key)){ - foreach($this->gosaMemberApplication[$key] as $app){ - $free_apps[] = $app['App']; - } - unset($this->gosaMemberApplication[$key]); - unset($this->Categories[$key]); - } - } - foreach($free_apps as $app){ - if(isset($this->used_apps[$app])){ - unset($this->used_apps[$app]); - } - } - } - - /* Edit application parameter */ - if((preg_match("/EdiApp_/",$name))&&(!$only_once)){ - - $only_once = true; - $appname = $value; - $appname = preg_replace("/EdiApp_/","",$name); - $appname = preg_replace("/_.*$/","",$appname); - - /* We've got the appname, get parameters from ldap */ - $ldap= $this->config->get_ldap_link(); - - /* Check if we have release management enabled */ - $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs')); - if(!empty($tmp)){ - - /* Get application parameter from ldap */ - $tmp = array_flip($this->Releases); - $base = $tmp[$this->FAIrelease]; - $ldap->cd($base); - $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter")); - $found = ""; - while($attrs = $ldap->fetch()) { - if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){ - $found = $attrs['dn']; - } - } - $ldap->cat($found, array("gosaApplicationParameter")); - }else{ - - /* Get application parameter from ldap */ - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter")); - } - - /* Check if this application is unique */ - if ($ldap->count() != 1){ - print_red (_("The selected application name is not uniq. Please check your LDAP.")); - } else { - - /* Get parameter */ - $attrs= $ldap->fetch(); - if(isset($attrs['gosaApplicationParameter'])){ - $this->dialog= TRUE; - - /* Fill name and value arrays */ - for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){ - $option= preg_replace('/^[^:]+:/', '', - $attrs['gosaApplicationParameter'][$i]); - $name= preg_replace('/:.*$/', '', - $attrs['gosaApplicationParameter'][$i]); - $this->option_name[$i]= $name; - - /* Fill with values from application, default should be - loaded by the external scripts */ - if (isset($this->appoption[$name])){ - $this->option_value[$i]= $this->appoption[$name]; - } - } - - /* Create edit field */ - $table= ""; - for ($i= 0; $i < count($this->option_name); $i++){ - if (isset($this->option_value[$i])){ - $value= $this->option_value[$i]; - } else { - $value= ""; - } - $table.=""; - } - $table.= "
".$this->option_name[$i]."". - "
"; - $this->table= $table; - } else { - print_red (_("The selected application has no options.")); - } - } - } - } - } - - /* Add multiple */ - if(isset($_POST['AddApps'])){ - foreach($_POST as $name => $value){ - if(preg_match("/AddApp_/",$name)){ - $app = preg_replace("/AddApp_/","",$name); - $this->addApp($app); - } - } - } - - /* Add application with post */ - if((isset($_GET['act']))&&($_GET['act']=="add")){ - $this->used_apps[$_GET['id']]= $_GET['id']; - asort($this->used_apps); - $this->addApp($_GET['id']); - } - - /* Cancel edit options? */ - if (isset($_POST['edit_options_cancel'])){ - $this->dialog= FALSE; - } - - /* Finish edit options? */ - if (isset($_POST['edit_options_finish'])){ - $this->dialog= FALSE; - - /* Save informations passed by the user */ - $this->option_value= array(); - for ($i= 0; $ioption_name); $i++){ - $this->appoption[$this->option_name[$i]]= $_POST["value$i"]; - $this->is_modified= TRUE; - } - } - - /* Prepare templating stuff */ - $smarty= get_smarty(); - $smarty->assign("used_apps", $this->used_apps); - $apps= array(); - foreach ($this->apps as $key => $value){ - if (!array_key_exists($key, $this->used_apps)){ - $apps["$key"]= "$value"; - } - } - - - /* Create application list */ - $div = new divSelectBox("appgroup"); - $div->SetHeight(300); - $departments = array(); - $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT); - foreach($res as $value){ - $fdn = $value['dn']; - $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn); - $fdn= @LDAP::fix($fdn); - if($value["description"][0]!=".."){ - $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]"; - }else{ - $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]"; - } - } - - /* Create 'open' and 'add' links */ - if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ - $linkadd = "%s"; - }else{ - $linkadd = "%s"; - } - $linkopen = "%s"; - - /* Create base back entry */ - $base_back = preg_replace("/^[^,]+,/","",$this->curbase); - if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){ - $div->AddEntry(array( - array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"), - "attach"=>"style='border:0px;'") - )); - } - - /* Append departments for current base */ - foreach($departments as $key => $app){ - $div->AddEntry(array( - array("string"=>""._("department")." ".sprintf($linkopen,base64_encode($key),$app), - "attach"=>"style='border:0px;'") - )); - } - - /* Add applications found on this base */ - foreach($apps as $key => $app){ - $div->AddEntry(array( - array("string"=>sprintf("",$key). - ""._("application")." ".sprintf($linkadd,$key,$app), - "attach"=>"style='border:0px;'") - )); - } - - /* Create list of used/assigned applications */ - $div2 = new divSelectBox("appgroup"); - $div2->SetHeight(300); - - /* Check acls to create "edit/remove" category links */ - if(!$this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ - $linkopen = "\"\" %s"; - $catremove = "  "; - $catupdown = ""; - }else{ - $linkopen = "\"\" %s"; - $catremove = " "; - $catupdown = "". - "\"\"". - " ". - "". - "\"\"". - ""; - } - - /* Add back category for current category */ - if(empty($this->curCatDir)){ - $cnt =0; - }else{ - $cnt = count(split("/",$this->curCatDir)); - $tmp = split("/",$this->curCatDir); - $bbk = ""; - for($i = 0 ; $i < ($cnt -1 ) ; $i++){ - $bbk .= $tmp[$i]."/"; - } - $bbk = preg_replace("/\/$/","",$bbk); - $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),".. ["._("Back")."]")),array("string"=>" ","attach"=>"style='border-right:0px;'"))); - } - - /* Add sub categories */ - $this->GetSubdirs($this->curCatDir); - foreach($this->GetSubdirs($this->curCatDir) as $path => $name){ - $div2 ->AddEntry(array( - array("string"=>sprintf($linkopen,base64_encode($path),$name)), - array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove), - "attach"=>"align='right' style='width:80px;border-right:0px;'"))); - } - - /* Create priority & seperator links */ - $separator ="
"; - if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ - $sep = ""; - $upudown = "". - " {t}sort{/t}". - " ". - "". - " {t}sort{/t}". - " ". - ""; - }else{ - $sep = ""; - $upudown = ""; - } - - /* Create edit link */ - if($this->acl_is_writeable("gosaApplicationParameter",$this->no_release_acls)){ - $edit= " "; - }else{ - $edit= ""; - } - - /* Get differences to mark those entries that have changed from last edit. */ - $Differences = $this->diffAppsInReleases(); - - /* Walk through entries an append them to list */ - if(isset($this->gosaMemberApplication[$this->curCatDir])){ - foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){ - - /* Add seperator */ - if(preg_match("/__SEPARATOR__/",$entry['App'])){ - $div2 ->AddEntry(array(array("string"=>$separator), - array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'"))); - }else{ - - /* Add application */ - - $image = ""; - /* Check if application was available within selected release - * or application list if release management is not active - */ - if(!in_array($entry['App'],$this->AllAppsForRelease)){ - - /* release managent is active - */ - if(!$this->enableReleaseManagement){ - $image = "R "; - }else{ - $image = "FFAIrelease)."\"> "; - } - - }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) { - $entry['App'].=" ["._("Check parameter")."]"; - $image = " "; - }else{ - $image = "\"\" "; - } - - $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])), - array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown), - "attach"=>"align='right' style='width:100px;border-right:0px;'"))); - } - } - } - - /* Assign created div lists to template */ - $smarty->assign("UsedApps", $div2->DrawList()); - $smarty->assign("List", $div->DrawList()); - $smarty->assign("apps", $apps); - - $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement); - - $smarty->assign("ReleaseSelectAble", false); - $smarty->assign("Release", $this->FAIrelease); - - if($this->enableReleaseManagement){ - $smarty->assign("FAIrelease", $this->FAIrelease); - $smarty->assign("Releases", $this->Releases); - - if(!$this->no_release_acls && count($this->Releases)){ - $smarty->assign("ReleaseSelectAble", true); - } - } - - /* Set acls to template */ - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $acl => $translation){ - $smarty->assign($acl."ACL",$this->getacl($acl,$this->no_release_acls)); - } - - /* Assign multiple edit values */ - foreach(array("apps") as $attr){ - if(in_array($attr,$this->multi_boxes)){ - $smarty->assign("use_".$attr,TRUE); - }else{ - $smarty->assign("use_".$attr,FALSE); - } - } - $smarty->assign("multiple_support",$this->multiple_support_active); - - /* Show main page */ - if (($this->dialog)){ - $smarty->assign("table", $this->table); - $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE,dirname(__FILE__))); - } else { - $display.= $smarty->fetch (get_template_path('application.tpl', TRUE,dirname(__FILE__))); - } - return ($display); - } - - - function getReleases() - { - /* Only display those releases that we are able to read */ - $dn = $this->config->current['BASE']; - $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))"; - $res = get_list($filter,"application", $dn, array("ou"), GL_SUBSEARCH); - - $ret =array(); - foreach($res as $attrs){ - if(preg_match("/".get_ou('applicationou')."/",$attrs['dn'])){ - $bb = preg_replace("/".get_ou('applicationou').".*/","",$attrs['dn']); - $parts = array_reverse(split("ou=",$bb)); - - $str =""; - foreach($parts as $part){ - if(empty($part)) { - continue; - } - $str .= str_replace(",","",$part)."/"; - } - $name = preg_replace("/\/$/","",$str); - if(empty($name)) { - $name ="/"; - } - $ret[$attrs['dn']] = $name; - } - } - natcasesort($ret); - return($ret); - } - - function save_object() - { - - /* Move category one position up or down */ - if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){ - if($_GET['act']=="cat_up"){ - $this->catUp(base64_decode($_GET['id'])); - } - if($_GET['act']=="cat_down"){ - $this->catDown(base64_decode($_GET['id'])); - } - } - - /* Move application one position up or down */ - if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){ - if(isset($_GET['id'])){ - $id = $_GET['id']; - $act = $_GET['act']; - - if($act == "one_up"){ - $this->getOneUp($id); - }elseif($act == "one_down") { - $this->getOneDown($id); - } - } - } - - - plugin::save_object(); - } - - - function remove_from_parent() - { - if(!$this->initially_was_account){ - return; - } - - plugin::remove_from_parent(); - - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $this->cleanup(); - - $ldap->modify ($this->attrs); - new log("remove","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn)); - - /* Optionally execute a command after we're done */ - $this->handle_post_events("remove"); - } - - - /* Save to LDAP */ - function save() - { - /* Skip saving application settings, if we do not have release acls */ - if($this->no_release_acls && $this->enableReleaseManagement){ - new log("security","groups/".get_class($this),$this->dn,array(),"Skip saving group application extension. Caused by insufficient acls"); - - return; - } - - plugin::save(); - - /* Copy members */ - $tmp = array("" => ""); - $tmp = array_merge($tmp,$this->Categories); - - $this->attrs["gosaMemberApplication"]= array(); - $this->attrs["gosaApplicationParameter"]= array(); - $cat_id= 0 ; - foreach($tmp as $name => $cats){ - $i =0; - if(isset($this->gosaMemberApplication[$name])){ - foreach($this->gosaMemberApplication[$name] as $entry){ - if(!preg_match("/__SEPARATOR__/",$entry['App'])){ - $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i; - $i ++; - } - } - } - if(($i==0)&&(!empty($name))){ - $this->attrs["gosaMemberApplication"][]= "|".$name."|".$cat_id; - } - $cat_id++; - } - - - - /* Are there application parameters to be saved */ - $this->attrs['gosaApplicationParameter']= array(); - foreach($this->appoption as $name => $value){ - if ($value != ""){ - $this->attrs['gosaApplicationParameter'][]= "$name:$value"; - } - } - - /* Write back to LDAP */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $this->cleanup(); - $ldap->modify ($this->attrs); - - if($this->initially_was_account){ - new log("modify","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - }else{ - new log("create","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - } - - show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn)); - - /* Optionally execute a command after we're done */ - if ($this->initially_was_account == $this->is_account){ - if ($this->is_modified){ - $this->handle_post_events("modify"); - } - } else { - $this->handle_post_events("add"); - } - - } - - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); - - return ($message); - } - - - function reload() - { - /* Generate applist */ - $this->apps= array(); - - /* Special handling for release managed apps */ - $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs')); - if(!empty($tmp) && count($this->Releases)){ - $this->enableReleaseManagement = true; - - /* Check if release is available */ - $tmp = array_flip($this->Releases); - if(isset($tmp[$this->FAIrelease])){ - $base = $tmp[$this->FAIrelease]; - }else{ - - /* Release is not available, check if there is an alternative */ - $old_r = $this->FAIrelease; - $k = key($tmp); - - if(isset($tmp[$k])){ - - /* We have found an alternative release name */ - $r = $tmp[$k]; - $this->FAIrelease = $k; - $base = $r; - - /* Display msg */ - if(!(!$this->initially_was_account && $old_r =="/")){ - print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k)); - } - }else{ - - /* There are no releases available ... */ - print_red(_("There are no releases available. You will not be able to select another release.")); - return; - } - } - - /* Get applications for this release */ - $base = preg_replace("/".get_ou('applicationou').".*$/",get_ou('applicationou').$this->curbase,$base); - $res = get_list("(objectClass=gosaApplication)","application",$base,array("*")); - }else{ - - /* Get applications for this base */ - $res = get_list("(objectClass=gosaApplication)","application",get_ou('applicationou').$this->curbase,array("*")); - } - - /* Append applications */ - foreach($res as $attrs){ - if (isset($attrs["description"][0])){ - $this->apps[$attrs["cn"][0]]= - $attrs["cn"][0]." (". - $attrs["description"][0].")"; - } else { - $this->apps[$attrs["cn"][0]]= - $attrs["cn"][0]; - } - } - - /* Get all apps ... */ - $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn"),GL_SUBSEARCH); - $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs')); - $this->AllAppsForRelease = array(); - if(!empty($tmp)){ - $tmp = array_flip($this->Releases); - foreach($res as $attrs){ - - $testdn = preg_replace("/".get_ou('applicationou').".*$/",get_ou('applicationou'),$attrs['dn']); - $testdn = preg_replace("/^[^,]+/","",$testdn); - $testdn = preg_replace("/^,/","",$testdn); - - if($testdn == preg_replace("/".get_ou('applicationou').".*$/",get_ou('applicationou'),$tmp[$this->FAIrelease])){ - $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0]; - $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs; - } - } - }else{ - foreach($res as $attrs){ - $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0]; - } - } - - natcasesort ($this->apps); - reset ($this->apps); - - if(is_array($this->gosaMemberApplication)) - foreach ($this->gosaMemberApplication as $cat){ - if(is_array($cat)) - foreach($cat as $entry){ - $this->used_apps[$entry['App']]= $entry['App']; - } - } - } - - - function addApp($cn) - { - if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){ - foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){ - if($entry['App'] == $cn) return; - } - } - $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn); - $this->used_apps[$cn]=$cn; - $this->is_modified= TRUE; - } - - - function removeApp($cn) - { - $temp= array(); - foreach ($this->gosaMemberApplication as $value){ - if ($value != $cn){ - $temp[]= $value; - } - } - $this->gosaMemberApplication= $temp; - $this->is_modified= TRUE; - } - - function getParameters($app) - { - $tmp = $this->getReleases(); - $ret = array(); - if(in_array($this->FAIrelease,$tmp)){ - $tmp2 = array_flip($tmp); - $base = $tmp2[$this->FAIrelease]; - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter")); - if($ldap->count()){ - $attrs = $ldap->fetch(); - for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){ - $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]); - $ret[$name] = $name; - } - } - } - return($ret); - } - - function GetSubdirs($dir) - { - $ret = array(); - $tmp1 = split("/",$this->curCatDir); - - foreach($this->Categories as $path=>$cat){ - $tmp2 = split("/",$path); - - if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){ - $abort = false; - }elseif(((count($tmp1))+1) == (count($tmp2))){ - $abort = false; - for($i = 0 ; $i < count($tmp1) ; $i++){ - if($tmp1[$i] != $tmp2[$i]){ - $abort = true; - } - } - }else{ - $abort= true; - } - if(!$abort){ - $ret[$path]=$cat; - } - } - return($ret); - } - - - function PrepareForCopyPaste($source) - { - $s = new appgroup($this->config,$source['dn']); - $this->FAIrelease = $this->InitialFAIrelease = $s->FAIrelease; - $this->gosaMemberApplication = $s->gosaMemberApplication; - $this->appoption = $s->appoption; - $this->Categories = $s->Categories; - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Applications"), - "plDescription" => _("Group applications"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 0, - "plSection" => array("admin"), - "plCategory" => array("groups"), - "plProvidedAcls"=> array( - "gosaMemberApplication" => _("Application"), - "FAIrelease" => _("Release"), - "gosaApplicationParameter" => _("Application parameter")) - )); - } - - - function multiple_save_object() - { - if(isset($_POST['group_apps_multi'])){ - $this->save_object(); - plugin::multiple_save_object(); - - /* Get posts */ - foreach(array("apps") as $attr){ - if(isset($_POST['use_'.$attr])) { - $this->multi_boxes[] = $attr; - } - } - } - } - - function multiple_execute() - { - return($this->execute()); - } - - function init_multiple_support($attrs,$all) - { - // Do nothing here - } - - function get_multi_edit_values() - { - $ret = plugin::get_multi_edit_values(); - - if(in_array("apps",$this->multi_boxes)){ - $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter; - $ret['Categories'] = $this->Categories; - $ret['gosaMemberApplication'] = $this->gosaMemberApplication; - $ret['FAIrelease'] = $this->FAIrelease; - $ret['appoption'] = $this->appoption; - } - return($ret); - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/groups/class_groupMail.inc b/gosa-core/plugins/admin/groups/class_groupMail.inc deleted file mode 100644 index 6f0758355..000000000 --- a/gosa-core/plugins/admin/groups/class_groupMail.inc +++ /dev/null @@ -1,1350 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - var $uid = ""; // User id - var $cn = ""; // cn - var $orig_cn = ""; // cn - - var $method = "mailMethod"; // Used Mail method - var $mmethod = ""; // Contains the gosa.conf MAILMETHOD - var $mail = ""; // Default mail address - - var $gosaMailAlternateAddress = array(); // Set default Alternate Mail Adresses to empty array - var $gosaMailForwardingAddress = array(); // Forwarding also empty - - var $gosaMailForwardingAddress_Some = array(); // Used in multiple edit - - var $gosaMailServer = ""; // Selected mailserver - var $gosaMailQuota = ""; // Defined Quota - var $quotaUsage = 0; // Currently used quota - - var $gosaVacationMessage = ""; // Vocation message - - var $imapacl = array('anyone' => 'p', // Set acls for everyone - '%members%' => 'lrswp', // %members% are all group-members - '' => 'p'); // Every user added gets this right - - var $kolabFolderType_SubType = ""; - var $kolabFolderType_Type = ""; - - var $gosaSpamSortLevel = ""; - var $gosaSpamMailbox = ""; - var $gosaSharedFolderTarget ; - - var $forward_dialog = FALSE; - - var $members = array(); // Group members - - var $mailusers = array(); - var $perms = array(); - var $gosaMailDeliveryMode = "[L ]"; // - var $gosaMailMaxSize = ""; // - - var $remove_folder_from_imap = true; - - /* Helper */ - var $indexed_acl= array(); - var $indexed_user= array(); - - var $view_logged = FALSE; - - /* attribute list for save action */ - var $attributes= array( "mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize", - "gosaMailAlternateAddress", "gosaMailForwardingAddress", - "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox", - "acl","gosaSharedFolderTarget", "gosaVacationMessage"); - - var $objectclasses= array("gosaMailAccount"); - var $CopyPasteVars = array("quotaUsage","imapacl"); - - var $multiple_support = TRUE; - - function mailgroup (&$config, $dn= NULL, $ui= NULL) - { - /* Initialise all available attributes ... if possible - */ - plugin::plugin($config, $dn); - $this->orig_cn = $this->cn; - - /* Set mailMethod to the one defined in gosa.conf - */ - if (isset($this->config->current['MAILMETHOD'])){ - $this->mmethod= $this->config->current['MAILMETHOD']; - } - - /* Check if selected mail method exists - */ - $cls = get_correct_class_name("mailMethod$this->mmethod"); - if ($cls && class_exists($cls)){ - $this->method= $cls; - } else { - print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod)); - } - - /* Load Mailserver - */ - if(isset($this->attrs['gosaMailServer'][0])){ - $this->gosaMailServer = $this->attrs['gosaMailServer'][0]; - } - - /* Convert cn to uid in case of existing entry - */ - if (isset($this->attrs['cn'][0])){ - $this->uid= $this->attrs['cn'][0]; - } - - /* Get folder type */ - if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ - if(isset($this->attrs['kolabFolderType'])){ - $tmp = split("\.",$this->attrs['kolabFolderType'][0]); - $this->kolabFolderType_Type = $tmp[0]; - $this->kolabFolderType_SubType = $tmp[1]; - } - } - - /* If this isn't a new mailgroup, read all required data from ldap - */ - if (($dn != "new")&&($dn !== NULL)){ - - /* Load attributes which represent multiple entries - */ - foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){ - $this->$val = array(); - if (isset($this->attrs["$val"]["count"])){ - for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){ - array_push($this->$val, $this->attrs["$val"][$i]); - } - } - } - - /* Only do IMAP actions if gosaMailServer attribute is set - */ - if (isset ($this->attrs["gosaMailServer"][0])){ - - /* Create new instance of our defined mailclass - */ - $method= new $this->method($this->config); - if ($method->connect($this->attrs["gosaMailServer"][0])){ - - /* If we do NOT use kolab or equal methods, - read imap the acls from the mail method class. - They will be merged later with the ldap specified acls. - */ - if(!preg_match("/olab/i",$this->mmethod) && !empty($this->mmethod)){ - $this->imapacl= $method->getSharedFolderPermissions($this->uid); - - /* Need to filter what a member acl could be... */ - $vote= array(); - $peak= 0; - $leader= ""; - foreach ($this->imapacl as $user => $acl){ - - if ($user != "anyone" ){ - if (!isset($vote[$acl])){ - $vote[$acl]= 1; - } else { - $vote[$acl]++; - } - if ($vote[$acl] > $peak){ - $leader= $acl; - $peek= $vote[$acl]; - } - } - } - /* Highest count wins as %members%, remove all members - with the same acl */ - if(!empty($leader)){ - $this->imapacl['%members%']= $leader; - } - foreach ($this->imapacl as $user => $acl){ - if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){ - unset($this->imapacl[$user]); - } - } - } - - /* Adapt attributes if needed */ - $method->fixAttributesOnLoad($this); - - /* get Quota */ - $quota= $method->getQuota($this->uid); - - /* Update quota values */ - if(is_array($quota)){ - if ($quota['gosaMailQuota'] == 2147483647){ - $this->quotaUsage= ""; - $this->gosaMailQuota= ""; - } else { - $this->quotaUsage= $quota['quotaUsage']; - $this->gosaMailQuota= $quota['gosaMailQuota']; - } - }else{ - $this->quotaUsage = ""; - $this->gosaMailQuota = ""; - } - $method->disconnect(); - } // ENDE $method->connect($this->attrs["gosaMailServer"][0])){ - } // ENDE gosaMailServer - } // ENDE dn != "new" - - - /* Get global filter config */ - if (!session::is_set("gmailfilter")){ - $ui= get_userinfo(); - $base= get_base_from_people($ui->dn); - $gmailfilter= array( "depselect" => $base, - "muser" => "", - "regex" => "*"); - session::set("gmailfilter", $gmailfilter); - } - - /* Load permissions */ - $tmp = array(); - $ldap = $this->config->get_ldap_link(); - - /* Read acls from ldap and merge them with - * acls read from mail method. - */ - if (isset($this->attrs['acl'])){ - - for ($i= 0; $i<$this->attrs['acl']['count']; $i++){ - list($user, $permission)= split(' ', $this->attrs['acl'][$i]); - - /* Add to list */ - $this->imapacl[$user]= $permission; - - /* Get all user permissions sorted by acl, to detect the most used acl - This acl is then used for %members% - */ - if ($user != "anyone" && $user != "%members%"){ - $tmp[$permission][] = $user; - } - - /* There is an entry in $this->imapacl like this this ... - $this->attrs['imapacl']['anyone'] = "p"; - $this->attrs['imapacl']['%members%'] = "lprs"; - $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty - Field for special acls in our template. - If there is at least one special acl in out imapacl, - we don't need this entry anymore, because it is already displayed. - */ - if ($user != "anyone" && $user != "%members%"){ - unset($this->imapacl['']); - } - } - } - - /** - * Detect group members which use the same acl - * as used for %members% and remove them. - **/ - - /* In this section we detect which acl is the most used. - This will be used as %members% acl. - */ - $tmp2 = array(); - foreach($tmp as $acl => $user){ - $tmp2[count($tmp[$acl])]=$acl; - } - /* Most used at last - */ - ksort($tmp2); - - /* Assign last (most used acl) to %members% acl - */ - $str = array_pop($tmp2); - if(!empty($str)) { - $this->imapacl['%members%']=$str; - } - if(!isset($this->imapacl['%members%'])){ - $this->imapacl['%members%'] = "lrspw"; - } - - - /* Open ldap connection - */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - - /* Remove those users, that use %members% acl && are member of this group. */ - foreach($this->imapacl as $mail => $permission){ - $ldap->search("(&(objectClass=person)(|(mail=".$mail.")(uid=".$mail.")))",array("uid")); - $atr = $ldap->fetch(); - if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){ - if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){ - unset($this->imapacl[$mail]); - } - } - } - - /** - * ENDE: Detect group member with same acl and replace them with %members% - **/ - $this->indexed_user = array("%members%","anyone"); - - /* Append an empty entry, for special acl handling */ - if(count($this->imapacl)==2){ - $this->imapacl[''] ="lrsw"; - $this->indexed_user[] = ''; - } - - /* Load Mailserver - */ - if(isset($this->attrs['gosaMailServer'][0])){ - $this->gosaMailServer = $this->attrs['gosaMailServer'][0]; - } - /* Fill translations */ - $this->perms["lrsw"]= _("read"); - $this->perms["lrswp"]= _("post"); - $this->perms["p"]= _("external post"); - $this->perms["lrswip"]= _("append"); - $this->perms["lrswipcd"]= _("write"); - $this->perms["lrswipcda"]= _("admin"); - $this->perms[""]= _("none"); - } - - - - function execute() - { - /* Call parent execute */ - //plugin::execute(); - $display = ""; - - /* Log view */ - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","groups/".get_class($this),$this->dn); - } - - /* Load templating engine */ - $smarty= get_smarty(); - - /* Assign acls */ - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translation) { - $smarty->assign($name."ACL",$this->getacl($name)); - } - - if (session::get('js')==FALSE){ - $smarty->assign("javascript", "false"); - } else { - $smarty->assign("javascript", "true"); - } - - /* Handle actions should not be done, when - * editing multiple entries at once. e.g. account state - */ - if(!$this->multiple_support_active){ - - /* Do we need to flip is_account state? */ - if(isset($_POST['modify_state'])){ - if($this->is_account && $this->acl_is_removeable()){ - $this->is_account= FALSE; - }elseif(!$this->is_account && $this->acl_is_createable()){ - $this->is_account= TRUE; - } - } - - $display = ""; - - /* Do we represent a valid account? */ - if (!$this->is_account && $this->parent === NULL){ - - $display.= "\"\" ". - _("This 'dn' has no valid mail extensions.").""; - return ($display); - } - - /* Show tab dialog headers */ - $display= ""; - if ($this->parent !== NULL){ - if ($this->is_account){ - $display.= $this->show_disable_header(_("Remove mail account"), - _("This account has mail features enabled. You can disable them by clicking below.")); - } else { - $display.= $this->show_enable_header(_("Create mail account"), - _("This account has mail features disabled. You can enable them by clicking below.")); - - /* Show checkbox that allows us to remove imap entry too*/ - if($this->initially_was_account){ - $c = ""; - if($this->remove_folder_from_imap){ - $c= " checked "; - } - $display .= "

Shared folder delete options

- "; - $display .= _("Remove the shared folder and all its contents after saving this account"); - } - return ($display); - } - } - } - - /* Add ACL? */ - if($this->acl_is_writeable("acl")){ - foreach ($this->indexed_user as $nr => $user){ - if (isset($_POST["add_$nr"])){ - $this->imapacl[""]= "l"; - } - if (isset($_POST["del_$nr"])){ - unset ($this->imapacl[$user]); - } - } - } - - /* Trigger forward add dialog? */ - if($this->acl_is_writeable("gosaMailForwardingAddress")){ - if (isset($_POST['add_local_forwarder'])){ - $this->forward_dialog= TRUE; - $this->dialog= TRUE; - } - } - - /* Cancel forward add dialog? */ - if($this->acl_is_writeable("gosaMailForwardingAddress")){ - if (isset($_POST['add_locals_cancel'])){ - $this->forward_dialog= FALSE; - $this->dialog= FALSE; - } - } - - /* Finished adding of locals? */ - if ((isset($_POST['add_locals_finish'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))) { - if (count ($_POST['local_list']) && $this->acl_is_writeable("gosaMailForwardingAddress")){ - - /* Walk through list of forwarders, ignore own addresses */ - foreach ($_POST['local_list'] as $val){ - if (!in_array ($val, $this->gosaMailAlternateAddress) && - $val != $this->mail){ - - $this->addForwarder($val); - } - } - } - $this->forward_dialog= FALSE; - $this->dialog= FALSE; - } - - /* Add forward email addresses */ - if ((isset($_POST['add_forwarder'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){ - if ($_POST['forward_address'] != ""){ - - /* Valid email address specified? */ - $address= $_POST['forward_address']; - if (!tests::is_email($address)){ - - print_red (_("You're trying to add an invalid email address ". - "to the list of forwarders.")); - - } elseif ($address == $this->mail - || in_array($address, $this->gosaMailAlternateAddress)) { - - print_red (_("Adding your one of your own addresses to the forwarders makes no sense.")); - - } else { - - /* Add it */ - if ($this->acl_is_writeable("gosaMailForwardingAddress")){ - $this->addForwarder ($address); - } - - } - } - } - - /* Delete forward email addresses */ - if (isset($_POST['delete_forwarder']) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){ - if (count($_POST['forwarder_list'])&& $this->acl_is_writeable("gosaMailForwardingAddress")){ - - $this->delForwarder ($_POST['forwarder_list']); - } - } - - /* Add alternate email addresses */ - if (isset($_POST['add_alternate'])){ - if ($_POST['alternate_address'] != "" && $this->acl_is_writeable("gosaMailAlternateAddress")){ - - if (!tests::is_email($_POST['alternate_address'])){ - print_red (_("You're trying to add an invalid email address to the list of alternate addresses.")); - - } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){ - $ui= get_userinfo(); - if ($user != $ui->username){ - print_red (_("The address you're trying to add is already used by user")." '$user'."); - } - } - } - } - - /* Delete alternate email addresses */ - if($this->acl_is_writeable("gosaMailAlternateAddress")){ - if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){ - if (count($_POST['alternates_list']) && $this->acl_is_writeable("gosaMailAlternateAddress")){ - $this->delAlternate ($_POST['alternates_list']); - } - } - } - - /* Show forward add dialog */ - if ($this->forward_dialog){ - $ldap= $this->config->get_ldap_link(); - - /* Save data */ - $gmailfilter= session::get("gmailfilter"); - foreach( array("depselect", "muser", "regex") as $type){ - if (isset($_POST[$type])){ - $gmailfilter[$type]= $_POST[$type]; - } - } - if (isset($_GET['search'])){ - $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*"; - if ($s == "**"){ - $s= "*"; - } - $gmailfilter['regex']= $s; - } - session::set("gmailfilter", $gmailfilter); - - /* Get actual list */ - $mailusers= array (); - if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){ - $regex= $gmailfilter['regex']; - $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))"; - } else { - $filter= ""; - } - if ($gmailfilter['muser'] != ""){ - $user= $gmailfilter['muser']; - $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))"; - } - - /* Add already present people to the filter */ - $exclude= ""; - foreach ($this->gosaMailForwardingAddress as $mail){ - $exclude.= "(mail=$mail)"; - } - if ($exclude != ""){ - $filter.= "(!(|$exclude))"; - } - - $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $gmailfilter['depselect'], - array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT); - $ldap->cd($gmailfilter['depselect']); - $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName")); - error_reporting (0); - while ($attrs= $ldap->fetch()){ - if(preg_match('/%/', $attrs['mail'][0])){ - continue; - } - $name= $this->make_name($attrs); - $mailusers[$attrs['mail'][0]]= $name."<". - $attrs['mail'][0].">"; - } - error_reporting (E_ALL | E_STRICT); - natcasesort ($mailusers); - reset ($mailusers); - - /* Show dialog */ - $smarty->assign("search_image", get_template_path('images/search.png')); - $smarty->assign("usearch_image", get_template_path('images/search_user.png')); - $smarty->assign("tree_image", get_template_path('images/tree.png')); - $smarty->assign("infoimage", get_template_path('images/info.png')); - $smarty->assign("launchimage", get_template_path('images/small_filter.png')); - $smarty->assign("mailusers", $mailusers); - $smarty->assign("deplist", $this->config->idepartments); - $smarty->assign("apply", apply_filter()); - $smarty->assign("alphabet", generate_alphabet()); - $smarty->assign("hint", print_sizelimit_warning()); - foreach( array("depselect", "muser", "regex") as $type){ - $smarty->assign("$type", $gmailfilter[$type]); - } - $smarty->assign("hint", print_sizelimit_warning()); - $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE)); - return ($display); - } - - /* Assemble normal permissions */ - if (isset($this->imapacl['anyone'])){ - $smarty->assign("default_permissions", $this->imapacl['anyone']); - } - $smarty->assign("member_permissions", "lrsp"); - if (isset($this->imapacl['%members%'])){ - $smarty->assign("member_permissions", $this->imapacl['%members%']); - } - - /* Assemble extra attributes */ - $perm= $this->getacl( "permissions"); - $tmp= ""; - $nr= 0; - $count= count($this->imapacl); - $this->indexed_user= array(); - $this->indexed_acl= array(); - foreach($this->imapacl as $user => $acl){ - - /* Add additional acl settings */ - if ($user != "anyone" && $user != "%members%"){ - - $Dis = ""; - if(!preg_match("/w/",$perm)){ - $Dis = " disabled "; - } - - /* Reset given Acls to ensure that nobody can read username and acls if not allwoed */ - if(!preg_match("/r/",$perm)){ - $user = ""; - $nr = "none"; - $key = "none"; - } - - $tmp.= " - - - - -  "; - - - - if ($nr == $count - 1){ - if($this->acl_is_writeable("acl")){ - $tmp.= ""; - } - } - if ($count > 3){ - if($this->acl_is_writeable("acl")){ - $tmp.= ""; - } - } - } - $this->indexed_user[$nr]= $user; - $this->indexed_acl[$nr++]= $acl; - } - $smarty->assign("plusattributes", $tmp); - - /* Show main page */ - $mailserver= array(); - foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){ - $mailserver[]= $key; - } - $smarty->assign("mailServers", $mailserver); - foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail", - "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){ - $smarty->assign("$val", $this->$val); - } - if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){ - if($this->acl_is_readable("gosaMailQuota")){ - $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true)); - $smarty->assign("quotadefined", "true"); - }else{ - $smarty->assign("quotadefined", "true"); - $smarty->assign("quotausage", "-"); - } - } else { - $smarty->assign("quotadefined", "false"); - } - - if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ - - $smarty->assign("kolab", TRUE); - $smarty->assign("JS",session::get('js')); - $smarty->assign("kolabFolderType_Types", array ( '' => _('Unspecified'), 'mail' => _('Mails'), - 'task' => _('Tasks') , 'journal' => _('Journals'), - 'calendar' => _('Calendar'), 'contact' => _('Contacts'), - 'note' => _('Notes'))); - if($this->kolabFolderType_Type == "mail"){ - $smarty->assign("kolabFolderType_SubTypes", array( - '' => _('Unspecified'), 'inbox' => _("Inbox") , - 'drafts' => _("Drafts"), 'sentitems' => _("Sent items"), - 'junkemail' => _("Junk mail"))); - }else{ - $smarty->assign("kolabFolderType_SubTypes", array( 'default' => _("Default"))); - } - $smarty->assign("kolabFolderType_Type", $this->kolabFolderType_Type); - $smarty->assign("kolabFolderType_SubType", $this->kolabFolderType_SubType); - }else{ - $smarty->assign("kolab", FALSE); - } - - /* Multiple support handling */ - foreach($this->attributes as $attr){ - if(in_array($attr,$this->multi_boxes)){ - $smarty->assign("use_".$attr,TRUE); - }else{ - $smarty->assign("use_".$attr,FALSE); - } - } - - /* Multiple support handling */ - foreach(array("kolabFolderType") as $attr){ - if(in_array($attr,$this->multi_boxes)){ - $smarty->assign("use_".$attr,TRUE); - }else{ - $smarty->assign("use_".$attr,FALSE); - } - } - - $smarty->assign("Forward_all",$this->gosaMailForwardingAddress); - $smarty->assign("Forward_some",$this->gosaMailForwardingAddress_Some); - - $smarty->assign("multiple_support",$this->multiple_support_active); - $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE)); - return ($display); - } - - - /* remove object from parent */ - function remove_from_parent() - { - if(!$this->initially_was_account){ - return; - } - - /* Added these ObjectClass and Attributes, because they were not - removed correctly, only in case of kolab ... - */ - if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ - $this->attributes[]="acl"; - $this->objectclasses[] = "kolabSharedFolder"; - } - /* include global link_info */ - $ldap= $this->config->get_ldap_link(); - - /* Remove and write to LDAP */ - plugin::remove_from_parent(); - - /* Zero arrays */ - $this->attrs['gosaMailAlternateAddress']= array(); - $this->attrs['gosaMailForwardingAddress']= array(); - $this->attrs['gosaSharedFolderTarget']= array(); - - /* Connect to IMAP server for account deletion */ - if ($this->initially_was_account){ - - $method= new $this->method($this->config); - $method->fixAttributesOnRemove($this); - if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){ - - /* Remove account from IMAP server */ - $method->deleteMailbox($this->uid); - $method->disconnect(); - } - } - /* Keep uid */ - unset ($this->attrs['uid']); - - $ldap->cd($this->dn); - $ldap->modify ($this->attrs); - show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/mail with dn '%s' failed."),$this->dn)); - - - new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - - /* Optionally execute a command after we're done */ - $this->handle_post_events("remove"); - } - - - /* Save data to object */ - function save_object() - { - - /* Add special kolab attributes */ - if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ - if(isset($_POST['kolabFolderType_Type'])){ - $this->kolabFolderType_Type = get_post("kolabFolderType_Type"); - $this->kolabFolderType_SubType = get_post("kolabFolderType_SubType"); - } - } - - /* Check if user wants to remove the shared folder from imap too */ - if($this->initially_was_account && !$this->is_account){ - if(isset($_POST['remove_folder_from_imap'])){ - $this->remove_folder_from_imap = true; - }else{ - $this->remove_folder_from_imap = false; - } - } - - /* Assemble mail delivery mode - The mode field in ldap consists of values between braces, this must - be called when 'mail' is set, because checkboxes may not be set when - we're in some other dialog. - - Example for gosaMailDeliveryMode [LR ] -L: Local delivery -R: Reject when exceeding mailsize limit -S: Use spam filter -V: Use vacation message -C: Use custom sieve script -I: Only insider delivery */ - if (isset($_POST['mailedit'])){ - - plugin::save_object(); - - $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode); - - /* Handle delivery flags */ - if($this->acl_is_writeable("gosaMailDeliveryModeL")){ - if(!preg_match("/L/",$tmp) && !isset($_POST['drop_own_mails'])){ - $tmp.="L"; - }elseif(preg_match("/L/",$tmp) && isset($_POST['drop_own_mails'])){ - $tmp = preg_replace("/L/","",$tmp); - } - } - - $opts = array( - "R" => "use_mailsize_limit", - "S" => "use_spam_filter", - "V" => "use_vacation", - "C" => "own_script", - "I" => "only_local"); - - foreach($opts as $flag => $post){ - if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){ - if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){ - $tmp.= $flag; - }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){ - $tmp = preg_replace("/".$flag."/","",$tmp); - } - } - } - - $tmp= "[$tmp]"; - if ($this->gosaMailDeliveryMode != $tmp){ - $this->is_modified= TRUE; - } - $this->gosaMailDeliveryMode= $tmp; - - /* Collect data and re-assign it to the imapacl array */ - if ($this->acl_is_writeable("acl")){ - $this->imapacl= array(); - $this->imapacl['%members%']= $_POST['member_permissions']; - $this->imapacl['anyone']= $_POST['default_permissions']; - foreach ($this->indexed_user as $nr => $user){ - if (!isset($_POST["user_$nr"])){ - continue; - } - if ($_POST["user_$nr"] != $user || - $_POST["perm_$nr"] != $this->indexed_acl[$nr]){ - $this->is_modified= TRUE; - } - $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"]; - } - } - } - - } - - - /* Save data to LDAP, depending on is_account we save or delete */ - function save() - { - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - - /* Call parents save to prepare $this->attrs */ - plugin::save(); - - /* Save arrays */ - $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress; - $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress; - $this->attrs['gosaSharedFolderTarget'] = "share+".$this->uid; - $this->attrs['acl']= array(); - - /* Prepare Mail server attribute */ - if(preg_match("/olab/i",$this->mmethod)){ - if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){ - if(isset($this->attrs['gosaMailServer'][0])){ - $this->gosaMailServer = $this->attrs['gosaMailServer'][0]; - } - } - } - /* Exchange '%member%' pseudo entry */ - $memberacl= $this->imapacl['%members%']; - foreach ($this->members as $user){ - if (!isset($this->imapacl[$user])){ - $this->imapacl[$user]= $memberacl; - } - } - - /* Prepare kolab attributes to be written */ - if(preg_match("/olab/i",$this->mmethod)){ - if(!empty($this->kolabFolderType_Type)){ - $this->attrs['kolabFolderType'] = $this->kolabFolderType_Type.".".$this->kolabFolderType_SubType; - }else{ - $this->attrs['kolabFolderType'] = array(); - } - } - - /* Get naming attribute for mail accounts */ - $tmp = new $this->method($this->config); - $uattrib = $tmp->uattrib; - - /* Create ACL array - What is done here. - - 1. Do not write acl entries for empty entries. - 2. Check if given user is a valid GOsa user. - - If he is one, check if he has a valid mail extension - -If this is true, add the user to the ACL entry. - -If this is NOT true, skip ACL entries for this user. - - He is not a GOsa Account, so write the ACL. (Manually entered ACL) - 3. In case of "olab" mail method, remove the entry from the $this->imapacl array - because the kolab deamon will set the acls for us. - - */ - foreach ($this->imapacl as $user => $acl){ - - /* Skip empty entries */ - if (empty($user) || $user == ""){ - unset($this->imapacl[$user]); - } - - /* Skip placeholder */ - if (empty($user) || $user == "" || preg_match("/%members%/",$user)){ - continue; - } - - /* Check if your is a real GOsa user - * If user is a real GOsa user but do not have an email address - SKIP adding acls - * If user is a real GOsa user with an email address - add acls - */ - $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail","uid")); - if($ldap->count()){ - - /* Has the user a valid mail account? */ - $attrs = $ldap->fetch(); - if(isset($attrs['mail'][0])){ - - $name = $attrs[$uattrib][0]; - $this->attrs['acl'][]= $name." ".$acl; - - /* Do not write imap acl directly i nkolab mode, let the kolab deamon do this. */ - unset($this->imapacl[$user]); - if(!preg_match("/olab/i",$this->mmethod)){ - $this->imapacl[$name] = $acl; - } - - }else{ - - /* User is a valid GOsa account, but he has no mail extension. Skip ACLs */ - unset($this->imapacl[$user]); - } - }else{ - - /* Seems to be a manually a added acl - * Write this acl. - */ - $this->attrs['acl'][]= $user." ".$acl; - - /* In case of kolab methods, let the deamon add the imap acls */ - if(preg_match("/olab/i",$this->mmethod)){ - unset($this->imapacl[$user]); - } - } - } - - /* Handle mail method actions, set acls, quota ...*/ - if ((!$this->is_template)&&(!empty($this->gosaMailServer))){ - $method= new $this->method($this->config); - $method->fixAttributesOnStore($this); - if (($method->connect($this->gosaMailServer))){ - $method->updateMailbox($this->uid); - $method->setQuota($this->uid, $this->gosaMailQuota); - - /* Only write imap acls directly if we are not - * using a kolab like mail method. - */ - if(!preg_match("/olab/i",$this->mmethod)){ - $method->setSharedFolderPermissions($this->uid, $this->imapacl); - } - $method->disconnect(); - } - } - - /* Save data to LDAP */ - $ldap->cd($this->dn); - $this->cleanup(); - $ldap->modify ($this->attrs); - show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/mail with dn '%s' failed."),$this->dn)); - - if($this->initially_was_account){ - new log("modify","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - }else{ - new log("create","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - } - - - /* Optionally execute a command after we're done */ - if ($this->initially_was_account == $this->is_account){ - if ($this->is_modified){ - $this->handle_post_events("modify"); - } - } else { - $this->handle_post_events("add"); - } - } - - - - /* Check formular input */ - function check() - { - $ldap= $this->config->get_ldap_link(); - - /* Call common method to give check the hook */ - $message= plugin::check(); - - if(!$this->is_account) return array(); - - //$message[] = $str; - - /* must: mail */ - if ($this->mail == ""){ - $message[]= _("The required field 'Primary address' is not set."); - } - if (!tests::is_email($this->mail)){ - $message[]= _("Please enter a valid email addres in 'Primary address' field."); - } - $ldap->cd($this->config->current['BASE']); - $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=". - $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))"); - if ($ldap->count() != 0){ - $message[]= _("The primary address you've entered is already in use."); - } - - /* Check quota */ - if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){ - if (!is_numeric($this->gosaMailQuota)) { - $message[]= _("Value in 'Quota size' is not valid."); - } else { - $this->gosaMailQuota= (int) $this->gosaMailQuota; - } - } - - /* Check rejectsize for integer */ - if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailQuota")){ - if (!is_numeric($this->gosaMailMaxSize)){ - $message[]= _("Please specify a vaild mail size for mails to be rejected."); - } else { - $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize; - } - } - - /* Need gosaMailMaxSize if use_mailsize_limit is checked */ - if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){ - $message[]= _("You need to set the maximum mail size in order to reject anything."); - } - - if(ord($this->imapacl['anyone'][0])==194){ - $message[] = _("Please choose valid permission settings. Default permission can't be emtpy."); - } - - if(empty($this->gosaMailServer)){ - $message[] = _("Please select a valid mail server."); - } - - return ($message); - } - - /* Adapt from template, using 'dn' */ - function adapt_from_template($dn) - { - plugin::adapt_from_template($dn); - - foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){ - $this->$val= array(); - if (isset($this->attrs["$val"]["count"])){ - for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){ - $value= $this->attrs["$val"][$i]; - foreach (array("sn", "givenName", "uid") as $repl){ - if (preg_match("/%$repl/i", $value)){ - $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value); - } - } - array_push($this->$val, $value); - } - } - } - } - - /* Add entry to forwarder list */ - function addForwarder($address) - { - $this->gosaMailForwardingAddress[]= $address; - $this->gosaMailForwardingAddress= array_unique($this->gosaMailForwardingAddress); - - /* Update multiple edit values too */ - if($this->multiple_support_active){ - $this->gosaMailForwardingAddress_Some= - array_remove_entries (array($address),$this->gosaMailForwardingAddress_Some); - } - - sort ($this->gosaMailForwardingAddress); - reset ($this->gosaMailForwardingAddress); - $this->is_modified= TRUE; - } - - /* Remove list of addresses from forwarder list */ - function delForwarder($addresses) - { - $this->gosaMailForwardingAddress= array_remove_entries ($addresses, - $this->gosaMailForwardingAddress); - - /* Update multiple edit values too */ - if($this->multiple_support_active){ - $this->gosaMailForwardingAddress_Some = array_remove_entries ($addresses, - $this->gosaMailForwardingAddress_Some); - } - $this->is_modified= TRUE; - } - - - - function addAlternate($address) - { - $ldap= $this->config->get_ldap_link(); - - $address= strtolower($address); - - /* Is this address already assigned in LDAP? */ - $ldap->cd ($this->config->current['BASE']); - $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)". - "(gosaMailAlternateAddress=$address)))"); - - if ($ldap->count() > 0){ - $attrs= $ldap->fetch (); - return ($attrs["uid"][0]); - } - - /* Add to list of alternates */ - if (!in_array($address, $this->gosaMailAlternateAddress)){ - $this->gosaMailAlternateAddress[]= $address; - } - - sort ($this->gosaMailAlternateAddress); - reset ($this->gosaMailAlternateAddress); - $this->is_modified= TRUE; - - return (""); - } - - - function delAlternate($addresses) - { - $this->gosaMailAlternateAddress= array_remove_entries ($addresses, - $this->gosaMailAlternateAddress); - $this->is_modified= TRUE; - } - - - function make_name($attrs) - { - $name= ""; - if (isset($attrs['sn'][0])){ - $name= $attrs['sn'][0]; - } - if (isset($attrs['givenName'][0])){ - if ($name != ""){ - $name.= ", ".$attrs['givenName'][0]; - } else { - $name.= $attrs['givenName'][0]; - } - } - if ($name != ""){ - $name.= " "; - } - - return ($name); - } - - function getCopyDialog() - { - if(!$this->is_account) return(""); - - $smarty = get_smarty(); - $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress); - $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress); - $smarty->assign("mail",$this->mail); - $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE)); - $ret = array(); - $ret['string'] = $display; - $ret['status'] = ""; - return($ret); - } - - function saveCopyDialog() - { - if(!$this->is_account) return; - - /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses - */ - $this->execute(); - if(isset($_POST['mail'])){ - $this->mail = $_POST['mail']; - } - } - - - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); - - /* Reset alternate mail addresses */ - $this->gosaMailAlternateAddress = array(); - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Mail"), - "plDescription" => _("Group mail"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 0, - "plSection" => array("administration"), - "plCategory" => array("groups"), - "plProvidedAcls"=> array( - "mail" => _("Mail address"), - "gosaMailAlternateAddress" => _("Alternate addresses"), - "gosaMailForwardingAddress" => _("Forwarding addresses"), - "gosaMailQuota" => _("Quota size"), - "gosaMailServer" => _("Mail server"), - "acl" => _("Permissions")) - )); - } - - - /* Remove given ACL for given member (uid,mail) .. - */ - function removeUserAcl($index ) - { - if(isset($this->imapacl[$index])){ - unset($this->imapacl[$index]); - } - } - - function multiple_execute() - { - return($this->execute()); - } - - - function init_multiple_support($attrs,$all) - { - plugin::init_multiple_support($attrs,$all); - - $this->gosaMailForwardingAddress = array(); - if(isset($attrs['gosaMailForwardingAddress'])){ - for($i = 0 ; $i < $attrs['gosaMailForwardingAddress']['count'] ; $i++){ - $this->gosaMailForwardingAddress[] = $attrs['gosaMailForwardingAddress'][$i]; - } - } - - $this->gosaMailForwardingAddress_Some = array(); - if(isset($all['gosaMailForwardingAddress'])){ - for($i = 0 ; $i < $all['gosaMailForwardingAddress']['count'] ; $i++){ - if(!in_array($all['gosaMailForwardingAddress'][$i],$this->gosaMailForwardingAddress)){ - $this->gosaMailForwardingAddress_Some[] = $all['gosaMailForwardingAddress'][$i]; - } - } - } - } - - function multiple_save_object() - { - if(isset($_POST['multiple_mail_group_posted'])){ - plugin::multiple_save_object(); - - foreach(array("kolabFolderType") as $attr){ - if(isset($_POST['use_'.$attr])){ - $this->multi_boxes[] = $attr; - } - } - - /* Add special kolab attributes */ - if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ - if(isset($_POST['kolabFolderType_Type'])){ - $this->kolabFolderType_Type = get_post("kolabFolderType_Type"); - $this->kolabFolderType_SubType = get_post("kolabFolderType_SubType"); - } - } - - /* Collect data and re-assign it to the imapacl array */ - if ($this->acl_is_writeable("acl")){ - $this->imapacl= array(); - $this->imapacl['%members%']= $_POST['member_permissions']; - $this->imapacl['anyone']= $_POST['default_permissions']; - foreach ($this->indexed_user as $nr => $user){ - if (!isset($_POST["user_$nr"])){ - continue; - } - if ($_POST["user_$nr"] != $user || - $_POST["perm_$nr"] != $this->indexed_acl[$nr]){ - $this->is_modified= TRUE; - } - $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"]; - } - } - } - } - - - /* Return selected values for multiple edit */ - function get_multi_edit_values() - { - $ret = plugin::get_multi_edit_values(); - $ret['Forward_some'] = $this->gosaMailForwardingAddress_Some; - $ret['Forward_all'] = $this->gosaMailForwardingAddress; - if(in_array('kolabFolderType',$this->multi_boxes)){ - $ret['kolabFolderType_Type'] = $this->kolabFolderType_Type; - $ret['kolabFolderType_SubType'] = $this->kolabFolderType_SubType; - } - if(in_array("acl",$this->multi_boxes)){ - $ret['imapacl'] = $this->imapacl; - } - return($ret); - } - - function set_multi_edit_values($attrs) - { - $forward = array(); - foreach($attrs['Forward_some'] as $addr){ - if(in_array($addr,$this->gosaMailForwardingAddress)){ - $forward[] = $addr; - } - } - foreach($attrs['Forward_all'] as $addr){ - $forward[] = $addr; - } - plugin::set_multi_edit_values($attrs); - $this->gosaMailForwardingAddress = $forward; - } -} - - // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/groups/mail.tpl b/gosa-core/plugins/admin/groups/mail.tpl deleted file mode 100644 index 6d57a98ae..000000000 --- a/gosa-core/plugins/admin/groups/mail.tpl +++ /dev/null @@ -1,225 +0,0 @@ - - - - - - - -{if $multiple_support} - -{else} - - -{/if} - - -
-

{t}Generic{/t}

- - - - - - - - - - - - - - - - - - {if $kolab} - - - - - {/if} -
{$must} -{if $multiple_support} - -{else} - {render acl=$mailACL} - - {/render} -{/if} -
-{render acl=$gosaMailServerACL checkbox=$multiple_support checked=$use_gosaMailServer} - -{/render} -
-
- -
-
-{if $quotadefined eq "true"} - {$quotausage} -{else} - {t}not defined{/t} -{/if} -
{t}Quota size{/t} -{render acl=$gosaMailQuotaACL checkbox=$multiple_support checked=$use_gosaMailQuota} - -{/render} - {t}MB{/t} -
- {t}Folder type{/t} - - - {if $multiple_support} - - - - {else} - - - {/if} - {if !$JS} - - {/if} -
- -
- - - -

{t}Alternative addresses{/t}

- -{render acl=$gosaMailAlternateAddressACL} - -{/render} - -
- -{render acl=$gosaMailAlternateAddressACL} - -{/render} - -{render acl=$gosaMailAlternateAddressACL} -   -{/render} - -{render acl=$gosaMailAlternateAddressACL} - -{/render} - -
-

 

- - - - - - -
-

{t}IMAP shared folders{/t}

-{if $multiple_support} - - {t}Set shared folder permissions{/t} - {if $use_acl} -
- {else} - -{/if} - -
-

- - {t}Forward messages to non group members{/t} -

- -{render acl=$gosaMailForwardingAddressACL} - -{/render} - -
- -{render acl=$gosaMailForwardingAddressACL} - -{/render} -{render acl=$gosaMailForwardingAddressACL} -   -{/render} -{render acl=$gosaMailForwardingAddressACL} -   -{/render} -{render acl=$gosaMailForwardingAddressACL} - -{/render} -
- - - -{if $multiple_support} - -{/if} diff --git a/gosa-core/plugins/admin/groups/mail/class_groupMail.inc b/gosa-core/plugins/admin/groups/mail/class_groupMail.inc new file mode 100644 index 000000000..8b48357e9 --- /dev/null +++ b/gosa-core/plugins/admin/groups/mail/class_groupMail.inc @@ -0,0 +1,1350 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + var $uid = ""; // User id + var $cn = ""; // cn + var $orig_cn = ""; // cn + + var $method = "mailMethod"; // Used Mail method + var $mmethod = ""; // Contains the gosa.conf MAILMETHOD + var $mail = ""; // Default mail address + + var $gosaMailAlternateAddress = array(); // Set default Alternate Mail Adresses to empty array + var $gosaMailForwardingAddress = array(); // Forwarding also empty + + var $gosaMailForwardingAddress_Some = array(); // Used in multiple edit + + var $gosaMailServer = ""; // Selected mailserver + var $gosaMailQuota = ""; // Defined Quota + var $quotaUsage = 0; // Currently used quota + + var $gosaVacationMessage = ""; // Vocation message + + var $imapacl = array('anyone' => 'p', // Set acls for everyone + '%members%' => 'lrswp', // %members% are all group-members + '' => 'p'); // Every user added gets this right + + var $kolabFolderType_SubType = ""; + var $kolabFolderType_Type = ""; + + var $gosaSpamSortLevel = ""; + var $gosaSpamMailbox = ""; + var $gosaSharedFolderTarget ; + + var $forward_dialog = FALSE; + + var $members = array(); // Group members + + var $mailusers = array(); + var $perms = array(); + var $gosaMailDeliveryMode = "[L ]"; // + var $gosaMailMaxSize = ""; // + + var $remove_folder_from_imap = true; + + /* Helper */ + var $indexed_acl= array(); + var $indexed_user= array(); + + var $view_logged = FALSE; + + /* attribute list for save action */ + var $attributes= array( "mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize", + "gosaMailAlternateAddress", "gosaMailForwardingAddress", + "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox", + "acl","gosaSharedFolderTarget", "gosaVacationMessage"); + + var $objectclasses= array("gosaMailAccount"); + var $CopyPasteVars = array("quotaUsage","imapacl"); + + var $multiple_support = TRUE; + + function mailgroup (&$config, $dn= NULL, $ui= NULL) + { + /* Initialise all available attributes ... if possible + */ + plugin::plugin($config, $dn); + $this->orig_cn = $this->cn; + + /* Set mailMethod to the one defined in gosa.conf + */ + if (isset($this->config->current['MAILMETHOD'])){ + $this->mmethod= $this->config->current['MAILMETHOD']; + } + + /* Check if selected mail method exists + */ + $cls = get_correct_class_name("mailMethod$this->mmethod"); + if ($cls && class_exists($cls)){ + $this->method= $cls; + } else { + print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod)); + } + + /* Load Mailserver + */ + if(isset($this->attrs['gosaMailServer'][0])){ + $this->gosaMailServer = $this->attrs['gosaMailServer'][0]; + } + + /* Convert cn to uid in case of existing entry + */ + if (isset($this->attrs['cn'][0])){ + $this->uid= $this->attrs['cn'][0]; + } + + /* Get folder type */ + if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ + if(isset($this->attrs['kolabFolderType'])){ + $tmp = split("\.",$this->attrs['kolabFolderType'][0]); + $this->kolabFolderType_Type = $tmp[0]; + $this->kolabFolderType_SubType = $tmp[1]; + } + } + + /* If this isn't a new mailgroup, read all required data from ldap + */ + if (($dn != "new")&&($dn !== NULL)){ + + /* Load attributes which represent multiple entries + */ + foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){ + $this->$val = array(); + if (isset($this->attrs["$val"]["count"])){ + for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){ + array_push($this->$val, $this->attrs["$val"][$i]); + } + } + } + + /* Only do IMAP actions if gosaMailServer attribute is set + */ + if (isset ($this->attrs["gosaMailServer"][0])){ + + /* Create new instance of our defined mailclass + */ + $method= new $this->method($this->config); + if ($method->connect($this->attrs["gosaMailServer"][0])){ + + /* If we do NOT use kolab or equal methods, + read imap the acls from the mail method class. + They will be merged later with the ldap specified acls. + */ + if(!preg_match("/olab/i",$this->mmethod) && !empty($this->mmethod)){ + $this->imapacl= $method->getSharedFolderPermissions($this->uid); + + /* Need to filter what a member acl could be... */ + $vote= array(); + $peak= 0; + $leader= ""; + foreach ($this->imapacl as $user => $acl){ + + if ($user != "anyone" ){ + if (!isset($vote[$acl])){ + $vote[$acl]= 1; + } else { + $vote[$acl]++; + } + if ($vote[$acl] > $peak){ + $leader= $acl; + $peek= $vote[$acl]; + } + } + } + /* Highest count wins as %members%, remove all members + with the same acl */ + if(!empty($leader)){ + $this->imapacl['%members%']= $leader; + } + foreach ($this->imapacl as $user => $acl){ + if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){ + unset($this->imapacl[$user]); + } + } + } + + /* Adapt attributes if needed */ + $method->fixAttributesOnLoad($this); + + /* get Quota */ + $quota= $method->getQuota($this->uid); + + /* Update quota values */ + if(is_array($quota)){ + if ($quota['gosaMailQuota'] == 2147483647){ + $this->quotaUsage= ""; + $this->gosaMailQuota= ""; + } else { + $this->quotaUsage= $quota['quotaUsage']; + $this->gosaMailQuota= $quota['gosaMailQuota']; + } + }else{ + $this->quotaUsage = ""; + $this->gosaMailQuota = ""; + } + $method->disconnect(); + } // ENDE $method->connect($this->attrs["gosaMailServer"][0])){ + } // ENDE gosaMailServer + } // ENDE dn != "new" + + + /* Get global filter config */ + if (!session::is_set("gmailfilter")){ + $ui= get_userinfo(); + $base= get_base_from_people($ui->dn); + $gmailfilter= array( "depselect" => $base, + "muser" => "", + "regex" => "*"); + session::set("gmailfilter", $gmailfilter); + } + + /* Load permissions */ + $tmp = array(); + $ldap = $this->config->get_ldap_link(); + + /* Read acls from ldap and merge them with + * acls read from mail method. + */ + if (isset($this->attrs['acl'])){ + + for ($i= 0; $i<$this->attrs['acl']['count']; $i++){ + list($user, $permission)= split(' ', $this->attrs['acl'][$i]); + + /* Add to list */ + $this->imapacl[$user]= $permission; + + /* Get all user permissions sorted by acl, to detect the most used acl + This acl is then used for %members% + */ + if ($user != "anyone" && $user != "%members%"){ + $tmp[$permission][] = $user; + } + + /* There is an entry in $this->imapacl like this this ... + $this->attrs['imapacl']['anyone'] = "p"; + $this->attrs['imapacl']['%members%'] = "lprs"; + $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty + Field for special acls in our template. + If there is at least one special acl in out imapacl, + we don't need this entry anymore, because it is already displayed. + */ + if ($user != "anyone" && $user != "%members%"){ + unset($this->imapacl['']); + } + } + } + + /** + * Detect group members which use the same acl + * as used for %members% and remove them. + **/ + + /* In this section we detect which acl is the most used. + This will be used as %members% acl. + */ + $tmp2 = array(); + foreach($tmp as $acl => $user){ + $tmp2[count($tmp[$acl])]=$acl; + } + /* Most used at last + */ + ksort($tmp2); + + /* Assign last (most used acl) to %members% acl + */ + $str = array_pop($tmp2); + if(!empty($str)) { + $this->imapacl['%members%']=$str; + } + if(!isset($this->imapacl['%members%'])){ + $this->imapacl['%members%'] = "lrspw"; + } + + + /* Open ldap connection + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + + /* Remove those users, that use %members% acl && are member of this group. */ + foreach($this->imapacl as $mail => $permission){ + $ldap->search("(&(objectClass=person)(|(mail=".$mail.")(uid=".$mail.")))",array("uid")); + $atr = $ldap->fetch(); + if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){ + if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){ + unset($this->imapacl[$mail]); + } + } + } + + /** + * ENDE: Detect group member with same acl and replace them with %members% + **/ + $this->indexed_user = array("%members%","anyone"); + + /* Append an empty entry, for special acl handling */ + if(count($this->imapacl)==2){ + $this->imapacl[''] ="lrsw"; + $this->indexed_user[] = ''; + } + + /* Load Mailserver + */ + if(isset($this->attrs['gosaMailServer'][0])){ + $this->gosaMailServer = $this->attrs['gosaMailServer'][0]; + } + /* Fill translations */ + $this->perms["lrsw"]= _("read"); + $this->perms["lrswp"]= _("post"); + $this->perms["p"]= _("external post"); + $this->perms["lrswip"]= _("append"); + $this->perms["lrswipcd"]= _("write"); + $this->perms["lrswipcda"]= _("admin"); + $this->perms[""]= _("none"); + } + + + + function execute() + { + /* Call parent execute */ + //plugin::execute(); + $display = ""; + + /* Log view */ + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","groups/".get_class($this),$this->dn); + } + + /* Load templating engine */ + $smarty= get_smarty(); + + /* Assign acls */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation) { + $smarty->assign($name."ACL",$this->getacl($name)); + } + + if (session::get('js')==FALSE){ + $smarty->assign("javascript", "false"); + } else { + $smarty->assign("javascript", "true"); + } + + /* Handle actions should not be done, when + * editing multiple entries at once. e.g. account state + */ + if(!$this->multiple_support_active){ + + /* Do we need to flip is_account state? */ + if(isset($_POST['modify_state'])){ + if($this->is_account && $this->acl_is_removeable()){ + $this->is_account= FALSE; + }elseif(!$this->is_account && $this->acl_is_createable()){ + $this->is_account= TRUE; + } + } + + $display = ""; + + /* Do we represent a valid account? */ + if (!$this->is_account && $this->parent === NULL){ + + $display.= "\"\" ". + _("This 'dn' has no valid mail extensions.").""; + return ($display); + } + + /* Show tab dialog headers */ + $display= ""; + if ($this->parent !== NULL){ + if ($this->is_account){ + $display.= $this->show_disable_header(_("Remove mail account"), + _("This account has mail features enabled. You can disable them by clicking below.")); + } else { + $display.= $this->show_enable_header(_("Create mail account"), + _("This account has mail features disabled. You can enable them by clicking below.")); + + /* Show checkbox that allows us to remove imap entry too*/ + if($this->initially_was_account){ + $c = ""; + if($this->remove_folder_from_imap){ + $c= " checked "; + } + $display .= "

Shared folder delete options

+ "; + $display .= _("Remove the shared folder and all its contents after saving this account"); + } + return ($display); + } + } + } + + /* Add ACL? */ + if($this->acl_is_writeable("acl")){ + foreach ($this->indexed_user as $nr => $user){ + if (isset($_POST["add_$nr"])){ + $this->imapacl[""]= "l"; + } + if (isset($_POST["del_$nr"])){ + unset ($this->imapacl[$user]); + } + } + } + + /* Trigger forward add dialog? */ + if($this->acl_is_writeable("gosaMailForwardingAddress")){ + if (isset($_POST['add_local_forwarder'])){ + $this->forward_dialog= TRUE; + $this->dialog= TRUE; + } + } + + /* Cancel forward add dialog? */ + if($this->acl_is_writeable("gosaMailForwardingAddress")){ + if (isset($_POST['add_locals_cancel'])){ + $this->forward_dialog= FALSE; + $this->dialog= FALSE; + } + } + + /* Finished adding of locals? */ + if ((isset($_POST['add_locals_finish'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))) { + if (count ($_POST['local_list']) && $this->acl_is_writeable("gosaMailForwardingAddress")){ + + /* Walk through list of forwarders, ignore own addresses */ + foreach ($_POST['local_list'] as $val){ + if (!in_array ($val, $this->gosaMailAlternateAddress) && + $val != $this->mail){ + + $this->addForwarder($val); + } + } + } + $this->forward_dialog= FALSE; + $this->dialog= FALSE; + } + + /* Add forward email addresses */ + if ((isset($_POST['add_forwarder'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){ + if ($_POST['forward_address'] != ""){ + + /* Valid email address specified? */ + $address= $_POST['forward_address']; + if (!tests::is_email($address)){ + + print_red (_("You're trying to add an invalid email address ". + "to the list of forwarders.")); + + } elseif ($address == $this->mail + || in_array($address, $this->gosaMailAlternateAddress)) { + + print_red (_("Adding your one of your own addresses to the forwarders makes no sense.")); + + } else { + + /* Add it */ + if ($this->acl_is_writeable("gosaMailForwardingAddress")){ + $this->addForwarder ($address); + } + + } + } + } + + /* Delete forward email addresses */ + if (isset($_POST['delete_forwarder']) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){ + if (count($_POST['forwarder_list'])&& $this->acl_is_writeable("gosaMailForwardingAddress")){ + + $this->delForwarder ($_POST['forwarder_list']); + } + } + + /* Add alternate email addresses */ + if (isset($_POST['add_alternate'])){ + if ($_POST['alternate_address'] != "" && $this->acl_is_writeable("gosaMailAlternateAddress")){ + + if (!tests::is_email($_POST['alternate_address'])){ + print_red (_("You're trying to add an invalid email address to the list of alternate addresses.")); + + } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){ + $ui= get_userinfo(); + if ($user != $ui->username){ + print_red (_("The address you're trying to add is already used by user")." '$user'."); + } + } + } + } + + /* Delete alternate email addresses */ + if($this->acl_is_writeable("gosaMailAlternateAddress")){ + if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){ + if (count($_POST['alternates_list']) && $this->acl_is_writeable("gosaMailAlternateAddress")){ + $this->delAlternate ($_POST['alternates_list']); + } + } + } + + /* Show forward add dialog */ + if ($this->forward_dialog){ + $ldap= $this->config->get_ldap_link(); + + /* Save data */ + $gmailfilter= session::get("gmailfilter"); + foreach( array("depselect", "muser", "regex") as $type){ + if (isset($_POST[$type])){ + $gmailfilter[$type]= $_POST[$type]; + } + } + if (isset($_GET['search'])){ + $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*"; + if ($s == "**"){ + $s= "*"; + } + $gmailfilter['regex']= $s; + } + session::set("gmailfilter", $gmailfilter); + + /* Get actual list */ + $mailusers= array (); + if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){ + $regex= $gmailfilter['regex']; + $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))"; + } else { + $filter= ""; + } + if ($gmailfilter['muser'] != ""){ + $user= $gmailfilter['muser']; + $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))"; + } + + /* Add already present people to the filter */ + $exclude= ""; + foreach ($this->gosaMailForwardingAddress as $mail){ + $exclude.= "(mail=$mail)"; + } + if ($exclude != ""){ + $filter.= "(!(|$exclude))"; + } + + $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $gmailfilter['depselect'], + array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT); + $ldap->cd($gmailfilter['depselect']); + $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName")); + error_reporting (0); + while ($attrs= $ldap->fetch()){ + if(preg_match('/%/', $attrs['mail'][0])){ + continue; + } + $name= $this->make_name($attrs); + $mailusers[$attrs['mail'][0]]= $name."<". + $attrs['mail'][0].">"; + } + error_reporting (E_ALL | E_STRICT); + natcasesort ($mailusers); + reset ($mailusers); + + /* Show dialog */ + $smarty->assign("search_image", get_template_path('images/search.png')); + $smarty->assign("usearch_image", get_template_path('images/search_user.png')); + $smarty->assign("tree_image", get_template_path('images/tree.png')); + $smarty->assign("infoimage", get_template_path('images/info.png')); + $smarty->assign("launchimage", get_template_path('images/small_filter.png')); + $smarty->assign("mailusers", $mailusers); + $smarty->assign("deplist", $this->config->idepartments); + $smarty->assign("apply", apply_filter()); + $smarty->assign("alphabet", generate_alphabet()); + $smarty->assign("hint", print_sizelimit_warning()); + foreach( array("depselect", "muser", "regex") as $type){ + $smarty->assign("$type", $gmailfilter[$type]); + } + $smarty->assign("hint", print_sizelimit_warning()); + $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__))); + return ($display); + } + + /* Assemble normal permissions */ + if (isset($this->imapacl['anyone'])){ + $smarty->assign("default_permissions", $this->imapacl['anyone']); + } + $smarty->assign("member_permissions", "lrsp"); + if (isset($this->imapacl['%members%'])){ + $smarty->assign("member_permissions", $this->imapacl['%members%']); + } + + /* Assemble extra attributes */ + $perm= $this->getacl( "permissions"); + $tmp= ""; + $nr= 0; + $count= count($this->imapacl); + $this->indexed_user= array(); + $this->indexed_acl= array(); + foreach($this->imapacl as $user => $acl){ + + /* Add additional acl settings */ + if ($user != "anyone" && $user != "%members%"){ + + $Dis = ""; + if(!preg_match("/w/",$perm)){ + $Dis = " disabled "; + } + + /* Reset given Acls to ensure that nobody can read username and acls if not allwoed */ + if(!preg_match("/r/",$perm)){ + $user = ""; + $nr = "none"; + $key = "none"; + } + + $tmp.= " + + + + +  "; + + + + if ($nr == $count - 1){ + if($this->acl_is_writeable("acl")){ + $tmp.= ""; + } + } + if ($count > 3){ + if($this->acl_is_writeable("acl")){ + $tmp.= ""; + } + } + } + $this->indexed_user[$nr]= $user; + $this->indexed_acl[$nr++]= $acl; + } + $smarty->assign("plusattributes", $tmp); + + /* Show main page */ + $mailserver= array(); + foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){ + $mailserver[]= $key; + } + $smarty->assign("mailServers", $mailserver); + foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail", + "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){ + $smarty->assign("$val", $this->$val); + } + if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){ + if($this->acl_is_readable("gosaMailQuota")){ + $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true)); + $smarty->assign("quotadefined", "true"); + }else{ + $smarty->assign("quotadefined", "true"); + $smarty->assign("quotausage", "-"); + } + } else { + $smarty->assign("quotadefined", "false"); + } + + if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ + + $smarty->assign("kolab", TRUE); + $smarty->assign("JS",session::get('js')); + $smarty->assign("kolabFolderType_Types", array ( '' => _('Unspecified'), 'mail' => _('Mails'), + 'task' => _('Tasks') , 'journal' => _('Journals'), + 'calendar' => _('Calendar'), 'contact' => _('Contacts'), + 'note' => _('Notes'))); + if($this->kolabFolderType_Type == "mail"){ + $smarty->assign("kolabFolderType_SubTypes", array( + '' => _('Unspecified'), 'inbox' => _("Inbox") , + 'drafts' => _("Drafts"), 'sentitems' => _("Sent items"), + 'junkemail' => _("Junk mail"))); + }else{ + $smarty->assign("kolabFolderType_SubTypes", array( 'default' => _("Default"))); + } + $smarty->assign("kolabFolderType_Type", $this->kolabFolderType_Type); + $smarty->assign("kolabFolderType_SubType", $this->kolabFolderType_SubType); + }else{ + $smarty->assign("kolab", FALSE); + } + + /* Multiple support handling */ + foreach($this->attributes as $attr){ + if(in_array($attr,$this->multi_boxes)){ + $smarty->assign("use_".$attr,TRUE); + }else{ + $smarty->assign("use_".$attr,FALSE); + } + } + + /* Multiple support handling */ + foreach(array("kolabFolderType") as $attr){ + if(in_array($attr,$this->multi_boxes)){ + $smarty->assign("use_".$attr,TRUE); + }else{ + $smarty->assign("use_".$attr,FALSE); + } + } + + $smarty->assign("Forward_all",$this->gosaMailForwardingAddress); + $smarty->assign("Forward_some",$this->gosaMailForwardingAddress_Some); + + $smarty->assign("multiple_support",$this->multiple_support_active); + $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE, dirname(__FILE__))); + return ($display); + } + + + /* remove object from parent */ + function remove_from_parent() + { + if(!$this->initially_was_account){ + return; + } + + /* Added these ObjectClass and Attributes, because they were not + removed correctly, only in case of kolab ... + */ + if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ + $this->attributes[]="acl"; + $this->objectclasses[] = "kolabSharedFolder"; + } + /* include global link_info */ + $ldap= $this->config->get_ldap_link(); + + /* Remove and write to LDAP */ + plugin::remove_from_parent(); + + /* Zero arrays */ + $this->attrs['gosaMailAlternateAddress']= array(); + $this->attrs['gosaMailForwardingAddress']= array(); + $this->attrs['gosaSharedFolderTarget']= array(); + + /* Connect to IMAP server for account deletion */ + if ($this->initially_was_account){ + + $method= new $this->method($this->config); + $method->fixAttributesOnRemove($this); + if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){ + + /* Remove account from IMAP server */ + $method->deleteMailbox($this->uid); + $method->disconnect(); + } + } + /* Keep uid */ + unset ($this->attrs['uid']); + + $ldap->cd($this->dn); + $ldap->modify ($this->attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/mail with dn '%s' failed."),$this->dn)); + + + new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + + /* Optionally execute a command after we're done */ + $this->handle_post_events("remove"); + } + + + /* Save data to object */ + function save_object() + { + + /* Add special kolab attributes */ + if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ + if(isset($_POST['kolabFolderType_Type'])){ + $this->kolabFolderType_Type = get_post("kolabFolderType_Type"); + $this->kolabFolderType_SubType = get_post("kolabFolderType_SubType"); + } + } + + /* Check if user wants to remove the shared folder from imap too */ + if($this->initially_was_account && !$this->is_account){ + if(isset($_POST['remove_folder_from_imap'])){ + $this->remove_folder_from_imap = true; + }else{ + $this->remove_folder_from_imap = false; + } + } + + /* Assemble mail delivery mode + The mode field in ldap consists of values between braces, this must + be called when 'mail' is set, because checkboxes may not be set when + we're in some other dialog. + + Example for gosaMailDeliveryMode [LR ] +L: Local delivery +R: Reject when exceeding mailsize limit +S: Use spam filter +V: Use vacation message +C: Use custom sieve script +I: Only insider delivery */ + if (isset($_POST['mailedit'])){ + + plugin::save_object(); + + $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode); + + /* Handle delivery flags */ + if($this->acl_is_writeable("gosaMailDeliveryModeL")){ + if(!preg_match("/L/",$tmp) && !isset($_POST['drop_own_mails'])){ + $tmp.="L"; + }elseif(preg_match("/L/",$tmp) && isset($_POST['drop_own_mails'])){ + $tmp = preg_replace("/L/","",$tmp); + } + } + + $opts = array( + "R" => "use_mailsize_limit", + "S" => "use_spam_filter", + "V" => "use_vacation", + "C" => "own_script", + "I" => "only_local"); + + foreach($opts as $flag => $post){ + if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){ + if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){ + $tmp.= $flag; + }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){ + $tmp = preg_replace("/".$flag."/","",$tmp); + } + } + } + + $tmp= "[$tmp]"; + if ($this->gosaMailDeliveryMode != $tmp){ + $this->is_modified= TRUE; + } + $this->gosaMailDeliveryMode= $tmp; + + /* Collect data and re-assign it to the imapacl array */ + if ($this->acl_is_writeable("acl")){ + $this->imapacl= array(); + $this->imapacl['%members%']= $_POST['member_permissions']; + $this->imapacl['anyone']= $_POST['default_permissions']; + foreach ($this->indexed_user as $nr => $user){ + if (!isset($_POST["user_$nr"])){ + continue; + } + if ($_POST["user_$nr"] != $user || + $_POST["perm_$nr"] != $this->indexed_acl[$nr]){ + $this->is_modified= TRUE; + } + $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"]; + } + } + } + + } + + + /* Save data to LDAP, depending on is_account we save or delete */ + function save() + { + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + + /* Call parents save to prepare $this->attrs */ + plugin::save(); + + /* Save arrays */ + $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress; + $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress; + $this->attrs['gosaSharedFolderTarget'] = "share+".$this->uid; + $this->attrs['acl']= array(); + + /* Prepare Mail server attribute */ + if(preg_match("/olab/i",$this->mmethod)){ + if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){ + if(isset($this->attrs['gosaMailServer'][0])){ + $this->gosaMailServer = $this->attrs['gosaMailServer'][0]; + } + } + } + /* Exchange '%member%' pseudo entry */ + $memberacl= $this->imapacl['%members%']; + foreach ($this->members as $user){ + if (!isset($this->imapacl[$user])){ + $this->imapacl[$user]= $memberacl; + } + } + + /* Prepare kolab attributes to be written */ + if(preg_match("/olab/i",$this->mmethod)){ + if(!empty($this->kolabFolderType_Type)){ + $this->attrs['kolabFolderType'] = $this->kolabFolderType_Type.".".$this->kolabFolderType_SubType; + }else{ + $this->attrs['kolabFolderType'] = array(); + } + } + + /* Get naming attribute for mail accounts */ + $tmp = new $this->method($this->config); + $uattrib = $tmp->uattrib; + + /* Create ACL array + What is done here. + + 1. Do not write acl entries for empty entries. + 2. Check if given user is a valid GOsa user. + - If he is one, check if he has a valid mail extension + -If this is true, add the user to the ACL entry. + -If this is NOT true, skip ACL entries for this user. + - He is not a GOsa Account, so write the ACL. (Manually entered ACL) + 3. In case of "olab" mail method, remove the entry from the $this->imapacl array + because the kolab deamon will set the acls for us. + + */ + foreach ($this->imapacl as $user => $acl){ + + /* Skip empty entries */ + if (empty($user) || $user == ""){ + unset($this->imapacl[$user]); + } + + /* Skip placeholder */ + if (empty($user) || $user == "" || preg_match("/%members%/",$user)){ + continue; + } + + /* Check if your is a real GOsa user + * If user is a real GOsa user but do not have an email address - SKIP adding acls + * If user is a real GOsa user with an email address - add acls + */ + $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail","uid")); + if($ldap->count()){ + + /* Has the user a valid mail account? */ + $attrs = $ldap->fetch(); + if(isset($attrs['mail'][0])){ + + $name = $attrs[$uattrib][0]; + $this->attrs['acl'][]= $name." ".$acl; + + /* Do not write imap acl directly i nkolab mode, let the kolab deamon do this. */ + unset($this->imapacl[$user]); + if(!preg_match("/olab/i",$this->mmethod)){ + $this->imapacl[$name] = $acl; + } + + }else{ + + /* User is a valid GOsa account, but he has no mail extension. Skip ACLs */ + unset($this->imapacl[$user]); + } + }else{ + + /* Seems to be a manually a added acl + * Write this acl. + */ + $this->attrs['acl'][]= $user." ".$acl; + + /* In case of kolab methods, let the deamon add the imap acls */ + if(preg_match("/olab/i",$this->mmethod)){ + unset($this->imapacl[$user]); + } + } + } + + /* Handle mail method actions, set acls, quota ...*/ + if ((!$this->is_template)&&(!empty($this->gosaMailServer))){ + $method= new $this->method($this->config); + $method->fixAttributesOnStore($this); + if (($method->connect($this->gosaMailServer))){ + $method->updateMailbox($this->uid); + $method->setQuota($this->uid, $this->gosaMailQuota); + + /* Only write imap acls directly if we are not + * using a kolab like mail method. + */ + if(!preg_match("/olab/i",$this->mmethod)){ + $method->setSharedFolderPermissions($this->uid, $this->imapacl); + } + $method->disconnect(); + } + } + + /* Save data to LDAP */ + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/mail with dn '%s' failed."),$this->dn)); + + if($this->initially_was_account){ + new log("modify","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + }else{ + new log("create","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + } + + + /* Optionally execute a command after we're done */ + if ($this->initially_was_account == $this->is_account){ + if ($this->is_modified){ + $this->handle_post_events("modify"); + } + } else { + $this->handle_post_events("add"); + } + } + + + + /* Check formular input */ + function check() + { + $ldap= $this->config->get_ldap_link(); + + /* Call common method to give check the hook */ + $message= plugin::check(); + + if(!$this->is_account) return array(); + + //$message[] = $str; + + /* must: mail */ + if ($this->mail == ""){ + $message[]= _("The required field 'Primary address' is not set."); + } + if (!tests::is_email($this->mail)){ + $message[]= _("Please enter a valid email addres in 'Primary address' field."); + } + $ldap->cd($this->config->current['BASE']); + $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=". + $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))"); + if ($ldap->count() != 0){ + $message[]= _("The primary address you've entered is already in use."); + } + + /* Check quota */ + if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){ + if (!is_numeric($this->gosaMailQuota)) { + $message[]= _("Value in 'Quota size' is not valid."); + } else { + $this->gosaMailQuota= (int) $this->gosaMailQuota; + } + } + + /* Check rejectsize for integer */ + if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailQuota")){ + if (!is_numeric($this->gosaMailMaxSize)){ + $message[]= _("Please specify a vaild mail size for mails to be rejected."); + } else { + $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize; + } + } + + /* Need gosaMailMaxSize if use_mailsize_limit is checked */ + if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){ + $message[]= _("You need to set the maximum mail size in order to reject anything."); + } + + if(ord($this->imapacl['anyone'][0])==194){ + $message[] = _("Please choose valid permission settings. Default permission can't be emtpy."); + } + + if(empty($this->gosaMailServer)){ + $message[] = _("Please select a valid mail server."); + } + + return ($message); + } + + /* Adapt from template, using 'dn' */ + function adapt_from_template($dn) + { + plugin::adapt_from_template($dn); + + foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){ + $this->$val= array(); + if (isset($this->attrs["$val"]["count"])){ + for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){ + $value= $this->attrs["$val"][$i]; + foreach (array("sn", "givenName", "uid") as $repl){ + if (preg_match("/%$repl/i", $value)){ + $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value); + } + } + array_push($this->$val, $value); + } + } + } + } + + /* Add entry to forwarder list */ + function addForwarder($address) + { + $this->gosaMailForwardingAddress[]= $address; + $this->gosaMailForwardingAddress= array_unique($this->gosaMailForwardingAddress); + + /* Update multiple edit values too */ + if($this->multiple_support_active){ + $this->gosaMailForwardingAddress_Some= + array_remove_entries (array($address),$this->gosaMailForwardingAddress_Some); + } + + sort ($this->gosaMailForwardingAddress); + reset ($this->gosaMailForwardingAddress); + $this->is_modified= TRUE; + } + + /* Remove list of addresses from forwarder list */ + function delForwarder($addresses) + { + $this->gosaMailForwardingAddress= array_remove_entries ($addresses, + $this->gosaMailForwardingAddress); + + /* Update multiple edit values too */ + if($this->multiple_support_active){ + $this->gosaMailForwardingAddress_Some = array_remove_entries ($addresses, + $this->gosaMailForwardingAddress_Some); + } + $this->is_modified= TRUE; + } + + + + function addAlternate($address) + { + $ldap= $this->config->get_ldap_link(); + + $address= strtolower($address); + + /* Is this address already assigned in LDAP? */ + $ldap->cd ($this->config->current['BASE']); + $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)". + "(gosaMailAlternateAddress=$address)))"); + + if ($ldap->count() > 0){ + $attrs= $ldap->fetch (); + return ($attrs["uid"][0]); + } + + /* Add to list of alternates */ + if (!in_array($address, $this->gosaMailAlternateAddress)){ + $this->gosaMailAlternateAddress[]= $address; + } + + sort ($this->gosaMailAlternateAddress); + reset ($this->gosaMailAlternateAddress); + $this->is_modified= TRUE; + + return (""); + } + + + function delAlternate($addresses) + { + $this->gosaMailAlternateAddress= array_remove_entries ($addresses, + $this->gosaMailAlternateAddress); + $this->is_modified= TRUE; + } + + + function make_name($attrs) + { + $name= ""; + if (isset($attrs['sn'][0])){ + $name= $attrs['sn'][0]; + } + if (isset($attrs['givenName'][0])){ + if ($name != ""){ + $name.= ", ".$attrs['givenName'][0]; + } else { + $name.= $attrs['givenName'][0]; + } + } + if ($name != ""){ + $name.= " "; + } + + return ($name); + } + + function getCopyDialog() + { + if(!$this->is_account) return(""); + + $smarty = get_smarty(); + $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress); + $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress); + $smarty->assign("mail",$this->mail); + $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE, dirname(__FILE__))); + $ret = array(); + $ret['string'] = $display; + $ret['status'] = ""; + return($ret); + } + + function saveCopyDialog() + { + if(!$this->is_account) return; + + /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses + */ + $this->execute(); + if(isset($_POST['mail'])){ + $this->mail = $_POST['mail']; + } + } + + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + + /* Reset alternate mail addresses */ + $this->gosaMailAlternateAddress = array(); + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Mail"), + "plDescription" => _("Group mail"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 0, + "plSection" => array("administration"), + "plCategory" => array("groups"), + "plProvidedAcls"=> array( + "mail" => _("Mail address"), + "gosaMailAlternateAddress" => _("Alternate addresses"), + "gosaMailForwardingAddress" => _("Forwarding addresses"), + "gosaMailQuota" => _("Quota size"), + "gosaMailServer" => _("Mail server"), + "acl" => _("Permissions")) + )); + } + + + /* Remove given ACL for given member (uid,mail) .. + */ + function removeUserAcl($index ) + { + if(isset($this->imapacl[$index])){ + unset($this->imapacl[$index]); + } + } + + function multiple_execute() + { + return($this->execute()); + } + + + function init_multiple_support($attrs,$all) + { + plugin::init_multiple_support($attrs,$all); + + $this->gosaMailForwardingAddress = array(); + if(isset($attrs['gosaMailForwardingAddress'])){ + for($i = 0 ; $i < $attrs['gosaMailForwardingAddress']['count'] ; $i++){ + $this->gosaMailForwardingAddress[] = $attrs['gosaMailForwardingAddress'][$i]; + } + } + + $this->gosaMailForwardingAddress_Some = array(); + if(isset($all['gosaMailForwardingAddress'])){ + for($i = 0 ; $i < $all['gosaMailForwardingAddress']['count'] ; $i++){ + if(!in_array($all['gosaMailForwardingAddress'][$i],$this->gosaMailForwardingAddress)){ + $this->gosaMailForwardingAddress_Some[] = $all['gosaMailForwardingAddress'][$i]; + } + } + } + } + + function multiple_save_object() + { + if(isset($_POST['multiple_mail_group_posted'])){ + plugin::multiple_save_object(); + + foreach(array("kolabFolderType") as $attr){ + if(isset($_POST['use_'.$attr])){ + $this->multi_boxes[] = $attr; + } + } + + /* Add special kolab attributes */ + if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){ + if(isset($_POST['kolabFolderType_Type'])){ + $this->kolabFolderType_Type = get_post("kolabFolderType_Type"); + $this->kolabFolderType_SubType = get_post("kolabFolderType_SubType"); + } + } + + /* Collect data and re-assign it to the imapacl array */ + if ($this->acl_is_writeable("acl")){ + $this->imapacl= array(); + $this->imapacl['%members%']= $_POST['member_permissions']; + $this->imapacl['anyone']= $_POST['default_permissions']; + foreach ($this->indexed_user as $nr => $user){ + if (!isset($_POST["user_$nr"])){ + continue; + } + if ($_POST["user_$nr"] != $user || + $_POST["perm_$nr"] != $this->indexed_acl[$nr]){ + $this->is_modified= TRUE; + } + $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"]; + } + } + } + } + + + /* Return selected values for multiple edit */ + function get_multi_edit_values() + { + $ret = plugin::get_multi_edit_values(); + $ret['Forward_some'] = $this->gosaMailForwardingAddress_Some; + $ret['Forward_all'] = $this->gosaMailForwardingAddress; + if(in_array('kolabFolderType',$this->multi_boxes)){ + $ret['kolabFolderType_Type'] = $this->kolabFolderType_Type; + $ret['kolabFolderType_SubType'] = $this->kolabFolderType_SubType; + } + if(in_array("acl",$this->multi_boxes)){ + $ret['imapacl'] = $this->imapacl; + } + return($ret); + } + + function set_multi_edit_values($attrs) + { + $forward = array(); + foreach($attrs['Forward_some'] as $addr){ + if(in_array($addr,$this->gosaMailForwardingAddress)){ + $forward[] = $addr; + } + } + foreach($attrs['Forward_all'] as $addr){ + $forward[] = $addr; + } + plugin::set_multi_edit_values($attrs); + $this->gosaMailForwardingAddress = $forward; + } +} + + // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-core/plugins/admin/groups/mail/mail.tpl b/gosa-core/plugins/admin/groups/mail/mail.tpl new file mode 100644 index 000000000..6d57a98ae --- /dev/null +++ b/gosa-core/plugins/admin/groups/mail/mail.tpl @@ -0,0 +1,225 @@ + + + + + + + +{if $multiple_support} + +{else} + + +{/if} + + +
+

{t}Generic{/t}

+ + + + + + + + + + + + + + + + + + {if $kolab} + + + + + {/if} +
{$must} +{if $multiple_support} + +{else} + {render acl=$mailACL} + + {/render} +{/if} +
+{render acl=$gosaMailServerACL checkbox=$multiple_support checked=$use_gosaMailServer} + +{/render} +
+
+ +
+
+{if $quotadefined eq "true"} + {$quotausage} +{else} + {t}not defined{/t} +{/if} +
{t}Quota size{/t} +{render acl=$gosaMailQuotaACL checkbox=$multiple_support checked=$use_gosaMailQuota} + +{/render} + {t}MB{/t} +
+ {t}Folder type{/t} + + + {if $multiple_support} + + + + {else} + + + {/if} + {if !$JS} + + {/if} +
+ +
+ + + +

{t}Alternative addresses{/t}

+ +{render acl=$gosaMailAlternateAddressACL} + +{/render} + +
+ +{render acl=$gosaMailAlternateAddressACL} + +{/render} + +{render acl=$gosaMailAlternateAddressACL} +   +{/render} + +{render acl=$gosaMailAlternateAddressACL} + +{/render} + +
+

 

+ + + + + + +
+

{t}IMAP shared folders{/t}

+{if $multiple_support} + + {t}Set shared folder permissions{/t} + {if $use_acl} +
+ {else} + +{/if} + +
+

+ + {t}Forward messages to non group members{/t} +

+ +{render acl=$gosaMailForwardingAddressACL} + +{/render} + +
+ +{render acl=$gosaMailForwardingAddressACL} + +{/render} +{render acl=$gosaMailForwardingAddressACL} +   +{/render} +{render acl=$gosaMailForwardingAddressACL} +   +{/render} +{render acl=$gosaMailForwardingAddressACL} + +{/render} +
+ + + +{if $multiple_support} + +{/if} diff --git a/gosa-core/plugins/admin/groups/mail/mail_admins.tpl b/gosa-core/plugins/admin/groups/mail/mail_admins.tpl new file mode 100644 index 000000000..8c95cb0d0 --- /dev/null +++ b/gosa-core/plugins/admin/groups/mail/mail_admins.tpl @@ -0,0 +1,40 @@ + + + + + + + + +
+ +
+ +
+ +
+
+ +
+
+ +
+ : + + + {if $javascript ne "true"} + + {/if} +
+ +

+ +   + +

diff --git a/gosa-core/plugins/admin/groups/mail/mail_locals.tpl b/gosa-core/plugins/admin/groups/mail/mail_locals.tpl new file mode 100644 index 000000000..09d734a9b --- /dev/null +++ b/gosa-core/plugins/admin/groups/mail/mail_locals.tpl @@ -0,0 +1,69 @@ + + + + + +
+
+

+
+

+
+
+

+ +

+
+
+
+

+ [F] + {t}Filters{/t} +

+
+
+ + {$alphabet} +
+ + + + +
+   + +
+ + + + + +
+ + + +
+ + + + + +
+ + + +
+ {$apply} +
+
+ +

+ +   + +

diff --git a/gosa-core/plugins/admin/groups/mail/paste_mail.tpl b/gosa-core/plugins/admin/groups/mail/paste_mail.tpl new file mode 100644 index 000000000..e30ba9af0 --- /dev/null +++ b/gosa-core/plugins/admin/groups/mail/paste_mail.tpl @@ -0,0 +1,56 @@ +

{t}Mail settings{/t}

+ + + + + + +
+ + + + + +
+ {$must} + + +
+
+ + + + + +
+ {t}Alternative addresses{/t} + +
+ +   + +
+ {t}Forward messages to non group members{/t} + +
+ +   +   + +
+
+
+ + + diff --git a/gosa-core/plugins/admin/groups/mail_admins.tpl b/gosa-core/plugins/admin/groups/mail_admins.tpl deleted file mode 100644 index 8c95cb0d0..000000000 --- a/gosa-core/plugins/admin/groups/mail_admins.tpl +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - -
- -
- -
- -
-
- -
-
- -
- : - - - {if $javascript ne "true"} - - {/if} -
- -

- -   - -

diff --git a/gosa-core/plugins/admin/groups/mail_locals.tpl b/gosa-core/plugins/admin/groups/mail_locals.tpl deleted file mode 100644 index 09d734a9b..000000000 --- a/gosa-core/plugins/admin/groups/mail_locals.tpl +++ /dev/null @@ -1,69 +0,0 @@ - - - - - -
-
-

-
-

-
-
-

- -

-
-
-
-

- [F] - {t}Filters{/t} -

-
-
- - {$alphabet} -
- - - - -
-   - -
- - - - - -
- - - -
- - - - - -
- - - -
- {$apply} -
-
- -

- -   - -

diff --git a/gosa-core/plugins/admin/groups/paste_mail.tpl b/gosa-core/plugins/admin/groups/paste_mail.tpl deleted file mode 100644 index e30ba9af0..000000000 --- a/gosa-core/plugins/admin/groups/paste_mail.tpl +++ /dev/null @@ -1,56 +0,0 @@ -

{t}Mail settings{/t}

- - - - - - -
- - - - - -
- {$must} - - -
-
- - - - - -
- {t}Alternative addresses{/t} - -
- -   - -
- {t}Forward messages to non group members{/t} - -
- -   -   - -
-
-
- - -