diff --git a/gosa-plugins/goto/admin/mimetypes/class_mimetypeGeneric.inc b/gosa-plugins/goto/admin/mimetypes/class_mimetypeGeneric.inc
index 03867ebab5497458f99500b8ca130b91de98329f..bd8f4cae6a082ecf4da9fc3aaf88e35a92209592 100644 (file)
<?php
class mimetype extends plugin
{
- /* CLI vars */
- var $cli_summary = "This tab allows you to modify, add or remove mime types in the selected department.";
- var $cli_description = "Management dialog to handle mime types";
var $ignore_account = true; // This is always a valid account
- var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
var $objectclasses = array("top","gotoMimeType");
var $attributes = array("cn","gotoMimeApplication","gotoMimeLeftClickAction","gotoMimeIcon",
"description","gotoMimeFilePattern","gotoMimeEmbeddedApplication",
var $DivApps = NULL;
var $DivEApps = NULL;
- /* Mime type release mode */
- var $isReleaseMimeType = false;
+ var $FAIstate ="";
/* These vars will be copied too, if you use copy&paste mode */
var $CopyPasteVars = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData",
/* Orig_Dn is used to verify if this object is new or only edited */
var $orig_dn = "";
+ var $orig_base = "";
function mimetype(&$config,$dn= NULL)
{
$tmp = array();
for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){
$str = $this->attrs[$attr][$i];
- $tmp2= split("\|",$str);
+ $tmp2= explode("|",$str);
if(count($tmp2) == 2){
$name = $tmp2[0];
}
}
- /* Check if release Management is enabled */
- $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
- if(!empty($tmp)) {
- $this->isReleaseMimeType= true;
- }
-
/* Set base */
if ($this->dn == "new"){
if(session::is_set('CurrentMainBase')){
$this->base= dn2base($ui->dn);
}
} else {
- $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
+ $this->base= preg_replace ("/^.*,".preg_quote(get_ou("mimetypeRDN"), '/')."/i", "", $this->dn);
}
/* Get icon data */
}
session::set('binary',$this->iconData);
session::set('binarytype',"image/jpeg");
+ $this->orig_base = $this->base;
}
$tmp = $this->plInfo();
foreach($tmp['plProvidedAcls'] as $name => $translation){
- $smarty->assign($name."ACL",$this->getacl($name));
- }
-
- /* Base select dialog */
- $once = true;
- foreach($_POST as $name => $value){
- if(preg_match("/^chooseBase/",$name) && $once){
- $once = false;
- $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
- $this->dialog->setCurrentBase($this->base);
- }
- }
-
- /* Dialog handling */
- if(is_object($this->dialog)){
-
- /* Must be called before save_object */
- $this->dialog->save_object();
-
- if($this->dialog->isClosed()){
- $this->dialog = false;
- }elseif($this->dialog->isSelected()){
-
- /* A new base was selected, check if it is a valid one */
- $tmp = $this->get_allowed_bases();
- if(isset($tmp[$this->dialog->isSelected()])){
- $this->base = $this->dialog->isSelected();
- }
-
- $this->dialog= false;
- }else{
- return($this->dialog->execute());
- }
+ $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/i",$this->FAIstate)));
}
+ $smarty->assign("IconReadable", preg_match("/r/",$this->getacl("gotoMimeIcon",preg_match("/freeze/i",$this->FAIstate))));
/* Check Posts */
$posts = array(
$once = true;
/* Walk through posts and try to find some commands for us. */
- foreach($_POST as $name => $value){
-
- /* Walk through possible commands */
- foreach($posts as $regex => $action){
-
- /* Check if there is a command posted */
- if(preg_match($regex,$name) && $once){
- $once = false;
-
- /* Get action vars */
- $func = $action['Func']; // Get function name
- $attr = $action['Attr']; // Get attribute name
-
- /* Get entry id */
- $s_entry = preg_replace($regex,"",$name);
- $s_entry = preg_replace("/_[xy]$/","",$s_entry);
-
- /* Execute a command with the given attribute and entry
- e.g. $this->gotoMimeFilePattern = $this->ArrayUp(3,$this->gotoMimeFilePattern) */
- if($this->acl_is_writeable($attr)){
- $this->$attr= $this->$func($s_entry,$this->$attr,true);
+ if(!preg_match("/freeze/i",$this->FAIstate)){
+ foreach($_POST as $name => $value){
+
+ /* Walk through possible commands */
+ foreach($posts as $regex => $action){
+
+ /* Check if there is a command posted */
+ if(preg_match($regex,$name) && $once){
+ $once = false;
+
+ /* Get action vars */
+ $func = $action['Func']; // Get function name
+ $attr = $action['Attr']; // Get attribute name
+ $acl_a = preg_replace("/^use_/","",$action['Attr']); // Get attribute name
+
+ /* Get entry id */
+ $s_entry = preg_replace($regex,"",$name);
+ $s_entry = preg_replace("/_[xy]$/","",$s_entry);
+
+ /* Execute a command with the given attribute and entry
+ e.g. $this->gotoMimeFilePattern = $this->ArrayUp(3,$this->gotoMimeFilePattern) */
+ if($this->acl_is_writeable($acl_a)){
+ $this->$attr= $this->$func($s_entry,$this->$attr,true);
+ }
}
}
}
- }
-
- /* Set a new icon was requested */
- if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
- $this->set_new_picture($_FILES['picture_file']['tmp_name']);
- }
-
- /* Add gotoMimeFilePattern */
- if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
- if($this->acl_is_writeable("gotoMimeFilePattern")){
- $str = $_POST['NewFilePattern'];
- if(!empty($str)){
- $this->use_gotoMimeFilePattern[] = $str;
- }
- }
- }
- /* Add gotoMimeFilePattern */
- if(isset($_POST['AddNewApplication']) &&
- (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
- if($this->acl_is_writeable("gotoMimeApplication")){
- $str = "";
- if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
- $str = get_post("NewApplicationSelect");
- }
- if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
- $str = get_post("NewApplication");
- }
- if(!empty($str) && !in_array($str,$this->use_gotoMimeApplication)){
- $this->use_gotoMimeApplication[] = $str;
- }
+ /* Set a new icon was requested */
+ if(isset($_POST['update_icon']) && (isset($_FILES['picture_file']['name']))){
+ $this->set_new_picture($_FILES['picture_file']['tmp_name']);
}
- }
- /* Add embedded application
- * - From input or from select box
- */
- if(isset($_POST['AddNewEmbeddedApplication']) &&
- (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
- if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
- $str = "";
- if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
- $str = get_post('NewEmbeddedApplicationSelect');
+ /* Add gotoMimeFilePattern */
+ if(isset($_POST['AddNewFilePattern']) && isset($_POST['NewFilePattern'])){
+ if($this->acl_is_writeable("gotoMimeFilePattern")){
+ $str = trim($_POST['NewFilePattern']);
+ if($str != ""){
+ $this->use_gotoMimeFilePattern[] = $str;
+ }
}
- if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
- $str = get_post('NewEmbeddedApplication');
+ }
+
+ /* Add gotoMimeFilePattern */
+ if(isset($_POST['AddNewApplication']) &&
+ (isset($_POST['NewApplication']) || isset($_POST['NewApplicationSelect']))){
+ if($this->acl_is_writeable("gotoMimeApplication")){
+ $str = "";
+ if(isset($_POST['NewApplicationSelect']) && !empty($_POST['NewApplicationSelect'])){
+ $str = trim(get_post("NewApplicationSelect"));
+ }
+ if(isset($_POST['NewApplication']) && !empty($_POST['NewApplication'])){
+ $str = trim(get_post("NewApplication"));
+ }
+ if($str != "" && !in_array($str,$this->use_gotoMimeApplication)){
+ $this->use_gotoMimeApplication[] = $str;
+ }
}
- if(!empty($str) && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
- $this->use_gotoMimeEmbeddedApplication[] = $str;
+ }
+
+ /* Add embedded application
+ * - From input or from select box
+ */
+ if(isset($_POST['AddNewEmbeddedApplication']) &&
+ (isset($_POST['NewEmbeddedApplication']) || isset($_POST['NewEmbeddedApplicationSelect']))){
+ if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
+ $str = "";
+ if(isset($_POST['NewEmbeddedApplicationSelect']) && !empty($_POST['NewEmbeddedApplicationSelect'])){
+ $str = trim(get_post('NewEmbeddedApplicationSelect'));
+ }
+ if(isset($_POST['NewEmbeddedApplication']) && !empty($_POST['NewEmbeddedApplication'])){
+ $str = trim(get_post('NewEmbeddedApplication'));
+ }
+ if($str != "" && !in_array($str,$this->use_gotoMimeEmbeddedApplication)){
+ $this->use_gotoMimeEmbeddedApplication[] = $str;
+ }
}
- }
+ }
}
/* Create divlists */
$DivEApps -> SetHeight(100);
- if($this->acl_is_writeable("gotoMimeFilePattern")){
- $Pattern_Actions= " <input type='image' src='images/sort_up.png' class='center' name='Pattern_SortUp_%s' >
- <input type='image' src='images/sort_down.png' class='center' name='Pattern_SortDown_%s'>
- <input type='image' src='images/edittrash.png' class='center' name='Pattern_Remove_%s'>";
+ if($this->acl_is_writeable("gotoMimeFilePattern") && !preg_match("/freeze/i",$this->FAIstate)){
+ $Pattern_Actions= " <input type='image' src='images/lists/sort-up.png' class='center' name='Pattern_SortUp_%s' >
+ <input type='image' src='images/lists/sort-down.png' class='center' name='Pattern_SortDown_%s'>
+ <input type='image' src='images/lists/trash.png' class='center' name='Pattern_Remove_%s'>";
}else{
$Pattern_Actions= "";
}
- if($this->acl_is_writeable("gotoMimeApplication")){
- $Apps_Actions = " <input type='image' src='images/sort_up.png' class='center' name='Apps_SortUp_%s' >
- <input type='image' src='images/sort_down.png' class='center' name='Apps_SortDown_%s'>
- <input type='image' src='images/edittrash.png' class='center' name='Apps_Remove_%s'>";
+ if($this->acl_is_writeable("gotoMimeApplication") && !preg_match("/freeze/i",$this->FAIstate)){
+ $Apps_Actions = " <input type='image' src='images/lists/sort-up.png' class='center' name='Apps_SortUp_%s' >
+ <input type='image' src='images/lists/sort-down.png' class='center' name='Apps_SortDown_%s'>
+ <input type='image' src='images/lists/trash.png' class='center' name='Apps_Remove_%s'>";
}else{
$Apps_Actions= "";
}
- if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
- $EApps_Actions = " <input type='image' src='images/sort_up.png' class='center' name='EApps_SortUp_%s' >
- <input type='image' src='images/sort_down.png' class='center' name='EApps_SortDown_%s'>
- <input type='image' src='images/edittrash.png' class='center' name='EApps_Remove_%s'>";
+ if($this->acl_is_writeable("gotoMimeEmbeddedApplication") && !preg_match("/freeze/i",$this->FAIstate)){
+ $EApps_Actions = " <input type='image' src='images/lists/sort-up.png' class='center' name='EApps_SortUp_%s' >
+ <input type='image' src='images/lists/sort-down.png' class='center' name='EApps_SortDown_%s'>
+ <input type='image' src='images/lists/trash.png' class='center' name='EApps_Remove_%s'>";
}else{
$EApps_Actions= "";
}
}
$smarty->assign("bases", $this->get_allowed_bases());
$smarty->assign("base_select", $this->base);
- $smarty->assign("isReleaseMimeType", $this->isReleaseMimeType);
+ $smarty->assign("isReleaseMimeType", $this->is_release());
$smarty->assign("gotoMimeFilePatterns", $DivPatterns->DrawList());
$smarty->assign("gotoMimeApplications", $DivApps->DrawList());
$smarty->assign("gotoMimeEmbeddedApplications", $DivEApps->DrawList());
function save_object()
{
- if(isset($_POST['MimeGeneric'])){
+ if(isset($_POST['MimeGeneric']) && !preg_match("/freeze/i",$this->FAIstate)){
/* Create a base backup and reset the
base directly after calling plugin::save_object();
$this->base = $base_tmp;
/* Only save base if we are not in release mode */
- if(!$this->isReleaseMimeType){
+ if(!$this->is_release()){
/* Set new base if allowed */
$tmp = $this->get_allowed_bases();
$ldap->add($this->attrs);
new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
}
- show_ldap_error($ldap->get_error(), sprintf(_("Saving of mime type/generic with dn '%s' failed."),$this->dn));
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+ }
}
plugin::remove_from_parent();
$ldap = $this->config->get_ldap_link();
$ldap->rmDir($this->dn);
- show_ldap_error($ldap->get_error(), sprintf(_("Removing of mime type/generic with dn '%s' failed."),$this->dn));
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
+ }
new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
/* Optionally execute a command after we're done */
$og= new ogroup($this->config, $ldap->getDN());
unset($og->member[$this->dn]);
$og->save ();
- show_ldap_error($ldap->get_error(), sprintf(_("Removing mime type from objectgroup '%s' failed"), $og->dn));
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, 0, get_class()));
+ }
}
}
function check()
{
$message = plugin::check();
- if(empty($this->cn)){
- $message[] = _("Please specify a valid name for this mime type.");
+ if($this->cn == "" ){
+ $message[] = msgPool::required(_("Name"));
}
if(!count($this->use_gotoMimeFilePattern)){
- $message[] = _("Please specify at least one file pattern.") ;
+ $message[] = msgPool::required(_("File pattern"));
}
/* Check if there is already a mime type with this cn */
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current["BASE"]);
- $mimefilter = session::get('mimefilter');
-
- if($this->isReleaseMimeType && (isset($mimefilter['release']))){
- $baseDn = str_replace($this->config->current['BASE'],$this->base,$mimefilter['release']);
- $baseDn = preg_replace("/".get_ou('mimetypeou').".*/",get_ou('mimetypeou').$this->base,$mimefilter['release']);
- $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$baseDn,array("cn"));
- if($ldap->count()){
- $attrs = $ldap->fetch();
- if($this->dn != $attrs['dn']) {
- $message[]= _("There's already a mime type with this 'Name'.");
- }
- }
+ if($this->is_release()){
+ $base = $this->parent->parent->mime_release;
}else{
- $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",get_ou('mimetypeou').$this->base,array("cn"));
- if ($ldap->count()){
- $attrs = $ldap->fetch();
- if($this->dn != $attrs['dn']) {
- $message[]= _("There's already an mime with this 'Name'.");
- }
+ $base = get_ou("mimetypeRDN").$this->base;
+ }
+
+ $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$base,array("cn"));
+ if($ldap->count()){
+ $attrs = $ldap->fetch();
+ if($this->dn != $attrs['dn']) {
+ $message[]= msgPool::duplicated("cn");
}
}
+ /* Check if we are allowed to create or move this object
+ */
+ if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
+ $message[] = msgPool::permCreate();
+ }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+ $message[] = msgPool::permMove();
+ }
+
return($message);
}
+
/** Helper functions **/
/* Set a new picture */
function set_new_picture($filename)
{
if (empty($filename)){
- $filename= "./images/default_icon.png";
+ $filename= "./plugins/goto/images/default_icon.png";
$this->use_gotoMimeIcon= "*removed*";
}else{
$this->use_gotoMimeIcon= $filename;
}
+
+ function is_release()
+ {
+ if(is_object($this->parent->parent)){
+ return($this->parent->parent->IsReleaseManagementActivated());
+ }else{
+ /* Check if we should enable the release selection */
+ $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
+ if(!empty($tmp)){
+ return(true);
+ }
+ }
+ return(FALSE);
+ }
+
+
function PrepareForCopyPaste($source)
{
plugin::PrepareForCopyPaste($source);