From c59187bbd00e137911ad8d775a0e99e7d65c0683 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 28 Jun 2006 10:31:01 +0000 Subject: [PATCH] Added mimetype classes git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3956 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../mimetypes/class_divListMimeTypes.inc | 212 +++++++ .../admin/mimetypes/class_mimetypeGeneric.inc | 536 ++++++++++++++++++ .../mimetypes/class_mimetypeManagement.inc | 506 +++++++++++++++++ plugins/admin/mimetypes/generic.tpl | 131 +++++ plugins/admin/mimetypes/main.inc | 49 ++ plugins/admin/mimetypes/paste_generic.tpl | 31 + plugins/admin/mimetypes/release_select.tpl | 16 + plugins/admin/mimetypes/remove.tpl | 17 + plugins/admin/mimetypes/tabs_mimetypes.inc | 61 ++ 9 files changed, 1559 insertions(+) create mode 100755 plugins/admin/mimetypes/class_divListMimeTypes.inc create mode 100644 plugins/admin/mimetypes/class_mimetypeGeneric.inc create mode 100755 plugins/admin/mimetypes/class_mimetypeManagement.inc create mode 100644 plugins/admin/mimetypes/generic.tpl create mode 100755 plugins/admin/mimetypes/main.inc create mode 100644 plugins/admin/mimetypes/paste_generic.tpl create mode 100755 plugins/admin/mimetypes/release_select.tpl create mode 100755 plugins/admin/mimetypes/remove.tpl create mode 100755 plugins/admin/mimetypes/tabs_mimetypes.inc diff --git a/plugins/admin/mimetypes/class_divListMimeTypes.inc b/plugins/admin/mimetypes/class_divListMimeTypes.inc new file mode 100755 index 000000000..91e60d29d --- /dev/null +++ b/plugins/admin/mimetypes/class_divListMimeTypes.inc @@ -0,0 +1,212 @@ +selectedRelease = "ou=mime,".$_SESSION['CurrentMainBase']; + $this->parent = $parent; + $this->ui = get_userinfo(); + $this->AvailableReleases= $this->parent->getReleases($this->selectedBase); + + /* Set list strings */ + $this->SetTitle (_("List of defined mime types")); + $this->SetSummary (_("List of defined mime types")); + $this->SetInformation (_("This menu allows you to add, edit and remove selected mime types. You may want to use the range selector on top of the mime type listbox, when working with a large number of mime types.")); + + /* Result page will look like a headpage */ + $this->SetHeadpageMode(); + $this->EnableAplhabet(true); + + /* Disable buttonsm */ + $this->EnableCloseButton(false); + $this->EnableSaveButton (false); + + /* set Page header */ + $action_col_size = 70; + if($this->parent->snapshotEnabled()){ + $action_col_size += 38; + } + + /* set Page header */ + $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); + $this->AddHeader(array("string" => _("Mime type name")." / "._("Department"), "attach" => "style=''")); + $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'")); + + /* Add SubSearch checkbox */ + $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false); + + /* Name ,Text ,Default , Connect with alphabet */ + $this->AddRegex ("Regex", _("Display mime types matching"),"*" , true); + } + + + /* This function allows us to add a user defined filter part at position $position*/ + function AddUserBoxToFilter($position) + { + $str = ""; + if(($position == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){ + $smarty = get_smarty(); + $smarty->assign("selectedRelease",$this->selectedRelease); + $smarty->assign("branchimage","images/branch.png"); + $smarty->assign("releases",$this->AvailableReleases); + $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE)); + } + return($str); + } + + + /* Create list header, with create / copy & paste etc*/ + function GenHeader() + { + /* Prepare departments, + which are shown in the listbox on top of the listbox + */ + $options= ""; + foreach ($this->config->idepartments as $key => $value){ + if ($this->selectedBase == $key){ + $options.= ""; + } else { + $options.= ""; + } + } + + /* Get copy & paste icon */ + if($this->parent->CopyPasteHandler){ + $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon(); + }else{ + $Copy_Paste =""; + } + + /* Create listhead, it will be shown on top of the divlist. + * It provides general navigation and object creation + */ + $listhead = "
". + "  ". + "  ". + "  ". + "  ". + "  "; + $listhead .= $this->get_snapshot_header($this->selectedBase); + $listhead .= "  ". + $Copy_Paste. + "  ". + _("Base")." ". + "  ". + "
"; + + $this->SetListHeader($listhead); + } + + + /* Some basic settings */ + function execute() + { + $this->ClearElementsList(); + $this->GenHeader(); + } + + + function setEntries($list) + { + /******************** + Variable init + ********************/ + + /* Create links */ + $linkopen = "%s"; + $editlink = "%s"; + $userimg = "User"; + $mimeimg = "A"; + $empty = ""; + + /* set Page header */ + $action_col_size = 70; + if($this->parent->snapshotEnabled()){ + $action_col_size += 38; + } + + /******************** + Attach objects + ********************/ + + foreach($list as $key => $val){ + + /* Create action icons */ + $actions = $this->GetSnapShotActions($val['dn']); + if($this->parent->CopyPasteHandler){ + $actions.= " "; + $actions.= " "; + } + $actions.= ""; + $actions.= ""; + + $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'"; + + if(!isset($val['description'][0])){ + $desc = ""; + }else{ + $desc = " - [ ".$val['description'][0]." ]"; + } + $field1 = array("string" => sprintf($mimeimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'"); + $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title); + $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"); + $this->AddElement(array($field1,$field2,$field3)); + } + + } + + function Save() + { + MultiSelectWindow::Save(); + } + + function save_object() + { + /* Save automatic created POSTs like regex, checkboxes */ + MultiSelectWindow::save_object(); + + /* check if returned selectedRelease is a valid release. + If it isn't set to a valid release */ + $this->AvailableReleases = $this->parent->getReleases($this->selectedBase); + if(!isset($this->AvailableReleases[$this->selectedRelease])){ + $this->selectedRelease =key($this->AvailableReleases); + } + $_SESSION['mimefilter']['release'] = $this->selectedRelease; + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/mimetypes/class_mimetypeGeneric.inc b/plugins/admin/mimetypes/class_mimetypeGeneric.inc new file mode 100644 index 000000000..07ae5b804 --- /dev/null +++ b/plugins/admin/mimetypes/class_mimetypeGeneric.inc @@ -0,0 +1,536 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + var $objectclasses = array("top","gotoMimeType"); + var $attributes = array("cn","gotoMimeApplication","gotoMimeLeftClickAction","gotoMimeIcon", + "description","gotoMimeFilePattern","gotoMimeEmbeddedApplication", + "gotoMimeGroup"); + + /* Class vars */ + var $acl; + var $ui; + var $cn = ""; + var $gotoMimeLeftClickAction = "I"; + var $gotoMimeLeftClickAction_I = false; + var $gotoMimeLeftClickAction_E = false; + var $gotoMimeLeftClickAction_Q = false; + var $gotoMimeIcon = "*removed*"; + var $description = ""; + var $gotoMimeFilePattern = array(); + var $gotoMimeApplication = array(); + var $gotoMimeEmbeddedApplication = array(); + var $use_gotoMimeFilePattern = array(); + var $use_gotoMimeApplication = array(); + var $use_gotoMimeEmbeddedApplication = array(); + var $gotoMimeGroup = ""; + var $iconData = NULL; + + /* divLists */ + var $DivPatterns = NULL; + var $DivApps = NULL; + var $DivEApps = NULL; + + /* Mime type release mode */ + var $isReleaseMimeType = false; + + /* These vars will be copied too, if you use copy&paste mode */ + var $CopyPasteVars = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData"); + + /* Select options */ + var $MimeGroups = array("video","audio","system"); + + + function mimetype($config,$dn= NULL) + { + plugin::plugin ($config, $dn); + + /* get gotoMimeLeftClickActions I/E/Q */ + if(isset($this->gotoMimeLeftClickAction)){ + $str = $this->gotoMimeLeftClickAction; + for($i = 0 ; $i < strlen($str) ; $i ++ ){ + $varna = "gotoMimeLeftClickAction_". $str[$i]; + if(isset($this->$varna)){ + $this->$varna = true; + } + } + } + + /* Get list of array attributes */ + foreach(array("gotoMimeFilePattern") as $attr){ + $this->$attr = array(); + if(isset($this->attrs[$attr])){ + $tmp = array(); + for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){ + $str = $this->attrs[$attr][$i]; + $tmp[] = $str; + } + $use_attr = "use_".$attr; + $this->$use_attr = $tmp; + } + } + + /* Get list of array attributes wit priority */ + foreach(array("gotoMimeApplication","gotoMimeEmbeddedApplication") as $attr){ + $this->$attr = array(); + if(isset($this->attrs[$attr])){ + $tmp = array(); + for($i = 0 ; $i < $this->attrs[$attr]['count'] ; $i ++){ + $str = $this->attrs[$attr][$i]; + $tmp2= split("\|",$str); + + if(count($tmp2) == 2){ + $name = $tmp2[0]; + $prio = $tmp2[1]; + $tmp[$prio] = $name; + } + } + ksort($tmp); + $use_attr = "use_".$attr; + $this->$use_attr = $tmp; + } + } + + /* Check if release Management is enabled */ + $tmp = search_config($this->config->data,"faiManagement","CLASS"); + if(!empty($tmp)) { + if(!preg_match("/^ou=apps,/",$_SESSION['mimefilter']['release'])){ + $this->isReleaseMimeType= true; + } + } + + /* Get icon data */ + if(isset($this->attrs['gotoMimeIcon'])){ + $ldap = $this->config->get_ldap_link(); + $this->iconData = $ldap->get_attribute($this->dn,"gotoMimeIcon"); + $this->saved_attributes['gotoMimeIcon'] = $this->iconData; + } + if ($this->iconData == ""){ + $this->set_new_picture(""); + } + $_SESSION['binary'] = $this->iconData; + $_SESSION['binarytype'] = "image/jpeg"; + } + + + function execute() + { + $smarty = get_smarty(); + + /* Check Posts */ + $posts = array( + "/^Pattern_SortUp_/" => array("Action" => "Pattern_SortUp", "Func" => "ArrayUp", "Attr" => "use_gotoMimeFilePattern"), + "/^Pattern_SortDown_/" => array("Action" => "Pattern_SortDown","Func" => "ArrayDown", "Attr" => "use_gotoMimeFilePattern"), + "/^Pattern_Remove_/" => array("Action" => "Pattern_Remove", "Func" => "ArrayRemove","Attr" => "use_gotoMimeFilePattern"), + "/^Apps_SortUp_/" => array("Action" => "Apps_SortUp", "Func" => "ArrayUp", "Attr" => "use_gotoMimeApplication"), + "/^Apps_SortDown_/" => array("Action" => "Apps_SortDown", "Func" => "ArrayDown", "Attr" => "use_gotoMimeApplication"), + "/^Apps_Remove_/" => array("Action" => "Apps_Remove", "Func" => "ArrayRemove","Attr" => "use_gotoMimeApplication"), + "/^EApps_SortUp_/" => array("Action" => "EApps_SortUp", "Func" => "ArrayUp", "Attr" => "use_gotoMimeEmbeddedApplication"), + "/^EApps_SortDown_/" => array("Action" => "EApps_SortDown", "Func" => "ArrayDown", "Attr" => "use_gotoMimeEmbeddedApplication"), + "/^EApps_Remove_/" => array("Action" => "EApps_Remove", "Func" => "ArrayRemove","Attr" => "use_gotoMimeEmbeddedApplication")); + $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(chkacl($this->acl,$attr) == ""){ + $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(chkacl($this->acl,"gotoMimeFilePattern") == ""){ + $str = $_POST['NewFilePattern']; + if(!empty($str)){ + $this->use_gotoMimeFilePattern[] = $str; + } + } + } + + /* Add gotoMimeFilePattern */ + if(isset($_POST['AddNewApplication']) && isset($_POST['NewApplication'])){ + if(chkacl($this->acl,"gotoMimeApplication") == ""){ + $str = $_POST['NewApplication']; + if(!empty($str)){ + $this->use_gotoMimeApplication[] = $str; + } + } + } + + /* Add gotoMimeFilePattern */ + if(isset($_POST['AddNewEmbeddedApplication']) && isset($_POST['NewEmbeddedApplication'])){ + if(chkacl($this->acl,"gotoMimeEmbeddedApplication") == ""){ + $str = $_POST['NewEmbeddedApplication']; + if(!empty($str)){ + $this->use_gotoMimeEmbeddedApplication[] = $str; + } + } + } + + /* Create divlists */ + $DivPatterns = new DivSelectBox("gotoMimePatterns"); + $DivApps = new DivSelectBox("gotoMimeApplications"); + $DivEApps = new DivSelectBox("gotoMimeEmbeddedApplications"); + $DivPatterns -> SetHeight(100); + $DivApps -> SetHeight(100); + $DivEApps -> SetHeight(100); + + + if(chkacl($this->acl,"gotoMimeFilePattern") == ""){ + $Pattern_Actions= "   +   + "; + }else{ + $Pattern_Actions= ""; + } + + if(chkacl($this->acl,"gotoMimeApplication") == ""){ + $Apps_Actions = "   +   + "; + }else{ + $Apps_Actions= ""; + } + + if(chkacl($this->acl,"gotoMimeEmbeddedApplication") == ""){ + $EApps_Actions = "   +   + "; + }else{ + $EApps_Actions= ""; + } + + foreach($this->use_gotoMimeFilePattern as $key => $pattern){ + $field1 = array("string" => $pattern); + $field2 = array("string" => preg_replace("/%s/",$key,$Pattern_Actions),"attach"=>"style='border-right:0px;width:50px;'"); + $fields = array($field1,$field2); + $DivPatterns -> AddEntry($fields); + } + foreach($this->use_gotoMimeApplication as $key => $pattern){ + $field1 = array("string" => $pattern); + $field2 = array("string" => preg_replace("/%s/",$key,$Apps_Actions),"attach"=>"style='border-right:0px;width:50px;'"); + $fields = array($field1,$field2); + $DivApps -> AddEntry($fields); + } + foreach($this->use_gotoMimeEmbeddedApplication as $key => $pattern){ + $field1 = array("string" => $pattern); + $field2 = array("string" => preg_replace("/%s/",$key,$EApps_Actions),"attach"=>"style='border-right:0px;width:50px;'"); + $fields = array($field1,$field2); + $DivEApps -> AddEntry($fields); + } + $smarty->assign("gotoMimeFilePatterns", $DivPatterns->DrawList()); + $smarty->assign("gotoMimeApplications", $DivApps->DrawList()); + $smarty->assign("gotoMimeEmbeddedApplications", $DivEApps->DrawList()); + + /* Assign class vars to smarty */ + foreach($this->attributes as $attr){ + $smarty->assign($attr,$this->$attr); + $smarty->assign($attr."ACL",chkacl($this->acl,$attr)); + } + + /* Assign additional vars that are not included in attributes*/ + foreach(array("gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q") as $attr){ + $smarty->assign($attr,$this->$attr); + } + + /* Assign select box options */ + $smarty->assign("gotoMimeGroups",$this->MimeGroups); + $smarty->assign("gotoMimeIcon" ,$this->get_picture()); + return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__)))); + } + + function save_object() + { + if(isset($_POST['MimeGeneric'])){ + plugin::save_object(); + + + /* Save radio buttons */ + if(chkacl($this->acl,"gotoMimeLeftClickAction")== ""){ + if(isset($_POST['gotoMimeLeftClickAction_IE'])){ + $chr = $_POST['gotoMimeLeftClickAction_IE']; + if($chr == "E"){ + $this->gotoMimeLeftClickAction_E = true; + $this->gotoMimeLeftClickAction_I = false; + }else{ + $this->gotoMimeLeftClickAction_E = false; + $this->gotoMimeLeftClickAction_I = true; + } + } + if(isset($_POST['gotoMimeLeftClickAction_Q'])){ + $this->gotoMimeLeftClickAction_Q = true; + }else{ + $this->gotoMimeLeftClickAction_Q = false; + } + } + } + } + + + /* save current changes */ + function save() + { + /* Create gotoMimeLeftClickAction out of checkboxes and radio buttons */ + $arr = array ("E","I","Q"); + $str = ""; + foreach ($arr as $Chr){ + $var = "gotoMimeLeftClickAction_".$Chr; + if($this->$var){ + $str .= $Chr; + } + } + $this->gotoMimeLeftClickAction = $str; + + /* Create array entries */ + foreach(array("gotoMimeEmbeddedApplication","gotoMimeApplication") as $attr){ + $i = 0; + $use_attr = "use_".$attr; + $tmp = array(); + $this->$attr = array(); + foreach($this->$use_attr as $entry){ + $tmp[] = $entry."|".$i ++; + } + if($this->new && count($tmp) == 0){ + $this->$attr = ""; + } + } + + /* Create array entries */ + foreach(array("gotoMimeFilePattern") as $attr){ + $i = 0; + $use_attr = "use_".$attr; + $tmp = array(); + $this->$attr = ""; + foreach($this->$use_attr as $entry){ + $tmp[] = $entry; + } + $this->$attr = $tmp; + } + + plugin::save(); + + if($this->gotoMimeIcon != "*removed"){ + $this->attrs['gotoMimeIcon'] = $this->iconData; + } + + $ldap = $this->config->get_ldap_link(); + $ldap-> cd ( $this->config->current['BASE']); + $ldap->cat($this->dn); + if($ldap->count()){ + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify($this->attrs); + }else{ + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); + $ldap->cd($this->dn); + $ldap->add($this->attrs); + } + show_ldap_error($ldap->get_error(),_("Saving mime type failed.")); + } + + + /* Remove current mime type */ + function remove_from_parent() + { + $ldap->rmDir($this->dn); + show_ldap_error($ldap->get_error(), _("Removing mie type failed")); + + /* Optionally execute a command after we're done */ + $this->handle_post_events("remove"); + + /* Delete references to object groups */ + $ldap->cd ($this->config->current['BASE']); + $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn")); + while ($ldap->fetch()){ + $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)); + } + } + + + /* Check given values */ + function check() + { + $message = plugin::check(); + if(empty($this->cn)){ + $message[] = _("Please specify a valid name for this mime type."); + } + if(!count($this->use_gotoMimeFilePattern)){ + $message[] = _("Please specify at least one file pattern.") ; + } + return($message); + } + + /** Helper functions **/ + + /* Set a new picture */ + function set_new_picture($filename) + { + if (empty($filename)){ + $filename= "./images/default_icon.png"; + $this->gotoMimeIcon= "*removed*"; + } + + if (file_exists($filename)){ + $fd = fopen ($filename, "rb"); + $this->iconData= fread ($fd, filesize ($filename)); + $_SESSION['binary']= $this->iconData; + $_SESSION['binarytype']= "image/jpeg"; + fclose ($fd); + } + } + + /* Get picture link */ + function get_picture() + { + $_SESSION['binary']= $this->iconData; + $_SESSION['binarytype']= "image/jpeg"; + return("getbin.php"); + } + + /* Transports the given 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 given Arraykey one position down*/ + 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); + } + + + /* return the position of the element in the array */ + function getpos($atr,$attrs) + { + $i = 0; + foreach($attrs as $attr => $name) { + $i++; + if($attr == $atr){ + return($i); + } + } + return(-1); + } + + + /* Remove this element from array */ + function ArrayRemove($key,$array,$reorder = false) + { + if(isset($array[$key])){ + unset($array[$key]); + if($reorder){ + $tmp = array(); + foreach($array as $entry){ + $tmp[] = $entry; + } + $array = $tmp; + } + } + return($array); + } + + + /* Combine new array */ + function combineArrays($ar0,$ar1,$ar2) + { + $ret = array(); + if(is_array($ar0)) + foreach($ar0 as $ar => $a){ + $ret[]=$a; + } + if(is_array($ar1)) + foreach($ar1 as $ar => $a){ + $ret[]=$a; + } + if(is_array($ar2)) + foreach($ar2 as $ar => $a){ + $ret[]=$a; + } + return($ret); + } + + + /* Return a dialog with all fields that must be changed, + if we want to copy this entry */ + function getCopyDialog() + { + $str = ""; + + $smarty = get_smarty(); + $smarty->assign("cn", $this->cn); + $smarty->assign("description", $this->description); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__))); + + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); + } + + + /* Save all */ + function saveCopyDialog() + { + $attrs = array("cn","description"); + foreach($attrs as $attr){ + if(isset($_POST[$attr])){ + $this->$attr = $_POST[$attr]; + } + } + } +} +?> diff --git a/plugins/admin/mimetypes/class_mimetypeManagement.inc b/plugins/admin/mimetypes/class_mimetypeManagement.inc new file mode 100755 index 000000000..c7b7c5284 --- /dev/null +++ b/plugins/admin/mimetypes/class_mimetypeManagement.inc @@ -0,0 +1,506 @@ +config = $config; + $this->ui = $ui; + + /* Check if copy & paste is activated */ + if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){ + $this->CopyPasteHandler = new CopyPasteHandler($this->config); + } + + /* Creat dialog object */ + $this->DivListMimeTypes = new divListMimeTypes($this->config,$this); + + if($this->IsReleaseManagementActivated()){ + + /* Check if we should enable the release selection */ + $this->enableReleaseManagement = true; + + /* Hide SubSearch checkbox */ + $this->DivListMimeTypes->DisableCheckBox("SubSearch"); + } + + /* Get acls */ + $acl= get_permissions ($ui->dn, $ui->subtreeACL); + $this->acl= get_module_permission($acl, "mimetype", $ui->dn); + } + + + /* Get all releases */ + function getReleases($base) + { + $ldap = $this->config->get_ldap_link(); + $dn = "ou=mime,".$base; + $ret = array(); + $ret ["ou=mime,".$base] = "/"; + + $ldap->cd($dn); + $ldap->search("objectClass=organizationalUnit",array("ou")); + + while($attrs = $ldap->fetch()){ + $str = str_replace($dn,"",$attrs['dn']); + $tmp = array_reverse( split("ou=",$str)); + $str = ""; + foreach($tmp as $val){ + $val = trim(preg_replace("/,/","",$val)); + if(empty($val)) break; + $str .= "/".$val; + } + if(!empty($str)){ + $ret[$attrs['dn']]= preg_replace("/^\//","",$str); + } + } + asort($ret); + return($ret); + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + + /**************** + Variable init + ****************/ + + /* These vars will be stored if you try to open a locked mime, + to be able to perform your last requests after showing a warning message */ + $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^mime_edit_/","/^mime_del_/"); + + $smarty = get_smarty(); // Smarty instance + $s_action = ""; // Contains the action to proceed + $s_entry = ""; // The value for s_action + $base_back = ""; // The Link for Backbutton + + /* Test Posts */ + foreach($_POST as $key => $val){ + // Post for delete + if(preg_match("/mime_del.*/",$key)){ + $s_action = "del"; + $s_entry = preg_replace("/mime_".$s_action."_/i","",$key); + // Post for edit + }elseif(preg_match("/mime_edit_.*/",$key)){ + $s_action="edit"; + $s_entry = preg_replace("/mime_".$s_action."_/i","",$key); + // Post for new + }elseif(preg_match("/^copy_.*/",$key)){ + $s_action="copy"; + $s_entry = preg_replace("/^copy_/i","",$key); + }elseif(preg_match("/^cut_.*/",$key)){ + $s_action="cut"; + $s_entry = preg_replace("/^cut_/i","",$key); + // Post for new + }elseif(preg_match("/^mime_new.*/",$key)){ + $s_action="new"; + }elseif(preg_match("/^editPaste.*/i",$key)){ + $s_action="editPaste"; + } + } + + if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){ + $s_action ="edit"; + $s_entry = $_GET['id']; + } + + $s_entry = preg_replace("/_.$/","",$s_entry); + + + /**************** + Copy & Paste handling + ****************/ + + /* Only perform copy / paste if it is enabled + */ + if($this->CopyPasteHandler){ + if($str = $this->copyPasteHandling($s_action,$s_entry)){ + return($str); + }; + } + + + /**************** + Create a new mime type + ****************/ + + /* New mime type? */ + if ($s_action=="new"){ + + /* By default we set 'dn' to 'new', all relevant plugins will + react on this. */ + $this->dn= "new"; + + /* Create new usertab object */ + $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn); + + /* set acl */ + $acl= get_permissions ($this->DivListMimeTypes->selectedBase, $this->ui->subtreeACL); + $this->mimetabs->set_acl($acl); + } + + + /**************** + Edit entry canceled + ****************/ + + /* Cancel dialogs */ + if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){ + del_lock ($this->mimetabs->dn); + unset ($this->mimetabs); + $this->mimetabs= NULL; + unset ($_SESSION['objectinfo']); + } + + + /**************** + Edit entry finished + ****************/ + + /* Finish mime edit is triggered by the tabulator dialog, so + the user wants to save edited data. Check and save at this point. */ + if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply']) ) && (isset($this->mimetabs->config))){ + + /* Check tabs, will feed message array */ + $this->mimetabs->save_object(); + $message= $this->mimetabs->check(); + + /* Save, or display error message? */ + if (count($message) == 0){ + + /* Save data data to ldap */ + $this->mimetabs->set_release($this->DivListMimeTypes->selectedRelease); + $this->mimetabs->save(); + gosa_log ("Mime object'".$this->dn."' has been saved"); + + if (!isset($_POST['edit_apply'])){ + /* Mime type has been saved successfully, remove lock from LDAP. */ + if ($this->dn != "new"){ + del_lock ($this->dn); + } + unset ($this->mimetabs); + $this->mimetabs= NULL; + unset ($_SESSION['objectinfo']); + } + } else { + /* Ok. There seem to be errors regarding to the tab data, + show message and continue as usual. */ + show_errors($message); + } + } + + + /**************** + Edit entry + ****************/ + + /* User wants to edit data? */ + if (($s_action=="edit") && (!isset($this->mimetabs->config))){ + + /* Get 'dn' from posted 'mimelist', must be unique */ + $this->dn= $this->mimetypes[$s_entry]['dn']; + + /* Check locking, save current plugin in 'back_plugin', so + the dialog knows where to return. */ + if (($user= get_lock($this->dn)) != ""){ + return(gen_locked_message ($user, $this->dn)); + } + + /* Lock the current entry, so everyone will get the + above dialog */ + add_lock ($this->dn, $this->ui->dn); + + + /* Register mimetabs to trigger edit dialog */ + $this->mimetabs= new mimetabs($this->config,$this->config->data['TABS']['MIMETABS'], $this->dn); + + /* Set up the users ACL's for this 'dn' */ + $acl= get_permissions ($this->dn, $this->ui->subtreeACL); + $this->mimetabs->set_acl($acl); + $_SESSION['objectinfo']= $this->dn; + } + + + /**************** + Delete mime type + ****************/ + + /* Remove user was requested */ + if ($s_action == "del"){ + + /* Get 'dn' from posted 'uid' */ + $this->dn= $this->mimetypes[$s_entry]['dn']; + + /* Load permissions for selected 'dn' and check if + we're allowed to remove this 'dn' */ + if (chkacl($this->acl, "delete") == ""){ + + /* Check locking, save current plugin in 'back_plugin', so + the dialog knows where to return. */ + if (($user= get_lock($this->dn)) != ""){ + return (gen_locked_message ($user, $this->dn)); + } + + /* Lock the current entry, so nobody will edit it during deletion */ + add_lock ($this->dn, $this->ui->dn); + $smarty= get_smarty(); + $smarty->assign("intro", sprintf(_("You're about to delete the mime type '%s'."), @LDAP::fix($this->dn))); + return($smarty->fetch (get_template_path('remove.tpl', TRUE))); + } else { + + /* Obviously the user isn't allowed to delete. Show message and + clean session. */ + print_red (_("You are not allowed to delete this mime type!")); + } + } + + + /**************** + Delete mime confirmed + ****************/ + + /* Confirmation for deletion has been passed. Group should be deleted. */ + if (isset($_POST['delete_mime_confirm'])){ + + /* Some nice guy may send this as POST, so we've to check + for the permissions again. */ + if (chkacl($this->acl, "delete") == ""){ + + /* Delete request is permitted, perform LDAP action */ + $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn); + $acl= get_permissions ($this->dn, $this->ui->subtreeACL); + $this->mimetabs->set_acl($acl); + $this->mimetabs->delete (); + gosa_log ("Mime type object'".$this->dn."' has been removed"); + unset ($this->mimetabs); + $this->mimetabs= NULL; + + } else { + + /* Normally this shouldn't be reached, send some extra + logs to notify the administrator */ + print_red (_("You are not allowed to delete this mime type!")); + gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion."); + } + + /* Remove lock file after successfull deletion */ + del_lock ($this->dn); + } + + + /**************** + Delete mime canceled + ****************/ + + /* Delete mime type canceled? */ + if (isset($_POST['delete_cancel'])){ + del_lock ($this->dn); + unset($_SESSION['objectinfo']); + } + + /* Show tab dialog if object is present */ + if (($this->mimetabs) && (isset($this->mimetabs->config))){ + $display= $this->mimetabs->execute(); + + /* Don't show buttons if tab dialog requests this */ + if (!$this->mimetabs->by_object[$this->mimetabs->current]->dialog){ + $display.= "

\n"; + $display.= "\n"; + $display.= " \n"; + if ($this->dn != "new"){ + $display.= "\n"; + $display.= " \n"; + } + $display.= "\n"; + $display.= "

"; + } + return ($display); + } + + + /**************** + Dialog display + ****************/ + + /* Check if there is a snapshot dialog open */ + $base = $this->DivListMimeTypes->selectedBase; + if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){ + return($str); + } + + /* Display dialog with system list */ + $this->DivListMimeTypes->parent = $this; + $this->DivListMimeTypes->execute(); + $this->DivListMimeTypes->AddDepartments($this->DivListMimeTypes->selectedBase); + $this->reload(); + $this->DivListMimeTypes->setEntries($this->mimetypes); + return($this->DivListMimeTypes->Draw()); + } + + + /* Return departments, that will be included within snapshot detection */ + function get_used_snapshot_bases() + { + return(array($this->DivListMimeTypes->selectedRelease)); + } + + + + function reload() + { + $this->mimetypes= array(); + + /* Set base for all searches */ + $base = $this->DivListMimeTypes->selectedBase; + $release = $this->DivListMimeTypes->selectedRelease; + $Regex = $this->DivListMimeTypes->Regex; + $SubSearch = $this->DivListMimeTypes->SubSearch; + $Flags = GL_NONE | GL_SIZELIMIT; + $Filter = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=gotoMimeType))"; + $tmp = array(); + $Releases = $this->getReleases($base); + + + /* If release management is enabled, use release as base. */ + if(!$this->enableReleaseManagement){ + $use_base = $base; + }else{ + if(isset($Releases[$release])){ + $use_base = $release; + }else{ + $use_base = $base; + } + } + + /* In case of subsearch, add the subsearch flag */ + if($SubSearch){ + $Flags |= GL_SUBSEARCH; + } + + /* Get results and create index */ + $res= get_list($Filter, $this->ui->subtreeACL,$use_base, array("cn","description","dn","objectClass"), $Flags); + foreach ($res as $val){ + $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val; + } + + /* sort entries */ + ksort($tmp); + $this->mimetypes=array(); + foreach($tmp as $val){ + $this->mimetypes[]=$val; + } + reset ($this->mimetypes); + } + + function remove_from_parent() + { + /* Optionally execute a command after we're done */ + $this->postremove(); + } + + + function copyPasteHandling($s_action,$s_entry) + { + /* Paste copied/cutted object in here + */ + if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){ + $this->CopyPasteHandler->save_object(); + $this->CopyPasteHandler->SetVar("base", $this->DivListMimeTypes->selectedBase); + + if($str = $this->CopyPasteHandler->execute()) { + return($str); + } + } + + /* Copy current object to CopyHandler + */ + if($s_action == "copy"){ + $this->CopyPasteHandler->Clear(); + $dn = $this->mimetypes[$s_entry]['dn']; + $obj = new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $dn); + $objNew = new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], "new"); + $this->CopyPasteHandler->Copy($obj,$objNew); + } + + /* Copy current object to CopyHandler + */ + if($s_action == "cut"){ + $this->CopyPasteHandler->Clear(); + $dn = $this->mimetypes[$s_entry]['dn']; + $obj = new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $dn); + $this->CopyPasteHandler->Cut($obj); + } + } + + /* Check if the release management is activated. */ + function IsReleaseManagementActivated() + { + /* Check if we should enable the release selection */ + $tmp = search_config($this->config->data,"faiManagement","CLASS"); + if(!empty($tmp)){ + return(true); + } + return(false); + } + + /* Save to LDAP */ + function save() + { + /* Optionally execute a command after we're done */ + $this->postcreate(); + } + + function remove_lock() + { + if (isset($this->mimetabs->dn)){ + del_lock ($this->mimetabs->dn); + } + } + + function save_object() { + $this->DivListMimeTypes->save_object(); + } + + function check() {} + function adapt_from_template($dn) {} + function password_change_needed() {} + function show_header($button_text, $text, $disabled= FALSE) {} +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/mimetypes/generic.tpl b/plugins/admin/mimetypes/generic.tpl new file mode 100644 index 000000000..b37681542 --- /dev/null +++ b/plugins/admin/mimetypes/generic.tpl @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

 {t}Generic{/t}

+
+ + + + + + + + + + + + + + +
+ {t}Mime type{/t} + + +
+ {t}Mime group{/t} + + +
+ {t}Description{/t} + + +
+ +
+ + + + + +
+
+ +
+  
+ + + +
+
+

 

+
+

 {t}Left click{/t}

+
+ {t}File patterns{/t} + {$gotoMimeFilePatterns} +
+ + +
+ {t}Applications{/t} + {$gotoMimeApplications} +
+ + +
+

 

+
+

 {t}Embedding{/t}

+
+ + + + + +
+ + {t}Show file in embedded viewer{/t} +
+ + + {t}Show file in external viewer{/t} +
+ + + {t}Ask wheter to save to local disk{/t} +
+ +
+ {t}Applications{/t} + {$gotoMimeEmbeddedApplications} +
+ + +
+ + + + + + diff --git a/plugins/admin/mimetypes/main.inc b/plugins/admin/mimetypes/main.inc new file mode 100755 index 000000000..4ed3886ca --- /dev/null +++ b/plugins/admin/mimetypes/main.inc @@ -0,0 +1,49 @@ +save_object(); +$output= $MimeTypeManagement->execute(); + +/* Page header*/ +if (isset($_SESSION['objectinfo'])){ + $display= print_header(get_template_path('images/mimetypes.png'), _("Mimetype management"), "\"\" ".@LDAP::fix($_SESSION['objectinfo'])); +} else { + $display= print_header(get_template_path('images/application.png'), _("Mimetype management")); +} + +/* Reset requested? */ +if (isset($_GET['reset']) && $_GET['reset'] == 1){ + del_lock ($ui->dn); + sess_del ('MimeTypeManagement'); +} + +/* Show and save dialog */ +$display.= $output; +$_SESSION['MimeTypeManagement']= $MimeTypeManagement; + +?> diff --git a/plugins/admin/mimetypes/paste_generic.tpl b/plugins/admin/mimetypes/paste_generic.tpl new file mode 100644 index 000000000..aa3bf8050 --- /dev/null +++ b/plugins/admin/mimetypes/paste_generic.tpl @@ -0,0 +1,31 @@ + + + + + + + +
+

 {t}Generic{/t}

+
+ + + + + + + + + + +
+ {t}Mime type{/t} + + +
+ {t}Description{/t} + + +
+ +
diff --git a/plugins/admin/mimetypes/release_select.tpl b/plugins/admin/mimetypes/release_select.tpl new file mode 100755 index 000000000..d58738f05 --- /dev/null +++ b/plugins/admin/mimetypes/release_select.tpl @@ -0,0 +1,16 @@ +
+
+

[F]{t}Branches{/t}

+
+
+ + + + +
+ {t}Current release{/t}  + +
+
diff --git a/plugins/admin/mimetypes/remove.tpl b/plugins/admin/mimetypes/remove.tpl new file mode 100755 index 000000000..593c8175d --- /dev/null +++ b/plugins/admin/mimetypes/remove.tpl @@ -0,0 +1,17 @@ +
+  {t}Warning{/t} +
+

+ {$intro} + {t}This may be used by several groups. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} +

+

+ {t}So - if you're sure - press 'Delete' to continue or 'Cancel' to abort.{/t} +

+ +

+ +   + +

+ diff --git a/plugins/admin/mimetypes/tabs_mimetypes.inc b/plugins/admin/mimetypes/tabs_mimetypes.inc new file mode 100755 index 000000000..eb4368ce9 --- /dev/null +++ b/plugins/admin/mimetypes/tabs_mimetypes.inc @@ -0,0 +1,61 @@ +Release= preg_replace('/,ou=mime,.*$/', '', $newRelease); + if ($this->Release != ""){ + $this->Release= ",".$this->Release; + } + } + + function save() + { + $baseobject= $this->by_object['mimetype']; + + /* Check for new 'dn', in order to propagate the + 'dn' to all plugins */ + $tmp = search_config($this->config->data,"faiManagement","CLASS"); + + if((!empty($tmp)) && (isset($_SESSION['mimefilter']['release']))){ + if(!$baseobject->isReleaseMimeType){ + $new_dn= "cn=".$baseobject->cn.",ou=mime,".$baseobject->base; + }else{ + $new_dn ="cn=".$baseobject->cn.",".$_SESSION['mimefilter']['release']; + } + }else{ + $new_dn= "cn=".$baseobject->cn.",ou=mime,".$baseobject->base; + } + + /* Move group? */ + if ($this->dn != $new_dn){ + + /* Write entry on new 'dn' */ + if ($this->dn != "new"){ + $baseobject->move($this->dn, $new_dn); + $this->by_object['mimetype']= $baseobject; + } + + /* Happen to use the new one */ + $this->dn= $new_dn; + } + + tabs::save(); + + /* Fix tagging if needed */ + $baseobject->dn= $this->dn; + $baseobject->handle_object_tagging(); + $this->by_object['mimetype'] = $baseobject; + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> -- 2.30.2