1<?php
2/*
3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
4 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
5 *
6 * == BEGIN LICENSE ==
7 *
8 * Licensed under the terms of any of the following licenses at your
9 * choice:
10 *
11 *  - GNU General Public License Version 2 or later (the "GPL")
12 *    http://www.gnu.org/licenses/gpl.html
13 *
14 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
15 *    http://www.gnu.org/licenses/lgpl.html
16 *
17 *  - Mozilla Public License Version 1.1 or later (the "MPL")
18 *    http://www.mozilla.org/MPL/MPL-1.1.html
19 *
20 * == END LICENSE ==
21 *
22 * This is the File Manager Connector for PHP.
23 */
24
25
26
27
28require_once 'check_acl.php';
29
30
31global $dwfck_conf;
32global $_FolderClass;
33
34function GetDwfckNs()
35{
36	echo $_SESSION['dwfck_ns'];
37}
38
39
40 function has_permission($folder, $resourceType, $isFolder=true) {
41   global $_FolderClass;
42   global $Dwfck_conf_values;
43        $folder = str_replace('//','/',$folder);
44
45        $sFolderPath = GetResourceTypeDirectory( $resourceType, 'GetFoldersAndFiles');
46
47       $ns_tmp = str_replace('/',':',$folder);
48       $ns_tmp=trim($ns_tmp,':');
49
50       if(preg_match('/%[a-zA-a0-9]/', $ns_tmp) && $Dwfck_conf_values['fnencode'] == 'safe') {
51          $test = dwiki_decodeFN($ns_tmp);
52       }
53       else {
54
55       $test = urldecode($ns_tmp);
56       }
57
58       if($isFolder) {
59           $test .=  ':*' ;
60       }
61       else {
62           $test=preg_replace('/\.txt$/',"",$test);
63       }
64
65       $AUTH =  auth_aclcheck($test, $_SESSION['dwfck_client'] , $_SESSION['dwfck_grps'], 1);
66
67       $_FolderClass = $AUTH;
68       if(!$isFolder) return($AUTH > 0);
69       return ($AUTH >1);
70 }
71
72
73function GetFolders( $resourceType, $currentFolder )
74{
75
76   global $_FolderClass;
77   global $Config;
78
79    $currentFolder=encode_dir($currentFolder);
80   $isInternalLink = isset($_GET['DWFCK_Browser']) && $_GET['DWFCK_Browser'] == 'local'?  true : false;
81
82	// Map the virtual path to the local server path.
83	$sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'GetFolders' ) ;
84
85    if($Config['osWindows']) {
86        $sServerDir = normalizeWIN($sServerDir);
87    }
88
89	// Array that will hold the folders names.
90	$aFolders	= array() ;
91
92	$oCurrentFolder = @opendir( $sServerDir ) ;
93
94	if ($oCurrentFolder !== false)
95	{
96		while ( $sFile = readdir( $oCurrentFolder ) )
97		{
98			if ( $sFile != '.' && $sFile != '..' && is_dir( $sServerDir . $sFile ) ) {
99
100
101                if(has_permission(dwiki_encodeFN($currentFolder) .'/' . $sFile,  $resourceType) || has_open_access() ) {
102                        if($isInternalLink && $_FolderClass < 255) {
103                            $class = 'r';
104                       }
105                       else $class = ($_FolderClass < 8) ? 'r' : 'u';
106                       if($_FolderClass) {
107 			  	           $aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) .
108                            '" class="'. $class .'" />' ;
109                       }
110
111               }
112			}
113		}
114
115
116		closedir( $oCurrentFolder ) ;
117	}
118
119	// Open the "Folders" node.
120	echo "<Folders>" ;
121
122	natcasesort( $aFolders ) ;
123
124	foreach ( $aFolders as $sFolder )
125
126		echo $sFolder ;
127
128
129	// Close the "Folders" node.
130	echo "</Folders>" ;
131
132}
133
134/**
135    seeks to determine whether user has rights to create folder
136    if the folder does not exist when file browser is opened
137    and the editor has not created it
138    This situation occurs when the file browser opened from the
139    root directory, where the file being written to is in a
140    new subdirectory that has been created for the file:
141           parent_dir:new_dir:new_file
142   Dokuwiki creates new_dir in data/pages but not in data/media.
143   Dokuwiki creates data/media/new_dir when the user opens
144   the media manager. Similarly, this directory has to be created when
145   FCKeditor's file browser is opened
146
147*/
148function has_open_access() {
149
150    $open_access = false;
151    if(isset($_REQUEST['TopLevel'])) {
152    //   list($top_level,$auth) = explode(';;',$_REQUEST['TopLevel']);
153     //  if($auth == 255 && $top_level =='/') $open_access = true;
154    }
155    $isadmin = isset($_SESSION['dwfck_conf']['isadmin']) ? $_SESSION['dwfck_conf']['isadmin'] : false;
156    $acl = isset($_SESSION['dwfck_acl']) ? $_SESSION['dwfck_acl'] : 1;
157    $openbrowser = (isset($_SESSION['dwfck_openfb']) && $_SESSION['dwfck_openfb'] == 'y') ? true : false;
158    if($open_access || $isadmin || $acl == 255 || ($openbrowser && $acl >= 8)) {
159         return true;
160    }
161
162    return false;
163}
164
165
166
167function GetFoldersAndFiles( $resourceType, $currentFolder )
168{
169	if (!isset($_GET)) {
170		global $_GET;
171	}
172     global $Config;
173
174
175   $isInternalLink = isset($_GET['DWFCK_Browser']) && $_GET['DWFCK_Browser'] == 'local'?  true : false;
176   global $_FolderClass;
177   global $Config;
178   $currentFolder=encode_dir($currentFolder);
179
180   $sess_id = session_id();
181   if(!isset($sess_id) || $sess_id != $_COOKIE['FCK_NmSp_acl']) {
182       session_id($_COOKIE['FCK_NmSp_acl']);
183       session_start();
184   }
185    $acl_del = isset($_SESSION['dwfck_del']) ? $_SESSION['dwfck_del'] : 0;
186	// Map the virtual path to the local server path.
187	$sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'GetFoldersAndFiles' ) ;
188    if($Config['osWindows']) {
189        $sServerDir = normalizeWIN($sServerDir);
190    }
191
192    mkdir_rek($sServerDir);
193	// Arrays that will hold the folders and files names.
194	$aFolders	= array() ;
195	$aFiles		= array() ;
196
197    $sFile = '__AAAAAAAA__.AAA';
198    $temp_folder = $currentFolder;
199    $temp_folder = dwiki_encodeFN(trim($temp_folder,'/'));
200    has_permission($temp_folder, $resourceType);
201    if($isInternalLink && $_FolderClass < 16) {
202         $sfclass = 'r';
203    }
204    else {
205         if($acl_del)  {
206            $sfclass = $_FolderClass >= 16 ? 'u' : 'r';
207         }
208         else $sfclass = ($_FolderClass >= 8  || has_open_access()) ? 'u' : 'r';
209    }
210    if(!$_FolderClass) return;
211    $aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) .
212                            '" class="'. $sfclass .'" />' ;
213
214    $sErrorNumber=0;
215
216
217     $sFolderPath = GetResourceTypeDirectory( $resourceType, 'GetFoldersAndFiles');
218
219     $absolute_path = $Config['UserFilesAbsolutePath'];
220
221
222
223
224	$oCurrentFolder = @opendir( $sServerDir ) ;
225
226	if ($oCurrentFolder !== false)
227	{
228		while ( $sFile = readdir( $oCurrentFolder ) )
229		{
230
231			if ( $sFile != '.' && $sFile != '..' )
232			{
233				if ( is_dir( $sServerDir . $sFile ) ) {
234
235                    if(has_permission(dwiki_encodeFN($currentFolder)  .$sFile,  $resourceType) || has_open_access()) {
236                        if($isInternalLink && $_FolderClass < 255) {
237                            $class = 'r';
238                       }
239                       else {
240                              $class = ($_FolderClass < 8) ? 'r' : 'u';
241                       }
242                       if($_FolderClass){
243				  	       $aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) .
244                              '" class="'. $class .'" />' ;
245                       }
246
247                    }
248
249				}
250				else
251				{
252					$iFileSize = @filesize( $sServerDir . $sFile ) ;
253
254					if ( !$iFileSize ) {
255						$iFileSize = 0 ;
256					}
257					if ( $iFileSize > 0 )
258					{
259						$iFileSize = round( $iFileSize / 1024 ) ;
260						if ( $iFileSize < 1 )
261							$iFileSize = 1 ;
262					}
263                    if($isInternalLink) {
264                        if(!preg_match('/\.txt$/', $sFile)) continue;
265                        if(has_permission(dwiki_encodeFN($currentFolder)  .$sFile,  $resourceType, false)) {
266       				   	   $aFiles[] = '<File name="' . ConvertToXmlAttribute( $sFile ) . '" size="' . $iFileSize . '" />' ;
267                        }
268                    }
269                    else {
270                       if($resourceType == 'Image') {
271                            list($width, $height, $type, $attr) = getimagesize($sServerDir . $sFile);
272                                if(isset($width) && isset($height)) {
273                                  $iFileSize .= ";;$width;;$height";
274                                }
275
276                            }
277
278
279                          $aFiles[] = '<File name="' . ConvertToXmlAttribute( $sFile ) . '" size="' . $iFileSize . '" />' ;
280                    }
281
282				}
283			}
284		}
285		closedir( $oCurrentFolder ) ;
286	}
287
288
289
290	// Send the folders
291	natcasesort( $aFolders ) ;
292	echo '<Folders>' ;
293
294	foreach ( $aFolders as $sFolder ) {
295
296		echo $sFolder;
297	}
298
299	echo '</Folders>' ;
300
301	// Send the files
302	natcasesort( $aFiles ) ;
303	echo '<Files>' ;
304
305	foreach ( $aFiles as $sFiles )
306		echo $sFiles ;
307
308	echo '</Files>' ;
309
310
311
312}
313
314function CreateFolder( $resourceType, $currentFolder )
315{
316    global $_FolderClass;
317    global $Config;
318	if (!isset($_GET)) {
319		global $_GET;
320	}
321	$sErrorNumber	= '0' ;
322	$sErrorMsg		= '' ;
323    if(!has_permission($currentFolder, $resourceType) || $_FolderClass < 8 ) {
324         if(!has_open_access()) {
325            $sErrorNumber = 103;
326      	    echo '<Error number="' . $sErrorNumber . '" />' ;
327            return;
328         }
329    }
330
331
332	if ( isset( $_GET['NewFolderName'] ) )
333	{
334       $sess_id = session_id();
335       if(!isset($sess_id) || $sess_id != $_COOKIE['FCK_NmSp_acl']) {
336           session_id($_COOKIE['FCK_NmSp_acl']);
337           session_start();
338       }
339
340        global $Dwfck_conf_values;
341        global $dwfck_conf;
342        $dwfck_conf = $_SESSION['dwfck_conf'];
343        if(empty($dwfck_conf)) {
344            $dwfck_conf['deaccent'] = isset($Dwfck_conf_values['deaccent'])? $Dwfck_conf_values['deaccent'] : 1;
345            $dwfck_conf['useslash'] = isset($Dwfck_conf_values['useslash']) ? $Dwfck_conf_values['useslash'] : 0;
346            $dwfck_conf['sepchar'] = isset($Dwfck_conf_values['sepchar']) ? $Dwfck_conf_values['sepchar'] : '_';
347        }
348
349		$sNewFolderName = $_GET['NewFolderName'] ;
350        $sNewFolderName = str_replace(' ', $dwfck_conf['sepchar'], $sNewFolderName);
351        $sNewFolderName=Dwfck_sanitize( $sNewFolderName ) ;
352
353		if ( strpos( $sNewFolderName, '..' ) !== FALSE )
354			$sErrorNumber = '102' ;		// Invalid folder name.
355		else
356		{
357			// Map the virtual path to the local server path of the current folder.
358			$sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'CreateFolder' ) ;
359
360           if($Dwfck_conf_values['fnencode'] == 'url' || ($Config['osWindows'] && !isset($Dwfck_conf_values['fnencode']))) {
361                  $sServerDir=encode_dir($sServerDir);
362           }
363            if($Config['osWindows']) {
364                $sServerDir = normalizeWIN($sServerDir);
365            }
366
367			if ( is_writable( $sServerDir ) )
368			{
369				$sServerDir .= $sNewFolderName ;
370
371				$sErrorMsg = CreateServerFolder( $sServerDir ) ;
372
373				switch ( $sErrorMsg )
374				{
375					case '' :
376						$sErrorNumber = '0' ;
377						break ;
378					case 'Invalid argument' :
379					case 'No such file or directory' :
380						$sErrorNumber = '102' ;		// Path too long.
381						break ;
382					default :
383						$sErrorNumber = '110' ;
384						break ;
385				}
386			}
387			else
388				$sErrorNumber = '103' ;
389		}
390	}
391	else
392		$sErrorNumber = '102' ;
393
394	// Create the "Error" node.
395	echo '<Error number="' . $sErrorNumber . '" />' ;
396}
397
398function Dwfck_sanitize($sFileName, $media=false) {
399  global $Dwfck_conf_values;
400
401        if($Dwfck_conf_values['fnencode'] == 'safe') {
402            if(!$media) {
403              return dwiki_encodeFN($sFileName);
404            }
405           return cleanID($sFileName,false,$media);
406        }
407        $sFileName = cleanID(dwiki_decodeFN($sFileName),false,$media);
408        return dwiki_encodeFN($sFileName);
409}
410
411
412function normalizeWIN($path) {
413  if(!$path) return "";
414  global $winChars,  $winSearch;
415  if(!isset($winSearch)) {
416      $winChars = array('/',':','(',')','{','}','{','}',' ', '\\',
417     ']','[', '$',  '+',  '@',  '!',  '#',  '%',  '*', '?');
418      $winSearch = array_map('rawurlencode', $winChars);
419  }
420
421   $path = str_replace($winSearch,$winChars,$path);
422   $path = str_replace('/','\\',$path);
423   $path = preg_replace('#\\\\{2,}#','\\',$path);
424   $path = str_replace('.\\','\\',$path);
425
426   return str_replace('+',' ', $path);
427
428
429}
430
431function UnlinkFile($resourceType, $currentFolder, $sCommand, $filename ) {
432global $Config;
433  global $Dwfck_conf_values;
434  $move = false;
435
436    $sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'GetFoldersAndFiles' ) ;
437
438    if(preg_match('/^(.*?)\/(.*?)$/',$filename,$matches)) {
439      $move = true;
440      $sMoveDir = $sServerDir;
441      $sMoveDir .= dwiki_encodeFN($matches[1]);
442
443      $sMoveDir = rtrim($sMoveDir, '/');
444      $filename = $matches[2];
445      mkdir_rek($sMoveDir);
446
447
448      if(preg_match('/secure$/', $sMoveDir)){
449          if(!file_exists($sMoveDir . '/' . '.htaccess')) {
450            copy( 'htaccess' , $sMoveDir . '/' . '.htaccess') ;
451          }
452      }
453      $moveFile = $sMoveDir . '/' . dwiki_encodeFN($filename );
454
455    }
456    else {
457        if($Dwfck_conf_values['fnencode'] == 'url' || ($Config['osWindows'] && !isset($Dwfck_conf_values['fnencode']))) {
458              $sServerDir=encode_dir($sServerDir);
459        }
460    }
461
462    $unlinkFile =    $sServerDir . dwiki_encodeFN($filename );
463
464    if($Config['osWindows']) {
465       $unlinkFile = normalizeWIN($unlinkFile);
466    }
467
468    if($move) {
469      if($Config['osWindows']) {
470         $moveFile = normalizeWIN($moveFile);
471       }
472
473       if(rename($unlinkFile, $moveFile)) {
474         return GetFoldersAndFiles( $resourceType, $currentFolder );
475       }
476       else {
477         $sErrorNumber = '205';
478         echo '<Error number="' . $sErrorNumber . '" />' ;
479         return;
480       }
481    }
482
483    if(file_exists($unlinkFile) && unlink($unlinkFile)) {
484          return GetFoldersAndFiles( $resourceType, $currentFolder );
485    }
486    else {
487        $sErrorNumber = '204';
488        echo '<Error number="' . $sErrorNumber . '" />' ;
489    }
490
491}
492
493function encode_dir($path) {
494
495   if(preg_match('/%25/',$path)) {
496     $path =  urldecode($path);
497     while(preg_match('/%25/',$path)) {
498       $path =  urldecode($path);
499     }
500
501     return $path;
502
503   }
504
505   if(preg_match('/%[A-F]\d/i',$path) || preg_match('/%\d[A-F]/i',$path)) {
506     return $path;
507   }
508
509
510   $dirs = explode('/',$path);
511
512   $new_path = "";
513   foreach($dirs as $dir) {
514     $new_path .= dwiki_encodeFN($dir). '/';
515   }
516
517    $new_path = rtrim($new_path,'/');
518    $new_path .= '/';
519
520    return $new_path;
521}
522
523function FileUpload( $resourceType, $currentFolder, $sCommand )
524{
525    global $dwfck_conf;
526
527	if (!isset($_FILES)) {
528		global $_FILES;
529	}
530	$sErrorNumber = '0' ;
531	$sFileName = '' ;
532
533    $sess_id = session_id();
534    if(!isset($sess_id) || $sess_id != $_COOKIE['FCK_NmSp_acl']) {
535       session_id($_COOKIE['FCK_NmSp_acl']);
536       session_start();
537   }
538
539    global $Dwfck_conf_values;
540    $dwfck_conf = $_SESSION['dwfck_conf'];
541    if(empty($dwfck_conf)) {
542        $dwfck_conf['deaccent'] = isset($Dwfck_conf_values['deaccent'])? $Dwfck_conf_values['deaccent'] : 1;
543        $dwfck_conf['useslash'] = isset($Dwfck_conf_values['useslash']) ? $Dwfck_conf_values['useslash'] : 0;
544        $dwfck_conf['sepchar'] = isset($Dwfck_conf_values['sepchar']) ? $Dwfck_conf_values['sepchar'] : '_';
545    }
546
547    $auth = 0;
548    if(isset($_REQUEST['TopLevel'])) {
549       list($top_level,$auth) = explode(';;',$_REQUEST['TopLevel']);
550    }
551
552
553
554  $safe = false;
555  global $Dwfck_conf_values;
556  if($Dwfck_conf_values['fnencode'] == 'safe') {
557      if(preg_match('/%[a-z]+[0-9]/',$currentFolder) || preg_match('/%[0-9][a-z]/',$currentFolderp)) {
558          $safe = true;
559      }
560  }
561  $ns_tmp = dwiki_decodeFN(trim($currentFolder, '/'));
562
563  $ns_tmp = str_replace('/', ':', $ns_tmp);
564  $test = $ns_tmp . ':*' ;
565
566  if(!$safe) {
567    $test = urldecode($test);
568
569    while(preg_match('/%25/',$test)){
570          $test =  urldecode($test);
571    }
572    $test = urldecode($test);
573  }
574
575   $isadmin = isset($_SESSION['dwfck_conf']['isadmin']) ? $_SESSION['dwfck_conf']['isadmin'] : false;
576   if(!$isadmin) {
577       $AUTH = auth_aclcheck($test, $_SESSION['dwfck_client'] , $_SESSION['dwfck_grps'],1);
578
579        if($AUTH < 8) {
580            $msg="";
581        	$sFileUrl = CombinePaths( GetResourceTypePath( $resourceType, $sCommand ) , $currentFolder ) ;
582    	    $sFileUrl = CombinePaths( $sFileUrl, $_FILES['NewFile']['name']);
583            SendUploadResults( '203', $sFileUrl, $_FILES['NewFile']['name'],  $msg ) ;
584            return;
585
586         }
587   }
588    if(!$safe) {
589        $currentFolder = encode_dir($currentFolder);
590    }
591	if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
592	{
593		global $Config ;
594
595        $upload_err = $_FILES['NewFile']['error'];
596        if($upload_err ) {
597            send_ckg_UploadError($upload_err,$sFileUrl, $_FILES['NewFile']['name']);
598            exit;
599        }
600		$oFile = $_FILES['NewFile'] ;
601
602
603		// Map the virtual path to the local server path.
604		$sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ;
605
606		// Get the uploaded file name.
607		$sFileName = dwiki_encodeFN($oFile['name']) ;
608        $sOriginalFileName = dwiki_encodeFN($sFileName);
609
610		// Get the extension.
611		$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
612		$sExtension = strtolower( $sExtension ) ;
613        $image_file = false;
614
615        if(in_array($sExtension,$Config['AllowedExtensions']['Image'])) {
616            $image_file=true;
617        }
618
619		if ( isset( $Config['SecureImageUploads'] ) )
620		{
621			if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false )
622			{
623				$sErrorNumber = '202' ;
624			}
625		}
626
627		if ( isset( $Config['HtmlExtensions'] ) )
628		{
629			if ( !IsHtmlExtension( $sExtension, $Config['HtmlExtensions'] ) &&
630				( $detectHtml = DetectHtml( $oFile['tmp_name'] ) ) === true )
631			{
632				$sErrorNumber = '202' ;
633			}
634		}
635
636        $sFileName = Dwfck_sanitize($sFileName, $image_file);
637
638		// Check if it is an allowed extension.
639		if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) )
640		{
641			$iCounter = 0 ;
642
643			while ( true )
644			{
645
646                //$sFileName = strtolower($sFileName);
647
648                if(!is_dir($sServerDir))
649                {
650                	if ( isset( $Config['ChmodOnFolderCreate'] ) && !$Config['ChmodOnFolderCreate'] )
651					{
652						mkdir_rek($sServerDir,$permissions);
653					}
654					else
655					{
656						$permissions = 0777 ;
657						if ( isset( $Config['ChmodOnFolderCreate'] ) )
658						{
659							$permissions = $Config['ChmodOnFolderCreate'] ;
660						}
661						// To create the folder with 0777 permissions, we need to set umask to zero.
662						$oldumask = umask(0) ;
663						mkdir_rek($sServerDir,$permissions);
664						umask( $oldumask ) ;
665					}
666
667                }
668
669				$sFilePath = $sServerDir . $sFileName ;
670
671
672				if ( is_file( $sFilePath ) )
673				{
674					$iCounter++ ;
675       			    $sFileName = RemoveExtension($sOriginalFileName) . '_' . $iCounter  . ".$sExtension" ;
676                    $sFileName = Dwfck_sanitize($sFileName, $image_file);
677
678					$sErrorNumber = '201' ;
679				}
680				else
681				{
682					move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
683
684					if ( is_file( $sFilePath ) )
685					{
686						if ( isset( $Config['ChmodOnUpload'] ) && !$Config['ChmodOnUpload'] )
687						{
688							break ;
689						}
690
691						$permissions = 0777;
692
693						if ( isset( $Config['ChmodOnUpload'] ) && $Config['ChmodOnUpload'] )
694						{
695							$permissions = $Config['ChmodOnUpload'] ;
696						}
697
698						$oldumask = umask(0) ;
699						chmod( $sFilePath, $permissions ) ;
700						umask( $oldumask ) ;
701					}
702
703					break ;
704				}
705			}
706
707			if ( file_exists( $sFilePath ) )
708			{
709				//previous checks failed, try once again
710				if ( isset( $isImageValid ) && $isImageValid === -1 && IsImageValid( $sFilePath, $sExtension ) === false )
711				{
712					@unlink( $sFilePath ) ;
713					$sErrorNumber = '202' ;
714				}
715				else if ( isset( $detectHtml ) && $detectHtml === -1 && DetectHtml( $sFilePath ) === true )
716				{
717					@unlink( $sFilePath ) ;
718					$sErrorNumber = '202' ;
719				}
720			}
721		}
722		else
723			$sErrorNumber = '202' ;
724	}
725	else
726		$sErrorNumber = '202' ;
727
728
729	$sFileUrl = CombinePaths( GetResourceTypePath( $resourceType, $sCommand ) , $currentFolder ) ;
730	$sFileUrl = CombinePaths( $sFileUrl, $sFileName ) ;
731
732	SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
733
734	exit ;
735}
736
737function mkdir_rek($dir, $mode = 0777)
738{
739 global $Config;
740    if($Config['osWindows']) $dir=normalizeWIN($dir);
741	if (!is_dir($dir))	{
742		mkdir_rek(dirname($dir), $mode);
743		mkdir($dir, $mode);
744
745	}
746}
747
748function send_ckg_UploadError($err,$sFileUrl, $file) {
749    switch($err) {
750
751        case UPLOAD_ERR_INI_SIZE:
752            $msg = "The uploaded file exceeds the upload_max_filesize directive in php.ini.";
753            break;
754
755        case UPLOAD_ERR_FORM_SIZE:
756        $msg = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
757        break;
758
759        case UPLOAD_ERR_PARTIAL:
760            $msg = "The uploaded file was only partially uploaded.";
761            break;
762
763        case UPLOAD_ERR_NO_FILE:
764            $msg = "No file was uploaded.";
765            break;
766
767       case 6:       //   UPLOAD_ERR_NO_TMP_DIR  Introduced in PHP 4.3.10 and PHP 5.0.3.
768            $msg = "Missing a temporary folder.";
769            break;
770
771       case 7:  //UPLOAD_ERR_CANT_WRITE  Introduced in PHP 5.1.0.
772            $msg="Failed to write file to disk.";
773            break;
774
775        case 8: //UPLOAD_ERR_EXTENSION   Introduced in PHP 5.2.0.
776            $msg="PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.";
777            break;
778
779        default:
780           $msg = "Undetermined  upload error";
781           break;
782    }
783      $upload_error = 300 + $err;
784       SendUploadResults( $upload_error, $sFileUrl, $file,  $msg ) ;
785
786}
787
788function cmd_write_debug($what) {
789return;
790if(is_array($what)) {
791   $what = print_r($what,true);
792}
793$dwfckFHandle = fopen("fbrowser_dbg.txt", "a");
794fwrite($dwfckFHandle, "$what\n");
795fclose($dwfckFHandle);
796}
797?>
798