ee53a31684b919f7081bdf005f15fc6549b16789
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 */
19 function CopyPasteHandler($config){
20 $this->config = $config;
21 $this->current= NULL;
22 }
25 /* Returns wether the current object can be pasted
26 */
27 function isCurrentObjectPastAble(){
29 /* Check if we got a valid object
30 */
31 if($this->current == NULL){
32 return(false);
33 }
34 return(true);
35 }
38 /* Clears all copy & paste informations
39 */
40 function Clear()
41 {
42 $this->copyCurrent = false;
43 $this->cutCurrent = false;
44 $this->dialogOpen = false;
45 $this->current = NULL;
46 }
49 /* return current obejct dn
50 */
51 function GetCurrentDn()
52 {
53 return($this->objectdn);
54 }
57 /* Add Object which should be copied
58 */
59 function Copy($obj,$emptyObj)
60 {
61 $this->copyCurrent = true;
62 $this->objectdn = $obj->dn;
63 $this->current = $emptyObj;
64 foreach($obj->by_object as $name => $obj){
65 foreach($obj->attributes as $attr){
66 $this->current->by_object[$name]->$attr = $obj->$attr;
67 }
68 foreach(array("is_account") as $attr){
69 if(isset($obj->$attr)){
70 $this->current->by_object[$name]->$attr = $obj->$attr;
71 }
72 }
73 }
74 if($this->isCurrentObjectPastAble()){
75 return(true);
76 }else{
77 $this->cutCurrent = $this->copyCurrent = false;
78 $this->obj = NULL;
79 }
80 return(false);
81 }
84 /* Add Object which should be cutted
85 */
86 function Cut($obj){
87 $this->cutCurrent = true;
88 $this->current = $obj;
89 $this->objectdn = $obj->dn;
90 if($this->isCurrentObjectPastAble()){
91 return(true);
92 }else{
93 $this->cutCurrent = $this->copyCurrent = false;
94 $this->obj = NULL;
95 }
96 return(false);
97 }
100 /* Returns true if current object
101 * is cutted. And awaits to be pasted anywhere
102 */
103 function isCurrentCutted(){
104 return($this->cutCurrent);
105 }
108 /* Returns true if current object
109 * was copied, and awaits to be pasted again
110 */
111 function isCurrentCopied(){
112 return($this->copyCurrent);
113 }
116 /* stillOpen
117 */
118 function stillOpen(){
119 if(isset($_POST['AbortCopyPaste'])){
120 $this->dialogOpen = false;
121 }
123 return($this->dialogOpen);
124 }
127 /* Displays a dialog which allows the user to fix all dependencies of this object.
128 Create unique names, ids, or what ever
129 */
130 function execute($displayMessageOnSuccess = true)
131 {
132 $this->dialogOpen = true;
134 /* Cut & paste
135 */
136 if($this->cutCurrent){
137 $this->current->save();
138 $this->dialogOpen =false;
139 $smarty = get_smarty();
140 $smarty->assign("Complete",true);
141 $this->lastdn= $this->current->dn;
142 $this->Clear();
143 return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
145 /* Copy & paste
146 */
147 }else{
148 if(isset($_POST['PerformCopyPaste'])){
149 $msgs = $this->check();
150 if(count ($msgs) ){
151 foreach( $msgs as $msg){
152 print_red($msg);
153 }
154 }else{
155 $this->current->save();
156 $this->dialogOpen =false;
157 $smarty = get_smarty();
158 $smarty->assign("Complete",true);
159 $this->lastdn = $this->current->dn;
160 $this->Clear();
161 if($displayMessageOnSuccess){
162 return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
163 }else{
164 return( false);
165 }
166 }
167 }
168 $smarty = get_smarty();
169 $smarty->assign("Complete",false);
170 $smarty->assign("AttributesToFix",$this->generateAttributesToFix());
171 $smarty->assign("objectDN" ,$this->objectdn);
172 $smarty->assign("message", sprintf(_("You are going to copy the entry '%s'."), $this->objectdn));
173 return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
174 }
175 }
177 /* Create dialog which asks unique attributes values ...
178 * calls tabs -> getCopyDialog()
179 * which calls tab -> getCopyDialog()
180 */
181 function generateAttributesToFix()
182 {
183 return($this->current->getCopyDialog());
184 }
187 /* Set a single attribute to specified value
188 * example : ("base", $newBase );
189 */
190 function SetVar($name,$value)
191 {
192 foreach($this-> current->by_object as $key => $obj){
193 if(isset($this->current->by_object[$key]->$name)){
194 $this->current->by_object[$key]->$name = $value;
195 }
196 }
197 }
200 /* Save new values posted by copy & paste dialog
201 */
202 function save_object()
203 {
204 /* Assign posted var to all tabs
205 */
206 $this->current->saveCopyDialog();
207 }
210 /* Returns possible errors returned from all including tabs ..
211 */
212 function check()
213 {
214 $ret = array();
215 foreach($this-> current->by_object as $obj){
216 if($obj->is_account){
217 $ret = array_merge($ret , $obj->check());
218 }
219 }
221 return($ret);
222 }
224 }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>