public function edit()
 {
     $GLOBALS['phpgw_info']['flags']['app_header'] .= '::' . lang('edit');
     // Get the contract part id
     $arena_id = (int) phpgw::get_var('id');
     $cancel_link = self::link(array('menuaction' => 'activitycalendar.uiarena.index'));
     $buildings = activitycalendar_soarena::get_instance()->get_buildings();
     //var_dump($buildings);
     // Retrieve the arena object or create a new one
     if (isset($arena_id) && $arena_id > 0) {
         $arena = activitycalendar_soarena::get_instance()->get_single($arena_id);
     } else {
         $arena = new activitycalendar_arena();
     }
     if (isset($_POST['save_arena'])) {
         if (isset($arena)) {
             // ... set all parameters
             $arena->set_internal_arena_id(phpgw::get_var('internal_arena_id'));
             $arena->set_arena_name(phpgw::get_var('arena_name'));
             $arena->set_address(phpgw::get_var('address'));
             $arena->set_addressnumber(phpgw::get_var('address_no'));
             $arena->set_zip_code(phpgw::get_var('zip_code'));
             $arena->set_city(phpgw::get_var('city'));
             $arena->set_active(phpgw::get_var('arena_active') == 'yes' ? true : false);
             if (activitycalendar_soarena::get_instance()->store($arena)) {
                 $message = lang('messages_saved_form');
             } else {
                 $error = lang('messages_form_error');
             }
         }
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'activitycalendar.uiarena.view', 'id' => $arena->get_id(), 'saved_ok' => 'yes'));
     }
     return $this->render('arena.php', array('arena' => $arena, 'buildings' => $buildings, 'editable' => true, 'cancel_link' => $cancel_link, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error')));
 }
 /**
  * Get a static reference to the storage object associated with this model object
  * 
  * @return the storage object
  */
 public static function get_so()
 {
     if (self::$so == null) {
         self::$so = CreateObject('rental.socontract');
     }
     return self::$so;
 }
 /**
  * Public method. Add new activity.
  */
 public function add()
 {
     //$GLOBALS['phpgw']->redirect_link('/activitycalendarfrontend/index.php', array('menuaction' => 'activitycalendarfrontend.uiactivity.edit', 'action' => 'new_activity'));
     $GLOBALS['phpgw']->js->validate_file('json', 'json', 'phpgwapi');
     $c = createobject('phpgwapi.config', 'activitycalendarfrontend');
     $c->read();
     $config = $c->config_data;
     $ajaxUrl = $c->config_data['AJAXURL'];
     $categories = $this->so_activity->get_categories();
     $targets = $this->so_activity->get_targets();
     $offices = $this->so_activity->select_district_list();
     $districts = $this->so_activity->get_districts();
     $buildings = $this->so_arena->get_buildings();
     $arenas = $this->so_arena->get(null, null, 'arena.arena_name', true, null, null, null);
     $organizations = $this->so_organization->get(null, null, 'org.name', true, null, null, null);
     $activity = new activitycalendar_activity();
     $o_id = phpgw::get_var('organization_id');
     $o_id_new = phpgw::get_var('organization_id_hidden');
     if (isset($_POST['step_1'])) {
         //activity shall be registred on a new organization
         if ($o_id_new == "new_org") {
             //add new organization to internal activitycalendar organization register
             $org_homepage = phpgw::get_var('homepage');
             if ($org_homepage == 'http://') {
                 $org_homepage = "";
             }
             $org_info['name'] = phpgw::get_var('orgname');
             $org_info['orgnr'] = phpgw::get_var('orgno');
             $org_info['homepage'] = $org_homepage;
             $org_info['street'] = phpgw::get_var('address');
             $org_info['streetnumber'] = phpgw::get_var('number');
             $org_info['zip'] = phpgw::get_var('postzip');
             $org_info['postaddress'] = phpgw::get_var('postaddress');
             $org_info['status'] = "new";
             $o_id = $this->so_activity->add_organization_local($org_info);
             //add contact persons
             $contact1 = array();
             $contact1['name'] = phpgw::get_var('org_contact1_name');
             $contact1['phone'] = phpgw::get_var('org_contact1_phone');
             $contact1['mail'] = phpgw::get_var('org_contact1_mail');
             $contact1['org_id'] = $o_id;
             $contact1['group_id'] = 0;
             $this->so_activity->add_contact_person_local($contact1);
             $person_arr = $this->so_contact->get_local_contact_persons($o_id);
             foreach ($person_arr as $p) {
                 $persons[] = $p;
             }
             $person_ids = $this->so_organization->get_contacts_local($o_id);
             $desc = phpgw::get_var('org_description');
             $organization = $this->so_organization->get_organization_local($o_id);
             $new_org = true;
             $organization = $this->so_organization->get_organization_local($o_id);
             $person_arr = $this->so_organization->get_contacts_local_as_objects($o_id);
             foreach ($person_arr as $p) {
                 //var_dump($p);
                 $persons[] = $p;
             }
             $message = lang('organization_saved_form');
             $this->render('activity_new.php', array('activity' => $activity, 'new_organization' => true, 'organization' => $organization, 'contact1' => $persons[0], 'arenas' => $arenas, 'buildings' => $buildings, 'categories' => $categories, 'targets' => $targets, 'districts' => $districts, 'offices' => $offices, 'editable' => true, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'ajaxURL' => $ajaxUrl));
         } else {
             $new_org = false;
             $organization = $this->so_organization->get_single($o_id);
             $person_arr = $this->so_contact->get(null, null, null, null, null, null, array('organization_id' => $o_id));
             foreach ($person_arr as $p) {
                 //var_dump($p);
                 $persons[] = $p;
             }
             $activity->set_organization_id($o_id);
             $activity->set_description($organization->get_description());
             $activity->set_contact_persons($pers);
             $this->render('activity_new.php', array('activity' => $activity, 'new_organization' => false, 'organization' => $organization, 'contact1' => $persons[0], 'arenas' => $arenas, 'buildings' => $buildings, 'categories' => $categories, 'targets' => $targets, 'districts' => $districts, 'offices' => $offices, 'editable' => true, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'ajaxURL' => $ajaxUrl));
         }
     } else {
         if (isset($_POST['save_activity'])) {
             $get_org_from_local = false;
             $new_org_group = false;
             $new_org = phpgw::get_var('new_organization');
             if ($new_org != null && $new_org == 'yes') {
                 $get_org_from_local = true;
             }
             if ($get_org_from_local) {
                 $activity->set_new_org(true);
                 //$person_arr = $this->so_contact->get_local_contact_persons($o_id);
                 //foreach($person_arr as $p)
                 //{
                 //$persons[] = $p;
                 //}
                 //$person_ids = $this->so_organization->get_contacts_local($o_id);
                 //$desc = $this->so_organization->get_description_local($o_id);
                 $organization = $this->so_organization->get_organization_local($o_id);
                 $new_org = true;
                 //$new_org_group = true;
                 //Add new group for the activity
                 $group_info['name'] = phpgw::get_var('title');
                 $group_info['organization_id'] = $o_id;
                 $group_info['description'] = phpgw::get_var('description');
                 $group_info['status'] = "new";
                 $g_id = $this->so_activity->add_group_local($group_info);
                 //add contact persons
                 $contact1 = array();
                 $contact1['name'] = phpgw::get_var('contact_name');
                 $contact1['phone'] = phpgw::get_var('contact_phone');
                 $contact1['mail'] = phpgw::get_var('contact_mail');
                 $contact1['org_id'] = $o_id;
                 $contact1['group_id'] = $g_id;
                 $this->so_activity->add_contact_person_local($contact1);
                 $person_arr = $this->so_contact->get_local_contact_persons($g_id, true);
                 foreach ($person_arr as $p) {
                     $persons[] = $p;
                 }
                 $desc = phpgw::get_var('description');
                 $group = $this->so_group->get_group_local($g_id);
                 $person_ids = $this->so_group->get_contacts_local($g_id);
                 $new_group = true;
             } else {
                 if (is_numeric($o_id) && $o_id > 0) {
                     $group_info['name'] = phpgw::get_var('title');
                     $group_info['organization_id'] = $o_id;
                     $group_info['description'] = phpgw::get_var('description');
                     $group_info['status'] = "new";
                     $g_id = $this->so_activity->add_group_local($group_info);
                     //add contact persons
                     $contact1 = array();
                     $contact1['name'] = phpgw::get_var('contact_name');
                     $contact1['phone'] = phpgw::get_var('contact_phone');
                     $contact1['mail'] = phpgw::get_var('contact_mail');
                     $contact1['org_id'] = 0;
                     $contact1['group_id'] = $g_id;
                     $this->so_activity->add_contact_person_local($contact1);
                     $person_arr = $this->so_contact->get_local_contact_persons($g_id, true);
                     foreach ($person_arr as $p) {
                         $persons[] = $p;
                     }
                     $desc = phpgw::get_var('description');
                     $group = $this->so_group->get_group_local($g_id);
                     $person_ids = $this->so_group->get_contacts_local($g_id);
                     $organization = $this->so_organization->get_single($o_id);
                     $new_group = true;
                 }
             }
             if (strlen($desc) > 254) {
                 $desc = substr($desc, 0, 254);
             }
             $arena_id = phpgw::get_var('internal_arena_id');
             $new_arena = phpgw::get_var('new_arena_hidden');
             if ($new_arena != null && $new_arena == 'new_arena') {
                 $arena = new activitycalendar_arena();
                 $arena_name = phpgw::get_var('arena_name');
                 $arena_address = phpgw::get_var('arena_address');
                 $arena_addressnumber = phpgw::get_var('arena_number');
                 $arena_zip_code = phpgw::get_var('arena_zip_code');
                 $arena_city = phpgw::get_var('arena_city');
                 $arena->set_arena_name($arena_name);
                 $arena->set_address($arena_address);
                 $arena->set_addressnumber($arena_addressnumber);
                 $arena->set_zip_code($arena_zip_code);
                 $arena->set_city($arena_city);
                 $arena->set_active(true);
                 // All is good, store arena
                 if ($this->so_arena->store($arena)) {
                     $arena_id = $arena->get_id();
                     $activity->set_arena($arena_id);
                 }
             } else {
                 $arena_arr = explode("_", $arena_id);
                 if ($arena_arr[0] == 'i') {
                     $activity->set_internal_arena($arena_arr[1]);
                 } else {
                     $activity->set_arena($arena_arr[1]);
                 }
             }
             //... set all parameters
             $activity->set_title(phpgw::get_var('title'));
             $activity->set_organization_id($o_id);
             $activity->set_group_id($g_id);
             $activity->set_district(phpgw::get_var('district'));
             $activity->set_office(phpgw::get_var('office'));
             $activity->set_state(1);
             $activity->set_category(phpgw::get_var('category'));
             $target_array = phpgw::get_var('target');
             $activity->set_target(implode(",", $target_array));
             $activity->set_description($desc);
             $activity->set_time(phpgw::get_var('time'));
             $activity->set_contact_persons($persons);
             $activity->set_special_adaptation(phpgw::get_var('special_adaptation'));
             $activity->set_contact_person_2_address(phpgw::get_var('contact2_address') . ", " . phpgw::get_var('contact2_number'));
             $activity->set_contact_person_2_zip(phpgw::get_var('contact2_postaddress'));
             $activity->set_frontend(true);
             $activity->set_new_org($new_org);
             $activity->set_new_group($new_group);
             $target_ok = false;
             $district_ok = false;
             if ($get_org_from_local) {
                 //update new organization with district-id from activity.
                 $this->so_organization->update_org_district_local($organization->get_id(), $activity->get_district());
             }
             if ($activity->get_target() && $activity->get_target() != '') {
                 $target_ok = true;
             }
             if ($activity->get_district() && $activity->get_district() != '') {
                 $district_ok = true;
             }
             if ($target_ok && $district_ok) {
                 if ($this->so_activity->store($activity)) {
                     // ... and then try to store the object
                     $message = lang('messages_saved_form');
                 } else {
                     $error = lang('messages_form_error');
                 }
                 //$org_info_edit_url = self::link('/index.php' ,array('menuaction' => 'activitycalendarfrontend.uiactivity.edit_organization_values'));
                 $GLOBALS['phpgw_info']['flags']['noframework'] = true;
                 $this->render('activity.php', array('activity' => $activity, 'organization' => $organization, 'group' => $group, 'contact1' => $persons[0], 'arenas' => $arenas, 'buildings' => $buildings, 'categories' => $categories, 'targets' => $targets, 'districts' => $districts, 'offices' => $offices, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'ajaxURL' => $ajaxUrl));
             } else {
                 if (!$target_ok) {
                     $error .= "<br/>" . lang('target_not_selected');
                 }
                 if (!$district_ok) {
                     $error .= "<br/>" . lang('district_not_selected');
                 }
                 return $this->render('activity_new.php', array('activity' => $activity, 'organizations' => $organizations, 'organization' => $organization, 'contact1' => $persons[0], 'contact2' => $persons[1], 'org_name' => $org_name, 'new_org' => $new_org, 'groups' => $groups, 'arenas' => $arenas, 'buildings' => $buildings, 'categories' => $categories, 'targets' => $targets, 'districts' => $districts, 'offices' => $offices, 'editable' => true, 'cancel_link' => $cancel_link, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'ajaxURL' => $ajaxUrl));
             }
         } else {
             return $this->render('activity_new_step_1.php', array('organizations' => $organizations, 'ajaxURL' => $ajaxUrl));
         }
     }
 }
 /**
  * Function for adding a new arena to the database. Updates the arena object.
  *
  * @param activitycalendar_arena $arena the party to be added
  * @return bool true if successful, false otherwise
  */
 function add(&$arena)
 {
     // Insert a new arena
     $q = "INSERT INTO activity_arena (arena_name) VALUES ('test')";
     $result = $this->db->query($q);
     if (isset($result)) {
         // Set the new party ID
         $arena->set_id($this->db->get_last_insert_id('activity_arena', 'id'));
         // Forward this request to the update method
         return $this->update($arena);
     } else {
         return false;
     }
 }
 protected function import_arenas()
 {
     $start_time = time();
     $soarena = activitycalendar_soarena::get_instance();
     $soactivity = activitycalendar_soactivity::get_instance();
     //var_dump($_FILES['file']['name']);
     //var_dump($this->file);
     //$datalines = $this->getcsvdata($_FILES['file']['tmp_name']);;
     $datalines = $this->csvdata;
     //$datalines = $this->getcsvdata($this->file);
     //$activity_district = $this->district;
     $this->messages[] = "Read 'import_all.csv' file in " . (time() - $start_time) . " seconds";
     $this->messages[] = "'importfile.csv' contained " . count($datalines) . " lines";
     //$so_arena = rental_socontract::get_instance();
     $db_activity = $soactivity->get_db();
     $db_activity->transaction_begin();
     foreach ($datalines as $data) {
         $arenaOK = true;
         $activityOK = true;
         unset($act_targets);
         unset($activity_persons);
         unset($activity_description);
         unset($org_info);
         unset($group_info);
         unset($contact_person);
         unset($contact1);
         unset($contact2);
         unset($contact3);
         unset($contact4);
         unset($new_group_id);
         $internal_arena = $this->decode($data[9]);
         if ($internal_arena) {
             $internal_arena_id = $internal_arena;
             $curr_arena_id = "";
         } else {
             $arena = new activitycalendar_arena();
             //8: sted, 10:adresse
             $arena_name = $this->decode($data[8]);
             $arena_address = $this->decode($data[10]);
             $curr_arena_id = 0;
             $existing_arena_id = 0;
             $internal_arena_id = "";
             if ($arena_name) {
                 $existing_arena_id = $soarena->get_arena_id_by_name($arena_name);
                 if ($existing_arena_id > 0) {
                     $curr_arena_id = $existing_arena_id;
                 } else {
                     $arena->set_arena_name($arena_name);
                     $arena->set_address($arena_address);
                     $arena->set_active(true);
                     // All is good, store notification
                     if ($soarena->store($arena)) {
                         $this->messages[] = "Successfully imported arena: Name ({$arena_name})";
                         $curr_arena_id = $arena->get_id();
                     } else {
                         $this->errors[] = "Error importing arena: Name ({$arena_name})";
                         $curr_arena_id = 0;
                         $arenaOK = false;
                     }
                 }
             } else {
                 $this->errors[] = "Error importing arena: Name not supplied";
                 $curr_arena_id = 0;
             }
         }
         $activity = new activitycalendar_activity();
         $activity_title = $this->decode($data[1]);
         $activity_group = $this->decode($data[2]);
         $activity_org = $this->decode($data[3]);
         $activity_category = $this->decode($data[5]);
         $org_name_tmp = $this->decode($data[1]);
         if (strlen($org_name_tmp) > 50) {
             $org_name_tmp = substr($org_name_tmp, 0, 49);
         }
         $org_email = $this->decode($data[15]);
         if (strlen($org_email) > 50) {
             $org_email = substr($org_email, 0, 49);
         }
         $org_phone = $this->decode($data[14]);
         if (strlen($org_phone) > 50) {
             $org_phone = substr($org_phone, 0, 49);
         }
         $contact_mail_2 = $this->decode($data[21]);
         if (strlen($contact_mail_2) > 50) {
             $contact_mail_2 = substr($contact_mail_2, 0, 49);
         }
         if ($activity_category) {
             $activity_category = $soactivity->get_category_from_name($activity_category);
         }
         $contact1_name = $this->decode($data[13]);
         if (strlen($contact1_name) > 50) {
             $contact1_name = substr($contact1_name, 0, 49);
         }
         $contact1_phone = $this->decode($data[14]);
         if (strlen($contact1_phone) > 50) {
             $contact1_phone = substr($contact1_phone, 0, 49);
         }
         $contact2_name = $this->decode($data[17]);
         if (strlen($contact2_name) > 50) {
             $contact2_name = substr($contact2_name, 0, 49);
         }
         $contact2_phone = $this->decode($data[20]);
         if (strlen($contact2_phone) > 50) {
             $contact2_phone = substr($contact2_phone, 0, 49);
         }
         if ($activity_org) {
             $activity_org = $soactivity->get_orgid_from_orgno($activity_org);
             if ($activity_org) {
                 //update the organization found
                 $org_info = array();
                 $org_info['orgid'] = $activity_org;
                 $org_info['name'] = $org_name_tmp;
                 //new
                 $org_info['homepage'] = $this->decode($data[16]);
                 $org_info['phone'] = $org_phone;
                 $org_info['email'] = $org_email;
                 $org_info['description'] = $this->decode($data[6]);
                 $org_info['street'] = $this->decode($data[10]);
                 $org_info['zip'] = $this->decode($data[19]);
                 $org_info['activity_id'] = $activity_category;
                 $org_info['district'] = $this->decode($data[23]);
                 $soactivity->update_organization($org_info);
                 //$new_org_id = $activity_org;
                 $soactivity->delete_contact_persons($activity_org);
                 $contact1 = array();
                 $contact1['name'] = $contact1_name;
                 $contact1['phone'] = $contact1_phone;
                 $contact1['mail'] = $org_email;
                 $contact1['org_id'] = $this->decode($activity_org);
                 $soactivity->add_contact_person_org($contact1);
                 $contact2 = array();
                 $contact2['name'] = $contact2_name;
                 $contact2['phone'] = $contact2_phone;
                 $contact2['mail'] = $contact_mail_2;
                 $contact2['org_id'] = $this->decode($activity_org);
                 $soactivity->add_contact_person_org($contact2);
                 //group-stuff:
                 if ($activity_group) {
                     $group_info = array();
                     $group_info['organization_id'] = $activity_org;
                     $group_info['description'] = $this->decode($data[6]);
                     $group_info['name'] = $this->decode($data[1]);
                     $group_info['activity_id'] = $activity_category;
                     $new_group_id = $soactivity->add_group($group_info);
                     $contact3 = array();
                     $contact3['name'] = $contact1_name;
                     $contact3['phone'] = $contact1_phone;
                     $contact3['mail'] = $org_email;
                     $contact3['group_id'] = $this->decode($new_group_id);
                     $soactivity->add_contact_person_group($contact3);
                     $contact4 = array();
                     $contact4['name'] = $contact2_name;
                     $contact4['phone'] = $contact2_phone;
                     $contact4['mail'] = $contact_mail_2;
                     $contact4['group_id'] = $this->decode($new_group_id);
                     $soactivity->add_contact_person_group($contact4);
                     $activity_persons = activitycalendar_sogroup::get_instance()->get_contacts($new_group_id);
                 } else {
                     $activity_persons = activitycalendar_soorganization::get_instance()->get_contacts($activity_org);
                 }
                 /*						
                 						foreach($activity_persons as $pers)
                 						{
                 							unset($contact_person);
                 							$contact_person['id'] = $pers;
                 							$contact_person['name'] = $this->decode($data[11]);
                 							$contact_person['phone'] = $this->decode($data[12]);
                 							$contact_person['mail'] = $this->decode($data[13]);
                 							$contact_person['org_id'] = $this->decode($new_org_id);
                 							$soactivity->update_contact_person_org($contact_person);							
                 						}						
                 */
                 /*
                 $soactivity->set_org_active($activity_org);
                 $activity_description = $this->decode($data[5]);
                 if($activity_description)
                 {
                 	//update description on organization
                 	$soactivity->update_org_description($activity_org, $activity_description);
                 	//var_dump(strlen($activity_description));
                 	//if(strlen($activity_description) > 255)
                 	//{
                 		//$activity_description = substr($activity_description,0,254);
                 	//} 
                 }
                 */
                 //$activity_persons = activitycalendar_soorganization::get_instance()->get_contacts($activity_org);
             } else {
                 $org_info = array();
                 $org_info['name'] = $org_name_tmp;
                 //new
                 $orgno_tmp = $this->decode($data[3]);
                 if (strlen($orgno_tmp) > 9) {
                     $orgno_tmp = NULL;
                 }
                 $org_info['orgnr'] = $orgno_tmp;
                 $org_info['homepage'] = $this->decode($data[16]);
                 $org_info['phone'] = $org_phone;
                 $org_info['email'] = $org_email;
                 $org_info['description'] = $this->decode($data[6]);
                 $org_info['street'] = $this->decode($data[10]);
                 $org_info['zip'] = $this->decode($data[19]);
                 $org_info['activity_id'] = $activity_category;
                 $org_info['district'] = $this->decode($data[23]);
                 $new_org_id = $soactivity->add_organization($org_info);
                 $contact1 = array();
                 $contact1['name'] = $contact1_name;
                 $contact1['phone'] = $contact1_phone;
                 $contact1['mail'] = $org_email;
                 $contact1['org_id'] = $this->decode($new_org_id);
                 $soactivity->add_contact_person_org($contact1);
                 $contact2 = array();
                 $contact2['name'] = $contact2_name;
                 $contact2['phone'] = $contact2_phone;
                 $contact2['mail'] = $contact_mail_2;
                 $contact2['org_id'] = $this->decode($new_org_id);
                 $soactivity->add_contact_person_org($contact2);
                 //group-stuff:
                 if ($activity_group) {
                     $group_info = array();
                     $group_info['organization_id'] = $new_org_id;
                     $group_info['description'] = $this->decode($data[6]);
                     $group_info['name'] = $this->decode($data[1]);
                     $group_info['activity_id'] = $activity_category;
                     $new_group_id = $soactivity->add_group($group_info);
                     $contact3 = array();
                     $contact3['name'] = $contact1_name;
                     $contact3['phone'] = $contact1_phone;
                     $contact3['mail'] = $org_email;
                     $contact3['group_id'] = $this->decode($new_group_id);
                     $soactivity->add_contact_person_group($contact3);
                     $contact4 = array();
                     $contact4['name'] = $contact2_name;
                     $contact4['phone'] = $contact2_phone;
                     $contact4['mail'] = $contact_mail_2;
                     $contact4['group_id'] = $this->decode($new_group_id);
                     $soactivity->add_contact_person_group($contact4);
                     $activity_persons = activitycalendar_sogroup::get_instance()->get_contacts($new_group_id);
                 } else {
                     $activity_persons = activitycalendar_soorganization::get_instance()->get_contacts($new_org_id);
                 }
             }
         } else {
             $org_info = array();
             if ($activity_group && !$activity_group == '') {
                 $org_info['name'] = $activity_group;
             } else {
                 $org_info['name'] = $org_name_tmp;
             }
             //$org_info['orgnr'] = $this->decode($data[2]);
             $org_info['homepage'] = $this->decode($data[16]);
             $org_info['phone'] = $org_phone;
             $org_info['email'] = $org_email;
             $org_info['description'] = $this->decode($data[6]);
             $org_info['street'] = $this->decode($data[10]);
             $org_info['zip'] = $this->decode($data[19]);
             $org_info['activity_id'] = $activity_category;
             $org_info['district'] = $this->decode($data[23]);
             $new_org_id = $soactivity->add_organization($org_info);
             $contact1 = array();
             $contact1['name'] = $contact1_name;
             $contact1['phone'] = $contact1_phone;
             $contact1['mail'] = $org_email;
             $contact1['org_id'] = $this->decode($new_org_id);
             $soactivity->add_contact_person_org($contact1);
             $contact2 = array();
             $contact2['name'] = $contact2_name;
             $contact2['phone'] = $contact2_phone;
             $contact2['mail'] = $contact_mail_2;
             $contact2['org_id'] = $this->decode($new_org_id);
             $soactivity->add_contact_person_org($contact2);
             //group-stuff:
             if ($activity_group) {
                 $group_info = array();
                 $group_info['organization_id'] = $new_org_id;
                 $group_info['description'] = $this->decode($data[6]);
                 $group_info['name'] = $this->decode($data[1]);
                 $group_info['activity_id'] = $activity_category;
                 $new_group_id = $soactivity->add_group($group_info);
                 $contact3 = array();
                 $contact3['name'] = $contact1_name;
                 $contact3['phone'] = $contact1_phone;
                 $contact3['mail'] = $org_email;
                 $contact3['group_id'] = $this->decode($new_group_id);
                 $soactivity->add_contact_person_group($contact3);
                 $contact4 = array();
                 $contact4['name'] = $contact2_name;
                 $contact4['phone'] = $contact2_phone;
                 $contact4['mail'] = $contact_mail_2;
                 $contact4['group_id'] = $this->decode($new_group_id);
                 $soactivity->add_contact_person_group($contact4);
                 $activity_persons = activitycalendar_sogroup::get_instance()->get_contacts($new_group_id);
             } else {
                 $activity_persons = activitycalendar_soorganization::get_instance()->get_contacts($new_org_id);
             }
         }
         $activity_adapted = $this->decode($data[4]);
         $activity_target = $this->decode($data[7]);
         //var_dump($activity_target);
         if ($activity_target) {
             $act_target_array = explode(",", $activity_target);
             foreach ($act_target_array as $at) {
                 $act_targets[] = $soactivity->get_target_from_sort_id($at);
             }
             $activity_target = implode(",", $act_targets);
         }
         $activity_day = $this->decode($data[11]);
         $activity_time = $this->decode($data[12]);
         $activity_update_date = $this->decode($data[22]);
         if ($activity_update_date) {
             $act_update_array = explode(".", $activity_update_date);
             if (count($act_update_array) == 3) {
                 $y = $act_update_array[2];
                 $m = $act_update_array[1];
                 $d = $act_update_array[0];
                 $activity_updated_date = strtotime($y . "-" . $m . "-" . $d);
                 //var_dump($activity_updated_date);
             }
         }
         $activity_district = $this->decode($data[23]);
         if ($activity_district) {
             $activity_district = $soactivity->get_district_from_name($activity_district);
         }
         $activity_contact_person_2_address = $this->decode($data[18]);
         $activity_contact_person_2_zip = $this->decode($data[19]);
         if ($activity_title) {
             $activity->set_title($activity_title);
             $activity->set_organization_id($activity_org);
             $activity->set_group_id($new_group_id);
             $activity->set_category($activity_category);
             $activity->set_target($activity_target);
             $activity->set_description($activity_description);
             $activity->set_arena($curr_arena_id);
             $activity->set_internal_arena($internal_arena_id);
             $activity->set_state(3);
             $activity->set_time($activity_day . ' ' . $activity_time);
             if ($activity_adapted) {
                 $activity->set_special_adaptation(true);
             }
             $activity->set_office($this->office);
             $activity->set_district($activity_district);
             $activity->set_contact_person_2_address($activity_contact_person_2_address);
             $activity->set_contact_person_2_zip($activity_contact_person_2_zip);
             $activity->set_last_change_date($activity_updated_date);
             if ($activity_persons) {
                 //set contact persons
                 $activity->set_contact_persons($activity_persons);
             }
             //var_dump($activity);
             // All is good, store activity
             if ($soactivity->import_activity($activity)) {
                 $this->messages[] = "Successfully imported activity: Title ({$this->decode($data[1])})";
             } else {
                 $this->errors[] = "Error importing activity: Title ({$this->decode($data[1])})";
                 $activityOK = false;
             }
         }
     }
     if ($arenaOK && $activityOK) {
         $this->messages[] = "Imported activities. (" . (time() - $start_time) . " seconds)";
         $db_activity->transaction_commit();
         return true;
     } else {
         if (!$arenaOK) {
             $this->messages[] = "Import of arenas failed. (" . (time() - $start_time) . " seconds)";
         } else {
             if (!$activityOK) {
                 $this->messages[] = "Import of activities failed. (" . (time() - $start_time) . " seconds)";
             } else {
                 $this->messages[] = "Import of activities/arenas failed. (" . (time() - $start_time) . " seconds)";
             }
         }
         $db_activity->transaction_abort();
         return false;
     }
 }