Index: branches/2.2.0.1/phpgwapi/inc/class.common.inc.php
===================================================================
--- branches/2.2.0.1/phpgwapi/inc/class.common.inc.php	(revision 3485)
+++ branches/2.2.0.1/phpgwapi/inc/class.common.inc.php	(revision 3966)
@@ -1841,4 +1841,6 @@
 				case 47: $s .= lang('The starting time can not be greater than end time').'.';
 					break;
+                                case 99: $s .= lang('The attachment is to big').'.';
+                                        break;
 				default:	return '';
 			}
Index: branches/2.2.0.1/calendar/setup/tables_current.inc.php
===================================================================
--- branches/2.2.0.1/calendar/setup/tables_current.inc.php	(revision 2)
+++ branches/2.2.0.1/calendar/setup/tables_current.inc.php	(revision 3966)
@@ -27,4 +27,5 @@
 				'title' => array('type' => 'varchar','precision' => '80','nullable' => False,'default' => '1'),
 				'description' => array('type' => 'text','nullable' => True),
+                                'attachment' => array('type' => 'text','nullable' => True),
 				'location' => array('type' => 'varchar','precision' => '255','nullable' => True),
 				'reference' => array('type' => 'int','precision' => '8','nullable' => False,'default' => '0'),
Index: branches/2.2.0.1/calendar/setup/tables_update.inc.php
===================================================================
--- branches/2.2.0.1/calendar/setup/tables_update.inc.php	(revision 3765)
+++ branches/2.2.0.1/calendar/setup/tables_update.inc.php	(revision 3966)
@@ -80,3 +80,8 @@
 		return $GLOBALS['setup_info']['calendar']['currentver'];
 	}
+        $test[] = '2.2.001';
+	function calendar_upgrade2_2_001()
+	{
+            $GLOBALS['phpgw_setup']->db->query("ALTER TABLE phpgw_cal ADD COLUMN attachment text");
+        }
 ?>
Index: branches/2.2.0.1/calendar/inc/class.bocustom_fields.inc.php
===================================================================
--- branches/2.2.0.1/calendar/inc/class.bocustom_fields.inc.php	(revision 2)
+++ branches/2.2.0.1/calendar/inc/class.bocustom_fields.inc.php	(revision 3966)
@@ -31,5 +31,6 @@
 			'updated'     => 'Updated',
 			'alarm'       => 'Alarm',
-			'recure_type' => 'Repetition'
+			'recure_type' => 'Repetition',
+                        'attachment' => 'attachment'
 		);
 
Index: branches/2.2.0.1/calendar/inc/class.bocalendar.inc.php
===================================================================
--- branches/2.2.0.1/calendar/inc/class.bocalendar.inc.php	(revision 3910)
+++ branches/2.2.0.1/calendar/inc/class.bocalendar.inc.php	(revision 3966)
@@ -1014,5 +1014,39 @@
 				$GLOBALS['phpgw']->datetime = createobject('phpgwapi.date_time');
 			}
+
 			$l_cal = (@isset($params['cal']) && $params['cal']?$params['cal']:$_POST['cal']);
+
+                        $post_max_size = ini_get('post_max_size');
+                        $mul = substr($post_max_size, -1);
+                        $mul = ($mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1)));
+                        if ($_SERVER['CONTENT_LENGTH'] > $mul*(int)$post_max_size && $post_max_size)
+                             $l_cal['attachment'] = 'ERROR';
+
+                        if(count($_FILES['cal']) > 0){
+
+                            if($l_cal['attachment'] != '')
+                               $attachments = unserialize($l_cal['attachment']);
+                            else
+                               $attachments = Array();
+
+                            foreach ($_FILES['cal']['error']['attachment'] as $key => $error) {
+
+                                if ($error == UPLOAD_ERR_OK) {
+
+                                    $new_file= $GLOBALS['phpgw_info']['server']['temp_dir'].'/'.$_SESSION[ 'phpgw_session' ][ 'session_id' ].md5($attachment['name'].microtime());
+                                    move_uploaded_file($_FILES['cal']['tmp_name']['attachment'][$key], $new_file);
+                                    $attach = Array('tmp_name' => $new_file, 'name' => $_FILES['cal']['name']['attachment'][$key], 'type' =>  $_FILES['cal']['type']['attachment'][$key]);
+
+                                    $attachments[] = $attach;
+
+                                }elseif($error == UPLOAD_ERR_INI_SIZE){
+                                    $attachments = 'ERROR';
+                                    break;
+
+                                }
+                            }
+                            $l_cal['attachment'] = $attachments;
+
+                        }
 			$l_participants = (@$params['participants']?$params['participants']:$_POST['participants']);
 			$this->ex_participants = (@$params['ex_participants']?$params['ex_participants']:$_POST['ex_participants']);
@@ -1153,4 +1187,5 @@
 				$this->so->set_title($l_cal['title']);
 				$this->so->set_description($l_cal['description']);
+                                $this->so->set_attachment($l_cal['attachment']);
 				$this->so->set_ex_participants($l_cal['ex_participants']);
 				$this->so->set_start($l_start['year'],$l_start['month'],$l_start['mday'],$l_start['hour'],$l_start['min'],0);
@@ -1722,4 +1757,7 @@
 				}
 			}
+                        if($event['attachment'] == 'ERROR')
+                            $error = 99;
+                        
 			return $error;
 		}
@@ -3502,4 +3540,11 @@
 					fclose($attach_fd);
 				}
+
+                                if(isset($new_event['attachment'])){
+                                    foreach($new_event['attachment'] as $attach){
+                                        $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $attach['type']);
+                                    }
+                                }
+                                
 				$mail->From = $sender;
 				$mail->FromName = $GLOBALS['phpgw_info']['user']['fullname'];
@@ -3911,4 +3956,9 @@
 				'data'	=> $GLOBALS['phpgw']->common->show_date($this->maketime($event['modtime']) - $GLOBALS['phpgw']->datetime->tz_offset)
 			);
+
+                        $var['attachment'] = Array(
+                                'field'	=> $this->translate('Attachment'),
+                                'data'	=> $event['attachment']
+                        );
 
 			$var['access'] = Array(
Index: branches/2.2.0.1/calendar/inc/class.socalendar__.inc.php
===================================================================
--- branches/2.2.0.1/calendar/inc/class.socalendar__.inc.php	(revision 2)
+++ branches/2.2.0.1/calendar/inc/class.socalendar__.inc.php	(revision 3966)
@@ -102,4 +102,9 @@
 		}
 
+                function set_attachment($attachment='')
+		{
+			$this->add_attribute('attachment',$attachment);
+		}
+
 		function set_ex_participants($ex_participants='')
 		{
Index: branches/2.2.0.1/calendar/inc/class.socalendar_sql.inc.php
===================================================================
--- branches/2.2.0.1/calendar/inc/class.socalendar_sql.inc.php	(revision 3608)
+++ branches/2.2.0.1/calendar/inc/class.socalendar_sql.inc.php	(revision 3966)
@@ -569,4 +569,5 @@
 				$this->set_title(stripslashes($GLOBALS['phpgw']->strip_html($this->stream->f('title'))));
 				$this->set_description(stripslashes($GLOBALS['phpgw']->strip_html($this->stream->f('description'))));
+                                $this->set_attachment(stripslashes($GLOBALS['phpgw']->strip_html($this->stream->f('attachment'))));
 				$this->set_ex_participants(stripslashes($GLOBALS['phpgw']->strip_html($this->stream->f('ex_participants'))));
 				$this->add_attribute('uid',$GLOBALS['phpgw']->strip_html($this->stream->f('uid')));
@@ -976,4 +977,5 @@
 					. "title='".$this->stream->db_addslashes($event['title'])."', "
 					. "description='".$this->stream->db_addslashes($event['description'])."', "
+                                        . "attachment='".$this->stream->db_addslashes(serialize($event['attachment']))."', "
 					. "ex_participants='".$this->stream->db_addslashes($event['ex_participants'])."', "
 					. "location='".$this->stream->db_addslashes($event['location'])."', "
Index: branches/2.2.0.1/calendar/inc/class.uipublicview.inc.php
===================================================================
--- branches/2.2.0.1/calendar/inc/class.uipublicview.inc.php	(revision 3201)
+++ branches/2.2.0.1/calendar/inc/class.uipublicview.inc.php	(revision 3966)
@@ -466,4 +466,13 @@
 					);
 				}
+                                if($event['attachment'] != '')
+				{
+					$picture[] = Array(
+						'pict'	=> $GLOBALS['phpgw']->common->image('calendar','circle'),
+						'width'	=> 9,
+						'height'=> 9,
+						'title' => lang('Has Attachment')
+					);
+				}
 				else
 				{
@@ -520,4 +529,13 @@
 			}
 
+                        if($event['attachment'] != '')
+			{
+                            $picture[] = Array(
+                                    'pict'	=> $GLOBALS['phpgw']->common->image('calendar','circle'),
+                                    'width'	=> 9,
+                                    'height'=> 9,
+                                    'title' => lang('Has Attachment')
+                            );
+			}
 			$description = $this->bo->get_short_field($event,$is_private,'description');
 			for($i=0;$i<count($picture);$i++)
Index: branches/2.2.0.1/calendar/inc/class.uicalendar.inc.php
===================================================================
--- branches/2.2.0.1/calendar/inc/class.uicalendar.inc.php	(revision 3914)
+++ branches/2.2.0.1/calendar/inc/class.uicalendar.inc.php	(revision 3966)
@@ -3561,4 +3561,14 @@
 			}
 
+                        if($event['attachment'] != '')
+				{
+					$picture[] = Array(
+						'pict'	=> $GLOBALS['phpgw']->common->image('calendar','clip'),
+						'width'	=> 9,
+						'height'=> 9,
+						'title' => lang('Notification with attachments sent.')
+					);
+				}
+
 			$description = $this->bo->get_short_field($event,$is_private,'description');
 			for($i=0;$i<count($picture);$i++)
@@ -4487,4 +4497,10 @@
 			$vars = $this->bo->event2array($event);
 
+                        if($vars['attachment']['data'] == "")
+                            $vars['attachment']['data'] = lang('No Attachment');
+                        else{
+                            $vars['attachment']['data'] = lang('Has attachment(s)');
+                        }
+                        
 			$vars['title']['tr_color'] = $this->theme['th_bg'];
 
@@ -5406,4 +5422,15 @@
 //			$this->output_template_array($p,'row','list',Array('data' => '<script src="simple_show_hide.js" type="text/javascript"></script>'));
 
+                        if ($event['attachment'] == '' || $event['attachment'] == 'ERROR' || is_array($event['attachment']))
+                            $data =  '<a onClick="javascript:addAttach()" href="#divFiles" >Anexos: adicionar+</a><div id="divFiles"</div>';
+                        else
+                            $data = '<input type="hidden" name="cal[attachment]" value='.$event["attachment"].'>'.lang('Notification with attachments sent.').'<br><a onClick="javascript:addAttach()" href="#divFiles" >Anexos: adicionar+</a><div id="divFiles"</div>';
+
+                        $var['attachment'] = Array(
+                                'field' => lang('Attachment'),
+                                //'data' => '<input  type="file" name="cal[attachment]" />'
+                                'data' => $data
+                        );
+
 			if (!isset($this->fields))
 			{
Index: branches/2.2.0.1/calendar/inc/class.socalendar.inc.php
===================================================================
--- branches/2.2.0.1/calendar/inc/class.socalendar.inc.php	(revision 1729)
+++ branches/2.2.0.1/calendar/inc/class.socalendar.inc.php	(revision 3966)
@@ -369,4 +369,8 @@
 			$this->cal->set_description($description);
 		}
+                function set_attachment($attachment='')
+		{
+			$this->cal->set_attachment($attachment);
+		}
 		function set_ex_participants($ex_participants='')
 		{
Index: branches/2.2.0.1/calendar/templates/default/edit.tpl
===================================================================
--- branches/2.2.0.1/calendar/templates/default/edit.tpl	(revision 3254)
+++ branches/2.2.0.1/calendar/templates/default/edit.tpl	(revision 3966)
@@ -10,4 +10,43 @@
 </style>
 <script language="JavaScript">
+
+        function addAttach(){
+            divFiles = document.getElementById("divFiles");
+            if (! divFiles)
+                    return false;
+
+            if (divFiles.lastChild)
+                    var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[1]) + 1;
+
+            if (! countDivFiles)
+                    var countDivFiles = 1;
+
+            divFile = document.createElement('DIV');
+
+
+            divFile.innerHTML = "<input type='file' size='50' maxLength='255' id='"+"inputFile_"+countDivFiles+"' name='cal[attachment][]'>";
+
+
+            var linkFile = document.createElement("A");
+            linkFile.id = "linkFile_"+countDivFiles;
+            linkFile.href='javascript:void(0)';
+            linkFile.onclick=function () {removeFile(this.id.replace("link","div")); return false;};
+            linkFile.innerHTML="Remove";
+            //divFile.innerHTML += "&nbsp;&nbsp;";
+            divFile.appendChild(linkFile);
+            divFile.id = "divFile_"+countDivFiles;
+            divFiles.appendChild(divFile);
+
+
+
+            return document.getElementById("inputFile_"+countDivFiles);
+        }
+
+        function removeFile(id){
+            var border_id = id.substr(8,1);
+            var el = Element(id);
+            el.parentNode.removeChild(el);
+        }
+
 	self.name="first_Window";
 	function accounts_popup()
@@ -38,5 +77,5 @@
 <font color="#000000" face="{font}">
 
-<form action="{action_url}" method="post" name="app_form">
+<form action="{action_url}" method="post" name="app_form" enctype="multipart/form-data">
 {common_hidden}
 <table id="editFormTable" border="0" width="90%"   class="prefTable">
