config= $config; $ui= get_userinfo(); $tag= $ui->gosaUnitTag; /* Preset values */ $this->targets= array("user" => _("Users"), "group" => _("Groups")); asort($this->targets); /* Users */ $ldap= $config->get_ldap_link(); $ldap->cd($config->current['BASE']); if ($tag == ""){ $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn')); } else { $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn')); } while ($attrs= $ldap->fetch()){ $this->users['U:'.$attrs['uid'][0]]= $attrs['cn'][0].' ['.$attrs['uid'][0].']'; } ksort($this->users); /* Groups */ $ldap->cd($config->current['BASE']); if ($tag == ""){ $ldap->search('(objectClass=posixGroup)', array('cn', 'description')); } else { $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description')); } while ($attrs= $ldap->fetch()){ $dsc= ""; if (isset($attrs['description'][0])){ $dsc= $attrs['description'][0]; } $this->groups['G:'.$attrs['cn'][0]]= $attrs['cn'][0].' ['.$dsc.']'; } ksort($this->groups); /* Load templates */ if (isset($this->config->current['NOTIFYDIR'])){ $dir= $this->config->current['NOTIFYDIR']; if (is_dir($dir) && is_readable($dir)){ /* Look for files and build the vacation array */ $dh= opendir($dir); while ($file = readdir($dh)){ $description= $this->parse_notification("$dir/$file"); if ($description != ""){ $this->templates["$dir/$file"]= $description; } } closedir($dh); } /* Enable templates if there are some... */ if (count($this->templates)){ $this->show_templates= true; } } } function execute() { /* Call parent execute */ plugin::execute(); /* Send message? */ if (isset($_POST['send'])){ /* Do we have recipients? */ if (count($this->recipients)){ /*Permissions ok? */ if (chkacl($this->acl, 'notify') != ""){ print_red(_("You have no permissions to send a message!")); } else { $cmd= search_config($this->config->data['MENU'], "msgplug", "NOTIFY_COMMAND"); if ($cmd == ""){ print_red(_("No NOTIFY_COMMAND definition found in your gosa.conf")); } else { $parameters= base64_encode($this->nmessage) ." "; foreach ($this->recipients as $key => $value){ $parameters.= "$key "; } exec ("$cmd $parameters", $dummy, $retval); if ($retval != 0){ print_red(sprintf(_("Execution of '%s' failed!"), $cmd)); } $this->finalized= true; } } } else { print_red(_("Please specify at least one recipient to send a message!")); } } /* Bounce back to the original dialog */ if (isset($_POST['continue'])){ $this->finalized= false; } /* Add to list? */ if (isset($_POST['add']) && isset($_POST['source'])){ foreach ($_POST['source'] as $key){ if ($this->target == 'user'){ $this->recipients[$key]= $this->users[$key]; } if ($this->target == 'group'){ $this->recipients[$key]= $this->groups[$key]; } } ksort($this->recipients); } /* Remove from list? */ if (isset($_POST['del']) && isset($_POST['recipient'])){ foreach ($_POST['recipient'] as $key){ unset($this->recipients[$key]); } } /* Import message? */ if (isset($_POST["import_template"]) && isset($this->templates[$_POST["nmessage_template"]])){ $contents= ""; $lines= file($_POST["nmessage_template"]); foreach ($lines as $line){ if (!preg_match('/^DESC:/', $line)){ $contents.= $line; } } /* Replace attributes */ $ui= get_userinfo(); $contents= preg_replace('/%self/', $ui->cn, $contents); /* Save message */ $this->nmessage= htmlspecialchars($contents); } $smarty= get_smarty(); /* Assign possible target types */ $smarty->assign("targets", $this->targets); foreach ($this->attributes as $attr){ $smarty->assign($attr, $this->$attr); } /* Generate list */ $tmp= array(); foreach (array("user" => "users", "group" => "groups") as $field => $arr){ if ($this->target == $field){ foreach ($this->$arr as $key => $value){ if (!isset($this->recipients[$key])){ $tmp[$key]= $value; } } } } $smarty->assign('sources', $tmp); $smarty->assign('recipients', $this->recipients); /* Assign ACL */ $smarty->assign('nmessageACL', chkacl($this->acl, "notify")); /* Handle templates */ $smarty->assign('show_templates', $this->show_templates?"true":"false"); $smarty->assign('message_templates', $this->templates); $smarty->assign('template', $this->template); $smarty->assign('finished', $this->finalized?"true":"false"); /* Show main page */ return ($smarty->fetch (get_template_path('contents.tpl', TRUE))); } function parse_notification($file) { $desc= ""; if (is_file($file)){ $fh = fopen($file, "r"); $line= fgets($fh, 256); if (!preg_match('/^DESC:/', $line)){ print_red (_("No DESC tag in message file:")." $file"); return $desc; } fclose ($fh); $desc= trim(preg_replace('/^DESC:\s*/', '', $line)); } return $desc; } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>