1 <?php
3 class printerPPDSelectionDialog extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage server basic objects";
7 var $cli_description = "Some longer text\nfor help";
8 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* attribute list for save action */
11 var $ignore_account = FALSE;
12 var $attributes = array("currentPos","currentSel");
13 var $objectclasses = array("whatever");
15 var $list =array();
16 var $header =array();
18 var $currentPos = "";
19 var $currentSel = -1;
20 var $selectedPPD = "";
22 function printerPPDSelectionDialog ($config, $dn= NULL,$list=false,$headers=false,$ppd=false)
23 {
24 plugin::plugin ($config, $dn);
25 $this->list = $list;
26 $this->header = $headers;
27 $this->depselect = $this->config->current['BASE'];
29 /* If there is already a ppd file selected, use this as preselected object in our ppds list
30 */
31 if(isset($ppd)){
32 $tmp2 = split("\n",$ppd['ppd']);
33 if(count($tmp2)==2){
34 $this->currentPos = $tmp2[0];
35 $this->currentSel = preg_replace("/^ -/","",$tmp2[1]);
36 }
37 }
39 /* Order the manufacturers index */
40 ksort($this->header);
41 }
43 function execute()
44 {
45 /* Fill templating stuff */
46 $smarty= get_smarty();
47 $display= "";
48 $s_action = "none";
50 /* Links used to open/select an entry */
51 $LINK_openDir = "<a href='?plug=".$_GET['plug']."&open=%s'>%s</a>";
52 $LINK_useThis = "<a href='?plug=".$_GET['plug']."&use=%s'>%s</a>";
54 /* Open manufacturer */
55 if(isset($_GET['open'])){
56 $this->currentPos=base64_decode($_GET['open']);
57 }
59 /* Select ppd */
60 if(isset($_GET['use'])){
61 $this->currentSel=base64_decode($_GET['use']);
62 }
64 /* if manufacturer is selected and a ppd file
65 * Set this selected file to our return value.
66 */
67 if(isset($this->list[$this->currentPos][$this->currentSel])){
68 $this->selectedPPD = $this->list[$this->currentPos][$this->currentSel];
69 }
71 /* "Back" resets our selection
72 */
73 foreach($_POST as $post => $val){
74 if(preg_match("/dep_back/",$post)){
75 $s_action = "back";
76 $this->currentPos = "";
77 $this->currentSel = -1;
78 }
79 }
81 /* The listhead is shown on top of the list.
82 * It represents a menu that contains basic option for this dialog/list
83 */
84 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
85 " <input type='image' align='middle' src='images/list_back.png' title='"._("Reset list")."' alt='"._("Up")."' name='dep_back'> ".
86 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
87 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Upload PPD")."' alt='"._("Upload PPD")."' name='upload'> ".
88 "</div>";
90 /* Create new list*/
91 $div = new divlist("PPD");
92 $div -> SetSummary(_("List with all available ppd files."));
93 $div -> SetEntriesPerPage(18);
95 /* If nothing is selected open manufacturers list */
96 if($this->currentPos==""){
97 $div -> SetHeader (array(
98 array("string"=>_("Name")),
99 array("string"=>_("Entries"),"attach"=>"style='border-right:none;width:100px;'")));
100 $options = "";
102 /* Append elements */
103 foreach($this->header as $header => $nums){
104 $field1 = array("string" => sprintf($LINK_openDir,base64_encode($header),$header),"attach"=>"style='border-right:none;height:26px;'");
105 $field2 = array("string" => $nums,"attach"=>"style='border-right:none;height:26px;'");
106 $div->AddEntry(array($field1,$field2));
107 }
109 /* Display all ppds for the given manufacturer */
110 }else{
111 $div -> SetHeader (array(
112 array("string"=>_("Name")." - ".$this->currentPos ,"attach"=>"style='border-right:none;'")));
114 /* Append elements */
115 foreach($this->list[$this->currentPos] as $pos => $ppd){
116 if($pos == $this->currentSel){
117 $field1 = array("string" => sprintf($LINK_useThis,base64_encode($pos),$ppd['name'])." - "._("selected"),"attach"=>"style='border-right:none;background:#99CCBB;height:25px;'");
118 }else{
119 $field1 = array("string" => sprintf($LINK_useThis,base64_encode($pos),$ppd['name']),"attach"=>"style='border-right:none;height:25px;'");
120 }
121 $div->AddEntry(array($field1));
122 }
123 }
125 /* print out template */
126 $smarty->assign("listhead",$listhead);
127 $smarty->assign("list",$div->DrawList());
128 $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__)));
129 return($display);
130 }
132 function check(){
133 $message=array();
134 if(empty($this->selectedPPD)){
135 $message[] = _("Please select a PPD or press cancel");
136 }
137 return $message;
138 }
140 /* Save to LDAP */
141 function save()
142 {
143 return $this->selectedPPD;
144 }
145 }
146 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
147 ?>