334bd988dc6e3c55e51552274d5b63439a1b3155
1 <?php
3 class CopyPasteHandler {
5 var $config;
6 var $current;
8 var $copyCurrent = false;
9 var $cutCurrent = false;
10 var $dialogOpen = false;
11 var $objectdn = false;
13 var $lastdn = "";
15 var $was_successfull = false;
17 /* Create CP handler */
18 function CopyPasteHandler($config){
19 $this->config = $config;
20 $this->current= NULL;
21 }
24 /* Returns wether the current object can be pasted */
25 function isCurrentObjectPastAble(){
27 /* Check if we got a valid object */
28 if($this->current == NULL){
29 return(false);
30 }
31 return(true);
32 }
35 /* Clears all copy & paste informations */
36 function Clear()
37 {
38 $this->copyCurrent = false;
39 $this->cutCurrent = false;
40 $this->dialogOpen = false;
41 $this->current = NULL;
42 }
45 /* return current obejct dn */
46 function GetCurrentDn()
47 {
48 return($this->objectdn);
49 }
52 /* Add Object which should be copied */
53 function Copy($obj,$emptyObj)
54 {
55 $this->copyCurrent = true;
56 $this->objectdn = $obj->dn;
57 $this->current = $emptyObj;
58 foreach($obj->by_object as $name => $obj){
60 /* Prepare every single class, to be copied */
61 $this->current->by_object[$name]->PrepareForCopyPaste($obj);
63 /* handle some special vars */
64 foreach(array("is_account") as $attr){
65 if(isset($obj->$attr)){
66 $this->current->by_object[$name]->$attr = $obj->$attr;
67 }
68 }
69 }
70 if($this->isCurrentObjectPastAble()){
71 return(true);
72 }else{
73 $this->cutCurrent = $this->copyCurrent = false;
74 $this->obj = NULL;
75 }
76 return(false);
77 }
80 /* Add Object which should be cutted */
81 function Cut($obj){
82 $this->cutCurrent = true;
83 $this->current = $obj;
84 $this->objectdn = $obj->dn;
85 if($this->isCurrentObjectPastAble()){
86 return(true);
87 }else{
88 $this->cutCurrent = $this->copyCurrent = false;
89 $this->obj = NULL;
90 }
91 return(false);
92 }
95 /* Returns true if current object
96 * is cutted. And awaits to be pasted anywhere */
97 function isCurrentCutted(){
98 return($this->cutCurrent);
99 }
102 /* Returns true if current object
103 * was copied, and awaits to be pasted again */
104 function isCurrentCopied(){
105 return($this->copyCurrent);
106 }
109 /* Returns true if the copy$paste dialog is still open */
110 function stillOpen(){
111 if(isset($_POST['AbortCopyPaste'])){
112 $this->dialogOpen = false;
113 }
114 return($this->dialogOpen);
115 }
118 /* Displays a dialog which allows the user to fix all dependencies of this object.
119 Create unique names, ids, or what ever */
120 function execute()
121 {
122 $this->dialogOpen = true;
124 /* Cut & paste
125 */
126 if($this->cutCurrent){
128 if(isset($_POST['PerformCopyPaste'])){
129 $msgs = $this->check();
130 if(count ($msgs) ){
131 foreach( $msgs as $msg){
132 print_red($msg);
133 }
134 }else{
135 $this->current->save();
136 $this->dialogOpen =false;
137 $this->Clear();
138 }
139 }
140 if($this->current){
141 $smarty = get_smarty();
142 $smarty->assign("type","cut");
143 $smarty->assign("Complete",false);
144 $smarty->assign("AttributesToFix"," ");
145 $smarty->assign("SubDialog",$this->current->SubDialog);
146 $smarty->assign("objectDN" ,$this->objectdn);
147 $smarty->assign("message", sprintf(_("You are going to paste the cutted entry '%s'."), $this->objectdn));
148 return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
149 }
151 /* Copy & paste
152 */
153 }else{
154 if(isset($_POST['PerformCopyPaste'])){
155 $msgs = $this->check();
156 if(count ($msgs) ){
157 foreach( $msgs as $msg){
158 print_red($msg);
159 }
160 }else{
161 $this->current->save();
162 $this->lastdn = $this->current->dn;
163 $this->dialogOpen =false;
164 $this->Clear();
165 }
166 }
167 if($this->current){
168 $smarty = get_smarty();
169 $smarty->assign("type","copy");
170 $smarty->assign("Complete",false);
171 $smarty->assign("AttributesToFix",$this->generateAttributesToFix());
172 $smarty->assign("SubDialog",$this->current->SubDialog);
173 $smarty->assign("objectDN" ,$this->objectdn);
174 $smarty->assign("message", sprintf(_("You are going to paste the copied entry '%s'."), $this->objectdn));
175 return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
176 }
177 }
178 }
180 /* Create dialog which asks unique attributes/values ...
181 * call tabs -> getCopyDialog()
182 * which calls tab -> getCopyDialog() */
183 function generateAttributesToFix()
184 {
185 if($this->current){
186 return($this->current->getCopyDialog());
187 }
188 }
191 /* Set a single attribute to specified value
192 * example : ("base", $newBase ); */
193 function SetVar($name,$value)
194 {
195 foreach($this-> current->by_object as $key => $obj){
196 if(isset($this->current->by_object[$key]->$name)){
197 $this->current->by_object[$key]->$name = $value;
198 }
199 }
200 }
203 /* Save new values posted by copy & paste dialog */
204 function save_object()
205 {
206 /* Assign posted var to all tabs
207 */
208 if($this->current){
209 $this->current->saveCopyDialog();
210 }
211 }
214 /* Returns errors from including tabs. */
215 function check()
216 {
217 $ret = array();
218 foreach($this-> current->by_object as $obj){
219 if($obj->is_account){
220 $ret = array_merge($ret , $obj->check());
221 }
222 }
223 return($ret);
224 }
227 /* returns the paste icon for headpages */
228 function generatePasteIcon()
229 {
230 $Copy_Paste= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
231 if($this->isCurrentObjectPastAble()){
232 if($this->isCurrentCutted()){
233 $img= "images/cutpaste.png";
234 }else{
235 $img= "images/copypaste.png";
236 }
237 $Copy_Paste.= "<input type='image' name='editPaste' class='center'
238 src='".$img."' alt='"._("Paste")."' title='".$this->GetCurrentDn()."'> ";
239 }else{
240 $Copy_Paste.= "<img class='center' src='images/cant_editpaste.png' alt=\""._("Can't paste")."\"> ";
241 }
243 return ($Copy_Paste);
244 }
246 }
247 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
248 ?>