Code Duplication    Length = 46-47 lines in 3 locations

API/TeamSpeak3.php 3 locations

@@ 274-320 (lines=47) @@
271
  * @param		array	$permissions	permissions
272
  * @return     boolean success
273
  */
274
	function channelAddPerm($cid, $permissions) {
275
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
276
		
277
		if(count($permissions) > 0) {
278
			//Permissions given
279
			
280
			//Errorcollector
281
			$errors = array();
282
			
283
			//Split Permissions to prevent query from overload
284
			$permissions = array_chunk($permissions, 50, true);
285
			
286
			//Action for each splitted part of permission
287
			foreach($permissions as $permission_part)
288
			{
289
				//Create command_string for each command that we could use implode later
290
				$command_string = array();
291
				
292
				foreach($permission_part as $key => $value)
293
				{
294
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
295
				}
296
				
297
				$result = $this->getData('boolean', 'channeladdperm cid='.$cid.' '.implode('|', $command_string));
298
				
299
				if(!$result['success'])
300
				{
301
					foreach($result['errors'] as $error)
302
					{
303
						$errors[] = $error;
304
					}
305
				}
306
			}
307
			
308
			if(count($errors) == 0)
309
			{
310
				return $this->generateOutput(true, array(), true);
311
			}else{
312
				return $this->generateOutput(false, $errors, false);
313
			}
314
			
315
		}else{
316
			// No permissions given
317
			$this->addDebugLog('no permissions given');
318
			return $this->generateOutput(false, array('Error: no permissions given'), false);
319
		}
320
	}
321
322
/**
323
  * channelClientAddPerm
@@ 341-387 (lines=47) @@
338
  * @param		array		$permissions	permissions
339
  * @return     boolean success
340
  */
341
	function channelClientAddPerm($cid, $cldbid, $permissions) {
342
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
343
		
344
		if(count($permissions) > 0) {
345
			//Permissions given
346
				
347
			//Errorcollector
348
			$errors = array();
349
				
350
			//Split Permissions to prevent query from overload
351
			$permissions = array_chunk($permissions, 50, true);
352
				
353
			//Action for each splitted part of permission
354
			foreach($permissions as $permission_part)
355
			{
356
				//Create command_string for each command that we could use implode later
357
				$command_string = array();
358
		
359
				foreach($permission_part as $key => $value)
360
				{
361
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
362
				}
363
		
364
				$result = $this->getData('boolean', 'channelclientaddperm cid='.$cid.' cldbid='.$cldbid.' '.implode('|', $command_string));
365
		
366
				if(!$result['success'])
367
				{
368
					foreach($result['errors'] as $error)
369
					{
370
						$errors[] = $error;
371
					}
372
				}
373
			}
374
				
375
			if(count($errors) == 0)
376
			{
377
				return $this->generateOutput(true, array(), true);
378
			}else{
379
				return $this->generateOutput(false, $errors, false);
380
			}
381
				
382
		}else{
383
			// No permissions given
384
			$this->addDebugLog('no permissions given');
385
			return $this->generateOutput(false, array('Error: no permissions given'), false);
386
		}
387
	}
388
389
/**
390
  * channelClientDelPerm
@@ 644-689 (lines=46) @@
641
  * @param		array		$permissions	permissions
642
  * @return     boolean success
643
  */
644
	function channelGroupAddPerm($cgid, $permissions) {
645
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
646
		
647
		if(count($permissions) > 0) {
648
			//Permissions given
649
		
650
			//Errorcollector
651
			$errors = array();
652
		
653
			//Split Permissions to prevent query from overload
654
			$permissions = array_chunk($permissions, 50, true);
655
		
656
			//Action for each splitted part of permission
657
			foreach($permissions as $permission_part)
658
			{
659
				//Create command_string for each command that we could use implode later
660
				$command_string = array();
661
		
662
				foreach($permission_part as $key => $value)
663
				{
664
					$command_string[] = (is_numeric($key) ? "permid=" : "permsid=").$this->escapeText($key).' permvalue='.$value;
665
				}
666
		
667
				$result = $this->getData('boolean', 'channelgroupaddperm cgid='.$cgid.' '.implode('|', $command_string));
668
		
669
				if(!$result['success'])
670
				{
671
					foreach($result['errors'] as $error)
672
					{
673
						$errors[] = $error;
674
					}
675
				}
676
			}
677
		
678
			if(count($errors) == 0) {
679
				return $this->generateOutput(true, array(), true);
680
			}else{
681
				return $this->generateOutput(false, $errors, false);
682
			}
683
		
684
		}else{
685
			// No permissions given
686
			$this->addDebugLog('no permissions given');
687
			return $this->generateOutput(false, array('Error: no permissions given'), false);
688
		}
689
	}
690
691
/**
692
  * channelGroupClientList