b10357b9d056ca6fc703002375cfde08642b1a76
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 $this->currentPos = $tmp2[0];
34 $this->currentSel = preg_replace("/^ -/","",$tmp2[1]);
35 }
37 /* Order the manufacturers index */
38 ksort($this->header);
39 }
41 function execute()
42 {
43 /* Fill templating stuff */
44 $smarty= get_smarty();
45 $display= "";
46 $s_action = "none";
48 /* Links used to open/select an entry */
49 $LINK_openDir = "<a href='?plug=".$_GET['plug']."&open=%s'>%s</a>";
50 $LINK_useThis = "<a href='?plug=".$_GET['plug']."&use=%s'>%s</a>";
52 /* Open manufacturer */
53 if(isset($_GET['open'])){
54 $this->currentPos=base64_decode($_GET['open']);
55 }
57 /* Select ppd */
58 if(isset($_GET['use'])){
59 $this->currentSel=base64_decode($_GET['use']);
60 }
62 /* if manufacturer is selected and a ppd file
63 * Set this selected file to our return value.
64 */
65 if(isset($this->list[$this->currentPos][$this->currentSel])){
66 $this->selectedPPD = $this->list[$this->currentPos][$this->currentSel];
67 }
69 /* "Back" resets our selection
70 */
71 foreach($_POST as $post => $val){
72 if(preg_match("/dep_back/",$post)){
73 $s_action = "back";
74 $this->currentPos = "";
75 $this->currentSel = -1;
76 }
77 }
79 /* The listhead is shown on top of the list.
80 * It represents a menu that contains basic option for this dialog/list
81 */
82 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
83 " <input type='image' align='middle' src='images/list_back.png' title='"._("Reset list")."' alt='"._("Up")."' name='dep_back'> ".
84 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
85 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Upload PPD")."' alt='"._("Uppload PPD")."' name='upload'> ".
86 "</div>";
88 /* Create new list*/
89 $div = new divlist("PPD");
90 $div -> SetSummary(_("List with all available ppd files."));
91 $div -> SetEntriesPerPage(18);
93 /* If nothing is selected open manufacturers list */
94 if($this->currentPos==""){
95 $div -> SetHeader (array(
96 array("string"=>_("Name")),
97 array("string"=>_("Entries"),"attach"=>"style='border-right:none;width:100px;'")));
98 $options = "";
100 /* Append elements */
101 foreach($this->header as $header => $nums){
102 $field1 = array("string" => sprintf($LINK_openDir,base64_encode($header),$header),"attach"=>"style='border-right:none;height:26px;'");
103 $field2 = array("string" => $nums,"attach"=>"style='border-right:none;height:26px;'");
104 $div->AddEntry(array($field1,$field2));
105 }
107 /* Display all ppds for the given manufacturer */
108 }else{
109 $div -> SetHeader (array(
110 array("string"=>_("Name")." - ".$this->currentPos ,"attach"=>"style='border-right:none;'")));
112 /* Append elements */
113 foreach($this->list[$this->currentPos] as $pos => $ppd){
114 if($pos == $this->currentSel){
115 $field1 = array("string" => sprintf($LINK_useThis,base64_encode($pos),$ppd['name'])." - "._("selected"),"attach"=>"style='border-right:none;background:#99CCBB;height:25px;'");
116 }else{
117 $field1 = array("string" => sprintf($LINK_useThis,base64_encode($pos),$ppd['name']),"attach"=>"style='border-right:none;height:25px;'");
118 }
119 $div->AddEntry(array($field1));
120 }
121 }
123 /* print out template */
124 $smarty->assign("listhead",$listhead);
125 $smarty->assign("list",$div->DrawList());
126 $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__)));
127 return($display);
128 }
130 function check(){
131 $message=array();
132 if(empty($this->selectedPPD)){
133 $message[] = _("Please select a PPD or press cancel");
134 }
135 return $message;
136 }
138 /* Save to LDAP */
139 function save()
140 {
141 return $this->selectedPPD;
142 }
143 }
144 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
145 ?>