summaryrefslogtreecommitdiff
path: root/list.php
blob: 5f363597cd7e03a456b9248f75a97f31c0ce5c69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
/**
 * $Horde: kasync/list.php,v 1.12 2009-01-06 18:02:10 jan Exp $
 *
 * Copyright 2007-2009 The Horde Project (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 *
 * @author Bogomil Shopov <shopov@kolabsys.com>
 */

@define('KASYNC_BASE', dirname(__FILE__));
require_once KASYNC_BASE . '/lib/base.php';

if (!Auth::isAuthenticated()) {
    Horde::authenticationFailureRedirect();
}

global $shares;
$title = _("ActiveSync Management screen");

require KASYNC_TEMPLATES . '/common-header.inc';
require KASYNC_TEMPLATES . '/menu.inc';

//include zpush conf files
//try to include ALL possible configuration files
@include_once '/kolab/var/kolab/www/z-push/config.php';
@include_once '/etc/z-push/config.php';
@include_once '/usr/share/z-push/config.php';
@include_once '/var/www/z-push/config.php';


require_once 'Horde/Kolab/Storage.php';
require_once 'Horde/Kolab/Storage/Folder.php';
require_once 'Horde/Kolab/Storage/List.php';
require_once 'Horde/Kolab/Kolab_Zpush/lib/kolabActivesyncData.php';

/*read from her value of the KOLAB_LAXPIC
 -1 = allow the user to select (or if the constant doesn't exist) 
 0  = same as the annotations (no lax mode just jpeg)
 1  = force the lax mode for all 
*/
if(!defined('KOLAB_LAXPIC')){define('KOLAB_LAXPIC',-1);}

//handle POST

//define list object
$list = Kolab_List::singleton();

//define folder object
$folder = Kolab_Storage::getFolder('INBOX');


function SaveDeviceData()
{
	$folderd = Kolab_Storage::getFolder('INBOX');		
	//$devices[$_POST['serial']]['ALIAS'] = $_POST['alias'];
	//$devices[$_POST['serial']]['LAXPIC'] = $_POST['laxpic'];
	//$devices[$_POST['serial']]['MODE'] = $_POST['mode'];
	
	
	$old_device_settings = $folderd->getActiveSync();
	$old_device_settings['DEVICE'][$_POST['serial']]['ALIAS']=$_POST['alias'];
	$old_device_settings['DEVICE'][$_POST['serial']]['LAXPIC']=$_POST['laxpic'];
	$old_device_settings['DEVICE'][$_POST['serial']]['MODE']=$_POST['mode'];
	
	
	$resss['DEVICE']=$old_device_settings['DEVICE'];
	//$imap = Horde_Kolab_Session::singleton()->getImap();
	//$result = $imap->setAnnotation(
      //      KOLAB_ANNOT_ROOT . 'activesync',
        //    array('value.priv' => base64_encode(json_encode($resss))),
          //  'INBOX'
        //);
	$folderd->setActiveSyncDeviceData($resss, 'DEVICE');
	
	
}



//delete device
if(isset($_POST['deid']))
{
  $del_folders = $list->listFolders();
 		foreach($del_folders as $id => $folder_object)
	 {
	 	$dfolder = Kolab_Storage::getFolder($folder_object);
	 	$dfolder->deleteActiveSyncDevice($_POST['deid']);
	}
}

// end  delete device 

if(isset( $_POST['serial']))
{
	 
	 	//start folders
	   $ch_folders = $list->listFolders();
	   $imap = Horde_Kolab_Session::singleton()->getImap();
 		foreach($ch_folders as $id => $folder_objects)
		 {
	 	//$cfolder = Kolab_Storage::getFolder($folder_object);
	 		//get folder name
	 		$fname=rtrim(mb_convert_encoding($folder_objects,"UTF8", "UTF7-IMAP"));
			
			//get 'S' param
			$fols[$_POST['serial']]['S'] = $_POST[preg_replace('/( )/','_',$fname)];
			
			//get folder object
			$folder_set= Kolab_Storage::getFolder($folder_objects);
			
			
									
			//get all device setting on this folder
			$old_device_settingsf = $folder_set->getActiveSync();
			
			
			//echo "<pre>"; print_r($old_device_settings['FOLDER']); echo "</pre>";
		    $old_device_settingsf['FOLDER'][$_POST['serial']]['S']=$_POST[preg_replace('/( )/','_',$fname)];
			
			//echo "Begin ($fname)<hr><pre>";
			//print_r($old_device_settingsf);
			//echo "</pre></hr> end";
			$ress['FOLDER']=$old_device_settingsf['FOLDER'];
			//echo "<pre> $fname<br/><br/><br/>";
			//print_r($ress);
			//echo "</pre>";
			
			$folder_set->setActiveSyncDeviceData($ress, 'FOLDER');
			//if($folder_set->name=="INBOX"){print_r($folder_set->getActiveSync());}
			
			//$result = $imap->setAnnotation(
            //KOLAB_ANNOT_ROOT . 'activesync',
            //array('value.priv' => base64_encode(json_encode($ress))),
            //$folder_set->name
        //);
			
			//print_r($folder_set->getActiveSync());
			
			
			}
		 
		 SaveDeviceData();
 	
		 }

//end POST
//View part



//we need that for device listing abn visual tabs
$results = $folder->getActiveSync();




function ReturnDataArray($list,$type)
{
	global $shares;
	$mfold = $list->getByType($type);
	foreach ($mfold as $folder) 
		{
			$nname= mb_convert_encoding(trim($folder->name),"UTF8", "UTF7-IMAP");
	 		$rda[]= $nname;
			$shares[$nname]= $folder->getActiveSync();
			
		}
		
		return $rda;
	
}
//mail
$mails= ReturnDataArray($list,"");

//contact
$conts = ReturnDataArray($list,'contact');

//events
$cals= ReturnDataArray($list,'event');


//tasks
$taskss=ReturnDataArray($list,'task');


//main function for generation checkboxes:

function chb_manager($folder,$device,$folder_type){
	

	$result = PlaceShares($folder,$device);
    if ($result=="") $result="0";
	
	if ($result==1)
    {
     $checked="checked=checked";
	 $checked2=null;
    
     
    }elseif($result==2)
    {
    
    $checked2="checked=checked";
    $checked="checked=checked";
    }
    
    else
    {
     $cheked="";
     $checked2="";
    }
	
    $rnd=rand(5, 121);
	
	$ch = "<td><input type=checkbox name='".$folder."' value='1' $checked></td><td width='20'></td>";
    
   
	if(preg_match("/(event)/",$folder_type) OR preg_match("/(task)/",$folder_type))
    {
    	$ch = "<td><input type='checkbox' id='".$rnd."-1' name='".$folder."' value='1' $checked onclick='synced(this)'></td>
    	<td><input type='checkbox' id='".$rnd."-2' name='".$folder."' value='2' $checked2 onclick='synced(this)'></td>"; 
    }
    
    
    

 return $ch;
	
	
}



function PlaceShares($folder,$device)
{
	 global $shares;    
     //is default folder for syncing
     $def=is_default($folder);
 

	if($def==true)
	{
    //all default folders
	$r=1;
	}
	
      
	     if($shares[$folder]['FOLDER'][$device]['S'] == NULL)
	     {
	       $r=0;
	     }if((isset($shares[$folder]['FOLDER'][$device]['S'])) and $shares[$folder]['FOLDER'][$device]['S'] !=NULL)
	     {
	     	
	     	return $r=$shares[$folder]['FOLDER'][$device]['S'];
	     }
	     
	    
	     return $r;
		
}


//check default folders
function is_default($folder)
	{
	
	 if(preg_match("/(^INBOX)/", $folder))
	 {
	 
	  return true;
	 }else
	 {
	 	return false;
	 }
	}

$devices = isset($results['DEVICE']) ? $results['DEVICE'] : null;
//echo "<pre>";
//print_r($results);
//echo "</pre>";
if($_POST)
{
	
	require KASYNC_TEMPLATES . '/done.inc';
}
else
{
	require KASYNC_TEMPLATES . '/async.inc';
}
require $registry->get('templates', 'horde') . '/common-footer.inc';