[3733] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * Tools for manipulating calendars |
---|
| 4 | * |
---|
| 5 | * @package davical |
---|
| 6 | * @subpackage DAViCalSession |
---|
| 7 | * @author Maxime Delorme <mdelorme@tennaxia.com> |
---|
| 8 | * @copyright Maxime Delorme |
---|
| 9 | * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | require_once("./always.php"); |
---|
| 13 | require_once("DAViCalSession.php"); |
---|
| 14 | $session->LoginRequired(); |
---|
| 15 | |
---|
| 16 | require_once("DataEntry.php"); |
---|
| 17 | require_once("interactive-page.php"); |
---|
| 18 | require_once("classBrowser.php"); |
---|
| 19 | |
---|
| 20 | if ( !$session->AllowedTo("Admin" ) ) |
---|
| 21 | exit; |
---|
| 22 | |
---|
| 23 | if( function_exists("sync_LDAP") && isset($_POST['Sync_LDAP'])){ |
---|
| 24 | sync_LDAP(); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | if( function_exists("sync_LDAP_groups") && isset($_POST['Sync_LDAP_groups'])){ |
---|
| 28 | sync_LDAP_groups(); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | if(isset($_POST['import_from_directory'])){ |
---|
| 32 | Tools::importFromDirectory(); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | class Tools { |
---|
| 37 | |
---|
| 38 | function render(){ |
---|
| 39 | global $c; |
---|
| 40 | echo $this->renderImportFromDirectory(); |
---|
| 41 | if ( isset($c->authenticate_hook['call']) && $c->authenticate_hook['call'] == 'LDAP_check' && function_exists("sync_LDAP") ) { |
---|
| 42 | echo $this->renderSyncLDAP(); |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | function renderSyncLDAP(){ |
---|
| 47 | $html = '<div id="entryform">'; |
---|
| 48 | $html .= '<h1>'.translate('Sync LDAP with DAViCal') .'</h1>'; |
---|
| 49 | |
---|
| 50 | $data = (object) array('directory_path' => '/path/to/your/ics/files','calendar_path' => 'home'); |
---|
| 51 | $ef = new EntryForm( $_SERVER['REQUEST_URI'],$data , true,true ); |
---|
| 52 | $html .= "<table width=\"100%\" class=\"data\">\n"; |
---|
| 53 | $html .= $ef->StartForm( array("autocomplete" => "off" ) ); |
---|
| 54 | $html .= sprintf( "<tr><td style=\"text-align:left\" colspan=\"2\" >%s</td></tr>\n", |
---|
| 55 | translate("This operation does the following: <ul><li>check valid users in LDAP directory</li> <li>check users in DAViCal</li></ul> then <ul><li>if a user is present in DAViCal but not in LDAP set him as inactive in DAViCal</li> <li>if a user is present in LDAP but not in DAViCal create the user in DAViCal</li> <li>if a user in present in LDAP and DAViCal then update information in DAViCal</li> </ul>")); |
---|
| 56 | $html .= "</table>\n"; |
---|
| 57 | |
---|
| 58 | $html .= $ef->SubmitButton( "Sync_LDAP", translate('Submit')); |
---|
| 59 | |
---|
| 60 | $html .= '<h1>'.translate('Sync LDAP Groups with RSCDS') .'</h1>'; |
---|
| 61 | $html .= "<table width=\"100%\" class=\"data\">\n"; |
---|
| 62 | $html .= $ef->StartForm( array("autocomplete" => "off" ) ); |
---|
| 63 | $html .= sprintf( "<tr><td style=\"text-align:left\" colspan=\"2\" >%s</td></tr>\n", |
---|
| 64 | translate("This operation does the following: <ul><li>check valid groups in LDAP directory</li> <li>check groups in DAViCal</li></ul> then <ul><li>if a group is present in DAViCal but not in LDAP set as inactive in DAViCal</li> <li>if a group is present in LDAP but not in DAViCal create the group in DAViCal</li> <li>if a group in present in LDAP and DAViCal then update information in DAViCal</li> </ul>")); |
---|
| 65 | $html .= "</table>\n"; |
---|
| 66 | |
---|
| 67 | $html .= $ef->SubmitButton( "Sync_LDAP_groups", translate('Submit')); |
---|
| 68 | $html .= $ef->EndForm(); |
---|
| 69 | |
---|
| 70 | $html .= "</div>"; |
---|
| 71 | return $html; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | function renderImportFromDirectory(){ |
---|
| 75 | $html = '<div id="entryform">'; |
---|
| 76 | $html .= '<h1>'.translate('Import all .ics files of a directory') .'</h1>'; |
---|
| 77 | |
---|
| 78 | $data = (object) array('directory_path' => '/path/to/your/ics/files','calendar_path' => 'home'); |
---|
| 79 | $ef = new EntryForm( $_SERVER['REQUEST_URI'],$data , true,true ); |
---|
| 80 | $html .= "<table width=\"100%\" class=\"data\">\n"; |
---|
| 81 | $html .= $ef->StartForm( array("autocomplete" => "off" ) ); |
---|
| 82 | |
---|
| 83 | $html .= $ef->DataEntryLine( translate("path to store your ics"), "%s", "text", "calendar_path", |
---|
| 84 | array( "size" => 20, |
---|
| 85 | "title" => translate("Set the path to store your ics e.g. 'home' will be referenced as /caldav.php/me/home/"), |
---|
| 86 | "help" => translate("<b>WARNING: all events in this path will be deleted before inserting allof the ics file</b>") |
---|
| 87 | ) |
---|
| 88 | , '' ); |
---|
| 89 | |
---|
| 90 | $html .= $ef->DataEntryLine( translate("Directory on the server"), "%s", "text", "directory_path", |
---|
| 91 | array( "size" => 20, "title" => translate("The path on the server where your .ics files are."))); |
---|
| 92 | |
---|
| 93 | $html .= "</table>\n"; |
---|
| 94 | $html .= $ef->SubmitButton( "import_from_directory", translate('Submit')); |
---|
| 95 | $html .= $ef->EndForm(); |
---|
| 96 | |
---|
| 97 | $html .= "</div>"; |
---|
| 98 | return $html; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | function importFromDirectory(){ |
---|
| 102 | global $c; |
---|
| 103 | if(!isset($_POST["calendar_path"])){ |
---|
| 104 | dbg_error_log( "importFromDirectory", "calendar path not given"); |
---|
| 105 | return ; |
---|
| 106 | } |
---|
| 107 | $path_ics = $_POST["calendar_path"]; |
---|
| 108 | if ( substr($path_ics,-1,1) != '/' ) $path_ics .= '/'; // ensure that we target a collection |
---|
| 109 | if ( substr($path_ics,0,1) != '/' ) $path_ics = '/'.$path_ics; // ensure that we target a collection |
---|
| 110 | |
---|
| 111 | if(!isset($_POST["directory_path"])){ |
---|
| 112 | dbg_error_log( "importFromDirectory", "directory path not given"); |
---|
| 113 | return ; |
---|
| 114 | } |
---|
| 115 | $dir = $_POST["directory_path"]; |
---|
| 116 | if(!is_readable($dir)){ |
---|
| 117 | $c->messages[] = sprintf(i18n('directory %s is not readable'),htmlspecialchars($dir)); |
---|
| 118 | dbg_error_log( "importFromDirectory", "directory is not readable"); |
---|
| 119 | return ; |
---|
| 120 | } |
---|
| 121 | if ($handle = opendir($dir)) { |
---|
| 122 | while (false !== ($file = readdir($handle))) { |
---|
| 123 | if ($file == "." || $file == ".." || substr($file,-4) != '.ics') continue; |
---|
| 124 | if ( !is_readable($dir.'/'.$file) ) { |
---|
| 125 | dbg_error_log( "importFromDirectory", "ics file '%s' is not readable",$dir .'/'.$file); |
---|
| 126 | continue; |
---|
| 127 | } |
---|
| 128 | $ics = file_get_contents($dir.'/'.$file); |
---|
| 129 | $ics = trim($ics); |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | if ( $ics != '' ) { |
---|
| 133 | include_once('check_UTF8.php'); |
---|
| 134 | if ( check_string($ics) ) { |
---|
| 135 | $path = "/".substr($file,0,-4).$path_ics; |
---|
| 136 | dbg_error_log( "importFromDirectory", "importing to $path"); |
---|
| 137 | $c->readonly_webdav_collections = false; // Override this setting so we can create collections/events on import. |
---|
| 138 | require_once("caldav-PUT-functions.php"); |
---|
| 139 | if ( $user = getUserByName(substr($file,0,-4),'importFromDirectory',__LINE__,__FILE__)) { |
---|
| 140 | $user_no = $user->user_no; |
---|
| 141 | } |
---|
| 142 | if(controlRequestContainer(substr($file,0,-4),$user_no, $path,false) === -1) |
---|
| 143 | continue; |
---|
| 144 | import_collection($ics,$user_no,$path,1); |
---|
| 145 | $c->messages[] = sprintf(translate('all events of user %s were deleted and replaced by those from file %s'),substr($file,0,-4),$dir.'/'.$file); |
---|
| 146 | } |
---|
| 147 | else { |
---|
| 148 | $c->messages[] = sprintf(translate('the file %s is not UTF-8 encoded, please check error for more details'),$dir.'/'.$file); |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | closedir($handle); |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | $Tools = new Tools(); |
---|
| 158 | |
---|
| 159 | include("page-header.php"); |
---|
| 160 | $Tools->render(); |
---|
| 161 | include("page-footer.php"); |
---|