[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - Calendar * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Based on Webcalendar by Craig Knudsen <cknudsen@radix.net> * |
---|
| 6 | * http://www.radix.net/~cknudsen * |
---|
| 7 | * Modified by Mark Peters <skeeter@phpgroupware.org> * |
---|
| 8 | * -------------------------------------------- * |
---|
| 9 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 10 | * under the terms of the GNU General Public License as published by the * |
---|
| 11 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 12 | * option) any later version. * |
---|
| 13 | \**************************************************************************/ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | class uiicalendar |
---|
| 17 | { |
---|
| 18 | var $bo; |
---|
| 19 | var $template; |
---|
| 20 | |
---|
| 21 | var $public_functions = array( |
---|
| 22 | 'test' => True, |
---|
[620] | 23 | 'import' => True, |
---|
| 24 | 'import_from_mail' => True |
---|
[2] | 25 | ); |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | function uiicalendar() |
---|
| 30 | { |
---|
| 31 | $this->bo = CreateObject('calendar.boicalendar'); |
---|
| 32 | $this->template = $GLOBALS['phpgw']->template; |
---|
| 33 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Calendar - [iv]Cal Importer'); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | function print_test($val,$title,$x_pre='') |
---|
| 37 | { |
---|
| 38 | // echo 'VAL = '._debug_array($val,False)."<br>\n"; |
---|
| 39 | if(is_array($val)) |
---|
| 40 | { |
---|
| 41 | @reset($val); |
---|
| 42 | while(list($key,$value) = each($val)) |
---|
| 43 | { |
---|
| 44 | if(is_array($key)) |
---|
| 45 | { |
---|
| 46 | $this->print_test($key,$title,$x_pre); |
---|
| 47 | } |
---|
| 48 | elseif(is_array($value)) |
---|
| 49 | { |
---|
| 50 | $this->print_test($value,$title,$x_pre); |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | if($x_pre && $key == 'name') |
---|
| 55 | { |
---|
| 56 | $x_key = $x_pre.$value; |
---|
| 57 | list($key,$value) = each($val); |
---|
| 58 | $key=$x_key; |
---|
| 59 | } |
---|
| 60 | if($this->bo->parameter[$key]['type'] == 'function') |
---|
| 61 | { |
---|
| 62 | $function = $this->bo->parameter[$key]['function']; |
---|
| 63 | $v_value = $this->bo->$function($value); |
---|
| 64 | } |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | $v_value = $value; |
---|
| 68 | } |
---|
| 69 | echo $title.' ('.$key.') = '.$v_value."<br>\n"; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | elseif($val != '') |
---|
| 74 | { |
---|
| 75 | echo $title.' = '.$val."<br>\n"; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
[620] | 79 | function import_from_mail() { |
---|
| 80 | $msg_number = $_GET['msg_number']; |
---|
| 81 | $idx_file = $_GET['idx_file']; |
---|
| 82 | $newfilename = $_GET['newfilename']; |
---|
| 83 | $msg_part = $_GET['msg_part']; |
---|
| 84 | $msg_folder = $_GET['msg_folder']; |
---|
| 85 | $encoding = strtolower($_GET['encoding']); |
---|
| 86 | $fileContent = ""; |
---|
| 87 | |
---|
| 88 | if($msg_number && $msg_part && $msg_folder && (intval($idx_file == '0' ? '1' : $idx_file))) { |
---|
| 89 | $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 90 | $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 91 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 92 | $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 93 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
| 94 | { |
---|
| 95 | $imap_options = '/tls/novalidate-cert'; |
---|
| 96 | } |
---|
| 97 | else |
---|
| 98 | { |
---|
| 99 | $imap_options = '/notls/novalidate-cert'; |
---|
| 100 | } |
---|
| 101 | $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$msg_folder, $username, $password); |
---|
| 102 | $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); |
---|
| 103 | |
---|
| 104 | $imap_attachment = CreateObject("expressoMail1_2.imap_attachment"); |
---|
| 105 | $a = $imap_attachment->download_attachment($mbox_stream, $msg_number); |
---|
| 106 | |
---|
| 107 | $filename = $a[$idx_file]['name']; |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | $filename = $idx_file; |
---|
| 111 | |
---|
| 112 | $filename = $filename ? $filename : "attachment.bin"; |
---|
| 113 | $newfilename = $newfilename ? $newfilename : $filename; |
---|
| 114 | $strFileType = strrev(substr(strrev(strtolower($filename)),0,4)); |
---|
| 115 | |
---|
| 116 | if($fileContent) { |
---|
| 117 | if($encoding == 'base64') |
---|
| 118 | $calendar = imap_base64($fileContent); |
---|
| 119 | else if($encoding == 'quoted-printable') |
---|
| 120 | $calendar = quoted_printable_decode($fileContent); |
---|
| 121 | else |
---|
| 122 | $calendar = $fileContent; |
---|
| 123 | } |
---|
| 124 | $this->bo->import(explode("\n",$calendar),true); |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
[2] | 130 | function import() |
---|
| 131 | { |
---|
| 132 | unset($GLOBALS['phpgw_info']['flags']['noheader']); |
---|
| 133 | unset($GLOBALS['phpgw_info']['flags']['nonavbar']); |
---|
| 134 | $GLOBALS['phpgw_info']['flags']['nonappheader'] = True; |
---|
| 135 | $GLOBALS['phpgw_info']['flags']['nonappfooter'] = True; |
---|
| 136 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 137 | |
---|
| 138 | if(!@is_dir($GLOBALS['phpgw_info']['server']['temp_dir'])) |
---|
| 139 | { |
---|
| 140 | mkdir($GLOBALS['phpgw_info']['server']['temp_dir'],0700); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | echo '<body bgcolor="' . $GLOBALS['phpgw_info']['theme']['bg_color'] . '">'; |
---|
| 144 | |
---|
| 145 | if ($GLOBALS['HTTP_GET_VARS']['action'] == 'GetFile') |
---|
| 146 | { |
---|
| 147 | echo '<b><center>' . lang('You must select a [iv]Cal. (*.[iv]cs)') . '</b></center><br><br>'; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | $this->template->set_file( |
---|
| 151 | Array( |
---|
| 152 | 'vcalimport' => 'vcal_import.tpl' |
---|
| 153 | ) |
---|
| 154 | ); |
---|
| 155 | |
---|
| 156 | $var = Array( |
---|
| 157 | 'vcal_header' => '<p>', |
---|
| 158 | 'ical_lang' => lang('(i/v)Cal'), |
---|
| 159 | 'action_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.boicalendar.import'), |
---|
| 160 | 'lang_access' => lang('Access'), |
---|
| 161 | 'lang_groups' => lang('Which groups'), |
---|
| 162 | 'access_option'=> $access_option, |
---|
| 163 | 'group_option' => $group_option, |
---|
| 164 | 'load_vcal' => lang('Load [iv]Cal') |
---|
| 165 | ); |
---|
| 166 | $this->template->set_var($var); |
---|
| 167 | $this->template->pparse('out','vcalimport'); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | ?> |
---|