X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_printGeneric.inc;h=a8843d920550ae492647e4e60614122cd63d7649;hb=38e36135b451936d249b671857b133a7d55b7360;hp=3394cc566927478f8cb511d7f67e99b3be0423f5;hpb=38faac5f97bc71af0a6cffbcca5138f09226470c;p=gosa.git
diff --git a/plugins/admin/systems/class_printGeneric.inc b/plugins/admin/systems/class_printGeneric.inc
index 3394cc566..a8843d920 100644
--- a/plugins/admin/systems/class_printGeneric.inc
+++ b/plugins/admin/systems/class_printGeneric.inc
@@ -3,13 +3,13 @@
class printgeneric extends plugin
{
/* CLI vars */
- var $cli_summary= "Manage terminal base objects";
- var $cli_description= "Some longer text\nfor help";
- var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+ var $cli_summary = "Manage terminal base objects";
+ var $cli_description = "Some longer text\nfor help";
+ var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
/* Generic terminal attributes */
- var $interfaces= array();
- var $ignore_account= FALSE;
+ var $interfaces = array();
+ var $ignore_account = FALSE;
/* Needed values and lists */
var $base = "";
@@ -26,17 +26,22 @@ class printgeneric extends plugin
var $UserMember ="";
var $UserMembers =array();
var $UserMemberKeys =array();
-
+
var $AdminMember ="";
var $AdminMembers =array();
var $AdminMemberKeys =array();
- var $member =array();
+ var $is_terminalBased = false;
+ var $PPDdialogToSave = NULL;
+
+ var $member =array();
+ var $strings = "";
+ var $type = "";
var $dialog =NULL;
/* attribute list for save action */
- var $attributes = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","macAddress", "ipHostNumber");
+ var $attributes = array("cn", "description", "l", "labeledURI", "macAddress", "ipHostNumber","gotoPrinterPPD");
var $objectclasses = array("top", "gotoPrinter");
function printgeneric ($config, $dn= NULL)
@@ -49,32 +54,49 @@ class printgeneric extends plugin
$ui= get_userinfo();
$this->base= dn2base($ui->dn);
$this->cn= "";
+ $this->is_terminal = true;
} else {
$this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
}
+ if(isset($this->gotoPrinterPPD)){
+ $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
+ }
- if((in_array("gotoWorkstation",$this->attrs['objectClass']))){
- $this->is_terminal = "true";
- $this->dn = preg_replace("/ou=workstation/","ou=printer",$this->dn);
-
- // Reload plugin with new dn... (ou=printers instead of ou=terminals)
- plugin::plugin ($this->config, $this->dn);
- $ldap->cat($this->dn);
- if(count($ldap->fetch())>0){
- $this->orig_dn= $this->dn;
- $this->is_account=true;
- $this->initially_was_account = true;
+ /* In case of gotoWorkstation this tab is calles from workstation plugin
+ * in case of gotoTerminal it is called from a terminal tab
+ * else it is a standalone printer
+ */
+ if((isset($this->attrs['objectClass']))&&(in_array("gotoWorkstation",$this->attrs['objectClass']))){
+ /* Fix for new Workstations */
+ if(preg_match("/ou=incoming/",$this->dn)){
+ $this->is_terminal = "true";
+ $this->dn = preg_replace("/ou=incoming/","ou=printers",$this->dn);
+ $this->type = "station";
}else{
- $this->orig_dn = "new";
- $this->is_account=false;
- $this->initially_was_account = false;
+ $this->is_terminal = "true";
+ $this->dn = preg_replace("/ou=workstations/","ou=printers",$this->dn);
+ $this->type = "station";
}
- }elseif((in_array("gotoTerminal",$this->attrs['objectClass']))){
- $this->is_terminal = "true";
- $this->dn = preg_replace("/ou=terminal/","ou=printer",$this->dn);
+ }elseif((isset($this->attrs['objectClass']))&&(in_array("gotoTerminal",$this->attrs['objectClass']))){
+ if(preg_match("/ou=incoming/",$this->dn)){
+ $this->is_terminal = "true";
+ $this->dn = preg_replace("/ou=incoming/","ou=printers",$this->dn);
+ $this->type = "terminal";
+ }else{
+ $this->type = "terminal";
+ $this->is_terminal = "true";
+ $this->dn = preg_replace("/ou=terminal/","ou=printers",$this->dn);
+ }
+ }else{
+ /* Save dn for later references */
+ $this->orig_dn= $this->dn;
+ }
- // Reload plugin with new dn... (ou=printers instead of ou=terminals)
+ /* If it is no standalone printer
+ */
+ if($this->is_terminal){
+ // Reload plugin with new dn... (ou=printers instead of ou=terminals)
plugin::plugin ($this->config, $this->dn);
$ldap->cat($this->dn);
if(count($ldap->fetch())>0){
@@ -86,43 +108,64 @@ class printgeneric extends plugin
$this->is_account=false;
$this->initially_was_account = false;
}
-
- }else{
-
- /* Save dn for later references */
- $this->orig_dn= $this->dn;
}
-
+
+ /* Prepare different member types
+ */
foreach(array("AddUser" =>"gotoUserPrinter",
"AddGroup" =>"gotoGroupPrinter",
"AddAdminUser" =>"gotoUserAdminPrinter",
"AddAdminGroup" =>"gotoGroupAdminPrinter") as $type => $attr){
+ /* $this->members contains all members */
$this->member[$type]=array();
- unset($this->attrs[$attr]['count']);
- if(isset($this->attrs[$attr]))
- foreach($this->attrs[$attr] as $mem){
- if(preg_match("/Group/",$type)){
- $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
- $entry = $ldap->fetch();
- if(isset($entry['description'])){
- $this->member[$type][$entry['cn'][0]]=$entry;
- }
- }else{
- $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
- $entry = $ldap->fetch();
- if(isset($entry['uid'])){
- $this->member[$type][$entry['uid'][0]]=$entry;
+
+ if (isset($this->attrs[$attr]['count'])) {
+ unset($this->attrs[$attr]['count']);
+ }
+
+ if(isset($this->attrs[$attr])){
+ foreach($this->attrs[$attr] as $mem){
+ if(preg_match("/Group/",$type)){
+ $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
+ $entry = $ldap->fetch();
+ if(isset($entry['description'])){
+ $this->member[$type][$entry['cn'][0]]=$entry;
+ }
+ }else{
+ $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
+ $entry = $ldap->fetch();
+ if(isset($entry['uid'])){
+ $this->member[$type][$entry['uid'][0]]=$entry;
+ }
}
}
}
}
-
+
+ $ldap->search("(&(cn=".$this->cn.")(|(objectClass=gotoTerminal)(objectClass=gotoWorkstation)))",array("cn","objectClass"));
+ if($attrs = $ldap->fetch()){
+ if(in_array("gotoTerminal",$attrs['objectClass'])){
+ $this->is_terminalBased = "Terminal";
+ }else{
+ $this->is_terminalBased = "Workstation";
+ }
+ }
+
+ /* A printer was only saved if the printer belongs to a workstation.
+ * If there was a new single printer created, it was never saved.
+ * -This allows new printers to be saved.
+ */
+ if($this->dn == "new"){
+ $this->is_account = true;
+ }
}
function execute()
{
- print_a($this);
+ /* Call parent execute */
+ plugin::execute();
+
$smarty= get_smarty();
$display="";
/* Template management.
@@ -146,13 +189,37 @@ class printgeneric extends plugin
}
if($this->is_terminal){
- if ($this->is_account){
- $display= $this->show_header(_("Remove environment extension"),
- _("This server has environment extension enabled. You can disable it by clicking below."));
- }else{
- $display= $this->show_header(_("Add environment extension"),
- _("This server has environment extension disabled. You can enable it by clicking below."));
- return ($display);
+ if(empty($this->cn)){
+ if(!in_array("gotoPrinter",$this->objectclasses)){
+ $display= $this->show_header(_("Add printer extension"),
+ _("This workstation has printer extension disabled. You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template"),TRUE,TRUE);
+ $this->is_account= false;
+ return $display;
+ }else{
+ $smarty->assign("is_terminal","false");
+ $skip = true;
+ }
+ }
+
+ if(!isset($skip)){
+ if (($this->is_account)){
+ if($this->type=="station"){
+ $display= $this->show_header(_("Remove printer extension"),
+ _("This workstation has printer extension enabled.You can disable it by clicking below."));
+ }else{
+ $display= $this->show_header(_("Remove printer extension"),
+ _("This terminal has printer extension enabled. You can disable it by clicking below."));
+ }
+ }else{
+ if($this->type=="station"){
+ $display= $this->show_header(_("Add printer extension"),
+ _("This workstation has printer extension disabled. You can enable it by clicking below."));
+ }else{
+ $display= $this->show_header(_("Add printer extension"),
+ _("This terminal has printer extension disabled. You can enable it by clicking below."));
+ }
+ return ($display);
+ }
}
}
@@ -173,7 +240,7 @@ class printgeneric extends plugin
$smarty->assign($attr."ACL", chkacl($this->acl, $attr));
$smarty->assign("$attr", $this->$attr);
}
-
+
if(isset($_POST['AddUser'])){
$this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddUser");
}
@@ -187,10 +254,47 @@ class printgeneric extends plugin
$this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminGroup");
}
+ if(isset($_POST['EditDriver'])){
+ if($this->PPDdialogToSave){
+ $this->dialog = $this->PPDdialogToSave;
+ }else{
+ $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
+ }
+ }
+
if(isset($_POST['PrinterCancel'])){
unset($this->dialog);
$this->dialog= NULL;
}
+
+ if(isset($_POST['RemoveDriver'])){
+ $this->gotoPrinterPPD = array();
+ $this->PPDdialogToSave = NULL;
+ }
+
+ if(isset($_POST['SavePPD'])){
+ $this->dialog->save_object();
+ if(count($this->dialog->check())){
+ foreach($this->dialog->check() as $msg){
+ print_red($msg);
+ }
+ }else{
+ $this->gotoPrinterPPD = array();
+
+ $this->gotoPrinterPPD = $this->dialog->save();
+ $this->PPDdialogToSave = $this->dialog;
+ unset($this->dialog);
+ $this->dialog=NULL;
+ }
+
+ }
+
+ if(isset($_POST['ClosePPD'])){
+ unset($this->dialog);
+ $this->dialog=NULL;
+ }
+
+
if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
if(isset($this->member['AddUser'][$_POST['UserMember']])){
@@ -211,7 +315,7 @@ class printgeneric extends plugin
}
if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
- if(isset($this->member['AddAdmingroup'][$_POST['AdminMember']])){
+ if(isset($this->member['AddAdminGroup'][$_POST['AdminMember']])){
unset($this->member['AddAdminGroup'][$_POST['AdminMember']]);
}
}
@@ -242,18 +346,49 @@ class printgeneric extends plugin
}
if($this->dialog != NULL){
+ $this->dialog->save_object();
$display = $this->dialog->execute();
return $display;
}
/* Don't show Asterisk for non-required attribute ipHostNumber and macAddress */
$smarty->assign("staticAddress", "");
- $smarty->assign("driverInfo", "Not implemented yet");
+
+
+ require_once ("class_ppdManager.inc");
+
+ if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
+ $ppdManager= new ppdManager($_SESSION['config']->data['MAIN']['PPD_PATH']);
+ if(!empty($this->gotoPrinterPPD)){
+ if((!file_exists($_SESSION['config']->data['MAIN']['PPD_PATH'].$this->gotoPrinterPPD))){
+ $smarty->assign("driverInfo", "".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$this->gotoPrinterPPD))."";
+ }else{
+ $smarty->assign("driverInfo", $ppdManager->loadDescription($_SESSION['config']->data['MAIN']['PPD_PATH'].$this->gotoPrinterPPD));
+ }
+ }else{
+ $smarty->assign("driverInfo", _("not defined"));
+ }
+ }else{
+ $smarty->assign("driverInfo",_("can't get ppd informations."));
+ }
+
$list=$this->generateList();
$userlist = array_merge($list['AddUser'],$list['AddGroup']);
$adminlist = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
+ asort($userlist);
+ asort($adminlist);
+ if($this->is_terminalBased){
+ if($this->is_terminalBased == "Terminal"){
+ $smarty->assign("desc" ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"".$this->cn.""));
+ }else{
+ $smarty->assign("desc" ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"".$this->cn.""));
+ }
+ $smarty->assign("cnACL" ," disabled ");
+ }else{
+ $smarty->assign("desc" ,"");
+ }
$smarty->assign("UserMember" ,$this->UserMember);
$smarty->assign("UserMembers" ,$userlist);
$smarty->assign("UserMemberKeys",array_flip($userlist));
@@ -263,12 +398,12 @@ class printgeneric extends plugin
$smarty->assign("AdminMemberKeys",array_flip($adminlist));
$smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
-
return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
}
function remove_from_parent()
{
+ $this->dn= preg_replace('/ou=workstations,/', 'ou=printers,', $this->dn);
$ldap= $this->config->get_ldap_link();
$ldap->rmdir($this->dn);
show_ldap_error($ldap->get_error());
@@ -334,19 +469,25 @@ class printgeneric extends plugin
/* Save to LDAP */
function save()
{
+ if (!$this->is_account){
+ return;
+ }
+
+ if($this->PPDdialogToSave){
+ $this->PPDdialogToSave->save_ppd();
+ }
$dn= $this->dn;
plugin::save();
+ $ldap= $this->config->get_ldap_link();
if((in_array("gotoTerminal",$this->attrs['objectClass']))){
- $this->dn= preg_replace("/ou=terminal/","ou=printer",$this->dn);
+ $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
}
-
+
if((in_array("gotoWorkstation",$this->attrs['objectClass']))){
- $this->dn= preg_replace("/ou=workstation/","ou=printer",$this->dn);
+ $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
}
- $ldap= $this->config->get_ldap_link();
-
/* We are currently editing a Terminal, so we want to save a seperate printer which cn is the terminla cn
*/
if($this->is_terminal){
@@ -375,6 +516,16 @@ class printgeneric extends plugin
$this->attrs= $attrs;
}
+ if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
+ $method="https://";
+ }else{
+ $method="http://";
+ }
+
+ if(!is_array($this->attrs['gotoPrinterPPD'])) {
+ $this->attrs['gotoPrinterPPD'] = $this->attrs['gotoPrinterPPD'];
+ $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->attrs['gotoPrinterPPD']);
+ }
/* Append printer user
*/
@@ -441,8 +592,6 @@ class printgeneric extends plugin
}
return($a_return);
}
-
-
}